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"
30 #define CPU_SINGLE_STEP 0x1
31 #define CPU_BRANCH_STEP 0x2
32 #define GDBSTUB_SINGLE_STEP 0x4
34 /* Include definitions for instructions classes and implementations flags */
35 //#define PPC_DEBUG_DISAS
36 //#define DO_PPC_STATISTICS
38 #ifdef PPC_DEBUG_DISAS
39 # define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
41 # define LOG_DISAS(...) do { } while (0)
43 /*****************************************************************************/
44 /* Code translation helpers */
46 /* global register indexes */
47 static TCGv_ptr cpu_env
;
48 static char cpu_reg_names
[10*3 + 22*4 /* GPR */
49 #if !defined(TARGET_PPC64)
50 + 10*4 + 22*5 /* SPE GPRh */
52 + 10*4 + 22*5 /* FPR */
53 + 2*(10*6 + 22*7) /* AVRh, AVRl */
54 + 10*5 + 22*6 /* VSR */
56 static TCGv cpu_gpr
[32];
57 #if !defined(TARGET_PPC64)
58 static TCGv cpu_gprh
[32];
60 static TCGv_i64 cpu_fpr
[32];
61 static TCGv_i64 cpu_avrh
[32], cpu_avrl
[32];
62 static TCGv_i64 cpu_vsr
[32];
63 static TCGv_i32 cpu_crf
[8];
68 #if defined(TARGET_PPC64)
71 static TCGv cpu_xer
, cpu_so
, cpu_ov
, cpu_ca
;
72 static TCGv cpu_reserve
;
73 static TCGv cpu_fpscr
;
74 static TCGv_i32 cpu_access_type
;
76 #include "exec/gen-icount.h"
78 void ppc_translate_init(void)
82 size_t cpu_reg_names_size
;
83 static int done_init
= 0;
88 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
91 cpu_reg_names_size
= sizeof(cpu_reg_names
);
93 for (i
= 0; i
< 8; i
++) {
94 snprintf(p
, cpu_reg_names_size
, "crf%d", i
);
95 cpu_crf
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
96 offsetof(CPUPPCState
, crf
[i
]), p
);
98 cpu_reg_names_size
-= 5;
101 for (i
= 0; i
< 32; i
++) {
102 snprintf(p
, cpu_reg_names_size
, "r%d", i
);
103 cpu_gpr
[i
] = tcg_global_mem_new(TCG_AREG0
,
104 offsetof(CPUPPCState
, gpr
[i
]), p
);
105 p
+= (i
< 10) ? 3 : 4;
106 cpu_reg_names_size
-= (i
< 10) ? 3 : 4;
107 #if !defined(TARGET_PPC64)
108 snprintf(p
, cpu_reg_names_size
, "r%dH", i
);
109 cpu_gprh
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
110 offsetof(CPUPPCState
, gprh
[i
]), p
);
111 p
+= (i
< 10) ? 4 : 5;
112 cpu_reg_names_size
-= (i
< 10) ? 4 : 5;
115 snprintf(p
, cpu_reg_names_size
, "fp%d", i
);
116 cpu_fpr
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
117 offsetof(CPUPPCState
, fpr
[i
]), p
);
118 p
+= (i
< 10) ? 4 : 5;
119 cpu_reg_names_size
-= (i
< 10) ? 4 : 5;
121 snprintf(p
, cpu_reg_names_size
, "avr%dH", i
);
122 #ifdef HOST_WORDS_BIGENDIAN
123 cpu_avrh
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
124 offsetof(CPUPPCState
, avr
[i
].u64
[0]), p
);
126 cpu_avrh
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
127 offsetof(CPUPPCState
, avr
[i
].u64
[1]), p
);
129 p
+= (i
< 10) ? 6 : 7;
130 cpu_reg_names_size
-= (i
< 10) ? 6 : 7;
132 snprintf(p
, cpu_reg_names_size
, "avr%dL", i
);
133 #ifdef HOST_WORDS_BIGENDIAN
134 cpu_avrl
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
135 offsetof(CPUPPCState
, avr
[i
].u64
[1]), p
);
137 cpu_avrl
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
138 offsetof(CPUPPCState
, avr
[i
].u64
[0]), p
);
140 p
+= (i
< 10) ? 6 : 7;
141 cpu_reg_names_size
-= (i
< 10) ? 6 : 7;
142 snprintf(p
, cpu_reg_names_size
, "vsr%d", i
);
143 cpu_vsr
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
144 offsetof(CPUPPCState
, vsr
[i
]), p
);
145 p
+= (i
< 10) ? 5 : 6;
146 cpu_reg_names_size
-= (i
< 10) ? 5 : 6;
149 cpu_nip
= tcg_global_mem_new(TCG_AREG0
,
150 offsetof(CPUPPCState
, nip
), "nip");
152 cpu_msr
= tcg_global_mem_new(TCG_AREG0
,
153 offsetof(CPUPPCState
, msr
), "msr");
155 cpu_ctr
= tcg_global_mem_new(TCG_AREG0
,
156 offsetof(CPUPPCState
, ctr
), "ctr");
158 cpu_lr
= tcg_global_mem_new(TCG_AREG0
,
159 offsetof(CPUPPCState
, lr
), "lr");
161 #if defined(TARGET_PPC64)
162 cpu_cfar
= tcg_global_mem_new(TCG_AREG0
,
163 offsetof(CPUPPCState
, cfar
), "cfar");
166 cpu_xer
= tcg_global_mem_new(TCG_AREG0
,
167 offsetof(CPUPPCState
, xer
), "xer");
168 cpu_so
= tcg_global_mem_new(TCG_AREG0
,
169 offsetof(CPUPPCState
, so
), "SO");
170 cpu_ov
= tcg_global_mem_new(TCG_AREG0
,
171 offsetof(CPUPPCState
, ov
), "OV");
172 cpu_ca
= tcg_global_mem_new(TCG_AREG0
,
173 offsetof(CPUPPCState
, ca
), "CA");
175 cpu_reserve
= tcg_global_mem_new(TCG_AREG0
,
176 offsetof(CPUPPCState
, reserve_addr
),
179 cpu_fpscr
= tcg_global_mem_new(TCG_AREG0
,
180 offsetof(CPUPPCState
, fpscr
), "fpscr");
182 cpu_access_type
= tcg_global_mem_new_i32(TCG_AREG0
,
183 offsetof(CPUPPCState
, access_type
), "access_type");
188 /* internal defines */
189 typedef struct DisasContext
{
190 struct TranslationBlock
*tb
;
194 /* Routine used to access memory */
197 /* Translation flags */
199 #if defined(TARGET_PPC64)
207 ppc_spr_t
*spr_cb
; /* Needed to check rights for mfspr/mtspr */
208 int singlestep_enabled
;
209 uint64_t insns_flags
;
210 uint64_t insns_flags2
;
213 /* True when active word size < size of target_long. */
215 # define NARROW_MODE(C) (!(C)->sf_mode)
217 # define NARROW_MODE(C) 0
220 struct opc_handler_t
{
221 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
223 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
225 /* instruction type */
227 /* extended instruction type */
230 void (*handler
)(DisasContext
*ctx
);
231 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
234 #if defined(DO_PPC_STATISTICS)
239 static inline void gen_reset_fpstatus(void)
241 gen_helper_reset_fpstatus(cpu_env
);
244 static inline void gen_compute_fprf(TCGv_i64 arg
, int set_fprf
, int set_rc
)
246 TCGv_i32 t0
= tcg_temp_new_i32();
249 /* This case might be optimized later */
250 tcg_gen_movi_i32(t0
, 1);
251 gen_helper_compute_fprf(t0
, cpu_env
, arg
, t0
);
252 if (unlikely(set_rc
)) {
253 tcg_gen_mov_i32(cpu_crf
[1], t0
);
255 gen_helper_float_check_status(cpu_env
);
256 } else if (unlikely(set_rc
)) {
257 /* We always need to compute fpcc */
258 tcg_gen_movi_i32(t0
, 0);
259 gen_helper_compute_fprf(t0
, cpu_env
, arg
, t0
);
260 tcg_gen_mov_i32(cpu_crf
[1], t0
);
263 tcg_temp_free_i32(t0
);
266 static inline void gen_set_access_type(DisasContext
*ctx
, int access_type
)
268 if (ctx
->access_type
!= access_type
) {
269 tcg_gen_movi_i32(cpu_access_type
, access_type
);
270 ctx
->access_type
= access_type
;
274 static inline void gen_update_nip(DisasContext
*ctx
, target_ulong nip
)
276 if (NARROW_MODE(ctx
)) {
279 tcg_gen_movi_tl(cpu_nip
, nip
);
282 static inline void gen_exception_err(DisasContext
*ctx
, uint32_t excp
, uint32_t error
)
285 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
286 gen_update_nip(ctx
, ctx
->nip
);
288 t0
= tcg_const_i32(excp
);
289 t1
= tcg_const_i32(error
);
290 gen_helper_raise_exception_err(cpu_env
, t0
, t1
);
291 tcg_temp_free_i32(t0
);
292 tcg_temp_free_i32(t1
);
293 ctx
->exception
= (excp
);
296 static inline void gen_exception(DisasContext
*ctx
, uint32_t excp
)
299 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
300 gen_update_nip(ctx
, ctx
->nip
);
302 t0
= tcg_const_i32(excp
);
303 gen_helper_raise_exception(cpu_env
, t0
);
304 tcg_temp_free_i32(t0
);
305 ctx
->exception
= (excp
);
308 static inline void gen_debug_exception(DisasContext
*ctx
)
312 if ((ctx
->exception
!= POWERPC_EXCP_BRANCH
) &&
313 (ctx
->exception
!= POWERPC_EXCP_SYNC
)) {
314 gen_update_nip(ctx
, ctx
->nip
);
316 t0
= tcg_const_i32(EXCP_DEBUG
);
317 gen_helper_raise_exception(cpu_env
, t0
);
318 tcg_temp_free_i32(t0
);
321 static inline void gen_inval_exception(DisasContext
*ctx
, uint32_t error
)
323 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_INVAL
| error
);
326 /* Stop translation */
327 static inline void gen_stop_exception(DisasContext
*ctx
)
329 gen_update_nip(ctx
, ctx
->nip
);
330 ctx
->exception
= POWERPC_EXCP_STOP
;
333 /* No need to update nip here, as execution flow will change */
334 static inline void gen_sync_exception(DisasContext
*ctx
)
336 ctx
->exception
= POWERPC_EXCP_SYNC
;
339 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
340 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
342 #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
343 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
345 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
346 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
348 #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
349 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
351 typedef struct opcode_t
{
352 unsigned char opc1
, opc2
, opc3
;
353 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
354 unsigned char pad
[5];
356 unsigned char pad
[1];
358 opc_handler_t handler
;
362 /*****************************************************************************/
363 /*** Instruction decoding ***/
364 #define EXTRACT_HELPER(name, shift, nb) \
365 static inline uint32_t name(uint32_t opcode) \
367 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
370 #define EXTRACT_SHELPER(name, shift, nb) \
371 static inline int32_t name(uint32_t opcode) \
373 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
376 #define EXTRACT_HELPER_SPLIT(name, shift1, nb1, shift2, nb2) \
377 static inline uint32_t name(uint32_t opcode) \
379 return (((opcode >> (shift1)) & ((1 << (nb1)) - 1)) << nb2) | \
380 ((opcode >> (shift2)) & ((1 << (nb2)) - 1)); \
383 EXTRACT_HELPER(opc1
, 26, 6);
385 EXTRACT_HELPER(opc2
, 1, 5);
387 EXTRACT_HELPER(opc3
, 6, 5);
388 /* Update Cr0 flags */
389 EXTRACT_HELPER(Rc
, 0, 1);
391 EXTRACT_HELPER(rD
, 21, 5);
393 EXTRACT_HELPER(rS
, 21, 5);
395 EXTRACT_HELPER(rA
, 16, 5);
397 EXTRACT_HELPER(rB
, 11, 5);
399 EXTRACT_HELPER(rC
, 6, 5);
401 EXTRACT_HELPER(crfD
, 23, 3);
402 EXTRACT_HELPER(crfS
, 18, 3);
403 EXTRACT_HELPER(crbD
, 21, 5);
404 EXTRACT_HELPER(crbA
, 16, 5);
405 EXTRACT_HELPER(crbB
, 11, 5);
407 EXTRACT_HELPER(_SPR
, 11, 10);
408 static inline uint32_t SPR(uint32_t opcode
)
410 uint32_t sprn
= _SPR(opcode
);
412 return ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
414 /*** Get constants ***/
415 EXTRACT_HELPER(IMM
, 12, 8);
416 /* 16 bits signed immediate value */
417 EXTRACT_SHELPER(SIMM
, 0, 16);
418 /* 16 bits unsigned immediate value */
419 EXTRACT_HELPER(UIMM
, 0, 16);
420 /* 5 bits signed immediate value */
421 EXTRACT_HELPER(SIMM5
, 16, 5);
422 /* 5 bits signed immediate value */
423 EXTRACT_HELPER(UIMM5
, 16, 5);
425 EXTRACT_HELPER(NB
, 11, 5);
427 EXTRACT_HELPER(SH
, 11, 5);
428 /* Vector shift count */
429 EXTRACT_HELPER(VSH
, 6, 4);
431 EXTRACT_HELPER(MB
, 6, 5);
433 EXTRACT_HELPER(ME
, 1, 5);
435 EXTRACT_HELPER(TO
, 21, 5);
437 EXTRACT_HELPER(CRM
, 12, 8);
438 EXTRACT_HELPER(SR
, 16, 4);
441 EXTRACT_HELPER(FPBF
, 23, 3);
442 EXTRACT_HELPER(FPIMM
, 12, 4);
443 EXTRACT_HELPER(FPL
, 25, 1);
444 EXTRACT_HELPER(FPFLM
, 17, 8);
445 EXTRACT_HELPER(FPW
, 16, 1);
447 /*** Jump target decoding ***/
449 EXTRACT_SHELPER(d
, 0, 16);
450 /* Immediate address */
451 static inline target_ulong
LI(uint32_t opcode
)
453 return (opcode
>> 0) & 0x03FFFFFC;
456 static inline uint32_t BD(uint32_t opcode
)
458 return (opcode
>> 0) & 0xFFFC;
461 EXTRACT_HELPER(BO
, 21, 5);
462 EXTRACT_HELPER(BI
, 16, 5);
463 /* Absolute/relative address */
464 EXTRACT_HELPER(AA
, 1, 1);
466 EXTRACT_HELPER(LK
, 0, 1);
468 /* Create a mask between <start> and <end> bits */
469 static inline target_ulong
MASK(uint32_t start
, uint32_t end
)
473 #if defined(TARGET_PPC64)
474 if (likely(start
== 0)) {
475 ret
= UINT64_MAX
<< (63 - end
);
476 } else if (likely(end
== 63)) {
477 ret
= UINT64_MAX
>> start
;
480 if (likely(start
== 0)) {
481 ret
= UINT32_MAX
<< (31 - end
);
482 } else if (likely(end
== 31)) {
483 ret
= UINT32_MAX
>> start
;
487 ret
= (((target_ulong
)(-1ULL)) >> (start
)) ^
488 (((target_ulong
)(-1ULL) >> (end
)) >> 1);
489 if (unlikely(start
> end
))
496 EXTRACT_HELPER_SPLIT(xT
, 0, 1, 21, 5);
497 EXTRACT_HELPER_SPLIT(xS
, 0, 1, 21, 5);
498 EXTRACT_HELPER_SPLIT(xA
, 2, 1, 16, 5);
499 EXTRACT_HELPER_SPLIT(xB
, 1, 1, 11, 5);
500 EXTRACT_HELPER_SPLIT(xC
, 3, 1, 6, 5);
501 EXTRACT_HELPER(DM
, 8, 2);
502 EXTRACT_HELPER(UIM
, 16, 2);
503 EXTRACT_HELPER(SHW
, 8, 2);
504 /*****************************************************************************/
505 /* PowerPC instructions table */
507 #if defined(DO_PPC_STATISTICS)
508 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
518 .handler = &gen_##name, \
519 .oname = stringify(name), \
521 .oname = stringify(name), \
523 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
534 .handler = &gen_##name, \
535 .oname = stringify(name), \
537 .oname = stringify(name), \
539 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
549 .handler = &gen_##name, \
555 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
565 .handler = &gen_##name, \
567 .oname = stringify(name), \
569 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
580 .handler = &gen_##name, \
582 .oname = stringify(name), \
584 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
594 .handler = &gen_##name, \
600 /* SPR load/store helpers */
601 static inline void gen_load_spr(TCGv t
, int reg
)
603 tcg_gen_ld_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
606 static inline void gen_store_spr(int reg
, TCGv t
)
608 tcg_gen_st_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
611 /* Invalid instruction */
612 static void gen_invalid(DisasContext
*ctx
)
614 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
617 static opc_handler_t invalid_handler
= {
618 .inval1
= 0xFFFFFFFF,
619 .inval2
= 0xFFFFFFFF,
622 .handler
= gen_invalid
,
625 /*** Integer comparison ***/
627 static inline void gen_op_cmp(TCGv arg0
, TCGv arg1
, int s
, int crf
)
629 TCGv t0
= tcg_temp_new();
630 TCGv_i32 t1
= tcg_temp_new_i32();
632 tcg_gen_trunc_tl_i32(cpu_crf
[crf
], cpu_so
);
634 tcg_gen_setcond_tl((s
? TCG_COND_LT
: TCG_COND_LTU
), t0
, arg0
, arg1
);
635 tcg_gen_trunc_tl_i32(t1
, t0
);
636 tcg_gen_shli_i32(t1
, t1
, CRF_LT
);
637 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
639 tcg_gen_setcond_tl((s
? TCG_COND_GT
: TCG_COND_GTU
), t0
, arg0
, arg1
);
640 tcg_gen_trunc_tl_i32(t1
, t0
);
641 tcg_gen_shli_i32(t1
, t1
, CRF_GT
);
642 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
644 tcg_gen_setcond_tl(TCG_COND_EQ
, t0
, arg0
, arg1
);
645 tcg_gen_trunc_tl_i32(t1
, t0
);
646 tcg_gen_shli_i32(t1
, t1
, CRF_EQ
);
647 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
650 tcg_temp_free_i32(t1
);
653 static inline void gen_op_cmpi(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
655 TCGv t0
= tcg_const_tl(arg1
);
656 gen_op_cmp(arg0
, t0
, s
, crf
);
660 static inline void gen_op_cmp32(TCGv arg0
, TCGv arg1
, int s
, int crf
)
666 tcg_gen_ext32s_tl(t0
, arg0
);
667 tcg_gen_ext32s_tl(t1
, arg1
);
669 tcg_gen_ext32u_tl(t0
, arg0
);
670 tcg_gen_ext32u_tl(t1
, arg1
);
672 gen_op_cmp(t0
, t1
, s
, crf
);
677 static inline void gen_op_cmpi32(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
679 TCGv t0
= tcg_const_tl(arg1
);
680 gen_op_cmp32(arg0
, t0
, s
, crf
);
684 static inline void gen_set_Rc0(DisasContext
*ctx
, TCGv reg
)
686 if (NARROW_MODE(ctx
)) {
687 gen_op_cmpi32(reg
, 0, 1, 0);
689 gen_op_cmpi(reg
, 0, 1, 0);
694 static void gen_cmp(DisasContext
*ctx
)
696 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
697 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
698 1, crfD(ctx
->opcode
));
700 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
701 1, crfD(ctx
->opcode
));
706 static void gen_cmpi(DisasContext
*ctx
)
708 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
709 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
710 1, crfD(ctx
->opcode
));
712 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
713 1, crfD(ctx
->opcode
));
718 static void gen_cmpl(DisasContext
*ctx
)
720 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
721 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
722 0, crfD(ctx
->opcode
));
724 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
725 0, crfD(ctx
->opcode
));
730 static void gen_cmpli(DisasContext
*ctx
)
732 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
733 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
734 0, crfD(ctx
->opcode
));
736 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
737 0, crfD(ctx
->opcode
));
741 /* isel (PowerPC 2.03 specification) */
742 static void gen_isel(DisasContext
*ctx
)
745 uint32_t bi
= rC(ctx
->opcode
);
749 l1
= gen_new_label();
750 l2
= gen_new_label();
752 mask
= 1 << (3 - (bi
& 0x03));
753 t0
= tcg_temp_new_i32();
754 tcg_gen_andi_i32(t0
, cpu_crf
[bi
>> 2], mask
);
755 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
756 if (rA(ctx
->opcode
) == 0)
757 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
759 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
762 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
764 tcg_temp_free_i32(t0
);
767 /* cmpb: PowerPC 2.05 specification */
768 static void gen_cmpb(DisasContext
*ctx
)
770 gen_helper_cmpb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
771 cpu_gpr
[rB(ctx
->opcode
)]);
774 /*** Integer arithmetic ***/
776 static inline void gen_op_arith_compute_ov(DisasContext
*ctx
, TCGv arg0
,
777 TCGv arg1
, TCGv arg2
, int sub
)
779 TCGv t0
= tcg_temp_new();
781 tcg_gen_xor_tl(cpu_ov
, arg0
, arg2
);
782 tcg_gen_xor_tl(t0
, arg1
, arg2
);
784 tcg_gen_and_tl(cpu_ov
, cpu_ov
, t0
);
786 tcg_gen_andc_tl(cpu_ov
, cpu_ov
, t0
);
789 if (NARROW_MODE(ctx
)) {
790 tcg_gen_ext32s_tl(cpu_ov
, cpu_ov
);
792 tcg_gen_shri_tl(cpu_ov
, cpu_ov
, TARGET_LONG_BITS
- 1);
793 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
796 /* Common add function */
797 static inline void gen_op_arith_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
798 TCGv arg2
, bool add_ca
, bool compute_ca
,
799 bool compute_ov
, bool compute_rc0
)
803 if (compute_ca
|| compute_ov
) {
808 if (NARROW_MODE(ctx
)) {
809 /* Caution: a non-obvious corner case of the spec is that we
810 must produce the *entire* 64-bit addition, but produce the
811 carry into bit 32. */
812 TCGv t1
= tcg_temp_new();
813 tcg_gen_xor_tl(t1
, arg1
, arg2
); /* add without carry */
814 tcg_gen_add_tl(t0
, arg1
, arg2
);
816 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
818 tcg_gen_xor_tl(cpu_ca
, t0
, t1
); /* bits changed w/ carry */
820 tcg_gen_shri_tl(cpu_ca
, cpu_ca
, 32); /* extract bit 32 */
821 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
823 TCGv zero
= tcg_const_tl(0);
825 tcg_gen_add2_tl(t0
, cpu_ca
, arg1
, zero
, cpu_ca
, zero
);
826 tcg_gen_add2_tl(t0
, cpu_ca
, t0
, cpu_ca
, arg2
, zero
);
828 tcg_gen_add2_tl(t0
, cpu_ca
, arg1
, zero
, arg2
, zero
);
833 tcg_gen_add_tl(t0
, arg1
, arg2
);
835 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
840 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 0);
842 if (unlikely(compute_rc0
)) {
843 gen_set_Rc0(ctx
, t0
);
846 if (!TCGV_EQUAL(t0
, ret
)) {
847 tcg_gen_mov_tl(ret
, t0
);
851 /* Add functions with two operands */
852 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
853 static void glue(gen_, name)(DisasContext *ctx) \
855 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
856 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
857 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
859 /* Add functions with one operand and one immediate */
860 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
861 add_ca, compute_ca, compute_ov) \
862 static void glue(gen_, name)(DisasContext *ctx) \
864 TCGv t0 = tcg_const_tl(const_val); \
865 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
866 cpu_gpr[rA(ctx->opcode)], t0, \
867 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
871 /* add add. addo addo. */
872 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
873 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
874 /* addc addc. addco addco. */
875 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
876 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
877 /* adde adde. addeo addeo. */
878 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
879 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
880 /* addme addme. addmeo addmeo. */
881 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
882 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
883 /* addze addze. addzeo addzeo.*/
884 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
885 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
887 static void gen_addi(DisasContext
*ctx
)
889 target_long simm
= SIMM(ctx
->opcode
);
891 if (rA(ctx
->opcode
) == 0) {
893 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
);
895 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)],
896 cpu_gpr
[rA(ctx
->opcode
)], simm
);
900 static inline void gen_op_addic(DisasContext
*ctx
, bool compute_rc0
)
902 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
903 gen_op_arith_add(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
904 c
, 0, 1, 0, compute_rc0
);
908 static void gen_addic(DisasContext
*ctx
)
910 gen_op_addic(ctx
, 0);
913 static void gen_addic_(DisasContext
*ctx
)
915 gen_op_addic(ctx
, 1);
919 static void gen_addis(DisasContext
*ctx
)
921 target_long simm
= SIMM(ctx
->opcode
);
923 if (rA(ctx
->opcode
) == 0) {
925 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
<< 16);
927 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)],
928 cpu_gpr
[rA(ctx
->opcode
)], simm
<< 16);
932 static inline void gen_op_arith_divw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
933 TCGv arg2
, int sign
, int compute_ov
)
935 int l1
= gen_new_label();
936 int l2
= gen_new_label();
937 TCGv_i32 t0
= tcg_temp_local_new_i32();
938 TCGv_i32 t1
= tcg_temp_local_new_i32();
940 tcg_gen_trunc_tl_i32(t0
, arg1
);
941 tcg_gen_trunc_tl_i32(t1
, arg2
);
942 tcg_gen_brcondi_i32(TCG_COND_EQ
, t1
, 0, l1
);
944 int l3
= gen_new_label();
945 tcg_gen_brcondi_i32(TCG_COND_NE
, t1
, -1, l3
);
946 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, INT32_MIN
, l1
);
948 tcg_gen_div_i32(t0
, t0
, t1
);
950 tcg_gen_divu_i32(t0
, t0
, t1
);
953 tcg_gen_movi_tl(cpu_ov
, 0);
958 tcg_gen_sari_i32(t0
, t0
, 31);
960 tcg_gen_movi_i32(t0
, 0);
963 tcg_gen_movi_tl(cpu_ov
, 1);
964 tcg_gen_movi_tl(cpu_so
, 1);
967 tcg_gen_extu_i32_tl(ret
, t0
);
968 tcg_temp_free_i32(t0
);
969 tcg_temp_free_i32(t1
);
970 if (unlikely(Rc(ctx
->opcode
) != 0))
971 gen_set_Rc0(ctx
, ret
);
974 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
975 static void glue(gen_, name)(DisasContext *ctx) \
977 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
978 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
981 /* divwu divwu. divwuo divwuo. */
982 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0);
983 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1);
984 /* divw divw. divwo divwo. */
985 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0);
986 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1);
988 /* div[wd]eu[o][.] */
989 #define GEN_DIVE(name, hlpr, compute_ov) \
990 static void gen_##name(DisasContext *ctx) \
992 TCGv_i32 t0 = tcg_const_i32(compute_ov); \
993 gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \
994 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \
995 tcg_temp_free_i32(t0); \
996 if (unlikely(Rc(ctx->opcode) != 0)) { \
997 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1001 GEN_DIVE(divweu
, divweu
, 0);
1002 GEN_DIVE(divweuo
, divweu
, 1);
1003 GEN_DIVE(divwe
, divwe
, 0);
1004 GEN_DIVE(divweo
, divwe
, 1);
1006 #if defined(TARGET_PPC64)
1007 static inline void gen_op_arith_divd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1008 TCGv arg2
, int sign
, int compute_ov
)
1010 int l1
= gen_new_label();
1011 int l2
= gen_new_label();
1013 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg2
, 0, l1
);
1015 int l3
= gen_new_label();
1016 tcg_gen_brcondi_i64(TCG_COND_NE
, arg2
, -1, l3
);
1017 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg1
, INT64_MIN
, l1
);
1019 tcg_gen_div_i64(ret
, arg1
, arg2
);
1021 tcg_gen_divu_i64(ret
, arg1
, arg2
);
1024 tcg_gen_movi_tl(cpu_ov
, 0);
1029 tcg_gen_sari_i64(ret
, arg1
, 63);
1031 tcg_gen_movi_i64(ret
, 0);
1034 tcg_gen_movi_tl(cpu_ov
, 1);
1035 tcg_gen_movi_tl(cpu_so
, 1);
1038 if (unlikely(Rc(ctx
->opcode
) != 0))
1039 gen_set_Rc0(ctx
, ret
);
1041 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1042 static void glue(gen_, name)(DisasContext *ctx) \
1044 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1045 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1046 sign, compute_ov); \
1048 /* divwu divwu. divwuo divwuo. */
1049 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0);
1050 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1);
1051 /* divw divw. divwo divwo. */
1052 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0);
1053 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1);
1055 GEN_DIVE(divdeu
, divdeu
, 0);
1056 GEN_DIVE(divdeuo
, divdeu
, 1);
1057 GEN_DIVE(divde
, divde
, 0);
1058 GEN_DIVE(divdeo
, divde
, 1);
1062 static void gen_mulhw(DisasContext
*ctx
)
1064 TCGv_i32 t0
= tcg_temp_new_i32();
1065 TCGv_i32 t1
= tcg_temp_new_i32();
1067 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1068 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1069 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1070 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1071 tcg_temp_free_i32(t0
);
1072 tcg_temp_free_i32(t1
);
1073 if (unlikely(Rc(ctx
->opcode
) != 0))
1074 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1077 /* mulhwu mulhwu. */
1078 static void gen_mulhwu(DisasContext
*ctx
)
1080 TCGv_i32 t0
= tcg_temp_new_i32();
1081 TCGv_i32 t1
= tcg_temp_new_i32();
1083 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1084 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1085 tcg_gen_mulu2_i32(t0
, t1
, t0
, t1
);
1086 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1087 tcg_temp_free_i32(t0
);
1088 tcg_temp_free_i32(t1
);
1089 if (unlikely(Rc(ctx
->opcode
) != 0))
1090 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1094 static void gen_mullw(DisasContext
*ctx
)
1096 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1097 cpu_gpr
[rB(ctx
->opcode
)]);
1098 tcg_gen_ext32s_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)]);
1099 if (unlikely(Rc(ctx
->opcode
) != 0))
1100 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1103 /* mullwo mullwo. */
1104 static void gen_mullwo(DisasContext
*ctx
)
1106 TCGv_i32 t0
= tcg_temp_new_i32();
1107 TCGv_i32 t1
= tcg_temp_new_i32();
1109 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1110 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1111 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1112 tcg_gen_ext_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1114 tcg_gen_sari_i32(t0
, t0
, 31);
1115 tcg_gen_setcond_i32(TCG_COND_NE
, t0
, t0
, t1
);
1116 tcg_gen_extu_i32_tl(cpu_ov
, t0
);
1117 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1119 tcg_temp_free_i32(t0
);
1120 tcg_temp_free_i32(t1
);
1121 if (unlikely(Rc(ctx
->opcode
) != 0))
1122 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1126 static void gen_mulli(DisasContext
*ctx
)
1128 tcg_gen_muli_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1132 #if defined(TARGET_PPC64)
1134 static void gen_mulhd(DisasContext
*ctx
)
1136 TCGv lo
= tcg_temp_new();
1137 tcg_gen_muls2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1138 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1140 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1141 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1145 /* mulhdu mulhdu. */
1146 static void gen_mulhdu(DisasContext
*ctx
)
1148 TCGv lo
= tcg_temp_new();
1149 tcg_gen_mulu2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1150 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1152 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1153 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1158 static void gen_mulld(DisasContext
*ctx
)
1160 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1161 cpu_gpr
[rB(ctx
->opcode
)]);
1162 if (unlikely(Rc(ctx
->opcode
) != 0))
1163 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1166 /* mulldo mulldo. */
1167 static void gen_mulldo(DisasContext
*ctx
)
1169 gen_helper_mulldo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
1170 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1171 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1172 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1177 /* Common subf function */
1178 static inline void gen_op_arith_subf(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1179 TCGv arg2
, bool add_ca
, bool compute_ca
,
1180 bool compute_ov
, bool compute_rc0
)
1184 if (compute_ca
|| compute_ov
) {
1185 t0
= tcg_temp_new();
1189 /* dest = ~arg1 + arg2 [+ ca]. */
1190 if (NARROW_MODE(ctx
)) {
1191 /* Caution: a non-obvious corner case of the spec is that we
1192 must produce the *entire* 64-bit addition, but produce the
1193 carry into bit 32. */
1194 TCGv inv1
= tcg_temp_new();
1195 TCGv t1
= tcg_temp_new();
1196 tcg_gen_not_tl(inv1
, arg1
);
1198 tcg_gen_add_tl(t0
, arg2
, cpu_ca
);
1200 tcg_gen_addi_tl(t0
, arg2
, 1);
1202 tcg_gen_xor_tl(t1
, arg2
, inv1
); /* add without carry */
1203 tcg_gen_add_tl(t0
, t0
, inv1
);
1204 tcg_gen_xor_tl(cpu_ca
, t0
, t1
); /* bits changes w/ carry */
1206 tcg_gen_shri_tl(cpu_ca
, cpu_ca
, 32); /* extract bit 32 */
1207 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
1208 } else if (add_ca
) {
1209 TCGv zero
, inv1
= tcg_temp_new();
1210 tcg_gen_not_tl(inv1
, arg1
);
1211 zero
= tcg_const_tl(0);
1212 tcg_gen_add2_tl(t0
, cpu_ca
, arg2
, zero
, cpu_ca
, zero
);
1213 tcg_gen_add2_tl(t0
, cpu_ca
, t0
, cpu_ca
, inv1
, zero
);
1214 tcg_temp_free(zero
);
1215 tcg_temp_free(inv1
);
1217 tcg_gen_setcond_tl(TCG_COND_GEU
, cpu_ca
, arg2
, arg1
);
1218 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1220 } else if (add_ca
) {
1221 /* Since we're ignoring carry-out, we can simplify the
1222 standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1. */
1223 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1224 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
1225 tcg_gen_subi_tl(t0
, t0
, 1);
1227 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1231 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 1);
1233 if (unlikely(compute_rc0
)) {
1234 gen_set_Rc0(ctx
, t0
);
1237 if (!TCGV_EQUAL(t0
, ret
)) {
1238 tcg_gen_mov_tl(ret
, t0
);
1242 /* Sub functions with Two operands functions */
1243 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1244 static void glue(gen_, name)(DisasContext *ctx) \
1246 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1247 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1248 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1250 /* Sub functions with one operand and one immediate */
1251 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1252 add_ca, compute_ca, compute_ov) \
1253 static void glue(gen_, name)(DisasContext *ctx) \
1255 TCGv t0 = tcg_const_tl(const_val); \
1256 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1257 cpu_gpr[rA(ctx->opcode)], t0, \
1258 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1259 tcg_temp_free(t0); \
1261 /* subf subf. subfo subfo. */
1262 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
1263 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
1264 /* subfc subfc. subfco subfco. */
1265 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
1266 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
1267 /* subfe subfe. subfeo subfo. */
1268 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
1269 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
1270 /* subfme subfme. subfmeo subfmeo. */
1271 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
1272 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
1273 /* subfze subfze. subfzeo subfzeo.*/
1274 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
1275 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
1278 static void gen_subfic(DisasContext
*ctx
)
1280 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
1281 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1286 /* neg neg. nego nego. */
1287 static inline void gen_op_arith_neg(DisasContext
*ctx
, bool compute_ov
)
1289 TCGv zero
= tcg_const_tl(0);
1290 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1291 zero
, 0, 0, compute_ov
, Rc(ctx
->opcode
));
1292 tcg_temp_free(zero
);
1295 static void gen_neg(DisasContext
*ctx
)
1297 gen_op_arith_neg(ctx
, 0);
1300 static void gen_nego(DisasContext
*ctx
)
1302 gen_op_arith_neg(ctx
, 1);
1305 /*** Integer logical ***/
1306 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1307 static void glue(gen_, name)(DisasContext *ctx) \
1309 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1310 cpu_gpr[rB(ctx->opcode)]); \
1311 if (unlikely(Rc(ctx->opcode) != 0)) \
1312 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1315 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1316 static void glue(gen_, name)(DisasContext *ctx) \
1318 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1319 if (unlikely(Rc(ctx->opcode) != 0)) \
1320 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1324 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
);
1326 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
);
1329 static void gen_andi_(DisasContext
*ctx
)
1331 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
));
1332 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1336 static void gen_andis_(DisasContext
*ctx
)
1338 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
) << 16);
1339 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1343 static void gen_cntlzw(DisasContext
*ctx
)
1345 gen_helper_cntlzw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1346 if (unlikely(Rc(ctx
->opcode
) != 0))
1347 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1350 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
);
1351 /* extsb & extsb. */
1352 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
);
1353 /* extsh & extsh. */
1354 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
);
1356 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
);
1358 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
);
1361 static void gen_or(DisasContext
*ctx
)
1365 rs
= rS(ctx
->opcode
);
1366 ra
= rA(ctx
->opcode
);
1367 rb
= rB(ctx
->opcode
);
1368 /* Optimisation for mr. ri case */
1369 if (rs
!= ra
|| rs
!= rb
) {
1371 tcg_gen_or_tl(cpu_gpr
[ra
], cpu_gpr
[rs
], cpu_gpr
[rb
]);
1373 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rs
]);
1374 if (unlikely(Rc(ctx
->opcode
) != 0))
1375 gen_set_Rc0(ctx
, cpu_gpr
[ra
]);
1376 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
1377 gen_set_Rc0(ctx
, cpu_gpr
[rs
]);
1378 #if defined(TARGET_PPC64)
1384 /* Set process priority to low */
1388 /* Set process priority to medium-low */
1392 /* Set process priority to normal */
1395 #if !defined(CONFIG_USER_ONLY)
1397 if (ctx
->mem_idx
> 0) {
1398 /* Set process priority to very low */
1403 if (ctx
->mem_idx
> 0) {
1404 /* Set process priority to medium-hight */
1409 if (ctx
->mem_idx
> 0) {
1410 /* Set process priority to high */
1415 if (ctx
->mem_idx
> 1) {
1416 /* Set process priority to very high */
1426 TCGv t0
= tcg_temp_new();
1427 gen_load_spr(t0
, SPR_PPR
);
1428 tcg_gen_andi_tl(t0
, t0
, ~0x001C000000000000ULL
);
1429 tcg_gen_ori_tl(t0
, t0
, ((uint64_t)prio
) << 50);
1430 gen_store_spr(SPR_PPR
, t0
);
1437 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
);
1440 static void gen_xor(DisasContext
*ctx
)
1442 /* Optimisation for "set to zero" case */
1443 if (rS(ctx
->opcode
) != rB(ctx
->opcode
))
1444 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1446 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1447 if (unlikely(Rc(ctx
->opcode
) != 0))
1448 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1452 static void gen_ori(DisasContext
*ctx
)
1454 target_ulong uimm
= UIMM(ctx
->opcode
);
1456 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1458 /* XXX: should handle special NOPs for POWER series */
1461 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1465 static void gen_oris(DisasContext
*ctx
)
1467 target_ulong uimm
= UIMM(ctx
->opcode
);
1469 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1473 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1477 static void gen_xori(DisasContext
*ctx
)
1479 target_ulong uimm
= UIMM(ctx
->opcode
);
1481 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1485 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1489 static void gen_xoris(DisasContext
*ctx
)
1491 target_ulong uimm
= UIMM(ctx
->opcode
);
1493 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1497 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1500 /* popcntb : PowerPC 2.03 specification */
1501 static void gen_popcntb(DisasContext
*ctx
)
1503 gen_helper_popcntb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1506 static void gen_popcntw(DisasContext
*ctx
)
1508 gen_helper_popcntw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1511 #if defined(TARGET_PPC64)
1512 /* popcntd: PowerPC 2.06 specification */
1513 static void gen_popcntd(DisasContext
*ctx
)
1515 gen_helper_popcntd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1519 /* prtyw: PowerPC 2.05 specification */
1520 static void gen_prtyw(DisasContext
*ctx
)
1522 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
1523 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
1524 TCGv t0
= tcg_temp_new();
1525 tcg_gen_shri_tl(t0
, rs
, 16);
1526 tcg_gen_xor_tl(ra
, rs
, t0
);
1527 tcg_gen_shri_tl(t0
, ra
, 8);
1528 tcg_gen_xor_tl(ra
, ra
, t0
);
1529 tcg_gen_andi_tl(ra
, ra
, (target_ulong
)0x100000001ULL
);
1533 #if defined(TARGET_PPC64)
1534 /* prtyd: PowerPC 2.05 specification */
1535 static void gen_prtyd(DisasContext
*ctx
)
1537 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
1538 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
1539 TCGv t0
= tcg_temp_new();
1540 tcg_gen_shri_tl(t0
, rs
, 32);
1541 tcg_gen_xor_tl(ra
, rs
, t0
);
1542 tcg_gen_shri_tl(t0
, ra
, 16);
1543 tcg_gen_xor_tl(ra
, ra
, t0
);
1544 tcg_gen_shri_tl(t0
, ra
, 8);
1545 tcg_gen_xor_tl(ra
, ra
, t0
);
1546 tcg_gen_andi_tl(ra
, ra
, 1);
1551 #if defined(TARGET_PPC64)
1553 static void gen_bpermd(DisasContext
*ctx
)
1555 gen_helper_bpermd(cpu_gpr
[rA(ctx
->opcode
)],
1556 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1560 #if defined(TARGET_PPC64)
1561 /* extsw & extsw. */
1562 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
);
1565 static void gen_cntlzd(DisasContext
*ctx
)
1567 gen_helper_cntlzd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1568 if (unlikely(Rc(ctx
->opcode
) != 0))
1569 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1573 /*** Integer rotate ***/
1575 /* rlwimi & rlwimi. */
1576 static void gen_rlwimi(DisasContext
*ctx
)
1578 uint32_t mb
, me
, sh
;
1580 mb
= MB(ctx
->opcode
);
1581 me
= ME(ctx
->opcode
);
1582 sh
= SH(ctx
->opcode
);
1583 if (likely(sh
== 0 && mb
== 0 && me
== 31)) {
1584 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1588 TCGv t0
= tcg_temp_new();
1589 #if defined(TARGET_PPC64)
1590 TCGv_i32 t2
= tcg_temp_new_i32();
1591 tcg_gen_trunc_i64_i32(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
1592 tcg_gen_rotli_i32(t2
, t2
, sh
);
1593 tcg_gen_extu_i32_i64(t0
, t2
);
1594 tcg_temp_free_i32(t2
);
1596 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1598 #if defined(TARGET_PPC64)
1602 mask
= MASK(mb
, me
);
1603 t1
= tcg_temp_new();
1604 tcg_gen_andi_tl(t0
, t0
, mask
);
1605 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1606 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1610 if (unlikely(Rc(ctx
->opcode
) != 0))
1611 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1614 /* rlwinm & rlwinm. */
1615 static void gen_rlwinm(DisasContext
*ctx
)
1617 uint32_t mb
, me
, sh
;
1619 sh
= SH(ctx
->opcode
);
1620 mb
= MB(ctx
->opcode
);
1621 me
= ME(ctx
->opcode
);
1623 if (likely(mb
== 0 && me
== (31 - sh
))) {
1624 if (likely(sh
== 0)) {
1625 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1627 TCGv t0
= tcg_temp_new();
1628 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1629 tcg_gen_shli_tl(t0
, t0
, sh
);
1630 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1633 } else if (likely(sh
!= 0 && me
== 31 && sh
== (32 - mb
))) {
1634 TCGv t0
= tcg_temp_new();
1635 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1636 tcg_gen_shri_tl(t0
, t0
, mb
);
1637 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1640 TCGv t0
= tcg_temp_new();
1641 #if defined(TARGET_PPC64)
1642 TCGv_i32 t1
= tcg_temp_new_i32();
1643 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1644 tcg_gen_rotli_i32(t1
, t1
, sh
);
1645 tcg_gen_extu_i32_i64(t0
, t1
);
1646 tcg_temp_free_i32(t1
);
1648 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1650 #if defined(TARGET_PPC64)
1654 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1657 if (unlikely(Rc(ctx
->opcode
) != 0))
1658 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1661 /* rlwnm & rlwnm. */
1662 static void gen_rlwnm(DisasContext
*ctx
)
1666 #if defined(TARGET_PPC64)
1670 mb
= MB(ctx
->opcode
);
1671 me
= ME(ctx
->opcode
);
1672 t0
= tcg_temp_new();
1673 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1674 #if defined(TARGET_PPC64)
1675 t1
= tcg_temp_new_i32();
1676 t2
= tcg_temp_new_i32();
1677 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1678 tcg_gen_trunc_i64_i32(t2
, t0
);
1679 tcg_gen_rotl_i32(t1
, t1
, t2
);
1680 tcg_gen_extu_i32_i64(t0
, t1
);
1681 tcg_temp_free_i32(t1
);
1682 tcg_temp_free_i32(t2
);
1684 tcg_gen_rotl_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1686 if (unlikely(mb
!= 0 || me
!= 31)) {
1687 #if defined(TARGET_PPC64)
1691 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1693 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1696 if (unlikely(Rc(ctx
->opcode
) != 0))
1697 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1700 #if defined(TARGET_PPC64)
1701 #define GEN_PPC64_R2(name, opc1, opc2) \
1702 static void glue(gen_, name##0)(DisasContext *ctx) \
1704 gen_##name(ctx, 0); \
1707 static void glue(gen_, name##1)(DisasContext *ctx) \
1709 gen_##name(ctx, 1); \
1711 #define GEN_PPC64_R4(name, opc1, opc2) \
1712 static void glue(gen_, name##0)(DisasContext *ctx) \
1714 gen_##name(ctx, 0, 0); \
1717 static void glue(gen_, name##1)(DisasContext *ctx) \
1719 gen_##name(ctx, 0, 1); \
1722 static void glue(gen_, name##2)(DisasContext *ctx) \
1724 gen_##name(ctx, 1, 0); \
1727 static void glue(gen_, name##3)(DisasContext *ctx) \
1729 gen_##name(ctx, 1, 1); \
1732 static inline void gen_rldinm(DisasContext
*ctx
, uint32_t mb
, uint32_t me
,
1735 if (likely(sh
!= 0 && mb
== 0 && me
== (63 - sh
))) {
1736 tcg_gen_shli_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
1737 } else if (likely(sh
!= 0 && me
== 63 && sh
== (64 - mb
))) {
1738 tcg_gen_shri_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], mb
);
1740 TCGv t0
= tcg_temp_new();
1741 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1742 if (likely(mb
== 0 && me
== 63)) {
1743 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1745 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1749 if (unlikely(Rc(ctx
->opcode
) != 0))
1750 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1752 /* rldicl - rldicl. */
1753 static inline void gen_rldicl(DisasContext
*ctx
, int mbn
, int shn
)
1757 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1758 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1759 gen_rldinm(ctx
, mb
, 63, sh
);
1761 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
1762 /* rldicr - rldicr. */
1763 static inline void gen_rldicr(DisasContext
*ctx
, int men
, int shn
)
1767 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1768 me
= MB(ctx
->opcode
) | (men
<< 5);
1769 gen_rldinm(ctx
, 0, me
, sh
);
1771 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
1772 /* rldic - rldic. */
1773 static inline void gen_rldic(DisasContext
*ctx
, int mbn
, int shn
)
1777 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1778 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1779 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
1781 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
1783 static inline void gen_rldnm(DisasContext
*ctx
, uint32_t mb
, uint32_t me
)
1787 t0
= tcg_temp_new();
1788 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1789 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1790 if (unlikely(mb
!= 0 || me
!= 63)) {
1791 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1793 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1796 if (unlikely(Rc(ctx
->opcode
) != 0))
1797 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1800 /* rldcl - rldcl. */
1801 static inline void gen_rldcl(DisasContext
*ctx
, int mbn
)
1805 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1806 gen_rldnm(ctx
, mb
, 63);
1808 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
1809 /* rldcr - rldcr. */
1810 static inline void gen_rldcr(DisasContext
*ctx
, int men
)
1814 me
= MB(ctx
->opcode
) | (men
<< 5);
1815 gen_rldnm(ctx
, 0, me
);
1817 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
1818 /* rldimi - rldimi. */
1819 static inline void gen_rldimi(DisasContext
*ctx
, int mbn
, int shn
)
1821 uint32_t sh
, mb
, me
;
1823 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1824 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1826 if (unlikely(sh
== 0 && mb
== 0)) {
1827 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1832 t0
= tcg_temp_new();
1833 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1834 t1
= tcg_temp_new();
1835 mask
= MASK(mb
, me
);
1836 tcg_gen_andi_tl(t0
, t0
, mask
);
1837 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1838 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1842 if (unlikely(Rc(ctx
->opcode
) != 0))
1843 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1845 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
1848 /*** Integer shift ***/
1851 static void gen_slw(DisasContext
*ctx
)
1855 t0
= tcg_temp_new();
1856 /* AND rS with a mask that is 0 when rB >= 0x20 */
1857 #if defined(TARGET_PPC64)
1858 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
1859 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1861 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
1862 tcg_gen_sari_tl(t0
, t0
, 0x1f);
1864 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1865 t1
= tcg_temp_new();
1866 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1867 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1870 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
1871 if (unlikely(Rc(ctx
->opcode
) != 0))
1872 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1876 static void gen_sraw(DisasContext
*ctx
)
1878 gen_helper_sraw(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
1879 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1880 if (unlikely(Rc(ctx
->opcode
) != 0))
1881 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1884 /* srawi & srawi. */
1885 static void gen_srawi(DisasContext
*ctx
)
1887 int sh
= SH(ctx
->opcode
);
1888 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
1889 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
1891 tcg_gen_mov_tl(dst
, src
);
1892 tcg_gen_movi_tl(cpu_ca
, 0);
1895 tcg_gen_ext32s_tl(dst
, src
);
1896 tcg_gen_andi_tl(cpu_ca
, dst
, (1ULL << sh
) - 1);
1897 t0
= tcg_temp_new();
1898 tcg_gen_sari_tl(t0
, dst
, TARGET_LONG_BITS
- 1);
1899 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
1901 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
1902 tcg_gen_sari_tl(dst
, dst
, sh
);
1904 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1905 gen_set_Rc0(ctx
, dst
);
1910 static void gen_srw(DisasContext
*ctx
)
1914 t0
= tcg_temp_new();
1915 /* AND rS with a mask that is 0 when rB >= 0x20 */
1916 #if defined(TARGET_PPC64)
1917 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
1918 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1920 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
1921 tcg_gen_sari_tl(t0
, t0
, 0x1f);
1923 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1924 tcg_gen_ext32u_tl(t0
, t0
);
1925 t1
= tcg_temp_new();
1926 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1927 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1930 if (unlikely(Rc(ctx
->opcode
) != 0))
1931 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1934 #if defined(TARGET_PPC64)
1936 static void gen_sld(DisasContext
*ctx
)
1940 t0
= tcg_temp_new();
1941 /* AND rS with a mask that is 0 when rB >= 0x40 */
1942 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
1943 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1944 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1945 t1
= tcg_temp_new();
1946 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1947 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1950 if (unlikely(Rc(ctx
->opcode
) != 0))
1951 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1955 static void gen_srad(DisasContext
*ctx
)
1957 gen_helper_srad(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
1958 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1959 if (unlikely(Rc(ctx
->opcode
) != 0))
1960 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1962 /* sradi & sradi. */
1963 static inline void gen_sradi(DisasContext
*ctx
, int n
)
1965 int sh
= SH(ctx
->opcode
) + (n
<< 5);
1966 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
1967 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
1969 tcg_gen_mov_tl(dst
, src
);
1970 tcg_gen_movi_tl(cpu_ca
, 0);
1973 tcg_gen_andi_tl(cpu_ca
, src
, (1ULL << sh
) - 1);
1974 t0
= tcg_temp_new();
1975 tcg_gen_sari_tl(t0
, src
, 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
, src
, sh
);
1981 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1982 gen_set_Rc0(ctx
, dst
);
1986 static void gen_sradi0(DisasContext
*ctx
)
1991 static void gen_sradi1(DisasContext
*ctx
)
1997 static void gen_srd(DisasContext
*ctx
)
2001 t0
= tcg_temp_new();
2002 /* AND rS with a mask that is 0 when rB >= 0x40 */
2003 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
2004 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2005 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2006 t1
= tcg_temp_new();
2007 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
2008 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2011 if (unlikely(Rc(ctx
->opcode
) != 0))
2012 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2016 /*** Floating-Point arithmetic ***/
2017 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
2018 static void gen_f##name(DisasContext *ctx) \
2020 if (unlikely(!ctx->fpu_enabled)) { \
2021 gen_exception(ctx, POWERPC_EXCP_FPU); \
2024 /* NIP cannot be restored if the memory exception comes from an helper */ \
2025 gen_update_nip(ctx, ctx->nip - 4); \
2026 gen_reset_fpstatus(); \
2027 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2028 cpu_fpr[rA(ctx->opcode)], \
2029 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2031 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2032 cpu_fpr[rD(ctx->opcode)]); \
2034 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \
2035 Rc(ctx->opcode) != 0); \
2038 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2039 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2040 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
2042 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2043 static void gen_f##name(DisasContext *ctx) \
2045 if (unlikely(!ctx->fpu_enabled)) { \
2046 gen_exception(ctx, POWERPC_EXCP_FPU); \
2049 /* NIP cannot be restored if the memory exception comes from an helper */ \
2050 gen_update_nip(ctx, ctx->nip - 4); \
2051 gen_reset_fpstatus(); \
2052 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2053 cpu_fpr[rA(ctx->opcode)], \
2054 cpu_fpr[rB(ctx->opcode)]); \
2056 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2057 cpu_fpr[rD(ctx->opcode)]); \
2059 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2060 set_fprf, Rc(ctx->opcode) != 0); \
2062 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2063 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2064 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2066 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2067 static void gen_f##name(DisasContext *ctx) \
2069 if (unlikely(!ctx->fpu_enabled)) { \
2070 gen_exception(ctx, POWERPC_EXCP_FPU); \
2073 /* NIP cannot be restored if the memory exception comes from an helper */ \
2074 gen_update_nip(ctx, ctx->nip - 4); \
2075 gen_reset_fpstatus(); \
2076 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2077 cpu_fpr[rA(ctx->opcode)], \
2078 cpu_fpr[rC(ctx->opcode)]); \
2080 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2081 cpu_fpr[rD(ctx->opcode)]); \
2083 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2084 set_fprf, Rc(ctx->opcode) != 0); \
2086 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2087 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2088 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2090 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
2091 static void gen_f##name(DisasContext *ctx) \
2093 if (unlikely(!ctx->fpu_enabled)) { \
2094 gen_exception(ctx, POWERPC_EXCP_FPU); \
2097 /* NIP cannot be restored if the memory exception comes from an helper */ \
2098 gen_update_nip(ctx, ctx->nip - 4); \
2099 gen_reset_fpstatus(); \
2100 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2101 cpu_fpr[rB(ctx->opcode)]); \
2102 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2103 set_fprf, Rc(ctx->opcode) != 0); \
2106 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
2107 static void gen_f##name(DisasContext *ctx) \
2109 if (unlikely(!ctx->fpu_enabled)) { \
2110 gen_exception(ctx, POWERPC_EXCP_FPU); \
2113 /* NIP cannot be restored if the memory exception comes from an helper */ \
2114 gen_update_nip(ctx, ctx->nip - 4); \
2115 gen_reset_fpstatus(); \
2116 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2117 cpu_fpr[rB(ctx->opcode)]); \
2118 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2119 set_fprf, Rc(ctx->opcode) != 0); \
2123 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
);
2125 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
);
2127 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
);
2130 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
);
2133 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
);
2136 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
);
2139 static void gen_frsqrtes(DisasContext
*ctx
)
2141 if (unlikely(!ctx
->fpu_enabled
)) {
2142 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2145 /* NIP cannot be restored if the memory exception comes from an helper */
2146 gen_update_nip(ctx
, ctx
->nip
- 4);
2147 gen_reset_fpstatus();
2148 gen_helper_frsqrte(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2149 cpu_fpr
[rB(ctx
->opcode
)]);
2150 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2151 cpu_fpr
[rD(ctx
->opcode
)]);
2152 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2156 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
);
2158 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
);
2162 static void gen_fsqrt(DisasContext
*ctx
)
2164 if (unlikely(!ctx
->fpu_enabled
)) {
2165 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2168 /* NIP cannot be restored if the memory exception comes from an helper */
2169 gen_update_nip(ctx
, ctx
->nip
- 4);
2170 gen_reset_fpstatus();
2171 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2172 cpu_fpr
[rB(ctx
->opcode
)]);
2173 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2176 static void gen_fsqrts(DisasContext
*ctx
)
2178 if (unlikely(!ctx
->fpu_enabled
)) {
2179 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2182 /* NIP cannot be restored if the memory exception comes from an helper */
2183 gen_update_nip(ctx
, ctx
->nip
- 4);
2184 gen_reset_fpstatus();
2185 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2186 cpu_fpr
[rB(ctx
->opcode
)]);
2187 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2188 cpu_fpr
[rD(ctx
->opcode
)]);
2189 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2192 /*** Floating-Point multiply-and-add ***/
2193 /* fmadd - fmadds */
2194 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
);
2195 /* fmsub - fmsubs */
2196 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
);
2197 /* fnmadd - fnmadds */
2198 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
);
2199 /* fnmsub - fnmsubs */
2200 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
);
2202 /*** Floating-Point round & convert ***/
2204 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
);
2206 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
);
2208 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
);
2209 #if defined(TARGET_PPC64)
2211 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
);
2213 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
);
2215 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
);
2219 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
);
2221 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
);
2223 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
);
2225 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
);
2227 /*** Floating-Point compare ***/
2230 static void gen_fcmpo(DisasContext
*ctx
)
2233 if (unlikely(!ctx
->fpu_enabled
)) {
2234 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2237 /* NIP cannot be restored if the memory exception comes from an helper */
2238 gen_update_nip(ctx
, ctx
->nip
- 4);
2239 gen_reset_fpstatus();
2240 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2241 gen_helper_fcmpo(cpu_env
, cpu_fpr
[rA(ctx
->opcode
)],
2242 cpu_fpr
[rB(ctx
->opcode
)], crf
);
2243 tcg_temp_free_i32(crf
);
2244 gen_helper_float_check_status(cpu_env
);
2248 static void gen_fcmpu(DisasContext
*ctx
)
2251 if (unlikely(!ctx
->fpu_enabled
)) {
2252 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2255 /* NIP cannot be restored if the memory exception comes from an helper */
2256 gen_update_nip(ctx
, ctx
->nip
- 4);
2257 gen_reset_fpstatus();
2258 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2259 gen_helper_fcmpu(cpu_env
, cpu_fpr
[rA(ctx
->opcode
)],
2260 cpu_fpr
[rB(ctx
->opcode
)], crf
);
2261 tcg_temp_free_i32(crf
);
2262 gen_helper_float_check_status(cpu_env
);
2265 /*** Floating-point move ***/
2267 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2268 static void gen_fabs(DisasContext
*ctx
)
2270 if (unlikely(!ctx
->fpu_enabled
)) {
2271 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2274 tcg_gen_andi_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)],
2276 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2280 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2281 static void gen_fmr(DisasContext
*ctx
)
2283 if (unlikely(!ctx
->fpu_enabled
)) {
2284 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2287 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2288 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2292 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2293 static void gen_fnabs(DisasContext
*ctx
)
2295 if (unlikely(!ctx
->fpu_enabled
)) {
2296 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2299 tcg_gen_ori_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)],
2301 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2305 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2306 static void gen_fneg(DisasContext
*ctx
)
2308 if (unlikely(!ctx
->fpu_enabled
)) {
2309 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2312 tcg_gen_xori_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)],
2314 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2317 /* fcpsgn: PowerPC 2.05 specification */
2318 /* XXX: beware that fcpsgn never checks for NaNs nor update FPSCR */
2319 static void gen_fcpsgn(DisasContext
*ctx
)
2321 if (unlikely(!ctx
->fpu_enabled
)) {
2322 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2325 tcg_gen_deposit_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rA(ctx
->opcode
)],
2326 cpu_fpr
[rB(ctx
->opcode
)], 0, 63);
2327 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2330 static void gen_fmrgew(DisasContext
*ctx
)
2333 if (unlikely(!ctx
->fpu_enabled
)) {
2334 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2337 b0
= tcg_temp_new_i64();
2338 tcg_gen_shri_i64(b0
, cpu_fpr
[rB(ctx
->opcode
)], 32);
2339 tcg_gen_deposit_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rA(ctx
->opcode
)],
2341 tcg_temp_free_i64(b0
);
2344 static void gen_fmrgow(DisasContext
*ctx
)
2346 if (unlikely(!ctx
->fpu_enabled
)) {
2347 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2350 tcg_gen_deposit_i64(cpu_fpr
[rD(ctx
->opcode
)],
2351 cpu_fpr
[rB(ctx
->opcode
)],
2352 cpu_fpr
[rA(ctx
->opcode
)],
2356 /*** Floating-Point status & ctrl register ***/
2359 static void gen_mcrfs(DisasContext
*ctx
)
2361 TCGv tmp
= tcg_temp_new();
2364 if (unlikely(!ctx
->fpu_enabled
)) {
2365 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2368 bfa
= 4 * (7 - crfS(ctx
->opcode
));
2369 tcg_gen_shri_tl(tmp
, cpu_fpscr
, bfa
);
2370 tcg_gen_trunc_tl_i32(cpu_crf
[crfD(ctx
->opcode
)], tmp
);
2372 tcg_gen_andi_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfD(ctx
->opcode
)], 0xf);
2373 tcg_gen_andi_tl(cpu_fpscr
, cpu_fpscr
, ~(0xF << bfa
));
2377 static void gen_mffs(DisasContext
*ctx
)
2379 if (unlikely(!ctx
->fpu_enabled
)) {
2380 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2383 gen_reset_fpstatus();
2384 tcg_gen_extu_tl_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpscr
);
2385 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2389 static void gen_mtfsb0(DisasContext
*ctx
)
2393 if (unlikely(!ctx
->fpu_enabled
)) {
2394 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2397 crb
= 31 - crbD(ctx
->opcode
);
2398 gen_reset_fpstatus();
2399 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
)) {
2401 /* NIP cannot be restored if the memory exception comes from an helper */
2402 gen_update_nip(ctx
, ctx
->nip
- 4);
2403 t0
= tcg_const_i32(crb
);
2404 gen_helper_fpscr_clrbit(cpu_env
, t0
);
2405 tcg_temp_free_i32(t0
);
2407 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2408 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2409 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2414 static void gen_mtfsb1(DisasContext
*ctx
)
2418 if (unlikely(!ctx
->fpu_enabled
)) {
2419 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2422 crb
= 31 - crbD(ctx
->opcode
);
2423 gen_reset_fpstatus();
2424 /* XXX: we pretend we can only do IEEE floating-point computations */
2425 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
&& crb
!= FPSCR_NI
)) {
2427 /* NIP cannot be restored if the memory exception comes from an helper */
2428 gen_update_nip(ctx
, ctx
->nip
- 4);
2429 t0
= tcg_const_i32(crb
);
2430 gen_helper_fpscr_setbit(cpu_env
, t0
);
2431 tcg_temp_free_i32(t0
);
2433 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2434 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2435 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2437 /* We can raise a differed exception */
2438 gen_helper_float_check_status(cpu_env
);
2442 static void gen_mtfsf(DisasContext
*ctx
)
2447 if (unlikely(!ctx
->fpu_enabled
)) {
2448 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2451 flm
= FPFLM(ctx
->opcode
);
2452 l
= FPL(ctx
->opcode
);
2453 w
= FPW(ctx
->opcode
);
2454 if (unlikely(w
& !(ctx
->insns_flags2
& PPC2_ISA205
))) {
2455 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2458 /* NIP cannot be restored if the memory exception comes from an helper */
2459 gen_update_nip(ctx
, ctx
->nip
- 4);
2460 gen_reset_fpstatus();
2462 t0
= tcg_const_i32((ctx
->insns_flags2
& PPC2_ISA205
) ? 0xffff : 0xff);
2464 t0
= tcg_const_i32(flm
<< (w
* 8));
2466 gen_helper_store_fpscr(cpu_env
, cpu_fpr
[rB(ctx
->opcode
)], t0
);
2467 tcg_temp_free_i32(t0
);
2468 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2469 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2470 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2472 /* We can raise a differed exception */
2473 gen_helper_float_check_status(cpu_env
);
2477 static void gen_mtfsfi(DisasContext
*ctx
)
2483 if (unlikely(!ctx
->fpu_enabled
)) {
2484 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2487 w
= FPW(ctx
->opcode
);
2488 bf
= FPBF(ctx
->opcode
);
2489 if (unlikely(w
& !(ctx
->insns_flags2
& PPC2_ISA205
))) {
2490 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2493 sh
= (8 * w
) + 7 - bf
;
2494 /* NIP cannot be restored if the memory exception comes from an helper */
2495 gen_update_nip(ctx
, ctx
->nip
- 4);
2496 gen_reset_fpstatus();
2497 t0
= tcg_const_i64(((uint64_t)FPIMM(ctx
->opcode
)) << (4 * sh
));
2498 t1
= tcg_const_i32(1 << sh
);
2499 gen_helper_store_fpscr(cpu_env
, t0
, t1
);
2500 tcg_temp_free_i64(t0
);
2501 tcg_temp_free_i32(t1
);
2502 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2503 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2504 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2506 /* We can raise a differed exception */
2507 gen_helper_float_check_status(cpu_env
);
2510 /*** Addressing modes ***/
2511 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2512 static inline void gen_addr_imm_index(DisasContext
*ctx
, TCGv EA
,
2515 target_long simm
= SIMM(ctx
->opcode
);
2518 if (rA(ctx
->opcode
) == 0) {
2519 if (NARROW_MODE(ctx
)) {
2520 simm
= (uint32_t)simm
;
2522 tcg_gen_movi_tl(EA
, simm
);
2523 } else if (likely(simm
!= 0)) {
2524 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
);
2525 if (NARROW_MODE(ctx
)) {
2526 tcg_gen_ext32u_tl(EA
, EA
);
2529 if (NARROW_MODE(ctx
)) {
2530 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2532 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2537 static inline void gen_addr_reg_index(DisasContext
*ctx
, TCGv EA
)
2539 if (rA(ctx
->opcode
) == 0) {
2540 if (NARROW_MODE(ctx
)) {
2541 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2543 tcg_gen_mov_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2546 tcg_gen_add_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2547 if (NARROW_MODE(ctx
)) {
2548 tcg_gen_ext32u_tl(EA
, EA
);
2553 static inline void gen_addr_register(DisasContext
*ctx
, TCGv EA
)
2555 if (rA(ctx
->opcode
) == 0) {
2556 tcg_gen_movi_tl(EA
, 0);
2557 } else if (NARROW_MODE(ctx
)) {
2558 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2560 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2564 static inline void gen_addr_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
2567 tcg_gen_addi_tl(ret
, arg1
, val
);
2568 if (NARROW_MODE(ctx
)) {
2569 tcg_gen_ext32u_tl(ret
, ret
);
2573 static inline void gen_check_align(DisasContext
*ctx
, TCGv EA
, int mask
)
2575 int l1
= gen_new_label();
2576 TCGv t0
= tcg_temp_new();
2578 /* NIP cannot be restored if the memory exception comes from an helper */
2579 gen_update_nip(ctx
, ctx
->nip
- 4);
2580 tcg_gen_andi_tl(t0
, EA
, mask
);
2581 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2582 t1
= tcg_const_i32(POWERPC_EXCP_ALIGN
);
2583 t2
= tcg_const_i32(0);
2584 gen_helper_raise_exception_err(cpu_env
, t1
, t2
);
2585 tcg_temp_free_i32(t1
);
2586 tcg_temp_free_i32(t2
);
2591 /*** Integer load ***/
2592 static inline void gen_qemu_ld8u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2594 tcg_gen_qemu_ld8u(arg1
, arg2
, ctx
->mem_idx
);
2597 static inline void gen_qemu_ld8s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2599 tcg_gen_qemu_ld8s(arg1
, arg2
, ctx
->mem_idx
);
2602 static inline void gen_qemu_ld16u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2604 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2605 if (unlikely(ctx
->le_mode
)) {
2606 tcg_gen_bswap16_tl(arg1
, arg1
);
2610 static inline void gen_qemu_ld16s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2612 if (unlikely(ctx
->le_mode
)) {
2613 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2614 tcg_gen_bswap16_tl(arg1
, arg1
);
2615 tcg_gen_ext16s_tl(arg1
, arg1
);
2617 tcg_gen_qemu_ld16s(arg1
, arg2
, ctx
->mem_idx
);
2621 static inline void gen_qemu_ld32u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2623 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2624 if (unlikely(ctx
->le_mode
)) {
2625 tcg_gen_bswap32_tl(arg1
, arg1
);
2629 static void gen_qemu_ld32u_i64(DisasContext
*ctx
, TCGv_i64 val
, TCGv addr
)
2631 TCGv tmp
= tcg_temp_new();
2632 gen_qemu_ld32u(ctx
, tmp
, addr
);
2633 tcg_gen_extu_tl_i64(val
, tmp
);
2637 static inline void gen_qemu_ld32s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2639 if (unlikely(ctx
->le_mode
)) {
2640 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2641 tcg_gen_bswap32_tl(arg1
, arg1
);
2642 tcg_gen_ext32s_tl(arg1
, arg1
);
2644 tcg_gen_qemu_ld32s(arg1
, arg2
, ctx
->mem_idx
);
2647 static void gen_qemu_ld32s_i64(DisasContext
*ctx
, TCGv_i64 val
, TCGv addr
)
2649 TCGv tmp
= tcg_temp_new();
2650 gen_qemu_ld32s(ctx
, tmp
, addr
);
2651 tcg_gen_ext_tl_i64(val
, tmp
);
2655 static inline void gen_qemu_ld64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2657 tcg_gen_qemu_ld64(arg1
, arg2
, ctx
->mem_idx
);
2658 if (unlikely(ctx
->le_mode
)) {
2659 tcg_gen_bswap64_i64(arg1
, arg1
);
2663 static inline void gen_qemu_st8(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2665 tcg_gen_qemu_st8(arg1
, arg2
, ctx
->mem_idx
);
2668 static inline void gen_qemu_st16(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2670 if (unlikely(ctx
->le_mode
)) {
2671 TCGv t0
= tcg_temp_new();
2672 tcg_gen_ext16u_tl(t0
, arg1
);
2673 tcg_gen_bswap16_tl(t0
, t0
);
2674 tcg_gen_qemu_st16(t0
, arg2
, ctx
->mem_idx
);
2677 tcg_gen_qemu_st16(arg1
, arg2
, ctx
->mem_idx
);
2681 static inline void gen_qemu_st32(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2683 if (unlikely(ctx
->le_mode
)) {
2684 TCGv t0
= tcg_temp_new();
2685 tcg_gen_ext32u_tl(t0
, arg1
);
2686 tcg_gen_bswap32_tl(t0
, t0
);
2687 tcg_gen_qemu_st32(t0
, arg2
, ctx
->mem_idx
);
2690 tcg_gen_qemu_st32(arg1
, arg2
, ctx
->mem_idx
);
2694 static void gen_qemu_st32_i64(DisasContext
*ctx
, TCGv_i64 val
, TCGv addr
)
2696 TCGv tmp
= tcg_temp_new();
2697 tcg_gen_trunc_i64_tl(tmp
, val
);
2698 gen_qemu_st32(ctx
, tmp
, addr
);
2702 static inline void gen_qemu_st64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2704 if (unlikely(ctx
->le_mode
)) {
2705 TCGv_i64 t0
= tcg_temp_new_i64();
2706 tcg_gen_bswap64_i64(t0
, arg1
);
2707 tcg_gen_qemu_st64(t0
, arg2
, ctx
->mem_idx
);
2708 tcg_temp_free_i64(t0
);
2710 tcg_gen_qemu_st64(arg1
, arg2
, ctx
->mem_idx
);
2713 #define GEN_LD(name, ldop, opc, type) \
2714 static void glue(gen_, name)(DisasContext *ctx) \
2717 gen_set_access_type(ctx, ACCESS_INT); \
2718 EA = tcg_temp_new(); \
2719 gen_addr_imm_index(ctx, EA, 0); \
2720 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2721 tcg_temp_free(EA); \
2724 #define GEN_LDU(name, ldop, opc, type) \
2725 static void glue(gen_, name##u)(DisasContext *ctx) \
2728 if (unlikely(rA(ctx->opcode) == 0 || \
2729 rA(ctx->opcode) == rD(ctx->opcode))) { \
2730 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2733 gen_set_access_type(ctx, ACCESS_INT); \
2734 EA = tcg_temp_new(); \
2735 if (type == PPC_64B) \
2736 gen_addr_imm_index(ctx, EA, 0x03); \
2738 gen_addr_imm_index(ctx, EA, 0); \
2739 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2740 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2741 tcg_temp_free(EA); \
2744 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
2745 static void glue(gen_, name##ux)(DisasContext *ctx) \
2748 if (unlikely(rA(ctx->opcode) == 0 || \
2749 rA(ctx->opcode) == rD(ctx->opcode))) { \
2750 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2753 gen_set_access_type(ctx, ACCESS_INT); \
2754 EA = tcg_temp_new(); \
2755 gen_addr_reg_index(ctx, EA); \
2756 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2757 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2758 tcg_temp_free(EA); \
2761 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
2762 static void glue(gen_, name##x)(DisasContext *ctx) \
2765 gen_set_access_type(ctx, ACCESS_INT); \
2766 EA = tcg_temp_new(); \
2767 gen_addr_reg_index(ctx, EA); \
2768 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2769 tcg_temp_free(EA); \
2771 #define GEN_LDX(name, ldop, opc2, opc3, type) \
2772 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE)
2774 #define GEN_LDS(name, ldop, op, type) \
2775 GEN_LD(name, ldop, op | 0x20, type); \
2776 GEN_LDU(name, ldop, op | 0x21, type); \
2777 GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2778 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
2780 /* lbz lbzu lbzux lbzx */
2781 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
);
2782 /* lha lhau lhaux lhax */
2783 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
);
2784 /* lhz lhzu lhzux lhzx */
2785 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
);
2786 /* lwz lwzu lwzux lwzx */
2787 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
);
2788 #if defined(TARGET_PPC64)
2790 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
);
2792 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
);
2794 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
);
2796 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
);
2798 static void gen_ld(DisasContext
*ctx
)
2801 if (Rc(ctx
->opcode
)) {
2802 if (unlikely(rA(ctx
->opcode
) == 0 ||
2803 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
2804 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2808 gen_set_access_type(ctx
, ACCESS_INT
);
2809 EA
= tcg_temp_new();
2810 gen_addr_imm_index(ctx
, EA
, 0x03);
2811 if (ctx
->opcode
& 0x02) {
2812 /* lwa (lwau is undefined) */
2813 gen_qemu_ld32s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2816 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2818 if (Rc(ctx
->opcode
))
2819 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2824 static void gen_lq(DisasContext
*ctx
)
2826 #if defined(CONFIG_USER_ONLY)
2827 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2832 /* Restore CPU state */
2833 if (unlikely(ctx
->mem_idx
== 0)) {
2834 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2837 ra
= rA(ctx
->opcode
);
2838 rd
= rD(ctx
->opcode
);
2839 if (unlikely((rd
& 1) || rd
== ra
)) {
2840 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2843 if (unlikely(ctx
->le_mode
)) {
2844 /* Little-endian mode is not handled */
2845 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2848 gen_set_access_type(ctx
, ACCESS_INT
);
2849 EA
= tcg_temp_new();
2850 gen_addr_imm_index(ctx
, EA
, 0x0F);
2851 gen_qemu_ld64(ctx
, cpu_gpr
[rd
], EA
);
2852 gen_addr_add(ctx
, EA
, EA
, 8);
2853 gen_qemu_ld64(ctx
, cpu_gpr
[rd
+1], EA
);
2859 /*** Integer store ***/
2860 #define GEN_ST(name, stop, opc, type) \
2861 static void glue(gen_, name)(DisasContext *ctx) \
2864 gen_set_access_type(ctx, ACCESS_INT); \
2865 EA = tcg_temp_new(); \
2866 gen_addr_imm_index(ctx, EA, 0); \
2867 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2868 tcg_temp_free(EA); \
2871 #define GEN_STU(name, stop, opc, type) \
2872 static void glue(gen_, stop##u)(DisasContext *ctx) \
2875 if (unlikely(rA(ctx->opcode) == 0)) { \
2876 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2879 gen_set_access_type(ctx, ACCESS_INT); \
2880 EA = tcg_temp_new(); \
2881 if (type == PPC_64B) \
2882 gen_addr_imm_index(ctx, EA, 0x03); \
2884 gen_addr_imm_index(ctx, EA, 0); \
2885 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2886 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2887 tcg_temp_free(EA); \
2890 #define GEN_STUX(name, stop, opc2, opc3, type) \
2891 static void glue(gen_, name##ux)(DisasContext *ctx) \
2894 if (unlikely(rA(ctx->opcode) == 0)) { \
2895 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2898 gen_set_access_type(ctx, ACCESS_INT); \
2899 EA = tcg_temp_new(); \
2900 gen_addr_reg_index(ctx, EA); \
2901 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2902 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2903 tcg_temp_free(EA); \
2906 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
2907 static void glue(gen_, name##x)(DisasContext *ctx) \
2910 gen_set_access_type(ctx, ACCESS_INT); \
2911 EA = tcg_temp_new(); \
2912 gen_addr_reg_index(ctx, EA); \
2913 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2914 tcg_temp_free(EA); \
2916 #define GEN_STX(name, stop, opc2, opc3, type) \
2917 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE)
2919 #define GEN_STS(name, stop, op, type) \
2920 GEN_ST(name, stop, op | 0x20, type); \
2921 GEN_STU(name, stop, op | 0x21, type); \
2922 GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2923 GEN_STX(name, stop, 0x17, op | 0x00, type)
2925 /* stb stbu stbux stbx */
2926 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
);
2927 /* sth sthu sthux sthx */
2928 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
);
2929 /* stw stwu stwux stwx */
2930 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
);
2931 #if defined(TARGET_PPC64)
2932 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
);
2933 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
);
2935 static void gen_std(DisasContext
*ctx
)
2940 rs
= rS(ctx
->opcode
);
2941 if ((ctx
->opcode
& 0x3) == 0x2) {
2942 #if defined(CONFIG_USER_ONLY)
2943 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2946 if (unlikely(ctx
->mem_idx
== 0)) {
2947 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2950 if (unlikely(rs
& 1)) {
2951 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2954 if (unlikely(ctx
->le_mode
)) {
2955 /* Little-endian mode is not handled */
2956 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2959 gen_set_access_type(ctx
, ACCESS_INT
);
2960 EA
= tcg_temp_new();
2961 gen_addr_imm_index(ctx
, EA
, 0x03);
2962 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
2963 gen_addr_add(ctx
, EA
, EA
, 8);
2964 gen_qemu_st64(ctx
, cpu_gpr
[rs
+1], EA
);
2969 if (Rc(ctx
->opcode
)) {
2970 if (unlikely(rA(ctx
->opcode
) == 0)) {
2971 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2975 gen_set_access_type(ctx
, ACCESS_INT
);
2976 EA
= tcg_temp_new();
2977 gen_addr_imm_index(ctx
, EA
, 0x03);
2978 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
2979 if (Rc(ctx
->opcode
))
2980 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2985 /*** Integer load and store with byte reverse ***/
2987 static inline void gen_qemu_ld16ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2989 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2990 if (likely(!ctx
->le_mode
)) {
2991 tcg_gen_bswap16_tl(arg1
, arg1
);
2994 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
);
2997 static inline void gen_qemu_ld32ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2999 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
3000 if (likely(!ctx
->le_mode
)) {
3001 tcg_gen_bswap32_tl(arg1
, arg1
);
3004 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
);
3006 #if defined(TARGET_PPC64)
3008 static inline void gen_qemu_ld64ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3010 tcg_gen_qemu_ld64(arg1
, arg2
, ctx
->mem_idx
);
3011 if (likely(!ctx
->le_mode
)) {
3012 tcg_gen_bswap64_tl(arg1
, arg1
);
3015 GEN_LDX_E(ldbr
, ld64ur
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
);
3016 #endif /* TARGET_PPC64 */
3019 static inline void gen_qemu_st16r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3021 if (likely(!ctx
->le_mode
)) {
3022 TCGv t0
= tcg_temp_new();
3023 tcg_gen_ext16u_tl(t0
, arg1
);
3024 tcg_gen_bswap16_tl(t0
, t0
);
3025 tcg_gen_qemu_st16(t0
, arg2
, ctx
->mem_idx
);
3028 tcg_gen_qemu_st16(arg1
, arg2
, ctx
->mem_idx
);
3031 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
);
3034 static inline void gen_qemu_st32r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3036 if (likely(!ctx
->le_mode
)) {
3037 TCGv t0
= tcg_temp_new();
3038 tcg_gen_ext32u_tl(t0
, arg1
);
3039 tcg_gen_bswap32_tl(t0
, t0
);
3040 tcg_gen_qemu_st32(t0
, arg2
, ctx
->mem_idx
);
3043 tcg_gen_qemu_st32(arg1
, arg2
, ctx
->mem_idx
);
3046 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
);
3048 #if defined(TARGET_PPC64)
3050 static inline void gen_qemu_st64r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3052 if (likely(!ctx
->le_mode
)) {
3053 TCGv t0
= tcg_temp_new();
3054 tcg_gen_bswap64_tl(t0
, arg1
);
3055 tcg_gen_qemu_st64(t0
, arg2
, ctx
->mem_idx
);
3058 tcg_gen_qemu_st64(arg1
, arg2
, ctx
->mem_idx
);
3061 GEN_STX_E(stdbr
, st64r
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
);
3062 #endif /* TARGET_PPC64 */
3064 /*** Integer load and store multiple ***/
3067 static void gen_lmw(DisasContext
*ctx
)
3071 gen_set_access_type(ctx
, ACCESS_INT
);
3072 /* NIP cannot be restored if the memory exception comes from an helper */
3073 gen_update_nip(ctx
, ctx
->nip
- 4);
3074 t0
= tcg_temp_new();
3075 t1
= tcg_const_i32(rD(ctx
->opcode
));
3076 gen_addr_imm_index(ctx
, t0
, 0);
3077 gen_helper_lmw(cpu_env
, t0
, t1
);
3079 tcg_temp_free_i32(t1
);
3083 static void gen_stmw(DisasContext
*ctx
)
3087 gen_set_access_type(ctx
, ACCESS_INT
);
3088 /* NIP cannot be restored if the memory exception comes from an helper */
3089 gen_update_nip(ctx
, ctx
->nip
- 4);
3090 t0
= tcg_temp_new();
3091 t1
= tcg_const_i32(rS(ctx
->opcode
));
3092 gen_addr_imm_index(ctx
, t0
, 0);
3093 gen_helper_stmw(cpu_env
, t0
, t1
);
3095 tcg_temp_free_i32(t1
);
3098 /*** Integer load and store strings ***/
3101 /* PowerPC32 specification says we must generate an exception if
3102 * rA is in the range of registers to be loaded.
3103 * In an other hand, IBM says this is valid, but rA won't be loaded.
3104 * For now, I'll follow the spec...
3106 static void gen_lswi(DisasContext
*ctx
)
3110 int nb
= NB(ctx
->opcode
);
3111 int start
= rD(ctx
->opcode
);
3112 int ra
= rA(ctx
->opcode
);
3118 if (unlikely(((start
+ nr
) > 32 &&
3119 start
<= ra
&& (start
+ nr
- 32) > ra
) ||
3120 ((start
+ nr
) <= 32 && start
<= ra
&& (start
+ nr
) > ra
))) {
3121 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
3124 gen_set_access_type(ctx
, ACCESS_INT
);
3125 /* NIP cannot be restored if the memory exception comes from an helper */
3126 gen_update_nip(ctx
, ctx
->nip
- 4);
3127 t0
= tcg_temp_new();
3128 gen_addr_register(ctx
, t0
);
3129 t1
= tcg_const_i32(nb
);
3130 t2
= tcg_const_i32(start
);
3131 gen_helper_lsw(cpu_env
, t0
, t1
, t2
);
3133 tcg_temp_free_i32(t1
);
3134 tcg_temp_free_i32(t2
);
3138 static void gen_lswx(DisasContext
*ctx
)
3141 TCGv_i32 t1
, t2
, t3
;
3142 gen_set_access_type(ctx
, ACCESS_INT
);
3143 /* NIP cannot be restored if the memory exception comes from an helper */
3144 gen_update_nip(ctx
, ctx
->nip
- 4);
3145 t0
= tcg_temp_new();
3146 gen_addr_reg_index(ctx
, t0
);
3147 t1
= tcg_const_i32(rD(ctx
->opcode
));
3148 t2
= tcg_const_i32(rA(ctx
->opcode
));
3149 t3
= tcg_const_i32(rB(ctx
->opcode
));
3150 gen_helper_lswx(cpu_env
, t0
, t1
, t2
, t3
);
3152 tcg_temp_free_i32(t1
);
3153 tcg_temp_free_i32(t2
);
3154 tcg_temp_free_i32(t3
);
3158 static void gen_stswi(DisasContext
*ctx
)
3162 int nb
= NB(ctx
->opcode
);
3163 gen_set_access_type(ctx
, ACCESS_INT
);
3164 /* NIP cannot be restored if the memory exception comes from an helper */
3165 gen_update_nip(ctx
, ctx
->nip
- 4);
3166 t0
= tcg_temp_new();
3167 gen_addr_register(ctx
, t0
);
3170 t1
= tcg_const_i32(nb
);
3171 t2
= tcg_const_i32(rS(ctx
->opcode
));
3172 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3174 tcg_temp_free_i32(t1
);
3175 tcg_temp_free_i32(t2
);
3179 static void gen_stswx(DisasContext
*ctx
)
3183 gen_set_access_type(ctx
, ACCESS_INT
);
3184 /* NIP cannot be restored if the memory exception comes from an helper */
3185 gen_update_nip(ctx
, ctx
->nip
- 4);
3186 t0
= tcg_temp_new();
3187 gen_addr_reg_index(ctx
, t0
);
3188 t1
= tcg_temp_new_i32();
3189 tcg_gen_trunc_tl_i32(t1
, cpu_xer
);
3190 tcg_gen_andi_i32(t1
, t1
, 0x7F);
3191 t2
= tcg_const_i32(rS(ctx
->opcode
));
3192 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3194 tcg_temp_free_i32(t1
);
3195 tcg_temp_free_i32(t2
);
3198 /*** Memory synchronisation ***/
3200 static void gen_eieio(DisasContext
*ctx
)
3205 static void gen_isync(DisasContext
*ctx
)
3207 gen_stop_exception(ctx
);
3210 #define LARX(name, len, loadop) \
3211 static void gen_##name(DisasContext *ctx) \
3214 TCGv gpr = cpu_gpr[rD(ctx->opcode)]; \
3215 gen_set_access_type(ctx, ACCESS_RES); \
3216 t0 = tcg_temp_local_new(); \
3217 gen_addr_reg_index(ctx, t0); \
3219 gen_check_align(ctx, t0, (len)-1); \
3221 gen_qemu_##loadop(ctx, gpr, t0); \
3222 tcg_gen_mov_tl(cpu_reserve, t0); \
3223 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); \
3224 tcg_temp_free(t0); \
3228 LARX(lbarx
, 1, ld8u
);
3229 LARX(lharx
, 2, ld16u
);
3230 LARX(lwarx
, 4, ld32u
);
3233 #if defined(CONFIG_USER_ONLY)
3234 static void gen_conditional_store(DisasContext
*ctx
, TCGv EA
,
3237 TCGv t0
= tcg_temp_new();
3238 uint32_t save_exception
= ctx
->exception
;
3240 tcg_gen_st_tl(EA
, cpu_env
, offsetof(CPUPPCState
, reserve_ea
));
3241 tcg_gen_movi_tl(t0
, (size
<< 5) | reg
);
3242 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, reserve_info
));
3244 gen_update_nip(ctx
, ctx
->nip
-4);
3245 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3246 gen_exception(ctx
, POWERPC_EXCP_STCX
);
3247 ctx
->exception
= save_exception
;
3250 static void gen_conditional_store(DisasContext
*ctx
, TCGv EA
,
3255 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
3256 l1
= gen_new_label();
3257 tcg_gen_brcond_tl(TCG_COND_NE
, EA
, cpu_reserve
, l1
);
3258 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3259 #if defined(TARGET_PPC64)
3261 gen_qemu_st64(ctx
, cpu_gpr
[reg
], EA
);
3265 gen_qemu_st32(ctx
, cpu_gpr
[reg
], EA
);
3266 } else if (size
== 2) {
3267 gen_qemu_st16(ctx
, cpu_gpr
[reg
], EA
);
3269 gen_qemu_st8(ctx
, cpu_gpr
[reg
], EA
);
3272 tcg_gen_movi_tl(cpu_reserve
, -1);
3276 #define STCX(name, len) \
3277 static void gen_##name(DisasContext *ctx) \
3280 gen_set_access_type(ctx, ACCESS_RES); \
3281 t0 = tcg_temp_local_new(); \
3282 gen_addr_reg_index(ctx, t0); \
3284 gen_check_align(ctx, t0, (len)-1); \
3286 gen_conditional_store(ctx, t0, rS(ctx->opcode), len); \
3287 tcg_temp_free(t0); \
3294 #if defined(TARGET_PPC64)
3296 LARX(ldarx
, 8, ld64
);
3300 #endif /* defined(TARGET_PPC64) */
3303 static void gen_sync(DisasContext
*ctx
)
3308 static void gen_wait(DisasContext
*ctx
)
3310 TCGv_i32 t0
= tcg_temp_new_i32();
3311 tcg_gen_st_i32(t0
, cpu_env
,
3312 -offsetof(PowerPCCPU
, env
) + offsetof(CPUState
, halted
));
3313 tcg_temp_free_i32(t0
);
3314 /* Stop translation, as the CPU is supposed to sleep from now */
3315 gen_exception_err(ctx
, EXCP_HLT
, 1);
3318 /*** Floating-point load ***/
3319 #define GEN_LDF(name, ldop, opc, type) \
3320 static void glue(gen_, name)(DisasContext *ctx) \
3323 if (unlikely(!ctx->fpu_enabled)) { \
3324 gen_exception(ctx, POWERPC_EXCP_FPU); \
3327 gen_set_access_type(ctx, ACCESS_FLOAT); \
3328 EA = tcg_temp_new(); \
3329 gen_addr_imm_index(ctx, EA, 0); \
3330 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3331 tcg_temp_free(EA); \
3334 #define GEN_LDUF(name, ldop, opc, type) \
3335 static void glue(gen_, name##u)(DisasContext *ctx) \
3338 if (unlikely(!ctx->fpu_enabled)) { \
3339 gen_exception(ctx, POWERPC_EXCP_FPU); \
3342 if (unlikely(rA(ctx->opcode) == 0)) { \
3343 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3346 gen_set_access_type(ctx, ACCESS_FLOAT); \
3347 EA = tcg_temp_new(); \
3348 gen_addr_imm_index(ctx, EA, 0); \
3349 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3350 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3351 tcg_temp_free(EA); \
3354 #define GEN_LDUXF(name, ldop, opc, type) \
3355 static void glue(gen_, name##ux)(DisasContext *ctx) \
3358 if (unlikely(!ctx->fpu_enabled)) { \
3359 gen_exception(ctx, POWERPC_EXCP_FPU); \
3362 if (unlikely(rA(ctx->opcode) == 0)) { \
3363 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3366 gen_set_access_type(ctx, ACCESS_FLOAT); \
3367 EA = tcg_temp_new(); \
3368 gen_addr_reg_index(ctx, EA); \
3369 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3370 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3371 tcg_temp_free(EA); \
3374 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
3375 static void glue(gen_, name##x)(DisasContext *ctx) \
3378 if (unlikely(!ctx->fpu_enabled)) { \
3379 gen_exception(ctx, POWERPC_EXCP_FPU); \
3382 gen_set_access_type(ctx, ACCESS_FLOAT); \
3383 EA = tcg_temp_new(); \
3384 gen_addr_reg_index(ctx, EA); \
3385 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3386 tcg_temp_free(EA); \
3389 #define GEN_LDFS(name, ldop, op, type) \
3390 GEN_LDF(name, ldop, op | 0x20, type); \
3391 GEN_LDUF(name, ldop, op | 0x21, type); \
3392 GEN_LDUXF(name, ldop, op | 0x01, type); \
3393 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3395 static inline void gen_qemu_ld32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3397 TCGv t0
= tcg_temp_new();
3398 TCGv_i32 t1
= tcg_temp_new_i32();
3399 gen_qemu_ld32u(ctx
, t0
, arg2
);
3400 tcg_gen_trunc_tl_i32(t1
, t0
);
3402 gen_helper_float32_to_float64(arg1
, cpu_env
, t1
);
3403 tcg_temp_free_i32(t1
);
3406 /* lfd lfdu lfdux lfdx */
3407 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
);
3408 /* lfs lfsu lfsux lfsx */
3409 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
);
3412 static void gen_lfdp(DisasContext
*ctx
)
3415 if (unlikely(!ctx
->fpu_enabled
)) {
3416 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3419 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3420 EA
= tcg_temp_new();
3421 gen_addr_imm_index(ctx
, EA
, 0); \
3422 if (unlikely(ctx
->le_mode
)) {
3423 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3424 tcg_gen_addi_tl(EA
, EA
, 8);
3425 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3427 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3428 tcg_gen_addi_tl(EA
, EA
, 8);
3429 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3435 static void gen_lfdpx(DisasContext
*ctx
)
3438 if (unlikely(!ctx
->fpu_enabled
)) {
3439 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3442 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3443 EA
= tcg_temp_new();
3444 gen_addr_reg_index(ctx
, EA
);
3445 if (unlikely(ctx
->le_mode
)) {
3446 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3447 tcg_gen_addi_tl(EA
, EA
, 8);
3448 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3450 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3451 tcg_gen_addi_tl(EA
, EA
, 8);
3452 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3458 static void gen_lfiwax(DisasContext
*ctx
)
3462 if (unlikely(!ctx
->fpu_enabled
)) {
3463 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3466 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3467 EA
= tcg_temp_new();
3468 t0
= tcg_temp_new();
3469 gen_addr_reg_index(ctx
, EA
);
3470 gen_qemu_ld32s(ctx
, t0
, EA
);
3471 tcg_gen_ext_tl_i64(cpu_fpr
[rD(ctx
->opcode
)], t0
);
3476 /*** Floating-point store ***/
3477 #define GEN_STF(name, stop, opc, type) \
3478 static void glue(gen_, name)(DisasContext *ctx) \
3481 if (unlikely(!ctx->fpu_enabled)) { \
3482 gen_exception(ctx, POWERPC_EXCP_FPU); \
3485 gen_set_access_type(ctx, ACCESS_FLOAT); \
3486 EA = tcg_temp_new(); \
3487 gen_addr_imm_index(ctx, EA, 0); \
3488 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3489 tcg_temp_free(EA); \
3492 #define GEN_STUF(name, stop, opc, type) \
3493 static void glue(gen_, name##u)(DisasContext *ctx) \
3496 if (unlikely(!ctx->fpu_enabled)) { \
3497 gen_exception(ctx, POWERPC_EXCP_FPU); \
3500 if (unlikely(rA(ctx->opcode) == 0)) { \
3501 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3504 gen_set_access_type(ctx, ACCESS_FLOAT); \
3505 EA = tcg_temp_new(); \
3506 gen_addr_imm_index(ctx, EA, 0); \
3507 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3508 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3509 tcg_temp_free(EA); \
3512 #define GEN_STUXF(name, stop, opc, type) \
3513 static void glue(gen_, name##ux)(DisasContext *ctx) \
3516 if (unlikely(!ctx->fpu_enabled)) { \
3517 gen_exception(ctx, POWERPC_EXCP_FPU); \
3520 if (unlikely(rA(ctx->opcode) == 0)) { \
3521 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3524 gen_set_access_type(ctx, ACCESS_FLOAT); \
3525 EA = tcg_temp_new(); \
3526 gen_addr_reg_index(ctx, EA); \
3527 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3528 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3529 tcg_temp_free(EA); \
3532 #define GEN_STXF(name, stop, opc2, opc3, type) \
3533 static void glue(gen_, name##x)(DisasContext *ctx) \
3536 if (unlikely(!ctx->fpu_enabled)) { \
3537 gen_exception(ctx, POWERPC_EXCP_FPU); \
3540 gen_set_access_type(ctx, ACCESS_FLOAT); \
3541 EA = tcg_temp_new(); \
3542 gen_addr_reg_index(ctx, EA); \
3543 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3544 tcg_temp_free(EA); \
3547 #define GEN_STFS(name, stop, op, type) \
3548 GEN_STF(name, stop, op | 0x20, type); \
3549 GEN_STUF(name, stop, op | 0x21, type); \
3550 GEN_STUXF(name, stop, op | 0x01, type); \
3551 GEN_STXF(name, stop, 0x17, op | 0x00, type)
3553 static inline void gen_qemu_st32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3555 TCGv_i32 t0
= tcg_temp_new_i32();
3556 TCGv t1
= tcg_temp_new();
3557 gen_helper_float64_to_float32(t0
, cpu_env
, arg1
);
3558 tcg_gen_extu_i32_tl(t1
, t0
);
3559 tcg_temp_free_i32(t0
);
3560 gen_qemu_st32(ctx
, t1
, arg2
);
3564 /* stfd stfdu stfdux stfdx */
3565 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
);
3566 /* stfs stfsu stfsux stfsx */
3567 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
);
3570 static void gen_stfdp(DisasContext
*ctx
)
3573 if (unlikely(!ctx
->fpu_enabled
)) {
3574 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3577 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3578 EA
= tcg_temp_new();
3579 gen_addr_imm_index(ctx
, EA
, 0); \
3580 if (unlikely(ctx
->le_mode
)) {
3581 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3582 tcg_gen_addi_tl(EA
, EA
, 8);
3583 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3585 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3586 tcg_gen_addi_tl(EA
, EA
, 8);
3587 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3593 static void gen_stfdpx(DisasContext
*ctx
)
3596 if (unlikely(!ctx
->fpu_enabled
)) {
3597 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3600 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3601 EA
= tcg_temp_new();
3602 gen_addr_reg_index(ctx
, EA
);
3603 if (unlikely(ctx
->le_mode
)) {
3604 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3605 tcg_gen_addi_tl(EA
, EA
, 8);
3606 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3608 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3609 tcg_gen_addi_tl(EA
, EA
, 8);
3610 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3616 static inline void gen_qemu_st32fiw(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3618 TCGv t0
= tcg_temp_new();
3619 tcg_gen_trunc_i64_tl(t0
, arg1
),
3620 gen_qemu_st32(ctx
, t0
, arg2
);
3624 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
);
3626 static inline void gen_update_cfar(DisasContext
*ctx
, target_ulong nip
)
3628 #if defined(TARGET_PPC64)
3630 tcg_gen_movi_tl(cpu_cfar
, nip
);
3635 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
3637 TranslationBlock
*tb
;
3639 if (NARROW_MODE(ctx
)) {
3640 dest
= (uint32_t) dest
;
3642 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
3643 likely(!ctx
->singlestep_enabled
)) {
3645 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3646 tcg_gen_exit_tb((uintptr_t)tb
+ n
);
3648 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3649 if (unlikely(ctx
->singlestep_enabled
)) {
3650 if ((ctx
->singlestep_enabled
&
3651 (CPU_BRANCH_STEP
| CPU_SINGLE_STEP
)) &&
3652 (ctx
->exception
== POWERPC_EXCP_BRANCH
||
3653 ctx
->exception
== POWERPC_EXCP_TRACE
)) {
3654 target_ulong tmp
= ctx
->nip
;
3656 gen_exception(ctx
, POWERPC_EXCP_TRACE
);
3659 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
3660 gen_debug_exception(ctx
);
3667 static inline void gen_setlr(DisasContext
*ctx
, target_ulong nip
)
3669 if (NARROW_MODE(ctx
)) {
3670 nip
= (uint32_t)nip
;
3672 tcg_gen_movi_tl(cpu_lr
, nip
);
3676 static void gen_b(DisasContext
*ctx
)
3678 target_ulong li
, target
;
3680 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3681 /* sign extend LI */
3682 li
= LI(ctx
->opcode
);
3683 li
= (li
^ 0x02000000) - 0x02000000;
3684 if (likely(AA(ctx
->opcode
) == 0)) {
3685 target
= ctx
->nip
+ li
- 4;
3689 if (LK(ctx
->opcode
)) {
3690 gen_setlr(ctx
, ctx
->nip
);
3692 gen_update_cfar(ctx
, ctx
->nip
);
3693 gen_goto_tb(ctx
, 0, target
);
3700 static inline void gen_bcond(DisasContext
*ctx
, int type
)
3702 uint32_t bo
= BO(ctx
->opcode
);
3706 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3707 if (type
== BCOND_LR
|| type
== BCOND_CTR
) {
3708 target
= tcg_temp_local_new();
3709 if (type
== BCOND_CTR
)
3710 tcg_gen_mov_tl(target
, cpu_ctr
);
3712 tcg_gen_mov_tl(target
, cpu_lr
);
3714 TCGV_UNUSED(target
);
3716 if (LK(ctx
->opcode
))
3717 gen_setlr(ctx
, ctx
->nip
);
3718 l1
= gen_new_label();
3719 if ((bo
& 0x4) == 0) {
3720 /* Decrement and test CTR */
3721 TCGv temp
= tcg_temp_new();
3722 if (unlikely(type
== BCOND_CTR
)) {
3723 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3726 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
3727 if (NARROW_MODE(ctx
)) {
3728 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
3730 tcg_gen_mov_tl(temp
, cpu_ctr
);
3733 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
3735 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
3737 tcg_temp_free(temp
);
3739 if ((bo
& 0x10) == 0) {
3741 uint32_t bi
= BI(ctx
->opcode
);
3742 uint32_t mask
= 1 << (3 - (bi
& 0x03));
3743 TCGv_i32 temp
= tcg_temp_new_i32();
3746 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3747 tcg_gen_brcondi_i32(TCG_COND_EQ
, temp
, 0, l1
);
3749 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3750 tcg_gen_brcondi_i32(TCG_COND_NE
, temp
, 0, l1
);
3752 tcg_temp_free_i32(temp
);
3754 gen_update_cfar(ctx
, ctx
->nip
);
3755 if (type
== BCOND_IM
) {
3756 target_ulong li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
3757 if (likely(AA(ctx
->opcode
) == 0)) {
3758 gen_goto_tb(ctx
, 0, ctx
->nip
+ li
- 4);
3760 gen_goto_tb(ctx
, 0, li
);
3763 gen_goto_tb(ctx
, 1, ctx
->nip
);
3765 if (NARROW_MODE(ctx
)) {
3766 tcg_gen_andi_tl(cpu_nip
, target
, (uint32_t)~3);
3768 tcg_gen_andi_tl(cpu_nip
, target
, ~3);
3772 gen_update_nip(ctx
, ctx
->nip
);
3777 static void gen_bc(DisasContext
*ctx
)
3779 gen_bcond(ctx
, BCOND_IM
);
3782 static void gen_bcctr(DisasContext
*ctx
)
3784 gen_bcond(ctx
, BCOND_CTR
);
3787 static void gen_bclr(DisasContext
*ctx
)
3789 gen_bcond(ctx
, BCOND_LR
);
3792 /*** Condition register logical ***/
3793 #define GEN_CRLOGIC(name, tcg_op, opc) \
3794 static void glue(gen_, name)(DisasContext *ctx) \
3799 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3800 t0 = tcg_temp_new_i32(); \
3802 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
3804 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
3806 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
3807 t1 = tcg_temp_new_i32(); \
3808 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3810 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
3812 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
3814 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3815 tcg_op(t0, t0, t1); \
3816 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
3817 tcg_gen_andi_i32(t0, t0, bitmask); \
3818 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3819 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
3820 tcg_temp_free_i32(t0); \
3821 tcg_temp_free_i32(t1); \
3825 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08);
3827 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04);
3829 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09);
3831 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07);
3833 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01);
3835 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E);
3837 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D);
3839 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06);
3842 static void gen_mcrf(DisasContext
*ctx
)
3844 tcg_gen_mov_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfS(ctx
->opcode
)]);
3847 /*** System linkage ***/
3849 /* rfi (mem_idx only) */
3850 static void gen_rfi(DisasContext
*ctx
)
3852 #if defined(CONFIG_USER_ONLY)
3853 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3855 /* Restore CPU state */
3856 if (unlikely(!ctx
->mem_idx
)) {
3857 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3860 gen_update_cfar(ctx
, ctx
->nip
);
3861 gen_helper_rfi(cpu_env
);
3862 gen_sync_exception(ctx
);
3866 #if defined(TARGET_PPC64)
3867 static void gen_rfid(DisasContext
*ctx
)
3869 #if defined(CONFIG_USER_ONLY)
3870 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3872 /* Restore CPU state */
3873 if (unlikely(!ctx
->mem_idx
)) {
3874 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3877 gen_update_cfar(ctx
, ctx
->nip
);
3878 gen_helper_rfid(cpu_env
);
3879 gen_sync_exception(ctx
);
3883 static void gen_hrfid(DisasContext
*ctx
)
3885 #if defined(CONFIG_USER_ONLY)
3886 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3888 /* Restore CPU state */
3889 if (unlikely(ctx
->mem_idx
<= 1)) {
3890 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3893 gen_helper_hrfid(cpu_env
);
3894 gen_sync_exception(ctx
);
3900 #if defined(CONFIG_USER_ONLY)
3901 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3903 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3905 static void gen_sc(DisasContext
*ctx
)
3909 lev
= (ctx
->opcode
>> 5) & 0x7F;
3910 gen_exception_err(ctx
, POWERPC_SYSCALL
, lev
);
3916 static void gen_tw(DisasContext
*ctx
)
3918 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3919 /* Update the nip since this might generate a trap exception */
3920 gen_update_nip(ctx
, ctx
->nip
);
3921 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
3923 tcg_temp_free_i32(t0
);
3927 static void gen_twi(DisasContext
*ctx
)
3929 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3930 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
3931 /* Update the nip since this might generate a trap exception */
3932 gen_update_nip(ctx
, ctx
->nip
);
3933 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3935 tcg_temp_free_i32(t1
);
3938 #if defined(TARGET_PPC64)
3940 static void gen_td(DisasContext
*ctx
)
3942 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3943 /* Update the nip since this might generate a trap exception */
3944 gen_update_nip(ctx
, ctx
->nip
);
3945 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
3947 tcg_temp_free_i32(t0
);
3951 static void gen_tdi(DisasContext
*ctx
)
3953 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3954 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
3955 /* Update the nip since this might generate a trap exception */
3956 gen_update_nip(ctx
, ctx
->nip
);
3957 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3959 tcg_temp_free_i32(t1
);
3963 /*** Processor control ***/
3965 static void gen_read_xer(TCGv dst
)
3967 TCGv t0
= tcg_temp_new();
3968 TCGv t1
= tcg_temp_new();
3969 TCGv t2
= tcg_temp_new();
3970 tcg_gen_mov_tl(dst
, cpu_xer
);
3971 tcg_gen_shli_tl(t0
, cpu_so
, XER_SO
);
3972 tcg_gen_shli_tl(t1
, cpu_ov
, XER_OV
);
3973 tcg_gen_shli_tl(t2
, cpu_ca
, XER_CA
);
3974 tcg_gen_or_tl(t0
, t0
, t1
);
3975 tcg_gen_or_tl(dst
, dst
, t2
);
3976 tcg_gen_or_tl(dst
, dst
, t0
);
3982 static void gen_write_xer(TCGv src
)
3984 tcg_gen_andi_tl(cpu_xer
, src
,
3985 ~((1u << XER_SO
) | (1u << XER_OV
) | (1u << XER_CA
)));
3986 tcg_gen_shri_tl(cpu_so
, src
, XER_SO
);
3987 tcg_gen_shri_tl(cpu_ov
, src
, XER_OV
);
3988 tcg_gen_shri_tl(cpu_ca
, src
, XER_CA
);
3989 tcg_gen_andi_tl(cpu_so
, cpu_so
, 1);
3990 tcg_gen_andi_tl(cpu_ov
, cpu_ov
, 1);
3991 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
3995 static void gen_mcrxr(DisasContext
*ctx
)
3997 TCGv_i32 t0
= tcg_temp_new_i32();
3998 TCGv_i32 t1
= tcg_temp_new_i32();
3999 TCGv_i32 dst
= cpu_crf
[crfD(ctx
->opcode
)];
4001 tcg_gen_trunc_tl_i32(t0
, cpu_so
);
4002 tcg_gen_trunc_tl_i32(t1
, cpu_ov
);
4003 tcg_gen_trunc_tl_i32(dst
, cpu_ca
);
4004 tcg_gen_shri_i32(t0
, t0
, 2);
4005 tcg_gen_shri_i32(t1
, t1
, 1);
4006 tcg_gen_or_i32(dst
, dst
, t0
);
4007 tcg_gen_or_i32(dst
, dst
, t1
);
4008 tcg_temp_free_i32(t0
);
4009 tcg_temp_free_i32(t1
);
4011 tcg_gen_movi_tl(cpu_so
, 0);
4012 tcg_gen_movi_tl(cpu_ov
, 0);
4013 tcg_gen_movi_tl(cpu_ca
, 0);
4017 static void gen_mfcr(DisasContext
*ctx
)
4021 if (likely(ctx
->opcode
& 0x00100000)) {
4022 crm
= CRM(ctx
->opcode
);
4023 if (likely(crm
&& ((crm
& (crm
- 1)) == 0))) {
4025 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_crf
[7 - crn
]);
4026 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)],
4027 cpu_gpr
[rD(ctx
->opcode
)], crn
* 4);
4030 TCGv_i32 t0
= tcg_temp_new_i32();
4031 tcg_gen_mov_i32(t0
, cpu_crf
[0]);
4032 tcg_gen_shli_i32(t0
, t0
, 4);
4033 tcg_gen_or_i32(t0
, t0
, cpu_crf
[1]);
4034 tcg_gen_shli_i32(t0
, t0
, 4);
4035 tcg_gen_or_i32(t0
, t0
, cpu_crf
[2]);
4036 tcg_gen_shli_i32(t0
, t0
, 4);
4037 tcg_gen_or_i32(t0
, t0
, cpu_crf
[3]);
4038 tcg_gen_shli_i32(t0
, t0
, 4);
4039 tcg_gen_or_i32(t0
, t0
, cpu_crf
[4]);
4040 tcg_gen_shli_i32(t0
, t0
, 4);
4041 tcg_gen_or_i32(t0
, t0
, cpu_crf
[5]);
4042 tcg_gen_shli_i32(t0
, t0
, 4);
4043 tcg_gen_or_i32(t0
, t0
, cpu_crf
[6]);
4044 tcg_gen_shli_i32(t0
, t0
, 4);
4045 tcg_gen_or_i32(t0
, t0
, cpu_crf
[7]);
4046 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4047 tcg_temp_free_i32(t0
);
4052 static void gen_mfmsr(DisasContext
*ctx
)
4054 #if defined(CONFIG_USER_ONLY)
4055 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4057 if (unlikely(!ctx
->mem_idx
)) {
4058 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4061 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_msr
);
4065 static void spr_noaccess(void *opaque
, int gprn
, int sprn
)
4068 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
4069 printf("ERROR: try to access SPR %d !\n", sprn
);
4072 #define SPR_NOACCESS (&spr_noaccess)
4075 static inline void gen_op_mfspr(DisasContext
*ctx
)
4077 void (*read_cb
)(void *opaque
, int gprn
, int sprn
);
4078 uint32_t sprn
= SPR(ctx
->opcode
);
4080 #if !defined(CONFIG_USER_ONLY)
4081 if (ctx
->mem_idx
== 2)
4082 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
4083 else if (ctx
->mem_idx
)
4084 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
4087 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
4088 if (likely(read_cb
!= NULL
)) {
4089 if (likely(read_cb
!= SPR_NOACCESS
)) {
4090 (*read_cb
)(ctx
, rD(ctx
->opcode
), sprn
);
4092 /* Privilege exception */
4093 /* This is a hack to avoid warnings when running Linux:
4094 * this OS breaks the PowerPC virtualisation model,
4095 * allowing userland application to read the PVR
4097 if (sprn
!= SPR_PVR
) {
4098 qemu_log("Trying to read privileged spr %d (0x%03x) at "
4099 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4100 printf("Trying to read privileged spr %d (0x%03x) at "
4101 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4103 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4107 qemu_log("Trying to read invalid spr %d (0x%03x) at "
4108 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4109 printf("Trying to read invalid spr %d (0x%03x) at "
4110 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4111 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4115 static void gen_mfspr(DisasContext
*ctx
)
4121 static void gen_mftb(DisasContext
*ctx
)
4127 static void gen_mtcrf(DisasContext
*ctx
)
4131 crm
= CRM(ctx
->opcode
);
4132 if (likely((ctx
->opcode
& 0x00100000))) {
4133 if (crm
&& ((crm
& (crm
- 1)) == 0)) {
4134 TCGv_i32 temp
= tcg_temp_new_i32();
4136 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
4137 tcg_gen_shri_i32(temp
, temp
, crn
* 4);
4138 tcg_gen_andi_i32(cpu_crf
[7 - crn
], temp
, 0xf);
4139 tcg_temp_free_i32(temp
);
4142 TCGv_i32 temp
= tcg_temp_new_i32();
4143 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
4144 for (crn
= 0 ; crn
< 8 ; crn
++) {
4145 if (crm
& (1 << crn
)) {
4146 tcg_gen_shri_i32(cpu_crf
[7 - crn
], temp
, crn
* 4);
4147 tcg_gen_andi_i32(cpu_crf
[7 - crn
], cpu_crf
[7 - crn
], 0xf);
4150 tcg_temp_free_i32(temp
);
4155 #if defined(TARGET_PPC64)
4156 static void gen_mtmsrd(DisasContext
*ctx
)
4158 #if defined(CONFIG_USER_ONLY)
4159 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4161 if (unlikely(!ctx
->mem_idx
)) {
4162 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4165 if (ctx
->opcode
& 0x00010000) {
4166 /* Special form that does not need any synchronisation */
4167 TCGv t0
= tcg_temp_new();
4168 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
4169 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
4170 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
4173 /* XXX: we need to update nip before the store
4174 * if we enter power saving mode, we will exit the loop
4175 * directly from ppc_store_msr
4177 gen_update_nip(ctx
, ctx
->nip
);
4178 gen_helper_store_msr(cpu_env
, cpu_gpr
[rS(ctx
->opcode
)]);
4179 /* Must stop the translation as machine state (may have) changed */
4180 /* Note that mtmsr is not always defined as context-synchronizing */
4181 gen_stop_exception(ctx
);
4187 static void gen_mtmsr(DisasContext
*ctx
)
4189 #if defined(CONFIG_USER_ONLY)
4190 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4192 if (unlikely(!ctx
->mem_idx
)) {
4193 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4196 if (ctx
->opcode
& 0x00010000) {
4197 /* Special form that does not need any synchronisation */
4198 TCGv t0
= tcg_temp_new();
4199 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
4200 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
4201 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
4204 TCGv msr
= tcg_temp_new();
4206 /* XXX: we need to update nip before the store
4207 * if we enter power saving mode, we will exit the loop
4208 * directly from ppc_store_msr
4210 gen_update_nip(ctx
, ctx
->nip
);
4211 #if defined(TARGET_PPC64)
4212 tcg_gen_deposit_tl(msr
, cpu_msr
, cpu_gpr
[rS(ctx
->opcode
)], 0, 32);
4214 tcg_gen_mov_tl(msr
, cpu_gpr
[rS(ctx
->opcode
)]);
4216 gen_helper_store_msr(cpu_env
, msr
);
4217 /* Must stop the translation as machine state (may have) changed */
4218 /* Note that mtmsr is not always defined as context-synchronizing */
4219 gen_stop_exception(ctx
);
4225 static void gen_mtspr(DisasContext
*ctx
)
4227 void (*write_cb
)(void *opaque
, int sprn
, int gprn
);
4228 uint32_t sprn
= SPR(ctx
->opcode
);
4230 #if !defined(CONFIG_USER_ONLY)
4231 if (ctx
->mem_idx
== 2)
4232 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
4233 else if (ctx
->mem_idx
)
4234 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
4237 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
4238 if (likely(write_cb
!= NULL
)) {
4239 if (likely(write_cb
!= SPR_NOACCESS
)) {
4240 (*write_cb
)(ctx
, sprn
, rS(ctx
->opcode
));
4242 /* Privilege exception */
4243 qemu_log("Trying to write privileged spr %d (0x%03x) at "
4244 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4245 printf("Trying to write privileged spr %d (0x%03x) at "
4246 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4247 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4251 qemu_log("Trying to write invalid spr %d (0x%03x) at "
4252 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4253 printf("Trying to write invalid spr %d (0x%03x) at "
4254 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4255 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4259 /*** Cache management ***/
4262 static void gen_dcbf(DisasContext
*ctx
)
4264 /* XXX: specification says this is treated as a load by the MMU */
4266 gen_set_access_type(ctx
, ACCESS_CACHE
);
4267 t0
= tcg_temp_new();
4268 gen_addr_reg_index(ctx
, t0
);
4269 gen_qemu_ld8u(ctx
, t0
, t0
);
4273 /* dcbi (Supervisor only) */
4274 static void gen_dcbi(DisasContext
*ctx
)
4276 #if defined(CONFIG_USER_ONLY)
4277 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4280 if (unlikely(!ctx
->mem_idx
)) {
4281 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4284 EA
= tcg_temp_new();
4285 gen_set_access_type(ctx
, ACCESS_CACHE
);
4286 gen_addr_reg_index(ctx
, EA
);
4287 val
= tcg_temp_new();
4288 /* XXX: specification says this should be treated as a store by the MMU */
4289 gen_qemu_ld8u(ctx
, val
, EA
);
4290 gen_qemu_st8(ctx
, val
, EA
);
4297 static void gen_dcbst(DisasContext
*ctx
)
4299 /* XXX: specification say this is treated as a load by the MMU */
4301 gen_set_access_type(ctx
, ACCESS_CACHE
);
4302 t0
= tcg_temp_new();
4303 gen_addr_reg_index(ctx
, t0
);
4304 gen_qemu_ld8u(ctx
, t0
, t0
);
4309 static void gen_dcbt(DisasContext
*ctx
)
4311 /* interpreted as no-op */
4312 /* XXX: specification say this is treated as a load by the MMU
4313 * but does not generate any exception
4318 static void gen_dcbtst(DisasContext
*ctx
)
4320 /* interpreted as no-op */
4321 /* XXX: specification say this is treated as a load by the MMU
4322 * but does not generate any exception
4327 static void gen_dcbz(DisasContext
*ctx
)
4330 TCGv_i32 tcgv_is_dcbzl
;
4331 int is_dcbzl
= ctx
->opcode
& 0x00200000 ? 1 : 0;
4333 gen_set_access_type(ctx
, ACCESS_CACHE
);
4334 /* NIP cannot be restored if the memory exception comes from an helper */
4335 gen_update_nip(ctx
, ctx
->nip
- 4);
4336 tcgv_addr
= tcg_temp_new();
4337 tcgv_is_dcbzl
= tcg_const_i32(is_dcbzl
);
4339 gen_addr_reg_index(ctx
, tcgv_addr
);
4340 gen_helper_dcbz(cpu_env
, tcgv_addr
, tcgv_is_dcbzl
);
4342 tcg_temp_free(tcgv_addr
);
4343 tcg_temp_free_i32(tcgv_is_dcbzl
);
4347 static void gen_dst(DisasContext
*ctx
)
4349 if (rA(ctx
->opcode
) == 0) {
4350 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
4352 /* interpreted as no-op */
4357 static void gen_dstst(DisasContext
*ctx
)
4359 if (rA(ctx
->opcode
) == 0) {
4360 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
4362 /* interpreted as no-op */
4368 static void gen_dss(DisasContext
*ctx
)
4370 /* interpreted as no-op */
4374 static void gen_icbi(DisasContext
*ctx
)
4377 gen_set_access_type(ctx
, ACCESS_CACHE
);
4378 /* NIP cannot be restored if the memory exception comes from an helper */
4379 gen_update_nip(ctx
, ctx
->nip
- 4);
4380 t0
= tcg_temp_new();
4381 gen_addr_reg_index(ctx
, t0
);
4382 gen_helper_icbi(cpu_env
, t0
);
4388 static void gen_dcba(DisasContext
*ctx
)
4390 /* interpreted as no-op */
4391 /* XXX: specification say this is treated as a store by the MMU
4392 * but does not generate any exception
4396 /*** Segment register manipulation ***/
4397 /* Supervisor only: */
4400 static void gen_mfsr(DisasContext
*ctx
)
4402 #if defined(CONFIG_USER_ONLY)
4403 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4406 if (unlikely(!ctx
->mem_idx
)) {
4407 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4410 t0
= tcg_const_tl(SR(ctx
->opcode
));
4411 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4417 static void gen_mfsrin(DisasContext
*ctx
)
4419 #if defined(CONFIG_USER_ONLY)
4420 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4423 if (unlikely(!ctx
->mem_idx
)) {
4424 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4427 t0
= tcg_temp_new();
4428 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4429 tcg_gen_andi_tl(t0
, t0
, 0xF);
4430 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4436 static void gen_mtsr(DisasContext
*ctx
)
4438 #if defined(CONFIG_USER_ONLY)
4439 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4442 if (unlikely(!ctx
->mem_idx
)) {
4443 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4446 t0
= tcg_const_tl(SR(ctx
->opcode
));
4447 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4453 static void gen_mtsrin(DisasContext
*ctx
)
4455 #if defined(CONFIG_USER_ONLY)
4456 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4459 if (unlikely(!ctx
->mem_idx
)) {
4460 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4463 t0
= tcg_temp_new();
4464 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4465 tcg_gen_andi_tl(t0
, t0
, 0xF);
4466 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rD(ctx
->opcode
)]);
4471 #if defined(TARGET_PPC64)
4472 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4475 static void gen_mfsr_64b(DisasContext
*ctx
)
4477 #if defined(CONFIG_USER_ONLY)
4478 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4481 if (unlikely(!ctx
->mem_idx
)) {
4482 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4485 t0
= tcg_const_tl(SR(ctx
->opcode
));
4486 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4492 static void gen_mfsrin_64b(DisasContext
*ctx
)
4494 #if defined(CONFIG_USER_ONLY)
4495 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4498 if (unlikely(!ctx
->mem_idx
)) {
4499 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4502 t0
= tcg_temp_new();
4503 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4504 tcg_gen_andi_tl(t0
, t0
, 0xF);
4505 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4511 static void gen_mtsr_64b(DisasContext
*ctx
)
4513 #if defined(CONFIG_USER_ONLY)
4514 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4517 if (unlikely(!ctx
->mem_idx
)) {
4518 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4521 t0
= tcg_const_tl(SR(ctx
->opcode
));
4522 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4528 static void gen_mtsrin_64b(DisasContext
*ctx
)
4530 #if defined(CONFIG_USER_ONLY)
4531 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4534 if (unlikely(!ctx
->mem_idx
)) {
4535 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4538 t0
= tcg_temp_new();
4539 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4540 tcg_gen_andi_tl(t0
, t0
, 0xF);
4541 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4547 static void gen_slbmte(DisasContext
*ctx
)
4549 #if defined(CONFIG_USER_ONLY)
4550 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4552 if (unlikely(!ctx
->mem_idx
)) {
4553 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4556 gen_helper_store_slb(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)],
4557 cpu_gpr
[rS(ctx
->opcode
)]);
4561 static void gen_slbmfee(DisasContext
*ctx
)
4563 #if defined(CONFIG_USER_ONLY)
4564 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4566 if (unlikely(!ctx
->mem_idx
)) {
4567 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4570 gen_helper_load_slb_esid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4571 cpu_gpr
[rB(ctx
->opcode
)]);
4575 static void gen_slbmfev(DisasContext
*ctx
)
4577 #if defined(CONFIG_USER_ONLY)
4578 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4580 if (unlikely(!ctx
->mem_idx
)) {
4581 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4584 gen_helper_load_slb_vsid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4585 cpu_gpr
[rB(ctx
->opcode
)]);
4588 #endif /* defined(TARGET_PPC64) */
4590 /*** Lookaside buffer management ***/
4591 /* Optional & mem_idx only: */
4594 static void gen_tlbia(DisasContext
*ctx
)
4596 #if defined(CONFIG_USER_ONLY)
4597 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4599 if (unlikely(!ctx
->mem_idx
)) {
4600 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4603 gen_helper_tlbia(cpu_env
);
4608 static void gen_tlbiel(DisasContext
*ctx
)
4610 #if defined(CONFIG_USER_ONLY)
4611 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4613 if (unlikely(!ctx
->mem_idx
)) {
4614 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4617 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4622 static void gen_tlbie(DisasContext
*ctx
)
4624 #if defined(CONFIG_USER_ONLY)
4625 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4627 if (unlikely(!ctx
->mem_idx
)) {
4628 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4631 if (NARROW_MODE(ctx
)) {
4632 TCGv t0
= tcg_temp_new();
4633 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
4634 gen_helper_tlbie(cpu_env
, t0
);
4637 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4643 static void gen_tlbsync(DisasContext
*ctx
)
4645 #if defined(CONFIG_USER_ONLY)
4646 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4648 if (unlikely(!ctx
->mem_idx
)) {
4649 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4652 /* This has no effect: it should ensure that all previous
4653 * tlbie have completed
4655 gen_stop_exception(ctx
);
4659 #if defined(TARGET_PPC64)
4661 static void gen_slbia(DisasContext
*ctx
)
4663 #if defined(CONFIG_USER_ONLY)
4664 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4666 if (unlikely(!ctx
->mem_idx
)) {
4667 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4670 gen_helper_slbia(cpu_env
);
4675 static void gen_slbie(DisasContext
*ctx
)
4677 #if defined(CONFIG_USER_ONLY)
4678 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4680 if (unlikely(!ctx
->mem_idx
)) {
4681 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4684 gen_helper_slbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4689 /*** External control ***/
4693 static void gen_eciwx(DisasContext
*ctx
)
4696 /* Should check EAR[E] ! */
4697 gen_set_access_type(ctx
, ACCESS_EXT
);
4698 t0
= tcg_temp_new();
4699 gen_addr_reg_index(ctx
, t0
);
4700 gen_check_align(ctx
, t0
, 0x03);
4701 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4706 static void gen_ecowx(DisasContext
*ctx
)
4709 /* Should check EAR[E] ! */
4710 gen_set_access_type(ctx
, ACCESS_EXT
);
4711 t0
= tcg_temp_new();
4712 gen_addr_reg_index(ctx
, t0
);
4713 gen_check_align(ctx
, t0
, 0x03);
4714 gen_qemu_st32(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4718 /* PowerPC 601 specific instructions */
4721 static void gen_abs(DisasContext
*ctx
)
4723 int l1
= gen_new_label();
4724 int l2
= gen_new_label();
4725 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4726 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4729 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4731 if (unlikely(Rc(ctx
->opcode
) != 0))
4732 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4736 static void gen_abso(DisasContext
*ctx
)
4738 int l1
= gen_new_label();
4739 int l2
= gen_new_label();
4740 int l3
= gen_new_label();
4741 /* Start with XER OV disabled, the most likely case */
4742 tcg_gen_movi_tl(cpu_ov
, 0);
4743 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l2
);
4744 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rA(ctx
->opcode
)], 0x80000000, l1
);
4745 tcg_gen_movi_tl(cpu_ov
, 1);
4746 tcg_gen_movi_tl(cpu_so
, 1);
4749 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4752 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4754 if (unlikely(Rc(ctx
->opcode
) != 0))
4755 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4759 static void gen_clcs(DisasContext
*ctx
)
4761 TCGv_i32 t0
= tcg_const_i32(rA(ctx
->opcode
));
4762 gen_helper_clcs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4763 tcg_temp_free_i32(t0
);
4764 /* Rc=1 sets CR0 to an undefined state */
4768 static void gen_div(DisasContext
*ctx
)
4770 gen_helper_div(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4771 cpu_gpr
[rB(ctx
->opcode
)]);
4772 if (unlikely(Rc(ctx
->opcode
) != 0))
4773 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4777 static void gen_divo(DisasContext
*ctx
)
4779 gen_helper_divo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4780 cpu_gpr
[rB(ctx
->opcode
)]);
4781 if (unlikely(Rc(ctx
->opcode
) != 0))
4782 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4786 static void gen_divs(DisasContext
*ctx
)
4788 gen_helper_divs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4789 cpu_gpr
[rB(ctx
->opcode
)]);
4790 if (unlikely(Rc(ctx
->opcode
) != 0))
4791 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4794 /* divso - divso. */
4795 static void gen_divso(DisasContext
*ctx
)
4797 gen_helper_divso(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
4798 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4799 if (unlikely(Rc(ctx
->opcode
) != 0))
4800 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4804 static void gen_doz(DisasContext
*ctx
)
4806 int l1
= gen_new_label();
4807 int l2
= gen_new_label();
4808 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4809 tcg_gen_sub_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4812 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4814 if (unlikely(Rc(ctx
->opcode
) != 0))
4815 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4819 static void gen_dozo(DisasContext
*ctx
)
4821 int l1
= gen_new_label();
4822 int l2
= gen_new_label();
4823 TCGv t0
= tcg_temp_new();
4824 TCGv t1
= tcg_temp_new();
4825 TCGv t2
= tcg_temp_new();
4826 /* Start with XER OV disabled, the most likely case */
4827 tcg_gen_movi_tl(cpu_ov
, 0);
4828 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4829 tcg_gen_sub_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4830 tcg_gen_xor_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4831 tcg_gen_xor_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], t0
);
4832 tcg_gen_andc_tl(t1
, t1
, t2
);
4833 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4834 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
4835 tcg_gen_movi_tl(cpu_ov
, 1);
4836 tcg_gen_movi_tl(cpu_so
, 1);
4839 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4844 if (unlikely(Rc(ctx
->opcode
) != 0))
4845 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4849 static void gen_dozi(DisasContext
*ctx
)
4851 target_long simm
= SIMM(ctx
->opcode
);
4852 int l1
= gen_new_label();
4853 int l2
= gen_new_label();
4854 tcg_gen_brcondi_tl(TCG_COND_LT
, cpu_gpr
[rA(ctx
->opcode
)], simm
, l1
);
4855 tcg_gen_subfi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
, cpu_gpr
[rA(ctx
->opcode
)]);
4858 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4860 if (unlikely(Rc(ctx
->opcode
) != 0))
4861 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4864 /* lscbx - lscbx. */
4865 static void gen_lscbx(DisasContext
*ctx
)
4867 TCGv t0
= tcg_temp_new();
4868 TCGv_i32 t1
= tcg_const_i32(rD(ctx
->opcode
));
4869 TCGv_i32 t2
= tcg_const_i32(rA(ctx
->opcode
));
4870 TCGv_i32 t3
= tcg_const_i32(rB(ctx
->opcode
));
4872 gen_addr_reg_index(ctx
, t0
);
4873 /* NIP cannot be restored if the memory exception comes from an helper */
4874 gen_update_nip(ctx
, ctx
->nip
- 4);
4875 gen_helper_lscbx(t0
, cpu_env
, t0
, t1
, t2
, t3
);
4876 tcg_temp_free_i32(t1
);
4877 tcg_temp_free_i32(t2
);
4878 tcg_temp_free_i32(t3
);
4879 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~0x7F);
4880 tcg_gen_or_tl(cpu_xer
, cpu_xer
, t0
);
4881 if (unlikely(Rc(ctx
->opcode
) != 0))
4882 gen_set_Rc0(ctx
, t0
);
4886 /* maskg - maskg. */
4887 static void gen_maskg(DisasContext
*ctx
)
4889 int l1
= gen_new_label();
4890 TCGv t0
= tcg_temp_new();
4891 TCGv t1
= tcg_temp_new();
4892 TCGv t2
= tcg_temp_new();
4893 TCGv t3
= tcg_temp_new();
4894 tcg_gen_movi_tl(t3
, 0xFFFFFFFF);
4895 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4896 tcg_gen_andi_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 0x1F);
4897 tcg_gen_addi_tl(t2
, t0
, 1);
4898 tcg_gen_shr_tl(t2
, t3
, t2
);
4899 tcg_gen_shr_tl(t3
, t3
, t1
);
4900 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], t2
, t3
);
4901 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
4902 tcg_gen_neg_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4908 if (unlikely(Rc(ctx
->opcode
) != 0))
4909 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4912 /* maskir - maskir. */
4913 static void gen_maskir(DisasContext
*ctx
)
4915 TCGv t0
= tcg_temp_new();
4916 TCGv t1
= tcg_temp_new();
4917 tcg_gen_and_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4918 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4919 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4922 if (unlikely(Rc(ctx
->opcode
) != 0))
4923 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4927 static void gen_mul(DisasContext
*ctx
)
4929 TCGv_i64 t0
= tcg_temp_new_i64();
4930 TCGv_i64 t1
= tcg_temp_new_i64();
4931 TCGv t2
= tcg_temp_new();
4932 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4933 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4934 tcg_gen_mul_i64(t0
, t0
, t1
);
4935 tcg_gen_trunc_i64_tl(t2
, t0
);
4936 gen_store_spr(SPR_MQ
, t2
);
4937 tcg_gen_shri_i64(t1
, t0
, 32);
4938 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4939 tcg_temp_free_i64(t0
);
4940 tcg_temp_free_i64(t1
);
4942 if (unlikely(Rc(ctx
->opcode
) != 0))
4943 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4947 static void gen_mulo(DisasContext
*ctx
)
4949 int l1
= gen_new_label();
4950 TCGv_i64 t0
= tcg_temp_new_i64();
4951 TCGv_i64 t1
= tcg_temp_new_i64();
4952 TCGv t2
= tcg_temp_new();
4953 /* Start with XER OV disabled, the most likely case */
4954 tcg_gen_movi_tl(cpu_ov
, 0);
4955 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4956 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4957 tcg_gen_mul_i64(t0
, t0
, t1
);
4958 tcg_gen_trunc_i64_tl(t2
, t0
);
4959 gen_store_spr(SPR_MQ
, t2
);
4960 tcg_gen_shri_i64(t1
, t0
, 32);
4961 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4962 tcg_gen_ext32s_i64(t1
, t0
);
4963 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
4964 tcg_gen_movi_tl(cpu_ov
, 1);
4965 tcg_gen_movi_tl(cpu_so
, 1);
4967 tcg_temp_free_i64(t0
);
4968 tcg_temp_free_i64(t1
);
4970 if (unlikely(Rc(ctx
->opcode
) != 0))
4971 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4975 static void gen_nabs(DisasContext
*ctx
)
4977 int l1
= gen_new_label();
4978 int l2
= gen_new_label();
4979 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4980 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4983 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4985 if (unlikely(Rc(ctx
->opcode
) != 0))
4986 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4989 /* nabso - nabso. */
4990 static void gen_nabso(DisasContext
*ctx
)
4992 int l1
= gen_new_label();
4993 int l2
= gen_new_label();
4994 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4995 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4998 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5000 /* nabs never overflows */
5001 tcg_gen_movi_tl(cpu_ov
, 0);
5002 if (unlikely(Rc(ctx
->opcode
) != 0))
5003 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5007 static void gen_rlmi(DisasContext
*ctx
)
5009 uint32_t mb
= MB(ctx
->opcode
);
5010 uint32_t me
= ME(ctx
->opcode
);
5011 TCGv t0
= tcg_temp_new();
5012 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5013 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5014 tcg_gen_andi_tl(t0
, t0
, MASK(mb
, me
));
5015 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~MASK(mb
, me
));
5016 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], t0
);
5018 if (unlikely(Rc(ctx
->opcode
) != 0))
5019 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5023 static void gen_rrib(DisasContext
*ctx
)
5025 TCGv t0
= tcg_temp_new();
5026 TCGv t1
= tcg_temp_new();
5027 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5028 tcg_gen_movi_tl(t1
, 0x80000000);
5029 tcg_gen_shr_tl(t1
, t1
, t0
);
5030 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5031 tcg_gen_and_tl(t0
, t0
, t1
);
5032 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], t1
);
5033 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5036 if (unlikely(Rc(ctx
->opcode
) != 0))
5037 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5041 static void gen_sle(DisasContext
*ctx
)
5043 TCGv t0
= tcg_temp_new();
5044 TCGv t1
= tcg_temp_new();
5045 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5046 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5047 tcg_gen_subfi_tl(t1
, 32, t1
);
5048 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5049 tcg_gen_or_tl(t1
, t0
, t1
);
5050 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5051 gen_store_spr(SPR_MQ
, t1
);
5054 if (unlikely(Rc(ctx
->opcode
) != 0))
5055 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5059 static void gen_sleq(DisasContext
*ctx
)
5061 TCGv t0
= tcg_temp_new();
5062 TCGv t1
= tcg_temp_new();
5063 TCGv t2
= tcg_temp_new();
5064 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5065 tcg_gen_movi_tl(t2
, 0xFFFFFFFF);
5066 tcg_gen_shl_tl(t2
, t2
, t0
);
5067 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5068 gen_load_spr(t1
, SPR_MQ
);
5069 gen_store_spr(SPR_MQ
, t0
);
5070 tcg_gen_and_tl(t0
, t0
, t2
);
5071 tcg_gen_andc_tl(t1
, t1
, t2
);
5072 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5076 if (unlikely(Rc(ctx
->opcode
) != 0))
5077 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5081 static void gen_sliq(DisasContext
*ctx
)
5083 int sh
= SH(ctx
->opcode
);
5084 TCGv t0
= tcg_temp_new();
5085 TCGv t1
= tcg_temp_new();
5086 tcg_gen_shli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5087 tcg_gen_shri_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5088 tcg_gen_or_tl(t1
, t0
, t1
);
5089 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5090 gen_store_spr(SPR_MQ
, t1
);
5093 if (unlikely(Rc(ctx
->opcode
) != 0))
5094 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5097 /* slliq - slliq. */
5098 static void gen_slliq(DisasContext
*ctx
)
5100 int sh
= SH(ctx
->opcode
);
5101 TCGv t0
= tcg_temp_new();
5102 TCGv t1
= tcg_temp_new();
5103 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5104 gen_load_spr(t1
, SPR_MQ
);
5105 gen_store_spr(SPR_MQ
, t0
);
5106 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
<< sh
));
5107 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
<< sh
));
5108 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5111 if (unlikely(Rc(ctx
->opcode
) != 0))
5112 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5116 static void gen_sllq(DisasContext
*ctx
)
5118 int l1
= gen_new_label();
5119 int l2
= gen_new_label();
5120 TCGv t0
= tcg_temp_local_new();
5121 TCGv t1
= tcg_temp_local_new();
5122 TCGv t2
= tcg_temp_local_new();
5123 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5124 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5125 tcg_gen_shl_tl(t1
, t1
, t2
);
5126 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5127 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5128 gen_load_spr(t0
, SPR_MQ
);
5129 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5132 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5133 gen_load_spr(t2
, SPR_MQ
);
5134 tcg_gen_andc_tl(t1
, t2
, t1
);
5135 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5140 if (unlikely(Rc(ctx
->opcode
) != 0))
5141 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5145 static void gen_slq(DisasContext
*ctx
)
5147 int l1
= gen_new_label();
5148 TCGv t0
= tcg_temp_new();
5149 TCGv t1
= tcg_temp_new();
5150 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5151 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5152 tcg_gen_subfi_tl(t1
, 32, t1
);
5153 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5154 tcg_gen_or_tl(t1
, t0
, t1
);
5155 gen_store_spr(SPR_MQ
, t1
);
5156 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5157 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5158 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
5159 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5163 if (unlikely(Rc(ctx
->opcode
) != 0))
5164 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5167 /* sraiq - sraiq. */
5168 static void gen_sraiq(DisasContext
*ctx
)
5170 int sh
= SH(ctx
->opcode
);
5171 int l1
= gen_new_label();
5172 TCGv t0
= tcg_temp_new();
5173 TCGv t1
= tcg_temp_new();
5174 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5175 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5176 tcg_gen_or_tl(t0
, t0
, t1
);
5177 gen_store_spr(SPR_MQ
, t0
);
5178 tcg_gen_movi_tl(cpu_ca
, 0);
5179 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
5180 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
5181 tcg_gen_movi_tl(cpu_ca
, 1);
5183 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
5186 if (unlikely(Rc(ctx
->opcode
) != 0))
5187 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5191 static void gen_sraq(DisasContext
*ctx
)
5193 int l1
= gen_new_label();
5194 int l2
= gen_new_label();
5195 TCGv t0
= tcg_temp_new();
5196 TCGv t1
= tcg_temp_local_new();
5197 TCGv t2
= tcg_temp_local_new();
5198 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5199 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5200 tcg_gen_sar_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5201 tcg_gen_subfi_tl(t2
, 32, t2
);
5202 tcg_gen_shl_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5203 tcg_gen_or_tl(t0
, t0
, t2
);
5204 gen_store_spr(SPR_MQ
, t0
);
5205 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5206 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l1
);
5207 tcg_gen_mov_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
5208 tcg_gen_sari_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 31);
5211 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
);
5212 tcg_gen_movi_tl(cpu_ca
, 0);
5213 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
5214 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l2
);
5215 tcg_gen_movi_tl(cpu_ca
, 1);
5219 if (unlikely(Rc(ctx
->opcode
) != 0))
5220 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5224 static void gen_sre(DisasContext
*ctx
)
5226 TCGv t0
= tcg_temp_new();
5227 TCGv t1
= tcg_temp_new();
5228 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5229 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5230 tcg_gen_subfi_tl(t1
, 32, t1
);
5231 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5232 tcg_gen_or_tl(t1
, t0
, t1
);
5233 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5234 gen_store_spr(SPR_MQ
, t1
);
5237 if (unlikely(Rc(ctx
->opcode
) != 0))
5238 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5242 static void gen_srea(DisasContext
*ctx
)
5244 TCGv t0
= tcg_temp_new();
5245 TCGv t1
= tcg_temp_new();
5246 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5247 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5248 gen_store_spr(SPR_MQ
, t0
);
5249 tcg_gen_sar_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t1
);
5252 if (unlikely(Rc(ctx
->opcode
) != 0))
5253 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5257 static void gen_sreq(DisasContext
*ctx
)
5259 TCGv t0
= tcg_temp_new();
5260 TCGv t1
= tcg_temp_new();
5261 TCGv t2
= tcg_temp_new();
5262 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5263 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5264 tcg_gen_shr_tl(t1
, t1
, t0
);
5265 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5266 gen_load_spr(t2
, SPR_MQ
);
5267 gen_store_spr(SPR_MQ
, t0
);
5268 tcg_gen_and_tl(t0
, t0
, t1
);
5269 tcg_gen_andc_tl(t2
, t2
, t1
);
5270 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5274 if (unlikely(Rc(ctx
->opcode
) != 0))
5275 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5279 static void gen_sriq(DisasContext
*ctx
)
5281 int sh
= SH(ctx
->opcode
);
5282 TCGv t0
= tcg_temp_new();
5283 TCGv t1
= tcg_temp_new();
5284 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5285 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5286 tcg_gen_or_tl(t1
, t0
, t1
);
5287 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5288 gen_store_spr(SPR_MQ
, t1
);
5291 if (unlikely(Rc(ctx
->opcode
) != 0))
5292 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5296 static void gen_srliq(DisasContext
*ctx
)
5298 int sh
= SH(ctx
->opcode
);
5299 TCGv t0
= tcg_temp_new();
5300 TCGv t1
= tcg_temp_new();
5301 tcg_gen_rotri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5302 gen_load_spr(t1
, SPR_MQ
);
5303 gen_store_spr(SPR_MQ
, t0
);
5304 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
>> sh
));
5305 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
>> sh
));
5306 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5309 if (unlikely(Rc(ctx
->opcode
) != 0))
5310 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5314 static void gen_srlq(DisasContext
*ctx
)
5316 int l1
= gen_new_label();
5317 int l2
= gen_new_label();
5318 TCGv t0
= tcg_temp_local_new();
5319 TCGv t1
= tcg_temp_local_new();
5320 TCGv t2
= tcg_temp_local_new();
5321 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5322 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5323 tcg_gen_shr_tl(t2
, t1
, t2
);
5324 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5325 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5326 gen_load_spr(t0
, SPR_MQ
);
5327 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5330 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5331 tcg_gen_and_tl(t0
, t0
, t2
);
5332 gen_load_spr(t1
, SPR_MQ
);
5333 tcg_gen_andc_tl(t1
, t1
, t2
);
5334 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5339 if (unlikely(Rc(ctx
->opcode
) != 0))
5340 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5344 static void gen_srq(DisasContext
*ctx
)
5346 int l1
= gen_new_label();
5347 TCGv t0
= tcg_temp_new();
5348 TCGv t1
= tcg_temp_new();
5349 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5350 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5351 tcg_gen_subfi_tl(t1
, 32, t1
);
5352 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5353 tcg_gen_or_tl(t1
, t0
, t1
);
5354 gen_store_spr(SPR_MQ
, t1
);
5355 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5356 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5357 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5358 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5362 if (unlikely(Rc(ctx
->opcode
) != 0))
5363 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5366 /* PowerPC 602 specific instructions */
5369 static void gen_dsa(DisasContext
*ctx
)
5372 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5376 static void gen_esa(DisasContext
*ctx
)
5379 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5383 static void gen_mfrom(DisasContext
*ctx
)
5385 #if defined(CONFIG_USER_ONLY)
5386 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5388 if (unlikely(!ctx
->mem_idx
)) {
5389 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5392 gen_helper_602_mfrom(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5396 /* 602 - 603 - G2 TLB management */
5399 static void gen_tlbld_6xx(DisasContext
*ctx
)
5401 #if defined(CONFIG_USER_ONLY)
5402 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5404 if (unlikely(!ctx
->mem_idx
)) {
5405 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5408 gen_helper_6xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5413 static void gen_tlbli_6xx(DisasContext
*ctx
)
5415 #if defined(CONFIG_USER_ONLY)
5416 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5418 if (unlikely(!ctx
->mem_idx
)) {
5419 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5422 gen_helper_6xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5426 /* 74xx TLB management */
5429 static void gen_tlbld_74xx(DisasContext
*ctx
)
5431 #if defined(CONFIG_USER_ONLY)
5432 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5434 if (unlikely(!ctx
->mem_idx
)) {
5435 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5438 gen_helper_74xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5443 static void gen_tlbli_74xx(DisasContext
*ctx
)
5445 #if defined(CONFIG_USER_ONLY)
5446 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5448 if (unlikely(!ctx
->mem_idx
)) {
5449 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5452 gen_helper_74xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5456 /* POWER instructions not in PowerPC 601 */
5459 static void gen_clf(DisasContext
*ctx
)
5461 /* Cache line flush: implemented as no-op */
5465 static void gen_cli(DisasContext
*ctx
)
5467 /* Cache line invalidate: privileged and treated as no-op */
5468 #if defined(CONFIG_USER_ONLY)
5469 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5471 if (unlikely(!ctx
->mem_idx
)) {
5472 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5479 static void gen_dclst(DisasContext
*ctx
)
5481 /* Data cache line store: treated as no-op */
5484 static void gen_mfsri(DisasContext
*ctx
)
5486 #if defined(CONFIG_USER_ONLY)
5487 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5489 int ra
= rA(ctx
->opcode
);
5490 int rd
= rD(ctx
->opcode
);
5492 if (unlikely(!ctx
->mem_idx
)) {
5493 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5496 t0
= tcg_temp_new();
5497 gen_addr_reg_index(ctx
, t0
);
5498 tcg_gen_shri_tl(t0
, t0
, 28);
5499 tcg_gen_andi_tl(t0
, t0
, 0xF);
5500 gen_helper_load_sr(cpu_gpr
[rd
], cpu_env
, t0
);
5502 if (ra
!= 0 && ra
!= rd
)
5503 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rd
]);
5507 static void gen_rac(DisasContext
*ctx
)
5509 #if defined(CONFIG_USER_ONLY)
5510 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5513 if (unlikely(!ctx
->mem_idx
)) {
5514 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5517 t0
= tcg_temp_new();
5518 gen_addr_reg_index(ctx
, t0
);
5519 gen_helper_rac(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5524 static void gen_rfsvc(DisasContext
*ctx
)
5526 #if defined(CONFIG_USER_ONLY)
5527 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5529 if (unlikely(!ctx
->mem_idx
)) {
5530 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5533 gen_helper_rfsvc(cpu_env
);
5534 gen_sync_exception(ctx
);
5538 /* svc is not implemented for now */
5540 /* POWER2 specific instructions */
5541 /* Quad manipulation (load/store two floats at a time) */
5544 static void gen_lfq(DisasContext
*ctx
)
5546 int rd
= rD(ctx
->opcode
);
5548 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5549 t0
= tcg_temp_new();
5550 gen_addr_imm_index(ctx
, t0
, 0);
5551 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5552 gen_addr_add(ctx
, t0
, t0
, 8);
5553 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5558 static void gen_lfqu(DisasContext
*ctx
)
5560 int ra
= rA(ctx
->opcode
);
5561 int rd
= rD(ctx
->opcode
);
5563 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5564 t0
= tcg_temp_new();
5565 t1
= tcg_temp_new();
5566 gen_addr_imm_index(ctx
, t0
, 0);
5567 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5568 gen_addr_add(ctx
, t1
, t0
, 8);
5569 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5571 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5577 static void gen_lfqux(DisasContext
*ctx
)
5579 int ra
= rA(ctx
->opcode
);
5580 int rd
= rD(ctx
->opcode
);
5581 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5583 t0
= tcg_temp_new();
5584 gen_addr_reg_index(ctx
, t0
);
5585 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5586 t1
= tcg_temp_new();
5587 gen_addr_add(ctx
, t1
, t0
, 8);
5588 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5591 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5596 static void gen_lfqx(DisasContext
*ctx
)
5598 int rd
= rD(ctx
->opcode
);
5600 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5601 t0
= tcg_temp_new();
5602 gen_addr_reg_index(ctx
, t0
);
5603 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5604 gen_addr_add(ctx
, t0
, t0
, 8);
5605 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5610 static void gen_stfq(DisasContext
*ctx
)
5612 int rd
= rD(ctx
->opcode
);
5614 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5615 t0
= tcg_temp_new();
5616 gen_addr_imm_index(ctx
, t0
, 0);
5617 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5618 gen_addr_add(ctx
, t0
, t0
, 8);
5619 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5624 static void gen_stfqu(DisasContext
*ctx
)
5626 int ra
= rA(ctx
->opcode
);
5627 int rd
= rD(ctx
->opcode
);
5629 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5630 t0
= tcg_temp_new();
5631 gen_addr_imm_index(ctx
, t0
, 0);
5632 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5633 t1
= tcg_temp_new();
5634 gen_addr_add(ctx
, t1
, t0
, 8);
5635 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5638 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5643 static void gen_stfqux(DisasContext
*ctx
)
5645 int ra
= rA(ctx
->opcode
);
5646 int rd
= rD(ctx
->opcode
);
5648 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5649 t0
= tcg_temp_new();
5650 gen_addr_reg_index(ctx
, t0
);
5651 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5652 t1
= tcg_temp_new();
5653 gen_addr_add(ctx
, t1
, t0
, 8);
5654 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5657 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5662 static void gen_stfqx(DisasContext
*ctx
)
5664 int rd
= rD(ctx
->opcode
);
5666 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5667 t0
= tcg_temp_new();
5668 gen_addr_reg_index(ctx
, t0
);
5669 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5670 gen_addr_add(ctx
, t0
, t0
, 8);
5671 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5675 /* BookE specific instructions */
5677 /* XXX: not implemented on 440 ? */
5678 static void gen_mfapidi(DisasContext
*ctx
)
5681 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5684 /* XXX: not implemented on 440 ? */
5685 static void gen_tlbiva(DisasContext
*ctx
)
5687 #if defined(CONFIG_USER_ONLY)
5688 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5691 if (unlikely(!ctx
->mem_idx
)) {
5692 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5695 t0
= tcg_temp_new();
5696 gen_addr_reg_index(ctx
, t0
);
5697 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5702 /* All 405 MAC instructions are translated here */
5703 static inline void gen_405_mulladd_insn(DisasContext
*ctx
, int opc2
, int opc3
,
5704 int ra
, int rb
, int rt
, int Rc
)
5708 t0
= tcg_temp_local_new();
5709 t1
= tcg_temp_local_new();
5711 switch (opc3
& 0x0D) {
5713 /* macchw - macchw. - macchwo - macchwo. */
5714 /* macchws - macchws. - macchwso - macchwso. */
5715 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5716 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5717 /* mulchw - mulchw. */
5718 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5719 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5720 tcg_gen_ext16s_tl(t1
, t1
);
5723 /* macchwu - macchwu. - macchwuo - macchwuo. */
5724 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5725 /* mulchwu - mulchwu. */
5726 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5727 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5728 tcg_gen_ext16u_tl(t1
, t1
);
5731 /* machhw - machhw. - machhwo - machhwo. */
5732 /* machhws - machhws. - machhwso - machhwso. */
5733 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5734 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5735 /* mulhhw - mulhhw. */
5736 tcg_gen_sari_tl(t0
, cpu_gpr
[ra
], 16);
5737 tcg_gen_ext16s_tl(t0
, t0
);
5738 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5739 tcg_gen_ext16s_tl(t1
, t1
);
5742 /* machhwu - machhwu. - machhwuo - machhwuo. */
5743 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5744 /* mulhhwu - mulhhwu. */
5745 tcg_gen_shri_tl(t0
, cpu_gpr
[ra
], 16);
5746 tcg_gen_ext16u_tl(t0
, t0
);
5747 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5748 tcg_gen_ext16u_tl(t1
, t1
);
5751 /* maclhw - maclhw. - maclhwo - maclhwo. */
5752 /* maclhws - maclhws. - maclhwso - maclhwso. */
5753 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5754 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5755 /* mullhw - mullhw. */
5756 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5757 tcg_gen_ext16s_tl(t1
, cpu_gpr
[rb
]);
5760 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5761 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5762 /* mullhwu - mullhwu. */
5763 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5764 tcg_gen_ext16u_tl(t1
, cpu_gpr
[rb
]);
5768 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5769 tcg_gen_mul_tl(t1
, t0
, t1
);
5771 /* nmultiply-and-accumulate (0x0E) */
5772 tcg_gen_sub_tl(t0
, cpu_gpr
[rt
], t1
);
5774 /* multiply-and-accumulate (0x0C) */
5775 tcg_gen_add_tl(t0
, cpu_gpr
[rt
], t1
);
5779 /* Check overflow and/or saturate */
5780 int l1
= gen_new_label();
5783 /* Start with XER OV disabled, the most likely case */
5784 tcg_gen_movi_tl(cpu_ov
, 0);
5788 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t1
);
5789 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
5790 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t0
);
5791 tcg_gen_brcondi_tl(TCG_COND_LT
, t1
, 0, l1
);
5794 tcg_gen_sari_tl(t0
, cpu_gpr
[rt
], 31);
5795 tcg_gen_xori_tl(t0
, t0
, 0x7fffffff);
5799 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
5802 tcg_gen_movi_tl(t0
, UINT32_MAX
);
5806 /* Check overflow */
5807 tcg_gen_movi_tl(cpu_ov
, 1);
5808 tcg_gen_movi_tl(cpu_so
, 1);
5811 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
5814 tcg_gen_mul_tl(cpu_gpr
[rt
], t0
, t1
);
5818 if (unlikely(Rc
) != 0) {
5820 gen_set_Rc0(ctx
, cpu_gpr
[rt
]);
5824 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5825 static void glue(gen_, name)(DisasContext *ctx) \
5827 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5828 rD(ctx->opcode), Rc(ctx->opcode)); \
5831 /* macchw - macchw. */
5832 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
5833 /* macchwo - macchwo. */
5834 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
5835 /* macchws - macchws. */
5836 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
5837 /* macchwso - macchwso. */
5838 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
5839 /* macchwsu - macchwsu. */
5840 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
5841 /* macchwsuo - macchwsuo. */
5842 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
5843 /* macchwu - macchwu. */
5844 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
5845 /* macchwuo - macchwuo. */
5846 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
5847 /* machhw - machhw. */
5848 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
5849 /* machhwo - machhwo. */
5850 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
5851 /* machhws - machhws. */
5852 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
5853 /* machhwso - machhwso. */
5854 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
5855 /* machhwsu - machhwsu. */
5856 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
5857 /* machhwsuo - machhwsuo. */
5858 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
5859 /* machhwu - machhwu. */
5860 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
5861 /* machhwuo - machhwuo. */
5862 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
5863 /* maclhw - maclhw. */
5864 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
5865 /* maclhwo - maclhwo. */
5866 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
5867 /* maclhws - maclhws. */
5868 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
5869 /* maclhwso - maclhwso. */
5870 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
5871 /* maclhwu - maclhwu. */
5872 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
5873 /* maclhwuo - maclhwuo. */
5874 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
5875 /* maclhwsu - maclhwsu. */
5876 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
5877 /* maclhwsuo - maclhwsuo. */
5878 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
5879 /* nmacchw - nmacchw. */
5880 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
5881 /* nmacchwo - nmacchwo. */
5882 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
5883 /* nmacchws - nmacchws. */
5884 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
5885 /* nmacchwso - nmacchwso. */
5886 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
5887 /* nmachhw - nmachhw. */
5888 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
5889 /* nmachhwo - nmachhwo. */
5890 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
5891 /* nmachhws - nmachhws. */
5892 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
5893 /* nmachhwso - nmachhwso. */
5894 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
5895 /* nmaclhw - nmaclhw. */
5896 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
5897 /* nmaclhwo - nmaclhwo. */
5898 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
5899 /* nmaclhws - nmaclhws. */
5900 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
5901 /* nmaclhwso - nmaclhwso. */
5902 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
5904 /* mulchw - mulchw. */
5905 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
5906 /* mulchwu - mulchwu. */
5907 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
5908 /* mulhhw - mulhhw. */
5909 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
5910 /* mulhhwu - mulhhwu. */
5911 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
5912 /* mullhw - mullhw. */
5913 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
5914 /* mullhwu - mullhwu. */
5915 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
5918 static void gen_mfdcr(DisasContext
*ctx
)
5920 #if defined(CONFIG_USER_ONLY)
5921 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5924 if (unlikely(!ctx
->mem_idx
)) {
5925 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5928 /* NIP cannot be restored if the memory exception comes from an helper */
5929 gen_update_nip(ctx
, ctx
->nip
- 4);
5930 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5931 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, dcrn
);
5932 tcg_temp_free(dcrn
);
5937 static void gen_mtdcr(DisasContext
*ctx
)
5939 #if defined(CONFIG_USER_ONLY)
5940 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5943 if (unlikely(!ctx
->mem_idx
)) {
5944 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5947 /* NIP cannot be restored if the memory exception comes from an helper */
5948 gen_update_nip(ctx
, ctx
->nip
- 4);
5949 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5950 gen_helper_store_dcr(cpu_env
, dcrn
, cpu_gpr
[rS(ctx
->opcode
)]);
5951 tcg_temp_free(dcrn
);
5956 /* XXX: not implemented on 440 ? */
5957 static void gen_mfdcrx(DisasContext
*ctx
)
5959 #if defined(CONFIG_USER_ONLY)
5960 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5962 if (unlikely(!ctx
->mem_idx
)) {
5963 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5966 /* NIP cannot be restored if the memory exception comes from an helper */
5967 gen_update_nip(ctx
, ctx
->nip
- 4);
5968 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5969 cpu_gpr
[rA(ctx
->opcode
)]);
5970 /* Note: Rc update flag set leads to undefined state of Rc0 */
5975 /* XXX: not implemented on 440 ? */
5976 static void gen_mtdcrx(DisasContext
*ctx
)
5978 #if defined(CONFIG_USER_ONLY)
5979 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5981 if (unlikely(!ctx
->mem_idx
)) {
5982 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5985 /* NIP cannot be restored if the memory exception comes from an helper */
5986 gen_update_nip(ctx
, ctx
->nip
- 4);
5987 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5988 cpu_gpr
[rS(ctx
->opcode
)]);
5989 /* Note: Rc update flag set leads to undefined state of Rc0 */
5993 /* mfdcrux (PPC 460) : user-mode access to DCR */
5994 static void gen_mfdcrux(DisasContext
*ctx
)
5996 /* NIP cannot be restored if the memory exception comes from an helper */
5997 gen_update_nip(ctx
, ctx
->nip
- 4);
5998 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5999 cpu_gpr
[rA(ctx
->opcode
)]);
6000 /* Note: Rc update flag set leads to undefined state of Rc0 */
6003 /* mtdcrux (PPC 460) : user-mode access to DCR */
6004 static void gen_mtdcrux(DisasContext
*ctx
)
6006 /* NIP cannot be restored if the memory exception comes from an helper */
6007 gen_update_nip(ctx
, ctx
->nip
- 4);
6008 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6009 cpu_gpr
[rS(ctx
->opcode
)]);
6010 /* Note: Rc update flag set leads to undefined state of Rc0 */
6014 static void gen_dccci(DisasContext
*ctx
)
6016 #if defined(CONFIG_USER_ONLY)
6017 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6019 if (unlikely(!ctx
->mem_idx
)) {
6020 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6023 /* interpreted as no-op */
6028 static void gen_dcread(DisasContext
*ctx
)
6030 #if defined(CONFIG_USER_ONLY)
6031 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6034 if (unlikely(!ctx
->mem_idx
)) {
6035 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6038 gen_set_access_type(ctx
, ACCESS_CACHE
);
6039 EA
= tcg_temp_new();
6040 gen_addr_reg_index(ctx
, EA
);
6041 val
= tcg_temp_new();
6042 gen_qemu_ld32u(ctx
, val
, EA
);
6044 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], EA
);
6050 static void gen_icbt_40x(DisasContext
*ctx
)
6052 /* interpreted as no-op */
6053 /* XXX: specification say this is treated as a load by the MMU
6054 * but does not generate any exception
6059 static void gen_iccci(DisasContext
*ctx
)
6061 #if defined(CONFIG_USER_ONLY)
6062 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6064 if (unlikely(!ctx
->mem_idx
)) {
6065 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6068 /* interpreted as no-op */
6073 static void gen_icread(DisasContext
*ctx
)
6075 #if defined(CONFIG_USER_ONLY)
6076 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6078 if (unlikely(!ctx
->mem_idx
)) {
6079 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6082 /* interpreted as no-op */
6086 /* rfci (mem_idx only) */
6087 static void gen_rfci_40x(DisasContext
*ctx
)
6089 #if defined(CONFIG_USER_ONLY)
6090 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6092 if (unlikely(!ctx
->mem_idx
)) {
6093 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6096 /* Restore CPU state */
6097 gen_helper_40x_rfci(cpu_env
);
6098 gen_sync_exception(ctx
);
6102 static void gen_rfci(DisasContext
*ctx
)
6104 #if defined(CONFIG_USER_ONLY)
6105 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6107 if (unlikely(!ctx
->mem_idx
)) {
6108 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6111 /* Restore CPU state */
6112 gen_helper_rfci(cpu_env
);
6113 gen_sync_exception(ctx
);
6117 /* BookE specific */
6119 /* XXX: not implemented on 440 ? */
6120 static void gen_rfdi(DisasContext
*ctx
)
6122 #if defined(CONFIG_USER_ONLY)
6123 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6125 if (unlikely(!ctx
->mem_idx
)) {
6126 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6129 /* Restore CPU state */
6130 gen_helper_rfdi(cpu_env
);
6131 gen_sync_exception(ctx
);
6135 /* XXX: not implemented on 440 ? */
6136 static void gen_rfmci(DisasContext
*ctx
)
6138 #if defined(CONFIG_USER_ONLY)
6139 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6141 if (unlikely(!ctx
->mem_idx
)) {
6142 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6145 /* Restore CPU state */
6146 gen_helper_rfmci(cpu_env
);
6147 gen_sync_exception(ctx
);
6151 /* TLB management - PowerPC 405 implementation */
6154 static void gen_tlbre_40x(DisasContext
*ctx
)
6156 #if defined(CONFIG_USER_ONLY)
6157 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6159 if (unlikely(!ctx
->mem_idx
)) {
6160 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6163 switch (rB(ctx
->opcode
)) {
6165 gen_helper_4xx_tlbre_hi(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6166 cpu_gpr
[rA(ctx
->opcode
)]);
6169 gen_helper_4xx_tlbre_lo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6170 cpu_gpr
[rA(ctx
->opcode
)]);
6173 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6179 /* tlbsx - tlbsx. */
6180 static void gen_tlbsx_40x(DisasContext
*ctx
)
6182 #if defined(CONFIG_USER_ONLY)
6183 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6186 if (unlikely(!ctx
->mem_idx
)) {
6187 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6190 t0
= tcg_temp_new();
6191 gen_addr_reg_index(ctx
, t0
);
6192 gen_helper_4xx_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
6194 if (Rc(ctx
->opcode
)) {
6195 int l1
= gen_new_label();
6196 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
6197 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
6198 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
6205 static void gen_tlbwe_40x(DisasContext
*ctx
)
6207 #if defined(CONFIG_USER_ONLY)
6208 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6210 if (unlikely(!ctx
->mem_idx
)) {
6211 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6214 switch (rB(ctx
->opcode
)) {
6216 gen_helper_4xx_tlbwe_hi(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6217 cpu_gpr
[rS(ctx
->opcode
)]);
6220 gen_helper_4xx_tlbwe_lo(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6221 cpu_gpr
[rS(ctx
->opcode
)]);
6224 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6230 /* TLB management - PowerPC 440 implementation */
6233 static void gen_tlbre_440(DisasContext
*ctx
)
6235 #if defined(CONFIG_USER_ONLY)
6236 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6238 if (unlikely(!ctx
->mem_idx
)) {
6239 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6242 switch (rB(ctx
->opcode
)) {
6247 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
6248 gen_helper_440_tlbre(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6249 t0
, cpu_gpr
[rA(ctx
->opcode
)]);
6250 tcg_temp_free_i32(t0
);
6254 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6260 /* tlbsx - tlbsx. */
6261 static void gen_tlbsx_440(DisasContext
*ctx
)
6263 #if defined(CONFIG_USER_ONLY)
6264 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6267 if (unlikely(!ctx
->mem_idx
)) {
6268 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6271 t0
= tcg_temp_new();
6272 gen_addr_reg_index(ctx
, t0
);
6273 gen_helper_440_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
6275 if (Rc(ctx
->opcode
)) {
6276 int l1
= gen_new_label();
6277 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
6278 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
6279 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
6286 static void gen_tlbwe_440(DisasContext
*ctx
)
6288 #if defined(CONFIG_USER_ONLY)
6289 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6291 if (unlikely(!ctx
->mem_idx
)) {
6292 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6295 switch (rB(ctx
->opcode
)) {
6300 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
6301 gen_helper_440_tlbwe(cpu_env
, t0
, cpu_gpr
[rA(ctx
->opcode
)],
6302 cpu_gpr
[rS(ctx
->opcode
)]);
6303 tcg_temp_free_i32(t0
);
6307 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6313 /* TLB management - PowerPC BookE 2.06 implementation */
6316 static void gen_tlbre_booke206(DisasContext
*ctx
)
6318 #if defined(CONFIG_USER_ONLY)
6319 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6321 if (unlikely(!ctx
->mem_idx
)) {
6322 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6326 gen_helper_booke206_tlbre(cpu_env
);
6330 /* tlbsx - tlbsx. */
6331 static void gen_tlbsx_booke206(DisasContext
*ctx
)
6333 #if defined(CONFIG_USER_ONLY)
6334 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6337 if (unlikely(!ctx
->mem_idx
)) {
6338 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6342 if (rA(ctx
->opcode
)) {
6343 t0
= tcg_temp_new();
6344 tcg_gen_mov_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)]);
6346 t0
= tcg_const_tl(0);
6349 tcg_gen_add_tl(t0
, t0
, cpu_gpr
[rB(ctx
->opcode
)]);
6350 gen_helper_booke206_tlbsx(cpu_env
, t0
);
6355 static void gen_tlbwe_booke206(DisasContext
*ctx
)
6357 #if defined(CONFIG_USER_ONLY)
6358 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6360 if (unlikely(!ctx
->mem_idx
)) {
6361 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6364 gen_update_nip(ctx
, ctx
->nip
- 4);
6365 gen_helper_booke206_tlbwe(cpu_env
);
6369 static void gen_tlbivax_booke206(DisasContext
*ctx
)
6371 #if defined(CONFIG_USER_ONLY)
6372 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6375 if (unlikely(!ctx
->mem_idx
)) {
6376 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6380 t0
= tcg_temp_new();
6381 gen_addr_reg_index(ctx
, t0
);
6383 gen_helper_booke206_tlbivax(cpu_env
, t0
);
6387 static void gen_tlbilx_booke206(DisasContext
*ctx
)
6389 #if defined(CONFIG_USER_ONLY)
6390 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6393 if (unlikely(!ctx
->mem_idx
)) {
6394 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6398 t0
= tcg_temp_new();
6399 gen_addr_reg_index(ctx
, t0
);
6401 switch((ctx
->opcode
>> 21) & 0x3) {
6403 gen_helper_booke206_tlbilx0(cpu_env
, t0
);
6406 gen_helper_booke206_tlbilx1(cpu_env
, t0
);
6409 gen_helper_booke206_tlbilx3(cpu_env
, t0
);
6412 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6422 static void gen_wrtee(DisasContext
*ctx
)
6424 #if defined(CONFIG_USER_ONLY)
6425 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6428 if (unlikely(!ctx
->mem_idx
)) {
6429 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6432 t0
= tcg_temp_new();
6433 tcg_gen_andi_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)], (1 << MSR_EE
));
6434 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6435 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
6437 /* Stop translation to have a chance to raise an exception
6438 * if we just set msr_ee to 1
6440 gen_stop_exception(ctx
);
6445 static void gen_wrteei(DisasContext
*ctx
)
6447 #if defined(CONFIG_USER_ONLY)
6448 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6450 if (unlikely(!ctx
->mem_idx
)) {
6451 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6454 if (ctx
->opcode
& 0x00008000) {
6455 tcg_gen_ori_tl(cpu_msr
, cpu_msr
, (1 << MSR_EE
));
6456 /* Stop translation to have a chance to raise an exception */
6457 gen_stop_exception(ctx
);
6459 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6464 /* PowerPC 440 specific instructions */
6467 static void gen_dlmzb(DisasContext
*ctx
)
6469 TCGv_i32 t0
= tcg_const_i32(Rc(ctx
->opcode
));
6470 gen_helper_dlmzb(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
6471 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
6472 tcg_temp_free_i32(t0
);
6475 /* mbar replaces eieio on 440 */
6476 static void gen_mbar(DisasContext
*ctx
)
6478 /* interpreted as no-op */
6481 /* msync replaces sync on 440 */
6482 static void gen_msync_4xx(DisasContext
*ctx
)
6484 /* interpreted as no-op */
6488 static void gen_icbt_440(DisasContext
*ctx
)
6490 /* interpreted as no-op */
6491 /* XXX: specification say this is treated as a load by the MMU
6492 * but does not generate any exception
6496 /* Embedded.Processor Control */
6498 static void gen_msgclr(DisasContext
*ctx
)
6500 #if defined(CONFIG_USER_ONLY)
6501 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6503 if (unlikely(ctx
->mem_idx
== 0)) {
6504 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6508 gen_helper_msgclr(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6512 static void gen_msgsnd(DisasContext
*ctx
)
6514 #if defined(CONFIG_USER_ONLY)
6515 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6517 if (unlikely(ctx
->mem_idx
== 0)) {
6518 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6522 gen_helper_msgsnd(cpu_gpr
[rB(ctx
->opcode
)]);
6526 /*** Altivec vector extension ***/
6527 /* Altivec registers moves */
6529 static inline TCGv_ptr
gen_avr_ptr(int reg
)
6531 TCGv_ptr r
= tcg_temp_new_ptr();
6532 tcg_gen_addi_ptr(r
, cpu_env
, offsetof(CPUPPCState
, avr
[reg
]));
6536 #define GEN_VR_LDX(name, opc2, opc3) \
6537 static void glue(gen_, name)(DisasContext *ctx) \
6540 if (unlikely(!ctx->altivec_enabled)) { \
6541 gen_exception(ctx, POWERPC_EXCP_VPU); \
6544 gen_set_access_type(ctx, ACCESS_INT); \
6545 EA = tcg_temp_new(); \
6546 gen_addr_reg_index(ctx, EA); \
6547 tcg_gen_andi_tl(EA, EA, ~0xf); \
6548 if (ctx->le_mode) { \
6549 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6550 tcg_gen_addi_tl(EA, EA, 8); \
6551 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6553 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6554 tcg_gen_addi_tl(EA, EA, 8); \
6555 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6557 tcg_temp_free(EA); \
6560 #define GEN_VR_STX(name, opc2, opc3) \
6561 static void gen_st##name(DisasContext *ctx) \
6564 if (unlikely(!ctx->altivec_enabled)) { \
6565 gen_exception(ctx, POWERPC_EXCP_VPU); \
6568 gen_set_access_type(ctx, ACCESS_INT); \
6569 EA = tcg_temp_new(); \
6570 gen_addr_reg_index(ctx, EA); \
6571 tcg_gen_andi_tl(EA, EA, ~0xf); \
6572 if (ctx->le_mode) { \
6573 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6574 tcg_gen_addi_tl(EA, EA, 8); \
6575 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6577 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6578 tcg_gen_addi_tl(EA, EA, 8); \
6579 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6581 tcg_temp_free(EA); \
6584 #define GEN_VR_LVE(name, opc2, opc3) \
6585 static void gen_lve##name(DisasContext *ctx) \
6589 if (unlikely(!ctx->altivec_enabled)) { \
6590 gen_exception(ctx, POWERPC_EXCP_VPU); \
6593 gen_set_access_type(ctx, ACCESS_INT); \
6594 EA = tcg_temp_new(); \
6595 gen_addr_reg_index(ctx, EA); \
6596 rs = gen_avr_ptr(rS(ctx->opcode)); \
6597 gen_helper_lve##name(cpu_env, rs, EA); \
6598 tcg_temp_free(EA); \
6599 tcg_temp_free_ptr(rs); \
6602 #define GEN_VR_STVE(name, opc2, opc3) \
6603 static void gen_stve##name(DisasContext *ctx) \
6607 if (unlikely(!ctx->altivec_enabled)) { \
6608 gen_exception(ctx, POWERPC_EXCP_VPU); \
6611 gen_set_access_type(ctx, ACCESS_INT); \
6612 EA = tcg_temp_new(); \
6613 gen_addr_reg_index(ctx, EA); \
6614 rs = gen_avr_ptr(rS(ctx->opcode)); \
6615 gen_helper_stve##name(cpu_env, rs, EA); \
6616 tcg_temp_free(EA); \
6617 tcg_temp_free_ptr(rs); \
6620 GEN_VR_LDX(lvx
, 0x07, 0x03);
6621 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
6622 GEN_VR_LDX(lvxl
, 0x07, 0x0B);
6624 GEN_VR_LVE(bx
, 0x07, 0x00);
6625 GEN_VR_LVE(hx
, 0x07, 0x01);
6626 GEN_VR_LVE(wx
, 0x07, 0x02);
6628 GEN_VR_STX(svx
, 0x07, 0x07);
6629 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
6630 GEN_VR_STX(svxl
, 0x07, 0x0F);
6632 GEN_VR_STVE(bx
, 0x07, 0x04);
6633 GEN_VR_STVE(hx
, 0x07, 0x05);
6634 GEN_VR_STVE(wx
, 0x07, 0x06);
6636 static void gen_lvsl(DisasContext
*ctx
)
6640 if (unlikely(!ctx
->altivec_enabled
)) {
6641 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6644 EA
= tcg_temp_new();
6645 gen_addr_reg_index(ctx
, EA
);
6646 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6647 gen_helper_lvsl(rd
, EA
);
6649 tcg_temp_free_ptr(rd
);
6652 static void gen_lvsr(DisasContext
*ctx
)
6656 if (unlikely(!ctx
->altivec_enabled
)) {
6657 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6660 EA
= tcg_temp_new();
6661 gen_addr_reg_index(ctx
, EA
);
6662 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6663 gen_helper_lvsr(rd
, EA
);
6665 tcg_temp_free_ptr(rd
);
6668 static void gen_mfvscr(DisasContext
*ctx
)
6671 if (unlikely(!ctx
->altivec_enabled
)) {
6672 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6675 tcg_gen_movi_i64(cpu_avrh
[rD(ctx
->opcode
)], 0);
6676 t
= tcg_temp_new_i32();
6677 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUPPCState
, vscr
));
6678 tcg_gen_extu_i32_i64(cpu_avrl
[rD(ctx
->opcode
)], t
);
6679 tcg_temp_free_i32(t
);
6682 static void gen_mtvscr(DisasContext
*ctx
)
6685 if (unlikely(!ctx
->altivec_enabled
)) {
6686 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6689 p
= gen_avr_ptr(rD(ctx
->opcode
));
6690 gen_helper_mtvscr(cpu_env
, p
);
6691 tcg_temp_free_ptr(p
);
6694 /* Logical operations */
6695 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
6696 static void glue(gen_, name)(DisasContext *ctx) \
6698 if (unlikely(!ctx->altivec_enabled)) { \
6699 gen_exception(ctx, POWERPC_EXCP_VPU); \
6702 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6703 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6706 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16);
6707 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17);
6708 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18);
6709 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19);
6710 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20);
6712 #define GEN_VXFORM(name, opc2, opc3) \
6713 static void glue(gen_, name)(DisasContext *ctx) \
6715 TCGv_ptr ra, rb, rd; \
6716 if (unlikely(!ctx->altivec_enabled)) { \
6717 gen_exception(ctx, POWERPC_EXCP_VPU); \
6720 ra = gen_avr_ptr(rA(ctx->opcode)); \
6721 rb = gen_avr_ptr(rB(ctx->opcode)); \
6722 rd = gen_avr_ptr(rD(ctx->opcode)); \
6723 gen_helper_##name (rd, ra, rb); \
6724 tcg_temp_free_ptr(ra); \
6725 tcg_temp_free_ptr(rb); \
6726 tcg_temp_free_ptr(rd); \
6729 #define GEN_VXFORM_ENV(name, opc2, opc3) \
6730 static void glue(gen_, name)(DisasContext *ctx) \
6732 TCGv_ptr ra, rb, rd; \
6733 if (unlikely(!ctx->altivec_enabled)) { \
6734 gen_exception(ctx, POWERPC_EXCP_VPU); \
6737 ra = gen_avr_ptr(rA(ctx->opcode)); \
6738 rb = gen_avr_ptr(rB(ctx->opcode)); \
6739 rd = gen_avr_ptr(rD(ctx->opcode)); \
6740 gen_helper_##name(cpu_env, rd, ra, rb); \
6741 tcg_temp_free_ptr(ra); \
6742 tcg_temp_free_ptr(rb); \
6743 tcg_temp_free_ptr(rd); \
6746 GEN_VXFORM(vaddubm
, 0, 0);
6747 GEN_VXFORM(vadduhm
, 0, 1);
6748 GEN_VXFORM(vadduwm
, 0, 2);
6749 GEN_VXFORM(vsububm
, 0, 16);
6750 GEN_VXFORM(vsubuhm
, 0, 17);
6751 GEN_VXFORM(vsubuwm
, 0, 18);
6752 GEN_VXFORM(vmaxub
, 1, 0);
6753 GEN_VXFORM(vmaxuh
, 1, 1);
6754 GEN_VXFORM(vmaxuw
, 1, 2);
6755 GEN_VXFORM(vmaxsb
, 1, 4);
6756 GEN_VXFORM(vmaxsh
, 1, 5);
6757 GEN_VXFORM(vmaxsw
, 1, 6);
6758 GEN_VXFORM(vminub
, 1, 8);
6759 GEN_VXFORM(vminuh
, 1, 9);
6760 GEN_VXFORM(vminuw
, 1, 10);
6761 GEN_VXFORM(vminsb
, 1, 12);
6762 GEN_VXFORM(vminsh
, 1, 13);
6763 GEN_VXFORM(vminsw
, 1, 14);
6764 GEN_VXFORM(vavgub
, 1, 16);
6765 GEN_VXFORM(vavguh
, 1, 17);
6766 GEN_VXFORM(vavguw
, 1, 18);
6767 GEN_VXFORM(vavgsb
, 1, 20);
6768 GEN_VXFORM(vavgsh
, 1, 21);
6769 GEN_VXFORM(vavgsw
, 1, 22);
6770 GEN_VXFORM(vmrghb
, 6, 0);
6771 GEN_VXFORM(vmrghh
, 6, 1);
6772 GEN_VXFORM(vmrghw
, 6, 2);
6773 GEN_VXFORM(vmrglb
, 6, 4);
6774 GEN_VXFORM(vmrglh
, 6, 5);
6775 GEN_VXFORM(vmrglw
, 6, 6);
6776 GEN_VXFORM(vmuloub
, 4, 0);
6777 GEN_VXFORM(vmulouh
, 4, 1);
6778 GEN_VXFORM(vmulosb
, 4, 4);
6779 GEN_VXFORM(vmulosh
, 4, 5);
6780 GEN_VXFORM(vmuleub
, 4, 8);
6781 GEN_VXFORM(vmuleuh
, 4, 9);
6782 GEN_VXFORM(vmulesb
, 4, 12);
6783 GEN_VXFORM(vmulesh
, 4, 13);
6784 GEN_VXFORM(vslb
, 2, 4);
6785 GEN_VXFORM(vslh
, 2, 5);
6786 GEN_VXFORM(vslw
, 2, 6);
6787 GEN_VXFORM(vsrb
, 2, 8);
6788 GEN_VXFORM(vsrh
, 2, 9);
6789 GEN_VXFORM(vsrw
, 2, 10);
6790 GEN_VXFORM(vsrab
, 2, 12);
6791 GEN_VXFORM(vsrah
, 2, 13);
6792 GEN_VXFORM(vsraw
, 2, 14);
6793 GEN_VXFORM(vslo
, 6, 16);
6794 GEN_VXFORM(vsro
, 6, 17);
6795 GEN_VXFORM(vaddcuw
, 0, 6);
6796 GEN_VXFORM(vsubcuw
, 0, 22);
6797 GEN_VXFORM_ENV(vaddubs
, 0, 8);
6798 GEN_VXFORM_ENV(vadduhs
, 0, 9);
6799 GEN_VXFORM_ENV(vadduws
, 0, 10);
6800 GEN_VXFORM_ENV(vaddsbs
, 0, 12);
6801 GEN_VXFORM_ENV(vaddshs
, 0, 13);
6802 GEN_VXFORM_ENV(vaddsws
, 0, 14);
6803 GEN_VXFORM_ENV(vsububs
, 0, 24);
6804 GEN_VXFORM_ENV(vsubuhs
, 0, 25);
6805 GEN_VXFORM_ENV(vsubuws
, 0, 26);
6806 GEN_VXFORM_ENV(vsubsbs
, 0, 28);
6807 GEN_VXFORM_ENV(vsubshs
, 0, 29);
6808 GEN_VXFORM_ENV(vsubsws
, 0, 30);
6809 GEN_VXFORM(vrlb
, 2, 0);
6810 GEN_VXFORM(vrlh
, 2, 1);
6811 GEN_VXFORM(vrlw
, 2, 2);
6812 GEN_VXFORM(vsl
, 2, 7);
6813 GEN_VXFORM(vsr
, 2, 11);
6814 GEN_VXFORM_ENV(vpkuhum
, 7, 0);
6815 GEN_VXFORM_ENV(vpkuwum
, 7, 1);
6816 GEN_VXFORM_ENV(vpkuhus
, 7, 2);
6817 GEN_VXFORM_ENV(vpkuwus
, 7, 3);
6818 GEN_VXFORM_ENV(vpkshus
, 7, 4);
6819 GEN_VXFORM_ENV(vpkswus
, 7, 5);
6820 GEN_VXFORM_ENV(vpkshss
, 7, 6);
6821 GEN_VXFORM_ENV(vpkswss
, 7, 7);
6822 GEN_VXFORM(vpkpx
, 7, 12);
6823 GEN_VXFORM_ENV(vsum4ubs
, 4, 24);
6824 GEN_VXFORM_ENV(vsum4sbs
, 4, 28);
6825 GEN_VXFORM_ENV(vsum4shs
, 4, 25);
6826 GEN_VXFORM_ENV(vsum2sws
, 4, 26);
6827 GEN_VXFORM_ENV(vsumsws
, 4, 30);
6828 GEN_VXFORM_ENV(vaddfp
, 5, 0);
6829 GEN_VXFORM_ENV(vsubfp
, 5, 1);
6830 GEN_VXFORM_ENV(vmaxfp
, 5, 16);
6831 GEN_VXFORM_ENV(vminfp
, 5, 17);
6833 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
6834 static void glue(gen_, name)(DisasContext *ctx) \
6836 TCGv_ptr ra, rb, rd; \
6837 if (unlikely(!ctx->altivec_enabled)) { \
6838 gen_exception(ctx, POWERPC_EXCP_VPU); \
6841 ra = gen_avr_ptr(rA(ctx->opcode)); \
6842 rb = gen_avr_ptr(rB(ctx->opcode)); \
6843 rd = gen_avr_ptr(rD(ctx->opcode)); \
6844 gen_helper_##opname(cpu_env, rd, ra, rb); \
6845 tcg_temp_free_ptr(ra); \
6846 tcg_temp_free_ptr(rb); \
6847 tcg_temp_free_ptr(rd); \
6850 #define GEN_VXRFORM(name, opc2, opc3) \
6851 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
6852 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
6854 GEN_VXRFORM(vcmpequb
, 3, 0)
6855 GEN_VXRFORM(vcmpequh
, 3, 1)
6856 GEN_VXRFORM(vcmpequw
, 3, 2)
6857 GEN_VXRFORM(vcmpgtsb
, 3, 12)
6858 GEN_VXRFORM(vcmpgtsh
, 3, 13)
6859 GEN_VXRFORM(vcmpgtsw
, 3, 14)
6860 GEN_VXRFORM(vcmpgtub
, 3, 8)
6861 GEN_VXRFORM(vcmpgtuh
, 3, 9)
6862 GEN_VXRFORM(vcmpgtuw
, 3, 10)
6863 GEN_VXRFORM(vcmpeqfp
, 3, 3)
6864 GEN_VXRFORM(vcmpgefp
, 3, 7)
6865 GEN_VXRFORM(vcmpgtfp
, 3, 11)
6866 GEN_VXRFORM(vcmpbfp
, 3, 15)
6868 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
6869 static void glue(gen_, name)(DisasContext *ctx) \
6873 if (unlikely(!ctx->altivec_enabled)) { \
6874 gen_exception(ctx, POWERPC_EXCP_VPU); \
6877 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6878 rd = gen_avr_ptr(rD(ctx->opcode)); \
6879 gen_helper_##name (rd, simm); \
6880 tcg_temp_free_i32(simm); \
6881 tcg_temp_free_ptr(rd); \
6884 GEN_VXFORM_SIMM(vspltisb
, 6, 12);
6885 GEN_VXFORM_SIMM(vspltish
, 6, 13);
6886 GEN_VXFORM_SIMM(vspltisw
, 6, 14);
6888 #define GEN_VXFORM_NOA(name, opc2, opc3) \
6889 static void glue(gen_, name)(DisasContext *ctx) \
6892 if (unlikely(!ctx->altivec_enabled)) { \
6893 gen_exception(ctx, POWERPC_EXCP_VPU); \
6896 rb = gen_avr_ptr(rB(ctx->opcode)); \
6897 rd = gen_avr_ptr(rD(ctx->opcode)); \
6898 gen_helper_##name (rd, rb); \
6899 tcg_temp_free_ptr(rb); \
6900 tcg_temp_free_ptr(rd); \
6903 #define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
6904 static void glue(gen_, name)(DisasContext *ctx) \
6908 if (unlikely(!ctx->altivec_enabled)) { \
6909 gen_exception(ctx, POWERPC_EXCP_VPU); \
6912 rb = gen_avr_ptr(rB(ctx->opcode)); \
6913 rd = gen_avr_ptr(rD(ctx->opcode)); \
6914 gen_helper_##name(cpu_env, rd, rb); \
6915 tcg_temp_free_ptr(rb); \
6916 tcg_temp_free_ptr(rd); \
6919 GEN_VXFORM_NOA(vupkhsb
, 7, 8);
6920 GEN_VXFORM_NOA(vupkhsh
, 7, 9);
6921 GEN_VXFORM_NOA(vupklsb
, 7, 10);
6922 GEN_VXFORM_NOA(vupklsh
, 7, 11);
6923 GEN_VXFORM_NOA(vupkhpx
, 7, 13);
6924 GEN_VXFORM_NOA(vupklpx
, 7, 15);
6925 GEN_VXFORM_NOA_ENV(vrefp
, 5, 4);
6926 GEN_VXFORM_NOA_ENV(vrsqrtefp
, 5, 5);
6927 GEN_VXFORM_NOA_ENV(vexptefp
, 5, 6);
6928 GEN_VXFORM_NOA_ENV(vlogefp
, 5, 7);
6929 GEN_VXFORM_NOA_ENV(vrfim
, 5, 8);
6930 GEN_VXFORM_NOA_ENV(vrfin
, 5, 9);
6931 GEN_VXFORM_NOA_ENV(vrfip
, 5, 10);
6932 GEN_VXFORM_NOA_ENV(vrfiz
, 5, 11);
6934 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
6935 static void glue(gen_, name)(DisasContext *ctx) \
6939 if (unlikely(!ctx->altivec_enabled)) { \
6940 gen_exception(ctx, POWERPC_EXCP_VPU); \
6943 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6944 rd = gen_avr_ptr(rD(ctx->opcode)); \
6945 gen_helper_##name (rd, simm); \
6946 tcg_temp_free_i32(simm); \
6947 tcg_temp_free_ptr(rd); \
6950 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
6951 static void glue(gen_, name)(DisasContext *ctx) \
6955 if (unlikely(!ctx->altivec_enabled)) { \
6956 gen_exception(ctx, POWERPC_EXCP_VPU); \
6959 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
6960 rb = gen_avr_ptr(rB(ctx->opcode)); \
6961 rd = gen_avr_ptr(rD(ctx->opcode)); \
6962 gen_helper_##name (rd, rb, uimm); \
6963 tcg_temp_free_i32(uimm); \
6964 tcg_temp_free_ptr(rb); \
6965 tcg_temp_free_ptr(rd); \
6968 #define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
6969 static void glue(gen_, name)(DisasContext *ctx) \
6974 if (unlikely(!ctx->altivec_enabled)) { \
6975 gen_exception(ctx, POWERPC_EXCP_VPU); \
6978 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
6979 rb = gen_avr_ptr(rB(ctx->opcode)); \
6980 rd = gen_avr_ptr(rD(ctx->opcode)); \
6981 gen_helper_##name(cpu_env, rd, rb, uimm); \
6982 tcg_temp_free_i32(uimm); \
6983 tcg_temp_free_ptr(rb); \
6984 tcg_temp_free_ptr(rd); \
6987 GEN_VXFORM_UIMM(vspltb
, 6, 8);
6988 GEN_VXFORM_UIMM(vsplth
, 6, 9);
6989 GEN_VXFORM_UIMM(vspltw
, 6, 10);
6990 GEN_VXFORM_UIMM_ENV(vcfux
, 5, 12);
6991 GEN_VXFORM_UIMM_ENV(vcfsx
, 5, 13);
6992 GEN_VXFORM_UIMM_ENV(vctuxs
, 5, 14);
6993 GEN_VXFORM_UIMM_ENV(vctsxs
, 5, 15);
6995 static void gen_vsldoi(DisasContext
*ctx
)
6997 TCGv_ptr ra
, rb
, rd
;
6999 if (unlikely(!ctx
->altivec_enabled
)) {
7000 gen_exception(ctx
, POWERPC_EXCP_VPU
);
7003 ra
= gen_avr_ptr(rA(ctx
->opcode
));
7004 rb
= gen_avr_ptr(rB(ctx
->opcode
));
7005 rd
= gen_avr_ptr(rD(ctx
->opcode
));
7006 sh
= tcg_const_i32(VSH(ctx
->opcode
));
7007 gen_helper_vsldoi (rd
, ra
, rb
, sh
);
7008 tcg_temp_free_ptr(ra
);
7009 tcg_temp_free_ptr(rb
);
7010 tcg_temp_free_ptr(rd
);
7011 tcg_temp_free_i32(sh
);
7014 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
7015 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7017 TCGv_ptr ra, rb, rc, rd; \
7018 if (unlikely(!ctx->altivec_enabled)) { \
7019 gen_exception(ctx, POWERPC_EXCP_VPU); \
7022 ra = gen_avr_ptr(rA(ctx->opcode)); \
7023 rb = gen_avr_ptr(rB(ctx->opcode)); \
7024 rc = gen_avr_ptr(rC(ctx->opcode)); \
7025 rd = gen_avr_ptr(rD(ctx->opcode)); \
7026 if (Rc(ctx->opcode)) { \
7027 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
7029 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
7031 tcg_temp_free_ptr(ra); \
7032 tcg_temp_free_ptr(rb); \
7033 tcg_temp_free_ptr(rc); \
7034 tcg_temp_free_ptr(rd); \
7037 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16)
7039 static void gen_vmladduhm(DisasContext
*ctx
)
7041 TCGv_ptr ra
, rb
, rc
, rd
;
7042 if (unlikely(!ctx
->altivec_enabled
)) {
7043 gen_exception(ctx
, POWERPC_EXCP_VPU
);
7046 ra
= gen_avr_ptr(rA(ctx
->opcode
));
7047 rb
= gen_avr_ptr(rB(ctx
->opcode
));
7048 rc
= gen_avr_ptr(rC(ctx
->opcode
));
7049 rd
= gen_avr_ptr(rD(ctx
->opcode
));
7050 gen_helper_vmladduhm(rd
, ra
, rb
, rc
);
7051 tcg_temp_free_ptr(ra
);
7052 tcg_temp_free_ptr(rb
);
7053 tcg_temp_free_ptr(rc
);
7054 tcg_temp_free_ptr(rd
);
7057 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18)
7058 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19)
7059 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20)
7060 GEN_VAFORM_PAIRED(vsel
, vperm
, 21)
7061 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23)
7063 /*** VSX extension ***/
7065 static inline TCGv_i64
cpu_vsrh(int n
)
7070 return cpu_avrh
[n
-32];
7074 static inline TCGv_i64
cpu_vsrl(int n
)
7079 return cpu_avrl
[n
-32];
7083 #define VSX_LOAD_SCALAR(name, operation) \
7084 static void gen_##name(DisasContext *ctx) \
7087 if (unlikely(!ctx->vsx_enabled)) { \
7088 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7091 gen_set_access_type(ctx, ACCESS_INT); \
7092 EA = tcg_temp_new(); \
7093 gen_addr_reg_index(ctx, EA); \
7094 gen_qemu_##operation(ctx, cpu_vsrh(xT(ctx->opcode)), EA); \
7095 /* NOTE: cpu_vsrl is undefined */ \
7096 tcg_temp_free(EA); \
7099 VSX_LOAD_SCALAR(lxsdx
, ld64
)
7100 VSX_LOAD_SCALAR(lxsiwax
, ld32s_i64
)
7101 VSX_LOAD_SCALAR(lxsiwzx
, ld32u_i64
)
7102 VSX_LOAD_SCALAR(lxsspx
, ld32fs
)
7104 static void gen_lxvd2x(DisasContext
*ctx
)
7107 if (unlikely(!ctx
->vsx_enabled
)) {
7108 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7111 gen_set_access_type(ctx
, ACCESS_INT
);
7112 EA
= tcg_temp_new();
7113 gen_addr_reg_index(ctx
, EA
);
7114 gen_qemu_ld64(ctx
, cpu_vsrh(xT(ctx
->opcode
)), EA
);
7115 tcg_gen_addi_tl(EA
, EA
, 8);
7116 gen_qemu_ld64(ctx
, cpu_vsrl(xT(ctx
->opcode
)), EA
);
7120 static void gen_lxvdsx(DisasContext
*ctx
)
7123 if (unlikely(!ctx
->vsx_enabled
)) {
7124 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7127 gen_set_access_type(ctx
, ACCESS_INT
);
7128 EA
= tcg_temp_new();
7129 gen_addr_reg_index(ctx
, EA
);
7130 gen_qemu_ld64(ctx
, cpu_vsrh(xT(ctx
->opcode
)), EA
);
7131 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), cpu_vsrh(xT(ctx
->opcode
)));
7135 static void gen_lxvw4x(DisasContext
*ctx
)
7139 TCGv_i64 xth
= cpu_vsrh(xT(ctx
->opcode
));
7140 TCGv_i64 xtl
= cpu_vsrl(xT(ctx
->opcode
));
7141 if (unlikely(!ctx
->vsx_enabled
)) {
7142 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7145 gen_set_access_type(ctx
, ACCESS_INT
);
7146 EA
= tcg_temp_new();
7147 tmp
= tcg_temp_new_i64();
7149 gen_addr_reg_index(ctx
, EA
);
7150 gen_qemu_ld32u_i64(ctx
, tmp
, EA
);
7151 tcg_gen_addi_tl(EA
, EA
, 4);
7152 gen_qemu_ld32u_i64(ctx
, xth
, EA
);
7153 tcg_gen_deposit_i64(xth
, xth
, tmp
, 32, 32);
7155 tcg_gen_addi_tl(EA
, EA
, 4);
7156 gen_qemu_ld32u_i64(ctx
, tmp
, EA
);
7157 tcg_gen_addi_tl(EA
, EA
, 4);
7158 gen_qemu_ld32u_i64(ctx
, xtl
, EA
);
7159 tcg_gen_deposit_i64(xtl
, xtl
, tmp
, 32, 32);
7162 tcg_temp_free_i64(tmp
);
7165 #define VSX_STORE_SCALAR(name, operation) \
7166 static void gen_##name(DisasContext *ctx) \
7169 if (unlikely(!ctx->vsx_enabled)) { \
7170 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7173 gen_set_access_type(ctx, ACCESS_INT); \
7174 EA = tcg_temp_new(); \
7175 gen_addr_reg_index(ctx, EA); \
7176 gen_qemu_##operation(ctx, cpu_vsrh(xS(ctx->opcode)), EA); \
7177 tcg_temp_free(EA); \
7180 VSX_STORE_SCALAR(stxsdx
, st64
)
7181 VSX_STORE_SCALAR(stxsiwx
, st32_i64
)
7182 VSX_STORE_SCALAR(stxsspx
, st32fs
)
7184 static void gen_stxvd2x(DisasContext
*ctx
)
7187 if (unlikely(!ctx
->vsx_enabled
)) {
7188 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7191 gen_set_access_type(ctx
, ACCESS_INT
);
7192 EA
= tcg_temp_new();
7193 gen_addr_reg_index(ctx
, EA
);
7194 gen_qemu_st64(ctx
, cpu_vsrh(xS(ctx
->opcode
)), EA
);
7195 tcg_gen_addi_tl(EA
, EA
, 8);
7196 gen_qemu_st64(ctx
, cpu_vsrl(xS(ctx
->opcode
)), EA
);
7200 static void gen_stxvw4x(DisasContext
*ctx
)
7204 if (unlikely(!ctx
->vsx_enabled
)) {
7205 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7208 gen_set_access_type(ctx
, ACCESS_INT
);
7209 EA
= tcg_temp_new();
7210 gen_addr_reg_index(ctx
, EA
);
7211 tmp
= tcg_temp_new_i64();
7213 tcg_gen_shri_i64(tmp
, cpu_vsrh(xS(ctx
->opcode
)), 32);
7214 gen_qemu_st32_i64(ctx
, tmp
, EA
);
7215 tcg_gen_addi_tl(EA
, EA
, 4);
7216 gen_qemu_st32_i64(ctx
, cpu_vsrh(xS(ctx
->opcode
)), EA
);
7218 tcg_gen_shri_i64(tmp
, cpu_vsrl(xS(ctx
->opcode
)), 32);
7219 tcg_gen_addi_tl(EA
, EA
, 4);
7220 gen_qemu_st32_i64(ctx
, tmp
, EA
);
7221 tcg_gen_addi_tl(EA
, EA
, 4);
7222 gen_qemu_st32_i64(ctx
, cpu_vsrl(xS(ctx
->opcode
)), EA
);
7225 tcg_temp_free_i64(tmp
);
7228 #define MV_VSRW(name, tcgop1, tcgop2, target, source) \
7229 static void gen_##name(DisasContext *ctx) \
7231 if (xS(ctx->opcode) < 32) { \
7232 if (unlikely(!ctx->fpu_enabled)) { \
7233 gen_exception(ctx, POWERPC_EXCP_FPU); \
7237 if (unlikely(!ctx->altivec_enabled)) { \
7238 gen_exception(ctx, POWERPC_EXCP_VPU); \
7242 TCGv_i64 tmp = tcg_temp_new_i64(); \
7243 tcg_gen_##tcgop1(tmp, source); \
7244 tcg_gen_##tcgop2(target, tmp); \
7245 tcg_temp_free_i64(tmp); \
7249 MV_VSRW(mfvsrwz
, ext32u_i64
, trunc_i64_tl
, cpu_gpr
[rA(ctx
->opcode
)], \
7250 cpu_vsrh(xS(ctx
->opcode
)))
7251 MV_VSRW(mtvsrwa
, extu_tl_i64
, ext32s_i64
, cpu_vsrh(xT(ctx
->opcode
)), \
7252 cpu_gpr
[rA(ctx
->opcode
)])
7253 MV_VSRW(mtvsrwz
, extu_tl_i64
, ext32u_i64
, cpu_vsrh(xT(ctx
->opcode
)), \
7254 cpu_gpr
[rA(ctx
->opcode
)])
7256 #if defined(TARGET_PPC64)
7257 #define MV_VSRD(name, target, source) \
7258 static void gen_##name(DisasContext *ctx) \
7260 if (xS(ctx->opcode) < 32) { \
7261 if (unlikely(!ctx->fpu_enabled)) { \
7262 gen_exception(ctx, POWERPC_EXCP_FPU); \
7266 if (unlikely(!ctx->altivec_enabled)) { \
7267 gen_exception(ctx, POWERPC_EXCP_VPU); \
7271 tcg_gen_mov_i64(target, source); \
7274 MV_VSRD(mfvsrd
, cpu_gpr
[rA(ctx
->opcode
)], cpu_vsrh(xS(ctx
->opcode
)))
7275 MV_VSRD(mtvsrd
, cpu_vsrh(xT(ctx
->opcode
)), cpu_gpr
[rA(ctx
->opcode
)])
7279 static void gen_xxpermdi(DisasContext
*ctx
)
7281 if (unlikely(!ctx
->vsx_enabled
)) {
7282 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7286 if ((DM(ctx
->opcode
) & 2) == 0) {
7287 tcg_gen_mov_i64(cpu_vsrh(xT(ctx
->opcode
)), cpu_vsrh(xA(ctx
->opcode
)));
7289 tcg_gen_mov_i64(cpu_vsrh(xT(ctx
->opcode
)), cpu_vsrl(xA(ctx
->opcode
)));
7291 if ((DM(ctx
->opcode
) & 1) == 0) {
7292 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), cpu_vsrh(xB(ctx
->opcode
)));
7294 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), cpu_vsrl(xB(ctx
->opcode
)));
7302 #define SGN_MASK_DP 0x8000000000000000ul
7303 #define SGN_MASK_SP 0x8000000080000000ul
7305 #define VSX_SCALAR_MOVE(name, op, sgn_mask) \
7306 static void glue(gen_, name)(DisasContext * ctx) \
7309 if (unlikely(!ctx->vsx_enabled)) { \
7310 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7313 xb = tcg_temp_new_i64(); \
7314 sgm = tcg_temp_new_i64(); \
7315 tcg_gen_mov_i64(xb, cpu_vsrh(xB(ctx->opcode))); \
7316 tcg_gen_movi_i64(sgm, sgn_mask); \
7319 tcg_gen_andc_i64(xb, xb, sgm); \
7323 tcg_gen_or_i64(xb, xb, sgm); \
7327 tcg_gen_xor_i64(xb, xb, sgm); \
7331 TCGv_i64 xa = tcg_temp_new_i64(); \
7332 tcg_gen_mov_i64(xa, cpu_vsrh(xA(ctx->opcode))); \
7333 tcg_gen_and_i64(xa, xa, sgm); \
7334 tcg_gen_andc_i64(xb, xb, sgm); \
7335 tcg_gen_or_i64(xb, xb, xa); \
7336 tcg_temp_free_i64(xa); \
7340 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xb); \
7341 tcg_temp_free_i64(xb); \
7342 tcg_temp_free_i64(sgm); \
7345 VSX_SCALAR_MOVE(xsabsdp
, OP_ABS
, SGN_MASK_DP
)
7346 VSX_SCALAR_MOVE(xsnabsdp
, OP_NABS
, SGN_MASK_DP
)
7347 VSX_SCALAR_MOVE(xsnegdp
, OP_NEG
, SGN_MASK_DP
)
7348 VSX_SCALAR_MOVE(xscpsgndp
, OP_CPSGN
, SGN_MASK_DP
)
7350 #define VSX_VECTOR_MOVE(name, op, sgn_mask) \
7351 static void glue(gen_, name)(DisasContext * ctx) \
7353 TCGv_i64 xbh, xbl, sgm; \
7354 if (unlikely(!ctx->vsx_enabled)) { \
7355 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7358 xbh = tcg_temp_new_i64(); \
7359 xbl = tcg_temp_new_i64(); \
7360 sgm = tcg_temp_new_i64(); \
7361 tcg_gen_mov_i64(xbh, cpu_vsrh(xB(ctx->opcode))); \
7362 tcg_gen_mov_i64(xbl, cpu_vsrl(xB(ctx->opcode))); \
7363 tcg_gen_movi_i64(sgm, sgn_mask); \
7366 tcg_gen_andc_i64(xbh, xbh, sgm); \
7367 tcg_gen_andc_i64(xbl, xbl, sgm); \
7371 tcg_gen_or_i64(xbh, xbh, sgm); \
7372 tcg_gen_or_i64(xbl, xbl, sgm); \
7376 tcg_gen_xor_i64(xbh, xbh, sgm); \
7377 tcg_gen_xor_i64(xbl, xbl, sgm); \
7381 TCGv_i64 xah = tcg_temp_new_i64(); \
7382 TCGv_i64 xal = tcg_temp_new_i64(); \
7383 tcg_gen_mov_i64(xah, cpu_vsrh(xA(ctx->opcode))); \
7384 tcg_gen_mov_i64(xal, cpu_vsrl(xA(ctx->opcode))); \
7385 tcg_gen_and_i64(xah, xah, sgm); \
7386 tcg_gen_and_i64(xal, xal, sgm); \
7387 tcg_gen_andc_i64(xbh, xbh, sgm); \
7388 tcg_gen_andc_i64(xbl, xbl, sgm); \
7389 tcg_gen_or_i64(xbh, xbh, xah); \
7390 tcg_gen_or_i64(xbl, xbl, xal); \
7391 tcg_temp_free_i64(xah); \
7392 tcg_temp_free_i64(xal); \
7396 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xbh); \
7397 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xbl); \
7398 tcg_temp_free_i64(xbh); \
7399 tcg_temp_free_i64(xbl); \
7400 tcg_temp_free_i64(sgm); \
7403 VSX_VECTOR_MOVE(xvabsdp
, OP_ABS
, SGN_MASK_DP
)
7404 VSX_VECTOR_MOVE(xvnabsdp
, OP_NABS
, SGN_MASK_DP
)
7405 VSX_VECTOR_MOVE(xvnegdp
, OP_NEG
, SGN_MASK_DP
)
7406 VSX_VECTOR_MOVE(xvcpsgndp
, OP_CPSGN
, SGN_MASK_DP
)
7407 VSX_VECTOR_MOVE(xvabssp
, OP_ABS
, SGN_MASK_SP
)
7408 VSX_VECTOR_MOVE(xvnabssp
, OP_NABS
, SGN_MASK_SP
)
7409 VSX_VECTOR_MOVE(xvnegsp
, OP_NEG
, SGN_MASK_SP
)
7410 VSX_VECTOR_MOVE(xvcpsgnsp
, OP_CPSGN
, SGN_MASK_SP
)
7412 #define GEN_VSX_HELPER_2(name, op1, op2, inval, type) \
7413 static void gen_##name(DisasContext * ctx) \
7416 if (unlikely(!ctx->vsx_enabled)) { \
7417 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7420 /* NIP cannot be restored if the memory exception comes from an helper */ \
7421 gen_update_nip(ctx, ctx->nip - 4); \
7422 opc = tcg_const_i32(ctx->opcode); \
7423 gen_helper_##name(cpu_env, opc); \
7424 tcg_temp_free_i32(opc); \
7427 #define GEN_VSX_HELPER_XT_XB_ENV(name, op1, op2, inval, type) \
7428 static void gen_##name(DisasContext * ctx) \
7430 if (unlikely(!ctx->vsx_enabled)) { \
7431 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7434 /* NIP cannot be restored if the exception comes */ \
7435 /* from a helper. */ \
7436 gen_update_nip(ctx, ctx->nip - 4); \
7438 gen_helper_##name(cpu_vsrh(xT(ctx->opcode)), cpu_env, \
7439 cpu_vsrh(xB(ctx->opcode))); \
7442 GEN_VSX_HELPER_2(xsadddp
, 0x00, 0x04, 0, PPC2_VSX
)
7443 GEN_VSX_HELPER_2(xssubdp
, 0x00, 0x05, 0, PPC2_VSX
)
7444 GEN_VSX_HELPER_2(xsmuldp
, 0x00, 0x06, 0, PPC2_VSX
)
7445 GEN_VSX_HELPER_2(xsdivdp
, 0x00, 0x07, 0, PPC2_VSX
)
7446 GEN_VSX_HELPER_2(xsredp
, 0x14, 0x05, 0, PPC2_VSX
)
7447 GEN_VSX_HELPER_2(xssqrtdp
, 0x16, 0x04, 0, PPC2_VSX
)
7448 GEN_VSX_HELPER_2(xsrsqrtedp
, 0x14, 0x04, 0, PPC2_VSX
)
7449 GEN_VSX_HELPER_2(xstdivdp
, 0x14, 0x07, 0, PPC2_VSX
)
7450 GEN_VSX_HELPER_2(xstsqrtdp
, 0x14, 0x06, 0, PPC2_VSX
)
7451 GEN_VSX_HELPER_2(xsmaddadp
, 0x04, 0x04, 0, PPC2_VSX
)
7452 GEN_VSX_HELPER_2(xsmaddmdp
, 0x04, 0x05, 0, PPC2_VSX
)
7453 GEN_VSX_HELPER_2(xsmsubadp
, 0x04, 0x06, 0, PPC2_VSX
)
7454 GEN_VSX_HELPER_2(xsmsubmdp
, 0x04, 0x07, 0, PPC2_VSX
)
7455 GEN_VSX_HELPER_2(xsnmaddadp
, 0x04, 0x14, 0, PPC2_VSX
)
7456 GEN_VSX_HELPER_2(xsnmaddmdp
, 0x04, 0x15, 0, PPC2_VSX
)
7457 GEN_VSX_HELPER_2(xsnmsubadp
, 0x04, 0x16, 0, PPC2_VSX
)
7458 GEN_VSX_HELPER_2(xsnmsubmdp
, 0x04, 0x17, 0, PPC2_VSX
)
7459 GEN_VSX_HELPER_2(xscmpodp
, 0x0C, 0x05, 0, PPC2_VSX
)
7460 GEN_VSX_HELPER_2(xscmpudp
, 0x0C, 0x04, 0, PPC2_VSX
)
7461 GEN_VSX_HELPER_2(xsmaxdp
, 0x00, 0x14, 0, PPC2_VSX
)
7462 GEN_VSX_HELPER_2(xsmindp
, 0x00, 0x15, 0, PPC2_VSX
)
7463 GEN_VSX_HELPER_2(xscvdpsp
, 0x12, 0x10, 0, PPC2_VSX
)
7464 GEN_VSX_HELPER_XT_XB_ENV(xscvdpspn
, 0x16, 0x10, 0, PPC2_VSX207
)
7465 GEN_VSX_HELPER_2(xscvspdp
, 0x12, 0x14, 0, PPC2_VSX
)
7466 GEN_VSX_HELPER_XT_XB_ENV(xscvspdpn
, 0x16, 0x14, 0, PPC2_VSX207
)
7467 GEN_VSX_HELPER_2(xscvdpsxds
, 0x10, 0x15, 0, PPC2_VSX
)
7468 GEN_VSX_HELPER_2(xscvdpsxws
, 0x10, 0x05, 0, PPC2_VSX
)
7469 GEN_VSX_HELPER_2(xscvdpuxds
, 0x10, 0x14, 0, PPC2_VSX
)
7470 GEN_VSX_HELPER_2(xscvdpuxws
, 0x10, 0x04, 0, PPC2_VSX
)
7471 GEN_VSX_HELPER_2(xscvsxddp
, 0x10, 0x17, 0, PPC2_VSX
)
7472 GEN_VSX_HELPER_2(xscvuxddp
, 0x10, 0x16, 0, PPC2_VSX
)
7473 GEN_VSX_HELPER_2(xsrdpi
, 0x12, 0x04, 0, PPC2_VSX
)
7474 GEN_VSX_HELPER_2(xsrdpic
, 0x16, 0x06, 0, PPC2_VSX
)
7475 GEN_VSX_HELPER_2(xsrdpim
, 0x12, 0x07, 0, PPC2_VSX
)
7476 GEN_VSX_HELPER_2(xsrdpip
, 0x12, 0x06, 0, PPC2_VSX
)
7477 GEN_VSX_HELPER_2(xsrdpiz
, 0x12, 0x05, 0, PPC2_VSX
)
7478 GEN_VSX_HELPER_XT_XB_ENV(xsrsp
, 0x12, 0x11, 0, PPC2_VSX207
)
7480 GEN_VSX_HELPER_2(xsaddsp
, 0x00, 0x00, 0, PPC2_VSX207
)
7481 GEN_VSX_HELPER_2(xssubsp
, 0x00, 0x01, 0, PPC2_VSX207
)
7482 GEN_VSX_HELPER_2(xsmulsp
, 0x00, 0x02, 0, PPC2_VSX207
)
7483 GEN_VSX_HELPER_2(xsdivsp
, 0x00, 0x03, 0, PPC2_VSX207
)
7484 GEN_VSX_HELPER_2(xsresp
, 0x14, 0x01, 0, PPC2_VSX207
)
7485 GEN_VSX_HELPER_2(xssqrtsp
, 0x16, 0x00, 0, PPC2_VSX207
)
7486 GEN_VSX_HELPER_2(xsrsqrtesp
, 0x14, 0x00, 0, PPC2_VSX207
)
7487 GEN_VSX_HELPER_2(xsmaddasp
, 0x04, 0x00, 0, PPC2_VSX207
)
7488 GEN_VSX_HELPER_2(xsmaddmsp
, 0x04, 0x01, 0, PPC2_VSX207
)
7489 GEN_VSX_HELPER_2(xsmsubasp
, 0x04, 0x02, 0, PPC2_VSX207
)
7490 GEN_VSX_HELPER_2(xsmsubmsp
, 0x04, 0x03, 0, PPC2_VSX207
)
7491 GEN_VSX_HELPER_2(xsnmaddasp
, 0x04, 0x10, 0, PPC2_VSX207
)
7492 GEN_VSX_HELPER_2(xsnmaddmsp
, 0x04, 0x11, 0, PPC2_VSX207
)
7493 GEN_VSX_HELPER_2(xsnmsubasp
, 0x04, 0x12, 0, PPC2_VSX207
)
7494 GEN_VSX_HELPER_2(xsnmsubmsp
, 0x04, 0x13, 0, PPC2_VSX207
)
7495 GEN_VSX_HELPER_2(xscvsxdsp
, 0x10, 0x13, 0, PPC2_VSX207
)
7496 GEN_VSX_HELPER_2(xscvuxdsp
, 0x10, 0x12, 0, PPC2_VSX207
)
7498 GEN_VSX_HELPER_2(xvadddp
, 0x00, 0x0C, 0, PPC2_VSX
)
7499 GEN_VSX_HELPER_2(xvsubdp
, 0x00, 0x0D, 0, PPC2_VSX
)
7500 GEN_VSX_HELPER_2(xvmuldp
, 0x00, 0x0E, 0, PPC2_VSX
)
7501 GEN_VSX_HELPER_2(xvdivdp
, 0x00, 0x0F, 0, PPC2_VSX
)
7502 GEN_VSX_HELPER_2(xvredp
, 0x14, 0x0D, 0, PPC2_VSX
)
7503 GEN_VSX_HELPER_2(xvsqrtdp
, 0x16, 0x0C, 0, PPC2_VSX
)
7504 GEN_VSX_HELPER_2(xvrsqrtedp
, 0x14, 0x0C, 0, PPC2_VSX
)
7505 GEN_VSX_HELPER_2(xvtdivdp
, 0x14, 0x0F, 0, PPC2_VSX
)
7506 GEN_VSX_HELPER_2(xvtsqrtdp
, 0x14, 0x0E, 0, PPC2_VSX
)
7507 GEN_VSX_HELPER_2(xvmaddadp
, 0x04, 0x0C, 0, PPC2_VSX
)
7508 GEN_VSX_HELPER_2(xvmaddmdp
, 0x04, 0x0D, 0, PPC2_VSX
)
7509 GEN_VSX_HELPER_2(xvmsubadp
, 0x04, 0x0E, 0, PPC2_VSX
)
7510 GEN_VSX_HELPER_2(xvmsubmdp
, 0x04, 0x0F, 0, PPC2_VSX
)
7511 GEN_VSX_HELPER_2(xvnmaddadp
, 0x04, 0x1C, 0, PPC2_VSX
)
7512 GEN_VSX_HELPER_2(xvnmaddmdp
, 0x04, 0x1D, 0, PPC2_VSX
)
7513 GEN_VSX_HELPER_2(xvnmsubadp
, 0x04, 0x1E, 0, PPC2_VSX
)
7514 GEN_VSX_HELPER_2(xvnmsubmdp
, 0x04, 0x1F, 0, PPC2_VSX
)
7515 GEN_VSX_HELPER_2(xvmaxdp
, 0x00, 0x1C, 0, PPC2_VSX
)
7516 GEN_VSX_HELPER_2(xvmindp
, 0x00, 0x1D, 0, PPC2_VSX
)
7517 GEN_VSX_HELPER_2(xvcmpeqdp
, 0x0C, 0x0C, 0, PPC2_VSX
)
7518 GEN_VSX_HELPER_2(xvcmpgtdp
, 0x0C, 0x0D, 0, PPC2_VSX
)
7519 GEN_VSX_HELPER_2(xvcmpgedp
, 0x0C, 0x0E, 0, PPC2_VSX
)
7520 GEN_VSX_HELPER_2(xvcvdpsp
, 0x12, 0x18, 0, PPC2_VSX
)
7521 GEN_VSX_HELPER_2(xvcvdpsxds
, 0x10, 0x1D, 0, PPC2_VSX
)
7522 GEN_VSX_HELPER_2(xvcvdpsxws
, 0x10, 0x0D, 0, PPC2_VSX
)
7523 GEN_VSX_HELPER_2(xvcvdpuxds
, 0x10, 0x1C, 0, PPC2_VSX
)
7524 GEN_VSX_HELPER_2(xvcvdpuxws
, 0x10, 0x0C, 0, PPC2_VSX
)
7525 GEN_VSX_HELPER_2(xvcvsxddp
, 0x10, 0x1F, 0, PPC2_VSX
)
7526 GEN_VSX_HELPER_2(xvcvuxddp
, 0x10, 0x1E, 0, PPC2_VSX
)
7527 GEN_VSX_HELPER_2(xvcvsxwdp
, 0x10, 0x0F, 0, PPC2_VSX
)
7528 GEN_VSX_HELPER_2(xvcvuxwdp
, 0x10, 0x0E, 0, PPC2_VSX
)
7529 GEN_VSX_HELPER_2(xvrdpi
, 0x12, 0x0C, 0, PPC2_VSX
)
7530 GEN_VSX_HELPER_2(xvrdpic
, 0x16, 0x0E, 0, PPC2_VSX
)
7531 GEN_VSX_HELPER_2(xvrdpim
, 0x12, 0x0F, 0, PPC2_VSX
)
7532 GEN_VSX_HELPER_2(xvrdpip
, 0x12, 0x0E, 0, PPC2_VSX
)
7533 GEN_VSX_HELPER_2(xvrdpiz
, 0x12, 0x0D, 0, PPC2_VSX
)
7535 GEN_VSX_HELPER_2(xvaddsp
, 0x00, 0x08, 0, PPC2_VSX
)
7536 GEN_VSX_HELPER_2(xvsubsp
, 0x00, 0x09, 0, PPC2_VSX
)
7537 GEN_VSX_HELPER_2(xvmulsp
, 0x00, 0x0A, 0, PPC2_VSX
)
7538 GEN_VSX_HELPER_2(xvdivsp
, 0x00, 0x0B, 0, PPC2_VSX
)
7539 GEN_VSX_HELPER_2(xvresp
, 0x14, 0x09, 0, PPC2_VSX
)
7540 GEN_VSX_HELPER_2(xvsqrtsp
, 0x16, 0x08, 0, PPC2_VSX
)
7541 GEN_VSX_HELPER_2(xvrsqrtesp
, 0x14, 0x08, 0, PPC2_VSX
)
7542 GEN_VSX_HELPER_2(xvtdivsp
, 0x14, 0x0B, 0, PPC2_VSX
)
7543 GEN_VSX_HELPER_2(xvtsqrtsp
, 0x14, 0x0A, 0, PPC2_VSX
)
7544 GEN_VSX_HELPER_2(xvmaddasp
, 0x04, 0x08, 0, PPC2_VSX
)
7545 GEN_VSX_HELPER_2(xvmaddmsp
, 0x04, 0x09, 0, PPC2_VSX
)
7546 GEN_VSX_HELPER_2(xvmsubasp
, 0x04, 0x0A, 0, PPC2_VSX
)
7547 GEN_VSX_HELPER_2(xvmsubmsp
, 0x04, 0x0B, 0, PPC2_VSX
)
7548 GEN_VSX_HELPER_2(xvnmaddasp
, 0x04, 0x18, 0, PPC2_VSX
)
7549 GEN_VSX_HELPER_2(xvnmaddmsp
, 0x04, 0x19, 0, PPC2_VSX
)
7550 GEN_VSX_HELPER_2(xvnmsubasp
, 0x04, 0x1A, 0, PPC2_VSX
)
7551 GEN_VSX_HELPER_2(xvnmsubmsp
, 0x04, 0x1B, 0, PPC2_VSX
)
7552 GEN_VSX_HELPER_2(xvmaxsp
, 0x00, 0x18, 0, PPC2_VSX
)
7553 GEN_VSX_HELPER_2(xvminsp
, 0x00, 0x19, 0, PPC2_VSX
)
7554 GEN_VSX_HELPER_2(xvcmpeqsp
, 0x0C, 0x08, 0, PPC2_VSX
)
7555 GEN_VSX_HELPER_2(xvcmpgtsp
, 0x0C, 0x09, 0, PPC2_VSX
)
7556 GEN_VSX_HELPER_2(xvcmpgesp
, 0x0C, 0x0A, 0, PPC2_VSX
)
7557 GEN_VSX_HELPER_2(xvcvspdp
, 0x12, 0x1C, 0, PPC2_VSX
)
7558 GEN_VSX_HELPER_2(xvcvspsxds
, 0x10, 0x19, 0, PPC2_VSX
)
7559 GEN_VSX_HELPER_2(xvcvspsxws
, 0x10, 0x09, 0, PPC2_VSX
)
7560 GEN_VSX_HELPER_2(xvcvspuxds
, 0x10, 0x18, 0, PPC2_VSX
)
7561 GEN_VSX_HELPER_2(xvcvspuxws
, 0x10, 0x08, 0, PPC2_VSX
)
7562 GEN_VSX_HELPER_2(xvcvsxdsp
, 0x10, 0x1B, 0, PPC2_VSX
)
7563 GEN_VSX_HELPER_2(xvcvuxdsp
, 0x10, 0x1A, 0, PPC2_VSX
)
7564 GEN_VSX_HELPER_2(xvcvsxwsp
, 0x10, 0x0B, 0, PPC2_VSX
)
7565 GEN_VSX_HELPER_2(xvcvuxwsp
, 0x10, 0x0A, 0, PPC2_VSX
)
7566 GEN_VSX_HELPER_2(xvrspi
, 0x12, 0x08, 0, PPC2_VSX
)
7567 GEN_VSX_HELPER_2(xvrspic
, 0x16, 0x0A, 0, PPC2_VSX
)
7568 GEN_VSX_HELPER_2(xvrspim
, 0x12, 0x0B, 0, PPC2_VSX
)
7569 GEN_VSX_HELPER_2(xvrspip
, 0x12, 0x0A, 0, PPC2_VSX
)
7570 GEN_VSX_HELPER_2(xvrspiz
, 0x12, 0x09, 0, PPC2_VSX
)
7572 #define VSX_LOGICAL(name, tcg_op) \
7573 static void glue(gen_, name)(DisasContext * ctx) \
7575 if (unlikely(!ctx->vsx_enabled)) { \
7576 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7579 tcg_op(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)), \
7580 cpu_vsrh(xB(ctx->opcode))); \
7581 tcg_op(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)), \
7582 cpu_vsrl(xB(ctx->opcode))); \
7585 VSX_LOGICAL(xxland
, tcg_gen_and_i64
)
7586 VSX_LOGICAL(xxlandc
, tcg_gen_andc_i64
)
7587 VSX_LOGICAL(xxlor
, tcg_gen_or_i64
)
7588 VSX_LOGICAL(xxlxor
, tcg_gen_xor_i64
)
7589 VSX_LOGICAL(xxlnor
, tcg_gen_nor_i64
)
7590 VSX_LOGICAL(xxleqv
, tcg_gen_eqv_i64
)
7591 VSX_LOGICAL(xxlnand
, tcg_gen_nand_i64
)
7592 VSX_LOGICAL(xxlorc
, tcg_gen_orc_i64
)
7594 #define VSX_XXMRG(name, high) \
7595 static void glue(gen_, name)(DisasContext * ctx) \
7597 TCGv_i64 a0, a1, b0, b1; \
7598 if (unlikely(!ctx->vsx_enabled)) { \
7599 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7602 a0 = tcg_temp_new_i64(); \
7603 a1 = tcg_temp_new_i64(); \
7604 b0 = tcg_temp_new_i64(); \
7605 b1 = tcg_temp_new_i64(); \
7607 tcg_gen_mov_i64(a0, cpu_vsrh(xA(ctx->opcode))); \
7608 tcg_gen_mov_i64(a1, cpu_vsrh(xA(ctx->opcode))); \
7609 tcg_gen_mov_i64(b0, cpu_vsrh(xB(ctx->opcode))); \
7610 tcg_gen_mov_i64(b1, cpu_vsrh(xB(ctx->opcode))); \
7612 tcg_gen_mov_i64(a0, cpu_vsrl(xA(ctx->opcode))); \
7613 tcg_gen_mov_i64(a1, cpu_vsrl(xA(ctx->opcode))); \
7614 tcg_gen_mov_i64(b0, cpu_vsrl(xB(ctx->opcode))); \
7615 tcg_gen_mov_i64(b1, cpu_vsrl(xB(ctx->opcode))); \
7617 tcg_gen_shri_i64(a0, a0, 32); \
7618 tcg_gen_shri_i64(b0, b0, 32); \
7619 tcg_gen_deposit_i64(cpu_vsrh(xT(ctx->opcode)), \
7621 tcg_gen_deposit_i64(cpu_vsrl(xT(ctx->opcode)), \
7623 tcg_temp_free_i64(a0); \
7624 tcg_temp_free_i64(a1); \
7625 tcg_temp_free_i64(b0); \
7626 tcg_temp_free_i64(b1); \
7629 VSX_XXMRG(xxmrghw
, 1)
7630 VSX_XXMRG(xxmrglw
, 0)
7632 static void gen_xxsel(DisasContext
* ctx
)
7635 if (unlikely(!ctx
->vsx_enabled
)) {
7636 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7639 a
= tcg_temp_new_i64();
7640 b
= tcg_temp_new_i64();
7641 c
= tcg_temp_new_i64();
7643 tcg_gen_mov_i64(a
, cpu_vsrh(xA(ctx
->opcode
)));
7644 tcg_gen_mov_i64(b
, cpu_vsrh(xB(ctx
->opcode
)));
7645 tcg_gen_mov_i64(c
, cpu_vsrh(xC(ctx
->opcode
)));
7647 tcg_gen_and_i64(b
, b
, c
);
7648 tcg_gen_andc_i64(a
, a
, c
);
7649 tcg_gen_or_i64(cpu_vsrh(xT(ctx
->opcode
)), a
, b
);
7651 tcg_gen_mov_i64(a
, cpu_vsrl(xA(ctx
->opcode
)));
7652 tcg_gen_mov_i64(b
, cpu_vsrl(xB(ctx
->opcode
)));
7653 tcg_gen_mov_i64(c
, cpu_vsrl(xC(ctx
->opcode
)));
7655 tcg_gen_and_i64(b
, b
, c
);
7656 tcg_gen_andc_i64(a
, a
, c
);
7657 tcg_gen_or_i64(cpu_vsrl(xT(ctx
->opcode
)), a
, b
);
7659 tcg_temp_free_i64(a
);
7660 tcg_temp_free_i64(b
);
7661 tcg_temp_free_i64(c
);
7664 static void gen_xxspltw(DisasContext
*ctx
)
7667 TCGv_i64 vsr
= (UIM(ctx
->opcode
) & 2) ?
7668 cpu_vsrl(xB(ctx
->opcode
)) :
7669 cpu_vsrh(xB(ctx
->opcode
));
7671 if (unlikely(!ctx
->vsx_enabled
)) {
7672 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7676 b
= tcg_temp_new_i64();
7677 b2
= tcg_temp_new_i64();
7679 if (UIM(ctx
->opcode
) & 1) {
7680 tcg_gen_ext32u_i64(b
, vsr
);
7682 tcg_gen_shri_i64(b
, vsr
, 32);
7685 tcg_gen_shli_i64(b2
, b
, 32);
7686 tcg_gen_or_i64(cpu_vsrh(xT(ctx
->opcode
)), b
, b2
);
7687 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), cpu_vsrh(xT(ctx
->opcode
)));
7689 tcg_temp_free_i64(b
);
7690 tcg_temp_free_i64(b2
);
7693 static void gen_xxsldwi(DisasContext
*ctx
)
7696 if (unlikely(!ctx
->vsx_enabled
)) {
7697 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7700 xth
= tcg_temp_new_i64();
7701 xtl
= tcg_temp_new_i64();
7703 switch (SHW(ctx
->opcode
)) {
7705 tcg_gen_mov_i64(xth
, cpu_vsrh(xA(ctx
->opcode
)));
7706 tcg_gen_mov_i64(xtl
, cpu_vsrl(xA(ctx
->opcode
)));
7710 TCGv_i64 t0
= tcg_temp_new_i64();
7711 tcg_gen_mov_i64(xth
, cpu_vsrh(xA(ctx
->opcode
)));
7712 tcg_gen_shli_i64(xth
, xth
, 32);
7713 tcg_gen_mov_i64(t0
, cpu_vsrl(xA(ctx
->opcode
)));
7714 tcg_gen_shri_i64(t0
, t0
, 32);
7715 tcg_gen_or_i64(xth
, xth
, t0
);
7716 tcg_gen_mov_i64(xtl
, cpu_vsrl(xA(ctx
->opcode
)));
7717 tcg_gen_shli_i64(xtl
, xtl
, 32);
7718 tcg_gen_mov_i64(t0
, cpu_vsrh(xB(ctx
->opcode
)));
7719 tcg_gen_shri_i64(t0
, t0
, 32);
7720 tcg_gen_or_i64(xtl
, xtl
, t0
);
7721 tcg_temp_free_i64(t0
);
7725 tcg_gen_mov_i64(xth
, cpu_vsrl(xA(ctx
->opcode
)));
7726 tcg_gen_mov_i64(xtl
, cpu_vsrh(xB(ctx
->opcode
)));
7730 TCGv_i64 t0
= tcg_temp_new_i64();
7731 tcg_gen_mov_i64(xth
, cpu_vsrl(xA(ctx
->opcode
)));
7732 tcg_gen_shli_i64(xth
, xth
, 32);
7733 tcg_gen_mov_i64(t0
, cpu_vsrh(xB(ctx
->opcode
)));
7734 tcg_gen_shri_i64(t0
, t0
, 32);
7735 tcg_gen_or_i64(xth
, xth
, t0
);
7736 tcg_gen_mov_i64(xtl
, cpu_vsrh(xB(ctx
->opcode
)));
7737 tcg_gen_shli_i64(xtl
, xtl
, 32);
7738 tcg_gen_mov_i64(t0
, cpu_vsrl(xB(ctx
->opcode
)));
7739 tcg_gen_shri_i64(t0
, t0
, 32);
7740 tcg_gen_or_i64(xtl
, xtl
, t0
);
7741 tcg_temp_free_i64(t0
);
7746 tcg_gen_mov_i64(cpu_vsrh(xT(ctx
->opcode
)), xth
);
7747 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), xtl
);
7749 tcg_temp_free_i64(xth
);
7750 tcg_temp_free_i64(xtl
);
7754 /*** SPE extension ***/
7755 /* Register moves */
7757 static inline void gen_evmra(DisasContext
*ctx
)
7760 if (unlikely(!ctx
->spe_enabled
)) {
7761 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7765 #if defined(TARGET_PPC64)
7767 tcg_gen_mov_i64(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7770 tcg_gen_st_i64(cpu_gpr
[rA(ctx
->opcode
)],
7772 offsetof(CPUPPCState
, spe_acc
));
7774 TCGv_i64 tmp
= tcg_temp_new_i64();
7776 /* tmp := rA_lo + rA_hi << 32 */
7777 tcg_gen_concat_i32_i64(tmp
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7779 /* spe_acc := tmp */
7780 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7781 tcg_temp_free_i64(tmp
);
7784 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7785 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7789 static inline void gen_load_gpr64(TCGv_i64 t
, int reg
)
7791 #if defined(TARGET_PPC64)
7792 tcg_gen_mov_i64(t
, cpu_gpr
[reg
]);
7794 tcg_gen_concat_i32_i64(t
, cpu_gpr
[reg
], cpu_gprh
[reg
]);
7798 static inline void gen_store_gpr64(int reg
, TCGv_i64 t
)
7800 #if defined(TARGET_PPC64)
7801 tcg_gen_mov_i64(cpu_gpr
[reg
], t
);
7803 TCGv_i64 tmp
= tcg_temp_new_i64();
7804 tcg_gen_trunc_i64_i32(cpu_gpr
[reg
], t
);
7805 tcg_gen_shri_i64(tmp
, t
, 32);
7806 tcg_gen_trunc_i64_i32(cpu_gprh
[reg
], tmp
);
7807 tcg_temp_free_i64(tmp
);
7811 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
7812 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7814 if (Rc(ctx->opcode)) \
7820 /* Handler for undefined SPE opcodes */
7821 static inline void gen_speundef(DisasContext
*ctx
)
7823 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
7827 #if defined(TARGET_PPC64)
7828 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
7829 static inline void gen_##name(DisasContext *ctx) \
7831 if (unlikely(!ctx->spe_enabled)) { \
7832 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7835 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7836 cpu_gpr[rB(ctx->opcode)]); \
7839 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
7840 static inline void gen_##name(DisasContext *ctx) \
7842 if (unlikely(!ctx->spe_enabled)) { \
7843 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7846 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7847 cpu_gpr[rB(ctx->opcode)]); \
7848 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7849 cpu_gprh[rB(ctx->opcode)]); \
7853 GEN_SPEOP_LOGIC2(evand
, tcg_gen_and_tl
);
7854 GEN_SPEOP_LOGIC2(evandc
, tcg_gen_andc_tl
);
7855 GEN_SPEOP_LOGIC2(evxor
, tcg_gen_xor_tl
);
7856 GEN_SPEOP_LOGIC2(evor
, tcg_gen_or_tl
);
7857 GEN_SPEOP_LOGIC2(evnor
, tcg_gen_nor_tl
);
7858 GEN_SPEOP_LOGIC2(eveqv
, tcg_gen_eqv_tl
);
7859 GEN_SPEOP_LOGIC2(evorc
, tcg_gen_orc_tl
);
7860 GEN_SPEOP_LOGIC2(evnand
, tcg_gen_nand_tl
);
7862 /* SPE logic immediate */
7863 #if defined(TARGET_PPC64)
7864 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
7865 static inline void gen_##name(DisasContext *ctx) \
7867 if (unlikely(!ctx->spe_enabled)) { \
7868 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7871 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7872 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7873 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7874 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7875 tcg_opi(t0, t0, rB(ctx->opcode)); \
7876 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7877 tcg_gen_trunc_i64_i32(t1, t2); \
7878 tcg_temp_free_i64(t2); \
7879 tcg_opi(t1, t1, rB(ctx->opcode)); \
7880 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7881 tcg_temp_free_i32(t0); \
7882 tcg_temp_free_i32(t1); \
7885 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
7886 static inline void gen_##name(DisasContext *ctx) \
7888 if (unlikely(!ctx->spe_enabled)) { \
7889 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7892 tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7894 tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7898 GEN_SPEOP_TCG_LOGIC_IMM2(evslwi
, tcg_gen_shli_i32
);
7899 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu
, tcg_gen_shri_i32
);
7900 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis
, tcg_gen_sari_i32
);
7901 GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi
, tcg_gen_rotli_i32
);
7903 /* SPE arithmetic */
7904 #if defined(TARGET_PPC64)
7905 #define GEN_SPEOP_ARITH1(name, tcg_op) \
7906 static inline void gen_##name(DisasContext *ctx) \
7908 if (unlikely(!ctx->spe_enabled)) { \
7909 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7912 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7913 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7914 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7915 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7917 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7918 tcg_gen_trunc_i64_i32(t1, t2); \
7919 tcg_temp_free_i64(t2); \
7921 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7922 tcg_temp_free_i32(t0); \
7923 tcg_temp_free_i32(t1); \
7926 #define GEN_SPEOP_ARITH1(name, tcg_op) \
7927 static inline void gen_##name(DisasContext *ctx) \
7929 if (unlikely(!ctx->spe_enabled)) { \
7930 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7933 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
7934 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
7938 static inline void gen_op_evabs(TCGv_i32 ret
, TCGv_i32 arg1
)
7940 int l1
= gen_new_label();
7941 int l2
= gen_new_label();
7943 tcg_gen_brcondi_i32(TCG_COND_GE
, arg1
, 0, l1
);
7944 tcg_gen_neg_i32(ret
, arg1
);
7947 tcg_gen_mov_i32(ret
, arg1
);
7950 GEN_SPEOP_ARITH1(evabs
, gen_op_evabs
);
7951 GEN_SPEOP_ARITH1(evneg
, tcg_gen_neg_i32
);
7952 GEN_SPEOP_ARITH1(evextsb
, tcg_gen_ext8s_i32
);
7953 GEN_SPEOP_ARITH1(evextsh
, tcg_gen_ext16s_i32
);
7954 static inline void gen_op_evrndw(TCGv_i32 ret
, TCGv_i32 arg1
)
7956 tcg_gen_addi_i32(ret
, arg1
, 0x8000);
7957 tcg_gen_ext16u_i32(ret
, ret
);
7959 GEN_SPEOP_ARITH1(evrndw
, gen_op_evrndw
);
7960 GEN_SPEOP_ARITH1(evcntlsw
, gen_helper_cntlsw32
);
7961 GEN_SPEOP_ARITH1(evcntlzw
, gen_helper_cntlzw32
);
7963 #if defined(TARGET_PPC64)
7964 #define GEN_SPEOP_ARITH2(name, tcg_op) \
7965 static inline void gen_##name(DisasContext *ctx) \
7967 if (unlikely(!ctx->spe_enabled)) { \
7968 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7971 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7972 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7973 TCGv_i32 t2 = tcg_temp_local_new_i32(); \
7974 TCGv_i64 t3 = tcg_temp_local_new_i64(); \
7975 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7976 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
7977 tcg_op(t0, t0, t2); \
7978 tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
7979 tcg_gen_trunc_i64_i32(t1, t3); \
7980 tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
7981 tcg_gen_trunc_i64_i32(t2, t3); \
7982 tcg_temp_free_i64(t3); \
7983 tcg_op(t1, t1, t2); \
7984 tcg_temp_free_i32(t2); \
7985 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7986 tcg_temp_free_i32(t0); \
7987 tcg_temp_free_i32(t1); \
7990 #define GEN_SPEOP_ARITH2(name, tcg_op) \
7991 static inline void gen_##name(DisasContext *ctx) \
7993 if (unlikely(!ctx->spe_enabled)) { \
7994 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7997 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7998 cpu_gpr[rB(ctx->opcode)]); \
7999 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8000 cpu_gprh[rB(ctx->opcode)]); \
8004 static inline void gen_op_evsrwu(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
8009 l1
= gen_new_label();
8010 l2
= gen_new_label();
8011 t0
= tcg_temp_local_new_i32();
8012 /* No error here: 6 bits are used */
8013 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
8014 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
8015 tcg_gen_shr_i32(ret
, arg1
, t0
);
8018 tcg_gen_movi_i32(ret
, 0);
8020 tcg_temp_free_i32(t0
);
8022 GEN_SPEOP_ARITH2(evsrwu
, gen_op_evsrwu
);
8023 static inline void gen_op_evsrws(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
8028 l1
= gen_new_label();
8029 l2
= gen_new_label();
8030 t0
= tcg_temp_local_new_i32();
8031 /* No error here: 6 bits are used */
8032 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
8033 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
8034 tcg_gen_sar_i32(ret
, arg1
, t0
);
8037 tcg_gen_movi_i32(ret
, 0);
8039 tcg_temp_free_i32(t0
);
8041 GEN_SPEOP_ARITH2(evsrws
, gen_op_evsrws
);
8042 static inline void gen_op_evslw(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
8047 l1
= gen_new_label();
8048 l2
= gen_new_label();
8049 t0
= tcg_temp_local_new_i32();
8050 /* No error here: 6 bits are used */
8051 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
8052 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
8053 tcg_gen_shl_i32(ret
, arg1
, t0
);
8056 tcg_gen_movi_i32(ret
, 0);
8058 tcg_temp_free_i32(t0
);
8060 GEN_SPEOP_ARITH2(evslw
, gen_op_evslw
);
8061 static inline void gen_op_evrlw(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
8063 TCGv_i32 t0
= tcg_temp_new_i32();
8064 tcg_gen_andi_i32(t0
, arg2
, 0x1F);
8065 tcg_gen_rotl_i32(ret
, arg1
, t0
);
8066 tcg_temp_free_i32(t0
);
8068 GEN_SPEOP_ARITH2(evrlw
, gen_op_evrlw
);
8069 static inline void gen_evmergehi(DisasContext
*ctx
)
8071 if (unlikely(!ctx
->spe_enabled
)) {
8072 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8075 #if defined(TARGET_PPC64)
8076 TCGv t0
= tcg_temp_new();
8077 TCGv t1
= tcg_temp_new();
8078 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
8079 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
8080 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
8084 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
8085 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
8088 GEN_SPEOP_ARITH2(evaddw
, tcg_gen_add_i32
);
8089 static inline void gen_op_evsubf(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
8091 tcg_gen_sub_i32(ret
, arg2
, arg1
);
8093 GEN_SPEOP_ARITH2(evsubfw
, gen_op_evsubf
);
8095 /* SPE arithmetic immediate */
8096 #if defined(TARGET_PPC64)
8097 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
8098 static inline void gen_##name(DisasContext *ctx) \
8100 if (unlikely(!ctx->spe_enabled)) { \
8101 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8104 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8105 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8106 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
8107 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8108 tcg_op(t0, t0, rA(ctx->opcode)); \
8109 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
8110 tcg_gen_trunc_i64_i32(t1, t2); \
8111 tcg_temp_free_i64(t2); \
8112 tcg_op(t1, t1, rA(ctx->opcode)); \
8113 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
8114 tcg_temp_free_i32(t0); \
8115 tcg_temp_free_i32(t1); \
8118 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
8119 static inline void gen_##name(DisasContext *ctx) \
8121 if (unlikely(!ctx->spe_enabled)) { \
8122 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8125 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
8127 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
8131 GEN_SPEOP_ARITH_IMM2(evaddiw
, tcg_gen_addi_i32
);
8132 GEN_SPEOP_ARITH_IMM2(evsubifw
, tcg_gen_subi_i32
);
8134 /* SPE comparison */
8135 #if defined(TARGET_PPC64)
8136 #define GEN_SPEOP_COMP(name, tcg_cond) \
8137 static inline void gen_##name(DisasContext *ctx) \
8139 if (unlikely(!ctx->spe_enabled)) { \
8140 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8143 int l1 = gen_new_label(); \
8144 int l2 = gen_new_label(); \
8145 int l3 = gen_new_label(); \
8146 int l4 = gen_new_label(); \
8147 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8148 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8149 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
8150 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8151 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8152 tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
8153 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
8155 gen_set_label(l1); \
8156 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8157 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8158 gen_set_label(l2); \
8159 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
8160 tcg_gen_trunc_i64_i32(t0, t2); \
8161 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
8162 tcg_gen_trunc_i64_i32(t1, t2); \
8163 tcg_temp_free_i64(t2); \
8164 tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
8165 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8166 ~(CRF_CH | CRF_CH_AND_CL)); \
8168 gen_set_label(l3); \
8169 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8170 CRF_CH | CRF_CH_OR_CL); \
8171 gen_set_label(l4); \
8172 tcg_temp_free_i32(t0); \
8173 tcg_temp_free_i32(t1); \
8176 #define GEN_SPEOP_COMP(name, tcg_cond) \
8177 static inline void gen_##name(DisasContext *ctx) \
8179 if (unlikely(!ctx->spe_enabled)) { \
8180 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8183 int l1 = gen_new_label(); \
8184 int l2 = gen_new_label(); \
8185 int l3 = gen_new_label(); \
8186 int l4 = gen_new_label(); \
8188 tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
8189 cpu_gpr[rB(ctx->opcode)], l1); \
8190 tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
8192 gen_set_label(l1); \
8193 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8194 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8195 gen_set_label(l2); \
8196 tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
8197 cpu_gprh[rB(ctx->opcode)], l3); \
8198 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8199 ~(CRF_CH | CRF_CH_AND_CL)); \
8201 gen_set_label(l3); \
8202 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8203 CRF_CH | CRF_CH_OR_CL); \
8204 gen_set_label(l4); \
8207 GEN_SPEOP_COMP(evcmpgtu
, TCG_COND_GTU
);
8208 GEN_SPEOP_COMP(evcmpgts
, TCG_COND_GT
);
8209 GEN_SPEOP_COMP(evcmpltu
, TCG_COND_LTU
);
8210 GEN_SPEOP_COMP(evcmplts
, TCG_COND_LT
);
8211 GEN_SPEOP_COMP(evcmpeq
, TCG_COND_EQ
);
8214 static inline void gen_brinc(DisasContext
*ctx
)
8216 /* Note: brinc is usable even if SPE is disabled */
8217 gen_helper_brinc(cpu_gpr
[rD(ctx
->opcode
)],
8218 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
8220 static inline void gen_evmergelo(DisasContext
*ctx
)
8222 if (unlikely(!ctx
->spe_enabled
)) {
8223 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8226 #if defined(TARGET_PPC64)
8227 TCGv t0
= tcg_temp_new();
8228 TCGv t1
= tcg_temp_new();
8229 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
8230 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
8231 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
8235 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8236 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
8239 static inline void gen_evmergehilo(DisasContext
*ctx
)
8241 if (unlikely(!ctx
->spe_enabled
)) {
8242 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8245 #if defined(TARGET_PPC64)
8246 TCGv t0
= tcg_temp_new();
8247 TCGv t1
= tcg_temp_new();
8248 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
8249 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
8250 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
8254 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
8255 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
8258 static inline void gen_evmergelohi(DisasContext
*ctx
)
8260 if (unlikely(!ctx
->spe_enabled
)) {
8261 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8264 #if defined(TARGET_PPC64)
8265 TCGv t0
= tcg_temp_new();
8266 TCGv t1
= tcg_temp_new();
8267 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
8268 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
8269 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
8273 if (rD(ctx
->opcode
) == rA(ctx
->opcode
)) {
8274 TCGv_i32 tmp
= tcg_temp_new_i32();
8275 tcg_gen_mov_i32(tmp
, cpu_gpr
[rA(ctx
->opcode
)]);
8276 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
8277 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], tmp
);
8278 tcg_temp_free_i32(tmp
);
8280 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
8281 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8285 static inline void gen_evsplati(DisasContext
*ctx
)
8287 uint64_t imm
= ((int32_t)(rA(ctx
->opcode
) << 27)) >> 27;
8289 #if defined(TARGET_PPC64)
8290 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
8292 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
8293 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
8296 static inline void gen_evsplatfi(DisasContext
*ctx
)
8298 uint64_t imm
= rA(ctx
->opcode
) << 27;
8300 #if defined(TARGET_PPC64)
8301 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
8303 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
8304 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
8308 static inline void gen_evsel(DisasContext
*ctx
)
8310 int l1
= gen_new_label();
8311 int l2
= gen_new_label();
8312 int l3
= gen_new_label();
8313 int l4
= gen_new_label();
8314 TCGv_i32 t0
= tcg_temp_local_new_i32();
8315 #if defined(TARGET_PPC64)
8316 TCGv t1
= tcg_temp_local_new();
8317 TCGv t2
= tcg_temp_local_new();
8319 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 3);
8320 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
8321 #if defined(TARGET_PPC64)
8322 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
8324 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
8328 #if defined(TARGET_PPC64)
8329 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
8331 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
8334 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 2);
8335 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l3
);
8336 #if defined(TARGET_PPC64)
8337 tcg_gen_ext32u_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)]);
8339 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8343 #if defined(TARGET_PPC64)
8344 tcg_gen_ext32u_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)]);
8346 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
8349 tcg_temp_free_i32(t0
);
8350 #if defined(TARGET_PPC64)
8351 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
, t2
);
8357 static void gen_evsel0(DisasContext
*ctx
)
8362 static void gen_evsel1(DisasContext
*ctx
)
8367 static void gen_evsel2(DisasContext
*ctx
)
8372 static void gen_evsel3(DisasContext
*ctx
)
8379 static inline void gen_evmwumi(DisasContext
*ctx
)
8383 if (unlikely(!ctx
->spe_enabled
)) {
8384 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8388 t0
= tcg_temp_new_i64();
8389 t1
= tcg_temp_new_i64();
8391 /* t0 := rA; t1 := rB */
8392 #if defined(TARGET_PPC64)
8393 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
8394 tcg_gen_ext32u_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
8396 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
8397 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
8400 tcg_gen_mul_i64(t0
, t0
, t1
); /* t0 := rA * rB */
8402 gen_store_gpr64(rD(ctx
->opcode
), t0
); /* rD := t0 */
8404 tcg_temp_free_i64(t0
);
8405 tcg_temp_free_i64(t1
);
8408 static inline void gen_evmwumia(DisasContext
*ctx
)
8412 if (unlikely(!ctx
->spe_enabled
)) {
8413 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8417 gen_evmwumi(ctx
); /* rD := rA * rB */
8419 tmp
= tcg_temp_new_i64();
8422 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
8423 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8424 tcg_temp_free_i64(tmp
);
8427 static inline void gen_evmwumiaa(DisasContext
*ctx
)
8432 if (unlikely(!ctx
->spe_enabled
)) {
8433 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8437 gen_evmwumi(ctx
); /* rD := rA * rB */
8439 acc
= tcg_temp_new_i64();
8440 tmp
= tcg_temp_new_i64();
8443 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
8446 tcg_gen_ld_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8448 /* acc := tmp + acc */
8449 tcg_gen_add_i64(acc
, acc
, tmp
);
8452 tcg_gen_st_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8455 gen_store_gpr64(rD(ctx
->opcode
), acc
);
8457 tcg_temp_free_i64(acc
);
8458 tcg_temp_free_i64(tmp
);
8461 static inline void gen_evmwsmi(DisasContext
*ctx
)
8465 if (unlikely(!ctx
->spe_enabled
)) {
8466 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8470 t0
= tcg_temp_new_i64();
8471 t1
= tcg_temp_new_i64();
8473 /* t0 := rA; t1 := rB */
8474 #if defined(TARGET_PPC64)
8475 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
8476 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
8478 tcg_gen_ext_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
8479 tcg_gen_ext_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
8482 tcg_gen_mul_i64(t0
, t0
, t1
); /* t0 := rA * rB */
8484 gen_store_gpr64(rD(ctx
->opcode
), t0
); /* rD := t0 */
8486 tcg_temp_free_i64(t0
);
8487 tcg_temp_free_i64(t1
);
8490 static inline void gen_evmwsmia(DisasContext
*ctx
)
8494 gen_evmwsmi(ctx
); /* rD := rA * rB */
8496 tmp
= tcg_temp_new_i64();
8499 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
8500 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8502 tcg_temp_free_i64(tmp
);
8505 static inline void gen_evmwsmiaa(DisasContext
*ctx
)
8507 TCGv_i64 acc
= tcg_temp_new_i64();
8508 TCGv_i64 tmp
= tcg_temp_new_i64();
8510 gen_evmwsmi(ctx
); /* rD := rA * rB */
8512 acc
= tcg_temp_new_i64();
8513 tmp
= tcg_temp_new_i64();
8516 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
8519 tcg_gen_ld_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8521 /* acc := tmp + acc */
8522 tcg_gen_add_i64(acc
, acc
, tmp
);
8525 tcg_gen_st_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8528 gen_store_gpr64(rD(ctx
->opcode
), acc
);
8530 tcg_temp_free_i64(acc
);
8531 tcg_temp_free_i64(tmp
);
8534 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
8535 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
8536 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
8537 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
8538 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
8539 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
8540 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
8541 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE
); //
8542 GEN_SPE(evmra
, speundef
, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE
);
8543 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
); ////
8544 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
8545 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
8546 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
8547 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
8548 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
8549 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
8550 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
); ////
8551 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
8552 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
8553 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE
);
8554 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
8555 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
8556 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE
); //
8557 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE
);
8558 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
8559 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
8560 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE
); ////
8561 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE
); ////
8562 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE
); ////
8564 /* SPE load and stores */
8565 static inline void gen_addr_spe_imm_index(DisasContext
*ctx
, TCGv EA
, int sh
)
8567 target_ulong uimm
= rB(ctx
->opcode
);
8569 if (rA(ctx
->opcode
) == 0) {
8570 tcg_gen_movi_tl(EA
, uimm
<< sh
);
8572 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], uimm
<< sh
);
8573 if (NARROW_MODE(ctx
)) {
8574 tcg_gen_ext32u_tl(EA
, EA
);
8579 static inline void gen_op_evldd(DisasContext
*ctx
, TCGv addr
)
8581 #if defined(TARGET_PPC64)
8582 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
8584 TCGv_i64 t0
= tcg_temp_new_i64();
8585 gen_qemu_ld64(ctx
, t0
, addr
);
8586 tcg_gen_trunc_i64_i32(cpu_gpr
[rD(ctx
->opcode
)], t0
);
8587 tcg_gen_shri_i64(t0
, t0
, 32);
8588 tcg_gen_trunc_i64_i32(cpu_gprh
[rD(ctx
->opcode
)], t0
);
8589 tcg_temp_free_i64(t0
);
8593 static inline void gen_op_evldw(DisasContext
*ctx
, TCGv addr
)
8595 #if defined(TARGET_PPC64)
8596 TCGv t0
= tcg_temp_new();
8597 gen_qemu_ld32u(ctx
, t0
, addr
);
8598 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
8599 gen_addr_add(ctx
, addr
, addr
, 4);
8600 gen_qemu_ld32u(ctx
, t0
, addr
);
8601 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8604 gen_qemu_ld32u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
8605 gen_addr_add(ctx
, addr
, addr
, 4);
8606 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
8610 static inline void gen_op_evldh(DisasContext
*ctx
, TCGv addr
)
8612 TCGv t0
= tcg_temp_new();
8613 #if defined(TARGET_PPC64)
8614 gen_qemu_ld16u(ctx
, t0
, addr
);
8615 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
8616 gen_addr_add(ctx
, addr
, addr
, 2);
8617 gen_qemu_ld16u(ctx
, t0
, addr
);
8618 tcg_gen_shli_tl(t0
, t0
, 32);
8619 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8620 gen_addr_add(ctx
, addr
, addr
, 2);
8621 gen_qemu_ld16u(ctx
, t0
, addr
);
8622 tcg_gen_shli_tl(t0
, t0
, 16);
8623 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8624 gen_addr_add(ctx
, addr
, addr
, 2);
8625 gen_qemu_ld16u(ctx
, t0
, addr
);
8626 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8628 gen_qemu_ld16u(ctx
, t0
, addr
);
8629 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
8630 gen_addr_add(ctx
, addr
, addr
, 2);
8631 gen_qemu_ld16u(ctx
, t0
, addr
);
8632 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
8633 gen_addr_add(ctx
, addr
, addr
, 2);
8634 gen_qemu_ld16u(ctx
, t0
, addr
);
8635 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
8636 gen_addr_add(ctx
, addr
, addr
, 2);
8637 gen_qemu_ld16u(ctx
, t0
, addr
);
8638 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8643 static inline void gen_op_evlhhesplat(DisasContext
*ctx
, TCGv addr
)
8645 TCGv t0
= tcg_temp_new();
8646 gen_qemu_ld16u(ctx
, t0
, addr
);
8647 #if defined(TARGET_PPC64)
8648 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
8649 tcg_gen_shli_tl(t0
, t0
, 16);
8650 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8652 tcg_gen_shli_tl(t0
, t0
, 16);
8653 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
8654 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
8659 static inline void gen_op_evlhhousplat(DisasContext
*ctx
, TCGv addr
)
8661 TCGv t0
= tcg_temp_new();
8662 gen_qemu_ld16u(ctx
, t0
, addr
);
8663 #if defined(TARGET_PPC64)
8664 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
8665 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8667 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
8668 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
8673 static inline void gen_op_evlhhossplat(DisasContext
*ctx
, TCGv addr
)
8675 TCGv t0
= tcg_temp_new();
8676 gen_qemu_ld16s(ctx
, t0
, addr
);
8677 #if defined(TARGET_PPC64)
8678 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
8679 tcg_gen_ext32u_tl(t0
, t0
);
8680 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8682 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
8683 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
8688 static inline void gen_op_evlwhe(DisasContext
*ctx
, TCGv addr
)
8690 TCGv t0
= tcg_temp_new();
8691 #if defined(TARGET_PPC64)
8692 gen_qemu_ld16u(ctx
, t0
, addr
);
8693 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
8694 gen_addr_add(ctx
, addr
, addr
, 2);
8695 gen_qemu_ld16u(ctx
, t0
, addr
);
8696 tcg_gen_shli_tl(t0
, t0
, 16);
8697 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8699 gen_qemu_ld16u(ctx
, t0
, addr
);
8700 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
8701 gen_addr_add(ctx
, addr
, addr
, 2);
8702 gen_qemu_ld16u(ctx
, t0
, addr
);
8703 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
8708 static inline void gen_op_evlwhou(DisasContext
*ctx
, TCGv addr
)
8710 #if defined(TARGET_PPC64)
8711 TCGv t0
= tcg_temp_new();
8712 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
8713 gen_addr_add(ctx
, addr
, addr
, 2);
8714 gen_qemu_ld16u(ctx
, t0
, addr
);
8715 tcg_gen_shli_tl(t0
, t0
, 32);
8716 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8719 gen_qemu_ld16u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
8720 gen_addr_add(ctx
, addr
, addr
, 2);
8721 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
8725 static inline void gen_op_evlwhos(DisasContext
*ctx
, TCGv addr
)
8727 #if defined(TARGET_PPC64)
8728 TCGv t0
= tcg_temp_new();
8729 gen_qemu_ld16s(ctx
, t0
, addr
);
8730 tcg_gen_ext32u_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
8731 gen_addr_add(ctx
, addr
, addr
, 2);
8732 gen_qemu_ld16s(ctx
, t0
, addr
);
8733 tcg_gen_shli_tl(t0
, t0
, 32);
8734 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8737 gen_qemu_ld16s(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
8738 gen_addr_add(ctx
, addr
, addr
, 2);
8739 gen_qemu_ld16s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
8743 static inline void gen_op_evlwwsplat(DisasContext
*ctx
, TCGv addr
)
8745 TCGv t0
= tcg_temp_new();
8746 gen_qemu_ld32u(ctx
, t0
, addr
);
8747 #if defined(TARGET_PPC64)
8748 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
8749 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8751 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
8752 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
8757 static inline void gen_op_evlwhsplat(DisasContext
*ctx
, TCGv addr
)
8759 TCGv t0
= tcg_temp_new();
8760 #if defined(TARGET_PPC64)
8761 gen_qemu_ld16u(ctx
, t0
, addr
);
8762 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
8763 tcg_gen_shli_tl(t0
, t0
, 32);
8764 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8765 gen_addr_add(ctx
, addr
, addr
, 2);
8766 gen_qemu_ld16u(ctx
, t0
, addr
);
8767 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8768 tcg_gen_shli_tl(t0
, t0
, 16);
8769 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8771 gen_qemu_ld16u(ctx
, t0
, addr
);
8772 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
8773 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
8774 gen_addr_add(ctx
, addr
, addr
, 2);
8775 gen_qemu_ld16u(ctx
, t0
, addr
);
8776 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
8777 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
8782 static inline void gen_op_evstdd(DisasContext
*ctx
, TCGv addr
)
8784 #if defined(TARGET_PPC64)
8785 gen_qemu_st64(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
8787 TCGv_i64 t0
= tcg_temp_new_i64();
8788 tcg_gen_concat_i32_i64(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gprh
[rS(ctx
->opcode
)]);
8789 gen_qemu_st64(ctx
, t0
, addr
);
8790 tcg_temp_free_i64(t0
);
8794 static inline void gen_op_evstdw(DisasContext
*ctx
, TCGv addr
)
8796 #if defined(TARGET_PPC64)
8797 TCGv t0
= tcg_temp_new();
8798 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
8799 gen_qemu_st32(ctx
, t0
, addr
);
8802 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
8804 gen_addr_add(ctx
, addr
, addr
, 4);
8805 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
8808 static inline void gen_op_evstdh(DisasContext
*ctx
, TCGv addr
)
8810 TCGv t0
= tcg_temp_new();
8811 #if defined(TARGET_PPC64)
8812 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
8814 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
8816 gen_qemu_st16(ctx
, t0
, addr
);
8817 gen_addr_add(ctx
, addr
, addr
, 2);
8818 #if defined(TARGET_PPC64)
8819 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
8820 gen_qemu_st16(ctx
, t0
, addr
);
8822 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
8824 gen_addr_add(ctx
, addr
, addr
, 2);
8825 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
8826 gen_qemu_st16(ctx
, t0
, addr
);
8828 gen_addr_add(ctx
, addr
, addr
, 2);
8829 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
8832 static inline void gen_op_evstwhe(DisasContext
*ctx
, TCGv addr
)
8834 TCGv t0
= tcg_temp_new();
8835 #if defined(TARGET_PPC64)
8836 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
8838 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
8840 gen_qemu_st16(ctx
, t0
, addr
);
8841 gen_addr_add(ctx
, addr
, addr
, 2);
8842 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
8843 gen_qemu_st16(ctx
, t0
, addr
);
8847 static inline void gen_op_evstwho(DisasContext
*ctx
, TCGv addr
)
8849 #if defined(TARGET_PPC64)
8850 TCGv t0
= tcg_temp_new();
8851 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
8852 gen_qemu_st16(ctx
, t0
, addr
);
8855 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
8857 gen_addr_add(ctx
, addr
, addr
, 2);
8858 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
8861 static inline void gen_op_evstwwe(DisasContext
*ctx
, TCGv addr
)
8863 #if defined(TARGET_PPC64)
8864 TCGv t0
= tcg_temp_new();
8865 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
8866 gen_qemu_st32(ctx
, t0
, addr
);
8869 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
8873 static inline void gen_op_evstwwo(DisasContext
*ctx
, TCGv addr
)
8875 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
8878 #define GEN_SPEOP_LDST(name, opc2, sh) \
8879 static void glue(gen_, name)(DisasContext *ctx) \
8882 if (unlikely(!ctx->spe_enabled)) { \
8883 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8886 gen_set_access_type(ctx, ACCESS_INT); \
8887 t0 = tcg_temp_new(); \
8888 if (Rc(ctx->opcode)) { \
8889 gen_addr_spe_imm_index(ctx, t0, sh); \
8891 gen_addr_reg_index(ctx, t0); \
8893 gen_op_##name(ctx, t0); \
8894 tcg_temp_free(t0); \
8897 GEN_SPEOP_LDST(evldd
, 0x00, 3);
8898 GEN_SPEOP_LDST(evldw
, 0x01, 3);
8899 GEN_SPEOP_LDST(evldh
, 0x02, 3);
8900 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1);
8901 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1);
8902 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1);
8903 GEN_SPEOP_LDST(evlwhe
, 0x08, 2);
8904 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2);
8905 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2);
8906 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2);
8907 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2);
8909 GEN_SPEOP_LDST(evstdd
, 0x10, 3);
8910 GEN_SPEOP_LDST(evstdw
, 0x11, 3);
8911 GEN_SPEOP_LDST(evstdh
, 0x12, 3);
8912 GEN_SPEOP_LDST(evstwhe
, 0x18, 2);
8913 GEN_SPEOP_LDST(evstwho
, 0x1A, 2);
8914 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2);
8915 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2);
8917 /* Multiply and add - TODO */
8919 GEN_SPE(speundef
, evmhessf
, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);//
8920 GEN_SPE(speundef
, evmhossf
, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8921 GEN_SPE(evmheumi
, evmhesmi
, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
8922 GEN_SPE(speundef
, evmhesmf
, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8923 GEN_SPE(evmhoumi
, evmhosmi
, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
8924 GEN_SPE(speundef
, evmhosmf
, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8925 GEN_SPE(speundef
, evmhessfa
, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8926 GEN_SPE(speundef
, evmhossfa
, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8927 GEN_SPE(evmheumia
, evmhesmia
, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
8928 GEN_SPE(speundef
, evmhesmfa
, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8929 GEN_SPE(evmhoumia
, evmhosmia
, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
8930 GEN_SPE(speundef
, evmhosmfa
, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8932 GEN_SPE(speundef
, evmwhssf
, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8933 GEN_SPE(evmwlumi
, speundef
, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
8934 GEN_SPE(evmwhumi
, evmwhsmi
, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
8935 GEN_SPE(speundef
, evmwhsmf
, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8936 GEN_SPE(speundef
, evmwssf
, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8937 GEN_SPE(speundef
, evmwsmf
, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8938 GEN_SPE(speundef
, evmwhssfa
, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8939 GEN_SPE(evmwlumia
, speundef
, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
8940 GEN_SPE(evmwhumia
, evmwhsmia
, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
8941 GEN_SPE(speundef
, evmwhsmfa
, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8942 GEN_SPE(speundef
, evmwssfa
, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8943 GEN_SPE(speundef
, evmwsmfa
, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8945 GEN_SPE(evadduiaaw
, evaddsiaaw
, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8946 GEN_SPE(evsubfusiaaw
, evsubfssiaaw
, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8947 GEN_SPE(evaddumiaaw
, evaddsmiaaw
, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8948 GEN_SPE(evsubfumiaaw
, evsubfsmiaaw
, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8949 GEN_SPE(evdivws
, evdivwu
, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE
);
8951 GEN_SPE(evmheusiaaw
, evmhessiaaw
, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8952 GEN_SPE(speundef
, evmhessfaaw
, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8953 GEN_SPE(evmhousiaaw
, evmhossiaaw
, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8954 GEN_SPE(speundef
, evmhossfaaw
, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8955 GEN_SPE(evmheumiaaw
, evmhesmiaaw
, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8956 GEN_SPE(speundef
, evmhesmfaaw
, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8957 GEN_SPE(evmhoumiaaw
, evmhosmiaaw
, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8958 GEN_SPE(speundef
, evmhosmfaaw
, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8959 GEN_SPE(evmhegumiaa
, evmhegsmiaa
, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8960 GEN_SPE(speundef
, evmhegsmfaa
, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8961 GEN_SPE(evmhogumiaa
, evmhogsmiaa
, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8962 GEN_SPE(speundef
, evmhogsmfaa
, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8964 GEN_SPE(evmwlusiaaw
, evmwlssiaaw
, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
8965 GEN_SPE(evmwlumiaaw
, evmwlsmiaaw
, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
8966 GEN_SPE(speundef
, evmwssfaa
, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8967 GEN_SPE(speundef
, evmwsmfaa
, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8969 GEN_SPE(evmheusianw
, evmhessianw
, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8970 GEN_SPE(speundef
, evmhessfanw
, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8971 GEN_SPE(evmhousianw
, evmhossianw
, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8972 GEN_SPE(speundef
, evmhossfanw
, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8973 GEN_SPE(evmheumianw
, evmhesmianw
, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8974 GEN_SPE(speundef
, evmhesmfanw
, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8975 GEN_SPE(evmhoumianw
, evmhosmianw
, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8976 GEN_SPE(speundef
, evmhosmfanw
, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8977 GEN_SPE(evmhegumian
, evmhegsmian
, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8978 GEN_SPE(speundef
, evmhegsmfan
, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8979 GEN_SPE(evmhigumian
, evmhigsmian
, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8980 GEN_SPE(speundef
, evmhogsmfan
, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8982 GEN_SPE(evmwlusianw
, evmwlssianw
, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
8983 GEN_SPE(evmwlumianw
, evmwlsmianw
, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
8984 GEN_SPE(speundef
, evmwssfan
, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8985 GEN_SPE(evmwumian
, evmwsmian
, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
8986 GEN_SPE(speundef
, evmwsmfan
, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8989 /*** SPE floating-point extension ***/
8990 #if defined(TARGET_PPC64)
8991 #define GEN_SPEFPUOP_CONV_32_32(name) \
8992 static inline void gen_##name(DisasContext *ctx) \
8996 t0 = tcg_temp_new_i32(); \
8997 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8998 gen_helper_##name(t0, cpu_env, t0); \
8999 t1 = tcg_temp_new(); \
9000 tcg_gen_extu_i32_tl(t1, t0); \
9001 tcg_temp_free_i32(t0); \
9002 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9003 0xFFFFFFFF00000000ULL); \
9004 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
9005 tcg_temp_free(t1); \
9007 #define GEN_SPEFPUOP_CONV_32_64(name) \
9008 static inline void gen_##name(DisasContext *ctx) \
9012 t0 = tcg_temp_new_i32(); \
9013 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
9014 t1 = tcg_temp_new(); \
9015 tcg_gen_extu_i32_tl(t1, t0); \
9016 tcg_temp_free_i32(t0); \
9017 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9018 0xFFFFFFFF00000000ULL); \
9019 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
9020 tcg_temp_free(t1); \
9022 #define GEN_SPEFPUOP_CONV_64_32(name) \
9023 static inline void gen_##name(DisasContext *ctx) \
9025 TCGv_i32 t0 = tcg_temp_new_i32(); \
9026 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
9027 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
9028 tcg_temp_free_i32(t0); \
9030 #define GEN_SPEFPUOP_CONV_64_64(name) \
9031 static inline void gen_##name(DisasContext *ctx) \
9033 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9034 cpu_gpr[rB(ctx->opcode)]); \
9036 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
9037 static inline void gen_##name(DisasContext *ctx) \
9041 if (unlikely(!ctx->spe_enabled)) { \
9042 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9045 t0 = tcg_temp_new_i32(); \
9046 t1 = tcg_temp_new_i32(); \
9047 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9048 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9049 gen_helper_##name(t0, cpu_env, t0, t1); \
9050 tcg_temp_free_i32(t1); \
9051 t2 = tcg_temp_new(); \
9052 tcg_gen_extu_i32_tl(t2, t0); \
9053 tcg_temp_free_i32(t0); \
9054 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9055 0xFFFFFFFF00000000ULL); \
9056 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \
9057 tcg_temp_free(t2); \
9059 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
9060 static inline void gen_##name(DisasContext *ctx) \
9062 if (unlikely(!ctx->spe_enabled)) { \
9063 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9066 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9067 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9069 #define GEN_SPEFPUOP_COMP_32(name) \
9070 static inline void gen_##name(DisasContext *ctx) \
9073 if (unlikely(!ctx->spe_enabled)) { \
9074 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9077 t0 = tcg_temp_new_i32(); \
9078 t1 = tcg_temp_new_i32(); \
9079 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9080 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9081 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
9082 tcg_temp_free_i32(t0); \
9083 tcg_temp_free_i32(t1); \
9085 #define GEN_SPEFPUOP_COMP_64(name) \
9086 static inline void gen_##name(DisasContext *ctx) \
9088 if (unlikely(!ctx->spe_enabled)) { \
9089 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9092 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
9093 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9096 #define GEN_SPEFPUOP_CONV_32_32(name) \
9097 static inline void gen_##name(DisasContext *ctx) \
9099 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9100 cpu_gpr[rB(ctx->opcode)]); \
9102 #define GEN_SPEFPUOP_CONV_32_64(name) \
9103 static inline void gen_##name(DisasContext *ctx) \
9105 TCGv_i64 t0 = tcg_temp_new_i64(); \
9106 gen_load_gpr64(t0, rB(ctx->opcode)); \
9107 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
9108 tcg_temp_free_i64(t0); \
9110 #define GEN_SPEFPUOP_CONV_64_32(name) \
9111 static inline void gen_##name(DisasContext *ctx) \
9113 TCGv_i64 t0 = tcg_temp_new_i64(); \
9114 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
9115 gen_store_gpr64(rD(ctx->opcode), t0); \
9116 tcg_temp_free_i64(t0); \
9118 #define GEN_SPEFPUOP_CONV_64_64(name) \
9119 static inline void gen_##name(DisasContext *ctx) \
9121 TCGv_i64 t0 = tcg_temp_new_i64(); \
9122 gen_load_gpr64(t0, rB(ctx->opcode)); \
9123 gen_helper_##name(t0, cpu_env, t0); \
9124 gen_store_gpr64(rD(ctx->opcode), t0); \
9125 tcg_temp_free_i64(t0); \
9127 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
9128 static inline void gen_##name(DisasContext *ctx) \
9130 if (unlikely(!ctx->spe_enabled)) { \
9131 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9134 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9135 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9137 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
9138 static inline void gen_##name(DisasContext *ctx) \
9141 if (unlikely(!ctx->spe_enabled)) { \
9142 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9145 t0 = tcg_temp_new_i64(); \
9146 t1 = tcg_temp_new_i64(); \
9147 gen_load_gpr64(t0, rA(ctx->opcode)); \
9148 gen_load_gpr64(t1, rB(ctx->opcode)); \
9149 gen_helper_##name(t0, cpu_env, t0, t1); \
9150 gen_store_gpr64(rD(ctx->opcode), t0); \
9151 tcg_temp_free_i64(t0); \
9152 tcg_temp_free_i64(t1); \
9154 #define GEN_SPEFPUOP_COMP_32(name) \
9155 static inline void gen_##name(DisasContext *ctx) \
9157 if (unlikely(!ctx->spe_enabled)) { \
9158 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9161 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
9162 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9164 #define GEN_SPEFPUOP_COMP_64(name) \
9165 static inline void gen_##name(DisasContext *ctx) \
9168 if (unlikely(!ctx->spe_enabled)) { \
9169 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9172 t0 = tcg_temp_new_i64(); \
9173 t1 = tcg_temp_new_i64(); \
9174 gen_load_gpr64(t0, rA(ctx->opcode)); \
9175 gen_load_gpr64(t1, rB(ctx->opcode)); \
9176 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
9177 tcg_temp_free_i64(t0); \
9178 tcg_temp_free_i64(t1); \
9182 /* Single precision floating-point vectors operations */
9184 GEN_SPEFPUOP_ARITH2_64_64(evfsadd
);
9185 GEN_SPEFPUOP_ARITH2_64_64(evfssub
);
9186 GEN_SPEFPUOP_ARITH2_64_64(evfsmul
);
9187 GEN_SPEFPUOP_ARITH2_64_64(evfsdiv
);
9188 static inline void gen_evfsabs(DisasContext
*ctx
)
9190 if (unlikely(!ctx
->spe_enabled
)) {
9191 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9194 #if defined(TARGET_PPC64)
9195 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000080000000LL
);
9197 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x80000000);
9198 tcg_gen_andi_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
9201 static inline void gen_evfsnabs(DisasContext
*ctx
)
9203 if (unlikely(!ctx
->spe_enabled
)) {
9204 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9207 #if defined(TARGET_PPC64)
9208 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
9210 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
9211 tcg_gen_ori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
9214 static inline void gen_evfsneg(DisasContext
*ctx
)
9216 if (unlikely(!ctx
->spe_enabled
)) {
9217 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9220 #if defined(TARGET_PPC64)
9221 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
9223 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
9224 tcg_gen_xori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
9229 GEN_SPEFPUOP_CONV_64_64(evfscfui
);
9230 GEN_SPEFPUOP_CONV_64_64(evfscfsi
);
9231 GEN_SPEFPUOP_CONV_64_64(evfscfuf
);
9232 GEN_SPEFPUOP_CONV_64_64(evfscfsf
);
9233 GEN_SPEFPUOP_CONV_64_64(evfsctui
);
9234 GEN_SPEFPUOP_CONV_64_64(evfsctsi
);
9235 GEN_SPEFPUOP_CONV_64_64(evfsctuf
);
9236 GEN_SPEFPUOP_CONV_64_64(evfsctsf
);
9237 GEN_SPEFPUOP_CONV_64_64(evfsctuiz
);
9238 GEN_SPEFPUOP_CONV_64_64(evfsctsiz
);
9241 GEN_SPEFPUOP_COMP_64(evfscmpgt
);
9242 GEN_SPEFPUOP_COMP_64(evfscmplt
);
9243 GEN_SPEFPUOP_COMP_64(evfscmpeq
);
9244 GEN_SPEFPUOP_COMP_64(evfststgt
);
9245 GEN_SPEFPUOP_COMP_64(evfststlt
);
9246 GEN_SPEFPUOP_COMP_64(evfststeq
);
9248 /* Opcodes definitions */
9249 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
9250 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
); //
9251 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9252 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
9253 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
9254 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9255 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9256 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9257 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9258 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9259 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9260 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9261 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
9262 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9264 /* Single precision floating-point operations */
9266 GEN_SPEFPUOP_ARITH2_32_32(efsadd
);
9267 GEN_SPEFPUOP_ARITH2_32_32(efssub
);
9268 GEN_SPEFPUOP_ARITH2_32_32(efsmul
);
9269 GEN_SPEFPUOP_ARITH2_32_32(efsdiv
);
9270 static inline void gen_efsabs(DisasContext
*ctx
)
9272 if (unlikely(!ctx
->spe_enabled
)) {
9273 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9276 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], (target_long
)~0x80000000LL
);
9278 static inline void gen_efsnabs(DisasContext
*ctx
)
9280 if (unlikely(!ctx
->spe_enabled
)) {
9281 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9284 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
9286 static inline void gen_efsneg(DisasContext
*ctx
)
9288 if (unlikely(!ctx
->spe_enabled
)) {
9289 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9292 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
9296 GEN_SPEFPUOP_CONV_32_32(efscfui
);
9297 GEN_SPEFPUOP_CONV_32_32(efscfsi
);
9298 GEN_SPEFPUOP_CONV_32_32(efscfuf
);
9299 GEN_SPEFPUOP_CONV_32_32(efscfsf
);
9300 GEN_SPEFPUOP_CONV_32_32(efsctui
);
9301 GEN_SPEFPUOP_CONV_32_32(efsctsi
);
9302 GEN_SPEFPUOP_CONV_32_32(efsctuf
);
9303 GEN_SPEFPUOP_CONV_32_32(efsctsf
);
9304 GEN_SPEFPUOP_CONV_32_32(efsctuiz
);
9305 GEN_SPEFPUOP_CONV_32_32(efsctsiz
);
9306 GEN_SPEFPUOP_CONV_32_64(efscfd
);
9309 GEN_SPEFPUOP_COMP_32(efscmpgt
);
9310 GEN_SPEFPUOP_COMP_32(efscmplt
);
9311 GEN_SPEFPUOP_COMP_32(efscmpeq
);
9312 GEN_SPEFPUOP_COMP_32(efststgt
);
9313 GEN_SPEFPUOP_COMP_32(efststlt
);
9314 GEN_SPEFPUOP_COMP_32(efststeq
);
9316 /* Opcodes definitions */
9317 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
9318 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
); //
9319 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9320 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
9321 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
9322 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE
); //
9323 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9324 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9325 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9326 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9327 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9328 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9329 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
9330 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9332 /* Double precision floating-point operations */
9334 GEN_SPEFPUOP_ARITH2_64_64(efdadd
);
9335 GEN_SPEFPUOP_ARITH2_64_64(efdsub
);
9336 GEN_SPEFPUOP_ARITH2_64_64(efdmul
);
9337 GEN_SPEFPUOP_ARITH2_64_64(efddiv
);
9338 static inline void gen_efdabs(DisasContext
*ctx
)
9340 if (unlikely(!ctx
->spe_enabled
)) {
9341 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9344 #if defined(TARGET_PPC64)
9345 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000000000000LL
);
9347 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
9348 tcg_gen_andi_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
9351 static inline void gen_efdnabs(DisasContext
*ctx
)
9353 if (unlikely(!ctx
->spe_enabled
)) {
9354 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9357 #if defined(TARGET_PPC64)
9358 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
9360 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
9361 tcg_gen_ori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
9364 static inline void gen_efdneg(DisasContext
*ctx
)
9366 if (unlikely(!ctx
->spe_enabled
)) {
9367 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9370 #if defined(TARGET_PPC64)
9371 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
9373 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
9374 tcg_gen_xori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
9379 GEN_SPEFPUOP_CONV_64_32(efdcfui
);
9380 GEN_SPEFPUOP_CONV_64_32(efdcfsi
);
9381 GEN_SPEFPUOP_CONV_64_32(efdcfuf
);
9382 GEN_SPEFPUOP_CONV_64_32(efdcfsf
);
9383 GEN_SPEFPUOP_CONV_32_64(efdctui
);
9384 GEN_SPEFPUOP_CONV_32_64(efdctsi
);
9385 GEN_SPEFPUOP_CONV_32_64(efdctuf
);
9386 GEN_SPEFPUOP_CONV_32_64(efdctsf
);
9387 GEN_SPEFPUOP_CONV_32_64(efdctuiz
);
9388 GEN_SPEFPUOP_CONV_32_64(efdctsiz
);
9389 GEN_SPEFPUOP_CONV_64_32(efdcfs
);
9390 GEN_SPEFPUOP_CONV_64_64(efdcfuid
);
9391 GEN_SPEFPUOP_CONV_64_64(efdcfsid
);
9392 GEN_SPEFPUOP_CONV_64_64(efdctuidz
);
9393 GEN_SPEFPUOP_CONV_64_64(efdctsidz
);
9396 GEN_SPEFPUOP_COMP_64(efdcmpgt
);
9397 GEN_SPEFPUOP_COMP_64(efdcmplt
);
9398 GEN_SPEFPUOP_COMP_64(efdcmpeq
);
9399 GEN_SPEFPUOP_COMP_64(efdtstgt
);
9400 GEN_SPEFPUOP_COMP_64(efdtstlt
);
9401 GEN_SPEFPUOP_COMP_64(efdtsteq
);
9403 /* Opcodes definitions */
9404 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
); //
9405 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9406 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE
); //
9407 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
9408 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
); //
9409 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9410 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
); //
9411 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE
); //
9412 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9413 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9414 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9415 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9416 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
9417 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
9418 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
); //
9419 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
9421 static opcode_t opcodes
[] = {
9422 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
),
9423 GEN_HANDLER(cmp
, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER
),
9424 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
9425 GEN_HANDLER(cmpl
, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER
),
9426 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
9427 GEN_HANDLER_E(cmpb
, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE
, PPC2_ISA205
),
9428 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
),
9429 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9430 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9431 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9432 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9433 GEN_HANDLER(mulhw
, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER
),
9434 GEN_HANDLER(mulhwu
, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER
),
9435 GEN_HANDLER(mullw
, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER
),
9436 GEN_HANDLER(mullwo
, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER
),
9437 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9438 #if defined(TARGET_PPC64)
9439 GEN_HANDLER(mulld
, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B
),
9441 GEN_HANDLER(neg
, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER
),
9442 GEN_HANDLER(nego
, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER
),
9443 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9444 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9445 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9446 GEN_HANDLER(cntlzw
, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER
),
9447 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
),
9448 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
),
9449 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9450 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9451 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9452 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9453 GEN_HANDLER(popcntb
, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB
),
9454 GEN_HANDLER(popcntw
, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD
),
9455 GEN_HANDLER_E(prtyw
, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
9456 #if defined(TARGET_PPC64)
9457 GEN_HANDLER(popcntd
, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD
),
9458 GEN_HANDLER(cntlzd
, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B
),
9459 GEN_HANDLER_E(prtyd
, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
9460 GEN_HANDLER_E(bpermd
, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE
, PPC2_PERM_ISA206
),
9462 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9463 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9464 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9465 GEN_HANDLER(slw
, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER
),
9466 GEN_HANDLER(sraw
, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER
),
9467 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
),
9468 GEN_HANDLER(srw
, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER
),
9469 #if defined(TARGET_PPC64)
9470 GEN_HANDLER(sld
, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B
),
9471 GEN_HANDLER(srad
, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B
),
9472 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
),
9473 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
),
9474 GEN_HANDLER(srd
, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B
),
9476 GEN_HANDLER(frsqrtes
, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES
),
9477 GEN_HANDLER(fsqrt
, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
9478 GEN_HANDLER(fsqrts
, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
9479 GEN_HANDLER(fcmpo
, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT
),
9480 GEN_HANDLER(fcmpu
, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT
),
9481 GEN_HANDLER(fabs
, 0x3F, 0x08, 0x08, 0x001F0000, PPC_FLOAT
),
9482 GEN_HANDLER(fmr
, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT
),
9483 GEN_HANDLER(fnabs
, 0x3F, 0x08, 0x04, 0x001F0000, PPC_FLOAT
),
9484 GEN_HANDLER(fneg
, 0x3F, 0x08, 0x01, 0x001F0000, PPC_FLOAT
),
9485 GEN_HANDLER_E(fcpsgn
, 0x3F, 0x08, 0x00, 0x00000000, PPC_NONE
, PPC2_ISA205
),
9486 GEN_HANDLER_E(fmrgew
, 0x3F, 0x06, 0x1E, 0x00000001, PPC_NONE
, PPC2_VSX207
),
9487 GEN_HANDLER_E(fmrgow
, 0x3F, 0x06, 0x1A, 0x00000001, PPC_NONE
, PPC2_VSX207
),
9488 GEN_HANDLER(mcrfs
, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT
),
9489 GEN_HANDLER(mffs
, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT
),
9490 GEN_HANDLER(mtfsb0
, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT
),
9491 GEN_HANDLER(mtfsb1
, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT
),
9492 GEN_HANDLER(mtfsf
, 0x3F, 0x07, 0x16, 0x00000000, PPC_FLOAT
),
9493 GEN_HANDLER(mtfsfi
, 0x3F, 0x06, 0x04, 0x006e0800, PPC_FLOAT
),
9494 #if defined(TARGET_PPC64)
9495 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
),
9496 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
),
9497 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
),
9499 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9500 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9501 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
),
9502 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
),
9503 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
),
9504 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
),
9505 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO
),
9506 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
),
9507 GEN_HANDLER_E(lbarx
, 0x1F, 0x14, 0x01, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
9508 GEN_HANDLER_E(lharx
, 0x1F, 0x14, 0x03, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
9509 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES
),
9510 GEN_HANDLER_E(stbcx_
, 0x1F, 0x16, 0x15, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
9511 GEN_HANDLER_E(sthcx_
, 0x1F, 0x16, 0x16, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
9512 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
),
9513 #if defined(TARGET_PPC64)
9514 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B
),
9515 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
),
9517 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
),
9518 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
),
9519 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
9520 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
9521 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
),
9522 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
),
9523 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
),
9524 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
),
9525 #if defined(TARGET_PPC64)
9526 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
),
9527 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
),
9529 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW
),
9530 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
),
9531 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
9532 #if defined(TARGET_PPC64)
9533 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
),
9534 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
),
9536 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
),
9537 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
),
9538 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
),
9539 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
),
9540 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
),
9541 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
),
9542 #if defined(TARGET_PPC64)
9543 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
),
9545 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC
),
9546 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC
),
9547 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
),
9548 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
),
9549 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
),
9550 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE
),
9551 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE
),
9552 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ
),
9553 GEN_HANDLER(dst
, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC
),
9554 GEN_HANDLER(dstst
, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC
),
9555 GEN_HANDLER(dss
, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC
),
9556 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
),
9557 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
),
9558 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
),
9559 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
),
9560 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
),
9561 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
),
9562 #if defined(TARGET_PPC64)
9563 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
),
9564 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
9566 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
),
9567 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
9569 GEN_HANDLER2(slbmte
, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B
),
9570 GEN_HANDLER2(slbmfee
, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B
),
9571 GEN_HANDLER2(slbmfev
, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B
),
9573 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
),
9574 GEN_HANDLER(tlbiel
, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE
),
9575 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE
),
9576 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
),
9577 #if defined(TARGET_PPC64)
9578 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI
),
9579 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
),
9581 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
),
9582 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
),
9583 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
),
9584 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
),
9585 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
),
9586 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
),
9587 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
),
9588 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
),
9589 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
),
9590 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
),
9591 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
),
9592 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
9593 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
),
9594 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
),
9595 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
),
9596 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
),
9597 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
),
9598 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
),
9599 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
),
9600 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
9601 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
),
9602 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
),
9603 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
),
9604 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
),
9605 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
),
9606 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
),
9607 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
),
9608 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
),
9609 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
),
9610 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
),
9611 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
),
9612 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
),
9613 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
),
9614 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
),
9615 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
),
9616 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
),
9617 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
),
9618 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
),
9619 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
),
9620 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
),
9621 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
),
9622 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
),
9623 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
),
9624 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
),
9625 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
),
9626 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
),
9627 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
),
9628 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
),
9629 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
),
9630 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
9631 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
9632 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
),
9633 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
),
9634 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
9635 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
9636 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
),
9637 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
),
9638 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
),
9639 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
),
9640 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
),
9641 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
),
9642 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
),
9643 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
),
9644 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
),
9645 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
),
9646 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
),
9647 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
),
9648 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
),
9649 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
),
9650 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
),
9651 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
),
9652 GEN_HANDLER_E(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
, PPC2_BOOKE206
),
9653 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
),
9654 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
),
9655 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
),
9656 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
),
9657 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
),
9658 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
),
9659 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
),
9660 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
),
9661 GEN_HANDLER2_E(tlbre_booke206
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
9662 PPC_NONE
, PPC2_BOOKE206
),
9663 GEN_HANDLER2_E(tlbsx_booke206
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
9664 PPC_NONE
, PPC2_BOOKE206
),
9665 GEN_HANDLER2_E(tlbwe_booke206
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
9666 PPC_NONE
, PPC2_BOOKE206
),
9667 GEN_HANDLER2_E(tlbivax_booke206
, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
9668 PPC_NONE
, PPC2_BOOKE206
),
9669 GEN_HANDLER2_E(tlbilx_booke206
, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
9670 PPC_NONE
, PPC2_BOOKE206
),
9671 GEN_HANDLER2_E(msgsnd
, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
9672 PPC_NONE
, PPC2_PRCNTL
),
9673 GEN_HANDLER2_E(msgclr
, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
9674 PPC_NONE
, PPC2_PRCNTL
),
9675 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
),
9676 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE
),
9677 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
),
9678 GEN_HANDLER_E(mbar
, 0x1F, 0x16, 0x1a, 0x001FF801,
9679 PPC_BOOKE
, PPC2_BOOKE206
),
9680 GEN_HANDLER(msync_4xx
, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE
),
9681 GEN_HANDLER2_E(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
9682 PPC_BOOKE
, PPC2_BOOKE206
),
9683 GEN_HANDLER(lvsl
, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC
),
9684 GEN_HANDLER(lvsr
, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC
),
9685 GEN_HANDLER(mfvscr
, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC
),
9686 GEN_HANDLER(mtvscr
, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC
),
9687 GEN_HANDLER(vsldoi
, 0x04, 0x16, 0xFF, 0x00000400, PPC_ALTIVEC
),
9688 GEN_HANDLER(vmladduhm
, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC
),
9689 GEN_HANDLER2(evsel0
, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE
),
9690 GEN_HANDLER2(evsel1
, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE
),
9691 GEN_HANDLER2(evsel2
, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE
),
9692 GEN_HANDLER2(evsel3
, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE
),
9694 #undef GEN_INT_ARITH_ADD
9695 #undef GEN_INT_ARITH_ADD_CONST
9696 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
9697 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
9698 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
9699 add_ca, compute_ca, compute_ov) \
9700 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
9701 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
9702 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
9703 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
9704 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
9705 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
9706 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
9707 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
9708 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
9709 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
9710 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
9712 #undef GEN_INT_ARITH_DIVW
9713 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
9714 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
9715 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0),
9716 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1),
9717 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0),
9718 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1),
9719 GEN_HANDLER_E(divwe
, 0x1F, 0x0B, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9720 GEN_HANDLER_E(divweo
, 0x1F, 0x0B, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9721 GEN_HANDLER_E(divweu
, 0x1F, 0x0B, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9722 GEN_HANDLER_E(divweuo
, 0x1F, 0x0B, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9724 #if defined(TARGET_PPC64)
9725 #undef GEN_INT_ARITH_DIVD
9726 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
9727 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
9728 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0),
9729 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1),
9730 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0),
9731 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1),
9733 GEN_HANDLER_E(divdeu
, 0x1F, 0x09, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9734 GEN_HANDLER_E(divdeuo
, 0x1F, 0x09, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9735 GEN_HANDLER_E(divde
, 0x1F, 0x09, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9736 GEN_HANDLER_E(divdeo
, 0x1F, 0x09, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9738 #undef GEN_INT_ARITH_MUL_HELPER
9739 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
9740 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
9741 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00),
9742 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02),
9743 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17),
9746 #undef GEN_INT_ARITH_SUBF
9747 #undef GEN_INT_ARITH_SUBF_CONST
9748 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
9749 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
9750 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
9751 add_ca, compute_ca, compute_ov) \
9752 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
9753 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
9754 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
9755 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
9756 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
9757 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
9758 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
9759 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
9760 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
9761 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
9762 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
9766 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
9767 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
9768 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
9769 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
9770 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
),
9771 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
),
9772 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
),
9773 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
),
9774 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
),
9775 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
),
9776 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
),
9777 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
),
9778 #if defined(TARGET_PPC64)
9779 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
),
9782 #if defined(TARGET_PPC64)
9785 #define GEN_PPC64_R2(name, opc1, opc2) \
9786 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
9787 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
9789 #define GEN_PPC64_R4(name, opc1, opc2) \
9790 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
9791 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
9793 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
9795 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
9797 GEN_PPC64_R4(rldicl
, 0x1E, 0x00),
9798 GEN_PPC64_R4(rldicr
, 0x1E, 0x02),
9799 GEN_PPC64_R4(rldic
, 0x1E, 0x04),
9800 GEN_PPC64_R2(rldcl
, 0x1E, 0x08),
9801 GEN_PPC64_R2(rldcr
, 0x1E, 0x09),
9802 GEN_PPC64_R4(rldimi
, 0x1E, 0x06),
9805 #undef _GEN_FLOAT_ACB
9806 #undef GEN_FLOAT_ACB
9807 #undef _GEN_FLOAT_AB
9809 #undef _GEN_FLOAT_AC
9813 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
9814 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
9815 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
9816 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
9817 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
9818 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
9819 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
9820 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
9821 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
9822 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
9823 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
9824 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
9825 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
9826 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
9827 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
9828 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
9829 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
9830 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
9831 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
9833 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
),
9834 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
),
9835 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
),
9836 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
),
9837 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
),
9838 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
),
9839 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
),
9840 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
),
9841 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
),
9842 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
),
9843 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
),
9844 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
),
9845 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
),
9846 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
),
9847 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
),
9848 #if defined(TARGET_PPC64)
9849 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
),
9850 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
),
9851 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
),
9853 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
),
9854 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
),
9855 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
),
9856 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
),
9863 #define GEN_LD(name, ldop, opc, type) \
9864 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9865 #define GEN_LDU(name, ldop, opc, type) \
9866 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
9867 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
9868 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
9869 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
9870 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
9871 #define GEN_LDS(name, ldop, op, type) \
9872 GEN_LD(name, ldop, op | 0x20, type) \
9873 GEN_LDU(name, ldop, op | 0x21, type) \
9874 GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
9875 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
9877 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
)
9878 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
)
9879 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
)
9880 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
)
9881 #if defined(TARGET_PPC64)
9882 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
)
9883 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
)
9884 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
)
9885 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
)
9886 GEN_LDX_E(ldbr
, ld64ur
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
)
9888 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
)
9889 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
)
9896 #define GEN_ST(name, stop, opc, type) \
9897 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9898 #define GEN_STU(name, stop, opc, type) \
9899 GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
9900 #define GEN_STUX(name, stop, opc2, opc3, type) \
9901 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
9902 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
9903 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
9904 #define GEN_STS(name, stop, op, type) \
9905 GEN_ST(name, stop, op | 0x20, type) \
9906 GEN_STU(name, stop, op | 0x21, type) \
9907 GEN_STUX(name, stop, 0x17, op | 0x01, type) \
9908 GEN_STX(name, stop, 0x17, op | 0x00, type)
9910 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
)
9911 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
)
9912 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
)
9913 #if defined(TARGET_PPC64)
9914 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
)
9915 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
)
9916 GEN_STX_E(stdbr
, st64r
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
)
9918 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
)
9919 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
)
9926 #define GEN_LDF(name, ldop, opc, type) \
9927 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9928 #define GEN_LDUF(name, ldop, opc, type) \
9929 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
9930 #define GEN_LDUXF(name, ldop, opc, type) \
9931 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
9932 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
9933 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
9934 #define GEN_LDFS(name, ldop, op, type) \
9935 GEN_LDF(name, ldop, op | 0x20, type) \
9936 GEN_LDUF(name, ldop, op | 0x21, type) \
9937 GEN_LDUXF(name, ldop, op | 0x01, type) \
9938 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
9940 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
)
9941 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
)
9942 GEN_HANDLER_E(lfiwax
, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE
, PPC2_ISA205
),
9943 GEN_HANDLER_E(lfdp
, 0x39, 0xFF, 0xFF, 0x00200003, PPC_NONE
, PPC2_ISA205
),
9944 GEN_HANDLER_E(lfdpx
, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE
, PPC2_ISA205
),
9951 #define GEN_STF(name, stop, opc, type) \
9952 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9953 #define GEN_STUF(name, stop, opc, type) \
9954 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
9955 #define GEN_STUXF(name, stop, opc, type) \
9956 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
9957 #define GEN_STXF(name, stop, opc2, opc3, type) \
9958 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
9959 #define GEN_STFS(name, stop, op, type) \
9960 GEN_STF(name, stop, op | 0x20, type) \
9961 GEN_STUF(name, stop, op | 0x21, type) \
9962 GEN_STUXF(name, stop, op | 0x01, type) \
9963 GEN_STXF(name, stop, 0x17, op | 0x00, type)
9965 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
)
9966 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
)
9967 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
)
9968 GEN_HANDLER_E(stfdp
, 0x3D, 0xFF, 0xFF, 0x00200003, PPC_NONE
, PPC2_ISA205
),
9969 GEN_HANDLER_E(stfdpx
, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE
, PPC2_ISA205
),
9972 #define GEN_CRLOGIC(name, tcg_op, opc) \
9973 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
9974 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08),
9975 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04),
9976 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09),
9977 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07),
9978 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01),
9979 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E),
9980 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D),
9981 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06),
9983 #undef GEN_MAC_HANDLER
9984 #define GEN_MAC_HANDLER(name, opc2, opc3) \
9985 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
9986 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05),
9987 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15),
9988 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07),
9989 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17),
9990 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06),
9991 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16),
9992 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04),
9993 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14),
9994 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01),
9995 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11),
9996 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03),
9997 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13),
9998 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02),
9999 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12),
10000 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00),
10001 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10),
10002 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D),
10003 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D),
10004 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F),
10005 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F),
10006 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C),
10007 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C),
10008 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E),
10009 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E),
10010 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05),
10011 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15),
10012 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07),
10013 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17),
10014 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01),
10015 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11),
10016 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03),
10017 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13),
10018 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D),
10019 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D),
10020 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F),
10021 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F),
10022 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05),
10023 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04),
10024 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01),
10025 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00),
10026 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D),
10027 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C),
10033 #define GEN_VR_LDX(name, opc2, opc3) \
10034 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10035 #define GEN_VR_STX(name, opc2, opc3) \
10036 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10037 #define GEN_VR_LVE(name, opc2, opc3) \
10038 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10039 #define GEN_VR_STVE(name, opc2, opc3) \
10040 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10041 GEN_VR_LDX(lvx
, 0x07, 0x03),
10042 GEN_VR_LDX(lvxl
, 0x07, 0x0B),
10043 GEN_VR_LVE(bx
, 0x07, 0x00),
10044 GEN_VR_LVE(hx
, 0x07, 0x01),
10045 GEN_VR_LVE(wx
, 0x07, 0x02),
10046 GEN_VR_STX(svx
, 0x07, 0x07),
10047 GEN_VR_STX(svxl
, 0x07, 0x0F),
10048 GEN_VR_STVE(bx
, 0x07, 0x04),
10049 GEN_VR_STVE(hx
, 0x07, 0x05),
10050 GEN_VR_STVE(wx
, 0x07, 0x06),
10052 #undef GEN_VX_LOGICAL
10053 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
10054 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10055 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16),
10056 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17),
10057 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18),
10058 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19),
10059 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20),
10062 #define GEN_VXFORM(name, opc2, opc3) \
10063 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10064 GEN_VXFORM(vaddubm
, 0, 0),
10065 GEN_VXFORM(vadduhm
, 0, 1),
10066 GEN_VXFORM(vadduwm
, 0, 2),
10067 GEN_VXFORM(vsububm
, 0, 16),
10068 GEN_VXFORM(vsubuhm
, 0, 17),
10069 GEN_VXFORM(vsubuwm
, 0, 18),
10070 GEN_VXFORM(vmaxub
, 1, 0),
10071 GEN_VXFORM(vmaxuh
, 1, 1),
10072 GEN_VXFORM(vmaxuw
, 1, 2),
10073 GEN_VXFORM(vmaxsb
, 1, 4),
10074 GEN_VXFORM(vmaxsh
, 1, 5),
10075 GEN_VXFORM(vmaxsw
, 1, 6),
10076 GEN_VXFORM(vminub
, 1, 8),
10077 GEN_VXFORM(vminuh
, 1, 9),
10078 GEN_VXFORM(vminuw
, 1, 10),
10079 GEN_VXFORM(vminsb
, 1, 12),
10080 GEN_VXFORM(vminsh
, 1, 13),
10081 GEN_VXFORM(vminsw
, 1, 14),
10082 GEN_VXFORM(vavgub
, 1, 16),
10083 GEN_VXFORM(vavguh
, 1, 17),
10084 GEN_VXFORM(vavguw
, 1, 18),
10085 GEN_VXFORM(vavgsb
, 1, 20),
10086 GEN_VXFORM(vavgsh
, 1, 21),
10087 GEN_VXFORM(vavgsw
, 1, 22),
10088 GEN_VXFORM(vmrghb
, 6, 0),
10089 GEN_VXFORM(vmrghh
, 6, 1),
10090 GEN_VXFORM(vmrghw
, 6, 2),
10091 GEN_VXFORM(vmrglb
, 6, 4),
10092 GEN_VXFORM(vmrglh
, 6, 5),
10093 GEN_VXFORM(vmrglw
, 6, 6),
10094 GEN_VXFORM(vmuloub
, 4, 0),
10095 GEN_VXFORM(vmulouh
, 4, 1),
10096 GEN_VXFORM(vmulosb
, 4, 4),
10097 GEN_VXFORM(vmulosh
, 4, 5),
10098 GEN_VXFORM(vmuleub
, 4, 8),
10099 GEN_VXFORM(vmuleuh
, 4, 9),
10100 GEN_VXFORM(vmulesb
, 4, 12),
10101 GEN_VXFORM(vmulesh
, 4, 13),
10102 GEN_VXFORM(vslb
, 2, 4),
10103 GEN_VXFORM(vslh
, 2, 5),
10104 GEN_VXFORM(vslw
, 2, 6),
10105 GEN_VXFORM(vsrb
, 2, 8),
10106 GEN_VXFORM(vsrh
, 2, 9),
10107 GEN_VXFORM(vsrw
, 2, 10),
10108 GEN_VXFORM(vsrab
, 2, 12),
10109 GEN_VXFORM(vsrah
, 2, 13),
10110 GEN_VXFORM(vsraw
, 2, 14),
10111 GEN_VXFORM(vslo
, 6, 16),
10112 GEN_VXFORM(vsro
, 6, 17),
10113 GEN_VXFORM(vaddcuw
, 0, 6),
10114 GEN_VXFORM(vsubcuw
, 0, 22),
10115 GEN_VXFORM(vaddubs
, 0, 8),
10116 GEN_VXFORM(vadduhs
, 0, 9),
10117 GEN_VXFORM(vadduws
, 0, 10),
10118 GEN_VXFORM(vaddsbs
, 0, 12),
10119 GEN_VXFORM(vaddshs
, 0, 13),
10120 GEN_VXFORM(vaddsws
, 0, 14),
10121 GEN_VXFORM(vsububs
, 0, 24),
10122 GEN_VXFORM(vsubuhs
, 0, 25),
10123 GEN_VXFORM(vsubuws
, 0, 26),
10124 GEN_VXFORM(vsubsbs
, 0, 28),
10125 GEN_VXFORM(vsubshs
, 0, 29),
10126 GEN_VXFORM(vsubsws
, 0, 30),
10127 GEN_VXFORM(vrlb
, 2, 0),
10128 GEN_VXFORM(vrlh
, 2, 1),
10129 GEN_VXFORM(vrlw
, 2, 2),
10130 GEN_VXFORM(vsl
, 2, 7),
10131 GEN_VXFORM(vsr
, 2, 11),
10132 GEN_VXFORM(vpkuhum
, 7, 0),
10133 GEN_VXFORM(vpkuwum
, 7, 1),
10134 GEN_VXFORM(vpkuhus
, 7, 2),
10135 GEN_VXFORM(vpkuwus
, 7, 3),
10136 GEN_VXFORM(vpkshus
, 7, 4),
10137 GEN_VXFORM(vpkswus
, 7, 5),
10138 GEN_VXFORM(vpkshss
, 7, 6),
10139 GEN_VXFORM(vpkswss
, 7, 7),
10140 GEN_VXFORM(vpkpx
, 7, 12),
10141 GEN_VXFORM(vsum4ubs
, 4, 24),
10142 GEN_VXFORM(vsum4sbs
, 4, 28),
10143 GEN_VXFORM(vsum4shs
, 4, 25),
10144 GEN_VXFORM(vsum2sws
, 4, 26),
10145 GEN_VXFORM(vsumsws
, 4, 30),
10146 GEN_VXFORM(vaddfp
, 5, 0),
10147 GEN_VXFORM(vsubfp
, 5, 1),
10148 GEN_VXFORM(vmaxfp
, 5, 16),
10149 GEN_VXFORM(vminfp
, 5, 17),
10151 #undef GEN_VXRFORM1
10153 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
10154 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
10155 #define GEN_VXRFORM(name, opc2, opc3) \
10156 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
10157 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
10158 GEN_VXRFORM(vcmpequb
, 3, 0)
10159 GEN_VXRFORM(vcmpequh
, 3, 1)
10160 GEN_VXRFORM(vcmpequw
, 3, 2)
10161 GEN_VXRFORM(vcmpgtsb
, 3, 12)
10162 GEN_VXRFORM(vcmpgtsh
, 3, 13)
10163 GEN_VXRFORM(vcmpgtsw
, 3, 14)
10164 GEN_VXRFORM(vcmpgtub
, 3, 8)
10165 GEN_VXRFORM(vcmpgtuh
, 3, 9)
10166 GEN_VXRFORM(vcmpgtuw
, 3, 10)
10167 GEN_VXRFORM(vcmpeqfp
, 3, 3)
10168 GEN_VXRFORM(vcmpgefp
, 3, 7)
10169 GEN_VXRFORM(vcmpgtfp
, 3, 11)
10170 GEN_VXRFORM(vcmpbfp
, 3, 15)
10172 #undef GEN_VXFORM_SIMM
10173 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
10174 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10175 GEN_VXFORM_SIMM(vspltisb
, 6, 12),
10176 GEN_VXFORM_SIMM(vspltish
, 6, 13),
10177 GEN_VXFORM_SIMM(vspltisw
, 6, 14),
10179 #undef GEN_VXFORM_NOA
10180 #define GEN_VXFORM_NOA(name, opc2, opc3) \
10181 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
10182 GEN_VXFORM_NOA(vupkhsb
, 7, 8),
10183 GEN_VXFORM_NOA(vupkhsh
, 7, 9),
10184 GEN_VXFORM_NOA(vupklsb
, 7, 10),
10185 GEN_VXFORM_NOA(vupklsh
, 7, 11),
10186 GEN_VXFORM_NOA(vupkhpx
, 7, 13),
10187 GEN_VXFORM_NOA(vupklpx
, 7, 15),
10188 GEN_VXFORM_NOA(vrefp
, 5, 4),
10189 GEN_VXFORM_NOA(vrsqrtefp
, 5, 5),
10190 GEN_VXFORM_NOA(vexptefp
, 5, 6),
10191 GEN_VXFORM_NOA(vlogefp
, 5, 7),
10192 GEN_VXFORM_NOA(vrfim
, 5, 8),
10193 GEN_VXFORM_NOA(vrfin
, 5, 9),
10194 GEN_VXFORM_NOA(vrfip
, 5, 10),
10195 GEN_VXFORM_NOA(vrfiz
, 5, 11),
10197 #undef GEN_VXFORM_UIMM
10198 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
10199 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10200 GEN_VXFORM_UIMM(vspltb
, 6, 8),
10201 GEN_VXFORM_UIMM(vsplth
, 6, 9),
10202 GEN_VXFORM_UIMM(vspltw
, 6, 10),
10203 GEN_VXFORM_UIMM(vcfux
, 5, 12),
10204 GEN_VXFORM_UIMM(vcfsx
, 5, 13),
10205 GEN_VXFORM_UIMM(vctuxs
, 5, 14),
10206 GEN_VXFORM_UIMM(vctsxs
, 5, 15),
10208 #undef GEN_VAFORM_PAIRED
10209 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
10210 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
10211 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16),
10212 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18),
10213 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19),
10214 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20),
10215 GEN_VAFORM_PAIRED(vsel
, vperm
, 21),
10216 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23),
10218 GEN_HANDLER_E(lxsdx
, 0x1F, 0x0C, 0x12, 0, PPC_NONE
, PPC2_VSX
),
10219 GEN_HANDLER_E(lxsiwax
, 0x1F, 0x0C, 0x02, 0, PPC_NONE
, PPC2_VSX207
),
10220 GEN_HANDLER_E(lxsiwzx
, 0x1F, 0x0C, 0x00, 0, PPC_NONE
, PPC2_VSX207
),
10221 GEN_HANDLER_E(lxsspx
, 0x1F, 0x0C, 0x10, 0, PPC_NONE
, PPC2_VSX207
),
10222 GEN_HANDLER_E(lxvd2x
, 0x1F, 0x0C, 0x1A, 0, PPC_NONE
, PPC2_VSX
),
10223 GEN_HANDLER_E(lxvdsx
, 0x1F, 0x0C, 0x0A, 0, PPC_NONE
, PPC2_VSX
),
10224 GEN_HANDLER_E(lxvw4x
, 0x1F, 0x0C, 0x18, 0, PPC_NONE
, PPC2_VSX
),
10226 GEN_HANDLER_E(stxsdx
, 0x1F, 0xC, 0x16, 0, PPC_NONE
, PPC2_VSX
),
10227 GEN_HANDLER_E(stxsiwx
, 0x1F, 0xC, 0x04, 0, PPC_NONE
, PPC2_VSX207
),
10228 GEN_HANDLER_E(stxsspx
, 0x1F, 0xC, 0x14, 0, PPC_NONE
, PPC2_VSX207
),
10229 GEN_HANDLER_E(stxvd2x
, 0x1F, 0xC, 0x1E, 0, PPC_NONE
, PPC2_VSX
),
10230 GEN_HANDLER_E(stxvw4x
, 0x1F, 0xC, 0x1C, 0, PPC_NONE
, PPC2_VSX
),
10232 GEN_HANDLER_E(mfvsrwz
, 0x1F, 0x13, 0x03, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
10233 GEN_HANDLER_E(mtvsrwa
, 0x1F, 0x13, 0x06, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
10234 GEN_HANDLER_E(mtvsrwz
, 0x1F, 0x13, 0x07, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
10235 #if defined(TARGET_PPC64)
10236 GEN_HANDLER_E(mfvsrd
, 0x1F, 0x13, 0x01, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
10237 GEN_HANDLER_E(mtvsrd
, 0x1F, 0x13, 0x05, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
10241 #define GEN_XX2FORM(name, opc2, opc3, fl2) \
10242 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10243 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2)
10246 #define GEN_XX3FORM(name, opc2, opc3, fl2) \
10247 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10248 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2), \
10249 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 0, PPC_NONE, fl2), \
10250 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 0, PPC_NONE, fl2)
10252 #undef GEN_XX3_RC_FORM
10253 #define GEN_XX3_RC_FORM(name, opc2, opc3, fl2) \
10254 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x00, 0, PPC_NONE, fl2), \
10255 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x00, 0, PPC_NONE, fl2), \
10256 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x00, 0, PPC_NONE, fl2), \
10257 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x00, 0, PPC_NONE, fl2), \
10258 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x10, 0, PPC_NONE, fl2), \
10259 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x10, 0, PPC_NONE, fl2), \
10260 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x10, 0, PPC_NONE, fl2), \
10261 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x10, 0, PPC_NONE, fl2)
10263 #undef GEN_XX3FORM_DM
10264 #define GEN_XX3FORM_DM(name, opc2, opc3) \
10265 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10266 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10267 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10268 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10269 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10270 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10271 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10272 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10273 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10274 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10275 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10276 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10277 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10278 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10279 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10280 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x0C, 0, PPC_NONE, PPC2_VSX)
10282 GEN_XX2FORM(xsabsdp
, 0x12, 0x15, PPC2_VSX
),
10283 GEN_XX2FORM(xsnabsdp
, 0x12, 0x16, PPC2_VSX
),
10284 GEN_XX2FORM(xsnegdp
, 0x12, 0x17, PPC2_VSX
),
10285 GEN_XX3FORM(xscpsgndp
, 0x00, 0x16, PPC2_VSX
),
10287 GEN_XX2FORM(xvabsdp
, 0x12, 0x1D, PPC2_VSX
),
10288 GEN_XX2FORM(xvnabsdp
, 0x12, 0x1E, PPC2_VSX
),
10289 GEN_XX2FORM(xvnegdp
, 0x12, 0x1F, PPC2_VSX
),
10290 GEN_XX3FORM(xvcpsgndp
, 0x00, 0x1E, PPC2_VSX
),
10291 GEN_XX2FORM(xvabssp
, 0x12, 0x19, PPC2_VSX
),
10292 GEN_XX2FORM(xvnabssp
, 0x12, 0x1A, PPC2_VSX
),
10293 GEN_XX2FORM(xvnegsp
, 0x12, 0x1B, PPC2_VSX
),
10294 GEN_XX3FORM(xvcpsgnsp
, 0x00, 0x1A, PPC2_VSX
),
10296 GEN_XX3FORM(xsadddp
, 0x00, 0x04, PPC2_VSX
),
10297 GEN_XX3FORM(xssubdp
, 0x00, 0x05, PPC2_VSX
),
10298 GEN_XX3FORM(xsmuldp
, 0x00, 0x06, PPC2_VSX
),
10299 GEN_XX3FORM(xsdivdp
, 0x00, 0x07, PPC2_VSX
),
10300 GEN_XX2FORM(xsredp
, 0x14, 0x05, PPC2_VSX
),
10301 GEN_XX2FORM(xssqrtdp
, 0x16, 0x04, PPC2_VSX
),
10302 GEN_XX2FORM(xsrsqrtedp
, 0x14, 0x04, PPC2_VSX
),
10303 GEN_XX3FORM(xstdivdp
, 0x14, 0x07, PPC2_VSX
),
10304 GEN_XX2FORM(xstsqrtdp
, 0x14, 0x06, PPC2_VSX
),
10305 GEN_XX3FORM(xsmaddadp
, 0x04, 0x04, PPC2_VSX
),
10306 GEN_XX3FORM(xsmaddmdp
, 0x04, 0x05, PPC2_VSX
),
10307 GEN_XX3FORM(xsmsubadp
, 0x04, 0x06, PPC2_VSX
),
10308 GEN_XX3FORM(xsmsubmdp
, 0x04, 0x07, PPC2_VSX
),
10309 GEN_XX3FORM(xsnmaddadp
, 0x04, 0x14, PPC2_VSX
),
10310 GEN_XX3FORM(xsnmaddmdp
, 0x04, 0x15, PPC2_VSX
),
10311 GEN_XX3FORM(xsnmsubadp
, 0x04, 0x16, PPC2_VSX
),
10312 GEN_XX3FORM(xsnmsubmdp
, 0x04, 0x17, PPC2_VSX
),
10313 GEN_XX2FORM(xscmpodp
, 0x0C, 0x05, PPC2_VSX
),
10314 GEN_XX2FORM(xscmpudp
, 0x0C, 0x04, PPC2_VSX
),
10315 GEN_XX3FORM(xsmaxdp
, 0x00, 0x14, PPC2_VSX
),
10316 GEN_XX3FORM(xsmindp
, 0x00, 0x15, PPC2_VSX
),
10317 GEN_XX2FORM(xscvdpsp
, 0x12, 0x10, PPC2_VSX
),
10318 GEN_XX2FORM(xscvdpspn
, 0x16, 0x10, PPC2_VSX207
),
10319 GEN_XX2FORM(xscvspdp
, 0x12, 0x14, PPC2_VSX
),
10320 GEN_XX2FORM(xscvspdpn
, 0x16, 0x14, PPC2_VSX207
),
10321 GEN_XX2FORM(xscvdpsxds
, 0x10, 0x15, PPC2_VSX
),
10322 GEN_XX2FORM(xscvdpsxws
, 0x10, 0x05, PPC2_VSX
),
10323 GEN_XX2FORM(xscvdpuxds
, 0x10, 0x14, PPC2_VSX
),
10324 GEN_XX2FORM(xscvdpuxws
, 0x10, 0x04, PPC2_VSX
),
10325 GEN_XX2FORM(xscvsxddp
, 0x10, 0x17, PPC2_VSX
),
10326 GEN_XX2FORM(xscvuxddp
, 0x10, 0x16, PPC2_VSX
),
10327 GEN_XX2FORM(xsrdpi
, 0x12, 0x04, PPC2_VSX
),
10328 GEN_XX2FORM(xsrdpic
, 0x16, 0x06, PPC2_VSX
),
10329 GEN_XX2FORM(xsrdpim
, 0x12, 0x07, PPC2_VSX
),
10330 GEN_XX2FORM(xsrdpip
, 0x12, 0x06, PPC2_VSX
),
10331 GEN_XX2FORM(xsrdpiz
, 0x12, 0x05, PPC2_VSX
),
10333 GEN_XX3FORM(xsaddsp
, 0x00, 0x00, PPC2_VSX207
),
10334 GEN_XX3FORM(xssubsp
, 0x00, 0x01, PPC2_VSX207
),
10335 GEN_XX3FORM(xsmulsp
, 0x00, 0x02, PPC2_VSX207
),
10336 GEN_XX3FORM(xsdivsp
, 0x00, 0x03, PPC2_VSX207
),
10337 GEN_XX2FORM(xsresp
, 0x14, 0x01, PPC2_VSX207
),
10338 GEN_XX2FORM(xsrsp
, 0x12, 0x11, PPC2_VSX207
),
10339 GEN_XX2FORM(xssqrtsp
, 0x16, 0x00, PPC2_VSX207
),
10340 GEN_XX2FORM(xsrsqrtesp
, 0x14, 0x00, PPC2_VSX207
),
10341 GEN_XX3FORM(xsmaddasp
, 0x04, 0x00, PPC2_VSX207
),
10342 GEN_XX3FORM(xsmaddmsp
, 0x04, 0x01, PPC2_VSX207
),
10343 GEN_XX3FORM(xsmsubasp
, 0x04, 0x02, PPC2_VSX207
),
10344 GEN_XX3FORM(xsmsubmsp
, 0x04, 0x03, PPC2_VSX207
),
10345 GEN_XX3FORM(xsnmaddasp
, 0x04, 0x10, PPC2_VSX207
),
10346 GEN_XX3FORM(xsnmaddmsp
, 0x04, 0x11, PPC2_VSX207
),
10347 GEN_XX3FORM(xsnmsubasp
, 0x04, 0x12, PPC2_VSX207
),
10348 GEN_XX3FORM(xsnmsubmsp
, 0x04, 0x13, PPC2_VSX207
),
10349 GEN_XX2FORM(xscvsxdsp
, 0x10, 0x13, PPC2_VSX207
),
10350 GEN_XX2FORM(xscvuxdsp
, 0x10, 0x12, PPC2_VSX207
),
10352 GEN_XX3FORM(xvadddp
, 0x00, 0x0C, PPC2_VSX
),
10353 GEN_XX3FORM(xvsubdp
, 0x00, 0x0D, PPC2_VSX
),
10354 GEN_XX3FORM(xvmuldp
, 0x00, 0x0E, PPC2_VSX
),
10355 GEN_XX3FORM(xvdivdp
, 0x00, 0x0F, PPC2_VSX
),
10356 GEN_XX2FORM(xvredp
, 0x14, 0x0D, PPC2_VSX
),
10357 GEN_XX2FORM(xvsqrtdp
, 0x16, 0x0C, PPC2_VSX
),
10358 GEN_XX2FORM(xvrsqrtedp
, 0x14, 0x0C, PPC2_VSX
),
10359 GEN_XX3FORM(xvtdivdp
, 0x14, 0x0F, PPC2_VSX
),
10360 GEN_XX2FORM(xvtsqrtdp
, 0x14, 0x0E, PPC2_VSX
),
10361 GEN_XX3FORM(xvmaddadp
, 0x04, 0x0C, PPC2_VSX
),
10362 GEN_XX3FORM(xvmaddmdp
, 0x04, 0x0D, PPC2_VSX
),
10363 GEN_XX3FORM(xvmsubadp
, 0x04, 0x0E, PPC2_VSX
),
10364 GEN_XX3FORM(xvmsubmdp
, 0x04, 0x0F, PPC2_VSX
),
10365 GEN_XX3FORM(xvnmaddadp
, 0x04, 0x1C, PPC2_VSX
),
10366 GEN_XX3FORM(xvnmaddmdp
, 0x04, 0x1D, PPC2_VSX
),
10367 GEN_XX3FORM(xvnmsubadp
, 0x04, 0x1E, PPC2_VSX
),
10368 GEN_XX3FORM(xvnmsubmdp
, 0x04, 0x1F, PPC2_VSX
),
10369 GEN_XX3FORM(xvmaxdp
, 0x00, 0x1C, PPC2_VSX
),
10370 GEN_XX3FORM(xvmindp
, 0x00, 0x1D, PPC2_VSX
),
10371 GEN_XX3_RC_FORM(xvcmpeqdp
, 0x0C, 0x0C, PPC2_VSX
),
10372 GEN_XX3_RC_FORM(xvcmpgtdp
, 0x0C, 0x0D, PPC2_VSX
),
10373 GEN_XX3_RC_FORM(xvcmpgedp
, 0x0C, 0x0E, PPC2_VSX
),
10374 GEN_XX2FORM(xvcvdpsp
, 0x12, 0x18, PPC2_VSX
),
10375 GEN_XX2FORM(xvcvdpsxds
, 0x10, 0x1D, PPC2_VSX
),
10376 GEN_XX2FORM(xvcvdpsxws
, 0x10, 0x0D, PPC2_VSX
),
10377 GEN_XX2FORM(xvcvdpuxds
, 0x10, 0x1C, PPC2_VSX
),
10378 GEN_XX2FORM(xvcvdpuxws
, 0x10, 0x0C, PPC2_VSX
),
10379 GEN_XX2FORM(xvcvsxddp
, 0x10, 0x1F, PPC2_VSX
),
10380 GEN_XX2FORM(xvcvuxddp
, 0x10, 0x1E, PPC2_VSX
),
10381 GEN_XX2FORM(xvcvsxwdp
, 0x10, 0x0F, PPC2_VSX
),
10382 GEN_XX2FORM(xvcvuxwdp
, 0x10, 0x0E, PPC2_VSX
),
10383 GEN_XX2FORM(xvrdpi
, 0x12, 0x0C, PPC2_VSX
),
10384 GEN_XX2FORM(xvrdpic
, 0x16, 0x0E, PPC2_VSX
),
10385 GEN_XX2FORM(xvrdpim
, 0x12, 0x0F, PPC2_VSX
),
10386 GEN_XX2FORM(xvrdpip
, 0x12, 0x0E, PPC2_VSX
),
10387 GEN_XX2FORM(xvrdpiz
, 0x12, 0x0D, PPC2_VSX
),
10389 GEN_XX3FORM(xvaddsp
, 0x00, 0x08, PPC2_VSX
),
10390 GEN_XX3FORM(xvsubsp
, 0x00, 0x09, PPC2_VSX
),
10391 GEN_XX3FORM(xvmulsp
, 0x00, 0x0A, PPC2_VSX
),
10392 GEN_XX3FORM(xvdivsp
, 0x00, 0x0B, PPC2_VSX
),
10393 GEN_XX2FORM(xvresp
, 0x14, 0x09, PPC2_VSX
),
10394 GEN_XX2FORM(xvsqrtsp
, 0x16, 0x08, PPC2_VSX
),
10395 GEN_XX2FORM(xvrsqrtesp
, 0x14, 0x08, PPC2_VSX
),
10396 GEN_XX3FORM(xvtdivsp
, 0x14, 0x0B, PPC2_VSX
),
10397 GEN_XX2FORM(xvtsqrtsp
, 0x14, 0x0A, PPC2_VSX
),
10398 GEN_XX3FORM(xvmaddasp
, 0x04, 0x08, PPC2_VSX
),
10399 GEN_XX3FORM(xvmaddmsp
, 0x04, 0x09, PPC2_VSX
),
10400 GEN_XX3FORM(xvmsubasp
, 0x04, 0x0A, PPC2_VSX
),
10401 GEN_XX3FORM(xvmsubmsp
, 0x04, 0x0B, PPC2_VSX
),
10402 GEN_XX3FORM(xvnmaddasp
, 0x04, 0x18, PPC2_VSX
),
10403 GEN_XX3FORM(xvnmaddmsp
, 0x04, 0x19, PPC2_VSX
),
10404 GEN_XX3FORM(xvnmsubasp
, 0x04, 0x1A, PPC2_VSX
),
10405 GEN_XX3FORM(xvnmsubmsp
, 0x04, 0x1B, PPC2_VSX
),
10406 GEN_XX3FORM(xvmaxsp
, 0x00, 0x18, PPC2_VSX
),
10407 GEN_XX3FORM(xvminsp
, 0x00, 0x19, PPC2_VSX
),
10408 GEN_XX3_RC_FORM(xvcmpeqsp
, 0x0C, 0x08, PPC2_VSX
),
10409 GEN_XX3_RC_FORM(xvcmpgtsp
, 0x0C, 0x09, PPC2_VSX
),
10410 GEN_XX3_RC_FORM(xvcmpgesp
, 0x0C, 0x0A, PPC2_VSX
),
10411 GEN_XX2FORM(xvcvspdp
, 0x12, 0x1C, PPC2_VSX
),
10412 GEN_XX2FORM(xvcvspsxds
, 0x10, 0x19, PPC2_VSX
),
10413 GEN_XX2FORM(xvcvspsxws
, 0x10, 0x09, PPC2_VSX
),
10414 GEN_XX2FORM(xvcvspuxds
, 0x10, 0x18, PPC2_VSX
),
10415 GEN_XX2FORM(xvcvspuxws
, 0x10, 0x08, PPC2_VSX
),
10416 GEN_XX2FORM(xvcvsxdsp
, 0x10, 0x1B, PPC2_VSX
),
10417 GEN_XX2FORM(xvcvuxdsp
, 0x10, 0x1A, PPC2_VSX
),
10418 GEN_XX2FORM(xvcvsxwsp
, 0x10, 0x0B, PPC2_VSX
),
10419 GEN_XX2FORM(xvcvuxwsp
, 0x10, 0x0A, PPC2_VSX
),
10420 GEN_XX2FORM(xvrspi
, 0x12, 0x08, PPC2_VSX
),
10421 GEN_XX2FORM(xvrspic
, 0x16, 0x0A, PPC2_VSX
),
10422 GEN_XX2FORM(xvrspim
, 0x12, 0x0B, PPC2_VSX
),
10423 GEN_XX2FORM(xvrspip
, 0x12, 0x0A, PPC2_VSX
),
10424 GEN_XX2FORM(xvrspiz
, 0x12, 0x09, PPC2_VSX
),
10427 #define VSX_LOGICAL(name, opc2, opc3, fl2) \
10428 GEN_XX3FORM(name, opc2, opc3, fl2)
10430 VSX_LOGICAL(xxland
, 0x8, 0x10, PPC2_VSX
),
10431 VSX_LOGICAL(xxlandc
, 0x8, 0x11, PPC2_VSX
),
10432 VSX_LOGICAL(xxlor
, 0x8, 0x12, PPC2_VSX
),
10433 VSX_LOGICAL(xxlxor
, 0x8, 0x13, PPC2_VSX
),
10434 VSX_LOGICAL(xxlnor
, 0x8, 0x14, PPC2_VSX
),
10435 VSX_LOGICAL(xxleqv
, 0x8, 0x17, PPC2_VSX207
),
10436 VSX_LOGICAL(xxlnand
, 0x8, 0x16, PPC2_VSX207
),
10437 VSX_LOGICAL(xxlorc
, 0x8, 0x15, PPC2_VSX207
),
10438 GEN_XX3FORM(xxmrghw
, 0x08, 0x02, PPC2_VSX
),
10439 GEN_XX3FORM(xxmrglw
, 0x08, 0x06, PPC2_VSX
),
10440 GEN_XX2FORM(xxspltw
, 0x08, 0x0A, PPC2_VSX
),
10441 GEN_XX3FORM_DM(xxsldwi
, 0x08, 0x00),
10443 #define GEN_XXSEL_ROW(opc3) \
10444 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x18, opc3, 0, PPC_NONE, PPC2_VSX), \
10445 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x19, opc3, 0, PPC_NONE, PPC2_VSX), \
10446 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1A, opc3, 0, PPC_NONE, PPC2_VSX), \
10447 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1B, opc3, 0, PPC_NONE, PPC2_VSX), \
10448 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1C, opc3, 0, PPC_NONE, PPC2_VSX), \
10449 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1D, opc3, 0, PPC_NONE, PPC2_VSX), \
10450 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1E, opc3, 0, PPC_NONE, PPC2_VSX), \
10451 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1F, opc3, 0, PPC_NONE, PPC2_VSX), \
10453 GEN_XXSEL_ROW(0x00)
10454 GEN_XXSEL_ROW(0x01)
10455 GEN_XXSEL_ROW(0x02)
10456 GEN_XXSEL_ROW(0x03)
10457 GEN_XXSEL_ROW(0x04)
10458 GEN_XXSEL_ROW(0x05)
10459 GEN_XXSEL_ROW(0x06)
10460 GEN_XXSEL_ROW(0x07)
10461 GEN_XXSEL_ROW(0x08)
10462 GEN_XXSEL_ROW(0x09)
10463 GEN_XXSEL_ROW(0x0A)
10464 GEN_XXSEL_ROW(0x0B)
10465 GEN_XXSEL_ROW(0x0C)
10466 GEN_XXSEL_ROW(0x0D)
10467 GEN_XXSEL_ROW(0x0E)
10468 GEN_XXSEL_ROW(0x0F)
10469 GEN_XXSEL_ROW(0x10)
10470 GEN_XXSEL_ROW(0x11)
10471 GEN_XXSEL_ROW(0x12)
10472 GEN_XXSEL_ROW(0x13)
10473 GEN_XXSEL_ROW(0x14)
10474 GEN_XXSEL_ROW(0x15)
10475 GEN_XXSEL_ROW(0x16)
10476 GEN_XXSEL_ROW(0x17)
10477 GEN_XXSEL_ROW(0x18)
10478 GEN_XXSEL_ROW(0x19)
10479 GEN_XXSEL_ROW(0x1A)
10480 GEN_XXSEL_ROW(0x1B)
10481 GEN_XXSEL_ROW(0x1C)
10482 GEN_XXSEL_ROW(0x1D)
10483 GEN_XXSEL_ROW(0x1E)
10484 GEN_XXSEL_ROW(0x1F)
10486 GEN_XX3FORM_DM(xxpermdi
, 0x08, 0x01),
10489 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
10490 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
10491 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10492 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10493 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10494 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10495 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
10496 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
10497 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
10498 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE
),
10499 GEN_SPE(evmra
, speundef
, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE
),
10500 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
),
10501 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10502 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
10503 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
10504 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE
),
10505 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE
),
10506 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE
),
10507 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
),
10508 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10509 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
10510 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
10511 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10512 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10513 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE
),
10514 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE
),
10515 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
10516 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
10517 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE
),
10518 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE
),
10519 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE
),
10521 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
10522 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
),
10523 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
),
10524 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
10525 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
10526 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
10527 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
10528 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
10529 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
10530 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
10531 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
10532 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
10533 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
10534 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
10536 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
10537 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
),
10538 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
),
10539 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
10540 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
10541 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE
),
10542 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
10543 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
10544 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
10545 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
10546 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
10547 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
10548 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
10549 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
10551 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
),
10552 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
10553 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE
),
10554 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
10555 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
),
10556 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
10557 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
),
10558 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE
),
10559 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
10560 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
10561 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
10562 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
10563 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
10564 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
10565 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
),
10566 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
10568 #undef GEN_SPEOP_LDST
10569 #define GEN_SPEOP_LDST(name, opc2, sh) \
10570 GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
10571 GEN_SPEOP_LDST(evldd
, 0x00, 3),
10572 GEN_SPEOP_LDST(evldw
, 0x01, 3),
10573 GEN_SPEOP_LDST(evldh
, 0x02, 3),
10574 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1),
10575 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1),
10576 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1),
10577 GEN_SPEOP_LDST(evlwhe
, 0x08, 2),
10578 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2),
10579 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2),
10580 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2),
10581 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2),
10583 GEN_SPEOP_LDST(evstdd
, 0x10, 3),
10584 GEN_SPEOP_LDST(evstdw
, 0x11, 3),
10585 GEN_SPEOP_LDST(evstdh
, 0x12, 3),
10586 GEN_SPEOP_LDST(evstwhe
, 0x18, 2),
10587 GEN_SPEOP_LDST(evstwho
, 0x1A, 2),
10588 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2),
10589 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2),
10592 #include "helper_regs.h"
10593 #include "translate_init.c"
10595 /*****************************************************************************/
10596 /* Misc PowerPC helpers */
10597 void ppc_cpu_dump_state(CPUState
*cs
, FILE *f
, fprintf_function cpu_fprintf
,
10603 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
10604 CPUPPCState
*env
= &cpu
->env
;
10607 cpu_fprintf(f
, "NIP " TARGET_FMT_lx
" LR " TARGET_FMT_lx
" CTR "
10608 TARGET_FMT_lx
" XER " TARGET_FMT_lx
"\n",
10609 env
->nip
, env
->lr
, env
->ctr
, cpu_read_xer(env
));
10610 cpu_fprintf(f
, "MSR " TARGET_FMT_lx
" HID0 " TARGET_FMT_lx
" HF "
10611 TARGET_FMT_lx
" idx %d\n", env
->msr
, env
->spr
[SPR_HID0
],
10612 env
->hflags
, env
->mmu_idx
);
10613 #if !defined(NO_TIMER_DUMP)
10614 cpu_fprintf(f
, "TB %08" PRIu32
" %08" PRIu64
10615 #if !defined(CONFIG_USER_ONLY)
10619 cpu_ppc_load_tbu(env
), cpu_ppc_load_tbl(env
)
10620 #if !defined(CONFIG_USER_ONLY)
10621 , cpu_ppc_load_decr(env
)
10625 for (i
= 0; i
< 32; i
++) {
10626 if ((i
& (RGPL
- 1)) == 0)
10627 cpu_fprintf(f
, "GPR%02d", i
);
10628 cpu_fprintf(f
, " %016" PRIx64
, ppc_dump_gpr(env
, i
));
10629 if ((i
& (RGPL
- 1)) == (RGPL
- 1))
10630 cpu_fprintf(f
, "\n");
10632 cpu_fprintf(f
, "CR ");
10633 for (i
= 0; i
< 8; i
++)
10634 cpu_fprintf(f
, "%01x", env
->crf
[i
]);
10635 cpu_fprintf(f
, " [");
10636 for (i
= 0; i
< 8; i
++) {
10638 if (env
->crf
[i
] & 0x08)
10640 else if (env
->crf
[i
] & 0x04)
10642 else if (env
->crf
[i
] & 0x02)
10644 cpu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
10646 cpu_fprintf(f
, " ] RES " TARGET_FMT_lx
"\n",
10647 env
->reserve_addr
);
10648 for (i
= 0; i
< 32; i
++) {
10649 if ((i
& (RFPL
- 1)) == 0)
10650 cpu_fprintf(f
, "FPR%02d", i
);
10651 cpu_fprintf(f
, " %016" PRIx64
, *((uint64_t *)&env
->fpr
[i
]));
10652 if ((i
& (RFPL
- 1)) == (RFPL
- 1))
10653 cpu_fprintf(f
, "\n");
10655 cpu_fprintf(f
, "FPSCR " TARGET_FMT_lx
"\n", env
->fpscr
);
10656 #if !defined(CONFIG_USER_ONLY)
10657 cpu_fprintf(f
, " SRR0 " TARGET_FMT_lx
" SRR1 " TARGET_FMT_lx
10658 " PVR " TARGET_FMT_lx
" VRSAVE " TARGET_FMT_lx
"\n",
10659 env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
10660 env
->spr
[SPR_PVR
], env
->spr
[SPR_VRSAVE
]);
10662 cpu_fprintf(f
, "SPRG0 " TARGET_FMT_lx
" SPRG1 " TARGET_FMT_lx
10663 " SPRG2 " TARGET_FMT_lx
" SPRG3 " TARGET_FMT_lx
"\n",
10664 env
->spr
[SPR_SPRG0
], env
->spr
[SPR_SPRG1
],
10665 env
->spr
[SPR_SPRG2
], env
->spr
[SPR_SPRG3
]);
10667 cpu_fprintf(f
, "SPRG4 " TARGET_FMT_lx
" SPRG5 " TARGET_FMT_lx
10668 " SPRG6 " TARGET_FMT_lx
" SPRG7 " TARGET_FMT_lx
"\n",
10669 env
->spr
[SPR_SPRG4
], env
->spr
[SPR_SPRG5
],
10670 env
->spr
[SPR_SPRG6
], env
->spr
[SPR_SPRG7
]);
10672 if (env
->excp_model
== POWERPC_EXCP_BOOKE
) {
10673 cpu_fprintf(f
, "CSRR0 " TARGET_FMT_lx
" CSRR1 " TARGET_FMT_lx
10674 " MCSRR0 " TARGET_FMT_lx
" MCSRR1 " TARGET_FMT_lx
"\n",
10675 env
->spr
[SPR_BOOKE_CSRR0
], env
->spr
[SPR_BOOKE_CSRR1
],
10676 env
->spr
[SPR_BOOKE_MCSRR0
], env
->spr
[SPR_BOOKE_MCSRR1
]);
10678 cpu_fprintf(f
, " TCR " TARGET_FMT_lx
" TSR " TARGET_FMT_lx
10679 " ESR " TARGET_FMT_lx
" DEAR " TARGET_FMT_lx
"\n",
10680 env
->spr
[SPR_BOOKE_TCR
], env
->spr
[SPR_BOOKE_TSR
],
10681 env
->spr
[SPR_BOOKE_ESR
], env
->spr
[SPR_BOOKE_DEAR
]);
10683 cpu_fprintf(f
, " PIR " TARGET_FMT_lx
" DECAR " TARGET_FMT_lx
10684 " IVPR " TARGET_FMT_lx
" EPCR " TARGET_FMT_lx
"\n",
10685 env
->spr
[SPR_BOOKE_PIR
], env
->spr
[SPR_BOOKE_DECAR
],
10686 env
->spr
[SPR_BOOKE_IVPR
], env
->spr
[SPR_BOOKE_EPCR
]);
10688 cpu_fprintf(f
, " MCSR " TARGET_FMT_lx
" SPRG8 " TARGET_FMT_lx
10689 " EPR " TARGET_FMT_lx
"\n",
10690 env
->spr
[SPR_BOOKE_MCSR
], env
->spr
[SPR_BOOKE_SPRG8
],
10691 env
->spr
[SPR_BOOKE_EPR
]);
10694 cpu_fprintf(f
, " MCAR " TARGET_FMT_lx
" PID1 " TARGET_FMT_lx
10695 " PID2 " TARGET_FMT_lx
" SVR " TARGET_FMT_lx
"\n",
10696 env
->spr
[SPR_Exxx_MCAR
], env
->spr
[SPR_BOOKE_PID1
],
10697 env
->spr
[SPR_BOOKE_PID2
], env
->spr
[SPR_E500_SVR
]);
10700 * IVORs are left out as they are large and do not change often --
10701 * they can be read with "p $ivor0", "p $ivor1", etc.
10705 #if defined(TARGET_PPC64)
10706 if (env
->flags
& POWERPC_FLAG_CFAR
) {
10707 cpu_fprintf(f
, " CFAR " TARGET_FMT_lx
"\n", env
->cfar
);
10711 switch (env
->mmu_model
) {
10712 case POWERPC_MMU_32B
:
10713 case POWERPC_MMU_601
:
10714 case POWERPC_MMU_SOFT_6xx
:
10715 case POWERPC_MMU_SOFT_74xx
:
10716 #if defined(TARGET_PPC64)
10717 case POWERPC_MMU_64B
:
10718 case POWERPC_MMU_2_06
:
10719 case POWERPC_MMU_2_06a
:
10720 case POWERPC_MMU_2_06d
:
10722 cpu_fprintf(f
, " SDR1 " TARGET_FMT_lx
" DAR " TARGET_FMT_lx
10723 " DSISR " TARGET_FMT_lx
"\n", env
->spr
[SPR_SDR1
],
10724 env
->spr
[SPR_DAR
], env
->spr
[SPR_DSISR
]);
10726 case POWERPC_MMU_BOOKE206
:
10727 cpu_fprintf(f
, " MAS0 " TARGET_FMT_lx
" MAS1 " TARGET_FMT_lx
10728 " MAS2 " TARGET_FMT_lx
" MAS3 " TARGET_FMT_lx
"\n",
10729 env
->spr
[SPR_BOOKE_MAS0
], env
->spr
[SPR_BOOKE_MAS1
],
10730 env
->spr
[SPR_BOOKE_MAS2
], env
->spr
[SPR_BOOKE_MAS3
]);
10732 cpu_fprintf(f
, " MAS4 " TARGET_FMT_lx
" MAS6 " TARGET_FMT_lx
10733 " MAS7 " TARGET_FMT_lx
" PID " TARGET_FMT_lx
"\n",
10734 env
->spr
[SPR_BOOKE_MAS4
], env
->spr
[SPR_BOOKE_MAS6
],
10735 env
->spr
[SPR_BOOKE_MAS7
], env
->spr
[SPR_BOOKE_PID
]);
10737 cpu_fprintf(f
, "MMUCFG " TARGET_FMT_lx
" TLB0CFG " TARGET_FMT_lx
10738 " TLB1CFG " TARGET_FMT_lx
"\n",
10739 env
->spr
[SPR_MMUCFG
], env
->spr
[SPR_BOOKE_TLB0CFG
],
10740 env
->spr
[SPR_BOOKE_TLB1CFG
]);
10751 void ppc_cpu_dump_statistics(CPUState
*cs
, FILE*f
,
10752 fprintf_function cpu_fprintf
, int flags
)
10754 #if defined(DO_PPC_STATISTICS)
10755 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
10756 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
10759 t1
= cpu
->env
.opcodes
;
10760 for (op1
= 0; op1
< 64; op1
++) {
10762 if (is_indirect_opcode(handler
)) {
10763 t2
= ind_table(handler
);
10764 for (op2
= 0; op2
< 32; op2
++) {
10766 if (is_indirect_opcode(handler
)) {
10767 t3
= ind_table(handler
);
10768 for (op3
= 0; op3
< 32; op3
++) {
10770 if (handler
->count
== 0)
10772 cpu_fprintf(f
, "%02x %02x %02x (%02x %04d) %16s: "
10773 "%016" PRIx64
" %" PRId64
"\n",
10774 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
10776 handler
->count
, handler
->count
);
10779 if (handler
->count
== 0)
10781 cpu_fprintf(f
, "%02x %02x (%02x %04d) %16s: "
10782 "%016" PRIx64
" %" PRId64
"\n",
10783 op1
, op2
, op1
, op2
, handler
->oname
,
10784 handler
->count
, handler
->count
);
10788 if (handler
->count
== 0)
10790 cpu_fprintf(f
, "%02x (%02x ) %16s: %016" PRIx64
10792 op1
, op1
, handler
->oname
,
10793 handler
->count
, handler
->count
);
10799 /*****************************************************************************/
10800 static inline void gen_intermediate_code_internal(PowerPCCPU
*cpu
,
10801 TranslationBlock
*tb
,
10804 CPUState
*cs
= CPU(cpu
);
10805 CPUPPCState
*env
= &cpu
->env
;
10806 DisasContext ctx
, *ctxp
= &ctx
;
10807 opc_handler_t
**table
, *handler
;
10808 target_ulong pc_start
;
10809 uint16_t *gen_opc_end
;
10816 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
10817 ctx
.nip
= pc_start
;
10819 ctx
.exception
= POWERPC_EXCP_NONE
;
10820 ctx
.spr_cb
= env
->spr_cb
;
10821 ctx
.mem_idx
= env
->mmu_idx
;
10822 ctx
.insns_flags
= env
->insns_flags
;
10823 ctx
.insns_flags2
= env
->insns_flags2
;
10824 ctx
.access_type
= -1;
10825 ctx
.le_mode
= env
->hflags
& (1 << MSR_LE
) ? 1 : 0;
10826 #if defined(TARGET_PPC64)
10827 ctx
.sf_mode
= msr_is_64bit(env
, env
->msr
);
10828 ctx
.has_cfar
= !!(env
->flags
& POWERPC_FLAG_CFAR
);
10830 ctx
.fpu_enabled
= msr_fp
;
10831 if ((env
->flags
& POWERPC_FLAG_SPE
) && msr_spe
)
10832 ctx
.spe_enabled
= msr_spe
;
10834 ctx
.spe_enabled
= 0;
10835 if ((env
->flags
& POWERPC_FLAG_VRE
) && msr_vr
)
10836 ctx
.altivec_enabled
= msr_vr
;
10838 ctx
.altivec_enabled
= 0;
10839 if ((env
->flags
& POWERPC_FLAG_VSX
) && msr_vsx
) {
10840 ctx
.vsx_enabled
= msr_vsx
;
10842 ctx
.vsx_enabled
= 0;
10844 if ((env
->flags
& POWERPC_FLAG_SE
) && msr_se
)
10845 ctx
.singlestep_enabled
= CPU_SINGLE_STEP
;
10847 ctx
.singlestep_enabled
= 0;
10848 if ((env
->flags
& POWERPC_FLAG_BE
) && msr_be
)
10849 ctx
.singlestep_enabled
|= CPU_BRANCH_STEP
;
10850 if (unlikely(cs
->singlestep_enabled
)) {
10851 ctx
.singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
10853 #if defined (DO_SINGLE_STEP) && 0
10854 /* Single step trace mode */
10858 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
10859 if (max_insns
== 0)
10860 max_insns
= CF_COUNT_MASK
;
10863 /* Set env in case of segfault during code fetch */
10864 while (ctx
.exception
== POWERPC_EXCP_NONE
10865 && tcg_ctx
.gen_opc_ptr
< gen_opc_end
) {
10866 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
10867 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
10868 if (bp
->pc
== ctx
.nip
) {
10869 gen_debug_exception(ctxp
);
10874 if (unlikely(search_pc
)) {
10875 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
10879 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
10881 tcg_ctx
.gen_opc_pc
[lj
] = ctx
.nip
;
10882 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
10883 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
10885 LOG_DISAS("----------------\n");
10886 LOG_DISAS("nip=" TARGET_FMT_lx
" super=%d ir=%d\n",
10887 ctx
.nip
, ctx
.mem_idx
, (int)msr_ir
);
10888 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
10890 if (unlikely(ctx
.le_mode
)) {
10891 ctx
.opcode
= bswap32(cpu_ldl_code(env
, ctx
.nip
));
10893 ctx
.opcode
= cpu_ldl_code(env
, ctx
.nip
);
10895 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
10896 ctx
.opcode
, opc1(ctx
.opcode
), opc2(ctx
.opcode
),
10897 opc3(ctx
.opcode
), ctx
.le_mode
? "little" : "big");
10898 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
10899 tcg_gen_debug_insn_start(ctx
.nip
);
10902 table
= env
->opcodes
;
10904 handler
= table
[opc1(ctx
.opcode
)];
10905 if (is_indirect_opcode(handler
)) {
10906 table
= ind_table(handler
);
10907 handler
= table
[opc2(ctx
.opcode
)];
10908 if (is_indirect_opcode(handler
)) {
10909 table
= ind_table(handler
);
10910 handler
= table
[opc3(ctx
.opcode
)];
10913 /* Is opcode *REALLY* valid ? */
10914 if (unlikely(handler
->handler
== &gen_invalid
)) {
10915 if (qemu_log_enabled()) {
10916 qemu_log("invalid/unsupported opcode: "
10917 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx
" %d\n",
10918 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
10919 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
10924 if (unlikely(handler
->type
& (PPC_SPE
| PPC_SPE_SINGLE
| PPC_SPE_DOUBLE
) && Rc(ctx
.opcode
))) {
10925 inval
= handler
->inval2
;
10927 inval
= handler
->inval1
;
10930 if (unlikely((ctx
.opcode
& inval
) != 0)) {
10931 if (qemu_log_enabled()) {
10932 qemu_log("invalid bits: %08x for opcode: "
10933 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx
"\n",
10934 ctx
.opcode
& inval
, opc1(ctx
.opcode
),
10935 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
10936 ctx
.opcode
, ctx
.nip
- 4);
10938 gen_inval_exception(ctxp
, POWERPC_EXCP_INVAL_INVAL
);
10942 (*(handler
->handler
))(&ctx
);
10943 #if defined(DO_PPC_STATISTICS)
10946 /* Check trace mode exceptions */
10947 if (unlikely(ctx
.singlestep_enabled
& CPU_SINGLE_STEP
&&
10948 (ctx
.nip
<= 0x100 || ctx
.nip
> 0xF00) &&
10949 ctx
.exception
!= POWERPC_SYSCALL
&&
10950 ctx
.exception
!= POWERPC_EXCP_TRAP
&&
10951 ctx
.exception
!= POWERPC_EXCP_BRANCH
)) {
10952 gen_exception(ctxp
, POWERPC_EXCP_TRACE
);
10953 } else if (unlikely(((ctx
.nip
& (TARGET_PAGE_SIZE
- 1)) == 0) ||
10954 (cs
->singlestep_enabled
) ||
10956 num_insns
>= max_insns
)) {
10957 /* if we reach a page boundary or are single stepping, stop
10963 if (tb
->cflags
& CF_LAST_IO
)
10965 if (ctx
.exception
== POWERPC_EXCP_NONE
) {
10966 gen_goto_tb(&ctx
, 0, ctx
.nip
);
10967 } else if (ctx
.exception
!= POWERPC_EXCP_BRANCH
) {
10968 if (unlikely(cs
->singlestep_enabled
)) {
10969 gen_debug_exception(ctxp
);
10971 /* Generate the return instruction */
10972 tcg_gen_exit_tb(0);
10974 gen_tb_end(tb
, num_insns
);
10975 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
10976 if (unlikely(search_pc
)) {
10977 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
10980 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
10982 tb
->size
= ctx
.nip
- pc_start
;
10983 tb
->icount
= num_insns
;
10985 #if defined(DEBUG_DISAS)
10986 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
10988 flags
= env
->bfd_mach
;
10989 flags
|= ctx
.le_mode
<< 16;
10990 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
10991 log_target_disas(env
, pc_start
, ctx
.nip
- pc_start
, flags
);
10997 void gen_intermediate_code (CPUPPCState
*env
, struct TranslationBlock
*tb
)
10999 gen_intermediate_code_internal(ppc_env_get_cpu(env
), tb
, false);
11002 void gen_intermediate_code_pc (CPUPPCState
*env
, struct TranslationBlock
*tb
)
11004 gen_intermediate_code_internal(ppc_env_get_cpu(env
), tb
, true);
11007 void restore_state_to_opc(CPUPPCState
*env
, TranslationBlock
*tb
, int pc_pos
)
11009 env
->nip
= tcg_ctx
.gen_opc_pc
[pc_pos
];