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 typedef struct DisasContext
{
187 struct TranslationBlock
*tb
;
191 /* Routine used to access memory */
194 /* Translation flags */
196 TCGMemOp default_tcg_memop_mask
;
197 #if defined(TARGET_PPC64)
205 ppc_spr_t
*spr_cb
; /* Needed to check rights for mfspr/mtspr */
206 int singlestep_enabled
;
207 uint64_t insns_flags
;
208 uint64_t insns_flags2
;
211 /* Return true iff byteswap is needed in a scalar memop */
212 static inline bool need_byteswap(const DisasContext
*ctx
)
214 #if defined(TARGET_WORDS_BIGENDIAN)
217 return !ctx
->le_mode
;
221 /* True when active word size < size of target_long. */
223 # define NARROW_MODE(C) (!(C)->sf_mode)
225 # define NARROW_MODE(C) 0
228 struct opc_handler_t
{
229 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
231 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
233 /* instruction type */
235 /* extended instruction type */
238 void (*handler
)(DisasContext
*ctx
);
239 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
242 #if defined(DO_PPC_STATISTICS)
247 static inline void gen_reset_fpstatus(void)
249 gen_helper_reset_fpstatus(cpu_env
);
252 static inline void gen_compute_fprf(TCGv_i64 arg
, int set_fprf
, int set_rc
)
254 TCGv_i32 t0
= tcg_temp_new_i32();
257 /* This case might be optimized later */
258 tcg_gen_movi_i32(t0
, 1);
259 gen_helper_compute_fprf(t0
, cpu_env
, arg
, t0
);
260 if (unlikely(set_rc
)) {
261 tcg_gen_mov_i32(cpu_crf
[1], t0
);
263 gen_helper_float_check_status(cpu_env
);
264 } else if (unlikely(set_rc
)) {
265 /* We always need to compute fpcc */
266 tcg_gen_movi_i32(t0
, 0);
267 gen_helper_compute_fprf(t0
, cpu_env
, arg
, t0
);
268 tcg_gen_mov_i32(cpu_crf
[1], t0
);
271 tcg_temp_free_i32(t0
);
274 static inline void gen_set_access_type(DisasContext
*ctx
, int access_type
)
276 if (ctx
->access_type
!= access_type
) {
277 tcg_gen_movi_i32(cpu_access_type
, access_type
);
278 ctx
->access_type
= access_type
;
282 static inline void gen_update_nip(DisasContext
*ctx
, target_ulong nip
)
284 if (NARROW_MODE(ctx
)) {
287 tcg_gen_movi_tl(cpu_nip
, nip
);
290 void gen_update_current_nip(void *opaque
)
292 DisasContext
*ctx
= opaque
;
294 tcg_gen_movi_tl(cpu_nip
, ctx
->nip
);
297 static inline void gen_exception_err(DisasContext
*ctx
, uint32_t excp
, uint32_t error
)
300 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
301 gen_update_nip(ctx
, ctx
->nip
);
303 t0
= tcg_const_i32(excp
);
304 t1
= tcg_const_i32(error
);
305 gen_helper_raise_exception_err(cpu_env
, t0
, t1
);
306 tcg_temp_free_i32(t0
);
307 tcg_temp_free_i32(t1
);
308 ctx
->exception
= (excp
);
311 static inline void gen_exception(DisasContext
*ctx
, uint32_t excp
)
314 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
315 gen_update_nip(ctx
, ctx
->nip
);
317 t0
= tcg_const_i32(excp
);
318 gen_helper_raise_exception(cpu_env
, t0
);
319 tcg_temp_free_i32(t0
);
320 ctx
->exception
= (excp
);
323 static inline void gen_debug_exception(DisasContext
*ctx
)
327 if ((ctx
->exception
!= POWERPC_EXCP_BRANCH
) &&
328 (ctx
->exception
!= POWERPC_EXCP_SYNC
)) {
329 gen_update_nip(ctx
, ctx
->nip
);
331 t0
= tcg_const_i32(EXCP_DEBUG
);
332 gen_helper_raise_exception(cpu_env
, t0
);
333 tcg_temp_free_i32(t0
);
336 static inline void gen_inval_exception(DisasContext
*ctx
, uint32_t error
)
338 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_INVAL
| error
);
341 /* Stop translation */
342 static inline void gen_stop_exception(DisasContext
*ctx
)
344 gen_update_nip(ctx
, ctx
->nip
);
345 ctx
->exception
= POWERPC_EXCP_STOP
;
348 /* No need to update nip here, as execution flow will change */
349 static inline void gen_sync_exception(DisasContext
*ctx
)
351 ctx
->exception
= POWERPC_EXCP_SYNC
;
354 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
355 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
357 #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
358 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
360 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
361 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
363 #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
364 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
366 typedef struct opcode_t
{
367 unsigned char opc1
, opc2
, opc3
;
368 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
369 unsigned char pad
[5];
371 unsigned char pad
[1];
373 opc_handler_t handler
;
377 /*****************************************************************************/
378 /*** Instruction decoding ***/
379 #define EXTRACT_HELPER(name, shift, nb) \
380 static inline uint32_t name(uint32_t opcode) \
382 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
385 #define EXTRACT_SHELPER(name, shift, nb) \
386 static inline int32_t name(uint32_t opcode) \
388 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
391 #define EXTRACT_HELPER_SPLIT(name, shift1, nb1, shift2, nb2) \
392 static inline uint32_t name(uint32_t opcode) \
394 return (((opcode >> (shift1)) & ((1 << (nb1)) - 1)) << nb2) | \
395 ((opcode >> (shift2)) & ((1 << (nb2)) - 1)); \
398 EXTRACT_HELPER(opc1
, 26, 6);
400 EXTRACT_HELPER(opc2
, 1, 5);
402 EXTRACT_HELPER(opc3
, 6, 5);
403 /* Update Cr0 flags */
404 EXTRACT_HELPER(Rc
, 0, 1);
405 /* Update Cr6 flags (Altivec) */
406 EXTRACT_HELPER(Rc21
, 10, 1);
408 EXTRACT_HELPER(rD
, 21, 5);
410 EXTRACT_HELPER(rS
, 21, 5);
412 EXTRACT_HELPER(rA
, 16, 5);
414 EXTRACT_HELPER(rB
, 11, 5);
416 EXTRACT_HELPER(rC
, 6, 5);
418 EXTRACT_HELPER(crfD
, 23, 3);
419 EXTRACT_HELPER(crfS
, 18, 3);
420 EXTRACT_HELPER(crbD
, 21, 5);
421 EXTRACT_HELPER(crbA
, 16, 5);
422 EXTRACT_HELPER(crbB
, 11, 5);
424 EXTRACT_HELPER(_SPR
, 11, 10);
425 static inline uint32_t SPR(uint32_t opcode
)
427 uint32_t sprn
= _SPR(opcode
);
429 return ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
431 /*** Get constants ***/
432 /* 16 bits signed immediate value */
433 EXTRACT_SHELPER(SIMM
, 0, 16);
434 /* 16 bits unsigned immediate value */
435 EXTRACT_HELPER(UIMM
, 0, 16);
436 /* 5 bits signed immediate value */
437 EXTRACT_HELPER(SIMM5
, 16, 5);
438 /* 5 bits signed immediate value */
439 EXTRACT_HELPER(UIMM5
, 16, 5);
441 EXTRACT_HELPER(NB
, 11, 5);
443 EXTRACT_HELPER(SH
, 11, 5);
444 /* Vector shift count */
445 EXTRACT_HELPER(VSH
, 6, 4);
447 EXTRACT_HELPER(MB
, 6, 5);
449 EXTRACT_HELPER(ME
, 1, 5);
451 EXTRACT_HELPER(TO
, 21, 5);
453 EXTRACT_HELPER(CRM
, 12, 8);
454 EXTRACT_HELPER(SR
, 16, 4);
457 EXTRACT_HELPER(FPBF
, 23, 3);
458 EXTRACT_HELPER(FPIMM
, 12, 4);
459 EXTRACT_HELPER(FPL
, 25, 1);
460 EXTRACT_HELPER(FPFLM
, 17, 8);
461 EXTRACT_HELPER(FPW
, 16, 1);
463 /*** Jump target decoding ***/
464 /* Immediate address */
465 static inline target_ulong
LI(uint32_t opcode
)
467 return (opcode
>> 0) & 0x03FFFFFC;
470 static inline uint32_t BD(uint32_t opcode
)
472 return (opcode
>> 0) & 0xFFFC;
475 EXTRACT_HELPER(BO
, 21, 5);
476 EXTRACT_HELPER(BI
, 16, 5);
477 /* Absolute/relative address */
478 EXTRACT_HELPER(AA
, 1, 1);
480 EXTRACT_HELPER(LK
, 0, 1);
483 EXTRACT_HELPER(DCM
, 10, 6)
486 EXTRACT_HELPER(RMC
, 9, 2)
488 /* Create a mask between <start> and <end> bits */
489 static inline target_ulong
MASK(uint32_t start
, uint32_t end
)
493 #if defined(TARGET_PPC64)
494 if (likely(start
== 0)) {
495 ret
= UINT64_MAX
<< (63 - end
);
496 } else if (likely(end
== 63)) {
497 ret
= UINT64_MAX
>> start
;
500 if (likely(start
== 0)) {
501 ret
= UINT32_MAX
<< (31 - end
);
502 } else if (likely(end
== 31)) {
503 ret
= UINT32_MAX
>> start
;
507 ret
= (((target_ulong
)(-1ULL)) >> (start
)) ^
508 (((target_ulong
)(-1ULL) >> (end
)) >> 1);
509 if (unlikely(start
> end
))
516 EXTRACT_HELPER_SPLIT(xT
, 0, 1, 21, 5);
517 EXTRACT_HELPER_SPLIT(xS
, 0, 1, 21, 5);
518 EXTRACT_HELPER_SPLIT(xA
, 2, 1, 16, 5);
519 EXTRACT_HELPER_SPLIT(xB
, 1, 1, 11, 5);
520 EXTRACT_HELPER_SPLIT(xC
, 3, 1, 6, 5);
521 EXTRACT_HELPER(DM
, 8, 2);
522 EXTRACT_HELPER(UIM
, 16, 2);
523 EXTRACT_HELPER(SHW
, 8, 2);
524 EXTRACT_HELPER(SP
, 19, 2);
525 /*****************************************************************************/
526 /* PowerPC instructions table */
528 #if defined(DO_PPC_STATISTICS)
529 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
539 .handler = &gen_##name, \
540 .oname = stringify(name), \
542 .oname = stringify(name), \
544 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
555 .handler = &gen_##name, \
556 .oname = stringify(name), \
558 .oname = stringify(name), \
560 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
570 .handler = &gen_##name, \
576 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
586 .handler = &gen_##name, \
588 .oname = stringify(name), \
590 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
601 .handler = &gen_##name, \
603 .oname = stringify(name), \
605 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
615 .handler = &gen_##name, \
621 /* SPR load/store helpers */
622 static inline void gen_load_spr(TCGv t
, int reg
)
624 tcg_gen_ld_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
627 static inline void gen_store_spr(int reg
, TCGv t
)
629 tcg_gen_st_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
632 /* Invalid instruction */
633 static void gen_invalid(DisasContext
*ctx
)
635 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
638 static opc_handler_t invalid_handler
= {
639 .inval1
= 0xFFFFFFFF,
640 .inval2
= 0xFFFFFFFF,
643 .handler
= gen_invalid
,
646 #if defined(TARGET_PPC64)
647 /* NOTE: as this time, the only use of is_user_mode() is in 64 bit code. And */
648 /* so the function is wrapped in the standard 64-bit ifdef in order to */
649 /* avoid compiler warnings in 32-bit implementations. */
650 static bool is_user_mode(DisasContext
*ctx
)
652 #if defined(CONFIG_USER_ONLY)
655 return ctx
->mem_idx
== 0;
660 /*** Integer comparison ***/
662 static inline void gen_op_cmp(TCGv arg0
, TCGv arg1
, int s
, int crf
)
664 TCGv t0
= tcg_temp_new();
665 TCGv_i32 t1
= tcg_temp_new_i32();
667 tcg_gen_trunc_tl_i32(cpu_crf
[crf
], cpu_so
);
669 tcg_gen_setcond_tl((s
? TCG_COND_LT
: TCG_COND_LTU
), t0
, arg0
, arg1
);
670 tcg_gen_trunc_tl_i32(t1
, t0
);
671 tcg_gen_shli_i32(t1
, t1
, CRF_LT
);
672 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
674 tcg_gen_setcond_tl((s
? TCG_COND_GT
: TCG_COND_GTU
), t0
, arg0
, arg1
);
675 tcg_gen_trunc_tl_i32(t1
, t0
);
676 tcg_gen_shli_i32(t1
, t1
, CRF_GT
);
677 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
679 tcg_gen_setcond_tl(TCG_COND_EQ
, t0
, arg0
, arg1
);
680 tcg_gen_trunc_tl_i32(t1
, t0
);
681 tcg_gen_shli_i32(t1
, t1
, CRF_EQ
);
682 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
685 tcg_temp_free_i32(t1
);
688 static inline void gen_op_cmpi(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
690 TCGv t0
= tcg_const_tl(arg1
);
691 gen_op_cmp(arg0
, t0
, s
, crf
);
695 static inline void gen_op_cmp32(TCGv arg0
, TCGv arg1
, int s
, int crf
)
701 tcg_gen_ext32s_tl(t0
, arg0
);
702 tcg_gen_ext32s_tl(t1
, arg1
);
704 tcg_gen_ext32u_tl(t0
, arg0
);
705 tcg_gen_ext32u_tl(t1
, arg1
);
707 gen_op_cmp(t0
, t1
, s
, crf
);
712 static inline void gen_op_cmpi32(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
714 TCGv t0
= tcg_const_tl(arg1
);
715 gen_op_cmp32(arg0
, t0
, s
, crf
);
719 static inline void gen_set_Rc0(DisasContext
*ctx
, TCGv reg
)
721 if (NARROW_MODE(ctx
)) {
722 gen_op_cmpi32(reg
, 0, 1, 0);
724 gen_op_cmpi(reg
, 0, 1, 0);
729 static void gen_cmp(DisasContext
*ctx
)
731 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
732 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
733 1, crfD(ctx
->opcode
));
735 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
736 1, crfD(ctx
->opcode
));
741 static void gen_cmpi(DisasContext
*ctx
)
743 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
744 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
745 1, crfD(ctx
->opcode
));
747 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
748 1, crfD(ctx
->opcode
));
753 static void gen_cmpl(DisasContext
*ctx
)
755 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
756 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
757 0, crfD(ctx
->opcode
));
759 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
760 0, crfD(ctx
->opcode
));
765 static void gen_cmpli(DisasContext
*ctx
)
767 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
768 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
769 0, crfD(ctx
->opcode
));
771 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
772 0, crfD(ctx
->opcode
));
776 /* isel (PowerPC 2.03 specification) */
777 static void gen_isel(DisasContext
*ctx
)
780 uint32_t bi
= rC(ctx
->opcode
);
784 l1
= gen_new_label();
785 l2
= gen_new_label();
787 mask
= 1 << (3 - (bi
& 0x03));
788 t0
= tcg_temp_new_i32();
789 tcg_gen_andi_i32(t0
, cpu_crf
[bi
>> 2], mask
);
790 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
791 if (rA(ctx
->opcode
) == 0)
792 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
794 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
797 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
799 tcg_temp_free_i32(t0
);
802 /* cmpb: PowerPC 2.05 specification */
803 static void gen_cmpb(DisasContext
*ctx
)
805 gen_helper_cmpb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
806 cpu_gpr
[rB(ctx
->opcode
)]);
809 /*** Integer arithmetic ***/
811 static inline void gen_op_arith_compute_ov(DisasContext
*ctx
, TCGv arg0
,
812 TCGv arg1
, TCGv arg2
, int sub
)
814 TCGv t0
= tcg_temp_new();
816 tcg_gen_xor_tl(cpu_ov
, arg0
, arg2
);
817 tcg_gen_xor_tl(t0
, arg1
, arg2
);
819 tcg_gen_and_tl(cpu_ov
, cpu_ov
, t0
);
821 tcg_gen_andc_tl(cpu_ov
, cpu_ov
, t0
);
824 if (NARROW_MODE(ctx
)) {
825 tcg_gen_ext32s_tl(cpu_ov
, cpu_ov
);
827 tcg_gen_shri_tl(cpu_ov
, cpu_ov
, TARGET_LONG_BITS
- 1);
828 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
831 /* Common add function */
832 static inline void gen_op_arith_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
833 TCGv arg2
, bool add_ca
, bool compute_ca
,
834 bool compute_ov
, bool compute_rc0
)
838 if (compute_ca
|| compute_ov
) {
843 if (NARROW_MODE(ctx
)) {
844 /* Caution: a non-obvious corner case of the spec is that we
845 must produce the *entire* 64-bit addition, but produce the
846 carry into bit 32. */
847 TCGv t1
= tcg_temp_new();
848 tcg_gen_xor_tl(t1
, arg1
, arg2
); /* add without carry */
849 tcg_gen_add_tl(t0
, arg1
, arg2
);
851 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
853 tcg_gen_xor_tl(cpu_ca
, t0
, t1
); /* bits changed w/ carry */
855 tcg_gen_shri_tl(cpu_ca
, cpu_ca
, 32); /* extract bit 32 */
856 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
858 TCGv zero
= tcg_const_tl(0);
860 tcg_gen_add2_tl(t0
, cpu_ca
, arg1
, zero
, cpu_ca
, zero
);
861 tcg_gen_add2_tl(t0
, cpu_ca
, t0
, cpu_ca
, arg2
, zero
);
863 tcg_gen_add2_tl(t0
, cpu_ca
, arg1
, zero
, arg2
, zero
);
868 tcg_gen_add_tl(t0
, arg1
, arg2
);
870 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
875 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 0);
877 if (unlikely(compute_rc0
)) {
878 gen_set_Rc0(ctx
, t0
);
881 if (!TCGV_EQUAL(t0
, ret
)) {
882 tcg_gen_mov_tl(ret
, t0
);
886 /* Add functions with two operands */
887 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
888 static void glue(gen_, name)(DisasContext *ctx) \
890 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
891 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
892 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
894 /* Add functions with one operand and one immediate */
895 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
896 add_ca, compute_ca, compute_ov) \
897 static void glue(gen_, name)(DisasContext *ctx) \
899 TCGv t0 = tcg_const_tl(const_val); \
900 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
901 cpu_gpr[rA(ctx->opcode)], t0, \
902 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
906 /* add add. addo addo. */
907 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
908 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
909 /* addc addc. addco addco. */
910 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
911 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
912 /* adde adde. addeo addeo. */
913 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
914 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
915 /* addme addme. addmeo addmeo. */
916 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
917 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
918 /* addze addze. addzeo addzeo.*/
919 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
920 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
922 static void gen_addi(DisasContext
*ctx
)
924 target_long simm
= SIMM(ctx
->opcode
);
926 if (rA(ctx
->opcode
) == 0) {
928 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
);
930 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)],
931 cpu_gpr
[rA(ctx
->opcode
)], simm
);
935 static inline void gen_op_addic(DisasContext
*ctx
, bool compute_rc0
)
937 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
938 gen_op_arith_add(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
939 c
, 0, 1, 0, compute_rc0
);
943 static void gen_addic(DisasContext
*ctx
)
945 gen_op_addic(ctx
, 0);
948 static void gen_addic_(DisasContext
*ctx
)
950 gen_op_addic(ctx
, 1);
954 static void gen_addis(DisasContext
*ctx
)
956 target_long simm
= SIMM(ctx
->opcode
);
958 if (rA(ctx
->opcode
) == 0) {
960 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
<< 16);
962 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)],
963 cpu_gpr
[rA(ctx
->opcode
)], simm
<< 16);
967 static inline void gen_op_arith_divw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
968 TCGv arg2
, int sign
, int compute_ov
)
970 int l1
= gen_new_label();
971 int l2
= gen_new_label();
972 TCGv_i32 t0
= tcg_temp_local_new_i32();
973 TCGv_i32 t1
= tcg_temp_local_new_i32();
975 tcg_gen_trunc_tl_i32(t0
, arg1
);
976 tcg_gen_trunc_tl_i32(t1
, arg2
);
977 tcg_gen_brcondi_i32(TCG_COND_EQ
, t1
, 0, l1
);
979 int l3
= gen_new_label();
980 tcg_gen_brcondi_i32(TCG_COND_NE
, t1
, -1, l3
);
981 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, INT32_MIN
, l1
);
983 tcg_gen_div_i32(t0
, t0
, t1
);
985 tcg_gen_divu_i32(t0
, t0
, t1
);
988 tcg_gen_movi_tl(cpu_ov
, 0);
993 tcg_gen_sari_i32(t0
, t0
, 31);
995 tcg_gen_movi_i32(t0
, 0);
998 tcg_gen_movi_tl(cpu_ov
, 1);
999 tcg_gen_movi_tl(cpu_so
, 1);
1002 tcg_gen_extu_i32_tl(ret
, t0
);
1003 tcg_temp_free_i32(t0
);
1004 tcg_temp_free_i32(t1
);
1005 if (unlikely(Rc(ctx
->opcode
) != 0))
1006 gen_set_Rc0(ctx
, ret
);
1009 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
1010 static void glue(gen_, name)(DisasContext *ctx) \
1012 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
1013 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1014 sign, compute_ov); \
1016 /* divwu divwu. divwuo divwuo. */
1017 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0);
1018 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1);
1019 /* divw divw. divwo divwo. */
1020 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0);
1021 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1);
1023 /* div[wd]eu[o][.] */
1024 #define GEN_DIVE(name, hlpr, compute_ov) \
1025 static void gen_##name(DisasContext *ctx) \
1027 TCGv_i32 t0 = tcg_const_i32(compute_ov); \
1028 gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1029 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \
1030 tcg_temp_free_i32(t0); \
1031 if (unlikely(Rc(ctx->opcode) != 0)) { \
1032 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1036 GEN_DIVE(divweu
, divweu
, 0);
1037 GEN_DIVE(divweuo
, divweu
, 1);
1038 GEN_DIVE(divwe
, divwe
, 0);
1039 GEN_DIVE(divweo
, divwe
, 1);
1041 #if defined(TARGET_PPC64)
1042 static inline void gen_op_arith_divd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1043 TCGv arg2
, int sign
, int compute_ov
)
1045 int l1
= gen_new_label();
1046 int l2
= gen_new_label();
1048 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg2
, 0, l1
);
1050 int l3
= gen_new_label();
1051 tcg_gen_brcondi_i64(TCG_COND_NE
, arg2
, -1, l3
);
1052 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg1
, INT64_MIN
, l1
);
1054 tcg_gen_div_i64(ret
, arg1
, arg2
);
1056 tcg_gen_divu_i64(ret
, arg1
, arg2
);
1059 tcg_gen_movi_tl(cpu_ov
, 0);
1064 tcg_gen_sari_i64(ret
, arg1
, 63);
1066 tcg_gen_movi_i64(ret
, 0);
1069 tcg_gen_movi_tl(cpu_ov
, 1);
1070 tcg_gen_movi_tl(cpu_so
, 1);
1073 if (unlikely(Rc(ctx
->opcode
) != 0))
1074 gen_set_Rc0(ctx
, ret
);
1076 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1077 static void glue(gen_, name)(DisasContext *ctx) \
1079 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1080 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1081 sign, compute_ov); \
1083 /* divwu divwu. divwuo divwuo. */
1084 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0);
1085 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1);
1086 /* divw divw. divwo divwo. */
1087 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0);
1088 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1);
1090 GEN_DIVE(divdeu
, divdeu
, 0);
1091 GEN_DIVE(divdeuo
, divdeu
, 1);
1092 GEN_DIVE(divde
, divde
, 0);
1093 GEN_DIVE(divdeo
, divde
, 1);
1097 static void gen_mulhw(DisasContext
*ctx
)
1099 TCGv_i32 t0
= tcg_temp_new_i32();
1100 TCGv_i32 t1
= tcg_temp_new_i32();
1102 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1103 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1104 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1105 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1106 tcg_temp_free_i32(t0
);
1107 tcg_temp_free_i32(t1
);
1108 if (unlikely(Rc(ctx
->opcode
) != 0))
1109 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1112 /* mulhwu mulhwu. */
1113 static void gen_mulhwu(DisasContext
*ctx
)
1115 TCGv_i32 t0
= tcg_temp_new_i32();
1116 TCGv_i32 t1
= tcg_temp_new_i32();
1118 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1119 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1120 tcg_gen_mulu2_i32(t0
, t1
, t0
, t1
);
1121 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1122 tcg_temp_free_i32(t0
);
1123 tcg_temp_free_i32(t1
);
1124 if (unlikely(Rc(ctx
->opcode
) != 0))
1125 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1129 static void gen_mullw(DisasContext
*ctx
)
1131 #if defined(TARGET_PPC64)
1133 t0
= tcg_temp_new_i64();
1134 t1
= tcg_temp_new_i64();
1135 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1136 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1137 tcg_gen_mul_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
1141 tcg_gen_mul_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1142 cpu_gpr
[rB(ctx
->opcode
)]);
1144 if (unlikely(Rc(ctx
->opcode
) != 0))
1145 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1148 /* mullwo mullwo. */
1149 static void gen_mullwo(DisasContext
*ctx
)
1151 TCGv_i32 t0
= tcg_temp_new_i32();
1152 TCGv_i32 t1
= tcg_temp_new_i32();
1154 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1155 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1156 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1157 #if defined(TARGET_PPC64)
1158 tcg_gen_concat_i32_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
1160 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1163 tcg_gen_sari_i32(t0
, t0
, 31);
1164 tcg_gen_setcond_i32(TCG_COND_NE
, t0
, t0
, t1
);
1165 tcg_gen_extu_i32_tl(cpu_ov
, t0
);
1166 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1168 tcg_temp_free_i32(t0
);
1169 tcg_temp_free_i32(t1
);
1170 if (unlikely(Rc(ctx
->opcode
) != 0))
1171 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1175 static void gen_mulli(DisasContext
*ctx
)
1177 tcg_gen_muli_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1181 #if defined(TARGET_PPC64)
1183 static void gen_mulhd(DisasContext
*ctx
)
1185 TCGv lo
= tcg_temp_new();
1186 tcg_gen_muls2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1187 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1189 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1190 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1194 /* mulhdu mulhdu. */
1195 static void gen_mulhdu(DisasContext
*ctx
)
1197 TCGv lo
= tcg_temp_new();
1198 tcg_gen_mulu2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1199 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1201 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1202 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1207 static void gen_mulld(DisasContext
*ctx
)
1209 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1210 cpu_gpr
[rB(ctx
->opcode
)]);
1211 if (unlikely(Rc(ctx
->opcode
) != 0))
1212 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1215 /* mulldo mulldo. */
1216 static void gen_mulldo(DisasContext
*ctx
)
1218 TCGv_i64 t0
= tcg_temp_new_i64();
1219 TCGv_i64 t1
= tcg_temp_new_i64();
1221 tcg_gen_muls2_i64(t0
, t1
, cpu_gpr
[rA(ctx
->opcode
)],
1222 cpu_gpr
[rB(ctx
->opcode
)]);
1223 tcg_gen_mov_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1225 tcg_gen_sari_i64(t0
, t0
, 63);
1226 tcg_gen_setcond_i64(TCG_COND_NE
, cpu_ov
, t0
, t1
);
1227 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1229 tcg_temp_free_i64(t0
);
1230 tcg_temp_free_i64(t1
);
1232 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1233 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1238 /* Common subf function */
1239 static inline void gen_op_arith_subf(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1240 TCGv arg2
, bool add_ca
, bool compute_ca
,
1241 bool compute_ov
, bool compute_rc0
)
1245 if (compute_ca
|| compute_ov
) {
1246 t0
= tcg_temp_new();
1250 /* dest = ~arg1 + arg2 [+ ca]. */
1251 if (NARROW_MODE(ctx
)) {
1252 /* Caution: a non-obvious corner case of the spec is that we
1253 must produce the *entire* 64-bit addition, but produce the
1254 carry into bit 32. */
1255 TCGv inv1
= tcg_temp_new();
1256 TCGv t1
= tcg_temp_new();
1257 tcg_gen_not_tl(inv1
, arg1
);
1259 tcg_gen_add_tl(t0
, arg2
, cpu_ca
);
1261 tcg_gen_addi_tl(t0
, arg2
, 1);
1263 tcg_gen_xor_tl(t1
, arg2
, inv1
); /* add without carry */
1264 tcg_gen_add_tl(t0
, t0
, inv1
);
1265 tcg_temp_free(inv1
);
1266 tcg_gen_xor_tl(cpu_ca
, t0
, t1
); /* bits changes w/ carry */
1268 tcg_gen_shri_tl(cpu_ca
, cpu_ca
, 32); /* extract bit 32 */
1269 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
1270 } else if (add_ca
) {
1271 TCGv zero
, inv1
= tcg_temp_new();
1272 tcg_gen_not_tl(inv1
, arg1
);
1273 zero
= tcg_const_tl(0);
1274 tcg_gen_add2_tl(t0
, cpu_ca
, arg2
, zero
, cpu_ca
, zero
);
1275 tcg_gen_add2_tl(t0
, cpu_ca
, t0
, cpu_ca
, inv1
, zero
);
1276 tcg_temp_free(zero
);
1277 tcg_temp_free(inv1
);
1279 tcg_gen_setcond_tl(TCG_COND_GEU
, cpu_ca
, arg2
, arg1
);
1280 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1282 } else if (add_ca
) {
1283 /* Since we're ignoring carry-out, we can simplify the
1284 standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1. */
1285 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1286 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
1287 tcg_gen_subi_tl(t0
, t0
, 1);
1289 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1293 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 1);
1295 if (unlikely(compute_rc0
)) {
1296 gen_set_Rc0(ctx
, t0
);
1299 if (!TCGV_EQUAL(t0
, ret
)) {
1300 tcg_gen_mov_tl(ret
, t0
);
1304 /* Sub functions with Two operands functions */
1305 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1306 static void glue(gen_, name)(DisasContext *ctx) \
1308 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1309 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1310 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1312 /* Sub functions with one operand and one immediate */
1313 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1314 add_ca, compute_ca, compute_ov) \
1315 static void glue(gen_, name)(DisasContext *ctx) \
1317 TCGv t0 = tcg_const_tl(const_val); \
1318 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1319 cpu_gpr[rA(ctx->opcode)], t0, \
1320 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1321 tcg_temp_free(t0); \
1323 /* subf subf. subfo subfo. */
1324 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
1325 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
1326 /* subfc subfc. subfco subfco. */
1327 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
1328 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
1329 /* subfe subfe. subfeo subfo. */
1330 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
1331 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
1332 /* subfme subfme. subfmeo subfmeo. */
1333 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
1334 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
1335 /* subfze subfze. subfzeo subfzeo.*/
1336 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
1337 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
1340 static void gen_subfic(DisasContext
*ctx
)
1342 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
1343 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1348 /* neg neg. nego nego. */
1349 static inline void gen_op_arith_neg(DisasContext
*ctx
, bool compute_ov
)
1351 TCGv zero
= tcg_const_tl(0);
1352 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1353 zero
, 0, 0, compute_ov
, Rc(ctx
->opcode
));
1354 tcg_temp_free(zero
);
1357 static void gen_neg(DisasContext
*ctx
)
1359 gen_op_arith_neg(ctx
, 0);
1362 static void gen_nego(DisasContext
*ctx
)
1364 gen_op_arith_neg(ctx
, 1);
1367 /*** Integer logical ***/
1368 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1369 static void glue(gen_, name)(DisasContext *ctx) \
1371 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1372 cpu_gpr[rB(ctx->opcode)]); \
1373 if (unlikely(Rc(ctx->opcode) != 0)) \
1374 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1377 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1378 static void glue(gen_, name)(DisasContext *ctx) \
1380 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1381 if (unlikely(Rc(ctx->opcode) != 0)) \
1382 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1386 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
);
1388 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
);
1391 static void gen_andi_(DisasContext
*ctx
)
1393 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
));
1394 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1398 static void gen_andis_(DisasContext
*ctx
)
1400 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
) << 16);
1401 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1405 static void gen_cntlzw(DisasContext
*ctx
)
1407 gen_helper_cntlzw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1408 if (unlikely(Rc(ctx
->opcode
) != 0))
1409 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1412 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
);
1413 /* extsb & extsb. */
1414 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
);
1415 /* extsh & extsh. */
1416 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
);
1418 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
);
1420 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
);
1423 static void gen_or(DisasContext
*ctx
)
1427 rs
= rS(ctx
->opcode
);
1428 ra
= rA(ctx
->opcode
);
1429 rb
= rB(ctx
->opcode
);
1430 /* Optimisation for mr. ri case */
1431 if (rs
!= ra
|| rs
!= rb
) {
1433 tcg_gen_or_tl(cpu_gpr
[ra
], cpu_gpr
[rs
], cpu_gpr
[rb
]);
1435 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rs
]);
1436 if (unlikely(Rc(ctx
->opcode
) != 0))
1437 gen_set_Rc0(ctx
, cpu_gpr
[ra
]);
1438 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
1439 gen_set_Rc0(ctx
, cpu_gpr
[rs
]);
1440 #if defined(TARGET_PPC64)
1446 /* Set process priority to low */
1450 /* Set process priority to medium-low */
1454 /* Set process priority to normal */
1457 #if !defined(CONFIG_USER_ONLY)
1459 if (ctx
->mem_idx
> 0) {
1460 /* Set process priority to very low */
1465 if (ctx
->mem_idx
> 0) {
1466 /* Set process priority to medium-hight */
1471 if (ctx
->mem_idx
> 0) {
1472 /* Set process priority to high */
1477 if (ctx
->mem_idx
> 1) {
1478 /* Set process priority to very high */
1488 TCGv t0
= tcg_temp_new();
1489 gen_load_spr(t0
, SPR_PPR
);
1490 tcg_gen_andi_tl(t0
, t0
, ~0x001C000000000000ULL
);
1491 tcg_gen_ori_tl(t0
, t0
, ((uint64_t)prio
) << 50);
1492 gen_store_spr(SPR_PPR
, t0
);
1499 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
);
1502 static void gen_xor(DisasContext
*ctx
)
1504 /* Optimisation for "set to zero" case */
1505 if (rS(ctx
->opcode
) != rB(ctx
->opcode
))
1506 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1508 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1509 if (unlikely(Rc(ctx
->opcode
) != 0))
1510 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1514 static void gen_ori(DisasContext
*ctx
)
1516 target_ulong uimm
= UIMM(ctx
->opcode
);
1518 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1520 /* XXX: should handle special NOPs for POWER series */
1523 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1527 static void gen_oris(DisasContext
*ctx
)
1529 target_ulong uimm
= UIMM(ctx
->opcode
);
1531 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1535 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1539 static void gen_xori(DisasContext
*ctx
)
1541 target_ulong uimm
= UIMM(ctx
->opcode
);
1543 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1547 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1551 static void gen_xoris(DisasContext
*ctx
)
1553 target_ulong uimm
= UIMM(ctx
->opcode
);
1555 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1559 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1562 /* popcntb : PowerPC 2.03 specification */
1563 static void gen_popcntb(DisasContext
*ctx
)
1565 gen_helper_popcntb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1568 static void gen_popcntw(DisasContext
*ctx
)
1570 gen_helper_popcntw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1573 #if defined(TARGET_PPC64)
1574 /* popcntd: PowerPC 2.06 specification */
1575 static void gen_popcntd(DisasContext
*ctx
)
1577 gen_helper_popcntd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1581 /* prtyw: PowerPC 2.05 specification */
1582 static void gen_prtyw(DisasContext
*ctx
)
1584 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
1585 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
1586 TCGv t0
= tcg_temp_new();
1587 tcg_gen_shri_tl(t0
, rs
, 16);
1588 tcg_gen_xor_tl(ra
, rs
, t0
);
1589 tcg_gen_shri_tl(t0
, ra
, 8);
1590 tcg_gen_xor_tl(ra
, ra
, t0
);
1591 tcg_gen_andi_tl(ra
, ra
, (target_ulong
)0x100000001ULL
);
1595 #if defined(TARGET_PPC64)
1596 /* prtyd: PowerPC 2.05 specification */
1597 static void gen_prtyd(DisasContext
*ctx
)
1599 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
1600 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
1601 TCGv t0
= tcg_temp_new();
1602 tcg_gen_shri_tl(t0
, rs
, 32);
1603 tcg_gen_xor_tl(ra
, rs
, t0
);
1604 tcg_gen_shri_tl(t0
, ra
, 16);
1605 tcg_gen_xor_tl(ra
, ra
, t0
);
1606 tcg_gen_shri_tl(t0
, ra
, 8);
1607 tcg_gen_xor_tl(ra
, ra
, t0
);
1608 tcg_gen_andi_tl(ra
, ra
, 1);
1613 #if defined(TARGET_PPC64)
1615 static void gen_bpermd(DisasContext
*ctx
)
1617 gen_helper_bpermd(cpu_gpr
[rA(ctx
->opcode
)],
1618 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1622 #if defined(TARGET_PPC64)
1623 /* extsw & extsw. */
1624 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
);
1627 static void gen_cntlzd(DisasContext
*ctx
)
1629 gen_helper_cntlzd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1630 if (unlikely(Rc(ctx
->opcode
) != 0))
1631 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1635 /*** Integer rotate ***/
1637 /* rlwimi & rlwimi. */
1638 static void gen_rlwimi(DisasContext
*ctx
)
1640 uint32_t mb
, me
, sh
;
1642 mb
= MB(ctx
->opcode
);
1643 me
= ME(ctx
->opcode
);
1644 sh
= SH(ctx
->opcode
);
1645 if (likely(sh
== (31-me
) && mb
<= me
)) {
1646 tcg_gen_deposit_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1647 cpu_gpr
[rS(ctx
->opcode
)], sh
, me
- mb
+ 1);
1651 TCGv t0
= tcg_temp_new();
1652 #if defined(TARGET_PPC64)
1653 tcg_gen_deposit_i64(t0
, cpu_gpr
[rS(ctx
->opcode
)],
1654 cpu_gpr
[rS(ctx
->opcode
)], 32, 32);
1655 tcg_gen_rotli_i64(t0
, t0
, sh
);
1657 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1659 #if defined(TARGET_PPC64)
1663 mask
= MASK(mb
, me
);
1664 t1
= tcg_temp_new();
1665 tcg_gen_andi_tl(t0
, t0
, mask
);
1666 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1667 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1671 if (unlikely(Rc(ctx
->opcode
) != 0))
1672 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1675 /* rlwinm & rlwinm. */
1676 static void gen_rlwinm(DisasContext
*ctx
)
1678 uint32_t mb
, me
, sh
;
1680 sh
= SH(ctx
->opcode
);
1681 mb
= MB(ctx
->opcode
);
1682 me
= ME(ctx
->opcode
);
1684 if (likely(mb
== 0 && me
== (31 - sh
))) {
1685 if (likely(sh
== 0)) {
1686 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1688 TCGv t0
= tcg_temp_new();
1689 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1690 tcg_gen_shli_tl(t0
, t0
, sh
);
1691 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1694 } else if (likely(sh
!= 0 && me
== 31 && sh
== (32 - mb
))) {
1695 TCGv t0
= tcg_temp_new();
1696 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1697 tcg_gen_shri_tl(t0
, t0
, mb
);
1698 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1700 } else if (likely(mb
== 0 && me
== 31)) {
1701 TCGv_i32 t0
= tcg_temp_new_i32();
1702 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1703 tcg_gen_rotli_i32(t0
, t0
, sh
);
1704 tcg_gen_extu_i32_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1705 tcg_temp_free_i32(t0
);
1707 TCGv t0
= tcg_temp_new();
1708 #if defined(TARGET_PPC64)
1709 tcg_gen_deposit_i64(t0
, cpu_gpr
[rS(ctx
->opcode
)],
1710 cpu_gpr
[rS(ctx
->opcode
)], 32, 32);
1711 tcg_gen_rotli_i64(t0
, t0
, sh
);
1713 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1715 #if defined(TARGET_PPC64)
1719 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1722 if (unlikely(Rc(ctx
->opcode
) != 0))
1723 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1726 /* rlwnm & rlwnm. */
1727 static void gen_rlwnm(DisasContext
*ctx
)
1730 mb
= MB(ctx
->opcode
);
1731 me
= ME(ctx
->opcode
);
1733 if (likely(mb
== 0 && me
== 31)) {
1735 t0
= tcg_temp_new_i32();
1736 t1
= tcg_temp_new_i32();
1737 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
1738 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1739 tcg_gen_andi_i32(t0
, t0
, 0x1f);
1740 tcg_gen_rotl_i32(t1
, t1
, t0
);
1741 tcg_gen_extu_i32_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
);
1742 tcg_temp_free_i32(t0
);
1743 tcg_temp_free_i32(t1
);
1746 #if defined(TARGET_PPC64)
1750 t0
= tcg_temp_new();
1751 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1752 #if defined(TARGET_PPC64)
1753 t1
= tcg_temp_new_i64();
1754 tcg_gen_deposit_i64(t1
, cpu_gpr
[rS(ctx
->opcode
)],
1755 cpu_gpr
[rS(ctx
->opcode
)], 32, 32);
1756 tcg_gen_rotl_i64(t0
, t1
, t0
);
1757 tcg_temp_free_i64(t1
);
1759 tcg_gen_rotl_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1761 if (unlikely(mb
!= 0 || me
!= 31)) {
1762 #if defined(TARGET_PPC64)
1766 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1768 tcg_gen_andi_tl(t0
, t0
, MASK(32, 63));
1769 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1773 if (unlikely(Rc(ctx
->opcode
) != 0))
1774 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1777 #if defined(TARGET_PPC64)
1778 #define GEN_PPC64_R2(name, opc1, opc2) \
1779 static void glue(gen_, name##0)(DisasContext *ctx) \
1781 gen_##name(ctx, 0); \
1784 static void glue(gen_, name##1)(DisasContext *ctx) \
1786 gen_##name(ctx, 1); \
1788 #define GEN_PPC64_R4(name, opc1, opc2) \
1789 static void glue(gen_, name##0)(DisasContext *ctx) \
1791 gen_##name(ctx, 0, 0); \
1794 static void glue(gen_, name##1)(DisasContext *ctx) \
1796 gen_##name(ctx, 0, 1); \
1799 static void glue(gen_, name##2)(DisasContext *ctx) \
1801 gen_##name(ctx, 1, 0); \
1804 static void glue(gen_, name##3)(DisasContext *ctx) \
1806 gen_##name(ctx, 1, 1); \
1809 static inline void gen_rldinm(DisasContext
*ctx
, uint32_t mb
, uint32_t me
,
1812 if (likely(sh
!= 0 && mb
== 0 && me
== (63 - sh
))) {
1813 tcg_gen_shli_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
1814 } else if (likely(sh
!= 0 && me
== 63 && sh
== (64 - mb
))) {
1815 tcg_gen_shri_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], mb
);
1817 TCGv t0
= tcg_temp_new();
1818 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1819 if (likely(mb
== 0 && me
== 63)) {
1820 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1822 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1826 if (unlikely(Rc(ctx
->opcode
) != 0))
1827 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1829 /* rldicl - rldicl. */
1830 static inline void gen_rldicl(DisasContext
*ctx
, int mbn
, int shn
)
1834 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1835 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1836 gen_rldinm(ctx
, mb
, 63, sh
);
1838 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
1839 /* rldicr - rldicr. */
1840 static inline void gen_rldicr(DisasContext
*ctx
, int men
, int shn
)
1844 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1845 me
= MB(ctx
->opcode
) | (men
<< 5);
1846 gen_rldinm(ctx
, 0, me
, sh
);
1848 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
1849 /* rldic - rldic. */
1850 static inline void gen_rldic(DisasContext
*ctx
, int mbn
, int shn
)
1854 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1855 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1856 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
1858 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
1860 static inline void gen_rldnm(DisasContext
*ctx
, uint32_t mb
, uint32_t me
)
1864 t0
= tcg_temp_new();
1865 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1866 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1867 if (unlikely(mb
!= 0 || me
!= 63)) {
1868 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1870 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1873 if (unlikely(Rc(ctx
->opcode
) != 0))
1874 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1877 /* rldcl - rldcl. */
1878 static inline void gen_rldcl(DisasContext
*ctx
, int mbn
)
1882 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1883 gen_rldnm(ctx
, mb
, 63);
1885 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
1886 /* rldcr - rldcr. */
1887 static inline void gen_rldcr(DisasContext
*ctx
, int men
)
1891 me
= MB(ctx
->opcode
) | (men
<< 5);
1892 gen_rldnm(ctx
, 0, me
);
1894 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
1895 /* rldimi - rldimi. */
1896 static inline void gen_rldimi(DisasContext
*ctx
, int mbn
, int shn
)
1898 uint32_t sh
, mb
, me
;
1900 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1901 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1903 if (unlikely(sh
== 0 && mb
== 0)) {
1904 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1909 t0
= tcg_temp_new();
1910 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1911 t1
= tcg_temp_new();
1912 mask
= MASK(mb
, me
);
1913 tcg_gen_andi_tl(t0
, t0
, mask
);
1914 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1915 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1919 if (unlikely(Rc(ctx
->opcode
) != 0))
1920 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1922 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
1925 /*** Integer shift ***/
1928 static void gen_slw(DisasContext
*ctx
)
1932 t0
= tcg_temp_new();
1933 /* AND rS with a mask that is 0 when rB >= 0x20 */
1934 #if defined(TARGET_PPC64)
1935 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
1936 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1938 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
1939 tcg_gen_sari_tl(t0
, t0
, 0x1f);
1941 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1942 t1
= tcg_temp_new();
1943 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1944 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1947 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
1948 if (unlikely(Rc(ctx
->opcode
) != 0))
1949 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1953 static void gen_sraw(DisasContext
*ctx
)
1955 gen_helper_sraw(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
1956 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1957 if (unlikely(Rc(ctx
->opcode
) != 0))
1958 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1961 /* srawi & srawi. */
1962 static void gen_srawi(DisasContext
*ctx
)
1964 int sh
= SH(ctx
->opcode
);
1965 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
1966 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
1968 tcg_gen_ext32s_tl(dst
, src
);
1969 tcg_gen_movi_tl(cpu_ca
, 0);
1972 tcg_gen_ext32s_tl(dst
, src
);
1973 tcg_gen_andi_tl(cpu_ca
, dst
, (1ULL << sh
) - 1);
1974 t0
= tcg_temp_new();
1975 tcg_gen_sari_tl(t0
, dst
, TARGET_LONG_BITS
- 1);
1976 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
1978 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
1979 tcg_gen_sari_tl(dst
, dst
, sh
);
1981 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1982 gen_set_Rc0(ctx
, dst
);
1987 static void gen_srw(DisasContext
*ctx
)
1991 t0
= tcg_temp_new();
1992 /* AND rS with a mask that is 0 when rB >= 0x20 */
1993 #if defined(TARGET_PPC64)
1994 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
1995 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1997 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
1998 tcg_gen_sari_tl(t0
, t0
, 0x1f);
2000 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2001 tcg_gen_ext32u_tl(t0
, t0
);
2002 t1
= tcg_temp_new();
2003 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
2004 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2007 if (unlikely(Rc(ctx
->opcode
) != 0))
2008 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2011 #if defined(TARGET_PPC64)
2013 static void gen_sld(DisasContext
*ctx
)
2017 t0
= tcg_temp_new();
2018 /* AND rS with a mask that is 0 when rB >= 0x40 */
2019 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
2020 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2021 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2022 t1
= tcg_temp_new();
2023 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
2024 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2027 if (unlikely(Rc(ctx
->opcode
) != 0))
2028 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2032 static void gen_srad(DisasContext
*ctx
)
2034 gen_helper_srad(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
2035 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2036 if (unlikely(Rc(ctx
->opcode
) != 0))
2037 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2039 /* sradi & sradi. */
2040 static inline void gen_sradi(DisasContext
*ctx
, int n
)
2042 int sh
= SH(ctx
->opcode
) + (n
<< 5);
2043 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
2044 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
2046 tcg_gen_mov_tl(dst
, src
);
2047 tcg_gen_movi_tl(cpu_ca
, 0);
2050 tcg_gen_andi_tl(cpu_ca
, src
, (1ULL << sh
) - 1);
2051 t0
= tcg_temp_new();
2052 tcg_gen_sari_tl(t0
, src
, TARGET_LONG_BITS
- 1);
2053 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
2055 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
2056 tcg_gen_sari_tl(dst
, src
, sh
);
2058 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2059 gen_set_Rc0(ctx
, dst
);
2063 static void gen_sradi0(DisasContext
*ctx
)
2068 static void gen_sradi1(DisasContext
*ctx
)
2074 static void gen_srd(DisasContext
*ctx
)
2078 t0
= tcg_temp_new();
2079 /* AND rS with a mask that is 0 when rB >= 0x40 */
2080 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
2081 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2082 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2083 t1
= tcg_temp_new();
2084 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
2085 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2088 if (unlikely(Rc(ctx
->opcode
) != 0))
2089 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2093 /*** Floating-Point arithmetic ***/
2094 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
2095 static void gen_f##name(DisasContext *ctx) \
2097 if (unlikely(!ctx->fpu_enabled)) { \
2098 gen_exception(ctx, POWERPC_EXCP_FPU); \
2101 /* NIP cannot be restored if the memory exception comes from an helper */ \
2102 gen_update_nip(ctx, ctx->nip - 4); \
2103 gen_reset_fpstatus(); \
2104 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2105 cpu_fpr[rA(ctx->opcode)], \
2106 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2108 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2109 cpu_fpr[rD(ctx->opcode)]); \
2111 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \
2112 Rc(ctx->opcode) != 0); \
2115 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2116 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2117 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
2119 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2120 static void gen_f##name(DisasContext *ctx) \
2122 if (unlikely(!ctx->fpu_enabled)) { \
2123 gen_exception(ctx, POWERPC_EXCP_FPU); \
2126 /* NIP cannot be restored if the memory exception comes from an helper */ \
2127 gen_update_nip(ctx, ctx->nip - 4); \
2128 gen_reset_fpstatus(); \
2129 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2130 cpu_fpr[rA(ctx->opcode)], \
2131 cpu_fpr[rB(ctx->opcode)]); \
2133 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2134 cpu_fpr[rD(ctx->opcode)]); \
2136 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2137 set_fprf, Rc(ctx->opcode) != 0); \
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)]); \
2160 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2161 set_fprf, Rc(ctx->opcode) != 0); \
2163 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2164 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2165 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2167 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
2168 static void gen_f##name(DisasContext *ctx) \
2170 if (unlikely(!ctx->fpu_enabled)) { \
2171 gen_exception(ctx, POWERPC_EXCP_FPU); \
2174 /* NIP cannot be restored if the memory exception comes from an helper */ \
2175 gen_update_nip(ctx, ctx->nip - 4); \
2176 gen_reset_fpstatus(); \
2177 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2178 cpu_fpr[rB(ctx->opcode)]); \
2179 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2180 set_fprf, Rc(ctx->opcode) != 0); \
2183 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
2184 static void gen_f##name(DisasContext *ctx) \
2186 if (unlikely(!ctx->fpu_enabled)) { \
2187 gen_exception(ctx, POWERPC_EXCP_FPU); \
2190 /* NIP cannot be restored if the memory exception comes from an helper */ \
2191 gen_update_nip(ctx, ctx->nip - 4); \
2192 gen_reset_fpstatus(); \
2193 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2194 cpu_fpr[rB(ctx->opcode)]); \
2195 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2196 set_fprf, Rc(ctx->opcode) != 0); \
2200 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
);
2202 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
);
2204 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
);
2207 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
);
2210 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
);
2213 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
);
2216 static void gen_frsqrtes(DisasContext
*ctx
)
2218 if (unlikely(!ctx
->fpu_enabled
)) {
2219 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2222 /* NIP cannot be restored if the memory exception comes from an helper */
2223 gen_update_nip(ctx
, ctx
->nip
- 4);
2224 gen_reset_fpstatus();
2225 gen_helper_frsqrte(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2226 cpu_fpr
[rB(ctx
->opcode
)]);
2227 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2228 cpu_fpr
[rD(ctx
->opcode
)]);
2229 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2233 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
);
2235 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
);
2239 static void gen_fsqrt(DisasContext
*ctx
)
2241 if (unlikely(!ctx
->fpu_enabled
)) {
2242 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2245 /* NIP cannot be restored if the memory exception comes from an helper */
2246 gen_update_nip(ctx
, ctx
->nip
- 4);
2247 gen_reset_fpstatus();
2248 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2249 cpu_fpr
[rB(ctx
->opcode
)]);
2250 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2253 static void gen_fsqrts(DisasContext
*ctx
)
2255 if (unlikely(!ctx
->fpu_enabled
)) {
2256 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2259 /* NIP cannot be restored if the memory exception comes from an helper */
2260 gen_update_nip(ctx
, ctx
->nip
- 4);
2261 gen_reset_fpstatus();
2262 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2263 cpu_fpr
[rB(ctx
->opcode
)]);
2264 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2265 cpu_fpr
[rD(ctx
->opcode
)]);
2266 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2269 /*** Floating-Point multiply-and-add ***/
2270 /* fmadd - fmadds */
2271 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
);
2272 /* fmsub - fmsubs */
2273 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
);
2274 /* fnmadd - fnmadds */
2275 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
);
2276 /* fnmsub - fnmsubs */
2277 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
);
2279 /*** Floating-Point round & convert ***/
2281 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
);
2283 GEN_FLOAT_B(ctiwu
, 0x0E, 0x04, 0, PPC2_FP_CVT_ISA206
);
2285 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
);
2287 GEN_FLOAT_B(ctiwuz
, 0x0F, 0x04, 0, PPC2_FP_CVT_ISA206
);
2289 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
);
2290 #if defined(TARGET_PPC64)
2292 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
);
2294 GEN_FLOAT_B(cfids
, 0x0E, 0x1A, 0, PPC2_FP_CVT_ISA206
);
2296 GEN_FLOAT_B(cfidu
, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206
);
2298 GEN_FLOAT_B(cfidus
, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206
);
2300 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
);
2302 GEN_FLOAT_B(ctidu
, 0x0E, 0x1D, 0, PPC2_FP_CVT_ISA206
);
2304 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
);
2306 GEN_FLOAT_B(ctiduz
, 0x0F, 0x1D, 0, PPC2_FP_CVT_ISA206
);
2310 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
);
2312 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
);
2314 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
);
2316 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
);
2318 static void gen_ftdiv(DisasContext
*ctx
)
2320 if (unlikely(!ctx
->fpu_enabled
)) {
2321 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2324 gen_helper_ftdiv(cpu_crf
[crfD(ctx
->opcode
)], cpu_fpr
[rA(ctx
->opcode
)],
2325 cpu_fpr
[rB(ctx
->opcode
)]);
2328 static void gen_ftsqrt(DisasContext
*ctx
)
2330 if (unlikely(!ctx
->fpu_enabled
)) {
2331 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2334 gen_helper_ftsqrt(cpu_crf
[crfD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2339 /*** Floating-Point compare ***/
2342 static void gen_fcmpo(DisasContext
*ctx
)
2345 if (unlikely(!ctx
->fpu_enabled
)) {
2346 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2349 /* NIP cannot be restored if the memory exception comes from an helper */
2350 gen_update_nip(ctx
, ctx
->nip
- 4);
2351 gen_reset_fpstatus();
2352 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2353 gen_helper_fcmpo(cpu_env
, cpu_fpr
[rA(ctx
->opcode
)],
2354 cpu_fpr
[rB(ctx
->opcode
)], crf
);
2355 tcg_temp_free_i32(crf
);
2356 gen_helper_float_check_status(cpu_env
);
2360 static void gen_fcmpu(DisasContext
*ctx
)
2363 if (unlikely(!ctx
->fpu_enabled
)) {
2364 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2367 /* NIP cannot be restored if the memory exception comes from an helper */
2368 gen_update_nip(ctx
, ctx
->nip
- 4);
2369 gen_reset_fpstatus();
2370 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2371 gen_helper_fcmpu(cpu_env
, cpu_fpr
[rA(ctx
->opcode
)],
2372 cpu_fpr
[rB(ctx
->opcode
)], crf
);
2373 tcg_temp_free_i32(crf
);
2374 gen_helper_float_check_status(cpu_env
);
2377 /*** Floating-point move ***/
2379 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2380 static void gen_fabs(DisasContext
*ctx
)
2382 if (unlikely(!ctx
->fpu_enabled
)) {
2383 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2386 tcg_gen_andi_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)],
2388 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2392 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2393 static void gen_fmr(DisasContext
*ctx
)
2395 if (unlikely(!ctx
->fpu_enabled
)) {
2396 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2399 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2400 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2404 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2405 static void gen_fnabs(DisasContext
*ctx
)
2407 if (unlikely(!ctx
->fpu_enabled
)) {
2408 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2411 tcg_gen_ori_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)],
2413 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2417 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2418 static void gen_fneg(DisasContext
*ctx
)
2420 if (unlikely(!ctx
->fpu_enabled
)) {
2421 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2424 tcg_gen_xori_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)],
2426 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2429 /* fcpsgn: PowerPC 2.05 specification */
2430 /* XXX: beware that fcpsgn never checks for NaNs nor update FPSCR */
2431 static void gen_fcpsgn(DisasContext
*ctx
)
2433 if (unlikely(!ctx
->fpu_enabled
)) {
2434 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2437 tcg_gen_deposit_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rA(ctx
->opcode
)],
2438 cpu_fpr
[rB(ctx
->opcode
)], 0, 63);
2439 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2442 static void gen_fmrgew(DisasContext
*ctx
)
2445 if (unlikely(!ctx
->fpu_enabled
)) {
2446 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2449 b0
= tcg_temp_new_i64();
2450 tcg_gen_shri_i64(b0
, cpu_fpr
[rB(ctx
->opcode
)], 32);
2451 tcg_gen_deposit_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rA(ctx
->opcode
)],
2453 tcg_temp_free_i64(b0
);
2456 static void gen_fmrgow(DisasContext
*ctx
)
2458 if (unlikely(!ctx
->fpu_enabled
)) {
2459 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2462 tcg_gen_deposit_i64(cpu_fpr
[rD(ctx
->opcode
)],
2463 cpu_fpr
[rB(ctx
->opcode
)],
2464 cpu_fpr
[rA(ctx
->opcode
)],
2468 /*** Floating-Point status & ctrl register ***/
2471 static void gen_mcrfs(DisasContext
*ctx
)
2473 TCGv tmp
= tcg_temp_new();
2476 if (unlikely(!ctx
->fpu_enabled
)) {
2477 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2480 bfa
= 4 * (7 - crfS(ctx
->opcode
));
2481 tcg_gen_shri_tl(tmp
, cpu_fpscr
, bfa
);
2482 tcg_gen_trunc_tl_i32(cpu_crf
[crfD(ctx
->opcode
)], tmp
);
2484 tcg_gen_andi_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfD(ctx
->opcode
)], 0xf);
2485 tcg_gen_andi_tl(cpu_fpscr
, cpu_fpscr
, ~(0xF << bfa
));
2489 static void gen_mffs(DisasContext
*ctx
)
2491 if (unlikely(!ctx
->fpu_enabled
)) {
2492 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2495 gen_reset_fpstatus();
2496 tcg_gen_extu_tl_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpscr
);
2497 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2501 static void gen_mtfsb0(DisasContext
*ctx
)
2505 if (unlikely(!ctx
->fpu_enabled
)) {
2506 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2509 crb
= 31 - crbD(ctx
->opcode
);
2510 gen_reset_fpstatus();
2511 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
)) {
2513 /* NIP cannot be restored if the memory exception comes from an helper */
2514 gen_update_nip(ctx
, ctx
->nip
- 4);
2515 t0
= tcg_const_i32(crb
);
2516 gen_helper_fpscr_clrbit(cpu_env
, t0
);
2517 tcg_temp_free_i32(t0
);
2519 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2520 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2521 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2526 static void gen_mtfsb1(DisasContext
*ctx
)
2530 if (unlikely(!ctx
->fpu_enabled
)) {
2531 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2534 crb
= 31 - crbD(ctx
->opcode
);
2535 gen_reset_fpstatus();
2536 /* XXX: we pretend we can only do IEEE floating-point computations */
2537 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
&& crb
!= FPSCR_NI
)) {
2539 /* NIP cannot be restored if the memory exception comes from an helper */
2540 gen_update_nip(ctx
, ctx
->nip
- 4);
2541 t0
= tcg_const_i32(crb
);
2542 gen_helper_fpscr_setbit(cpu_env
, t0
);
2543 tcg_temp_free_i32(t0
);
2545 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2546 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2547 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2549 /* We can raise a differed exception */
2550 gen_helper_float_check_status(cpu_env
);
2554 static void gen_mtfsf(DisasContext
*ctx
)
2559 if (unlikely(!ctx
->fpu_enabled
)) {
2560 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2563 flm
= FPFLM(ctx
->opcode
);
2564 l
= FPL(ctx
->opcode
);
2565 w
= FPW(ctx
->opcode
);
2566 if (unlikely(w
& !(ctx
->insns_flags2
& PPC2_ISA205
))) {
2567 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2570 /* NIP cannot be restored if the memory exception comes from an helper */
2571 gen_update_nip(ctx
, ctx
->nip
- 4);
2572 gen_reset_fpstatus();
2574 t0
= tcg_const_i32((ctx
->insns_flags2
& PPC2_ISA205
) ? 0xffff : 0xff);
2576 t0
= tcg_const_i32(flm
<< (w
* 8));
2578 gen_helper_store_fpscr(cpu_env
, cpu_fpr
[rB(ctx
->opcode
)], t0
);
2579 tcg_temp_free_i32(t0
);
2580 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2581 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2582 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2584 /* We can raise a differed exception */
2585 gen_helper_float_check_status(cpu_env
);
2589 static void gen_mtfsfi(DisasContext
*ctx
)
2595 if (unlikely(!ctx
->fpu_enabled
)) {
2596 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2599 w
= FPW(ctx
->opcode
);
2600 bf
= FPBF(ctx
->opcode
);
2601 if (unlikely(w
& !(ctx
->insns_flags2
& PPC2_ISA205
))) {
2602 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2605 sh
= (8 * w
) + 7 - bf
;
2606 /* NIP cannot be restored if the memory exception comes from an helper */
2607 gen_update_nip(ctx
, ctx
->nip
- 4);
2608 gen_reset_fpstatus();
2609 t0
= tcg_const_i64(((uint64_t)FPIMM(ctx
->opcode
)) << (4 * sh
));
2610 t1
= tcg_const_i32(1 << sh
);
2611 gen_helper_store_fpscr(cpu_env
, t0
, t1
);
2612 tcg_temp_free_i64(t0
);
2613 tcg_temp_free_i32(t1
);
2614 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2615 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2616 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2618 /* We can raise a differed exception */
2619 gen_helper_float_check_status(cpu_env
);
2622 /*** Addressing modes ***/
2623 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2624 static inline void gen_addr_imm_index(DisasContext
*ctx
, TCGv EA
,
2627 target_long simm
= SIMM(ctx
->opcode
);
2630 if (rA(ctx
->opcode
) == 0) {
2631 if (NARROW_MODE(ctx
)) {
2632 simm
= (uint32_t)simm
;
2634 tcg_gen_movi_tl(EA
, simm
);
2635 } else if (likely(simm
!= 0)) {
2636 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
);
2637 if (NARROW_MODE(ctx
)) {
2638 tcg_gen_ext32u_tl(EA
, EA
);
2641 if (NARROW_MODE(ctx
)) {
2642 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2644 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2649 static inline void gen_addr_reg_index(DisasContext
*ctx
, TCGv EA
)
2651 if (rA(ctx
->opcode
) == 0) {
2652 if (NARROW_MODE(ctx
)) {
2653 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2655 tcg_gen_mov_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2658 tcg_gen_add_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2659 if (NARROW_MODE(ctx
)) {
2660 tcg_gen_ext32u_tl(EA
, EA
);
2665 static inline void gen_addr_register(DisasContext
*ctx
, TCGv EA
)
2667 if (rA(ctx
->opcode
) == 0) {
2668 tcg_gen_movi_tl(EA
, 0);
2669 } else if (NARROW_MODE(ctx
)) {
2670 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2672 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2676 static inline void gen_addr_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
2679 tcg_gen_addi_tl(ret
, arg1
, val
);
2680 if (NARROW_MODE(ctx
)) {
2681 tcg_gen_ext32u_tl(ret
, ret
);
2685 static inline void gen_check_align(DisasContext
*ctx
, TCGv EA
, int mask
)
2687 int l1
= gen_new_label();
2688 TCGv t0
= tcg_temp_new();
2690 /* NIP cannot be restored if the memory exception comes from an helper */
2691 gen_update_nip(ctx
, ctx
->nip
- 4);
2692 tcg_gen_andi_tl(t0
, EA
, mask
);
2693 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2694 t1
= tcg_const_i32(POWERPC_EXCP_ALIGN
);
2695 t2
= tcg_const_i32(0);
2696 gen_helper_raise_exception_err(cpu_env
, t1
, t2
);
2697 tcg_temp_free_i32(t1
);
2698 tcg_temp_free_i32(t2
);
2703 /*** Integer load ***/
2704 static inline void gen_qemu_ld8u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2706 tcg_gen_qemu_ld8u(arg1
, arg2
, ctx
->mem_idx
);
2709 static inline void gen_qemu_ld16u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2711 TCGMemOp op
= MO_UW
| ctx
->default_tcg_memop_mask
;
2712 tcg_gen_qemu_ld_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
2715 static inline void gen_qemu_ld16s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2717 TCGMemOp op
= MO_SW
| ctx
->default_tcg_memop_mask
;
2718 tcg_gen_qemu_ld_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
2721 static inline void gen_qemu_ld32u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2723 TCGMemOp op
= MO_UL
| ctx
->default_tcg_memop_mask
;
2724 tcg_gen_qemu_ld_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
2727 static void gen_qemu_ld32u_i64(DisasContext
*ctx
, TCGv_i64 val
, TCGv addr
)
2729 TCGv tmp
= tcg_temp_new();
2730 gen_qemu_ld32u(ctx
, tmp
, addr
);
2731 tcg_gen_extu_tl_i64(val
, tmp
);
2735 static inline void gen_qemu_ld32s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2737 TCGMemOp op
= MO_SL
| ctx
->default_tcg_memop_mask
;
2738 tcg_gen_qemu_ld_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
2741 static void gen_qemu_ld32s_i64(DisasContext
*ctx
, TCGv_i64 val
, TCGv addr
)
2743 TCGv tmp
= tcg_temp_new();
2744 gen_qemu_ld32s(ctx
, tmp
, addr
);
2745 tcg_gen_ext_tl_i64(val
, tmp
);
2749 static inline void gen_qemu_ld64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2751 TCGMemOp op
= MO_Q
| ctx
->default_tcg_memop_mask
;
2752 tcg_gen_qemu_ld_i64(arg1
, arg2
, ctx
->mem_idx
, op
);
2755 static inline void gen_qemu_st8(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2757 tcg_gen_qemu_st8(arg1
, arg2
, ctx
->mem_idx
);
2760 static inline void gen_qemu_st16(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2762 TCGMemOp op
= MO_UW
| ctx
->default_tcg_memop_mask
;
2763 tcg_gen_qemu_st_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
2766 static inline void gen_qemu_st32(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2768 TCGMemOp op
= MO_UL
| ctx
->default_tcg_memop_mask
;
2769 tcg_gen_qemu_st_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
2772 static void gen_qemu_st32_i64(DisasContext
*ctx
, TCGv_i64 val
, TCGv addr
)
2774 TCGv tmp
= tcg_temp_new();
2775 tcg_gen_trunc_i64_tl(tmp
, val
);
2776 gen_qemu_st32(ctx
, tmp
, addr
);
2780 static inline void gen_qemu_st64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2782 TCGMemOp op
= MO_Q
| ctx
->default_tcg_memop_mask
;
2783 tcg_gen_qemu_st_i64(arg1
, arg2
, ctx
->mem_idx
, op
);
2786 #define GEN_LD(name, ldop, opc, type) \
2787 static void glue(gen_, name)(DisasContext *ctx) \
2790 gen_set_access_type(ctx, ACCESS_INT); \
2791 EA = tcg_temp_new(); \
2792 gen_addr_imm_index(ctx, EA, 0); \
2793 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2794 tcg_temp_free(EA); \
2797 #define GEN_LDU(name, ldop, opc, type) \
2798 static void glue(gen_, name##u)(DisasContext *ctx) \
2801 if (unlikely(rA(ctx->opcode) == 0 || \
2802 rA(ctx->opcode) == rD(ctx->opcode))) { \
2803 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2806 gen_set_access_type(ctx, ACCESS_INT); \
2807 EA = tcg_temp_new(); \
2808 if (type == PPC_64B) \
2809 gen_addr_imm_index(ctx, EA, 0x03); \
2811 gen_addr_imm_index(ctx, EA, 0); \
2812 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2813 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2814 tcg_temp_free(EA); \
2817 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
2818 static void glue(gen_, name##ux)(DisasContext *ctx) \
2821 if (unlikely(rA(ctx->opcode) == 0 || \
2822 rA(ctx->opcode) == rD(ctx->opcode))) { \
2823 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2826 gen_set_access_type(ctx, ACCESS_INT); \
2827 EA = tcg_temp_new(); \
2828 gen_addr_reg_index(ctx, EA); \
2829 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2830 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2831 tcg_temp_free(EA); \
2834 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
2835 static void glue(gen_, name##x)(DisasContext *ctx) \
2838 gen_set_access_type(ctx, ACCESS_INT); \
2839 EA = tcg_temp_new(); \
2840 gen_addr_reg_index(ctx, EA); \
2841 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2842 tcg_temp_free(EA); \
2844 #define GEN_LDX(name, ldop, opc2, opc3, type) \
2845 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE)
2847 #define GEN_LDS(name, ldop, op, type) \
2848 GEN_LD(name, ldop, op | 0x20, type); \
2849 GEN_LDU(name, ldop, op | 0x21, type); \
2850 GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2851 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
2853 /* lbz lbzu lbzux lbzx */
2854 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
);
2855 /* lha lhau lhaux lhax */
2856 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
);
2857 /* lhz lhzu lhzux lhzx */
2858 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
);
2859 /* lwz lwzu lwzux lwzx */
2860 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
);
2861 #if defined(TARGET_PPC64)
2863 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
);
2865 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
);
2867 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
);
2869 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
);
2871 static void gen_ld(DisasContext
*ctx
)
2874 if (Rc(ctx
->opcode
)) {
2875 if (unlikely(rA(ctx
->opcode
) == 0 ||
2876 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
2877 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2881 gen_set_access_type(ctx
, ACCESS_INT
);
2882 EA
= tcg_temp_new();
2883 gen_addr_imm_index(ctx
, EA
, 0x03);
2884 if (ctx
->opcode
& 0x02) {
2885 /* lwa (lwau is undefined) */
2886 gen_qemu_ld32s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2889 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2891 if (Rc(ctx
->opcode
))
2892 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2897 static void gen_lq(DisasContext
*ctx
)
2902 /* lq is a legal user mode instruction starting in ISA 2.07 */
2903 bool legal_in_user_mode
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
2904 bool le_is_supported
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
2906 if (!legal_in_user_mode
&& is_user_mode(ctx
)) {
2907 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2911 if (!le_is_supported
&& ctx
->le_mode
) {
2912 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2916 ra
= rA(ctx
->opcode
);
2917 rd
= rD(ctx
->opcode
);
2918 if (unlikely((rd
& 1) || rd
== ra
)) {
2919 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2923 gen_set_access_type(ctx
, ACCESS_INT
);
2924 EA
= tcg_temp_new();
2925 gen_addr_imm_index(ctx
, EA
, 0x0F);
2927 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
2928 64-bit byteswap already. */
2929 if (unlikely(ctx
->le_mode
)) {
2930 gen_qemu_ld64(ctx
, cpu_gpr
[rd
+1], EA
);
2931 gen_addr_add(ctx
, EA
, EA
, 8);
2932 gen_qemu_ld64(ctx
, cpu_gpr
[rd
], EA
);
2934 gen_qemu_ld64(ctx
, cpu_gpr
[rd
], EA
);
2935 gen_addr_add(ctx
, EA
, EA
, 8);
2936 gen_qemu_ld64(ctx
, cpu_gpr
[rd
+1], EA
);
2942 /*** Integer store ***/
2943 #define GEN_ST(name, stop, opc, type) \
2944 static void glue(gen_, name)(DisasContext *ctx) \
2947 gen_set_access_type(ctx, ACCESS_INT); \
2948 EA = tcg_temp_new(); \
2949 gen_addr_imm_index(ctx, EA, 0); \
2950 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2951 tcg_temp_free(EA); \
2954 #define GEN_STU(name, stop, opc, type) \
2955 static void glue(gen_, stop##u)(DisasContext *ctx) \
2958 if (unlikely(rA(ctx->opcode) == 0)) { \
2959 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2962 gen_set_access_type(ctx, ACCESS_INT); \
2963 EA = tcg_temp_new(); \
2964 if (type == PPC_64B) \
2965 gen_addr_imm_index(ctx, EA, 0x03); \
2967 gen_addr_imm_index(ctx, EA, 0); \
2968 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2969 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2970 tcg_temp_free(EA); \
2973 #define GEN_STUX(name, stop, opc2, opc3, type) \
2974 static void glue(gen_, name##ux)(DisasContext *ctx) \
2977 if (unlikely(rA(ctx->opcode) == 0)) { \
2978 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2981 gen_set_access_type(ctx, ACCESS_INT); \
2982 EA = tcg_temp_new(); \
2983 gen_addr_reg_index(ctx, EA); \
2984 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2985 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2986 tcg_temp_free(EA); \
2989 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
2990 static void glue(gen_, name##x)(DisasContext *ctx) \
2993 gen_set_access_type(ctx, ACCESS_INT); \
2994 EA = tcg_temp_new(); \
2995 gen_addr_reg_index(ctx, EA); \
2996 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2997 tcg_temp_free(EA); \
2999 #define GEN_STX(name, stop, opc2, opc3, type) \
3000 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE)
3002 #define GEN_STS(name, stop, op, type) \
3003 GEN_ST(name, stop, op | 0x20, type); \
3004 GEN_STU(name, stop, op | 0x21, type); \
3005 GEN_STUX(name, stop, 0x17, op | 0x01, type); \
3006 GEN_STX(name, stop, 0x17, op | 0x00, type)
3008 /* stb stbu stbux stbx */
3009 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
);
3010 /* sth sthu sthux sthx */
3011 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
);
3012 /* stw stwu stwux stwx */
3013 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
);
3014 #if defined(TARGET_PPC64)
3015 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
);
3016 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
);
3018 static void gen_std(DisasContext
*ctx
)
3023 rs
= rS(ctx
->opcode
);
3024 if ((ctx
->opcode
& 0x3) == 0x2) { /* stq */
3026 bool legal_in_user_mode
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
3027 bool le_is_supported
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
3029 if (!legal_in_user_mode
&& is_user_mode(ctx
)) {
3030 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3034 if (!le_is_supported
&& ctx
->le_mode
) {
3035 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
3039 if (unlikely(rs
& 1)) {
3040 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3043 gen_set_access_type(ctx
, ACCESS_INT
);
3044 EA
= tcg_temp_new();
3045 gen_addr_imm_index(ctx
, EA
, 0x03);
3047 /* We only need to swap high and low halves. gen_qemu_st64 does
3048 necessary 64-bit byteswap already. */
3049 if (unlikely(ctx
->le_mode
)) {
3050 gen_qemu_st64(ctx
, cpu_gpr
[rs
+1], EA
);
3051 gen_addr_add(ctx
, EA
, EA
, 8);
3052 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
3054 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
3055 gen_addr_add(ctx
, EA
, EA
, 8);
3056 gen_qemu_st64(ctx
, cpu_gpr
[rs
+1], EA
);
3061 if (Rc(ctx
->opcode
)) {
3062 if (unlikely(rA(ctx
->opcode
) == 0)) {
3063 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3067 gen_set_access_type(ctx
, ACCESS_INT
);
3068 EA
= tcg_temp_new();
3069 gen_addr_imm_index(ctx
, EA
, 0x03);
3070 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
3071 if (Rc(ctx
->opcode
))
3072 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
3077 /*** Integer load and store with byte reverse ***/
3080 static inline void gen_qemu_ld16ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3082 TCGMemOp op
= MO_UW
| (ctx
->default_tcg_memop_mask
^ MO_BSWAP
);
3083 tcg_gen_qemu_ld_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
3085 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
);
3088 static inline void gen_qemu_ld32ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3090 TCGMemOp op
= MO_UL
| (ctx
->default_tcg_memop_mask
^ MO_BSWAP
);
3091 tcg_gen_qemu_ld_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
3093 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
);
3095 #if defined(TARGET_PPC64)
3097 static inline void gen_qemu_ld64ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3099 TCGMemOp op
= MO_Q
| (ctx
->default_tcg_memop_mask
^ MO_BSWAP
);
3100 tcg_gen_qemu_ld_i64(arg1
, arg2
, ctx
->mem_idx
, op
);
3102 GEN_LDX_E(ldbr
, ld64ur
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
);
3103 #endif /* TARGET_PPC64 */
3106 static inline void gen_qemu_st16r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3108 TCGMemOp op
= MO_UW
| (ctx
->default_tcg_memop_mask
^ MO_BSWAP
);
3109 tcg_gen_qemu_st_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
3111 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
);
3114 static inline void gen_qemu_st32r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3116 TCGMemOp op
= MO_UL
| (ctx
->default_tcg_memop_mask
^ MO_BSWAP
);
3117 tcg_gen_qemu_st_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
3119 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
);
3121 #if defined(TARGET_PPC64)
3123 static inline void gen_qemu_st64r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3125 TCGMemOp op
= MO_Q
| (ctx
->default_tcg_memop_mask
^ MO_BSWAP
);
3126 tcg_gen_qemu_st_i64(arg1
, arg2
, ctx
->mem_idx
, op
);
3128 GEN_STX_E(stdbr
, st64r
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
);
3129 #endif /* TARGET_PPC64 */
3131 /*** Integer load and store multiple ***/
3134 static void gen_lmw(DisasContext
*ctx
)
3138 gen_set_access_type(ctx
, ACCESS_INT
);
3139 /* NIP cannot be restored if the memory exception comes from an helper */
3140 gen_update_nip(ctx
, ctx
->nip
- 4);
3141 t0
= tcg_temp_new();
3142 t1
= tcg_const_i32(rD(ctx
->opcode
));
3143 gen_addr_imm_index(ctx
, t0
, 0);
3144 gen_helper_lmw(cpu_env
, t0
, t1
);
3146 tcg_temp_free_i32(t1
);
3150 static void gen_stmw(DisasContext
*ctx
)
3154 gen_set_access_type(ctx
, ACCESS_INT
);
3155 /* NIP cannot be restored if the memory exception comes from an helper */
3156 gen_update_nip(ctx
, ctx
->nip
- 4);
3157 t0
= tcg_temp_new();
3158 t1
= tcg_const_i32(rS(ctx
->opcode
));
3159 gen_addr_imm_index(ctx
, t0
, 0);
3160 gen_helper_stmw(cpu_env
, t0
, t1
);
3162 tcg_temp_free_i32(t1
);
3165 /*** Integer load and store strings ***/
3168 /* PowerPC32 specification says we must generate an exception if
3169 * rA is in the range of registers to be loaded.
3170 * In an other hand, IBM says this is valid, but rA won't be loaded.
3171 * For now, I'll follow the spec...
3173 static void gen_lswi(DisasContext
*ctx
)
3177 int nb
= NB(ctx
->opcode
);
3178 int start
= rD(ctx
->opcode
);
3179 int ra
= rA(ctx
->opcode
);
3185 if (unlikely(((start
+ nr
) > 32 &&
3186 start
<= ra
&& (start
+ nr
- 32) > ra
) ||
3187 ((start
+ nr
) <= 32 && start
<= ra
&& (start
+ nr
) > ra
))) {
3188 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
3191 gen_set_access_type(ctx
, ACCESS_INT
);
3192 /* NIP cannot be restored if the memory exception comes from an helper */
3193 gen_update_nip(ctx
, ctx
->nip
- 4);
3194 t0
= tcg_temp_new();
3195 gen_addr_register(ctx
, t0
);
3196 t1
= tcg_const_i32(nb
);
3197 t2
= tcg_const_i32(start
);
3198 gen_helper_lsw(cpu_env
, t0
, t1
, t2
);
3200 tcg_temp_free_i32(t1
);
3201 tcg_temp_free_i32(t2
);
3205 static void gen_lswx(DisasContext
*ctx
)
3208 TCGv_i32 t1
, t2
, t3
;
3209 gen_set_access_type(ctx
, ACCESS_INT
);
3210 /* NIP cannot be restored if the memory exception comes from an helper */
3211 gen_update_nip(ctx
, ctx
->nip
- 4);
3212 t0
= tcg_temp_new();
3213 gen_addr_reg_index(ctx
, t0
);
3214 t1
= tcg_const_i32(rD(ctx
->opcode
));
3215 t2
= tcg_const_i32(rA(ctx
->opcode
));
3216 t3
= tcg_const_i32(rB(ctx
->opcode
));
3217 gen_helper_lswx(cpu_env
, t0
, t1
, t2
, t3
);
3219 tcg_temp_free_i32(t1
);
3220 tcg_temp_free_i32(t2
);
3221 tcg_temp_free_i32(t3
);
3225 static void gen_stswi(DisasContext
*ctx
)
3229 int nb
= NB(ctx
->opcode
);
3230 gen_set_access_type(ctx
, ACCESS_INT
);
3231 /* NIP cannot be restored if the memory exception comes from an helper */
3232 gen_update_nip(ctx
, ctx
->nip
- 4);
3233 t0
= tcg_temp_new();
3234 gen_addr_register(ctx
, t0
);
3237 t1
= tcg_const_i32(nb
);
3238 t2
= tcg_const_i32(rS(ctx
->opcode
));
3239 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3241 tcg_temp_free_i32(t1
);
3242 tcg_temp_free_i32(t2
);
3246 static void gen_stswx(DisasContext
*ctx
)
3250 gen_set_access_type(ctx
, ACCESS_INT
);
3251 /* NIP cannot be restored if the memory exception comes from an helper */
3252 gen_update_nip(ctx
, ctx
->nip
- 4);
3253 t0
= tcg_temp_new();
3254 gen_addr_reg_index(ctx
, t0
);
3255 t1
= tcg_temp_new_i32();
3256 tcg_gen_trunc_tl_i32(t1
, cpu_xer
);
3257 tcg_gen_andi_i32(t1
, t1
, 0x7F);
3258 t2
= tcg_const_i32(rS(ctx
->opcode
));
3259 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3261 tcg_temp_free_i32(t1
);
3262 tcg_temp_free_i32(t2
);
3265 /*** Memory synchronisation ***/
3267 static void gen_eieio(DisasContext
*ctx
)
3272 static void gen_isync(DisasContext
*ctx
)
3274 gen_stop_exception(ctx
);
3277 #define LARX(name, len, loadop) \
3278 static void gen_##name(DisasContext *ctx) \
3281 TCGv gpr = cpu_gpr[rD(ctx->opcode)]; \
3282 gen_set_access_type(ctx, ACCESS_RES); \
3283 t0 = tcg_temp_local_new(); \
3284 gen_addr_reg_index(ctx, t0); \
3286 gen_check_align(ctx, t0, (len)-1); \
3288 gen_qemu_##loadop(ctx, gpr, t0); \
3289 tcg_gen_mov_tl(cpu_reserve, t0); \
3290 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); \
3291 tcg_temp_free(t0); \
3295 LARX(lbarx
, 1, ld8u
);
3296 LARX(lharx
, 2, ld16u
);
3297 LARX(lwarx
, 4, ld32u
);
3300 #if defined(CONFIG_USER_ONLY)
3301 static void gen_conditional_store(DisasContext
*ctx
, TCGv EA
,
3304 TCGv t0
= tcg_temp_new();
3305 uint32_t save_exception
= ctx
->exception
;
3307 tcg_gen_st_tl(EA
, cpu_env
, offsetof(CPUPPCState
, reserve_ea
));
3308 tcg_gen_movi_tl(t0
, (size
<< 5) | reg
);
3309 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, reserve_info
));
3311 gen_update_nip(ctx
, ctx
->nip
-4);
3312 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3313 gen_exception(ctx
, POWERPC_EXCP_STCX
);
3314 ctx
->exception
= save_exception
;
3317 static void gen_conditional_store(DisasContext
*ctx
, TCGv EA
,
3322 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
3323 l1
= gen_new_label();
3324 tcg_gen_brcond_tl(TCG_COND_NE
, EA
, cpu_reserve
, l1
);
3325 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3326 #if defined(TARGET_PPC64)
3328 gen_qemu_st64(ctx
, cpu_gpr
[reg
], EA
);
3332 gen_qemu_st32(ctx
, cpu_gpr
[reg
], EA
);
3333 } else if (size
== 2) {
3334 gen_qemu_st16(ctx
, cpu_gpr
[reg
], EA
);
3335 #if defined(TARGET_PPC64)
3336 } else if (size
== 16) {
3337 TCGv gpr1
, gpr2
, EA8
;
3338 if (unlikely(ctx
->le_mode
)) {
3339 gpr1
= cpu_gpr
[reg
+1];
3340 gpr2
= cpu_gpr
[reg
];
3342 gpr1
= cpu_gpr
[reg
];
3343 gpr2
= cpu_gpr
[reg
+1];
3345 gen_qemu_st64(ctx
, gpr1
, EA
);
3346 EA8
= tcg_temp_local_new();
3347 gen_addr_add(ctx
, EA8
, EA
, 8);
3348 gen_qemu_st64(ctx
, gpr2
, EA8
);
3352 gen_qemu_st8(ctx
, cpu_gpr
[reg
], EA
);
3355 tcg_gen_movi_tl(cpu_reserve
, -1);
3359 #define STCX(name, len) \
3360 static void gen_##name(DisasContext *ctx) \
3363 if (unlikely((len == 16) && (rD(ctx->opcode) & 1))) { \
3364 gen_inval_exception(ctx, \
3365 POWERPC_EXCP_INVAL_INVAL); \
3368 gen_set_access_type(ctx, ACCESS_RES); \
3369 t0 = tcg_temp_local_new(); \
3370 gen_addr_reg_index(ctx, t0); \
3372 gen_check_align(ctx, t0, (len)-1); \
3374 gen_conditional_store(ctx, t0, rS(ctx->opcode), len); \
3375 tcg_temp_free(t0); \
3382 #if defined(TARGET_PPC64)
3384 LARX(ldarx
, 8, ld64
);
3387 static void gen_lqarx(DisasContext
*ctx
)
3390 int rd
= rD(ctx
->opcode
);
3393 if (unlikely((rd
& 1) || (rd
== rA(ctx
->opcode
)) ||
3394 (rd
== rB(ctx
->opcode
)))) {
3395 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3399 gen_set_access_type(ctx
, ACCESS_RES
);
3400 EA
= tcg_temp_local_new();
3401 gen_addr_reg_index(ctx
, EA
);
3402 gen_check_align(ctx
, EA
, 15);
3403 if (unlikely(ctx
->le_mode
)) {
3404 gpr1
= cpu_gpr
[rd
+1];
3408 gpr2
= cpu_gpr
[rd
+1];
3410 gen_qemu_ld64(ctx
, gpr1
, EA
);
3411 tcg_gen_mov_tl(cpu_reserve
, EA
);
3413 gen_addr_add(ctx
, EA
, EA
, 8);
3414 gen_qemu_ld64(ctx
, gpr2
, EA
);
3416 tcg_gen_st_tl(gpr1
, cpu_env
, offsetof(CPUPPCState
, reserve_val
));
3417 tcg_gen_st_tl(gpr2
, cpu_env
, offsetof(CPUPPCState
, reserve_val2
));
3425 #endif /* defined(TARGET_PPC64) */
3428 static void gen_sync(DisasContext
*ctx
)
3433 static void gen_wait(DisasContext
*ctx
)
3435 TCGv_i32 t0
= tcg_temp_new_i32();
3436 tcg_gen_st_i32(t0
, cpu_env
,
3437 -offsetof(PowerPCCPU
, env
) + offsetof(CPUState
, halted
));
3438 tcg_temp_free_i32(t0
);
3439 /* Stop translation, as the CPU is supposed to sleep from now */
3440 gen_exception_err(ctx
, EXCP_HLT
, 1);
3443 /*** Floating-point load ***/
3444 #define GEN_LDF(name, ldop, opc, type) \
3445 static void glue(gen_, name)(DisasContext *ctx) \
3448 if (unlikely(!ctx->fpu_enabled)) { \
3449 gen_exception(ctx, POWERPC_EXCP_FPU); \
3452 gen_set_access_type(ctx, ACCESS_FLOAT); \
3453 EA = tcg_temp_new(); \
3454 gen_addr_imm_index(ctx, EA, 0); \
3455 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3456 tcg_temp_free(EA); \
3459 #define GEN_LDUF(name, ldop, opc, type) \
3460 static void glue(gen_, name##u)(DisasContext *ctx) \
3463 if (unlikely(!ctx->fpu_enabled)) { \
3464 gen_exception(ctx, POWERPC_EXCP_FPU); \
3467 if (unlikely(rA(ctx->opcode) == 0)) { \
3468 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3471 gen_set_access_type(ctx, ACCESS_FLOAT); \
3472 EA = tcg_temp_new(); \
3473 gen_addr_imm_index(ctx, EA, 0); \
3474 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3475 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3476 tcg_temp_free(EA); \
3479 #define GEN_LDUXF(name, ldop, opc, type) \
3480 static void glue(gen_, name##ux)(DisasContext *ctx) \
3483 if (unlikely(!ctx->fpu_enabled)) { \
3484 gen_exception(ctx, POWERPC_EXCP_FPU); \
3487 if (unlikely(rA(ctx->opcode) == 0)) { \
3488 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3491 gen_set_access_type(ctx, ACCESS_FLOAT); \
3492 EA = tcg_temp_new(); \
3493 gen_addr_reg_index(ctx, EA); \
3494 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3495 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3496 tcg_temp_free(EA); \
3499 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
3500 static void glue(gen_, name##x)(DisasContext *ctx) \
3503 if (unlikely(!ctx->fpu_enabled)) { \
3504 gen_exception(ctx, POWERPC_EXCP_FPU); \
3507 gen_set_access_type(ctx, ACCESS_FLOAT); \
3508 EA = tcg_temp_new(); \
3509 gen_addr_reg_index(ctx, EA); \
3510 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3511 tcg_temp_free(EA); \
3514 #define GEN_LDFS(name, ldop, op, type) \
3515 GEN_LDF(name, ldop, op | 0x20, type); \
3516 GEN_LDUF(name, ldop, op | 0x21, type); \
3517 GEN_LDUXF(name, ldop, op | 0x01, type); \
3518 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3520 static inline void gen_qemu_ld32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3522 TCGv t0
= tcg_temp_new();
3523 TCGv_i32 t1
= tcg_temp_new_i32();
3524 gen_qemu_ld32u(ctx
, t0
, arg2
);
3525 tcg_gen_trunc_tl_i32(t1
, t0
);
3527 gen_helper_float32_to_float64(arg1
, cpu_env
, t1
);
3528 tcg_temp_free_i32(t1
);
3531 /* lfd lfdu lfdux lfdx */
3532 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
);
3533 /* lfs lfsu lfsux lfsx */
3534 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
);
3537 static void gen_lfdp(DisasContext
*ctx
)
3540 if (unlikely(!ctx
->fpu_enabled
)) {
3541 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3544 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3545 EA
= tcg_temp_new();
3546 gen_addr_imm_index(ctx
, EA
, 0);
3547 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
3548 64-bit byteswap already. */
3549 if (unlikely(ctx
->le_mode
)) {
3550 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3551 tcg_gen_addi_tl(EA
, EA
, 8);
3552 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3554 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3555 tcg_gen_addi_tl(EA
, EA
, 8);
3556 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3562 static void gen_lfdpx(DisasContext
*ctx
)
3565 if (unlikely(!ctx
->fpu_enabled
)) {
3566 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3569 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3570 EA
= tcg_temp_new();
3571 gen_addr_reg_index(ctx
, EA
);
3572 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
3573 64-bit byteswap already. */
3574 if (unlikely(ctx
->le_mode
)) {
3575 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3576 tcg_gen_addi_tl(EA
, EA
, 8);
3577 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3579 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3580 tcg_gen_addi_tl(EA
, EA
, 8);
3581 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3587 static void gen_lfiwax(DisasContext
*ctx
)
3591 if (unlikely(!ctx
->fpu_enabled
)) {
3592 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3595 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3596 EA
= tcg_temp_new();
3597 t0
= tcg_temp_new();
3598 gen_addr_reg_index(ctx
, EA
);
3599 gen_qemu_ld32s(ctx
, t0
, EA
);
3600 tcg_gen_ext_tl_i64(cpu_fpr
[rD(ctx
->opcode
)], t0
);
3606 static void gen_lfiwzx(DisasContext
*ctx
)
3609 if (unlikely(!ctx
->fpu_enabled
)) {
3610 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3613 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3614 EA
= tcg_temp_new();
3615 gen_addr_reg_index(ctx
, EA
);
3616 gen_qemu_ld32u_i64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3619 /*** Floating-point store ***/
3620 #define GEN_STF(name, stop, opc, type) \
3621 static void glue(gen_, name)(DisasContext *ctx) \
3624 if (unlikely(!ctx->fpu_enabled)) { \
3625 gen_exception(ctx, POWERPC_EXCP_FPU); \
3628 gen_set_access_type(ctx, ACCESS_FLOAT); \
3629 EA = tcg_temp_new(); \
3630 gen_addr_imm_index(ctx, EA, 0); \
3631 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3632 tcg_temp_free(EA); \
3635 #define GEN_STUF(name, stop, opc, type) \
3636 static void glue(gen_, name##u)(DisasContext *ctx) \
3639 if (unlikely(!ctx->fpu_enabled)) { \
3640 gen_exception(ctx, POWERPC_EXCP_FPU); \
3643 if (unlikely(rA(ctx->opcode) == 0)) { \
3644 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3647 gen_set_access_type(ctx, ACCESS_FLOAT); \
3648 EA = tcg_temp_new(); \
3649 gen_addr_imm_index(ctx, EA, 0); \
3650 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3651 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3652 tcg_temp_free(EA); \
3655 #define GEN_STUXF(name, stop, opc, type) \
3656 static void glue(gen_, name##ux)(DisasContext *ctx) \
3659 if (unlikely(!ctx->fpu_enabled)) { \
3660 gen_exception(ctx, POWERPC_EXCP_FPU); \
3663 if (unlikely(rA(ctx->opcode) == 0)) { \
3664 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3667 gen_set_access_type(ctx, ACCESS_FLOAT); \
3668 EA = tcg_temp_new(); \
3669 gen_addr_reg_index(ctx, EA); \
3670 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3671 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3672 tcg_temp_free(EA); \
3675 #define GEN_STXF(name, stop, opc2, opc3, type) \
3676 static void glue(gen_, name##x)(DisasContext *ctx) \
3679 if (unlikely(!ctx->fpu_enabled)) { \
3680 gen_exception(ctx, POWERPC_EXCP_FPU); \
3683 gen_set_access_type(ctx, ACCESS_FLOAT); \
3684 EA = tcg_temp_new(); \
3685 gen_addr_reg_index(ctx, EA); \
3686 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3687 tcg_temp_free(EA); \
3690 #define GEN_STFS(name, stop, op, type) \
3691 GEN_STF(name, stop, op | 0x20, type); \
3692 GEN_STUF(name, stop, op | 0x21, type); \
3693 GEN_STUXF(name, stop, op | 0x01, type); \
3694 GEN_STXF(name, stop, 0x17, op | 0x00, type)
3696 static inline void gen_qemu_st32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3698 TCGv_i32 t0
= tcg_temp_new_i32();
3699 TCGv t1
= tcg_temp_new();
3700 gen_helper_float64_to_float32(t0
, cpu_env
, arg1
);
3701 tcg_gen_extu_i32_tl(t1
, t0
);
3702 tcg_temp_free_i32(t0
);
3703 gen_qemu_st32(ctx
, t1
, arg2
);
3707 /* stfd stfdu stfdux stfdx */
3708 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
);
3709 /* stfs stfsu stfsux stfsx */
3710 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
);
3713 static void gen_stfdp(DisasContext
*ctx
)
3716 if (unlikely(!ctx
->fpu_enabled
)) {
3717 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3720 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3721 EA
= tcg_temp_new();
3722 gen_addr_imm_index(ctx
, EA
, 0);
3723 /* We only need to swap high and low halves. gen_qemu_st64 does necessary
3724 64-bit byteswap already. */
3725 if (unlikely(ctx
->le_mode
)) {
3726 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3727 tcg_gen_addi_tl(EA
, EA
, 8);
3728 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3730 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3731 tcg_gen_addi_tl(EA
, EA
, 8);
3732 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3738 static void gen_stfdpx(DisasContext
*ctx
)
3741 if (unlikely(!ctx
->fpu_enabled
)) {
3742 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3745 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3746 EA
= tcg_temp_new();
3747 gen_addr_reg_index(ctx
, EA
);
3748 /* We only need to swap high and low halves. gen_qemu_st64 does necessary
3749 64-bit byteswap already. */
3750 if (unlikely(ctx
->le_mode
)) {
3751 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3752 tcg_gen_addi_tl(EA
, EA
, 8);
3753 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3755 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3756 tcg_gen_addi_tl(EA
, EA
, 8);
3757 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3763 static inline void gen_qemu_st32fiw(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3765 TCGv t0
= tcg_temp_new();
3766 tcg_gen_trunc_i64_tl(t0
, arg1
),
3767 gen_qemu_st32(ctx
, t0
, arg2
);
3771 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
);
3773 static inline void gen_update_cfar(DisasContext
*ctx
, target_ulong nip
)
3775 #if defined(TARGET_PPC64)
3777 tcg_gen_movi_tl(cpu_cfar
, nip
);
3782 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
3784 TranslationBlock
*tb
;
3786 if (NARROW_MODE(ctx
)) {
3787 dest
= (uint32_t) dest
;
3789 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
3790 likely(!ctx
->singlestep_enabled
)) {
3792 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3793 tcg_gen_exit_tb((uintptr_t)tb
+ n
);
3795 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3796 if (unlikely(ctx
->singlestep_enabled
)) {
3797 if ((ctx
->singlestep_enabled
&
3798 (CPU_BRANCH_STEP
| CPU_SINGLE_STEP
)) &&
3799 (ctx
->exception
== POWERPC_EXCP_BRANCH
||
3800 ctx
->exception
== POWERPC_EXCP_TRACE
)) {
3801 target_ulong tmp
= ctx
->nip
;
3803 gen_exception(ctx
, POWERPC_EXCP_TRACE
);
3806 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
3807 gen_debug_exception(ctx
);
3814 static inline void gen_setlr(DisasContext
*ctx
, target_ulong nip
)
3816 if (NARROW_MODE(ctx
)) {
3817 nip
= (uint32_t)nip
;
3819 tcg_gen_movi_tl(cpu_lr
, nip
);
3823 static void gen_b(DisasContext
*ctx
)
3825 target_ulong li
, target
;
3827 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3828 /* sign extend LI */
3829 li
= LI(ctx
->opcode
);
3830 li
= (li
^ 0x02000000) - 0x02000000;
3831 if (likely(AA(ctx
->opcode
) == 0)) {
3832 target
= ctx
->nip
+ li
- 4;
3836 if (LK(ctx
->opcode
)) {
3837 gen_setlr(ctx
, ctx
->nip
);
3839 gen_update_cfar(ctx
, ctx
->nip
);
3840 gen_goto_tb(ctx
, 0, target
);
3848 static inline void gen_bcond(DisasContext
*ctx
, int type
)
3850 uint32_t bo
= BO(ctx
->opcode
);
3854 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3855 if (type
== BCOND_LR
|| type
== BCOND_CTR
|| type
== BCOND_TAR
) {
3856 target
= tcg_temp_local_new();
3857 if (type
== BCOND_CTR
)
3858 tcg_gen_mov_tl(target
, cpu_ctr
);
3859 else if (type
== BCOND_TAR
)
3860 gen_load_spr(target
, SPR_TAR
);
3862 tcg_gen_mov_tl(target
, cpu_lr
);
3864 TCGV_UNUSED(target
);
3866 if (LK(ctx
->opcode
))
3867 gen_setlr(ctx
, ctx
->nip
);
3868 l1
= gen_new_label();
3869 if ((bo
& 0x4) == 0) {
3870 /* Decrement and test CTR */
3871 TCGv temp
= tcg_temp_new();
3872 if (unlikely(type
== BCOND_CTR
)) {
3873 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3876 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
3877 if (NARROW_MODE(ctx
)) {
3878 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
3880 tcg_gen_mov_tl(temp
, cpu_ctr
);
3883 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
3885 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
3887 tcg_temp_free(temp
);
3889 if ((bo
& 0x10) == 0) {
3891 uint32_t bi
= BI(ctx
->opcode
);
3892 uint32_t mask
= 1 << (3 - (bi
& 0x03));
3893 TCGv_i32 temp
= tcg_temp_new_i32();
3896 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3897 tcg_gen_brcondi_i32(TCG_COND_EQ
, temp
, 0, l1
);
3899 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3900 tcg_gen_brcondi_i32(TCG_COND_NE
, temp
, 0, l1
);
3902 tcg_temp_free_i32(temp
);
3904 gen_update_cfar(ctx
, ctx
->nip
);
3905 if (type
== BCOND_IM
) {
3906 target_ulong li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
3907 if (likely(AA(ctx
->opcode
) == 0)) {
3908 gen_goto_tb(ctx
, 0, ctx
->nip
+ li
- 4);
3910 gen_goto_tb(ctx
, 0, li
);
3913 gen_goto_tb(ctx
, 1, ctx
->nip
);
3915 if (NARROW_MODE(ctx
)) {
3916 tcg_gen_andi_tl(cpu_nip
, target
, (uint32_t)~3);
3918 tcg_gen_andi_tl(cpu_nip
, target
, ~3);
3922 gen_update_nip(ctx
, ctx
->nip
);
3925 if (type
== BCOND_LR
|| type
== BCOND_CTR
|| type
== BCOND_TAR
) {
3926 tcg_temp_free(target
);
3930 static void gen_bc(DisasContext
*ctx
)
3932 gen_bcond(ctx
, BCOND_IM
);
3935 static void gen_bcctr(DisasContext
*ctx
)
3937 gen_bcond(ctx
, BCOND_CTR
);
3940 static void gen_bclr(DisasContext
*ctx
)
3942 gen_bcond(ctx
, BCOND_LR
);
3945 static void gen_bctar(DisasContext
*ctx
)
3947 gen_bcond(ctx
, BCOND_TAR
);
3950 /*** Condition register logical ***/
3951 #define GEN_CRLOGIC(name, tcg_op, opc) \
3952 static void glue(gen_, name)(DisasContext *ctx) \
3957 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3958 t0 = tcg_temp_new_i32(); \
3960 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
3962 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
3964 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
3965 t1 = tcg_temp_new_i32(); \
3966 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3968 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
3970 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
3972 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3973 tcg_op(t0, t0, t1); \
3974 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
3975 tcg_gen_andi_i32(t0, t0, bitmask); \
3976 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3977 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
3978 tcg_temp_free_i32(t0); \
3979 tcg_temp_free_i32(t1); \
3983 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08);
3985 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04);
3987 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09);
3989 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07);
3991 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01);
3993 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E);
3995 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D);
3997 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06);
4000 static void gen_mcrf(DisasContext
*ctx
)
4002 tcg_gen_mov_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfS(ctx
->opcode
)]);
4005 /*** System linkage ***/
4007 /* rfi (mem_idx only) */
4008 static void gen_rfi(DisasContext
*ctx
)
4010 #if defined(CONFIG_USER_ONLY)
4011 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4013 /* Restore CPU state */
4014 if (unlikely(!ctx
->mem_idx
)) {
4015 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4018 gen_update_cfar(ctx
, ctx
->nip
);
4019 gen_helper_rfi(cpu_env
);
4020 gen_sync_exception(ctx
);
4024 #if defined(TARGET_PPC64)
4025 static void gen_rfid(DisasContext
*ctx
)
4027 #if defined(CONFIG_USER_ONLY)
4028 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4030 /* Restore CPU state */
4031 if (unlikely(!ctx
->mem_idx
)) {
4032 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4035 gen_update_cfar(ctx
, ctx
->nip
);
4036 gen_helper_rfid(cpu_env
);
4037 gen_sync_exception(ctx
);
4041 static void gen_hrfid(DisasContext
*ctx
)
4043 #if defined(CONFIG_USER_ONLY)
4044 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4046 /* Restore CPU state */
4047 if (unlikely(ctx
->mem_idx
<= 1)) {
4048 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4051 gen_helper_hrfid(cpu_env
);
4052 gen_sync_exception(ctx
);
4058 #if defined(CONFIG_USER_ONLY)
4059 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
4061 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
4063 static void gen_sc(DisasContext
*ctx
)
4067 lev
= (ctx
->opcode
>> 5) & 0x7F;
4068 gen_exception_err(ctx
, POWERPC_SYSCALL
, lev
);
4074 static void gen_tw(DisasContext
*ctx
)
4076 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
4077 /* Update the nip since this might generate a trap exception */
4078 gen_update_nip(ctx
, ctx
->nip
);
4079 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
4081 tcg_temp_free_i32(t0
);
4085 static void gen_twi(DisasContext
*ctx
)
4087 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
4088 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
4089 /* Update the nip since this might generate a trap exception */
4090 gen_update_nip(ctx
, ctx
->nip
);
4091 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4093 tcg_temp_free_i32(t1
);
4096 #if defined(TARGET_PPC64)
4098 static void gen_td(DisasContext
*ctx
)
4100 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
4101 /* Update the nip since this might generate a trap exception */
4102 gen_update_nip(ctx
, ctx
->nip
);
4103 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
4105 tcg_temp_free_i32(t0
);
4109 static void gen_tdi(DisasContext
*ctx
)
4111 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
4112 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
4113 /* Update the nip since this might generate a trap exception */
4114 gen_update_nip(ctx
, ctx
->nip
);
4115 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4117 tcg_temp_free_i32(t1
);
4121 /*** Processor control ***/
4123 static void gen_read_xer(TCGv dst
)
4125 TCGv t0
= tcg_temp_new();
4126 TCGv t1
= tcg_temp_new();
4127 TCGv t2
= tcg_temp_new();
4128 tcg_gen_mov_tl(dst
, cpu_xer
);
4129 tcg_gen_shli_tl(t0
, cpu_so
, XER_SO
);
4130 tcg_gen_shli_tl(t1
, cpu_ov
, XER_OV
);
4131 tcg_gen_shli_tl(t2
, cpu_ca
, XER_CA
);
4132 tcg_gen_or_tl(t0
, t0
, t1
);
4133 tcg_gen_or_tl(dst
, dst
, t2
);
4134 tcg_gen_or_tl(dst
, dst
, t0
);
4140 static void gen_write_xer(TCGv src
)
4142 tcg_gen_andi_tl(cpu_xer
, src
,
4143 ~((1u << XER_SO
) | (1u << XER_OV
) | (1u << XER_CA
)));
4144 tcg_gen_shri_tl(cpu_so
, src
, XER_SO
);
4145 tcg_gen_shri_tl(cpu_ov
, src
, XER_OV
);
4146 tcg_gen_shri_tl(cpu_ca
, src
, XER_CA
);
4147 tcg_gen_andi_tl(cpu_so
, cpu_so
, 1);
4148 tcg_gen_andi_tl(cpu_ov
, cpu_ov
, 1);
4149 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
4153 static void gen_mcrxr(DisasContext
*ctx
)
4155 TCGv_i32 t0
= tcg_temp_new_i32();
4156 TCGv_i32 t1
= tcg_temp_new_i32();
4157 TCGv_i32 dst
= cpu_crf
[crfD(ctx
->opcode
)];
4159 tcg_gen_trunc_tl_i32(t0
, cpu_so
);
4160 tcg_gen_trunc_tl_i32(t1
, cpu_ov
);
4161 tcg_gen_trunc_tl_i32(dst
, cpu_ca
);
4162 tcg_gen_shli_i32(t0
, t0
, 3);
4163 tcg_gen_shli_i32(t1
, t1
, 2);
4164 tcg_gen_shli_i32(dst
, dst
, 1);
4165 tcg_gen_or_i32(dst
, dst
, t0
);
4166 tcg_gen_or_i32(dst
, dst
, t1
);
4167 tcg_temp_free_i32(t0
);
4168 tcg_temp_free_i32(t1
);
4170 tcg_gen_movi_tl(cpu_so
, 0);
4171 tcg_gen_movi_tl(cpu_ov
, 0);
4172 tcg_gen_movi_tl(cpu_ca
, 0);
4176 static void gen_mfcr(DisasContext
*ctx
)
4180 if (likely(ctx
->opcode
& 0x00100000)) {
4181 crm
= CRM(ctx
->opcode
);
4182 if (likely(crm
&& ((crm
& (crm
- 1)) == 0))) {
4184 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_crf
[7 - crn
]);
4185 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)],
4186 cpu_gpr
[rD(ctx
->opcode
)], crn
* 4);
4189 TCGv_i32 t0
= tcg_temp_new_i32();
4190 tcg_gen_mov_i32(t0
, cpu_crf
[0]);
4191 tcg_gen_shli_i32(t0
, t0
, 4);
4192 tcg_gen_or_i32(t0
, t0
, cpu_crf
[1]);
4193 tcg_gen_shli_i32(t0
, t0
, 4);
4194 tcg_gen_or_i32(t0
, t0
, cpu_crf
[2]);
4195 tcg_gen_shli_i32(t0
, t0
, 4);
4196 tcg_gen_or_i32(t0
, t0
, cpu_crf
[3]);
4197 tcg_gen_shli_i32(t0
, t0
, 4);
4198 tcg_gen_or_i32(t0
, t0
, cpu_crf
[4]);
4199 tcg_gen_shli_i32(t0
, t0
, 4);
4200 tcg_gen_or_i32(t0
, t0
, cpu_crf
[5]);
4201 tcg_gen_shli_i32(t0
, t0
, 4);
4202 tcg_gen_or_i32(t0
, t0
, cpu_crf
[6]);
4203 tcg_gen_shli_i32(t0
, t0
, 4);
4204 tcg_gen_or_i32(t0
, t0
, cpu_crf
[7]);
4205 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4206 tcg_temp_free_i32(t0
);
4211 static void gen_mfmsr(DisasContext
*ctx
)
4213 #if defined(CONFIG_USER_ONLY)
4214 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4216 if (unlikely(!ctx
->mem_idx
)) {
4217 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4220 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_msr
);
4224 static void spr_noaccess(void *opaque
, int gprn
, int sprn
)
4227 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
4228 printf("ERROR: try to access SPR %d !\n", sprn
);
4231 #define SPR_NOACCESS (&spr_noaccess)
4234 static inline void gen_op_mfspr(DisasContext
*ctx
)
4236 void (*read_cb
)(void *opaque
, int gprn
, int sprn
);
4237 uint32_t sprn
= SPR(ctx
->opcode
);
4239 #if !defined(CONFIG_USER_ONLY)
4240 if (ctx
->mem_idx
== 2)
4241 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
4242 else if (ctx
->mem_idx
)
4243 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
4246 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
4247 if (likely(read_cb
!= NULL
)) {
4248 if (likely(read_cb
!= SPR_NOACCESS
)) {
4249 (*read_cb
)(ctx
, rD(ctx
->opcode
), sprn
);
4251 /* Privilege exception */
4252 /* This is a hack to avoid warnings when running Linux:
4253 * this OS breaks the PowerPC virtualisation model,
4254 * allowing userland application to read the PVR
4256 if (sprn
!= SPR_PVR
) {
4257 qemu_log("Trying to read privileged spr %d (0x%03x) at "
4258 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4259 printf("Trying to read privileged spr %d (0x%03x) at "
4260 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4262 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4266 qemu_log("Trying to read invalid spr %d (0x%03x) at "
4267 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4268 printf("Trying to read invalid spr %d (0x%03x) at "
4269 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4270 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4274 static void gen_mfspr(DisasContext
*ctx
)
4280 static void gen_mftb(DisasContext
*ctx
)
4286 static void gen_mtcrf(DisasContext
*ctx
)
4290 crm
= CRM(ctx
->opcode
);
4291 if (likely((ctx
->opcode
& 0x00100000))) {
4292 if (crm
&& ((crm
& (crm
- 1)) == 0)) {
4293 TCGv_i32 temp
= tcg_temp_new_i32();
4295 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
4296 tcg_gen_shri_i32(temp
, temp
, crn
* 4);
4297 tcg_gen_andi_i32(cpu_crf
[7 - crn
], temp
, 0xf);
4298 tcg_temp_free_i32(temp
);
4301 TCGv_i32 temp
= tcg_temp_new_i32();
4302 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
4303 for (crn
= 0 ; crn
< 8 ; crn
++) {
4304 if (crm
& (1 << crn
)) {
4305 tcg_gen_shri_i32(cpu_crf
[7 - crn
], temp
, crn
* 4);
4306 tcg_gen_andi_i32(cpu_crf
[7 - crn
], cpu_crf
[7 - crn
], 0xf);
4309 tcg_temp_free_i32(temp
);
4314 #if defined(TARGET_PPC64)
4315 static void gen_mtmsrd(DisasContext
*ctx
)
4317 #if defined(CONFIG_USER_ONLY)
4318 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4320 if (unlikely(!ctx
->mem_idx
)) {
4321 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4324 if (ctx
->opcode
& 0x00010000) {
4325 /* Special form that does not need any synchronisation */
4326 TCGv t0
= tcg_temp_new();
4327 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
4328 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
4329 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
4332 /* XXX: we need to update nip before the store
4333 * if we enter power saving mode, we will exit the loop
4334 * directly from ppc_store_msr
4336 gen_update_nip(ctx
, ctx
->nip
);
4337 gen_helper_store_msr(cpu_env
, cpu_gpr
[rS(ctx
->opcode
)]);
4338 /* Must stop the translation as machine state (may have) changed */
4339 /* Note that mtmsr is not always defined as context-synchronizing */
4340 gen_stop_exception(ctx
);
4346 static void gen_mtmsr(DisasContext
*ctx
)
4348 #if defined(CONFIG_USER_ONLY)
4349 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4351 if (unlikely(!ctx
->mem_idx
)) {
4352 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4355 if (ctx
->opcode
& 0x00010000) {
4356 /* Special form that does not need any synchronisation */
4357 TCGv t0
= tcg_temp_new();
4358 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
4359 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
4360 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
4363 TCGv msr
= tcg_temp_new();
4365 /* XXX: we need to update nip before the store
4366 * if we enter power saving mode, we will exit the loop
4367 * directly from ppc_store_msr
4369 gen_update_nip(ctx
, ctx
->nip
);
4370 #if defined(TARGET_PPC64)
4371 tcg_gen_deposit_tl(msr
, cpu_msr
, cpu_gpr
[rS(ctx
->opcode
)], 0, 32);
4373 tcg_gen_mov_tl(msr
, cpu_gpr
[rS(ctx
->opcode
)]);
4375 gen_helper_store_msr(cpu_env
, msr
);
4377 /* Must stop the translation as machine state (may have) changed */
4378 /* Note that mtmsr is not always defined as context-synchronizing */
4379 gen_stop_exception(ctx
);
4385 static void gen_mtspr(DisasContext
*ctx
)
4387 void (*write_cb
)(void *opaque
, int sprn
, int gprn
);
4388 uint32_t sprn
= SPR(ctx
->opcode
);
4390 #if !defined(CONFIG_USER_ONLY)
4391 if (ctx
->mem_idx
== 2)
4392 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
4393 else if (ctx
->mem_idx
)
4394 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
4397 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
4398 if (likely(write_cb
!= NULL
)) {
4399 if (likely(write_cb
!= SPR_NOACCESS
)) {
4400 (*write_cb
)(ctx
, sprn
, rS(ctx
->opcode
));
4402 /* Privilege exception */
4403 qemu_log("Trying to write privileged spr %d (0x%03x) at "
4404 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4405 printf("Trying to write privileged spr %d (0x%03x) at "
4406 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4407 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4411 qemu_log("Trying to write invalid spr %d (0x%03x) at "
4412 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4413 printf("Trying to write invalid spr %d (0x%03x) at "
4414 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4415 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4419 /*** Cache management ***/
4422 static void gen_dcbf(DisasContext
*ctx
)
4424 /* XXX: specification says this is treated as a load by the MMU */
4426 gen_set_access_type(ctx
, ACCESS_CACHE
);
4427 t0
= tcg_temp_new();
4428 gen_addr_reg_index(ctx
, t0
);
4429 gen_qemu_ld8u(ctx
, t0
, t0
);
4433 /* dcbi (Supervisor only) */
4434 static void gen_dcbi(DisasContext
*ctx
)
4436 #if defined(CONFIG_USER_ONLY)
4437 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4440 if (unlikely(!ctx
->mem_idx
)) {
4441 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4444 EA
= tcg_temp_new();
4445 gen_set_access_type(ctx
, ACCESS_CACHE
);
4446 gen_addr_reg_index(ctx
, EA
);
4447 val
= tcg_temp_new();
4448 /* XXX: specification says this should be treated as a store by the MMU */
4449 gen_qemu_ld8u(ctx
, val
, EA
);
4450 gen_qemu_st8(ctx
, val
, EA
);
4457 static void gen_dcbst(DisasContext
*ctx
)
4459 /* XXX: specification say this is treated as a load by the MMU */
4461 gen_set_access_type(ctx
, ACCESS_CACHE
);
4462 t0
= tcg_temp_new();
4463 gen_addr_reg_index(ctx
, t0
);
4464 gen_qemu_ld8u(ctx
, t0
, t0
);
4469 static void gen_dcbt(DisasContext
*ctx
)
4471 /* interpreted as no-op */
4472 /* XXX: specification say this is treated as a load by the MMU
4473 * but does not generate any exception
4478 static void gen_dcbtst(DisasContext
*ctx
)
4480 /* interpreted as no-op */
4481 /* XXX: specification say this is treated as a load by the MMU
4482 * but does not generate any exception
4487 static void gen_dcbtls(DisasContext
*ctx
)
4489 /* Always fails locking the cache */
4490 TCGv t0
= tcg_temp_new();
4491 gen_load_spr(t0
, SPR_Exxx_L1CSR0
);
4492 tcg_gen_ori_tl(t0
, t0
, L1CSR0_CUL
);
4493 gen_store_spr(SPR_Exxx_L1CSR0
, t0
);
4498 static void gen_dcbz(DisasContext
*ctx
)
4501 TCGv_i32 tcgv_is_dcbzl
;
4502 int is_dcbzl
= ctx
->opcode
& 0x00200000 ? 1 : 0;
4504 gen_set_access_type(ctx
, ACCESS_CACHE
);
4505 /* NIP cannot be restored if the memory exception comes from an helper */
4506 gen_update_nip(ctx
, ctx
->nip
- 4);
4507 tcgv_addr
= tcg_temp_new();
4508 tcgv_is_dcbzl
= tcg_const_i32(is_dcbzl
);
4510 gen_addr_reg_index(ctx
, tcgv_addr
);
4511 gen_helper_dcbz(cpu_env
, tcgv_addr
, tcgv_is_dcbzl
);
4513 tcg_temp_free(tcgv_addr
);
4514 tcg_temp_free_i32(tcgv_is_dcbzl
);
4518 static void gen_dst(DisasContext
*ctx
)
4520 if (rA(ctx
->opcode
) == 0) {
4521 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
4523 /* interpreted as no-op */
4528 static void gen_dstst(DisasContext
*ctx
)
4530 if (rA(ctx
->opcode
) == 0) {
4531 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
4533 /* interpreted as no-op */
4539 static void gen_dss(DisasContext
*ctx
)
4541 /* interpreted as no-op */
4545 static void gen_icbi(DisasContext
*ctx
)
4548 gen_set_access_type(ctx
, ACCESS_CACHE
);
4549 /* NIP cannot be restored if the memory exception comes from an helper */
4550 gen_update_nip(ctx
, ctx
->nip
- 4);
4551 t0
= tcg_temp_new();
4552 gen_addr_reg_index(ctx
, t0
);
4553 gen_helper_icbi(cpu_env
, t0
);
4559 static void gen_dcba(DisasContext
*ctx
)
4561 /* interpreted as no-op */
4562 /* XXX: specification say this is treated as a store by the MMU
4563 * but does not generate any exception
4567 /*** Segment register manipulation ***/
4568 /* Supervisor only: */
4571 static void gen_mfsr(DisasContext
*ctx
)
4573 #if defined(CONFIG_USER_ONLY)
4574 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4577 if (unlikely(!ctx
->mem_idx
)) {
4578 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4581 t0
= tcg_const_tl(SR(ctx
->opcode
));
4582 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4588 static void gen_mfsrin(DisasContext
*ctx
)
4590 #if defined(CONFIG_USER_ONLY)
4591 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4594 if (unlikely(!ctx
->mem_idx
)) {
4595 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4598 t0
= tcg_temp_new();
4599 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4600 tcg_gen_andi_tl(t0
, t0
, 0xF);
4601 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4607 static void gen_mtsr(DisasContext
*ctx
)
4609 #if defined(CONFIG_USER_ONLY)
4610 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4613 if (unlikely(!ctx
->mem_idx
)) {
4614 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4617 t0
= tcg_const_tl(SR(ctx
->opcode
));
4618 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4624 static void gen_mtsrin(DisasContext
*ctx
)
4626 #if defined(CONFIG_USER_ONLY)
4627 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4630 if (unlikely(!ctx
->mem_idx
)) {
4631 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4634 t0
= tcg_temp_new();
4635 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4636 tcg_gen_andi_tl(t0
, t0
, 0xF);
4637 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rD(ctx
->opcode
)]);
4642 #if defined(TARGET_PPC64)
4643 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4646 static void gen_mfsr_64b(DisasContext
*ctx
)
4648 #if defined(CONFIG_USER_ONLY)
4649 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4652 if (unlikely(!ctx
->mem_idx
)) {
4653 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4656 t0
= tcg_const_tl(SR(ctx
->opcode
));
4657 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4663 static void gen_mfsrin_64b(DisasContext
*ctx
)
4665 #if defined(CONFIG_USER_ONLY)
4666 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4669 if (unlikely(!ctx
->mem_idx
)) {
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_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4682 static void gen_mtsr_64b(DisasContext
*ctx
)
4684 #if defined(CONFIG_USER_ONLY)
4685 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4688 if (unlikely(!ctx
->mem_idx
)) {
4689 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4692 t0
= tcg_const_tl(SR(ctx
->opcode
));
4693 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4699 static void gen_mtsrin_64b(DisasContext
*ctx
)
4701 #if defined(CONFIG_USER_ONLY)
4702 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4705 if (unlikely(!ctx
->mem_idx
)) {
4706 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4709 t0
= tcg_temp_new();
4710 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4711 tcg_gen_andi_tl(t0
, t0
, 0xF);
4712 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4718 static void gen_slbmte(DisasContext
*ctx
)
4720 #if defined(CONFIG_USER_ONLY)
4721 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4723 if (unlikely(!ctx
->mem_idx
)) {
4724 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4727 gen_helper_store_slb(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)],
4728 cpu_gpr
[rS(ctx
->opcode
)]);
4732 static void gen_slbmfee(DisasContext
*ctx
)
4734 #if defined(CONFIG_USER_ONLY)
4735 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4737 if (unlikely(!ctx
->mem_idx
)) {
4738 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4741 gen_helper_load_slb_esid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4742 cpu_gpr
[rB(ctx
->opcode
)]);
4746 static void gen_slbmfev(DisasContext
*ctx
)
4748 #if defined(CONFIG_USER_ONLY)
4749 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4751 if (unlikely(!ctx
->mem_idx
)) {
4752 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4755 gen_helper_load_slb_vsid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4756 cpu_gpr
[rB(ctx
->opcode
)]);
4759 #endif /* defined(TARGET_PPC64) */
4761 /*** Lookaside buffer management ***/
4762 /* Optional & mem_idx only: */
4765 static void gen_tlbia(DisasContext
*ctx
)
4767 #if defined(CONFIG_USER_ONLY)
4768 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4770 if (unlikely(!ctx
->mem_idx
)) {
4771 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4774 gen_helper_tlbia(cpu_env
);
4779 static void gen_tlbiel(DisasContext
*ctx
)
4781 #if defined(CONFIG_USER_ONLY)
4782 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4784 if (unlikely(!ctx
->mem_idx
)) {
4785 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4788 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4793 static void gen_tlbie(DisasContext
*ctx
)
4795 #if defined(CONFIG_USER_ONLY)
4796 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4798 if (unlikely(!ctx
->mem_idx
)) {
4799 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4802 if (NARROW_MODE(ctx
)) {
4803 TCGv t0
= tcg_temp_new();
4804 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
4805 gen_helper_tlbie(cpu_env
, t0
);
4808 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4814 static void gen_tlbsync(DisasContext
*ctx
)
4816 #if defined(CONFIG_USER_ONLY)
4817 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4819 if (unlikely(!ctx
->mem_idx
)) {
4820 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4823 /* This has no effect: it should ensure that all previous
4824 * tlbie have completed
4826 gen_stop_exception(ctx
);
4830 #if defined(TARGET_PPC64)
4832 static void gen_slbia(DisasContext
*ctx
)
4834 #if defined(CONFIG_USER_ONLY)
4835 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4837 if (unlikely(!ctx
->mem_idx
)) {
4838 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4841 gen_helper_slbia(cpu_env
);
4846 static void gen_slbie(DisasContext
*ctx
)
4848 #if defined(CONFIG_USER_ONLY)
4849 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4851 if (unlikely(!ctx
->mem_idx
)) {
4852 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4855 gen_helper_slbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4860 /*** External control ***/
4864 static void gen_eciwx(DisasContext
*ctx
)
4867 /* Should check EAR[E] ! */
4868 gen_set_access_type(ctx
, ACCESS_EXT
);
4869 t0
= tcg_temp_new();
4870 gen_addr_reg_index(ctx
, t0
);
4871 gen_check_align(ctx
, t0
, 0x03);
4872 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4877 static void gen_ecowx(DisasContext
*ctx
)
4880 /* Should check EAR[E] ! */
4881 gen_set_access_type(ctx
, ACCESS_EXT
);
4882 t0
= tcg_temp_new();
4883 gen_addr_reg_index(ctx
, t0
);
4884 gen_check_align(ctx
, t0
, 0x03);
4885 gen_qemu_st32(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4889 /* PowerPC 601 specific instructions */
4892 static void gen_abs(DisasContext
*ctx
)
4894 int l1
= gen_new_label();
4895 int l2
= gen_new_label();
4896 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4897 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4900 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4902 if (unlikely(Rc(ctx
->opcode
) != 0))
4903 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4907 static void gen_abso(DisasContext
*ctx
)
4909 int l1
= gen_new_label();
4910 int l2
= gen_new_label();
4911 int l3
= gen_new_label();
4912 /* Start with XER OV disabled, the most likely case */
4913 tcg_gen_movi_tl(cpu_ov
, 0);
4914 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l2
);
4915 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rA(ctx
->opcode
)], 0x80000000, l1
);
4916 tcg_gen_movi_tl(cpu_ov
, 1);
4917 tcg_gen_movi_tl(cpu_so
, 1);
4920 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4923 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4925 if (unlikely(Rc(ctx
->opcode
) != 0))
4926 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4930 static void gen_clcs(DisasContext
*ctx
)
4932 TCGv_i32 t0
= tcg_const_i32(rA(ctx
->opcode
));
4933 gen_helper_clcs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4934 tcg_temp_free_i32(t0
);
4935 /* Rc=1 sets CR0 to an undefined state */
4939 static void gen_div(DisasContext
*ctx
)
4941 gen_helper_div(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4942 cpu_gpr
[rB(ctx
->opcode
)]);
4943 if (unlikely(Rc(ctx
->opcode
) != 0))
4944 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4948 static void gen_divo(DisasContext
*ctx
)
4950 gen_helper_divo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4951 cpu_gpr
[rB(ctx
->opcode
)]);
4952 if (unlikely(Rc(ctx
->opcode
) != 0))
4953 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4957 static void gen_divs(DisasContext
*ctx
)
4959 gen_helper_divs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4960 cpu_gpr
[rB(ctx
->opcode
)]);
4961 if (unlikely(Rc(ctx
->opcode
) != 0))
4962 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4965 /* divso - divso. */
4966 static void gen_divso(DisasContext
*ctx
)
4968 gen_helper_divso(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
4969 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4970 if (unlikely(Rc(ctx
->opcode
) != 0))
4971 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4975 static void gen_doz(DisasContext
*ctx
)
4977 int l1
= gen_new_label();
4978 int l2
= gen_new_label();
4979 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4980 tcg_gen_sub_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4983 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4985 if (unlikely(Rc(ctx
->opcode
) != 0))
4986 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4990 static void gen_dozo(DisasContext
*ctx
)
4992 int l1
= gen_new_label();
4993 int l2
= gen_new_label();
4994 TCGv t0
= tcg_temp_new();
4995 TCGv t1
= tcg_temp_new();
4996 TCGv t2
= tcg_temp_new();
4997 /* Start with XER OV disabled, the most likely case */
4998 tcg_gen_movi_tl(cpu_ov
, 0);
4999 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
5000 tcg_gen_sub_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5001 tcg_gen_xor_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5002 tcg_gen_xor_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], t0
);
5003 tcg_gen_andc_tl(t1
, t1
, t2
);
5004 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
5005 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
5006 tcg_gen_movi_tl(cpu_ov
, 1);
5007 tcg_gen_movi_tl(cpu_so
, 1);
5010 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
5015 if (unlikely(Rc(ctx
->opcode
) != 0))
5016 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5020 static void gen_dozi(DisasContext
*ctx
)
5022 target_long simm
= SIMM(ctx
->opcode
);
5023 int l1
= gen_new_label();
5024 int l2
= gen_new_label();
5025 tcg_gen_brcondi_tl(TCG_COND_LT
, cpu_gpr
[rA(ctx
->opcode
)], simm
, l1
);
5026 tcg_gen_subfi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
, cpu_gpr
[rA(ctx
->opcode
)]);
5029 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
5031 if (unlikely(Rc(ctx
->opcode
) != 0))
5032 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5035 /* lscbx - lscbx. */
5036 static void gen_lscbx(DisasContext
*ctx
)
5038 TCGv t0
= tcg_temp_new();
5039 TCGv_i32 t1
= tcg_const_i32(rD(ctx
->opcode
));
5040 TCGv_i32 t2
= tcg_const_i32(rA(ctx
->opcode
));
5041 TCGv_i32 t3
= tcg_const_i32(rB(ctx
->opcode
));
5043 gen_addr_reg_index(ctx
, t0
);
5044 /* NIP cannot be restored if the memory exception comes from an helper */
5045 gen_update_nip(ctx
, ctx
->nip
- 4);
5046 gen_helper_lscbx(t0
, cpu_env
, t0
, t1
, t2
, t3
);
5047 tcg_temp_free_i32(t1
);
5048 tcg_temp_free_i32(t2
);
5049 tcg_temp_free_i32(t3
);
5050 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~0x7F);
5051 tcg_gen_or_tl(cpu_xer
, cpu_xer
, t0
);
5052 if (unlikely(Rc(ctx
->opcode
) != 0))
5053 gen_set_Rc0(ctx
, t0
);
5057 /* maskg - maskg. */
5058 static void gen_maskg(DisasContext
*ctx
)
5060 int l1
= gen_new_label();
5061 TCGv t0
= tcg_temp_new();
5062 TCGv t1
= tcg_temp_new();
5063 TCGv t2
= tcg_temp_new();
5064 TCGv t3
= tcg_temp_new();
5065 tcg_gen_movi_tl(t3
, 0xFFFFFFFF);
5066 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5067 tcg_gen_andi_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 0x1F);
5068 tcg_gen_addi_tl(t2
, t0
, 1);
5069 tcg_gen_shr_tl(t2
, t3
, t2
);
5070 tcg_gen_shr_tl(t3
, t3
, t1
);
5071 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], t2
, t3
);
5072 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
5073 tcg_gen_neg_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5079 if (unlikely(Rc(ctx
->opcode
) != 0))
5080 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5083 /* maskir - maskir. */
5084 static void gen_maskir(DisasContext
*ctx
)
5086 TCGv t0
= tcg_temp_new();
5087 TCGv t1
= tcg_temp_new();
5088 tcg_gen_and_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
5089 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
5090 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5093 if (unlikely(Rc(ctx
->opcode
) != 0))
5094 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5098 static void gen_mul(DisasContext
*ctx
)
5100 TCGv_i64 t0
= tcg_temp_new_i64();
5101 TCGv_i64 t1
= tcg_temp_new_i64();
5102 TCGv t2
= tcg_temp_new();
5103 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
5104 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
5105 tcg_gen_mul_i64(t0
, t0
, t1
);
5106 tcg_gen_trunc_i64_tl(t2
, t0
);
5107 gen_store_spr(SPR_MQ
, t2
);
5108 tcg_gen_shri_i64(t1
, t0
, 32);
5109 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
5110 tcg_temp_free_i64(t0
);
5111 tcg_temp_free_i64(t1
);
5113 if (unlikely(Rc(ctx
->opcode
) != 0))
5114 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5118 static void gen_mulo(DisasContext
*ctx
)
5120 int l1
= gen_new_label();
5121 TCGv_i64 t0
= tcg_temp_new_i64();
5122 TCGv_i64 t1
= tcg_temp_new_i64();
5123 TCGv t2
= tcg_temp_new();
5124 /* Start with XER OV disabled, the most likely case */
5125 tcg_gen_movi_tl(cpu_ov
, 0);
5126 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
5127 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
5128 tcg_gen_mul_i64(t0
, t0
, t1
);
5129 tcg_gen_trunc_i64_tl(t2
, t0
);
5130 gen_store_spr(SPR_MQ
, t2
);
5131 tcg_gen_shri_i64(t1
, t0
, 32);
5132 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
5133 tcg_gen_ext32s_i64(t1
, t0
);
5134 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
5135 tcg_gen_movi_tl(cpu_ov
, 1);
5136 tcg_gen_movi_tl(cpu_so
, 1);
5138 tcg_temp_free_i64(t0
);
5139 tcg_temp_free_i64(t1
);
5141 if (unlikely(Rc(ctx
->opcode
) != 0))
5142 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5146 static void gen_nabs(DisasContext
*ctx
)
5148 int l1
= gen_new_label();
5149 int l2
= gen_new_label();
5150 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
5151 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5154 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5156 if (unlikely(Rc(ctx
->opcode
) != 0))
5157 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5160 /* nabso - nabso. */
5161 static void gen_nabso(DisasContext
*ctx
)
5163 int l1
= gen_new_label();
5164 int l2
= gen_new_label();
5165 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
5166 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5169 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5171 /* nabs never overflows */
5172 tcg_gen_movi_tl(cpu_ov
, 0);
5173 if (unlikely(Rc(ctx
->opcode
) != 0))
5174 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5178 static void gen_rlmi(DisasContext
*ctx
)
5180 uint32_t mb
= MB(ctx
->opcode
);
5181 uint32_t me
= ME(ctx
->opcode
);
5182 TCGv t0
= tcg_temp_new();
5183 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5184 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5185 tcg_gen_andi_tl(t0
, t0
, MASK(mb
, me
));
5186 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~MASK(mb
, me
));
5187 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], t0
);
5189 if (unlikely(Rc(ctx
->opcode
) != 0))
5190 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5194 static void gen_rrib(DisasContext
*ctx
)
5196 TCGv t0
= tcg_temp_new();
5197 TCGv t1
= tcg_temp_new();
5198 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5199 tcg_gen_movi_tl(t1
, 0x80000000);
5200 tcg_gen_shr_tl(t1
, t1
, t0
);
5201 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5202 tcg_gen_and_tl(t0
, t0
, t1
);
5203 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], t1
);
5204 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5207 if (unlikely(Rc(ctx
->opcode
) != 0))
5208 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5212 static void gen_sle(DisasContext
*ctx
)
5214 TCGv t0
= tcg_temp_new();
5215 TCGv t1
= tcg_temp_new();
5216 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5217 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5218 tcg_gen_subfi_tl(t1
, 32, t1
);
5219 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5220 tcg_gen_or_tl(t1
, t0
, t1
);
5221 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5222 gen_store_spr(SPR_MQ
, t1
);
5225 if (unlikely(Rc(ctx
->opcode
) != 0))
5226 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5230 static void gen_sleq(DisasContext
*ctx
)
5232 TCGv t0
= tcg_temp_new();
5233 TCGv t1
= tcg_temp_new();
5234 TCGv t2
= tcg_temp_new();
5235 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5236 tcg_gen_movi_tl(t2
, 0xFFFFFFFF);
5237 tcg_gen_shl_tl(t2
, t2
, t0
);
5238 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5239 gen_load_spr(t1
, SPR_MQ
);
5240 gen_store_spr(SPR_MQ
, t0
);
5241 tcg_gen_and_tl(t0
, t0
, t2
);
5242 tcg_gen_andc_tl(t1
, t1
, t2
);
5243 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5247 if (unlikely(Rc(ctx
->opcode
) != 0))
5248 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5252 static void gen_sliq(DisasContext
*ctx
)
5254 int sh
= SH(ctx
->opcode
);
5255 TCGv t0
= tcg_temp_new();
5256 TCGv t1
= tcg_temp_new();
5257 tcg_gen_shli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5258 tcg_gen_shri_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
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
)]);
5268 /* slliq - slliq. */
5269 static void gen_slliq(DisasContext
*ctx
)
5271 int sh
= SH(ctx
->opcode
);
5272 TCGv t0
= tcg_temp_new();
5273 TCGv t1
= tcg_temp_new();
5274 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5275 gen_load_spr(t1
, SPR_MQ
);
5276 gen_store_spr(SPR_MQ
, t0
);
5277 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
<< sh
));
5278 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
<< sh
));
5279 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5282 if (unlikely(Rc(ctx
->opcode
) != 0))
5283 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5287 static void gen_sllq(DisasContext
*ctx
)
5289 int l1
= gen_new_label();
5290 int l2
= gen_new_label();
5291 TCGv t0
= tcg_temp_local_new();
5292 TCGv t1
= tcg_temp_local_new();
5293 TCGv t2
= tcg_temp_local_new();
5294 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5295 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5296 tcg_gen_shl_tl(t1
, t1
, t2
);
5297 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5298 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5299 gen_load_spr(t0
, SPR_MQ
);
5300 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5303 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5304 gen_load_spr(t2
, SPR_MQ
);
5305 tcg_gen_andc_tl(t1
, t2
, t1
);
5306 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5311 if (unlikely(Rc(ctx
->opcode
) != 0))
5312 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5316 static void gen_slq(DisasContext
*ctx
)
5318 int l1
= gen_new_label();
5319 TCGv t0
= tcg_temp_new();
5320 TCGv t1
= tcg_temp_new();
5321 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5322 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5323 tcg_gen_subfi_tl(t1
, 32, t1
);
5324 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5325 tcg_gen_or_tl(t1
, t0
, t1
);
5326 gen_store_spr(SPR_MQ
, t1
);
5327 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5328 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5329 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
5330 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5334 if (unlikely(Rc(ctx
->opcode
) != 0))
5335 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5338 /* sraiq - sraiq. */
5339 static void gen_sraiq(DisasContext
*ctx
)
5341 int sh
= SH(ctx
->opcode
);
5342 int l1
= gen_new_label();
5343 TCGv t0
= tcg_temp_new();
5344 TCGv t1
= tcg_temp_new();
5345 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5346 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5347 tcg_gen_or_tl(t0
, t0
, t1
);
5348 gen_store_spr(SPR_MQ
, t0
);
5349 tcg_gen_movi_tl(cpu_ca
, 0);
5350 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
5351 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
5352 tcg_gen_movi_tl(cpu_ca
, 1);
5354 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
5357 if (unlikely(Rc(ctx
->opcode
) != 0))
5358 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5362 static void gen_sraq(DisasContext
*ctx
)
5364 int l1
= gen_new_label();
5365 int l2
= gen_new_label();
5366 TCGv t0
= tcg_temp_new();
5367 TCGv t1
= tcg_temp_local_new();
5368 TCGv t2
= tcg_temp_local_new();
5369 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5370 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5371 tcg_gen_sar_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5372 tcg_gen_subfi_tl(t2
, 32, t2
);
5373 tcg_gen_shl_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5374 tcg_gen_or_tl(t0
, t0
, t2
);
5375 gen_store_spr(SPR_MQ
, t0
);
5376 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5377 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l1
);
5378 tcg_gen_mov_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
5379 tcg_gen_sari_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 31);
5382 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
);
5383 tcg_gen_movi_tl(cpu_ca
, 0);
5384 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
5385 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l2
);
5386 tcg_gen_movi_tl(cpu_ca
, 1);
5390 if (unlikely(Rc(ctx
->opcode
) != 0))
5391 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5395 static void gen_sre(DisasContext
*ctx
)
5397 TCGv t0
= tcg_temp_new();
5398 TCGv t1
= tcg_temp_new();
5399 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5400 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5401 tcg_gen_subfi_tl(t1
, 32, t1
);
5402 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5403 tcg_gen_or_tl(t1
, t0
, t1
);
5404 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5405 gen_store_spr(SPR_MQ
, t1
);
5408 if (unlikely(Rc(ctx
->opcode
) != 0))
5409 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5413 static void gen_srea(DisasContext
*ctx
)
5415 TCGv t0
= tcg_temp_new();
5416 TCGv t1
= tcg_temp_new();
5417 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5418 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5419 gen_store_spr(SPR_MQ
, t0
);
5420 tcg_gen_sar_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t1
);
5423 if (unlikely(Rc(ctx
->opcode
) != 0))
5424 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5428 static void gen_sreq(DisasContext
*ctx
)
5430 TCGv t0
= tcg_temp_new();
5431 TCGv t1
= tcg_temp_new();
5432 TCGv t2
= tcg_temp_new();
5433 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5434 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5435 tcg_gen_shr_tl(t1
, t1
, t0
);
5436 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5437 gen_load_spr(t2
, SPR_MQ
);
5438 gen_store_spr(SPR_MQ
, t0
);
5439 tcg_gen_and_tl(t0
, t0
, t1
);
5440 tcg_gen_andc_tl(t2
, t2
, t1
);
5441 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5445 if (unlikely(Rc(ctx
->opcode
) != 0))
5446 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5450 static void gen_sriq(DisasContext
*ctx
)
5452 int sh
= SH(ctx
->opcode
);
5453 TCGv t0
= tcg_temp_new();
5454 TCGv t1
= tcg_temp_new();
5455 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5456 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5457 tcg_gen_or_tl(t1
, t0
, t1
);
5458 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5459 gen_store_spr(SPR_MQ
, t1
);
5462 if (unlikely(Rc(ctx
->opcode
) != 0))
5463 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5467 static void gen_srliq(DisasContext
*ctx
)
5469 int sh
= SH(ctx
->opcode
);
5470 TCGv t0
= tcg_temp_new();
5471 TCGv t1
= tcg_temp_new();
5472 tcg_gen_rotri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5473 gen_load_spr(t1
, SPR_MQ
);
5474 gen_store_spr(SPR_MQ
, t0
);
5475 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
>> sh
));
5476 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
>> sh
));
5477 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5480 if (unlikely(Rc(ctx
->opcode
) != 0))
5481 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5485 static void gen_srlq(DisasContext
*ctx
)
5487 int l1
= gen_new_label();
5488 int l2
= gen_new_label();
5489 TCGv t0
= tcg_temp_local_new();
5490 TCGv t1
= tcg_temp_local_new();
5491 TCGv t2
= tcg_temp_local_new();
5492 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5493 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5494 tcg_gen_shr_tl(t2
, t1
, t2
);
5495 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5496 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5497 gen_load_spr(t0
, SPR_MQ
);
5498 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5501 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5502 tcg_gen_and_tl(t0
, t0
, t2
);
5503 gen_load_spr(t1
, SPR_MQ
);
5504 tcg_gen_andc_tl(t1
, t1
, t2
);
5505 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5510 if (unlikely(Rc(ctx
->opcode
) != 0))
5511 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5515 static void gen_srq(DisasContext
*ctx
)
5517 int l1
= gen_new_label();
5518 TCGv t0
= tcg_temp_new();
5519 TCGv t1
= tcg_temp_new();
5520 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5521 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5522 tcg_gen_subfi_tl(t1
, 32, t1
);
5523 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5524 tcg_gen_or_tl(t1
, t0
, t1
);
5525 gen_store_spr(SPR_MQ
, t1
);
5526 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5527 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5528 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5529 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5533 if (unlikely(Rc(ctx
->opcode
) != 0))
5534 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5537 /* PowerPC 602 specific instructions */
5540 static void gen_dsa(DisasContext
*ctx
)
5543 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5547 static void gen_esa(DisasContext
*ctx
)
5550 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5554 static void gen_mfrom(DisasContext
*ctx
)
5556 #if defined(CONFIG_USER_ONLY)
5557 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5559 if (unlikely(!ctx
->mem_idx
)) {
5560 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5563 gen_helper_602_mfrom(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5567 /* 602 - 603 - G2 TLB management */
5570 static void gen_tlbld_6xx(DisasContext
*ctx
)
5572 #if defined(CONFIG_USER_ONLY)
5573 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5575 if (unlikely(!ctx
->mem_idx
)) {
5576 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5579 gen_helper_6xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5584 static void gen_tlbli_6xx(DisasContext
*ctx
)
5586 #if defined(CONFIG_USER_ONLY)
5587 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5589 if (unlikely(!ctx
->mem_idx
)) {
5590 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5593 gen_helper_6xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5597 /* 74xx TLB management */
5600 static void gen_tlbld_74xx(DisasContext
*ctx
)
5602 #if defined(CONFIG_USER_ONLY)
5603 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5605 if (unlikely(!ctx
->mem_idx
)) {
5606 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5609 gen_helper_74xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5614 static void gen_tlbli_74xx(DisasContext
*ctx
)
5616 #if defined(CONFIG_USER_ONLY)
5617 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5619 if (unlikely(!ctx
->mem_idx
)) {
5620 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5623 gen_helper_74xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5627 /* POWER instructions not in PowerPC 601 */
5630 static void gen_clf(DisasContext
*ctx
)
5632 /* Cache line flush: implemented as no-op */
5636 static void gen_cli(DisasContext
*ctx
)
5638 /* Cache line invalidate: privileged and treated as no-op */
5639 #if defined(CONFIG_USER_ONLY)
5640 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5642 if (unlikely(!ctx
->mem_idx
)) {
5643 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5650 static void gen_dclst(DisasContext
*ctx
)
5652 /* Data cache line store: treated as no-op */
5655 static void gen_mfsri(DisasContext
*ctx
)
5657 #if defined(CONFIG_USER_ONLY)
5658 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5660 int ra
= rA(ctx
->opcode
);
5661 int rd
= rD(ctx
->opcode
);
5663 if (unlikely(!ctx
->mem_idx
)) {
5664 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5667 t0
= tcg_temp_new();
5668 gen_addr_reg_index(ctx
, t0
);
5669 tcg_gen_shri_tl(t0
, t0
, 28);
5670 tcg_gen_andi_tl(t0
, t0
, 0xF);
5671 gen_helper_load_sr(cpu_gpr
[rd
], cpu_env
, t0
);
5673 if (ra
!= 0 && ra
!= rd
)
5674 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rd
]);
5678 static void gen_rac(DisasContext
*ctx
)
5680 #if defined(CONFIG_USER_ONLY)
5681 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5684 if (unlikely(!ctx
->mem_idx
)) {
5685 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5688 t0
= tcg_temp_new();
5689 gen_addr_reg_index(ctx
, t0
);
5690 gen_helper_rac(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5695 static void gen_rfsvc(DisasContext
*ctx
)
5697 #if defined(CONFIG_USER_ONLY)
5698 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5700 if (unlikely(!ctx
->mem_idx
)) {
5701 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5704 gen_helper_rfsvc(cpu_env
);
5705 gen_sync_exception(ctx
);
5709 /* svc is not implemented for now */
5711 /* POWER2 specific instructions */
5712 /* Quad manipulation (load/store two floats at a time) */
5715 static void gen_lfq(DisasContext
*ctx
)
5717 int rd
= rD(ctx
->opcode
);
5719 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5720 t0
= tcg_temp_new();
5721 gen_addr_imm_index(ctx
, t0
, 0);
5722 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5723 gen_addr_add(ctx
, t0
, t0
, 8);
5724 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5729 static void gen_lfqu(DisasContext
*ctx
)
5731 int ra
= rA(ctx
->opcode
);
5732 int rd
= rD(ctx
->opcode
);
5734 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5735 t0
= tcg_temp_new();
5736 t1
= tcg_temp_new();
5737 gen_addr_imm_index(ctx
, t0
, 0);
5738 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5739 gen_addr_add(ctx
, t1
, t0
, 8);
5740 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5742 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5748 static void gen_lfqux(DisasContext
*ctx
)
5750 int ra
= rA(ctx
->opcode
);
5751 int rd
= rD(ctx
->opcode
);
5752 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5754 t0
= tcg_temp_new();
5755 gen_addr_reg_index(ctx
, t0
);
5756 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5757 t1
= tcg_temp_new();
5758 gen_addr_add(ctx
, t1
, t0
, 8);
5759 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5762 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5767 static void gen_lfqx(DisasContext
*ctx
)
5769 int rd
= rD(ctx
->opcode
);
5771 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5772 t0
= tcg_temp_new();
5773 gen_addr_reg_index(ctx
, t0
);
5774 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5775 gen_addr_add(ctx
, t0
, t0
, 8);
5776 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5781 static void gen_stfq(DisasContext
*ctx
)
5783 int rd
= rD(ctx
->opcode
);
5785 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5786 t0
= tcg_temp_new();
5787 gen_addr_imm_index(ctx
, t0
, 0);
5788 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5789 gen_addr_add(ctx
, t0
, t0
, 8);
5790 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5795 static void gen_stfqu(DisasContext
*ctx
)
5797 int ra
= rA(ctx
->opcode
);
5798 int rd
= rD(ctx
->opcode
);
5800 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5801 t0
= tcg_temp_new();
5802 gen_addr_imm_index(ctx
, t0
, 0);
5803 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5804 t1
= tcg_temp_new();
5805 gen_addr_add(ctx
, t1
, t0
, 8);
5806 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5809 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5814 static void gen_stfqux(DisasContext
*ctx
)
5816 int ra
= rA(ctx
->opcode
);
5817 int rd
= rD(ctx
->opcode
);
5819 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5820 t0
= tcg_temp_new();
5821 gen_addr_reg_index(ctx
, t0
);
5822 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5823 t1
= tcg_temp_new();
5824 gen_addr_add(ctx
, t1
, t0
, 8);
5825 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5828 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5833 static void gen_stfqx(DisasContext
*ctx
)
5835 int rd
= rD(ctx
->opcode
);
5837 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5838 t0
= tcg_temp_new();
5839 gen_addr_reg_index(ctx
, t0
);
5840 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5841 gen_addr_add(ctx
, t0
, t0
, 8);
5842 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5846 /* BookE specific instructions */
5848 /* XXX: not implemented on 440 ? */
5849 static void gen_mfapidi(DisasContext
*ctx
)
5852 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5855 /* XXX: not implemented on 440 ? */
5856 static void gen_tlbiva(DisasContext
*ctx
)
5858 #if defined(CONFIG_USER_ONLY)
5859 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5862 if (unlikely(!ctx
->mem_idx
)) {
5863 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5866 t0
= tcg_temp_new();
5867 gen_addr_reg_index(ctx
, t0
);
5868 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5873 /* All 405 MAC instructions are translated here */
5874 static inline void gen_405_mulladd_insn(DisasContext
*ctx
, int opc2
, int opc3
,
5875 int ra
, int rb
, int rt
, int Rc
)
5879 t0
= tcg_temp_local_new();
5880 t1
= tcg_temp_local_new();
5882 switch (opc3
& 0x0D) {
5884 /* macchw - macchw. - macchwo - macchwo. */
5885 /* macchws - macchws. - macchwso - macchwso. */
5886 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5887 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5888 /* mulchw - mulchw. */
5889 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5890 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5891 tcg_gen_ext16s_tl(t1
, t1
);
5894 /* macchwu - macchwu. - macchwuo - macchwuo. */
5895 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5896 /* mulchwu - mulchwu. */
5897 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5898 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5899 tcg_gen_ext16u_tl(t1
, t1
);
5902 /* machhw - machhw. - machhwo - machhwo. */
5903 /* machhws - machhws. - machhwso - machhwso. */
5904 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5905 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5906 /* mulhhw - mulhhw. */
5907 tcg_gen_sari_tl(t0
, cpu_gpr
[ra
], 16);
5908 tcg_gen_ext16s_tl(t0
, t0
);
5909 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5910 tcg_gen_ext16s_tl(t1
, t1
);
5913 /* machhwu - machhwu. - machhwuo - machhwuo. */
5914 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5915 /* mulhhwu - mulhhwu. */
5916 tcg_gen_shri_tl(t0
, cpu_gpr
[ra
], 16);
5917 tcg_gen_ext16u_tl(t0
, t0
);
5918 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5919 tcg_gen_ext16u_tl(t1
, t1
);
5922 /* maclhw - maclhw. - maclhwo - maclhwo. */
5923 /* maclhws - maclhws. - maclhwso - maclhwso. */
5924 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5925 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5926 /* mullhw - mullhw. */
5927 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5928 tcg_gen_ext16s_tl(t1
, cpu_gpr
[rb
]);
5931 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5932 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5933 /* mullhwu - mullhwu. */
5934 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5935 tcg_gen_ext16u_tl(t1
, cpu_gpr
[rb
]);
5939 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5940 tcg_gen_mul_tl(t1
, t0
, t1
);
5942 /* nmultiply-and-accumulate (0x0E) */
5943 tcg_gen_sub_tl(t0
, cpu_gpr
[rt
], t1
);
5945 /* multiply-and-accumulate (0x0C) */
5946 tcg_gen_add_tl(t0
, cpu_gpr
[rt
], t1
);
5950 /* Check overflow and/or saturate */
5951 int l1
= gen_new_label();
5954 /* Start with XER OV disabled, the most likely case */
5955 tcg_gen_movi_tl(cpu_ov
, 0);
5959 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t1
);
5960 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
5961 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t0
);
5962 tcg_gen_brcondi_tl(TCG_COND_LT
, t1
, 0, l1
);
5965 tcg_gen_sari_tl(t0
, cpu_gpr
[rt
], 31);
5966 tcg_gen_xori_tl(t0
, t0
, 0x7fffffff);
5970 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
5973 tcg_gen_movi_tl(t0
, UINT32_MAX
);
5977 /* Check overflow */
5978 tcg_gen_movi_tl(cpu_ov
, 1);
5979 tcg_gen_movi_tl(cpu_so
, 1);
5982 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
5985 tcg_gen_mul_tl(cpu_gpr
[rt
], t0
, t1
);
5989 if (unlikely(Rc
) != 0) {
5991 gen_set_Rc0(ctx
, cpu_gpr
[rt
]);
5995 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5996 static void glue(gen_, name)(DisasContext *ctx) \
5998 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5999 rD(ctx->opcode), Rc(ctx->opcode)); \
6002 /* macchw - macchw. */
6003 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
6004 /* macchwo - macchwo. */
6005 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
6006 /* macchws - macchws. */
6007 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
6008 /* macchwso - macchwso. */
6009 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
6010 /* macchwsu - macchwsu. */
6011 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
6012 /* macchwsuo - macchwsuo. */
6013 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
6014 /* macchwu - macchwu. */
6015 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
6016 /* macchwuo - macchwuo. */
6017 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
6018 /* machhw - machhw. */
6019 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
6020 /* machhwo - machhwo. */
6021 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
6022 /* machhws - machhws. */
6023 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
6024 /* machhwso - machhwso. */
6025 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
6026 /* machhwsu - machhwsu. */
6027 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
6028 /* machhwsuo - machhwsuo. */
6029 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
6030 /* machhwu - machhwu. */
6031 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
6032 /* machhwuo - machhwuo. */
6033 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
6034 /* maclhw - maclhw. */
6035 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
6036 /* maclhwo - maclhwo. */
6037 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
6038 /* maclhws - maclhws. */
6039 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
6040 /* maclhwso - maclhwso. */
6041 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
6042 /* maclhwu - maclhwu. */
6043 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
6044 /* maclhwuo - maclhwuo. */
6045 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
6046 /* maclhwsu - maclhwsu. */
6047 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
6048 /* maclhwsuo - maclhwsuo. */
6049 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
6050 /* nmacchw - nmacchw. */
6051 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
6052 /* nmacchwo - nmacchwo. */
6053 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
6054 /* nmacchws - nmacchws. */
6055 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
6056 /* nmacchwso - nmacchwso. */
6057 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
6058 /* nmachhw - nmachhw. */
6059 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
6060 /* nmachhwo - nmachhwo. */
6061 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
6062 /* nmachhws - nmachhws. */
6063 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
6064 /* nmachhwso - nmachhwso. */
6065 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
6066 /* nmaclhw - nmaclhw. */
6067 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
6068 /* nmaclhwo - nmaclhwo. */
6069 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
6070 /* nmaclhws - nmaclhws. */
6071 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
6072 /* nmaclhwso - nmaclhwso. */
6073 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
6075 /* mulchw - mulchw. */
6076 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
6077 /* mulchwu - mulchwu. */
6078 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
6079 /* mulhhw - mulhhw. */
6080 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
6081 /* mulhhwu - mulhhwu. */
6082 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
6083 /* mullhw - mullhw. */
6084 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
6085 /* mullhwu - mullhwu. */
6086 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
6089 static void gen_mfdcr(DisasContext
*ctx
)
6091 #if defined(CONFIG_USER_ONLY)
6092 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
6095 if (unlikely(!ctx
->mem_idx
)) {
6096 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
6099 /* NIP cannot be restored if the memory exception comes from an helper */
6100 gen_update_nip(ctx
, ctx
->nip
- 4);
6101 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
6102 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, dcrn
);
6103 tcg_temp_free(dcrn
);
6108 static void gen_mtdcr(DisasContext
*ctx
)
6110 #if defined(CONFIG_USER_ONLY)
6111 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
6114 if (unlikely(!ctx
->mem_idx
)) {
6115 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
6118 /* NIP cannot be restored if the memory exception comes from an helper */
6119 gen_update_nip(ctx
, ctx
->nip
- 4);
6120 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
6121 gen_helper_store_dcr(cpu_env
, dcrn
, cpu_gpr
[rS(ctx
->opcode
)]);
6122 tcg_temp_free(dcrn
);
6127 /* XXX: not implemented on 440 ? */
6128 static void gen_mfdcrx(DisasContext
*ctx
)
6130 #if defined(CONFIG_USER_ONLY)
6131 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
6133 if (unlikely(!ctx
->mem_idx
)) {
6134 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
6137 /* NIP cannot be restored if the memory exception comes from an helper */
6138 gen_update_nip(ctx
, ctx
->nip
- 4);
6139 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6140 cpu_gpr
[rA(ctx
->opcode
)]);
6141 /* Note: Rc update flag set leads to undefined state of Rc0 */
6146 /* XXX: not implemented on 440 ? */
6147 static void gen_mtdcrx(DisasContext
*ctx
)
6149 #if defined(CONFIG_USER_ONLY)
6150 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
6152 if (unlikely(!ctx
->mem_idx
)) {
6153 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
6156 /* NIP cannot be restored if the memory exception comes from an helper */
6157 gen_update_nip(ctx
, ctx
->nip
- 4);
6158 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6159 cpu_gpr
[rS(ctx
->opcode
)]);
6160 /* Note: Rc update flag set leads to undefined state of Rc0 */
6164 /* mfdcrux (PPC 460) : user-mode access to DCR */
6165 static void gen_mfdcrux(DisasContext
*ctx
)
6167 /* NIP cannot be restored if the memory exception comes from an helper */
6168 gen_update_nip(ctx
, ctx
->nip
- 4);
6169 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6170 cpu_gpr
[rA(ctx
->opcode
)]);
6171 /* Note: Rc update flag set leads to undefined state of Rc0 */
6174 /* mtdcrux (PPC 460) : user-mode access to DCR */
6175 static void gen_mtdcrux(DisasContext
*ctx
)
6177 /* NIP cannot be restored if the memory exception comes from an helper */
6178 gen_update_nip(ctx
, ctx
->nip
- 4);
6179 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6180 cpu_gpr
[rS(ctx
->opcode
)]);
6181 /* Note: Rc update flag set leads to undefined state of Rc0 */
6185 static void gen_dccci(DisasContext
*ctx
)
6187 #if defined(CONFIG_USER_ONLY)
6188 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6190 if (unlikely(!ctx
->mem_idx
)) {
6191 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6194 /* interpreted as no-op */
6199 static void gen_dcread(DisasContext
*ctx
)
6201 #if defined(CONFIG_USER_ONLY)
6202 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6205 if (unlikely(!ctx
->mem_idx
)) {
6206 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6209 gen_set_access_type(ctx
, ACCESS_CACHE
);
6210 EA
= tcg_temp_new();
6211 gen_addr_reg_index(ctx
, EA
);
6212 val
= tcg_temp_new();
6213 gen_qemu_ld32u(ctx
, val
, EA
);
6215 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], EA
);
6221 static void gen_icbt_40x(DisasContext
*ctx
)
6223 /* interpreted as no-op */
6224 /* XXX: specification say this is treated as a load by the MMU
6225 * but does not generate any exception
6230 static void gen_iccci(DisasContext
*ctx
)
6232 #if defined(CONFIG_USER_ONLY)
6233 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6235 if (unlikely(!ctx
->mem_idx
)) {
6236 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6239 /* interpreted as no-op */
6244 static void gen_icread(DisasContext
*ctx
)
6246 #if defined(CONFIG_USER_ONLY)
6247 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6249 if (unlikely(!ctx
->mem_idx
)) {
6250 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6253 /* interpreted as no-op */
6257 /* rfci (mem_idx only) */
6258 static void gen_rfci_40x(DisasContext
*ctx
)
6260 #if defined(CONFIG_USER_ONLY)
6261 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6263 if (unlikely(!ctx
->mem_idx
)) {
6264 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6267 /* Restore CPU state */
6268 gen_helper_40x_rfci(cpu_env
);
6269 gen_sync_exception(ctx
);
6273 static void gen_rfci(DisasContext
*ctx
)
6275 #if defined(CONFIG_USER_ONLY)
6276 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6278 if (unlikely(!ctx
->mem_idx
)) {
6279 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6282 /* Restore CPU state */
6283 gen_helper_rfci(cpu_env
);
6284 gen_sync_exception(ctx
);
6288 /* BookE specific */
6290 /* XXX: not implemented on 440 ? */
6291 static void gen_rfdi(DisasContext
*ctx
)
6293 #if defined(CONFIG_USER_ONLY)
6294 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6296 if (unlikely(!ctx
->mem_idx
)) {
6297 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6300 /* Restore CPU state */
6301 gen_helper_rfdi(cpu_env
);
6302 gen_sync_exception(ctx
);
6306 /* XXX: not implemented on 440 ? */
6307 static void gen_rfmci(DisasContext
*ctx
)
6309 #if defined(CONFIG_USER_ONLY)
6310 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6312 if (unlikely(!ctx
->mem_idx
)) {
6313 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6316 /* Restore CPU state */
6317 gen_helper_rfmci(cpu_env
);
6318 gen_sync_exception(ctx
);
6322 /* TLB management - PowerPC 405 implementation */
6325 static void gen_tlbre_40x(DisasContext
*ctx
)
6327 #if defined(CONFIG_USER_ONLY)
6328 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6330 if (unlikely(!ctx
->mem_idx
)) {
6331 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6334 switch (rB(ctx
->opcode
)) {
6336 gen_helper_4xx_tlbre_hi(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6337 cpu_gpr
[rA(ctx
->opcode
)]);
6340 gen_helper_4xx_tlbre_lo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6341 cpu_gpr
[rA(ctx
->opcode
)]);
6344 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6350 /* tlbsx - tlbsx. */
6351 static void gen_tlbsx_40x(DisasContext
*ctx
)
6353 #if defined(CONFIG_USER_ONLY)
6354 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6357 if (unlikely(!ctx
->mem_idx
)) {
6358 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6361 t0
= tcg_temp_new();
6362 gen_addr_reg_index(ctx
, t0
);
6363 gen_helper_4xx_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
6365 if (Rc(ctx
->opcode
)) {
6366 int l1
= gen_new_label();
6367 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
6368 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
6369 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
6376 static void gen_tlbwe_40x(DisasContext
*ctx
)
6378 #if defined(CONFIG_USER_ONLY)
6379 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6381 if (unlikely(!ctx
->mem_idx
)) {
6382 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6385 switch (rB(ctx
->opcode
)) {
6387 gen_helper_4xx_tlbwe_hi(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6388 cpu_gpr
[rS(ctx
->opcode
)]);
6391 gen_helper_4xx_tlbwe_lo(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6392 cpu_gpr
[rS(ctx
->opcode
)]);
6395 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6401 /* TLB management - PowerPC 440 implementation */
6404 static void gen_tlbre_440(DisasContext
*ctx
)
6406 #if defined(CONFIG_USER_ONLY)
6407 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6409 if (unlikely(!ctx
->mem_idx
)) {
6410 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6413 switch (rB(ctx
->opcode
)) {
6418 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
6419 gen_helper_440_tlbre(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6420 t0
, cpu_gpr
[rA(ctx
->opcode
)]);
6421 tcg_temp_free_i32(t0
);
6425 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6431 /* tlbsx - tlbsx. */
6432 static void gen_tlbsx_440(DisasContext
*ctx
)
6434 #if defined(CONFIG_USER_ONLY)
6435 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6438 if (unlikely(!ctx
->mem_idx
)) {
6439 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6442 t0
= tcg_temp_new();
6443 gen_addr_reg_index(ctx
, t0
);
6444 gen_helper_440_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
6446 if (Rc(ctx
->opcode
)) {
6447 int l1
= gen_new_label();
6448 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
6449 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
6450 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
6457 static void gen_tlbwe_440(DisasContext
*ctx
)
6459 #if defined(CONFIG_USER_ONLY)
6460 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6462 if (unlikely(!ctx
->mem_idx
)) {
6463 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6466 switch (rB(ctx
->opcode
)) {
6471 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
6472 gen_helper_440_tlbwe(cpu_env
, t0
, cpu_gpr
[rA(ctx
->opcode
)],
6473 cpu_gpr
[rS(ctx
->opcode
)]);
6474 tcg_temp_free_i32(t0
);
6478 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6484 /* TLB management - PowerPC BookE 2.06 implementation */
6487 static void gen_tlbre_booke206(DisasContext
*ctx
)
6489 #if defined(CONFIG_USER_ONLY)
6490 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6492 if (unlikely(!ctx
->mem_idx
)) {
6493 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6497 gen_helper_booke206_tlbre(cpu_env
);
6501 /* tlbsx - tlbsx. */
6502 static void gen_tlbsx_booke206(DisasContext
*ctx
)
6504 #if defined(CONFIG_USER_ONLY)
6505 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6508 if (unlikely(!ctx
->mem_idx
)) {
6509 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6513 if (rA(ctx
->opcode
)) {
6514 t0
= tcg_temp_new();
6515 tcg_gen_mov_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)]);
6517 t0
= tcg_const_tl(0);
6520 tcg_gen_add_tl(t0
, t0
, cpu_gpr
[rB(ctx
->opcode
)]);
6521 gen_helper_booke206_tlbsx(cpu_env
, t0
);
6527 static void gen_tlbwe_booke206(DisasContext
*ctx
)
6529 #if defined(CONFIG_USER_ONLY)
6530 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6532 if (unlikely(!ctx
->mem_idx
)) {
6533 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6536 gen_update_nip(ctx
, ctx
->nip
- 4);
6537 gen_helper_booke206_tlbwe(cpu_env
);
6541 static void gen_tlbivax_booke206(DisasContext
*ctx
)
6543 #if defined(CONFIG_USER_ONLY)
6544 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6547 if (unlikely(!ctx
->mem_idx
)) {
6548 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6552 t0
= tcg_temp_new();
6553 gen_addr_reg_index(ctx
, t0
);
6555 gen_helper_booke206_tlbivax(cpu_env
, t0
);
6560 static void gen_tlbilx_booke206(DisasContext
*ctx
)
6562 #if defined(CONFIG_USER_ONLY)
6563 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6566 if (unlikely(!ctx
->mem_idx
)) {
6567 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6571 t0
= tcg_temp_new();
6572 gen_addr_reg_index(ctx
, t0
);
6574 switch((ctx
->opcode
>> 21) & 0x3) {
6576 gen_helper_booke206_tlbilx0(cpu_env
, t0
);
6579 gen_helper_booke206_tlbilx1(cpu_env
, t0
);
6582 gen_helper_booke206_tlbilx3(cpu_env
, t0
);
6585 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6595 static void gen_wrtee(DisasContext
*ctx
)
6597 #if defined(CONFIG_USER_ONLY)
6598 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6601 if (unlikely(!ctx
->mem_idx
)) {
6602 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6605 t0
= tcg_temp_new();
6606 tcg_gen_andi_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)], (1 << MSR_EE
));
6607 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6608 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
6610 /* Stop translation to have a chance to raise an exception
6611 * if we just set msr_ee to 1
6613 gen_stop_exception(ctx
);
6618 static void gen_wrteei(DisasContext
*ctx
)
6620 #if defined(CONFIG_USER_ONLY)
6621 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6623 if (unlikely(!ctx
->mem_idx
)) {
6624 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6627 if (ctx
->opcode
& 0x00008000) {
6628 tcg_gen_ori_tl(cpu_msr
, cpu_msr
, (1 << MSR_EE
));
6629 /* Stop translation to have a chance to raise an exception */
6630 gen_stop_exception(ctx
);
6632 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6637 /* PowerPC 440 specific instructions */
6640 static void gen_dlmzb(DisasContext
*ctx
)
6642 TCGv_i32 t0
= tcg_const_i32(Rc(ctx
->opcode
));
6643 gen_helper_dlmzb(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
6644 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
6645 tcg_temp_free_i32(t0
);
6648 /* mbar replaces eieio on 440 */
6649 static void gen_mbar(DisasContext
*ctx
)
6651 /* interpreted as no-op */
6654 /* msync replaces sync on 440 */
6655 static void gen_msync_4xx(DisasContext
*ctx
)
6657 /* interpreted as no-op */
6661 static void gen_icbt_440(DisasContext
*ctx
)
6663 /* interpreted as no-op */
6664 /* XXX: specification say this is treated as a load by the MMU
6665 * but does not generate any exception
6669 /* Embedded.Processor Control */
6671 static void gen_msgclr(DisasContext
*ctx
)
6673 #if defined(CONFIG_USER_ONLY)
6674 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6676 if (unlikely(ctx
->mem_idx
== 0)) {
6677 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6681 gen_helper_msgclr(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6685 static void gen_msgsnd(DisasContext
*ctx
)
6687 #if defined(CONFIG_USER_ONLY)
6688 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6690 if (unlikely(ctx
->mem_idx
== 0)) {
6691 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6695 gen_helper_msgsnd(cpu_gpr
[rB(ctx
->opcode
)]);
6699 /*** Altivec vector extension ***/
6700 /* Altivec registers moves */
6702 static inline TCGv_ptr
gen_avr_ptr(int reg
)
6704 TCGv_ptr r
= tcg_temp_new_ptr();
6705 tcg_gen_addi_ptr(r
, cpu_env
, offsetof(CPUPPCState
, avr
[reg
]));
6709 #define GEN_VR_LDX(name, opc2, opc3) \
6710 static void glue(gen_, name)(DisasContext *ctx) \
6713 if (unlikely(!ctx->altivec_enabled)) { \
6714 gen_exception(ctx, POWERPC_EXCP_VPU); \
6717 gen_set_access_type(ctx, ACCESS_INT); \
6718 EA = tcg_temp_new(); \
6719 gen_addr_reg_index(ctx, EA); \
6720 tcg_gen_andi_tl(EA, EA, ~0xf); \
6721 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary \
6722 64-bit byteswap already. */ \
6723 if (ctx->le_mode) { \
6724 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6725 tcg_gen_addi_tl(EA, EA, 8); \
6726 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6728 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6729 tcg_gen_addi_tl(EA, EA, 8); \
6730 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6732 tcg_temp_free(EA); \
6735 #define GEN_VR_STX(name, opc2, opc3) \
6736 static void gen_st##name(DisasContext *ctx) \
6739 if (unlikely(!ctx->altivec_enabled)) { \
6740 gen_exception(ctx, POWERPC_EXCP_VPU); \
6743 gen_set_access_type(ctx, ACCESS_INT); \
6744 EA = tcg_temp_new(); \
6745 gen_addr_reg_index(ctx, EA); \
6746 tcg_gen_andi_tl(EA, EA, ~0xf); \
6747 /* We only need to swap high and low halves. gen_qemu_st64 does necessary \
6748 64-bit byteswap already. */ \
6749 if (ctx->le_mode) { \
6750 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6751 tcg_gen_addi_tl(EA, EA, 8); \
6752 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6754 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6755 tcg_gen_addi_tl(EA, EA, 8); \
6756 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6758 tcg_temp_free(EA); \
6761 #define GEN_VR_LVE(name, opc2, opc3) \
6762 static void gen_lve##name(DisasContext *ctx) \
6766 if (unlikely(!ctx->altivec_enabled)) { \
6767 gen_exception(ctx, POWERPC_EXCP_VPU); \
6770 gen_set_access_type(ctx, ACCESS_INT); \
6771 EA = tcg_temp_new(); \
6772 gen_addr_reg_index(ctx, EA); \
6773 rs = gen_avr_ptr(rS(ctx->opcode)); \
6774 gen_helper_lve##name(cpu_env, rs, EA); \
6775 tcg_temp_free(EA); \
6776 tcg_temp_free_ptr(rs); \
6779 #define GEN_VR_STVE(name, opc2, opc3) \
6780 static void gen_stve##name(DisasContext *ctx) \
6784 if (unlikely(!ctx->altivec_enabled)) { \
6785 gen_exception(ctx, POWERPC_EXCP_VPU); \
6788 gen_set_access_type(ctx, ACCESS_INT); \
6789 EA = tcg_temp_new(); \
6790 gen_addr_reg_index(ctx, EA); \
6791 rs = gen_avr_ptr(rS(ctx->opcode)); \
6792 gen_helper_stve##name(cpu_env, rs, EA); \
6793 tcg_temp_free(EA); \
6794 tcg_temp_free_ptr(rs); \
6797 GEN_VR_LDX(lvx
, 0x07, 0x03);
6798 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
6799 GEN_VR_LDX(lvxl
, 0x07, 0x0B);
6801 GEN_VR_LVE(bx
, 0x07, 0x00);
6802 GEN_VR_LVE(hx
, 0x07, 0x01);
6803 GEN_VR_LVE(wx
, 0x07, 0x02);
6805 GEN_VR_STX(svx
, 0x07, 0x07);
6806 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
6807 GEN_VR_STX(svxl
, 0x07, 0x0F);
6809 GEN_VR_STVE(bx
, 0x07, 0x04);
6810 GEN_VR_STVE(hx
, 0x07, 0x05);
6811 GEN_VR_STVE(wx
, 0x07, 0x06);
6813 static void gen_lvsl(DisasContext
*ctx
)
6817 if (unlikely(!ctx
->altivec_enabled
)) {
6818 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6821 EA
= tcg_temp_new();
6822 gen_addr_reg_index(ctx
, EA
);
6823 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6824 gen_helper_lvsl(rd
, EA
);
6826 tcg_temp_free_ptr(rd
);
6829 static void gen_lvsr(DisasContext
*ctx
)
6833 if (unlikely(!ctx
->altivec_enabled
)) {
6834 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6837 EA
= tcg_temp_new();
6838 gen_addr_reg_index(ctx
, EA
);
6839 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6840 gen_helper_lvsr(rd
, EA
);
6842 tcg_temp_free_ptr(rd
);
6845 static void gen_mfvscr(DisasContext
*ctx
)
6848 if (unlikely(!ctx
->altivec_enabled
)) {
6849 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6852 tcg_gen_movi_i64(cpu_avrh
[rD(ctx
->opcode
)], 0);
6853 t
= tcg_temp_new_i32();
6854 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUPPCState
, vscr
));
6855 tcg_gen_extu_i32_i64(cpu_avrl
[rD(ctx
->opcode
)], t
);
6856 tcg_temp_free_i32(t
);
6859 static void gen_mtvscr(DisasContext
*ctx
)
6862 if (unlikely(!ctx
->altivec_enabled
)) {
6863 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6866 p
= gen_avr_ptr(rD(ctx
->opcode
));
6867 gen_helper_mtvscr(cpu_env
, p
);
6868 tcg_temp_free_ptr(p
);
6871 /* Logical operations */
6872 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
6873 static void glue(gen_, name)(DisasContext *ctx) \
6875 if (unlikely(!ctx->altivec_enabled)) { \
6876 gen_exception(ctx, POWERPC_EXCP_VPU); \
6879 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6880 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6883 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16);
6884 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17);
6885 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18);
6886 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19);
6887 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20);
6888 GEN_VX_LOGICAL(veqv
, tcg_gen_eqv_i64
, 2, 26);
6889 GEN_VX_LOGICAL(vnand
, tcg_gen_nand_i64
, 2, 22);
6890 GEN_VX_LOGICAL(vorc
, tcg_gen_orc_i64
, 2, 21);
6892 #define GEN_VXFORM(name, opc2, opc3) \
6893 static void glue(gen_, name)(DisasContext *ctx) \
6895 TCGv_ptr ra, rb, rd; \
6896 if (unlikely(!ctx->altivec_enabled)) { \
6897 gen_exception(ctx, POWERPC_EXCP_VPU); \
6900 ra = gen_avr_ptr(rA(ctx->opcode)); \
6901 rb = gen_avr_ptr(rB(ctx->opcode)); \
6902 rd = gen_avr_ptr(rD(ctx->opcode)); \
6903 gen_helper_##name (rd, ra, rb); \
6904 tcg_temp_free_ptr(ra); \
6905 tcg_temp_free_ptr(rb); \
6906 tcg_temp_free_ptr(rd); \
6909 #define GEN_VXFORM_ENV(name, opc2, opc3) \
6910 static void glue(gen_, name)(DisasContext *ctx) \
6912 TCGv_ptr ra, rb, rd; \
6913 if (unlikely(!ctx->altivec_enabled)) { \
6914 gen_exception(ctx, POWERPC_EXCP_VPU); \
6917 ra = gen_avr_ptr(rA(ctx->opcode)); \
6918 rb = gen_avr_ptr(rB(ctx->opcode)); \
6919 rd = gen_avr_ptr(rD(ctx->opcode)); \
6920 gen_helper_##name(cpu_env, rd, ra, rb); \
6921 tcg_temp_free_ptr(ra); \
6922 tcg_temp_free_ptr(rb); \
6923 tcg_temp_free_ptr(rd); \
6926 #define GEN_VXFORM3(name, opc2, opc3) \
6927 static void glue(gen_, name)(DisasContext *ctx) \
6929 TCGv_ptr ra, rb, rc, rd; \
6930 if (unlikely(!ctx->altivec_enabled)) { \
6931 gen_exception(ctx, POWERPC_EXCP_VPU); \
6934 ra = gen_avr_ptr(rA(ctx->opcode)); \
6935 rb = gen_avr_ptr(rB(ctx->opcode)); \
6936 rc = gen_avr_ptr(rC(ctx->opcode)); \
6937 rd = gen_avr_ptr(rD(ctx->opcode)); \
6938 gen_helper_##name(rd, ra, rb, rc); \
6939 tcg_temp_free_ptr(ra); \
6940 tcg_temp_free_ptr(rb); \
6941 tcg_temp_free_ptr(rc); \
6942 tcg_temp_free_ptr(rd); \
6946 * Support for Altivec instruction pairs that use bit 31 (Rc) as
6947 * an opcode bit. In general, these pairs come from different
6948 * versions of the ISA, so we must also support a pair of flags for
6951 #define GEN_VXFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
6952 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
6954 if ((Rc(ctx->opcode) == 0) && \
6955 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
6957 } else if ((Rc(ctx->opcode) == 1) && \
6958 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
6961 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
6965 GEN_VXFORM(vaddubm
, 0, 0);
6966 GEN_VXFORM(vadduhm
, 0, 1);
6967 GEN_VXFORM(vadduwm
, 0, 2);
6968 GEN_VXFORM(vaddudm
, 0, 3);
6969 GEN_VXFORM(vsububm
, 0, 16);
6970 GEN_VXFORM(vsubuhm
, 0, 17);
6971 GEN_VXFORM(vsubuwm
, 0, 18);
6972 GEN_VXFORM(vsubudm
, 0, 19);
6973 GEN_VXFORM(vmaxub
, 1, 0);
6974 GEN_VXFORM(vmaxuh
, 1, 1);
6975 GEN_VXFORM(vmaxuw
, 1, 2);
6976 GEN_VXFORM(vmaxud
, 1, 3);
6977 GEN_VXFORM(vmaxsb
, 1, 4);
6978 GEN_VXFORM(vmaxsh
, 1, 5);
6979 GEN_VXFORM(vmaxsw
, 1, 6);
6980 GEN_VXFORM(vmaxsd
, 1, 7);
6981 GEN_VXFORM(vminub
, 1, 8);
6982 GEN_VXFORM(vminuh
, 1, 9);
6983 GEN_VXFORM(vminuw
, 1, 10);
6984 GEN_VXFORM(vminud
, 1, 11);
6985 GEN_VXFORM(vminsb
, 1, 12);
6986 GEN_VXFORM(vminsh
, 1, 13);
6987 GEN_VXFORM(vminsw
, 1, 14);
6988 GEN_VXFORM(vminsd
, 1, 15);
6989 GEN_VXFORM(vavgub
, 1, 16);
6990 GEN_VXFORM(vavguh
, 1, 17);
6991 GEN_VXFORM(vavguw
, 1, 18);
6992 GEN_VXFORM(vavgsb
, 1, 20);
6993 GEN_VXFORM(vavgsh
, 1, 21);
6994 GEN_VXFORM(vavgsw
, 1, 22);
6995 GEN_VXFORM(vmrghb
, 6, 0);
6996 GEN_VXFORM(vmrghh
, 6, 1);
6997 GEN_VXFORM(vmrghw
, 6, 2);
6998 GEN_VXFORM(vmrglb
, 6, 4);
6999 GEN_VXFORM(vmrglh
, 6, 5);
7000 GEN_VXFORM(vmrglw
, 6, 6);
7002 static void gen_vmrgew(DisasContext
*ctx
)
7006 if (unlikely(!ctx
->altivec_enabled
)) {
7007 gen_exception(ctx
, POWERPC_EXCP_VPU
);
7010 VT
= rD(ctx
->opcode
);
7011 VA
= rA(ctx
->opcode
);
7012 VB
= rB(ctx
->opcode
);
7013 tmp
= tcg_temp_new_i64();
7014 tcg_gen_shri_i64(tmp
, cpu_avrh
[VB
], 32);
7015 tcg_gen_deposit_i64(cpu_avrh
[VT
], cpu_avrh
[VA
], tmp
, 0, 32);
7016 tcg_gen_shri_i64(tmp
, cpu_avrl
[VB
], 32);
7017 tcg_gen_deposit_i64(cpu_avrl
[VT
], cpu_avrl
[VA
], tmp
, 0, 32);
7018 tcg_temp_free_i64(tmp
);
7021 static void gen_vmrgow(DisasContext
*ctx
)
7024 if (unlikely(!ctx
->altivec_enabled
)) {
7025 gen_exception(ctx
, POWERPC_EXCP_VPU
);
7028 VT
= rD(ctx
->opcode
);
7029 VA
= rA(ctx
->opcode
);
7030 VB
= rB(ctx
->opcode
);
7032 tcg_gen_deposit_i64(cpu_avrh
[VT
], cpu_avrh
[VB
], cpu_avrh
[VA
], 32, 32);
7033 tcg_gen_deposit_i64(cpu_avrl
[VT
], cpu_avrl
[VB
], cpu_avrl
[VA
], 32, 32);
7036 GEN_VXFORM(vmuloub
, 4, 0);
7037 GEN_VXFORM(vmulouh
, 4, 1);
7038 GEN_VXFORM(vmulouw
, 4, 2);
7039 GEN_VXFORM(vmuluwm
, 4, 2);
7040 GEN_VXFORM_DUAL(vmulouw
, PPC_ALTIVEC
, PPC_NONE
,
7041 vmuluwm
, PPC_NONE
, PPC2_ALTIVEC_207
)
7042 GEN_VXFORM(vmulosb
, 4, 4);
7043 GEN_VXFORM(vmulosh
, 4, 5);
7044 GEN_VXFORM(vmulosw
, 4, 6);
7045 GEN_VXFORM(vmuleub
, 4, 8);
7046 GEN_VXFORM(vmuleuh
, 4, 9);
7047 GEN_VXFORM(vmuleuw
, 4, 10);
7048 GEN_VXFORM(vmulesb
, 4, 12);
7049 GEN_VXFORM(vmulesh
, 4, 13);
7050 GEN_VXFORM(vmulesw
, 4, 14);
7051 GEN_VXFORM(vslb
, 2, 4);
7052 GEN_VXFORM(vslh
, 2, 5);
7053 GEN_VXFORM(vslw
, 2, 6);
7054 GEN_VXFORM(vsld
, 2, 23);
7055 GEN_VXFORM(vsrb
, 2, 8);
7056 GEN_VXFORM(vsrh
, 2, 9);
7057 GEN_VXFORM(vsrw
, 2, 10);
7058 GEN_VXFORM(vsrd
, 2, 27);
7059 GEN_VXFORM(vsrab
, 2, 12);
7060 GEN_VXFORM(vsrah
, 2, 13);
7061 GEN_VXFORM(vsraw
, 2, 14);
7062 GEN_VXFORM(vsrad
, 2, 15);
7063 GEN_VXFORM(vslo
, 6, 16);
7064 GEN_VXFORM(vsro
, 6, 17);
7065 GEN_VXFORM(vaddcuw
, 0, 6);
7066 GEN_VXFORM(vsubcuw
, 0, 22);
7067 GEN_VXFORM_ENV(vaddubs
, 0, 8);
7068 GEN_VXFORM_ENV(vadduhs
, 0, 9);
7069 GEN_VXFORM_ENV(vadduws
, 0, 10);
7070 GEN_VXFORM_ENV(vaddsbs
, 0, 12);
7071 GEN_VXFORM_ENV(vaddshs
, 0, 13);
7072 GEN_VXFORM_ENV(vaddsws
, 0, 14);
7073 GEN_VXFORM_ENV(vsububs
, 0, 24);
7074 GEN_VXFORM_ENV(vsubuhs
, 0, 25);
7075 GEN_VXFORM_ENV(vsubuws
, 0, 26);
7076 GEN_VXFORM_ENV(vsubsbs
, 0, 28);
7077 GEN_VXFORM_ENV(vsubshs
, 0, 29);
7078 GEN_VXFORM_ENV(vsubsws
, 0, 30);
7079 GEN_VXFORM(vadduqm
, 0, 4);
7080 GEN_VXFORM(vaddcuq
, 0, 5);
7081 GEN_VXFORM3(vaddeuqm
, 30, 0);
7082 GEN_VXFORM3(vaddecuq
, 30, 0);
7083 GEN_VXFORM_DUAL(vaddeuqm
, PPC_NONE
, PPC2_ALTIVEC_207
, \
7084 vaddecuq
, PPC_NONE
, PPC2_ALTIVEC_207
)
7085 GEN_VXFORM(vsubuqm
, 0, 20);
7086 GEN_VXFORM(vsubcuq
, 0, 21);
7087 GEN_VXFORM3(vsubeuqm
, 31, 0);
7088 GEN_VXFORM3(vsubecuq
, 31, 0);
7089 GEN_VXFORM_DUAL(vsubeuqm
, PPC_NONE
, PPC2_ALTIVEC_207
, \
7090 vsubecuq
, PPC_NONE
, PPC2_ALTIVEC_207
)
7091 GEN_VXFORM(vrlb
, 2, 0);
7092 GEN_VXFORM(vrlh
, 2, 1);
7093 GEN_VXFORM(vrlw
, 2, 2);
7094 GEN_VXFORM(vrld
, 2, 3);
7095 GEN_VXFORM(vsl
, 2, 7);
7096 GEN_VXFORM(vsr
, 2, 11);
7097 GEN_VXFORM_ENV(vpkuhum
, 7, 0);
7098 GEN_VXFORM_ENV(vpkuwum
, 7, 1);
7099 GEN_VXFORM_ENV(vpkudum
, 7, 17);
7100 GEN_VXFORM_ENV(vpkuhus
, 7, 2);
7101 GEN_VXFORM_ENV(vpkuwus
, 7, 3);
7102 GEN_VXFORM_ENV(vpkudus
, 7, 19);
7103 GEN_VXFORM_ENV(vpkshus
, 7, 4);
7104 GEN_VXFORM_ENV(vpkswus
, 7, 5);
7105 GEN_VXFORM_ENV(vpksdus
, 7, 21);
7106 GEN_VXFORM_ENV(vpkshss
, 7, 6);
7107 GEN_VXFORM_ENV(vpkswss
, 7, 7);
7108 GEN_VXFORM_ENV(vpksdss
, 7, 23);
7109 GEN_VXFORM(vpkpx
, 7, 12);
7110 GEN_VXFORM_ENV(vsum4ubs
, 4, 24);
7111 GEN_VXFORM_ENV(vsum4sbs
, 4, 28);
7112 GEN_VXFORM_ENV(vsum4shs
, 4, 25);
7113 GEN_VXFORM_ENV(vsum2sws
, 4, 26);
7114 GEN_VXFORM_ENV(vsumsws
, 4, 30);
7115 GEN_VXFORM_ENV(vaddfp
, 5, 0);
7116 GEN_VXFORM_ENV(vsubfp
, 5, 1);
7117 GEN_VXFORM_ENV(vmaxfp
, 5, 16);
7118 GEN_VXFORM_ENV(vminfp
, 5, 17);
7120 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
7121 static void glue(gen_, name)(DisasContext *ctx) \
7123 TCGv_ptr ra, rb, rd; \
7124 if (unlikely(!ctx->altivec_enabled)) { \
7125 gen_exception(ctx, POWERPC_EXCP_VPU); \
7128 ra = gen_avr_ptr(rA(ctx->opcode)); \
7129 rb = gen_avr_ptr(rB(ctx->opcode)); \
7130 rd = gen_avr_ptr(rD(ctx->opcode)); \
7131 gen_helper_##opname(cpu_env, rd, ra, rb); \
7132 tcg_temp_free_ptr(ra); \
7133 tcg_temp_free_ptr(rb); \
7134 tcg_temp_free_ptr(rd); \
7137 #define GEN_VXRFORM(name, opc2, opc3) \
7138 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
7139 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
7142 * Support for Altivec instructions that use bit 31 (Rc) as an opcode
7143 * bit but also use bit 21 as an actual Rc bit. In general, thse pairs
7144 * come from different versions of the ISA, so we must also support a
7145 * pair of flags for each instruction.
7147 #define GEN_VXRFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
7148 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7150 if ((Rc(ctx->opcode) == 0) && \
7151 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
7152 if (Rc21(ctx->opcode) == 0) { \
7155 gen_##name0##_(ctx); \
7157 } else if ((Rc(ctx->opcode) == 1) && \
7158 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
7159 if (Rc21(ctx->opcode) == 0) { \
7162 gen_##name1##_(ctx); \
7165 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
7169 GEN_VXRFORM(vcmpequb
, 3, 0)
7170 GEN_VXRFORM(vcmpequh
, 3, 1)
7171 GEN_VXRFORM(vcmpequw
, 3, 2)
7172 GEN_VXRFORM(vcmpequd
, 3, 3)
7173 GEN_VXRFORM(vcmpgtsb
, 3, 12)
7174 GEN_VXRFORM(vcmpgtsh
, 3, 13)
7175 GEN_VXRFORM(vcmpgtsw
, 3, 14)
7176 GEN_VXRFORM(vcmpgtsd
, 3, 15)
7177 GEN_VXRFORM(vcmpgtub
, 3, 8)
7178 GEN_VXRFORM(vcmpgtuh
, 3, 9)
7179 GEN_VXRFORM(vcmpgtuw
, 3, 10)
7180 GEN_VXRFORM(vcmpgtud
, 3, 11)
7181 GEN_VXRFORM(vcmpeqfp
, 3, 3)
7182 GEN_VXRFORM(vcmpgefp
, 3, 7)
7183 GEN_VXRFORM(vcmpgtfp
, 3, 11)
7184 GEN_VXRFORM(vcmpbfp
, 3, 15)
7186 GEN_VXRFORM_DUAL(vcmpeqfp
, PPC_ALTIVEC
, PPC_NONE
, \
7187 vcmpequd
, PPC_NONE
, PPC2_ALTIVEC_207
)
7188 GEN_VXRFORM_DUAL(vcmpbfp
, PPC_ALTIVEC
, PPC_NONE
, \
7189 vcmpgtsd
, PPC_NONE
, PPC2_ALTIVEC_207
)
7190 GEN_VXRFORM_DUAL(vcmpgtfp
, PPC_ALTIVEC
, PPC_NONE
, \
7191 vcmpgtud
, PPC_NONE
, PPC2_ALTIVEC_207
)
7193 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
7194 static void glue(gen_, name)(DisasContext *ctx) \
7198 if (unlikely(!ctx->altivec_enabled)) { \
7199 gen_exception(ctx, POWERPC_EXCP_VPU); \
7202 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7203 rd = gen_avr_ptr(rD(ctx->opcode)); \
7204 gen_helper_##name (rd, simm); \
7205 tcg_temp_free_i32(simm); \
7206 tcg_temp_free_ptr(rd); \
7209 GEN_VXFORM_SIMM(vspltisb
, 6, 12);
7210 GEN_VXFORM_SIMM(vspltish
, 6, 13);
7211 GEN_VXFORM_SIMM(vspltisw
, 6, 14);
7213 #define GEN_VXFORM_NOA(name, opc2, opc3) \
7214 static void glue(gen_, name)(DisasContext *ctx) \
7217 if (unlikely(!ctx->altivec_enabled)) { \
7218 gen_exception(ctx, POWERPC_EXCP_VPU); \
7221 rb = gen_avr_ptr(rB(ctx->opcode)); \
7222 rd = gen_avr_ptr(rD(ctx->opcode)); \
7223 gen_helper_##name (rd, rb); \
7224 tcg_temp_free_ptr(rb); \
7225 tcg_temp_free_ptr(rd); \
7228 #define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
7229 static void glue(gen_, name)(DisasContext *ctx) \
7233 if (unlikely(!ctx->altivec_enabled)) { \
7234 gen_exception(ctx, POWERPC_EXCP_VPU); \
7237 rb = gen_avr_ptr(rB(ctx->opcode)); \
7238 rd = gen_avr_ptr(rD(ctx->opcode)); \
7239 gen_helper_##name(cpu_env, rd, rb); \
7240 tcg_temp_free_ptr(rb); \
7241 tcg_temp_free_ptr(rd); \
7244 GEN_VXFORM_NOA(vupkhsb
, 7, 8);
7245 GEN_VXFORM_NOA(vupkhsh
, 7, 9);
7246 GEN_VXFORM_NOA(vupkhsw
, 7, 25);
7247 GEN_VXFORM_NOA(vupklsb
, 7, 10);
7248 GEN_VXFORM_NOA(vupklsh
, 7, 11);
7249 GEN_VXFORM_NOA(vupklsw
, 7, 27);
7250 GEN_VXFORM_NOA(vupkhpx
, 7, 13);
7251 GEN_VXFORM_NOA(vupklpx
, 7, 15);
7252 GEN_VXFORM_NOA_ENV(vrefp
, 5, 4);
7253 GEN_VXFORM_NOA_ENV(vrsqrtefp
, 5, 5);
7254 GEN_VXFORM_NOA_ENV(vexptefp
, 5, 6);
7255 GEN_VXFORM_NOA_ENV(vlogefp
, 5, 7);
7256 GEN_VXFORM_NOA_ENV(vrfim
, 5, 8);
7257 GEN_VXFORM_NOA_ENV(vrfin
, 5, 9);
7258 GEN_VXFORM_NOA_ENV(vrfip
, 5, 10);
7259 GEN_VXFORM_NOA_ENV(vrfiz
, 5, 11);
7261 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
7262 static void glue(gen_, name)(DisasContext *ctx) \
7266 if (unlikely(!ctx->altivec_enabled)) { \
7267 gen_exception(ctx, POWERPC_EXCP_VPU); \
7270 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7271 rd = gen_avr_ptr(rD(ctx->opcode)); \
7272 gen_helper_##name (rd, simm); \
7273 tcg_temp_free_i32(simm); \
7274 tcg_temp_free_ptr(rd); \
7277 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
7278 static void glue(gen_, name)(DisasContext *ctx) \
7282 if (unlikely(!ctx->altivec_enabled)) { \
7283 gen_exception(ctx, POWERPC_EXCP_VPU); \
7286 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7287 rb = gen_avr_ptr(rB(ctx->opcode)); \
7288 rd = gen_avr_ptr(rD(ctx->opcode)); \
7289 gen_helper_##name (rd, rb, uimm); \
7290 tcg_temp_free_i32(uimm); \
7291 tcg_temp_free_ptr(rb); \
7292 tcg_temp_free_ptr(rd); \
7295 #define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
7296 static void glue(gen_, name)(DisasContext *ctx) \
7301 if (unlikely(!ctx->altivec_enabled)) { \
7302 gen_exception(ctx, POWERPC_EXCP_VPU); \
7305 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7306 rb = gen_avr_ptr(rB(ctx->opcode)); \
7307 rd = gen_avr_ptr(rD(ctx->opcode)); \
7308 gen_helper_##name(cpu_env, rd, rb, uimm); \
7309 tcg_temp_free_i32(uimm); \
7310 tcg_temp_free_ptr(rb); \
7311 tcg_temp_free_ptr(rd); \
7314 GEN_VXFORM_UIMM(vspltb
, 6, 8);
7315 GEN_VXFORM_UIMM(vsplth
, 6, 9);
7316 GEN_VXFORM_UIMM(vspltw
, 6, 10);
7317 GEN_VXFORM_UIMM_ENV(vcfux
, 5, 12);
7318 GEN_VXFORM_UIMM_ENV(vcfsx
, 5, 13);
7319 GEN_VXFORM_UIMM_ENV(vctuxs
, 5, 14);
7320 GEN_VXFORM_UIMM_ENV(vctsxs
, 5, 15);
7322 static void gen_vsldoi(DisasContext
*ctx
)
7324 TCGv_ptr ra
, rb
, rd
;
7326 if (unlikely(!ctx
->altivec_enabled
)) {
7327 gen_exception(ctx
, POWERPC_EXCP_VPU
);
7330 ra
= gen_avr_ptr(rA(ctx
->opcode
));
7331 rb
= gen_avr_ptr(rB(ctx
->opcode
));
7332 rd
= gen_avr_ptr(rD(ctx
->opcode
));
7333 sh
= tcg_const_i32(VSH(ctx
->opcode
));
7334 gen_helper_vsldoi (rd
, ra
, rb
, sh
);
7335 tcg_temp_free_ptr(ra
);
7336 tcg_temp_free_ptr(rb
);
7337 tcg_temp_free_ptr(rd
);
7338 tcg_temp_free_i32(sh
);
7341 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
7342 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7344 TCGv_ptr ra, rb, rc, rd; \
7345 if (unlikely(!ctx->altivec_enabled)) { \
7346 gen_exception(ctx, POWERPC_EXCP_VPU); \
7349 ra = gen_avr_ptr(rA(ctx->opcode)); \
7350 rb = gen_avr_ptr(rB(ctx->opcode)); \
7351 rc = gen_avr_ptr(rC(ctx->opcode)); \
7352 rd = gen_avr_ptr(rD(ctx->opcode)); \
7353 if (Rc(ctx->opcode)) { \
7354 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
7356 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
7358 tcg_temp_free_ptr(ra); \
7359 tcg_temp_free_ptr(rb); \
7360 tcg_temp_free_ptr(rc); \
7361 tcg_temp_free_ptr(rd); \
7364 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16)
7366 static void gen_vmladduhm(DisasContext
*ctx
)
7368 TCGv_ptr ra
, rb
, rc
, rd
;
7369 if (unlikely(!ctx
->altivec_enabled
)) {
7370 gen_exception(ctx
, POWERPC_EXCP_VPU
);
7373 ra
= gen_avr_ptr(rA(ctx
->opcode
));
7374 rb
= gen_avr_ptr(rB(ctx
->opcode
));
7375 rc
= gen_avr_ptr(rC(ctx
->opcode
));
7376 rd
= gen_avr_ptr(rD(ctx
->opcode
));
7377 gen_helper_vmladduhm(rd
, ra
, rb
, rc
);
7378 tcg_temp_free_ptr(ra
);
7379 tcg_temp_free_ptr(rb
);
7380 tcg_temp_free_ptr(rc
);
7381 tcg_temp_free_ptr(rd
);
7384 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18)
7385 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19)
7386 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20)
7387 GEN_VAFORM_PAIRED(vsel
, vperm
, 21)
7388 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23)
7390 GEN_VXFORM_NOA(vclzb
, 1, 28)
7391 GEN_VXFORM_NOA(vclzh
, 1, 29)
7392 GEN_VXFORM_NOA(vclzw
, 1, 30)
7393 GEN_VXFORM_NOA(vclzd
, 1, 31)
7394 GEN_VXFORM_NOA(vpopcntb
, 1, 28)
7395 GEN_VXFORM_NOA(vpopcnth
, 1, 29)
7396 GEN_VXFORM_NOA(vpopcntw
, 1, 30)
7397 GEN_VXFORM_NOA(vpopcntd
, 1, 31)
7398 GEN_VXFORM_DUAL(vclzb
, PPC_NONE
, PPC2_ALTIVEC_207
, \
7399 vpopcntb
, PPC_NONE
, PPC2_ALTIVEC_207
)
7400 GEN_VXFORM_DUAL(vclzh
, PPC_NONE
, PPC2_ALTIVEC_207
, \
7401 vpopcnth
, PPC_NONE
, PPC2_ALTIVEC_207
)
7402 GEN_VXFORM_DUAL(vclzw
, PPC_NONE
, PPC2_ALTIVEC_207
, \
7403 vpopcntw
, PPC_NONE
, PPC2_ALTIVEC_207
)
7404 GEN_VXFORM_DUAL(vclzd
, PPC_NONE
, PPC2_ALTIVEC_207
, \
7405 vpopcntd
, PPC_NONE
, PPC2_ALTIVEC_207
)
7406 GEN_VXFORM(vbpermq
, 6, 21);
7407 GEN_VXFORM_NOA(vgbbd
, 6, 20);
7408 GEN_VXFORM(vpmsumb
, 4, 16)
7409 GEN_VXFORM(vpmsumh
, 4, 17)
7410 GEN_VXFORM(vpmsumw
, 4, 18)
7411 GEN_VXFORM(vpmsumd
, 4, 19)
7413 #define GEN_BCD(op) \
7414 static void gen_##op(DisasContext *ctx) \
7416 TCGv_ptr ra, rb, rd; \
7419 if (unlikely(!ctx->altivec_enabled)) { \
7420 gen_exception(ctx, POWERPC_EXCP_VPU); \
7424 ra = gen_avr_ptr(rA(ctx->opcode)); \
7425 rb = gen_avr_ptr(rB(ctx->opcode)); \
7426 rd = gen_avr_ptr(rD(ctx->opcode)); \
7428 ps = tcg_const_i32((ctx->opcode & 0x200) != 0); \
7430 gen_helper_##op(cpu_crf[6], rd, ra, rb, ps); \
7432 tcg_temp_free_ptr(ra); \
7433 tcg_temp_free_ptr(rb); \
7434 tcg_temp_free_ptr(rd); \
7435 tcg_temp_free_i32(ps); \
7441 GEN_VXFORM_DUAL(vsububm
, PPC_ALTIVEC
, PPC_NONE
, \
7442 bcdadd
, PPC_NONE
, PPC2_ALTIVEC_207
)
7443 GEN_VXFORM_DUAL(vsububs
, PPC_ALTIVEC
, PPC_NONE
, \
7444 bcdadd
, PPC_NONE
, PPC2_ALTIVEC_207
)
7445 GEN_VXFORM_DUAL(vsubuhm
, PPC_ALTIVEC
, PPC_NONE
, \
7446 bcdsub
, PPC_NONE
, PPC2_ALTIVEC_207
)
7447 GEN_VXFORM_DUAL(vsubuhs
, PPC_ALTIVEC
, PPC_NONE
, \
7448 bcdsub
, PPC_NONE
, PPC2_ALTIVEC_207
)
7450 static void gen_vsbox(DisasContext
*ctx
)
7453 if (unlikely(!ctx
->altivec_enabled
)) {
7454 gen_exception(ctx
, POWERPC_EXCP_VPU
);
7457 ra
= gen_avr_ptr(rA(ctx
->opcode
));
7458 rd
= gen_avr_ptr(rD(ctx
->opcode
));
7459 gen_helper_vsbox(rd
, ra
);
7460 tcg_temp_free_ptr(ra
);
7461 tcg_temp_free_ptr(rd
);
7464 GEN_VXFORM(vcipher
, 4, 20)
7465 GEN_VXFORM(vcipherlast
, 4, 20)
7466 GEN_VXFORM(vncipher
, 4, 21)
7467 GEN_VXFORM(vncipherlast
, 4, 21)
7469 GEN_VXFORM_DUAL(vcipher
, PPC_NONE
, PPC2_ALTIVEC_207
,
7470 vcipherlast
, PPC_NONE
, PPC2_ALTIVEC_207
)
7471 GEN_VXFORM_DUAL(vncipher
, PPC_NONE
, PPC2_ALTIVEC_207
,
7472 vncipherlast
, PPC_NONE
, PPC2_ALTIVEC_207
)
7474 #define VSHASIGMA(op) \
7475 static void gen_##op(DisasContext *ctx) \
7479 if (unlikely(!ctx->altivec_enabled)) { \
7480 gen_exception(ctx, POWERPC_EXCP_VPU); \
7483 ra = gen_avr_ptr(rA(ctx->opcode)); \
7484 rd = gen_avr_ptr(rD(ctx->opcode)); \
7485 st_six = tcg_const_i32(rB(ctx->opcode)); \
7486 gen_helper_##op(rd, ra, st_six); \
7487 tcg_temp_free_ptr(ra); \
7488 tcg_temp_free_ptr(rd); \
7489 tcg_temp_free_i32(st_six); \
7492 VSHASIGMA(vshasigmaw
)
7493 VSHASIGMA(vshasigmad
)
7495 GEN_VXFORM3(vpermxor
, 22, 0xFF)
7496 GEN_VXFORM_DUAL(vsldoi
, PPC_ALTIVEC
, PPC_NONE
,
7497 vpermxor
, PPC_NONE
, PPC2_ALTIVEC_207
)
7499 /*** VSX extension ***/
7501 static inline TCGv_i64
cpu_vsrh(int n
)
7506 return cpu_avrh
[n
-32];
7510 static inline TCGv_i64
cpu_vsrl(int n
)
7515 return cpu_avrl
[n
-32];
7519 #define VSX_LOAD_SCALAR(name, operation) \
7520 static void gen_##name(DisasContext *ctx) \
7523 if (unlikely(!ctx->vsx_enabled)) { \
7524 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7527 gen_set_access_type(ctx, ACCESS_INT); \
7528 EA = tcg_temp_new(); \
7529 gen_addr_reg_index(ctx, EA); \
7530 gen_qemu_##operation(ctx, cpu_vsrh(xT(ctx->opcode)), EA); \
7531 /* NOTE: cpu_vsrl is undefined */ \
7532 tcg_temp_free(EA); \
7535 VSX_LOAD_SCALAR(lxsdx
, ld64
)
7536 VSX_LOAD_SCALAR(lxsiwax
, ld32s_i64
)
7537 VSX_LOAD_SCALAR(lxsiwzx
, ld32u_i64
)
7538 VSX_LOAD_SCALAR(lxsspx
, ld32fs
)
7540 static void gen_lxvd2x(DisasContext
*ctx
)
7543 if (unlikely(!ctx
->vsx_enabled
)) {
7544 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7547 gen_set_access_type(ctx
, ACCESS_INT
);
7548 EA
= tcg_temp_new();
7549 gen_addr_reg_index(ctx
, EA
);
7550 gen_qemu_ld64(ctx
, cpu_vsrh(xT(ctx
->opcode
)), EA
);
7551 tcg_gen_addi_tl(EA
, EA
, 8);
7552 gen_qemu_ld64(ctx
, cpu_vsrl(xT(ctx
->opcode
)), EA
);
7556 static void gen_lxvdsx(DisasContext
*ctx
)
7559 if (unlikely(!ctx
->vsx_enabled
)) {
7560 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7563 gen_set_access_type(ctx
, ACCESS_INT
);
7564 EA
= tcg_temp_new();
7565 gen_addr_reg_index(ctx
, EA
);
7566 gen_qemu_ld64(ctx
, cpu_vsrh(xT(ctx
->opcode
)), EA
);
7567 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), cpu_vsrh(xT(ctx
->opcode
)));
7571 static void gen_lxvw4x(DisasContext
*ctx
)
7575 TCGv_i64 xth
= cpu_vsrh(xT(ctx
->opcode
));
7576 TCGv_i64 xtl
= cpu_vsrl(xT(ctx
->opcode
));
7577 if (unlikely(!ctx
->vsx_enabled
)) {
7578 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7581 gen_set_access_type(ctx
, ACCESS_INT
);
7582 EA
= tcg_temp_new();
7583 tmp
= tcg_temp_new_i64();
7585 gen_addr_reg_index(ctx
, EA
);
7586 gen_qemu_ld32u_i64(ctx
, tmp
, EA
);
7587 tcg_gen_addi_tl(EA
, EA
, 4);
7588 gen_qemu_ld32u_i64(ctx
, xth
, EA
);
7589 tcg_gen_deposit_i64(xth
, xth
, tmp
, 32, 32);
7591 tcg_gen_addi_tl(EA
, EA
, 4);
7592 gen_qemu_ld32u_i64(ctx
, tmp
, EA
);
7593 tcg_gen_addi_tl(EA
, EA
, 4);
7594 gen_qemu_ld32u_i64(ctx
, xtl
, EA
);
7595 tcg_gen_deposit_i64(xtl
, xtl
, tmp
, 32, 32);
7598 tcg_temp_free_i64(tmp
);
7601 #define VSX_STORE_SCALAR(name, operation) \
7602 static void gen_##name(DisasContext *ctx) \
7605 if (unlikely(!ctx->vsx_enabled)) { \
7606 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7609 gen_set_access_type(ctx, ACCESS_INT); \
7610 EA = tcg_temp_new(); \
7611 gen_addr_reg_index(ctx, EA); \
7612 gen_qemu_##operation(ctx, cpu_vsrh(xS(ctx->opcode)), EA); \
7613 tcg_temp_free(EA); \
7616 VSX_STORE_SCALAR(stxsdx
, st64
)
7617 VSX_STORE_SCALAR(stxsiwx
, st32_i64
)
7618 VSX_STORE_SCALAR(stxsspx
, st32fs
)
7620 static void gen_stxvd2x(DisasContext
*ctx
)
7623 if (unlikely(!ctx
->vsx_enabled
)) {
7624 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7627 gen_set_access_type(ctx
, ACCESS_INT
);
7628 EA
= tcg_temp_new();
7629 gen_addr_reg_index(ctx
, EA
);
7630 gen_qemu_st64(ctx
, cpu_vsrh(xS(ctx
->opcode
)), EA
);
7631 tcg_gen_addi_tl(EA
, EA
, 8);
7632 gen_qemu_st64(ctx
, cpu_vsrl(xS(ctx
->opcode
)), EA
);
7636 static void gen_stxvw4x(DisasContext
*ctx
)
7640 if (unlikely(!ctx
->vsx_enabled
)) {
7641 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7644 gen_set_access_type(ctx
, ACCESS_INT
);
7645 EA
= tcg_temp_new();
7646 gen_addr_reg_index(ctx
, EA
);
7647 tmp
= tcg_temp_new_i64();
7649 tcg_gen_shri_i64(tmp
, cpu_vsrh(xS(ctx
->opcode
)), 32);
7650 gen_qemu_st32_i64(ctx
, tmp
, EA
);
7651 tcg_gen_addi_tl(EA
, EA
, 4);
7652 gen_qemu_st32_i64(ctx
, cpu_vsrh(xS(ctx
->opcode
)), EA
);
7654 tcg_gen_shri_i64(tmp
, cpu_vsrl(xS(ctx
->opcode
)), 32);
7655 tcg_gen_addi_tl(EA
, EA
, 4);
7656 gen_qemu_st32_i64(ctx
, tmp
, EA
);
7657 tcg_gen_addi_tl(EA
, EA
, 4);
7658 gen_qemu_st32_i64(ctx
, cpu_vsrl(xS(ctx
->opcode
)), EA
);
7661 tcg_temp_free_i64(tmp
);
7664 #define MV_VSRW(name, tcgop1, tcgop2, target, source) \
7665 static void gen_##name(DisasContext *ctx) \
7667 if (xS(ctx->opcode) < 32) { \
7668 if (unlikely(!ctx->fpu_enabled)) { \
7669 gen_exception(ctx, POWERPC_EXCP_FPU); \
7673 if (unlikely(!ctx->altivec_enabled)) { \
7674 gen_exception(ctx, POWERPC_EXCP_VPU); \
7678 TCGv_i64 tmp = tcg_temp_new_i64(); \
7679 tcg_gen_##tcgop1(tmp, source); \
7680 tcg_gen_##tcgop2(target, tmp); \
7681 tcg_temp_free_i64(tmp); \
7685 MV_VSRW(mfvsrwz
, ext32u_i64
, trunc_i64_tl
, cpu_gpr
[rA(ctx
->opcode
)], \
7686 cpu_vsrh(xS(ctx
->opcode
)))
7687 MV_VSRW(mtvsrwa
, extu_tl_i64
, ext32s_i64
, cpu_vsrh(xT(ctx
->opcode
)), \
7688 cpu_gpr
[rA(ctx
->opcode
)])
7689 MV_VSRW(mtvsrwz
, extu_tl_i64
, ext32u_i64
, cpu_vsrh(xT(ctx
->opcode
)), \
7690 cpu_gpr
[rA(ctx
->opcode
)])
7692 #if defined(TARGET_PPC64)
7693 #define MV_VSRD(name, target, source) \
7694 static void gen_##name(DisasContext *ctx) \
7696 if (xS(ctx->opcode) < 32) { \
7697 if (unlikely(!ctx->fpu_enabled)) { \
7698 gen_exception(ctx, POWERPC_EXCP_FPU); \
7702 if (unlikely(!ctx->altivec_enabled)) { \
7703 gen_exception(ctx, POWERPC_EXCP_VPU); \
7707 tcg_gen_mov_i64(target, source); \
7710 MV_VSRD(mfvsrd
, cpu_gpr
[rA(ctx
->opcode
)], cpu_vsrh(xS(ctx
->opcode
)))
7711 MV_VSRD(mtvsrd
, cpu_vsrh(xT(ctx
->opcode
)), cpu_gpr
[rA(ctx
->opcode
)])
7715 static void gen_xxpermdi(DisasContext
*ctx
)
7717 if (unlikely(!ctx
->vsx_enabled
)) {
7718 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7722 if (unlikely((xT(ctx
->opcode
) == xA(ctx
->opcode
)) ||
7723 (xT(ctx
->opcode
) == xB(ctx
->opcode
)))) {
7726 xh
= tcg_temp_new_i64();
7727 xl
= tcg_temp_new_i64();
7729 if ((DM(ctx
->opcode
) & 2) == 0) {
7730 tcg_gen_mov_i64(xh
, cpu_vsrh(xA(ctx
->opcode
)));
7732 tcg_gen_mov_i64(xh
, cpu_vsrl(xA(ctx
->opcode
)));
7734 if ((DM(ctx
->opcode
) & 1) == 0) {
7735 tcg_gen_mov_i64(xl
, cpu_vsrh(xB(ctx
->opcode
)));
7737 tcg_gen_mov_i64(xl
, cpu_vsrl(xB(ctx
->opcode
)));
7740 tcg_gen_mov_i64(cpu_vsrh(xT(ctx
->opcode
)), xh
);
7741 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), xl
);
7743 tcg_temp_free_i64(xh
);
7744 tcg_temp_free_i64(xl
);
7746 if ((DM(ctx
->opcode
) & 2) == 0) {
7747 tcg_gen_mov_i64(cpu_vsrh(xT(ctx
->opcode
)), cpu_vsrh(xA(ctx
->opcode
)));
7749 tcg_gen_mov_i64(cpu_vsrh(xT(ctx
->opcode
)), cpu_vsrl(xA(ctx
->opcode
)));
7751 if ((DM(ctx
->opcode
) & 1) == 0) {
7752 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), cpu_vsrh(xB(ctx
->opcode
)));
7754 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), cpu_vsrl(xB(ctx
->opcode
)));
7763 #define SGN_MASK_DP 0x8000000000000000ull
7764 #define SGN_MASK_SP 0x8000000080000000ull
7766 #define VSX_SCALAR_MOVE(name, op, sgn_mask) \
7767 static void glue(gen_, name)(DisasContext * ctx) \
7770 if (unlikely(!ctx->vsx_enabled)) { \
7771 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7774 xb = tcg_temp_new_i64(); \
7775 sgm = tcg_temp_new_i64(); \
7776 tcg_gen_mov_i64(xb, cpu_vsrh(xB(ctx->opcode))); \
7777 tcg_gen_movi_i64(sgm, sgn_mask); \
7780 tcg_gen_andc_i64(xb, xb, sgm); \
7784 tcg_gen_or_i64(xb, xb, sgm); \
7788 tcg_gen_xor_i64(xb, xb, sgm); \
7792 TCGv_i64 xa = tcg_temp_new_i64(); \
7793 tcg_gen_mov_i64(xa, cpu_vsrh(xA(ctx->opcode))); \
7794 tcg_gen_and_i64(xa, xa, sgm); \
7795 tcg_gen_andc_i64(xb, xb, sgm); \
7796 tcg_gen_or_i64(xb, xb, xa); \
7797 tcg_temp_free_i64(xa); \
7801 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xb); \
7802 tcg_temp_free_i64(xb); \
7803 tcg_temp_free_i64(sgm); \
7806 VSX_SCALAR_MOVE(xsabsdp
, OP_ABS
, SGN_MASK_DP
)
7807 VSX_SCALAR_MOVE(xsnabsdp
, OP_NABS
, SGN_MASK_DP
)
7808 VSX_SCALAR_MOVE(xsnegdp
, OP_NEG
, SGN_MASK_DP
)
7809 VSX_SCALAR_MOVE(xscpsgndp
, OP_CPSGN
, SGN_MASK_DP
)
7811 #define VSX_VECTOR_MOVE(name, op, sgn_mask) \
7812 static void glue(gen_, name)(DisasContext * ctx) \
7814 TCGv_i64 xbh, xbl, sgm; \
7815 if (unlikely(!ctx->vsx_enabled)) { \
7816 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7819 xbh = tcg_temp_new_i64(); \
7820 xbl = tcg_temp_new_i64(); \
7821 sgm = tcg_temp_new_i64(); \
7822 tcg_gen_mov_i64(xbh, cpu_vsrh(xB(ctx->opcode))); \
7823 tcg_gen_mov_i64(xbl, cpu_vsrl(xB(ctx->opcode))); \
7824 tcg_gen_movi_i64(sgm, sgn_mask); \
7827 tcg_gen_andc_i64(xbh, xbh, sgm); \
7828 tcg_gen_andc_i64(xbl, xbl, sgm); \
7832 tcg_gen_or_i64(xbh, xbh, sgm); \
7833 tcg_gen_or_i64(xbl, xbl, sgm); \
7837 tcg_gen_xor_i64(xbh, xbh, sgm); \
7838 tcg_gen_xor_i64(xbl, xbl, sgm); \
7842 TCGv_i64 xah = tcg_temp_new_i64(); \
7843 TCGv_i64 xal = tcg_temp_new_i64(); \
7844 tcg_gen_mov_i64(xah, cpu_vsrh(xA(ctx->opcode))); \
7845 tcg_gen_mov_i64(xal, cpu_vsrl(xA(ctx->opcode))); \
7846 tcg_gen_and_i64(xah, xah, sgm); \
7847 tcg_gen_and_i64(xal, xal, sgm); \
7848 tcg_gen_andc_i64(xbh, xbh, sgm); \
7849 tcg_gen_andc_i64(xbl, xbl, sgm); \
7850 tcg_gen_or_i64(xbh, xbh, xah); \
7851 tcg_gen_or_i64(xbl, xbl, xal); \
7852 tcg_temp_free_i64(xah); \
7853 tcg_temp_free_i64(xal); \
7857 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xbh); \
7858 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xbl); \
7859 tcg_temp_free_i64(xbh); \
7860 tcg_temp_free_i64(xbl); \
7861 tcg_temp_free_i64(sgm); \
7864 VSX_VECTOR_MOVE(xvabsdp
, OP_ABS
, SGN_MASK_DP
)
7865 VSX_VECTOR_MOVE(xvnabsdp
, OP_NABS
, SGN_MASK_DP
)
7866 VSX_VECTOR_MOVE(xvnegdp
, OP_NEG
, SGN_MASK_DP
)
7867 VSX_VECTOR_MOVE(xvcpsgndp
, OP_CPSGN
, SGN_MASK_DP
)
7868 VSX_VECTOR_MOVE(xvabssp
, OP_ABS
, SGN_MASK_SP
)
7869 VSX_VECTOR_MOVE(xvnabssp
, OP_NABS
, SGN_MASK_SP
)
7870 VSX_VECTOR_MOVE(xvnegsp
, OP_NEG
, SGN_MASK_SP
)
7871 VSX_VECTOR_MOVE(xvcpsgnsp
, OP_CPSGN
, SGN_MASK_SP
)
7873 #define GEN_VSX_HELPER_2(name, op1, op2, inval, type) \
7874 static void gen_##name(DisasContext * ctx) \
7877 if (unlikely(!ctx->vsx_enabled)) { \
7878 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7881 /* NIP cannot be restored if the memory exception comes from an helper */ \
7882 gen_update_nip(ctx, ctx->nip - 4); \
7883 opc = tcg_const_i32(ctx->opcode); \
7884 gen_helper_##name(cpu_env, opc); \
7885 tcg_temp_free_i32(opc); \
7888 #define GEN_VSX_HELPER_XT_XB_ENV(name, op1, op2, inval, type) \
7889 static void gen_##name(DisasContext * ctx) \
7891 if (unlikely(!ctx->vsx_enabled)) { \
7892 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7895 /* NIP cannot be restored if the exception comes */ \
7896 /* from a helper. */ \
7897 gen_update_nip(ctx, ctx->nip - 4); \
7899 gen_helper_##name(cpu_vsrh(xT(ctx->opcode)), cpu_env, \
7900 cpu_vsrh(xB(ctx->opcode))); \
7903 GEN_VSX_HELPER_2(xsadddp
, 0x00, 0x04, 0, PPC2_VSX
)
7904 GEN_VSX_HELPER_2(xssubdp
, 0x00, 0x05, 0, PPC2_VSX
)
7905 GEN_VSX_HELPER_2(xsmuldp
, 0x00, 0x06, 0, PPC2_VSX
)
7906 GEN_VSX_HELPER_2(xsdivdp
, 0x00, 0x07, 0, PPC2_VSX
)
7907 GEN_VSX_HELPER_2(xsredp
, 0x14, 0x05, 0, PPC2_VSX
)
7908 GEN_VSX_HELPER_2(xssqrtdp
, 0x16, 0x04, 0, PPC2_VSX
)
7909 GEN_VSX_HELPER_2(xsrsqrtedp
, 0x14, 0x04, 0, PPC2_VSX
)
7910 GEN_VSX_HELPER_2(xstdivdp
, 0x14, 0x07, 0, PPC2_VSX
)
7911 GEN_VSX_HELPER_2(xstsqrtdp
, 0x14, 0x06, 0, PPC2_VSX
)
7912 GEN_VSX_HELPER_2(xsmaddadp
, 0x04, 0x04, 0, PPC2_VSX
)
7913 GEN_VSX_HELPER_2(xsmaddmdp
, 0x04, 0x05, 0, PPC2_VSX
)
7914 GEN_VSX_HELPER_2(xsmsubadp
, 0x04, 0x06, 0, PPC2_VSX
)
7915 GEN_VSX_HELPER_2(xsmsubmdp
, 0x04, 0x07, 0, PPC2_VSX
)
7916 GEN_VSX_HELPER_2(xsnmaddadp
, 0x04, 0x14, 0, PPC2_VSX
)
7917 GEN_VSX_HELPER_2(xsnmaddmdp
, 0x04, 0x15, 0, PPC2_VSX
)
7918 GEN_VSX_HELPER_2(xsnmsubadp
, 0x04, 0x16, 0, PPC2_VSX
)
7919 GEN_VSX_HELPER_2(xsnmsubmdp
, 0x04, 0x17, 0, PPC2_VSX
)
7920 GEN_VSX_HELPER_2(xscmpodp
, 0x0C, 0x05, 0, PPC2_VSX
)
7921 GEN_VSX_HELPER_2(xscmpudp
, 0x0C, 0x04, 0, PPC2_VSX
)
7922 GEN_VSX_HELPER_2(xsmaxdp
, 0x00, 0x14, 0, PPC2_VSX
)
7923 GEN_VSX_HELPER_2(xsmindp
, 0x00, 0x15, 0, PPC2_VSX
)
7924 GEN_VSX_HELPER_2(xscvdpsp
, 0x12, 0x10, 0, PPC2_VSX
)
7925 GEN_VSX_HELPER_XT_XB_ENV(xscvdpspn
, 0x16, 0x10, 0, PPC2_VSX207
)
7926 GEN_VSX_HELPER_2(xscvspdp
, 0x12, 0x14, 0, PPC2_VSX
)
7927 GEN_VSX_HELPER_XT_XB_ENV(xscvspdpn
, 0x16, 0x14, 0, PPC2_VSX207
)
7928 GEN_VSX_HELPER_2(xscvdpsxds
, 0x10, 0x15, 0, PPC2_VSX
)
7929 GEN_VSX_HELPER_2(xscvdpsxws
, 0x10, 0x05, 0, PPC2_VSX
)
7930 GEN_VSX_HELPER_2(xscvdpuxds
, 0x10, 0x14, 0, PPC2_VSX
)
7931 GEN_VSX_HELPER_2(xscvdpuxws
, 0x10, 0x04, 0, PPC2_VSX
)
7932 GEN_VSX_HELPER_2(xscvsxddp
, 0x10, 0x17, 0, PPC2_VSX
)
7933 GEN_VSX_HELPER_2(xscvuxddp
, 0x10, 0x16, 0, PPC2_VSX
)
7934 GEN_VSX_HELPER_2(xsrdpi
, 0x12, 0x04, 0, PPC2_VSX
)
7935 GEN_VSX_HELPER_2(xsrdpic
, 0x16, 0x06, 0, PPC2_VSX
)
7936 GEN_VSX_HELPER_2(xsrdpim
, 0x12, 0x07, 0, PPC2_VSX
)
7937 GEN_VSX_HELPER_2(xsrdpip
, 0x12, 0x06, 0, PPC2_VSX
)
7938 GEN_VSX_HELPER_2(xsrdpiz
, 0x12, 0x05, 0, PPC2_VSX
)
7939 GEN_VSX_HELPER_XT_XB_ENV(xsrsp
, 0x12, 0x11, 0, PPC2_VSX207
)
7941 GEN_VSX_HELPER_2(xsaddsp
, 0x00, 0x00, 0, PPC2_VSX207
)
7942 GEN_VSX_HELPER_2(xssubsp
, 0x00, 0x01, 0, PPC2_VSX207
)
7943 GEN_VSX_HELPER_2(xsmulsp
, 0x00, 0x02, 0, PPC2_VSX207
)
7944 GEN_VSX_HELPER_2(xsdivsp
, 0x00, 0x03, 0, PPC2_VSX207
)
7945 GEN_VSX_HELPER_2(xsresp
, 0x14, 0x01, 0, PPC2_VSX207
)
7946 GEN_VSX_HELPER_2(xssqrtsp
, 0x16, 0x00, 0, PPC2_VSX207
)
7947 GEN_VSX_HELPER_2(xsrsqrtesp
, 0x14, 0x00, 0, PPC2_VSX207
)
7948 GEN_VSX_HELPER_2(xsmaddasp
, 0x04, 0x00, 0, PPC2_VSX207
)
7949 GEN_VSX_HELPER_2(xsmaddmsp
, 0x04, 0x01, 0, PPC2_VSX207
)
7950 GEN_VSX_HELPER_2(xsmsubasp
, 0x04, 0x02, 0, PPC2_VSX207
)
7951 GEN_VSX_HELPER_2(xsmsubmsp
, 0x04, 0x03, 0, PPC2_VSX207
)
7952 GEN_VSX_HELPER_2(xsnmaddasp
, 0x04, 0x10, 0, PPC2_VSX207
)
7953 GEN_VSX_HELPER_2(xsnmaddmsp
, 0x04, 0x11, 0, PPC2_VSX207
)
7954 GEN_VSX_HELPER_2(xsnmsubasp
, 0x04, 0x12, 0, PPC2_VSX207
)
7955 GEN_VSX_HELPER_2(xsnmsubmsp
, 0x04, 0x13, 0, PPC2_VSX207
)
7956 GEN_VSX_HELPER_2(xscvsxdsp
, 0x10, 0x13, 0, PPC2_VSX207
)
7957 GEN_VSX_HELPER_2(xscvuxdsp
, 0x10, 0x12, 0, PPC2_VSX207
)
7959 GEN_VSX_HELPER_2(xvadddp
, 0x00, 0x0C, 0, PPC2_VSX
)
7960 GEN_VSX_HELPER_2(xvsubdp
, 0x00, 0x0D, 0, PPC2_VSX
)
7961 GEN_VSX_HELPER_2(xvmuldp
, 0x00, 0x0E, 0, PPC2_VSX
)
7962 GEN_VSX_HELPER_2(xvdivdp
, 0x00, 0x0F, 0, PPC2_VSX
)
7963 GEN_VSX_HELPER_2(xvredp
, 0x14, 0x0D, 0, PPC2_VSX
)
7964 GEN_VSX_HELPER_2(xvsqrtdp
, 0x16, 0x0C, 0, PPC2_VSX
)
7965 GEN_VSX_HELPER_2(xvrsqrtedp
, 0x14, 0x0C, 0, PPC2_VSX
)
7966 GEN_VSX_HELPER_2(xvtdivdp
, 0x14, 0x0F, 0, PPC2_VSX
)
7967 GEN_VSX_HELPER_2(xvtsqrtdp
, 0x14, 0x0E, 0, PPC2_VSX
)
7968 GEN_VSX_HELPER_2(xvmaddadp
, 0x04, 0x0C, 0, PPC2_VSX
)
7969 GEN_VSX_HELPER_2(xvmaddmdp
, 0x04, 0x0D, 0, PPC2_VSX
)
7970 GEN_VSX_HELPER_2(xvmsubadp
, 0x04, 0x0E, 0, PPC2_VSX
)
7971 GEN_VSX_HELPER_2(xvmsubmdp
, 0x04, 0x0F, 0, PPC2_VSX
)
7972 GEN_VSX_HELPER_2(xvnmaddadp
, 0x04, 0x1C, 0, PPC2_VSX
)
7973 GEN_VSX_HELPER_2(xvnmaddmdp
, 0x04, 0x1D, 0, PPC2_VSX
)
7974 GEN_VSX_HELPER_2(xvnmsubadp
, 0x04, 0x1E, 0, PPC2_VSX
)
7975 GEN_VSX_HELPER_2(xvnmsubmdp
, 0x04, 0x1F, 0, PPC2_VSX
)
7976 GEN_VSX_HELPER_2(xvmaxdp
, 0x00, 0x1C, 0, PPC2_VSX
)
7977 GEN_VSX_HELPER_2(xvmindp
, 0x00, 0x1D, 0, PPC2_VSX
)
7978 GEN_VSX_HELPER_2(xvcmpeqdp
, 0x0C, 0x0C, 0, PPC2_VSX
)
7979 GEN_VSX_HELPER_2(xvcmpgtdp
, 0x0C, 0x0D, 0, PPC2_VSX
)
7980 GEN_VSX_HELPER_2(xvcmpgedp
, 0x0C, 0x0E, 0, PPC2_VSX
)
7981 GEN_VSX_HELPER_2(xvcvdpsp
, 0x12, 0x18, 0, PPC2_VSX
)
7982 GEN_VSX_HELPER_2(xvcvdpsxds
, 0x10, 0x1D, 0, PPC2_VSX
)
7983 GEN_VSX_HELPER_2(xvcvdpsxws
, 0x10, 0x0D, 0, PPC2_VSX
)
7984 GEN_VSX_HELPER_2(xvcvdpuxds
, 0x10, 0x1C, 0, PPC2_VSX
)
7985 GEN_VSX_HELPER_2(xvcvdpuxws
, 0x10, 0x0C, 0, PPC2_VSX
)
7986 GEN_VSX_HELPER_2(xvcvsxddp
, 0x10, 0x1F, 0, PPC2_VSX
)
7987 GEN_VSX_HELPER_2(xvcvuxddp
, 0x10, 0x1E, 0, PPC2_VSX
)
7988 GEN_VSX_HELPER_2(xvcvsxwdp
, 0x10, 0x0F, 0, PPC2_VSX
)
7989 GEN_VSX_HELPER_2(xvcvuxwdp
, 0x10, 0x0E, 0, PPC2_VSX
)
7990 GEN_VSX_HELPER_2(xvrdpi
, 0x12, 0x0C, 0, PPC2_VSX
)
7991 GEN_VSX_HELPER_2(xvrdpic
, 0x16, 0x0E, 0, PPC2_VSX
)
7992 GEN_VSX_HELPER_2(xvrdpim
, 0x12, 0x0F, 0, PPC2_VSX
)
7993 GEN_VSX_HELPER_2(xvrdpip
, 0x12, 0x0E, 0, PPC2_VSX
)
7994 GEN_VSX_HELPER_2(xvrdpiz
, 0x12, 0x0D, 0, PPC2_VSX
)
7996 GEN_VSX_HELPER_2(xvaddsp
, 0x00, 0x08, 0, PPC2_VSX
)
7997 GEN_VSX_HELPER_2(xvsubsp
, 0x00, 0x09, 0, PPC2_VSX
)
7998 GEN_VSX_HELPER_2(xvmulsp
, 0x00, 0x0A, 0, PPC2_VSX
)
7999 GEN_VSX_HELPER_2(xvdivsp
, 0x00, 0x0B, 0, PPC2_VSX
)
8000 GEN_VSX_HELPER_2(xvresp
, 0x14, 0x09, 0, PPC2_VSX
)
8001 GEN_VSX_HELPER_2(xvsqrtsp
, 0x16, 0x08, 0, PPC2_VSX
)
8002 GEN_VSX_HELPER_2(xvrsqrtesp
, 0x14, 0x08, 0, PPC2_VSX
)
8003 GEN_VSX_HELPER_2(xvtdivsp
, 0x14, 0x0B, 0, PPC2_VSX
)
8004 GEN_VSX_HELPER_2(xvtsqrtsp
, 0x14, 0x0A, 0, PPC2_VSX
)
8005 GEN_VSX_HELPER_2(xvmaddasp
, 0x04, 0x08, 0, PPC2_VSX
)
8006 GEN_VSX_HELPER_2(xvmaddmsp
, 0x04, 0x09, 0, PPC2_VSX
)
8007 GEN_VSX_HELPER_2(xvmsubasp
, 0x04, 0x0A, 0, PPC2_VSX
)
8008 GEN_VSX_HELPER_2(xvmsubmsp
, 0x04, 0x0B, 0, PPC2_VSX
)
8009 GEN_VSX_HELPER_2(xvnmaddasp
, 0x04, 0x18, 0, PPC2_VSX
)
8010 GEN_VSX_HELPER_2(xvnmaddmsp
, 0x04, 0x19, 0, PPC2_VSX
)
8011 GEN_VSX_HELPER_2(xvnmsubasp
, 0x04, 0x1A, 0, PPC2_VSX
)
8012 GEN_VSX_HELPER_2(xvnmsubmsp
, 0x04, 0x1B, 0, PPC2_VSX
)
8013 GEN_VSX_HELPER_2(xvmaxsp
, 0x00, 0x18, 0, PPC2_VSX
)
8014 GEN_VSX_HELPER_2(xvminsp
, 0x00, 0x19, 0, PPC2_VSX
)
8015 GEN_VSX_HELPER_2(xvcmpeqsp
, 0x0C, 0x08, 0, PPC2_VSX
)
8016 GEN_VSX_HELPER_2(xvcmpgtsp
, 0x0C, 0x09, 0, PPC2_VSX
)
8017 GEN_VSX_HELPER_2(xvcmpgesp
, 0x0C, 0x0A, 0, PPC2_VSX
)
8018 GEN_VSX_HELPER_2(xvcvspdp
, 0x12, 0x1C, 0, PPC2_VSX
)
8019 GEN_VSX_HELPER_2(xvcvspsxds
, 0x10, 0x19, 0, PPC2_VSX
)
8020 GEN_VSX_HELPER_2(xvcvspsxws
, 0x10, 0x09, 0, PPC2_VSX
)
8021 GEN_VSX_HELPER_2(xvcvspuxds
, 0x10, 0x18, 0, PPC2_VSX
)
8022 GEN_VSX_HELPER_2(xvcvspuxws
, 0x10, 0x08, 0, PPC2_VSX
)
8023 GEN_VSX_HELPER_2(xvcvsxdsp
, 0x10, 0x1B, 0, PPC2_VSX
)
8024 GEN_VSX_HELPER_2(xvcvuxdsp
, 0x10, 0x1A, 0, PPC2_VSX
)
8025 GEN_VSX_HELPER_2(xvcvsxwsp
, 0x10, 0x0B, 0, PPC2_VSX
)
8026 GEN_VSX_HELPER_2(xvcvuxwsp
, 0x10, 0x0A, 0, PPC2_VSX
)
8027 GEN_VSX_HELPER_2(xvrspi
, 0x12, 0x08, 0, PPC2_VSX
)
8028 GEN_VSX_HELPER_2(xvrspic
, 0x16, 0x0A, 0, PPC2_VSX
)
8029 GEN_VSX_HELPER_2(xvrspim
, 0x12, 0x0B, 0, PPC2_VSX
)
8030 GEN_VSX_HELPER_2(xvrspip
, 0x12, 0x0A, 0, PPC2_VSX
)
8031 GEN_VSX_HELPER_2(xvrspiz
, 0x12, 0x09, 0, PPC2_VSX
)
8033 #define VSX_LOGICAL(name, tcg_op) \
8034 static void glue(gen_, name)(DisasContext * ctx) \
8036 if (unlikely(!ctx->vsx_enabled)) { \
8037 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8040 tcg_op(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)), \
8041 cpu_vsrh(xB(ctx->opcode))); \
8042 tcg_op(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)), \
8043 cpu_vsrl(xB(ctx->opcode))); \
8046 VSX_LOGICAL(xxland
, tcg_gen_and_i64
)
8047 VSX_LOGICAL(xxlandc
, tcg_gen_andc_i64
)
8048 VSX_LOGICAL(xxlor
, tcg_gen_or_i64
)
8049 VSX_LOGICAL(xxlxor
, tcg_gen_xor_i64
)
8050 VSX_LOGICAL(xxlnor
, tcg_gen_nor_i64
)
8051 VSX_LOGICAL(xxleqv
, tcg_gen_eqv_i64
)
8052 VSX_LOGICAL(xxlnand
, tcg_gen_nand_i64
)
8053 VSX_LOGICAL(xxlorc
, tcg_gen_orc_i64
)
8055 #define VSX_XXMRG(name, high) \
8056 static void glue(gen_, name)(DisasContext * ctx) \
8058 TCGv_i64 a0, a1, b0, b1; \
8059 if (unlikely(!ctx->vsx_enabled)) { \
8060 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8063 a0 = tcg_temp_new_i64(); \
8064 a1 = tcg_temp_new_i64(); \
8065 b0 = tcg_temp_new_i64(); \
8066 b1 = tcg_temp_new_i64(); \
8068 tcg_gen_mov_i64(a0, cpu_vsrh(xA(ctx->opcode))); \
8069 tcg_gen_mov_i64(a1, cpu_vsrh(xA(ctx->opcode))); \
8070 tcg_gen_mov_i64(b0, cpu_vsrh(xB(ctx->opcode))); \
8071 tcg_gen_mov_i64(b1, cpu_vsrh(xB(ctx->opcode))); \
8073 tcg_gen_mov_i64(a0, cpu_vsrl(xA(ctx->opcode))); \
8074 tcg_gen_mov_i64(a1, cpu_vsrl(xA(ctx->opcode))); \
8075 tcg_gen_mov_i64(b0, cpu_vsrl(xB(ctx->opcode))); \
8076 tcg_gen_mov_i64(b1, cpu_vsrl(xB(ctx->opcode))); \
8078 tcg_gen_shri_i64(a0, a0, 32); \
8079 tcg_gen_shri_i64(b0, b0, 32); \
8080 tcg_gen_deposit_i64(cpu_vsrh(xT(ctx->opcode)), \
8082 tcg_gen_deposit_i64(cpu_vsrl(xT(ctx->opcode)), \
8084 tcg_temp_free_i64(a0); \
8085 tcg_temp_free_i64(a1); \
8086 tcg_temp_free_i64(b0); \
8087 tcg_temp_free_i64(b1); \
8090 VSX_XXMRG(xxmrghw
, 1)
8091 VSX_XXMRG(xxmrglw
, 0)
8093 static void gen_xxsel(DisasContext
* ctx
)
8096 if (unlikely(!ctx
->vsx_enabled
)) {
8097 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
8100 a
= tcg_temp_new_i64();
8101 b
= tcg_temp_new_i64();
8102 c
= tcg_temp_new_i64();
8104 tcg_gen_mov_i64(a
, cpu_vsrh(xA(ctx
->opcode
)));
8105 tcg_gen_mov_i64(b
, cpu_vsrh(xB(ctx
->opcode
)));
8106 tcg_gen_mov_i64(c
, cpu_vsrh(xC(ctx
->opcode
)));
8108 tcg_gen_and_i64(b
, b
, c
);
8109 tcg_gen_andc_i64(a
, a
, c
);
8110 tcg_gen_or_i64(cpu_vsrh(xT(ctx
->opcode
)), a
, b
);
8112 tcg_gen_mov_i64(a
, cpu_vsrl(xA(ctx
->opcode
)));
8113 tcg_gen_mov_i64(b
, cpu_vsrl(xB(ctx
->opcode
)));
8114 tcg_gen_mov_i64(c
, cpu_vsrl(xC(ctx
->opcode
)));
8116 tcg_gen_and_i64(b
, b
, c
);
8117 tcg_gen_andc_i64(a
, a
, c
);
8118 tcg_gen_or_i64(cpu_vsrl(xT(ctx
->opcode
)), a
, b
);
8120 tcg_temp_free_i64(a
);
8121 tcg_temp_free_i64(b
);
8122 tcg_temp_free_i64(c
);
8125 static void gen_xxspltw(DisasContext
*ctx
)
8128 TCGv_i64 vsr
= (UIM(ctx
->opcode
) & 2) ?
8129 cpu_vsrl(xB(ctx
->opcode
)) :
8130 cpu_vsrh(xB(ctx
->opcode
));
8132 if (unlikely(!ctx
->vsx_enabled
)) {
8133 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
8137 b
= tcg_temp_new_i64();
8138 b2
= tcg_temp_new_i64();
8140 if (UIM(ctx
->opcode
) & 1) {
8141 tcg_gen_ext32u_i64(b
, vsr
);
8143 tcg_gen_shri_i64(b
, vsr
, 32);
8146 tcg_gen_shli_i64(b2
, b
, 32);
8147 tcg_gen_or_i64(cpu_vsrh(xT(ctx
->opcode
)), b
, b2
);
8148 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), cpu_vsrh(xT(ctx
->opcode
)));
8150 tcg_temp_free_i64(b
);
8151 tcg_temp_free_i64(b2
);
8154 static void gen_xxsldwi(DisasContext
*ctx
)
8157 if (unlikely(!ctx
->vsx_enabled
)) {
8158 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
8161 xth
= tcg_temp_new_i64();
8162 xtl
= tcg_temp_new_i64();
8164 switch (SHW(ctx
->opcode
)) {
8166 tcg_gen_mov_i64(xth
, cpu_vsrh(xA(ctx
->opcode
)));
8167 tcg_gen_mov_i64(xtl
, cpu_vsrl(xA(ctx
->opcode
)));
8171 TCGv_i64 t0
= tcg_temp_new_i64();
8172 tcg_gen_mov_i64(xth
, cpu_vsrh(xA(ctx
->opcode
)));
8173 tcg_gen_shli_i64(xth
, xth
, 32);
8174 tcg_gen_mov_i64(t0
, cpu_vsrl(xA(ctx
->opcode
)));
8175 tcg_gen_shri_i64(t0
, t0
, 32);
8176 tcg_gen_or_i64(xth
, xth
, t0
);
8177 tcg_gen_mov_i64(xtl
, cpu_vsrl(xA(ctx
->opcode
)));
8178 tcg_gen_shli_i64(xtl
, xtl
, 32);
8179 tcg_gen_mov_i64(t0
, cpu_vsrh(xB(ctx
->opcode
)));
8180 tcg_gen_shri_i64(t0
, t0
, 32);
8181 tcg_gen_or_i64(xtl
, xtl
, t0
);
8182 tcg_temp_free_i64(t0
);
8186 tcg_gen_mov_i64(xth
, cpu_vsrl(xA(ctx
->opcode
)));
8187 tcg_gen_mov_i64(xtl
, cpu_vsrh(xB(ctx
->opcode
)));
8191 TCGv_i64 t0
= tcg_temp_new_i64();
8192 tcg_gen_mov_i64(xth
, cpu_vsrl(xA(ctx
->opcode
)));
8193 tcg_gen_shli_i64(xth
, xth
, 32);
8194 tcg_gen_mov_i64(t0
, cpu_vsrh(xB(ctx
->opcode
)));
8195 tcg_gen_shri_i64(t0
, t0
, 32);
8196 tcg_gen_or_i64(xth
, xth
, t0
);
8197 tcg_gen_mov_i64(xtl
, cpu_vsrh(xB(ctx
->opcode
)));
8198 tcg_gen_shli_i64(xtl
, xtl
, 32);
8199 tcg_gen_mov_i64(t0
, cpu_vsrl(xB(ctx
->opcode
)));
8200 tcg_gen_shri_i64(t0
, t0
, 32);
8201 tcg_gen_or_i64(xtl
, xtl
, t0
);
8202 tcg_temp_free_i64(t0
);
8207 tcg_gen_mov_i64(cpu_vsrh(xT(ctx
->opcode
)), xth
);
8208 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), xtl
);
8210 tcg_temp_free_i64(xth
);
8211 tcg_temp_free_i64(xtl
);
8214 /*** Decimal Floating Point ***/
8216 static inline TCGv_ptr
gen_fprp_ptr(int reg
)
8218 TCGv_ptr r
= tcg_temp_new_ptr();
8219 tcg_gen_addi_ptr(r
, cpu_env
, offsetof(CPUPPCState
, fpr
[reg
]));
8223 #if defined(TARGET_PPC64)
8224 static void gen_set_cr6_from_fpscr(DisasContext
*ctx
)
8226 TCGv_i32 tmp
= tcg_temp_new_i32();
8227 tcg_gen_trunc_tl_i32(tmp
, cpu_fpscr
);
8228 tcg_gen_shri_i32(cpu_crf
[1], tmp
, 28);
8229 tcg_temp_free_i32(tmp
);
8232 static void gen_set_cr6_from_fpscr(DisasContext
*ctx
)
8234 tcg_gen_shri_tl(cpu_crf
[1], cpu_fpscr
, 28);
8238 #define GEN_DFP_T_A_B_Rc(name) \
8239 static void gen_##name(DisasContext *ctx) \
8241 TCGv_ptr rd, ra, rb; \
8242 if (unlikely(!ctx->fpu_enabled)) { \
8243 gen_exception(ctx, POWERPC_EXCP_FPU); \
8246 gen_update_nip(ctx, ctx->nip - 4); \
8247 rd = gen_fprp_ptr(rD(ctx->opcode)); \
8248 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8249 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8250 gen_helper_##name(cpu_env, rd, ra, rb); \
8251 if (unlikely(Rc(ctx->opcode) != 0)) { \
8252 gen_set_cr6_from_fpscr(ctx); \
8254 tcg_temp_free_ptr(rd); \
8255 tcg_temp_free_ptr(ra); \
8256 tcg_temp_free_ptr(rb); \
8259 #define GEN_DFP_BF_A_B(name) \
8260 static void gen_##name(DisasContext *ctx) \
8263 if (unlikely(!ctx->fpu_enabled)) { \
8264 gen_exception(ctx, POWERPC_EXCP_FPU); \
8267 gen_update_nip(ctx, ctx->nip - 4); \
8268 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8269 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8270 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
8272 tcg_temp_free_ptr(ra); \
8273 tcg_temp_free_ptr(rb); \
8276 #define GEN_DFP_BF_A_DCM(name) \
8277 static void gen_##name(DisasContext *ctx) \
8281 if (unlikely(!ctx->fpu_enabled)) { \
8282 gen_exception(ctx, POWERPC_EXCP_FPU); \
8285 gen_update_nip(ctx, ctx->nip - 4); \
8286 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8287 dcm = tcg_const_i32(DCM(ctx->opcode)); \
8288 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
8289 cpu_env, ra, dcm); \
8290 tcg_temp_free_ptr(ra); \
8291 tcg_temp_free_i32(dcm); \
8294 #define GEN_DFP_T_B_U32_U32_Rc(name, u32f1, u32f2) \
8295 static void gen_##name(DisasContext *ctx) \
8298 TCGv_i32 u32_1, u32_2; \
8299 if (unlikely(!ctx->fpu_enabled)) { \
8300 gen_exception(ctx, POWERPC_EXCP_FPU); \
8303 gen_update_nip(ctx, ctx->nip - 4); \
8304 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8305 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8306 u32_1 = tcg_const_i32(u32f1(ctx->opcode)); \
8307 u32_2 = tcg_const_i32(u32f2(ctx->opcode)); \
8308 gen_helper_##name(cpu_env, rt, rb, u32_1, u32_2); \
8309 if (unlikely(Rc(ctx->opcode) != 0)) { \
8310 gen_set_cr6_from_fpscr(ctx); \
8312 tcg_temp_free_ptr(rt); \
8313 tcg_temp_free_ptr(rb); \
8314 tcg_temp_free_i32(u32_1); \
8315 tcg_temp_free_i32(u32_2); \
8318 #define GEN_DFP_T_A_B_I32_Rc(name, i32fld) \
8319 static void gen_##name(DisasContext *ctx) \
8321 TCGv_ptr rt, ra, rb; \
8323 if (unlikely(!ctx->fpu_enabled)) { \
8324 gen_exception(ctx, POWERPC_EXCP_FPU); \
8327 gen_update_nip(ctx, ctx->nip - 4); \
8328 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8329 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8330 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8331 i32 = tcg_const_i32(i32fld(ctx->opcode)); \
8332 gen_helper_##name(cpu_env, rt, ra, rb, i32); \
8333 if (unlikely(Rc(ctx->opcode) != 0)) { \
8334 gen_set_cr6_from_fpscr(ctx); \
8336 tcg_temp_free_ptr(rt); \
8337 tcg_temp_free_ptr(rb); \
8338 tcg_temp_free_ptr(ra); \
8339 tcg_temp_free_i32(i32); \
8342 #define GEN_DFP_T_B_Rc(name) \
8343 static void gen_##name(DisasContext *ctx) \
8346 if (unlikely(!ctx->fpu_enabled)) { \
8347 gen_exception(ctx, POWERPC_EXCP_FPU); \
8350 gen_update_nip(ctx, ctx->nip - 4); \
8351 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8352 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8353 gen_helper_##name(cpu_env, rt, rb); \
8354 if (unlikely(Rc(ctx->opcode) != 0)) { \
8355 gen_set_cr6_from_fpscr(ctx); \
8357 tcg_temp_free_ptr(rt); \
8358 tcg_temp_free_ptr(rb); \
8361 #define GEN_DFP_T_FPR_I32_Rc(name, fprfld, i32fld) \
8362 static void gen_##name(DisasContext *ctx) \
8366 if (unlikely(!ctx->fpu_enabled)) { \
8367 gen_exception(ctx, POWERPC_EXCP_FPU); \
8370 gen_update_nip(ctx, ctx->nip - 4); \
8371 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8372 rs = gen_fprp_ptr(fprfld(ctx->opcode)); \
8373 i32 = tcg_const_i32(i32fld(ctx->opcode)); \
8374 gen_helper_##name(cpu_env, rt, rs, i32); \
8375 if (unlikely(Rc(ctx->opcode) != 0)) { \
8376 gen_set_cr6_from_fpscr(ctx); \
8378 tcg_temp_free_ptr(rt); \
8379 tcg_temp_free_ptr(rs); \
8380 tcg_temp_free_i32(i32); \
8383 GEN_DFP_T_A_B_Rc(dadd
)
8384 GEN_DFP_T_A_B_Rc(daddq
)
8385 GEN_DFP_T_A_B_Rc(dsub
)
8386 GEN_DFP_T_A_B_Rc(dsubq
)
8387 GEN_DFP_T_A_B_Rc(dmul
)
8388 GEN_DFP_T_A_B_Rc(dmulq
)
8389 GEN_DFP_T_A_B_Rc(ddiv
)
8390 GEN_DFP_T_A_B_Rc(ddivq
)
8391 GEN_DFP_BF_A_B(dcmpu
)
8392 GEN_DFP_BF_A_B(dcmpuq
)
8393 GEN_DFP_BF_A_B(dcmpo
)
8394 GEN_DFP_BF_A_B(dcmpoq
)
8395 GEN_DFP_BF_A_DCM(dtstdc
)
8396 GEN_DFP_BF_A_DCM(dtstdcq
)
8397 GEN_DFP_BF_A_DCM(dtstdg
)
8398 GEN_DFP_BF_A_DCM(dtstdgq
)
8399 GEN_DFP_BF_A_B(dtstex
)
8400 GEN_DFP_BF_A_B(dtstexq
)
8401 GEN_DFP_BF_A_B(dtstsf
)
8402 GEN_DFP_BF_A_B(dtstsfq
)
8403 GEN_DFP_T_B_U32_U32_Rc(dquai
, SIMM5
, RMC
)
8404 GEN_DFP_T_B_U32_U32_Rc(dquaiq
, SIMM5
, RMC
)
8405 GEN_DFP_T_A_B_I32_Rc(dqua
, RMC
)
8406 GEN_DFP_T_A_B_I32_Rc(dquaq
, RMC
)
8407 GEN_DFP_T_A_B_I32_Rc(drrnd
, RMC
)
8408 GEN_DFP_T_A_B_I32_Rc(drrndq
, RMC
)
8409 GEN_DFP_T_B_U32_U32_Rc(drintx
, FPW
, RMC
)
8410 GEN_DFP_T_B_U32_U32_Rc(drintxq
, FPW
, RMC
)
8411 GEN_DFP_T_B_U32_U32_Rc(drintn
, FPW
, RMC
)
8412 GEN_DFP_T_B_U32_U32_Rc(drintnq
, FPW
, RMC
)
8413 GEN_DFP_T_B_Rc(dctdp
)
8414 GEN_DFP_T_B_Rc(dctqpq
)
8415 GEN_DFP_T_B_Rc(drsp
)
8416 GEN_DFP_T_B_Rc(drdpq
)
8417 GEN_DFP_T_B_Rc(dcffix
)
8418 GEN_DFP_T_B_Rc(dcffixq
)
8419 GEN_DFP_T_B_Rc(dctfix
)
8420 GEN_DFP_T_B_Rc(dctfixq
)
8421 GEN_DFP_T_FPR_I32_Rc(ddedpd
, rB
, SP
)
8422 GEN_DFP_T_FPR_I32_Rc(ddedpdq
, rB
, SP
)
8423 GEN_DFP_T_FPR_I32_Rc(denbcd
, rB
, SP
)
8424 GEN_DFP_T_FPR_I32_Rc(denbcdq
, rB
, SP
)
8425 GEN_DFP_T_B_Rc(dxex
)
8426 GEN_DFP_T_B_Rc(dxexq
)
8427 GEN_DFP_T_A_B_Rc(diex
)
8428 GEN_DFP_T_A_B_Rc(diexq
)
8429 GEN_DFP_T_FPR_I32_Rc(dscli
, rA
, DCM
)
8430 GEN_DFP_T_FPR_I32_Rc(dscliq
, rA
, DCM
)
8431 GEN_DFP_T_FPR_I32_Rc(dscri
, rA
, DCM
)
8432 GEN_DFP_T_FPR_I32_Rc(dscriq
, rA
, DCM
)
8434 /*** SPE extension ***/
8435 /* Register moves */
8437 static inline void gen_evmra(DisasContext
*ctx
)
8440 if (unlikely(!ctx
->spe_enabled
)) {
8441 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8445 TCGv_i64 tmp
= tcg_temp_new_i64();
8447 /* tmp := rA_lo + rA_hi << 32 */
8448 tcg_gen_concat_tl_i64(tmp
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
8450 /* spe_acc := tmp */
8451 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8452 tcg_temp_free_i64(tmp
);
8455 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8456 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
8459 static inline void gen_load_gpr64(TCGv_i64 t
, int reg
)
8461 tcg_gen_concat_tl_i64(t
, cpu_gpr
[reg
], cpu_gprh
[reg
]);
8464 static inline void gen_store_gpr64(int reg
, TCGv_i64 t
)
8466 tcg_gen_extr_i64_tl(cpu_gpr
[reg
], cpu_gprh
[reg
], t
);
8469 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
8470 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
8472 if (Rc(ctx->opcode)) \
8478 /* Handler for undefined SPE opcodes */
8479 static inline void gen_speundef(DisasContext
*ctx
)
8481 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
8485 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
8486 static inline void gen_##name(DisasContext *ctx) \
8488 if (unlikely(!ctx->spe_enabled)) { \
8489 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8492 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8493 cpu_gpr[rB(ctx->opcode)]); \
8494 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8495 cpu_gprh[rB(ctx->opcode)]); \
8498 GEN_SPEOP_LOGIC2(evand
, tcg_gen_and_tl
);
8499 GEN_SPEOP_LOGIC2(evandc
, tcg_gen_andc_tl
);
8500 GEN_SPEOP_LOGIC2(evxor
, tcg_gen_xor_tl
);
8501 GEN_SPEOP_LOGIC2(evor
, tcg_gen_or_tl
);
8502 GEN_SPEOP_LOGIC2(evnor
, tcg_gen_nor_tl
);
8503 GEN_SPEOP_LOGIC2(eveqv
, tcg_gen_eqv_tl
);
8504 GEN_SPEOP_LOGIC2(evorc
, tcg_gen_orc_tl
);
8505 GEN_SPEOP_LOGIC2(evnand
, tcg_gen_nand_tl
);
8507 /* SPE logic immediate */
8508 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
8509 static inline void gen_##name(DisasContext *ctx) \
8512 if (unlikely(!ctx->spe_enabled)) { \
8513 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8516 t0 = tcg_temp_new_i32(); \
8518 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8519 tcg_opi(t0, t0, rB(ctx->opcode)); \
8520 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8522 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
8523 tcg_opi(t0, t0, rB(ctx->opcode)); \
8524 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8526 tcg_temp_free_i32(t0); \
8528 GEN_SPEOP_TCG_LOGIC_IMM2(evslwi
, tcg_gen_shli_i32
);
8529 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu
, tcg_gen_shri_i32
);
8530 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis
, tcg_gen_sari_i32
);
8531 GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi
, tcg_gen_rotli_i32
);
8533 /* SPE arithmetic */
8534 #define GEN_SPEOP_ARITH1(name, tcg_op) \
8535 static inline void gen_##name(DisasContext *ctx) \
8538 if (unlikely(!ctx->spe_enabled)) { \
8539 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8542 t0 = tcg_temp_new_i32(); \
8544 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8546 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8548 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
8550 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8552 tcg_temp_free_i32(t0); \
8555 static inline void gen_op_evabs(TCGv_i32 ret
, TCGv_i32 arg1
)
8557 int l1
= gen_new_label();
8558 int l2
= gen_new_label();
8560 tcg_gen_brcondi_i32(TCG_COND_GE
, arg1
, 0, l1
);
8561 tcg_gen_neg_i32(ret
, arg1
);
8564 tcg_gen_mov_i32(ret
, arg1
);
8567 GEN_SPEOP_ARITH1(evabs
, gen_op_evabs
);
8568 GEN_SPEOP_ARITH1(evneg
, tcg_gen_neg_i32
);
8569 GEN_SPEOP_ARITH1(evextsb
, tcg_gen_ext8s_i32
);
8570 GEN_SPEOP_ARITH1(evextsh
, tcg_gen_ext16s_i32
);
8571 static inline void gen_op_evrndw(TCGv_i32 ret
, TCGv_i32 arg1
)
8573 tcg_gen_addi_i32(ret
, arg1
, 0x8000);
8574 tcg_gen_ext16u_i32(ret
, ret
);
8576 GEN_SPEOP_ARITH1(evrndw
, gen_op_evrndw
);
8577 GEN_SPEOP_ARITH1(evcntlsw
, gen_helper_cntlsw32
);
8578 GEN_SPEOP_ARITH1(evcntlzw
, gen_helper_cntlzw32
);
8580 #define GEN_SPEOP_ARITH2(name, tcg_op) \
8581 static inline void gen_##name(DisasContext *ctx) \
8584 if (unlikely(!ctx->spe_enabled)) { \
8585 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8588 t0 = tcg_temp_new_i32(); \
8589 t1 = tcg_temp_new_i32(); \
8591 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8592 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8593 tcg_op(t0, t0, t1); \
8594 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8596 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
8597 tcg_gen_trunc_tl_i32(t1, cpu_gprh[rB(ctx->opcode)]); \
8598 tcg_op(t0, t0, t1); \
8599 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8601 tcg_temp_free_i32(t0); \
8602 tcg_temp_free_i32(t1); \
8605 static inline void gen_op_evsrwu(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
8610 l1
= gen_new_label();
8611 l2
= gen_new_label();
8612 t0
= tcg_temp_local_new_i32();
8613 /* No error here: 6 bits are used */
8614 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
8615 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
8616 tcg_gen_shr_i32(ret
, arg1
, t0
);
8619 tcg_gen_movi_i32(ret
, 0);
8621 tcg_temp_free_i32(t0
);
8623 GEN_SPEOP_ARITH2(evsrwu
, gen_op_evsrwu
);
8624 static inline void gen_op_evsrws(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
8629 l1
= gen_new_label();
8630 l2
= gen_new_label();
8631 t0
= tcg_temp_local_new_i32();
8632 /* No error here: 6 bits are used */
8633 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
8634 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
8635 tcg_gen_sar_i32(ret
, arg1
, t0
);
8638 tcg_gen_movi_i32(ret
, 0);
8640 tcg_temp_free_i32(t0
);
8642 GEN_SPEOP_ARITH2(evsrws
, gen_op_evsrws
);
8643 static inline void gen_op_evslw(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
8648 l1
= gen_new_label();
8649 l2
= gen_new_label();
8650 t0
= tcg_temp_local_new_i32();
8651 /* No error here: 6 bits are used */
8652 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
8653 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
8654 tcg_gen_shl_i32(ret
, arg1
, t0
);
8657 tcg_gen_movi_i32(ret
, 0);
8659 tcg_temp_free_i32(t0
);
8661 GEN_SPEOP_ARITH2(evslw
, gen_op_evslw
);
8662 static inline void gen_op_evrlw(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
8664 TCGv_i32 t0
= tcg_temp_new_i32();
8665 tcg_gen_andi_i32(t0
, arg2
, 0x1F);
8666 tcg_gen_rotl_i32(ret
, arg1
, t0
);
8667 tcg_temp_free_i32(t0
);
8669 GEN_SPEOP_ARITH2(evrlw
, gen_op_evrlw
);
8670 static inline void gen_evmergehi(DisasContext
*ctx
)
8672 if (unlikely(!ctx
->spe_enabled
)) {
8673 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8676 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
8677 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
8679 GEN_SPEOP_ARITH2(evaddw
, tcg_gen_add_i32
);
8680 static inline void gen_op_evsubf(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
8682 tcg_gen_sub_i32(ret
, arg2
, arg1
);
8684 GEN_SPEOP_ARITH2(evsubfw
, gen_op_evsubf
);
8686 /* SPE arithmetic immediate */
8687 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
8688 static inline void gen_##name(DisasContext *ctx) \
8691 if (unlikely(!ctx->spe_enabled)) { \
8692 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8695 t0 = tcg_temp_new_i32(); \
8697 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8698 tcg_op(t0, t0, rA(ctx->opcode)); \
8699 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8701 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rB(ctx->opcode)]); \
8702 tcg_op(t0, t0, rA(ctx->opcode)); \
8703 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8705 tcg_temp_free_i32(t0); \
8707 GEN_SPEOP_ARITH_IMM2(evaddiw
, tcg_gen_addi_i32
);
8708 GEN_SPEOP_ARITH_IMM2(evsubifw
, tcg_gen_subi_i32
);
8710 /* SPE comparison */
8711 #define GEN_SPEOP_COMP(name, tcg_cond) \
8712 static inline void gen_##name(DisasContext *ctx) \
8714 if (unlikely(!ctx->spe_enabled)) { \
8715 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8718 int l1 = gen_new_label(); \
8719 int l2 = gen_new_label(); \
8720 int l3 = gen_new_label(); \
8721 int l4 = gen_new_label(); \
8723 tcg_gen_ext32s_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
8724 tcg_gen_ext32s_tl(cpu_gpr[rB(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8725 tcg_gen_ext32s_tl(cpu_gprh[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
8726 tcg_gen_ext32s_tl(cpu_gprh[rB(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); \
8728 tcg_gen_brcond_tl(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
8729 cpu_gpr[rB(ctx->opcode)], l1); \
8730 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
8732 gen_set_label(l1); \
8733 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8734 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8735 gen_set_label(l2); \
8736 tcg_gen_brcond_tl(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
8737 cpu_gprh[rB(ctx->opcode)], l3); \
8738 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8739 ~(CRF_CH | CRF_CH_AND_CL)); \
8741 gen_set_label(l3); \
8742 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8743 CRF_CH | CRF_CH_OR_CL); \
8744 gen_set_label(l4); \
8746 GEN_SPEOP_COMP(evcmpgtu
, TCG_COND_GTU
);
8747 GEN_SPEOP_COMP(evcmpgts
, TCG_COND_GT
);
8748 GEN_SPEOP_COMP(evcmpltu
, TCG_COND_LTU
);
8749 GEN_SPEOP_COMP(evcmplts
, TCG_COND_LT
);
8750 GEN_SPEOP_COMP(evcmpeq
, TCG_COND_EQ
);
8753 static inline void gen_brinc(DisasContext
*ctx
)
8755 /* Note: brinc is usable even if SPE is disabled */
8756 gen_helper_brinc(cpu_gpr
[rD(ctx
->opcode
)],
8757 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
8759 static inline void gen_evmergelo(DisasContext
*ctx
)
8761 if (unlikely(!ctx
->spe_enabled
)) {
8762 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8765 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8766 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
8768 static inline void gen_evmergehilo(DisasContext
*ctx
)
8770 if (unlikely(!ctx
->spe_enabled
)) {
8771 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8774 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
8775 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
8777 static inline void gen_evmergelohi(DisasContext
*ctx
)
8779 if (unlikely(!ctx
->spe_enabled
)) {
8780 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8783 if (rD(ctx
->opcode
) == rA(ctx
->opcode
)) {
8784 TCGv tmp
= tcg_temp_new();
8785 tcg_gen_mov_tl(tmp
, cpu_gpr
[rA(ctx
->opcode
)]);
8786 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
8787 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], tmp
);
8790 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
8791 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8794 static inline void gen_evsplati(DisasContext
*ctx
)
8796 uint64_t imm
= ((int32_t)(rA(ctx
->opcode
) << 27)) >> 27;
8798 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], imm
);
8799 tcg_gen_movi_tl(cpu_gprh
[rD(ctx
->opcode
)], imm
);
8801 static inline void gen_evsplatfi(DisasContext
*ctx
)
8803 uint64_t imm
= rA(ctx
->opcode
) << 27;
8805 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], imm
);
8806 tcg_gen_movi_tl(cpu_gprh
[rD(ctx
->opcode
)], imm
);
8809 static inline void gen_evsel(DisasContext
*ctx
)
8811 int l1
= gen_new_label();
8812 int l2
= gen_new_label();
8813 int l3
= gen_new_label();
8814 int l4
= gen_new_label();
8815 TCGv_i32 t0
= tcg_temp_local_new_i32();
8816 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 3);
8817 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
8818 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
8821 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
8823 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 2);
8824 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l3
);
8825 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8828 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
8830 tcg_temp_free_i32(t0
);
8833 static void gen_evsel0(DisasContext
*ctx
)
8838 static void gen_evsel1(DisasContext
*ctx
)
8843 static void gen_evsel2(DisasContext
*ctx
)
8848 static void gen_evsel3(DisasContext
*ctx
)
8855 static inline void gen_evmwumi(DisasContext
*ctx
)
8859 if (unlikely(!ctx
->spe_enabled
)) {
8860 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8864 t0
= tcg_temp_new_i64();
8865 t1
= tcg_temp_new_i64();
8867 /* t0 := rA; t1 := rB */
8868 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
8869 tcg_gen_ext32u_i64(t0
, t0
);
8870 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
8871 tcg_gen_ext32u_i64(t1
, t1
);
8873 tcg_gen_mul_i64(t0
, t0
, t1
); /* t0 := rA * rB */
8875 gen_store_gpr64(rD(ctx
->opcode
), t0
); /* rD := t0 */
8877 tcg_temp_free_i64(t0
);
8878 tcg_temp_free_i64(t1
);
8881 static inline void gen_evmwumia(DisasContext
*ctx
)
8885 if (unlikely(!ctx
->spe_enabled
)) {
8886 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8890 gen_evmwumi(ctx
); /* rD := rA * rB */
8892 tmp
= tcg_temp_new_i64();
8895 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
8896 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8897 tcg_temp_free_i64(tmp
);
8900 static inline void gen_evmwumiaa(DisasContext
*ctx
)
8905 if (unlikely(!ctx
->spe_enabled
)) {
8906 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8910 gen_evmwumi(ctx
); /* rD := rA * rB */
8912 acc
= tcg_temp_new_i64();
8913 tmp
= tcg_temp_new_i64();
8916 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
8919 tcg_gen_ld_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8921 /* acc := tmp + acc */
8922 tcg_gen_add_i64(acc
, acc
, tmp
);
8925 tcg_gen_st_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8928 gen_store_gpr64(rD(ctx
->opcode
), acc
);
8930 tcg_temp_free_i64(acc
);
8931 tcg_temp_free_i64(tmp
);
8934 static inline void gen_evmwsmi(DisasContext
*ctx
)
8938 if (unlikely(!ctx
->spe_enabled
)) {
8939 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8943 t0
= tcg_temp_new_i64();
8944 t1
= tcg_temp_new_i64();
8946 /* t0 := rA; t1 := rB */
8947 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
8948 tcg_gen_ext32s_i64(t0
, t0
);
8949 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
8950 tcg_gen_ext32s_i64(t1
, t1
);
8952 tcg_gen_mul_i64(t0
, t0
, t1
); /* t0 := rA * rB */
8954 gen_store_gpr64(rD(ctx
->opcode
), t0
); /* rD := t0 */
8956 tcg_temp_free_i64(t0
);
8957 tcg_temp_free_i64(t1
);
8960 static inline void gen_evmwsmia(DisasContext
*ctx
)
8964 gen_evmwsmi(ctx
); /* rD := rA * rB */
8966 tmp
= tcg_temp_new_i64();
8969 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
8970 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8972 tcg_temp_free_i64(tmp
);
8975 static inline void gen_evmwsmiaa(DisasContext
*ctx
)
8977 TCGv_i64 acc
= tcg_temp_new_i64();
8978 TCGv_i64 tmp
= tcg_temp_new_i64();
8980 gen_evmwsmi(ctx
); /* rD := rA * rB */
8982 acc
= tcg_temp_new_i64();
8983 tmp
= tcg_temp_new_i64();
8986 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
8989 tcg_gen_ld_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8991 /* acc := tmp + acc */
8992 tcg_gen_add_i64(acc
, acc
, tmp
);
8995 tcg_gen_st_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8998 gen_store_gpr64(rD(ctx
->opcode
), acc
);
9000 tcg_temp_free_i64(acc
);
9001 tcg_temp_free_i64(tmp
);
9004 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
9005 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
9006 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
9007 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
9008 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
9009 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
9010 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
9011 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE
); //
9012 GEN_SPE(evmra
, speundef
, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE
);
9013 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
); ////
9014 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
9015 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
9016 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
9017 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
9018 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
9019 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
9020 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
); ////
9021 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
9022 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
9023 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE
);
9024 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
9025 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
9026 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE
); //
9027 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE
);
9028 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
9029 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
9030 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE
); ////
9031 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE
); ////
9032 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE
); ////
9034 /* SPE load and stores */
9035 static inline void gen_addr_spe_imm_index(DisasContext
*ctx
, TCGv EA
, int sh
)
9037 target_ulong uimm
= rB(ctx
->opcode
);
9039 if (rA(ctx
->opcode
) == 0) {
9040 tcg_gen_movi_tl(EA
, uimm
<< sh
);
9042 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], uimm
<< sh
);
9043 if (NARROW_MODE(ctx
)) {
9044 tcg_gen_ext32u_tl(EA
, EA
);
9049 static inline void gen_op_evldd(DisasContext
*ctx
, TCGv addr
)
9051 TCGv_i64 t0
= tcg_temp_new_i64();
9052 gen_qemu_ld64(ctx
, t0
, addr
);
9053 gen_store_gpr64(rD(ctx
->opcode
), t0
);
9054 tcg_temp_free_i64(t0
);
9057 static inline void gen_op_evldw(DisasContext
*ctx
, TCGv addr
)
9059 gen_qemu_ld32u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
9060 gen_addr_add(ctx
, addr
, addr
, 4);
9061 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
9064 static inline void gen_op_evldh(DisasContext
*ctx
, TCGv addr
)
9066 TCGv t0
= tcg_temp_new();
9067 gen_qemu_ld16u(ctx
, t0
, addr
);
9068 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
9069 gen_addr_add(ctx
, addr
, addr
, 2);
9070 gen_qemu_ld16u(ctx
, t0
, addr
);
9071 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
9072 gen_addr_add(ctx
, addr
, addr
, 2);
9073 gen_qemu_ld16u(ctx
, t0
, addr
);
9074 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
9075 gen_addr_add(ctx
, addr
, addr
, 2);
9076 gen_qemu_ld16u(ctx
, t0
, addr
);
9077 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
9081 static inline void gen_op_evlhhesplat(DisasContext
*ctx
, TCGv addr
)
9083 TCGv t0
= tcg_temp_new();
9084 gen_qemu_ld16u(ctx
, t0
, addr
);
9085 tcg_gen_shli_tl(t0
, t0
, 16);
9086 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
9087 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
9091 static inline void gen_op_evlhhousplat(DisasContext
*ctx
, TCGv addr
)
9093 TCGv t0
= tcg_temp_new();
9094 gen_qemu_ld16u(ctx
, t0
, addr
);
9095 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
9096 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
9100 static inline void gen_op_evlhhossplat(DisasContext
*ctx
, TCGv addr
)
9102 TCGv t0
= tcg_temp_new();
9103 gen_qemu_ld16s(ctx
, t0
, addr
);
9104 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
9105 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
9109 static inline void gen_op_evlwhe(DisasContext
*ctx
, TCGv addr
)
9111 TCGv t0
= tcg_temp_new();
9112 gen_qemu_ld16u(ctx
, t0
, addr
);
9113 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
9114 gen_addr_add(ctx
, addr
, addr
, 2);
9115 gen_qemu_ld16u(ctx
, t0
, addr
);
9116 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
9120 static inline void gen_op_evlwhou(DisasContext
*ctx
, TCGv addr
)
9122 gen_qemu_ld16u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
9123 gen_addr_add(ctx
, addr
, addr
, 2);
9124 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
9127 static inline void gen_op_evlwhos(DisasContext
*ctx
, TCGv addr
)
9129 gen_qemu_ld16s(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
9130 gen_addr_add(ctx
, addr
, addr
, 2);
9131 gen_qemu_ld16s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
9134 static inline void gen_op_evlwwsplat(DisasContext
*ctx
, TCGv addr
)
9136 TCGv t0
= tcg_temp_new();
9137 gen_qemu_ld32u(ctx
, t0
, addr
);
9138 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
9139 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
9143 static inline void gen_op_evlwhsplat(DisasContext
*ctx
, TCGv addr
)
9145 TCGv t0
= tcg_temp_new();
9146 gen_qemu_ld16u(ctx
, t0
, addr
);
9147 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
9148 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
9149 gen_addr_add(ctx
, addr
, addr
, 2);
9150 gen_qemu_ld16u(ctx
, t0
, addr
);
9151 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
9152 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
9156 static inline void gen_op_evstdd(DisasContext
*ctx
, TCGv addr
)
9158 TCGv_i64 t0
= tcg_temp_new_i64();
9159 gen_load_gpr64(t0
, rS(ctx
->opcode
));
9160 gen_qemu_st64(ctx
, t0
, addr
);
9161 tcg_temp_free_i64(t0
);
9164 static inline void gen_op_evstdw(DisasContext
*ctx
, TCGv addr
)
9166 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
9167 gen_addr_add(ctx
, addr
, addr
, 4);
9168 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
9171 static inline void gen_op_evstdh(DisasContext
*ctx
, TCGv addr
)
9173 TCGv t0
= tcg_temp_new();
9174 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
9175 gen_qemu_st16(ctx
, t0
, addr
);
9176 gen_addr_add(ctx
, addr
, addr
, 2);
9177 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
9178 gen_addr_add(ctx
, addr
, addr
, 2);
9179 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
9180 gen_qemu_st16(ctx
, t0
, addr
);
9182 gen_addr_add(ctx
, addr
, addr
, 2);
9183 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
9186 static inline void gen_op_evstwhe(DisasContext
*ctx
, TCGv addr
)
9188 TCGv t0
= tcg_temp_new();
9189 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
9190 gen_qemu_st16(ctx
, t0
, addr
);
9191 gen_addr_add(ctx
, addr
, addr
, 2);
9192 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
9193 gen_qemu_st16(ctx
, t0
, addr
);
9197 static inline void gen_op_evstwho(DisasContext
*ctx
, TCGv addr
)
9199 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
9200 gen_addr_add(ctx
, addr
, addr
, 2);
9201 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
9204 static inline void gen_op_evstwwe(DisasContext
*ctx
, TCGv addr
)
9206 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
9209 static inline void gen_op_evstwwo(DisasContext
*ctx
, TCGv addr
)
9211 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
9214 #define GEN_SPEOP_LDST(name, opc2, sh) \
9215 static void glue(gen_, name)(DisasContext *ctx) \
9218 if (unlikely(!ctx->spe_enabled)) { \
9219 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9222 gen_set_access_type(ctx, ACCESS_INT); \
9223 t0 = tcg_temp_new(); \
9224 if (Rc(ctx->opcode)) { \
9225 gen_addr_spe_imm_index(ctx, t0, sh); \
9227 gen_addr_reg_index(ctx, t0); \
9229 gen_op_##name(ctx, t0); \
9230 tcg_temp_free(t0); \
9233 GEN_SPEOP_LDST(evldd
, 0x00, 3);
9234 GEN_SPEOP_LDST(evldw
, 0x01, 3);
9235 GEN_SPEOP_LDST(evldh
, 0x02, 3);
9236 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1);
9237 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1);
9238 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1);
9239 GEN_SPEOP_LDST(evlwhe
, 0x08, 2);
9240 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2);
9241 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2);
9242 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2);
9243 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2);
9245 GEN_SPEOP_LDST(evstdd
, 0x10, 3);
9246 GEN_SPEOP_LDST(evstdw
, 0x11, 3);
9247 GEN_SPEOP_LDST(evstdh
, 0x12, 3);
9248 GEN_SPEOP_LDST(evstwhe
, 0x18, 2);
9249 GEN_SPEOP_LDST(evstwho
, 0x1A, 2);
9250 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2);
9251 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2);
9253 /* Multiply and add - TODO */
9255 GEN_SPE(speundef
, evmhessf
, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);//
9256 GEN_SPE(speundef
, evmhossf
, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9257 GEN_SPE(evmheumi
, evmhesmi
, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
9258 GEN_SPE(speundef
, evmhesmf
, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9259 GEN_SPE(evmhoumi
, evmhosmi
, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
9260 GEN_SPE(speundef
, evmhosmf
, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9261 GEN_SPE(speundef
, evmhessfa
, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9262 GEN_SPE(speundef
, evmhossfa
, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9263 GEN_SPE(evmheumia
, evmhesmia
, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
9264 GEN_SPE(speundef
, evmhesmfa
, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9265 GEN_SPE(evmhoumia
, evmhosmia
, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
9266 GEN_SPE(speundef
, evmhosmfa
, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9268 GEN_SPE(speundef
, evmwhssf
, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9269 GEN_SPE(evmwlumi
, speundef
, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
9270 GEN_SPE(evmwhumi
, evmwhsmi
, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
9271 GEN_SPE(speundef
, evmwhsmf
, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9272 GEN_SPE(speundef
, evmwssf
, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9273 GEN_SPE(speundef
, evmwsmf
, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9274 GEN_SPE(speundef
, evmwhssfa
, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9275 GEN_SPE(evmwlumia
, speundef
, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
9276 GEN_SPE(evmwhumia
, evmwhsmia
, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
9277 GEN_SPE(speundef
, evmwhsmfa
, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9278 GEN_SPE(speundef
, evmwssfa
, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9279 GEN_SPE(speundef
, evmwsmfa
, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9281 GEN_SPE(evadduiaaw
, evaddsiaaw
, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
9282 GEN_SPE(evsubfusiaaw
, evsubfssiaaw
, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
9283 GEN_SPE(evaddumiaaw
, evaddsmiaaw
, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
9284 GEN_SPE(evsubfumiaaw
, evsubfsmiaaw
, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
9285 GEN_SPE(evdivws
, evdivwu
, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE
);
9287 GEN_SPE(evmheusiaaw
, evmhessiaaw
, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9288 GEN_SPE(speundef
, evmhessfaaw
, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9289 GEN_SPE(evmhousiaaw
, evmhossiaaw
, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9290 GEN_SPE(speundef
, evmhossfaaw
, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9291 GEN_SPE(evmheumiaaw
, evmhesmiaaw
, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9292 GEN_SPE(speundef
, evmhesmfaaw
, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9293 GEN_SPE(evmhoumiaaw
, evmhosmiaaw
, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9294 GEN_SPE(speundef
, evmhosmfaaw
, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9295 GEN_SPE(evmhegumiaa
, evmhegsmiaa
, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9296 GEN_SPE(speundef
, evmhegsmfaa
, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9297 GEN_SPE(evmhogumiaa
, evmhogsmiaa
, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9298 GEN_SPE(speundef
, evmhogsmfaa
, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9300 GEN_SPE(evmwlusiaaw
, evmwlssiaaw
, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
9301 GEN_SPE(evmwlumiaaw
, evmwlsmiaaw
, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
9302 GEN_SPE(speundef
, evmwssfaa
, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9303 GEN_SPE(speundef
, evmwsmfaa
, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9305 GEN_SPE(evmheusianw
, evmhessianw
, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9306 GEN_SPE(speundef
, evmhessfanw
, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9307 GEN_SPE(evmhousianw
, evmhossianw
, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9308 GEN_SPE(speundef
, evmhossfanw
, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9309 GEN_SPE(evmheumianw
, evmhesmianw
, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9310 GEN_SPE(speundef
, evmhesmfanw
, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9311 GEN_SPE(evmhoumianw
, evmhosmianw
, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9312 GEN_SPE(speundef
, evmhosmfanw
, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9313 GEN_SPE(evmhegumian
, evmhegsmian
, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9314 GEN_SPE(speundef
, evmhegsmfan
, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9315 GEN_SPE(evmhigumian
, evmhigsmian
, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9316 GEN_SPE(speundef
, evmhogsmfan
, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9318 GEN_SPE(evmwlusianw
, evmwlssianw
, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
9319 GEN_SPE(evmwlumianw
, evmwlsmianw
, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
9320 GEN_SPE(speundef
, evmwssfan
, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9321 GEN_SPE(evmwumian
, evmwsmian
, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
9322 GEN_SPE(speundef
, evmwsmfan
, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9325 /*** SPE floating-point extension ***/
9326 #define GEN_SPEFPUOP_CONV_32_32(name) \
9327 static inline void gen_##name(DisasContext *ctx) \
9329 TCGv_i32 t0 = tcg_temp_new_i32(); \
9330 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
9331 gen_helper_##name(t0, cpu_env, t0); \
9332 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
9333 tcg_temp_free_i32(t0); \
9335 #define GEN_SPEFPUOP_CONV_32_64(name) \
9336 static inline void gen_##name(DisasContext *ctx) \
9338 TCGv_i64 t0 = tcg_temp_new_i64(); \
9339 TCGv_i32 t1 = tcg_temp_new_i32(); \
9340 gen_load_gpr64(t0, rB(ctx->opcode)); \
9341 gen_helper_##name(t1, cpu_env, t0); \
9342 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1); \
9343 tcg_temp_free_i64(t0); \
9344 tcg_temp_free_i32(t1); \
9346 #define GEN_SPEFPUOP_CONV_64_32(name) \
9347 static inline void gen_##name(DisasContext *ctx) \
9349 TCGv_i64 t0 = tcg_temp_new_i64(); \
9350 TCGv_i32 t1 = tcg_temp_new_i32(); \
9351 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9352 gen_helper_##name(t0, cpu_env, t1); \
9353 gen_store_gpr64(rD(ctx->opcode), t0); \
9354 tcg_temp_free_i64(t0); \
9355 tcg_temp_free_i32(t1); \
9357 #define GEN_SPEFPUOP_CONV_64_64(name) \
9358 static inline void gen_##name(DisasContext *ctx) \
9360 TCGv_i64 t0 = tcg_temp_new_i64(); \
9361 gen_load_gpr64(t0, rB(ctx->opcode)); \
9362 gen_helper_##name(t0, cpu_env, t0); \
9363 gen_store_gpr64(rD(ctx->opcode), t0); \
9364 tcg_temp_free_i64(t0); \
9366 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
9367 static inline void gen_##name(DisasContext *ctx) \
9370 if (unlikely(!ctx->spe_enabled)) { \
9371 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9374 t0 = tcg_temp_new_i32(); \
9375 t1 = tcg_temp_new_i32(); \
9376 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9377 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9378 gen_helper_##name(t0, cpu_env, t0, t1); \
9379 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
9381 tcg_temp_free_i32(t0); \
9382 tcg_temp_free_i32(t1); \
9384 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
9385 static inline void gen_##name(DisasContext *ctx) \
9388 if (unlikely(!ctx->spe_enabled)) { \
9389 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9392 t0 = tcg_temp_new_i64(); \
9393 t1 = tcg_temp_new_i64(); \
9394 gen_load_gpr64(t0, rA(ctx->opcode)); \
9395 gen_load_gpr64(t1, rB(ctx->opcode)); \
9396 gen_helper_##name(t0, cpu_env, t0, t1); \
9397 gen_store_gpr64(rD(ctx->opcode), t0); \
9398 tcg_temp_free_i64(t0); \
9399 tcg_temp_free_i64(t1); \
9401 #define GEN_SPEFPUOP_COMP_32(name) \
9402 static inline void gen_##name(DisasContext *ctx) \
9405 if (unlikely(!ctx->spe_enabled)) { \
9406 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9409 t0 = tcg_temp_new_i32(); \
9410 t1 = tcg_temp_new_i32(); \
9412 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9413 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9414 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
9416 tcg_temp_free_i32(t0); \
9417 tcg_temp_free_i32(t1); \
9419 #define GEN_SPEFPUOP_COMP_64(name) \
9420 static inline void gen_##name(DisasContext *ctx) \
9423 if (unlikely(!ctx->spe_enabled)) { \
9424 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9427 t0 = tcg_temp_new_i64(); \
9428 t1 = tcg_temp_new_i64(); \
9429 gen_load_gpr64(t0, rA(ctx->opcode)); \
9430 gen_load_gpr64(t1, rB(ctx->opcode)); \
9431 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
9432 tcg_temp_free_i64(t0); \
9433 tcg_temp_free_i64(t1); \
9436 /* Single precision floating-point vectors operations */
9438 GEN_SPEFPUOP_ARITH2_64_64(evfsadd
);
9439 GEN_SPEFPUOP_ARITH2_64_64(evfssub
);
9440 GEN_SPEFPUOP_ARITH2_64_64(evfsmul
);
9441 GEN_SPEFPUOP_ARITH2_64_64(evfsdiv
);
9442 static inline void gen_evfsabs(DisasContext
*ctx
)
9444 if (unlikely(!ctx
->spe_enabled
)) {
9445 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9448 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
9450 tcg_gen_andi_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)],
9453 static inline void gen_evfsnabs(DisasContext
*ctx
)
9455 if (unlikely(!ctx
->spe_enabled
)) {
9456 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9459 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
9461 tcg_gen_ori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)],
9464 static inline void gen_evfsneg(DisasContext
*ctx
)
9466 if (unlikely(!ctx
->spe_enabled
)) {
9467 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9470 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
9472 tcg_gen_xori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)],
9477 GEN_SPEFPUOP_CONV_64_64(evfscfui
);
9478 GEN_SPEFPUOP_CONV_64_64(evfscfsi
);
9479 GEN_SPEFPUOP_CONV_64_64(evfscfuf
);
9480 GEN_SPEFPUOP_CONV_64_64(evfscfsf
);
9481 GEN_SPEFPUOP_CONV_64_64(evfsctui
);
9482 GEN_SPEFPUOP_CONV_64_64(evfsctsi
);
9483 GEN_SPEFPUOP_CONV_64_64(evfsctuf
);
9484 GEN_SPEFPUOP_CONV_64_64(evfsctsf
);
9485 GEN_SPEFPUOP_CONV_64_64(evfsctuiz
);
9486 GEN_SPEFPUOP_CONV_64_64(evfsctsiz
);
9489 GEN_SPEFPUOP_COMP_64(evfscmpgt
);
9490 GEN_SPEFPUOP_COMP_64(evfscmplt
);
9491 GEN_SPEFPUOP_COMP_64(evfscmpeq
);
9492 GEN_SPEFPUOP_COMP_64(evfststgt
);
9493 GEN_SPEFPUOP_COMP_64(evfststlt
);
9494 GEN_SPEFPUOP_COMP_64(evfststeq
);
9496 /* Opcodes definitions */
9497 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
9498 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
); //
9499 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9500 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
9501 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
9502 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9503 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9504 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9505 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9506 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9507 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9508 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9509 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
9510 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9512 /* Single precision floating-point operations */
9514 GEN_SPEFPUOP_ARITH2_32_32(efsadd
);
9515 GEN_SPEFPUOP_ARITH2_32_32(efssub
);
9516 GEN_SPEFPUOP_ARITH2_32_32(efsmul
);
9517 GEN_SPEFPUOP_ARITH2_32_32(efsdiv
);
9518 static inline void gen_efsabs(DisasContext
*ctx
)
9520 if (unlikely(!ctx
->spe_enabled
)) {
9521 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9524 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], (target_long
)~0x80000000LL
);
9526 static inline void gen_efsnabs(DisasContext
*ctx
)
9528 if (unlikely(!ctx
->spe_enabled
)) {
9529 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9532 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
9534 static inline void gen_efsneg(DisasContext
*ctx
)
9536 if (unlikely(!ctx
->spe_enabled
)) {
9537 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9540 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
9544 GEN_SPEFPUOP_CONV_32_32(efscfui
);
9545 GEN_SPEFPUOP_CONV_32_32(efscfsi
);
9546 GEN_SPEFPUOP_CONV_32_32(efscfuf
);
9547 GEN_SPEFPUOP_CONV_32_32(efscfsf
);
9548 GEN_SPEFPUOP_CONV_32_32(efsctui
);
9549 GEN_SPEFPUOP_CONV_32_32(efsctsi
);
9550 GEN_SPEFPUOP_CONV_32_32(efsctuf
);
9551 GEN_SPEFPUOP_CONV_32_32(efsctsf
);
9552 GEN_SPEFPUOP_CONV_32_32(efsctuiz
);
9553 GEN_SPEFPUOP_CONV_32_32(efsctsiz
);
9554 GEN_SPEFPUOP_CONV_32_64(efscfd
);
9557 GEN_SPEFPUOP_COMP_32(efscmpgt
);
9558 GEN_SPEFPUOP_COMP_32(efscmplt
);
9559 GEN_SPEFPUOP_COMP_32(efscmpeq
);
9560 GEN_SPEFPUOP_COMP_32(efststgt
);
9561 GEN_SPEFPUOP_COMP_32(efststlt
);
9562 GEN_SPEFPUOP_COMP_32(efststeq
);
9564 /* Opcodes definitions */
9565 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
9566 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
); //
9567 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9568 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
9569 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
9570 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE
); //
9571 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9572 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9573 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9574 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9575 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9576 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9577 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
9578 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9580 /* Double precision floating-point operations */
9582 GEN_SPEFPUOP_ARITH2_64_64(efdadd
);
9583 GEN_SPEFPUOP_ARITH2_64_64(efdsub
);
9584 GEN_SPEFPUOP_ARITH2_64_64(efdmul
);
9585 GEN_SPEFPUOP_ARITH2_64_64(efddiv
);
9586 static inline void gen_efdabs(DisasContext
*ctx
)
9588 if (unlikely(!ctx
->spe_enabled
)) {
9589 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9592 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
9593 tcg_gen_andi_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)],
9596 static inline void gen_efdnabs(DisasContext
*ctx
)
9598 if (unlikely(!ctx
->spe_enabled
)) {
9599 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9602 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
9603 tcg_gen_ori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)],
9606 static inline void gen_efdneg(DisasContext
*ctx
)
9608 if (unlikely(!ctx
->spe_enabled
)) {
9609 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9612 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
9613 tcg_gen_xori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)],
9618 GEN_SPEFPUOP_CONV_64_32(efdcfui
);
9619 GEN_SPEFPUOP_CONV_64_32(efdcfsi
);
9620 GEN_SPEFPUOP_CONV_64_32(efdcfuf
);
9621 GEN_SPEFPUOP_CONV_64_32(efdcfsf
);
9622 GEN_SPEFPUOP_CONV_32_64(efdctui
);
9623 GEN_SPEFPUOP_CONV_32_64(efdctsi
);
9624 GEN_SPEFPUOP_CONV_32_64(efdctuf
);
9625 GEN_SPEFPUOP_CONV_32_64(efdctsf
);
9626 GEN_SPEFPUOP_CONV_32_64(efdctuiz
);
9627 GEN_SPEFPUOP_CONV_32_64(efdctsiz
);
9628 GEN_SPEFPUOP_CONV_64_32(efdcfs
);
9629 GEN_SPEFPUOP_CONV_64_64(efdcfuid
);
9630 GEN_SPEFPUOP_CONV_64_64(efdcfsid
);
9631 GEN_SPEFPUOP_CONV_64_64(efdctuidz
);
9632 GEN_SPEFPUOP_CONV_64_64(efdctsidz
);
9635 GEN_SPEFPUOP_COMP_64(efdcmpgt
);
9636 GEN_SPEFPUOP_COMP_64(efdcmplt
);
9637 GEN_SPEFPUOP_COMP_64(efdcmpeq
);
9638 GEN_SPEFPUOP_COMP_64(efdtstgt
);
9639 GEN_SPEFPUOP_COMP_64(efdtstlt
);
9640 GEN_SPEFPUOP_COMP_64(efdtsteq
);
9642 /* Opcodes definitions */
9643 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
); //
9644 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9645 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE
); //
9646 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
9647 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
); //
9648 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9649 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
); //
9650 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE
); //
9651 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9652 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9653 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9654 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9655 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
9656 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
9657 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
); //
9658 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
9660 static opcode_t opcodes
[] = {
9661 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
),
9662 GEN_HANDLER(cmp
, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER
),
9663 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
9664 GEN_HANDLER(cmpl
, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER
),
9665 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
9666 GEN_HANDLER_E(cmpb
, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE
, PPC2_ISA205
),
9667 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
),
9668 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9669 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9670 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9671 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9672 GEN_HANDLER(mulhw
, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER
),
9673 GEN_HANDLER(mulhwu
, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER
),
9674 GEN_HANDLER(mullw
, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER
),
9675 GEN_HANDLER(mullwo
, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER
),
9676 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9677 #if defined(TARGET_PPC64)
9678 GEN_HANDLER(mulld
, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B
),
9680 GEN_HANDLER(neg
, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER
),
9681 GEN_HANDLER(nego
, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER
),
9682 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9683 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9684 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9685 GEN_HANDLER(cntlzw
, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER
),
9686 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
),
9687 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
),
9688 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9689 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9690 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9691 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9692 GEN_HANDLER(popcntb
, 0x1F, 0x1A, 0x03, 0x0000F801, PPC_POPCNTB
),
9693 GEN_HANDLER(popcntw
, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD
),
9694 GEN_HANDLER_E(prtyw
, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
9695 #if defined(TARGET_PPC64)
9696 GEN_HANDLER(popcntd
, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD
),
9697 GEN_HANDLER(cntlzd
, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B
),
9698 GEN_HANDLER_E(prtyd
, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
9699 GEN_HANDLER_E(bpermd
, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE
, PPC2_PERM_ISA206
),
9701 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9702 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9703 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9704 GEN_HANDLER(slw
, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER
),
9705 GEN_HANDLER(sraw
, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER
),
9706 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
),
9707 GEN_HANDLER(srw
, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER
),
9708 #if defined(TARGET_PPC64)
9709 GEN_HANDLER(sld
, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B
),
9710 GEN_HANDLER(srad
, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B
),
9711 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
),
9712 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
),
9713 GEN_HANDLER(srd
, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B
),
9715 GEN_HANDLER(frsqrtes
, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES
),
9716 GEN_HANDLER(fsqrt
, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
9717 GEN_HANDLER(fsqrts
, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
9718 GEN_HANDLER(fcmpo
, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT
),
9719 GEN_HANDLER(fcmpu
, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT
),
9720 GEN_HANDLER(fabs
, 0x3F, 0x08, 0x08, 0x001F0000, PPC_FLOAT
),
9721 GEN_HANDLER(fmr
, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT
),
9722 GEN_HANDLER(fnabs
, 0x3F, 0x08, 0x04, 0x001F0000, PPC_FLOAT
),
9723 GEN_HANDLER(fneg
, 0x3F, 0x08, 0x01, 0x001F0000, PPC_FLOAT
),
9724 GEN_HANDLER_E(fcpsgn
, 0x3F, 0x08, 0x00, 0x00000000, PPC_NONE
, PPC2_ISA205
),
9725 GEN_HANDLER_E(fmrgew
, 0x3F, 0x06, 0x1E, 0x00000001, PPC_NONE
, PPC2_VSX207
),
9726 GEN_HANDLER_E(fmrgow
, 0x3F, 0x06, 0x1A, 0x00000001, PPC_NONE
, PPC2_VSX207
),
9727 GEN_HANDLER(mcrfs
, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT
),
9728 GEN_HANDLER(mffs
, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT
),
9729 GEN_HANDLER(mtfsb0
, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT
),
9730 GEN_HANDLER(mtfsb1
, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT
),
9731 GEN_HANDLER(mtfsf
, 0x3F, 0x07, 0x16, 0x00000000, PPC_FLOAT
),
9732 GEN_HANDLER(mtfsfi
, 0x3F, 0x06, 0x04, 0x006e0800, PPC_FLOAT
),
9733 #if defined(TARGET_PPC64)
9734 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
),
9735 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
),
9736 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
),
9738 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9739 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9740 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
),
9741 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
),
9742 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
),
9743 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
),
9744 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO
),
9745 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
),
9746 GEN_HANDLER_E(lbarx
, 0x1F, 0x14, 0x01, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
9747 GEN_HANDLER_E(lharx
, 0x1F, 0x14, 0x03, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
9748 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES
),
9749 GEN_HANDLER_E(stbcx_
, 0x1F, 0x16, 0x15, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
9750 GEN_HANDLER_E(sthcx_
, 0x1F, 0x16, 0x16, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
9751 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
),
9752 #if defined(TARGET_PPC64)
9753 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B
),
9754 GEN_HANDLER_E(lqarx
, 0x1F, 0x14, 0x08, 0, PPC_NONE
, PPC2_LSQ_ISA207
),
9755 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
),
9756 GEN_HANDLER_E(stqcx_
, 0x1F, 0x16, 0x05, 0, PPC_NONE
, PPC2_LSQ_ISA207
),
9758 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
),
9759 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
),
9760 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
9761 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
9762 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
),
9763 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
),
9764 GEN_HANDLER_E(bctar
, 0x13, 0x10, 0x11, 0, PPC_NONE
, PPC2_BCTAR_ISA207
),
9765 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
),
9766 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
),
9767 #if defined(TARGET_PPC64)
9768 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
),
9769 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
),
9771 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW
),
9772 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
),
9773 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
9774 #if defined(TARGET_PPC64)
9775 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
),
9776 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
),
9778 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
),
9779 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
),
9780 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
),
9781 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
),
9782 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
),
9783 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
),
9784 #if defined(TARGET_PPC64)
9785 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
),
9787 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC
),
9788 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC
),
9789 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
),
9790 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
),
9791 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
),
9792 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE
),
9793 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE
),
9794 GEN_HANDLER_E(dcbtls
, 0x1F, 0x06, 0x05, 0x02000001, PPC_BOOKE
, PPC2_BOOKE206
),
9795 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ
),
9796 GEN_HANDLER(dst
, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC
),
9797 GEN_HANDLER(dstst
, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC
),
9798 GEN_HANDLER(dss
, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC
),
9799 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
),
9800 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
),
9801 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
),
9802 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
),
9803 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
),
9804 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
),
9805 #if defined(TARGET_PPC64)
9806 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
),
9807 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
9809 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
),
9810 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
9812 GEN_HANDLER2(slbmte
, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B
),
9813 GEN_HANDLER2(slbmfee
, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B
),
9814 GEN_HANDLER2(slbmfev
, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B
),
9816 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
),
9817 GEN_HANDLER(tlbiel
, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE
),
9818 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE
),
9819 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
),
9820 #if defined(TARGET_PPC64)
9821 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI
),
9822 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
),
9824 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
),
9825 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
),
9826 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
),
9827 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
),
9828 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
),
9829 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
),
9830 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
),
9831 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
),
9832 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
),
9833 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
),
9834 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
),
9835 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
9836 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
),
9837 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
),
9838 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
),
9839 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
),
9840 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
),
9841 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
),
9842 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
),
9843 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
9844 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
),
9845 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
),
9846 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
),
9847 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
),
9848 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
),
9849 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
),
9850 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
),
9851 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
),
9852 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
),
9853 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
),
9854 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
),
9855 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
),
9856 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
),
9857 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
),
9858 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
),
9859 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
),
9860 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
),
9861 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
),
9862 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
),
9863 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
),
9864 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
),
9865 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
),
9866 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
),
9867 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
),
9868 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
),
9869 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
),
9870 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
),
9871 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
),
9872 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
),
9873 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
9874 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
9875 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
),
9876 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
),
9877 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
9878 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
9879 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
),
9880 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
),
9881 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
),
9882 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
),
9883 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
),
9884 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
),
9885 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
),
9886 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
),
9887 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
),
9888 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
),
9889 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
),
9890 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
),
9891 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
),
9892 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
),
9893 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
),
9894 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
),
9895 GEN_HANDLER_E(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
, PPC2_BOOKE206
),
9896 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
),
9897 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
),
9898 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
),
9899 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
),
9900 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
),
9901 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
),
9902 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
),
9903 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
),
9904 GEN_HANDLER2_E(tlbre_booke206
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
9905 PPC_NONE
, PPC2_BOOKE206
),
9906 GEN_HANDLER2_E(tlbsx_booke206
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
9907 PPC_NONE
, PPC2_BOOKE206
),
9908 GEN_HANDLER2_E(tlbwe_booke206
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
9909 PPC_NONE
, PPC2_BOOKE206
),
9910 GEN_HANDLER2_E(tlbivax_booke206
, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
9911 PPC_NONE
, PPC2_BOOKE206
),
9912 GEN_HANDLER2_E(tlbilx_booke206
, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
9913 PPC_NONE
, PPC2_BOOKE206
),
9914 GEN_HANDLER2_E(msgsnd
, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
9915 PPC_NONE
, PPC2_PRCNTL
),
9916 GEN_HANDLER2_E(msgclr
, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
9917 PPC_NONE
, PPC2_PRCNTL
),
9918 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
),
9919 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE
),
9920 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
),
9921 GEN_HANDLER_E(mbar
, 0x1F, 0x16, 0x1a, 0x001FF801,
9922 PPC_BOOKE
, PPC2_BOOKE206
),
9923 GEN_HANDLER(msync_4xx
, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE
),
9924 GEN_HANDLER2_E(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
9925 PPC_BOOKE
, PPC2_BOOKE206
),
9926 GEN_HANDLER(lvsl
, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC
),
9927 GEN_HANDLER(lvsr
, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC
),
9928 GEN_HANDLER(mfvscr
, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC
),
9929 GEN_HANDLER(mtvscr
, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC
),
9930 GEN_HANDLER(vmladduhm
, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC
),
9931 GEN_HANDLER2(evsel0
, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE
),
9932 GEN_HANDLER2(evsel1
, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE
),
9933 GEN_HANDLER2(evsel2
, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE
),
9934 GEN_HANDLER2(evsel3
, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE
),
9936 #undef GEN_INT_ARITH_ADD
9937 #undef GEN_INT_ARITH_ADD_CONST
9938 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
9939 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
9940 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
9941 add_ca, compute_ca, compute_ov) \
9942 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
9943 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
9944 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
9945 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
9946 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
9947 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
9948 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
9949 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
9950 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
9951 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
9952 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
9954 #undef GEN_INT_ARITH_DIVW
9955 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
9956 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
9957 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0),
9958 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1),
9959 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0),
9960 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1),
9961 GEN_HANDLER_E(divwe
, 0x1F, 0x0B, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9962 GEN_HANDLER_E(divweo
, 0x1F, 0x0B, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9963 GEN_HANDLER_E(divweu
, 0x1F, 0x0B, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9964 GEN_HANDLER_E(divweuo
, 0x1F, 0x0B, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9966 #if defined(TARGET_PPC64)
9967 #undef GEN_INT_ARITH_DIVD
9968 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
9969 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
9970 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0),
9971 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1),
9972 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0),
9973 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1),
9975 GEN_HANDLER_E(divdeu
, 0x1F, 0x09, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9976 GEN_HANDLER_E(divdeuo
, 0x1F, 0x09, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9977 GEN_HANDLER_E(divde
, 0x1F, 0x09, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9978 GEN_HANDLER_E(divdeo
, 0x1F, 0x09, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9980 #undef GEN_INT_ARITH_MUL_HELPER
9981 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
9982 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
9983 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00),
9984 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02),
9985 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17),
9988 #undef GEN_INT_ARITH_SUBF
9989 #undef GEN_INT_ARITH_SUBF_CONST
9990 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
9991 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
9992 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
9993 add_ca, compute_ca, compute_ov) \
9994 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
9995 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
9996 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
9997 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
9998 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
9999 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
10000 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
10001 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
10002 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
10003 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
10004 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
10006 #undef GEN_LOGICAL1
10007 #undef GEN_LOGICAL2
10008 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
10009 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
10010 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
10011 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
10012 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
),
10013 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
),
10014 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
),
10015 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
),
10016 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
),
10017 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
),
10018 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
),
10019 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
),
10020 #if defined(TARGET_PPC64)
10021 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
),
10024 #if defined(TARGET_PPC64)
10025 #undef GEN_PPC64_R2
10026 #undef GEN_PPC64_R4
10027 #define GEN_PPC64_R2(name, opc1, opc2) \
10028 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10029 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10031 #define GEN_PPC64_R4(name, opc1, opc2) \
10032 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10033 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
10035 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10037 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
10039 GEN_PPC64_R4(rldicl
, 0x1E, 0x00),
10040 GEN_PPC64_R4(rldicr
, 0x1E, 0x02),
10041 GEN_PPC64_R4(rldic
, 0x1E, 0x04),
10042 GEN_PPC64_R2(rldcl
, 0x1E, 0x08),
10043 GEN_PPC64_R2(rldcr
, 0x1E, 0x09),
10044 GEN_PPC64_R4(rldimi
, 0x1E, 0x06),
10047 #undef _GEN_FLOAT_ACB
10048 #undef GEN_FLOAT_ACB
10049 #undef _GEN_FLOAT_AB
10050 #undef GEN_FLOAT_AB
10051 #undef _GEN_FLOAT_AC
10052 #undef GEN_FLOAT_AC
10054 #undef GEN_FLOAT_BS
10055 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
10056 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
10057 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
10058 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
10059 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
10060 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10061 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10062 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
10063 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10064 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10065 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10066 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10067 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
10068 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10069 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10070 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
10071 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
10072 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
10073 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
10075 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
),
10076 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
),
10077 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
),
10078 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
),
10079 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
),
10080 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
),
10081 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
),
10082 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
),
10083 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
),
10084 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
),
10085 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
),
10086 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
),
10087 GEN_HANDLER_E(ftdiv
, 0x3F, 0x00, 0x04, 1, PPC_NONE
, PPC2_FP_TST_ISA206
),
10088 GEN_HANDLER_E(ftsqrt
, 0x3F, 0x00, 0x05, 1, PPC_NONE
, PPC2_FP_TST_ISA206
),
10089 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
),
10090 GEN_HANDLER_E(fctiwu
, 0x3F, 0x0E, 0x04, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10091 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
),
10092 GEN_HANDLER_E(fctiwuz
, 0x3F, 0x0F, 0x04, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10093 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
),
10094 #if defined(TARGET_PPC64)
10095 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
),
10096 GEN_HANDLER_E(fcfids
, 0x3B, 0x0E, 0x1A, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10097 GEN_HANDLER_E(fcfidu
, 0x3F, 0x0E, 0x1E, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10098 GEN_HANDLER_E(fcfidus
, 0x3B, 0x0E, 0x1E, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10099 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
),
10100 GEN_HANDLER_E(fctidu
, 0x3F, 0x0E, 0x1D, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10101 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
),
10102 GEN_HANDLER_E(fctiduz
, 0x3F, 0x0F, 0x1D, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10104 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
),
10105 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
),
10106 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
),
10107 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
),
10114 #define GEN_LD(name, ldop, opc, type) \
10115 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10116 #define GEN_LDU(name, ldop, opc, type) \
10117 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10118 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
10119 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
10120 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
10121 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
10122 #define GEN_LDS(name, ldop, op, type) \
10123 GEN_LD(name, ldop, op | 0x20, type) \
10124 GEN_LDU(name, ldop, op | 0x21, type) \
10125 GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
10126 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
10128 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
)
10129 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
)
10130 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
)
10131 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
)
10132 #if defined(TARGET_PPC64)
10133 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
)
10134 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
)
10135 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
)
10136 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
)
10137 GEN_LDX_E(ldbr
, ld64ur
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
)
10139 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
)
10140 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
)
10147 #define GEN_ST(name, stop, opc, type) \
10148 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10149 #define GEN_STU(name, stop, opc, type) \
10150 GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
10151 #define GEN_STUX(name, stop, opc2, opc3, type) \
10152 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
10153 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
10154 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
10155 #define GEN_STS(name, stop, op, type) \
10156 GEN_ST(name, stop, op | 0x20, type) \
10157 GEN_STU(name, stop, op | 0x21, type) \
10158 GEN_STUX(name, stop, 0x17, op | 0x01, type) \
10159 GEN_STX(name, stop, 0x17, op | 0x00, type)
10161 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
)
10162 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
)
10163 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
)
10164 #if defined(TARGET_PPC64)
10165 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
)
10166 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
)
10167 GEN_STX_E(stdbr
, st64r
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
)
10169 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
)
10170 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
)
10177 #define GEN_LDF(name, ldop, opc, type) \
10178 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10179 #define GEN_LDUF(name, ldop, opc, type) \
10180 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10181 #define GEN_LDUXF(name, ldop, opc, type) \
10182 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10183 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
10184 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10185 #define GEN_LDFS(name, ldop, op, type) \
10186 GEN_LDF(name, ldop, op | 0x20, type) \
10187 GEN_LDUF(name, ldop, op | 0x21, type) \
10188 GEN_LDUXF(name, ldop, op | 0x01, type) \
10189 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
10191 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
)
10192 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
)
10193 GEN_HANDLER_E(lfiwax
, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE
, PPC2_ISA205
),
10194 GEN_HANDLER_E(lfiwzx
, 0x1f, 0x17, 0x1b, 0x1, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10195 GEN_HANDLER_E(lfdp
, 0x39, 0xFF, 0xFF, 0x00200003, PPC_NONE
, PPC2_ISA205
),
10196 GEN_HANDLER_E(lfdpx
, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE
, PPC2_ISA205
),
10203 #define GEN_STF(name, stop, opc, type) \
10204 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10205 #define GEN_STUF(name, stop, opc, type) \
10206 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10207 #define GEN_STUXF(name, stop, opc, type) \
10208 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10209 #define GEN_STXF(name, stop, opc2, opc3, type) \
10210 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10211 #define GEN_STFS(name, stop, op, type) \
10212 GEN_STF(name, stop, op | 0x20, type) \
10213 GEN_STUF(name, stop, op | 0x21, type) \
10214 GEN_STUXF(name, stop, op | 0x01, type) \
10215 GEN_STXF(name, stop, 0x17, op | 0x00, type)
10217 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
)
10218 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
)
10219 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
)
10220 GEN_HANDLER_E(stfdp
, 0x3D, 0xFF, 0xFF, 0x00200003, PPC_NONE
, PPC2_ISA205
),
10221 GEN_HANDLER_E(stfdpx
, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE
, PPC2_ISA205
),
10224 #define GEN_CRLOGIC(name, tcg_op, opc) \
10225 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
10226 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08),
10227 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04),
10228 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09),
10229 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07),
10230 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01),
10231 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E),
10232 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D),
10233 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06),
10235 #undef GEN_MAC_HANDLER
10236 #define GEN_MAC_HANDLER(name, opc2, opc3) \
10237 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
10238 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05),
10239 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15),
10240 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07),
10241 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17),
10242 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06),
10243 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16),
10244 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04),
10245 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14),
10246 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01),
10247 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11),
10248 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03),
10249 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13),
10250 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02),
10251 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12),
10252 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00),
10253 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10),
10254 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D),
10255 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D),
10256 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F),
10257 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F),
10258 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C),
10259 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C),
10260 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E),
10261 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E),
10262 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05),
10263 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15),
10264 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07),
10265 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17),
10266 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01),
10267 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11),
10268 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03),
10269 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13),
10270 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D),
10271 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D),
10272 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F),
10273 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F),
10274 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05),
10275 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04),
10276 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01),
10277 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00),
10278 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D),
10279 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C),
10285 #define GEN_VR_LDX(name, opc2, opc3) \
10286 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10287 #define GEN_VR_STX(name, opc2, opc3) \
10288 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10289 #define GEN_VR_LVE(name, opc2, opc3) \
10290 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10291 #define GEN_VR_STVE(name, opc2, opc3) \
10292 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10293 GEN_VR_LDX(lvx
, 0x07, 0x03),
10294 GEN_VR_LDX(lvxl
, 0x07, 0x0B),
10295 GEN_VR_LVE(bx
, 0x07, 0x00),
10296 GEN_VR_LVE(hx
, 0x07, 0x01),
10297 GEN_VR_LVE(wx
, 0x07, 0x02),
10298 GEN_VR_STX(svx
, 0x07, 0x07),
10299 GEN_VR_STX(svxl
, 0x07, 0x0F),
10300 GEN_VR_STVE(bx
, 0x07, 0x04),
10301 GEN_VR_STVE(hx
, 0x07, 0x05),
10302 GEN_VR_STVE(wx
, 0x07, 0x06),
10304 #undef GEN_VX_LOGICAL
10305 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
10306 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10308 #undef GEN_VX_LOGICAL_207
10309 #define GEN_VX_LOGICAL_207(name, tcg_op, opc2, opc3) \
10310 GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10312 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16),
10313 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17),
10314 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18),
10315 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19),
10316 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20),
10317 GEN_VX_LOGICAL_207(veqv
, tcg_gen_eqv_i64
, 2, 26),
10318 GEN_VX_LOGICAL_207(vnand
, tcg_gen_nand_i64
, 2, 22),
10319 GEN_VX_LOGICAL_207(vorc
, tcg_gen_orc_i64
, 2, 21),
10322 #define GEN_VXFORM(name, opc2, opc3) \
10323 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10325 #undef GEN_VXFORM_207
10326 #define GEN_VXFORM_207(name, opc2, opc3) \
10327 GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10329 #undef GEN_VXFORM_DUAL
10330 #define GEN_VXFORM_DUAL(name0, name1, opc2, opc3, type0, type1) \
10331 GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, type0, type1)
10333 #undef GEN_VXRFORM_DUAL
10334 #define GEN_VXRFORM_DUAL(name0, name1, opc2, opc3, tp0, tp1) \
10335 GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, tp0, tp1), \
10336 GEN_HANDLER_E(name0##_##name1, 0x4, opc2, (opc3 | 0x10), 0x00000000, tp0, tp1),
10338 GEN_VXFORM(vaddubm
, 0, 0),
10339 GEN_VXFORM(vadduhm
, 0, 1),
10340 GEN_VXFORM(vadduwm
, 0, 2),
10341 GEN_VXFORM_207(vaddudm
, 0, 3),
10342 GEN_VXFORM_DUAL(vsububm
, bcdadd
, 0, 16, PPC_ALTIVEC
, PPC_NONE
),
10343 GEN_VXFORM_DUAL(vsubuhm
, bcdsub
, 0, 17, PPC_ALTIVEC
, PPC_NONE
),
10344 GEN_VXFORM(vsubuwm
, 0, 18),
10345 GEN_VXFORM_207(vsubudm
, 0, 19),
10346 GEN_VXFORM(vmaxub
, 1, 0),
10347 GEN_VXFORM(vmaxuh
, 1, 1),
10348 GEN_VXFORM(vmaxuw
, 1, 2),
10349 GEN_VXFORM_207(vmaxud
, 1, 3),
10350 GEN_VXFORM(vmaxsb
, 1, 4),
10351 GEN_VXFORM(vmaxsh
, 1, 5),
10352 GEN_VXFORM(vmaxsw
, 1, 6),
10353 GEN_VXFORM_207(vmaxsd
, 1, 7),
10354 GEN_VXFORM(vminub
, 1, 8),
10355 GEN_VXFORM(vminuh
, 1, 9),
10356 GEN_VXFORM(vminuw
, 1, 10),
10357 GEN_VXFORM_207(vminud
, 1, 11),
10358 GEN_VXFORM(vminsb
, 1, 12),
10359 GEN_VXFORM(vminsh
, 1, 13),
10360 GEN_VXFORM(vminsw
, 1, 14),
10361 GEN_VXFORM_207(vminsd
, 1, 15),
10362 GEN_VXFORM(vavgub
, 1, 16),
10363 GEN_VXFORM(vavguh
, 1, 17),
10364 GEN_VXFORM(vavguw
, 1, 18),
10365 GEN_VXFORM(vavgsb
, 1, 20),
10366 GEN_VXFORM(vavgsh
, 1, 21),
10367 GEN_VXFORM(vavgsw
, 1, 22),
10368 GEN_VXFORM(vmrghb
, 6, 0),
10369 GEN_VXFORM(vmrghh
, 6, 1),
10370 GEN_VXFORM(vmrghw
, 6, 2),
10371 GEN_VXFORM(vmrglb
, 6, 4),
10372 GEN_VXFORM(vmrglh
, 6, 5),
10373 GEN_VXFORM(vmrglw
, 6, 6),
10374 GEN_VXFORM_207(vmrgew
, 6, 30),
10375 GEN_VXFORM_207(vmrgow
, 6, 26),
10376 GEN_VXFORM(vmuloub
, 4, 0),
10377 GEN_VXFORM(vmulouh
, 4, 1),
10378 GEN_VXFORM_DUAL(vmulouw
, vmuluwm
, 4, 2, PPC_ALTIVEC
, PPC_NONE
),
10379 GEN_VXFORM(vmulosb
, 4, 4),
10380 GEN_VXFORM(vmulosh
, 4, 5),
10381 GEN_VXFORM_207(vmulosw
, 4, 6),
10382 GEN_VXFORM(vmuleub
, 4, 8),
10383 GEN_VXFORM(vmuleuh
, 4, 9),
10384 GEN_VXFORM_207(vmuleuw
, 4, 10),
10385 GEN_VXFORM(vmulesb
, 4, 12),
10386 GEN_VXFORM(vmulesh
, 4, 13),
10387 GEN_VXFORM_207(vmulesw
, 4, 14),
10388 GEN_VXFORM(vslb
, 2, 4),
10389 GEN_VXFORM(vslh
, 2, 5),
10390 GEN_VXFORM(vslw
, 2, 6),
10391 GEN_VXFORM_207(vsld
, 2, 23),
10392 GEN_VXFORM(vsrb
, 2, 8),
10393 GEN_VXFORM(vsrh
, 2, 9),
10394 GEN_VXFORM(vsrw
, 2, 10),
10395 GEN_VXFORM_207(vsrd
, 2, 27),
10396 GEN_VXFORM(vsrab
, 2, 12),
10397 GEN_VXFORM(vsrah
, 2, 13),
10398 GEN_VXFORM(vsraw
, 2, 14),
10399 GEN_VXFORM_207(vsrad
, 2, 15),
10400 GEN_VXFORM(vslo
, 6, 16),
10401 GEN_VXFORM(vsro
, 6, 17),
10402 GEN_VXFORM(vaddcuw
, 0, 6),
10403 GEN_VXFORM(vsubcuw
, 0, 22),
10404 GEN_VXFORM(vaddubs
, 0, 8),
10405 GEN_VXFORM(vadduhs
, 0, 9),
10406 GEN_VXFORM(vadduws
, 0, 10),
10407 GEN_VXFORM(vaddsbs
, 0, 12),
10408 GEN_VXFORM(vaddshs
, 0, 13),
10409 GEN_VXFORM(vaddsws
, 0, 14),
10410 GEN_VXFORM_DUAL(vsububs
, bcdadd
, 0, 24, PPC_ALTIVEC
, PPC_NONE
),
10411 GEN_VXFORM_DUAL(vsubuhs
, bcdsub
, 0, 25, PPC_ALTIVEC
, PPC_NONE
),
10412 GEN_VXFORM(vsubuws
, 0, 26),
10413 GEN_VXFORM(vsubsbs
, 0, 28),
10414 GEN_VXFORM(vsubshs
, 0, 29),
10415 GEN_VXFORM(vsubsws
, 0, 30),
10416 GEN_VXFORM_207(vadduqm
, 0, 4),
10417 GEN_VXFORM_207(vaddcuq
, 0, 5),
10418 GEN_VXFORM_DUAL(vaddeuqm
, vaddecuq
, 30, 0xFF, PPC_NONE
, PPC2_ALTIVEC_207
),
10419 GEN_VXFORM_207(vsubuqm
, 0, 20),
10420 GEN_VXFORM_207(vsubcuq
, 0, 21),
10421 GEN_VXFORM_DUAL(vsubeuqm
, vsubecuq
, 31, 0xFF, PPC_NONE
, PPC2_ALTIVEC_207
),
10422 GEN_VXFORM(vrlb
, 2, 0),
10423 GEN_VXFORM(vrlh
, 2, 1),
10424 GEN_VXFORM(vrlw
, 2, 2),
10425 GEN_VXFORM_207(vrld
, 2, 3),
10426 GEN_VXFORM(vsl
, 2, 7),
10427 GEN_VXFORM(vsr
, 2, 11),
10428 GEN_VXFORM(vpkuhum
, 7, 0),
10429 GEN_VXFORM(vpkuwum
, 7, 1),
10430 GEN_VXFORM_207(vpkudum
, 7, 17),
10431 GEN_VXFORM(vpkuhus
, 7, 2),
10432 GEN_VXFORM(vpkuwus
, 7, 3),
10433 GEN_VXFORM_207(vpkudus
, 7, 19),
10434 GEN_VXFORM(vpkshus
, 7, 4),
10435 GEN_VXFORM(vpkswus
, 7, 5),
10436 GEN_VXFORM_207(vpksdus
, 7, 21),
10437 GEN_VXFORM(vpkshss
, 7, 6),
10438 GEN_VXFORM(vpkswss
, 7, 7),
10439 GEN_VXFORM_207(vpksdss
, 7, 23),
10440 GEN_VXFORM(vpkpx
, 7, 12),
10441 GEN_VXFORM(vsum4ubs
, 4, 24),
10442 GEN_VXFORM(vsum4sbs
, 4, 28),
10443 GEN_VXFORM(vsum4shs
, 4, 25),
10444 GEN_VXFORM(vsum2sws
, 4, 26),
10445 GEN_VXFORM(vsumsws
, 4, 30),
10446 GEN_VXFORM(vaddfp
, 5, 0),
10447 GEN_VXFORM(vsubfp
, 5, 1),
10448 GEN_VXFORM(vmaxfp
, 5, 16),
10449 GEN_VXFORM(vminfp
, 5, 17),
10451 #undef GEN_VXRFORM1
10453 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
10454 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
10455 #define GEN_VXRFORM(name, opc2, opc3) \
10456 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
10457 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
10458 GEN_VXRFORM(vcmpequb
, 3, 0)
10459 GEN_VXRFORM(vcmpequh
, 3, 1)
10460 GEN_VXRFORM(vcmpequw
, 3, 2)
10461 GEN_VXRFORM(vcmpgtsb
, 3, 12)
10462 GEN_VXRFORM(vcmpgtsh
, 3, 13)
10463 GEN_VXRFORM(vcmpgtsw
, 3, 14)
10464 GEN_VXRFORM(vcmpgtub
, 3, 8)
10465 GEN_VXRFORM(vcmpgtuh
, 3, 9)
10466 GEN_VXRFORM(vcmpgtuw
, 3, 10)
10467 GEN_VXRFORM_DUAL(vcmpeqfp
, vcmpequd
, 3, 3, PPC_ALTIVEC
, PPC_NONE
)
10468 GEN_VXRFORM(vcmpgefp
, 3, 7)
10469 GEN_VXRFORM_DUAL(vcmpgtfp
, vcmpgtud
, 3, 11, PPC_ALTIVEC
, PPC_NONE
)
10470 GEN_VXRFORM_DUAL(vcmpbfp
, vcmpgtsd
, 3, 15, PPC_ALTIVEC
, PPC_NONE
)
10472 #undef GEN_VXFORM_SIMM
10473 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
10474 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10475 GEN_VXFORM_SIMM(vspltisb
, 6, 12),
10476 GEN_VXFORM_SIMM(vspltish
, 6, 13),
10477 GEN_VXFORM_SIMM(vspltisw
, 6, 14),
10479 #undef GEN_VXFORM_NOA
10480 #define GEN_VXFORM_NOA(name, opc2, opc3) \
10481 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
10482 GEN_VXFORM_NOA(vupkhsb
, 7, 8),
10483 GEN_VXFORM_NOA(vupkhsh
, 7, 9),
10484 GEN_VXFORM_207(vupkhsw
, 7, 25),
10485 GEN_VXFORM_NOA(vupklsb
, 7, 10),
10486 GEN_VXFORM_NOA(vupklsh
, 7, 11),
10487 GEN_VXFORM_207(vupklsw
, 7, 27),
10488 GEN_VXFORM_NOA(vupkhpx
, 7, 13),
10489 GEN_VXFORM_NOA(vupklpx
, 7, 15),
10490 GEN_VXFORM_NOA(vrefp
, 5, 4),
10491 GEN_VXFORM_NOA(vrsqrtefp
, 5, 5),
10492 GEN_VXFORM_NOA(vexptefp
, 5, 6),
10493 GEN_VXFORM_NOA(vlogefp
, 5, 7),
10494 GEN_VXFORM_NOA(vrfim
, 5, 8),
10495 GEN_VXFORM_NOA(vrfin
, 5, 9),
10496 GEN_VXFORM_NOA(vrfip
, 5, 10),
10497 GEN_VXFORM_NOA(vrfiz
, 5, 11),
10499 #undef GEN_VXFORM_UIMM
10500 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
10501 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10502 GEN_VXFORM_UIMM(vspltb
, 6, 8),
10503 GEN_VXFORM_UIMM(vsplth
, 6, 9),
10504 GEN_VXFORM_UIMM(vspltw
, 6, 10),
10505 GEN_VXFORM_UIMM(vcfux
, 5, 12),
10506 GEN_VXFORM_UIMM(vcfsx
, 5, 13),
10507 GEN_VXFORM_UIMM(vctuxs
, 5, 14),
10508 GEN_VXFORM_UIMM(vctsxs
, 5, 15),
10510 #undef GEN_VAFORM_PAIRED
10511 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
10512 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
10513 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16),
10514 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18),
10515 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19),
10516 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20),
10517 GEN_VAFORM_PAIRED(vsel
, vperm
, 21),
10518 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23),
10520 GEN_VXFORM_DUAL(vclzb
, vpopcntb
, 1, 28, PPC_NONE
, PPC2_ALTIVEC_207
),
10521 GEN_VXFORM_DUAL(vclzh
, vpopcnth
, 1, 29, PPC_NONE
, PPC2_ALTIVEC_207
),
10522 GEN_VXFORM_DUAL(vclzw
, vpopcntw
, 1, 30, PPC_NONE
, PPC2_ALTIVEC_207
),
10523 GEN_VXFORM_DUAL(vclzd
, vpopcntd
, 1, 31, PPC_NONE
, PPC2_ALTIVEC_207
),
10525 GEN_VXFORM_207(vbpermq
, 6, 21),
10526 GEN_VXFORM_207(vgbbd
, 6, 20),
10527 GEN_VXFORM_207(vpmsumb
, 4, 16),
10528 GEN_VXFORM_207(vpmsumh
, 4, 17),
10529 GEN_VXFORM_207(vpmsumw
, 4, 18),
10530 GEN_VXFORM_207(vpmsumd
, 4, 19),
10532 GEN_VXFORM_207(vsbox
, 4, 23),
10534 GEN_VXFORM_DUAL(vcipher
, vcipherlast
, 4, 20, PPC_NONE
, PPC2_ALTIVEC_207
),
10535 GEN_VXFORM_DUAL(vncipher
, vncipherlast
, 4, 21, PPC_NONE
, PPC2_ALTIVEC_207
),
10537 GEN_VXFORM_207(vshasigmaw
, 1, 26),
10538 GEN_VXFORM_207(vshasigmad
, 1, 27),
10540 GEN_VXFORM_DUAL(vsldoi
, vpermxor
, 22, 0xFF, PPC_ALTIVEC
, PPC_NONE
),
10542 GEN_HANDLER_E(lxsdx
, 0x1F, 0x0C, 0x12, 0, PPC_NONE
, PPC2_VSX
),
10543 GEN_HANDLER_E(lxsiwax
, 0x1F, 0x0C, 0x02, 0, PPC_NONE
, PPC2_VSX207
),
10544 GEN_HANDLER_E(lxsiwzx
, 0x1F, 0x0C, 0x00, 0, PPC_NONE
, PPC2_VSX207
),
10545 GEN_HANDLER_E(lxsspx
, 0x1F, 0x0C, 0x10, 0, PPC_NONE
, PPC2_VSX207
),
10546 GEN_HANDLER_E(lxvd2x
, 0x1F, 0x0C, 0x1A, 0, PPC_NONE
, PPC2_VSX
),
10547 GEN_HANDLER_E(lxvdsx
, 0x1F, 0x0C, 0x0A, 0, PPC_NONE
, PPC2_VSX
),
10548 GEN_HANDLER_E(lxvw4x
, 0x1F, 0x0C, 0x18, 0, PPC_NONE
, PPC2_VSX
),
10550 GEN_HANDLER_E(stxsdx
, 0x1F, 0xC, 0x16, 0, PPC_NONE
, PPC2_VSX
),
10551 GEN_HANDLER_E(stxsiwx
, 0x1F, 0xC, 0x04, 0, PPC_NONE
, PPC2_VSX207
),
10552 GEN_HANDLER_E(stxsspx
, 0x1F, 0xC, 0x14, 0, PPC_NONE
, PPC2_VSX207
),
10553 GEN_HANDLER_E(stxvd2x
, 0x1F, 0xC, 0x1E, 0, PPC_NONE
, PPC2_VSX
),
10554 GEN_HANDLER_E(stxvw4x
, 0x1F, 0xC, 0x1C, 0, PPC_NONE
, PPC2_VSX
),
10556 GEN_HANDLER_E(mfvsrwz
, 0x1F, 0x13, 0x03, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
10557 GEN_HANDLER_E(mtvsrwa
, 0x1F, 0x13, 0x06, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
10558 GEN_HANDLER_E(mtvsrwz
, 0x1F, 0x13, 0x07, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
10559 #if defined(TARGET_PPC64)
10560 GEN_HANDLER_E(mfvsrd
, 0x1F, 0x13, 0x01, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
10561 GEN_HANDLER_E(mtvsrd
, 0x1F, 0x13, 0x05, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
10565 #define GEN_XX2FORM(name, opc2, opc3, fl2) \
10566 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10567 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2)
10570 #define GEN_XX3FORM(name, opc2, opc3, fl2) \
10571 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10572 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2), \
10573 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 0, PPC_NONE, fl2), \
10574 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 0, PPC_NONE, fl2)
10576 #undef GEN_XX3_RC_FORM
10577 #define GEN_XX3_RC_FORM(name, opc2, opc3, fl2) \
10578 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x00, 0, PPC_NONE, fl2), \
10579 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x00, 0, PPC_NONE, fl2), \
10580 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x00, 0, PPC_NONE, fl2), \
10581 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x00, 0, PPC_NONE, fl2), \
10582 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x10, 0, PPC_NONE, fl2), \
10583 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x10, 0, PPC_NONE, fl2), \
10584 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x10, 0, PPC_NONE, fl2), \
10585 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x10, 0, PPC_NONE, fl2)
10587 #undef GEN_XX3FORM_DM
10588 #define GEN_XX3FORM_DM(name, opc2, opc3) \
10589 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10590 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10591 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10592 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10593 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10594 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10595 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10596 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10597 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10598 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10599 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10600 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10601 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10602 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10603 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10604 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x0C, 0, PPC_NONE, PPC2_VSX)
10606 GEN_XX2FORM(xsabsdp
, 0x12, 0x15, PPC2_VSX
),
10607 GEN_XX2FORM(xsnabsdp
, 0x12, 0x16, PPC2_VSX
),
10608 GEN_XX2FORM(xsnegdp
, 0x12, 0x17, PPC2_VSX
),
10609 GEN_XX3FORM(xscpsgndp
, 0x00, 0x16, PPC2_VSX
),
10611 GEN_XX2FORM(xvabsdp
, 0x12, 0x1D, PPC2_VSX
),
10612 GEN_XX2FORM(xvnabsdp
, 0x12, 0x1E, PPC2_VSX
),
10613 GEN_XX2FORM(xvnegdp
, 0x12, 0x1F, PPC2_VSX
),
10614 GEN_XX3FORM(xvcpsgndp
, 0x00, 0x1E, PPC2_VSX
),
10615 GEN_XX2FORM(xvabssp
, 0x12, 0x19, PPC2_VSX
),
10616 GEN_XX2FORM(xvnabssp
, 0x12, 0x1A, PPC2_VSX
),
10617 GEN_XX2FORM(xvnegsp
, 0x12, 0x1B, PPC2_VSX
),
10618 GEN_XX3FORM(xvcpsgnsp
, 0x00, 0x1A, PPC2_VSX
),
10620 GEN_XX3FORM(xsadddp
, 0x00, 0x04, PPC2_VSX
),
10621 GEN_XX3FORM(xssubdp
, 0x00, 0x05, PPC2_VSX
),
10622 GEN_XX3FORM(xsmuldp
, 0x00, 0x06, PPC2_VSX
),
10623 GEN_XX3FORM(xsdivdp
, 0x00, 0x07, PPC2_VSX
),
10624 GEN_XX2FORM(xsredp
, 0x14, 0x05, PPC2_VSX
),
10625 GEN_XX2FORM(xssqrtdp
, 0x16, 0x04, PPC2_VSX
),
10626 GEN_XX2FORM(xsrsqrtedp
, 0x14, 0x04, PPC2_VSX
),
10627 GEN_XX3FORM(xstdivdp
, 0x14, 0x07, PPC2_VSX
),
10628 GEN_XX2FORM(xstsqrtdp
, 0x14, 0x06, PPC2_VSX
),
10629 GEN_XX3FORM(xsmaddadp
, 0x04, 0x04, PPC2_VSX
),
10630 GEN_XX3FORM(xsmaddmdp
, 0x04, 0x05, PPC2_VSX
),
10631 GEN_XX3FORM(xsmsubadp
, 0x04, 0x06, PPC2_VSX
),
10632 GEN_XX3FORM(xsmsubmdp
, 0x04, 0x07, PPC2_VSX
),
10633 GEN_XX3FORM(xsnmaddadp
, 0x04, 0x14, PPC2_VSX
),
10634 GEN_XX3FORM(xsnmaddmdp
, 0x04, 0x15, PPC2_VSX
),
10635 GEN_XX3FORM(xsnmsubadp
, 0x04, 0x16, PPC2_VSX
),
10636 GEN_XX3FORM(xsnmsubmdp
, 0x04, 0x17, PPC2_VSX
),
10637 GEN_XX2FORM(xscmpodp
, 0x0C, 0x05, PPC2_VSX
),
10638 GEN_XX2FORM(xscmpudp
, 0x0C, 0x04, PPC2_VSX
),
10639 GEN_XX3FORM(xsmaxdp
, 0x00, 0x14, PPC2_VSX
),
10640 GEN_XX3FORM(xsmindp
, 0x00, 0x15, PPC2_VSX
),
10641 GEN_XX2FORM(xscvdpsp
, 0x12, 0x10, PPC2_VSX
),
10642 GEN_XX2FORM(xscvdpspn
, 0x16, 0x10, PPC2_VSX207
),
10643 GEN_XX2FORM(xscvspdp
, 0x12, 0x14, PPC2_VSX
),
10644 GEN_XX2FORM(xscvspdpn
, 0x16, 0x14, PPC2_VSX207
),
10645 GEN_XX2FORM(xscvdpsxds
, 0x10, 0x15, PPC2_VSX
),
10646 GEN_XX2FORM(xscvdpsxws
, 0x10, 0x05, PPC2_VSX
),
10647 GEN_XX2FORM(xscvdpuxds
, 0x10, 0x14, PPC2_VSX
),
10648 GEN_XX2FORM(xscvdpuxws
, 0x10, 0x04, PPC2_VSX
),
10649 GEN_XX2FORM(xscvsxddp
, 0x10, 0x17, PPC2_VSX
),
10650 GEN_XX2FORM(xscvuxddp
, 0x10, 0x16, PPC2_VSX
),
10651 GEN_XX2FORM(xsrdpi
, 0x12, 0x04, PPC2_VSX
),
10652 GEN_XX2FORM(xsrdpic
, 0x16, 0x06, PPC2_VSX
),
10653 GEN_XX2FORM(xsrdpim
, 0x12, 0x07, PPC2_VSX
),
10654 GEN_XX2FORM(xsrdpip
, 0x12, 0x06, PPC2_VSX
),
10655 GEN_XX2FORM(xsrdpiz
, 0x12, 0x05, PPC2_VSX
),
10657 GEN_XX3FORM(xsaddsp
, 0x00, 0x00, PPC2_VSX207
),
10658 GEN_XX3FORM(xssubsp
, 0x00, 0x01, PPC2_VSX207
),
10659 GEN_XX3FORM(xsmulsp
, 0x00, 0x02, PPC2_VSX207
),
10660 GEN_XX3FORM(xsdivsp
, 0x00, 0x03, PPC2_VSX207
),
10661 GEN_XX2FORM(xsresp
, 0x14, 0x01, PPC2_VSX207
),
10662 GEN_XX2FORM(xsrsp
, 0x12, 0x11, PPC2_VSX207
),
10663 GEN_XX2FORM(xssqrtsp
, 0x16, 0x00, PPC2_VSX207
),
10664 GEN_XX2FORM(xsrsqrtesp
, 0x14, 0x00, PPC2_VSX207
),
10665 GEN_XX3FORM(xsmaddasp
, 0x04, 0x00, PPC2_VSX207
),
10666 GEN_XX3FORM(xsmaddmsp
, 0x04, 0x01, PPC2_VSX207
),
10667 GEN_XX3FORM(xsmsubasp
, 0x04, 0x02, PPC2_VSX207
),
10668 GEN_XX3FORM(xsmsubmsp
, 0x04, 0x03, PPC2_VSX207
),
10669 GEN_XX3FORM(xsnmaddasp
, 0x04, 0x10, PPC2_VSX207
),
10670 GEN_XX3FORM(xsnmaddmsp
, 0x04, 0x11, PPC2_VSX207
),
10671 GEN_XX3FORM(xsnmsubasp
, 0x04, 0x12, PPC2_VSX207
),
10672 GEN_XX3FORM(xsnmsubmsp
, 0x04, 0x13, PPC2_VSX207
),
10673 GEN_XX2FORM(xscvsxdsp
, 0x10, 0x13, PPC2_VSX207
),
10674 GEN_XX2FORM(xscvuxdsp
, 0x10, 0x12, PPC2_VSX207
),
10676 GEN_XX3FORM(xvadddp
, 0x00, 0x0C, PPC2_VSX
),
10677 GEN_XX3FORM(xvsubdp
, 0x00, 0x0D, PPC2_VSX
),
10678 GEN_XX3FORM(xvmuldp
, 0x00, 0x0E, PPC2_VSX
),
10679 GEN_XX3FORM(xvdivdp
, 0x00, 0x0F, PPC2_VSX
),
10680 GEN_XX2FORM(xvredp
, 0x14, 0x0D, PPC2_VSX
),
10681 GEN_XX2FORM(xvsqrtdp
, 0x16, 0x0C, PPC2_VSX
),
10682 GEN_XX2FORM(xvrsqrtedp
, 0x14, 0x0C, PPC2_VSX
),
10683 GEN_XX3FORM(xvtdivdp
, 0x14, 0x0F, PPC2_VSX
),
10684 GEN_XX2FORM(xvtsqrtdp
, 0x14, 0x0E, PPC2_VSX
),
10685 GEN_XX3FORM(xvmaddadp
, 0x04, 0x0C, PPC2_VSX
),
10686 GEN_XX3FORM(xvmaddmdp
, 0x04, 0x0D, PPC2_VSX
),
10687 GEN_XX3FORM(xvmsubadp
, 0x04, 0x0E, PPC2_VSX
),
10688 GEN_XX3FORM(xvmsubmdp
, 0x04, 0x0F, PPC2_VSX
),
10689 GEN_XX3FORM(xvnmaddadp
, 0x04, 0x1C, PPC2_VSX
),
10690 GEN_XX3FORM(xvnmaddmdp
, 0x04, 0x1D, PPC2_VSX
),
10691 GEN_XX3FORM(xvnmsubadp
, 0x04, 0x1E, PPC2_VSX
),
10692 GEN_XX3FORM(xvnmsubmdp
, 0x04, 0x1F, PPC2_VSX
),
10693 GEN_XX3FORM(xvmaxdp
, 0x00, 0x1C, PPC2_VSX
),
10694 GEN_XX3FORM(xvmindp
, 0x00, 0x1D, PPC2_VSX
),
10695 GEN_XX3_RC_FORM(xvcmpeqdp
, 0x0C, 0x0C, PPC2_VSX
),
10696 GEN_XX3_RC_FORM(xvcmpgtdp
, 0x0C, 0x0D, PPC2_VSX
),
10697 GEN_XX3_RC_FORM(xvcmpgedp
, 0x0C, 0x0E, PPC2_VSX
),
10698 GEN_XX2FORM(xvcvdpsp
, 0x12, 0x18, PPC2_VSX
),
10699 GEN_XX2FORM(xvcvdpsxds
, 0x10, 0x1D, PPC2_VSX
),
10700 GEN_XX2FORM(xvcvdpsxws
, 0x10, 0x0D, PPC2_VSX
),
10701 GEN_XX2FORM(xvcvdpuxds
, 0x10, 0x1C, PPC2_VSX
),
10702 GEN_XX2FORM(xvcvdpuxws
, 0x10, 0x0C, PPC2_VSX
),
10703 GEN_XX2FORM(xvcvsxddp
, 0x10, 0x1F, PPC2_VSX
),
10704 GEN_XX2FORM(xvcvuxddp
, 0x10, 0x1E, PPC2_VSX
),
10705 GEN_XX2FORM(xvcvsxwdp
, 0x10, 0x0F, PPC2_VSX
),
10706 GEN_XX2FORM(xvcvuxwdp
, 0x10, 0x0E, PPC2_VSX
),
10707 GEN_XX2FORM(xvrdpi
, 0x12, 0x0C, PPC2_VSX
),
10708 GEN_XX2FORM(xvrdpic
, 0x16, 0x0E, PPC2_VSX
),
10709 GEN_XX2FORM(xvrdpim
, 0x12, 0x0F, PPC2_VSX
),
10710 GEN_XX2FORM(xvrdpip
, 0x12, 0x0E, PPC2_VSX
),
10711 GEN_XX2FORM(xvrdpiz
, 0x12, 0x0D, PPC2_VSX
),
10713 GEN_XX3FORM(xvaddsp
, 0x00, 0x08, PPC2_VSX
),
10714 GEN_XX3FORM(xvsubsp
, 0x00, 0x09, PPC2_VSX
),
10715 GEN_XX3FORM(xvmulsp
, 0x00, 0x0A, PPC2_VSX
),
10716 GEN_XX3FORM(xvdivsp
, 0x00, 0x0B, PPC2_VSX
),
10717 GEN_XX2FORM(xvresp
, 0x14, 0x09, PPC2_VSX
),
10718 GEN_XX2FORM(xvsqrtsp
, 0x16, 0x08, PPC2_VSX
),
10719 GEN_XX2FORM(xvrsqrtesp
, 0x14, 0x08, PPC2_VSX
),
10720 GEN_XX3FORM(xvtdivsp
, 0x14, 0x0B, PPC2_VSX
),
10721 GEN_XX2FORM(xvtsqrtsp
, 0x14, 0x0A, PPC2_VSX
),
10722 GEN_XX3FORM(xvmaddasp
, 0x04, 0x08, PPC2_VSX
),
10723 GEN_XX3FORM(xvmaddmsp
, 0x04, 0x09, PPC2_VSX
),
10724 GEN_XX3FORM(xvmsubasp
, 0x04, 0x0A, PPC2_VSX
),
10725 GEN_XX3FORM(xvmsubmsp
, 0x04, 0x0B, PPC2_VSX
),
10726 GEN_XX3FORM(xvnmaddasp
, 0x04, 0x18, PPC2_VSX
),
10727 GEN_XX3FORM(xvnmaddmsp
, 0x04, 0x19, PPC2_VSX
),
10728 GEN_XX3FORM(xvnmsubasp
, 0x04, 0x1A, PPC2_VSX
),
10729 GEN_XX3FORM(xvnmsubmsp
, 0x04, 0x1B, PPC2_VSX
),
10730 GEN_XX3FORM(xvmaxsp
, 0x00, 0x18, PPC2_VSX
),
10731 GEN_XX3FORM(xvminsp
, 0x00, 0x19, PPC2_VSX
),
10732 GEN_XX3_RC_FORM(xvcmpeqsp
, 0x0C, 0x08, PPC2_VSX
),
10733 GEN_XX3_RC_FORM(xvcmpgtsp
, 0x0C, 0x09, PPC2_VSX
),
10734 GEN_XX3_RC_FORM(xvcmpgesp
, 0x0C, 0x0A, PPC2_VSX
),
10735 GEN_XX2FORM(xvcvspdp
, 0x12, 0x1C, PPC2_VSX
),
10736 GEN_XX2FORM(xvcvspsxds
, 0x10, 0x19, PPC2_VSX
),
10737 GEN_XX2FORM(xvcvspsxws
, 0x10, 0x09, PPC2_VSX
),
10738 GEN_XX2FORM(xvcvspuxds
, 0x10, 0x18, PPC2_VSX
),
10739 GEN_XX2FORM(xvcvspuxws
, 0x10, 0x08, PPC2_VSX
),
10740 GEN_XX2FORM(xvcvsxdsp
, 0x10, 0x1B, PPC2_VSX
),
10741 GEN_XX2FORM(xvcvuxdsp
, 0x10, 0x1A, PPC2_VSX
),
10742 GEN_XX2FORM(xvcvsxwsp
, 0x10, 0x0B, PPC2_VSX
),
10743 GEN_XX2FORM(xvcvuxwsp
, 0x10, 0x0A, PPC2_VSX
),
10744 GEN_XX2FORM(xvrspi
, 0x12, 0x08, PPC2_VSX
),
10745 GEN_XX2FORM(xvrspic
, 0x16, 0x0A, PPC2_VSX
),
10746 GEN_XX2FORM(xvrspim
, 0x12, 0x0B, PPC2_VSX
),
10747 GEN_XX2FORM(xvrspip
, 0x12, 0x0A, PPC2_VSX
),
10748 GEN_XX2FORM(xvrspiz
, 0x12, 0x09, PPC2_VSX
),
10751 #define VSX_LOGICAL(name, opc2, opc3, fl2) \
10752 GEN_XX3FORM(name, opc2, opc3, fl2)
10754 VSX_LOGICAL(xxland
, 0x8, 0x10, PPC2_VSX
),
10755 VSX_LOGICAL(xxlandc
, 0x8, 0x11, PPC2_VSX
),
10756 VSX_LOGICAL(xxlor
, 0x8, 0x12, PPC2_VSX
),
10757 VSX_LOGICAL(xxlxor
, 0x8, 0x13, PPC2_VSX
),
10758 VSX_LOGICAL(xxlnor
, 0x8, 0x14, PPC2_VSX
),
10759 VSX_LOGICAL(xxleqv
, 0x8, 0x17, PPC2_VSX207
),
10760 VSX_LOGICAL(xxlnand
, 0x8, 0x16, PPC2_VSX207
),
10761 VSX_LOGICAL(xxlorc
, 0x8, 0x15, PPC2_VSX207
),
10762 GEN_XX3FORM(xxmrghw
, 0x08, 0x02, PPC2_VSX
),
10763 GEN_XX3FORM(xxmrglw
, 0x08, 0x06, PPC2_VSX
),
10764 GEN_XX2FORM(xxspltw
, 0x08, 0x0A, PPC2_VSX
),
10765 GEN_XX3FORM_DM(xxsldwi
, 0x08, 0x00),
10767 #define GEN_XXSEL_ROW(opc3) \
10768 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x18, opc3, 0, PPC_NONE, PPC2_VSX), \
10769 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x19, opc3, 0, PPC_NONE, PPC2_VSX), \
10770 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1A, opc3, 0, PPC_NONE, PPC2_VSX), \
10771 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1B, opc3, 0, PPC_NONE, PPC2_VSX), \
10772 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1C, opc3, 0, PPC_NONE, PPC2_VSX), \
10773 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1D, opc3, 0, PPC_NONE, PPC2_VSX), \
10774 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1E, opc3, 0, PPC_NONE, PPC2_VSX), \
10775 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1F, opc3, 0, PPC_NONE, PPC2_VSX), \
10777 GEN_XXSEL_ROW(0x00)
10778 GEN_XXSEL_ROW(0x01)
10779 GEN_XXSEL_ROW(0x02)
10780 GEN_XXSEL_ROW(0x03)
10781 GEN_XXSEL_ROW(0x04)
10782 GEN_XXSEL_ROW(0x05)
10783 GEN_XXSEL_ROW(0x06)
10784 GEN_XXSEL_ROW(0x07)
10785 GEN_XXSEL_ROW(0x08)
10786 GEN_XXSEL_ROW(0x09)
10787 GEN_XXSEL_ROW(0x0A)
10788 GEN_XXSEL_ROW(0x0B)
10789 GEN_XXSEL_ROW(0x0C)
10790 GEN_XXSEL_ROW(0x0D)
10791 GEN_XXSEL_ROW(0x0E)
10792 GEN_XXSEL_ROW(0x0F)
10793 GEN_XXSEL_ROW(0x10)
10794 GEN_XXSEL_ROW(0x11)
10795 GEN_XXSEL_ROW(0x12)
10796 GEN_XXSEL_ROW(0x13)
10797 GEN_XXSEL_ROW(0x14)
10798 GEN_XXSEL_ROW(0x15)
10799 GEN_XXSEL_ROW(0x16)
10800 GEN_XXSEL_ROW(0x17)
10801 GEN_XXSEL_ROW(0x18)
10802 GEN_XXSEL_ROW(0x19)
10803 GEN_XXSEL_ROW(0x1A)
10804 GEN_XXSEL_ROW(0x1B)
10805 GEN_XXSEL_ROW(0x1C)
10806 GEN_XXSEL_ROW(0x1D)
10807 GEN_XXSEL_ROW(0x1E)
10808 GEN_XXSEL_ROW(0x1F)
10810 GEN_XX3FORM_DM(xxpermdi
, 0x08, 0x01),
10812 #undef GEN_DFP_T_A_B_Rc
10813 #undef GEN_DFP_BF_A_B
10814 #undef GEN_DFP_BF_A_DCM
10815 #undef GEN_DFP_T_B_U32_U32_Rc
10816 #undef GEN_DFP_T_A_B_I32_Rc
10817 #undef GEN_DFP_T_B_Rc
10818 #undef GEN_DFP_T_FPR_I32_Rc
10820 #define _GEN_DFP_LONG(name, op1, op2, mask) \
10821 GEN_HANDLER_E(name, 0x3B, op1, op2, mask, PPC_NONE, PPC2_DFP)
10823 #define _GEN_DFP_LONGx2(name, op1, op2, mask) \
10824 GEN_HANDLER_E(name, 0x3B, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10825 GEN_HANDLER_E(name, 0x3B, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP)
10827 #define _GEN_DFP_LONGx4(name, op1, op2, mask) \
10828 GEN_HANDLER_E(name, 0x3B, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10829 GEN_HANDLER_E(name, 0x3B, op1, 0x08 | op2, mask, PPC_NONE, PPC2_DFP), \
10830 GEN_HANDLER_E(name, 0x3B, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP), \
10831 GEN_HANDLER_E(name, 0x3B, op1, 0x18 | op2, mask, PPC_NONE, PPC2_DFP)
10833 #define _GEN_DFP_QUAD(name, op1, op2, mask) \
10834 GEN_HANDLER_E(name, 0x3F, op1, op2, mask, PPC_NONE, PPC2_DFP)
10836 #define _GEN_DFP_QUADx2(name, op1, op2, mask) \
10837 GEN_HANDLER_E(name, 0x3F, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10838 GEN_HANDLER_E(name, 0x3F, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP)
10840 #define _GEN_DFP_QUADx4(name, op1, op2, mask) \
10841 GEN_HANDLER_E(name, 0x3F, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
10842 GEN_HANDLER_E(name, 0x3F, op1, 0x08 | op2, mask, PPC_NONE, PPC2_DFP), \
10843 GEN_HANDLER_E(name, 0x3F, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP), \
10844 GEN_HANDLER_E(name, 0x3F, op1, 0x18 | op2, mask, PPC_NONE, PPC2_DFP)
10846 #define GEN_DFP_T_A_B_Rc(name, op1, op2) \
10847 _GEN_DFP_LONG(name, op1, op2, 0x00000000)
10849 #define GEN_DFP_Tp_Ap_Bp_Rc(name, op1, op2) \
10850 _GEN_DFP_QUAD(name, op1, op2, 0x00210800)
10852 #define GEN_DFP_Tp_A_Bp_Rc(name, op1, op2) \
10853 _GEN_DFP_QUAD(name, op1, op2, 0x00200800)
10855 #define GEN_DFP_T_B_Rc(name, op1, op2) \
10856 _GEN_DFP_LONG(name, op1, op2, 0x001F0000)
10858 #define GEN_DFP_Tp_Bp_Rc(name, op1, op2) \
10859 _GEN_DFP_QUAD(name, op1, op2, 0x003F0800)
10861 #define GEN_DFP_Tp_B_Rc(name, op1, op2) \
10862 _GEN_DFP_QUAD(name, op1, op2, 0x003F0000)
10864 #define GEN_DFP_T_Bp_Rc(name, op1, op2) \
10865 _GEN_DFP_QUAD(name, op1, op2, 0x001F0800)
10867 #define GEN_DFP_BF_A_B(name, op1, op2) \
10868 _GEN_DFP_LONG(name, op1, op2, 0x00000001)
10870 #define GEN_DFP_BF_Ap_Bp(name, op1, op2) \
10871 _GEN_DFP_QUAD(name, op1, op2, 0x00610801)
10873 #define GEN_DFP_BF_A_Bp(name, op1, op2) \
10874 _GEN_DFP_QUAD(name, op1, op2, 0x00600801)
10876 #define GEN_DFP_BF_A_DCM(name, op1, op2) \
10877 _GEN_DFP_LONGx2(name, op1, op2, 0x00600001)
10879 #define GEN_DFP_BF_Ap_DCM(name, op1, op2) \
10880 _GEN_DFP_QUADx2(name, op1, op2, 0x00610001)
10882 #define GEN_DFP_T_A_B_RMC_Rc(name, op1, op2) \
10883 _GEN_DFP_LONGx4(name, op1, op2, 0x00000000)
10885 #define GEN_DFP_Tp_Ap_Bp_RMC_Rc(name, op1, op2) \
10886 _GEN_DFP_QUADx4(name, op1, op2, 0x02010800)
10888 #define GEN_DFP_Tp_A_Bp_RMC_Rc(name, op1, op2) \
10889 _GEN_DFP_QUADx4(name, op1, op2, 0x02000800)
10891 #define GEN_DFP_TE_T_B_RMC_Rc(name, op1, op2) \
10892 _GEN_DFP_LONGx4(name, op1, op2, 0x00000000)
10894 #define GEN_DFP_TE_Tp_Bp_RMC_Rc(name, op1, op2) \
10895 _GEN_DFP_QUADx4(name, op1, op2, 0x00200800)
10897 #define GEN_DFP_R_T_B_RMC_Rc(name, op1, op2) \
10898 _GEN_DFP_LONGx4(name, op1, op2, 0x001E0000)
10900 #define GEN_DFP_R_Tp_Bp_RMC_Rc(name, op1, op2) \
10901 _GEN_DFP_QUADx4(name, op1, op2, 0x003E0800)
10903 #define GEN_DFP_SP_T_B_Rc(name, op1, op2) \
10904 _GEN_DFP_LONG(name, op1, op2, 0x00070000)
10906 #define GEN_DFP_SP_Tp_Bp_Rc(name, op1, op2) \
10907 _GEN_DFP_QUAD(name, op1, op2, 0x00270800)
10909 #define GEN_DFP_S_T_B_Rc(name, op1, op2) \
10910 _GEN_DFP_LONG(name, op1, op2, 0x000F0000)
10912 #define GEN_DFP_S_Tp_Bp_Rc(name, op1, op2) \
10913 _GEN_DFP_QUAD(name, op1, op2, 0x002F0800)
10915 #define GEN_DFP_T_A_SH_Rc(name, op1, op2) \
10916 _GEN_DFP_LONGx2(name, op1, op2, 0x00000000)
10918 #define GEN_DFP_Tp_Ap_SH_Rc(name, op1, op2) \
10919 _GEN_DFP_QUADx2(name, op1, op2, 0x00210000)
10921 GEN_DFP_T_A_B_Rc(dadd
, 0x02, 0x00),
10922 GEN_DFP_Tp_Ap_Bp_Rc(daddq
, 0x02, 0x00),
10923 GEN_DFP_T_A_B_Rc(dsub
, 0x02, 0x10),
10924 GEN_DFP_Tp_Ap_Bp_Rc(dsubq
, 0x02, 0x10),
10925 GEN_DFP_T_A_B_Rc(dmul
, 0x02, 0x01),
10926 GEN_DFP_Tp_Ap_Bp_Rc(dmulq
, 0x02, 0x01),
10927 GEN_DFP_T_A_B_Rc(ddiv
, 0x02, 0x11),
10928 GEN_DFP_Tp_Ap_Bp_Rc(ddivq
, 0x02, 0x11),
10929 GEN_DFP_BF_A_B(dcmpu
, 0x02, 0x14),
10930 GEN_DFP_BF_Ap_Bp(dcmpuq
, 0x02, 0x14),
10931 GEN_DFP_BF_A_B(dcmpo
, 0x02, 0x04),
10932 GEN_DFP_BF_Ap_Bp(dcmpoq
, 0x02, 0x04),
10933 GEN_DFP_BF_A_DCM(dtstdc
, 0x02, 0x06),
10934 GEN_DFP_BF_Ap_DCM(dtstdcq
, 0x02, 0x06),
10935 GEN_DFP_BF_A_DCM(dtstdg
, 0x02, 0x07),
10936 GEN_DFP_BF_Ap_DCM(dtstdgq
, 0x02, 0x07),
10937 GEN_DFP_BF_A_B(dtstex
, 0x02, 0x05),
10938 GEN_DFP_BF_Ap_Bp(dtstexq
, 0x02, 0x05),
10939 GEN_DFP_BF_A_B(dtstsf
, 0x02, 0x15),
10940 GEN_DFP_BF_A_Bp(dtstsfq
, 0x02, 0x15),
10941 GEN_DFP_TE_T_B_RMC_Rc(dquai
, 0x03, 0x02),
10942 GEN_DFP_TE_Tp_Bp_RMC_Rc(dquaiq
, 0x03, 0x02),
10943 GEN_DFP_T_A_B_RMC_Rc(dqua
, 0x03, 0x00),
10944 GEN_DFP_Tp_Ap_Bp_RMC_Rc(dquaq
, 0x03, 0x00),
10945 GEN_DFP_T_A_B_RMC_Rc(drrnd
, 0x03, 0x01),
10946 GEN_DFP_Tp_A_Bp_RMC_Rc(drrndq
, 0x03, 0x01),
10947 GEN_DFP_R_T_B_RMC_Rc(drintx
, 0x03, 0x03),
10948 GEN_DFP_R_Tp_Bp_RMC_Rc(drintxq
, 0x03, 0x03),
10949 GEN_DFP_R_T_B_RMC_Rc(drintn
, 0x03, 0x07),
10950 GEN_DFP_R_Tp_Bp_RMC_Rc(drintnq
, 0x03, 0x07),
10951 GEN_DFP_T_B_Rc(dctdp
, 0x02, 0x08),
10952 GEN_DFP_Tp_B_Rc(dctqpq
, 0x02, 0x08),
10953 GEN_DFP_T_B_Rc(drsp
, 0x02, 0x18),
10954 GEN_DFP_Tp_Bp_Rc(drdpq
, 0x02, 0x18),
10955 GEN_DFP_T_B_Rc(dcffix
, 0x02, 0x19),
10956 GEN_DFP_Tp_B_Rc(dcffixq
, 0x02, 0x19),
10957 GEN_DFP_T_B_Rc(dctfix
, 0x02, 0x09),
10958 GEN_DFP_T_Bp_Rc(dctfixq
, 0x02, 0x09),
10959 GEN_DFP_SP_T_B_Rc(ddedpd
, 0x02, 0x0a),
10960 GEN_DFP_SP_Tp_Bp_Rc(ddedpdq
, 0x02, 0x0a),
10961 GEN_DFP_S_T_B_Rc(denbcd
, 0x02, 0x1a),
10962 GEN_DFP_S_Tp_Bp_Rc(denbcdq
, 0x02, 0x1a),
10963 GEN_DFP_T_B_Rc(dxex
, 0x02, 0x0b),
10964 GEN_DFP_T_Bp_Rc(dxexq
, 0x02, 0x0b),
10965 GEN_DFP_T_A_B_Rc(diex
, 0x02, 0x1b),
10966 GEN_DFP_Tp_A_Bp_Rc(diexq
, 0x02, 0x1b),
10967 GEN_DFP_T_A_SH_Rc(dscli
, 0x02, 0x02),
10968 GEN_DFP_Tp_Ap_SH_Rc(dscliq
, 0x02, 0x02),
10969 GEN_DFP_T_A_SH_Rc(dscri
, 0x02, 0x03),
10970 GEN_DFP_Tp_Ap_SH_Rc(dscriq
, 0x02, 0x03),
10973 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
10974 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
10975 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10976 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10977 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10978 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10979 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
10980 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
10981 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
10982 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE
),
10983 GEN_SPE(evmra
, speundef
, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE
),
10984 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
),
10985 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10986 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
10987 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
10988 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE
),
10989 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE
),
10990 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE
),
10991 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
),
10992 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10993 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
10994 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
10995 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10996 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10997 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE
),
10998 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE
),
10999 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
11000 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
11001 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE
),
11002 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE
),
11003 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE
),
11005 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
11006 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
),
11007 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11008 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
11009 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
11010 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11011 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11012 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11013 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11014 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11015 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11016 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11017 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
11018 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11020 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
11021 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
),
11022 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11023 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
11024 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
11025 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE
),
11026 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11027 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11028 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11029 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11030 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11031 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11032 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
11033 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11035 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
),
11036 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
11037 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE
),
11038 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
11039 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
),
11040 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
11041 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
),
11042 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE
),
11043 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
11044 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
11045 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
11046 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
11047 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
11048 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
11049 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
),
11050 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
11052 #undef GEN_SPEOP_LDST
11053 #define GEN_SPEOP_LDST(name, opc2, sh) \
11054 GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
11055 GEN_SPEOP_LDST(evldd
, 0x00, 3),
11056 GEN_SPEOP_LDST(evldw
, 0x01, 3),
11057 GEN_SPEOP_LDST(evldh
, 0x02, 3),
11058 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1),
11059 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1),
11060 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1),
11061 GEN_SPEOP_LDST(evlwhe
, 0x08, 2),
11062 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2),
11063 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2),
11064 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2),
11065 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2),
11067 GEN_SPEOP_LDST(evstdd
, 0x10, 3),
11068 GEN_SPEOP_LDST(evstdw
, 0x11, 3),
11069 GEN_SPEOP_LDST(evstdh
, 0x12, 3),
11070 GEN_SPEOP_LDST(evstwhe
, 0x18, 2),
11071 GEN_SPEOP_LDST(evstwho
, 0x1A, 2),
11072 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2),
11073 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2),
11076 #include "helper_regs.h"
11077 #include "translate_init.c"
11079 /*****************************************************************************/
11080 /* Misc PowerPC helpers */
11081 void ppc_cpu_dump_state(CPUState
*cs
, FILE *f
, fprintf_function cpu_fprintf
,
11087 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
11088 CPUPPCState
*env
= &cpu
->env
;
11091 cpu_fprintf(f
, "NIP " TARGET_FMT_lx
" LR " TARGET_FMT_lx
" CTR "
11092 TARGET_FMT_lx
" XER " TARGET_FMT_lx
"\n",
11093 env
->nip
, env
->lr
, env
->ctr
, cpu_read_xer(env
));
11094 cpu_fprintf(f
, "MSR " TARGET_FMT_lx
" HID0 " TARGET_FMT_lx
" HF "
11095 TARGET_FMT_lx
" idx %d\n", env
->msr
, env
->spr
[SPR_HID0
],
11096 env
->hflags
, env
->mmu_idx
);
11097 #if !defined(NO_TIMER_DUMP)
11098 cpu_fprintf(f
, "TB %08" PRIu32
" %08" PRIu64
11099 #if !defined(CONFIG_USER_ONLY)
11103 cpu_ppc_load_tbu(env
), cpu_ppc_load_tbl(env
)
11104 #if !defined(CONFIG_USER_ONLY)
11105 , cpu_ppc_load_decr(env
)
11109 for (i
= 0; i
< 32; i
++) {
11110 if ((i
& (RGPL
- 1)) == 0)
11111 cpu_fprintf(f
, "GPR%02d", i
);
11112 cpu_fprintf(f
, " %016" PRIx64
, ppc_dump_gpr(env
, i
));
11113 if ((i
& (RGPL
- 1)) == (RGPL
- 1))
11114 cpu_fprintf(f
, "\n");
11116 cpu_fprintf(f
, "CR ");
11117 for (i
= 0; i
< 8; i
++)
11118 cpu_fprintf(f
, "%01x", env
->crf
[i
]);
11119 cpu_fprintf(f
, " [");
11120 for (i
= 0; i
< 8; i
++) {
11122 if (env
->crf
[i
] & 0x08)
11124 else if (env
->crf
[i
] & 0x04)
11126 else if (env
->crf
[i
] & 0x02)
11128 cpu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
11130 cpu_fprintf(f
, " ] RES " TARGET_FMT_lx
"\n",
11131 env
->reserve_addr
);
11132 for (i
= 0; i
< 32; i
++) {
11133 if ((i
& (RFPL
- 1)) == 0)
11134 cpu_fprintf(f
, "FPR%02d", i
);
11135 cpu_fprintf(f
, " %016" PRIx64
, *((uint64_t *)&env
->fpr
[i
]));
11136 if ((i
& (RFPL
- 1)) == (RFPL
- 1))
11137 cpu_fprintf(f
, "\n");
11139 cpu_fprintf(f
, "FPSCR " TARGET_FMT_lx
"\n", env
->fpscr
);
11140 #if !defined(CONFIG_USER_ONLY)
11141 cpu_fprintf(f
, " SRR0 " TARGET_FMT_lx
" SRR1 " TARGET_FMT_lx
11142 " PVR " TARGET_FMT_lx
" VRSAVE " TARGET_FMT_lx
"\n",
11143 env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
11144 env
->spr
[SPR_PVR
], env
->spr
[SPR_VRSAVE
]);
11146 cpu_fprintf(f
, "SPRG0 " TARGET_FMT_lx
" SPRG1 " TARGET_FMT_lx
11147 " SPRG2 " TARGET_FMT_lx
" SPRG3 " TARGET_FMT_lx
"\n",
11148 env
->spr
[SPR_SPRG0
], env
->spr
[SPR_SPRG1
],
11149 env
->spr
[SPR_SPRG2
], env
->spr
[SPR_SPRG3
]);
11151 cpu_fprintf(f
, "SPRG4 " TARGET_FMT_lx
" SPRG5 " TARGET_FMT_lx
11152 " SPRG6 " TARGET_FMT_lx
" SPRG7 " TARGET_FMT_lx
"\n",
11153 env
->spr
[SPR_SPRG4
], env
->spr
[SPR_SPRG5
],
11154 env
->spr
[SPR_SPRG6
], env
->spr
[SPR_SPRG7
]);
11156 if (env
->excp_model
== POWERPC_EXCP_BOOKE
) {
11157 cpu_fprintf(f
, "CSRR0 " TARGET_FMT_lx
" CSRR1 " TARGET_FMT_lx
11158 " MCSRR0 " TARGET_FMT_lx
" MCSRR1 " TARGET_FMT_lx
"\n",
11159 env
->spr
[SPR_BOOKE_CSRR0
], env
->spr
[SPR_BOOKE_CSRR1
],
11160 env
->spr
[SPR_BOOKE_MCSRR0
], env
->spr
[SPR_BOOKE_MCSRR1
]);
11162 cpu_fprintf(f
, " TCR " TARGET_FMT_lx
" TSR " TARGET_FMT_lx
11163 " ESR " TARGET_FMT_lx
" DEAR " TARGET_FMT_lx
"\n",
11164 env
->spr
[SPR_BOOKE_TCR
], env
->spr
[SPR_BOOKE_TSR
],
11165 env
->spr
[SPR_BOOKE_ESR
], env
->spr
[SPR_BOOKE_DEAR
]);
11167 cpu_fprintf(f
, " PIR " TARGET_FMT_lx
" DECAR " TARGET_FMT_lx
11168 " IVPR " TARGET_FMT_lx
" EPCR " TARGET_FMT_lx
"\n",
11169 env
->spr
[SPR_BOOKE_PIR
], env
->spr
[SPR_BOOKE_DECAR
],
11170 env
->spr
[SPR_BOOKE_IVPR
], env
->spr
[SPR_BOOKE_EPCR
]);
11172 cpu_fprintf(f
, " MCSR " TARGET_FMT_lx
" SPRG8 " TARGET_FMT_lx
11173 " EPR " TARGET_FMT_lx
"\n",
11174 env
->spr
[SPR_BOOKE_MCSR
], env
->spr
[SPR_BOOKE_SPRG8
],
11175 env
->spr
[SPR_BOOKE_EPR
]);
11178 cpu_fprintf(f
, " MCAR " TARGET_FMT_lx
" PID1 " TARGET_FMT_lx
11179 " PID2 " TARGET_FMT_lx
" SVR " TARGET_FMT_lx
"\n",
11180 env
->spr
[SPR_Exxx_MCAR
], env
->spr
[SPR_BOOKE_PID1
],
11181 env
->spr
[SPR_BOOKE_PID2
], env
->spr
[SPR_E500_SVR
]);
11184 * IVORs are left out as they are large and do not change often --
11185 * they can be read with "p $ivor0", "p $ivor1", etc.
11189 #if defined(TARGET_PPC64)
11190 if (env
->flags
& POWERPC_FLAG_CFAR
) {
11191 cpu_fprintf(f
, " CFAR " TARGET_FMT_lx
"\n", env
->cfar
);
11195 switch (env
->mmu_model
) {
11196 case POWERPC_MMU_32B
:
11197 case POWERPC_MMU_601
:
11198 case POWERPC_MMU_SOFT_6xx
:
11199 case POWERPC_MMU_SOFT_74xx
:
11200 #if defined(TARGET_PPC64)
11201 case POWERPC_MMU_64B
:
11202 case POWERPC_MMU_2_06
:
11203 case POWERPC_MMU_2_06a
:
11204 case POWERPC_MMU_2_06d
:
11206 cpu_fprintf(f
, " SDR1 " TARGET_FMT_lx
" DAR " TARGET_FMT_lx
11207 " DSISR " TARGET_FMT_lx
"\n", env
->spr
[SPR_SDR1
],
11208 env
->spr
[SPR_DAR
], env
->spr
[SPR_DSISR
]);
11210 case POWERPC_MMU_BOOKE206
:
11211 cpu_fprintf(f
, " MAS0 " TARGET_FMT_lx
" MAS1 " TARGET_FMT_lx
11212 " MAS2 " TARGET_FMT_lx
" MAS3 " TARGET_FMT_lx
"\n",
11213 env
->spr
[SPR_BOOKE_MAS0
], env
->spr
[SPR_BOOKE_MAS1
],
11214 env
->spr
[SPR_BOOKE_MAS2
], env
->spr
[SPR_BOOKE_MAS3
]);
11216 cpu_fprintf(f
, " MAS4 " TARGET_FMT_lx
" MAS6 " TARGET_FMT_lx
11217 " MAS7 " TARGET_FMT_lx
" PID " TARGET_FMT_lx
"\n",
11218 env
->spr
[SPR_BOOKE_MAS4
], env
->spr
[SPR_BOOKE_MAS6
],
11219 env
->spr
[SPR_BOOKE_MAS7
], env
->spr
[SPR_BOOKE_PID
]);
11221 cpu_fprintf(f
, "MMUCFG " TARGET_FMT_lx
" TLB0CFG " TARGET_FMT_lx
11222 " TLB1CFG " TARGET_FMT_lx
"\n",
11223 env
->spr
[SPR_MMUCFG
], env
->spr
[SPR_BOOKE_TLB0CFG
],
11224 env
->spr
[SPR_BOOKE_TLB1CFG
]);
11235 void ppc_cpu_dump_statistics(CPUState
*cs
, FILE*f
,
11236 fprintf_function cpu_fprintf
, int flags
)
11238 #if defined(DO_PPC_STATISTICS)
11239 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
11240 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
11243 t1
= cpu
->env
.opcodes
;
11244 for (op1
= 0; op1
< 64; op1
++) {
11246 if (is_indirect_opcode(handler
)) {
11247 t2
= ind_table(handler
);
11248 for (op2
= 0; op2
< 32; op2
++) {
11250 if (is_indirect_opcode(handler
)) {
11251 t3
= ind_table(handler
);
11252 for (op3
= 0; op3
< 32; op3
++) {
11254 if (handler
->count
== 0)
11256 cpu_fprintf(f
, "%02x %02x %02x (%02x %04d) %16s: "
11257 "%016" PRIx64
" %" PRId64
"\n",
11258 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
11260 handler
->count
, handler
->count
);
11263 if (handler
->count
== 0)
11265 cpu_fprintf(f
, "%02x %02x (%02x %04d) %16s: "
11266 "%016" PRIx64
" %" PRId64
"\n",
11267 op1
, op2
, op1
, op2
, handler
->oname
,
11268 handler
->count
, handler
->count
);
11272 if (handler
->count
== 0)
11274 cpu_fprintf(f
, "%02x (%02x ) %16s: %016" PRIx64
11276 op1
, op1
, handler
->oname
,
11277 handler
->count
, handler
->count
);
11283 /*****************************************************************************/
11284 static inline void gen_intermediate_code_internal(PowerPCCPU
*cpu
,
11285 TranslationBlock
*tb
,
11288 CPUState
*cs
= CPU(cpu
);
11289 CPUPPCState
*env
= &cpu
->env
;
11290 DisasContext ctx
, *ctxp
= &ctx
;
11291 opc_handler_t
**table
, *handler
;
11292 target_ulong pc_start
;
11293 uint16_t *gen_opc_end
;
11300 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
11301 ctx
.nip
= pc_start
;
11303 ctx
.exception
= POWERPC_EXCP_NONE
;
11304 ctx
.spr_cb
= env
->spr_cb
;
11305 ctx
.mem_idx
= env
->mmu_idx
;
11306 ctx
.insns_flags
= env
->insns_flags
;
11307 ctx
.insns_flags2
= env
->insns_flags2
;
11308 ctx
.access_type
= -1;
11309 ctx
.le_mode
= env
->hflags
& (1 << MSR_LE
) ? 1 : 0;
11310 ctx
.default_tcg_memop_mask
= ctx
.le_mode
? MO_LE
: MO_BE
;
11311 #if defined(TARGET_PPC64)
11312 ctx
.sf_mode
= msr_is_64bit(env
, env
->msr
);
11313 ctx
.has_cfar
= !!(env
->flags
& POWERPC_FLAG_CFAR
);
11315 ctx
.fpu_enabled
= msr_fp
;
11316 if ((env
->flags
& POWERPC_FLAG_SPE
) && msr_spe
)
11317 ctx
.spe_enabled
= msr_spe
;
11319 ctx
.spe_enabled
= 0;
11320 if ((env
->flags
& POWERPC_FLAG_VRE
) && msr_vr
)
11321 ctx
.altivec_enabled
= msr_vr
;
11323 ctx
.altivec_enabled
= 0;
11324 if ((env
->flags
& POWERPC_FLAG_VSX
) && msr_vsx
) {
11325 ctx
.vsx_enabled
= msr_vsx
;
11327 ctx
.vsx_enabled
= 0;
11329 if ((env
->flags
& POWERPC_FLAG_SE
) && msr_se
)
11330 ctx
.singlestep_enabled
= CPU_SINGLE_STEP
;
11332 ctx
.singlestep_enabled
= 0;
11333 if ((env
->flags
& POWERPC_FLAG_BE
) && msr_be
)
11334 ctx
.singlestep_enabled
|= CPU_BRANCH_STEP
;
11335 if (unlikely(cs
->singlestep_enabled
)) {
11336 ctx
.singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
11338 #if defined (DO_SINGLE_STEP) && 0
11339 /* Single step trace mode */
11343 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
11344 if (max_insns
== 0)
11345 max_insns
= CF_COUNT_MASK
;
11348 tcg_clear_temp_count();
11349 /* Set env in case of segfault during code fetch */
11350 while (ctx
.exception
== POWERPC_EXCP_NONE
11351 && tcg_ctx
.gen_opc_ptr
< gen_opc_end
) {
11352 if (unlikely(!QTAILQ_EMPTY(&cs
->breakpoints
))) {
11353 QTAILQ_FOREACH(bp
, &cs
->breakpoints
, entry
) {
11354 if (bp
->pc
== ctx
.nip
) {
11355 gen_debug_exception(ctxp
);
11360 if (unlikely(search_pc
)) {
11361 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
11365 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
11367 tcg_ctx
.gen_opc_pc
[lj
] = ctx
.nip
;
11368 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
11369 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
11371 LOG_DISAS("----------------\n");
11372 LOG_DISAS("nip=" TARGET_FMT_lx
" super=%d ir=%d\n",
11373 ctx
.nip
, ctx
.mem_idx
, (int)msr_ir
);
11374 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
11376 if (unlikely(need_byteswap(&ctx
))) {
11377 ctx
.opcode
= bswap32(cpu_ldl_code(env
, ctx
.nip
));
11379 ctx
.opcode
= cpu_ldl_code(env
, ctx
.nip
);
11381 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
11382 ctx
.opcode
, opc1(ctx
.opcode
), opc2(ctx
.opcode
),
11383 opc3(ctx
.opcode
), ctx
.le_mode
? "little" : "big");
11384 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
11385 tcg_gen_debug_insn_start(ctx
.nip
);
11388 table
= env
->opcodes
;
11390 handler
= table
[opc1(ctx
.opcode
)];
11391 if (is_indirect_opcode(handler
)) {
11392 table
= ind_table(handler
);
11393 handler
= table
[opc2(ctx
.opcode
)];
11394 if (is_indirect_opcode(handler
)) {
11395 table
= ind_table(handler
);
11396 handler
= table
[opc3(ctx
.opcode
)];
11399 /* Is opcode *REALLY* valid ? */
11400 if (unlikely(handler
->handler
== &gen_invalid
)) {
11401 if (qemu_log_enabled()) {
11402 qemu_log("invalid/unsupported opcode: "
11403 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx
" %d\n",
11404 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
11405 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
11410 if (unlikely(handler
->type
& (PPC_SPE
| PPC_SPE_SINGLE
| PPC_SPE_DOUBLE
) && Rc(ctx
.opcode
))) {
11411 inval
= handler
->inval2
;
11413 inval
= handler
->inval1
;
11416 if (unlikely((ctx
.opcode
& inval
) != 0)) {
11417 if (qemu_log_enabled()) {
11418 qemu_log("invalid bits: %08x for opcode: "
11419 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx
"\n",
11420 ctx
.opcode
& inval
, opc1(ctx
.opcode
),
11421 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
11422 ctx
.opcode
, ctx
.nip
- 4);
11424 gen_inval_exception(ctxp
, POWERPC_EXCP_INVAL_INVAL
);
11428 (*(handler
->handler
))(&ctx
);
11429 #if defined(DO_PPC_STATISTICS)
11432 /* Check trace mode exceptions */
11433 if (unlikely(ctx
.singlestep_enabled
& CPU_SINGLE_STEP
&&
11434 (ctx
.nip
<= 0x100 || ctx
.nip
> 0xF00) &&
11435 ctx
.exception
!= POWERPC_SYSCALL
&&
11436 ctx
.exception
!= POWERPC_EXCP_TRAP
&&
11437 ctx
.exception
!= POWERPC_EXCP_BRANCH
)) {
11438 gen_exception(ctxp
, POWERPC_EXCP_TRACE
);
11439 } else if (unlikely(((ctx
.nip
& (TARGET_PAGE_SIZE
- 1)) == 0) ||
11440 (cs
->singlestep_enabled
) ||
11442 num_insns
>= max_insns
)) {
11443 /* if we reach a page boundary or are single stepping, stop
11448 if (tcg_check_temp_count()) {
11449 fprintf(stderr
, "Opcode %02x %02x %02x (%08x) leaked temporaries\n",
11450 opc1(ctx
.opcode
), opc2(ctx
.opcode
), opc3(ctx
.opcode
),
11455 if (tb
->cflags
& CF_LAST_IO
)
11457 if (ctx
.exception
== POWERPC_EXCP_NONE
) {
11458 gen_goto_tb(&ctx
, 0, ctx
.nip
);
11459 } else if (ctx
.exception
!= POWERPC_EXCP_BRANCH
) {
11460 if (unlikely(cs
->singlestep_enabled
)) {
11461 gen_debug_exception(ctxp
);
11463 /* Generate the return instruction */
11464 tcg_gen_exit_tb(0);
11466 gen_tb_end(tb
, num_insns
);
11467 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
11468 if (unlikely(search_pc
)) {
11469 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
11472 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
11474 tb
->size
= ctx
.nip
- pc_start
;
11475 tb
->icount
= num_insns
;
11477 #if defined(DEBUG_DISAS)
11478 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
11480 flags
= env
->bfd_mach
;
11481 flags
|= ctx
.le_mode
<< 16;
11482 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
11483 log_target_disas(env
, pc_start
, ctx
.nip
- pc_start
, flags
);
11489 void gen_intermediate_code (CPUPPCState
*env
, struct TranslationBlock
*tb
)
11491 gen_intermediate_code_internal(ppc_env_get_cpu(env
), tb
, false);
11494 void gen_intermediate_code_pc (CPUPPCState
*env
, struct TranslationBlock
*tb
)
11496 gen_intermediate_code_internal(ppc_env_get_cpu(env
), tb
, true);
11499 void restore_state_to_opc(CPUPPCState
*env
, TranslationBlock
*tb
, int pc_pos
)
11501 env
->nip
= tcg_ctx
.gen_opc_pc
[pc_pos
];