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/>.
24 #include "host-utils.h"
30 #define CPU_SINGLE_STEP 0x1
31 #define CPU_BRANCH_STEP 0x2
32 #define GDBSTUB_SINGLE_STEP 0x4
34 /* Include definitions for instructions classes and implementations flags */
35 //#define PPC_DEBUG_DISAS
36 //#define DO_PPC_STATISTICS
38 #ifdef PPC_DEBUG_DISAS
39 # define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
41 # define LOG_DISAS(...) do { } while (0)
43 /*****************************************************************************/
44 /* Code translation helpers */
46 /* global register indexes */
47 static TCGv_ptr cpu_env
;
48 static char cpu_reg_names
[10*3 + 22*4 /* GPR */
49 #if !defined(TARGET_PPC64)
50 + 10*4 + 22*5 /* SPE GPRh */
52 + 10*4 + 22*5 /* FPR */
53 + 2*(10*6 + 22*7) /* AVRh, AVRl */
55 static TCGv cpu_gpr
[32];
56 #if !defined(TARGET_PPC64)
57 static TCGv cpu_gprh
[32];
59 static TCGv_i64 cpu_fpr
[32];
60 static TCGv_i64 cpu_avrh
[32], cpu_avrl
[32];
61 static TCGv_i32 cpu_crf
[8];
66 #if defined(TARGET_PPC64)
70 static TCGv cpu_reserve
;
71 static TCGv_i32 cpu_fpscr
;
72 static TCGv_i32 cpu_access_type
;
74 #include "gen-icount.h"
76 void ppc_translate_init(void)
80 size_t cpu_reg_names_size
;
81 static int done_init
= 0;
86 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
89 cpu_reg_names_size
= sizeof(cpu_reg_names
);
91 for (i
= 0; i
< 8; i
++) {
92 snprintf(p
, cpu_reg_names_size
, "crf%d", i
);
93 cpu_crf
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
94 offsetof(CPUPPCState
, crf
[i
]), p
);
96 cpu_reg_names_size
-= 5;
99 for (i
= 0; i
< 32; i
++) {
100 snprintf(p
, cpu_reg_names_size
, "r%d", i
);
101 cpu_gpr
[i
] = tcg_global_mem_new(TCG_AREG0
,
102 offsetof(CPUPPCState
, gpr
[i
]), p
);
103 p
+= (i
< 10) ? 3 : 4;
104 cpu_reg_names_size
-= (i
< 10) ? 3 : 4;
105 #if !defined(TARGET_PPC64)
106 snprintf(p
, cpu_reg_names_size
, "r%dH", i
);
107 cpu_gprh
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
108 offsetof(CPUPPCState
, gprh
[i
]), p
);
109 p
+= (i
< 10) ? 4 : 5;
110 cpu_reg_names_size
-= (i
< 10) ? 4 : 5;
113 snprintf(p
, cpu_reg_names_size
, "fp%d", i
);
114 cpu_fpr
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
115 offsetof(CPUPPCState
, fpr
[i
]), p
);
116 p
+= (i
< 10) ? 4 : 5;
117 cpu_reg_names_size
-= (i
< 10) ? 4 : 5;
119 snprintf(p
, cpu_reg_names_size
, "avr%dH", i
);
120 #ifdef HOST_WORDS_BIGENDIAN
121 cpu_avrh
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
122 offsetof(CPUPPCState
, avr
[i
].u64
[0]), p
);
124 cpu_avrh
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
125 offsetof(CPUPPCState
, avr
[i
].u64
[1]), p
);
127 p
+= (i
< 10) ? 6 : 7;
128 cpu_reg_names_size
-= (i
< 10) ? 6 : 7;
130 snprintf(p
, cpu_reg_names_size
, "avr%dL", i
);
131 #ifdef HOST_WORDS_BIGENDIAN
132 cpu_avrl
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
133 offsetof(CPUPPCState
, avr
[i
].u64
[1]), p
);
135 cpu_avrl
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
136 offsetof(CPUPPCState
, avr
[i
].u64
[0]), p
);
138 p
+= (i
< 10) ? 6 : 7;
139 cpu_reg_names_size
-= (i
< 10) ? 6 : 7;
142 cpu_nip
= tcg_global_mem_new(TCG_AREG0
,
143 offsetof(CPUPPCState
, nip
), "nip");
145 cpu_msr
= tcg_global_mem_new(TCG_AREG0
,
146 offsetof(CPUPPCState
, msr
), "msr");
148 cpu_ctr
= tcg_global_mem_new(TCG_AREG0
,
149 offsetof(CPUPPCState
, ctr
), "ctr");
151 cpu_lr
= tcg_global_mem_new(TCG_AREG0
,
152 offsetof(CPUPPCState
, lr
), "lr");
154 #if defined(TARGET_PPC64)
155 cpu_cfar
= tcg_global_mem_new(TCG_AREG0
,
156 offsetof(CPUPPCState
, cfar
), "cfar");
159 cpu_xer
= tcg_global_mem_new(TCG_AREG0
,
160 offsetof(CPUPPCState
, xer
), "xer");
162 cpu_reserve
= tcg_global_mem_new(TCG_AREG0
,
163 offsetof(CPUPPCState
, reserve_addr
),
166 cpu_fpscr
= tcg_global_mem_new_i32(TCG_AREG0
,
167 offsetof(CPUPPCState
, fpscr
), "fpscr");
169 cpu_access_type
= tcg_global_mem_new_i32(TCG_AREG0
,
170 offsetof(CPUPPCState
, access_type
), "access_type");
172 /* register helpers */
179 /* internal defines */
180 typedef struct DisasContext
{
181 struct TranslationBlock
*tb
;
185 /* Routine used to access memory */
188 /* Translation flags */
190 #if defined(TARGET_PPC64)
197 ppc_spr_t
*spr_cb
; /* Needed to check rights for mfspr/mtspr */
198 int singlestep_enabled
;
201 struct opc_handler_t
{
202 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
204 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
206 /* instruction type */
208 /* extended instruction type */
211 void (*handler
)(DisasContext
*ctx
);
212 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
215 #if defined(DO_PPC_STATISTICS)
220 static inline void gen_reset_fpstatus(void)
222 gen_helper_reset_fpstatus();
225 static inline void gen_compute_fprf(TCGv_i64 arg
, int set_fprf
, int set_rc
)
227 TCGv_i32 t0
= tcg_temp_new_i32();
230 /* This case might be optimized later */
231 tcg_gen_movi_i32(t0
, 1);
232 gen_helper_compute_fprf(t0
, arg
, t0
);
233 if (unlikely(set_rc
)) {
234 tcg_gen_mov_i32(cpu_crf
[1], t0
);
236 gen_helper_float_check_status();
237 } else if (unlikely(set_rc
)) {
238 /* We always need to compute fpcc */
239 tcg_gen_movi_i32(t0
, 0);
240 gen_helper_compute_fprf(t0
, arg
, t0
);
241 tcg_gen_mov_i32(cpu_crf
[1], t0
);
244 tcg_temp_free_i32(t0
);
247 static inline void gen_set_access_type(DisasContext
*ctx
, int access_type
)
249 if (ctx
->access_type
!= access_type
) {
250 tcg_gen_movi_i32(cpu_access_type
, access_type
);
251 ctx
->access_type
= access_type
;
255 static inline void gen_update_nip(DisasContext
*ctx
, target_ulong nip
)
257 #if defined(TARGET_PPC64)
259 tcg_gen_movi_tl(cpu_nip
, nip
);
262 tcg_gen_movi_tl(cpu_nip
, (uint32_t)nip
);
265 static inline void gen_exception_err(DisasContext
*ctx
, uint32_t excp
, uint32_t error
)
268 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
269 gen_update_nip(ctx
, ctx
->nip
);
271 t0
= tcg_const_i32(excp
);
272 t1
= tcg_const_i32(error
);
273 gen_helper_raise_exception_err(cpu_env
, t0
, t1
);
274 tcg_temp_free_i32(t0
);
275 tcg_temp_free_i32(t1
);
276 ctx
->exception
= (excp
);
279 static inline void gen_exception(DisasContext
*ctx
, uint32_t excp
)
282 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
283 gen_update_nip(ctx
, ctx
->nip
);
285 t0
= tcg_const_i32(excp
);
286 gen_helper_raise_exception(cpu_env
, t0
);
287 tcg_temp_free_i32(t0
);
288 ctx
->exception
= (excp
);
291 static inline void gen_debug_exception(DisasContext
*ctx
)
295 if ((ctx
->exception
!= POWERPC_EXCP_BRANCH
) &&
296 (ctx
->exception
!= POWERPC_EXCP_SYNC
)) {
297 gen_update_nip(ctx
, ctx
->nip
);
299 t0
= tcg_const_i32(EXCP_DEBUG
);
300 gen_helper_raise_exception(cpu_env
, t0
);
301 tcg_temp_free_i32(t0
);
304 static inline void gen_inval_exception(DisasContext
*ctx
, uint32_t error
)
306 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_INVAL
| error
);
309 /* Stop translation */
310 static inline void gen_stop_exception(DisasContext
*ctx
)
312 gen_update_nip(ctx
, ctx
->nip
);
313 ctx
->exception
= POWERPC_EXCP_STOP
;
316 /* No need to update nip here, as execution flow will change */
317 static inline void gen_sync_exception(DisasContext
*ctx
)
319 ctx
->exception
= POWERPC_EXCP_SYNC
;
322 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
323 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
325 #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
326 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
328 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
329 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
331 #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
332 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
334 typedef struct opcode_t
{
335 unsigned char opc1
, opc2
, opc3
;
336 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
337 unsigned char pad
[5];
339 unsigned char pad
[1];
341 opc_handler_t handler
;
345 /*****************************************************************************/
346 /*** Instruction decoding ***/
347 #define EXTRACT_HELPER(name, shift, nb) \
348 static inline uint32_t name(uint32_t opcode) \
350 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
353 #define EXTRACT_SHELPER(name, shift, nb) \
354 static inline int32_t name(uint32_t opcode) \
356 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
360 EXTRACT_HELPER(opc1
, 26, 6);
362 EXTRACT_HELPER(opc2
, 1, 5);
364 EXTRACT_HELPER(opc3
, 6, 5);
365 /* Update Cr0 flags */
366 EXTRACT_HELPER(Rc
, 0, 1);
368 EXTRACT_HELPER(rD
, 21, 5);
370 EXTRACT_HELPER(rS
, 21, 5);
372 EXTRACT_HELPER(rA
, 16, 5);
374 EXTRACT_HELPER(rB
, 11, 5);
376 EXTRACT_HELPER(rC
, 6, 5);
378 EXTRACT_HELPER(crfD
, 23, 3);
379 EXTRACT_HELPER(crfS
, 18, 3);
380 EXTRACT_HELPER(crbD
, 21, 5);
381 EXTRACT_HELPER(crbA
, 16, 5);
382 EXTRACT_HELPER(crbB
, 11, 5);
384 EXTRACT_HELPER(_SPR
, 11, 10);
385 static inline uint32_t SPR(uint32_t opcode
)
387 uint32_t sprn
= _SPR(opcode
);
389 return ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
391 /*** Get constants ***/
392 EXTRACT_HELPER(IMM
, 12, 8);
393 /* 16 bits signed immediate value */
394 EXTRACT_SHELPER(SIMM
, 0, 16);
395 /* 16 bits unsigned immediate value */
396 EXTRACT_HELPER(UIMM
, 0, 16);
397 /* 5 bits signed immediate value */
398 EXTRACT_HELPER(SIMM5
, 16, 5);
399 /* 5 bits signed immediate value */
400 EXTRACT_HELPER(UIMM5
, 16, 5);
402 EXTRACT_HELPER(NB
, 11, 5);
404 EXTRACT_HELPER(SH
, 11, 5);
405 /* Vector shift count */
406 EXTRACT_HELPER(VSH
, 6, 4);
408 EXTRACT_HELPER(MB
, 6, 5);
410 EXTRACT_HELPER(ME
, 1, 5);
412 EXTRACT_HELPER(TO
, 21, 5);
414 EXTRACT_HELPER(CRM
, 12, 8);
415 EXTRACT_HELPER(FM
, 17, 8);
416 EXTRACT_HELPER(SR
, 16, 4);
417 EXTRACT_HELPER(FPIMM
, 12, 4);
419 /*** Jump target decoding ***/
421 EXTRACT_SHELPER(d
, 0, 16);
422 /* Immediate address */
423 static inline target_ulong
LI(uint32_t opcode
)
425 return (opcode
>> 0) & 0x03FFFFFC;
428 static inline uint32_t BD(uint32_t opcode
)
430 return (opcode
>> 0) & 0xFFFC;
433 EXTRACT_HELPER(BO
, 21, 5);
434 EXTRACT_HELPER(BI
, 16, 5);
435 /* Absolute/relative address */
436 EXTRACT_HELPER(AA
, 1, 1);
438 EXTRACT_HELPER(LK
, 0, 1);
440 /* Create a mask between <start> and <end> bits */
441 static inline target_ulong
MASK(uint32_t start
, uint32_t end
)
445 #if defined(TARGET_PPC64)
446 if (likely(start
== 0)) {
447 ret
= UINT64_MAX
<< (63 - end
);
448 } else if (likely(end
== 63)) {
449 ret
= UINT64_MAX
>> start
;
452 if (likely(start
== 0)) {
453 ret
= UINT32_MAX
<< (31 - end
);
454 } else if (likely(end
== 31)) {
455 ret
= UINT32_MAX
>> start
;
459 ret
= (((target_ulong
)(-1ULL)) >> (start
)) ^
460 (((target_ulong
)(-1ULL) >> (end
)) >> 1);
461 if (unlikely(start
> end
))
468 /*****************************************************************************/
469 /* PowerPC instructions table */
471 #if defined(DO_PPC_STATISTICS)
472 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
482 .handler = &gen_##name, \
483 .oname = stringify(name), \
485 .oname = stringify(name), \
487 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
498 .handler = &gen_##name, \
499 .oname = stringify(name), \
501 .oname = stringify(name), \
503 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
513 .handler = &gen_##name, \
519 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
529 .handler = &gen_##name, \
531 .oname = stringify(name), \
533 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
544 .handler = &gen_##name, \
546 .oname = stringify(name), \
548 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
558 .handler = &gen_##name, \
564 /* SPR load/store helpers */
565 static inline void gen_load_spr(TCGv t
, int reg
)
567 tcg_gen_ld_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
570 static inline void gen_store_spr(int reg
, TCGv t
)
572 tcg_gen_st_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
575 /* Invalid instruction */
576 static void gen_invalid(DisasContext
*ctx
)
578 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
581 static opc_handler_t invalid_handler
= {
582 .inval1
= 0xFFFFFFFF,
583 .inval2
= 0xFFFFFFFF,
586 .handler
= gen_invalid
,
589 /*** Integer comparison ***/
591 static inline void gen_op_cmp(TCGv arg0
, TCGv arg1
, int s
, int crf
)
595 tcg_gen_trunc_tl_i32(cpu_crf
[crf
], cpu_xer
);
596 tcg_gen_shri_i32(cpu_crf
[crf
], cpu_crf
[crf
], XER_SO
);
597 tcg_gen_andi_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1);
599 l1
= gen_new_label();
600 l2
= gen_new_label();
601 l3
= gen_new_label();
603 tcg_gen_brcond_tl(TCG_COND_LT
, arg0
, arg1
, l1
);
604 tcg_gen_brcond_tl(TCG_COND_GT
, arg0
, arg1
, l2
);
606 tcg_gen_brcond_tl(TCG_COND_LTU
, arg0
, arg1
, l1
);
607 tcg_gen_brcond_tl(TCG_COND_GTU
, arg0
, arg1
, l2
);
609 tcg_gen_ori_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1 << CRF_EQ
);
612 tcg_gen_ori_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1 << CRF_LT
);
615 tcg_gen_ori_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1 << CRF_GT
);
619 static inline void gen_op_cmpi(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
621 TCGv t0
= tcg_const_local_tl(arg1
);
622 gen_op_cmp(arg0
, t0
, s
, crf
);
626 #if defined(TARGET_PPC64)
627 static inline void gen_op_cmp32(TCGv arg0
, TCGv arg1
, int s
, int crf
)
630 t0
= tcg_temp_local_new();
631 t1
= tcg_temp_local_new();
633 tcg_gen_ext32s_tl(t0
, arg0
);
634 tcg_gen_ext32s_tl(t1
, arg1
);
636 tcg_gen_ext32u_tl(t0
, arg0
);
637 tcg_gen_ext32u_tl(t1
, arg1
);
639 gen_op_cmp(t0
, t1
, s
, crf
);
644 static inline void gen_op_cmpi32(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
646 TCGv t0
= tcg_const_local_tl(arg1
);
647 gen_op_cmp32(arg0
, t0
, s
, crf
);
652 static inline void gen_set_Rc0(DisasContext
*ctx
, TCGv reg
)
654 #if defined(TARGET_PPC64)
656 gen_op_cmpi32(reg
, 0, 1, 0);
659 gen_op_cmpi(reg
, 0, 1, 0);
663 static void gen_cmp(DisasContext
*ctx
)
665 #if defined(TARGET_PPC64)
666 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
667 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
668 1, crfD(ctx
->opcode
));
671 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
672 1, crfD(ctx
->opcode
));
676 static void gen_cmpi(DisasContext
*ctx
)
678 #if defined(TARGET_PPC64)
679 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
680 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
681 1, crfD(ctx
->opcode
));
684 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
685 1, crfD(ctx
->opcode
));
689 static void gen_cmpl(DisasContext
*ctx
)
691 #if defined(TARGET_PPC64)
692 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
693 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
694 0, crfD(ctx
->opcode
));
697 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
698 0, crfD(ctx
->opcode
));
702 static void gen_cmpli(DisasContext
*ctx
)
704 #if defined(TARGET_PPC64)
705 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
706 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
707 0, crfD(ctx
->opcode
));
710 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
711 0, crfD(ctx
->opcode
));
714 /* isel (PowerPC 2.03 specification) */
715 static void gen_isel(DisasContext
*ctx
)
718 uint32_t bi
= rC(ctx
->opcode
);
722 l1
= gen_new_label();
723 l2
= gen_new_label();
725 mask
= 1 << (3 - (bi
& 0x03));
726 t0
= tcg_temp_new_i32();
727 tcg_gen_andi_i32(t0
, cpu_crf
[bi
>> 2], mask
);
728 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
729 if (rA(ctx
->opcode
) == 0)
730 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
732 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
735 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
737 tcg_temp_free_i32(t0
);
740 /*** Integer arithmetic ***/
742 static inline void gen_op_arith_compute_ov(DisasContext
*ctx
, TCGv arg0
,
743 TCGv arg1
, TCGv arg2
, int sub
)
748 l1
= gen_new_label();
749 /* Start with XER OV disabled, the most likely case */
750 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
751 t0
= tcg_temp_local_new();
752 tcg_gen_xor_tl(t0
, arg0
, arg1
);
753 #if defined(TARGET_PPC64)
755 tcg_gen_ext32s_tl(t0
, t0
);
758 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0, l1
);
760 tcg_gen_brcondi_tl(TCG_COND_GE
, t0
, 0, l1
);
761 tcg_gen_xor_tl(t0
, arg1
, arg2
);
762 #if defined(TARGET_PPC64)
764 tcg_gen_ext32s_tl(t0
, t0
);
767 tcg_gen_brcondi_tl(TCG_COND_GE
, t0
, 0, l1
);
769 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0, l1
);
770 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
775 static inline void gen_op_arith_compute_ca(DisasContext
*ctx
, TCGv arg1
,
778 int l1
= gen_new_label();
780 #if defined(TARGET_PPC64)
781 if (!(ctx
->sf_mode
)) {
786 tcg_gen_ext32u_tl(t0
, arg1
);
787 tcg_gen_ext32u_tl(t1
, arg2
);
789 tcg_gen_brcond_tl(TCG_COND_GTU
, t0
, t1
, l1
);
791 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
793 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
801 tcg_gen_brcond_tl(TCG_COND_GTU
, arg1
, arg2
, l1
);
803 tcg_gen_brcond_tl(TCG_COND_GEU
, arg1
, arg2
, l1
);
805 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
810 /* Common add function */
811 static inline void gen_op_arith_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
812 TCGv arg2
, int add_ca
, int compute_ca
,
817 if ((!compute_ca
&& !compute_ov
) ||
818 (!TCGV_EQUAL(ret
,arg1
) && !TCGV_EQUAL(ret
, arg2
))) {
821 t0
= tcg_temp_local_new();
825 t1
= tcg_temp_local_new();
826 tcg_gen_andi_tl(t1
, cpu_xer
, (1 << XER_CA
));
827 tcg_gen_shri_tl(t1
, t1
, XER_CA
);
832 if (compute_ca
&& compute_ov
) {
833 /* Start with XER CA and OV disabled, the most likely case */
834 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~((1 << XER_CA
) | (1 << XER_OV
)));
835 } else if (compute_ca
) {
836 /* Start with XER CA disabled, the most likely case */
837 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
838 } else if (compute_ov
) {
839 /* Start with XER OV disabled, the most likely case */
840 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
843 tcg_gen_add_tl(t0
, arg1
, arg2
);
846 gen_op_arith_compute_ca(ctx
, t0
, arg1
, 0);
849 tcg_gen_add_tl(t0
, t0
, t1
);
850 gen_op_arith_compute_ca(ctx
, t0
, t1
, 0);
854 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 0);
857 if (unlikely(Rc(ctx
->opcode
) != 0))
858 gen_set_Rc0(ctx
, t0
);
860 if (!TCGV_EQUAL(t0
, ret
)) {
861 tcg_gen_mov_tl(ret
, t0
);
865 /* Add functions with two operands */
866 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
867 static void glue(gen_, name)(DisasContext *ctx) \
869 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
870 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
871 add_ca, compute_ca, compute_ov); \
873 /* Add functions with one operand and one immediate */
874 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
875 add_ca, compute_ca, compute_ov) \
876 static void glue(gen_, name)(DisasContext *ctx) \
878 TCGv t0 = tcg_const_local_tl(const_val); \
879 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
880 cpu_gpr[rA(ctx->opcode)], t0, \
881 add_ca, compute_ca, compute_ov); \
885 /* add add. addo addo. */
886 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
887 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
888 /* addc addc. addco addco. */
889 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
890 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
891 /* adde adde. addeo addeo. */
892 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
893 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
894 /* addme addme. addmeo addmeo. */
895 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
896 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
897 /* addze addze. addzeo addzeo.*/
898 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
899 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
901 static void gen_addi(DisasContext
*ctx
)
903 target_long simm
= SIMM(ctx
->opcode
);
905 if (rA(ctx
->opcode
) == 0) {
907 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
);
909 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], simm
);
913 static inline void gen_op_addic(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
916 target_long simm
= SIMM(ctx
->opcode
);
918 /* Start with XER CA and OV disabled, the most likely case */
919 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
921 if (likely(simm
!= 0)) {
922 TCGv t0
= tcg_temp_local_new();
923 tcg_gen_addi_tl(t0
, arg1
, simm
);
924 gen_op_arith_compute_ca(ctx
, t0
, arg1
, 0);
925 tcg_gen_mov_tl(ret
, t0
);
928 tcg_gen_mov_tl(ret
, arg1
);
931 gen_set_Rc0(ctx
, ret
);
935 static void gen_addic(DisasContext
*ctx
)
937 gen_op_addic(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0);
940 static void gen_addic_(DisasContext
*ctx
)
942 gen_op_addic(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 1);
946 static void gen_addis(DisasContext
*ctx
)
948 target_long simm
= SIMM(ctx
->opcode
);
950 if (rA(ctx
->opcode
) == 0) {
952 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
<< 16);
954 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], simm
<< 16);
958 static inline void gen_op_arith_divw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
959 TCGv arg2
, int sign
, int compute_ov
)
961 int l1
= gen_new_label();
962 int l2
= gen_new_label();
963 TCGv_i32 t0
= tcg_temp_local_new_i32();
964 TCGv_i32 t1
= tcg_temp_local_new_i32();
966 tcg_gen_trunc_tl_i32(t0
, arg1
);
967 tcg_gen_trunc_tl_i32(t1
, arg2
);
968 tcg_gen_brcondi_i32(TCG_COND_EQ
, t1
, 0, l1
);
970 int l3
= gen_new_label();
971 tcg_gen_brcondi_i32(TCG_COND_NE
, t1
, -1, l3
);
972 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, INT32_MIN
, l1
);
974 tcg_gen_div_i32(t0
, t0
, t1
);
976 tcg_gen_divu_i32(t0
, t0
, t1
);
979 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
984 tcg_gen_sari_i32(t0
, t0
, 31);
986 tcg_gen_movi_i32(t0
, 0);
989 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
992 tcg_gen_extu_i32_tl(ret
, t0
);
993 tcg_temp_free_i32(t0
);
994 tcg_temp_free_i32(t1
);
995 if (unlikely(Rc(ctx
->opcode
) != 0))
996 gen_set_Rc0(ctx
, ret
);
999 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
1000 static void glue(gen_, name)(DisasContext *ctx) \
1002 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
1003 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1004 sign, compute_ov); \
1006 /* divwu divwu. divwuo divwuo. */
1007 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0);
1008 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1);
1009 /* divw divw. divwo divwo. */
1010 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0);
1011 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1);
1012 #if defined(TARGET_PPC64)
1013 static inline void gen_op_arith_divd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1014 TCGv arg2
, int sign
, int compute_ov
)
1016 int l1
= gen_new_label();
1017 int l2
= gen_new_label();
1019 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg2
, 0, l1
);
1021 int l3
= gen_new_label();
1022 tcg_gen_brcondi_i64(TCG_COND_NE
, arg2
, -1, l3
);
1023 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg1
, INT64_MIN
, l1
);
1025 tcg_gen_div_i64(ret
, arg1
, arg2
);
1027 tcg_gen_divu_i64(ret
, arg1
, arg2
);
1030 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1035 tcg_gen_sari_i64(ret
, arg1
, 63);
1037 tcg_gen_movi_i64(ret
, 0);
1040 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1043 if (unlikely(Rc(ctx
->opcode
) != 0))
1044 gen_set_Rc0(ctx
, ret
);
1046 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1047 static void glue(gen_, name)(DisasContext *ctx) \
1049 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1050 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1051 sign, compute_ov); \
1053 /* divwu divwu. divwuo divwuo. */
1054 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0);
1055 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1);
1056 /* divw divw. divwo divwo. */
1057 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0);
1058 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1);
1062 static void gen_mulhw(DisasContext
*ctx
)
1066 t0
= tcg_temp_new_i64();
1067 t1
= tcg_temp_new_i64();
1068 #if defined(TARGET_PPC64)
1069 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1070 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1071 tcg_gen_mul_i64(t0
, t0
, t1
);
1072 tcg_gen_shri_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
1074 tcg_gen_ext_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1075 tcg_gen_ext_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1076 tcg_gen_mul_i64(t0
, t0
, t1
);
1077 tcg_gen_shri_i64(t0
, t0
, 32);
1078 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1080 tcg_temp_free_i64(t0
);
1081 tcg_temp_free_i64(t1
);
1082 if (unlikely(Rc(ctx
->opcode
) != 0))
1083 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1086 /* mulhwu mulhwu. */
1087 static void gen_mulhwu(DisasContext
*ctx
)
1091 t0
= tcg_temp_new_i64();
1092 t1
= tcg_temp_new_i64();
1093 #if defined(TARGET_PPC64)
1094 tcg_gen_ext32u_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1095 tcg_gen_ext32u_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1096 tcg_gen_mul_i64(t0
, t0
, t1
);
1097 tcg_gen_shri_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
1099 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1100 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1101 tcg_gen_mul_i64(t0
, t0
, t1
);
1102 tcg_gen_shri_i64(t0
, t0
, 32);
1103 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1105 tcg_temp_free_i64(t0
);
1106 tcg_temp_free_i64(t1
);
1107 if (unlikely(Rc(ctx
->opcode
) != 0))
1108 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1112 static void gen_mullw(DisasContext
*ctx
)
1114 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1115 cpu_gpr
[rB(ctx
->opcode
)]);
1116 tcg_gen_ext32s_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)]);
1117 if (unlikely(Rc(ctx
->opcode
) != 0))
1118 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1121 /* mullwo mullwo. */
1122 static void gen_mullwo(DisasContext
*ctx
)
1127 t0
= tcg_temp_new_i64();
1128 t1
= tcg_temp_new_i64();
1129 l1
= gen_new_label();
1130 /* Start with XER OV disabled, the most likely case */
1131 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1132 #if defined(TARGET_PPC64)
1133 tcg_gen_ext32s_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1134 tcg_gen_ext32s_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1136 tcg_gen_ext_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1137 tcg_gen_ext_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1139 tcg_gen_mul_i64(t0
, t0
, t1
);
1140 #if defined(TARGET_PPC64)
1141 tcg_gen_ext32s_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1142 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, cpu_gpr
[rD(ctx
->opcode
)], l1
);
1144 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1145 tcg_gen_ext32s_i64(t1
, t0
);
1146 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
1148 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1150 tcg_temp_free_i64(t0
);
1151 tcg_temp_free_i64(t1
);
1152 if (unlikely(Rc(ctx
->opcode
) != 0))
1153 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1157 static void gen_mulli(DisasContext
*ctx
)
1159 tcg_gen_muli_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1162 #if defined(TARGET_PPC64)
1163 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
1164 static void glue(gen_, name)(DisasContext *ctx) \
1166 gen_helper_##name (cpu_gpr[rD(ctx->opcode)], \
1167 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
1168 if (unlikely(Rc(ctx->opcode) != 0)) \
1169 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1172 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00);
1173 /* mulhdu mulhdu. */
1174 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02);
1177 static void gen_mulld(DisasContext
*ctx
)
1179 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1180 cpu_gpr
[rB(ctx
->opcode
)]);
1181 if (unlikely(Rc(ctx
->opcode
) != 0))
1182 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1184 /* mulldo mulldo. */
1185 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17);
1188 /* neg neg. nego nego. */
1189 static inline void gen_op_arith_neg(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1192 int l1
= gen_new_label();
1193 int l2
= gen_new_label();
1194 TCGv t0
= tcg_temp_local_new();
1195 #if defined(TARGET_PPC64)
1197 tcg_gen_mov_tl(t0
, arg1
);
1198 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, INT64_MIN
, l1
);
1202 tcg_gen_ext32s_tl(t0
, arg1
);
1203 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, INT32_MIN
, l1
);
1205 tcg_gen_neg_tl(ret
, arg1
);
1207 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1211 tcg_gen_mov_tl(ret
, t0
);
1213 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1217 if (unlikely(Rc(ctx
->opcode
) != 0))
1218 gen_set_Rc0(ctx
, ret
);
1221 static void gen_neg(DisasContext
*ctx
)
1223 gen_op_arith_neg(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0);
1226 static void gen_nego(DisasContext
*ctx
)
1228 gen_op_arith_neg(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 1);
1231 /* Common subf function */
1232 static inline void gen_op_arith_subf(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1233 TCGv arg2
, int add_ca
, int compute_ca
,
1238 if ((!compute_ca
&& !compute_ov
) ||
1239 (!TCGV_EQUAL(ret
, arg1
) && !TCGV_EQUAL(ret
, arg2
))) {
1242 t0
= tcg_temp_local_new();
1246 t1
= tcg_temp_local_new();
1247 tcg_gen_andi_tl(t1
, cpu_xer
, (1 << XER_CA
));
1248 tcg_gen_shri_tl(t1
, t1
, XER_CA
);
1253 if (compute_ca
&& compute_ov
) {
1254 /* Start with XER CA and OV disabled, the most likely case */
1255 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~((1 << XER_CA
) | (1 << XER_OV
)));
1256 } else if (compute_ca
) {
1257 /* Start with XER CA disabled, the most likely case */
1258 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1259 } else if (compute_ov
) {
1260 /* Start with XER OV disabled, the most likely case */
1261 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1265 tcg_gen_not_tl(t0
, arg1
);
1266 tcg_gen_add_tl(t0
, t0
, arg2
);
1267 gen_op_arith_compute_ca(ctx
, t0
, arg2
, 0);
1268 tcg_gen_add_tl(t0
, t0
, t1
);
1269 gen_op_arith_compute_ca(ctx
, t0
, t1
, 0);
1272 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1274 gen_op_arith_compute_ca(ctx
, t0
, arg2
, 1);
1278 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 1);
1281 if (unlikely(Rc(ctx
->opcode
) != 0))
1282 gen_set_Rc0(ctx
, t0
);
1284 if (!TCGV_EQUAL(t0
, ret
)) {
1285 tcg_gen_mov_tl(ret
, t0
);
1289 /* Sub functions with Two operands functions */
1290 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1291 static void glue(gen_, name)(DisasContext *ctx) \
1293 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1294 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1295 add_ca, compute_ca, compute_ov); \
1297 /* Sub functions with one operand and one immediate */
1298 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1299 add_ca, compute_ca, compute_ov) \
1300 static void glue(gen_, name)(DisasContext *ctx) \
1302 TCGv t0 = tcg_const_local_tl(const_val); \
1303 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1304 cpu_gpr[rA(ctx->opcode)], t0, \
1305 add_ca, compute_ca, compute_ov); \
1306 tcg_temp_free(t0); \
1308 /* subf subf. subfo subfo. */
1309 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
1310 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
1311 /* subfc subfc. subfco subfco. */
1312 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
1313 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
1314 /* subfe subfe. subfeo subfo. */
1315 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
1316 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
1317 /* subfme subfme. subfmeo subfmeo. */
1318 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
1319 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
1320 /* subfze subfze. subfzeo subfzeo.*/
1321 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
1322 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
1325 static void gen_subfic(DisasContext
*ctx
)
1327 /* Start with XER CA and OV disabled, the most likely case */
1328 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1329 TCGv t0
= tcg_temp_local_new();
1330 TCGv t1
= tcg_const_local_tl(SIMM(ctx
->opcode
));
1331 tcg_gen_sub_tl(t0
, t1
, cpu_gpr
[rA(ctx
->opcode
)]);
1332 gen_op_arith_compute_ca(ctx
, t0
, t1
, 1);
1334 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1338 /*** Integer logical ***/
1339 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1340 static void glue(gen_, name)(DisasContext *ctx) \
1342 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1343 cpu_gpr[rB(ctx->opcode)]); \
1344 if (unlikely(Rc(ctx->opcode) != 0)) \
1345 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1348 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1349 static void glue(gen_, name)(DisasContext *ctx) \
1351 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1352 if (unlikely(Rc(ctx->opcode) != 0)) \
1353 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1357 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
);
1359 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
);
1362 static void gen_andi_(DisasContext
*ctx
)
1364 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
));
1365 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1369 static void gen_andis_(DisasContext
*ctx
)
1371 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
) << 16);
1372 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1376 static void gen_cntlzw(DisasContext
*ctx
)
1378 gen_helper_cntlzw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1379 if (unlikely(Rc(ctx
->opcode
) != 0))
1380 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1383 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
);
1384 /* extsb & extsb. */
1385 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
);
1386 /* extsh & extsh. */
1387 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
);
1389 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
);
1391 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
);
1394 static void gen_or(DisasContext
*ctx
)
1398 rs
= rS(ctx
->opcode
);
1399 ra
= rA(ctx
->opcode
);
1400 rb
= rB(ctx
->opcode
);
1401 /* Optimisation for mr. ri case */
1402 if (rs
!= ra
|| rs
!= rb
) {
1404 tcg_gen_or_tl(cpu_gpr
[ra
], cpu_gpr
[rs
], cpu_gpr
[rb
]);
1406 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rs
]);
1407 if (unlikely(Rc(ctx
->opcode
) != 0))
1408 gen_set_Rc0(ctx
, cpu_gpr
[ra
]);
1409 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
1410 gen_set_Rc0(ctx
, cpu_gpr
[rs
]);
1411 #if defined(TARGET_PPC64)
1417 /* Set process priority to low */
1421 /* Set process priority to medium-low */
1425 /* Set process priority to normal */
1428 #if !defined(CONFIG_USER_ONLY)
1430 if (ctx
->mem_idx
> 0) {
1431 /* Set process priority to very low */
1436 if (ctx
->mem_idx
> 0) {
1437 /* Set process priority to medium-hight */
1442 if (ctx
->mem_idx
> 0) {
1443 /* Set process priority to high */
1448 if (ctx
->mem_idx
> 1) {
1449 /* Set process priority to very high */
1459 TCGv t0
= tcg_temp_new();
1460 gen_load_spr(t0
, SPR_PPR
);
1461 tcg_gen_andi_tl(t0
, t0
, ~0x001C000000000000ULL
);
1462 tcg_gen_ori_tl(t0
, t0
, ((uint64_t)prio
) << 50);
1463 gen_store_spr(SPR_PPR
, t0
);
1470 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
);
1473 static void gen_xor(DisasContext
*ctx
)
1475 /* Optimisation for "set to zero" case */
1476 if (rS(ctx
->opcode
) != rB(ctx
->opcode
))
1477 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1479 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1480 if (unlikely(Rc(ctx
->opcode
) != 0))
1481 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1485 static void gen_ori(DisasContext
*ctx
)
1487 target_ulong uimm
= UIMM(ctx
->opcode
);
1489 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1491 /* XXX: should handle special NOPs for POWER series */
1494 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1498 static void gen_oris(DisasContext
*ctx
)
1500 target_ulong uimm
= UIMM(ctx
->opcode
);
1502 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1506 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1510 static void gen_xori(DisasContext
*ctx
)
1512 target_ulong uimm
= UIMM(ctx
->opcode
);
1514 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1518 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1522 static void gen_xoris(DisasContext
*ctx
)
1524 target_ulong uimm
= UIMM(ctx
->opcode
);
1526 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1530 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1533 /* popcntb : PowerPC 2.03 specification */
1534 static void gen_popcntb(DisasContext
*ctx
)
1536 gen_helper_popcntb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1539 static void gen_popcntw(DisasContext
*ctx
)
1541 gen_helper_popcntw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1544 #if defined(TARGET_PPC64)
1545 /* popcntd: PowerPC 2.06 specification */
1546 static void gen_popcntd(DisasContext
*ctx
)
1548 gen_helper_popcntd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1552 #if defined(TARGET_PPC64)
1553 /* extsw & extsw. */
1554 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
);
1557 static void gen_cntlzd(DisasContext
*ctx
)
1559 gen_helper_cntlzd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1560 if (unlikely(Rc(ctx
->opcode
) != 0))
1561 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1565 /*** Integer rotate ***/
1567 /* rlwimi & rlwimi. */
1568 static void gen_rlwimi(DisasContext
*ctx
)
1570 uint32_t mb
, me
, sh
;
1572 mb
= MB(ctx
->opcode
);
1573 me
= ME(ctx
->opcode
);
1574 sh
= SH(ctx
->opcode
);
1575 if (likely(sh
== 0 && mb
== 0 && me
== 31)) {
1576 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1580 TCGv t0
= tcg_temp_new();
1581 #if defined(TARGET_PPC64)
1582 TCGv_i32 t2
= tcg_temp_new_i32();
1583 tcg_gen_trunc_i64_i32(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
1584 tcg_gen_rotli_i32(t2
, t2
, sh
);
1585 tcg_gen_extu_i32_i64(t0
, t2
);
1586 tcg_temp_free_i32(t2
);
1588 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1590 #if defined(TARGET_PPC64)
1594 mask
= MASK(mb
, me
);
1595 t1
= tcg_temp_new();
1596 tcg_gen_andi_tl(t0
, t0
, mask
);
1597 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1598 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1602 if (unlikely(Rc(ctx
->opcode
) != 0))
1603 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1606 /* rlwinm & rlwinm. */
1607 static void gen_rlwinm(DisasContext
*ctx
)
1609 uint32_t mb
, me
, sh
;
1611 sh
= SH(ctx
->opcode
);
1612 mb
= MB(ctx
->opcode
);
1613 me
= ME(ctx
->opcode
);
1615 if (likely(mb
== 0 && me
== (31 - sh
))) {
1616 if (likely(sh
== 0)) {
1617 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1619 TCGv t0
= tcg_temp_new();
1620 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1621 tcg_gen_shli_tl(t0
, t0
, sh
);
1622 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1625 } else if (likely(sh
!= 0 && me
== 31 && sh
== (32 - mb
))) {
1626 TCGv t0
= tcg_temp_new();
1627 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1628 tcg_gen_shri_tl(t0
, t0
, mb
);
1629 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1632 TCGv t0
= tcg_temp_new();
1633 #if defined(TARGET_PPC64)
1634 TCGv_i32 t1
= tcg_temp_new_i32();
1635 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1636 tcg_gen_rotli_i32(t1
, t1
, sh
);
1637 tcg_gen_extu_i32_i64(t0
, t1
);
1638 tcg_temp_free_i32(t1
);
1640 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1642 #if defined(TARGET_PPC64)
1646 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1649 if (unlikely(Rc(ctx
->opcode
) != 0))
1650 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1653 /* rlwnm & rlwnm. */
1654 static void gen_rlwnm(DisasContext
*ctx
)
1658 #if defined(TARGET_PPC64)
1662 mb
= MB(ctx
->opcode
);
1663 me
= ME(ctx
->opcode
);
1664 t0
= tcg_temp_new();
1665 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1666 #if defined(TARGET_PPC64)
1667 t1
= tcg_temp_new_i32();
1668 t2
= tcg_temp_new_i32();
1669 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1670 tcg_gen_trunc_i64_i32(t2
, t0
);
1671 tcg_gen_rotl_i32(t1
, t1
, t2
);
1672 tcg_gen_extu_i32_i64(t0
, t1
);
1673 tcg_temp_free_i32(t1
);
1674 tcg_temp_free_i32(t2
);
1676 tcg_gen_rotl_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1678 if (unlikely(mb
!= 0 || me
!= 31)) {
1679 #if defined(TARGET_PPC64)
1683 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1685 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1688 if (unlikely(Rc(ctx
->opcode
) != 0))
1689 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1692 #if defined(TARGET_PPC64)
1693 #define GEN_PPC64_R2(name, opc1, opc2) \
1694 static void glue(gen_, name##0)(DisasContext *ctx) \
1696 gen_##name(ctx, 0); \
1699 static void glue(gen_, name##1)(DisasContext *ctx) \
1701 gen_##name(ctx, 1); \
1703 #define GEN_PPC64_R4(name, opc1, opc2) \
1704 static void glue(gen_, name##0)(DisasContext *ctx) \
1706 gen_##name(ctx, 0, 0); \
1709 static void glue(gen_, name##1)(DisasContext *ctx) \
1711 gen_##name(ctx, 0, 1); \
1714 static void glue(gen_, name##2)(DisasContext *ctx) \
1716 gen_##name(ctx, 1, 0); \
1719 static void glue(gen_, name##3)(DisasContext *ctx) \
1721 gen_##name(ctx, 1, 1); \
1724 static inline void gen_rldinm(DisasContext
*ctx
, uint32_t mb
, uint32_t me
,
1727 if (likely(sh
!= 0 && mb
== 0 && me
== (63 - sh
))) {
1728 tcg_gen_shli_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
1729 } else if (likely(sh
!= 0 && me
== 63 && sh
== (64 - mb
))) {
1730 tcg_gen_shri_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], mb
);
1732 TCGv t0
= tcg_temp_new();
1733 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1734 if (likely(mb
== 0 && me
== 63)) {
1735 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1737 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1741 if (unlikely(Rc(ctx
->opcode
) != 0))
1742 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1744 /* rldicl - rldicl. */
1745 static inline void gen_rldicl(DisasContext
*ctx
, int mbn
, int shn
)
1749 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1750 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1751 gen_rldinm(ctx
, mb
, 63, sh
);
1753 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
1754 /* rldicr - rldicr. */
1755 static inline void gen_rldicr(DisasContext
*ctx
, int men
, int shn
)
1759 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1760 me
= MB(ctx
->opcode
) | (men
<< 5);
1761 gen_rldinm(ctx
, 0, me
, sh
);
1763 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
1764 /* rldic - rldic. */
1765 static inline void gen_rldic(DisasContext
*ctx
, int mbn
, int shn
)
1769 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1770 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1771 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
1773 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
1775 static inline void gen_rldnm(DisasContext
*ctx
, uint32_t mb
, uint32_t me
)
1779 mb
= MB(ctx
->opcode
);
1780 me
= ME(ctx
->opcode
);
1781 t0
= tcg_temp_new();
1782 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1783 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1784 if (unlikely(mb
!= 0 || me
!= 63)) {
1785 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1787 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1790 if (unlikely(Rc(ctx
->opcode
) != 0))
1791 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1794 /* rldcl - rldcl. */
1795 static inline void gen_rldcl(DisasContext
*ctx
, int mbn
)
1799 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1800 gen_rldnm(ctx
, mb
, 63);
1802 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
1803 /* rldcr - rldcr. */
1804 static inline void gen_rldcr(DisasContext
*ctx
, int men
)
1808 me
= MB(ctx
->opcode
) | (men
<< 5);
1809 gen_rldnm(ctx
, 0, me
);
1811 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
1812 /* rldimi - rldimi. */
1813 static inline void gen_rldimi(DisasContext
*ctx
, int mbn
, int shn
)
1815 uint32_t sh
, mb
, me
;
1817 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1818 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1820 if (unlikely(sh
== 0 && mb
== 0)) {
1821 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1826 t0
= tcg_temp_new();
1827 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1828 t1
= tcg_temp_new();
1829 mask
= MASK(mb
, me
);
1830 tcg_gen_andi_tl(t0
, t0
, mask
);
1831 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1832 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1836 if (unlikely(Rc(ctx
->opcode
) != 0))
1837 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1839 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
1842 /*** Integer shift ***/
1845 static void gen_slw(DisasContext
*ctx
)
1849 t0
= tcg_temp_new();
1850 /* AND rS with a mask that is 0 when rB >= 0x20 */
1851 #if defined(TARGET_PPC64)
1852 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
1853 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1855 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
1856 tcg_gen_sari_tl(t0
, t0
, 0x1f);
1858 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1859 t1
= tcg_temp_new();
1860 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1861 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1864 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
1865 if (unlikely(Rc(ctx
->opcode
) != 0))
1866 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1870 static void gen_sraw(DisasContext
*ctx
)
1872 gen_helper_sraw(cpu_gpr
[rA(ctx
->opcode
)],
1873 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1874 if (unlikely(Rc(ctx
->opcode
) != 0))
1875 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1878 /* srawi & srawi. */
1879 static void gen_srawi(DisasContext
*ctx
)
1881 int sh
= SH(ctx
->opcode
);
1885 l1
= gen_new_label();
1886 l2
= gen_new_label();
1887 t0
= tcg_temp_local_new();
1888 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1889 tcg_gen_brcondi_tl(TCG_COND_GE
, t0
, 0, l1
);
1890 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1ULL << sh
) - 1);
1891 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
1892 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
1895 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1897 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1898 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, sh
);
1901 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1902 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1904 if (unlikely(Rc(ctx
->opcode
) != 0))
1905 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1909 static void gen_srw(DisasContext
*ctx
)
1913 t0
= tcg_temp_new();
1914 /* AND rS with a mask that is 0 when rB >= 0x20 */
1915 #if defined(TARGET_PPC64)
1916 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
1917 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1919 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
1920 tcg_gen_sari_tl(t0
, t0
, 0x1f);
1922 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1923 tcg_gen_ext32u_tl(t0
, t0
);
1924 t1
= tcg_temp_new();
1925 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1926 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1929 if (unlikely(Rc(ctx
->opcode
) != 0))
1930 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1933 #if defined(TARGET_PPC64)
1935 static void gen_sld(DisasContext
*ctx
)
1939 t0
= tcg_temp_new();
1940 /* AND rS with a mask that is 0 when rB >= 0x40 */
1941 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
1942 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1943 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1944 t1
= tcg_temp_new();
1945 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1946 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1949 if (unlikely(Rc(ctx
->opcode
) != 0))
1950 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1954 static void gen_srad(DisasContext
*ctx
)
1956 gen_helper_srad(cpu_gpr
[rA(ctx
->opcode
)],
1957 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1958 if (unlikely(Rc(ctx
->opcode
) != 0))
1959 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1961 /* sradi & sradi. */
1962 static inline void gen_sradi(DisasContext
*ctx
, int n
)
1964 int sh
= SH(ctx
->opcode
) + (n
<< 5);
1968 l1
= gen_new_label();
1969 l2
= gen_new_label();
1970 t0
= tcg_temp_local_new();
1971 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
1972 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1ULL << sh
) - 1);
1973 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
1974 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
1977 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1980 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
1982 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1983 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1985 if (unlikely(Rc(ctx
->opcode
) != 0))
1986 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1989 static void gen_sradi0(DisasContext
*ctx
)
1994 static void gen_sradi1(DisasContext
*ctx
)
2000 static void gen_srd(DisasContext
*ctx
)
2004 t0
= tcg_temp_new();
2005 /* AND rS with a mask that is 0 when rB >= 0x40 */
2006 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
2007 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2008 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2009 t1
= tcg_temp_new();
2010 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
2011 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2014 if (unlikely(Rc(ctx
->opcode
) != 0))
2015 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2019 /*** Floating-Point arithmetic ***/
2020 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
2021 static void gen_f##name(DisasContext *ctx) \
2023 if (unlikely(!ctx->fpu_enabled)) { \
2024 gen_exception(ctx, POWERPC_EXCP_FPU); \
2027 /* NIP cannot be restored if the memory exception comes from an helper */ \
2028 gen_update_nip(ctx, ctx->nip - 4); \
2029 gen_reset_fpstatus(); \
2030 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], \
2031 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2033 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]); \
2035 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \
2036 Rc(ctx->opcode) != 0); \
2039 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2040 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2041 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
2043 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2044 static void gen_f##name(DisasContext *ctx) \
2046 if (unlikely(!ctx->fpu_enabled)) { \
2047 gen_exception(ctx, POWERPC_EXCP_FPU); \
2050 /* NIP cannot be restored if the memory exception comes from an helper */ \
2051 gen_update_nip(ctx, ctx->nip - 4); \
2052 gen_reset_fpstatus(); \
2053 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], \
2054 cpu_fpr[rB(ctx->opcode)]); \
2056 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]); \
2058 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2059 set_fprf, Rc(ctx->opcode) != 0); \
2061 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2062 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2063 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2065 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2066 static void gen_f##name(DisasContext *ctx) \
2068 if (unlikely(!ctx->fpu_enabled)) { \
2069 gen_exception(ctx, POWERPC_EXCP_FPU); \
2072 /* NIP cannot be restored if the memory exception comes from an helper */ \
2073 gen_update_nip(ctx, ctx->nip - 4); \
2074 gen_reset_fpstatus(); \
2075 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], \
2076 cpu_fpr[rC(ctx->opcode)]); \
2078 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]); \
2080 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2081 set_fprf, Rc(ctx->opcode) != 0); \
2083 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2084 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2085 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2087 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
2088 static void gen_f##name(DisasContext *ctx) \
2090 if (unlikely(!ctx->fpu_enabled)) { \
2091 gen_exception(ctx, POWERPC_EXCP_FPU); \
2094 /* NIP cannot be restored if the memory exception comes from an helper */ \
2095 gen_update_nip(ctx, ctx->nip - 4); \
2096 gen_reset_fpstatus(); \
2097 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2098 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2099 set_fprf, Rc(ctx->opcode) != 0); \
2102 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
2103 static void gen_f##name(DisasContext *ctx) \
2105 if (unlikely(!ctx->fpu_enabled)) { \
2106 gen_exception(ctx, POWERPC_EXCP_FPU); \
2109 /* NIP cannot be restored if the memory exception comes from an helper */ \
2110 gen_update_nip(ctx, ctx->nip - 4); \
2111 gen_reset_fpstatus(); \
2112 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2113 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2114 set_fprf, Rc(ctx->opcode) != 0); \
2118 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
);
2120 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
);
2122 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
);
2125 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
);
2128 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
);
2131 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
);
2134 static void gen_frsqrtes(DisasContext
*ctx
)
2136 if (unlikely(!ctx
->fpu_enabled
)) {
2137 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2140 /* NIP cannot be restored if the memory exception comes from an helper */
2141 gen_update_nip(ctx
, ctx
->nip
- 4);
2142 gen_reset_fpstatus();
2143 gen_helper_frsqrte(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2144 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rD(ctx
->opcode
)]);
2145 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2149 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
);
2151 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
);
2155 static void gen_fsqrt(DisasContext
*ctx
)
2157 if (unlikely(!ctx
->fpu_enabled
)) {
2158 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2161 /* NIP cannot be restored if the memory exception comes from an helper */
2162 gen_update_nip(ctx
, ctx
->nip
- 4);
2163 gen_reset_fpstatus();
2164 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2165 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2168 static void gen_fsqrts(DisasContext
*ctx
)
2170 if (unlikely(!ctx
->fpu_enabled
)) {
2171 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2174 /* NIP cannot be restored if the memory exception comes from an helper */
2175 gen_update_nip(ctx
, ctx
->nip
- 4);
2176 gen_reset_fpstatus();
2177 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2178 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rD(ctx
->opcode
)]);
2179 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2182 /*** Floating-Point multiply-and-add ***/
2183 /* fmadd - fmadds */
2184 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
);
2185 /* fmsub - fmsubs */
2186 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
);
2187 /* fnmadd - fnmadds */
2188 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
);
2189 /* fnmsub - fnmsubs */
2190 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
);
2192 /*** Floating-Point round & convert ***/
2194 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
);
2196 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
);
2198 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
);
2199 #if defined(TARGET_PPC64)
2201 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
);
2203 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
);
2205 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
);
2209 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
);
2211 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
);
2213 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
);
2215 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
);
2217 /*** Floating-Point compare ***/
2220 static void gen_fcmpo(DisasContext
*ctx
)
2223 if (unlikely(!ctx
->fpu_enabled
)) {
2224 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2227 /* NIP cannot be restored if the memory exception comes from an helper */
2228 gen_update_nip(ctx
, ctx
->nip
- 4);
2229 gen_reset_fpstatus();
2230 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2231 gen_helper_fcmpo(cpu_fpr
[rA(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)], crf
);
2232 tcg_temp_free_i32(crf
);
2233 gen_helper_float_check_status();
2237 static void gen_fcmpu(DisasContext
*ctx
)
2240 if (unlikely(!ctx
->fpu_enabled
)) {
2241 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2244 /* NIP cannot be restored if the memory exception comes from an helper */
2245 gen_update_nip(ctx
, ctx
->nip
- 4);
2246 gen_reset_fpstatus();
2247 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2248 gen_helper_fcmpu(cpu_fpr
[rA(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)], crf
);
2249 tcg_temp_free_i32(crf
);
2250 gen_helper_float_check_status();
2253 /*** Floating-point move ***/
2255 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2256 GEN_FLOAT_B(abs
, 0x08, 0x08, 0, PPC_FLOAT
);
2259 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2260 static void gen_fmr(DisasContext
*ctx
)
2262 if (unlikely(!ctx
->fpu_enabled
)) {
2263 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2266 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2267 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2271 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2272 GEN_FLOAT_B(nabs
, 0x08, 0x04, 0, PPC_FLOAT
);
2274 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2275 GEN_FLOAT_B(neg
, 0x08, 0x01, 0, PPC_FLOAT
);
2277 /*** Floating-Point status & ctrl register ***/
2280 static void gen_mcrfs(DisasContext
*ctx
)
2284 if (unlikely(!ctx
->fpu_enabled
)) {
2285 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2288 bfa
= 4 * (7 - crfS(ctx
->opcode
));
2289 tcg_gen_shri_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_fpscr
, bfa
);
2290 tcg_gen_andi_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfD(ctx
->opcode
)], 0xf);
2291 tcg_gen_andi_i32(cpu_fpscr
, cpu_fpscr
, ~(0xF << bfa
));
2295 static void gen_mffs(DisasContext
*ctx
)
2297 if (unlikely(!ctx
->fpu_enabled
)) {
2298 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2301 gen_reset_fpstatus();
2302 tcg_gen_extu_i32_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpscr
);
2303 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2307 static void gen_mtfsb0(DisasContext
*ctx
)
2311 if (unlikely(!ctx
->fpu_enabled
)) {
2312 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2315 crb
= 31 - crbD(ctx
->opcode
);
2316 gen_reset_fpstatus();
2317 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
)) {
2319 /* NIP cannot be restored if the memory exception comes from an helper */
2320 gen_update_nip(ctx
, ctx
->nip
- 4);
2321 t0
= tcg_const_i32(crb
);
2322 gen_helper_fpscr_clrbit(t0
);
2323 tcg_temp_free_i32(t0
);
2325 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2326 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2331 static void gen_mtfsb1(DisasContext
*ctx
)
2335 if (unlikely(!ctx
->fpu_enabled
)) {
2336 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2339 crb
= 31 - crbD(ctx
->opcode
);
2340 gen_reset_fpstatus();
2341 /* XXX: we pretend we can only do IEEE floating-point computations */
2342 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
&& crb
!= FPSCR_NI
)) {
2344 /* NIP cannot be restored if the memory exception comes from an helper */
2345 gen_update_nip(ctx
, ctx
->nip
- 4);
2346 t0
= tcg_const_i32(crb
);
2347 gen_helper_fpscr_setbit(t0
);
2348 tcg_temp_free_i32(t0
);
2350 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2351 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2353 /* We can raise a differed exception */
2354 gen_helper_float_check_status();
2358 static void gen_mtfsf(DisasContext
*ctx
)
2361 int L
= ctx
->opcode
& 0x02000000;
2363 if (unlikely(!ctx
->fpu_enabled
)) {
2364 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2367 /* NIP cannot be restored if the memory exception comes from an helper */
2368 gen_update_nip(ctx
, ctx
->nip
- 4);
2369 gen_reset_fpstatus();
2371 t0
= tcg_const_i32(0xff);
2373 t0
= tcg_const_i32(FM(ctx
->opcode
));
2374 gen_helper_store_fpscr(cpu_fpr
[rB(ctx
->opcode
)], t0
);
2375 tcg_temp_free_i32(t0
);
2376 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2377 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2379 /* We can raise a differed exception */
2380 gen_helper_float_check_status();
2384 static void gen_mtfsfi(DisasContext
*ctx
)
2390 if (unlikely(!ctx
->fpu_enabled
)) {
2391 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2394 bf
= crbD(ctx
->opcode
) >> 2;
2396 /* NIP cannot be restored if the memory exception comes from an helper */
2397 gen_update_nip(ctx
, ctx
->nip
- 4);
2398 gen_reset_fpstatus();
2399 t0
= tcg_const_i64(FPIMM(ctx
->opcode
) << (4 * sh
));
2400 t1
= tcg_const_i32(1 << sh
);
2401 gen_helper_store_fpscr(t0
, t1
);
2402 tcg_temp_free_i64(t0
);
2403 tcg_temp_free_i32(t1
);
2404 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2405 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2407 /* We can raise a differed exception */
2408 gen_helper_float_check_status();
2411 /*** Addressing modes ***/
2412 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2413 static inline void gen_addr_imm_index(DisasContext
*ctx
, TCGv EA
,
2416 target_long simm
= SIMM(ctx
->opcode
);
2419 if (rA(ctx
->opcode
) == 0) {
2420 #if defined(TARGET_PPC64)
2421 if (!ctx
->sf_mode
) {
2422 tcg_gen_movi_tl(EA
, (uint32_t)simm
);
2425 tcg_gen_movi_tl(EA
, simm
);
2426 } else if (likely(simm
!= 0)) {
2427 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
);
2428 #if defined(TARGET_PPC64)
2429 if (!ctx
->sf_mode
) {
2430 tcg_gen_ext32u_tl(EA
, EA
);
2434 #if defined(TARGET_PPC64)
2435 if (!ctx
->sf_mode
) {
2436 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2439 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2443 static inline void gen_addr_reg_index(DisasContext
*ctx
, TCGv EA
)
2445 if (rA(ctx
->opcode
) == 0) {
2446 #if defined(TARGET_PPC64)
2447 if (!ctx
->sf_mode
) {
2448 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2451 tcg_gen_mov_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2453 tcg_gen_add_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2454 #if defined(TARGET_PPC64)
2455 if (!ctx
->sf_mode
) {
2456 tcg_gen_ext32u_tl(EA
, EA
);
2462 static inline void gen_addr_register(DisasContext
*ctx
, TCGv EA
)
2464 if (rA(ctx
->opcode
) == 0) {
2465 tcg_gen_movi_tl(EA
, 0);
2467 #if defined(TARGET_PPC64)
2468 if (!ctx
->sf_mode
) {
2469 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2472 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2476 static inline void gen_addr_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
2479 tcg_gen_addi_tl(ret
, arg1
, val
);
2480 #if defined(TARGET_PPC64)
2481 if (!ctx
->sf_mode
) {
2482 tcg_gen_ext32u_tl(ret
, ret
);
2487 static inline void gen_check_align(DisasContext
*ctx
, TCGv EA
, int mask
)
2489 int l1
= gen_new_label();
2490 TCGv t0
= tcg_temp_new();
2492 /* NIP cannot be restored if the memory exception comes from an helper */
2493 gen_update_nip(ctx
, ctx
->nip
- 4);
2494 tcg_gen_andi_tl(t0
, EA
, mask
);
2495 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2496 t1
= tcg_const_i32(POWERPC_EXCP_ALIGN
);
2497 t2
= tcg_const_i32(0);
2498 gen_helper_raise_exception_err(cpu_env
, t1
, t2
);
2499 tcg_temp_free_i32(t1
);
2500 tcg_temp_free_i32(t2
);
2505 /*** Integer load ***/
2506 static inline void gen_qemu_ld8u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2508 tcg_gen_qemu_ld8u(arg1
, arg2
, ctx
->mem_idx
);
2511 static inline void gen_qemu_ld8s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2513 tcg_gen_qemu_ld8s(arg1
, arg2
, ctx
->mem_idx
);
2516 static inline void gen_qemu_ld16u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2518 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2519 if (unlikely(ctx
->le_mode
)) {
2520 tcg_gen_bswap16_tl(arg1
, arg1
);
2524 static inline void gen_qemu_ld16s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2526 if (unlikely(ctx
->le_mode
)) {
2527 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2528 tcg_gen_bswap16_tl(arg1
, arg1
);
2529 tcg_gen_ext16s_tl(arg1
, arg1
);
2531 tcg_gen_qemu_ld16s(arg1
, arg2
, ctx
->mem_idx
);
2535 static inline void gen_qemu_ld32u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2537 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2538 if (unlikely(ctx
->le_mode
)) {
2539 tcg_gen_bswap32_tl(arg1
, arg1
);
2543 #if defined(TARGET_PPC64)
2544 static inline void gen_qemu_ld32s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2546 if (unlikely(ctx
->le_mode
)) {
2547 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2548 tcg_gen_bswap32_tl(arg1
, arg1
);
2549 tcg_gen_ext32s_tl(arg1
, arg1
);
2551 tcg_gen_qemu_ld32s(arg1
, arg2
, ctx
->mem_idx
);
2555 static inline void gen_qemu_ld64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2557 tcg_gen_qemu_ld64(arg1
, arg2
, ctx
->mem_idx
);
2558 if (unlikely(ctx
->le_mode
)) {
2559 tcg_gen_bswap64_i64(arg1
, arg1
);
2563 static inline void gen_qemu_st8(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2565 tcg_gen_qemu_st8(arg1
, arg2
, ctx
->mem_idx
);
2568 static inline void gen_qemu_st16(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2570 if (unlikely(ctx
->le_mode
)) {
2571 TCGv t0
= tcg_temp_new();
2572 tcg_gen_ext16u_tl(t0
, arg1
);
2573 tcg_gen_bswap16_tl(t0
, t0
);
2574 tcg_gen_qemu_st16(t0
, arg2
, ctx
->mem_idx
);
2577 tcg_gen_qemu_st16(arg1
, arg2
, ctx
->mem_idx
);
2581 static inline void gen_qemu_st32(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2583 if (unlikely(ctx
->le_mode
)) {
2584 TCGv t0
= tcg_temp_new();
2585 tcg_gen_ext32u_tl(t0
, arg1
);
2586 tcg_gen_bswap32_tl(t0
, t0
);
2587 tcg_gen_qemu_st32(t0
, arg2
, ctx
->mem_idx
);
2590 tcg_gen_qemu_st32(arg1
, arg2
, ctx
->mem_idx
);
2594 static inline void gen_qemu_st64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2596 if (unlikely(ctx
->le_mode
)) {
2597 TCGv_i64 t0
= tcg_temp_new_i64();
2598 tcg_gen_bswap64_i64(t0
, arg1
);
2599 tcg_gen_qemu_st64(t0
, arg2
, ctx
->mem_idx
);
2600 tcg_temp_free_i64(t0
);
2602 tcg_gen_qemu_st64(arg1
, arg2
, ctx
->mem_idx
);
2605 #define GEN_LD(name, ldop, opc, type) \
2606 static void glue(gen_, name)(DisasContext *ctx) \
2609 gen_set_access_type(ctx, ACCESS_INT); \
2610 EA = tcg_temp_new(); \
2611 gen_addr_imm_index(ctx, EA, 0); \
2612 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2613 tcg_temp_free(EA); \
2616 #define GEN_LDU(name, ldop, opc, type) \
2617 static void glue(gen_, name##u)(DisasContext *ctx) \
2620 if (unlikely(rA(ctx->opcode) == 0 || \
2621 rA(ctx->opcode) == rD(ctx->opcode))) { \
2622 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2625 gen_set_access_type(ctx, ACCESS_INT); \
2626 EA = tcg_temp_new(); \
2627 if (type == PPC_64B) \
2628 gen_addr_imm_index(ctx, EA, 0x03); \
2630 gen_addr_imm_index(ctx, EA, 0); \
2631 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2632 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2633 tcg_temp_free(EA); \
2636 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
2637 static void glue(gen_, name##ux)(DisasContext *ctx) \
2640 if (unlikely(rA(ctx->opcode) == 0 || \
2641 rA(ctx->opcode) == rD(ctx->opcode))) { \
2642 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2645 gen_set_access_type(ctx, ACCESS_INT); \
2646 EA = tcg_temp_new(); \
2647 gen_addr_reg_index(ctx, EA); \
2648 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2649 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2650 tcg_temp_free(EA); \
2653 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
2654 static void glue(gen_, name##x)(DisasContext *ctx) \
2657 gen_set_access_type(ctx, ACCESS_INT); \
2658 EA = tcg_temp_new(); \
2659 gen_addr_reg_index(ctx, EA); \
2660 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2661 tcg_temp_free(EA); \
2663 #define GEN_LDX(name, ldop, opc2, opc3, type) \
2664 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE)
2666 #define GEN_LDS(name, ldop, op, type) \
2667 GEN_LD(name, ldop, op | 0x20, type); \
2668 GEN_LDU(name, ldop, op | 0x21, type); \
2669 GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2670 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
2672 /* lbz lbzu lbzux lbzx */
2673 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
);
2674 /* lha lhau lhaux lhax */
2675 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
);
2676 /* lhz lhzu lhzux lhzx */
2677 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
);
2678 /* lwz lwzu lwzux lwzx */
2679 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
);
2680 #if defined(TARGET_PPC64)
2682 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
);
2684 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
);
2686 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
);
2688 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
);
2690 static void gen_ld(DisasContext
*ctx
)
2693 if (Rc(ctx
->opcode
)) {
2694 if (unlikely(rA(ctx
->opcode
) == 0 ||
2695 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
2696 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2700 gen_set_access_type(ctx
, ACCESS_INT
);
2701 EA
= tcg_temp_new();
2702 gen_addr_imm_index(ctx
, EA
, 0x03);
2703 if (ctx
->opcode
& 0x02) {
2704 /* lwa (lwau is undefined) */
2705 gen_qemu_ld32s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2708 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2710 if (Rc(ctx
->opcode
))
2711 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2716 static void gen_lq(DisasContext
*ctx
)
2718 #if defined(CONFIG_USER_ONLY)
2719 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2724 /* Restore CPU state */
2725 if (unlikely(ctx
->mem_idx
== 0)) {
2726 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2729 ra
= rA(ctx
->opcode
);
2730 rd
= rD(ctx
->opcode
);
2731 if (unlikely((rd
& 1) || rd
== ra
)) {
2732 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2735 if (unlikely(ctx
->le_mode
)) {
2736 /* Little-endian mode is not handled */
2737 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2740 gen_set_access_type(ctx
, ACCESS_INT
);
2741 EA
= tcg_temp_new();
2742 gen_addr_imm_index(ctx
, EA
, 0x0F);
2743 gen_qemu_ld64(ctx
, cpu_gpr
[rd
], EA
);
2744 gen_addr_add(ctx
, EA
, EA
, 8);
2745 gen_qemu_ld64(ctx
, cpu_gpr
[rd
+1], EA
);
2751 /*** Integer store ***/
2752 #define GEN_ST(name, stop, opc, type) \
2753 static void glue(gen_, name)(DisasContext *ctx) \
2756 gen_set_access_type(ctx, ACCESS_INT); \
2757 EA = tcg_temp_new(); \
2758 gen_addr_imm_index(ctx, EA, 0); \
2759 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2760 tcg_temp_free(EA); \
2763 #define GEN_STU(name, stop, opc, type) \
2764 static void glue(gen_, stop##u)(DisasContext *ctx) \
2767 if (unlikely(rA(ctx->opcode) == 0)) { \
2768 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2771 gen_set_access_type(ctx, ACCESS_INT); \
2772 EA = tcg_temp_new(); \
2773 if (type == PPC_64B) \
2774 gen_addr_imm_index(ctx, EA, 0x03); \
2776 gen_addr_imm_index(ctx, EA, 0); \
2777 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2778 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2779 tcg_temp_free(EA); \
2782 #define GEN_STUX(name, stop, opc2, opc3, type) \
2783 static void glue(gen_, name##ux)(DisasContext *ctx) \
2786 if (unlikely(rA(ctx->opcode) == 0)) { \
2787 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2790 gen_set_access_type(ctx, ACCESS_INT); \
2791 EA = tcg_temp_new(); \
2792 gen_addr_reg_index(ctx, EA); \
2793 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2794 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2795 tcg_temp_free(EA); \
2798 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
2799 static void glue(gen_, name##x)(DisasContext *ctx) \
2802 gen_set_access_type(ctx, ACCESS_INT); \
2803 EA = tcg_temp_new(); \
2804 gen_addr_reg_index(ctx, EA); \
2805 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2806 tcg_temp_free(EA); \
2808 #define GEN_STX(name, stop, opc2, opc3, type) \
2809 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE)
2811 #define GEN_STS(name, stop, op, type) \
2812 GEN_ST(name, stop, op | 0x20, type); \
2813 GEN_STU(name, stop, op | 0x21, type); \
2814 GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2815 GEN_STX(name, stop, 0x17, op | 0x00, type)
2817 /* stb stbu stbux stbx */
2818 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
);
2819 /* sth sthu sthux sthx */
2820 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
);
2821 /* stw stwu stwux stwx */
2822 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
);
2823 #if defined(TARGET_PPC64)
2824 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
);
2825 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
);
2827 static void gen_std(DisasContext
*ctx
)
2832 rs
= rS(ctx
->opcode
);
2833 if ((ctx
->opcode
& 0x3) == 0x2) {
2834 #if defined(CONFIG_USER_ONLY)
2835 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2838 if (unlikely(ctx
->mem_idx
== 0)) {
2839 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2842 if (unlikely(rs
& 1)) {
2843 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2846 if (unlikely(ctx
->le_mode
)) {
2847 /* Little-endian mode is not handled */
2848 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2851 gen_set_access_type(ctx
, ACCESS_INT
);
2852 EA
= tcg_temp_new();
2853 gen_addr_imm_index(ctx
, EA
, 0x03);
2854 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
2855 gen_addr_add(ctx
, EA
, EA
, 8);
2856 gen_qemu_st64(ctx
, cpu_gpr
[rs
+1], EA
);
2861 if (Rc(ctx
->opcode
)) {
2862 if (unlikely(rA(ctx
->opcode
) == 0)) {
2863 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2867 gen_set_access_type(ctx
, ACCESS_INT
);
2868 EA
= tcg_temp_new();
2869 gen_addr_imm_index(ctx
, EA
, 0x03);
2870 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
2871 if (Rc(ctx
->opcode
))
2872 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2877 /*** Integer load and store with byte reverse ***/
2879 static inline void gen_qemu_ld16ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2881 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2882 if (likely(!ctx
->le_mode
)) {
2883 tcg_gen_bswap16_tl(arg1
, arg1
);
2886 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
);
2889 static inline void gen_qemu_ld32ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2891 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2892 if (likely(!ctx
->le_mode
)) {
2893 tcg_gen_bswap32_tl(arg1
, arg1
);
2896 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
);
2898 #if defined(TARGET_PPC64)
2900 static inline void gen_qemu_ld64ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2902 tcg_gen_qemu_ld64(arg1
, arg2
, ctx
->mem_idx
);
2903 if (likely(!ctx
->le_mode
)) {
2904 tcg_gen_bswap64_tl(arg1
, arg1
);
2907 GEN_LDX_E(ldbr
, ld64ur
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
);
2908 #endif /* TARGET_PPC64 */
2911 static inline void gen_qemu_st16r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2913 if (likely(!ctx
->le_mode
)) {
2914 TCGv t0
= tcg_temp_new();
2915 tcg_gen_ext16u_tl(t0
, arg1
);
2916 tcg_gen_bswap16_tl(t0
, t0
);
2917 tcg_gen_qemu_st16(t0
, arg2
, ctx
->mem_idx
);
2920 tcg_gen_qemu_st16(arg1
, arg2
, ctx
->mem_idx
);
2923 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
);
2926 static inline void gen_qemu_st32r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2928 if (likely(!ctx
->le_mode
)) {
2929 TCGv t0
= tcg_temp_new();
2930 tcg_gen_ext32u_tl(t0
, arg1
);
2931 tcg_gen_bswap32_tl(t0
, t0
);
2932 tcg_gen_qemu_st32(t0
, arg2
, ctx
->mem_idx
);
2935 tcg_gen_qemu_st32(arg1
, arg2
, ctx
->mem_idx
);
2938 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
);
2940 #if defined(TARGET_PPC64)
2942 static inline void gen_qemu_st64r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2944 if (likely(!ctx
->le_mode
)) {
2945 TCGv t0
= tcg_temp_new();
2946 tcg_gen_bswap64_tl(t0
, arg1
);
2947 tcg_gen_qemu_st64(t0
, arg2
, ctx
->mem_idx
);
2950 tcg_gen_qemu_st64(arg1
, arg2
, ctx
->mem_idx
);
2953 GEN_STX_E(stdbr
, st64r
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
);
2954 #endif /* TARGET_PPC64 */
2956 /*** Integer load and store multiple ***/
2959 static void gen_lmw(DisasContext
*ctx
)
2963 gen_set_access_type(ctx
, ACCESS_INT
);
2964 /* NIP cannot be restored if the memory exception comes from an helper */
2965 gen_update_nip(ctx
, ctx
->nip
- 4);
2966 t0
= tcg_temp_new();
2967 t1
= tcg_const_i32(rD(ctx
->opcode
));
2968 gen_addr_imm_index(ctx
, t0
, 0);
2969 gen_helper_lmw(t0
, t1
);
2971 tcg_temp_free_i32(t1
);
2975 static void gen_stmw(DisasContext
*ctx
)
2979 gen_set_access_type(ctx
, ACCESS_INT
);
2980 /* NIP cannot be restored if the memory exception comes from an helper */
2981 gen_update_nip(ctx
, ctx
->nip
- 4);
2982 t0
= tcg_temp_new();
2983 t1
= tcg_const_i32(rS(ctx
->opcode
));
2984 gen_addr_imm_index(ctx
, t0
, 0);
2985 gen_helper_stmw(t0
, t1
);
2987 tcg_temp_free_i32(t1
);
2990 /*** Integer load and store strings ***/
2993 /* PowerPC32 specification says we must generate an exception if
2994 * rA is in the range of registers to be loaded.
2995 * In an other hand, IBM says this is valid, but rA won't be loaded.
2996 * For now, I'll follow the spec...
2998 static void gen_lswi(DisasContext
*ctx
)
3002 int nb
= NB(ctx
->opcode
);
3003 int start
= rD(ctx
->opcode
);
3004 int ra
= rA(ctx
->opcode
);
3010 if (unlikely(((start
+ nr
) > 32 &&
3011 start
<= ra
&& (start
+ nr
- 32) > ra
) ||
3012 ((start
+ nr
) <= 32 && start
<= ra
&& (start
+ nr
) > ra
))) {
3013 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
3016 gen_set_access_type(ctx
, ACCESS_INT
);
3017 /* NIP cannot be restored if the memory exception comes from an helper */
3018 gen_update_nip(ctx
, ctx
->nip
- 4);
3019 t0
= tcg_temp_new();
3020 gen_addr_register(ctx
, t0
);
3021 t1
= tcg_const_i32(nb
);
3022 t2
= tcg_const_i32(start
);
3023 gen_helper_lsw(t0
, t1
, t2
);
3025 tcg_temp_free_i32(t1
);
3026 tcg_temp_free_i32(t2
);
3030 static void gen_lswx(DisasContext
*ctx
)
3033 TCGv_i32 t1
, t2
, t3
;
3034 gen_set_access_type(ctx
, ACCESS_INT
);
3035 /* NIP cannot be restored if the memory exception comes from an helper */
3036 gen_update_nip(ctx
, ctx
->nip
- 4);
3037 t0
= tcg_temp_new();
3038 gen_addr_reg_index(ctx
, t0
);
3039 t1
= tcg_const_i32(rD(ctx
->opcode
));
3040 t2
= tcg_const_i32(rA(ctx
->opcode
));
3041 t3
= tcg_const_i32(rB(ctx
->opcode
));
3042 gen_helper_lswx(t0
, t1
, t2
, t3
);
3044 tcg_temp_free_i32(t1
);
3045 tcg_temp_free_i32(t2
);
3046 tcg_temp_free_i32(t3
);
3050 static void gen_stswi(DisasContext
*ctx
)
3054 int nb
= NB(ctx
->opcode
);
3055 gen_set_access_type(ctx
, ACCESS_INT
);
3056 /* NIP cannot be restored if the memory exception comes from an helper */
3057 gen_update_nip(ctx
, ctx
->nip
- 4);
3058 t0
= tcg_temp_new();
3059 gen_addr_register(ctx
, t0
);
3062 t1
= tcg_const_i32(nb
);
3063 t2
= tcg_const_i32(rS(ctx
->opcode
));
3064 gen_helper_stsw(t0
, t1
, t2
);
3066 tcg_temp_free_i32(t1
);
3067 tcg_temp_free_i32(t2
);
3071 static void gen_stswx(DisasContext
*ctx
)
3075 gen_set_access_type(ctx
, ACCESS_INT
);
3076 /* NIP cannot be restored if the memory exception comes from an helper */
3077 gen_update_nip(ctx
, ctx
->nip
- 4);
3078 t0
= tcg_temp_new();
3079 gen_addr_reg_index(ctx
, t0
);
3080 t1
= tcg_temp_new_i32();
3081 tcg_gen_trunc_tl_i32(t1
, cpu_xer
);
3082 tcg_gen_andi_i32(t1
, t1
, 0x7F);
3083 t2
= tcg_const_i32(rS(ctx
->opcode
));
3084 gen_helper_stsw(t0
, t1
, t2
);
3086 tcg_temp_free_i32(t1
);
3087 tcg_temp_free_i32(t2
);
3090 /*** Memory synchronisation ***/
3092 static void gen_eieio(DisasContext
*ctx
)
3097 static void gen_isync(DisasContext
*ctx
)
3099 gen_stop_exception(ctx
);
3103 static void gen_lwarx(DisasContext
*ctx
)
3106 TCGv gpr
= cpu_gpr
[rD(ctx
->opcode
)];
3107 gen_set_access_type(ctx
, ACCESS_RES
);
3108 t0
= tcg_temp_local_new();
3109 gen_addr_reg_index(ctx
, t0
);
3110 gen_check_align(ctx
, t0
, 0x03);
3111 gen_qemu_ld32u(ctx
, gpr
, t0
);
3112 tcg_gen_mov_tl(cpu_reserve
, t0
);
3113 tcg_gen_st_tl(gpr
, cpu_env
, offsetof(CPUPPCState
, reserve_val
));
3117 #if defined(CONFIG_USER_ONLY)
3118 static void gen_conditional_store (DisasContext
*ctx
, TCGv EA
,
3121 TCGv t0
= tcg_temp_new();
3122 uint32_t save_exception
= ctx
->exception
;
3124 tcg_gen_st_tl(EA
, cpu_env
, offsetof(CPUPPCState
, reserve_ea
));
3125 tcg_gen_movi_tl(t0
, (size
<< 5) | reg
);
3126 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, reserve_info
));
3128 gen_update_nip(ctx
, ctx
->nip
-4);
3129 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3130 gen_exception(ctx
, POWERPC_EXCP_STCX
);
3131 ctx
->exception
= save_exception
;
3136 static void gen_stwcx_(DisasContext
*ctx
)
3139 gen_set_access_type(ctx
, ACCESS_RES
);
3140 t0
= tcg_temp_local_new();
3141 gen_addr_reg_index(ctx
, t0
);
3142 gen_check_align(ctx
, t0
, 0x03);
3143 #if defined(CONFIG_USER_ONLY)
3144 gen_conditional_store(ctx
, t0
, rS(ctx
->opcode
), 4);
3149 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_xer
);
3150 tcg_gen_shri_i32(cpu_crf
[0], cpu_crf
[0], XER_SO
);
3151 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 1);
3152 l1
= gen_new_label();
3153 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
3154 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3155 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3157 tcg_gen_movi_tl(cpu_reserve
, -1);
3163 #if defined(TARGET_PPC64)
3165 static void gen_ldarx(DisasContext
*ctx
)
3168 TCGv gpr
= cpu_gpr
[rD(ctx
->opcode
)];
3169 gen_set_access_type(ctx
, ACCESS_RES
);
3170 t0
= tcg_temp_local_new();
3171 gen_addr_reg_index(ctx
, t0
);
3172 gen_check_align(ctx
, t0
, 0x07);
3173 gen_qemu_ld64(ctx
, gpr
, t0
);
3174 tcg_gen_mov_tl(cpu_reserve
, t0
);
3175 tcg_gen_st_tl(gpr
, cpu_env
, offsetof(CPUPPCState
, reserve_val
));
3180 static void gen_stdcx_(DisasContext
*ctx
)
3183 gen_set_access_type(ctx
, ACCESS_RES
);
3184 t0
= tcg_temp_local_new();
3185 gen_addr_reg_index(ctx
, t0
);
3186 gen_check_align(ctx
, t0
, 0x07);
3187 #if defined(CONFIG_USER_ONLY)
3188 gen_conditional_store(ctx
, t0
, rS(ctx
->opcode
), 8);
3192 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_xer
);
3193 tcg_gen_shri_i32(cpu_crf
[0], cpu_crf
[0], XER_SO
);
3194 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 1);
3195 l1
= gen_new_label();
3196 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
3197 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3198 gen_qemu_st64(ctx
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3200 tcg_gen_movi_tl(cpu_reserve
, -1);
3205 #endif /* defined(TARGET_PPC64) */
3208 static void gen_sync(DisasContext
*ctx
)
3213 static void gen_wait(DisasContext
*ctx
)
3215 TCGv_i32 t0
= tcg_temp_new_i32();
3216 tcg_gen_st_i32(t0
, cpu_env
, offsetof(CPUPPCState
, halted
));
3217 tcg_temp_free_i32(t0
);
3218 /* Stop translation, as the CPU is supposed to sleep from now */
3219 gen_exception_err(ctx
, EXCP_HLT
, 1);
3222 /*** Floating-point load ***/
3223 #define GEN_LDF(name, ldop, opc, type) \
3224 static void glue(gen_, name)(DisasContext *ctx) \
3227 if (unlikely(!ctx->fpu_enabled)) { \
3228 gen_exception(ctx, POWERPC_EXCP_FPU); \
3231 gen_set_access_type(ctx, ACCESS_FLOAT); \
3232 EA = tcg_temp_new(); \
3233 gen_addr_imm_index(ctx, EA, 0); \
3234 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3235 tcg_temp_free(EA); \
3238 #define GEN_LDUF(name, ldop, opc, type) \
3239 static void glue(gen_, name##u)(DisasContext *ctx) \
3242 if (unlikely(!ctx->fpu_enabled)) { \
3243 gen_exception(ctx, POWERPC_EXCP_FPU); \
3246 if (unlikely(rA(ctx->opcode) == 0)) { \
3247 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3250 gen_set_access_type(ctx, ACCESS_FLOAT); \
3251 EA = tcg_temp_new(); \
3252 gen_addr_imm_index(ctx, EA, 0); \
3253 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3254 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3255 tcg_temp_free(EA); \
3258 #define GEN_LDUXF(name, ldop, opc, type) \
3259 static void glue(gen_, name##ux)(DisasContext *ctx) \
3262 if (unlikely(!ctx->fpu_enabled)) { \
3263 gen_exception(ctx, POWERPC_EXCP_FPU); \
3266 if (unlikely(rA(ctx->opcode) == 0)) { \
3267 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3270 gen_set_access_type(ctx, ACCESS_FLOAT); \
3271 EA = tcg_temp_new(); \
3272 gen_addr_reg_index(ctx, EA); \
3273 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3274 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3275 tcg_temp_free(EA); \
3278 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
3279 static void glue(gen_, name##x)(DisasContext *ctx) \
3282 if (unlikely(!ctx->fpu_enabled)) { \
3283 gen_exception(ctx, POWERPC_EXCP_FPU); \
3286 gen_set_access_type(ctx, ACCESS_FLOAT); \
3287 EA = tcg_temp_new(); \
3288 gen_addr_reg_index(ctx, EA); \
3289 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3290 tcg_temp_free(EA); \
3293 #define GEN_LDFS(name, ldop, op, type) \
3294 GEN_LDF(name, ldop, op | 0x20, type); \
3295 GEN_LDUF(name, ldop, op | 0x21, type); \
3296 GEN_LDUXF(name, ldop, op | 0x01, type); \
3297 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3299 static inline void gen_qemu_ld32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3301 TCGv t0
= tcg_temp_new();
3302 TCGv_i32 t1
= tcg_temp_new_i32();
3303 gen_qemu_ld32u(ctx
, t0
, arg2
);
3304 tcg_gen_trunc_tl_i32(t1
, t0
);
3306 gen_helper_float32_to_float64(arg1
, t1
);
3307 tcg_temp_free_i32(t1
);
3310 /* lfd lfdu lfdux lfdx */
3311 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
);
3312 /* lfs lfsu lfsux lfsx */
3313 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
);
3315 /*** Floating-point store ***/
3316 #define GEN_STF(name, stop, opc, type) \
3317 static void glue(gen_, name)(DisasContext *ctx) \
3320 if (unlikely(!ctx->fpu_enabled)) { \
3321 gen_exception(ctx, POWERPC_EXCP_FPU); \
3324 gen_set_access_type(ctx, ACCESS_FLOAT); \
3325 EA = tcg_temp_new(); \
3326 gen_addr_imm_index(ctx, EA, 0); \
3327 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3328 tcg_temp_free(EA); \
3331 #define GEN_STUF(name, stop, opc, type) \
3332 static void glue(gen_, name##u)(DisasContext *ctx) \
3335 if (unlikely(!ctx->fpu_enabled)) { \
3336 gen_exception(ctx, POWERPC_EXCP_FPU); \
3339 if (unlikely(rA(ctx->opcode) == 0)) { \
3340 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3343 gen_set_access_type(ctx, ACCESS_FLOAT); \
3344 EA = tcg_temp_new(); \
3345 gen_addr_imm_index(ctx, EA, 0); \
3346 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3347 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3348 tcg_temp_free(EA); \
3351 #define GEN_STUXF(name, stop, opc, type) \
3352 static void glue(gen_, name##ux)(DisasContext *ctx) \
3355 if (unlikely(!ctx->fpu_enabled)) { \
3356 gen_exception(ctx, POWERPC_EXCP_FPU); \
3359 if (unlikely(rA(ctx->opcode) == 0)) { \
3360 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3363 gen_set_access_type(ctx, ACCESS_FLOAT); \
3364 EA = tcg_temp_new(); \
3365 gen_addr_reg_index(ctx, EA); \
3366 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3367 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3368 tcg_temp_free(EA); \
3371 #define GEN_STXF(name, stop, opc2, opc3, type) \
3372 static void glue(gen_, name##x)(DisasContext *ctx) \
3375 if (unlikely(!ctx->fpu_enabled)) { \
3376 gen_exception(ctx, POWERPC_EXCP_FPU); \
3379 gen_set_access_type(ctx, ACCESS_FLOAT); \
3380 EA = tcg_temp_new(); \
3381 gen_addr_reg_index(ctx, EA); \
3382 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3383 tcg_temp_free(EA); \
3386 #define GEN_STFS(name, stop, op, type) \
3387 GEN_STF(name, stop, op | 0x20, type); \
3388 GEN_STUF(name, stop, op | 0x21, type); \
3389 GEN_STUXF(name, stop, op | 0x01, type); \
3390 GEN_STXF(name, stop, 0x17, op | 0x00, type)
3392 static inline void gen_qemu_st32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3394 TCGv_i32 t0
= tcg_temp_new_i32();
3395 TCGv t1
= tcg_temp_new();
3396 gen_helper_float64_to_float32(t0
, arg1
);
3397 tcg_gen_extu_i32_tl(t1
, t0
);
3398 tcg_temp_free_i32(t0
);
3399 gen_qemu_st32(ctx
, t1
, arg2
);
3403 /* stfd stfdu stfdux stfdx */
3404 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
);
3405 /* stfs stfsu stfsux stfsx */
3406 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
);
3409 static inline void gen_qemu_st32fiw(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3411 TCGv t0
= tcg_temp_new();
3412 tcg_gen_trunc_i64_tl(t0
, arg1
),
3413 gen_qemu_st32(ctx
, t0
, arg2
);
3417 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
);
3419 static inline void gen_update_cfar(DisasContext
*ctx
, target_ulong nip
)
3421 #if defined(TARGET_PPC64)
3423 tcg_gen_movi_tl(cpu_cfar
, nip
);
3428 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
3430 TranslationBlock
*tb
;
3432 #if defined(TARGET_PPC64)
3434 dest
= (uint32_t) dest
;
3436 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
3437 likely(!ctx
->singlestep_enabled
)) {
3439 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3440 tcg_gen_exit_tb((tcg_target_long
)tb
+ n
);
3442 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3443 if (unlikely(ctx
->singlestep_enabled
)) {
3444 if ((ctx
->singlestep_enabled
&
3445 (CPU_BRANCH_STEP
| CPU_SINGLE_STEP
)) &&
3446 ctx
->exception
== POWERPC_EXCP_BRANCH
) {
3447 target_ulong tmp
= ctx
->nip
;
3449 gen_exception(ctx
, POWERPC_EXCP_TRACE
);
3452 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
3453 gen_debug_exception(ctx
);
3460 static inline void gen_setlr(DisasContext
*ctx
, target_ulong nip
)
3462 #if defined(TARGET_PPC64)
3463 if (ctx
->sf_mode
== 0)
3464 tcg_gen_movi_tl(cpu_lr
, (uint32_t)nip
);
3467 tcg_gen_movi_tl(cpu_lr
, nip
);
3471 static void gen_b(DisasContext
*ctx
)
3473 target_ulong li
, target
;
3475 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3476 /* sign extend LI */
3477 #if defined(TARGET_PPC64)
3479 li
= ((int64_t)LI(ctx
->opcode
) << 38) >> 38;
3482 li
= ((int32_t)LI(ctx
->opcode
) << 6) >> 6;
3483 if (likely(AA(ctx
->opcode
) == 0))
3484 target
= ctx
->nip
+ li
- 4;
3487 if (LK(ctx
->opcode
))
3488 gen_setlr(ctx
, ctx
->nip
);
3489 gen_update_cfar(ctx
, ctx
->nip
);
3490 gen_goto_tb(ctx
, 0, target
);
3497 static inline void gen_bcond(DisasContext
*ctx
, int type
)
3499 uint32_t bo
= BO(ctx
->opcode
);
3503 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3504 if (type
== BCOND_LR
|| type
== BCOND_CTR
) {
3505 target
= tcg_temp_local_new();
3506 if (type
== BCOND_CTR
)
3507 tcg_gen_mov_tl(target
, cpu_ctr
);
3509 tcg_gen_mov_tl(target
, cpu_lr
);
3511 TCGV_UNUSED(target
);
3513 if (LK(ctx
->opcode
))
3514 gen_setlr(ctx
, ctx
->nip
);
3515 l1
= gen_new_label();
3516 if ((bo
& 0x4) == 0) {
3517 /* Decrement and test CTR */
3518 TCGv temp
= tcg_temp_new();
3519 if (unlikely(type
== BCOND_CTR
)) {
3520 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3523 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
3524 #if defined(TARGET_PPC64)
3526 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
3529 tcg_gen_mov_tl(temp
, cpu_ctr
);
3531 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
3533 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
3535 tcg_temp_free(temp
);
3537 if ((bo
& 0x10) == 0) {
3539 uint32_t bi
= BI(ctx
->opcode
);
3540 uint32_t mask
= 1 << (3 - (bi
& 0x03));
3541 TCGv_i32 temp
= tcg_temp_new_i32();
3544 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3545 tcg_gen_brcondi_i32(TCG_COND_EQ
, temp
, 0, l1
);
3547 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3548 tcg_gen_brcondi_i32(TCG_COND_NE
, temp
, 0, l1
);
3550 tcg_temp_free_i32(temp
);
3552 gen_update_cfar(ctx
, ctx
->nip
);
3553 if (type
== BCOND_IM
) {
3554 target_ulong li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
3555 if (likely(AA(ctx
->opcode
) == 0)) {
3556 gen_goto_tb(ctx
, 0, ctx
->nip
+ li
- 4);
3558 gen_goto_tb(ctx
, 0, li
);
3561 gen_goto_tb(ctx
, 1, ctx
->nip
);
3563 #if defined(TARGET_PPC64)
3564 if (!(ctx
->sf_mode
))
3565 tcg_gen_andi_tl(cpu_nip
, target
, (uint32_t)~3);
3568 tcg_gen_andi_tl(cpu_nip
, target
, ~3);
3571 #if defined(TARGET_PPC64)
3572 if (!(ctx
->sf_mode
))
3573 tcg_gen_movi_tl(cpu_nip
, (uint32_t)ctx
->nip
);
3576 tcg_gen_movi_tl(cpu_nip
, ctx
->nip
);
3581 static void gen_bc(DisasContext
*ctx
)
3583 gen_bcond(ctx
, BCOND_IM
);
3586 static void gen_bcctr(DisasContext
*ctx
)
3588 gen_bcond(ctx
, BCOND_CTR
);
3591 static void gen_bclr(DisasContext
*ctx
)
3593 gen_bcond(ctx
, BCOND_LR
);
3596 /*** Condition register logical ***/
3597 #define GEN_CRLOGIC(name, tcg_op, opc) \
3598 static void glue(gen_, name)(DisasContext *ctx) \
3603 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3604 t0 = tcg_temp_new_i32(); \
3606 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
3608 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
3610 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
3611 t1 = tcg_temp_new_i32(); \
3612 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3614 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
3616 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
3618 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3619 tcg_op(t0, t0, t1); \
3620 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
3621 tcg_gen_andi_i32(t0, t0, bitmask); \
3622 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3623 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
3624 tcg_temp_free_i32(t0); \
3625 tcg_temp_free_i32(t1); \
3629 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08);
3631 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04);
3633 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09);
3635 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07);
3637 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01);
3639 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E);
3641 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D);
3643 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06);
3646 static void gen_mcrf(DisasContext
*ctx
)
3648 tcg_gen_mov_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfS(ctx
->opcode
)]);
3651 /*** System linkage ***/
3653 /* rfi (mem_idx only) */
3654 static void gen_rfi(DisasContext
*ctx
)
3656 #if defined(CONFIG_USER_ONLY)
3657 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3659 /* Restore CPU state */
3660 if (unlikely(!ctx
->mem_idx
)) {
3661 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3664 gen_update_cfar(ctx
, ctx
->nip
);
3665 gen_helper_rfi(cpu_env
);
3666 gen_sync_exception(ctx
);
3670 #if defined(TARGET_PPC64)
3671 static void gen_rfid(DisasContext
*ctx
)
3673 #if defined(CONFIG_USER_ONLY)
3674 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3676 /* Restore CPU state */
3677 if (unlikely(!ctx
->mem_idx
)) {
3678 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3681 gen_update_cfar(ctx
, ctx
->nip
);
3682 gen_helper_rfid(cpu_env
);
3683 gen_sync_exception(ctx
);
3687 static void gen_hrfid(DisasContext
*ctx
)
3689 #if defined(CONFIG_USER_ONLY)
3690 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3692 /* Restore CPU state */
3693 if (unlikely(ctx
->mem_idx
<= 1)) {
3694 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3697 gen_helper_hrfid(cpu_env
);
3698 gen_sync_exception(ctx
);
3704 #if defined(CONFIG_USER_ONLY)
3705 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3707 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3709 static void gen_sc(DisasContext
*ctx
)
3713 lev
= (ctx
->opcode
>> 5) & 0x7F;
3714 gen_exception_err(ctx
, POWERPC_SYSCALL
, lev
);
3720 static void gen_tw(DisasContext
*ctx
)
3722 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3723 /* Update the nip since this might generate a trap exception */
3724 gen_update_nip(ctx
, ctx
->nip
);
3725 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
3727 tcg_temp_free_i32(t0
);
3731 static void gen_twi(DisasContext
*ctx
)
3733 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3734 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
3735 /* Update the nip since this might generate a trap exception */
3736 gen_update_nip(ctx
, ctx
->nip
);
3737 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3739 tcg_temp_free_i32(t1
);
3742 #if defined(TARGET_PPC64)
3744 static void gen_td(DisasContext
*ctx
)
3746 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3747 /* Update the nip since this might generate a trap exception */
3748 gen_update_nip(ctx
, ctx
->nip
);
3749 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
3751 tcg_temp_free_i32(t0
);
3755 static void gen_tdi(DisasContext
*ctx
)
3757 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3758 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
3759 /* Update the nip since this might generate a trap exception */
3760 gen_update_nip(ctx
, ctx
->nip
);
3761 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3763 tcg_temp_free_i32(t1
);
3767 /*** Processor control ***/
3770 static void gen_mcrxr(DisasContext
*ctx
)
3772 tcg_gen_trunc_tl_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_xer
);
3773 tcg_gen_shri_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfD(ctx
->opcode
)], XER_CA
);
3774 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_SO
| 1 << XER_OV
| 1 << XER_CA
));
3778 static void gen_mfcr(DisasContext
*ctx
)
3782 if (likely(ctx
->opcode
& 0x00100000)) {
3783 crm
= CRM(ctx
->opcode
);
3784 if (likely(crm
&& ((crm
& (crm
- 1)) == 0))) {
3786 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_crf
[7 - crn
]);
3787 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)],
3788 cpu_gpr
[rD(ctx
->opcode
)], crn
* 4);
3791 TCGv_i32 t0
= tcg_temp_new_i32();
3792 tcg_gen_mov_i32(t0
, cpu_crf
[0]);
3793 tcg_gen_shli_i32(t0
, t0
, 4);
3794 tcg_gen_or_i32(t0
, t0
, cpu_crf
[1]);
3795 tcg_gen_shli_i32(t0
, t0
, 4);
3796 tcg_gen_or_i32(t0
, t0
, cpu_crf
[2]);
3797 tcg_gen_shli_i32(t0
, t0
, 4);
3798 tcg_gen_or_i32(t0
, t0
, cpu_crf
[3]);
3799 tcg_gen_shli_i32(t0
, t0
, 4);
3800 tcg_gen_or_i32(t0
, t0
, cpu_crf
[4]);
3801 tcg_gen_shli_i32(t0
, t0
, 4);
3802 tcg_gen_or_i32(t0
, t0
, cpu_crf
[5]);
3803 tcg_gen_shli_i32(t0
, t0
, 4);
3804 tcg_gen_or_i32(t0
, t0
, cpu_crf
[6]);
3805 tcg_gen_shli_i32(t0
, t0
, 4);
3806 tcg_gen_or_i32(t0
, t0
, cpu_crf
[7]);
3807 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
3808 tcg_temp_free_i32(t0
);
3813 static void gen_mfmsr(DisasContext
*ctx
)
3815 #if defined(CONFIG_USER_ONLY)
3816 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3818 if (unlikely(!ctx
->mem_idx
)) {
3819 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3822 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_msr
);
3826 static void spr_noaccess(void *opaque
, int gprn
, int sprn
)
3829 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
3830 printf("ERROR: try to access SPR %d !\n", sprn
);
3833 #define SPR_NOACCESS (&spr_noaccess)
3836 static inline void gen_op_mfspr(DisasContext
*ctx
)
3838 void (*read_cb
)(void *opaque
, int gprn
, int sprn
);
3839 uint32_t sprn
= SPR(ctx
->opcode
);
3841 #if !defined(CONFIG_USER_ONLY)
3842 if (ctx
->mem_idx
== 2)
3843 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
3844 else if (ctx
->mem_idx
)
3845 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
3848 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
3849 if (likely(read_cb
!= NULL
)) {
3850 if (likely(read_cb
!= SPR_NOACCESS
)) {
3851 (*read_cb
)(ctx
, rD(ctx
->opcode
), sprn
);
3853 /* Privilege exception */
3854 /* This is a hack to avoid warnings when running Linux:
3855 * this OS breaks the PowerPC virtualisation model,
3856 * allowing userland application to read the PVR
3858 if (sprn
!= SPR_PVR
) {
3859 qemu_log("Trying to read privileged spr %d %03x at "
3860 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
3861 printf("Trying to read privileged spr %d %03x at "
3862 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
3864 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3868 qemu_log("Trying to read invalid spr %d %03x at "
3869 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
3870 printf("Trying to read invalid spr %d %03x at " TARGET_FMT_lx
"\n",
3871 sprn
, sprn
, ctx
->nip
);
3872 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
3876 static void gen_mfspr(DisasContext
*ctx
)
3882 static void gen_mftb(DisasContext
*ctx
)
3888 static void gen_mtcrf(DisasContext
*ctx
)
3892 crm
= CRM(ctx
->opcode
);
3893 if (likely((ctx
->opcode
& 0x00100000))) {
3894 if (crm
&& ((crm
& (crm
- 1)) == 0)) {
3895 TCGv_i32 temp
= tcg_temp_new_i32();
3897 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
3898 tcg_gen_shri_i32(temp
, temp
, crn
* 4);
3899 tcg_gen_andi_i32(cpu_crf
[7 - crn
], temp
, 0xf);
3900 tcg_temp_free_i32(temp
);
3903 TCGv_i32 temp
= tcg_temp_new_i32();
3904 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
3905 for (crn
= 0 ; crn
< 8 ; crn
++) {
3906 if (crm
& (1 << crn
)) {
3907 tcg_gen_shri_i32(cpu_crf
[7 - crn
], temp
, crn
* 4);
3908 tcg_gen_andi_i32(cpu_crf
[7 - crn
], cpu_crf
[7 - crn
], 0xf);
3911 tcg_temp_free_i32(temp
);
3916 #if defined(TARGET_PPC64)
3917 static void gen_mtmsrd(DisasContext
*ctx
)
3919 #if defined(CONFIG_USER_ONLY)
3920 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3922 if (unlikely(!ctx
->mem_idx
)) {
3923 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3926 if (ctx
->opcode
& 0x00010000) {
3927 /* Special form that does not need any synchronisation */
3928 TCGv t0
= tcg_temp_new();
3929 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
3930 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
3931 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
3934 /* XXX: we need to update nip before the store
3935 * if we enter power saving mode, we will exit the loop
3936 * directly from ppc_store_msr
3938 gen_update_nip(ctx
, ctx
->nip
);
3939 gen_helper_store_msr(cpu_env
, cpu_gpr
[rS(ctx
->opcode
)]);
3940 /* Must stop the translation as machine state (may have) changed */
3941 /* Note that mtmsr is not always defined as context-synchronizing */
3942 gen_stop_exception(ctx
);
3948 static void gen_mtmsr(DisasContext
*ctx
)
3950 #if defined(CONFIG_USER_ONLY)
3951 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3953 if (unlikely(!ctx
->mem_idx
)) {
3954 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3957 if (ctx
->opcode
& 0x00010000) {
3958 /* Special form that does not need any synchronisation */
3959 TCGv t0
= tcg_temp_new();
3960 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
3961 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
3962 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
3965 TCGv msr
= tcg_temp_new();
3967 /* XXX: we need to update nip before the store
3968 * if we enter power saving mode, we will exit the loop
3969 * directly from ppc_store_msr
3971 gen_update_nip(ctx
, ctx
->nip
);
3972 #if defined(TARGET_PPC64)
3973 tcg_gen_deposit_tl(msr
, cpu_msr
, cpu_gpr
[rS(ctx
->opcode
)], 0, 32);
3975 tcg_gen_mov_tl(msr
, cpu_gpr
[rS(ctx
->opcode
)]);
3977 gen_helper_store_msr(cpu_env
, msr
);
3978 /* Must stop the translation as machine state (may have) changed */
3979 /* Note that mtmsr is not always defined as context-synchronizing */
3980 gen_stop_exception(ctx
);
3986 static void gen_mtspr(DisasContext
*ctx
)
3988 void (*write_cb
)(void *opaque
, int sprn
, int gprn
);
3989 uint32_t sprn
= SPR(ctx
->opcode
);
3991 #if !defined(CONFIG_USER_ONLY)
3992 if (ctx
->mem_idx
== 2)
3993 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
3994 else if (ctx
->mem_idx
)
3995 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
3998 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
3999 if (likely(write_cb
!= NULL
)) {
4000 if (likely(write_cb
!= SPR_NOACCESS
)) {
4001 (*write_cb
)(ctx
, sprn
, rS(ctx
->opcode
));
4003 /* Privilege exception */
4004 qemu_log("Trying to write privileged spr %d %03x at "
4005 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
4006 printf("Trying to write privileged spr %d %03x at " TARGET_FMT_lx
4007 "\n", sprn
, sprn
, ctx
->nip
);
4008 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4012 qemu_log("Trying to write invalid spr %d %03x at "
4013 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
4014 printf("Trying to write invalid spr %d %03x at " TARGET_FMT_lx
"\n",
4015 sprn
, sprn
, ctx
->nip
);
4016 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4020 /*** Cache management ***/
4023 static void gen_dcbf(DisasContext
*ctx
)
4025 /* XXX: specification says this is treated as a load by the MMU */
4027 gen_set_access_type(ctx
, ACCESS_CACHE
);
4028 t0
= tcg_temp_new();
4029 gen_addr_reg_index(ctx
, t0
);
4030 gen_qemu_ld8u(ctx
, t0
, t0
);
4034 /* dcbi (Supervisor only) */
4035 static void gen_dcbi(DisasContext
*ctx
)
4037 #if defined(CONFIG_USER_ONLY)
4038 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4041 if (unlikely(!ctx
->mem_idx
)) {
4042 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4045 EA
= tcg_temp_new();
4046 gen_set_access_type(ctx
, ACCESS_CACHE
);
4047 gen_addr_reg_index(ctx
, EA
);
4048 val
= tcg_temp_new();
4049 /* XXX: specification says this should be treated as a store by the MMU */
4050 gen_qemu_ld8u(ctx
, val
, EA
);
4051 gen_qemu_st8(ctx
, val
, EA
);
4058 static void gen_dcbst(DisasContext
*ctx
)
4060 /* XXX: specification say this is treated as a load by the MMU */
4062 gen_set_access_type(ctx
, ACCESS_CACHE
);
4063 t0
= tcg_temp_new();
4064 gen_addr_reg_index(ctx
, t0
);
4065 gen_qemu_ld8u(ctx
, t0
, t0
);
4070 static void gen_dcbt(DisasContext
*ctx
)
4072 /* interpreted as no-op */
4073 /* XXX: specification say this is treated as a load by the MMU
4074 * but does not generate any exception
4079 static void gen_dcbtst(DisasContext
*ctx
)
4081 /* interpreted as no-op */
4082 /* XXX: specification say this is treated as a load by the MMU
4083 * but does not generate any exception
4088 static void gen_dcbz(DisasContext
*ctx
)
4091 gen_set_access_type(ctx
, ACCESS_CACHE
);
4092 /* NIP cannot be restored if the memory exception comes from an helper */
4093 gen_update_nip(ctx
, ctx
->nip
- 4);
4094 t0
= tcg_temp_new();
4095 gen_addr_reg_index(ctx
, t0
);
4096 gen_helper_dcbz(t0
);
4100 static void gen_dcbz_970(DisasContext
*ctx
)
4103 gen_set_access_type(ctx
, ACCESS_CACHE
);
4104 /* NIP cannot be restored if the memory exception comes from an helper */
4105 gen_update_nip(ctx
, ctx
->nip
- 4);
4106 t0
= tcg_temp_new();
4107 gen_addr_reg_index(ctx
, t0
);
4108 if (ctx
->opcode
& 0x00200000)
4109 gen_helper_dcbz(t0
);
4111 gen_helper_dcbz_970(t0
);
4116 static void gen_dst(DisasContext
*ctx
)
4118 if (rA(ctx
->opcode
) == 0) {
4119 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
4121 /* interpreted as no-op */
4126 static void gen_dstst(DisasContext
*ctx
)
4128 if (rA(ctx
->opcode
) == 0) {
4129 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
4131 /* interpreted as no-op */
4137 static void gen_dss(DisasContext
*ctx
)
4139 /* interpreted as no-op */
4143 static void gen_icbi(DisasContext
*ctx
)
4146 gen_set_access_type(ctx
, ACCESS_CACHE
);
4147 /* NIP cannot be restored if the memory exception comes from an helper */
4148 gen_update_nip(ctx
, ctx
->nip
- 4);
4149 t0
= tcg_temp_new();
4150 gen_addr_reg_index(ctx
, t0
);
4151 gen_helper_icbi(t0
);
4157 static void gen_dcba(DisasContext
*ctx
)
4159 /* interpreted as no-op */
4160 /* XXX: specification say this is treated as a store by the MMU
4161 * but does not generate any exception
4165 /*** Segment register manipulation ***/
4166 /* Supervisor only: */
4169 static void gen_mfsr(DisasContext
*ctx
)
4171 #if defined(CONFIG_USER_ONLY)
4172 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4175 if (unlikely(!ctx
->mem_idx
)) {
4176 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4179 t0
= tcg_const_tl(SR(ctx
->opcode
));
4180 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4186 static void gen_mfsrin(DisasContext
*ctx
)
4188 #if defined(CONFIG_USER_ONLY)
4189 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4192 if (unlikely(!ctx
->mem_idx
)) {
4193 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4196 t0
= tcg_temp_new();
4197 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4198 tcg_gen_andi_tl(t0
, t0
, 0xF);
4199 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4205 static void gen_mtsr(DisasContext
*ctx
)
4207 #if defined(CONFIG_USER_ONLY)
4208 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4211 if (unlikely(!ctx
->mem_idx
)) {
4212 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4215 t0
= tcg_const_tl(SR(ctx
->opcode
));
4216 gen_helper_store_sr(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4222 static void gen_mtsrin(DisasContext
*ctx
)
4224 #if defined(CONFIG_USER_ONLY)
4225 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4228 if (unlikely(!ctx
->mem_idx
)) {
4229 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4232 t0
= tcg_temp_new();
4233 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4234 tcg_gen_andi_tl(t0
, t0
, 0xF);
4235 gen_helper_store_sr(t0
, cpu_gpr
[rD(ctx
->opcode
)]);
4240 #if defined(TARGET_PPC64)
4241 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4244 static void gen_mfsr_64b(DisasContext
*ctx
)
4246 #if defined(CONFIG_USER_ONLY)
4247 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4250 if (unlikely(!ctx
->mem_idx
)) {
4251 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4254 t0
= tcg_const_tl(SR(ctx
->opcode
));
4255 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4261 static void gen_mfsrin_64b(DisasContext
*ctx
)
4263 #if defined(CONFIG_USER_ONLY)
4264 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4267 if (unlikely(!ctx
->mem_idx
)) {
4268 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4271 t0
= tcg_temp_new();
4272 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4273 tcg_gen_andi_tl(t0
, t0
, 0xF);
4274 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4280 static void gen_mtsr_64b(DisasContext
*ctx
)
4282 #if defined(CONFIG_USER_ONLY)
4283 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4286 if (unlikely(!ctx
->mem_idx
)) {
4287 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4290 t0
= tcg_const_tl(SR(ctx
->opcode
));
4291 gen_helper_store_sr(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4297 static void gen_mtsrin_64b(DisasContext
*ctx
)
4299 #if defined(CONFIG_USER_ONLY)
4300 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4303 if (unlikely(!ctx
->mem_idx
)) {
4304 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4307 t0
= tcg_temp_new();
4308 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4309 tcg_gen_andi_tl(t0
, t0
, 0xF);
4310 gen_helper_store_sr(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4316 static void gen_slbmte(DisasContext
*ctx
)
4318 #if defined(CONFIG_USER_ONLY)
4319 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4321 if (unlikely(!ctx
->mem_idx
)) {
4322 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4325 gen_helper_store_slb(cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
4329 static void gen_slbmfee(DisasContext
*ctx
)
4331 #if defined(CONFIG_USER_ONLY)
4332 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4334 if (unlikely(!ctx
->mem_idx
)) {
4335 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4338 gen_helper_load_slb_esid(cpu_gpr
[rS(ctx
->opcode
)],
4339 cpu_gpr
[rB(ctx
->opcode
)]);
4343 static void gen_slbmfev(DisasContext
*ctx
)
4345 #if defined(CONFIG_USER_ONLY)
4346 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4348 if (unlikely(!ctx
->mem_idx
)) {
4349 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4352 gen_helper_load_slb_vsid(cpu_gpr
[rS(ctx
->opcode
)],
4353 cpu_gpr
[rB(ctx
->opcode
)]);
4356 #endif /* defined(TARGET_PPC64) */
4358 /*** Lookaside buffer management ***/
4359 /* Optional & mem_idx only: */
4362 static void gen_tlbia(DisasContext
*ctx
)
4364 #if defined(CONFIG_USER_ONLY)
4365 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4367 if (unlikely(!ctx
->mem_idx
)) {
4368 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4376 static void gen_tlbiel(DisasContext
*ctx
)
4378 #if defined(CONFIG_USER_ONLY)
4379 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4381 if (unlikely(!ctx
->mem_idx
)) {
4382 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4385 gen_helper_tlbie(cpu_gpr
[rB(ctx
->opcode
)]);
4390 static void gen_tlbie(DisasContext
*ctx
)
4392 #if defined(CONFIG_USER_ONLY)
4393 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4395 if (unlikely(!ctx
->mem_idx
)) {
4396 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4399 #if defined(TARGET_PPC64)
4400 if (!ctx
->sf_mode
) {
4401 TCGv t0
= tcg_temp_new();
4402 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
4403 gen_helper_tlbie(t0
);
4407 gen_helper_tlbie(cpu_gpr
[rB(ctx
->opcode
)]);
4412 static void gen_tlbsync(DisasContext
*ctx
)
4414 #if defined(CONFIG_USER_ONLY)
4415 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4417 if (unlikely(!ctx
->mem_idx
)) {
4418 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4421 /* This has no effect: it should ensure that all previous
4422 * tlbie have completed
4424 gen_stop_exception(ctx
);
4428 #if defined(TARGET_PPC64)
4430 static void gen_slbia(DisasContext
*ctx
)
4432 #if defined(CONFIG_USER_ONLY)
4433 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4435 if (unlikely(!ctx
->mem_idx
)) {
4436 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4444 static void gen_slbie(DisasContext
*ctx
)
4446 #if defined(CONFIG_USER_ONLY)
4447 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4449 if (unlikely(!ctx
->mem_idx
)) {
4450 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4453 gen_helper_slbie(cpu_gpr
[rB(ctx
->opcode
)]);
4458 /*** External control ***/
4462 static void gen_eciwx(DisasContext
*ctx
)
4465 /* Should check EAR[E] ! */
4466 gen_set_access_type(ctx
, ACCESS_EXT
);
4467 t0
= tcg_temp_new();
4468 gen_addr_reg_index(ctx
, t0
);
4469 gen_check_align(ctx
, t0
, 0x03);
4470 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4475 static void gen_ecowx(DisasContext
*ctx
)
4478 /* Should check EAR[E] ! */
4479 gen_set_access_type(ctx
, ACCESS_EXT
);
4480 t0
= tcg_temp_new();
4481 gen_addr_reg_index(ctx
, t0
);
4482 gen_check_align(ctx
, t0
, 0x03);
4483 gen_qemu_st32(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4487 /* PowerPC 601 specific instructions */
4490 static void gen_abs(DisasContext
*ctx
)
4492 int l1
= gen_new_label();
4493 int l2
= gen_new_label();
4494 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4495 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4498 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4500 if (unlikely(Rc(ctx
->opcode
) != 0))
4501 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4505 static void gen_abso(DisasContext
*ctx
)
4507 int l1
= gen_new_label();
4508 int l2
= gen_new_label();
4509 int l3
= gen_new_label();
4510 /* Start with XER OV disabled, the most likely case */
4511 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
4512 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l2
);
4513 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rA(ctx
->opcode
)], 0x80000000, l1
);
4514 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
4517 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4520 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4522 if (unlikely(Rc(ctx
->opcode
) != 0))
4523 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4527 static void gen_clcs(DisasContext
*ctx
)
4529 TCGv_i32 t0
= tcg_const_i32(rA(ctx
->opcode
));
4530 gen_helper_clcs(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4531 tcg_temp_free_i32(t0
);
4532 /* Rc=1 sets CR0 to an undefined state */
4536 static void gen_div(DisasContext
*ctx
)
4538 gen_helper_div(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4539 if (unlikely(Rc(ctx
->opcode
) != 0))
4540 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4544 static void gen_divo(DisasContext
*ctx
)
4546 gen_helper_divo(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4547 if (unlikely(Rc(ctx
->opcode
) != 0))
4548 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4552 static void gen_divs(DisasContext
*ctx
)
4554 gen_helper_divs(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4555 if (unlikely(Rc(ctx
->opcode
) != 0))
4556 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4559 /* divso - divso. */
4560 static void gen_divso(DisasContext
*ctx
)
4562 gen_helper_divso(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4563 if (unlikely(Rc(ctx
->opcode
) != 0))
4564 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4568 static void gen_doz(DisasContext
*ctx
)
4570 int l1
= gen_new_label();
4571 int l2
= gen_new_label();
4572 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4573 tcg_gen_sub_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4576 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4578 if (unlikely(Rc(ctx
->opcode
) != 0))
4579 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4583 static void gen_dozo(DisasContext
*ctx
)
4585 int l1
= gen_new_label();
4586 int l2
= gen_new_label();
4587 TCGv t0
= tcg_temp_new();
4588 TCGv t1
= tcg_temp_new();
4589 TCGv t2
= tcg_temp_new();
4590 /* Start with XER OV disabled, the most likely case */
4591 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
4592 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4593 tcg_gen_sub_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4594 tcg_gen_xor_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4595 tcg_gen_xor_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], t0
);
4596 tcg_gen_andc_tl(t1
, t1
, t2
);
4597 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4598 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
4599 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
4602 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4607 if (unlikely(Rc(ctx
->opcode
) != 0))
4608 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4612 static void gen_dozi(DisasContext
*ctx
)
4614 target_long simm
= SIMM(ctx
->opcode
);
4615 int l1
= gen_new_label();
4616 int l2
= gen_new_label();
4617 tcg_gen_brcondi_tl(TCG_COND_LT
, cpu_gpr
[rA(ctx
->opcode
)], simm
, l1
);
4618 tcg_gen_subfi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
, cpu_gpr
[rA(ctx
->opcode
)]);
4621 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4623 if (unlikely(Rc(ctx
->opcode
) != 0))
4624 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4627 /* lscbx - lscbx. */
4628 static void gen_lscbx(DisasContext
*ctx
)
4630 TCGv t0
= tcg_temp_new();
4631 TCGv_i32 t1
= tcg_const_i32(rD(ctx
->opcode
));
4632 TCGv_i32 t2
= tcg_const_i32(rA(ctx
->opcode
));
4633 TCGv_i32 t3
= tcg_const_i32(rB(ctx
->opcode
));
4635 gen_addr_reg_index(ctx
, t0
);
4636 /* NIP cannot be restored if the memory exception comes from an helper */
4637 gen_update_nip(ctx
, ctx
->nip
- 4);
4638 gen_helper_lscbx(t0
, t0
, t1
, t2
, t3
);
4639 tcg_temp_free_i32(t1
);
4640 tcg_temp_free_i32(t2
);
4641 tcg_temp_free_i32(t3
);
4642 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~0x7F);
4643 tcg_gen_or_tl(cpu_xer
, cpu_xer
, t0
);
4644 if (unlikely(Rc(ctx
->opcode
) != 0))
4645 gen_set_Rc0(ctx
, t0
);
4649 /* maskg - maskg. */
4650 static void gen_maskg(DisasContext
*ctx
)
4652 int l1
= gen_new_label();
4653 TCGv t0
= tcg_temp_new();
4654 TCGv t1
= tcg_temp_new();
4655 TCGv t2
= tcg_temp_new();
4656 TCGv t3
= tcg_temp_new();
4657 tcg_gen_movi_tl(t3
, 0xFFFFFFFF);
4658 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4659 tcg_gen_andi_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 0x1F);
4660 tcg_gen_addi_tl(t2
, t0
, 1);
4661 tcg_gen_shr_tl(t2
, t3
, t2
);
4662 tcg_gen_shr_tl(t3
, t3
, t1
);
4663 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], t2
, t3
);
4664 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
4665 tcg_gen_neg_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4671 if (unlikely(Rc(ctx
->opcode
) != 0))
4672 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4675 /* maskir - maskir. */
4676 static void gen_maskir(DisasContext
*ctx
)
4678 TCGv t0
= tcg_temp_new();
4679 TCGv t1
= tcg_temp_new();
4680 tcg_gen_and_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4681 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4682 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4685 if (unlikely(Rc(ctx
->opcode
) != 0))
4686 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4690 static void gen_mul(DisasContext
*ctx
)
4692 TCGv_i64 t0
= tcg_temp_new_i64();
4693 TCGv_i64 t1
= tcg_temp_new_i64();
4694 TCGv t2
= tcg_temp_new();
4695 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4696 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4697 tcg_gen_mul_i64(t0
, t0
, t1
);
4698 tcg_gen_trunc_i64_tl(t2
, t0
);
4699 gen_store_spr(SPR_MQ
, t2
);
4700 tcg_gen_shri_i64(t1
, t0
, 32);
4701 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4702 tcg_temp_free_i64(t0
);
4703 tcg_temp_free_i64(t1
);
4705 if (unlikely(Rc(ctx
->opcode
) != 0))
4706 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4710 static void gen_mulo(DisasContext
*ctx
)
4712 int l1
= gen_new_label();
4713 TCGv_i64 t0
= tcg_temp_new_i64();
4714 TCGv_i64 t1
= tcg_temp_new_i64();
4715 TCGv t2
= tcg_temp_new();
4716 /* Start with XER OV disabled, the most likely case */
4717 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
4718 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4719 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4720 tcg_gen_mul_i64(t0
, t0
, t1
);
4721 tcg_gen_trunc_i64_tl(t2
, t0
);
4722 gen_store_spr(SPR_MQ
, t2
);
4723 tcg_gen_shri_i64(t1
, t0
, 32);
4724 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4725 tcg_gen_ext32s_i64(t1
, t0
);
4726 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
4727 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
4729 tcg_temp_free_i64(t0
);
4730 tcg_temp_free_i64(t1
);
4732 if (unlikely(Rc(ctx
->opcode
) != 0))
4733 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4737 static void gen_nabs(DisasContext
*ctx
)
4739 int l1
= gen_new_label();
4740 int l2
= gen_new_label();
4741 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4742 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4745 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4747 if (unlikely(Rc(ctx
->opcode
) != 0))
4748 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4751 /* nabso - nabso. */
4752 static void gen_nabso(DisasContext
*ctx
)
4754 int l1
= gen_new_label();
4755 int l2
= gen_new_label();
4756 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4757 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4760 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4762 /* nabs never overflows */
4763 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
4764 if (unlikely(Rc(ctx
->opcode
) != 0))
4765 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4769 static void gen_rlmi(DisasContext
*ctx
)
4771 uint32_t mb
= MB(ctx
->opcode
);
4772 uint32_t me
= ME(ctx
->opcode
);
4773 TCGv t0
= tcg_temp_new();
4774 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4775 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4776 tcg_gen_andi_tl(t0
, t0
, MASK(mb
, me
));
4777 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~MASK(mb
, me
));
4778 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], t0
);
4780 if (unlikely(Rc(ctx
->opcode
) != 0))
4781 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4785 static void gen_rrib(DisasContext
*ctx
)
4787 TCGv t0
= tcg_temp_new();
4788 TCGv t1
= tcg_temp_new();
4789 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4790 tcg_gen_movi_tl(t1
, 0x80000000);
4791 tcg_gen_shr_tl(t1
, t1
, t0
);
4792 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4793 tcg_gen_and_tl(t0
, t0
, t1
);
4794 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], t1
);
4795 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4798 if (unlikely(Rc(ctx
->opcode
) != 0))
4799 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4803 static void gen_sle(DisasContext
*ctx
)
4805 TCGv t0
= tcg_temp_new();
4806 TCGv t1
= tcg_temp_new();
4807 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4808 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4809 tcg_gen_subfi_tl(t1
, 32, t1
);
4810 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4811 tcg_gen_or_tl(t1
, t0
, t1
);
4812 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4813 gen_store_spr(SPR_MQ
, t1
);
4816 if (unlikely(Rc(ctx
->opcode
) != 0))
4817 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4821 static void gen_sleq(DisasContext
*ctx
)
4823 TCGv t0
= tcg_temp_new();
4824 TCGv t1
= tcg_temp_new();
4825 TCGv t2
= tcg_temp_new();
4826 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4827 tcg_gen_movi_tl(t2
, 0xFFFFFFFF);
4828 tcg_gen_shl_tl(t2
, t2
, t0
);
4829 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4830 gen_load_spr(t1
, SPR_MQ
);
4831 gen_store_spr(SPR_MQ
, t0
);
4832 tcg_gen_and_tl(t0
, t0
, t2
);
4833 tcg_gen_andc_tl(t1
, t1
, t2
);
4834 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4838 if (unlikely(Rc(ctx
->opcode
) != 0))
4839 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4843 static void gen_sliq(DisasContext
*ctx
)
4845 int sh
= SH(ctx
->opcode
);
4846 TCGv t0
= tcg_temp_new();
4847 TCGv t1
= tcg_temp_new();
4848 tcg_gen_shli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4849 tcg_gen_shri_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
4850 tcg_gen_or_tl(t1
, t0
, t1
);
4851 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4852 gen_store_spr(SPR_MQ
, t1
);
4855 if (unlikely(Rc(ctx
->opcode
) != 0))
4856 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4859 /* slliq - slliq. */
4860 static void gen_slliq(DisasContext
*ctx
)
4862 int sh
= SH(ctx
->opcode
);
4863 TCGv t0
= tcg_temp_new();
4864 TCGv t1
= tcg_temp_new();
4865 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4866 gen_load_spr(t1
, SPR_MQ
);
4867 gen_store_spr(SPR_MQ
, t0
);
4868 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
<< sh
));
4869 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
<< sh
));
4870 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4873 if (unlikely(Rc(ctx
->opcode
) != 0))
4874 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4878 static void gen_sllq(DisasContext
*ctx
)
4880 int l1
= gen_new_label();
4881 int l2
= gen_new_label();
4882 TCGv t0
= tcg_temp_local_new();
4883 TCGv t1
= tcg_temp_local_new();
4884 TCGv t2
= tcg_temp_local_new();
4885 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4886 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
4887 tcg_gen_shl_tl(t1
, t1
, t2
);
4888 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4889 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
4890 gen_load_spr(t0
, SPR_MQ
);
4891 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4894 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4895 gen_load_spr(t2
, SPR_MQ
);
4896 tcg_gen_andc_tl(t1
, t2
, t1
);
4897 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4902 if (unlikely(Rc(ctx
->opcode
) != 0))
4903 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4907 static void gen_slq(DisasContext
*ctx
)
4909 int l1
= gen_new_label();
4910 TCGv t0
= tcg_temp_new();
4911 TCGv t1
= tcg_temp_new();
4912 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4913 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4914 tcg_gen_subfi_tl(t1
, 32, t1
);
4915 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4916 tcg_gen_or_tl(t1
, t0
, t1
);
4917 gen_store_spr(SPR_MQ
, t1
);
4918 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4919 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4920 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
4921 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
4925 if (unlikely(Rc(ctx
->opcode
) != 0))
4926 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4929 /* sraiq - sraiq. */
4930 static void gen_sraiq(DisasContext
*ctx
)
4932 int sh
= SH(ctx
->opcode
);
4933 int l1
= gen_new_label();
4934 TCGv t0
= tcg_temp_new();
4935 TCGv t1
= tcg_temp_new();
4936 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4937 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
4938 tcg_gen_or_tl(t0
, t0
, t1
);
4939 gen_store_spr(SPR_MQ
, t0
);
4940 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
4941 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
4942 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
4943 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_CA
));
4945 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
4948 if (unlikely(Rc(ctx
->opcode
) != 0))
4949 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4953 static void gen_sraq(DisasContext
*ctx
)
4955 int l1
= gen_new_label();
4956 int l2
= gen_new_label();
4957 TCGv t0
= tcg_temp_new();
4958 TCGv t1
= tcg_temp_local_new();
4959 TCGv t2
= tcg_temp_local_new();
4960 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4961 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4962 tcg_gen_sar_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4963 tcg_gen_subfi_tl(t2
, 32, t2
);
4964 tcg_gen_shl_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4965 tcg_gen_or_tl(t0
, t0
, t2
);
4966 gen_store_spr(SPR_MQ
, t0
);
4967 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4968 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l1
);
4969 tcg_gen_mov_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
4970 tcg_gen_sari_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 31);
4973 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
);
4974 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
4975 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
4976 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l2
);
4977 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_CA
));
4981 if (unlikely(Rc(ctx
->opcode
) != 0))
4982 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4986 static void gen_sre(DisasContext
*ctx
)
4988 TCGv t0
= tcg_temp_new();
4989 TCGv t1
= tcg_temp_new();
4990 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4991 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4992 tcg_gen_subfi_tl(t1
, 32, t1
);
4993 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4994 tcg_gen_or_tl(t1
, t0
, t1
);
4995 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4996 gen_store_spr(SPR_MQ
, t1
);
4999 if (unlikely(Rc(ctx
->opcode
) != 0))
5000 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5004 static void gen_srea(DisasContext
*ctx
)
5006 TCGv t0
= tcg_temp_new();
5007 TCGv t1
= tcg_temp_new();
5008 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5009 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5010 gen_store_spr(SPR_MQ
, t0
);
5011 tcg_gen_sar_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t1
);
5014 if (unlikely(Rc(ctx
->opcode
) != 0))
5015 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5019 static void gen_sreq(DisasContext
*ctx
)
5021 TCGv t0
= tcg_temp_new();
5022 TCGv t1
= tcg_temp_new();
5023 TCGv t2
= tcg_temp_new();
5024 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5025 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5026 tcg_gen_shr_tl(t1
, t1
, t0
);
5027 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5028 gen_load_spr(t2
, SPR_MQ
);
5029 gen_store_spr(SPR_MQ
, t0
);
5030 tcg_gen_and_tl(t0
, t0
, t1
);
5031 tcg_gen_andc_tl(t2
, t2
, t1
);
5032 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5036 if (unlikely(Rc(ctx
->opcode
) != 0))
5037 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5041 static void gen_sriq(DisasContext
*ctx
)
5043 int sh
= SH(ctx
->opcode
);
5044 TCGv t0
= tcg_temp_new();
5045 TCGv t1
= tcg_temp_new();
5046 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5047 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5048 tcg_gen_or_tl(t1
, t0
, t1
);
5049 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5050 gen_store_spr(SPR_MQ
, t1
);
5053 if (unlikely(Rc(ctx
->opcode
) != 0))
5054 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5058 static void gen_srliq(DisasContext
*ctx
)
5060 int sh
= SH(ctx
->opcode
);
5061 TCGv t0
= tcg_temp_new();
5062 TCGv t1
= tcg_temp_new();
5063 tcg_gen_rotri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5064 gen_load_spr(t1
, SPR_MQ
);
5065 gen_store_spr(SPR_MQ
, t0
);
5066 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
>> sh
));
5067 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
>> sh
));
5068 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5071 if (unlikely(Rc(ctx
->opcode
) != 0))
5072 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5076 static void gen_srlq(DisasContext
*ctx
)
5078 int l1
= gen_new_label();
5079 int l2
= gen_new_label();
5080 TCGv t0
= tcg_temp_local_new();
5081 TCGv t1
= tcg_temp_local_new();
5082 TCGv t2
= tcg_temp_local_new();
5083 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5084 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5085 tcg_gen_shr_tl(t2
, t1
, t2
);
5086 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5087 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5088 gen_load_spr(t0
, SPR_MQ
);
5089 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5092 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5093 tcg_gen_and_tl(t0
, t0
, t2
);
5094 gen_load_spr(t1
, SPR_MQ
);
5095 tcg_gen_andc_tl(t1
, t1
, t2
);
5096 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5101 if (unlikely(Rc(ctx
->opcode
) != 0))
5102 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5106 static void gen_srq(DisasContext
*ctx
)
5108 int l1
= gen_new_label();
5109 TCGv t0
= tcg_temp_new();
5110 TCGv t1
= tcg_temp_new();
5111 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5112 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5113 tcg_gen_subfi_tl(t1
, 32, t1
);
5114 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5115 tcg_gen_or_tl(t1
, t0
, t1
);
5116 gen_store_spr(SPR_MQ
, t1
);
5117 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5118 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5119 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5120 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5124 if (unlikely(Rc(ctx
->opcode
) != 0))
5125 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5128 /* PowerPC 602 specific instructions */
5131 static void gen_dsa(DisasContext
*ctx
)
5134 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5138 static void gen_esa(DisasContext
*ctx
)
5141 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5145 static void gen_mfrom(DisasContext
*ctx
)
5147 #if defined(CONFIG_USER_ONLY)
5148 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5150 if (unlikely(!ctx
->mem_idx
)) {
5151 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5154 gen_helper_602_mfrom(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5158 /* 602 - 603 - G2 TLB management */
5161 static void gen_tlbld_6xx(DisasContext
*ctx
)
5163 #if defined(CONFIG_USER_ONLY)
5164 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5166 if (unlikely(!ctx
->mem_idx
)) {
5167 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5170 gen_helper_6xx_tlbd(cpu_gpr
[rB(ctx
->opcode
)]);
5175 static void gen_tlbli_6xx(DisasContext
*ctx
)
5177 #if defined(CONFIG_USER_ONLY)
5178 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5180 if (unlikely(!ctx
->mem_idx
)) {
5181 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5184 gen_helper_6xx_tlbi(cpu_gpr
[rB(ctx
->opcode
)]);
5188 /* 74xx TLB management */
5191 static void gen_tlbld_74xx(DisasContext
*ctx
)
5193 #if defined(CONFIG_USER_ONLY)
5194 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5196 if (unlikely(!ctx
->mem_idx
)) {
5197 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5200 gen_helper_74xx_tlbd(cpu_gpr
[rB(ctx
->opcode
)]);
5205 static void gen_tlbli_74xx(DisasContext
*ctx
)
5207 #if defined(CONFIG_USER_ONLY)
5208 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5210 if (unlikely(!ctx
->mem_idx
)) {
5211 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5214 gen_helper_74xx_tlbi(cpu_gpr
[rB(ctx
->opcode
)]);
5218 /* POWER instructions not in PowerPC 601 */
5221 static void gen_clf(DisasContext
*ctx
)
5223 /* Cache line flush: implemented as no-op */
5227 static void gen_cli(DisasContext
*ctx
)
5229 /* Cache line invalidate: privileged and treated as no-op */
5230 #if defined(CONFIG_USER_ONLY)
5231 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5233 if (unlikely(!ctx
->mem_idx
)) {
5234 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5241 static void gen_dclst(DisasContext
*ctx
)
5243 /* Data cache line store: treated as no-op */
5246 static void gen_mfsri(DisasContext
*ctx
)
5248 #if defined(CONFIG_USER_ONLY)
5249 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5251 int ra
= rA(ctx
->opcode
);
5252 int rd
= rD(ctx
->opcode
);
5254 if (unlikely(!ctx
->mem_idx
)) {
5255 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5258 t0
= tcg_temp_new();
5259 gen_addr_reg_index(ctx
, t0
);
5260 tcg_gen_shri_tl(t0
, t0
, 28);
5261 tcg_gen_andi_tl(t0
, t0
, 0xF);
5262 gen_helper_load_sr(cpu_gpr
[rd
], t0
);
5264 if (ra
!= 0 && ra
!= rd
)
5265 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rd
]);
5269 static void gen_rac(DisasContext
*ctx
)
5271 #if defined(CONFIG_USER_ONLY)
5272 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5275 if (unlikely(!ctx
->mem_idx
)) {
5276 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5279 t0
= tcg_temp_new();
5280 gen_addr_reg_index(ctx
, t0
);
5281 gen_helper_rac(cpu_gpr
[rD(ctx
->opcode
)], t0
);
5286 static void gen_rfsvc(DisasContext
*ctx
)
5288 #if defined(CONFIG_USER_ONLY)
5289 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5291 if (unlikely(!ctx
->mem_idx
)) {
5292 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5295 gen_helper_rfsvc(cpu_env
);
5296 gen_sync_exception(ctx
);
5300 /* svc is not implemented for now */
5302 /* POWER2 specific instructions */
5303 /* Quad manipulation (load/store two floats at a time) */
5306 static void gen_lfq(DisasContext
*ctx
)
5308 int rd
= rD(ctx
->opcode
);
5310 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5311 t0
= tcg_temp_new();
5312 gen_addr_imm_index(ctx
, t0
, 0);
5313 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5314 gen_addr_add(ctx
, t0
, t0
, 8);
5315 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5320 static void gen_lfqu(DisasContext
*ctx
)
5322 int ra
= rA(ctx
->opcode
);
5323 int rd
= rD(ctx
->opcode
);
5325 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5326 t0
= tcg_temp_new();
5327 t1
= tcg_temp_new();
5328 gen_addr_imm_index(ctx
, t0
, 0);
5329 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5330 gen_addr_add(ctx
, t1
, t0
, 8);
5331 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5333 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5339 static void gen_lfqux(DisasContext
*ctx
)
5341 int ra
= rA(ctx
->opcode
);
5342 int rd
= rD(ctx
->opcode
);
5343 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5345 t0
= tcg_temp_new();
5346 gen_addr_reg_index(ctx
, t0
);
5347 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5348 t1
= tcg_temp_new();
5349 gen_addr_add(ctx
, t1
, t0
, 8);
5350 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5353 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5358 static void gen_lfqx(DisasContext
*ctx
)
5360 int rd
= rD(ctx
->opcode
);
5362 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5363 t0
= tcg_temp_new();
5364 gen_addr_reg_index(ctx
, t0
);
5365 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5366 gen_addr_add(ctx
, t0
, t0
, 8);
5367 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5372 static void gen_stfq(DisasContext
*ctx
)
5374 int rd
= rD(ctx
->opcode
);
5376 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5377 t0
= tcg_temp_new();
5378 gen_addr_imm_index(ctx
, t0
, 0);
5379 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5380 gen_addr_add(ctx
, t0
, t0
, 8);
5381 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5386 static void gen_stfqu(DisasContext
*ctx
)
5388 int ra
= rA(ctx
->opcode
);
5389 int rd
= rD(ctx
->opcode
);
5391 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5392 t0
= tcg_temp_new();
5393 gen_addr_imm_index(ctx
, t0
, 0);
5394 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5395 t1
= tcg_temp_new();
5396 gen_addr_add(ctx
, t1
, t0
, 8);
5397 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5400 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5405 static void gen_stfqux(DisasContext
*ctx
)
5407 int ra
= rA(ctx
->opcode
);
5408 int rd
= rD(ctx
->opcode
);
5410 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5411 t0
= tcg_temp_new();
5412 gen_addr_reg_index(ctx
, t0
);
5413 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5414 t1
= tcg_temp_new();
5415 gen_addr_add(ctx
, t1
, t0
, 8);
5416 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5419 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5424 static void gen_stfqx(DisasContext
*ctx
)
5426 int rd
= rD(ctx
->opcode
);
5428 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5429 t0
= tcg_temp_new();
5430 gen_addr_reg_index(ctx
, t0
);
5431 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5432 gen_addr_add(ctx
, t0
, t0
, 8);
5433 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5437 /* BookE specific instructions */
5439 /* XXX: not implemented on 440 ? */
5440 static void gen_mfapidi(DisasContext
*ctx
)
5443 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5446 /* XXX: not implemented on 440 ? */
5447 static void gen_tlbiva(DisasContext
*ctx
)
5449 #if defined(CONFIG_USER_ONLY)
5450 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5453 if (unlikely(!ctx
->mem_idx
)) {
5454 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5457 t0
= tcg_temp_new();
5458 gen_addr_reg_index(ctx
, t0
);
5459 gen_helper_tlbie(cpu_gpr
[rB(ctx
->opcode
)]);
5464 /* All 405 MAC instructions are translated here */
5465 static inline void gen_405_mulladd_insn(DisasContext
*ctx
, int opc2
, int opc3
,
5466 int ra
, int rb
, int rt
, int Rc
)
5470 t0
= tcg_temp_local_new();
5471 t1
= tcg_temp_local_new();
5473 switch (opc3
& 0x0D) {
5475 /* macchw - macchw. - macchwo - macchwo. */
5476 /* macchws - macchws. - macchwso - macchwso. */
5477 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5478 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5479 /* mulchw - mulchw. */
5480 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5481 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5482 tcg_gen_ext16s_tl(t1
, t1
);
5485 /* macchwu - macchwu. - macchwuo - macchwuo. */
5486 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5487 /* mulchwu - mulchwu. */
5488 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5489 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5490 tcg_gen_ext16u_tl(t1
, t1
);
5493 /* machhw - machhw. - machhwo - machhwo. */
5494 /* machhws - machhws. - machhwso - machhwso. */
5495 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5496 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5497 /* mulhhw - mulhhw. */
5498 tcg_gen_sari_tl(t0
, cpu_gpr
[ra
], 16);
5499 tcg_gen_ext16s_tl(t0
, t0
);
5500 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5501 tcg_gen_ext16s_tl(t1
, t1
);
5504 /* machhwu - machhwu. - machhwuo - machhwuo. */
5505 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5506 /* mulhhwu - mulhhwu. */
5507 tcg_gen_shri_tl(t0
, cpu_gpr
[ra
], 16);
5508 tcg_gen_ext16u_tl(t0
, t0
);
5509 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5510 tcg_gen_ext16u_tl(t1
, t1
);
5513 /* maclhw - maclhw. - maclhwo - maclhwo. */
5514 /* maclhws - maclhws. - maclhwso - maclhwso. */
5515 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5516 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5517 /* mullhw - mullhw. */
5518 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5519 tcg_gen_ext16s_tl(t1
, cpu_gpr
[rb
]);
5522 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5523 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5524 /* mullhwu - mullhwu. */
5525 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5526 tcg_gen_ext16u_tl(t1
, cpu_gpr
[rb
]);
5530 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5531 tcg_gen_mul_tl(t1
, t0
, t1
);
5533 /* nmultiply-and-accumulate (0x0E) */
5534 tcg_gen_sub_tl(t0
, cpu_gpr
[rt
], t1
);
5536 /* multiply-and-accumulate (0x0C) */
5537 tcg_gen_add_tl(t0
, cpu_gpr
[rt
], t1
);
5541 /* Check overflow and/or saturate */
5542 int l1
= gen_new_label();
5545 /* Start with XER OV disabled, the most likely case */
5546 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
5550 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t1
);
5551 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
5552 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t0
);
5553 tcg_gen_brcondi_tl(TCG_COND_LT
, t1
, 0, l1
);
5556 tcg_gen_sari_tl(t0
, cpu_gpr
[rt
], 31);
5557 tcg_gen_xori_tl(t0
, t0
, 0x7fffffff);
5561 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
5564 tcg_gen_movi_tl(t0
, UINT32_MAX
);
5568 /* Check overflow */
5569 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
5572 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
5575 tcg_gen_mul_tl(cpu_gpr
[rt
], t0
, t1
);
5579 if (unlikely(Rc
) != 0) {
5581 gen_set_Rc0(ctx
, cpu_gpr
[rt
]);
5585 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5586 static void glue(gen_, name)(DisasContext *ctx) \
5588 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5589 rD(ctx->opcode), Rc(ctx->opcode)); \
5592 /* macchw - macchw. */
5593 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
5594 /* macchwo - macchwo. */
5595 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
5596 /* macchws - macchws. */
5597 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
5598 /* macchwso - macchwso. */
5599 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
5600 /* macchwsu - macchwsu. */
5601 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
5602 /* macchwsuo - macchwsuo. */
5603 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
5604 /* macchwu - macchwu. */
5605 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
5606 /* macchwuo - macchwuo. */
5607 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
5608 /* machhw - machhw. */
5609 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
5610 /* machhwo - machhwo. */
5611 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
5612 /* machhws - machhws. */
5613 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
5614 /* machhwso - machhwso. */
5615 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
5616 /* machhwsu - machhwsu. */
5617 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
5618 /* machhwsuo - machhwsuo. */
5619 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
5620 /* machhwu - machhwu. */
5621 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
5622 /* machhwuo - machhwuo. */
5623 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
5624 /* maclhw - maclhw. */
5625 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
5626 /* maclhwo - maclhwo. */
5627 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
5628 /* maclhws - maclhws. */
5629 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
5630 /* maclhwso - maclhwso. */
5631 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
5632 /* maclhwu - maclhwu. */
5633 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
5634 /* maclhwuo - maclhwuo. */
5635 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
5636 /* maclhwsu - maclhwsu. */
5637 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
5638 /* maclhwsuo - maclhwsuo. */
5639 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
5640 /* nmacchw - nmacchw. */
5641 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
5642 /* nmacchwo - nmacchwo. */
5643 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
5644 /* nmacchws - nmacchws. */
5645 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
5646 /* nmacchwso - nmacchwso. */
5647 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
5648 /* nmachhw - nmachhw. */
5649 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
5650 /* nmachhwo - nmachhwo. */
5651 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
5652 /* nmachhws - nmachhws. */
5653 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
5654 /* nmachhwso - nmachhwso. */
5655 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
5656 /* nmaclhw - nmaclhw. */
5657 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
5658 /* nmaclhwo - nmaclhwo. */
5659 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
5660 /* nmaclhws - nmaclhws. */
5661 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
5662 /* nmaclhwso - nmaclhwso. */
5663 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
5665 /* mulchw - mulchw. */
5666 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
5667 /* mulchwu - mulchwu. */
5668 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
5669 /* mulhhw - mulhhw. */
5670 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
5671 /* mulhhwu - mulhhwu. */
5672 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
5673 /* mullhw - mullhw. */
5674 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
5675 /* mullhwu - mullhwu. */
5676 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
5679 static void gen_mfdcr(DisasContext
*ctx
)
5681 #if defined(CONFIG_USER_ONLY)
5682 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5685 if (unlikely(!ctx
->mem_idx
)) {
5686 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5689 /* NIP cannot be restored if the memory exception comes from an helper */
5690 gen_update_nip(ctx
, ctx
->nip
- 4);
5691 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5692 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], dcrn
);
5693 tcg_temp_free(dcrn
);
5698 static void gen_mtdcr(DisasContext
*ctx
)
5700 #if defined(CONFIG_USER_ONLY)
5701 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5704 if (unlikely(!ctx
->mem_idx
)) {
5705 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5708 /* NIP cannot be restored if the memory exception comes from an helper */
5709 gen_update_nip(ctx
, ctx
->nip
- 4);
5710 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5711 gen_helper_store_dcr(dcrn
, cpu_gpr
[rS(ctx
->opcode
)]);
5712 tcg_temp_free(dcrn
);
5717 /* XXX: not implemented on 440 ? */
5718 static void gen_mfdcrx(DisasContext
*ctx
)
5720 #if defined(CONFIG_USER_ONLY)
5721 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5723 if (unlikely(!ctx
->mem_idx
)) {
5724 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5727 /* NIP cannot be restored if the memory exception comes from an helper */
5728 gen_update_nip(ctx
, ctx
->nip
- 4);
5729 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5730 /* Note: Rc update flag set leads to undefined state of Rc0 */
5735 /* XXX: not implemented on 440 ? */
5736 static void gen_mtdcrx(DisasContext
*ctx
)
5738 #if defined(CONFIG_USER_ONLY)
5739 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5741 if (unlikely(!ctx
->mem_idx
)) {
5742 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5745 /* NIP cannot be restored if the memory exception comes from an helper */
5746 gen_update_nip(ctx
, ctx
->nip
- 4);
5747 gen_helper_store_dcr(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
5748 /* Note: Rc update flag set leads to undefined state of Rc0 */
5752 /* mfdcrux (PPC 460) : user-mode access to DCR */
5753 static void gen_mfdcrux(DisasContext
*ctx
)
5755 /* NIP cannot be restored if the memory exception comes from an helper */
5756 gen_update_nip(ctx
, ctx
->nip
- 4);
5757 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5758 /* Note: Rc update flag set leads to undefined state of Rc0 */
5761 /* mtdcrux (PPC 460) : user-mode access to DCR */
5762 static void gen_mtdcrux(DisasContext
*ctx
)
5764 /* NIP cannot be restored if the memory exception comes from an helper */
5765 gen_update_nip(ctx
, ctx
->nip
- 4);
5766 gen_helper_store_dcr(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
5767 /* Note: Rc update flag set leads to undefined state of Rc0 */
5771 static void gen_dccci(DisasContext
*ctx
)
5773 #if defined(CONFIG_USER_ONLY)
5774 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5776 if (unlikely(!ctx
->mem_idx
)) {
5777 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5780 /* interpreted as no-op */
5785 static void gen_dcread(DisasContext
*ctx
)
5787 #if defined(CONFIG_USER_ONLY)
5788 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5791 if (unlikely(!ctx
->mem_idx
)) {
5792 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5795 gen_set_access_type(ctx
, ACCESS_CACHE
);
5796 EA
= tcg_temp_new();
5797 gen_addr_reg_index(ctx
, EA
);
5798 val
= tcg_temp_new();
5799 gen_qemu_ld32u(ctx
, val
, EA
);
5801 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], EA
);
5807 static void gen_icbt_40x(DisasContext
*ctx
)
5809 /* interpreted as no-op */
5810 /* XXX: specification say this is treated as a load by the MMU
5811 * but does not generate any exception
5816 static void gen_iccci(DisasContext
*ctx
)
5818 #if defined(CONFIG_USER_ONLY)
5819 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5821 if (unlikely(!ctx
->mem_idx
)) {
5822 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5825 /* interpreted as no-op */
5830 static void gen_icread(DisasContext
*ctx
)
5832 #if defined(CONFIG_USER_ONLY)
5833 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5835 if (unlikely(!ctx
->mem_idx
)) {
5836 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5839 /* interpreted as no-op */
5843 /* rfci (mem_idx only) */
5844 static void gen_rfci_40x(DisasContext
*ctx
)
5846 #if defined(CONFIG_USER_ONLY)
5847 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5849 if (unlikely(!ctx
->mem_idx
)) {
5850 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5853 /* Restore CPU state */
5854 gen_helper_40x_rfci(cpu_env
);
5855 gen_sync_exception(ctx
);
5859 static void gen_rfci(DisasContext
*ctx
)
5861 #if defined(CONFIG_USER_ONLY)
5862 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5864 if (unlikely(!ctx
->mem_idx
)) {
5865 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5868 /* Restore CPU state */
5869 gen_helper_rfci(cpu_env
);
5870 gen_sync_exception(ctx
);
5874 /* BookE specific */
5876 /* XXX: not implemented on 440 ? */
5877 static void gen_rfdi(DisasContext
*ctx
)
5879 #if defined(CONFIG_USER_ONLY)
5880 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5882 if (unlikely(!ctx
->mem_idx
)) {
5883 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5886 /* Restore CPU state */
5887 gen_helper_rfdi(cpu_env
);
5888 gen_sync_exception(ctx
);
5892 /* XXX: not implemented on 440 ? */
5893 static void gen_rfmci(DisasContext
*ctx
)
5895 #if defined(CONFIG_USER_ONLY)
5896 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5898 if (unlikely(!ctx
->mem_idx
)) {
5899 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5902 /* Restore CPU state */
5903 gen_helper_rfmci(cpu_env
);
5904 gen_sync_exception(ctx
);
5908 /* TLB management - PowerPC 405 implementation */
5911 static void gen_tlbre_40x(DisasContext
*ctx
)
5913 #if defined(CONFIG_USER_ONLY)
5914 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5916 if (unlikely(!ctx
->mem_idx
)) {
5917 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5920 switch (rB(ctx
->opcode
)) {
5922 gen_helper_4xx_tlbre_hi(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5925 gen_helper_4xx_tlbre_lo(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5928 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5934 /* tlbsx - tlbsx. */
5935 static void gen_tlbsx_40x(DisasContext
*ctx
)
5937 #if defined(CONFIG_USER_ONLY)
5938 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5941 if (unlikely(!ctx
->mem_idx
)) {
5942 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5945 t0
= tcg_temp_new();
5946 gen_addr_reg_index(ctx
, t0
);
5947 gen_helper_4xx_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], t0
);
5949 if (Rc(ctx
->opcode
)) {
5950 int l1
= gen_new_label();
5951 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_xer
);
5952 tcg_gen_shri_i32(cpu_crf
[0], cpu_crf
[0], XER_SO
);
5953 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 1);
5954 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
5955 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
5962 static void gen_tlbwe_40x(DisasContext
*ctx
)
5964 #if defined(CONFIG_USER_ONLY)
5965 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5967 if (unlikely(!ctx
->mem_idx
)) {
5968 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5971 switch (rB(ctx
->opcode
)) {
5973 gen_helper_4xx_tlbwe_hi(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
5976 gen_helper_4xx_tlbwe_lo(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
5979 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5985 /* TLB management - PowerPC 440 implementation */
5988 static void gen_tlbre_440(DisasContext
*ctx
)
5990 #if defined(CONFIG_USER_ONLY)
5991 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5993 if (unlikely(!ctx
->mem_idx
)) {
5994 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5997 switch (rB(ctx
->opcode
)) {
6002 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
6003 gen_helper_440_tlbre(cpu_gpr
[rD(ctx
->opcode
)], t0
, cpu_gpr
[rA(ctx
->opcode
)]);
6004 tcg_temp_free_i32(t0
);
6008 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6014 /* tlbsx - tlbsx. */
6015 static void gen_tlbsx_440(DisasContext
*ctx
)
6017 #if defined(CONFIG_USER_ONLY)
6018 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6021 if (unlikely(!ctx
->mem_idx
)) {
6022 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6025 t0
= tcg_temp_new();
6026 gen_addr_reg_index(ctx
, t0
);
6027 gen_helper_440_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], t0
);
6029 if (Rc(ctx
->opcode
)) {
6030 int l1
= gen_new_label();
6031 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_xer
);
6032 tcg_gen_shri_i32(cpu_crf
[0], cpu_crf
[0], XER_SO
);
6033 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 1);
6034 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
6035 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
6042 static void gen_tlbwe_440(DisasContext
*ctx
)
6044 #if defined(CONFIG_USER_ONLY)
6045 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6047 if (unlikely(!ctx
->mem_idx
)) {
6048 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6051 switch (rB(ctx
->opcode
)) {
6056 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
6057 gen_helper_440_tlbwe(t0
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
6058 tcg_temp_free_i32(t0
);
6062 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6068 /* TLB management - PowerPC BookE 2.06 implementation */
6071 static void gen_tlbre_booke206(DisasContext
*ctx
)
6073 #if defined(CONFIG_USER_ONLY)
6074 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6076 if (unlikely(!ctx
->mem_idx
)) {
6077 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6081 gen_helper_booke206_tlbre();
6085 /* tlbsx - tlbsx. */
6086 static void gen_tlbsx_booke206(DisasContext
*ctx
)
6088 #if defined(CONFIG_USER_ONLY)
6089 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6092 if (unlikely(!ctx
->mem_idx
)) {
6093 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6097 if (rA(ctx
->opcode
)) {
6098 t0
= tcg_temp_new();
6099 tcg_gen_mov_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)]);
6101 t0
= tcg_const_tl(0);
6104 tcg_gen_add_tl(t0
, t0
, cpu_gpr
[rB(ctx
->opcode
)]);
6105 gen_helper_booke206_tlbsx(t0
);
6110 static void gen_tlbwe_booke206(DisasContext
*ctx
)
6112 #if defined(CONFIG_USER_ONLY)
6113 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6115 if (unlikely(!ctx
->mem_idx
)) {
6116 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6119 gen_update_nip(ctx
, ctx
->nip
- 4);
6120 gen_helper_booke206_tlbwe();
6124 static void gen_tlbivax_booke206(DisasContext
*ctx
)
6126 #if defined(CONFIG_USER_ONLY)
6127 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6130 if (unlikely(!ctx
->mem_idx
)) {
6131 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6135 t0
= tcg_temp_new();
6136 gen_addr_reg_index(ctx
, t0
);
6138 gen_helper_booke206_tlbivax(t0
);
6142 static void gen_tlbilx_booke206(DisasContext
*ctx
)
6144 #if defined(CONFIG_USER_ONLY)
6145 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6148 if (unlikely(!ctx
->mem_idx
)) {
6149 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6153 t0
= tcg_temp_new();
6154 gen_addr_reg_index(ctx
, t0
);
6156 switch((ctx
->opcode
>> 21) & 0x3) {
6158 gen_helper_booke206_tlbilx0(t0
);
6161 gen_helper_booke206_tlbilx1(t0
);
6164 gen_helper_booke206_tlbilx3(t0
);
6167 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6177 static void gen_wrtee(DisasContext
*ctx
)
6179 #if defined(CONFIG_USER_ONLY)
6180 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6183 if (unlikely(!ctx
->mem_idx
)) {
6184 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6187 t0
= tcg_temp_new();
6188 tcg_gen_andi_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)], (1 << MSR_EE
));
6189 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6190 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
6192 /* Stop translation to have a chance to raise an exception
6193 * if we just set msr_ee to 1
6195 gen_stop_exception(ctx
);
6200 static void gen_wrteei(DisasContext
*ctx
)
6202 #if defined(CONFIG_USER_ONLY)
6203 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6205 if (unlikely(!ctx
->mem_idx
)) {
6206 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6209 if (ctx
->opcode
& 0x00008000) {
6210 tcg_gen_ori_tl(cpu_msr
, cpu_msr
, (1 << MSR_EE
));
6211 /* Stop translation to have a chance to raise an exception */
6212 gen_stop_exception(ctx
);
6214 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6219 /* PowerPC 440 specific instructions */
6222 static void gen_dlmzb(DisasContext
*ctx
)
6224 TCGv_i32 t0
= tcg_const_i32(Rc(ctx
->opcode
));
6225 gen_helper_dlmzb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
6226 cpu_gpr
[rB(ctx
->opcode
)], t0
);
6227 tcg_temp_free_i32(t0
);
6230 /* mbar replaces eieio on 440 */
6231 static void gen_mbar(DisasContext
*ctx
)
6233 /* interpreted as no-op */
6236 /* msync replaces sync on 440 */
6237 static void gen_msync_4xx(DisasContext
*ctx
)
6239 /* interpreted as no-op */
6243 static void gen_icbt_440(DisasContext
*ctx
)
6245 /* interpreted as no-op */
6246 /* XXX: specification say this is treated as a load by the MMU
6247 * but does not generate any exception
6251 /* Embedded.Processor Control */
6253 static void gen_msgclr(DisasContext
*ctx
)
6255 #if defined(CONFIG_USER_ONLY)
6256 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6258 if (unlikely(ctx
->mem_idx
== 0)) {
6259 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6263 gen_helper_msgclr(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6267 static void gen_msgsnd(DisasContext
*ctx
)
6269 #if defined(CONFIG_USER_ONLY)
6270 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6272 if (unlikely(ctx
->mem_idx
== 0)) {
6273 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6277 gen_helper_msgsnd(cpu_gpr
[rB(ctx
->opcode
)]);
6281 /*** Altivec vector extension ***/
6282 /* Altivec registers moves */
6284 static inline TCGv_ptr
gen_avr_ptr(int reg
)
6286 TCGv_ptr r
= tcg_temp_new_ptr();
6287 tcg_gen_addi_ptr(r
, cpu_env
, offsetof(CPUPPCState
, avr
[reg
]));
6291 #define GEN_VR_LDX(name, opc2, opc3) \
6292 static void glue(gen_, name)(DisasContext *ctx) \
6295 if (unlikely(!ctx->altivec_enabled)) { \
6296 gen_exception(ctx, POWERPC_EXCP_VPU); \
6299 gen_set_access_type(ctx, ACCESS_INT); \
6300 EA = tcg_temp_new(); \
6301 gen_addr_reg_index(ctx, EA); \
6302 tcg_gen_andi_tl(EA, EA, ~0xf); \
6303 if (ctx->le_mode) { \
6304 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6305 tcg_gen_addi_tl(EA, EA, 8); \
6306 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6308 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6309 tcg_gen_addi_tl(EA, EA, 8); \
6310 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6312 tcg_temp_free(EA); \
6315 #define GEN_VR_STX(name, opc2, opc3) \
6316 static void gen_st##name(DisasContext *ctx) \
6319 if (unlikely(!ctx->altivec_enabled)) { \
6320 gen_exception(ctx, POWERPC_EXCP_VPU); \
6323 gen_set_access_type(ctx, ACCESS_INT); \
6324 EA = tcg_temp_new(); \
6325 gen_addr_reg_index(ctx, EA); \
6326 tcg_gen_andi_tl(EA, EA, ~0xf); \
6327 if (ctx->le_mode) { \
6328 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6329 tcg_gen_addi_tl(EA, EA, 8); \
6330 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6332 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6333 tcg_gen_addi_tl(EA, EA, 8); \
6334 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6336 tcg_temp_free(EA); \
6339 #define GEN_VR_LVE(name, opc2, opc3) \
6340 static void gen_lve##name(DisasContext *ctx) \
6344 if (unlikely(!ctx->altivec_enabled)) { \
6345 gen_exception(ctx, POWERPC_EXCP_VPU); \
6348 gen_set_access_type(ctx, ACCESS_INT); \
6349 EA = tcg_temp_new(); \
6350 gen_addr_reg_index(ctx, EA); \
6351 rs = gen_avr_ptr(rS(ctx->opcode)); \
6352 gen_helper_lve##name (rs, EA); \
6353 tcg_temp_free(EA); \
6354 tcg_temp_free_ptr(rs); \
6357 #define GEN_VR_STVE(name, opc2, opc3) \
6358 static void gen_stve##name(DisasContext *ctx) \
6362 if (unlikely(!ctx->altivec_enabled)) { \
6363 gen_exception(ctx, POWERPC_EXCP_VPU); \
6366 gen_set_access_type(ctx, ACCESS_INT); \
6367 EA = tcg_temp_new(); \
6368 gen_addr_reg_index(ctx, EA); \
6369 rs = gen_avr_ptr(rS(ctx->opcode)); \
6370 gen_helper_stve##name (rs, EA); \
6371 tcg_temp_free(EA); \
6372 tcg_temp_free_ptr(rs); \
6375 GEN_VR_LDX(lvx
, 0x07, 0x03);
6376 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
6377 GEN_VR_LDX(lvxl
, 0x07, 0x0B);
6379 GEN_VR_LVE(bx
, 0x07, 0x00);
6380 GEN_VR_LVE(hx
, 0x07, 0x01);
6381 GEN_VR_LVE(wx
, 0x07, 0x02);
6383 GEN_VR_STX(svx
, 0x07, 0x07);
6384 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
6385 GEN_VR_STX(svxl
, 0x07, 0x0F);
6387 GEN_VR_STVE(bx
, 0x07, 0x04);
6388 GEN_VR_STVE(hx
, 0x07, 0x05);
6389 GEN_VR_STVE(wx
, 0x07, 0x06);
6391 static void gen_lvsl(DisasContext
*ctx
)
6395 if (unlikely(!ctx
->altivec_enabled
)) {
6396 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6399 EA
= tcg_temp_new();
6400 gen_addr_reg_index(ctx
, EA
);
6401 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6402 gen_helper_lvsl(rd
, EA
);
6404 tcg_temp_free_ptr(rd
);
6407 static void gen_lvsr(DisasContext
*ctx
)
6411 if (unlikely(!ctx
->altivec_enabled
)) {
6412 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6415 EA
= tcg_temp_new();
6416 gen_addr_reg_index(ctx
, EA
);
6417 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6418 gen_helper_lvsr(rd
, EA
);
6420 tcg_temp_free_ptr(rd
);
6423 static void gen_mfvscr(DisasContext
*ctx
)
6426 if (unlikely(!ctx
->altivec_enabled
)) {
6427 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6430 tcg_gen_movi_i64(cpu_avrh
[rD(ctx
->opcode
)], 0);
6431 t
= tcg_temp_new_i32();
6432 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUPPCState
, vscr
));
6433 tcg_gen_extu_i32_i64(cpu_avrl
[rD(ctx
->opcode
)], t
);
6434 tcg_temp_free_i32(t
);
6437 static void gen_mtvscr(DisasContext
*ctx
)
6440 if (unlikely(!ctx
->altivec_enabled
)) {
6441 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6444 p
= gen_avr_ptr(rD(ctx
->opcode
));
6445 gen_helper_mtvscr(p
);
6446 tcg_temp_free_ptr(p
);
6449 /* Logical operations */
6450 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
6451 static void glue(gen_, name)(DisasContext *ctx) \
6453 if (unlikely(!ctx->altivec_enabled)) { \
6454 gen_exception(ctx, POWERPC_EXCP_VPU); \
6457 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6458 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6461 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16);
6462 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17);
6463 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18);
6464 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19);
6465 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20);
6467 #define GEN_VXFORM(name, opc2, opc3) \
6468 static void glue(gen_, name)(DisasContext *ctx) \
6470 TCGv_ptr ra, rb, rd; \
6471 if (unlikely(!ctx->altivec_enabled)) { \
6472 gen_exception(ctx, POWERPC_EXCP_VPU); \
6475 ra = gen_avr_ptr(rA(ctx->opcode)); \
6476 rb = gen_avr_ptr(rB(ctx->opcode)); \
6477 rd = gen_avr_ptr(rD(ctx->opcode)); \
6478 gen_helper_##name (rd, ra, rb); \
6479 tcg_temp_free_ptr(ra); \
6480 tcg_temp_free_ptr(rb); \
6481 tcg_temp_free_ptr(rd); \
6484 GEN_VXFORM(vaddubm
, 0, 0);
6485 GEN_VXFORM(vadduhm
, 0, 1);
6486 GEN_VXFORM(vadduwm
, 0, 2);
6487 GEN_VXFORM(vsububm
, 0, 16);
6488 GEN_VXFORM(vsubuhm
, 0, 17);
6489 GEN_VXFORM(vsubuwm
, 0, 18);
6490 GEN_VXFORM(vmaxub
, 1, 0);
6491 GEN_VXFORM(vmaxuh
, 1, 1);
6492 GEN_VXFORM(vmaxuw
, 1, 2);
6493 GEN_VXFORM(vmaxsb
, 1, 4);
6494 GEN_VXFORM(vmaxsh
, 1, 5);
6495 GEN_VXFORM(vmaxsw
, 1, 6);
6496 GEN_VXFORM(vminub
, 1, 8);
6497 GEN_VXFORM(vminuh
, 1, 9);
6498 GEN_VXFORM(vminuw
, 1, 10);
6499 GEN_VXFORM(vminsb
, 1, 12);
6500 GEN_VXFORM(vminsh
, 1, 13);
6501 GEN_VXFORM(vminsw
, 1, 14);
6502 GEN_VXFORM(vavgub
, 1, 16);
6503 GEN_VXFORM(vavguh
, 1, 17);
6504 GEN_VXFORM(vavguw
, 1, 18);
6505 GEN_VXFORM(vavgsb
, 1, 20);
6506 GEN_VXFORM(vavgsh
, 1, 21);
6507 GEN_VXFORM(vavgsw
, 1, 22);
6508 GEN_VXFORM(vmrghb
, 6, 0);
6509 GEN_VXFORM(vmrghh
, 6, 1);
6510 GEN_VXFORM(vmrghw
, 6, 2);
6511 GEN_VXFORM(vmrglb
, 6, 4);
6512 GEN_VXFORM(vmrglh
, 6, 5);
6513 GEN_VXFORM(vmrglw
, 6, 6);
6514 GEN_VXFORM(vmuloub
, 4, 0);
6515 GEN_VXFORM(vmulouh
, 4, 1);
6516 GEN_VXFORM(vmulosb
, 4, 4);
6517 GEN_VXFORM(vmulosh
, 4, 5);
6518 GEN_VXFORM(vmuleub
, 4, 8);
6519 GEN_VXFORM(vmuleuh
, 4, 9);
6520 GEN_VXFORM(vmulesb
, 4, 12);
6521 GEN_VXFORM(vmulesh
, 4, 13);
6522 GEN_VXFORM(vslb
, 2, 4);
6523 GEN_VXFORM(vslh
, 2, 5);
6524 GEN_VXFORM(vslw
, 2, 6);
6525 GEN_VXFORM(vsrb
, 2, 8);
6526 GEN_VXFORM(vsrh
, 2, 9);
6527 GEN_VXFORM(vsrw
, 2, 10);
6528 GEN_VXFORM(vsrab
, 2, 12);
6529 GEN_VXFORM(vsrah
, 2, 13);
6530 GEN_VXFORM(vsraw
, 2, 14);
6531 GEN_VXFORM(vslo
, 6, 16);
6532 GEN_VXFORM(vsro
, 6, 17);
6533 GEN_VXFORM(vaddcuw
, 0, 6);
6534 GEN_VXFORM(vsubcuw
, 0, 22);
6535 GEN_VXFORM(vaddubs
, 0, 8);
6536 GEN_VXFORM(vadduhs
, 0, 9);
6537 GEN_VXFORM(vadduws
, 0, 10);
6538 GEN_VXFORM(vaddsbs
, 0, 12);
6539 GEN_VXFORM(vaddshs
, 0, 13);
6540 GEN_VXFORM(vaddsws
, 0, 14);
6541 GEN_VXFORM(vsububs
, 0, 24);
6542 GEN_VXFORM(vsubuhs
, 0, 25);
6543 GEN_VXFORM(vsubuws
, 0, 26);
6544 GEN_VXFORM(vsubsbs
, 0, 28);
6545 GEN_VXFORM(vsubshs
, 0, 29);
6546 GEN_VXFORM(vsubsws
, 0, 30);
6547 GEN_VXFORM(vrlb
, 2, 0);
6548 GEN_VXFORM(vrlh
, 2, 1);
6549 GEN_VXFORM(vrlw
, 2, 2);
6550 GEN_VXFORM(vsl
, 2, 7);
6551 GEN_VXFORM(vsr
, 2, 11);
6552 GEN_VXFORM(vpkuhum
, 7, 0);
6553 GEN_VXFORM(vpkuwum
, 7, 1);
6554 GEN_VXFORM(vpkuhus
, 7, 2);
6555 GEN_VXFORM(vpkuwus
, 7, 3);
6556 GEN_VXFORM(vpkshus
, 7, 4);
6557 GEN_VXFORM(vpkswus
, 7, 5);
6558 GEN_VXFORM(vpkshss
, 7, 6);
6559 GEN_VXFORM(vpkswss
, 7, 7);
6560 GEN_VXFORM(vpkpx
, 7, 12);
6561 GEN_VXFORM(vsum4ubs
, 4, 24);
6562 GEN_VXFORM(vsum4sbs
, 4, 28);
6563 GEN_VXFORM(vsum4shs
, 4, 25);
6564 GEN_VXFORM(vsum2sws
, 4, 26);
6565 GEN_VXFORM(vsumsws
, 4, 30);
6566 GEN_VXFORM(vaddfp
, 5, 0);
6567 GEN_VXFORM(vsubfp
, 5, 1);
6568 GEN_VXFORM(vmaxfp
, 5, 16);
6569 GEN_VXFORM(vminfp
, 5, 17);
6571 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
6572 static void glue(gen_, name)(DisasContext *ctx) \
6574 TCGv_ptr ra, rb, rd; \
6575 if (unlikely(!ctx->altivec_enabled)) { \
6576 gen_exception(ctx, POWERPC_EXCP_VPU); \
6579 ra = gen_avr_ptr(rA(ctx->opcode)); \
6580 rb = gen_avr_ptr(rB(ctx->opcode)); \
6581 rd = gen_avr_ptr(rD(ctx->opcode)); \
6582 gen_helper_##opname (rd, ra, rb); \
6583 tcg_temp_free_ptr(ra); \
6584 tcg_temp_free_ptr(rb); \
6585 tcg_temp_free_ptr(rd); \
6588 #define GEN_VXRFORM(name, opc2, opc3) \
6589 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
6590 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
6592 GEN_VXRFORM(vcmpequb
, 3, 0)
6593 GEN_VXRFORM(vcmpequh
, 3, 1)
6594 GEN_VXRFORM(vcmpequw
, 3, 2)
6595 GEN_VXRFORM(vcmpgtsb
, 3, 12)
6596 GEN_VXRFORM(vcmpgtsh
, 3, 13)
6597 GEN_VXRFORM(vcmpgtsw
, 3, 14)
6598 GEN_VXRFORM(vcmpgtub
, 3, 8)
6599 GEN_VXRFORM(vcmpgtuh
, 3, 9)
6600 GEN_VXRFORM(vcmpgtuw
, 3, 10)
6601 GEN_VXRFORM(vcmpeqfp
, 3, 3)
6602 GEN_VXRFORM(vcmpgefp
, 3, 7)
6603 GEN_VXRFORM(vcmpgtfp
, 3, 11)
6604 GEN_VXRFORM(vcmpbfp
, 3, 15)
6606 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
6607 static void glue(gen_, name)(DisasContext *ctx) \
6611 if (unlikely(!ctx->altivec_enabled)) { \
6612 gen_exception(ctx, POWERPC_EXCP_VPU); \
6615 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6616 rd = gen_avr_ptr(rD(ctx->opcode)); \
6617 gen_helper_##name (rd, simm); \
6618 tcg_temp_free_i32(simm); \
6619 tcg_temp_free_ptr(rd); \
6622 GEN_VXFORM_SIMM(vspltisb
, 6, 12);
6623 GEN_VXFORM_SIMM(vspltish
, 6, 13);
6624 GEN_VXFORM_SIMM(vspltisw
, 6, 14);
6626 #define GEN_VXFORM_NOA(name, opc2, opc3) \
6627 static void glue(gen_, name)(DisasContext *ctx) \
6630 if (unlikely(!ctx->altivec_enabled)) { \
6631 gen_exception(ctx, POWERPC_EXCP_VPU); \
6634 rb = gen_avr_ptr(rB(ctx->opcode)); \
6635 rd = gen_avr_ptr(rD(ctx->opcode)); \
6636 gen_helper_##name (rd, rb); \
6637 tcg_temp_free_ptr(rb); \
6638 tcg_temp_free_ptr(rd); \
6641 GEN_VXFORM_NOA(vupkhsb
, 7, 8);
6642 GEN_VXFORM_NOA(vupkhsh
, 7, 9);
6643 GEN_VXFORM_NOA(vupklsb
, 7, 10);
6644 GEN_VXFORM_NOA(vupklsh
, 7, 11);
6645 GEN_VXFORM_NOA(vupkhpx
, 7, 13);
6646 GEN_VXFORM_NOA(vupklpx
, 7, 15);
6647 GEN_VXFORM_NOA(vrefp
, 5, 4);
6648 GEN_VXFORM_NOA(vrsqrtefp
, 5, 5);
6649 GEN_VXFORM_NOA(vexptefp
, 5, 6);
6650 GEN_VXFORM_NOA(vlogefp
, 5, 7);
6651 GEN_VXFORM_NOA(vrfim
, 5, 8);
6652 GEN_VXFORM_NOA(vrfin
, 5, 9);
6653 GEN_VXFORM_NOA(vrfip
, 5, 10);
6654 GEN_VXFORM_NOA(vrfiz
, 5, 11);
6656 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
6657 static void glue(gen_, name)(DisasContext *ctx) \
6661 if (unlikely(!ctx->altivec_enabled)) { \
6662 gen_exception(ctx, POWERPC_EXCP_VPU); \
6665 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6666 rd = gen_avr_ptr(rD(ctx->opcode)); \
6667 gen_helper_##name (rd, simm); \
6668 tcg_temp_free_i32(simm); \
6669 tcg_temp_free_ptr(rd); \
6672 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
6673 static void glue(gen_, name)(DisasContext *ctx) \
6677 if (unlikely(!ctx->altivec_enabled)) { \
6678 gen_exception(ctx, POWERPC_EXCP_VPU); \
6681 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
6682 rb = gen_avr_ptr(rB(ctx->opcode)); \
6683 rd = gen_avr_ptr(rD(ctx->opcode)); \
6684 gen_helper_##name (rd, rb, uimm); \
6685 tcg_temp_free_i32(uimm); \
6686 tcg_temp_free_ptr(rb); \
6687 tcg_temp_free_ptr(rd); \
6690 GEN_VXFORM_UIMM(vspltb
, 6, 8);
6691 GEN_VXFORM_UIMM(vsplth
, 6, 9);
6692 GEN_VXFORM_UIMM(vspltw
, 6, 10);
6693 GEN_VXFORM_UIMM(vcfux
, 5, 12);
6694 GEN_VXFORM_UIMM(vcfsx
, 5, 13);
6695 GEN_VXFORM_UIMM(vctuxs
, 5, 14);
6696 GEN_VXFORM_UIMM(vctsxs
, 5, 15);
6698 static void gen_vsldoi(DisasContext
*ctx
)
6700 TCGv_ptr ra
, rb
, rd
;
6702 if (unlikely(!ctx
->altivec_enabled
)) {
6703 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6706 ra
= gen_avr_ptr(rA(ctx
->opcode
));
6707 rb
= gen_avr_ptr(rB(ctx
->opcode
));
6708 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6709 sh
= tcg_const_i32(VSH(ctx
->opcode
));
6710 gen_helper_vsldoi (rd
, ra
, rb
, sh
);
6711 tcg_temp_free_ptr(ra
);
6712 tcg_temp_free_ptr(rb
);
6713 tcg_temp_free_ptr(rd
);
6714 tcg_temp_free_i32(sh
);
6717 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
6718 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
6720 TCGv_ptr ra, rb, rc, rd; \
6721 if (unlikely(!ctx->altivec_enabled)) { \
6722 gen_exception(ctx, POWERPC_EXCP_VPU); \
6725 ra = gen_avr_ptr(rA(ctx->opcode)); \
6726 rb = gen_avr_ptr(rB(ctx->opcode)); \
6727 rc = gen_avr_ptr(rC(ctx->opcode)); \
6728 rd = gen_avr_ptr(rD(ctx->opcode)); \
6729 if (Rc(ctx->opcode)) { \
6730 gen_helper_##name1 (rd, ra, rb, rc); \
6732 gen_helper_##name0 (rd, ra, rb, rc); \
6734 tcg_temp_free_ptr(ra); \
6735 tcg_temp_free_ptr(rb); \
6736 tcg_temp_free_ptr(rc); \
6737 tcg_temp_free_ptr(rd); \
6740 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16)
6742 static void gen_vmladduhm(DisasContext
*ctx
)
6744 TCGv_ptr ra
, rb
, rc
, rd
;
6745 if (unlikely(!ctx
->altivec_enabled
)) {
6746 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6749 ra
= gen_avr_ptr(rA(ctx
->opcode
));
6750 rb
= gen_avr_ptr(rB(ctx
->opcode
));
6751 rc
= gen_avr_ptr(rC(ctx
->opcode
));
6752 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6753 gen_helper_vmladduhm(rd
, ra
, rb
, rc
);
6754 tcg_temp_free_ptr(ra
);
6755 tcg_temp_free_ptr(rb
);
6756 tcg_temp_free_ptr(rc
);
6757 tcg_temp_free_ptr(rd
);
6760 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18)
6761 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19)
6762 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20)
6763 GEN_VAFORM_PAIRED(vsel
, vperm
, 21)
6764 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23)
6766 /*** SPE extension ***/
6767 /* Register moves */
6770 static inline void gen_evmra(DisasContext
*ctx
)
6773 if (unlikely(!ctx
->spe_enabled
)) {
6774 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
6778 #if defined(TARGET_PPC64)
6780 tcg_gen_mov_i64(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6783 tcg_gen_st_i64(cpu_gpr
[rA(ctx
->opcode
)],
6785 offsetof(CPUPPCState
, spe_acc
));
6787 TCGv_i64 tmp
= tcg_temp_new_i64();
6789 /* tmp := rA_lo + rA_hi << 32 */
6790 tcg_gen_concat_i32_i64(tmp
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6792 /* spe_acc := tmp */
6793 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
6794 tcg_temp_free_i64(tmp
);
6797 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6798 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6802 static inline void gen_load_gpr64(TCGv_i64 t
, int reg
)
6804 #if defined(TARGET_PPC64)
6805 tcg_gen_mov_i64(t
, cpu_gpr
[reg
]);
6807 tcg_gen_concat_i32_i64(t
, cpu_gpr
[reg
], cpu_gprh
[reg
]);
6811 static inline void gen_store_gpr64(int reg
, TCGv_i64 t
)
6813 #if defined(TARGET_PPC64)
6814 tcg_gen_mov_i64(cpu_gpr
[reg
], t
);
6816 TCGv_i64 tmp
= tcg_temp_new_i64();
6817 tcg_gen_trunc_i64_i32(cpu_gpr
[reg
], t
);
6818 tcg_gen_shri_i64(tmp
, t
, 32);
6819 tcg_gen_trunc_i64_i32(cpu_gprh
[reg
], tmp
);
6820 tcg_temp_free_i64(tmp
);
6824 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
6825 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
6827 if (Rc(ctx->opcode)) \
6833 /* Handler for undefined SPE opcodes */
6834 static inline void gen_speundef(DisasContext
*ctx
)
6836 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6840 #if defined(TARGET_PPC64)
6841 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
6842 static inline void gen_##name(DisasContext *ctx) \
6844 if (unlikely(!ctx->spe_enabled)) { \
6845 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6848 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6849 cpu_gpr[rB(ctx->opcode)]); \
6852 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
6853 static inline void gen_##name(DisasContext *ctx) \
6855 if (unlikely(!ctx->spe_enabled)) { \
6856 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6859 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6860 cpu_gpr[rB(ctx->opcode)]); \
6861 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6862 cpu_gprh[rB(ctx->opcode)]); \
6866 GEN_SPEOP_LOGIC2(evand
, tcg_gen_and_tl
);
6867 GEN_SPEOP_LOGIC2(evandc
, tcg_gen_andc_tl
);
6868 GEN_SPEOP_LOGIC2(evxor
, tcg_gen_xor_tl
);
6869 GEN_SPEOP_LOGIC2(evor
, tcg_gen_or_tl
);
6870 GEN_SPEOP_LOGIC2(evnor
, tcg_gen_nor_tl
);
6871 GEN_SPEOP_LOGIC2(eveqv
, tcg_gen_eqv_tl
);
6872 GEN_SPEOP_LOGIC2(evorc
, tcg_gen_orc_tl
);
6873 GEN_SPEOP_LOGIC2(evnand
, tcg_gen_nand_tl
);
6875 /* SPE logic immediate */
6876 #if defined(TARGET_PPC64)
6877 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
6878 static inline void gen_##name(DisasContext *ctx) \
6880 if (unlikely(!ctx->spe_enabled)) { \
6881 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6884 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6885 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6886 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6887 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6888 tcg_opi(t0, t0, rB(ctx->opcode)); \
6889 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6890 tcg_gen_trunc_i64_i32(t1, t2); \
6891 tcg_temp_free_i64(t2); \
6892 tcg_opi(t1, t1, rB(ctx->opcode)); \
6893 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6894 tcg_temp_free_i32(t0); \
6895 tcg_temp_free_i32(t1); \
6898 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
6899 static inline void gen_##name(DisasContext *ctx) \
6901 if (unlikely(!ctx->spe_enabled)) { \
6902 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6905 tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6907 tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6911 GEN_SPEOP_TCG_LOGIC_IMM2(evslwi
, tcg_gen_shli_i32
);
6912 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu
, tcg_gen_shri_i32
);
6913 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis
, tcg_gen_sari_i32
);
6914 GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi
, tcg_gen_rotli_i32
);
6916 /* SPE arithmetic */
6917 #if defined(TARGET_PPC64)
6918 #define GEN_SPEOP_ARITH1(name, tcg_op) \
6919 static inline void gen_##name(DisasContext *ctx) \
6921 if (unlikely(!ctx->spe_enabled)) { \
6922 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6925 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6926 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6927 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6928 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6930 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6931 tcg_gen_trunc_i64_i32(t1, t2); \
6932 tcg_temp_free_i64(t2); \
6934 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6935 tcg_temp_free_i32(t0); \
6936 tcg_temp_free_i32(t1); \
6939 #define GEN_SPEOP_ARITH1(name, tcg_op) \
6940 static inline void gen_##name(DisasContext *ctx) \
6942 if (unlikely(!ctx->spe_enabled)) { \
6943 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6946 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
6947 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
6951 static inline void gen_op_evabs(TCGv_i32 ret
, TCGv_i32 arg1
)
6953 int l1
= gen_new_label();
6954 int l2
= gen_new_label();
6956 tcg_gen_brcondi_i32(TCG_COND_GE
, arg1
, 0, l1
);
6957 tcg_gen_neg_i32(ret
, arg1
);
6960 tcg_gen_mov_i32(ret
, arg1
);
6963 GEN_SPEOP_ARITH1(evabs
, gen_op_evabs
);
6964 GEN_SPEOP_ARITH1(evneg
, tcg_gen_neg_i32
);
6965 GEN_SPEOP_ARITH1(evextsb
, tcg_gen_ext8s_i32
);
6966 GEN_SPEOP_ARITH1(evextsh
, tcg_gen_ext16s_i32
);
6967 static inline void gen_op_evrndw(TCGv_i32 ret
, TCGv_i32 arg1
)
6969 tcg_gen_addi_i32(ret
, arg1
, 0x8000);
6970 tcg_gen_ext16u_i32(ret
, ret
);
6972 GEN_SPEOP_ARITH1(evrndw
, gen_op_evrndw
);
6973 GEN_SPEOP_ARITH1(evcntlsw
, gen_helper_cntlsw32
);
6974 GEN_SPEOP_ARITH1(evcntlzw
, gen_helper_cntlzw32
);
6976 #if defined(TARGET_PPC64)
6977 #define GEN_SPEOP_ARITH2(name, tcg_op) \
6978 static inline void gen_##name(DisasContext *ctx) \
6980 if (unlikely(!ctx->spe_enabled)) { \
6981 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6984 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6985 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6986 TCGv_i32 t2 = tcg_temp_local_new_i32(); \
6987 TCGv_i64 t3 = tcg_temp_local_new_i64(); \
6988 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6989 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
6990 tcg_op(t0, t0, t2); \
6991 tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
6992 tcg_gen_trunc_i64_i32(t1, t3); \
6993 tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
6994 tcg_gen_trunc_i64_i32(t2, t3); \
6995 tcg_temp_free_i64(t3); \
6996 tcg_op(t1, t1, t2); \
6997 tcg_temp_free_i32(t2); \
6998 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6999 tcg_temp_free_i32(t0); \
7000 tcg_temp_free_i32(t1); \
7003 #define GEN_SPEOP_ARITH2(name, tcg_op) \
7004 static inline void gen_##name(DisasContext *ctx) \
7006 if (unlikely(!ctx->spe_enabled)) { \
7007 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7010 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7011 cpu_gpr[rB(ctx->opcode)]); \
7012 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7013 cpu_gprh[rB(ctx->opcode)]); \
7017 static inline void gen_op_evsrwu(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7022 l1
= gen_new_label();
7023 l2
= gen_new_label();
7024 t0
= tcg_temp_local_new_i32();
7025 /* No error here: 6 bits are used */
7026 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
7027 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
7028 tcg_gen_shr_i32(ret
, arg1
, t0
);
7031 tcg_gen_movi_i32(ret
, 0);
7033 tcg_temp_free_i32(t0
);
7035 GEN_SPEOP_ARITH2(evsrwu
, gen_op_evsrwu
);
7036 static inline void gen_op_evsrws(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7041 l1
= gen_new_label();
7042 l2
= gen_new_label();
7043 t0
= tcg_temp_local_new_i32();
7044 /* No error here: 6 bits are used */
7045 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
7046 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
7047 tcg_gen_sar_i32(ret
, arg1
, t0
);
7050 tcg_gen_movi_i32(ret
, 0);
7052 tcg_temp_free_i32(t0
);
7054 GEN_SPEOP_ARITH2(evsrws
, gen_op_evsrws
);
7055 static inline void gen_op_evslw(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7060 l1
= gen_new_label();
7061 l2
= gen_new_label();
7062 t0
= tcg_temp_local_new_i32();
7063 /* No error here: 6 bits are used */
7064 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
7065 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
7066 tcg_gen_shl_i32(ret
, arg1
, t0
);
7069 tcg_gen_movi_i32(ret
, 0);
7071 tcg_temp_free_i32(t0
);
7073 GEN_SPEOP_ARITH2(evslw
, gen_op_evslw
);
7074 static inline void gen_op_evrlw(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7076 TCGv_i32 t0
= tcg_temp_new_i32();
7077 tcg_gen_andi_i32(t0
, arg2
, 0x1F);
7078 tcg_gen_rotl_i32(ret
, arg1
, t0
);
7079 tcg_temp_free_i32(t0
);
7081 GEN_SPEOP_ARITH2(evrlw
, gen_op_evrlw
);
7082 static inline void gen_evmergehi(DisasContext
*ctx
)
7084 if (unlikely(!ctx
->spe_enabled
)) {
7085 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7088 #if defined(TARGET_PPC64)
7089 TCGv t0
= tcg_temp_new();
7090 TCGv t1
= tcg_temp_new();
7091 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
7092 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
7093 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7097 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7098 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7101 GEN_SPEOP_ARITH2(evaddw
, tcg_gen_add_i32
);
7102 static inline void gen_op_evsubf(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7104 tcg_gen_sub_i32(ret
, arg2
, arg1
);
7106 GEN_SPEOP_ARITH2(evsubfw
, gen_op_evsubf
);
7108 /* SPE arithmetic immediate */
7109 #if defined(TARGET_PPC64)
7110 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
7111 static inline void gen_##name(DisasContext *ctx) \
7113 if (unlikely(!ctx->spe_enabled)) { \
7114 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7117 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7118 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7119 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7120 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
7121 tcg_op(t0, t0, rA(ctx->opcode)); \
7122 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
7123 tcg_gen_trunc_i64_i32(t1, t2); \
7124 tcg_temp_free_i64(t2); \
7125 tcg_op(t1, t1, rA(ctx->opcode)); \
7126 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7127 tcg_temp_free_i32(t0); \
7128 tcg_temp_free_i32(t1); \
7131 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
7132 static inline void gen_##name(DisasContext *ctx) \
7134 if (unlikely(!ctx->spe_enabled)) { \
7135 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7138 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
7140 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
7144 GEN_SPEOP_ARITH_IMM2(evaddiw
, tcg_gen_addi_i32
);
7145 GEN_SPEOP_ARITH_IMM2(evsubifw
, tcg_gen_subi_i32
);
7147 /* SPE comparison */
7148 #if defined(TARGET_PPC64)
7149 #define GEN_SPEOP_COMP(name, tcg_cond) \
7150 static inline void gen_##name(DisasContext *ctx) \
7152 if (unlikely(!ctx->spe_enabled)) { \
7153 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7156 int l1 = gen_new_label(); \
7157 int l2 = gen_new_label(); \
7158 int l3 = gen_new_label(); \
7159 int l4 = gen_new_label(); \
7160 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7161 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7162 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7163 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7164 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
7165 tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
7166 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
7168 gen_set_label(l1); \
7169 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
7170 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
7171 gen_set_label(l2); \
7172 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7173 tcg_gen_trunc_i64_i32(t0, t2); \
7174 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
7175 tcg_gen_trunc_i64_i32(t1, t2); \
7176 tcg_temp_free_i64(t2); \
7177 tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
7178 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7179 ~(CRF_CH | CRF_CH_AND_CL)); \
7181 gen_set_label(l3); \
7182 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7183 CRF_CH | CRF_CH_OR_CL); \
7184 gen_set_label(l4); \
7185 tcg_temp_free_i32(t0); \
7186 tcg_temp_free_i32(t1); \
7189 #define GEN_SPEOP_COMP(name, tcg_cond) \
7190 static inline void gen_##name(DisasContext *ctx) \
7192 if (unlikely(!ctx->spe_enabled)) { \
7193 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7196 int l1 = gen_new_label(); \
7197 int l2 = gen_new_label(); \
7198 int l3 = gen_new_label(); \
7199 int l4 = gen_new_label(); \
7201 tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
7202 cpu_gpr[rB(ctx->opcode)], l1); \
7203 tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
7205 gen_set_label(l1); \
7206 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
7207 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
7208 gen_set_label(l2); \
7209 tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
7210 cpu_gprh[rB(ctx->opcode)], l3); \
7211 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7212 ~(CRF_CH | CRF_CH_AND_CL)); \
7214 gen_set_label(l3); \
7215 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7216 CRF_CH | CRF_CH_OR_CL); \
7217 gen_set_label(l4); \
7220 GEN_SPEOP_COMP(evcmpgtu
, TCG_COND_GTU
);
7221 GEN_SPEOP_COMP(evcmpgts
, TCG_COND_GT
);
7222 GEN_SPEOP_COMP(evcmpltu
, TCG_COND_LTU
);
7223 GEN_SPEOP_COMP(evcmplts
, TCG_COND_LT
);
7224 GEN_SPEOP_COMP(evcmpeq
, TCG_COND_EQ
);
7227 static inline void gen_brinc(DisasContext
*ctx
)
7229 /* Note: brinc is usable even if SPE is disabled */
7230 gen_helper_brinc(cpu_gpr
[rD(ctx
->opcode
)],
7231 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7233 static inline void gen_evmergelo(DisasContext
*ctx
)
7235 if (unlikely(!ctx
->spe_enabled
)) {
7236 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7239 #if defined(TARGET_PPC64)
7240 TCGv t0
= tcg_temp_new();
7241 TCGv t1
= tcg_temp_new();
7242 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
7243 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
7244 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7248 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7249 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7252 static inline void gen_evmergehilo(DisasContext
*ctx
)
7254 if (unlikely(!ctx
->spe_enabled
)) {
7255 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7258 #if defined(TARGET_PPC64)
7259 TCGv t0
= tcg_temp_new();
7260 TCGv t1
= tcg_temp_new();
7261 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
7262 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
7263 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7267 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7268 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7271 static inline void gen_evmergelohi(DisasContext
*ctx
)
7273 if (unlikely(!ctx
->spe_enabled
)) {
7274 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7277 #if defined(TARGET_PPC64)
7278 TCGv t0
= tcg_temp_new();
7279 TCGv t1
= tcg_temp_new();
7280 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
7281 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
7282 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7286 if (rD(ctx
->opcode
) == rA(ctx
->opcode
)) {
7287 TCGv_i32 tmp
= tcg_temp_new_i32();
7288 tcg_gen_mov_i32(tmp
, cpu_gpr
[rA(ctx
->opcode
)]);
7289 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7290 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], tmp
);
7291 tcg_temp_free_i32(tmp
);
7293 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7294 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7298 static inline void gen_evsplati(DisasContext
*ctx
)
7300 uint64_t imm
= ((int32_t)(rA(ctx
->opcode
) << 27)) >> 27;
7302 #if defined(TARGET_PPC64)
7303 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
7305 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
7306 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
7309 static inline void gen_evsplatfi(DisasContext
*ctx
)
7311 uint64_t imm
= rA(ctx
->opcode
) << 27;
7313 #if defined(TARGET_PPC64)
7314 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
7316 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
7317 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
7321 static inline void gen_evsel(DisasContext
*ctx
)
7323 int l1
= gen_new_label();
7324 int l2
= gen_new_label();
7325 int l3
= gen_new_label();
7326 int l4
= gen_new_label();
7327 TCGv_i32 t0
= tcg_temp_local_new_i32();
7328 #if defined(TARGET_PPC64)
7329 TCGv t1
= tcg_temp_local_new();
7330 TCGv t2
= tcg_temp_local_new();
7332 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 3);
7333 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
7334 #if defined(TARGET_PPC64)
7335 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
7337 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7341 #if defined(TARGET_PPC64)
7342 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
7344 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7347 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 2);
7348 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l3
);
7349 #if defined(TARGET_PPC64)
7350 tcg_gen_ext32u_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)]);
7352 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7356 #if defined(TARGET_PPC64)
7357 tcg_gen_ext32u_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)]);
7359 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7362 tcg_temp_free_i32(t0
);
7363 #if defined(TARGET_PPC64)
7364 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
, t2
);
7370 static void gen_evsel0(DisasContext
*ctx
)
7375 static void gen_evsel1(DisasContext
*ctx
)
7380 static void gen_evsel2(DisasContext
*ctx
)
7385 static void gen_evsel3(DisasContext
*ctx
)
7392 static inline void gen_evmwumi(DisasContext
*ctx
)
7396 if (unlikely(!ctx
->spe_enabled
)) {
7397 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7401 t0
= tcg_temp_new_i64();
7402 t1
= tcg_temp_new_i64();
7404 /* t0 := rA; t1 := rB */
7405 #if defined(TARGET_PPC64)
7406 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7407 tcg_gen_ext32u_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7409 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7410 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7413 tcg_gen_mul_i64(t0
, t0
, t1
); /* t0 := rA * rB */
7415 gen_store_gpr64(rD(ctx
->opcode
), t0
); /* rD := t0 */
7417 tcg_temp_free_i64(t0
);
7418 tcg_temp_free_i64(t1
);
7421 static inline void gen_evmwumia(DisasContext
*ctx
)
7425 if (unlikely(!ctx
->spe_enabled
)) {
7426 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7430 gen_evmwumi(ctx
); /* rD := rA * rB */
7432 tmp
= tcg_temp_new_i64();
7435 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7436 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7437 tcg_temp_free_i64(tmp
);
7440 static inline void gen_evmwumiaa(DisasContext
*ctx
)
7445 if (unlikely(!ctx
->spe_enabled
)) {
7446 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7450 gen_evmwumi(ctx
); /* rD := rA * rB */
7452 acc
= tcg_temp_new_i64();
7453 tmp
= tcg_temp_new_i64();
7456 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7459 tcg_gen_ld_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7461 /* acc := tmp + acc */
7462 tcg_gen_add_i64(acc
, acc
, tmp
);
7465 tcg_gen_st_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7468 gen_store_gpr64(rD(ctx
->opcode
), acc
);
7470 tcg_temp_free_i64(acc
);
7471 tcg_temp_free_i64(tmp
);
7474 static inline void gen_evmwsmi(DisasContext
*ctx
)
7478 if (unlikely(!ctx
->spe_enabled
)) {
7479 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7483 t0
= tcg_temp_new_i64();
7484 t1
= tcg_temp_new_i64();
7486 /* t0 := rA; t1 := rB */
7487 #if defined(TARGET_PPC64)
7488 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7489 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7491 tcg_gen_ext_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7492 tcg_gen_ext_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7495 tcg_gen_mul_i64(t0
, t0
, t1
); /* t0 := rA * rB */
7497 gen_store_gpr64(rD(ctx
->opcode
), t0
); /* rD := t0 */
7499 tcg_temp_free_i64(t0
);
7500 tcg_temp_free_i64(t1
);
7503 static inline void gen_evmwsmia(DisasContext
*ctx
)
7507 gen_evmwsmi(ctx
); /* rD := rA * rB */
7509 tmp
= tcg_temp_new_i64();
7512 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7513 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7515 tcg_temp_free_i64(tmp
);
7518 static inline void gen_evmwsmiaa(DisasContext
*ctx
)
7520 TCGv_i64 acc
= tcg_temp_new_i64();
7521 TCGv_i64 tmp
= tcg_temp_new_i64();
7523 gen_evmwsmi(ctx
); /* rD := rA * rB */
7525 acc
= tcg_temp_new_i64();
7526 tmp
= tcg_temp_new_i64();
7529 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7532 tcg_gen_ld_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7534 /* acc := tmp + acc */
7535 tcg_gen_add_i64(acc
, acc
, tmp
);
7538 tcg_gen_st_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7541 gen_store_gpr64(rD(ctx
->opcode
), acc
);
7543 tcg_temp_free_i64(acc
);
7544 tcg_temp_free_i64(tmp
);
7547 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7548 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7549 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7550 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7551 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
7552 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
7553 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
7554 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE
); //
7555 GEN_SPE(evmra
, speundef
, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE
);
7556 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
); ////
7557 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7558 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7559 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7560 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
7561 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
7562 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
7563 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
); ////
7564 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7565 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7566 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE
);
7567 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7568 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7569 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE
); //
7570 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE
);
7571 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7572 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7573 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE
); ////
7574 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE
); ////
7575 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE
); ////
7577 /* SPE load and stores */
7578 static inline void gen_addr_spe_imm_index(DisasContext
*ctx
, TCGv EA
, int sh
)
7580 target_ulong uimm
= rB(ctx
->opcode
);
7582 if (rA(ctx
->opcode
) == 0) {
7583 tcg_gen_movi_tl(EA
, uimm
<< sh
);
7585 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], uimm
<< sh
);
7586 #if defined(TARGET_PPC64)
7587 if (!ctx
->sf_mode
) {
7588 tcg_gen_ext32u_tl(EA
, EA
);
7594 static inline void gen_op_evldd(DisasContext
*ctx
, TCGv addr
)
7596 #if defined(TARGET_PPC64)
7597 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7599 TCGv_i64 t0
= tcg_temp_new_i64();
7600 gen_qemu_ld64(ctx
, t0
, addr
);
7601 tcg_gen_trunc_i64_i32(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7602 tcg_gen_shri_i64(t0
, t0
, 32);
7603 tcg_gen_trunc_i64_i32(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7604 tcg_temp_free_i64(t0
);
7608 static inline void gen_op_evldw(DisasContext
*ctx
, TCGv addr
)
7610 #if defined(TARGET_PPC64)
7611 TCGv t0
= tcg_temp_new();
7612 gen_qemu_ld32u(ctx
, t0
, addr
);
7613 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7614 gen_addr_add(ctx
, addr
, addr
, 4);
7615 gen_qemu_ld32u(ctx
, t0
, addr
);
7616 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7619 gen_qemu_ld32u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7620 gen_addr_add(ctx
, addr
, addr
, 4);
7621 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7625 static inline void gen_op_evldh(DisasContext
*ctx
, TCGv addr
)
7627 TCGv t0
= tcg_temp_new();
7628 #if defined(TARGET_PPC64)
7629 gen_qemu_ld16u(ctx
, t0
, addr
);
7630 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7631 gen_addr_add(ctx
, addr
, addr
, 2);
7632 gen_qemu_ld16u(ctx
, t0
, addr
);
7633 tcg_gen_shli_tl(t0
, t0
, 32);
7634 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7635 gen_addr_add(ctx
, addr
, addr
, 2);
7636 gen_qemu_ld16u(ctx
, t0
, addr
);
7637 tcg_gen_shli_tl(t0
, t0
, 16);
7638 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7639 gen_addr_add(ctx
, addr
, addr
, 2);
7640 gen_qemu_ld16u(ctx
, t0
, addr
);
7641 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7643 gen_qemu_ld16u(ctx
, t0
, addr
);
7644 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7645 gen_addr_add(ctx
, addr
, addr
, 2);
7646 gen_qemu_ld16u(ctx
, t0
, addr
);
7647 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
7648 gen_addr_add(ctx
, addr
, addr
, 2);
7649 gen_qemu_ld16u(ctx
, t0
, addr
);
7650 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7651 gen_addr_add(ctx
, addr
, addr
, 2);
7652 gen_qemu_ld16u(ctx
, t0
, addr
);
7653 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7658 static inline void gen_op_evlhhesplat(DisasContext
*ctx
, TCGv addr
)
7660 TCGv t0
= tcg_temp_new();
7661 gen_qemu_ld16u(ctx
, t0
, addr
);
7662 #if defined(TARGET_PPC64)
7663 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7664 tcg_gen_shli_tl(t0
, t0
, 16);
7665 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7667 tcg_gen_shli_tl(t0
, t0
, 16);
7668 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7669 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7674 static inline void gen_op_evlhhousplat(DisasContext
*ctx
, TCGv addr
)
7676 TCGv t0
= tcg_temp_new();
7677 gen_qemu_ld16u(ctx
, t0
, addr
);
7678 #if defined(TARGET_PPC64)
7679 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7680 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7682 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7683 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7688 static inline void gen_op_evlhhossplat(DisasContext
*ctx
, TCGv addr
)
7690 TCGv t0
= tcg_temp_new();
7691 gen_qemu_ld16s(ctx
, t0
, addr
);
7692 #if defined(TARGET_PPC64)
7693 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7694 tcg_gen_ext32u_tl(t0
, t0
);
7695 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7697 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7698 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7703 static inline void gen_op_evlwhe(DisasContext
*ctx
, TCGv addr
)
7705 TCGv t0
= tcg_temp_new();
7706 #if defined(TARGET_PPC64)
7707 gen_qemu_ld16u(ctx
, t0
, addr
);
7708 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7709 gen_addr_add(ctx
, addr
, addr
, 2);
7710 gen_qemu_ld16u(ctx
, t0
, addr
);
7711 tcg_gen_shli_tl(t0
, t0
, 16);
7712 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7714 gen_qemu_ld16u(ctx
, t0
, addr
);
7715 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7716 gen_addr_add(ctx
, addr
, addr
, 2);
7717 gen_qemu_ld16u(ctx
, t0
, addr
);
7718 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
7723 static inline void gen_op_evlwhou(DisasContext
*ctx
, TCGv addr
)
7725 #if defined(TARGET_PPC64)
7726 TCGv t0
= tcg_temp_new();
7727 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7728 gen_addr_add(ctx
, addr
, addr
, 2);
7729 gen_qemu_ld16u(ctx
, t0
, addr
);
7730 tcg_gen_shli_tl(t0
, t0
, 32);
7731 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7734 gen_qemu_ld16u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7735 gen_addr_add(ctx
, addr
, addr
, 2);
7736 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7740 static inline void gen_op_evlwhos(DisasContext
*ctx
, TCGv addr
)
7742 #if defined(TARGET_PPC64)
7743 TCGv t0
= tcg_temp_new();
7744 gen_qemu_ld16s(ctx
, t0
, addr
);
7745 tcg_gen_ext32u_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7746 gen_addr_add(ctx
, addr
, addr
, 2);
7747 gen_qemu_ld16s(ctx
, t0
, addr
);
7748 tcg_gen_shli_tl(t0
, t0
, 32);
7749 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7752 gen_qemu_ld16s(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7753 gen_addr_add(ctx
, addr
, addr
, 2);
7754 gen_qemu_ld16s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7758 static inline void gen_op_evlwwsplat(DisasContext
*ctx
, TCGv addr
)
7760 TCGv t0
= tcg_temp_new();
7761 gen_qemu_ld32u(ctx
, t0
, addr
);
7762 #if defined(TARGET_PPC64)
7763 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7764 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7766 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7767 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7772 static inline void gen_op_evlwhsplat(DisasContext
*ctx
, TCGv addr
)
7774 TCGv t0
= tcg_temp_new();
7775 #if defined(TARGET_PPC64)
7776 gen_qemu_ld16u(ctx
, t0
, addr
);
7777 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7778 tcg_gen_shli_tl(t0
, t0
, 32);
7779 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7780 gen_addr_add(ctx
, addr
, addr
, 2);
7781 gen_qemu_ld16u(ctx
, t0
, addr
);
7782 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7783 tcg_gen_shli_tl(t0
, t0
, 16);
7784 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7786 gen_qemu_ld16u(ctx
, t0
, addr
);
7787 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7788 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
7789 gen_addr_add(ctx
, addr
, addr
, 2);
7790 gen_qemu_ld16u(ctx
, t0
, addr
);
7791 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
7792 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
7797 static inline void gen_op_evstdd(DisasContext
*ctx
, TCGv addr
)
7799 #if defined(TARGET_PPC64)
7800 gen_qemu_st64(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7802 TCGv_i64 t0
= tcg_temp_new_i64();
7803 tcg_gen_concat_i32_i64(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gprh
[rS(ctx
->opcode
)]);
7804 gen_qemu_st64(ctx
, t0
, addr
);
7805 tcg_temp_free_i64(t0
);
7809 static inline void gen_op_evstdw(DisasContext
*ctx
, TCGv addr
)
7811 #if defined(TARGET_PPC64)
7812 TCGv t0
= tcg_temp_new();
7813 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7814 gen_qemu_st32(ctx
, t0
, addr
);
7817 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7819 gen_addr_add(ctx
, addr
, addr
, 4);
7820 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7823 static inline void gen_op_evstdh(DisasContext
*ctx
, TCGv addr
)
7825 TCGv t0
= tcg_temp_new();
7826 #if defined(TARGET_PPC64)
7827 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
7829 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
7831 gen_qemu_st16(ctx
, t0
, addr
);
7832 gen_addr_add(ctx
, addr
, addr
, 2);
7833 #if defined(TARGET_PPC64)
7834 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7835 gen_qemu_st16(ctx
, t0
, addr
);
7837 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7839 gen_addr_add(ctx
, addr
, addr
, 2);
7840 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
7841 gen_qemu_st16(ctx
, t0
, addr
);
7843 gen_addr_add(ctx
, addr
, addr
, 2);
7844 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7847 static inline void gen_op_evstwhe(DisasContext
*ctx
, TCGv addr
)
7849 TCGv t0
= tcg_temp_new();
7850 #if defined(TARGET_PPC64)
7851 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
7853 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
7855 gen_qemu_st16(ctx
, t0
, addr
);
7856 gen_addr_add(ctx
, addr
, addr
, 2);
7857 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
7858 gen_qemu_st16(ctx
, t0
, addr
);
7862 static inline void gen_op_evstwho(DisasContext
*ctx
, TCGv addr
)
7864 #if defined(TARGET_PPC64)
7865 TCGv t0
= tcg_temp_new();
7866 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7867 gen_qemu_st16(ctx
, t0
, addr
);
7870 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7872 gen_addr_add(ctx
, addr
, addr
, 2);
7873 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7876 static inline void gen_op_evstwwe(DisasContext
*ctx
, TCGv addr
)
7878 #if defined(TARGET_PPC64)
7879 TCGv t0
= tcg_temp_new();
7880 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7881 gen_qemu_st32(ctx
, t0
, addr
);
7884 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7888 static inline void gen_op_evstwwo(DisasContext
*ctx
, TCGv addr
)
7890 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7893 #define GEN_SPEOP_LDST(name, opc2, sh) \
7894 static void glue(gen_, name)(DisasContext *ctx) \
7897 if (unlikely(!ctx->spe_enabled)) { \
7898 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7901 gen_set_access_type(ctx, ACCESS_INT); \
7902 t0 = tcg_temp_new(); \
7903 if (Rc(ctx->opcode)) { \
7904 gen_addr_spe_imm_index(ctx, t0, sh); \
7906 gen_addr_reg_index(ctx, t0); \
7908 gen_op_##name(ctx, t0); \
7909 tcg_temp_free(t0); \
7912 GEN_SPEOP_LDST(evldd
, 0x00, 3);
7913 GEN_SPEOP_LDST(evldw
, 0x01, 3);
7914 GEN_SPEOP_LDST(evldh
, 0x02, 3);
7915 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1);
7916 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1);
7917 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1);
7918 GEN_SPEOP_LDST(evlwhe
, 0x08, 2);
7919 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2);
7920 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2);
7921 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2);
7922 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2);
7924 GEN_SPEOP_LDST(evstdd
, 0x10, 3);
7925 GEN_SPEOP_LDST(evstdw
, 0x11, 3);
7926 GEN_SPEOP_LDST(evstdh
, 0x12, 3);
7927 GEN_SPEOP_LDST(evstwhe
, 0x18, 2);
7928 GEN_SPEOP_LDST(evstwho
, 0x1A, 2);
7929 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2);
7930 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2);
7932 /* Multiply and add - TODO */
7934 GEN_SPE(speundef
, evmhessf
, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);//
7935 GEN_SPE(speundef
, evmhossf
, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7936 GEN_SPE(evmheumi
, evmhesmi
, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
7937 GEN_SPE(speundef
, evmhesmf
, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7938 GEN_SPE(evmhoumi
, evmhosmi
, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
7939 GEN_SPE(speundef
, evmhosmf
, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7940 GEN_SPE(speundef
, evmhessfa
, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7941 GEN_SPE(speundef
, evmhossfa
, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7942 GEN_SPE(evmheumia
, evmhesmia
, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
7943 GEN_SPE(speundef
, evmhesmfa
, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7944 GEN_SPE(evmhoumia
, evmhosmia
, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
7945 GEN_SPE(speundef
, evmhosmfa
, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7947 GEN_SPE(speundef
, evmwhssf
, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7948 GEN_SPE(evmwlumi
, speundef
, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7949 GEN_SPE(evmwhumi
, evmwhsmi
, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
7950 GEN_SPE(speundef
, evmwhsmf
, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7951 GEN_SPE(speundef
, evmwssf
, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7952 GEN_SPE(speundef
, evmwsmf
, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7953 GEN_SPE(speundef
, evmwhssfa
, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7954 GEN_SPE(evmwlumia
, speundef
, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7955 GEN_SPE(evmwhumia
, evmwhsmia
, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
7956 GEN_SPE(speundef
, evmwhsmfa
, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7957 GEN_SPE(speundef
, evmwssfa
, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7958 GEN_SPE(speundef
, evmwsmfa
, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7960 GEN_SPE(evadduiaaw
, evaddsiaaw
, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
7961 GEN_SPE(evsubfusiaaw
, evsubfssiaaw
, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
7962 GEN_SPE(evaddumiaaw
, evaddsmiaaw
, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
7963 GEN_SPE(evsubfumiaaw
, evsubfsmiaaw
, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
7964 GEN_SPE(evdivws
, evdivwu
, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE
);
7966 GEN_SPE(evmheusiaaw
, evmhessiaaw
, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
7967 GEN_SPE(speundef
, evmhessfaaw
, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7968 GEN_SPE(evmhousiaaw
, evmhossiaaw
, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
7969 GEN_SPE(speundef
, evmhossfaaw
, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7970 GEN_SPE(evmheumiaaw
, evmhesmiaaw
, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
7971 GEN_SPE(speundef
, evmhesmfaaw
, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7972 GEN_SPE(evmhoumiaaw
, evmhosmiaaw
, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
7973 GEN_SPE(speundef
, evmhosmfaaw
, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7974 GEN_SPE(evmhegumiaa
, evmhegsmiaa
, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
7975 GEN_SPE(speundef
, evmhegsmfaa
, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7976 GEN_SPE(evmhogumiaa
, evmhogsmiaa
, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
7977 GEN_SPE(speundef
, evmhogsmfaa
, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7979 GEN_SPE(evmwlusiaaw
, evmwlssiaaw
, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
7980 GEN_SPE(evmwlumiaaw
, evmwlsmiaaw
, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
7981 GEN_SPE(speundef
, evmwssfaa
, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7982 GEN_SPE(speundef
, evmwsmfaa
, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7984 GEN_SPE(evmheusianw
, evmhessianw
, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
7985 GEN_SPE(speundef
, evmhessfanw
, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7986 GEN_SPE(evmhousianw
, evmhossianw
, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
7987 GEN_SPE(speundef
, evmhossfanw
, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7988 GEN_SPE(evmheumianw
, evmhesmianw
, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
7989 GEN_SPE(speundef
, evmhesmfanw
, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7990 GEN_SPE(evmhoumianw
, evmhosmianw
, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
7991 GEN_SPE(speundef
, evmhosmfanw
, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7992 GEN_SPE(evmhegumian
, evmhegsmian
, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
7993 GEN_SPE(speundef
, evmhegsmfan
, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7994 GEN_SPE(evmhigumian
, evmhigsmian
, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
7995 GEN_SPE(speundef
, evmhogsmfan
, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7997 GEN_SPE(evmwlusianw
, evmwlssianw
, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
7998 GEN_SPE(evmwlumianw
, evmwlsmianw
, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
7999 GEN_SPE(speundef
, evmwssfan
, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8000 GEN_SPE(evmwumian
, evmwsmian
, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
8001 GEN_SPE(speundef
, evmwsmfan
, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8004 /*** SPE floating-point extension ***/
8005 #if defined(TARGET_PPC64)
8006 #define GEN_SPEFPUOP_CONV_32_32(name) \
8007 static inline void gen_##name(DisasContext *ctx) \
8011 t0 = tcg_temp_new_i32(); \
8012 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8013 gen_helper_##name(t0, t0); \
8014 t1 = tcg_temp_new(); \
8015 tcg_gen_extu_i32_tl(t1, t0); \
8016 tcg_temp_free_i32(t0); \
8017 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8018 0xFFFFFFFF00000000ULL); \
8019 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
8020 tcg_temp_free(t1); \
8022 #define GEN_SPEFPUOP_CONV_32_64(name) \
8023 static inline void gen_##name(DisasContext *ctx) \
8027 t0 = tcg_temp_new_i32(); \
8028 gen_helper_##name(t0, cpu_gpr[rB(ctx->opcode)]); \
8029 t1 = tcg_temp_new(); \
8030 tcg_gen_extu_i32_tl(t1, t0); \
8031 tcg_temp_free_i32(t0); \
8032 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8033 0xFFFFFFFF00000000ULL); \
8034 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
8035 tcg_temp_free(t1); \
8037 #define GEN_SPEFPUOP_CONV_64_32(name) \
8038 static inline void gen_##name(DisasContext *ctx) \
8040 TCGv_i32 t0 = tcg_temp_new_i32(); \
8041 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8042 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], t0); \
8043 tcg_temp_free_i32(t0); \
8045 #define GEN_SPEFPUOP_CONV_64_64(name) \
8046 static inline void gen_##name(DisasContext *ctx) \
8048 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8050 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
8051 static inline void gen_##name(DisasContext *ctx) \
8055 if (unlikely(!ctx->spe_enabled)) { \
8056 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8059 t0 = tcg_temp_new_i32(); \
8060 t1 = tcg_temp_new_i32(); \
8061 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8062 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8063 gen_helper_##name(t0, t0, t1); \
8064 tcg_temp_free_i32(t1); \
8065 t2 = tcg_temp_new(); \
8066 tcg_gen_extu_i32_tl(t2, t0); \
8067 tcg_temp_free_i32(t0); \
8068 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8069 0xFFFFFFFF00000000ULL); \
8070 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \
8071 tcg_temp_free(t2); \
8073 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
8074 static inline void gen_##name(DisasContext *ctx) \
8076 if (unlikely(!ctx->spe_enabled)) { \
8077 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8080 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
8081 cpu_gpr[rB(ctx->opcode)]); \
8083 #define GEN_SPEFPUOP_COMP_32(name) \
8084 static inline void gen_##name(DisasContext *ctx) \
8087 if (unlikely(!ctx->spe_enabled)) { \
8088 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8091 t0 = tcg_temp_new_i32(); \
8092 t1 = tcg_temp_new_i32(); \
8093 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8094 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8095 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], t0, t1); \
8096 tcg_temp_free_i32(t0); \
8097 tcg_temp_free_i32(t1); \
8099 #define GEN_SPEFPUOP_COMP_64(name) \
8100 static inline void gen_##name(DisasContext *ctx) \
8102 if (unlikely(!ctx->spe_enabled)) { \
8103 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8106 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
8107 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8110 #define GEN_SPEFPUOP_CONV_32_32(name) \
8111 static inline void gen_##name(DisasContext *ctx) \
8113 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8115 #define GEN_SPEFPUOP_CONV_32_64(name) \
8116 static inline void gen_##name(DisasContext *ctx) \
8118 TCGv_i64 t0 = tcg_temp_new_i64(); \
8119 gen_load_gpr64(t0, rB(ctx->opcode)); \
8120 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], t0); \
8121 tcg_temp_free_i64(t0); \
8123 #define GEN_SPEFPUOP_CONV_64_32(name) \
8124 static inline void gen_##name(DisasContext *ctx) \
8126 TCGv_i64 t0 = tcg_temp_new_i64(); \
8127 gen_helper_##name(t0, cpu_gpr[rB(ctx->opcode)]); \
8128 gen_store_gpr64(rD(ctx->opcode), t0); \
8129 tcg_temp_free_i64(t0); \
8131 #define GEN_SPEFPUOP_CONV_64_64(name) \
8132 static inline void gen_##name(DisasContext *ctx) \
8134 TCGv_i64 t0 = tcg_temp_new_i64(); \
8135 gen_load_gpr64(t0, rB(ctx->opcode)); \
8136 gen_helper_##name(t0, t0); \
8137 gen_store_gpr64(rD(ctx->opcode), t0); \
8138 tcg_temp_free_i64(t0); \
8140 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
8141 static inline void gen_##name(DisasContext *ctx) \
8143 if (unlikely(!ctx->spe_enabled)) { \
8144 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8147 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], \
8148 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8150 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
8151 static inline void gen_##name(DisasContext *ctx) \
8154 if (unlikely(!ctx->spe_enabled)) { \
8155 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8158 t0 = tcg_temp_new_i64(); \
8159 t1 = tcg_temp_new_i64(); \
8160 gen_load_gpr64(t0, rA(ctx->opcode)); \
8161 gen_load_gpr64(t1, rB(ctx->opcode)); \
8162 gen_helper_##name(t0, t0, t1); \
8163 gen_store_gpr64(rD(ctx->opcode), t0); \
8164 tcg_temp_free_i64(t0); \
8165 tcg_temp_free_i64(t1); \
8167 #define GEN_SPEFPUOP_COMP_32(name) \
8168 static inline void gen_##name(DisasContext *ctx) \
8170 if (unlikely(!ctx->spe_enabled)) { \
8171 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8174 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
8175 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8177 #define GEN_SPEFPUOP_COMP_64(name) \
8178 static inline void gen_##name(DisasContext *ctx) \
8181 if (unlikely(!ctx->spe_enabled)) { \
8182 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8185 t0 = tcg_temp_new_i64(); \
8186 t1 = tcg_temp_new_i64(); \
8187 gen_load_gpr64(t0, rA(ctx->opcode)); \
8188 gen_load_gpr64(t1, rB(ctx->opcode)); \
8189 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], t0, t1); \
8190 tcg_temp_free_i64(t0); \
8191 tcg_temp_free_i64(t1); \
8195 /* Single precision floating-point vectors operations */
8197 GEN_SPEFPUOP_ARITH2_64_64(evfsadd
);
8198 GEN_SPEFPUOP_ARITH2_64_64(evfssub
);
8199 GEN_SPEFPUOP_ARITH2_64_64(evfsmul
);
8200 GEN_SPEFPUOP_ARITH2_64_64(evfsdiv
);
8201 static inline void gen_evfsabs(DisasContext
*ctx
)
8203 if (unlikely(!ctx
->spe_enabled
)) {
8204 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8207 #if defined(TARGET_PPC64)
8208 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000080000000LL
);
8210 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x80000000);
8211 tcg_gen_andi_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
8214 static inline void gen_evfsnabs(DisasContext
*ctx
)
8216 if (unlikely(!ctx
->spe_enabled
)) {
8217 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8220 #if defined(TARGET_PPC64)
8221 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
8223 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8224 tcg_gen_ori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8227 static inline void gen_evfsneg(DisasContext
*ctx
)
8229 if (unlikely(!ctx
->spe_enabled
)) {
8230 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8233 #if defined(TARGET_PPC64)
8234 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
8236 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8237 tcg_gen_xori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8242 GEN_SPEFPUOP_CONV_64_64(evfscfui
);
8243 GEN_SPEFPUOP_CONV_64_64(evfscfsi
);
8244 GEN_SPEFPUOP_CONV_64_64(evfscfuf
);
8245 GEN_SPEFPUOP_CONV_64_64(evfscfsf
);
8246 GEN_SPEFPUOP_CONV_64_64(evfsctui
);
8247 GEN_SPEFPUOP_CONV_64_64(evfsctsi
);
8248 GEN_SPEFPUOP_CONV_64_64(evfsctuf
);
8249 GEN_SPEFPUOP_CONV_64_64(evfsctsf
);
8250 GEN_SPEFPUOP_CONV_64_64(evfsctuiz
);
8251 GEN_SPEFPUOP_CONV_64_64(evfsctsiz
);
8254 GEN_SPEFPUOP_COMP_64(evfscmpgt
);
8255 GEN_SPEFPUOP_COMP_64(evfscmplt
);
8256 GEN_SPEFPUOP_COMP_64(evfscmpeq
);
8257 GEN_SPEFPUOP_COMP_64(evfststgt
);
8258 GEN_SPEFPUOP_COMP_64(evfststlt
);
8259 GEN_SPEFPUOP_COMP_64(evfststeq
);
8261 /* Opcodes definitions */
8262 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8263 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
); //
8264 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8265 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8266 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8267 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8268 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8269 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8270 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8271 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8272 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8273 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8274 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8275 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8277 /* Single precision floating-point operations */
8279 GEN_SPEFPUOP_ARITH2_32_32(efsadd
);
8280 GEN_SPEFPUOP_ARITH2_32_32(efssub
);
8281 GEN_SPEFPUOP_ARITH2_32_32(efsmul
);
8282 GEN_SPEFPUOP_ARITH2_32_32(efsdiv
);
8283 static inline void gen_efsabs(DisasContext
*ctx
)
8285 if (unlikely(!ctx
->spe_enabled
)) {
8286 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8289 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], (target_long
)~0x80000000LL
);
8291 static inline void gen_efsnabs(DisasContext
*ctx
)
8293 if (unlikely(!ctx
->spe_enabled
)) {
8294 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8297 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8299 static inline void gen_efsneg(DisasContext
*ctx
)
8301 if (unlikely(!ctx
->spe_enabled
)) {
8302 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8305 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8309 GEN_SPEFPUOP_CONV_32_32(efscfui
);
8310 GEN_SPEFPUOP_CONV_32_32(efscfsi
);
8311 GEN_SPEFPUOP_CONV_32_32(efscfuf
);
8312 GEN_SPEFPUOP_CONV_32_32(efscfsf
);
8313 GEN_SPEFPUOP_CONV_32_32(efsctui
);
8314 GEN_SPEFPUOP_CONV_32_32(efsctsi
);
8315 GEN_SPEFPUOP_CONV_32_32(efsctuf
);
8316 GEN_SPEFPUOP_CONV_32_32(efsctsf
);
8317 GEN_SPEFPUOP_CONV_32_32(efsctuiz
);
8318 GEN_SPEFPUOP_CONV_32_32(efsctsiz
);
8319 GEN_SPEFPUOP_CONV_32_64(efscfd
);
8322 GEN_SPEFPUOP_COMP_32(efscmpgt
);
8323 GEN_SPEFPUOP_COMP_32(efscmplt
);
8324 GEN_SPEFPUOP_COMP_32(efscmpeq
);
8325 GEN_SPEFPUOP_COMP_32(efststgt
);
8326 GEN_SPEFPUOP_COMP_32(efststlt
);
8327 GEN_SPEFPUOP_COMP_32(efststeq
);
8329 /* Opcodes definitions */
8330 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8331 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
); //
8332 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8333 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8334 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8335 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE
); //
8336 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8337 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8338 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8339 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8340 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8341 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8342 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8343 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8345 /* Double precision floating-point operations */
8347 GEN_SPEFPUOP_ARITH2_64_64(efdadd
);
8348 GEN_SPEFPUOP_ARITH2_64_64(efdsub
);
8349 GEN_SPEFPUOP_ARITH2_64_64(efdmul
);
8350 GEN_SPEFPUOP_ARITH2_64_64(efddiv
);
8351 static inline void gen_efdabs(DisasContext
*ctx
)
8353 if (unlikely(!ctx
->spe_enabled
)) {
8354 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8357 #if defined(TARGET_PPC64)
8358 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000000000000LL
);
8360 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8361 tcg_gen_andi_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
8364 static inline void gen_efdnabs(DisasContext
*ctx
)
8366 if (unlikely(!ctx
->spe_enabled
)) {
8367 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8370 #if defined(TARGET_PPC64)
8371 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
8373 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8374 tcg_gen_ori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8377 static inline void gen_efdneg(DisasContext
*ctx
)
8379 if (unlikely(!ctx
->spe_enabled
)) {
8380 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8383 #if defined(TARGET_PPC64)
8384 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
8386 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8387 tcg_gen_xori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8392 GEN_SPEFPUOP_CONV_64_32(efdcfui
);
8393 GEN_SPEFPUOP_CONV_64_32(efdcfsi
);
8394 GEN_SPEFPUOP_CONV_64_32(efdcfuf
);
8395 GEN_SPEFPUOP_CONV_64_32(efdcfsf
);
8396 GEN_SPEFPUOP_CONV_32_64(efdctui
);
8397 GEN_SPEFPUOP_CONV_32_64(efdctsi
);
8398 GEN_SPEFPUOP_CONV_32_64(efdctuf
);
8399 GEN_SPEFPUOP_CONV_32_64(efdctsf
);
8400 GEN_SPEFPUOP_CONV_32_64(efdctuiz
);
8401 GEN_SPEFPUOP_CONV_32_64(efdctsiz
);
8402 GEN_SPEFPUOP_CONV_64_32(efdcfs
);
8403 GEN_SPEFPUOP_CONV_64_64(efdcfuid
);
8404 GEN_SPEFPUOP_CONV_64_64(efdcfsid
);
8405 GEN_SPEFPUOP_CONV_64_64(efdctuidz
);
8406 GEN_SPEFPUOP_CONV_64_64(efdctsidz
);
8409 GEN_SPEFPUOP_COMP_64(efdcmpgt
);
8410 GEN_SPEFPUOP_COMP_64(efdcmplt
);
8411 GEN_SPEFPUOP_COMP_64(efdcmpeq
);
8412 GEN_SPEFPUOP_COMP_64(efdtstgt
);
8413 GEN_SPEFPUOP_COMP_64(efdtstlt
);
8414 GEN_SPEFPUOP_COMP_64(efdtsteq
);
8416 /* Opcodes definitions */
8417 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
); //
8418 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8419 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE
); //
8420 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8421 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
); //
8422 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8423 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
); //
8424 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE
); //
8425 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8426 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8427 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8428 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8429 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8430 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8431 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
); //
8432 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8434 static opcode_t opcodes
[] = {
8435 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
),
8436 GEN_HANDLER(cmp
, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER
),
8437 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
8438 GEN_HANDLER(cmpl
, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER
),
8439 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
8440 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
),
8441 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8442 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8443 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8444 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8445 GEN_HANDLER(mulhw
, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER
),
8446 GEN_HANDLER(mulhwu
, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER
),
8447 GEN_HANDLER(mullw
, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER
),
8448 GEN_HANDLER(mullwo
, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER
),
8449 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8450 #if defined(TARGET_PPC64)
8451 GEN_HANDLER(mulld
, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B
),
8453 GEN_HANDLER(neg
, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER
),
8454 GEN_HANDLER(nego
, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER
),
8455 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8456 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8457 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8458 GEN_HANDLER(cntlzw
, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER
),
8459 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
),
8460 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
),
8461 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8462 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8463 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8464 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8465 GEN_HANDLER(popcntb
, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB
),
8466 GEN_HANDLER(popcntw
, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD
),
8467 #if defined(TARGET_PPC64)
8468 GEN_HANDLER(popcntd
, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD
),
8469 GEN_HANDLER(cntlzd
, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B
),
8471 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8472 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8473 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8474 GEN_HANDLER(slw
, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER
),
8475 GEN_HANDLER(sraw
, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER
),
8476 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
),
8477 GEN_HANDLER(srw
, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER
),
8478 #if defined(TARGET_PPC64)
8479 GEN_HANDLER(sld
, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B
),
8480 GEN_HANDLER(srad
, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B
),
8481 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
),
8482 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
),
8483 GEN_HANDLER(srd
, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B
),
8485 GEN_HANDLER(frsqrtes
, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES
),
8486 GEN_HANDLER(fsqrt
, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
8487 GEN_HANDLER(fsqrts
, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
8488 GEN_HANDLER(fcmpo
, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT
),
8489 GEN_HANDLER(fcmpu
, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT
),
8490 GEN_HANDLER(fmr
, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT
),
8491 GEN_HANDLER(mcrfs
, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT
),
8492 GEN_HANDLER(mffs
, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT
),
8493 GEN_HANDLER(mtfsb0
, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT
),
8494 GEN_HANDLER(mtfsb1
, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT
),
8495 GEN_HANDLER(mtfsf
, 0x3F, 0x07, 0x16, 0x00010000, PPC_FLOAT
),
8496 GEN_HANDLER(mtfsfi
, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT
),
8497 #if defined(TARGET_PPC64)
8498 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
),
8499 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
),
8500 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
),
8502 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8503 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8504 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
),
8505 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
),
8506 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
),
8507 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
),
8508 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO
),
8509 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
),
8510 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES
),
8511 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
),
8512 #if defined(TARGET_PPC64)
8513 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B
),
8514 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
),
8516 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
),
8517 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
),
8518 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
8519 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
8520 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
),
8521 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
),
8522 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
),
8523 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
),
8524 #if defined(TARGET_PPC64)
8525 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
),
8526 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
),
8528 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW
),
8529 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
),
8530 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
8531 #if defined(TARGET_PPC64)
8532 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
),
8533 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
),
8535 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
),
8536 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
),
8537 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
),
8538 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
),
8539 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
),
8540 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
),
8541 #if defined(TARGET_PPC64)
8542 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
),
8544 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC
),
8545 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC
),
8546 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
),
8547 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
),
8548 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
),
8549 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE
),
8550 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE
),
8551 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE_DCBZ
),
8552 GEN_HANDLER2(dcbz_970
, "dcbz", 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZT
),
8553 GEN_HANDLER(dst
, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC
),
8554 GEN_HANDLER(dstst
, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC
),
8555 GEN_HANDLER(dss
, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC
),
8556 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
),
8557 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
),
8558 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
),
8559 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
),
8560 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
),
8561 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
),
8562 #if defined(TARGET_PPC64)
8563 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
),
8564 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
8566 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
),
8567 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
8569 GEN_HANDLER2(slbmte
, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B
),
8570 GEN_HANDLER2(slbmfee
, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B
),
8571 GEN_HANDLER2(slbmfev
, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B
),
8573 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
),
8574 GEN_HANDLER(tlbiel
, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE
),
8575 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE
),
8576 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
),
8577 #if defined(TARGET_PPC64)
8578 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI
),
8579 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
),
8581 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
),
8582 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
),
8583 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
),
8584 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
),
8585 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
),
8586 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
),
8587 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
),
8588 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
),
8589 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
),
8590 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
),
8591 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
),
8592 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
8593 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
),
8594 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
),
8595 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
),
8596 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
),
8597 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
),
8598 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
),
8599 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
),
8600 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
8601 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
),
8602 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
),
8603 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
),
8604 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
),
8605 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
),
8606 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
),
8607 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
),
8608 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
),
8609 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
),
8610 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
),
8611 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
),
8612 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
),
8613 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
),
8614 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
),
8615 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
),
8616 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
),
8617 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
),
8618 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
),
8619 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
),
8620 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
),
8621 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
),
8622 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
),
8623 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
),
8624 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
),
8625 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
),
8626 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
),
8627 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
),
8628 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
),
8629 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
),
8630 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8631 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8632 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
),
8633 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
),
8634 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8635 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8636 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
),
8637 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
),
8638 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
),
8639 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
),
8640 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
),
8641 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
),
8642 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
),
8643 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
),
8644 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
),
8645 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
),
8646 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
),
8647 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
),
8648 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
),
8649 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
),
8650 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
),
8651 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
),
8652 GEN_HANDLER_E(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
, PPC2_BOOKE206
),
8653 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
),
8654 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
),
8655 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
),
8656 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
),
8657 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
),
8658 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
),
8659 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
),
8660 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
),
8661 GEN_HANDLER2_E(tlbre_booke206
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
8662 PPC_NONE
, PPC2_BOOKE206
),
8663 GEN_HANDLER2_E(tlbsx_booke206
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
8664 PPC_NONE
, PPC2_BOOKE206
),
8665 GEN_HANDLER2_E(tlbwe_booke206
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
8666 PPC_NONE
, PPC2_BOOKE206
),
8667 GEN_HANDLER2_E(tlbivax_booke206
, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
8668 PPC_NONE
, PPC2_BOOKE206
),
8669 GEN_HANDLER2_E(tlbilx_booke206
, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
8670 PPC_NONE
, PPC2_BOOKE206
),
8671 GEN_HANDLER2_E(msgsnd
, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
8672 PPC_NONE
, PPC2_PRCNTL
),
8673 GEN_HANDLER2_E(msgclr
, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
8674 PPC_NONE
, PPC2_PRCNTL
),
8675 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
),
8676 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE
),
8677 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
),
8678 GEN_HANDLER_E(mbar
, 0x1F, 0x16, 0x1a, 0x001FF801,
8679 PPC_BOOKE
, PPC2_BOOKE206
),
8680 GEN_HANDLER(msync_4xx
, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE
),
8681 GEN_HANDLER2_E(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
8682 PPC_BOOKE
, PPC2_BOOKE206
),
8683 GEN_HANDLER(lvsl
, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC
),
8684 GEN_HANDLER(lvsr
, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC
),
8685 GEN_HANDLER(mfvscr
, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC
),
8686 GEN_HANDLER(mtvscr
, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC
),
8687 GEN_HANDLER(vsldoi
, 0x04, 0x16, 0xFF, 0x00000400, PPC_ALTIVEC
),
8688 GEN_HANDLER(vmladduhm
, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC
),
8689 GEN_HANDLER2(evsel0
, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE
),
8690 GEN_HANDLER2(evsel1
, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE
),
8691 GEN_HANDLER2(evsel2
, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE
),
8692 GEN_HANDLER2(evsel3
, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE
),
8694 #undef GEN_INT_ARITH_ADD
8695 #undef GEN_INT_ARITH_ADD_CONST
8696 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
8697 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
8698 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
8699 add_ca, compute_ca, compute_ov) \
8700 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
8701 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
8702 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
8703 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
8704 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
8705 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
8706 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
8707 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
8708 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
8709 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
8710 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
8712 #undef GEN_INT_ARITH_DIVW
8713 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
8714 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
8715 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0),
8716 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1),
8717 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0),
8718 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1),
8720 #if defined(TARGET_PPC64)
8721 #undef GEN_INT_ARITH_DIVD
8722 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
8723 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8724 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0),
8725 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1),
8726 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0),
8727 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1),
8729 #undef GEN_INT_ARITH_MUL_HELPER
8730 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
8731 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8732 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00),
8733 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02),
8734 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17),
8737 #undef GEN_INT_ARITH_SUBF
8738 #undef GEN_INT_ARITH_SUBF_CONST
8739 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
8740 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
8741 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
8742 add_ca, compute_ca, compute_ov) \
8743 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
8744 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
8745 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
8746 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
8747 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
8748 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
8749 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
8750 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
8751 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
8752 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
8753 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
8757 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
8758 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
8759 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
8760 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
8761 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
),
8762 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
),
8763 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
),
8764 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
),
8765 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
),
8766 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
),
8767 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
),
8768 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
),
8769 #if defined(TARGET_PPC64)
8770 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
),
8773 #if defined(TARGET_PPC64)
8776 #define GEN_PPC64_R2(name, opc1, opc2) \
8777 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8778 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
8780 #define GEN_PPC64_R4(name, opc1, opc2) \
8781 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8782 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
8784 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
8786 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
8788 GEN_PPC64_R4(rldicl
, 0x1E, 0x00),
8789 GEN_PPC64_R4(rldicr
, 0x1E, 0x02),
8790 GEN_PPC64_R4(rldic
, 0x1E, 0x04),
8791 GEN_PPC64_R2(rldcl
, 0x1E, 0x08),
8792 GEN_PPC64_R2(rldcr
, 0x1E, 0x09),
8793 GEN_PPC64_R4(rldimi
, 0x1E, 0x06),
8796 #undef _GEN_FLOAT_ACB
8797 #undef GEN_FLOAT_ACB
8798 #undef _GEN_FLOAT_AB
8800 #undef _GEN_FLOAT_AC
8804 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
8805 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
8806 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
8807 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
8808 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
8809 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
8810 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
8811 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
8812 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
8813 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
8814 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
8815 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
8816 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
8817 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
8818 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
8819 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
8820 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
8821 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
8822 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
8824 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
),
8825 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
),
8826 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
),
8827 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
),
8828 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
),
8829 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
),
8830 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
),
8831 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
),
8832 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
),
8833 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
),
8834 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
),
8835 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
),
8836 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
),
8837 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
),
8838 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
),
8839 #if defined(TARGET_PPC64)
8840 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
),
8841 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
),
8842 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
),
8844 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
),
8845 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
),
8846 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
),
8847 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
),
8848 GEN_FLOAT_B(abs
, 0x08, 0x08, 0, PPC_FLOAT
),
8849 GEN_FLOAT_B(nabs
, 0x08, 0x04, 0, PPC_FLOAT
),
8850 GEN_FLOAT_B(neg
, 0x08, 0x01, 0, PPC_FLOAT
),
8857 #define GEN_LD(name, ldop, opc, type) \
8858 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8859 #define GEN_LDU(name, ldop, opc, type) \
8860 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
8861 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
8862 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
8863 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
8864 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
8865 #define GEN_LDS(name, ldop, op, type) \
8866 GEN_LD(name, ldop, op | 0x20, type) \
8867 GEN_LDU(name, ldop, op | 0x21, type) \
8868 GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
8869 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
8871 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
)
8872 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
)
8873 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
)
8874 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
)
8875 #if defined(TARGET_PPC64)
8876 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
)
8877 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
)
8878 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
)
8879 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
)
8880 GEN_LDX_E(ldbr
, ld64ur
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
)
8882 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
)
8883 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
)
8890 #define GEN_ST(name, stop, opc, type) \
8891 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8892 #define GEN_STU(name, stop, opc, type) \
8893 GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
8894 #define GEN_STUX(name, stop, opc2, opc3, type) \
8895 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
8896 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
8897 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
8898 #define GEN_STS(name, stop, op, type) \
8899 GEN_ST(name, stop, op | 0x20, type) \
8900 GEN_STU(name, stop, op | 0x21, type) \
8901 GEN_STUX(name, stop, 0x17, op | 0x01, type) \
8902 GEN_STX(name, stop, 0x17, op | 0x00, type)
8904 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
)
8905 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
)
8906 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
)
8907 #if defined(TARGET_PPC64)
8908 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
)
8909 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
)
8910 GEN_STX_E(stdbr
, st64r
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
)
8912 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
)
8913 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
)
8920 #define GEN_LDF(name, ldop, opc, type) \
8921 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8922 #define GEN_LDUF(name, ldop, opc, type) \
8923 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
8924 #define GEN_LDUXF(name, ldop, opc, type) \
8925 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
8926 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
8927 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
8928 #define GEN_LDFS(name, ldop, op, type) \
8929 GEN_LDF(name, ldop, op | 0x20, type) \
8930 GEN_LDUF(name, ldop, op | 0x21, type) \
8931 GEN_LDUXF(name, ldop, op | 0x01, type) \
8932 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
8934 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
)
8935 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
)
8942 #define GEN_STF(name, stop, opc, type) \
8943 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8944 #define GEN_STUF(name, stop, opc, type) \
8945 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
8946 #define GEN_STUXF(name, stop, opc, type) \
8947 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
8948 #define GEN_STXF(name, stop, opc2, opc3, type) \
8949 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
8950 #define GEN_STFS(name, stop, op, type) \
8951 GEN_STF(name, stop, op | 0x20, type) \
8952 GEN_STUF(name, stop, op | 0x21, type) \
8953 GEN_STUXF(name, stop, op | 0x01, type) \
8954 GEN_STXF(name, stop, 0x17, op | 0x00, type)
8956 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
)
8957 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
)
8958 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
)
8961 #define GEN_CRLOGIC(name, tcg_op, opc) \
8962 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
8963 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08),
8964 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04),
8965 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09),
8966 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07),
8967 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01),
8968 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E),
8969 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D),
8970 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06),
8972 #undef GEN_MAC_HANDLER
8973 #define GEN_MAC_HANDLER(name, opc2, opc3) \
8974 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
8975 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05),
8976 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15),
8977 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07),
8978 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17),
8979 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06),
8980 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16),
8981 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04),
8982 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14),
8983 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01),
8984 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11),
8985 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03),
8986 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13),
8987 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02),
8988 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12),
8989 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00),
8990 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10),
8991 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D),
8992 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D),
8993 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F),
8994 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F),
8995 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C),
8996 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C),
8997 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E),
8998 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E),
8999 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05),
9000 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15),
9001 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07),
9002 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17),
9003 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01),
9004 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11),
9005 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03),
9006 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13),
9007 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D),
9008 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D),
9009 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F),
9010 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F),
9011 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05),
9012 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04),
9013 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01),
9014 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00),
9015 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D),
9016 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C),
9022 #define GEN_VR_LDX(name, opc2, opc3) \
9023 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9024 #define GEN_VR_STX(name, opc2, opc3) \
9025 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9026 #define GEN_VR_LVE(name, opc2, opc3) \
9027 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9028 #define GEN_VR_STVE(name, opc2, opc3) \
9029 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9030 GEN_VR_LDX(lvx
, 0x07, 0x03),
9031 GEN_VR_LDX(lvxl
, 0x07, 0x0B),
9032 GEN_VR_LVE(bx
, 0x07, 0x00),
9033 GEN_VR_LVE(hx
, 0x07, 0x01),
9034 GEN_VR_LVE(wx
, 0x07, 0x02),
9035 GEN_VR_STX(svx
, 0x07, 0x07),
9036 GEN_VR_STX(svxl
, 0x07, 0x0F),
9037 GEN_VR_STVE(bx
, 0x07, 0x04),
9038 GEN_VR_STVE(hx
, 0x07, 0x05),
9039 GEN_VR_STVE(wx
, 0x07, 0x06),
9041 #undef GEN_VX_LOGICAL
9042 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
9043 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9044 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16),
9045 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17),
9046 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18),
9047 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19),
9048 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20),
9051 #define GEN_VXFORM(name, opc2, opc3) \
9052 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9053 GEN_VXFORM(vaddubm
, 0, 0),
9054 GEN_VXFORM(vadduhm
, 0, 1),
9055 GEN_VXFORM(vadduwm
, 0, 2),
9056 GEN_VXFORM(vsububm
, 0, 16),
9057 GEN_VXFORM(vsubuhm
, 0, 17),
9058 GEN_VXFORM(vsubuwm
, 0, 18),
9059 GEN_VXFORM(vmaxub
, 1, 0),
9060 GEN_VXFORM(vmaxuh
, 1, 1),
9061 GEN_VXFORM(vmaxuw
, 1, 2),
9062 GEN_VXFORM(vmaxsb
, 1, 4),
9063 GEN_VXFORM(vmaxsh
, 1, 5),
9064 GEN_VXFORM(vmaxsw
, 1, 6),
9065 GEN_VXFORM(vminub
, 1, 8),
9066 GEN_VXFORM(vminuh
, 1, 9),
9067 GEN_VXFORM(vminuw
, 1, 10),
9068 GEN_VXFORM(vminsb
, 1, 12),
9069 GEN_VXFORM(vminsh
, 1, 13),
9070 GEN_VXFORM(vminsw
, 1, 14),
9071 GEN_VXFORM(vavgub
, 1, 16),
9072 GEN_VXFORM(vavguh
, 1, 17),
9073 GEN_VXFORM(vavguw
, 1, 18),
9074 GEN_VXFORM(vavgsb
, 1, 20),
9075 GEN_VXFORM(vavgsh
, 1, 21),
9076 GEN_VXFORM(vavgsw
, 1, 22),
9077 GEN_VXFORM(vmrghb
, 6, 0),
9078 GEN_VXFORM(vmrghh
, 6, 1),
9079 GEN_VXFORM(vmrghw
, 6, 2),
9080 GEN_VXFORM(vmrglb
, 6, 4),
9081 GEN_VXFORM(vmrglh
, 6, 5),
9082 GEN_VXFORM(vmrglw
, 6, 6),
9083 GEN_VXFORM(vmuloub
, 4, 0),
9084 GEN_VXFORM(vmulouh
, 4, 1),
9085 GEN_VXFORM(vmulosb
, 4, 4),
9086 GEN_VXFORM(vmulosh
, 4, 5),
9087 GEN_VXFORM(vmuleub
, 4, 8),
9088 GEN_VXFORM(vmuleuh
, 4, 9),
9089 GEN_VXFORM(vmulesb
, 4, 12),
9090 GEN_VXFORM(vmulesh
, 4, 13),
9091 GEN_VXFORM(vslb
, 2, 4),
9092 GEN_VXFORM(vslh
, 2, 5),
9093 GEN_VXFORM(vslw
, 2, 6),
9094 GEN_VXFORM(vsrb
, 2, 8),
9095 GEN_VXFORM(vsrh
, 2, 9),
9096 GEN_VXFORM(vsrw
, 2, 10),
9097 GEN_VXFORM(vsrab
, 2, 12),
9098 GEN_VXFORM(vsrah
, 2, 13),
9099 GEN_VXFORM(vsraw
, 2, 14),
9100 GEN_VXFORM(vslo
, 6, 16),
9101 GEN_VXFORM(vsro
, 6, 17),
9102 GEN_VXFORM(vaddcuw
, 0, 6),
9103 GEN_VXFORM(vsubcuw
, 0, 22),
9104 GEN_VXFORM(vaddubs
, 0, 8),
9105 GEN_VXFORM(vadduhs
, 0, 9),
9106 GEN_VXFORM(vadduws
, 0, 10),
9107 GEN_VXFORM(vaddsbs
, 0, 12),
9108 GEN_VXFORM(vaddshs
, 0, 13),
9109 GEN_VXFORM(vaddsws
, 0, 14),
9110 GEN_VXFORM(vsububs
, 0, 24),
9111 GEN_VXFORM(vsubuhs
, 0, 25),
9112 GEN_VXFORM(vsubuws
, 0, 26),
9113 GEN_VXFORM(vsubsbs
, 0, 28),
9114 GEN_VXFORM(vsubshs
, 0, 29),
9115 GEN_VXFORM(vsubsws
, 0, 30),
9116 GEN_VXFORM(vrlb
, 2, 0),
9117 GEN_VXFORM(vrlh
, 2, 1),
9118 GEN_VXFORM(vrlw
, 2, 2),
9119 GEN_VXFORM(vsl
, 2, 7),
9120 GEN_VXFORM(vsr
, 2, 11),
9121 GEN_VXFORM(vpkuhum
, 7, 0),
9122 GEN_VXFORM(vpkuwum
, 7, 1),
9123 GEN_VXFORM(vpkuhus
, 7, 2),
9124 GEN_VXFORM(vpkuwus
, 7, 3),
9125 GEN_VXFORM(vpkshus
, 7, 4),
9126 GEN_VXFORM(vpkswus
, 7, 5),
9127 GEN_VXFORM(vpkshss
, 7, 6),
9128 GEN_VXFORM(vpkswss
, 7, 7),
9129 GEN_VXFORM(vpkpx
, 7, 12),
9130 GEN_VXFORM(vsum4ubs
, 4, 24),
9131 GEN_VXFORM(vsum4sbs
, 4, 28),
9132 GEN_VXFORM(vsum4shs
, 4, 25),
9133 GEN_VXFORM(vsum2sws
, 4, 26),
9134 GEN_VXFORM(vsumsws
, 4, 30),
9135 GEN_VXFORM(vaddfp
, 5, 0),
9136 GEN_VXFORM(vsubfp
, 5, 1),
9137 GEN_VXFORM(vmaxfp
, 5, 16),
9138 GEN_VXFORM(vminfp
, 5, 17),
9142 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
9143 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
9144 #define GEN_VXRFORM(name, opc2, opc3) \
9145 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
9146 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
9147 GEN_VXRFORM(vcmpequb
, 3, 0)
9148 GEN_VXRFORM(vcmpequh
, 3, 1)
9149 GEN_VXRFORM(vcmpequw
, 3, 2)
9150 GEN_VXRFORM(vcmpgtsb
, 3, 12)
9151 GEN_VXRFORM(vcmpgtsh
, 3, 13)
9152 GEN_VXRFORM(vcmpgtsw
, 3, 14)
9153 GEN_VXRFORM(vcmpgtub
, 3, 8)
9154 GEN_VXRFORM(vcmpgtuh
, 3, 9)
9155 GEN_VXRFORM(vcmpgtuw
, 3, 10)
9156 GEN_VXRFORM(vcmpeqfp
, 3, 3)
9157 GEN_VXRFORM(vcmpgefp
, 3, 7)
9158 GEN_VXRFORM(vcmpgtfp
, 3, 11)
9159 GEN_VXRFORM(vcmpbfp
, 3, 15)
9161 #undef GEN_VXFORM_SIMM
9162 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
9163 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9164 GEN_VXFORM_SIMM(vspltisb
, 6, 12),
9165 GEN_VXFORM_SIMM(vspltish
, 6, 13),
9166 GEN_VXFORM_SIMM(vspltisw
, 6, 14),
9168 #undef GEN_VXFORM_NOA
9169 #define GEN_VXFORM_NOA(name, opc2, opc3) \
9170 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
9171 GEN_VXFORM_NOA(vupkhsb
, 7, 8),
9172 GEN_VXFORM_NOA(vupkhsh
, 7, 9),
9173 GEN_VXFORM_NOA(vupklsb
, 7, 10),
9174 GEN_VXFORM_NOA(vupklsh
, 7, 11),
9175 GEN_VXFORM_NOA(vupkhpx
, 7, 13),
9176 GEN_VXFORM_NOA(vupklpx
, 7, 15),
9177 GEN_VXFORM_NOA(vrefp
, 5, 4),
9178 GEN_VXFORM_NOA(vrsqrtefp
, 5, 5),
9179 GEN_VXFORM_NOA(vexptefp
, 5, 6),
9180 GEN_VXFORM_NOA(vlogefp
, 5, 7),
9181 GEN_VXFORM_NOA(vrfim
, 5, 8),
9182 GEN_VXFORM_NOA(vrfin
, 5, 9),
9183 GEN_VXFORM_NOA(vrfip
, 5, 10),
9184 GEN_VXFORM_NOA(vrfiz
, 5, 11),
9186 #undef GEN_VXFORM_UIMM
9187 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
9188 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9189 GEN_VXFORM_UIMM(vspltb
, 6, 8),
9190 GEN_VXFORM_UIMM(vsplth
, 6, 9),
9191 GEN_VXFORM_UIMM(vspltw
, 6, 10),
9192 GEN_VXFORM_UIMM(vcfux
, 5, 12),
9193 GEN_VXFORM_UIMM(vcfsx
, 5, 13),
9194 GEN_VXFORM_UIMM(vctuxs
, 5, 14),
9195 GEN_VXFORM_UIMM(vctsxs
, 5, 15),
9197 #undef GEN_VAFORM_PAIRED
9198 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
9199 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
9200 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16),
9201 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18),
9202 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19),
9203 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20),
9204 GEN_VAFORM_PAIRED(vsel
, vperm
, 21),
9205 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23),
9208 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
9209 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
9210 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9211 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9212 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9213 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9214 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
9215 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
9216 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
9217 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE
),
9218 GEN_SPE(evmra
, speundef
, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE
),
9219 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
),
9220 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9221 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9222 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9223 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE
),
9224 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE
),
9225 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE
),
9226 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
),
9227 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9228 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9229 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9230 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9231 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9232 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE
),
9233 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE
),
9234 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9235 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9236 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE
),
9237 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE
),
9238 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE
),
9240 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9241 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
),
9242 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9243 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9244 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9245 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9246 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9247 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9248 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9249 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9250 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9251 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9252 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9253 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9255 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9256 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
),
9257 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9258 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9259 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9260 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE
),
9261 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9262 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9263 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9264 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9265 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9266 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9267 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9268 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9270 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
),
9271 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9272 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE
),
9273 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9274 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
),
9275 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9276 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
),
9277 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE
),
9278 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9279 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9280 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9281 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9282 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9283 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9284 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
),
9285 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9287 #undef GEN_SPEOP_LDST
9288 #define GEN_SPEOP_LDST(name, opc2, sh) \
9289 GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
9290 GEN_SPEOP_LDST(evldd
, 0x00, 3),
9291 GEN_SPEOP_LDST(evldw
, 0x01, 3),
9292 GEN_SPEOP_LDST(evldh
, 0x02, 3),
9293 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1),
9294 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1),
9295 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1),
9296 GEN_SPEOP_LDST(evlwhe
, 0x08, 2),
9297 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2),
9298 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2),
9299 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2),
9300 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2),
9302 GEN_SPEOP_LDST(evstdd
, 0x10, 3),
9303 GEN_SPEOP_LDST(evstdw
, 0x11, 3),
9304 GEN_SPEOP_LDST(evstdh
, 0x12, 3),
9305 GEN_SPEOP_LDST(evstwhe
, 0x18, 2),
9306 GEN_SPEOP_LDST(evstwho
, 0x1A, 2),
9307 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2),
9308 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2),
9311 #include "helper_regs.h"
9312 #include "translate_init.c"
9314 /*****************************************************************************/
9315 /* Misc PowerPC helpers */
9316 void cpu_dump_state (CPUPPCState
*env
, FILE *f
, fprintf_function cpu_fprintf
,
9324 cpu_synchronize_state(env
);
9326 cpu_fprintf(f
, "NIP " TARGET_FMT_lx
" LR " TARGET_FMT_lx
" CTR "
9327 TARGET_FMT_lx
" XER " TARGET_FMT_lx
"\n",
9328 env
->nip
, env
->lr
, env
->ctr
, env
->xer
);
9329 cpu_fprintf(f
, "MSR " TARGET_FMT_lx
" HID0 " TARGET_FMT_lx
" HF "
9330 TARGET_FMT_lx
" idx %d\n", env
->msr
, env
->spr
[SPR_HID0
],
9331 env
->hflags
, env
->mmu_idx
);
9332 #if !defined(NO_TIMER_DUMP)
9333 cpu_fprintf(f
, "TB %08" PRIu32
" %08" PRIu64
9334 #if !defined(CONFIG_USER_ONLY)
9338 cpu_ppc_load_tbu(env
), cpu_ppc_load_tbl(env
)
9339 #if !defined(CONFIG_USER_ONLY)
9340 , cpu_ppc_load_decr(env
)
9344 for (i
= 0; i
< 32; i
++) {
9345 if ((i
& (RGPL
- 1)) == 0)
9346 cpu_fprintf(f
, "GPR%02d", i
);
9347 cpu_fprintf(f
, " %016" PRIx64
, ppc_dump_gpr(env
, i
));
9348 if ((i
& (RGPL
- 1)) == (RGPL
- 1))
9349 cpu_fprintf(f
, "\n");
9351 cpu_fprintf(f
, "CR ");
9352 for (i
= 0; i
< 8; i
++)
9353 cpu_fprintf(f
, "%01x", env
->crf
[i
]);
9354 cpu_fprintf(f
, " [");
9355 for (i
= 0; i
< 8; i
++) {
9357 if (env
->crf
[i
] & 0x08)
9359 else if (env
->crf
[i
] & 0x04)
9361 else if (env
->crf
[i
] & 0x02)
9363 cpu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
9365 cpu_fprintf(f
, " ] RES " TARGET_FMT_lx
"\n",
9367 for (i
= 0; i
< 32; i
++) {
9368 if ((i
& (RFPL
- 1)) == 0)
9369 cpu_fprintf(f
, "FPR%02d", i
);
9370 cpu_fprintf(f
, " %016" PRIx64
, *((uint64_t *)&env
->fpr
[i
]));
9371 if ((i
& (RFPL
- 1)) == (RFPL
- 1))
9372 cpu_fprintf(f
, "\n");
9374 cpu_fprintf(f
, "FPSCR %08x\n", env
->fpscr
);
9375 #if !defined(CONFIG_USER_ONLY)
9376 cpu_fprintf(f
, " SRR0 " TARGET_FMT_lx
" SRR1 " TARGET_FMT_lx
9377 " PVR " TARGET_FMT_lx
" VRSAVE " TARGET_FMT_lx
"\n",
9378 env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
9379 env
->spr
[SPR_PVR
], env
->spr
[SPR_VRSAVE
]);
9381 cpu_fprintf(f
, "SPRG0 " TARGET_FMT_lx
" SPRG1 " TARGET_FMT_lx
9382 " SPRG2 " TARGET_FMT_lx
" SPRG3 " TARGET_FMT_lx
"\n",
9383 env
->spr
[SPR_SPRG0
], env
->spr
[SPR_SPRG1
],
9384 env
->spr
[SPR_SPRG2
], env
->spr
[SPR_SPRG3
]);
9386 cpu_fprintf(f
, "SPRG4 " TARGET_FMT_lx
" SPRG5 " TARGET_FMT_lx
9387 " SPRG6 " TARGET_FMT_lx
" SPRG7 " TARGET_FMT_lx
"\n",
9388 env
->spr
[SPR_SPRG4
], env
->spr
[SPR_SPRG5
],
9389 env
->spr
[SPR_SPRG6
], env
->spr
[SPR_SPRG7
]);
9391 if (env
->excp_model
== POWERPC_EXCP_BOOKE
) {
9392 cpu_fprintf(f
, "CSRR0 " TARGET_FMT_lx
" CSRR1 " TARGET_FMT_lx
9393 " MCSRR0 " TARGET_FMT_lx
" MCSRR1 " TARGET_FMT_lx
"\n",
9394 env
->spr
[SPR_BOOKE_CSRR0
], env
->spr
[SPR_BOOKE_CSRR1
],
9395 env
->spr
[SPR_BOOKE_MCSRR0
], env
->spr
[SPR_BOOKE_MCSRR1
]);
9397 cpu_fprintf(f
, " TCR " TARGET_FMT_lx
" TSR " TARGET_FMT_lx
9398 " ESR " TARGET_FMT_lx
" DEAR " TARGET_FMT_lx
"\n",
9399 env
->spr
[SPR_BOOKE_TCR
], env
->spr
[SPR_BOOKE_TSR
],
9400 env
->spr
[SPR_BOOKE_ESR
], env
->spr
[SPR_BOOKE_DEAR
]);
9402 cpu_fprintf(f
, " PIR " TARGET_FMT_lx
" DECAR " TARGET_FMT_lx
9403 " IVPR " TARGET_FMT_lx
" EPCR " TARGET_FMT_lx
"\n",
9404 env
->spr
[SPR_BOOKE_PIR
], env
->spr
[SPR_BOOKE_DECAR
],
9405 env
->spr
[SPR_BOOKE_IVPR
], env
->spr
[SPR_BOOKE_EPCR
]);
9407 cpu_fprintf(f
, " MCSR " TARGET_FMT_lx
" SPRG8 " TARGET_FMT_lx
9408 " EPR " TARGET_FMT_lx
"\n",
9409 env
->spr
[SPR_BOOKE_MCSR
], env
->spr
[SPR_BOOKE_SPRG8
],
9410 env
->spr
[SPR_BOOKE_EPR
]);
9413 cpu_fprintf(f
, " MCAR " TARGET_FMT_lx
" PID1 " TARGET_FMT_lx
9414 " PID2 " TARGET_FMT_lx
" SVR " TARGET_FMT_lx
"\n",
9415 env
->spr
[SPR_Exxx_MCAR
], env
->spr
[SPR_BOOKE_PID1
],
9416 env
->spr
[SPR_BOOKE_PID2
], env
->spr
[SPR_E500_SVR
]);
9419 * IVORs are left out as they are large and do not change often --
9420 * they can be read with "p $ivor0", "p $ivor1", etc.
9424 #if defined(TARGET_PPC64)
9425 if (env
->flags
& POWERPC_FLAG_CFAR
) {
9426 cpu_fprintf(f
, " CFAR " TARGET_FMT_lx
"\n", env
->cfar
);
9430 switch (env
->mmu_model
) {
9431 case POWERPC_MMU_32B
:
9432 case POWERPC_MMU_601
:
9433 case POWERPC_MMU_SOFT_6xx
:
9434 case POWERPC_MMU_SOFT_74xx
:
9435 #if defined(TARGET_PPC64)
9436 case POWERPC_MMU_620
:
9437 case POWERPC_MMU_64B
:
9439 cpu_fprintf(f
, " SDR1 " TARGET_FMT_lx
"\n", env
->spr
[SPR_SDR1
]);
9441 case POWERPC_MMU_BOOKE206
:
9442 cpu_fprintf(f
, " MAS0 " TARGET_FMT_lx
" MAS1 " TARGET_FMT_lx
9443 " MAS2 " TARGET_FMT_lx
" MAS3 " TARGET_FMT_lx
"\n",
9444 env
->spr
[SPR_BOOKE_MAS0
], env
->spr
[SPR_BOOKE_MAS1
],
9445 env
->spr
[SPR_BOOKE_MAS2
], env
->spr
[SPR_BOOKE_MAS3
]);
9447 cpu_fprintf(f
, " MAS4 " TARGET_FMT_lx
" MAS6 " TARGET_FMT_lx
9448 " MAS7 " TARGET_FMT_lx
" PID " TARGET_FMT_lx
"\n",
9449 env
->spr
[SPR_BOOKE_MAS4
], env
->spr
[SPR_BOOKE_MAS6
],
9450 env
->spr
[SPR_BOOKE_MAS7
], env
->spr
[SPR_BOOKE_PID
]);
9452 cpu_fprintf(f
, "MMUCFG " TARGET_FMT_lx
" TLB0CFG " TARGET_FMT_lx
9453 " TLB1CFG " TARGET_FMT_lx
"\n",
9454 env
->spr
[SPR_MMUCFG
], env
->spr
[SPR_BOOKE_TLB0CFG
],
9455 env
->spr
[SPR_BOOKE_TLB1CFG
]);
9466 void cpu_dump_statistics (CPUPPCState
*env
, FILE*f
, fprintf_function cpu_fprintf
,
9469 #if defined(DO_PPC_STATISTICS)
9470 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
9474 for (op1
= 0; op1
< 64; op1
++) {
9476 if (is_indirect_opcode(handler
)) {
9477 t2
= ind_table(handler
);
9478 for (op2
= 0; op2
< 32; op2
++) {
9480 if (is_indirect_opcode(handler
)) {
9481 t3
= ind_table(handler
);
9482 for (op3
= 0; op3
< 32; op3
++) {
9484 if (handler
->count
== 0)
9486 cpu_fprintf(f
, "%02x %02x %02x (%02x %04d) %16s: "
9487 "%016" PRIx64
" %" PRId64
"\n",
9488 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
9490 handler
->count
, handler
->count
);
9493 if (handler
->count
== 0)
9495 cpu_fprintf(f
, "%02x %02x (%02x %04d) %16s: "
9496 "%016" PRIx64
" %" PRId64
"\n",
9497 op1
, op2
, op1
, op2
, handler
->oname
,
9498 handler
->count
, handler
->count
);
9502 if (handler
->count
== 0)
9504 cpu_fprintf(f
, "%02x (%02x ) %16s: %016" PRIx64
9506 op1
, op1
, handler
->oname
,
9507 handler
->count
, handler
->count
);
9513 /*****************************************************************************/
9514 static inline void gen_intermediate_code_internal(CPUPPCState
*env
,
9515 TranslationBlock
*tb
,
9518 DisasContext ctx
, *ctxp
= &ctx
;
9519 opc_handler_t
**table
, *handler
;
9520 target_ulong pc_start
;
9521 uint16_t *gen_opc_end
;
9528 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
9531 ctx
.exception
= POWERPC_EXCP_NONE
;
9532 ctx
.spr_cb
= env
->spr_cb
;
9533 ctx
.mem_idx
= env
->mmu_idx
;
9534 ctx
.access_type
= -1;
9535 ctx
.le_mode
= env
->hflags
& (1 << MSR_LE
) ? 1 : 0;
9536 #if defined(TARGET_PPC64)
9537 ctx
.sf_mode
= msr_sf
;
9538 ctx
.has_cfar
= !!(env
->flags
& POWERPC_FLAG_CFAR
);
9540 ctx
.fpu_enabled
= msr_fp
;
9541 if ((env
->flags
& POWERPC_FLAG_SPE
) && msr_spe
)
9542 ctx
.spe_enabled
= msr_spe
;
9544 ctx
.spe_enabled
= 0;
9545 if ((env
->flags
& POWERPC_FLAG_VRE
) && msr_vr
)
9546 ctx
.altivec_enabled
= msr_vr
;
9548 ctx
.altivec_enabled
= 0;
9549 if ((env
->flags
& POWERPC_FLAG_SE
) && msr_se
)
9550 ctx
.singlestep_enabled
= CPU_SINGLE_STEP
;
9552 ctx
.singlestep_enabled
= 0;
9553 if ((env
->flags
& POWERPC_FLAG_BE
) && msr_be
)
9554 ctx
.singlestep_enabled
|= CPU_BRANCH_STEP
;
9555 if (unlikely(env
->singlestep_enabled
))
9556 ctx
.singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
9557 #if defined (DO_SINGLE_STEP) && 0
9558 /* Single step trace mode */
9562 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
9564 max_insns
= CF_COUNT_MASK
;
9567 /* Set env in case of segfault during code fetch */
9568 while (ctx
.exception
== POWERPC_EXCP_NONE
&& gen_opc_ptr
< gen_opc_end
) {
9569 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
9570 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
9571 if (bp
->pc
== ctx
.nip
) {
9572 gen_debug_exception(ctxp
);
9577 if (unlikely(search_pc
)) {
9578 j
= gen_opc_ptr
- gen_opc_buf
;
9582 gen_opc_instr_start
[lj
++] = 0;
9584 gen_opc_pc
[lj
] = ctx
.nip
;
9585 gen_opc_instr_start
[lj
] = 1;
9586 gen_opc_icount
[lj
] = num_insns
;
9588 LOG_DISAS("----------------\n");
9589 LOG_DISAS("nip=" TARGET_FMT_lx
" super=%d ir=%d\n",
9590 ctx
.nip
, ctx
.mem_idx
, (int)msr_ir
);
9591 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
9593 if (unlikely(ctx
.le_mode
)) {
9594 ctx
.opcode
= bswap32(ldl_code(ctx
.nip
));
9596 ctx
.opcode
= ldl_code(ctx
.nip
);
9598 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
9599 ctx
.opcode
, opc1(ctx
.opcode
), opc2(ctx
.opcode
),
9600 opc3(ctx
.opcode
), little_endian
? "little" : "big");
9601 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
)))
9602 tcg_gen_debug_insn_start(ctx
.nip
);
9604 table
= env
->opcodes
;
9606 handler
= table
[opc1(ctx
.opcode
)];
9607 if (is_indirect_opcode(handler
)) {
9608 table
= ind_table(handler
);
9609 handler
= table
[opc2(ctx
.opcode
)];
9610 if (is_indirect_opcode(handler
)) {
9611 table
= ind_table(handler
);
9612 handler
= table
[opc3(ctx
.opcode
)];
9615 /* Is opcode *REALLY* valid ? */
9616 if (unlikely(handler
->handler
== &gen_invalid
)) {
9617 if (qemu_log_enabled()) {
9618 qemu_log("invalid/unsupported opcode: "
9619 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx
" %d\n",
9620 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
9621 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
9626 if (unlikely(handler
->type
& (PPC_SPE
| PPC_SPE_SINGLE
| PPC_SPE_DOUBLE
) && Rc(ctx
.opcode
))) {
9627 inval
= handler
->inval2
;
9629 inval
= handler
->inval1
;
9632 if (unlikely((ctx
.opcode
& inval
) != 0)) {
9633 if (qemu_log_enabled()) {
9634 qemu_log("invalid bits: %08x for opcode: "
9635 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx
"\n",
9636 ctx
.opcode
& inval
, opc1(ctx
.opcode
),
9637 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
9638 ctx
.opcode
, ctx
.nip
- 4);
9640 gen_inval_exception(ctxp
, POWERPC_EXCP_INVAL_INVAL
);
9644 (*(handler
->handler
))(&ctx
);
9645 #if defined(DO_PPC_STATISTICS)
9648 /* Check trace mode exceptions */
9649 if (unlikely(ctx
.singlestep_enabled
& CPU_SINGLE_STEP
&&
9650 (ctx
.nip
<= 0x100 || ctx
.nip
> 0xF00) &&
9651 ctx
.exception
!= POWERPC_SYSCALL
&&
9652 ctx
.exception
!= POWERPC_EXCP_TRAP
&&
9653 ctx
.exception
!= POWERPC_EXCP_BRANCH
)) {
9654 gen_exception(ctxp
, POWERPC_EXCP_TRACE
);
9655 } else if (unlikely(((ctx
.nip
& (TARGET_PAGE_SIZE
- 1)) == 0) ||
9656 (env
->singlestep_enabled
) ||
9658 num_insns
>= max_insns
)) {
9659 /* if we reach a page boundary or are single stepping, stop
9665 if (tb
->cflags
& CF_LAST_IO
)
9667 if (ctx
.exception
== POWERPC_EXCP_NONE
) {
9668 gen_goto_tb(&ctx
, 0, ctx
.nip
);
9669 } else if (ctx
.exception
!= POWERPC_EXCP_BRANCH
) {
9670 if (unlikely(env
->singlestep_enabled
)) {
9671 gen_debug_exception(ctxp
);
9673 /* Generate the return instruction */
9676 gen_icount_end(tb
, num_insns
);
9677 *gen_opc_ptr
= INDEX_op_end
;
9678 if (unlikely(search_pc
)) {
9679 j
= gen_opc_ptr
- gen_opc_buf
;
9682 gen_opc_instr_start
[lj
++] = 0;
9684 tb
->size
= ctx
.nip
- pc_start
;
9685 tb
->icount
= num_insns
;
9687 #if defined(DEBUG_DISAS)
9688 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
9690 flags
= env
->bfd_mach
;
9691 flags
|= ctx
.le_mode
<< 16;
9692 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
9693 log_target_disas(pc_start
, ctx
.nip
- pc_start
, flags
);
9699 void gen_intermediate_code (CPUPPCState
*env
, struct TranslationBlock
*tb
)
9701 gen_intermediate_code_internal(env
, tb
, 0);
9704 void gen_intermediate_code_pc (CPUPPCState
*env
, struct TranslationBlock
*tb
)
9706 gen_intermediate_code_internal(env
, tb
, 1);
9709 void restore_state_to_opc(CPUPPCState
*env
, TranslationBlock
*tb
, int pc_pos
)
9711 env
->nip
= gen_opc_pc
[pc_pos
];