2 * PowerPC emulation for qemu: main translation routines.
4 * Copyright (c) 2003-2007 Jocelyn Mayer
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "qemu-common.h"
33 #define CPU_SINGLE_STEP 0x1
34 #define CPU_BRANCH_STEP 0x2
35 #define GDBSTUB_SINGLE_STEP 0x4
37 /* Include definitions for instructions classes and implementations flags */
38 //#define DO_SINGLE_STEP
39 //#define PPC_DEBUG_DISAS
40 //#define DO_PPC_STATISTICS
41 //#define OPTIMIZE_FPRF_UPDATE
43 /*****************************************************************************/
44 /* Code translation helpers */
46 /* global register indexes */
48 static char cpu_reg_names[10*3 + 22*4 /* GPR */
49 #if !defined(TARGET_PPC64)
50 + 10*4 + 22*5 /* SPE GPRh */
52 + 10*4 + 22*5 /* FPR */
53 + 2*(10*6 + 22*7) /* AVRh, AVRl */
55 static TCGv cpu_gpr[32];
56 #if !defined(TARGET_PPC64)
57 static TCGv cpu_gprh[32];
59 static TCGv cpu_fpr[32];
60 static TCGv cpu_avrh[32], cpu_avrl[32];
61 static TCGv cpu_crf[8];
66 static TCGv cpu_fpscr;
68 /* dyngen register indexes */
70 #if defined(TARGET_PPC64)
73 static TCGv cpu_T64[3];
75 static TCGv cpu_FT[3];
76 static TCGv cpu_AVRh[3], cpu_AVRl[3];
78 #include "gen-icount.h"
80 void ppc_translate_init(void)
84 static int done_init = 0;
89 cpu_env = tcg_global_reg_new(TCG_TYPE_PTR, TCG_AREG0, "env");
90 #if TARGET_LONG_BITS > HOST_LONG_BITS
91 cpu_T[0] = tcg_global_mem_new(TCG_TYPE_TL,
92 TCG_AREG0, offsetof(CPUState, t0), "T0");
93 cpu_T[1] = tcg_global_mem_new(TCG_TYPE_TL,
94 TCG_AREG0, offsetof(CPUState, t1), "T1");
95 cpu_T[2] = tcg_global_mem_new(TCG_TYPE_TL,
96 TCG_AREG0, offsetof(CPUState, t2), "T2");
98 cpu_T[0] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG1, "T0");
99 cpu_T[1] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG2, "T1");
101 /* XXX: This is a temporary workaround for i386.
102 * On i386 qemu_st32 runs out of registers.
103 * The proper fix is to remove cpu_T.
105 cpu_T[2] = tcg_global_mem_new(TCG_TYPE_TL,
106 TCG_AREG0, offsetof(CPUState, t2), "T2");
108 cpu_T[2] = tcg_global_reg_new(TCG_TYPE_TL, TCG_AREG3, "T2");
111 #if !defined(TARGET_PPC64)
112 cpu_T64[0] = tcg_global_mem_new(TCG_TYPE_I64,
113 TCG_AREG0, offsetof(CPUState, t0_64),
115 cpu_T64[1] = tcg_global_mem_new(TCG_TYPE_I64,
116 TCG_AREG0, offsetof(CPUState, t1_64),
118 cpu_T64[2] = tcg_global_mem_new(TCG_TYPE_I64,
119 TCG_AREG0, offsetof(CPUState, t2_64),
123 cpu_FT[0] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
124 offsetof(CPUState, ft0), "FT0");
125 cpu_FT[1] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
126 offsetof(CPUState, ft1), "FT1");
127 cpu_FT[2] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
128 offsetof(CPUState, ft2), "FT2");
130 cpu_AVRh[0] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
131 offsetof(CPUState, avr0.u64[0]), "AVR0H");
132 cpu_AVRl[0] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
133 offsetof(CPUState, avr0.u64[1]), "AVR0L");
134 cpu_AVRh[1] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
135 offsetof(CPUState, avr1.u64[0]), "AVR1H");
136 cpu_AVRl[1] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
137 offsetof(CPUState, avr1.u64[1]), "AVR1L");
138 cpu_AVRh[2] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
139 offsetof(CPUState, avr2.u64[0]), "AVR2H");
140 cpu_AVRl[2] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
141 offsetof(CPUState, avr2.u64[1]), "AVR2L");
145 for (i = 0; i < 8; i++) {
146 sprintf(p, "crf%d", i);
147 cpu_crf[i] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
148 offsetof(CPUState, crf[i]), p);
152 for (i = 0; i < 32; i++) {
153 sprintf(p, "r%d", i);
154 cpu_gpr[i] = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
155 offsetof(CPUState, gpr[i]), p);
156 p += (i < 10) ? 3 : 4;
157 #if !defined(TARGET_PPC64)
158 sprintf(p, "r%dH", i);
159 cpu_gprh[i] = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
160 offsetof(CPUState, gprh[i]), p);
161 p += (i < 10) ? 4 : 5;
164 sprintf(p, "fp%d", i);
165 cpu_fpr[i] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
166 offsetof(CPUState, fpr[i]), p);
167 p += (i < 10) ? 4 : 5;
169 sprintf(p, "avr%dH", i);
170 cpu_avrh[i] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
171 offsetof(CPUState, avr[i].u64[0]), p);
172 p += (i < 10) ? 6 : 7;
174 sprintf(p, "avr%dL", i);
175 cpu_avrl[i] = tcg_global_mem_new(TCG_TYPE_I64, TCG_AREG0,
176 offsetof(CPUState, avr[i].u64[1]), p);
177 p += (i < 10) ? 6 : 7;
180 cpu_nip = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
181 offsetof(CPUState, nip), "nip");
183 cpu_ctr = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
184 offsetof(CPUState, ctr), "ctr");
186 cpu_lr = tcg_global_mem_new(TCG_TYPE_TL, TCG_AREG0,
187 offsetof(CPUState, lr), "lr");
189 cpu_xer = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
190 offsetof(CPUState, xer), "xer");
192 cpu_fpscr = tcg_global_mem_new(TCG_TYPE_I32, TCG_AREG0,
193 offsetof(CPUState, fpscr), "fpscr");
195 /* register helpers */
197 #define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
203 #if defined(OPTIMIZE_FPRF_UPDATE)
204 static uint16_t *gen_fprf_buf[OPC_BUF_SIZE];
205 static uint16_t **gen_fprf_ptr;
208 /* internal defines */
209 typedef struct DisasContext {
210 struct TranslationBlock *tb;
214 /* Routine used to access memory */
216 /* Translation flags */
217 #if !defined(CONFIG_USER_ONLY)
220 #if defined(TARGET_PPC64)
226 ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */
227 int singlestep_enabled;
228 int dcache_line_size;
231 struct opc_handler_t {
234 /* instruction type */
237 void (*handler)(DisasContext *ctx);
238 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
241 #if defined(DO_PPC_STATISTICS)
246 static always_inline void gen_reset_fpstatus (void)
248 #ifdef CONFIG_SOFTFLOAT
249 gen_op_reset_fpstatus();
253 static always_inline void gen_compute_fprf (int set_fprf, int set_rc)
256 /* This case might be optimized later */
257 #if defined(OPTIMIZE_FPRF_UPDATE)
258 *gen_fprf_ptr++ = gen_opc_ptr;
260 gen_op_compute_fprf(1);
261 if (unlikely(set_rc))
262 tcg_gen_andi_i32(cpu_crf[1], cpu_T[0], 0xf);
263 gen_op_float_check_status();
264 } else if (unlikely(set_rc)) {
265 /* We always need to compute fpcc */
266 gen_op_compute_fprf(0);
267 tcg_gen_andi_i32(cpu_crf[1], cpu_T[0], 0xf);
269 gen_op_float_check_status();
273 static always_inline void gen_optimize_fprf (void)
275 #if defined(OPTIMIZE_FPRF_UPDATE)
278 for (ptr = gen_fprf_buf; ptr != (gen_fprf_ptr - 1); ptr++)
279 *ptr = INDEX_op_nop1;
280 gen_fprf_ptr = gen_fprf_buf;
284 static always_inline void gen_update_nip (DisasContext *ctx, target_ulong nip)
286 #if defined(TARGET_PPC64)
288 tcg_gen_movi_tl(cpu_nip, nip);
291 tcg_gen_movi_tl(cpu_nip, (uint32_t)nip);
294 #define GEN_EXCP(ctx, excp, error) \
296 if ((ctx)->exception == POWERPC_EXCP_NONE) { \
297 gen_update_nip(ctx, (ctx)->nip); \
299 gen_op_raise_exception_err((excp), (error)); \
300 ctx->exception = (excp); \
303 #define GEN_EXCP_INVAL(ctx) \
304 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
305 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_INVAL)
307 #define GEN_EXCP_PRIVOPC(ctx) \
308 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
309 POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_OPC)
311 #define GEN_EXCP_PRIVREG(ctx) \
312 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
313 POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_REG)
315 #define GEN_EXCP_NO_FP(ctx) \
316 GEN_EXCP(ctx, POWERPC_EXCP_FPU, 0)
318 #define GEN_EXCP_NO_AP(ctx) \
319 GEN_EXCP(ctx, POWERPC_EXCP_APU, 0)
321 #define GEN_EXCP_NO_VR(ctx) \
322 GEN_EXCP(ctx, POWERPC_EXCP_VPU, 0)
324 /* Stop translation */
325 static always_inline void GEN_STOP (DisasContext *ctx)
327 gen_update_nip(ctx, ctx->nip);
328 ctx->exception = POWERPC_EXCP_STOP;
331 /* No need to update nip here, as execution flow will change */
332 static always_inline void GEN_SYNC (DisasContext *ctx)
334 ctx->exception = POWERPC_EXCP_SYNC;
337 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
338 static void gen_##name (DisasContext *ctx); \
339 GEN_OPCODE(name, opc1, opc2, opc3, inval, type); \
340 static void gen_##name (DisasContext *ctx)
342 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
343 static void gen_##name (DisasContext *ctx); \
344 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type); \
345 static void gen_##name (DisasContext *ctx)
347 typedef struct opcode_t {
348 unsigned char opc1, opc2, opc3;
349 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
350 unsigned char pad[5];
352 unsigned char pad[1];
354 opc_handler_t handler;
358 /*****************************************************************************/
359 /*** Instruction decoding ***/
360 #define EXTRACT_HELPER(name, shift, nb) \
361 static always_inline uint32_t name (uint32_t opcode) \
363 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
366 #define EXTRACT_SHELPER(name, shift, nb) \
367 static always_inline int32_t name (uint32_t opcode) \
369 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
373 EXTRACT_HELPER(opc1, 26, 6);
375 EXTRACT_HELPER(opc2, 1, 5);
377 EXTRACT_HELPER(opc3, 6, 5);
378 /* Update Cr0 flags */
379 EXTRACT_HELPER(Rc, 0, 1);
381 EXTRACT_HELPER(rD, 21, 5);
383 EXTRACT_HELPER(rS, 21, 5);
385 EXTRACT_HELPER(rA, 16, 5);
387 EXTRACT_HELPER(rB, 11, 5);
389 EXTRACT_HELPER(rC, 6, 5);
391 EXTRACT_HELPER(crfD, 23, 3);
392 EXTRACT_HELPER(crfS, 18, 3);
393 EXTRACT_HELPER(crbD, 21, 5);
394 EXTRACT_HELPER(crbA, 16, 5);
395 EXTRACT_HELPER(crbB, 11, 5);
397 EXTRACT_HELPER(_SPR, 11, 10);
398 static always_inline uint32_t SPR (uint32_t opcode)
400 uint32_t sprn = _SPR(opcode);
402 return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
404 /*** Get constants ***/
405 EXTRACT_HELPER(IMM, 12, 8);
406 /* 16 bits signed immediate value */
407 EXTRACT_SHELPER(SIMM, 0, 16);
408 /* 16 bits unsigned immediate value */
409 EXTRACT_HELPER(UIMM, 0, 16);
411 EXTRACT_HELPER(NB, 11, 5);
413 EXTRACT_HELPER(SH, 11, 5);
415 EXTRACT_HELPER(MB, 6, 5);
417 EXTRACT_HELPER(ME, 1, 5);
419 EXTRACT_HELPER(TO, 21, 5);
421 EXTRACT_HELPER(CRM, 12, 8);
422 EXTRACT_HELPER(FM, 17, 8);
423 EXTRACT_HELPER(SR, 16, 4);
424 EXTRACT_HELPER(FPIMM, 12, 4);
426 /*** Jump target decoding ***/
428 EXTRACT_SHELPER(d, 0, 16);
429 /* Immediate address */
430 static always_inline target_ulong LI (uint32_t opcode)
432 return (opcode >> 0) & 0x03FFFFFC;
435 static always_inline uint32_t BD (uint32_t opcode)
437 return (opcode >> 0) & 0xFFFC;
440 EXTRACT_HELPER(BO, 21, 5);
441 EXTRACT_HELPER(BI, 16, 5);
442 /* Absolute/relative address */
443 EXTRACT_HELPER(AA, 1, 1);
445 EXTRACT_HELPER(LK, 0, 1);
447 /* Create a mask between <start> and <end> bits */
448 static always_inline target_ulong MASK (uint32_t start, uint32_t end)
452 #if defined(TARGET_PPC64)
453 if (likely(start == 0)) {
454 ret = UINT64_MAX << (63 - end);
455 } else if (likely(end == 63)) {
456 ret = UINT64_MAX >> start;
459 if (likely(start == 0)) {
460 ret = UINT32_MAX << (31 - end);
461 } else if (likely(end == 31)) {
462 ret = UINT32_MAX >> start;
466 ret = (((target_ulong)(-1ULL)) >> (start)) ^
467 (((target_ulong)(-1ULL) >> (end)) >> 1);
468 if (unlikely(start > end))
475 /*****************************************************************************/
476 /* PowerPC Instructions types definitions */
478 PPC_NONE = 0x0000000000000000ULL,
479 /* PowerPC base instructions set */
480 PPC_INSNS_BASE = 0x0000000000000001ULL,
481 /* integer operations instructions */
482 #define PPC_INTEGER PPC_INSNS_BASE
483 /* flow control instructions */
484 #define PPC_FLOW PPC_INSNS_BASE
485 /* virtual memory instructions */
486 #define PPC_MEM PPC_INSNS_BASE
487 /* ld/st with reservation instructions */
488 #define PPC_RES PPC_INSNS_BASE
489 /* spr/msr access instructions */
490 #define PPC_MISC PPC_INSNS_BASE
491 /* Deprecated instruction sets */
492 /* Original POWER instruction set */
493 PPC_POWER = 0x0000000000000002ULL,
494 /* POWER2 instruction set extension */
495 PPC_POWER2 = 0x0000000000000004ULL,
496 /* Power RTC support */
497 PPC_POWER_RTC = 0x0000000000000008ULL,
498 /* Power-to-PowerPC bridge (601) */
499 PPC_POWER_BR = 0x0000000000000010ULL,
500 /* 64 bits PowerPC instruction set */
501 PPC_64B = 0x0000000000000020ULL,
502 /* New 64 bits extensions (PowerPC 2.0x) */
503 PPC_64BX = 0x0000000000000040ULL,
504 /* 64 bits hypervisor extensions */
505 PPC_64H = 0x0000000000000080ULL,
506 /* New wait instruction (PowerPC 2.0x) */
507 PPC_WAIT = 0x0000000000000100ULL,
508 /* Time base mftb instruction */
509 PPC_MFTB = 0x0000000000000200ULL,
511 /* Fixed-point unit extensions */
512 /* PowerPC 602 specific */
513 PPC_602_SPEC = 0x0000000000000400ULL,
514 /* isel instruction */
515 PPC_ISEL = 0x0000000000000800ULL,
516 /* popcntb instruction */
517 PPC_POPCNTB = 0x0000000000001000ULL,
518 /* string load / store */
519 PPC_STRING = 0x0000000000002000ULL,
521 /* Floating-point unit extensions */
522 /* Optional floating point instructions */
523 PPC_FLOAT = 0x0000000000010000ULL,
524 /* New floating-point extensions (PowerPC 2.0x) */
525 PPC_FLOAT_EXT = 0x0000000000020000ULL,
526 PPC_FLOAT_FSQRT = 0x0000000000040000ULL,
527 PPC_FLOAT_FRES = 0x0000000000080000ULL,
528 PPC_FLOAT_FRSQRTE = 0x0000000000100000ULL,
529 PPC_FLOAT_FRSQRTES = 0x0000000000200000ULL,
530 PPC_FLOAT_FSEL = 0x0000000000400000ULL,
531 PPC_FLOAT_STFIWX = 0x0000000000800000ULL,
533 /* Vector/SIMD extensions */
534 /* Altivec support */
535 PPC_ALTIVEC = 0x0000000001000000ULL,
536 /* PowerPC 2.03 SPE extension */
537 PPC_SPE = 0x0000000002000000ULL,
538 /* PowerPC 2.03 SPE floating-point extension */
539 PPC_SPEFPU = 0x0000000004000000ULL,
541 /* Optional memory control instructions */
542 PPC_MEM_TLBIA = 0x0000000010000000ULL,
543 PPC_MEM_TLBIE = 0x0000000020000000ULL,
544 PPC_MEM_TLBSYNC = 0x0000000040000000ULL,
545 /* sync instruction */
546 PPC_MEM_SYNC = 0x0000000080000000ULL,
547 /* eieio instruction */
548 PPC_MEM_EIEIO = 0x0000000100000000ULL,
550 /* Cache control instructions */
551 PPC_CACHE = 0x0000000200000000ULL,
552 /* icbi instruction */
553 PPC_CACHE_ICBI = 0x0000000400000000ULL,
554 /* dcbz instruction with fixed cache line size */
555 PPC_CACHE_DCBZ = 0x0000000800000000ULL,
556 /* dcbz instruction with tunable cache line size */
557 PPC_CACHE_DCBZT = 0x0000001000000000ULL,
558 /* dcba instruction */
559 PPC_CACHE_DCBA = 0x0000002000000000ULL,
560 /* Freescale cache locking instructions */
561 PPC_CACHE_LOCK = 0x0000004000000000ULL,
563 /* MMU related extensions */
564 /* external control instructions */
565 PPC_EXTERN = 0x0000010000000000ULL,
566 /* segment register access instructions */
567 PPC_SEGMENT = 0x0000020000000000ULL,
568 /* PowerPC 6xx TLB management instructions */
569 PPC_6xx_TLB = 0x0000040000000000ULL,
570 /* PowerPC 74xx TLB management instructions */
571 PPC_74xx_TLB = 0x0000080000000000ULL,
572 /* PowerPC 40x TLB management instructions */
573 PPC_40x_TLB = 0x0000100000000000ULL,
574 /* segment register access instructions for PowerPC 64 "bridge" */
575 PPC_SEGMENT_64B = 0x0000200000000000ULL,
577 PPC_SLBI = 0x0000400000000000ULL,
579 /* Embedded PowerPC dedicated instructions */
580 PPC_WRTEE = 0x0001000000000000ULL,
581 /* PowerPC 40x exception model */
582 PPC_40x_EXCP = 0x0002000000000000ULL,
583 /* PowerPC 405 Mac instructions */
584 PPC_405_MAC = 0x0004000000000000ULL,
585 /* PowerPC 440 specific instructions */
586 PPC_440_SPEC = 0x0008000000000000ULL,
587 /* BookE (embedded) PowerPC specification */
588 PPC_BOOKE = 0x0010000000000000ULL,
589 /* mfapidi instruction */
590 PPC_MFAPIDI = 0x0020000000000000ULL,
591 /* tlbiva instruction */
592 PPC_TLBIVA = 0x0040000000000000ULL,
593 /* tlbivax instruction */
594 PPC_TLBIVAX = 0x0080000000000000ULL,
595 /* PowerPC 4xx dedicated instructions */
596 PPC_4xx_COMMON = 0x0100000000000000ULL,
597 /* PowerPC 40x ibct instructions */
598 PPC_40x_ICBT = 0x0200000000000000ULL,
599 /* rfmci is not implemented in all BookE PowerPC */
600 PPC_RFMCI = 0x0400000000000000ULL,
601 /* rfdi instruction */
602 PPC_RFDI = 0x0800000000000000ULL,
604 PPC_DCR = 0x1000000000000000ULL,
605 /* DCR extended accesse */
606 PPC_DCRX = 0x2000000000000000ULL,
607 /* user-mode DCR access, implemented in PowerPC 460 */
608 PPC_DCRUX = 0x4000000000000000ULL,
611 /*****************************************************************************/
612 /* PowerPC instructions table */
613 #if HOST_LONG_BITS == 64
618 #if defined(__APPLE__)
619 #define OPCODES_SECTION \
620 __attribute__ ((section("__TEXT,__opcodes"), unused, aligned (OPC_ALIGN) ))
622 #define OPCODES_SECTION \
623 __attribute__ ((section(".opcodes"), unused, aligned (OPC_ALIGN) ))
626 #if defined(DO_PPC_STATISTICS)
627 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
628 OPCODES_SECTION opcode_t opc_##name = { \
636 .handler = &gen_##name, \
637 .oname = stringify(name), \
639 .oname = stringify(name), \
641 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
642 OPCODES_SECTION opcode_t opc_##name = { \
650 .handler = &gen_##name, \
656 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
657 OPCODES_SECTION opcode_t opc_##name = { \
665 .handler = &gen_##name, \
667 .oname = stringify(name), \
669 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
670 OPCODES_SECTION opcode_t opc_##name = { \
678 .handler = &gen_##name, \
684 #define GEN_OPCODE_MARK(name) \
685 OPCODES_SECTION opcode_t opc_##name = { \
691 .inval = 0x00000000, \
695 .oname = stringify(name), \
698 /* Start opcode list */
699 GEN_OPCODE_MARK(start);
701 /* Invalid instruction */
702 GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE)
707 static opc_handler_t invalid_handler = {
710 .handler = gen_invalid,
713 /*** Integer comparison ***/
715 static always_inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf)
719 tcg_gen_trunc_tl_i32(cpu_crf[crf], cpu_xer);
720 tcg_gen_shri_i32(cpu_crf[crf], cpu_crf[crf], XER_SO);
721 tcg_gen_andi_i32(cpu_crf[crf], cpu_crf[crf], 1);
723 l1 = gen_new_label();
724 l2 = gen_new_label();
725 l3 = gen_new_label();
727 tcg_gen_brcond_tl(TCG_COND_LT, arg0, arg1, l1);
728 tcg_gen_brcond_tl(TCG_COND_GT, arg0, arg1, l2);
730 tcg_gen_brcond_tl(TCG_COND_LTU, arg0, arg1, l1);
731 tcg_gen_brcond_tl(TCG_COND_GTU, arg0, arg1, l2);
733 tcg_gen_ori_i32(cpu_crf[crf], cpu_crf[crf], 1 << CRF_EQ);
736 tcg_gen_ori_i32(cpu_crf[crf], cpu_crf[crf], 1 << CRF_LT);
739 tcg_gen_ori_i32(cpu_crf[crf], cpu_crf[crf], 1 << CRF_GT);
743 static always_inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf)
745 TCGv t0 = tcg_const_local_tl(arg1);
746 gen_op_cmp(arg0, t0, s, crf);
750 #if defined(TARGET_PPC64)
751 static always_inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf)
754 t0 = tcg_temp_local_new(TCG_TYPE_TL);
755 t1 = tcg_temp_local_new(TCG_TYPE_TL);
757 tcg_gen_ext32s_tl(t0, arg0);
758 tcg_gen_ext32s_tl(t1, arg1);
760 tcg_gen_ext32u_tl(t0, arg0);
761 tcg_gen_ext32u_tl(t1, arg1);
763 gen_op_cmp(t0, t1, s, crf);
768 static always_inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf)
770 TCGv t0 = tcg_const_local_tl(arg1);
771 gen_op_cmp32(arg0, t0, s, crf);
776 static always_inline void gen_set_Rc0 (DisasContext *ctx, TCGv reg)
778 #if defined(TARGET_PPC64)
780 gen_op_cmpi32(reg, 0, 1, 0);
783 gen_op_cmpi(reg, 0, 1, 0);
787 GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER)
789 #if defined(TARGET_PPC64)
790 if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
791 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
792 1, crfD(ctx->opcode));
795 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
796 1, crfD(ctx->opcode));
800 GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER)
802 #if defined(TARGET_PPC64)
803 if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
804 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
805 1, crfD(ctx->opcode));
808 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode),
809 1, crfD(ctx->opcode));
813 GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER)
815 #if defined(TARGET_PPC64)
816 if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
817 gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
818 0, crfD(ctx->opcode));
821 gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)],
822 0, crfD(ctx->opcode));
826 GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER)
828 #if defined(TARGET_PPC64)
829 if (!(ctx->sf_mode && (ctx->opcode & 0x00200000)))
830 gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
831 0, crfD(ctx->opcode));
834 gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode),
835 0, crfD(ctx->opcode));
838 /* isel (PowerPC 2.03 specification) */
839 GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL)
842 uint32_t bi = rC(ctx->opcode);
846 l1 = gen_new_label();
847 l2 = gen_new_label();
849 mask = 1 << (3 - (bi & 0x03));
850 t0 = tcg_temp_new(TCG_TYPE_I32);
851 tcg_gen_andi_i32(t0, cpu_crf[bi >> 2], mask);
852 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1);
853 if (rA(ctx->opcode) == 0)
854 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0);
856 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
859 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
863 /*** Integer arithmetic ***/
865 static always_inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0, TCGv arg1, TCGv arg2, int sub)
870 l1 = gen_new_label();
871 /* Start with XER OV disabled, the most likely case */
872 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
873 t0 = tcg_temp_local_new(TCG_TYPE_TL);
874 tcg_gen_xor_tl(t0, arg0, arg1);
875 #if defined(TARGET_PPC64)
877 tcg_gen_ext32s_tl(t0, t0);
880 tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0, l1);
882 tcg_gen_brcondi_tl(TCG_COND_GE, t0, 0, l1);
883 tcg_gen_xor_tl(t0, arg1, arg2);
884 #if defined(TARGET_PPC64)
886 tcg_gen_ext32s_tl(t0, t0);
889 tcg_gen_brcondi_tl(TCG_COND_GE, t0, 0, l1);
891 tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0, l1);
892 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
897 static always_inline void gen_op_arith_compute_ca(DisasContext *ctx, TCGv arg1, TCGv arg2, int sub)
899 int l1 = gen_new_label();
901 #if defined(TARGET_PPC64)
902 if (!(ctx->sf_mode)) {
904 t0 = tcg_temp_new(TCG_TYPE_TL);
905 t1 = tcg_temp_new(TCG_TYPE_TL);
907 tcg_gen_ext32u_tl(t0, arg1);
908 tcg_gen_ext32u_tl(t1, arg2);
910 tcg_gen_brcond_tl(TCG_COND_GTU, t0, t1, l1);
912 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
917 tcg_gen_brcond_tl(TCG_COND_GTU, arg1, arg2, l1);
919 tcg_gen_brcond_tl(TCG_COND_GEU, arg1, arg2, l1);
921 tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA);
925 /* Common add function */
926 static always_inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1, TCGv arg2,
927 int add_ca, int compute_ca, int compute_ov)
931 if ((!compute_ca && !compute_ov) ||
932 (GET_TCGV(ret) != GET_TCGV(arg1) && GET_TCGV(ret) != GET_TCGV(arg2))) {
935 t0 = tcg_temp_local_new(TCG_TYPE_TL);
939 t1 = tcg_temp_local_new(TCG_TYPE_TL);
940 tcg_gen_andi_tl(t1, cpu_xer, (1 << XER_CA));
941 tcg_gen_shri_tl(t1, t1, XER_CA);
944 if (compute_ca && compute_ov) {
945 /* Start with XER CA and OV disabled, the most likely case */
946 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~((1 << XER_CA) | (1 << XER_OV)));
947 } else if (compute_ca) {
948 /* Start with XER CA disabled, the most likely case */
949 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
950 } else if (compute_ov) {
951 /* Start with XER OV disabled, the most likely case */
952 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
955 tcg_gen_add_tl(t0, arg1, arg2);
958 gen_op_arith_compute_ca(ctx, t0, arg1, 0);
961 tcg_gen_add_tl(t0, t0, t1);
962 gen_op_arith_compute_ca(ctx, t0, t1, 0);
966 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 0);
969 if (unlikely(Rc(ctx->opcode) != 0))
970 gen_set_Rc0(ctx, t0);
972 if (GET_TCGV(t0) != GET_TCGV(ret)) {
973 tcg_gen_mov_tl(ret, t0);
977 /* Add functions with two operands */
978 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
979 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER) \
981 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
982 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
983 add_ca, compute_ca, compute_ov); \
985 /* Add functions with one operand and one immediate */
986 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
987 add_ca, compute_ca, compute_ov) \
988 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER) \
990 TCGv t0 = tcg_const_local_tl(const_val); \
991 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
992 cpu_gpr[rA(ctx->opcode)], t0, \
993 add_ca, compute_ca, compute_ov); \
997 /* add add. addo addo. */
998 GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0)
999 GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1)
1000 /* addc addc. addco addco. */
1001 GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0)
1002 GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1)
1003 /* adde adde. addeo addeo. */
1004 GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0)
1005 GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1)
1006 /* addme addme. addmeo addmeo. */
1007 GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0)
1008 GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1)
1009 /* addze addze. addzeo addzeo.*/
1010 GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0)
1011 GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1)
1013 GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1015 target_long simm = SIMM(ctx->opcode);
1017 if (rA(ctx->opcode) == 0) {
1019 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm);
1021 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], simm);
1025 static always_inline void gen_op_addic (DisasContext *ctx, TCGv ret, TCGv arg1,
1028 target_long simm = SIMM(ctx->opcode);
1030 /* Start with XER CA and OV disabled, the most likely case */
1031 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
1033 if (likely(simm != 0)) {
1034 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1035 tcg_gen_addi_tl(t0, arg1, simm);
1036 gen_op_arith_compute_ca(ctx, t0, arg1, 0);
1037 tcg_gen_mov_tl(ret, t0);
1040 tcg_gen_mov_tl(ret, arg1);
1043 gen_set_Rc0(ctx, ret);
1046 GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1048 gen_op_addic(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0);
1050 GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1052 gen_op_addic(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 1);
1055 GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1057 target_long simm = SIMM(ctx->opcode);
1059 if (rA(ctx->opcode) == 0) {
1061 tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm << 16);
1063 tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], simm << 16);
1067 static always_inline void gen_op_arith_divw (DisasContext *ctx, TCGv ret, TCGv arg1, TCGv arg2,
1068 int sign, int compute_ov)
1070 int l1 = gen_new_label();
1071 int l2 = gen_new_label();
1072 TCGv t0 = tcg_temp_local_new(TCG_TYPE_I32);
1073 TCGv t1 = tcg_temp_local_new(TCG_TYPE_I32);
1075 tcg_gen_trunc_tl_i32(t0, arg1);
1076 tcg_gen_trunc_tl_i32(t1, arg2);
1077 tcg_gen_brcondi_i32(TCG_COND_EQ, t1, 0, l1);
1079 int l3 = gen_new_label();
1080 tcg_gen_brcondi_i32(TCG_COND_NE, t1, -1, l3);
1081 tcg_gen_brcondi_i32(TCG_COND_EQ, t0, INT32_MIN, l1);
1083 tcg_gen_div_i32(t0, t0, t1);
1085 tcg_gen_divu_i32(t0, t0, t1);
1088 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
1093 tcg_gen_sari_i32(t0, t0, 31);
1095 tcg_gen_movi_i32(t0, 0);
1098 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
1101 tcg_gen_extu_i32_tl(ret, t0);
1104 if (unlikely(Rc(ctx->opcode) != 0))
1105 gen_set_Rc0(ctx, ret);
1108 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
1109 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER) \
1111 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
1112 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1113 sign, compute_ov); \
1115 /* divwu divwu. divwuo divwuo. */
1116 GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0);
1117 GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1);
1118 /* divw divw. divwo divwo. */
1119 GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0);
1120 GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1);
1121 #if defined(TARGET_PPC64)
1122 static always_inline void gen_op_arith_divd (DisasContext *ctx, TCGv ret, TCGv arg1, TCGv arg2,
1123 int sign, int compute_ov)
1125 int l1 = gen_new_label();
1126 int l2 = gen_new_label();
1128 tcg_gen_brcondi_i64(TCG_COND_EQ, arg2, 0, l1);
1130 int l3 = gen_new_label();
1131 tcg_gen_brcondi_i64(TCG_COND_NE, arg2, -1, l3);
1132 tcg_gen_brcondi_i64(TCG_COND_EQ, arg1, INT64_MIN, l1);
1134 tcg_gen_div_i64(ret, arg1, arg2);
1136 tcg_gen_divu_i64(ret, arg1, arg2);
1139 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
1144 tcg_gen_sari_i64(ret, arg1, 63);
1146 tcg_gen_movi_i64(ret, 0);
1149 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
1152 if (unlikely(Rc(ctx->opcode) != 0))
1153 gen_set_Rc0(ctx, ret);
1155 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1156 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) \
1158 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1159 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1160 sign, compute_ov); \
1162 /* divwu divwu. divwuo divwuo. */
1163 GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0);
1164 GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1);
1165 /* divw divw. divwo divwo. */
1166 GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0);
1167 GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1);
1171 GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER)
1175 t0 = tcg_temp_new(TCG_TYPE_I64);
1176 t1 = tcg_temp_new(TCG_TYPE_I64);
1177 #if defined(TARGET_PPC64)
1178 tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]);
1179 tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]);
1180 tcg_gen_mul_i64(t0, t0, t1);
1181 tcg_gen_shri_i64(cpu_gpr[rD(ctx->opcode)], t0, 32);
1183 tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1184 tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1185 tcg_gen_mul_i64(t0, t0, t1);
1186 tcg_gen_shri_i64(t0, t0, 32);
1187 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t0);
1191 if (unlikely(Rc(ctx->opcode) != 0))
1192 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1194 /* mulhwu mulhwu. */
1195 GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER)
1199 t0 = tcg_temp_new(TCG_TYPE_I64);
1200 t1 = tcg_temp_new(TCG_TYPE_I64);
1201 #if defined(TARGET_PPC64)
1202 tcg_gen_ext32u_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1203 tcg_gen_ext32u_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1204 tcg_gen_mul_i64(t0, t0, t1);
1205 tcg_gen_shri_i64(cpu_gpr[rD(ctx->opcode)], t0, 32);
1207 tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1208 tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1209 tcg_gen_mul_i64(t0, t0, t1);
1210 tcg_gen_shri_i64(t0, t0, 32);
1211 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t0);
1215 if (unlikely(Rc(ctx->opcode) != 0))
1216 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1219 GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER)
1221 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1222 cpu_gpr[rB(ctx->opcode)]);
1223 tcg_gen_ext32s_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)]);
1224 if (unlikely(Rc(ctx->opcode) != 0))
1225 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1227 /* mullwo mullwo. */
1228 GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER)
1233 t0 = tcg_temp_local_new(TCG_TYPE_I64);
1234 t1 = tcg_temp_local_new(TCG_TYPE_I64);
1235 l1 = gen_new_label();
1236 /* Start with XER OV disabled, the most likely case */
1237 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
1238 #if defined(TARGET_PPC64)
1239 tcg_gen_ext32s_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1240 tcg_gen_ext32s_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1242 tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]);
1243 tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]);
1245 tcg_gen_mul_i64(t0, t0, t1);
1246 #if defined(TARGET_PPC64)
1247 tcg_gen_ext32s_i64(cpu_gpr[rD(ctx->opcode)], t0);
1248 tcg_gen_brcond_i64(TCG_COND_EQ, t0, cpu_gpr[rD(ctx->opcode)], l1);
1250 tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t0);
1251 tcg_gen_ext32s_i64(t1, t0);
1252 tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1);
1254 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
1256 if (unlikely(Rc(ctx->opcode) != 0))
1257 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1260 GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1262 tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1265 #if defined(TARGET_PPC64)
1266 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
1267 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) \
1269 tcg_gen_helper_1_2(helper_##name, cpu_gpr[rD(ctx->opcode)], \
1270 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
1271 if (unlikely(Rc(ctx->opcode) != 0)) \
1272 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1275 GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00);
1276 /* mulhdu mulhdu. */
1277 GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02);
1279 GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B)
1281 tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)],
1282 cpu_gpr[rB(ctx->opcode)]);
1283 if (unlikely(Rc(ctx->opcode) != 0))
1284 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]);
1286 /* mulldo mulldo. */
1287 GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17);
1290 /* neg neg. nego nego. */
1291 static always_inline void gen_op_neg (DisasContext *ctx, TCGv ret, TCGv arg1, int ov_check)
1295 l1 = gen_new_label();
1296 l2 = gen_new_label();
1297 #if defined(TARGET_PPC64)
1299 tcg_gen_brcondi_tl(TCG_COND_EQ, arg1, INT64_MIN, l1);
1301 TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
1302 tcg_gen_ext32s_tl(t0, arg1);
1303 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, INT32_MIN, l1);
1306 tcg_gen_brcondi_tl(TCG_COND_EQ, arg1, INT32_MIN, l1);
1308 tcg_gen_neg_tl(ret, arg1);
1310 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
1314 tcg_gen_mov_tl(ret, arg1);
1316 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
1319 if (unlikely(Rc(ctx->opcode) != 0))
1320 gen_set_Rc0(ctx, ret);
1322 GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER)
1324 gen_op_neg(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0);
1326 GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER)
1328 gen_op_neg(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 1);
1331 /* Common subf function */
1332 static always_inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1, TCGv arg2,
1333 int add_ca, int compute_ca, int compute_ov)
1337 if ((!compute_ca && !compute_ov) ||
1338 (GET_TCGV(ret) != GET_TCGV(arg1) && GET_TCGV(ret) != GET_TCGV(arg2))) {
1341 t0 = tcg_temp_local_new(TCG_TYPE_TL);
1345 t1 = tcg_temp_local_new(TCG_TYPE_TL);
1346 tcg_gen_andi_tl(t1, cpu_xer, (1 << XER_CA));
1347 tcg_gen_shri_tl(t1, t1, XER_CA);
1350 if (compute_ca && compute_ov) {
1351 /* Start with XER CA and OV disabled, the most likely case */
1352 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~((1 << XER_CA) | (1 << XER_OV)));
1353 } else if (compute_ca) {
1354 /* Start with XER CA disabled, the most likely case */
1355 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
1356 } else if (compute_ov) {
1357 /* Start with XER OV disabled, the most likely case */
1358 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
1362 tcg_gen_not_tl(t0, arg1);
1363 tcg_gen_add_tl(t0, t0, arg2);
1364 gen_op_arith_compute_ca(ctx, t0, arg2, 0);
1365 tcg_gen_add_tl(t0, t0, t1);
1366 gen_op_arith_compute_ca(ctx, t0, t1, 0);
1369 tcg_gen_sub_tl(t0, arg2, arg1);
1371 gen_op_arith_compute_ca(ctx, t0, arg2, 1);
1375 gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1);
1378 if (unlikely(Rc(ctx->opcode) != 0))
1379 gen_set_Rc0(ctx, t0);
1381 if (GET_TCGV(t0) != GET_TCGV(ret)) {
1382 tcg_gen_mov_tl(ret, t0);
1386 /* Sub functions with Two operands functions */
1387 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1388 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER) \
1390 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1391 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1392 add_ca, compute_ca, compute_ov); \
1394 /* Sub functions with one operand and one immediate */
1395 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1396 add_ca, compute_ca, compute_ov) \
1397 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER) \
1399 TCGv t0 = tcg_const_local_tl(const_val); \
1400 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1401 cpu_gpr[rA(ctx->opcode)], t0, \
1402 add_ca, compute_ca, compute_ov); \
1403 tcg_temp_free(t0); \
1405 /* subf subf. subfo subfo. */
1406 GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0)
1407 GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1)
1408 /* subfc subfc. subfco subfco. */
1409 GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0)
1410 GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1)
1411 /* subfe subfe. subfeo subfo. */
1412 GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0)
1413 GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1)
1414 /* subfme subfme. subfmeo subfmeo. */
1415 GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0)
1416 GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1)
1417 /* subfze subfze. subfzeo subfzeo.*/
1418 GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0)
1419 GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1)
1421 GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1423 /* Start with XER CA and OV disabled, the most likely case */
1424 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
1425 TCGv t0 = tcg_temp_local_new(TCG_TYPE_TL);
1426 TCGv t1 = tcg_const_local_tl(SIMM(ctx->opcode));
1427 tcg_gen_sub_tl(t0, t1, cpu_gpr[rA(ctx->opcode)]);
1428 gen_op_arith_compute_ca(ctx, t0, t1, 1);
1430 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0);
1434 /*** Integer logical ***/
1435 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1436 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type) \
1438 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1439 cpu_gpr[rB(ctx->opcode)]); \
1440 if (unlikely(Rc(ctx->opcode) != 0)) \
1441 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1444 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1445 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type) \
1447 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1448 if (unlikely(Rc(ctx->opcode) != 0)) \
1449 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1453 GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER);
1455 GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER);
1457 GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1459 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode));
1460 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1463 GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1465 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16);
1466 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1469 GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER)
1471 tcg_gen_helper_1_1(helper_cntlzw, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1472 if (unlikely(Rc(ctx->opcode) != 0))
1473 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1476 GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER);
1477 /* extsb & extsb. */
1478 GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER);
1479 /* extsh & extsh. */
1480 GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER);
1482 GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER);
1484 GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER);
1486 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER)
1490 rs = rS(ctx->opcode);
1491 ra = rA(ctx->opcode);
1492 rb = rB(ctx->opcode);
1493 /* Optimisation for mr. ri case */
1494 if (rs != ra || rs != rb) {
1496 tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]);
1498 tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]);
1499 if (unlikely(Rc(ctx->opcode) != 0))
1500 gen_set_Rc0(ctx, cpu_gpr[ra]);
1501 } else if (unlikely(Rc(ctx->opcode) != 0)) {
1502 gen_set_Rc0(ctx, cpu_gpr[rs]);
1503 #if defined(TARGET_PPC64)
1509 /* Set process priority to low */
1513 /* Set process priority to medium-low */
1517 /* Set process priority to normal */
1520 #if !defined(CONFIG_USER_ONLY)
1522 if (ctx->supervisor > 0) {
1523 /* Set process priority to very low */
1528 if (ctx->supervisor > 0) {
1529 /* Set process priority to medium-hight */
1534 if (ctx->supervisor > 0) {
1535 /* Set process priority to high */
1540 if (ctx->supervisor > 1) {
1541 /* Set process priority to very high */
1551 TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
1552 tcg_gen_ld_tl(t0, cpu_env, offsetof(CPUState, spr[SPR_PPR]));
1553 tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL);
1554 tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50);
1555 tcg_gen_st_tl(t0, cpu_env, offsetof(CPUState, spr[SPR_PPR]));
1562 GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER);
1564 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER)
1566 /* Optimisation for "set to zero" case */
1567 if (rS(ctx->opcode) != rB(ctx->opcode))
1568 tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1570 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
1571 if (unlikely(Rc(ctx->opcode) != 0))
1572 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1575 GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1577 target_ulong uimm = UIMM(ctx->opcode);
1579 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1581 /* XXX: should handle special NOPs for POWER series */
1584 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
1587 GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1589 target_ulong uimm = UIMM(ctx->opcode);
1591 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1595 tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
1598 GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1600 target_ulong uimm = UIMM(ctx->opcode);
1602 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1606 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm);
1609 GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1611 target_ulong uimm = UIMM(ctx->opcode);
1613 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1617 tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16);
1619 /* popcntb : PowerPC 2.03 specification */
1620 GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB)
1622 #if defined(TARGET_PPC64)
1624 tcg_gen_helper_1_1(helper_popcntb_64, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1627 tcg_gen_helper_1_1(helper_popcntb, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1630 #if defined(TARGET_PPC64)
1631 /* extsw & extsw. */
1632 GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B);
1634 GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B)
1636 tcg_gen_helper_1_1(helper_cntlzd, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1637 if (unlikely(Rc(ctx->opcode) != 0))
1638 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1642 /*** Integer rotate ***/
1643 /* rlwimi & rlwimi. */
1644 GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1646 uint32_t mb, me, sh;
1648 mb = MB(ctx->opcode);
1649 me = ME(ctx->opcode);
1650 sh = SH(ctx->opcode);
1651 if (likely(sh == 0 && mb == 0 && me == 31)) {
1652 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1657 t0 = tcg_temp_new(TCG_TYPE_TL);
1658 #if defined(TARGET_PPC64)
1659 t1 = tcg_temp_new(TCG_TYPE_I32);
1660 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1661 tcg_gen_rotli_i32(t1, t1, sh);
1662 tcg_gen_extu_i32_i64(t0, t1);
1665 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1667 #if defined(TARGET_PPC64)
1671 mask = MASK(mb, me);
1672 t1 = tcg_temp_new(TCG_TYPE_TL);
1673 tcg_gen_andi_tl(t0, t0, mask);
1674 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1675 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1679 if (unlikely(Rc(ctx->opcode) != 0))
1680 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1682 /* rlwinm & rlwinm. */
1683 GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1685 uint32_t mb, me, sh;
1687 sh = SH(ctx->opcode);
1688 mb = MB(ctx->opcode);
1689 me = ME(ctx->opcode);
1691 if (likely(mb == 0 && me == (31 - sh))) {
1692 if (likely(sh == 0)) {
1693 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1695 TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
1696 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1697 tcg_gen_shli_tl(t0, t0, sh);
1698 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1701 } else if (likely(sh != 0 && me == 31 && sh == (32 - mb))) {
1702 TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
1703 tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1704 tcg_gen_shri_tl(t0, t0, mb);
1705 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0);
1708 TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
1709 #if defined(TARGET_PPC64)
1710 TCGv t1 = tcg_temp_new(TCG_TYPE_I32);
1711 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1712 tcg_gen_rotli_i32(t1, t1, sh);
1713 tcg_gen_extu_i32_i64(t0, t1);
1716 tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh);
1718 #if defined(TARGET_PPC64)
1722 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1725 if (unlikely(Rc(ctx->opcode) != 0))
1726 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1728 /* rlwnm & rlwnm. */
1729 GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1733 #if defined(TARGET_PPC64)
1737 mb = MB(ctx->opcode);
1738 me = ME(ctx->opcode);
1739 t0 = tcg_temp_new(TCG_TYPE_TL);
1740 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1f);
1741 #if defined(TARGET_PPC64)
1742 t1 = tcg_temp_new(TCG_TYPE_I32);
1743 t2 = tcg_temp_new(TCG_TYPE_I32);
1744 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]);
1745 tcg_gen_trunc_i64_i32(t2, t0);
1746 tcg_gen_rotl_i32(t1, t1, t2);
1747 tcg_gen_extu_i32_i64(t0, t1);
1751 tcg_gen_rotl_i32(t0, cpu_gpr[rS(ctx->opcode)], t0);
1753 if (unlikely(mb != 0 || me != 31)) {
1754 #if defined(TARGET_PPC64)
1758 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1760 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1763 if (unlikely(Rc(ctx->opcode) != 0))
1764 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1767 #if defined(TARGET_PPC64)
1768 #define GEN_PPC64_R2(name, opc1, opc2) \
1769 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1771 gen_##name(ctx, 0); \
1773 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1776 gen_##name(ctx, 1); \
1778 #define GEN_PPC64_R4(name, opc1, opc2) \
1779 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1781 gen_##name(ctx, 0, 0); \
1783 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
1786 gen_##name(ctx, 0, 1); \
1788 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1791 gen_##name(ctx, 1, 0); \
1793 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
1796 gen_##name(ctx, 1, 1); \
1799 static always_inline void gen_rldinm (DisasContext *ctx, uint32_t mb,
1800 uint32_t me, uint32_t sh)
1802 if (likely(sh != 0 && mb == 0 && me == (63 - sh))) {
1803 tcg_gen_shli_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
1804 } else if (likely(sh != 0 && me == 63 && sh == (64 - mb))) {
1805 tcg_gen_shri_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], mb);
1807 TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
1808 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
1809 if (likely(mb == 0 && me == 63)) {
1810 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1812 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1816 if (unlikely(Rc(ctx->opcode) != 0))
1817 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1819 /* rldicl - rldicl. */
1820 static always_inline void gen_rldicl (DisasContext *ctx, int mbn, int shn)
1824 sh = SH(ctx->opcode) | (shn << 5);
1825 mb = MB(ctx->opcode) | (mbn << 5);
1826 gen_rldinm(ctx, mb, 63, sh);
1828 GEN_PPC64_R4(rldicl, 0x1E, 0x00);
1829 /* rldicr - rldicr. */
1830 static always_inline void gen_rldicr (DisasContext *ctx, int men, int shn)
1834 sh = SH(ctx->opcode) | (shn << 5);
1835 me = MB(ctx->opcode) | (men << 5);
1836 gen_rldinm(ctx, 0, me, sh);
1838 GEN_PPC64_R4(rldicr, 0x1E, 0x02);
1839 /* rldic - rldic. */
1840 static always_inline void gen_rldic (DisasContext *ctx, int mbn, int shn)
1844 sh = SH(ctx->opcode) | (shn << 5);
1845 mb = MB(ctx->opcode) | (mbn << 5);
1846 gen_rldinm(ctx, mb, 63 - sh, sh);
1848 GEN_PPC64_R4(rldic, 0x1E, 0x04);
1850 static always_inline void gen_rldnm (DisasContext *ctx, uint32_t mb,
1855 mb = MB(ctx->opcode);
1856 me = ME(ctx->opcode);
1857 t0 = tcg_temp_new(TCG_TYPE_TL);
1858 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f);
1859 tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0);
1860 if (unlikely(mb != 0 || me != 63)) {
1861 tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me));
1863 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0);
1866 if (unlikely(Rc(ctx->opcode) != 0))
1867 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1870 /* rldcl - rldcl. */
1871 static always_inline void gen_rldcl (DisasContext *ctx, int mbn)
1875 mb = MB(ctx->opcode) | (mbn << 5);
1876 gen_rldnm(ctx, mb, 63);
1878 GEN_PPC64_R2(rldcl, 0x1E, 0x08);
1879 /* rldcr - rldcr. */
1880 static always_inline void gen_rldcr (DisasContext *ctx, int men)
1884 me = MB(ctx->opcode) | (men << 5);
1885 gen_rldnm(ctx, 0, me);
1887 GEN_PPC64_R2(rldcr, 0x1E, 0x09);
1888 /* rldimi - rldimi. */
1889 static always_inline void gen_rldimi (DisasContext *ctx, int mbn, int shn)
1891 uint32_t sh, mb, me;
1893 sh = SH(ctx->opcode) | (shn << 5);
1894 mb = MB(ctx->opcode) | (mbn << 5);
1896 if (unlikely(sh == 0 && mb == 0)) {
1897 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1902 t0 = tcg_temp_new(TCG_TYPE_TL);
1903 tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh);
1904 t1 = tcg_temp_new(TCG_TYPE_TL);
1905 mask = MASK(mb, me);
1906 tcg_gen_andi_tl(t0, t0, mask);
1907 tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask);
1908 tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1);
1912 if (unlikely(Rc(ctx->opcode) != 0))
1913 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1915 GEN_PPC64_R4(rldimi, 0x1E, 0x06);
1918 /*** Integer shift ***/
1920 GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER)
1924 l1 = gen_new_label();
1925 l2 = gen_new_label();
1927 t0 = tcg_temp_local_new(TCG_TYPE_TL);
1928 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f);
1929 tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0x20, l1);
1930 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
1933 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t0);
1934 tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]);
1937 if (unlikely(Rc(ctx->opcode) != 0))
1938 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1941 GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER)
1943 tcg_gen_helper_1_2(helper_sraw, cpu_gpr[rA(ctx->opcode)],
1944 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
1945 if (unlikely(Rc(ctx->opcode) != 0))
1946 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1948 /* srawi & srawi. */
1949 GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER)
1951 int sh = SH(ctx->opcode);
1955 l1 = gen_new_label();
1956 l2 = gen_new_label();
1957 t0 = tcg_temp_local_new(TCG_TYPE_TL);
1958 tcg_gen_ext32s_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1959 tcg_gen_brcondi_tl(TCG_COND_GE, t0, 0, l1);
1960 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1ULL << sh) - 1);
1961 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
1962 tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA);
1965 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
1967 tcg_gen_ext32s_tl(t0, cpu_gpr[rS(ctx->opcode)]);
1968 tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], t0, sh);
1971 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
1972 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
1974 if (unlikely(Rc(ctx->opcode) != 0))
1975 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
1978 GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER)
1982 l1 = gen_new_label();
1983 l2 = gen_new_label();
1985 t0 = tcg_temp_local_new(TCG_TYPE_TL);
1986 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f);
1987 tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0x20, l1);
1988 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
1991 t1 = tcg_temp_new(TCG_TYPE_TL);
1992 tcg_gen_ext32u_tl(t1, cpu_gpr[rS(ctx->opcode)]);
1993 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t1, t0);
1997 if (unlikely(Rc(ctx->opcode) != 0))
1998 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2000 #if defined(TARGET_PPC64)
2002 GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B)
2006 l1 = gen_new_label();
2007 l2 = gen_new_label();
2009 t0 = tcg_temp_local_new(TCG_TYPE_TL);
2010 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x7f);
2011 tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0x40, l1);
2012 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
2015 tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t0);
2018 if (unlikely(Rc(ctx->opcode) != 0))
2019 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2022 GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B)
2024 tcg_gen_helper_1_2(helper_srad, cpu_gpr[rA(ctx->opcode)],
2025 cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
2026 if (unlikely(Rc(ctx->opcode) != 0))
2027 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2029 /* sradi & sradi. */
2030 static always_inline void gen_sradi (DisasContext *ctx, int n)
2032 int sh = SH(ctx->opcode) + (n << 5);
2036 l1 = gen_new_label();
2037 l2 = gen_new_label();
2038 tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1);
2039 t0 = tcg_temp_new(TCG_TYPE_TL);
2040 tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1ULL << sh) - 1);
2041 tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1);
2042 tcg_gen_ori_tl(cpu_xer, cpu_xer, 1 << XER_CA);
2045 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
2047 tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh);
2049 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]);
2050 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_CA));
2052 if (unlikely(Rc(ctx->opcode) != 0))
2053 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2055 GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B)
2059 GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B)
2064 GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B)
2068 l1 = gen_new_label();
2069 l2 = gen_new_label();
2071 t0 = tcg_temp_local_new(TCG_TYPE_TL);
2072 tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x7f);
2073 tcg_gen_brcondi_tl(TCG_COND_LT, t0, 0x40, l1);
2074 tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0);
2077 tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t0);
2080 if (unlikely(Rc(ctx->opcode) != 0))
2081 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]);
2085 /*** Floating-Point arithmetic ***/
2086 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
2087 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type) \
2089 if (unlikely(!ctx->fpu_enabled)) { \
2090 GEN_EXCP_NO_FP(ctx); \
2093 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]); \
2094 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rC(ctx->opcode)]); \
2095 tcg_gen_mov_i64(cpu_FT[2], cpu_fpr[rB(ctx->opcode)]); \
2096 gen_reset_fpstatus(); \
2101 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2102 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
2105 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2106 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2107 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
2109 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2110 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
2112 if (unlikely(!ctx->fpu_enabled)) { \
2113 GEN_EXCP_NO_FP(ctx); \
2116 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]); \
2117 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rB(ctx->opcode)]); \
2118 gen_reset_fpstatus(); \
2123 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2124 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
2126 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2127 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2128 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2130 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2131 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
2133 if (unlikely(!ctx->fpu_enabled)) { \
2134 GEN_EXCP_NO_FP(ctx); \
2137 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]); \
2138 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rC(ctx->opcode)]); \
2139 gen_reset_fpstatus(); \
2144 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2145 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
2147 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2148 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2149 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2151 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
2152 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type) \
2154 if (unlikely(!ctx->fpu_enabled)) { \
2155 GEN_EXCP_NO_FP(ctx); \
2158 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]); \
2159 gen_reset_fpstatus(); \
2161 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2162 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
2165 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
2166 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type) \
2168 if (unlikely(!ctx->fpu_enabled)) { \
2169 GEN_EXCP_NO_FP(ctx); \
2172 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]); \
2173 gen_reset_fpstatus(); \
2175 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2176 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
2180 GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT);
2182 GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT);
2184 GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT);
2187 GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT);
2190 GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES);
2193 GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE);
2196 static always_inline void gen_op_frsqrtes (void)
2201 GEN_FLOAT_BS(rsqrtes, 0x3B, 0x1A, 1, PPC_FLOAT_FRSQRTES);
2204 _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL);
2206 GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT);
2209 GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT)
2211 if (unlikely(!ctx->fpu_enabled)) {
2212 GEN_EXCP_NO_FP(ctx);
2215 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]);
2216 gen_reset_fpstatus();
2218 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
2219 gen_compute_fprf(1, Rc(ctx->opcode) != 0);
2222 GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT)
2224 if (unlikely(!ctx->fpu_enabled)) {
2225 GEN_EXCP_NO_FP(ctx);
2228 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]);
2229 gen_reset_fpstatus();
2232 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
2233 gen_compute_fprf(1, Rc(ctx->opcode) != 0);
2236 /*** Floating-Point multiply-and-add ***/
2237 /* fmadd - fmadds */
2238 GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT);
2239 /* fmsub - fmsubs */
2240 GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT);
2241 /* fnmadd - fnmadds */
2242 GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT);
2243 /* fnmsub - fnmsubs */
2244 GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT);
2246 /*** Floating-Point round & convert ***/
2248 GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT);
2250 GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT);
2252 GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT);
2253 #if defined(TARGET_PPC64)
2255 GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B);
2257 GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B);
2259 GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B);
2263 GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT);
2265 GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT);
2267 GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT);
2269 GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT);
2271 /*** Floating-Point compare ***/
2273 GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT)
2275 if (unlikely(!ctx->fpu_enabled)) {
2276 GEN_EXCP_NO_FP(ctx);
2279 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]);
2280 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rB(ctx->opcode)]);
2281 gen_reset_fpstatus();
2282 tcg_gen_helper_1_0(helper_fcmpo, cpu_crf[crfD(ctx->opcode)]);
2283 gen_op_float_check_status();
2287 GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT)
2289 if (unlikely(!ctx->fpu_enabled)) {
2290 GEN_EXCP_NO_FP(ctx);
2293 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]);
2294 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rB(ctx->opcode)]);
2295 gen_reset_fpstatus();
2296 tcg_gen_helper_1_0(helper_fcmpu, cpu_crf[crfD(ctx->opcode)]);
2297 gen_op_float_check_status();
2300 /*** Floating-point move ***/
2302 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2303 GEN_FLOAT_B(abs, 0x08, 0x08, 0, PPC_FLOAT);
2306 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2307 GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT)
2309 if (unlikely(!ctx->fpu_enabled)) {
2310 GEN_EXCP_NO_FP(ctx);
2313 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]);
2314 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
2315 gen_compute_fprf(0, Rc(ctx->opcode) != 0);
2319 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2320 GEN_FLOAT_B(nabs, 0x08, 0x04, 0, PPC_FLOAT);
2322 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2323 GEN_FLOAT_B(neg, 0x08, 0x01, 0, PPC_FLOAT);
2325 /*** Floating-Point status & ctrl register ***/
2327 GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT)
2331 if (unlikely(!ctx->fpu_enabled)) {
2332 GEN_EXCP_NO_FP(ctx);
2335 gen_optimize_fprf();
2336 bfa = 4 * (7 - crfS(ctx->opcode));
2337 tcg_gen_shri_i32(cpu_crf[crfD(ctx->opcode)], cpu_fpscr, bfa);
2338 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf);
2339 gen_op_fpscr_resetbit(~(0xF << bfa));
2343 GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT)
2345 if (unlikely(!ctx->fpu_enabled)) {
2346 GEN_EXCP_NO_FP(ctx);
2349 gen_optimize_fprf();
2350 gen_reset_fpstatus();
2351 gen_op_load_fpscr_FT0();
2352 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
2353 gen_compute_fprf(0, Rc(ctx->opcode) != 0);
2357 GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT)
2361 if (unlikely(!ctx->fpu_enabled)) {
2362 GEN_EXCP_NO_FP(ctx);
2365 crb = 32 - (crbD(ctx->opcode) >> 2);
2366 gen_optimize_fprf();
2367 gen_reset_fpstatus();
2368 if (likely(crb != 30 && crb != 29))
2369 gen_op_fpscr_resetbit(~(1 << crb));
2370 if (unlikely(Rc(ctx->opcode) != 0)) {
2371 tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX);
2376 GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT)
2380 if (unlikely(!ctx->fpu_enabled)) {
2381 GEN_EXCP_NO_FP(ctx);
2384 crb = 32 - (crbD(ctx->opcode) >> 2);
2385 gen_optimize_fprf();
2386 gen_reset_fpstatus();
2387 /* XXX: we pretend we can only do IEEE floating-point computations */
2388 if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI))
2389 gen_op_fpscr_setbit(crb);
2390 if (unlikely(Rc(ctx->opcode) != 0)) {
2391 tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX);
2393 /* We can raise a differed exception */
2394 gen_op_float_check_status();
2398 GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x02010000, PPC_FLOAT)
2400 if (unlikely(!ctx->fpu_enabled)) {
2401 GEN_EXCP_NO_FP(ctx);
2404 gen_optimize_fprf();
2405 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]);
2406 gen_reset_fpstatus();
2407 gen_op_store_fpscr(FM(ctx->opcode));
2408 if (unlikely(Rc(ctx->opcode) != 0)) {
2409 tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX);
2411 /* We can raise a differed exception */
2412 gen_op_float_check_status();
2416 GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT)
2420 if (unlikely(!ctx->fpu_enabled)) {
2421 GEN_EXCP_NO_FP(ctx);
2424 bf = crbD(ctx->opcode) >> 2;
2426 gen_optimize_fprf();
2427 tcg_gen_movi_i64(cpu_FT[0], FPIMM(ctx->opcode) << (4 * sh));
2428 gen_reset_fpstatus();
2429 gen_op_store_fpscr(1 << sh);
2430 if (unlikely(Rc(ctx->opcode) != 0)) {
2431 tcg_gen_shri_i32(cpu_crf[1], cpu_fpscr, FPSCR_OX);
2433 /* We can raise a differed exception */
2434 gen_op_float_check_status();
2437 /*** Addressing modes ***/
2438 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2439 static always_inline void gen_addr_imm_index (TCGv EA,
2443 target_long simm = SIMM(ctx->opcode);
2446 if (rA(ctx->opcode) == 0)
2447 tcg_gen_movi_tl(EA, simm);
2448 else if (likely(simm != 0))
2449 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm);
2451 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2454 static always_inline void gen_addr_reg_index (TCGv EA,
2457 if (rA(ctx->opcode) == 0)
2458 tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]);
2460 tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]);
2463 static always_inline void gen_addr_register (TCGv EA,
2466 if (rA(ctx->opcode) == 0)
2467 tcg_gen_movi_tl(EA, 0);
2469 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
2472 #if defined(TARGET_PPC64)
2473 #define _GEN_MEM_FUNCS(name, mode) \
2474 &gen_op_##name##_##mode, \
2475 &gen_op_##name##_le_##mode, \
2476 &gen_op_##name##_64_##mode, \
2477 &gen_op_##name##_le_64_##mode
2479 #define _GEN_MEM_FUNCS(name, mode) \
2480 &gen_op_##name##_##mode, \
2481 &gen_op_##name##_le_##mode
2483 #if defined(CONFIG_USER_ONLY)
2484 #if defined(TARGET_PPC64)
2485 #define NB_MEM_FUNCS 4
2487 #define NB_MEM_FUNCS 2
2489 #define GEN_MEM_FUNCS(name) \
2490 _GEN_MEM_FUNCS(name, raw)
2492 #if defined(TARGET_PPC64)
2493 #define NB_MEM_FUNCS 12
2495 #define NB_MEM_FUNCS 6
2497 #define GEN_MEM_FUNCS(name) \
2498 _GEN_MEM_FUNCS(name, user), \
2499 _GEN_MEM_FUNCS(name, kernel), \
2500 _GEN_MEM_FUNCS(name, hypv)
2503 /*** Integer load ***/
2504 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
2505 #define OP_LD_TABLE(width) \
2506 static GenOpFunc *gen_op_l##width[NB_MEM_FUNCS] = { \
2507 GEN_MEM_FUNCS(l##width), \
2509 #define OP_ST_TABLE(width) \
2510 static GenOpFunc *gen_op_st##width[NB_MEM_FUNCS] = { \
2511 GEN_MEM_FUNCS(st##width), \
2515 #if defined(TARGET_PPC64)
2516 #define GEN_QEMU_LD_PPC64(width) \
2517 static always_inline void gen_qemu_ld##width##_ppc64(TCGv t0, TCGv t1, int flags)\
2519 if (likely(flags & 2)) \
2520 tcg_gen_qemu_ld##width(t0, t1, flags >> 2); \
2522 TCGv addr = tcg_temp_new(TCG_TYPE_TL); \
2523 tcg_gen_ext32u_tl(addr, t1); \
2524 tcg_gen_qemu_ld##width(t0, addr, flags >> 2); \
2525 tcg_temp_free(addr); \
2528 GEN_QEMU_LD_PPC64(8u)
2529 GEN_QEMU_LD_PPC64(8s)
2530 GEN_QEMU_LD_PPC64(16u)
2531 GEN_QEMU_LD_PPC64(16s)
2532 GEN_QEMU_LD_PPC64(32u)
2533 GEN_QEMU_LD_PPC64(32s)
2534 GEN_QEMU_LD_PPC64(64)
2536 #define GEN_QEMU_ST_PPC64(width) \
2537 static always_inline void gen_qemu_st##width##_ppc64(TCGv t0, TCGv t1, int flags)\
2539 if (likely(flags & 2)) \
2540 tcg_gen_qemu_st##width(t0, t1, flags >> 2); \
2542 TCGv addr = tcg_temp_new(TCG_TYPE_TL); \
2543 tcg_gen_ext32u_tl(addr, t1); \
2544 tcg_gen_qemu_st##width(t0, addr, flags >> 2); \
2545 tcg_temp_free(addr); \
2548 GEN_QEMU_ST_PPC64(8)
2549 GEN_QEMU_ST_PPC64(16)
2550 GEN_QEMU_ST_PPC64(32)
2551 GEN_QEMU_ST_PPC64(64)
2553 static always_inline void gen_qemu_ld8u(TCGv arg0, TCGv arg1, int flags)
2555 gen_qemu_ld8u_ppc64(arg0, arg1, flags);
2558 static always_inline void gen_qemu_ld8s(TCGv arg0, TCGv arg1, int flags)
2560 gen_qemu_ld8s_ppc64(arg0, arg1, flags);
2563 static always_inline void gen_qemu_ld16u(TCGv arg0, TCGv arg1, int flags)
2565 if (unlikely(flags & 1)) {
2567 gen_qemu_ld16u_ppc64(arg0, arg1, flags);
2568 t0 = tcg_temp_new(TCG_TYPE_I32);
2569 tcg_gen_trunc_tl_i32(t0, arg0);
2570 tcg_gen_bswap16_i32(t0, t0);
2571 tcg_gen_extu_i32_tl(arg0, t0);
2574 gen_qemu_ld16u_ppc64(arg0, arg1, flags);
2577 static always_inline void gen_qemu_ld16s(TCGv arg0, TCGv arg1, int flags)
2579 if (unlikely(flags & 1)) {
2581 gen_qemu_ld16u_ppc64(arg0, arg1, flags);
2582 t0 = tcg_temp_new(TCG_TYPE_I32);
2583 tcg_gen_trunc_tl_i32(t0, arg0);
2584 tcg_gen_bswap16_i32(t0, t0);
2585 tcg_gen_extu_i32_tl(arg0, t0);
2586 tcg_gen_ext16s_tl(arg0, arg0);
2589 gen_qemu_ld16s_ppc64(arg0, arg1, flags);
2592 static always_inline void gen_qemu_ld32u(TCGv arg0, TCGv arg1, int flags)
2594 if (unlikely(flags & 1)) {
2596 gen_qemu_ld32u_ppc64(arg0, arg1, flags);
2597 t0 = tcg_temp_new(TCG_TYPE_I32);
2598 tcg_gen_trunc_tl_i32(t0, arg0);
2599 tcg_gen_bswap_i32(t0, t0);
2600 tcg_gen_extu_i32_tl(arg0, t0);
2603 gen_qemu_ld32u_ppc64(arg0, arg1, flags);
2606 static always_inline void gen_qemu_ld32s(TCGv arg0, TCGv arg1, int flags)
2608 if (unlikely(flags & 1)) {
2610 gen_qemu_ld32u_ppc64(arg0, arg1, flags);
2611 t0 = tcg_temp_new(TCG_TYPE_I32);
2612 tcg_gen_trunc_tl_i32(t0, arg0);
2613 tcg_gen_bswap_i32(t0, t0);
2614 tcg_gen_ext_i32_tl(arg0, t0);
2617 gen_qemu_ld32s_ppc64(arg0, arg1, flags);
2620 static always_inline void gen_qemu_ld64(TCGv arg0, TCGv arg1, int flags)
2622 gen_qemu_ld64_ppc64(arg0, arg1, flags);
2623 if (unlikely(flags & 1))
2624 tcg_gen_bswap_i64(arg0, arg0);
2627 static always_inline void gen_qemu_st8(TCGv arg0, TCGv arg1, int flags)
2629 gen_qemu_st8_ppc64(arg0, arg1, flags);
2632 static always_inline void gen_qemu_st16(TCGv arg0, TCGv arg1, int flags)
2634 if (unlikely(flags & 1)) {
2636 t0 = tcg_temp_new(TCG_TYPE_I32);
2637 tcg_gen_trunc_tl_i32(t0, arg0);
2638 tcg_gen_ext16u_i32(t0, t0);
2639 tcg_gen_bswap16_i32(t0, t0);
2640 t1 = tcg_temp_new(TCG_TYPE_I64);
2641 tcg_gen_extu_i32_tl(t1, t0);
2643 gen_qemu_st16_ppc64(t1, arg1, flags);
2646 gen_qemu_st16_ppc64(arg0, arg1, flags);
2649 static always_inline void gen_qemu_st32(TCGv arg0, TCGv arg1, int flags)
2651 if (unlikely(flags & 1)) {
2653 t0 = tcg_temp_new(TCG_TYPE_I32);
2654 tcg_gen_trunc_tl_i32(t0, arg0);
2655 tcg_gen_bswap_i32(t0, t0);
2656 t1 = tcg_temp_new(TCG_TYPE_I64);
2657 tcg_gen_extu_i32_tl(t1, t0);
2659 gen_qemu_st32_ppc64(t1, arg1, flags);
2662 gen_qemu_st32_ppc64(arg0, arg1, flags);
2665 static always_inline void gen_qemu_st64(TCGv arg0, TCGv arg1, int flags)
2667 if (unlikely(flags & 1)) {
2668 TCGv t0 = tcg_temp_new(TCG_TYPE_I64);
2669 tcg_gen_bswap_i64(t0, arg0);
2670 gen_qemu_st64_ppc64(t0, arg1, flags);
2673 gen_qemu_st64_ppc64(arg0, arg1, flags);
2677 #else /* defined(TARGET_PPC64) */
2678 #define GEN_QEMU_LD_PPC32(width) \
2679 static always_inline void gen_qemu_ld##width##_ppc32(TCGv arg0, TCGv arg1, int flags)\
2681 tcg_gen_qemu_ld##width(arg0, arg1, flags >> 1); \
2683 GEN_QEMU_LD_PPC32(8u)
2684 GEN_QEMU_LD_PPC32(8s)
2685 GEN_QEMU_LD_PPC32(16u)
2686 GEN_QEMU_LD_PPC32(16s)
2687 GEN_QEMU_LD_PPC32(32u)
2688 GEN_QEMU_LD_PPC32(32s)
2689 GEN_QEMU_LD_PPC32(64)
2691 #define GEN_QEMU_ST_PPC32(width) \
2692 static always_inline void gen_qemu_st##width##_ppc32(TCGv arg0, TCGv arg1, int flags)\
2694 tcg_gen_qemu_st##width(arg0, arg1, flags >> 1); \
2696 GEN_QEMU_ST_PPC32(8)
2697 GEN_QEMU_ST_PPC32(16)
2698 GEN_QEMU_ST_PPC32(32)
2699 GEN_QEMU_ST_PPC32(64)
2701 static always_inline void gen_qemu_ld8u(TCGv arg0, TCGv arg1, int flags)
2703 gen_qemu_ld8u_ppc32(arg0, arg1, flags >> 1);
2706 static always_inline void gen_qemu_ld8s(TCGv arg0, TCGv arg1, int flags)
2708 gen_qemu_ld8s_ppc32(arg0, arg1, flags >> 1);
2711 static always_inline void gen_qemu_ld16u(TCGv arg0, TCGv arg1, int flags)
2713 gen_qemu_ld16u_ppc32(arg0, arg1, flags >> 1);
2714 if (unlikely(flags & 1))
2715 tcg_gen_bswap16_i32(arg0, arg0);
2718 static always_inline void gen_qemu_ld16s(TCGv arg0, TCGv arg1, int flags)
2720 if (unlikely(flags & 1)) {
2721 gen_qemu_ld16u_ppc32(arg0, arg1, flags);
2722 tcg_gen_bswap16_i32(arg0, arg0);
2723 tcg_gen_ext16s_i32(arg0, arg0);
2725 gen_qemu_ld16s_ppc32(arg0, arg1, flags);
2728 static always_inline void gen_qemu_ld32u(TCGv arg0, TCGv arg1, int flags)
2730 gen_qemu_ld32u_ppc32(arg0, arg1, flags);
2731 if (unlikely(flags & 1))
2732 tcg_gen_bswap_i32(arg0, arg0);
2735 static always_inline void gen_qemu_ld64(TCGv arg0, TCGv arg1, int flags)
2737 gen_qemu_ld64_ppc32(arg0, arg1, flags);
2738 if (unlikely(flags & 1))
2739 tcg_gen_bswap_i64(arg0, arg0);
2742 static always_inline void gen_qemu_st8(TCGv arg0, TCGv arg1, int flags)
2744 gen_qemu_st8_ppc32(arg0, arg1, flags);
2747 static always_inline void gen_qemu_st16(TCGv arg0, TCGv arg1, int flags)
2749 if (unlikely(flags & 1)) {
2750 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
2751 tcg_gen_ext16u_i32(temp, arg0);
2752 tcg_gen_bswap16_i32(temp, temp);
2753 gen_qemu_st16_ppc32(temp, arg1, flags);
2754 tcg_temp_free(temp);
2756 gen_qemu_st16_ppc32(arg0, arg1, flags);
2759 static always_inline void gen_qemu_st32(TCGv arg0, TCGv arg1, int flags)
2761 if (unlikely(flags & 1)) {
2762 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
2763 tcg_gen_bswap_i32(temp, arg0);
2764 gen_qemu_st32_ppc32(temp, arg1, flags);
2765 tcg_temp_free(temp);
2767 gen_qemu_st32_ppc32(arg0, arg1, flags);
2770 static always_inline void gen_qemu_st64(TCGv arg0, TCGv arg1, int flags)
2772 if (unlikely(flags & 1)) {
2773 TCGv temp = tcg_temp_new(TCG_TYPE_I64);
2774 tcg_gen_bswap_i64(temp, arg0);
2775 gen_qemu_st64_ppc32(temp, arg1, flags);
2776 tcg_temp_free(temp);
2778 gen_qemu_st64_ppc32(arg0, arg1, flags);
2783 #define GEN_LD(width, opc, type) \
2784 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2786 TCGv EA = tcg_temp_new(TCG_TYPE_TL); \
2787 gen_addr_imm_index(EA, ctx, 0); \
2788 gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2789 tcg_temp_free(EA); \
2792 #define GEN_LDU(width, opc, type) \
2793 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2796 if (unlikely(rA(ctx->opcode) == 0 || \
2797 rA(ctx->opcode) == rD(ctx->opcode))) { \
2798 GEN_EXCP_INVAL(ctx); \
2801 EA = tcg_temp_new(TCG_TYPE_TL); \
2802 if (type == PPC_64B) \
2803 gen_addr_imm_index(EA, ctx, 0x03); \
2805 gen_addr_imm_index(EA, ctx, 0); \
2806 gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2807 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2808 tcg_temp_free(EA); \
2811 #define GEN_LDUX(width, opc2, opc3, type) \
2812 GEN_HANDLER(l##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2815 if (unlikely(rA(ctx->opcode) == 0 || \
2816 rA(ctx->opcode) == rD(ctx->opcode))) { \
2817 GEN_EXCP_INVAL(ctx); \
2820 EA = tcg_temp_new(TCG_TYPE_TL); \
2821 gen_addr_reg_index(EA, ctx); \
2822 gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2823 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2824 tcg_temp_free(EA); \
2827 #define GEN_LDX(width, opc2, opc3, type) \
2828 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2830 TCGv EA = tcg_temp_new(TCG_TYPE_TL); \
2831 gen_addr_reg_index(EA, ctx); \
2832 gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2833 tcg_temp_free(EA); \
2836 #define GEN_LDS(width, op, type) \
2837 GEN_LD(width, op | 0x20, type); \
2838 GEN_LDU(width, op | 0x21, type); \
2839 GEN_LDUX(width, 0x17, op | 0x01, type); \
2840 GEN_LDX(width, 0x17, op | 0x00, type)
2842 /* lbz lbzu lbzux lbzx */
2843 GEN_LDS(8u, 0x02, PPC_INTEGER);
2844 /* lha lhau lhaux lhax */
2845 GEN_LDS(16s, 0x0A, PPC_INTEGER);
2846 /* lhz lhzu lhzux lhzx */
2847 GEN_LDS(16u, 0x08, PPC_INTEGER);
2848 /* lwz lwzu lwzux lwzx */
2849 GEN_LDS(32u, 0x00, PPC_INTEGER);
2850 #if defined(TARGET_PPC64)
2852 GEN_LDUX(32s, 0x15, 0x0B, PPC_64B);
2854 GEN_LDX(32s, 0x15, 0x0A, PPC_64B);
2856 GEN_LDUX(64, 0x15, 0x01, PPC_64B);
2858 GEN_LDX(64, 0x15, 0x00, PPC_64B);
2859 GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B)
2862 if (Rc(ctx->opcode)) {
2863 if (unlikely(rA(ctx->opcode) == 0 ||
2864 rA(ctx->opcode) == rD(ctx->opcode))) {
2865 GEN_EXCP_INVAL(ctx);
2869 EA = tcg_temp_new(TCG_TYPE_TL);
2870 gen_addr_imm_index(EA, ctx, 0x03);
2871 if (ctx->opcode & 0x02) {
2872 /* lwa (lwau is undefined) */
2873 gen_qemu_ld32s(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx);
2876 gen_qemu_ld64(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx);
2878 if (Rc(ctx->opcode))
2879 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
2883 GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX)
2885 #if defined(CONFIG_USER_ONLY)
2886 GEN_EXCP_PRIVOPC(ctx);
2891 /* Restore CPU state */
2892 if (unlikely(ctx->supervisor == 0)) {
2893 GEN_EXCP_PRIVOPC(ctx);
2896 ra = rA(ctx->opcode);
2897 rd = rD(ctx->opcode);
2898 if (unlikely((rd & 1) || rd == ra)) {
2899 GEN_EXCP_INVAL(ctx);
2902 if (unlikely(ctx->mem_idx & 1)) {
2903 /* Little-endian mode is not handled */
2904 GEN_EXCP(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
2907 EA = tcg_temp_new(TCG_TYPE_TL);
2908 gen_addr_imm_index(EA, ctx, 0x0F);
2909 gen_qemu_ld64(cpu_gpr[rd], EA, ctx->mem_idx);
2910 tcg_gen_addi_tl(EA, EA, 8);
2911 gen_qemu_ld64(cpu_gpr[rd+1], EA, ctx->mem_idx);
2917 /*** Integer store ***/
2918 #define GEN_ST(width, opc, type) \
2919 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2921 TCGv EA = tcg_temp_new(TCG_TYPE_TL); \
2922 gen_addr_imm_index(EA, ctx, 0); \
2923 gen_qemu_st##width(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
2924 tcg_temp_free(EA); \
2927 #define GEN_STU(width, opc, type) \
2928 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2931 if (unlikely(rA(ctx->opcode) == 0)) { \
2932 GEN_EXCP_INVAL(ctx); \
2935 EA = tcg_temp_new(TCG_TYPE_TL); \
2936 if (type == PPC_64B) \
2937 gen_addr_imm_index(EA, ctx, 0x03); \
2939 gen_addr_imm_index(EA, ctx, 0); \
2940 gen_qemu_st##width(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
2941 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2942 tcg_temp_free(EA); \
2945 #define GEN_STUX(width, opc2, opc3, type) \
2946 GEN_HANDLER(st##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2949 if (unlikely(rA(ctx->opcode) == 0)) { \
2950 GEN_EXCP_INVAL(ctx); \
2953 EA = tcg_temp_new(TCG_TYPE_TL); \
2954 gen_addr_reg_index(EA, ctx); \
2955 gen_qemu_st##width(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
2956 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2957 tcg_temp_free(EA); \
2960 #define GEN_STX(width, opc2, opc3, type) \
2961 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2963 TCGv EA = tcg_temp_new(TCG_TYPE_TL); \
2964 gen_addr_reg_index(EA, ctx); \
2965 gen_qemu_st##width(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
2966 tcg_temp_free(EA); \
2969 #define GEN_STS(width, op, type) \
2970 GEN_ST(width, op | 0x20, type); \
2971 GEN_STU(width, op | 0x21, type); \
2972 GEN_STUX(width, 0x17, op | 0x01, type); \
2973 GEN_STX(width, 0x17, op | 0x00, type)
2975 /* stb stbu stbux stbx */
2976 GEN_STS(8, 0x06, PPC_INTEGER);
2977 /* sth sthu sthux sthx */
2978 GEN_STS(16, 0x0C, PPC_INTEGER);
2979 /* stw stwu stwux stwx */
2980 GEN_STS(32, 0x04, PPC_INTEGER);
2981 #if defined(TARGET_PPC64)
2982 GEN_STUX(64, 0x15, 0x05, PPC_64B);
2983 GEN_STX(64, 0x15, 0x04, PPC_64B);
2984 GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B)
2989 rs = rS(ctx->opcode);
2990 if ((ctx->opcode & 0x3) == 0x2) {
2991 #if defined(CONFIG_USER_ONLY)
2992 GEN_EXCP_PRIVOPC(ctx);
2995 if (unlikely(ctx->supervisor == 0)) {
2996 GEN_EXCP_PRIVOPC(ctx);
2999 if (unlikely(rs & 1)) {
3000 GEN_EXCP_INVAL(ctx);
3003 if (unlikely(ctx->mem_idx & 1)) {
3004 /* Little-endian mode is not handled */
3005 GEN_EXCP(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE);
3008 EA = tcg_temp_new(TCG_TYPE_TL);
3009 gen_addr_imm_index(EA, ctx, 0x03);
3010 gen_qemu_st64(cpu_gpr[rs], EA, ctx->mem_idx);
3011 tcg_gen_addi_tl(EA, EA, 8);
3012 gen_qemu_st64(cpu_gpr[rs+1], EA, ctx->mem_idx);
3017 if (Rc(ctx->opcode)) {
3018 if (unlikely(rA(ctx->opcode) == 0)) {
3019 GEN_EXCP_INVAL(ctx);
3023 EA = tcg_temp_new(TCG_TYPE_TL);
3024 gen_addr_imm_index(EA, ctx, 0x03);
3025 gen_qemu_st64(cpu_gpr[rs], EA, ctx->mem_idx);
3026 if (Rc(ctx->opcode))
3027 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA);
3032 /*** Integer load and store with byte reverse ***/
3034 void always_inline gen_qemu_ld16ur(TCGv t0, TCGv t1, int flags)
3036 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
3037 gen_qemu_ld16u(temp, t1, flags);
3038 tcg_gen_bswap16_i32(temp, temp);
3039 tcg_gen_extu_i32_tl(t0, temp);
3040 tcg_temp_free(temp);
3042 GEN_LDX(16ur, 0x16, 0x18, PPC_INTEGER);
3045 void always_inline gen_qemu_ld32ur(TCGv t0, TCGv t1, int flags)
3047 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
3048 gen_qemu_ld32u(temp, t1, flags);
3049 tcg_gen_bswap_i32(temp, temp);
3050 tcg_gen_extu_i32_tl(t0, temp);
3051 tcg_temp_free(temp);
3053 GEN_LDX(32ur, 0x16, 0x10, PPC_INTEGER);
3056 void always_inline gen_qemu_st16r(TCGv t0, TCGv t1, int flags)
3058 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
3059 tcg_gen_trunc_tl_i32(temp, t0);
3060 tcg_gen_ext16u_i32(temp, temp);
3061 tcg_gen_bswap16_i32(temp, temp);
3062 gen_qemu_st16(temp, t1, flags);
3063 tcg_temp_free(temp);
3065 GEN_STX(16r, 0x16, 0x1C, PPC_INTEGER);
3068 void always_inline gen_qemu_st32r(TCGv t0, TCGv t1, int flags)
3070 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
3071 tcg_gen_trunc_tl_i32(temp, t0);
3072 tcg_gen_bswap_i32(temp, temp);
3073 gen_qemu_st32(temp, t1, flags);
3074 tcg_temp_free(temp);
3076 GEN_STX(32r, 0x16, 0x14, PPC_INTEGER);
3078 /*** Integer load and store multiple ***/
3079 #define op_ldstm(name, reg) (*gen_op_##name[ctx->mem_idx])(reg)
3080 static GenOpFunc1 *gen_op_lmw[NB_MEM_FUNCS] = {
3083 static GenOpFunc1 *gen_op_stmw[NB_MEM_FUNCS] = {
3084 GEN_MEM_FUNCS(stmw),
3088 GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
3090 /* NIP cannot be restored if the memory exception comes from an helper */
3091 gen_update_nip(ctx, ctx->nip - 4);
3092 gen_addr_imm_index(cpu_T[0], ctx, 0);
3093 op_ldstm(lmw, rD(ctx->opcode));
3097 GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
3099 /* NIP cannot be restored if the memory exception comes from an helper */
3100 gen_update_nip(ctx, ctx->nip - 4);
3101 gen_addr_imm_index(cpu_T[0], ctx, 0);
3102 op_ldstm(stmw, rS(ctx->opcode));
3105 /*** Integer load and store strings ***/
3106 #define op_ldsts(name, start) (*gen_op_##name[ctx->mem_idx])(start)
3107 #define op_ldstsx(name, rd, ra, rb) (*gen_op_##name[ctx->mem_idx])(rd, ra, rb)
3108 /* string load & stores are by definition endian-safe */
3109 #define gen_op_lswi_le_raw gen_op_lswi_raw
3110 #define gen_op_lswi_le_user gen_op_lswi_user
3111 #define gen_op_lswi_le_kernel gen_op_lswi_kernel
3112 #define gen_op_lswi_le_hypv gen_op_lswi_hypv
3113 #define gen_op_lswi_le_64_raw gen_op_lswi_raw
3114 #define gen_op_lswi_le_64_user gen_op_lswi_user
3115 #define gen_op_lswi_le_64_kernel gen_op_lswi_kernel
3116 #define gen_op_lswi_le_64_hypv gen_op_lswi_hypv
3117 static GenOpFunc1 *gen_op_lswi[NB_MEM_FUNCS] = {
3118 GEN_MEM_FUNCS(lswi),
3120 #define gen_op_lswx_le_raw gen_op_lswx_raw
3121 #define gen_op_lswx_le_user gen_op_lswx_user
3122 #define gen_op_lswx_le_kernel gen_op_lswx_kernel
3123 #define gen_op_lswx_le_hypv gen_op_lswx_hypv
3124 #define gen_op_lswx_le_64_raw gen_op_lswx_raw
3125 #define gen_op_lswx_le_64_user gen_op_lswx_user
3126 #define gen_op_lswx_le_64_kernel gen_op_lswx_kernel
3127 #define gen_op_lswx_le_64_hypv gen_op_lswx_hypv
3128 static GenOpFunc3 *gen_op_lswx[NB_MEM_FUNCS] = {
3129 GEN_MEM_FUNCS(lswx),
3131 #define gen_op_stsw_le_raw gen_op_stsw_raw
3132 #define gen_op_stsw_le_user gen_op_stsw_user
3133 #define gen_op_stsw_le_kernel gen_op_stsw_kernel
3134 #define gen_op_stsw_le_hypv gen_op_stsw_hypv
3135 #define gen_op_stsw_le_64_raw gen_op_stsw_raw
3136 #define gen_op_stsw_le_64_user gen_op_stsw_user
3137 #define gen_op_stsw_le_64_kernel gen_op_stsw_kernel
3138 #define gen_op_stsw_le_64_hypv gen_op_stsw_hypv
3139 static GenOpFunc1 *gen_op_stsw[NB_MEM_FUNCS] = {
3140 GEN_MEM_FUNCS(stsw),
3144 /* PowerPC32 specification says we must generate an exception if
3145 * rA is in the range of registers to be loaded.
3146 * In an other hand, IBM says this is valid, but rA won't be loaded.
3147 * For now, I'll follow the spec...
3149 GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING)
3151 int nb = NB(ctx->opcode);
3152 int start = rD(ctx->opcode);
3153 int ra = rA(ctx->opcode);
3159 if (unlikely(((start + nr) > 32 &&
3160 start <= ra && (start + nr - 32) > ra) ||
3161 ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) {
3162 GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM,
3163 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_LSWX);
3166 /* NIP cannot be restored if the memory exception comes from an helper */
3167 gen_update_nip(ctx, ctx->nip - 4);
3168 gen_addr_register(cpu_T[0], ctx);
3169 tcg_gen_movi_tl(cpu_T[1], nb);
3170 op_ldsts(lswi, start);
3174 GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING)
3176 int ra = rA(ctx->opcode);
3177 int rb = rB(ctx->opcode);
3179 /* NIP cannot be restored if the memory exception comes from an helper */
3180 gen_update_nip(ctx, ctx->nip - 4);
3181 gen_addr_reg_index(cpu_T[0], ctx);
3185 tcg_gen_andi_tl(cpu_T[1], cpu_xer, 0x7F);
3186 op_ldstsx(lswx, rD(ctx->opcode), ra, rb);
3190 GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING)
3192 int nb = NB(ctx->opcode);
3194 /* NIP cannot be restored if the memory exception comes from an helper */
3195 gen_update_nip(ctx, ctx->nip - 4);
3196 gen_addr_register(cpu_T[0], ctx);
3199 tcg_gen_movi_tl(cpu_T[1], nb);
3200 op_ldsts(stsw, rS(ctx->opcode));
3204 GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING)
3206 /* NIP cannot be restored if the memory exception comes from an helper */
3207 gen_update_nip(ctx, ctx->nip - 4);
3208 gen_addr_reg_index(cpu_T[0], ctx);
3209 tcg_gen_andi_tl(cpu_T[1], cpu_xer, 0x7F);
3210 op_ldsts(stsw, rS(ctx->opcode));
3213 /*** Memory synchronisation ***/
3215 GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO)
3220 GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM)
3225 #define op_lwarx() (*gen_op_lwarx[ctx->mem_idx])()
3226 #define op_stwcx() (*gen_op_stwcx[ctx->mem_idx])()
3227 static GenOpFunc *gen_op_lwarx[NB_MEM_FUNCS] = {
3228 GEN_MEM_FUNCS(lwarx),
3230 static GenOpFunc *gen_op_stwcx[NB_MEM_FUNCS] = {
3231 GEN_MEM_FUNCS(stwcx),
3235 GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000001, PPC_RES)
3237 /* NIP cannot be restored if the memory exception comes from an helper */
3238 gen_update_nip(ctx, ctx->nip - 4);
3239 gen_addr_reg_index(cpu_T[0], ctx);
3241 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[1]);
3245 GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES)
3247 /* NIP cannot be restored if the memory exception comes from an helper */
3248 gen_update_nip(ctx, ctx->nip - 4);
3249 gen_addr_reg_index(cpu_T[0], ctx);
3250 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
3254 #if defined(TARGET_PPC64)
3255 #define op_ldarx() (*gen_op_ldarx[ctx->mem_idx])()
3256 #define op_stdcx() (*gen_op_stdcx[ctx->mem_idx])()
3257 static GenOpFunc *gen_op_ldarx[NB_MEM_FUNCS] = {
3258 GEN_MEM_FUNCS(ldarx),
3260 static GenOpFunc *gen_op_stdcx[NB_MEM_FUNCS] = {
3261 GEN_MEM_FUNCS(stdcx),
3265 GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000001, PPC_64B)
3267 /* NIP cannot be restored if the memory exception comes from an helper */
3268 gen_update_nip(ctx, ctx->nip - 4);
3269 gen_addr_reg_index(cpu_T[0], ctx);
3271 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[1]);
3275 GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B)
3277 /* NIP cannot be restored if the memory exception comes from an helper */
3278 gen_update_nip(ctx, ctx->nip - 4);
3279 gen_addr_reg_index(cpu_T[0], ctx);
3280 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
3283 #endif /* defined(TARGET_PPC64) */
3286 GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC)
3291 GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT)
3293 /* Stop translation, as the CPU is supposed to sleep from now */
3295 GEN_EXCP(ctx, EXCP_HLT, 1);
3298 /*** Floating-point load ***/
3299 #define GEN_LDF(width, opc, type) \
3300 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
3302 if (unlikely(!ctx->fpu_enabled)) { \
3303 GEN_EXCP_NO_FP(ctx); \
3306 gen_addr_imm_index(cpu_T[0], ctx, 0); \
3307 op_ldst(l##width); \
3308 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
3311 #define GEN_LDUF(width, opc, type) \
3312 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
3314 if (unlikely(!ctx->fpu_enabled)) { \
3315 GEN_EXCP_NO_FP(ctx); \
3318 if (unlikely(rA(ctx->opcode) == 0)) { \
3319 GEN_EXCP_INVAL(ctx); \
3322 gen_addr_imm_index(cpu_T[0], ctx, 0); \
3323 op_ldst(l##width); \
3324 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
3325 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
3328 #define GEN_LDUXF(width, opc, type) \
3329 GEN_HANDLER(l##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \
3331 if (unlikely(!ctx->fpu_enabled)) { \
3332 GEN_EXCP_NO_FP(ctx); \
3335 if (unlikely(rA(ctx->opcode) == 0)) { \
3336 GEN_EXCP_INVAL(ctx); \
3339 gen_addr_reg_index(cpu_T[0], ctx); \
3340 op_ldst(l##width); \
3341 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
3342 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
3345 #define GEN_LDXF(width, opc2, opc3, type) \
3346 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
3348 if (unlikely(!ctx->fpu_enabled)) { \
3349 GEN_EXCP_NO_FP(ctx); \
3352 gen_addr_reg_index(cpu_T[0], ctx); \
3353 op_ldst(l##width); \
3354 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
3357 #define GEN_LDFS(width, op, type) \
3358 OP_LD_TABLE(width); \
3359 GEN_LDF(width, op | 0x20, type); \
3360 GEN_LDUF(width, op | 0x21, type); \
3361 GEN_LDUXF(width, op | 0x01, type); \
3362 GEN_LDXF(width, 0x17, op | 0x00, type)
3364 /* lfd lfdu lfdux lfdx */
3365 GEN_LDFS(fd, 0x12, PPC_FLOAT);
3366 /* lfs lfsu lfsux lfsx */
3367 GEN_LDFS(fs, 0x10, PPC_FLOAT);
3369 /*** Floating-point store ***/
3370 #define GEN_STF(width, opc, type) \
3371 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \
3373 if (unlikely(!ctx->fpu_enabled)) { \
3374 GEN_EXCP_NO_FP(ctx); \
3377 gen_addr_imm_index(cpu_T[0], ctx, 0); \
3378 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
3379 op_ldst(st##width); \
3382 #define GEN_STUF(width, opc, type) \
3383 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
3385 if (unlikely(!ctx->fpu_enabled)) { \
3386 GEN_EXCP_NO_FP(ctx); \
3389 if (unlikely(rA(ctx->opcode) == 0)) { \
3390 GEN_EXCP_INVAL(ctx); \
3393 gen_addr_imm_index(cpu_T[0], ctx, 0); \
3394 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
3395 op_ldst(st##width); \
3396 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
3399 #define GEN_STUXF(width, opc, type) \
3400 GEN_HANDLER(st##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \
3402 if (unlikely(!ctx->fpu_enabled)) { \
3403 GEN_EXCP_NO_FP(ctx); \
3406 if (unlikely(rA(ctx->opcode) == 0)) { \
3407 GEN_EXCP_INVAL(ctx); \
3410 gen_addr_reg_index(cpu_T[0], ctx); \
3411 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
3412 op_ldst(st##width); \
3413 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
3416 #define GEN_STXF(width, opc2, opc3, type) \
3417 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
3419 if (unlikely(!ctx->fpu_enabled)) { \
3420 GEN_EXCP_NO_FP(ctx); \
3423 gen_addr_reg_index(cpu_T[0], ctx); \
3424 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
3425 op_ldst(st##width); \
3428 #define GEN_STFS(width, op, type) \
3429 OP_ST_TABLE(width); \
3430 GEN_STF(width, op | 0x20, type); \
3431 GEN_STUF(width, op | 0x21, type); \
3432 GEN_STUXF(width, op | 0x01, type); \
3433 GEN_STXF(width, 0x17, op | 0x00, type)
3435 /* stfd stfdu stfdux stfdx */
3436 GEN_STFS(fd, 0x16, PPC_FLOAT);
3437 /* stfs stfsu stfsux stfsx */
3438 GEN_STFS(fs, 0x14, PPC_FLOAT);
3443 GEN_STXF(fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX);
3446 static always_inline void gen_goto_tb (DisasContext *ctx, int n,
3449 TranslationBlock *tb;
3451 #if defined(TARGET_PPC64)
3453 dest = (uint32_t) dest;
3455 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) &&
3456 likely(!ctx->singlestep_enabled)) {
3458 tcg_gen_movi_tl(cpu_nip, dest & ~3);
3459 tcg_gen_exit_tb((long)tb + n);
3461 tcg_gen_movi_tl(cpu_nip, dest & ~3);
3462 if (unlikely(ctx->singlestep_enabled)) {
3463 if ((ctx->singlestep_enabled &
3464 (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) &&
3465 ctx->exception == POWERPC_EXCP_BRANCH) {
3466 target_ulong tmp = ctx->nip;
3468 GEN_EXCP(ctx, POWERPC_EXCP_TRACE, 0);
3471 if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) {
3472 gen_update_nip(ctx, dest);
3480 static always_inline void gen_setlr (DisasContext *ctx, target_ulong nip)
3482 #if defined(TARGET_PPC64)
3483 if (ctx->sf_mode == 0)
3484 tcg_gen_movi_tl(cpu_lr, (uint32_t)nip);
3487 tcg_gen_movi_tl(cpu_lr, nip);
3491 GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
3493 target_ulong li, target;
3495 ctx->exception = POWERPC_EXCP_BRANCH;
3496 /* sign extend LI */
3497 #if defined(TARGET_PPC64)
3499 li = ((int64_t)LI(ctx->opcode) << 38) >> 38;
3502 li = ((int32_t)LI(ctx->opcode) << 6) >> 6;
3503 if (likely(AA(ctx->opcode) == 0))
3504 target = ctx->nip + li - 4;
3507 if (LK(ctx->opcode))
3508 gen_setlr(ctx, ctx->nip);
3509 gen_goto_tb(ctx, 0, target);
3516 static always_inline void gen_bcond (DisasContext *ctx, int type)
3518 uint32_t bo = BO(ctx->opcode);
3519 int l1 = gen_new_label();
3522 ctx->exception = POWERPC_EXCP_BRANCH;
3523 if (type == BCOND_LR || type == BCOND_CTR) {
3524 target = tcg_temp_local_new(TCG_TYPE_TL);
3525 if (type == BCOND_CTR)
3526 tcg_gen_mov_tl(target, cpu_ctr);
3528 tcg_gen_mov_tl(target, cpu_lr);
3530 if (LK(ctx->opcode))
3531 gen_setlr(ctx, ctx->nip);
3532 l1 = gen_new_label();
3533 if ((bo & 0x4) == 0) {
3534 /* Decrement and test CTR */
3535 TCGv temp = tcg_temp_new(TCG_TYPE_TL);
3536 if (unlikely(type == BCOND_CTR)) {
3537 GEN_EXCP_INVAL(ctx);
3540 tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1);
3541 #if defined(TARGET_PPC64)
3543 tcg_gen_ext32u_tl(temp, cpu_ctr);
3546 tcg_gen_mov_tl(temp, cpu_ctr);
3548 tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1);
3550 tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1);
3553 if ((bo & 0x10) == 0) {
3555 uint32_t bi = BI(ctx->opcode);
3556 uint32_t mask = 1 << (3 - (bi & 0x03));
3557 TCGv temp = tcg_temp_new(TCG_TYPE_I32);
3560 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3561 tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1);
3563 tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask);
3564 tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1);
3567 if (type == BCOND_IM) {
3568 target_ulong li = (target_long)((int16_t)(BD(ctx->opcode)));
3569 if (likely(AA(ctx->opcode) == 0)) {
3570 gen_goto_tb(ctx, 0, ctx->nip + li - 4);
3572 gen_goto_tb(ctx, 0, li);
3575 gen_goto_tb(ctx, 1, ctx->nip);
3577 #if defined(TARGET_PPC64)
3578 if (!(ctx->sf_mode))
3579 tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3);
3582 tcg_gen_andi_tl(cpu_nip, target, ~3);
3585 #if defined(TARGET_PPC64)
3586 if (!(ctx->sf_mode))
3587 tcg_gen_movi_tl(cpu_nip, (uint32_t)ctx->nip);
3590 tcg_gen_movi_tl(cpu_nip, ctx->nip);
3595 GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
3597 gen_bcond(ctx, BCOND_IM);
3600 GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW)
3602 gen_bcond(ctx, BCOND_CTR);
3605 GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW)
3607 gen_bcond(ctx, BCOND_LR);
3610 /*** Condition register logical ***/
3611 #define GEN_CRLOGIC(name, tcg_op, opc) \
3612 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) \
3617 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3618 t0 = tcg_temp_new(TCG_TYPE_I32); \
3620 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
3622 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
3624 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
3625 t1 = tcg_temp_new(TCG_TYPE_I32); \
3626 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3628 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
3630 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
3632 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3633 tcg_op(t0, t0, t1); \
3634 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
3635 tcg_gen_andi_i32(t0, t0, bitmask); \
3636 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3637 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
3638 tcg_temp_free(t0); \
3639 tcg_temp_free(t1); \
3643 GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08);
3645 GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04);
3647 GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09);
3649 GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07);
3651 GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01);
3653 GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E);
3655 GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D);
3657 GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06);
3659 GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER)
3661 tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]);
3664 /*** System linkage ***/
3665 /* rfi (supervisor only) */
3666 GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW)
3668 #if defined(CONFIG_USER_ONLY)
3669 GEN_EXCP_PRIVOPC(ctx);
3671 /* Restore CPU state */
3672 if (unlikely(!ctx->supervisor)) {
3673 GEN_EXCP_PRIVOPC(ctx);
3681 #if defined(TARGET_PPC64)
3682 GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B)
3684 #if defined(CONFIG_USER_ONLY)
3685 GEN_EXCP_PRIVOPC(ctx);
3687 /* Restore CPU state */
3688 if (unlikely(!ctx->supervisor)) {
3689 GEN_EXCP_PRIVOPC(ctx);
3697 GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H)
3699 #if defined(CONFIG_USER_ONLY)
3700 GEN_EXCP_PRIVOPC(ctx);
3702 /* Restore CPU state */
3703 if (unlikely(ctx->supervisor <= 1)) {
3704 GEN_EXCP_PRIVOPC(ctx);
3714 #if defined(CONFIG_USER_ONLY)
3715 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3717 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3719 GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW)
3723 lev = (ctx->opcode >> 5) & 0x7F;
3724 GEN_EXCP(ctx, POWERPC_SYSCALL, lev);
3729 GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW)
3731 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
3732 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
3733 /* Update the nip since this might generate a trap exception */
3734 gen_update_nip(ctx, ctx->nip);
3735 gen_op_tw(TO(ctx->opcode));
3739 GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
3741 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
3742 tcg_gen_movi_tl(cpu_T[1], SIMM(ctx->opcode));
3743 /* Update the nip since this might generate a trap exception */
3744 gen_update_nip(ctx, ctx->nip);
3745 gen_op_tw(TO(ctx->opcode));
3748 #if defined(TARGET_PPC64)
3750 GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B)
3752 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
3753 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
3754 /* Update the nip since this might generate a trap exception */
3755 gen_update_nip(ctx, ctx->nip);
3756 gen_op_td(TO(ctx->opcode));
3760 GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B)
3762 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
3763 tcg_gen_movi_tl(cpu_T[1], SIMM(ctx->opcode));
3764 /* Update the nip since this might generate a trap exception */
3765 gen_update_nip(ctx, ctx->nip);
3766 gen_op_td(TO(ctx->opcode));
3770 /*** Processor control ***/
3772 GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC)
3774 tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], cpu_xer);
3775 tcg_gen_shri_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], XER_CA);
3776 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_SO | 1 << XER_OV | 1 << XER_CA));
3780 GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC)
3784 if (likely(ctx->opcode & 0x00100000)) {
3785 crm = CRM(ctx->opcode);
3786 if (likely((crm ^ (crm - 1)) == 0)) {
3788 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]);
3791 tcg_gen_helper_1_0(helper_load_cr, cpu_gpr[rD(ctx->opcode)]);
3796 GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC)
3798 #if defined(CONFIG_USER_ONLY)
3799 GEN_EXCP_PRIVREG(ctx);
3801 if (unlikely(!ctx->supervisor)) {
3802 GEN_EXCP_PRIVREG(ctx);
3806 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
3811 #define SPR_NOACCESS ((void *)(-1UL))
3813 static void spr_noaccess (void *opaque, int sprn)
3815 sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
3816 printf("ERROR: try to access SPR %d !\n", sprn);
3818 #define SPR_NOACCESS (&spr_noaccess)
3822 static always_inline void gen_op_mfspr (DisasContext *ctx)
3824 void (*read_cb)(void *opaque, int sprn);
3825 uint32_t sprn = SPR(ctx->opcode);
3827 #if !defined(CONFIG_USER_ONLY)
3828 if (ctx->supervisor == 2)
3829 read_cb = ctx->spr_cb[sprn].hea_read;
3830 else if (ctx->supervisor)
3831 read_cb = ctx->spr_cb[sprn].oea_read;
3834 read_cb = ctx->spr_cb[sprn].uea_read;
3835 if (likely(read_cb != NULL)) {
3836 if (likely(read_cb != SPR_NOACCESS)) {
3837 (*read_cb)(ctx, sprn);
3838 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
3840 /* Privilege exception */
3841 /* This is a hack to avoid warnings when running Linux:
3842 * this OS breaks the PowerPC virtualisation model,
3843 * allowing userland application to read the PVR
3845 if (sprn != SPR_PVR) {
3846 if (loglevel != 0) {
3847 fprintf(logfile, "Trying to read privileged spr %d %03x at "
3848 ADDRX "\n", sprn, sprn, ctx->nip);
3850 printf("Trying to read privileged spr %d %03x at " ADDRX "\n",
3851 sprn, sprn, ctx->nip);
3853 GEN_EXCP_PRIVREG(ctx);
3857 if (loglevel != 0) {
3858 fprintf(logfile, "Trying to read invalid spr %d %03x at "
3859 ADDRX "\n", sprn, sprn, ctx->nip);
3861 printf("Trying to read invalid spr %d %03x at " ADDRX "\n",
3862 sprn, sprn, ctx->nip);
3863 GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM,
3864 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_SPR);
3868 GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC)
3874 GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB)
3880 GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC)
3884 crm = CRM(ctx->opcode);
3885 if (likely((ctx->opcode & 0x00100000) || (crm ^ (crm - 1)) == 0)) {
3887 tcg_gen_shri_i32(cpu_crf[7 - crn], cpu_gpr[rS(ctx->opcode)], crn * 4);
3888 tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf);
3890 TCGv t0 = tcg_const_tl(crm);
3891 tcg_gen_helper_0_2(helper_store_cr, cpu_gpr[rS(ctx->opcode)], t0);
3897 #if defined(TARGET_PPC64)
3898 GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B)
3900 #if defined(CONFIG_USER_ONLY)
3901 GEN_EXCP_PRIVREG(ctx);
3903 if (unlikely(!ctx->supervisor)) {
3904 GEN_EXCP_PRIVREG(ctx);
3907 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
3908 if (ctx->opcode & 0x00010000) {
3909 /* Special form that does not need any synchronisation */
3910 gen_op_update_riee();
3912 /* XXX: we need to update nip before the store
3913 * if we enter power saving mode, we will exit the loop
3914 * directly from ppc_store_msr
3916 gen_update_nip(ctx, ctx->nip);
3918 /* Must stop the translation as machine state (may have) changed */
3919 /* Note that mtmsr is not always defined as context-synchronizing */
3920 ctx->exception = POWERPC_EXCP_STOP;
3926 GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC)
3928 #if defined(CONFIG_USER_ONLY)
3929 GEN_EXCP_PRIVREG(ctx);
3931 if (unlikely(!ctx->supervisor)) {
3932 GEN_EXCP_PRIVREG(ctx);
3935 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
3936 if (ctx->opcode & 0x00010000) {
3937 /* Special form that does not need any synchronisation */
3938 gen_op_update_riee();
3940 /* XXX: we need to update nip before the store
3941 * if we enter power saving mode, we will exit the loop
3942 * directly from ppc_store_msr
3944 gen_update_nip(ctx, ctx->nip);
3945 #if defined(TARGET_PPC64)
3947 gen_op_store_msr_32();
3951 /* Must stop the translation as machine state (may have) changed */
3952 /* Note that mtmsrd is not always defined as context-synchronizing */
3953 ctx->exception = POWERPC_EXCP_STOP;
3959 GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC)
3961 void (*write_cb)(void *opaque, int sprn);
3962 uint32_t sprn = SPR(ctx->opcode);
3964 #if !defined(CONFIG_USER_ONLY)
3965 if (ctx->supervisor == 2)
3966 write_cb = ctx->spr_cb[sprn].hea_write;
3967 else if (ctx->supervisor)
3968 write_cb = ctx->spr_cb[sprn].oea_write;
3971 write_cb = ctx->spr_cb[sprn].uea_write;
3972 if (likely(write_cb != NULL)) {
3973 if (likely(write_cb != SPR_NOACCESS)) {
3974 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
3975 (*write_cb)(ctx, sprn);
3977 /* Privilege exception */
3978 if (loglevel != 0) {
3979 fprintf(logfile, "Trying to write privileged spr %d %03x at "
3980 ADDRX "\n", sprn, sprn, ctx->nip);
3982 printf("Trying to write privileged spr %d %03x at " ADDRX "\n",
3983 sprn, sprn, ctx->nip);
3984 GEN_EXCP_PRIVREG(ctx);
3988 if (loglevel != 0) {
3989 fprintf(logfile, "Trying to write invalid spr %d %03x at "
3990 ADDRX "\n", sprn, sprn, ctx->nip);
3992 printf("Trying to write invalid spr %d %03x at " ADDRX "\n",
3993 sprn, sprn, ctx->nip);
3994 GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM,
3995 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_SPR);
3999 /*** Cache management ***/
4001 GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE)
4003 /* XXX: specification says this is treated as a load by the MMU */
4004 TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
4005 gen_addr_reg_index(t0, ctx);
4006 gen_qemu_ld8u(t0, t0, ctx->mem_idx);
4010 /* dcbi (Supervisor only) */
4011 GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE)
4013 #if defined(CONFIG_USER_ONLY)
4014 GEN_EXCP_PRIVOPC(ctx);
4017 if (unlikely(!ctx->supervisor)) {
4018 GEN_EXCP_PRIVOPC(ctx);
4021 EA = tcg_temp_new(TCG_TYPE_TL);
4022 gen_addr_reg_index(EA, ctx);
4023 val = tcg_temp_new(TCG_TYPE_TL);
4024 /* XXX: specification says this should be treated as a store by the MMU */
4025 gen_qemu_ld8u(val, EA, ctx->mem_idx);
4026 gen_qemu_st8(val, EA, ctx->mem_idx);
4033 GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE)
4035 /* XXX: specification say this is treated as a load by the MMU */
4036 TCGv t0 = tcg_temp_new(TCG_TYPE_TL);
4037 gen_addr_reg_index(t0, ctx);
4038 gen_qemu_ld8u(t0, t0, ctx->mem_idx);
4043 GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE)
4045 /* interpreted as no-op */
4046 /* XXX: specification say this is treated as a load by the MMU
4047 * but does not generate any exception
4052 GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE)
4054 /* interpreted as no-op */
4055 /* XXX: specification say this is treated as a load by the MMU
4056 * but does not generate any exception
4061 #define op_dcbz(n) (*gen_op_dcbz[n][ctx->mem_idx])()
4062 static GenOpFunc *gen_op_dcbz[4][NB_MEM_FUNCS] = {
4063 /* 32 bytes cache line size */
4065 #define gen_op_dcbz_l32_le_raw gen_op_dcbz_l32_raw
4066 #define gen_op_dcbz_l32_le_user gen_op_dcbz_l32_user
4067 #define gen_op_dcbz_l32_le_kernel gen_op_dcbz_l32_kernel
4068 #define gen_op_dcbz_l32_le_hypv gen_op_dcbz_l32_hypv
4069 #define gen_op_dcbz_l32_le_64_raw gen_op_dcbz_l32_64_raw
4070 #define gen_op_dcbz_l32_le_64_user gen_op_dcbz_l32_64_user
4071 #define gen_op_dcbz_l32_le_64_kernel gen_op_dcbz_l32_64_kernel
4072 #define gen_op_dcbz_l32_le_64_hypv gen_op_dcbz_l32_64_hypv
4073 GEN_MEM_FUNCS(dcbz_l32),
4075 /* 64 bytes cache line size */
4077 #define gen_op_dcbz_l64_le_raw gen_op_dcbz_l64_raw
4078 #define gen_op_dcbz_l64_le_user gen_op_dcbz_l64_user
4079 #define gen_op_dcbz_l64_le_kernel gen_op_dcbz_l64_kernel
4080 #define gen_op_dcbz_l64_le_hypv gen_op_dcbz_l64_hypv
4081 #define gen_op_dcbz_l64_le_64_raw gen_op_dcbz_l64_64_raw
4082 #define gen_op_dcbz_l64_le_64_user gen_op_dcbz_l64_64_user
4083 #define gen_op_dcbz_l64_le_64_kernel gen_op_dcbz_l64_64_kernel
4084 #define gen_op_dcbz_l64_le_64_hypv gen_op_dcbz_l64_64_hypv
4085 GEN_MEM_FUNCS(dcbz_l64),
4087 /* 128 bytes cache line size */
4089 #define gen_op_dcbz_l128_le_raw gen_op_dcbz_l128_raw
4090 #define gen_op_dcbz_l128_le_user gen_op_dcbz_l128_user
4091 #define gen_op_dcbz_l128_le_kernel gen_op_dcbz_l128_kernel
4092 #define gen_op_dcbz_l128_le_hypv gen_op_dcbz_l128_hypv
4093 #define gen_op_dcbz_l128_le_64_raw gen_op_dcbz_l128_64_raw
4094 #define gen_op_dcbz_l128_le_64_user gen_op_dcbz_l128_64_user
4095 #define gen_op_dcbz_l128_le_64_kernel gen_op_dcbz_l128_64_kernel
4096 #define gen_op_dcbz_l128_le_64_hypv gen_op_dcbz_l128_64_hypv
4097 GEN_MEM_FUNCS(dcbz_l128),
4099 /* tunable cache line size */
4101 #define gen_op_dcbz_le_raw gen_op_dcbz_raw
4102 #define gen_op_dcbz_le_user gen_op_dcbz_user
4103 #define gen_op_dcbz_le_kernel gen_op_dcbz_kernel
4104 #define gen_op_dcbz_le_hypv gen_op_dcbz_hypv
4105 #define gen_op_dcbz_le_64_raw gen_op_dcbz_64_raw
4106 #define gen_op_dcbz_le_64_user gen_op_dcbz_64_user
4107 #define gen_op_dcbz_le_64_kernel gen_op_dcbz_64_kernel
4108 #define gen_op_dcbz_le_64_hypv gen_op_dcbz_64_hypv
4109 GEN_MEM_FUNCS(dcbz),
4113 static always_inline void handler_dcbz (DisasContext *ctx,
4114 int dcache_line_size)
4118 switch (dcache_line_size) {
4135 GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE_DCBZ)
4137 gen_addr_reg_index(cpu_T[0], ctx);
4138 handler_dcbz(ctx, ctx->dcache_line_size);
4139 gen_op_check_reservation();
4142 GEN_HANDLER2(dcbz_970, "dcbz", 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZT)
4144 gen_addr_reg_index(cpu_T[0], ctx);
4145 if (ctx->opcode & 0x00200000)
4146 handler_dcbz(ctx, ctx->dcache_line_size);
4148 handler_dcbz(ctx, -1);
4149 gen_op_check_reservation();
4153 #define op_icbi() (*gen_op_icbi[ctx->mem_idx])()
4154 #define gen_op_icbi_le_raw gen_op_icbi_raw
4155 #define gen_op_icbi_le_user gen_op_icbi_user
4156 #define gen_op_icbi_le_kernel gen_op_icbi_kernel
4157 #define gen_op_icbi_le_hypv gen_op_icbi_hypv
4158 #define gen_op_icbi_le_64_raw gen_op_icbi_64_raw
4159 #define gen_op_icbi_le_64_user gen_op_icbi_64_user
4160 #define gen_op_icbi_le_64_kernel gen_op_icbi_64_kernel
4161 #define gen_op_icbi_le_64_hypv gen_op_icbi_64_hypv
4162 static GenOpFunc *gen_op_icbi[NB_MEM_FUNCS] = {
4163 GEN_MEM_FUNCS(icbi),
4166 GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI)
4168 /* NIP cannot be restored if the memory exception comes from an helper */
4169 gen_update_nip(ctx, ctx->nip - 4);
4170 gen_addr_reg_index(cpu_T[0], ctx);
4176 GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA)
4178 /* interpreted as no-op */
4179 /* XXX: specification say this is treated as a store by the MMU
4180 * but does not generate any exception
4184 /*** Segment register manipulation ***/
4185 /* Supervisor only: */
4187 GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT)
4189 #if defined(CONFIG_USER_ONLY)
4190 GEN_EXCP_PRIVREG(ctx);
4192 if (unlikely(!ctx->supervisor)) {
4193 GEN_EXCP_PRIVREG(ctx);
4196 tcg_gen_movi_tl(cpu_T[1], SR(ctx->opcode));
4198 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4203 GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT)
4205 #if defined(CONFIG_USER_ONLY)
4206 GEN_EXCP_PRIVREG(ctx);
4208 if (unlikely(!ctx->supervisor)) {
4209 GEN_EXCP_PRIVREG(ctx);
4212 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4215 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4220 GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT)
4222 #if defined(CONFIG_USER_ONLY)
4223 GEN_EXCP_PRIVREG(ctx);
4225 if (unlikely(!ctx->supervisor)) {
4226 GEN_EXCP_PRIVREG(ctx);
4229 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4230 tcg_gen_movi_tl(cpu_T[1], SR(ctx->opcode));
4236 GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT)
4238 #if defined(CONFIG_USER_ONLY)
4239 GEN_EXCP_PRIVREG(ctx);
4241 if (unlikely(!ctx->supervisor)) {
4242 GEN_EXCP_PRIVREG(ctx);
4245 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4246 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4252 #if defined(TARGET_PPC64)
4253 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4255 GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B)
4257 #if defined(CONFIG_USER_ONLY)
4258 GEN_EXCP_PRIVREG(ctx);
4260 if (unlikely(!ctx->supervisor)) {
4261 GEN_EXCP_PRIVREG(ctx);
4264 tcg_gen_movi_tl(cpu_T[1], SR(ctx->opcode));
4266 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4271 GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
4274 #if defined(CONFIG_USER_ONLY)
4275 GEN_EXCP_PRIVREG(ctx);
4277 if (unlikely(!ctx->supervisor)) {
4278 GEN_EXCP_PRIVREG(ctx);
4281 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4284 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4289 GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B)
4291 #if defined(CONFIG_USER_ONLY)
4292 GEN_EXCP_PRIVREG(ctx);
4294 if (unlikely(!ctx->supervisor)) {
4295 GEN_EXCP_PRIVREG(ctx);
4298 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4299 tcg_gen_movi_tl(cpu_T[1], SR(ctx->opcode));
4305 GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
4308 #if defined(CONFIG_USER_ONLY)
4309 GEN_EXCP_PRIVREG(ctx);
4311 if (unlikely(!ctx->supervisor)) {
4312 GEN_EXCP_PRIVREG(ctx);
4315 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4316 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4321 #endif /* defined(TARGET_PPC64) */
4323 /*** Lookaside buffer management ***/
4324 /* Optional & supervisor only: */
4326 GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA)
4328 #if defined(CONFIG_USER_ONLY)
4329 GEN_EXCP_PRIVOPC(ctx);
4331 if (unlikely(!ctx->supervisor)) {
4332 GEN_EXCP_PRIVOPC(ctx);
4340 GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE)
4342 #if defined(CONFIG_USER_ONLY)
4343 GEN_EXCP_PRIVOPC(ctx);
4345 if (unlikely(!ctx->supervisor)) {
4346 GEN_EXCP_PRIVOPC(ctx);
4349 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4350 #if defined(TARGET_PPC64)
4360 GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC)
4362 #if defined(CONFIG_USER_ONLY)
4363 GEN_EXCP_PRIVOPC(ctx);
4365 if (unlikely(!ctx->supervisor)) {
4366 GEN_EXCP_PRIVOPC(ctx);
4369 /* This has no effect: it should ensure that all previous
4370 * tlbie have completed
4376 #if defined(TARGET_PPC64)
4378 GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI)
4380 #if defined(CONFIG_USER_ONLY)
4381 GEN_EXCP_PRIVOPC(ctx);
4383 if (unlikely(!ctx->supervisor)) {
4384 GEN_EXCP_PRIVOPC(ctx);
4392 GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI)
4394 #if defined(CONFIG_USER_ONLY)
4395 GEN_EXCP_PRIVOPC(ctx);
4397 if (unlikely(!ctx->supervisor)) {
4398 GEN_EXCP_PRIVOPC(ctx);
4401 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4407 /*** External control ***/
4409 #define op_eciwx() (*gen_op_eciwx[ctx->mem_idx])()
4410 #define op_ecowx() (*gen_op_ecowx[ctx->mem_idx])()
4411 static GenOpFunc *gen_op_eciwx[NB_MEM_FUNCS] = {
4412 GEN_MEM_FUNCS(eciwx),
4414 static GenOpFunc *gen_op_ecowx[NB_MEM_FUNCS] = {
4415 GEN_MEM_FUNCS(ecowx),
4419 GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN)
4421 /* Should check EAR[E] & alignment ! */
4422 gen_addr_reg_index(cpu_T[0], ctx);
4424 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4428 GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN)
4430 /* Should check EAR[E] & alignment ! */
4431 gen_addr_reg_index(cpu_T[0], ctx);
4432 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
4436 /* PowerPC 601 specific instructions */
4438 GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR)
4440 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4442 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4443 if (unlikely(Rc(ctx->opcode) != 0))
4444 gen_set_Rc0(ctx, cpu_T[0]);
4448 GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR)
4450 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4451 gen_op_POWER_abso();
4452 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4453 if (unlikely(Rc(ctx->opcode) != 0))
4454 gen_set_Rc0(ctx, cpu_T[0]);
4458 GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR)
4460 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4461 gen_op_POWER_clcs();
4462 /* Rc=1 sets CR0 to an undefined state */
4463 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4467 GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR)
4469 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4470 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4472 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4473 if (unlikely(Rc(ctx->opcode) != 0))
4474 gen_set_Rc0(ctx, cpu_T[0]);
4478 GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR)
4480 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4481 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4482 gen_op_POWER_divo();
4483 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4484 if (unlikely(Rc(ctx->opcode) != 0))
4485 gen_set_Rc0(ctx, cpu_T[0]);
4489 GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR)
4491 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4492 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4493 gen_op_POWER_divs();
4494 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4495 if (unlikely(Rc(ctx->opcode) != 0))
4496 gen_set_Rc0(ctx, cpu_T[0]);
4499 /* divso - divso. */
4500 GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR)
4502 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4503 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4504 gen_op_POWER_divso();
4505 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4506 if (unlikely(Rc(ctx->opcode) != 0))
4507 gen_set_Rc0(ctx, cpu_T[0]);
4511 GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR)
4513 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4514 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4516 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4517 if (unlikely(Rc(ctx->opcode) != 0))
4518 gen_set_Rc0(ctx, cpu_T[0]);
4522 GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR)
4524 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4525 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4526 gen_op_POWER_dozo();
4527 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4528 if (unlikely(Rc(ctx->opcode) != 0))
4529 gen_set_Rc0(ctx, cpu_T[0]);
4533 GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR)
4535 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4536 tcg_gen_movi_tl(cpu_T[1], SIMM(ctx->opcode));
4538 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4541 /* As lscbx load from memory byte after byte, it's always endian safe.
4542 * Original POWER is 32 bits only, define 64 bits ops as 32 bits ones
4544 #define op_POWER_lscbx(start, ra, rb) \
4545 (*gen_op_POWER_lscbx[ctx->mem_idx])(start, ra, rb)
4546 #define gen_op_POWER_lscbx_64_raw gen_op_POWER_lscbx_raw
4547 #define gen_op_POWER_lscbx_64_user gen_op_POWER_lscbx_user
4548 #define gen_op_POWER_lscbx_64_kernel gen_op_POWER_lscbx_kernel
4549 #define gen_op_POWER_lscbx_64_hypv gen_op_POWER_lscbx_hypv
4550 #define gen_op_POWER_lscbx_le_raw gen_op_POWER_lscbx_raw
4551 #define gen_op_POWER_lscbx_le_user gen_op_POWER_lscbx_user
4552 #define gen_op_POWER_lscbx_le_kernel gen_op_POWER_lscbx_kernel
4553 #define gen_op_POWER_lscbx_le_hypv gen_op_POWER_lscbx_hypv
4554 #define gen_op_POWER_lscbx_le_64_raw gen_op_POWER_lscbx_raw
4555 #define gen_op_POWER_lscbx_le_64_user gen_op_POWER_lscbx_user
4556 #define gen_op_POWER_lscbx_le_64_kernel gen_op_POWER_lscbx_kernel
4557 #define gen_op_POWER_lscbx_le_64_hypv gen_op_POWER_lscbx_hypv
4558 static GenOpFunc3 *gen_op_POWER_lscbx[NB_MEM_FUNCS] = {
4559 GEN_MEM_FUNCS(POWER_lscbx),
4562 /* lscbx - lscbx. */
4563 GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR)
4565 int ra = rA(ctx->opcode);
4566 int rb = rB(ctx->opcode);
4568 gen_addr_reg_index(cpu_T[0], ctx);
4572 /* NIP cannot be restored if the memory exception comes from an helper */
4573 gen_update_nip(ctx, ctx->nip - 4);
4574 tcg_gen_andi_tl(cpu_T[1], cpu_xer, 0x7F);
4575 tcg_gen_shri_tl(cpu_T[2], cpu_xer, XER_CMP);
4576 tcg_gen_andi_tl(cpu_T[2], cpu_T[2], 0xFF);
4577 op_POWER_lscbx(rD(ctx->opcode), ra, rb);
4578 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
4579 tcg_gen_or_tl(cpu_xer, cpu_xer, cpu_T[0]);
4580 if (unlikely(Rc(ctx->opcode) != 0))
4581 gen_set_Rc0(ctx, cpu_T[0]);
4584 /* maskg - maskg. */
4585 GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR)
4587 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4588 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4589 gen_op_POWER_maskg();
4590 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4591 if (unlikely(Rc(ctx->opcode) != 0))
4592 gen_set_Rc0(ctx, cpu_T[0]);
4595 /* maskir - maskir. */
4596 GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR)
4598 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4599 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
4600 tcg_gen_mov_tl(cpu_T[2], cpu_gpr[rB(ctx->opcode)]);
4601 gen_op_POWER_maskir();
4602 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4603 if (unlikely(Rc(ctx->opcode) != 0))
4604 gen_set_Rc0(ctx, cpu_T[0]);
4608 GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR)
4610 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4611 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4613 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4614 if (unlikely(Rc(ctx->opcode) != 0))
4615 gen_set_Rc0(ctx, cpu_T[0]);
4619 GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR)
4621 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4622 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4623 gen_op_POWER_mulo();
4624 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4625 if (unlikely(Rc(ctx->opcode) != 0))
4626 gen_set_Rc0(ctx, cpu_T[0]);
4630 GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR)
4632 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4633 gen_op_POWER_nabs();
4634 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4635 if (unlikely(Rc(ctx->opcode) != 0))
4636 gen_set_Rc0(ctx, cpu_T[0]);
4639 /* nabso - nabso. */
4640 GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR)
4642 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4643 gen_op_POWER_nabso();
4644 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4645 if (unlikely(Rc(ctx->opcode) != 0))
4646 gen_set_Rc0(ctx, cpu_T[0]);
4650 GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR)
4654 mb = MB(ctx->opcode);
4655 me = ME(ctx->opcode);
4656 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4657 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rA(ctx->opcode)]);
4658 tcg_gen_mov_tl(cpu_T[2], cpu_gpr[rB(ctx->opcode)]);
4659 gen_op_POWER_rlmi(MASK(mb, me), ~MASK(mb, me));
4660 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4661 if (unlikely(Rc(ctx->opcode) != 0))
4662 gen_set_Rc0(ctx, cpu_T[0]);
4666 GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR)
4668 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4669 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rA(ctx->opcode)]);
4670 tcg_gen_mov_tl(cpu_T[2], cpu_gpr[rB(ctx->opcode)]);
4671 gen_op_POWER_rrib();
4672 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4673 if (unlikely(Rc(ctx->opcode) != 0))
4674 gen_set_Rc0(ctx, cpu_T[0]);
4678 GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR)
4680 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4681 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4683 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4684 if (unlikely(Rc(ctx->opcode) != 0))
4685 gen_set_Rc0(ctx, cpu_T[0]);
4689 GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR)
4691 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4692 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4693 gen_op_POWER_sleq();
4694 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4695 if (unlikely(Rc(ctx->opcode) != 0))
4696 gen_set_Rc0(ctx, cpu_T[0]);
4700 GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR)
4702 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4703 tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4705 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4706 if (unlikely(Rc(ctx->opcode) != 0))
4707 gen_set_Rc0(ctx, cpu_T[0]);
4710 /* slliq - slliq. */
4711 GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR)
4713 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4714 tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4715 gen_op_POWER_sleq();
4716 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4717 if (unlikely(Rc(ctx->opcode) != 0))
4718 gen_set_Rc0(ctx, cpu_T[0]);
4722 GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR)
4724 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4725 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4726 gen_op_POWER_sllq();
4727 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4728 if (unlikely(Rc(ctx->opcode) != 0))
4729 gen_set_Rc0(ctx, cpu_T[0]);
4733 GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR)
4735 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4736 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4738 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4739 if (unlikely(Rc(ctx->opcode) != 0))
4740 gen_set_Rc0(ctx, cpu_T[0]);
4743 /* sraiq - sraiq. */
4744 GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR)
4746 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4747 tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4748 gen_op_POWER_sraq();
4749 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4750 if (unlikely(Rc(ctx->opcode) != 0))
4751 gen_set_Rc0(ctx, cpu_T[0]);
4755 GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR)
4757 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4758 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4759 gen_op_POWER_sraq();
4760 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4761 if (unlikely(Rc(ctx->opcode) != 0))
4762 gen_set_Rc0(ctx, cpu_T[0]);
4766 GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR)
4768 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4769 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4771 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4772 if (unlikely(Rc(ctx->opcode) != 0))
4773 gen_set_Rc0(ctx, cpu_T[0]);
4777 GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR)
4779 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4780 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4781 gen_op_POWER_srea();
4782 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4783 if (unlikely(Rc(ctx->opcode) != 0))
4784 gen_set_Rc0(ctx, cpu_T[0]);
4788 GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR)
4790 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4791 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4792 gen_op_POWER_sreq();
4793 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4794 if (unlikely(Rc(ctx->opcode) != 0))
4795 gen_set_Rc0(ctx, cpu_T[0]);
4799 GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR)
4801 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4802 tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4804 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4805 if (unlikely(Rc(ctx->opcode) != 0))
4806 gen_set_Rc0(ctx, cpu_T[0]);
4810 GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR)
4812 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4813 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4814 tcg_gen_movi_tl(cpu_T[1], SH(ctx->opcode));
4815 gen_op_POWER_srlq();
4816 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4817 if (unlikely(Rc(ctx->opcode) != 0))
4818 gen_set_Rc0(ctx, cpu_T[0]);
4822 GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR)
4824 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4825 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4826 gen_op_POWER_srlq();
4827 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4828 if (unlikely(Rc(ctx->opcode) != 0))
4829 gen_set_Rc0(ctx, cpu_T[0]);
4833 GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR)
4835 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
4836 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
4838 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
4839 if (unlikely(Rc(ctx->opcode) != 0))
4840 gen_set_Rc0(ctx, cpu_T[0]);
4843 /* PowerPC 602 specific instructions */
4845 GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC)
4848 GEN_EXCP_INVAL(ctx);
4852 GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC)
4855 GEN_EXCP_INVAL(ctx);
4859 GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC)
4861 #if defined(CONFIG_USER_ONLY)
4862 GEN_EXCP_PRIVOPC(ctx);
4864 if (unlikely(!ctx->supervisor)) {
4865 GEN_EXCP_PRIVOPC(ctx);
4868 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
4870 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4874 /* 602 - 603 - G2 TLB management */
4876 GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB)
4878 #if defined(CONFIG_USER_ONLY)
4879 GEN_EXCP_PRIVOPC(ctx);
4881 if (unlikely(!ctx->supervisor)) {
4882 GEN_EXCP_PRIVOPC(ctx);
4885 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4891 GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB)
4893 #if defined(CONFIG_USER_ONLY)
4894 GEN_EXCP_PRIVOPC(ctx);
4896 if (unlikely(!ctx->supervisor)) {
4897 GEN_EXCP_PRIVOPC(ctx);
4900 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4905 /* 74xx TLB management */
4907 GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB)
4909 #if defined(CONFIG_USER_ONLY)
4910 GEN_EXCP_PRIVOPC(ctx);
4912 if (unlikely(!ctx->supervisor)) {
4913 GEN_EXCP_PRIVOPC(ctx);
4916 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4917 gen_op_74xx_tlbld();
4922 GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB)
4924 #if defined(CONFIG_USER_ONLY)
4925 GEN_EXCP_PRIVOPC(ctx);
4927 if (unlikely(!ctx->supervisor)) {
4928 GEN_EXCP_PRIVOPC(ctx);
4931 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rB(ctx->opcode)]);
4932 gen_op_74xx_tlbli();
4936 /* POWER instructions not in PowerPC 601 */
4938 GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER)
4940 /* Cache line flush: implemented as no-op */
4944 GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER)
4946 /* Cache line invalidate: privileged and treated as no-op */
4947 #if defined(CONFIG_USER_ONLY)
4948 GEN_EXCP_PRIVOPC(ctx);
4950 if (unlikely(!ctx->supervisor)) {
4951 GEN_EXCP_PRIVOPC(ctx);
4958 GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER)
4960 /* Data cache line store: treated as no-op */
4963 GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER)
4965 #if defined(CONFIG_USER_ONLY)
4966 GEN_EXCP_PRIVOPC(ctx);
4968 if (unlikely(!ctx->supervisor)) {
4969 GEN_EXCP_PRIVOPC(ctx);
4972 int ra = rA(ctx->opcode);
4973 int rd = rD(ctx->opcode);
4975 gen_addr_reg_index(cpu_T[0], ctx);
4976 gen_op_POWER_mfsri();
4977 tcg_gen_mov_tl(cpu_gpr[rd], cpu_T[0]);
4978 if (ra != 0 && ra != rd)
4979 tcg_gen_mov_tl(cpu_gpr[ra], cpu_T[1]);
4983 GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER)
4985 #if defined(CONFIG_USER_ONLY)
4986 GEN_EXCP_PRIVOPC(ctx);
4988 if (unlikely(!ctx->supervisor)) {
4989 GEN_EXCP_PRIVOPC(ctx);
4992 gen_addr_reg_index(cpu_T[0], ctx);
4994 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
4998 GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER)
5000 #if defined(CONFIG_USER_ONLY)
5001 GEN_EXCP_PRIVOPC(ctx);
5003 if (unlikely(!ctx->supervisor)) {
5004 GEN_EXCP_PRIVOPC(ctx);
5007 gen_op_POWER_rfsvc();
5012 /* svc is not implemented for now */
5014 /* POWER2 specific instructions */
5015 /* Quad manipulation (load/store two floats at a time) */
5016 /* Original POWER2 is 32 bits only, define 64 bits ops as 32 bits ones */
5017 #define op_POWER2_lfq() (*gen_op_POWER2_lfq[ctx->mem_idx])()
5018 #define op_POWER2_stfq() (*gen_op_POWER2_stfq[ctx->mem_idx])()
5019 #define gen_op_POWER2_lfq_64_raw gen_op_POWER2_lfq_raw
5020 #define gen_op_POWER2_lfq_64_user gen_op_POWER2_lfq_user
5021 #define gen_op_POWER2_lfq_64_kernel gen_op_POWER2_lfq_kernel
5022 #define gen_op_POWER2_lfq_64_hypv gen_op_POWER2_lfq_hypv
5023 #define gen_op_POWER2_lfq_le_64_raw gen_op_POWER2_lfq_le_raw
5024 #define gen_op_POWER2_lfq_le_64_user gen_op_POWER2_lfq_le_user
5025 #define gen_op_POWER2_lfq_le_64_kernel gen_op_POWER2_lfq_le_kernel
5026 #define gen_op_POWER2_lfq_le_64_hypv gen_op_POWER2_lfq_le_hypv
5027 #define gen_op_POWER2_stfq_64_raw gen_op_POWER2_stfq_raw
5028 #define gen_op_POWER2_stfq_64_user gen_op_POWER2_stfq_user
5029 #define gen_op_POWER2_stfq_64_kernel gen_op_POWER2_stfq_kernel
5030 #define gen_op_POWER2_stfq_64_hypv gen_op_POWER2_stfq_hypv
5031 #define gen_op_POWER2_stfq_le_64_raw gen_op_POWER2_stfq_le_raw
5032 #define gen_op_POWER2_stfq_le_64_user gen_op_POWER2_stfq_le_user
5033 #define gen_op_POWER2_stfq_le_64_kernel gen_op_POWER2_stfq_le_kernel
5034 #define gen_op_POWER2_stfq_le_64_hypv gen_op_POWER2_stfq_le_hypv
5035 static GenOpFunc *gen_op_POWER2_lfq[NB_MEM_FUNCS] = {
5036 GEN_MEM_FUNCS(POWER2_lfq),
5038 static GenOpFunc *gen_op_POWER2_stfq[NB_MEM_FUNCS] = {
5039 GEN_MEM_FUNCS(POWER2_stfq),
5043 GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
5045 /* NIP cannot be restored if the memory exception comes from an helper */
5046 gen_update_nip(ctx, ctx->nip - 4);
5047 gen_addr_imm_index(cpu_T[0], ctx, 0);
5049 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
5050 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode) + 1], cpu_FT[1]);
5054 GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
5056 int ra = rA(ctx->opcode);
5058 /* NIP cannot be restored if the memory exception comes from an helper */
5059 gen_update_nip(ctx, ctx->nip - 4);
5060 gen_addr_imm_index(cpu_T[0], ctx, 0);
5062 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
5063 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode) + 1], cpu_FT[1]);
5065 tcg_gen_mov_tl(cpu_gpr[ra], cpu_T[0]);
5069 GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2)
5071 int ra = rA(ctx->opcode);
5073 /* NIP cannot be restored if the memory exception comes from an helper */
5074 gen_update_nip(ctx, ctx->nip - 4);
5075 gen_addr_reg_index(cpu_T[0], ctx);
5077 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
5078 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode) + 1], cpu_FT[1]);
5080 tcg_gen_mov_tl(cpu_gpr[ra], cpu_T[0]);
5084 GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2)
5086 /* NIP cannot be restored if the memory exception comes from an helper */
5087 gen_update_nip(ctx, ctx->nip - 4);
5088 gen_addr_reg_index(cpu_T[0], ctx);
5090 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]);
5091 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode) + 1], cpu_FT[1]);
5095 GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
5097 /* NIP cannot be restored if the memory exception comes from an helper */
5098 gen_update_nip(ctx, ctx->nip - 4);
5099 gen_addr_imm_index(cpu_T[0], ctx, 0);
5100 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]);
5101 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rS(ctx->opcode) + 1]);
5106 GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
5108 int ra = rA(ctx->opcode);
5110 /* NIP cannot be restored if the memory exception comes from an helper */
5111 gen_update_nip(ctx, ctx->nip - 4);
5112 gen_addr_imm_index(cpu_T[0], ctx, 0);
5113 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]);
5114 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rS(ctx->opcode) + 1]);
5117 tcg_gen_mov_tl(cpu_gpr[ra], cpu_T[0]);
5121 GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2)
5123 int ra = rA(ctx->opcode);
5125 /* NIP cannot be restored if the memory exception comes from an helper */
5126 gen_update_nip(ctx, ctx->nip - 4);
5127 gen_addr_reg_index(cpu_T[0], ctx);
5128 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]);
5129 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rS(ctx->opcode) + 1]);
5132 tcg_gen_mov_tl(cpu_gpr[ra], cpu_T[0]);
5136 GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2)
5138 /* NIP cannot be restored if the memory exception comes from an helper */
5139 gen_update_nip(ctx, ctx->nip - 4);
5140 gen_addr_reg_index(cpu_T[0], ctx);
5141 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]);
5142 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rS(ctx->opcode) + 1]);
5146 /* BookE specific instructions */
5147 /* XXX: not implemented on 440 ? */
5148 GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI)
5151 GEN_EXCP_INVAL(ctx);
5154 /* XXX: not implemented on 440 ? */
5155 GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA)
5157 #if defined(CONFIG_USER_ONLY)
5158 GEN_EXCP_PRIVOPC(ctx);
5160 if (unlikely(!ctx->supervisor)) {
5161 GEN_EXCP_PRIVOPC(ctx);
5164 gen_addr_reg_index(cpu_T[0], ctx);
5165 /* Use the same micro-ops as for tlbie */
5166 #if defined(TARGET_PPC64)
5175 /* All 405 MAC instructions are translated here */
5176 static always_inline void gen_405_mulladd_insn (DisasContext *ctx,
5178 int ra, int rb, int rt, int Rc)
5182 t0 = tcg_temp_local_new(TCG_TYPE_TL);
5183 t1 = tcg_temp_local_new(TCG_TYPE_TL);
5185 switch (opc3 & 0x0D) {
5187 /* macchw - macchw. - macchwo - macchwo. */
5188 /* macchws - macchws. - macchwso - macchwso. */
5189 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5190 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5191 /* mulchw - mulchw. */
5192 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5193 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5194 tcg_gen_ext16s_tl(t1, t1);
5197 /* macchwu - macchwu. - macchwuo - macchwuo. */
5198 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5199 /* mulchwu - mulchwu. */
5200 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5201 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5202 tcg_gen_ext16u_tl(t1, t1);
5205 /* machhw - machhw. - machhwo - machhwo. */
5206 /* machhws - machhws. - machhwso - machhwso. */
5207 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5208 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5209 /* mulhhw - mulhhw. */
5210 tcg_gen_sari_tl(t0, cpu_gpr[ra], 16);
5211 tcg_gen_ext16s_tl(t0, t0);
5212 tcg_gen_sari_tl(t1, cpu_gpr[rb], 16);
5213 tcg_gen_ext16s_tl(t1, t1);
5216 /* machhwu - machhwu. - machhwuo - machhwuo. */
5217 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5218 /* mulhhwu - mulhhwu. */
5219 tcg_gen_shri_tl(t0, cpu_gpr[ra], 16);
5220 tcg_gen_ext16u_tl(t0, t0);
5221 tcg_gen_shri_tl(t1, cpu_gpr[rb], 16);
5222 tcg_gen_ext16u_tl(t1, t1);
5225 /* maclhw - maclhw. - maclhwo - maclhwo. */
5226 /* maclhws - maclhws. - maclhwso - maclhwso. */
5227 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5228 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5229 /* mullhw - mullhw. */
5230 tcg_gen_ext16s_tl(t0, cpu_gpr[ra]);
5231 tcg_gen_ext16s_tl(t1, cpu_gpr[rb]);
5234 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5235 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5236 /* mullhwu - mullhwu. */
5237 tcg_gen_ext16u_tl(t0, cpu_gpr[ra]);
5238 tcg_gen_ext16u_tl(t1, cpu_gpr[rb]);
5242 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5243 tcg_gen_mul_tl(t1, t0, t1);
5245 /* nmultiply-and-accumulate (0x0E) */
5246 tcg_gen_sub_tl(t0, cpu_gpr[rt], t1);
5248 /* multiply-and-accumulate (0x0C) */
5249 tcg_gen_add_tl(t0, cpu_gpr[rt], t1);
5253 /* Check overflow and/or saturate */
5254 int l1 = gen_new_label();
5257 /* Start with XER OV disabled, the most likely case */
5258 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~(1 << XER_OV));
5262 tcg_gen_xor_tl(t1, cpu_gpr[rt], t1);
5263 tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1);
5264 tcg_gen_xor_tl(t1, cpu_gpr[rt], t0);
5265 tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1);
5268 tcg_gen_sari_tl(t0, cpu_gpr[rt], 31);
5269 tcg_gen_xori_tl(t0, t0, 0x7fffffff);
5273 tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1);
5276 tcg_gen_movi_tl(t0, UINT32_MAX);
5280 /* Check overflow */
5281 tcg_gen_ori_tl(cpu_xer, cpu_xer, (1 << XER_OV) | (1 << XER_SO));
5284 tcg_gen_mov_tl(cpu_gpr[rt], t0);
5287 tcg_gen_mul_tl(cpu_gpr[rt], t0, t1);
5291 if (unlikely(Rc) != 0) {
5293 gen_set_Rc0(ctx, cpu_gpr[rt]);
5297 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5298 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC) \
5300 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5301 rD(ctx->opcode), Rc(ctx->opcode)); \
5304 /* macchw - macchw. */
5305 GEN_MAC_HANDLER(macchw, 0x0C, 0x05);
5306 /* macchwo - macchwo. */
5307 GEN_MAC_HANDLER(macchwo, 0x0C, 0x15);
5308 /* macchws - macchws. */
5309 GEN_MAC_HANDLER(macchws, 0x0C, 0x07);
5310 /* macchwso - macchwso. */
5311 GEN_MAC_HANDLER(macchwso, 0x0C, 0x17);
5312 /* macchwsu - macchwsu. */
5313 GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06);
5314 /* macchwsuo - macchwsuo. */
5315 GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16);
5316 /* macchwu - macchwu. */
5317 GEN_MAC_HANDLER(macchwu, 0x0C, 0x04);
5318 /* macchwuo - macchwuo. */
5319 GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14);
5320 /* machhw - machhw. */
5321 GEN_MAC_HANDLER(machhw, 0x0C, 0x01);
5322 /* machhwo - machhwo. */
5323 GEN_MAC_HANDLER(machhwo, 0x0C, 0x11);
5324 /* machhws - machhws. */
5325 GEN_MAC_HANDLER(machhws, 0x0C, 0x03);
5326 /* machhwso - machhwso. */
5327 GEN_MAC_HANDLER(machhwso, 0x0C, 0x13);
5328 /* machhwsu - machhwsu. */
5329 GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02);
5330 /* machhwsuo - machhwsuo. */
5331 GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12);
5332 /* machhwu - machhwu. */
5333 GEN_MAC_HANDLER(machhwu, 0x0C, 0x00);
5334 /* machhwuo - machhwuo. */
5335 GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10);
5336 /* maclhw - maclhw. */
5337 GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D);
5338 /* maclhwo - maclhwo. */
5339 GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D);
5340 /* maclhws - maclhws. */
5341 GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F);
5342 /* maclhwso - maclhwso. */
5343 GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F);
5344 /* maclhwu - maclhwu. */
5345 GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C);
5346 /* maclhwuo - maclhwuo. */
5347 GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C);
5348 /* maclhwsu - maclhwsu. */
5349 GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E);
5350 /* maclhwsuo - maclhwsuo. */
5351 GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E);
5352 /* nmacchw - nmacchw. */
5353 GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05);
5354 /* nmacchwo - nmacchwo. */
5355 GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15);
5356 /* nmacchws - nmacchws. */
5357 GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07);
5358 /* nmacchwso - nmacchwso. */
5359 GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17);
5360 /* nmachhw - nmachhw. */
5361 GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01);
5362 /* nmachhwo - nmachhwo. */
5363 GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11);
5364 /* nmachhws - nmachhws. */
5365 GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03);
5366 /* nmachhwso - nmachhwso. */
5367 GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13);
5368 /* nmaclhw - nmaclhw. */
5369 GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D);
5370 /* nmaclhwo - nmaclhwo. */
5371 GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D);
5372 /* nmaclhws - nmaclhws. */
5373 GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F);
5374 /* nmaclhwso - nmaclhwso. */
5375 GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F);
5377 /* mulchw - mulchw. */
5378 GEN_MAC_HANDLER(mulchw, 0x08, 0x05);
5379 /* mulchwu - mulchwu. */
5380 GEN_MAC_HANDLER(mulchwu, 0x08, 0x04);
5381 /* mulhhw - mulhhw. */
5382 GEN_MAC_HANDLER(mulhhw, 0x08, 0x01);
5383 /* mulhhwu - mulhhwu. */
5384 GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00);
5385 /* mullhw - mullhw. */
5386 GEN_MAC_HANDLER(mullhw, 0x08, 0x0D);
5387 /* mullhwu - mullhwu. */
5388 GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
5391 GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR)
5393 #if defined(CONFIG_USER_ONLY)
5394 GEN_EXCP_PRIVREG(ctx);
5396 uint32_t dcrn = SPR(ctx->opcode);
5398 if (unlikely(!ctx->supervisor)) {
5399 GEN_EXCP_PRIVREG(ctx);
5402 tcg_gen_movi_tl(cpu_T[0], dcrn);
5404 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5409 GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR)
5411 #if defined(CONFIG_USER_ONLY)
5412 GEN_EXCP_PRIVREG(ctx);
5414 uint32_t dcrn = SPR(ctx->opcode);
5416 if (unlikely(!ctx->supervisor)) {
5417 GEN_EXCP_PRIVREG(ctx);
5420 tcg_gen_movi_tl(cpu_T[0], dcrn);
5421 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5427 /* XXX: not implemented on 440 ? */
5428 GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX)
5430 #if defined(CONFIG_USER_ONLY)
5431 GEN_EXCP_PRIVREG(ctx);
5433 if (unlikely(!ctx->supervisor)) {
5434 GEN_EXCP_PRIVREG(ctx);
5437 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5439 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5440 /* Note: Rc update flag set leads to undefined state of Rc0 */
5445 /* XXX: not implemented on 440 ? */
5446 GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX)
5448 #if defined(CONFIG_USER_ONLY)
5449 GEN_EXCP_PRIVREG(ctx);
5451 if (unlikely(!ctx->supervisor)) {
5452 GEN_EXCP_PRIVREG(ctx);
5455 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5456 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5458 /* Note: Rc update flag set leads to undefined state of Rc0 */
5462 /* mfdcrux (PPC 460) : user-mode access to DCR */
5463 GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX)
5465 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5467 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5468 /* Note: Rc update flag set leads to undefined state of Rc0 */
5471 /* mtdcrux (PPC 460) : user-mode access to DCR */
5472 GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX)
5474 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5475 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5477 /* Note: Rc update flag set leads to undefined state of Rc0 */
5481 GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON)
5483 #if defined(CONFIG_USER_ONLY)
5484 GEN_EXCP_PRIVOPC(ctx);
5486 if (unlikely(!ctx->supervisor)) {
5487 GEN_EXCP_PRIVOPC(ctx);
5490 /* interpreted as no-op */
5495 GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON)
5497 #if defined(CONFIG_USER_ONLY)
5498 GEN_EXCP_PRIVOPC(ctx);
5501 if (unlikely(!ctx->supervisor)) {
5502 GEN_EXCP_PRIVOPC(ctx);
5505 EA = tcg_temp_new(TCG_TYPE_TL);
5506 gen_addr_reg_index(EA, ctx);
5507 val = tcg_temp_new(TCG_TYPE_TL);
5508 gen_qemu_ld32u(val, EA, ctx->mem_idx);
5510 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA);
5516 GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT)
5518 /* interpreted as no-op */
5519 /* XXX: specification say this is treated as a load by the MMU
5520 * but does not generate any exception
5525 GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON)
5527 #if defined(CONFIG_USER_ONLY)
5528 GEN_EXCP_PRIVOPC(ctx);
5530 if (unlikely(!ctx->supervisor)) {
5531 GEN_EXCP_PRIVOPC(ctx);
5534 /* interpreted as no-op */
5539 GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON)
5541 #if defined(CONFIG_USER_ONLY)
5542 GEN_EXCP_PRIVOPC(ctx);
5544 if (unlikely(!ctx->supervisor)) {
5545 GEN_EXCP_PRIVOPC(ctx);
5548 /* interpreted as no-op */
5552 /* rfci (supervisor only) */
5553 GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP)
5555 #if defined(CONFIG_USER_ONLY)
5556 GEN_EXCP_PRIVOPC(ctx);
5558 if (unlikely(!ctx->supervisor)) {
5559 GEN_EXCP_PRIVOPC(ctx);
5562 /* Restore CPU state */
5568 GEN_HANDLER(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE)
5570 #if defined(CONFIG_USER_ONLY)
5571 GEN_EXCP_PRIVOPC(ctx);
5573 if (unlikely(!ctx->supervisor)) {
5574 GEN_EXCP_PRIVOPC(ctx);
5577 /* Restore CPU state */
5583 /* BookE specific */
5584 /* XXX: not implemented on 440 ? */
5585 GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI)
5587 #if defined(CONFIG_USER_ONLY)
5588 GEN_EXCP_PRIVOPC(ctx);
5590 if (unlikely(!ctx->supervisor)) {
5591 GEN_EXCP_PRIVOPC(ctx);
5594 /* Restore CPU state */
5600 /* XXX: not implemented on 440 ? */
5601 GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI)
5603 #if defined(CONFIG_USER_ONLY)
5604 GEN_EXCP_PRIVOPC(ctx);
5606 if (unlikely(!ctx->supervisor)) {
5607 GEN_EXCP_PRIVOPC(ctx);
5610 /* Restore CPU state */
5616 /* TLB management - PowerPC 405 implementation */
5618 GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB)
5620 #if defined(CONFIG_USER_ONLY)
5621 GEN_EXCP_PRIVOPC(ctx);
5623 if (unlikely(!ctx->supervisor)) {
5624 GEN_EXCP_PRIVOPC(ctx);
5627 switch (rB(ctx->opcode)) {
5629 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5630 gen_op_4xx_tlbre_hi();
5631 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5634 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5635 gen_op_4xx_tlbre_lo();
5636 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5639 GEN_EXCP_INVAL(ctx);
5645 /* tlbsx - tlbsx. */
5646 GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB)
5648 #if defined(CONFIG_USER_ONLY)
5649 GEN_EXCP_PRIVOPC(ctx);
5651 if (unlikely(!ctx->supervisor)) {
5652 GEN_EXCP_PRIVOPC(ctx);
5655 gen_addr_reg_index(cpu_T[0], ctx);
5657 if (Rc(ctx->opcode))
5658 gen_op_4xx_tlbsx_check();
5659 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5664 GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB)
5666 #if defined(CONFIG_USER_ONLY)
5667 GEN_EXCP_PRIVOPC(ctx);
5669 if (unlikely(!ctx->supervisor)) {
5670 GEN_EXCP_PRIVOPC(ctx);
5673 switch (rB(ctx->opcode)) {
5675 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5676 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5677 gen_op_4xx_tlbwe_hi();
5680 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5681 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5682 gen_op_4xx_tlbwe_lo();
5685 GEN_EXCP_INVAL(ctx);
5691 /* TLB management - PowerPC 440 implementation */
5693 GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE)
5695 #if defined(CONFIG_USER_ONLY)
5696 GEN_EXCP_PRIVOPC(ctx);
5698 if (unlikely(!ctx->supervisor)) {
5699 GEN_EXCP_PRIVOPC(ctx);
5702 switch (rB(ctx->opcode)) {
5706 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5707 gen_op_440_tlbre(rB(ctx->opcode));
5708 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5711 GEN_EXCP_INVAL(ctx);
5717 /* tlbsx - tlbsx. */
5718 GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE)
5720 #if defined(CONFIG_USER_ONLY)
5721 GEN_EXCP_PRIVOPC(ctx);
5723 if (unlikely(!ctx->supervisor)) {
5724 GEN_EXCP_PRIVOPC(ctx);
5727 gen_addr_reg_index(cpu_T[0], ctx);
5729 if (Rc(ctx->opcode))
5730 gen_op_4xx_tlbsx_check();
5731 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
5736 GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE)
5738 #if defined(CONFIG_USER_ONLY)
5739 GEN_EXCP_PRIVOPC(ctx);
5741 if (unlikely(!ctx->supervisor)) {
5742 GEN_EXCP_PRIVOPC(ctx);
5745 switch (rB(ctx->opcode)) {
5749 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
5750 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]);
5751 gen_op_440_tlbwe(rB(ctx->opcode));
5754 GEN_EXCP_INVAL(ctx);
5761 GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE)
5763 #if defined(CONFIG_USER_ONLY)
5764 GEN_EXCP_PRIVOPC(ctx);
5766 if (unlikely(!ctx->supervisor)) {
5767 GEN_EXCP_PRIVOPC(ctx);
5770 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rD(ctx->opcode)]);
5772 /* Stop translation to have a chance to raise an exception
5773 * if we just set msr_ee to 1
5780 GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000EFC01, PPC_WRTEE)
5782 #if defined(CONFIG_USER_ONLY)
5783 GEN_EXCP_PRIVOPC(ctx);
5785 if (unlikely(!ctx->supervisor)) {
5786 GEN_EXCP_PRIVOPC(ctx);
5789 tcg_gen_movi_tl(cpu_T[0], ctx->opcode & 0x00010000);
5791 /* Stop translation to have a chance to raise an exception
5792 * if we just set msr_ee to 1
5798 /* PowerPC 440 specific instructions */
5800 GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC)
5802 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]);
5803 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
5805 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]);
5806 tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F);
5807 tcg_gen_or_tl(cpu_xer, cpu_xer, cpu_T[0]);
5808 if (Rc(ctx->opcode)) {
5809 gen_op_440_dlmzb_update_Rc();
5810 tcg_gen_andi_i32(cpu_crf[0], cpu_T[0], 0xf);
5814 /* mbar replaces eieio on 440 */
5815 GEN_HANDLER(mbar, 0x1F, 0x16, 0x13, 0x001FF801, PPC_BOOKE)
5817 /* interpreted as no-op */
5820 /* msync replaces sync on 440 */
5821 GEN_HANDLER(msync, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE)
5823 /* interpreted as no-op */
5827 GEN_HANDLER2(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001, PPC_BOOKE)
5829 /* interpreted as no-op */
5830 /* XXX: specification say this is treated as a load by the MMU
5831 * but does not generate any exception
5835 /*** Altivec vector extension ***/
5836 /* Altivec registers moves */
5838 static always_inline void gen_load_avr(int t, int reg) {
5839 tcg_gen_mov_i64(cpu_AVRh[t], cpu_avrh[reg]);
5840 tcg_gen_mov_i64(cpu_AVRl[t], cpu_avrl[reg]);
5843 static always_inline void gen_store_avr(int reg, int t) {
5844 tcg_gen_mov_i64(cpu_avrh[reg], cpu_AVRh[t]);
5845 tcg_gen_mov_i64(cpu_avrl[reg], cpu_AVRl[t]);
5848 #define op_vr_ldst(name) (*gen_op_##name[ctx->mem_idx])()
5849 #define OP_VR_LD_TABLE(name) \
5850 static GenOpFunc *gen_op_vr_l##name[NB_MEM_FUNCS] = { \
5851 GEN_MEM_FUNCS(vr_l##name), \
5853 #define OP_VR_ST_TABLE(name) \
5854 static GenOpFunc *gen_op_vr_st##name[NB_MEM_FUNCS] = { \
5855 GEN_MEM_FUNCS(vr_st##name), \
5858 #define GEN_VR_LDX(name, opc2, opc3) \
5859 GEN_HANDLER(l##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
5861 if (unlikely(!ctx->altivec_enabled)) { \
5862 GEN_EXCP_NO_VR(ctx); \
5865 gen_addr_reg_index(cpu_T[0], ctx); \
5866 op_vr_ldst(vr_l##name); \
5867 gen_store_avr(rD(ctx->opcode), 0); \
5870 #define GEN_VR_STX(name, opc2, opc3) \
5871 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
5873 if (unlikely(!ctx->altivec_enabled)) { \
5874 GEN_EXCP_NO_VR(ctx); \
5877 gen_addr_reg_index(cpu_T[0], ctx); \
5878 gen_load_avr(0, rS(ctx->opcode)); \
5879 op_vr_ldst(vr_st##name); \
5883 GEN_VR_LDX(vx, 0x07, 0x03);
5884 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
5885 #define gen_op_vr_lvxl gen_op_vr_lvx
5886 GEN_VR_LDX(vxl, 0x07, 0x0B);
5889 GEN_VR_STX(vx, 0x07, 0x07);
5890 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
5891 #define gen_op_vr_stvxl gen_op_vr_stvx
5892 GEN_VR_STX(vxl, 0x07, 0x0F);
5894 /*** SPE extension ***/
5895 /* Register moves */
5897 static always_inline void gen_load_gpr64(TCGv t, int reg) {
5898 #if defined(TARGET_PPC64)
5899 tcg_gen_mov_i64(t, cpu_gpr[reg]);
5901 tcg_gen_concat_i32_i64(t, cpu_gpr[reg], cpu_gprh[reg]);
5905 static always_inline void gen_store_gpr64(int reg, TCGv t) {
5906 #if defined(TARGET_PPC64)
5907 tcg_gen_mov_i64(cpu_gpr[reg], t);
5909 tcg_gen_trunc_i64_i32(cpu_gpr[reg], t);
5910 TCGv tmp = tcg_temp_new(TCG_TYPE_I64);
5911 tcg_gen_shri_i64(tmp, t, 32);
5912 tcg_gen_trunc_i64_i32(cpu_gprh[reg], tmp);
5917 #define GEN_SPE(name0, name1, opc2, opc3, inval, type) \
5918 GEN_HANDLER(name0##_##name1, 0x04, opc2, opc3, inval, type) \
5920 if (Rc(ctx->opcode)) \
5926 /* Handler for undefined SPE opcodes */
5927 static always_inline void gen_speundef (DisasContext *ctx)
5929 GEN_EXCP_INVAL(ctx);
5932 /* SPE load and stores */
5933 static always_inline void gen_addr_spe_imm_index (TCGv EA, DisasContext *ctx, int sh)
5935 target_long simm = rB(ctx->opcode);
5937 if (rA(ctx->opcode) == 0)
5938 tcg_gen_movi_tl(EA, simm << sh);
5939 else if (likely(simm != 0))
5940 tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm << sh);
5942 tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]);
5945 #define op_spe_ldst(name) (*gen_op_##name[ctx->mem_idx])()
5946 #define OP_SPE_LD_TABLE(name) \
5947 static GenOpFunc *gen_op_spe_l##name[NB_MEM_FUNCS] = { \
5948 GEN_MEM_FUNCS(spe_l##name), \
5950 #define OP_SPE_ST_TABLE(name) \
5951 static GenOpFunc *gen_op_spe_st##name[NB_MEM_FUNCS] = { \
5952 GEN_MEM_FUNCS(spe_st##name), \
5955 #define GEN_SPE_LD(name, sh) \
5956 static always_inline void gen_evl##name (DisasContext *ctx) \
5958 if (unlikely(!ctx->spe_enabled)) { \
5959 GEN_EXCP_NO_AP(ctx); \
5962 gen_addr_spe_imm_index(cpu_T[0], ctx, sh); \
5963 op_spe_ldst(spe_l##name); \
5964 gen_store_gpr64(rD(ctx->opcode), cpu_T64[1]); \
5967 #define GEN_SPE_LDX(name) \
5968 static always_inline void gen_evl##name##x (DisasContext *ctx) \
5970 if (unlikely(!ctx->spe_enabled)) { \
5971 GEN_EXCP_NO_AP(ctx); \
5974 gen_addr_reg_index(cpu_T[0], ctx); \
5975 op_spe_ldst(spe_l##name); \
5976 gen_store_gpr64(rD(ctx->opcode), cpu_T64[1]); \
5979 #define GEN_SPEOP_LD(name, sh) \
5980 OP_SPE_LD_TABLE(name); \
5981 GEN_SPE_LD(name, sh); \
5984 #define GEN_SPE_ST(name, sh) \
5985 static always_inline void gen_evst##name (DisasContext *ctx) \
5987 if (unlikely(!ctx->spe_enabled)) { \
5988 GEN_EXCP_NO_AP(ctx); \
5991 gen_addr_spe_imm_index(cpu_T[0], ctx, sh); \
5992 gen_load_gpr64(cpu_T64[1], rS(ctx->opcode)); \
5993 op_spe_ldst(spe_st##name); \
5996 #define GEN_SPE_STX(name) \
5997 static always_inline void gen_evst##name##x (DisasContext *ctx) \
5999 if (unlikely(!ctx->spe_enabled)) { \
6000 GEN_EXCP_NO_AP(ctx); \
6003 gen_addr_reg_index(cpu_T[0], ctx); \
6004 gen_load_gpr64(cpu_T64[1], rS(ctx->opcode)); \
6005 op_spe_ldst(spe_st##name); \
6008 #define GEN_SPEOP_ST(name, sh) \
6009 OP_SPE_ST_TABLE(name); \
6010 GEN_SPE_ST(name, sh); \
6013 #define GEN_SPEOP_LDST(name, sh) \
6014 GEN_SPEOP_LD(name, sh); \
6015 GEN_SPEOP_ST(name, sh)
6017 /* SPE arithmetic and logic */
6018 #define GEN_SPEOP_ARITH2(name) \
6019 static always_inline void gen_##name (DisasContext *ctx) \
6021 if (unlikely(!ctx->spe_enabled)) { \
6022 GEN_EXCP_NO_AP(ctx); \
6025 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode)); \
6026 gen_load_gpr64(cpu_T64[1], rB(ctx->opcode)); \
6028 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
6031 #define GEN_SPEOP_TCG_ARITH2(name, tcg_op) \
6032 static always_inline void gen_##name (DisasContext *ctx) \
6034 if (unlikely(!ctx->spe_enabled)) { \
6035 GEN_EXCP_NO_AP(ctx); \
6038 TCGv t0 = tcg_temp_new(TCG_TYPE_I64); \
6039 TCGv t1 = tcg_temp_new(TCG_TYPE_I64); \
6040 gen_load_gpr64(t0, rA(ctx->opcode)); \
6041 gen_load_gpr64(t1, rB(ctx->opcode)); \
6042 tcg_op(t0, t0, t1); \
6043 gen_store_gpr64(rD(ctx->opcode), t0); \
6044 tcg_temp_free(t0); \
6045 tcg_temp_free(t1); \
6048 #define GEN_SPEOP_ARITH1(name) \
6049 static always_inline void gen_##name (DisasContext *ctx) \
6051 if (unlikely(!ctx->spe_enabled)) { \
6052 GEN_EXCP_NO_AP(ctx); \
6055 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode)); \
6057 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
6060 #define GEN_SPEOP_COMP(name) \
6061 static always_inline void gen_##name (DisasContext *ctx) \
6063 if (unlikely(!ctx->spe_enabled)) { \
6064 GEN_EXCP_NO_AP(ctx); \
6067 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode)); \
6068 gen_load_gpr64(cpu_T64[1], rB(ctx->opcode)); \
6070 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_T[0], 0xf); \
6074 GEN_SPEOP_TCG_ARITH2(evand, tcg_gen_and_i64);
6075 GEN_SPEOP_TCG_ARITH2(evandc, tcg_gen_andc_i64);
6076 GEN_SPEOP_TCG_ARITH2(evxor, tcg_gen_xor_i64);
6077 GEN_SPEOP_TCG_ARITH2(evor, tcg_gen_or_i64);
6078 GEN_SPEOP_TCG_ARITH2(evnor, tcg_gen_nor_i64);
6079 GEN_SPEOP_TCG_ARITH2(eveqv, tcg_gen_eqv_i64);
6080 GEN_SPEOP_TCG_ARITH2(evorc, tcg_gen_orc_i64);
6081 GEN_SPEOP_TCG_ARITH2(evnand, tcg_gen_nand_i64);
6082 GEN_SPEOP_ARITH2(evsrwu);
6083 GEN_SPEOP_ARITH2(evsrws);
6084 GEN_SPEOP_ARITH2(evslw);
6085 GEN_SPEOP_ARITH2(evrlw);
6086 GEN_SPEOP_ARITH2(evmergehi);
6087 GEN_SPEOP_ARITH2(evmergelo);
6088 GEN_SPEOP_ARITH2(evmergehilo);
6089 GEN_SPEOP_ARITH2(evmergelohi);
6092 GEN_SPEOP_ARITH2(evaddw);
6093 GEN_SPEOP_ARITH2(evsubfw);
6094 GEN_SPEOP_ARITH1(evabs);
6095 GEN_SPEOP_ARITH1(evneg);
6096 GEN_SPEOP_ARITH1(evextsb);
6097 GEN_SPEOP_ARITH1(evextsh);
6098 GEN_SPEOP_ARITH1(evrndw);
6099 GEN_SPEOP_ARITH1(evcntlzw);
6100 GEN_SPEOP_ARITH1(evcntlsw);
6101 static always_inline void gen_brinc (DisasContext *ctx)
6103 /* Note: brinc is usable even if SPE is disabled */
6104 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]);
6105 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]);
6107 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]);
6110 #define GEN_SPEOP_ARITH_IMM2(name) \
6111 static always_inline void gen_##name##i (DisasContext *ctx) \
6113 if (unlikely(!ctx->spe_enabled)) { \
6114 GEN_EXCP_NO_AP(ctx); \
6117 gen_load_gpr64(cpu_T64[0], rB(ctx->opcode)); \
6118 gen_op_splatwi_T1_64(rA(ctx->opcode)); \
6120 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
6123 #define GEN_SPEOP_LOGIC_IMM2(name) \
6124 static always_inline void gen_##name##i (DisasContext *ctx) \
6126 if (unlikely(!ctx->spe_enabled)) { \
6127 GEN_EXCP_NO_AP(ctx); \
6130 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode)); \
6131 gen_op_splatwi_T1_64(rB(ctx->opcode)); \
6133 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
6136 GEN_SPEOP_ARITH_IMM2(evaddw);
6137 #define gen_evaddiw gen_evaddwi
6138 GEN_SPEOP_ARITH_IMM2(evsubfw);
6139 #define gen_evsubifw gen_evsubfwi
6140 GEN_SPEOP_LOGIC_IMM2(evslw);
6141 GEN_SPEOP_LOGIC_IMM2(evsrwu);
6142 #define gen_evsrwis gen_evsrwsi
6143 GEN_SPEOP_LOGIC_IMM2(evsrws);
6144 #define gen_evsrwiu gen_evsrwui
6145 GEN_SPEOP_LOGIC_IMM2(evrlw);
6147 static always_inline void gen_evsplati (DisasContext *ctx)
6149 int32_t imm = (int32_t)(rA(ctx->opcode) << 27) >> 27;
6151 gen_op_splatwi_T0_64(imm);
6152 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]);
6155 static always_inline void gen_evsplatfi (DisasContext *ctx)
6157 uint32_t imm = rA(ctx->opcode) << 27;
6159 gen_op_splatwi_T0_64(imm);
6160 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]);
6164 GEN_SPEOP_COMP(evcmpgtu);
6165 GEN_SPEOP_COMP(evcmpgts);
6166 GEN_SPEOP_COMP(evcmpltu);
6167 GEN_SPEOP_COMP(evcmplts);
6168 GEN_SPEOP_COMP(evcmpeq);
6170 GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, PPC_SPE); ////
6171 GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, PPC_SPE);
6172 GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, PPC_SPE); ////
6173 GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, PPC_SPE);
6174 GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, PPC_SPE); ////
6175 GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, PPC_SPE); ////
6176 GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, PPC_SPE); ////
6177 GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x00000000, PPC_SPE); //
6178 GEN_SPE(speundef, evand, 0x08, 0x08, 0x00000000, PPC_SPE); ////
6179 GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, PPC_SPE); ////
6180 GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, PPC_SPE); ////
6181 GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, PPC_SPE); ////
6182 GEN_SPE(speundef, evorc, 0x0D, 0x08, 0x00000000, PPC_SPE); ////
6183 GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, PPC_SPE); ////
6184 GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, PPC_SPE); ////
6185 GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, PPC_SPE);
6186 GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, PPC_SPE); ////
6187 GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, PPC_SPE);
6188 GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, PPC_SPE); //
6189 GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, PPC_SPE);
6190 GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, PPC_SPE); ////
6191 GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, PPC_SPE); ////
6192 GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, PPC_SPE); ////
6193 GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, PPC_SPE); ////
6194 GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, PPC_SPE); ////
6196 static always_inline void gen_evsel (DisasContext *ctx)
6198 if (unlikely(!ctx->spe_enabled)) {
6199 GEN_EXCP_NO_AP(ctx);
6202 tcg_gen_mov_i32(cpu_T[0], cpu_crf[ctx->opcode & 0x7]);
6203 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode));
6204 gen_load_gpr64(cpu_T64[1], rB(ctx->opcode));
6206 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]);
6209 GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE)
6213 GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE)
6217 GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE)
6221 GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE)
6226 /* Load and stores */
6227 GEN_SPEOP_LDST(dd, 3);
6228 GEN_SPEOP_LDST(dw, 3);
6229 GEN_SPEOP_LDST(dh, 3);
6230 GEN_SPEOP_LDST(whe, 2);
6231 GEN_SPEOP_LD(whou, 2);
6232 GEN_SPEOP_LD(whos, 2);
6233 GEN_SPEOP_ST(who, 2);
6235 #define _GEN_OP_SPE_STWWE(suffix) \
6236 static always_inline void gen_op_spe_stwwe_##suffix (void) \
6238 gen_op_srli32_T1_64(); \
6239 gen_op_spe_stwwo_##suffix(); \
6241 #define _GEN_OP_SPE_STWWE_LE(suffix) \
6242 static always_inline void gen_op_spe_stwwe_le_##suffix (void) \
6244 gen_op_srli32_T1_64(); \
6245 gen_op_spe_stwwo_le_##suffix(); \
6247 #if defined(TARGET_PPC64)
6248 #define GEN_OP_SPE_STWWE(suffix) \
6249 _GEN_OP_SPE_STWWE(suffix); \
6250 _GEN_OP_SPE_STWWE_LE(suffix); \
6251 static always_inline void gen_op_spe_stwwe_64_##suffix (void) \
6253 gen_op_srli32_T1_64(); \
6254 gen_op_spe_stwwo_64_##suffix(); \
6256 static always_inline void gen_op_spe_stwwe_le_64_##suffix (void) \
6258 gen_op_srli32_T1_64(); \
6259 gen_op_spe_stwwo_le_64_##suffix(); \
6262 #define GEN_OP_SPE_STWWE(suffix) \
6263 _GEN_OP_SPE_STWWE(suffix); \
6264 _GEN_OP_SPE_STWWE_LE(suffix)
6266 #if defined(CONFIG_USER_ONLY)
6267 GEN_OP_SPE_STWWE(raw);
6268 #else /* defined(CONFIG_USER_ONLY) */
6269 GEN_OP_SPE_STWWE(user);
6270 GEN_OP_SPE_STWWE(kernel);
6271 GEN_OP_SPE_STWWE(hypv);
6272 #endif /* defined(CONFIG_USER_ONLY) */
6273 GEN_SPEOP_ST(wwe, 2);
6274 GEN_SPEOP_ST(wwo, 2);
6276 #define GEN_SPE_LDSPLAT(name, op, suffix) \
6277 static always_inline void gen_op_spe_l##name##_##suffix (void) \
6279 gen_op_##op##_##suffix(); \
6280 gen_op_splatw_T1_64(); \
6283 #define GEN_OP_SPE_LHE(suffix) \
6284 static always_inline void gen_op_spe_lhe_##suffix (void) \
6286 gen_op_spe_lh_##suffix(); \
6287 gen_op_sli16_T1_64(); \
6290 #define GEN_OP_SPE_LHX(suffix) \
6291 static always_inline void gen_op_spe_lhx_##suffix (void) \
6293 gen_op_spe_lh_##suffix(); \
6294 gen_op_extsh_T1_64(); \
6297 #if defined(CONFIG_USER_ONLY)
6298 GEN_OP_SPE_LHE(raw);
6299 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, raw);
6300 GEN_OP_SPE_LHE(le_raw);
6301 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_raw);
6302 GEN_SPE_LDSPLAT(hhousplat, spe_lh, raw);
6303 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_raw);
6304 GEN_OP_SPE_LHX(raw);
6305 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, raw);
6306 GEN_OP_SPE_LHX(le_raw);
6307 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_raw);
6308 #if defined(TARGET_PPC64)
6309 GEN_OP_SPE_LHE(64_raw);
6310 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_raw);
6311 GEN_OP_SPE_LHE(le_64_raw);
6312 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_raw);
6313 GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_raw);
6314 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_raw);
6315 GEN_OP_SPE_LHX(64_raw);
6316 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_raw);
6317 GEN_OP_SPE_LHX(le_64_raw);
6318 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_raw);
6321 GEN_OP_SPE_LHE(user);
6322 GEN_OP_SPE_LHE(kernel);
6323 GEN_OP_SPE_LHE(hypv);
6324 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, user);
6325 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, kernel);
6326 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, hypv);
6327 GEN_OP_SPE_LHE(le_user);
6328 GEN_OP_SPE_LHE(le_kernel);
6329 GEN_OP_SPE_LHE(le_hypv);
6330 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_user);
6331 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_kernel);
6332 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_hypv);
6333 GEN_SPE_LDSPLAT(hhousplat, spe_lh, user);
6334 GEN_SPE_LDSPLAT(hhousplat, spe_lh, kernel);
6335 GEN_SPE_LDSPLAT(hhousplat, spe_lh, hypv);
6336 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_user);
6337 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_kernel);
6338 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_hypv);
6339 GEN_OP_SPE_LHX(user);
6340 GEN_OP_SPE_LHX(kernel);
6341 GEN_OP_SPE_LHX(hypv);
6342 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, user);
6343 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, kernel);
6344 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, hypv);
6345 GEN_OP_SPE_LHX(le_user);
6346 GEN_OP_SPE_LHX(le_kernel);
6347 GEN_OP_SPE_LHX(le_hypv);
6348 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_user);
6349 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_kernel);
6350 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_hypv);
6351 #if defined(TARGET_PPC64)
6352 GEN_OP_SPE_LHE(64_user);
6353 GEN_OP_SPE_LHE(64_kernel);
6354 GEN_OP_SPE_LHE(64_hypv);
6355 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_user);
6356 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_kernel);
6357 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_hypv);
6358 GEN_OP_SPE_LHE(le_64_user);
6359 GEN_OP_SPE_LHE(le_64_kernel);
6360 GEN_OP_SPE_LHE(le_64_hypv);
6361 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_user);
6362 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_kernel);
6363 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_hypv);
6364 GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_user);
6365 GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_kernel);
6366 GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_hypv);
6367 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_user);
6368 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_kernel);
6369 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_hypv);
6370 GEN_OP_SPE_LHX(64_user);
6371 GEN_OP_SPE_LHX(64_kernel);
6372 GEN_OP_SPE_LHX(64_hypv);
6373 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_user);
6374 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_kernel);
6375 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_hypv);
6376 GEN_OP_SPE_LHX(le_64_user);
6377 GEN_OP_SPE_LHX(le_64_kernel);
6378 GEN_OP_SPE_LHX(le_64_hypv);
6379 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_user);
6380 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_kernel);
6381 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_hypv);
6384 GEN_SPEOP_LD(hhesplat, 1);
6385 GEN_SPEOP_LD(hhousplat, 1);
6386 GEN_SPEOP_LD(hhossplat, 1);
6387 GEN_SPEOP_LD(wwsplat, 2);
6388 GEN_SPEOP_LD(whsplat, 2);
6390 GEN_SPE(evlddx, evldd, 0x00, 0x0C, 0x00000000, PPC_SPE); //
6391 GEN_SPE(evldwx, evldw, 0x01, 0x0C, 0x00000000, PPC_SPE); //
6392 GEN_SPE(evldhx, evldh, 0x02, 0x0C, 0x00000000, PPC_SPE); //
6393 GEN_SPE(evlhhesplatx, evlhhesplat, 0x04, 0x0C, 0x00000000, PPC_SPE); //
6394 GEN_SPE(evlhhousplatx, evlhhousplat, 0x06, 0x0C, 0x00000000, PPC_SPE); //
6395 GEN_SPE(evlhhossplatx, evlhhossplat, 0x07, 0x0C, 0x00000000, PPC_SPE); //
6396 GEN_SPE(evlwhex, evlwhe, 0x08, 0x0C, 0x00000000, PPC_SPE); //
6397 GEN_SPE(evlwhoux, evlwhou, 0x0A, 0x0C, 0x00000000, PPC_SPE); //
6398 GEN_SPE(evlwhosx, evlwhos, 0x0B, 0x0C, 0x00000000, PPC_SPE); //
6399 GEN_SPE(evlwwsplatx, evlwwsplat, 0x0C, 0x0C, 0x00000000, PPC_SPE); //
6400 GEN_SPE(evlwhsplatx, evlwhsplat, 0x0E, 0x0C, 0x00000000, PPC_SPE); //
6401 GEN_SPE(evstddx, evstdd, 0x10, 0x0C, 0x00000000, PPC_SPE); //
6402 GEN_SPE(evstdwx, evstdw, 0x11, 0x0C, 0x00000000, PPC_SPE); //
6403 GEN_SPE(evstdhx, evstdh, 0x12, 0x0C, 0x00000000, PPC_SPE); //
6404 GEN_SPE(evstwhex, evstwhe, 0x18, 0x0C, 0x00000000, PPC_SPE); //
6405 GEN_SPE(evstwhox, evstwho, 0x1A, 0x0C, 0x00000000, PPC_SPE); //
6406 GEN_SPE(evstwwex, evstwwe, 0x1C, 0x0C, 0x00000000, PPC_SPE); //
6407 GEN_SPE(evstwwox, evstwwo, 0x1E, 0x0C, 0x00000000, PPC_SPE); //
6409 /* Multiply and add - TODO */
6411 GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0x00000000, PPC_SPE);
6412 GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0x00000000, PPC_SPE);
6413 GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, PPC_SPE);
6414 GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0x00000000, PPC_SPE);
6415 GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, PPC_SPE);
6416 GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0x00000000, PPC_SPE);
6417 GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0x00000000, PPC_SPE);
6418 GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0x00000000, PPC_SPE);
6419 GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, PPC_SPE);
6420 GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0x00000000, PPC_SPE);
6421 GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, PPC_SPE);
6422 GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0x00000000, PPC_SPE);
6424 GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0x00000000, PPC_SPE);
6425 GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, PPC_SPE);
6426 GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, PPC_SPE);
6427 GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0x00000000, PPC_SPE);
6428 GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0x00000000, PPC_SPE);
6429 GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, PPC_SPE);
6430 GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0x00000000, PPC_SPE);
6431 GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0x00000000, PPC_SPE);
6432 GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, PPC_SPE);
6433 GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, PPC_SPE);
6434 GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0x00000000, PPC_SPE);
6435 GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0x00000000, PPC_SPE);
6436 GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, PPC_SPE);
6437 GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0x00000000, PPC_SPE);
6439 GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, PPC_SPE);
6440 GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, PPC_SPE);
6441 GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, PPC_SPE);
6442 GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, PPC_SPE);
6443 GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, PPC_SPE);
6444 GEN_SPE(evmra, speundef, 0x07, 0x13, 0x0000F800, PPC_SPE);
6446 GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, PPC_SPE);
6447 GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0x00000000, PPC_SPE);
6448 GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, PPC_SPE);
6449 GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0x00000000, PPC_SPE);
6450 GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, PPC_SPE);
6451 GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0x00000000, PPC_SPE);
6452 GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, PPC_SPE);
6453 GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0x00000000, PPC_SPE);
6454 GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, PPC_SPE);
6455 GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0x00000000, PPC_SPE);
6456 GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, PPC_SPE);
6457 GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0x00000000, PPC_SPE);
6459 GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, PPC_SPE);
6460 GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, PPC_SPE);
6461 GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0x00000000, PPC_SPE);
6462 GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, PPC_SPE);
6463 GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0x00000000, PPC_SPE);
6465 GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, PPC_SPE);
6466 GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0x00000000, PPC_SPE);
6467 GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, PPC_SPE);
6468 GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0x00000000, PPC_SPE);
6469 GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, PPC_SPE);
6470 GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0x00000000, PPC_SPE);
6471 GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, PPC_SPE);
6472 GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0x00000000, PPC_SPE);
6473 GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, PPC_SPE);
6474 GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0x00000000, PPC_SPE);
6475 GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, PPC_SPE);
6476 GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0x00000000, PPC_SPE);
6478 GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, PPC_SPE);
6479 GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, PPC_SPE);
6480 GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0x00000000, PPC_SPE);
6481 GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, PPC_SPE);
6482 GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0x00000000, PPC_SPE);
6485 /*** SPE floating-point extension ***/
6486 #define GEN_SPEFPUOP_CONV(name) \
6487 static always_inline void gen_##name (DisasContext *ctx) \
6489 gen_load_gpr64(cpu_T64[0], rB(ctx->opcode)); \
6491 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
6494 /* Single precision floating-point vectors operations */
6496 GEN_SPEOP_ARITH2(evfsadd);
6497 GEN_SPEOP_ARITH2(evfssub);
6498 GEN_SPEOP_ARITH2(evfsmul);
6499 GEN_SPEOP_ARITH2(evfsdiv);
6500 GEN_SPEOP_ARITH1(evfsabs);
6501 GEN_SPEOP_ARITH1(evfsnabs);
6502 GEN_SPEOP_ARITH1(evfsneg);
6504 GEN_SPEFPUOP_CONV(evfscfui);
6505 GEN_SPEFPUOP_CONV(evfscfsi);
6506 GEN_SPEFPUOP_CONV(evfscfuf);
6507 GEN_SPEFPUOP_CONV(evfscfsf);
6508 GEN_SPEFPUOP_CONV(evfsctui);
6509 GEN_SPEFPUOP_CONV(evfsctsi);
6510 GEN_SPEFPUOP_CONV(evfsctuf);
6511 GEN_SPEFPUOP_CONV(evfsctsf);
6512 GEN_SPEFPUOP_CONV(evfsctuiz);
6513 GEN_SPEFPUOP_CONV(evfsctsiz);
6515 GEN_SPEOP_COMP(evfscmpgt);
6516 GEN_SPEOP_COMP(evfscmplt);
6517 GEN_SPEOP_COMP(evfscmpeq);
6518 GEN_SPEOP_COMP(evfststgt);
6519 GEN_SPEOP_COMP(evfststlt);
6520 GEN_SPEOP_COMP(evfststeq);
6522 /* Opcodes definitions */
6523 GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, PPC_SPEFPU); //
6524 GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, PPC_SPEFPU); //
6525 GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, PPC_SPEFPU); //
6526 GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, PPC_SPEFPU); //
6527 GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, PPC_SPEFPU); //
6528 GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, PPC_SPEFPU); //
6529 GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, PPC_SPEFPU); //
6530 GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, PPC_SPEFPU); //
6531 GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, PPC_SPEFPU); //
6532 GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, PPC_SPEFPU); //
6533 GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, PPC_SPEFPU); //
6534 GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, PPC_SPEFPU); //
6535 GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, PPC_SPEFPU); //
6536 GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, PPC_SPEFPU); //
6538 /* Single precision floating-point operations */
6540 GEN_SPEOP_ARITH2(efsadd);
6541 GEN_SPEOP_ARITH2(efssub);
6542 GEN_SPEOP_ARITH2(efsmul);
6543 GEN_SPEOP_ARITH2(efsdiv);
6544 GEN_SPEOP_ARITH1(efsabs);
6545 GEN_SPEOP_ARITH1(efsnabs);
6546 GEN_SPEOP_ARITH1(efsneg);
6548 GEN_SPEFPUOP_CONV(efscfui);
6549 GEN_SPEFPUOP_CONV(efscfsi);
6550 GEN_SPEFPUOP_CONV(efscfuf);
6551 GEN_SPEFPUOP_CONV(efscfsf);
6552 GEN_SPEFPUOP_CONV(efsctui);
6553 GEN_SPEFPUOP_CONV(efsctsi);
6554 GEN_SPEFPUOP_CONV(efsctuf);
6555 GEN_SPEFPUOP_CONV(efsctsf);
6556 GEN_SPEFPUOP_CONV(efsctuiz);
6557 GEN_SPEFPUOP_CONV(efsctsiz);
6558 GEN_SPEFPUOP_CONV(efscfd);
6560 GEN_SPEOP_COMP(efscmpgt);
6561 GEN_SPEOP_COMP(efscmplt);
6562 GEN_SPEOP_COMP(efscmpeq);
6563 GEN_SPEOP_COMP(efststgt);
6564 GEN_SPEOP_COMP(efststlt);
6565 GEN_SPEOP_COMP(efststeq);
6567 /* Opcodes definitions */
6568 GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, PPC_SPEFPU); //
6569 GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, PPC_SPEFPU); //
6570 GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, PPC_SPEFPU); //
6571 GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, PPC_SPEFPU); //
6572 GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, PPC_SPEFPU); //
6573 GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, PPC_SPEFPU); //
6574 GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, PPC_SPEFPU); //
6575 GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, PPC_SPEFPU); //
6576 GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, PPC_SPEFPU); //
6577 GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, PPC_SPEFPU); //
6578 GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, PPC_SPEFPU); //
6579 GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, PPC_SPEFPU); //
6580 GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, PPC_SPEFPU); //
6581 GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, PPC_SPEFPU); //
6583 /* Double precision floating-point operations */
6585 GEN_SPEOP_ARITH2(efdadd);
6586 GEN_SPEOP_ARITH2(efdsub);
6587 GEN_SPEOP_ARITH2(efdmul);
6588 GEN_SPEOP_ARITH2(efddiv);
6589 GEN_SPEOP_ARITH1(efdabs);
6590 GEN_SPEOP_ARITH1(efdnabs);
6591 GEN_SPEOP_ARITH1(efdneg);
6594 GEN_SPEFPUOP_CONV(efdcfui);
6595 GEN_SPEFPUOP_CONV(efdcfsi);
6596 GEN_SPEFPUOP_CONV(efdcfuf);
6597 GEN_SPEFPUOP_CONV(efdcfsf);
6598 GEN_SPEFPUOP_CONV(efdctui);
6599 GEN_SPEFPUOP_CONV(efdctsi);
6600 GEN_SPEFPUOP_CONV(efdctuf);
6601 GEN_SPEFPUOP_CONV(efdctsf);
6602 GEN_SPEFPUOP_CONV(efdctuiz);
6603 GEN_SPEFPUOP_CONV(efdctsiz);
6604 GEN_SPEFPUOP_CONV(efdcfs);
6605 GEN_SPEFPUOP_CONV(efdcfuid);
6606 GEN_SPEFPUOP_CONV(efdcfsid);
6607 GEN_SPEFPUOP_CONV(efdctuidz);
6608 GEN_SPEFPUOP_CONV(efdctsidz);
6610 GEN_SPEOP_COMP(efdcmpgt);
6611 GEN_SPEOP_COMP(efdcmplt);
6612 GEN_SPEOP_COMP(efdcmpeq);
6613 GEN_SPEOP_COMP(efdtstgt);
6614 GEN_SPEOP_COMP(efdtstlt);
6615 GEN_SPEOP_COMP(efdtsteq);
6617 /* Opcodes definitions */
6618 GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, PPC_SPEFPU); //
6619 GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, PPC_SPEFPU); //
6620 GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, PPC_SPEFPU); //
6621 GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, PPC_SPEFPU); //
6622 GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, PPC_SPEFPU); //
6623 GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, PPC_SPEFPU); //
6624 GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, PPC_SPEFPU); //
6625 GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, PPC_SPEFPU); //
6626 GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, PPC_SPEFPU); //
6627 GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, PPC_SPEFPU); //
6628 GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, PPC_SPEFPU); //
6629 GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, PPC_SPEFPU); //
6630 GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, PPC_SPEFPU); //
6631 GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, PPC_SPEFPU); //
6632 GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, PPC_SPEFPU); //
6633 GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, PPC_SPEFPU); //
6635 /* End opcode list */
6636 GEN_OPCODE_MARK(end);
6638 #include "translate_init.c"
6639 #include "helper_regs.h"
6641 /*****************************************************************************/
6642 /* Misc PowerPC helpers */
6643 void cpu_dump_state (CPUState *env, FILE *f,
6644 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
6652 cpu_fprintf(f, "NIP " ADDRX " LR " ADDRX " CTR " ADDRX " XER %08x\n",
6653 env->nip, env->lr, env->ctr, env->xer);
6654 cpu_fprintf(f, "MSR " ADDRX " HID0 " ADDRX " HF " ADDRX " idx %d\n",
6655 env->msr, env->spr[SPR_HID0], env->hflags, env->mmu_idx);
6656 #if !defined(NO_TIMER_DUMP)
6657 cpu_fprintf(f, "TB %08x %08x "
6658 #if !defined(CONFIG_USER_ONLY)
6662 cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
6663 #if !defined(CONFIG_USER_ONLY)
6664 , cpu_ppc_load_decr(env)
6668 for (i = 0; i < 32; i++) {
6669 if ((i & (RGPL - 1)) == 0)
6670 cpu_fprintf(f, "GPR%02d", i);
6671 cpu_fprintf(f, " " REGX, ppc_dump_gpr(env, i));
6672 if ((i & (RGPL - 1)) == (RGPL - 1))
6673 cpu_fprintf(f, "\n");
6675 cpu_fprintf(f, "CR ");
6676 for (i = 0; i < 8; i++)
6677 cpu_fprintf(f, "%01x", env->crf[i]);
6678 cpu_fprintf(f, " [");
6679 for (i = 0; i < 8; i++) {
6681 if (env->crf[i] & 0x08)
6683 else if (env->crf[i] & 0x04)
6685 else if (env->crf[i] & 0x02)
6687 cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
6689 cpu_fprintf(f, " ] RES " ADDRX "\n", env->reserve);
6690 for (i = 0; i < 32; i++) {
6691 if ((i & (RFPL - 1)) == 0)
6692 cpu_fprintf(f, "FPR%02d", i);
6693 cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
6694 if ((i & (RFPL - 1)) == (RFPL - 1))
6695 cpu_fprintf(f, "\n");
6697 #if !defined(CONFIG_USER_ONLY)
6698 cpu_fprintf(f, "SRR0 " ADDRX " SRR1 " ADDRX " SDR1 " ADDRX "\n",
6699 env->spr[SPR_SRR0], env->spr[SPR_SRR1], env->sdr1);
6706 void cpu_dump_statistics (CPUState *env, FILE*f,
6707 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
6710 #if defined(DO_PPC_STATISTICS)
6711 opc_handler_t **t1, **t2, **t3, *handler;
6715 for (op1 = 0; op1 < 64; op1++) {
6717 if (is_indirect_opcode(handler)) {
6718 t2 = ind_table(handler);
6719 for (op2 = 0; op2 < 32; op2++) {
6721 if (is_indirect_opcode(handler)) {
6722 t3 = ind_table(handler);
6723 for (op3 = 0; op3 < 32; op3++) {
6725 if (handler->count == 0)
6727 cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
6729 op1, op2, op3, op1, (op3 << 5) | op2,
6731 handler->count, handler->count);
6734 if (handler->count == 0)
6736 cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: "
6738 op1, op2, op1, op2, handler->oname,
6739 handler->count, handler->count);
6743 if (handler->count == 0)
6745 cpu_fprintf(f, "%02x (%02x ) %16s: %016llx %lld\n",
6746 op1, op1, handler->oname,
6747 handler->count, handler->count);
6753 /*****************************************************************************/
6754 static always_inline void gen_intermediate_code_internal (CPUState *env,
6755 TranslationBlock *tb,
6758 DisasContext ctx, *ctxp = &ctx;
6759 opc_handler_t **table, *handler;
6760 target_ulong pc_start;
6761 uint16_t *gen_opc_end;
6762 int supervisor, little_endian;
6768 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
6769 #if defined(OPTIMIZE_FPRF_UPDATE)
6770 gen_fprf_ptr = gen_fprf_buf;
6774 ctx.exception = POWERPC_EXCP_NONE;
6775 ctx.spr_cb = env->spr_cb;
6776 supervisor = env->mmu_idx;
6777 #if !defined(CONFIG_USER_ONLY)
6778 ctx.supervisor = supervisor;
6780 little_endian = env->hflags & (1 << MSR_LE) ? 1 : 0;
6781 #if defined(TARGET_PPC64)
6782 ctx.sf_mode = msr_sf;
6783 ctx.mem_idx = (supervisor << 2) | (msr_sf << 1) | little_endian;
6785 ctx.mem_idx = (supervisor << 1) | little_endian;
6787 ctx.dcache_line_size = env->dcache_line_size;
6788 ctx.fpu_enabled = msr_fp;
6789 if ((env->flags & POWERPC_FLAG_SPE) && msr_spe)
6790 ctx.spe_enabled = msr_spe;
6792 ctx.spe_enabled = 0;
6793 if ((env->flags & POWERPC_FLAG_VRE) && msr_vr)
6794 ctx.altivec_enabled = msr_vr;
6796 ctx.altivec_enabled = 0;
6797 if ((env->flags & POWERPC_FLAG_SE) && msr_se)
6798 ctx.singlestep_enabled = CPU_SINGLE_STEP;
6800 ctx.singlestep_enabled = 0;
6801 if ((env->flags & POWERPC_FLAG_BE) && msr_be)
6802 ctx.singlestep_enabled |= CPU_BRANCH_STEP;
6803 if (unlikely(env->singlestep_enabled))
6804 ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP;
6805 #if defined (DO_SINGLE_STEP) && 0
6806 /* Single step trace mode */
6810 max_insns = tb->cflags & CF_COUNT_MASK;
6812 max_insns = CF_COUNT_MASK;
6815 /* Set env in case of segfault during code fetch */
6816 while (ctx.exception == POWERPC_EXCP_NONE && gen_opc_ptr < gen_opc_end) {
6817 if (unlikely(env->nb_breakpoints > 0)) {
6818 for (j = 0; j < env->nb_breakpoints; j++) {
6819 if (env->breakpoints[j] == ctx.nip) {
6820 gen_update_nip(&ctx, ctx.nip);
6826 if (unlikely(search_pc)) {
6827 j = gen_opc_ptr - gen_opc_buf;
6831 gen_opc_instr_start[lj++] = 0;
6832 gen_opc_pc[lj] = ctx.nip;
6833 gen_opc_instr_start[lj] = 1;
6834 gen_opc_icount[lj] = num_insns;
6837 #if defined PPC_DEBUG_DISAS
6838 if (loglevel & CPU_LOG_TB_IN_ASM) {
6839 fprintf(logfile, "----------------\n");
6840 fprintf(logfile, "nip=" ADDRX " super=%d ir=%d\n",
6841 ctx.nip, supervisor, (int)msr_ir);
6844 if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO))
6846 if (unlikely(little_endian)) {
6847 ctx.opcode = bswap32(ldl_code(ctx.nip));
6849 ctx.opcode = ldl_code(ctx.nip);
6851 #if defined PPC_DEBUG_DISAS
6852 if (loglevel & CPU_LOG_TB_IN_ASM) {
6853 fprintf(logfile, "translate opcode %08x (%02x %02x %02x) (%s)\n",
6854 ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
6855 opc3(ctx.opcode), little_endian ? "little" : "big");
6859 table = env->opcodes;
6861 handler = table[opc1(ctx.opcode)];
6862 if (is_indirect_opcode(handler)) {
6863 table = ind_table(handler);
6864 handler = table[opc2(ctx.opcode)];
6865 if (is_indirect_opcode(handler)) {
6866 table = ind_table(handler);
6867 handler = table[opc3(ctx.opcode)];
6870 /* Is opcode *REALLY* valid ? */
6871 if (unlikely(handler->handler == &gen_invalid)) {
6872 if (loglevel != 0) {
6873 fprintf(logfile, "invalid/unsupported opcode: "
6874 "%02x - %02x - %02x (%08x) " ADDRX " %d\n",
6875 opc1(ctx.opcode), opc2(ctx.opcode),
6876 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
6878 printf("invalid/unsupported opcode: "
6879 "%02x - %02x - %02x (%08x) " ADDRX " %d\n",
6880 opc1(ctx.opcode), opc2(ctx.opcode),
6881 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir);
6884 if (unlikely((ctx.opcode & handler->inval) != 0)) {
6885 if (loglevel != 0) {
6886 fprintf(logfile, "invalid bits: %08x for opcode: "
6887 "%02x - %02x - %02x (%08x) " ADDRX "\n",
6888 ctx.opcode & handler->inval, opc1(ctx.opcode),
6889 opc2(ctx.opcode), opc3(ctx.opcode),
6890 ctx.opcode, ctx.nip - 4);
6892 printf("invalid bits: %08x for opcode: "
6893 "%02x - %02x - %02x (%08x) " ADDRX "\n",
6894 ctx.opcode & handler->inval, opc1(ctx.opcode),
6895 opc2(ctx.opcode), opc3(ctx.opcode),
6896 ctx.opcode, ctx.nip - 4);
6898 GEN_EXCP_INVAL(ctxp);
6902 (*(handler->handler))(&ctx);
6903 #if defined(DO_PPC_STATISTICS)
6906 /* Check trace mode exceptions */
6907 if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP &&
6908 (ctx.nip <= 0x100 || ctx.nip > 0xF00) &&
6909 ctx.exception != POWERPC_SYSCALL &&
6910 ctx.exception != POWERPC_EXCP_TRAP &&
6911 ctx.exception != POWERPC_EXCP_BRANCH)) {
6912 GEN_EXCP(ctxp, POWERPC_EXCP_TRACE, 0);
6913 } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
6914 (env->singlestep_enabled) ||
6915 num_insns >= max_insns)) {
6916 /* if we reach a page boundary or are single stepping, stop
6921 #if defined (DO_SINGLE_STEP)
6925 if (tb->cflags & CF_LAST_IO)
6927 if (ctx.exception == POWERPC_EXCP_NONE) {
6928 gen_goto_tb(&ctx, 0, ctx.nip);
6929 } else if (ctx.exception != POWERPC_EXCP_BRANCH) {
6930 if (unlikely(env->singlestep_enabled)) {
6931 gen_update_nip(&ctx, ctx.nip);
6934 /* Generate the return instruction */
6937 gen_icount_end(tb, num_insns);
6938 *gen_opc_ptr = INDEX_op_end;
6939 if (unlikely(search_pc)) {
6940 j = gen_opc_ptr - gen_opc_buf;
6943 gen_opc_instr_start[lj++] = 0;
6945 tb->size = ctx.nip - pc_start;
6946 tb->icount = num_insns;
6948 #if defined(DEBUG_DISAS)
6949 if (loglevel & CPU_LOG_TB_CPU) {
6950 fprintf(logfile, "---------------- excp: %04x\n", ctx.exception);
6951 cpu_dump_state(env, logfile, fprintf, 0);
6953 if (loglevel & CPU_LOG_TB_IN_ASM) {
6955 flags = env->bfd_mach;
6956 flags |= little_endian << 16;
6957 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
6958 target_disas(logfile, pc_start, ctx.nip - pc_start, flags);
6959 fprintf(logfile, "\n");
6964 void gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
6966 gen_intermediate_code_internal(env, tb, 0);
6969 void gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
6971 gen_intermediate_code_internal(env, tb, 1);
6974 void gen_pc_load(CPUState *env, TranslationBlock *tb,
6975 unsigned long searched_pc, int pc_pos, void *puc)
6978 /* for PPC, we need to look at the micro operation to get the
6980 env->nip = gen_opc_pc[pc_pos];
6981 c = gen_opc_buf[pc_pos];
6983 #if defined(CONFIG_USER_ONLY)
6985 case INDEX_op_ ## op ## _raw
6988 case INDEX_op_ ## op ## _user:\
6989 case INDEX_op_ ## op ## _kernel:\
6990 case INDEX_op_ ## op ## _hypv
6997 type = ACCESS_FLOAT;
7013 env->access_type = type;