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(ctiwu
, 0x0E, 0x04, 0, PPC2_FP_CVT_ISA206
);
2208 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
);
2210 GEN_FLOAT_B(ctiwuz
, 0x0F, 0x04, 0, PPC2_FP_CVT_ISA206
);
2212 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
);
2213 #if defined(TARGET_PPC64)
2215 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
);
2217 GEN_FLOAT_B(cfids
, 0x0E, 0x1A, 0, PPC2_FP_CVT_ISA206
);
2219 GEN_FLOAT_B(cfidu
, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206
);
2221 GEN_FLOAT_B(cfidus
, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206
);
2223 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
);
2225 GEN_FLOAT_B(ctidu
, 0x0E, 0x1D, 0, PPC2_FP_CVT_ISA206
);
2227 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
);
2229 GEN_FLOAT_B(ctiduz
, 0x0F, 0x1D, 0, PPC2_FP_CVT_ISA206
);
2233 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
);
2235 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
);
2237 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
);
2239 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
);
2241 static void gen_ftdiv(DisasContext
*ctx
)
2243 if (unlikely(!ctx
->fpu_enabled
)) {
2244 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2247 gen_helper_ftdiv(cpu_crf
[crfD(ctx
->opcode
)], cpu_fpr
[rA(ctx
->opcode
)],
2248 cpu_fpr
[rB(ctx
->opcode
)]);
2251 static void gen_ftsqrt(DisasContext
*ctx
)
2253 if (unlikely(!ctx
->fpu_enabled
)) {
2254 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2257 gen_helper_ftsqrt(cpu_crf
[crfD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2262 /*** Floating-Point compare ***/
2265 static void gen_fcmpo(DisasContext
*ctx
)
2268 if (unlikely(!ctx
->fpu_enabled
)) {
2269 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2272 /* NIP cannot be restored if the memory exception comes from an helper */
2273 gen_update_nip(ctx
, ctx
->nip
- 4);
2274 gen_reset_fpstatus();
2275 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2276 gen_helper_fcmpo(cpu_env
, cpu_fpr
[rA(ctx
->opcode
)],
2277 cpu_fpr
[rB(ctx
->opcode
)], crf
);
2278 tcg_temp_free_i32(crf
);
2279 gen_helper_float_check_status(cpu_env
);
2283 static void gen_fcmpu(DisasContext
*ctx
)
2286 if (unlikely(!ctx
->fpu_enabled
)) {
2287 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2290 /* NIP cannot be restored if the memory exception comes from an helper */
2291 gen_update_nip(ctx
, ctx
->nip
- 4);
2292 gen_reset_fpstatus();
2293 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2294 gen_helper_fcmpu(cpu_env
, cpu_fpr
[rA(ctx
->opcode
)],
2295 cpu_fpr
[rB(ctx
->opcode
)], crf
);
2296 tcg_temp_free_i32(crf
);
2297 gen_helper_float_check_status(cpu_env
);
2300 /*** Floating-point move ***/
2302 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2303 static void gen_fabs(DisasContext
*ctx
)
2305 if (unlikely(!ctx
->fpu_enabled
)) {
2306 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2309 tcg_gen_andi_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)],
2311 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2315 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2316 static void gen_fmr(DisasContext
*ctx
)
2318 if (unlikely(!ctx
->fpu_enabled
)) {
2319 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2322 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2323 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2327 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2328 static void gen_fnabs(DisasContext
*ctx
)
2330 if (unlikely(!ctx
->fpu_enabled
)) {
2331 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2334 tcg_gen_ori_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)],
2336 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2340 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2341 static void gen_fneg(DisasContext
*ctx
)
2343 if (unlikely(!ctx
->fpu_enabled
)) {
2344 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2347 tcg_gen_xori_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)],
2349 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2352 /* fcpsgn: PowerPC 2.05 specification */
2353 /* XXX: beware that fcpsgn never checks for NaNs nor update FPSCR */
2354 static void gen_fcpsgn(DisasContext
*ctx
)
2356 if (unlikely(!ctx
->fpu_enabled
)) {
2357 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2360 tcg_gen_deposit_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rA(ctx
->opcode
)],
2361 cpu_fpr
[rB(ctx
->opcode
)], 0, 63);
2362 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2365 static void gen_fmrgew(DisasContext
*ctx
)
2368 if (unlikely(!ctx
->fpu_enabled
)) {
2369 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2372 b0
= tcg_temp_new_i64();
2373 tcg_gen_shri_i64(b0
, cpu_fpr
[rB(ctx
->opcode
)], 32);
2374 tcg_gen_deposit_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rA(ctx
->opcode
)],
2376 tcg_temp_free_i64(b0
);
2379 static void gen_fmrgow(DisasContext
*ctx
)
2381 if (unlikely(!ctx
->fpu_enabled
)) {
2382 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2385 tcg_gen_deposit_i64(cpu_fpr
[rD(ctx
->opcode
)],
2386 cpu_fpr
[rB(ctx
->opcode
)],
2387 cpu_fpr
[rA(ctx
->opcode
)],
2391 /*** Floating-Point status & ctrl register ***/
2394 static void gen_mcrfs(DisasContext
*ctx
)
2396 TCGv tmp
= tcg_temp_new();
2399 if (unlikely(!ctx
->fpu_enabled
)) {
2400 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2403 bfa
= 4 * (7 - crfS(ctx
->opcode
));
2404 tcg_gen_shri_tl(tmp
, cpu_fpscr
, bfa
);
2405 tcg_gen_trunc_tl_i32(cpu_crf
[crfD(ctx
->opcode
)], tmp
);
2407 tcg_gen_andi_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfD(ctx
->opcode
)], 0xf);
2408 tcg_gen_andi_tl(cpu_fpscr
, cpu_fpscr
, ~(0xF << bfa
));
2412 static void gen_mffs(DisasContext
*ctx
)
2414 if (unlikely(!ctx
->fpu_enabled
)) {
2415 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2418 gen_reset_fpstatus();
2419 tcg_gen_extu_tl_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpscr
);
2420 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2424 static void gen_mtfsb0(DisasContext
*ctx
)
2428 if (unlikely(!ctx
->fpu_enabled
)) {
2429 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2432 crb
= 31 - crbD(ctx
->opcode
);
2433 gen_reset_fpstatus();
2434 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
)) {
2436 /* NIP cannot be restored if the memory exception comes from an helper */
2437 gen_update_nip(ctx
, ctx
->nip
- 4);
2438 t0
= tcg_const_i32(crb
);
2439 gen_helper_fpscr_clrbit(cpu_env
, t0
);
2440 tcg_temp_free_i32(t0
);
2442 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2443 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2444 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2449 static void gen_mtfsb1(DisasContext
*ctx
)
2453 if (unlikely(!ctx
->fpu_enabled
)) {
2454 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2457 crb
= 31 - crbD(ctx
->opcode
);
2458 gen_reset_fpstatus();
2459 /* XXX: we pretend we can only do IEEE floating-point computations */
2460 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
&& crb
!= FPSCR_NI
)) {
2462 /* NIP cannot be restored if the memory exception comes from an helper */
2463 gen_update_nip(ctx
, ctx
->nip
- 4);
2464 t0
= tcg_const_i32(crb
);
2465 gen_helper_fpscr_setbit(cpu_env
, t0
);
2466 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_mtfsf(DisasContext
*ctx
)
2482 if (unlikely(!ctx
->fpu_enabled
)) {
2483 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2486 flm
= FPFLM(ctx
->opcode
);
2487 l
= FPL(ctx
->opcode
);
2488 w
= FPW(ctx
->opcode
);
2489 if (unlikely(w
& !(ctx
->insns_flags2
& PPC2_ISA205
))) {
2490 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2493 /* NIP cannot be restored if the memory exception comes from an helper */
2494 gen_update_nip(ctx
, ctx
->nip
- 4);
2495 gen_reset_fpstatus();
2497 t0
= tcg_const_i32((ctx
->insns_flags2
& PPC2_ISA205
) ? 0xffff : 0xff);
2499 t0
= tcg_const_i32(flm
<< (w
* 8));
2501 gen_helper_store_fpscr(cpu_env
, cpu_fpr
[rB(ctx
->opcode
)], t0
);
2502 tcg_temp_free_i32(t0
);
2503 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2504 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2505 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2507 /* We can raise a differed exception */
2508 gen_helper_float_check_status(cpu_env
);
2512 static void gen_mtfsfi(DisasContext
*ctx
)
2518 if (unlikely(!ctx
->fpu_enabled
)) {
2519 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2522 w
= FPW(ctx
->opcode
);
2523 bf
= FPBF(ctx
->opcode
);
2524 if (unlikely(w
& !(ctx
->insns_flags2
& PPC2_ISA205
))) {
2525 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2528 sh
= (8 * w
) + 7 - bf
;
2529 /* NIP cannot be restored if the memory exception comes from an helper */
2530 gen_update_nip(ctx
, ctx
->nip
- 4);
2531 gen_reset_fpstatus();
2532 t0
= tcg_const_i64(((uint64_t)FPIMM(ctx
->opcode
)) << (4 * sh
));
2533 t1
= tcg_const_i32(1 << sh
);
2534 gen_helper_store_fpscr(cpu_env
, t0
, t1
);
2535 tcg_temp_free_i64(t0
);
2536 tcg_temp_free_i32(t1
);
2537 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2538 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2539 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2541 /* We can raise a differed exception */
2542 gen_helper_float_check_status(cpu_env
);
2545 /*** Addressing modes ***/
2546 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2547 static inline void gen_addr_imm_index(DisasContext
*ctx
, TCGv EA
,
2550 target_long simm
= SIMM(ctx
->opcode
);
2553 if (rA(ctx
->opcode
) == 0) {
2554 if (NARROW_MODE(ctx
)) {
2555 simm
= (uint32_t)simm
;
2557 tcg_gen_movi_tl(EA
, simm
);
2558 } else if (likely(simm
!= 0)) {
2559 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
);
2560 if (NARROW_MODE(ctx
)) {
2561 tcg_gen_ext32u_tl(EA
, EA
);
2564 if (NARROW_MODE(ctx
)) {
2565 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2567 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2572 static inline void gen_addr_reg_index(DisasContext
*ctx
, TCGv EA
)
2574 if (rA(ctx
->opcode
) == 0) {
2575 if (NARROW_MODE(ctx
)) {
2576 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2578 tcg_gen_mov_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2581 tcg_gen_add_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2582 if (NARROW_MODE(ctx
)) {
2583 tcg_gen_ext32u_tl(EA
, EA
);
2588 static inline void gen_addr_register(DisasContext
*ctx
, TCGv EA
)
2590 if (rA(ctx
->opcode
) == 0) {
2591 tcg_gen_movi_tl(EA
, 0);
2592 } else if (NARROW_MODE(ctx
)) {
2593 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2595 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2599 static inline void gen_addr_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
2602 tcg_gen_addi_tl(ret
, arg1
, val
);
2603 if (NARROW_MODE(ctx
)) {
2604 tcg_gen_ext32u_tl(ret
, ret
);
2608 static inline void gen_check_align(DisasContext
*ctx
, TCGv EA
, int mask
)
2610 int l1
= gen_new_label();
2611 TCGv t0
= tcg_temp_new();
2613 /* NIP cannot be restored if the memory exception comes from an helper */
2614 gen_update_nip(ctx
, ctx
->nip
- 4);
2615 tcg_gen_andi_tl(t0
, EA
, mask
);
2616 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2617 t1
= tcg_const_i32(POWERPC_EXCP_ALIGN
);
2618 t2
= tcg_const_i32(0);
2619 gen_helper_raise_exception_err(cpu_env
, t1
, t2
);
2620 tcg_temp_free_i32(t1
);
2621 tcg_temp_free_i32(t2
);
2626 /*** Integer load ***/
2627 static inline void gen_qemu_ld8u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2629 tcg_gen_qemu_ld8u(arg1
, arg2
, ctx
->mem_idx
);
2632 static inline void gen_qemu_ld8s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2634 tcg_gen_qemu_ld8s(arg1
, arg2
, ctx
->mem_idx
);
2637 static inline void gen_qemu_ld16u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2639 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2640 if (unlikely(ctx
->le_mode
)) {
2641 tcg_gen_bswap16_tl(arg1
, arg1
);
2645 static inline void gen_qemu_ld16s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2647 if (unlikely(ctx
->le_mode
)) {
2648 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2649 tcg_gen_bswap16_tl(arg1
, arg1
);
2650 tcg_gen_ext16s_tl(arg1
, arg1
);
2652 tcg_gen_qemu_ld16s(arg1
, arg2
, ctx
->mem_idx
);
2656 static inline void gen_qemu_ld32u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2658 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2659 if (unlikely(ctx
->le_mode
)) {
2660 tcg_gen_bswap32_tl(arg1
, arg1
);
2664 static void gen_qemu_ld32u_i64(DisasContext
*ctx
, TCGv_i64 val
, TCGv addr
)
2666 TCGv tmp
= tcg_temp_new();
2667 gen_qemu_ld32u(ctx
, tmp
, addr
);
2668 tcg_gen_extu_tl_i64(val
, tmp
);
2672 static inline void gen_qemu_ld32s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2674 if (unlikely(ctx
->le_mode
)) {
2675 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2676 tcg_gen_bswap32_tl(arg1
, arg1
);
2677 tcg_gen_ext32s_tl(arg1
, arg1
);
2679 tcg_gen_qemu_ld32s(arg1
, arg2
, ctx
->mem_idx
);
2682 static void gen_qemu_ld32s_i64(DisasContext
*ctx
, TCGv_i64 val
, TCGv addr
)
2684 TCGv tmp
= tcg_temp_new();
2685 gen_qemu_ld32s(ctx
, tmp
, addr
);
2686 tcg_gen_ext_tl_i64(val
, tmp
);
2690 static inline void gen_qemu_ld64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2692 tcg_gen_qemu_ld64(arg1
, arg2
, ctx
->mem_idx
);
2693 if (unlikely(ctx
->le_mode
)) {
2694 tcg_gen_bswap64_i64(arg1
, arg1
);
2698 static inline void gen_qemu_st8(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2700 tcg_gen_qemu_st8(arg1
, arg2
, ctx
->mem_idx
);
2703 static inline void gen_qemu_st16(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2705 if (unlikely(ctx
->le_mode
)) {
2706 TCGv t0
= tcg_temp_new();
2707 tcg_gen_ext16u_tl(t0
, arg1
);
2708 tcg_gen_bswap16_tl(t0
, t0
);
2709 tcg_gen_qemu_st16(t0
, arg2
, ctx
->mem_idx
);
2712 tcg_gen_qemu_st16(arg1
, arg2
, ctx
->mem_idx
);
2716 static inline void gen_qemu_st32(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2718 if (unlikely(ctx
->le_mode
)) {
2719 TCGv t0
= tcg_temp_new();
2720 tcg_gen_ext32u_tl(t0
, arg1
);
2721 tcg_gen_bswap32_tl(t0
, t0
);
2722 tcg_gen_qemu_st32(t0
, arg2
, ctx
->mem_idx
);
2725 tcg_gen_qemu_st32(arg1
, arg2
, ctx
->mem_idx
);
2729 static void gen_qemu_st32_i64(DisasContext
*ctx
, TCGv_i64 val
, TCGv addr
)
2731 TCGv tmp
= tcg_temp_new();
2732 tcg_gen_trunc_i64_tl(tmp
, val
);
2733 gen_qemu_st32(ctx
, tmp
, addr
);
2737 static inline void gen_qemu_st64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2739 if (unlikely(ctx
->le_mode
)) {
2740 TCGv_i64 t0
= tcg_temp_new_i64();
2741 tcg_gen_bswap64_i64(t0
, arg1
);
2742 tcg_gen_qemu_st64(t0
, arg2
, ctx
->mem_idx
);
2743 tcg_temp_free_i64(t0
);
2745 tcg_gen_qemu_st64(arg1
, arg2
, ctx
->mem_idx
);
2748 #define GEN_LD(name, ldop, opc, type) \
2749 static void glue(gen_, name)(DisasContext *ctx) \
2752 gen_set_access_type(ctx, ACCESS_INT); \
2753 EA = tcg_temp_new(); \
2754 gen_addr_imm_index(ctx, EA, 0); \
2755 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2756 tcg_temp_free(EA); \
2759 #define GEN_LDU(name, ldop, opc, type) \
2760 static void glue(gen_, name##u)(DisasContext *ctx) \
2763 if (unlikely(rA(ctx->opcode) == 0 || \
2764 rA(ctx->opcode) == rD(ctx->opcode))) { \
2765 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2768 gen_set_access_type(ctx, ACCESS_INT); \
2769 EA = tcg_temp_new(); \
2770 if (type == PPC_64B) \
2771 gen_addr_imm_index(ctx, EA, 0x03); \
2773 gen_addr_imm_index(ctx, EA, 0); \
2774 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2775 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2776 tcg_temp_free(EA); \
2779 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
2780 static void glue(gen_, name##ux)(DisasContext *ctx) \
2783 if (unlikely(rA(ctx->opcode) == 0 || \
2784 rA(ctx->opcode) == rD(ctx->opcode))) { \
2785 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2788 gen_set_access_type(ctx, ACCESS_INT); \
2789 EA = tcg_temp_new(); \
2790 gen_addr_reg_index(ctx, EA); \
2791 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2792 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2793 tcg_temp_free(EA); \
2796 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
2797 static void glue(gen_, name##x)(DisasContext *ctx) \
2800 gen_set_access_type(ctx, ACCESS_INT); \
2801 EA = tcg_temp_new(); \
2802 gen_addr_reg_index(ctx, EA); \
2803 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2804 tcg_temp_free(EA); \
2806 #define GEN_LDX(name, ldop, opc2, opc3, type) \
2807 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE)
2809 #define GEN_LDS(name, ldop, op, type) \
2810 GEN_LD(name, ldop, op | 0x20, type); \
2811 GEN_LDU(name, ldop, op | 0x21, type); \
2812 GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2813 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
2815 /* lbz lbzu lbzux lbzx */
2816 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
);
2817 /* lha lhau lhaux lhax */
2818 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
);
2819 /* lhz lhzu lhzux lhzx */
2820 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
);
2821 /* lwz lwzu lwzux lwzx */
2822 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
);
2823 #if defined(TARGET_PPC64)
2825 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
);
2827 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
);
2829 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
);
2831 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
);
2833 static void gen_ld(DisasContext
*ctx
)
2836 if (Rc(ctx
->opcode
)) {
2837 if (unlikely(rA(ctx
->opcode
) == 0 ||
2838 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
2839 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2843 gen_set_access_type(ctx
, ACCESS_INT
);
2844 EA
= tcg_temp_new();
2845 gen_addr_imm_index(ctx
, EA
, 0x03);
2846 if (ctx
->opcode
& 0x02) {
2847 /* lwa (lwau is undefined) */
2848 gen_qemu_ld32s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2851 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2853 if (Rc(ctx
->opcode
))
2854 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2859 static void gen_lq(DisasContext
*ctx
)
2861 #if defined(CONFIG_USER_ONLY)
2862 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2867 /* Restore CPU state */
2868 if (unlikely(ctx
->mem_idx
== 0)) {
2869 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2872 ra
= rA(ctx
->opcode
);
2873 rd
= rD(ctx
->opcode
);
2874 if (unlikely((rd
& 1) || rd
== ra
)) {
2875 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2878 if (unlikely(ctx
->le_mode
)) {
2879 /* Little-endian mode is not handled */
2880 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2883 gen_set_access_type(ctx
, ACCESS_INT
);
2884 EA
= tcg_temp_new();
2885 gen_addr_imm_index(ctx
, EA
, 0x0F);
2886 gen_qemu_ld64(ctx
, cpu_gpr
[rd
], EA
);
2887 gen_addr_add(ctx
, EA
, EA
, 8);
2888 gen_qemu_ld64(ctx
, cpu_gpr
[rd
+1], EA
);
2894 /*** Integer store ***/
2895 #define GEN_ST(name, stop, opc, type) \
2896 static void glue(gen_, name)(DisasContext *ctx) \
2899 gen_set_access_type(ctx, ACCESS_INT); \
2900 EA = tcg_temp_new(); \
2901 gen_addr_imm_index(ctx, EA, 0); \
2902 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2903 tcg_temp_free(EA); \
2906 #define GEN_STU(name, stop, opc, type) \
2907 static void glue(gen_, stop##u)(DisasContext *ctx) \
2910 if (unlikely(rA(ctx->opcode) == 0)) { \
2911 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2914 gen_set_access_type(ctx, ACCESS_INT); \
2915 EA = tcg_temp_new(); \
2916 if (type == PPC_64B) \
2917 gen_addr_imm_index(ctx, EA, 0x03); \
2919 gen_addr_imm_index(ctx, EA, 0); \
2920 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2921 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2922 tcg_temp_free(EA); \
2925 #define GEN_STUX(name, stop, opc2, opc3, type) \
2926 static void glue(gen_, name##ux)(DisasContext *ctx) \
2929 if (unlikely(rA(ctx->opcode) == 0)) { \
2930 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2933 gen_set_access_type(ctx, ACCESS_INT); \
2934 EA = tcg_temp_new(); \
2935 gen_addr_reg_index(ctx, EA); \
2936 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2937 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2938 tcg_temp_free(EA); \
2941 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
2942 static void glue(gen_, name##x)(DisasContext *ctx) \
2945 gen_set_access_type(ctx, ACCESS_INT); \
2946 EA = tcg_temp_new(); \
2947 gen_addr_reg_index(ctx, EA); \
2948 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2949 tcg_temp_free(EA); \
2951 #define GEN_STX(name, stop, opc2, opc3, type) \
2952 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE)
2954 #define GEN_STS(name, stop, op, type) \
2955 GEN_ST(name, stop, op | 0x20, type); \
2956 GEN_STU(name, stop, op | 0x21, type); \
2957 GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2958 GEN_STX(name, stop, 0x17, op | 0x00, type)
2960 /* stb stbu stbux stbx */
2961 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
);
2962 /* sth sthu sthux sthx */
2963 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
);
2964 /* stw stwu stwux stwx */
2965 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
);
2966 #if defined(TARGET_PPC64)
2967 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
);
2968 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
);
2970 static void gen_std(DisasContext
*ctx
)
2975 rs
= rS(ctx
->opcode
);
2976 if ((ctx
->opcode
& 0x3) == 0x2) {
2977 #if defined(CONFIG_USER_ONLY)
2978 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2981 if (unlikely(ctx
->mem_idx
== 0)) {
2982 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2985 if (unlikely(rs
& 1)) {
2986 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2989 if (unlikely(ctx
->le_mode
)) {
2990 /* Little-endian mode is not handled */
2991 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2994 gen_set_access_type(ctx
, ACCESS_INT
);
2995 EA
= tcg_temp_new();
2996 gen_addr_imm_index(ctx
, EA
, 0x03);
2997 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
2998 gen_addr_add(ctx
, EA
, EA
, 8);
2999 gen_qemu_st64(ctx
, cpu_gpr
[rs
+1], EA
);
3004 if (Rc(ctx
->opcode
)) {
3005 if (unlikely(rA(ctx
->opcode
) == 0)) {
3006 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3010 gen_set_access_type(ctx
, ACCESS_INT
);
3011 EA
= tcg_temp_new();
3012 gen_addr_imm_index(ctx
, EA
, 0x03);
3013 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
3014 if (Rc(ctx
->opcode
))
3015 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
3020 /*** Integer load and store with byte reverse ***/
3022 static inline void gen_qemu_ld16ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3024 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
3025 if (likely(!ctx
->le_mode
)) {
3026 tcg_gen_bswap16_tl(arg1
, arg1
);
3029 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
);
3032 static inline void gen_qemu_ld32ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3034 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
3035 if (likely(!ctx
->le_mode
)) {
3036 tcg_gen_bswap32_tl(arg1
, arg1
);
3039 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
);
3041 #if defined(TARGET_PPC64)
3043 static inline void gen_qemu_ld64ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3045 tcg_gen_qemu_ld64(arg1
, arg2
, ctx
->mem_idx
);
3046 if (likely(!ctx
->le_mode
)) {
3047 tcg_gen_bswap64_tl(arg1
, arg1
);
3050 GEN_LDX_E(ldbr
, ld64ur
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
);
3051 #endif /* TARGET_PPC64 */
3054 static inline void gen_qemu_st16r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3056 if (likely(!ctx
->le_mode
)) {
3057 TCGv t0
= tcg_temp_new();
3058 tcg_gen_ext16u_tl(t0
, arg1
);
3059 tcg_gen_bswap16_tl(t0
, t0
);
3060 tcg_gen_qemu_st16(t0
, arg2
, ctx
->mem_idx
);
3063 tcg_gen_qemu_st16(arg1
, arg2
, ctx
->mem_idx
);
3066 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
);
3069 static inline void gen_qemu_st32r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3071 if (likely(!ctx
->le_mode
)) {
3072 TCGv t0
= tcg_temp_new();
3073 tcg_gen_ext32u_tl(t0
, arg1
);
3074 tcg_gen_bswap32_tl(t0
, t0
);
3075 tcg_gen_qemu_st32(t0
, arg2
, ctx
->mem_idx
);
3078 tcg_gen_qemu_st32(arg1
, arg2
, ctx
->mem_idx
);
3081 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
);
3083 #if defined(TARGET_PPC64)
3085 static inline void gen_qemu_st64r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3087 if (likely(!ctx
->le_mode
)) {
3088 TCGv t0
= tcg_temp_new();
3089 tcg_gen_bswap64_tl(t0
, arg1
);
3090 tcg_gen_qemu_st64(t0
, arg2
, ctx
->mem_idx
);
3093 tcg_gen_qemu_st64(arg1
, arg2
, ctx
->mem_idx
);
3096 GEN_STX_E(stdbr
, st64r
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
);
3097 #endif /* TARGET_PPC64 */
3099 /*** Integer load and store multiple ***/
3102 static void gen_lmw(DisasContext
*ctx
)
3106 gen_set_access_type(ctx
, ACCESS_INT
);
3107 /* NIP cannot be restored if the memory exception comes from an helper */
3108 gen_update_nip(ctx
, ctx
->nip
- 4);
3109 t0
= tcg_temp_new();
3110 t1
= tcg_const_i32(rD(ctx
->opcode
));
3111 gen_addr_imm_index(ctx
, t0
, 0);
3112 gen_helper_lmw(cpu_env
, t0
, t1
);
3114 tcg_temp_free_i32(t1
);
3118 static void gen_stmw(DisasContext
*ctx
)
3122 gen_set_access_type(ctx
, ACCESS_INT
);
3123 /* NIP cannot be restored if the memory exception comes from an helper */
3124 gen_update_nip(ctx
, ctx
->nip
- 4);
3125 t0
= tcg_temp_new();
3126 t1
= tcg_const_i32(rS(ctx
->opcode
));
3127 gen_addr_imm_index(ctx
, t0
, 0);
3128 gen_helper_stmw(cpu_env
, t0
, t1
);
3130 tcg_temp_free_i32(t1
);
3133 /*** Integer load and store strings ***/
3136 /* PowerPC32 specification says we must generate an exception if
3137 * rA is in the range of registers to be loaded.
3138 * In an other hand, IBM says this is valid, but rA won't be loaded.
3139 * For now, I'll follow the spec...
3141 static void gen_lswi(DisasContext
*ctx
)
3145 int nb
= NB(ctx
->opcode
);
3146 int start
= rD(ctx
->opcode
);
3147 int ra
= rA(ctx
->opcode
);
3153 if (unlikely(((start
+ nr
) > 32 &&
3154 start
<= ra
&& (start
+ nr
- 32) > ra
) ||
3155 ((start
+ nr
) <= 32 && start
<= ra
&& (start
+ nr
) > ra
))) {
3156 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
3159 gen_set_access_type(ctx
, ACCESS_INT
);
3160 /* NIP cannot be restored if the memory exception comes from an helper */
3161 gen_update_nip(ctx
, ctx
->nip
- 4);
3162 t0
= tcg_temp_new();
3163 gen_addr_register(ctx
, t0
);
3164 t1
= tcg_const_i32(nb
);
3165 t2
= tcg_const_i32(start
);
3166 gen_helper_lsw(cpu_env
, t0
, t1
, t2
);
3168 tcg_temp_free_i32(t1
);
3169 tcg_temp_free_i32(t2
);
3173 static void gen_lswx(DisasContext
*ctx
)
3176 TCGv_i32 t1
, t2
, t3
;
3177 gen_set_access_type(ctx
, ACCESS_INT
);
3178 /* NIP cannot be restored if the memory exception comes from an helper */
3179 gen_update_nip(ctx
, ctx
->nip
- 4);
3180 t0
= tcg_temp_new();
3181 gen_addr_reg_index(ctx
, t0
);
3182 t1
= tcg_const_i32(rD(ctx
->opcode
));
3183 t2
= tcg_const_i32(rA(ctx
->opcode
));
3184 t3
= tcg_const_i32(rB(ctx
->opcode
));
3185 gen_helper_lswx(cpu_env
, t0
, t1
, t2
, t3
);
3187 tcg_temp_free_i32(t1
);
3188 tcg_temp_free_i32(t2
);
3189 tcg_temp_free_i32(t3
);
3193 static void gen_stswi(DisasContext
*ctx
)
3197 int nb
= NB(ctx
->opcode
);
3198 gen_set_access_type(ctx
, ACCESS_INT
);
3199 /* NIP cannot be restored if the memory exception comes from an helper */
3200 gen_update_nip(ctx
, ctx
->nip
- 4);
3201 t0
= tcg_temp_new();
3202 gen_addr_register(ctx
, t0
);
3205 t1
= tcg_const_i32(nb
);
3206 t2
= tcg_const_i32(rS(ctx
->opcode
));
3207 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3209 tcg_temp_free_i32(t1
);
3210 tcg_temp_free_i32(t2
);
3214 static void gen_stswx(DisasContext
*ctx
)
3218 gen_set_access_type(ctx
, ACCESS_INT
);
3219 /* NIP cannot be restored if the memory exception comes from an helper */
3220 gen_update_nip(ctx
, ctx
->nip
- 4);
3221 t0
= tcg_temp_new();
3222 gen_addr_reg_index(ctx
, t0
);
3223 t1
= tcg_temp_new_i32();
3224 tcg_gen_trunc_tl_i32(t1
, cpu_xer
);
3225 tcg_gen_andi_i32(t1
, t1
, 0x7F);
3226 t2
= tcg_const_i32(rS(ctx
->opcode
));
3227 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3229 tcg_temp_free_i32(t1
);
3230 tcg_temp_free_i32(t2
);
3233 /*** Memory synchronisation ***/
3235 static void gen_eieio(DisasContext
*ctx
)
3240 static void gen_isync(DisasContext
*ctx
)
3242 gen_stop_exception(ctx
);
3245 #define LARX(name, len, loadop) \
3246 static void gen_##name(DisasContext *ctx) \
3249 TCGv gpr = cpu_gpr[rD(ctx->opcode)]; \
3250 gen_set_access_type(ctx, ACCESS_RES); \
3251 t0 = tcg_temp_local_new(); \
3252 gen_addr_reg_index(ctx, t0); \
3254 gen_check_align(ctx, t0, (len)-1); \
3256 gen_qemu_##loadop(ctx, gpr, t0); \
3257 tcg_gen_mov_tl(cpu_reserve, t0); \
3258 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); \
3259 tcg_temp_free(t0); \
3263 LARX(lbarx
, 1, ld8u
);
3264 LARX(lharx
, 2, ld16u
);
3265 LARX(lwarx
, 4, ld32u
);
3268 #if defined(CONFIG_USER_ONLY)
3269 static void gen_conditional_store(DisasContext
*ctx
, TCGv EA
,
3272 TCGv t0
= tcg_temp_new();
3273 uint32_t save_exception
= ctx
->exception
;
3275 tcg_gen_st_tl(EA
, cpu_env
, offsetof(CPUPPCState
, reserve_ea
));
3276 tcg_gen_movi_tl(t0
, (size
<< 5) | reg
);
3277 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, reserve_info
));
3279 gen_update_nip(ctx
, ctx
->nip
-4);
3280 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3281 gen_exception(ctx
, POWERPC_EXCP_STCX
);
3282 ctx
->exception
= save_exception
;
3285 static void gen_conditional_store(DisasContext
*ctx
, TCGv EA
,
3290 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
3291 l1
= gen_new_label();
3292 tcg_gen_brcond_tl(TCG_COND_NE
, EA
, cpu_reserve
, l1
);
3293 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3294 #if defined(TARGET_PPC64)
3296 gen_qemu_st64(ctx
, cpu_gpr
[reg
], EA
);
3300 gen_qemu_st32(ctx
, cpu_gpr
[reg
], EA
);
3301 } else if (size
== 2) {
3302 gen_qemu_st16(ctx
, cpu_gpr
[reg
], EA
);
3304 gen_qemu_st8(ctx
, cpu_gpr
[reg
], EA
);
3307 tcg_gen_movi_tl(cpu_reserve
, -1);
3311 #define STCX(name, len) \
3312 static void gen_##name(DisasContext *ctx) \
3315 gen_set_access_type(ctx, ACCESS_RES); \
3316 t0 = tcg_temp_local_new(); \
3317 gen_addr_reg_index(ctx, t0); \
3319 gen_check_align(ctx, t0, (len)-1); \
3321 gen_conditional_store(ctx, t0, rS(ctx->opcode), len); \
3322 tcg_temp_free(t0); \
3329 #if defined(TARGET_PPC64)
3331 LARX(ldarx
, 8, ld64
);
3335 #endif /* defined(TARGET_PPC64) */
3338 static void gen_sync(DisasContext
*ctx
)
3343 static void gen_wait(DisasContext
*ctx
)
3345 TCGv_i32 t0
= tcg_temp_new_i32();
3346 tcg_gen_st_i32(t0
, cpu_env
,
3347 -offsetof(PowerPCCPU
, env
) + offsetof(CPUState
, halted
));
3348 tcg_temp_free_i32(t0
);
3349 /* Stop translation, as the CPU is supposed to sleep from now */
3350 gen_exception_err(ctx
, EXCP_HLT
, 1);
3353 /*** Floating-point load ***/
3354 #define GEN_LDF(name, ldop, opc, type) \
3355 static void glue(gen_, name)(DisasContext *ctx) \
3358 if (unlikely(!ctx->fpu_enabled)) { \
3359 gen_exception(ctx, POWERPC_EXCP_FPU); \
3362 gen_set_access_type(ctx, ACCESS_FLOAT); \
3363 EA = tcg_temp_new(); \
3364 gen_addr_imm_index(ctx, EA, 0); \
3365 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3366 tcg_temp_free(EA); \
3369 #define GEN_LDUF(name, ldop, opc, type) \
3370 static void glue(gen_, name##u)(DisasContext *ctx) \
3373 if (unlikely(!ctx->fpu_enabled)) { \
3374 gen_exception(ctx, POWERPC_EXCP_FPU); \
3377 if (unlikely(rA(ctx->opcode) == 0)) { \
3378 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3381 gen_set_access_type(ctx, ACCESS_FLOAT); \
3382 EA = tcg_temp_new(); \
3383 gen_addr_imm_index(ctx, EA, 0); \
3384 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3385 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3386 tcg_temp_free(EA); \
3389 #define GEN_LDUXF(name, ldop, opc, type) \
3390 static void glue(gen_, name##ux)(DisasContext *ctx) \
3393 if (unlikely(!ctx->fpu_enabled)) { \
3394 gen_exception(ctx, POWERPC_EXCP_FPU); \
3397 if (unlikely(rA(ctx->opcode) == 0)) { \
3398 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3401 gen_set_access_type(ctx, ACCESS_FLOAT); \
3402 EA = tcg_temp_new(); \
3403 gen_addr_reg_index(ctx, EA); \
3404 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3405 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3406 tcg_temp_free(EA); \
3409 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
3410 static void glue(gen_, name##x)(DisasContext *ctx) \
3413 if (unlikely(!ctx->fpu_enabled)) { \
3414 gen_exception(ctx, POWERPC_EXCP_FPU); \
3417 gen_set_access_type(ctx, ACCESS_FLOAT); \
3418 EA = tcg_temp_new(); \
3419 gen_addr_reg_index(ctx, EA); \
3420 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3421 tcg_temp_free(EA); \
3424 #define GEN_LDFS(name, ldop, op, type) \
3425 GEN_LDF(name, ldop, op | 0x20, type); \
3426 GEN_LDUF(name, ldop, op | 0x21, type); \
3427 GEN_LDUXF(name, ldop, op | 0x01, type); \
3428 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3430 static inline void gen_qemu_ld32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3432 TCGv t0
= tcg_temp_new();
3433 TCGv_i32 t1
= tcg_temp_new_i32();
3434 gen_qemu_ld32u(ctx
, t0
, arg2
);
3435 tcg_gen_trunc_tl_i32(t1
, t0
);
3437 gen_helper_float32_to_float64(arg1
, cpu_env
, t1
);
3438 tcg_temp_free_i32(t1
);
3441 /* lfd lfdu lfdux lfdx */
3442 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
);
3443 /* lfs lfsu lfsux lfsx */
3444 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
);
3447 static void gen_lfdp(DisasContext
*ctx
)
3450 if (unlikely(!ctx
->fpu_enabled
)) {
3451 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3454 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3455 EA
= tcg_temp_new();
3456 gen_addr_imm_index(ctx
, EA
, 0); \
3457 if (unlikely(ctx
->le_mode
)) {
3458 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3459 tcg_gen_addi_tl(EA
, EA
, 8);
3460 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3462 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3463 tcg_gen_addi_tl(EA
, EA
, 8);
3464 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3470 static void gen_lfdpx(DisasContext
*ctx
)
3473 if (unlikely(!ctx
->fpu_enabled
)) {
3474 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3477 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3478 EA
= tcg_temp_new();
3479 gen_addr_reg_index(ctx
, EA
);
3480 if (unlikely(ctx
->le_mode
)) {
3481 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3482 tcg_gen_addi_tl(EA
, EA
, 8);
3483 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3485 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3486 tcg_gen_addi_tl(EA
, EA
, 8);
3487 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3493 static void gen_lfiwax(DisasContext
*ctx
)
3497 if (unlikely(!ctx
->fpu_enabled
)) {
3498 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3501 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3502 EA
= tcg_temp_new();
3503 t0
= tcg_temp_new();
3504 gen_addr_reg_index(ctx
, EA
);
3505 gen_qemu_ld32s(ctx
, t0
, EA
);
3506 tcg_gen_ext_tl_i64(cpu_fpr
[rD(ctx
->opcode
)], t0
);
3512 static void gen_lfiwzx(DisasContext
*ctx
)
3515 if (unlikely(!ctx
->fpu_enabled
)) {
3516 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3519 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3520 EA
= tcg_temp_new();
3521 gen_addr_reg_index(ctx
, EA
);
3522 gen_qemu_ld32u_i64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3525 /*** Floating-point store ***/
3526 #define GEN_STF(name, stop, opc, type) \
3527 static void glue(gen_, name)(DisasContext *ctx) \
3530 if (unlikely(!ctx->fpu_enabled)) { \
3531 gen_exception(ctx, POWERPC_EXCP_FPU); \
3534 gen_set_access_type(ctx, ACCESS_FLOAT); \
3535 EA = tcg_temp_new(); \
3536 gen_addr_imm_index(ctx, EA, 0); \
3537 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3538 tcg_temp_free(EA); \
3541 #define GEN_STUF(name, stop, opc, type) \
3542 static void glue(gen_, name##u)(DisasContext *ctx) \
3545 if (unlikely(!ctx->fpu_enabled)) { \
3546 gen_exception(ctx, POWERPC_EXCP_FPU); \
3549 if (unlikely(rA(ctx->opcode) == 0)) { \
3550 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3553 gen_set_access_type(ctx, ACCESS_FLOAT); \
3554 EA = tcg_temp_new(); \
3555 gen_addr_imm_index(ctx, EA, 0); \
3556 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3557 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3558 tcg_temp_free(EA); \
3561 #define GEN_STUXF(name, stop, opc, type) \
3562 static void glue(gen_, name##ux)(DisasContext *ctx) \
3565 if (unlikely(!ctx->fpu_enabled)) { \
3566 gen_exception(ctx, POWERPC_EXCP_FPU); \
3569 if (unlikely(rA(ctx->opcode) == 0)) { \
3570 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3573 gen_set_access_type(ctx, ACCESS_FLOAT); \
3574 EA = tcg_temp_new(); \
3575 gen_addr_reg_index(ctx, EA); \
3576 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3577 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3578 tcg_temp_free(EA); \
3581 #define GEN_STXF(name, stop, opc2, opc3, type) \
3582 static void glue(gen_, name##x)(DisasContext *ctx) \
3585 if (unlikely(!ctx->fpu_enabled)) { \
3586 gen_exception(ctx, POWERPC_EXCP_FPU); \
3589 gen_set_access_type(ctx, ACCESS_FLOAT); \
3590 EA = tcg_temp_new(); \
3591 gen_addr_reg_index(ctx, EA); \
3592 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3593 tcg_temp_free(EA); \
3596 #define GEN_STFS(name, stop, op, type) \
3597 GEN_STF(name, stop, op | 0x20, type); \
3598 GEN_STUF(name, stop, op | 0x21, type); \
3599 GEN_STUXF(name, stop, op | 0x01, type); \
3600 GEN_STXF(name, stop, 0x17, op | 0x00, type)
3602 static inline void gen_qemu_st32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3604 TCGv_i32 t0
= tcg_temp_new_i32();
3605 TCGv t1
= tcg_temp_new();
3606 gen_helper_float64_to_float32(t0
, cpu_env
, arg1
);
3607 tcg_gen_extu_i32_tl(t1
, t0
);
3608 tcg_temp_free_i32(t0
);
3609 gen_qemu_st32(ctx
, t1
, arg2
);
3613 /* stfd stfdu stfdux stfdx */
3614 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
);
3615 /* stfs stfsu stfsux stfsx */
3616 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
);
3619 static void gen_stfdp(DisasContext
*ctx
)
3622 if (unlikely(!ctx
->fpu_enabled
)) {
3623 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3626 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3627 EA
= tcg_temp_new();
3628 gen_addr_imm_index(ctx
, EA
, 0); \
3629 if (unlikely(ctx
->le_mode
)) {
3630 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3631 tcg_gen_addi_tl(EA
, EA
, 8);
3632 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3634 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3635 tcg_gen_addi_tl(EA
, EA
, 8);
3636 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3642 static void gen_stfdpx(DisasContext
*ctx
)
3645 if (unlikely(!ctx
->fpu_enabled
)) {
3646 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3649 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3650 EA
= tcg_temp_new();
3651 gen_addr_reg_index(ctx
, EA
);
3652 if (unlikely(ctx
->le_mode
)) {
3653 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3654 tcg_gen_addi_tl(EA
, EA
, 8);
3655 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3657 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3658 tcg_gen_addi_tl(EA
, EA
, 8);
3659 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3665 static inline void gen_qemu_st32fiw(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3667 TCGv t0
= tcg_temp_new();
3668 tcg_gen_trunc_i64_tl(t0
, arg1
),
3669 gen_qemu_st32(ctx
, t0
, arg2
);
3673 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
);
3675 static inline void gen_update_cfar(DisasContext
*ctx
, target_ulong nip
)
3677 #if defined(TARGET_PPC64)
3679 tcg_gen_movi_tl(cpu_cfar
, nip
);
3684 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
3686 TranslationBlock
*tb
;
3688 if (NARROW_MODE(ctx
)) {
3689 dest
= (uint32_t) dest
;
3691 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
3692 likely(!ctx
->singlestep_enabled
)) {
3694 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3695 tcg_gen_exit_tb((uintptr_t)tb
+ n
);
3697 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3698 if (unlikely(ctx
->singlestep_enabled
)) {
3699 if ((ctx
->singlestep_enabled
&
3700 (CPU_BRANCH_STEP
| CPU_SINGLE_STEP
)) &&
3701 (ctx
->exception
== POWERPC_EXCP_BRANCH
||
3702 ctx
->exception
== POWERPC_EXCP_TRACE
)) {
3703 target_ulong tmp
= ctx
->nip
;
3705 gen_exception(ctx
, POWERPC_EXCP_TRACE
);
3708 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
3709 gen_debug_exception(ctx
);
3716 static inline void gen_setlr(DisasContext
*ctx
, target_ulong nip
)
3718 if (NARROW_MODE(ctx
)) {
3719 nip
= (uint32_t)nip
;
3721 tcg_gen_movi_tl(cpu_lr
, nip
);
3725 static void gen_b(DisasContext
*ctx
)
3727 target_ulong li
, target
;
3729 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3730 /* sign extend LI */
3731 li
= LI(ctx
->opcode
);
3732 li
= (li
^ 0x02000000) - 0x02000000;
3733 if (likely(AA(ctx
->opcode
) == 0)) {
3734 target
= ctx
->nip
+ li
- 4;
3738 if (LK(ctx
->opcode
)) {
3739 gen_setlr(ctx
, ctx
->nip
);
3741 gen_update_cfar(ctx
, ctx
->nip
);
3742 gen_goto_tb(ctx
, 0, target
);
3749 static inline void gen_bcond(DisasContext
*ctx
, int type
)
3751 uint32_t bo
= BO(ctx
->opcode
);
3755 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3756 if (type
== BCOND_LR
|| type
== BCOND_CTR
) {
3757 target
= tcg_temp_local_new();
3758 if (type
== BCOND_CTR
)
3759 tcg_gen_mov_tl(target
, cpu_ctr
);
3761 tcg_gen_mov_tl(target
, cpu_lr
);
3763 TCGV_UNUSED(target
);
3765 if (LK(ctx
->opcode
))
3766 gen_setlr(ctx
, ctx
->nip
);
3767 l1
= gen_new_label();
3768 if ((bo
& 0x4) == 0) {
3769 /* Decrement and test CTR */
3770 TCGv temp
= tcg_temp_new();
3771 if (unlikely(type
== BCOND_CTR
)) {
3772 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3775 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
3776 if (NARROW_MODE(ctx
)) {
3777 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
3779 tcg_gen_mov_tl(temp
, cpu_ctr
);
3782 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
3784 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
3786 tcg_temp_free(temp
);
3788 if ((bo
& 0x10) == 0) {
3790 uint32_t bi
= BI(ctx
->opcode
);
3791 uint32_t mask
= 1 << (3 - (bi
& 0x03));
3792 TCGv_i32 temp
= tcg_temp_new_i32();
3795 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3796 tcg_gen_brcondi_i32(TCG_COND_EQ
, temp
, 0, l1
);
3798 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3799 tcg_gen_brcondi_i32(TCG_COND_NE
, temp
, 0, l1
);
3801 tcg_temp_free_i32(temp
);
3803 gen_update_cfar(ctx
, ctx
->nip
);
3804 if (type
== BCOND_IM
) {
3805 target_ulong li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
3806 if (likely(AA(ctx
->opcode
) == 0)) {
3807 gen_goto_tb(ctx
, 0, ctx
->nip
+ li
- 4);
3809 gen_goto_tb(ctx
, 0, li
);
3812 gen_goto_tb(ctx
, 1, ctx
->nip
);
3814 if (NARROW_MODE(ctx
)) {
3815 tcg_gen_andi_tl(cpu_nip
, target
, (uint32_t)~3);
3817 tcg_gen_andi_tl(cpu_nip
, target
, ~3);
3821 gen_update_nip(ctx
, ctx
->nip
);
3826 static void gen_bc(DisasContext
*ctx
)
3828 gen_bcond(ctx
, BCOND_IM
);
3831 static void gen_bcctr(DisasContext
*ctx
)
3833 gen_bcond(ctx
, BCOND_CTR
);
3836 static void gen_bclr(DisasContext
*ctx
)
3838 gen_bcond(ctx
, BCOND_LR
);
3841 /*** Condition register logical ***/
3842 #define GEN_CRLOGIC(name, tcg_op, opc) \
3843 static void glue(gen_, name)(DisasContext *ctx) \
3848 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3849 t0 = tcg_temp_new_i32(); \
3851 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
3853 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
3855 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
3856 t1 = tcg_temp_new_i32(); \
3857 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3859 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
3861 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
3863 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3864 tcg_op(t0, t0, t1); \
3865 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
3866 tcg_gen_andi_i32(t0, t0, bitmask); \
3867 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3868 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
3869 tcg_temp_free_i32(t0); \
3870 tcg_temp_free_i32(t1); \
3874 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08);
3876 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04);
3878 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09);
3880 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07);
3882 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01);
3884 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E);
3886 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D);
3888 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06);
3891 static void gen_mcrf(DisasContext
*ctx
)
3893 tcg_gen_mov_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfS(ctx
->opcode
)]);
3896 /*** System linkage ***/
3898 /* rfi (mem_idx only) */
3899 static void gen_rfi(DisasContext
*ctx
)
3901 #if defined(CONFIG_USER_ONLY)
3902 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3904 /* Restore CPU state */
3905 if (unlikely(!ctx
->mem_idx
)) {
3906 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3909 gen_update_cfar(ctx
, ctx
->nip
);
3910 gen_helper_rfi(cpu_env
);
3911 gen_sync_exception(ctx
);
3915 #if defined(TARGET_PPC64)
3916 static void gen_rfid(DisasContext
*ctx
)
3918 #if defined(CONFIG_USER_ONLY)
3919 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3921 /* Restore CPU state */
3922 if (unlikely(!ctx
->mem_idx
)) {
3923 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3926 gen_update_cfar(ctx
, ctx
->nip
);
3927 gen_helper_rfid(cpu_env
);
3928 gen_sync_exception(ctx
);
3932 static void gen_hrfid(DisasContext
*ctx
)
3934 #if defined(CONFIG_USER_ONLY)
3935 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3937 /* Restore CPU state */
3938 if (unlikely(ctx
->mem_idx
<= 1)) {
3939 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3942 gen_helper_hrfid(cpu_env
);
3943 gen_sync_exception(ctx
);
3949 #if defined(CONFIG_USER_ONLY)
3950 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3952 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3954 static void gen_sc(DisasContext
*ctx
)
3958 lev
= (ctx
->opcode
>> 5) & 0x7F;
3959 gen_exception_err(ctx
, POWERPC_SYSCALL
, lev
);
3965 static void gen_tw(DisasContext
*ctx
)
3967 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3968 /* Update the nip since this might generate a trap exception */
3969 gen_update_nip(ctx
, ctx
->nip
);
3970 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
3972 tcg_temp_free_i32(t0
);
3976 static void gen_twi(DisasContext
*ctx
)
3978 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3979 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
3980 /* Update the nip since this might generate a trap exception */
3981 gen_update_nip(ctx
, ctx
->nip
);
3982 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3984 tcg_temp_free_i32(t1
);
3987 #if defined(TARGET_PPC64)
3989 static void gen_td(DisasContext
*ctx
)
3991 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3992 /* Update the nip since this might generate a trap exception */
3993 gen_update_nip(ctx
, ctx
->nip
);
3994 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
3996 tcg_temp_free_i32(t0
);
4000 static void gen_tdi(DisasContext
*ctx
)
4002 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
4003 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
4004 /* Update the nip since this might generate a trap exception */
4005 gen_update_nip(ctx
, ctx
->nip
);
4006 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4008 tcg_temp_free_i32(t1
);
4012 /*** Processor control ***/
4014 static void gen_read_xer(TCGv dst
)
4016 TCGv t0
= tcg_temp_new();
4017 TCGv t1
= tcg_temp_new();
4018 TCGv t2
= tcg_temp_new();
4019 tcg_gen_mov_tl(dst
, cpu_xer
);
4020 tcg_gen_shli_tl(t0
, cpu_so
, XER_SO
);
4021 tcg_gen_shli_tl(t1
, cpu_ov
, XER_OV
);
4022 tcg_gen_shli_tl(t2
, cpu_ca
, XER_CA
);
4023 tcg_gen_or_tl(t0
, t0
, t1
);
4024 tcg_gen_or_tl(dst
, dst
, t2
);
4025 tcg_gen_or_tl(dst
, dst
, t0
);
4031 static void gen_write_xer(TCGv src
)
4033 tcg_gen_andi_tl(cpu_xer
, src
,
4034 ~((1u << XER_SO
) | (1u << XER_OV
) | (1u << XER_CA
)));
4035 tcg_gen_shri_tl(cpu_so
, src
, XER_SO
);
4036 tcg_gen_shri_tl(cpu_ov
, src
, XER_OV
);
4037 tcg_gen_shri_tl(cpu_ca
, src
, XER_CA
);
4038 tcg_gen_andi_tl(cpu_so
, cpu_so
, 1);
4039 tcg_gen_andi_tl(cpu_ov
, cpu_ov
, 1);
4040 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
4044 static void gen_mcrxr(DisasContext
*ctx
)
4046 TCGv_i32 t0
= tcg_temp_new_i32();
4047 TCGv_i32 t1
= tcg_temp_new_i32();
4048 TCGv_i32 dst
= cpu_crf
[crfD(ctx
->opcode
)];
4050 tcg_gen_trunc_tl_i32(t0
, cpu_so
);
4051 tcg_gen_trunc_tl_i32(t1
, cpu_ov
);
4052 tcg_gen_trunc_tl_i32(dst
, cpu_ca
);
4053 tcg_gen_shri_i32(t0
, t0
, 2);
4054 tcg_gen_shri_i32(t1
, t1
, 1);
4055 tcg_gen_or_i32(dst
, dst
, t0
);
4056 tcg_gen_or_i32(dst
, dst
, t1
);
4057 tcg_temp_free_i32(t0
);
4058 tcg_temp_free_i32(t1
);
4060 tcg_gen_movi_tl(cpu_so
, 0);
4061 tcg_gen_movi_tl(cpu_ov
, 0);
4062 tcg_gen_movi_tl(cpu_ca
, 0);
4066 static void gen_mfcr(DisasContext
*ctx
)
4070 if (likely(ctx
->opcode
& 0x00100000)) {
4071 crm
= CRM(ctx
->opcode
);
4072 if (likely(crm
&& ((crm
& (crm
- 1)) == 0))) {
4074 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_crf
[7 - crn
]);
4075 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)],
4076 cpu_gpr
[rD(ctx
->opcode
)], crn
* 4);
4079 TCGv_i32 t0
= tcg_temp_new_i32();
4080 tcg_gen_mov_i32(t0
, cpu_crf
[0]);
4081 tcg_gen_shli_i32(t0
, t0
, 4);
4082 tcg_gen_or_i32(t0
, t0
, cpu_crf
[1]);
4083 tcg_gen_shli_i32(t0
, t0
, 4);
4084 tcg_gen_or_i32(t0
, t0
, cpu_crf
[2]);
4085 tcg_gen_shli_i32(t0
, t0
, 4);
4086 tcg_gen_or_i32(t0
, t0
, cpu_crf
[3]);
4087 tcg_gen_shli_i32(t0
, t0
, 4);
4088 tcg_gen_or_i32(t0
, t0
, cpu_crf
[4]);
4089 tcg_gen_shli_i32(t0
, t0
, 4);
4090 tcg_gen_or_i32(t0
, t0
, cpu_crf
[5]);
4091 tcg_gen_shli_i32(t0
, t0
, 4);
4092 tcg_gen_or_i32(t0
, t0
, cpu_crf
[6]);
4093 tcg_gen_shli_i32(t0
, t0
, 4);
4094 tcg_gen_or_i32(t0
, t0
, cpu_crf
[7]);
4095 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4096 tcg_temp_free_i32(t0
);
4101 static void gen_mfmsr(DisasContext
*ctx
)
4103 #if defined(CONFIG_USER_ONLY)
4104 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4106 if (unlikely(!ctx
->mem_idx
)) {
4107 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4110 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_msr
);
4114 static void spr_noaccess(void *opaque
, int gprn
, int sprn
)
4117 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
4118 printf("ERROR: try to access SPR %d !\n", sprn
);
4121 #define SPR_NOACCESS (&spr_noaccess)
4124 static inline void gen_op_mfspr(DisasContext
*ctx
)
4126 void (*read_cb
)(void *opaque
, int gprn
, int sprn
);
4127 uint32_t sprn
= SPR(ctx
->opcode
);
4129 #if !defined(CONFIG_USER_ONLY)
4130 if (ctx
->mem_idx
== 2)
4131 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
4132 else if (ctx
->mem_idx
)
4133 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
4136 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
4137 if (likely(read_cb
!= NULL
)) {
4138 if (likely(read_cb
!= SPR_NOACCESS
)) {
4139 (*read_cb
)(ctx
, rD(ctx
->opcode
), sprn
);
4141 /* Privilege exception */
4142 /* This is a hack to avoid warnings when running Linux:
4143 * this OS breaks the PowerPC virtualisation model,
4144 * allowing userland application to read the PVR
4146 if (sprn
!= SPR_PVR
) {
4147 qemu_log("Trying to read privileged spr %d (0x%03x) at "
4148 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4149 printf("Trying to read privileged spr %d (0x%03x) at "
4150 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4152 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4156 qemu_log("Trying to read invalid spr %d (0x%03x) at "
4157 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4158 printf("Trying to read invalid spr %d (0x%03x) at "
4159 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4160 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4164 static void gen_mfspr(DisasContext
*ctx
)
4170 static void gen_mftb(DisasContext
*ctx
)
4176 static void gen_mtcrf(DisasContext
*ctx
)
4180 crm
= CRM(ctx
->opcode
);
4181 if (likely((ctx
->opcode
& 0x00100000))) {
4182 if (crm
&& ((crm
& (crm
- 1)) == 0)) {
4183 TCGv_i32 temp
= tcg_temp_new_i32();
4185 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
4186 tcg_gen_shri_i32(temp
, temp
, crn
* 4);
4187 tcg_gen_andi_i32(cpu_crf
[7 - crn
], temp
, 0xf);
4188 tcg_temp_free_i32(temp
);
4191 TCGv_i32 temp
= tcg_temp_new_i32();
4192 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
4193 for (crn
= 0 ; crn
< 8 ; crn
++) {
4194 if (crm
& (1 << crn
)) {
4195 tcg_gen_shri_i32(cpu_crf
[7 - crn
], temp
, crn
* 4);
4196 tcg_gen_andi_i32(cpu_crf
[7 - crn
], cpu_crf
[7 - crn
], 0xf);
4199 tcg_temp_free_i32(temp
);
4204 #if defined(TARGET_PPC64)
4205 static void gen_mtmsrd(DisasContext
*ctx
)
4207 #if defined(CONFIG_USER_ONLY)
4208 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4210 if (unlikely(!ctx
->mem_idx
)) {
4211 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4214 if (ctx
->opcode
& 0x00010000) {
4215 /* Special form that does not need any synchronisation */
4216 TCGv t0
= tcg_temp_new();
4217 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
4218 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
4219 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
4222 /* XXX: we need to update nip before the store
4223 * if we enter power saving mode, we will exit the loop
4224 * directly from ppc_store_msr
4226 gen_update_nip(ctx
, ctx
->nip
);
4227 gen_helper_store_msr(cpu_env
, cpu_gpr
[rS(ctx
->opcode
)]);
4228 /* Must stop the translation as machine state (may have) changed */
4229 /* Note that mtmsr is not always defined as context-synchronizing */
4230 gen_stop_exception(ctx
);
4236 static void gen_mtmsr(DisasContext
*ctx
)
4238 #if defined(CONFIG_USER_ONLY)
4239 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4241 if (unlikely(!ctx
->mem_idx
)) {
4242 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4245 if (ctx
->opcode
& 0x00010000) {
4246 /* Special form that does not need any synchronisation */
4247 TCGv t0
= tcg_temp_new();
4248 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
4249 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
4250 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
4253 TCGv msr
= tcg_temp_new();
4255 /* XXX: we need to update nip before the store
4256 * if we enter power saving mode, we will exit the loop
4257 * directly from ppc_store_msr
4259 gen_update_nip(ctx
, ctx
->nip
);
4260 #if defined(TARGET_PPC64)
4261 tcg_gen_deposit_tl(msr
, cpu_msr
, cpu_gpr
[rS(ctx
->opcode
)], 0, 32);
4263 tcg_gen_mov_tl(msr
, cpu_gpr
[rS(ctx
->opcode
)]);
4265 gen_helper_store_msr(cpu_env
, msr
);
4266 /* Must stop the translation as machine state (may have) changed */
4267 /* Note that mtmsr is not always defined as context-synchronizing */
4268 gen_stop_exception(ctx
);
4274 static void gen_mtspr(DisasContext
*ctx
)
4276 void (*write_cb
)(void *opaque
, int sprn
, int gprn
);
4277 uint32_t sprn
= SPR(ctx
->opcode
);
4279 #if !defined(CONFIG_USER_ONLY)
4280 if (ctx
->mem_idx
== 2)
4281 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
4282 else if (ctx
->mem_idx
)
4283 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
4286 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
4287 if (likely(write_cb
!= NULL
)) {
4288 if (likely(write_cb
!= SPR_NOACCESS
)) {
4289 (*write_cb
)(ctx
, sprn
, rS(ctx
->opcode
));
4291 /* Privilege exception */
4292 qemu_log("Trying to write privileged spr %d (0x%03x) at "
4293 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4294 printf("Trying to write privileged spr %d (0x%03x) at "
4295 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4296 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4300 qemu_log("Trying to write invalid spr %d (0x%03x) at "
4301 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4302 printf("Trying to write invalid spr %d (0x%03x) at "
4303 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4304 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4308 /*** Cache management ***/
4311 static void gen_dcbf(DisasContext
*ctx
)
4313 /* XXX: specification says this is treated as a load by the MMU */
4315 gen_set_access_type(ctx
, ACCESS_CACHE
);
4316 t0
= tcg_temp_new();
4317 gen_addr_reg_index(ctx
, t0
);
4318 gen_qemu_ld8u(ctx
, t0
, t0
);
4322 /* dcbi (Supervisor only) */
4323 static void gen_dcbi(DisasContext
*ctx
)
4325 #if defined(CONFIG_USER_ONLY)
4326 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4329 if (unlikely(!ctx
->mem_idx
)) {
4330 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4333 EA
= tcg_temp_new();
4334 gen_set_access_type(ctx
, ACCESS_CACHE
);
4335 gen_addr_reg_index(ctx
, EA
);
4336 val
= tcg_temp_new();
4337 /* XXX: specification says this should be treated as a store by the MMU */
4338 gen_qemu_ld8u(ctx
, val
, EA
);
4339 gen_qemu_st8(ctx
, val
, EA
);
4346 static void gen_dcbst(DisasContext
*ctx
)
4348 /* XXX: specification say this is treated as a load by the MMU */
4350 gen_set_access_type(ctx
, ACCESS_CACHE
);
4351 t0
= tcg_temp_new();
4352 gen_addr_reg_index(ctx
, t0
);
4353 gen_qemu_ld8u(ctx
, t0
, t0
);
4358 static void gen_dcbt(DisasContext
*ctx
)
4360 /* interpreted as no-op */
4361 /* XXX: specification say this is treated as a load by the MMU
4362 * but does not generate any exception
4367 static void gen_dcbtst(DisasContext
*ctx
)
4369 /* interpreted as no-op */
4370 /* XXX: specification say this is treated as a load by the MMU
4371 * but does not generate any exception
4376 static void gen_dcbz(DisasContext
*ctx
)
4379 TCGv_i32 tcgv_is_dcbzl
;
4380 int is_dcbzl
= ctx
->opcode
& 0x00200000 ? 1 : 0;
4382 gen_set_access_type(ctx
, ACCESS_CACHE
);
4383 /* NIP cannot be restored if the memory exception comes from an helper */
4384 gen_update_nip(ctx
, ctx
->nip
- 4);
4385 tcgv_addr
= tcg_temp_new();
4386 tcgv_is_dcbzl
= tcg_const_i32(is_dcbzl
);
4388 gen_addr_reg_index(ctx
, tcgv_addr
);
4389 gen_helper_dcbz(cpu_env
, tcgv_addr
, tcgv_is_dcbzl
);
4391 tcg_temp_free(tcgv_addr
);
4392 tcg_temp_free_i32(tcgv_is_dcbzl
);
4396 static void gen_dst(DisasContext
*ctx
)
4398 if (rA(ctx
->opcode
) == 0) {
4399 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
4401 /* interpreted as no-op */
4406 static void gen_dstst(DisasContext
*ctx
)
4408 if (rA(ctx
->opcode
) == 0) {
4409 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
4411 /* interpreted as no-op */
4417 static void gen_dss(DisasContext
*ctx
)
4419 /* interpreted as no-op */
4423 static void gen_icbi(DisasContext
*ctx
)
4426 gen_set_access_type(ctx
, ACCESS_CACHE
);
4427 /* NIP cannot be restored if the memory exception comes from an helper */
4428 gen_update_nip(ctx
, ctx
->nip
- 4);
4429 t0
= tcg_temp_new();
4430 gen_addr_reg_index(ctx
, t0
);
4431 gen_helper_icbi(cpu_env
, t0
);
4437 static void gen_dcba(DisasContext
*ctx
)
4439 /* interpreted as no-op */
4440 /* XXX: specification say this is treated as a store by the MMU
4441 * but does not generate any exception
4445 /*** Segment register manipulation ***/
4446 /* Supervisor only: */
4449 static void gen_mfsr(DisasContext
*ctx
)
4451 #if defined(CONFIG_USER_ONLY)
4452 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4455 if (unlikely(!ctx
->mem_idx
)) {
4456 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4459 t0
= tcg_const_tl(SR(ctx
->opcode
));
4460 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4466 static void gen_mfsrin(DisasContext
*ctx
)
4468 #if defined(CONFIG_USER_ONLY)
4469 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4472 if (unlikely(!ctx
->mem_idx
)) {
4473 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4476 t0
= tcg_temp_new();
4477 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4478 tcg_gen_andi_tl(t0
, t0
, 0xF);
4479 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4485 static void gen_mtsr(DisasContext
*ctx
)
4487 #if defined(CONFIG_USER_ONLY)
4488 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4491 if (unlikely(!ctx
->mem_idx
)) {
4492 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4495 t0
= tcg_const_tl(SR(ctx
->opcode
));
4496 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4502 static void gen_mtsrin(DisasContext
*ctx
)
4504 #if defined(CONFIG_USER_ONLY)
4505 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4508 if (unlikely(!ctx
->mem_idx
)) {
4509 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4512 t0
= tcg_temp_new();
4513 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4514 tcg_gen_andi_tl(t0
, t0
, 0xF);
4515 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rD(ctx
->opcode
)]);
4520 #if defined(TARGET_PPC64)
4521 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4524 static void gen_mfsr_64b(DisasContext
*ctx
)
4526 #if defined(CONFIG_USER_ONLY)
4527 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4530 if (unlikely(!ctx
->mem_idx
)) {
4531 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4534 t0
= tcg_const_tl(SR(ctx
->opcode
));
4535 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4541 static void gen_mfsrin_64b(DisasContext
*ctx
)
4543 #if defined(CONFIG_USER_ONLY)
4544 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4547 if (unlikely(!ctx
->mem_idx
)) {
4548 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4551 t0
= tcg_temp_new();
4552 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4553 tcg_gen_andi_tl(t0
, t0
, 0xF);
4554 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4560 static void gen_mtsr_64b(DisasContext
*ctx
)
4562 #if defined(CONFIG_USER_ONLY)
4563 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4566 if (unlikely(!ctx
->mem_idx
)) {
4567 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4570 t0
= tcg_const_tl(SR(ctx
->opcode
));
4571 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4577 static void gen_mtsrin_64b(DisasContext
*ctx
)
4579 #if defined(CONFIG_USER_ONLY)
4580 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4583 if (unlikely(!ctx
->mem_idx
)) {
4584 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4587 t0
= tcg_temp_new();
4588 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4589 tcg_gen_andi_tl(t0
, t0
, 0xF);
4590 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4596 static void gen_slbmte(DisasContext
*ctx
)
4598 #if defined(CONFIG_USER_ONLY)
4599 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4601 if (unlikely(!ctx
->mem_idx
)) {
4602 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4605 gen_helper_store_slb(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)],
4606 cpu_gpr
[rS(ctx
->opcode
)]);
4610 static void gen_slbmfee(DisasContext
*ctx
)
4612 #if defined(CONFIG_USER_ONLY)
4613 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4615 if (unlikely(!ctx
->mem_idx
)) {
4616 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4619 gen_helper_load_slb_esid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4620 cpu_gpr
[rB(ctx
->opcode
)]);
4624 static void gen_slbmfev(DisasContext
*ctx
)
4626 #if defined(CONFIG_USER_ONLY)
4627 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4629 if (unlikely(!ctx
->mem_idx
)) {
4630 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4633 gen_helper_load_slb_vsid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4634 cpu_gpr
[rB(ctx
->opcode
)]);
4637 #endif /* defined(TARGET_PPC64) */
4639 /*** Lookaside buffer management ***/
4640 /* Optional & mem_idx only: */
4643 static void gen_tlbia(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 gen_helper_tlbia(cpu_env
);
4657 static void gen_tlbiel(DisasContext
*ctx
)
4659 #if defined(CONFIG_USER_ONLY)
4660 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4662 if (unlikely(!ctx
->mem_idx
)) {
4663 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4666 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4671 static void gen_tlbie(DisasContext
*ctx
)
4673 #if defined(CONFIG_USER_ONLY)
4674 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4676 if (unlikely(!ctx
->mem_idx
)) {
4677 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4680 if (NARROW_MODE(ctx
)) {
4681 TCGv t0
= tcg_temp_new();
4682 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
4683 gen_helper_tlbie(cpu_env
, t0
);
4686 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4692 static void gen_tlbsync(DisasContext
*ctx
)
4694 #if defined(CONFIG_USER_ONLY)
4695 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4697 if (unlikely(!ctx
->mem_idx
)) {
4698 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4701 /* This has no effect: it should ensure that all previous
4702 * tlbie have completed
4704 gen_stop_exception(ctx
);
4708 #if defined(TARGET_PPC64)
4710 static void gen_slbia(DisasContext
*ctx
)
4712 #if defined(CONFIG_USER_ONLY)
4713 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4715 if (unlikely(!ctx
->mem_idx
)) {
4716 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4719 gen_helper_slbia(cpu_env
);
4724 static void gen_slbie(DisasContext
*ctx
)
4726 #if defined(CONFIG_USER_ONLY)
4727 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4729 if (unlikely(!ctx
->mem_idx
)) {
4730 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4733 gen_helper_slbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4738 /*** External control ***/
4742 static void gen_eciwx(DisasContext
*ctx
)
4745 /* Should check EAR[E] ! */
4746 gen_set_access_type(ctx
, ACCESS_EXT
);
4747 t0
= tcg_temp_new();
4748 gen_addr_reg_index(ctx
, t0
);
4749 gen_check_align(ctx
, t0
, 0x03);
4750 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4755 static void gen_ecowx(DisasContext
*ctx
)
4758 /* Should check EAR[E] ! */
4759 gen_set_access_type(ctx
, ACCESS_EXT
);
4760 t0
= tcg_temp_new();
4761 gen_addr_reg_index(ctx
, t0
);
4762 gen_check_align(ctx
, t0
, 0x03);
4763 gen_qemu_st32(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4767 /* PowerPC 601 specific instructions */
4770 static void gen_abs(DisasContext
*ctx
)
4772 int l1
= gen_new_label();
4773 int l2
= gen_new_label();
4774 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4775 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4778 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4780 if (unlikely(Rc(ctx
->opcode
) != 0))
4781 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4785 static void gen_abso(DisasContext
*ctx
)
4787 int l1
= gen_new_label();
4788 int l2
= gen_new_label();
4789 int l3
= gen_new_label();
4790 /* Start with XER OV disabled, the most likely case */
4791 tcg_gen_movi_tl(cpu_ov
, 0);
4792 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l2
);
4793 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rA(ctx
->opcode
)], 0x80000000, l1
);
4794 tcg_gen_movi_tl(cpu_ov
, 1);
4795 tcg_gen_movi_tl(cpu_so
, 1);
4798 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4801 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4803 if (unlikely(Rc(ctx
->opcode
) != 0))
4804 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4808 static void gen_clcs(DisasContext
*ctx
)
4810 TCGv_i32 t0
= tcg_const_i32(rA(ctx
->opcode
));
4811 gen_helper_clcs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4812 tcg_temp_free_i32(t0
);
4813 /* Rc=1 sets CR0 to an undefined state */
4817 static void gen_div(DisasContext
*ctx
)
4819 gen_helper_div(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4820 cpu_gpr
[rB(ctx
->opcode
)]);
4821 if (unlikely(Rc(ctx
->opcode
) != 0))
4822 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4826 static void gen_divo(DisasContext
*ctx
)
4828 gen_helper_divo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4829 cpu_gpr
[rB(ctx
->opcode
)]);
4830 if (unlikely(Rc(ctx
->opcode
) != 0))
4831 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4835 static void gen_divs(DisasContext
*ctx
)
4837 gen_helper_divs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4838 cpu_gpr
[rB(ctx
->opcode
)]);
4839 if (unlikely(Rc(ctx
->opcode
) != 0))
4840 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4843 /* divso - divso. */
4844 static void gen_divso(DisasContext
*ctx
)
4846 gen_helper_divso(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
4847 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4848 if (unlikely(Rc(ctx
->opcode
) != 0))
4849 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4853 static void gen_doz(DisasContext
*ctx
)
4855 int l1
= gen_new_label();
4856 int l2
= gen_new_label();
4857 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4858 tcg_gen_sub_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4861 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4863 if (unlikely(Rc(ctx
->opcode
) != 0))
4864 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4868 static void gen_dozo(DisasContext
*ctx
)
4870 int l1
= gen_new_label();
4871 int l2
= gen_new_label();
4872 TCGv t0
= tcg_temp_new();
4873 TCGv t1
= tcg_temp_new();
4874 TCGv t2
= tcg_temp_new();
4875 /* Start with XER OV disabled, the most likely case */
4876 tcg_gen_movi_tl(cpu_ov
, 0);
4877 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4878 tcg_gen_sub_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4879 tcg_gen_xor_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4880 tcg_gen_xor_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], t0
);
4881 tcg_gen_andc_tl(t1
, t1
, t2
);
4882 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4883 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
4884 tcg_gen_movi_tl(cpu_ov
, 1);
4885 tcg_gen_movi_tl(cpu_so
, 1);
4888 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4893 if (unlikely(Rc(ctx
->opcode
) != 0))
4894 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4898 static void gen_dozi(DisasContext
*ctx
)
4900 target_long simm
= SIMM(ctx
->opcode
);
4901 int l1
= gen_new_label();
4902 int l2
= gen_new_label();
4903 tcg_gen_brcondi_tl(TCG_COND_LT
, cpu_gpr
[rA(ctx
->opcode
)], simm
, l1
);
4904 tcg_gen_subfi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
, cpu_gpr
[rA(ctx
->opcode
)]);
4907 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4909 if (unlikely(Rc(ctx
->opcode
) != 0))
4910 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4913 /* lscbx - lscbx. */
4914 static void gen_lscbx(DisasContext
*ctx
)
4916 TCGv t0
= tcg_temp_new();
4917 TCGv_i32 t1
= tcg_const_i32(rD(ctx
->opcode
));
4918 TCGv_i32 t2
= tcg_const_i32(rA(ctx
->opcode
));
4919 TCGv_i32 t3
= tcg_const_i32(rB(ctx
->opcode
));
4921 gen_addr_reg_index(ctx
, t0
);
4922 /* NIP cannot be restored if the memory exception comes from an helper */
4923 gen_update_nip(ctx
, ctx
->nip
- 4);
4924 gen_helper_lscbx(t0
, cpu_env
, t0
, t1
, t2
, t3
);
4925 tcg_temp_free_i32(t1
);
4926 tcg_temp_free_i32(t2
);
4927 tcg_temp_free_i32(t3
);
4928 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~0x7F);
4929 tcg_gen_or_tl(cpu_xer
, cpu_xer
, t0
);
4930 if (unlikely(Rc(ctx
->opcode
) != 0))
4931 gen_set_Rc0(ctx
, t0
);
4935 /* maskg - maskg. */
4936 static void gen_maskg(DisasContext
*ctx
)
4938 int l1
= gen_new_label();
4939 TCGv t0
= tcg_temp_new();
4940 TCGv t1
= tcg_temp_new();
4941 TCGv t2
= tcg_temp_new();
4942 TCGv t3
= tcg_temp_new();
4943 tcg_gen_movi_tl(t3
, 0xFFFFFFFF);
4944 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4945 tcg_gen_andi_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 0x1F);
4946 tcg_gen_addi_tl(t2
, t0
, 1);
4947 tcg_gen_shr_tl(t2
, t3
, t2
);
4948 tcg_gen_shr_tl(t3
, t3
, t1
);
4949 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], t2
, t3
);
4950 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
4951 tcg_gen_neg_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4957 if (unlikely(Rc(ctx
->opcode
) != 0))
4958 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4961 /* maskir - maskir. */
4962 static void gen_maskir(DisasContext
*ctx
)
4964 TCGv t0
= tcg_temp_new();
4965 TCGv t1
= tcg_temp_new();
4966 tcg_gen_and_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4967 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4968 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4971 if (unlikely(Rc(ctx
->opcode
) != 0))
4972 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4976 static void gen_mul(DisasContext
*ctx
)
4978 TCGv_i64 t0
= tcg_temp_new_i64();
4979 TCGv_i64 t1
= tcg_temp_new_i64();
4980 TCGv t2
= tcg_temp_new();
4981 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4982 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4983 tcg_gen_mul_i64(t0
, t0
, t1
);
4984 tcg_gen_trunc_i64_tl(t2
, t0
);
4985 gen_store_spr(SPR_MQ
, t2
);
4986 tcg_gen_shri_i64(t1
, t0
, 32);
4987 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4988 tcg_temp_free_i64(t0
);
4989 tcg_temp_free_i64(t1
);
4991 if (unlikely(Rc(ctx
->opcode
) != 0))
4992 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4996 static void gen_mulo(DisasContext
*ctx
)
4998 int l1
= gen_new_label();
4999 TCGv_i64 t0
= tcg_temp_new_i64();
5000 TCGv_i64 t1
= tcg_temp_new_i64();
5001 TCGv t2
= tcg_temp_new();
5002 /* Start with XER OV disabled, the most likely case */
5003 tcg_gen_movi_tl(cpu_ov
, 0);
5004 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
5005 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
5006 tcg_gen_mul_i64(t0
, t0
, t1
);
5007 tcg_gen_trunc_i64_tl(t2
, t0
);
5008 gen_store_spr(SPR_MQ
, t2
);
5009 tcg_gen_shri_i64(t1
, t0
, 32);
5010 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
5011 tcg_gen_ext32s_i64(t1
, t0
);
5012 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
5013 tcg_gen_movi_tl(cpu_ov
, 1);
5014 tcg_gen_movi_tl(cpu_so
, 1);
5016 tcg_temp_free_i64(t0
);
5017 tcg_temp_free_i64(t1
);
5019 if (unlikely(Rc(ctx
->opcode
) != 0))
5020 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5024 static void gen_nabs(DisasContext
*ctx
)
5026 int l1
= gen_new_label();
5027 int l2
= gen_new_label();
5028 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
5029 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5032 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5034 if (unlikely(Rc(ctx
->opcode
) != 0))
5035 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5038 /* nabso - nabso. */
5039 static void gen_nabso(DisasContext
*ctx
)
5041 int l1
= gen_new_label();
5042 int l2
= gen_new_label();
5043 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
5044 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5047 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5049 /* nabs never overflows */
5050 tcg_gen_movi_tl(cpu_ov
, 0);
5051 if (unlikely(Rc(ctx
->opcode
) != 0))
5052 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5056 static void gen_rlmi(DisasContext
*ctx
)
5058 uint32_t mb
= MB(ctx
->opcode
);
5059 uint32_t me
= ME(ctx
->opcode
);
5060 TCGv t0
= tcg_temp_new();
5061 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5062 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5063 tcg_gen_andi_tl(t0
, t0
, MASK(mb
, me
));
5064 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~MASK(mb
, me
));
5065 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], t0
);
5067 if (unlikely(Rc(ctx
->opcode
) != 0))
5068 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5072 static void gen_rrib(DisasContext
*ctx
)
5074 TCGv t0
= tcg_temp_new();
5075 TCGv t1
= tcg_temp_new();
5076 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5077 tcg_gen_movi_tl(t1
, 0x80000000);
5078 tcg_gen_shr_tl(t1
, t1
, t0
);
5079 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5080 tcg_gen_and_tl(t0
, t0
, t1
);
5081 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], t1
);
5082 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5085 if (unlikely(Rc(ctx
->opcode
) != 0))
5086 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5090 static void gen_sle(DisasContext
*ctx
)
5092 TCGv t0
= tcg_temp_new();
5093 TCGv t1
= tcg_temp_new();
5094 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5095 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5096 tcg_gen_subfi_tl(t1
, 32, t1
);
5097 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5098 tcg_gen_or_tl(t1
, t0
, t1
);
5099 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5100 gen_store_spr(SPR_MQ
, t1
);
5103 if (unlikely(Rc(ctx
->opcode
) != 0))
5104 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5108 static void gen_sleq(DisasContext
*ctx
)
5110 TCGv t0
= tcg_temp_new();
5111 TCGv t1
= tcg_temp_new();
5112 TCGv t2
= tcg_temp_new();
5113 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5114 tcg_gen_movi_tl(t2
, 0xFFFFFFFF);
5115 tcg_gen_shl_tl(t2
, t2
, t0
);
5116 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5117 gen_load_spr(t1
, SPR_MQ
);
5118 gen_store_spr(SPR_MQ
, t0
);
5119 tcg_gen_and_tl(t0
, t0
, t2
);
5120 tcg_gen_andc_tl(t1
, t1
, t2
);
5121 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5125 if (unlikely(Rc(ctx
->opcode
) != 0))
5126 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5130 static void gen_sliq(DisasContext
*ctx
)
5132 int sh
= SH(ctx
->opcode
);
5133 TCGv t0
= tcg_temp_new();
5134 TCGv t1
= tcg_temp_new();
5135 tcg_gen_shli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5136 tcg_gen_shri_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5137 tcg_gen_or_tl(t1
, t0
, t1
);
5138 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5139 gen_store_spr(SPR_MQ
, t1
);
5142 if (unlikely(Rc(ctx
->opcode
) != 0))
5143 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5146 /* slliq - slliq. */
5147 static void gen_slliq(DisasContext
*ctx
)
5149 int sh
= SH(ctx
->opcode
);
5150 TCGv t0
= tcg_temp_new();
5151 TCGv t1
= tcg_temp_new();
5152 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5153 gen_load_spr(t1
, SPR_MQ
);
5154 gen_store_spr(SPR_MQ
, t0
);
5155 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
<< sh
));
5156 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
<< sh
));
5157 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5160 if (unlikely(Rc(ctx
->opcode
) != 0))
5161 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5165 static void gen_sllq(DisasContext
*ctx
)
5167 int l1
= gen_new_label();
5168 int l2
= gen_new_label();
5169 TCGv t0
= tcg_temp_local_new();
5170 TCGv t1
= tcg_temp_local_new();
5171 TCGv t2
= tcg_temp_local_new();
5172 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5173 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5174 tcg_gen_shl_tl(t1
, t1
, t2
);
5175 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5176 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5177 gen_load_spr(t0
, SPR_MQ
);
5178 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5181 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5182 gen_load_spr(t2
, SPR_MQ
);
5183 tcg_gen_andc_tl(t1
, t2
, t1
);
5184 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5189 if (unlikely(Rc(ctx
->opcode
) != 0))
5190 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5194 static void gen_slq(DisasContext
*ctx
)
5196 int l1
= gen_new_label();
5197 TCGv t0
= tcg_temp_new();
5198 TCGv t1
= tcg_temp_new();
5199 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5200 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5201 tcg_gen_subfi_tl(t1
, 32, t1
);
5202 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5203 tcg_gen_or_tl(t1
, t0
, t1
);
5204 gen_store_spr(SPR_MQ
, t1
);
5205 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5206 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5207 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
5208 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5212 if (unlikely(Rc(ctx
->opcode
) != 0))
5213 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5216 /* sraiq - sraiq. */
5217 static void gen_sraiq(DisasContext
*ctx
)
5219 int sh
= SH(ctx
->opcode
);
5220 int l1
= gen_new_label();
5221 TCGv t0
= tcg_temp_new();
5222 TCGv t1
= tcg_temp_new();
5223 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5224 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5225 tcg_gen_or_tl(t0
, t0
, t1
);
5226 gen_store_spr(SPR_MQ
, t0
);
5227 tcg_gen_movi_tl(cpu_ca
, 0);
5228 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
5229 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
5230 tcg_gen_movi_tl(cpu_ca
, 1);
5232 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
5235 if (unlikely(Rc(ctx
->opcode
) != 0))
5236 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5240 static void gen_sraq(DisasContext
*ctx
)
5242 int l1
= gen_new_label();
5243 int l2
= gen_new_label();
5244 TCGv t0
= tcg_temp_new();
5245 TCGv t1
= tcg_temp_local_new();
5246 TCGv t2
= tcg_temp_local_new();
5247 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5248 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5249 tcg_gen_sar_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5250 tcg_gen_subfi_tl(t2
, 32, t2
);
5251 tcg_gen_shl_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5252 tcg_gen_or_tl(t0
, t0
, t2
);
5253 gen_store_spr(SPR_MQ
, t0
);
5254 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5255 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l1
);
5256 tcg_gen_mov_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
5257 tcg_gen_sari_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 31);
5260 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
);
5261 tcg_gen_movi_tl(cpu_ca
, 0);
5262 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
5263 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l2
);
5264 tcg_gen_movi_tl(cpu_ca
, 1);
5268 if (unlikely(Rc(ctx
->opcode
) != 0))
5269 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5273 static void gen_sre(DisasContext
*ctx
)
5275 TCGv t0
= tcg_temp_new();
5276 TCGv t1
= tcg_temp_new();
5277 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5278 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5279 tcg_gen_subfi_tl(t1
, 32, t1
);
5280 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5281 tcg_gen_or_tl(t1
, t0
, t1
);
5282 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5283 gen_store_spr(SPR_MQ
, t1
);
5286 if (unlikely(Rc(ctx
->opcode
) != 0))
5287 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5291 static void gen_srea(DisasContext
*ctx
)
5293 TCGv t0
= tcg_temp_new();
5294 TCGv t1
= tcg_temp_new();
5295 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5296 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5297 gen_store_spr(SPR_MQ
, t0
);
5298 tcg_gen_sar_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t1
);
5301 if (unlikely(Rc(ctx
->opcode
) != 0))
5302 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5306 static void gen_sreq(DisasContext
*ctx
)
5308 TCGv t0
= tcg_temp_new();
5309 TCGv t1
= tcg_temp_new();
5310 TCGv t2
= tcg_temp_new();
5311 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5312 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5313 tcg_gen_shr_tl(t1
, t1
, t0
);
5314 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5315 gen_load_spr(t2
, SPR_MQ
);
5316 gen_store_spr(SPR_MQ
, t0
);
5317 tcg_gen_and_tl(t0
, t0
, t1
);
5318 tcg_gen_andc_tl(t2
, t2
, t1
);
5319 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5323 if (unlikely(Rc(ctx
->opcode
) != 0))
5324 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5328 static void gen_sriq(DisasContext
*ctx
)
5330 int sh
= SH(ctx
->opcode
);
5331 TCGv t0
= tcg_temp_new();
5332 TCGv t1
= tcg_temp_new();
5333 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5334 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5335 tcg_gen_or_tl(t1
, t0
, t1
);
5336 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5337 gen_store_spr(SPR_MQ
, t1
);
5340 if (unlikely(Rc(ctx
->opcode
) != 0))
5341 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5345 static void gen_srliq(DisasContext
*ctx
)
5347 int sh
= SH(ctx
->opcode
);
5348 TCGv t0
= tcg_temp_new();
5349 TCGv t1
= tcg_temp_new();
5350 tcg_gen_rotri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5351 gen_load_spr(t1
, SPR_MQ
);
5352 gen_store_spr(SPR_MQ
, t0
);
5353 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
>> sh
));
5354 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
>> sh
));
5355 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5358 if (unlikely(Rc(ctx
->opcode
) != 0))
5359 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5363 static void gen_srlq(DisasContext
*ctx
)
5365 int l1
= gen_new_label();
5366 int l2
= gen_new_label();
5367 TCGv t0
= tcg_temp_local_new();
5368 TCGv t1
= tcg_temp_local_new();
5369 TCGv t2
= tcg_temp_local_new();
5370 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5371 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5372 tcg_gen_shr_tl(t2
, t1
, t2
);
5373 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5374 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5375 gen_load_spr(t0
, SPR_MQ
);
5376 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5379 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5380 tcg_gen_and_tl(t0
, t0
, t2
);
5381 gen_load_spr(t1
, SPR_MQ
);
5382 tcg_gen_andc_tl(t1
, t1
, t2
);
5383 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5388 if (unlikely(Rc(ctx
->opcode
) != 0))
5389 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5393 static void gen_srq(DisasContext
*ctx
)
5395 int l1
= gen_new_label();
5396 TCGv t0
= tcg_temp_new();
5397 TCGv t1
= tcg_temp_new();
5398 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5399 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5400 tcg_gen_subfi_tl(t1
, 32, t1
);
5401 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5402 tcg_gen_or_tl(t1
, t0
, t1
);
5403 gen_store_spr(SPR_MQ
, t1
);
5404 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5405 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5406 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5407 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5411 if (unlikely(Rc(ctx
->opcode
) != 0))
5412 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5415 /* PowerPC 602 specific instructions */
5418 static void gen_dsa(DisasContext
*ctx
)
5421 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5425 static void gen_esa(DisasContext
*ctx
)
5428 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5432 static void gen_mfrom(DisasContext
*ctx
)
5434 #if defined(CONFIG_USER_ONLY)
5435 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5437 if (unlikely(!ctx
->mem_idx
)) {
5438 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5441 gen_helper_602_mfrom(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5445 /* 602 - 603 - G2 TLB management */
5448 static void gen_tlbld_6xx(DisasContext
*ctx
)
5450 #if defined(CONFIG_USER_ONLY)
5451 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5453 if (unlikely(!ctx
->mem_idx
)) {
5454 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5457 gen_helper_6xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5462 static void gen_tlbli_6xx(DisasContext
*ctx
)
5464 #if defined(CONFIG_USER_ONLY)
5465 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5467 if (unlikely(!ctx
->mem_idx
)) {
5468 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5471 gen_helper_6xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5475 /* 74xx TLB management */
5478 static void gen_tlbld_74xx(DisasContext
*ctx
)
5480 #if defined(CONFIG_USER_ONLY)
5481 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5483 if (unlikely(!ctx
->mem_idx
)) {
5484 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5487 gen_helper_74xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5492 static void gen_tlbli_74xx(DisasContext
*ctx
)
5494 #if defined(CONFIG_USER_ONLY)
5495 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5497 if (unlikely(!ctx
->mem_idx
)) {
5498 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5501 gen_helper_74xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5505 /* POWER instructions not in PowerPC 601 */
5508 static void gen_clf(DisasContext
*ctx
)
5510 /* Cache line flush: implemented as no-op */
5514 static void gen_cli(DisasContext
*ctx
)
5516 /* Cache line invalidate: privileged and treated as no-op */
5517 #if defined(CONFIG_USER_ONLY)
5518 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5520 if (unlikely(!ctx
->mem_idx
)) {
5521 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5528 static void gen_dclst(DisasContext
*ctx
)
5530 /* Data cache line store: treated as no-op */
5533 static void gen_mfsri(DisasContext
*ctx
)
5535 #if defined(CONFIG_USER_ONLY)
5536 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5538 int ra
= rA(ctx
->opcode
);
5539 int rd
= rD(ctx
->opcode
);
5541 if (unlikely(!ctx
->mem_idx
)) {
5542 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5545 t0
= tcg_temp_new();
5546 gen_addr_reg_index(ctx
, t0
);
5547 tcg_gen_shri_tl(t0
, t0
, 28);
5548 tcg_gen_andi_tl(t0
, t0
, 0xF);
5549 gen_helper_load_sr(cpu_gpr
[rd
], cpu_env
, t0
);
5551 if (ra
!= 0 && ra
!= rd
)
5552 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rd
]);
5556 static void gen_rac(DisasContext
*ctx
)
5558 #if defined(CONFIG_USER_ONLY)
5559 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5562 if (unlikely(!ctx
->mem_idx
)) {
5563 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5566 t0
= tcg_temp_new();
5567 gen_addr_reg_index(ctx
, t0
);
5568 gen_helper_rac(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5573 static void gen_rfsvc(DisasContext
*ctx
)
5575 #if defined(CONFIG_USER_ONLY)
5576 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5578 if (unlikely(!ctx
->mem_idx
)) {
5579 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5582 gen_helper_rfsvc(cpu_env
);
5583 gen_sync_exception(ctx
);
5587 /* svc is not implemented for now */
5589 /* POWER2 specific instructions */
5590 /* Quad manipulation (load/store two floats at a time) */
5593 static void gen_lfq(DisasContext
*ctx
)
5595 int rd
= rD(ctx
->opcode
);
5597 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5598 t0
= tcg_temp_new();
5599 gen_addr_imm_index(ctx
, t0
, 0);
5600 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5601 gen_addr_add(ctx
, t0
, t0
, 8);
5602 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5607 static void gen_lfqu(DisasContext
*ctx
)
5609 int ra
= rA(ctx
->opcode
);
5610 int rd
= rD(ctx
->opcode
);
5612 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5613 t0
= tcg_temp_new();
5614 t1
= tcg_temp_new();
5615 gen_addr_imm_index(ctx
, t0
, 0);
5616 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5617 gen_addr_add(ctx
, t1
, t0
, 8);
5618 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5620 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5626 static void gen_lfqux(DisasContext
*ctx
)
5628 int ra
= rA(ctx
->opcode
);
5629 int rd
= rD(ctx
->opcode
);
5630 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5632 t0
= tcg_temp_new();
5633 gen_addr_reg_index(ctx
, t0
);
5634 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5635 t1
= tcg_temp_new();
5636 gen_addr_add(ctx
, t1
, t0
, 8);
5637 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5640 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5645 static void gen_lfqx(DisasContext
*ctx
)
5647 int rd
= rD(ctx
->opcode
);
5649 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5650 t0
= tcg_temp_new();
5651 gen_addr_reg_index(ctx
, t0
);
5652 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5653 gen_addr_add(ctx
, t0
, t0
, 8);
5654 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5659 static void gen_stfq(DisasContext
*ctx
)
5661 int rd
= rD(ctx
->opcode
);
5663 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5664 t0
= tcg_temp_new();
5665 gen_addr_imm_index(ctx
, t0
, 0);
5666 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5667 gen_addr_add(ctx
, t0
, t0
, 8);
5668 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5673 static void gen_stfqu(DisasContext
*ctx
)
5675 int ra
= rA(ctx
->opcode
);
5676 int rd
= rD(ctx
->opcode
);
5678 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5679 t0
= tcg_temp_new();
5680 gen_addr_imm_index(ctx
, t0
, 0);
5681 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5682 t1
= tcg_temp_new();
5683 gen_addr_add(ctx
, t1
, t0
, 8);
5684 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5687 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5692 static void gen_stfqux(DisasContext
*ctx
)
5694 int ra
= rA(ctx
->opcode
);
5695 int rd
= rD(ctx
->opcode
);
5697 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5698 t0
= tcg_temp_new();
5699 gen_addr_reg_index(ctx
, t0
);
5700 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5701 t1
= tcg_temp_new();
5702 gen_addr_add(ctx
, t1
, t0
, 8);
5703 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5706 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5711 static void gen_stfqx(DisasContext
*ctx
)
5713 int rd
= rD(ctx
->opcode
);
5715 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5716 t0
= tcg_temp_new();
5717 gen_addr_reg_index(ctx
, t0
);
5718 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5719 gen_addr_add(ctx
, t0
, t0
, 8);
5720 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5724 /* BookE specific instructions */
5726 /* XXX: not implemented on 440 ? */
5727 static void gen_mfapidi(DisasContext
*ctx
)
5730 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5733 /* XXX: not implemented on 440 ? */
5734 static void gen_tlbiva(DisasContext
*ctx
)
5736 #if defined(CONFIG_USER_ONLY)
5737 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5740 if (unlikely(!ctx
->mem_idx
)) {
5741 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5744 t0
= tcg_temp_new();
5745 gen_addr_reg_index(ctx
, t0
);
5746 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5751 /* All 405 MAC instructions are translated here */
5752 static inline void gen_405_mulladd_insn(DisasContext
*ctx
, int opc2
, int opc3
,
5753 int ra
, int rb
, int rt
, int Rc
)
5757 t0
= tcg_temp_local_new();
5758 t1
= tcg_temp_local_new();
5760 switch (opc3
& 0x0D) {
5762 /* macchw - macchw. - macchwo - macchwo. */
5763 /* macchws - macchws. - macchwso - macchwso. */
5764 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5765 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5766 /* mulchw - mulchw. */
5767 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5768 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5769 tcg_gen_ext16s_tl(t1
, t1
);
5772 /* macchwu - macchwu. - macchwuo - macchwuo. */
5773 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5774 /* mulchwu - mulchwu. */
5775 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5776 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5777 tcg_gen_ext16u_tl(t1
, t1
);
5780 /* machhw - machhw. - machhwo - machhwo. */
5781 /* machhws - machhws. - machhwso - machhwso. */
5782 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5783 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5784 /* mulhhw - mulhhw. */
5785 tcg_gen_sari_tl(t0
, cpu_gpr
[ra
], 16);
5786 tcg_gen_ext16s_tl(t0
, t0
);
5787 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5788 tcg_gen_ext16s_tl(t1
, t1
);
5791 /* machhwu - machhwu. - machhwuo - machhwuo. */
5792 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5793 /* mulhhwu - mulhhwu. */
5794 tcg_gen_shri_tl(t0
, cpu_gpr
[ra
], 16);
5795 tcg_gen_ext16u_tl(t0
, t0
);
5796 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5797 tcg_gen_ext16u_tl(t1
, t1
);
5800 /* maclhw - maclhw. - maclhwo - maclhwo. */
5801 /* maclhws - maclhws. - maclhwso - maclhwso. */
5802 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5803 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5804 /* mullhw - mullhw. */
5805 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5806 tcg_gen_ext16s_tl(t1
, cpu_gpr
[rb
]);
5809 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5810 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5811 /* mullhwu - mullhwu. */
5812 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5813 tcg_gen_ext16u_tl(t1
, cpu_gpr
[rb
]);
5817 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5818 tcg_gen_mul_tl(t1
, t0
, t1
);
5820 /* nmultiply-and-accumulate (0x0E) */
5821 tcg_gen_sub_tl(t0
, cpu_gpr
[rt
], t1
);
5823 /* multiply-and-accumulate (0x0C) */
5824 tcg_gen_add_tl(t0
, cpu_gpr
[rt
], t1
);
5828 /* Check overflow and/or saturate */
5829 int l1
= gen_new_label();
5832 /* Start with XER OV disabled, the most likely case */
5833 tcg_gen_movi_tl(cpu_ov
, 0);
5837 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t1
);
5838 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
5839 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t0
);
5840 tcg_gen_brcondi_tl(TCG_COND_LT
, t1
, 0, l1
);
5843 tcg_gen_sari_tl(t0
, cpu_gpr
[rt
], 31);
5844 tcg_gen_xori_tl(t0
, t0
, 0x7fffffff);
5848 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
5851 tcg_gen_movi_tl(t0
, UINT32_MAX
);
5855 /* Check overflow */
5856 tcg_gen_movi_tl(cpu_ov
, 1);
5857 tcg_gen_movi_tl(cpu_so
, 1);
5860 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
5863 tcg_gen_mul_tl(cpu_gpr
[rt
], t0
, t1
);
5867 if (unlikely(Rc
) != 0) {
5869 gen_set_Rc0(ctx
, cpu_gpr
[rt
]);
5873 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5874 static void glue(gen_, name)(DisasContext *ctx) \
5876 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5877 rD(ctx->opcode), Rc(ctx->opcode)); \
5880 /* macchw - macchw. */
5881 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
5882 /* macchwo - macchwo. */
5883 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
5884 /* macchws - macchws. */
5885 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
5886 /* macchwso - macchwso. */
5887 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
5888 /* macchwsu - macchwsu. */
5889 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
5890 /* macchwsuo - macchwsuo. */
5891 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
5892 /* macchwu - macchwu. */
5893 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
5894 /* macchwuo - macchwuo. */
5895 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
5896 /* machhw - machhw. */
5897 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
5898 /* machhwo - machhwo. */
5899 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
5900 /* machhws - machhws. */
5901 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
5902 /* machhwso - machhwso. */
5903 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
5904 /* machhwsu - machhwsu. */
5905 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
5906 /* machhwsuo - machhwsuo. */
5907 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
5908 /* machhwu - machhwu. */
5909 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
5910 /* machhwuo - machhwuo. */
5911 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
5912 /* maclhw - maclhw. */
5913 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
5914 /* maclhwo - maclhwo. */
5915 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
5916 /* maclhws - maclhws. */
5917 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
5918 /* maclhwso - maclhwso. */
5919 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
5920 /* maclhwu - maclhwu. */
5921 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
5922 /* maclhwuo - maclhwuo. */
5923 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
5924 /* maclhwsu - maclhwsu. */
5925 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
5926 /* maclhwsuo - maclhwsuo. */
5927 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
5928 /* nmacchw - nmacchw. */
5929 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
5930 /* nmacchwo - nmacchwo. */
5931 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
5932 /* nmacchws - nmacchws. */
5933 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
5934 /* nmacchwso - nmacchwso. */
5935 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
5936 /* nmachhw - nmachhw. */
5937 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
5938 /* nmachhwo - nmachhwo. */
5939 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
5940 /* nmachhws - nmachhws. */
5941 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
5942 /* nmachhwso - nmachhwso. */
5943 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
5944 /* nmaclhw - nmaclhw. */
5945 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
5946 /* nmaclhwo - nmaclhwo. */
5947 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
5948 /* nmaclhws - nmaclhws. */
5949 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
5950 /* nmaclhwso - nmaclhwso. */
5951 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
5953 /* mulchw - mulchw. */
5954 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
5955 /* mulchwu - mulchwu. */
5956 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
5957 /* mulhhw - mulhhw. */
5958 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
5959 /* mulhhwu - mulhhwu. */
5960 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
5961 /* mullhw - mullhw. */
5962 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
5963 /* mullhwu - mullhwu. */
5964 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
5967 static void gen_mfdcr(DisasContext
*ctx
)
5969 #if defined(CONFIG_USER_ONLY)
5970 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5973 if (unlikely(!ctx
->mem_idx
)) {
5974 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5977 /* NIP cannot be restored if the memory exception comes from an helper */
5978 gen_update_nip(ctx
, ctx
->nip
- 4);
5979 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5980 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, dcrn
);
5981 tcg_temp_free(dcrn
);
5986 static void gen_mtdcr(DisasContext
*ctx
)
5988 #if defined(CONFIG_USER_ONLY)
5989 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5992 if (unlikely(!ctx
->mem_idx
)) {
5993 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5996 /* NIP cannot be restored if the memory exception comes from an helper */
5997 gen_update_nip(ctx
, ctx
->nip
- 4);
5998 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5999 gen_helper_store_dcr(cpu_env
, dcrn
, cpu_gpr
[rS(ctx
->opcode
)]);
6000 tcg_temp_free(dcrn
);
6005 /* XXX: not implemented on 440 ? */
6006 static void gen_mfdcrx(DisasContext
*ctx
)
6008 #if defined(CONFIG_USER_ONLY)
6009 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
6011 if (unlikely(!ctx
->mem_idx
)) {
6012 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
6015 /* NIP cannot be restored if the memory exception comes from an helper */
6016 gen_update_nip(ctx
, ctx
->nip
- 4);
6017 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6018 cpu_gpr
[rA(ctx
->opcode
)]);
6019 /* Note: Rc update flag set leads to undefined state of Rc0 */
6024 /* XXX: not implemented on 440 ? */
6025 static void gen_mtdcrx(DisasContext
*ctx
)
6027 #if defined(CONFIG_USER_ONLY)
6028 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
6030 if (unlikely(!ctx
->mem_idx
)) {
6031 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
6034 /* NIP cannot be restored if the memory exception comes from an helper */
6035 gen_update_nip(ctx
, ctx
->nip
- 4);
6036 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6037 cpu_gpr
[rS(ctx
->opcode
)]);
6038 /* Note: Rc update flag set leads to undefined state of Rc0 */
6042 /* mfdcrux (PPC 460) : user-mode access to DCR */
6043 static void gen_mfdcrux(DisasContext
*ctx
)
6045 /* NIP cannot be restored if the memory exception comes from an helper */
6046 gen_update_nip(ctx
, ctx
->nip
- 4);
6047 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6048 cpu_gpr
[rA(ctx
->opcode
)]);
6049 /* Note: Rc update flag set leads to undefined state of Rc0 */
6052 /* mtdcrux (PPC 460) : user-mode access to DCR */
6053 static void gen_mtdcrux(DisasContext
*ctx
)
6055 /* NIP cannot be restored if the memory exception comes from an helper */
6056 gen_update_nip(ctx
, ctx
->nip
- 4);
6057 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6058 cpu_gpr
[rS(ctx
->opcode
)]);
6059 /* Note: Rc update flag set leads to undefined state of Rc0 */
6063 static void gen_dccci(DisasContext
*ctx
)
6065 #if defined(CONFIG_USER_ONLY)
6066 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6068 if (unlikely(!ctx
->mem_idx
)) {
6069 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6072 /* interpreted as no-op */
6077 static void gen_dcread(DisasContext
*ctx
)
6079 #if defined(CONFIG_USER_ONLY)
6080 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6083 if (unlikely(!ctx
->mem_idx
)) {
6084 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6087 gen_set_access_type(ctx
, ACCESS_CACHE
);
6088 EA
= tcg_temp_new();
6089 gen_addr_reg_index(ctx
, EA
);
6090 val
= tcg_temp_new();
6091 gen_qemu_ld32u(ctx
, val
, EA
);
6093 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], EA
);
6099 static void gen_icbt_40x(DisasContext
*ctx
)
6101 /* interpreted as no-op */
6102 /* XXX: specification say this is treated as a load by the MMU
6103 * but does not generate any exception
6108 static void gen_iccci(DisasContext
*ctx
)
6110 #if defined(CONFIG_USER_ONLY)
6111 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6113 if (unlikely(!ctx
->mem_idx
)) {
6114 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6117 /* interpreted as no-op */
6122 static void gen_icread(DisasContext
*ctx
)
6124 #if defined(CONFIG_USER_ONLY)
6125 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6127 if (unlikely(!ctx
->mem_idx
)) {
6128 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6131 /* interpreted as no-op */
6135 /* rfci (mem_idx only) */
6136 static void gen_rfci_40x(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_40x_rfci(cpu_env
);
6147 gen_sync_exception(ctx
);
6151 static void gen_rfci(DisasContext
*ctx
)
6153 #if defined(CONFIG_USER_ONLY)
6154 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6156 if (unlikely(!ctx
->mem_idx
)) {
6157 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6160 /* Restore CPU state */
6161 gen_helper_rfci(cpu_env
);
6162 gen_sync_exception(ctx
);
6166 /* BookE specific */
6168 /* XXX: not implemented on 440 ? */
6169 static void gen_rfdi(DisasContext
*ctx
)
6171 #if defined(CONFIG_USER_ONLY)
6172 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6174 if (unlikely(!ctx
->mem_idx
)) {
6175 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6178 /* Restore CPU state */
6179 gen_helper_rfdi(cpu_env
);
6180 gen_sync_exception(ctx
);
6184 /* XXX: not implemented on 440 ? */
6185 static void gen_rfmci(DisasContext
*ctx
)
6187 #if defined(CONFIG_USER_ONLY)
6188 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6190 if (unlikely(!ctx
->mem_idx
)) {
6191 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6194 /* Restore CPU state */
6195 gen_helper_rfmci(cpu_env
);
6196 gen_sync_exception(ctx
);
6200 /* TLB management - PowerPC 405 implementation */
6203 static void gen_tlbre_40x(DisasContext
*ctx
)
6205 #if defined(CONFIG_USER_ONLY)
6206 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6208 if (unlikely(!ctx
->mem_idx
)) {
6209 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6212 switch (rB(ctx
->opcode
)) {
6214 gen_helper_4xx_tlbre_hi(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6215 cpu_gpr
[rA(ctx
->opcode
)]);
6218 gen_helper_4xx_tlbre_lo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6219 cpu_gpr
[rA(ctx
->opcode
)]);
6222 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6228 /* tlbsx - tlbsx. */
6229 static void gen_tlbsx_40x(DisasContext
*ctx
)
6231 #if defined(CONFIG_USER_ONLY)
6232 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6235 if (unlikely(!ctx
->mem_idx
)) {
6236 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6239 t0
= tcg_temp_new();
6240 gen_addr_reg_index(ctx
, t0
);
6241 gen_helper_4xx_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
6243 if (Rc(ctx
->opcode
)) {
6244 int l1
= gen_new_label();
6245 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
6246 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
6247 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
6254 static void gen_tlbwe_40x(DisasContext
*ctx
)
6256 #if defined(CONFIG_USER_ONLY)
6257 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6259 if (unlikely(!ctx
->mem_idx
)) {
6260 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6263 switch (rB(ctx
->opcode
)) {
6265 gen_helper_4xx_tlbwe_hi(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6266 cpu_gpr
[rS(ctx
->opcode
)]);
6269 gen_helper_4xx_tlbwe_lo(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6270 cpu_gpr
[rS(ctx
->opcode
)]);
6273 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6279 /* TLB management - PowerPC 440 implementation */
6282 static void gen_tlbre_440(DisasContext
*ctx
)
6284 #if defined(CONFIG_USER_ONLY)
6285 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6287 if (unlikely(!ctx
->mem_idx
)) {
6288 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6291 switch (rB(ctx
->opcode
)) {
6296 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
6297 gen_helper_440_tlbre(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6298 t0
, cpu_gpr
[rA(ctx
->opcode
)]);
6299 tcg_temp_free_i32(t0
);
6303 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6309 /* tlbsx - tlbsx. */
6310 static void gen_tlbsx_440(DisasContext
*ctx
)
6312 #if defined(CONFIG_USER_ONLY)
6313 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6316 if (unlikely(!ctx
->mem_idx
)) {
6317 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6320 t0
= tcg_temp_new();
6321 gen_addr_reg_index(ctx
, t0
);
6322 gen_helper_440_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
6324 if (Rc(ctx
->opcode
)) {
6325 int l1
= gen_new_label();
6326 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
6327 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
6328 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
6335 static void gen_tlbwe_440(DisasContext
*ctx
)
6337 #if defined(CONFIG_USER_ONLY)
6338 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6340 if (unlikely(!ctx
->mem_idx
)) {
6341 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6344 switch (rB(ctx
->opcode
)) {
6349 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
6350 gen_helper_440_tlbwe(cpu_env
, t0
, cpu_gpr
[rA(ctx
->opcode
)],
6351 cpu_gpr
[rS(ctx
->opcode
)]);
6352 tcg_temp_free_i32(t0
);
6356 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6362 /* TLB management - PowerPC BookE 2.06 implementation */
6365 static void gen_tlbre_booke206(DisasContext
*ctx
)
6367 #if defined(CONFIG_USER_ONLY)
6368 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6370 if (unlikely(!ctx
->mem_idx
)) {
6371 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6375 gen_helper_booke206_tlbre(cpu_env
);
6379 /* tlbsx - tlbsx. */
6380 static void gen_tlbsx_booke206(DisasContext
*ctx
)
6382 #if defined(CONFIG_USER_ONLY)
6383 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6386 if (unlikely(!ctx
->mem_idx
)) {
6387 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6391 if (rA(ctx
->opcode
)) {
6392 t0
= tcg_temp_new();
6393 tcg_gen_mov_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)]);
6395 t0
= tcg_const_tl(0);
6398 tcg_gen_add_tl(t0
, t0
, cpu_gpr
[rB(ctx
->opcode
)]);
6399 gen_helper_booke206_tlbsx(cpu_env
, t0
);
6404 static void gen_tlbwe_booke206(DisasContext
*ctx
)
6406 #if defined(CONFIG_USER_ONLY)
6407 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6409 if (unlikely(!ctx
->mem_idx
)) {
6410 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6413 gen_update_nip(ctx
, ctx
->nip
- 4);
6414 gen_helper_booke206_tlbwe(cpu_env
);
6418 static void gen_tlbivax_booke206(DisasContext
*ctx
)
6420 #if defined(CONFIG_USER_ONLY)
6421 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6424 if (unlikely(!ctx
->mem_idx
)) {
6425 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6429 t0
= tcg_temp_new();
6430 gen_addr_reg_index(ctx
, t0
);
6432 gen_helper_booke206_tlbivax(cpu_env
, t0
);
6436 static void gen_tlbilx_booke206(DisasContext
*ctx
)
6438 #if defined(CONFIG_USER_ONLY)
6439 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6442 if (unlikely(!ctx
->mem_idx
)) {
6443 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6447 t0
= tcg_temp_new();
6448 gen_addr_reg_index(ctx
, t0
);
6450 switch((ctx
->opcode
>> 21) & 0x3) {
6452 gen_helper_booke206_tlbilx0(cpu_env
, t0
);
6455 gen_helper_booke206_tlbilx1(cpu_env
, t0
);
6458 gen_helper_booke206_tlbilx3(cpu_env
, t0
);
6461 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6471 static void gen_wrtee(DisasContext
*ctx
)
6473 #if defined(CONFIG_USER_ONLY)
6474 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6477 if (unlikely(!ctx
->mem_idx
)) {
6478 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6481 t0
= tcg_temp_new();
6482 tcg_gen_andi_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)], (1 << MSR_EE
));
6483 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6484 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
6486 /* Stop translation to have a chance to raise an exception
6487 * if we just set msr_ee to 1
6489 gen_stop_exception(ctx
);
6494 static void gen_wrteei(DisasContext
*ctx
)
6496 #if defined(CONFIG_USER_ONLY)
6497 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6499 if (unlikely(!ctx
->mem_idx
)) {
6500 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6503 if (ctx
->opcode
& 0x00008000) {
6504 tcg_gen_ori_tl(cpu_msr
, cpu_msr
, (1 << MSR_EE
));
6505 /* Stop translation to have a chance to raise an exception */
6506 gen_stop_exception(ctx
);
6508 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6513 /* PowerPC 440 specific instructions */
6516 static void gen_dlmzb(DisasContext
*ctx
)
6518 TCGv_i32 t0
= tcg_const_i32(Rc(ctx
->opcode
));
6519 gen_helper_dlmzb(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
6520 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
6521 tcg_temp_free_i32(t0
);
6524 /* mbar replaces eieio on 440 */
6525 static void gen_mbar(DisasContext
*ctx
)
6527 /* interpreted as no-op */
6530 /* msync replaces sync on 440 */
6531 static void gen_msync_4xx(DisasContext
*ctx
)
6533 /* interpreted as no-op */
6537 static void gen_icbt_440(DisasContext
*ctx
)
6539 /* interpreted as no-op */
6540 /* XXX: specification say this is treated as a load by the MMU
6541 * but does not generate any exception
6545 /* Embedded.Processor Control */
6547 static void gen_msgclr(DisasContext
*ctx
)
6549 #if defined(CONFIG_USER_ONLY)
6550 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6552 if (unlikely(ctx
->mem_idx
== 0)) {
6553 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6557 gen_helper_msgclr(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6561 static void gen_msgsnd(DisasContext
*ctx
)
6563 #if defined(CONFIG_USER_ONLY)
6564 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6566 if (unlikely(ctx
->mem_idx
== 0)) {
6567 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6571 gen_helper_msgsnd(cpu_gpr
[rB(ctx
->opcode
)]);
6575 /*** Altivec vector extension ***/
6576 /* Altivec registers moves */
6578 static inline TCGv_ptr
gen_avr_ptr(int reg
)
6580 TCGv_ptr r
= tcg_temp_new_ptr();
6581 tcg_gen_addi_ptr(r
, cpu_env
, offsetof(CPUPPCState
, avr
[reg
]));
6585 #define GEN_VR_LDX(name, opc2, opc3) \
6586 static void glue(gen_, 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 tcg_gen_andi_tl(EA, EA, ~0xf); \
6597 if (ctx->le_mode) { \
6598 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6599 tcg_gen_addi_tl(EA, EA, 8); \
6600 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6602 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6603 tcg_gen_addi_tl(EA, EA, 8); \
6604 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6606 tcg_temp_free(EA); \
6609 #define GEN_VR_STX(name, opc2, opc3) \
6610 static void gen_st##name(DisasContext *ctx) \
6613 if (unlikely(!ctx->altivec_enabled)) { \
6614 gen_exception(ctx, POWERPC_EXCP_VPU); \
6617 gen_set_access_type(ctx, ACCESS_INT); \
6618 EA = tcg_temp_new(); \
6619 gen_addr_reg_index(ctx, EA); \
6620 tcg_gen_andi_tl(EA, EA, ~0xf); \
6621 if (ctx->le_mode) { \
6622 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6623 tcg_gen_addi_tl(EA, EA, 8); \
6624 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6626 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6627 tcg_gen_addi_tl(EA, EA, 8); \
6628 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6630 tcg_temp_free(EA); \
6633 #define GEN_VR_LVE(name, opc2, opc3) \
6634 static void gen_lve##name(DisasContext *ctx) \
6638 if (unlikely(!ctx->altivec_enabled)) { \
6639 gen_exception(ctx, POWERPC_EXCP_VPU); \
6642 gen_set_access_type(ctx, ACCESS_INT); \
6643 EA = tcg_temp_new(); \
6644 gen_addr_reg_index(ctx, EA); \
6645 rs = gen_avr_ptr(rS(ctx->opcode)); \
6646 gen_helper_lve##name(cpu_env, rs, EA); \
6647 tcg_temp_free(EA); \
6648 tcg_temp_free_ptr(rs); \
6651 #define GEN_VR_STVE(name, opc2, opc3) \
6652 static void gen_stve##name(DisasContext *ctx) \
6656 if (unlikely(!ctx->altivec_enabled)) { \
6657 gen_exception(ctx, POWERPC_EXCP_VPU); \
6660 gen_set_access_type(ctx, ACCESS_INT); \
6661 EA = tcg_temp_new(); \
6662 gen_addr_reg_index(ctx, EA); \
6663 rs = gen_avr_ptr(rS(ctx->opcode)); \
6664 gen_helper_stve##name(cpu_env, rs, EA); \
6665 tcg_temp_free(EA); \
6666 tcg_temp_free_ptr(rs); \
6669 GEN_VR_LDX(lvx
, 0x07, 0x03);
6670 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
6671 GEN_VR_LDX(lvxl
, 0x07, 0x0B);
6673 GEN_VR_LVE(bx
, 0x07, 0x00);
6674 GEN_VR_LVE(hx
, 0x07, 0x01);
6675 GEN_VR_LVE(wx
, 0x07, 0x02);
6677 GEN_VR_STX(svx
, 0x07, 0x07);
6678 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
6679 GEN_VR_STX(svxl
, 0x07, 0x0F);
6681 GEN_VR_STVE(bx
, 0x07, 0x04);
6682 GEN_VR_STVE(hx
, 0x07, 0x05);
6683 GEN_VR_STVE(wx
, 0x07, 0x06);
6685 static void gen_lvsl(DisasContext
*ctx
)
6689 if (unlikely(!ctx
->altivec_enabled
)) {
6690 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6693 EA
= tcg_temp_new();
6694 gen_addr_reg_index(ctx
, EA
);
6695 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6696 gen_helper_lvsl(rd
, EA
);
6698 tcg_temp_free_ptr(rd
);
6701 static void gen_lvsr(DisasContext
*ctx
)
6705 if (unlikely(!ctx
->altivec_enabled
)) {
6706 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6709 EA
= tcg_temp_new();
6710 gen_addr_reg_index(ctx
, EA
);
6711 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6712 gen_helper_lvsr(rd
, EA
);
6714 tcg_temp_free_ptr(rd
);
6717 static void gen_mfvscr(DisasContext
*ctx
)
6720 if (unlikely(!ctx
->altivec_enabled
)) {
6721 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6724 tcg_gen_movi_i64(cpu_avrh
[rD(ctx
->opcode
)], 0);
6725 t
= tcg_temp_new_i32();
6726 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUPPCState
, vscr
));
6727 tcg_gen_extu_i32_i64(cpu_avrl
[rD(ctx
->opcode
)], t
);
6728 tcg_temp_free_i32(t
);
6731 static void gen_mtvscr(DisasContext
*ctx
)
6734 if (unlikely(!ctx
->altivec_enabled
)) {
6735 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6738 p
= gen_avr_ptr(rD(ctx
->opcode
));
6739 gen_helper_mtvscr(cpu_env
, p
);
6740 tcg_temp_free_ptr(p
);
6743 /* Logical operations */
6744 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
6745 static void glue(gen_, name)(DisasContext *ctx) \
6747 if (unlikely(!ctx->altivec_enabled)) { \
6748 gen_exception(ctx, POWERPC_EXCP_VPU); \
6751 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6752 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6755 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16);
6756 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17);
6757 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18);
6758 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19);
6759 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20);
6761 #define GEN_VXFORM(name, opc2, opc3) \
6762 static void glue(gen_, name)(DisasContext *ctx) \
6764 TCGv_ptr ra, rb, rd; \
6765 if (unlikely(!ctx->altivec_enabled)) { \
6766 gen_exception(ctx, POWERPC_EXCP_VPU); \
6769 ra = gen_avr_ptr(rA(ctx->opcode)); \
6770 rb = gen_avr_ptr(rB(ctx->opcode)); \
6771 rd = gen_avr_ptr(rD(ctx->opcode)); \
6772 gen_helper_##name (rd, ra, rb); \
6773 tcg_temp_free_ptr(ra); \
6774 tcg_temp_free_ptr(rb); \
6775 tcg_temp_free_ptr(rd); \
6778 #define GEN_VXFORM_ENV(name, opc2, opc3) \
6779 static void glue(gen_, name)(DisasContext *ctx) \
6781 TCGv_ptr ra, rb, rd; \
6782 if (unlikely(!ctx->altivec_enabled)) { \
6783 gen_exception(ctx, POWERPC_EXCP_VPU); \
6786 ra = gen_avr_ptr(rA(ctx->opcode)); \
6787 rb = gen_avr_ptr(rB(ctx->opcode)); \
6788 rd = gen_avr_ptr(rD(ctx->opcode)); \
6789 gen_helper_##name(cpu_env, rd, ra, rb); \
6790 tcg_temp_free_ptr(ra); \
6791 tcg_temp_free_ptr(rb); \
6792 tcg_temp_free_ptr(rd); \
6795 GEN_VXFORM(vaddubm
, 0, 0);
6796 GEN_VXFORM(vadduhm
, 0, 1);
6797 GEN_VXFORM(vadduwm
, 0, 2);
6798 GEN_VXFORM(vsububm
, 0, 16);
6799 GEN_VXFORM(vsubuhm
, 0, 17);
6800 GEN_VXFORM(vsubuwm
, 0, 18);
6801 GEN_VXFORM(vmaxub
, 1, 0);
6802 GEN_VXFORM(vmaxuh
, 1, 1);
6803 GEN_VXFORM(vmaxuw
, 1, 2);
6804 GEN_VXFORM(vmaxsb
, 1, 4);
6805 GEN_VXFORM(vmaxsh
, 1, 5);
6806 GEN_VXFORM(vmaxsw
, 1, 6);
6807 GEN_VXFORM(vminub
, 1, 8);
6808 GEN_VXFORM(vminuh
, 1, 9);
6809 GEN_VXFORM(vminuw
, 1, 10);
6810 GEN_VXFORM(vminsb
, 1, 12);
6811 GEN_VXFORM(vminsh
, 1, 13);
6812 GEN_VXFORM(vminsw
, 1, 14);
6813 GEN_VXFORM(vavgub
, 1, 16);
6814 GEN_VXFORM(vavguh
, 1, 17);
6815 GEN_VXFORM(vavguw
, 1, 18);
6816 GEN_VXFORM(vavgsb
, 1, 20);
6817 GEN_VXFORM(vavgsh
, 1, 21);
6818 GEN_VXFORM(vavgsw
, 1, 22);
6819 GEN_VXFORM(vmrghb
, 6, 0);
6820 GEN_VXFORM(vmrghh
, 6, 1);
6821 GEN_VXFORM(vmrghw
, 6, 2);
6822 GEN_VXFORM(vmrglb
, 6, 4);
6823 GEN_VXFORM(vmrglh
, 6, 5);
6824 GEN_VXFORM(vmrglw
, 6, 6);
6825 GEN_VXFORM(vmuloub
, 4, 0);
6826 GEN_VXFORM(vmulouh
, 4, 1);
6827 GEN_VXFORM(vmulosb
, 4, 4);
6828 GEN_VXFORM(vmulosh
, 4, 5);
6829 GEN_VXFORM(vmuleub
, 4, 8);
6830 GEN_VXFORM(vmuleuh
, 4, 9);
6831 GEN_VXFORM(vmulesb
, 4, 12);
6832 GEN_VXFORM(vmulesh
, 4, 13);
6833 GEN_VXFORM(vslb
, 2, 4);
6834 GEN_VXFORM(vslh
, 2, 5);
6835 GEN_VXFORM(vslw
, 2, 6);
6836 GEN_VXFORM(vsrb
, 2, 8);
6837 GEN_VXFORM(vsrh
, 2, 9);
6838 GEN_VXFORM(vsrw
, 2, 10);
6839 GEN_VXFORM(vsrab
, 2, 12);
6840 GEN_VXFORM(vsrah
, 2, 13);
6841 GEN_VXFORM(vsraw
, 2, 14);
6842 GEN_VXFORM(vslo
, 6, 16);
6843 GEN_VXFORM(vsro
, 6, 17);
6844 GEN_VXFORM(vaddcuw
, 0, 6);
6845 GEN_VXFORM(vsubcuw
, 0, 22);
6846 GEN_VXFORM_ENV(vaddubs
, 0, 8);
6847 GEN_VXFORM_ENV(vadduhs
, 0, 9);
6848 GEN_VXFORM_ENV(vadduws
, 0, 10);
6849 GEN_VXFORM_ENV(vaddsbs
, 0, 12);
6850 GEN_VXFORM_ENV(vaddshs
, 0, 13);
6851 GEN_VXFORM_ENV(vaddsws
, 0, 14);
6852 GEN_VXFORM_ENV(vsububs
, 0, 24);
6853 GEN_VXFORM_ENV(vsubuhs
, 0, 25);
6854 GEN_VXFORM_ENV(vsubuws
, 0, 26);
6855 GEN_VXFORM_ENV(vsubsbs
, 0, 28);
6856 GEN_VXFORM_ENV(vsubshs
, 0, 29);
6857 GEN_VXFORM_ENV(vsubsws
, 0, 30);
6858 GEN_VXFORM(vrlb
, 2, 0);
6859 GEN_VXFORM(vrlh
, 2, 1);
6860 GEN_VXFORM(vrlw
, 2, 2);
6861 GEN_VXFORM(vsl
, 2, 7);
6862 GEN_VXFORM(vsr
, 2, 11);
6863 GEN_VXFORM_ENV(vpkuhum
, 7, 0);
6864 GEN_VXFORM_ENV(vpkuwum
, 7, 1);
6865 GEN_VXFORM_ENV(vpkuhus
, 7, 2);
6866 GEN_VXFORM_ENV(vpkuwus
, 7, 3);
6867 GEN_VXFORM_ENV(vpkshus
, 7, 4);
6868 GEN_VXFORM_ENV(vpkswus
, 7, 5);
6869 GEN_VXFORM_ENV(vpkshss
, 7, 6);
6870 GEN_VXFORM_ENV(vpkswss
, 7, 7);
6871 GEN_VXFORM(vpkpx
, 7, 12);
6872 GEN_VXFORM_ENV(vsum4ubs
, 4, 24);
6873 GEN_VXFORM_ENV(vsum4sbs
, 4, 28);
6874 GEN_VXFORM_ENV(vsum4shs
, 4, 25);
6875 GEN_VXFORM_ENV(vsum2sws
, 4, 26);
6876 GEN_VXFORM_ENV(vsumsws
, 4, 30);
6877 GEN_VXFORM_ENV(vaddfp
, 5, 0);
6878 GEN_VXFORM_ENV(vsubfp
, 5, 1);
6879 GEN_VXFORM_ENV(vmaxfp
, 5, 16);
6880 GEN_VXFORM_ENV(vminfp
, 5, 17);
6882 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
6883 static void glue(gen_, name)(DisasContext *ctx) \
6885 TCGv_ptr ra, rb, rd; \
6886 if (unlikely(!ctx->altivec_enabled)) { \
6887 gen_exception(ctx, POWERPC_EXCP_VPU); \
6890 ra = gen_avr_ptr(rA(ctx->opcode)); \
6891 rb = gen_avr_ptr(rB(ctx->opcode)); \
6892 rd = gen_avr_ptr(rD(ctx->opcode)); \
6893 gen_helper_##opname(cpu_env, rd, ra, rb); \
6894 tcg_temp_free_ptr(ra); \
6895 tcg_temp_free_ptr(rb); \
6896 tcg_temp_free_ptr(rd); \
6899 #define GEN_VXRFORM(name, opc2, opc3) \
6900 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
6901 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
6903 GEN_VXRFORM(vcmpequb
, 3, 0)
6904 GEN_VXRFORM(vcmpequh
, 3, 1)
6905 GEN_VXRFORM(vcmpequw
, 3, 2)
6906 GEN_VXRFORM(vcmpgtsb
, 3, 12)
6907 GEN_VXRFORM(vcmpgtsh
, 3, 13)
6908 GEN_VXRFORM(vcmpgtsw
, 3, 14)
6909 GEN_VXRFORM(vcmpgtub
, 3, 8)
6910 GEN_VXRFORM(vcmpgtuh
, 3, 9)
6911 GEN_VXRFORM(vcmpgtuw
, 3, 10)
6912 GEN_VXRFORM(vcmpeqfp
, 3, 3)
6913 GEN_VXRFORM(vcmpgefp
, 3, 7)
6914 GEN_VXRFORM(vcmpgtfp
, 3, 11)
6915 GEN_VXRFORM(vcmpbfp
, 3, 15)
6917 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
6918 static void glue(gen_, name)(DisasContext *ctx) \
6922 if (unlikely(!ctx->altivec_enabled)) { \
6923 gen_exception(ctx, POWERPC_EXCP_VPU); \
6926 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6927 rd = gen_avr_ptr(rD(ctx->opcode)); \
6928 gen_helper_##name (rd, simm); \
6929 tcg_temp_free_i32(simm); \
6930 tcg_temp_free_ptr(rd); \
6933 GEN_VXFORM_SIMM(vspltisb
, 6, 12);
6934 GEN_VXFORM_SIMM(vspltish
, 6, 13);
6935 GEN_VXFORM_SIMM(vspltisw
, 6, 14);
6937 #define GEN_VXFORM_NOA(name, opc2, opc3) \
6938 static void glue(gen_, name)(DisasContext *ctx) \
6941 if (unlikely(!ctx->altivec_enabled)) { \
6942 gen_exception(ctx, POWERPC_EXCP_VPU); \
6945 rb = gen_avr_ptr(rB(ctx->opcode)); \
6946 rd = gen_avr_ptr(rD(ctx->opcode)); \
6947 gen_helper_##name (rd, rb); \
6948 tcg_temp_free_ptr(rb); \
6949 tcg_temp_free_ptr(rd); \
6952 #define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
6953 static void glue(gen_, name)(DisasContext *ctx) \
6957 if (unlikely(!ctx->altivec_enabled)) { \
6958 gen_exception(ctx, POWERPC_EXCP_VPU); \
6961 rb = gen_avr_ptr(rB(ctx->opcode)); \
6962 rd = gen_avr_ptr(rD(ctx->opcode)); \
6963 gen_helper_##name(cpu_env, rd, rb); \
6964 tcg_temp_free_ptr(rb); \
6965 tcg_temp_free_ptr(rd); \
6968 GEN_VXFORM_NOA(vupkhsb
, 7, 8);
6969 GEN_VXFORM_NOA(vupkhsh
, 7, 9);
6970 GEN_VXFORM_NOA(vupklsb
, 7, 10);
6971 GEN_VXFORM_NOA(vupklsh
, 7, 11);
6972 GEN_VXFORM_NOA(vupkhpx
, 7, 13);
6973 GEN_VXFORM_NOA(vupklpx
, 7, 15);
6974 GEN_VXFORM_NOA_ENV(vrefp
, 5, 4);
6975 GEN_VXFORM_NOA_ENV(vrsqrtefp
, 5, 5);
6976 GEN_VXFORM_NOA_ENV(vexptefp
, 5, 6);
6977 GEN_VXFORM_NOA_ENV(vlogefp
, 5, 7);
6978 GEN_VXFORM_NOA_ENV(vrfim
, 5, 8);
6979 GEN_VXFORM_NOA_ENV(vrfin
, 5, 9);
6980 GEN_VXFORM_NOA_ENV(vrfip
, 5, 10);
6981 GEN_VXFORM_NOA_ENV(vrfiz
, 5, 11);
6983 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
6984 static void glue(gen_, name)(DisasContext *ctx) \
6988 if (unlikely(!ctx->altivec_enabled)) { \
6989 gen_exception(ctx, POWERPC_EXCP_VPU); \
6992 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6993 rd = gen_avr_ptr(rD(ctx->opcode)); \
6994 gen_helper_##name (rd, simm); \
6995 tcg_temp_free_i32(simm); \
6996 tcg_temp_free_ptr(rd); \
6999 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
7000 static void glue(gen_, name)(DisasContext *ctx) \
7004 if (unlikely(!ctx->altivec_enabled)) { \
7005 gen_exception(ctx, POWERPC_EXCP_VPU); \
7008 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7009 rb = gen_avr_ptr(rB(ctx->opcode)); \
7010 rd = gen_avr_ptr(rD(ctx->opcode)); \
7011 gen_helper_##name (rd, rb, uimm); \
7012 tcg_temp_free_i32(uimm); \
7013 tcg_temp_free_ptr(rb); \
7014 tcg_temp_free_ptr(rd); \
7017 #define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
7018 static void glue(gen_, name)(DisasContext *ctx) \
7023 if (unlikely(!ctx->altivec_enabled)) { \
7024 gen_exception(ctx, POWERPC_EXCP_VPU); \
7027 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7028 rb = gen_avr_ptr(rB(ctx->opcode)); \
7029 rd = gen_avr_ptr(rD(ctx->opcode)); \
7030 gen_helper_##name(cpu_env, rd, rb, uimm); \
7031 tcg_temp_free_i32(uimm); \
7032 tcg_temp_free_ptr(rb); \
7033 tcg_temp_free_ptr(rd); \
7036 GEN_VXFORM_UIMM(vspltb
, 6, 8);
7037 GEN_VXFORM_UIMM(vsplth
, 6, 9);
7038 GEN_VXFORM_UIMM(vspltw
, 6, 10);
7039 GEN_VXFORM_UIMM_ENV(vcfux
, 5, 12);
7040 GEN_VXFORM_UIMM_ENV(vcfsx
, 5, 13);
7041 GEN_VXFORM_UIMM_ENV(vctuxs
, 5, 14);
7042 GEN_VXFORM_UIMM_ENV(vctsxs
, 5, 15);
7044 static void gen_vsldoi(DisasContext
*ctx
)
7046 TCGv_ptr ra
, rb
, rd
;
7048 if (unlikely(!ctx
->altivec_enabled
)) {
7049 gen_exception(ctx
, POWERPC_EXCP_VPU
);
7052 ra
= gen_avr_ptr(rA(ctx
->opcode
));
7053 rb
= gen_avr_ptr(rB(ctx
->opcode
));
7054 rd
= gen_avr_ptr(rD(ctx
->opcode
));
7055 sh
= tcg_const_i32(VSH(ctx
->opcode
));
7056 gen_helper_vsldoi (rd
, ra
, rb
, sh
);
7057 tcg_temp_free_ptr(ra
);
7058 tcg_temp_free_ptr(rb
);
7059 tcg_temp_free_ptr(rd
);
7060 tcg_temp_free_i32(sh
);
7063 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
7064 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7066 TCGv_ptr ra, rb, rc, rd; \
7067 if (unlikely(!ctx->altivec_enabled)) { \
7068 gen_exception(ctx, POWERPC_EXCP_VPU); \
7071 ra = gen_avr_ptr(rA(ctx->opcode)); \
7072 rb = gen_avr_ptr(rB(ctx->opcode)); \
7073 rc = gen_avr_ptr(rC(ctx->opcode)); \
7074 rd = gen_avr_ptr(rD(ctx->opcode)); \
7075 if (Rc(ctx->opcode)) { \
7076 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
7078 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
7080 tcg_temp_free_ptr(ra); \
7081 tcg_temp_free_ptr(rb); \
7082 tcg_temp_free_ptr(rc); \
7083 tcg_temp_free_ptr(rd); \
7086 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16)
7088 static void gen_vmladduhm(DisasContext
*ctx
)
7090 TCGv_ptr ra
, rb
, rc
, rd
;
7091 if (unlikely(!ctx
->altivec_enabled
)) {
7092 gen_exception(ctx
, POWERPC_EXCP_VPU
);
7095 ra
= gen_avr_ptr(rA(ctx
->opcode
));
7096 rb
= gen_avr_ptr(rB(ctx
->opcode
));
7097 rc
= gen_avr_ptr(rC(ctx
->opcode
));
7098 rd
= gen_avr_ptr(rD(ctx
->opcode
));
7099 gen_helper_vmladduhm(rd
, ra
, rb
, rc
);
7100 tcg_temp_free_ptr(ra
);
7101 tcg_temp_free_ptr(rb
);
7102 tcg_temp_free_ptr(rc
);
7103 tcg_temp_free_ptr(rd
);
7106 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18)
7107 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19)
7108 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20)
7109 GEN_VAFORM_PAIRED(vsel
, vperm
, 21)
7110 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23)
7112 /*** VSX extension ***/
7114 static inline TCGv_i64
cpu_vsrh(int n
)
7119 return cpu_avrh
[n
-32];
7123 static inline TCGv_i64
cpu_vsrl(int n
)
7128 return cpu_avrl
[n
-32];
7132 #define VSX_LOAD_SCALAR(name, operation) \
7133 static void gen_##name(DisasContext *ctx) \
7136 if (unlikely(!ctx->vsx_enabled)) { \
7137 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7140 gen_set_access_type(ctx, ACCESS_INT); \
7141 EA = tcg_temp_new(); \
7142 gen_addr_reg_index(ctx, EA); \
7143 gen_qemu_##operation(ctx, cpu_vsrh(xT(ctx->opcode)), EA); \
7144 /* NOTE: cpu_vsrl is undefined */ \
7145 tcg_temp_free(EA); \
7148 VSX_LOAD_SCALAR(lxsdx
, ld64
)
7149 VSX_LOAD_SCALAR(lxsiwax
, ld32s_i64
)
7150 VSX_LOAD_SCALAR(lxsiwzx
, ld32u_i64
)
7151 VSX_LOAD_SCALAR(lxsspx
, ld32fs
)
7153 static void gen_lxvd2x(DisasContext
*ctx
)
7156 if (unlikely(!ctx
->vsx_enabled
)) {
7157 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7160 gen_set_access_type(ctx
, ACCESS_INT
);
7161 EA
= tcg_temp_new();
7162 gen_addr_reg_index(ctx
, EA
);
7163 gen_qemu_ld64(ctx
, cpu_vsrh(xT(ctx
->opcode
)), EA
);
7164 tcg_gen_addi_tl(EA
, EA
, 8);
7165 gen_qemu_ld64(ctx
, cpu_vsrl(xT(ctx
->opcode
)), EA
);
7169 static void gen_lxvdsx(DisasContext
*ctx
)
7172 if (unlikely(!ctx
->vsx_enabled
)) {
7173 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7176 gen_set_access_type(ctx
, ACCESS_INT
);
7177 EA
= tcg_temp_new();
7178 gen_addr_reg_index(ctx
, EA
);
7179 gen_qemu_ld64(ctx
, cpu_vsrh(xT(ctx
->opcode
)), EA
);
7180 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), cpu_vsrh(xT(ctx
->opcode
)));
7184 static void gen_lxvw4x(DisasContext
*ctx
)
7188 TCGv_i64 xth
= cpu_vsrh(xT(ctx
->opcode
));
7189 TCGv_i64 xtl
= cpu_vsrl(xT(ctx
->opcode
));
7190 if (unlikely(!ctx
->vsx_enabled
)) {
7191 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7194 gen_set_access_type(ctx
, ACCESS_INT
);
7195 EA
= tcg_temp_new();
7196 tmp
= tcg_temp_new_i64();
7198 gen_addr_reg_index(ctx
, EA
);
7199 gen_qemu_ld32u_i64(ctx
, tmp
, EA
);
7200 tcg_gen_addi_tl(EA
, EA
, 4);
7201 gen_qemu_ld32u_i64(ctx
, xth
, EA
);
7202 tcg_gen_deposit_i64(xth
, xth
, tmp
, 32, 32);
7204 tcg_gen_addi_tl(EA
, EA
, 4);
7205 gen_qemu_ld32u_i64(ctx
, tmp
, EA
);
7206 tcg_gen_addi_tl(EA
, EA
, 4);
7207 gen_qemu_ld32u_i64(ctx
, xtl
, EA
);
7208 tcg_gen_deposit_i64(xtl
, xtl
, tmp
, 32, 32);
7211 tcg_temp_free_i64(tmp
);
7214 #define VSX_STORE_SCALAR(name, operation) \
7215 static void gen_##name(DisasContext *ctx) \
7218 if (unlikely(!ctx->vsx_enabled)) { \
7219 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7222 gen_set_access_type(ctx, ACCESS_INT); \
7223 EA = tcg_temp_new(); \
7224 gen_addr_reg_index(ctx, EA); \
7225 gen_qemu_##operation(ctx, cpu_vsrh(xS(ctx->opcode)), EA); \
7226 tcg_temp_free(EA); \
7229 VSX_STORE_SCALAR(stxsdx
, st64
)
7230 VSX_STORE_SCALAR(stxsiwx
, st32_i64
)
7231 VSX_STORE_SCALAR(stxsspx
, st32fs
)
7233 static void gen_stxvd2x(DisasContext
*ctx
)
7236 if (unlikely(!ctx
->vsx_enabled
)) {
7237 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7240 gen_set_access_type(ctx
, ACCESS_INT
);
7241 EA
= tcg_temp_new();
7242 gen_addr_reg_index(ctx
, EA
);
7243 gen_qemu_st64(ctx
, cpu_vsrh(xS(ctx
->opcode
)), EA
);
7244 tcg_gen_addi_tl(EA
, EA
, 8);
7245 gen_qemu_st64(ctx
, cpu_vsrl(xS(ctx
->opcode
)), EA
);
7249 static void gen_stxvw4x(DisasContext
*ctx
)
7253 if (unlikely(!ctx
->vsx_enabled
)) {
7254 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7257 gen_set_access_type(ctx
, ACCESS_INT
);
7258 EA
= tcg_temp_new();
7259 gen_addr_reg_index(ctx
, EA
);
7260 tmp
= tcg_temp_new_i64();
7262 tcg_gen_shri_i64(tmp
, cpu_vsrh(xS(ctx
->opcode
)), 32);
7263 gen_qemu_st32_i64(ctx
, tmp
, EA
);
7264 tcg_gen_addi_tl(EA
, EA
, 4);
7265 gen_qemu_st32_i64(ctx
, cpu_vsrh(xS(ctx
->opcode
)), EA
);
7267 tcg_gen_shri_i64(tmp
, cpu_vsrl(xS(ctx
->opcode
)), 32);
7268 tcg_gen_addi_tl(EA
, EA
, 4);
7269 gen_qemu_st32_i64(ctx
, tmp
, EA
);
7270 tcg_gen_addi_tl(EA
, EA
, 4);
7271 gen_qemu_st32_i64(ctx
, cpu_vsrl(xS(ctx
->opcode
)), EA
);
7274 tcg_temp_free_i64(tmp
);
7277 #define MV_VSRW(name, tcgop1, tcgop2, target, source) \
7278 static void gen_##name(DisasContext *ctx) \
7280 if (xS(ctx->opcode) < 32) { \
7281 if (unlikely(!ctx->fpu_enabled)) { \
7282 gen_exception(ctx, POWERPC_EXCP_FPU); \
7286 if (unlikely(!ctx->altivec_enabled)) { \
7287 gen_exception(ctx, POWERPC_EXCP_VPU); \
7291 TCGv_i64 tmp = tcg_temp_new_i64(); \
7292 tcg_gen_##tcgop1(tmp, source); \
7293 tcg_gen_##tcgop2(target, tmp); \
7294 tcg_temp_free_i64(tmp); \
7298 MV_VSRW(mfvsrwz
, ext32u_i64
, trunc_i64_tl
, cpu_gpr
[rA(ctx
->opcode
)], \
7299 cpu_vsrh(xS(ctx
->opcode
)))
7300 MV_VSRW(mtvsrwa
, extu_tl_i64
, ext32s_i64
, cpu_vsrh(xT(ctx
->opcode
)), \
7301 cpu_gpr
[rA(ctx
->opcode
)])
7302 MV_VSRW(mtvsrwz
, extu_tl_i64
, ext32u_i64
, cpu_vsrh(xT(ctx
->opcode
)), \
7303 cpu_gpr
[rA(ctx
->opcode
)])
7305 #if defined(TARGET_PPC64)
7306 #define MV_VSRD(name, target, source) \
7307 static void gen_##name(DisasContext *ctx) \
7309 if (xS(ctx->opcode) < 32) { \
7310 if (unlikely(!ctx->fpu_enabled)) { \
7311 gen_exception(ctx, POWERPC_EXCP_FPU); \
7315 if (unlikely(!ctx->altivec_enabled)) { \
7316 gen_exception(ctx, POWERPC_EXCP_VPU); \
7320 tcg_gen_mov_i64(target, source); \
7323 MV_VSRD(mfvsrd
, cpu_gpr
[rA(ctx
->opcode
)], cpu_vsrh(xS(ctx
->opcode
)))
7324 MV_VSRD(mtvsrd
, cpu_vsrh(xT(ctx
->opcode
)), cpu_gpr
[rA(ctx
->opcode
)])
7328 static void gen_xxpermdi(DisasContext
*ctx
)
7330 if (unlikely(!ctx
->vsx_enabled
)) {
7331 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7335 if ((DM(ctx
->opcode
) & 2) == 0) {
7336 tcg_gen_mov_i64(cpu_vsrh(xT(ctx
->opcode
)), cpu_vsrh(xA(ctx
->opcode
)));
7338 tcg_gen_mov_i64(cpu_vsrh(xT(ctx
->opcode
)), cpu_vsrl(xA(ctx
->opcode
)));
7340 if ((DM(ctx
->opcode
) & 1) == 0) {
7341 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), cpu_vsrh(xB(ctx
->opcode
)));
7343 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), cpu_vsrl(xB(ctx
->opcode
)));
7351 #define SGN_MASK_DP 0x8000000000000000ul
7352 #define SGN_MASK_SP 0x8000000080000000ul
7354 #define VSX_SCALAR_MOVE(name, op, sgn_mask) \
7355 static void glue(gen_, name)(DisasContext * ctx) \
7358 if (unlikely(!ctx->vsx_enabled)) { \
7359 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7362 xb = tcg_temp_new_i64(); \
7363 sgm = tcg_temp_new_i64(); \
7364 tcg_gen_mov_i64(xb, cpu_vsrh(xB(ctx->opcode))); \
7365 tcg_gen_movi_i64(sgm, sgn_mask); \
7368 tcg_gen_andc_i64(xb, xb, sgm); \
7372 tcg_gen_or_i64(xb, xb, sgm); \
7376 tcg_gen_xor_i64(xb, xb, sgm); \
7380 TCGv_i64 xa = tcg_temp_new_i64(); \
7381 tcg_gen_mov_i64(xa, cpu_vsrh(xA(ctx->opcode))); \
7382 tcg_gen_and_i64(xa, xa, sgm); \
7383 tcg_gen_andc_i64(xb, xb, sgm); \
7384 tcg_gen_or_i64(xb, xb, xa); \
7385 tcg_temp_free_i64(xa); \
7389 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xb); \
7390 tcg_temp_free_i64(xb); \
7391 tcg_temp_free_i64(sgm); \
7394 VSX_SCALAR_MOVE(xsabsdp
, OP_ABS
, SGN_MASK_DP
)
7395 VSX_SCALAR_MOVE(xsnabsdp
, OP_NABS
, SGN_MASK_DP
)
7396 VSX_SCALAR_MOVE(xsnegdp
, OP_NEG
, SGN_MASK_DP
)
7397 VSX_SCALAR_MOVE(xscpsgndp
, OP_CPSGN
, SGN_MASK_DP
)
7399 #define VSX_VECTOR_MOVE(name, op, sgn_mask) \
7400 static void glue(gen_, name)(DisasContext * ctx) \
7402 TCGv_i64 xbh, xbl, sgm; \
7403 if (unlikely(!ctx->vsx_enabled)) { \
7404 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7407 xbh = tcg_temp_new_i64(); \
7408 xbl = tcg_temp_new_i64(); \
7409 sgm = tcg_temp_new_i64(); \
7410 tcg_gen_mov_i64(xbh, cpu_vsrh(xB(ctx->opcode))); \
7411 tcg_gen_mov_i64(xbl, cpu_vsrl(xB(ctx->opcode))); \
7412 tcg_gen_movi_i64(sgm, sgn_mask); \
7415 tcg_gen_andc_i64(xbh, xbh, sgm); \
7416 tcg_gen_andc_i64(xbl, xbl, sgm); \
7420 tcg_gen_or_i64(xbh, xbh, sgm); \
7421 tcg_gen_or_i64(xbl, xbl, sgm); \
7425 tcg_gen_xor_i64(xbh, xbh, sgm); \
7426 tcg_gen_xor_i64(xbl, xbl, sgm); \
7430 TCGv_i64 xah = tcg_temp_new_i64(); \
7431 TCGv_i64 xal = tcg_temp_new_i64(); \
7432 tcg_gen_mov_i64(xah, cpu_vsrh(xA(ctx->opcode))); \
7433 tcg_gen_mov_i64(xal, cpu_vsrl(xA(ctx->opcode))); \
7434 tcg_gen_and_i64(xah, xah, sgm); \
7435 tcg_gen_and_i64(xal, xal, sgm); \
7436 tcg_gen_andc_i64(xbh, xbh, sgm); \
7437 tcg_gen_andc_i64(xbl, xbl, sgm); \
7438 tcg_gen_or_i64(xbh, xbh, xah); \
7439 tcg_gen_or_i64(xbl, xbl, xal); \
7440 tcg_temp_free_i64(xah); \
7441 tcg_temp_free_i64(xal); \
7445 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xbh); \
7446 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xbl); \
7447 tcg_temp_free_i64(xbh); \
7448 tcg_temp_free_i64(xbl); \
7449 tcg_temp_free_i64(sgm); \
7452 VSX_VECTOR_MOVE(xvabsdp
, OP_ABS
, SGN_MASK_DP
)
7453 VSX_VECTOR_MOVE(xvnabsdp
, OP_NABS
, SGN_MASK_DP
)
7454 VSX_VECTOR_MOVE(xvnegdp
, OP_NEG
, SGN_MASK_DP
)
7455 VSX_VECTOR_MOVE(xvcpsgndp
, OP_CPSGN
, SGN_MASK_DP
)
7456 VSX_VECTOR_MOVE(xvabssp
, OP_ABS
, SGN_MASK_SP
)
7457 VSX_VECTOR_MOVE(xvnabssp
, OP_NABS
, SGN_MASK_SP
)
7458 VSX_VECTOR_MOVE(xvnegsp
, OP_NEG
, SGN_MASK_SP
)
7459 VSX_VECTOR_MOVE(xvcpsgnsp
, OP_CPSGN
, SGN_MASK_SP
)
7461 #define GEN_VSX_HELPER_2(name, op1, op2, inval, type) \
7462 static void gen_##name(DisasContext * ctx) \
7465 if (unlikely(!ctx->vsx_enabled)) { \
7466 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7469 /* NIP cannot be restored if the memory exception comes from an helper */ \
7470 gen_update_nip(ctx, ctx->nip - 4); \
7471 opc = tcg_const_i32(ctx->opcode); \
7472 gen_helper_##name(cpu_env, opc); \
7473 tcg_temp_free_i32(opc); \
7476 #define GEN_VSX_HELPER_XT_XB_ENV(name, op1, op2, inval, type) \
7477 static void gen_##name(DisasContext * ctx) \
7479 if (unlikely(!ctx->vsx_enabled)) { \
7480 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7483 /* NIP cannot be restored if the exception comes */ \
7484 /* from a helper. */ \
7485 gen_update_nip(ctx, ctx->nip - 4); \
7487 gen_helper_##name(cpu_vsrh(xT(ctx->opcode)), cpu_env, \
7488 cpu_vsrh(xB(ctx->opcode))); \
7491 GEN_VSX_HELPER_2(xsadddp
, 0x00, 0x04, 0, PPC2_VSX
)
7492 GEN_VSX_HELPER_2(xssubdp
, 0x00, 0x05, 0, PPC2_VSX
)
7493 GEN_VSX_HELPER_2(xsmuldp
, 0x00, 0x06, 0, PPC2_VSX
)
7494 GEN_VSX_HELPER_2(xsdivdp
, 0x00, 0x07, 0, PPC2_VSX
)
7495 GEN_VSX_HELPER_2(xsredp
, 0x14, 0x05, 0, PPC2_VSX
)
7496 GEN_VSX_HELPER_2(xssqrtdp
, 0x16, 0x04, 0, PPC2_VSX
)
7497 GEN_VSX_HELPER_2(xsrsqrtedp
, 0x14, 0x04, 0, PPC2_VSX
)
7498 GEN_VSX_HELPER_2(xstdivdp
, 0x14, 0x07, 0, PPC2_VSX
)
7499 GEN_VSX_HELPER_2(xstsqrtdp
, 0x14, 0x06, 0, PPC2_VSX
)
7500 GEN_VSX_HELPER_2(xsmaddadp
, 0x04, 0x04, 0, PPC2_VSX
)
7501 GEN_VSX_HELPER_2(xsmaddmdp
, 0x04, 0x05, 0, PPC2_VSX
)
7502 GEN_VSX_HELPER_2(xsmsubadp
, 0x04, 0x06, 0, PPC2_VSX
)
7503 GEN_VSX_HELPER_2(xsmsubmdp
, 0x04, 0x07, 0, PPC2_VSX
)
7504 GEN_VSX_HELPER_2(xsnmaddadp
, 0x04, 0x14, 0, PPC2_VSX
)
7505 GEN_VSX_HELPER_2(xsnmaddmdp
, 0x04, 0x15, 0, PPC2_VSX
)
7506 GEN_VSX_HELPER_2(xsnmsubadp
, 0x04, 0x16, 0, PPC2_VSX
)
7507 GEN_VSX_HELPER_2(xsnmsubmdp
, 0x04, 0x17, 0, PPC2_VSX
)
7508 GEN_VSX_HELPER_2(xscmpodp
, 0x0C, 0x05, 0, PPC2_VSX
)
7509 GEN_VSX_HELPER_2(xscmpudp
, 0x0C, 0x04, 0, PPC2_VSX
)
7510 GEN_VSX_HELPER_2(xsmaxdp
, 0x00, 0x14, 0, PPC2_VSX
)
7511 GEN_VSX_HELPER_2(xsmindp
, 0x00, 0x15, 0, PPC2_VSX
)
7512 GEN_VSX_HELPER_2(xscvdpsp
, 0x12, 0x10, 0, PPC2_VSX
)
7513 GEN_VSX_HELPER_XT_XB_ENV(xscvdpspn
, 0x16, 0x10, 0, PPC2_VSX207
)
7514 GEN_VSX_HELPER_2(xscvspdp
, 0x12, 0x14, 0, PPC2_VSX
)
7515 GEN_VSX_HELPER_XT_XB_ENV(xscvspdpn
, 0x16, 0x14, 0, PPC2_VSX207
)
7516 GEN_VSX_HELPER_2(xscvdpsxds
, 0x10, 0x15, 0, PPC2_VSX
)
7517 GEN_VSX_HELPER_2(xscvdpsxws
, 0x10, 0x05, 0, PPC2_VSX
)
7518 GEN_VSX_HELPER_2(xscvdpuxds
, 0x10, 0x14, 0, PPC2_VSX
)
7519 GEN_VSX_HELPER_2(xscvdpuxws
, 0x10, 0x04, 0, PPC2_VSX
)
7520 GEN_VSX_HELPER_2(xscvsxddp
, 0x10, 0x17, 0, PPC2_VSX
)
7521 GEN_VSX_HELPER_2(xscvuxddp
, 0x10, 0x16, 0, PPC2_VSX
)
7522 GEN_VSX_HELPER_2(xsrdpi
, 0x12, 0x04, 0, PPC2_VSX
)
7523 GEN_VSX_HELPER_2(xsrdpic
, 0x16, 0x06, 0, PPC2_VSX
)
7524 GEN_VSX_HELPER_2(xsrdpim
, 0x12, 0x07, 0, PPC2_VSX
)
7525 GEN_VSX_HELPER_2(xsrdpip
, 0x12, 0x06, 0, PPC2_VSX
)
7526 GEN_VSX_HELPER_2(xsrdpiz
, 0x12, 0x05, 0, PPC2_VSX
)
7527 GEN_VSX_HELPER_XT_XB_ENV(xsrsp
, 0x12, 0x11, 0, PPC2_VSX207
)
7529 GEN_VSX_HELPER_2(xsaddsp
, 0x00, 0x00, 0, PPC2_VSX207
)
7530 GEN_VSX_HELPER_2(xssubsp
, 0x00, 0x01, 0, PPC2_VSX207
)
7531 GEN_VSX_HELPER_2(xsmulsp
, 0x00, 0x02, 0, PPC2_VSX207
)
7532 GEN_VSX_HELPER_2(xsdivsp
, 0x00, 0x03, 0, PPC2_VSX207
)
7533 GEN_VSX_HELPER_2(xsresp
, 0x14, 0x01, 0, PPC2_VSX207
)
7534 GEN_VSX_HELPER_2(xssqrtsp
, 0x16, 0x00, 0, PPC2_VSX207
)
7535 GEN_VSX_HELPER_2(xsrsqrtesp
, 0x14, 0x00, 0, PPC2_VSX207
)
7536 GEN_VSX_HELPER_2(xsmaddasp
, 0x04, 0x00, 0, PPC2_VSX207
)
7537 GEN_VSX_HELPER_2(xsmaddmsp
, 0x04, 0x01, 0, PPC2_VSX207
)
7538 GEN_VSX_HELPER_2(xsmsubasp
, 0x04, 0x02, 0, PPC2_VSX207
)
7539 GEN_VSX_HELPER_2(xsmsubmsp
, 0x04, 0x03, 0, PPC2_VSX207
)
7540 GEN_VSX_HELPER_2(xsnmaddasp
, 0x04, 0x10, 0, PPC2_VSX207
)
7541 GEN_VSX_HELPER_2(xsnmaddmsp
, 0x04, 0x11, 0, PPC2_VSX207
)
7542 GEN_VSX_HELPER_2(xsnmsubasp
, 0x04, 0x12, 0, PPC2_VSX207
)
7543 GEN_VSX_HELPER_2(xsnmsubmsp
, 0x04, 0x13, 0, PPC2_VSX207
)
7544 GEN_VSX_HELPER_2(xscvsxdsp
, 0x10, 0x13, 0, PPC2_VSX207
)
7545 GEN_VSX_HELPER_2(xscvuxdsp
, 0x10, 0x12, 0, PPC2_VSX207
)
7547 GEN_VSX_HELPER_2(xvadddp
, 0x00, 0x0C, 0, PPC2_VSX
)
7548 GEN_VSX_HELPER_2(xvsubdp
, 0x00, 0x0D, 0, PPC2_VSX
)
7549 GEN_VSX_HELPER_2(xvmuldp
, 0x00, 0x0E, 0, PPC2_VSX
)
7550 GEN_VSX_HELPER_2(xvdivdp
, 0x00, 0x0F, 0, PPC2_VSX
)
7551 GEN_VSX_HELPER_2(xvredp
, 0x14, 0x0D, 0, PPC2_VSX
)
7552 GEN_VSX_HELPER_2(xvsqrtdp
, 0x16, 0x0C, 0, PPC2_VSX
)
7553 GEN_VSX_HELPER_2(xvrsqrtedp
, 0x14, 0x0C, 0, PPC2_VSX
)
7554 GEN_VSX_HELPER_2(xvtdivdp
, 0x14, 0x0F, 0, PPC2_VSX
)
7555 GEN_VSX_HELPER_2(xvtsqrtdp
, 0x14, 0x0E, 0, PPC2_VSX
)
7556 GEN_VSX_HELPER_2(xvmaddadp
, 0x04, 0x0C, 0, PPC2_VSX
)
7557 GEN_VSX_HELPER_2(xvmaddmdp
, 0x04, 0x0D, 0, PPC2_VSX
)
7558 GEN_VSX_HELPER_2(xvmsubadp
, 0x04, 0x0E, 0, PPC2_VSX
)
7559 GEN_VSX_HELPER_2(xvmsubmdp
, 0x04, 0x0F, 0, PPC2_VSX
)
7560 GEN_VSX_HELPER_2(xvnmaddadp
, 0x04, 0x1C, 0, PPC2_VSX
)
7561 GEN_VSX_HELPER_2(xvnmaddmdp
, 0x04, 0x1D, 0, PPC2_VSX
)
7562 GEN_VSX_HELPER_2(xvnmsubadp
, 0x04, 0x1E, 0, PPC2_VSX
)
7563 GEN_VSX_HELPER_2(xvnmsubmdp
, 0x04, 0x1F, 0, PPC2_VSX
)
7564 GEN_VSX_HELPER_2(xvmaxdp
, 0x00, 0x1C, 0, PPC2_VSX
)
7565 GEN_VSX_HELPER_2(xvmindp
, 0x00, 0x1D, 0, PPC2_VSX
)
7566 GEN_VSX_HELPER_2(xvcmpeqdp
, 0x0C, 0x0C, 0, PPC2_VSX
)
7567 GEN_VSX_HELPER_2(xvcmpgtdp
, 0x0C, 0x0D, 0, PPC2_VSX
)
7568 GEN_VSX_HELPER_2(xvcmpgedp
, 0x0C, 0x0E, 0, PPC2_VSX
)
7569 GEN_VSX_HELPER_2(xvcvdpsp
, 0x12, 0x18, 0, PPC2_VSX
)
7570 GEN_VSX_HELPER_2(xvcvdpsxds
, 0x10, 0x1D, 0, PPC2_VSX
)
7571 GEN_VSX_HELPER_2(xvcvdpsxws
, 0x10, 0x0D, 0, PPC2_VSX
)
7572 GEN_VSX_HELPER_2(xvcvdpuxds
, 0x10, 0x1C, 0, PPC2_VSX
)
7573 GEN_VSX_HELPER_2(xvcvdpuxws
, 0x10, 0x0C, 0, PPC2_VSX
)
7574 GEN_VSX_HELPER_2(xvcvsxddp
, 0x10, 0x1F, 0, PPC2_VSX
)
7575 GEN_VSX_HELPER_2(xvcvuxddp
, 0x10, 0x1E, 0, PPC2_VSX
)
7576 GEN_VSX_HELPER_2(xvcvsxwdp
, 0x10, 0x0F, 0, PPC2_VSX
)
7577 GEN_VSX_HELPER_2(xvcvuxwdp
, 0x10, 0x0E, 0, PPC2_VSX
)
7578 GEN_VSX_HELPER_2(xvrdpi
, 0x12, 0x0C, 0, PPC2_VSX
)
7579 GEN_VSX_HELPER_2(xvrdpic
, 0x16, 0x0E, 0, PPC2_VSX
)
7580 GEN_VSX_HELPER_2(xvrdpim
, 0x12, 0x0F, 0, PPC2_VSX
)
7581 GEN_VSX_HELPER_2(xvrdpip
, 0x12, 0x0E, 0, PPC2_VSX
)
7582 GEN_VSX_HELPER_2(xvrdpiz
, 0x12, 0x0D, 0, PPC2_VSX
)
7584 GEN_VSX_HELPER_2(xvaddsp
, 0x00, 0x08, 0, PPC2_VSX
)
7585 GEN_VSX_HELPER_2(xvsubsp
, 0x00, 0x09, 0, PPC2_VSX
)
7586 GEN_VSX_HELPER_2(xvmulsp
, 0x00, 0x0A, 0, PPC2_VSX
)
7587 GEN_VSX_HELPER_2(xvdivsp
, 0x00, 0x0B, 0, PPC2_VSX
)
7588 GEN_VSX_HELPER_2(xvresp
, 0x14, 0x09, 0, PPC2_VSX
)
7589 GEN_VSX_HELPER_2(xvsqrtsp
, 0x16, 0x08, 0, PPC2_VSX
)
7590 GEN_VSX_HELPER_2(xvrsqrtesp
, 0x14, 0x08, 0, PPC2_VSX
)
7591 GEN_VSX_HELPER_2(xvtdivsp
, 0x14, 0x0B, 0, PPC2_VSX
)
7592 GEN_VSX_HELPER_2(xvtsqrtsp
, 0x14, 0x0A, 0, PPC2_VSX
)
7593 GEN_VSX_HELPER_2(xvmaddasp
, 0x04, 0x08, 0, PPC2_VSX
)
7594 GEN_VSX_HELPER_2(xvmaddmsp
, 0x04, 0x09, 0, PPC2_VSX
)
7595 GEN_VSX_HELPER_2(xvmsubasp
, 0x04, 0x0A, 0, PPC2_VSX
)
7596 GEN_VSX_HELPER_2(xvmsubmsp
, 0x04, 0x0B, 0, PPC2_VSX
)
7597 GEN_VSX_HELPER_2(xvnmaddasp
, 0x04, 0x18, 0, PPC2_VSX
)
7598 GEN_VSX_HELPER_2(xvnmaddmsp
, 0x04, 0x19, 0, PPC2_VSX
)
7599 GEN_VSX_HELPER_2(xvnmsubasp
, 0x04, 0x1A, 0, PPC2_VSX
)
7600 GEN_VSX_HELPER_2(xvnmsubmsp
, 0x04, 0x1B, 0, PPC2_VSX
)
7601 GEN_VSX_HELPER_2(xvmaxsp
, 0x00, 0x18, 0, PPC2_VSX
)
7602 GEN_VSX_HELPER_2(xvminsp
, 0x00, 0x19, 0, PPC2_VSX
)
7603 GEN_VSX_HELPER_2(xvcmpeqsp
, 0x0C, 0x08, 0, PPC2_VSX
)
7604 GEN_VSX_HELPER_2(xvcmpgtsp
, 0x0C, 0x09, 0, PPC2_VSX
)
7605 GEN_VSX_HELPER_2(xvcmpgesp
, 0x0C, 0x0A, 0, PPC2_VSX
)
7606 GEN_VSX_HELPER_2(xvcvspdp
, 0x12, 0x1C, 0, PPC2_VSX
)
7607 GEN_VSX_HELPER_2(xvcvspsxds
, 0x10, 0x19, 0, PPC2_VSX
)
7608 GEN_VSX_HELPER_2(xvcvspsxws
, 0x10, 0x09, 0, PPC2_VSX
)
7609 GEN_VSX_HELPER_2(xvcvspuxds
, 0x10, 0x18, 0, PPC2_VSX
)
7610 GEN_VSX_HELPER_2(xvcvspuxws
, 0x10, 0x08, 0, PPC2_VSX
)
7611 GEN_VSX_HELPER_2(xvcvsxdsp
, 0x10, 0x1B, 0, PPC2_VSX
)
7612 GEN_VSX_HELPER_2(xvcvuxdsp
, 0x10, 0x1A, 0, PPC2_VSX
)
7613 GEN_VSX_HELPER_2(xvcvsxwsp
, 0x10, 0x0B, 0, PPC2_VSX
)
7614 GEN_VSX_HELPER_2(xvcvuxwsp
, 0x10, 0x0A, 0, PPC2_VSX
)
7615 GEN_VSX_HELPER_2(xvrspi
, 0x12, 0x08, 0, PPC2_VSX
)
7616 GEN_VSX_HELPER_2(xvrspic
, 0x16, 0x0A, 0, PPC2_VSX
)
7617 GEN_VSX_HELPER_2(xvrspim
, 0x12, 0x0B, 0, PPC2_VSX
)
7618 GEN_VSX_HELPER_2(xvrspip
, 0x12, 0x0A, 0, PPC2_VSX
)
7619 GEN_VSX_HELPER_2(xvrspiz
, 0x12, 0x09, 0, PPC2_VSX
)
7621 #define VSX_LOGICAL(name, tcg_op) \
7622 static void glue(gen_, name)(DisasContext * ctx) \
7624 if (unlikely(!ctx->vsx_enabled)) { \
7625 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7628 tcg_op(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)), \
7629 cpu_vsrh(xB(ctx->opcode))); \
7630 tcg_op(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)), \
7631 cpu_vsrl(xB(ctx->opcode))); \
7634 VSX_LOGICAL(xxland
, tcg_gen_and_i64
)
7635 VSX_LOGICAL(xxlandc
, tcg_gen_andc_i64
)
7636 VSX_LOGICAL(xxlor
, tcg_gen_or_i64
)
7637 VSX_LOGICAL(xxlxor
, tcg_gen_xor_i64
)
7638 VSX_LOGICAL(xxlnor
, tcg_gen_nor_i64
)
7639 VSX_LOGICAL(xxleqv
, tcg_gen_eqv_i64
)
7640 VSX_LOGICAL(xxlnand
, tcg_gen_nand_i64
)
7641 VSX_LOGICAL(xxlorc
, tcg_gen_orc_i64
)
7643 #define VSX_XXMRG(name, high) \
7644 static void glue(gen_, name)(DisasContext * ctx) \
7646 TCGv_i64 a0, a1, b0, b1; \
7647 if (unlikely(!ctx->vsx_enabled)) { \
7648 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7651 a0 = tcg_temp_new_i64(); \
7652 a1 = tcg_temp_new_i64(); \
7653 b0 = tcg_temp_new_i64(); \
7654 b1 = tcg_temp_new_i64(); \
7656 tcg_gen_mov_i64(a0, cpu_vsrh(xA(ctx->opcode))); \
7657 tcg_gen_mov_i64(a1, cpu_vsrh(xA(ctx->opcode))); \
7658 tcg_gen_mov_i64(b0, cpu_vsrh(xB(ctx->opcode))); \
7659 tcg_gen_mov_i64(b1, cpu_vsrh(xB(ctx->opcode))); \
7661 tcg_gen_mov_i64(a0, cpu_vsrl(xA(ctx->opcode))); \
7662 tcg_gen_mov_i64(a1, cpu_vsrl(xA(ctx->opcode))); \
7663 tcg_gen_mov_i64(b0, cpu_vsrl(xB(ctx->opcode))); \
7664 tcg_gen_mov_i64(b1, cpu_vsrl(xB(ctx->opcode))); \
7666 tcg_gen_shri_i64(a0, a0, 32); \
7667 tcg_gen_shri_i64(b0, b0, 32); \
7668 tcg_gen_deposit_i64(cpu_vsrh(xT(ctx->opcode)), \
7670 tcg_gen_deposit_i64(cpu_vsrl(xT(ctx->opcode)), \
7672 tcg_temp_free_i64(a0); \
7673 tcg_temp_free_i64(a1); \
7674 tcg_temp_free_i64(b0); \
7675 tcg_temp_free_i64(b1); \
7678 VSX_XXMRG(xxmrghw
, 1)
7679 VSX_XXMRG(xxmrglw
, 0)
7681 static void gen_xxsel(DisasContext
* ctx
)
7684 if (unlikely(!ctx
->vsx_enabled
)) {
7685 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7688 a
= tcg_temp_new_i64();
7689 b
= tcg_temp_new_i64();
7690 c
= tcg_temp_new_i64();
7692 tcg_gen_mov_i64(a
, cpu_vsrh(xA(ctx
->opcode
)));
7693 tcg_gen_mov_i64(b
, cpu_vsrh(xB(ctx
->opcode
)));
7694 tcg_gen_mov_i64(c
, cpu_vsrh(xC(ctx
->opcode
)));
7696 tcg_gen_and_i64(b
, b
, c
);
7697 tcg_gen_andc_i64(a
, a
, c
);
7698 tcg_gen_or_i64(cpu_vsrh(xT(ctx
->opcode
)), a
, b
);
7700 tcg_gen_mov_i64(a
, cpu_vsrl(xA(ctx
->opcode
)));
7701 tcg_gen_mov_i64(b
, cpu_vsrl(xB(ctx
->opcode
)));
7702 tcg_gen_mov_i64(c
, cpu_vsrl(xC(ctx
->opcode
)));
7704 tcg_gen_and_i64(b
, b
, c
);
7705 tcg_gen_andc_i64(a
, a
, c
);
7706 tcg_gen_or_i64(cpu_vsrl(xT(ctx
->opcode
)), a
, b
);
7708 tcg_temp_free_i64(a
);
7709 tcg_temp_free_i64(b
);
7710 tcg_temp_free_i64(c
);
7713 static void gen_xxspltw(DisasContext
*ctx
)
7716 TCGv_i64 vsr
= (UIM(ctx
->opcode
) & 2) ?
7717 cpu_vsrl(xB(ctx
->opcode
)) :
7718 cpu_vsrh(xB(ctx
->opcode
));
7720 if (unlikely(!ctx
->vsx_enabled
)) {
7721 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7725 b
= tcg_temp_new_i64();
7726 b2
= tcg_temp_new_i64();
7728 if (UIM(ctx
->opcode
) & 1) {
7729 tcg_gen_ext32u_i64(b
, vsr
);
7731 tcg_gen_shri_i64(b
, vsr
, 32);
7734 tcg_gen_shli_i64(b2
, b
, 32);
7735 tcg_gen_or_i64(cpu_vsrh(xT(ctx
->opcode
)), b
, b2
);
7736 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), cpu_vsrh(xT(ctx
->opcode
)));
7738 tcg_temp_free_i64(b
);
7739 tcg_temp_free_i64(b2
);
7742 static void gen_xxsldwi(DisasContext
*ctx
)
7745 if (unlikely(!ctx
->vsx_enabled
)) {
7746 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7749 xth
= tcg_temp_new_i64();
7750 xtl
= tcg_temp_new_i64();
7752 switch (SHW(ctx
->opcode
)) {
7754 tcg_gen_mov_i64(xth
, cpu_vsrh(xA(ctx
->opcode
)));
7755 tcg_gen_mov_i64(xtl
, cpu_vsrl(xA(ctx
->opcode
)));
7759 TCGv_i64 t0
= tcg_temp_new_i64();
7760 tcg_gen_mov_i64(xth
, cpu_vsrh(xA(ctx
->opcode
)));
7761 tcg_gen_shli_i64(xth
, xth
, 32);
7762 tcg_gen_mov_i64(t0
, cpu_vsrl(xA(ctx
->opcode
)));
7763 tcg_gen_shri_i64(t0
, t0
, 32);
7764 tcg_gen_or_i64(xth
, xth
, t0
);
7765 tcg_gen_mov_i64(xtl
, cpu_vsrl(xA(ctx
->opcode
)));
7766 tcg_gen_shli_i64(xtl
, xtl
, 32);
7767 tcg_gen_mov_i64(t0
, cpu_vsrh(xB(ctx
->opcode
)));
7768 tcg_gen_shri_i64(t0
, t0
, 32);
7769 tcg_gen_or_i64(xtl
, xtl
, t0
);
7770 tcg_temp_free_i64(t0
);
7774 tcg_gen_mov_i64(xth
, cpu_vsrl(xA(ctx
->opcode
)));
7775 tcg_gen_mov_i64(xtl
, cpu_vsrh(xB(ctx
->opcode
)));
7779 TCGv_i64 t0
= tcg_temp_new_i64();
7780 tcg_gen_mov_i64(xth
, cpu_vsrl(xA(ctx
->opcode
)));
7781 tcg_gen_shli_i64(xth
, xth
, 32);
7782 tcg_gen_mov_i64(t0
, cpu_vsrh(xB(ctx
->opcode
)));
7783 tcg_gen_shri_i64(t0
, t0
, 32);
7784 tcg_gen_or_i64(xth
, xth
, t0
);
7785 tcg_gen_mov_i64(xtl
, cpu_vsrh(xB(ctx
->opcode
)));
7786 tcg_gen_shli_i64(xtl
, xtl
, 32);
7787 tcg_gen_mov_i64(t0
, cpu_vsrl(xB(ctx
->opcode
)));
7788 tcg_gen_shri_i64(t0
, t0
, 32);
7789 tcg_gen_or_i64(xtl
, xtl
, t0
);
7790 tcg_temp_free_i64(t0
);
7795 tcg_gen_mov_i64(cpu_vsrh(xT(ctx
->opcode
)), xth
);
7796 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), xtl
);
7798 tcg_temp_free_i64(xth
);
7799 tcg_temp_free_i64(xtl
);
7803 /*** SPE extension ***/
7804 /* Register moves */
7806 static inline void gen_evmra(DisasContext
*ctx
)
7809 if (unlikely(!ctx
->spe_enabled
)) {
7810 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7814 #if defined(TARGET_PPC64)
7816 tcg_gen_mov_i64(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7819 tcg_gen_st_i64(cpu_gpr
[rA(ctx
->opcode
)],
7821 offsetof(CPUPPCState
, spe_acc
));
7823 TCGv_i64 tmp
= tcg_temp_new_i64();
7825 /* tmp := rA_lo + rA_hi << 32 */
7826 tcg_gen_concat_i32_i64(tmp
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7828 /* spe_acc := tmp */
7829 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7830 tcg_temp_free_i64(tmp
);
7833 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7834 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7838 static inline void gen_load_gpr64(TCGv_i64 t
, int reg
)
7840 #if defined(TARGET_PPC64)
7841 tcg_gen_mov_i64(t
, cpu_gpr
[reg
]);
7843 tcg_gen_concat_i32_i64(t
, cpu_gpr
[reg
], cpu_gprh
[reg
]);
7847 static inline void gen_store_gpr64(int reg
, TCGv_i64 t
)
7849 #if defined(TARGET_PPC64)
7850 tcg_gen_mov_i64(cpu_gpr
[reg
], t
);
7852 TCGv_i64 tmp
= tcg_temp_new_i64();
7853 tcg_gen_trunc_i64_i32(cpu_gpr
[reg
], t
);
7854 tcg_gen_shri_i64(tmp
, t
, 32);
7855 tcg_gen_trunc_i64_i32(cpu_gprh
[reg
], tmp
);
7856 tcg_temp_free_i64(tmp
);
7860 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
7861 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7863 if (Rc(ctx->opcode)) \
7869 /* Handler for undefined SPE opcodes */
7870 static inline void gen_speundef(DisasContext
*ctx
)
7872 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
7876 #if defined(TARGET_PPC64)
7877 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
7878 static inline void gen_##name(DisasContext *ctx) \
7880 if (unlikely(!ctx->spe_enabled)) { \
7881 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7884 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7885 cpu_gpr[rB(ctx->opcode)]); \
7888 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
7889 static inline void gen_##name(DisasContext *ctx) \
7891 if (unlikely(!ctx->spe_enabled)) { \
7892 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7895 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7896 cpu_gpr[rB(ctx->opcode)]); \
7897 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7898 cpu_gprh[rB(ctx->opcode)]); \
7902 GEN_SPEOP_LOGIC2(evand
, tcg_gen_and_tl
);
7903 GEN_SPEOP_LOGIC2(evandc
, tcg_gen_andc_tl
);
7904 GEN_SPEOP_LOGIC2(evxor
, tcg_gen_xor_tl
);
7905 GEN_SPEOP_LOGIC2(evor
, tcg_gen_or_tl
);
7906 GEN_SPEOP_LOGIC2(evnor
, tcg_gen_nor_tl
);
7907 GEN_SPEOP_LOGIC2(eveqv
, tcg_gen_eqv_tl
);
7908 GEN_SPEOP_LOGIC2(evorc
, tcg_gen_orc_tl
);
7909 GEN_SPEOP_LOGIC2(evnand
, tcg_gen_nand_tl
);
7911 /* SPE logic immediate */
7912 #if defined(TARGET_PPC64)
7913 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
7914 static inline void gen_##name(DisasContext *ctx) \
7916 if (unlikely(!ctx->spe_enabled)) { \
7917 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7920 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7921 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7922 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7923 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7924 tcg_opi(t0, t0, rB(ctx->opcode)); \
7925 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7926 tcg_gen_trunc_i64_i32(t1, t2); \
7927 tcg_temp_free_i64(t2); \
7928 tcg_opi(t1, t1, rB(ctx->opcode)); \
7929 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7930 tcg_temp_free_i32(t0); \
7931 tcg_temp_free_i32(t1); \
7934 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
7935 static inline void gen_##name(DisasContext *ctx) \
7937 if (unlikely(!ctx->spe_enabled)) { \
7938 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7941 tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7943 tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7947 GEN_SPEOP_TCG_LOGIC_IMM2(evslwi
, tcg_gen_shli_i32
);
7948 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu
, tcg_gen_shri_i32
);
7949 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis
, tcg_gen_sari_i32
);
7950 GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi
, tcg_gen_rotli_i32
);
7952 /* SPE arithmetic */
7953 #if defined(TARGET_PPC64)
7954 #define GEN_SPEOP_ARITH1(name, tcg_op) \
7955 static inline void gen_##name(DisasContext *ctx) \
7957 if (unlikely(!ctx->spe_enabled)) { \
7958 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7961 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7962 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7963 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7964 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7966 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7967 tcg_gen_trunc_i64_i32(t1, t2); \
7968 tcg_temp_free_i64(t2); \
7970 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7971 tcg_temp_free_i32(t0); \
7972 tcg_temp_free_i32(t1); \
7975 #define GEN_SPEOP_ARITH1(name, tcg_op) \
7976 static inline void gen_##name(DisasContext *ctx) \
7978 if (unlikely(!ctx->spe_enabled)) { \
7979 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7982 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
7983 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
7987 static inline void gen_op_evabs(TCGv_i32 ret
, TCGv_i32 arg1
)
7989 int l1
= gen_new_label();
7990 int l2
= gen_new_label();
7992 tcg_gen_brcondi_i32(TCG_COND_GE
, arg1
, 0, l1
);
7993 tcg_gen_neg_i32(ret
, arg1
);
7996 tcg_gen_mov_i32(ret
, arg1
);
7999 GEN_SPEOP_ARITH1(evabs
, gen_op_evabs
);
8000 GEN_SPEOP_ARITH1(evneg
, tcg_gen_neg_i32
);
8001 GEN_SPEOP_ARITH1(evextsb
, tcg_gen_ext8s_i32
);
8002 GEN_SPEOP_ARITH1(evextsh
, tcg_gen_ext16s_i32
);
8003 static inline void gen_op_evrndw(TCGv_i32 ret
, TCGv_i32 arg1
)
8005 tcg_gen_addi_i32(ret
, arg1
, 0x8000);
8006 tcg_gen_ext16u_i32(ret
, ret
);
8008 GEN_SPEOP_ARITH1(evrndw
, gen_op_evrndw
);
8009 GEN_SPEOP_ARITH1(evcntlsw
, gen_helper_cntlsw32
);
8010 GEN_SPEOP_ARITH1(evcntlzw
, gen_helper_cntlzw32
);
8012 #if defined(TARGET_PPC64)
8013 #define GEN_SPEOP_ARITH2(name, tcg_op) \
8014 static inline void gen_##name(DisasContext *ctx) \
8016 if (unlikely(!ctx->spe_enabled)) { \
8017 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8020 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8021 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8022 TCGv_i32 t2 = tcg_temp_local_new_i32(); \
8023 TCGv_i64 t3 = tcg_temp_local_new_i64(); \
8024 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8025 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
8026 tcg_op(t0, t0, t2); \
8027 tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
8028 tcg_gen_trunc_i64_i32(t1, t3); \
8029 tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
8030 tcg_gen_trunc_i64_i32(t2, t3); \
8031 tcg_temp_free_i64(t3); \
8032 tcg_op(t1, t1, t2); \
8033 tcg_temp_free_i32(t2); \
8034 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
8035 tcg_temp_free_i32(t0); \
8036 tcg_temp_free_i32(t1); \
8039 #define GEN_SPEOP_ARITH2(name, tcg_op) \
8040 static inline void gen_##name(DisasContext *ctx) \
8042 if (unlikely(!ctx->spe_enabled)) { \
8043 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8046 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8047 cpu_gpr[rB(ctx->opcode)]); \
8048 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8049 cpu_gprh[rB(ctx->opcode)]); \
8053 static inline void gen_op_evsrwu(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
8058 l1
= gen_new_label();
8059 l2
= gen_new_label();
8060 t0
= tcg_temp_local_new_i32();
8061 /* No error here: 6 bits are used */
8062 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
8063 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
8064 tcg_gen_shr_i32(ret
, arg1
, t0
);
8067 tcg_gen_movi_i32(ret
, 0);
8069 tcg_temp_free_i32(t0
);
8071 GEN_SPEOP_ARITH2(evsrwu
, gen_op_evsrwu
);
8072 static inline void gen_op_evsrws(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
8077 l1
= gen_new_label();
8078 l2
= gen_new_label();
8079 t0
= tcg_temp_local_new_i32();
8080 /* No error here: 6 bits are used */
8081 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
8082 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
8083 tcg_gen_sar_i32(ret
, arg1
, t0
);
8086 tcg_gen_movi_i32(ret
, 0);
8088 tcg_temp_free_i32(t0
);
8090 GEN_SPEOP_ARITH2(evsrws
, gen_op_evsrws
);
8091 static inline void gen_op_evslw(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
8096 l1
= gen_new_label();
8097 l2
= gen_new_label();
8098 t0
= tcg_temp_local_new_i32();
8099 /* No error here: 6 bits are used */
8100 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
8101 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
8102 tcg_gen_shl_i32(ret
, arg1
, t0
);
8105 tcg_gen_movi_i32(ret
, 0);
8107 tcg_temp_free_i32(t0
);
8109 GEN_SPEOP_ARITH2(evslw
, gen_op_evslw
);
8110 static inline void gen_op_evrlw(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
8112 TCGv_i32 t0
= tcg_temp_new_i32();
8113 tcg_gen_andi_i32(t0
, arg2
, 0x1F);
8114 tcg_gen_rotl_i32(ret
, arg1
, t0
);
8115 tcg_temp_free_i32(t0
);
8117 GEN_SPEOP_ARITH2(evrlw
, gen_op_evrlw
);
8118 static inline void gen_evmergehi(DisasContext
*ctx
)
8120 if (unlikely(!ctx
->spe_enabled
)) {
8121 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8124 #if defined(TARGET_PPC64)
8125 TCGv t0
= tcg_temp_new();
8126 TCGv t1
= tcg_temp_new();
8127 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
8128 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
8129 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
8133 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
8134 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
8137 GEN_SPEOP_ARITH2(evaddw
, tcg_gen_add_i32
);
8138 static inline void gen_op_evsubf(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
8140 tcg_gen_sub_i32(ret
, arg2
, arg1
);
8142 GEN_SPEOP_ARITH2(evsubfw
, gen_op_evsubf
);
8144 /* SPE arithmetic immediate */
8145 #if defined(TARGET_PPC64)
8146 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
8147 static inline void gen_##name(DisasContext *ctx) \
8149 if (unlikely(!ctx->spe_enabled)) { \
8150 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8153 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8154 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8155 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
8156 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8157 tcg_op(t0, t0, rA(ctx->opcode)); \
8158 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
8159 tcg_gen_trunc_i64_i32(t1, t2); \
8160 tcg_temp_free_i64(t2); \
8161 tcg_op(t1, t1, rA(ctx->opcode)); \
8162 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
8163 tcg_temp_free_i32(t0); \
8164 tcg_temp_free_i32(t1); \
8167 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
8168 static inline void gen_##name(DisasContext *ctx) \
8170 if (unlikely(!ctx->spe_enabled)) { \
8171 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8174 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
8176 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
8180 GEN_SPEOP_ARITH_IMM2(evaddiw
, tcg_gen_addi_i32
);
8181 GEN_SPEOP_ARITH_IMM2(evsubifw
, tcg_gen_subi_i32
);
8183 /* SPE comparison */
8184 #if defined(TARGET_PPC64)
8185 #define GEN_SPEOP_COMP(name, tcg_cond) \
8186 static inline void gen_##name(DisasContext *ctx) \
8188 if (unlikely(!ctx->spe_enabled)) { \
8189 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8192 int l1 = gen_new_label(); \
8193 int l2 = gen_new_label(); \
8194 int l3 = gen_new_label(); \
8195 int l4 = gen_new_label(); \
8196 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
8197 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
8198 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
8199 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8200 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8201 tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
8202 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
8204 gen_set_label(l1); \
8205 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8206 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8207 gen_set_label(l2); \
8208 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
8209 tcg_gen_trunc_i64_i32(t0, t2); \
8210 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
8211 tcg_gen_trunc_i64_i32(t1, t2); \
8212 tcg_temp_free_i64(t2); \
8213 tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
8214 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8215 ~(CRF_CH | CRF_CH_AND_CL)); \
8217 gen_set_label(l3); \
8218 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8219 CRF_CH | CRF_CH_OR_CL); \
8220 gen_set_label(l4); \
8221 tcg_temp_free_i32(t0); \
8222 tcg_temp_free_i32(t1); \
8225 #define GEN_SPEOP_COMP(name, tcg_cond) \
8226 static inline void gen_##name(DisasContext *ctx) \
8228 if (unlikely(!ctx->spe_enabled)) { \
8229 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8232 int l1 = gen_new_label(); \
8233 int l2 = gen_new_label(); \
8234 int l3 = gen_new_label(); \
8235 int l4 = gen_new_label(); \
8237 tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
8238 cpu_gpr[rB(ctx->opcode)], l1); \
8239 tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
8241 gen_set_label(l1); \
8242 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
8243 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
8244 gen_set_label(l2); \
8245 tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
8246 cpu_gprh[rB(ctx->opcode)], l3); \
8247 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8248 ~(CRF_CH | CRF_CH_AND_CL)); \
8250 gen_set_label(l3); \
8251 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
8252 CRF_CH | CRF_CH_OR_CL); \
8253 gen_set_label(l4); \
8256 GEN_SPEOP_COMP(evcmpgtu
, TCG_COND_GTU
);
8257 GEN_SPEOP_COMP(evcmpgts
, TCG_COND_GT
);
8258 GEN_SPEOP_COMP(evcmpltu
, TCG_COND_LTU
);
8259 GEN_SPEOP_COMP(evcmplts
, TCG_COND_LT
);
8260 GEN_SPEOP_COMP(evcmpeq
, TCG_COND_EQ
);
8263 static inline void gen_brinc(DisasContext
*ctx
)
8265 /* Note: brinc is usable even if SPE is disabled */
8266 gen_helper_brinc(cpu_gpr
[rD(ctx
->opcode
)],
8267 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
8269 static inline void gen_evmergelo(DisasContext
*ctx
)
8271 if (unlikely(!ctx
->spe_enabled
)) {
8272 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8275 #if defined(TARGET_PPC64)
8276 TCGv t0
= tcg_temp_new();
8277 TCGv t1
= tcg_temp_new();
8278 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
8279 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
8280 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
8284 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8285 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
8288 static inline void gen_evmergehilo(DisasContext
*ctx
)
8290 if (unlikely(!ctx
->spe_enabled
)) {
8291 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8294 #if defined(TARGET_PPC64)
8295 TCGv t0
= tcg_temp_new();
8296 TCGv t1
= tcg_temp_new();
8297 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
8298 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
8299 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
8303 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
8304 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
8307 static inline void gen_evmergelohi(DisasContext
*ctx
)
8309 if (unlikely(!ctx
->spe_enabled
)) {
8310 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8313 #if defined(TARGET_PPC64)
8314 TCGv t0
= tcg_temp_new();
8315 TCGv t1
= tcg_temp_new();
8316 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
8317 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
8318 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
8322 if (rD(ctx
->opcode
) == rA(ctx
->opcode
)) {
8323 TCGv_i32 tmp
= tcg_temp_new_i32();
8324 tcg_gen_mov_i32(tmp
, cpu_gpr
[rA(ctx
->opcode
)]);
8325 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
8326 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], tmp
);
8327 tcg_temp_free_i32(tmp
);
8329 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
8330 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8334 static inline void gen_evsplati(DisasContext
*ctx
)
8336 uint64_t imm
= ((int32_t)(rA(ctx
->opcode
) << 27)) >> 27;
8338 #if defined(TARGET_PPC64)
8339 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
8341 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
8342 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
8345 static inline void gen_evsplatfi(DisasContext
*ctx
)
8347 uint64_t imm
= rA(ctx
->opcode
) << 27;
8349 #if defined(TARGET_PPC64)
8350 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
8352 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
8353 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
8357 static inline void gen_evsel(DisasContext
*ctx
)
8359 int l1
= gen_new_label();
8360 int l2
= gen_new_label();
8361 int l3
= gen_new_label();
8362 int l4
= gen_new_label();
8363 TCGv_i32 t0
= tcg_temp_local_new_i32();
8364 #if defined(TARGET_PPC64)
8365 TCGv t1
= tcg_temp_local_new();
8366 TCGv t2
= tcg_temp_local_new();
8368 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 3);
8369 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
8370 #if defined(TARGET_PPC64)
8371 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
8373 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
8377 #if defined(TARGET_PPC64)
8378 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
8380 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
8383 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 2);
8384 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l3
);
8385 #if defined(TARGET_PPC64)
8386 tcg_gen_ext32u_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)]);
8388 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8392 #if defined(TARGET_PPC64)
8393 tcg_gen_ext32u_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)]);
8395 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
8398 tcg_temp_free_i32(t0
);
8399 #if defined(TARGET_PPC64)
8400 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
, t2
);
8406 static void gen_evsel0(DisasContext
*ctx
)
8411 static void gen_evsel1(DisasContext
*ctx
)
8416 static void gen_evsel2(DisasContext
*ctx
)
8421 static void gen_evsel3(DisasContext
*ctx
)
8428 static inline void gen_evmwumi(DisasContext
*ctx
)
8432 if (unlikely(!ctx
->spe_enabled
)) {
8433 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8437 t0
= tcg_temp_new_i64();
8438 t1
= tcg_temp_new_i64();
8440 /* t0 := rA; t1 := rB */
8441 #if defined(TARGET_PPC64)
8442 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
8443 tcg_gen_ext32u_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
8445 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
8446 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
8449 tcg_gen_mul_i64(t0
, t0
, t1
); /* t0 := rA * rB */
8451 gen_store_gpr64(rD(ctx
->opcode
), t0
); /* rD := t0 */
8453 tcg_temp_free_i64(t0
);
8454 tcg_temp_free_i64(t1
);
8457 static inline void gen_evmwumia(DisasContext
*ctx
)
8461 if (unlikely(!ctx
->spe_enabled
)) {
8462 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8466 gen_evmwumi(ctx
); /* rD := rA * rB */
8468 tmp
= tcg_temp_new_i64();
8471 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
8472 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8473 tcg_temp_free_i64(tmp
);
8476 static inline void gen_evmwumiaa(DisasContext
*ctx
)
8481 if (unlikely(!ctx
->spe_enabled
)) {
8482 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8486 gen_evmwumi(ctx
); /* rD := rA * rB */
8488 acc
= tcg_temp_new_i64();
8489 tmp
= tcg_temp_new_i64();
8492 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
8495 tcg_gen_ld_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8497 /* acc := tmp + acc */
8498 tcg_gen_add_i64(acc
, acc
, tmp
);
8501 tcg_gen_st_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8504 gen_store_gpr64(rD(ctx
->opcode
), acc
);
8506 tcg_temp_free_i64(acc
);
8507 tcg_temp_free_i64(tmp
);
8510 static inline void gen_evmwsmi(DisasContext
*ctx
)
8514 if (unlikely(!ctx
->spe_enabled
)) {
8515 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8519 t0
= tcg_temp_new_i64();
8520 t1
= tcg_temp_new_i64();
8522 /* t0 := rA; t1 := rB */
8523 #if defined(TARGET_PPC64)
8524 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
8525 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
8527 tcg_gen_ext_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
8528 tcg_gen_ext_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
8531 tcg_gen_mul_i64(t0
, t0
, t1
); /* t0 := rA * rB */
8533 gen_store_gpr64(rD(ctx
->opcode
), t0
); /* rD := t0 */
8535 tcg_temp_free_i64(t0
);
8536 tcg_temp_free_i64(t1
);
8539 static inline void gen_evmwsmia(DisasContext
*ctx
)
8543 gen_evmwsmi(ctx
); /* rD := rA * rB */
8545 tmp
= tcg_temp_new_i64();
8548 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
8549 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8551 tcg_temp_free_i64(tmp
);
8554 static inline void gen_evmwsmiaa(DisasContext
*ctx
)
8556 TCGv_i64 acc
= tcg_temp_new_i64();
8557 TCGv_i64 tmp
= tcg_temp_new_i64();
8559 gen_evmwsmi(ctx
); /* rD := rA * rB */
8561 acc
= tcg_temp_new_i64();
8562 tmp
= tcg_temp_new_i64();
8565 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
8568 tcg_gen_ld_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8570 /* acc := tmp + acc */
8571 tcg_gen_add_i64(acc
, acc
, tmp
);
8574 tcg_gen_st_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8577 gen_store_gpr64(rD(ctx
->opcode
), acc
);
8579 tcg_temp_free_i64(acc
);
8580 tcg_temp_free_i64(tmp
);
8583 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
8584 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
8585 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
8586 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
8587 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
8588 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
8589 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
8590 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE
); //
8591 GEN_SPE(evmra
, speundef
, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE
);
8592 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
); ////
8593 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
8594 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
8595 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
8596 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
8597 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
8598 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
8599 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
); ////
8600 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
8601 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
8602 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE
);
8603 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
8604 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
8605 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE
); //
8606 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE
);
8607 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
8608 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
8609 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE
); ////
8610 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE
); ////
8611 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE
); ////
8613 /* SPE load and stores */
8614 static inline void gen_addr_spe_imm_index(DisasContext
*ctx
, TCGv EA
, int sh
)
8616 target_ulong uimm
= rB(ctx
->opcode
);
8618 if (rA(ctx
->opcode
) == 0) {
8619 tcg_gen_movi_tl(EA
, uimm
<< sh
);
8621 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], uimm
<< sh
);
8622 if (NARROW_MODE(ctx
)) {
8623 tcg_gen_ext32u_tl(EA
, EA
);
8628 static inline void gen_op_evldd(DisasContext
*ctx
, TCGv addr
)
8630 #if defined(TARGET_PPC64)
8631 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
8633 TCGv_i64 t0
= tcg_temp_new_i64();
8634 gen_qemu_ld64(ctx
, t0
, addr
);
8635 tcg_gen_trunc_i64_i32(cpu_gpr
[rD(ctx
->opcode
)], t0
);
8636 tcg_gen_shri_i64(t0
, t0
, 32);
8637 tcg_gen_trunc_i64_i32(cpu_gprh
[rD(ctx
->opcode
)], t0
);
8638 tcg_temp_free_i64(t0
);
8642 static inline void gen_op_evldw(DisasContext
*ctx
, TCGv addr
)
8644 #if defined(TARGET_PPC64)
8645 TCGv t0
= tcg_temp_new();
8646 gen_qemu_ld32u(ctx
, t0
, addr
);
8647 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
8648 gen_addr_add(ctx
, addr
, addr
, 4);
8649 gen_qemu_ld32u(ctx
, t0
, addr
);
8650 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8653 gen_qemu_ld32u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
8654 gen_addr_add(ctx
, addr
, addr
, 4);
8655 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
8659 static inline void gen_op_evldh(DisasContext
*ctx
, TCGv addr
)
8661 TCGv t0
= tcg_temp_new();
8662 #if defined(TARGET_PPC64)
8663 gen_qemu_ld16u(ctx
, t0
, addr
);
8664 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
8665 gen_addr_add(ctx
, addr
, addr
, 2);
8666 gen_qemu_ld16u(ctx
, t0
, addr
);
8667 tcg_gen_shli_tl(t0
, t0
, 32);
8668 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8669 gen_addr_add(ctx
, addr
, addr
, 2);
8670 gen_qemu_ld16u(ctx
, t0
, addr
);
8671 tcg_gen_shli_tl(t0
, t0
, 16);
8672 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8673 gen_addr_add(ctx
, addr
, addr
, 2);
8674 gen_qemu_ld16u(ctx
, t0
, addr
);
8675 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8677 gen_qemu_ld16u(ctx
, t0
, addr
);
8678 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
8679 gen_addr_add(ctx
, addr
, addr
, 2);
8680 gen_qemu_ld16u(ctx
, t0
, addr
);
8681 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
8682 gen_addr_add(ctx
, addr
, addr
, 2);
8683 gen_qemu_ld16u(ctx
, t0
, addr
);
8684 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
8685 gen_addr_add(ctx
, addr
, addr
, 2);
8686 gen_qemu_ld16u(ctx
, t0
, addr
);
8687 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8692 static inline void gen_op_evlhhesplat(DisasContext
*ctx
, TCGv addr
)
8694 TCGv t0
= tcg_temp_new();
8695 gen_qemu_ld16u(ctx
, t0
, addr
);
8696 #if defined(TARGET_PPC64)
8697 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
8698 tcg_gen_shli_tl(t0
, t0
, 16);
8699 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8701 tcg_gen_shli_tl(t0
, t0
, 16);
8702 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
8703 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
8708 static inline void gen_op_evlhhousplat(DisasContext
*ctx
, TCGv addr
)
8710 TCGv t0
= tcg_temp_new();
8711 gen_qemu_ld16u(ctx
, t0
, addr
);
8712 #if defined(TARGET_PPC64)
8713 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
8714 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8716 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
8717 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
8722 static inline void gen_op_evlhhossplat(DisasContext
*ctx
, TCGv addr
)
8724 TCGv t0
= tcg_temp_new();
8725 gen_qemu_ld16s(ctx
, t0
, addr
);
8726 #if defined(TARGET_PPC64)
8727 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
8728 tcg_gen_ext32u_tl(t0
, t0
);
8729 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8731 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
8732 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
8737 static inline void gen_op_evlwhe(DisasContext
*ctx
, TCGv addr
)
8739 TCGv t0
= tcg_temp_new();
8740 #if defined(TARGET_PPC64)
8741 gen_qemu_ld16u(ctx
, t0
, addr
);
8742 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
8743 gen_addr_add(ctx
, addr
, addr
, 2);
8744 gen_qemu_ld16u(ctx
, t0
, addr
);
8745 tcg_gen_shli_tl(t0
, t0
, 16);
8746 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8748 gen_qemu_ld16u(ctx
, t0
, addr
);
8749 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
8750 gen_addr_add(ctx
, addr
, addr
, 2);
8751 gen_qemu_ld16u(ctx
, t0
, addr
);
8752 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
8757 static inline void gen_op_evlwhou(DisasContext
*ctx
, TCGv addr
)
8759 #if defined(TARGET_PPC64)
8760 TCGv t0
= tcg_temp_new();
8761 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
8762 gen_addr_add(ctx
, addr
, addr
, 2);
8763 gen_qemu_ld16u(ctx
, t0
, addr
);
8764 tcg_gen_shli_tl(t0
, t0
, 32);
8765 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8768 gen_qemu_ld16u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
8769 gen_addr_add(ctx
, addr
, addr
, 2);
8770 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
8774 static inline void gen_op_evlwhos(DisasContext
*ctx
, TCGv addr
)
8776 #if defined(TARGET_PPC64)
8777 TCGv t0
= tcg_temp_new();
8778 gen_qemu_ld16s(ctx
, t0
, addr
);
8779 tcg_gen_ext32u_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
8780 gen_addr_add(ctx
, addr
, addr
, 2);
8781 gen_qemu_ld16s(ctx
, t0
, addr
);
8782 tcg_gen_shli_tl(t0
, t0
, 32);
8783 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8786 gen_qemu_ld16s(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
8787 gen_addr_add(ctx
, addr
, addr
, 2);
8788 gen_qemu_ld16s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
8792 static inline void gen_op_evlwwsplat(DisasContext
*ctx
, TCGv addr
)
8794 TCGv t0
= tcg_temp_new();
8795 gen_qemu_ld32u(ctx
, t0
, addr
);
8796 #if defined(TARGET_PPC64)
8797 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
8798 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8800 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
8801 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
8806 static inline void gen_op_evlwhsplat(DisasContext
*ctx
, TCGv addr
)
8808 TCGv t0
= tcg_temp_new();
8809 #if defined(TARGET_PPC64)
8810 gen_qemu_ld16u(ctx
, t0
, addr
);
8811 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
8812 tcg_gen_shli_tl(t0
, t0
, 32);
8813 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8814 gen_addr_add(ctx
, addr
, addr
, 2);
8815 gen_qemu_ld16u(ctx
, t0
, addr
);
8816 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8817 tcg_gen_shli_tl(t0
, t0
, 16);
8818 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
8820 gen_qemu_ld16u(ctx
, t0
, addr
);
8821 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
8822 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
8823 gen_addr_add(ctx
, addr
, addr
, 2);
8824 gen_qemu_ld16u(ctx
, t0
, addr
);
8825 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
8826 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
8831 static inline void gen_op_evstdd(DisasContext
*ctx
, TCGv addr
)
8833 #if defined(TARGET_PPC64)
8834 gen_qemu_st64(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
8836 TCGv_i64 t0
= tcg_temp_new_i64();
8837 tcg_gen_concat_i32_i64(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gprh
[rS(ctx
->opcode
)]);
8838 gen_qemu_st64(ctx
, t0
, addr
);
8839 tcg_temp_free_i64(t0
);
8843 static inline void gen_op_evstdw(DisasContext
*ctx
, TCGv addr
)
8845 #if defined(TARGET_PPC64)
8846 TCGv t0
= tcg_temp_new();
8847 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
8848 gen_qemu_st32(ctx
, t0
, addr
);
8851 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
8853 gen_addr_add(ctx
, addr
, addr
, 4);
8854 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
8857 static inline void gen_op_evstdh(DisasContext
*ctx
, TCGv addr
)
8859 TCGv t0
= tcg_temp_new();
8860 #if defined(TARGET_PPC64)
8861 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
8863 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
8865 gen_qemu_st16(ctx
, t0
, addr
);
8866 gen_addr_add(ctx
, addr
, addr
, 2);
8867 #if defined(TARGET_PPC64)
8868 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
8869 gen_qemu_st16(ctx
, t0
, addr
);
8871 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
8873 gen_addr_add(ctx
, addr
, addr
, 2);
8874 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
8875 gen_qemu_st16(ctx
, t0
, addr
);
8877 gen_addr_add(ctx
, addr
, addr
, 2);
8878 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
8881 static inline void gen_op_evstwhe(DisasContext
*ctx
, TCGv addr
)
8883 TCGv t0
= tcg_temp_new();
8884 #if defined(TARGET_PPC64)
8885 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
8887 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
8889 gen_qemu_st16(ctx
, t0
, addr
);
8890 gen_addr_add(ctx
, addr
, addr
, 2);
8891 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
8892 gen_qemu_st16(ctx
, t0
, addr
);
8896 static inline void gen_op_evstwho(DisasContext
*ctx
, TCGv addr
)
8898 #if defined(TARGET_PPC64)
8899 TCGv t0
= tcg_temp_new();
8900 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
8901 gen_qemu_st16(ctx
, t0
, addr
);
8904 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
8906 gen_addr_add(ctx
, addr
, addr
, 2);
8907 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
8910 static inline void gen_op_evstwwe(DisasContext
*ctx
, TCGv addr
)
8912 #if defined(TARGET_PPC64)
8913 TCGv t0
= tcg_temp_new();
8914 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
8915 gen_qemu_st32(ctx
, t0
, addr
);
8918 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
8922 static inline void gen_op_evstwwo(DisasContext
*ctx
, TCGv addr
)
8924 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
8927 #define GEN_SPEOP_LDST(name, opc2, sh) \
8928 static void glue(gen_, name)(DisasContext *ctx) \
8931 if (unlikely(!ctx->spe_enabled)) { \
8932 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8935 gen_set_access_type(ctx, ACCESS_INT); \
8936 t0 = tcg_temp_new(); \
8937 if (Rc(ctx->opcode)) { \
8938 gen_addr_spe_imm_index(ctx, t0, sh); \
8940 gen_addr_reg_index(ctx, t0); \
8942 gen_op_##name(ctx, t0); \
8943 tcg_temp_free(t0); \
8946 GEN_SPEOP_LDST(evldd
, 0x00, 3);
8947 GEN_SPEOP_LDST(evldw
, 0x01, 3);
8948 GEN_SPEOP_LDST(evldh
, 0x02, 3);
8949 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1);
8950 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1);
8951 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1);
8952 GEN_SPEOP_LDST(evlwhe
, 0x08, 2);
8953 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2);
8954 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2);
8955 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2);
8956 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2);
8958 GEN_SPEOP_LDST(evstdd
, 0x10, 3);
8959 GEN_SPEOP_LDST(evstdw
, 0x11, 3);
8960 GEN_SPEOP_LDST(evstdh
, 0x12, 3);
8961 GEN_SPEOP_LDST(evstwhe
, 0x18, 2);
8962 GEN_SPEOP_LDST(evstwho
, 0x1A, 2);
8963 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2);
8964 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2);
8966 /* Multiply and add - TODO */
8968 GEN_SPE(speundef
, evmhessf
, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);//
8969 GEN_SPE(speundef
, evmhossf
, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8970 GEN_SPE(evmheumi
, evmhesmi
, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
8971 GEN_SPE(speundef
, evmhesmf
, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8972 GEN_SPE(evmhoumi
, evmhosmi
, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
8973 GEN_SPE(speundef
, evmhosmf
, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8974 GEN_SPE(speundef
, evmhessfa
, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8975 GEN_SPE(speundef
, evmhossfa
, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8976 GEN_SPE(evmheumia
, evmhesmia
, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
8977 GEN_SPE(speundef
, evmhesmfa
, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8978 GEN_SPE(evmhoumia
, evmhosmia
, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
8979 GEN_SPE(speundef
, evmhosmfa
, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8981 GEN_SPE(speundef
, evmwhssf
, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8982 GEN_SPE(evmwlumi
, speundef
, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
8983 GEN_SPE(evmwhumi
, evmwhsmi
, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
8984 GEN_SPE(speundef
, evmwhsmf
, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8985 GEN_SPE(speundef
, evmwssf
, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8986 GEN_SPE(speundef
, evmwsmf
, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8987 GEN_SPE(speundef
, evmwhssfa
, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8988 GEN_SPE(evmwlumia
, speundef
, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
8989 GEN_SPE(evmwhumia
, evmwhsmia
, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
8990 GEN_SPE(speundef
, evmwhsmfa
, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8991 GEN_SPE(speundef
, evmwssfa
, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8992 GEN_SPE(speundef
, evmwsmfa
, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8994 GEN_SPE(evadduiaaw
, evaddsiaaw
, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8995 GEN_SPE(evsubfusiaaw
, evsubfssiaaw
, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8996 GEN_SPE(evaddumiaaw
, evaddsmiaaw
, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8997 GEN_SPE(evsubfumiaaw
, evsubfsmiaaw
, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8998 GEN_SPE(evdivws
, evdivwu
, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE
);
9000 GEN_SPE(evmheusiaaw
, evmhessiaaw
, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9001 GEN_SPE(speundef
, evmhessfaaw
, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9002 GEN_SPE(evmhousiaaw
, evmhossiaaw
, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9003 GEN_SPE(speundef
, evmhossfaaw
, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9004 GEN_SPE(evmheumiaaw
, evmhesmiaaw
, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9005 GEN_SPE(speundef
, evmhesmfaaw
, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9006 GEN_SPE(evmhoumiaaw
, evmhosmiaaw
, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9007 GEN_SPE(speundef
, evmhosmfaaw
, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9008 GEN_SPE(evmhegumiaa
, evmhegsmiaa
, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9009 GEN_SPE(speundef
, evmhegsmfaa
, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9010 GEN_SPE(evmhogumiaa
, evmhogsmiaa
, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9011 GEN_SPE(speundef
, evmhogsmfaa
, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9013 GEN_SPE(evmwlusiaaw
, evmwlssiaaw
, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
9014 GEN_SPE(evmwlumiaaw
, evmwlsmiaaw
, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
9015 GEN_SPE(speundef
, evmwssfaa
, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9016 GEN_SPE(speundef
, evmwsmfaa
, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9018 GEN_SPE(evmheusianw
, evmhessianw
, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9019 GEN_SPE(speundef
, evmhessfanw
, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9020 GEN_SPE(evmhousianw
, evmhossianw
, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9021 GEN_SPE(speundef
, evmhossfanw
, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9022 GEN_SPE(evmheumianw
, evmhesmianw
, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9023 GEN_SPE(speundef
, evmhesmfanw
, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9024 GEN_SPE(evmhoumianw
, evmhosmianw
, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9025 GEN_SPE(speundef
, evmhosmfanw
, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9026 GEN_SPE(evmhegumian
, evmhegsmian
, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9027 GEN_SPE(speundef
, evmhegsmfan
, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9028 GEN_SPE(evmhigumian
, evmhigsmian
, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9029 GEN_SPE(speundef
, evmhogsmfan
, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9031 GEN_SPE(evmwlusianw
, evmwlssianw
, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
9032 GEN_SPE(evmwlumianw
, evmwlsmianw
, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
9033 GEN_SPE(speundef
, evmwssfan
, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9034 GEN_SPE(evmwumian
, evmwsmian
, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
9035 GEN_SPE(speundef
, evmwsmfan
, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9038 /*** SPE floating-point extension ***/
9039 #if defined(TARGET_PPC64)
9040 #define GEN_SPEFPUOP_CONV_32_32(name) \
9041 static inline void gen_##name(DisasContext *ctx) \
9045 t0 = tcg_temp_new_i32(); \
9046 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
9047 gen_helper_##name(t0, cpu_env, t0); \
9048 t1 = tcg_temp_new(); \
9049 tcg_gen_extu_i32_tl(t1, t0); \
9050 tcg_temp_free_i32(t0); \
9051 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9052 0xFFFFFFFF00000000ULL); \
9053 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
9054 tcg_temp_free(t1); \
9056 #define GEN_SPEFPUOP_CONV_32_64(name) \
9057 static inline void gen_##name(DisasContext *ctx) \
9061 t0 = tcg_temp_new_i32(); \
9062 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
9063 t1 = tcg_temp_new(); \
9064 tcg_gen_extu_i32_tl(t1, t0); \
9065 tcg_temp_free_i32(t0); \
9066 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9067 0xFFFFFFFF00000000ULL); \
9068 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
9069 tcg_temp_free(t1); \
9071 #define GEN_SPEFPUOP_CONV_64_32(name) \
9072 static inline void gen_##name(DisasContext *ctx) \
9074 TCGv_i32 t0 = tcg_temp_new_i32(); \
9075 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
9076 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
9077 tcg_temp_free_i32(t0); \
9079 #define GEN_SPEFPUOP_CONV_64_64(name) \
9080 static inline void gen_##name(DisasContext *ctx) \
9082 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9083 cpu_gpr[rB(ctx->opcode)]); \
9085 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
9086 static inline void gen_##name(DisasContext *ctx) \
9090 if (unlikely(!ctx->spe_enabled)) { \
9091 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9094 t0 = tcg_temp_new_i32(); \
9095 t1 = tcg_temp_new_i32(); \
9096 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9097 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9098 gen_helper_##name(t0, cpu_env, t0, t1); \
9099 tcg_temp_free_i32(t1); \
9100 t2 = tcg_temp_new(); \
9101 tcg_gen_extu_i32_tl(t2, t0); \
9102 tcg_temp_free_i32(t0); \
9103 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
9104 0xFFFFFFFF00000000ULL); \
9105 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \
9106 tcg_temp_free(t2); \
9108 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
9109 static inline void gen_##name(DisasContext *ctx) \
9111 if (unlikely(!ctx->spe_enabled)) { \
9112 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9115 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9116 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9118 #define GEN_SPEFPUOP_COMP_32(name) \
9119 static inline void gen_##name(DisasContext *ctx) \
9122 if (unlikely(!ctx->spe_enabled)) { \
9123 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9126 t0 = tcg_temp_new_i32(); \
9127 t1 = tcg_temp_new_i32(); \
9128 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9129 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9130 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
9131 tcg_temp_free_i32(t0); \
9132 tcg_temp_free_i32(t1); \
9134 #define GEN_SPEFPUOP_COMP_64(name) \
9135 static inline void gen_##name(DisasContext *ctx) \
9137 if (unlikely(!ctx->spe_enabled)) { \
9138 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9141 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
9142 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9145 #define GEN_SPEFPUOP_CONV_32_32(name) \
9146 static inline void gen_##name(DisasContext *ctx) \
9148 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9149 cpu_gpr[rB(ctx->opcode)]); \
9151 #define GEN_SPEFPUOP_CONV_32_64(name) \
9152 static inline void gen_##name(DisasContext *ctx) \
9154 TCGv_i64 t0 = tcg_temp_new_i64(); \
9155 gen_load_gpr64(t0, rB(ctx->opcode)); \
9156 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
9157 tcg_temp_free_i64(t0); \
9159 #define GEN_SPEFPUOP_CONV_64_32(name) \
9160 static inline void gen_##name(DisasContext *ctx) \
9162 TCGv_i64 t0 = tcg_temp_new_i64(); \
9163 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
9164 gen_store_gpr64(rD(ctx->opcode), t0); \
9165 tcg_temp_free_i64(t0); \
9167 #define GEN_SPEFPUOP_CONV_64_64(name) \
9168 static inline void gen_##name(DisasContext *ctx) \
9170 TCGv_i64 t0 = tcg_temp_new_i64(); \
9171 gen_load_gpr64(t0, rB(ctx->opcode)); \
9172 gen_helper_##name(t0, cpu_env, t0); \
9173 gen_store_gpr64(rD(ctx->opcode), t0); \
9174 tcg_temp_free_i64(t0); \
9176 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
9177 static inline void gen_##name(DisasContext *ctx) \
9179 if (unlikely(!ctx->spe_enabled)) { \
9180 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9183 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
9184 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9186 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
9187 static inline void gen_##name(DisasContext *ctx) \
9190 if (unlikely(!ctx->spe_enabled)) { \
9191 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9194 t0 = tcg_temp_new_i64(); \
9195 t1 = tcg_temp_new_i64(); \
9196 gen_load_gpr64(t0, rA(ctx->opcode)); \
9197 gen_load_gpr64(t1, rB(ctx->opcode)); \
9198 gen_helper_##name(t0, cpu_env, t0, t1); \
9199 gen_store_gpr64(rD(ctx->opcode), t0); \
9200 tcg_temp_free_i64(t0); \
9201 tcg_temp_free_i64(t1); \
9203 #define GEN_SPEFPUOP_COMP_32(name) \
9204 static inline void gen_##name(DisasContext *ctx) \
9206 if (unlikely(!ctx->spe_enabled)) { \
9207 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9210 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
9211 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9213 #define GEN_SPEFPUOP_COMP_64(name) \
9214 static inline void gen_##name(DisasContext *ctx) \
9217 if (unlikely(!ctx->spe_enabled)) { \
9218 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9221 t0 = tcg_temp_new_i64(); \
9222 t1 = tcg_temp_new_i64(); \
9223 gen_load_gpr64(t0, rA(ctx->opcode)); \
9224 gen_load_gpr64(t1, rB(ctx->opcode)); \
9225 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
9226 tcg_temp_free_i64(t0); \
9227 tcg_temp_free_i64(t1); \
9231 /* Single precision floating-point vectors operations */
9233 GEN_SPEFPUOP_ARITH2_64_64(evfsadd
);
9234 GEN_SPEFPUOP_ARITH2_64_64(evfssub
);
9235 GEN_SPEFPUOP_ARITH2_64_64(evfsmul
);
9236 GEN_SPEFPUOP_ARITH2_64_64(evfsdiv
);
9237 static inline void gen_evfsabs(DisasContext
*ctx
)
9239 if (unlikely(!ctx
->spe_enabled
)) {
9240 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9243 #if defined(TARGET_PPC64)
9244 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000080000000LL
);
9246 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x80000000);
9247 tcg_gen_andi_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
9250 static inline void gen_evfsnabs(DisasContext
*ctx
)
9252 if (unlikely(!ctx
->spe_enabled
)) {
9253 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9256 #if defined(TARGET_PPC64)
9257 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
9259 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
9260 tcg_gen_ori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
9263 static inline void gen_evfsneg(DisasContext
*ctx
)
9265 if (unlikely(!ctx
->spe_enabled
)) {
9266 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9269 #if defined(TARGET_PPC64)
9270 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
9272 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
9273 tcg_gen_xori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
9278 GEN_SPEFPUOP_CONV_64_64(evfscfui
);
9279 GEN_SPEFPUOP_CONV_64_64(evfscfsi
);
9280 GEN_SPEFPUOP_CONV_64_64(evfscfuf
);
9281 GEN_SPEFPUOP_CONV_64_64(evfscfsf
);
9282 GEN_SPEFPUOP_CONV_64_64(evfsctui
);
9283 GEN_SPEFPUOP_CONV_64_64(evfsctsi
);
9284 GEN_SPEFPUOP_CONV_64_64(evfsctuf
);
9285 GEN_SPEFPUOP_CONV_64_64(evfsctsf
);
9286 GEN_SPEFPUOP_CONV_64_64(evfsctuiz
);
9287 GEN_SPEFPUOP_CONV_64_64(evfsctsiz
);
9290 GEN_SPEFPUOP_COMP_64(evfscmpgt
);
9291 GEN_SPEFPUOP_COMP_64(evfscmplt
);
9292 GEN_SPEFPUOP_COMP_64(evfscmpeq
);
9293 GEN_SPEFPUOP_COMP_64(evfststgt
);
9294 GEN_SPEFPUOP_COMP_64(evfststlt
);
9295 GEN_SPEFPUOP_COMP_64(evfststeq
);
9297 /* Opcodes definitions */
9298 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
9299 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
); //
9300 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9301 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
9302 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
9303 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9304 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9305 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9306 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9307 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9308 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9309 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9310 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
9311 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9313 /* Single precision floating-point operations */
9315 GEN_SPEFPUOP_ARITH2_32_32(efsadd
);
9316 GEN_SPEFPUOP_ARITH2_32_32(efssub
);
9317 GEN_SPEFPUOP_ARITH2_32_32(efsmul
);
9318 GEN_SPEFPUOP_ARITH2_32_32(efsdiv
);
9319 static inline void gen_efsabs(DisasContext
*ctx
)
9321 if (unlikely(!ctx
->spe_enabled
)) {
9322 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9325 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], (target_long
)~0x80000000LL
);
9327 static inline void gen_efsnabs(DisasContext
*ctx
)
9329 if (unlikely(!ctx
->spe_enabled
)) {
9330 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9333 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
9335 static inline void gen_efsneg(DisasContext
*ctx
)
9337 if (unlikely(!ctx
->spe_enabled
)) {
9338 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9341 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
9345 GEN_SPEFPUOP_CONV_32_32(efscfui
);
9346 GEN_SPEFPUOP_CONV_32_32(efscfsi
);
9347 GEN_SPEFPUOP_CONV_32_32(efscfuf
);
9348 GEN_SPEFPUOP_CONV_32_32(efscfsf
);
9349 GEN_SPEFPUOP_CONV_32_32(efsctui
);
9350 GEN_SPEFPUOP_CONV_32_32(efsctsi
);
9351 GEN_SPEFPUOP_CONV_32_32(efsctuf
);
9352 GEN_SPEFPUOP_CONV_32_32(efsctsf
);
9353 GEN_SPEFPUOP_CONV_32_32(efsctuiz
);
9354 GEN_SPEFPUOP_CONV_32_32(efsctsiz
);
9355 GEN_SPEFPUOP_CONV_32_64(efscfd
);
9358 GEN_SPEFPUOP_COMP_32(efscmpgt
);
9359 GEN_SPEFPUOP_COMP_32(efscmplt
);
9360 GEN_SPEFPUOP_COMP_32(efscmpeq
);
9361 GEN_SPEFPUOP_COMP_32(efststgt
);
9362 GEN_SPEFPUOP_COMP_32(efststlt
);
9363 GEN_SPEFPUOP_COMP_32(efststeq
);
9365 /* Opcodes definitions */
9366 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
9367 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
); //
9368 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9369 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
9370 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
9371 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE
); //
9372 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9373 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9374 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9375 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9376 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9377 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9378 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
9379 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9381 /* Double precision floating-point operations */
9383 GEN_SPEFPUOP_ARITH2_64_64(efdadd
);
9384 GEN_SPEFPUOP_ARITH2_64_64(efdsub
);
9385 GEN_SPEFPUOP_ARITH2_64_64(efdmul
);
9386 GEN_SPEFPUOP_ARITH2_64_64(efddiv
);
9387 static inline void gen_efdabs(DisasContext
*ctx
)
9389 if (unlikely(!ctx
->spe_enabled
)) {
9390 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9393 #if defined(TARGET_PPC64)
9394 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000000000000LL
);
9396 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
9397 tcg_gen_andi_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
9400 static inline void gen_efdnabs(DisasContext
*ctx
)
9402 if (unlikely(!ctx
->spe_enabled
)) {
9403 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9406 #if defined(TARGET_PPC64)
9407 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
9409 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
9410 tcg_gen_ori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
9413 static inline void gen_efdneg(DisasContext
*ctx
)
9415 if (unlikely(!ctx
->spe_enabled
)) {
9416 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9419 #if defined(TARGET_PPC64)
9420 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
9422 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
9423 tcg_gen_xori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
9428 GEN_SPEFPUOP_CONV_64_32(efdcfui
);
9429 GEN_SPEFPUOP_CONV_64_32(efdcfsi
);
9430 GEN_SPEFPUOP_CONV_64_32(efdcfuf
);
9431 GEN_SPEFPUOP_CONV_64_32(efdcfsf
);
9432 GEN_SPEFPUOP_CONV_32_64(efdctui
);
9433 GEN_SPEFPUOP_CONV_32_64(efdctsi
);
9434 GEN_SPEFPUOP_CONV_32_64(efdctuf
);
9435 GEN_SPEFPUOP_CONV_32_64(efdctsf
);
9436 GEN_SPEFPUOP_CONV_32_64(efdctuiz
);
9437 GEN_SPEFPUOP_CONV_32_64(efdctsiz
);
9438 GEN_SPEFPUOP_CONV_64_32(efdcfs
);
9439 GEN_SPEFPUOP_CONV_64_64(efdcfuid
);
9440 GEN_SPEFPUOP_CONV_64_64(efdcfsid
);
9441 GEN_SPEFPUOP_CONV_64_64(efdctuidz
);
9442 GEN_SPEFPUOP_CONV_64_64(efdctsidz
);
9445 GEN_SPEFPUOP_COMP_64(efdcmpgt
);
9446 GEN_SPEFPUOP_COMP_64(efdcmplt
);
9447 GEN_SPEFPUOP_COMP_64(efdcmpeq
);
9448 GEN_SPEFPUOP_COMP_64(efdtstgt
);
9449 GEN_SPEFPUOP_COMP_64(efdtstlt
);
9450 GEN_SPEFPUOP_COMP_64(efdtsteq
);
9452 /* Opcodes definitions */
9453 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
); //
9454 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9455 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE
); //
9456 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
9457 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
); //
9458 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9459 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
); //
9460 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE
); //
9461 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9462 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9463 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9464 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
9465 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
9466 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
9467 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
); //
9468 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
9470 static opcode_t opcodes
[] = {
9471 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
),
9472 GEN_HANDLER(cmp
, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER
),
9473 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
9474 GEN_HANDLER(cmpl
, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER
),
9475 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
9476 GEN_HANDLER_E(cmpb
, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE
, PPC2_ISA205
),
9477 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
),
9478 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9479 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9480 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9481 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9482 GEN_HANDLER(mulhw
, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER
),
9483 GEN_HANDLER(mulhwu
, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER
),
9484 GEN_HANDLER(mullw
, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER
),
9485 GEN_HANDLER(mullwo
, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER
),
9486 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9487 #if defined(TARGET_PPC64)
9488 GEN_HANDLER(mulld
, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B
),
9490 GEN_HANDLER(neg
, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER
),
9491 GEN_HANDLER(nego
, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER
),
9492 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9493 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9494 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9495 GEN_HANDLER(cntlzw
, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER
),
9496 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
),
9497 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
),
9498 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9499 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9500 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9501 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9502 GEN_HANDLER(popcntb
, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB
),
9503 GEN_HANDLER(popcntw
, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD
),
9504 GEN_HANDLER_E(prtyw
, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
9505 #if defined(TARGET_PPC64)
9506 GEN_HANDLER(popcntd
, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD
),
9507 GEN_HANDLER(cntlzd
, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B
),
9508 GEN_HANDLER_E(prtyd
, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
9509 GEN_HANDLER_E(bpermd
, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE
, PPC2_PERM_ISA206
),
9511 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9512 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9513 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9514 GEN_HANDLER(slw
, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER
),
9515 GEN_HANDLER(sraw
, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER
),
9516 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
),
9517 GEN_HANDLER(srw
, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER
),
9518 #if defined(TARGET_PPC64)
9519 GEN_HANDLER(sld
, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B
),
9520 GEN_HANDLER(srad
, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B
),
9521 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
),
9522 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
),
9523 GEN_HANDLER(srd
, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B
),
9525 GEN_HANDLER(frsqrtes
, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES
),
9526 GEN_HANDLER(fsqrt
, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
9527 GEN_HANDLER(fsqrts
, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
9528 GEN_HANDLER(fcmpo
, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT
),
9529 GEN_HANDLER(fcmpu
, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT
),
9530 GEN_HANDLER(fabs
, 0x3F, 0x08, 0x08, 0x001F0000, PPC_FLOAT
),
9531 GEN_HANDLER(fmr
, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT
),
9532 GEN_HANDLER(fnabs
, 0x3F, 0x08, 0x04, 0x001F0000, PPC_FLOAT
),
9533 GEN_HANDLER(fneg
, 0x3F, 0x08, 0x01, 0x001F0000, PPC_FLOAT
),
9534 GEN_HANDLER_E(fcpsgn
, 0x3F, 0x08, 0x00, 0x00000000, PPC_NONE
, PPC2_ISA205
),
9535 GEN_HANDLER_E(fmrgew
, 0x3F, 0x06, 0x1E, 0x00000001, PPC_NONE
, PPC2_VSX207
),
9536 GEN_HANDLER_E(fmrgow
, 0x3F, 0x06, 0x1A, 0x00000001, PPC_NONE
, PPC2_VSX207
),
9537 GEN_HANDLER(mcrfs
, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT
),
9538 GEN_HANDLER(mffs
, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT
),
9539 GEN_HANDLER(mtfsb0
, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT
),
9540 GEN_HANDLER(mtfsb1
, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT
),
9541 GEN_HANDLER(mtfsf
, 0x3F, 0x07, 0x16, 0x00000000, PPC_FLOAT
),
9542 GEN_HANDLER(mtfsfi
, 0x3F, 0x06, 0x04, 0x006e0800, PPC_FLOAT
),
9543 #if defined(TARGET_PPC64)
9544 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
),
9545 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
),
9546 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
),
9548 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9549 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
9550 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
),
9551 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
),
9552 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
),
9553 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
),
9554 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO
),
9555 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
),
9556 GEN_HANDLER_E(lbarx
, 0x1F, 0x14, 0x01, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
9557 GEN_HANDLER_E(lharx
, 0x1F, 0x14, 0x03, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
9558 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES
),
9559 GEN_HANDLER_E(stbcx_
, 0x1F, 0x16, 0x15, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
9560 GEN_HANDLER_E(sthcx_
, 0x1F, 0x16, 0x16, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
9561 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
),
9562 #if defined(TARGET_PPC64)
9563 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B
),
9564 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
),
9566 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
),
9567 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
),
9568 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
9569 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
9570 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
),
9571 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
),
9572 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
),
9573 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
),
9574 #if defined(TARGET_PPC64)
9575 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
),
9576 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
),
9578 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW
),
9579 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
),
9580 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
9581 #if defined(TARGET_PPC64)
9582 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
),
9583 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
),
9585 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
),
9586 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
),
9587 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
),
9588 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
),
9589 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
),
9590 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
),
9591 #if defined(TARGET_PPC64)
9592 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
),
9594 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC
),
9595 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC
),
9596 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
),
9597 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
),
9598 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
),
9599 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE
),
9600 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE
),
9601 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ
),
9602 GEN_HANDLER(dst
, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC
),
9603 GEN_HANDLER(dstst
, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC
),
9604 GEN_HANDLER(dss
, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC
),
9605 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
),
9606 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
),
9607 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
),
9608 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
),
9609 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
),
9610 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
),
9611 #if defined(TARGET_PPC64)
9612 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
),
9613 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
9615 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
),
9616 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
9618 GEN_HANDLER2(slbmte
, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B
),
9619 GEN_HANDLER2(slbmfee
, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B
),
9620 GEN_HANDLER2(slbmfev
, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B
),
9622 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
),
9623 GEN_HANDLER(tlbiel
, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE
),
9624 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE
),
9625 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
),
9626 #if defined(TARGET_PPC64)
9627 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI
),
9628 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
),
9630 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
),
9631 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
),
9632 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
),
9633 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
),
9634 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
),
9635 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
),
9636 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
),
9637 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
),
9638 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
),
9639 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
),
9640 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
),
9641 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
9642 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
),
9643 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
),
9644 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
),
9645 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
),
9646 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
),
9647 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
),
9648 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
),
9649 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
9650 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
),
9651 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
),
9652 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
),
9653 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
),
9654 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
),
9655 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
),
9656 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
),
9657 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
),
9658 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
),
9659 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
),
9660 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
),
9661 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
),
9662 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
),
9663 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
),
9664 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
),
9665 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
),
9666 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
),
9667 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
),
9668 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
),
9669 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
),
9670 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
),
9671 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
),
9672 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
),
9673 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
),
9674 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
),
9675 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
),
9676 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
),
9677 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
),
9678 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
),
9679 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
9680 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
9681 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
),
9682 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
),
9683 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
9684 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
9685 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
),
9686 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
),
9687 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
),
9688 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
),
9689 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
),
9690 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
),
9691 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
),
9692 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
),
9693 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
),
9694 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
),
9695 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
),
9696 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
),
9697 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
),
9698 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
),
9699 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
),
9700 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
),
9701 GEN_HANDLER_E(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
, PPC2_BOOKE206
),
9702 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
),
9703 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
),
9704 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
),
9705 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
),
9706 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
),
9707 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
),
9708 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
),
9709 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
),
9710 GEN_HANDLER2_E(tlbre_booke206
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
9711 PPC_NONE
, PPC2_BOOKE206
),
9712 GEN_HANDLER2_E(tlbsx_booke206
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
9713 PPC_NONE
, PPC2_BOOKE206
),
9714 GEN_HANDLER2_E(tlbwe_booke206
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
9715 PPC_NONE
, PPC2_BOOKE206
),
9716 GEN_HANDLER2_E(tlbivax_booke206
, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
9717 PPC_NONE
, PPC2_BOOKE206
),
9718 GEN_HANDLER2_E(tlbilx_booke206
, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
9719 PPC_NONE
, PPC2_BOOKE206
),
9720 GEN_HANDLER2_E(msgsnd
, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
9721 PPC_NONE
, PPC2_PRCNTL
),
9722 GEN_HANDLER2_E(msgclr
, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
9723 PPC_NONE
, PPC2_PRCNTL
),
9724 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
),
9725 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE
),
9726 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
),
9727 GEN_HANDLER_E(mbar
, 0x1F, 0x16, 0x1a, 0x001FF801,
9728 PPC_BOOKE
, PPC2_BOOKE206
),
9729 GEN_HANDLER(msync_4xx
, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE
),
9730 GEN_HANDLER2_E(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
9731 PPC_BOOKE
, PPC2_BOOKE206
),
9732 GEN_HANDLER(lvsl
, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC
),
9733 GEN_HANDLER(lvsr
, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC
),
9734 GEN_HANDLER(mfvscr
, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC
),
9735 GEN_HANDLER(mtvscr
, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC
),
9736 GEN_HANDLER(vsldoi
, 0x04, 0x16, 0xFF, 0x00000400, PPC_ALTIVEC
),
9737 GEN_HANDLER(vmladduhm
, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC
),
9738 GEN_HANDLER2(evsel0
, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE
),
9739 GEN_HANDLER2(evsel1
, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE
),
9740 GEN_HANDLER2(evsel2
, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE
),
9741 GEN_HANDLER2(evsel3
, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE
),
9743 #undef GEN_INT_ARITH_ADD
9744 #undef GEN_INT_ARITH_ADD_CONST
9745 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
9746 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
9747 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
9748 add_ca, compute_ca, compute_ov) \
9749 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
9750 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
9751 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
9752 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
9753 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
9754 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
9755 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
9756 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
9757 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
9758 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
9759 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
9761 #undef GEN_INT_ARITH_DIVW
9762 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
9763 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
9764 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0),
9765 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1),
9766 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0),
9767 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1),
9768 GEN_HANDLER_E(divwe
, 0x1F, 0x0B, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9769 GEN_HANDLER_E(divweo
, 0x1F, 0x0B, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9770 GEN_HANDLER_E(divweu
, 0x1F, 0x0B, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9771 GEN_HANDLER_E(divweuo
, 0x1F, 0x0B, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9773 #if defined(TARGET_PPC64)
9774 #undef GEN_INT_ARITH_DIVD
9775 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
9776 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
9777 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0),
9778 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1),
9779 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0),
9780 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1),
9782 GEN_HANDLER_E(divdeu
, 0x1F, 0x09, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9783 GEN_HANDLER_E(divdeuo
, 0x1F, 0x09, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9784 GEN_HANDLER_E(divde
, 0x1F, 0x09, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9785 GEN_HANDLER_E(divdeo
, 0x1F, 0x09, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
9787 #undef GEN_INT_ARITH_MUL_HELPER
9788 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
9789 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
9790 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00),
9791 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02),
9792 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17),
9795 #undef GEN_INT_ARITH_SUBF
9796 #undef GEN_INT_ARITH_SUBF_CONST
9797 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
9798 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
9799 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
9800 add_ca, compute_ca, compute_ov) \
9801 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
9802 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
9803 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
9804 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
9805 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
9806 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
9807 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
9808 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
9809 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
9810 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
9811 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
9815 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
9816 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
9817 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
9818 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
9819 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
),
9820 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
),
9821 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
),
9822 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
),
9823 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
),
9824 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
),
9825 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
),
9826 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
),
9827 #if defined(TARGET_PPC64)
9828 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
),
9831 #if defined(TARGET_PPC64)
9834 #define GEN_PPC64_R2(name, opc1, opc2) \
9835 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
9836 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
9838 #define GEN_PPC64_R4(name, opc1, opc2) \
9839 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
9840 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
9842 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
9844 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
9846 GEN_PPC64_R4(rldicl
, 0x1E, 0x00),
9847 GEN_PPC64_R4(rldicr
, 0x1E, 0x02),
9848 GEN_PPC64_R4(rldic
, 0x1E, 0x04),
9849 GEN_PPC64_R2(rldcl
, 0x1E, 0x08),
9850 GEN_PPC64_R2(rldcr
, 0x1E, 0x09),
9851 GEN_PPC64_R4(rldimi
, 0x1E, 0x06),
9854 #undef _GEN_FLOAT_ACB
9855 #undef GEN_FLOAT_ACB
9856 #undef _GEN_FLOAT_AB
9858 #undef _GEN_FLOAT_AC
9862 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
9863 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
9864 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
9865 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
9866 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
9867 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
9868 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
9869 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
9870 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
9871 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
9872 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
9873 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
9874 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
9875 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
9876 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
9877 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
9878 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
9879 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
9880 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
9882 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
),
9883 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
),
9884 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
),
9885 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
),
9886 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
),
9887 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
),
9888 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
),
9889 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
),
9890 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
),
9891 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
),
9892 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
),
9893 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
),
9894 GEN_HANDLER_E(ftdiv
, 0x3F, 0x00, 0x04, 1, PPC_NONE
, PPC2_FP_TST_ISA206
),
9895 GEN_HANDLER_E(ftsqrt
, 0x3F, 0x00, 0x05, 1, PPC_NONE
, PPC2_FP_TST_ISA206
),
9896 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
),
9897 GEN_HANDLER_E(fctiwu
, 0x3F, 0x0E, 0x04, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
9898 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
),
9899 GEN_HANDLER_E(fctiwuz
, 0x3F, 0x0F, 0x04, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
9900 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
),
9901 #if defined(TARGET_PPC64)
9902 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
),
9903 GEN_HANDLER_E(fcfids
, 0x3B, 0x0E, 0x1A, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
9904 GEN_HANDLER_E(fcfidu
, 0x3F, 0x0E, 0x1E, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
9905 GEN_HANDLER_E(fcfidus
, 0x3B, 0x0E, 0x1E, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
9906 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
),
9907 GEN_HANDLER_E(fctidu
, 0x3F, 0x0E, 0x1D, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
9908 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
),
9909 GEN_HANDLER_E(fctiduz
, 0x3F, 0x0F, 0x1D, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
9911 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
),
9912 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
),
9913 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
),
9914 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
),
9921 #define GEN_LD(name, ldop, opc, type) \
9922 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9923 #define GEN_LDU(name, ldop, opc, type) \
9924 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
9925 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
9926 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
9927 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
9928 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
9929 #define GEN_LDS(name, ldop, op, type) \
9930 GEN_LD(name, ldop, op | 0x20, type) \
9931 GEN_LDU(name, ldop, op | 0x21, type) \
9932 GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
9933 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
9935 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
)
9936 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
)
9937 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
)
9938 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
)
9939 #if defined(TARGET_PPC64)
9940 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
)
9941 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
)
9942 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
)
9943 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
)
9944 GEN_LDX_E(ldbr
, ld64ur
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
)
9946 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
)
9947 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
)
9954 #define GEN_ST(name, stop, opc, type) \
9955 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9956 #define GEN_STU(name, stop, opc, type) \
9957 GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
9958 #define GEN_STUX(name, stop, opc2, opc3, type) \
9959 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
9960 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
9961 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
9962 #define GEN_STS(name, stop, op, type) \
9963 GEN_ST(name, stop, op | 0x20, type) \
9964 GEN_STU(name, stop, op | 0x21, type) \
9965 GEN_STUX(name, stop, 0x17, op | 0x01, type) \
9966 GEN_STX(name, stop, 0x17, op | 0x00, type)
9968 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
)
9969 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
)
9970 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
)
9971 #if defined(TARGET_PPC64)
9972 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
)
9973 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
)
9974 GEN_STX_E(stdbr
, st64r
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
)
9976 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
)
9977 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
)
9984 #define GEN_LDF(name, ldop, opc, type) \
9985 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9986 #define GEN_LDUF(name, ldop, opc, type) \
9987 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
9988 #define GEN_LDUXF(name, ldop, opc, type) \
9989 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
9990 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
9991 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
9992 #define GEN_LDFS(name, ldop, op, type) \
9993 GEN_LDF(name, ldop, op | 0x20, type) \
9994 GEN_LDUF(name, ldop, op | 0x21, type) \
9995 GEN_LDUXF(name, ldop, op | 0x01, type) \
9996 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
9998 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
)
9999 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
)
10000 GEN_HANDLER_E(lfiwax
, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE
, PPC2_ISA205
),
10001 GEN_HANDLER_E(lfiwzx
, 0x1f, 0x17, 0x1b, 0x1, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10002 GEN_HANDLER_E(lfdp
, 0x39, 0xFF, 0xFF, 0x00200003, PPC_NONE
, PPC2_ISA205
),
10003 GEN_HANDLER_E(lfdpx
, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE
, PPC2_ISA205
),
10010 #define GEN_STF(name, stop, opc, type) \
10011 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10012 #define GEN_STUF(name, stop, opc, type) \
10013 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10014 #define GEN_STUXF(name, stop, opc, type) \
10015 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10016 #define GEN_STXF(name, stop, opc2, opc3, type) \
10017 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10018 #define GEN_STFS(name, stop, op, type) \
10019 GEN_STF(name, stop, op | 0x20, type) \
10020 GEN_STUF(name, stop, op | 0x21, type) \
10021 GEN_STUXF(name, stop, op | 0x01, type) \
10022 GEN_STXF(name, stop, 0x17, op | 0x00, type)
10024 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
)
10025 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
)
10026 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
)
10027 GEN_HANDLER_E(stfdp
, 0x3D, 0xFF, 0xFF, 0x00200003, PPC_NONE
, PPC2_ISA205
),
10028 GEN_HANDLER_E(stfdpx
, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE
, PPC2_ISA205
),
10031 #define GEN_CRLOGIC(name, tcg_op, opc) \
10032 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
10033 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08),
10034 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04),
10035 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09),
10036 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07),
10037 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01),
10038 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E),
10039 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D),
10040 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06),
10042 #undef GEN_MAC_HANDLER
10043 #define GEN_MAC_HANDLER(name, opc2, opc3) \
10044 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
10045 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05),
10046 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15),
10047 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07),
10048 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17),
10049 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06),
10050 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16),
10051 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04),
10052 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14),
10053 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01),
10054 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11),
10055 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03),
10056 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13),
10057 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02),
10058 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12),
10059 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00),
10060 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10),
10061 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D),
10062 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D),
10063 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F),
10064 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F),
10065 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C),
10066 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C),
10067 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E),
10068 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E),
10069 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05),
10070 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15),
10071 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07),
10072 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17),
10073 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01),
10074 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11),
10075 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03),
10076 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13),
10077 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D),
10078 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D),
10079 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F),
10080 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F),
10081 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05),
10082 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04),
10083 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01),
10084 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00),
10085 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D),
10086 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C),
10092 #define GEN_VR_LDX(name, opc2, opc3) \
10093 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10094 #define GEN_VR_STX(name, opc2, opc3) \
10095 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10096 #define GEN_VR_LVE(name, opc2, opc3) \
10097 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10098 #define GEN_VR_STVE(name, opc2, opc3) \
10099 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10100 GEN_VR_LDX(lvx
, 0x07, 0x03),
10101 GEN_VR_LDX(lvxl
, 0x07, 0x0B),
10102 GEN_VR_LVE(bx
, 0x07, 0x00),
10103 GEN_VR_LVE(hx
, 0x07, 0x01),
10104 GEN_VR_LVE(wx
, 0x07, 0x02),
10105 GEN_VR_STX(svx
, 0x07, 0x07),
10106 GEN_VR_STX(svxl
, 0x07, 0x0F),
10107 GEN_VR_STVE(bx
, 0x07, 0x04),
10108 GEN_VR_STVE(hx
, 0x07, 0x05),
10109 GEN_VR_STVE(wx
, 0x07, 0x06),
10111 #undef GEN_VX_LOGICAL
10112 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
10113 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10114 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16),
10115 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17),
10116 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18),
10117 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19),
10118 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20),
10121 #define GEN_VXFORM(name, opc2, opc3) \
10122 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10123 GEN_VXFORM(vaddubm
, 0, 0),
10124 GEN_VXFORM(vadduhm
, 0, 1),
10125 GEN_VXFORM(vadduwm
, 0, 2),
10126 GEN_VXFORM(vsububm
, 0, 16),
10127 GEN_VXFORM(vsubuhm
, 0, 17),
10128 GEN_VXFORM(vsubuwm
, 0, 18),
10129 GEN_VXFORM(vmaxub
, 1, 0),
10130 GEN_VXFORM(vmaxuh
, 1, 1),
10131 GEN_VXFORM(vmaxuw
, 1, 2),
10132 GEN_VXFORM(vmaxsb
, 1, 4),
10133 GEN_VXFORM(vmaxsh
, 1, 5),
10134 GEN_VXFORM(vmaxsw
, 1, 6),
10135 GEN_VXFORM(vminub
, 1, 8),
10136 GEN_VXFORM(vminuh
, 1, 9),
10137 GEN_VXFORM(vminuw
, 1, 10),
10138 GEN_VXFORM(vminsb
, 1, 12),
10139 GEN_VXFORM(vminsh
, 1, 13),
10140 GEN_VXFORM(vminsw
, 1, 14),
10141 GEN_VXFORM(vavgub
, 1, 16),
10142 GEN_VXFORM(vavguh
, 1, 17),
10143 GEN_VXFORM(vavguw
, 1, 18),
10144 GEN_VXFORM(vavgsb
, 1, 20),
10145 GEN_VXFORM(vavgsh
, 1, 21),
10146 GEN_VXFORM(vavgsw
, 1, 22),
10147 GEN_VXFORM(vmrghb
, 6, 0),
10148 GEN_VXFORM(vmrghh
, 6, 1),
10149 GEN_VXFORM(vmrghw
, 6, 2),
10150 GEN_VXFORM(vmrglb
, 6, 4),
10151 GEN_VXFORM(vmrglh
, 6, 5),
10152 GEN_VXFORM(vmrglw
, 6, 6),
10153 GEN_VXFORM(vmuloub
, 4, 0),
10154 GEN_VXFORM(vmulouh
, 4, 1),
10155 GEN_VXFORM(vmulosb
, 4, 4),
10156 GEN_VXFORM(vmulosh
, 4, 5),
10157 GEN_VXFORM(vmuleub
, 4, 8),
10158 GEN_VXFORM(vmuleuh
, 4, 9),
10159 GEN_VXFORM(vmulesb
, 4, 12),
10160 GEN_VXFORM(vmulesh
, 4, 13),
10161 GEN_VXFORM(vslb
, 2, 4),
10162 GEN_VXFORM(vslh
, 2, 5),
10163 GEN_VXFORM(vslw
, 2, 6),
10164 GEN_VXFORM(vsrb
, 2, 8),
10165 GEN_VXFORM(vsrh
, 2, 9),
10166 GEN_VXFORM(vsrw
, 2, 10),
10167 GEN_VXFORM(vsrab
, 2, 12),
10168 GEN_VXFORM(vsrah
, 2, 13),
10169 GEN_VXFORM(vsraw
, 2, 14),
10170 GEN_VXFORM(vslo
, 6, 16),
10171 GEN_VXFORM(vsro
, 6, 17),
10172 GEN_VXFORM(vaddcuw
, 0, 6),
10173 GEN_VXFORM(vsubcuw
, 0, 22),
10174 GEN_VXFORM(vaddubs
, 0, 8),
10175 GEN_VXFORM(vadduhs
, 0, 9),
10176 GEN_VXFORM(vadduws
, 0, 10),
10177 GEN_VXFORM(vaddsbs
, 0, 12),
10178 GEN_VXFORM(vaddshs
, 0, 13),
10179 GEN_VXFORM(vaddsws
, 0, 14),
10180 GEN_VXFORM(vsububs
, 0, 24),
10181 GEN_VXFORM(vsubuhs
, 0, 25),
10182 GEN_VXFORM(vsubuws
, 0, 26),
10183 GEN_VXFORM(vsubsbs
, 0, 28),
10184 GEN_VXFORM(vsubshs
, 0, 29),
10185 GEN_VXFORM(vsubsws
, 0, 30),
10186 GEN_VXFORM(vrlb
, 2, 0),
10187 GEN_VXFORM(vrlh
, 2, 1),
10188 GEN_VXFORM(vrlw
, 2, 2),
10189 GEN_VXFORM(vsl
, 2, 7),
10190 GEN_VXFORM(vsr
, 2, 11),
10191 GEN_VXFORM(vpkuhum
, 7, 0),
10192 GEN_VXFORM(vpkuwum
, 7, 1),
10193 GEN_VXFORM(vpkuhus
, 7, 2),
10194 GEN_VXFORM(vpkuwus
, 7, 3),
10195 GEN_VXFORM(vpkshus
, 7, 4),
10196 GEN_VXFORM(vpkswus
, 7, 5),
10197 GEN_VXFORM(vpkshss
, 7, 6),
10198 GEN_VXFORM(vpkswss
, 7, 7),
10199 GEN_VXFORM(vpkpx
, 7, 12),
10200 GEN_VXFORM(vsum4ubs
, 4, 24),
10201 GEN_VXFORM(vsum4sbs
, 4, 28),
10202 GEN_VXFORM(vsum4shs
, 4, 25),
10203 GEN_VXFORM(vsum2sws
, 4, 26),
10204 GEN_VXFORM(vsumsws
, 4, 30),
10205 GEN_VXFORM(vaddfp
, 5, 0),
10206 GEN_VXFORM(vsubfp
, 5, 1),
10207 GEN_VXFORM(vmaxfp
, 5, 16),
10208 GEN_VXFORM(vminfp
, 5, 17),
10210 #undef GEN_VXRFORM1
10212 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
10213 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
10214 #define GEN_VXRFORM(name, opc2, opc3) \
10215 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
10216 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
10217 GEN_VXRFORM(vcmpequb
, 3, 0)
10218 GEN_VXRFORM(vcmpequh
, 3, 1)
10219 GEN_VXRFORM(vcmpequw
, 3, 2)
10220 GEN_VXRFORM(vcmpgtsb
, 3, 12)
10221 GEN_VXRFORM(vcmpgtsh
, 3, 13)
10222 GEN_VXRFORM(vcmpgtsw
, 3, 14)
10223 GEN_VXRFORM(vcmpgtub
, 3, 8)
10224 GEN_VXRFORM(vcmpgtuh
, 3, 9)
10225 GEN_VXRFORM(vcmpgtuw
, 3, 10)
10226 GEN_VXRFORM(vcmpeqfp
, 3, 3)
10227 GEN_VXRFORM(vcmpgefp
, 3, 7)
10228 GEN_VXRFORM(vcmpgtfp
, 3, 11)
10229 GEN_VXRFORM(vcmpbfp
, 3, 15)
10231 #undef GEN_VXFORM_SIMM
10232 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
10233 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10234 GEN_VXFORM_SIMM(vspltisb
, 6, 12),
10235 GEN_VXFORM_SIMM(vspltish
, 6, 13),
10236 GEN_VXFORM_SIMM(vspltisw
, 6, 14),
10238 #undef GEN_VXFORM_NOA
10239 #define GEN_VXFORM_NOA(name, opc2, opc3) \
10240 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
10241 GEN_VXFORM_NOA(vupkhsb
, 7, 8),
10242 GEN_VXFORM_NOA(vupkhsh
, 7, 9),
10243 GEN_VXFORM_NOA(vupklsb
, 7, 10),
10244 GEN_VXFORM_NOA(vupklsh
, 7, 11),
10245 GEN_VXFORM_NOA(vupkhpx
, 7, 13),
10246 GEN_VXFORM_NOA(vupklpx
, 7, 15),
10247 GEN_VXFORM_NOA(vrefp
, 5, 4),
10248 GEN_VXFORM_NOA(vrsqrtefp
, 5, 5),
10249 GEN_VXFORM_NOA(vexptefp
, 5, 6),
10250 GEN_VXFORM_NOA(vlogefp
, 5, 7),
10251 GEN_VXFORM_NOA(vrfim
, 5, 8),
10252 GEN_VXFORM_NOA(vrfin
, 5, 9),
10253 GEN_VXFORM_NOA(vrfip
, 5, 10),
10254 GEN_VXFORM_NOA(vrfiz
, 5, 11),
10256 #undef GEN_VXFORM_UIMM
10257 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
10258 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10259 GEN_VXFORM_UIMM(vspltb
, 6, 8),
10260 GEN_VXFORM_UIMM(vsplth
, 6, 9),
10261 GEN_VXFORM_UIMM(vspltw
, 6, 10),
10262 GEN_VXFORM_UIMM(vcfux
, 5, 12),
10263 GEN_VXFORM_UIMM(vcfsx
, 5, 13),
10264 GEN_VXFORM_UIMM(vctuxs
, 5, 14),
10265 GEN_VXFORM_UIMM(vctsxs
, 5, 15),
10267 #undef GEN_VAFORM_PAIRED
10268 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
10269 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
10270 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16),
10271 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18),
10272 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19),
10273 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20),
10274 GEN_VAFORM_PAIRED(vsel
, vperm
, 21),
10275 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23),
10277 GEN_HANDLER_E(lxsdx
, 0x1F, 0x0C, 0x12, 0, PPC_NONE
, PPC2_VSX
),
10278 GEN_HANDLER_E(lxsiwax
, 0x1F, 0x0C, 0x02, 0, PPC_NONE
, PPC2_VSX207
),
10279 GEN_HANDLER_E(lxsiwzx
, 0x1F, 0x0C, 0x00, 0, PPC_NONE
, PPC2_VSX207
),
10280 GEN_HANDLER_E(lxsspx
, 0x1F, 0x0C, 0x10, 0, PPC_NONE
, PPC2_VSX207
),
10281 GEN_HANDLER_E(lxvd2x
, 0x1F, 0x0C, 0x1A, 0, PPC_NONE
, PPC2_VSX
),
10282 GEN_HANDLER_E(lxvdsx
, 0x1F, 0x0C, 0x0A, 0, PPC_NONE
, PPC2_VSX
),
10283 GEN_HANDLER_E(lxvw4x
, 0x1F, 0x0C, 0x18, 0, PPC_NONE
, PPC2_VSX
),
10285 GEN_HANDLER_E(stxsdx
, 0x1F, 0xC, 0x16, 0, PPC_NONE
, PPC2_VSX
),
10286 GEN_HANDLER_E(stxsiwx
, 0x1F, 0xC, 0x04, 0, PPC_NONE
, PPC2_VSX207
),
10287 GEN_HANDLER_E(stxsspx
, 0x1F, 0xC, 0x14, 0, PPC_NONE
, PPC2_VSX207
),
10288 GEN_HANDLER_E(stxvd2x
, 0x1F, 0xC, 0x1E, 0, PPC_NONE
, PPC2_VSX
),
10289 GEN_HANDLER_E(stxvw4x
, 0x1F, 0xC, 0x1C, 0, PPC_NONE
, PPC2_VSX
),
10291 GEN_HANDLER_E(mfvsrwz
, 0x1F, 0x13, 0x03, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
10292 GEN_HANDLER_E(mtvsrwa
, 0x1F, 0x13, 0x06, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
10293 GEN_HANDLER_E(mtvsrwz
, 0x1F, 0x13, 0x07, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
10294 #if defined(TARGET_PPC64)
10295 GEN_HANDLER_E(mfvsrd
, 0x1F, 0x13, 0x01, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
10296 GEN_HANDLER_E(mtvsrd
, 0x1F, 0x13, 0x05, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
10300 #define GEN_XX2FORM(name, opc2, opc3, fl2) \
10301 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10302 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2)
10305 #define GEN_XX3FORM(name, opc2, opc3, fl2) \
10306 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
10307 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2), \
10308 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 0, PPC_NONE, fl2), \
10309 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 0, PPC_NONE, fl2)
10311 #undef GEN_XX3_RC_FORM
10312 #define GEN_XX3_RC_FORM(name, opc2, opc3, fl2) \
10313 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x00, 0, PPC_NONE, fl2), \
10314 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x00, 0, PPC_NONE, fl2), \
10315 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x00, 0, PPC_NONE, fl2), \
10316 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x00, 0, PPC_NONE, fl2), \
10317 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x10, 0, PPC_NONE, fl2), \
10318 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x10, 0, PPC_NONE, fl2), \
10319 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x10, 0, PPC_NONE, fl2), \
10320 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x10, 0, PPC_NONE, fl2)
10322 #undef GEN_XX3FORM_DM
10323 #define GEN_XX3FORM_DM(name, opc2, opc3) \
10324 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10325 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10326 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10327 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
10328 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10329 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10330 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10331 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
10332 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10333 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10334 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10335 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
10336 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10337 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10338 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
10339 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x0C, 0, PPC_NONE, PPC2_VSX)
10341 GEN_XX2FORM(xsabsdp
, 0x12, 0x15, PPC2_VSX
),
10342 GEN_XX2FORM(xsnabsdp
, 0x12, 0x16, PPC2_VSX
),
10343 GEN_XX2FORM(xsnegdp
, 0x12, 0x17, PPC2_VSX
),
10344 GEN_XX3FORM(xscpsgndp
, 0x00, 0x16, PPC2_VSX
),
10346 GEN_XX2FORM(xvabsdp
, 0x12, 0x1D, PPC2_VSX
),
10347 GEN_XX2FORM(xvnabsdp
, 0x12, 0x1E, PPC2_VSX
),
10348 GEN_XX2FORM(xvnegdp
, 0x12, 0x1F, PPC2_VSX
),
10349 GEN_XX3FORM(xvcpsgndp
, 0x00, 0x1E, PPC2_VSX
),
10350 GEN_XX2FORM(xvabssp
, 0x12, 0x19, PPC2_VSX
),
10351 GEN_XX2FORM(xvnabssp
, 0x12, 0x1A, PPC2_VSX
),
10352 GEN_XX2FORM(xvnegsp
, 0x12, 0x1B, PPC2_VSX
),
10353 GEN_XX3FORM(xvcpsgnsp
, 0x00, 0x1A, PPC2_VSX
),
10355 GEN_XX3FORM(xsadddp
, 0x00, 0x04, PPC2_VSX
),
10356 GEN_XX3FORM(xssubdp
, 0x00, 0x05, PPC2_VSX
),
10357 GEN_XX3FORM(xsmuldp
, 0x00, 0x06, PPC2_VSX
),
10358 GEN_XX3FORM(xsdivdp
, 0x00, 0x07, PPC2_VSX
),
10359 GEN_XX2FORM(xsredp
, 0x14, 0x05, PPC2_VSX
),
10360 GEN_XX2FORM(xssqrtdp
, 0x16, 0x04, PPC2_VSX
),
10361 GEN_XX2FORM(xsrsqrtedp
, 0x14, 0x04, PPC2_VSX
),
10362 GEN_XX3FORM(xstdivdp
, 0x14, 0x07, PPC2_VSX
),
10363 GEN_XX2FORM(xstsqrtdp
, 0x14, 0x06, PPC2_VSX
),
10364 GEN_XX3FORM(xsmaddadp
, 0x04, 0x04, PPC2_VSX
),
10365 GEN_XX3FORM(xsmaddmdp
, 0x04, 0x05, PPC2_VSX
),
10366 GEN_XX3FORM(xsmsubadp
, 0x04, 0x06, PPC2_VSX
),
10367 GEN_XX3FORM(xsmsubmdp
, 0x04, 0x07, PPC2_VSX
),
10368 GEN_XX3FORM(xsnmaddadp
, 0x04, 0x14, PPC2_VSX
),
10369 GEN_XX3FORM(xsnmaddmdp
, 0x04, 0x15, PPC2_VSX
),
10370 GEN_XX3FORM(xsnmsubadp
, 0x04, 0x16, PPC2_VSX
),
10371 GEN_XX3FORM(xsnmsubmdp
, 0x04, 0x17, PPC2_VSX
),
10372 GEN_XX2FORM(xscmpodp
, 0x0C, 0x05, PPC2_VSX
),
10373 GEN_XX2FORM(xscmpudp
, 0x0C, 0x04, PPC2_VSX
),
10374 GEN_XX3FORM(xsmaxdp
, 0x00, 0x14, PPC2_VSX
),
10375 GEN_XX3FORM(xsmindp
, 0x00, 0x15, PPC2_VSX
),
10376 GEN_XX2FORM(xscvdpsp
, 0x12, 0x10, PPC2_VSX
),
10377 GEN_XX2FORM(xscvdpspn
, 0x16, 0x10, PPC2_VSX207
),
10378 GEN_XX2FORM(xscvspdp
, 0x12, 0x14, PPC2_VSX
),
10379 GEN_XX2FORM(xscvspdpn
, 0x16, 0x14, PPC2_VSX207
),
10380 GEN_XX2FORM(xscvdpsxds
, 0x10, 0x15, PPC2_VSX
),
10381 GEN_XX2FORM(xscvdpsxws
, 0x10, 0x05, PPC2_VSX
),
10382 GEN_XX2FORM(xscvdpuxds
, 0x10, 0x14, PPC2_VSX
),
10383 GEN_XX2FORM(xscvdpuxws
, 0x10, 0x04, PPC2_VSX
),
10384 GEN_XX2FORM(xscvsxddp
, 0x10, 0x17, PPC2_VSX
),
10385 GEN_XX2FORM(xscvuxddp
, 0x10, 0x16, PPC2_VSX
),
10386 GEN_XX2FORM(xsrdpi
, 0x12, 0x04, PPC2_VSX
),
10387 GEN_XX2FORM(xsrdpic
, 0x16, 0x06, PPC2_VSX
),
10388 GEN_XX2FORM(xsrdpim
, 0x12, 0x07, PPC2_VSX
),
10389 GEN_XX2FORM(xsrdpip
, 0x12, 0x06, PPC2_VSX
),
10390 GEN_XX2FORM(xsrdpiz
, 0x12, 0x05, PPC2_VSX
),
10392 GEN_XX3FORM(xsaddsp
, 0x00, 0x00, PPC2_VSX207
),
10393 GEN_XX3FORM(xssubsp
, 0x00, 0x01, PPC2_VSX207
),
10394 GEN_XX3FORM(xsmulsp
, 0x00, 0x02, PPC2_VSX207
),
10395 GEN_XX3FORM(xsdivsp
, 0x00, 0x03, PPC2_VSX207
),
10396 GEN_XX2FORM(xsresp
, 0x14, 0x01, PPC2_VSX207
),
10397 GEN_XX2FORM(xsrsp
, 0x12, 0x11, PPC2_VSX207
),
10398 GEN_XX2FORM(xssqrtsp
, 0x16, 0x00, PPC2_VSX207
),
10399 GEN_XX2FORM(xsrsqrtesp
, 0x14, 0x00, PPC2_VSX207
),
10400 GEN_XX3FORM(xsmaddasp
, 0x04, 0x00, PPC2_VSX207
),
10401 GEN_XX3FORM(xsmaddmsp
, 0x04, 0x01, PPC2_VSX207
),
10402 GEN_XX3FORM(xsmsubasp
, 0x04, 0x02, PPC2_VSX207
),
10403 GEN_XX3FORM(xsmsubmsp
, 0x04, 0x03, PPC2_VSX207
),
10404 GEN_XX3FORM(xsnmaddasp
, 0x04, 0x10, PPC2_VSX207
),
10405 GEN_XX3FORM(xsnmaddmsp
, 0x04, 0x11, PPC2_VSX207
),
10406 GEN_XX3FORM(xsnmsubasp
, 0x04, 0x12, PPC2_VSX207
),
10407 GEN_XX3FORM(xsnmsubmsp
, 0x04, 0x13, PPC2_VSX207
),
10408 GEN_XX2FORM(xscvsxdsp
, 0x10, 0x13, PPC2_VSX207
),
10409 GEN_XX2FORM(xscvuxdsp
, 0x10, 0x12, PPC2_VSX207
),
10411 GEN_XX3FORM(xvadddp
, 0x00, 0x0C, PPC2_VSX
),
10412 GEN_XX3FORM(xvsubdp
, 0x00, 0x0D, PPC2_VSX
),
10413 GEN_XX3FORM(xvmuldp
, 0x00, 0x0E, PPC2_VSX
),
10414 GEN_XX3FORM(xvdivdp
, 0x00, 0x0F, PPC2_VSX
),
10415 GEN_XX2FORM(xvredp
, 0x14, 0x0D, PPC2_VSX
),
10416 GEN_XX2FORM(xvsqrtdp
, 0x16, 0x0C, PPC2_VSX
),
10417 GEN_XX2FORM(xvrsqrtedp
, 0x14, 0x0C, PPC2_VSX
),
10418 GEN_XX3FORM(xvtdivdp
, 0x14, 0x0F, PPC2_VSX
),
10419 GEN_XX2FORM(xvtsqrtdp
, 0x14, 0x0E, PPC2_VSX
),
10420 GEN_XX3FORM(xvmaddadp
, 0x04, 0x0C, PPC2_VSX
),
10421 GEN_XX3FORM(xvmaddmdp
, 0x04, 0x0D, PPC2_VSX
),
10422 GEN_XX3FORM(xvmsubadp
, 0x04, 0x0E, PPC2_VSX
),
10423 GEN_XX3FORM(xvmsubmdp
, 0x04, 0x0F, PPC2_VSX
),
10424 GEN_XX3FORM(xvnmaddadp
, 0x04, 0x1C, PPC2_VSX
),
10425 GEN_XX3FORM(xvnmaddmdp
, 0x04, 0x1D, PPC2_VSX
),
10426 GEN_XX3FORM(xvnmsubadp
, 0x04, 0x1E, PPC2_VSX
),
10427 GEN_XX3FORM(xvnmsubmdp
, 0x04, 0x1F, PPC2_VSX
),
10428 GEN_XX3FORM(xvmaxdp
, 0x00, 0x1C, PPC2_VSX
),
10429 GEN_XX3FORM(xvmindp
, 0x00, 0x1D, PPC2_VSX
),
10430 GEN_XX3_RC_FORM(xvcmpeqdp
, 0x0C, 0x0C, PPC2_VSX
),
10431 GEN_XX3_RC_FORM(xvcmpgtdp
, 0x0C, 0x0D, PPC2_VSX
),
10432 GEN_XX3_RC_FORM(xvcmpgedp
, 0x0C, 0x0E, PPC2_VSX
),
10433 GEN_XX2FORM(xvcvdpsp
, 0x12, 0x18, PPC2_VSX
),
10434 GEN_XX2FORM(xvcvdpsxds
, 0x10, 0x1D, PPC2_VSX
),
10435 GEN_XX2FORM(xvcvdpsxws
, 0x10, 0x0D, PPC2_VSX
),
10436 GEN_XX2FORM(xvcvdpuxds
, 0x10, 0x1C, PPC2_VSX
),
10437 GEN_XX2FORM(xvcvdpuxws
, 0x10, 0x0C, PPC2_VSX
),
10438 GEN_XX2FORM(xvcvsxddp
, 0x10, 0x1F, PPC2_VSX
),
10439 GEN_XX2FORM(xvcvuxddp
, 0x10, 0x1E, PPC2_VSX
),
10440 GEN_XX2FORM(xvcvsxwdp
, 0x10, 0x0F, PPC2_VSX
),
10441 GEN_XX2FORM(xvcvuxwdp
, 0x10, 0x0E, PPC2_VSX
),
10442 GEN_XX2FORM(xvrdpi
, 0x12, 0x0C, PPC2_VSX
),
10443 GEN_XX2FORM(xvrdpic
, 0x16, 0x0E, PPC2_VSX
),
10444 GEN_XX2FORM(xvrdpim
, 0x12, 0x0F, PPC2_VSX
),
10445 GEN_XX2FORM(xvrdpip
, 0x12, 0x0E, PPC2_VSX
),
10446 GEN_XX2FORM(xvrdpiz
, 0x12, 0x0D, PPC2_VSX
),
10448 GEN_XX3FORM(xvaddsp
, 0x00, 0x08, PPC2_VSX
),
10449 GEN_XX3FORM(xvsubsp
, 0x00, 0x09, PPC2_VSX
),
10450 GEN_XX3FORM(xvmulsp
, 0x00, 0x0A, PPC2_VSX
),
10451 GEN_XX3FORM(xvdivsp
, 0x00, 0x0B, PPC2_VSX
),
10452 GEN_XX2FORM(xvresp
, 0x14, 0x09, PPC2_VSX
),
10453 GEN_XX2FORM(xvsqrtsp
, 0x16, 0x08, PPC2_VSX
),
10454 GEN_XX2FORM(xvrsqrtesp
, 0x14, 0x08, PPC2_VSX
),
10455 GEN_XX3FORM(xvtdivsp
, 0x14, 0x0B, PPC2_VSX
),
10456 GEN_XX2FORM(xvtsqrtsp
, 0x14, 0x0A, PPC2_VSX
),
10457 GEN_XX3FORM(xvmaddasp
, 0x04, 0x08, PPC2_VSX
),
10458 GEN_XX3FORM(xvmaddmsp
, 0x04, 0x09, PPC2_VSX
),
10459 GEN_XX3FORM(xvmsubasp
, 0x04, 0x0A, PPC2_VSX
),
10460 GEN_XX3FORM(xvmsubmsp
, 0x04, 0x0B, PPC2_VSX
),
10461 GEN_XX3FORM(xvnmaddasp
, 0x04, 0x18, PPC2_VSX
),
10462 GEN_XX3FORM(xvnmaddmsp
, 0x04, 0x19, PPC2_VSX
),
10463 GEN_XX3FORM(xvnmsubasp
, 0x04, 0x1A, PPC2_VSX
),
10464 GEN_XX3FORM(xvnmsubmsp
, 0x04, 0x1B, PPC2_VSX
),
10465 GEN_XX3FORM(xvmaxsp
, 0x00, 0x18, PPC2_VSX
),
10466 GEN_XX3FORM(xvminsp
, 0x00, 0x19, PPC2_VSX
),
10467 GEN_XX3_RC_FORM(xvcmpeqsp
, 0x0C, 0x08, PPC2_VSX
),
10468 GEN_XX3_RC_FORM(xvcmpgtsp
, 0x0C, 0x09, PPC2_VSX
),
10469 GEN_XX3_RC_FORM(xvcmpgesp
, 0x0C, 0x0A, PPC2_VSX
),
10470 GEN_XX2FORM(xvcvspdp
, 0x12, 0x1C, PPC2_VSX
),
10471 GEN_XX2FORM(xvcvspsxds
, 0x10, 0x19, PPC2_VSX
),
10472 GEN_XX2FORM(xvcvspsxws
, 0x10, 0x09, PPC2_VSX
),
10473 GEN_XX2FORM(xvcvspuxds
, 0x10, 0x18, PPC2_VSX
),
10474 GEN_XX2FORM(xvcvspuxws
, 0x10, 0x08, PPC2_VSX
),
10475 GEN_XX2FORM(xvcvsxdsp
, 0x10, 0x1B, PPC2_VSX
),
10476 GEN_XX2FORM(xvcvuxdsp
, 0x10, 0x1A, PPC2_VSX
),
10477 GEN_XX2FORM(xvcvsxwsp
, 0x10, 0x0B, PPC2_VSX
),
10478 GEN_XX2FORM(xvcvuxwsp
, 0x10, 0x0A, PPC2_VSX
),
10479 GEN_XX2FORM(xvrspi
, 0x12, 0x08, PPC2_VSX
),
10480 GEN_XX2FORM(xvrspic
, 0x16, 0x0A, PPC2_VSX
),
10481 GEN_XX2FORM(xvrspim
, 0x12, 0x0B, PPC2_VSX
),
10482 GEN_XX2FORM(xvrspip
, 0x12, 0x0A, PPC2_VSX
),
10483 GEN_XX2FORM(xvrspiz
, 0x12, 0x09, PPC2_VSX
),
10486 #define VSX_LOGICAL(name, opc2, opc3, fl2) \
10487 GEN_XX3FORM(name, opc2, opc3, fl2)
10489 VSX_LOGICAL(xxland
, 0x8, 0x10, PPC2_VSX
),
10490 VSX_LOGICAL(xxlandc
, 0x8, 0x11, PPC2_VSX
),
10491 VSX_LOGICAL(xxlor
, 0x8, 0x12, PPC2_VSX
),
10492 VSX_LOGICAL(xxlxor
, 0x8, 0x13, PPC2_VSX
),
10493 VSX_LOGICAL(xxlnor
, 0x8, 0x14, PPC2_VSX
),
10494 VSX_LOGICAL(xxleqv
, 0x8, 0x17, PPC2_VSX207
),
10495 VSX_LOGICAL(xxlnand
, 0x8, 0x16, PPC2_VSX207
),
10496 VSX_LOGICAL(xxlorc
, 0x8, 0x15, PPC2_VSX207
),
10497 GEN_XX3FORM(xxmrghw
, 0x08, 0x02, PPC2_VSX
),
10498 GEN_XX3FORM(xxmrglw
, 0x08, 0x06, PPC2_VSX
),
10499 GEN_XX2FORM(xxspltw
, 0x08, 0x0A, PPC2_VSX
),
10500 GEN_XX3FORM_DM(xxsldwi
, 0x08, 0x00),
10502 #define GEN_XXSEL_ROW(opc3) \
10503 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x18, opc3, 0, PPC_NONE, PPC2_VSX), \
10504 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x19, opc3, 0, PPC_NONE, PPC2_VSX), \
10505 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1A, opc3, 0, PPC_NONE, PPC2_VSX), \
10506 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1B, opc3, 0, PPC_NONE, PPC2_VSX), \
10507 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1C, opc3, 0, PPC_NONE, PPC2_VSX), \
10508 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1D, opc3, 0, PPC_NONE, PPC2_VSX), \
10509 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1E, opc3, 0, PPC_NONE, PPC2_VSX), \
10510 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1F, opc3, 0, PPC_NONE, PPC2_VSX), \
10512 GEN_XXSEL_ROW(0x00)
10513 GEN_XXSEL_ROW(0x01)
10514 GEN_XXSEL_ROW(0x02)
10515 GEN_XXSEL_ROW(0x03)
10516 GEN_XXSEL_ROW(0x04)
10517 GEN_XXSEL_ROW(0x05)
10518 GEN_XXSEL_ROW(0x06)
10519 GEN_XXSEL_ROW(0x07)
10520 GEN_XXSEL_ROW(0x08)
10521 GEN_XXSEL_ROW(0x09)
10522 GEN_XXSEL_ROW(0x0A)
10523 GEN_XXSEL_ROW(0x0B)
10524 GEN_XXSEL_ROW(0x0C)
10525 GEN_XXSEL_ROW(0x0D)
10526 GEN_XXSEL_ROW(0x0E)
10527 GEN_XXSEL_ROW(0x0F)
10528 GEN_XXSEL_ROW(0x10)
10529 GEN_XXSEL_ROW(0x11)
10530 GEN_XXSEL_ROW(0x12)
10531 GEN_XXSEL_ROW(0x13)
10532 GEN_XXSEL_ROW(0x14)
10533 GEN_XXSEL_ROW(0x15)
10534 GEN_XXSEL_ROW(0x16)
10535 GEN_XXSEL_ROW(0x17)
10536 GEN_XXSEL_ROW(0x18)
10537 GEN_XXSEL_ROW(0x19)
10538 GEN_XXSEL_ROW(0x1A)
10539 GEN_XXSEL_ROW(0x1B)
10540 GEN_XXSEL_ROW(0x1C)
10541 GEN_XXSEL_ROW(0x1D)
10542 GEN_XXSEL_ROW(0x1E)
10543 GEN_XXSEL_ROW(0x1F)
10545 GEN_XX3FORM_DM(xxpermdi
, 0x08, 0x01),
10548 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
10549 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
10550 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10551 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10552 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10553 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10554 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
10555 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
10556 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
10557 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE
),
10558 GEN_SPE(evmra
, speundef
, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE
),
10559 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
),
10560 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10561 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
10562 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
10563 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE
),
10564 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE
),
10565 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE
),
10566 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
),
10567 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10568 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
10569 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
10570 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10571 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
10572 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE
),
10573 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE
),
10574 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
10575 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
10576 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE
),
10577 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE
),
10578 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE
),
10580 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
10581 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
),
10582 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
),
10583 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
10584 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
10585 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
10586 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
10587 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
10588 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
10589 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
10590 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
10591 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
10592 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
10593 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
10595 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
10596 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
),
10597 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
),
10598 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
10599 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
10600 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE
),
10601 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
10602 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
10603 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
10604 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
10605 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
10606 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
10607 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
10608 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
10610 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
),
10611 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
10612 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE
),
10613 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
10614 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
),
10615 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
10616 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
),
10617 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE
),
10618 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
10619 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
10620 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
10621 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
10622 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
10623 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
10624 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
),
10625 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
10627 #undef GEN_SPEOP_LDST
10628 #define GEN_SPEOP_LDST(name, opc2, sh) \
10629 GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
10630 GEN_SPEOP_LDST(evldd
, 0x00, 3),
10631 GEN_SPEOP_LDST(evldw
, 0x01, 3),
10632 GEN_SPEOP_LDST(evldh
, 0x02, 3),
10633 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1),
10634 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1),
10635 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1),
10636 GEN_SPEOP_LDST(evlwhe
, 0x08, 2),
10637 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2),
10638 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2),
10639 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2),
10640 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2),
10642 GEN_SPEOP_LDST(evstdd
, 0x10, 3),
10643 GEN_SPEOP_LDST(evstdw
, 0x11, 3),
10644 GEN_SPEOP_LDST(evstdh
, 0x12, 3),
10645 GEN_SPEOP_LDST(evstwhe
, 0x18, 2),
10646 GEN_SPEOP_LDST(evstwho
, 0x1A, 2),
10647 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2),
10648 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2),
10651 #include "helper_regs.h"
10652 #include "translate_init.c"
10654 /*****************************************************************************/
10655 /* Misc PowerPC helpers */
10656 void ppc_cpu_dump_state(CPUState
*cs
, FILE *f
, fprintf_function cpu_fprintf
,
10662 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
10663 CPUPPCState
*env
= &cpu
->env
;
10666 cpu_fprintf(f
, "NIP " TARGET_FMT_lx
" LR " TARGET_FMT_lx
" CTR "
10667 TARGET_FMT_lx
" XER " TARGET_FMT_lx
"\n",
10668 env
->nip
, env
->lr
, env
->ctr
, cpu_read_xer(env
));
10669 cpu_fprintf(f
, "MSR " TARGET_FMT_lx
" HID0 " TARGET_FMT_lx
" HF "
10670 TARGET_FMT_lx
" idx %d\n", env
->msr
, env
->spr
[SPR_HID0
],
10671 env
->hflags
, env
->mmu_idx
);
10672 #if !defined(NO_TIMER_DUMP)
10673 cpu_fprintf(f
, "TB %08" PRIu32
" %08" PRIu64
10674 #if !defined(CONFIG_USER_ONLY)
10678 cpu_ppc_load_tbu(env
), cpu_ppc_load_tbl(env
)
10679 #if !defined(CONFIG_USER_ONLY)
10680 , cpu_ppc_load_decr(env
)
10684 for (i
= 0; i
< 32; i
++) {
10685 if ((i
& (RGPL
- 1)) == 0)
10686 cpu_fprintf(f
, "GPR%02d", i
);
10687 cpu_fprintf(f
, " %016" PRIx64
, ppc_dump_gpr(env
, i
));
10688 if ((i
& (RGPL
- 1)) == (RGPL
- 1))
10689 cpu_fprintf(f
, "\n");
10691 cpu_fprintf(f
, "CR ");
10692 for (i
= 0; i
< 8; i
++)
10693 cpu_fprintf(f
, "%01x", env
->crf
[i
]);
10694 cpu_fprintf(f
, " [");
10695 for (i
= 0; i
< 8; i
++) {
10697 if (env
->crf
[i
] & 0x08)
10699 else if (env
->crf
[i
] & 0x04)
10701 else if (env
->crf
[i
] & 0x02)
10703 cpu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
10705 cpu_fprintf(f
, " ] RES " TARGET_FMT_lx
"\n",
10706 env
->reserve_addr
);
10707 for (i
= 0; i
< 32; i
++) {
10708 if ((i
& (RFPL
- 1)) == 0)
10709 cpu_fprintf(f
, "FPR%02d", i
);
10710 cpu_fprintf(f
, " %016" PRIx64
, *((uint64_t *)&env
->fpr
[i
]));
10711 if ((i
& (RFPL
- 1)) == (RFPL
- 1))
10712 cpu_fprintf(f
, "\n");
10714 cpu_fprintf(f
, "FPSCR " TARGET_FMT_lx
"\n", env
->fpscr
);
10715 #if !defined(CONFIG_USER_ONLY)
10716 cpu_fprintf(f
, " SRR0 " TARGET_FMT_lx
" SRR1 " TARGET_FMT_lx
10717 " PVR " TARGET_FMT_lx
" VRSAVE " TARGET_FMT_lx
"\n",
10718 env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
10719 env
->spr
[SPR_PVR
], env
->spr
[SPR_VRSAVE
]);
10721 cpu_fprintf(f
, "SPRG0 " TARGET_FMT_lx
" SPRG1 " TARGET_FMT_lx
10722 " SPRG2 " TARGET_FMT_lx
" SPRG3 " TARGET_FMT_lx
"\n",
10723 env
->spr
[SPR_SPRG0
], env
->spr
[SPR_SPRG1
],
10724 env
->spr
[SPR_SPRG2
], env
->spr
[SPR_SPRG3
]);
10726 cpu_fprintf(f
, "SPRG4 " TARGET_FMT_lx
" SPRG5 " TARGET_FMT_lx
10727 " SPRG6 " TARGET_FMT_lx
" SPRG7 " TARGET_FMT_lx
"\n",
10728 env
->spr
[SPR_SPRG4
], env
->spr
[SPR_SPRG5
],
10729 env
->spr
[SPR_SPRG6
], env
->spr
[SPR_SPRG7
]);
10731 if (env
->excp_model
== POWERPC_EXCP_BOOKE
) {
10732 cpu_fprintf(f
, "CSRR0 " TARGET_FMT_lx
" CSRR1 " TARGET_FMT_lx
10733 " MCSRR0 " TARGET_FMT_lx
" MCSRR1 " TARGET_FMT_lx
"\n",
10734 env
->spr
[SPR_BOOKE_CSRR0
], env
->spr
[SPR_BOOKE_CSRR1
],
10735 env
->spr
[SPR_BOOKE_MCSRR0
], env
->spr
[SPR_BOOKE_MCSRR1
]);
10737 cpu_fprintf(f
, " TCR " TARGET_FMT_lx
" TSR " TARGET_FMT_lx
10738 " ESR " TARGET_FMT_lx
" DEAR " TARGET_FMT_lx
"\n",
10739 env
->spr
[SPR_BOOKE_TCR
], env
->spr
[SPR_BOOKE_TSR
],
10740 env
->spr
[SPR_BOOKE_ESR
], env
->spr
[SPR_BOOKE_DEAR
]);
10742 cpu_fprintf(f
, " PIR " TARGET_FMT_lx
" DECAR " TARGET_FMT_lx
10743 " IVPR " TARGET_FMT_lx
" EPCR " TARGET_FMT_lx
"\n",
10744 env
->spr
[SPR_BOOKE_PIR
], env
->spr
[SPR_BOOKE_DECAR
],
10745 env
->spr
[SPR_BOOKE_IVPR
], env
->spr
[SPR_BOOKE_EPCR
]);
10747 cpu_fprintf(f
, " MCSR " TARGET_FMT_lx
" SPRG8 " TARGET_FMT_lx
10748 " EPR " TARGET_FMT_lx
"\n",
10749 env
->spr
[SPR_BOOKE_MCSR
], env
->spr
[SPR_BOOKE_SPRG8
],
10750 env
->spr
[SPR_BOOKE_EPR
]);
10753 cpu_fprintf(f
, " MCAR " TARGET_FMT_lx
" PID1 " TARGET_FMT_lx
10754 " PID2 " TARGET_FMT_lx
" SVR " TARGET_FMT_lx
"\n",
10755 env
->spr
[SPR_Exxx_MCAR
], env
->spr
[SPR_BOOKE_PID1
],
10756 env
->spr
[SPR_BOOKE_PID2
], env
->spr
[SPR_E500_SVR
]);
10759 * IVORs are left out as they are large and do not change often --
10760 * they can be read with "p $ivor0", "p $ivor1", etc.
10764 #if defined(TARGET_PPC64)
10765 if (env
->flags
& POWERPC_FLAG_CFAR
) {
10766 cpu_fprintf(f
, " CFAR " TARGET_FMT_lx
"\n", env
->cfar
);
10770 switch (env
->mmu_model
) {
10771 case POWERPC_MMU_32B
:
10772 case POWERPC_MMU_601
:
10773 case POWERPC_MMU_SOFT_6xx
:
10774 case POWERPC_MMU_SOFT_74xx
:
10775 #if defined(TARGET_PPC64)
10776 case POWERPC_MMU_64B
:
10777 case POWERPC_MMU_2_06
:
10778 case POWERPC_MMU_2_06a
:
10779 case POWERPC_MMU_2_06d
:
10781 cpu_fprintf(f
, " SDR1 " TARGET_FMT_lx
" DAR " TARGET_FMT_lx
10782 " DSISR " TARGET_FMT_lx
"\n", env
->spr
[SPR_SDR1
],
10783 env
->spr
[SPR_DAR
], env
->spr
[SPR_DSISR
]);
10785 case POWERPC_MMU_BOOKE206
:
10786 cpu_fprintf(f
, " MAS0 " TARGET_FMT_lx
" MAS1 " TARGET_FMT_lx
10787 " MAS2 " TARGET_FMT_lx
" MAS3 " TARGET_FMT_lx
"\n",
10788 env
->spr
[SPR_BOOKE_MAS0
], env
->spr
[SPR_BOOKE_MAS1
],
10789 env
->spr
[SPR_BOOKE_MAS2
], env
->spr
[SPR_BOOKE_MAS3
]);
10791 cpu_fprintf(f
, " MAS4 " TARGET_FMT_lx
" MAS6 " TARGET_FMT_lx
10792 " MAS7 " TARGET_FMT_lx
" PID " TARGET_FMT_lx
"\n",
10793 env
->spr
[SPR_BOOKE_MAS4
], env
->spr
[SPR_BOOKE_MAS6
],
10794 env
->spr
[SPR_BOOKE_MAS7
], env
->spr
[SPR_BOOKE_PID
]);
10796 cpu_fprintf(f
, "MMUCFG " TARGET_FMT_lx
" TLB0CFG " TARGET_FMT_lx
10797 " TLB1CFG " TARGET_FMT_lx
"\n",
10798 env
->spr
[SPR_MMUCFG
], env
->spr
[SPR_BOOKE_TLB0CFG
],
10799 env
->spr
[SPR_BOOKE_TLB1CFG
]);
10810 void ppc_cpu_dump_statistics(CPUState
*cs
, FILE*f
,
10811 fprintf_function cpu_fprintf
, int flags
)
10813 #if defined(DO_PPC_STATISTICS)
10814 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
10815 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
10818 t1
= cpu
->env
.opcodes
;
10819 for (op1
= 0; op1
< 64; op1
++) {
10821 if (is_indirect_opcode(handler
)) {
10822 t2
= ind_table(handler
);
10823 for (op2
= 0; op2
< 32; op2
++) {
10825 if (is_indirect_opcode(handler
)) {
10826 t3
= ind_table(handler
);
10827 for (op3
= 0; op3
< 32; op3
++) {
10829 if (handler
->count
== 0)
10831 cpu_fprintf(f
, "%02x %02x %02x (%02x %04d) %16s: "
10832 "%016" PRIx64
" %" PRId64
"\n",
10833 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
10835 handler
->count
, handler
->count
);
10838 if (handler
->count
== 0)
10840 cpu_fprintf(f
, "%02x %02x (%02x %04d) %16s: "
10841 "%016" PRIx64
" %" PRId64
"\n",
10842 op1
, op2
, op1
, op2
, handler
->oname
,
10843 handler
->count
, handler
->count
);
10847 if (handler
->count
== 0)
10849 cpu_fprintf(f
, "%02x (%02x ) %16s: %016" PRIx64
10851 op1
, op1
, handler
->oname
,
10852 handler
->count
, handler
->count
);
10858 /*****************************************************************************/
10859 static inline void gen_intermediate_code_internal(PowerPCCPU
*cpu
,
10860 TranslationBlock
*tb
,
10863 CPUState
*cs
= CPU(cpu
);
10864 CPUPPCState
*env
= &cpu
->env
;
10865 DisasContext ctx
, *ctxp
= &ctx
;
10866 opc_handler_t
**table
, *handler
;
10867 target_ulong pc_start
;
10868 uint16_t *gen_opc_end
;
10875 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
10876 ctx
.nip
= pc_start
;
10878 ctx
.exception
= POWERPC_EXCP_NONE
;
10879 ctx
.spr_cb
= env
->spr_cb
;
10880 ctx
.mem_idx
= env
->mmu_idx
;
10881 ctx
.insns_flags
= env
->insns_flags
;
10882 ctx
.insns_flags2
= env
->insns_flags2
;
10883 ctx
.access_type
= -1;
10884 ctx
.le_mode
= env
->hflags
& (1 << MSR_LE
) ? 1 : 0;
10885 #if defined(TARGET_PPC64)
10886 ctx
.sf_mode
= msr_is_64bit(env
, env
->msr
);
10887 ctx
.has_cfar
= !!(env
->flags
& POWERPC_FLAG_CFAR
);
10889 ctx
.fpu_enabled
= msr_fp
;
10890 if ((env
->flags
& POWERPC_FLAG_SPE
) && msr_spe
)
10891 ctx
.spe_enabled
= msr_spe
;
10893 ctx
.spe_enabled
= 0;
10894 if ((env
->flags
& POWERPC_FLAG_VRE
) && msr_vr
)
10895 ctx
.altivec_enabled
= msr_vr
;
10897 ctx
.altivec_enabled
= 0;
10898 if ((env
->flags
& POWERPC_FLAG_VSX
) && msr_vsx
) {
10899 ctx
.vsx_enabled
= msr_vsx
;
10901 ctx
.vsx_enabled
= 0;
10903 if ((env
->flags
& POWERPC_FLAG_SE
) && msr_se
)
10904 ctx
.singlestep_enabled
= CPU_SINGLE_STEP
;
10906 ctx
.singlestep_enabled
= 0;
10907 if ((env
->flags
& POWERPC_FLAG_BE
) && msr_be
)
10908 ctx
.singlestep_enabled
|= CPU_BRANCH_STEP
;
10909 if (unlikely(cs
->singlestep_enabled
)) {
10910 ctx
.singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
10912 #if defined (DO_SINGLE_STEP) && 0
10913 /* Single step trace mode */
10917 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
10918 if (max_insns
== 0)
10919 max_insns
= CF_COUNT_MASK
;
10922 /* Set env in case of segfault during code fetch */
10923 while (ctx
.exception
== POWERPC_EXCP_NONE
10924 && tcg_ctx
.gen_opc_ptr
< gen_opc_end
) {
10925 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
10926 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
10927 if (bp
->pc
== ctx
.nip
) {
10928 gen_debug_exception(ctxp
);
10933 if (unlikely(search_pc
)) {
10934 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
10938 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
10940 tcg_ctx
.gen_opc_pc
[lj
] = ctx
.nip
;
10941 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
10942 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
10944 LOG_DISAS("----------------\n");
10945 LOG_DISAS("nip=" TARGET_FMT_lx
" super=%d ir=%d\n",
10946 ctx
.nip
, ctx
.mem_idx
, (int)msr_ir
);
10947 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
10949 if (unlikely(ctx
.le_mode
)) {
10950 ctx
.opcode
= bswap32(cpu_ldl_code(env
, ctx
.nip
));
10952 ctx
.opcode
= cpu_ldl_code(env
, ctx
.nip
);
10954 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
10955 ctx
.opcode
, opc1(ctx
.opcode
), opc2(ctx
.opcode
),
10956 opc3(ctx
.opcode
), ctx
.le_mode
? "little" : "big");
10957 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
10958 tcg_gen_debug_insn_start(ctx
.nip
);
10961 table
= env
->opcodes
;
10963 handler
= table
[opc1(ctx
.opcode
)];
10964 if (is_indirect_opcode(handler
)) {
10965 table
= ind_table(handler
);
10966 handler
= table
[opc2(ctx
.opcode
)];
10967 if (is_indirect_opcode(handler
)) {
10968 table
= ind_table(handler
);
10969 handler
= table
[opc3(ctx
.opcode
)];
10972 /* Is opcode *REALLY* valid ? */
10973 if (unlikely(handler
->handler
== &gen_invalid
)) {
10974 if (qemu_log_enabled()) {
10975 qemu_log("invalid/unsupported opcode: "
10976 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx
" %d\n",
10977 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
10978 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
10983 if (unlikely(handler
->type
& (PPC_SPE
| PPC_SPE_SINGLE
| PPC_SPE_DOUBLE
) && Rc(ctx
.opcode
))) {
10984 inval
= handler
->inval2
;
10986 inval
= handler
->inval1
;
10989 if (unlikely((ctx
.opcode
& inval
) != 0)) {
10990 if (qemu_log_enabled()) {
10991 qemu_log("invalid bits: %08x for opcode: "
10992 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx
"\n",
10993 ctx
.opcode
& inval
, opc1(ctx
.opcode
),
10994 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
10995 ctx
.opcode
, ctx
.nip
- 4);
10997 gen_inval_exception(ctxp
, POWERPC_EXCP_INVAL_INVAL
);
11001 (*(handler
->handler
))(&ctx
);
11002 #if defined(DO_PPC_STATISTICS)
11005 /* Check trace mode exceptions */
11006 if (unlikely(ctx
.singlestep_enabled
& CPU_SINGLE_STEP
&&
11007 (ctx
.nip
<= 0x100 || ctx
.nip
> 0xF00) &&
11008 ctx
.exception
!= POWERPC_SYSCALL
&&
11009 ctx
.exception
!= POWERPC_EXCP_TRAP
&&
11010 ctx
.exception
!= POWERPC_EXCP_BRANCH
)) {
11011 gen_exception(ctxp
, POWERPC_EXCP_TRACE
);
11012 } else if (unlikely(((ctx
.nip
& (TARGET_PAGE_SIZE
- 1)) == 0) ||
11013 (cs
->singlestep_enabled
) ||
11015 num_insns
>= max_insns
)) {
11016 /* if we reach a page boundary or are single stepping, stop
11022 if (tb
->cflags
& CF_LAST_IO
)
11024 if (ctx
.exception
== POWERPC_EXCP_NONE
) {
11025 gen_goto_tb(&ctx
, 0, ctx
.nip
);
11026 } else if (ctx
.exception
!= POWERPC_EXCP_BRANCH
) {
11027 if (unlikely(cs
->singlestep_enabled
)) {
11028 gen_debug_exception(ctxp
);
11030 /* Generate the return instruction */
11031 tcg_gen_exit_tb(0);
11033 gen_tb_end(tb
, num_insns
);
11034 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
11035 if (unlikely(search_pc
)) {
11036 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
11039 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
11041 tb
->size
= ctx
.nip
- pc_start
;
11042 tb
->icount
= num_insns
;
11044 #if defined(DEBUG_DISAS)
11045 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
11047 flags
= env
->bfd_mach
;
11048 flags
|= ctx
.le_mode
<< 16;
11049 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
11050 log_target_disas(env
, pc_start
, ctx
.nip
- pc_start
, flags
);
11056 void gen_intermediate_code (CPUPPCState
*env
, struct TranslationBlock
*tb
)
11058 gen_intermediate_code_internal(ppc_env_get_cpu(env
), tb
, false);
11061 void gen_intermediate_code_pc (CPUPPCState
*env
, struct TranslationBlock
*tb
)
11063 gen_intermediate_code_internal(ppc_env_get_cpu(env
), tb
, true);
11066 void restore_state_to_opc(CPUPPCState
*env
, TranslationBlock
*tb
, int pc_pos
)
11068 env
->nip
= tcg_ctx
.gen_opc_pc
[pc_pos
];