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/>.
21 #include "qemu/osdep.h"
23 #include "disas/disas.h"
24 #include "exec/exec-all.h"
26 #include "qemu/host-utils.h"
27 #include "exec/cpu_ldst.h"
29 #include "exec/helper-proto.h"
30 #include "exec/helper-gen.h"
32 #include "trace-tcg.h"
36 #define CPU_SINGLE_STEP 0x1
37 #define CPU_BRANCH_STEP 0x2
38 #define GDBSTUB_SINGLE_STEP 0x4
40 /* Include definitions for instructions classes and implementations flags */
41 //#define PPC_DEBUG_DISAS
42 //#define DO_PPC_STATISTICS
44 #ifdef PPC_DEBUG_DISAS
45 # define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
47 # define LOG_DISAS(...) do { } while (0)
49 /*****************************************************************************/
50 /* Code translation helpers */
52 /* global register indexes */
53 static TCGv_env cpu_env
;
54 static char cpu_reg_names
[10*3 + 22*4 /* GPR */
55 + 10*4 + 22*5 /* SPE GPRh */
56 + 10*4 + 22*5 /* FPR */
57 + 2*(10*6 + 22*7) /* AVRh, AVRl */
58 + 10*5 + 22*6 /* VSR */
60 static TCGv cpu_gpr
[32];
61 static TCGv cpu_gprh
[32];
62 static TCGv_i64 cpu_fpr
[32];
63 static TCGv_i64 cpu_avrh
[32], cpu_avrl
[32];
64 static TCGv_i64 cpu_vsr
[32];
65 static TCGv_i32 cpu_crf
[8];
70 #if defined(TARGET_PPC64)
73 static TCGv cpu_xer
, cpu_so
, cpu_ov
, cpu_ca
;
74 static TCGv cpu_reserve
;
75 static TCGv cpu_fpscr
;
76 static TCGv_i32 cpu_access_type
;
78 #include "exec/gen-icount.h"
80 void ppc_translate_init(void)
84 size_t cpu_reg_names_size
;
85 static int done_init
= 0;
90 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
91 tcg_ctx
.tcg_env
= cpu_env
;
94 cpu_reg_names_size
= sizeof(cpu_reg_names
);
96 for (i
= 0; i
< 8; i
++) {
97 snprintf(p
, cpu_reg_names_size
, "crf%d", i
);
98 cpu_crf
[i
] = tcg_global_mem_new_i32(cpu_env
,
99 offsetof(CPUPPCState
, crf
[i
]), p
);
101 cpu_reg_names_size
-= 5;
104 for (i
= 0; i
< 32; i
++) {
105 snprintf(p
, cpu_reg_names_size
, "r%d", i
);
106 cpu_gpr
[i
] = tcg_global_mem_new(cpu_env
,
107 offsetof(CPUPPCState
, gpr
[i
]), p
);
108 p
+= (i
< 10) ? 3 : 4;
109 cpu_reg_names_size
-= (i
< 10) ? 3 : 4;
110 snprintf(p
, cpu_reg_names_size
, "r%dH", i
);
111 cpu_gprh
[i
] = tcg_global_mem_new(cpu_env
,
112 offsetof(CPUPPCState
, gprh
[i
]), p
);
113 p
+= (i
< 10) ? 4 : 5;
114 cpu_reg_names_size
-= (i
< 10) ? 4 : 5;
116 snprintf(p
, cpu_reg_names_size
, "fp%d", i
);
117 cpu_fpr
[i
] = tcg_global_mem_new_i64(cpu_env
,
118 offsetof(CPUPPCState
, fpr
[i
]), p
);
119 p
+= (i
< 10) ? 4 : 5;
120 cpu_reg_names_size
-= (i
< 10) ? 4 : 5;
122 snprintf(p
, cpu_reg_names_size
, "avr%dH", i
);
123 #ifdef HOST_WORDS_BIGENDIAN
124 cpu_avrh
[i
] = tcg_global_mem_new_i64(cpu_env
,
125 offsetof(CPUPPCState
, avr
[i
].u64
[0]), p
);
127 cpu_avrh
[i
] = tcg_global_mem_new_i64(cpu_env
,
128 offsetof(CPUPPCState
, avr
[i
].u64
[1]), p
);
130 p
+= (i
< 10) ? 6 : 7;
131 cpu_reg_names_size
-= (i
< 10) ? 6 : 7;
133 snprintf(p
, cpu_reg_names_size
, "avr%dL", i
);
134 #ifdef HOST_WORDS_BIGENDIAN
135 cpu_avrl
[i
] = tcg_global_mem_new_i64(cpu_env
,
136 offsetof(CPUPPCState
, avr
[i
].u64
[1]), p
);
138 cpu_avrl
[i
] = tcg_global_mem_new_i64(cpu_env
,
139 offsetof(CPUPPCState
, avr
[i
].u64
[0]), p
);
141 p
+= (i
< 10) ? 6 : 7;
142 cpu_reg_names_size
-= (i
< 10) ? 6 : 7;
143 snprintf(p
, cpu_reg_names_size
, "vsr%d", i
);
144 cpu_vsr
[i
] = tcg_global_mem_new_i64(cpu_env
,
145 offsetof(CPUPPCState
, vsr
[i
]), p
);
146 p
+= (i
< 10) ? 5 : 6;
147 cpu_reg_names_size
-= (i
< 10) ? 5 : 6;
150 cpu_nip
= tcg_global_mem_new(cpu_env
,
151 offsetof(CPUPPCState
, nip
), "nip");
153 cpu_msr
= tcg_global_mem_new(cpu_env
,
154 offsetof(CPUPPCState
, msr
), "msr");
156 cpu_ctr
= tcg_global_mem_new(cpu_env
,
157 offsetof(CPUPPCState
, ctr
), "ctr");
159 cpu_lr
= tcg_global_mem_new(cpu_env
,
160 offsetof(CPUPPCState
, lr
), "lr");
162 #if defined(TARGET_PPC64)
163 cpu_cfar
= tcg_global_mem_new(cpu_env
,
164 offsetof(CPUPPCState
, cfar
), "cfar");
167 cpu_xer
= tcg_global_mem_new(cpu_env
,
168 offsetof(CPUPPCState
, xer
), "xer");
169 cpu_so
= tcg_global_mem_new(cpu_env
,
170 offsetof(CPUPPCState
, so
), "SO");
171 cpu_ov
= tcg_global_mem_new(cpu_env
,
172 offsetof(CPUPPCState
, ov
), "OV");
173 cpu_ca
= tcg_global_mem_new(cpu_env
,
174 offsetof(CPUPPCState
, ca
), "CA");
176 cpu_reserve
= tcg_global_mem_new(cpu_env
,
177 offsetof(CPUPPCState
, reserve_addr
),
180 cpu_fpscr
= tcg_global_mem_new(cpu_env
,
181 offsetof(CPUPPCState
, fpscr
), "fpscr");
183 cpu_access_type
= tcg_global_mem_new_i32(cpu_env
,
184 offsetof(CPUPPCState
, access_type
), "access_type");
189 /* internal defines */
190 struct DisasContext
{
191 struct TranslationBlock
*tb
;
195 /* Routine used to access memory */
196 bool pr
, hv
, dr
, le_mode
;
200 /* Translation flags */
201 TCGMemOp default_tcg_memop_mask
;
202 #if defined(TARGET_PPC64)
207 bool altivec_enabled
;
211 ppc_spr_t
*spr_cb
; /* Needed to check rights for mfspr/mtspr */
212 int singlestep_enabled
;
213 uint64_t insns_flags
;
214 uint64_t insns_flags2
;
217 /* Return true iff byteswap is needed in a scalar memop */
218 static inline bool need_byteswap(const DisasContext
*ctx
)
220 #if defined(TARGET_WORDS_BIGENDIAN)
223 return !ctx
->le_mode
;
227 /* True when active word size < size of target_long. */
229 # define NARROW_MODE(C) (!(C)->sf_mode)
231 # define NARROW_MODE(C) 0
234 struct opc_handler_t
{
235 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
237 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
239 /* instruction type */
241 /* extended instruction type */
244 void (*handler
)(DisasContext
*ctx
);
245 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
248 #if defined(DO_PPC_STATISTICS)
253 static inline void gen_reset_fpstatus(void)
255 gen_helper_reset_fpstatus(cpu_env
);
258 static inline void gen_compute_fprf(TCGv_i64 arg
)
260 gen_helper_compute_fprf(cpu_env
, arg
);
261 gen_helper_float_check_status(cpu_env
);
264 static inline void gen_set_access_type(DisasContext
*ctx
, int access_type
)
266 if (ctx
->access_type
!= access_type
) {
267 tcg_gen_movi_i32(cpu_access_type
, access_type
);
268 ctx
->access_type
= access_type
;
272 static inline void gen_update_nip(DisasContext
*ctx
, target_ulong nip
)
274 if (NARROW_MODE(ctx
)) {
277 tcg_gen_movi_tl(cpu_nip
, nip
);
280 void gen_update_current_nip(void *opaque
)
282 DisasContext
*ctx
= opaque
;
284 tcg_gen_movi_tl(cpu_nip
, ctx
->nip
);
287 static void gen_exception_err(DisasContext
*ctx
, uint32_t excp
, uint32_t error
)
290 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
291 gen_update_nip(ctx
, ctx
->nip
);
293 t0
= tcg_const_i32(excp
);
294 t1
= tcg_const_i32(error
);
295 gen_helper_raise_exception_err(cpu_env
, t0
, t1
);
296 tcg_temp_free_i32(t0
);
297 tcg_temp_free_i32(t1
);
298 ctx
->exception
= (excp
);
301 static void gen_exception(DisasContext
*ctx
, uint32_t excp
)
304 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
305 gen_update_nip(ctx
, ctx
->nip
);
307 t0
= tcg_const_i32(excp
);
308 gen_helper_raise_exception(cpu_env
, t0
);
309 tcg_temp_free_i32(t0
);
310 ctx
->exception
= (excp
);
313 static void gen_debug_exception(DisasContext
*ctx
)
317 if ((ctx
->exception
!= POWERPC_EXCP_BRANCH
) &&
318 (ctx
->exception
!= POWERPC_EXCP_SYNC
)) {
319 gen_update_nip(ctx
, ctx
->nip
);
321 t0
= tcg_const_i32(EXCP_DEBUG
);
322 gen_helper_raise_exception(cpu_env
, t0
);
323 tcg_temp_free_i32(t0
);
326 static inline void gen_inval_exception(DisasContext
*ctx
, uint32_t error
)
328 /* Will be converted to program check if needed */
329 gen_exception_err(ctx
, POWERPC_EXCP_HV_EMU
, POWERPC_EXCP_INVAL
| error
);
332 static inline void gen_priv_exception(DisasContext
*ctx
, uint32_t error
)
334 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_PRIV
| error
);
337 static inline void gen_hvpriv_exception(DisasContext
*ctx
, uint32_t error
)
339 /* Will be converted to program check if needed */
340 gen_exception_err(ctx
, POWERPC_EXCP_HV_EMU
, POWERPC_EXCP_PRIV
| error
);
343 /* Stop translation */
344 static inline void gen_stop_exception(DisasContext
*ctx
)
346 gen_update_nip(ctx
, ctx
->nip
);
347 ctx
->exception
= POWERPC_EXCP_STOP
;
350 #ifndef CONFIG_USER_ONLY
351 /* No need to update nip here, as execution flow will change */
352 static inline void gen_sync_exception(DisasContext
*ctx
)
354 ctx
->exception
= POWERPC_EXCP_SYNC
;
358 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
359 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
361 #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
362 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
364 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
365 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
367 #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
368 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
370 typedef struct opcode_t
{
371 unsigned char opc1
, opc2
, opc3
;
372 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
373 unsigned char pad
[5];
375 unsigned char pad
[1];
377 opc_handler_t handler
;
381 /* Helpers for priv. check */
384 gen_priv_exception(ctx, POWERPC_EXCP_PRIV_OPC); return; \
387 #if defined(CONFIG_USER_ONLY)
388 #define CHK_HV GEN_PRIV
389 #define CHK_SV GEN_PRIV
390 #define CHK_HVRM GEN_PRIV
394 if (unlikely(ctx->pr || !ctx->hv)) { \
400 if (unlikely(ctx->pr)) { \
406 if (unlikely(ctx->pr || !ctx->hv || ctx->dr)) { \
415 /*****************************************************************************/
416 /*** Instruction decoding ***/
417 #define EXTRACT_HELPER(name, shift, nb) \
418 static inline uint32_t name(uint32_t opcode) \
420 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
423 #define EXTRACT_SHELPER(name, shift, nb) \
424 static inline int32_t name(uint32_t opcode) \
426 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
429 #define EXTRACT_HELPER_SPLIT(name, shift1, nb1, shift2, nb2) \
430 static inline uint32_t name(uint32_t opcode) \
432 return (((opcode >> (shift1)) & ((1 << (nb1)) - 1)) << nb2) | \
433 ((opcode >> (shift2)) & ((1 << (nb2)) - 1)); \
436 #define EXTRACT_HELPER_DXFORM(name, \
437 d0_bits, shift_op_d0, shift_d0, \
438 d1_bits, shift_op_d1, shift_d1, \
439 d2_bits, shift_op_d2, shift_d2) \
440 static inline int16_t name(uint32_t opcode) \
443 (((opcode >> (shift_op_d0)) & ((1 << (d0_bits)) - 1)) << (shift_d0)) | \
444 (((opcode >> (shift_op_d1)) & ((1 << (d1_bits)) - 1)) << (shift_d1)) | \
445 (((opcode >> (shift_op_d2)) & ((1 << (d2_bits)) - 1)) << (shift_d2)); \
450 EXTRACT_HELPER(opc1
, 26, 6);
452 EXTRACT_HELPER(opc2
, 1, 5);
454 EXTRACT_HELPER(opc3
, 6, 5);
455 /* Update Cr0 flags */
456 EXTRACT_HELPER(Rc
, 0, 1);
457 /* Update Cr6 flags (Altivec) */
458 EXTRACT_HELPER(Rc21
, 10, 1);
460 EXTRACT_HELPER(rD
, 21, 5);
462 EXTRACT_HELPER(rS
, 21, 5);
464 EXTRACT_HELPER(rA
, 16, 5);
466 EXTRACT_HELPER(rB
, 11, 5);
468 EXTRACT_HELPER(rC
, 6, 5);
470 EXTRACT_HELPER(crfD
, 23, 3);
471 EXTRACT_HELPER(crfS
, 18, 3);
472 EXTRACT_HELPER(crbD
, 21, 5);
473 EXTRACT_HELPER(crbA
, 16, 5);
474 EXTRACT_HELPER(crbB
, 11, 5);
476 EXTRACT_HELPER(_SPR
, 11, 10);
477 static inline uint32_t SPR(uint32_t opcode
)
479 uint32_t sprn
= _SPR(opcode
);
481 return ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
483 /*** Get constants ***/
484 /* 16 bits signed immediate value */
485 EXTRACT_SHELPER(SIMM
, 0, 16);
486 /* 16 bits unsigned immediate value */
487 EXTRACT_HELPER(UIMM
, 0, 16);
488 /* 5 bits signed immediate value */
489 EXTRACT_HELPER(SIMM5
, 16, 5);
490 /* 5 bits signed immediate value */
491 EXTRACT_HELPER(UIMM5
, 16, 5);
493 EXTRACT_HELPER(NB
, 11, 5);
495 EXTRACT_HELPER(SH
, 11, 5);
496 /* Vector shift count */
497 EXTRACT_HELPER(VSH
, 6, 4);
499 EXTRACT_HELPER(MB
, 6, 5);
501 EXTRACT_HELPER(ME
, 1, 5);
503 EXTRACT_HELPER(TO
, 21, 5);
505 EXTRACT_HELPER(CRM
, 12, 8);
507 #ifndef CONFIG_USER_ONLY
508 EXTRACT_HELPER(SR
, 16, 4);
512 EXTRACT_HELPER(FPBF
, 23, 3);
513 EXTRACT_HELPER(FPIMM
, 12, 4);
514 EXTRACT_HELPER(FPL
, 25, 1);
515 EXTRACT_HELPER(FPFLM
, 17, 8);
516 EXTRACT_HELPER(FPW
, 16, 1);
519 EXTRACT_HELPER_DXFORM(DX
, 10, 6, 6, 5, 16, 1, 1, 0, 0)
521 /*** Jump target decoding ***/
522 /* Immediate address */
523 static inline target_ulong
LI(uint32_t opcode
)
525 return (opcode
>> 0) & 0x03FFFFFC;
528 static inline uint32_t BD(uint32_t opcode
)
530 return (opcode
>> 0) & 0xFFFC;
533 EXTRACT_HELPER(BO
, 21, 5);
534 EXTRACT_HELPER(BI
, 16, 5);
535 /* Absolute/relative address */
536 EXTRACT_HELPER(AA
, 1, 1);
538 EXTRACT_HELPER(LK
, 0, 1);
541 EXTRACT_HELPER(DCM
, 10, 6)
544 EXTRACT_HELPER(RMC
, 9, 2)
546 /* Create a mask between <start> and <end> bits */
547 static inline target_ulong
MASK(uint32_t start
, uint32_t end
)
551 #if defined(TARGET_PPC64)
552 if (likely(start
== 0)) {
553 ret
= UINT64_MAX
<< (63 - end
);
554 } else if (likely(end
== 63)) {
555 ret
= UINT64_MAX
>> start
;
558 if (likely(start
== 0)) {
559 ret
= UINT32_MAX
<< (31 - end
);
560 } else if (likely(end
== 31)) {
561 ret
= UINT32_MAX
>> start
;
565 ret
= (((target_ulong
)(-1ULL)) >> (start
)) ^
566 (((target_ulong
)(-1ULL) >> (end
)) >> 1);
567 if (unlikely(start
> end
))
574 EXTRACT_HELPER_SPLIT(xT
, 0, 1, 21, 5);
575 EXTRACT_HELPER_SPLIT(xS
, 0, 1, 21, 5);
576 EXTRACT_HELPER_SPLIT(xA
, 2, 1, 16, 5);
577 EXTRACT_HELPER_SPLIT(xB
, 1, 1, 11, 5);
578 EXTRACT_HELPER_SPLIT(xC
, 3, 1, 6, 5);
579 EXTRACT_HELPER(DM
, 8, 2);
580 EXTRACT_HELPER(UIM
, 16, 2);
581 EXTRACT_HELPER(SHW
, 8, 2);
582 EXTRACT_HELPER(SP
, 19, 2);
583 /*****************************************************************************/
584 /* PowerPC instructions table */
586 #if defined(DO_PPC_STATISTICS)
587 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
597 .handler = &gen_##name, \
598 .oname = stringify(name), \
600 .oname = stringify(name), \
602 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
613 .handler = &gen_##name, \
614 .oname = stringify(name), \
616 .oname = stringify(name), \
618 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
628 .handler = &gen_##name, \
634 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
644 .handler = &gen_##name, \
646 .oname = stringify(name), \
648 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
659 .handler = &gen_##name, \
661 .oname = stringify(name), \
663 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
673 .handler = &gen_##name, \
679 /* SPR load/store helpers */
680 static inline void gen_load_spr(TCGv t
, int reg
)
682 tcg_gen_ld_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
685 static inline void gen_store_spr(int reg
, TCGv t
)
687 tcg_gen_st_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
690 /* Invalid instruction */
691 static void gen_invalid(DisasContext
*ctx
)
693 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
696 static opc_handler_t invalid_handler
= {
697 .inval1
= 0xFFFFFFFF,
698 .inval2
= 0xFFFFFFFF,
701 .handler
= gen_invalid
,
704 /*** Integer comparison ***/
706 static inline void gen_op_cmp(TCGv arg0
, TCGv arg1
, int s
, int crf
)
708 TCGv t0
= tcg_temp_new();
709 TCGv_i32 t1
= tcg_temp_new_i32();
711 tcg_gen_trunc_tl_i32(cpu_crf
[crf
], cpu_so
);
713 tcg_gen_setcond_tl((s
? TCG_COND_LT
: TCG_COND_LTU
), t0
, arg0
, arg1
);
714 tcg_gen_trunc_tl_i32(t1
, t0
);
715 tcg_gen_shli_i32(t1
, t1
, CRF_LT
);
716 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
718 tcg_gen_setcond_tl((s
? TCG_COND_GT
: TCG_COND_GTU
), t0
, arg0
, arg1
);
719 tcg_gen_trunc_tl_i32(t1
, t0
);
720 tcg_gen_shli_i32(t1
, t1
, CRF_GT
);
721 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
723 tcg_gen_setcond_tl(TCG_COND_EQ
, t0
, arg0
, arg1
);
724 tcg_gen_trunc_tl_i32(t1
, t0
);
725 tcg_gen_shli_i32(t1
, t1
, CRF_EQ
);
726 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
729 tcg_temp_free_i32(t1
);
732 static inline void gen_op_cmpi(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
734 TCGv t0
= tcg_const_tl(arg1
);
735 gen_op_cmp(arg0
, t0
, s
, crf
);
739 static inline void gen_op_cmp32(TCGv arg0
, TCGv arg1
, int s
, int crf
)
745 tcg_gen_ext32s_tl(t0
, arg0
);
746 tcg_gen_ext32s_tl(t1
, arg1
);
748 tcg_gen_ext32u_tl(t0
, arg0
);
749 tcg_gen_ext32u_tl(t1
, arg1
);
751 gen_op_cmp(t0
, t1
, s
, crf
);
756 static inline void gen_op_cmpi32(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
758 TCGv t0
= tcg_const_tl(arg1
);
759 gen_op_cmp32(arg0
, t0
, s
, crf
);
763 static inline void gen_set_Rc0(DisasContext
*ctx
, TCGv reg
)
765 if (NARROW_MODE(ctx
)) {
766 gen_op_cmpi32(reg
, 0, 1, 0);
768 gen_op_cmpi(reg
, 0, 1, 0);
773 static void gen_cmp(DisasContext
*ctx
)
775 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
776 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
777 1, crfD(ctx
->opcode
));
779 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
780 1, crfD(ctx
->opcode
));
785 static void gen_cmpi(DisasContext
*ctx
)
787 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
788 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
789 1, crfD(ctx
->opcode
));
791 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
792 1, crfD(ctx
->opcode
));
797 static void gen_cmpl(DisasContext
*ctx
)
799 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
800 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
801 0, crfD(ctx
->opcode
));
803 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
804 0, crfD(ctx
->opcode
));
809 static void gen_cmpli(DisasContext
*ctx
)
811 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
812 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
813 0, crfD(ctx
->opcode
));
815 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
816 0, crfD(ctx
->opcode
));
820 /* cmprb - range comparison: isupper, isaplha, islower*/
821 static void gen_cmprb(DisasContext
*ctx
)
823 TCGv_i32 src1
= tcg_temp_new_i32();
824 TCGv_i32 src2
= tcg_temp_new_i32();
825 TCGv_i32 src2lo
= tcg_temp_new_i32();
826 TCGv_i32 src2hi
= tcg_temp_new_i32();
827 TCGv_i32 crf
= cpu_crf
[crfD(ctx
->opcode
)];
829 tcg_gen_trunc_tl_i32(src1
, cpu_gpr
[rA(ctx
->opcode
)]);
830 tcg_gen_trunc_tl_i32(src2
, cpu_gpr
[rB(ctx
->opcode
)]);
832 tcg_gen_andi_i32(src1
, src1
, 0xFF);
833 tcg_gen_ext8u_i32(src2lo
, src2
);
834 tcg_gen_shri_i32(src2
, src2
, 8);
835 tcg_gen_ext8u_i32(src2hi
, src2
);
837 tcg_gen_setcond_i32(TCG_COND_LEU
, src2lo
, src2lo
, src1
);
838 tcg_gen_setcond_i32(TCG_COND_LEU
, src2hi
, src1
, src2hi
);
839 tcg_gen_and_i32(crf
, src2lo
, src2hi
);
841 if (ctx
->opcode
& 0x00200000) {
842 tcg_gen_shri_i32(src2
, src2
, 8);
843 tcg_gen_ext8u_i32(src2lo
, src2
);
844 tcg_gen_shri_i32(src2
, src2
, 8);
845 tcg_gen_ext8u_i32(src2hi
, src2
);
846 tcg_gen_setcond_i32(TCG_COND_LEU
, src2lo
, src2lo
, src1
);
847 tcg_gen_setcond_i32(TCG_COND_LEU
, src2hi
, src1
, src2hi
);
848 tcg_gen_and_i32(src2lo
, src2lo
, src2hi
);
849 tcg_gen_or_i32(crf
, crf
, src2lo
);
851 tcg_gen_shli_i32(crf
, crf
, CRF_GT
);
852 tcg_temp_free_i32(src1
);
853 tcg_temp_free_i32(src2
);
854 tcg_temp_free_i32(src2lo
);
855 tcg_temp_free_i32(src2hi
);
858 #if defined(TARGET_PPC64)
860 static void gen_cmpeqb(DisasContext
*ctx
)
862 gen_helper_cmpeqb(cpu_crf
[crfD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
863 cpu_gpr
[rB(ctx
->opcode
)]);
867 /* isel (PowerPC 2.03 specification) */
868 static void gen_isel(DisasContext
*ctx
)
870 uint32_t bi
= rC(ctx
->opcode
);
871 uint32_t mask
= 0x08 >> (bi
& 0x03);
872 TCGv t0
= tcg_temp_new();
875 tcg_gen_extu_i32_tl(t0
, cpu_crf
[bi
>> 2]);
876 tcg_gen_andi_tl(t0
, t0
, mask
);
878 zr
= tcg_const_tl(0);
879 tcg_gen_movcond_tl(TCG_COND_NE
, cpu_gpr
[rD(ctx
->opcode
)], t0
, zr
,
880 rA(ctx
->opcode
) ? cpu_gpr
[rA(ctx
->opcode
)] : zr
,
881 cpu_gpr
[rB(ctx
->opcode
)]);
886 /* cmpb: PowerPC 2.05 specification */
887 static void gen_cmpb(DisasContext
*ctx
)
889 gen_helper_cmpb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
890 cpu_gpr
[rB(ctx
->opcode
)]);
893 /*** Integer arithmetic ***/
895 static inline void gen_op_arith_compute_ov(DisasContext
*ctx
, TCGv arg0
,
896 TCGv arg1
, TCGv arg2
, int sub
)
898 TCGv t0
= tcg_temp_new();
900 tcg_gen_xor_tl(cpu_ov
, arg0
, arg2
);
901 tcg_gen_xor_tl(t0
, arg1
, arg2
);
903 tcg_gen_and_tl(cpu_ov
, cpu_ov
, t0
);
905 tcg_gen_andc_tl(cpu_ov
, cpu_ov
, t0
);
908 if (NARROW_MODE(ctx
)) {
909 tcg_gen_ext32s_tl(cpu_ov
, cpu_ov
);
911 tcg_gen_shri_tl(cpu_ov
, cpu_ov
, TARGET_LONG_BITS
- 1);
912 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
915 /* Common add function */
916 static inline void gen_op_arith_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
917 TCGv arg2
, bool add_ca
, bool compute_ca
,
918 bool compute_ov
, bool compute_rc0
)
922 if (compute_ca
|| compute_ov
) {
927 if (NARROW_MODE(ctx
)) {
928 /* Caution: a non-obvious corner case of the spec is that we
929 must produce the *entire* 64-bit addition, but produce the
930 carry into bit 32. */
931 TCGv t1
= tcg_temp_new();
932 tcg_gen_xor_tl(t1
, arg1
, arg2
); /* add without carry */
933 tcg_gen_add_tl(t0
, arg1
, arg2
);
935 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
937 tcg_gen_xor_tl(cpu_ca
, t0
, t1
); /* bits changed w/ carry */
939 tcg_gen_shri_tl(cpu_ca
, cpu_ca
, 32); /* extract bit 32 */
940 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
942 TCGv zero
= tcg_const_tl(0);
944 tcg_gen_add2_tl(t0
, cpu_ca
, arg1
, zero
, cpu_ca
, zero
);
945 tcg_gen_add2_tl(t0
, cpu_ca
, t0
, cpu_ca
, arg2
, zero
);
947 tcg_gen_add2_tl(t0
, cpu_ca
, arg1
, zero
, arg2
, zero
);
952 tcg_gen_add_tl(t0
, arg1
, arg2
);
954 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
959 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 0);
961 if (unlikely(compute_rc0
)) {
962 gen_set_Rc0(ctx
, t0
);
965 if (!TCGV_EQUAL(t0
, ret
)) {
966 tcg_gen_mov_tl(ret
, t0
);
970 /* Add functions with two operands */
971 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
972 static void glue(gen_, name)(DisasContext *ctx) \
974 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
975 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
976 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
978 /* Add functions with one operand and one immediate */
979 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
980 add_ca, compute_ca, compute_ov) \
981 static void glue(gen_, name)(DisasContext *ctx) \
983 TCGv t0 = tcg_const_tl(const_val); \
984 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
985 cpu_gpr[rA(ctx->opcode)], t0, \
986 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
990 /* add add. addo addo. */
991 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
992 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
993 /* addc addc. addco addco. */
994 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
995 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
996 /* adde adde. addeo addeo. */
997 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
998 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
999 /* addme addme. addmeo addmeo. */
1000 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
1001 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
1002 /* addze addze. addzeo addzeo.*/
1003 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
1004 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
1006 static void gen_addi(DisasContext
*ctx
)
1008 target_long simm
= SIMM(ctx
->opcode
);
1010 if (rA(ctx
->opcode
) == 0) {
1012 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
);
1014 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)],
1015 cpu_gpr
[rA(ctx
->opcode
)], simm
);
1019 static inline void gen_op_addic(DisasContext
*ctx
, bool compute_rc0
)
1021 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
1022 gen_op_arith_add(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1023 c
, 0, 1, 0, compute_rc0
);
1027 static void gen_addic(DisasContext
*ctx
)
1029 gen_op_addic(ctx
, 0);
1032 static void gen_addic_(DisasContext
*ctx
)
1034 gen_op_addic(ctx
, 1);
1038 static void gen_addis(DisasContext
*ctx
)
1040 target_long simm
= SIMM(ctx
->opcode
);
1042 if (rA(ctx
->opcode
) == 0) {
1044 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
<< 16);
1046 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)],
1047 cpu_gpr
[rA(ctx
->opcode
)], simm
<< 16);
1052 static void gen_addpcis(DisasContext
*ctx
)
1054 target_long d
= DX(ctx
->opcode
);
1056 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], ctx
->nip
+ (d
<< 16));
1059 static inline void gen_op_arith_divw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1060 TCGv arg2
, int sign
, int compute_ov
)
1062 TCGLabel
*l1
= gen_new_label();
1063 TCGLabel
*l2
= gen_new_label();
1064 TCGv_i32 t0
= tcg_temp_local_new_i32();
1065 TCGv_i32 t1
= tcg_temp_local_new_i32();
1067 tcg_gen_trunc_tl_i32(t0
, arg1
);
1068 tcg_gen_trunc_tl_i32(t1
, arg2
);
1069 tcg_gen_brcondi_i32(TCG_COND_EQ
, t1
, 0, l1
);
1071 TCGLabel
*l3
= gen_new_label();
1072 tcg_gen_brcondi_i32(TCG_COND_NE
, t1
, -1, l3
);
1073 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, INT32_MIN
, l1
);
1075 tcg_gen_div_i32(t0
, t0
, t1
);
1077 tcg_gen_divu_i32(t0
, t0
, t1
);
1080 tcg_gen_movi_tl(cpu_ov
, 0);
1085 tcg_gen_sari_i32(t0
, t0
, 31);
1087 tcg_gen_movi_i32(t0
, 0);
1090 tcg_gen_movi_tl(cpu_ov
, 1);
1091 tcg_gen_movi_tl(cpu_so
, 1);
1094 tcg_gen_extu_i32_tl(ret
, t0
);
1095 tcg_temp_free_i32(t0
);
1096 tcg_temp_free_i32(t1
);
1097 if (unlikely(Rc(ctx
->opcode
) != 0))
1098 gen_set_Rc0(ctx
, ret
);
1101 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
1102 static void glue(gen_, name)(DisasContext *ctx) \
1104 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
1105 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1106 sign, compute_ov); \
1108 /* divwu divwu. divwuo divwuo. */
1109 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0);
1110 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1);
1111 /* divw divw. divwo divwo. */
1112 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0);
1113 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1);
1115 /* div[wd]eu[o][.] */
1116 #define GEN_DIVE(name, hlpr, compute_ov) \
1117 static void gen_##name(DisasContext *ctx) \
1119 TCGv_i32 t0 = tcg_const_i32(compute_ov); \
1120 gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1121 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \
1122 tcg_temp_free_i32(t0); \
1123 if (unlikely(Rc(ctx->opcode) != 0)) { \
1124 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1128 GEN_DIVE(divweu
, divweu
, 0);
1129 GEN_DIVE(divweuo
, divweu
, 1);
1130 GEN_DIVE(divwe
, divwe
, 0);
1131 GEN_DIVE(divweo
, divwe
, 1);
1133 #if defined(TARGET_PPC64)
1134 static inline void gen_op_arith_divd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1135 TCGv arg2
, int sign
, int compute_ov
)
1137 TCGLabel
*l1
= gen_new_label();
1138 TCGLabel
*l2
= gen_new_label();
1140 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg2
, 0, l1
);
1142 TCGLabel
*l3
= gen_new_label();
1143 tcg_gen_brcondi_i64(TCG_COND_NE
, arg2
, -1, l3
);
1144 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg1
, INT64_MIN
, l1
);
1146 tcg_gen_div_i64(ret
, arg1
, arg2
);
1148 tcg_gen_divu_i64(ret
, arg1
, arg2
);
1151 tcg_gen_movi_tl(cpu_ov
, 0);
1156 tcg_gen_sari_i64(ret
, arg1
, 63);
1158 tcg_gen_movi_i64(ret
, 0);
1161 tcg_gen_movi_tl(cpu_ov
, 1);
1162 tcg_gen_movi_tl(cpu_so
, 1);
1165 if (unlikely(Rc(ctx
->opcode
) != 0))
1166 gen_set_Rc0(ctx
, ret
);
1168 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1169 static void glue(gen_, name)(DisasContext *ctx) \
1171 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1172 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1173 sign, compute_ov); \
1175 /* divwu divwu. divwuo divwuo. */
1176 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0);
1177 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1);
1178 /* divw divw. divwo divwo. */
1179 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0);
1180 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1);
1182 GEN_DIVE(divdeu
, divdeu
, 0);
1183 GEN_DIVE(divdeuo
, divdeu
, 1);
1184 GEN_DIVE(divde
, divde
, 0);
1185 GEN_DIVE(divdeo
, divde
, 1);
1188 static inline void gen_op_arith_modw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1189 TCGv arg2
, int sign
)
1191 TCGv_i32 t0
= tcg_temp_new_i32();
1192 TCGv_i32 t1
= tcg_temp_new_i32();
1194 tcg_gen_trunc_tl_i32(t0
, arg1
);
1195 tcg_gen_trunc_tl_i32(t1
, arg2
);
1197 TCGv_i32 t2
= tcg_temp_new_i32();
1198 TCGv_i32 t3
= tcg_temp_new_i32();
1199 tcg_gen_setcondi_i32(TCG_COND_EQ
, t2
, t0
, INT_MIN
);
1200 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, -1);
1201 tcg_gen_and_i32(t2
, t2
, t3
);
1202 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, 0);
1203 tcg_gen_or_i32(t2
, t2
, t3
);
1204 tcg_gen_movi_i32(t3
, 0);
1205 tcg_gen_movcond_i32(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1206 tcg_gen_rem_i32(t3
, t0
, t1
);
1207 tcg_gen_ext_i32_tl(ret
, t3
);
1208 tcg_temp_free_i32(t2
);
1209 tcg_temp_free_i32(t3
);
1211 TCGv_i32 t2
= tcg_const_i32(1);
1212 TCGv_i32 t3
= tcg_const_i32(0);
1213 tcg_gen_movcond_i32(TCG_COND_EQ
, t1
, t1
, t3
, t2
, t1
);
1214 tcg_gen_remu_i32(t3
, t0
, t1
);
1215 tcg_gen_extu_i32_tl(ret
, t3
);
1216 tcg_temp_free_i32(t2
);
1217 tcg_temp_free_i32(t3
);
1219 tcg_temp_free_i32(t0
);
1220 tcg_temp_free_i32(t1
);
1223 #define GEN_INT_ARITH_MODW(name, opc3, sign) \
1224 static void glue(gen_, name)(DisasContext *ctx) \
1226 gen_op_arith_modw(ctx, cpu_gpr[rD(ctx->opcode)], \
1227 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1231 GEN_INT_ARITH_MODW(moduw
, 0x08, 0);
1232 GEN_INT_ARITH_MODW(modsw
, 0x18, 1);
1234 #if defined(TARGET_PPC64)
1235 static inline void gen_op_arith_modd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1236 TCGv arg2
, int sign
)
1238 TCGv_i64 t0
= tcg_temp_new_i64();
1239 TCGv_i64 t1
= tcg_temp_new_i64();
1241 tcg_gen_mov_i64(t0
, arg1
);
1242 tcg_gen_mov_i64(t1
, arg2
);
1244 TCGv_i64 t2
= tcg_temp_new_i64();
1245 TCGv_i64 t3
= tcg_temp_new_i64();
1246 tcg_gen_setcondi_i64(TCG_COND_EQ
, t2
, t0
, INT64_MIN
);
1247 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, -1);
1248 tcg_gen_and_i64(t2
, t2
, t3
);
1249 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, 0);
1250 tcg_gen_or_i64(t2
, t2
, t3
);
1251 tcg_gen_movi_i64(t3
, 0);
1252 tcg_gen_movcond_i64(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1253 tcg_gen_rem_i64(ret
, t0
, t1
);
1254 tcg_temp_free_i64(t2
);
1255 tcg_temp_free_i64(t3
);
1257 TCGv_i64 t2
= tcg_const_i64(1);
1258 TCGv_i64 t3
= tcg_const_i64(0);
1259 tcg_gen_movcond_i64(TCG_COND_EQ
, t1
, t1
, t3
, t2
, t1
);
1260 tcg_gen_remu_i64(ret
, t0
, t1
);
1261 tcg_temp_free_i64(t2
);
1262 tcg_temp_free_i64(t3
);
1264 tcg_temp_free_i64(t0
);
1265 tcg_temp_free_i64(t1
);
1268 #define GEN_INT_ARITH_MODD(name, opc3, sign) \
1269 static void glue(gen_, name)(DisasContext *ctx) \
1271 gen_op_arith_modd(ctx, cpu_gpr[rD(ctx->opcode)], \
1272 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1276 GEN_INT_ARITH_MODD(modud
, 0x08, 0);
1277 GEN_INT_ARITH_MODD(modsd
, 0x18, 1);
1281 static void gen_mulhw(DisasContext
*ctx
)
1283 TCGv_i32 t0
= tcg_temp_new_i32();
1284 TCGv_i32 t1
= tcg_temp_new_i32();
1286 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1287 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1288 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1289 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1290 tcg_temp_free_i32(t0
);
1291 tcg_temp_free_i32(t1
);
1292 if (unlikely(Rc(ctx
->opcode
) != 0))
1293 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1296 /* mulhwu mulhwu. */
1297 static void gen_mulhwu(DisasContext
*ctx
)
1299 TCGv_i32 t0
= tcg_temp_new_i32();
1300 TCGv_i32 t1
= tcg_temp_new_i32();
1302 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1303 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1304 tcg_gen_mulu2_i32(t0
, t1
, t0
, t1
);
1305 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1306 tcg_temp_free_i32(t0
);
1307 tcg_temp_free_i32(t1
);
1308 if (unlikely(Rc(ctx
->opcode
) != 0))
1309 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1313 static void gen_mullw(DisasContext
*ctx
)
1315 #if defined(TARGET_PPC64)
1317 t0
= tcg_temp_new_i64();
1318 t1
= tcg_temp_new_i64();
1319 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1320 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1321 tcg_gen_mul_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
1325 tcg_gen_mul_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1326 cpu_gpr
[rB(ctx
->opcode
)]);
1328 if (unlikely(Rc(ctx
->opcode
) != 0))
1329 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1332 /* mullwo mullwo. */
1333 static void gen_mullwo(DisasContext
*ctx
)
1335 TCGv_i32 t0
= tcg_temp_new_i32();
1336 TCGv_i32 t1
= tcg_temp_new_i32();
1338 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1339 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1340 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1341 #if defined(TARGET_PPC64)
1342 tcg_gen_concat_i32_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
1344 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1347 tcg_gen_sari_i32(t0
, t0
, 31);
1348 tcg_gen_setcond_i32(TCG_COND_NE
, t0
, t0
, t1
);
1349 tcg_gen_extu_i32_tl(cpu_ov
, t0
);
1350 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1352 tcg_temp_free_i32(t0
);
1353 tcg_temp_free_i32(t1
);
1354 if (unlikely(Rc(ctx
->opcode
) != 0))
1355 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1359 static void gen_mulli(DisasContext
*ctx
)
1361 tcg_gen_muli_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1365 #if defined(TARGET_PPC64)
1367 static void gen_mulhd(DisasContext
*ctx
)
1369 TCGv lo
= tcg_temp_new();
1370 tcg_gen_muls2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1371 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1373 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1374 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1378 /* mulhdu mulhdu. */
1379 static void gen_mulhdu(DisasContext
*ctx
)
1381 TCGv lo
= tcg_temp_new();
1382 tcg_gen_mulu2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1383 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1385 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1386 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1391 static void gen_mulld(DisasContext
*ctx
)
1393 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1394 cpu_gpr
[rB(ctx
->opcode
)]);
1395 if (unlikely(Rc(ctx
->opcode
) != 0))
1396 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1399 /* mulldo mulldo. */
1400 static void gen_mulldo(DisasContext
*ctx
)
1402 TCGv_i64 t0
= tcg_temp_new_i64();
1403 TCGv_i64 t1
= tcg_temp_new_i64();
1405 tcg_gen_muls2_i64(t0
, t1
, cpu_gpr
[rA(ctx
->opcode
)],
1406 cpu_gpr
[rB(ctx
->opcode
)]);
1407 tcg_gen_mov_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1409 tcg_gen_sari_i64(t0
, t0
, 63);
1410 tcg_gen_setcond_i64(TCG_COND_NE
, cpu_ov
, t0
, t1
);
1411 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1413 tcg_temp_free_i64(t0
);
1414 tcg_temp_free_i64(t1
);
1416 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1417 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1422 /* Common subf function */
1423 static inline void gen_op_arith_subf(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1424 TCGv arg2
, bool add_ca
, bool compute_ca
,
1425 bool compute_ov
, bool compute_rc0
)
1429 if (compute_ca
|| compute_ov
) {
1430 t0
= tcg_temp_new();
1434 /* dest = ~arg1 + arg2 [+ ca]. */
1435 if (NARROW_MODE(ctx
)) {
1436 /* Caution: a non-obvious corner case of the spec is that we
1437 must produce the *entire* 64-bit addition, but produce the
1438 carry into bit 32. */
1439 TCGv inv1
= tcg_temp_new();
1440 TCGv t1
= tcg_temp_new();
1441 tcg_gen_not_tl(inv1
, arg1
);
1443 tcg_gen_add_tl(t0
, arg2
, cpu_ca
);
1445 tcg_gen_addi_tl(t0
, arg2
, 1);
1447 tcg_gen_xor_tl(t1
, arg2
, inv1
); /* add without carry */
1448 tcg_gen_add_tl(t0
, t0
, inv1
);
1449 tcg_temp_free(inv1
);
1450 tcg_gen_xor_tl(cpu_ca
, t0
, t1
); /* bits changes w/ carry */
1452 tcg_gen_shri_tl(cpu_ca
, cpu_ca
, 32); /* extract bit 32 */
1453 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
1454 } else if (add_ca
) {
1455 TCGv zero
, inv1
= tcg_temp_new();
1456 tcg_gen_not_tl(inv1
, arg1
);
1457 zero
= tcg_const_tl(0);
1458 tcg_gen_add2_tl(t0
, cpu_ca
, arg2
, zero
, cpu_ca
, zero
);
1459 tcg_gen_add2_tl(t0
, cpu_ca
, t0
, cpu_ca
, inv1
, zero
);
1460 tcg_temp_free(zero
);
1461 tcg_temp_free(inv1
);
1463 tcg_gen_setcond_tl(TCG_COND_GEU
, cpu_ca
, arg2
, arg1
);
1464 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1466 } else if (add_ca
) {
1467 /* Since we're ignoring carry-out, we can simplify the
1468 standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1. */
1469 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1470 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
1471 tcg_gen_subi_tl(t0
, t0
, 1);
1473 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1477 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 1);
1479 if (unlikely(compute_rc0
)) {
1480 gen_set_Rc0(ctx
, t0
);
1483 if (!TCGV_EQUAL(t0
, ret
)) {
1484 tcg_gen_mov_tl(ret
, t0
);
1488 /* Sub functions with Two operands functions */
1489 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1490 static void glue(gen_, name)(DisasContext *ctx) \
1492 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1493 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1494 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1496 /* Sub functions with one operand and one immediate */
1497 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1498 add_ca, compute_ca, compute_ov) \
1499 static void glue(gen_, name)(DisasContext *ctx) \
1501 TCGv t0 = tcg_const_tl(const_val); \
1502 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1503 cpu_gpr[rA(ctx->opcode)], t0, \
1504 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1505 tcg_temp_free(t0); \
1507 /* subf subf. subfo subfo. */
1508 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
1509 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
1510 /* subfc subfc. subfco subfco. */
1511 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
1512 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
1513 /* subfe subfe. subfeo subfo. */
1514 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
1515 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
1516 /* subfme subfme. subfmeo subfmeo. */
1517 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
1518 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
1519 /* subfze subfze. subfzeo subfzeo.*/
1520 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
1521 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
1524 static void gen_subfic(DisasContext
*ctx
)
1526 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
1527 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1532 /* neg neg. nego nego. */
1533 static inline void gen_op_arith_neg(DisasContext
*ctx
, bool compute_ov
)
1535 TCGv zero
= tcg_const_tl(0);
1536 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1537 zero
, 0, 0, compute_ov
, Rc(ctx
->opcode
));
1538 tcg_temp_free(zero
);
1541 static void gen_neg(DisasContext
*ctx
)
1543 gen_op_arith_neg(ctx
, 0);
1546 static void gen_nego(DisasContext
*ctx
)
1548 gen_op_arith_neg(ctx
, 1);
1551 /*** Integer logical ***/
1552 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1553 static void glue(gen_, name)(DisasContext *ctx) \
1555 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1556 cpu_gpr[rB(ctx->opcode)]); \
1557 if (unlikely(Rc(ctx->opcode) != 0)) \
1558 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1561 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1562 static void glue(gen_, name)(DisasContext *ctx) \
1564 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1565 if (unlikely(Rc(ctx->opcode) != 0)) \
1566 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1570 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
);
1572 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
);
1575 static void gen_andi_(DisasContext
*ctx
)
1577 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
));
1578 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1582 static void gen_andis_(DisasContext
*ctx
)
1584 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
) << 16);
1585 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1589 static void gen_cntlzw(DisasContext
*ctx
)
1591 gen_helper_cntlzw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1592 if (unlikely(Rc(ctx
->opcode
) != 0))
1593 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1597 static void gen_cnttzw(DisasContext
*ctx
)
1599 gen_helper_cnttzw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1600 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1601 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1606 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
);
1607 /* extsb & extsb. */
1608 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
);
1609 /* extsh & extsh. */
1610 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
);
1612 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
);
1614 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
);
1616 #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY)
1617 static void gen_pause(DisasContext
*ctx
)
1619 TCGv_i32 t0
= tcg_const_i32(0);
1620 tcg_gen_st_i32(t0
, cpu_env
,
1621 -offsetof(PowerPCCPU
, env
) + offsetof(CPUState
, halted
));
1622 tcg_temp_free_i32(t0
);
1624 /* Stop translation, this gives other CPUs a chance to run */
1625 gen_exception_err(ctx
, EXCP_HLT
, 1);
1627 #endif /* defined(TARGET_PPC64) */
1630 static void gen_or(DisasContext
*ctx
)
1634 rs
= rS(ctx
->opcode
);
1635 ra
= rA(ctx
->opcode
);
1636 rb
= rB(ctx
->opcode
);
1637 /* Optimisation for mr. ri case */
1638 if (rs
!= ra
|| rs
!= rb
) {
1640 tcg_gen_or_tl(cpu_gpr
[ra
], cpu_gpr
[rs
], cpu_gpr
[rb
]);
1642 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rs
]);
1643 if (unlikely(Rc(ctx
->opcode
) != 0))
1644 gen_set_Rc0(ctx
, cpu_gpr
[ra
]);
1645 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
1646 gen_set_Rc0(ctx
, cpu_gpr
[rs
]);
1647 #if defined(TARGET_PPC64)
1648 } else if (rs
!= 0) { /* 0 is nop */
1653 /* Set process priority to low */
1657 /* Set process priority to medium-low */
1661 /* Set process priority to normal */
1664 #if !defined(CONFIG_USER_ONLY)
1667 /* Set process priority to very low */
1673 /* Set process priority to medium-hight */
1679 /* Set process priority to high */
1684 if (ctx
->hv
&& !ctx
->pr
) {
1685 /* Set process priority to very high */
1694 TCGv t0
= tcg_temp_new();
1695 gen_load_spr(t0
, SPR_PPR
);
1696 tcg_gen_andi_tl(t0
, t0
, ~0x001C000000000000ULL
);
1697 tcg_gen_ori_tl(t0
, t0
, ((uint64_t)prio
) << 50);
1698 gen_store_spr(SPR_PPR
, t0
);
1701 #if !defined(CONFIG_USER_ONLY)
1702 /* Pause out of TCG otherwise spin loops with smt_low eat too much
1703 * CPU and the kernel hangs. This applies to all encodings other
1704 * than no-op, e.g., miso(rs=26), yield(27), mdoio(29), mdoom(30),
1705 * and all currently undefined.
1713 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
);
1716 static void gen_xor(DisasContext
*ctx
)
1718 /* Optimisation for "set to zero" case */
1719 if (rS(ctx
->opcode
) != rB(ctx
->opcode
))
1720 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1722 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1723 if (unlikely(Rc(ctx
->opcode
) != 0))
1724 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1728 static void gen_ori(DisasContext
*ctx
)
1730 target_ulong uimm
= UIMM(ctx
->opcode
);
1732 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1735 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1739 static void gen_oris(DisasContext
*ctx
)
1741 target_ulong uimm
= UIMM(ctx
->opcode
);
1743 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1747 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1751 static void gen_xori(DisasContext
*ctx
)
1753 target_ulong uimm
= UIMM(ctx
->opcode
);
1755 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1759 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1763 static void gen_xoris(DisasContext
*ctx
)
1765 target_ulong uimm
= UIMM(ctx
->opcode
);
1767 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1771 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1774 /* popcntb : PowerPC 2.03 specification */
1775 static void gen_popcntb(DisasContext
*ctx
)
1777 gen_helper_popcntb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1780 static void gen_popcntw(DisasContext
*ctx
)
1782 gen_helper_popcntw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1785 #if defined(TARGET_PPC64)
1786 /* popcntd: PowerPC 2.06 specification */
1787 static void gen_popcntd(DisasContext
*ctx
)
1789 gen_helper_popcntd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1793 /* prtyw: PowerPC 2.05 specification */
1794 static void gen_prtyw(DisasContext
*ctx
)
1796 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
1797 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
1798 TCGv t0
= tcg_temp_new();
1799 tcg_gen_shri_tl(t0
, rs
, 16);
1800 tcg_gen_xor_tl(ra
, rs
, t0
);
1801 tcg_gen_shri_tl(t0
, ra
, 8);
1802 tcg_gen_xor_tl(ra
, ra
, t0
);
1803 tcg_gen_andi_tl(ra
, ra
, (target_ulong
)0x100000001ULL
);
1807 #if defined(TARGET_PPC64)
1808 /* prtyd: PowerPC 2.05 specification */
1809 static void gen_prtyd(DisasContext
*ctx
)
1811 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
1812 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
1813 TCGv t0
= tcg_temp_new();
1814 tcg_gen_shri_tl(t0
, rs
, 32);
1815 tcg_gen_xor_tl(ra
, rs
, t0
);
1816 tcg_gen_shri_tl(t0
, ra
, 16);
1817 tcg_gen_xor_tl(ra
, ra
, t0
);
1818 tcg_gen_shri_tl(t0
, ra
, 8);
1819 tcg_gen_xor_tl(ra
, ra
, t0
);
1820 tcg_gen_andi_tl(ra
, ra
, 1);
1825 #if defined(TARGET_PPC64)
1827 static void gen_bpermd(DisasContext
*ctx
)
1829 gen_helper_bpermd(cpu_gpr
[rA(ctx
->opcode
)],
1830 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1834 #if defined(TARGET_PPC64)
1835 /* extsw & extsw. */
1836 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
);
1839 static void gen_cntlzd(DisasContext
*ctx
)
1841 gen_helper_cntlzd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1842 if (unlikely(Rc(ctx
->opcode
) != 0))
1843 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1847 static void gen_cnttzd(DisasContext
*ctx
)
1849 gen_helper_cnttzd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1850 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1851 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1856 /*** Integer rotate ***/
1858 /* rlwimi & rlwimi. */
1859 static void gen_rlwimi(DisasContext
*ctx
)
1861 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
1862 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
1863 uint32_t sh
= SH(ctx
->opcode
);
1864 uint32_t mb
= MB(ctx
->opcode
);
1865 uint32_t me
= ME(ctx
->opcode
);
1867 if (sh
== (31-me
) && mb
<= me
) {
1868 tcg_gen_deposit_tl(t_ra
, t_ra
, t_rs
, sh
, me
- mb
+ 1);
1873 #if defined(TARGET_PPC64)
1877 mask
= MASK(mb
, me
);
1879 t1
= tcg_temp_new();
1880 if (mask
<= 0xffffffffu
) {
1881 TCGv_i32 t0
= tcg_temp_new_i32();
1882 tcg_gen_trunc_tl_i32(t0
, t_rs
);
1883 tcg_gen_rotli_i32(t0
, t0
, sh
);
1884 tcg_gen_extu_i32_tl(t1
, t0
);
1885 tcg_temp_free_i32(t0
);
1887 #if defined(TARGET_PPC64)
1888 tcg_gen_deposit_i64(t1
, t_rs
, t_rs
, 32, 32);
1889 tcg_gen_rotli_i64(t1
, t1
, sh
);
1891 g_assert_not_reached();
1895 tcg_gen_andi_tl(t1
, t1
, mask
);
1896 tcg_gen_andi_tl(t_ra
, t_ra
, ~mask
);
1897 tcg_gen_or_tl(t_ra
, t_ra
, t1
);
1900 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1901 gen_set_Rc0(ctx
, t_ra
);
1905 /* rlwinm & rlwinm. */
1906 static void gen_rlwinm(DisasContext
*ctx
)
1908 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
1909 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
1910 uint32_t sh
= SH(ctx
->opcode
);
1911 uint32_t mb
= MB(ctx
->opcode
);
1912 uint32_t me
= ME(ctx
->opcode
);
1914 if (mb
== 0 && me
== (31 - sh
)) {
1915 tcg_gen_shli_tl(t_ra
, t_rs
, sh
);
1916 tcg_gen_ext32u_tl(t_ra
, t_ra
);
1917 } else if (sh
!= 0 && me
== 31 && sh
== (32 - mb
)) {
1918 tcg_gen_ext32u_tl(t_ra
, t_rs
);
1919 tcg_gen_shri_tl(t_ra
, t_ra
, mb
);
1922 #if defined(TARGET_PPC64)
1926 mask
= MASK(mb
, me
);
1928 if (mask
<= 0xffffffffu
) {
1929 TCGv_i32 t0
= tcg_temp_new_i32();
1930 tcg_gen_trunc_tl_i32(t0
, t_rs
);
1931 tcg_gen_rotli_i32(t0
, t0
, sh
);
1932 tcg_gen_andi_i32(t0
, t0
, mask
);
1933 tcg_gen_extu_i32_tl(t_ra
, t0
);
1934 tcg_temp_free_i32(t0
);
1936 #if defined(TARGET_PPC64)
1937 tcg_gen_deposit_i64(t_ra
, t_rs
, t_rs
, 32, 32);
1938 tcg_gen_rotli_i64(t_ra
, t_ra
, sh
);
1939 tcg_gen_andi_i64(t_ra
, t_ra
, mask
);
1941 g_assert_not_reached();
1945 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1946 gen_set_Rc0(ctx
, t_ra
);
1950 /* rlwnm & rlwnm. */
1951 static void gen_rlwnm(DisasContext
*ctx
)
1953 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
1954 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
1955 TCGv t_rb
= cpu_gpr
[rB(ctx
->opcode
)];
1956 uint32_t mb
= MB(ctx
->opcode
);
1957 uint32_t me
= ME(ctx
->opcode
);
1960 #if defined(TARGET_PPC64)
1964 mask
= MASK(mb
, me
);
1966 if (mask
<= 0xffffffffu
) {
1967 TCGv_i32 t0
= tcg_temp_new_i32();
1968 TCGv_i32 t1
= tcg_temp_new_i32();
1969 tcg_gen_trunc_tl_i32(t0
, t_rb
);
1970 tcg_gen_trunc_tl_i32(t1
, t_rs
);
1971 tcg_gen_andi_i32(t0
, t0
, 0x1f);
1972 tcg_gen_rotl_i32(t1
, t1
, t0
);
1973 tcg_gen_extu_i32_tl(t_ra
, t1
);
1974 tcg_temp_free_i32(t0
);
1975 tcg_temp_free_i32(t1
);
1977 #if defined(TARGET_PPC64)
1978 TCGv_i64 t0
= tcg_temp_new_i64();
1979 tcg_gen_andi_i64(t0
, t_rb
, 0x1f);
1980 tcg_gen_deposit_i64(t_ra
, t_rs
, t_rs
, 32, 32);
1981 tcg_gen_rotl_i64(t_ra
, t_ra
, t0
);
1982 tcg_temp_free_i64(t0
);
1984 g_assert_not_reached();
1988 tcg_gen_andi_tl(t_ra
, t_ra
, mask
);
1990 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1991 gen_set_Rc0(ctx
, t_ra
);
1995 #if defined(TARGET_PPC64)
1996 #define GEN_PPC64_R2(name, opc1, opc2) \
1997 static void glue(gen_, name##0)(DisasContext *ctx) \
1999 gen_##name(ctx, 0); \
2002 static void glue(gen_, name##1)(DisasContext *ctx) \
2004 gen_##name(ctx, 1); \
2006 #define GEN_PPC64_R4(name, opc1, opc2) \
2007 static void glue(gen_, name##0)(DisasContext *ctx) \
2009 gen_##name(ctx, 0, 0); \
2012 static void glue(gen_, name##1)(DisasContext *ctx) \
2014 gen_##name(ctx, 0, 1); \
2017 static void glue(gen_, name##2)(DisasContext *ctx) \
2019 gen_##name(ctx, 1, 0); \
2022 static void glue(gen_, name##3)(DisasContext *ctx) \
2024 gen_##name(ctx, 1, 1); \
2027 static void gen_rldinm(DisasContext
*ctx
, int mb
, int me
, int sh
)
2029 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2030 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2032 if (sh
!= 0 && mb
== 0 && me
== (63 - sh
)) {
2033 tcg_gen_shli_tl(t_ra
, t_rs
, sh
);
2034 } else if (sh
!= 0 && me
== 63 && sh
== (64 - mb
)) {
2035 tcg_gen_shri_tl(t_ra
, t_rs
, mb
);
2037 tcg_gen_rotli_tl(t_ra
, t_rs
, sh
);
2038 tcg_gen_andi_tl(t_ra
, t_ra
, MASK(mb
, me
));
2040 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2041 gen_set_Rc0(ctx
, t_ra
);
2045 /* rldicl - rldicl. */
2046 static inline void gen_rldicl(DisasContext
*ctx
, int mbn
, int shn
)
2050 sh
= SH(ctx
->opcode
) | (shn
<< 5);
2051 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2052 gen_rldinm(ctx
, mb
, 63, sh
);
2054 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
2056 /* rldicr - rldicr. */
2057 static inline void gen_rldicr(DisasContext
*ctx
, int men
, int shn
)
2061 sh
= SH(ctx
->opcode
) | (shn
<< 5);
2062 me
= MB(ctx
->opcode
) | (men
<< 5);
2063 gen_rldinm(ctx
, 0, me
, sh
);
2065 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
2067 /* rldic - rldic. */
2068 static inline void gen_rldic(DisasContext
*ctx
, int mbn
, int shn
)
2072 sh
= SH(ctx
->opcode
) | (shn
<< 5);
2073 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2074 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
2076 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
2078 static void gen_rldnm(DisasContext
*ctx
, int mb
, int me
)
2080 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2081 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2082 TCGv t_rb
= cpu_gpr
[rB(ctx
->opcode
)];
2085 t0
= tcg_temp_new();
2086 tcg_gen_andi_tl(t0
, t_rb
, 0x3f);
2087 tcg_gen_rotl_tl(t_ra
, t_rs
, t0
);
2090 tcg_gen_andi_tl(t_ra
, t_ra
, MASK(mb
, me
));
2091 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2092 gen_set_Rc0(ctx
, t_ra
);
2096 /* rldcl - rldcl. */
2097 static inline void gen_rldcl(DisasContext
*ctx
, int mbn
)
2101 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2102 gen_rldnm(ctx
, mb
, 63);
2104 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
2106 /* rldcr - rldcr. */
2107 static inline void gen_rldcr(DisasContext
*ctx
, int men
)
2111 me
= MB(ctx
->opcode
) | (men
<< 5);
2112 gen_rldnm(ctx
, 0, me
);
2114 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
2116 /* rldimi - rldimi. */
2117 static void gen_rldimi(DisasContext
*ctx
, int mbn
, int shn
)
2119 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2120 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2121 uint32_t sh
= SH(ctx
->opcode
) | (shn
<< 5);
2122 uint32_t mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2123 uint32_t me
= 63 - sh
;
2126 tcg_gen_deposit_tl(t_ra
, t_ra
, t_rs
, sh
, me
- mb
+ 1);
2128 target_ulong mask
= MASK(mb
, me
);
2129 TCGv t1
= tcg_temp_new();
2131 tcg_gen_rotli_tl(t1
, t_rs
, sh
);
2132 tcg_gen_andi_tl(t1
, t1
, mask
);
2133 tcg_gen_andi_tl(t_ra
, t_ra
, ~mask
);
2134 tcg_gen_or_tl(t_ra
, t_ra
, t1
);
2137 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2138 gen_set_Rc0(ctx
, t_ra
);
2141 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
2144 /*** Integer shift ***/
2147 static void gen_slw(DisasContext
*ctx
)
2151 t0
= tcg_temp_new();
2152 /* AND rS with a mask that is 0 when rB >= 0x20 */
2153 #if defined(TARGET_PPC64)
2154 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
2155 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2157 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
2158 tcg_gen_sari_tl(t0
, t0
, 0x1f);
2160 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2161 t1
= tcg_temp_new();
2162 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
2163 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2166 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
2167 if (unlikely(Rc(ctx
->opcode
) != 0))
2168 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2172 static void gen_sraw(DisasContext
*ctx
)
2174 gen_helper_sraw(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
2175 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2176 if (unlikely(Rc(ctx
->opcode
) != 0))
2177 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2180 /* srawi & srawi. */
2181 static void gen_srawi(DisasContext
*ctx
)
2183 int sh
= SH(ctx
->opcode
);
2184 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
2185 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
2187 tcg_gen_ext32s_tl(dst
, src
);
2188 tcg_gen_movi_tl(cpu_ca
, 0);
2191 tcg_gen_ext32s_tl(dst
, src
);
2192 tcg_gen_andi_tl(cpu_ca
, dst
, (1ULL << sh
) - 1);
2193 t0
= tcg_temp_new();
2194 tcg_gen_sari_tl(t0
, dst
, TARGET_LONG_BITS
- 1);
2195 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
2197 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
2198 tcg_gen_sari_tl(dst
, dst
, sh
);
2200 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2201 gen_set_Rc0(ctx
, dst
);
2206 static void gen_srw(DisasContext
*ctx
)
2210 t0
= tcg_temp_new();
2211 /* AND rS with a mask that is 0 when rB >= 0x20 */
2212 #if defined(TARGET_PPC64)
2213 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
2214 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2216 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
2217 tcg_gen_sari_tl(t0
, t0
, 0x1f);
2219 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2220 tcg_gen_ext32u_tl(t0
, t0
);
2221 t1
= tcg_temp_new();
2222 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
2223 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2226 if (unlikely(Rc(ctx
->opcode
) != 0))
2227 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2230 #if defined(TARGET_PPC64)
2232 static void gen_sld(DisasContext
*ctx
)
2236 t0
= tcg_temp_new();
2237 /* AND rS with a mask that is 0 when rB >= 0x40 */
2238 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
2239 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2240 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2241 t1
= tcg_temp_new();
2242 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
2243 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2246 if (unlikely(Rc(ctx
->opcode
) != 0))
2247 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2251 static void gen_srad(DisasContext
*ctx
)
2253 gen_helper_srad(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
2254 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2255 if (unlikely(Rc(ctx
->opcode
) != 0))
2256 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2258 /* sradi & sradi. */
2259 static inline void gen_sradi(DisasContext
*ctx
, int n
)
2261 int sh
= SH(ctx
->opcode
) + (n
<< 5);
2262 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
2263 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
2265 tcg_gen_mov_tl(dst
, src
);
2266 tcg_gen_movi_tl(cpu_ca
, 0);
2269 tcg_gen_andi_tl(cpu_ca
, src
, (1ULL << sh
) - 1);
2270 t0
= tcg_temp_new();
2271 tcg_gen_sari_tl(t0
, src
, TARGET_LONG_BITS
- 1);
2272 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
2274 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
2275 tcg_gen_sari_tl(dst
, src
, sh
);
2277 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2278 gen_set_Rc0(ctx
, dst
);
2282 static void gen_sradi0(DisasContext
*ctx
)
2287 static void gen_sradi1(DisasContext
*ctx
)
2293 static void gen_srd(DisasContext
*ctx
)
2297 t0
= tcg_temp_new();
2298 /* AND rS with a mask that is 0 when rB >= 0x40 */
2299 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
2300 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2301 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2302 t1
= tcg_temp_new();
2303 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
2304 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2307 if (unlikely(Rc(ctx
->opcode
) != 0))
2308 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2312 #if defined(TARGET_PPC64)
2313 static void gen_set_cr1_from_fpscr(DisasContext
*ctx
)
2315 TCGv_i32 tmp
= tcg_temp_new_i32();
2316 tcg_gen_trunc_tl_i32(tmp
, cpu_fpscr
);
2317 tcg_gen_shri_i32(cpu_crf
[1], tmp
, 28);
2318 tcg_temp_free_i32(tmp
);
2321 static void gen_set_cr1_from_fpscr(DisasContext
*ctx
)
2323 tcg_gen_shri_tl(cpu_crf
[1], cpu_fpscr
, 28);
2327 /*** Floating-Point arithmetic ***/
2328 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
2329 static void gen_f##name(DisasContext *ctx) \
2331 if (unlikely(!ctx->fpu_enabled)) { \
2332 gen_exception(ctx, POWERPC_EXCP_FPU); \
2335 /* NIP cannot be restored if the memory exception comes from an helper */ \
2336 gen_update_nip(ctx, ctx->nip - 4); \
2337 gen_reset_fpstatus(); \
2338 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2339 cpu_fpr[rA(ctx->opcode)], \
2340 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2342 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2343 cpu_fpr[rD(ctx->opcode)]); \
2346 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2348 if (unlikely(Rc(ctx->opcode) != 0)) { \
2349 gen_set_cr1_from_fpscr(ctx); \
2353 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2354 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2355 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
2357 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2358 static void gen_f##name(DisasContext *ctx) \
2360 if (unlikely(!ctx->fpu_enabled)) { \
2361 gen_exception(ctx, POWERPC_EXCP_FPU); \
2364 /* NIP cannot be restored if the memory exception comes from an helper */ \
2365 gen_update_nip(ctx, ctx->nip - 4); \
2366 gen_reset_fpstatus(); \
2367 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2368 cpu_fpr[rA(ctx->opcode)], \
2369 cpu_fpr[rB(ctx->opcode)]); \
2371 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2372 cpu_fpr[rD(ctx->opcode)]); \
2375 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2377 if (unlikely(Rc(ctx->opcode) != 0)) { \
2378 gen_set_cr1_from_fpscr(ctx); \
2381 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2382 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2383 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2385 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2386 static void gen_f##name(DisasContext *ctx) \
2388 if (unlikely(!ctx->fpu_enabled)) { \
2389 gen_exception(ctx, POWERPC_EXCP_FPU); \
2392 /* NIP cannot be restored if the memory exception comes from an helper */ \
2393 gen_update_nip(ctx, ctx->nip - 4); \
2394 gen_reset_fpstatus(); \
2395 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2396 cpu_fpr[rA(ctx->opcode)], \
2397 cpu_fpr[rC(ctx->opcode)]); \
2399 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2400 cpu_fpr[rD(ctx->opcode)]); \
2403 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2405 if (unlikely(Rc(ctx->opcode) != 0)) { \
2406 gen_set_cr1_from_fpscr(ctx); \
2409 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2410 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2411 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2413 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
2414 static void gen_f##name(DisasContext *ctx) \
2416 if (unlikely(!ctx->fpu_enabled)) { \
2417 gen_exception(ctx, POWERPC_EXCP_FPU); \
2420 /* NIP cannot be restored if the memory exception comes from an helper */ \
2421 gen_update_nip(ctx, ctx->nip - 4); \
2422 gen_reset_fpstatus(); \
2423 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2424 cpu_fpr[rB(ctx->opcode)]); \
2426 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2428 if (unlikely(Rc(ctx->opcode) != 0)) { \
2429 gen_set_cr1_from_fpscr(ctx); \
2433 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
2434 static void gen_f##name(DisasContext *ctx) \
2436 if (unlikely(!ctx->fpu_enabled)) { \
2437 gen_exception(ctx, POWERPC_EXCP_FPU); \
2440 /* NIP cannot be restored if the memory exception comes from an helper */ \
2441 gen_update_nip(ctx, ctx->nip - 4); \
2442 gen_reset_fpstatus(); \
2443 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2444 cpu_fpr[rB(ctx->opcode)]); \
2446 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)]); \
2448 if (unlikely(Rc(ctx->opcode) != 0)) { \
2449 gen_set_cr1_from_fpscr(ctx); \
2454 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
);
2456 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
);
2458 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
);
2461 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
);
2464 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
);
2467 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
);
2470 static void gen_frsqrtes(DisasContext
*ctx
)
2472 if (unlikely(!ctx
->fpu_enabled
)) {
2473 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2476 /* NIP cannot be restored if the memory exception comes from an helper */
2477 gen_update_nip(ctx
, ctx
->nip
- 4);
2478 gen_reset_fpstatus();
2479 gen_helper_frsqrte(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2480 cpu_fpr
[rB(ctx
->opcode
)]);
2481 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2482 cpu_fpr
[rD(ctx
->opcode
)]);
2483 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)]);
2484 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2485 gen_set_cr1_from_fpscr(ctx
);
2490 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
);
2492 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
);
2496 static void gen_fsqrt(DisasContext
*ctx
)
2498 if (unlikely(!ctx
->fpu_enabled
)) {
2499 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2502 /* NIP cannot be restored if the memory exception comes from an helper */
2503 gen_update_nip(ctx
, ctx
->nip
- 4);
2504 gen_reset_fpstatus();
2505 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2506 cpu_fpr
[rB(ctx
->opcode
)]);
2507 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)]);
2508 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2509 gen_set_cr1_from_fpscr(ctx
);
2513 static void gen_fsqrts(DisasContext
*ctx
)
2515 if (unlikely(!ctx
->fpu_enabled
)) {
2516 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2519 /* NIP cannot be restored if the memory exception comes from an helper */
2520 gen_update_nip(ctx
, ctx
->nip
- 4);
2521 gen_reset_fpstatus();
2522 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2523 cpu_fpr
[rB(ctx
->opcode
)]);
2524 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2525 cpu_fpr
[rD(ctx
->opcode
)]);
2526 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)]);
2527 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2528 gen_set_cr1_from_fpscr(ctx
);
2532 /*** Floating-Point multiply-and-add ***/
2533 /* fmadd - fmadds */
2534 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
);
2535 /* fmsub - fmsubs */
2536 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
);
2537 /* fnmadd - fnmadds */
2538 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
);
2539 /* fnmsub - fnmsubs */
2540 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
);
2542 /*** Floating-Point round & convert ***/
2544 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
);
2546 GEN_FLOAT_B(ctiwu
, 0x0E, 0x04, 0, PPC2_FP_CVT_ISA206
);
2548 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
);
2550 GEN_FLOAT_B(ctiwuz
, 0x0F, 0x04, 0, PPC2_FP_CVT_ISA206
);
2552 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
);
2554 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC2_FP_CVT_S64
);
2556 GEN_FLOAT_B(cfids
, 0x0E, 0x1A, 0, PPC2_FP_CVT_ISA206
);
2558 GEN_FLOAT_B(cfidu
, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206
);
2560 GEN_FLOAT_B(cfidus
, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206
);
2562 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC2_FP_CVT_S64
);
2564 GEN_FLOAT_B(ctidu
, 0x0E, 0x1D, 0, PPC2_FP_CVT_ISA206
);
2566 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC2_FP_CVT_S64
);
2568 GEN_FLOAT_B(ctiduz
, 0x0F, 0x1D, 0, PPC2_FP_CVT_ISA206
);
2571 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
);
2573 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
);
2575 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
);
2577 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
);
2579 static void gen_ftdiv(DisasContext
*ctx
)
2581 if (unlikely(!ctx
->fpu_enabled
)) {
2582 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2585 gen_helper_ftdiv(cpu_crf
[crfD(ctx
->opcode
)], cpu_fpr
[rA(ctx
->opcode
)],
2586 cpu_fpr
[rB(ctx
->opcode
)]);
2589 static void gen_ftsqrt(DisasContext
*ctx
)
2591 if (unlikely(!ctx
->fpu_enabled
)) {
2592 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2595 gen_helper_ftsqrt(cpu_crf
[crfD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2600 /*** Floating-Point compare ***/
2603 static void gen_fcmpo(DisasContext
*ctx
)
2606 if (unlikely(!ctx
->fpu_enabled
)) {
2607 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2610 /* NIP cannot be restored if the memory exception comes from an helper */
2611 gen_update_nip(ctx
, ctx
->nip
- 4);
2612 gen_reset_fpstatus();
2613 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2614 gen_helper_fcmpo(cpu_env
, cpu_fpr
[rA(ctx
->opcode
)],
2615 cpu_fpr
[rB(ctx
->opcode
)], crf
);
2616 tcg_temp_free_i32(crf
);
2617 gen_helper_float_check_status(cpu_env
);
2621 static void gen_fcmpu(DisasContext
*ctx
)
2624 if (unlikely(!ctx
->fpu_enabled
)) {
2625 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2628 /* NIP cannot be restored if the memory exception comes from an helper */
2629 gen_update_nip(ctx
, ctx
->nip
- 4);
2630 gen_reset_fpstatus();
2631 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2632 gen_helper_fcmpu(cpu_env
, cpu_fpr
[rA(ctx
->opcode
)],
2633 cpu_fpr
[rB(ctx
->opcode
)], crf
);
2634 tcg_temp_free_i32(crf
);
2635 gen_helper_float_check_status(cpu_env
);
2638 /*** Floating-point move ***/
2640 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2641 static void gen_fabs(DisasContext
*ctx
)
2643 if (unlikely(!ctx
->fpu_enabled
)) {
2644 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2647 tcg_gen_andi_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)],
2649 if (unlikely(Rc(ctx
->opcode
))) {
2650 gen_set_cr1_from_fpscr(ctx
);
2655 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2656 static void gen_fmr(DisasContext
*ctx
)
2658 if (unlikely(!ctx
->fpu_enabled
)) {
2659 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2662 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2663 if (unlikely(Rc(ctx
->opcode
))) {
2664 gen_set_cr1_from_fpscr(ctx
);
2669 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2670 static void gen_fnabs(DisasContext
*ctx
)
2672 if (unlikely(!ctx
->fpu_enabled
)) {
2673 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2676 tcg_gen_ori_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)],
2678 if (unlikely(Rc(ctx
->opcode
))) {
2679 gen_set_cr1_from_fpscr(ctx
);
2684 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2685 static void gen_fneg(DisasContext
*ctx
)
2687 if (unlikely(!ctx
->fpu_enabled
)) {
2688 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2691 tcg_gen_xori_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)],
2693 if (unlikely(Rc(ctx
->opcode
))) {
2694 gen_set_cr1_from_fpscr(ctx
);
2698 /* fcpsgn: PowerPC 2.05 specification */
2699 /* XXX: beware that fcpsgn never checks for NaNs nor update FPSCR */
2700 static void gen_fcpsgn(DisasContext
*ctx
)
2702 if (unlikely(!ctx
->fpu_enabled
)) {
2703 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2706 tcg_gen_deposit_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rA(ctx
->opcode
)],
2707 cpu_fpr
[rB(ctx
->opcode
)], 0, 63);
2708 if (unlikely(Rc(ctx
->opcode
))) {
2709 gen_set_cr1_from_fpscr(ctx
);
2713 static void gen_fmrgew(DisasContext
*ctx
)
2716 if (unlikely(!ctx
->fpu_enabled
)) {
2717 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2720 b0
= tcg_temp_new_i64();
2721 tcg_gen_shri_i64(b0
, cpu_fpr
[rB(ctx
->opcode
)], 32);
2722 tcg_gen_deposit_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rA(ctx
->opcode
)],
2724 tcg_temp_free_i64(b0
);
2727 static void gen_fmrgow(DisasContext
*ctx
)
2729 if (unlikely(!ctx
->fpu_enabled
)) {
2730 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2733 tcg_gen_deposit_i64(cpu_fpr
[rD(ctx
->opcode
)],
2734 cpu_fpr
[rB(ctx
->opcode
)],
2735 cpu_fpr
[rA(ctx
->opcode
)],
2739 /*** Floating-Point status & ctrl register ***/
2742 static void gen_mcrfs(DisasContext
*ctx
)
2744 TCGv tmp
= tcg_temp_new();
2746 TCGv_i64 tnew_fpscr
= tcg_temp_new_i64();
2751 if (unlikely(!ctx
->fpu_enabled
)) {
2752 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2755 bfa
= crfS(ctx
->opcode
);
2758 tcg_gen_shri_tl(tmp
, cpu_fpscr
, shift
);
2759 tcg_gen_trunc_tl_i32(cpu_crf
[crfD(ctx
->opcode
)], tmp
);
2760 tcg_gen_andi_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfD(ctx
->opcode
)], 0xf);
2762 tcg_gen_extu_tl_i64(tnew_fpscr
, cpu_fpscr
);
2763 /* Only the exception bits (including FX) should be cleared if read */
2764 tcg_gen_andi_i64(tnew_fpscr
, tnew_fpscr
, ~((0xF << shift
) & FP_EX_CLEAR_BITS
));
2765 /* FEX and VX need to be updated, so don't set fpscr directly */
2766 tmask
= tcg_const_i32(1 << nibble
);
2767 gen_helper_store_fpscr(cpu_env
, tnew_fpscr
, tmask
);
2768 tcg_temp_free_i32(tmask
);
2769 tcg_temp_free_i64(tnew_fpscr
);
2773 static void gen_mffs(DisasContext
*ctx
)
2775 if (unlikely(!ctx
->fpu_enabled
)) {
2776 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2779 gen_reset_fpstatus();
2780 tcg_gen_extu_tl_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpscr
);
2781 if (unlikely(Rc(ctx
->opcode
))) {
2782 gen_set_cr1_from_fpscr(ctx
);
2787 static void gen_mtfsb0(DisasContext
*ctx
)
2791 if (unlikely(!ctx
->fpu_enabled
)) {
2792 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2795 crb
= 31 - crbD(ctx
->opcode
);
2796 gen_reset_fpstatus();
2797 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
)) {
2799 /* NIP cannot be restored if the memory exception comes from an helper */
2800 gen_update_nip(ctx
, ctx
->nip
- 4);
2801 t0
= tcg_const_i32(crb
);
2802 gen_helper_fpscr_clrbit(cpu_env
, t0
);
2803 tcg_temp_free_i32(t0
);
2805 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2806 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2807 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2812 static void gen_mtfsb1(DisasContext
*ctx
)
2816 if (unlikely(!ctx
->fpu_enabled
)) {
2817 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2820 crb
= 31 - crbD(ctx
->opcode
);
2821 gen_reset_fpstatus();
2822 /* XXX: we pretend we can only do IEEE floating-point computations */
2823 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
&& crb
!= FPSCR_NI
)) {
2825 /* NIP cannot be restored if the memory exception comes from an helper */
2826 gen_update_nip(ctx
, ctx
->nip
- 4);
2827 t0
= tcg_const_i32(crb
);
2828 gen_helper_fpscr_setbit(cpu_env
, t0
);
2829 tcg_temp_free_i32(t0
);
2831 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2832 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2833 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2835 /* We can raise a differed exception */
2836 gen_helper_float_check_status(cpu_env
);
2840 static void gen_mtfsf(DisasContext
*ctx
)
2845 if (unlikely(!ctx
->fpu_enabled
)) {
2846 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2849 flm
= FPFLM(ctx
->opcode
);
2850 l
= FPL(ctx
->opcode
);
2851 w
= FPW(ctx
->opcode
);
2852 if (unlikely(w
& !(ctx
->insns_flags2
& PPC2_ISA205
))) {
2853 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2856 /* NIP cannot be restored if the memory exception comes from an helper */
2857 gen_update_nip(ctx
, ctx
->nip
- 4);
2858 gen_reset_fpstatus();
2860 t0
= tcg_const_i32((ctx
->insns_flags2
& PPC2_ISA205
) ? 0xffff : 0xff);
2862 t0
= tcg_const_i32(flm
<< (w
* 8));
2864 gen_helper_store_fpscr(cpu_env
, cpu_fpr
[rB(ctx
->opcode
)], t0
);
2865 tcg_temp_free_i32(t0
);
2866 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2867 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2868 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2870 /* We can raise a differed exception */
2871 gen_helper_float_check_status(cpu_env
);
2875 static void gen_mtfsfi(DisasContext
*ctx
)
2881 if (unlikely(!ctx
->fpu_enabled
)) {
2882 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2885 w
= FPW(ctx
->opcode
);
2886 bf
= FPBF(ctx
->opcode
);
2887 if (unlikely(w
& !(ctx
->insns_flags2
& PPC2_ISA205
))) {
2888 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2891 sh
= (8 * w
) + 7 - bf
;
2892 /* NIP cannot be restored if the memory exception comes from an helper */
2893 gen_update_nip(ctx
, ctx
->nip
- 4);
2894 gen_reset_fpstatus();
2895 t0
= tcg_const_i64(((uint64_t)FPIMM(ctx
->opcode
)) << (4 * sh
));
2896 t1
= tcg_const_i32(1 << sh
);
2897 gen_helper_store_fpscr(cpu_env
, t0
, t1
);
2898 tcg_temp_free_i64(t0
);
2899 tcg_temp_free_i32(t1
);
2900 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2901 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2902 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2904 /* We can raise a differed exception */
2905 gen_helper_float_check_status(cpu_env
);
2908 /*** Addressing modes ***/
2909 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2910 static inline void gen_addr_imm_index(DisasContext
*ctx
, TCGv EA
,
2913 target_long simm
= SIMM(ctx
->opcode
);
2916 if (rA(ctx
->opcode
) == 0) {
2917 if (NARROW_MODE(ctx
)) {
2918 simm
= (uint32_t)simm
;
2920 tcg_gen_movi_tl(EA
, simm
);
2921 } else if (likely(simm
!= 0)) {
2922 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
);
2923 if (NARROW_MODE(ctx
)) {
2924 tcg_gen_ext32u_tl(EA
, EA
);
2927 if (NARROW_MODE(ctx
)) {
2928 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2930 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2935 static inline void gen_addr_reg_index(DisasContext
*ctx
, TCGv EA
)
2937 if (rA(ctx
->opcode
) == 0) {
2938 if (NARROW_MODE(ctx
)) {
2939 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2941 tcg_gen_mov_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2944 tcg_gen_add_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2945 if (NARROW_MODE(ctx
)) {
2946 tcg_gen_ext32u_tl(EA
, EA
);
2951 static inline void gen_addr_register(DisasContext
*ctx
, TCGv EA
)
2953 if (rA(ctx
->opcode
) == 0) {
2954 tcg_gen_movi_tl(EA
, 0);
2955 } else if (NARROW_MODE(ctx
)) {
2956 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2958 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2962 static inline void gen_addr_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
2965 tcg_gen_addi_tl(ret
, arg1
, val
);
2966 if (NARROW_MODE(ctx
)) {
2967 tcg_gen_ext32u_tl(ret
, ret
);
2971 static inline void gen_check_align(DisasContext
*ctx
, TCGv EA
, int mask
)
2973 TCGLabel
*l1
= gen_new_label();
2974 TCGv t0
= tcg_temp_new();
2976 /* NIP cannot be restored if the memory exception comes from an helper */
2977 gen_update_nip(ctx
, ctx
->nip
- 4);
2978 tcg_gen_andi_tl(t0
, EA
, mask
);
2979 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2980 t1
= tcg_const_i32(POWERPC_EXCP_ALIGN
);
2981 t2
= tcg_const_i32(0);
2982 gen_helper_raise_exception_err(cpu_env
, t1
, t2
);
2983 tcg_temp_free_i32(t1
);
2984 tcg_temp_free_i32(t2
);
2989 /*** Integer load ***/
2990 static inline void gen_qemu_ld8u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2992 tcg_gen_qemu_ld8u(arg1
, arg2
, ctx
->mem_idx
);
2995 static inline void gen_qemu_ld16u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2997 TCGMemOp op
= MO_UW
| ctx
->default_tcg_memop_mask
;
2998 tcg_gen_qemu_ld_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
3001 static inline void gen_qemu_ld16s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3003 TCGMemOp op
= MO_SW
| ctx
->default_tcg_memop_mask
;
3004 tcg_gen_qemu_ld_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
3007 static inline void gen_qemu_ld32u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3009 TCGMemOp op
= MO_UL
| ctx
->default_tcg_memop_mask
;
3010 tcg_gen_qemu_ld_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
3013 static void gen_qemu_ld32u_i64(DisasContext
*ctx
, TCGv_i64 val
, TCGv addr
)
3015 TCGv tmp
= tcg_temp_new();
3016 gen_qemu_ld32u(ctx
, tmp
, addr
);
3017 tcg_gen_extu_tl_i64(val
, tmp
);
3021 static inline void gen_qemu_ld32s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3023 TCGMemOp op
= MO_SL
| ctx
->default_tcg_memop_mask
;
3024 tcg_gen_qemu_ld_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
3027 static void gen_qemu_ld32s_i64(DisasContext
*ctx
, TCGv_i64 val
, TCGv addr
)
3029 TCGv tmp
= tcg_temp_new();
3030 gen_qemu_ld32s(ctx
, tmp
, addr
);
3031 tcg_gen_ext_tl_i64(val
, tmp
);
3035 static inline void gen_qemu_ld64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3037 TCGMemOp op
= MO_Q
| ctx
->default_tcg_memop_mask
;
3038 tcg_gen_qemu_ld_i64(arg1
, arg2
, ctx
->mem_idx
, op
);
3041 static inline void gen_qemu_st8(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3043 tcg_gen_qemu_st8(arg1
, arg2
, ctx
->mem_idx
);
3046 static inline void gen_qemu_st16(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3048 TCGMemOp op
= MO_UW
| ctx
->default_tcg_memop_mask
;
3049 tcg_gen_qemu_st_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
3052 static inline void gen_qemu_st32(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3054 TCGMemOp op
= MO_UL
| ctx
->default_tcg_memop_mask
;
3055 tcg_gen_qemu_st_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
3058 static void gen_qemu_st32_i64(DisasContext
*ctx
, TCGv_i64 val
, TCGv addr
)
3060 TCGv tmp
= tcg_temp_new();
3061 tcg_gen_trunc_i64_tl(tmp
, val
);
3062 gen_qemu_st32(ctx
, tmp
, addr
);
3066 static inline void gen_qemu_st64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3068 TCGMemOp op
= MO_Q
| ctx
->default_tcg_memop_mask
;
3069 tcg_gen_qemu_st_i64(arg1
, arg2
, ctx
->mem_idx
, op
);
3072 #define GEN_LD(name, ldop, opc, type) \
3073 static void glue(gen_, name)(DisasContext *ctx) \
3076 gen_set_access_type(ctx, ACCESS_INT); \
3077 EA = tcg_temp_new(); \
3078 gen_addr_imm_index(ctx, EA, 0); \
3079 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
3080 tcg_temp_free(EA); \
3083 #define GEN_LDU(name, ldop, opc, type) \
3084 static void glue(gen_, name##u)(DisasContext *ctx) \
3087 if (unlikely(rA(ctx->opcode) == 0 || \
3088 rA(ctx->opcode) == rD(ctx->opcode))) { \
3089 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3092 gen_set_access_type(ctx, ACCESS_INT); \
3093 EA = tcg_temp_new(); \
3094 if (type == PPC_64B) \
3095 gen_addr_imm_index(ctx, EA, 0x03); \
3097 gen_addr_imm_index(ctx, EA, 0); \
3098 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
3099 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3100 tcg_temp_free(EA); \
3103 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
3104 static void glue(gen_, name##ux)(DisasContext *ctx) \
3107 if (unlikely(rA(ctx->opcode) == 0 || \
3108 rA(ctx->opcode) == rD(ctx->opcode))) { \
3109 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3112 gen_set_access_type(ctx, ACCESS_INT); \
3113 EA = tcg_temp_new(); \
3114 gen_addr_reg_index(ctx, EA); \
3115 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
3116 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3117 tcg_temp_free(EA); \
3120 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2, chk) \
3121 static void glue(gen_, name##x)(DisasContext *ctx) \
3125 gen_set_access_type(ctx, ACCESS_INT); \
3126 EA = tcg_temp_new(); \
3127 gen_addr_reg_index(ctx, EA); \
3128 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
3129 tcg_temp_free(EA); \
3132 #define GEN_LDX(name, ldop, opc2, opc3, type) \
3133 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE, CHK_NONE)
3135 #define GEN_LDX_HVRM(name, ldop, opc2, opc3, type) \
3136 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE, CHK_HVRM)
3138 #define GEN_LDS(name, ldop, op, type) \
3139 GEN_LD(name, ldop, op | 0x20, type); \
3140 GEN_LDU(name, ldop, op | 0x21, type); \
3141 GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
3142 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
3144 /* lbz lbzu lbzux lbzx */
3145 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
);
3146 /* lha lhau lhaux lhax */
3147 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
);
3148 /* lhz lhzu lhzux lhzx */
3149 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
);
3150 /* lwz lwzu lwzux lwzx */
3151 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
);
3152 #if defined(TARGET_PPC64)
3154 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
);
3156 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
);
3158 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
);
3160 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
);
3162 /* CI load/store variants */
3163 GEN_LDX_HVRM(ldcix
, ld64
, 0x15, 0x1b, PPC_CILDST
)
3164 GEN_LDX_HVRM(lwzcix
, ld32u
, 0x15, 0x15, PPC_CILDST
)
3165 GEN_LDX_HVRM(lhzcix
, ld16u
, 0x15, 0x19, PPC_CILDST
)
3166 GEN_LDX_HVRM(lbzcix
, ld8u
, 0x15, 0x1a, PPC_CILDST
)
3168 static void gen_ld(DisasContext
*ctx
)
3171 if (Rc(ctx
->opcode
)) {
3172 if (unlikely(rA(ctx
->opcode
) == 0 ||
3173 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
3174 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3178 gen_set_access_type(ctx
, ACCESS_INT
);
3179 EA
= tcg_temp_new();
3180 gen_addr_imm_index(ctx
, EA
, 0x03);
3181 if (ctx
->opcode
& 0x02) {
3182 /* lwa (lwau is undefined) */
3183 gen_qemu_ld32s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
3186 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
3188 if (Rc(ctx
->opcode
))
3189 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
3194 static void gen_lq(DisasContext
*ctx
)
3199 /* lq is a legal user mode instruction starting in ISA 2.07 */
3200 bool legal_in_user_mode
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
3201 bool le_is_supported
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
3203 if (!legal_in_user_mode
&& ctx
->pr
) {
3204 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3208 if (!le_is_supported
&& ctx
->le_mode
) {
3209 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
3213 ra
= rA(ctx
->opcode
);
3214 rd
= rD(ctx
->opcode
);
3215 if (unlikely((rd
& 1) || rd
== ra
)) {
3216 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3220 gen_set_access_type(ctx
, ACCESS_INT
);
3221 EA
= tcg_temp_new();
3222 gen_addr_imm_index(ctx
, EA
, 0x0F);
3224 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
3225 64-bit byteswap already. */
3226 if (unlikely(ctx
->le_mode
)) {
3227 gen_qemu_ld64(ctx
, cpu_gpr
[rd
+1], EA
);
3228 gen_addr_add(ctx
, EA
, EA
, 8);
3229 gen_qemu_ld64(ctx
, cpu_gpr
[rd
], EA
);
3231 gen_qemu_ld64(ctx
, cpu_gpr
[rd
], EA
);
3232 gen_addr_add(ctx
, EA
, EA
, 8);
3233 gen_qemu_ld64(ctx
, cpu_gpr
[rd
+1], EA
);
3239 /*** Integer store ***/
3240 #define GEN_ST(name, stop, opc, type) \
3241 static void glue(gen_, name)(DisasContext *ctx) \
3244 gen_set_access_type(ctx, ACCESS_INT); \
3245 EA = tcg_temp_new(); \
3246 gen_addr_imm_index(ctx, EA, 0); \
3247 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
3248 tcg_temp_free(EA); \
3251 #define GEN_STU(name, stop, opc, type) \
3252 static void glue(gen_, stop##u)(DisasContext *ctx) \
3255 if (unlikely(rA(ctx->opcode) == 0)) { \
3256 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3259 gen_set_access_type(ctx, ACCESS_INT); \
3260 EA = tcg_temp_new(); \
3261 if (type == PPC_64B) \
3262 gen_addr_imm_index(ctx, EA, 0x03); \
3264 gen_addr_imm_index(ctx, EA, 0); \
3265 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
3266 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3267 tcg_temp_free(EA); \
3270 #define GEN_STUX(name, stop, opc2, opc3, type) \
3271 static void glue(gen_, name##ux)(DisasContext *ctx) \
3274 if (unlikely(rA(ctx->opcode) == 0)) { \
3275 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3278 gen_set_access_type(ctx, ACCESS_INT); \
3279 EA = tcg_temp_new(); \
3280 gen_addr_reg_index(ctx, EA); \
3281 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
3282 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3283 tcg_temp_free(EA); \
3286 #define GEN_STX_E(name, stop, opc2, opc3, type, type2, chk) \
3287 static void glue(gen_, name##x)(DisasContext *ctx) \
3291 gen_set_access_type(ctx, ACCESS_INT); \
3292 EA = tcg_temp_new(); \
3293 gen_addr_reg_index(ctx, EA); \
3294 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
3295 tcg_temp_free(EA); \
3297 #define GEN_STX(name, stop, opc2, opc3, type) \
3298 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE, CHK_NONE)
3300 #define GEN_STX_HVRM(name, stop, opc2, opc3, type) \
3301 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE, CHK_HVRM)
3303 #define GEN_STS(name, stop, op, type) \
3304 GEN_ST(name, stop, op | 0x20, type); \
3305 GEN_STU(name, stop, op | 0x21, type); \
3306 GEN_STUX(name, stop, 0x17, op | 0x01, type); \
3307 GEN_STX(name, stop, 0x17, op | 0x00, type)
3309 /* stb stbu stbux stbx */
3310 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
);
3311 /* sth sthu sthux sthx */
3312 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
);
3313 /* stw stwu stwux stwx */
3314 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
);
3315 #if defined(TARGET_PPC64)
3316 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
);
3317 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
);
3318 GEN_STX_HVRM(stdcix
, st64
, 0x15, 0x1f, PPC_CILDST
)
3319 GEN_STX_HVRM(stwcix
, st32
, 0x15, 0x1c, PPC_CILDST
)
3320 GEN_STX_HVRM(sthcix
, st16
, 0x15, 0x1d, PPC_CILDST
)
3321 GEN_STX_HVRM(stbcix
, st8
, 0x15, 0x1e, PPC_CILDST
)
3323 static void gen_std(DisasContext
*ctx
)
3328 rs
= rS(ctx
->opcode
);
3329 if ((ctx
->opcode
& 0x3) == 0x2) { /* stq */
3330 bool legal_in_user_mode
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
3331 bool le_is_supported
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
3333 if (!(ctx
->insns_flags
& PPC_64BX
)) {
3334 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3337 if (!legal_in_user_mode
&& ctx
->pr
) {
3338 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3342 if (!le_is_supported
&& ctx
->le_mode
) {
3343 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
3347 if (unlikely(rs
& 1)) {
3348 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3351 gen_set_access_type(ctx
, ACCESS_INT
);
3352 EA
= tcg_temp_new();
3353 gen_addr_imm_index(ctx
, EA
, 0x03);
3355 /* We only need to swap high and low halves. gen_qemu_st64 does
3356 necessary 64-bit byteswap already. */
3357 if (unlikely(ctx
->le_mode
)) {
3358 gen_qemu_st64(ctx
, cpu_gpr
[rs
+1], EA
);
3359 gen_addr_add(ctx
, EA
, EA
, 8);
3360 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
3362 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
3363 gen_addr_add(ctx
, EA
, EA
, 8);
3364 gen_qemu_st64(ctx
, cpu_gpr
[rs
+1], EA
);
3369 if (Rc(ctx
->opcode
)) {
3370 if (unlikely(rA(ctx
->opcode
) == 0)) {
3371 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3375 gen_set_access_type(ctx
, ACCESS_INT
);
3376 EA
= tcg_temp_new();
3377 gen_addr_imm_index(ctx
, EA
, 0x03);
3378 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
3379 if (Rc(ctx
->opcode
))
3380 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
3385 /*** Integer load and store with byte reverse ***/
3388 static inline void gen_qemu_ld16ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3390 TCGMemOp op
= MO_UW
| (ctx
->default_tcg_memop_mask
^ MO_BSWAP
);
3391 tcg_gen_qemu_ld_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
3393 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
);
3396 static inline void gen_qemu_ld32ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3398 TCGMemOp op
= MO_UL
| (ctx
->default_tcg_memop_mask
^ MO_BSWAP
);
3399 tcg_gen_qemu_ld_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
3401 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
);
3403 #if defined(TARGET_PPC64)
3405 static inline void gen_qemu_ld64ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3407 TCGMemOp op
= MO_Q
| (ctx
->default_tcg_memop_mask
^ MO_BSWAP
);
3408 tcg_gen_qemu_ld_i64(arg1
, arg2
, ctx
->mem_idx
, op
);
3410 GEN_LDX_E(ldbr
, ld64ur
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
, CHK_NONE
);
3411 #endif /* TARGET_PPC64 */
3414 static inline void gen_qemu_st16r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3416 TCGMemOp op
= MO_UW
| (ctx
->default_tcg_memop_mask
^ MO_BSWAP
);
3417 tcg_gen_qemu_st_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
3419 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
);
3422 static inline void gen_qemu_st32r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3424 TCGMemOp op
= MO_UL
| (ctx
->default_tcg_memop_mask
^ MO_BSWAP
);
3425 tcg_gen_qemu_st_tl(arg1
, arg2
, ctx
->mem_idx
, op
);
3427 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
);
3429 #if defined(TARGET_PPC64)
3431 static inline void gen_qemu_st64r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3433 TCGMemOp op
= MO_Q
| (ctx
->default_tcg_memop_mask
^ MO_BSWAP
);
3434 tcg_gen_qemu_st_i64(arg1
, arg2
, ctx
->mem_idx
, op
);
3436 GEN_STX_E(stdbr
, st64r
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
, CHK_NONE
);
3437 #endif /* TARGET_PPC64 */
3439 /*** Integer load and store multiple ***/
3442 static void gen_lmw(DisasContext
*ctx
)
3446 gen_set_access_type(ctx
, ACCESS_INT
);
3447 /* NIP cannot be restored if the memory exception comes from an helper */
3448 gen_update_nip(ctx
, ctx
->nip
- 4);
3449 t0
= tcg_temp_new();
3450 t1
= tcg_const_i32(rD(ctx
->opcode
));
3451 gen_addr_imm_index(ctx
, t0
, 0);
3452 gen_helper_lmw(cpu_env
, t0
, t1
);
3454 tcg_temp_free_i32(t1
);
3458 static void gen_stmw(DisasContext
*ctx
)
3462 gen_set_access_type(ctx
, ACCESS_INT
);
3463 /* NIP cannot be restored if the memory exception comes from an helper */
3464 gen_update_nip(ctx
, ctx
->nip
- 4);
3465 t0
= tcg_temp_new();
3466 t1
= tcg_const_i32(rS(ctx
->opcode
));
3467 gen_addr_imm_index(ctx
, t0
, 0);
3468 gen_helper_stmw(cpu_env
, t0
, t1
);
3470 tcg_temp_free_i32(t1
);
3473 /*** Integer load and store strings ***/
3476 /* PowerPC32 specification says we must generate an exception if
3477 * rA is in the range of registers to be loaded.
3478 * In an other hand, IBM says this is valid, but rA won't be loaded.
3479 * For now, I'll follow the spec...
3481 static void gen_lswi(DisasContext
*ctx
)
3485 int nb
= NB(ctx
->opcode
);
3486 int start
= rD(ctx
->opcode
);
3487 int ra
= rA(ctx
->opcode
);
3493 if (unlikely(lsw_reg_in_range(start
, nr
, ra
))) {
3494 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
3497 gen_set_access_type(ctx
, ACCESS_INT
);
3498 /* NIP cannot be restored if the memory exception comes from an helper */
3499 gen_update_nip(ctx
, ctx
->nip
- 4);
3500 t0
= tcg_temp_new();
3501 gen_addr_register(ctx
, t0
);
3502 t1
= tcg_const_i32(nb
);
3503 t2
= tcg_const_i32(start
);
3504 gen_helper_lsw(cpu_env
, t0
, t1
, t2
);
3506 tcg_temp_free_i32(t1
);
3507 tcg_temp_free_i32(t2
);
3511 static void gen_lswx(DisasContext
*ctx
)
3514 TCGv_i32 t1
, t2
, t3
;
3515 gen_set_access_type(ctx
, ACCESS_INT
);
3516 /* NIP cannot be restored if the memory exception comes from an helper */
3517 gen_update_nip(ctx
, ctx
->nip
- 4);
3518 t0
= tcg_temp_new();
3519 gen_addr_reg_index(ctx
, t0
);
3520 t1
= tcg_const_i32(rD(ctx
->opcode
));
3521 t2
= tcg_const_i32(rA(ctx
->opcode
));
3522 t3
= tcg_const_i32(rB(ctx
->opcode
));
3523 gen_helper_lswx(cpu_env
, t0
, t1
, t2
, t3
);
3525 tcg_temp_free_i32(t1
);
3526 tcg_temp_free_i32(t2
);
3527 tcg_temp_free_i32(t3
);
3531 static void gen_stswi(DisasContext
*ctx
)
3535 int nb
= NB(ctx
->opcode
);
3536 gen_set_access_type(ctx
, ACCESS_INT
);
3537 /* NIP cannot be restored if the memory exception comes from an helper */
3538 gen_update_nip(ctx
, ctx
->nip
- 4);
3539 t0
= tcg_temp_new();
3540 gen_addr_register(ctx
, t0
);
3543 t1
= tcg_const_i32(nb
);
3544 t2
= tcg_const_i32(rS(ctx
->opcode
));
3545 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3547 tcg_temp_free_i32(t1
);
3548 tcg_temp_free_i32(t2
);
3552 static void gen_stswx(DisasContext
*ctx
)
3556 gen_set_access_type(ctx
, ACCESS_INT
);
3557 /* NIP cannot be restored if the memory exception comes from an helper */
3558 gen_update_nip(ctx
, ctx
->nip
- 4);
3559 t0
= tcg_temp_new();
3560 gen_addr_reg_index(ctx
, t0
);
3561 t1
= tcg_temp_new_i32();
3562 tcg_gen_trunc_tl_i32(t1
, cpu_xer
);
3563 tcg_gen_andi_i32(t1
, t1
, 0x7F);
3564 t2
= tcg_const_i32(rS(ctx
->opcode
));
3565 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3567 tcg_temp_free_i32(t1
);
3568 tcg_temp_free_i32(t2
);
3571 /*** Memory synchronisation ***/
3573 static void gen_eieio(DisasContext
*ctx
)
3577 #if !defined(CONFIG_USER_ONLY)
3578 static inline void gen_check_tlb_flush(DisasContext
*ctx
)
3583 if (!ctx
->lazy_tlb_flush
) {
3586 l
= gen_new_label();
3587 t
= tcg_temp_new_i32();
3588 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUPPCState
, tlb_need_flush
));
3589 tcg_gen_brcondi_i32(TCG_COND_EQ
, t
, 0, l
);
3590 gen_helper_check_tlb_flush(cpu_env
);
3592 tcg_temp_free_i32(t
);
3595 static inline void gen_check_tlb_flush(DisasContext
*ctx
) { }
3599 static void gen_isync(DisasContext
*ctx
)
3602 * We need to check for a pending TLB flush. This can only happen in
3603 * kernel mode however so check MSR_PR
3606 gen_check_tlb_flush(ctx
);
3608 gen_stop_exception(ctx
);
3611 #define LARX(name, len, loadop) \
3612 static void gen_##name(DisasContext *ctx) \
3615 TCGv gpr = cpu_gpr[rD(ctx->opcode)]; \
3616 gen_set_access_type(ctx, ACCESS_RES); \
3617 t0 = tcg_temp_local_new(); \
3618 gen_addr_reg_index(ctx, t0); \
3620 gen_check_align(ctx, t0, (len)-1); \
3622 gen_qemu_##loadop(ctx, gpr, t0); \
3623 tcg_gen_mov_tl(cpu_reserve, t0); \
3624 tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); \
3625 tcg_temp_free(t0); \
3629 LARX(lbarx
, 1, ld8u
);
3630 LARX(lharx
, 2, ld16u
);
3631 LARX(lwarx
, 4, ld32u
);
3634 #if defined(CONFIG_USER_ONLY)
3635 static void gen_conditional_store(DisasContext
*ctx
, TCGv EA
,
3638 TCGv t0
= tcg_temp_new();
3639 uint32_t save_exception
= ctx
->exception
;
3641 tcg_gen_st_tl(EA
, cpu_env
, offsetof(CPUPPCState
, reserve_ea
));
3642 tcg_gen_movi_tl(t0
, (size
<< 5) | reg
);
3643 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, reserve_info
));
3645 gen_update_nip(ctx
, ctx
->nip
-4);
3646 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3647 gen_exception(ctx
, POWERPC_EXCP_STCX
);
3648 ctx
->exception
= save_exception
;
3651 static void gen_conditional_store(DisasContext
*ctx
, TCGv EA
,
3656 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
3657 l1
= gen_new_label();
3658 tcg_gen_brcond_tl(TCG_COND_NE
, EA
, cpu_reserve
, l1
);
3659 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3660 #if defined(TARGET_PPC64)
3662 gen_qemu_st64(ctx
, cpu_gpr
[reg
], EA
);
3666 gen_qemu_st32(ctx
, cpu_gpr
[reg
], EA
);
3667 } else if (size
== 2) {
3668 gen_qemu_st16(ctx
, cpu_gpr
[reg
], EA
);
3669 #if defined(TARGET_PPC64)
3670 } else if (size
== 16) {
3671 TCGv gpr1
, gpr2
, EA8
;
3672 if (unlikely(ctx
->le_mode
)) {
3673 gpr1
= cpu_gpr
[reg
+1];
3674 gpr2
= cpu_gpr
[reg
];
3676 gpr1
= cpu_gpr
[reg
];
3677 gpr2
= cpu_gpr
[reg
+1];
3679 gen_qemu_st64(ctx
, gpr1
, EA
);
3680 EA8
= tcg_temp_local_new();
3681 gen_addr_add(ctx
, EA8
, EA
, 8);
3682 gen_qemu_st64(ctx
, gpr2
, EA8
);
3686 gen_qemu_st8(ctx
, cpu_gpr
[reg
], EA
);
3689 tcg_gen_movi_tl(cpu_reserve
, -1);
3693 #define STCX(name, len) \
3694 static void gen_##name(DisasContext *ctx) \
3697 if (unlikely((len == 16) && (rD(ctx->opcode) & 1))) { \
3698 gen_inval_exception(ctx, \
3699 POWERPC_EXCP_INVAL_INVAL); \
3702 gen_set_access_type(ctx, ACCESS_RES); \
3703 t0 = tcg_temp_local_new(); \
3704 gen_addr_reg_index(ctx, t0); \
3706 gen_check_align(ctx, t0, (len)-1); \
3708 gen_conditional_store(ctx, t0, rS(ctx->opcode), len); \
3709 tcg_temp_free(t0); \
3716 #if defined(TARGET_PPC64)
3718 LARX(ldarx
, 8, ld64
);
3721 static void gen_lqarx(DisasContext
*ctx
)
3724 int rd
= rD(ctx
->opcode
);
3727 if (unlikely((rd
& 1) || (rd
== rA(ctx
->opcode
)) ||
3728 (rd
== rB(ctx
->opcode
)))) {
3729 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3733 gen_set_access_type(ctx
, ACCESS_RES
);
3734 EA
= tcg_temp_local_new();
3735 gen_addr_reg_index(ctx
, EA
);
3736 gen_check_align(ctx
, EA
, 15);
3737 if (unlikely(ctx
->le_mode
)) {
3738 gpr1
= cpu_gpr
[rd
+1];
3742 gpr2
= cpu_gpr
[rd
+1];
3744 gen_qemu_ld64(ctx
, gpr1
, EA
);
3745 tcg_gen_mov_tl(cpu_reserve
, EA
);
3747 gen_addr_add(ctx
, EA
, EA
, 8);
3748 gen_qemu_ld64(ctx
, gpr2
, EA
);
3750 tcg_gen_st_tl(gpr1
, cpu_env
, offsetof(CPUPPCState
, reserve_val
));
3751 tcg_gen_st_tl(gpr2
, cpu_env
, offsetof(CPUPPCState
, reserve_val2
));
3759 #endif /* defined(TARGET_PPC64) */
3762 static void gen_sync(DisasContext
*ctx
)
3764 uint32_t l
= (ctx
->opcode
>> 21) & 3;
3767 * We may need to check for a pending TLB flush.
3769 * We do this on ptesync (l == 2) on ppc64 and any sync pn ppc32.
3771 * Additionally, this can only happen in kernel mode however so
3772 * check MSR_PR as well.
3774 if (((l
== 2) || !(ctx
->insns_flags
& PPC_64B
)) && !ctx
->pr
) {
3775 gen_check_tlb_flush(ctx
);
3780 static void gen_wait(DisasContext
*ctx
)
3782 TCGv_i32 t0
= tcg_const_i32(1);
3783 tcg_gen_st_i32(t0
, cpu_env
,
3784 -offsetof(PowerPCCPU
, env
) + offsetof(CPUState
, halted
));
3785 tcg_temp_free_i32(t0
);
3786 /* Stop translation, as the CPU is supposed to sleep from now */
3787 gen_exception_err(ctx
, EXCP_HLT
, 1);
3790 #if defined(TARGET_PPC64)
3791 static void gen_doze(DisasContext
*ctx
)
3793 #if defined(CONFIG_USER_ONLY)
3799 t
= tcg_const_i32(PPC_PM_DOZE
);
3800 gen_helper_pminsn(cpu_env
, t
);
3801 tcg_temp_free_i32(t
);
3802 gen_stop_exception(ctx
);
3803 #endif /* defined(CONFIG_USER_ONLY) */
3806 static void gen_nap(DisasContext
*ctx
)
3808 #if defined(CONFIG_USER_ONLY)
3814 t
= tcg_const_i32(PPC_PM_NAP
);
3815 gen_helper_pminsn(cpu_env
, t
);
3816 tcg_temp_free_i32(t
);
3817 gen_stop_exception(ctx
);
3818 #endif /* defined(CONFIG_USER_ONLY) */
3821 static void gen_sleep(DisasContext
*ctx
)
3823 #if defined(CONFIG_USER_ONLY)
3829 t
= tcg_const_i32(PPC_PM_SLEEP
);
3830 gen_helper_pminsn(cpu_env
, t
);
3831 tcg_temp_free_i32(t
);
3832 gen_stop_exception(ctx
);
3833 #endif /* defined(CONFIG_USER_ONLY) */
3836 static void gen_rvwinkle(DisasContext
*ctx
)
3838 #if defined(CONFIG_USER_ONLY)
3844 t
= tcg_const_i32(PPC_PM_RVWINKLE
);
3845 gen_helper_pminsn(cpu_env
, t
);
3846 tcg_temp_free_i32(t
);
3847 gen_stop_exception(ctx
);
3848 #endif /* defined(CONFIG_USER_ONLY) */
3850 #endif /* #if defined(TARGET_PPC64) */
3852 /*** Floating-point load ***/
3853 #define GEN_LDF(name, ldop, opc, type) \
3854 static void glue(gen_, name)(DisasContext *ctx) \
3857 if (unlikely(!ctx->fpu_enabled)) { \
3858 gen_exception(ctx, POWERPC_EXCP_FPU); \
3861 gen_set_access_type(ctx, ACCESS_FLOAT); \
3862 EA = tcg_temp_new(); \
3863 gen_addr_imm_index(ctx, EA, 0); \
3864 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3865 tcg_temp_free(EA); \
3868 #define GEN_LDUF(name, ldop, opc, type) \
3869 static void glue(gen_, name##u)(DisasContext *ctx) \
3872 if (unlikely(!ctx->fpu_enabled)) { \
3873 gen_exception(ctx, POWERPC_EXCP_FPU); \
3876 if (unlikely(rA(ctx->opcode) == 0)) { \
3877 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3880 gen_set_access_type(ctx, ACCESS_FLOAT); \
3881 EA = tcg_temp_new(); \
3882 gen_addr_imm_index(ctx, EA, 0); \
3883 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3884 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3885 tcg_temp_free(EA); \
3888 #define GEN_LDUXF(name, ldop, opc, type) \
3889 static void glue(gen_, name##ux)(DisasContext *ctx) \
3892 if (unlikely(!ctx->fpu_enabled)) { \
3893 gen_exception(ctx, POWERPC_EXCP_FPU); \
3896 if (unlikely(rA(ctx->opcode) == 0)) { \
3897 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3900 gen_set_access_type(ctx, ACCESS_FLOAT); \
3901 EA = tcg_temp_new(); \
3902 gen_addr_reg_index(ctx, EA); \
3903 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3904 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3905 tcg_temp_free(EA); \
3908 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
3909 static void glue(gen_, name##x)(DisasContext *ctx) \
3912 if (unlikely(!ctx->fpu_enabled)) { \
3913 gen_exception(ctx, POWERPC_EXCP_FPU); \
3916 gen_set_access_type(ctx, ACCESS_FLOAT); \
3917 EA = tcg_temp_new(); \
3918 gen_addr_reg_index(ctx, EA); \
3919 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3920 tcg_temp_free(EA); \
3923 #define GEN_LDFS(name, ldop, op, type) \
3924 GEN_LDF(name, ldop, op | 0x20, type); \
3925 GEN_LDUF(name, ldop, op | 0x21, type); \
3926 GEN_LDUXF(name, ldop, op | 0x01, type); \
3927 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3929 static inline void gen_qemu_ld32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3931 TCGv t0
= tcg_temp_new();
3932 TCGv_i32 t1
= tcg_temp_new_i32();
3933 gen_qemu_ld32u(ctx
, t0
, arg2
);
3934 tcg_gen_trunc_tl_i32(t1
, t0
);
3936 gen_helper_float32_to_float64(arg1
, cpu_env
, t1
);
3937 tcg_temp_free_i32(t1
);
3940 /* lfd lfdu lfdux lfdx */
3941 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
);
3942 /* lfs lfsu lfsux lfsx */
3943 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
);
3946 static void gen_lfdp(DisasContext
*ctx
)
3949 if (unlikely(!ctx
->fpu_enabled
)) {
3950 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3953 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3954 EA
= tcg_temp_new();
3955 gen_addr_imm_index(ctx
, EA
, 0);
3956 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
3957 64-bit byteswap already. */
3958 if (unlikely(ctx
->le_mode
)) {
3959 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3960 tcg_gen_addi_tl(EA
, EA
, 8);
3961 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3963 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3964 tcg_gen_addi_tl(EA
, EA
, 8);
3965 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3971 static void gen_lfdpx(DisasContext
*ctx
)
3974 if (unlikely(!ctx
->fpu_enabled
)) {
3975 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3978 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3979 EA
= tcg_temp_new();
3980 gen_addr_reg_index(ctx
, EA
);
3981 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary
3982 64-bit byteswap already. */
3983 if (unlikely(ctx
->le_mode
)) {
3984 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3985 tcg_gen_addi_tl(EA
, EA
, 8);
3986 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3988 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3989 tcg_gen_addi_tl(EA
, EA
, 8);
3990 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3996 static void gen_lfiwax(DisasContext
*ctx
)
4000 if (unlikely(!ctx
->fpu_enabled
)) {
4001 gen_exception(ctx
, POWERPC_EXCP_FPU
);
4004 gen_set_access_type(ctx
, ACCESS_FLOAT
);
4005 EA
= tcg_temp_new();
4006 t0
= tcg_temp_new();
4007 gen_addr_reg_index(ctx
, EA
);
4008 gen_qemu_ld32s(ctx
, t0
, EA
);
4009 tcg_gen_ext_tl_i64(cpu_fpr
[rD(ctx
->opcode
)], t0
);
4015 static void gen_lfiwzx(DisasContext
*ctx
)
4018 if (unlikely(!ctx
->fpu_enabled
)) {
4019 gen_exception(ctx
, POWERPC_EXCP_FPU
);
4022 gen_set_access_type(ctx
, ACCESS_FLOAT
);
4023 EA
= tcg_temp_new();
4024 gen_addr_reg_index(ctx
, EA
);
4025 gen_qemu_ld32u_i64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
4028 /*** Floating-point store ***/
4029 #define GEN_STF(name, stop, opc, type) \
4030 static void glue(gen_, name)(DisasContext *ctx) \
4033 if (unlikely(!ctx->fpu_enabled)) { \
4034 gen_exception(ctx, POWERPC_EXCP_FPU); \
4037 gen_set_access_type(ctx, ACCESS_FLOAT); \
4038 EA = tcg_temp_new(); \
4039 gen_addr_imm_index(ctx, EA, 0); \
4040 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
4041 tcg_temp_free(EA); \
4044 #define GEN_STUF(name, stop, opc, type) \
4045 static void glue(gen_, name##u)(DisasContext *ctx) \
4048 if (unlikely(!ctx->fpu_enabled)) { \
4049 gen_exception(ctx, POWERPC_EXCP_FPU); \
4052 if (unlikely(rA(ctx->opcode) == 0)) { \
4053 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
4056 gen_set_access_type(ctx, ACCESS_FLOAT); \
4057 EA = tcg_temp_new(); \
4058 gen_addr_imm_index(ctx, EA, 0); \
4059 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
4060 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
4061 tcg_temp_free(EA); \
4064 #define GEN_STUXF(name, stop, opc, type) \
4065 static void glue(gen_, name##ux)(DisasContext *ctx) \
4068 if (unlikely(!ctx->fpu_enabled)) { \
4069 gen_exception(ctx, POWERPC_EXCP_FPU); \
4072 if (unlikely(rA(ctx->opcode) == 0)) { \
4073 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
4076 gen_set_access_type(ctx, ACCESS_FLOAT); \
4077 EA = tcg_temp_new(); \
4078 gen_addr_reg_index(ctx, EA); \
4079 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
4080 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
4081 tcg_temp_free(EA); \
4084 #define GEN_STXF(name, stop, opc2, opc3, type) \
4085 static void glue(gen_, name##x)(DisasContext *ctx) \
4088 if (unlikely(!ctx->fpu_enabled)) { \
4089 gen_exception(ctx, POWERPC_EXCP_FPU); \
4092 gen_set_access_type(ctx, ACCESS_FLOAT); \
4093 EA = tcg_temp_new(); \
4094 gen_addr_reg_index(ctx, EA); \
4095 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
4096 tcg_temp_free(EA); \
4099 #define GEN_STFS(name, stop, op, type) \
4100 GEN_STF(name, stop, op | 0x20, type); \
4101 GEN_STUF(name, stop, op | 0x21, type); \
4102 GEN_STUXF(name, stop, op | 0x01, type); \
4103 GEN_STXF(name, stop, 0x17, op | 0x00, type)
4105 static inline void gen_qemu_st32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
4107 TCGv_i32 t0
= tcg_temp_new_i32();
4108 TCGv t1
= tcg_temp_new();
4109 gen_helper_float64_to_float32(t0
, cpu_env
, arg1
);
4110 tcg_gen_extu_i32_tl(t1
, t0
);
4111 tcg_temp_free_i32(t0
);
4112 gen_qemu_st32(ctx
, t1
, arg2
);
4116 /* stfd stfdu stfdux stfdx */
4117 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
);
4118 /* stfs stfsu stfsux stfsx */
4119 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
);
4122 static void gen_stfdp(DisasContext
*ctx
)
4125 if (unlikely(!ctx
->fpu_enabled
)) {
4126 gen_exception(ctx
, POWERPC_EXCP_FPU
);
4129 gen_set_access_type(ctx
, ACCESS_FLOAT
);
4130 EA
= tcg_temp_new();
4131 gen_addr_imm_index(ctx
, EA
, 0);
4132 /* We only need to swap high and low halves. gen_qemu_st64 does necessary
4133 64-bit byteswap already. */
4134 if (unlikely(ctx
->le_mode
)) {
4135 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
4136 tcg_gen_addi_tl(EA
, EA
, 8);
4137 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
4139 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
4140 tcg_gen_addi_tl(EA
, EA
, 8);
4141 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
4147 static void gen_stfdpx(DisasContext
*ctx
)
4150 if (unlikely(!ctx
->fpu_enabled
)) {
4151 gen_exception(ctx
, POWERPC_EXCP_FPU
);
4154 gen_set_access_type(ctx
, ACCESS_FLOAT
);
4155 EA
= tcg_temp_new();
4156 gen_addr_reg_index(ctx
, EA
);
4157 /* We only need to swap high and low halves. gen_qemu_st64 does necessary
4158 64-bit byteswap already. */
4159 if (unlikely(ctx
->le_mode
)) {
4160 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
4161 tcg_gen_addi_tl(EA
, EA
, 8);
4162 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
4164 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
4165 tcg_gen_addi_tl(EA
, EA
, 8);
4166 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
4172 static inline void gen_qemu_st32fiw(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
4174 TCGv t0
= tcg_temp_new();
4175 tcg_gen_trunc_i64_tl(t0
, arg1
),
4176 gen_qemu_st32(ctx
, t0
, arg2
);
4180 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
);
4182 static inline void gen_update_cfar(DisasContext
*ctx
, target_ulong nip
)
4184 #if defined(TARGET_PPC64)
4186 tcg_gen_movi_tl(cpu_cfar
, nip
);
4190 static inline bool use_goto_tb(DisasContext
*ctx
, target_ulong dest
)
4192 if (unlikely(ctx
->singlestep_enabled
)) {
4196 #ifndef CONFIG_USER_ONLY
4197 return (ctx
->tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
);
4204 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
4206 if (NARROW_MODE(ctx
)) {
4207 dest
= (uint32_t) dest
;
4209 if (use_goto_tb(ctx
, dest
)) {
4211 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
4212 tcg_gen_exit_tb((uintptr_t)ctx
->tb
+ n
);
4214 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
4215 if (unlikely(ctx
->singlestep_enabled
)) {
4216 if ((ctx
->singlestep_enabled
&
4217 (CPU_BRANCH_STEP
| CPU_SINGLE_STEP
)) &&
4218 (ctx
->exception
== POWERPC_EXCP_BRANCH
||
4219 ctx
->exception
== POWERPC_EXCP_TRACE
)) {
4220 target_ulong tmp
= ctx
->nip
;
4222 gen_exception(ctx
, POWERPC_EXCP_TRACE
);
4225 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
4226 gen_debug_exception(ctx
);
4233 static inline void gen_setlr(DisasContext
*ctx
, target_ulong nip
)
4235 if (NARROW_MODE(ctx
)) {
4236 nip
= (uint32_t)nip
;
4238 tcg_gen_movi_tl(cpu_lr
, nip
);
4242 static void gen_b(DisasContext
*ctx
)
4244 target_ulong li
, target
;
4246 ctx
->exception
= POWERPC_EXCP_BRANCH
;
4247 /* sign extend LI */
4248 li
= LI(ctx
->opcode
);
4249 li
= (li
^ 0x02000000) - 0x02000000;
4250 if (likely(AA(ctx
->opcode
) == 0)) {
4251 target
= ctx
->nip
+ li
- 4;
4255 if (LK(ctx
->opcode
)) {
4256 gen_setlr(ctx
, ctx
->nip
);
4258 gen_update_cfar(ctx
, ctx
->nip
);
4259 gen_goto_tb(ctx
, 0, target
);
4267 static inline void gen_bcond(DisasContext
*ctx
, int type
)
4269 uint32_t bo
= BO(ctx
->opcode
);
4273 ctx
->exception
= POWERPC_EXCP_BRANCH
;
4274 if (type
== BCOND_LR
|| type
== BCOND_CTR
|| type
== BCOND_TAR
) {
4275 target
= tcg_temp_local_new();
4276 if (type
== BCOND_CTR
)
4277 tcg_gen_mov_tl(target
, cpu_ctr
);
4278 else if (type
== BCOND_TAR
)
4279 gen_load_spr(target
, SPR_TAR
);
4281 tcg_gen_mov_tl(target
, cpu_lr
);
4283 TCGV_UNUSED(target
);
4285 if (LK(ctx
->opcode
))
4286 gen_setlr(ctx
, ctx
->nip
);
4287 l1
= gen_new_label();
4288 if ((bo
& 0x4) == 0) {
4289 /* Decrement and test CTR */
4290 TCGv temp
= tcg_temp_new();
4291 if (unlikely(type
== BCOND_CTR
)) {
4292 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
4295 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
4296 if (NARROW_MODE(ctx
)) {
4297 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
4299 tcg_gen_mov_tl(temp
, cpu_ctr
);
4302 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
4304 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
4306 tcg_temp_free(temp
);
4308 if ((bo
& 0x10) == 0) {
4310 uint32_t bi
= BI(ctx
->opcode
);
4311 uint32_t mask
= 0x08 >> (bi
& 0x03);
4312 TCGv_i32 temp
= tcg_temp_new_i32();
4315 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
4316 tcg_gen_brcondi_i32(TCG_COND_EQ
, temp
, 0, l1
);
4318 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
4319 tcg_gen_brcondi_i32(TCG_COND_NE
, temp
, 0, l1
);
4321 tcg_temp_free_i32(temp
);
4323 gen_update_cfar(ctx
, ctx
->nip
);
4324 if (type
== BCOND_IM
) {
4325 target_ulong li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
4326 if (likely(AA(ctx
->opcode
) == 0)) {
4327 gen_goto_tb(ctx
, 0, ctx
->nip
+ li
- 4);
4329 gen_goto_tb(ctx
, 0, li
);
4332 gen_goto_tb(ctx
, 1, ctx
->nip
);
4334 if (NARROW_MODE(ctx
)) {
4335 tcg_gen_andi_tl(cpu_nip
, target
, (uint32_t)~3);
4337 tcg_gen_andi_tl(cpu_nip
, target
, ~3);
4341 gen_update_nip(ctx
, ctx
->nip
);
4344 if (type
== BCOND_LR
|| type
== BCOND_CTR
|| type
== BCOND_TAR
) {
4345 tcg_temp_free(target
);
4349 static void gen_bc(DisasContext
*ctx
)
4351 gen_bcond(ctx
, BCOND_IM
);
4354 static void gen_bcctr(DisasContext
*ctx
)
4356 gen_bcond(ctx
, BCOND_CTR
);
4359 static void gen_bclr(DisasContext
*ctx
)
4361 gen_bcond(ctx
, BCOND_LR
);
4364 static void gen_bctar(DisasContext
*ctx
)
4366 gen_bcond(ctx
, BCOND_TAR
);
4369 /*** Condition register logical ***/
4370 #define GEN_CRLOGIC(name, tcg_op, opc) \
4371 static void glue(gen_, name)(DisasContext *ctx) \
4376 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
4377 t0 = tcg_temp_new_i32(); \
4379 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
4381 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
4383 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
4384 t1 = tcg_temp_new_i32(); \
4385 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
4387 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
4389 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
4391 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
4392 tcg_op(t0, t0, t1); \
4393 bitmask = 0x08 >> (crbD(ctx->opcode) & 0x03); \
4394 tcg_gen_andi_i32(t0, t0, bitmask); \
4395 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
4396 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
4397 tcg_temp_free_i32(t0); \
4398 tcg_temp_free_i32(t1); \
4402 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08);
4404 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04);
4406 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09);
4408 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07);
4410 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01);
4412 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E);
4414 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D);
4416 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06);
4419 static void gen_mcrf(DisasContext
*ctx
)
4421 tcg_gen_mov_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfS(ctx
->opcode
)]);
4424 /*** System linkage ***/
4426 /* rfi (supervisor only) */
4427 static void gen_rfi(DisasContext
*ctx
)
4429 #if defined(CONFIG_USER_ONLY)
4432 /* FIXME: This instruction doesn't exist anymore on 64-bit server
4433 * processors compliant with arch 2.x, we should remove it there,
4434 * but we need to fix OpenBIOS not to use it on 970 first
4436 /* Restore CPU state */
4438 gen_update_cfar(ctx
, ctx
->nip
);
4439 gen_helper_rfi(cpu_env
);
4440 gen_sync_exception(ctx
);
4444 #if defined(TARGET_PPC64)
4445 static void gen_rfid(DisasContext
*ctx
)
4447 #if defined(CONFIG_USER_ONLY)
4450 /* Restore CPU state */
4452 gen_update_cfar(ctx
, ctx
->nip
);
4453 gen_helper_rfid(cpu_env
);
4454 gen_sync_exception(ctx
);
4458 static void gen_hrfid(DisasContext
*ctx
)
4460 #if defined(CONFIG_USER_ONLY)
4463 /* Restore CPU state */
4465 gen_helper_hrfid(cpu_env
);
4466 gen_sync_exception(ctx
);
4472 #if defined(CONFIG_USER_ONLY)
4473 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
4475 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
4477 static void gen_sc(DisasContext
*ctx
)
4481 lev
= (ctx
->opcode
>> 5) & 0x7F;
4482 gen_exception_err(ctx
, POWERPC_SYSCALL
, lev
);
4488 static void gen_tw(DisasContext
*ctx
)
4490 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
4491 /* Update the nip since this might generate a trap exception */
4492 gen_update_nip(ctx
, ctx
->nip
);
4493 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
4495 tcg_temp_free_i32(t0
);
4499 static void gen_twi(DisasContext
*ctx
)
4501 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
4502 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
4503 /* Update the nip since this might generate a trap exception */
4504 gen_update_nip(ctx
, ctx
->nip
);
4505 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4507 tcg_temp_free_i32(t1
);
4510 #if defined(TARGET_PPC64)
4512 static void gen_td(DisasContext
*ctx
)
4514 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
4515 /* Update the nip since this might generate a trap exception */
4516 gen_update_nip(ctx
, ctx
->nip
);
4517 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
4519 tcg_temp_free_i32(t0
);
4523 static void gen_tdi(DisasContext
*ctx
)
4525 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
4526 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
4527 /* Update the nip since this might generate a trap exception */
4528 gen_update_nip(ctx
, ctx
->nip
);
4529 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4531 tcg_temp_free_i32(t1
);
4535 /*** Processor control ***/
4537 static void gen_read_xer(TCGv dst
)
4539 TCGv t0
= tcg_temp_new();
4540 TCGv t1
= tcg_temp_new();
4541 TCGv t2
= tcg_temp_new();
4542 tcg_gen_mov_tl(dst
, cpu_xer
);
4543 tcg_gen_shli_tl(t0
, cpu_so
, XER_SO
);
4544 tcg_gen_shli_tl(t1
, cpu_ov
, XER_OV
);
4545 tcg_gen_shli_tl(t2
, cpu_ca
, XER_CA
);
4546 tcg_gen_or_tl(t0
, t0
, t1
);
4547 tcg_gen_or_tl(dst
, dst
, t2
);
4548 tcg_gen_or_tl(dst
, dst
, t0
);
4554 static void gen_write_xer(TCGv src
)
4556 tcg_gen_andi_tl(cpu_xer
, src
,
4557 ~((1u << XER_SO
) | (1u << XER_OV
) | (1u << XER_CA
)));
4558 tcg_gen_shri_tl(cpu_so
, src
, XER_SO
);
4559 tcg_gen_shri_tl(cpu_ov
, src
, XER_OV
);
4560 tcg_gen_shri_tl(cpu_ca
, src
, XER_CA
);
4561 tcg_gen_andi_tl(cpu_so
, cpu_so
, 1);
4562 tcg_gen_andi_tl(cpu_ov
, cpu_ov
, 1);
4563 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
4567 static void gen_mcrxr(DisasContext
*ctx
)
4569 TCGv_i32 t0
= tcg_temp_new_i32();
4570 TCGv_i32 t1
= tcg_temp_new_i32();
4571 TCGv_i32 dst
= cpu_crf
[crfD(ctx
->opcode
)];
4573 tcg_gen_trunc_tl_i32(t0
, cpu_so
);
4574 tcg_gen_trunc_tl_i32(t1
, cpu_ov
);
4575 tcg_gen_trunc_tl_i32(dst
, cpu_ca
);
4576 tcg_gen_shli_i32(t0
, t0
, 3);
4577 tcg_gen_shli_i32(t1
, t1
, 2);
4578 tcg_gen_shli_i32(dst
, dst
, 1);
4579 tcg_gen_or_i32(dst
, dst
, t0
);
4580 tcg_gen_or_i32(dst
, dst
, t1
);
4581 tcg_temp_free_i32(t0
);
4582 tcg_temp_free_i32(t1
);
4584 tcg_gen_movi_tl(cpu_so
, 0);
4585 tcg_gen_movi_tl(cpu_ov
, 0);
4586 tcg_gen_movi_tl(cpu_ca
, 0);
4590 static void gen_mfcr(DisasContext
*ctx
)
4594 if (likely(ctx
->opcode
& 0x00100000)) {
4595 crm
= CRM(ctx
->opcode
);
4596 if (likely(crm
&& ((crm
& (crm
- 1)) == 0))) {
4598 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_crf
[7 - crn
]);
4599 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)],
4600 cpu_gpr
[rD(ctx
->opcode
)], crn
* 4);
4603 TCGv_i32 t0
= tcg_temp_new_i32();
4604 tcg_gen_mov_i32(t0
, cpu_crf
[0]);
4605 tcg_gen_shli_i32(t0
, t0
, 4);
4606 tcg_gen_or_i32(t0
, t0
, cpu_crf
[1]);
4607 tcg_gen_shli_i32(t0
, t0
, 4);
4608 tcg_gen_or_i32(t0
, t0
, cpu_crf
[2]);
4609 tcg_gen_shli_i32(t0
, t0
, 4);
4610 tcg_gen_or_i32(t0
, t0
, cpu_crf
[3]);
4611 tcg_gen_shli_i32(t0
, t0
, 4);
4612 tcg_gen_or_i32(t0
, t0
, cpu_crf
[4]);
4613 tcg_gen_shli_i32(t0
, t0
, 4);
4614 tcg_gen_or_i32(t0
, t0
, cpu_crf
[5]);
4615 tcg_gen_shli_i32(t0
, t0
, 4);
4616 tcg_gen_or_i32(t0
, t0
, cpu_crf
[6]);
4617 tcg_gen_shli_i32(t0
, t0
, 4);
4618 tcg_gen_or_i32(t0
, t0
, cpu_crf
[7]);
4619 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4620 tcg_temp_free_i32(t0
);
4625 static void gen_mfmsr(DisasContext
*ctx
)
4628 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_msr
);
4631 static void spr_noaccess(DisasContext
*ctx
, int gprn
, int sprn
)
4634 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
4635 printf("ERROR: try to access SPR %d !\n", sprn
);
4638 #define SPR_NOACCESS (&spr_noaccess)
4641 static inline void gen_op_mfspr(DisasContext
*ctx
)
4643 void (*read_cb
)(DisasContext
*ctx
, int gprn
, int sprn
);
4644 uint32_t sprn
= SPR(ctx
->opcode
);
4646 #if defined(CONFIG_USER_ONLY)
4647 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
4650 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
4651 } else if (ctx
->hv
) {
4652 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
4654 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
4657 if (likely(read_cb
!= NULL
)) {
4658 if (likely(read_cb
!= SPR_NOACCESS
)) {
4659 (*read_cb
)(ctx
, rD(ctx
->opcode
), sprn
);
4661 /* Privilege exception */
4662 /* This is a hack to avoid warnings when running Linux:
4663 * this OS breaks the PowerPC virtualisation model,
4664 * allowing userland application to read the PVR
4666 if (sprn
!= SPR_PVR
) {
4667 fprintf(stderr
, "Trying to read privileged spr %d (0x%03x) at "
4668 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4669 if (qemu_log_separate()) {
4670 qemu_log("Trying to read privileged spr %d (0x%03x) at "
4671 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4674 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4677 /* ISA 2.07 defines these as no-ops */
4678 if ((ctx
->insns_flags2
& PPC2_ISA207S
) &&
4679 (sprn
>= 808 && sprn
<= 811)) {
4684 fprintf(stderr
, "Trying to read invalid spr %d (0x%03x) at "
4685 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4686 if (qemu_log_separate()) {
4687 qemu_log("Trying to read invalid spr %d (0x%03x) at "
4688 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4691 /* The behaviour depends on MSR:PR and SPR# bit 0x10,
4692 * it can generate a priv, a hv emu or a no-op
4696 gen_priv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4699 if (ctx
->pr
|| sprn
== 0 || sprn
== 4 || sprn
== 5 || sprn
== 6) {
4700 gen_hvpriv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4706 static void gen_mfspr(DisasContext
*ctx
)
4712 static void gen_mftb(DisasContext
*ctx
)
4718 static void gen_mtcrf(DisasContext
*ctx
)
4722 crm
= CRM(ctx
->opcode
);
4723 if (likely((ctx
->opcode
& 0x00100000))) {
4724 if (crm
&& ((crm
& (crm
- 1)) == 0)) {
4725 TCGv_i32 temp
= tcg_temp_new_i32();
4727 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
4728 tcg_gen_shri_i32(temp
, temp
, crn
* 4);
4729 tcg_gen_andi_i32(cpu_crf
[7 - crn
], temp
, 0xf);
4730 tcg_temp_free_i32(temp
);
4733 TCGv_i32 temp
= tcg_temp_new_i32();
4734 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
4735 for (crn
= 0 ; crn
< 8 ; crn
++) {
4736 if (crm
& (1 << crn
)) {
4737 tcg_gen_shri_i32(cpu_crf
[7 - crn
], temp
, crn
* 4);
4738 tcg_gen_andi_i32(cpu_crf
[7 - crn
], cpu_crf
[7 - crn
], 0xf);
4741 tcg_temp_free_i32(temp
);
4746 #if defined(TARGET_PPC64)
4747 static void gen_mtmsrd(DisasContext
*ctx
)
4751 #if !defined(CONFIG_USER_ONLY)
4752 if (ctx
->opcode
& 0x00010000) {
4753 /* Special form that does not need any synchronisation */
4754 TCGv t0
= tcg_temp_new();
4755 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
4756 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(target_ulong
)((1 << MSR_RI
) | (1 << MSR_EE
)));
4757 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
4760 /* XXX: we need to update nip before the store
4761 * if we enter power saving mode, we will exit the loop
4762 * directly from ppc_store_msr
4764 gen_update_nip(ctx
, ctx
->nip
);
4765 gen_helper_store_msr(cpu_env
, cpu_gpr
[rS(ctx
->opcode
)]);
4766 /* Must stop the translation as machine state (may have) changed */
4767 /* Note that mtmsr is not always defined as context-synchronizing */
4768 gen_stop_exception(ctx
);
4770 #endif /* !defined(CONFIG_USER_ONLY) */
4772 #endif /* defined(TARGET_PPC64) */
4774 static void gen_mtmsr(DisasContext
*ctx
)
4778 #if !defined(CONFIG_USER_ONLY)
4779 if (ctx
->opcode
& 0x00010000) {
4780 /* Special form that does not need any synchronisation */
4781 TCGv t0
= tcg_temp_new();
4782 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
4783 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(target_ulong
)((1 << MSR_RI
) | (1 << MSR_EE
)));
4784 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
4787 TCGv msr
= tcg_temp_new();
4789 /* XXX: we need to update nip before the store
4790 * if we enter power saving mode, we will exit the loop
4791 * directly from ppc_store_msr
4793 gen_update_nip(ctx
, ctx
->nip
);
4794 #if defined(TARGET_PPC64)
4795 tcg_gen_deposit_tl(msr
, cpu_msr
, cpu_gpr
[rS(ctx
->opcode
)], 0, 32);
4797 tcg_gen_mov_tl(msr
, cpu_gpr
[rS(ctx
->opcode
)]);
4799 gen_helper_store_msr(cpu_env
, msr
);
4801 /* Must stop the translation as machine state (may have) changed */
4802 /* Note that mtmsr is not always defined as context-synchronizing */
4803 gen_stop_exception(ctx
);
4809 static void gen_mtspr(DisasContext
*ctx
)
4811 void (*write_cb
)(DisasContext
*ctx
, int sprn
, int gprn
);
4812 uint32_t sprn
= SPR(ctx
->opcode
);
4814 #if defined(CONFIG_USER_ONLY)
4815 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
4818 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
4819 } else if (ctx
->hv
) {
4820 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
4822 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
4825 if (likely(write_cb
!= NULL
)) {
4826 if (likely(write_cb
!= SPR_NOACCESS
)) {
4827 (*write_cb
)(ctx
, sprn
, rS(ctx
->opcode
));
4829 /* Privilege exception */
4830 fprintf(stderr
, "Trying to write privileged spr %d (0x%03x) at "
4831 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4832 if (qemu_log_separate()) {
4833 qemu_log("Trying to write privileged spr %d (0x%03x) at "
4834 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4836 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4839 /* ISA 2.07 defines these as no-ops */
4840 if ((ctx
->insns_flags2
& PPC2_ISA207S
) &&
4841 (sprn
>= 808 && sprn
<= 811)) {
4847 if (qemu_log_separate()) {
4848 qemu_log("Trying to write invalid spr %d (0x%03x) at "
4849 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4851 fprintf(stderr
, "Trying to write invalid spr %d (0x%03x) at "
4852 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4855 /* The behaviour depends on MSR:PR and SPR# bit 0x10,
4856 * it can generate a priv, a hv emu or a no-op
4860 gen_priv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4863 if (ctx
->pr
|| sprn
== 0) {
4864 gen_hvpriv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4870 #if defined(TARGET_PPC64)
4872 static void gen_setb(DisasContext
*ctx
)
4874 TCGv_i32 t0
= tcg_temp_new_i32();
4875 TCGv_i32 t8
= tcg_temp_new_i32();
4876 TCGv_i32 tm1
= tcg_temp_new_i32();
4877 int crf
= crfS(ctx
->opcode
);
4879 tcg_gen_setcondi_i32(TCG_COND_GEU
, t0
, cpu_crf
[crf
], 4);
4880 tcg_gen_movi_i32(t8
, 8);
4881 tcg_gen_movi_i32(tm1
, -1);
4882 tcg_gen_movcond_i32(TCG_COND_GEU
, t0
, cpu_crf
[crf
], t8
, tm1
, t0
);
4883 tcg_gen_ext_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4885 tcg_temp_free_i32(t0
);
4886 tcg_temp_free_i32(t8
);
4887 tcg_temp_free_i32(tm1
);
4891 /*** Cache management ***/
4894 static void gen_dcbf(DisasContext
*ctx
)
4896 /* XXX: specification says this is treated as a load by the MMU */
4898 gen_set_access_type(ctx
, ACCESS_CACHE
);
4899 t0
= tcg_temp_new();
4900 gen_addr_reg_index(ctx
, t0
);
4901 gen_qemu_ld8u(ctx
, t0
, t0
);
4905 /* dcbi (Supervisor only) */
4906 static void gen_dcbi(DisasContext
*ctx
)
4908 #if defined(CONFIG_USER_ONLY)
4914 EA
= tcg_temp_new();
4915 gen_set_access_type(ctx
, ACCESS_CACHE
);
4916 gen_addr_reg_index(ctx
, EA
);
4917 val
= tcg_temp_new();
4918 /* XXX: specification says this should be treated as a store by the MMU */
4919 gen_qemu_ld8u(ctx
, val
, EA
);
4920 gen_qemu_st8(ctx
, val
, EA
);
4923 #endif /* defined(CONFIG_USER_ONLY) */
4927 static void gen_dcbst(DisasContext
*ctx
)
4929 /* XXX: specification say this is treated as a load by the MMU */
4931 gen_set_access_type(ctx
, ACCESS_CACHE
);
4932 t0
= tcg_temp_new();
4933 gen_addr_reg_index(ctx
, t0
);
4934 gen_qemu_ld8u(ctx
, t0
, t0
);
4939 static void gen_dcbt(DisasContext
*ctx
)
4941 /* interpreted as no-op */
4942 /* XXX: specification say this is treated as a load by the MMU
4943 * but does not generate any exception
4948 static void gen_dcbtst(DisasContext
*ctx
)
4950 /* interpreted as no-op */
4951 /* XXX: specification say this is treated as a load by the MMU
4952 * but does not generate any exception
4957 static void gen_dcbtls(DisasContext
*ctx
)
4959 /* Always fails locking the cache */
4960 TCGv t0
= tcg_temp_new();
4961 gen_load_spr(t0
, SPR_Exxx_L1CSR0
);
4962 tcg_gen_ori_tl(t0
, t0
, L1CSR0_CUL
);
4963 gen_store_spr(SPR_Exxx_L1CSR0
, t0
);
4968 static void gen_dcbz(DisasContext
*ctx
)
4971 TCGv_i32 tcgv_is_dcbzl
;
4972 int is_dcbzl
= ctx
->opcode
& 0x00200000 ? 1 : 0;
4974 gen_set_access_type(ctx
, ACCESS_CACHE
);
4975 /* NIP cannot be restored if the memory exception comes from an helper */
4976 gen_update_nip(ctx
, ctx
->nip
- 4);
4977 tcgv_addr
= tcg_temp_new();
4978 tcgv_is_dcbzl
= tcg_const_i32(is_dcbzl
);
4980 gen_addr_reg_index(ctx
, tcgv_addr
);
4981 gen_helper_dcbz(cpu_env
, tcgv_addr
, tcgv_is_dcbzl
);
4983 tcg_temp_free(tcgv_addr
);
4984 tcg_temp_free_i32(tcgv_is_dcbzl
);
4988 static void gen_dst(DisasContext
*ctx
)
4990 if (rA(ctx
->opcode
) == 0) {
4991 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
4993 /* interpreted as no-op */
4998 static void gen_dstst(DisasContext
*ctx
)
5000 if (rA(ctx
->opcode
) == 0) {
5001 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
5003 /* interpreted as no-op */
5009 static void gen_dss(DisasContext
*ctx
)
5011 /* interpreted as no-op */
5015 static void gen_icbi(DisasContext
*ctx
)
5018 gen_set_access_type(ctx
, ACCESS_CACHE
);
5019 /* NIP cannot be restored if the memory exception comes from an helper */
5020 gen_update_nip(ctx
, ctx
->nip
- 4);
5021 t0
= tcg_temp_new();
5022 gen_addr_reg_index(ctx
, t0
);
5023 gen_helper_icbi(cpu_env
, t0
);
5029 static void gen_dcba(DisasContext
*ctx
)
5031 /* interpreted as no-op */
5032 /* XXX: specification say this is treated as a store by the MMU
5033 * but does not generate any exception
5037 /*** Segment register manipulation ***/
5038 /* Supervisor only: */
5041 static void gen_mfsr(DisasContext
*ctx
)
5043 #if defined(CONFIG_USER_ONLY)
5049 t0
= tcg_const_tl(SR(ctx
->opcode
));
5050 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5052 #endif /* defined(CONFIG_USER_ONLY) */
5056 static void gen_mfsrin(DisasContext
*ctx
)
5058 #if defined(CONFIG_USER_ONLY)
5064 t0
= tcg_temp_new();
5065 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
5066 tcg_gen_andi_tl(t0
, t0
, 0xF);
5067 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5069 #endif /* defined(CONFIG_USER_ONLY) */
5073 static void gen_mtsr(DisasContext
*ctx
)
5075 #if defined(CONFIG_USER_ONLY)
5081 t0
= tcg_const_tl(SR(ctx
->opcode
));
5082 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
5084 #endif /* defined(CONFIG_USER_ONLY) */
5088 static void gen_mtsrin(DisasContext
*ctx
)
5090 #if defined(CONFIG_USER_ONLY)
5096 t0
= tcg_temp_new();
5097 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
5098 tcg_gen_andi_tl(t0
, t0
, 0xF);
5099 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rD(ctx
->opcode
)]);
5101 #endif /* defined(CONFIG_USER_ONLY) */
5104 #if defined(TARGET_PPC64)
5105 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
5108 static void gen_mfsr_64b(DisasContext
*ctx
)
5110 #if defined(CONFIG_USER_ONLY)
5116 t0
= tcg_const_tl(SR(ctx
->opcode
));
5117 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5119 #endif /* defined(CONFIG_USER_ONLY) */
5123 static void gen_mfsrin_64b(DisasContext
*ctx
)
5125 #if defined(CONFIG_USER_ONLY)
5131 t0
= tcg_temp_new();
5132 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
5133 tcg_gen_andi_tl(t0
, t0
, 0xF);
5134 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5136 #endif /* defined(CONFIG_USER_ONLY) */
5140 static void gen_mtsr_64b(DisasContext
*ctx
)
5142 #if defined(CONFIG_USER_ONLY)
5148 t0
= tcg_const_tl(SR(ctx
->opcode
));
5149 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
5151 #endif /* defined(CONFIG_USER_ONLY) */
5155 static void gen_mtsrin_64b(DisasContext
*ctx
)
5157 #if defined(CONFIG_USER_ONLY)
5163 t0
= tcg_temp_new();
5164 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
5165 tcg_gen_andi_tl(t0
, t0
, 0xF);
5166 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
5168 #endif /* defined(CONFIG_USER_ONLY) */
5172 static void gen_slbmte(DisasContext
*ctx
)
5174 #if defined(CONFIG_USER_ONLY)
5179 gen_helper_store_slb(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)],
5180 cpu_gpr
[rS(ctx
->opcode
)]);
5181 #endif /* defined(CONFIG_USER_ONLY) */
5184 static void gen_slbmfee(DisasContext
*ctx
)
5186 #if defined(CONFIG_USER_ONLY)
5191 gen_helper_load_slb_esid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
5192 cpu_gpr
[rB(ctx
->opcode
)]);
5193 #endif /* defined(CONFIG_USER_ONLY) */
5196 static void gen_slbmfev(DisasContext
*ctx
)
5198 #if defined(CONFIG_USER_ONLY)
5203 gen_helper_load_slb_vsid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
5204 cpu_gpr
[rB(ctx
->opcode
)]);
5205 #endif /* defined(CONFIG_USER_ONLY) */
5208 static void gen_slbfee_(DisasContext
*ctx
)
5210 #if defined(CONFIG_USER_ONLY)
5211 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5215 if (unlikely(ctx
->pr
)) {
5216 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5219 gen_helper_find_slb_vsid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
5220 cpu_gpr
[rB(ctx
->opcode
)]);
5221 l1
= gen_new_label();
5222 l2
= gen_new_label();
5223 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
5224 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rS(ctx
->opcode
)], -1, l1
);
5225 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
5228 tcg_gen_movi_tl(cpu_gpr
[rS(ctx
->opcode
)], 0);
5232 #endif /* defined(TARGET_PPC64) */
5234 /*** Lookaside buffer management ***/
5235 /* Optional & supervisor only: */
5238 static void gen_tlbia(DisasContext
*ctx
)
5240 #if defined(CONFIG_USER_ONLY)
5245 gen_helper_tlbia(cpu_env
);
5246 #endif /* defined(CONFIG_USER_ONLY) */
5250 static void gen_tlbiel(DisasContext
*ctx
)
5252 #if defined(CONFIG_USER_ONLY)
5257 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5258 #endif /* defined(CONFIG_USER_ONLY) */
5262 static void gen_tlbie(DisasContext
*ctx
)
5264 #if defined(CONFIG_USER_ONLY)
5269 if (NARROW_MODE(ctx
)) {
5270 TCGv t0
= tcg_temp_new();
5271 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
5272 gen_helper_tlbie(cpu_env
, t0
);
5275 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5277 #endif /* defined(CONFIG_USER_ONLY) */
5281 static void gen_tlbsync(DisasContext
*ctx
)
5283 #if defined(CONFIG_USER_ONLY)
5288 /* tlbsync is a nop for server, ptesync handles delayed tlb flush,
5289 * embedded however needs to deal with tlbsync. We don't try to be
5290 * fancy and swallow the overhead of checking for both.
5292 gen_check_tlb_flush(ctx
);
5293 #endif /* defined(CONFIG_USER_ONLY) */
5296 #if defined(TARGET_PPC64)
5298 static void gen_slbia(DisasContext
*ctx
)
5300 #if defined(CONFIG_USER_ONLY)
5305 gen_helper_slbia(cpu_env
);
5306 #endif /* defined(CONFIG_USER_ONLY) */
5310 static void gen_slbie(DisasContext
*ctx
)
5312 #if defined(CONFIG_USER_ONLY)
5317 gen_helper_slbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5318 #endif /* defined(CONFIG_USER_ONLY) */
5320 #endif /* defined(TARGET_PPC64) */
5322 /*** External control ***/
5326 static void gen_eciwx(DisasContext
*ctx
)
5329 /* Should check EAR[E] ! */
5330 gen_set_access_type(ctx
, ACCESS_EXT
);
5331 t0
= tcg_temp_new();
5332 gen_addr_reg_index(ctx
, t0
);
5333 gen_check_align(ctx
, t0
, 0x03);
5334 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
5339 static void gen_ecowx(DisasContext
*ctx
)
5342 /* Should check EAR[E] ! */
5343 gen_set_access_type(ctx
, ACCESS_EXT
);
5344 t0
= tcg_temp_new();
5345 gen_addr_reg_index(ctx
, t0
);
5346 gen_check_align(ctx
, t0
, 0x03);
5347 gen_qemu_st32(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
5351 /* PowerPC 601 specific instructions */
5354 static void gen_abs(DisasContext
*ctx
)
5356 TCGLabel
*l1
= gen_new_label();
5357 TCGLabel
*l2
= gen_new_label();
5358 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
5359 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5362 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5364 if (unlikely(Rc(ctx
->opcode
) != 0))
5365 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5369 static void gen_abso(DisasContext
*ctx
)
5371 TCGLabel
*l1
= gen_new_label();
5372 TCGLabel
*l2
= gen_new_label();
5373 TCGLabel
*l3
= gen_new_label();
5374 /* Start with XER OV disabled, the most likely case */
5375 tcg_gen_movi_tl(cpu_ov
, 0);
5376 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l2
);
5377 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rA(ctx
->opcode
)], 0x80000000, l1
);
5378 tcg_gen_movi_tl(cpu_ov
, 1);
5379 tcg_gen_movi_tl(cpu_so
, 1);
5382 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5385 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5387 if (unlikely(Rc(ctx
->opcode
) != 0))
5388 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5392 static void gen_clcs(DisasContext
*ctx
)
5394 TCGv_i32 t0
= tcg_const_i32(rA(ctx
->opcode
));
5395 gen_helper_clcs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5396 tcg_temp_free_i32(t0
);
5397 /* Rc=1 sets CR0 to an undefined state */
5401 static void gen_div(DisasContext
*ctx
)
5403 gen_helper_div(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5404 cpu_gpr
[rB(ctx
->opcode
)]);
5405 if (unlikely(Rc(ctx
->opcode
) != 0))
5406 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5410 static void gen_divo(DisasContext
*ctx
)
5412 gen_helper_divo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5413 cpu_gpr
[rB(ctx
->opcode
)]);
5414 if (unlikely(Rc(ctx
->opcode
) != 0))
5415 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5419 static void gen_divs(DisasContext
*ctx
)
5421 gen_helper_divs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5422 cpu_gpr
[rB(ctx
->opcode
)]);
5423 if (unlikely(Rc(ctx
->opcode
) != 0))
5424 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5427 /* divso - divso. */
5428 static void gen_divso(DisasContext
*ctx
)
5430 gen_helper_divso(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5431 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
5432 if (unlikely(Rc(ctx
->opcode
) != 0))
5433 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5437 static void gen_doz(DisasContext
*ctx
)
5439 TCGLabel
*l1
= gen_new_label();
5440 TCGLabel
*l2
= gen_new_label();
5441 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
5442 tcg_gen_sub_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5445 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
5447 if (unlikely(Rc(ctx
->opcode
) != 0))
5448 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5452 static void gen_dozo(DisasContext
*ctx
)
5454 TCGLabel
*l1
= gen_new_label();
5455 TCGLabel
*l2
= gen_new_label();
5456 TCGv t0
= tcg_temp_new();
5457 TCGv t1
= tcg_temp_new();
5458 TCGv t2
= tcg_temp_new();
5459 /* Start with XER OV disabled, the most likely case */
5460 tcg_gen_movi_tl(cpu_ov
, 0);
5461 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
5462 tcg_gen_sub_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5463 tcg_gen_xor_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5464 tcg_gen_xor_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], t0
);
5465 tcg_gen_andc_tl(t1
, t1
, t2
);
5466 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
5467 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
5468 tcg_gen_movi_tl(cpu_ov
, 1);
5469 tcg_gen_movi_tl(cpu_so
, 1);
5472 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
5477 if (unlikely(Rc(ctx
->opcode
) != 0))
5478 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5482 static void gen_dozi(DisasContext
*ctx
)
5484 target_long simm
= SIMM(ctx
->opcode
);
5485 TCGLabel
*l1
= gen_new_label();
5486 TCGLabel
*l2
= gen_new_label();
5487 tcg_gen_brcondi_tl(TCG_COND_LT
, cpu_gpr
[rA(ctx
->opcode
)], simm
, l1
);
5488 tcg_gen_subfi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
, cpu_gpr
[rA(ctx
->opcode
)]);
5491 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
5493 if (unlikely(Rc(ctx
->opcode
) != 0))
5494 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5497 /* lscbx - lscbx. */
5498 static void gen_lscbx(DisasContext
*ctx
)
5500 TCGv t0
= tcg_temp_new();
5501 TCGv_i32 t1
= tcg_const_i32(rD(ctx
->opcode
));
5502 TCGv_i32 t2
= tcg_const_i32(rA(ctx
->opcode
));
5503 TCGv_i32 t3
= tcg_const_i32(rB(ctx
->opcode
));
5505 gen_addr_reg_index(ctx
, t0
);
5506 /* NIP cannot be restored if the memory exception comes from an helper */
5507 gen_update_nip(ctx
, ctx
->nip
- 4);
5508 gen_helper_lscbx(t0
, cpu_env
, t0
, t1
, t2
, t3
);
5509 tcg_temp_free_i32(t1
);
5510 tcg_temp_free_i32(t2
);
5511 tcg_temp_free_i32(t3
);
5512 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~0x7F);
5513 tcg_gen_or_tl(cpu_xer
, cpu_xer
, t0
);
5514 if (unlikely(Rc(ctx
->opcode
) != 0))
5515 gen_set_Rc0(ctx
, t0
);
5519 /* maskg - maskg. */
5520 static void gen_maskg(DisasContext
*ctx
)
5522 TCGLabel
*l1
= gen_new_label();
5523 TCGv t0
= tcg_temp_new();
5524 TCGv t1
= tcg_temp_new();
5525 TCGv t2
= tcg_temp_new();
5526 TCGv t3
= tcg_temp_new();
5527 tcg_gen_movi_tl(t3
, 0xFFFFFFFF);
5528 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5529 tcg_gen_andi_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 0x1F);
5530 tcg_gen_addi_tl(t2
, t0
, 1);
5531 tcg_gen_shr_tl(t2
, t3
, t2
);
5532 tcg_gen_shr_tl(t3
, t3
, t1
);
5533 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], t2
, t3
);
5534 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
5535 tcg_gen_neg_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5541 if (unlikely(Rc(ctx
->opcode
) != 0))
5542 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5545 /* maskir - maskir. */
5546 static void gen_maskir(DisasContext
*ctx
)
5548 TCGv t0
= tcg_temp_new();
5549 TCGv t1
= tcg_temp_new();
5550 tcg_gen_and_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
5551 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
5552 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5555 if (unlikely(Rc(ctx
->opcode
) != 0))
5556 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5560 static void gen_mul(DisasContext
*ctx
)
5562 TCGv_i64 t0
= tcg_temp_new_i64();
5563 TCGv_i64 t1
= tcg_temp_new_i64();
5564 TCGv t2
= tcg_temp_new();
5565 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
5566 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
5567 tcg_gen_mul_i64(t0
, t0
, t1
);
5568 tcg_gen_trunc_i64_tl(t2
, t0
);
5569 gen_store_spr(SPR_MQ
, t2
);
5570 tcg_gen_shri_i64(t1
, t0
, 32);
5571 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
5572 tcg_temp_free_i64(t0
);
5573 tcg_temp_free_i64(t1
);
5575 if (unlikely(Rc(ctx
->opcode
) != 0))
5576 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5580 static void gen_mulo(DisasContext
*ctx
)
5582 TCGLabel
*l1
= gen_new_label();
5583 TCGv_i64 t0
= tcg_temp_new_i64();
5584 TCGv_i64 t1
= tcg_temp_new_i64();
5585 TCGv t2
= tcg_temp_new();
5586 /* Start with XER OV disabled, the most likely case */
5587 tcg_gen_movi_tl(cpu_ov
, 0);
5588 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
5589 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
5590 tcg_gen_mul_i64(t0
, t0
, t1
);
5591 tcg_gen_trunc_i64_tl(t2
, t0
);
5592 gen_store_spr(SPR_MQ
, t2
);
5593 tcg_gen_shri_i64(t1
, t0
, 32);
5594 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
5595 tcg_gen_ext32s_i64(t1
, t0
);
5596 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
5597 tcg_gen_movi_tl(cpu_ov
, 1);
5598 tcg_gen_movi_tl(cpu_so
, 1);
5600 tcg_temp_free_i64(t0
);
5601 tcg_temp_free_i64(t1
);
5603 if (unlikely(Rc(ctx
->opcode
) != 0))
5604 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5608 static void gen_nabs(DisasContext
*ctx
)
5610 TCGLabel
*l1
= gen_new_label();
5611 TCGLabel
*l2
= gen_new_label();
5612 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
5613 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5616 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5618 if (unlikely(Rc(ctx
->opcode
) != 0))
5619 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5622 /* nabso - nabso. */
5623 static void gen_nabso(DisasContext
*ctx
)
5625 TCGLabel
*l1
= gen_new_label();
5626 TCGLabel
*l2
= gen_new_label();
5627 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
5628 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5631 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5633 /* nabs never overflows */
5634 tcg_gen_movi_tl(cpu_ov
, 0);
5635 if (unlikely(Rc(ctx
->opcode
) != 0))
5636 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5640 static void gen_rlmi(DisasContext
*ctx
)
5642 uint32_t mb
= MB(ctx
->opcode
);
5643 uint32_t me
= ME(ctx
->opcode
);
5644 TCGv t0
= tcg_temp_new();
5645 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5646 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5647 tcg_gen_andi_tl(t0
, t0
, MASK(mb
, me
));
5648 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~MASK(mb
, me
));
5649 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], t0
);
5651 if (unlikely(Rc(ctx
->opcode
) != 0))
5652 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5656 static void gen_rrib(DisasContext
*ctx
)
5658 TCGv t0
= tcg_temp_new();
5659 TCGv t1
= tcg_temp_new();
5660 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5661 tcg_gen_movi_tl(t1
, 0x80000000);
5662 tcg_gen_shr_tl(t1
, t1
, t0
);
5663 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5664 tcg_gen_and_tl(t0
, t0
, t1
);
5665 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], t1
);
5666 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5669 if (unlikely(Rc(ctx
->opcode
) != 0))
5670 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5674 static void gen_sle(DisasContext
*ctx
)
5676 TCGv t0
= tcg_temp_new();
5677 TCGv t1
= tcg_temp_new();
5678 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5679 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5680 tcg_gen_subfi_tl(t1
, 32, t1
);
5681 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5682 tcg_gen_or_tl(t1
, t0
, t1
);
5683 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5684 gen_store_spr(SPR_MQ
, t1
);
5687 if (unlikely(Rc(ctx
->opcode
) != 0))
5688 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5692 static void gen_sleq(DisasContext
*ctx
)
5694 TCGv t0
= tcg_temp_new();
5695 TCGv t1
= tcg_temp_new();
5696 TCGv t2
= tcg_temp_new();
5697 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5698 tcg_gen_movi_tl(t2
, 0xFFFFFFFF);
5699 tcg_gen_shl_tl(t2
, t2
, t0
);
5700 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5701 gen_load_spr(t1
, SPR_MQ
);
5702 gen_store_spr(SPR_MQ
, t0
);
5703 tcg_gen_and_tl(t0
, t0
, t2
);
5704 tcg_gen_andc_tl(t1
, t1
, t2
);
5705 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5709 if (unlikely(Rc(ctx
->opcode
) != 0))
5710 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5714 static void gen_sliq(DisasContext
*ctx
)
5716 int sh
= SH(ctx
->opcode
);
5717 TCGv t0
= tcg_temp_new();
5718 TCGv t1
= tcg_temp_new();
5719 tcg_gen_shli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5720 tcg_gen_shri_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5721 tcg_gen_or_tl(t1
, t0
, t1
);
5722 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5723 gen_store_spr(SPR_MQ
, t1
);
5726 if (unlikely(Rc(ctx
->opcode
) != 0))
5727 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5730 /* slliq - slliq. */
5731 static void gen_slliq(DisasContext
*ctx
)
5733 int sh
= SH(ctx
->opcode
);
5734 TCGv t0
= tcg_temp_new();
5735 TCGv t1
= tcg_temp_new();
5736 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5737 gen_load_spr(t1
, SPR_MQ
);
5738 gen_store_spr(SPR_MQ
, t0
);
5739 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
<< sh
));
5740 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
<< sh
));
5741 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5744 if (unlikely(Rc(ctx
->opcode
) != 0))
5745 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5749 static void gen_sllq(DisasContext
*ctx
)
5751 TCGLabel
*l1
= gen_new_label();
5752 TCGLabel
*l2
= gen_new_label();
5753 TCGv t0
= tcg_temp_local_new();
5754 TCGv t1
= tcg_temp_local_new();
5755 TCGv t2
= tcg_temp_local_new();
5756 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5757 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5758 tcg_gen_shl_tl(t1
, t1
, t2
);
5759 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5760 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5761 gen_load_spr(t0
, SPR_MQ
);
5762 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5765 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5766 gen_load_spr(t2
, SPR_MQ
);
5767 tcg_gen_andc_tl(t1
, t2
, t1
);
5768 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5773 if (unlikely(Rc(ctx
->opcode
) != 0))
5774 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5778 static void gen_slq(DisasContext
*ctx
)
5780 TCGLabel
*l1
= gen_new_label();
5781 TCGv t0
= tcg_temp_new();
5782 TCGv t1
= tcg_temp_new();
5783 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5784 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5785 tcg_gen_subfi_tl(t1
, 32, t1
);
5786 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5787 tcg_gen_or_tl(t1
, t0
, t1
);
5788 gen_store_spr(SPR_MQ
, t1
);
5789 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5790 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5791 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
5792 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5796 if (unlikely(Rc(ctx
->opcode
) != 0))
5797 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5800 /* sraiq - sraiq. */
5801 static void gen_sraiq(DisasContext
*ctx
)
5803 int sh
= SH(ctx
->opcode
);
5804 TCGLabel
*l1
= gen_new_label();
5805 TCGv t0
= tcg_temp_new();
5806 TCGv t1
= tcg_temp_new();
5807 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5808 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5809 tcg_gen_or_tl(t0
, t0
, t1
);
5810 gen_store_spr(SPR_MQ
, t0
);
5811 tcg_gen_movi_tl(cpu_ca
, 0);
5812 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
5813 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
5814 tcg_gen_movi_tl(cpu_ca
, 1);
5816 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
5819 if (unlikely(Rc(ctx
->opcode
) != 0))
5820 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5824 static void gen_sraq(DisasContext
*ctx
)
5826 TCGLabel
*l1
= gen_new_label();
5827 TCGLabel
*l2
= gen_new_label();
5828 TCGv t0
= tcg_temp_new();
5829 TCGv t1
= tcg_temp_local_new();
5830 TCGv t2
= tcg_temp_local_new();
5831 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5832 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5833 tcg_gen_sar_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5834 tcg_gen_subfi_tl(t2
, 32, t2
);
5835 tcg_gen_shl_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5836 tcg_gen_or_tl(t0
, t0
, t2
);
5837 gen_store_spr(SPR_MQ
, t0
);
5838 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5839 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l1
);
5840 tcg_gen_mov_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
5841 tcg_gen_sari_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 31);
5844 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
);
5845 tcg_gen_movi_tl(cpu_ca
, 0);
5846 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
5847 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l2
);
5848 tcg_gen_movi_tl(cpu_ca
, 1);
5852 if (unlikely(Rc(ctx
->opcode
) != 0))
5853 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5857 static void gen_sre(DisasContext
*ctx
)
5859 TCGv t0
= tcg_temp_new();
5860 TCGv t1
= tcg_temp_new();
5861 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5862 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5863 tcg_gen_subfi_tl(t1
, 32, t1
);
5864 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5865 tcg_gen_or_tl(t1
, t0
, t1
);
5866 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5867 gen_store_spr(SPR_MQ
, t1
);
5870 if (unlikely(Rc(ctx
->opcode
) != 0))
5871 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5875 static void gen_srea(DisasContext
*ctx
)
5877 TCGv t0
= tcg_temp_new();
5878 TCGv t1
= tcg_temp_new();
5879 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5880 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5881 gen_store_spr(SPR_MQ
, t0
);
5882 tcg_gen_sar_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t1
);
5885 if (unlikely(Rc(ctx
->opcode
) != 0))
5886 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5890 static void gen_sreq(DisasContext
*ctx
)
5892 TCGv t0
= tcg_temp_new();
5893 TCGv t1
= tcg_temp_new();
5894 TCGv t2
= tcg_temp_new();
5895 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5896 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5897 tcg_gen_shr_tl(t1
, t1
, t0
);
5898 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5899 gen_load_spr(t2
, SPR_MQ
);
5900 gen_store_spr(SPR_MQ
, t0
);
5901 tcg_gen_and_tl(t0
, t0
, t1
);
5902 tcg_gen_andc_tl(t2
, t2
, t1
);
5903 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5907 if (unlikely(Rc(ctx
->opcode
) != 0))
5908 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5912 static void gen_sriq(DisasContext
*ctx
)
5914 int sh
= SH(ctx
->opcode
);
5915 TCGv t0
= tcg_temp_new();
5916 TCGv t1
= tcg_temp_new();
5917 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5918 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5919 tcg_gen_or_tl(t1
, t0
, t1
);
5920 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5921 gen_store_spr(SPR_MQ
, t1
);
5924 if (unlikely(Rc(ctx
->opcode
) != 0))
5925 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5929 static void gen_srliq(DisasContext
*ctx
)
5931 int sh
= SH(ctx
->opcode
);
5932 TCGv t0
= tcg_temp_new();
5933 TCGv t1
= tcg_temp_new();
5934 tcg_gen_rotri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5935 gen_load_spr(t1
, SPR_MQ
);
5936 gen_store_spr(SPR_MQ
, t0
);
5937 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
>> sh
));
5938 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
>> sh
));
5939 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5942 if (unlikely(Rc(ctx
->opcode
) != 0))
5943 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5947 static void gen_srlq(DisasContext
*ctx
)
5949 TCGLabel
*l1
= gen_new_label();
5950 TCGLabel
*l2
= gen_new_label();
5951 TCGv t0
= tcg_temp_local_new();
5952 TCGv t1
= tcg_temp_local_new();
5953 TCGv t2
= tcg_temp_local_new();
5954 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5955 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5956 tcg_gen_shr_tl(t2
, t1
, t2
);
5957 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5958 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5959 gen_load_spr(t0
, SPR_MQ
);
5960 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5963 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5964 tcg_gen_and_tl(t0
, t0
, t2
);
5965 gen_load_spr(t1
, SPR_MQ
);
5966 tcg_gen_andc_tl(t1
, t1
, t2
);
5967 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5972 if (unlikely(Rc(ctx
->opcode
) != 0))
5973 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5977 static void gen_srq(DisasContext
*ctx
)
5979 TCGLabel
*l1
= gen_new_label();
5980 TCGv t0
= tcg_temp_new();
5981 TCGv t1
= tcg_temp_new();
5982 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5983 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5984 tcg_gen_subfi_tl(t1
, 32, t1
);
5985 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5986 tcg_gen_or_tl(t1
, t0
, t1
);
5987 gen_store_spr(SPR_MQ
, t1
);
5988 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5989 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5990 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5991 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5995 if (unlikely(Rc(ctx
->opcode
) != 0))
5996 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5999 /* PowerPC 602 specific instructions */
6002 static void gen_dsa(DisasContext
*ctx
)
6005 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6009 static void gen_esa(DisasContext
*ctx
)
6012 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6016 static void gen_mfrom(DisasContext
*ctx
)
6018 #if defined(CONFIG_USER_ONLY)
6022 gen_helper_602_mfrom(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6023 #endif /* defined(CONFIG_USER_ONLY) */
6026 /* 602 - 603 - G2 TLB management */
6029 static void gen_tlbld_6xx(DisasContext
*ctx
)
6031 #if defined(CONFIG_USER_ONLY)
6035 gen_helper_6xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6036 #endif /* defined(CONFIG_USER_ONLY) */
6040 static void gen_tlbli_6xx(DisasContext
*ctx
)
6042 #if defined(CONFIG_USER_ONLY)
6046 gen_helper_6xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6047 #endif /* defined(CONFIG_USER_ONLY) */
6050 /* 74xx TLB management */
6053 static void gen_tlbld_74xx(DisasContext
*ctx
)
6055 #if defined(CONFIG_USER_ONLY)
6059 gen_helper_74xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6060 #endif /* defined(CONFIG_USER_ONLY) */
6064 static void gen_tlbli_74xx(DisasContext
*ctx
)
6066 #if defined(CONFIG_USER_ONLY)
6070 gen_helper_74xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6071 #endif /* defined(CONFIG_USER_ONLY) */
6074 /* POWER instructions not in PowerPC 601 */
6077 static void gen_clf(DisasContext
*ctx
)
6079 /* Cache line flush: implemented as no-op */
6083 static void gen_cli(DisasContext
*ctx
)
6085 #if defined(CONFIG_USER_ONLY)
6088 /* Cache line invalidate: privileged and treated as no-op */
6090 #endif /* defined(CONFIG_USER_ONLY) */
6094 static void gen_dclst(DisasContext
*ctx
)
6096 /* Data cache line store: treated as no-op */
6099 static void gen_mfsri(DisasContext
*ctx
)
6101 #if defined(CONFIG_USER_ONLY)
6104 int ra
= rA(ctx
->opcode
);
6105 int rd
= rD(ctx
->opcode
);
6109 t0
= tcg_temp_new();
6110 gen_addr_reg_index(ctx
, t0
);
6111 tcg_gen_shri_tl(t0
, t0
, 28);
6112 tcg_gen_andi_tl(t0
, t0
, 0xF);
6113 gen_helper_load_sr(cpu_gpr
[rd
], cpu_env
, t0
);
6115 if (ra
!= 0 && ra
!= rd
)
6116 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rd
]);
6117 #endif /* defined(CONFIG_USER_ONLY) */
6120 static void gen_rac(DisasContext
*ctx
)
6122 #if defined(CONFIG_USER_ONLY)
6128 t0
= tcg_temp_new();
6129 gen_addr_reg_index(ctx
, t0
);
6130 gen_helper_rac(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
6132 #endif /* defined(CONFIG_USER_ONLY) */
6135 static void gen_rfsvc(DisasContext
*ctx
)
6137 #if defined(CONFIG_USER_ONLY)
6142 gen_helper_rfsvc(cpu_env
);
6143 gen_sync_exception(ctx
);
6144 #endif /* defined(CONFIG_USER_ONLY) */
6147 /* svc is not implemented for now */
6149 /* POWER2 specific instructions */
6150 /* Quad manipulation (load/store two floats at a time) */
6153 static void gen_lfq(DisasContext
*ctx
)
6155 int rd
= rD(ctx
->opcode
);
6157 gen_set_access_type(ctx
, ACCESS_FLOAT
);
6158 t0
= tcg_temp_new();
6159 gen_addr_imm_index(ctx
, t0
, 0);
6160 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
6161 gen_addr_add(ctx
, t0
, t0
, 8);
6162 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
6167 static void gen_lfqu(DisasContext
*ctx
)
6169 int ra
= rA(ctx
->opcode
);
6170 int rd
= rD(ctx
->opcode
);
6172 gen_set_access_type(ctx
, ACCESS_FLOAT
);
6173 t0
= tcg_temp_new();
6174 t1
= tcg_temp_new();
6175 gen_addr_imm_index(ctx
, t0
, 0);
6176 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
6177 gen_addr_add(ctx
, t1
, t0
, 8);
6178 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
6180 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
6186 static void gen_lfqux(DisasContext
*ctx
)
6188 int ra
= rA(ctx
->opcode
);
6189 int rd
= rD(ctx
->opcode
);
6190 gen_set_access_type(ctx
, ACCESS_FLOAT
);
6192 t0
= tcg_temp_new();
6193 gen_addr_reg_index(ctx
, t0
);
6194 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
6195 t1
= tcg_temp_new();
6196 gen_addr_add(ctx
, t1
, t0
, 8);
6197 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
6200 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
6205 static void gen_lfqx(DisasContext
*ctx
)
6207 int rd
= rD(ctx
->opcode
);
6209 gen_set_access_type(ctx
, ACCESS_FLOAT
);
6210 t0
= tcg_temp_new();
6211 gen_addr_reg_index(ctx
, t0
);
6212 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
6213 gen_addr_add(ctx
, t0
, t0
, 8);
6214 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
6219 static void gen_stfq(DisasContext
*ctx
)
6221 int rd
= rD(ctx
->opcode
);
6223 gen_set_access_type(ctx
, ACCESS_FLOAT
);
6224 t0
= tcg_temp_new();
6225 gen_addr_imm_index(ctx
, t0
, 0);
6226 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
6227 gen_addr_add(ctx
, t0
, t0
, 8);
6228 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
6233 static void gen_stfqu(DisasContext
*ctx
)
6235 int ra
= rA(ctx
->opcode
);
6236 int rd
= rD(ctx
->opcode
);
6238 gen_set_access_type(ctx
, ACCESS_FLOAT
);
6239 t0
= tcg_temp_new();
6240 gen_addr_imm_index(ctx
, t0
, 0);
6241 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
6242 t1
= tcg_temp_new();
6243 gen_addr_add(ctx
, t1
, t0
, 8);
6244 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
6247 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
6252 static void gen_stfqux(DisasContext
*ctx
)
6254 int ra
= rA(ctx
->opcode
);
6255 int rd
= rD(ctx
->opcode
);
6257 gen_set_access_type(ctx
, ACCESS_FLOAT
);
6258 t0
= tcg_temp_new();
6259 gen_addr_reg_index(ctx
, t0
);
6260 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
6261 t1
= tcg_temp_new();
6262 gen_addr_add(ctx
, t1
, t0
, 8);
6263 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
6266 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
6271 static void gen_stfqx(DisasContext
*ctx
)
6273 int rd
= rD(ctx
->opcode
);
6275 gen_set_access_type(ctx
, ACCESS_FLOAT
);
6276 t0
= tcg_temp_new();
6277 gen_addr_reg_index(ctx
, t0
);
6278 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
6279 gen_addr_add(ctx
, t0
, t0
, 8);
6280 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
6284 /* BookE specific instructions */
6286 /* XXX: not implemented on 440 ? */
6287 static void gen_mfapidi(DisasContext
*ctx
)
6290 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6293 /* XXX: not implemented on 440 ? */
6294 static void gen_tlbiva(DisasContext
*ctx
)
6296 #if defined(CONFIG_USER_ONLY)
6302 t0
= tcg_temp_new();
6303 gen_addr_reg_index(ctx
, t0
);
6304 gen_helper_tlbiva(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6306 #endif /* defined(CONFIG_USER_ONLY) */
6309 /* All 405 MAC instructions are translated here */
6310 static inline void gen_405_mulladd_insn(DisasContext
*ctx
, int opc2
, int opc3
,
6311 int ra
, int rb
, int rt
, int Rc
)
6315 t0
= tcg_temp_local_new();
6316 t1
= tcg_temp_local_new();
6318 switch (opc3
& 0x0D) {
6320 /* macchw - macchw. - macchwo - macchwo. */
6321 /* macchws - macchws. - macchwso - macchwso. */
6322 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
6323 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
6324 /* mulchw - mulchw. */
6325 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
6326 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
6327 tcg_gen_ext16s_tl(t1
, t1
);
6330 /* macchwu - macchwu. - macchwuo - macchwuo. */
6331 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
6332 /* mulchwu - mulchwu. */
6333 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
6334 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
6335 tcg_gen_ext16u_tl(t1
, t1
);
6338 /* machhw - machhw. - machhwo - machhwo. */
6339 /* machhws - machhws. - machhwso - machhwso. */
6340 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
6341 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
6342 /* mulhhw - mulhhw. */
6343 tcg_gen_sari_tl(t0
, cpu_gpr
[ra
], 16);
6344 tcg_gen_ext16s_tl(t0
, t0
);
6345 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
6346 tcg_gen_ext16s_tl(t1
, t1
);
6349 /* machhwu - machhwu. - machhwuo - machhwuo. */
6350 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
6351 /* mulhhwu - mulhhwu. */
6352 tcg_gen_shri_tl(t0
, cpu_gpr
[ra
], 16);
6353 tcg_gen_ext16u_tl(t0
, t0
);
6354 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
6355 tcg_gen_ext16u_tl(t1
, t1
);
6358 /* maclhw - maclhw. - maclhwo - maclhwo. */
6359 /* maclhws - maclhws. - maclhwso - maclhwso. */
6360 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
6361 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
6362 /* mullhw - mullhw. */
6363 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
6364 tcg_gen_ext16s_tl(t1
, cpu_gpr
[rb
]);
6367 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
6368 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
6369 /* mullhwu - mullhwu. */
6370 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
6371 tcg_gen_ext16u_tl(t1
, cpu_gpr
[rb
]);
6375 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
6376 tcg_gen_mul_tl(t1
, t0
, t1
);
6378 /* nmultiply-and-accumulate (0x0E) */
6379 tcg_gen_sub_tl(t0
, cpu_gpr
[rt
], t1
);
6381 /* multiply-and-accumulate (0x0C) */
6382 tcg_gen_add_tl(t0
, cpu_gpr
[rt
], t1
);
6386 /* Check overflow and/or saturate */
6387 TCGLabel
*l1
= gen_new_label();
6390 /* Start with XER OV disabled, the most likely case */
6391 tcg_gen_movi_tl(cpu_ov
, 0);
6395 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t1
);
6396 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
6397 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t0
);
6398 tcg_gen_brcondi_tl(TCG_COND_LT
, t1
, 0, l1
);
6401 tcg_gen_sari_tl(t0
, cpu_gpr
[rt
], 31);
6402 tcg_gen_xori_tl(t0
, t0
, 0x7fffffff);
6406 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
6409 tcg_gen_movi_tl(t0
, UINT32_MAX
);
6413 /* Check overflow */
6414 tcg_gen_movi_tl(cpu_ov
, 1);
6415 tcg_gen_movi_tl(cpu_so
, 1);
6418 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
6421 tcg_gen_mul_tl(cpu_gpr
[rt
], t0
, t1
);
6425 if (unlikely(Rc
) != 0) {
6427 gen_set_Rc0(ctx
, cpu_gpr
[rt
]);
6431 #define GEN_MAC_HANDLER(name, opc2, opc3) \
6432 static void glue(gen_, name)(DisasContext *ctx) \
6434 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
6435 rD(ctx->opcode), Rc(ctx->opcode)); \
6438 /* macchw - macchw. */
6439 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
6440 /* macchwo - macchwo. */
6441 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
6442 /* macchws - macchws. */
6443 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
6444 /* macchwso - macchwso. */
6445 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
6446 /* macchwsu - macchwsu. */
6447 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
6448 /* macchwsuo - macchwsuo. */
6449 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
6450 /* macchwu - macchwu. */
6451 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
6452 /* macchwuo - macchwuo. */
6453 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
6454 /* machhw - machhw. */
6455 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
6456 /* machhwo - machhwo. */
6457 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
6458 /* machhws - machhws. */
6459 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
6460 /* machhwso - machhwso. */
6461 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
6462 /* machhwsu - machhwsu. */
6463 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
6464 /* machhwsuo - machhwsuo. */
6465 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
6466 /* machhwu - machhwu. */
6467 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
6468 /* machhwuo - machhwuo. */
6469 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
6470 /* maclhw - maclhw. */
6471 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
6472 /* maclhwo - maclhwo. */
6473 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
6474 /* maclhws - maclhws. */
6475 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
6476 /* maclhwso - maclhwso. */
6477 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
6478 /* maclhwu - maclhwu. */
6479 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
6480 /* maclhwuo - maclhwuo. */
6481 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
6482 /* maclhwsu - maclhwsu. */
6483 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
6484 /* maclhwsuo - maclhwsuo. */
6485 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
6486 /* nmacchw - nmacchw. */
6487 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
6488 /* nmacchwo - nmacchwo. */
6489 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
6490 /* nmacchws - nmacchws. */
6491 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
6492 /* nmacchwso - nmacchwso. */
6493 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
6494 /* nmachhw - nmachhw. */
6495 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
6496 /* nmachhwo - nmachhwo. */
6497 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
6498 /* nmachhws - nmachhws. */
6499 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
6500 /* nmachhwso - nmachhwso. */
6501 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
6502 /* nmaclhw - nmaclhw. */
6503 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
6504 /* nmaclhwo - nmaclhwo. */
6505 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
6506 /* nmaclhws - nmaclhws. */
6507 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
6508 /* nmaclhwso - nmaclhwso. */
6509 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
6511 /* mulchw - mulchw. */
6512 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
6513 /* mulchwu - mulchwu. */
6514 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
6515 /* mulhhw - mulhhw. */
6516 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
6517 /* mulhhwu - mulhhwu. */
6518 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
6519 /* mullhw - mullhw. */
6520 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
6521 /* mullhwu - mullhwu. */
6522 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
6525 static void gen_mfdcr(DisasContext
*ctx
)
6527 #if defined(CONFIG_USER_ONLY)
6533 /* NIP cannot be restored if the memory exception comes from an helper */
6534 gen_update_nip(ctx
, ctx
->nip
- 4);
6535 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
6536 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, dcrn
);
6537 tcg_temp_free(dcrn
);
6538 #endif /* defined(CONFIG_USER_ONLY) */
6542 static void gen_mtdcr(DisasContext
*ctx
)
6544 #if defined(CONFIG_USER_ONLY)
6550 /* NIP cannot be restored if the memory exception comes from an helper */
6551 gen_update_nip(ctx
, ctx
->nip
- 4);
6552 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
6553 gen_helper_store_dcr(cpu_env
, dcrn
, cpu_gpr
[rS(ctx
->opcode
)]);
6554 tcg_temp_free(dcrn
);
6555 #endif /* defined(CONFIG_USER_ONLY) */
6559 /* XXX: not implemented on 440 ? */
6560 static void gen_mfdcrx(DisasContext
*ctx
)
6562 #if defined(CONFIG_USER_ONLY)
6566 /* NIP cannot be restored if the memory exception comes from an helper */
6567 gen_update_nip(ctx
, ctx
->nip
- 4);
6568 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6569 cpu_gpr
[rA(ctx
->opcode
)]);
6570 /* Note: Rc update flag set leads to undefined state of Rc0 */
6571 #endif /* defined(CONFIG_USER_ONLY) */
6575 /* XXX: not implemented on 440 ? */
6576 static void gen_mtdcrx(DisasContext
*ctx
)
6578 #if defined(CONFIG_USER_ONLY)
6582 /* NIP cannot be restored if the memory exception comes from an helper */
6583 gen_update_nip(ctx
, ctx
->nip
- 4);
6584 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6585 cpu_gpr
[rS(ctx
->opcode
)]);
6586 /* Note: Rc update flag set leads to undefined state of Rc0 */
6587 #endif /* defined(CONFIG_USER_ONLY) */
6590 /* mfdcrux (PPC 460) : user-mode access to DCR */
6591 static void gen_mfdcrux(DisasContext
*ctx
)
6593 /* NIP cannot be restored if the memory exception comes from an helper */
6594 gen_update_nip(ctx
, ctx
->nip
- 4);
6595 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6596 cpu_gpr
[rA(ctx
->opcode
)]);
6597 /* Note: Rc update flag set leads to undefined state of Rc0 */
6600 /* mtdcrux (PPC 460) : user-mode access to DCR */
6601 static void gen_mtdcrux(DisasContext
*ctx
)
6603 /* NIP cannot be restored if the memory exception comes from an helper */
6604 gen_update_nip(ctx
, ctx
->nip
- 4);
6605 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6606 cpu_gpr
[rS(ctx
->opcode
)]);
6607 /* Note: Rc update flag set leads to undefined state of Rc0 */
6611 static void gen_dccci(DisasContext
*ctx
)
6614 /* interpreted as no-op */
6618 static void gen_dcread(DisasContext
*ctx
)
6620 #if defined(CONFIG_USER_ONLY)
6626 gen_set_access_type(ctx
, ACCESS_CACHE
);
6627 EA
= tcg_temp_new();
6628 gen_addr_reg_index(ctx
, EA
);
6629 val
= tcg_temp_new();
6630 gen_qemu_ld32u(ctx
, val
, EA
);
6632 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], EA
);
6634 #endif /* defined(CONFIG_USER_ONLY) */
6638 static void gen_icbt_40x(DisasContext
*ctx
)
6640 /* interpreted as no-op */
6641 /* XXX: specification say this is treated as a load by the MMU
6642 * but does not generate any exception
6647 static void gen_iccci(DisasContext
*ctx
)
6650 /* interpreted as no-op */
6654 static void gen_icread(DisasContext
*ctx
)
6657 /* interpreted as no-op */
6660 /* rfci (supervisor only) */
6661 static void gen_rfci_40x(DisasContext
*ctx
)
6663 #if defined(CONFIG_USER_ONLY)
6667 /* Restore CPU state */
6668 gen_helper_40x_rfci(cpu_env
);
6669 gen_sync_exception(ctx
);
6670 #endif /* defined(CONFIG_USER_ONLY) */
6673 static void gen_rfci(DisasContext
*ctx
)
6675 #if defined(CONFIG_USER_ONLY)
6679 /* Restore CPU state */
6680 gen_helper_rfci(cpu_env
);
6681 gen_sync_exception(ctx
);
6682 #endif /* defined(CONFIG_USER_ONLY) */
6685 /* BookE specific */
6687 /* XXX: not implemented on 440 ? */
6688 static void gen_rfdi(DisasContext
*ctx
)
6690 #if defined(CONFIG_USER_ONLY)
6694 /* Restore CPU state */
6695 gen_helper_rfdi(cpu_env
);
6696 gen_sync_exception(ctx
);
6697 #endif /* defined(CONFIG_USER_ONLY) */
6700 /* XXX: not implemented on 440 ? */
6701 static void gen_rfmci(DisasContext
*ctx
)
6703 #if defined(CONFIG_USER_ONLY)
6707 /* Restore CPU state */
6708 gen_helper_rfmci(cpu_env
);
6709 gen_sync_exception(ctx
);
6710 #endif /* defined(CONFIG_USER_ONLY) */
6713 /* TLB management - PowerPC 405 implementation */
6716 static void gen_tlbre_40x(DisasContext
*ctx
)
6718 #if defined(CONFIG_USER_ONLY)
6722 switch (rB(ctx
->opcode
)) {
6724 gen_helper_4xx_tlbre_hi(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6725 cpu_gpr
[rA(ctx
->opcode
)]);
6728 gen_helper_4xx_tlbre_lo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6729 cpu_gpr
[rA(ctx
->opcode
)]);
6732 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6735 #endif /* defined(CONFIG_USER_ONLY) */
6738 /* tlbsx - tlbsx. */
6739 static void gen_tlbsx_40x(DisasContext
*ctx
)
6741 #if defined(CONFIG_USER_ONLY)
6747 t0
= tcg_temp_new();
6748 gen_addr_reg_index(ctx
, t0
);
6749 gen_helper_4xx_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
6751 if (Rc(ctx
->opcode
)) {
6752 TCGLabel
*l1
= gen_new_label();
6753 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
6754 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
6755 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
6758 #endif /* defined(CONFIG_USER_ONLY) */
6762 static void gen_tlbwe_40x(DisasContext
*ctx
)
6764 #if defined(CONFIG_USER_ONLY)
6769 switch (rB(ctx
->opcode
)) {
6771 gen_helper_4xx_tlbwe_hi(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6772 cpu_gpr
[rS(ctx
->opcode
)]);
6775 gen_helper_4xx_tlbwe_lo(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6776 cpu_gpr
[rS(ctx
->opcode
)]);
6779 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6782 #endif /* defined(CONFIG_USER_ONLY) */
6785 /* TLB management - PowerPC 440 implementation */
6788 static void gen_tlbre_440(DisasContext
*ctx
)
6790 #if defined(CONFIG_USER_ONLY)
6795 switch (rB(ctx
->opcode
)) {
6800 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
6801 gen_helper_440_tlbre(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6802 t0
, cpu_gpr
[rA(ctx
->opcode
)]);
6803 tcg_temp_free_i32(t0
);
6807 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6810 #endif /* defined(CONFIG_USER_ONLY) */
6813 /* tlbsx - tlbsx. */
6814 static void gen_tlbsx_440(DisasContext
*ctx
)
6816 #if defined(CONFIG_USER_ONLY)
6822 t0
= tcg_temp_new();
6823 gen_addr_reg_index(ctx
, t0
);
6824 gen_helper_440_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
6826 if (Rc(ctx
->opcode
)) {
6827 TCGLabel
*l1
= gen_new_label();
6828 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
6829 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
6830 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
6833 #endif /* defined(CONFIG_USER_ONLY) */
6837 static void gen_tlbwe_440(DisasContext
*ctx
)
6839 #if defined(CONFIG_USER_ONLY)
6843 switch (rB(ctx
->opcode
)) {
6848 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
6849 gen_helper_440_tlbwe(cpu_env
, t0
, cpu_gpr
[rA(ctx
->opcode
)],
6850 cpu_gpr
[rS(ctx
->opcode
)]);
6851 tcg_temp_free_i32(t0
);
6855 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6858 #endif /* defined(CONFIG_USER_ONLY) */
6861 /* TLB management - PowerPC BookE 2.06 implementation */
6864 static void gen_tlbre_booke206(DisasContext
*ctx
)
6866 #if defined(CONFIG_USER_ONLY)
6870 gen_helper_booke206_tlbre(cpu_env
);
6871 #endif /* defined(CONFIG_USER_ONLY) */
6874 /* tlbsx - tlbsx. */
6875 static void gen_tlbsx_booke206(DisasContext
*ctx
)
6877 #if defined(CONFIG_USER_ONLY)
6883 if (rA(ctx
->opcode
)) {
6884 t0
= tcg_temp_new();
6885 tcg_gen_mov_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)]);
6887 t0
= tcg_const_tl(0);
6890 tcg_gen_add_tl(t0
, t0
, cpu_gpr
[rB(ctx
->opcode
)]);
6891 gen_helper_booke206_tlbsx(cpu_env
, t0
);
6893 #endif /* defined(CONFIG_USER_ONLY) */
6897 static void gen_tlbwe_booke206(DisasContext
*ctx
)
6899 #if defined(CONFIG_USER_ONLY)
6903 gen_update_nip(ctx
, ctx
->nip
- 4);
6904 gen_helper_booke206_tlbwe(cpu_env
);
6905 #endif /* defined(CONFIG_USER_ONLY) */
6908 static void gen_tlbivax_booke206(DisasContext
*ctx
)
6910 #if defined(CONFIG_USER_ONLY)
6916 t0
= tcg_temp_new();
6917 gen_addr_reg_index(ctx
, t0
);
6918 gen_helper_booke206_tlbivax(cpu_env
, t0
);
6920 #endif /* defined(CONFIG_USER_ONLY) */
6923 static void gen_tlbilx_booke206(DisasContext
*ctx
)
6925 #if defined(CONFIG_USER_ONLY)
6931 t0
= tcg_temp_new();
6932 gen_addr_reg_index(ctx
, t0
);
6934 switch((ctx
->opcode
>> 21) & 0x3) {
6936 gen_helper_booke206_tlbilx0(cpu_env
, t0
);
6939 gen_helper_booke206_tlbilx1(cpu_env
, t0
);
6942 gen_helper_booke206_tlbilx3(cpu_env
, t0
);
6945 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6950 #endif /* defined(CONFIG_USER_ONLY) */
6955 static void gen_wrtee(DisasContext
*ctx
)
6957 #if defined(CONFIG_USER_ONLY)
6963 t0
= tcg_temp_new();
6964 tcg_gen_andi_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)], (1 << MSR_EE
));
6965 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6966 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
6968 /* Stop translation to have a chance to raise an exception
6969 * if we just set msr_ee to 1
6971 gen_stop_exception(ctx
);
6972 #endif /* defined(CONFIG_USER_ONLY) */
6976 static void gen_wrteei(DisasContext
*ctx
)
6978 #if defined(CONFIG_USER_ONLY)
6982 if (ctx
->opcode
& 0x00008000) {
6983 tcg_gen_ori_tl(cpu_msr
, cpu_msr
, (1 << MSR_EE
));
6984 /* Stop translation to have a chance to raise an exception */
6985 gen_stop_exception(ctx
);
6987 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6989 #endif /* defined(CONFIG_USER_ONLY) */
6992 /* PowerPC 440 specific instructions */
6995 static void gen_dlmzb(DisasContext
*ctx
)
6997 TCGv_i32 t0
= tcg_const_i32(Rc(ctx
->opcode
));
6998 gen_helper_dlmzb(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
6999 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
7000 tcg_temp_free_i32(t0
);
7003 /* mbar replaces eieio on 440 */
7004 static void gen_mbar(DisasContext
*ctx
)
7006 /* interpreted as no-op */
7009 /* msync replaces sync on 440 */
7010 static void gen_msync_4xx(DisasContext
*ctx
)
7012 /* interpreted as no-op */
7016 static void gen_icbt_440(DisasContext
*ctx
)
7018 /* interpreted as no-op */
7019 /* XXX: specification say this is treated as a load by the MMU
7020 * but does not generate any exception
7024 /* Embedded.Processor Control */
7026 static void gen_msgclr(DisasContext
*ctx
)
7028 #if defined(CONFIG_USER_ONLY)
7032 gen_helper_msgclr(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
7033 #endif /* defined(CONFIG_USER_ONLY) */
7036 static void gen_msgsnd(DisasContext
*ctx
)
7038 #if defined(CONFIG_USER_ONLY)
7042 gen_helper_msgsnd(cpu_gpr
[rB(ctx
->opcode
)]);
7043 #endif /* defined(CONFIG_USER_ONLY) */
7046 /*** Altivec vector extension ***/
7047 /* Altivec registers moves */
7049 static inline TCGv_ptr
gen_avr_ptr(int reg
)
7051 TCGv_ptr r
= tcg_temp_new_ptr();
7052 tcg_gen_addi_ptr(r
, cpu_env
, offsetof(CPUPPCState
, avr
[reg
]));
7056 #define GEN_VR_LDX(name, opc2, opc3) \
7057 static void glue(gen_, name)(DisasContext *ctx) \
7060 if (unlikely(!ctx->altivec_enabled)) { \
7061 gen_exception(ctx, POWERPC_EXCP_VPU); \
7064 gen_set_access_type(ctx, ACCESS_INT); \
7065 EA = tcg_temp_new(); \
7066 gen_addr_reg_index(ctx, EA); \
7067 tcg_gen_andi_tl(EA, EA, ~0xf); \
7068 /* We only need to swap high and low halves. gen_qemu_ld64 does necessary \
7069 64-bit byteswap already. */ \
7070 if (ctx->le_mode) { \
7071 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
7072 tcg_gen_addi_tl(EA, EA, 8); \
7073 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
7075 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
7076 tcg_gen_addi_tl(EA, EA, 8); \
7077 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
7079 tcg_temp_free(EA); \
7082 #define GEN_VR_STX(name, opc2, opc3) \
7083 static void gen_st##name(DisasContext *ctx) \
7086 if (unlikely(!ctx->altivec_enabled)) { \
7087 gen_exception(ctx, POWERPC_EXCP_VPU); \
7090 gen_set_access_type(ctx, ACCESS_INT); \
7091 EA = tcg_temp_new(); \
7092 gen_addr_reg_index(ctx, EA); \
7093 tcg_gen_andi_tl(EA, EA, ~0xf); \
7094 /* We only need to swap high and low halves. gen_qemu_st64 does necessary \
7095 64-bit byteswap already. */ \
7096 if (ctx->le_mode) { \
7097 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
7098 tcg_gen_addi_tl(EA, EA, 8); \
7099 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
7101 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
7102 tcg_gen_addi_tl(EA, EA, 8); \
7103 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
7105 tcg_temp_free(EA); \
7108 #define GEN_VR_LVE(name, opc2, opc3, size) \
7109 static void gen_lve##name(DisasContext *ctx) \
7113 if (unlikely(!ctx->altivec_enabled)) { \
7114 gen_exception(ctx, POWERPC_EXCP_VPU); \
7117 gen_set_access_type(ctx, ACCESS_INT); \
7118 EA = tcg_temp_new(); \
7119 gen_addr_reg_index(ctx, EA); \
7121 tcg_gen_andi_tl(EA, EA, ~(size - 1)); \
7123 rs = gen_avr_ptr(rS(ctx->opcode)); \
7124 gen_helper_lve##name(cpu_env, rs, EA); \
7125 tcg_temp_free(EA); \
7126 tcg_temp_free_ptr(rs); \
7129 #define GEN_VR_STVE(name, opc2, opc3, size) \
7130 static void gen_stve##name(DisasContext *ctx) \
7134 if (unlikely(!ctx->altivec_enabled)) { \
7135 gen_exception(ctx, POWERPC_EXCP_VPU); \
7138 gen_set_access_type(ctx, ACCESS_INT); \
7139 EA = tcg_temp_new(); \
7140 gen_addr_reg_index(ctx, EA); \
7142 tcg_gen_andi_tl(EA, EA, ~(size - 1)); \
7144 rs = gen_avr_ptr(rS(ctx->opcode)); \
7145 gen_helper_stve##name(cpu_env, rs, EA); \
7146 tcg_temp_free(EA); \
7147 tcg_temp_free_ptr(rs); \
7150 GEN_VR_LDX(lvx
, 0x07, 0x03);
7151 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
7152 GEN_VR_LDX(lvxl
, 0x07, 0x0B);
7154 GEN_VR_LVE(bx
, 0x07, 0x00, 1);
7155 GEN_VR_LVE(hx
, 0x07, 0x01, 2);
7156 GEN_VR_LVE(wx
, 0x07, 0x02, 4);
7158 GEN_VR_STX(svx
, 0x07, 0x07);
7159 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
7160 GEN_VR_STX(svxl
, 0x07, 0x0F);
7162 GEN_VR_STVE(bx
, 0x07, 0x04, 1);
7163 GEN_VR_STVE(hx
, 0x07, 0x05, 2);
7164 GEN_VR_STVE(wx
, 0x07, 0x06, 4);
7166 static void gen_lvsl(DisasContext
*ctx
)
7170 if (unlikely(!ctx
->altivec_enabled
)) {
7171 gen_exception(ctx
, POWERPC_EXCP_VPU
);
7174 EA
= tcg_temp_new();
7175 gen_addr_reg_index(ctx
, EA
);
7176 rd
= gen_avr_ptr(rD(ctx
->opcode
));
7177 gen_helper_lvsl(rd
, EA
);
7179 tcg_temp_free_ptr(rd
);
7182 static void gen_lvsr(DisasContext
*ctx
)
7186 if (unlikely(!ctx
->altivec_enabled
)) {
7187 gen_exception(ctx
, POWERPC_EXCP_VPU
);
7190 EA
= tcg_temp_new();
7191 gen_addr_reg_index(ctx
, EA
);
7192 rd
= gen_avr_ptr(rD(ctx
->opcode
));
7193 gen_helper_lvsr(rd
, EA
);
7195 tcg_temp_free_ptr(rd
);
7198 static void gen_mfvscr(DisasContext
*ctx
)
7201 if (unlikely(!ctx
->altivec_enabled
)) {
7202 gen_exception(ctx
, POWERPC_EXCP_VPU
);
7205 tcg_gen_movi_i64(cpu_avrh
[rD(ctx
->opcode
)], 0);
7206 t
= tcg_temp_new_i32();
7207 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUPPCState
, vscr
));
7208 tcg_gen_extu_i32_i64(cpu_avrl
[rD(ctx
->opcode
)], t
);
7209 tcg_temp_free_i32(t
);
7212 static void gen_mtvscr(DisasContext
*ctx
)
7215 if (unlikely(!ctx
->altivec_enabled
)) {
7216 gen_exception(ctx
, POWERPC_EXCP_VPU
);
7219 p
= gen_avr_ptr(rB(ctx
->opcode
));
7220 gen_helper_mtvscr(cpu_env
, p
);
7221 tcg_temp_free_ptr(p
);
7224 /* Logical operations */
7225 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
7226 static void glue(gen_, name)(DisasContext *ctx) \
7228 if (unlikely(!ctx->altivec_enabled)) { \
7229 gen_exception(ctx, POWERPC_EXCP_VPU); \
7232 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
7233 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
7236 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16);
7237 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17);
7238 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18);
7239 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19);
7240 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20);
7241 GEN_VX_LOGICAL(veqv
, tcg_gen_eqv_i64
, 2, 26);
7242 GEN_VX_LOGICAL(vnand
, tcg_gen_nand_i64
, 2, 22);
7243 GEN_VX_LOGICAL(vorc
, tcg_gen_orc_i64
, 2, 21);
7245 #define GEN_VXFORM(name, opc2, opc3) \
7246 static void glue(gen_, name)(DisasContext *ctx) \
7248 TCGv_ptr ra, rb, rd; \
7249 if (unlikely(!ctx->altivec_enabled)) { \
7250 gen_exception(ctx, POWERPC_EXCP_VPU); \
7253 ra = gen_avr_ptr(rA(ctx->opcode)); \
7254 rb = gen_avr_ptr(rB(ctx->opcode)); \
7255 rd = gen_avr_ptr(rD(ctx->opcode)); \
7256 gen_helper_##name (rd, ra, rb); \
7257 tcg_temp_free_ptr(ra); \
7258 tcg_temp_free_ptr(rb); \
7259 tcg_temp_free_ptr(rd); \
7262 #define GEN_VXFORM_ENV(name, opc2, opc3) \
7263 static void glue(gen_, name)(DisasContext *ctx) \
7265 TCGv_ptr ra, rb, rd; \
7266 if (unlikely(!ctx->altivec_enabled)) { \
7267 gen_exception(ctx, POWERPC_EXCP_VPU); \
7270 ra = gen_avr_ptr(rA(ctx->opcode)); \
7271 rb = gen_avr_ptr(rB(ctx->opcode)); \
7272 rd = gen_avr_ptr(rD(ctx->opcode)); \
7273 gen_helper_##name(cpu_env, rd, ra, rb); \
7274 tcg_temp_free_ptr(ra); \
7275 tcg_temp_free_ptr(rb); \
7276 tcg_temp_free_ptr(rd); \
7279 #define GEN_VXFORM3(name, opc2, opc3) \
7280 static void glue(gen_, name)(DisasContext *ctx) \
7282 TCGv_ptr ra, rb, rc, rd; \
7283 if (unlikely(!ctx->altivec_enabled)) { \
7284 gen_exception(ctx, POWERPC_EXCP_VPU); \
7287 ra = gen_avr_ptr(rA(ctx->opcode)); \
7288 rb = gen_avr_ptr(rB(ctx->opcode)); \
7289 rc = gen_avr_ptr(rC(ctx->opcode)); \
7290 rd = gen_avr_ptr(rD(ctx->opcode)); \
7291 gen_helper_##name(rd, ra, rb, rc); \
7292 tcg_temp_free_ptr(ra); \
7293 tcg_temp_free_ptr(rb); \
7294 tcg_temp_free_ptr(rc); \
7295 tcg_temp_free_ptr(rd); \
7299 * Support for Altivec instruction pairs that use bit 31 (Rc) as
7300 * an opcode bit. In general, these pairs come from different
7301 * versions of the ISA, so we must also support a pair of flags for
7304 #define GEN_VXFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
7305 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7307 if ((Rc(ctx->opcode) == 0) && \
7308 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
7310 } else if ((Rc(ctx->opcode) == 1) && \
7311 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
7314 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
7318 GEN_VXFORM(vaddubm
, 0, 0);
7319 GEN_VXFORM(vadduhm
, 0, 1);
7320 GEN_VXFORM(vadduwm
, 0, 2);
7321 GEN_VXFORM(vaddudm
, 0, 3);
7322 GEN_VXFORM(vsububm
, 0, 16);
7323 GEN_VXFORM(vsubuhm
, 0, 17);
7324 GEN_VXFORM(vsubuwm
, 0, 18);
7325 GEN_VXFORM(vsubudm
, 0, 19);
7326 GEN_VXFORM(vmaxub
, 1, 0);
7327 GEN_VXFORM(vmaxuh
, 1, 1);
7328 GEN_VXFORM(vmaxuw
, 1, 2);
7329 GEN_VXFORM(vmaxud
, 1, 3);
7330 GEN_VXFORM(vmaxsb
, 1, 4);
7331 GEN_VXFORM(vmaxsh
, 1, 5);
7332 GEN_VXFORM(vmaxsw
, 1, 6);
7333 GEN_VXFORM(vmaxsd
, 1, 7);
7334 GEN_VXFORM(vminub
, 1, 8);
7335 GEN_VXFORM(vminuh
, 1, 9);
7336 GEN_VXFORM(vminuw
, 1, 10);
7337 GEN_VXFORM(vminud
, 1, 11);
7338 GEN_VXFORM(vminsb
, 1, 12);
7339 GEN_VXFORM(vminsh
, 1, 13);
7340 GEN_VXFORM(vminsw
, 1, 14);
7341 GEN_VXFORM(vminsd
, 1, 15);
7342 GEN_VXFORM(vavgub
, 1, 16);
7343 GEN_VXFORM(vavguh
, 1, 17);
7344 GEN_VXFORM(vavguw
, 1, 18);
7345 GEN_VXFORM(vavgsb
, 1, 20);
7346 GEN_VXFORM(vavgsh
, 1, 21);
7347 GEN_VXFORM(vavgsw
, 1, 22);
7348 GEN_VXFORM(vmrghb
, 6, 0);
7349 GEN_VXFORM(vmrghh
, 6, 1);
7350 GEN_VXFORM(vmrghw
, 6, 2);
7351 GEN_VXFORM(vmrglb
, 6, 4);
7352 GEN_VXFORM(vmrglh
, 6, 5);
7353 GEN_VXFORM(vmrglw
, 6, 6);
7355 static void gen_vmrgew(DisasContext
*ctx
)
7359 if (unlikely(!ctx
->altivec_enabled
)) {
7360 gen_exception(ctx
, POWERPC_EXCP_VPU
);
7363 VT
= rD(ctx
->opcode
);
7364 VA
= rA(ctx
->opcode
);
7365 VB
= rB(ctx
->opcode
);
7366 tmp
= tcg_temp_new_i64();
7367 tcg_gen_shri_i64(tmp
, cpu_avrh
[VB
], 32);
7368 tcg_gen_deposit_i64(cpu_avrh
[VT
], cpu_avrh
[VA
], tmp
, 0, 32);
7369 tcg_gen_shri_i64(tmp
, cpu_avrl
[VB
], 32);
7370 tcg_gen_deposit_i64(cpu_avrl
[VT
], cpu_avrl
[VA
], tmp
, 0, 32);
7371 tcg_temp_free_i64(tmp
);
7374 static void gen_vmrgow(DisasContext
*ctx
)
7377 if (unlikely(!ctx
->altivec_enabled
)) {
7378 gen_exception(ctx
, POWERPC_EXCP_VPU
);
7381 VT
= rD(ctx
->opcode
);
7382 VA
= rA(ctx
->opcode
);
7383 VB
= rB(ctx
->opcode
);
7385 tcg_gen_deposit_i64(cpu_avrh
[VT
], cpu_avrh
[VB
], cpu_avrh
[VA
], 32, 32);
7386 tcg_gen_deposit_i64(cpu_avrl
[VT
], cpu_avrl
[VB
], cpu_avrl
[VA
], 32, 32);
7389 GEN_VXFORM(vmuloub
, 4, 0);
7390 GEN_VXFORM(vmulouh
, 4, 1);
7391 GEN_VXFORM(vmulouw
, 4, 2);
7392 GEN_VXFORM(vmuluwm
, 4, 2);
7393 GEN_VXFORM_DUAL(vmulouw
, PPC_ALTIVEC
, PPC_NONE
,
7394 vmuluwm
, PPC_NONE
, PPC2_ALTIVEC_207
)
7395 GEN_VXFORM(vmulosb
, 4, 4);
7396 GEN_VXFORM(vmulosh
, 4, 5);
7397 GEN_VXFORM(vmulosw
, 4, 6);
7398 GEN_VXFORM(vmuleub
, 4, 8);
7399 GEN_VXFORM(vmuleuh
, 4, 9);
7400 GEN_VXFORM(vmuleuw
, 4, 10);
7401 GEN_VXFORM(vmulesb
, 4, 12);
7402 GEN_VXFORM(vmulesh
, 4, 13);
7403 GEN_VXFORM(vmulesw
, 4, 14);
7404 GEN_VXFORM(vslb
, 2, 4);
7405 GEN_VXFORM(vslh
, 2, 5);
7406 GEN_VXFORM(vslw
, 2, 6);
7407 GEN_VXFORM(vsld
, 2, 23);
7408 GEN_VXFORM(vsrb
, 2, 8);
7409 GEN_VXFORM(vsrh
, 2, 9);
7410 GEN_VXFORM(vsrw
, 2, 10);
7411 GEN_VXFORM(vsrd
, 2, 27);
7412 GEN_VXFORM(vsrab
, 2, 12);
7413 GEN_VXFORM(vsrah
, 2, 13);
7414 GEN_VXFORM(vsraw
, 2, 14);
7415 GEN_VXFORM(vsrad
, 2, 15);
7416 GEN_VXFORM(vslo
, 6, 16);
7417 GEN_VXFORM(vsro
, 6, 17);
7418 GEN_VXFORM(vaddcuw
, 0, 6);
7419 GEN_VXFORM(vsubcuw
, 0, 22);
7420 GEN_VXFORM_ENV(vaddubs
, 0, 8);
7421 GEN_VXFORM_ENV(vadduhs
, 0, 9);
7422 GEN_VXFORM_ENV(vadduws
, 0, 10);
7423 GEN_VXFORM_ENV(vaddsbs
, 0, 12);
7424 GEN_VXFORM_ENV(vaddshs
, 0, 13);
7425 GEN_VXFORM_ENV(vaddsws
, 0, 14);
7426 GEN_VXFORM_ENV(vsububs
, 0, 24);
7427 GEN_VXFORM_ENV(vsubuhs
, 0, 25);
7428 GEN_VXFORM_ENV(vsubuws
, 0, 26);
7429 GEN_VXFORM_ENV(vsubsbs
, 0, 28);
7430 GEN_VXFORM_ENV(vsubshs
, 0, 29);
7431 GEN_VXFORM_ENV(vsubsws
, 0, 30);
7432 GEN_VXFORM(vadduqm
, 0, 4);
7433 GEN_VXFORM(vaddcuq
, 0, 5);
7434 GEN_VXFORM3(vaddeuqm
, 30, 0);
7435 GEN_VXFORM3(vaddecuq
, 30, 0);
7436 GEN_VXFORM_DUAL(vaddeuqm
, PPC_NONE
, PPC2_ALTIVEC_207
, \
7437 vaddecuq
, PPC_NONE
, PPC2_ALTIVEC_207
)
7438 GEN_VXFORM(vsubuqm
, 0, 20);
7439 GEN_VXFORM(vsubcuq
, 0, 21);
7440 GEN_VXFORM3(vsubeuqm
, 31, 0);
7441 GEN_VXFORM3(vsubecuq
, 31, 0);
7442 GEN_VXFORM_DUAL(vsubeuqm
, PPC_NONE
, PPC2_ALTIVEC_207
, \
7443 vsubecuq
, PPC_NONE
, PPC2_ALTIVEC_207
)
7444 GEN_VXFORM(vrlb
, 2, 0);
7445 GEN_VXFORM(vrlh
, 2, 1);
7446 GEN_VXFORM(vrlw
, 2, 2);
7447 GEN_VXFORM(vrld
, 2, 3);
7448 GEN_VXFORM(vsl
, 2, 7);
7449 GEN_VXFORM(vsr
, 2, 11);
7450 GEN_VXFORM_ENV(vpkuhum
, 7, 0);
7451 GEN_VXFORM_ENV(vpkuwum
, 7, 1);
7452 GEN_VXFORM_ENV(vpkudum
, 7, 17);
7453 GEN_VXFORM_ENV(vpkuhus
, 7, 2);
7454 GEN_VXFORM_ENV(vpkuwus
, 7, 3);
7455 GEN_VXFORM_ENV(vpkudus
, 7, 19);
7456 GEN_VXFORM_ENV(vpkshus
, 7, 4);
7457 GEN_VXFORM_ENV(vpkswus
, 7, 5);
7458 GEN_VXFORM_ENV(vpksdus
, 7, 21);
7459 GEN_VXFORM_ENV(vpkshss
, 7, 6);
7460 GEN_VXFORM_ENV(vpkswss
, 7, 7);
7461 GEN_VXFORM_ENV(vpksdss
, 7, 23);
7462 GEN_VXFORM(vpkpx
, 7, 12);
7463 GEN_VXFORM_ENV(vsum4ubs
, 4, 24);
7464 GEN_VXFORM_ENV(vsum4sbs
, 4, 28);
7465 GEN_VXFORM_ENV(vsum4shs
, 4, 25);
7466 GEN_VXFORM_ENV(vsum2sws
, 4, 26);
7467 GEN_VXFORM_ENV(vsumsws
, 4, 30);
7468 GEN_VXFORM_ENV(vaddfp
, 5, 0);
7469 GEN_VXFORM_ENV(vsubfp
, 5, 1);
7470 GEN_VXFORM_ENV(vmaxfp
, 5, 16);
7471 GEN_VXFORM_ENV(vminfp
, 5, 17);
7473 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
7474 static void glue(gen_, name)(DisasContext *ctx) \
7476 TCGv_ptr ra, rb, rd; \
7477 if (unlikely(!ctx->altivec_enabled)) { \
7478 gen_exception(ctx, POWERPC_EXCP_VPU); \
7481 ra = gen_avr_ptr(rA(ctx->opcode)); \
7482 rb = gen_avr_ptr(rB(ctx->opcode)); \
7483 rd = gen_avr_ptr(rD(ctx->opcode)); \
7484 gen_helper_##opname(cpu_env, rd, ra, rb); \
7485 tcg_temp_free_ptr(ra); \
7486 tcg_temp_free_ptr(rb); \
7487 tcg_temp_free_ptr(rd); \
7490 #define GEN_VXRFORM(name, opc2, opc3) \
7491 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
7492 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
7495 * Support for Altivec instructions that use bit 31 (Rc) as an opcode
7496 * bit but also use bit 21 as an actual Rc bit. In general, thse pairs
7497 * come from different versions of the ISA, so we must also support a
7498 * pair of flags for each instruction.
7500 #define GEN_VXRFORM_DUAL(name0, flg0, flg2_0, name1, flg1, flg2_1) \
7501 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7503 if ((Rc(ctx->opcode) == 0) && \
7504 ((ctx->insns_flags & flg0) || (ctx->insns_flags2 & flg2_0))) { \
7505 if (Rc21(ctx->opcode) == 0) { \
7508 gen_##name0##_(ctx); \
7510 } else if ((Rc(ctx->opcode) == 1) && \
7511 ((ctx->insns_flags & flg1) || (ctx->insns_flags2 & flg2_1))) { \
7512 if (Rc21(ctx->opcode) == 0) { \
7515 gen_##name1##_(ctx); \
7518 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
7522 GEN_VXRFORM(vcmpequb
, 3, 0)
7523 GEN_VXRFORM(vcmpequh
, 3, 1)
7524 GEN_VXRFORM(vcmpequw
, 3, 2)
7525 GEN_VXRFORM(vcmpequd
, 3, 3)
7526 GEN_VXRFORM(vcmpgtsb
, 3, 12)
7527 GEN_VXRFORM(vcmpgtsh
, 3, 13)
7528 GEN_VXRFORM(vcmpgtsw
, 3, 14)
7529 GEN_VXRFORM(vcmpgtsd
, 3, 15)
7530 GEN_VXRFORM(vcmpgtub
, 3, 8)
7531 GEN_VXRFORM(vcmpgtuh
, 3, 9)
7532 GEN_VXRFORM(vcmpgtuw
, 3, 10)
7533 GEN_VXRFORM(vcmpgtud
, 3, 11)
7534 GEN_VXRFORM(vcmpeqfp
, 3, 3)
7535 GEN_VXRFORM(vcmpgefp
, 3, 7)
7536 GEN_VXRFORM(vcmpgtfp
, 3, 11)
7537 GEN_VXRFORM(vcmpbfp
, 3, 15)
7539 GEN_VXRFORM_DUAL(vcmpeqfp
, PPC_ALTIVEC
, PPC_NONE
, \
7540 vcmpequd
, PPC_NONE
, PPC2_ALTIVEC_207
)
7541 GEN_VXRFORM_DUAL(vcmpbfp
, PPC_ALTIVEC
, PPC_NONE
, \
7542 vcmpgtsd
, PPC_NONE
, PPC2_ALTIVEC_207
)
7543 GEN_VXRFORM_DUAL(vcmpgtfp
, PPC_ALTIVEC
, PPC_NONE
, \
7544 vcmpgtud
, PPC_NONE
, PPC2_ALTIVEC_207
)
7546 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
7547 static void glue(gen_, name)(DisasContext *ctx) \
7551 if (unlikely(!ctx->altivec_enabled)) { \
7552 gen_exception(ctx, POWERPC_EXCP_VPU); \
7555 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7556 rd = gen_avr_ptr(rD(ctx->opcode)); \
7557 gen_helper_##name (rd, simm); \
7558 tcg_temp_free_i32(simm); \
7559 tcg_temp_free_ptr(rd); \
7562 GEN_VXFORM_SIMM(vspltisb
, 6, 12);
7563 GEN_VXFORM_SIMM(vspltish
, 6, 13);
7564 GEN_VXFORM_SIMM(vspltisw
, 6, 14);
7566 #define GEN_VXFORM_NOA(name, opc2, opc3) \
7567 static void glue(gen_, name)(DisasContext *ctx) \
7570 if (unlikely(!ctx->altivec_enabled)) { \
7571 gen_exception(ctx, POWERPC_EXCP_VPU); \
7574 rb = gen_avr_ptr(rB(ctx->opcode)); \
7575 rd = gen_avr_ptr(rD(ctx->opcode)); \
7576 gen_helper_##name (rd, rb); \
7577 tcg_temp_free_ptr(rb); \
7578 tcg_temp_free_ptr(rd); \
7581 #define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
7582 static void glue(gen_, name)(DisasContext *ctx) \
7586 if (unlikely(!ctx->altivec_enabled)) { \
7587 gen_exception(ctx, POWERPC_EXCP_VPU); \
7590 rb = gen_avr_ptr(rB(ctx->opcode)); \
7591 rd = gen_avr_ptr(rD(ctx->opcode)); \
7592 gen_helper_##name(cpu_env, rd, rb); \
7593 tcg_temp_free_ptr(rb); \
7594 tcg_temp_free_ptr(rd); \
7597 GEN_VXFORM_NOA(vupkhsb
, 7, 8);
7598 GEN_VXFORM_NOA(vupkhsh
, 7, 9);
7599 GEN_VXFORM_NOA(vupkhsw
, 7, 25);
7600 GEN_VXFORM_NOA(vupklsb
, 7, 10);
7601 GEN_VXFORM_NOA(vupklsh
, 7, 11);
7602 GEN_VXFORM_NOA(vupklsw
, 7, 27);
7603 GEN_VXFORM_NOA(vupkhpx
, 7, 13);
7604 GEN_VXFORM_NOA(vupklpx
, 7, 15);
7605 GEN_VXFORM_NOA_ENV(vrefp
, 5, 4);
7606 GEN_VXFORM_NOA_ENV(vrsqrtefp
, 5, 5);
7607 GEN_VXFORM_NOA_ENV(vexptefp
, 5, 6);
7608 GEN_VXFORM_NOA_ENV(vlogefp
, 5, 7);
7609 GEN_VXFORM_NOA_ENV(vrfim
, 5, 11);
7610 GEN_VXFORM_NOA_ENV(vrfin
, 5, 8);
7611 GEN_VXFORM_NOA_ENV(vrfip
, 5, 10);
7612 GEN_VXFORM_NOA_ENV(vrfiz
, 5, 9);
7614 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
7615 static void glue(gen_, name)(DisasContext *ctx) \
7619 if (unlikely(!ctx->altivec_enabled)) { \
7620 gen_exception(ctx, POWERPC_EXCP_VPU); \
7623 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
7624 rd = gen_avr_ptr(rD(ctx->opcode)); \
7625 gen_helper_##name (rd, simm); \
7626 tcg_temp_free_i32(simm); \
7627 tcg_temp_free_ptr(rd); \
7630 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
7631 static void glue(gen_, name)(DisasContext *ctx) \
7635 if (unlikely(!ctx->altivec_enabled)) { \
7636 gen_exception(ctx, POWERPC_EXCP_VPU); \
7639 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7640 rb = gen_avr_ptr(rB(ctx->opcode)); \
7641 rd = gen_avr_ptr(rD(ctx->opcode)); \
7642 gen_helper_##name (rd, rb, uimm); \
7643 tcg_temp_free_i32(uimm); \
7644 tcg_temp_free_ptr(rb); \
7645 tcg_temp_free_ptr(rd); \
7648 #define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
7649 static void glue(gen_, name)(DisasContext *ctx) \
7654 if (unlikely(!ctx->altivec_enabled)) { \
7655 gen_exception(ctx, POWERPC_EXCP_VPU); \
7658 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
7659 rb = gen_avr_ptr(rB(ctx->opcode)); \
7660 rd = gen_avr_ptr(rD(ctx->opcode)); \
7661 gen_helper_##name(cpu_env, rd, rb, uimm); \
7662 tcg_temp_free_i32(uimm); \
7663 tcg_temp_free_ptr(rb); \
7664 tcg_temp_free_ptr(rd); \
7667 GEN_VXFORM_UIMM(vspltb
, 6, 8);
7668 GEN_VXFORM_UIMM(vsplth
, 6, 9);
7669 GEN_VXFORM_UIMM(vspltw
, 6, 10);
7670 GEN_VXFORM_UIMM_ENV(vcfux
, 5, 12);
7671 GEN_VXFORM_UIMM_ENV(vcfsx
, 5, 13);
7672 GEN_VXFORM_UIMM_ENV(vctuxs
, 5, 14);
7673 GEN_VXFORM_UIMM_ENV(vctsxs
, 5, 15);
7675 static void gen_vsldoi(DisasContext
*ctx
)
7677 TCGv_ptr ra
, rb
, rd
;
7679 if (unlikely(!ctx
->altivec_enabled
)) {
7680 gen_exception(ctx
, POWERPC_EXCP_VPU
);
7683 ra
= gen_avr_ptr(rA(ctx
->opcode
));
7684 rb
= gen_avr_ptr(rB(ctx
->opcode
));
7685 rd
= gen_avr_ptr(rD(ctx
->opcode
));
7686 sh
= tcg_const_i32(VSH(ctx
->opcode
));
7687 gen_helper_vsldoi (rd
, ra
, rb
, sh
);
7688 tcg_temp_free_ptr(ra
);
7689 tcg_temp_free_ptr(rb
);
7690 tcg_temp_free_ptr(rd
);
7691 tcg_temp_free_i32(sh
);
7694 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
7695 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7697 TCGv_ptr ra, rb, rc, rd; \
7698 if (unlikely(!ctx->altivec_enabled)) { \
7699 gen_exception(ctx, POWERPC_EXCP_VPU); \
7702 ra = gen_avr_ptr(rA(ctx->opcode)); \
7703 rb = gen_avr_ptr(rB(ctx->opcode)); \
7704 rc = gen_avr_ptr(rC(ctx->opcode)); \
7705 rd = gen_avr_ptr(rD(ctx->opcode)); \
7706 if (Rc(ctx->opcode)) { \
7707 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
7709 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
7711 tcg_temp_free_ptr(ra); \
7712 tcg_temp_free_ptr(rb); \
7713 tcg_temp_free_ptr(rc); \
7714 tcg_temp_free_ptr(rd); \
7717 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16)
7719 static void gen_vmladduhm(DisasContext
*ctx
)
7721 TCGv_ptr ra
, rb
, rc
, rd
;
7722 if (unlikely(!ctx
->altivec_enabled
)) {
7723 gen_exception(ctx
, POWERPC_EXCP_VPU
);
7726 ra
= gen_avr_ptr(rA(ctx
->opcode
));
7727 rb
= gen_avr_ptr(rB(ctx
->opcode
));
7728 rc
= gen_avr_ptr(rC(ctx
->opcode
));
7729 rd
= gen_avr_ptr(rD(ctx
->opcode
));
7730 gen_helper_vmladduhm(rd
, ra
, rb
, rc
);
7731 tcg_temp_free_ptr(ra
);
7732 tcg_temp_free_ptr(rb
);
7733 tcg_temp_free_ptr(rc
);
7734 tcg_temp_free_ptr(rd
);
7737 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18)
7738 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19)
7739 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20)
7740 GEN_VAFORM_PAIRED(vsel
, vperm
, 21)
7741 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23)
7743 #if defined(TARGET_PPC64)
7744 static void gen_maddld(DisasContext
*ctx
)
7746 TCGv_i64 t1
= tcg_temp_new_i64();
7748 tcg_gen_mul_i64(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7749 tcg_gen_add_i64(cpu_gpr
[rD(ctx
->opcode
)], t1
, cpu_gpr
[rC(ctx
->opcode
)]);
7750 tcg_temp_free_i64(t1
);
7753 /* maddhd maddhdu */
7754 static void gen_maddhd_maddhdu(DisasContext
*ctx
)
7756 TCGv_i64 lo
= tcg_temp_new_i64();
7757 TCGv_i64 hi
= tcg_temp_new_i64();
7758 TCGv_i64 t1
= tcg_temp_new_i64();
7760 if (Rc(ctx
->opcode
)) {
7761 tcg_gen_mulu2_i64(lo
, hi
, cpu_gpr
[rA(ctx
->opcode
)],
7762 cpu_gpr
[rB(ctx
->opcode
)]);
7763 tcg_gen_movi_i64(t1
, 0);
7765 tcg_gen_muls2_i64(lo
, hi
, cpu_gpr
[rA(ctx
->opcode
)],
7766 cpu_gpr
[rB(ctx
->opcode
)]);
7767 tcg_gen_sari_i64(t1
, cpu_gpr
[rC(ctx
->opcode
)], 63);
7769 tcg_gen_add2_i64(t1
, cpu_gpr
[rD(ctx
->opcode
)], lo
, hi
,
7770 cpu_gpr
[rC(ctx
->opcode
)], t1
);
7771 tcg_temp_free_i64(lo
);
7772 tcg_temp_free_i64(hi
);
7773 tcg_temp_free_i64(t1
);
7775 #endif /* defined(TARGET_PPC64) */
7777 GEN_VXFORM_NOA(vclzb
, 1, 28)
7778 GEN_VXFORM_NOA(vclzh
, 1, 29)
7779 GEN_VXFORM_NOA(vclzw
, 1, 30)
7780 GEN_VXFORM_NOA(vclzd
, 1, 31)
7781 GEN_VXFORM_NOA(vpopcntb
, 1, 28)
7782 GEN_VXFORM_NOA(vpopcnth
, 1, 29)
7783 GEN_VXFORM_NOA(vpopcntw
, 1, 30)
7784 GEN_VXFORM_NOA(vpopcntd
, 1, 31)
7785 GEN_VXFORM_DUAL(vclzb
, PPC_NONE
, PPC2_ALTIVEC_207
, \
7786 vpopcntb
, PPC_NONE
, PPC2_ALTIVEC_207
)
7787 GEN_VXFORM_DUAL(vclzh
, PPC_NONE
, PPC2_ALTIVEC_207
, \
7788 vpopcnth
, PPC_NONE
, PPC2_ALTIVEC_207
)
7789 GEN_VXFORM_DUAL(vclzw
, PPC_NONE
, PPC2_ALTIVEC_207
, \
7790 vpopcntw
, PPC_NONE
, PPC2_ALTIVEC_207
)
7791 GEN_VXFORM_DUAL(vclzd
, PPC_NONE
, PPC2_ALTIVEC_207
, \
7792 vpopcntd
, PPC_NONE
, PPC2_ALTIVEC_207
)
7793 GEN_VXFORM(vbpermq
, 6, 21);
7794 GEN_VXFORM_NOA(vgbbd
, 6, 20);
7795 GEN_VXFORM(vpmsumb
, 4, 16)
7796 GEN_VXFORM(vpmsumh
, 4, 17)
7797 GEN_VXFORM(vpmsumw
, 4, 18)
7798 GEN_VXFORM(vpmsumd
, 4, 19)
7800 #define GEN_BCD(op) \
7801 static void gen_##op(DisasContext *ctx) \
7803 TCGv_ptr ra, rb, rd; \
7806 if (unlikely(!ctx->altivec_enabled)) { \
7807 gen_exception(ctx, POWERPC_EXCP_VPU); \
7811 ra = gen_avr_ptr(rA(ctx->opcode)); \
7812 rb = gen_avr_ptr(rB(ctx->opcode)); \
7813 rd = gen_avr_ptr(rD(ctx->opcode)); \
7815 ps = tcg_const_i32((ctx->opcode & 0x200) != 0); \
7817 gen_helper_##op(cpu_crf[6], rd, ra, rb, ps); \
7819 tcg_temp_free_ptr(ra); \
7820 tcg_temp_free_ptr(rb); \
7821 tcg_temp_free_ptr(rd); \
7822 tcg_temp_free_i32(ps); \
7828 GEN_VXFORM_DUAL(vsububm
, PPC_ALTIVEC
, PPC_NONE
, \
7829 bcdadd
, PPC_NONE
, PPC2_ALTIVEC_207
)
7830 GEN_VXFORM_DUAL(vsububs
, PPC_ALTIVEC
, PPC_NONE
, \
7831 bcdadd
, PPC_NONE
, PPC2_ALTIVEC_207
)
7832 GEN_VXFORM_DUAL(vsubuhm
, PPC_ALTIVEC
, PPC_NONE
, \
7833 bcdsub
, PPC_NONE
, PPC2_ALTIVEC_207
)
7834 GEN_VXFORM_DUAL(vsubuhs
, PPC_ALTIVEC
, PPC_NONE
, \
7835 bcdsub
, PPC_NONE
, PPC2_ALTIVEC_207
)
7837 static void gen_vsbox(DisasContext
*ctx
)
7840 if (unlikely(!ctx
->altivec_enabled
)) {
7841 gen_exception(ctx
, POWERPC_EXCP_VPU
);
7844 ra
= gen_avr_ptr(rA(ctx
->opcode
));
7845 rd
= gen_avr_ptr(rD(ctx
->opcode
));
7846 gen_helper_vsbox(rd
, ra
);
7847 tcg_temp_free_ptr(ra
);
7848 tcg_temp_free_ptr(rd
);
7851 GEN_VXFORM(vcipher
, 4, 20)
7852 GEN_VXFORM(vcipherlast
, 4, 20)
7853 GEN_VXFORM(vncipher
, 4, 21)
7854 GEN_VXFORM(vncipherlast
, 4, 21)
7856 GEN_VXFORM_DUAL(vcipher
, PPC_NONE
, PPC2_ALTIVEC_207
,
7857 vcipherlast
, PPC_NONE
, PPC2_ALTIVEC_207
)
7858 GEN_VXFORM_DUAL(vncipher
, PPC_NONE
, PPC2_ALTIVEC_207
,
7859 vncipherlast
, PPC_NONE
, PPC2_ALTIVEC_207
)
7861 #define VSHASIGMA(op) \
7862 static void gen_##op(DisasContext *ctx) \
7866 if (unlikely(!ctx->altivec_enabled)) { \
7867 gen_exception(ctx, POWERPC_EXCP_VPU); \
7870 ra = gen_avr_ptr(rA(ctx->opcode)); \
7871 rd = gen_avr_ptr(rD(ctx->opcode)); \
7872 st_six = tcg_const_i32(rB(ctx->opcode)); \
7873 gen_helper_##op(rd, ra, st_six); \
7874 tcg_temp_free_ptr(ra); \
7875 tcg_temp_free_ptr(rd); \
7876 tcg_temp_free_i32(st_six); \
7879 VSHASIGMA(vshasigmaw
)
7880 VSHASIGMA(vshasigmad
)
7882 GEN_VXFORM3(vpermxor
, 22, 0xFF)
7883 GEN_VXFORM_DUAL(vsldoi
, PPC_ALTIVEC
, PPC_NONE
,
7884 vpermxor
, PPC_NONE
, PPC2_ALTIVEC_207
)
7886 /*** VSX extension ***/
7888 static inline TCGv_i64
cpu_vsrh(int n
)
7893 return cpu_avrh
[n
-32];
7897 static inline TCGv_i64
cpu_vsrl(int n
)
7902 return cpu_avrl
[n
-32];
7906 #define VSX_LOAD_SCALAR(name, operation) \
7907 static void gen_##name(DisasContext *ctx) \
7910 if (unlikely(!ctx->vsx_enabled)) { \
7911 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7914 gen_set_access_type(ctx, ACCESS_INT); \
7915 EA = tcg_temp_new(); \
7916 gen_addr_reg_index(ctx, EA); \
7917 gen_qemu_##operation(ctx, cpu_vsrh(xT(ctx->opcode)), EA); \
7918 /* NOTE: cpu_vsrl is undefined */ \
7919 tcg_temp_free(EA); \
7922 VSX_LOAD_SCALAR(lxsdx
, ld64
)
7923 VSX_LOAD_SCALAR(lxsiwax
, ld32s_i64
)
7924 VSX_LOAD_SCALAR(lxsiwzx
, ld32u_i64
)
7925 VSX_LOAD_SCALAR(lxsspx
, ld32fs
)
7927 static void gen_lxvd2x(DisasContext
*ctx
)
7930 if (unlikely(!ctx
->vsx_enabled
)) {
7931 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7934 gen_set_access_type(ctx
, ACCESS_INT
);
7935 EA
= tcg_temp_new();
7936 gen_addr_reg_index(ctx
, EA
);
7937 gen_qemu_ld64(ctx
, cpu_vsrh(xT(ctx
->opcode
)), EA
);
7938 tcg_gen_addi_tl(EA
, EA
, 8);
7939 gen_qemu_ld64(ctx
, cpu_vsrl(xT(ctx
->opcode
)), EA
);
7943 static void gen_lxvdsx(DisasContext
*ctx
)
7946 if (unlikely(!ctx
->vsx_enabled
)) {
7947 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7950 gen_set_access_type(ctx
, ACCESS_INT
);
7951 EA
= tcg_temp_new();
7952 gen_addr_reg_index(ctx
, EA
);
7953 gen_qemu_ld64(ctx
, cpu_vsrh(xT(ctx
->opcode
)), EA
);
7954 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), cpu_vsrh(xT(ctx
->opcode
)));
7958 static void gen_lxvw4x(DisasContext
*ctx
)
7962 TCGv_i64 xth
= cpu_vsrh(xT(ctx
->opcode
));
7963 TCGv_i64 xtl
= cpu_vsrl(xT(ctx
->opcode
));
7964 if (unlikely(!ctx
->vsx_enabled
)) {
7965 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
7968 gen_set_access_type(ctx
, ACCESS_INT
);
7969 EA
= tcg_temp_new();
7970 tmp
= tcg_temp_new_i64();
7972 gen_addr_reg_index(ctx
, EA
);
7973 gen_qemu_ld32u_i64(ctx
, tmp
, EA
);
7974 tcg_gen_addi_tl(EA
, EA
, 4);
7975 gen_qemu_ld32u_i64(ctx
, xth
, EA
);
7976 tcg_gen_deposit_i64(xth
, xth
, tmp
, 32, 32);
7978 tcg_gen_addi_tl(EA
, EA
, 4);
7979 gen_qemu_ld32u_i64(ctx
, tmp
, EA
);
7980 tcg_gen_addi_tl(EA
, EA
, 4);
7981 gen_qemu_ld32u_i64(ctx
, xtl
, EA
);
7982 tcg_gen_deposit_i64(xtl
, xtl
, tmp
, 32, 32);
7985 tcg_temp_free_i64(tmp
);
7988 #define VSX_STORE_SCALAR(name, operation) \
7989 static void gen_##name(DisasContext *ctx) \
7992 if (unlikely(!ctx->vsx_enabled)) { \
7993 gen_exception(ctx, POWERPC_EXCP_VSXU); \
7996 gen_set_access_type(ctx, ACCESS_INT); \
7997 EA = tcg_temp_new(); \
7998 gen_addr_reg_index(ctx, EA); \
7999 gen_qemu_##operation(ctx, cpu_vsrh(xS(ctx->opcode)), EA); \
8000 tcg_temp_free(EA); \
8003 VSX_STORE_SCALAR(stxsdx
, st64
)
8004 VSX_STORE_SCALAR(stxsiwx
, st32_i64
)
8005 VSX_STORE_SCALAR(stxsspx
, st32fs
)
8007 static void gen_stxvd2x(DisasContext
*ctx
)
8010 if (unlikely(!ctx
->vsx_enabled
)) {
8011 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
8014 gen_set_access_type(ctx
, ACCESS_INT
);
8015 EA
= tcg_temp_new();
8016 gen_addr_reg_index(ctx
, EA
);
8017 gen_qemu_st64(ctx
, cpu_vsrh(xS(ctx
->opcode
)), EA
);
8018 tcg_gen_addi_tl(EA
, EA
, 8);
8019 gen_qemu_st64(ctx
, cpu_vsrl(xS(ctx
->opcode
)), EA
);
8023 static void gen_stxvw4x(DisasContext
*ctx
)
8027 if (unlikely(!ctx
->vsx_enabled
)) {
8028 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
8031 gen_set_access_type(ctx
, ACCESS_INT
);
8032 EA
= tcg_temp_new();
8033 gen_addr_reg_index(ctx
, EA
);
8034 tmp
= tcg_temp_new_i64();
8036 tcg_gen_shri_i64(tmp
, cpu_vsrh(xS(ctx
->opcode
)), 32);
8037 gen_qemu_st32_i64(ctx
, tmp
, EA
);
8038 tcg_gen_addi_tl(EA
, EA
, 4);
8039 gen_qemu_st32_i64(ctx
, cpu_vsrh(xS(ctx
->opcode
)), EA
);
8041 tcg_gen_shri_i64(tmp
, cpu_vsrl(xS(ctx
->opcode
)), 32);
8042 tcg_gen_addi_tl(EA
, EA
, 4);
8043 gen_qemu_st32_i64(ctx
, tmp
, EA
);
8044 tcg_gen_addi_tl(EA
, EA
, 4);
8045 gen_qemu_st32_i64(ctx
, cpu_vsrl(xS(ctx
->opcode
)), EA
);
8048 tcg_temp_free_i64(tmp
);
8051 #define MV_VSRW(name, tcgop1, tcgop2, target, source) \
8052 static void gen_##name(DisasContext *ctx) \
8054 if (xS(ctx->opcode) < 32) { \
8055 if (unlikely(!ctx->fpu_enabled)) { \
8056 gen_exception(ctx, POWERPC_EXCP_FPU); \
8060 if (unlikely(!ctx->altivec_enabled)) { \
8061 gen_exception(ctx, POWERPC_EXCP_VPU); \
8065 TCGv_i64 tmp = tcg_temp_new_i64(); \
8066 tcg_gen_##tcgop1(tmp, source); \
8067 tcg_gen_##tcgop2(target, tmp); \
8068 tcg_temp_free_i64(tmp); \
8072 MV_VSRW(mfvsrwz
, ext32u_i64
, trunc_i64_tl
, cpu_gpr
[rA(ctx
->opcode
)], \
8073 cpu_vsrh(xS(ctx
->opcode
)))
8074 MV_VSRW(mtvsrwa
, extu_tl_i64
, ext32s_i64
, cpu_vsrh(xT(ctx
->opcode
)), \
8075 cpu_gpr
[rA(ctx
->opcode
)])
8076 MV_VSRW(mtvsrwz
, extu_tl_i64
, ext32u_i64
, cpu_vsrh(xT(ctx
->opcode
)), \
8077 cpu_gpr
[rA(ctx
->opcode
)])
8079 #if defined(TARGET_PPC64)
8080 #define MV_VSRD(name, target, source) \
8081 static void gen_##name(DisasContext *ctx) \
8083 if (xS(ctx->opcode) < 32) { \
8084 if (unlikely(!ctx->fpu_enabled)) { \
8085 gen_exception(ctx, POWERPC_EXCP_FPU); \
8089 if (unlikely(!ctx->altivec_enabled)) { \
8090 gen_exception(ctx, POWERPC_EXCP_VPU); \
8094 tcg_gen_mov_i64(target, source); \
8097 MV_VSRD(mfvsrd
, cpu_gpr
[rA(ctx
->opcode
)], cpu_vsrh(xS(ctx
->opcode
)))
8098 MV_VSRD(mtvsrd
, cpu_vsrh(xT(ctx
->opcode
)), cpu_gpr
[rA(ctx
->opcode
)])
8102 static void gen_xxpermdi(DisasContext
*ctx
)
8104 if (unlikely(!ctx
->vsx_enabled
)) {
8105 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
8109 if (unlikely((xT(ctx
->opcode
) == xA(ctx
->opcode
)) ||
8110 (xT(ctx
->opcode
) == xB(ctx
->opcode
)))) {
8113 xh
= tcg_temp_new_i64();
8114 xl
= tcg_temp_new_i64();
8116 if ((DM(ctx
->opcode
) & 2) == 0) {
8117 tcg_gen_mov_i64(xh
, cpu_vsrh(xA(ctx
->opcode
)));
8119 tcg_gen_mov_i64(xh
, cpu_vsrl(xA(ctx
->opcode
)));
8121 if ((DM(ctx
->opcode
) & 1) == 0) {
8122 tcg_gen_mov_i64(xl
, cpu_vsrh(xB(ctx
->opcode
)));
8124 tcg_gen_mov_i64(xl
, cpu_vsrl(xB(ctx
->opcode
)));
8127 tcg_gen_mov_i64(cpu_vsrh(xT(ctx
->opcode
)), xh
);
8128 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), xl
);
8130 tcg_temp_free_i64(xh
);
8131 tcg_temp_free_i64(xl
);
8133 if ((DM(ctx
->opcode
) & 2) == 0) {
8134 tcg_gen_mov_i64(cpu_vsrh(xT(ctx
->opcode
)), cpu_vsrh(xA(ctx
->opcode
)));
8136 tcg_gen_mov_i64(cpu_vsrh(xT(ctx
->opcode
)), cpu_vsrl(xA(ctx
->opcode
)));
8138 if ((DM(ctx
->opcode
) & 1) == 0) {
8139 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), cpu_vsrh(xB(ctx
->opcode
)));
8141 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), cpu_vsrl(xB(ctx
->opcode
)));
8150 #define SGN_MASK_DP 0x8000000000000000ull
8151 #define SGN_MASK_SP 0x8000000080000000ull
8153 #define VSX_SCALAR_MOVE(name, op, sgn_mask) \
8154 static void glue(gen_, name)(DisasContext * ctx) \
8157 if (unlikely(!ctx->vsx_enabled)) { \
8158 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8161 xb = tcg_temp_new_i64(); \
8162 sgm = tcg_temp_new_i64(); \
8163 tcg_gen_mov_i64(xb, cpu_vsrh(xB(ctx->opcode))); \
8164 tcg_gen_movi_i64(sgm, sgn_mask); \
8167 tcg_gen_andc_i64(xb, xb, sgm); \
8171 tcg_gen_or_i64(xb, xb, sgm); \
8175 tcg_gen_xor_i64(xb, xb, sgm); \
8179 TCGv_i64 xa = tcg_temp_new_i64(); \
8180 tcg_gen_mov_i64(xa, cpu_vsrh(xA(ctx->opcode))); \
8181 tcg_gen_and_i64(xa, xa, sgm); \
8182 tcg_gen_andc_i64(xb, xb, sgm); \
8183 tcg_gen_or_i64(xb, xb, xa); \
8184 tcg_temp_free_i64(xa); \
8188 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xb); \
8189 tcg_temp_free_i64(xb); \
8190 tcg_temp_free_i64(sgm); \
8193 VSX_SCALAR_MOVE(xsabsdp
, OP_ABS
, SGN_MASK_DP
)
8194 VSX_SCALAR_MOVE(xsnabsdp
, OP_NABS
, SGN_MASK_DP
)
8195 VSX_SCALAR_MOVE(xsnegdp
, OP_NEG
, SGN_MASK_DP
)
8196 VSX_SCALAR_MOVE(xscpsgndp
, OP_CPSGN
, SGN_MASK_DP
)
8198 #define VSX_VECTOR_MOVE(name, op, sgn_mask) \
8199 static void glue(gen_, name)(DisasContext * ctx) \
8201 TCGv_i64 xbh, xbl, sgm; \
8202 if (unlikely(!ctx->vsx_enabled)) { \
8203 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8206 xbh = tcg_temp_new_i64(); \
8207 xbl = tcg_temp_new_i64(); \
8208 sgm = tcg_temp_new_i64(); \
8209 tcg_gen_mov_i64(xbh, cpu_vsrh(xB(ctx->opcode))); \
8210 tcg_gen_mov_i64(xbl, cpu_vsrl(xB(ctx->opcode))); \
8211 tcg_gen_movi_i64(sgm, sgn_mask); \
8214 tcg_gen_andc_i64(xbh, xbh, sgm); \
8215 tcg_gen_andc_i64(xbl, xbl, sgm); \
8219 tcg_gen_or_i64(xbh, xbh, sgm); \
8220 tcg_gen_or_i64(xbl, xbl, sgm); \
8224 tcg_gen_xor_i64(xbh, xbh, sgm); \
8225 tcg_gen_xor_i64(xbl, xbl, sgm); \
8229 TCGv_i64 xah = tcg_temp_new_i64(); \
8230 TCGv_i64 xal = tcg_temp_new_i64(); \
8231 tcg_gen_mov_i64(xah, cpu_vsrh(xA(ctx->opcode))); \
8232 tcg_gen_mov_i64(xal, cpu_vsrl(xA(ctx->opcode))); \
8233 tcg_gen_and_i64(xah, xah, sgm); \
8234 tcg_gen_and_i64(xal, xal, sgm); \
8235 tcg_gen_andc_i64(xbh, xbh, sgm); \
8236 tcg_gen_andc_i64(xbl, xbl, sgm); \
8237 tcg_gen_or_i64(xbh, xbh, xah); \
8238 tcg_gen_or_i64(xbl, xbl, xal); \
8239 tcg_temp_free_i64(xah); \
8240 tcg_temp_free_i64(xal); \
8244 tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xbh); \
8245 tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xbl); \
8246 tcg_temp_free_i64(xbh); \
8247 tcg_temp_free_i64(xbl); \
8248 tcg_temp_free_i64(sgm); \
8251 VSX_VECTOR_MOVE(xvabsdp
, OP_ABS
, SGN_MASK_DP
)
8252 VSX_VECTOR_MOVE(xvnabsdp
, OP_NABS
, SGN_MASK_DP
)
8253 VSX_VECTOR_MOVE(xvnegdp
, OP_NEG
, SGN_MASK_DP
)
8254 VSX_VECTOR_MOVE(xvcpsgndp
, OP_CPSGN
, SGN_MASK_DP
)
8255 VSX_VECTOR_MOVE(xvabssp
, OP_ABS
, SGN_MASK_SP
)
8256 VSX_VECTOR_MOVE(xvnabssp
, OP_NABS
, SGN_MASK_SP
)
8257 VSX_VECTOR_MOVE(xvnegsp
, OP_NEG
, SGN_MASK_SP
)
8258 VSX_VECTOR_MOVE(xvcpsgnsp
, OP_CPSGN
, SGN_MASK_SP
)
8260 #define GEN_VSX_HELPER_2(name, op1, op2, inval, type) \
8261 static void gen_##name(DisasContext * ctx) \
8264 if (unlikely(!ctx->vsx_enabled)) { \
8265 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8268 /* NIP cannot be restored if the memory exception comes from an helper */ \
8269 gen_update_nip(ctx, ctx->nip - 4); \
8270 opc = tcg_const_i32(ctx->opcode); \
8271 gen_helper_##name(cpu_env, opc); \
8272 tcg_temp_free_i32(opc); \
8275 #define GEN_VSX_HELPER_XT_XB_ENV(name, op1, op2, inval, type) \
8276 static void gen_##name(DisasContext * ctx) \
8278 if (unlikely(!ctx->vsx_enabled)) { \
8279 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8282 /* NIP cannot be restored if the exception comes */ \
8283 /* from a helper. */ \
8284 gen_update_nip(ctx, ctx->nip - 4); \
8286 gen_helper_##name(cpu_vsrh(xT(ctx->opcode)), cpu_env, \
8287 cpu_vsrh(xB(ctx->opcode))); \
8290 GEN_VSX_HELPER_2(xsadddp
, 0x00, 0x04, 0, PPC2_VSX
)
8291 GEN_VSX_HELPER_2(xssubdp
, 0x00, 0x05, 0, PPC2_VSX
)
8292 GEN_VSX_HELPER_2(xsmuldp
, 0x00, 0x06, 0, PPC2_VSX
)
8293 GEN_VSX_HELPER_2(xsdivdp
, 0x00, 0x07, 0, PPC2_VSX
)
8294 GEN_VSX_HELPER_2(xsredp
, 0x14, 0x05, 0, PPC2_VSX
)
8295 GEN_VSX_HELPER_2(xssqrtdp
, 0x16, 0x04, 0, PPC2_VSX
)
8296 GEN_VSX_HELPER_2(xsrsqrtedp
, 0x14, 0x04, 0, PPC2_VSX
)
8297 GEN_VSX_HELPER_2(xstdivdp
, 0x14, 0x07, 0, PPC2_VSX
)
8298 GEN_VSX_HELPER_2(xstsqrtdp
, 0x14, 0x06, 0, PPC2_VSX
)
8299 GEN_VSX_HELPER_2(xsmaddadp
, 0x04, 0x04, 0, PPC2_VSX
)
8300 GEN_VSX_HELPER_2(xsmaddmdp
, 0x04, 0x05, 0, PPC2_VSX
)
8301 GEN_VSX_HELPER_2(xsmsubadp
, 0x04, 0x06, 0, PPC2_VSX
)
8302 GEN_VSX_HELPER_2(xsmsubmdp
, 0x04, 0x07, 0, PPC2_VSX
)
8303 GEN_VSX_HELPER_2(xsnmaddadp
, 0x04, 0x14, 0, PPC2_VSX
)
8304 GEN_VSX_HELPER_2(xsnmaddmdp
, 0x04, 0x15, 0, PPC2_VSX
)
8305 GEN_VSX_HELPER_2(xsnmsubadp
, 0x04, 0x16, 0, PPC2_VSX
)
8306 GEN_VSX_HELPER_2(xsnmsubmdp
, 0x04, 0x17, 0, PPC2_VSX
)
8307 GEN_VSX_HELPER_2(xscmpodp
, 0x0C, 0x05, 0, PPC2_VSX
)
8308 GEN_VSX_HELPER_2(xscmpudp
, 0x0C, 0x04, 0, PPC2_VSX
)
8309 GEN_VSX_HELPER_2(xsmaxdp
, 0x00, 0x14, 0, PPC2_VSX
)
8310 GEN_VSX_HELPER_2(xsmindp
, 0x00, 0x15, 0, PPC2_VSX
)
8311 GEN_VSX_HELPER_2(xscvdpsp
, 0x12, 0x10, 0, PPC2_VSX
)
8312 GEN_VSX_HELPER_XT_XB_ENV(xscvdpspn
, 0x16, 0x10, 0, PPC2_VSX207
)
8313 GEN_VSX_HELPER_2(xscvspdp
, 0x12, 0x14, 0, PPC2_VSX
)
8314 GEN_VSX_HELPER_XT_XB_ENV(xscvspdpn
, 0x16, 0x14, 0, PPC2_VSX207
)
8315 GEN_VSX_HELPER_2(xscvdpsxds
, 0x10, 0x15, 0, PPC2_VSX
)
8316 GEN_VSX_HELPER_2(xscvdpsxws
, 0x10, 0x05, 0, PPC2_VSX
)
8317 GEN_VSX_HELPER_2(xscvdpuxds
, 0x10, 0x14, 0, PPC2_VSX
)
8318 GEN_VSX_HELPER_2(xscvdpuxws
, 0x10, 0x04, 0, PPC2_VSX
)
8319 GEN_VSX_HELPER_2(xscvsxddp
, 0x10, 0x17, 0, PPC2_VSX
)
8320 GEN_VSX_HELPER_2(xscvuxddp
, 0x10, 0x16, 0, PPC2_VSX
)
8321 GEN_VSX_HELPER_2(xsrdpi
, 0x12, 0x04, 0, PPC2_VSX
)
8322 GEN_VSX_HELPER_2(xsrdpic
, 0x16, 0x06, 0, PPC2_VSX
)
8323 GEN_VSX_HELPER_2(xsrdpim
, 0x12, 0x07, 0, PPC2_VSX
)
8324 GEN_VSX_HELPER_2(xsrdpip
, 0x12, 0x06, 0, PPC2_VSX
)
8325 GEN_VSX_HELPER_2(xsrdpiz
, 0x12, 0x05, 0, PPC2_VSX
)
8326 GEN_VSX_HELPER_XT_XB_ENV(xsrsp
, 0x12, 0x11, 0, PPC2_VSX207
)
8328 GEN_VSX_HELPER_2(xsaddsp
, 0x00, 0x00, 0, PPC2_VSX207
)
8329 GEN_VSX_HELPER_2(xssubsp
, 0x00, 0x01, 0, PPC2_VSX207
)
8330 GEN_VSX_HELPER_2(xsmulsp
, 0x00, 0x02, 0, PPC2_VSX207
)
8331 GEN_VSX_HELPER_2(xsdivsp
, 0x00, 0x03, 0, PPC2_VSX207
)
8332 GEN_VSX_HELPER_2(xsresp
, 0x14, 0x01, 0, PPC2_VSX207
)
8333 GEN_VSX_HELPER_2(xssqrtsp
, 0x16, 0x00, 0, PPC2_VSX207
)
8334 GEN_VSX_HELPER_2(xsrsqrtesp
, 0x14, 0x00, 0, PPC2_VSX207
)
8335 GEN_VSX_HELPER_2(xsmaddasp
, 0x04, 0x00, 0, PPC2_VSX207
)
8336 GEN_VSX_HELPER_2(xsmaddmsp
, 0x04, 0x01, 0, PPC2_VSX207
)
8337 GEN_VSX_HELPER_2(xsmsubasp
, 0x04, 0x02, 0, PPC2_VSX207
)
8338 GEN_VSX_HELPER_2(xsmsubmsp
, 0x04, 0x03, 0, PPC2_VSX207
)
8339 GEN_VSX_HELPER_2(xsnmaddasp
, 0x04, 0x10, 0, PPC2_VSX207
)
8340 GEN_VSX_HELPER_2(xsnmaddmsp
, 0x04, 0x11, 0, PPC2_VSX207
)
8341 GEN_VSX_HELPER_2(xsnmsubasp
, 0x04, 0x12, 0, PPC2_VSX207
)
8342 GEN_VSX_HELPER_2(xsnmsubmsp
, 0x04, 0x13, 0, PPC2_VSX207
)
8343 GEN_VSX_HELPER_2(xscvsxdsp
, 0x10, 0x13, 0, PPC2_VSX207
)
8344 GEN_VSX_HELPER_2(xscvuxdsp
, 0x10, 0x12, 0, PPC2_VSX207
)
8346 GEN_VSX_HELPER_2(xvadddp
, 0x00, 0x0C, 0, PPC2_VSX
)
8347 GEN_VSX_HELPER_2(xvsubdp
, 0x00, 0x0D, 0, PPC2_VSX
)
8348 GEN_VSX_HELPER_2(xvmuldp
, 0x00, 0x0E, 0, PPC2_VSX
)
8349 GEN_VSX_HELPER_2(xvdivdp
, 0x00, 0x0F, 0, PPC2_VSX
)
8350 GEN_VSX_HELPER_2(xvredp
, 0x14, 0x0D, 0, PPC2_VSX
)
8351 GEN_VSX_HELPER_2(xvsqrtdp
, 0x16, 0x0C, 0, PPC2_VSX
)
8352 GEN_VSX_HELPER_2(xvrsqrtedp
, 0x14, 0x0C, 0, PPC2_VSX
)
8353 GEN_VSX_HELPER_2(xvtdivdp
, 0x14, 0x0F, 0, PPC2_VSX
)
8354 GEN_VSX_HELPER_2(xvtsqrtdp
, 0x14, 0x0E, 0, PPC2_VSX
)
8355 GEN_VSX_HELPER_2(xvmaddadp
, 0x04, 0x0C, 0, PPC2_VSX
)
8356 GEN_VSX_HELPER_2(xvmaddmdp
, 0x04, 0x0D, 0, PPC2_VSX
)
8357 GEN_VSX_HELPER_2(xvmsubadp
, 0x04, 0x0E, 0, PPC2_VSX
)
8358 GEN_VSX_HELPER_2(xvmsubmdp
, 0x04, 0x0F, 0, PPC2_VSX
)
8359 GEN_VSX_HELPER_2(xvnmaddadp
, 0x04, 0x1C, 0, PPC2_VSX
)
8360 GEN_VSX_HELPER_2(xvnmaddmdp
, 0x04, 0x1D, 0, PPC2_VSX
)
8361 GEN_VSX_HELPER_2(xvnmsubadp
, 0x04, 0x1E, 0, PPC2_VSX
)
8362 GEN_VSX_HELPER_2(xvnmsubmdp
, 0x04, 0x1F, 0, PPC2_VSX
)
8363 GEN_VSX_HELPER_2(xvmaxdp
, 0x00, 0x1C, 0, PPC2_VSX
)
8364 GEN_VSX_HELPER_2(xvmindp
, 0x00, 0x1D, 0, PPC2_VSX
)
8365 GEN_VSX_HELPER_2(xvcmpeqdp
, 0x0C, 0x0C, 0, PPC2_VSX
)
8366 GEN_VSX_HELPER_2(xvcmpgtdp
, 0x0C, 0x0D, 0, PPC2_VSX
)
8367 GEN_VSX_HELPER_2(xvcmpgedp
, 0x0C, 0x0E, 0, PPC2_VSX
)
8368 GEN_VSX_HELPER_2(xvcvdpsp
, 0x12, 0x18, 0, PPC2_VSX
)
8369 GEN_VSX_HELPER_2(xvcvdpsxds
, 0x10, 0x1D, 0, PPC2_VSX
)
8370 GEN_VSX_HELPER_2(xvcvdpsxws
, 0x10, 0x0D, 0, PPC2_VSX
)
8371 GEN_VSX_HELPER_2(xvcvdpuxds
, 0x10, 0x1C, 0, PPC2_VSX
)
8372 GEN_VSX_HELPER_2(xvcvdpuxws
, 0x10, 0x0C, 0, PPC2_VSX
)
8373 GEN_VSX_HELPER_2(xvcvsxddp
, 0x10, 0x1F, 0, PPC2_VSX
)
8374 GEN_VSX_HELPER_2(xvcvuxddp
, 0x10, 0x1E, 0, PPC2_VSX
)
8375 GEN_VSX_HELPER_2(xvcvsxwdp
, 0x10, 0x0F, 0, PPC2_VSX
)
8376 GEN_VSX_HELPER_2(xvcvuxwdp
, 0x10, 0x0E, 0, PPC2_VSX
)
8377 GEN_VSX_HELPER_2(xvrdpi
, 0x12, 0x0C, 0, PPC2_VSX
)
8378 GEN_VSX_HELPER_2(xvrdpic
, 0x16, 0x0E, 0, PPC2_VSX
)
8379 GEN_VSX_HELPER_2(xvrdpim
, 0x12, 0x0F, 0, PPC2_VSX
)
8380 GEN_VSX_HELPER_2(xvrdpip
, 0x12, 0x0E, 0, PPC2_VSX
)
8381 GEN_VSX_HELPER_2(xvrdpiz
, 0x12, 0x0D, 0, PPC2_VSX
)
8383 GEN_VSX_HELPER_2(xvaddsp
, 0x00, 0x08, 0, PPC2_VSX
)
8384 GEN_VSX_HELPER_2(xvsubsp
, 0x00, 0x09, 0, PPC2_VSX
)
8385 GEN_VSX_HELPER_2(xvmulsp
, 0x00, 0x0A, 0, PPC2_VSX
)
8386 GEN_VSX_HELPER_2(xvdivsp
, 0x00, 0x0B, 0, PPC2_VSX
)
8387 GEN_VSX_HELPER_2(xvresp
, 0x14, 0x09, 0, PPC2_VSX
)
8388 GEN_VSX_HELPER_2(xvsqrtsp
, 0x16, 0x08, 0, PPC2_VSX
)
8389 GEN_VSX_HELPER_2(xvrsqrtesp
, 0x14, 0x08, 0, PPC2_VSX
)
8390 GEN_VSX_HELPER_2(xvtdivsp
, 0x14, 0x0B, 0, PPC2_VSX
)
8391 GEN_VSX_HELPER_2(xvtsqrtsp
, 0x14, 0x0A, 0, PPC2_VSX
)
8392 GEN_VSX_HELPER_2(xvmaddasp
, 0x04, 0x08, 0, PPC2_VSX
)
8393 GEN_VSX_HELPER_2(xvmaddmsp
, 0x04, 0x09, 0, PPC2_VSX
)
8394 GEN_VSX_HELPER_2(xvmsubasp
, 0x04, 0x0A, 0, PPC2_VSX
)
8395 GEN_VSX_HELPER_2(xvmsubmsp
, 0x04, 0x0B, 0, PPC2_VSX
)
8396 GEN_VSX_HELPER_2(xvnmaddasp
, 0x04, 0x18, 0, PPC2_VSX
)
8397 GEN_VSX_HELPER_2(xvnmaddmsp
, 0x04, 0x19, 0, PPC2_VSX
)
8398 GEN_VSX_HELPER_2(xvnmsubasp
, 0x04, 0x1A, 0, PPC2_VSX
)
8399 GEN_VSX_HELPER_2(xvnmsubmsp
, 0x04, 0x1B, 0, PPC2_VSX
)
8400 GEN_VSX_HELPER_2(xvmaxsp
, 0x00, 0x18, 0, PPC2_VSX
)
8401 GEN_VSX_HELPER_2(xvminsp
, 0x00, 0x19, 0, PPC2_VSX
)
8402 GEN_VSX_HELPER_2(xvcmpeqsp
, 0x0C, 0x08, 0, PPC2_VSX
)
8403 GEN_VSX_HELPER_2(xvcmpgtsp
, 0x0C, 0x09, 0, PPC2_VSX
)
8404 GEN_VSX_HELPER_2(xvcmpgesp
, 0x0C, 0x0A, 0, PPC2_VSX
)
8405 GEN_VSX_HELPER_2(xvcvspdp
, 0x12, 0x1C, 0, PPC2_VSX
)
8406 GEN_VSX_HELPER_2(xvcvspsxds
, 0x10, 0x19, 0, PPC2_VSX
)
8407 GEN_VSX_HELPER_2(xvcvspsxws
, 0x10, 0x09, 0, PPC2_VSX
)
8408 GEN_VSX_HELPER_2(xvcvspuxds
, 0x10, 0x18, 0, PPC2_VSX
)
8409 GEN_VSX_HELPER_2(xvcvspuxws
, 0x10, 0x08, 0, PPC2_VSX
)
8410 GEN_VSX_HELPER_2(xvcvsxdsp
, 0x10, 0x1B, 0, PPC2_VSX
)
8411 GEN_VSX_HELPER_2(xvcvuxdsp
, 0x10, 0x1A, 0, PPC2_VSX
)
8412 GEN_VSX_HELPER_2(xvcvsxwsp
, 0x10, 0x0B, 0, PPC2_VSX
)
8413 GEN_VSX_HELPER_2(xvcvuxwsp
, 0x10, 0x0A, 0, PPC2_VSX
)
8414 GEN_VSX_HELPER_2(xvrspi
, 0x12, 0x08, 0, PPC2_VSX
)
8415 GEN_VSX_HELPER_2(xvrspic
, 0x16, 0x0A, 0, PPC2_VSX
)
8416 GEN_VSX_HELPER_2(xvrspim
, 0x12, 0x0B, 0, PPC2_VSX
)
8417 GEN_VSX_HELPER_2(xvrspip
, 0x12, 0x0A, 0, PPC2_VSX
)
8418 GEN_VSX_HELPER_2(xvrspiz
, 0x12, 0x09, 0, PPC2_VSX
)
8420 #define VSX_LOGICAL(name, tcg_op) \
8421 static void glue(gen_, name)(DisasContext * ctx) \
8423 if (unlikely(!ctx->vsx_enabled)) { \
8424 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8427 tcg_op(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)), \
8428 cpu_vsrh(xB(ctx->opcode))); \
8429 tcg_op(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)), \
8430 cpu_vsrl(xB(ctx->opcode))); \
8433 VSX_LOGICAL(xxland
, tcg_gen_and_i64
)
8434 VSX_LOGICAL(xxlandc
, tcg_gen_andc_i64
)
8435 VSX_LOGICAL(xxlor
, tcg_gen_or_i64
)
8436 VSX_LOGICAL(xxlxor
, tcg_gen_xor_i64
)
8437 VSX_LOGICAL(xxlnor
, tcg_gen_nor_i64
)
8438 VSX_LOGICAL(xxleqv
, tcg_gen_eqv_i64
)
8439 VSX_LOGICAL(xxlnand
, tcg_gen_nand_i64
)
8440 VSX_LOGICAL(xxlorc
, tcg_gen_orc_i64
)
8442 #define VSX_XXMRG(name, high) \
8443 static void glue(gen_, name)(DisasContext * ctx) \
8445 TCGv_i64 a0, a1, b0, b1; \
8446 if (unlikely(!ctx->vsx_enabled)) { \
8447 gen_exception(ctx, POWERPC_EXCP_VSXU); \
8450 a0 = tcg_temp_new_i64(); \
8451 a1 = tcg_temp_new_i64(); \
8452 b0 = tcg_temp_new_i64(); \
8453 b1 = tcg_temp_new_i64(); \
8455 tcg_gen_mov_i64(a0, cpu_vsrh(xA(ctx->opcode))); \
8456 tcg_gen_mov_i64(a1, cpu_vsrh(xA(ctx->opcode))); \
8457 tcg_gen_mov_i64(b0, cpu_vsrh(xB(ctx->opcode))); \
8458 tcg_gen_mov_i64(b1, cpu_vsrh(xB(ctx->opcode))); \
8460 tcg_gen_mov_i64(a0, cpu_vsrl(xA(ctx->opcode))); \
8461 tcg_gen_mov_i64(a1, cpu_vsrl(xA(ctx->opcode))); \
8462 tcg_gen_mov_i64(b0, cpu_vsrl(xB(ctx->opcode))); \
8463 tcg_gen_mov_i64(b1, cpu_vsrl(xB(ctx->opcode))); \
8465 tcg_gen_shri_i64(a0, a0, 32); \
8466 tcg_gen_shri_i64(b0, b0, 32); \
8467 tcg_gen_deposit_i64(cpu_vsrh(xT(ctx->opcode)), \
8469 tcg_gen_deposit_i64(cpu_vsrl(xT(ctx->opcode)), \
8471 tcg_temp_free_i64(a0); \
8472 tcg_temp_free_i64(a1); \
8473 tcg_temp_free_i64(b0); \
8474 tcg_temp_free_i64(b1); \
8477 VSX_XXMRG(xxmrghw
, 1)
8478 VSX_XXMRG(xxmrglw
, 0)
8480 static void gen_xxsel(DisasContext
* ctx
)
8483 if (unlikely(!ctx
->vsx_enabled
)) {
8484 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
8487 a
= tcg_temp_new_i64();
8488 b
= tcg_temp_new_i64();
8489 c
= tcg_temp_new_i64();
8491 tcg_gen_mov_i64(a
, cpu_vsrh(xA(ctx
->opcode
)));
8492 tcg_gen_mov_i64(b
, cpu_vsrh(xB(ctx
->opcode
)));
8493 tcg_gen_mov_i64(c
, cpu_vsrh(xC(ctx
->opcode
)));
8495 tcg_gen_and_i64(b
, b
, c
);
8496 tcg_gen_andc_i64(a
, a
, c
);
8497 tcg_gen_or_i64(cpu_vsrh(xT(ctx
->opcode
)), a
, b
);
8499 tcg_gen_mov_i64(a
, cpu_vsrl(xA(ctx
->opcode
)));
8500 tcg_gen_mov_i64(b
, cpu_vsrl(xB(ctx
->opcode
)));
8501 tcg_gen_mov_i64(c
, cpu_vsrl(xC(ctx
->opcode
)));
8503 tcg_gen_and_i64(b
, b
, c
);
8504 tcg_gen_andc_i64(a
, a
, c
);
8505 tcg_gen_or_i64(cpu_vsrl(xT(ctx
->opcode
)), a
, b
);
8507 tcg_temp_free_i64(a
);
8508 tcg_temp_free_i64(b
);
8509 tcg_temp_free_i64(c
);
8512 static void gen_xxspltw(DisasContext
*ctx
)
8515 TCGv_i64 vsr
= (UIM(ctx
->opcode
) & 2) ?
8516 cpu_vsrl(xB(ctx
->opcode
)) :
8517 cpu_vsrh(xB(ctx
->opcode
));
8519 if (unlikely(!ctx
->vsx_enabled
)) {
8520 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
8524 b
= tcg_temp_new_i64();
8525 b2
= tcg_temp_new_i64();
8527 if (UIM(ctx
->opcode
) & 1) {
8528 tcg_gen_ext32u_i64(b
, vsr
);
8530 tcg_gen_shri_i64(b
, vsr
, 32);
8533 tcg_gen_shli_i64(b2
, b
, 32);
8534 tcg_gen_or_i64(cpu_vsrh(xT(ctx
->opcode
)), b
, b2
);
8535 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), cpu_vsrh(xT(ctx
->opcode
)));
8537 tcg_temp_free_i64(b
);
8538 tcg_temp_free_i64(b2
);
8541 static void gen_xxsldwi(DisasContext
*ctx
)
8544 if (unlikely(!ctx
->vsx_enabled
)) {
8545 gen_exception(ctx
, POWERPC_EXCP_VSXU
);
8548 xth
= tcg_temp_new_i64();
8549 xtl
= tcg_temp_new_i64();
8551 switch (SHW(ctx
->opcode
)) {
8553 tcg_gen_mov_i64(xth
, cpu_vsrh(xA(ctx
->opcode
)));
8554 tcg_gen_mov_i64(xtl
, cpu_vsrl(xA(ctx
->opcode
)));
8558 TCGv_i64 t0
= tcg_temp_new_i64();
8559 tcg_gen_mov_i64(xth
, cpu_vsrh(xA(ctx
->opcode
)));
8560 tcg_gen_shli_i64(xth
, xth
, 32);
8561 tcg_gen_mov_i64(t0
, cpu_vsrl(xA(ctx
->opcode
)));
8562 tcg_gen_shri_i64(t0
, t0
, 32);
8563 tcg_gen_or_i64(xth
, xth
, t0
);
8564 tcg_gen_mov_i64(xtl
, cpu_vsrl(xA(ctx
->opcode
)));
8565 tcg_gen_shli_i64(xtl
, xtl
, 32);
8566 tcg_gen_mov_i64(t0
, cpu_vsrh(xB(ctx
->opcode
)));
8567 tcg_gen_shri_i64(t0
, t0
, 32);
8568 tcg_gen_or_i64(xtl
, xtl
, t0
);
8569 tcg_temp_free_i64(t0
);
8573 tcg_gen_mov_i64(xth
, cpu_vsrl(xA(ctx
->opcode
)));
8574 tcg_gen_mov_i64(xtl
, cpu_vsrh(xB(ctx
->opcode
)));
8578 TCGv_i64 t0
= tcg_temp_new_i64();
8579 tcg_gen_mov_i64(xth
, cpu_vsrl(xA(ctx
->opcode
)));
8580 tcg_gen_shli_i64(xth
, xth
, 32);
8581 tcg_gen_mov_i64(t0
, cpu_vsrh(xB(ctx
->opcode
)));
8582 tcg_gen_shri_i64(t0
, t0
, 32);
8583 tcg_gen_or_i64(xth
, xth
, t0
);
8584 tcg_gen_mov_i64(xtl
, cpu_vsrh(xB(ctx
->opcode
)));
8585 tcg_gen_shli_i64(xtl
, xtl
, 32);
8586 tcg_gen_mov_i64(t0
, cpu_vsrl(xB(ctx
->opcode
)));
8587 tcg_gen_shri_i64(t0
, t0
, 32);
8588 tcg_gen_or_i64(xtl
, xtl
, t0
);
8589 tcg_temp_free_i64(t0
);
8594 tcg_gen_mov_i64(cpu_vsrh(xT(ctx
->opcode
)), xth
);
8595 tcg_gen_mov_i64(cpu_vsrl(xT(ctx
->opcode
)), xtl
);
8597 tcg_temp_free_i64(xth
);
8598 tcg_temp_free_i64(xtl
);
8601 /*** Decimal Floating Point ***/
8603 static inline TCGv_ptr
gen_fprp_ptr(int reg
)
8605 TCGv_ptr r
= tcg_temp_new_ptr();
8606 tcg_gen_addi_ptr(r
, cpu_env
, offsetof(CPUPPCState
, fpr
[reg
]));
8610 #define GEN_DFP_T_A_B_Rc(name) \
8611 static void gen_##name(DisasContext *ctx) \
8613 TCGv_ptr rd, ra, rb; \
8614 if (unlikely(!ctx->fpu_enabled)) { \
8615 gen_exception(ctx, POWERPC_EXCP_FPU); \
8618 gen_update_nip(ctx, ctx->nip - 4); \
8619 rd = gen_fprp_ptr(rD(ctx->opcode)); \
8620 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8621 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8622 gen_helper_##name(cpu_env, rd, ra, rb); \
8623 if (unlikely(Rc(ctx->opcode) != 0)) { \
8624 gen_set_cr1_from_fpscr(ctx); \
8626 tcg_temp_free_ptr(rd); \
8627 tcg_temp_free_ptr(ra); \
8628 tcg_temp_free_ptr(rb); \
8631 #define GEN_DFP_BF_A_B(name) \
8632 static void gen_##name(DisasContext *ctx) \
8635 if (unlikely(!ctx->fpu_enabled)) { \
8636 gen_exception(ctx, POWERPC_EXCP_FPU); \
8639 gen_update_nip(ctx, ctx->nip - 4); \
8640 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8641 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8642 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
8644 tcg_temp_free_ptr(ra); \
8645 tcg_temp_free_ptr(rb); \
8648 #define GEN_DFP_BF_A_DCM(name) \
8649 static void gen_##name(DisasContext *ctx) \
8653 if (unlikely(!ctx->fpu_enabled)) { \
8654 gen_exception(ctx, POWERPC_EXCP_FPU); \
8657 gen_update_nip(ctx, ctx->nip - 4); \
8658 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8659 dcm = tcg_const_i32(DCM(ctx->opcode)); \
8660 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
8661 cpu_env, ra, dcm); \
8662 tcg_temp_free_ptr(ra); \
8663 tcg_temp_free_i32(dcm); \
8666 #define GEN_DFP_T_B_U32_U32_Rc(name, u32f1, u32f2) \
8667 static void gen_##name(DisasContext *ctx) \
8670 TCGv_i32 u32_1, u32_2; \
8671 if (unlikely(!ctx->fpu_enabled)) { \
8672 gen_exception(ctx, POWERPC_EXCP_FPU); \
8675 gen_update_nip(ctx, ctx->nip - 4); \
8676 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8677 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8678 u32_1 = tcg_const_i32(u32f1(ctx->opcode)); \
8679 u32_2 = tcg_const_i32(u32f2(ctx->opcode)); \
8680 gen_helper_##name(cpu_env, rt, rb, u32_1, u32_2); \
8681 if (unlikely(Rc(ctx->opcode) != 0)) { \
8682 gen_set_cr1_from_fpscr(ctx); \
8684 tcg_temp_free_ptr(rt); \
8685 tcg_temp_free_ptr(rb); \
8686 tcg_temp_free_i32(u32_1); \
8687 tcg_temp_free_i32(u32_2); \
8690 #define GEN_DFP_T_A_B_I32_Rc(name, i32fld) \
8691 static void gen_##name(DisasContext *ctx) \
8693 TCGv_ptr rt, ra, rb; \
8695 if (unlikely(!ctx->fpu_enabled)) { \
8696 gen_exception(ctx, POWERPC_EXCP_FPU); \
8699 gen_update_nip(ctx, ctx->nip - 4); \
8700 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8701 ra = gen_fprp_ptr(rA(ctx->opcode)); \
8702 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8703 i32 = tcg_const_i32(i32fld(ctx->opcode)); \
8704 gen_helper_##name(cpu_env, rt, ra, rb, i32); \
8705 if (unlikely(Rc(ctx->opcode) != 0)) { \
8706 gen_set_cr1_from_fpscr(ctx); \
8708 tcg_temp_free_ptr(rt); \
8709 tcg_temp_free_ptr(rb); \
8710 tcg_temp_free_ptr(ra); \
8711 tcg_temp_free_i32(i32); \
8714 #define GEN_DFP_T_B_Rc(name) \
8715 static void gen_##name(DisasContext *ctx) \
8718 if (unlikely(!ctx->fpu_enabled)) { \
8719 gen_exception(ctx, POWERPC_EXCP_FPU); \
8722 gen_update_nip(ctx, ctx->nip - 4); \
8723 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8724 rb = gen_fprp_ptr(rB(ctx->opcode)); \
8725 gen_helper_##name(cpu_env, rt, rb); \
8726 if (unlikely(Rc(ctx->opcode) != 0)) { \
8727 gen_set_cr1_from_fpscr(ctx); \
8729 tcg_temp_free_ptr(rt); \
8730 tcg_temp_free_ptr(rb); \
8733 #define GEN_DFP_T_FPR_I32_Rc(name, fprfld, i32fld) \
8734 static void gen_##name(DisasContext *ctx) \
8738 if (unlikely(!ctx->fpu_enabled)) { \
8739 gen_exception(ctx, POWERPC_EXCP_FPU); \
8742 gen_update_nip(ctx, ctx->nip - 4); \
8743 rt = gen_fprp_ptr(rD(ctx->opcode)); \
8744 rs = gen_fprp_ptr(fprfld(ctx->opcode)); \
8745 i32 = tcg_const_i32(i32fld(ctx->opcode)); \
8746 gen_helper_##name(cpu_env, rt, rs, i32); \
8747 if (unlikely(Rc(ctx->opcode) != 0)) { \
8748 gen_set_cr1_from_fpscr(ctx); \
8750 tcg_temp_free_ptr(rt); \
8751 tcg_temp_free_ptr(rs); \
8752 tcg_temp_free_i32(i32); \
8755 GEN_DFP_T_A_B_Rc(dadd
)
8756 GEN_DFP_T_A_B_Rc(daddq
)
8757 GEN_DFP_T_A_B_Rc(dsub
)
8758 GEN_DFP_T_A_B_Rc(dsubq
)
8759 GEN_DFP_T_A_B_Rc(dmul
)
8760 GEN_DFP_T_A_B_Rc(dmulq
)
8761 GEN_DFP_T_A_B_Rc(ddiv
)
8762 GEN_DFP_T_A_B_Rc(ddivq
)
8763 GEN_DFP_BF_A_B(dcmpu
)
8764 GEN_DFP_BF_A_B(dcmpuq
)
8765 GEN_DFP_BF_A_B(dcmpo
)
8766 GEN_DFP_BF_A_B(dcmpoq
)
8767 GEN_DFP_BF_A_DCM(dtstdc
)
8768 GEN_DFP_BF_A_DCM(dtstdcq
)
8769 GEN_DFP_BF_A_DCM(dtstdg
)
8770 GEN_DFP_BF_A_DCM(dtstdgq
)
8771 GEN_DFP_BF_A_B(dtstex
)
8772 GEN_DFP_BF_A_B(dtstexq
)
8773 GEN_DFP_BF_A_B(dtstsf
)
8774 GEN_DFP_BF_A_B(dtstsfq
)
8775 GEN_DFP_T_B_U32_U32_Rc(dquai
, SIMM5
, RMC
)
8776 GEN_DFP_T_B_U32_U32_Rc(dquaiq
, SIMM5
, RMC
)
8777 GEN_DFP_T_A_B_I32_Rc(dqua
, RMC
)
8778 GEN_DFP_T_A_B_I32_Rc(dquaq
, RMC
)
8779 GEN_DFP_T_A_B_I32_Rc(drrnd
, RMC
)
8780 GEN_DFP_T_A_B_I32_Rc(drrndq
, RMC
)
8781 GEN_DFP_T_B_U32_U32_Rc(drintx
, FPW
, RMC
)
8782 GEN_DFP_T_B_U32_U32_Rc(drintxq
, FPW
, RMC
)
8783 GEN_DFP_T_B_U32_U32_Rc(drintn
, FPW
, RMC
)
8784 GEN_DFP_T_B_U32_U32_Rc(drintnq
, FPW
, RMC
)
8785 GEN_DFP_T_B_Rc(dctdp
)
8786 GEN_DFP_T_B_Rc(dctqpq
)
8787 GEN_DFP_T_B_Rc(drsp
)
8788 GEN_DFP_T_B_Rc(drdpq
)
8789 GEN_DFP_T_B_Rc(dcffix
)
8790 GEN_DFP_T_B_Rc(dcffixq
)
8791 GEN_DFP_T_B_Rc(dctfix
)
8792 GEN_DFP_T_B_Rc(dctfixq
)
8793 GEN_DFP_T_FPR_I32_Rc(ddedpd
, rB
, SP
)
8794 GEN_DFP_T_FPR_I32_Rc(ddedpdq
, rB
, SP
)
8795 GEN_DFP_T_FPR_I32_Rc(denbcd
, rB
, SP
)
8796 GEN_DFP_T_FPR_I32_Rc(denbcdq
, rB
, SP
)
8797 GEN_DFP_T_B_Rc(dxex
)
8798 GEN_DFP_T_B_Rc(dxexq
)
8799 GEN_DFP_T_A_B_Rc(diex
)
8800 GEN_DFP_T_A_B_Rc(diexq
)
8801 GEN_DFP_T_FPR_I32_Rc(dscli
, rA
, DCM
)
8802 GEN_DFP_T_FPR_I32_Rc(dscliq
, rA
, DCM
)
8803 GEN_DFP_T_FPR_I32_Rc(dscri
, rA
, DCM
)
8804 GEN_DFP_T_FPR_I32_Rc(dscriq
, rA
, DCM
)
8806 /*** SPE extension ***/
8807 /* Register moves */
8809 static inline void gen_evmra(DisasContext
*ctx
)
8812 if (unlikely(!ctx
->spe_enabled
)) {
8813 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8817 TCGv_i64 tmp
= tcg_temp_new_i64();
8819 /* tmp := rA_lo + rA_hi << 32 */
8820 tcg_gen_concat_tl_i64(tmp
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
8822 /* spe_acc := tmp */
8823 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
8824 tcg_temp_free_i64(tmp
);
8827 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8828 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
8831 static inline void gen_load_gpr64(TCGv_i64 t
, int reg
)
8833 tcg_gen_concat_tl_i64(t
, cpu_gpr
[reg
], cpu_gprh
[reg
]);
8836 static inline void gen_store_gpr64(int reg
, TCGv_i64 t
)
8838 tcg_gen_extr_i64_tl(cpu_gpr
[reg
], cpu_gprh
[reg
], t
);
8841 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
8842 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
8844 if (Rc(ctx->opcode)) \
8850 /* Handler for undefined SPE opcodes */
8851 static inline void gen_speundef(DisasContext
*ctx
)
8853 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
8857 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
8858 static inline void gen_##name(DisasContext *ctx) \
8860 if (unlikely(!ctx->spe_enabled)) { \
8861 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8864 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8865 cpu_gpr[rB(ctx->opcode)]); \
8866 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
8867 cpu_gprh[rB(ctx->opcode)]); \
8870 GEN_SPEOP_LOGIC2(evand
, tcg_gen_and_tl
);
8871 GEN_SPEOP_LOGIC2(evandc
, tcg_gen_andc_tl
);
8872 GEN_SPEOP_LOGIC2(evxor
, tcg_gen_xor_tl
);
8873 GEN_SPEOP_LOGIC2(evor
, tcg_gen_or_tl
);
8874 GEN_SPEOP_LOGIC2(evnor
, tcg_gen_nor_tl
);
8875 GEN_SPEOP_LOGIC2(eveqv
, tcg_gen_eqv_tl
);
8876 GEN_SPEOP_LOGIC2(evorc
, tcg_gen_orc_tl
);
8877 GEN_SPEOP_LOGIC2(evnand
, tcg_gen_nand_tl
);
8879 /* SPE logic immediate */
8880 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
8881 static inline void gen_##name(DisasContext *ctx) \
8884 if (unlikely(!ctx->spe_enabled)) { \
8885 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8888 t0 = tcg_temp_new_i32(); \
8890 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8891 tcg_opi(t0, t0, rB(ctx->opcode)); \
8892 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8894 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
8895 tcg_opi(t0, t0, rB(ctx->opcode)); \
8896 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8898 tcg_temp_free_i32(t0); \
8900 GEN_SPEOP_TCG_LOGIC_IMM2(evslwi
, tcg_gen_shli_i32
);
8901 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu
, tcg_gen_shri_i32
);
8902 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis
, tcg_gen_sari_i32
);
8903 GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi
, tcg_gen_rotli_i32
);
8905 /* SPE arithmetic */
8906 #define GEN_SPEOP_ARITH1(name, tcg_op) \
8907 static inline void gen_##name(DisasContext *ctx) \
8910 if (unlikely(!ctx->spe_enabled)) { \
8911 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8914 t0 = tcg_temp_new_i32(); \
8916 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8918 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8920 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
8922 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8924 tcg_temp_free_i32(t0); \
8927 static inline void gen_op_evabs(TCGv_i32 ret
, TCGv_i32 arg1
)
8929 TCGLabel
*l1
= gen_new_label();
8930 TCGLabel
*l2
= gen_new_label();
8932 tcg_gen_brcondi_i32(TCG_COND_GE
, arg1
, 0, l1
);
8933 tcg_gen_neg_i32(ret
, arg1
);
8936 tcg_gen_mov_i32(ret
, arg1
);
8939 GEN_SPEOP_ARITH1(evabs
, gen_op_evabs
);
8940 GEN_SPEOP_ARITH1(evneg
, tcg_gen_neg_i32
);
8941 GEN_SPEOP_ARITH1(evextsb
, tcg_gen_ext8s_i32
);
8942 GEN_SPEOP_ARITH1(evextsh
, tcg_gen_ext16s_i32
);
8943 static inline void gen_op_evrndw(TCGv_i32 ret
, TCGv_i32 arg1
)
8945 tcg_gen_addi_i32(ret
, arg1
, 0x8000);
8946 tcg_gen_ext16u_i32(ret
, ret
);
8948 GEN_SPEOP_ARITH1(evrndw
, gen_op_evrndw
);
8949 GEN_SPEOP_ARITH1(evcntlsw
, gen_helper_cntlsw32
);
8950 GEN_SPEOP_ARITH1(evcntlzw
, gen_helper_cntlzw32
);
8952 #define GEN_SPEOP_ARITH2(name, tcg_op) \
8953 static inline void gen_##name(DisasContext *ctx) \
8956 if (unlikely(!ctx->spe_enabled)) { \
8957 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8960 t0 = tcg_temp_new_i32(); \
8961 t1 = tcg_temp_new_i32(); \
8963 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8964 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8965 tcg_op(t0, t0, t1); \
8966 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
8968 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rA(ctx->opcode)]); \
8969 tcg_gen_trunc_tl_i32(t1, cpu_gprh[rB(ctx->opcode)]); \
8970 tcg_op(t0, t0, t1); \
8971 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
8973 tcg_temp_free_i32(t0); \
8974 tcg_temp_free_i32(t1); \
8977 static inline void gen_op_evsrwu(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
8979 TCGLabel
*l1
= gen_new_label();
8980 TCGLabel
*l2
= gen_new_label();
8981 TCGv_i32 t0
= tcg_temp_local_new_i32();
8983 /* No error here: 6 bits are used */
8984 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
8985 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
8986 tcg_gen_shr_i32(ret
, arg1
, t0
);
8989 tcg_gen_movi_i32(ret
, 0);
8991 tcg_temp_free_i32(t0
);
8993 GEN_SPEOP_ARITH2(evsrwu
, gen_op_evsrwu
);
8994 static inline void gen_op_evsrws(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
8996 TCGLabel
*l1
= gen_new_label();
8997 TCGLabel
*l2
= gen_new_label();
8998 TCGv_i32 t0
= tcg_temp_local_new_i32();
9000 /* No error here: 6 bits are used */
9001 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
9002 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
9003 tcg_gen_sar_i32(ret
, arg1
, t0
);
9006 tcg_gen_movi_i32(ret
, 0);
9008 tcg_temp_free_i32(t0
);
9010 GEN_SPEOP_ARITH2(evsrws
, gen_op_evsrws
);
9011 static inline void gen_op_evslw(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
9013 TCGLabel
*l1
= gen_new_label();
9014 TCGLabel
*l2
= gen_new_label();
9015 TCGv_i32 t0
= tcg_temp_local_new_i32();
9017 /* No error here: 6 bits are used */
9018 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
9019 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
9020 tcg_gen_shl_i32(ret
, arg1
, t0
);
9023 tcg_gen_movi_i32(ret
, 0);
9025 tcg_temp_free_i32(t0
);
9027 GEN_SPEOP_ARITH2(evslw
, gen_op_evslw
);
9028 static inline void gen_op_evrlw(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
9030 TCGv_i32 t0
= tcg_temp_new_i32();
9031 tcg_gen_andi_i32(t0
, arg2
, 0x1F);
9032 tcg_gen_rotl_i32(ret
, arg1
, t0
);
9033 tcg_temp_free_i32(t0
);
9035 GEN_SPEOP_ARITH2(evrlw
, gen_op_evrlw
);
9036 static inline void gen_evmergehi(DisasContext
*ctx
)
9038 if (unlikely(!ctx
->spe_enabled
)) {
9039 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9042 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
9043 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
9045 GEN_SPEOP_ARITH2(evaddw
, tcg_gen_add_i32
);
9046 static inline void gen_op_evsubf(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
9048 tcg_gen_sub_i32(ret
, arg2
, arg1
);
9050 GEN_SPEOP_ARITH2(evsubfw
, gen_op_evsubf
);
9052 /* SPE arithmetic immediate */
9053 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
9054 static inline void gen_##name(DisasContext *ctx) \
9057 if (unlikely(!ctx->spe_enabled)) { \
9058 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9061 t0 = tcg_temp_new_i32(); \
9063 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
9064 tcg_op(t0, t0, rA(ctx->opcode)); \
9065 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
9067 tcg_gen_trunc_tl_i32(t0, cpu_gprh[rB(ctx->opcode)]); \
9068 tcg_op(t0, t0, rA(ctx->opcode)); \
9069 tcg_gen_extu_i32_tl(cpu_gprh[rD(ctx->opcode)], t0); \
9071 tcg_temp_free_i32(t0); \
9073 GEN_SPEOP_ARITH_IMM2(evaddiw
, tcg_gen_addi_i32
);
9074 GEN_SPEOP_ARITH_IMM2(evsubifw
, tcg_gen_subi_i32
);
9076 /* SPE comparison */
9077 #define GEN_SPEOP_COMP(name, tcg_cond) \
9078 static inline void gen_##name(DisasContext *ctx) \
9080 if (unlikely(!ctx->spe_enabled)) { \
9081 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9084 TCGLabel *l1 = gen_new_label(); \
9085 TCGLabel *l2 = gen_new_label(); \
9086 TCGLabel *l3 = gen_new_label(); \
9087 TCGLabel *l4 = gen_new_label(); \
9089 tcg_gen_ext32s_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
9090 tcg_gen_ext32s_tl(cpu_gpr[rB(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
9091 tcg_gen_ext32s_tl(cpu_gprh[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
9092 tcg_gen_ext32s_tl(cpu_gprh[rB(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); \
9094 tcg_gen_brcond_tl(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
9095 cpu_gpr[rB(ctx->opcode)], l1); \
9096 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
9098 gen_set_label(l1); \
9099 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
9100 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
9101 gen_set_label(l2); \
9102 tcg_gen_brcond_tl(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
9103 cpu_gprh[rB(ctx->opcode)], l3); \
9104 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
9105 ~(CRF_CH | CRF_CH_AND_CL)); \
9107 gen_set_label(l3); \
9108 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
9109 CRF_CH | CRF_CH_OR_CL); \
9110 gen_set_label(l4); \
9112 GEN_SPEOP_COMP(evcmpgtu
, TCG_COND_GTU
);
9113 GEN_SPEOP_COMP(evcmpgts
, TCG_COND_GT
);
9114 GEN_SPEOP_COMP(evcmpltu
, TCG_COND_LTU
);
9115 GEN_SPEOP_COMP(evcmplts
, TCG_COND_LT
);
9116 GEN_SPEOP_COMP(evcmpeq
, TCG_COND_EQ
);
9119 static inline void gen_brinc(DisasContext
*ctx
)
9121 /* Note: brinc is usable even if SPE is disabled */
9122 gen_helper_brinc(cpu_gpr
[rD(ctx
->opcode
)],
9123 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
9125 static inline void gen_evmergelo(DisasContext
*ctx
)
9127 if (unlikely(!ctx
->spe_enabled
)) {
9128 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9131 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
9132 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
9134 static inline void gen_evmergehilo(DisasContext
*ctx
)
9136 if (unlikely(!ctx
->spe_enabled
)) {
9137 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9140 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
9141 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
9143 static inline void gen_evmergelohi(DisasContext
*ctx
)
9145 if (unlikely(!ctx
->spe_enabled
)) {
9146 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9149 if (rD(ctx
->opcode
) == rA(ctx
->opcode
)) {
9150 TCGv tmp
= tcg_temp_new();
9151 tcg_gen_mov_tl(tmp
, cpu_gpr
[rA(ctx
->opcode
)]);
9152 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
9153 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], tmp
);
9156 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
9157 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
9160 static inline void gen_evsplati(DisasContext
*ctx
)
9162 uint64_t imm
= ((int32_t)(rA(ctx
->opcode
) << 27)) >> 27;
9164 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], imm
);
9165 tcg_gen_movi_tl(cpu_gprh
[rD(ctx
->opcode
)], imm
);
9167 static inline void gen_evsplatfi(DisasContext
*ctx
)
9169 uint64_t imm
= rA(ctx
->opcode
) << 27;
9171 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], imm
);
9172 tcg_gen_movi_tl(cpu_gprh
[rD(ctx
->opcode
)], imm
);
9175 static inline void gen_evsel(DisasContext
*ctx
)
9177 TCGLabel
*l1
= gen_new_label();
9178 TCGLabel
*l2
= gen_new_label();
9179 TCGLabel
*l3
= gen_new_label();
9180 TCGLabel
*l4
= gen_new_label();
9181 TCGv_i32 t0
= tcg_temp_local_new_i32();
9183 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 3);
9184 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
9185 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
9188 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
9190 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 2);
9191 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l3
);
9192 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
9195 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
9197 tcg_temp_free_i32(t0
);
9200 static void gen_evsel0(DisasContext
*ctx
)
9205 static void gen_evsel1(DisasContext
*ctx
)
9210 static void gen_evsel2(DisasContext
*ctx
)
9215 static void gen_evsel3(DisasContext
*ctx
)
9222 static inline void gen_evmwumi(DisasContext
*ctx
)
9226 if (unlikely(!ctx
->spe_enabled
)) {
9227 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9231 t0
= tcg_temp_new_i64();
9232 t1
= tcg_temp_new_i64();
9234 /* t0 := rA; t1 := rB */
9235 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
9236 tcg_gen_ext32u_i64(t0
, t0
);
9237 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
9238 tcg_gen_ext32u_i64(t1
, t1
);
9240 tcg_gen_mul_i64(t0
, t0
, t1
); /* t0 := rA * rB */
9242 gen_store_gpr64(rD(ctx
->opcode
), t0
); /* rD := t0 */
9244 tcg_temp_free_i64(t0
);
9245 tcg_temp_free_i64(t1
);
9248 static inline void gen_evmwumia(DisasContext
*ctx
)
9252 if (unlikely(!ctx
->spe_enabled
)) {
9253 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9257 gen_evmwumi(ctx
); /* rD := rA * rB */
9259 tmp
= tcg_temp_new_i64();
9262 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
9263 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
9264 tcg_temp_free_i64(tmp
);
9267 static inline void gen_evmwumiaa(DisasContext
*ctx
)
9272 if (unlikely(!ctx
->spe_enabled
)) {
9273 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9277 gen_evmwumi(ctx
); /* rD := rA * rB */
9279 acc
= tcg_temp_new_i64();
9280 tmp
= tcg_temp_new_i64();
9283 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
9286 tcg_gen_ld_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
9288 /* acc := tmp + acc */
9289 tcg_gen_add_i64(acc
, acc
, tmp
);
9292 tcg_gen_st_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
9295 gen_store_gpr64(rD(ctx
->opcode
), acc
);
9297 tcg_temp_free_i64(acc
);
9298 tcg_temp_free_i64(tmp
);
9301 static inline void gen_evmwsmi(DisasContext
*ctx
)
9305 if (unlikely(!ctx
->spe_enabled
)) {
9306 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9310 t0
= tcg_temp_new_i64();
9311 t1
= tcg_temp_new_i64();
9313 /* t0 := rA; t1 := rB */
9314 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
9315 tcg_gen_ext32s_i64(t0
, t0
);
9316 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
9317 tcg_gen_ext32s_i64(t1
, t1
);
9319 tcg_gen_mul_i64(t0
, t0
, t1
); /* t0 := rA * rB */
9321 gen_store_gpr64(rD(ctx
->opcode
), t0
); /* rD := t0 */
9323 tcg_temp_free_i64(t0
);
9324 tcg_temp_free_i64(t1
);
9327 static inline void gen_evmwsmia(DisasContext
*ctx
)
9331 gen_evmwsmi(ctx
); /* rD := rA * rB */
9333 tmp
= tcg_temp_new_i64();
9336 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
9337 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
9339 tcg_temp_free_i64(tmp
);
9342 static inline void gen_evmwsmiaa(DisasContext
*ctx
)
9344 TCGv_i64 acc
= tcg_temp_new_i64();
9345 TCGv_i64 tmp
= tcg_temp_new_i64();
9347 gen_evmwsmi(ctx
); /* rD := rA * rB */
9349 acc
= tcg_temp_new_i64();
9350 tmp
= tcg_temp_new_i64();
9353 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
9356 tcg_gen_ld_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
9358 /* acc := tmp + acc */
9359 tcg_gen_add_i64(acc
, acc
, tmp
);
9362 tcg_gen_st_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
9365 gen_store_gpr64(rD(ctx
->opcode
), acc
);
9367 tcg_temp_free_i64(acc
);
9368 tcg_temp_free_i64(tmp
);
9371 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
9372 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
9373 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
9374 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
9375 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
9376 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
9377 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
9378 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE
); //
9379 GEN_SPE(evmra
, speundef
, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE
);
9380 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
); ////
9381 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
9382 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
9383 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
9384 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
9385 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
9386 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
9387 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
); ////
9388 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
9389 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
9390 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE
);
9391 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
9392 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
9393 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE
); //
9394 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE
);
9395 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
9396 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
9397 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE
); ////
9398 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE
); ////
9399 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE
); ////
9401 /* SPE load and stores */
9402 static inline void gen_addr_spe_imm_index(DisasContext
*ctx
, TCGv EA
, int sh
)
9404 target_ulong uimm
= rB(ctx
->opcode
);
9406 if (rA(ctx
->opcode
) == 0) {
9407 tcg_gen_movi_tl(EA
, uimm
<< sh
);
9409 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], uimm
<< sh
);
9410 if (NARROW_MODE(ctx
)) {
9411 tcg_gen_ext32u_tl(EA
, EA
);
9416 static inline void gen_op_evldd(DisasContext
*ctx
, TCGv addr
)
9418 TCGv_i64 t0
= tcg_temp_new_i64();
9419 gen_qemu_ld64(ctx
, t0
, addr
);
9420 gen_store_gpr64(rD(ctx
->opcode
), t0
);
9421 tcg_temp_free_i64(t0
);
9424 static inline void gen_op_evldw(DisasContext
*ctx
, TCGv addr
)
9426 gen_qemu_ld32u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
9427 gen_addr_add(ctx
, addr
, addr
, 4);
9428 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
9431 static inline void gen_op_evldh(DisasContext
*ctx
, TCGv addr
)
9433 TCGv t0
= tcg_temp_new();
9434 gen_qemu_ld16u(ctx
, t0
, addr
);
9435 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
9436 gen_addr_add(ctx
, addr
, addr
, 2);
9437 gen_qemu_ld16u(ctx
, t0
, addr
);
9438 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
9439 gen_addr_add(ctx
, addr
, addr
, 2);
9440 gen_qemu_ld16u(ctx
, t0
, addr
);
9441 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
9442 gen_addr_add(ctx
, addr
, addr
, 2);
9443 gen_qemu_ld16u(ctx
, t0
, addr
);
9444 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
9448 static inline void gen_op_evlhhesplat(DisasContext
*ctx
, TCGv addr
)
9450 TCGv t0
= tcg_temp_new();
9451 gen_qemu_ld16u(ctx
, t0
, addr
);
9452 tcg_gen_shli_tl(t0
, t0
, 16);
9453 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
9454 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
9458 static inline void gen_op_evlhhousplat(DisasContext
*ctx
, TCGv addr
)
9460 TCGv t0
= tcg_temp_new();
9461 gen_qemu_ld16u(ctx
, t0
, addr
);
9462 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
9463 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
9467 static inline void gen_op_evlhhossplat(DisasContext
*ctx
, TCGv addr
)
9469 TCGv t0
= tcg_temp_new();
9470 gen_qemu_ld16s(ctx
, t0
, addr
);
9471 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
9472 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
9476 static inline void gen_op_evlwhe(DisasContext
*ctx
, TCGv addr
)
9478 TCGv t0
= tcg_temp_new();
9479 gen_qemu_ld16u(ctx
, t0
, addr
);
9480 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
9481 gen_addr_add(ctx
, addr
, addr
, 2);
9482 gen_qemu_ld16u(ctx
, t0
, addr
);
9483 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
9487 static inline void gen_op_evlwhou(DisasContext
*ctx
, TCGv addr
)
9489 gen_qemu_ld16u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
9490 gen_addr_add(ctx
, addr
, addr
, 2);
9491 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
9494 static inline void gen_op_evlwhos(DisasContext
*ctx
, TCGv addr
)
9496 gen_qemu_ld16s(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
9497 gen_addr_add(ctx
, addr
, addr
, 2);
9498 gen_qemu_ld16s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
9501 static inline void gen_op_evlwwsplat(DisasContext
*ctx
, TCGv addr
)
9503 TCGv t0
= tcg_temp_new();
9504 gen_qemu_ld32u(ctx
, t0
, addr
);
9505 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
9506 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
9510 static inline void gen_op_evlwhsplat(DisasContext
*ctx
, TCGv addr
)
9512 TCGv t0
= tcg_temp_new();
9513 gen_qemu_ld16u(ctx
, t0
, addr
);
9514 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
9515 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
9516 gen_addr_add(ctx
, addr
, addr
, 2);
9517 gen_qemu_ld16u(ctx
, t0
, addr
);
9518 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
9519 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
9523 static inline void gen_op_evstdd(DisasContext
*ctx
, TCGv addr
)
9525 TCGv_i64 t0
= tcg_temp_new_i64();
9526 gen_load_gpr64(t0
, rS(ctx
->opcode
));
9527 gen_qemu_st64(ctx
, t0
, addr
);
9528 tcg_temp_free_i64(t0
);
9531 static inline void gen_op_evstdw(DisasContext
*ctx
, TCGv addr
)
9533 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
9534 gen_addr_add(ctx
, addr
, addr
, 4);
9535 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
9538 static inline void gen_op_evstdh(DisasContext
*ctx
, TCGv addr
)
9540 TCGv t0
= tcg_temp_new();
9541 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
9542 gen_qemu_st16(ctx
, t0
, addr
);
9543 gen_addr_add(ctx
, addr
, addr
, 2);
9544 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
9545 gen_addr_add(ctx
, addr
, addr
, 2);
9546 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
9547 gen_qemu_st16(ctx
, t0
, addr
);
9549 gen_addr_add(ctx
, addr
, addr
, 2);
9550 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
9553 static inline void gen_op_evstwhe(DisasContext
*ctx
, TCGv addr
)
9555 TCGv t0
= tcg_temp_new();
9556 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
9557 gen_qemu_st16(ctx
, t0
, addr
);
9558 gen_addr_add(ctx
, addr
, addr
, 2);
9559 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
9560 gen_qemu_st16(ctx
, t0
, addr
);
9564 static inline void gen_op_evstwho(DisasContext
*ctx
, TCGv addr
)
9566 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
9567 gen_addr_add(ctx
, addr
, addr
, 2);
9568 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
9571 static inline void gen_op_evstwwe(DisasContext
*ctx
, TCGv addr
)
9573 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
9576 static inline void gen_op_evstwwo(DisasContext
*ctx
, TCGv addr
)
9578 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
9581 #define GEN_SPEOP_LDST(name, opc2, sh) \
9582 static void glue(gen_, name)(DisasContext *ctx) \
9585 if (unlikely(!ctx->spe_enabled)) { \
9586 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9589 gen_set_access_type(ctx, ACCESS_INT); \
9590 t0 = tcg_temp_new(); \
9591 if (Rc(ctx->opcode)) { \
9592 gen_addr_spe_imm_index(ctx, t0, sh); \
9594 gen_addr_reg_index(ctx, t0); \
9596 gen_op_##name(ctx, t0); \
9597 tcg_temp_free(t0); \
9600 GEN_SPEOP_LDST(evldd
, 0x00, 3);
9601 GEN_SPEOP_LDST(evldw
, 0x01, 3);
9602 GEN_SPEOP_LDST(evldh
, 0x02, 3);
9603 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1);
9604 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1);
9605 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1);
9606 GEN_SPEOP_LDST(evlwhe
, 0x08, 2);
9607 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2);
9608 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2);
9609 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2);
9610 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2);
9612 GEN_SPEOP_LDST(evstdd
, 0x10, 3);
9613 GEN_SPEOP_LDST(evstdw
, 0x11, 3);
9614 GEN_SPEOP_LDST(evstdh
, 0x12, 3);
9615 GEN_SPEOP_LDST(evstwhe
, 0x18, 2);
9616 GEN_SPEOP_LDST(evstwho
, 0x1A, 2);
9617 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2);
9618 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2);
9620 /* Multiply and add - TODO */
9622 GEN_SPE(speundef
, evmhessf
, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);//
9623 GEN_SPE(speundef
, evmhossf
, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9624 GEN_SPE(evmheumi
, evmhesmi
, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
9625 GEN_SPE(speundef
, evmhesmf
, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9626 GEN_SPE(evmhoumi
, evmhosmi
, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
9627 GEN_SPE(speundef
, evmhosmf
, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9628 GEN_SPE(speundef
, evmhessfa
, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9629 GEN_SPE(speundef
, evmhossfa
, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9630 GEN_SPE(evmheumia
, evmhesmia
, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
9631 GEN_SPE(speundef
, evmhesmfa
, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9632 GEN_SPE(evmhoumia
, evmhosmia
, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
9633 GEN_SPE(speundef
, evmhosmfa
, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9635 GEN_SPE(speundef
, evmwhssf
, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9636 GEN_SPE(evmwlumi
, speundef
, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
9637 GEN_SPE(evmwhumi
, evmwhsmi
, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
9638 GEN_SPE(speundef
, evmwhsmf
, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9639 GEN_SPE(speundef
, evmwssf
, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9640 GEN_SPE(speundef
, evmwsmf
, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9641 GEN_SPE(speundef
, evmwhssfa
, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9642 GEN_SPE(evmwlumia
, speundef
, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
9643 GEN_SPE(evmwhumia
, evmwhsmia
, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
9644 GEN_SPE(speundef
, evmwhsmfa
, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9645 GEN_SPE(speundef
, evmwssfa
, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9646 GEN_SPE(speundef
, evmwsmfa
, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9648 GEN_SPE(evadduiaaw
, evaddsiaaw
, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
9649 GEN_SPE(evsubfusiaaw
, evsubfssiaaw
, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
9650 GEN_SPE(evaddumiaaw
, evaddsmiaaw
, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
9651 GEN_SPE(evsubfumiaaw
, evsubfsmiaaw
, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
9652 GEN_SPE(evdivws
, evdivwu
, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE
);
9654 GEN_SPE(evmheusiaaw
, evmhessiaaw
, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9655 GEN_SPE(speundef
, evmhessfaaw
, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9656 GEN_SPE(evmhousiaaw
, evmhossiaaw
, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9657 GEN_SPE(speundef
, evmhossfaaw
, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9658 GEN_SPE(evmheumiaaw
, evmhesmiaaw
, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9659 GEN_SPE(speundef
, evmhesmfaaw
, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9660 GEN_SPE(evmhoumiaaw
, evmhosmiaaw
, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9661 GEN_SPE(speundef
, evmhosmfaaw
, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9662 GEN_SPE(evmhegumiaa
, evmhegsmiaa
, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9663 GEN_SPE(speundef
, evmhegsmfaa
, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9664 GEN_SPE(evmhogumiaa
, evmhogsmiaa
, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
9665 GEN_SPE(speundef
, evmhogsmfaa
, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9667 GEN_SPE(evmwlusiaaw
, evmwlssiaaw
, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
9668 GEN_SPE(evmwlumiaaw
, evmwlsmiaaw
, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
9669 GEN_SPE(speundef
, evmwssfaa
, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9670 GEN_SPE(speundef
, evmwsmfaa
, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9672 GEN_SPE(evmheusianw
, evmhessianw
, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9673 GEN_SPE(speundef
, evmhessfanw
, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9674 GEN_SPE(evmhousianw
, evmhossianw
, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9675 GEN_SPE(speundef
, evmhossfanw
, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9676 GEN_SPE(evmheumianw
, evmhesmianw
, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9677 GEN_SPE(speundef
, evmhesmfanw
, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9678 GEN_SPE(evmhoumianw
, evmhosmianw
, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9679 GEN_SPE(speundef
, evmhosmfanw
, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9680 GEN_SPE(evmhegumian
, evmhegsmian
, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9681 GEN_SPE(speundef
, evmhegsmfan
, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9682 GEN_SPE(evmhigumian
, evmhigsmian
, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
9683 GEN_SPE(speundef
, evmhogsmfan
, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9685 GEN_SPE(evmwlusianw
, evmwlssianw
, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
9686 GEN_SPE(evmwlumianw
, evmwlsmianw
, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
9687 GEN_SPE(speundef
, evmwssfan
, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9688 GEN_SPE(evmwumian
, evmwsmian
, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
9689 GEN_SPE(speundef
, evmwsmfan
, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
9692 /*** SPE floating-point extension ***/
9693 #define GEN_SPEFPUOP_CONV_32_32(name) \
9694 static inline void gen_##name(DisasContext *ctx) \
9696 TCGv_i32 t0 = tcg_temp_new_i32(); \
9697 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
9698 gen_helper_##name(t0, cpu_env, t0); \
9699 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
9700 tcg_temp_free_i32(t0); \
9702 #define GEN_SPEFPUOP_CONV_32_64(name) \
9703 static inline void gen_##name(DisasContext *ctx) \
9705 TCGv_i64 t0 = tcg_temp_new_i64(); \
9706 TCGv_i32 t1 = tcg_temp_new_i32(); \
9707 gen_load_gpr64(t0, rB(ctx->opcode)); \
9708 gen_helper_##name(t1, cpu_env, t0); \
9709 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1); \
9710 tcg_temp_free_i64(t0); \
9711 tcg_temp_free_i32(t1); \
9713 #define GEN_SPEFPUOP_CONV_64_32(name) \
9714 static inline void gen_##name(DisasContext *ctx) \
9716 TCGv_i64 t0 = tcg_temp_new_i64(); \
9717 TCGv_i32 t1 = tcg_temp_new_i32(); \
9718 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9719 gen_helper_##name(t0, cpu_env, t1); \
9720 gen_store_gpr64(rD(ctx->opcode), t0); \
9721 tcg_temp_free_i64(t0); \
9722 tcg_temp_free_i32(t1); \
9724 #define GEN_SPEFPUOP_CONV_64_64(name) \
9725 static inline void gen_##name(DisasContext *ctx) \
9727 TCGv_i64 t0 = tcg_temp_new_i64(); \
9728 gen_load_gpr64(t0, rB(ctx->opcode)); \
9729 gen_helper_##name(t0, cpu_env, t0); \
9730 gen_store_gpr64(rD(ctx->opcode), t0); \
9731 tcg_temp_free_i64(t0); \
9733 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
9734 static inline void gen_##name(DisasContext *ctx) \
9737 if (unlikely(!ctx->spe_enabled)) { \
9738 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9741 t0 = tcg_temp_new_i32(); \
9742 t1 = tcg_temp_new_i32(); \
9743 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9744 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9745 gen_helper_##name(t0, cpu_env, t0, t1); \
9746 tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); \
9748 tcg_temp_free_i32(t0); \
9749 tcg_temp_free_i32(t1); \
9751 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
9752 static inline void gen_##name(DisasContext *ctx) \
9755 if (unlikely(!ctx->spe_enabled)) { \
9756 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9759 t0 = tcg_temp_new_i64(); \
9760 t1 = tcg_temp_new_i64(); \
9761 gen_load_gpr64(t0, rA(ctx->opcode)); \
9762 gen_load_gpr64(t1, rB(ctx->opcode)); \
9763 gen_helper_##name(t0, cpu_env, t0, t1); \
9764 gen_store_gpr64(rD(ctx->opcode), t0); \
9765 tcg_temp_free_i64(t0); \
9766 tcg_temp_free_i64(t1); \
9768 #define GEN_SPEFPUOP_COMP_32(name) \
9769 static inline void gen_##name(DisasContext *ctx) \
9772 if (unlikely(!ctx->spe_enabled)) { \
9773 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9776 t0 = tcg_temp_new_i32(); \
9777 t1 = tcg_temp_new_i32(); \
9779 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
9780 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
9781 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
9783 tcg_temp_free_i32(t0); \
9784 tcg_temp_free_i32(t1); \
9786 #define GEN_SPEFPUOP_COMP_64(name) \
9787 static inline void gen_##name(DisasContext *ctx) \
9790 if (unlikely(!ctx->spe_enabled)) { \
9791 gen_exception(ctx, POWERPC_EXCP_SPEU); \
9794 t0 = tcg_temp_new_i64(); \
9795 t1 = tcg_temp_new_i64(); \
9796 gen_load_gpr64(t0, rA(ctx->opcode)); \
9797 gen_load_gpr64(t1, rB(ctx->opcode)); \
9798 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
9799 tcg_temp_free_i64(t0); \
9800 tcg_temp_free_i64(t1); \
9803 /* Single precision floating-point vectors operations */
9805 GEN_SPEFPUOP_ARITH2_64_64(evfsadd
);
9806 GEN_SPEFPUOP_ARITH2_64_64(evfssub
);
9807 GEN_SPEFPUOP_ARITH2_64_64(evfsmul
);
9808 GEN_SPEFPUOP_ARITH2_64_64(evfsdiv
);
9809 static inline void gen_evfsabs(DisasContext
*ctx
)
9811 if (unlikely(!ctx
->spe_enabled
)) {
9812 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9815 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
9817 tcg_gen_andi_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)],
9820 static inline void gen_evfsnabs(DisasContext
*ctx
)
9822 if (unlikely(!ctx
->spe_enabled
)) {
9823 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9826 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
9828 tcg_gen_ori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)],
9831 static inline void gen_evfsneg(DisasContext
*ctx
)
9833 if (unlikely(!ctx
->spe_enabled
)) {
9834 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9837 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
9839 tcg_gen_xori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)],
9844 GEN_SPEFPUOP_CONV_64_64(evfscfui
);
9845 GEN_SPEFPUOP_CONV_64_64(evfscfsi
);
9846 GEN_SPEFPUOP_CONV_64_64(evfscfuf
);
9847 GEN_SPEFPUOP_CONV_64_64(evfscfsf
);
9848 GEN_SPEFPUOP_CONV_64_64(evfsctui
);
9849 GEN_SPEFPUOP_CONV_64_64(evfsctsi
);
9850 GEN_SPEFPUOP_CONV_64_64(evfsctuf
);
9851 GEN_SPEFPUOP_CONV_64_64(evfsctsf
);
9852 GEN_SPEFPUOP_CONV_64_64(evfsctuiz
);
9853 GEN_SPEFPUOP_CONV_64_64(evfsctsiz
);
9856 GEN_SPEFPUOP_COMP_64(evfscmpgt
);
9857 GEN_SPEFPUOP_COMP_64(evfscmplt
);
9858 GEN_SPEFPUOP_COMP_64(evfscmpeq
);
9859 GEN_SPEFPUOP_COMP_64(evfststgt
);
9860 GEN_SPEFPUOP_COMP_64(evfststlt
);
9861 GEN_SPEFPUOP_COMP_64(evfststeq
);
9863 /* Opcodes definitions */
9864 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
9865 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
); //
9866 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9867 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
9868 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
9869 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9870 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9871 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9872 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9873 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9874 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9875 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9876 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
9877 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9879 /* Single precision floating-point operations */
9881 GEN_SPEFPUOP_ARITH2_32_32(efsadd
);
9882 GEN_SPEFPUOP_ARITH2_32_32(efssub
);
9883 GEN_SPEFPUOP_ARITH2_32_32(efsmul
);
9884 GEN_SPEFPUOP_ARITH2_32_32(efsdiv
);
9885 static inline void gen_efsabs(DisasContext
*ctx
)
9887 if (unlikely(!ctx
->spe_enabled
)) {
9888 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9891 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], (target_long
)~0x80000000LL
);
9893 static inline void gen_efsnabs(DisasContext
*ctx
)
9895 if (unlikely(!ctx
->spe_enabled
)) {
9896 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9899 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
9901 static inline void gen_efsneg(DisasContext
*ctx
)
9903 if (unlikely(!ctx
->spe_enabled
)) {
9904 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9907 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
9911 GEN_SPEFPUOP_CONV_32_32(efscfui
);
9912 GEN_SPEFPUOP_CONV_32_32(efscfsi
);
9913 GEN_SPEFPUOP_CONV_32_32(efscfuf
);
9914 GEN_SPEFPUOP_CONV_32_32(efscfsf
);
9915 GEN_SPEFPUOP_CONV_32_32(efsctui
);
9916 GEN_SPEFPUOP_CONV_32_32(efsctsi
);
9917 GEN_SPEFPUOP_CONV_32_32(efsctuf
);
9918 GEN_SPEFPUOP_CONV_32_32(efsctsf
);
9919 GEN_SPEFPUOP_CONV_32_32(efsctuiz
);
9920 GEN_SPEFPUOP_CONV_32_32(efsctsiz
);
9921 GEN_SPEFPUOP_CONV_32_64(efscfd
);
9924 GEN_SPEFPUOP_COMP_32(efscmpgt
);
9925 GEN_SPEFPUOP_COMP_32(efscmplt
);
9926 GEN_SPEFPUOP_COMP_32(efscmpeq
);
9927 GEN_SPEFPUOP_COMP_32(efststgt
);
9928 GEN_SPEFPUOP_COMP_32(efststlt
);
9929 GEN_SPEFPUOP_COMP_32(efststeq
);
9931 /* Opcodes definitions */
9932 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
9933 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
); //
9934 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9935 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
9936 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
9937 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE
); //
9938 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9939 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9940 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9941 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
9942 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9943 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9944 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
9945 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
9947 /* Double precision floating-point operations */
9949 GEN_SPEFPUOP_ARITH2_64_64(efdadd
);
9950 GEN_SPEFPUOP_ARITH2_64_64(efdsub
);
9951 GEN_SPEFPUOP_ARITH2_64_64(efdmul
);
9952 GEN_SPEFPUOP_ARITH2_64_64(efddiv
);
9953 static inline void gen_efdabs(DisasContext
*ctx
)
9955 if (unlikely(!ctx
->spe_enabled
)) {
9956 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9959 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
9960 tcg_gen_andi_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)],
9963 static inline void gen_efdnabs(DisasContext
*ctx
)
9965 if (unlikely(!ctx
->spe_enabled
)) {
9966 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9969 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
9970 tcg_gen_ori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)],
9973 static inline void gen_efdneg(DisasContext
*ctx
)
9975 if (unlikely(!ctx
->spe_enabled
)) {
9976 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
9979 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
9980 tcg_gen_xori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)],
9985 GEN_SPEFPUOP_CONV_64_32(efdcfui
);
9986 GEN_SPEFPUOP_CONV_64_32(efdcfsi
);
9987 GEN_SPEFPUOP_CONV_64_32(efdcfuf
);
9988 GEN_SPEFPUOP_CONV_64_32(efdcfsf
);
9989 GEN_SPEFPUOP_CONV_32_64(efdctui
);
9990 GEN_SPEFPUOP_CONV_32_64(efdctsi
);
9991 GEN_SPEFPUOP_CONV_32_64(efdctuf
);
9992 GEN_SPEFPUOP_CONV_32_64(efdctsf
);
9993 GEN_SPEFPUOP_CONV_32_64(efdctuiz
);
9994 GEN_SPEFPUOP_CONV_32_64(efdctsiz
);
9995 GEN_SPEFPUOP_CONV_64_32(efdcfs
);
9996 GEN_SPEFPUOP_CONV_64_64(efdcfuid
);
9997 GEN_SPEFPUOP_CONV_64_64(efdcfsid
);
9998 GEN_SPEFPUOP_CONV_64_64(efdctuidz
);
9999 GEN_SPEFPUOP_CONV_64_64(efdctsidz
);
10002 GEN_SPEFPUOP_COMP_64(efdcmpgt
);
10003 GEN_SPEFPUOP_COMP_64(efdcmplt
);
10004 GEN_SPEFPUOP_COMP_64(efdcmpeq
);
10005 GEN_SPEFPUOP_COMP_64(efdtstgt
);
10006 GEN_SPEFPUOP_COMP_64(efdtstlt
);
10007 GEN_SPEFPUOP_COMP_64(efdtsteq
);
10009 /* Opcodes definitions */
10010 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
); //
10011 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
10012 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE
); //
10013 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
10014 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
); //
10015 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
10016 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
); //
10017 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE
); //
10018 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
10019 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
10020 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
10021 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
10022 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
10023 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
10024 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
); //
10025 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
10027 static void gen_tbegin(DisasContext
*ctx
)
10029 if (unlikely(!ctx
->tm_enabled
)) {
10030 gen_exception_err(ctx
, POWERPC_EXCP_FU
, FSCR_IC_TM
);
10033 gen_helper_tbegin(cpu_env
);
10036 #define GEN_TM_NOOP(name) \
10037 static inline void gen_##name(DisasContext *ctx) \
10039 if (unlikely(!ctx->tm_enabled)) { \
10040 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
10043 /* Because tbegin always fails in QEMU, these user \
10044 * space instructions all have a simple implementation: \
10046 * CR[0] = 0b0 || MSR[TS] || 0b0 \
10047 * = 0b0 || 0b00 || 0b0 \
10049 tcg_gen_movi_i32(cpu_crf[0], 0); \
10053 GEN_TM_NOOP(tabort
);
10054 GEN_TM_NOOP(tabortwc
);
10055 GEN_TM_NOOP(tabortwci
);
10056 GEN_TM_NOOP(tabortdc
);
10057 GEN_TM_NOOP(tabortdci
);
10060 static void gen_tcheck(DisasContext
*ctx
)
10062 if (unlikely(!ctx
->tm_enabled
)) {
10063 gen_exception_err(ctx
, POWERPC_EXCP_FU
, FSCR_IC_TM
);
10066 /* Because tbegin always fails, the tcheck implementation
10069 * CR[CRF] = TDOOMED || MSR[TS] || 0b0
10070 * = 0b1 || 0b00 || 0b0
10072 tcg_gen_movi_i32(cpu_crf
[crfD(ctx
->opcode
)], 0x8);
10075 #if defined(CONFIG_USER_ONLY)
10076 #define GEN_TM_PRIV_NOOP(name) \
10077 static inline void gen_##name(DisasContext *ctx) \
10079 gen_priv_exception(ctx, POWERPC_EXCP_PRIV_OPC); \
10084 #define GEN_TM_PRIV_NOOP(name) \
10085 static inline void gen_##name(DisasContext *ctx) \
10088 if (unlikely(!ctx->tm_enabled)) { \
10089 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
10092 /* Because tbegin always fails, the implementation is \
10095 * CR[0] = 0b0 || MSR[TS] || 0b0 \
10096 * = 0b0 || 0b00 | 0b0 \
10098 tcg_gen_movi_i32(cpu_crf[0], 0); \
10103 GEN_TM_PRIV_NOOP(treclaim
);
10104 GEN_TM_PRIV_NOOP(trechkpt
);
10106 static opcode_t opcodes
[] = {
10107 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
),
10108 GEN_HANDLER(cmp
, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER
),
10109 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
10110 GEN_HANDLER(cmpl
, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER
),
10111 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
10112 #if defined(TARGET_PPC64)
10113 GEN_HANDLER_E(cmpeqb
, 0x1F, 0x00, 0x07, 0x00600000, PPC_NONE
, PPC2_ISA300
),
10115 GEN_HANDLER_E(cmpb
, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE
, PPC2_ISA205
),
10116 GEN_HANDLER_E(cmprb
, 0x1F, 0x00, 0x06, 0x00400001, PPC_NONE
, PPC2_ISA300
),
10117 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
),
10118 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
10119 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
10120 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
10121 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
10122 GEN_HANDLER_E(addpcis
, 0x13, 0x2, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA300
),
10123 GEN_HANDLER(mulhw
, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER
),
10124 GEN_HANDLER(mulhwu
, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER
),
10125 GEN_HANDLER(mullw
, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER
),
10126 GEN_HANDLER(mullwo
, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER
),
10127 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
10128 #if defined(TARGET_PPC64)
10129 GEN_HANDLER(mulld
, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B
),
10131 GEN_HANDLER(neg
, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER
),
10132 GEN_HANDLER(nego
, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER
),
10133 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
10134 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
10135 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
10136 GEN_HANDLER(cntlzw
, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER
),
10137 GEN_HANDLER_E(cnttzw
, 0x1F, 0x1A, 0x10, 0x00000000, PPC_NONE
, PPC2_ISA300
),
10138 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
),
10139 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
),
10140 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
10141 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
10142 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
10143 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
10144 GEN_HANDLER(popcntb
, 0x1F, 0x1A, 0x03, 0x0000F801, PPC_POPCNTB
),
10145 GEN_HANDLER(popcntw
, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD
),
10146 GEN_HANDLER_E(prtyw
, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
10147 #if defined(TARGET_PPC64)
10148 GEN_HANDLER(popcntd
, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD
),
10149 GEN_HANDLER(cntlzd
, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B
),
10150 GEN_HANDLER_E(cnttzd
, 0x1F, 0x1A, 0x11, 0x00000000, PPC_NONE
, PPC2_ISA300
),
10151 GEN_HANDLER_E(prtyd
, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
10152 GEN_HANDLER_E(bpermd
, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE
, PPC2_PERM_ISA206
),
10154 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
10155 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
10156 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
10157 GEN_HANDLER(slw
, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER
),
10158 GEN_HANDLER(sraw
, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER
),
10159 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
),
10160 GEN_HANDLER(srw
, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER
),
10161 #if defined(TARGET_PPC64)
10162 GEN_HANDLER(sld
, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B
),
10163 GEN_HANDLER(srad
, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B
),
10164 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
),
10165 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
),
10166 GEN_HANDLER(srd
, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B
),
10168 GEN_HANDLER(frsqrtes
, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES
),
10169 GEN_HANDLER(fsqrt
, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
10170 GEN_HANDLER(fsqrts
, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
10171 GEN_HANDLER(fcmpo
, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT
),
10172 GEN_HANDLER(fcmpu
, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT
),
10173 GEN_HANDLER(fabs
, 0x3F, 0x08, 0x08, 0x001F0000, PPC_FLOAT
),
10174 GEN_HANDLER(fmr
, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT
),
10175 GEN_HANDLER(fnabs
, 0x3F, 0x08, 0x04, 0x001F0000, PPC_FLOAT
),
10176 GEN_HANDLER(fneg
, 0x3F, 0x08, 0x01, 0x001F0000, PPC_FLOAT
),
10177 GEN_HANDLER_E(fcpsgn
, 0x3F, 0x08, 0x00, 0x00000000, PPC_NONE
, PPC2_ISA205
),
10178 GEN_HANDLER_E(fmrgew
, 0x3F, 0x06, 0x1E, 0x00000001, PPC_NONE
, PPC2_VSX207
),
10179 GEN_HANDLER_E(fmrgow
, 0x3F, 0x06, 0x1A, 0x00000001, PPC_NONE
, PPC2_VSX207
),
10180 GEN_HANDLER(mcrfs
, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT
),
10181 GEN_HANDLER(mffs
, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT
),
10182 GEN_HANDLER(mtfsb0
, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT
),
10183 GEN_HANDLER(mtfsb1
, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT
),
10184 GEN_HANDLER(mtfsf
, 0x3F, 0x07, 0x16, 0x00000000, PPC_FLOAT
),
10185 GEN_HANDLER(mtfsfi
, 0x3F, 0x06, 0x04, 0x006e0800, PPC_FLOAT
),
10186 #if defined(TARGET_PPC64)
10187 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
),
10188 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
),
10189 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
),
10191 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
10192 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
10193 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
),
10194 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
),
10195 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
),
10196 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
),
10197 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO
),
10198 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
),
10199 GEN_HANDLER_E(lbarx
, 0x1F, 0x14, 0x01, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
10200 GEN_HANDLER_E(lharx
, 0x1F, 0x14, 0x03, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
10201 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES
),
10202 GEN_HANDLER_E(stbcx_
, 0x1F, 0x16, 0x15, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
10203 GEN_HANDLER_E(sthcx_
, 0x1F, 0x16, 0x16, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
10204 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
),
10205 #if defined(TARGET_PPC64)
10206 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B
),
10207 GEN_HANDLER_E(lqarx
, 0x1F, 0x14, 0x08, 0, PPC_NONE
, PPC2_LSQ_ISA207
),
10208 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
),
10209 GEN_HANDLER_E(stqcx_
, 0x1F, 0x16, 0x05, 0, PPC_NONE
, PPC2_LSQ_ISA207
),
10211 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
),
10212 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
),
10213 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
10214 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
10215 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
),
10216 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
),
10217 GEN_HANDLER_E(bctar
, 0x13, 0x10, 0x11, 0, PPC_NONE
, PPC2_BCTAR_ISA207
),
10218 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
),
10219 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
),
10220 #if defined(TARGET_PPC64)
10221 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
),
10222 GEN_HANDLER_E(doze
, 0x13, 0x12, 0x0c, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
10223 GEN_HANDLER_E(nap
, 0x13, 0x12, 0x0d, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
10224 GEN_HANDLER_E(sleep
, 0x13, 0x12, 0x0e, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
10225 GEN_HANDLER_E(rvwinkle
, 0x13, 0x12, 0x0f, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
10226 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
),
10228 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW
),
10229 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
),
10230 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
10231 #if defined(TARGET_PPC64)
10232 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
),
10233 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
),
10235 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
),
10236 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
),
10237 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
),
10238 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
),
10239 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
),
10240 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
),
10241 #if defined(TARGET_PPC64)
10242 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
),
10243 GEN_HANDLER_E(setb
, 0x1F, 0x00, 0x04, 0x0003F801, PPC_NONE
, PPC2_ISA300
),
10245 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001EF801, PPC_MISC
),
10246 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000000, PPC_MISC
),
10247 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
),
10248 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
),
10249 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
),
10250 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE
),
10251 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE
),
10252 GEN_HANDLER_E(dcbtls
, 0x1F, 0x06, 0x05, 0x02000001, PPC_BOOKE
, PPC2_BOOKE206
),
10253 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ
),
10254 GEN_HANDLER(dst
, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC
),
10255 GEN_HANDLER(dstst
, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC
),
10256 GEN_HANDLER(dss
, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC
),
10257 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
),
10258 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
),
10259 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
),
10260 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
),
10261 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
),
10262 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
),
10263 #if defined(TARGET_PPC64)
10264 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
),
10265 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
10267 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
),
10268 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
10270 GEN_HANDLER2(slbmte
, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B
),
10271 GEN_HANDLER2(slbmfee
, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B
),
10272 GEN_HANDLER2(slbmfev
, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B
),
10273 GEN_HANDLER2(slbfee_
, "slbfee.", 0x1F, 0x13, 0x1E, 0x001F0000, PPC_SEGMENT_64B
),
10275 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
),
10276 /* XXX Those instructions will need to be handled differently for
10277 * different ISA versions */
10278 GEN_HANDLER(tlbiel
, 0x1F, 0x12, 0x08, 0x001F0001, PPC_MEM_TLBIE
),
10279 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x001F0001, PPC_MEM_TLBIE
),
10280 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
),
10281 #if defined(TARGET_PPC64)
10282 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x031FFC01, PPC_SLBI
),
10283 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
),
10285 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
),
10286 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
),
10287 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
),
10288 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
),
10289 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
),
10290 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
),
10291 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
),
10292 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
),
10293 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
),
10294 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
),
10295 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
),
10296 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
10297 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
),
10298 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
),
10299 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
),
10300 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
),
10301 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
),
10302 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
),
10303 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
),
10304 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
10305 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
),
10306 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
),
10307 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
),
10308 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
),
10309 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
),
10310 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
),
10311 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
),
10312 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
),
10313 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
),
10314 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
),
10315 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
),
10316 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
),
10317 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
),
10318 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
),
10319 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
),
10320 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
),
10321 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
),
10322 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
),
10323 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
),
10324 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
),
10325 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
),
10326 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
),
10327 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
),
10328 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
),
10329 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
),
10330 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
),
10331 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
),
10332 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
),
10333 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
),
10334 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
10335 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
10336 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
),
10337 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
),
10338 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
10339 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
10340 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
),
10341 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
),
10342 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
),
10343 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
),
10344 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
),
10345 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
),
10346 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
),
10347 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
),
10348 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
),
10349 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
),
10350 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
),
10351 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
),
10352 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
),
10353 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
),
10354 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
),
10355 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
),
10356 GEN_HANDLER_E(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
, PPC2_BOOKE206
),
10357 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
),
10358 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
),
10359 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
),
10360 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
),
10361 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
),
10362 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
),
10363 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
),
10364 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
),
10365 GEN_HANDLER2_E(tlbre_booke206
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
10366 PPC_NONE
, PPC2_BOOKE206
),
10367 GEN_HANDLER2_E(tlbsx_booke206
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
10368 PPC_NONE
, PPC2_BOOKE206
),
10369 GEN_HANDLER2_E(tlbwe_booke206
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
10370 PPC_NONE
, PPC2_BOOKE206
),
10371 GEN_HANDLER2_E(tlbivax_booke206
, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
10372 PPC_NONE
, PPC2_BOOKE206
),
10373 GEN_HANDLER2_E(tlbilx_booke206
, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
10374 PPC_NONE
, PPC2_BOOKE206
),
10375 GEN_HANDLER2_E(msgsnd
, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
10376 PPC_NONE
, PPC2_PRCNTL
),
10377 GEN_HANDLER2_E(msgclr
, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
10378 PPC_NONE
, PPC2_PRCNTL
),
10379 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
),
10380 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE
),
10381 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
),
10382 GEN_HANDLER_E(mbar
, 0x1F, 0x16, 0x1a, 0x001FF801,
10383 PPC_BOOKE
, PPC2_BOOKE206
),
10384 GEN_HANDLER(msync_4xx
, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE
),
10385 GEN_HANDLER2_E(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
10386 PPC_BOOKE
, PPC2_BOOKE206
),
10387 GEN_HANDLER(lvsl
, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC
),
10388 GEN_HANDLER(lvsr
, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC
),
10389 GEN_HANDLER(mfvscr
, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC
),
10390 GEN_HANDLER(mtvscr
, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC
),
10391 GEN_HANDLER(vmladduhm
, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC
),
10392 #if defined(TARGET_PPC64)
10393 GEN_HANDLER_E(maddhd_maddhdu
, 0x04, 0x18, 0xFF, 0x00000000, PPC_NONE
,
10395 GEN_HANDLER_E(maddld
, 0x04, 0x19, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA300
),
10397 GEN_HANDLER2(evsel0
, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE
),
10398 GEN_HANDLER2(evsel1
, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE
),
10399 GEN_HANDLER2(evsel2
, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE
),
10400 GEN_HANDLER2(evsel3
, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE
),
10402 #undef GEN_INT_ARITH_ADD
10403 #undef GEN_INT_ARITH_ADD_CONST
10404 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
10405 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
10406 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
10407 add_ca, compute_ca, compute_ov) \
10408 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
10409 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
10410 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
10411 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
10412 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
10413 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
10414 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
10415 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
10416 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
10417 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
10418 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
10420 #undef GEN_INT_ARITH_DIVW
10421 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
10422 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
10423 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0),
10424 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1),
10425 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0),
10426 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1),
10427 GEN_HANDLER_E(divwe
, 0x1F, 0x0B, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
10428 GEN_HANDLER_E(divweo
, 0x1F, 0x0B, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
10429 GEN_HANDLER_E(divweu
, 0x1F, 0x0B, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
10430 GEN_HANDLER_E(divweuo
, 0x1F, 0x0B, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
10431 GEN_HANDLER_E(modsw
, 0x1F, 0x0B, 0x18, 0x00000001, PPC_NONE
, PPC2_ISA300
),
10432 GEN_HANDLER_E(moduw
, 0x1F, 0x0B, 0x08, 0x00000001, PPC_NONE
, PPC2_ISA300
),
10434 #if defined(TARGET_PPC64)
10435 #undef GEN_INT_ARITH_DIVD
10436 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
10437 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
10438 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0),
10439 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1),
10440 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0),
10441 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1),
10443 GEN_HANDLER_E(divdeu
, 0x1F, 0x09, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
10444 GEN_HANDLER_E(divdeuo
, 0x1F, 0x09, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
10445 GEN_HANDLER_E(divde
, 0x1F, 0x09, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
10446 GEN_HANDLER_E(divdeo
, 0x1F, 0x09, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
10447 GEN_HANDLER_E(modsd
, 0x1F, 0x09, 0x18, 0x00000001, PPC_NONE
, PPC2_ISA300
),
10448 GEN_HANDLER_E(modud
, 0x1F, 0x09, 0x08, 0x00000001, PPC_NONE
, PPC2_ISA300
),
10450 #undef GEN_INT_ARITH_MUL_HELPER
10451 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
10452 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
10453 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00),
10454 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02),
10455 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17),
10458 #undef GEN_INT_ARITH_SUBF
10459 #undef GEN_INT_ARITH_SUBF_CONST
10460 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
10461 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
10462 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
10463 add_ca, compute_ca, compute_ov) \
10464 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
10465 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
10466 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
10467 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
10468 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
10469 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
10470 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
10471 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
10472 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
10473 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
10474 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
10476 #undef GEN_LOGICAL1
10477 #undef GEN_LOGICAL2
10478 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
10479 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
10480 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
10481 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
10482 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
),
10483 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
),
10484 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
),
10485 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
),
10486 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
),
10487 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
),
10488 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
),
10489 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
),
10490 #if defined(TARGET_PPC64)
10491 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
),
10494 #if defined(TARGET_PPC64)
10495 #undef GEN_PPC64_R2
10496 #undef GEN_PPC64_R4
10497 #define GEN_PPC64_R2(name, opc1, opc2) \
10498 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10499 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10501 #define GEN_PPC64_R4(name, opc1, opc2) \
10502 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
10503 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
10505 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
10507 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
10509 GEN_PPC64_R4(rldicl
, 0x1E, 0x00),
10510 GEN_PPC64_R4(rldicr
, 0x1E, 0x02),
10511 GEN_PPC64_R4(rldic
, 0x1E, 0x04),
10512 GEN_PPC64_R2(rldcl
, 0x1E, 0x08),
10513 GEN_PPC64_R2(rldcr
, 0x1E, 0x09),
10514 GEN_PPC64_R4(rldimi
, 0x1E, 0x06),
10517 #undef _GEN_FLOAT_ACB
10518 #undef GEN_FLOAT_ACB
10519 #undef _GEN_FLOAT_AB
10520 #undef GEN_FLOAT_AB
10521 #undef _GEN_FLOAT_AC
10522 #undef GEN_FLOAT_AC
10524 #undef GEN_FLOAT_BS
10525 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
10526 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
10527 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
10528 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
10529 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
10530 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10531 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10532 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
10533 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10534 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10535 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
10536 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
10537 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
10538 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
10539 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
10540 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
10541 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
10542 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
10543 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
10545 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
),
10546 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
),
10547 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
),
10548 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
),
10549 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
),
10550 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
),
10551 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
),
10552 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
),
10553 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
),
10554 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
),
10555 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
),
10556 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
),
10557 GEN_HANDLER_E(ftdiv
, 0x3F, 0x00, 0x04, 1, PPC_NONE
, PPC2_FP_TST_ISA206
),
10558 GEN_HANDLER_E(ftsqrt
, 0x3F, 0x00, 0x05, 1, PPC_NONE
, PPC2_FP_TST_ISA206
),
10559 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
),
10560 GEN_HANDLER_E(fctiwu
, 0x3F, 0x0E, 0x04, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10561 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
),
10562 GEN_HANDLER_E(fctiwuz
, 0x3F, 0x0F, 0x04, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10563 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
),
10564 GEN_HANDLER_E(fcfid
, 0x3F, 0x0E, 0x1A, 0x001F0000, PPC_NONE
, PPC2_FP_CVT_S64
),
10565 GEN_HANDLER_E(fcfids
, 0x3B, 0x0E, 0x1A, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10566 GEN_HANDLER_E(fcfidu
, 0x3F, 0x0E, 0x1E, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10567 GEN_HANDLER_E(fcfidus
, 0x3B, 0x0E, 0x1E, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10568 GEN_HANDLER_E(fctid
, 0x3F, 0x0E, 0x19, 0x001F0000, PPC_NONE
, PPC2_FP_CVT_S64
),
10569 GEN_HANDLER_E(fctidu
, 0x3F, 0x0E, 0x1D, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10570 GEN_HANDLER_E(fctidz
, 0x3F, 0x0F, 0x19, 0x001F0000, PPC_NONE
, PPC2_FP_CVT_S64
),
10571 GEN_HANDLER_E(fctiduz
, 0x3F, 0x0F, 0x1D, 0, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10572 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
),
10573 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
),
10574 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
),
10575 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
),
10582 #define GEN_LD(name, ldop, opc, type) \
10583 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10584 #define GEN_LDU(name, ldop, opc, type) \
10585 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10586 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
10587 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
10588 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2, chk) \
10589 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
10590 #define GEN_LDS(name, ldop, op, type) \
10591 GEN_LD(name, ldop, op | 0x20, type) \
10592 GEN_LDU(name, ldop, op | 0x21, type) \
10593 GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
10594 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
10596 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
)
10597 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
)
10598 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
)
10599 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
)
10600 #if defined(TARGET_PPC64)
10601 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
)
10602 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
)
10603 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
)
10604 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
)
10605 GEN_LDX_E(ldbr
, ld64ur
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
, CHK_NONE
)
10607 /* HV/P7 and later only */
10608 GEN_LDX_HVRM(ldcix
, ld64
, 0x15, 0x1b, PPC_CILDST
)
10609 GEN_LDX_HVRM(lwzcix
, ld32u
, 0x15, 0x18, PPC_CILDST
)
10610 GEN_LDX_HVRM(lhzcix
, ld16u
, 0x15, 0x19, PPC_CILDST
)
10611 GEN_LDX_HVRM(lbzcix
, ld8u
, 0x15, 0x1a, PPC_CILDST
)
10613 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
)
10614 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
)
10621 #define GEN_ST(name, stop, opc, type) \
10622 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10623 #define GEN_STU(name, stop, opc, type) \
10624 GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
10625 #define GEN_STUX(name, stop, opc2, opc3, type) \
10626 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
10627 #define GEN_STX_E(name, stop, opc2, opc3, type, type2, chk) \
10628 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
10629 #define GEN_STS(name, stop, op, type) \
10630 GEN_ST(name, stop, op | 0x20, type) \
10631 GEN_STU(name, stop, op | 0x21, type) \
10632 GEN_STUX(name, stop, 0x17, op | 0x01, type) \
10633 GEN_STX(name, stop, 0x17, op | 0x00, type)
10635 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
)
10636 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
)
10637 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
)
10638 #if defined(TARGET_PPC64)
10639 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
)
10640 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
)
10641 GEN_STX_E(stdbr
, st64r
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
, CHK_NONE
)
10642 GEN_STX_HVRM(stdcix
, st64
, 0x15, 0x1f, PPC_CILDST
)
10643 GEN_STX_HVRM(stwcix
, st32
, 0x15, 0x1c, PPC_CILDST
)
10644 GEN_STX_HVRM(sthcix
, st16
, 0x15, 0x1d, PPC_CILDST
)
10645 GEN_STX_HVRM(stbcix
, st8
, 0x15, 0x1e, PPC_CILDST
)
10647 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
)
10648 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
)
10655 #define GEN_LDF(name, ldop, opc, type) \
10656 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10657 #define GEN_LDUF(name, ldop, opc, type) \
10658 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10659 #define GEN_LDUXF(name, ldop, opc, type) \
10660 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10661 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
10662 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10663 #define GEN_LDFS(name, ldop, op, type) \
10664 GEN_LDF(name, ldop, op | 0x20, type) \
10665 GEN_LDUF(name, ldop, op | 0x21, type) \
10666 GEN_LDUXF(name, ldop, op | 0x01, type) \
10667 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
10669 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
)
10670 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
)
10671 GEN_HANDLER_E(lfiwax
, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE
, PPC2_ISA205
),
10672 GEN_HANDLER_E(lfiwzx
, 0x1f, 0x17, 0x1b, 0x1, PPC_NONE
, PPC2_FP_CVT_ISA206
),
10673 GEN_HANDLER_E(lfdp
, 0x39, 0xFF, 0xFF, 0x00200003, PPC_NONE
, PPC2_ISA205
),
10674 GEN_HANDLER_E(lfdpx
, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE
, PPC2_ISA205
),
10681 #define GEN_STF(name, stop, opc, type) \
10682 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
10683 #define GEN_STUF(name, stop, opc, type) \
10684 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
10685 #define GEN_STUXF(name, stop, opc, type) \
10686 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
10687 #define GEN_STXF(name, stop, opc2, opc3, type) \
10688 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
10689 #define GEN_STFS(name, stop, op, type) \
10690 GEN_STF(name, stop, op | 0x20, type) \
10691 GEN_STUF(name, stop, op | 0x21, type) \
10692 GEN_STUXF(name, stop, op | 0x01, type) \
10693 GEN_STXF(name, stop, 0x17, op | 0x00, type)
10695 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
)
10696 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
)
10697 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
)
10698 GEN_HANDLER_E(stfdp
, 0x3D, 0xFF, 0xFF, 0x00200003, PPC_NONE
, PPC2_ISA205
),
10699 GEN_HANDLER_E(stfdpx
, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE
, PPC2_ISA205
),
10702 #define GEN_CRLOGIC(name, tcg_op, opc) \
10703 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
10704 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08),
10705 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04),
10706 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09),
10707 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07),
10708 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01),
10709 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E),
10710 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D),
10711 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06),
10713 #undef GEN_MAC_HANDLER
10714 #define GEN_MAC_HANDLER(name, opc2, opc3) \
10715 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
10716 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05),
10717 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15),
10718 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07),
10719 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17),
10720 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06),
10721 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16),
10722 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04),
10723 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14),
10724 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01),
10725 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11),
10726 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03),
10727 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13),
10728 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02),
10729 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12),
10730 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00),
10731 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10),
10732 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D),
10733 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D),
10734 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F),
10735 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F),
10736 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C),
10737 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C),
10738 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E),
10739 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E),
10740 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05),
10741 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15),
10742 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07),
10743 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17),
10744 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01),
10745 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11),
10746 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03),
10747 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13),
10748 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D),
10749 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D),
10750 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F),
10751 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F),
10752 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05),
10753 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04),
10754 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01),
10755 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00),
10756 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D),
10757 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C),
10763 #define GEN_VR_LDX(name, opc2, opc3) \
10764 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10765 #define GEN_VR_STX(name, opc2, opc3) \
10766 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10767 #define GEN_VR_LVE(name, opc2, opc3) \
10768 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10769 #define GEN_VR_STVE(name, opc2, opc3) \
10770 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
10771 GEN_VR_LDX(lvx
, 0x07, 0x03),
10772 GEN_VR_LDX(lvxl
, 0x07, 0x0B),
10773 GEN_VR_LVE(bx
, 0x07, 0x00),
10774 GEN_VR_LVE(hx
, 0x07, 0x01),
10775 GEN_VR_LVE(wx
, 0x07, 0x02),
10776 GEN_VR_STX(svx
, 0x07, 0x07),
10777 GEN_VR_STX(svxl
, 0x07, 0x0F),
10778 GEN_VR_STVE(bx
, 0x07, 0x04),
10779 GEN_VR_STVE(hx
, 0x07, 0x05),
10780 GEN_VR_STVE(wx
, 0x07, 0x06),
10782 #undef GEN_VX_LOGICAL
10783 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
10784 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10786 #undef GEN_VX_LOGICAL_207
10787 #define GEN_VX_LOGICAL_207(name, tcg_op, opc2, opc3) \
10788 GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10790 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16),
10791 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17),
10792 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18),
10793 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19),
10794 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20),
10795 GEN_VX_LOGICAL_207(veqv
, tcg_gen_eqv_i64
, 2, 26),
10796 GEN_VX_LOGICAL_207(vnand
, tcg_gen_nand_i64
, 2, 22),
10797 GEN_VX_LOGICAL_207(vorc
, tcg_gen_orc_i64
, 2, 21),
10800 #define GEN_VXFORM(name, opc2, opc3) \
10801 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10803 #undef GEN_VXFORM_207
10804 #define GEN_VXFORM_207(name, opc2, opc3) \
10805 GEN_HANDLER_E(name, 0x04, opc2, opc3, 0x00000000, PPC_NONE, PPC2_ALTIVEC_207)
10807 #undef GEN_VXFORM_DUAL
10808 #define GEN_VXFORM_DUAL(name0, name1, opc2, opc3, type0, type1) \
10809 GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, type0, type1)
10811 #undef GEN_VXRFORM_DUAL
10812 #define GEN_VXRFORM_DUAL(name0, name1, opc2, opc3, tp0, tp1) \
10813 GEN_HANDLER_E(name0##_##name1, 0x4, opc2, opc3, 0x00000000, tp0, tp1), \
10814 GEN_HANDLER_E(name0##_##name1, 0x4, opc2, (opc3 | 0x10), 0x00000000, tp0, tp1),
10816 GEN_VXFORM(vaddubm
, 0, 0),
10817 GEN_VXFORM(vadduhm
, 0, 1),
10818 GEN_VXFORM(vadduwm
, 0, 2),
10819 GEN_VXFORM_207(vaddudm
, 0, 3),
10820 GEN_VXFORM_DUAL(vsububm
, bcdadd
, 0, 16, PPC_ALTIVEC
, PPC_NONE
),
10821 GEN_VXFORM_DUAL(vsubuhm
, bcdsub
, 0, 17, PPC_ALTIVEC
, PPC_NONE
),
10822 GEN_VXFORM(vsubuwm
, 0, 18),
10823 GEN_VXFORM_207(vsubudm
, 0, 19),
10824 GEN_VXFORM(vmaxub
, 1, 0),
10825 GEN_VXFORM(vmaxuh
, 1, 1),
10826 GEN_VXFORM(vmaxuw
, 1, 2),
10827 GEN_VXFORM_207(vmaxud
, 1, 3),
10828 GEN_VXFORM(vmaxsb
, 1, 4),
10829 GEN_VXFORM(vmaxsh
, 1, 5),
10830 GEN_VXFORM(vmaxsw
, 1, 6),
10831 GEN_VXFORM_207(vmaxsd
, 1, 7),
10832 GEN_VXFORM(vminub
, 1, 8),
10833 GEN_VXFORM(vminuh
, 1, 9),
10834 GEN_VXFORM(vminuw
, 1, 10),
10835 GEN_VXFORM_207(vminud
, 1, 11),
10836 GEN_VXFORM(vminsb
, 1, 12),
10837 GEN_VXFORM(vminsh
, 1, 13),
10838 GEN_VXFORM(vminsw
, 1, 14),
10839 GEN_VXFORM_207(vminsd
, 1, 15),
10840 GEN_VXFORM(vavgub
, 1, 16),
10841 GEN_VXFORM(vavguh
, 1, 17),
10842 GEN_VXFORM(vavguw
, 1, 18),
10843 GEN_VXFORM(vavgsb
, 1, 20),
10844 GEN_VXFORM(vavgsh
, 1, 21),
10845 GEN_VXFORM(vavgsw
, 1, 22),
10846 GEN_VXFORM(vmrghb
, 6, 0),
10847 GEN_VXFORM(vmrghh
, 6, 1),
10848 GEN_VXFORM(vmrghw
, 6, 2),
10849 GEN_VXFORM(vmrglb
, 6, 4),
10850 GEN_VXFORM(vmrglh
, 6, 5),
10851 GEN_VXFORM(vmrglw
, 6, 6),
10852 GEN_VXFORM_207(vmrgew
, 6, 30),
10853 GEN_VXFORM_207(vmrgow
, 6, 26),
10854 GEN_VXFORM(vmuloub
, 4, 0),
10855 GEN_VXFORM(vmulouh
, 4, 1),
10856 GEN_VXFORM_DUAL(vmulouw
, vmuluwm
, 4, 2, PPC_ALTIVEC
, PPC_NONE
),
10857 GEN_VXFORM(vmulosb
, 4, 4),
10858 GEN_VXFORM(vmulosh
, 4, 5),
10859 GEN_VXFORM_207(vmulosw
, 4, 6),
10860 GEN_VXFORM(vmuleub
, 4, 8),
10861 GEN_VXFORM(vmuleuh
, 4, 9),
10862 GEN_VXFORM_207(vmuleuw
, 4, 10),
10863 GEN_VXFORM(vmulesb
, 4, 12),
10864 GEN_VXFORM(vmulesh
, 4, 13),
10865 GEN_VXFORM_207(vmulesw
, 4, 14),
10866 GEN_VXFORM(vslb
, 2, 4),
10867 GEN_VXFORM(vslh
, 2, 5),
10868 GEN_VXFORM(vslw
, 2, 6),
10869 GEN_VXFORM_207(vsld
, 2, 23),
10870 GEN_VXFORM(vsrb
, 2, 8),
10871 GEN_VXFORM(vsrh
, 2, 9),
10872 GEN_VXFORM(vsrw
, 2, 10),
10873 GEN_VXFORM_207(vsrd
, 2, 27),
10874 GEN_VXFORM(vsrab
, 2, 12),
10875 GEN_VXFORM(vsrah
, 2, 13),
10876 GEN_VXFORM(vsraw
, 2, 14),
10877 GEN_VXFORM_207(vsrad
, 2, 15),
10878 GEN_VXFORM(vslo
, 6, 16),
10879 GEN_VXFORM(vsro
, 6, 17),
10880 GEN_VXFORM(vaddcuw
, 0, 6),
10881 GEN_VXFORM(vsubcuw
, 0, 22),
10882 GEN_VXFORM(vaddubs
, 0, 8),
10883 GEN_VXFORM(vadduhs
, 0, 9),
10884 GEN_VXFORM(vadduws
, 0, 10),
10885 GEN_VXFORM(vaddsbs
, 0, 12),
10886 GEN_VXFORM(vaddshs
, 0, 13),
10887 GEN_VXFORM(vaddsws
, 0, 14),
10888 GEN_VXFORM_DUAL(vsububs
, bcdadd
, 0, 24, PPC_ALTIVEC
, PPC_NONE
),
10889 GEN_VXFORM_DUAL(vsubuhs
, bcdsub
, 0, 25, PPC_ALTIVEC
, PPC_NONE
),
10890 GEN_VXFORM(vsubuws
, 0, 26),
10891 GEN_VXFORM(vsubsbs
, 0, 28),
10892 GEN_VXFORM(vsubshs
, 0, 29),
10893 GEN_VXFORM(vsubsws
, 0, 30),
10894 GEN_VXFORM_207(vadduqm
, 0, 4),
10895 GEN_VXFORM_207(vaddcuq
, 0, 5),
10896 GEN_VXFORM_DUAL(vaddeuqm
, vaddecuq
, 30, 0xFF, PPC_NONE
, PPC2_ALTIVEC_207
),
10897 GEN_VXFORM_207(vsubuqm
, 0, 20),
10898 GEN_VXFORM_207(vsubcuq
, 0, 21),
10899 GEN_VXFORM_DUAL(vsubeuqm
, vsubecuq
, 31, 0xFF, PPC_NONE
, PPC2_ALTIVEC_207
),
10900 GEN_VXFORM(vrlb
, 2, 0),
10901 GEN_VXFORM(vrlh
, 2, 1),
10902 GEN_VXFORM(vrlw
, 2, 2),
10903 GEN_VXFORM_207(vrld
, 2, 3),
10904 GEN_VXFORM(vsl
, 2, 7),
10905 GEN_VXFORM(vsr
, 2, 11),
10906 GEN_VXFORM(vpkuhum
, 7, 0),
10907 GEN_VXFORM(vpkuwum
, 7, 1),
10908 GEN_VXFORM_207(vpkudum
, 7, 17),
10909 GEN_VXFORM(vpkuhus
, 7, 2),
10910 GEN_VXFORM(vpkuwus
, 7, 3),
10911 GEN_VXFORM_207(vpkudus
, 7, 19),
10912 GEN_VXFORM(vpkshus
, 7, 4),
10913 GEN_VXFORM(vpkswus
, 7, 5),
10914 GEN_VXFORM_207(vpksdus
, 7, 21),
10915 GEN_VXFORM(vpkshss
, 7, 6),
10916 GEN_VXFORM(vpkswss
, 7, 7),
10917 GEN_VXFORM_207(vpksdss
, 7, 23),
10918 GEN_VXFORM(vpkpx
, 7, 12),
10919 GEN_VXFORM(vsum4ubs
, 4, 24),
10920 GEN_VXFORM(vsum4sbs
, 4, 28),
10921 GEN_VXFORM(vsum4shs
, 4, 25),
10922 GEN_VXFORM(vsum2sws
, 4, 26),
10923 GEN_VXFORM(vsumsws
, 4, 30),
10924 GEN_VXFORM(vaddfp
, 5, 0),
10925 GEN_VXFORM(vsubfp
, 5, 1),
10926 GEN_VXFORM(vmaxfp
, 5, 16),
10927 GEN_VXFORM(vminfp
, 5, 17),
10929 #undef GEN_VXRFORM1
10931 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
10932 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
10933 #define GEN_VXRFORM(name, opc2, opc3) \
10934 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
10935 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
10936 GEN_VXRFORM(vcmpequb
, 3, 0)
10937 GEN_VXRFORM(vcmpequh
, 3, 1)
10938 GEN_VXRFORM(vcmpequw
, 3, 2)
10939 GEN_VXRFORM(vcmpgtsb
, 3, 12)
10940 GEN_VXRFORM(vcmpgtsh
, 3, 13)
10941 GEN_VXRFORM(vcmpgtsw
, 3, 14)
10942 GEN_VXRFORM(vcmpgtub
, 3, 8)
10943 GEN_VXRFORM(vcmpgtuh
, 3, 9)
10944 GEN_VXRFORM(vcmpgtuw
, 3, 10)
10945 GEN_VXRFORM_DUAL(vcmpeqfp
, vcmpequd
, 3, 3, PPC_ALTIVEC
, PPC_NONE
)
10946 GEN_VXRFORM(vcmpgefp
, 3, 7)
10947 GEN_VXRFORM_DUAL(vcmpgtfp
, vcmpgtud
, 3, 11, PPC_ALTIVEC
, PPC_NONE
)
10948 GEN_VXRFORM_DUAL(vcmpbfp
, vcmpgtsd
, 3, 15, PPC_ALTIVEC
, PPC_NONE
)
10950 #undef GEN_VXFORM_SIMM
10951 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
10952 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10953 GEN_VXFORM_SIMM(vspltisb
, 6, 12),
10954 GEN_VXFORM_SIMM(vspltish
, 6, 13),
10955 GEN_VXFORM_SIMM(vspltisw
, 6, 14),
10957 #undef GEN_VXFORM_NOA
10958 #define GEN_VXFORM_NOA(name, opc2, opc3) \
10959 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
10960 GEN_VXFORM_NOA(vupkhsb
, 7, 8),
10961 GEN_VXFORM_NOA(vupkhsh
, 7, 9),
10962 GEN_VXFORM_207(vupkhsw
, 7, 25),
10963 GEN_VXFORM_NOA(vupklsb
, 7, 10),
10964 GEN_VXFORM_NOA(vupklsh
, 7, 11),
10965 GEN_VXFORM_207(vupklsw
, 7, 27),
10966 GEN_VXFORM_NOA(vupkhpx
, 7, 13),
10967 GEN_VXFORM_NOA(vupklpx
, 7, 15),
10968 GEN_VXFORM_NOA(vrefp
, 5, 4),
10969 GEN_VXFORM_NOA(vrsqrtefp
, 5, 5),
10970 GEN_VXFORM_NOA(vexptefp
, 5, 6),
10971 GEN_VXFORM_NOA(vlogefp
, 5, 7),
10972 GEN_VXFORM_NOA(vrfim
, 5, 11),
10973 GEN_VXFORM_NOA(vrfin
, 5, 8),
10974 GEN_VXFORM_NOA(vrfip
, 5, 10),
10975 GEN_VXFORM_NOA(vrfiz
, 5, 9),
10977 #undef GEN_VXFORM_UIMM
10978 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
10979 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
10980 GEN_VXFORM_UIMM(vspltb
, 6, 8),
10981 GEN_VXFORM_UIMM(vsplth
, 6, 9),
10982 GEN_VXFORM_UIMM(vspltw
, 6, 10),
10983 GEN_VXFORM_UIMM(vcfux
, 5, 12),
10984 GEN_VXFORM_UIMM(vcfsx
, 5, 13),
10985 GEN_VXFORM_UIMM(vctuxs
, 5, 14),
10986 GEN_VXFORM_UIMM(vctsxs
, 5, 15),
10988 #undef GEN_VAFORM_PAIRED
10989 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
10990 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
10991 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16),
10992 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18),
10993 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19),
10994 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20),
10995 GEN_VAFORM_PAIRED(vsel
, vperm
, 21),
10996 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23),
10998 GEN_VXFORM_DUAL(vclzb
, vpopcntb
, 1, 28, PPC_NONE
, PPC2_ALTIVEC_207
),
10999 GEN_VXFORM_DUAL(vclzh
, vpopcnth
, 1, 29, PPC_NONE
, PPC2_ALTIVEC_207
),
11000 GEN_VXFORM_DUAL(vclzw
, vpopcntw
, 1, 30, PPC_NONE
, PPC2_ALTIVEC_207
),
11001 GEN_VXFORM_DUAL(vclzd
, vpopcntd
, 1, 31, PPC_NONE
, PPC2_ALTIVEC_207
),
11003 GEN_VXFORM_207(vbpermq
, 6, 21),
11004 GEN_VXFORM_207(vgbbd
, 6, 20),
11005 GEN_VXFORM_207(vpmsumb
, 4, 16),
11006 GEN_VXFORM_207(vpmsumh
, 4, 17),
11007 GEN_VXFORM_207(vpmsumw
, 4, 18),
11008 GEN_VXFORM_207(vpmsumd
, 4, 19),
11010 GEN_VXFORM_207(vsbox
, 4, 23),
11012 GEN_VXFORM_DUAL(vcipher
, vcipherlast
, 4, 20, PPC_NONE
, PPC2_ALTIVEC_207
),
11013 GEN_VXFORM_DUAL(vncipher
, vncipherlast
, 4, 21, PPC_NONE
, PPC2_ALTIVEC_207
),
11015 GEN_VXFORM_207(vshasigmaw
, 1, 26),
11016 GEN_VXFORM_207(vshasigmad
, 1, 27),
11018 GEN_VXFORM_DUAL(vsldoi
, vpermxor
, 22, 0xFF, PPC_ALTIVEC
, PPC_NONE
),
11020 GEN_HANDLER_E(lxsdx
, 0x1F, 0x0C, 0x12, 0, PPC_NONE
, PPC2_VSX
),
11021 GEN_HANDLER_E(lxsiwax
, 0x1F, 0x0C, 0x02, 0, PPC_NONE
, PPC2_VSX207
),
11022 GEN_HANDLER_E(lxsiwzx
, 0x1F, 0x0C, 0x00, 0, PPC_NONE
, PPC2_VSX207
),
11023 GEN_HANDLER_E(lxsspx
, 0x1F, 0x0C, 0x10, 0, PPC_NONE
, PPC2_VSX207
),
11024 GEN_HANDLER_E(lxvd2x
, 0x1F, 0x0C, 0x1A, 0, PPC_NONE
, PPC2_VSX
),
11025 GEN_HANDLER_E(lxvdsx
, 0x1F, 0x0C, 0x0A, 0, PPC_NONE
, PPC2_VSX
),
11026 GEN_HANDLER_E(lxvw4x
, 0x1F, 0x0C, 0x18, 0, PPC_NONE
, PPC2_VSX
),
11028 GEN_HANDLER_E(stxsdx
, 0x1F, 0xC, 0x16, 0, PPC_NONE
, PPC2_VSX
),
11029 GEN_HANDLER_E(stxsiwx
, 0x1F, 0xC, 0x04, 0, PPC_NONE
, PPC2_VSX207
),
11030 GEN_HANDLER_E(stxsspx
, 0x1F, 0xC, 0x14, 0, PPC_NONE
, PPC2_VSX207
),
11031 GEN_HANDLER_E(stxvd2x
, 0x1F, 0xC, 0x1E, 0, PPC_NONE
, PPC2_VSX
),
11032 GEN_HANDLER_E(stxvw4x
, 0x1F, 0xC, 0x1C, 0, PPC_NONE
, PPC2_VSX
),
11034 GEN_HANDLER_E(mfvsrwz
, 0x1F, 0x13, 0x03, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
11035 GEN_HANDLER_E(mtvsrwa
, 0x1F, 0x13, 0x06, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
11036 GEN_HANDLER_E(mtvsrwz
, 0x1F, 0x13, 0x07, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
11037 #if defined(TARGET_PPC64)
11038 GEN_HANDLER_E(mfvsrd
, 0x1F, 0x13, 0x01, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
11039 GEN_HANDLER_E(mtvsrd
, 0x1F, 0x13, 0x05, 0x0000F800, PPC_NONE
, PPC2_VSX207
),
11043 #define GEN_XX2FORM(name, opc2, opc3, fl2) \
11044 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
11045 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2)
11048 #define GEN_XX3FORM(name, opc2, opc3, fl2) \
11049 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \
11050 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2), \
11051 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 0, PPC_NONE, fl2), \
11052 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 0, PPC_NONE, fl2)
11054 #undef GEN_XX2IFORM
11055 #define GEN_XX2IFORM(name, opc2, opc3, fl2) \
11056 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 1, PPC_NONE, fl2), \
11057 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 1, PPC_NONE, fl2), \
11058 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 1, PPC_NONE, fl2), \
11059 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 1, PPC_NONE, fl2)
11061 #undef GEN_XX3_RC_FORM
11062 #define GEN_XX3_RC_FORM(name, opc2, opc3, fl2) \
11063 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x00, 0, PPC_NONE, fl2), \
11064 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x00, 0, PPC_NONE, fl2), \
11065 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x00, 0, PPC_NONE, fl2), \
11066 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x00, 0, PPC_NONE, fl2), \
11067 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x10, 0, PPC_NONE, fl2), \
11068 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x10, 0, PPC_NONE, fl2), \
11069 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x10, 0, PPC_NONE, fl2), \
11070 GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x10, 0, PPC_NONE, fl2)
11072 #undef GEN_XX3FORM_DM
11073 #define GEN_XX3FORM_DM(name, opc2, opc3) \
11074 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
11075 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
11076 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
11077 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\
11078 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
11079 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
11080 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
11081 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\
11082 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
11083 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
11084 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
11085 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\
11086 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
11087 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
11088 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\
11089 GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x0C, 0, PPC_NONE, PPC2_VSX)
11091 GEN_XX2FORM(xsabsdp
, 0x12, 0x15, PPC2_VSX
),
11092 GEN_XX2FORM(xsnabsdp
, 0x12, 0x16, PPC2_VSX
),
11093 GEN_XX2FORM(xsnegdp
, 0x12, 0x17, PPC2_VSX
),
11094 GEN_XX3FORM(xscpsgndp
, 0x00, 0x16, PPC2_VSX
),
11096 GEN_XX2FORM(xvabsdp
, 0x12, 0x1D, PPC2_VSX
),
11097 GEN_XX2FORM(xvnabsdp
, 0x12, 0x1E, PPC2_VSX
),
11098 GEN_XX2FORM(xvnegdp
, 0x12, 0x1F, PPC2_VSX
),
11099 GEN_XX3FORM(xvcpsgndp
, 0x00, 0x1E, PPC2_VSX
),
11100 GEN_XX2FORM(xvabssp
, 0x12, 0x19, PPC2_VSX
),
11101 GEN_XX2FORM(xvnabssp
, 0x12, 0x1A, PPC2_VSX
),
11102 GEN_XX2FORM(xvnegsp
, 0x12, 0x1B, PPC2_VSX
),
11103 GEN_XX3FORM(xvcpsgnsp
, 0x00, 0x1A, PPC2_VSX
),
11105 GEN_XX3FORM(xsadddp
, 0x00, 0x04, PPC2_VSX
),
11106 GEN_XX3FORM(xssubdp
, 0x00, 0x05, PPC2_VSX
),
11107 GEN_XX3FORM(xsmuldp
, 0x00, 0x06, PPC2_VSX
),
11108 GEN_XX3FORM(xsdivdp
, 0x00, 0x07, PPC2_VSX
),
11109 GEN_XX2FORM(xsredp
, 0x14, 0x05, PPC2_VSX
),
11110 GEN_XX2FORM(xssqrtdp
, 0x16, 0x04, PPC2_VSX
),
11111 GEN_XX2FORM(xsrsqrtedp
, 0x14, 0x04, PPC2_VSX
),
11112 GEN_XX3FORM(xstdivdp
, 0x14, 0x07, PPC2_VSX
),
11113 GEN_XX2FORM(xstsqrtdp
, 0x14, 0x06, PPC2_VSX
),
11114 GEN_XX3FORM(xsmaddadp
, 0x04, 0x04, PPC2_VSX
),
11115 GEN_XX3FORM(xsmaddmdp
, 0x04, 0x05, PPC2_VSX
),
11116 GEN_XX3FORM(xsmsubadp
, 0x04, 0x06, PPC2_VSX
),
11117 GEN_XX3FORM(xsmsubmdp
, 0x04, 0x07, PPC2_VSX
),
11118 GEN_XX3FORM(xsnmaddadp
, 0x04, 0x14, PPC2_VSX
),
11119 GEN_XX3FORM(xsnmaddmdp
, 0x04, 0x15, PPC2_VSX
),
11120 GEN_XX3FORM(xsnmsubadp
, 0x04, 0x16, PPC2_VSX
),
11121 GEN_XX3FORM(xsnmsubmdp
, 0x04, 0x17, PPC2_VSX
),
11122 GEN_XX2IFORM(xscmpodp
, 0x0C, 0x05, PPC2_VSX
),
11123 GEN_XX2IFORM(xscmpudp
, 0x0C, 0x04, PPC2_VSX
),
11124 GEN_XX3FORM(xsmaxdp
, 0x00, 0x14, PPC2_VSX
),
11125 GEN_XX3FORM(xsmindp
, 0x00, 0x15, PPC2_VSX
),
11126 GEN_XX2FORM(xscvdpsp
, 0x12, 0x10, PPC2_VSX
),
11127 GEN_XX2FORM(xscvdpspn
, 0x16, 0x10, PPC2_VSX207
),
11128 GEN_XX2FORM(xscvspdp
, 0x12, 0x14, PPC2_VSX
),
11129 GEN_XX2FORM(xscvspdpn
, 0x16, 0x14, PPC2_VSX207
),
11130 GEN_XX2FORM(xscvdpsxds
, 0x10, 0x15, PPC2_VSX
),
11131 GEN_XX2FORM(xscvdpsxws
, 0x10, 0x05, PPC2_VSX
),
11132 GEN_XX2FORM(xscvdpuxds
, 0x10, 0x14, PPC2_VSX
),
11133 GEN_XX2FORM(xscvdpuxws
, 0x10, 0x04, PPC2_VSX
),
11134 GEN_XX2FORM(xscvsxddp
, 0x10, 0x17, PPC2_VSX
),
11135 GEN_XX2FORM(xscvuxddp
, 0x10, 0x16, PPC2_VSX
),
11136 GEN_XX2FORM(xsrdpi
, 0x12, 0x04, PPC2_VSX
),
11137 GEN_XX2FORM(xsrdpic
, 0x16, 0x06, PPC2_VSX
),
11138 GEN_XX2FORM(xsrdpim
, 0x12, 0x07, PPC2_VSX
),
11139 GEN_XX2FORM(xsrdpip
, 0x12, 0x06, PPC2_VSX
),
11140 GEN_XX2FORM(xsrdpiz
, 0x12, 0x05, PPC2_VSX
),
11142 GEN_XX3FORM(xsaddsp
, 0x00, 0x00, PPC2_VSX207
),
11143 GEN_XX3FORM(xssubsp
, 0x00, 0x01, PPC2_VSX207
),
11144 GEN_XX3FORM(xsmulsp
, 0x00, 0x02, PPC2_VSX207
),
11145 GEN_XX3FORM(xsdivsp
, 0x00, 0x03, PPC2_VSX207
),
11146 GEN_XX2FORM(xsresp
, 0x14, 0x01, PPC2_VSX207
),
11147 GEN_XX2FORM(xsrsp
, 0x12, 0x11, PPC2_VSX207
),
11148 GEN_XX2FORM(xssqrtsp
, 0x16, 0x00, PPC2_VSX207
),
11149 GEN_XX2FORM(xsrsqrtesp
, 0x14, 0x00, PPC2_VSX207
),
11150 GEN_XX3FORM(xsmaddasp
, 0x04, 0x00, PPC2_VSX207
),
11151 GEN_XX3FORM(xsmaddmsp
, 0x04, 0x01, PPC2_VSX207
),
11152 GEN_XX3FORM(xsmsubasp
, 0x04, 0x02, PPC2_VSX207
),
11153 GEN_XX3FORM(xsmsubmsp
, 0x04, 0x03, PPC2_VSX207
),
11154 GEN_XX3FORM(xsnmaddasp
, 0x04, 0x10, PPC2_VSX207
),
11155 GEN_XX3FORM(xsnmaddmsp
, 0x04, 0x11, PPC2_VSX207
),
11156 GEN_XX3FORM(xsnmsubasp
, 0x04, 0x12, PPC2_VSX207
),
11157 GEN_XX3FORM(xsnmsubmsp
, 0x04, 0x13, PPC2_VSX207
),
11158 GEN_XX2FORM(xscvsxdsp
, 0x10, 0x13, PPC2_VSX207
),
11159 GEN_XX2FORM(xscvuxdsp
, 0x10, 0x12, PPC2_VSX207
),
11161 GEN_XX3FORM(xvadddp
, 0x00, 0x0C, PPC2_VSX
),
11162 GEN_XX3FORM(xvsubdp
, 0x00, 0x0D, PPC2_VSX
),
11163 GEN_XX3FORM(xvmuldp
, 0x00, 0x0E, PPC2_VSX
),
11164 GEN_XX3FORM(xvdivdp
, 0x00, 0x0F, PPC2_VSX
),
11165 GEN_XX2FORM(xvredp
, 0x14, 0x0D, PPC2_VSX
),
11166 GEN_XX2FORM(xvsqrtdp
, 0x16, 0x0C, PPC2_VSX
),
11167 GEN_XX2FORM(xvrsqrtedp
, 0x14, 0x0C, PPC2_VSX
),
11168 GEN_XX3FORM(xvtdivdp
, 0x14, 0x0F, PPC2_VSX
),
11169 GEN_XX2FORM(xvtsqrtdp
, 0x14, 0x0E, PPC2_VSX
),
11170 GEN_XX3FORM(xvmaddadp
, 0x04, 0x0C, PPC2_VSX
),
11171 GEN_XX3FORM(xvmaddmdp
, 0x04, 0x0D, PPC2_VSX
),
11172 GEN_XX3FORM(xvmsubadp
, 0x04, 0x0E, PPC2_VSX
),
11173 GEN_XX3FORM(xvmsubmdp
, 0x04, 0x0F, PPC2_VSX
),
11174 GEN_XX3FORM(xvnmaddadp
, 0x04, 0x1C, PPC2_VSX
),
11175 GEN_XX3FORM(xvnmaddmdp
, 0x04, 0x1D, PPC2_VSX
),
11176 GEN_XX3FORM(xvnmsubadp
, 0x04, 0x1E, PPC2_VSX
),
11177 GEN_XX3FORM(xvnmsubmdp
, 0x04, 0x1F, PPC2_VSX
),
11178 GEN_XX3FORM(xvmaxdp
, 0x00, 0x1C, PPC2_VSX
),
11179 GEN_XX3FORM(xvmindp
, 0x00, 0x1D, PPC2_VSX
),
11180 GEN_XX3_RC_FORM(xvcmpeqdp
, 0x0C, 0x0C, PPC2_VSX
),
11181 GEN_XX3_RC_FORM(xvcmpgtdp
, 0x0C, 0x0D, PPC2_VSX
),
11182 GEN_XX3_RC_FORM(xvcmpgedp
, 0x0C, 0x0E, PPC2_VSX
),
11183 GEN_XX2FORM(xvcvdpsp
, 0x12, 0x18, PPC2_VSX
),
11184 GEN_XX2FORM(xvcvdpsxds
, 0x10, 0x1D, PPC2_VSX
),
11185 GEN_XX2FORM(xvcvdpsxws
, 0x10, 0x0D, PPC2_VSX
),
11186 GEN_XX2FORM(xvcvdpuxds
, 0x10, 0x1C, PPC2_VSX
),
11187 GEN_XX2FORM(xvcvdpuxws
, 0x10, 0x0C, PPC2_VSX
),
11188 GEN_XX2FORM(xvcvsxddp
, 0x10, 0x1F, PPC2_VSX
),
11189 GEN_XX2FORM(xvcvuxddp
, 0x10, 0x1E, PPC2_VSX
),
11190 GEN_XX2FORM(xvcvsxwdp
, 0x10, 0x0F, PPC2_VSX
),
11191 GEN_XX2FORM(xvcvuxwdp
, 0x10, 0x0E, PPC2_VSX
),
11192 GEN_XX2FORM(xvrdpi
, 0x12, 0x0C, PPC2_VSX
),
11193 GEN_XX2FORM(xvrdpic
, 0x16, 0x0E, PPC2_VSX
),
11194 GEN_XX2FORM(xvrdpim
, 0x12, 0x0F, PPC2_VSX
),
11195 GEN_XX2FORM(xvrdpip
, 0x12, 0x0E, PPC2_VSX
),
11196 GEN_XX2FORM(xvrdpiz
, 0x12, 0x0D, PPC2_VSX
),
11198 GEN_XX3FORM(xvaddsp
, 0x00, 0x08, PPC2_VSX
),
11199 GEN_XX3FORM(xvsubsp
, 0x00, 0x09, PPC2_VSX
),
11200 GEN_XX3FORM(xvmulsp
, 0x00, 0x0A, PPC2_VSX
),
11201 GEN_XX3FORM(xvdivsp
, 0x00, 0x0B, PPC2_VSX
),
11202 GEN_XX2FORM(xvresp
, 0x14, 0x09, PPC2_VSX
),
11203 GEN_XX2FORM(xvsqrtsp
, 0x16, 0x08, PPC2_VSX
),
11204 GEN_XX2FORM(xvrsqrtesp
, 0x14, 0x08, PPC2_VSX
),
11205 GEN_XX3FORM(xvtdivsp
, 0x14, 0x0B, PPC2_VSX
),
11206 GEN_XX2FORM(xvtsqrtsp
, 0x14, 0x0A, PPC2_VSX
),
11207 GEN_XX3FORM(xvmaddasp
, 0x04, 0x08, PPC2_VSX
),
11208 GEN_XX3FORM(xvmaddmsp
, 0x04, 0x09, PPC2_VSX
),
11209 GEN_XX3FORM(xvmsubasp
, 0x04, 0x0A, PPC2_VSX
),
11210 GEN_XX3FORM(xvmsubmsp
, 0x04, 0x0B, PPC2_VSX
),
11211 GEN_XX3FORM(xvnmaddasp
, 0x04, 0x18, PPC2_VSX
),
11212 GEN_XX3FORM(xvnmaddmsp
, 0x04, 0x19, PPC2_VSX
),
11213 GEN_XX3FORM(xvnmsubasp
, 0x04, 0x1A, PPC2_VSX
),
11214 GEN_XX3FORM(xvnmsubmsp
, 0x04, 0x1B, PPC2_VSX
),
11215 GEN_XX3FORM(xvmaxsp
, 0x00, 0x18, PPC2_VSX
),
11216 GEN_XX3FORM(xvminsp
, 0x00, 0x19, PPC2_VSX
),
11217 GEN_XX3_RC_FORM(xvcmpeqsp
, 0x0C, 0x08, PPC2_VSX
),
11218 GEN_XX3_RC_FORM(xvcmpgtsp
, 0x0C, 0x09, PPC2_VSX
),
11219 GEN_XX3_RC_FORM(xvcmpgesp
, 0x0C, 0x0A, PPC2_VSX
),
11220 GEN_XX2FORM(xvcvspdp
, 0x12, 0x1C, PPC2_VSX
),
11221 GEN_XX2FORM(xvcvspsxds
, 0x10, 0x19, PPC2_VSX
),
11222 GEN_XX2FORM(xvcvspsxws
, 0x10, 0x09, PPC2_VSX
),
11223 GEN_XX2FORM(xvcvspuxds
, 0x10, 0x18, PPC2_VSX
),
11224 GEN_XX2FORM(xvcvspuxws
, 0x10, 0x08, PPC2_VSX
),
11225 GEN_XX2FORM(xvcvsxdsp
, 0x10, 0x1B, PPC2_VSX
),
11226 GEN_XX2FORM(xvcvuxdsp
, 0x10, 0x1A, PPC2_VSX
),
11227 GEN_XX2FORM(xvcvsxwsp
, 0x10, 0x0B, PPC2_VSX
),
11228 GEN_XX2FORM(xvcvuxwsp
, 0x10, 0x0A, PPC2_VSX
),
11229 GEN_XX2FORM(xvrspi
, 0x12, 0x08, PPC2_VSX
),
11230 GEN_XX2FORM(xvrspic
, 0x16, 0x0A, PPC2_VSX
),
11231 GEN_XX2FORM(xvrspim
, 0x12, 0x0B, PPC2_VSX
),
11232 GEN_XX2FORM(xvrspip
, 0x12, 0x0A, PPC2_VSX
),
11233 GEN_XX2FORM(xvrspiz
, 0x12, 0x09, PPC2_VSX
),
11236 #define VSX_LOGICAL(name, opc2, opc3, fl2) \
11237 GEN_XX3FORM(name, opc2, opc3, fl2)
11239 VSX_LOGICAL(xxland
, 0x8, 0x10, PPC2_VSX
),
11240 VSX_LOGICAL(xxlandc
, 0x8, 0x11, PPC2_VSX
),
11241 VSX_LOGICAL(xxlor
, 0x8, 0x12, PPC2_VSX
),
11242 VSX_LOGICAL(xxlxor
, 0x8, 0x13, PPC2_VSX
),
11243 VSX_LOGICAL(xxlnor
, 0x8, 0x14, PPC2_VSX
),
11244 VSX_LOGICAL(xxleqv
, 0x8, 0x17, PPC2_VSX207
),
11245 VSX_LOGICAL(xxlnand
, 0x8, 0x16, PPC2_VSX207
),
11246 VSX_LOGICAL(xxlorc
, 0x8, 0x15, PPC2_VSX207
),
11247 GEN_XX3FORM(xxmrghw
, 0x08, 0x02, PPC2_VSX
),
11248 GEN_XX3FORM(xxmrglw
, 0x08, 0x06, PPC2_VSX
),
11249 GEN_XX2FORM(xxspltw
, 0x08, 0x0A, PPC2_VSX
),
11250 GEN_XX3FORM_DM(xxsldwi
, 0x08, 0x00),
11252 #define GEN_XXSEL_ROW(opc3) \
11253 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x18, opc3, 0, PPC_NONE, PPC2_VSX), \
11254 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x19, opc3, 0, PPC_NONE, PPC2_VSX), \
11255 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1A, opc3, 0, PPC_NONE, PPC2_VSX), \
11256 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1B, opc3, 0, PPC_NONE, PPC2_VSX), \
11257 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1C, opc3, 0, PPC_NONE, PPC2_VSX), \
11258 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1D, opc3, 0, PPC_NONE, PPC2_VSX), \
11259 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1E, opc3, 0, PPC_NONE, PPC2_VSX), \
11260 GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1F, opc3, 0, PPC_NONE, PPC2_VSX), \
11262 GEN_XXSEL_ROW(0x00)
11263 GEN_XXSEL_ROW(0x01)
11264 GEN_XXSEL_ROW(0x02)
11265 GEN_XXSEL_ROW(0x03)
11266 GEN_XXSEL_ROW(0x04)
11267 GEN_XXSEL_ROW(0x05)
11268 GEN_XXSEL_ROW(0x06)
11269 GEN_XXSEL_ROW(0x07)
11270 GEN_XXSEL_ROW(0x08)
11271 GEN_XXSEL_ROW(0x09)
11272 GEN_XXSEL_ROW(0x0A)
11273 GEN_XXSEL_ROW(0x0B)
11274 GEN_XXSEL_ROW(0x0C)
11275 GEN_XXSEL_ROW(0x0D)
11276 GEN_XXSEL_ROW(0x0E)
11277 GEN_XXSEL_ROW(0x0F)
11278 GEN_XXSEL_ROW(0x10)
11279 GEN_XXSEL_ROW(0x11)
11280 GEN_XXSEL_ROW(0x12)
11281 GEN_XXSEL_ROW(0x13)
11282 GEN_XXSEL_ROW(0x14)
11283 GEN_XXSEL_ROW(0x15)
11284 GEN_XXSEL_ROW(0x16)
11285 GEN_XXSEL_ROW(0x17)
11286 GEN_XXSEL_ROW(0x18)
11287 GEN_XXSEL_ROW(0x19)
11288 GEN_XXSEL_ROW(0x1A)
11289 GEN_XXSEL_ROW(0x1B)
11290 GEN_XXSEL_ROW(0x1C)
11291 GEN_XXSEL_ROW(0x1D)
11292 GEN_XXSEL_ROW(0x1E)
11293 GEN_XXSEL_ROW(0x1F)
11295 GEN_XX3FORM_DM(xxpermdi
, 0x08, 0x01),
11297 #undef GEN_DFP_T_A_B_Rc
11298 #undef GEN_DFP_BF_A_B
11299 #undef GEN_DFP_BF_A_DCM
11300 #undef GEN_DFP_T_B_U32_U32_Rc
11301 #undef GEN_DFP_T_A_B_I32_Rc
11302 #undef GEN_DFP_T_B_Rc
11303 #undef GEN_DFP_T_FPR_I32_Rc
11305 #define _GEN_DFP_LONG(name, op1, op2, mask) \
11306 GEN_HANDLER_E(name, 0x3B, op1, op2, mask, PPC_NONE, PPC2_DFP)
11308 #define _GEN_DFP_LONGx2(name, op1, op2, mask) \
11309 GEN_HANDLER_E(name, 0x3B, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
11310 GEN_HANDLER_E(name, 0x3B, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP)
11312 #define _GEN_DFP_LONGx4(name, op1, op2, mask) \
11313 GEN_HANDLER_E(name, 0x3B, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
11314 GEN_HANDLER_E(name, 0x3B, op1, 0x08 | op2, mask, PPC_NONE, PPC2_DFP), \
11315 GEN_HANDLER_E(name, 0x3B, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP), \
11316 GEN_HANDLER_E(name, 0x3B, op1, 0x18 | op2, mask, PPC_NONE, PPC2_DFP)
11318 #define _GEN_DFP_QUAD(name, op1, op2, mask) \
11319 GEN_HANDLER_E(name, 0x3F, op1, op2, mask, PPC_NONE, PPC2_DFP)
11321 #define _GEN_DFP_QUADx2(name, op1, op2, mask) \
11322 GEN_HANDLER_E(name, 0x3F, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
11323 GEN_HANDLER_E(name, 0x3F, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP)
11325 #define _GEN_DFP_QUADx4(name, op1, op2, mask) \
11326 GEN_HANDLER_E(name, 0x3F, op1, 0x00 | op2, mask, PPC_NONE, PPC2_DFP), \
11327 GEN_HANDLER_E(name, 0x3F, op1, 0x08 | op2, mask, PPC_NONE, PPC2_DFP), \
11328 GEN_HANDLER_E(name, 0x3F, op1, 0x10 | op2, mask, PPC_NONE, PPC2_DFP), \
11329 GEN_HANDLER_E(name, 0x3F, op1, 0x18 | op2, mask, PPC_NONE, PPC2_DFP)
11331 #define GEN_DFP_T_A_B_Rc(name, op1, op2) \
11332 _GEN_DFP_LONG(name, op1, op2, 0x00000000)
11334 #define GEN_DFP_Tp_Ap_Bp_Rc(name, op1, op2) \
11335 _GEN_DFP_QUAD(name, op1, op2, 0x00210800)
11337 #define GEN_DFP_Tp_A_Bp_Rc(name, op1, op2) \
11338 _GEN_DFP_QUAD(name, op1, op2, 0x00200800)
11340 #define GEN_DFP_T_B_Rc(name, op1, op2) \
11341 _GEN_DFP_LONG(name, op1, op2, 0x001F0000)
11343 #define GEN_DFP_Tp_Bp_Rc(name, op1, op2) \
11344 _GEN_DFP_QUAD(name, op1, op2, 0x003F0800)
11346 #define GEN_DFP_Tp_B_Rc(name, op1, op2) \
11347 _GEN_DFP_QUAD(name, op1, op2, 0x003F0000)
11349 #define GEN_DFP_T_Bp_Rc(name, op1, op2) \
11350 _GEN_DFP_QUAD(name, op1, op2, 0x001F0800)
11352 #define GEN_DFP_BF_A_B(name, op1, op2) \
11353 _GEN_DFP_LONG(name, op1, op2, 0x00000001)
11355 #define GEN_DFP_BF_Ap_Bp(name, op1, op2) \
11356 _GEN_DFP_QUAD(name, op1, op2, 0x00610801)
11358 #define GEN_DFP_BF_A_Bp(name, op1, op2) \
11359 _GEN_DFP_QUAD(name, op1, op2, 0x00600801)
11361 #define GEN_DFP_BF_A_DCM(name, op1, op2) \
11362 _GEN_DFP_LONGx2(name, op1, op2, 0x00600001)
11364 #define GEN_DFP_BF_Ap_DCM(name, op1, op2) \
11365 _GEN_DFP_QUADx2(name, op1, op2, 0x00610001)
11367 #define GEN_DFP_T_A_B_RMC_Rc(name, op1, op2) \
11368 _GEN_DFP_LONGx4(name, op1, op2, 0x00000000)
11370 #define GEN_DFP_Tp_Ap_Bp_RMC_Rc(name, op1, op2) \
11371 _GEN_DFP_QUADx4(name, op1, op2, 0x02010800)
11373 #define GEN_DFP_Tp_A_Bp_RMC_Rc(name, op1, op2) \
11374 _GEN_DFP_QUADx4(name, op1, op2, 0x02000800)
11376 #define GEN_DFP_TE_T_B_RMC_Rc(name, op1, op2) \
11377 _GEN_DFP_LONGx4(name, op1, op2, 0x00000000)
11379 #define GEN_DFP_TE_Tp_Bp_RMC_Rc(name, op1, op2) \
11380 _GEN_DFP_QUADx4(name, op1, op2, 0x00200800)
11382 #define GEN_DFP_R_T_B_RMC_Rc(name, op1, op2) \
11383 _GEN_DFP_LONGx4(name, op1, op2, 0x001E0000)
11385 #define GEN_DFP_R_Tp_Bp_RMC_Rc(name, op1, op2) \
11386 _GEN_DFP_QUADx4(name, op1, op2, 0x003E0800)
11388 #define GEN_DFP_SP_T_B_Rc(name, op1, op2) \
11389 _GEN_DFP_LONG(name, op1, op2, 0x00070000)
11391 #define GEN_DFP_SP_Tp_Bp_Rc(name, op1, op2) \
11392 _GEN_DFP_QUAD(name, op1, op2, 0x00270800)
11394 #define GEN_DFP_S_T_B_Rc(name, op1, op2) \
11395 _GEN_DFP_LONG(name, op1, op2, 0x000F0000)
11397 #define GEN_DFP_S_Tp_Bp_Rc(name, op1, op2) \
11398 _GEN_DFP_QUAD(name, op1, op2, 0x002F0800)
11400 #define GEN_DFP_T_A_SH_Rc(name, op1, op2) \
11401 _GEN_DFP_LONGx2(name, op1, op2, 0x00000000)
11403 #define GEN_DFP_Tp_Ap_SH_Rc(name, op1, op2) \
11404 _GEN_DFP_QUADx2(name, op1, op2, 0x00210000)
11406 GEN_DFP_T_A_B_Rc(dadd
, 0x02, 0x00),
11407 GEN_DFP_Tp_Ap_Bp_Rc(daddq
, 0x02, 0x00),
11408 GEN_DFP_T_A_B_Rc(dsub
, 0x02, 0x10),
11409 GEN_DFP_Tp_Ap_Bp_Rc(dsubq
, 0x02, 0x10),
11410 GEN_DFP_T_A_B_Rc(dmul
, 0x02, 0x01),
11411 GEN_DFP_Tp_Ap_Bp_Rc(dmulq
, 0x02, 0x01),
11412 GEN_DFP_T_A_B_Rc(ddiv
, 0x02, 0x11),
11413 GEN_DFP_Tp_Ap_Bp_Rc(ddivq
, 0x02, 0x11),
11414 GEN_DFP_BF_A_B(dcmpu
, 0x02, 0x14),
11415 GEN_DFP_BF_Ap_Bp(dcmpuq
, 0x02, 0x14),
11416 GEN_DFP_BF_A_B(dcmpo
, 0x02, 0x04),
11417 GEN_DFP_BF_Ap_Bp(dcmpoq
, 0x02, 0x04),
11418 GEN_DFP_BF_A_DCM(dtstdc
, 0x02, 0x06),
11419 GEN_DFP_BF_Ap_DCM(dtstdcq
, 0x02, 0x06),
11420 GEN_DFP_BF_A_DCM(dtstdg
, 0x02, 0x07),
11421 GEN_DFP_BF_Ap_DCM(dtstdgq
, 0x02, 0x07),
11422 GEN_DFP_BF_A_B(dtstex
, 0x02, 0x05),
11423 GEN_DFP_BF_Ap_Bp(dtstexq
, 0x02, 0x05),
11424 GEN_DFP_BF_A_B(dtstsf
, 0x02, 0x15),
11425 GEN_DFP_BF_A_Bp(dtstsfq
, 0x02, 0x15),
11426 GEN_DFP_TE_T_B_RMC_Rc(dquai
, 0x03, 0x02),
11427 GEN_DFP_TE_Tp_Bp_RMC_Rc(dquaiq
, 0x03, 0x02),
11428 GEN_DFP_T_A_B_RMC_Rc(dqua
, 0x03, 0x00),
11429 GEN_DFP_Tp_Ap_Bp_RMC_Rc(dquaq
, 0x03, 0x00),
11430 GEN_DFP_T_A_B_RMC_Rc(drrnd
, 0x03, 0x01),
11431 GEN_DFP_Tp_A_Bp_RMC_Rc(drrndq
, 0x03, 0x01),
11432 GEN_DFP_R_T_B_RMC_Rc(drintx
, 0x03, 0x03),
11433 GEN_DFP_R_Tp_Bp_RMC_Rc(drintxq
, 0x03, 0x03),
11434 GEN_DFP_R_T_B_RMC_Rc(drintn
, 0x03, 0x07),
11435 GEN_DFP_R_Tp_Bp_RMC_Rc(drintnq
, 0x03, 0x07),
11436 GEN_DFP_T_B_Rc(dctdp
, 0x02, 0x08),
11437 GEN_DFP_Tp_B_Rc(dctqpq
, 0x02, 0x08),
11438 GEN_DFP_T_B_Rc(drsp
, 0x02, 0x18),
11439 GEN_DFP_Tp_Bp_Rc(drdpq
, 0x02, 0x18),
11440 GEN_DFP_T_B_Rc(dcffix
, 0x02, 0x19),
11441 GEN_DFP_Tp_B_Rc(dcffixq
, 0x02, 0x19),
11442 GEN_DFP_T_B_Rc(dctfix
, 0x02, 0x09),
11443 GEN_DFP_T_Bp_Rc(dctfixq
, 0x02, 0x09),
11444 GEN_DFP_SP_T_B_Rc(ddedpd
, 0x02, 0x0a),
11445 GEN_DFP_SP_Tp_Bp_Rc(ddedpdq
, 0x02, 0x0a),
11446 GEN_DFP_S_T_B_Rc(denbcd
, 0x02, 0x1a),
11447 GEN_DFP_S_Tp_Bp_Rc(denbcdq
, 0x02, 0x1a),
11448 GEN_DFP_T_B_Rc(dxex
, 0x02, 0x0b),
11449 GEN_DFP_T_Bp_Rc(dxexq
, 0x02, 0x0b),
11450 GEN_DFP_T_A_B_Rc(diex
, 0x02, 0x1b),
11451 GEN_DFP_Tp_A_Bp_Rc(diexq
, 0x02, 0x1b),
11452 GEN_DFP_T_A_SH_Rc(dscli
, 0x02, 0x02),
11453 GEN_DFP_Tp_Ap_SH_Rc(dscliq
, 0x02, 0x02),
11454 GEN_DFP_T_A_SH_Rc(dscri
, 0x02, 0x03),
11455 GEN_DFP_Tp_Ap_SH_Rc(dscriq
, 0x02, 0x03),
11458 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
11459 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
11460 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
11461 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
11462 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
11463 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
11464 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
11465 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
11466 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
11467 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE
),
11468 GEN_SPE(evmra
, speundef
, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE
),
11469 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
),
11470 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
11471 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
11472 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
11473 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE
),
11474 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE
),
11475 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE
),
11476 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
),
11477 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
11478 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
11479 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
11480 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
11481 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
11482 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE
),
11483 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE
),
11484 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
11485 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
11486 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE
),
11487 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE
),
11488 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE
),
11490 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
11491 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
),
11492 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11493 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
11494 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
11495 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11496 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11497 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11498 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11499 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11500 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11501 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11502 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
11503 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11505 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
11506 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
),
11507 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11508 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
11509 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
11510 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE
),
11511 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11512 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11513 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11514 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
11515 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11516 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11517 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
11518 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
11520 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
),
11521 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
11522 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE
),
11523 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
11524 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
),
11525 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
11526 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
),
11527 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE
),
11528 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
11529 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
11530 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
11531 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
11532 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
11533 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
11534 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
),
11535 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
11537 #undef GEN_SPEOP_LDST
11538 #define GEN_SPEOP_LDST(name, opc2, sh) \
11539 GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
11540 GEN_SPEOP_LDST(evldd
, 0x00, 3),
11541 GEN_SPEOP_LDST(evldw
, 0x01, 3),
11542 GEN_SPEOP_LDST(evldh
, 0x02, 3),
11543 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1),
11544 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1),
11545 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1),
11546 GEN_SPEOP_LDST(evlwhe
, 0x08, 2),
11547 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2),
11548 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2),
11549 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2),
11550 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2),
11552 GEN_SPEOP_LDST(evstdd
, 0x10, 3),
11553 GEN_SPEOP_LDST(evstdw
, 0x11, 3),
11554 GEN_SPEOP_LDST(evstdh
, 0x12, 3),
11555 GEN_SPEOP_LDST(evstwhe
, 0x18, 2),
11556 GEN_SPEOP_LDST(evstwho
, 0x1A, 2),
11557 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2),
11558 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2),
11560 GEN_HANDLER2_E(tbegin
, "tbegin", 0x1F, 0x0E, 0x14, 0x01DFF800, \
11561 PPC_NONE
, PPC2_TM
),
11562 GEN_HANDLER2_E(tend
, "tend", 0x1F, 0x0E, 0x15, 0x01FFF800, \
11563 PPC_NONE
, PPC2_TM
),
11564 GEN_HANDLER2_E(tabort
, "tabort", 0x1F, 0x0E, 0x1C, 0x03E0F800, \
11565 PPC_NONE
, PPC2_TM
),
11566 GEN_HANDLER2_E(tabortwc
, "tabortwc", 0x1F, 0x0E, 0x18, 0x00000000, \
11567 PPC_NONE
, PPC2_TM
),
11568 GEN_HANDLER2_E(tabortwci
, "tabortwci", 0x1F, 0x0E, 0x1A, 0x00000000, \
11569 PPC_NONE
, PPC2_TM
),
11570 GEN_HANDLER2_E(tabortdc
, "tabortdc", 0x1F, 0x0E, 0x19, 0x00000000, \
11571 PPC_NONE
, PPC2_TM
),
11572 GEN_HANDLER2_E(tabortdci
, "tabortdci", 0x1F, 0x0E, 0x1B, 0x00000000, \
11573 PPC_NONE
, PPC2_TM
),
11574 GEN_HANDLER2_E(tsr
, "tsr", 0x1F, 0x0E, 0x17, 0x03DFF800, \
11575 PPC_NONE
, PPC2_TM
),
11576 GEN_HANDLER2_E(tcheck
, "tcheck", 0x1F, 0x0E, 0x16, 0x007FF800, \
11577 PPC_NONE
, PPC2_TM
),
11578 GEN_HANDLER2_E(treclaim
, "treclaim", 0x1F, 0x0E, 0x1D, 0x03E0F800, \
11579 PPC_NONE
, PPC2_TM
),
11580 GEN_HANDLER2_E(trechkpt
, "trechkpt", 0x1F, 0x0E, 0x1F, 0x03FFF800, \
11581 PPC_NONE
, PPC2_TM
),
11584 #include "helper_regs.h"
11585 #include "translate_init.c"
11587 /*****************************************************************************/
11588 /* Misc PowerPC helpers */
11589 void ppc_cpu_dump_state(CPUState
*cs
, FILE *f
, fprintf_function cpu_fprintf
,
11595 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
11596 CPUPPCState
*env
= &cpu
->env
;
11599 cpu_fprintf(f
, "NIP " TARGET_FMT_lx
" LR " TARGET_FMT_lx
" CTR "
11600 TARGET_FMT_lx
" XER " TARGET_FMT_lx
" CPU#%d\n",
11601 env
->nip
, env
->lr
, env
->ctr
, cpu_read_xer(env
),
11603 cpu_fprintf(f
, "MSR " TARGET_FMT_lx
" HID0 " TARGET_FMT_lx
" HF "
11604 TARGET_FMT_lx
" iidx %d didx %d\n",
11605 env
->msr
, env
->spr
[SPR_HID0
],
11606 env
->hflags
, env
->immu_idx
, env
->dmmu_idx
);
11607 #if !defined(NO_TIMER_DUMP)
11608 cpu_fprintf(f
, "TB %08" PRIu32
" %08" PRIu64
11609 #if !defined(CONFIG_USER_ONLY)
11613 cpu_ppc_load_tbu(env
), cpu_ppc_load_tbl(env
)
11614 #if !defined(CONFIG_USER_ONLY)
11615 , cpu_ppc_load_decr(env
)
11619 for (i
= 0; i
< 32; i
++) {
11620 if ((i
& (RGPL
- 1)) == 0)
11621 cpu_fprintf(f
, "GPR%02d", i
);
11622 cpu_fprintf(f
, " %016" PRIx64
, ppc_dump_gpr(env
, i
));
11623 if ((i
& (RGPL
- 1)) == (RGPL
- 1))
11624 cpu_fprintf(f
, "\n");
11626 cpu_fprintf(f
, "CR ");
11627 for (i
= 0; i
< 8; i
++)
11628 cpu_fprintf(f
, "%01x", env
->crf
[i
]);
11629 cpu_fprintf(f
, " [");
11630 for (i
= 0; i
< 8; i
++) {
11632 if (env
->crf
[i
] & 0x08)
11634 else if (env
->crf
[i
] & 0x04)
11636 else if (env
->crf
[i
] & 0x02)
11638 cpu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
11640 cpu_fprintf(f
, " ] RES " TARGET_FMT_lx
"\n",
11641 env
->reserve_addr
);
11642 for (i
= 0; i
< 32; i
++) {
11643 if ((i
& (RFPL
- 1)) == 0)
11644 cpu_fprintf(f
, "FPR%02d", i
);
11645 cpu_fprintf(f
, " %016" PRIx64
, *((uint64_t *)&env
->fpr
[i
]));
11646 if ((i
& (RFPL
- 1)) == (RFPL
- 1))
11647 cpu_fprintf(f
, "\n");
11649 cpu_fprintf(f
, "FPSCR " TARGET_FMT_lx
"\n", env
->fpscr
);
11650 #if !defined(CONFIG_USER_ONLY)
11651 cpu_fprintf(f
, " SRR0 " TARGET_FMT_lx
" SRR1 " TARGET_FMT_lx
11652 " PVR " TARGET_FMT_lx
" VRSAVE " TARGET_FMT_lx
"\n",
11653 env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
11654 env
->spr
[SPR_PVR
], env
->spr
[SPR_VRSAVE
]);
11656 cpu_fprintf(f
, "SPRG0 " TARGET_FMT_lx
" SPRG1 " TARGET_FMT_lx
11657 " SPRG2 " TARGET_FMT_lx
" SPRG3 " TARGET_FMT_lx
"\n",
11658 env
->spr
[SPR_SPRG0
], env
->spr
[SPR_SPRG1
],
11659 env
->spr
[SPR_SPRG2
], env
->spr
[SPR_SPRG3
]);
11661 cpu_fprintf(f
, "SPRG4 " TARGET_FMT_lx
" SPRG5 " TARGET_FMT_lx
11662 " SPRG6 " TARGET_FMT_lx
" SPRG7 " TARGET_FMT_lx
"\n",
11663 env
->spr
[SPR_SPRG4
], env
->spr
[SPR_SPRG5
],
11664 env
->spr
[SPR_SPRG6
], env
->spr
[SPR_SPRG7
]);
11666 #if defined(TARGET_PPC64)
11667 if (env
->excp_model
== POWERPC_EXCP_POWER7
||
11668 env
->excp_model
== POWERPC_EXCP_POWER8
) {
11669 cpu_fprintf(f
, "HSRR0 " TARGET_FMT_lx
" HSRR1 " TARGET_FMT_lx
"\n",
11670 env
->spr
[SPR_HSRR0
], env
->spr
[SPR_HSRR1
]);
11673 if (env
->excp_model
== POWERPC_EXCP_BOOKE
) {
11674 cpu_fprintf(f
, "CSRR0 " TARGET_FMT_lx
" CSRR1 " TARGET_FMT_lx
11675 " MCSRR0 " TARGET_FMT_lx
" MCSRR1 " TARGET_FMT_lx
"\n",
11676 env
->spr
[SPR_BOOKE_CSRR0
], env
->spr
[SPR_BOOKE_CSRR1
],
11677 env
->spr
[SPR_BOOKE_MCSRR0
], env
->spr
[SPR_BOOKE_MCSRR1
]);
11679 cpu_fprintf(f
, " TCR " TARGET_FMT_lx
" TSR " TARGET_FMT_lx
11680 " ESR " TARGET_FMT_lx
" DEAR " TARGET_FMT_lx
"\n",
11681 env
->spr
[SPR_BOOKE_TCR
], env
->spr
[SPR_BOOKE_TSR
],
11682 env
->spr
[SPR_BOOKE_ESR
], env
->spr
[SPR_BOOKE_DEAR
]);
11684 cpu_fprintf(f
, " PIR " TARGET_FMT_lx
" DECAR " TARGET_FMT_lx
11685 " IVPR " TARGET_FMT_lx
" EPCR " TARGET_FMT_lx
"\n",
11686 env
->spr
[SPR_BOOKE_PIR
], env
->spr
[SPR_BOOKE_DECAR
],
11687 env
->spr
[SPR_BOOKE_IVPR
], env
->spr
[SPR_BOOKE_EPCR
]);
11689 cpu_fprintf(f
, " MCSR " TARGET_FMT_lx
" SPRG8 " TARGET_FMT_lx
11690 " EPR " TARGET_FMT_lx
"\n",
11691 env
->spr
[SPR_BOOKE_MCSR
], env
->spr
[SPR_BOOKE_SPRG8
],
11692 env
->spr
[SPR_BOOKE_EPR
]);
11695 cpu_fprintf(f
, " MCAR " TARGET_FMT_lx
" PID1 " TARGET_FMT_lx
11696 " PID2 " TARGET_FMT_lx
" SVR " TARGET_FMT_lx
"\n",
11697 env
->spr
[SPR_Exxx_MCAR
], env
->spr
[SPR_BOOKE_PID1
],
11698 env
->spr
[SPR_BOOKE_PID2
], env
->spr
[SPR_E500_SVR
]);
11701 * IVORs are left out as they are large and do not change often --
11702 * they can be read with "p $ivor0", "p $ivor1", etc.
11706 #if defined(TARGET_PPC64)
11707 if (env
->flags
& POWERPC_FLAG_CFAR
) {
11708 cpu_fprintf(f
, " CFAR " TARGET_FMT_lx
"\n", env
->cfar
);
11712 switch (env
->mmu_model
) {
11713 case POWERPC_MMU_32B
:
11714 case POWERPC_MMU_601
:
11715 case POWERPC_MMU_SOFT_6xx
:
11716 case POWERPC_MMU_SOFT_74xx
:
11717 #if defined(TARGET_PPC64)
11718 case POWERPC_MMU_64B
:
11719 case POWERPC_MMU_2_03
:
11720 case POWERPC_MMU_2_06
:
11721 case POWERPC_MMU_2_06a
:
11722 case POWERPC_MMU_2_07
:
11723 case POWERPC_MMU_2_07a
:
11725 cpu_fprintf(f
, " SDR1 " TARGET_FMT_lx
" DAR " TARGET_FMT_lx
11726 " DSISR " TARGET_FMT_lx
"\n", env
->spr
[SPR_SDR1
],
11727 env
->spr
[SPR_DAR
], env
->spr
[SPR_DSISR
]);
11729 case POWERPC_MMU_BOOKE206
:
11730 cpu_fprintf(f
, " MAS0 " TARGET_FMT_lx
" MAS1 " TARGET_FMT_lx
11731 " MAS2 " TARGET_FMT_lx
" MAS3 " TARGET_FMT_lx
"\n",
11732 env
->spr
[SPR_BOOKE_MAS0
], env
->spr
[SPR_BOOKE_MAS1
],
11733 env
->spr
[SPR_BOOKE_MAS2
], env
->spr
[SPR_BOOKE_MAS3
]);
11735 cpu_fprintf(f
, " MAS4 " TARGET_FMT_lx
" MAS6 " TARGET_FMT_lx
11736 " MAS7 " TARGET_FMT_lx
" PID " TARGET_FMT_lx
"\n",
11737 env
->spr
[SPR_BOOKE_MAS4
], env
->spr
[SPR_BOOKE_MAS6
],
11738 env
->spr
[SPR_BOOKE_MAS7
], env
->spr
[SPR_BOOKE_PID
]);
11740 cpu_fprintf(f
, "MMUCFG " TARGET_FMT_lx
" TLB0CFG " TARGET_FMT_lx
11741 " TLB1CFG " TARGET_FMT_lx
"\n",
11742 env
->spr
[SPR_MMUCFG
], env
->spr
[SPR_BOOKE_TLB0CFG
],
11743 env
->spr
[SPR_BOOKE_TLB1CFG
]);
11754 void ppc_cpu_dump_statistics(CPUState
*cs
, FILE*f
,
11755 fprintf_function cpu_fprintf
, int flags
)
11757 #if defined(DO_PPC_STATISTICS)
11758 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
11759 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
11762 t1
= cpu
->env
.opcodes
;
11763 for (op1
= 0; op1
< 64; op1
++) {
11765 if (is_indirect_opcode(handler
)) {
11766 t2
= ind_table(handler
);
11767 for (op2
= 0; op2
< 32; op2
++) {
11769 if (is_indirect_opcode(handler
)) {
11770 t3
= ind_table(handler
);
11771 for (op3
= 0; op3
< 32; op3
++) {
11773 if (handler
->count
== 0)
11775 cpu_fprintf(f
, "%02x %02x %02x (%02x %04d) %16s: "
11776 "%016" PRIx64
" %" PRId64
"\n",
11777 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
11779 handler
->count
, handler
->count
);
11782 if (handler
->count
== 0)
11784 cpu_fprintf(f
, "%02x %02x (%02x %04d) %16s: "
11785 "%016" PRIx64
" %" PRId64
"\n",
11786 op1
, op2
, op1
, op2
, handler
->oname
,
11787 handler
->count
, handler
->count
);
11791 if (handler
->count
== 0)
11793 cpu_fprintf(f
, "%02x (%02x ) %16s: %016" PRIx64
11795 op1
, op1
, handler
->oname
,
11796 handler
->count
, handler
->count
);
11802 /*****************************************************************************/
11803 void gen_intermediate_code(CPUPPCState
*env
, struct TranslationBlock
*tb
)
11805 PowerPCCPU
*cpu
= ppc_env_get_cpu(env
);
11806 CPUState
*cs
= CPU(cpu
);
11807 DisasContext ctx
, *ctxp
= &ctx
;
11808 opc_handler_t
**table
, *handler
;
11809 target_ulong pc_start
;
11814 ctx
.nip
= pc_start
;
11816 ctx
.exception
= POWERPC_EXCP_NONE
;
11817 ctx
.spr_cb
= env
->spr_cb
;
11819 ctx
.mem_idx
= env
->dmmu_idx
;
11821 #if !defined(CONFIG_USER_ONLY)
11822 ctx
.hv
= msr_hv
|| !env
->has_hv_mode
;
11824 ctx
.insns_flags
= env
->insns_flags
;
11825 ctx
.insns_flags2
= env
->insns_flags2
;
11826 ctx
.access_type
= -1;
11827 ctx
.le_mode
= !!(env
->hflags
& (1 << MSR_LE
));
11828 ctx
.default_tcg_memop_mask
= ctx
.le_mode
? MO_LE
: MO_BE
;
11829 #if defined(TARGET_PPC64)
11830 ctx
.sf_mode
= msr_is_64bit(env
, env
->msr
);
11831 ctx
.has_cfar
= !!(env
->flags
& POWERPC_FLAG_CFAR
);
11833 if (env
->mmu_model
== POWERPC_MMU_32B
||
11834 env
->mmu_model
== POWERPC_MMU_601
||
11835 (env
->mmu_model
& POWERPC_MMU_64B
))
11836 ctx
.lazy_tlb_flush
= true;
11838 ctx
.fpu_enabled
= !!msr_fp
;
11839 if ((env
->flags
& POWERPC_FLAG_SPE
) && msr_spe
)
11840 ctx
.spe_enabled
= !!msr_spe
;
11842 ctx
.spe_enabled
= false;
11843 if ((env
->flags
& POWERPC_FLAG_VRE
) && msr_vr
)
11844 ctx
.altivec_enabled
= !!msr_vr
;
11846 ctx
.altivec_enabled
= false;
11847 if ((env
->flags
& POWERPC_FLAG_VSX
) && msr_vsx
) {
11848 ctx
.vsx_enabled
= !!msr_vsx
;
11850 ctx
.vsx_enabled
= false;
11852 #if defined(TARGET_PPC64)
11853 if ((env
->flags
& POWERPC_FLAG_TM
) && msr_tm
) {
11854 ctx
.tm_enabled
= !!msr_tm
;
11856 ctx
.tm_enabled
= false;
11859 if ((env
->flags
& POWERPC_FLAG_SE
) && msr_se
)
11860 ctx
.singlestep_enabled
= CPU_SINGLE_STEP
;
11862 ctx
.singlestep_enabled
= 0;
11863 if ((env
->flags
& POWERPC_FLAG_BE
) && msr_be
)
11864 ctx
.singlestep_enabled
|= CPU_BRANCH_STEP
;
11865 if (unlikely(cs
->singlestep_enabled
)) {
11866 ctx
.singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
11868 #if defined (DO_SINGLE_STEP) && 0
11869 /* Single step trace mode */
11873 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
11874 if (max_insns
== 0) {
11875 max_insns
= CF_COUNT_MASK
;
11877 if (max_insns
> TCG_MAX_INSNS
) {
11878 max_insns
= TCG_MAX_INSNS
;
11882 tcg_clear_temp_count();
11883 /* Set env in case of segfault during code fetch */
11884 while (ctx
.exception
== POWERPC_EXCP_NONE
&& !tcg_op_buf_full()) {
11885 tcg_gen_insn_start(ctx
.nip
);
11888 if (unlikely(cpu_breakpoint_test(cs
, ctx
.nip
, BP_ANY
))) {
11889 gen_debug_exception(ctxp
);
11890 /* The address covered by the breakpoint must be included in
11891 [tb->pc, tb->pc + tb->size) in order to for it to be
11892 properly cleared -- thus we increment the PC here so that
11893 the logic setting tb->size below does the right thing. */
11898 LOG_DISAS("----------------\n");
11899 LOG_DISAS("nip=" TARGET_FMT_lx
" super=%d ir=%d\n",
11900 ctx
.nip
, ctx
.mem_idx
, (int)msr_ir
);
11901 if (num_insns
== max_insns
&& (tb
->cflags
& CF_LAST_IO
))
11903 if (unlikely(need_byteswap(&ctx
))) {
11904 ctx
.opcode
= bswap32(cpu_ldl_code(env
, ctx
.nip
));
11906 ctx
.opcode
= cpu_ldl_code(env
, ctx
.nip
);
11908 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
11909 ctx
.opcode
, opc1(ctx
.opcode
), opc2(ctx
.opcode
),
11910 opc3(ctx
.opcode
), ctx
.le_mode
? "little" : "big");
11912 table
= env
->opcodes
;
11913 handler
= table
[opc1(ctx
.opcode
)];
11914 if (is_indirect_opcode(handler
)) {
11915 table
= ind_table(handler
);
11916 handler
= table
[opc2(ctx
.opcode
)];
11917 if (is_indirect_opcode(handler
)) {
11918 table
= ind_table(handler
);
11919 handler
= table
[opc3(ctx
.opcode
)];
11922 /* Is opcode *REALLY* valid ? */
11923 if (unlikely(handler
->handler
== &gen_invalid
)) {
11924 qemu_log_mask(LOG_GUEST_ERROR
, "invalid/unsupported opcode: "
11925 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx
" %d\n",
11926 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
11927 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
11931 if (unlikely(handler
->type
& (PPC_SPE
| PPC_SPE_SINGLE
| PPC_SPE_DOUBLE
) && Rc(ctx
.opcode
))) {
11932 inval
= handler
->inval2
;
11934 inval
= handler
->inval1
;
11937 if (unlikely((ctx
.opcode
& inval
) != 0)) {
11938 qemu_log_mask(LOG_GUEST_ERROR
, "invalid bits: %08x for opcode: "
11939 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx
"\n",
11940 ctx
.opcode
& inval
, opc1(ctx
.opcode
),
11941 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
11942 ctx
.opcode
, ctx
.nip
- 4);
11943 gen_inval_exception(ctxp
, POWERPC_EXCP_INVAL_INVAL
);
11947 (*(handler
->handler
))(&ctx
);
11948 #if defined(DO_PPC_STATISTICS)
11951 /* Check trace mode exceptions */
11952 if (unlikely(ctx
.singlestep_enabled
& CPU_SINGLE_STEP
&&
11953 (ctx
.nip
<= 0x100 || ctx
.nip
> 0xF00) &&
11954 ctx
.exception
!= POWERPC_SYSCALL
&&
11955 ctx
.exception
!= POWERPC_EXCP_TRAP
&&
11956 ctx
.exception
!= POWERPC_EXCP_BRANCH
)) {
11957 gen_exception(ctxp
, POWERPC_EXCP_TRACE
);
11958 } else if (unlikely(((ctx
.nip
& (TARGET_PAGE_SIZE
- 1)) == 0) ||
11959 (cs
->singlestep_enabled
) ||
11961 num_insns
>= max_insns
)) {
11962 /* if we reach a page boundary or are single stepping, stop
11967 if (tcg_check_temp_count()) {
11968 fprintf(stderr
, "Opcode %02x %02x %02x (%08x) leaked temporaries\n",
11969 opc1(ctx
.opcode
), opc2(ctx
.opcode
), opc3(ctx
.opcode
),
11974 if (tb
->cflags
& CF_LAST_IO
)
11976 if (ctx
.exception
== POWERPC_EXCP_NONE
) {
11977 gen_goto_tb(&ctx
, 0, ctx
.nip
);
11978 } else if (ctx
.exception
!= POWERPC_EXCP_BRANCH
) {
11979 if (unlikely(cs
->singlestep_enabled
)) {
11980 gen_debug_exception(ctxp
);
11982 /* Generate the return instruction */
11983 tcg_gen_exit_tb(0);
11985 gen_tb_end(tb
, num_insns
);
11987 tb
->size
= ctx
.nip
- pc_start
;
11988 tb
->icount
= num_insns
;
11990 #if defined(DEBUG_DISAS)
11991 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)
11992 && qemu_log_in_addr_range(pc_start
)) {
11994 flags
= env
->bfd_mach
;
11995 flags
|= ctx
.le_mode
<< 16;
11996 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
11997 log_target_disas(cs
, pc_start
, ctx
.nip
- pc_start
, flags
);
12003 void restore_state_to_opc(CPUPPCState
*env
, TranslationBlock
*tb
,
12004 target_ulong
*data
)
12006 env
->nip
= data
[0];