2 * PowerPC emulation for qemu: main translation routines.
4 * Copyright (c) 2003-2007 Jocelyn Mayer
5 * Copyright (C) 2011 Freescale Semiconductor, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 #include "disas/disas.h"
24 #include "qemu/host-utils.h"
25 #include "exec/cpu_ldst.h"
27 #include "exec/helper-proto.h"
28 #include "exec/helper-gen.h"
30 #include "trace-tcg.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 PPC_DEBUG_DISAS
39 //#define DO_PPC_STATISTICS
41 #ifdef PPC_DEBUG_DISAS
42 # define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
44 # define LOG_DISAS(...) do { } while (0)
46 /*****************************************************************************/
47 /* Code translation helpers */
49 /* global register indexes */
50 static TCGv_ptr cpu_env
;
51 static char cpu_reg_names
[10*3 + 22*4 /* GPR */
52 + 10*4 + 22*5 /* SPE GPRh */
53 + 10*4 + 22*5 /* FPR */
54 + 2*(10*6 + 22*7) /* AVRh, AVRl */
55 + 10*5 + 22*6 /* VSR */
57 static TCGv cpu_gpr
[32];
58 static TCGv cpu_gprh
[32];
59 static TCGv_i64 cpu_fpr
[32];
60 static TCGv_i64 cpu_avrh
[32], cpu_avrl
[32];
61 static TCGv_i64 cpu_vsr
[32];
62 static TCGv_i32 cpu_crf
[8];
67 #if defined(TARGET_PPC64)
70 static TCGv cpu_xer
, cpu_so
, cpu_ov
, cpu_ca
;
71 static TCGv cpu_reserve
;
72 static TCGv cpu_fpscr
;
73 static TCGv_i32 cpu_access_type
;
75 #include "exec/gen-icount.h"
77 void ppc_translate_init(void)
81 size_t cpu_reg_names_size
;
82 static int done_init
= 0;
87 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
90 cpu_reg_names_size
= sizeof(cpu_reg_names
);
92 for (i
= 0; i
< 8; i
++) {
93 snprintf(p
, cpu_reg_names_size
, "crf%d", i
);
94 cpu_crf
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
95 offsetof(CPUPPCState
, crf
[i
]), p
);
97 cpu_reg_names_size
-= 5;
100 for (i
= 0; i
< 32; i
++) {
101 snprintf(p
, cpu_reg_names_size
, "r%d", i
);
102 cpu_gpr
[i
] = tcg_global_mem_new(TCG_AREG0
,
103 offsetof(CPUPPCState
, gpr
[i
]), p
);
104 p
+= (i
< 10) ? 3 : 4;
105 cpu_reg_names_size
-= (i
< 10) ? 3 : 4;
106 snprintf(p
, cpu_reg_names_size
, "r%dH", i
);
107 cpu_gprh
[i
] = tcg_global_mem_new(TCG_AREG0
,
108 offsetof(CPUPPCState
, gprh
[i
]), p
);
109 p
+= (i
< 10) ? 4 : 5;
110 cpu_reg_names_size
-= (i
< 10) ? 4 : 5;
112 snprintf(p
, cpu_reg_names_size
, "fp%d", i
);
113 cpu_fpr
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
114 offsetof(CPUPPCState
, fpr
[i
]), p
);
115 p
+= (i
< 10) ? 4 : 5;
116 cpu_reg_names_size
-= (i
< 10) ? 4 : 5;
118 snprintf(p
, cpu_reg_names_size
, "avr%dH", i
);
119 #ifdef HOST_WORDS_BIGENDIAN
120 cpu_avrh
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
121 offsetof(CPUPPCState
, avr
[i
].u64
[0]), p
);
123 cpu_avrh
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
124 offsetof(CPUPPCState
, avr
[i
].u64
[1]), p
);
126 p
+= (i
< 10) ? 6 : 7;
127 cpu_reg_names_size
-= (i
< 10) ? 6 : 7;
129 snprintf(p
, cpu_reg_names_size
, "avr%dL", i
);
130 #ifdef HOST_WORDS_BIGENDIAN
131 cpu_avrl
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
132 offsetof(CPUPPCState
, avr
[i
].u64
[1]), p
);
134 cpu_avrl
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
135 offsetof(CPUPPCState
, avr
[i
].u64
[0]), p
);
137 p
+= (i
< 10) ? 6 : 7;
138 cpu_reg_names_size
-= (i
< 10) ? 6 : 7;
139 snprintf(p
, cpu_reg_names_size
, "vsr%d", i
);
140 cpu_vsr
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
141 offsetof(CPUPPCState
, vsr
[i
]), p
);
142 p
+= (i
< 10) ? 5 : 6;
143 cpu_reg_names_size
-= (i
< 10) ? 5 : 6;
146 cpu_nip
= tcg_global_mem_new(TCG_AREG0
,
147 offsetof(CPUPPCState
, nip
), "nip");
149 cpu_msr
= tcg_global_mem_new(TCG_AREG0
,
150 offsetof(CPUPPCState
, msr
), "msr");
152 cpu_ctr
= tcg_global_mem_new(TCG_AREG0
,
153 offsetof(CPUPPCState
, ctr
), "ctr");
155 cpu_lr
= tcg_global_mem_new(TCG_AREG0
,
156 offsetof(CPUPPCState
, lr
), "lr");
158 #if defined(TARGET_PPC64)
159 cpu_cfar
= tcg_global_mem_new(TCG_AREG0
,
160 offsetof(CPUPPCState
, cfar
), "cfar");
163 cpu_xer
= tcg_global_mem_new(TCG_AREG0
,
164 offsetof(CPUPPCState
, xer
), "xer");
165 cpu_so
= tcg_global_mem_new(TCG_AREG0
,
166 offsetof(CPUPPCState
, so
), "SO");
167 cpu_ov
= tcg_global_mem_new(TCG_AREG0
,
168 offsetof(CPUPPCState
, ov
), "OV");
169 cpu_ca
= tcg_global_mem_new(TCG_AREG0
,
170 offsetof(CPUPPCState
, ca
), "CA");
172 cpu_reserve
= tcg_global_mem_new(TCG_AREG0
,
173 offsetof(CPUPPCState
, reserve_addr
),
176 cpu_fpscr
= tcg_global_mem_new(TCG_AREG0
,
177 offsetof(CPUPPCState
, fpscr
), "fpscr");
179 cpu_access_type
= tcg_global_mem_new_i32(TCG_AREG0
,
180 offsetof(CPUPPCState
, access_type
), "access_type");
185 /* internal defines */
186 struct DisasContext
{
187 struct TranslationBlock
*tb
;
191 /* Routine used to access memory */
195 /* Translation flags */
197 TCGMemOp default_tcg_memop_mask
;
198 #if defined(TARGET_PPC64)
207 ppc_spr_t
*spr_cb
; /* Needed to check rights for mfspr/mtspr */
208 int singlestep_enabled
;
209 uint64_t insns_flags
;
210 uint64_t insns_flags2
;
213 /* Return true iff byteswap is needed in a scalar memop */
214 static inline bool need_byteswap(const DisasContext
*ctx
)
216 #if defined(TARGET_WORDS_BIGENDIAN)
219 return !ctx
->le_mode
;
223 /* True when active word size < size of target_long. */
225 # define NARROW_MODE(C) (!(C)->sf_mode)
227 # define NARROW_MODE(C) 0
230 struct opc_handler_t
{
231 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
233 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
235 /* instruction type */
237 /* extended instruction type */
240 void (*handler
)(DisasContext
*ctx
);
241 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
244 #if defined(DO_PPC_STATISTICS)
249 static inline void gen_reset_fpstatus(void)
251 gen_helper_reset_fpstatus(cpu_env
);
254 static inline void gen_compute_fprf(TCGv_i64 arg
)
256 gen_helper_compute_fprf(cpu_env
, arg
);
257 gen_helper_float_check_status(cpu_env
);
260 static inline void gen_set_access_type(DisasContext
*ctx
, int access_type
)
262 if (ctx
->access_type
!= access_type
) {
263 tcg_gen_movi_i32(cpu_access_type
, access_type
);
264 ctx
->access_type
= access_type
;
268 static inline void gen_update_nip(DisasContext
*ctx
, target_ulong nip
)
270 if (NARROW_MODE(ctx
)) {
273 tcg_gen_movi_tl(cpu_nip
, nip
);
276 void gen_update_current_nip(void *opaque
)
278 DisasContext
*ctx
= opaque
;
280 tcg_gen_movi_tl(cpu_nip
, ctx
->nip
);
283 static inline void gen_exception_err(DisasContext
*ctx
, uint32_t excp
, uint32_t error
)
286 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
287 gen_update_nip(ctx
, ctx
->nip
);
289 t0
= tcg_const_i32(excp
);
290 t1
= tcg_const_i32(error
);
291 gen_helper_raise_exception_err(cpu_env
, t0
, t1
);
292 tcg_temp_free_i32(t0
);
293 tcg_temp_free_i32(t1
);
294 ctx
->exception
= (excp
);
297 static inline void gen_exception(DisasContext
*ctx
, uint32_t excp
)
300 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
301 gen_update_nip(ctx
, ctx
->nip
);
303 t0
= tcg_const_i32(excp
);
304 gen_helper_raise_exception(cpu_env
, t0
);
305 tcg_temp_free_i32(t0
);
306 ctx
->exception
= (excp
);
309 static inline void gen_debug_exception(DisasContext
*ctx
)
313 if ((ctx
->exception
!= POWERPC_EXCP_BRANCH
) &&
314 (ctx
->exception
!= POWERPC_EXCP_SYNC
)) {
315 gen_update_nip(ctx
, ctx
->nip
);
317 t0
= tcg_const_i32(EXCP_DEBUG
);
318 gen_helper_raise_exception(cpu_env
, t0
);
319 tcg_temp_free_i32(t0
);
322 static inline void gen_inval_exception(DisasContext
*ctx
, uint32_t error
)
324 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_INVAL
| error
);
327 /* Stop translation */
328 static inline void gen_stop_exception(DisasContext
*ctx
)
330 gen_update_nip(ctx
, ctx
->nip
);
331 ctx
->exception
= POWERPC_EXCP_STOP
;
334 #ifndef CONFIG_USER_ONLY
335 /* No need to update nip here, as execution flow will change */
336 static inline void gen_sync_exception(DisasContext
*ctx
)
338 ctx
->exception
= POWERPC_EXCP_SYNC
;
342 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
343 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
345 #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
346 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
348 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
349 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
351 #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
352 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
354 typedef struct opcode_t
{
355 unsigned char opc1
, opc2
, opc3
;
356 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
357 unsigned char pad
[5];
359 unsigned char pad
[1];
361 opc_handler_t handler
;
365 /*****************************************************************************/
366 /*** Instruction decoding ***/
367 #define EXTRACT_HELPER(name, shift, nb) \
368 static inline uint32_t name(uint32_t opcode) \
370 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
373 #define EXTRACT_SHELPER(name, shift, nb) \
374 static inline int32_t name(uint32_t opcode) \
376 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
379 #define EXTRACT_HELPER_SPLIT(name, shift1, nb1, shift2, nb2) \
380 static inline uint32_t name(uint32_t opcode) \
382 return (((opcode >> (shift1)) & ((1 << (nb1)) - 1)) << nb2) | \
383 ((opcode >> (shift2)) & ((1 << (nb2)) - 1)); \
386 EXTRACT_HELPER(opc1
, 26, 6);
388 EXTRACT_HELPER(opc2
, 1, 5);
390 EXTRACT_HELPER(opc3
, 6, 5);
391 /* Update Cr0 flags */
392 EXTRACT_HELPER(Rc
, 0, 1);
393 /* Update Cr6 flags (Altivec) */
394 EXTRACT_HELPER(Rc21
, 10, 1);
396 EXTRACT_HELPER(rD
, 21, 5);
398 EXTRACT_HELPER(rS
, 21, 5);
400 EXTRACT_HELPER(rA
, 16, 5);
402 EXTRACT_HELPER(rB
, 11, 5);
404 EXTRACT_HELPER(rC
, 6, 5);
406 EXTRACT_HELPER(crfD
, 23, 3);
407 EXTRACT_HELPER(crfS
, 18, 3);
408 EXTRACT_HELPER(crbD
, 21, 5);
409 EXTRACT_HELPER(crbA
, 16, 5);
410 EXTRACT_HELPER(crbB
, 11, 5);
412 EXTRACT_HELPER(_SPR
, 11, 10);
413 static inline uint32_t SPR(uint32_t opcode
)
415 uint32_t sprn
= _SPR(opcode
);
417 return ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
419 /*** Get constants ***/
420 /* 16 bits signed immediate value */
421 EXTRACT_SHELPER(SIMM
, 0, 16);
422 /* 16 bits unsigned immediate value */
423 EXTRACT_HELPER(UIMM
, 0, 16);
424 /* 5 bits signed immediate value */
425 EXTRACT_HELPER(SIMM5
, 16, 5);
426 /* 5 bits signed immediate value */
427 EXTRACT_HELPER(UIMM5
, 16, 5);
429 EXTRACT_HELPER(NB
, 11, 5);
431 EXTRACT_HELPER(SH
, 11, 5);
432 /* Vector shift count */
433 EXTRACT_HELPER(VSH
, 6, 4);
435 EXTRACT_HELPER(MB
, 6, 5);
437 EXTRACT_HELPER(ME
, 1, 5);
439 EXTRACT_HELPER(TO
, 21, 5);
441 EXTRACT_HELPER(CRM
, 12, 8);
443 #ifndef CONFIG_USER_ONLY
444 EXTRACT_HELPER(SR
, 16, 4);
448 EXTRACT_HELPER(FPBF
, 23, 3);
449 EXTRACT_HELPER(FPIMM
, 12, 4);
450 EXTRACT_HELPER(FPL
, 25, 1);
451 EXTRACT_HELPER(FPFLM
, 17, 8);
452 EXTRACT_HELPER(FPW
, 16, 1);
454 /*** Jump target decoding ***/
455 /* Immediate address */
456 static inline target_ulong
LI(uint32_t opcode
)
458 return (opcode
>> 0) & 0x03FFFFFC;
461 static inline uint32_t BD(uint32_t opcode
)
463 return (opcode
>> 0) & 0xFFFC;
466 EXTRACT_HELPER(BO
, 21, 5);
467 EXTRACT_HELPER(BI
, 16, 5);
468 /* Absolute/relative address */
469 EXTRACT_HELPER(AA
, 1, 1);
471 EXTRACT_HELPER(LK
, 0, 1);
474 EXTRACT_HELPER(DCM
, 10, 6)
477 EXTRACT_HELPER(RMC
, 9, 2)
479 /* Create a mask between <start> and <end> bits */
480 static inline target_ulong
MASK(uint32_t start
, uint32_t end
)
484 #if defined(TARGET_PPC64)
485 if (likely(start
== 0)) {
486 ret
= UINT64_MAX
<< (63 - end
);
487 } else if (likely(end
== 63)) {
488 ret
= UINT64_MAX
>> start
;
491 if (likely(start
== 0)) {
492 ret
= UINT32_MAX
<< (31 - end
);
493 } else if (likely(end
== 31)) {
494 ret
= UINT32_MAX
>> start
;
498 ret
= (((target_ulong
)(-1ULL)) >> (start
)) ^
499 (((target_ulong
)(-1ULL) >> (end
)) >> 1);
500 if (unlikely(start
> end
))
507 EXTRACT_HELPER_SPLIT(xT
, 0, 1, 21, 5);
508 EXTRACT_HELPER_SPLIT(xS
, 0, 1, 21, 5);
509 EXTRACT_HELPER_SPLIT(xA
, 2, 1, 16, 5);
510 EXTRACT_HELPER_SPLIT(xB
, 1, 1, 11, 5);
511 EXTRACT_HELPER_SPLIT(xC
, 3, 1, 6, 5);
512 EXTRACT_HELPER(DM
, 8, 2);
513 EXTRACT_HELPER(UIM
, 16, 2);
514 EXTRACT_HELPER(SHW
, 8, 2);
515 EXTRACT_HELPER(SP
, 19, 2);
516 /*****************************************************************************/
517 /* PowerPC instructions table */
519 #if defined(DO_PPC_STATISTICS)
520 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
530 .handler = &gen_##name, \
531 .oname = stringify(name), \
533 .oname = stringify(name), \
535 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
546 .handler = &gen_##name, \
547 .oname = stringify(name), \
549 .oname = stringify(name), \
551 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
561 .handler = &gen_##name, \
567 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
577 .handler = &gen_##name, \
579 .oname = stringify(name), \
581 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
592 .handler = &gen_##name, \
594 .oname = stringify(name), \
596 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
606 .handler = &gen_##name, \
612 /* SPR load/store helpers */
613 static inline void gen_load_spr(TCGv t
, int reg
)
615 tcg_gen_ld_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
618 static inline void gen_store_spr(int reg
, TCGv t
)
620 tcg_gen_st_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
623 /* Invalid instruction */
624 static void gen_invalid(DisasContext
*ctx
)
626 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
629 static opc_handler_t invalid_handler
= {
630 .inval1
= 0xFFFFFFFF,
631 .inval2
= 0xFFFFFFFF,
634 .handler
= gen_invalid
,
637 /*** Integer comparison ***/
639 static inline void gen_op_cmp(TCGv arg0
, TCGv arg1
, int s
, int crf
)
641 TCGv t0
= tcg_temp_new();
642 TCGv_i32 t1
= tcg_temp_new_i32();
644 tcg_gen_trunc_tl_i32(cpu_crf
[crf
], cpu_so
);
646 tcg_gen_setcond_tl((s
? TCG_COND_LT
: TCG_COND_LTU
), t0
, arg0
, arg1
);
647 tcg_gen_trunc_tl_i32(t1
, t0
);
648 tcg_gen_shli_i32(t1
, t1
, CRF_LT
);
649 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
651 tcg_gen_setcond_tl((s
? TCG_COND_GT
: TCG_COND_GTU
), t0
, arg0
, arg1
);
652 tcg_gen_trunc_tl_i32(t1
, t0
);
653 tcg_gen_shli_i32(t1
, t1
, CRF_GT
);
654 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
656 tcg_gen_setcond_tl(TCG_COND_EQ
, t0
, arg0
, arg1
);
657 tcg_gen_trunc_tl_i32(t1
, t0
);
658 tcg_gen_shli_i32(t1
, t1
, CRF_EQ
);
659 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
662 tcg_temp_free_i32(t1
);
665 static inline void gen_op_cmpi(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
667 TCGv t0
= tcg_const_tl(arg1
);
668 gen_op_cmp(arg0
, t0
, s
, crf
);
672 static inline void gen_op_cmp32(TCGv arg0
, TCGv arg1
, int s
, int crf
)
678 tcg_gen_ext32s_tl(t0
, arg0
);
679 tcg_gen_ext32s_tl(t1
, arg1
);
681 tcg_gen_ext32u_tl(t0
, arg0
);
682 tcg_gen_ext32u_tl(t1
, arg1
);
684 gen_op_cmp(t0
, t1
, s
, crf
);
689 static inline void gen_op_cmpi32(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
691 TCGv t0
= tcg_const_tl(arg1
);
692 gen_op_cmp32(arg0
, t0
, s
, crf
);
696 static inline void gen_set_Rc0(DisasContext
*ctx
, TCGv reg
)
698 if (NARROW_MODE(ctx
)) {
699 gen_op_cmpi32(reg
, 0, 1, 0);
701 gen_op_cmpi(reg
, 0, 1, 0);
706 static void gen_cmp(DisasContext
*ctx
)
708 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
709 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
710 1, crfD(ctx
->opcode
));
712 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
713 1, crfD(ctx
->opcode
));
718 static void gen_cmpi(DisasContext
*ctx
)
720 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
721 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
722 1, crfD(ctx
->opcode
));
724 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
725 1, crfD(ctx
->opcode
));
730 static void gen_cmpl(DisasContext
*ctx
)
732 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
733 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
734 0, crfD(ctx
->opcode
));
736 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
737 0, crfD(ctx
->opcode
));
742 static void gen_cmpli(DisasContext
*ctx
)
744 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
745 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
746 0, crfD(ctx
->opcode
));
748 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
749 0, crfD(ctx
->opcode
));
753 /* isel (PowerPC 2.03 specification) */
754 static void gen_isel(DisasContext
*ctx
)
757 uint32_t bi
= rC(ctx
->opcode
);
761 l1
= gen_new_label();
762 l2
= gen_new_label();
764 mask
= 0x08 >> (bi
& 0x03);
765 t0
= tcg_temp_new_i32();
766 tcg_gen_andi_i32(t0
, cpu_crf
[bi
>> 2], mask
);
767 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
768 if (rA(ctx
->opcode
) == 0)
769 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
771 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
774 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
776 tcg_temp_free_i32(t0
);
779 /* cmpb: PowerPC 2.05 specification */
780 static void gen_cmpb(DisasContext
*ctx
)
782 gen_helper_cmpb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
783 cpu_gpr
[rB(ctx
->opcode
)]);
786 /*** Integer arithmetic ***/
788 static inline void gen_op_arith_compute_ov(DisasContext
*ctx
, TCGv arg0
,
789 TCGv arg1
, TCGv arg2
, int sub
)
791 TCGv t0
= tcg_temp_new();
793 tcg_gen_xor_tl(cpu_ov
, arg0
, arg2
);
794 tcg_gen_xor_tl(t0
, arg1
, arg2
);
796 tcg_gen_and_tl(cpu_ov
, cpu_ov
, t0
);
798 tcg_gen_andc_tl(cpu_ov
, cpu_ov
, t0
);
801 if (NARROW_MODE(ctx
)) {
802 tcg_gen_ext32s_tl(cpu_ov
, cpu_ov
);
804 tcg_gen_shri_tl(cpu_ov
, cpu_ov
, TARGET_LONG_BITS
- 1);
805 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
808 /* Common add function */
809 static inline void gen_op_arith_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
810 TCGv arg2
, bool add_ca
, bool compute_ca
,
811 bool compute_ov
, bool compute_rc0
)
815 if (compute_ca
|| compute_ov
) {
820 if (NARROW_MODE(ctx
)) {
821 /* Caution: a non-obvious corner case of the spec is that we
822 must produce the *entire* 64-bit addition, but produce the
823 carry into bit 32. */
824 TCGv t1
= tcg_temp_new();
825 tcg_gen_xor_tl(t1
, arg1
, arg2
); /* add without carry */
826 tcg_gen_add_tl(t0
, arg1
, arg2
);
828 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
830 tcg_gen_xor_tl(cpu_ca
, t0
, t1
); /* bits changed w/ carry */
832 tcg_gen_shri_tl(cpu_ca
, cpu_ca
, 32); /* extract bit 32 */
833 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
835 TCGv zero
= tcg_const_tl(0);
837 tcg_gen_add2_tl(t0
, cpu_ca
, arg1
, zero
, cpu_ca
, zero
);
838 tcg_gen_add2_tl(t0
, cpu_ca
, t0
, cpu_ca
, arg2
, zero
);
840 tcg_gen_add2_tl(t0
, cpu_ca
, arg1
, zero
, arg2
, zero
);
845 tcg_gen_add_tl(t0
, arg1
, arg2
);
847 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
852 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 0);
854 if (unlikely(compute_rc0
)) {
855 gen_set_Rc0(ctx
, t0
);
858 if (!TCGV_EQUAL(t0
, ret
)) {
859 tcg_gen_mov_tl(ret
, t0
);
863 /* Add functions with two operands */
864 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
865 static void glue(gen_, name)(DisasContext *ctx) \
867 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
868 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
869 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
871 /* Add functions with one operand and one immediate */
872 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
873 add_ca, compute_ca, compute_ov) \
874 static void glue(gen_, name)(DisasContext *ctx) \
876 TCGv t0 = tcg_const_tl(const_val); \
877 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
878 cpu_gpr[rA(ctx->opcode)], t0, \
879 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
883 /* add add. addo addo. */
884 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
885 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
886 /* addc addc. addco addco. */
887 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
888 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
889 /* adde adde. addeo addeo. */
890 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
891 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
892 /* addme addme. addmeo addmeo. */
893 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
894 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
895 /* addze addze. addzeo addzeo.*/
896 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
897 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
899 static void gen_addi(DisasContext
*ctx
)
901 target_long simm
= SIMM(ctx
->opcode
);
903 if (rA(ctx
->opcode
) == 0) {
905 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
);
907 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)],
908 cpu_gpr
[rA(ctx
->opcode
)], simm
);
912 static inline void gen_op_addic(DisasContext
*ctx
, bool compute_rc0
)
914 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
915 gen_op_arith_add(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
916 c
, 0, 1, 0, compute_rc0
);
920 static void gen_addic(DisasContext
*ctx
)
922 gen_op_addic(ctx
, 0);
925 static void gen_addic_(DisasContext
*ctx
)
927 gen_op_addic(ctx
, 1);
931 static void gen_addis(DisasContext
*ctx
)
933 target_long simm
= SIMM(ctx
->opcode
);
935 if (rA(ctx
->opcode
) == 0) {
937 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
<< 16);
939 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)],
940 cpu_gpr
[rA(ctx
->opcode
)], simm
<< 16);
944 static inline void gen_op_arith_divw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
945 TCGv arg2
, int sign
, int compute_ov
)
947 TCGLabel
*l1
= gen_new_label();
948 TCGLabel
*l2
= gen_new_label();
949 TCGv_i32 t0
= tcg_temp_local_new_i32();
950 TCGv_i32 t1
= tcg_temp_local_new_i32();
952 tcg_gen_trunc_tl_i32(t0
, arg1
);
953 tcg_gen_trunc_tl_i32(t1
, arg2
);
954 tcg_gen_brcondi_i32(TCG_COND_EQ
, t1
, 0, l1
);
956 TCGLabel
*l3
= gen_new_label();
957 tcg_gen_brcondi_i32(TCG_COND_NE
, t1
, -1, l3
);
958 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, INT32_MIN
, l1
);
960 tcg_gen_div_i32(t0
, t0
, t1
);
962 tcg_gen_divu_i32(t0
, t0
, t1
);
965 tcg_gen_movi_tl(cpu_ov
, 0);
970 tcg_gen_sari_i32(t0
, t0
, 31);
972 tcg_gen_movi_i32(t0
, 0);
975 tcg_gen_movi_tl(cpu_ov
, 1);
976 tcg_gen_movi_tl(cpu_so
, 1);
979 tcg_gen_extu_i32_tl(ret
, t0
);
980 tcg_temp_free_i32(t0
);
981 tcg_temp_free_i32(t1
);
982 if (unlikely(Rc(ctx
->opcode
) != 0))
983 gen_set_Rc0(ctx
, ret
);
986 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
987 static void glue(gen_, name)(DisasContext *ctx) \
989 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
990 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
993 /* divwu divwu. divwuo divwuo. */
994 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0);
995 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1);
996 /* divw divw. divwo divwo. */
997 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0);
998 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1);
1000 /* div[wd]eu[o][.] */
1001 #define GEN_DIVE(name, hlpr, compute_ov) \
1002 static void gen_##name(DisasContext *ctx) \
1004 TCGv_i32 t0 = tcg_const_i32(compute_ov); \
1005 gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1006 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \
1007 tcg_temp_free_i32(t0); \
1008 if (unlikely(Rc(ctx->opcode) != 0)) { \
1009 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1013 GEN_DIVE(divweu
, divweu
, 0);
1014 GEN_DIVE(divweuo
, divweu
, 1);
1015 GEN_DIVE(divwe
, divwe
, 0);
1016 GEN_DIVE(divweo
, divwe
, 1);
1018 #if defined(TARGET_PPC64)
1019 static inline void gen_op_arith_divd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1020 TCGv arg2
, int sign
, int compute_ov
)
1022 TCGLabel
*l1
= gen_new_label();
1023 TCGLabel
*l2
= gen_new_label();
1025 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg2
, 0, l1
);
1027 TCGLabel
*l3
= gen_new_label();
1028 tcg_gen_brcondi_i64(TCG_COND_NE
, arg2
, -1, l3
);
1029 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg1
, INT64_MIN
, l1
);
1031 tcg_gen_div_i64(ret
, arg1
, arg2
);
1033 tcg_gen_divu_i64(ret
, arg1
, arg2
);
1036 tcg_gen_movi_tl(cpu_ov
, 0);
1041 tcg_gen_sari_i64(ret
, arg1
, 63);
1043 tcg_gen_movi_i64(ret
, 0);
1046 tcg_gen_movi_tl(cpu_ov
, 1);
1047 tcg_gen_movi_tl(cpu_so
, 1);
1050 if (unlikely(Rc(ctx
->opcode
) != 0))
1051 gen_set_Rc0(ctx
, ret
);
1053 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1054 static void glue(gen_, name)(DisasContext *ctx) \
1056 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1057 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1058 sign, compute_ov); \
1060 /* divwu divwu. divwuo divwuo. */
1061 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0);
1062 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1);
1063 /* divw divw. divwo divwo. */
1064 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0);
1065 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1);
1067 GEN_DIVE(divdeu
, divdeu
, 0);
1068 GEN_DIVE(divdeuo
, divdeu
, 1);
1069 GEN_DIVE(divde
, divde
, 0);
1070 GEN_DIVE(divdeo
, divde
, 1);
1074 static void gen_mulhw(DisasContext
*ctx
)
1076 TCGv_i32 t0
= tcg_temp_new_i32();
1077 TCGv_i32 t1
= tcg_temp_new_i32();
1079 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1080 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1081 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1082 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1083 tcg_temp_free_i32(t0
);
1084 tcg_temp_free_i32(t1
);
1085 if (unlikely(Rc(ctx
->opcode
) != 0))
1086 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1089 /* mulhwu mulhwu. */
1090 static void gen_mulhwu(DisasContext
*ctx
)
1092 TCGv_i32 t0
= tcg_temp_new_i32();
1093 TCGv_i32 t1
= tcg_temp_new_i32();
1095 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1096 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1097 tcg_gen_mulu2_i32(t0
, t1
, t0
, t1
);
1098 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1099 tcg_temp_free_i32(t0
);
1100 tcg_temp_free_i32(t1
);
1101 if (unlikely(Rc(ctx
->opcode
) != 0))
1102 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1106 static void gen_mullw(DisasContext
*ctx
)
1108 #if defined(TARGET_PPC64)
1110 t0
= tcg_temp_new_i64();
1111 t1
= tcg_temp_new_i64();
1112 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1113 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1114 tcg_gen_mul_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
1118 tcg_gen_mul_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1119 cpu_gpr
[rB(ctx
->opcode
)]);
1121 if (unlikely(Rc(ctx
->opcode
) != 0))
1122 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1125 /* mullwo mullwo. */
1126 static void gen_mullwo(DisasContext
*ctx
)
1128 TCGv_i32 t0
= tcg_temp_new_i32();
1129 TCGv_i32 t1
= tcg_temp_new_i32();
1131 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1132 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1133 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1134 #if defined(TARGET_PPC64)
1135 tcg_gen_concat_i32_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
1137 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1140 tcg_gen_sari_i32(t0
, t0
, 31);
1141 tcg_gen_setcond_i32(TCG_COND_NE
, t0
, t0
, t1
);
1142 tcg_gen_extu_i32_tl(cpu_ov
, t0
);
1143 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1145 tcg_temp_free_i32(t0
);
1146 tcg_temp_free_i32(t1
);
1147 if (unlikely(Rc(ctx
->opcode
) != 0))
1148 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1152 static void gen_mulli(DisasContext
*ctx
)
1154 tcg_gen_muli_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1158 #if defined(TARGET_PPC64)
1160 static void gen_mulhd(DisasContext
*ctx
)
1162 TCGv lo
= tcg_temp_new();
1163 tcg_gen_muls2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1164 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1166 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1167 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1171 /* mulhdu mulhdu. */
1172 static void gen_mulhdu(DisasContext
*ctx
)
1174 TCGv lo
= tcg_temp_new();
1175 tcg_gen_mulu2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1176 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1178 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1179 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1184 static void gen_mulld(DisasContext
*ctx
)
1186 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1187 cpu_gpr
[rB(ctx
->opcode
)]);
1188 if (unlikely(Rc(ctx
->opcode
) != 0))
1189 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1192 /* mulldo mulldo. */
1193 static void gen_mulldo(DisasContext
*ctx
)
1195 TCGv_i64 t0
= tcg_temp_new_i64();
1196 TCGv_i64 t1
= tcg_temp_new_i64();
1198 tcg_gen_muls2_i64(t0
, t1
, cpu_gpr
[rA(ctx
->opcode
)],
1199 cpu_gpr
[rB(ctx
->opcode
)]);
1200 tcg_gen_mov_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1202 tcg_gen_sari_i64(t0
, t0
, 63);
1203 tcg_gen_setcond_i64(TCG_COND_NE
, cpu_ov
, t0
, t1
);
1204 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1206 tcg_temp_free_i64(t0
);
1207 tcg_temp_free_i64(t1
);
1209 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1210 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1215 /* Common subf function */
1216 static inline void gen_op_arith_subf(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1217 TCGv arg2
, bool add_ca
, bool compute_ca
,
1218 bool compute_ov
, bool compute_rc0
)
1222 if (compute_ca
|| compute_ov
) {
1223 t0
= tcg_temp_new();
1227 /* dest = ~arg1 + arg2 [+ ca]. */
1228 if (NARROW_MODE(ctx
)) {
1229 /* Caution: a non-obvious corner case of the spec is that we
1230 must produce the *entire* 64-bit addition, but produce the
1231 carry into bit 32. */
1232 TCGv inv1
= tcg_temp_new();
1233 TCGv t1
= tcg_temp_new();
1234 tcg_gen_not_tl(inv1
, arg1
);
1236 tcg_gen_add_tl(t0
, arg2
, cpu_ca
);
1238 tcg_gen_addi_tl(t0
, arg2
, 1);
1240 tcg_gen_xor_tl(t1
, arg2
, inv1
); /* add without carry */
1241 tcg_gen_add_tl(t0
, t0
, inv1
);
1242 tcg_temp_free(inv1
);
1243 tcg_gen_xor_tl(cpu_ca
, t0
, t1
); /* bits changes w/ carry */
1245 tcg_gen_shri_tl(cpu_ca
, cpu_ca
, 32); /* extract bit 32 */
1246 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
1247 } else if (add_ca
) {
1248 TCGv zero
, inv1
= tcg_temp_new();
1249 tcg_gen_not_tl(inv1
, arg1
);
1250 zero
= tcg_const_tl(0);
1251 tcg_gen_add2_tl(t0
, cpu_ca
, arg2
, zero
, cpu_ca
, zero
);
1252 tcg_gen_add2_tl(t0
, cpu_ca
, t0
, cpu_ca
, inv1
, zero
);
1253 tcg_temp_free(zero
);
1254 tcg_temp_free(inv1
);
1256 tcg_gen_setcond_tl(TCG_COND_GEU
, cpu_ca
, arg2
, arg1
);
1257 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1259 } else if (add_ca
) {
1260 /* Since we're ignoring carry-out, we can simplify the
1261 standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1. */
1262 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1263 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
1264 tcg_gen_subi_tl(t0
, t0
, 1);
1266 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1270 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 1);
1272 if (unlikely(compute_rc0
)) {
1273 gen_set_Rc0(ctx
, t0
);
1276 if (!TCGV_EQUAL(t0
, ret
)) {
1277 tcg_gen_mov_tl(ret
, t0
);
1281 /* Sub functions with Two operands functions */
1282 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1283 static void glue(gen_, name)(DisasContext *ctx) \
1285 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1286 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1287 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1289 /* Sub functions with one operand and one immediate */
1290 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1291 add_ca, compute_ca, compute_ov) \
1292 static void glue(gen_, name)(DisasContext *ctx) \
1294 TCGv t0 = tcg_const_tl(const_val); \
1295 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1296 cpu_gpr[rA(ctx->opcode)], t0, \
1297 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1298 tcg_temp_free(t0); \
1300 /* subf subf. subfo subfo. */
1301 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
1302 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
1303 /* subfc subfc. subfco subfco. */
1304 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
1305 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
1306 /* subfe subfe. subfeo subfo. */
1307 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
1308 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
1309 /* subfme subfme. subfmeo subfmeo. */
1310 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
1311 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
1312 /* subfze subfze. subfzeo subfzeo.*/
1313 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
1314 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
1317 static void gen_subfic(DisasContext
*ctx
)
1319 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
1320 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1325 /* neg neg. nego nego. */
1326 static inline void gen_op_arith_neg(DisasContext
*ctx
, bool compute_ov
)
1328 TCGv zero
= tcg_const_tl(0);
1329 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1330 zero
, 0, 0, compute_ov
, Rc(ctx
->opcode
));
1331 tcg_temp_free(zero
);
1334 static void gen_neg(DisasContext
*ctx
)
1336 gen_op_arith_neg(ctx
, 0);
1339 static void gen_nego(DisasContext
*ctx
)
1341 gen_op_arith_neg(ctx
, 1);
1344 /*** Integer logical ***/
1345 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1346 static void glue(gen_, name)(DisasContext *ctx) \
1348 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1349 cpu_gpr[rB(ctx->opcode)]); \
1350 if (unlikely(Rc(ctx->opcode) != 0)) \
1351 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1354 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1355 static void glue(gen_, name)(DisasContext *ctx) \
1357 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1358 if (unlikely(Rc(ctx->opcode) != 0)) \
1359 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1363 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
);
1365 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
);
1368 static void gen_andi_(DisasContext
*ctx
)
1370 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
));
1371 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1375 static void gen_andis_(DisasContext
*ctx
)
1377 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
) << 16);
1378 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1382 static void gen_cntlzw(DisasContext
*ctx
)
1384 gen_helper_cntlzw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1385 if (unlikely(Rc(ctx
->opcode
) != 0))
1386 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1389 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
);
1390 /* extsb & extsb. */
1391 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
);
1392 /* extsh & extsh. */
1393 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
);
1395 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
);
1397 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
);
1400 static void gen_or(DisasContext
*ctx
)
1404 rs
= rS(ctx
->opcode
);
1405 ra
= rA(ctx
->opcode
);
1406 rb
= rB(ctx
->opcode
);
1407 /* Optimisation for mr. ri case */
1408 if (rs
!= ra
|| rs
!= rb
) {
1410 tcg_gen_or_tl(cpu_gpr
[ra
], cpu_gpr
[rs
], cpu_gpr
[rb
]);
1412 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rs
]);
1413 if (unlikely(Rc(ctx
->opcode
) != 0))
1414 gen_set_Rc0(ctx
, cpu_gpr
[ra
]);
1415 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
1416 gen_set_Rc0(ctx
, cpu_gpr
[rs
]);
1417 #if defined(TARGET_PPC64)
1423 /* Set process priority to low */
1427 /* Set process priority to medium-low */
1431 /* Set process priority to normal */
1434 #if !defined(CONFIG_USER_ONLY)
1437 /* Set process priority to very low */
1443 /* Set process priority to medium-hight */
1449 /* Set process priority to high */
1455 /* Set process priority to very high */
1465 TCGv t0
= tcg_temp_new();
1466 gen_load_spr(t0
, SPR_PPR
);
1467 tcg_gen_andi_tl(t0
, t0
, ~0x001C000000000000ULL
);
1468 tcg_gen_ori_tl(t0
, t0
, ((uint64_t)prio
) << 50);
1469 gen_store_spr(SPR_PPR
, t0
);
1476 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
);
1479 static void gen_xor(DisasContext
*ctx
)
1481 /* Optimisation for "set to zero" case */
1482 if (rS(ctx
->opcode
) != rB(ctx
->opcode
))
1483 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1485 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1486 if (unlikely(Rc(ctx
->opcode
) != 0))
1487 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1491 static void gen_ori(DisasContext
*ctx
)
1493 target_ulong uimm
= UIMM(ctx
->opcode
);
1495 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1497 /* XXX: should handle special NOPs for POWER series */
1500 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1504 static void gen_oris(DisasContext
*ctx
)
1506 target_ulong uimm
= UIMM(ctx
->opcode
);
1508 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1512 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1516 static void gen_xori(DisasContext
*ctx
)
1518 target_ulong uimm
= UIMM(ctx
->opcode
);
1520 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1524 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1528 static void gen_xoris(DisasContext
*ctx
)
1530 target_ulong uimm
= UIMM(ctx
->opcode
);
1532 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1536 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1539 /* popcntb : PowerPC 2.03 specification */
1540 static void gen_popcntb(DisasContext
*ctx
)
1542 gen_helper_popcntb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1545 static void gen_popcntw(DisasContext
*ctx
)
1547 gen_helper_popcntw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1550 #if defined(TARGET_PPC64)
1551 /* popcntd: PowerPC 2.06 specification */
1552 static void gen_popcntd(DisasContext
*ctx
)
1554 gen_helper_popcntd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1558 /* prtyw: PowerPC 2.05 specification */
1559 static void gen_prtyw(DisasContext
*ctx
)
1561 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
1562 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
1563 TCGv t0
= tcg_temp_new();
1564 tcg_gen_shri_tl(t0
, rs
, 16);
1565 tcg_gen_xor_tl(ra
, rs
, t0
);
1566 tcg_gen_shri_tl(t0
, ra
, 8);
1567 tcg_gen_xor_tl(ra
, ra
, t0
);
1568 tcg_gen_andi_tl(ra
, ra
, (target_ulong
)0x100000001ULL
);
1572 #if defined(TARGET_PPC64)
1573 /* prtyd: PowerPC 2.05 specification */
1574 static void gen_prtyd(DisasContext
*ctx
)
1576 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
1577 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
1578 TCGv t0
= tcg_temp_new();
1579 tcg_gen_shri_tl(t0
, rs
, 32);
1580 tcg_gen_xor_tl(ra
, rs
, t0
);
1581 tcg_gen_shri_tl(t0
, ra
, 16);
1582 tcg_gen_xor_tl(ra
, ra
, t0
);
1583 tcg_gen_shri_tl(t0
, ra
, 8);
1584 tcg_gen_xor_tl(ra
, ra
, t0
);
1585 tcg_gen_andi_tl(ra
, ra
, 1);
1590 #if defined(TARGET_PPC64)
1592 static void gen_bpermd(DisasContext
*ctx
)
1594 gen_helper_bpermd(cpu_gpr
[rA(ctx
->opcode
)],
1595 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1599 #if defined(TARGET_PPC64)
1600 /* extsw & extsw. */
1601 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
);
1604 static void gen_cntlzd(DisasContext
*ctx
)
1606 gen_helper_cntlzd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1607 if (unlikely(Rc(ctx
->opcode
) != 0))
1608 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1612 /*** Integer rotate ***/
1614 /* rlwimi & rlwimi. */
1615 static void gen_rlwimi(DisasContext
*ctx
)
1617 uint32_t mb
, me
, sh
;
1619 mb
= MB(ctx
->opcode
);
1620 me
= ME(ctx
->opcode
);
1621 sh
= SH(ctx
->opcode
);
1622 if (likely(sh
== (31-me
) && mb
<= me
)) {
1623 tcg_gen_deposit_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1624 cpu_gpr
[rS(ctx
->opcode
)], sh
, me
- mb
+ 1);
1628 TCGv t0
= tcg_temp_new();
1629 #if defined(TARGET_PPC64)
1630 tcg_gen_deposit_i64(t0
, cpu_gpr
[rS(ctx
->opcode
)],
1631 cpu_gpr
[rS(ctx
->opcode
)], 32, 32);
1632 tcg_gen_rotli_i64(t0
, t0
, sh
);
1634 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1636 #if defined(TARGET_PPC64)
1640 mask
= MASK(mb
, me
);
1641 t1
= tcg_temp_new();
1642 tcg_gen_andi_tl(t0
, t0
, mask
);
1643 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1644 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1648 if (unlikely(Rc(ctx
->opcode
) != 0))
1649 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1652 /* rlwinm & rlwinm. */
1653 static void gen_rlwinm(DisasContext
*ctx
)
1655 uint32_t mb
, me
, sh
;
1657 sh
= SH(ctx
->opcode
);
1658 mb
= MB(ctx
->opcode
);
1659 me
= ME(ctx
->opcode
);
1661 if (likely(mb
== 0 && me
== (31 - sh
))) {
1662 if (likely(sh
== 0)) {
1663 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1665 TCGv t0
= tcg_temp_new();
1666 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1667 tcg_gen_shli_tl(t0
, t0
, sh
);
1668 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1671 } else if (likely(sh
!= 0 && me
== 31 && sh
== (32 - mb
))) {
1672 TCGv t0
= tcg_temp_new();
1673 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1674 tcg_gen_shri_tl(t0
, t0
, mb
);
1675 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1677 } else if (likely(mb
== 0 && me
== 31)) {
1678 TCGv_i32 t0
= tcg_temp_new_i32();
1679 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1680 tcg_gen_rotli_i32(t0
, t0
, sh
);
1681 tcg_gen_extu_i32_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1682 tcg_temp_free_i32(t0
);
1684 TCGv t0
= tcg_temp_new();
1685 #if defined(TARGET_PPC64)
1686 tcg_gen_deposit_i64(t0
, cpu_gpr
[rS(ctx
->opcode
)],
1687 cpu_gpr
[rS(ctx
->opcode
)], 32, 32);
1688 tcg_gen_rotli_i64(t0
, t0
, sh
);
1690 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1692 #if defined(TARGET_PPC64)
1696 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1699 if (unlikely(Rc(ctx
->opcode
) != 0))
1700 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1703 /* rlwnm & rlwnm. */
1704 static void gen_rlwnm(DisasContext
*ctx
)
1707 mb
= MB(ctx
->opcode
);
1708 me
= ME(ctx
->opcode
);
1710 if (likely(mb
== 0 && me
== 31)) {
1712 t0
= tcg_temp_new_i32();
1713 t1
= tcg_temp_new_i32();
1714 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
1715 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1716 tcg_gen_andi_i32(t0
, t0
, 0x1f);
1717 tcg_gen_rotl_i32(t1
, t1
, t0
);
1718 tcg_gen_extu_i32_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
);
1719 tcg_temp_free_i32(t0
);
1720 tcg_temp_free_i32(t1
);
1723 #if defined(TARGET_PPC64)
1727 t0
= tcg_temp_new();
1728 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1729 #if defined(TARGET_PPC64)
1730 t1
= tcg_temp_new_i64();
1731 tcg_gen_deposit_i64(t1
, cpu_gpr
[rS(ctx
->opcode
)],
1732 cpu_gpr
[rS(ctx
->opcode
)], 32, 32);
1733 tcg_gen_rotl_i64(t0
, t1
, t0
);
1734 tcg_temp_free_i64(t1
);
1736 tcg_gen_rotl_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1738 if (unlikely(mb
!= 0 || me
!= 31)) {
1739 #if defined(TARGET_PPC64)
1743 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1745 tcg_gen_andi_tl(t0
, t0
, MASK(32, 63));
1746 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1750 if (unlikely(Rc(ctx
->opcode
) != 0))
1751 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1754 #if defined(TARGET_PPC64)
1755 #define GEN_PPC64_R2(name, opc1, opc2) \
1756 static void glue(gen_, name##0)(DisasContext *ctx) \
1758 gen_##name(ctx, 0); \
1761 static void glue(gen_, name##1)(DisasContext *ctx) \
1763 gen_##name(ctx, 1); \
1765 #define GEN_PPC64_R4(name, opc1, opc2) \
1766 static void glue(gen_, name##0)(DisasContext *ctx) \
1768 gen_##name(ctx, 0, 0); \
1771 static void glue(gen_, name##1)(DisasContext *ctx) \
1773 gen_##name(ctx, 0, 1); \
1776 static void glue(gen_, name##2)(DisasContext *ctx) \
1778 gen_##name(ctx, 1, 0); \
1781 static void glue(gen_, name##3)(DisasContext *ctx) \
1783 gen_##name(ctx, 1, 1); \
1786 static inline void gen_rldinm(DisasContext
*ctx
, uint32_t mb
, uint32_t me
,
1789 if (likely(sh
!= 0 && mb
== 0 && me
== (63 - sh
))) {
1790 tcg_gen_shli_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
1791 } else if (likely(sh
!= 0 && me
== 63 && sh
== (64 - mb
))) {
1792 tcg_gen_shri_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], mb
);
1794 TCGv t0
= tcg_temp_new();
1795 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1796 if (likely(mb
== 0 && me
== 63)) {
1797 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1799 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1803 if (unlikely(Rc(ctx
->opcode
) != 0))
1804 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1806 /* rldicl - rldicl. */
1807 static inline void gen_rldicl(DisasContext
*ctx
, int mbn
, int shn
)
1811 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1812 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1813 gen_rldinm(ctx
, mb
, 63, sh
);
1815 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
1816 /* rldicr - rldicr. */
1817 static inline void gen_rldicr(DisasContext
*ctx
, int men
, int shn
)
1821 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1822 me
= MB(ctx
->opcode
) | (men
<< 5);
1823 gen_rldinm(ctx
, 0, me
, sh
);
1825 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
1826 /* rldic - rldic. */
1827 static inline void gen_rldic(DisasContext
*ctx
, int mbn
, int shn
)
1831 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1832 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1833 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
1835 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
1837 static inline void gen_rldnm(DisasContext
*ctx
, uint32_t mb
, uint32_t me
)
1841 t0
= tcg_temp_new();
1842 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1843 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1844 if (unlikely(mb
!= 0 || me
!= 63)) {
1845 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1847 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1850 if (unlikely(Rc(ctx
->opcode
) != 0))
1851 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1854 /* rldcl - rldcl. */
1855 static inline void gen_rldcl(DisasContext
*ctx
, int mbn
)
1859 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1860 gen_rldnm(ctx
, mb
, 63);
1862 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
1863 /* rldcr - rldcr. */
1864 static inline void gen_rldcr(DisasContext
*ctx
, int men
)
1868 me
= MB(ctx
->opcode
) | (men
<< 5);
1869 gen_rldnm(ctx
, 0, me
);
1871 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
1872 /* rldimi - rldimi. */
1873 static inline void gen_rldimi(DisasContext
*ctx
, int mbn
, int shn
)
1875 uint32_t sh
, mb
, me
;
1877 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1878 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1880 if (unlikely(sh
== 0 && mb
== 0)) {
1881 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1886 t0
= tcg_temp_new();
1887 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1888 t1
= tcg_temp_new();
1889 mask
= MASK(mb
, me
);
1890 tcg_gen_andi_tl(t0
, t0
, mask
);
1891 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1892 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1896 if (unlikely(Rc(ctx
->opcode
) != 0))
1897 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1899 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
1902 /*** Integer shift ***/
1905 static void gen_slw(DisasContext
*ctx
)
1909 t0
= tcg_temp_new();
1910 /* AND rS with a mask that is 0 when rB >= 0x20 */
1911 #if defined(TARGET_PPC64)
1912 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
1913 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1915 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
1916 tcg_gen_sari_tl(t0
, t0
, 0x1f);
1918 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1919 t1
= tcg_temp_new();
1920 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1921 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1924 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
1925 if (unlikely(Rc(ctx
->opcode
) != 0))
1926 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1930 static void gen_sraw(DisasContext
*ctx
)
1932 gen_helper_sraw(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
1933 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1934 if (unlikely(Rc(ctx
->opcode
) != 0))
1935 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1938 /* srawi & srawi. */
1939 static void gen_srawi(DisasContext
*ctx
)
1941 int sh
= SH(ctx
->opcode
);
1942 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
1943 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
1945 tcg_gen_ext32s_tl(dst
, src
);
1946 tcg_gen_movi_tl(cpu_ca
, 0);
1949 tcg_gen_ext32s_tl(dst
, src
);
1950 tcg_gen_andi_tl(cpu_ca
, dst
, (1ULL << sh
) - 1);
1951 t0
= tcg_temp_new();
1952 tcg_gen_sari_tl(t0
, dst
, TARGET_LONG_BITS
- 1);
1953 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
1955 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
1956 tcg_gen_sari_tl(dst
, dst
, sh
);
1958 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1959 gen_set_Rc0(ctx
, dst
);
1964 static void gen_srw(DisasContext
*ctx
)
1968 t0
= tcg_temp_new();
1969 /* AND rS with a mask that is 0 when rB >= 0x20 */
1970 #if defined(TARGET_PPC64)
1971 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
1972 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1974 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
1975 tcg_gen_sari_tl(t0
, t0
, 0x1f);
1977 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1978 tcg_gen_ext32u_tl(t0
, t0
);
1979 t1
= tcg_temp_new();
1980 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1981 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1984 if (unlikely(Rc(ctx
->opcode
) != 0))
1985 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1988 #if defined(TARGET_PPC64)
1990 static void gen_sld(DisasContext
*ctx
)
1994 t0
= tcg_temp_new();
1995 /* AND rS with a mask that is 0 when rB >= 0x40 */
1996 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
1997 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1998 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1999 t1
= tcg_temp_new();
2000 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
2001 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2004 if (unlikely(Rc(ctx
->opcode
) != 0))
2005 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2009 static void gen_srad(DisasContext
*ctx
)
2011 gen_helper_srad(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
2012 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2013 if (unlikely(Rc(ctx
->opcode
) != 0))
2014 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2016 /* sradi & sradi. */
2017 static inline void gen_sradi(DisasContext
*ctx
, int n
)
2019 int sh
= SH(ctx
->opcode
) + (n
<< 5);
2020 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
2021 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
2023 tcg_gen_mov_tl(dst
, src
);
2024 tcg_gen_movi_tl(cpu_ca
, 0);
2027 tcg_gen_andi_tl(cpu_ca
, src
, (1ULL << sh
) - 1);
2028 t0
= tcg_temp_new();
2029 tcg_gen_sari_tl(t0
, src
, TARGET_LONG_BITS
- 1);
2030 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
2032 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
2033 tcg_gen_sari_tl(dst
, src
, sh
);
2035 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2036 gen_set_Rc0(ctx
, dst
);
2040 static void gen_sradi0(DisasContext
*ctx
)
2045 static void gen_sradi1(DisasContext
*ctx
)
2051 static void gen_srd(DisasContext
*ctx
)
2055 t0
= tcg_temp_new();
2056 /* AND rS with a mask that is 0 when rB >= 0x40 */
2057 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
2058 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2059 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2060 t1
= tcg_temp_new();
2061 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
2062 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2065 if (unlikely(Rc(ctx
->opcode
) != 0))
2066 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2070 #if defined(TARGET_PPC64)
2071 static void gen_set_cr1_from_fpscr(DisasContext
*ctx
)
2073 TCGv_i32 tmp
= tcg_temp_new_i32();
2074 tcg_gen_trunc_tl_i32(tmp
, cpu_fpscr
);
2075 tcg_gen_shri_i32(cpu_crf
[1], tmp
, 28);
2076 tcg_temp_free_i32(tmp
);
2079 static void gen_set_cr1_from_fpscr(DisasContext
*ctx
)
2081 tcg_gen_shri_tl(cpu_crf
[1], cpu_fpscr
, 28);
2085 /*** Floating-Point arithmetic ***/
2086 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
2087 static void gen_f##name(DisasContext *ctx) \
2089 if (unlikely(!ctx->fpu_enabled)) { \
2090 gen_exception(ctx, POWERPC_EXCP_FPU); \
2093 /* NIP cannot be restored if the memory exception comes from an helper */ \
2094 gen_update_nip(ctx, ctx->nip - 4); \
2095 gen_reset_fpstatus(); \
2096 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2097 cpu_fpr[rA(ctx->opcode)], \
2098 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2100 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2101 cpu_fpr[rD(ctx->opcode)]); \
2104 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2106 if (unlikely(Rc(ctx->opcode) != 0)) { \
2107 gen_set_cr1_from_fpscr(ctx); \
2111 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2112 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2113 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
2115 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2116 static void gen_f##name(DisasContext *ctx) \
2118 if (unlikely(!ctx->fpu_enabled)) { \
2119 gen_exception(ctx, POWERPC_EXCP_FPU); \
2122 /* NIP cannot be restored if the memory exception comes from an helper */ \
2123 gen_update_nip(ctx, ctx->nip - 4); \
2124 gen_reset_fpstatus(); \
2125 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2126 cpu_fpr[rA(ctx->opcode)], \
2127 cpu_fpr[rB(ctx->opcode)]); \
2129 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2130 cpu_fpr[rD(ctx->opcode)]); \
2133 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2135 if (unlikely(Rc(ctx->opcode) != 0)) { \
2136 gen_set_cr1_from_fpscr(ctx); \
2139 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2140 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2141 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2143 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2144 static void gen_f##name(DisasContext *ctx) \
2146 if (unlikely(!ctx->fpu_enabled)) { \
2147 gen_exception(ctx, POWERPC_EXCP_FPU); \
2150 /* NIP cannot be restored if the memory exception comes from an helper */ \
2151 gen_update_nip(ctx, ctx->nip - 4); \
2152 gen_reset_fpstatus(); \
2153 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2154 cpu_fpr[rA(ctx->opcode)], \
2155 cpu_fpr[rC(ctx->opcode)]); \
2157 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2158 cpu_fpr[rD(ctx->opcode)]); \
2161 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2163 if (unlikely(Rc(ctx->opcode) != 0)) { \
2164 gen_set_cr1_from_fpscr(ctx); \
2167 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2168 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2169 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2171 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
2172 static void gen_f##name(DisasContext *ctx) \
2174 if (unlikely(!ctx->fpu_enabled)) { \
2175 gen_exception(ctx, POWERPC_EXCP_FPU); \
2178 /* NIP cannot be restored if the memory exception comes from an helper */ \
2179 gen_update_nip(ctx, ctx->nip - 4); \
2180 gen_reset_fpstatus(); \
2181 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2182 cpu_fpr[rB(ctx->opcode)]); \
2184 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2186 if (unlikely(Rc(ctx->opcode) != 0)) { \
2187 gen_set_cr1_from_fpscr(ctx); \
2191 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
2192 static void gen_f##name(DisasContext *ctx) \
2194 if (unlikely(!ctx->fpu_enabled)) { \
2195 gen_exception(ctx, POWERPC_EXCP_FPU); \
2198 /* NIP cannot be restored if the memory exception comes from an helper */ \
2199 gen_update_nip(ctx, ctx->nip - 4); \
2200 gen_reset_fpstatus(); \
2201 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2202 cpu_fpr[rB(ctx->opcode)]); \
2204 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2206 if (unlikely(Rc(ctx->opcode) != 0)) { \
2207 gen_set_cr1_from_fpscr(ctx); \
2212 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
);
2214 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
);
2216 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
);
2219 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
);
2222 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
);
2225 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
);
2228 static void gen_frsqrtes(DisasContext
*ctx
)
2230 if (unlikely(!ctx
->fpu_enabled
)) {
2231 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2234 /* NIP cannot be restored if the memory exception comes from an helper */
2235 gen_update_nip(ctx
, ctx
->nip
- 4);
2236 gen_reset_fpstatus();
2237 gen_helper_frsqrte(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2238 cpu_fpr
[rB(ctx
->opcode
)]);
2239 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2240 cpu_fpr
[rD(ctx
->opcode
)]);
2241 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)]);
2242 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2243 gen_set_cr1_from_fpscr(ctx
);
2248 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
);
2250 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
);
2254 static void gen_fsqrt(DisasContext
*ctx
)
2256 if (unlikely(!ctx
->fpu_enabled
)) {
2257 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2260 /* NIP cannot be restored if the memory exception comes from an helper */
2261 gen_update_nip(ctx
, ctx
->nip
- 4);
2262 gen_reset_fpstatus();
2263 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2264 cpu_fpr
[rB(ctx
->opcode
)]);
2265 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)]);
2266 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2267 gen_set_cr1_from_fpscr(ctx
);
2271 static void gen_fsqrts(DisasContext
*ctx
)
2273 if (unlikely(!ctx
->fpu_enabled
)) {
2274 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2277 /* NIP cannot be restored if the memory exception comes from an helper */
2278 gen_update_nip(ctx
, ctx
->nip
- 4);
2279 gen_reset_fpstatus();
2280 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2281 cpu_fpr
[rB(ctx
->opcode
)]);
2282 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2283 cpu_fpr
[rD(ctx
->opcode
)]);
2284 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)]);
2285 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2286 gen_set_cr1_from_fpscr(ctx
);
2290 /*** Floating-Point multiply-and-add ***/
2291 /* fmadd - fmadds */
2292 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
);
2293 /* fmsub - fmsubs */
2294 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
);
2295 /* fnmadd - fnmadds */
2296 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
);
2297 /* fnmsub - fnmsubs */
2298 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
);
2300 /*** Floating-Point round & convert ***/
2302 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
);
2304 GEN_FLOAT_B(ctiwu
, 0x0E, 0x04, 0, PPC2_FP_CVT_ISA206
);
2306 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
);
2308 GEN_FLOAT_B(ctiwuz
, 0x0F, 0x04, 0, PPC2_FP_CVT_ISA206
);
2310 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
);
2312 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC2_FP_CVT_S64
);
2314 GEN_FLOAT_B(cfids
, 0x0E, 0x1A, 0, PPC2_FP_CVT_ISA206
);
2316 GEN_FLOAT_B(cfidu
, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206
);
2318 GEN_FLOAT_B(cfidus
, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206
);
2320 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC2_FP_CVT_S64
);
2322 GEN_FLOAT_B(ctidu
, 0x0E, 0x1D, 0, PPC2_FP_CVT_ISA206
);
2324 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC2_FP_CVT_S64
);
2326 GEN_FLOAT_B(ctiduz
, 0x0F, 0x1D, 0, PPC2_FP_CVT_ISA206
);
2329 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
);
2331 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
);
2333 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
);
2335 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
);
2337 static void gen_ftdiv(DisasContext
*ctx
)
2339 if (unlikely(!ctx
->fpu_enabled
)) {
2340 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2343 gen_helper_ftdiv(cpu_crf
[crfD(ctx
->opcode
)], cpu_fpr
[rA(ctx
->opcode
)],
2344 cpu_fpr
[rB(ctx
->opcode
)]);
2347 static void gen_ftsqrt(DisasContext
*ctx
)
2349 if (unlikely(!ctx
->fpu_enabled
)) {
2350 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2353 gen_helper_ftsqrt(cpu_crf
[crfD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2358 /*** Floating-Point compare ***/
2361 static void gen_fcmpo(DisasContext
*ctx
)
2364 if (unlikely(!ctx
->fpu_enabled
)) {
2365 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2368 /* NIP cannot be restored if the memory exception comes from an helper */
2369 gen_update_nip(ctx
, ctx
->nip
- 4);
2370 gen_reset_fpstatus();
2371 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2372 gen_helper_fcmpo(cpu_env
, cpu_fpr
[rA(ctx
->opcode
)],
2373 cpu_fpr
[rB(ctx
->opcode
)], crf
);
2374 tcg_temp_free_i32(crf
);
2375 gen_helper_float_check_status(cpu_env
);
2379 static void gen_fcmpu(DisasContext
*ctx
)
2382 if (unlikely(!ctx
->fpu_enabled
)) {
2383 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2386 /* NIP cannot be restored if the memory exception comes from an helper */
2387 gen_update_nip(ctx
, ctx
->nip
- 4);
2388 gen_reset_fpstatus();
2389 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2390 gen_helper_fcmpu(cpu_env
, cpu_fpr
[rA(ctx
->opcode
)],
2391 cpu_fpr
[rB(ctx
->opcode
)], crf
);
2392 tcg_temp_free_i32(crf
);
2393 gen_helper_float_check_status(cpu_env
);
2396 /*** Floating-point move ***/
2398 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2399 static void gen_fabs(DisasContext
*ctx
)
2401 if (unlikely(!ctx
->fpu_enabled
)) {
2402 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2405 tcg_gen_andi_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)],
2407 if (unlikely(Rc(ctx
->opcode
))) {
2408 gen_set_cr1_from_fpscr(ctx
);
2413 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2414 static void gen_fmr(DisasContext
*ctx
)
2416 if (unlikely(!ctx
->fpu_enabled
)) {
2417 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2420 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2421 if (unlikely(Rc(ctx
->opcode
))) {
2422 gen_set_cr1_from_fpscr(ctx
);
2427 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2428 static void gen_fnabs(DisasContext
*ctx
)
2430 if (unlikely(!ctx
->fpu_enabled
)) {
2431 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2434 tcg_gen_ori_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)],
2436 if (unlikely(Rc(ctx
->opcode
))) {
2437 gen_set_cr1_from_fpscr(ctx
);
2442 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2443 static void gen_fneg(DisasContext
*ctx
)
2445 if (unlikely(!ctx
->fpu_enabled
)) {
2446 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2449 tcg_gen_xori_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)],
2451 if (unlikely(Rc(ctx
->opcode
))) {
2452 gen_set_cr1_from_fpscr(ctx
);
2456 /* fcpsgn: PowerPC 2.05 specification */
2457 /* XXX: beware that fcpsgn never checks for NaNs nor update FPSCR */
2458 static void gen_fcpsgn(DisasContext
*ctx
)
2460 if (unlikely(!ctx
->fpu_enabled
)) {
2461 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2464 tcg_gen_deposit_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rA(ctx
->opcode
)],
2465 cpu_fpr
[rB(ctx
->opcode
)], 0, 63);
2466 if (unlikely(Rc(ctx
->opcode
))) {
2467 gen_set_cr1_from_fpscr(ctx
);
2471 static void gen_fmrgew(DisasContext
*ctx
)
2474 if (unlikely(!ctx
->fpu_enabled
)) {
2475 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2478 b0
= tcg_temp_new_i64();
2479 tcg_gen_shri_i64(b0
, cpu_fpr
[rB(ctx
->opcode
)], 32);
2480 tcg_gen_deposit_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rA(ctx
->opcode
)],
2482 tcg_temp_free_i64(b0
);
2485 static void gen_fmrgow(DisasContext
*ctx
)
2487 if (unlikely(!ctx
->fpu_enabled
)) {
2488 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2491 tcg_gen_deposit_i64(cpu_fpr
[rD(ctx
->opcode
)],
2492 cpu_fpr
[rB(ctx
->opcode
)],
2493 cpu_fpr
[rA(ctx
->opcode
)],
2497 /*** Floating-Point status & ctrl register ***/
2500 static void gen_mcrfs(DisasContext
*ctx
)
2502 TCGv tmp
= tcg_temp_new();
2505 if (unlikely(!ctx
->fpu_enabled
)) {
2506 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2509 bfa
= 4 * (7 - crfS(ctx
->opcode
));
2510 tcg_gen_shri_tl(tmp
, cpu_fpscr
, bfa
);
2511 tcg_gen_trunc_tl_i32(cpu_crf
[crfD(ctx
->opcode
)], tmp
);
2513 tcg_gen_andi_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfD(ctx
->opcode
)], 0xf);
2514 tcg_gen_andi_tl(cpu_fpscr
, cpu_fpscr
, ~(0xF << bfa
));
2518 static void gen_mffs(DisasContext
*ctx
)
2520 if (unlikely(!ctx
->fpu_enabled
)) {
2521 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2524 gen_reset_fpstatus();
2525 tcg_gen_extu_tl_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpscr
);
2526 if (unlikely(Rc(ctx
->opcode
))) {
2527 gen_set_cr1_from_fpscr(ctx
);
2532 static void gen_mtfsb0(DisasContext
*ctx
)
2536 if (unlikely(!ctx
->fpu_enabled
)) {
2537 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2540 crb
= 31 - crbD(ctx
->opcode
);
2541 gen_reset_fpstatus();
2542 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
)) {
2544 /* NIP cannot be restored if the memory exception comes from an helper */
2545 gen_update_nip(ctx
, ctx
->nip
- 4);
2546 t0
= tcg_const_i32(crb
);
2547 gen_helper_fpscr_clrbit(cpu_env
, t0
);
2548 tcg_temp_free_i32(t0
);
2550 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2551 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2552 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2557 static void gen_mtfsb1(DisasContext
*ctx
)
2561 if (unlikely(!ctx
->fpu_enabled
)) {
2562 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2565 crb
= 31 - crbD(ctx
->opcode
);
2566 gen_reset_fpstatus();
2567 /* XXX: we pretend we can only do IEEE floating-point computations */
2568 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
&& crb
!= FPSCR_NI
)) {
2570 /* NIP cannot be restored if the memory exception comes from an helper */
2571 gen_update_nip(ctx
, ctx
->nip
- 4);
2572 t0
= tcg_const_i32(crb
);
2573 gen_helper_fpscr_setbit(cpu_env
, t0
);
2574 tcg_temp_free_i32(t0
);
2576 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2577 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2578 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2580 /* We can raise a differed exception */
2581 gen_helper_float_check_status(cpu_env
);
2585 static void gen_mtfsf(DisasContext
*ctx
)
2590 if (unlikely(!ctx
->fpu_enabled
)) {
2591 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2594 flm
= FPFLM(ctx
->opcode
);
2595 l
= FPL(ctx
->opcode
);
2596 w
= FPW(ctx
->opcode
);
2597 if (unlikely(w
& !(ctx
->insns_flags2
& PPC2_ISA205
))) {
2598 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2601 /* NIP cannot be restored if the memory exception comes from an helper */
2602 gen_update_nip(ctx
, ctx
->nip
- 4);
2603 gen_reset_fpstatus();
2605 t0
= tcg_const_i32((ctx
->insns_flags2
& PPC2_ISA205
) ? 0xffff : 0xff);
2607 t0
= tcg_const_i32(flm
<< (w
* 8));
2609 gen_helper_store_fpscr(cpu_env
, cpu_fpr
[rB(ctx
->opcode
)], t0
);
2610 tcg_temp_free_i32(t0
);
2611 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2612 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2613 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2615 /* We can raise a differed exception */
2616 gen_helper_float_check_status(cpu_env
);
2620 static void gen_mtfsfi(DisasContext
*ctx
)
2626 if (unlikely(!ctx
->fpu_enabled
)) {
2627 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2630 w
= FPW(ctx
->opcode
);
2631 bf
= FPBF(ctx
->opcode
);
2632 if (unlikely(w
& !(ctx
->insns_flags2
& PPC2_ISA205
))) {
2633 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2636 sh
= (8 * w
) + 7 - bf
;
2637 /* NIP cannot be restored if the memory exception comes from an helper */
2638 gen_update_nip(ctx
, ctx
->nip
- 4);
2639 gen_reset_fpstatus();
2640 t0
= tcg_const_i64(((uint64_t)FPIMM(ctx
->opcode
)) << (4 * sh
));
2641 t1
= tcg_const_i32(1 << sh
);
2642 gen_helper_store_fpscr(cpu_env
, t0
, t1
);
2643 tcg_temp_free_i64(t0
);
2644 tcg_temp_free_i32(t1
);
2645 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2646 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2647 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2649 /* We can raise a differed exception */
2650 gen_helper_float_check_status(cpu_env
);
2653 /*** Addressing modes ***/
2654 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2655 static inline void gen_addr_imm_index(DisasContext
*ctx
, TCGv EA
,
2658 target_long simm
= SIMM(ctx
->opcode
);
2661 if (rA(ctx
->opcode
) == 0) {
2662 if (NARROW_MODE(ctx
)) {
2663 simm
= (uint32_t)simm
;
2665 tcg_gen_movi_tl(EA
, simm
);
2666 } else if (likely(simm
!= 0)) {
2667 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
);
2668 if (NARROW_MODE(ctx
)) {
2669 tcg_gen_ext32u_tl(EA
, EA
);
2672 if (NARROW_MODE(ctx
)) {
2673 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2675 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2680 static inline void gen_addr_reg_index(DisasContext
*ctx
, TCGv EA
)
2682 if (rA(ctx
->opcode
) == 0) {
2683 if (NARROW_MODE(ctx
)) {
2684 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2686 tcg_gen_mov_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2689 tcg_gen_add_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2690 if (NARROW_MODE(ctx
)) {
2691 tcg_gen_ext32u_tl(EA
, EA
);
2696 static inline void gen_addr_register(DisasContext
*ctx
, TCGv EA
)
2698 if (rA(ctx
->opcode
) == 0) {
2699 tcg_gen_movi_tl(EA
, 0);
2700 } else if (NARROW_MODE(ctx
)) {
2701 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2703 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2707 static inline void gen_addr_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
2710 tcg_gen_addi_tl(ret
, arg1
, val
);
2711 if (NARROW_MODE(ctx
)) {
2712 tcg_gen_ext32u_tl(ret
, ret
);
2716 static inline void gen_check_align(DisasContext
*ctx
, TCGv EA
, int mask
)
2718 TCGLabel
*l1
= gen_new_label();
2719 TCGv t0
= tcg_temp_new();
2721 /* NIP cannot be restored if the memory exception comes from an helper */
2722 gen_update_nip(ctx
, ctx
->nip
- 4);
2723 tcg_gen_andi_tl(t0
, EA
, mask
);
2724 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2725 t1
= tcg_const_i32(POWERPC_EXCP_ALIGN
);
2726 t2
= tcg_const_i32(0);
2727 gen_helper_raise_exception_err(cpu_env
, t1
, t2
);
2728 tcg_temp_free_i32(t1
);
2729 tcg_temp_free_i32(t2
);
2734 /*** Integer load ***/
2735 static inline void gen_qemu_ld8u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2737 tcg_gen_qemu_ld8u(arg1
, arg2
, ctx
->mem_idx
);
2740 static inline void gen_qemu_ld16u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2742 TCGMemOp op
= MO_UW
| ctx
->default_tcg_memop_mask
;
2743 tcg_gen_qemu_ld_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
2746 static inline void gen_qemu_ld16s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2748 TCGMemOp op
= MO_SW
| ctx
->default_tcg_memop_mask
;
2749 tcg_gen_qemu_ld_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
2752 static inline void gen_qemu_ld32u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2754 TCGMemOp op
= MO_UL
| ctx
->default_tcg_memop_mask
;
2755 tcg_gen_qemu_ld_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
2758 static void gen_qemu_ld32u_i64(DisasContext
*ctx
, TCGv_i64 val
, TCGv addr
)
2760 TCGv tmp
= tcg_temp_new();
2761 gen_qemu_ld32u(ctx
, tmp
, addr
);
2762 tcg_gen_extu_tl_i64(val
, tmp
);
2766 static inline void gen_qemu_ld32s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2768 TCGMemOp op
= MO_SL
| ctx
->default_tcg_memop_mask
;
2769 tcg_gen_qemu_ld_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
2772 static void gen_qemu_ld32s_i64(DisasContext
*ctx
, TCGv_i64 val
, TCGv addr
)
2774 TCGv tmp
= tcg_temp_new();
2775 gen_qemu_ld32s(ctx
, tmp
, addr
);
2776 tcg_gen_ext_tl_i64(val
, tmp
);
2780 static inline void gen_qemu_ld64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2782 TCGMemOp op
= MO_Q
| ctx
->default_tcg_memop_mask
;
2783 tcg_gen_qemu_ld_i64(arg1
, arg2
, ctx
->mem_idx
, op
);
2786 static inline void gen_qemu_st8(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2788 tcg_gen_qemu_st8(arg1
, arg2
, ctx
->mem_idx
);
2791 static inline void gen_qemu_st16(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2793 TCGMemOp op
= MO_UW
| ctx
->default_tcg_memop_mask
;
2794 tcg_gen_qemu_st_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
2797 static inline void gen_qemu_st32(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2799 TCGMemOp op
= MO_UL
| ctx
->default_tcg_memop_mask
;
2800 tcg_gen_qemu_st_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
2803 static void gen_qemu_st32_i64(DisasContext
*ctx
, TCGv_i64 val
, TCGv addr
)
2805 TCGv tmp
= tcg_temp_new();
2806 tcg_gen_trunc_i64_tl(tmp
, val
);
2807 gen_qemu_st32(ctx
, tmp
, addr
);
2811 static inline void gen_qemu_st64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2813 TCGMemOp op
= MO_Q
| ctx
->default_tcg_memop_mask
;
2814 tcg_gen_qemu_st_i64(arg1
, arg2
, ctx
->mem_idx
, op
);
2817 #define GEN_LD(name, ldop, opc, type) \
2818 static void glue(gen_, name)(DisasContext *ctx) \
2821 gen_set_access_type(ctx, ACCESS_INT); \
2822 EA = tcg_temp_new(); \
2823 gen_addr_imm_index(ctx, EA, 0); \
2824 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2825 tcg_temp_free(EA); \
2828 #define GEN_LDU(name, ldop, opc, type) \
2829 static void glue(gen_, name##u)(DisasContext *ctx) \
2832 if (unlikely(rA(ctx->opcode) == 0 || \
2833 rA(ctx->opcode) == rD(ctx->opcode))) { \
2834 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2837 gen_set_access_type(ctx, ACCESS_INT); \
2838 EA = tcg_temp_new(); \
2839 if (type == PPC_64B) \
2840 gen_addr_imm_index(ctx, EA, 0x03); \
2842 gen_addr_imm_index(ctx, EA, 0); \
2843 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2844 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2845 tcg_temp_free(EA); \
2848 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
2849 static void glue(gen_, name##ux)(DisasContext *ctx) \
2852 if (unlikely(rA(ctx->opcode) == 0 || \
2853 rA(ctx->opcode) == rD(ctx->opcode))) { \
2854 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2857 gen_set_access_type(ctx, ACCESS_INT); \
2858 EA = tcg_temp_new(); \
2859 gen_addr_reg_index(ctx, EA); \
2860 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2861 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2862 tcg_temp_free(EA); \
2865 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
2866 static void glue(gen_, name##x)(DisasContext *ctx) \
2869 gen_set_access_type(ctx, ACCESS_INT); \
2870 EA = tcg_temp_new(); \
2871 gen_addr_reg_index(ctx, EA); \
2872 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2873 tcg_temp_free(EA); \
2875 #define GEN_LDX(name, ldop, opc2, opc3, type) \
2876 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE)
2878 #define GEN_LDS(name, ldop, op, type) \
2879 GEN_LD(name, ldop, op | 0x20, type); \
2880 GEN_LDU(name, ldop, op | 0x21, type); \
2881 GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2882 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
2884 /* lbz lbzu lbzux lbzx */
2885 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
);
2886 /* lha lhau lhaux lhax */
2887 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
);
2888 /* lhz lhzu lhzux lhzx */
2889 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
);
2890 /* lwz lwzu lwzux lwzx */
2891 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
);
2892 #if defined(TARGET_PPC64)
2894 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
);
2896 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
);
2898 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
);
2900 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
);
2902 static void gen_ld(DisasContext
*ctx
)
2905 if (Rc(ctx
->opcode
)) {
2906 if (unlikely(rA(ctx
->opcode
) == 0 ||
2907 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
2908 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2912 gen_set_access_type(ctx
, ACCESS_INT
);
2913 EA
= tcg_temp_new();
2914 gen_addr_imm_index(ctx
, EA
, 0x03);
2915 if (ctx
->opcode
& 0x02) {
2916 /* lwa (lwau is undefined) */
2917 gen_qemu_ld32s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2920 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2922 if (Rc(ctx
->opcode
))
2923 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2928 static void gen_lq(DisasContext
*ctx
)
2933 /* lq is a legal user mode instruction starting in ISA 2.07 */
2934 bool legal_in_user_mode
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
2935 bool le_is_supported
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
2937 if (!legal_in_user_mode
&& ctx
->pr
) {
2938 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2942 if (!le_is_supported
&& ctx
->le_mode
) {
2943 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2947 ra
= rA(ctx
->opcode
);
2948 rd
= rD(ctx
->opcode
);
2949 if (unlikely((rd
& 1) || rd
== ra
)) {
2950 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2954 gen_set_access_type(ctx
, ACCESS_INT
);
2955 EA
= tcg_temp_new();
2956 gen_addr_imm_index(ctx
, EA
, 0x0F);
2958 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
2959 64-bit byteswap already. */
2960 if (unlikely(ctx
->le_mode
)) {
2961 gen_qemu_ld64(ctx
, cpu_gpr
[rd
+1], EA
);
2962 gen_addr_add(ctx
, EA
, EA
, 8);
2963 gen_qemu_ld64(ctx
, cpu_gpr
[rd
], EA
);
2965 gen_qemu_ld64(ctx
, cpu_gpr
[rd
], EA
);
2966 gen_addr_add(ctx
, EA
, EA
, 8);
2967 gen_qemu_ld64(ctx
, cpu_gpr
[rd
+1], EA
);
2973 /*** Integer store ***/
2974 #define GEN_ST(name, stop, opc, type) \
2975 static void glue(gen_, name)(DisasContext *ctx) \
2978 gen_set_access_type(ctx, ACCESS_INT); \
2979 EA = tcg_temp_new(); \
2980 gen_addr_imm_index(ctx, EA, 0); \
2981 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2982 tcg_temp_free(EA); \
2985 #define GEN_STU(name, stop, opc, type) \
2986 static void glue(gen_, stop##u)(DisasContext *ctx) \
2989 if (unlikely(rA(ctx->opcode) == 0)) { \
2990 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2993 gen_set_access_type(ctx, ACCESS_INT); \
2994 EA = tcg_temp_new(); \
2995 if (type == PPC_64B) \
2996 gen_addr_imm_index(ctx, EA, 0x03); \
2998 gen_addr_imm_index(ctx, EA, 0); \
2999 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
3000 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3001 tcg_temp_free(EA); \
3004 #define GEN_STUX(name, stop, opc2, opc3, type) \
3005 static void glue(gen_, name##ux)(DisasContext *ctx) \
3008 if (unlikely(rA(ctx->opcode) == 0)) { \
3009 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3012 gen_set_access_type(ctx, ACCESS_INT); \
3013 EA = tcg_temp_new(); \
3014 gen_addr_reg_index(ctx, EA); \
3015 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
3016 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3017 tcg_temp_free(EA); \
3020 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
3021 static void glue(gen_, name##x)(DisasContext *ctx) \
3024 gen_set_access_type(ctx, ACCESS_INT); \
3025 EA = tcg_temp_new(); \
3026 gen_addr_reg_index(ctx, EA); \
3027 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
3028 tcg_temp_free(EA); \
3030 #define GEN_STX(name, stop, opc2, opc3, type) \
3031 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE)
3033 #define GEN_STS(name, stop, op, type) \
3034 GEN_ST(name, stop, op | 0x20, type); \
3035 GEN_STU(name, stop, op | 0x21, type); \
3036 GEN_STUX(name, stop, 0x17, op | 0x01, type); \
3037 GEN_STX(name, stop, 0x17, op | 0x00, type)
3039 /* stb stbu stbux stbx */
3040 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
);
3041 /* sth sthu sthux sthx */
3042 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
);
3043 /* stw stwu stwux stwx */
3044 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
);
3045 #if defined(TARGET_PPC64)
3046 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
);
3047 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
);
3049 static void gen_std(DisasContext
*ctx
)
3054 rs
= rS(ctx
->opcode
);
3055 if ((ctx
->opcode
& 0x3) == 0x2) { /* stq */
3057 bool legal_in_user_mode
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
3058 bool le_is_supported
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
3060 if (!legal_in_user_mode
&& ctx
->pr
) {
3061 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3065 if (!le_is_supported
&& ctx
->le_mode
) {
3066 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
3070 if (unlikely(rs
& 1)) {
3071 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3074 gen_set_access_type(ctx
, ACCESS_INT
);
3075 EA
= tcg_temp_new();
3076 gen_addr_imm_index(ctx
, EA
, 0x03);
3078 /* We only need to swap high and low halves. gen_qemu_st64 does
3079 necessary 64-bit byteswap already. */
3080 if (unlikely(ctx
->le_mode
)) {
3081 gen_qemu_st64(ctx
, cpu_gpr
[rs
+1], EA
);
3082 gen_addr_add(ctx
, EA
, EA
, 8);
3083 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
3085 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
3086 gen_addr_add(ctx
, EA
, EA
, 8);
3087 gen_qemu_st64(ctx
, cpu_gpr
[rs
+1], EA
);
3092 if (Rc(ctx
->opcode
)) {
3093 if (unlikely(rA(ctx
->opcode
) == 0)) {
3094 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3098 gen_set_access_type(ctx
, ACCESS_INT
);
3099 EA
= tcg_temp_new();
3100 gen_addr_imm_index(ctx
, EA
, 0x03);
3101 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
3102 if (Rc(ctx
->opcode
))
3103 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
3108 /*** Integer load and store with byte reverse ***/
3111 static inline void gen_qemu_ld16ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3113 TCGMemOp op
= MO_UW
| (ctx
->default_tcg_memop_mask
^ MO_BSWAP
);
3114 tcg_gen_qemu_ld_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
3116 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
);
3119 static inline void gen_qemu_ld32ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3121 TCGMemOp op
= MO_UL
| (ctx
->default_tcg_memop_mask
^ MO_BSWAP
);
3122 tcg_gen_qemu_ld_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
3124 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
);
3126 #if defined(TARGET_PPC64)
3128 static inline void gen_qemu_ld64ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3130 TCGMemOp op
= MO_Q
| (ctx
->default_tcg_memop_mask
^ MO_BSWAP
);
3131 tcg_gen_qemu_ld_i64(arg1
, arg2
, ctx
->mem_idx
, op
);
3133 GEN_LDX_E(ldbr
, ld64ur
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
);
3134 #endif /* TARGET_PPC64 */
3137 static inline void gen_qemu_st16r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3139 TCGMemOp op
= MO_UW
| (ctx
->default_tcg_memop_mask
^ MO_BSWAP
);
3140 tcg_gen_qemu_st_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
3142 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
);
3145 static inline void gen_qemu_st32r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3147 TCGMemOp op
= MO_UL
| (ctx
->default_tcg_memop_mask
^ MO_BSWAP
);
3148 tcg_gen_qemu_st_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
3150 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
);
3152 #if defined(TARGET_PPC64)
3154 static inline void gen_qemu_st64r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3156 TCGMemOp op
= MO_Q
| (ctx
->default_tcg_memop_mask
^ MO_BSWAP
);
3157 tcg_gen_qemu_st_i64(arg1
, arg2
, ctx
->mem_idx
, op
);
3159 GEN_STX_E(stdbr
, st64r
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
);
3160 #endif /* TARGET_PPC64 */
3162 /*** Integer load and store multiple ***/
3165 static void gen_lmw(DisasContext
*ctx
)
3169 gen_set_access_type(ctx
, ACCESS_INT
);
3170 /* NIP cannot be restored if the memory exception comes from an helper */
3171 gen_update_nip(ctx
, ctx
->nip
- 4);
3172 t0
= tcg_temp_new();
3173 t1
= tcg_const_i32(rD(ctx
->opcode
));
3174 gen_addr_imm_index(ctx
, t0
, 0);
3175 gen_helper_lmw(cpu_env
, t0
, t1
);
3177 tcg_temp_free_i32(t1
);
3181 static void gen_stmw(DisasContext
*ctx
)
3185 gen_set_access_type(ctx
, ACCESS_INT
);
3186 /* NIP cannot be restored if the memory exception comes from an helper */
3187 gen_update_nip(ctx
, ctx
->nip
- 4);
3188 t0
= tcg_temp_new();
3189 t1
= tcg_const_i32(rS(ctx
->opcode
));
3190 gen_addr_imm_index(ctx
, t0
, 0);
3191 gen_helper_stmw(cpu_env
, t0
, t1
);
3193 tcg_temp_free_i32(t1
);
3196 /*** Integer load and store strings ***/
3199 /* PowerPC32 specification says we must generate an exception if
3200 * rA is in the range of registers to be loaded.
3201 * In an other hand, IBM says this is valid, but rA won't be loaded.
3202 * For now, I'll follow the spec...
3204 static void gen_lswi(DisasContext
*ctx
)
3208 int nb
= NB(ctx
->opcode
);
3209 int start
= rD(ctx
->opcode
);
3210 int ra
= rA(ctx
->opcode
);
3216 if (unlikely(((start
+ nr
) > 32 &&
3217 start
<= ra
&& (start
+ nr
- 32) > ra
) ||
3218 ((start
+ nr
) <= 32 && start
<= ra
&& (start
+ nr
) > ra
))) {
3219 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
3222 gen_set_access_type(ctx
, ACCESS_INT
);
3223 /* NIP cannot be restored if the memory exception comes from an helper */
3224 gen_update_nip(ctx
, ctx
->nip
- 4);
3225 t0
= tcg_temp_new();
3226 gen_addr_register(ctx
, t0
);
3227 t1
= tcg_const_i32(nb
);
3228 t2
= tcg_const_i32(start
);
3229 gen_helper_lsw(cpu_env
, t0
, t1
, t2
);
3231 tcg_temp_free_i32(t1
);
3232 tcg_temp_free_i32(t2
);
3236 static void gen_lswx(DisasContext
*ctx
)
3239 TCGv_i32 t1
, t2
, t3
;
3240 gen_set_access_type(ctx
, ACCESS_INT
);
3241 /* NIP cannot be restored if the memory exception comes from an helper */
3242 gen_update_nip(ctx
, ctx
->nip
- 4);
3243 t0
= tcg_temp_new();
3244 gen_addr_reg_index(ctx
, t0
);
3245 t1
= tcg_const_i32(rD(ctx
->opcode
));
3246 t2
= tcg_const_i32(rA(ctx
->opcode
));
3247 t3
= tcg_const_i32(rB(ctx
->opcode
));
3248 gen_helper_lswx(cpu_env
, t0
, t1
, t2
, t3
);
3250 tcg_temp_free_i32(t1
);
3251 tcg_temp_free_i32(t2
);
3252 tcg_temp_free_i32(t3
);
3256 static void gen_stswi(DisasContext
*ctx
)
3260 int nb
= NB(ctx
->opcode
);
3261 gen_set_access_type(ctx
, ACCESS_INT
);
3262 /* NIP cannot be restored if the memory exception comes from an helper */
3263 gen_update_nip(ctx
, ctx
->nip
- 4);
3264 t0
= tcg_temp_new();
3265 gen_addr_register(ctx
, t0
);
3268 t1
= tcg_const_i32(nb
);
3269 t2
= tcg_const_i32(rS(ctx
->opcode
));
3270 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3272 tcg_temp_free_i32(t1
);
3273 tcg_temp_free_i32(t2
);
3277 static void gen_stswx(DisasContext
*ctx
)
3281 gen_set_access_type(ctx
, ACCESS_INT
);
3282 /* NIP cannot be restored if the memory exception comes from an helper */
3283 gen_update_nip(ctx
, ctx
->nip
- 4);
3284 t0
= tcg_temp_new();
3285 gen_addr_reg_index(ctx
, t0
);
3286 t1
= tcg_temp_new_i32();
3287 tcg_gen_trunc_tl_i32(t1
, cpu_xer
);
3288 tcg_gen_andi_i32(t1
, t1
, 0x7F);
3289 t2
= tcg_const_i32(rS(ctx
->opcode
));
3290 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3292 tcg_temp_free_i32(t1
);
3293 tcg_temp_free_i32(t2
);
3296 /*** Memory synchronisation ***/
3298 static void gen_eieio(DisasContext
*ctx
)
3303 static void gen_isync(DisasContext
*ctx
)
3305 gen_stop_exception(ctx
);
3308 #define LARX(name, len, loadop) \
3309 static void gen_##name(DisasContext *ctx) \
3312 TCGv gpr = cpu_gpr[rD(ctx->opcode)]; \
3313 gen_set_access_type(ctx, ACCESS_RES); \
3314 t0 = tcg_temp_local_new(); \
3315 gen_addr_reg_index(ctx, t0); \
3317 gen_check_align(ctx, t0, (len)-1); \
3319 gen_qemu_##loadop(ctx, gpr, t0); \
3320 tcg_gen_mov_tl(cpu_reserve, t0); \
3321 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); \
3322 tcg_temp_free(t0); \
3326 LARX(lbarx
, 1, ld8u
);
3327 LARX(lharx
, 2, ld16u
);
3328 LARX(lwarx
, 4, ld32u
);
3331 #if defined(CONFIG_USER_ONLY)
3332 static void gen_conditional_store(DisasContext
*ctx
, TCGv EA
,
3335 TCGv t0
= tcg_temp_new();
3336 uint32_t save_exception
= ctx
->exception
;
3338 tcg_gen_st_tl(EA
, cpu_env
, offsetof(CPUPPCState
, reserve_ea
));
3339 tcg_gen_movi_tl(t0
, (size
<< 5) | reg
);
3340 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, reserve_info
));
3342 gen_update_nip(ctx
, ctx
->nip
-4);
3343 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3344 gen_exception(ctx
, POWERPC_EXCP_STCX
);
3345 ctx
->exception
= save_exception
;
3348 static void gen_conditional_store(DisasContext
*ctx
, TCGv EA
,
3353 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
3354 l1
= gen_new_label();
3355 tcg_gen_brcond_tl(TCG_COND_NE
, EA
, cpu_reserve
, l1
);
3356 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3357 #if defined(TARGET_PPC64)
3359 gen_qemu_st64(ctx
, cpu_gpr
[reg
], EA
);
3363 gen_qemu_st32(ctx
, cpu_gpr
[reg
], EA
);
3364 } else if (size
== 2) {
3365 gen_qemu_st16(ctx
, cpu_gpr
[reg
], EA
);
3366 #if defined(TARGET_PPC64)
3367 } else if (size
== 16) {
3368 TCGv gpr1
, gpr2
, EA8
;
3369 if (unlikely(ctx
->le_mode
)) {
3370 gpr1
= cpu_gpr
[reg
+1];
3371 gpr2
= cpu_gpr
[reg
];
3373 gpr1
= cpu_gpr
[reg
];
3374 gpr2
= cpu_gpr
[reg
+1];
3376 gen_qemu_st64(ctx
, gpr1
, EA
);
3377 EA8
= tcg_temp_local_new();
3378 gen_addr_add(ctx
, EA8
, EA
, 8);
3379 gen_qemu_st64(ctx
, gpr2
, EA8
);
3383 gen_qemu_st8(ctx
, cpu_gpr
[reg
], EA
);
3386 tcg_gen_movi_tl(cpu_reserve
, -1);
3390 #define STCX(name, len) \
3391 static void gen_##name(DisasContext *ctx) \
3394 if (unlikely((len == 16) && (rD(ctx->opcode) & 1))) { \
3395 gen_inval_exception(ctx, \
3396 POWERPC_EXCP_INVAL_INVAL); \
3399 gen_set_access_type(ctx, ACCESS_RES); \
3400 t0 = tcg_temp_local_new(); \
3401 gen_addr_reg_index(ctx, t0); \
3403 gen_check_align(ctx, t0, (len)-1); \
3405 gen_conditional_store(ctx, t0, rS(ctx->opcode), len); \
3406 tcg_temp_free(t0); \
3413 #if defined(TARGET_PPC64)
3415 LARX(ldarx
, 8, ld64
);
3418 static void gen_lqarx(DisasContext
*ctx
)
3421 int rd
= rD(ctx
->opcode
);
3424 if (unlikely((rd
& 1) || (rd
== rA(ctx
->opcode
)) ||
3425 (rd
== rB(ctx
->opcode
)))) {
3426 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3430 gen_set_access_type(ctx
, ACCESS_RES
);
3431 EA
= tcg_temp_local_new();
3432 gen_addr_reg_index(ctx
, EA
);
3433 gen_check_align(ctx
, EA
, 15);
3434 if (unlikely(ctx
->le_mode
)) {
3435 gpr1
= cpu_gpr
[rd
+1];
3439 gpr2
= cpu_gpr
[rd
+1];
3441 gen_qemu_ld64(ctx
, gpr1
, EA
);
3442 tcg_gen_mov_tl(cpu_reserve
, EA
);
3444 gen_addr_add(ctx
, EA
, EA
, 8);
3445 gen_qemu_ld64(ctx
, gpr2
, EA
);
3447 tcg_gen_st_tl(gpr1
, cpu_env
, offsetof(CPUPPCState
, reserve_val
));
3448 tcg_gen_st_tl(gpr2
, cpu_env
, offsetof(CPUPPCState
, reserve_val2
));
3456 #endif /* defined(TARGET_PPC64) */
3459 static void gen_sync(DisasContext
*ctx
)
3464 static void gen_wait(DisasContext
*ctx
)
3466 TCGv_i32 t0
= tcg_temp_new_i32();
3467 tcg_gen_st_i32(t0
, cpu_env
,
3468 -offsetof(PowerPCCPU
, env
) + offsetof(CPUState
, halted
));
3469 tcg_temp_free_i32(t0
);
3470 /* Stop translation, as the CPU is supposed to sleep from now */
3471 gen_exception_err(ctx
, EXCP_HLT
, 1);
3474 /*** Floating-point load ***/
3475 #define GEN_LDF(name, ldop, opc, type) \
3476 static void glue(gen_, name)(DisasContext *ctx) \
3479 if (unlikely(!ctx->fpu_enabled)) { \
3480 gen_exception(ctx, POWERPC_EXCP_FPU); \
3483 gen_set_access_type(ctx, ACCESS_FLOAT); \
3484 EA = tcg_temp_new(); \
3485 gen_addr_imm_index(ctx, EA, 0); \
3486 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3487 tcg_temp_free(EA); \
3490 #define GEN_LDUF(name, ldop, opc, type) \
3491 static void glue(gen_, name##u)(DisasContext *ctx) \
3494 if (unlikely(!ctx->fpu_enabled)) { \
3495 gen_exception(ctx, POWERPC_EXCP_FPU); \
3498 if (unlikely(rA(ctx->opcode) == 0)) { \
3499 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3502 gen_set_access_type(ctx, ACCESS_FLOAT); \
3503 EA = tcg_temp_new(); \
3504 gen_addr_imm_index(ctx, EA, 0); \
3505 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3506 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3507 tcg_temp_free(EA); \
3510 #define GEN_LDUXF(name, ldop, opc, type) \
3511 static void glue(gen_, name##ux)(DisasContext *ctx) \
3514 if (unlikely(!ctx->fpu_enabled)) { \
3515 gen_exception(ctx, POWERPC_EXCP_FPU); \
3518 if (unlikely(rA(ctx->opcode) == 0)) { \
3519 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3522 gen_set_access_type(ctx, ACCESS_FLOAT); \
3523 EA = tcg_temp_new(); \
3524 gen_addr_reg_index(ctx, EA); \
3525 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3526 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3527 tcg_temp_free(EA); \
3530 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
3531 static void glue(gen_, name##x)(DisasContext *ctx) \
3534 if (unlikely(!ctx->fpu_enabled)) { \
3535 gen_exception(ctx, POWERPC_EXCP_FPU); \
3538 gen_set_access_type(ctx, ACCESS_FLOAT); \
3539 EA = tcg_temp_new(); \
3540 gen_addr_reg_index(ctx, EA); \
3541 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3542 tcg_temp_free(EA); \
3545 #define GEN_LDFS(name, ldop, op, type) \
3546 GEN_LDF(name, ldop, op | 0x20, type); \
3547 GEN_LDUF(name, ldop, op | 0x21, type); \
3548 GEN_LDUXF(name, ldop, op | 0x01, type); \
3549 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3551 static inline void gen_qemu_ld32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3553 TCGv t0
= tcg_temp_new();
3554 TCGv_i32 t1
= tcg_temp_new_i32();
3555 gen_qemu_ld32u(ctx
, t0
, arg2
);
3556 tcg_gen_trunc_tl_i32(t1
, t0
);
3558 gen_helper_float32_to_float64(arg1
, cpu_env
, t1
);
3559 tcg_temp_free_i32(t1
);
3562 /* lfd lfdu lfdux lfdx */
3563 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
);
3564 /* lfs lfsu lfsux lfsx */
3565 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
);
3568 static void gen_lfdp(DisasContext
*ctx
)
3571 if (unlikely(!ctx
->fpu_enabled
)) {
3572 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3575 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3576 EA
= tcg_temp_new();
3577 gen_addr_imm_index(ctx
, EA
, 0);
3578 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
3579 64-bit byteswap already. */
3580 if (unlikely(ctx
->le_mode
)) {
3581 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3582 tcg_gen_addi_tl(EA
, EA
, 8);
3583 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3585 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3586 tcg_gen_addi_tl(EA
, EA
, 8);
3587 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3593 static void gen_lfdpx(DisasContext
*ctx
)
3596 if (unlikely(!ctx
->fpu_enabled
)) {
3597 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3600 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3601 EA
= tcg_temp_new();
3602 gen_addr_reg_index(ctx
, EA
);
3603 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
3604 64-bit byteswap already. */
3605 if (unlikely(ctx
->le_mode
)) {
3606 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3607 tcg_gen_addi_tl(EA
, EA
, 8);
3608 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3610 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3611 tcg_gen_addi_tl(EA
, EA
, 8);
3612 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3618 static void gen_lfiwax(DisasContext
*ctx
)
3622 if (unlikely(!ctx
->fpu_enabled
)) {
3623 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3626 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3627 EA
= tcg_temp_new();
3628 t0
= tcg_temp_new();
3629 gen_addr_reg_index(ctx
, EA
);
3630 gen_qemu_ld32s(ctx
, t0
, EA
);
3631 tcg_gen_ext_tl_i64(cpu_fpr
[rD(ctx
->opcode
)], t0
);
3637 static void gen_lfiwzx(DisasContext
*ctx
)
3640 if (unlikely(!ctx
->fpu_enabled
)) {
3641 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3644 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3645 EA
= tcg_temp_new();
3646 gen_addr_reg_index(ctx
, EA
);
3647 gen_qemu_ld32u_i64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3650 /*** Floating-point store ***/
3651 #define GEN_STF(name, stop, opc, type) \
3652 static void glue(gen_, name)(DisasContext *ctx) \
3655 if (unlikely(!ctx->fpu_enabled)) { \
3656 gen_exception(ctx, POWERPC_EXCP_FPU); \
3659 gen_set_access_type(ctx, ACCESS_FLOAT); \
3660 EA = tcg_temp_new(); \
3661 gen_addr_imm_index(ctx, EA, 0); \
3662 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3663 tcg_temp_free(EA); \
3666 #define GEN_STUF(name, stop, opc, type) \
3667 static void glue(gen_, name##u)(DisasContext *ctx) \
3670 if (unlikely(!ctx->fpu_enabled)) { \
3671 gen_exception(ctx, POWERPC_EXCP_FPU); \
3674 if (unlikely(rA(ctx->opcode) == 0)) { \
3675 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3678 gen_set_access_type(ctx, ACCESS_FLOAT); \
3679 EA = tcg_temp_new(); \
3680 gen_addr_imm_index(ctx, EA, 0); \
3681 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3682 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3683 tcg_temp_free(EA); \
3686 #define GEN_STUXF(name, stop, opc, type) \
3687 static void glue(gen_, name##ux)(DisasContext *ctx) \
3690 if (unlikely(!ctx->fpu_enabled)) { \
3691 gen_exception(ctx, POWERPC_EXCP_FPU); \
3694 if (unlikely(rA(ctx->opcode) == 0)) { \
3695 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3698 gen_set_access_type(ctx, ACCESS_FLOAT); \
3699 EA = tcg_temp_new(); \
3700 gen_addr_reg_index(ctx, EA); \
3701 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3702 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3703 tcg_temp_free(EA); \
3706 #define GEN_STXF(name, stop, opc2, opc3, type) \
3707 static void glue(gen_, name##x)(DisasContext *ctx) \
3710 if (unlikely(!ctx->fpu_enabled)) { \
3711 gen_exception(ctx, POWERPC_EXCP_FPU); \
3714 gen_set_access_type(ctx, ACCESS_FLOAT); \
3715 EA = tcg_temp_new(); \
3716 gen_addr_reg_index(ctx, EA); \
3717 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3718 tcg_temp_free(EA); \
3721 #define GEN_STFS(name, stop, op, type) \
3722 GEN_STF(name, stop, op | 0x20, type); \
3723 GEN_STUF(name, stop, op | 0x21, type); \
3724 GEN_STUXF(name, stop, op | 0x01, type); \
3725 GEN_STXF(name, stop, 0x17, op | 0x00, type)
3727 static inline void gen_qemu_st32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3729 TCGv_i32 t0
= tcg_temp_new_i32();
3730 TCGv t1
= tcg_temp_new();
3731 gen_helper_float64_to_float32(t0
, cpu_env
, arg1
);
3732 tcg_gen_extu_i32_tl(t1
, t0
);
3733 tcg_temp_free_i32(t0
);
3734 gen_qemu_st32(ctx
, t1
, arg2
);
3738 /* stfd stfdu stfdux stfdx */
3739 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
);
3740 /* stfs stfsu stfsux stfsx */
3741 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
);
3744 static void gen_stfdp(DisasContext
*ctx
)
3747 if (unlikely(!ctx
->fpu_enabled
)) {
3748 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3751 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3752 EA
= tcg_temp_new();
3753 gen_addr_imm_index(ctx
, EA
, 0);
3754 /* We only need to swap high and low halves. gen_qemu_st64 does necessary
3755 64-bit byteswap already. */
3756 if (unlikely(ctx
->le_mode
)) {
3757 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3758 tcg_gen_addi_tl(EA
, EA
, 8);
3759 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3761 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3762 tcg_gen_addi_tl(EA
, EA
, 8);
3763 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3769 static void gen_stfdpx(DisasContext
*ctx
)
3772 if (unlikely(!ctx
->fpu_enabled
)) {
3773 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3776 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3777 EA
= tcg_temp_new();
3778 gen_addr_reg_index(ctx
, EA
);
3779 /* We only need to swap high and low halves. gen_qemu_st64 does necessary
3780 64-bit byteswap already. */
3781 if (unlikely(ctx
->le_mode
)) {
3782 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3783 tcg_gen_addi_tl(EA
, EA
, 8);
3784 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3786 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3787 tcg_gen_addi_tl(EA
, EA
, 8);
3788 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3794 static inline void gen_qemu_st32fiw(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3796 TCGv t0
= tcg_temp_new();
3797 tcg_gen_trunc_i64_tl(t0
, arg1
),
3798 gen_qemu_st32(ctx
, t0
, arg2
);
3802 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
);
3804 static inline void gen_update_cfar(DisasContext
*ctx
, target_ulong nip
)
3806 #if defined(TARGET_PPC64)
3808 tcg_gen_movi_tl(cpu_cfar
, nip
);
3813 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
3815 TranslationBlock
*tb
;
3817 if (NARROW_MODE(ctx
)) {
3818 dest
= (uint32_t) dest
;
3820 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
3821 likely(!ctx
->singlestep_enabled
)) {
3823 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3824 tcg_gen_exit_tb((uintptr_t)tb
+ n
);
3826 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3827 if (unlikely(ctx
->singlestep_enabled
)) {
3828 if ((ctx
->singlestep_enabled
&
3829 (CPU_BRANCH_STEP
| CPU_SINGLE_STEP
)) &&
3830 (ctx
->exception
== POWERPC_EXCP_BRANCH
||
3831 ctx
->exception
== POWERPC_EXCP_TRACE
)) {
3832 target_ulong tmp
= ctx
->nip
;
3834 gen_exception(ctx
, POWERPC_EXCP_TRACE
);
3837 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
3838 gen_debug_exception(ctx
);
3845 static inline void gen_setlr(DisasContext
*ctx
, target_ulong nip
)
3847 if (NARROW_MODE(ctx
)) {
3848 nip
= (uint32_t)nip
;
3850 tcg_gen_movi_tl(cpu_lr
, nip
);
3854 static void gen_b(DisasContext
*ctx
)
3856 target_ulong li
, target
;
3858 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3859 /* sign extend LI */
3860 li
= LI(ctx
->opcode
);
3861 li
= (li
^ 0x02000000) - 0x02000000;
3862 if (likely(AA(ctx
->opcode
) == 0)) {
3863 target
= ctx
->nip
+ li
- 4;
3867 if (LK(ctx
->opcode
)) {
3868 gen_setlr(ctx
, ctx
->nip
);
3870 gen_update_cfar(ctx
, ctx
->nip
);
3871 gen_goto_tb(ctx
, 0, target
);
3879 static inline void gen_bcond(DisasContext
*ctx
, int type
)
3881 uint32_t bo
= BO(ctx
->opcode
);
3885 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3886 if (type
== BCOND_LR
|| type
== BCOND_CTR
|| type
== BCOND_TAR
) {
3887 target
= tcg_temp_local_new();
3888 if (type
== BCOND_CTR
)
3889 tcg_gen_mov_tl(target
, cpu_ctr
);
3890 else if (type
== BCOND_TAR
)
3891 gen_load_spr(target
, SPR_TAR
);
3893 tcg_gen_mov_tl(target
, cpu_lr
);
3895 TCGV_UNUSED(target
);
3897 if (LK(ctx
->opcode
))
3898 gen_setlr(ctx
, ctx
->nip
);
3899 l1
= gen_new_label();
3900 if ((bo
& 0x4) == 0) {
3901 /* Decrement and test CTR */
3902 TCGv temp
= tcg_temp_new();
3903 if (unlikely(type
== BCOND_CTR
)) {
3904 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3907 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
3908 if (NARROW_MODE(ctx
)) {
3909 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
3911 tcg_gen_mov_tl(temp
, cpu_ctr
);
3914 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
3916 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
3918 tcg_temp_free(temp
);
3920 if ((bo
& 0x10) == 0) {
3922 uint32_t bi
= BI(ctx
->opcode
);
3923 uint32_t mask
= 0x08 >> (bi
& 0x03);
3924 TCGv_i32 temp
= tcg_temp_new_i32();
3927 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3928 tcg_gen_brcondi_i32(TCG_COND_EQ
, temp
, 0, l1
);
3930 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3931 tcg_gen_brcondi_i32(TCG_COND_NE
, temp
, 0, l1
);
3933 tcg_temp_free_i32(temp
);
3935 gen_update_cfar(ctx
, ctx
->nip
);
3936 if (type
== BCOND_IM
) {
3937 target_ulong li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
3938 if (likely(AA(ctx
->opcode
) == 0)) {
3939 gen_goto_tb(ctx
, 0, ctx
->nip
+ li
- 4);
3941 gen_goto_tb(ctx
, 0, li
);
3944 gen_goto_tb(ctx
, 1, ctx
->nip
);
3946 if (NARROW_MODE(ctx
)) {
3947 tcg_gen_andi_tl(cpu_nip
, target
, (uint32_t)~3);
3949 tcg_gen_andi_tl(cpu_nip
, target
, ~3);
3953 gen_update_nip(ctx
, ctx
->nip
);
3956 if (type
== BCOND_LR
|| type
== BCOND_CTR
|| type
== BCOND_TAR
) {
3957 tcg_temp_free(target
);
3961 static void gen_bc(DisasContext
*ctx
)
3963 gen_bcond(ctx
, BCOND_IM
);
3966 static void gen_bcctr(DisasContext
*ctx
)
3968 gen_bcond(ctx
, BCOND_CTR
);
3971 static void gen_bclr(DisasContext
*ctx
)
3973 gen_bcond(ctx
, BCOND_LR
);
3976 static void gen_bctar(DisasContext
*ctx
)
3978 gen_bcond(ctx
, BCOND_TAR
);
3981 /*** Condition register logical ***/
3982 #define GEN_CRLOGIC(name, tcg_op, opc) \
3983 static void glue(gen_, name)(DisasContext *ctx) \
3988 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3989 t0 = tcg_temp_new_i32(); \
3991 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
3993 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
3995 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
3996 t1 = tcg_temp_new_i32(); \
3997 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3999 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
4001 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
4003 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
4004 tcg_op(t0, t0, t1); \
4005 bitmask = 0x08 >> (crbD(ctx->opcode) & 0x03); \
4006 tcg_gen_andi_i32(t0, t0, bitmask); \
4007 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
4008 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
4009 tcg_temp_free_i32(t0); \
4010 tcg_temp_free_i32(t1); \
4014 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08);
4016 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04);
4018 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09);
4020 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07);
4022 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01);
4024 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E);
4026 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D);
4028 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06);
4031 static void gen_mcrf(DisasContext
*ctx
)
4033 tcg_gen_mov_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfS(ctx
->opcode
)]);
4036 /*** System linkage ***/
4038 /* rfi (supervisor only) */
4039 static void gen_rfi(DisasContext
*ctx
)
4041 #if defined(CONFIG_USER_ONLY)
4042 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4044 /* Restore CPU state */
4045 if (unlikely(ctx
->pr
)) {
4046 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4049 gen_update_cfar(ctx
, ctx
->nip
);
4050 gen_helper_rfi(cpu_env
);
4051 gen_sync_exception(ctx
);
4055 #if defined(TARGET_PPC64)
4056 static void gen_rfid(DisasContext
*ctx
)
4058 #if defined(CONFIG_USER_ONLY)
4059 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4061 /* Restore CPU state */
4062 if (unlikely(ctx
->pr
)) {
4063 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4066 gen_update_cfar(ctx
, ctx
->nip
);
4067 gen_helper_rfid(cpu_env
);
4068 gen_sync_exception(ctx
);
4072 static void gen_hrfid(DisasContext
*ctx
)
4074 #if defined(CONFIG_USER_ONLY)
4075 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4077 /* Restore CPU state */
4078 if (unlikely(!ctx
->hv
)) {
4079 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4082 gen_helper_hrfid(cpu_env
);
4083 gen_sync_exception(ctx
);
4089 #if defined(CONFIG_USER_ONLY)
4090 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
4092 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
4094 static void gen_sc(DisasContext
*ctx
)
4098 lev
= (ctx
->opcode
>> 5) & 0x7F;
4099 gen_exception_err(ctx
, POWERPC_SYSCALL
, lev
);
4105 static void gen_tw(DisasContext
*ctx
)
4107 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
4108 /* Update the nip since this might generate a trap exception */
4109 gen_update_nip(ctx
, ctx
->nip
);
4110 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
4112 tcg_temp_free_i32(t0
);
4116 static void gen_twi(DisasContext
*ctx
)
4118 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
4119 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
4120 /* Update the nip since this might generate a trap exception */
4121 gen_update_nip(ctx
, ctx
->nip
);
4122 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4124 tcg_temp_free_i32(t1
);
4127 #if defined(TARGET_PPC64)
4129 static void gen_td(DisasContext
*ctx
)
4131 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
4132 /* Update the nip since this might generate a trap exception */
4133 gen_update_nip(ctx
, ctx
->nip
);
4134 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
4136 tcg_temp_free_i32(t0
);
4140 static void gen_tdi(DisasContext
*ctx
)
4142 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
4143 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
4144 /* Update the nip since this might generate a trap exception */
4145 gen_update_nip(ctx
, ctx
->nip
);
4146 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4148 tcg_temp_free_i32(t1
);
4152 /*** Processor control ***/
4154 static void gen_read_xer(TCGv dst
)
4156 TCGv t0
= tcg_temp_new();
4157 TCGv t1
= tcg_temp_new();
4158 TCGv t2
= tcg_temp_new();
4159 tcg_gen_mov_tl(dst
, cpu_xer
);
4160 tcg_gen_shli_tl(t0
, cpu_so
, XER_SO
);
4161 tcg_gen_shli_tl(t1
, cpu_ov
, XER_OV
);
4162 tcg_gen_shli_tl(t2
, cpu_ca
, XER_CA
);
4163 tcg_gen_or_tl(t0
, t0
, t1
);
4164 tcg_gen_or_tl(dst
, dst
, t2
);
4165 tcg_gen_or_tl(dst
, dst
, t0
);
4171 static void gen_write_xer(TCGv src
)
4173 tcg_gen_andi_tl(cpu_xer
, src
,
4174 ~((1u << XER_SO
) | (1u << XER_OV
) | (1u << XER_CA
)));
4175 tcg_gen_shri_tl(cpu_so
, src
, XER_SO
);
4176 tcg_gen_shri_tl(cpu_ov
, src
, XER_OV
);
4177 tcg_gen_shri_tl(cpu_ca
, src
, XER_CA
);
4178 tcg_gen_andi_tl(cpu_so
, cpu_so
, 1);
4179 tcg_gen_andi_tl(cpu_ov
, cpu_ov
, 1);
4180 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
4184 static void gen_mcrxr(DisasContext
*ctx
)
4186 TCGv_i32 t0
= tcg_temp_new_i32();
4187 TCGv_i32 t1
= tcg_temp_new_i32();
4188 TCGv_i32 dst
= cpu_crf
[crfD(ctx
->opcode
)];
4190 tcg_gen_trunc_tl_i32(t0
, cpu_so
);
4191 tcg_gen_trunc_tl_i32(t1
, cpu_ov
);
4192 tcg_gen_trunc_tl_i32(dst
, cpu_ca
);
4193 tcg_gen_shli_i32(t0
, t0
, 3);
4194 tcg_gen_shli_i32(t1
, t1
, 2);
4195 tcg_gen_shli_i32(dst
, dst
, 1);
4196 tcg_gen_or_i32(dst
, dst
, t0
);
4197 tcg_gen_or_i32(dst
, dst
, t1
);
4198 tcg_temp_free_i32(t0
);
4199 tcg_temp_free_i32(t1
);
4201 tcg_gen_movi_tl(cpu_so
, 0);
4202 tcg_gen_movi_tl(cpu_ov
, 0);
4203 tcg_gen_movi_tl(cpu_ca
, 0);
4207 static void gen_mfcr(DisasContext
*ctx
)
4211 if (likely(ctx
->opcode
& 0x00100000)) {
4212 crm
= CRM(ctx
->opcode
);
4213 if (likely(crm
&& ((crm
& (crm
- 1)) == 0))) {
4215 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_crf
[7 - crn
]);
4216 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)],
4217 cpu_gpr
[rD(ctx
->opcode
)], crn
* 4);
4220 TCGv_i32 t0
= tcg_temp_new_i32();
4221 tcg_gen_mov_i32(t0
, cpu_crf
[0]);
4222 tcg_gen_shli_i32(t0
, t0
, 4);
4223 tcg_gen_or_i32(t0
, t0
, cpu_crf
[1]);
4224 tcg_gen_shli_i32(t0
, t0
, 4);
4225 tcg_gen_or_i32(t0
, t0
, cpu_crf
[2]);
4226 tcg_gen_shli_i32(t0
, t0
, 4);
4227 tcg_gen_or_i32(t0
, t0
, cpu_crf
[3]);
4228 tcg_gen_shli_i32(t0
, t0
, 4);
4229 tcg_gen_or_i32(t0
, t0
, cpu_crf
[4]);
4230 tcg_gen_shli_i32(t0
, t0
, 4);
4231 tcg_gen_or_i32(t0
, t0
, cpu_crf
[5]);
4232 tcg_gen_shli_i32(t0
, t0
, 4);
4233 tcg_gen_or_i32(t0
, t0
, cpu_crf
[6]);
4234 tcg_gen_shli_i32(t0
, t0
, 4);
4235 tcg_gen_or_i32(t0
, t0
, cpu_crf
[7]);
4236 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4237 tcg_temp_free_i32(t0
);
4242 static void gen_mfmsr(DisasContext
*ctx
)
4244 #if defined(CONFIG_USER_ONLY)
4245 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4247 if (unlikely(ctx
->pr
)) {
4248 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4251 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_msr
);
4255 static void spr_noaccess(DisasContext
*ctx
, int gprn
, int sprn
)
4258 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
4259 printf("ERROR: try to access SPR %d !\n", sprn
);
4262 #define SPR_NOACCESS (&spr_noaccess)
4265 static inline void gen_op_mfspr(DisasContext
*ctx
)
4267 void (*read_cb
)(DisasContext
*ctx
, int gprn
, int sprn
);
4268 uint32_t sprn
= SPR(ctx
->opcode
);
4270 #if !defined(CONFIG_USER_ONLY)
4272 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
4274 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
4277 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
4278 if (likely(read_cb
!= NULL
)) {
4279 if (likely(read_cb
!= SPR_NOACCESS
)) {
4280 (*read_cb
)(ctx
, rD(ctx
->opcode
), sprn
);
4282 /* Privilege exception */
4283 /* This is a hack to avoid warnings when running Linux:
4284 * this OS breaks the PowerPC virtualisation model,
4285 * allowing userland application to read the PVR
4287 if (sprn
!= SPR_PVR
) {
4288 fprintf(stderr
, "Trying to read privileged spr %d (0x%03x) at "
4289 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4290 if (qemu_log_separate()) {
4291 qemu_log("Trying to read privileged spr %d (0x%03x) at "
4292 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4295 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4299 fprintf(stderr
, "Trying to read invalid spr %d (0x%03x) at "
4300 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4301 if (qemu_log_separate()) {
4302 qemu_log("Trying to read invalid spr %d (0x%03x) at "
4303 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4305 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4309 static void gen_mfspr(DisasContext
*ctx
)
4315 static void gen_mftb(DisasContext
*ctx
)
4321 static void gen_mtcrf(DisasContext
*ctx
)
4325 crm
= CRM(ctx
->opcode
);
4326 if (likely((ctx
->opcode
& 0x00100000))) {
4327 if (crm
&& ((crm
& (crm
- 1)) == 0)) {
4328 TCGv_i32 temp
= tcg_temp_new_i32();
4330 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
4331 tcg_gen_shri_i32(temp
, temp
, crn
* 4);
4332 tcg_gen_andi_i32(cpu_crf
[7 - crn
], temp
, 0xf);
4333 tcg_temp_free_i32(temp
);
4336 TCGv_i32 temp
= tcg_temp_new_i32();
4337 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
4338 for (crn
= 0 ; crn
< 8 ; crn
++) {
4339 if (crm
& (1 << crn
)) {
4340 tcg_gen_shri_i32(cpu_crf
[7 - crn
], temp
, crn
* 4);
4341 tcg_gen_andi_i32(cpu_crf
[7 - crn
], cpu_crf
[7 - crn
], 0xf);
4344 tcg_temp_free_i32(temp
);
4349 #if defined(TARGET_PPC64)
4350 static void gen_mtmsrd(DisasContext
*ctx
)
4352 #if defined(CONFIG_USER_ONLY)
4353 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4355 if (unlikely(ctx
->pr
)) {
4356 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4359 if (ctx
->opcode
& 0x00010000) {
4360 /* Special form that does not need any synchronisation */
4361 TCGv t0
= tcg_temp_new();
4362 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
4363 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
4364 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
4367 /* XXX: we need to update nip before the store
4368 * if we enter power saving mode, we will exit the loop
4369 * directly from ppc_store_msr
4371 gen_update_nip(ctx
, ctx
->nip
);
4372 gen_helper_store_msr(cpu_env
, cpu_gpr
[rS(ctx
->opcode
)]);
4373 /* Must stop the translation as machine state (may have) changed */
4374 /* Note that mtmsr is not always defined as context-synchronizing */
4375 gen_stop_exception(ctx
);
4381 static void gen_mtmsr(DisasContext
*ctx
)
4383 #if defined(CONFIG_USER_ONLY)
4384 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4386 if (unlikely(ctx
->pr
)) {
4387 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4390 if (ctx
->opcode
& 0x00010000) {
4391 /* Special form that does not need any synchronisation */
4392 TCGv t0
= tcg_temp_new();
4393 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
4394 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
4395 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
4398 TCGv msr
= tcg_temp_new();
4400 /* XXX: we need to update nip before the store
4401 * if we enter power saving mode, we will exit the loop
4402 * directly from ppc_store_msr
4404 gen_update_nip(ctx
, ctx
->nip
);
4405 #if defined(TARGET_PPC64)
4406 tcg_gen_deposit_tl(msr
, cpu_msr
, cpu_gpr
[rS(ctx
->opcode
)], 0, 32);
4408 tcg_gen_mov_tl(msr
, cpu_gpr
[rS(ctx
->opcode
)]);
4410 gen_helper_store_msr(cpu_env
, msr
);
4412 /* Must stop the translation as machine state (may have) changed */
4413 /* Note that mtmsr is not always defined as context-synchronizing */
4414 gen_stop_exception(ctx
);
4420 static void gen_mtspr(DisasContext
*ctx
)
4422 void (*write_cb
)(DisasContext
*ctx
, int sprn
, int gprn
);
4423 uint32_t sprn
= SPR(ctx
->opcode
);
4425 #if !defined(CONFIG_USER_ONLY)
4427 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
4429 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
4432 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
4433 if (likely(write_cb
!= NULL
)) {
4434 if (likely(write_cb
!= SPR_NOACCESS
)) {
4435 (*write_cb
)(ctx
, sprn
, rS(ctx
->opcode
));
4437 /* Privilege exception */
4438 fprintf(stderr
, "Trying to write privileged spr %d (0x%03x) at "
4439 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4440 if (qemu_log_separate()) {
4441 qemu_log("Trying to write privileged spr %d (0x%03x) at "
4442 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4444 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4448 if (qemu_log_separate()) {
4449 qemu_log("Trying to write invalid spr %d (0x%03x) at "
4450 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4452 fprintf(stderr
, "Trying to write invalid spr %d (0x%03x) at "
4453 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4454 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4458 /*** Cache management ***/
4461 static void gen_dcbf(DisasContext
*ctx
)
4463 /* XXX: specification says this is treated as a load by the MMU */
4465 gen_set_access_type(ctx
, ACCESS_CACHE
);
4466 t0
= tcg_temp_new();
4467 gen_addr_reg_index(ctx
, t0
);
4468 gen_qemu_ld8u(ctx
, t0
, t0
);
4472 /* dcbi (Supervisor only) */
4473 static void gen_dcbi(DisasContext
*ctx
)
4475 #if defined(CONFIG_USER_ONLY)
4476 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4479 if (unlikely(ctx
->pr
)) {
4480 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4483 EA
= tcg_temp_new();
4484 gen_set_access_type(ctx
, ACCESS_CACHE
);
4485 gen_addr_reg_index(ctx
, EA
);
4486 val
= tcg_temp_new();
4487 /* XXX: specification says this should be treated as a store by the MMU */
4488 gen_qemu_ld8u(ctx
, val
, EA
);
4489 gen_qemu_st8(ctx
, val
, EA
);
4496 static void gen_dcbst(DisasContext
*ctx
)
4498 /* XXX: specification say this is treated as a load by the MMU */
4500 gen_set_access_type(ctx
, ACCESS_CACHE
);
4501 t0
= tcg_temp_new();
4502 gen_addr_reg_index(ctx
, t0
);
4503 gen_qemu_ld8u(ctx
, t0
, t0
);
4508 static void gen_dcbt(DisasContext
*ctx
)
4510 /* interpreted as no-op */
4511 /* XXX: specification say this is treated as a load by the MMU
4512 * but does not generate any exception
4517 static void gen_dcbtst(DisasContext
*ctx
)
4519 /* interpreted as no-op */
4520 /* XXX: specification say this is treated as a load by the MMU
4521 * but does not generate any exception
4526 static void gen_dcbtls(DisasContext
*ctx
)
4528 /* Always fails locking the cache */
4529 TCGv t0
= tcg_temp_new();
4530 gen_load_spr(t0
, SPR_Exxx_L1CSR0
);
4531 tcg_gen_ori_tl(t0
, t0
, L1CSR0_CUL
);
4532 gen_store_spr(SPR_Exxx_L1CSR0
, t0
);
4537 static void gen_dcbz(DisasContext
*ctx
)
4540 TCGv_i32 tcgv_is_dcbzl
;
4541 int is_dcbzl
= ctx
->opcode
& 0x00200000 ? 1 : 0;
4543 gen_set_access_type(ctx
, ACCESS_CACHE
);
4544 /* NIP cannot be restored if the memory exception comes from an helper */
4545 gen_update_nip(ctx
, ctx
->nip
- 4);
4546 tcgv_addr
= tcg_temp_new();
4547 tcgv_is_dcbzl
= tcg_const_i32(is_dcbzl
);
4549 gen_addr_reg_index(ctx
, tcgv_addr
);
4550 gen_helper_dcbz(cpu_env
, tcgv_addr
, tcgv_is_dcbzl
);
4552 tcg_temp_free(tcgv_addr
);
4553 tcg_temp_free_i32(tcgv_is_dcbzl
);
4557 static void gen_dst(DisasContext
*ctx
)
4559 if (rA(ctx
->opcode
) == 0) {
4560 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
4562 /* interpreted as no-op */
4567 static void gen_dstst(DisasContext
*ctx
)
4569 if (rA(ctx
->opcode
) == 0) {
4570 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
4572 /* interpreted as no-op */
4578 static void gen_dss(DisasContext
*ctx
)
4580 /* interpreted as no-op */
4584 static void gen_icbi(DisasContext
*ctx
)
4587 gen_set_access_type(ctx
, ACCESS_CACHE
);
4588 /* NIP cannot be restored if the memory exception comes from an helper */
4589 gen_update_nip(ctx
, ctx
->nip
- 4);
4590 t0
= tcg_temp_new();
4591 gen_addr_reg_index(ctx
, t0
);
4592 gen_helper_icbi(cpu_env
, t0
);
4598 static void gen_dcba(DisasContext
*ctx
)
4600 /* interpreted as no-op */
4601 /* XXX: specification say this is treated as a store by the MMU
4602 * but does not generate any exception
4606 /*** Segment register manipulation ***/
4607 /* Supervisor only: */
4610 static void gen_mfsr(DisasContext
*ctx
)
4612 #if defined(CONFIG_USER_ONLY)
4613 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4616 if (unlikely(ctx
->pr
)) {
4617 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4620 t0
= tcg_const_tl(SR(ctx
->opcode
));
4621 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4627 static void gen_mfsrin(DisasContext
*ctx
)
4629 #if defined(CONFIG_USER_ONLY)
4630 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4633 if (unlikely(ctx
->pr
)) {
4634 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4637 t0
= tcg_temp_new();
4638 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4639 tcg_gen_andi_tl(t0
, t0
, 0xF);
4640 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4646 static void gen_mtsr(DisasContext
*ctx
)
4648 #if defined(CONFIG_USER_ONLY)
4649 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4652 if (unlikely(ctx
->pr
)) {
4653 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4656 t0
= tcg_const_tl(SR(ctx
->opcode
));
4657 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4663 static void gen_mtsrin(DisasContext
*ctx
)
4665 #if defined(CONFIG_USER_ONLY)
4666 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4669 if (unlikely(ctx
->pr
)) {
4670 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4673 t0
= tcg_temp_new();
4674 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4675 tcg_gen_andi_tl(t0
, t0
, 0xF);
4676 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rD(ctx
->opcode
)]);
4681 #if defined(TARGET_PPC64)
4682 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4685 static void gen_mfsr_64b(DisasContext
*ctx
)
4687 #if defined(CONFIG_USER_ONLY)
4688 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4691 if (unlikely(ctx
->pr
)) {
4692 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4695 t0
= tcg_const_tl(SR(ctx
->opcode
));
4696 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4702 static void gen_mfsrin_64b(DisasContext
*ctx
)
4704 #if defined(CONFIG_USER_ONLY)
4705 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4708 if (unlikely(ctx
->pr
)) {
4709 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4712 t0
= tcg_temp_new();
4713 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4714 tcg_gen_andi_tl(t0
, t0
, 0xF);
4715 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4721 static void gen_mtsr_64b(DisasContext
*ctx
)
4723 #if defined(CONFIG_USER_ONLY)
4724 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4727 if (unlikely(ctx
->pr
)) {
4728 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4731 t0
= tcg_const_tl(SR(ctx
->opcode
));
4732 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4738 static void gen_mtsrin_64b(DisasContext
*ctx
)
4740 #if defined(CONFIG_USER_ONLY)
4741 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4744 if (unlikely(ctx
->pr
)) {
4745 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4748 t0
= tcg_temp_new();
4749 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4750 tcg_gen_andi_tl(t0
, t0
, 0xF);
4751 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4757 static void gen_slbmte(DisasContext
*ctx
)
4759 #if defined(CONFIG_USER_ONLY)
4760 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4762 if (unlikely(ctx
->pr
)) {
4763 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4766 gen_helper_store_slb(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)],
4767 cpu_gpr
[rS(ctx
->opcode
)]);
4771 static void gen_slbmfee(DisasContext
*ctx
)
4773 #if defined(CONFIG_USER_ONLY)
4774 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4776 if (unlikely(ctx
->pr
)) {
4777 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4780 gen_helper_load_slb_esid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4781 cpu_gpr
[rB(ctx
->opcode
)]);
4785 static void gen_slbmfev(DisasContext
*ctx
)
4787 #if defined(CONFIG_USER_ONLY)
4788 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4790 if (unlikely(ctx
->pr
)) {
4791 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4794 gen_helper_load_slb_vsid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4795 cpu_gpr
[rB(ctx
->opcode
)]);
4798 #endif /* defined(TARGET_PPC64) */
4800 /*** Lookaside buffer management ***/
4801 /* Optional & supervisor only: */
4804 static void gen_tlbia(DisasContext
*ctx
)
4806 #if defined(CONFIG_USER_ONLY)
4807 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4809 if (unlikely(ctx
->pr
)) {
4810 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4813 gen_helper_tlbia(cpu_env
);
4818 static void gen_tlbiel(DisasContext
*ctx
)
4820 #if defined(CONFIG_USER_ONLY)
4821 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4823 if (unlikely(ctx
->pr
)) {
4824 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4827 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4832 static void gen_tlbie(DisasContext
*ctx
)
4834 #if defined(CONFIG_USER_ONLY)
4835 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4837 if (unlikely(ctx
->pr
)) {
4838 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4841 if (NARROW_MODE(ctx
)) {
4842 TCGv t0
= tcg_temp_new();
4843 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
4844 gen_helper_tlbie(cpu_env
, t0
);
4847 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4853 static void gen_tlbsync(DisasContext
*ctx
)
4855 #if defined(CONFIG_USER_ONLY)
4856 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4858 if (unlikely(ctx
->pr
)) {
4859 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4862 /* This has no effect: it should ensure that all previous
4863 * tlbie have completed
4865 gen_stop_exception(ctx
);
4869 #if defined(TARGET_PPC64)
4871 static void gen_slbia(DisasContext
*ctx
)
4873 #if defined(CONFIG_USER_ONLY)
4874 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4876 if (unlikely(ctx
->pr
)) {
4877 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4880 gen_helper_slbia(cpu_env
);
4885 static void gen_slbie(DisasContext
*ctx
)
4887 #if defined(CONFIG_USER_ONLY)
4888 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4890 if (unlikely(ctx
->pr
)) {
4891 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4894 gen_helper_slbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4899 /*** External control ***/
4903 static void gen_eciwx(DisasContext
*ctx
)
4906 /* Should check EAR[E] ! */
4907 gen_set_access_type(ctx
, ACCESS_EXT
);
4908 t0
= tcg_temp_new();
4909 gen_addr_reg_index(ctx
, t0
);
4910 gen_check_align(ctx
, t0
, 0x03);
4911 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4916 static void gen_ecowx(DisasContext
*ctx
)
4919 /* Should check EAR[E] ! */
4920 gen_set_access_type(ctx
, ACCESS_EXT
);
4921 t0
= tcg_temp_new();
4922 gen_addr_reg_index(ctx
, t0
);
4923 gen_check_align(ctx
, t0
, 0x03);
4924 gen_qemu_st32(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4928 /* PowerPC 601 specific instructions */
4931 static void gen_abs(DisasContext
*ctx
)
4933 TCGLabel
*l1
= gen_new_label();
4934 TCGLabel
*l2
= gen_new_label();
4935 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4936 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4939 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4941 if (unlikely(Rc(ctx
->opcode
) != 0))
4942 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4946 static void gen_abso(DisasContext
*ctx
)
4948 TCGLabel
*l1
= gen_new_label();
4949 TCGLabel
*l2
= gen_new_label();
4950 TCGLabel
*l3
= gen_new_label();
4951 /* Start with XER OV disabled, the most likely case */
4952 tcg_gen_movi_tl(cpu_ov
, 0);
4953 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l2
);
4954 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rA(ctx
->opcode
)], 0x80000000, l1
);
4955 tcg_gen_movi_tl(cpu_ov
, 1);
4956 tcg_gen_movi_tl(cpu_so
, 1);
4959 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4962 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4964 if (unlikely(Rc(ctx
->opcode
) != 0))
4965 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4969 static void gen_clcs(DisasContext
*ctx
)
4971 TCGv_i32 t0
= tcg_const_i32(rA(ctx
->opcode
));
4972 gen_helper_clcs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4973 tcg_temp_free_i32(t0
);
4974 /* Rc=1 sets CR0 to an undefined state */
4978 static void gen_div(DisasContext
*ctx
)
4980 gen_helper_div(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4981 cpu_gpr
[rB(ctx
->opcode
)]);
4982 if (unlikely(Rc(ctx
->opcode
) != 0))
4983 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4987 static void gen_divo(DisasContext
*ctx
)
4989 gen_helper_divo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4990 cpu_gpr
[rB(ctx
->opcode
)]);
4991 if (unlikely(Rc(ctx
->opcode
) != 0))
4992 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4996 static void gen_divs(DisasContext
*ctx
)
4998 gen_helper_divs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4999 cpu_gpr
[rB(ctx
->opcode
)]);
5000 if (unlikely(Rc(ctx
->opcode
) != 0))
5001 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5004 /* divso - divso. */
5005 static void gen_divso(DisasContext
*ctx
)
5007 gen_helper_divso(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5008 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
5009 if (unlikely(Rc(ctx
->opcode
) != 0))
5010 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5014 static void gen_doz(DisasContext
*ctx
)
5016 TCGLabel
*l1
= gen_new_label();
5017 TCGLabel
*l2
= gen_new_label();
5018 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
5019 tcg_gen_sub_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5022 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
5024 if (unlikely(Rc(ctx
->opcode
) != 0))
5025 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5029 static void gen_dozo(DisasContext
*ctx
)
5031 TCGLabel
*l1
= gen_new_label();
5032 TCGLabel
*l2
= gen_new_label();
5033 TCGv t0
= tcg_temp_new();
5034 TCGv t1
= tcg_temp_new();
5035 TCGv t2
= tcg_temp_new();
5036 /* Start with XER OV disabled, the most likely case */
5037 tcg_gen_movi_tl(cpu_ov
, 0);
5038 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
5039 tcg_gen_sub_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5040 tcg_gen_xor_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5041 tcg_gen_xor_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], t0
);
5042 tcg_gen_andc_tl(t1
, t1
, t2
);
5043 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
5044 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
5045 tcg_gen_movi_tl(cpu_ov
, 1);
5046 tcg_gen_movi_tl(cpu_so
, 1);
5049 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
5054 if (unlikely(Rc(ctx
->opcode
) != 0))
5055 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5059 static void gen_dozi(DisasContext
*ctx
)
5061 target_long simm
= SIMM(ctx
->opcode
);
5062 TCGLabel
*l1
= gen_new_label();
5063 TCGLabel
*l2
= gen_new_label();
5064 tcg_gen_brcondi_tl(TCG_COND_LT
, cpu_gpr
[rA(ctx
->opcode
)], simm
, l1
);
5065 tcg_gen_subfi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
, cpu_gpr
[rA(ctx
->opcode
)]);
5068 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
5070 if (unlikely(Rc(ctx
->opcode
) != 0))
5071 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5074 /* lscbx - lscbx. */
5075 static void gen_lscbx(DisasContext
*ctx
)
5077 TCGv t0
= tcg_temp_new();
5078 TCGv_i32 t1
= tcg_const_i32(rD(ctx
->opcode
));
5079 TCGv_i32 t2
= tcg_const_i32(rA(ctx
->opcode
));
5080 TCGv_i32 t3
= tcg_const_i32(rB(ctx
->opcode
));
5082 gen_addr_reg_index(ctx
, t0
);
5083 /* NIP cannot be restored if the memory exception comes from an helper */
5084 gen_update_nip(ctx
, ctx
->nip
- 4);
5085 gen_helper_lscbx(t0
, cpu_env
, t0
, t1
, t2
, t3
);
5086 tcg_temp_free_i32(t1
);
5087 tcg_temp_free_i32(t2
);
5088 tcg_temp_free_i32(t3
);
5089 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~0x7F);
5090 tcg_gen_or_tl(cpu_xer
, cpu_xer
, t0
);
5091 if (unlikely(Rc(ctx
->opcode
) != 0))
5092 gen_set_Rc0(ctx
, t0
);
5096 /* maskg - maskg. */
5097 static void gen_maskg(DisasContext
*ctx
)
5099 TCGLabel
*l1
= gen_new_label();
5100 TCGv t0
= tcg_temp_new();
5101 TCGv t1
= tcg_temp_new();
5102 TCGv t2
= tcg_temp_new();
5103 TCGv t3
= tcg_temp_new();
5104 tcg_gen_movi_tl(t3
, 0xFFFFFFFF);
5105 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5106 tcg_gen_andi_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 0x1F);
5107 tcg_gen_addi_tl(t2
, t0
, 1);
5108 tcg_gen_shr_tl(t2
, t3
, t2
);
5109 tcg_gen_shr_tl(t3
, t3
, t1
);
5110 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], t2
, t3
);
5111 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
5112 tcg_gen_neg_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5118 if (unlikely(Rc(ctx
->opcode
) != 0))
5119 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5122 /* maskir - maskir. */
5123 static void gen_maskir(DisasContext
*ctx
)
5125 TCGv t0
= tcg_temp_new();
5126 TCGv t1
= tcg_temp_new();
5127 tcg_gen_and_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
5128 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
5129 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5132 if (unlikely(Rc(ctx
->opcode
) != 0))
5133 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5137 static void gen_mul(DisasContext
*ctx
)
5139 TCGv_i64 t0
= tcg_temp_new_i64();
5140 TCGv_i64 t1
= tcg_temp_new_i64();
5141 TCGv t2
= tcg_temp_new();
5142 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
5143 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
5144 tcg_gen_mul_i64(t0
, t0
, t1
);
5145 tcg_gen_trunc_i64_tl(t2
, t0
);
5146 gen_store_spr(SPR_MQ
, t2
);
5147 tcg_gen_shri_i64(t1
, t0
, 32);
5148 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
5149 tcg_temp_free_i64(t0
);
5150 tcg_temp_free_i64(t1
);
5152 if (unlikely(Rc(ctx
->opcode
) != 0))
5153 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5157 static void gen_mulo(DisasContext
*ctx
)
5159 TCGLabel
*l1
= gen_new_label();
5160 TCGv_i64 t0
= tcg_temp_new_i64();
5161 TCGv_i64 t1
= tcg_temp_new_i64();
5162 TCGv t2
= tcg_temp_new();
5163 /* Start with XER OV disabled, the most likely case */
5164 tcg_gen_movi_tl(cpu_ov
, 0);
5165 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
5166 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
5167 tcg_gen_mul_i64(t0
, t0
, t1
);
5168 tcg_gen_trunc_i64_tl(t2
, t0
);
5169 gen_store_spr(SPR_MQ
, t2
);
5170 tcg_gen_shri_i64(t1
, t0
, 32);
5171 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
5172 tcg_gen_ext32s_i64(t1
, t0
);
5173 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
5174 tcg_gen_movi_tl(cpu_ov
, 1);
5175 tcg_gen_movi_tl(cpu_so
, 1);
5177 tcg_temp_free_i64(t0
);
5178 tcg_temp_free_i64(t1
);
5180 if (unlikely(Rc(ctx
->opcode
) != 0))
5181 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5185 static void gen_nabs(DisasContext
*ctx
)
5187 TCGLabel
*l1
= gen_new_label();
5188 TCGLabel
*l2
= gen_new_label();
5189 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
5190 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5193 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5195 if (unlikely(Rc(ctx
->opcode
) != 0))
5196 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5199 /* nabso - nabso. */
5200 static void gen_nabso(DisasContext
*ctx
)
5202 TCGLabel
*l1
= gen_new_label();
5203 TCGLabel
*l2
= gen_new_label();
5204 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
5205 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5208 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5210 /* nabs never overflows */
5211 tcg_gen_movi_tl(cpu_ov
, 0);
5212 if (unlikely(Rc(ctx
->opcode
) != 0))
5213 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5217 static void gen_rlmi(DisasContext
*ctx
)
5219 uint32_t mb
= MB(ctx
->opcode
);
5220 uint32_t me
= ME(ctx
->opcode
);
5221 TCGv t0
= tcg_temp_new();
5222 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5223 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5224 tcg_gen_andi_tl(t0
, t0
, MASK(mb
, me
));
5225 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~MASK(mb
, me
));
5226 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], t0
);
5228 if (unlikely(Rc(ctx
->opcode
) != 0))
5229 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5233 static void gen_rrib(DisasContext
*ctx
)
5235 TCGv t0
= tcg_temp_new();
5236 TCGv t1
= tcg_temp_new();
5237 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5238 tcg_gen_movi_tl(t1
, 0x80000000);
5239 tcg_gen_shr_tl(t1
, t1
, t0
);
5240 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5241 tcg_gen_and_tl(t0
, t0
, t1
);
5242 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], t1
);
5243 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5246 if (unlikely(Rc(ctx
->opcode
) != 0))
5247 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5251 static void gen_sle(DisasContext
*ctx
)
5253 TCGv t0
= tcg_temp_new();
5254 TCGv t1
= tcg_temp_new();
5255 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5256 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5257 tcg_gen_subfi_tl(t1
, 32, t1
);
5258 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5259 tcg_gen_or_tl(t1
, t0
, t1
);
5260 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5261 gen_store_spr(SPR_MQ
, t1
);
5264 if (unlikely(Rc(ctx
->opcode
) != 0))
5265 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5269 static void gen_sleq(DisasContext
*ctx
)
5271 TCGv t0
= tcg_temp_new();
5272 TCGv t1
= tcg_temp_new();
5273 TCGv t2
= tcg_temp_new();
5274 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5275 tcg_gen_movi_tl(t2
, 0xFFFFFFFF);
5276 tcg_gen_shl_tl(t2
, t2
, t0
);
5277 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5278 gen_load_spr(t1
, SPR_MQ
);
5279 gen_store_spr(SPR_MQ
, t0
);
5280 tcg_gen_and_tl(t0
, t0
, t2
);
5281 tcg_gen_andc_tl(t1
, t1
, t2
);
5282 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5286 if (unlikely(Rc(ctx
->opcode
) != 0))
5287 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5291 static void gen_sliq(DisasContext
*ctx
)
5293 int sh
= SH(ctx
->opcode
);
5294 TCGv t0
= tcg_temp_new();
5295 TCGv t1
= tcg_temp_new();
5296 tcg_gen_shli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5297 tcg_gen_shri_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5298 tcg_gen_or_tl(t1
, t0
, t1
);
5299 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5300 gen_store_spr(SPR_MQ
, t1
);
5303 if (unlikely(Rc(ctx
->opcode
) != 0))
5304 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5307 /* slliq - slliq. */
5308 static void gen_slliq(DisasContext
*ctx
)
5310 int sh
= SH(ctx
->opcode
);
5311 TCGv t0
= tcg_temp_new();
5312 TCGv t1
= tcg_temp_new();
5313 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5314 gen_load_spr(t1
, SPR_MQ
);
5315 gen_store_spr(SPR_MQ
, t0
);
5316 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
<< sh
));
5317 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
<< sh
));
5318 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5321 if (unlikely(Rc(ctx
->opcode
) != 0))
5322 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5326 static void gen_sllq(DisasContext
*ctx
)
5328 TCGLabel
*l1
= gen_new_label();
5329 TCGLabel
*l2
= gen_new_label();
5330 TCGv t0
= tcg_temp_local_new();
5331 TCGv t1
= tcg_temp_local_new();
5332 TCGv t2
= tcg_temp_local_new();
5333 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5334 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5335 tcg_gen_shl_tl(t1
, t1
, t2
);
5336 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5337 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5338 gen_load_spr(t0
, SPR_MQ
);
5339 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5342 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5343 gen_load_spr(t2
, SPR_MQ
);
5344 tcg_gen_andc_tl(t1
, t2
, t1
);
5345 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5350 if (unlikely(Rc(ctx
->opcode
) != 0))
5351 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5355 static void gen_slq(DisasContext
*ctx
)
5357 TCGLabel
*l1
= gen_new_label();
5358 TCGv t0
= tcg_temp_new();
5359 TCGv t1
= tcg_temp_new();
5360 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5361 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5362 tcg_gen_subfi_tl(t1
, 32, t1
);
5363 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5364 tcg_gen_or_tl(t1
, t0
, t1
);
5365 gen_store_spr(SPR_MQ
, t1
);
5366 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5367 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5368 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
5369 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5373 if (unlikely(Rc(ctx
->opcode
) != 0))
5374 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5377 /* sraiq - sraiq. */
5378 static void gen_sraiq(DisasContext
*ctx
)
5380 int sh
= SH(ctx
->opcode
);
5381 TCGLabel
*l1
= gen_new_label();
5382 TCGv t0
= tcg_temp_new();
5383 TCGv t1
= tcg_temp_new();
5384 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5385 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5386 tcg_gen_or_tl(t0
, t0
, t1
);
5387 gen_store_spr(SPR_MQ
, t0
);
5388 tcg_gen_movi_tl(cpu_ca
, 0);
5389 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
5390 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
5391 tcg_gen_movi_tl(cpu_ca
, 1);
5393 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
5396 if (unlikely(Rc(ctx
->opcode
) != 0))
5397 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5401 static void gen_sraq(DisasContext
*ctx
)
5403 TCGLabel
*l1
= gen_new_label();
5404 TCGLabel
*l2
= gen_new_label();
5405 TCGv t0
= tcg_temp_new();
5406 TCGv t1
= tcg_temp_local_new();
5407 TCGv t2
= tcg_temp_local_new();
5408 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5409 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5410 tcg_gen_sar_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5411 tcg_gen_subfi_tl(t2
, 32, t2
);
5412 tcg_gen_shl_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5413 tcg_gen_or_tl(t0
, t0
, t2
);
5414 gen_store_spr(SPR_MQ
, t0
);
5415 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5416 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l1
);
5417 tcg_gen_mov_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
5418 tcg_gen_sari_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 31);
5421 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
);
5422 tcg_gen_movi_tl(cpu_ca
, 0);
5423 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
5424 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l2
);
5425 tcg_gen_movi_tl(cpu_ca
, 1);
5429 if (unlikely(Rc(ctx
->opcode
) != 0))
5430 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5434 static void gen_sre(DisasContext
*ctx
)
5436 TCGv t0
= tcg_temp_new();
5437 TCGv t1
= tcg_temp_new();
5438 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5439 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5440 tcg_gen_subfi_tl(t1
, 32, t1
);
5441 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5442 tcg_gen_or_tl(t1
, t0
, t1
);
5443 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5444 gen_store_spr(SPR_MQ
, t1
);
5447 if (unlikely(Rc(ctx
->opcode
) != 0))
5448 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5452 static void gen_srea(DisasContext
*ctx
)
5454 TCGv t0
= tcg_temp_new();
5455 TCGv t1
= tcg_temp_new();
5456 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5457 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5458 gen_store_spr(SPR_MQ
, t0
);
5459 tcg_gen_sar_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t1
);
5462 if (unlikely(Rc(ctx
->opcode
) != 0))
5463 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5467 static void gen_sreq(DisasContext
*ctx
)
5469 TCGv t0
= tcg_temp_new();
5470 TCGv t1
= tcg_temp_new();
5471 TCGv t2
= tcg_temp_new();
5472 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5473 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5474 tcg_gen_shr_tl(t1
, t1
, t0
);
5475 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5476 gen_load_spr(t2
, SPR_MQ
);
5477 gen_store_spr(SPR_MQ
, t0
);
5478 tcg_gen_and_tl(t0
, t0
, t1
);
5479 tcg_gen_andc_tl(t2
, t2
, t1
);
5480 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5484 if (unlikely(Rc(ctx
->opcode
) != 0))
5485 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5489 static void gen_sriq(DisasContext
*ctx
)
5491 int sh
= SH(ctx
->opcode
);
5492 TCGv t0
= tcg_temp_new();
5493 TCGv t1
= tcg_temp_new();
5494 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5495 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5496 tcg_gen_or_tl(t1
, t0
, t1
);
5497 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5498 gen_store_spr(SPR_MQ
, t1
);
5501 if (unlikely(Rc(ctx
->opcode
) != 0))
5502 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5506 static void gen_srliq(DisasContext
*ctx
)
5508 int sh
= SH(ctx
->opcode
);
5509 TCGv t0
= tcg_temp_new();
5510 TCGv t1
= tcg_temp_new();
5511 tcg_gen_rotri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5512 gen_load_spr(t1
, SPR_MQ
);
5513 gen_store_spr(SPR_MQ
, t0
);
5514 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
>> sh
));
5515 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
>> sh
));
5516 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5519 if (unlikely(Rc(ctx
->opcode
) != 0))
5520 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5524 static void gen_srlq(DisasContext
*ctx
)
5526 TCGLabel
*l1
= gen_new_label();
5527 TCGLabel
*l2
= gen_new_label();
5528 TCGv t0
= tcg_temp_local_new();
5529 TCGv t1
= tcg_temp_local_new();
5530 TCGv t2
= tcg_temp_local_new();
5531 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5532 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5533 tcg_gen_shr_tl(t2
, t1
, t2
);
5534 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5535 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5536 gen_load_spr(t0
, SPR_MQ
);
5537 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5540 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5541 tcg_gen_and_tl(t0
, t0
, t2
);
5542 gen_load_spr(t1
, SPR_MQ
);
5543 tcg_gen_andc_tl(t1
, t1
, t2
);
5544 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5549 if (unlikely(Rc(ctx
->opcode
) != 0))
5550 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5554 static void gen_srq(DisasContext
*ctx
)
5556 TCGLabel
*l1
= gen_new_label();
5557 TCGv t0
= tcg_temp_new();
5558 TCGv t1
= tcg_temp_new();
5559 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5560 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5561 tcg_gen_subfi_tl(t1
, 32, t1
);
5562 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5563 tcg_gen_or_tl(t1
, t0
, t1
);
5564 gen_store_spr(SPR_MQ
, t1
);
5565 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5566 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5567 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5568 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5572 if (unlikely(Rc(ctx
->opcode
) != 0))
5573 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5576 /* PowerPC 602 specific instructions */
5579 static void gen_dsa(DisasContext
*ctx
)
5582 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5586 static void gen_esa(DisasContext
*ctx
)
5589 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5593 static void gen_mfrom(DisasContext
*ctx
)
5595 #if defined(CONFIG_USER_ONLY)
5596 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5598 if (unlikely(ctx
->pr
)) {
5599 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5602 gen_helper_602_mfrom(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5606 /* 602 - 603 - G2 TLB management */
5609 static void gen_tlbld_6xx(DisasContext
*ctx
)
5611 #if defined(CONFIG_USER_ONLY)
5612 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5614 if (unlikely(ctx
->pr
)) {
5615 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5618 gen_helper_6xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5623 static void gen_tlbli_6xx(DisasContext
*ctx
)
5625 #if defined(CONFIG_USER_ONLY)
5626 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5628 if (unlikely(ctx
->pr
)) {
5629 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5632 gen_helper_6xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5636 /* 74xx TLB management */
5639 static void gen_tlbld_74xx(DisasContext
*ctx
)
5641 #if defined(CONFIG_USER_ONLY)
5642 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5644 if (unlikely(ctx
->pr
)) {
5645 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5648 gen_helper_74xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5653 static void gen_tlbli_74xx(DisasContext
*ctx
)
5655 #if defined(CONFIG_USER_ONLY)
5656 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5658 if (unlikely(ctx
->pr
)) {
5659 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5662 gen_helper_74xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5666 /* POWER instructions not in PowerPC 601 */
5669 static void gen_clf(DisasContext
*ctx
)
5671 /* Cache line flush: implemented as no-op */
5675 static void gen_cli(DisasContext
*ctx
)
5677 /* Cache line invalidate: privileged and treated as no-op */
5678 #if defined(CONFIG_USER_ONLY)
5679 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5681 if (unlikely(ctx
->pr
)) {
5682 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5689 static void gen_dclst(DisasContext
*ctx
)
5691 /* Data cache line store: treated as no-op */
5694 static void gen_mfsri(DisasContext
*ctx
)
5696 #if defined(CONFIG_USER_ONLY)
5697 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5699 int ra
= rA(ctx
->opcode
);
5700 int rd
= rD(ctx
->opcode
);
5702 if (unlikely(ctx
->pr
)) {
5703 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5706 t0
= tcg_temp_new();
5707 gen_addr_reg_index(ctx
, t0
);
5708 tcg_gen_shri_tl(t0
, t0
, 28);
5709 tcg_gen_andi_tl(t0
, t0
, 0xF);
5710 gen_helper_load_sr(cpu_gpr
[rd
], cpu_env
, t0
);
5712 if (ra
!= 0 && ra
!= rd
)
5713 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rd
]);
5717 static void gen_rac(DisasContext
*ctx
)
5719 #if defined(CONFIG_USER_ONLY)
5720 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5723 if (unlikely(ctx
->pr
)) {
5724 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5727 t0
= tcg_temp_new();
5728 gen_addr_reg_index(ctx
, t0
);
5729 gen_helper_rac(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5734 static void gen_rfsvc(DisasContext
*ctx
)
5736 #if defined(CONFIG_USER_ONLY)
5737 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5739 if (unlikely(ctx
->pr
)) {
5740 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5743 gen_helper_rfsvc(cpu_env
);
5744 gen_sync_exception(ctx
);
5748 /* svc is not implemented for now */
5750 /* POWER2 specific instructions */
5751 /* Quad manipulation (load/store two floats at a time) */
5754 static void gen_lfq(DisasContext
*ctx
)
5756 int rd
= rD(ctx
->opcode
);
5758 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5759 t0
= tcg_temp_new();
5760 gen_addr_imm_index(ctx
, t0
, 0);
5761 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5762 gen_addr_add(ctx
, t0
, t0
, 8);
5763 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5768 static void gen_lfqu(DisasContext
*ctx
)
5770 int ra
= rA(ctx
->opcode
);
5771 int rd
= rD(ctx
->opcode
);
5773 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5774 t0
= tcg_temp_new();
5775 t1
= tcg_temp_new();
5776 gen_addr_imm_index(ctx
, t0
, 0);
5777 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5778 gen_addr_add(ctx
, t1
, t0
, 8);
5779 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5781 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5787 static void gen_lfqux(DisasContext
*ctx
)
5789 int ra
= rA(ctx
->opcode
);
5790 int rd
= rD(ctx
->opcode
);
5791 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5793 t0
= tcg_temp_new();
5794 gen_addr_reg_index(ctx
, t0
);
5795 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5796 t1
= tcg_temp_new();
5797 gen_addr_add(ctx
, t1
, t0
, 8);
5798 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5801 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5806 static void gen_lfqx(DisasContext
*ctx
)
5808 int rd
= rD(ctx
->opcode
);
5810 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5811 t0
= tcg_temp_new();
5812 gen_addr_reg_index(ctx
, t0
);
5813 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5814 gen_addr_add(ctx
, t0
, t0
, 8);
5815 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5820 static void gen_stfq(DisasContext
*ctx
)
5822 int rd
= rD(ctx
->opcode
);
5824 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5825 t0
= tcg_temp_new();
5826 gen_addr_imm_index(ctx
, t0
, 0);
5827 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5828 gen_addr_add(ctx
, t0
, t0
, 8);
5829 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5834 static void gen_stfqu(DisasContext
*ctx
)
5836 int ra
= rA(ctx
->opcode
);
5837 int rd
= rD(ctx
->opcode
);
5839 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5840 t0
= tcg_temp_new();
5841 gen_addr_imm_index(ctx
, t0
, 0);
5842 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5843 t1
= tcg_temp_new();
5844 gen_addr_add(ctx
, t1
, t0
, 8);
5845 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5848 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5853 static void gen_stfqux(DisasContext
*ctx
)
5855 int ra
= rA(ctx
->opcode
);
5856 int rd
= rD(ctx
->opcode
);
5858 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5859 t0
= tcg_temp_new();
5860 gen_addr_reg_index(ctx
, t0
);
5861 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5862 t1
= tcg_temp_new();
5863 gen_addr_add(ctx
, t1
, t0
, 8);
5864 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5867 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5872 static void gen_stfqx(DisasContext
*ctx
)
5874 int rd
= rD(ctx
->opcode
);
5876 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5877 t0
= tcg_temp_new();
5878 gen_addr_reg_index(ctx
, t0
);
5879 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5880 gen_addr_add(ctx
, t0
, t0
, 8);
5881 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5885 /* BookE specific instructions */
5887 /* XXX: not implemented on 440 ? */
5888 static void gen_mfapidi(DisasContext
*ctx
)
5891 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5894 /* XXX: not implemented on 440 ? */
5895 static void gen_tlbiva(DisasContext
*ctx
)
5897 #if defined(CONFIG_USER_ONLY)
5898 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5901 if (unlikely(ctx
->pr
)) {
5902 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5905 t0
= tcg_temp_new();
5906 gen_addr_reg_index(ctx
, t0
);
5907 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5912 /* All 405 MAC instructions are translated here */
5913 static inline void gen_405_mulladd_insn(DisasContext
*ctx
, int opc2
, int opc3
,
5914 int ra
, int rb
, int rt
, int Rc
)
5918 t0
= tcg_temp_local_new();
5919 t1
= tcg_temp_local_new();
5921 switch (opc3
& 0x0D) {
5923 /* macchw - macchw. - macchwo - macchwo. */
5924 /* macchws - macchws. - macchwso - macchwso. */
5925 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5926 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5927 /* mulchw - mulchw. */
5928 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5929 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5930 tcg_gen_ext16s_tl(t1
, t1
);
5933 /* macchwu - macchwu. - macchwuo - macchwuo. */
5934 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5935 /* mulchwu - mulchwu. */
5936 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5937 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5938 tcg_gen_ext16u_tl(t1
, t1
);
5941 /* machhw - machhw. - machhwo - machhwo. */
5942 /* machhws - machhws. - machhwso - machhwso. */
5943 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5944 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5945 /* mulhhw - mulhhw. */
5946 tcg_gen_sari_tl(t0
, cpu_gpr
[ra
], 16);
5947 tcg_gen_ext16s_tl(t0
, t0
);
5948 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5949 tcg_gen_ext16s_tl(t1
, t1
);
5952 /* machhwu - machhwu. - machhwuo - machhwuo. */
5953 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5954 /* mulhhwu - mulhhwu. */
5955 tcg_gen_shri_tl(t0
, cpu_gpr
[ra
], 16);
5956 tcg_gen_ext16u_tl(t0
, t0
);
5957 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5958 tcg_gen_ext16u_tl(t1
, t1
);
5961 /* maclhw - maclhw. - maclhwo - maclhwo. */
5962 /* maclhws - maclhws. - maclhwso - maclhwso. */
5963 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5964 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5965 /* mullhw - mullhw. */
5966 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5967 tcg_gen_ext16s_tl(t1
, cpu_gpr
[rb
]);
5970 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5971 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5972 /* mullhwu - mullhwu. */
5973 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5974 tcg_gen_ext16u_tl(t1
, cpu_gpr
[rb
]);
5978 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5979 tcg_gen_mul_tl(t1
, t0
, t1
);
5981 /* nmultiply-and-accumulate (0x0E) */
5982 tcg_gen_sub_tl(t0
, cpu_gpr
[rt
], t1
);
5984 /* multiply-and-accumulate (0x0C) */
5985 tcg_gen_add_tl(t0
, cpu_gpr
[rt
], t1
);
5989 /* Check overflow and/or saturate */
5990 TCGLabel
*l1
= gen_new_label();
5993 /* Start with XER OV disabled, the most likely case */
5994 tcg_gen_movi_tl(cpu_ov
, 0);
5998 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t1
);
5999 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
6000 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t0
);
6001 tcg_gen_brcondi_tl(TCG_COND_LT
, t1
, 0, l1
);
6004 tcg_gen_sari_tl(t0
, cpu_gpr
[rt
], 31);
6005 tcg_gen_xori_tl(t0
, t0
, 0x7fffffff);
6009 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
6012 tcg_gen_movi_tl(t0
, UINT32_MAX
);
6016 /* Check overflow */
6017 tcg_gen_movi_tl(cpu_ov
, 1);
6018 tcg_gen_movi_tl(cpu_so
, 1);
6021 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
6024 tcg_gen_mul_tl(cpu_gpr
[rt
], t0
, t1
);
6028 if (unlikely(Rc
) != 0) {
6030 gen_set_Rc0(ctx
, cpu_gpr
[rt
]);
6034 #define GEN_MAC_HANDLER(name, opc2, opc3) \
6035 static void glue(gen_, name)(DisasContext *ctx) \
6037 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
6038 rD(ctx->opcode), Rc(ctx->opcode)); \
6041 /* macchw - macchw. */
6042 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
6043 /* macchwo - macchwo. */
6044 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
6045 /* macchws - macchws. */
6046 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
6047 /* macchwso - macchwso. */
6048 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
6049 /* macchwsu - macchwsu. */
6050 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
6051 /* macchwsuo - macchwsuo. */
6052 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
6053 /* macchwu - macchwu. */
6054 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
6055 /* macchwuo - macchwuo. */
6056 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
6057 /* machhw - machhw. */
6058 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
6059 /* machhwo - machhwo. */
6060 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
6061 /* machhws - machhws. */
6062 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
6063 /* machhwso - machhwso. */
6064 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
6065 /* machhwsu - machhwsu. */
6066 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
6067 /* machhwsuo - machhwsuo. */
6068 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
6069 /* machhwu - machhwu. */
6070 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
6071 /* machhwuo - machhwuo. */
6072 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
6073 /* maclhw - maclhw. */
6074 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
6075 /* maclhwo - maclhwo. */
6076 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
6077 /* maclhws - maclhws. */
6078 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
6079 /* maclhwso - maclhwso. */
6080 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
6081 /* maclhwu - maclhwu. */
6082 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
6083 /* maclhwuo - maclhwuo. */
6084 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
6085 /* maclhwsu - maclhwsu. */
6086 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
6087 /* maclhwsuo - maclhwsuo. */
6088 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
6089 /* nmacchw - nmacchw. */
6090 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
6091 /* nmacchwo - nmacchwo. */
6092 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
6093 /* nmacchws - nmacchws. */
6094 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
6095 /* nmacchwso - nmacchwso. */
6096 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
6097 /* nmachhw - nmachhw. */
6098 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
6099 /* nmachhwo - nmachhwo. */
6100 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
6101 /* nmachhws - nmachhws. */
6102 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
6103 /* nmachhwso - nmachhwso. */
6104 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
6105 /* nmaclhw - nmaclhw. */
6106 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
6107 /* nmaclhwo - nmaclhwo. */
6108 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
6109 /* nmaclhws - nmaclhws. */
6110 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
6111 /* nmaclhwso - nmaclhwso. */
6112 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
6114 /* mulchw - mulchw. */
6115 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
6116 /* mulchwu - mulchwu. */
6117 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
6118 /* mulhhw - mulhhw. */
6119 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
6120 /* mulhhwu - mulhhwu. */
6121 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
6122 /* mullhw - mullhw. */
6123 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
6124 /* mullhwu - mullhwu. */
6125 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
6128 static void gen_mfdcr(DisasContext
*ctx
)
6130 #if defined(CONFIG_USER_ONLY)
6131 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
6134 if (unlikely(ctx
->pr
)) {
6135 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
6138 /* NIP cannot be restored if the memory exception comes from an helper */
6139 gen_update_nip(ctx
, ctx
->nip
- 4);
6140 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
6141 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, dcrn
);
6142 tcg_temp_free(dcrn
);
6147 static void gen_mtdcr(DisasContext
*ctx
)
6149 #if defined(CONFIG_USER_ONLY)
6150 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
6153 if (unlikely(ctx
->pr
)) {
6154 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
6157 /* NIP cannot be restored if the memory exception comes from an helper */
6158 gen_update_nip(ctx
, ctx
->nip
- 4);
6159 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
6160 gen_helper_store_dcr(cpu_env
, dcrn
, cpu_gpr
[rS(ctx
->opcode
)]);
6161 tcg_temp_free(dcrn
);
6166 /* XXX: not implemented on 440 ? */
6167 static void gen_mfdcrx(DisasContext
*ctx
)
6169 #if defined(CONFIG_USER_ONLY)
6170 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
6172 if (unlikely(ctx
->pr
)) {
6173 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
6176 /* NIP cannot be restored if the memory exception comes from an helper */
6177 gen_update_nip(ctx
, ctx
->nip
- 4);
6178 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6179 cpu_gpr
[rA(ctx
->opcode
)]);
6180 /* Note: Rc update flag set leads to undefined state of Rc0 */
6185 /* XXX: not implemented on 440 ? */
6186 static void gen_mtdcrx(DisasContext
*ctx
)
6188 #if defined(CONFIG_USER_ONLY)
6189 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
6191 if (unlikely(ctx
->pr
)) {
6192 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
6195 /* NIP cannot be restored if the memory exception comes from an helper */
6196 gen_update_nip(ctx
, ctx
->nip
- 4);
6197 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6198 cpu_gpr
[rS(ctx
->opcode
)]);
6199 /* Note: Rc update flag set leads to undefined state of Rc0 */
6203 /* mfdcrux (PPC 460) : user-mode access to DCR */
6204 static void gen_mfdcrux(DisasContext
*ctx
)
6206 /* NIP cannot be restored if the memory exception comes from an helper */
6207 gen_update_nip(ctx
, ctx
->nip
- 4);
6208 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6209 cpu_gpr
[rA(ctx
->opcode
)]);
6210 /* Note: Rc update flag set leads to undefined state of Rc0 */
6213 /* mtdcrux (PPC 460) : user-mode access to DCR */
6214 static void gen_mtdcrux(DisasContext
*ctx
)
6216 /* NIP cannot be restored if the memory exception comes from an helper */
6217 gen_update_nip(ctx
, ctx
->nip
- 4);
6218 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6219 cpu_gpr
[rS(ctx
->opcode
)]);
6220 /* Note: Rc update flag set leads to undefined state of Rc0 */
6224 static void gen_dccci(DisasContext
*ctx
)
6226 #if defined(CONFIG_USER_ONLY)
6227 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6229 if (unlikely(ctx
->pr
)) {
6230 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6233 /* interpreted as no-op */
6238 static void gen_dcread(DisasContext
*ctx
)
6240 #if defined(CONFIG_USER_ONLY)
6241 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6244 if (unlikely(ctx
->pr
)) {
6245 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6248 gen_set_access_type(ctx
, ACCESS_CACHE
);
6249 EA
= tcg_temp_new();
6250 gen_addr_reg_index(ctx
, EA
);
6251 val
= tcg_temp_new();
6252 gen_qemu_ld32u(ctx
, val
, EA
);
6254 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], EA
);
6260 static void gen_icbt_40x(DisasContext
*ctx
)
6262 /* interpreted as no-op */
6263 /* XXX: specification say this is treated as a load by the MMU
6264 * but does not generate any exception
6269 static void gen_iccci(DisasContext
*ctx
)
6271 #if defined(CONFIG_USER_ONLY)
6272 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6274 if (unlikely(ctx
->pr
)) {
6275 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6278 /* interpreted as no-op */
6283 static void gen_icread(DisasContext
*ctx
)
6285 #if defined(CONFIG_USER_ONLY)
6286 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6288 if (unlikely(ctx
->pr
)) {
6289 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6292 /* interpreted as no-op */
6296 /* rfci (supervisor only) */
6297 static void gen_rfci_40x(DisasContext
*ctx
)
6299 #if defined(CONFIG_USER_ONLY)
6300 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6302 if (unlikely(ctx
->pr
)) {
6303 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6306 /* Restore CPU state */
6307 gen_helper_40x_rfci(cpu_env
);
6308 gen_sync_exception(ctx
);
6312 static void gen_rfci(DisasContext
*ctx
)
6314 #if defined(CONFIG_USER_ONLY)
6315 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6317 if (unlikely(ctx
->pr
)) {
6318 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6321 /* Restore CPU state */
6322 gen_helper_rfci(cpu_env
);
6323 gen_sync_exception(ctx
);
6327 /* BookE specific */
6329 /* XXX: not implemented on 440 ? */
6330 static void gen_rfdi(DisasContext
*ctx
)
6332 #if defined(CONFIG_USER_ONLY)
6333 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6335 if (unlikely(ctx
->pr
)) {
6336 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6339 /* Restore CPU state */
6340 gen_helper_rfdi(cpu_env
);
6341 gen_sync_exception(ctx
);
6345 /* XXX: not implemented on 440 ? */
6346 static void gen_rfmci(DisasContext
*ctx
)
6348 #if defined(CONFIG_USER_ONLY)
6349 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6351 if (unlikely(ctx
->pr
)) {
6352 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6355 /* Restore CPU state */
6356 gen_helper_rfmci(cpu_env
);
6357 gen_sync_exception(ctx
);
6361 /* TLB management - PowerPC 405 implementation */
6364 static void gen_tlbre_40x(DisasContext
*ctx
)
6366 #if defined(CONFIG_USER_ONLY)
6367 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6369 if (unlikely(ctx
->pr
)) {
6370 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6373 switch (rB(ctx
->opcode
)) {
6375 gen_helper_4xx_tlbre_hi(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6376 cpu_gpr
[rA(ctx
->opcode
)]);
6379 gen_helper_4xx_tlbre_lo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6380 cpu_gpr
[rA(ctx
->opcode
)]);
6383 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6389 /* tlbsx - tlbsx. */
6390 static void gen_tlbsx_40x(DisasContext
*ctx
)
6392 #if defined(CONFIG_USER_ONLY)
6393 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6396 if (unlikely(ctx
->pr
)) {
6397 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6400 t0
= tcg_temp_new();
6401 gen_addr_reg_index(ctx
, t0
);
6402 gen_helper_4xx_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
6404 if (Rc(ctx
->opcode
)) {
6405 TCGLabel
*l1
= gen_new_label();
6406 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
6407 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
6408 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
6415 static void gen_tlbwe_40x(DisasContext
*ctx
)
6417 #if defined(CONFIG_USER_ONLY)
6418 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6420 if (unlikely(ctx
->pr
)) {
6421 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6424 switch (rB(ctx
->opcode
)) {
6426 gen_helper_4xx_tlbwe_hi(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6427 cpu_gpr
[rS(ctx
->opcode
)]);
6430 gen_helper_4xx_tlbwe_lo(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6431 cpu_gpr
[rS(ctx
->opcode
)]);
6434 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6440 /* TLB management - PowerPC 440 implementation */
6443 static void gen_tlbre_440(DisasContext
*ctx
)
6445 #if defined(CONFIG_USER_ONLY)
6446 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6448 if (unlikely(ctx
->pr
)) {
6449 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6452 switch (rB(ctx
->opcode
)) {
6457 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
6458 gen_helper_440_tlbre(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6459 t0
, cpu_gpr
[rA(ctx
->opcode
)]);
6460 tcg_temp_free_i32(t0
);
6464 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6470 /* tlbsx - tlbsx. */
6471 static void gen_tlbsx_440(DisasContext
*ctx
)
6473 #if defined(CONFIG_USER_ONLY)
6474 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6477 if (unlikely(ctx
->pr
)) {
6478 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6481 t0
= tcg_temp_new();
6482 gen_addr_reg_index(ctx
, t0
);
6483 gen_helper_440_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
6485 if (Rc(ctx
->opcode
)) {
6486 TCGLabel
*l1
= gen_new_label();
6487 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
6488 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
6489 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
6496 static void gen_tlbwe_440(DisasContext
*ctx
)
6498 #if defined(CONFIG_USER_ONLY)
6499 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6501 if (unlikely(ctx
->pr
)) {
6502 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6505 switch (rB(ctx
->opcode
)) {
6510 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
6511 gen_helper_440_tlbwe(cpu_env
, t0
, cpu_gpr
[rA(ctx
->opcode
)],
6512 cpu_gpr
[rS(ctx
->opcode
)]);
6513 tcg_temp_free_i32(t0
);
6517 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6523 /* TLB management - PowerPC BookE 2.06 implementation */
6526 static void gen_tlbre_booke206(DisasContext
*ctx
)
6528 #if defined(CONFIG_USER_ONLY)
6529 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6531 if (unlikely(ctx
->pr
)) {
6532 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6536 gen_helper_booke206_tlbre(cpu_env
);
6540 /* tlbsx - tlbsx. */
6541 static void gen_tlbsx_booke206(DisasContext
*ctx
)
6543 #if defined(CONFIG_USER_ONLY)
6544 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6547 if (unlikely(ctx
->pr
)) {
6548 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6552 if (rA(ctx
->opcode
)) {
6553 t0
= tcg_temp_new();
6554 tcg_gen_mov_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)]);
6556 t0
= tcg_const_tl(0);
6559 tcg_gen_add_tl(t0
, t0
, cpu_gpr
[rB(ctx
->opcode
)]);
6560 gen_helper_booke206_tlbsx(cpu_env
, t0
);
6566 static void gen_tlbwe_booke206(DisasContext
*ctx
)
6568 #if defined(CONFIG_USER_ONLY)
6569 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6571 if (unlikely(ctx
->pr
)) {
6572 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6575 gen_update_nip(ctx
, ctx
->nip
- 4);
6576 gen_helper_booke206_tlbwe(cpu_env
);
6580 static void gen_tlbivax_booke206(DisasContext
*ctx
)
6582 #if defined(CONFIG_USER_ONLY)
6583 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6586 if (unlikely(ctx
->pr
)) {
6587 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6591 t0
= tcg_temp_new();
6592 gen_addr_reg_index(ctx
, t0
);
6594 gen_helper_booke206_tlbivax(cpu_env
, t0
);
6599 static void gen_tlbilx_booke206(DisasContext
*ctx
)
6601 #if defined(CONFIG_USER_ONLY)
6602 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6605 if (unlikely(ctx
->pr
)) {
6606 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6610 t0
= tcg_temp_new();
6611 gen_addr_reg_index(ctx
, t0
);
6613 switch((ctx
->opcode
>> 21) & 0x3) {
6615 gen_helper_booke206_tlbilx0(cpu_env
, t0
);
6618 gen_helper_booke206_tlbilx1(cpu_env
, t0
);
6621 gen_helper_booke206_tlbilx3(cpu_env
, t0
);
6624 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6634 static void gen_wrtee(DisasContext
*ctx
)
6636 #if defined(CONFIG_USER_ONLY)
6637 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6640 if (unlikely(ctx
->pr
)) {
6641 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6644 t0
= tcg_temp_new();
6645 tcg_gen_andi_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)], (1 << MSR_EE
));
6646 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6647 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
6649 /* Stop translation to have a chance to raise an exception
6650 * if we just set msr_ee to 1
6652 gen_stop_exception(ctx
);
6657 static void gen_wrteei(DisasContext
*ctx
)
6659 #if defined(CONFIG_USER_ONLY)
6660 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6662 if (unlikely(ctx
->pr
)) {
6663 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6666 if (ctx
->opcode
& 0x00008000) {
6667 tcg_gen_ori_tl(cpu_msr
, cpu_msr
, (1 << MSR_EE
));
6668 /* Stop translation to have a chance to raise an exception */
6669 gen_stop_exception(ctx
);
6671 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6676 /* PowerPC 440 specific instructions */
6679 static void gen_dlmzb(DisasContext
*ctx
)
6681 TCGv_i32 t0
= tcg_const_i32(Rc(ctx
->opcode
));
6682 gen_helper_dlmzb(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
6683 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
6684 tcg_temp_free_i32(t0
);
6687 /* mbar replaces eieio on 440 */
6688 static void gen_mbar(DisasContext
*ctx
)
6690 /* interpreted as no-op */
6693 /* msync replaces sync on 440 */
6694 static void gen_msync_4xx(DisasContext
*ctx
)
6696 /* interpreted as no-op */
6700 static void gen_icbt_440(DisasContext
*ctx
)
6702 /* interpreted as no-op */
6703 /* XXX: specification say this is treated as a load by the MMU
6704 * but does not generate any exception
6708 /* Embedded.Processor Control */
6710 static void gen_msgclr(DisasContext
*ctx
)
6712 #if defined(CONFIG_USER_ONLY)
6713 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6715 if (unlikely(ctx
->pr
)) {
6716 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6720 gen_helper_msgclr(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6724 static void gen_msgsnd(DisasContext
*ctx
)
6726 #if defined(CONFIG_USER_ONLY)
6727 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6729 if (unlikely(ctx
->pr
)) {
6730 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6734 gen_helper_msgsnd(cpu_gpr
[rB(ctx
->opcode
)]);
6738 /*** Altivec vector extension ***/
6739 /* Altivec registers moves */
6741 static inline TCGv_ptr
gen_avr_ptr(int reg
)
6743 TCGv_ptr r
= tcg_temp_new_ptr();
6744 tcg_gen_addi_ptr(r
, cpu_env
, offsetof(CPUPPCState
, avr
[reg
]));
6748 #define GEN_VR_LDX(name, opc2, opc3) \
6749 static void glue(gen_, name)(DisasContext *ctx) \
6752 if (unlikely(!ctx->altivec_enabled)) { \
6753 gen_exception(ctx, POWERPC_EXCP_VPU); \
6756 gen_set_access_type(ctx, ACCESS_INT); \
6757 EA = tcg_temp_new(); \
6758 gen_addr_reg_index(ctx, EA); \
6759 tcg_gen_andi_tl(EA, EA, ~0xf); \
6760 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary \
6761 64-bit byteswap already. */ \
6762 if (ctx->le_mode) { \
6763 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6764 tcg_gen_addi_tl(EA, EA, 8); \
6765 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6767 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6768 tcg_gen_addi_tl(EA, EA, 8); \
6769 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6771 tcg_temp_free(EA); \
6774 #define GEN_VR_STX(name, opc2, opc3) \
6775 static void gen_st##name(DisasContext *ctx) \
6778 if (unlikely(!ctx->altivec_enabled)) { \
6779 gen_exception(ctx, POWERPC_EXCP_VPU); \
6782 gen_set_access_type(ctx, ACCESS_INT); \
6783 EA = tcg_temp_new(); \
6784 gen_addr_reg_index(ctx, EA); \
6785 tcg_gen_andi_tl(EA, EA, ~0xf); \
6786 /* We only need to swap high and low halves. gen_qemu_st64 does necessary \
6787 64-bit byteswap already. */ \
6788 if (ctx->le_mode) { \
6789 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6790 tcg_gen_addi_tl(EA, EA, 8); \
6791 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6793 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6794 tcg_gen_addi_tl(EA, EA, 8); \
6795 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6797 tcg_temp_free(EA); \
6800 #define GEN_VR_LVE(name, opc2, opc3, size) \
6801 static void gen_lve##name(DisasContext *ctx) \
6805 if (unlikely(!ctx->altivec_enabled)) { \
6806 gen_exception(ctx, POWERPC_EXCP_VPU); \
6809 gen_set_access_type(ctx, ACCESS_INT); \
6810 EA = tcg_temp_new(); \
6811 gen_addr_reg_index(ctx, EA); \
6813 tcg_gen_andi_tl(EA, EA, ~(size - 1)); \
6815 rs = gen_avr_ptr(rS(ctx->opcode)); \
6816 gen_helper_lve##name(cpu_env, rs, EA); \
6817 tcg_temp_free(EA); \
6818 tcg_temp_free_ptr(rs); \
6821 #define GEN_VR_STVE(name, opc2, opc3, size) \
6822 static void gen_stve##name(DisasContext *ctx) \
6826 if (unlikely(!ctx->altivec_enabled)) { \
6827 gen_exception(ctx, POWERPC_EXCP_VPU); \
6830 gen_set_access_type(ctx, ACCESS_INT); \
6831 EA = tcg_temp_new(); \
6832 gen_addr_reg_index(ctx, EA); \
6834 tcg_gen_andi_tl(EA, EA, ~(size - 1)); \
6836 rs = gen_avr_ptr(rS(ctx->opcode)); \
6837 gen_helper_stve##name(cpu_env, rs, EA); \
6838 tcg_temp_free(EA); \
6839 tcg_temp_free_ptr(rs); \
6842 GEN_VR_LDX(lvx
, 0x07, 0x03);
6843 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
6844 GEN_VR_LDX(lvxl
, 0x07, 0x0B);
6846 GEN_VR_LVE(bx
, 0x07, 0x00, 1);
6847 GEN_VR_LVE(hx
, 0x07, 0x01, 2);
6848 GEN_VR_LVE(wx
, 0x07, 0x02, 4);
6850 GEN_VR_STX(svx
, 0x07, 0x07);
6851 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
6852 GEN_VR_STX(svxl
, 0x07, 0x0F);
6854 GEN_VR_STVE(bx
, 0x07, 0x04, 1);
6855 GEN_VR_STVE(hx
, 0x07, 0x05, 2);
6856 GEN_VR_STVE(wx
, 0x07, 0x06, 4);
6858 static void gen_lvsl(DisasContext
*ctx
)
6862 if (unlikely(!ctx
->altivec_enabled
)) {
6863 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6866 EA
= tcg_temp_new();
6867 gen_addr_reg_index(ctx
, EA
);
6868 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6869 gen_helper_lvsl(rd
, EA
);
6871 tcg_temp_free_ptr(rd
);
6874 static void gen_lvsr(DisasContext
*ctx
)
6878 if (unlikely(!ctx
->altivec_enabled
)) {
6879 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6882 EA
= tcg_temp_new();
6883 gen_addr_reg_index(ctx
, EA
);
6884 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6885 gen_helper_lvsr(rd
, EA
);
6887 tcg_temp_free_ptr(rd
);
6890 static void gen_mfvscr(DisasContext
*ctx
)
6893 if (unlikely(!ctx
->altivec_enabled
)) {
6894 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6897 tcg_gen_movi_i64(cpu_avrh
[rD(ctx
->opcode
)], 0);
6898 t
= tcg_temp_new_i32();
6899 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUPPCState
, vscr
));
6900 tcg_gen_extu_i32_i64(cpu_avrl
[rD(ctx
->opcode
)], t
);
6901 tcg_temp_free_i32(t
);
6904 static void gen_mtvscr(DisasContext
*ctx
)
6907 if (unlikely(!ctx
->altivec_enabled
)) {
6908 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6911 p
= gen_avr_ptr(rB(ctx
->opcode
));
6912 gen_helper_mtvscr(cpu_env
, p
);
6913 tcg_temp_free_ptr(p
);
6916 /* Logical operations */
6917 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
6918 static void glue(gen_, name)(DisasContext *ctx) \
6920 if (unlikely(!ctx->altivec_enabled)) { \
6921 gen_exception(ctx, POWERPC_EXCP_VPU); \
6924 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6925 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6928 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16);
6929 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17);
6930 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18);
6931 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19);
6932 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20);
6933 GEN_VX_LOGICAL(veqv
, tcg_gen_eqv_i64
, 2, 26);
6934 GEN_VX_LOGICAL(vnand
, tcg_gen_nand_i64
, 2, 22);
6935 GEN_VX_LOGICAL(vorc
, tcg_gen_orc_i64
, 2, 21);
6937 #define GEN_VXFORM(name, opc2, opc3) \
6938 static void glue(gen_, name)(DisasContext *ctx) \
6940 TCGv_ptr ra, rb, rd; \
6941 if (unlikely(!ctx->altivec_enabled)) { \
6942 gen_exception(ctx, POWERPC_EXCP_VPU); \
6945 ra = gen_avr_ptr(rA(ctx->opcode)); \
6946 rb = gen_avr_ptr(rB(ctx->opcode)); \
6947 rd = gen_avr_ptr(rD(ctx->opcode)); \
6948 gen_helper_##name (rd, ra, rb); \
6949 tcg_temp_free_ptr(ra); \
6950 tcg_temp_free_ptr(rb); \
6951 tcg_temp_free_ptr(rd); \
6954 #define GEN_VXFORM_ENV(name, opc2, opc3) \
6955 static void glue(gen_, name)(DisasContext *ctx) \
6957 TCGv_ptr ra, rb, rd; \
6958 if (unlikely(!ctx->altivec_enabled)) { \
6959 gen_exception(ctx, POWERPC_EXCP_VPU); \
6962 ra = gen_avr_ptr(rA(ctx->opcode)); \
6963 rb = gen_avr_ptr(rB(ctx->opcode)); \
6964 rd = gen_avr_ptr(rD(ctx->opcode)); \
6965 gen_helper_##name(cpu_env, rd, ra, rb); \
6966 tcg_temp_free_ptr(ra); \
6967 tcg_temp_free_ptr(rb); \
6968 tcg_temp_free_ptr(rd); \
6971 #define GEN_VXFORM3(name, opc2, opc3) \
6972 static void glue(gen_, name)(DisasContext *ctx) \
6974 TCGv_ptr ra, rb, rc, rd; \
6975 if (unlikely(!ctx->altivec_enabled)) { \
6976 gen_exception(ctx, POWERPC_EXCP_VPU); \
6979 ra = gen_avr_ptr(rA(ctx->opcode)); \
6980 rb = gen_avr_ptr(rB(ctx->opcode)); \
6981 rc = gen_avr_ptr(rC(ctx->opcode)); \
6982 rd = gen_avr_ptr(rD(ctx->opcode)); \
6983 gen_helper_##name(rd, ra, rb, rc); \
6984 tcg_temp_free_ptr(ra); \
6985 tcg_temp_free_ptr(rb); \
6986 tcg_temp_free_ptr(rc); \
6987 tcg_temp_free_ptr(rd); \
6991 * Support for Altivec instruction pairs that use bit 31 (Rc) as
6992 * an opcode bit. In general, these pairs come from different
6993 * versions of the ISA, so we must also support a pair of flags for
6996 #define GEN_VXFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
6997 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
6999 if ((Rc(ctx->opcode) == 0) && \
7000 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
7002 } else if ((Rc(ctx->opcode) == 1) && \
7003 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
7006 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
7010 GEN_VXFORM(vaddubm
, 0, 0);
7011 GEN_VXFORM(vadduhm
, 0, 1);
7012 GEN_VXFORM(vadduwm
, 0, 2);
7013 GEN_VXFORM(vaddudm
, 0, 3);
7014 GEN_VXFORM(vsububm
, 0, 16);
7015 GEN_VXFORM(vsubuhm
, 0, 17);
7016 GEN_VXFORM(vsubuwm
, 0, 18);
7017 GEN_VXFORM(vsubudm
, 0, 19);
7018 GEN_VXFORM(vmaxub
, 1, 0);
7019 GEN_VXFORM(vmaxuh
, 1, 1);
7020 GEN_VXFORM(vmaxuw
, 1, 2);
7021 GEN_VXFORM(vmaxud
, 1, 3);
7022 GEN_VXFORM(vmaxsb
, 1, 4);
7023 GEN_VXFORM(vmaxsh
, 1, 5);
7024 GEN_VXFORM(vmaxsw
, 1, 6);
7025 GEN_VXFORM(vmaxsd
, 1, 7);
7026 GEN_VXFORM(vminub
, 1, 8);
7027 GEN_VXFORM(vminuh
, 1, 9);
7028 GEN_VXFORM(vminuw
, 1, 10);
7029 GEN_VXFORM(vminud
, 1, 11);
7030 GEN_VXFORM(vminsb
, 1, 12);
7031 GEN_VXFORM(vminsh
, 1, 13);
7032 GEN_VXFORM(vminsw
, 1, 14);
7033 GEN_VXFORM(vminsd
, 1, 15);
7034 GEN_VXFORM(vavgub
, 1, 16);
7035 GEN_VXFORM(vavguh
, 1, 17);
7036 GEN_VXFORM(vavguw
, 1, 18);
7037 GEN_VXFORM(vavgsb
, 1, 20);
7038 GEN_VXFORM(vavgsh
, 1, 21);
7039 GEN_VXFORM(vavgsw
, 1, 22);
7040 GEN_VXFORM(vmrghb
, 6, 0);
7041 GEN_VXFORM(vmrghh
, 6, 1);
7042 GEN_VXFORM(vmrghw
, 6, 2);
7043 GEN_VXFORM(vmrglb
, 6, 4);
7044 GEN_VXFORM(vmrglh
, 6, 5);
7045 GEN_VXFORM(vmrglw
, 6, 6);
7047 static void gen_vmrgew(DisasContext
*ctx
)
7051 if (unlikely(!ctx
->altivec_enabled
)) {
7052 gen_exception(ctx
, POWERPC_EXCP_VPU
);
7055 VT
= rD(ctx
->opcode
);
7056 VA
= rA(ctx
->opcode
);
7057 VB
= rB(ctx
->opcode
);
7058 tmp
= tcg_temp_new_i64();
7059 tcg_gen_shri_i64(tmp
, cpu_avrh
[VB
], 32);
7060 tcg_gen_deposit_i64(cpu_avrh
[VT
], cpu_avrh
[VA
], tmp
, 0, 32);
7061 tcg_gen_shri_i64(tmp
, cpu_avrl
[VB
], 32);
7062 tcg_gen_deposit_i64(cpu_avrl
[VT
], cpu_avrl
[VA
], tmp
, 0, 32);
7063 tcg_temp_free_i64(tmp
);
7066 static void gen_vmrgow(DisasContext
*ctx
)
7069 if (unlikely(!ctx
->altivec_enabled
)) {
7070 gen_exception(ctx
, POWERPC_EXCP_VPU
);
7073 VT
= rD(ctx
->opcode
);
7074 VA
= rA(ctx
->opcode
);
7075 VB
= rB(ctx
->opcode
);
7077 tcg_gen_deposit_i64(cpu_avrh
[VT
], cpu_avrh
[VB
], cpu_avrh
[VA
], 32, 32);
7078 tcg_gen_deposit_i64(cpu_avrl
[VT
], cpu_avrl
[VB
], cpu_avrl
[VA
], 32, 32);
7081 GEN_VXFORM(vmuloub
, 4, 0);
7082 GEN_VXFORM(vmulouh
, 4, 1);
7083 GEN_VXFORM(vmulouw
, 4, 2);
7084 GEN_VXFORM(vmuluwm
, 4, 2);
7085 GEN_VXFORM_DUAL(vmulouw
, PPC_ALTIVEC
, PPC_NONE
,
7086 vmuluwm
, PPC_NONE
, PPC2_ALTIVEC_207
)
7087 GEN_VXFORM(vmulosb
, 4, 4);
7088 GEN_VXFORM(vmulosh
, 4, 5);
7089 GEN_VXFORM(vmulosw
, 4, 6);
7090 GEN_VXFORM(vmuleub
, 4, 8);
7091 GEN_VXFORM(vmuleuh
, 4, 9);
7092 GEN_VXFORM(vmuleuw
, 4, 10);
7093 GEN_VXFORM(vmulesb
, 4, 12);
7094 GEN_VXFORM(vmulesh
, 4, 13);
7095 GEN_VXFORM(vmulesw
, 4, 14);
7096 GEN_VXFORM(vslb
, 2, 4);
7097 GEN_VXFORM(vslh
, 2, 5);
7098 GEN_VXFORM(vslw
, 2, 6);
7099 GEN_VXFORM(vsld
, 2, 23);
7100 GEN_VXFORM(vsrb
, 2, 8);
7101 GEN_VXFORM(vsrh
, 2, 9);
7102 GEN_VXFORM(vsrw
, 2, 10);
7103 GEN_VXFORM(vsrd
, 2, 27);
7104 GEN_VXFORM(vsrab
, 2, 12);
7105 GEN_VXFORM(vsrah
, 2, 13);
7106 GEN_VXFORM(vsraw
, 2, 14);
7107 GEN_VXFORM(vsrad
, 2, 15);
7108 GEN_VXFORM(vslo
, 6, 16);
7109 GEN_VXFORM(vsro
, 6, 17);
7110 GEN_VXFORM(vaddcuw
, 0, 6);
7111 GEN_VXFORM(vsubcuw
, 0, 22);
7112 GEN_VXFORM_ENV(vaddubs
, 0, 8);
7113 GEN_VXFORM_ENV(vadduhs
, 0, 9);
7114 GEN_VXFORM_ENV(vadduws
, 0, 10);
7115 GEN_VXFORM_ENV(vaddsbs
, 0, 12);
7116 GEN_VXFORM_ENV(vaddshs
, 0, 13);
7117 GEN_VXFORM_ENV(vaddsws
, 0, 14);
7118 GEN_VXFORM_ENV(vsububs
, 0, 24);
7119 GEN_VXFORM_ENV(vsubuhs
, 0, 25);
7120 GEN_VXFORM_ENV(vsubuws
, 0, 26);
7121 GEN_VXFORM_ENV(vsubsbs
, 0, 28);
7122 GEN_VXFORM_ENV(vsubshs
, 0, 29);
7123 GEN_VXFORM_ENV(vsubsws
, 0, 30);
7124 GEN_VXFORM(vadduqm
, 0, 4);
7125 GEN_VXFORM(vaddcuq
, 0, 5);
7126 GEN_VXFORM3(vaddeuqm
, 30, 0);
7127 GEN_VXFORM3(vaddecuq
, 30, 0);
7128 GEN_VXFORM_DUAL(vaddeuqm
, PPC_NONE
, PPC2_ALTIVEC_207
, \
7129 vaddecuq
, PPC_NONE
, PPC2_ALTIVEC_207
)
7130 GEN_VXFORM(vsubuqm
, 0, 20);
7131 GEN_VXFORM(vsubcuq
, 0, 21);
7132 GEN_VXFORM3(vsubeuqm
, 31, 0);
7133 GEN_VXFORM3(vsubecuq
, 31, 0);
7134 GEN_VXFORM_DUAL(vsubeuqm
, PPC_NONE
, PPC2_ALTIVEC_207
, \
7135 vsubecuq
, PPC_NONE
, PPC2_ALTIVEC_207
)
7136 GEN_VXFORM(vrlb
, 2, 0);
7137 GEN_VXFORM(vrlh
, 2, 1);
7138 GEN_VXFORM(vrlw
, 2, 2);
7139 GEN_VXFORM(vrld
, 2, 3);
7140 GEN_VXFORM(vsl
, 2, 7);
7141 GEN_VXFORM(vsr
, 2, 11);
7142 GEN_VXFORM_ENV(vpkuhum
, 7, 0);
7143 GEN_VXFORM_ENV(vpkuwum
, 7, 1);
7144 GEN_VXFORM_ENV(vpkudum
, 7, 17);
7145 GEN_VXFORM_ENV(vpkuhus
, 7, 2);
7146 GEN_VXFORM_ENV(vpkuwus
, 7, 3);
7147 GEN_VXFORM_ENV(vpkudus
, 7, 19);
7148 GEN_VXFORM_ENV(vpkshus
, 7, 4);
7149 GEN_VXFORM_ENV(vpkswus
, 7, 5);
7150 GEN_VXFORM_ENV(vpksdus
, 7, 21);
7151 GEN_VXFORM_ENV(vpkshss
, 7, 6);
7152 GEN_VXFORM_ENV(vpkswss
, 7, 7);
7153 GEN_VXFORM_ENV(vpksdss
, 7, 23);
7154 GEN_VXFORM(vpkpx
, 7, 12);
7155 GEN_VXFORM_ENV(vsum4ubs
, 4, 24);
7156 GEN_VXFORM_ENV(vsum4sbs
, 4, 28);
7157 GEN_VXFORM_ENV(vsum4shs
, 4, 25);
7158 GEN_VXFORM_ENV(vsum2sws
, 4, 26);
7159 GEN_VXFORM_ENV(vsumsws
, 4, 30);
7160 GEN_VXFORM_ENV(vaddfp
, 5, 0);
7161 GEN_VXFORM_ENV(vsubfp
, 5, 1);
7162 GEN_VXFORM_ENV(vmaxfp
, 5, 16);
7163 GEN_VXFORM_ENV(vminfp
, 5, 17);
7165 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
7166 static void glue(gen_, name)(DisasContext *ctx) \
7168 TCGv_ptr ra, rb, rd; \
7169 if (unlikely(!ctx->altivec_enabled)) { \
7170 gen_exception(ctx, POWERPC_EXCP_VPU); \
7173 ra = gen_avr_ptr(rA(ctx->opcode)); \
7174 rb = gen_avr_ptr(rB(ctx->opcode)); \
7175 rd = gen_avr_ptr(rD(ctx->opcode)); \
7176 gen_helper_##opname(cpu_env, rd, ra, rb); \
7177 tcg_temp_free_ptr(ra); \
7178 tcg_temp_free_ptr(rb); \
7179 tcg_temp_free_ptr(rd); \
7182 #define GEN_VXRFORM(name, opc2, opc3) \
7183 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
7184 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
7187 * Support for Altivec instructions that use bit 31 (Rc) as an opcode
7188 * bit but also use bit 21 as an actual Rc bit. In general, thse pairs
7189 * come from different versions of the ISA, so we must also support a
7190 * pair of flags for each instruction.
7192 #define GEN_VXRFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
7193 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7195 if ((Rc(ctx->opcode) == 0) && \
7196 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
7197 if (Rc21(ctx->opcode) == 0) { \
7200 gen_##name0##_(ctx); \
7202 } else if ((Rc(ctx->opcode) == 1) && \
7203 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
7204 if (Rc21(ctx->opcode) == 0) { \
7207 gen_##name1##_(ctx); \
7210 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
7214 GEN_VXRFORM(vcmpequb
, 3, 0)
7215 GEN_VXRFORM(vcmpequh
, 3, 1)
7216 GEN_VXRFORM(vcmpequw
, 3, 2)
7217 GEN_VXRFORM(vcmpequd
, 3, 3)
7218 GEN_VXRFORM(vcmpgtsb
, 3, 12)
7219 GEN_VXRFORM(vcmpgtsh
, 3, 13)
7220 GEN_VXRFORM(vcmpgtsw
, 3, 14)
7221 GEN_VXRFORM(vcmpgtsd
, 3, 15)
7222 GEN_VXRFORM(vcmpgtub
, 3, 8)
7223 GEN_VXRFORM(vcmpgtuh
, 3, 9)
7224 GEN_VXRFORM(vcmpgtuw
, 3, 10)
7225 GEN_VXRFORM(vcmpgtud
, 3, 11)
7226 GEN_VXRFORM(vcmpeqfp
, 3, 3)
7227 GEN_VXRFORM(vcmpgefp
, 3, 7)
7228 GEN_VXRFORM(vcmpgtfp
, 3, 11)
7229 GEN_VXRFORM(vcmpbfp
, 3, 15)
7231 GEN_VXRFORM_DUAL(vcmpeqfp
, PPC_ALTIVEC
, PPC_NONE
, \
7232 vcmpequd
, PPC_NONE
, PPC2_ALTIVEC_207
)
7233 GEN_VXRFORM_DUAL(vcmpbfp
, PPC_ALTIVEC
, PPC_NONE
, \
7234 vcmpgtsd
, PPC_NONE
, PPC2_ALTIVEC_207
)
7235 GEN_VXRFORM_DUAL(vcmpgtfp
, PPC_ALTIVEC
, PPC_NONE
, \
7236 vcmpgtud
, PPC_NONE
, PPC2_ALTIVEC_207
)
7238 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
7239 static void glue(gen_, name)(DisasContext *ctx) \
7243 if (unlikely(!ctx->altivec_enabled)) { \
7244 gen_exception(ctx, POWERPC_EXCP_VPU); \
7247 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7248 rd = gen_avr_ptr(rD(ctx->opcode)); \
7249 gen_helper_##name (rd, simm); \
7250 tcg_temp_free_i32(simm); \
7251 tcg_temp_free_ptr(rd); \
7254 GEN_VXFORM_SIMM(vspltisb
, 6, 12);
7255 GEN_VXFORM_SIMM(vspltish
, 6, 13);
7256 GEN_VXFORM_SIMM(vspltisw
, 6, 14);
7258 #define GEN_VXFORM_NOA(name, opc2, opc3) \
7259 static void glue(gen_, name)(DisasContext *ctx) \
7262 if (unlikely(!ctx->altivec_enabled)) { \
7263 gen_exception(ctx, POWERPC_EXCP_VPU); \
7266 rb = gen_avr_ptr(rB(ctx->opcode)); \
7267 rd = gen_avr_ptr(rD(ctx->opcode)); \
7268 gen_helper_##name (rd, rb); \
7269 tcg_temp_free_ptr(rb); \
7270 tcg_temp_free_ptr(rd); \
7273 #define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
7274 static void glue(gen_, name)(DisasContext *ctx) \
7278 if (unlikely(!ctx->altivec_enabled)) { \
7279 gen_exception(ctx, POWERPC_EXCP_VPU); \
7282 rb = gen_avr_ptr(rB(ctx->opcode)); \
7283 rd = gen_avr_ptr(rD(ctx->opcode)); \
7284 gen_helper_##name(cpu_env, rd, rb); \
7285 tcg_temp_free_ptr(rb); \
7286 tcg_temp_free_ptr(rd); \
7289 GEN_VXFORM_NOA(vupkhsb
, 7, 8);
7290 GEN_VXFORM_NOA(vupkhsh
, 7, 9);
7291 GEN_VXFORM_NOA(vupkhsw
, 7, 25);
7292 GEN_VXFORM_NOA(vupklsb
, 7, 10);
7293 GEN_VXFORM_NOA(vupklsh
, 7, 11);
7294 GEN_VXFORM_NOA(vupklsw
, 7, 27);
7295 GEN_VXFORM_NOA(vupkhpx
, 7, 13);
7296 GEN_VXFORM_NOA(vupklpx
, 7, 15);
7297 GEN_VXFORM_NOA_ENV(vrefp
, 5, 4);
7298 GEN_VXFORM_NOA_ENV(vrsqrtefp
, 5, 5);
7299 GEN_VXFORM_NOA_ENV(vexptefp
, 5, 6);
7300 GEN_VXFORM_NOA_ENV(vlogefp
, 5, 7);
7301 GEN_VXFORM_NOA_ENV(vrfim
, 5, 11);
7302 GEN_VXFORM_NOA_ENV(vrfin
, 5, 8);
7303 GEN_VXFORM_NOA_ENV(vrfip
, 5, 10);
7304 GEN_VXFORM_NOA_ENV(vrfiz
, 5, 9);
7306 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
7307 static void glue(gen_, name)(DisasContext *ctx) \
7311 if (unlikely(!ctx->altivec_enabled)) { \
7312 gen_exception(ctx, POWERPC_EXCP_VPU); \
7315 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7316 rd = gen_avr_ptr(rD(ctx->opcode)); \
7317 gen_helper_##name (rd, simm); \
7318 tcg_temp_free_i32(simm); \
7319 tcg_temp_free_ptr(rd); \
7322 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
7323 static void glue(gen_, name)(DisasContext *ctx) \
7327 if (unlikely(!ctx->altivec_enabled)) { \
7328 gen_exception(ctx, POWERPC_EXCP_VPU); \
7331 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7332 rb = gen_avr_ptr(rB(ctx->opcode)); \
7333 rd = gen_avr_ptr(rD(ctx->opcode)); \
7334 gen_helper_##name (rd, rb, uimm); \
7335 tcg_temp_free_i32(uimm); \
7336 tcg_temp_free_ptr(rb); \
7337 tcg_temp_free_ptr(rd); \
7340 #define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
7341 static void glue(gen_, name)(DisasContext *ctx) \
7346 if (unlikely(!ctx->altivec_enabled)) { \
7347 gen_exception(ctx, POWERPC_EXCP_VPU); \
7350 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7351 rb = gen_avr_ptr(rB(ctx->opcode)); \
7352 rd = gen_avr_ptr(rD(ctx->opcode)); \
7353 gen_helper_##name(cpu_env, rd, rb, uimm); \
7354 tcg_temp_free_i32(uimm); \
7355 tcg_temp_free_ptr(rb); \
7356 tcg_temp_free_ptr(rd); \
7359 GEN_VXFORM_UIMM(vspltb
, 6, 8);
7360 GEN_VXFORM_UIMM(vsplth
, 6, 9);
7361 GEN_VXFORM_UIMM(vspltw
, 6, 10);
7362 GEN_VXFORM_UIMM_ENV(vcfux
, 5, 12);
7363 GEN_VXFORM_UIMM_ENV(vcfsx
, 5, 13);
7364 GEN_VXFORM_UIMM_ENV(vctuxs
, 5, 14);
7365 GEN_VXFORM_UIMM_ENV(vctsxs
, 5, 15);
7367 static void gen_vsldoi(DisasContext
*ctx
)
7369 TCGv_ptr ra
, rb
, rd
;
7371 if (unlikely(!ctx
->altivec_enabled
)) {
7372 gen_exception(ctx
, POWERPC_EXCP_VPU
);
7375 ra
= gen_avr_ptr(rA(ctx
->opcode
));
7376 rb
= gen_avr_ptr(rB(ctx
->opcode
));
7377 rd
= gen_avr_ptr(rD(ctx
->opcode
));
7378 sh
= tcg_const_i32(VSH(ctx
->opcode
));
7379 gen_helper_vsldoi (rd
, ra
, rb
, sh
);
7380 tcg_temp_free_ptr(ra
);
7381 tcg_temp_free_ptr(rb
);
7382 tcg_temp_free_ptr(rd
);
7383 tcg_temp_free_i32(sh
);
7386 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
7387 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7389 TCGv_ptr ra, rb, rc, rd; \
7390 if (unlikely(!ctx->altivec_enabled)) { \
7391 gen_exception(ctx, POWERPC_EXCP_VPU); \
7394 ra = gen_avr_ptr(rA(ctx->opcode)); \
7395 rb = gen_avr_ptr(rB(ctx->opcode)); \
7396 rc = gen_avr_ptr(rC(ctx->opcode)); \
7397 rd = gen_avr_ptr(rD(ctx->opcode)); \
7398 if (Rc(ctx->opcode)) { \
7399 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
7401 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
7403 tcg_temp_free_ptr(ra); \
7404 tcg_temp_free_ptr(rb); \
7405 tcg_temp_free_ptr(rc); \
7406 tcg_temp_free_ptr(rd); \
7409 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16)
7411 static void gen_vmladduhm(DisasContext
*ctx
)
7413 TCGv_ptr ra
, rb
, rc
, rd
;
7414 if (unlikely(!ctx
->altivec_enabled
)) {
7415 gen_exception(ctx
, POWERPC_EXCP_VPU
);
7418 ra
= gen_avr_ptr(rA(ctx
->opcode
));
7419 rb
= gen_avr_ptr(rB(ctx
->opcode
));
7420 rc
= gen_avr_ptr(rC(ctx
->opcode
));
7421 rd
= gen_avr_ptr(rD(ctx
->opcode
));
7422 gen_helper_vmladduhm(rd
, ra
, rb
, rc
);
7423 tcg_temp_free_ptr(ra
);
7424 tcg_temp_free_ptr(rb
);
7425 tcg_temp_free_ptr(rc
);
7426 tcg_temp_free_ptr(rd
);
7429 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18)
7430 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19)
7431 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20)
7432 GEN_VAFORM_PAIRED(vsel
, vperm
, 21)
7433 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23)
7435 GEN_VXFORM_NOA(vclzb
, 1, 28)
7436 GEN_VXFORM_NOA(vclzh
, 1, 29)
7437 GEN_VXFORM_NOA(vclzw
, 1, 30)
7438 GEN_VXFORM_NOA(vclzd
, 1, 31)
7439 GEN_VXFORM_NOA(vpopcntb
, 1, 28)
7440 GEN_VXFORM_NOA(vpopcnth
, 1, 29)
7441 GEN_VXFORM_NOA(vpopcntw
, 1, 30)
7442 GEN_VXFORM_NOA(vpopcntd
, 1, 31)
7443 GEN_VXFORM_DUAL(vclzb
, PPC_NONE
, PPC2_ALTIVEC_207
, \
7444 vpopcntb
, PPC_NONE
, PPC2_ALTIVEC_207
)
7445 GEN_VXFORM_DUAL(vclzh
, PPC_NONE
, PPC2_ALTIVEC_207
, \
7446 vpopcnth
, PPC_NONE
, PPC2_ALTIVEC_207
)
7447 GEN_VXFORM_DUAL(vclzw
, PPC_NONE
, PPC2_ALTIVEC_207
, \
7448 vpopcntw
, PPC_NONE
, PPC2_ALTIVEC_207
)
7449 GEN_VXFORM_DUAL(vclzd
, PPC_NONE
, PPC2_ALTIVEC_207
, \
7450 vpopcntd
, PPC_NONE
, PPC2_ALTIVEC_207
)
7451 GEN_VXFORM(vbpermq
, 6, 21);
7452 GEN_VXFORM_NOA(vgbbd
, 6, 20);
7453 GEN_VXFORM(vpmsumb
, 4, 16)
7454 GEN_VXFORM(vpmsumh
, 4, 17)
7455 GEN_VXFORM(vpmsumw
, 4, 18)
7456 GEN_VXFORM(vpmsumd
, 4, 19)
7458 #define GEN_BCD(op) \
7459 static void gen_##op(DisasContext *ctx) \
7461 TCGv_ptr ra, rb, rd; \
7464 if (unlikely(!ctx->altivec_enabled)) { \
7465 gen_exception(ctx, POWERPC_EXCP_VPU); \
7469 ra = gen_avr_ptr(rA(ctx->opcode)); \
7470 rb = gen_avr_ptr(rB(ctx->opcode)); \
7471 rd = gen_avr_ptr(rD(ctx->opcode)); \
7473 ps = tcg_const_i32((ctx->opcode & 0x200) != 0); \
7475 gen_helper_##op(cpu_crf[6], rd, ra, rb, ps); \
7477 tcg_temp_free_ptr(ra); \
7478 tcg_temp_free_ptr(rb); \
7479 tcg_temp_free_ptr(rd); \
7480 tcg_temp_free_i32(ps); \
7486 GEN_VXFORM_DUAL(vsububm
, PPC_ALTIVEC
, PPC_NONE
, \
7487 bcdadd
, PPC_NONE
, PPC2_ALTIVEC_207
)
7488 GEN_VXFORM_DUAL(vsububs
, PPC_ALTIVEC
, PPC_NONE
, \
7489 bcdadd
, PPC_NONE
, PPC2_ALTIVEC_207
)
7490 GEN_VXFORM_DUAL(vsubuhm
, PPC_ALTIVEC
, PPC_NONE
, \
7491 bcdsub
, PPC_NONE
, PPC2_ALTIVEC_207
)
7492 GEN_VXFORM_DUAL(vsubuhs
, PPC_ALTIVEC
, PPC_NONE
, \
7493 bcdsub
, PPC_NONE
, PPC2_ALTIVEC_207
)
7495 static void gen_vsbox(DisasContext
*ctx
)
7498 if (unlikely(!ctx
->altivec_enabled
)) {
7499 gen_exception(ctx
, POWERPC_EXCP_VPU
);
7502 ra
= gen_avr_ptr(rA(ctx
->opcode
));
7503 rd
= gen_avr_ptr(rD(ctx
->opcode
));
7504 gen_helper_vsbox(rd
, ra
);
7505 tcg_temp_free_ptr(ra
);
7506 tcg_temp_free_ptr(rd
);
7509 GEN_VXFORM(vcipher
, 4, 20)
7510 GEN_VXFORM(vcipherlast
, 4, 20)
7511 GEN_VXFORM(vncipher
, 4, 21)
7512 GEN_VXFORM(vncipherlast
, 4, 21)
7514 GEN_VXFORM_DUAL(vcipher
, PPC_NONE
, PPC2_ALTIVEC_207
,
7515 vcipherlast
, PPC_NONE
, PPC2_ALTIVEC_207
)
7516 GEN_VXFORM_DUAL(vncipher
, PPC_NONE
, PPC2_ALTIVEC_207
,
7517 vncipherlast
, PPC_NONE
, PPC2_ALTIVEC_207
)
7519 #define VSHASIGMA(op) \
7520 static void gen_##op(DisasContext *ctx) \
7524 if (unlikely(!ctx->altivec_enabled)) { \
7525 gen_exception(ctx, POWERPC_EXCP_VPU); \
7528 ra = gen_avr_ptr(rA(ctx->opcode)); \
7529 rd = gen_avr_ptr(rD(ctx->opcode)); \
7530 st_six = tcg_const_i32(rB(ctx->opcode)); \
7531 gen_helper_##op(rd, ra, st_six); \
7532 tcg_temp_free_ptr(ra); \
7533 tcg_temp_free_ptr(rd); \
7534 tcg_temp_free_i32(st_six); \
7537 VSHASIGMA(vshasigmaw
)
7538 VSHASIGMA(vshasigmad
)
7540 GEN_VXFORM3(vpermxor
, 22, 0xFF)
7541 GEN_VXFORM_DUAL(vsldoi
, PPC_ALTIVEC
, PPC_NONE
,
7542 vpermxor
, PPC_NONE
, PPC2_ALTIVEC_207
)
7544 /*** VSX extension ***/
7546 static inline TCGv_i64
cpu_vsrh(int n
)
7551 return cpu_avrh
[n
-32];
7555 static inline TCGv_i64
cpu_vsrl(int n
)
7560 return cpu_avrl
[n
-32];
7564 #define VSX_LOAD_SCALAR(name, operation) \
7565 static void gen_##name(DisasContext *ctx) \
7568 if (unlikely(!ctx->vsx_enabled)) { \
7569 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7572 gen_set_access_type(ctx, ACCESS_INT); \
7573 EA = tcg_temp_new(); \
7574 gen_addr_reg_index(ctx, EA); \
7575 gen_qemu_##operation(ctx, cpu_vsrh(xT(ctx->opcode)), EA); \
7576 /* NOTE: cpu_vsrl is undefined */ \
7577 tcg_temp_free(EA); \
7580 VSX_LOAD_SCALAR(lxsdx
, ld64
)
7581 VSX_LOAD_SCALAR(lxsiwax
, ld32s_i64
)
7582 VSX_LOAD_SCALAR(lxsiwzx
, ld32u_i64
)
7583 VSX_LOAD_SCALAR(lxsspx
, ld32fs
)
7585 static void gen_lxvd2x(DisasContext
*ctx
)
7588 if (unlikely(!ctx
->vsx_enabled
)) {
7589 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7592 gen_set_access_type(ctx
, ACCESS_INT
);
7593 EA
= tcg_temp_new();
7594 gen_addr_reg_index(ctx
, EA
);
7595 gen_qemu_ld64(ctx
, cpu_vsrh(xT(ctx
->opcode
)), EA
);
7596 tcg_gen_addi_tl(EA
, EA
, 8);
7597 gen_qemu_ld64(ctx
, cpu_vsrl(xT(ctx
->opcode
)), EA
);
7601 static void gen_lxvdsx(DisasContext
*ctx
)
7604 if (unlikely(!ctx
->vsx_enabled
)) {
7605 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7608 gen_set_access_type(ctx
, ACCESS_INT
);
7609 EA
= tcg_temp_new();
7610 gen_addr_reg_index(ctx
, EA
);
7611 gen_qemu_ld64(ctx
, cpu_vsrh(xT(ctx
->opcode
)), EA
);
7612 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), cpu_vsrh(xT(ctx
->opcode
)));
7616 static void gen_lxvw4x(DisasContext
*ctx
)
7620 TCGv_i64 xth
= cpu_vsrh(xT(ctx
->opcode
));
7621 TCGv_i64 xtl
= cpu_vsrl(xT(ctx
->opcode
));
7622 if (unlikely(!ctx
->vsx_enabled
)) {
7623 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7626 gen_set_access_type(ctx
, ACCESS_INT
);
7627 EA
= tcg_temp_new();
7628 tmp
= tcg_temp_new_i64();
7630 gen_addr_reg_index(ctx
, EA
);
7631 gen_qemu_ld32u_i64(ctx
, tmp
, EA
);
7632 tcg_gen_addi_tl(EA
, EA
, 4);
7633 gen_qemu_ld32u_i64(ctx
, xth
, EA
);
7634 tcg_gen_deposit_i64(xth
, xth
, tmp
, 32, 32);
7636 tcg_gen_addi_tl(EA
, EA
, 4);
7637 gen_qemu_ld32u_i64(ctx
, tmp
, EA
);
7638 tcg_gen_addi_tl(EA
, EA
, 4);
7639 gen_qemu_ld32u_i64(ctx
, xtl
, EA
);
7640 tcg_gen_deposit_i64(xtl
, xtl
, tmp
, 32, 32);
7643 tcg_temp_free_i64(tmp
);
7646 #define VSX_STORE_SCALAR(name, operation) \
7647 static void gen_##name(DisasContext *ctx) \
7650 if (unlikely(!ctx->vsx_enabled)) { \
7651 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7654 gen_set_access_type(ctx, ACCESS_INT); \
7655 EA = tcg_temp_new(); \
7656 gen_addr_reg_index(ctx, EA); \
7657 gen_qemu_##operation(ctx, cpu_vsrh(xS(ctx->opcode)), EA); \
7658 tcg_temp_free(EA); \
7661 VSX_STORE_SCALAR(stxsdx
, st64
)
7662 VSX_STORE_SCALAR(stxsiwx
, st32_i64
)
7663 VSX_STORE_SCALAR(stxsspx
, st32fs
)
7665 static void gen_stxvd2x(DisasContext
*ctx
)
7668 if (unlikely(!ctx
->vsx_enabled
)) {
7669 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7672 gen_set_access_type(ctx
, ACCESS_INT
);
7673 EA
= tcg_temp_new();
7674 gen_addr_reg_index(ctx
, EA
);
7675 gen_qemu_st64(ctx
, cpu_vsrh(xS(ctx
->opcode
)), EA
);
7676 tcg_gen_addi_tl(EA
, EA
, 8);
7677 gen_qemu_st64(ctx
, cpu_vsrl(xS(ctx
->opcode
)), EA
);
7681 static void gen_stxvw4x(DisasContext
*ctx
)
7685 if (unlikely(!ctx
->vsx_enabled
)) {
7686 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7689 gen_set_access_type(ctx
, ACCESS_INT
);
7690 EA
= tcg_temp_new();
7691 gen_addr_reg_index(ctx
, EA
);
7692 tmp
= tcg_temp_new_i64();
7694 tcg_gen_shri_i64(tmp
, cpu_vsrh(xS(ctx
->opcode
)), 32);
7695 gen_qemu_st32_i64(ctx
, tmp
, EA
);
7696 tcg_gen_addi_tl(EA
, EA
, 4);
7697 gen_qemu_st32_i64(ctx
, cpu_vsrh(xS(ctx
->opcode
)), EA
);
7699 tcg_gen_shri_i64(tmp
, cpu_vsrl(xS(ctx
->opcode
)), 32);
7700 tcg_gen_addi_tl(EA
, EA
, 4);
7701 gen_qemu_st32_i64(ctx
, tmp
, EA
);
7702 tcg_gen_addi_tl(EA
, EA
, 4);
7703 gen_qemu_st32_i64(ctx
, cpu_vsrl(xS(ctx
->opcode
)), EA
);
7706 tcg_temp_free_i64(tmp
);
7709 #define MV_VSRW(name, tcgop1, tcgop2, target, source) \
7710 static void gen_##name(DisasContext *ctx) \
7712 if (xS(ctx->opcode) < 32) { \
7713 if (unlikely(!ctx->fpu_enabled)) { \
7714 gen_exception(ctx, POWERPC_EXCP_FPU); \
7718 if (unlikely(!ctx->altivec_enabled)) { \
7719 gen_exception(ctx, POWERPC_EXCP_VPU); \
7723 TCGv_i64 tmp = tcg_temp_new_i64(); \
7724 tcg_gen_##tcgop1(tmp, source); \
7725 tcg_gen_##tcgop2(target, tmp); \
7726 tcg_temp_free_i64(tmp); \
7730 MV_VSRW(mfvsrwz
, ext32u_i64
, trunc_i64_tl
, cpu_gpr
[rA(ctx
->opcode
)], \
7731 cpu_vsrh(xS(ctx
->opcode
)))
7732 MV_VSRW(mtvsrwa
, extu_tl_i64
, ext32s_i64
, cpu_vsrh(xT(ctx
->opcode
)), \
7733 cpu_gpr
[rA(ctx
->opcode
)])
7734 MV_VSRW(mtvsrwz
, extu_tl_i64
, ext32u_i64
, cpu_vsrh(xT(ctx
->opcode
)), \
7735 cpu_gpr
[rA(ctx
->opcode
)])
7737 #if defined(TARGET_PPC64)
7738 #define MV_VSRD(name, target, source) \
7739 static void gen_##name(DisasContext *ctx) \
7741 if (xS(ctx->opcode) < 32) { \
7742 if (unlikely(!ctx->fpu_enabled)) { \
7743 gen_exception(ctx, POWERPC_EXCP_FPU); \
7747 if (unlikely(!ctx->altivec_enabled)) { \
7748 gen_exception(ctx, POWERPC_EXCP_VPU); \
7752 tcg_gen_mov_i64(target, source); \
7755 MV_VSRD(mfvsrd
, cpu_gpr
[rA(ctx
->opcode
)], cpu_vsrh(xS(ctx
->opcode
)))
7756 MV_VSRD(mtvsrd
, cpu_vsrh(xT(ctx
->opcode
)), cpu_gpr
[rA(ctx
->opcode
)])
7760 static void gen_xxpermdi(DisasContext
*ctx
)
7762 if (unlikely(!ctx
->vsx_enabled
)) {
7763 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7767 if (unlikely((xT(ctx
->opcode
) == xA(ctx
->opcode
)) ||
7768 (xT(ctx
->opcode
) == xB(ctx
->opcode
)))) {
7771 xh
= tcg_temp_new_i64();
7772 xl
= tcg_temp_new_i64();
7774 if ((DM(ctx
->opcode
) & 2) == 0) {
7775 tcg_gen_mov_i64(xh
, cpu_vsrh(xA(ctx
->opcode
)));
7777 tcg_gen_mov_i64(xh
, cpu_vsrl(xA(ctx
->opcode
)));
7779 if ((DM(ctx
->opcode
) & 1) == 0) {
7780 tcg_gen_mov_i64(xl
, cpu_vsrh(xB(ctx
->opcode
)));
7782 tcg_gen_mov_i64(xl
, cpu_vsrl(xB(ctx
->opcode
)));
7785 tcg_gen_mov_i64(cpu_vsrh(xT(ctx
->opcode
)), xh
);
7786 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), xl
);
7788 tcg_temp_free_i64(xh
);
7789 tcg_temp_free_i64(xl
);
7791 if ((DM(ctx
->opcode
) & 2) == 0) {
7792 tcg_gen_mov_i64(cpu_vsrh(xT(ctx
->opcode
)), cpu_vsrh(xA(ctx
->opcode
)));
7794 tcg_gen_mov_i64(cpu_vsrh(xT(ctx
->opcode
)), cpu_vsrl(xA(ctx
->opcode
)));
7796 if ((DM(ctx
->opcode
) & 1) == 0) {
7797 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), cpu_vsrh(xB(ctx
->opcode
)));
7799 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), cpu_vsrl(xB(ctx
->opcode
)));
7808 #define SGN_MASK_DP 0x8000000000000000ull
7809 #define SGN_MASK_SP 0x8000000080000000ull
7811 #define VSX_SCALAR_MOVE(name, op, sgn_mask) \
7812 static void glue(gen_, name)(DisasContext * ctx) \
7815 if (unlikely(!ctx->vsx_enabled)) { \
7816 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7819 xb = tcg_temp_new_i64(); \
7820 sgm = tcg_temp_new_i64(); \
7821 tcg_gen_mov_i64(xb, cpu_vsrh(xB(ctx->opcode))); \
7822 tcg_gen_movi_i64(sgm, sgn_mask); \
7825 tcg_gen_andc_i64(xb, xb, sgm); \
7829 tcg_gen_or_i64(xb, xb, sgm); \
7833 tcg_gen_xor_i64(xb, xb, sgm); \
7837 TCGv_i64 xa = tcg_temp_new_i64(); \
7838 tcg_gen_mov_i64(xa, cpu_vsrh(xA(ctx->opcode))); \
7839 tcg_gen_and_i64(xa, xa, sgm); \
7840 tcg_gen_andc_i64(xb, xb, sgm); \
7841 tcg_gen_or_i64(xb, xb, xa); \
7842 tcg_temp_free_i64(xa); \
7846 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xb); \
7847 tcg_temp_free_i64(xb); \
7848 tcg_temp_free_i64(sgm); \
7851 VSX_SCALAR_MOVE(xsabsdp
, OP_ABS
, SGN_MASK_DP
)
7852 VSX_SCALAR_MOVE(xsnabsdp
, OP_NABS
, SGN_MASK_DP
)
7853 VSX_SCALAR_MOVE(xsnegdp
, OP_NEG
, SGN_MASK_DP
)
7854 VSX_SCALAR_MOVE(xscpsgndp
, OP_CPSGN
, SGN_MASK_DP
)
7856 #define VSX_VECTOR_MOVE(name, op, sgn_mask) \
7857 static void glue(gen_, name)(DisasContext * ctx) \
7859 TCGv_i64 xbh, xbl, sgm; \
7860 if (unlikely(!ctx->vsx_enabled)) { \
7861 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7864 xbh = tcg_temp_new_i64(); \
7865 xbl = tcg_temp_new_i64(); \
7866 sgm = tcg_temp_new_i64(); \
7867 tcg_gen_mov_i64(xbh, cpu_vsrh(xB(ctx->opcode))); \
7868 tcg_gen_mov_i64(xbl, cpu_vsrl(xB(ctx->opcode))); \
7869 tcg_gen_movi_i64(sgm, sgn_mask); \
7872 tcg_gen_andc_i64(xbh, xbh, sgm); \
7873 tcg_gen_andc_i64(xbl, xbl, sgm); \
7877 tcg_gen_or_i64(xbh, xbh, sgm); \
7878 tcg_gen_or_i64(xbl, xbl, sgm); \
7882 tcg_gen_xor_i64(xbh, xbh, sgm); \
7883 tcg_gen_xor_i64(xbl, xbl, sgm); \
7887 TCGv_i64 xah = tcg_temp_new_i64(); \
7888 TCGv_i64 xal = tcg_temp_new_i64(); \
7889 tcg_gen_mov_i64(xah, cpu_vsrh(xA(ctx->opcode))); \
7890 tcg_gen_mov_i64(xal, cpu_vsrl(xA(ctx->opcode))); \
7891 tcg_gen_and_i64(xah, xah, sgm); \
7892 tcg_gen_and_i64(xal, xal, sgm); \
7893 tcg_gen_andc_i64(xbh, xbh, sgm); \
7894 tcg_gen_andc_i64(xbl, xbl, sgm); \
7895 tcg_gen_or_i64(xbh, xbh, xah); \
7896 tcg_gen_or_i64(xbl, xbl, xal); \
7897 tcg_temp_free_i64(xah); \
7898 tcg_temp_free_i64(xal); \
7902 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xbh); \
7903 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xbl); \
7904 tcg_temp_free_i64(xbh); \
7905 tcg_temp_free_i64(xbl); \
7906 tcg_temp_free_i64(sgm); \
7909 VSX_VECTOR_MOVE(xvabsdp
, OP_ABS
, SGN_MASK_DP
)
7910 VSX_VECTOR_MOVE(xvnabsdp
, OP_NABS
, SGN_MASK_DP
)
7911 VSX_VECTOR_MOVE(xvnegdp
, OP_NEG
, SGN_MASK_DP
)
7912 VSX_VECTOR_MOVE(xvcpsgndp
, OP_CPSGN
, SGN_MASK_DP
)
7913 VSX_VECTOR_MOVE(xvabssp
, OP_ABS
, SGN_MASK_SP
)
7914 VSX_VECTOR_MOVE(xvnabssp
, OP_NABS
, SGN_MASK_SP
)
7915 VSX_VECTOR_MOVE(xvnegsp
, OP_NEG
, SGN_MASK_SP
)
7916 VSX_VECTOR_MOVE(xvcpsgnsp
, OP_CPSGN
, SGN_MASK_SP
)
7918 #define GEN_VSX_HELPER_2(name, op1, op2, inval, type) \
7919 static void gen_##name(DisasContext * ctx) \
7922 if (unlikely(!ctx->vsx_enabled)) { \
7923 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7926 /* NIP cannot be restored if the memory exception comes from an helper */ \
7927 gen_update_nip(ctx, ctx->nip - 4); \
7928 opc = tcg_const_i32(ctx->opcode); \
7929 gen_helper_##name(cpu_env, opc); \
7930 tcg_temp_free_i32(opc); \
7933 #define GEN_VSX_HELPER_XT_XB_ENV(name, op1, op2, inval, type) \
7934 static void gen_##name(DisasContext * ctx) \
7936 if (unlikely(!ctx->vsx_enabled)) { \
7937 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7940 /* NIP cannot be restored if the exception comes */ \
7941 /* from a helper. */ \
7942 gen_update_nip(ctx, ctx->nip - 4); \
7944 gen_helper_##name(cpu_vsrh(xT(ctx->opcode)), cpu_env, \
7945 cpu_vsrh(xB(ctx->opcode))); \
7948 GEN_VSX_HELPER_2(xsadddp
, 0x00, 0x04, 0, PPC2_VSX
)
7949 GEN_VSX_HELPER_2(xssubdp
, 0x00, 0x05, 0, PPC2_VSX
)
7950 GEN_VSX_HELPER_2(xsmuldp
, 0x00, 0x06, 0, PPC2_VSX
)
7951 GEN_VSX_HELPER_2(xsdivdp
, 0x00, 0x07, 0, PPC2_VSX
)
7952 GEN_VSX_HELPER_2(xsredp
, 0x14, 0x05, 0, PPC2_VSX
)
7953 GEN_VSX_HELPER_2(xssqrtdp
, 0x16, 0x04, 0, PPC2_VSX
)
7954 GEN_VSX_HELPER_2(xsrsqrtedp
, 0x14, 0x04, 0, PPC2_VSX
)
7955 GEN_VSX_HELPER_2(xstdivdp
, 0x14, 0x07, 0, PPC2_VSX
)
7956 GEN_VSX_HELPER_2(xstsqrtdp
, 0x14, 0x06, 0, PPC2_VSX
)
7957 GEN_VSX_HELPER_2(xsmaddadp
, 0x04, 0x04, 0, PPC2_VSX
)
7958 GEN_VSX_HELPER_2(xsmaddmdp
, 0x04, 0x05, 0, PPC2_VSX
)
7959 GEN_VSX_HELPER_2(xsmsubadp
, 0x04, 0x06, 0, PPC2_VSX
)
7960 GEN_VSX_HELPER_2(xsmsubmdp
, 0x04, 0x07, 0, PPC2_VSX
)
7961 GEN_VSX_HELPER_2(xsnmaddadp
, 0x04, 0x14, 0, PPC2_VSX
)
7962 GEN_VSX_HELPER_2(xsnmaddmdp
, 0x04, 0x15, 0, PPC2_VSX
)
7963 GEN_VSX_HELPER_2(xsnmsubadp
, 0x04, 0x16, 0, PPC2_VSX
)
7964 GEN_VSX_HELPER_2(xsnmsubmdp
, 0x04, 0x17, 0, PPC2_VSX
)
7965 GEN_VSX_HELPER_2(xscmpodp
, 0x0C, 0x05, 0, PPC2_VSX
)
7966 GEN_VSX_HELPER_2(xscmpudp
, 0x0C, 0x04, 0, PPC2_VSX
)
7967 GEN_VSX_HELPER_2(xsmaxdp
, 0x00, 0x14, 0, PPC2_VSX
)
7968 GEN_VSX_HELPER_2(xsmindp
, 0x00, 0x15, 0, PPC2_VSX
)
7969 GEN_VSX_HELPER_2(xscvdpsp
, 0x12, 0x10, 0, PPC2_VSX
)
7970 GEN_VSX_HELPER_XT_XB_ENV(xscvdpspn
, 0x16, 0x10, 0, PPC2_VSX207
)
7971 GEN_VSX_HELPER_2(xscvspdp
, 0x12, 0x14, 0, PPC2_VSX
)
7972 GEN_VSX_HELPER_XT_XB_ENV(xscvspdpn
, 0x16, 0x14, 0, PPC2_VSX207
)
7973 GEN_VSX_HELPER_2(xscvdpsxds
, 0x10, 0x15, 0, PPC2_VSX
)
7974 GEN_VSX_HELPER_2(xscvdpsxws
, 0x10, 0x05, 0, PPC2_VSX
)
7975 GEN_VSX_HELPER_2(xscvdpuxds
, 0x10, 0x14, 0, PPC2_VSX
)
7976 GEN_VSX_HELPER_2(xscvdpuxws
, 0x10, 0x04, 0, PPC2_VSX
)
7977 GEN_VSX_HELPER_2(xscvsxddp
, 0x10, 0x17, 0, PPC2_VSX
)
7978 GEN_VSX_HELPER_2(xscvuxddp
, 0x10, 0x16, 0, PPC2_VSX
)
7979 GEN_VSX_HELPER_2(xsrdpi
, 0x12, 0x04, 0, PPC2_VSX
)
7980 GEN_VSX_HELPER_2(xsrdpic
, 0x16, 0x06, 0, PPC2_VSX
)
7981 GEN_VSX_HELPER_2(xsrdpim
, 0x12, 0x07, 0, PPC2_VSX
)
7982 GEN_VSX_HELPER_2(xsrdpip
, 0x12, 0x06, 0, PPC2_VSX
)
7983 GEN_VSX_HELPER_2(xsrdpiz
, 0x12, 0x05, 0, PPC2_VSX
)
7984 GEN_VSX_HELPER_XT_XB_ENV(xsrsp
, 0x12, 0x11, 0, PPC2_VSX207
)
7986 GEN_VSX_HELPER_2(xsaddsp
, 0x00, 0x00, 0, PPC2_VSX207
)
7987 GEN_VSX_HELPER_2(xssubsp
, 0x00, 0x01, 0, PPC2_VSX207
)
7988 GEN_VSX_HELPER_2(xsmulsp
, 0x00, 0x02, 0, PPC2_VSX207
)
7989 GEN_VSX_HELPER_2(xsdivsp
, 0x00, 0x03, 0, PPC2_VSX207
)
7990 GEN_VSX_HELPER_2(xsresp
, 0x14, 0x01, 0, PPC2_VSX207
)
7991 GEN_VSX_HELPER_2(xssqrtsp
, 0x16, 0x00, 0, PPC2_VSX207
)
7992 GEN_VSX_HELPER_2(xsrsqrtesp
, 0x14, 0x00, 0, PPC2_VSX207
)
7993 GEN_VSX_HELPER_2(xsmaddasp
, 0x04, 0x00, 0, PPC2_VSX207
)
7994 GEN_VSX_HELPER_2(xsmaddmsp
, 0x04, 0x01, 0, PPC2_VSX207
)
7995 GEN_VSX_HELPER_2(xsmsubasp
, 0x04, 0x02, 0, PPC2_VSX207
)
7996 GEN_VSX_HELPER_2(xsmsubmsp
, 0x04, 0x03, 0, PPC2_VSX207
)
7997 GEN_VSX_HELPER_2(xsnmaddasp
, 0x04, 0x10, 0, PPC2_VSX207
)
7998 GEN_VSX_HELPER_2(xsnmaddmsp
, 0x04, 0x11, 0, PPC2_VSX207
)
7999 GEN_VSX_HELPER_2(xsnmsubasp
, 0x04, 0x12, 0, PPC2_VSX207
)
8000 GEN_VSX_HELPER_2(xsnmsubmsp
, 0x04, 0x13, 0, PPC2_VSX207
)
8001 GEN_VSX_HELPER_2(xscvsxdsp
, 0x10, 0x13, 0, PPC2_VSX207
)
8002 GEN_VSX_HELPER_2(xscvuxdsp
, 0x10, 0x12, 0, PPC2_VSX207
)
8004 GEN_VSX_HELPER_2(xvadddp
, 0x00, 0x0C, 0, PPC2_VSX
)
8005 GEN_VSX_HELPER_2(xvsubdp
, 0x00, 0x0D, 0, PPC2_VSX
)
8006 GEN_VSX_HELPER_2(xvmuldp
, 0x00, 0x0E, 0, PPC2_VSX
)
8007 GEN_VSX_HELPER_2(xvdivdp
, 0x00, 0x0F, 0, PPC2_VSX
)
8008 GEN_VSX_HELPER_2(xvredp
, 0x14, 0x0D, 0, PPC2_VSX
)
8009 GEN_VSX_HELPER_2(xvsqrtdp
, 0x16, 0x0C, 0, PPC2_VSX
)
8010 GEN_VSX_HELPER_2(xvrsqrtedp
, 0x14, 0x0C, 0, PPC2_VSX
)
8011 GEN_VSX_HELPER_2(xvtdivdp
, 0x14, 0x0F, 0, PPC2_VSX
)
8012 GEN_VSX_HELPER_2(xvtsqrtdp
, 0x14, 0x0E, 0, PPC2_VSX
)
8013 GEN_VSX_HELPER_2(xvmaddadp
, 0x04, 0x0C, 0, PPC2_VSX
)
8014 GEN_VSX_HELPER_2(xvmaddmdp
, 0x04, 0x0D, 0, PPC2_VSX
)
8015 GEN_VSX_HELPER_2(xvmsubadp
, 0x04, 0x0E, 0, PPC2_VSX
)
8016 GEN_VSX_HELPER_2(xvmsubmdp
, 0x04, 0x0F, 0, PPC2_VSX
)
8017 GEN_VSX_HELPER_2(xvnmaddadp
, 0x04, 0x1C, 0, PPC2_VSX
)
8018 GEN_VSX_HELPER_2(xvnmaddmdp
, 0x04, 0x1D, 0, PPC2_VSX
)
8019 GEN_VSX_HELPER_2(xvnmsubadp
, 0x04, 0x1E, 0, PPC2_VSX
)
8020 GEN_VSX_HELPER_2(xvnmsubmdp
, 0x04, 0x1F, 0, PPC2_VSX
)
8021 GEN_VSX_HELPER_2(xvmaxdp
, 0x00, 0x1C, 0, PPC2_VSX
)
8022 GEN_VSX_HELPER_2(xvmindp
, 0x00, 0x1D, 0, PPC2_VSX
)
8023 GEN_VSX_HELPER_2(xvcmpeqdp
, 0x0C, 0x0C, 0, PPC2_VSX
)
8024 GEN_VSX_HELPER_2(xvcmpgtdp
, 0x0C, 0x0D, 0, PPC2_VSX
)
8025 GEN_VSX_HELPER_2(xvcmpgedp
, 0x0C, 0x0E, 0, PPC2_VSX
)
8026 GEN_VSX_HELPER_2(xvcvdpsp
, 0x12, 0x18, 0, PPC2_VSX
)
8027 GEN_VSX_HELPER_2(xvcvdpsxds
, 0x10, 0x1D, 0, PPC2_VSX
)
8028 GEN_VSX_HELPER_2(xvcvdpsxws
, 0x10, 0x0D, 0, PPC2_VSX
)
8029 GEN_VSX_HELPER_2(xvcvdpuxds
, 0x10, 0x1C, 0, PPC2_VSX
)
8030 GEN_VSX_HELPER_2(xvcvdpuxws
, 0x10, 0x0C, 0, PPC2_VSX
)
8031 GEN_VSX_HELPER_2(xvcvsxddp
, 0x10, 0x1F, 0, PPC2_VSX
)
8032 GEN_VSX_HELPER_2(xvcvuxddp
, 0x10, 0x1E, 0, PPC2_VSX
)
8033 GEN_VSX_HELPER_2(xvcvsxwdp
, 0x10, 0x0F, 0, PPC2_VSX
)
8034 GEN_VSX_HELPER_2(xvcvuxwdp
, 0x10, 0x0E, 0, PPC2_VSX
)
8035 GEN_VSX_HELPER_2(xvrdpi
, 0x12, 0x0C, 0, PPC2_VSX
)
8036 GEN_VSX_HELPER_2(xvrdpic
, 0x16, 0x0E, 0, PPC2_VSX
)
8037 GEN_VSX_HELPER_2(xvrdpim
, 0x12, 0x0F, 0, PPC2_VSX
)
8038 GEN_VSX_HELPER_2(xvrdpip
, 0x12, 0x0E, 0, PPC2_VSX
)
8039 GEN_VSX_HELPER_2(xvrdpiz
, 0x12, 0x0D, 0, PPC2_VSX
)
8041 GEN_VSX_HELPER_2(xvaddsp
, 0x00, 0x08, 0, PPC2_VSX
)
8042 GEN_VSX_HELPER_2(xvsubsp
, 0x00, 0x09, 0, PPC2_VSX
)
8043 GEN_VSX_HELPER_2(xvmulsp
, 0x00, 0x0A, 0, PPC2_VSX
)
8044 GEN_VSX_HELPER_2(xvdivsp
, 0x00, 0x0B, 0, PPC2_VSX
)
8045 GEN_VSX_HELPER_2(xvresp
, 0x14, 0x09, 0, PPC2_VSX
)
8046 GEN_VSX_HELPER_2(xvsqrtsp
, 0x16, 0x08, 0, PPC2_VSX
)
8047 GEN_VSX_HELPER_2(xvrsqrtesp
, 0x14, 0x08, 0, PPC2_VSX
)
8048 GEN_VSX_HELPER_2(xvtdivsp
, 0x14, 0x0B, 0, PPC2_VSX
)
8049 GEN_VSX_HELPER_2(xvtsqrtsp
, 0x14, 0x0A, 0, PPC2_VSX
)
8050 GEN_VSX_HELPER_2(xvmaddasp
, 0x04, 0x08, 0, PPC2_VSX
)
8051 GEN_VSX_HELPER_2(xvmaddmsp
, 0x04, 0x09, 0, PPC2_VSX
)
8052 GEN_VSX_HELPER_2(xvmsubasp
, 0x04, 0x0A, 0, PPC2_VSX
)
8053 GEN_VSX_HELPER_2(xvmsubmsp
, 0x04, 0x0B, 0, PPC2_VSX
)
8054 GEN_VSX_HELPER_2(xvnmaddasp
, 0x04, 0x18, 0, PPC2_VSX
)
8055 GEN_VSX_HELPER_2(xvnmaddmsp
, 0x04, 0x19, 0, PPC2_VSX
)
8056 GEN_VSX_HELPER_2(xvnmsubasp
, 0x04, 0x1A, 0, PPC2_VSX
)
8057 GEN_VSX_HELPER_2(xvnmsubmsp
, 0x04, 0x1B, 0, PPC2_VSX
)
8058 GEN_VSX_HELPER_2(xvmaxsp
, 0x00, 0x18, 0, PPC2_VSX
)
8059 GEN_VSX_HELPER_2(xvminsp
, 0x00, 0x19, 0, PPC2_VSX
)
8060 GEN_VSX_HELPER_2(xvcmpeqsp
, 0x0C, 0x08, 0, PPC2_VSX
)
8061 GEN_VSX_HELPER_2(xvcmpgtsp
, 0x0C, 0x09, 0, PPC2_VSX
)
8062 GEN_VSX_HELPER_2(xvcmpgesp
, 0x0C, 0x0A, 0, PPC2_VSX
)
8063 GEN_VSX_HELPER_2(xvcvspdp
, 0x12, 0x1C, 0, PPC2_VSX
)
8064 GEN_VSX_HELPER_2(xvcvspsxds
, 0x10, 0x19, 0, PPC2_VSX
)
8065 GEN_VSX_HELPER_2(xvcvspsxws
, 0x10, 0x09, 0, PPC2_VSX
)
8066 GEN_VSX_HELPER_2(xvcvspuxds
, 0x10, 0x18, 0, PPC2_VSX
)
8067 GEN_VSX_HELPER_2(xvcvspuxws
, 0x10, 0x08, 0, PPC2_VSX
)
8068 GEN_VSX_HELPER_2(xvcvsxdsp
, 0x10, 0x1B, 0, PPC2_VSX
)
8069 GEN_VSX_HELPER_2(xvcvuxdsp
, 0x10, 0x1A, 0, PPC2_VSX
)
8070 GEN_VSX_HELPER_2(xvcvsxwsp
, 0x10, 0x0B, 0, PPC2_VSX
)
8071 GEN_VSX_HELPER_2(xvcvuxwsp
, 0x10, 0x0A, 0, PPC2_VSX
)
8072 GEN_VSX_HELPER_2(xvrspi
, 0x12, 0x08, 0, PPC2_VSX
)
8073 GEN_VSX_HELPER_2(xvrspic
, 0x16, 0x0A, 0, PPC2_VSX
)
8074 GEN_VSX_HELPER_2(xvrspim
, 0x12, 0x0B, 0, PPC2_VSX
)
8075 GEN_VSX_HELPER_2(xvrspip
, 0x12, 0x0A, 0, PPC2_VSX
)
8076 GEN_VSX_HELPER_2(xvrspiz
, 0x12, 0x09, 0, PPC2_VSX
)
8078 #define VSX_LOGICAL(name, tcg_op) \
8079 static void glue(gen_, name)(DisasContext * ctx) \
8081 if (unlikely(!ctx->vsx_enabled)) { \
8082 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8085 tcg_op(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)), \
8086 cpu_vsrh(xB(ctx->opcode))); \
8087 tcg_op(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)), \
8088 cpu_vsrl(xB(ctx->opcode))); \
8091 VSX_LOGICAL(xxland
, tcg_gen_and_i64
)
8092 VSX_LOGICAL(xxlandc
, tcg_gen_andc_i64
)
8093 VSX_LOGICAL(xxlor
, tcg_gen_or_i64
)
8094 VSX_LOGICAL(xxlxor
, tcg_gen_xor_i64
)
8095 VSX_LOGICAL(xxlnor
, tcg_gen_nor_i64
)
8096 VSX_LOGICAL(xxleqv
, tcg_gen_eqv_i64
)
8097 VSX_LOGICAL(xxlnand
, tcg_gen_nand_i64
)
8098 VSX_LOGICAL(xxlorc
, tcg_gen_orc_i64
)
8100 #define VSX_XXMRG(name, high) \
8101 static void glue(gen_, name)(DisasContext * ctx) \
8103 TCGv_i64 a0, a1, b0, b1; \
8104 if (unlikely(!ctx->vsx_enabled)) { \
8105 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8108 a0 = tcg_temp_new_i64(); \
8109 a1 = tcg_temp_new_i64(); \
8110 b0 = tcg_temp_new_i64(); \
8111 b1 = tcg_temp_new_i64(); \
8113 tcg_gen_mov_i64(a0, cpu_vsrh(xA(ctx->opcode))); \
8114 tcg_gen_mov_i64(a1, cpu_vsrh(xA(ctx->opcode))); \
8115 tcg_gen_mov_i64(b0, cpu_vsrh(xB(ctx->opcode))); \
8116 tcg_gen_mov_i64(b1, cpu_vsrh(xB(ctx->opcode))); \
8118 tcg_gen_mov_i64(a0, cpu_vsrl(xA(ctx->opcode))); \
8119 tcg_gen_mov_i64(a1, cpu_vsrl(xA(ctx->opcode))); \
8120 tcg_gen_mov_i64(b0, cpu_vsrl(xB(ctx->opcode))); \
8121 tcg_gen_mov_i64(b1, cpu_vsrl(xB(ctx->opcode))); \
8123 tcg_gen_shri_i64(a0, a0, 32); \
8124 tcg_gen_shri_i64(b0, b0, 32); \
8125 tcg_gen_deposit_i64(cpu_vsrh(xT(ctx->opcode)), \
8127 tcg_gen_deposit_i64(cpu_vsrl(xT(ctx->opcode)), \
8129 tcg_temp_free_i64(a0); \
8130 tcg_temp_free_i64(a1); \
8131 tcg_temp_free_i64(b0); \
8132 tcg_temp_free_i64(b1); \
8135 VSX_XXMRG(xxmrghw
, 1)
8136 VSX_XXMRG(xxmrglw
, 0)
8138 static void gen_xxsel(DisasContext
* ctx
)
8141 if (unlikely(!ctx
->vsx_enabled
)) {
8142 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
8145 a
= tcg_temp_new_i64();
8146 b
= tcg_temp_new_i64();
8147 c
= tcg_temp_new_i64();
8149 tcg_gen_mov_i64(a
, cpu_vsrh(xA(ctx
->opcode
)));
8150 tcg_gen_mov_i64(b
, cpu_vsrh(xB(ctx
->opcode
)));
8151 tcg_gen_mov_i64(c
, cpu_vsrh(xC(ctx
->opcode
)));
8153 tcg_gen_and_i64(b
, b
, c
);
8154 tcg_gen_andc_i64(a
, a
, c
);
8155 tcg_gen_or_i64(cpu_vsrh(xT(ctx
->opcode
)), a
, b
);
8157 tcg_gen_mov_i64(a
, cpu_vsrl(xA(ctx
->opcode
)));
8158 tcg_gen_mov_i64(b
, cpu_vsrl(xB(ctx
->opcode
)));
8159 tcg_gen_mov_i64(c
, cpu_vsrl(xC(ctx
->opcode
)));
8161 tcg_gen_and_i64(b
, b
, c
);
8162 tcg_gen_andc_i64(a
, a
, c
);
8163 tcg_gen_or_i64(cpu_vsrl(xT(ctx
->opcode
)), a
, b
);
8165 tcg_temp_free_i64(a
);
8166 tcg_temp_free_i64(b
);
8167 tcg_temp_free_i64(c
);
8170 static void gen_xxspltw(DisasContext
*ctx
)
8173 TCGv_i64 vsr
= (UIM(ctx
->opcode
) & 2) ?
8174 cpu_vsrl(xB(ctx
->opcode
)) :
8175 cpu_vsrh(xB(ctx
->opcode
));
8177 if (unlikely(!ctx
->vsx_enabled
)) {
8178 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
8182 b
= tcg_temp_new_i64();
8183 b2
= tcg_temp_new_i64();
8185 if (UIM(ctx
->opcode
) & 1) {
8186 tcg_gen_ext32u_i64(b
, vsr
);
8188 tcg_gen_shri_i64(b
, vsr
, 32);
8191 tcg_gen_shli_i64(b2
, b
, 32);
8192 tcg_gen_or_i64(cpu_vsrh(xT(ctx
->opcode
)), b
, b2
);
8193 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), cpu_vsrh(xT(ctx
->opcode
)));
8195 tcg_temp_free_i64(b
);
8196 tcg_temp_free_i64(b2
);
8199 static void gen_xxsldwi(DisasContext
*ctx
)
8202 if (unlikely(!ctx
->vsx_enabled
)) {
8203 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
8206 xth
= tcg_temp_new_i64();
8207 xtl
= tcg_temp_new_i64();
8209 switch (SHW(ctx
->opcode
)) {
8211 tcg_gen_mov_i64(xth
, cpu_vsrh(xA(ctx
->opcode
)));
8212 tcg_gen_mov_i64(xtl
, cpu_vsrl(xA(ctx
->opcode
)));
8216 TCGv_i64 t0
= tcg_temp_new_i64();
8217 tcg_gen_mov_i64(xth
, cpu_vsrh(xA(ctx
->opcode
)));
8218 tcg_gen_shli_i64(xth
, xth
, 32);
8219 tcg_gen_mov_i64(t0
, cpu_vsrl(xA(ctx
->opcode
)));
8220 tcg_gen_shri_i64(t0
, t0
, 32);
8221 tcg_gen_or_i64(xth
, xth
, t0
);
8222 tcg_gen_mov_i64(xtl
, cpu_vsrl(xA(ctx
->opcode
)));
8223 tcg_gen_shli_i64(xtl
, xtl
, 32);
8224 tcg_gen_mov_i64(t0
, cpu_vsrh(xB(ctx
->opcode
)));
8225 tcg_gen_shri_i64(t0
, t0
, 32);
8226 tcg_gen_or_i64(xtl
, xtl
, t0
);
8227 tcg_temp_free_i64(t0
);
8231 tcg_gen_mov_i64(xth
, cpu_vsrl(xA(ctx
->opcode
)));
8232 tcg_gen_mov_i64(xtl
, cpu_vsrh(xB(ctx
->opcode
)));
8236 TCGv_i64 t0
= tcg_temp_new_i64();
8237 tcg_gen_mov_i64(xth
, cpu_vsrl(xA(ctx
->opcode
)));
8238 tcg_gen_shli_i64(xth
, xth
, 32);
8239 tcg_gen_mov_i64(t0
, cpu_vsrh(xB(ctx
->opcode
)));
8240 tcg_gen_shri_i64(t0
, t0
, 32);
8241 tcg_gen_or_i64(xth
, xth
, t0
);
8242 tcg_gen_mov_i64(xtl
, cpu_vsrh(xB(ctx
->opcode
)));
8243 tcg_gen_shli_i64(xtl
, xtl
, 32);
8244 tcg_gen_mov_i64(t0
, cpu_vsrl(xB(ctx
->opcode
)));
8245 tcg_gen_shri_i64(t0
, t0
, 32);
8246 tcg_gen_or_i64(xtl
, xtl
, t0
);
8247 tcg_temp_free_i64(t0
);
8252 tcg_gen_mov_i64(cpu_vsrh(xT(ctx
->opcode
)), xth
);
8253 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), xtl
);
8255 tcg_temp_free_i64(xth
);
8256 tcg_temp_free_i64(xtl
);
8259 /*** Decimal Floating Point ***/
8261 static inline TCGv_ptr
gen_fprp_ptr(int reg
)
8263 TCGv_ptr r
= tcg_temp_new_ptr();
8264 tcg_gen_addi_ptr(r
, cpu_env
, offsetof(CPUPPCState
, fpr
[reg
]));
8268 #define GEN_DFP_T_A_B_Rc(name) \
8269 static void gen_##name(DisasContext *ctx) \
8271 TCGv_ptr rd, ra, rb; \
8272 if (unlikely(!ctx->fpu_enabled)) { \
8273 gen_exception(ctx, POWERPC_EXCP_FPU); \
8276 gen_update_nip(ctx, ctx->nip - 4); \
8277 rd = gen_fprp_ptr(rD(ctx->opcode)); \
8278 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8279 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8280 gen_helper_##name(cpu_env, rd, ra, rb); \
8281 if (unlikely(Rc(ctx->opcode) != 0)) { \
8282 gen_set_cr1_from_fpscr(ctx); \
8284 tcg_temp_free_ptr(rd); \
8285 tcg_temp_free_ptr(ra); \
8286 tcg_temp_free_ptr(rb); \
8289 #define GEN_DFP_BF_A_B(name) \
8290 static void gen_##name(DisasContext *ctx) \
8293 if (unlikely(!ctx->fpu_enabled)) { \
8294 gen_exception(ctx, POWERPC_EXCP_FPU); \
8297 gen_update_nip(ctx, ctx->nip - 4); \
8298 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8299 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8300 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
8302 tcg_temp_free_ptr(ra); \
8303 tcg_temp_free_ptr(rb); \
8306 #define GEN_DFP_BF_A_DCM(name) \
8307 static void gen_##name(DisasContext *ctx) \
8311 if (unlikely(!ctx->fpu_enabled)) { \
8312 gen_exception(ctx, POWERPC_EXCP_FPU); \
8315 gen_update_nip(ctx, ctx->nip - 4); \
8316 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8317 dcm = tcg_const_i32(DCM(ctx->opcode)); \
8318 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
8319 cpu_env, ra, dcm); \
8320 tcg_temp_free_ptr(ra); \
8321 tcg_temp_free_i32(dcm); \
8324 #define GEN_DFP_T_B_U32_U32_Rc(name, u32f1, u32f2) \
8325 static void gen_##name(DisasContext *ctx) \
8328 TCGv_i32 u32_1, u32_2; \
8329 if (unlikely(!ctx->fpu_enabled)) { \
8330 gen_exception(ctx, POWERPC_EXCP_FPU); \
8333 gen_update_nip(ctx, ctx->nip - 4); \
8334 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8335 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8336 u32_1 = tcg_const_i32(u32f1(ctx->opcode)); \
8337 u32_2 = tcg_const_i32(u32f2(ctx->opcode)); \
8338 gen_helper_##name(cpu_env, rt, rb, u32_1, u32_2); \
8339 if (unlikely(Rc(ctx->opcode) != 0)) { \
8340 gen_set_cr1_from_fpscr(ctx); \
8342 tcg_temp_free_ptr(rt); \
8343 tcg_temp_free_ptr(rb); \
8344 tcg_temp_free_i32(u32_1); \
8345 tcg_temp_free_i32(u32_2); \
8348 #define GEN_DFP_T_A_B_I32_Rc(name, i32fld) \
8349 static void gen_##name(DisasContext *ctx) \
8351 TCGv_ptr rt, ra, rb; \
8353 if (unlikely(!ctx->fpu_enabled)) { \
8354 gen_exception(ctx, POWERPC_EXCP_FPU); \
8357 gen_update_nip(ctx, ctx->nip - 4); \
8358 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8359 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8360 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8361 i32 = tcg_const_i32(i32fld(ctx->opcode)); \
8362 gen_helper_##name(cpu_env, rt, ra, rb, i32); \
8363 if (unlikely(Rc(ctx->opcode) != 0)) { \
8364 gen_set_cr1_from_fpscr(ctx); \
8366 tcg_temp_free_ptr(rt); \
8367 tcg_temp_free_ptr(rb); \
8368 tcg_temp_free_ptr(ra); \
8369 tcg_temp_free_i32(i32); \
8372 #define GEN_DFP_T_B_Rc(name) \
8373 static void gen_##name(DisasContext *ctx) \
8376 if (unlikely(!ctx->fpu_enabled)) { \
8377 gen_exception(ctx, POWERPC_EXCP_FPU); \
8380 gen_update_nip(ctx, ctx->nip - 4); \
8381 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8382 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8383 gen_helper_##name(cpu_env, rt, rb); \
8384 if (unlikely(Rc(ctx->opcode) != 0)) { \
8385 gen_set_cr1_from_fpscr(ctx); \
8387 tcg_temp_free_ptr(rt); \
8388 tcg_temp_free_ptr(rb); \
8391 #define GEN_DFP_T_FPR_I32_Rc(name, fprfld, i32fld) \
8392 static void gen_##name(DisasContext *ctx) \
8396 if (unlikely(!ctx->fpu_enabled)) { \
8397 gen_exception(ctx, POWERPC_EXCP_FPU); \
8400 gen_update_nip(ctx, ctx->nip - 4); \
8401 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8402 rs = gen_fprp_ptr(fprfld(ctx->opcode)); \
8403 i32 = tcg_const_i32(i32fld(ctx->opcode)); \
8404 gen_helper_##name(cpu_env, rt, rs, i32); \
8405 if (unlikely(Rc(ctx->opcode) != 0)) { \
8406 gen_set_cr1_from_fpscr(ctx); \
8408 tcg_temp_free_ptr(rt); \
8409 tcg_temp_free_ptr(rs); \
8410 tcg_temp_free_i32(i32); \
8413 GEN_DFP_T_A_B_Rc(dadd
)
8414 GEN_DFP_T_A_B_Rc(daddq
)
8415 GEN_DFP_T_A_B_Rc(dsub
)
8416 GEN_DFP_T_A_B_Rc(dsubq
)
8417 GEN_DFP_T_A_B_Rc(dmul
)
8418 GEN_DFP_T_A_B_Rc(dmulq
)
8419 GEN_DFP_T_A_B_Rc(ddiv
)
8420 GEN_DFP_T_A_B_Rc(ddivq
)
8421 GEN_DFP_BF_A_B(dcmpu
)
8422 GEN_DFP_BF_A_B(dcmpuq
)
8423 GEN_DFP_BF_A_B(dcmpo
)
8424 GEN_DFP_BF_A_B(dcmpoq
)
8425 GEN_DFP_BF_A_DCM(dtstdc
)
8426 GEN_DFP_BF_A_DCM(dtstdcq
)
8427 GEN_DFP_BF_A_DCM(dtstdg
)
8428 GEN_DFP_BF_A_DCM(dtstdgq
)
8429 GEN_DFP_BF_A_B(dtstex
)
8430 GEN_DFP_BF_A_B(dtstexq
)
8431 GEN_DFP_BF_A_B(dtstsf
)
8432 GEN_DFP_BF_A_B(dtstsfq
)
8433 GEN_DFP_T_B_U32_U32_Rc(dquai
, SIMM5
, RMC
)
8434 GEN_DFP_T_B_U32_U32_Rc(dquaiq
, SIMM5
, RMC
)
8435 GEN_DFP_T_A_B_I32_Rc(dqua
, RMC
)
8436 GEN_DFP_T_A_B_I32_Rc(dquaq
, RMC
)
8437 GEN_DFP_T_A_B_I32_Rc(drrnd
, RMC
)
8438 GEN_DFP_T_A_B_I32_Rc(drrndq
, RMC
)
8439 GEN_DFP_T_B_U32_U32_Rc(drintx
, FPW
, RMC
)
8440 GEN_DFP_T_B_U32_U32_Rc(drintxq
, FPW
, RMC
)
8441 GEN_DFP_T_B_U32_U32_Rc(drintn
, FPW
, RMC
)
8442 GEN_DFP_T_B_U32_U32_Rc(drintnq
, FPW
, RMC
)
8443 GEN_DFP_T_B_Rc(dctdp
)
8444 GEN_DFP_T_B_Rc(dctqpq
)
8445 GEN_DFP_T_B_Rc(drsp
)
8446 GEN_DFP_T_B_Rc(drdpq
)
8447 GEN_DFP_T_B_Rc(dcffix
)
8448 GEN_DFP_T_B_Rc(dcffixq
)
8449 GEN_DFP_T_B_Rc(dctfix
)
8450 GEN_DFP_T_B_Rc(dctfixq
)
8451 GEN_DFP_T_FPR_I32_Rc(ddedpd
, rB
, SP
)
8452 GEN_DFP_T_FPR_I32_Rc(ddedpdq
, rB
, SP
)
8453 GEN_DFP_T_FPR_I32_Rc(denbcd
, rB
, SP
)
8454 GEN_DFP_T_FPR_I32_Rc(denbcdq
, rB
, SP
)
8455 GEN_DFP_T_B_Rc(dxex
)
8456 GEN_DFP_T_B_Rc(dxexq
)
8457 GEN_DFP_T_A_B_Rc(diex
)
8458 GEN_DFP_T_A_B_Rc(diexq
)
8459 GEN_DFP_T_FPR_I32_Rc(dscli
, rA
, DCM
)
8460 GEN_DFP_T_FPR_I32_Rc(dscliq
, rA
, DCM
)
8461 GEN_DFP_T_FPR_I32_Rc(dscri
, rA
, DCM
)
8462 GEN_DFP_T_FPR_I32_Rc(dscriq
, rA
, DCM
)
8464 /*** SPE extension ***/
8465 /* Register moves */
8467 static inline void gen_evmra(DisasContext
*ctx
)
8470 if (unlikely(!ctx
->spe_enabled
)) {
8471 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8475 TCGv_i64 tmp
= tcg_temp_new_i64();
8477 /* tmp := rA_lo + rA_hi << 32 */
8478 tcg_gen_concat_tl_i64(tmp
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
8480 /* spe_acc := tmp */
8481 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8482 tcg_temp_free_i64(tmp
);
8485 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8486 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
8489 static inline void gen_load_gpr64(TCGv_i64 t
, int reg
)
8491 tcg_gen_concat_tl_i64(t
, cpu_gpr
[reg
], cpu_gprh
[reg
]);
8494 static inline void gen_store_gpr64(int reg
, TCGv_i64 t
)
8496 tcg_gen_extr_i64_tl(cpu_gpr
[reg
], cpu_gprh
[reg
], t
);
8499 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
8500 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
8502 if (Rc(ctx->opcode)) \
8508 /* Handler for undefined SPE opcodes */
8509 static inline void gen_speundef(DisasContext
*ctx
)
8511 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
8515 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
8516 static inline void gen_##name(DisasContext *ctx) \
8518 if (unlikely(!ctx->spe_enabled)) { \
8519 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8522 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8523 cpu_gpr[rB(ctx->opcode)]); \
8524 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8525 cpu_gprh[rB(ctx->opcode)]); \
8528 GEN_SPEOP_LOGIC2(evand
, tcg_gen_and_tl
);
8529 GEN_SPEOP_LOGIC2(evandc
, tcg_gen_andc_tl
);
8530 GEN_SPEOP_LOGIC2(evxor
, tcg_gen_xor_tl
);
8531 GEN_SPEOP_LOGIC2(evor
, tcg_gen_or_tl
);
8532 GEN_SPEOP_LOGIC2(evnor
, tcg_gen_nor_tl
);
8533 GEN_SPEOP_LOGIC2(eveqv
, tcg_gen_eqv_tl
);
8534 GEN_SPEOP_LOGIC2(evorc
, tcg_gen_orc_tl
);
8535 GEN_SPEOP_LOGIC2(evnand
, tcg_gen_nand_tl
);
8537 /* SPE logic immediate */
8538 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
8539 static inline void gen_##name(DisasContext *ctx) \
8542 if (unlikely(!ctx->spe_enabled)) { \
8543 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8546 t0 = tcg_temp_new_i32(); \
8548 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8549 tcg_opi(t0, t0, rB(ctx->opcode)); \
8550 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8552 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
8553 tcg_opi(t0, t0, rB(ctx->opcode)); \
8554 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8556 tcg_temp_free_i32(t0); \
8558 GEN_SPEOP_TCG_LOGIC_IMM2(evslwi
, tcg_gen_shli_i32
);
8559 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu
, tcg_gen_shri_i32
);
8560 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis
, tcg_gen_sari_i32
);
8561 GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi
, tcg_gen_rotli_i32
);
8563 /* SPE arithmetic */
8564 #define GEN_SPEOP_ARITH1(name, tcg_op) \
8565 static inline void gen_##name(DisasContext *ctx) \
8568 if (unlikely(!ctx->spe_enabled)) { \
8569 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8572 t0 = tcg_temp_new_i32(); \
8574 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8576 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8578 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
8580 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8582 tcg_temp_free_i32(t0); \
8585 static inline void gen_op_evabs(TCGv_i32 ret
, TCGv_i32 arg1
)
8587 TCGLabel
*l1
= gen_new_label();
8588 TCGLabel
*l2
= gen_new_label();
8590 tcg_gen_brcondi_i32(TCG_COND_GE
, arg1
, 0, l1
);
8591 tcg_gen_neg_i32(ret
, arg1
);
8594 tcg_gen_mov_i32(ret
, arg1
);
8597 GEN_SPEOP_ARITH1(evabs
, gen_op_evabs
);
8598 GEN_SPEOP_ARITH1(evneg
, tcg_gen_neg_i32
);
8599 GEN_SPEOP_ARITH1(evextsb
, tcg_gen_ext8s_i32
);
8600 GEN_SPEOP_ARITH1(evextsh
, tcg_gen_ext16s_i32
);
8601 static inline void gen_op_evrndw(TCGv_i32 ret
, TCGv_i32 arg1
)
8603 tcg_gen_addi_i32(ret
, arg1
, 0x8000);
8604 tcg_gen_ext16u_i32(ret
, ret
);
8606 GEN_SPEOP_ARITH1(evrndw
, gen_op_evrndw
);
8607 GEN_SPEOP_ARITH1(evcntlsw
, gen_helper_cntlsw32
);
8608 GEN_SPEOP_ARITH1(evcntlzw
, gen_helper_cntlzw32
);
8610 #define GEN_SPEOP_ARITH2(name, tcg_op) \
8611 static inline void gen_##name(DisasContext *ctx) \
8614 if (unlikely(!ctx->spe_enabled)) { \
8615 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8618 t0 = tcg_temp_new_i32(); \
8619 t1 = tcg_temp_new_i32(); \
8621 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8622 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8623 tcg_op(t0, t0, t1); \
8624 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8626 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
8627 tcg_gen_trunc_tl_i32(t1, cpu_gprh[rB(ctx->opcode)]); \
8628 tcg_op(t0, t0, t1); \
8629 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8631 tcg_temp_free_i32(t0); \
8632 tcg_temp_free_i32(t1); \
8635 static inline void gen_op_evsrwu(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
8637 TCGLabel
*l1
= gen_new_label();
8638 TCGLabel
*l2
= gen_new_label();
8639 TCGv_i32 t0
= tcg_temp_local_new_i32();
8641 /* No error here: 6 bits are used */
8642 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
8643 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
8644 tcg_gen_shr_i32(ret
, arg1
, t0
);
8647 tcg_gen_movi_i32(ret
, 0);
8649 tcg_temp_free_i32(t0
);
8651 GEN_SPEOP_ARITH2(evsrwu
, gen_op_evsrwu
);
8652 static inline void gen_op_evsrws(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
8654 TCGLabel
*l1
= gen_new_label();
8655 TCGLabel
*l2
= gen_new_label();
8656 TCGv_i32 t0
= tcg_temp_local_new_i32();
8658 /* No error here: 6 bits are used */
8659 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
8660 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
8661 tcg_gen_sar_i32(ret
, arg1
, t0
);
8664 tcg_gen_movi_i32(ret
, 0);
8666 tcg_temp_free_i32(t0
);
8668 GEN_SPEOP_ARITH2(evsrws
, gen_op_evsrws
);
8669 static inline void gen_op_evslw(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
8671 TCGLabel
*l1
= gen_new_label();
8672 TCGLabel
*l2
= gen_new_label();
8673 TCGv_i32 t0
= tcg_temp_local_new_i32();
8675 /* No error here: 6 bits are used */
8676 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
8677 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
8678 tcg_gen_shl_i32(ret
, arg1
, t0
);
8681 tcg_gen_movi_i32(ret
, 0);
8683 tcg_temp_free_i32(t0
);
8685 GEN_SPEOP_ARITH2(evslw
, gen_op_evslw
);
8686 static inline void gen_op_evrlw(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
8688 TCGv_i32 t0
= tcg_temp_new_i32();
8689 tcg_gen_andi_i32(t0
, arg2
, 0x1F);
8690 tcg_gen_rotl_i32(ret
, arg1
, t0
);
8691 tcg_temp_free_i32(t0
);
8693 GEN_SPEOP_ARITH2(evrlw
, gen_op_evrlw
);
8694 static inline void gen_evmergehi(DisasContext
*ctx
)
8696 if (unlikely(!ctx
->spe_enabled
)) {
8697 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8700 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
8701 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
8703 GEN_SPEOP_ARITH2(evaddw
, tcg_gen_add_i32
);
8704 static inline void gen_op_evsubf(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
8706 tcg_gen_sub_i32(ret
, arg2
, arg1
);
8708 GEN_SPEOP_ARITH2(evsubfw
, gen_op_evsubf
);
8710 /* SPE arithmetic immediate */
8711 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
8712 static inline void gen_##name(DisasContext *ctx) \
8715 if (unlikely(!ctx->spe_enabled)) { \
8716 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8719 t0 = tcg_temp_new_i32(); \
8721 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8722 tcg_op(t0, t0, rA(ctx->opcode)); \
8723 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8725 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rB(ctx->opcode)]); \
8726 tcg_op(t0, t0, rA(ctx->opcode)); \
8727 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8729 tcg_temp_free_i32(t0); \
8731 GEN_SPEOP_ARITH_IMM2(evaddiw
, tcg_gen_addi_i32
);
8732 GEN_SPEOP_ARITH_IMM2(evsubifw
, tcg_gen_subi_i32
);
8734 /* SPE comparison */
8735 #define GEN_SPEOP_COMP(name, tcg_cond) \
8736 static inline void gen_##name(DisasContext *ctx) \
8738 if (unlikely(!ctx->spe_enabled)) { \
8739 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8742 TCGLabel *l1 = gen_new_label(); \
8743 TCGLabel *l2 = gen_new_label(); \
8744 TCGLabel *l3 = gen_new_label(); \
8745 TCGLabel *l4 = gen_new_label(); \
8747 tcg_gen_ext32s_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
8748 tcg_gen_ext32s_tl(cpu_gpr[rB(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8749 tcg_gen_ext32s_tl(cpu_gprh[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
8750 tcg_gen_ext32s_tl(cpu_gprh[rB(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); \
8752 tcg_gen_brcond_tl(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
8753 cpu_gpr[rB(ctx->opcode)], l1); \
8754 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
8756 gen_set_label(l1); \
8757 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8758 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8759 gen_set_label(l2); \
8760 tcg_gen_brcond_tl(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
8761 cpu_gprh[rB(ctx->opcode)], l3); \
8762 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8763 ~(CRF_CH | CRF_CH_AND_CL)); \
8765 gen_set_label(l3); \
8766 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8767 CRF_CH | CRF_CH_OR_CL); \
8768 gen_set_label(l4); \
8770 GEN_SPEOP_COMP(evcmpgtu
, TCG_COND_GTU
);
8771 GEN_SPEOP_COMP(evcmpgts
, TCG_COND_GT
);
8772 GEN_SPEOP_COMP(evcmpltu
, TCG_COND_LTU
);
8773 GEN_SPEOP_COMP(evcmplts
, TCG_COND_LT
);
8774 GEN_SPEOP_COMP(evcmpeq
, TCG_COND_EQ
);
8777 static inline void gen_brinc(DisasContext
*ctx
)
8779 /* Note: brinc is usable even if SPE is disabled */
8780 gen_helper_brinc(cpu_gpr
[rD(ctx
->opcode
)],
8781 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
8783 static inline void gen_evmergelo(DisasContext
*ctx
)
8785 if (unlikely(!ctx
->spe_enabled
)) {
8786 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8789 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8790 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
8792 static inline void gen_evmergehilo(DisasContext
*ctx
)
8794 if (unlikely(!ctx
->spe_enabled
)) {
8795 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8798 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
8799 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
8801 static inline void gen_evmergelohi(DisasContext
*ctx
)
8803 if (unlikely(!ctx
->spe_enabled
)) {
8804 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8807 if (rD(ctx
->opcode
) == rA(ctx
->opcode
)) {
8808 TCGv tmp
= tcg_temp_new();
8809 tcg_gen_mov_tl(tmp
, cpu_gpr
[rA(ctx
->opcode
)]);
8810 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
8811 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], tmp
);
8814 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
8815 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8818 static inline void gen_evsplati(DisasContext
*ctx
)
8820 uint64_t imm
= ((int32_t)(rA(ctx
->opcode
) << 27)) >> 27;
8822 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], imm
);
8823 tcg_gen_movi_tl(cpu_gprh
[rD(ctx
->opcode
)], imm
);
8825 static inline void gen_evsplatfi(DisasContext
*ctx
)
8827 uint64_t imm
= rA(ctx
->opcode
) << 27;
8829 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], imm
);
8830 tcg_gen_movi_tl(cpu_gprh
[rD(ctx
->opcode
)], imm
);
8833 static inline void gen_evsel(DisasContext
*ctx
)
8835 TCGLabel
*l1
= gen_new_label();
8836 TCGLabel
*l2
= gen_new_label();
8837 TCGLabel
*l3
= gen_new_label();
8838 TCGLabel
*l4
= gen_new_label();
8839 TCGv_i32 t0
= tcg_temp_local_new_i32();
8841 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 3);
8842 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
8843 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
8846 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
8848 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 2);
8849 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l3
);
8850 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8853 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
8855 tcg_temp_free_i32(t0
);
8858 static void gen_evsel0(DisasContext
*ctx
)
8863 static void gen_evsel1(DisasContext
*ctx
)
8868 static void gen_evsel2(DisasContext
*ctx
)
8873 static void gen_evsel3(DisasContext
*ctx
)
8880 static inline void gen_evmwumi(DisasContext
*ctx
)
8884 if (unlikely(!ctx
->spe_enabled
)) {
8885 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8889 t0
= tcg_temp_new_i64();
8890 t1
= tcg_temp_new_i64();
8892 /* t0 := rA; t1 := rB */
8893 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
8894 tcg_gen_ext32u_i64(t0
, t0
);
8895 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
8896 tcg_gen_ext32u_i64(t1
, t1
);
8898 tcg_gen_mul_i64(t0
, t0
, t1
); /* t0 := rA * rB */
8900 gen_store_gpr64(rD(ctx
->opcode
), t0
); /* rD := t0 */
8902 tcg_temp_free_i64(t0
);
8903 tcg_temp_free_i64(t1
);
8906 static inline void gen_evmwumia(DisasContext
*ctx
)
8910 if (unlikely(!ctx
->spe_enabled
)) {
8911 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8915 gen_evmwumi(ctx
); /* rD := rA * rB */
8917 tmp
= tcg_temp_new_i64();
8920 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
8921 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8922 tcg_temp_free_i64(tmp
);
8925 static inline void gen_evmwumiaa(DisasContext
*ctx
)
8930 if (unlikely(!ctx
->spe_enabled
)) {
8931 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8935 gen_evmwumi(ctx
); /* rD := rA * rB */
8937 acc
= tcg_temp_new_i64();
8938 tmp
= tcg_temp_new_i64();
8941 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
8944 tcg_gen_ld_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8946 /* acc := tmp + acc */
8947 tcg_gen_add_i64(acc
, acc
, tmp
);
8950 tcg_gen_st_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8953 gen_store_gpr64(rD(ctx
->opcode
), acc
);
8955 tcg_temp_free_i64(acc
);
8956 tcg_temp_free_i64(tmp
);
8959 static inline void gen_evmwsmi(DisasContext
*ctx
)
8963 if (unlikely(!ctx
->spe_enabled
)) {
8964 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8968 t0
= tcg_temp_new_i64();
8969 t1
= tcg_temp_new_i64();
8971 /* t0 := rA; t1 := rB */
8972 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
8973 tcg_gen_ext32s_i64(t0
, t0
);
8974 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
8975 tcg_gen_ext32s_i64(t1
, t1
);
8977 tcg_gen_mul_i64(t0
, t0
, t1
); /* t0 := rA * rB */
8979 gen_store_gpr64(rD(ctx
->opcode
), t0
); /* rD := t0 */
8981 tcg_temp_free_i64(t0
);
8982 tcg_temp_free_i64(t1
);
8985 static inline void gen_evmwsmia(DisasContext
*ctx
)
8989 gen_evmwsmi(ctx
); /* rD := rA * rB */
8991 tmp
= tcg_temp_new_i64();
8994 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
8995 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8997 tcg_temp_free_i64(tmp
);
9000 static inline void gen_evmwsmiaa(DisasContext
*ctx
)
9002 TCGv_i64 acc
= tcg_temp_new_i64();
9003 TCGv_i64 tmp
= tcg_temp_new_i64();
9005 gen_evmwsmi(ctx
); /* rD := rA * rB */
9007 acc
= tcg_temp_new_i64();
9008 tmp
= tcg_temp_new_i64();
9011 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
9014 tcg_gen_ld_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
9016 /* acc := tmp + acc */
9017 tcg_gen_add_i64(acc
, acc
, tmp
);
9020 tcg_gen_st_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
9023 gen_store_gpr64(rD(ctx
->opcode
), acc
);
9025 tcg_temp_free_i64(acc
);
9026 tcg_temp_free_i64(tmp
);
9029 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
9030 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
9031 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
9032 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
9033 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
9034 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
9035 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
9036 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE
); //
9037 GEN_SPE(evmra
, speundef
, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE
);
9038 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
); ////
9039 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
9040 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
9041 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
9042 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
9043 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
9044 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
9045 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
); ////
9046 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
9047 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
9048 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE
);
9049 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
9050 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
9051 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE
); //
9052 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE
);
9053 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
9054 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
9055 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE
); ////
9056 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE
); ////
9057 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE
); ////
9059 /* SPE load and stores */
9060 static inline void gen_addr_spe_imm_index(DisasContext
*ctx
, TCGv EA
, int sh
)
9062 target_ulong uimm
= rB(ctx
->opcode
);
9064 if (rA(ctx
->opcode
) == 0) {
9065 tcg_gen_movi_tl(EA
, uimm
<< sh
);
9067 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], uimm
<< sh
);
9068 if (NARROW_MODE(ctx
)) {
9069 tcg_gen_ext32u_tl(EA
, EA
);
9074 static inline void gen_op_evldd(DisasContext
*ctx
, TCGv addr
)
9076 TCGv_i64 t0
= tcg_temp_new_i64();
9077 gen_qemu_ld64(ctx
, t0
, addr
);
9078 gen_store_gpr64(rD(ctx
->opcode
), t0
);
9079 tcg_temp_free_i64(t0
);
9082 static inline void gen_op_evldw(DisasContext
*ctx
, TCGv addr
)
9084 gen_qemu_ld32u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
9085 gen_addr_add(ctx
, addr
, addr
, 4);
9086 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
9089 static inline void gen_op_evldh(DisasContext
*ctx
, TCGv addr
)
9091 TCGv t0
= tcg_temp_new();
9092 gen_qemu_ld16u(ctx
, t0
, addr
);
9093 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
9094 gen_addr_add(ctx
, addr
, addr
, 2);
9095 gen_qemu_ld16u(ctx
, t0
, addr
);
9096 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
9097 gen_addr_add(ctx
, addr
, addr
, 2);
9098 gen_qemu_ld16u(ctx
, t0
, addr
);
9099 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
9100 gen_addr_add(ctx
, addr
, addr
, 2);
9101 gen_qemu_ld16u(ctx
, t0
, addr
);
9102 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
9106 static inline void gen_op_evlhhesplat(DisasContext
*ctx
, TCGv addr
)
9108 TCGv t0
= tcg_temp_new();
9109 gen_qemu_ld16u(ctx
, t0
, addr
);
9110 tcg_gen_shli_tl(t0
, t0
, 16);
9111 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
9112 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
9116 static inline void gen_op_evlhhousplat(DisasContext
*ctx
, TCGv addr
)
9118 TCGv t0
= tcg_temp_new();
9119 gen_qemu_ld16u(ctx
, t0
, addr
);
9120 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
9121 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
9125 static inline void gen_op_evlhhossplat(DisasContext
*ctx
, TCGv addr
)
9127 TCGv t0
= tcg_temp_new();
9128 gen_qemu_ld16s(ctx
, t0
, addr
);
9129 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
9130 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
9134 static inline void gen_op_evlwhe(DisasContext
*ctx
, TCGv addr
)
9136 TCGv t0
= tcg_temp_new();
9137 gen_qemu_ld16u(ctx
, t0
, addr
);
9138 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
9139 gen_addr_add(ctx
, addr
, addr
, 2);
9140 gen_qemu_ld16u(ctx
, t0
, addr
);
9141 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
9145 static inline void gen_op_evlwhou(DisasContext
*ctx
, TCGv addr
)
9147 gen_qemu_ld16u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
9148 gen_addr_add(ctx
, addr
, addr
, 2);
9149 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
9152 static inline void gen_op_evlwhos(DisasContext
*ctx
, TCGv addr
)
9154 gen_qemu_ld16s(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
9155 gen_addr_add(ctx
, addr
, addr
, 2);
9156 gen_qemu_ld16s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
9159 static inline void gen_op_evlwwsplat(DisasContext
*ctx
, TCGv addr
)
9161 TCGv t0
= tcg_temp_new();
9162 gen_qemu_ld32u(ctx
, t0
, addr
);
9163 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
9164 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
9168 static inline void gen_op_evlwhsplat(DisasContext
*ctx
, TCGv addr
)
9170 TCGv t0
= tcg_temp_new();
9171 gen_qemu_ld16u(ctx
, t0
, addr
);
9172 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
9173 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
9174 gen_addr_add(ctx
, addr
, addr
, 2);
9175 gen_qemu_ld16u(ctx
, t0
, addr
);
9176 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
9177 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
9181 static inline void gen_op_evstdd(DisasContext
*ctx
, TCGv addr
)
9183 TCGv_i64 t0
= tcg_temp_new_i64();
9184 gen_load_gpr64(t0
, rS(ctx
->opcode
));
9185 gen_qemu_st64(ctx
, t0
, addr
);
9186 tcg_temp_free_i64(t0
);
9189 static inline void gen_op_evstdw(DisasContext
*ctx
, TCGv addr
)
9191 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
9192 gen_addr_add(ctx
, addr
, addr
, 4);
9193 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
9196 static inline void gen_op_evstdh(DisasContext
*ctx
, TCGv addr
)
9198 TCGv t0
= tcg_temp_new();
9199 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
9200 gen_qemu_st16(ctx
, t0
, addr
);
9201 gen_addr_add(ctx
, addr
, addr
, 2);
9202 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
9203 gen_addr_add(ctx
, addr
, addr
, 2);
9204 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
9205 gen_qemu_st16(ctx
, t0
, addr
);
9207 gen_addr_add(ctx
, addr
, addr
, 2);
9208 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
9211 static inline void gen_op_evstwhe(DisasContext
*ctx
, TCGv addr
)
9213 TCGv t0
= tcg_temp_new();
9214 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
9215 gen_qemu_st16(ctx
, t0
, addr
);
9216 gen_addr_add(ctx
, addr
, addr
, 2);
9217 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
9218 gen_qemu_st16(ctx
, t0
, addr
);
9222 static inline void gen_op_evstwho(DisasContext
*ctx
, TCGv addr
)
9224 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
9225 gen_addr_add(ctx
, addr
, addr
, 2);
9226 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
9229 static inline void gen_op_evstwwe(DisasContext
*ctx
, TCGv addr
)
9231 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
9234 static inline void gen_op_evstwwo(DisasContext
*ctx
, TCGv addr
)
9236 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
9239 #define GEN_SPEOP_LDST(name, opc2, sh) \
9240 static void glue(gen_, name)(DisasContext *ctx) \
9243 if (unlikely(!ctx->spe_enabled)) { \
9244 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9247 gen_set_access_type(ctx, ACCESS_INT); \
9248 t0 = tcg_temp_new(); \
9249 if (Rc(ctx->opcode)) { \
9250 gen_addr_spe_imm_index(ctx, t0, sh); \
9252 gen_addr_reg_index(ctx, t0); \
9254 gen_op_##name(ctx, t0); \
9255 tcg_temp_free(t0); \
9258 GEN_SPEOP_LDST(evldd
, 0x00, 3);
9259 GEN_SPEOP_LDST(evldw
, 0x01, 3);
9260 GEN_SPEOP_LDST(evldh
, 0x02, 3);
9261 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1);
9262 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1);
9263 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1);
9264 GEN_SPEOP_LDST(evlwhe
, 0x08, 2);
9265 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2);
9266 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2);
9267 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2);
9268 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2);
9270 GEN_SPEOP_LDST(evstdd
, 0x10, 3);
9271 GEN_SPEOP_LDST(evstdw
, 0x11, 3);
9272 GEN_SPEOP_LDST(evstdh
, 0x12, 3);
9273 GEN_SPEOP_LDST(evstwhe
, 0x18, 2);
9274 GEN_SPEOP_LDST(evstwho
, 0x1A, 2);
9275 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2);
9276 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2);
9278 /* Multiply and add - TODO */
9280 GEN_SPE(speundef
, evmhessf
, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);//
9281 GEN_SPE(speundef
, evmhossf
, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9282 GEN_SPE(evmheumi
, evmhesmi
, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
9283 GEN_SPE(speundef
, evmhesmf
, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9284 GEN_SPE(evmhoumi
, evmhosmi
, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
9285 GEN_SPE(speundef
, evmhosmf
, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9286 GEN_SPE(speundef
, evmhessfa
, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9287 GEN_SPE(speundef
, evmhossfa
, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9288 GEN_SPE(evmheumia
, evmhesmia
, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
9289 GEN_SPE(speundef
, evmhesmfa
, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9290 GEN_SPE(evmhoumia
, evmhosmia
, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
9291 GEN_SPE(speundef
, evmhosmfa
, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9293 GEN_SPE(speundef
, evmwhssf
, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9294 GEN_SPE(evmwlumi
, speundef
, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
9295 GEN_SPE(evmwhumi
, evmwhsmi
, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
9296 GEN_SPE(speundef
, evmwhsmf
, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9297 GEN_SPE(speundef
, evmwssf
, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9298 GEN_SPE(speundef
, evmwsmf
, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9299 GEN_SPE(speundef
, evmwhssfa
, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9300 GEN_SPE(evmwlumia
, speundef
, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
9301 GEN_SPE(evmwhumia
, evmwhsmia
, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
9302 GEN_SPE(speundef
, evmwhsmfa
, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9303 GEN_SPE(speundef
, evmwssfa
, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9304 GEN_SPE(speundef
, evmwsmfa
, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9306 GEN_SPE(evadduiaaw
, evaddsiaaw
, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
9307 GEN_SPE(evsubfusiaaw
, evsubfssiaaw
, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
9308 GEN_SPE(evaddumiaaw
, evaddsmiaaw
, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
9309 GEN_SPE(evsubfumiaaw
, evsubfsmiaaw
, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
9310 GEN_SPE(evdivws
, evdivwu
, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE
);
9312 GEN_SPE(evmheusiaaw
, evmhessiaaw
, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9313 GEN_SPE(speundef
, evmhessfaaw
, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9314 GEN_SPE(evmhousiaaw
, evmhossiaaw
, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9315 GEN_SPE(speundef
, evmhossfaaw
, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9316 GEN_SPE(evmheumiaaw
, evmhesmiaaw
, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9317 GEN_SPE(speundef
, evmhesmfaaw
, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9318 GEN_SPE(evmhoumiaaw
, evmhosmiaaw
, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9319 GEN_SPE(speundef
, evmhosmfaaw
, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9320 GEN_SPE(evmhegumiaa
, evmhegsmiaa
, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9321 GEN_SPE(speundef
, evmhegsmfaa
, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9322 GEN_SPE(evmhogumiaa
, evmhogsmiaa
, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9323 GEN_SPE(speundef
, evmhogsmfaa
, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9325 GEN_SPE(evmwlusiaaw
, evmwlssiaaw
, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
9326 GEN_SPE(evmwlumiaaw
, evmwlsmiaaw
, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
9327 GEN_SPE(speundef
, evmwssfaa
, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9328 GEN_SPE(speundef
, evmwsmfaa
, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9330 GEN_SPE(evmheusianw
, evmhessianw
, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9331 GEN_SPE(speundef
, evmhessfanw
, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9332 GEN_SPE(evmhousianw
, evmhossianw
, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9333 GEN_SPE(speundef
, evmhossfanw
, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9334 GEN_SPE(evmheumianw
, evmhesmianw
, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9335 GEN_SPE(speundef
, evmhesmfanw
, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9336 GEN_SPE(evmhoumianw
, evmhosmianw
, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9337 GEN_SPE(speundef
, evmhosmfanw
, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9338 GEN_SPE(evmhegumian
, evmhegsmian
, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9339 GEN_SPE(speundef
, evmhegsmfan
, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9340 GEN_SPE(evmhigumian
, evmhigsmian
, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9341 GEN_SPE(speundef
, evmhogsmfan
, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9343 GEN_SPE(evmwlusianw
, evmwlssianw
, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
9344 GEN_SPE(evmwlumianw
, evmwlsmianw
, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
9345 GEN_SPE(speundef
, evmwssfan
, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9346 GEN_SPE(evmwumian
, evmwsmian
, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
9347 GEN_SPE(speundef
, evmwsmfan
, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9350 /*** SPE floating-point extension ***/
9351 #define GEN_SPEFPUOP_CONV_32_32(name) \
9352 static inline void gen_##name(DisasContext *ctx) \
9354 TCGv_i32 t0 = tcg_temp_new_i32(); \
9355 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
9356 gen_helper_##name(t0, cpu_env, t0); \
9357 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
9358 tcg_temp_free_i32(t0); \
9360 #define GEN_SPEFPUOP_CONV_32_64(name) \
9361 static inline void gen_##name(DisasContext *ctx) \
9363 TCGv_i64 t0 = tcg_temp_new_i64(); \
9364 TCGv_i32 t1 = tcg_temp_new_i32(); \
9365 gen_load_gpr64(t0, rB(ctx->opcode)); \
9366 gen_helper_##name(t1, cpu_env, t0); \
9367 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1); \
9368 tcg_temp_free_i64(t0); \
9369 tcg_temp_free_i32(t1); \
9371 #define GEN_SPEFPUOP_CONV_64_32(name) \
9372 static inline void gen_##name(DisasContext *ctx) \
9374 TCGv_i64 t0 = tcg_temp_new_i64(); \
9375 TCGv_i32 t1 = tcg_temp_new_i32(); \
9376 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9377 gen_helper_##name(t0, cpu_env, t1); \
9378 gen_store_gpr64(rD(ctx->opcode), t0); \
9379 tcg_temp_free_i64(t0); \
9380 tcg_temp_free_i32(t1); \
9382 #define GEN_SPEFPUOP_CONV_64_64(name) \
9383 static inline void gen_##name(DisasContext *ctx) \
9385 TCGv_i64 t0 = tcg_temp_new_i64(); \
9386 gen_load_gpr64(t0, rB(ctx->opcode)); \
9387 gen_helper_##name(t0, cpu_env, t0); \
9388 gen_store_gpr64(rD(ctx->opcode), t0); \
9389 tcg_temp_free_i64(t0); \
9391 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
9392 static inline void gen_##name(DisasContext *ctx) \
9395 if (unlikely(!ctx->spe_enabled)) { \
9396 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9399 t0 = tcg_temp_new_i32(); \
9400 t1 = tcg_temp_new_i32(); \
9401 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9402 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9403 gen_helper_##name(t0, cpu_env, t0, t1); \
9404 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
9406 tcg_temp_free_i32(t0); \
9407 tcg_temp_free_i32(t1); \
9409 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
9410 static inline void gen_##name(DisasContext *ctx) \
9413 if (unlikely(!ctx->spe_enabled)) { \
9414 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9417 t0 = tcg_temp_new_i64(); \
9418 t1 = tcg_temp_new_i64(); \
9419 gen_load_gpr64(t0, rA(ctx->opcode)); \
9420 gen_load_gpr64(t1, rB(ctx->opcode)); \
9421 gen_helper_##name(t0, cpu_env, t0, t1); \
9422 gen_store_gpr64(rD(ctx->opcode), t0); \
9423 tcg_temp_free_i64(t0); \
9424 tcg_temp_free_i64(t1); \
9426 #define GEN_SPEFPUOP_COMP_32(name) \
9427 static inline void gen_##name(DisasContext *ctx) \
9430 if (unlikely(!ctx->spe_enabled)) { \
9431 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9434 t0 = tcg_temp_new_i32(); \
9435 t1 = tcg_temp_new_i32(); \
9437 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9438 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9439 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
9441 tcg_temp_free_i32(t0); \
9442 tcg_temp_free_i32(t1); \
9444 #define GEN_SPEFPUOP_COMP_64(name) \
9445 static inline void gen_##name(DisasContext *ctx) \
9448 if (unlikely(!ctx->spe_enabled)) { \
9449 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9452 t0 = tcg_temp_new_i64(); \
9453 t1 = tcg_temp_new_i64(); \
9454 gen_load_gpr64(t0, rA(ctx->opcode)); \
9455 gen_load_gpr64(t1, rB(ctx->opcode)); \
9456 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
9457 tcg_temp_free_i64(t0); \
9458 tcg_temp_free_i64(t1); \
9461 /* Single precision floating-point vectors operations */
9463 GEN_SPEFPUOP_ARITH2_64_64(evfsadd
);
9464 GEN_SPEFPUOP_ARITH2_64_64(evfssub
);
9465 GEN_SPEFPUOP_ARITH2_64_64(evfsmul
);
9466 GEN_SPEFPUOP_ARITH2_64_64(evfsdiv
);
9467 static inline void gen_evfsabs(DisasContext
*ctx
)
9469 if (unlikely(!ctx
->spe_enabled
)) {
9470 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9473 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
9475 tcg_gen_andi_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)],
9478 static inline void gen_evfsnabs(DisasContext
*ctx
)
9480 if (unlikely(!ctx
->spe_enabled
)) {
9481 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9484 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
9486 tcg_gen_ori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)],
9489 static inline void gen_evfsneg(DisasContext
*ctx
)
9491 if (unlikely(!ctx
->spe_enabled
)) {
9492 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9495 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
9497 tcg_gen_xori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)],
9502 GEN_SPEFPUOP_CONV_64_64(evfscfui
);
9503 GEN_SPEFPUOP_CONV_64_64(evfscfsi
);
9504 GEN_SPEFPUOP_CONV_64_64(evfscfuf
);
9505 GEN_SPEFPUOP_CONV_64_64(evfscfsf
);
9506 GEN_SPEFPUOP_CONV_64_64(evfsctui
);
9507 GEN_SPEFPUOP_CONV_64_64(evfsctsi
);
9508 GEN_SPEFPUOP_CONV_64_64(evfsctuf
);
9509 GEN_SPEFPUOP_CONV_64_64(evfsctsf
);
9510 GEN_SPEFPUOP_CONV_64_64(evfsctuiz
);
9511 GEN_SPEFPUOP_CONV_64_64(evfsctsiz
);
9514 GEN_SPEFPUOP_COMP_64(evfscmpgt
);
9515 GEN_SPEFPUOP_COMP_64(evfscmplt
);
9516 GEN_SPEFPUOP_COMP_64(evfscmpeq
);
9517 GEN_SPEFPUOP_COMP_64(evfststgt
);
9518 GEN_SPEFPUOP_COMP_64(evfststlt
);
9519 GEN_SPEFPUOP_COMP_64(evfststeq
);
9521 /* Opcodes definitions */
9522 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
9523 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
); //
9524 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9525 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
9526 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
9527 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9528 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9529 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9530 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9531 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9532 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9533 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9534 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
9535 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9537 /* Single precision floating-point operations */
9539 GEN_SPEFPUOP_ARITH2_32_32(efsadd
);
9540 GEN_SPEFPUOP_ARITH2_32_32(efssub
);
9541 GEN_SPEFPUOP_ARITH2_32_32(efsmul
);
9542 GEN_SPEFPUOP_ARITH2_32_32(efsdiv
);
9543 static inline void gen_efsabs(DisasContext
*ctx
)
9545 if (unlikely(!ctx
->spe_enabled
)) {
9546 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9549 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], (target_long
)~0x80000000LL
);
9551 static inline void gen_efsnabs(DisasContext
*ctx
)
9553 if (unlikely(!ctx
->spe_enabled
)) {
9554 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9557 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
9559 static inline void gen_efsneg(DisasContext
*ctx
)
9561 if (unlikely(!ctx
->spe_enabled
)) {
9562 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9565 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
9569 GEN_SPEFPUOP_CONV_32_32(efscfui
);
9570 GEN_SPEFPUOP_CONV_32_32(efscfsi
);
9571 GEN_SPEFPUOP_CONV_32_32(efscfuf
);
9572 GEN_SPEFPUOP_CONV_32_32(efscfsf
);
9573 GEN_SPEFPUOP_CONV_32_32(efsctui
);
9574 GEN_SPEFPUOP_CONV_32_32(efsctsi
);
9575 GEN_SPEFPUOP_CONV_32_32(efsctuf
);
9576 GEN_SPEFPUOP_CONV_32_32(efsctsf
);
9577 GEN_SPEFPUOP_CONV_32_32(efsctuiz
);
9578 GEN_SPEFPUOP_CONV_32_32(efsctsiz
);
9579 GEN_SPEFPUOP_CONV_32_64(efscfd
);
9582 GEN_SPEFPUOP_COMP_32(efscmpgt
);
9583 GEN_SPEFPUOP_COMP_32(efscmplt
);
9584 GEN_SPEFPUOP_COMP_32(efscmpeq
);
9585 GEN_SPEFPUOP_COMP_32(efststgt
);
9586 GEN_SPEFPUOP_COMP_32(efststlt
);
9587 GEN_SPEFPUOP_COMP_32(efststeq
);
9589 /* Opcodes definitions */
9590 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
9591 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
); //
9592 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9593 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
9594 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
9595 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE
); //
9596 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9597 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9598 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9599 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9600 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9601 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9602 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
9603 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9605 /* Double precision floating-point operations */
9607 GEN_SPEFPUOP_ARITH2_64_64(efdadd
);
9608 GEN_SPEFPUOP_ARITH2_64_64(efdsub
);
9609 GEN_SPEFPUOP_ARITH2_64_64(efdmul
);
9610 GEN_SPEFPUOP_ARITH2_64_64(efddiv
);
9611 static inline void gen_efdabs(DisasContext
*ctx
)
9613 if (unlikely(!ctx
->spe_enabled
)) {
9614 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9617 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
9618 tcg_gen_andi_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)],
9621 static inline void gen_efdnabs(DisasContext
*ctx
)
9623 if (unlikely(!ctx
->spe_enabled
)) {
9624 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9627 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
9628 tcg_gen_ori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)],
9631 static inline void gen_efdneg(DisasContext
*ctx
)
9633 if (unlikely(!ctx
->spe_enabled
)) {
9634 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9637 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
9638 tcg_gen_xori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)],
9643 GEN_SPEFPUOP_CONV_64_32(efdcfui
);
9644 GEN_SPEFPUOP_CONV_64_32(efdcfsi
);
9645 GEN_SPEFPUOP_CONV_64_32(efdcfuf
);
9646 GEN_SPEFPUOP_CONV_64_32(efdcfsf
);
9647 GEN_SPEFPUOP_CONV_32_64(efdctui
);
9648 GEN_SPEFPUOP_CONV_32_64(efdctsi
);
9649 GEN_SPEFPUOP_CONV_32_64(efdctuf
);
9650 GEN_SPEFPUOP_CONV_32_64(efdctsf
);
9651 GEN_SPEFPUOP_CONV_32_64(efdctuiz
);
9652 GEN_SPEFPUOP_CONV_32_64(efdctsiz
);
9653 GEN_SPEFPUOP_CONV_64_32(efdcfs
);
9654 GEN_SPEFPUOP_CONV_64_64(efdcfuid
);
9655 GEN_SPEFPUOP_CONV_64_64(efdcfsid
);
9656 GEN_SPEFPUOP_CONV_64_64(efdctuidz
);
9657 GEN_SPEFPUOP_CONV_64_64(efdctsidz
);
9660 GEN_SPEFPUOP_COMP_64(efdcmpgt
);
9661 GEN_SPEFPUOP_COMP_64(efdcmplt
);
9662 GEN_SPEFPUOP_COMP_64(efdcmpeq
);
9663 GEN_SPEFPUOP_COMP_64(efdtstgt
);
9664 GEN_SPEFPUOP_COMP_64(efdtstlt
);
9665 GEN_SPEFPUOP_COMP_64(efdtsteq
);
9667 /* Opcodes definitions */
9668 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
); //
9669 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9670 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE
); //
9671 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
9672 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
); //
9673 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9674 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
); //
9675 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE
); //
9676 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9677 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9678 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9679 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9680 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
9681 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
9682 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
); //
9683 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
9685 static void gen_tbegin(DisasContext
*ctx
)
9687 if (unlikely(!ctx
->tm_enabled
)) {
9688 gen_exception_err(ctx
, POWERPC_EXCP_FU
, FSCR_IC_TM
);
9691 gen_helper_tbegin(cpu_env
);
9694 #define GEN_TM_NOOP(name) \
9695 static inline void gen_##name(DisasContext *ctx) \
9697 if (unlikely(!ctx->tm_enabled)) { \
9698 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
9701 /* Because tbegin always fails in QEMU, these user \
9702 * space instructions all have a simple implementation: \
9704 * CR[0] = 0b0 || MSR[TS] || 0b0 \
9705 * = 0b0 || 0b00 || 0b0 \
9707 tcg_gen_movi_i32(cpu_crf[0], 0); \
9711 GEN_TM_NOOP(tabort
);
9712 GEN_TM_NOOP(tabortwc
);
9713 GEN_TM_NOOP(tabortwci
);
9714 GEN_TM_NOOP(tabortdc
);
9715 GEN_TM_NOOP(tabortdci
);
9718 static void gen_tcheck(DisasContext
*ctx
)
9720 if (unlikely(!ctx
->tm_enabled
)) {
9721 gen_exception_err(ctx
, POWERPC_EXCP_FU
, FSCR_IC_TM
);
9724 /* Because tbegin always fails, the tcheck implementation
9727 * CR[CRF] = TDOOMED || MSR[TS] || 0b0
9728 * = 0b1 || 0b00 || 0b0
9730 tcg_gen_movi_i32(cpu_crf
[crfD(ctx
->opcode
)], 0x8);
9733 #if defined(CONFIG_USER_ONLY)
9734 #define GEN_TM_PRIV_NOOP(name) \
9735 static inline void gen_##name(DisasContext *ctx) \
9737 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); \
9742 #define GEN_TM_PRIV_NOOP(name) \
9743 static inline void gen_##name(DisasContext *ctx) \
9745 if (unlikely(ctx->pr)) { \
9746 gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); \
9749 if (unlikely(!ctx->tm_enabled)) { \
9750 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
9753 /* Because tbegin always fails, the implementation is \
9756 * CR[0] = 0b0 || MSR[TS] || 0b0 \
9757 * = 0b0 || 0b00 | 0b0 \
9759 tcg_gen_movi_i32(cpu_crf[0], 0); \
9764 GEN_TM_PRIV_NOOP(treclaim
);
9765 GEN_TM_PRIV_NOOP(trechkpt
);
9767 static opcode_t opcodes
[] = {
9768 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
),
9769 GEN_HANDLER(cmp
, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER
),
9770 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
9771 GEN_HANDLER(cmpl
, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER
),
9772 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
9773 GEN_HANDLER_E(cmpb
, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE
, PPC2_ISA205
),
9774 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
),
9775 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9776 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9777 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9778 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9779 GEN_HANDLER(mulhw
, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER
),
9780 GEN_HANDLER(mulhwu
, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER
),
9781 GEN_HANDLER(mullw
, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER
),
9782 GEN_HANDLER(mullwo
, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER
),
9783 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9784 #if defined(TARGET_PPC64)
9785 GEN_HANDLER(mulld
, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B
),
9787 GEN_HANDLER(neg
, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER
),
9788 GEN_HANDLER(nego
, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER
),
9789 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9790 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9791 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9792 GEN_HANDLER(cntlzw
, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER
),
9793 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
),
9794 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
),
9795 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9796 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9797 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9798 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9799 GEN_HANDLER(popcntb
, 0x1F, 0x1A, 0x03, 0x0000F801, PPC_POPCNTB
),
9800 GEN_HANDLER(popcntw
, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD
),
9801 GEN_HANDLER_E(prtyw
, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
9802 #if defined(TARGET_PPC64)
9803 GEN_HANDLER(popcntd
, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD
),
9804 GEN_HANDLER(cntlzd
, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B
),
9805 GEN_HANDLER_E(prtyd
, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
9806 GEN_HANDLER_E(bpermd
, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE
, PPC2_PERM_ISA206
),
9808 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9809 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9810 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9811 GEN_HANDLER(slw
, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER
),
9812 GEN_HANDLER(sraw
, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER
),
9813 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
),
9814 GEN_HANDLER(srw
, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER
),
9815 #if defined(TARGET_PPC64)
9816 GEN_HANDLER(sld
, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B
),
9817 GEN_HANDLER(srad
, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B
),
9818 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
),
9819 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
),
9820 GEN_HANDLER(srd
, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B
),
9822 GEN_HANDLER(frsqrtes
, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES
),
9823 GEN_HANDLER(fsqrt
, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
9824 GEN_HANDLER(fsqrts
, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
9825 GEN_HANDLER(fcmpo
, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT
),
9826 GEN_HANDLER(fcmpu
, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT
),
9827 GEN_HANDLER(fabs
, 0x3F, 0x08, 0x08, 0x001F0000, PPC_FLOAT
),
9828 GEN_HANDLER(fmr
, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT
),
9829 GEN_HANDLER(fnabs
, 0x3F, 0x08, 0x04, 0x001F0000, PPC_FLOAT
),
9830 GEN_HANDLER(fneg
, 0x3F, 0x08, 0x01, 0x001F0000, PPC_FLOAT
),
9831 GEN_HANDLER_E(fcpsgn
, 0x3F, 0x08, 0x00, 0x00000000, PPC_NONE
, PPC2_ISA205
),
9832 GEN_HANDLER_E(fmrgew
, 0x3F, 0x06, 0x1E, 0x00000001, PPC_NONE
, PPC2_VSX207
),
9833 GEN_HANDLER_E(fmrgow
, 0x3F, 0x06, 0x1A, 0x00000001, PPC_NONE
, PPC2_VSX207
),
9834 GEN_HANDLER(mcrfs
, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT
),
9835 GEN_HANDLER(mffs
, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT
),
9836 GEN_HANDLER(mtfsb0
, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT
),
9837 GEN_HANDLER(mtfsb1
, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT
),
9838 GEN_HANDLER(mtfsf
, 0x3F, 0x07, 0x16, 0x00000000, PPC_FLOAT
),
9839 GEN_HANDLER(mtfsfi
, 0x3F, 0x06, 0x04, 0x006e0800, PPC_FLOAT
),
9840 #if defined(TARGET_PPC64)
9841 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
),
9842 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
),
9843 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
),
9845 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9846 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9847 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
),
9848 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
),
9849 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
),
9850 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
),
9851 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO
),
9852 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
),
9853 GEN_HANDLER_E(lbarx
, 0x1F, 0x14, 0x01, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
9854 GEN_HANDLER_E(lharx
, 0x1F, 0x14, 0x03, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
9855 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES
),
9856 GEN_HANDLER_E(stbcx_
, 0x1F, 0x16, 0x15, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
9857 GEN_HANDLER_E(sthcx_
, 0x1F, 0x16, 0x16, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
9858 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
),
9859 #if defined(TARGET_PPC64)
9860 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B
),
9861 GEN_HANDLER_E(lqarx
, 0x1F, 0x14, 0x08, 0, PPC_NONE
, PPC2_LSQ_ISA207
),
9862 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
),
9863 GEN_HANDLER_E(stqcx_
, 0x1F, 0x16, 0x05, 0, PPC_NONE
, PPC2_LSQ_ISA207
),
9865 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
),
9866 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
),
9867 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
9868 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
9869 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
),
9870 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
),
9871 GEN_HANDLER_E(bctar
, 0x13, 0x10, 0x11, 0, PPC_NONE
, PPC2_BCTAR_ISA207
),
9872 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
),
9873 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
),
9874 #if defined(TARGET_PPC64)
9875 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
),
9876 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
),
9878 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW
),
9879 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
),
9880 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
9881 #if defined(TARGET_PPC64)
9882 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
),
9883 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
),
9885 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
),
9886 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
),
9887 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
),
9888 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
),
9889 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
),
9890 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
),
9891 #if defined(TARGET_PPC64)
9892 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
),
9894 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC
),
9895 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000000, PPC_MISC
),
9896 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
),
9897 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
),
9898 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
),
9899 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE
),
9900 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE
),
9901 GEN_HANDLER_E(dcbtls
, 0x1F, 0x06, 0x05, 0x02000001, PPC_BOOKE
, PPC2_BOOKE206
),
9902 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ
),
9903 GEN_HANDLER(dst
, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC
),
9904 GEN_HANDLER(dstst
, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC
),
9905 GEN_HANDLER(dss
, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC
),
9906 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
),
9907 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
),
9908 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
),
9909 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
),
9910 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
),
9911 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
),
9912 #if defined(TARGET_PPC64)
9913 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
),
9914 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
9916 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
),
9917 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
9919 GEN_HANDLER2(slbmte
, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B
),
9920 GEN_HANDLER2(slbmfee
, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B
),
9921 GEN_HANDLER2(slbmfev
, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B
),
9923 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
),
9924 GEN_HANDLER(tlbiel
, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE
),
9925 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE
),
9926 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
),
9927 #if defined(TARGET_PPC64)
9928 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI
),
9929 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
),
9931 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
),
9932 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
),
9933 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
),
9934 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
),
9935 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
),
9936 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
),
9937 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
),
9938 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
),
9939 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
),
9940 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
),
9941 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
),
9942 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
9943 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
),
9944 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
),
9945 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
),
9946 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
),
9947 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
),
9948 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
),
9949 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
),
9950 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
9951 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
),
9952 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
),
9953 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
),
9954 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
),
9955 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
),
9956 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
),
9957 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
),
9958 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
),
9959 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
),
9960 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
),
9961 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
),
9962 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
),
9963 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
),
9964 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
),
9965 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
),
9966 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
),
9967 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
),
9968 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
),
9969 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
),
9970 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
),
9971 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
),
9972 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
),
9973 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
),
9974 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
),
9975 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
),
9976 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
),
9977 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
),
9978 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
),
9979 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
),
9980 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
9981 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
9982 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
),
9983 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
),
9984 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
9985 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
9986 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
),
9987 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
),
9988 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
),
9989 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
),
9990 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
),
9991 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
),
9992 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
),
9993 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
),
9994 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
),
9995 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
),
9996 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
),
9997 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
),
9998 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
),
9999 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
),
10000 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
),
10001 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
),
10002 GEN_HANDLER_E(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
, PPC2_BOOKE206
),
10003 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
),
10004 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
),
10005 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
),
10006 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
),
10007 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
),
10008 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
),
10009 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
),
10010 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
),
10011 GEN_HANDLER2_E(tlbre_booke206
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
10012 PPC_NONE
, PPC2_BOOKE206
),
10013 GEN_HANDLER2_E(tlbsx_booke206
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
10014 PPC_NONE
, PPC2_BOOKE206
),
10015 GEN_HANDLER2_E(tlbwe_booke206
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
10016 PPC_NONE
, PPC2_BOOKE206
),
10017 GEN_HANDLER2_E(tlbivax_booke206
, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
10018 PPC_NONE
, PPC2_BOOKE206
),
10019 GEN_HANDLER2_E(tlbilx_booke206
, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
10020 PPC_NONE
, PPC2_BOOKE206
),
10021 GEN_HANDLER2_E(msgsnd
, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
10022 PPC_NONE
, PPC2_PRCNTL
),
10023 GEN_HANDLER2_E(msgclr
, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
10024 PPC_NONE
, PPC2_PRCNTL
),
10025 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
),
10026 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE
),
10027 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
),
10028 GEN_HANDLER_E(mbar
, 0x1F, 0x16, 0x1a, 0x001FF801,
10029 PPC_BOOKE
, PPC2_BOOKE206
),
10030 GEN_HANDLER(msync_4xx
, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE
),
10031 GEN_HANDLER2_E(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
10032 PPC_BOOKE
, PPC2_BOOKE206
),
10033 GEN_HANDLER(lvsl
, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC
),
10034 GEN_HANDLER(lvsr
, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC
),
10035 GEN_HANDLER(mfvscr
, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC
),
10036 GEN_HANDLER(mtvscr
, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC
),
10037 GEN_HANDLER(vmladduhm
, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC
),
10038 GEN_HANDLER2(evsel0
, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE
),
10039 GEN_HANDLER2(evsel1
, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE
),
10040 GEN_HANDLER2(evsel2
, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE
),
10041 GEN_HANDLER2(evsel3
, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE
),
10043 #undef GEN_INT_ARITH_ADD
10044 #undef GEN_INT_ARITH_ADD_CONST
10045 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
10046 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
10047 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
10048 add_ca, compute_ca, compute_ov) \
10049 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
10050 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
10051 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
10052 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
10053 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
10054 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
10055 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
10056 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
10057 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
10058 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
10059 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
10061 #undef GEN_INT_ARITH_DIVW
10062 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
10063 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
10064 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0),
10065 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1),
10066 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0),
10067 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1),
10068 GEN_HANDLER_E(divwe
, 0x1F, 0x0B, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
10069 GEN_HANDLER_E(divweo
, 0x1F, 0x0B, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
10070 GEN_HANDLER_E(divweu
, 0x1F, 0x0B, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
10071 GEN_HANDLER_E(divweuo
, 0x1F, 0x0B, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
10073 #if defined(TARGET_PPC64)
10074 #undef GEN_INT_ARITH_DIVD
10075 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
10076 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
10077 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0),
10078 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1),
10079 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0),
10080 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1),
10082 GEN_HANDLER_E(divdeu
, 0x1F, 0x09, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
10083 GEN_HANDLER_E(divdeuo
, 0x1F, 0x09, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
10084 GEN_HANDLER_E(divde
, 0x1F, 0x09, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
10085 GEN_HANDLER_E(divdeo
, 0x1F, 0x09, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
10087 #undef GEN_INT_ARITH_MUL_HELPER
10088 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
10089 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
10090 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00),
10091 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02),
10092 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17),
10095 #undef GEN_INT_ARITH_SUBF
10096 #undef GEN_INT_ARITH_SUBF_CONST
10097 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
10098 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
10099 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
10100 add_ca, compute_ca, compute_ov) \
10101 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
10102 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
10103 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
10104 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
10105 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
10106 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
10107 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
10108 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
10109 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
10110 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
10111 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
10113 #undef GEN_LOGICAL1
10114 #undef GEN_LOGICAL2
10115 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
10116 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
10117 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
10118 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
10119 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
),
10120 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
),
10121 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
),
10122 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
),
10123 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
),
10124 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
),
10125 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
),
10126 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
),
10127 #if defined(TARGET_PPC64)
10128 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
),
10131 #if defined(TARGET_PPC64)
10132 #undef GEN_PPC64_R2
10133 #undef GEN_PPC64_R4
10134 #define GEN_PPC64_R2(name, opc1, opc2) \
10135 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10136 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10138 #define GEN_PPC64_R4(name, opc1, opc2) \
10139 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10140 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
10142 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10144 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
10146 GEN_PPC64_R4(rldicl
, 0x1E, 0x00),
10147 GEN_PPC64_R4(rldicr
, 0x1E, 0x02),
10148 GEN_PPC64_R4(rldic
, 0x1E, 0x04),
10149 GEN_PPC64_R2(rldcl
, 0x1E, 0x08),
10150 GEN_PPC64_R2(rldcr
, 0x1E, 0x09),
10151 GEN_PPC64_R4(rldimi
, 0x1E, 0x06),
10154 #undef _GEN_FLOAT_ACB
10155 #undef GEN_FLOAT_ACB
10156 #undef _GEN_FLOAT_AB
10157 #undef GEN_FLOAT_AB
10158 #undef _GEN_FLOAT_AC
10159 #undef GEN_FLOAT_AC
10161 #undef GEN_FLOAT_BS
10162 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
10163 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
10164 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
10165 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
10166 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
10167 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10168 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10169 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
10170 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10171 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10172 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10173 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10174 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
10175 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10176 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10177 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
10178 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
10179 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
10180 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
10182 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
),
10183 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
),
10184 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
),
10185 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
),
10186 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
),
10187 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
),
10188 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
),
10189 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
),
10190 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
),
10191 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
),
10192 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
),
10193 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
),
10194 GEN_HANDLER_E(ftdiv
, 0x3F, 0x00, 0x04, 1, PPC_NONE
, PPC2_FP_TST_ISA206
),
10195 GEN_HANDLER_E(ftsqrt
, 0x3F, 0x00, 0x05, 1, PPC_NONE
, PPC2_FP_TST_ISA206
),
10196 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
),
10197 GEN_HANDLER_E(fctiwu
, 0x3F, 0x0E, 0x04, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10198 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
),
10199 GEN_HANDLER_E(fctiwuz
, 0x3F, 0x0F, 0x04, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10200 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
),
10201 GEN_HANDLER_E(fcfid
, 0x3F, 0x0E, 0x1A, 0x001F0000, PPC_NONE
, PPC2_FP_CVT_S64
),
10202 GEN_HANDLER_E(fcfids
, 0x3B, 0x0E, 0x1A, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10203 GEN_HANDLER_E(fcfidu
, 0x3F, 0x0E, 0x1E, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10204 GEN_HANDLER_E(fcfidus
, 0x3B, 0x0E, 0x1E, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10205 GEN_HANDLER_E(fctid
, 0x3F, 0x0E, 0x19, 0x001F0000, PPC_NONE
, PPC2_FP_CVT_S64
),
10206 GEN_HANDLER_E(fctidu
, 0x3F, 0x0E, 0x1D, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10207 GEN_HANDLER_E(fctidz
, 0x3F, 0x0F, 0x19, 0x001F0000, PPC_NONE
, PPC2_FP_CVT_S64
),
10208 GEN_HANDLER_E(fctiduz
, 0x3F, 0x0F, 0x1D, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10209 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
),
10210 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
),
10211 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
),
10212 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
),
10219 #define GEN_LD(name, ldop, opc, type) \
10220 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10221 #define GEN_LDU(name, ldop, opc, type) \
10222 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10223 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
10224 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
10225 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
10226 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
10227 #define GEN_LDS(name, ldop, op, type) \
10228 GEN_LD(name, ldop, op | 0x20, type) \
10229 GEN_LDU(name, ldop, op | 0x21, type) \
10230 GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
10231 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
10233 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
)
10234 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
)
10235 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
)
10236 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
)
10237 #if defined(TARGET_PPC64)
10238 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
)
10239 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
)
10240 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
)
10241 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
)
10242 GEN_LDX_E(ldbr
, ld64ur
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
)
10244 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
)
10245 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
)
10252 #define GEN_ST(name, stop, opc, type) \
10253 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10254 #define GEN_STU(name, stop, opc, type) \
10255 GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
10256 #define GEN_STUX(name, stop, opc2, opc3, type) \
10257 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
10258 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
10259 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
10260 #define GEN_STS(name, stop, op, type) \
10261 GEN_ST(name, stop, op | 0x20, type) \
10262 GEN_STU(name, stop, op | 0x21, type) \
10263 GEN_STUX(name, stop, 0x17, op | 0x01, type) \
10264 GEN_STX(name, stop, 0x17, op | 0x00, type)
10266 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
)
10267 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
)
10268 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
)
10269 #if defined(TARGET_PPC64)
10270 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
)
10271 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
)
10272 GEN_STX_E(stdbr
, st64r
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
)
10274 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
)
10275 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
)
10282 #define GEN_LDF(name, ldop, opc, type) \
10283 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10284 #define GEN_LDUF(name, ldop, opc, type) \
10285 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10286 #define GEN_LDUXF(name, ldop, opc, type) \
10287 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10288 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
10289 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10290 #define GEN_LDFS(name, ldop, op, type) \
10291 GEN_LDF(name, ldop, op | 0x20, type) \
10292 GEN_LDUF(name, ldop, op | 0x21, type) \
10293 GEN_LDUXF(name, ldop, op | 0x01, type) \
10294 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
10296 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
)
10297 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
)
10298 GEN_HANDLER_E(lfiwax
, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE
, PPC2_ISA205
),
10299 GEN_HANDLER_E(lfiwzx
, 0x1f, 0x17, 0x1b, 0x1, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10300 GEN_HANDLER_E(lfdp
, 0x39, 0xFF, 0xFF, 0x00200003, PPC_NONE
, PPC2_ISA205
),
10301 GEN_HANDLER_E(lfdpx
, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE
, PPC2_ISA205
),
10308 #define GEN_STF(name, stop, opc, type) \
10309 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10310 #define GEN_STUF(name, stop, opc, type) \
10311 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10312 #define GEN_STUXF(name, stop, opc, type) \
10313 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10314 #define GEN_STXF(name, stop, opc2, opc3, type) \
10315 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10316 #define GEN_STFS(name, stop, op, type) \
10317 GEN_STF(name, stop, op | 0x20, type) \
10318 GEN_STUF(name, stop, op | 0x21, type) \
10319 GEN_STUXF(name, stop, op | 0x01, type) \
10320 GEN_STXF(name, stop, 0x17, op | 0x00, type)
10322 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
)
10323 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
)
10324 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
)
10325 GEN_HANDLER_E(stfdp
, 0x3D, 0xFF, 0xFF, 0x00200003, PPC_NONE
, PPC2_ISA205
),
10326 GEN_HANDLER_E(stfdpx
, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE
, PPC2_ISA205
),
10329 #define GEN_CRLOGIC(name, tcg_op, opc) \
10330 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
10331 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08),
10332 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04),
10333 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09),
10334 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07),
10335 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01),
10336 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E),
10337 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D),
10338 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06),
10340 #undef GEN_MAC_HANDLER
10341 #define GEN_MAC_HANDLER(name, opc2, opc3) \
10342 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
10343 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05),
10344 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15),
10345 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07),
10346 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17),
10347 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06),
10348 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16),
10349 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04),
10350 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14),
10351 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01),
10352 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11),
10353 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03),
10354 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13),
10355 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02),
10356 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12),
10357 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00),
10358 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10),
10359 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D),
10360 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D),
10361 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F),
10362 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F),
10363 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C),
10364 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C),
10365 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E),
10366 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E),
10367 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05),
10368 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15),
10369 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07),
10370 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17),
10371 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01),
10372 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11),
10373 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03),
10374 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13),
10375 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D),
10376 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D),
10377 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F),
10378 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F),
10379 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05),
10380 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04),
10381 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01),
10382 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00),
10383 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D),
10384 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C),
10390 #define GEN_VR_LDX(name, opc2, opc3) \
10391 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10392 #define GEN_VR_STX(name, opc2, opc3) \
10393 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10394 #define GEN_VR_LVE(name, opc2, opc3) \
10395 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10396 #define GEN_VR_STVE(name, opc2, opc3) \
10397 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10398 GEN_VR_LDX(lvx
, 0x07, 0x03),
10399 GEN_VR_LDX(lvxl
, 0x07, 0x0B),
10400 GEN_VR_LVE(bx
, 0x07, 0x00),
10401 GEN_VR_LVE(hx
, 0x07, 0x01),
10402 GEN_VR_LVE(wx
, 0x07, 0x02),
10403 GEN_VR_STX(svx
, 0x07, 0x07),
10404 GEN_VR_STX(svxl
, 0x07, 0x0F),
10405 GEN_VR_STVE(bx
, 0x07, 0x04),
10406 GEN_VR_STVE(hx
, 0x07, 0x05),
10407 GEN_VR_STVE(wx
, 0x07, 0x06),
10409 #undef GEN_VX_LOGICAL
10410 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
10411 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10413 #undef GEN_VX_LOGICAL_207
10414 #define GEN_VX_LOGICAL_207(name, tcg_op, opc2, opc3) \
10415 GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10417 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16),
10418 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17),
10419 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18),
10420 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19),
10421 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20),
10422 GEN_VX_LOGICAL_207(veqv
, tcg_gen_eqv_i64
, 2, 26),
10423 GEN_VX_LOGICAL_207(vnand
, tcg_gen_nand_i64
, 2, 22),
10424 GEN_VX_LOGICAL_207(vorc
, tcg_gen_orc_i64
, 2, 21),
10427 #define GEN_VXFORM(name, opc2, opc3) \
10428 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10430 #undef GEN_VXFORM_207
10431 #define GEN_VXFORM_207(name, opc2, opc3) \
10432 GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10434 #undef GEN_VXFORM_DUAL
10435 #define GEN_VXFORM_DUAL(name0, name1, opc2, opc3, type0, type1) \
10436 GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, type0, type1)
10438 #undef GEN_VXRFORM_DUAL
10439 #define GEN_VXRFORM_DUAL(name0, name1, opc2, opc3, tp0, tp1) \
10440 GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, tp0, tp1), \
10441 GEN_HANDLER_E(name0##_##name1, 0x4, opc2, (opc3 | 0x10), 0x00000000, tp0, tp1),
10443 GEN_VXFORM(vaddubm
, 0, 0),
10444 GEN_VXFORM(vadduhm
, 0, 1),
10445 GEN_VXFORM(vadduwm
, 0, 2),
10446 GEN_VXFORM_207(vaddudm
, 0, 3),
10447 GEN_VXFORM_DUAL(vsububm
, bcdadd
, 0, 16, PPC_ALTIVEC
, PPC_NONE
),
10448 GEN_VXFORM_DUAL(vsubuhm
, bcdsub
, 0, 17, PPC_ALTIVEC
, PPC_NONE
),
10449 GEN_VXFORM(vsubuwm
, 0, 18),
10450 GEN_VXFORM_207(vsubudm
, 0, 19),
10451 GEN_VXFORM(vmaxub
, 1, 0),
10452 GEN_VXFORM(vmaxuh
, 1, 1),
10453 GEN_VXFORM(vmaxuw
, 1, 2),
10454 GEN_VXFORM_207(vmaxud
, 1, 3),
10455 GEN_VXFORM(vmaxsb
, 1, 4),
10456 GEN_VXFORM(vmaxsh
, 1, 5),
10457 GEN_VXFORM(vmaxsw
, 1, 6),
10458 GEN_VXFORM_207(vmaxsd
, 1, 7),
10459 GEN_VXFORM(vminub
, 1, 8),
10460 GEN_VXFORM(vminuh
, 1, 9),
10461 GEN_VXFORM(vminuw
, 1, 10),
10462 GEN_VXFORM_207(vminud
, 1, 11),
10463 GEN_VXFORM(vminsb
, 1, 12),
10464 GEN_VXFORM(vminsh
, 1, 13),
10465 GEN_VXFORM(vminsw
, 1, 14),
10466 GEN_VXFORM_207(vminsd
, 1, 15),
10467 GEN_VXFORM(vavgub
, 1, 16),
10468 GEN_VXFORM(vavguh
, 1, 17),
10469 GEN_VXFORM(vavguw
, 1, 18),
10470 GEN_VXFORM(vavgsb
, 1, 20),
10471 GEN_VXFORM(vavgsh
, 1, 21),
10472 GEN_VXFORM(vavgsw
, 1, 22),
10473 GEN_VXFORM(vmrghb
, 6, 0),
10474 GEN_VXFORM(vmrghh
, 6, 1),
10475 GEN_VXFORM(vmrghw
, 6, 2),
10476 GEN_VXFORM(vmrglb
, 6, 4),
10477 GEN_VXFORM(vmrglh
, 6, 5),
10478 GEN_VXFORM(vmrglw
, 6, 6),
10479 GEN_VXFORM_207(vmrgew
, 6, 30),
10480 GEN_VXFORM_207(vmrgow
, 6, 26),
10481 GEN_VXFORM(vmuloub
, 4, 0),
10482 GEN_VXFORM(vmulouh
, 4, 1),
10483 GEN_VXFORM_DUAL(vmulouw
, vmuluwm
, 4, 2, PPC_ALTIVEC
, PPC_NONE
),
10484 GEN_VXFORM(vmulosb
, 4, 4),
10485 GEN_VXFORM(vmulosh
, 4, 5),
10486 GEN_VXFORM_207(vmulosw
, 4, 6),
10487 GEN_VXFORM(vmuleub
, 4, 8),
10488 GEN_VXFORM(vmuleuh
, 4, 9),
10489 GEN_VXFORM_207(vmuleuw
, 4, 10),
10490 GEN_VXFORM(vmulesb
, 4, 12),
10491 GEN_VXFORM(vmulesh
, 4, 13),
10492 GEN_VXFORM_207(vmulesw
, 4, 14),
10493 GEN_VXFORM(vslb
, 2, 4),
10494 GEN_VXFORM(vslh
, 2, 5),
10495 GEN_VXFORM(vslw
, 2, 6),
10496 GEN_VXFORM_207(vsld
, 2, 23),
10497 GEN_VXFORM(vsrb
, 2, 8),
10498 GEN_VXFORM(vsrh
, 2, 9),
10499 GEN_VXFORM(vsrw
, 2, 10),
10500 GEN_VXFORM_207(vsrd
, 2, 27),
10501 GEN_VXFORM(vsrab
, 2, 12),
10502 GEN_VXFORM(vsrah
, 2, 13),
10503 GEN_VXFORM(vsraw
, 2, 14),
10504 GEN_VXFORM_207(vsrad
, 2, 15),
10505 GEN_VXFORM(vslo
, 6, 16),
10506 GEN_VXFORM(vsro
, 6, 17),
10507 GEN_VXFORM(vaddcuw
, 0, 6),
10508 GEN_VXFORM(vsubcuw
, 0, 22),
10509 GEN_VXFORM(vaddubs
, 0, 8),
10510 GEN_VXFORM(vadduhs
, 0, 9),
10511 GEN_VXFORM(vadduws
, 0, 10),
10512 GEN_VXFORM(vaddsbs
, 0, 12),
10513 GEN_VXFORM(vaddshs
, 0, 13),
10514 GEN_VXFORM(vaddsws
, 0, 14),
10515 GEN_VXFORM_DUAL(vsububs
, bcdadd
, 0, 24, PPC_ALTIVEC
, PPC_NONE
),
10516 GEN_VXFORM_DUAL(vsubuhs
, bcdsub
, 0, 25, PPC_ALTIVEC
, PPC_NONE
),
10517 GEN_VXFORM(vsubuws
, 0, 26),
10518 GEN_VXFORM(vsubsbs
, 0, 28),
10519 GEN_VXFORM(vsubshs
, 0, 29),
10520 GEN_VXFORM(vsubsws
, 0, 30),
10521 GEN_VXFORM_207(vadduqm
, 0, 4),
10522 GEN_VXFORM_207(vaddcuq
, 0, 5),
10523 GEN_VXFORM_DUAL(vaddeuqm
, vaddecuq
, 30, 0xFF, PPC_NONE
, PPC2_ALTIVEC_207
),
10524 GEN_VXFORM_207(vsubuqm
, 0, 20),
10525 GEN_VXFORM_207(vsubcuq
, 0, 21),
10526 GEN_VXFORM_DUAL(vsubeuqm
, vsubecuq
, 31, 0xFF, PPC_NONE
, PPC2_ALTIVEC_207
),
10527 GEN_VXFORM(vrlb
, 2, 0),
10528 GEN_VXFORM(vrlh
, 2, 1),
10529 GEN_VXFORM(vrlw
, 2, 2),
10530 GEN_VXFORM_207(vrld
, 2, 3),
10531 GEN_VXFORM(vsl
, 2, 7),
10532 GEN_VXFORM(vsr
, 2, 11),
10533 GEN_VXFORM(vpkuhum
, 7, 0),
10534 GEN_VXFORM(vpkuwum
, 7, 1),
10535 GEN_VXFORM_207(vpkudum
, 7, 17),
10536 GEN_VXFORM(vpkuhus
, 7, 2),
10537 GEN_VXFORM(vpkuwus
, 7, 3),
10538 GEN_VXFORM_207(vpkudus
, 7, 19),
10539 GEN_VXFORM(vpkshus
, 7, 4),
10540 GEN_VXFORM(vpkswus
, 7, 5),
10541 GEN_VXFORM_207(vpksdus
, 7, 21),
10542 GEN_VXFORM(vpkshss
, 7, 6),
10543 GEN_VXFORM(vpkswss
, 7, 7),
10544 GEN_VXFORM_207(vpksdss
, 7, 23),
10545 GEN_VXFORM(vpkpx
, 7, 12),
10546 GEN_VXFORM(vsum4ubs
, 4, 24),
10547 GEN_VXFORM(vsum4sbs
, 4, 28),
10548 GEN_VXFORM(vsum4shs
, 4, 25),
10549 GEN_VXFORM(vsum2sws
, 4, 26),
10550 GEN_VXFORM(vsumsws
, 4, 30),
10551 GEN_VXFORM(vaddfp
, 5, 0),
10552 GEN_VXFORM(vsubfp
, 5, 1),
10553 GEN_VXFORM(vmaxfp
, 5, 16),
10554 GEN_VXFORM(vminfp
, 5, 17),
10556 #undef GEN_VXRFORM1
10558 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
10559 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
10560 #define GEN_VXRFORM(name, opc2, opc3) \
10561 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
10562 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
10563 GEN_VXRFORM(vcmpequb
, 3, 0)
10564 GEN_VXRFORM(vcmpequh
, 3, 1)
10565 GEN_VXRFORM(vcmpequw
, 3, 2)
10566 GEN_VXRFORM(vcmpgtsb
, 3, 12)
10567 GEN_VXRFORM(vcmpgtsh
, 3, 13)
10568 GEN_VXRFORM(vcmpgtsw
, 3, 14)
10569 GEN_VXRFORM(vcmpgtub
, 3, 8)
10570 GEN_VXRFORM(vcmpgtuh
, 3, 9)
10571 GEN_VXRFORM(vcmpgtuw
, 3, 10)
10572 GEN_VXRFORM_DUAL(vcmpeqfp
, vcmpequd
, 3, 3, PPC_ALTIVEC
, PPC_NONE
)
10573 GEN_VXRFORM(vcmpgefp
, 3, 7)
10574 GEN_VXRFORM_DUAL(vcmpgtfp
, vcmpgtud
, 3, 11, PPC_ALTIVEC
, PPC_NONE
)
10575 GEN_VXRFORM_DUAL(vcmpbfp
, vcmpgtsd
, 3, 15, PPC_ALTIVEC
, PPC_NONE
)
10577 #undef GEN_VXFORM_SIMM
10578 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
10579 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10580 GEN_VXFORM_SIMM(vspltisb
, 6, 12),
10581 GEN_VXFORM_SIMM(vspltish
, 6, 13),
10582 GEN_VXFORM_SIMM(vspltisw
, 6, 14),
10584 #undef GEN_VXFORM_NOA
10585 #define GEN_VXFORM_NOA(name, opc2, opc3) \
10586 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
10587 GEN_VXFORM_NOA(vupkhsb
, 7, 8),
10588 GEN_VXFORM_NOA(vupkhsh
, 7, 9),
10589 GEN_VXFORM_207(vupkhsw
, 7, 25),
10590 GEN_VXFORM_NOA(vupklsb
, 7, 10),
10591 GEN_VXFORM_NOA(vupklsh
, 7, 11),
10592 GEN_VXFORM_207(vupklsw
, 7, 27),
10593 GEN_VXFORM_NOA(vupkhpx
, 7, 13),
10594 GEN_VXFORM_NOA(vupklpx
, 7, 15),
10595 GEN_VXFORM_NOA(vrefp
, 5, 4),
10596 GEN_VXFORM_NOA(vrsqrtefp
, 5, 5),
10597 GEN_VXFORM_NOA(vexptefp
, 5, 6),
10598 GEN_VXFORM_NOA(vlogefp
, 5, 7),
10599 GEN_VXFORM_NOA(vrfim
, 5, 11),
10600 GEN_VXFORM_NOA(vrfin
, 5, 8),
10601 GEN_VXFORM_NOA(vrfip
, 5, 10),
10602 GEN_VXFORM_NOA(vrfiz
, 5, 9),
10604 #undef GEN_VXFORM_UIMM
10605 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
10606 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10607 GEN_VXFORM_UIMM(vspltb
, 6, 8),
10608 GEN_VXFORM_UIMM(vsplth
, 6, 9),
10609 GEN_VXFORM_UIMM(vspltw
, 6, 10),
10610 GEN_VXFORM_UIMM(vcfux
, 5, 12),
10611 GEN_VXFORM_UIMM(vcfsx
, 5, 13),
10612 GEN_VXFORM_UIMM(vctuxs
, 5, 14),
10613 GEN_VXFORM_UIMM(vctsxs
, 5, 15),
10615 #undef GEN_VAFORM_PAIRED
10616 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
10617 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
10618 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16),
10619 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18),
10620 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19),
10621 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20),
10622 GEN_VAFORM_PAIRED(vsel
, vperm
, 21),
10623 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23),
10625 GEN_VXFORM_DUAL(vclzb
, vpopcntb
, 1, 28, PPC_NONE
, PPC2_ALTIVEC_207
),
10626 GEN_VXFORM_DUAL(vclzh
, vpopcnth
, 1, 29, PPC_NONE
, PPC2_ALTIVEC_207
),
10627 GEN_VXFORM_DUAL(vclzw
, vpopcntw
, 1, 30, PPC_NONE
, PPC2_ALTIVEC_207
),
10628 GEN_VXFORM_DUAL(vclzd
, vpopcntd
, 1, 31, PPC_NONE
, PPC2_ALTIVEC_207
),
10630 GEN_VXFORM_207(vbpermq
, 6, 21),
10631 GEN_VXFORM_207(vgbbd
, 6, 20),
10632 GEN_VXFORM_207(vpmsumb
, 4, 16),
10633 GEN_VXFORM_207(vpmsumh
, 4, 17),
10634 GEN_VXFORM_207(vpmsumw
, 4, 18),
10635 GEN_VXFORM_207(vpmsumd
, 4, 19),
10637 GEN_VXFORM_207(vsbox
, 4, 23),
10639 GEN_VXFORM_DUAL(vcipher
, vcipherlast
, 4, 20, PPC_NONE
, PPC2_ALTIVEC_207
),
10640 GEN_VXFORM_DUAL(vncipher
, vncipherlast
, 4, 21, PPC_NONE
, PPC2_ALTIVEC_207
),
10642 GEN_VXFORM_207(vshasigmaw
, 1, 26),
10643 GEN_VXFORM_207(vshasigmad
, 1, 27),
10645 GEN_VXFORM_DUAL(vsldoi
, vpermxor
, 22, 0xFF, PPC_ALTIVEC
, PPC_NONE
),
10647 GEN_HANDLER_E(lxsdx
, 0x1F, 0x0C, 0x12, 0, PPC_NONE
, PPC2_VSX
),
10648 GEN_HANDLER_E(lxsiwax
, 0x1F, 0x0C, 0x02, 0, PPC_NONE
, PPC2_VSX207
),
10649 GEN_HANDLER_E(lxsiwzx
, 0x1F, 0x0C, 0x00, 0, PPC_NONE
, PPC2_VSX207
),
10650 GEN_HANDLER_E(lxsspx
, 0x1F, 0x0C, 0x10, 0, PPC_NONE
, PPC2_VSX207
),
10651 GEN_HANDLER_E(lxvd2x
, 0x1F, 0x0C, 0x1A, 0, PPC_NONE
, PPC2_VSX
),
10652 GEN_HANDLER_E(lxvdsx
, 0x1F, 0x0C, 0x0A, 0, PPC_NONE
, PPC2_VSX
),
10653 GEN_HANDLER_E(lxvw4x
, 0x1F, 0x0C, 0x18, 0, PPC_NONE
, PPC2_VSX
),
10655 GEN_HANDLER_E(stxsdx
, 0x1F, 0xC, 0x16, 0, PPC_NONE
, PPC2_VSX
),
10656 GEN_HANDLER_E(stxsiwx
, 0x1F, 0xC, 0x04, 0, PPC_NONE
, PPC2_VSX207
),
10657 GEN_HANDLER_E(stxsspx
, 0x1F, 0xC, 0x14, 0, PPC_NONE
, PPC2_VSX207
),
10658 GEN_HANDLER_E(stxvd2x
, 0x1F, 0xC, 0x1E, 0, PPC_NONE
, PPC2_VSX
),
10659 GEN_HANDLER_E(stxvw4x
, 0x1F, 0xC, 0x1C, 0, PPC_NONE
, PPC2_VSX
),
10661 GEN_HANDLER_E(mfvsrwz
, 0x1F, 0x13, 0x03, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
10662 GEN_HANDLER_E(mtvsrwa
, 0x1F, 0x13, 0x06, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
10663 GEN_HANDLER_E(mtvsrwz
, 0x1F, 0x13, 0x07, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
10664 #if defined(TARGET_PPC64)
10665 GEN_HANDLER_E(mfvsrd
, 0x1F, 0x13, 0x01, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
10666 GEN_HANDLER_E(mtvsrd
, 0x1F, 0x13, 0x05, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
10670 #define GEN_XX2FORM(name, opc2, opc3, fl2) \
10671 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10672 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2)
10675 #define GEN_XX3FORM(name, opc2, opc3, fl2) \
10676 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10677 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2), \
10678 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 0, PPC_NONE, fl2), \
10679 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 0, PPC_NONE, fl2)
10681 #undef GEN_XX2IFORM
10682 #define GEN_XX2IFORM(name, opc2, opc3, fl2) \
10683 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 1, PPC_NONE, fl2), \
10684 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 1, PPC_NONE, fl2), \
10685 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 1, PPC_NONE, fl2), \
10686 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 1, PPC_NONE, fl2)
10688 #undef GEN_XX3_RC_FORM
10689 #define GEN_XX3_RC_FORM(name, opc2, opc3, fl2) \
10690 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x00, 0, PPC_NONE, fl2), \
10691 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x00, 0, PPC_NONE, fl2), \
10692 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x00, 0, PPC_NONE, fl2), \
10693 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x00, 0, PPC_NONE, fl2), \
10694 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x10, 0, PPC_NONE, fl2), \
10695 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x10, 0, PPC_NONE, fl2), \
10696 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x10, 0, PPC_NONE, fl2), \
10697 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x10, 0, PPC_NONE, fl2)
10699 #undef GEN_XX3FORM_DM
10700 #define GEN_XX3FORM_DM(name, opc2, opc3) \
10701 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10702 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10703 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10704 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10705 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10706 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10707 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10708 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10709 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10710 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10711 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10712 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10713 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10714 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10715 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10716 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x0C, 0, PPC_NONE, PPC2_VSX)
10718 GEN_XX2FORM(xsabsdp
, 0x12, 0x15, PPC2_VSX
),
10719 GEN_XX2FORM(xsnabsdp
, 0x12, 0x16, PPC2_VSX
),
10720 GEN_XX2FORM(xsnegdp
, 0x12, 0x17, PPC2_VSX
),
10721 GEN_XX3FORM(xscpsgndp
, 0x00, 0x16, PPC2_VSX
),
10723 GEN_XX2FORM(xvabsdp
, 0x12, 0x1D, PPC2_VSX
),
10724 GEN_XX2FORM(xvnabsdp
, 0x12, 0x1E, PPC2_VSX
),
10725 GEN_XX2FORM(xvnegdp
, 0x12, 0x1F, PPC2_VSX
),
10726 GEN_XX3FORM(xvcpsgndp
, 0x00, 0x1E, PPC2_VSX
),
10727 GEN_XX2FORM(xvabssp
, 0x12, 0x19, PPC2_VSX
),
10728 GEN_XX2FORM(xvnabssp
, 0x12, 0x1A, PPC2_VSX
),
10729 GEN_XX2FORM(xvnegsp
, 0x12, 0x1B, PPC2_VSX
),
10730 GEN_XX3FORM(xvcpsgnsp
, 0x00, 0x1A, PPC2_VSX
),
10732 GEN_XX3FORM(xsadddp
, 0x00, 0x04, PPC2_VSX
),
10733 GEN_XX3FORM(xssubdp
, 0x00, 0x05, PPC2_VSX
),
10734 GEN_XX3FORM(xsmuldp
, 0x00, 0x06, PPC2_VSX
),
10735 GEN_XX3FORM(xsdivdp
, 0x00, 0x07, PPC2_VSX
),
10736 GEN_XX2FORM(xsredp
, 0x14, 0x05, PPC2_VSX
),
10737 GEN_XX2FORM(xssqrtdp
, 0x16, 0x04, PPC2_VSX
),
10738 GEN_XX2FORM(xsrsqrtedp
, 0x14, 0x04, PPC2_VSX
),
10739 GEN_XX3FORM(xstdivdp
, 0x14, 0x07, PPC2_VSX
),
10740 GEN_XX2FORM(xstsqrtdp
, 0x14, 0x06, PPC2_VSX
),
10741 GEN_XX3FORM(xsmaddadp
, 0x04, 0x04, PPC2_VSX
),
10742 GEN_XX3FORM(xsmaddmdp
, 0x04, 0x05, PPC2_VSX
),
10743 GEN_XX3FORM(xsmsubadp
, 0x04, 0x06, PPC2_VSX
),
10744 GEN_XX3FORM(xsmsubmdp
, 0x04, 0x07, PPC2_VSX
),
10745 GEN_XX3FORM(xsnmaddadp
, 0x04, 0x14, PPC2_VSX
),
10746 GEN_XX3FORM(xsnmaddmdp
, 0x04, 0x15, PPC2_VSX
),
10747 GEN_XX3FORM(xsnmsubadp
, 0x04, 0x16, PPC2_VSX
),
10748 GEN_XX3FORM(xsnmsubmdp
, 0x04, 0x17, PPC2_VSX
),
10749 GEN_XX2IFORM(xscmpodp
, 0x0C, 0x05, PPC2_VSX
),
10750 GEN_XX2IFORM(xscmpudp
, 0x0C, 0x04, PPC2_VSX
),
10751 GEN_XX3FORM(xsmaxdp
, 0x00, 0x14, PPC2_VSX
),
10752 GEN_XX3FORM(xsmindp
, 0x00, 0x15, PPC2_VSX
),
10753 GEN_XX2FORM(xscvdpsp
, 0x12, 0x10, PPC2_VSX
),
10754 GEN_XX2FORM(xscvdpspn
, 0x16, 0x10, PPC2_VSX207
),
10755 GEN_XX2FORM(xscvspdp
, 0x12, 0x14, PPC2_VSX
),
10756 GEN_XX2FORM(xscvspdpn
, 0x16, 0x14, PPC2_VSX207
),
10757 GEN_XX2FORM(xscvdpsxds
, 0x10, 0x15, PPC2_VSX
),
10758 GEN_XX2FORM(xscvdpsxws
, 0x10, 0x05, PPC2_VSX
),
10759 GEN_XX2FORM(xscvdpuxds
, 0x10, 0x14, PPC2_VSX
),
10760 GEN_XX2FORM(xscvdpuxws
, 0x10, 0x04, PPC2_VSX
),
10761 GEN_XX2FORM(xscvsxddp
, 0x10, 0x17, PPC2_VSX
),
10762 GEN_XX2FORM(xscvuxddp
, 0x10, 0x16, PPC2_VSX
),
10763 GEN_XX2FORM(xsrdpi
, 0x12, 0x04, PPC2_VSX
),
10764 GEN_XX2FORM(xsrdpic
, 0x16, 0x06, PPC2_VSX
),
10765 GEN_XX2FORM(xsrdpim
, 0x12, 0x07, PPC2_VSX
),
10766 GEN_XX2FORM(xsrdpip
, 0x12, 0x06, PPC2_VSX
),
10767 GEN_XX2FORM(xsrdpiz
, 0x12, 0x05, PPC2_VSX
),
10769 GEN_XX3FORM(xsaddsp
, 0x00, 0x00, PPC2_VSX207
),
10770 GEN_XX3FORM(xssubsp
, 0x00, 0x01, PPC2_VSX207
),
10771 GEN_XX3FORM(xsmulsp
, 0x00, 0x02, PPC2_VSX207
),
10772 GEN_XX3FORM(xsdivsp
, 0x00, 0x03, PPC2_VSX207
),
10773 GEN_XX2FORM(xsresp
, 0x14, 0x01, PPC2_VSX207
),
10774 GEN_XX2FORM(xsrsp
, 0x12, 0x11, PPC2_VSX207
),
10775 GEN_XX2FORM(xssqrtsp
, 0x16, 0x00, PPC2_VSX207
),
10776 GEN_XX2FORM(xsrsqrtesp
, 0x14, 0x00, PPC2_VSX207
),
10777 GEN_XX3FORM(xsmaddasp
, 0x04, 0x00, PPC2_VSX207
),
10778 GEN_XX3FORM(xsmaddmsp
, 0x04, 0x01, PPC2_VSX207
),
10779 GEN_XX3FORM(xsmsubasp
, 0x04, 0x02, PPC2_VSX207
),
10780 GEN_XX3FORM(xsmsubmsp
, 0x04, 0x03, PPC2_VSX207
),
10781 GEN_XX3FORM(xsnmaddasp
, 0x04, 0x10, PPC2_VSX207
),
10782 GEN_XX3FORM(xsnmaddmsp
, 0x04, 0x11, PPC2_VSX207
),
10783 GEN_XX3FORM(xsnmsubasp
, 0x04, 0x12, PPC2_VSX207
),
10784 GEN_XX3FORM(xsnmsubmsp
, 0x04, 0x13, PPC2_VSX207
),
10785 GEN_XX2FORM(xscvsxdsp
, 0x10, 0x13, PPC2_VSX207
),
10786 GEN_XX2FORM(xscvuxdsp
, 0x10, 0x12, PPC2_VSX207
),
10788 GEN_XX3FORM(xvadddp
, 0x00, 0x0C, PPC2_VSX
),
10789 GEN_XX3FORM(xvsubdp
, 0x00, 0x0D, PPC2_VSX
),
10790 GEN_XX3FORM(xvmuldp
, 0x00, 0x0E, PPC2_VSX
),
10791 GEN_XX3FORM(xvdivdp
, 0x00, 0x0F, PPC2_VSX
),
10792 GEN_XX2FORM(xvredp
, 0x14, 0x0D, PPC2_VSX
),
10793 GEN_XX2FORM(xvsqrtdp
, 0x16, 0x0C, PPC2_VSX
),
10794 GEN_XX2FORM(xvrsqrtedp
, 0x14, 0x0C, PPC2_VSX
),
10795 GEN_XX3FORM(xvtdivdp
, 0x14, 0x0F, PPC2_VSX
),
10796 GEN_XX2FORM(xvtsqrtdp
, 0x14, 0x0E, PPC2_VSX
),
10797 GEN_XX3FORM(xvmaddadp
, 0x04, 0x0C, PPC2_VSX
),
10798 GEN_XX3FORM(xvmaddmdp
, 0x04, 0x0D, PPC2_VSX
),
10799 GEN_XX3FORM(xvmsubadp
, 0x04, 0x0E, PPC2_VSX
),
10800 GEN_XX3FORM(xvmsubmdp
, 0x04, 0x0F, PPC2_VSX
),
10801 GEN_XX3FORM(xvnmaddadp
, 0x04, 0x1C, PPC2_VSX
),
10802 GEN_XX3FORM(xvnmaddmdp
, 0x04, 0x1D, PPC2_VSX
),
10803 GEN_XX3FORM(xvnmsubadp
, 0x04, 0x1E, PPC2_VSX
),
10804 GEN_XX3FORM(xvnmsubmdp
, 0x04, 0x1F, PPC2_VSX
),
10805 GEN_XX3FORM(xvmaxdp
, 0x00, 0x1C, PPC2_VSX
),
10806 GEN_XX3FORM(xvmindp
, 0x00, 0x1D, PPC2_VSX
),
10807 GEN_XX3_RC_FORM(xvcmpeqdp
, 0x0C, 0x0C, PPC2_VSX
),
10808 GEN_XX3_RC_FORM(xvcmpgtdp
, 0x0C, 0x0D, PPC2_VSX
),
10809 GEN_XX3_RC_FORM(xvcmpgedp
, 0x0C, 0x0E, PPC2_VSX
),
10810 GEN_XX2FORM(xvcvdpsp
, 0x12, 0x18, PPC2_VSX
),
10811 GEN_XX2FORM(xvcvdpsxds
, 0x10, 0x1D, PPC2_VSX
),
10812 GEN_XX2FORM(xvcvdpsxws
, 0x10, 0x0D, PPC2_VSX
),
10813 GEN_XX2FORM(xvcvdpuxds
, 0x10, 0x1C, PPC2_VSX
),
10814 GEN_XX2FORM(xvcvdpuxws
, 0x10, 0x0C, PPC2_VSX
),
10815 GEN_XX2FORM(xvcvsxddp
, 0x10, 0x1F, PPC2_VSX
),
10816 GEN_XX2FORM(xvcvuxddp
, 0x10, 0x1E, PPC2_VSX
),
10817 GEN_XX2FORM(xvcvsxwdp
, 0x10, 0x0F, PPC2_VSX
),
10818 GEN_XX2FORM(xvcvuxwdp
, 0x10, 0x0E, PPC2_VSX
),
10819 GEN_XX2FORM(xvrdpi
, 0x12, 0x0C, PPC2_VSX
),
10820 GEN_XX2FORM(xvrdpic
, 0x16, 0x0E, PPC2_VSX
),
10821 GEN_XX2FORM(xvrdpim
, 0x12, 0x0F, PPC2_VSX
),
10822 GEN_XX2FORM(xvrdpip
, 0x12, 0x0E, PPC2_VSX
),
10823 GEN_XX2FORM(xvrdpiz
, 0x12, 0x0D, PPC2_VSX
),
10825 GEN_XX3FORM(xvaddsp
, 0x00, 0x08, PPC2_VSX
),
10826 GEN_XX3FORM(xvsubsp
, 0x00, 0x09, PPC2_VSX
),
10827 GEN_XX3FORM(xvmulsp
, 0x00, 0x0A, PPC2_VSX
),
10828 GEN_XX3FORM(xvdivsp
, 0x00, 0x0B, PPC2_VSX
),
10829 GEN_XX2FORM(xvresp
, 0x14, 0x09, PPC2_VSX
),
10830 GEN_XX2FORM(xvsqrtsp
, 0x16, 0x08, PPC2_VSX
),
10831 GEN_XX2FORM(xvrsqrtesp
, 0x14, 0x08, PPC2_VSX
),
10832 GEN_XX3FORM(xvtdivsp
, 0x14, 0x0B, PPC2_VSX
),
10833 GEN_XX2FORM(xvtsqrtsp
, 0x14, 0x0A, PPC2_VSX
),
10834 GEN_XX3FORM(xvmaddasp
, 0x04, 0x08, PPC2_VSX
),
10835 GEN_XX3FORM(xvmaddmsp
, 0x04, 0x09, PPC2_VSX
),
10836 GEN_XX3FORM(xvmsubasp
, 0x04, 0x0A, PPC2_VSX
),
10837 GEN_XX3FORM(xvmsubmsp
, 0x04, 0x0B, PPC2_VSX
),
10838 GEN_XX3FORM(xvnmaddasp
, 0x04, 0x18, PPC2_VSX
),
10839 GEN_XX3FORM(xvnmaddmsp
, 0x04, 0x19, PPC2_VSX
),
10840 GEN_XX3FORM(xvnmsubasp
, 0x04, 0x1A, PPC2_VSX
),
10841 GEN_XX3FORM(xvnmsubmsp
, 0x04, 0x1B, PPC2_VSX
),
10842 GEN_XX3FORM(xvmaxsp
, 0x00, 0x18, PPC2_VSX
),
10843 GEN_XX3FORM(xvminsp
, 0x00, 0x19, PPC2_VSX
),
10844 GEN_XX3_RC_FORM(xvcmpeqsp
, 0x0C, 0x08, PPC2_VSX
),
10845 GEN_XX3_RC_FORM(xvcmpgtsp
, 0x0C, 0x09, PPC2_VSX
),
10846 GEN_XX3_RC_FORM(xvcmpgesp
, 0x0C, 0x0A, PPC2_VSX
),
10847 GEN_XX2FORM(xvcvspdp
, 0x12, 0x1C, PPC2_VSX
),
10848 GEN_XX2FORM(xvcvspsxds
, 0x10, 0x19, PPC2_VSX
),
10849 GEN_XX2FORM(xvcvspsxws
, 0x10, 0x09, PPC2_VSX
),
10850 GEN_XX2FORM(xvcvspuxds
, 0x10, 0x18, PPC2_VSX
),
10851 GEN_XX2FORM(xvcvspuxws
, 0x10, 0x08, PPC2_VSX
),
10852 GEN_XX2FORM(xvcvsxdsp
, 0x10, 0x1B, PPC2_VSX
),
10853 GEN_XX2FORM(xvcvuxdsp
, 0x10, 0x1A, PPC2_VSX
),
10854 GEN_XX2FORM(xvcvsxwsp
, 0x10, 0x0B, PPC2_VSX
),
10855 GEN_XX2FORM(xvcvuxwsp
, 0x10, 0x0A, PPC2_VSX
),
10856 GEN_XX2FORM(xvrspi
, 0x12, 0x08, PPC2_VSX
),
10857 GEN_XX2FORM(xvrspic
, 0x16, 0x0A, PPC2_VSX
),
10858 GEN_XX2FORM(xvrspim
, 0x12, 0x0B, PPC2_VSX
),
10859 GEN_XX2FORM(xvrspip
, 0x12, 0x0A, PPC2_VSX
),
10860 GEN_XX2FORM(xvrspiz
, 0x12, 0x09, PPC2_VSX
),
10863 #define VSX_LOGICAL(name, opc2, opc3, fl2) \
10864 GEN_XX3FORM(name, opc2, opc3, fl2)
10866 VSX_LOGICAL(xxland
, 0x8, 0x10, PPC2_VSX
),
10867 VSX_LOGICAL(xxlandc
, 0x8, 0x11, PPC2_VSX
),
10868 VSX_LOGICAL(xxlor
, 0x8, 0x12, PPC2_VSX
),
10869 VSX_LOGICAL(xxlxor
, 0x8, 0x13, PPC2_VSX
),
10870 VSX_LOGICAL(xxlnor
, 0x8, 0x14, PPC2_VSX
),
10871 VSX_LOGICAL(xxleqv
, 0x8, 0x17, PPC2_VSX207
),
10872 VSX_LOGICAL(xxlnand
, 0x8, 0x16, PPC2_VSX207
),
10873 VSX_LOGICAL(xxlorc
, 0x8, 0x15, PPC2_VSX207
),
10874 GEN_XX3FORM(xxmrghw
, 0x08, 0x02, PPC2_VSX
),
10875 GEN_XX3FORM(xxmrglw
, 0x08, 0x06, PPC2_VSX
),
10876 GEN_XX2FORM(xxspltw
, 0x08, 0x0A, PPC2_VSX
),
10877 GEN_XX3FORM_DM(xxsldwi
, 0x08, 0x00),
10879 #define GEN_XXSEL_ROW(opc3) \
10880 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x18, opc3, 0, PPC_NONE, PPC2_VSX), \
10881 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x19, opc3, 0, PPC_NONE, PPC2_VSX), \
10882 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1A, opc3, 0, PPC_NONE, PPC2_VSX), \
10883 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1B, opc3, 0, PPC_NONE, PPC2_VSX), \
10884 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1C, opc3, 0, PPC_NONE, PPC2_VSX), \
10885 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1D, opc3, 0, PPC_NONE, PPC2_VSX), \
10886 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1E, opc3, 0, PPC_NONE, PPC2_VSX), \
10887 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1F, opc3, 0, PPC_NONE, PPC2_VSX), \
10889 GEN_XXSEL_ROW(0x00)
10890 GEN_XXSEL_ROW(0x01)
10891 GEN_XXSEL_ROW(0x02)
10892 GEN_XXSEL_ROW(0x03)
10893 GEN_XXSEL_ROW(0x04)
10894 GEN_XXSEL_ROW(0x05)
10895 GEN_XXSEL_ROW(0x06)
10896 GEN_XXSEL_ROW(0x07)
10897 GEN_XXSEL_ROW(0x08)
10898 GEN_XXSEL_ROW(0x09)
10899 GEN_XXSEL_ROW(0x0A)
10900 GEN_XXSEL_ROW(0x0B)
10901 GEN_XXSEL_ROW(0x0C)
10902 GEN_XXSEL_ROW(0x0D)
10903 GEN_XXSEL_ROW(0x0E)
10904 GEN_XXSEL_ROW(0x0F)
10905 GEN_XXSEL_ROW(0x10)
10906 GEN_XXSEL_ROW(0x11)
10907 GEN_XXSEL_ROW(0x12)
10908 GEN_XXSEL_ROW(0x13)
10909 GEN_XXSEL_ROW(0x14)
10910 GEN_XXSEL_ROW(0x15)
10911 GEN_XXSEL_ROW(0x16)
10912 GEN_XXSEL_ROW(0x17)
10913 GEN_XXSEL_ROW(0x18)
10914 GEN_XXSEL_ROW(0x19)
10915 GEN_XXSEL_ROW(0x1A)
10916 GEN_XXSEL_ROW(0x1B)
10917 GEN_XXSEL_ROW(0x1C)
10918 GEN_XXSEL_ROW(0x1D)
10919 GEN_XXSEL_ROW(0x1E)
10920 GEN_XXSEL_ROW(0x1F)
10922 GEN_XX3FORM_DM(xxpermdi
, 0x08, 0x01),
10924 #undef GEN_DFP_T_A_B_Rc
10925 #undef GEN_DFP_BF_A_B
10926 #undef GEN_DFP_BF_A_DCM
10927 #undef GEN_DFP_T_B_U32_U32_Rc
10928 #undef GEN_DFP_T_A_B_I32_Rc
10929 #undef GEN_DFP_T_B_Rc
10930 #undef GEN_DFP_T_FPR_I32_Rc
10932 #define _GEN_DFP_LONG(name, op1, op2, mask) \
10933 GEN_HANDLER_E(name, 0x3B, op1, op2, mask, PPC_NONE, PPC2_DFP)
10935 #define _GEN_DFP_LONGx2(name, op1, op2, mask) \
10936 GEN_HANDLER_E(name, 0x3B, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10937 GEN_HANDLER_E(name, 0x3B, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP)
10939 #define _GEN_DFP_LONGx4(name, op1, op2, mask) \
10940 GEN_HANDLER_E(name, 0x3B, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10941 GEN_HANDLER_E(name, 0x3B, op1, 0x08 | op2, mask, PPC_NONE, PPC2_DFP), \
10942 GEN_HANDLER_E(name, 0x3B, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP), \
10943 GEN_HANDLER_E(name, 0x3B, op1, 0x18 | op2, mask, PPC_NONE, PPC2_DFP)
10945 #define _GEN_DFP_QUAD(name, op1, op2, mask) \
10946 GEN_HANDLER_E(name, 0x3F, op1, op2, mask, PPC_NONE, PPC2_DFP)
10948 #define _GEN_DFP_QUADx2(name, op1, op2, mask) \
10949 GEN_HANDLER_E(name, 0x3F, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10950 GEN_HANDLER_E(name, 0x3F, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP)
10952 #define _GEN_DFP_QUADx4(name, op1, op2, mask) \
10953 GEN_HANDLER_E(name, 0x3F, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10954 GEN_HANDLER_E(name, 0x3F, op1, 0x08 | op2, mask, PPC_NONE, PPC2_DFP), \
10955 GEN_HANDLER_E(name, 0x3F, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP), \
10956 GEN_HANDLER_E(name, 0x3F, op1, 0x18 | op2, mask, PPC_NONE, PPC2_DFP)
10958 #define GEN_DFP_T_A_B_Rc(name, op1, op2) \
10959 _GEN_DFP_LONG(name, op1, op2, 0x00000000)
10961 #define GEN_DFP_Tp_Ap_Bp_Rc(name, op1, op2) \
10962 _GEN_DFP_QUAD(name, op1, op2, 0x00210800)
10964 #define GEN_DFP_Tp_A_Bp_Rc(name, op1, op2) \
10965 _GEN_DFP_QUAD(name, op1, op2, 0x00200800)
10967 #define GEN_DFP_T_B_Rc(name, op1, op2) \
10968 _GEN_DFP_LONG(name, op1, op2, 0x001F0000)
10970 #define GEN_DFP_Tp_Bp_Rc(name, op1, op2) \
10971 _GEN_DFP_QUAD(name, op1, op2, 0x003F0800)
10973 #define GEN_DFP_Tp_B_Rc(name, op1, op2) \
10974 _GEN_DFP_QUAD(name, op1, op2, 0x003F0000)
10976 #define GEN_DFP_T_Bp_Rc(name, op1, op2) \
10977 _GEN_DFP_QUAD(name, op1, op2, 0x001F0800)
10979 #define GEN_DFP_BF_A_B(name, op1, op2) \
10980 _GEN_DFP_LONG(name, op1, op2, 0x00000001)
10982 #define GEN_DFP_BF_Ap_Bp(name, op1, op2) \
10983 _GEN_DFP_QUAD(name, op1, op2, 0x00610801)
10985 #define GEN_DFP_BF_A_Bp(name, op1, op2) \
10986 _GEN_DFP_QUAD(name, op1, op2, 0x00600801)
10988 #define GEN_DFP_BF_A_DCM(name, op1, op2) \
10989 _GEN_DFP_LONGx2(name, op1, op2, 0x00600001)
10991 #define GEN_DFP_BF_Ap_DCM(name, op1, op2) \
10992 _GEN_DFP_QUADx2(name, op1, op2, 0x00610001)
10994 #define GEN_DFP_T_A_B_RMC_Rc(name, op1, op2) \
10995 _GEN_DFP_LONGx4(name, op1, op2, 0x00000000)
10997 #define GEN_DFP_Tp_Ap_Bp_RMC_Rc(name, op1, op2) \
10998 _GEN_DFP_QUADx4(name, op1, op2, 0x02010800)
11000 #define GEN_DFP_Tp_A_Bp_RMC_Rc(name, op1, op2) \
11001 _GEN_DFP_QUADx4(name, op1, op2, 0x02000800)
11003 #define GEN_DFP_TE_T_B_RMC_Rc(name, op1, op2) \
11004 _GEN_DFP_LONGx4(name, op1, op2, 0x00000000)
11006 #define GEN_DFP_TE_Tp_Bp_RMC_Rc(name, op1, op2) \
11007 _GEN_DFP_QUADx4(name, op1, op2, 0x00200800)
11009 #define GEN_DFP_R_T_B_RMC_Rc(name, op1, op2) \
11010 _GEN_DFP_LONGx4(name, op1, op2, 0x001E0000)
11012 #define GEN_DFP_R_Tp_Bp_RMC_Rc(name, op1, op2) \
11013 _GEN_DFP_QUADx4(name, op1, op2, 0x003E0800)
11015 #define GEN_DFP_SP_T_B_Rc(name, op1, op2) \
11016 _GEN_DFP_LONG(name, op1, op2, 0x00070000)
11018 #define GEN_DFP_SP_Tp_Bp_Rc(name, op1, op2) \
11019 _GEN_DFP_QUAD(name, op1, op2, 0x00270800)
11021 #define GEN_DFP_S_T_B_Rc(name, op1, op2) \
11022 _GEN_DFP_LONG(name, op1, op2, 0x000F0000)
11024 #define GEN_DFP_S_Tp_Bp_Rc(name, op1, op2) \
11025 _GEN_DFP_QUAD(name, op1, op2, 0x002F0800)
11027 #define GEN_DFP_T_A_SH_Rc(name, op1, op2) \
11028 _GEN_DFP_LONGx2(name, op1, op2, 0x00000000)
11030 #define GEN_DFP_Tp_Ap_SH_Rc(name, op1, op2) \
11031 _GEN_DFP_QUADx2(name, op1, op2, 0x00210000)
11033 GEN_DFP_T_A_B_Rc(dadd
, 0x02, 0x00),
11034 GEN_DFP_Tp_Ap_Bp_Rc(daddq
, 0x02, 0x00),
11035 GEN_DFP_T_A_B_Rc(dsub
, 0x02, 0x10),
11036 GEN_DFP_Tp_Ap_Bp_Rc(dsubq
, 0x02, 0x10),
11037 GEN_DFP_T_A_B_Rc(dmul
, 0x02, 0x01),
11038 GEN_DFP_Tp_Ap_Bp_Rc(dmulq
, 0x02, 0x01),
11039 GEN_DFP_T_A_B_Rc(ddiv
, 0x02, 0x11),
11040 GEN_DFP_Tp_Ap_Bp_Rc(ddivq
, 0x02, 0x11),
11041 GEN_DFP_BF_A_B(dcmpu
, 0x02, 0x14),
11042 GEN_DFP_BF_Ap_Bp(dcmpuq
, 0x02, 0x14),
11043 GEN_DFP_BF_A_B(dcmpo
, 0x02, 0x04),
11044 GEN_DFP_BF_Ap_Bp(dcmpoq
, 0x02, 0x04),
11045 GEN_DFP_BF_A_DCM(dtstdc
, 0x02, 0x06),
11046 GEN_DFP_BF_Ap_DCM(dtstdcq
, 0x02, 0x06),
11047 GEN_DFP_BF_A_DCM(dtstdg
, 0x02, 0x07),
11048 GEN_DFP_BF_Ap_DCM(dtstdgq
, 0x02, 0x07),
11049 GEN_DFP_BF_A_B(dtstex
, 0x02, 0x05),
11050 GEN_DFP_BF_Ap_Bp(dtstexq
, 0x02, 0x05),
11051 GEN_DFP_BF_A_B(dtstsf
, 0x02, 0x15),
11052 GEN_DFP_BF_A_Bp(dtstsfq
, 0x02, 0x15),
11053 GEN_DFP_TE_T_B_RMC_Rc(dquai
, 0x03, 0x02),
11054 GEN_DFP_TE_Tp_Bp_RMC_Rc(dquaiq
, 0x03, 0x02),
11055 GEN_DFP_T_A_B_RMC_Rc(dqua
, 0x03, 0x00),
11056 GEN_DFP_Tp_Ap_Bp_RMC_Rc(dquaq
, 0x03, 0x00),
11057 GEN_DFP_T_A_B_RMC_Rc(drrnd
, 0x03, 0x01),
11058 GEN_DFP_Tp_A_Bp_RMC_Rc(drrndq
, 0x03, 0x01),
11059 GEN_DFP_R_T_B_RMC_Rc(drintx
, 0x03, 0x03),
11060 GEN_DFP_R_Tp_Bp_RMC_Rc(drintxq
, 0x03, 0x03),
11061 GEN_DFP_R_T_B_RMC_Rc(drintn
, 0x03, 0x07),
11062 GEN_DFP_R_Tp_Bp_RMC_Rc(drintnq
, 0x03, 0x07),
11063 GEN_DFP_T_B_Rc(dctdp
, 0x02, 0x08),
11064 GEN_DFP_Tp_B_Rc(dctqpq
, 0x02, 0x08),
11065 GEN_DFP_T_B_Rc(drsp
, 0x02, 0x18),
11066 GEN_DFP_Tp_Bp_Rc(drdpq
, 0x02, 0x18),
11067 GEN_DFP_T_B_Rc(dcffix
, 0x02, 0x19),
11068 GEN_DFP_Tp_B_Rc(dcffixq
, 0x02, 0x19),
11069 GEN_DFP_T_B_Rc(dctfix
, 0x02, 0x09),
11070 GEN_DFP_T_Bp_Rc(dctfixq
, 0x02, 0x09),
11071 GEN_DFP_SP_T_B_Rc(ddedpd
, 0x02, 0x0a),
11072 GEN_DFP_SP_Tp_Bp_Rc(ddedpdq
, 0x02, 0x0a),
11073 GEN_DFP_S_T_B_Rc(denbcd
, 0x02, 0x1a),
11074 GEN_DFP_S_Tp_Bp_Rc(denbcdq
, 0x02, 0x1a),
11075 GEN_DFP_T_B_Rc(dxex
, 0x02, 0x0b),
11076 GEN_DFP_T_Bp_Rc(dxexq
, 0x02, 0x0b),
11077 GEN_DFP_T_A_B_Rc(diex
, 0x02, 0x1b),
11078 GEN_DFP_Tp_A_Bp_Rc(diexq
, 0x02, 0x1b),
11079 GEN_DFP_T_A_SH_Rc(dscli
, 0x02, 0x02),
11080 GEN_DFP_Tp_Ap_SH_Rc(dscliq
, 0x02, 0x02),
11081 GEN_DFP_T_A_SH_Rc(dscri
, 0x02, 0x03),
11082 GEN_DFP_Tp_Ap_SH_Rc(dscriq
, 0x02, 0x03),
11085 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
11086 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
11087 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
11088 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
11089 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
11090 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
11091 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
11092 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
11093 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
11094 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE
),
11095 GEN_SPE(evmra
, speundef
, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE
),
11096 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
),
11097 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
11098 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
11099 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
11100 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE
),
11101 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE
),
11102 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE
),
11103 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
),
11104 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
11105 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
11106 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
11107 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
11108 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
11109 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE
),
11110 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE
),
11111 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
11112 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
11113 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE
),
11114 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE
),
11115 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE
),
11117 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
11118 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
),
11119 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11120 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
11121 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
11122 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11123 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11124 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11125 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11126 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11127 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11128 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11129 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
11130 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11132 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
11133 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
),
11134 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11135 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
11136 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
11137 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE
),
11138 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11139 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11140 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11141 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11142 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11143 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11144 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
11145 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11147 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
),
11148 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
11149 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE
),
11150 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
11151 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
),
11152 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
11153 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
),
11154 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE
),
11155 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
11156 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
11157 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
11158 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
11159 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
11160 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
11161 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
),
11162 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
11164 #undef GEN_SPEOP_LDST
11165 #define GEN_SPEOP_LDST(name, opc2, sh) \
11166 GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
11167 GEN_SPEOP_LDST(evldd
, 0x00, 3),
11168 GEN_SPEOP_LDST(evldw
, 0x01, 3),
11169 GEN_SPEOP_LDST(evldh
, 0x02, 3),
11170 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1),
11171 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1),
11172 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1),
11173 GEN_SPEOP_LDST(evlwhe
, 0x08, 2),
11174 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2),
11175 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2),
11176 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2),
11177 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2),
11179 GEN_SPEOP_LDST(evstdd
, 0x10, 3),
11180 GEN_SPEOP_LDST(evstdw
, 0x11, 3),
11181 GEN_SPEOP_LDST(evstdh
, 0x12, 3),
11182 GEN_SPEOP_LDST(evstwhe
, 0x18, 2),
11183 GEN_SPEOP_LDST(evstwho
, 0x1A, 2),
11184 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2),
11185 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2),
11187 GEN_HANDLER2_E(tbegin
, "tbegin", 0x1F, 0x0E, 0x14, 0x01DFF800, \
11188 PPC_NONE
, PPC2_TM
),
11189 GEN_HANDLER2_E(tend
, "tend", 0x1F, 0x0E, 0x15, 0x01FFF800, \
11190 PPC_NONE
, PPC2_TM
),
11191 GEN_HANDLER2_E(tabort
, "tabort", 0x1F, 0x0E, 0x1C, 0x03E0F800, \
11192 PPC_NONE
, PPC2_TM
),
11193 GEN_HANDLER2_E(tabortwc
, "tabortwc", 0x1F, 0x0E, 0x18, 0x00000000, \
11194 PPC_NONE
, PPC2_TM
),
11195 GEN_HANDLER2_E(tabortwci
, "tabortwci", 0x1F, 0x0E, 0x1A, 0x00000000, \
11196 PPC_NONE
, PPC2_TM
),
11197 GEN_HANDLER2_E(tabortdc
, "tabortdc", 0x1F, 0x0E, 0x19, 0x00000000, \
11198 PPC_NONE
, PPC2_TM
),
11199 GEN_HANDLER2_E(tabortdci
, "tabortdci", 0x1F, 0x0E, 0x1B, 0x00000000, \
11200 PPC_NONE
, PPC2_TM
),
11201 GEN_HANDLER2_E(tsr
, "tsr", 0x1F, 0x0E, 0x17, 0x03DFF800, \
11202 PPC_NONE
, PPC2_TM
),
11203 GEN_HANDLER2_E(tcheck
, "tcheck", 0x1F, 0x0E, 0x16, 0x007FF800, \
11204 PPC_NONE
, PPC2_TM
),
11205 GEN_HANDLER2_E(treclaim
, "treclaim", 0x1F, 0x0E, 0x1D, 0x03E0F800, \
11206 PPC_NONE
, PPC2_TM
),
11207 GEN_HANDLER2_E(trechkpt
, "trechkpt", 0x1F, 0x0E, 0x1F, 0x03FFF800, \
11208 PPC_NONE
, PPC2_TM
),
11211 #include "helper_regs.h"
11212 #include "translate_init.c"
11214 /*****************************************************************************/
11215 /* Misc PowerPC helpers */
11216 void ppc_cpu_dump_state(CPUState
*cs
, FILE *f
, fprintf_function cpu_fprintf
,
11222 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
11223 CPUPPCState
*env
= &cpu
->env
;
11226 cpu_fprintf(f
, "NIP " TARGET_FMT_lx
" LR " TARGET_FMT_lx
" CTR "
11227 TARGET_FMT_lx
" XER " TARGET_FMT_lx
" CPU#%d\n",
11228 env
->nip
, env
->lr
, env
->ctr
, cpu_read_xer(env
),
11230 cpu_fprintf(f
, "MSR " TARGET_FMT_lx
" HID0 " TARGET_FMT_lx
" HF "
11231 TARGET_FMT_lx
" idx %d\n", env
->msr
, env
->spr
[SPR_HID0
],
11232 env
->hflags
, env
->mmu_idx
);
11233 #if !defined(NO_TIMER_DUMP)
11234 cpu_fprintf(f
, "TB %08" PRIu32
" %08" PRIu64
11235 #if !defined(CONFIG_USER_ONLY)
11239 cpu_ppc_load_tbu(env
), cpu_ppc_load_tbl(env
)
11240 #if !defined(CONFIG_USER_ONLY)
11241 , cpu_ppc_load_decr(env
)
11245 for (i
= 0; i
< 32; i
++) {
11246 if ((i
& (RGPL
- 1)) == 0)
11247 cpu_fprintf(f
, "GPR%02d", i
);
11248 cpu_fprintf(f
, " %016" PRIx64
, ppc_dump_gpr(env
, i
));
11249 if ((i
& (RGPL
- 1)) == (RGPL
- 1))
11250 cpu_fprintf(f
, "\n");
11252 cpu_fprintf(f
, "CR ");
11253 for (i
= 0; i
< 8; i
++)
11254 cpu_fprintf(f
, "%01x", env
->crf
[i
]);
11255 cpu_fprintf(f
, " [");
11256 for (i
= 0; i
< 8; i
++) {
11258 if (env
->crf
[i
] & 0x08)
11260 else if (env
->crf
[i
] & 0x04)
11262 else if (env
->crf
[i
] & 0x02)
11264 cpu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
11266 cpu_fprintf(f
, " ] RES " TARGET_FMT_lx
"\n",
11267 env
->reserve_addr
);
11268 for (i
= 0; i
< 32; i
++) {
11269 if ((i
& (RFPL
- 1)) == 0)
11270 cpu_fprintf(f
, "FPR%02d", i
);
11271 cpu_fprintf(f
, " %016" PRIx64
, *((uint64_t *)&env
->fpr
[i
]));
11272 if ((i
& (RFPL
- 1)) == (RFPL
- 1))
11273 cpu_fprintf(f
, "\n");
11275 cpu_fprintf(f
, "FPSCR " TARGET_FMT_lx
"\n", env
->fpscr
);
11276 #if !defined(CONFIG_USER_ONLY)
11277 cpu_fprintf(f
, " SRR0 " TARGET_FMT_lx
" SRR1 " TARGET_FMT_lx
11278 " PVR " TARGET_FMT_lx
" VRSAVE " TARGET_FMT_lx
"\n",
11279 env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
11280 env
->spr
[SPR_PVR
], env
->spr
[SPR_VRSAVE
]);
11282 cpu_fprintf(f
, "SPRG0 " TARGET_FMT_lx
" SPRG1 " TARGET_FMT_lx
11283 " SPRG2 " TARGET_FMT_lx
" SPRG3 " TARGET_FMT_lx
"\n",
11284 env
->spr
[SPR_SPRG0
], env
->spr
[SPR_SPRG1
],
11285 env
->spr
[SPR_SPRG2
], env
->spr
[SPR_SPRG3
]);
11287 cpu_fprintf(f
, "SPRG4 " TARGET_FMT_lx
" SPRG5 " TARGET_FMT_lx
11288 " SPRG6 " TARGET_FMT_lx
" SPRG7 " TARGET_FMT_lx
"\n",
11289 env
->spr
[SPR_SPRG4
], env
->spr
[SPR_SPRG5
],
11290 env
->spr
[SPR_SPRG6
], env
->spr
[SPR_SPRG7
]);
11292 if (env
->excp_model
== POWERPC_EXCP_BOOKE
) {
11293 cpu_fprintf(f
, "CSRR0 " TARGET_FMT_lx
" CSRR1 " TARGET_FMT_lx
11294 " MCSRR0 " TARGET_FMT_lx
" MCSRR1 " TARGET_FMT_lx
"\n",
11295 env
->spr
[SPR_BOOKE_CSRR0
], env
->spr
[SPR_BOOKE_CSRR1
],
11296 env
->spr
[SPR_BOOKE_MCSRR0
], env
->spr
[SPR_BOOKE_MCSRR1
]);
11298 cpu_fprintf(f
, " TCR " TARGET_FMT_lx
" TSR " TARGET_FMT_lx
11299 " ESR " TARGET_FMT_lx
" DEAR " TARGET_FMT_lx
"\n",
11300 env
->spr
[SPR_BOOKE_TCR
], env
->spr
[SPR_BOOKE_TSR
],
11301 env
->spr
[SPR_BOOKE_ESR
], env
->spr
[SPR_BOOKE_DEAR
]);
11303 cpu_fprintf(f
, " PIR " TARGET_FMT_lx
" DECAR " TARGET_FMT_lx
11304 " IVPR " TARGET_FMT_lx
" EPCR " TARGET_FMT_lx
"\n",
11305 env
->spr
[SPR_BOOKE_PIR
], env
->spr
[SPR_BOOKE_DECAR
],
11306 env
->spr
[SPR_BOOKE_IVPR
], env
->spr
[SPR_BOOKE_EPCR
]);
11308 cpu_fprintf(f
, " MCSR " TARGET_FMT_lx
" SPRG8 " TARGET_FMT_lx
11309 " EPR " TARGET_FMT_lx
"\n",
11310 env
->spr
[SPR_BOOKE_MCSR
], env
->spr
[SPR_BOOKE_SPRG8
],
11311 env
->spr
[SPR_BOOKE_EPR
]);
11314 cpu_fprintf(f
, " MCAR " TARGET_FMT_lx
" PID1 " TARGET_FMT_lx
11315 " PID2 " TARGET_FMT_lx
" SVR " TARGET_FMT_lx
"\n",
11316 env
->spr
[SPR_Exxx_MCAR
], env
->spr
[SPR_BOOKE_PID1
],
11317 env
->spr
[SPR_BOOKE_PID2
], env
->spr
[SPR_E500_SVR
]);
11320 * IVORs are left out as they are large and do not change often --
11321 * they can be read with "p $ivor0", "p $ivor1", etc.
11325 #if defined(TARGET_PPC64)
11326 if (env
->flags
& POWERPC_FLAG_CFAR
) {
11327 cpu_fprintf(f
, " CFAR " TARGET_FMT_lx
"\n", env
->cfar
);
11331 switch (env
->mmu_model
) {
11332 case POWERPC_MMU_32B
:
11333 case POWERPC_MMU_601
:
11334 case POWERPC_MMU_SOFT_6xx
:
11335 case POWERPC_MMU_SOFT_74xx
:
11336 #if defined(TARGET_PPC64)
11337 case POWERPC_MMU_64B
:
11338 case POWERPC_MMU_2_03
:
11339 case POWERPC_MMU_2_06
:
11340 case POWERPC_MMU_2_07
:
11342 cpu_fprintf(f
, " SDR1 " TARGET_FMT_lx
" DAR " TARGET_FMT_lx
11343 " DSISR " TARGET_FMT_lx
"\n", env
->spr
[SPR_SDR1
],
11344 env
->spr
[SPR_DAR
], env
->spr
[SPR_DSISR
]);
11346 case POWERPC_MMU_BOOKE206
:
11347 cpu_fprintf(f
, " MAS0 " TARGET_FMT_lx
" MAS1 " TARGET_FMT_lx
11348 " MAS2 " TARGET_FMT_lx
" MAS3 " TARGET_FMT_lx
"\n",
11349 env
->spr
[SPR_BOOKE_MAS0
], env
->spr
[SPR_BOOKE_MAS1
],
11350 env
->spr
[SPR_BOOKE_MAS2
], env
->spr
[SPR_BOOKE_MAS3
]);
11352 cpu_fprintf(f
, " MAS4 " TARGET_FMT_lx
" MAS6 " TARGET_FMT_lx
11353 " MAS7 " TARGET_FMT_lx
" PID " TARGET_FMT_lx
"\n",
11354 env
->spr
[SPR_BOOKE_MAS4
], env
->spr
[SPR_BOOKE_MAS6
],
11355 env
->spr
[SPR_BOOKE_MAS7
], env
->spr
[SPR_BOOKE_PID
]);
11357 cpu_fprintf(f
, "MMUCFG " TARGET_FMT_lx
" TLB0CFG " TARGET_FMT_lx
11358 " TLB1CFG " TARGET_FMT_lx
"\n",
11359 env
->spr
[SPR_MMUCFG
], env
->spr
[SPR_BOOKE_TLB0CFG
],
11360 env
->spr
[SPR_BOOKE_TLB1CFG
]);
11371 void ppc_cpu_dump_statistics(CPUState
*cs
, FILE*f
,
11372 fprintf_function cpu_fprintf
, int flags
)
11374 #if defined(DO_PPC_STATISTICS)
11375 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
11376 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
11379 t1
= cpu
->env
.opcodes
;
11380 for (op1
= 0; op1
< 64; op1
++) {
11382 if (is_indirect_opcode(handler
)) {
11383 t2
= ind_table(handler
);
11384 for (op2
= 0; op2
< 32; op2
++) {
11386 if (is_indirect_opcode(handler
)) {
11387 t3
= ind_table(handler
);
11388 for (op3
= 0; op3
< 32; op3
++) {
11390 if (handler
->count
== 0)
11392 cpu_fprintf(f
, "%02x %02x %02x (%02x %04d) %16s: "
11393 "%016" PRIx64
" %" PRId64
"\n",
11394 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
11396 handler
->count
, handler
->count
);
11399 if (handler
->count
== 0)
11401 cpu_fprintf(f
, "%02x %02x (%02x %04d) %16s: "
11402 "%016" PRIx64
" %" PRId64
"\n",
11403 op1
, op2
, op1
, op2
, handler
->oname
,
11404 handler
->count
, handler
->count
);
11408 if (handler
->count
== 0)
11410 cpu_fprintf(f
, "%02x (%02x ) %16s: %016" PRIx64
11412 op1
, op1
, handler
->oname
,
11413 handler
->count
, handler
->count
);
11419 /*****************************************************************************/
11420 void gen_intermediate_code(CPUPPCState
*env
, struct TranslationBlock
*tb
)
11422 PowerPCCPU
*cpu
= ppc_env_get_cpu(env
);
11423 CPUState
*cs
= CPU(cpu
);
11424 DisasContext ctx
, *ctxp
= &ctx
;
11425 opc_handler_t
**table
, *handler
;
11426 target_ulong pc_start
;
11431 ctx
.nip
= pc_start
;
11433 ctx
.exception
= POWERPC_EXCP_NONE
;
11434 ctx
.spr_cb
= env
->spr_cb
;
11436 ctx
.hv
= !msr_pr
&& msr_hv
;
11437 ctx
.mem_idx
= env
->mmu_idx
;
11438 ctx
.insns_flags
= env
->insns_flags
;
11439 ctx
.insns_flags2
= env
->insns_flags2
;
11440 ctx
.access_type
= -1;
11441 ctx
.le_mode
= env
->hflags
& (1 << MSR_LE
) ? 1 : 0;
11442 ctx
.default_tcg_memop_mask
= ctx
.le_mode
? MO_LE
: MO_BE
;
11443 #if defined(TARGET_PPC64)
11444 ctx
.sf_mode
= msr_is_64bit(env
, env
->msr
);
11445 ctx
.has_cfar
= !!(env
->flags
& POWERPC_FLAG_CFAR
);
11447 ctx
.fpu_enabled
= msr_fp
;
11448 if ((env
->flags
& POWERPC_FLAG_SPE
) && msr_spe
)
11449 ctx
.spe_enabled
= msr_spe
;
11451 ctx
.spe_enabled
= 0;
11452 if ((env
->flags
& POWERPC_FLAG_VRE
) && msr_vr
)
11453 ctx
.altivec_enabled
= msr_vr
;
11455 ctx
.altivec_enabled
= 0;
11456 if ((env
->flags
& POWERPC_FLAG_VSX
) && msr_vsx
) {
11457 ctx
.vsx_enabled
= msr_vsx
;
11459 ctx
.vsx_enabled
= 0;
11461 #if defined(TARGET_PPC64)
11462 if ((env
->flags
& POWERPC_FLAG_TM
) && msr_tm
) {
11463 ctx
.tm_enabled
= msr_tm
;
11465 ctx
.tm_enabled
= 0;
11468 if ((env
->flags
& POWERPC_FLAG_SE
) && msr_se
)
11469 ctx
.singlestep_enabled
= CPU_SINGLE_STEP
;
11471 ctx
.singlestep_enabled
= 0;
11472 if ((env
->flags
& POWERPC_FLAG_BE
) && msr_be
)
11473 ctx
.singlestep_enabled
|= CPU_BRANCH_STEP
;
11474 if (unlikely(cs
->singlestep_enabled
)) {
11475 ctx
.singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
11477 #if defined (DO_SINGLE_STEP) && 0
11478 /* Single step trace mode */
11482 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
11483 if (max_insns
== 0) {
11484 max_insns
= CF_COUNT_MASK
;
11486 if (max_insns
> TCG_MAX_INSNS
) {
11487 max_insns
= TCG_MAX_INSNS
;
11491 tcg_clear_temp_count();
11492 /* Set env in case of segfault during code fetch */
11493 while (ctx
.exception
== POWERPC_EXCP_NONE
&& !tcg_op_buf_full()) {
11494 tcg_gen_insn_start(ctx
.nip
);
11497 if (unlikely(cpu_breakpoint_test(cs
, ctx
.nip
, BP_ANY
))) {
11498 gen_debug_exception(ctxp
);
11499 /* The address covered by the breakpoint must be included in
11500 [tb->pc, tb->pc + tb->size) in order to for it to be
11501 properly cleared -- thus we increment the PC here so that
11502 the logic setting tb->size below does the right thing. */
11507 LOG_DISAS("----------------\n");
11508 LOG_DISAS("nip=" TARGET_FMT_lx
" super=%d ir=%d\n",
11509 ctx
.nip
, ctx
.mem_idx
, (int)msr_ir
);
11510 if (num_insns
== max_insns
&& (tb
->cflags
& CF_LAST_IO
))
11512 if (unlikely(need_byteswap(&ctx
))) {
11513 ctx
.opcode
= bswap32(cpu_ldl_code(env
, ctx
.nip
));
11515 ctx
.opcode
= cpu_ldl_code(env
, ctx
.nip
);
11517 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
11518 ctx
.opcode
, opc1(ctx
.opcode
), opc2(ctx
.opcode
),
11519 opc3(ctx
.opcode
), ctx
.le_mode
? "little" : "big");
11521 table
= env
->opcodes
;
11522 handler
= table
[opc1(ctx
.opcode
)];
11523 if (is_indirect_opcode(handler
)) {
11524 table
= ind_table(handler
);
11525 handler
= table
[opc2(ctx
.opcode
)];
11526 if (is_indirect_opcode(handler
)) {
11527 table
= ind_table(handler
);
11528 handler
= table
[opc3(ctx
.opcode
)];
11531 /* Is opcode *REALLY* valid ? */
11532 if (unlikely(handler
->handler
== &gen_invalid
)) {
11533 qemu_log_mask(LOG_GUEST_ERROR
, "invalid/unsupported opcode: "
11534 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx
" %d\n",
11535 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
11536 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
11540 if (unlikely(handler
->type
& (PPC_SPE
| PPC_SPE_SINGLE
| PPC_SPE_DOUBLE
) && Rc(ctx
.opcode
))) {
11541 inval
= handler
->inval2
;
11543 inval
= handler
->inval1
;
11546 if (unlikely((ctx
.opcode
& inval
) != 0)) {
11547 qemu_log_mask(LOG_GUEST_ERROR
, "invalid bits: %08x for opcode: "
11548 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx
"\n",
11549 ctx
.opcode
& inval
, opc1(ctx
.opcode
),
11550 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
11551 ctx
.opcode
, ctx
.nip
- 4);
11552 gen_inval_exception(ctxp
, POWERPC_EXCP_INVAL_INVAL
);
11556 (*(handler
->handler
))(&ctx
);
11557 #if defined(DO_PPC_STATISTICS)
11560 /* Check trace mode exceptions */
11561 if (unlikely(ctx
.singlestep_enabled
& CPU_SINGLE_STEP
&&
11562 (ctx
.nip
<= 0x100 || ctx
.nip
> 0xF00) &&
11563 ctx
.exception
!= POWERPC_SYSCALL
&&
11564 ctx
.exception
!= POWERPC_EXCP_TRAP
&&
11565 ctx
.exception
!= POWERPC_EXCP_BRANCH
)) {
11566 gen_exception(ctxp
, POWERPC_EXCP_TRACE
);
11567 } else if (unlikely(((ctx
.nip
& (TARGET_PAGE_SIZE
- 1)) == 0) ||
11568 (cs
->singlestep_enabled
) ||
11570 num_insns
>= max_insns
)) {
11571 /* if we reach a page boundary or are single stepping, stop
11576 if (tcg_check_temp_count()) {
11577 fprintf(stderr
, "Opcode %02x %02x %02x (%08x) leaked temporaries\n",
11578 opc1(ctx
.opcode
), opc2(ctx
.opcode
), opc3(ctx
.opcode
),
11583 if (tb
->cflags
& CF_LAST_IO
)
11585 if (ctx
.exception
== POWERPC_EXCP_NONE
) {
11586 gen_goto_tb(&ctx
, 0, ctx
.nip
);
11587 } else if (ctx
.exception
!= POWERPC_EXCP_BRANCH
) {
11588 if (unlikely(cs
->singlestep_enabled
)) {
11589 gen_debug_exception(ctxp
);
11591 /* Generate the return instruction */
11592 tcg_gen_exit_tb(0);
11594 gen_tb_end(tb
, num_insns
);
11596 tb
->size
= ctx
.nip
- pc_start
;
11597 tb
->icount
= num_insns
;
11599 #if defined(DEBUG_DISAS)
11600 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
11602 flags
= env
->bfd_mach
;
11603 flags
|= ctx
.le_mode
<< 16;
11604 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
11605 log_target_disas(cs
, pc_start
, ctx
.nip
- pc_start
, flags
);
11611 void restore_state_to_opc(CPUPPCState
*env
, TranslationBlock
*tb
,
11612 target_ulong
*data
)
11614 env
->nip
= data
[0];