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];
67 /* dyngen register indexes */
69 #if defined(TARGET_PPC64)
72 static TCGv cpu_T64[3];
74 static TCGv cpu_FT[3];
75 static TCGv cpu_AVRh[3], cpu_AVRl[3];
77 #include "gen-icount.h"
79 void ppc_translate_init(void)
83 static int done_init = 0;
88 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
89 #if TARGET_LONG_BITS > HOST_LONG_BITS
90 cpu_T[0] = tcg_global_mem_new(TCG_TYPE_TL,
91 TCG_AREG0, offsetof(CPUState, t0), "T0");
92 cpu_T[1] = tcg_global_mem_new(TCG_TYPE_TL,
93 TCG_AREG0, offsetof(CPUState, t1), "T1");
94 cpu_T[2] = tcg_global_mem_new(TCG_TYPE_TL,
95 TCG_AREG0, offsetof(CPUState, t2), "T2");
97 cpu_T[0] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG1, "T0");
98 cpu_T[1] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG2, "T1");
99 cpu_T[2] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG3, "T2");
101 #if !defined(TARGET_PPC64)
102 cpu_T64[0] = tcg_global_mem_new(TCG_TYPE_I64,
103 TCG_AREG0, offsetof(CPUState, t0_64),
105 cpu_T64[1] = tcg_global_mem_new(TCG_TYPE_I64,
106 TCG_AREG0, offsetof(CPUState, t1_64),
108 cpu_T64[2] = tcg_global_mem_new(TCG_TYPE_I64,
109 TCG_AREG0, offsetof(CPUState, t2_64),
113 cpu_FT[0] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
114 offsetof(CPUState, ft0), "FT0");
115 cpu_FT[1] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
116 offsetof(CPUState, ft1), "FT1");
117 cpu_FT[2] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
118 offsetof(CPUState, ft2), "FT2");
120 cpu_AVRh[0] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
121 offsetof(CPUState, avr0.u64[0]), "AVR0H");
122 cpu_AVRl[0] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
123 offsetof(CPUState, avr0.u64[1]), "AVR0L");
124 cpu_AVRh[1] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
125 offsetof(CPUState, avr1.u64[0]), "AVR1H");
126 cpu_AVRl[1] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
127 offsetof(CPUState, avr1.u64[1]), "AVR1L");
128 cpu_AVRh[2] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
129 offsetof(CPUState, avr2.u64[0]), "AVR2H");
130 cpu_AVRl[2] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
131 offsetof(CPUState, avr2.u64[1]), "AVR2L");
135 for (i = 0; i < 8; i++) {
136 sprintf(p, "crf%d", i);
137 cpu_crf[i] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
138 offsetof(CPUState, crf[i]), p);
142 for (i = 0; i < 32; i++) {
143 sprintf(p, "r%d", i);
144 cpu_gpr[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
145 offsetof(CPUState, gpr[i]), p);
146 p += (i < 10) ? 3 : 4;
147 #if !defined(TARGET_PPC64)
148 sprintf(p, "r%dH", i);
149 cpu_gprh[i] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
150 offsetof(CPUState, gprh[i]), p);
151 p += (i < 10) ? 4 : 5;
154 sprintf(p, "fp%d", i);
155 cpu_fpr[i] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
156 offsetof(CPUState, fpr[i]), p);
157 p += (i < 10) ? 4 : 5;
159 sprintf(p, "avr%dH", i);
160 cpu_avrh[i] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
161 offsetof(CPUState, avr[i].u64[0]), p);
162 p += (i < 10) ? 6 : 7;
164 sprintf(p, "avr%dL", i);
165 cpu_avrl[i] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
166 offsetof(CPUState, avr[i].u64[1]), p);
167 p += (i < 10) ? 6 : 7;
170 cpu_nip = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
171 offsetof(CPUState, nip), "nip");
173 cpu_ctr = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
174 offsetof(CPUState, ctr), "ctr");
176 cpu_lr = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
177 offsetof(CPUState, lr), "lr");
179 cpu_xer = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
180 offsetof(CPUState, xer), "xer");
182 /* register helpers */
184 #define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
190 #if defined(OPTIMIZE_FPRF_UPDATE)
191 static uint16_t *gen_fprf_buf[OPC_BUF_SIZE];
192 static uint16_t **gen_fprf_ptr;
195 /* internal defines */
196 typedef struct DisasContext {
197 struct TranslationBlock *tb;
201 /* Routine used to access memory */
203 /* Translation flags */
204 #if !defined(CONFIG_USER_ONLY)
207 #if defined(TARGET_PPC64)
213 ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */
214 int singlestep_enabled;
215 int dcache_line_size;
218 struct opc_handler_t {
221 /* instruction type */
224 void (*handler)(DisasContext *ctx);
225 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
228 #if defined(DO_PPC_STATISTICS)
233 static always_inline void gen_set_Rc0 (DisasContext *ctx)
235 #if defined(TARGET_PPC64)
244 static always_inline void gen_reset_fpstatus (void)
246 #ifdef CONFIG_SOFTFLOAT
247 gen_op_reset_fpstatus();
251 static always_inline void gen_compute_fprf (int set_fprf, int set_rc)
254 /* This case might be optimized later */
255 #if defined(OPTIMIZE_FPRF_UPDATE)
256 *gen_fprf_ptr++ = gen_opc_ptr;
258 gen_op_compute_fprf(1);
259 if (unlikely(set_rc))
260 tcg_gen_andi_i32(cpu_crf[1], cpu_T[0], 0xf);
261 gen_op_float_check_status();
262 } else if (unlikely(set_rc)) {
263 /* We always need to compute fpcc */
264 gen_op_compute_fprf(0);
265 tcg_gen_andi_i32(cpu_crf[1], cpu_T[0], 0xf);
267 gen_op_float_check_status();
271 static always_inline void gen_optimize_fprf (void)
273 #if defined(OPTIMIZE_FPRF_UPDATE)
276 for (ptr = gen_fprf_buf; ptr != (gen_fprf_ptr - 1); ptr++)
277 *ptr = INDEX_op_nop1;
278 gen_fprf_ptr = gen_fprf_buf;
282 static always_inline void gen_update_nip (DisasContext *ctx, target_ulong nip)
284 #if defined(TARGET_PPC64)
286 tcg_gen_movi_tl(cpu_nip, nip);
289 tcg_gen_movi_tl(cpu_nip, (uint32_t)nip);
292 #define GEN_EXCP(ctx, excp, error) \
294 if ((ctx)->exception == POWERPC_EXCP_NONE) { \
295 gen_update_nip(ctx, (ctx)->nip); \
297 gen_op_raise_exception_err((excp), (error)); \
298 ctx->exception = (excp); \
301 #define GEN_EXCP_INVAL(ctx) \
302 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
303 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_INVAL)
305 #define GEN_EXCP_PRIVOPC(ctx) \
306 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
307 POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_OPC)
309 #define GEN_EXCP_PRIVREG(ctx) \
310 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
311 POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_REG)
313 #define GEN_EXCP_NO_FP(ctx) \
314 GEN_EXCP(ctx, POWERPC_EXCP_FPU, 0)
316 #define GEN_EXCP_NO_AP(ctx) \
317 GEN_EXCP(ctx, POWERPC_EXCP_APU, 0)
319 #define GEN_EXCP_NO_VR(ctx) \
320 GEN_EXCP(ctx, POWERPC_EXCP_VPU, 0)
322 /* Stop translation */
323 static always_inline void GEN_STOP (DisasContext *ctx)
325 gen_update_nip(ctx, ctx->nip);
326 ctx->exception = POWERPC_EXCP_STOP;
329 /* No need to update nip here, as execution flow will change */
330 static always_inline void GEN_SYNC (DisasContext *ctx)
332 ctx->exception = POWERPC_EXCP_SYNC;
335 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
336 static void gen_##name (DisasContext *ctx); \
337 GEN_OPCODE(name, opc1, opc2, opc3, inval, type); \
338 static void gen_##name (DisasContext *ctx)
340 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
341 static void gen_##name (DisasContext *ctx); \
342 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type); \
343 static void gen_##name (DisasContext *ctx)
345 typedef struct opcode_t {
346 unsigned char opc1, opc2, opc3;
347 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
348 unsigned char pad[5];
350 unsigned char pad[1];
352 opc_handler_t handler;
356 /*****************************************************************************/
357 /*** Instruction decoding ***/
358 #define EXTRACT_HELPER(name, shift, nb) \
359 static always_inline uint32_t name (uint32_t opcode) \
361 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
364 #define EXTRACT_SHELPER(name, shift, nb) \
365 static always_inline int32_t name (uint32_t opcode) \
367 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
371 EXTRACT_HELPER(opc1, 26, 6);
373 EXTRACT_HELPER(opc2, 1, 5);
375 EXTRACT_HELPER(opc3, 6, 5);
376 /* Update Cr0 flags */
377 EXTRACT_HELPER(Rc, 0, 1);
379 EXTRACT_HELPER(rD, 21, 5);
381 EXTRACT_HELPER(rS, 21, 5);
383 EXTRACT_HELPER(rA, 16, 5);
385 EXTRACT_HELPER(rB, 11, 5);
387 EXTRACT_HELPER(rC, 6, 5);
389 EXTRACT_HELPER(crfD, 23, 3);
390 EXTRACT_HELPER(crfS, 18, 3);
391 EXTRACT_HELPER(crbD, 21, 5);
392 EXTRACT_HELPER(crbA, 16, 5);
393 EXTRACT_HELPER(crbB, 11, 5);
395 EXTRACT_HELPER(_SPR, 11, 10);
396 static always_inline uint32_t SPR (uint32_t opcode)
398 uint32_t sprn = _SPR(opcode);
400 return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
402 /*** Get constants ***/
403 EXTRACT_HELPER(IMM, 12, 8);
404 /* 16 bits signed immediate value */
405 EXTRACT_SHELPER(SIMM, 0, 16);
406 /* 16 bits unsigned immediate value */
407 EXTRACT_HELPER(UIMM, 0, 16);
409 EXTRACT_HELPER(NB, 11, 5);
411 EXTRACT_HELPER(SH, 11, 5);
413 EXTRACT_HELPER(MB, 6, 5);
415 EXTRACT_HELPER(ME, 1, 5);
417 EXTRACT_HELPER(TO, 21, 5);
419 EXTRACT_HELPER(CRM, 12, 8);
420 EXTRACT_HELPER(FM, 17, 8);
421 EXTRACT_HELPER(SR, 16, 4);
422 EXTRACT_HELPER(FPIMM, 12, 4);
424 /*** Jump target decoding ***/
426 EXTRACT_SHELPER(d, 0, 16);
427 /* Immediate address */
428 static always_inline target_ulong LI (uint32_t opcode)
430 return (opcode >> 0) & 0x03FFFFFC;
433 static always_inline uint32_t BD (uint32_t opcode)
435 return (opcode >> 0) & 0xFFFC;
438 EXTRACT_HELPER(BO, 21, 5);
439 EXTRACT_HELPER(BI, 16, 5);
440 /* Absolute/relative address */
441 EXTRACT_HELPER(AA, 1, 1);
443 EXTRACT_HELPER(LK, 0, 1);
445 /* Create a mask between <start> and <end> bits */
446 static always_inline target_ulong MASK (uint32_t start, uint32_t end)
450 #if defined(TARGET_PPC64)
451 if (likely(start == 0)) {
452 ret = UINT64_MAX << (63 - end);
453 } else if (likely(end == 63)) {
454 ret = UINT64_MAX >> start;
457 if (likely(start == 0)) {
458 ret = UINT32_MAX << (31 - end);
459 } else if (likely(end == 31)) {
460 ret = UINT32_MAX >> start;
464 ret = (((target_ulong)(-1ULL)) >> (start)) ^
465 (((target_ulong)(-1ULL) >> (end)) >> 1);
466 if (unlikely(start > end))
473 /*****************************************************************************/
474 /* PowerPC Instructions types definitions */
476 PPC_NONE = 0x0000000000000000ULL,
477 /* PowerPC base instructions set */
478 PPC_INSNS_BASE = 0x0000000000000001ULL,
479 /* integer operations instructions */
480 #define PPC_INTEGER PPC_INSNS_BASE
481 /* flow control instructions */
482 #define PPC_FLOW PPC_INSNS_BASE
483 /* virtual memory instructions */
484 #define PPC_MEM PPC_INSNS_BASE
485 /* ld/st with reservation instructions */
486 #define PPC_RES PPC_INSNS_BASE
487 /* spr/msr access instructions */
488 #define PPC_MISC PPC_INSNS_BASE
489 /* Deprecated instruction sets */
490 /* Original POWER instruction set */
491 PPC_POWER = 0x0000000000000002ULL,
492 /* POWER2 instruction set extension */
493 PPC_POWER2 = 0x0000000000000004ULL,
494 /* Power RTC support */
495 PPC_POWER_RTC = 0x0000000000000008ULL,
496 /* Power-to-PowerPC bridge (601) */
497 PPC_POWER_BR = 0x0000000000000010ULL,
498 /* 64 bits PowerPC instruction set */
499 PPC_64B = 0x0000000000000020ULL,
500 /* New 64 bits extensions (PowerPC 2.0x) */
501 PPC_64BX = 0x0000000000000040ULL,
502 /* 64 bits hypervisor extensions */
503 PPC_64H = 0x0000000000000080ULL,
504 /* New wait instruction (PowerPC 2.0x) */
505 PPC_WAIT = 0x0000000000000100ULL,
506 /* Time base mftb instruction */
507 PPC_MFTB = 0x0000000000000200ULL,
509 /* Fixed-point unit extensions */
510 /* PowerPC 602 specific */
511 PPC_602_SPEC = 0x0000000000000400ULL,
512 /* isel instruction */
513 PPC_ISEL = 0x0000000000000800ULL,
514 /* popcntb instruction */
515 PPC_POPCNTB = 0x0000000000001000ULL,
516 /* string load / store */
517 PPC_STRING = 0x0000000000002000ULL,
519 /* Floating-point unit extensions */
520 /* Optional floating point instructions */
521 PPC_FLOAT = 0x0000000000010000ULL,
522 /* New floating-point extensions (PowerPC 2.0x) */
523 PPC_FLOAT_EXT = 0x0000000000020000ULL,
524 PPC_FLOAT_FSQRT = 0x0000000000040000ULL,
525 PPC_FLOAT_FRES = 0x0000000000080000ULL,
526 PPC_FLOAT_FRSQRTE = 0x0000000000100000ULL,
527 PPC_FLOAT_FRSQRTES = 0x0000000000200000ULL,
528 PPC_FLOAT_FSEL = 0x0000000000400000ULL,
529 PPC_FLOAT_STFIWX = 0x0000000000800000ULL,
531 /* Vector/SIMD extensions */
532 /* Altivec support */
533 PPC_ALTIVEC = 0x0000000001000000ULL,
534 /* PowerPC 2.03 SPE extension */
535 PPC_SPE = 0x0000000002000000ULL,
536 /* PowerPC 2.03 SPE floating-point extension */
537 PPC_SPEFPU = 0x0000000004000000ULL,
539 /* Optional memory control instructions */
540 PPC_MEM_TLBIA = 0x0000000010000000ULL,
541 PPC_MEM_TLBIE = 0x0000000020000000ULL,
542 PPC_MEM_TLBSYNC = 0x0000000040000000ULL,
543 /* sync instruction */
544 PPC_MEM_SYNC = 0x0000000080000000ULL,
545 /* eieio instruction */
546 PPC_MEM_EIEIO = 0x0000000100000000ULL,
548 /* Cache control instructions */
549 PPC_CACHE = 0x0000000200000000ULL,
550 /* icbi instruction */
551 PPC_CACHE_ICBI = 0x0000000400000000ULL,
552 /* dcbz instruction with fixed cache line size */
553 PPC_CACHE_DCBZ = 0x0000000800000000ULL,
554 /* dcbz instruction with tunable cache line size */
555 PPC_CACHE_DCBZT = 0x0000001000000000ULL,
556 /* dcba instruction */
557 PPC_CACHE_DCBA = 0x0000002000000000ULL,
558 /* Freescale cache locking instructions */
559 PPC_CACHE_LOCK = 0x0000004000000000ULL,
561 /* MMU related extensions */
562 /* external control instructions */
563 PPC_EXTERN = 0x0000010000000000ULL,
564 /* segment register access instructions */
565 PPC_SEGMENT = 0x0000020000000000ULL,
566 /* PowerPC 6xx TLB management instructions */
567 PPC_6xx_TLB = 0x0000040000000000ULL,
568 /* PowerPC 74xx TLB management instructions */
569 PPC_74xx_TLB = 0x0000080000000000ULL,
570 /* PowerPC 40x TLB management instructions */
571 PPC_40x_TLB = 0x0000100000000000ULL,
572 /* segment register access instructions for PowerPC 64 "bridge" */
573 PPC_SEGMENT_64B = 0x0000200000000000ULL,
575 PPC_SLBI = 0x0000400000000000ULL,
577 /* Embedded PowerPC dedicated instructions */
578 PPC_WRTEE = 0x0001000000000000ULL,
579 /* PowerPC 40x exception model */
580 PPC_40x_EXCP = 0x0002000000000000ULL,
581 /* PowerPC 405 Mac instructions */
582 PPC_405_MAC = 0x0004000000000000ULL,
583 /* PowerPC 440 specific instructions */
584 PPC_440_SPEC = 0x0008000000000000ULL,
585 /* BookE (embedded) PowerPC specification */
586 PPC_BOOKE = 0x0010000000000000ULL,
587 /* mfapidi instruction */
588 PPC_MFAPIDI = 0x0020000000000000ULL,
589 /* tlbiva instruction */
590 PPC_TLBIVA = 0x0040000000000000ULL,
591 /* tlbivax instruction */
592 PPC_TLBIVAX = 0x0080000000000000ULL,
593 /* PowerPC 4xx dedicated instructions */
594 PPC_4xx_COMMON = 0x0100000000000000ULL,
595 /* PowerPC 40x ibct instructions */
596 PPC_40x_ICBT = 0x0200000000000000ULL,
597 /* rfmci is not implemented in all BookE PowerPC */
598 PPC_RFMCI = 0x0400000000000000ULL,
599 /* rfdi instruction */
600 PPC_RFDI = 0x0800000000000000ULL,
602 PPC_DCR = 0x1000000000000000ULL,
603 /* DCR extended accesse */
604 PPC_DCRX = 0x2000000000000000ULL,
605 /* user-mode DCR access, implemented in PowerPC 460 */
606 PPC_DCRUX = 0x4000000000000000ULL,
609 /*****************************************************************************/
610 /* PowerPC instructions table */
611 #if HOST_LONG_BITS == 64
616 #if defined(__APPLE__)
617 #define OPCODES_SECTION \
618 __attribute__ ((section("__TEXT,__opcodes"), unused, aligned (OPC_ALIGN) ))
620 #define OPCODES_SECTION \
621 __attribute__ ((section(".opcodes"), unused, aligned (OPC_ALIGN) ))
624 #if defined(DO_PPC_STATISTICS)
625 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
626 OPCODES_SECTION opcode_t opc_##name = { \
634 .handler = &gen_##name, \
635 .oname = stringify(name), \
637 .oname = stringify(name), \
639 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
640 OPCODES_SECTION opcode_t opc_##name = { \
648 .handler = &gen_##name, \
654 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
655 OPCODES_SECTION opcode_t opc_##name = { \
663 .handler = &gen_##name, \
665 .oname = stringify(name), \
667 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
668 OPCODES_SECTION opcode_t opc_##name = { \
676 .handler = &gen_##name, \
682 #define GEN_OPCODE_MARK(name) \
683 OPCODES_SECTION opcode_t opc_##name = { \
689 .inval = 0x00000000, \
693 .oname = stringify(name), \
696 /* Start opcode list */
697 GEN_OPCODE_MARK(start);
699 /* Invalid instruction */
700 GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE)
705 static opc_handler_t invalid_handler = {
708 .handler = gen_invalid,
711 /*** Integer arithmetic ***/
712 #define __GEN_INT_ARITH2(name, opc1, opc2, opc3, inval, type) \
713 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
715 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]); \
716 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]); \
718 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]); \
719 if (unlikely(Rc(ctx->opcode) != 0)) \
723 #define __GEN_INT_ARITH2_O(name, opc1, opc2, opc3, inval, type) \
724 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
726 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]); \
727 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]); \
729 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]); \
730 if (unlikely(Rc(ctx->opcode) != 0)) \
734 #define __GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
735 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
737 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]); \
739 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]); \
740 if (unlikely(Rc(ctx->opcode) != 0)) \
743 #define __GEN_INT_ARITH1_O(name, opc1, opc2, opc3, type) \
744 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
746 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]); \
748 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]); \
749 if (unlikely(Rc(ctx->opcode) != 0)) \
753 /* Two operands arithmetic functions */
754 #define GEN_INT_ARITH2(name, opc1, opc2, opc3, type) \
755 __GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000000, type) \
756 __GEN_INT_ARITH2_O(name##o, opc1, opc2, opc3 | 0x10, 0x00000000, type)
758 /* Two operands arithmetic functions with no overflow allowed */
759 #define GEN_INT_ARITHN(name, opc1, opc2, opc3, type) \
760 __GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000400, type)
762 /* One operand arithmetic functions */
763 #define GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
764 __GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
765 __GEN_INT_ARITH1_O(name##o, opc1, opc2, opc3 | 0x10, type)
767 #if defined(TARGET_PPC64)
768 #define __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, inval, type) \
769 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
771 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]); \
772 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]); \
774 gen_op_##name##_64(); \
777 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]); \
778 if (unlikely(Rc(ctx->opcode) != 0)) \
782 #define __GEN_INT_ARITH2_O_64(name, opc1, opc2, opc3, inval, type) \
783 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
785 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]); \
786 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]); \
788 gen_op_##name##_64(); \
791 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]); \
792 if (unlikely(Rc(ctx->opcode) != 0)) \
796 #define __GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
797 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
799 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]); \
801 gen_op_##name##_64(); \
804 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]); \
805 if (unlikely(Rc(ctx->opcode) != 0)) \
808 #define __GEN_INT_ARITH1_O_64(name, opc1, opc2, opc3, type) \
809 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
811 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]); \
813 gen_op_##name##_64(); \
816 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]); \
817 if (unlikely(Rc(ctx->opcode) != 0)) \
821 /* Two operands arithmetic functions */
822 #define GEN_INT_ARITH2_64(name, opc1, opc2, opc3, type) \
823 __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, 0x00000000, type) \
824 __GEN_INT_ARITH2_O_64(name##o, opc1, opc2, opc3 | 0x10, 0x00000000, type)
826 /* Two operands arithmetic functions with no overflow allowed */
827 #define GEN_INT_ARITHN_64(name, opc1, opc2, opc3, type) \
828 __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, 0x00000400, type)
830 /* One operand arithmetic functions */
831 #define GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
832 __GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
833 __GEN_INT_ARITH1_O_64(name##o, opc1, opc2, opc3 | 0x10, type)
835 #define GEN_INT_ARITH2_64 GEN_INT_ARITH2
836 #define GEN_INT_ARITHN_64 GEN_INT_ARITHN
837 #define GEN_INT_ARITH1_64 GEN_INT_ARITH1
840 /* add add. addo addo. */
841 static always_inline void gen_op_add (void)
843 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
845 static always_inline void gen_op_addo (void)
847 tcg_gen_mov_tl(cpu_T[2], cpu_T[0]);
848 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
851 #if defined(TARGET_PPC64)
852 #define gen_op_add_64 gen_op_add
853 static always_inline void gen_op_addo_64 (void)
855 tcg_gen_mov_tl(cpu_T[2], cpu_T[0]);
856 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
857 gen_op_check_addo_64();
860 GEN_INT_ARITH2_64 (add, 0x1F, 0x0A, 0x08, PPC_INTEGER);
861 /* addc addc. addco addco. */
862 static always_inline void gen_op_addc (void)
864 tcg_gen_mov_tl(cpu_T[2], cpu_T[0]);
865 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
868 static always_inline void gen_op_addco (void)
870 tcg_gen_mov_tl(cpu_T[2], cpu_T[0]);
871 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
875 #if defined(TARGET_PPC64)
876 static always_inline void gen_op_addc_64 (void)
878 tcg_gen_mov_tl(cpu_T[2], cpu_T[0]);
879 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
880 gen_op_check_addc_64();
882 static always_inline void gen_op_addco_64 (void)
884 tcg_gen_mov_tl(cpu_T[2], cpu_T[0]);
885 tcg_gen_add_tl(cpu_T[0], cpu_T[0], cpu_T[1]);
886 gen_op_check_addc_64();
887 gen_op_check_addo_64();
890 GEN_INT_ARITH2_64 (addc, 0x1F, 0x0A, 0x00, PPC_INTEGER);
891 /* adde adde. addeo addeo. */
892 static always_inline void gen_op_addeo (void)
894 tcg_gen_mov_tl(cpu_T[2], cpu_T[0]);
898 #if defined(TARGET_PPC64)
899 static always_inline void gen_op_addeo_64 (void)
901 tcg_gen_mov_tl(cpu_T[2], cpu_T[0]);
903 gen_op_check_addo_64();
906 GEN_INT_ARITH2_64 (adde, 0x1F, 0x0A, 0x04, PPC_INTEGER);
907 /* addme addme. addmeo addmeo. */
908 static always_inline void gen_op_addme (void)
910 tcg_gen_mov_tl(cpu_T[1], cpu_T[0]);
913 #if defined(TARGET_PPC64)
914 static always_inline void gen_op_addme_64 (void)
916 tcg_gen_mov_tl(cpu_T[1], cpu_T[0]);
920 GEN_INT_ARITH1_64 (addme, 0x1F, 0x0A, 0x07, PPC_INTEGER);
921 /* addze addze. addzeo addzeo. */
922 static always_inline void gen_op_addze (void)
924 tcg_gen_mov_tl(cpu_T[2], cpu_T[0]);
928 static always_inline void gen_op_addzeo (void)
930 tcg_gen_mov_tl(cpu_T[2], cpu_T[0]);
935 #if defined(TARGET_PPC64)
936 static always_inline void gen_op_addze_64 (void)
938 tcg_gen_mov_tl(cpu_T[2], cpu_T[0]);
940 gen_op_check_addc_64();
942 static always_inline void gen_op_addzeo_64 (void)
944 tcg_gen_mov_tl(cpu_T[2], cpu_T[0]);
946 gen_op_check_addc_64();
947 gen_op_check_addo_64();
950 GEN_INT_ARITH1_64 (addze, 0x1F, 0x0A, 0x06, PPC_INTEGER);
951 /* divw divw. divwo divwo. */
952 GEN_INT_ARITH2 (divw, 0x1F, 0x0B, 0x0F, PPC_INTEGER);
953 /* divwu divwu. divwuo divwuo. */
954 GEN_INT_ARITH2 (divwu, 0x1F, 0x0B, 0x0E, PPC_INTEGER);
956 GEN_INT_ARITHN (mulhw, 0x1F, 0x0B, 0x02, PPC_INTEGER);
958 GEN_INT_ARITHN (mulhwu, 0x1F, 0x0B, 0x00, PPC_INTEGER);
959 /* mullw mullw. mullwo mullwo. */
960 GEN_INT_ARITH2 (mullw, 0x1F, 0x0B, 0x07, PPC_INTEGER);
961 /* neg neg. nego nego. */
962 GEN_INT_ARITH1_64 (neg, 0x1F, 0x08, 0x03, PPC_INTEGER);
963 /* subf subf. subfo subfo. */
964 static always_inline void gen_op_subf (void)
966 tcg_gen_sub_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
968 static always_inline void gen_op_subfo (void)
970 tcg_gen_not_tl(cpu_T[2], cpu_T[0]);
971 tcg_gen_sub_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
974 #if defined(TARGET_PPC64)
975 #define gen_op_subf_64 gen_op_subf
976 static always_inline void gen_op_subfo_64 (void)
978 tcg_gen_not_i64(cpu_T[2], cpu_T[0]);
979 tcg_gen_sub_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
980 gen_op_check_addo_64();
983 GEN_INT_ARITH2_64 (subf, 0x1F, 0x08, 0x01, PPC_INTEGER);
984 /* subfc subfc. subfco subfco. */
985 static always_inline void gen_op_subfc (void)
987 tcg_gen_sub_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
988 gen_op_check_subfc();
990 static always_inline void gen_op_subfco (void)
992 tcg_gen_not_tl(cpu_T[2], cpu_T[0]);
993 tcg_gen_sub_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
994 gen_op_check_subfc();
997 #if defined(TARGET_PPC64)
998 static always_inline void gen_op_subfc_64 (void)
1000 tcg_gen_sub_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
1001 gen_op_check_subfc_64();
1003 static always_inline void gen_op_subfco_64 (void)
1005 tcg_gen_not_i64(cpu_T[2], cpu_T[0]);
1006 tcg_gen_sub_tl(cpu_T[0], cpu_T[1], cpu_T[0]);
1007 gen_op_check_subfc_64();
1008 gen_op_check_addo_64();
1011 GEN_INT_ARITH2_64 (subfc, 0x1F, 0x08, 0x00, PPC_INTEGER);
1012 /* subfe subfe. subfeo subfeo. */
1013 static always_inline void gen_op_subfeo (void)
1015 tcg_gen_not_tl(cpu_T[2], cpu_T[0]);
1017 gen_op_check_addo();
1019 #if defined(TARGET_PPC64)
1020 #define gen_op_subfe_64 gen_op_subfe
1021 static always_inline void gen_op_subfeo_64 (void)
1023 tcg_gen_not_i64(cpu_T[2], cpu_T[0]);
1025 gen_op_check_addo_64();
1028 GEN_INT_ARITH2_64 (subfe, 0x1F, 0x08, 0x04, PPC_INTEGER);
1029 /* subfme subfme. subfmeo subfmeo. */
1030 GEN_INT_ARITH1_64 (subfme, 0x1F, 0x08, 0x07, PPC_INTEGER);
1031 /* subfze subfze. subfzeo subfzeo. */
1032 GEN_INT_ARITH1_64 (subfze, 0x1F, 0x08, 0x06, PPC_INTEGER);
1034 GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1036 target_long simm = SIMM(ctx->opcode);
1038 if (rA(ctx->opcode) == 0) {
1040 tcg_gen_movi_tl(cpu_T[0], simm);
1042 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
1043 if (likely(simm != 0))
1044 tcg_gen_addi_tl(cpu_T[0], cpu_T[0], simm);
1046 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
1049 GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1051 target_long simm = SIMM(ctx->opcode);
1053 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
1054 if (likely(simm != 0)) {
1055 tcg_gen_mov_tl(cpu_T[2], cpu_T[0]);
1056 tcg_gen_addi_tl(cpu_T[0], cpu_T[0], simm);
1057 #if defined(TARGET_PPC64)
1059 gen_op_check_addc_64();
1062 gen_op_check_addc();
1064 tcg_gen_andi_i32(cpu_xer, cpu_xer, ~(1 << XER_CA));
1066 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
1069 GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1071 target_long simm = SIMM(ctx->opcode);
1073 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
1074 if (likely(simm != 0)) {
1075 tcg_gen_mov_tl(cpu_T[2], cpu_T[0]);
1076 tcg_gen_addi_tl(cpu_T[0], cpu_T[0], simm);
1077 #if defined(TARGET_PPC64)
1079 gen_op_check_addc_64();
1082 gen_op_check_addc();
1084 tcg_gen_andi_i32(cpu_xer, cpu_xer, ~(1 << XER_CA));
1086 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
1090 GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1092 target_long simm = SIMM(ctx->opcode);
1094 if (rA(ctx->opcode) == 0) {
1096 tcg_gen_movi_tl(cpu_T[0], simm << 16);
1098 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
1099 if (likely(simm != 0))
1100 tcg_gen_addi_tl(cpu_T[0], cpu_T[0], simm << 16);
1102 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
1105 GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1107 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
1108 gen_op_mulli(SIMM(ctx->opcode));
1109 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
1112 GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1114 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
1115 #if defined(TARGET_PPC64)
1117 gen_op_subfic_64(SIMM(ctx->opcode));
1120 gen_op_subfic(SIMM(ctx->opcode));
1121 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
1124 #if defined(TARGET_PPC64)
1126 GEN_INT_ARITHN (mulhd, 0x1F, 0x09, 0x02, PPC_64B);
1127 /* mulhdu mulhdu. */
1128 GEN_INT_ARITHN (mulhdu, 0x1F, 0x09, 0x00, PPC_64B);
1129 /* mulld mulld. mulldo mulldo. */
1130 GEN_INT_ARITH2 (mulld, 0x1F, 0x09, 0x07, PPC_64B);
1131 /* divd divd. divdo divdo. */
1132 GEN_INT_ARITH2 (divd, 0x1F, 0x09, 0x0F, PPC_64B);
1133 /* divdu divdu. divduo divduo. */
1134 GEN_INT_ARITH2 (divdu, 0x1F, 0x09, 0x0E, PPC_64B);
1137 /*** Integer comparison ***/
1138 #if defined(TARGET_PPC64)
1139 #define GEN_CMP(name, opc, type) \
1140 GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, type) \
1142 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]); \
1143 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]); \
1144 if (ctx->sf_mode && (ctx->opcode & 0x00200000)) \
1145 gen_op_##name##_64(); \
1148 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_T[0], 0xf); \
1151 #define GEN_CMP(name, opc, type) \
1152 GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, type) \
1154 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]); \
1155 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]); \
1157 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_T[0], 0xf); \
1162 GEN_CMP(cmp, 0x00, PPC_INTEGER);
1164 GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER)
1166 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
1167 #if defined(TARGET_PPC64)
1168 if (ctx->sf_mode && (ctx->opcode & 0x00200000))
1169 gen_op_cmpi_64(SIMM(ctx->opcode));
1172 gen_op_cmpi(SIMM(ctx->opcode));
1173 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_T[0], 0xf);
1176 GEN_CMP(cmpl, 0x01, PPC_INTEGER);
1178 GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER)
1180 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
1181 #if defined(TARGET_PPC64)
1182 if (ctx->sf_mode && (ctx->opcode & 0x00200000))
1183 gen_op_cmpli_64(UIMM(ctx->opcode));
1186 gen_op_cmpli(UIMM(ctx->opcode));
1187 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_T[0], 0xf);
1190 /* isel (PowerPC 2.03 specification) */
1191 GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL)
1193 uint32_t bi = rC(ctx->opcode);
1196 if (rA(ctx->opcode) == 0) {
1197 tcg_gen_movi_tl(cpu_T[0], 0);
1199 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rA(ctx->opcode)]);
1201 tcg_gen_mov_tl(cpu_T[2], cpu_gpr[rB(ctx->opcode)]);
1202 mask = 1 << (3 - (bi & 0x03));
1203 tcg_gen_mov_i32(cpu_T[0], cpu_crf[bi >> 2]);
1204 gen_op_test_true(mask);
1206 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
1209 /*** Integer logical ***/
1210 #define __GEN_LOGICAL2(name, opc2, opc3, type) \
1211 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000000, type) \
1213 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]); \
1214 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]); \
1216 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
1217 if (unlikely(Rc(ctx->opcode) != 0)) \
1220 #define GEN_LOGICAL2(name, opc, type) \
1221 __GEN_LOGICAL2(name, 0x1C, opc, type)
1223 #define GEN_LOGICAL1(name, opc, type) \
1224 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type) \
1226 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]); \
1228 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
1229 if (unlikely(Rc(ctx->opcode) != 0)) \
1234 GEN_LOGICAL2(and, 0x00, PPC_INTEGER);
1236 GEN_LOGICAL2(andc, 0x01, PPC_INTEGER);
1238 GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1240 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
1241 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], UIMM(ctx->opcode));
1242 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
1246 GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1248 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
1249 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], UIMM(ctx->opcode) << 16);
1250 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
1255 GEN_LOGICAL1(cntlzw, 0x00, PPC_INTEGER);
1257 GEN_LOGICAL2(eqv, 0x08, PPC_INTEGER);
1258 /* extsb & extsb. */
1259 GEN_LOGICAL1(extsb, 0x1D, PPC_INTEGER);
1260 /* extsh & extsh. */
1261 GEN_LOGICAL1(extsh, 0x1C, PPC_INTEGER);
1263 GEN_LOGICAL2(nand, 0x0E, PPC_INTEGER);
1265 GEN_LOGICAL2(nor, 0x03, PPC_INTEGER);
1268 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER)
1272 rs = rS(ctx->opcode);
1273 ra = rA(ctx->opcode);
1274 rb = rB(ctx->opcode);
1275 /* Optimisation for mr. ri case */
1276 if (rs != ra || rs != rb) {
1277 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rs]);
1279 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rb]);
1282 tcg_gen_mov_tl(cpu_gpr[ra], cpu_T[0]);
1283 if (unlikely(Rc(ctx->opcode) != 0))
1285 } else if (unlikely(Rc(ctx->opcode) != 0)) {
1286 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rs]);
1288 #if defined(TARGET_PPC64)
1292 /* Set process priority to low */
1293 gen_op_store_pri(2);
1296 /* Set process priority to medium-low */
1297 gen_op_store_pri(3);
1300 /* Set process priority to normal */
1301 gen_op_store_pri(4);
1303 #if !defined(CONFIG_USER_ONLY)
1305 if (ctx->supervisor > 0) {
1306 /* Set process priority to very low */
1307 gen_op_store_pri(1);
1311 if (ctx->supervisor > 0) {
1312 /* Set process priority to medium-hight */
1313 gen_op_store_pri(5);
1317 if (ctx->supervisor > 0) {
1318 /* Set process priority to high */
1319 gen_op_store_pri(6);
1323 if (ctx->supervisor > 1) {
1324 /* Set process priority to very high */
1325 gen_op_store_pri(7);
1338 GEN_LOGICAL2(orc, 0x0C, PPC_INTEGER);
1340 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER)
1342 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
1343 /* Optimisation for "set to zero" case */
1344 if (rS(ctx->opcode) != rB(ctx->opcode)) {
1345 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
1348 tcg_gen_movi_tl(cpu_T[0], 0);
1350 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
1351 if (unlikely(Rc(ctx->opcode) != 0))
1355 GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1357 target_ulong uimm = UIMM(ctx->opcode);
1359 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1361 /* XXX: should handle special NOPs for POWER series */
1364 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
1365 if (likely(uimm != 0))
1367 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
1370 GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1372 target_ulong uimm = UIMM(ctx->opcode);
1374 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1378 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
1379 if (likely(uimm != 0))
1380 gen_op_ori(uimm << 16);
1381 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
1384 GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1386 target_ulong uimm = UIMM(ctx->opcode);
1388 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1392 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
1393 if (likely(uimm != 0))
1395 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
1399 GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1401 target_ulong uimm = UIMM(ctx->opcode);
1403 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1407 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
1408 if (likely(uimm != 0))
1409 gen_op_xori(uimm << 16);
1410 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
1413 /* popcntb : PowerPC 2.03 specification */
1414 GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB)
1416 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
1417 #if defined(TARGET_PPC64)
1419 gen_op_popcntb_64();
1423 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
1426 #if defined(TARGET_PPC64)
1427 /* extsw & extsw. */
1428 GEN_LOGICAL1(extsw, 0x1E, PPC_64B);
1430 GEN_LOGICAL1(cntlzd, 0x01, PPC_64B);
1433 /*** Integer rotate ***/
1434 /* rlwimi & rlwimi. */
1435 GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1438 uint32_t mb, me, sh;
1440 mb = MB(ctx->opcode);
1441 me = ME(ctx->opcode);
1442 sh = SH(ctx->opcode);
1443 if (likely(sh == 0)) {
1444 if (likely(mb == 0 && me == 31)) {
1445 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
1447 } else if (likely(mb == 31 && me == 0)) {
1448 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
1451 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
1452 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rA(ctx->opcode)]);
1455 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
1456 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rA(ctx->opcode)]);
1457 gen_op_rotli32_T0(SH(ctx->opcode));
1459 #if defined(TARGET_PPC64)
1463 mask = MASK(mb, me);
1464 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], mask);
1465 tcg_gen_andi_tl(cpu_T[1], cpu_T[1], ~mask);
1468 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
1469 if (unlikely(Rc(ctx->opcode) != 0))
1472 /* rlwinm & rlwinm. */
1473 GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1475 uint32_t mb, me, sh;
1477 sh = SH(ctx->opcode);
1478 mb = MB(ctx->opcode);
1479 me = ME(ctx->opcode);
1480 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
1481 if (likely(sh == 0)) {
1484 if (likely(mb == 0)) {
1485 if (likely(me == 31)) {
1486 gen_op_rotli32_T0(sh);
1488 } else if (likely(me == (31 - sh))) {
1492 } else if (likely(me == 31)) {
1493 if (likely(sh == (32 - mb))) {
1498 gen_op_rotli32_T0(sh);
1500 #if defined(TARGET_PPC64)
1504 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], MASK(mb, me));
1506 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
1507 if (unlikely(Rc(ctx->opcode) != 0))
1510 /* rlwnm & rlwnm. */
1511 GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1515 mb = MB(ctx->opcode);
1516 me = ME(ctx->opcode);
1517 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
1518 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
1519 gen_op_rotl32_T0_T1();
1520 if (unlikely(mb != 0 || me != 31)) {
1521 #if defined(TARGET_PPC64)
1525 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], MASK(mb, me));
1527 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
1528 if (unlikely(Rc(ctx->opcode) != 0))
1532 #if defined(TARGET_PPC64)
1533 #define GEN_PPC64_R2(name, opc1, opc2) \
1534 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1536 gen_##name(ctx, 0); \
1538 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1541 gen_##name(ctx, 1); \
1543 #define GEN_PPC64_R4(name, opc1, opc2) \
1544 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1546 gen_##name(ctx, 0, 0); \
1548 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
1551 gen_##name(ctx, 0, 1); \
1553 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1556 gen_##name(ctx, 1, 0); \
1558 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
1561 gen_##name(ctx, 1, 1); \
1564 static always_inline void gen_rldinm (DisasContext *ctx, uint32_t mb,
1565 uint32_t me, uint32_t sh)
1567 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
1568 if (likely(sh == 0)) {
1571 if (likely(mb == 0)) {
1572 if (likely(me == 63)) {
1573 gen_op_rotli64_T0(sh);
1575 } else if (likely(me == (63 - sh))) {
1579 } else if (likely(me == 63)) {
1580 if (likely(sh == (64 - mb))) {
1581 gen_op_srli_T0_64(mb);
1585 gen_op_rotli64_T0(sh);
1587 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], MASK(mb, me));
1589 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
1590 if (unlikely(Rc(ctx->opcode) != 0))
1593 /* rldicl - rldicl. */
1594 static always_inline void gen_rldicl (DisasContext *ctx, int mbn, int shn)
1598 sh = SH(ctx->opcode) | (shn << 5);
1599 mb = MB(ctx->opcode) | (mbn << 5);
1600 gen_rldinm(ctx, mb, 63, sh);
1602 GEN_PPC64_R4(rldicl, 0x1E, 0x00);
1603 /* rldicr - rldicr. */
1604 static always_inline void gen_rldicr (DisasContext *ctx, int men, int shn)
1608 sh = SH(ctx->opcode) | (shn << 5);
1609 me = MB(ctx->opcode) | (men << 5);
1610 gen_rldinm(ctx, 0, me, sh);
1612 GEN_PPC64_R4(rldicr, 0x1E, 0x02);
1613 /* rldic - rldic. */
1614 static always_inline void gen_rldic (DisasContext *ctx, int mbn, int shn)
1618 sh = SH(ctx->opcode) | (shn << 5);
1619 mb = MB(ctx->opcode) | (mbn << 5);
1620 gen_rldinm(ctx, mb, 63 - sh, sh);
1622 GEN_PPC64_R4(rldic, 0x1E, 0x04);
1624 static always_inline void gen_rldnm (DisasContext *ctx, uint32_t mb,
1627 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
1628 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
1629 gen_op_rotl64_T0_T1();
1630 if (unlikely(mb != 0 || me != 63)) {
1631 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], MASK(mb, me));
1633 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
1634 if (unlikely(Rc(ctx->opcode) != 0))
1638 /* rldcl - rldcl. */
1639 static always_inline void gen_rldcl (DisasContext *ctx, int mbn)
1643 mb = MB(ctx->opcode) | (mbn << 5);
1644 gen_rldnm(ctx, mb, 63);
1646 GEN_PPC64_R2(rldcl, 0x1E, 0x08);
1647 /* rldcr - rldcr. */
1648 static always_inline void gen_rldcr (DisasContext *ctx, int men)
1652 me = MB(ctx->opcode) | (men << 5);
1653 gen_rldnm(ctx, 0, me);
1655 GEN_PPC64_R2(rldcr, 0x1E, 0x09);
1656 /* rldimi - rldimi. */
1657 static always_inline void gen_rldimi (DisasContext *ctx, int mbn, int shn)
1660 uint32_t sh, mb, me;
1662 sh = SH(ctx->opcode) | (shn << 5);
1663 mb = MB(ctx->opcode) | (mbn << 5);
1665 if (likely(sh == 0)) {
1666 if (likely(mb == 0)) {
1667 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
1670 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
1671 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rA(ctx->opcode)]);
1674 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
1675 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rA(ctx->opcode)]);
1676 gen_op_rotli64_T0(sh);
1678 mask = MASK(mb, me);
1679 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], mask);
1680 tcg_gen_andi_tl(cpu_T[1], cpu_T[1], ~mask);
1683 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
1684 if (unlikely(Rc(ctx->opcode) != 0))
1687 GEN_PPC64_R4(rldimi, 0x1E, 0x06);
1690 /*** Integer shift ***/
1692 __GEN_LOGICAL2(slw, 0x18, 0x00, PPC_INTEGER);
1694 __GEN_LOGICAL2(sraw, 0x18, 0x18, PPC_INTEGER);
1695 /* srawi & srawi. */
1696 GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER)
1699 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
1700 if (SH(ctx->opcode) != 0) {
1701 tcg_gen_mov_tl(cpu_T[1], cpu_T[0]);
1702 mb = 32 - SH(ctx->opcode);
1704 #if defined(TARGET_PPC64)
1708 gen_op_srawi(SH(ctx->opcode), MASK(mb, me));
1710 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
1711 if (unlikely(Rc(ctx->opcode) != 0))
1715 __GEN_LOGICAL2(srw, 0x18, 0x10, PPC_INTEGER);
1717 #if defined(TARGET_PPC64)
1719 __GEN_LOGICAL2(sld, 0x1B, 0x00, PPC_64B);
1721 __GEN_LOGICAL2(srad, 0x1A, 0x18, PPC_64B);
1722 /* sradi & sradi. */
1723 static always_inline void gen_sradi (DisasContext *ctx, int n)
1728 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
1729 sh = SH(ctx->opcode) + (n << 5);
1731 tcg_gen_mov_tl(cpu_T[1], cpu_T[0]);
1732 mb = 64 - SH(ctx->opcode);
1734 mask = MASK(mb, me);
1735 gen_op_sradi(sh, mask >> 32, mask);
1737 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
1738 if (unlikely(Rc(ctx->opcode) != 0))
1741 GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B)
1745 GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B)
1750 __GEN_LOGICAL2(srd, 0x1B, 0x10, PPC_64B);
1753 /*** Floating-Point arithmetic ***/
1754 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
1755 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type) \
1757 if (unlikely(!ctx->fpu_enabled)) { \
1758 GEN_EXCP_NO_FP(ctx); \
1761 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]); \
1762 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rC(ctx->opcode)]); \
1763 tcg_gen_mov_i64(cpu_FT[2], cpu_fpr[rB(ctx->opcode)]); \
1764 gen_reset_fpstatus(); \
1769 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
1770 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
1773 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
1774 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
1775 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
1777 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
1778 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
1780 if (unlikely(!ctx->fpu_enabled)) { \
1781 GEN_EXCP_NO_FP(ctx); \
1784 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]); \
1785 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rB(ctx->opcode)]); \
1786 gen_reset_fpstatus(); \
1791 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
1792 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
1794 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
1795 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
1796 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
1798 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
1799 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
1801 if (unlikely(!ctx->fpu_enabled)) { \
1802 GEN_EXCP_NO_FP(ctx); \
1805 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]); \
1806 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rC(ctx->opcode)]); \
1807 gen_reset_fpstatus(); \
1812 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
1813 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
1815 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
1816 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
1817 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
1819 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
1820 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type) \
1822 if (unlikely(!ctx->fpu_enabled)) { \
1823 GEN_EXCP_NO_FP(ctx); \
1826 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]); \
1827 gen_reset_fpstatus(); \
1829 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
1830 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
1833 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
1834 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type) \
1836 if (unlikely(!ctx->fpu_enabled)) { \
1837 GEN_EXCP_NO_FP(ctx); \
1840 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]); \
1841 gen_reset_fpstatus(); \
1843 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
1844 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
1848 GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT);
1850 GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT);
1852 GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT);
1855 GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT);
1858 GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES);
1861 GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE);
1864 static always_inline void gen_op_frsqrtes (void)
1869 GEN_FLOAT_BS(rsqrtes, 0x3B, 0x1A, 1, PPC_FLOAT_FRSQRTES);
1872 _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL);
1874 GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT);
1877 GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT)
1879 if (unlikely(!ctx->fpu_enabled)) {
1880 GEN_EXCP_NO_FP(ctx);
1883 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]);
1884 gen_reset_fpstatus();
1886 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
1887 gen_compute_fprf(1, Rc(ctx->opcode) != 0);
1890 GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT)
1892 if (unlikely(!ctx->fpu_enabled)) {
1893 GEN_EXCP_NO_FP(ctx);
1896 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]);
1897 gen_reset_fpstatus();
1900 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
1901 gen_compute_fprf(1, Rc(ctx->opcode) != 0);
1904 /*** Floating-Point multiply-and-add ***/
1905 /* fmadd - fmadds */
1906 GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT);
1907 /* fmsub - fmsubs */
1908 GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT);
1909 /* fnmadd - fnmadds */
1910 GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT);
1911 /* fnmsub - fnmsubs */
1912 GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT);
1914 /*** Floating-Point round & convert ***/
1916 GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT);
1918 GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT);
1920 GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT);
1921 #if defined(TARGET_PPC64)
1923 GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B);
1925 GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B);
1927 GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B);
1931 GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT);
1933 GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT);
1935 GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT);
1937 GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT);
1939 /*** Floating-Point compare ***/
1941 GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT)
1943 if (unlikely(!ctx->fpu_enabled)) {
1944 GEN_EXCP_NO_FP(ctx);
1947 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]);
1948 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rB(ctx->opcode)]);
1949 gen_reset_fpstatus();
1951 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_T[0], 0xf);
1952 gen_op_float_check_status();
1956 GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT)
1958 if (unlikely(!ctx->fpu_enabled)) {
1959 GEN_EXCP_NO_FP(ctx);
1962 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]);
1963 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rB(ctx->opcode)]);
1964 gen_reset_fpstatus();
1966 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_T[0], 0xf);
1967 gen_op_float_check_status();
1970 /*** Floating-point move ***/
1972 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
1973 GEN_FLOAT_B(abs, 0x08, 0x08, 0, PPC_FLOAT);
1976 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
1977 GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT)
1979 if (unlikely(!ctx->fpu_enabled)) {
1980 GEN_EXCP_NO_FP(ctx);
1983 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]);
1984 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
1985 gen_compute_fprf(0, Rc(ctx->opcode) != 0);
1989 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
1990 GEN_FLOAT_B(nabs, 0x08, 0x04, 0, PPC_FLOAT);
1992 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
1993 GEN_FLOAT_B(neg, 0x08, 0x01, 0, PPC_FLOAT);
1995 /*** Floating-Point status & ctrl register ***/
1997 GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT)
2001 if (unlikely(!ctx->fpu_enabled)) {
2002 GEN_EXCP_NO_FP(ctx);
2005 gen_optimize_fprf();
2006 bfa = 4 * (7 - crfS(ctx->opcode));
2007 gen_op_load_fpscr_T0(bfa);
2008 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_T[0], 0xf);
2009 gen_op_fpscr_resetbit(~(0xF << bfa));
2013 GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT)
2015 if (unlikely(!ctx->fpu_enabled)) {
2016 GEN_EXCP_NO_FP(ctx);
2019 gen_optimize_fprf();
2020 gen_reset_fpstatus();
2021 gen_op_load_fpscr_FT0();
2022 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
2023 gen_compute_fprf(0, Rc(ctx->opcode) != 0);
2027 GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT)
2031 if (unlikely(!ctx->fpu_enabled)) {
2032 GEN_EXCP_NO_FP(ctx);
2035 crb = 32 - (crbD(ctx->opcode) >> 2);
2036 gen_optimize_fprf();
2037 gen_reset_fpstatus();
2038 if (likely(crb != 30 && crb != 29))
2039 gen_op_fpscr_resetbit(~(1 << crb));
2040 if (unlikely(Rc(ctx->opcode) != 0)) {
2047 GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT)
2051 if (unlikely(!ctx->fpu_enabled)) {
2052 GEN_EXCP_NO_FP(ctx);
2055 crb = 32 - (crbD(ctx->opcode) >> 2);
2056 gen_optimize_fprf();
2057 gen_reset_fpstatus();
2058 /* XXX: we pretend we can only do IEEE floating-point computations */
2059 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI))
2060 gen_op_fpscr_setbit(crb);
2061 if (unlikely(Rc(ctx->opcode) != 0)) {
2065 /* We can raise a differed exception */
2066 gen_op_float_check_status();
2070 GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x02010000, PPC_FLOAT)
2072 if (unlikely(!ctx->fpu_enabled)) {
2073 GEN_EXCP_NO_FP(ctx);
2076 gen_optimize_fprf();
2077 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]);
2078 gen_reset_fpstatus();
2079 gen_op_store_fpscr(FM(ctx->opcode));
2080 if (unlikely(Rc(ctx->opcode) != 0)) {
2084 /* We can raise a differed exception */
2085 gen_op_float_check_status();
2089 GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT)
2093 if (unlikely(!ctx->fpu_enabled)) {
2094 GEN_EXCP_NO_FP(ctx);
2097 bf = crbD(ctx->opcode) >> 2;
2099 gen_optimize_fprf();
2100 tcg_gen_movi_i64(cpu_FT[0], FPIMM(ctx->opcode) << (4 * sh));
2101 gen_reset_fpstatus();
2102 gen_op_store_fpscr(1 << sh);
2103 if (unlikely(Rc(ctx->opcode) != 0)) {
2107 /* We can raise a differed exception */
2108 gen_op_float_check_status();
2111 /*** Addressing modes ***/
2112 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2113 static always_inline void gen_addr_imm_index (TCGv EA,
2117 target_long simm = SIMM(ctx->opcode);
2120 if (rA(ctx->opcode) == 0)
2121 tcg_gen_movi_tl(EA, simm);
2122 else if (likely(simm != 0))
2123 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm);
2125 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2128 static always_inline void gen_addr_reg_index (TCGv EA,
2131 if (rA(ctx->opcode) == 0)
2132 tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2134 tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
2137 static always_inline void gen_addr_register (TCGv EA,
2140 if (rA(ctx->opcode) == 0)
2141 tcg_gen_movi_tl(EA, 0);
2143 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2146 #if defined(TARGET_PPC64)
2147 #define _GEN_MEM_FUNCS(name, mode) \
2148 &gen_op_##name##_##mode, \
2149 &gen_op_##name##_le_##mode, \
2150 &gen_op_##name##_64_##mode, \
2151 &gen_op_##name##_le_64_##mode
2153 #define _GEN_MEM_FUNCS(name, mode) \
2154 &gen_op_##name##_##mode, \
2155 &gen_op_##name##_le_##mode
2157 #if defined(CONFIG_USER_ONLY)
2158 #if defined(TARGET_PPC64)
2159 #define NB_MEM_FUNCS 4
2161 #define NB_MEM_FUNCS 2
2163 #define GEN_MEM_FUNCS(name) \
2164 _GEN_MEM_FUNCS(name, raw)
2166 #if defined(TARGET_PPC64)
2167 #define NB_MEM_FUNCS 12
2169 #define NB_MEM_FUNCS 6
2171 #define GEN_MEM_FUNCS(name) \
2172 _GEN_MEM_FUNCS(name, user), \
2173 _GEN_MEM_FUNCS(name, kernel), \
2174 _GEN_MEM_FUNCS(name, hypv)
2177 /*** Integer load ***/
2178 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
2179 #define OP_LD_TABLE(width) \
2180 static GenOpFunc *gen_op_l##width[NB_MEM_FUNCS] = { \
2181 GEN_MEM_FUNCS(l##width), \
2183 #define OP_ST_TABLE(width) \
2184 static GenOpFunc *gen_op_st##width[NB_MEM_FUNCS] = { \
2185 GEN_MEM_FUNCS(st##width), \
2189 #if defined(TARGET_PPC64)
2190 #define GEN_QEMU_LD_PPC64(width) \
2191 static always_inline void gen_qemu_ld##width##_ppc64(TCGv t0, TCGv t1, int flags)\
2193 if (likely(flags & 2)) \
2194 tcg_gen_qemu_ld##width(t0, t1, flags >> 2); \
2196 TCGv addr = tcg_temp_new(TCG_TYPE_TL); \
2197 tcg_gen_ext32u_tl(addr, t1); \
2198 tcg_gen_qemu_ld##width(t0, addr, flags >> 2); \
2199 tcg_temp_free(addr); \
2202 GEN_QEMU_LD_PPC64(8u)
2203 GEN_QEMU_LD_PPC64(8s)
2204 GEN_QEMU_LD_PPC64(16u)
2205 GEN_QEMU_LD_PPC64(16s)
2206 GEN_QEMU_LD_PPC64(32u)
2207 GEN_QEMU_LD_PPC64(32s)
2208 GEN_QEMU_LD_PPC64(64)
2210 #define GEN_QEMU_ST_PPC64(width) \
2211 static always_inline void gen_qemu_st##width##_ppc64(TCGv t0, TCGv t1, int flags)\
2213 if (likely(flags & 2)) \
2214 tcg_gen_qemu_st##width(t0, t1, flags >> 2); \
2216 TCGv addr = tcg_temp_new(TCG_TYPE_TL); \
2217 tcg_gen_ext32u_tl(addr, t1); \
2218 tcg_gen_qemu_st##width(t0, addr, flags >> 2); \
2219 tcg_temp_free(addr); \
2222 GEN_QEMU_ST_PPC64(8)
2223 GEN_QEMU_ST_PPC64(16)
2224 GEN_QEMU_ST_PPC64(32)
2225 GEN_QEMU_ST_PPC64(64)
2227 static always_inline void gen_qemu_ld8u(TCGv t0, TCGv t1, int flags)
2229 gen_qemu_ld8u_ppc64(t0, t1, flags);
2232 static always_inline void gen_qemu_ld8s(TCGv t0, TCGv t1, int flags)
2234 gen_qemu_ld8s_ppc64(t0, t1, flags);
2237 static always_inline void gen_qemu_ld16u(TCGv t0, TCGv t1, int flags)
2239 if (unlikely(flags & 1)) {
2241 gen_qemu_ld16u_ppc64(t0, t1, flags);
2242 t0_32 = tcg_temp_new(TCG_TYPE_I32);
2243 tcg_gen_trunc_tl_i32(t0_32, t0);
2244 tcg_gen_bswap16_i32(t0_32, t0_32);
2245 tcg_gen_extu_i32_tl(t0, t0_32);
2246 tcg_temp_free(t0_32);
2248 gen_qemu_ld16u_ppc64(t0, t1, flags);
2251 static always_inline void gen_qemu_ld16s(TCGv t0, TCGv t1, int flags)
2253 if (unlikely(flags & 1)) {
2255 gen_qemu_ld16u_ppc64(t0, t1, flags);
2256 t0_32 = tcg_temp_new(TCG_TYPE_I32);
2257 tcg_gen_trunc_tl_i32(t0_32, t0);
2258 tcg_gen_bswap16_i32(t0_32, t0_32);
2259 tcg_gen_extu_i32_tl(t0, t0_32);
2260 tcg_gen_ext16s_tl(t0, t0);
2261 tcg_temp_free(t0_32);
2263 gen_qemu_ld16s_ppc64(t0, t1, flags);
2266 static always_inline void gen_qemu_ld32u(TCGv t0, TCGv t1, int flags)
2268 if (unlikely(flags & 1)) {
2270 gen_qemu_ld32u_ppc64(t0, t1, flags);
2271 t0_32 = tcg_temp_new(TCG_TYPE_I32);
2272 tcg_gen_trunc_tl_i32(t0_32, t0);
2273 tcg_gen_bswap_i32(t0_32, t0_32);
2274 tcg_gen_extu_i32_tl(t0, t0_32);
2275 tcg_temp_free(t0_32);
2277 gen_qemu_ld32u_ppc64(t0, t1, flags);
2280 static always_inline void gen_qemu_ld32s(TCGv t0, TCGv t1, int flags)
2282 if (unlikely(flags & 1)) {
2284 gen_qemu_ld32u_ppc64(t0, t1, flags);
2285 t0_32 = tcg_temp_new(TCG_TYPE_I32);
2286 tcg_gen_trunc_tl_i32(t0_32, t0);
2287 tcg_gen_bswap_i32(t0_32, t0_32);
2288 tcg_gen_ext_i32_tl(t0, t0_32);
2289 tcg_temp_free(t0_32);
2291 gen_qemu_ld32s_ppc64(t0, t1, flags);
2294 static always_inline void gen_qemu_ld64(TCGv t0, TCGv t1, int flags)
2296 gen_qemu_ld64_ppc64(t0, t1, flags);
2297 if (unlikely(flags & 1))
2298 tcg_gen_bswap_i64(t0, t0);
2301 static always_inline void gen_qemu_st8(TCGv t0, TCGv t1, int flags)
2303 gen_qemu_st8_ppc64(t0, t1, flags);
2306 static always_inline void gen_qemu_st16(TCGv t0, TCGv t1, int flags)
2308 if (unlikely(flags & 1)) {
2310 temp1 = tcg_temp_new(TCG_TYPE_I32);
2311 tcg_gen_trunc_tl_i32(temp1, t0);
2312 tcg_gen_ext16u_i32(temp1, temp1);
2313 tcg_gen_bswap16_i32(temp1, temp1);
2314 temp2 = tcg_temp_new(TCG_TYPE_I64);
2315 tcg_gen_extu_i32_tl(temp2, temp1);
2316 tcg_temp_free(temp1);
2317 gen_qemu_st16_ppc64(temp2, t1, flags);
2318 tcg_temp_free(temp2);
2320 gen_qemu_st16_ppc64(t0, t1, flags);
2323 static always_inline void gen_qemu_st32(TCGv t0, TCGv t1, int flags)
2325 if (unlikely(flags & 1)) {
2327 temp1 = tcg_temp_new(TCG_TYPE_I32);
2328 tcg_gen_trunc_tl_i32(temp1, t0);
2329 tcg_gen_bswap_i32(temp1, temp1);
2330 temp2 = tcg_temp_new(TCG_TYPE_I64);
2331 tcg_gen_extu_i32_tl(temp2, temp1);
2332 tcg_temp_free(temp1);
2333 gen_qemu_st32_ppc64(temp2, t1, flags);
2334 tcg_temp_free(temp2);
2336 gen_qemu_st32_ppc64(t0, t1, flags);
2339 static always_inline void gen_qemu_st64(TCGv t0, TCGv t1, int flags)
2341 if (unlikely(flags & 1)) {
2342 TCGv temp = tcg_temp_new(TCG_TYPE_I64);
2343 tcg_gen_bswap_i64(temp, t0);
2344 gen_qemu_st64_ppc64(temp, t1, flags);
2345 tcg_temp_free(temp);
2347 gen_qemu_st64_ppc64(t0, t1, flags);
2351 #else /* defined(TARGET_PPC64) */
2352 #define GEN_QEMU_LD_PPC32(width) \
2353 static always_inline void gen_qemu_ld##width##_ppc32(TCGv t0, TCGv t1, int flags)\
2355 tcg_gen_qemu_ld##width(t0, t1, flags >> 1); \
2357 GEN_QEMU_LD_PPC32(8u)
2358 GEN_QEMU_LD_PPC32(8s)
2359 GEN_QEMU_LD_PPC32(16u)
2360 GEN_QEMU_LD_PPC32(16s)
2361 GEN_QEMU_LD_PPC32(32u)
2362 GEN_QEMU_LD_PPC32(32s)
2363 GEN_QEMU_LD_PPC32(64)
2365 #define GEN_QEMU_ST_PPC32(width) \
2366 static always_inline void gen_qemu_st##width##_ppc32(TCGv t0, TCGv t1, int flags)\
2368 tcg_gen_qemu_st##width(t0, t1, flags >> 1); \
2370 GEN_QEMU_ST_PPC32(8)
2371 GEN_QEMU_ST_PPC32(16)
2372 GEN_QEMU_ST_PPC32(32)
2373 GEN_QEMU_ST_PPC32(64)
2375 static always_inline void gen_qemu_ld8u(TCGv t0, TCGv t1, int flags)
2377 gen_qemu_ld8u_ppc32(t0, t1, flags >> 1);
2380 static always_inline void gen_qemu_ld8s(TCGv t0, TCGv t1, int flags)
2382 gen_qemu_ld8s_ppc32(t0, t1, flags >> 1);
2385 static always_inline void gen_qemu_ld16u(TCGv t0, TCGv t1, int flags)
2387 gen_qemu_ld16u_ppc32(t0, t1, flags >> 1);
2388 if (unlikely(flags & 1))
2389 tcg_gen_bswap16_i32(t0, t0);
2392 static always_inline void gen_qemu_ld16s(TCGv t0, TCGv t1, int flags)
2394 if (unlikely(flags & 1)) {
2395 gen_qemu_ld16u_ppc32(t0, t1, flags);
2396 tcg_gen_bswap16_i32(t0, t0);
2397 tcg_gen_ext16s_i32(t0, t0);
2399 gen_qemu_ld16s_ppc32(t0, t1, flags);
2402 static always_inline void gen_qemu_ld32u(TCGv t0, TCGv t1, int flags)
2404 gen_qemu_ld32u_ppc32(t0, t1, flags);
2405 if (unlikely(flags & 1))
2406 tcg_gen_bswap_i32(t0, t0);
2409 static always_inline void gen_qemu_ld64(TCGv t0, TCGv t1, int flags)
2411 gen_qemu_ld64_ppc32(t0, t1, flags);
2412 if (unlikely(flags & 1))
2413 tcg_gen_bswap_i64(t0, t0);
2416 static always_inline void gen_qemu_st8(TCGv t0, TCGv t1, int flags)
2418 gen_qemu_st8_ppc32(t0, t1, flags >> 1);
2421 static always_inline void gen_qemu_st16(TCGv t0, TCGv t1, int flags)
2423 if (unlikely(flags & 1)) {
2424 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
2425 tcg_gen_ext16u_i32(temp, t0);
2426 tcg_gen_bswap16_i32(temp, temp);
2427 gen_qemu_st16_ppc32(temp, t1, flags >> 1);
2428 tcg_temp_free(temp);
2430 gen_qemu_st16_ppc32(t0, t1, flags >> 1);
2433 static always_inline void gen_qemu_st32(TCGv t0, TCGv t1, int flags)
2435 if (unlikely(flags & 1)) {
2436 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
2437 tcg_gen_bswap_i32(temp, t0);
2438 gen_qemu_st32_ppc32(temp, t1, flags >> 1);
2439 tcg_temp_free(temp);
2441 gen_qemu_st32_ppc32(t0, t1, flags >> 1);
2444 static always_inline void gen_qemu_st64(TCGv t0, TCGv t1, int flags)
2446 if (unlikely(flags & 1)) {
2447 TCGv temp = tcg_temp_new(TCG_TYPE_I64);
2448 tcg_gen_bswap_i64(temp, t0);
2449 gen_qemu_st64_ppc32(temp, t1, flags >> 1);
2450 tcg_temp_free(temp);
2452 gen_qemu_st64_ppc32(t0, t1, flags >> 1);
2457 #define GEN_LD(width, opc, type) \
2458 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2460 TCGv EA = tcg_temp_new(TCG_TYPE_TL); \
2461 gen_addr_imm_index(EA, ctx, 0); \
2462 gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2463 tcg_temp_free(EA); \
2466 #define GEN_LDU(width, opc, type) \
2467 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2470 if (unlikely(rA(ctx->opcode) == 0 || \
2471 rA(ctx->opcode) == rD(ctx->opcode))) { \
2472 GEN_EXCP_INVAL(ctx); \
2475 EA = tcg_temp_new(TCG_TYPE_TL); \
2476 if (type == PPC_64B) \
2477 gen_addr_imm_index(EA, ctx, 0x03); \
2479 gen_addr_imm_index(EA, ctx, 0); \
2480 gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2481 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2482 tcg_temp_free(EA); \
2485 #define GEN_LDUX(width, opc2, opc3, type) \
2486 GEN_HANDLER(l##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2489 if (unlikely(rA(ctx->opcode) == 0 || \
2490 rA(ctx->opcode) == rD(ctx->opcode))) { \
2491 GEN_EXCP_INVAL(ctx); \
2494 EA = tcg_temp_new(TCG_TYPE_TL); \
2495 gen_addr_reg_index(EA, ctx); \
2496 gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2497 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2498 tcg_temp_free(EA); \
2501 #define GEN_LDX(width, opc2, opc3, type) \
2502 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2504 TCGv EA = tcg_temp_new(TCG_TYPE_TL); \
2505 gen_addr_reg_index(EA, ctx); \
2506 gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2507 tcg_temp_free(EA); \
2510 #define GEN_LDS(width, op, type) \
2511 GEN_LD(width, op | 0x20, type); \
2512 GEN_LDU(width, op | 0x21, type); \
2513 GEN_LDUX(width, 0x17, op | 0x01, type); \
2514 GEN_LDX(width, 0x17, op | 0x00, type)
2516 /* lbz lbzu lbzux lbzx */
2517 GEN_LDS(8u, 0x02, PPC_INTEGER);
2518 /* lha lhau lhaux lhax */
2519 GEN_LDS(16s, 0x0A, PPC_INTEGER);
2520 /* lhz lhzu lhzux lhzx */
2521 GEN_LDS(16u, 0x08, PPC_INTEGER);
2522 /* lwz lwzu lwzux lwzx */
2523 GEN_LDS(32u, 0x00, PPC_INTEGER);
2524 #if defined(TARGET_PPC64)
2526 GEN_LDUX(32s, 0x15, 0x0B, PPC_64B);
2528 GEN_LDX(32s, 0x15, 0x0A, PPC_64B);
2530 GEN_LDUX(64, 0x15, 0x01, PPC_64B);
2532 GEN_LDX(64, 0x15, 0x00, PPC_64B);
2533 GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B)
2536 if (Rc(ctx->opcode)) {
2537 if (unlikely(rA(ctx->opcode) == 0 ||
2538 rA(ctx->opcode) == rD(ctx->opcode))) {
2539 GEN_EXCP_INVAL(ctx);
2543 EA = tcg_temp_new(TCG_TYPE_TL);
2544 gen_addr_imm_index(EA, ctx, 0x03);
2545 if (ctx->opcode & 0x02) {
2546 /* lwa (lwau is undefined) */
2547 gen_qemu_ld32s(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx);
2550 gen_qemu_ld64(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx);
2552 if (Rc(ctx->opcode))
2553 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2557 GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX)
2559 #if defined(CONFIG_USER_ONLY)
2560 GEN_EXCP_PRIVOPC(ctx);
2565 /* Restore CPU state */
2566 if (unlikely(ctx->supervisor == 0)) {
2567 GEN_EXCP_PRIVOPC(ctx);
2570 ra = rA(ctx->opcode);
2571 rd = rD(ctx->opcode);
2572 if (unlikely((rd & 1) || rd == ra)) {
2573 GEN_EXCP_INVAL(ctx);
2576 if (unlikely(ctx->mem_idx & 1)) {
2577 /* Little-endian mode is not handled */
2578 GEN_EXCP(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
2581 EA = tcg_temp_new(TCG_TYPE_TL);
2582 gen_addr_imm_index(EA, ctx, 0x0F);
2583 gen_qemu_ld64(cpu_gpr[rd], EA, ctx->mem_idx);
2584 tcg_gen_addi_tl(EA, EA, 8);
2585 gen_qemu_ld64(cpu_gpr[rd+1], EA, ctx->mem_idx);
2591 /*** Integer store ***/
2592 #define GEN_ST(width, opc, type) \
2593 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2595 TCGv EA = tcg_temp_new(TCG_TYPE_TL); \
2596 gen_addr_imm_index(EA, ctx, 0); \
2597 gen_qemu_st##width(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
2598 tcg_temp_free(EA); \
2601 #define GEN_STU(width, opc, type) \
2602 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2605 if (unlikely(rA(ctx->opcode) == 0)) { \
2606 GEN_EXCP_INVAL(ctx); \
2609 EA = tcg_temp_new(TCG_TYPE_TL); \
2610 if (type == PPC_64B) \
2611 gen_addr_imm_index(EA, ctx, 0x03); \
2613 gen_addr_imm_index(EA, ctx, 0); \
2614 gen_qemu_st##width(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
2615 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2616 tcg_temp_free(EA); \
2619 #define GEN_STUX(width, opc2, opc3, type) \
2620 GEN_HANDLER(st##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2623 if (unlikely(rA(ctx->opcode) == 0)) { \
2624 GEN_EXCP_INVAL(ctx); \
2627 EA = tcg_temp_new(TCG_TYPE_TL); \
2628 gen_addr_reg_index(EA, ctx); \
2629 gen_qemu_st##width(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
2630 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2631 tcg_temp_free(EA); \
2634 #define GEN_STX(width, opc2, opc3, type) \
2635 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2637 TCGv EA = tcg_temp_new(TCG_TYPE_TL); \
2638 gen_addr_reg_index(EA, ctx); \
2639 gen_qemu_st##width(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
2640 tcg_temp_free(EA); \
2643 #define GEN_STS(width, op, type) \
2644 GEN_ST(width, op | 0x20, type); \
2645 GEN_STU(width, op | 0x21, type); \
2646 GEN_STUX(width, 0x17, op | 0x01, type); \
2647 GEN_STX(width, 0x17, op | 0x00, type)
2649 /* stb stbu stbux stbx */
2650 GEN_STS(8, 0x06, PPC_INTEGER);
2651 /* sth sthu sthux sthx */
2652 GEN_STS(16, 0x0C, PPC_INTEGER);
2653 /* stw stwu stwux stwx */
2654 GEN_STS(32, 0x04, PPC_INTEGER);
2655 #if defined(TARGET_PPC64)
2656 GEN_STUX(64, 0x15, 0x05, PPC_64B);
2657 GEN_STX(64, 0x15, 0x04, PPC_64B);
2658 GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B)
2663 rs = rS(ctx->opcode);
2664 if ((ctx->opcode & 0x3) == 0x2) {
2665 #if defined(CONFIG_USER_ONLY)
2666 GEN_EXCP_PRIVOPC(ctx);
2669 if (unlikely(ctx->supervisor == 0)) {
2670 GEN_EXCP_PRIVOPC(ctx);
2673 if (unlikely(rs & 1)) {
2674 GEN_EXCP_INVAL(ctx);
2677 if (unlikely(ctx->mem_idx & 1)) {
2678 /* Little-endian mode is not handled */
2679 GEN_EXCP(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
2682 EA = tcg_temp_new(TCG_TYPE_TL);
2683 gen_addr_imm_index(EA, ctx, 0x03);
2684 gen_qemu_st64(cpu_gpr[rs], EA, ctx->mem_idx);
2685 tcg_gen_addi_tl(EA, EA, 8);
2686 gen_qemu_st64(cpu_gpr[rs+1], EA, ctx->mem_idx);
2691 if (Rc(ctx->opcode)) {
2692 if (unlikely(rA(ctx->opcode) == 0)) {
2693 GEN_EXCP_INVAL(ctx);
2697 EA = tcg_temp_new(TCG_TYPE_TL);
2698 gen_addr_imm_index(EA, ctx, 0x03);
2699 gen_qemu_st64(cpu_gpr[rs], EA, ctx->mem_idx);
2700 if (Rc(ctx->opcode))
2701 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2706 /*** Integer load and store with byte reverse ***/
2708 void always_inline gen_qemu_ld16ur(TCGv t0, TCGv t1, int flags)
2710 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
2711 gen_qemu_ld16u(temp, t1, flags);
2712 tcg_gen_bswap16_i32(temp, temp);
2713 tcg_gen_extu_i32_tl(t0, temp);
2714 tcg_temp_free(temp);
2716 GEN_LDX(16ur, 0x16, 0x18, PPC_INTEGER);
2719 void always_inline gen_qemu_ld32ur(TCGv t0, TCGv t1, int flags)
2721 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
2722 gen_qemu_ld32u(temp, t1, flags);
2723 tcg_gen_bswap_i32(temp, temp);
2724 tcg_gen_extu_i32_tl(t0, temp);
2725 tcg_temp_free(temp);
2727 GEN_LDX(32ur, 0x16, 0x10, PPC_INTEGER);
2730 void always_inline gen_qemu_st16r(TCGv t0, TCGv t1, int flags)
2732 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
2733 tcg_gen_trunc_tl_i32(temp, t0);
2734 tcg_gen_ext16u_i32(temp, temp);
2735 tcg_gen_bswap16_i32(temp, temp);
2736 gen_qemu_st16(temp, t1, flags);
2737 tcg_temp_free(temp);
2739 GEN_STX(16r, 0x16, 0x1C, PPC_INTEGER);
2742 void always_inline gen_qemu_st32r(TCGv t0, TCGv t1, int flags)
2744 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
2745 tcg_gen_trunc_tl_i32(temp, t0);
2746 tcg_gen_bswap_i32(temp, temp);
2747 gen_qemu_st32(temp, t1, flags);
2748 tcg_temp_free(temp);
2750 GEN_STX(32r, 0x16, 0x14, PPC_INTEGER);
2752 /*** Integer load and store multiple ***/
2753 #define op_ldstm(name, reg) (*gen_op_##name[ctx->mem_idx])(reg)
2754 static GenOpFunc1 *gen_op_lmw[NB_MEM_FUNCS] = {
2757 static GenOpFunc1 *gen_op_stmw[NB_MEM_FUNCS] = {
2758 GEN_MEM_FUNCS(stmw),
2762 GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
2764 /* NIP cannot be restored if the memory exception comes from an helper */
2765 gen_update_nip(ctx, ctx->nip - 4);
2766 gen_addr_imm_index(cpu_T[0], ctx, 0);
2767 op_ldstm(lmw, rD(ctx->opcode));
2771 GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
2773 /* NIP cannot be restored if the memory exception comes from an helper */
2774 gen_update_nip(ctx, ctx->nip - 4);
2775 gen_addr_imm_index(cpu_T[0], ctx, 0);
2776 op_ldstm(stmw, rS(ctx->opcode));
2779 /*** Integer load and store strings ***/
2780 #define op_ldsts(name, start) (*gen_op_##name[ctx->mem_idx])(start)
2781 #define op_ldstsx(name, rd, ra, rb) (*gen_op_##name[ctx->mem_idx])(rd, ra, rb)
2782 /* string load & stores are by definition endian-safe */
2783 #define gen_op_lswi_le_raw gen_op_lswi_raw
2784 #define gen_op_lswi_le_user gen_op_lswi_user
2785 #define gen_op_lswi_le_kernel gen_op_lswi_kernel
2786 #define gen_op_lswi_le_hypv gen_op_lswi_hypv
2787 #define gen_op_lswi_le_64_raw gen_op_lswi_raw
2788 #define gen_op_lswi_le_64_user gen_op_lswi_user
2789 #define gen_op_lswi_le_64_kernel gen_op_lswi_kernel
2790 #define gen_op_lswi_le_64_hypv gen_op_lswi_hypv
2791 static GenOpFunc1 *gen_op_lswi[NB_MEM_FUNCS] = {
2792 GEN_MEM_FUNCS(lswi),
2794 #define gen_op_lswx_le_raw gen_op_lswx_raw
2795 #define gen_op_lswx_le_user gen_op_lswx_user
2796 #define gen_op_lswx_le_kernel gen_op_lswx_kernel
2797 #define gen_op_lswx_le_hypv gen_op_lswx_hypv
2798 #define gen_op_lswx_le_64_raw gen_op_lswx_raw
2799 #define gen_op_lswx_le_64_user gen_op_lswx_user
2800 #define gen_op_lswx_le_64_kernel gen_op_lswx_kernel
2801 #define gen_op_lswx_le_64_hypv gen_op_lswx_hypv
2802 static GenOpFunc3 *gen_op_lswx[NB_MEM_FUNCS] = {
2803 GEN_MEM_FUNCS(lswx),
2805 #define gen_op_stsw_le_raw gen_op_stsw_raw
2806 #define gen_op_stsw_le_user gen_op_stsw_user
2807 #define gen_op_stsw_le_kernel gen_op_stsw_kernel
2808 #define gen_op_stsw_le_hypv gen_op_stsw_hypv
2809 #define gen_op_stsw_le_64_raw gen_op_stsw_raw
2810 #define gen_op_stsw_le_64_user gen_op_stsw_user
2811 #define gen_op_stsw_le_64_kernel gen_op_stsw_kernel
2812 #define gen_op_stsw_le_64_hypv gen_op_stsw_hypv
2813 static GenOpFunc1 *gen_op_stsw[NB_MEM_FUNCS] = {
2814 GEN_MEM_FUNCS(stsw),
2818 /* PowerPC32 specification says we must generate an exception if
2819 * rA is in the range of registers to be loaded.
2820 * In an other hand, IBM says this is valid, but rA won't be loaded.
2821 * For now, I'll follow the spec...
2823 GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING)
2825 int nb = NB(ctx->opcode);
2826 int start = rD(ctx->opcode);
2827 int ra = rA(ctx->opcode);
2833 if (unlikely(((start + nr) > 32 &&
2834 start <= ra && (start + nr - 32) > ra) ||
2835 ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) {
2836 GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM,
2837 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_LSWX);
2840 /* NIP cannot be restored if the memory exception comes from an helper */
2841 gen_update_nip(ctx, ctx->nip - 4);
2842 gen_addr_register(cpu_T[0], ctx);
2843 tcg_gen_movi_tl(cpu_T[1], nb);
2844 op_ldsts(lswi, start);
2848 GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING)
2850 int ra = rA(ctx->opcode);
2851 int rb = rB(ctx->opcode);
2853 /* NIP cannot be restored if the memory exception comes from an helper */
2854 gen_update_nip(ctx, ctx->nip - 4);
2855 gen_addr_reg_index(cpu_T[0], ctx);
2859 tcg_gen_andi_tl(cpu_T[1], cpu_xer, 0x7F);
2860 op_ldstsx(lswx, rD(ctx->opcode), ra, rb);
2864 GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING)
2866 int nb = NB(ctx->opcode);
2868 /* NIP cannot be restored if the memory exception comes from an helper */
2869 gen_update_nip(ctx, ctx->nip - 4);
2870 gen_addr_register(cpu_T[0], ctx);
2873 tcg_gen_movi_tl(cpu_T[1], nb);
2874 op_ldsts(stsw, rS(ctx->opcode));
2878 GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING)
2880 /* NIP cannot be restored if the memory exception comes from an helper */
2881 gen_update_nip(ctx, ctx->nip - 4);
2882 gen_addr_reg_index(cpu_T[0], ctx);
2883 tcg_gen_andi_tl(cpu_T[1], cpu_xer, 0x7F);
2884 op_ldsts(stsw, rS(ctx->opcode));
2887 /*** Memory synchronisation ***/
2889 GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO)
2894 GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM)
2899 #define op_lwarx() (*gen_op_lwarx[ctx->mem_idx])()
2900 #define op_stwcx() (*gen_op_stwcx[ctx->mem_idx])()
2901 static GenOpFunc *gen_op_lwarx[NB_MEM_FUNCS] = {
2902 GEN_MEM_FUNCS(lwarx),
2904 static GenOpFunc *gen_op_stwcx[NB_MEM_FUNCS] = {
2905 GEN_MEM_FUNCS(stwcx),
2909 GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000001, PPC_RES)
2911 /* NIP cannot be restored if the memory exception comes from an helper */
2912 gen_update_nip(ctx, ctx->nip - 4);
2913 gen_addr_reg_index(cpu_T[0], ctx);
2915 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[1]);
2919 GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES)
2921 /* NIP cannot be restored if the memory exception comes from an helper */
2922 gen_update_nip(ctx, ctx->nip - 4);
2923 gen_addr_reg_index(cpu_T[0], ctx);
2924 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
2928 #if defined(TARGET_PPC64)
2929 #define op_ldarx() (*gen_op_ldarx[ctx->mem_idx])()
2930 #define op_stdcx() (*gen_op_stdcx[ctx->mem_idx])()
2931 static GenOpFunc *gen_op_ldarx[NB_MEM_FUNCS] = {
2932 GEN_MEM_FUNCS(ldarx),
2934 static GenOpFunc *gen_op_stdcx[NB_MEM_FUNCS] = {
2935 GEN_MEM_FUNCS(stdcx),
2939 GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000001, PPC_64B)
2941 /* NIP cannot be restored if the memory exception comes from an helper */
2942 gen_update_nip(ctx, ctx->nip - 4);
2943 gen_addr_reg_index(cpu_T[0], ctx);
2945 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[1]);
2949 GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B)
2951 /* NIP cannot be restored if the memory exception comes from an helper */
2952 gen_update_nip(ctx, ctx->nip - 4);
2953 gen_addr_reg_index(cpu_T[0], ctx);
2954 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
2957 #endif /* defined(TARGET_PPC64) */
2960 GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC)
2965 GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT)
2967 /* Stop translation, as the CPU is supposed to sleep from now */
2969 GEN_EXCP(ctx, EXCP_HLT, 1);
2972 /*** Floating-point load ***/
2973 #define GEN_LDF(width, opc, type) \
2974 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2976 if (unlikely(!ctx->fpu_enabled)) { \
2977 GEN_EXCP_NO_FP(ctx); \
2980 gen_addr_imm_index(cpu_T[0], ctx, 0); \
2981 op_ldst(l##width); \
2982 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2985 #define GEN_LDUF(width, opc, type) \
2986 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2988 if (unlikely(!ctx->fpu_enabled)) { \
2989 GEN_EXCP_NO_FP(ctx); \
2992 if (unlikely(rA(ctx->opcode) == 0)) { \
2993 GEN_EXCP_INVAL(ctx); \
2996 gen_addr_imm_index(cpu_T[0], ctx, 0); \
2997 op_ldst(l##width); \
2998 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2999 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
3002 #define GEN_LDUXF(width, opc, type) \
3003 GEN_HANDLER(l##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \
3005 if (unlikely(!ctx->fpu_enabled)) { \
3006 GEN_EXCP_NO_FP(ctx); \
3009 if (unlikely(rA(ctx->opcode) == 0)) { \
3010 GEN_EXCP_INVAL(ctx); \
3013 gen_addr_reg_index(cpu_T[0], ctx); \
3014 op_ldst(l##width); \
3015 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
3016 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
3019 #define GEN_LDXF(width, opc2, opc3, type) \
3020 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
3022 if (unlikely(!ctx->fpu_enabled)) { \
3023 GEN_EXCP_NO_FP(ctx); \
3026 gen_addr_reg_index(cpu_T[0], ctx); \
3027 op_ldst(l##width); \
3028 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
3031 #define GEN_LDFS(width, op, type) \
3032 OP_LD_TABLE(width); \
3033 GEN_LDF(width, op | 0x20, type); \
3034 GEN_LDUF(width, op | 0x21, type); \
3035 GEN_LDUXF(width, op | 0x01, type); \
3036 GEN_LDXF(width, 0x17, op | 0x00, type)
3038 /* lfd lfdu lfdux lfdx */
3039 GEN_LDFS(fd, 0x12, PPC_FLOAT);
3040 /* lfs lfsu lfsux lfsx */
3041 GEN_LDFS(fs, 0x10, PPC_FLOAT);
3043 /*** Floating-point store ***/
3044 #define GEN_STF(width, opc, type) \
3045 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \
3047 if (unlikely(!ctx->fpu_enabled)) { \
3048 GEN_EXCP_NO_FP(ctx); \
3051 gen_addr_imm_index(cpu_T[0], ctx, 0); \
3052 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
3053 op_ldst(st##width); \
3056 #define GEN_STUF(width, opc, type) \
3057 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
3059 if (unlikely(!ctx->fpu_enabled)) { \
3060 GEN_EXCP_NO_FP(ctx); \
3063 if (unlikely(rA(ctx->opcode) == 0)) { \
3064 GEN_EXCP_INVAL(ctx); \
3067 gen_addr_imm_index(cpu_T[0], ctx, 0); \
3068 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
3069 op_ldst(st##width); \
3070 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
3073 #define GEN_STUXF(width, opc, type) \
3074 GEN_HANDLER(st##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \
3076 if (unlikely(!ctx->fpu_enabled)) { \
3077 GEN_EXCP_NO_FP(ctx); \
3080 if (unlikely(rA(ctx->opcode) == 0)) { \
3081 GEN_EXCP_INVAL(ctx); \
3084 gen_addr_reg_index(cpu_T[0], ctx); \
3085 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
3086 op_ldst(st##width); \
3087 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
3090 #define GEN_STXF(width, opc2, opc3, type) \
3091 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
3093 if (unlikely(!ctx->fpu_enabled)) { \
3094 GEN_EXCP_NO_FP(ctx); \
3097 gen_addr_reg_index(cpu_T[0], ctx); \
3098 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
3099 op_ldst(st##width); \
3102 #define GEN_STFS(width, op, type) \
3103 OP_ST_TABLE(width); \
3104 GEN_STF(width, op | 0x20, type); \
3105 GEN_STUF(width, op | 0x21, type); \
3106 GEN_STUXF(width, op | 0x01, type); \
3107 GEN_STXF(width, 0x17, op | 0x00, type)
3109 /* stfd stfdu stfdux stfdx */
3110 GEN_STFS(fd, 0x16, PPC_FLOAT);
3111 /* stfs stfsu stfsux stfsx */
3112 GEN_STFS(fs, 0x14, PPC_FLOAT);
3117 GEN_STXF(fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX);
3120 static always_inline void gen_goto_tb (DisasContext *ctx, int n,
3123 TranslationBlock *tb;
3125 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) &&
3126 likely(!ctx->singlestep_enabled)) {
3128 tcg_gen_movi_tl(cpu_T[1], dest);
3129 #if defined(TARGET_PPC64)
3131 tcg_gen_andi_tl(cpu_nip, cpu_T[1], ~3);
3134 tcg_gen_andi_tl(cpu_nip, cpu_T[1], (uint32_t)~3);
3135 tcg_gen_exit_tb((long)tb + n);
3137 tcg_gen_movi_tl(cpu_T[1], dest);
3138 #if defined(TARGET_PPC64)
3140 tcg_gen_andi_tl(cpu_nip, cpu_T[1], ~3);
3143 tcg_gen_andi_tl(cpu_nip, cpu_T[1], (uint32_t)~3);
3144 if (unlikely(ctx->singlestep_enabled)) {
3145 if ((ctx->singlestep_enabled &
3146 (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) &&
3147 ctx->exception == POWERPC_EXCP_BRANCH) {
3148 target_ulong tmp = ctx->nip;
3150 GEN_EXCP(ctx, POWERPC_EXCP_TRACE, 0);
3153 if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) {
3154 gen_update_nip(ctx, dest);
3162 static always_inline void gen_setlr (DisasContext *ctx, target_ulong nip)
3164 #if defined(TARGET_PPC64)
3165 if (ctx->sf_mode != 0 && (nip >> 32))
3166 gen_op_setlr_64(ctx->nip >> 32, ctx->nip);
3169 gen_op_setlr(ctx->nip);
3173 GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
3175 target_ulong li, target;
3177 ctx->exception = POWERPC_EXCP_BRANCH;
3178 /* sign extend LI */
3179 #if defined(TARGET_PPC64)
3181 li = ((int64_t)LI(ctx->opcode) << 38) >> 38;
3184 li = ((int32_t)LI(ctx->opcode) << 6) >> 6;
3185 if (likely(AA(ctx->opcode) == 0))
3186 target = ctx->nip + li - 4;
3189 #if defined(TARGET_PPC64)
3191 target = (uint32_t)target;
3193 if (LK(ctx->opcode))
3194 gen_setlr(ctx, ctx->nip);
3195 gen_goto_tb(ctx, 0, target);
3202 static always_inline void gen_bcond (DisasContext *ctx, int type)
3204 target_ulong target = 0;
3206 uint32_t bo = BO(ctx->opcode);
3207 uint32_t bi = BI(ctx->opcode);
3210 ctx->exception = POWERPC_EXCP_BRANCH;
3211 if ((bo & 0x4) == 0)
3215 li = (target_long)((int16_t)(BD(ctx->opcode)));
3216 if (likely(AA(ctx->opcode) == 0)) {
3217 target = ctx->nip + li - 4;
3221 #if defined(TARGET_PPC64)
3223 target = (uint32_t)target;
3227 gen_op_movl_T1_ctr();
3231 gen_op_movl_T1_lr();
3234 if (LK(ctx->opcode))
3235 gen_setlr(ctx, ctx->nip);
3237 /* No CR condition */
3240 #if defined(TARGET_PPC64)
3242 gen_op_test_ctr_64();
3248 #if defined(TARGET_PPC64)
3250 gen_op_test_ctrz_64();
3258 if (type == BCOND_IM) {
3259 gen_goto_tb(ctx, 0, target);
3262 #if defined(TARGET_PPC64)
3264 tcg_gen_andi_tl(cpu_nip, cpu_T[1], ~3);
3267 tcg_gen_andi_tl(cpu_nip, cpu_T[1], (uint32_t)~3);
3273 mask = 1 << (3 - (bi & 0x03));
3274 tcg_gen_mov_i32(cpu_T[0], cpu_crf[bi >> 2]);
3278 #if defined(TARGET_PPC64)
3280 gen_op_test_ctr_true_64(mask);
3283 gen_op_test_ctr_true(mask);
3286 #if defined(TARGET_PPC64)
3288 gen_op_test_ctrz_true_64(mask);
3291 gen_op_test_ctrz_true(mask);
3296 gen_op_test_true(mask);
3302 #if defined(TARGET_PPC64)
3304 gen_op_test_ctr_false_64(mask);
3307 gen_op_test_ctr_false(mask);
3310 #if defined(TARGET_PPC64)
3312 gen_op_test_ctrz_false_64(mask);
3315 gen_op_test_ctrz_false(mask);
3320 gen_op_test_false(mask);
3325 if (type == BCOND_IM) {
3326 int l1 = gen_new_label();
3328 gen_goto_tb(ctx, 0, target);
3330 gen_goto_tb(ctx, 1, ctx->nip);
3332 #if defined(TARGET_PPC64)
3334 gen_op_btest_T1_64(ctx->nip >> 32, ctx->nip);
3337 gen_op_btest_T1(ctx->nip);
3343 GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
3345 gen_bcond(ctx, BCOND_IM);
3348 GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW)
3350 gen_bcond(ctx, BCOND_CTR);
3353 GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW)
3355 gen_bcond(ctx, BCOND_LR);
3358 /*** Condition register logical ***/
3359 #define GEN_CRLOGIC(op, opc) \
3360 GEN_HANDLER(cr##op, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) \
3364 tcg_gen_mov_i32(cpu_T[0], cpu_crf[crbA(ctx->opcode) >> 2]); \
3365 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3367 gen_op_srli_T0(sh); \
3369 gen_op_sli_T0(-sh); \
3370 tcg_gen_mov_i32(cpu_T[1], cpu_crf[crbB(ctx->opcode) >> 2]); \
3371 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3373 gen_op_srli_T1(sh); \
3375 gen_op_sli_T1(-sh); \
3377 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
3378 tcg_gen_andi_tl(cpu_T[0], cpu_T[0], bitmask); \
3379 tcg_gen_andi_i32(cpu_T[1], cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3381 tcg_gen_andi_i32(cpu_crf[crbD(ctx->opcode) >> 2], cpu_T[0], 0xf); \
3385 GEN_CRLOGIC(and, 0x08);
3387 GEN_CRLOGIC(andc, 0x04);
3389 GEN_CRLOGIC(eqv, 0x09);
3391 GEN_CRLOGIC(nand, 0x07);
3393 GEN_CRLOGIC(nor, 0x01);
3395 GEN_CRLOGIC(or, 0x0E);
3397 GEN_CRLOGIC(orc, 0x0D);
3399 GEN_CRLOGIC(xor, 0x06);
3401 GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER)
3403 tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]);
3406 /*** System linkage ***/
3407 /* rfi (supervisor only) */
3408 GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW)
3410 #if defined(CONFIG_USER_ONLY)
3411 GEN_EXCP_PRIVOPC(ctx);
3413 /* Restore CPU state */
3414 if (unlikely(!ctx->supervisor)) {
3415 GEN_EXCP_PRIVOPC(ctx);
3423 #if defined(TARGET_PPC64)
3424 GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B)
3426 #if defined(CONFIG_USER_ONLY)
3427 GEN_EXCP_PRIVOPC(ctx);
3429 /* Restore CPU state */
3430 if (unlikely(!ctx->supervisor)) {
3431 GEN_EXCP_PRIVOPC(ctx);
3439 GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H)
3441 #if defined(CONFIG_USER_ONLY)
3442 GEN_EXCP_PRIVOPC(ctx);
3444 /* Restore CPU state */
3445 if (unlikely(ctx->supervisor <= 1)) {
3446 GEN_EXCP_PRIVOPC(ctx);
3456 #if defined(CONFIG_USER_ONLY)
3457 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3459 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3461 GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW)
3465 lev = (ctx->opcode >> 5) & 0x7F;
3466 GEN_EXCP(ctx, POWERPC_SYSCALL, lev);
3471 GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW)
3473 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
3474 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
3475 /* Update the nip since this might generate a trap exception */
3476 gen_update_nip(ctx, ctx->nip);
3477 gen_op_tw(TO(ctx->opcode));
3481 GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
3483 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
3484 tcg_gen_movi_tl(cpu_T[1], SIMM(ctx->opcode));
3485 /* Update the nip since this might generate a trap exception */
3486 gen_update_nip(ctx, ctx->nip);
3487 gen_op_tw(TO(ctx->opcode));
3490 #if defined(TARGET_PPC64)
3492 GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B)
3494 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
3495 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
3496 /* Update the nip since this might generate a trap exception */
3497 gen_update_nip(ctx, ctx->nip);
3498 gen_op_td(TO(ctx->opcode));
3502 GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B)
3504 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
3505 tcg_gen_movi_tl(cpu_T[1], SIMM(ctx->opcode));
3506 /* Update the nip since this might generate a trap exception */
3507 gen_update_nip(ctx, ctx->nip);
3508 gen_op_td(TO(ctx->opcode));
3512 /*** Processor control ***/
3514 GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC)
3516 tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], cpu_xer);
3517 tcg_gen_shri_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], XER_CA);
3518 tcg_gen_andi_i32(cpu_xer, cpu_xer, ~(1 << XER_SO | 1 << XER_OV | 1 << XER_CA));
3522 GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC)
3526 if (likely(ctx->opcode & 0x00100000)) {
3527 crm = CRM(ctx->opcode);
3528 if (likely((crm ^ (crm - 1)) == 0)) {
3530 tcg_gen_mov_i32(cpu_T[0], cpu_crf[7 - crn]);
3535 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
3539 GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC)
3541 #if defined(CONFIG_USER_ONLY)
3542 GEN_EXCP_PRIVREG(ctx);
3544 if (unlikely(!ctx->supervisor)) {
3545 GEN_EXCP_PRIVREG(ctx);
3549 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
3554 #define SPR_NOACCESS ((void *)(-1UL))
3556 static void spr_noaccess (void *opaque, int sprn)
3558 sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
3559 printf("ERROR: try to access SPR %d !\n", sprn);
3561 #define SPR_NOACCESS (&spr_noaccess)
3565 static always_inline void gen_op_mfspr (DisasContext *ctx)
3567 void (*read_cb)(void *opaque, int sprn);
3568 uint32_t sprn = SPR(ctx->opcode);
3570 #if !defined(CONFIG_USER_ONLY)
3571 if (ctx->supervisor == 2)
3572 read_cb = ctx->spr_cb[sprn].hea_read;
3573 else if (ctx->supervisor)
3574 read_cb = ctx->spr_cb[sprn].oea_read;
3577 read_cb = ctx->spr_cb[sprn].uea_read;
3578 if (likely(read_cb != NULL)) {
3579 if (likely(read_cb != SPR_NOACCESS)) {
3580 (*read_cb)(ctx, sprn);
3581 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
3583 /* Privilege exception */
3584 /* This is a hack to avoid warnings when running Linux:
3585 * this OS breaks the PowerPC virtualisation model,
3586 * allowing userland application to read the PVR
3588 if (sprn != SPR_PVR) {
3589 if (loglevel != 0) {
3590 fprintf(logfile, "Trying to read privileged spr %d %03x at "
3591 ADDRX "\n", sprn, sprn, ctx->nip);
3593 printf("Trying to read privileged spr %d %03x at " ADDRX "\n",
3594 sprn, sprn, ctx->nip);
3596 GEN_EXCP_PRIVREG(ctx);
3600 if (loglevel != 0) {
3601 fprintf(logfile, "Trying to read invalid spr %d %03x at "
3602 ADDRX "\n", sprn, sprn, ctx->nip);
3604 printf("Trying to read invalid spr %d %03x at " ADDRX "\n",
3605 sprn, sprn, ctx->nip);
3606 GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM,
3607 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_SPR);
3611 GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC)
3617 GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB)
3623 GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC)
3627 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
3628 crm = CRM(ctx->opcode);
3629 if (likely((ctx->opcode & 0x00100000) || (crm ^ (crm - 1)) == 0)) {
3631 gen_op_srli_T0(crn * 4);
3632 tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_T[0], 0xf);
3634 gen_op_store_cr(crm);
3639 #if defined(TARGET_PPC64)
3640 GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B)
3642 #if defined(CONFIG_USER_ONLY)
3643 GEN_EXCP_PRIVREG(ctx);
3645 if (unlikely(!ctx->supervisor)) {
3646 GEN_EXCP_PRIVREG(ctx);
3649 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
3650 if (ctx->opcode & 0x00010000) {
3651 /* Special form that does not need any synchronisation */
3652 gen_op_update_riee();
3654 /* XXX: we need to update nip before the store
3655 * if we enter power saving mode, we will exit the loop
3656 * directly from ppc_store_msr
3658 gen_update_nip(ctx, ctx->nip);
3660 /* Must stop the translation as machine state (may have) changed */
3661 /* Note that mtmsr is not always defined as context-synchronizing */
3662 ctx->exception = POWERPC_EXCP_STOP;
3668 GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC)
3670 #if defined(CONFIG_USER_ONLY)
3671 GEN_EXCP_PRIVREG(ctx);
3673 if (unlikely(!ctx->supervisor)) {
3674 GEN_EXCP_PRIVREG(ctx);
3677 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
3678 if (ctx->opcode & 0x00010000) {
3679 /* Special form that does not need any synchronisation */
3680 gen_op_update_riee();
3682 /* XXX: we need to update nip before the store
3683 * if we enter power saving mode, we will exit the loop
3684 * directly from ppc_store_msr
3686 gen_update_nip(ctx, ctx->nip);
3687 #if defined(TARGET_PPC64)
3689 gen_op_store_msr_32();
3693 /* Must stop the translation as machine state (may have) changed */
3694 /* Note that mtmsrd is not always defined as context-synchronizing */
3695 ctx->exception = POWERPC_EXCP_STOP;
3701 GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC)
3703 void (*write_cb)(void *opaque, int sprn);
3704 uint32_t sprn = SPR(ctx->opcode);
3706 #if !defined(CONFIG_USER_ONLY)
3707 if (ctx->supervisor == 2)
3708 write_cb = ctx->spr_cb[sprn].hea_write;
3709 else if (ctx->supervisor)
3710 write_cb = ctx->spr_cb[sprn].oea_write;
3713 write_cb = ctx->spr_cb[sprn].uea_write;
3714 if (likely(write_cb != NULL)) {
3715 if (likely(write_cb != SPR_NOACCESS)) {
3716 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
3717 (*write_cb)(ctx, sprn);
3719 /* Privilege exception */
3720 if (loglevel != 0) {
3721 fprintf(logfile, "Trying to write privileged spr %d %03x at "
3722 ADDRX "\n", sprn, sprn, ctx->nip);
3724 printf("Trying to write privileged spr %d %03x at " ADDRX "\n",
3725 sprn, sprn, ctx->nip);
3726 GEN_EXCP_PRIVREG(ctx);
3730 if (loglevel != 0) {
3731 fprintf(logfile, "Trying to write invalid spr %d %03x at "
3732 ADDRX "\n", sprn, sprn, ctx->nip);
3734 printf("Trying to write invalid spr %d %03x at " ADDRX "\n",
3735 sprn, sprn, ctx->nip);
3736 GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM,
3737 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_SPR);
3741 /*** Cache management ***/
3743 GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE)
3745 /* XXX: specification says this is treated as a load by the MMU */
3746 TCGv temp = tcg_temp_new(TCG_TYPE_TL);
3747 gen_addr_reg_index(temp, ctx);
3748 gen_qemu_ld8u(temp, temp, ctx->mem_idx);
3749 tcg_temp_free(temp);
3752 /* dcbi (Supervisor only) */
3753 GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE)
3755 #if defined(CONFIG_USER_ONLY)
3756 GEN_EXCP_PRIVOPC(ctx);
3759 if (unlikely(!ctx->supervisor)) {
3760 GEN_EXCP_PRIVOPC(ctx);
3763 EA = tcg_temp_new(TCG_TYPE_TL);
3764 gen_addr_reg_index(EA, ctx);
3765 val = tcg_temp_new(TCG_TYPE_TL);
3766 /* XXX: specification says this should be treated as a store by the MMU */
3767 gen_qemu_ld8u(val, EA, ctx->mem_idx);
3768 gen_qemu_st8(val, EA, ctx->mem_idx);
3775 GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE)
3777 /* XXX: specification say this is treated as a load by the MMU */
3778 TCGv temp = tcg_temp_new(TCG_TYPE_TL);
3779 gen_addr_reg_index(temp, ctx);
3780 gen_qemu_ld8u(temp, temp, ctx->mem_idx);
3781 tcg_temp_free(temp);
3785 GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE)
3787 /* interpreted as no-op */
3788 /* XXX: specification say this is treated as a load by the MMU
3789 * but does not generate any exception
3794 GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE)
3796 /* interpreted as no-op */
3797 /* XXX: specification say this is treated as a load by the MMU
3798 * but does not generate any exception
3803 #define op_dcbz(n) (*gen_op_dcbz[n][ctx->mem_idx])()
3804 static GenOpFunc *gen_op_dcbz[4][NB_MEM_FUNCS] = {
3805 /* 32 bytes cache line size */
3807 #define gen_op_dcbz_l32_le_raw gen_op_dcbz_l32_raw
3808 #define gen_op_dcbz_l32_le_user gen_op_dcbz_l32_user
3809 #define gen_op_dcbz_l32_le_kernel gen_op_dcbz_l32_kernel
3810 #define gen_op_dcbz_l32_le_hypv gen_op_dcbz_l32_hypv
3811 #define gen_op_dcbz_l32_le_64_raw gen_op_dcbz_l32_64_raw
3812 #define gen_op_dcbz_l32_le_64_user gen_op_dcbz_l32_64_user
3813 #define gen_op_dcbz_l32_le_64_kernel gen_op_dcbz_l32_64_kernel
3814 #define gen_op_dcbz_l32_le_64_hypv gen_op_dcbz_l32_64_hypv
3815 GEN_MEM_FUNCS(dcbz_l32),
3817 /* 64 bytes cache line size */
3819 #define gen_op_dcbz_l64_le_raw gen_op_dcbz_l64_raw
3820 #define gen_op_dcbz_l64_le_user gen_op_dcbz_l64_user
3821 #define gen_op_dcbz_l64_le_kernel gen_op_dcbz_l64_kernel
3822 #define gen_op_dcbz_l64_le_hypv gen_op_dcbz_l64_hypv
3823 #define gen_op_dcbz_l64_le_64_raw gen_op_dcbz_l64_64_raw
3824 #define gen_op_dcbz_l64_le_64_user gen_op_dcbz_l64_64_user
3825 #define gen_op_dcbz_l64_le_64_kernel gen_op_dcbz_l64_64_kernel
3826 #define gen_op_dcbz_l64_le_64_hypv gen_op_dcbz_l64_64_hypv
3827 GEN_MEM_FUNCS(dcbz_l64),
3829 /* 128 bytes cache line size */
3831 #define gen_op_dcbz_l128_le_raw gen_op_dcbz_l128_raw
3832 #define gen_op_dcbz_l128_le_user gen_op_dcbz_l128_user
3833 #define gen_op_dcbz_l128_le_kernel gen_op_dcbz_l128_kernel
3834 #define gen_op_dcbz_l128_le_hypv gen_op_dcbz_l128_hypv
3835 #define gen_op_dcbz_l128_le_64_raw gen_op_dcbz_l128_64_raw
3836 #define gen_op_dcbz_l128_le_64_user gen_op_dcbz_l128_64_user
3837 #define gen_op_dcbz_l128_le_64_kernel gen_op_dcbz_l128_64_kernel
3838 #define gen_op_dcbz_l128_le_64_hypv gen_op_dcbz_l128_64_hypv
3839 GEN_MEM_FUNCS(dcbz_l128),
3841 /* tunable cache line size */
3843 #define gen_op_dcbz_le_raw gen_op_dcbz_raw
3844 #define gen_op_dcbz_le_user gen_op_dcbz_user
3845 #define gen_op_dcbz_le_kernel gen_op_dcbz_kernel
3846 #define gen_op_dcbz_le_hypv gen_op_dcbz_hypv
3847 #define gen_op_dcbz_le_64_raw gen_op_dcbz_64_raw
3848 #define gen_op_dcbz_le_64_user gen_op_dcbz_64_user
3849 #define gen_op_dcbz_le_64_kernel gen_op_dcbz_64_kernel
3850 #define gen_op_dcbz_le_64_hypv gen_op_dcbz_64_hypv
3851 GEN_MEM_FUNCS(dcbz),
3855 static always_inline void handler_dcbz (DisasContext *ctx,
3856 int dcache_line_size)
3860 switch (dcache_line_size) {
3877 GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE_DCBZ)
3879 gen_addr_reg_index(cpu_T[0], ctx);
3880 handler_dcbz(ctx, ctx->dcache_line_size);
3881 gen_op_check_reservation();
3884 GEN_HANDLER2(dcbz_970, "dcbz", 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZT)
3886 gen_addr_reg_index(cpu_T[0], ctx);
3887 if (ctx->opcode & 0x00200000)
3888 handler_dcbz(ctx, ctx->dcache_line_size);
3890 handler_dcbz(ctx, -1);
3891 gen_op_check_reservation();
3895 #define op_icbi() (*gen_op_icbi[ctx->mem_idx])()
3896 #define gen_op_icbi_le_raw gen_op_icbi_raw
3897 #define gen_op_icbi_le_user gen_op_icbi_user
3898 #define gen_op_icbi_le_kernel gen_op_icbi_kernel
3899 #define gen_op_icbi_le_hypv gen_op_icbi_hypv
3900 #define gen_op_icbi_le_64_raw gen_op_icbi_64_raw
3901 #define gen_op_icbi_le_64_user gen_op_icbi_64_user
3902 #define gen_op_icbi_le_64_kernel gen_op_icbi_64_kernel
3903 #define gen_op_icbi_le_64_hypv gen_op_icbi_64_hypv
3904 static GenOpFunc *gen_op_icbi[NB_MEM_FUNCS] = {
3905 GEN_MEM_FUNCS(icbi),
3908 GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI)
3910 /* NIP cannot be restored if the memory exception comes from an helper */
3911 gen_update_nip(ctx, ctx->nip - 4);
3912 gen_addr_reg_index(cpu_T[0], ctx);
3918 GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA)
3920 /* interpreted as no-op */
3921 /* XXX: specification say this is treated as a store by the MMU
3922 * but does not generate any exception
3926 /*** Segment register manipulation ***/
3927 /* Supervisor only: */
3929 GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT)
3931 #if defined(CONFIG_USER_ONLY)
3932 GEN_EXCP_PRIVREG(ctx);
3934 if (unlikely(!ctx->supervisor)) {
3935 GEN_EXCP_PRIVREG(ctx);
3938 tcg_gen_movi_tl(cpu_T[1], SR(ctx->opcode));
3940 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
3945 GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT)
3947 #if defined(CONFIG_USER_ONLY)
3948 GEN_EXCP_PRIVREG(ctx);
3950 if (unlikely(!ctx->supervisor)) {
3951 GEN_EXCP_PRIVREG(ctx);
3954 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
3957 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
3962 GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT)
3964 #if defined(CONFIG_USER_ONLY)
3965 GEN_EXCP_PRIVREG(ctx);
3967 if (unlikely(!ctx->supervisor)) {
3968 GEN_EXCP_PRIVREG(ctx);
3971 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
3972 tcg_gen_movi_tl(cpu_T[1], SR(ctx->opcode));
3978 GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT)
3980 #if defined(CONFIG_USER_ONLY)
3981 GEN_EXCP_PRIVREG(ctx);
3983 if (unlikely(!ctx->supervisor)) {
3984 GEN_EXCP_PRIVREG(ctx);
3987 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
3988 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
3994 #if defined(TARGET_PPC64)
3995 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
3997 GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B)
3999 #if defined(CONFIG_USER_ONLY)
4000 GEN_EXCP_PRIVREG(ctx);
4002 if (unlikely(!ctx->supervisor)) {
4003 GEN_EXCP_PRIVREG(ctx);
4006 tcg_gen_movi_tl(cpu_T[1], SR(ctx->opcode));
4008 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4013 GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
4016 #if defined(CONFIG_USER_ONLY)
4017 GEN_EXCP_PRIVREG(ctx);
4019 if (unlikely(!ctx->supervisor)) {
4020 GEN_EXCP_PRIVREG(ctx);
4023 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4026 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4031 GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B)
4033 #if defined(CONFIG_USER_ONLY)
4034 GEN_EXCP_PRIVREG(ctx);
4036 if (unlikely(!ctx->supervisor)) {
4037 GEN_EXCP_PRIVREG(ctx);
4040 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4041 tcg_gen_movi_tl(cpu_T[1], SR(ctx->opcode));
4047 GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
4050 #if defined(CONFIG_USER_ONLY)
4051 GEN_EXCP_PRIVREG(ctx);
4053 if (unlikely(!ctx->supervisor)) {
4054 GEN_EXCP_PRIVREG(ctx);
4057 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4058 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4063 #endif /* defined(TARGET_PPC64) */
4065 /*** Lookaside buffer management ***/
4066 /* Optional & supervisor only: */
4068 GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA)
4070 #if defined(CONFIG_USER_ONLY)
4071 GEN_EXCP_PRIVOPC(ctx);
4073 if (unlikely(!ctx->supervisor)) {
4074 GEN_EXCP_PRIVOPC(ctx);
4082 GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE)
4084 #if defined(CONFIG_USER_ONLY)
4085 GEN_EXCP_PRIVOPC(ctx);
4087 if (unlikely(!ctx->supervisor)) {
4088 GEN_EXCP_PRIVOPC(ctx);
4091 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4092 #if defined(TARGET_PPC64)
4102 GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC)
4104 #if defined(CONFIG_USER_ONLY)
4105 GEN_EXCP_PRIVOPC(ctx);
4107 if (unlikely(!ctx->supervisor)) {
4108 GEN_EXCP_PRIVOPC(ctx);
4111 /* This has no effect: it should ensure that all previous
4112 * tlbie have completed
4118 #if defined(TARGET_PPC64)
4120 GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI)
4122 #if defined(CONFIG_USER_ONLY)
4123 GEN_EXCP_PRIVOPC(ctx);
4125 if (unlikely(!ctx->supervisor)) {
4126 GEN_EXCP_PRIVOPC(ctx);
4134 GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI)
4136 #if defined(CONFIG_USER_ONLY)
4137 GEN_EXCP_PRIVOPC(ctx);
4139 if (unlikely(!ctx->supervisor)) {
4140 GEN_EXCP_PRIVOPC(ctx);
4143 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4149 /*** External control ***/
4151 #define op_eciwx() (*gen_op_eciwx[ctx->mem_idx])()
4152 #define op_ecowx() (*gen_op_ecowx[ctx->mem_idx])()
4153 static GenOpFunc *gen_op_eciwx[NB_MEM_FUNCS] = {
4154 GEN_MEM_FUNCS(eciwx),
4156 static GenOpFunc *gen_op_ecowx[NB_MEM_FUNCS] = {
4157 GEN_MEM_FUNCS(ecowx),
4161 GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN)
4163 /* Should check EAR[E] & alignment ! */
4164 gen_addr_reg_index(cpu_T[0], ctx);
4166 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4170 GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN)
4172 /* Should check EAR[E] & alignment ! */
4173 gen_addr_reg_index(cpu_T[0], ctx);
4174 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
4178 /* PowerPC 601 specific instructions */
4180 GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR)
4182 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4184 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4185 if (unlikely(Rc(ctx->opcode) != 0))
4190 GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR)
4192 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4193 gen_op_POWER_abso();
4194 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4195 if (unlikely(Rc(ctx->opcode) != 0))
4200 GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR)
4202 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4203 gen_op_POWER_clcs();
4204 /* Rc=1 sets CR0 to an undefined state */
4205 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4209 GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR)
4211 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4212 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4214 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4215 if (unlikely(Rc(ctx->opcode) != 0))
4220 GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR)
4222 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4223 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4224 gen_op_POWER_divo();
4225 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4226 if (unlikely(Rc(ctx->opcode) != 0))
4231 GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR)
4233 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4234 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4235 gen_op_POWER_divs();
4236 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4237 if (unlikely(Rc(ctx->opcode) != 0))
4241 /* divso - divso. */
4242 GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR)
4244 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4245 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4246 gen_op_POWER_divso();
4247 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4248 if (unlikely(Rc(ctx->opcode) != 0))
4253 GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR)
4255 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4256 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4258 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4259 if (unlikely(Rc(ctx->opcode) != 0))
4264 GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR)
4266 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4267 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4268 gen_op_POWER_dozo();
4269 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4270 if (unlikely(Rc(ctx->opcode) != 0))
4275 GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR)
4277 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4278 tcg_gen_movi_tl(cpu_T[1], SIMM(ctx->opcode));
4280 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4283 /* As lscbx load from memory byte after byte, it's always endian safe.
4284 * Original POWER is 32 bits only, define 64 bits ops as 32 bits ones
4286 #define op_POWER_lscbx(start, ra, rb) \
4287 (*gen_op_POWER_lscbx[ctx->mem_idx])(start, ra, rb)
4288 #define gen_op_POWER_lscbx_64_raw gen_op_POWER_lscbx_raw
4289 #define gen_op_POWER_lscbx_64_user gen_op_POWER_lscbx_user
4290 #define gen_op_POWER_lscbx_64_kernel gen_op_POWER_lscbx_kernel
4291 #define gen_op_POWER_lscbx_64_hypv gen_op_POWER_lscbx_hypv
4292 #define gen_op_POWER_lscbx_le_raw gen_op_POWER_lscbx_raw
4293 #define gen_op_POWER_lscbx_le_user gen_op_POWER_lscbx_user
4294 #define gen_op_POWER_lscbx_le_kernel gen_op_POWER_lscbx_kernel
4295 #define gen_op_POWER_lscbx_le_hypv gen_op_POWER_lscbx_hypv
4296 #define gen_op_POWER_lscbx_le_64_raw gen_op_POWER_lscbx_raw
4297 #define gen_op_POWER_lscbx_le_64_user gen_op_POWER_lscbx_user
4298 #define gen_op_POWER_lscbx_le_64_kernel gen_op_POWER_lscbx_kernel
4299 #define gen_op_POWER_lscbx_le_64_hypv gen_op_POWER_lscbx_hypv
4300 static GenOpFunc3 *gen_op_POWER_lscbx[NB_MEM_FUNCS] = {
4301 GEN_MEM_FUNCS(POWER_lscbx),
4304 /* lscbx - lscbx. */
4305 GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR)
4307 int ra = rA(ctx->opcode);
4308 int rb = rB(ctx->opcode);
4310 gen_addr_reg_index(cpu_T[0], ctx);
4314 /* NIP cannot be restored if the memory exception comes from an helper */
4315 gen_update_nip(ctx, ctx->nip - 4);
4316 tcg_gen_andi_tl(cpu_T[1], cpu_xer, 0x7F);
4317 tcg_gen_shri_tl(cpu_T[2], cpu_xer, XER_CMP);
4318 tcg_gen_andi_tl(cpu_T[2], cpu_T[2], 0xFF);
4319 op_POWER_lscbx(rD(ctx->opcode), ra, rb);
4320 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
4321 tcg_gen_or_tl(cpu_xer, cpu_xer, cpu_T[0]);
4322 if (unlikely(Rc(ctx->opcode) != 0))
4326 /* maskg - maskg. */
4327 GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR)
4329 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4330 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4331 gen_op_POWER_maskg();
4332 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4333 if (unlikely(Rc(ctx->opcode) != 0))
4337 /* maskir - maskir. */
4338 GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR)
4340 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4341 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
4342 tcg_gen_mov_tl(cpu_T[2], cpu_gpr[rB(ctx->opcode)]);
4343 gen_op_POWER_maskir();
4344 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4345 if (unlikely(Rc(ctx->opcode) != 0))
4350 GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR)
4352 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4353 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4355 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4356 if (unlikely(Rc(ctx->opcode) != 0))
4361 GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR)
4363 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4364 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4365 gen_op_POWER_mulo();
4366 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4367 if (unlikely(Rc(ctx->opcode) != 0))
4372 GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR)
4374 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4375 gen_op_POWER_nabs();
4376 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4377 if (unlikely(Rc(ctx->opcode) != 0))
4381 /* nabso - nabso. */
4382 GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR)
4384 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4385 gen_op_POWER_nabso();
4386 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4387 if (unlikely(Rc(ctx->opcode) != 0))
4392 GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR)
4396 mb = MB(ctx->opcode);
4397 me = ME(ctx->opcode);
4398 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4399 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rA(ctx->opcode)]);
4400 tcg_gen_mov_tl(cpu_T[2], cpu_gpr[rB(ctx->opcode)]);
4401 gen_op_POWER_rlmi(MASK(mb, me), ~MASK(mb, me));
4402 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4403 if (unlikely(Rc(ctx->opcode) != 0))
4408 GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR)
4410 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4411 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rA(ctx->opcode)]);
4412 tcg_gen_mov_tl(cpu_T[2], cpu_gpr[rB(ctx->opcode)]);
4413 gen_op_POWER_rrib();
4414 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4415 if (unlikely(Rc(ctx->opcode) != 0))
4420 GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR)
4422 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4423 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4425 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4426 if (unlikely(Rc(ctx->opcode) != 0))
4431 GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR)
4433 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4434 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4435 gen_op_POWER_sleq();
4436 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4437 if (unlikely(Rc(ctx->opcode) != 0))
4442 GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR)
4444 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4445 tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4447 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4448 if (unlikely(Rc(ctx->opcode) != 0))
4452 /* slliq - slliq. */
4453 GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR)
4455 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4456 tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4457 gen_op_POWER_sleq();
4458 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4459 if (unlikely(Rc(ctx->opcode) != 0))
4464 GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR)
4466 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4467 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4468 gen_op_POWER_sllq();
4469 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4470 if (unlikely(Rc(ctx->opcode) != 0))
4475 GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR)
4477 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4478 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4480 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4481 if (unlikely(Rc(ctx->opcode) != 0))
4485 /* sraiq - sraiq. */
4486 GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR)
4488 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4489 tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4490 gen_op_POWER_sraq();
4491 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4492 if (unlikely(Rc(ctx->opcode) != 0))
4497 GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR)
4499 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4500 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4501 gen_op_POWER_sraq();
4502 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4503 if (unlikely(Rc(ctx->opcode) != 0))
4508 GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR)
4510 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4511 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4513 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4514 if (unlikely(Rc(ctx->opcode) != 0))
4519 GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR)
4521 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4522 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4523 gen_op_POWER_srea();
4524 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4525 if (unlikely(Rc(ctx->opcode) != 0))
4530 GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR)
4532 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4533 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4534 gen_op_POWER_sreq();
4535 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4536 if (unlikely(Rc(ctx->opcode) != 0))
4541 GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR)
4543 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4544 tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4546 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4547 if (unlikely(Rc(ctx->opcode) != 0))
4552 GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR)
4554 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4555 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4556 tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4557 gen_op_POWER_srlq();
4558 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4559 if (unlikely(Rc(ctx->opcode) != 0))
4564 GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR)
4566 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4567 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4568 gen_op_POWER_srlq();
4569 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4570 if (unlikely(Rc(ctx->opcode) != 0))
4575 GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR)
4577 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4578 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4580 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4581 if (unlikely(Rc(ctx->opcode) != 0))
4585 /* PowerPC 602 specific instructions */
4587 GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC)
4590 GEN_EXCP_INVAL(ctx);
4594 GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC)
4597 GEN_EXCP_INVAL(ctx);
4601 GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC)
4603 #if defined(CONFIG_USER_ONLY)
4604 GEN_EXCP_PRIVOPC(ctx);
4606 if (unlikely(!ctx->supervisor)) {
4607 GEN_EXCP_PRIVOPC(ctx);
4610 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4612 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4616 /* 602 - 603 - G2 TLB management */
4618 GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB)
4620 #if defined(CONFIG_USER_ONLY)
4621 GEN_EXCP_PRIVOPC(ctx);
4623 if (unlikely(!ctx->supervisor)) {
4624 GEN_EXCP_PRIVOPC(ctx);
4627 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4633 GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB)
4635 #if defined(CONFIG_USER_ONLY)
4636 GEN_EXCP_PRIVOPC(ctx);
4638 if (unlikely(!ctx->supervisor)) {
4639 GEN_EXCP_PRIVOPC(ctx);
4642 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4647 /* 74xx TLB management */
4649 GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB)
4651 #if defined(CONFIG_USER_ONLY)
4652 GEN_EXCP_PRIVOPC(ctx);
4654 if (unlikely(!ctx->supervisor)) {
4655 GEN_EXCP_PRIVOPC(ctx);
4658 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4659 gen_op_74xx_tlbld();
4664 GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB)
4666 #if defined(CONFIG_USER_ONLY)
4667 GEN_EXCP_PRIVOPC(ctx);
4669 if (unlikely(!ctx->supervisor)) {
4670 GEN_EXCP_PRIVOPC(ctx);
4673 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4674 gen_op_74xx_tlbli();
4678 /* POWER instructions not in PowerPC 601 */
4680 GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER)
4682 /* Cache line flush: implemented as no-op */
4686 GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER)
4688 /* Cache line invalidate: privileged and treated as no-op */
4689 #if defined(CONFIG_USER_ONLY)
4690 GEN_EXCP_PRIVOPC(ctx);
4692 if (unlikely(!ctx->supervisor)) {
4693 GEN_EXCP_PRIVOPC(ctx);
4700 GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER)
4702 /* Data cache line store: treated as no-op */
4705 GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER)
4707 #if defined(CONFIG_USER_ONLY)
4708 GEN_EXCP_PRIVOPC(ctx);
4710 if (unlikely(!ctx->supervisor)) {
4711 GEN_EXCP_PRIVOPC(ctx);
4714 int ra = rA(ctx->opcode);
4715 int rd = rD(ctx->opcode);
4717 gen_addr_reg_index(cpu_T[0], ctx);
4718 gen_op_POWER_mfsri();
4719 tcg_gen_mov_tl(cpu_gpr[rd], cpu_T[0]);
4720 if (ra != 0 && ra != rd)
4721 tcg_gen_mov_tl(cpu_gpr[ra], cpu_T[1]);
4725 GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER)
4727 #if defined(CONFIG_USER_ONLY)
4728 GEN_EXCP_PRIVOPC(ctx);
4730 if (unlikely(!ctx->supervisor)) {
4731 GEN_EXCP_PRIVOPC(ctx);
4734 gen_addr_reg_index(cpu_T[0], ctx);
4736 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4740 GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER)
4742 #if defined(CONFIG_USER_ONLY)
4743 GEN_EXCP_PRIVOPC(ctx);
4745 if (unlikely(!ctx->supervisor)) {
4746 GEN_EXCP_PRIVOPC(ctx);
4749 gen_op_POWER_rfsvc();
4754 /* svc is not implemented for now */
4756 /* POWER2 specific instructions */
4757 /* Quad manipulation (load/store two floats at a time) */
4758 /* Original POWER2 is 32 bits only, define 64 bits ops as 32 bits ones */
4759 #define op_POWER2_lfq() (*gen_op_POWER2_lfq[ctx->mem_idx])()
4760 #define op_POWER2_stfq() (*gen_op_POWER2_stfq[ctx->mem_idx])()
4761 #define gen_op_POWER2_lfq_64_raw gen_op_POWER2_lfq_raw
4762 #define gen_op_POWER2_lfq_64_user gen_op_POWER2_lfq_user
4763 #define gen_op_POWER2_lfq_64_kernel gen_op_POWER2_lfq_kernel
4764 #define gen_op_POWER2_lfq_64_hypv gen_op_POWER2_lfq_hypv
4765 #define gen_op_POWER2_lfq_le_64_raw gen_op_POWER2_lfq_le_raw
4766 #define gen_op_POWER2_lfq_le_64_user gen_op_POWER2_lfq_le_user
4767 #define gen_op_POWER2_lfq_le_64_kernel gen_op_POWER2_lfq_le_kernel
4768 #define gen_op_POWER2_lfq_le_64_hypv gen_op_POWER2_lfq_le_hypv
4769 #define gen_op_POWER2_stfq_64_raw gen_op_POWER2_stfq_raw
4770 #define gen_op_POWER2_stfq_64_user gen_op_POWER2_stfq_user
4771 #define gen_op_POWER2_stfq_64_kernel gen_op_POWER2_stfq_kernel
4772 #define gen_op_POWER2_stfq_64_hypv gen_op_POWER2_stfq_hypv
4773 #define gen_op_POWER2_stfq_le_64_raw gen_op_POWER2_stfq_le_raw
4774 #define gen_op_POWER2_stfq_le_64_user gen_op_POWER2_stfq_le_user
4775 #define gen_op_POWER2_stfq_le_64_kernel gen_op_POWER2_stfq_le_kernel
4776 #define gen_op_POWER2_stfq_le_64_hypv gen_op_POWER2_stfq_le_hypv
4777 static GenOpFunc *gen_op_POWER2_lfq[NB_MEM_FUNCS] = {
4778 GEN_MEM_FUNCS(POWER2_lfq),
4780 static GenOpFunc *gen_op_POWER2_stfq[NB_MEM_FUNCS] = {
4781 GEN_MEM_FUNCS(POWER2_stfq),
4785 GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
4787 /* NIP cannot be restored if the memory exception comes from an helper */
4788 gen_update_nip(ctx, ctx->nip - 4);
4789 gen_addr_imm_index(cpu_T[0], ctx, 0);
4791 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
4792 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode) + 1], cpu_FT[1]);
4796 GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
4798 int ra = rA(ctx->opcode);
4800 /* NIP cannot be restored if the memory exception comes from an helper */
4801 gen_update_nip(ctx, ctx->nip - 4);
4802 gen_addr_imm_index(cpu_T[0], ctx, 0);
4804 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
4805 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode) + 1], cpu_FT[1]);
4807 tcg_gen_mov_tl(cpu_gpr[ra], cpu_T[0]);
4811 GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2)
4813 int ra = rA(ctx->opcode);
4815 /* NIP cannot be restored if the memory exception comes from an helper */
4816 gen_update_nip(ctx, ctx->nip - 4);
4817 gen_addr_reg_index(cpu_T[0], ctx);
4819 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
4820 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode) + 1], cpu_FT[1]);
4822 tcg_gen_mov_tl(cpu_gpr[ra], cpu_T[0]);
4826 GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2)
4828 /* NIP cannot be restored if the memory exception comes from an helper */
4829 gen_update_nip(ctx, ctx->nip - 4);
4830 gen_addr_reg_index(cpu_T[0], ctx);
4832 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
4833 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode) + 1], cpu_FT[1]);
4837 GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
4839 /* NIP cannot be restored if the memory exception comes from an helper */
4840 gen_update_nip(ctx, ctx->nip - 4);
4841 gen_addr_imm_index(cpu_T[0], ctx, 0);
4842 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]);
4843 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rS(ctx->opcode) + 1]);
4848 GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
4850 int ra = rA(ctx->opcode);
4852 /* NIP cannot be restored if the memory exception comes from an helper */
4853 gen_update_nip(ctx, ctx->nip - 4);
4854 gen_addr_imm_index(cpu_T[0], ctx, 0);
4855 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]);
4856 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rS(ctx->opcode) + 1]);
4859 tcg_gen_mov_tl(cpu_gpr[ra], cpu_T[0]);
4863 GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2)
4865 int ra = rA(ctx->opcode);
4867 /* NIP cannot be restored if the memory exception comes from an helper */
4868 gen_update_nip(ctx, ctx->nip - 4);
4869 gen_addr_reg_index(cpu_T[0], ctx);
4870 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]);
4871 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rS(ctx->opcode) + 1]);
4874 tcg_gen_mov_tl(cpu_gpr[ra], cpu_T[0]);
4878 GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2)
4880 /* NIP cannot be restored if the memory exception comes from an helper */
4881 gen_update_nip(ctx, ctx->nip - 4);
4882 gen_addr_reg_index(cpu_T[0], ctx);
4883 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]);
4884 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rS(ctx->opcode) + 1]);
4888 /* BookE specific instructions */
4889 /* XXX: not implemented on 440 ? */
4890 GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI)
4893 GEN_EXCP_INVAL(ctx);
4896 /* XXX: not implemented on 440 ? */
4897 GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA)
4899 #if defined(CONFIG_USER_ONLY)
4900 GEN_EXCP_PRIVOPC(ctx);
4902 if (unlikely(!ctx->supervisor)) {
4903 GEN_EXCP_PRIVOPC(ctx);
4906 gen_addr_reg_index(cpu_T[0], ctx);
4907 /* Use the same micro-ops as for tlbie */
4908 #if defined(TARGET_PPC64)
4917 /* All 405 MAC instructions are translated here */
4918 static always_inline void gen_405_mulladd_insn (DisasContext *ctx,
4920 int ra, int rb, int rt, int Rc)
4922 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[ra]);
4923 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rb]);
4924 switch (opc3 & 0x0D) {
4926 /* macchw - macchw. - macchwo - macchwo. */
4927 /* macchws - macchws. - macchwso - macchwso. */
4928 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
4929 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
4930 /* mulchw - mulchw. */
4931 gen_op_405_mulchw();
4934 /* macchwu - macchwu. - macchwuo - macchwuo. */
4935 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
4936 /* mulchwu - mulchwu. */
4937 gen_op_405_mulchwu();
4940 /* machhw - machhw. - machhwo - machhwo. */
4941 /* machhws - machhws. - machhwso - machhwso. */
4942 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
4943 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
4944 /* mulhhw - mulhhw. */
4945 gen_op_405_mulhhw();
4948 /* machhwu - machhwu. - machhwuo - machhwuo. */
4949 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
4950 /* mulhhwu - mulhhwu. */
4951 gen_op_405_mulhhwu();
4954 /* maclhw - maclhw. - maclhwo - maclhwo. */
4955 /* maclhws - maclhws. - maclhwso - maclhwso. */
4956 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
4957 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
4958 /* mullhw - mullhw. */
4959 gen_op_405_mullhw();
4962 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
4963 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
4964 /* mullhwu - mullhwu. */
4965 gen_op_405_mullhwu();
4969 /* nmultiply-and-accumulate (0x0E) */
4973 /* (n)multiply-and-accumulate (0x0C - 0x0E) */
4974 tcg_gen_mov_tl(cpu_T[2], cpu_gpr[rt]);
4975 tcg_gen_mov_tl(cpu_T[1], cpu_T[0]);
4976 gen_op_405_add_T0_T2();
4979 /* Check overflow */
4981 gen_op_check_addo();
4983 gen_op_405_check_ovu();
4988 gen_op_405_check_sat();
4990 gen_op_405_check_satu();
4992 tcg_gen_mov_tl(cpu_gpr[rt], cpu_T[0]);
4993 if (unlikely(Rc) != 0) {
4999 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5000 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC) \
5002 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5003 rD(ctx->opcode), Rc(ctx->opcode)); \
5006 /* macchw - macchw. */
5007 GEN_MAC_HANDLER(macchw, 0x0C, 0x05);
5008 /* macchwo - macchwo. */
5009 GEN_MAC_HANDLER(macchwo, 0x0C, 0x15);
5010 /* macchws - macchws. */
5011 GEN_MAC_HANDLER(macchws, 0x0C, 0x07);
5012 /* macchwso - macchwso. */
5013 GEN_MAC_HANDLER(macchwso, 0x0C, 0x17);
5014 /* macchwsu - macchwsu. */
5015 GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06);
5016 /* macchwsuo - macchwsuo. */
5017 GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16);
5018 /* macchwu - macchwu. */
5019 GEN_MAC_HANDLER(macchwu, 0x0C, 0x04);
5020 /* macchwuo - macchwuo. */
5021 GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14);
5022 /* machhw - machhw. */
5023 GEN_MAC_HANDLER(machhw, 0x0C, 0x01);
5024 /* machhwo - machhwo. */
5025 GEN_MAC_HANDLER(machhwo, 0x0C, 0x11);
5026 /* machhws - machhws. */
5027 GEN_MAC_HANDLER(machhws, 0x0C, 0x03);
5028 /* machhwso - machhwso. */
5029 GEN_MAC_HANDLER(machhwso, 0x0C, 0x13);
5030 /* machhwsu - machhwsu. */
5031 GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02);
5032 /* machhwsuo - machhwsuo. */
5033 GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12);
5034 /* machhwu - machhwu. */
5035 GEN_MAC_HANDLER(machhwu, 0x0C, 0x00);
5036 /* machhwuo - machhwuo. */
5037 GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10);
5038 /* maclhw - maclhw. */
5039 GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D);
5040 /* maclhwo - maclhwo. */
5041 GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D);
5042 /* maclhws - maclhws. */
5043 GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F);
5044 /* maclhwso - maclhwso. */
5045 GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F);
5046 /* maclhwu - maclhwu. */
5047 GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C);
5048 /* maclhwuo - maclhwuo. */
5049 GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C);
5050 /* maclhwsu - maclhwsu. */
5051 GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E);
5052 /* maclhwsuo - maclhwsuo. */
5053 GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E);
5054 /* nmacchw - nmacchw. */
5055 GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05);
5056 /* nmacchwo - nmacchwo. */
5057 GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15);
5058 /* nmacchws - nmacchws. */
5059 GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07);
5060 /* nmacchwso - nmacchwso. */
5061 GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17);
5062 /* nmachhw - nmachhw. */
5063 GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01);
5064 /* nmachhwo - nmachhwo. */
5065 GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11);
5066 /* nmachhws - nmachhws. */
5067 GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03);
5068 /* nmachhwso - nmachhwso. */
5069 GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13);
5070 /* nmaclhw - nmaclhw. */
5071 GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D);
5072 /* nmaclhwo - nmaclhwo. */
5073 GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D);
5074 /* nmaclhws - nmaclhws. */
5075 GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F);
5076 /* nmaclhwso - nmaclhwso. */
5077 GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F);
5079 /* mulchw - mulchw. */
5080 GEN_MAC_HANDLER(mulchw, 0x08, 0x05);
5081 /* mulchwu - mulchwu. */
5082 GEN_MAC_HANDLER(mulchwu, 0x08, 0x04);
5083 /* mulhhw - mulhhw. */
5084 GEN_MAC_HANDLER(mulhhw, 0x08, 0x01);
5085 /* mulhhwu - mulhhwu. */
5086 GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00);
5087 /* mullhw - mullhw. */
5088 GEN_MAC_HANDLER(mullhw, 0x08, 0x0D);
5089 /* mullhwu - mullhwu. */
5090 GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
5093 GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR)
5095 #if defined(CONFIG_USER_ONLY)
5096 GEN_EXCP_PRIVREG(ctx);
5098 uint32_t dcrn = SPR(ctx->opcode);
5100 if (unlikely(!ctx->supervisor)) {
5101 GEN_EXCP_PRIVREG(ctx);
5104 tcg_gen_movi_tl(cpu_T[0], dcrn);
5106 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5111 GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR)
5113 #if defined(CONFIG_USER_ONLY)
5114 GEN_EXCP_PRIVREG(ctx);
5116 uint32_t dcrn = SPR(ctx->opcode);
5118 if (unlikely(!ctx->supervisor)) {
5119 GEN_EXCP_PRIVREG(ctx);
5122 tcg_gen_movi_tl(cpu_T[0], dcrn);
5123 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5129 /* XXX: not implemented on 440 ? */
5130 GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX)
5132 #if defined(CONFIG_USER_ONLY)
5133 GEN_EXCP_PRIVREG(ctx);
5135 if (unlikely(!ctx->supervisor)) {
5136 GEN_EXCP_PRIVREG(ctx);
5139 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5141 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5142 /* Note: Rc update flag set leads to undefined state of Rc0 */
5147 /* XXX: not implemented on 440 ? */
5148 GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX)
5150 #if defined(CONFIG_USER_ONLY)
5151 GEN_EXCP_PRIVREG(ctx);
5153 if (unlikely(!ctx->supervisor)) {
5154 GEN_EXCP_PRIVREG(ctx);
5157 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5158 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5160 /* Note: Rc update flag set leads to undefined state of Rc0 */
5164 /* mfdcrux (PPC 460) : user-mode access to DCR */
5165 GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX)
5167 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5169 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5170 /* Note: Rc update flag set leads to undefined state of Rc0 */
5173 /* mtdcrux (PPC 460) : user-mode access to DCR */
5174 GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX)
5176 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5177 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5179 /* Note: Rc update flag set leads to undefined state of Rc0 */
5183 GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON)
5185 #if defined(CONFIG_USER_ONLY)
5186 GEN_EXCP_PRIVOPC(ctx);
5188 if (unlikely(!ctx->supervisor)) {
5189 GEN_EXCP_PRIVOPC(ctx);
5192 /* interpreted as no-op */
5197 GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON)
5199 #if defined(CONFIG_USER_ONLY)
5200 GEN_EXCP_PRIVOPC(ctx);
5203 if (unlikely(!ctx->supervisor)) {
5204 GEN_EXCP_PRIVOPC(ctx);
5207 EA = tcg_temp_new(TCG_TYPE_TL);
5208 gen_addr_reg_index(EA, ctx);
5209 val = tcg_temp_new(TCG_TYPE_TL);
5210 gen_qemu_ld32u(val, EA, ctx->mem_idx);
5212 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA);
5218 GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT)
5220 /* interpreted as no-op */
5221 /* XXX: specification say this is treated as a load by the MMU
5222 * but does not generate any exception
5227 GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON)
5229 #if defined(CONFIG_USER_ONLY)
5230 GEN_EXCP_PRIVOPC(ctx);
5232 if (unlikely(!ctx->supervisor)) {
5233 GEN_EXCP_PRIVOPC(ctx);
5236 /* interpreted as no-op */
5241 GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON)
5243 #if defined(CONFIG_USER_ONLY)
5244 GEN_EXCP_PRIVOPC(ctx);
5246 if (unlikely(!ctx->supervisor)) {
5247 GEN_EXCP_PRIVOPC(ctx);
5250 /* interpreted as no-op */
5254 /* rfci (supervisor only) */
5255 GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP)
5257 #if defined(CONFIG_USER_ONLY)
5258 GEN_EXCP_PRIVOPC(ctx);
5260 if (unlikely(!ctx->supervisor)) {
5261 GEN_EXCP_PRIVOPC(ctx);
5264 /* Restore CPU state */
5270 GEN_HANDLER(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE)
5272 #if defined(CONFIG_USER_ONLY)
5273 GEN_EXCP_PRIVOPC(ctx);
5275 if (unlikely(!ctx->supervisor)) {
5276 GEN_EXCP_PRIVOPC(ctx);
5279 /* Restore CPU state */
5285 /* BookE specific */
5286 /* XXX: not implemented on 440 ? */
5287 GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI)
5289 #if defined(CONFIG_USER_ONLY)
5290 GEN_EXCP_PRIVOPC(ctx);
5292 if (unlikely(!ctx->supervisor)) {
5293 GEN_EXCP_PRIVOPC(ctx);
5296 /* Restore CPU state */
5302 /* XXX: not implemented on 440 ? */
5303 GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI)
5305 #if defined(CONFIG_USER_ONLY)
5306 GEN_EXCP_PRIVOPC(ctx);
5308 if (unlikely(!ctx->supervisor)) {
5309 GEN_EXCP_PRIVOPC(ctx);
5312 /* Restore CPU state */
5318 /* TLB management - PowerPC 405 implementation */
5320 GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB)
5322 #if defined(CONFIG_USER_ONLY)
5323 GEN_EXCP_PRIVOPC(ctx);
5325 if (unlikely(!ctx->supervisor)) {
5326 GEN_EXCP_PRIVOPC(ctx);
5329 switch (rB(ctx->opcode)) {
5331 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5332 gen_op_4xx_tlbre_hi();
5333 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5336 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5337 gen_op_4xx_tlbre_lo();
5338 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5341 GEN_EXCP_INVAL(ctx);
5347 /* tlbsx - tlbsx. */
5348 GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB)
5350 #if defined(CONFIG_USER_ONLY)
5351 GEN_EXCP_PRIVOPC(ctx);
5353 if (unlikely(!ctx->supervisor)) {
5354 GEN_EXCP_PRIVOPC(ctx);
5357 gen_addr_reg_index(cpu_T[0], ctx);
5359 if (Rc(ctx->opcode))
5360 gen_op_4xx_tlbsx_check();
5361 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5366 GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB)
5368 #if defined(CONFIG_USER_ONLY)
5369 GEN_EXCP_PRIVOPC(ctx);
5371 if (unlikely(!ctx->supervisor)) {
5372 GEN_EXCP_PRIVOPC(ctx);
5375 switch (rB(ctx->opcode)) {
5377 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5378 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5379 gen_op_4xx_tlbwe_hi();
5382 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5383 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5384 gen_op_4xx_tlbwe_lo();
5387 GEN_EXCP_INVAL(ctx);
5393 /* TLB management - PowerPC 440 implementation */
5395 GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE)
5397 #if defined(CONFIG_USER_ONLY)
5398 GEN_EXCP_PRIVOPC(ctx);
5400 if (unlikely(!ctx->supervisor)) {
5401 GEN_EXCP_PRIVOPC(ctx);
5404 switch (rB(ctx->opcode)) {
5408 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5409 gen_op_440_tlbre(rB(ctx->opcode));
5410 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5413 GEN_EXCP_INVAL(ctx);
5419 /* tlbsx - tlbsx. */
5420 GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE)
5422 #if defined(CONFIG_USER_ONLY)
5423 GEN_EXCP_PRIVOPC(ctx);
5425 if (unlikely(!ctx->supervisor)) {
5426 GEN_EXCP_PRIVOPC(ctx);
5429 gen_addr_reg_index(cpu_T[0], ctx);
5431 if (Rc(ctx->opcode))
5432 gen_op_4xx_tlbsx_check();
5433 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5438 GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE)
5440 #if defined(CONFIG_USER_ONLY)
5441 GEN_EXCP_PRIVOPC(ctx);
5443 if (unlikely(!ctx->supervisor)) {
5444 GEN_EXCP_PRIVOPC(ctx);
5447 switch (rB(ctx->opcode)) {
5451 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5452 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5453 gen_op_440_tlbwe(rB(ctx->opcode));
5456 GEN_EXCP_INVAL(ctx);
5463 GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE)
5465 #if defined(CONFIG_USER_ONLY)
5466 GEN_EXCP_PRIVOPC(ctx);
5468 if (unlikely(!ctx->supervisor)) {
5469 GEN_EXCP_PRIVOPC(ctx);
5472 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rD(ctx->opcode)]);
5474 /* Stop translation to have a chance to raise an exception
5475 * if we just set msr_ee to 1
5482 GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000EFC01, PPC_WRTEE)
5484 #if defined(CONFIG_USER_ONLY)
5485 GEN_EXCP_PRIVOPC(ctx);
5487 if (unlikely(!ctx->supervisor)) {
5488 GEN_EXCP_PRIVOPC(ctx);
5491 tcg_gen_movi_tl(cpu_T[0], ctx->opcode & 0x00010000);
5493 /* Stop translation to have a chance to raise an exception
5494 * if we just set msr_ee to 1
5500 /* PowerPC 440 specific instructions */
5502 GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC)
5504 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
5505 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
5507 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
5508 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
5509 tcg_gen_or_tl(cpu_xer, cpu_xer, cpu_T[0]);
5510 if (Rc(ctx->opcode)) {
5511 gen_op_440_dlmzb_update_Rc();
5512 tcg_gen_andi_i32(cpu_crf[0], cpu_T[0], 0xf);
5516 /* mbar replaces eieio on 440 */
5517 GEN_HANDLER(mbar, 0x1F, 0x16, 0x13, 0x001FF801, PPC_BOOKE)
5519 /* interpreted as no-op */
5522 /* msync replaces sync on 440 */
5523 GEN_HANDLER(msync, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE)
5525 /* interpreted as no-op */
5529 GEN_HANDLER2(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001, PPC_BOOKE)
5531 /* interpreted as no-op */
5532 /* XXX: specification say this is treated as a load by the MMU
5533 * but does not generate any exception
5537 /*** Altivec vector extension ***/
5538 /* Altivec registers moves */
5540 static always_inline void gen_load_avr(int t, int reg) {
5541 tcg_gen_mov_i64(cpu_AVRh[t], cpu_avrh[reg]);
5542 tcg_gen_mov_i64(cpu_AVRl[t], cpu_avrl[reg]);
5545 static always_inline void gen_store_avr(int reg, int t) {
5546 tcg_gen_mov_i64(cpu_avrh[reg], cpu_AVRh[t]);
5547 tcg_gen_mov_i64(cpu_avrl[reg], cpu_AVRl[t]);
5550 #define op_vr_ldst(name) (*gen_op_##name[ctx->mem_idx])()
5551 #define OP_VR_LD_TABLE(name) \
5552 static GenOpFunc *gen_op_vr_l##name[NB_MEM_FUNCS] = { \
5553 GEN_MEM_FUNCS(vr_l##name), \
5555 #define OP_VR_ST_TABLE(name) \
5556 static GenOpFunc *gen_op_vr_st##name[NB_MEM_FUNCS] = { \
5557 GEN_MEM_FUNCS(vr_st##name), \
5560 #define GEN_VR_LDX(name, opc2, opc3) \
5561 GEN_HANDLER(l##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
5563 if (unlikely(!ctx->altivec_enabled)) { \
5564 GEN_EXCP_NO_VR(ctx); \
5567 gen_addr_reg_index(cpu_T[0], ctx); \
5568 op_vr_ldst(vr_l##name); \
5569 gen_store_avr(rD(ctx->opcode), 0); \
5572 #define GEN_VR_STX(name, opc2, opc3) \
5573 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
5575 if (unlikely(!ctx->altivec_enabled)) { \
5576 GEN_EXCP_NO_VR(ctx); \
5579 gen_addr_reg_index(cpu_T[0], ctx); \
5580 gen_load_avr(0, rS(ctx->opcode)); \
5581 op_vr_ldst(vr_st##name); \
5585 GEN_VR_LDX(vx, 0x07, 0x03);
5586 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
5587 #define gen_op_vr_lvxl gen_op_vr_lvx
5588 GEN_VR_LDX(vxl, 0x07, 0x0B);
5591 GEN_VR_STX(vx, 0x07, 0x07);
5592 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
5593 #define gen_op_vr_stvxl gen_op_vr_stvx
5594 GEN_VR_STX(vxl, 0x07, 0x0F);
5596 /*** SPE extension ***/
5597 /* Register moves */
5599 static always_inline void gen_load_gpr64(TCGv t, int reg) {
5600 #if defined(TARGET_PPC64)
5601 tcg_gen_mov_i64(t, cpu_gpr[reg]);
5603 tcg_gen_concat_i32_i64(t, cpu_gpr[reg], cpu_gprh[reg]);
5607 static always_inline void gen_store_gpr64(int reg, TCGv t) {
5608 #if defined(TARGET_PPC64)
5609 tcg_gen_mov_i64(cpu_gpr[reg], t);
5611 tcg_gen_trunc_i64_i32(cpu_gpr[reg], t);
5612 TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
5613 tcg_gen_shri_i64(tmp, t, 32);
5614 tcg_gen_trunc_i64_i32(cpu_gprh[reg], tmp);
5619 #define GEN_SPE(name0, name1, opc2, opc3, inval, type) \
5620 GEN_HANDLER(name0##_##name1, 0x04, opc2, opc3, inval, type) \
5622 if (Rc(ctx->opcode)) \
5628 /* Handler for undefined SPE opcodes */
5629 static always_inline void gen_speundef (DisasContext *ctx)
5631 GEN_EXCP_INVAL(ctx);
5634 /* SPE load and stores */
5635 static always_inline void gen_addr_spe_imm_index (TCGv EA, DisasContext *ctx, int sh)
5637 target_long simm = rB(ctx->opcode);
5639 if (rA(ctx->opcode) == 0)
5640 tcg_gen_movi_tl(EA, simm << sh);
5641 else if (likely(simm != 0))
5642 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm << sh);
5644 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
5647 #define op_spe_ldst(name) (*gen_op_##name[ctx->mem_idx])()
5648 #define OP_SPE_LD_TABLE(name) \
5649 static GenOpFunc *gen_op_spe_l##name[NB_MEM_FUNCS] = { \
5650 GEN_MEM_FUNCS(spe_l##name), \
5652 #define OP_SPE_ST_TABLE(name) \
5653 static GenOpFunc *gen_op_spe_st##name[NB_MEM_FUNCS] = { \
5654 GEN_MEM_FUNCS(spe_st##name), \
5657 #define GEN_SPE_LD(name, sh) \
5658 static always_inline void gen_evl##name (DisasContext *ctx) \
5660 if (unlikely(!ctx->spe_enabled)) { \
5661 GEN_EXCP_NO_AP(ctx); \
5664 gen_addr_spe_imm_index(cpu_T[0], ctx, sh); \
5665 op_spe_ldst(spe_l##name); \
5666 gen_store_gpr64(rD(ctx->opcode), cpu_T64[1]); \
5669 #define GEN_SPE_LDX(name) \
5670 static always_inline void gen_evl##name##x (DisasContext *ctx) \
5672 if (unlikely(!ctx->spe_enabled)) { \
5673 GEN_EXCP_NO_AP(ctx); \
5676 gen_addr_reg_index(cpu_T[0], ctx); \
5677 op_spe_ldst(spe_l##name); \
5678 gen_store_gpr64(rD(ctx->opcode), cpu_T64[1]); \
5681 #define GEN_SPEOP_LD(name, sh) \
5682 OP_SPE_LD_TABLE(name); \
5683 GEN_SPE_LD(name, sh); \
5686 #define GEN_SPE_ST(name, sh) \
5687 static always_inline void gen_evst##name (DisasContext *ctx) \
5689 if (unlikely(!ctx->spe_enabled)) { \
5690 GEN_EXCP_NO_AP(ctx); \
5693 gen_addr_spe_imm_index(cpu_T[0], ctx, sh); \
5694 gen_load_gpr64(cpu_T64[1], rS(ctx->opcode)); \
5695 op_spe_ldst(spe_st##name); \
5698 #define GEN_SPE_STX(name) \
5699 static always_inline void gen_evst##name##x (DisasContext *ctx) \
5701 if (unlikely(!ctx->spe_enabled)) { \
5702 GEN_EXCP_NO_AP(ctx); \
5705 gen_addr_reg_index(cpu_T[0], ctx); \
5706 gen_load_gpr64(cpu_T64[1], rS(ctx->opcode)); \
5707 op_spe_ldst(spe_st##name); \
5710 #define GEN_SPEOP_ST(name, sh) \
5711 OP_SPE_ST_TABLE(name); \
5712 GEN_SPE_ST(name, sh); \
5715 #define GEN_SPEOP_LDST(name, sh) \
5716 GEN_SPEOP_LD(name, sh); \
5717 GEN_SPEOP_ST(name, sh)
5719 /* SPE arithmetic and logic */
5720 #define GEN_SPEOP_ARITH2(name) \
5721 static always_inline void gen_##name (DisasContext *ctx) \
5723 if (unlikely(!ctx->spe_enabled)) { \
5724 GEN_EXCP_NO_AP(ctx); \
5727 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode)); \
5728 gen_load_gpr64(cpu_T64[1], rB(ctx->opcode)); \
5730 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
5733 #define GEN_SPEOP_TCG_ARITH2(name) \
5734 static always_inline void gen_##name (DisasContext *ctx) \
5736 if (unlikely(!ctx->spe_enabled)) { \
5737 GEN_EXCP_NO_AP(ctx); \
5740 TCGv t0 = tcg_temp_new(TCG_TYPE_I64); \
5741 TCGv t1 = tcg_temp_new(TCG_TYPE_I64); \
5742 gen_load_gpr64(t0, rA(ctx->opcode)); \
5743 gen_load_gpr64(t1, rB(ctx->opcode)); \
5744 gen_op_##name(t0, t1); \
5745 gen_store_gpr64(rD(ctx->opcode), t0); \
5746 tcg_temp_free(t0); \
5747 tcg_temp_free(t1); \
5750 #define GEN_SPEOP_ARITH1(name) \
5751 static always_inline void gen_##name (DisasContext *ctx) \
5753 if (unlikely(!ctx->spe_enabled)) { \
5754 GEN_EXCP_NO_AP(ctx); \
5757 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode)); \
5759 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
5762 #define GEN_SPEOP_COMP(name) \
5763 static always_inline void gen_##name (DisasContext *ctx) \
5765 if (unlikely(!ctx->spe_enabled)) { \
5766 GEN_EXCP_NO_AP(ctx); \
5769 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode)); \
5770 gen_load_gpr64(cpu_T64[1], rB(ctx->opcode)); \
5772 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_T[0], 0xf); \
5776 static always_inline void gen_op_evand (TCGv t0, TCGv t1)
5778 tcg_gen_and_i64(t0, t0, t1);
5781 static always_inline void gen_op_evandc (TCGv t0, TCGv t1)
5783 tcg_gen_not_i64(t1, t1);
5784 tcg_gen_and_i64(t0, t0, t1);
5787 static always_inline void gen_op_evxor (TCGv t0, TCGv t1)
5789 tcg_gen_xor_i64(t0, t0, t1);
5792 static always_inline void gen_op_evor (TCGv t0, TCGv t1)
5794 tcg_gen_or_i64(t0, t0, t1);
5797 static always_inline void gen_op_evnor (TCGv t0, TCGv t1)
5799 tcg_gen_or_i64(t0, t0, t1);
5800 tcg_gen_not_i64(t0, t0);
5803 static always_inline void gen_op_eveqv (TCGv t0, TCGv t1)
5805 tcg_gen_xor_i64(t0, t0, t1);
5806 tcg_gen_not_i64(t0, t0);
5809 static always_inline void gen_op_evorc (TCGv t0, TCGv t1)
5811 tcg_gen_not_i64(t1, t1);
5812 tcg_gen_or_i64(t0, t0, t1);
5815 static always_inline void gen_op_evnand (TCGv t0, TCGv t1)
5817 tcg_gen_and_i64(t0, t0, t1);
5818 tcg_gen_not_i64(t0, t0);
5821 GEN_SPEOP_TCG_ARITH2(evand);
5822 GEN_SPEOP_TCG_ARITH2(evandc);
5823 GEN_SPEOP_TCG_ARITH2(evxor);
5824 GEN_SPEOP_TCG_ARITH2(evor);
5825 GEN_SPEOP_TCG_ARITH2(evnor);
5826 GEN_SPEOP_TCG_ARITH2(eveqv);
5827 GEN_SPEOP_TCG_ARITH2(evorc);
5828 GEN_SPEOP_TCG_ARITH2(evnand);
5829 GEN_SPEOP_ARITH2(evsrwu);
5830 GEN_SPEOP_ARITH2(evsrws);
5831 GEN_SPEOP_ARITH2(evslw);
5832 GEN_SPEOP_ARITH2(evrlw);
5833 GEN_SPEOP_ARITH2(evmergehi);
5834 GEN_SPEOP_ARITH2(evmergelo);
5835 GEN_SPEOP_ARITH2(evmergehilo);
5836 GEN_SPEOP_ARITH2(evmergelohi);
5839 GEN_SPEOP_ARITH2(evaddw);
5840 GEN_SPEOP_ARITH2(evsubfw);
5841 GEN_SPEOP_ARITH1(evabs);
5842 GEN_SPEOP_ARITH1(evneg);
5843 GEN_SPEOP_ARITH1(evextsb);
5844 GEN_SPEOP_ARITH1(evextsh);
5845 GEN_SPEOP_ARITH1(evrndw);
5846 GEN_SPEOP_ARITH1(evcntlzw);
5847 GEN_SPEOP_ARITH1(evcntlsw);
5848 static always_inline void gen_brinc (DisasContext *ctx)
5850 /* Note: brinc is usable even if SPE is disabled */
5851 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5852 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
5854 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5857 #define GEN_SPEOP_ARITH_IMM2(name) \
5858 static always_inline void gen_##name##i (DisasContext *ctx) \
5860 if (unlikely(!ctx->spe_enabled)) { \
5861 GEN_EXCP_NO_AP(ctx); \
5864 gen_load_gpr64(cpu_T64[0], rB(ctx->opcode)); \
5865 gen_op_splatwi_T1_64(rA(ctx->opcode)); \
5867 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
5870 #define GEN_SPEOP_LOGIC_IMM2(name) \
5871 static always_inline void gen_##name##i (DisasContext *ctx) \
5873 if (unlikely(!ctx->spe_enabled)) { \
5874 GEN_EXCP_NO_AP(ctx); \
5877 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode)); \
5878 gen_op_splatwi_T1_64(rB(ctx->opcode)); \
5880 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
5883 GEN_SPEOP_ARITH_IMM2(evaddw);
5884 #define gen_evaddiw gen_evaddwi
5885 GEN_SPEOP_ARITH_IMM2(evsubfw);
5886 #define gen_evsubifw gen_evsubfwi
5887 GEN_SPEOP_LOGIC_IMM2(evslw);
5888 GEN_SPEOP_LOGIC_IMM2(evsrwu);
5889 #define gen_evsrwis gen_evsrwsi
5890 GEN_SPEOP_LOGIC_IMM2(evsrws);
5891 #define gen_evsrwiu gen_evsrwui
5892 GEN_SPEOP_LOGIC_IMM2(evrlw);
5894 static always_inline void gen_evsplati (DisasContext *ctx)
5896 int32_t imm = (int32_t)(rA(ctx->opcode) << 27) >> 27;
5898 gen_op_splatwi_T0_64(imm);
5899 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]);
5902 static always_inline void gen_evsplatfi (DisasContext *ctx)
5904 uint32_t imm = rA(ctx->opcode) << 27;
5906 gen_op_splatwi_T0_64(imm);
5907 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]);
5911 GEN_SPEOP_COMP(evcmpgtu);
5912 GEN_SPEOP_COMP(evcmpgts);
5913 GEN_SPEOP_COMP(evcmpltu);
5914 GEN_SPEOP_COMP(evcmplts);
5915 GEN_SPEOP_COMP(evcmpeq);
5917 GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, PPC_SPE); ////
5918 GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, PPC_SPE);
5919 GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, PPC_SPE); ////
5920 GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, PPC_SPE);
5921 GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, PPC_SPE); ////
5922 GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, PPC_SPE); ////
5923 GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, PPC_SPE); ////
5924 GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x00000000, PPC_SPE); //
5925 GEN_SPE(speundef, evand, 0x08, 0x08, 0x00000000, PPC_SPE); ////
5926 GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, PPC_SPE); ////
5927 GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, PPC_SPE); ////
5928 GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, PPC_SPE); ////
5929 GEN_SPE(speundef, evorc, 0x0D, 0x08, 0x00000000, PPC_SPE); ////
5930 GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, PPC_SPE); ////
5931 GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, PPC_SPE); ////
5932 GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, PPC_SPE);
5933 GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, PPC_SPE); ////
5934 GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, PPC_SPE);
5935 GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, PPC_SPE); //
5936 GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, PPC_SPE);
5937 GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, PPC_SPE); ////
5938 GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, PPC_SPE); ////
5939 GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, PPC_SPE); ////
5940 GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, PPC_SPE); ////
5941 GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, PPC_SPE); ////
5943 static always_inline void gen_evsel (DisasContext *ctx)
5945 if (unlikely(!ctx->spe_enabled)) {
5946 GEN_EXCP_NO_AP(ctx);
5949 tcg_gen_mov_i32(cpu_T[0], cpu_crf[ctx->opcode & 0x7]);
5950 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode));
5951 gen_load_gpr64(cpu_T64[1], rB(ctx->opcode));
5953 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]);
5956 GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE)
5960 GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE)
5964 GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE)
5968 GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE)
5973 /* Load and stores */
5974 GEN_SPEOP_LDST(dd, 3);
5975 GEN_SPEOP_LDST(dw, 3);
5976 GEN_SPEOP_LDST(dh, 3);
5977 GEN_SPEOP_LDST(whe, 2);
5978 GEN_SPEOP_LD(whou, 2);
5979 GEN_SPEOP_LD(whos, 2);
5980 GEN_SPEOP_ST(who, 2);
5982 #define _GEN_OP_SPE_STWWE(suffix) \
5983 static always_inline void gen_op_spe_stwwe_##suffix (void) \
5985 gen_op_srli32_T1_64(); \
5986 gen_op_spe_stwwo_##suffix(); \
5988 #define _GEN_OP_SPE_STWWE_LE(suffix) \
5989 static always_inline void gen_op_spe_stwwe_le_##suffix (void) \
5991 gen_op_srli32_T1_64(); \
5992 gen_op_spe_stwwo_le_##suffix(); \
5994 #if defined(TARGET_PPC64)
5995 #define GEN_OP_SPE_STWWE(suffix) \
5996 _GEN_OP_SPE_STWWE(suffix); \
5997 _GEN_OP_SPE_STWWE_LE(suffix); \
5998 static always_inline void gen_op_spe_stwwe_64_##suffix (void) \
6000 gen_op_srli32_T1_64(); \
6001 gen_op_spe_stwwo_64_##suffix(); \
6003 static always_inline void gen_op_spe_stwwe_le_64_##suffix (void) \
6005 gen_op_srli32_T1_64(); \
6006 gen_op_spe_stwwo_le_64_##suffix(); \
6009 #define GEN_OP_SPE_STWWE(suffix) \
6010 _GEN_OP_SPE_STWWE(suffix); \
6011 _GEN_OP_SPE_STWWE_LE(suffix)
6013 #if defined(CONFIG_USER_ONLY)
6014 GEN_OP_SPE_STWWE(raw);
6015 #else /* defined(CONFIG_USER_ONLY) */
6016 GEN_OP_SPE_STWWE(user);
6017 GEN_OP_SPE_STWWE(kernel);
6018 GEN_OP_SPE_STWWE(hypv);
6019 #endif /* defined(CONFIG_USER_ONLY) */
6020 GEN_SPEOP_ST(wwe, 2);
6021 GEN_SPEOP_ST(wwo, 2);
6023 #define GEN_SPE_LDSPLAT(name, op, suffix) \
6024 static always_inline void gen_op_spe_l##name##_##suffix (void) \
6026 gen_op_##op##_##suffix(); \
6027 gen_op_splatw_T1_64(); \
6030 #define GEN_OP_SPE_LHE(suffix) \
6031 static always_inline void gen_op_spe_lhe_##suffix (void) \
6033 gen_op_spe_lh_##suffix(); \
6034 gen_op_sli16_T1_64(); \
6037 #define GEN_OP_SPE_LHX(suffix) \
6038 static always_inline void gen_op_spe_lhx_##suffix (void) \
6040 gen_op_spe_lh_##suffix(); \
6041 gen_op_extsh_T1_64(); \
6044 #if defined(CONFIG_USER_ONLY)
6045 GEN_OP_SPE_LHE(raw);
6046 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, raw);
6047 GEN_OP_SPE_LHE(le_raw);
6048 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_raw);
6049 GEN_SPE_LDSPLAT(hhousplat, spe_lh, raw);
6050 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_raw);
6051 GEN_OP_SPE_LHX(raw);
6052 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, raw);
6053 GEN_OP_SPE_LHX(le_raw);
6054 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_raw);
6055 #if defined(TARGET_PPC64)
6056 GEN_OP_SPE_LHE(64_raw);
6057 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_raw);
6058 GEN_OP_SPE_LHE(le_64_raw);
6059 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_raw);
6060 GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_raw);
6061 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_raw);
6062 GEN_OP_SPE_LHX(64_raw);
6063 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_raw);
6064 GEN_OP_SPE_LHX(le_64_raw);
6065 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_raw);
6068 GEN_OP_SPE_LHE(user);
6069 GEN_OP_SPE_LHE(kernel);
6070 GEN_OP_SPE_LHE(hypv);
6071 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, user);
6072 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, kernel);
6073 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, hypv);
6074 GEN_OP_SPE_LHE(le_user);
6075 GEN_OP_SPE_LHE(le_kernel);
6076 GEN_OP_SPE_LHE(le_hypv);
6077 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_user);
6078 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_kernel);
6079 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_hypv);
6080 GEN_SPE_LDSPLAT(hhousplat, spe_lh, user);
6081 GEN_SPE_LDSPLAT(hhousplat, spe_lh, kernel);
6082 GEN_SPE_LDSPLAT(hhousplat, spe_lh, hypv);
6083 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_user);
6084 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_kernel);
6085 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_hypv);
6086 GEN_OP_SPE_LHX(user);
6087 GEN_OP_SPE_LHX(kernel);
6088 GEN_OP_SPE_LHX(hypv);
6089 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, user);
6090 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, kernel);
6091 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, hypv);
6092 GEN_OP_SPE_LHX(le_user);
6093 GEN_OP_SPE_LHX(le_kernel);
6094 GEN_OP_SPE_LHX(le_hypv);
6095 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_user);
6096 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_kernel);
6097 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_hypv);
6098 #if defined(TARGET_PPC64)
6099 GEN_OP_SPE_LHE(64_user);
6100 GEN_OP_SPE_LHE(64_kernel);
6101 GEN_OP_SPE_LHE(64_hypv);
6102 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_user);
6103 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_kernel);
6104 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_hypv);
6105 GEN_OP_SPE_LHE(le_64_user);
6106 GEN_OP_SPE_LHE(le_64_kernel);
6107 GEN_OP_SPE_LHE(le_64_hypv);
6108 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_user);
6109 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_kernel);
6110 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_hypv);
6111 GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_user);
6112 GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_kernel);
6113 GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_hypv);
6114 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_user);
6115 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_kernel);
6116 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_hypv);
6117 GEN_OP_SPE_LHX(64_user);
6118 GEN_OP_SPE_LHX(64_kernel);
6119 GEN_OP_SPE_LHX(64_hypv);
6120 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_user);
6121 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_kernel);
6122 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_hypv);
6123 GEN_OP_SPE_LHX(le_64_user);
6124 GEN_OP_SPE_LHX(le_64_kernel);
6125 GEN_OP_SPE_LHX(le_64_hypv);
6126 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_user);
6127 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_kernel);
6128 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_hypv);
6131 GEN_SPEOP_LD(hhesplat, 1);
6132 GEN_SPEOP_LD(hhousplat, 1);
6133 GEN_SPEOP_LD(hhossplat, 1);
6134 GEN_SPEOP_LD(wwsplat, 2);
6135 GEN_SPEOP_LD(whsplat, 2);
6137 GEN_SPE(evlddx, evldd, 0x00, 0x0C, 0x00000000, PPC_SPE); //
6138 GEN_SPE(evldwx, evldw, 0x01, 0x0C, 0x00000000, PPC_SPE); //
6139 GEN_SPE(evldhx, evldh, 0x02, 0x0C, 0x00000000, PPC_SPE); //
6140 GEN_SPE(evlhhesplatx, evlhhesplat, 0x04, 0x0C, 0x00000000, PPC_SPE); //
6141 GEN_SPE(evlhhousplatx, evlhhousplat, 0x06, 0x0C, 0x00000000, PPC_SPE); //
6142 GEN_SPE(evlhhossplatx, evlhhossplat, 0x07, 0x0C, 0x00000000, PPC_SPE); //
6143 GEN_SPE(evlwhex, evlwhe, 0x08, 0x0C, 0x00000000, PPC_SPE); //
6144 GEN_SPE(evlwhoux, evlwhou, 0x0A, 0x0C, 0x00000000, PPC_SPE); //
6145 GEN_SPE(evlwhosx, evlwhos, 0x0B, 0x0C, 0x00000000, PPC_SPE); //
6146 GEN_SPE(evlwwsplatx, evlwwsplat, 0x0C, 0x0C, 0x00000000, PPC_SPE); //
6147 GEN_SPE(evlwhsplatx, evlwhsplat, 0x0E, 0x0C, 0x00000000, PPC_SPE); //
6148 GEN_SPE(evstddx, evstdd, 0x10, 0x0C, 0x00000000, PPC_SPE); //
6149 GEN_SPE(evstdwx, evstdw, 0x11, 0x0C, 0x00000000, PPC_SPE); //
6150 GEN_SPE(evstdhx, evstdh, 0x12, 0x0C, 0x00000000, PPC_SPE); //
6151 GEN_SPE(evstwhex, evstwhe, 0x18, 0x0C, 0x00000000, PPC_SPE); //
6152 GEN_SPE(evstwhox, evstwho, 0x1A, 0x0C, 0x00000000, PPC_SPE); //
6153 GEN_SPE(evstwwex, evstwwe, 0x1C, 0x0C, 0x00000000, PPC_SPE); //
6154 GEN_SPE(evstwwox, evstwwo, 0x1E, 0x0C, 0x00000000, PPC_SPE); //
6156 /* Multiply and add - TODO */
6158 GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0x00000000, PPC_SPE);
6159 GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0x00000000, PPC_SPE);
6160 GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, PPC_SPE);
6161 GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0x00000000, PPC_SPE);
6162 GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, PPC_SPE);
6163 GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0x00000000, PPC_SPE);
6164 GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0x00000000, PPC_SPE);
6165 GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0x00000000, PPC_SPE);
6166 GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, PPC_SPE);
6167 GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0x00000000, PPC_SPE);
6168 GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, PPC_SPE);
6169 GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0x00000000, PPC_SPE);
6171 GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0x00000000, PPC_SPE);
6172 GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, PPC_SPE);
6173 GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, PPC_SPE);
6174 GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0x00000000, PPC_SPE);
6175 GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0x00000000, PPC_SPE);
6176 GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, PPC_SPE);
6177 GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0x00000000, PPC_SPE);
6178 GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0x00000000, PPC_SPE);
6179 GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, PPC_SPE);
6180 GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, PPC_SPE);
6181 GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0x00000000, PPC_SPE);
6182 GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0x00000000, PPC_SPE);
6183 GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, PPC_SPE);
6184 GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0x00000000, PPC_SPE);
6186 GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, PPC_SPE);
6187 GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, PPC_SPE);
6188 GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, PPC_SPE);
6189 GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, PPC_SPE);
6190 GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, PPC_SPE);
6191 GEN_SPE(evmra, speundef, 0x07, 0x13, 0x0000F800, PPC_SPE);
6193 GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, PPC_SPE);
6194 GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0x00000000, PPC_SPE);
6195 GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, PPC_SPE);
6196 GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0x00000000, PPC_SPE);
6197 GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, PPC_SPE);
6198 GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0x00000000, PPC_SPE);
6199 GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, PPC_SPE);
6200 GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0x00000000, PPC_SPE);
6201 GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, PPC_SPE);
6202 GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0x00000000, PPC_SPE);
6203 GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, PPC_SPE);
6204 GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0x00000000, PPC_SPE);
6206 GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, PPC_SPE);
6207 GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, PPC_SPE);
6208 GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0x00000000, PPC_SPE);
6209 GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, PPC_SPE);
6210 GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0x00000000, PPC_SPE);
6212 GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, PPC_SPE);
6213 GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0x00000000, PPC_SPE);
6214 GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, PPC_SPE);
6215 GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0x00000000, PPC_SPE);
6216 GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, PPC_SPE);
6217 GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0x00000000, PPC_SPE);
6218 GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, PPC_SPE);
6219 GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0x00000000, PPC_SPE);
6220 GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, PPC_SPE);
6221 GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0x00000000, PPC_SPE);
6222 GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, PPC_SPE);
6223 GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0x00000000, PPC_SPE);
6225 GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, PPC_SPE);
6226 GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, PPC_SPE);
6227 GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0x00000000, PPC_SPE);
6228 GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, PPC_SPE);
6229 GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0x00000000, PPC_SPE);
6232 /*** SPE floating-point extension ***/
6233 #define GEN_SPEFPUOP_CONV(name) \
6234 static always_inline void gen_##name (DisasContext *ctx) \
6236 gen_load_gpr64(cpu_T64[0], rB(ctx->opcode)); \
6238 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
6241 /* Single precision floating-point vectors operations */
6243 GEN_SPEOP_ARITH2(evfsadd);
6244 GEN_SPEOP_ARITH2(evfssub);
6245 GEN_SPEOP_ARITH2(evfsmul);
6246 GEN_SPEOP_ARITH2(evfsdiv);
6247 GEN_SPEOP_ARITH1(evfsabs);
6248 GEN_SPEOP_ARITH1(evfsnabs);
6249 GEN_SPEOP_ARITH1(evfsneg);
6251 GEN_SPEFPUOP_CONV(evfscfui);
6252 GEN_SPEFPUOP_CONV(evfscfsi);
6253 GEN_SPEFPUOP_CONV(evfscfuf);
6254 GEN_SPEFPUOP_CONV(evfscfsf);
6255 GEN_SPEFPUOP_CONV(evfsctui);
6256 GEN_SPEFPUOP_CONV(evfsctsi);
6257 GEN_SPEFPUOP_CONV(evfsctuf);
6258 GEN_SPEFPUOP_CONV(evfsctsf);
6259 GEN_SPEFPUOP_CONV(evfsctuiz);
6260 GEN_SPEFPUOP_CONV(evfsctsiz);
6262 GEN_SPEOP_COMP(evfscmpgt);
6263 GEN_SPEOP_COMP(evfscmplt);
6264 GEN_SPEOP_COMP(evfscmpeq);
6265 GEN_SPEOP_COMP(evfststgt);
6266 GEN_SPEOP_COMP(evfststlt);
6267 GEN_SPEOP_COMP(evfststeq);
6269 /* Opcodes definitions */
6270 GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, PPC_SPEFPU); //
6271 GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, PPC_SPEFPU); //
6272 GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, PPC_SPEFPU); //
6273 GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, PPC_SPEFPU); //
6274 GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, PPC_SPEFPU); //
6275 GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, PPC_SPEFPU); //
6276 GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, PPC_SPEFPU); //
6277 GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, PPC_SPEFPU); //
6278 GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, PPC_SPEFPU); //
6279 GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, PPC_SPEFPU); //
6280 GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, PPC_SPEFPU); //
6281 GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, PPC_SPEFPU); //
6282 GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, PPC_SPEFPU); //
6283 GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, PPC_SPEFPU); //
6285 /* Single precision floating-point operations */
6287 GEN_SPEOP_ARITH2(efsadd);
6288 GEN_SPEOP_ARITH2(efssub);
6289 GEN_SPEOP_ARITH2(efsmul);
6290 GEN_SPEOP_ARITH2(efsdiv);
6291 GEN_SPEOP_ARITH1(efsabs);
6292 GEN_SPEOP_ARITH1(efsnabs);
6293 GEN_SPEOP_ARITH1(efsneg);
6295 GEN_SPEFPUOP_CONV(efscfui);
6296 GEN_SPEFPUOP_CONV(efscfsi);
6297 GEN_SPEFPUOP_CONV(efscfuf);
6298 GEN_SPEFPUOP_CONV(efscfsf);
6299 GEN_SPEFPUOP_CONV(efsctui);
6300 GEN_SPEFPUOP_CONV(efsctsi);
6301 GEN_SPEFPUOP_CONV(efsctuf);
6302 GEN_SPEFPUOP_CONV(efsctsf);
6303 GEN_SPEFPUOP_CONV(efsctuiz);
6304 GEN_SPEFPUOP_CONV(efsctsiz);
6305 GEN_SPEFPUOP_CONV(efscfd);
6307 GEN_SPEOP_COMP(efscmpgt);
6308 GEN_SPEOP_COMP(efscmplt);
6309 GEN_SPEOP_COMP(efscmpeq);
6310 GEN_SPEOP_COMP(efststgt);
6311 GEN_SPEOP_COMP(efststlt);
6312 GEN_SPEOP_COMP(efststeq);
6314 /* Opcodes definitions */
6315 GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, PPC_SPEFPU); //
6316 GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, PPC_SPEFPU); //
6317 GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, PPC_SPEFPU); //
6318 GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, PPC_SPEFPU); //
6319 GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, PPC_SPEFPU); //
6320 GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, PPC_SPEFPU); //
6321 GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, PPC_SPEFPU); //
6322 GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, PPC_SPEFPU); //
6323 GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, PPC_SPEFPU); //
6324 GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, PPC_SPEFPU); //
6325 GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, PPC_SPEFPU); //
6326 GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, PPC_SPEFPU); //
6327 GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, PPC_SPEFPU); //
6328 GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, PPC_SPEFPU); //
6330 /* Double precision floating-point operations */
6332 GEN_SPEOP_ARITH2(efdadd);
6333 GEN_SPEOP_ARITH2(efdsub);
6334 GEN_SPEOP_ARITH2(efdmul);
6335 GEN_SPEOP_ARITH2(efddiv);
6336 GEN_SPEOP_ARITH1(efdabs);
6337 GEN_SPEOP_ARITH1(efdnabs);
6338 GEN_SPEOP_ARITH1(efdneg);
6341 GEN_SPEFPUOP_CONV(efdcfui);
6342 GEN_SPEFPUOP_CONV(efdcfsi);
6343 GEN_SPEFPUOP_CONV(efdcfuf);
6344 GEN_SPEFPUOP_CONV(efdcfsf);
6345 GEN_SPEFPUOP_CONV(efdctui);
6346 GEN_SPEFPUOP_CONV(efdctsi);
6347 GEN_SPEFPUOP_CONV(efdctuf);
6348 GEN_SPEFPUOP_CONV(efdctsf);
6349 GEN_SPEFPUOP_CONV(efdctuiz);
6350 GEN_SPEFPUOP_CONV(efdctsiz);
6351 GEN_SPEFPUOP_CONV(efdcfs);
6352 GEN_SPEFPUOP_CONV(efdcfuid);
6353 GEN_SPEFPUOP_CONV(efdcfsid);
6354 GEN_SPEFPUOP_CONV(efdctuidz);
6355 GEN_SPEFPUOP_CONV(efdctsidz);
6357 GEN_SPEOP_COMP(efdcmpgt);
6358 GEN_SPEOP_COMP(efdcmplt);
6359 GEN_SPEOP_COMP(efdcmpeq);
6360 GEN_SPEOP_COMP(efdtstgt);
6361 GEN_SPEOP_COMP(efdtstlt);
6362 GEN_SPEOP_COMP(efdtsteq);
6364 /* Opcodes definitions */
6365 GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, PPC_SPEFPU); //
6366 GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, PPC_SPEFPU); //
6367 GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, PPC_SPEFPU); //
6368 GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, PPC_SPEFPU); //
6369 GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, PPC_SPEFPU); //
6370 GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, PPC_SPEFPU); //
6371 GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, PPC_SPEFPU); //
6372 GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, PPC_SPEFPU); //
6373 GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, PPC_SPEFPU); //
6374 GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, PPC_SPEFPU); //
6375 GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, PPC_SPEFPU); //
6376 GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, PPC_SPEFPU); //
6377 GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, PPC_SPEFPU); //
6378 GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, PPC_SPEFPU); //
6379 GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, PPC_SPEFPU); //
6380 GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, PPC_SPEFPU); //
6382 /* End opcode list */
6383 GEN_OPCODE_MARK(end);
6385 #include "translate_init.c"
6386 #include "helper_regs.h"
6388 /*****************************************************************************/
6389 /* Misc PowerPC helpers */
6390 void cpu_dump_state (CPUState *env, FILE *f,
6391 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
6399 cpu_fprintf(f, "NIP " ADDRX " LR " ADDRX " CTR " ADDRX " XER %08x\n",
6400 env->nip, env->lr, env->ctr, env->xer);
6401 cpu_fprintf(f, "MSR " ADDRX " HID0 " ADDRX " HF " ADDRX " idx %d\n",
6402 env->msr, env->spr[SPR_HID0], env->hflags, env->mmu_idx);
6403 #if !defined(NO_TIMER_DUMP)
6404 cpu_fprintf(f, "TB %08x %08x "
6405 #if !defined(CONFIG_USER_ONLY)
6409 cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
6410 #if !defined(CONFIG_USER_ONLY)
6411 , cpu_ppc_load_decr(env)
6415 for (i = 0; i < 32; i++) {
6416 if ((i & (RGPL - 1)) == 0)
6417 cpu_fprintf(f, "GPR%02d", i);
6418 cpu_fprintf(f, " " REGX, ppc_dump_gpr(env, i));
6419 if ((i & (RGPL - 1)) == (RGPL - 1))
6420 cpu_fprintf(f, "\n");
6422 cpu_fprintf(f, "CR ");
6423 for (i = 0; i < 8; i++)
6424 cpu_fprintf(f, "%01x", env->crf[i]);
6425 cpu_fprintf(f, " [");
6426 for (i = 0; i < 8; i++) {
6428 if (env->crf[i] & 0x08)
6430 else if (env->crf[i] & 0x04)
6432 else if (env->crf[i] & 0x02)
6434 cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
6436 cpu_fprintf(f, " ] RES " ADDRX "\n", env->reserve);
6437 for (i = 0; i < 32; i++) {
6438 if ((i & (RFPL - 1)) == 0)
6439 cpu_fprintf(f, "FPR%02d", i);
6440 cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
6441 if ((i & (RFPL - 1)) == (RFPL - 1))
6442 cpu_fprintf(f, "\n");
6444 #if !defined(CONFIG_USER_ONLY)
6445 cpu_fprintf(f, "SRR0 " ADDRX " SRR1 " ADDRX " SDR1 " ADDRX "\n",
6446 env->spr[SPR_SRR0], env->spr[SPR_SRR1], env->sdr1);
6453 void cpu_dump_statistics (CPUState *env, FILE*f,
6454 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
6457 #if defined(DO_PPC_STATISTICS)
6458 opc_handler_t **t1, **t2, **t3, *handler;
6462 for (op1 = 0; op1 < 64; op1++) {
6464 if (is_indirect_opcode(handler)) {
6465 t2 = ind_table(handler);
6466 for (op2 = 0; op2 < 32; op2++) {
6468 if (is_indirect_opcode(handler)) {
6469 t3 = ind_table(handler);
6470 for (op3 = 0; op3 < 32; op3++) {
6472 if (handler->count == 0)
6474 cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
6476 op1, op2, op3, op1, (op3 << 5) | op2,
6478 handler->count, handler->count);
6481 if (handler->count == 0)
6483 cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: "
6485 op1, op2, op1, op2, handler->oname,
6486 handler->count, handler->count);
6490 if (handler->count == 0)
6492 cpu_fprintf(f, "%02x (%02x ) %16s: %016llx %lld\n",
6493 op1, op1, handler->oname,
6494 handler->count, handler->count);
6500 /*****************************************************************************/
6501 static always_inline void gen_intermediate_code_internal (CPUState *env,
6502 TranslationBlock *tb,
6505 DisasContext ctx, *ctxp = &ctx;
6506 opc_handler_t **table, *handler;
6507 target_ulong pc_start;
6508 uint16_t *gen_opc_end;
6509 int supervisor, little_endian;
6515 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
6516 #if defined(OPTIMIZE_FPRF_UPDATE)
6517 gen_fprf_ptr = gen_fprf_buf;
6521 ctx.exception = POWERPC_EXCP_NONE;
6522 ctx.spr_cb = env->spr_cb;
6523 supervisor = env->mmu_idx;
6524 #if !defined(CONFIG_USER_ONLY)
6525 ctx.supervisor = supervisor;
6527 little_endian = env->hflags & (1 << MSR_LE) ? 1 : 0;
6528 #if defined(TARGET_PPC64)
6529 ctx.sf_mode = msr_sf;
6530 ctx.mem_idx = (supervisor << 2) | (msr_sf << 1) | little_endian;
6532 ctx.mem_idx = (supervisor << 1) | little_endian;
6534 ctx.dcache_line_size = env->dcache_line_size;
6535 ctx.fpu_enabled = msr_fp;
6536 if ((env->flags & POWERPC_FLAG_SPE) && msr_spe)
6537 ctx.spe_enabled = msr_spe;
6539 ctx.spe_enabled = 0;
6540 if ((env->flags & POWERPC_FLAG_VRE) && msr_vr)
6541 ctx.altivec_enabled = msr_vr;
6543 ctx.altivec_enabled = 0;
6544 if ((env->flags & POWERPC_FLAG_SE) && msr_se)
6545 ctx.singlestep_enabled = CPU_SINGLE_STEP;
6547 ctx.singlestep_enabled = 0;
6548 if ((env->flags & POWERPC_FLAG_BE) && msr_be)
6549 ctx.singlestep_enabled |= CPU_BRANCH_STEP;
6550 if (unlikely(env->singlestep_enabled))
6551 ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP;
6552 #if defined (DO_SINGLE_STEP) && 0
6553 /* Single step trace mode */
6557 max_insns = tb->cflags & CF_COUNT_MASK;
6559 max_insns = CF_COUNT_MASK;
6562 /* Set env in case of segfault during code fetch */
6563 while (ctx.exception == POWERPC_EXCP_NONE && gen_opc_ptr < gen_opc_end) {
6564 if (unlikely(env->nb_breakpoints > 0)) {
6565 for (j = 0; j < env->nb_breakpoints; j++) {
6566 if (env->breakpoints[j] == ctx.nip) {
6567 gen_update_nip(&ctx, ctx.nip);
6573 if (unlikely(search_pc)) {
6574 j = gen_opc_ptr - gen_opc_buf;
6578 gen_opc_instr_start[lj++] = 0;
6579 gen_opc_pc[lj] = ctx.nip;
6580 gen_opc_instr_start[lj] = 1;
6581 gen_opc_icount[lj] = num_insns;
6584 #if defined PPC_DEBUG_DISAS
6585 if (loglevel & CPU_LOG_TB_IN_ASM) {
6586 fprintf(logfile, "----------------\n");
6587 fprintf(logfile, "nip=" ADDRX " super=%d ir=%d\n",
6588 ctx.nip, supervisor, (int)msr_ir);
6591 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
6593 if (unlikely(little_endian)) {
6594 ctx.opcode = bswap32(ldl_code(ctx.nip));
6596 ctx.opcode = ldl_code(ctx.nip);
6598 #if defined PPC_DEBUG_DISAS
6599 if (loglevel & CPU_LOG_TB_IN_ASM) {
6600 fprintf(logfile, "translate opcode %08x (%02x %02x %02x) (%s)\n",
6601 ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
6602 opc3(ctx.opcode), little_endian ? "little" : "big");
6606 table = env->opcodes;
6608 handler = table[opc1(ctx.opcode)];
6609 if (is_indirect_opcode(handler)) {
6610 table = ind_table(handler);
6611 handler = table[opc2(ctx.opcode)];
6612 if (is_indirect_opcode(handler)) {
6613 table = ind_table(handler);
6614 handler = table[opc3(ctx.opcode)];
6617 /* Is opcode *REALLY* valid ? */
6618 if (unlikely(handler->handler == &gen_invalid)) {
6619 if (loglevel != 0) {
6620 fprintf(logfile, "invalid/unsupported opcode: "
6621 "%02x - %02x - %02x (%08x) " ADDRX " %d\n",
6622 opc1(ctx.opcode), opc2(ctx.opcode),
6623 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
6625 printf("invalid/unsupported opcode: "
6626 "%02x - %02x - %02x (%08x) " ADDRX " %d\n",
6627 opc1(ctx.opcode), opc2(ctx.opcode),
6628 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
6631 if (unlikely((ctx.opcode & handler->inval) != 0)) {
6632 if (loglevel != 0) {
6633 fprintf(logfile, "invalid bits: %08x for opcode: "
6634 "%02x - %02x - %02x (%08x) " ADDRX "\n",
6635 ctx.opcode & handler->inval, opc1(ctx.opcode),
6636 opc2(ctx.opcode), opc3(ctx.opcode),
6637 ctx.opcode, ctx.nip - 4);
6639 printf("invalid bits: %08x for opcode: "
6640 "%02x - %02x - %02x (%08x) " ADDRX "\n",
6641 ctx.opcode & handler->inval, opc1(ctx.opcode),
6642 opc2(ctx.opcode), opc3(ctx.opcode),
6643 ctx.opcode, ctx.nip - 4);
6645 GEN_EXCP_INVAL(ctxp);
6649 (*(handler->handler))(&ctx);
6650 #if defined(DO_PPC_STATISTICS)
6653 /* Check trace mode exceptions */
6654 if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP &&
6655 (ctx.nip <= 0x100 || ctx.nip > 0xF00) &&
6656 ctx.exception != POWERPC_SYSCALL &&
6657 ctx.exception != POWERPC_EXCP_TRAP &&
6658 ctx.exception != POWERPC_EXCP_BRANCH)) {
6659 GEN_EXCP(ctxp, POWERPC_EXCP_TRACE, 0);
6660 } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
6661 (env->singlestep_enabled) ||
6662 num_insns >= max_insns)) {
6663 /* if we reach a page boundary or are single stepping, stop
6668 #if defined (DO_SINGLE_STEP)
6672 if (tb->cflags & CF_LAST_IO)
6674 if (ctx.exception == POWERPC_EXCP_NONE) {
6675 gen_goto_tb(&ctx, 0, ctx.nip);
6676 } else if (ctx.exception != POWERPC_EXCP_BRANCH) {
6677 if (unlikely(env->singlestep_enabled)) {
6678 gen_update_nip(&ctx, ctx.nip);
6681 /* Generate the return instruction */
6684 gen_icount_end(tb, num_insns);
6685 *gen_opc_ptr = INDEX_op_end;
6686 if (unlikely(search_pc)) {
6687 j = gen_opc_ptr - gen_opc_buf;
6690 gen_opc_instr_start[lj++] = 0;
6692 tb->size = ctx.nip - pc_start;
6693 tb->icount = num_insns;
6695 #if defined(DEBUG_DISAS)
6696 if (loglevel & CPU_LOG_TB_CPU) {
6697 fprintf(logfile, "---------------- excp: %04x\n", ctx.exception);
6698 cpu_dump_state(env, logfile, fprintf, 0);
6700 if (loglevel & CPU_LOG_TB_IN_ASM) {
6702 flags = env->bfd_mach;
6703 flags |= little_endian << 16;
6704 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
6705 target_disas(logfile, pc_start, ctx.nip - pc_start, flags);
6706 fprintf(logfile, "\n");
6711 void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
6713 gen_intermediate_code_internal(env, tb, 0);
6716 void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
6718 gen_intermediate_code_internal(env, tb, 1);
6721 void gen_pc_load(CPUState *env, TranslationBlock *tb,
6722 unsigned long searched_pc, int pc_pos, void *puc)
6725 /* for PPC, we need to look at the micro operation to get the
6727 env->nip = gen_opc_pc[pc_pos];
6728 c = gen_opc_buf[pc_pos];
6730 #if defined(CONFIG_USER_ONLY)
6732 case INDEX_op_ ## op ## _raw
6735 case INDEX_op_ ## op ## _user:\
6736 case INDEX_op_ ## op ## _kernel:\
6737 case INDEX_op_ ## op ## _hypv
6744 type = ACCESS_FLOAT;
6760 env->access_type = type;