2 * PowerPC emulation for qemu: main translation routines.
4 * Copyright (c) 2003-2007 Jocelyn Mayer
5 * Copyright (C) 2011 Freescale Semiconductor, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
22 #include "disas/disas.h"
24 #include "qemu/host-utils.h"
30 #define CPU_SINGLE_STEP 0x1
31 #define CPU_BRANCH_STEP 0x2
32 #define GDBSTUB_SINGLE_STEP 0x4
34 /* Include definitions for instructions classes and implementations flags */
35 //#define PPC_DEBUG_DISAS
36 //#define DO_PPC_STATISTICS
38 #ifdef PPC_DEBUG_DISAS
39 # define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
41 # define LOG_DISAS(...) do { } while (0)
43 /*****************************************************************************/
44 /* Code translation helpers */
46 /* global register indexes */
47 static TCGv_ptr cpu_env
;
48 static char cpu_reg_names
[10*3 + 22*4 /* GPR */
49 #if !defined(TARGET_PPC64)
50 + 10*4 + 22*5 /* SPE GPRh */
52 + 10*4 + 22*5 /* FPR */
53 + 2*(10*6 + 22*7) /* AVRh, AVRl */
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)
69 static TCGv cpu_xer
, cpu_so
, cpu_ov
, cpu_ca
;
70 static TCGv cpu_reserve
;
71 static TCGv cpu_fpscr
;
72 static TCGv_i32 cpu_access_type
;
74 #include "exec/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");
161 cpu_so
= tcg_global_mem_new(TCG_AREG0
,
162 offsetof(CPUPPCState
, so
), "SO");
163 cpu_ov
= tcg_global_mem_new(TCG_AREG0
,
164 offsetof(CPUPPCState
, ov
), "OV");
165 cpu_ca
= tcg_global_mem_new(TCG_AREG0
,
166 offsetof(CPUPPCState
, ca
), "CA");
168 cpu_reserve
= tcg_global_mem_new(TCG_AREG0
,
169 offsetof(CPUPPCState
, reserve_addr
),
172 cpu_fpscr
= tcg_global_mem_new(TCG_AREG0
,
173 offsetof(CPUPPCState
, fpscr
), "fpscr");
175 cpu_access_type
= tcg_global_mem_new_i32(TCG_AREG0
,
176 offsetof(CPUPPCState
, access_type
), "access_type");
178 /* register helpers */
185 /* internal defines */
186 typedef struct DisasContext
{
187 struct TranslationBlock
*tb
;
191 /* Routine used to access memory */
194 /* Translation flags */
196 #if defined(TARGET_PPC64)
203 ppc_spr_t
*spr_cb
; /* Needed to check rights for mfspr/mtspr */
204 int singlestep_enabled
;
205 uint64_t insns_flags
;
206 uint64_t insns_flags2
;
209 /* True when active word size < size of target_long. */
211 # define NARROW_MODE(C) (!(C)->sf_mode)
213 # define NARROW_MODE(C) 0
216 struct opc_handler_t
{
217 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
219 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
221 /* instruction type */
223 /* extended instruction type */
226 void (*handler
)(DisasContext
*ctx
);
227 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
230 #if defined(DO_PPC_STATISTICS)
235 static inline void gen_reset_fpstatus(void)
237 gen_helper_reset_fpstatus(cpu_env
);
240 static inline void gen_compute_fprf(TCGv_i64 arg
, int set_fprf
, int set_rc
)
242 TCGv_i32 t0
= tcg_temp_new_i32();
245 /* This case might be optimized later */
246 tcg_gen_movi_i32(t0
, 1);
247 gen_helper_compute_fprf(t0
, cpu_env
, arg
, t0
);
248 if (unlikely(set_rc
)) {
249 tcg_gen_mov_i32(cpu_crf
[1], t0
);
251 gen_helper_float_check_status(cpu_env
);
252 } else if (unlikely(set_rc
)) {
253 /* We always need to compute fpcc */
254 tcg_gen_movi_i32(t0
, 0);
255 gen_helper_compute_fprf(t0
, cpu_env
, arg
, t0
);
256 tcg_gen_mov_i32(cpu_crf
[1], t0
);
259 tcg_temp_free_i32(t0
);
262 static inline void gen_set_access_type(DisasContext
*ctx
, int access_type
)
264 if (ctx
->access_type
!= access_type
) {
265 tcg_gen_movi_i32(cpu_access_type
, access_type
);
266 ctx
->access_type
= access_type
;
270 static inline void gen_update_nip(DisasContext
*ctx
, target_ulong nip
)
272 if (NARROW_MODE(ctx
)) {
275 tcg_gen_movi_tl(cpu_nip
, nip
);
278 static inline void gen_exception_err(DisasContext
*ctx
, uint32_t excp
, uint32_t error
)
281 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
282 gen_update_nip(ctx
, ctx
->nip
);
284 t0
= tcg_const_i32(excp
);
285 t1
= tcg_const_i32(error
);
286 gen_helper_raise_exception_err(cpu_env
, t0
, t1
);
287 tcg_temp_free_i32(t0
);
288 tcg_temp_free_i32(t1
);
289 ctx
->exception
= (excp
);
292 static inline void gen_exception(DisasContext
*ctx
, uint32_t excp
)
295 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
296 gen_update_nip(ctx
, ctx
->nip
);
298 t0
= tcg_const_i32(excp
);
299 gen_helper_raise_exception(cpu_env
, t0
);
300 tcg_temp_free_i32(t0
);
301 ctx
->exception
= (excp
);
304 static inline void gen_debug_exception(DisasContext
*ctx
)
308 if ((ctx
->exception
!= POWERPC_EXCP_BRANCH
) &&
309 (ctx
->exception
!= POWERPC_EXCP_SYNC
)) {
310 gen_update_nip(ctx
, ctx
->nip
);
312 t0
= tcg_const_i32(EXCP_DEBUG
);
313 gen_helper_raise_exception(cpu_env
, t0
);
314 tcg_temp_free_i32(t0
);
317 static inline void gen_inval_exception(DisasContext
*ctx
, uint32_t error
)
319 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_INVAL
| error
);
322 /* Stop translation */
323 static inline void gen_stop_exception(DisasContext
*ctx
)
325 gen_update_nip(ctx
, ctx
->nip
);
326 ctx
->exception
= POWERPC_EXCP_STOP
;
329 /* No need to update nip here, as execution flow will change */
330 static inline void gen_sync_exception(DisasContext
*ctx
)
332 ctx
->exception
= POWERPC_EXCP_SYNC
;
335 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
336 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
338 #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
339 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
341 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
342 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
344 #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
345 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
347 typedef struct opcode_t
{
348 unsigned char opc1
, opc2
, opc3
;
349 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
350 unsigned char pad
[5];
352 unsigned char pad
[1];
354 opc_handler_t handler
;
358 /*****************************************************************************/
359 /*** Instruction decoding ***/
360 #define EXTRACT_HELPER(name, shift, nb) \
361 static inline uint32_t name(uint32_t opcode) \
363 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
366 #define EXTRACT_SHELPER(name, shift, nb) \
367 static inline int32_t name(uint32_t opcode) \
369 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
373 EXTRACT_HELPER(opc1
, 26, 6);
375 EXTRACT_HELPER(opc2
, 1, 5);
377 EXTRACT_HELPER(opc3
, 6, 5);
378 /* Update Cr0 flags */
379 EXTRACT_HELPER(Rc
, 0, 1);
381 EXTRACT_HELPER(rD
, 21, 5);
383 EXTRACT_HELPER(rS
, 21, 5);
385 EXTRACT_HELPER(rA
, 16, 5);
387 EXTRACT_HELPER(rB
, 11, 5);
389 EXTRACT_HELPER(rC
, 6, 5);
391 EXTRACT_HELPER(crfD
, 23, 3);
392 EXTRACT_HELPER(crfS
, 18, 3);
393 EXTRACT_HELPER(crbD
, 21, 5);
394 EXTRACT_HELPER(crbA
, 16, 5);
395 EXTRACT_HELPER(crbB
, 11, 5);
397 EXTRACT_HELPER(_SPR
, 11, 10);
398 static inline uint32_t SPR(uint32_t opcode
)
400 uint32_t sprn
= _SPR(opcode
);
402 return ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
404 /*** Get constants ***/
405 EXTRACT_HELPER(IMM
, 12, 8);
406 /* 16 bits signed immediate value */
407 EXTRACT_SHELPER(SIMM
, 0, 16);
408 /* 16 bits unsigned immediate value */
409 EXTRACT_HELPER(UIMM
, 0, 16);
410 /* 5 bits signed immediate value */
411 EXTRACT_HELPER(SIMM5
, 16, 5);
412 /* 5 bits signed immediate value */
413 EXTRACT_HELPER(UIMM5
, 16, 5);
415 EXTRACT_HELPER(NB
, 11, 5);
417 EXTRACT_HELPER(SH
, 11, 5);
418 /* Vector shift count */
419 EXTRACT_HELPER(VSH
, 6, 4);
421 EXTRACT_HELPER(MB
, 6, 5);
423 EXTRACT_HELPER(ME
, 1, 5);
425 EXTRACT_HELPER(TO
, 21, 5);
427 EXTRACT_HELPER(CRM
, 12, 8);
428 EXTRACT_HELPER(SR
, 16, 4);
431 EXTRACT_HELPER(FPBF
, 19, 3);
432 EXTRACT_HELPER(FPIMM
, 12, 4);
433 EXTRACT_HELPER(FPL
, 21, 1);
434 EXTRACT_HELPER(FPFLM
, 17, 8);
435 EXTRACT_HELPER(FPW
, 16, 1);
437 /*** Jump target decoding ***/
439 EXTRACT_SHELPER(d
, 0, 16);
440 /* Immediate address */
441 static inline target_ulong
LI(uint32_t opcode
)
443 return (opcode
>> 0) & 0x03FFFFFC;
446 static inline uint32_t BD(uint32_t opcode
)
448 return (opcode
>> 0) & 0xFFFC;
451 EXTRACT_HELPER(BO
, 21, 5);
452 EXTRACT_HELPER(BI
, 16, 5);
453 /* Absolute/relative address */
454 EXTRACT_HELPER(AA
, 1, 1);
456 EXTRACT_HELPER(LK
, 0, 1);
458 /* Create a mask between <start> and <end> bits */
459 static inline target_ulong
MASK(uint32_t start
, uint32_t end
)
463 #if defined(TARGET_PPC64)
464 if (likely(start
== 0)) {
465 ret
= UINT64_MAX
<< (63 - end
);
466 } else if (likely(end
== 63)) {
467 ret
= UINT64_MAX
>> start
;
470 if (likely(start
== 0)) {
471 ret
= UINT32_MAX
<< (31 - end
);
472 } else if (likely(end
== 31)) {
473 ret
= UINT32_MAX
>> start
;
477 ret
= (((target_ulong
)(-1ULL)) >> (start
)) ^
478 (((target_ulong
)(-1ULL) >> (end
)) >> 1);
479 if (unlikely(start
> end
))
486 /*****************************************************************************/
487 /* PowerPC instructions table */
489 #if defined(DO_PPC_STATISTICS)
490 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
500 .handler = &gen_##name, \
501 .oname = stringify(name), \
503 .oname = stringify(name), \
505 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
516 .handler = &gen_##name, \
517 .oname = stringify(name), \
519 .oname = stringify(name), \
521 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
531 .handler = &gen_##name, \
537 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
547 .handler = &gen_##name, \
549 .oname = stringify(name), \
551 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
562 .handler = &gen_##name, \
564 .oname = stringify(name), \
566 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
576 .handler = &gen_##name, \
582 /* SPR load/store helpers */
583 static inline void gen_load_spr(TCGv t
, int reg
)
585 tcg_gen_ld_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
588 static inline void gen_store_spr(int reg
, TCGv t
)
590 tcg_gen_st_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
593 /* Invalid instruction */
594 static void gen_invalid(DisasContext
*ctx
)
596 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
599 static opc_handler_t invalid_handler
= {
600 .inval1
= 0xFFFFFFFF,
601 .inval2
= 0xFFFFFFFF,
604 .handler
= gen_invalid
,
607 /*** Integer comparison ***/
609 static inline void gen_op_cmp(TCGv arg0
, TCGv arg1
, int s
, int crf
)
611 TCGv t0
= tcg_temp_new();
612 TCGv_i32 t1
= tcg_temp_new_i32();
614 tcg_gen_trunc_tl_i32(cpu_crf
[crf
], cpu_so
);
616 tcg_gen_setcond_tl((s
? TCG_COND_LT
: TCG_COND_LTU
), t0
, arg0
, arg1
);
617 tcg_gen_trunc_tl_i32(t1
, t0
);
618 tcg_gen_shli_i32(t1
, t1
, CRF_LT
);
619 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
621 tcg_gen_setcond_tl((s
? TCG_COND_GT
: TCG_COND_GTU
), t0
, arg0
, arg1
);
622 tcg_gen_trunc_tl_i32(t1
, t0
);
623 tcg_gen_shli_i32(t1
, t1
, CRF_GT
);
624 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
626 tcg_gen_setcond_tl(TCG_COND_EQ
, t0
, arg0
, arg1
);
627 tcg_gen_trunc_tl_i32(t1
, t0
);
628 tcg_gen_shli_i32(t1
, t1
, CRF_EQ
);
629 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
632 tcg_temp_free_i32(t1
);
635 static inline void gen_op_cmpi(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
637 TCGv t0
= tcg_const_tl(arg1
);
638 gen_op_cmp(arg0
, t0
, s
, crf
);
642 static inline void gen_op_cmp32(TCGv arg0
, TCGv arg1
, int s
, int crf
)
648 tcg_gen_ext32s_tl(t0
, arg0
);
649 tcg_gen_ext32s_tl(t1
, arg1
);
651 tcg_gen_ext32u_tl(t0
, arg0
);
652 tcg_gen_ext32u_tl(t1
, arg1
);
654 gen_op_cmp(t0
, t1
, s
, crf
);
659 static inline void gen_op_cmpi32(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
661 TCGv t0
= tcg_const_tl(arg1
);
662 gen_op_cmp32(arg0
, t0
, s
, crf
);
666 static inline void gen_set_Rc0(DisasContext
*ctx
, TCGv reg
)
668 if (NARROW_MODE(ctx
)) {
669 gen_op_cmpi32(reg
, 0, 1, 0);
671 gen_op_cmpi(reg
, 0, 1, 0);
676 static void gen_cmp(DisasContext
*ctx
)
678 if (NARROW_MODE(ctx
) || !(ctx
->opcode
& 0x00200000)) {
679 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
680 1, crfD(ctx
->opcode
));
682 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
683 1, crfD(ctx
->opcode
));
688 static void gen_cmpi(DisasContext
*ctx
)
690 if (NARROW_MODE(ctx
) || !(ctx
->opcode
& 0x00200000)) {
691 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
692 1, crfD(ctx
->opcode
));
694 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
695 1, crfD(ctx
->opcode
));
700 static void gen_cmpl(DisasContext
*ctx
)
702 if (NARROW_MODE(ctx
) || !(ctx
->opcode
& 0x00200000)) {
703 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
704 0, crfD(ctx
->opcode
));
706 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
707 0, crfD(ctx
->opcode
));
712 static void gen_cmpli(DisasContext
*ctx
)
714 if (NARROW_MODE(ctx
) || !(ctx
->opcode
& 0x00200000)) {
715 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
716 0, crfD(ctx
->opcode
));
718 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
719 0, crfD(ctx
->opcode
));
723 /* isel (PowerPC 2.03 specification) */
724 static void gen_isel(DisasContext
*ctx
)
727 uint32_t bi
= rC(ctx
->opcode
);
731 l1
= gen_new_label();
732 l2
= gen_new_label();
734 mask
= 1 << (3 - (bi
& 0x03));
735 t0
= tcg_temp_new_i32();
736 tcg_gen_andi_i32(t0
, cpu_crf
[bi
>> 2], mask
);
737 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
738 if (rA(ctx
->opcode
) == 0)
739 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
741 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
744 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
746 tcg_temp_free_i32(t0
);
749 /* cmpb: PowerPC 2.05 specification */
750 static void gen_cmpb(DisasContext
*ctx
)
752 gen_helper_cmpb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
753 cpu_gpr
[rB(ctx
->opcode
)]);
756 /*** Integer arithmetic ***/
758 static inline void gen_op_arith_compute_ov(DisasContext
*ctx
, TCGv arg0
,
759 TCGv arg1
, TCGv arg2
, int sub
)
761 TCGv t0
= tcg_temp_new();
763 tcg_gen_xor_tl(cpu_ov
, arg0
, arg2
);
764 tcg_gen_xor_tl(t0
, arg1
, arg2
);
766 tcg_gen_and_tl(cpu_ov
, cpu_ov
, t0
);
768 tcg_gen_andc_tl(cpu_ov
, cpu_ov
, t0
);
771 if (NARROW_MODE(ctx
)) {
772 tcg_gen_ext32s_tl(cpu_ov
, cpu_ov
);
774 tcg_gen_shri_tl(cpu_ov
, cpu_ov
, TARGET_LONG_BITS
- 1);
775 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
778 /* Common add function */
779 static inline void gen_op_arith_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
780 TCGv arg2
, bool add_ca
, bool compute_ca
,
781 bool compute_ov
, bool compute_rc0
)
785 if (compute_ca
|| compute_ov
) {
790 if (NARROW_MODE(ctx
)) {
791 /* Caution: a non-obvious corner case of the spec is that we
792 must produce the *entire* 64-bit addition, but produce the
793 carry into bit 32. */
794 TCGv t1
= tcg_temp_new();
795 tcg_gen_xor_tl(t1
, arg1
, arg2
); /* add without carry */
796 tcg_gen_add_tl(t0
, arg1
, arg2
);
798 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
800 tcg_gen_xor_tl(cpu_ca
, t0
, t1
); /* bits changed w/ carry */
802 tcg_gen_shri_tl(cpu_ca
, cpu_ca
, 32); /* extract bit 32 */
803 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
805 TCGv zero
= tcg_const_tl(0);
807 tcg_gen_add2_tl(t0
, cpu_ca
, arg1
, zero
, cpu_ca
, zero
);
808 tcg_gen_add2_tl(t0
, cpu_ca
, t0
, cpu_ca
, arg2
, zero
);
810 tcg_gen_add2_tl(t0
, cpu_ca
, arg1
, zero
, arg2
, zero
);
815 tcg_gen_add_tl(t0
, arg1
, arg2
);
817 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
822 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 0);
824 if (unlikely(compute_rc0
)) {
825 gen_set_Rc0(ctx
, t0
);
828 if (!TCGV_EQUAL(t0
, ret
)) {
829 tcg_gen_mov_tl(ret
, t0
);
833 /* Add functions with two operands */
834 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
835 static void glue(gen_, name)(DisasContext *ctx) \
837 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
838 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
839 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
841 /* Add functions with one operand and one immediate */
842 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
843 add_ca, compute_ca, compute_ov) \
844 static void glue(gen_, name)(DisasContext *ctx) \
846 TCGv t0 = tcg_const_tl(const_val); \
847 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
848 cpu_gpr[rA(ctx->opcode)], t0, \
849 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
853 /* add add. addo addo. */
854 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
855 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
856 /* addc addc. addco addco. */
857 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
858 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
859 /* adde adde. addeo addeo. */
860 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
861 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
862 /* addme addme. addmeo addmeo. */
863 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
864 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
865 /* addze addze. addzeo addzeo.*/
866 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
867 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
869 static void gen_addi(DisasContext
*ctx
)
871 target_long simm
= SIMM(ctx
->opcode
);
873 if (rA(ctx
->opcode
) == 0) {
875 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
);
877 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)],
878 cpu_gpr
[rA(ctx
->opcode
)], simm
);
882 static inline void gen_op_addic(DisasContext
*ctx
, bool compute_rc0
)
884 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
885 gen_op_arith_add(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
886 c
, 0, 1, 0, compute_rc0
);
890 static void gen_addic(DisasContext
*ctx
)
892 gen_op_addic(ctx
, 0);
895 static void gen_addic_(DisasContext
*ctx
)
897 gen_op_addic(ctx
, 1);
901 static void gen_addis(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
<< 16);
909 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)],
910 cpu_gpr
[rA(ctx
->opcode
)], simm
<< 16);
914 static inline void gen_op_arith_divw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
915 TCGv arg2
, int sign
, int compute_ov
)
917 int l1
= gen_new_label();
918 int l2
= gen_new_label();
919 TCGv_i32 t0
= tcg_temp_local_new_i32();
920 TCGv_i32 t1
= tcg_temp_local_new_i32();
922 tcg_gen_trunc_tl_i32(t0
, arg1
);
923 tcg_gen_trunc_tl_i32(t1
, arg2
);
924 tcg_gen_brcondi_i32(TCG_COND_EQ
, t1
, 0, l1
);
926 int l3
= gen_new_label();
927 tcg_gen_brcondi_i32(TCG_COND_NE
, t1
, -1, l3
);
928 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, INT32_MIN
, l1
);
930 tcg_gen_div_i32(t0
, t0
, t1
);
932 tcg_gen_divu_i32(t0
, t0
, t1
);
935 tcg_gen_movi_tl(cpu_ov
, 0);
940 tcg_gen_sari_i32(t0
, t0
, 31);
942 tcg_gen_movi_i32(t0
, 0);
945 tcg_gen_movi_tl(cpu_ov
, 1);
946 tcg_gen_movi_tl(cpu_so
, 1);
949 tcg_gen_extu_i32_tl(ret
, t0
);
950 tcg_temp_free_i32(t0
);
951 tcg_temp_free_i32(t1
);
952 if (unlikely(Rc(ctx
->opcode
) != 0))
953 gen_set_Rc0(ctx
, ret
);
956 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
957 static void glue(gen_, name)(DisasContext *ctx) \
959 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
960 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
963 /* divwu divwu. divwuo divwuo. */
964 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0);
965 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1);
966 /* divw divw. divwo divwo. */
967 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0);
968 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1);
969 #if defined(TARGET_PPC64)
970 static inline void gen_op_arith_divd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
971 TCGv arg2
, int sign
, int compute_ov
)
973 int l1
= gen_new_label();
974 int l2
= gen_new_label();
976 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg2
, 0, l1
);
978 int l3
= gen_new_label();
979 tcg_gen_brcondi_i64(TCG_COND_NE
, arg2
, -1, l3
);
980 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg1
, INT64_MIN
, l1
);
982 tcg_gen_div_i64(ret
, arg1
, arg2
);
984 tcg_gen_divu_i64(ret
, arg1
, arg2
);
987 tcg_gen_movi_tl(cpu_ov
, 0);
992 tcg_gen_sari_i64(ret
, arg1
, 63);
994 tcg_gen_movi_i64(ret
, 0);
997 tcg_gen_movi_tl(cpu_ov
, 1);
998 tcg_gen_movi_tl(cpu_so
, 1);
1001 if (unlikely(Rc(ctx
->opcode
) != 0))
1002 gen_set_Rc0(ctx
, ret
);
1004 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1005 static void glue(gen_, name)(DisasContext *ctx) \
1007 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1008 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1009 sign, compute_ov); \
1011 /* divwu divwu. divwuo divwuo. */
1012 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0);
1013 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1);
1014 /* divw divw. divwo divwo. */
1015 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0);
1016 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1);
1020 static void gen_mulhw(DisasContext
*ctx
)
1022 TCGv_i32 t0
= tcg_temp_new_i32();
1023 TCGv_i32 t1
= tcg_temp_new_i32();
1025 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1026 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1027 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1028 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1029 tcg_temp_free_i32(t0
);
1030 tcg_temp_free_i32(t1
);
1031 if (unlikely(Rc(ctx
->opcode
) != 0))
1032 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1035 /* mulhwu mulhwu. */
1036 static void gen_mulhwu(DisasContext
*ctx
)
1038 TCGv_i32 t0
= tcg_temp_new_i32();
1039 TCGv_i32 t1
= tcg_temp_new_i32();
1041 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1042 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1043 tcg_gen_mulu2_i32(t0
, t1
, t0
, t1
);
1044 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1045 tcg_temp_free_i32(t0
);
1046 tcg_temp_free_i32(t1
);
1047 if (unlikely(Rc(ctx
->opcode
) != 0))
1048 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1052 static void gen_mullw(DisasContext
*ctx
)
1054 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1055 cpu_gpr
[rB(ctx
->opcode
)]);
1056 tcg_gen_ext32s_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)]);
1057 if (unlikely(Rc(ctx
->opcode
) != 0))
1058 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1061 /* mullwo mullwo. */
1062 static void gen_mullwo(DisasContext
*ctx
)
1064 TCGv_i32 t0
= tcg_temp_new_i32();
1065 TCGv_i32 t1
= tcg_temp_new_i32();
1067 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1068 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1069 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1070 tcg_gen_ext_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1072 tcg_gen_sari_i32(t0
, t0
, 31);
1073 tcg_gen_setcond_i32(TCG_COND_NE
, t0
, t0
, t1
);
1074 tcg_gen_extu_i32_tl(cpu_ov
, t0
);
1075 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1077 tcg_temp_free_i32(t0
);
1078 tcg_temp_free_i32(t1
);
1079 if (unlikely(Rc(ctx
->opcode
) != 0))
1080 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1084 static void gen_mulli(DisasContext
*ctx
)
1086 tcg_gen_muli_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1090 #if defined(TARGET_PPC64)
1092 static void gen_mulhd(DisasContext
*ctx
)
1094 TCGv lo
= tcg_temp_new();
1095 tcg_gen_muls2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1096 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1098 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1099 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1103 /* mulhdu mulhdu. */
1104 static void gen_mulhdu(DisasContext
*ctx
)
1106 TCGv lo
= tcg_temp_new();
1107 tcg_gen_mulu2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1108 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1110 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1111 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1116 static void gen_mulld(DisasContext
*ctx
)
1118 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1119 cpu_gpr
[rB(ctx
->opcode
)]);
1120 if (unlikely(Rc(ctx
->opcode
) != 0))
1121 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1124 /* mulldo mulldo. */
1125 static void gen_mulldo(DisasContext
*ctx
)
1127 gen_helper_mulldo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
1128 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1129 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1130 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1135 /* Common subf function */
1136 static inline void gen_op_arith_subf(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1137 TCGv arg2
, bool add_ca
, bool compute_ca
,
1138 bool compute_ov
, bool compute_rc0
)
1142 if (compute_ca
|| compute_ov
) {
1143 t0
= tcg_temp_new();
1147 /* dest = ~arg1 + arg2 [+ ca]. */
1148 if (NARROW_MODE(ctx
)) {
1149 /* Caution: a non-obvious corner case of the spec is that we
1150 must produce the *entire* 64-bit addition, but produce the
1151 carry into bit 32. */
1152 TCGv inv1
= tcg_temp_new();
1153 TCGv t1
= tcg_temp_new();
1154 tcg_gen_not_tl(inv1
, arg1
);
1156 tcg_gen_add_tl(t0
, arg2
, cpu_ca
);
1158 tcg_gen_addi_tl(t0
, arg2
, 1);
1160 tcg_gen_xor_tl(t1
, arg2
, inv1
); /* add without carry */
1161 tcg_gen_add_tl(t0
, t0
, inv1
);
1162 tcg_gen_xor_tl(cpu_ca
, t0
, t1
); /* bits changes w/ carry */
1164 tcg_gen_shri_tl(cpu_ca
, cpu_ca
, 32); /* extract bit 32 */
1165 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
1166 } else if (add_ca
) {
1167 TCGv zero
, inv1
= tcg_temp_new();
1168 tcg_gen_not_tl(inv1
, arg1
);
1169 zero
= tcg_const_tl(0);
1170 tcg_gen_add2_tl(t0
, cpu_ca
, arg2
, zero
, cpu_ca
, zero
);
1171 tcg_gen_add2_tl(t0
, cpu_ca
, t0
, cpu_ca
, inv1
, zero
);
1172 tcg_temp_free(zero
);
1173 tcg_temp_free(inv1
);
1175 tcg_gen_setcond_tl(TCG_COND_GEU
, cpu_ca
, arg2
, arg1
);
1176 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1178 } else if (add_ca
) {
1179 /* Since we're ignoring carry-out, we can simplify the
1180 standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1. */
1181 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1182 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
1183 tcg_gen_subi_tl(t0
, t0
, 1);
1185 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1189 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 1);
1191 if (unlikely(compute_rc0
)) {
1192 gen_set_Rc0(ctx
, t0
);
1195 if (!TCGV_EQUAL(t0
, ret
)) {
1196 tcg_gen_mov_tl(ret
, t0
);
1200 /* Sub functions with Two operands functions */
1201 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1202 static void glue(gen_, name)(DisasContext *ctx) \
1204 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1205 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1206 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1208 /* Sub functions with one operand and one immediate */
1209 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1210 add_ca, compute_ca, compute_ov) \
1211 static void glue(gen_, name)(DisasContext *ctx) \
1213 TCGv t0 = tcg_const_tl(const_val); \
1214 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1215 cpu_gpr[rA(ctx->opcode)], t0, \
1216 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1217 tcg_temp_free(t0); \
1219 /* subf subf. subfo subfo. */
1220 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
1221 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
1222 /* subfc subfc. subfco subfco. */
1223 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
1224 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
1225 /* subfe subfe. subfeo subfo. */
1226 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
1227 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
1228 /* subfme subfme. subfmeo subfmeo. */
1229 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
1230 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
1231 /* subfze subfze. subfzeo subfzeo.*/
1232 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
1233 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
1236 static void gen_subfic(DisasContext
*ctx
)
1238 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
1239 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1244 /* neg neg. nego nego. */
1245 static inline void gen_op_arith_neg(DisasContext
*ctx
, bool compute_ov
)
1247 TCGv zero
= tcg_const_tl(0);
1248 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1249 zero
, 0, 0, compute_ov
, Rc(ctx
->opcode
));
1250 tcg_temp_free(zero
);
1253 static void gen_neg(DisasContext
*ctx
)
1255 gen_op_arith_neg(ctx
, 0);
1258 static void gen_nego(DisasContext
*ctx
)
1260 gen_op_arith_neg(ctx
, 1);
1263 /*** Integer logical ***/
1264 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1265 static void glue(gen_, name)(DisasContext *ctx) \
1267 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1268 cpu_gpr[rB(ctx->opcode)]); \
1269 if (unlikely(Rc(ctx->opcode) != 0)) \
1270 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1273 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1274 static void glue(gen_, name)(DisasContext *ctx) \
1276 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1277 if (unlikely(Rc(ctx->opcode) != 0)) \
1278 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1282 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
);
1284 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
);
1287 static void gen_andi_(DisasContext
*ctx
)
1289 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
));
1290 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1294 static void gen_andis_(DisasContext
*ctx
)
1296 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
) << 16);
1297 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1301 static void gen_cntlzw(DisasContext
*ctx
)
1303 gen_helper_cntlzw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1304 if (unlikely(Rc(ctx
->opcode
) != 0))
1305 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1308 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
);
1309 /* extsb & extsb. */
1310 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
);
1311 /* extsh & extsh. */
1312 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
);
1314 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
);
1316 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
);
1319 static void gen_or(DisasContext
*ctx
)
1323 rs
= rS(ctx
->opcode
);
1324 ra
= rA(ctx
->opcode
);
1325 rb
= rB(ctx
->opcode
);
1326 /* Optimisation for mr. ri case */
1327 if (rs
!= ra
|| rs
!= rb
) {
1329 tcg_gen_or_tl(cpu_gpr
[ra
], cpu_gpr
[rs
], cpu_gpr
[rb
]);
1331 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rs
]);
1332 if (unlikely(Rc(ctx
->opcode
) != 0))
1333 gen_set_Rc0(ctx
, cpu_gpr
[ra
]);
1334 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
1335 gen_set_Rc0(ctx
, cpu_gpr
[rs
]);
1336 #if defined(TARGET_PPC64)
1342 /* Set process priority to low */
1346 /* Set process priority to medium-low */
1350 /* Set process priority to normal */
1353 #if !defined(CONFIG_USER_ONLY)
1355 if (ctx
->mem_idx
> 0) {
1356 /* Set process priority to very low */
1361 if (ctx
->mem_idx
> 0) {
1362 /* Set process priority to medium-hight */
1367 if (ctx
->mem_idx
> 0) {
1368 /* Set process priority to high */
1373 if (ctx
->mem_idx
> 1) {
1374 /* Set process priority to very high */
1384 TCGv t0
= tcg_temp_new();
1385 gen_load_spr(t0
, SPR_PPR
);
1386 tcg_gen_andi_tl(t0
, t0
, ~0x001C000000000000ULL
);
1387 tcg_gen_ori_tl(t0
, t0
, ((uint64_t)prio
) << 50);
1388 gen_store_spr(SPR_PPR
, t0
);
1395 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
);
1398 static void gen_xor(DisasContext
*ctx
)
1400 /* Optimisation for "set to zero" case */
1401 if (rS(ctx
->opcode
) != rB(ctx
->opcode
))
1402 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1404 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1405 if (unlikely(Rc(ctx
->opcode
) != 0))
1406 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1410 static void gen_ori(DisasContext
*ctx
)
1412 target_ulong uimm
= UIMM(ctx
->opcode
);
1414 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1416 /* XXX: should handle special NOPs for POWER series */
1419 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1423 static void gen_oris(DisasContext
*ctx
)
1425 target_ulong uimm
= UIMM(ctx
->opcode
);
1427 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1431 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1435 static void gen_xori(DisasContext
*ctx
)
1437 target_ulong uimm
= UIMM(ctx
->opcode
);
1439 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1443 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1447 static void gen_xoris(DisasContext
*ctx
)
1449 target_ulong uimm
= UIMM(ctx
->opcode
);
1451 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1455 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1458 /* popcntb : PowerPC 2.03 specification */
1459 static void gen_popcntb(DisasContext
*ctx
)
1461 gen_helper_popcntb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1464 static void gen_popcntw(DisasContext
*ctx
)
1466 gen_helper_popcntw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1469 #if defined(TARGET_PPC64)
1470 /* popcntd: PowerPC 2.06 specification */
1471 static void gen_popcntd(DisasContext
*ctx
)
1473 gen_helper_popcntd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1477 /* prtyw: PowerPC 2.05 specification */
1478 static void gen_prtyw(DisasContext
*ctx
)
1480 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
1481 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
1482 TCGv t0
= tcg_temp_new();
1483 tcg_gen_shri_tl(t0
, rs
, 16);
1484 tcg_gen_xor_tl(ra
, rs
, t0
);
1485 tcg_gen_shri_tl(t0
, ra
, 8);
1486 tcg_gen_xor_tl(ra
, ra
, t0
);
1487 tcg_gen_andi_tl(ra
, ra
, (target_ulong
)0x100000001ULL
);
1491 #if defined(TARGET_PPC64)
1492 /* prtyd: PowerPC 2.05 specification */
1493 static void gen_prtyd(DisasContext
*ctx
)
1495 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
1496 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
1497 TCGv t0
= tcg_temp_new();
1498 tcg_gen_shri_tl(t0
, rs
, 32);
1499 tcg_gen_xor_tl(ra
, rs
, t0
);
1500 tcg_gen_shri_tl(t0
, ra
, 16);
1501 tcg_gen_xor_tl(ra
, ra
, t0
);
1502 tcg_gen_shri_tl(t0
, ra
, 8);
1503 tcg_gen_xor_tl(ra
, ra
, t0
);
1504 tcg_gen_andi_tl(ra
, ra
, 1);
1509 #if defined(TARGET_PPC64)
1510 /* extsw & extsw. */
1511 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
);
1514 static void gen_cntlzd(DisasContext
*ctx
)
1516 gen_helper_cntlzd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1517 if (unlikely(Rc(ctx
->opcode
) != 0))
1518 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1522 /*** Integer rotate ***/
1524 /* rlwimi & rlwimi. */
1525 static void gen_rlwimi(DisasContext
*ctx
)
1527 uint32_t mb
, me
, sh
;
1529 mb
= MB(ctx
->opcode
);
1530 me
= ME(ctx
->opcode
);
1531 sh
= SH(ctx
->opcode
);
1532 if (likely(sh
== 0 && mb
== 0 && me
== 31)) {
1533 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1537 TCGv t0
= tcg_temp_new();
1538 #if defined(TARGET_PPC64)
1539 TCGv_i32 t2
= tcg_temp_new_i32();
1540 tcg_gen_trunc_i64_i32(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
1541 tcg_gen_rotli_i32(t2
, t2
, sh
);
1542 tcg_gen_extu_i32_i64(t0
, t2
);
1543 tcg_temp_free_i32(t2
);
1545 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1547 #if defined(TARGET_PPC64)
1551 mask
= MASK(mb
, me
);
1552 t1
= tcg_temp_new();
1553 tcg_gen_andi_tl(t0
, t0
, mask
);
1554 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1555 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1559 if (unlikely(Rc(ctx
->opcode
) != 0))
1560 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1563 /* rlwinm & rlwinm. */
1564 static void gen_rlwinm(DisasContext
*ctx
)
1566 uint32_t mb
, me
, sh
;
1568 sh
= SH(ctx
->opcode
);
1569 mb
= MB(ctx
->opcode
);
1570 me
= ME(ctx
->opcode
);
1572 if (likely(mb
== 0 && me
== (31 - sh
))) {
1573 if (likely(sh
== 0)) {
1574 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1576 TCGv t0
= tcg_temp_new();
1577 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1578 tcg_gen_shli_tl(t0
, t0
, sh
);
1579 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1582 } else if (likely(sh
!= 0 && me
== 31 && sh
== (32 - mb
))) {
1583 TCGv t0
= tcg_temp_new();
1584 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1585 tcg_gen_shri_tl(t0
, t0
, mb
);
1586 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1589 TCGv t0
= tcg_temp_new();
1590 #if defined(TARGET_PPC64)
1591 TCGv_i32 t1
= tcg_temp_new_i32();
1592 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1593 tcg_gen_rotli_i32(t1
, t1
, sh
);
1594 tcg_gen_extu_i32_i64(t0
, t1
);
1595 tcg_temp_free_i32(t1
);
1597 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1599 #if defined(TARGET_PPC64)
1603 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1606 if (unlikely(Rc(ctx
->opcode
) != 0))
1607 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1610 /* rlwnm & rlwnm. */
1611 static void gen_rlwnm(DisasContext
*ctx
)
1615 #if defined(TARGET_PPC64)
1619 mb
= MB(ctx
->opcode
);
1620 me
= ME(ctx
->opcode
);
1621 t0
= tcg_temp_new();
1622 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1623 #if defined(TARGET_PPC64)
1624 t1
= tcg_temp_new_i32();
1625 t2
= tcg_temp_new_i32();
1626 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1627 tcg_gen_trunc_i64_i32(t2
, t0
);
1628 tcg_gen_rotl_i32(t1
, t1
, t2
);
1629 tcg_gen_extu_i32_i64(t0
, t1
);
1630 tcg_temp_free_i32(t1
);
1631 tcg_temp_free_i32(t2
);
1633 tcg_gen_rotl_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1635 if (unlikely(mb
!= 0 || me
!= 31)) {
1636 #if defined(TARGET_PPC64)
1640 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1642 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1645 if (unlikely(Rc(ctx
->opcode
) != 0))
1646 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1649 #if defined(TARGET_PPC64)
1650 #define GEN_PPC64_R2(name, opc1, opc2) \
1651 static void glue(gen_, name##0)(DisasContext *ctx) \
1653 gen_##name(ctx, 0); \
1656 static void glue(gen_, name##1)(DisasContext *ctx) \
1658 gen_##name(ctx, 1); \
1660 #define GEN_PPC64_R4(name, opc1, opc2) \
1661 static void glue(gen_, name##0)(DisasContext *ctx) \
1663 gen_##name(ctx, 0, 0); \
1666 static void glue(gen_, name##1)(DisasContext *ctx) \
1668 gen_##name(ctx, 0, 1); \
1671 static void glue(gen_, name##2)(DisasContext *ctx) \
1673 gen_##name(ctx, 1, 0); \
1676 static void glue(gen_, name##3)(DisasContext *ctx) \
1678 gen_##name(ctx, 1, 1); \
1681 static inline void gen_rldinm(DisasContext
*ctx
, uint32_t mb
, uint32_t me
,
1684 if (likely(sh
!= 0 && mb
== 0 && me
== (63 - sh
))) {
1685 tcg_gen_shli_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
1686 } else if (likely(sh
!= 0 && me
== 63 && sh
== (64 - mb
))) {
1687 tcg_gen_shri_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], mb
);
1689 TCGv t0
= tcg_temp_new();
1690 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1691 if (likely(mb
== 0 && me
== 63)) {
1692 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1694 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1698 if (unlikely(Rc(ctx
->opcode
) != 0))
1699 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1701 /* rldicl - rldicl. */
1702 static inline void gen_rldicl(DisasContext
*ctx
, int mbn
, int shn
)
1706 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1707 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1708 gen_rldinm(ctx
, mb
, 63, sh
);
1710 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
1711 /* rldicr - rldicr. */
1712 static inline void gen_rldicr(DisasContext
*ctx
, int men
, int shn
)
1716 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1717 me
= MB(ctx
->opcode
) | (men
<< 5);
1718 gen_rldinm(ctx
, 0, me
, sh
);
1720 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
1721 /* rldic - rldic. */
1722 static inline void gen_rldic(DisasContext
*ctx
, int mbn
, int shn
)
1726 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1727 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1728 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
1730 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
1732 static inline void gen_rldnm(DisasContext
*ctx
, uint32_t mb
, uint32_t me
)
1736 mb
= MB(ctx
->opcode
);
1737 me
= ME(ctx
->opcode
);
1738 t0
= tcg_temp_new();
1739 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1740 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1741 if (unlikely(mb
!= 0 || me
!= 63)) {
1742 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1744 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1747 if (unlikely(Rc(ctx
->opcode
) != 0))
1748 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1751 /* rldcl - rldcl. */
1752 static inline void gen_rldcl(DisasContext
*ctx
, int mbn
)
1756 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1757 gen_rldnm(ctx
, mb
, 63);
1759 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
1760 /* rldcr - rldcr. */
1761 static inline void gen_rldcr(DisasContext
*ctx
, int men
)
1765 me
= MB(ctx
->opcode
) | (men
<< 5);
1766 gen_rldnm(ctx
, 0, me
);
1768 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
1769 /* rldimi - rldimi. */
1770 static inline void gen_rldimi(DisasContext
*ctx
, int mbn
, int shn
)
1772 uint32_t sh
, mb
, me
;
1774 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1775 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1777 if (unlikely(sh
== 0 && mb
== 0)) {
1778 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1783 t0
= tcg_temp_new();
1784 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1785 t1
= tcg_temp_new();
1786 mask
= MASK(mb
, me
);
1787 tcg_gen_andi_tl(t0
, t0
, mask
);
1788 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1789 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1793 if (unlikely(Rc(ctx
->opcode
) != 0))
1794 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1796 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
1799 /*** Integer shift ***/
1802 static void gen_slw(DisasContext
*ctx
)
1806 t0
= tcg_temp_new();
1807 /* AND rS with a mask that is 0 when rB >= 0x20 */
1808 #if defined(TARGET_PPC64)
1809 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
1810 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1812 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
1813 tcg_gen_sari_tl(t0
, t0
, 0x1f);
1815 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1816 t1
= tcg_temp_new();
1817 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1818 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1821 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
1822 if (unlikely(Rc(ctx
->opcode
) != 0))
1823 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1827 static void gen_sraw(DisasContext
*ctx
)
1829 gen_helper_sraw(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
1830 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1831 if (unlikely(Rc(ctx
->opcode
) != 0))
1832 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1835 /* srawi & srawi. */
1836 static void gen_srawi(DisasContext
*ctx
)
1838 int sh
= SH(ctx
->opcode
);
1839 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
1840 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
1842 tcg_gen_mov_tl(dst
, src
);
1843 tcg_gen_movi_tl(cpu_ca
, 0);
1846 tcg_gen_ext32s_tl(dst
, src
);
1847 tcg_gen_andi_tl(cpu_ca
, dst
, (1ULL << sh
) - 1);
1848 t0
= tcg_temp_new();
1849 tcg_gen_sari_tl(t0
, dst
, TARGET_LONG_BITS
- 1);
1850 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
1852 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
1853 tcg_gen_sari_tl(dst
, dst
, sh
);
1855 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1856 gen_set_Rc0(ctx
, dst
);
1861 static void gen_srw(DisasContext
*ctx
)
1865 t0
= tcg_temp_new();
1866 /* AND rS with a mask that is 0 when rB >= 0x20 */
1867 #if defined(TARGET_PPC64)
1868 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
1869 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1871 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
1872 tcg_gen_sari_tl(t0
, t0
, 0x1f);
1874 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1875 tcg_gen_ext32u_tl(t0
, t0
);
1876 t1
= tcg_temp_new();
1877 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1878 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1881 if (unlikely(Rc(ctx
->opcode
) != 0))
1882 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1885 #if defined(TARGET_PPC64)
1887 static void gen_sld(DisasContext
*ctx
)
1891 t0
= tcg_temp_new();
1892 /* AND rS with a mask that is 0 when rB >= 0x40 */
1893 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
1894 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1895 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1896 t1
= tcg_temp_new();
1897 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1898 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1901 if (unlikely(Rc(ctx
->opcode
) != 0))
1902 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1906 static void gen_srad(DisasContext
*ctx
)
1908 gen_helper_srad(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
1909 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1910 if (unlikely(Rc(ctx
->opcode
) != 0))
1911 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1913 /* sradi & sradi. */
1914 static inline void gen_sradi(DisasContext
*ctx
, int n
)
1916 int sh
= SH(ctx
->opcode
) + (n
<< 5);
1917 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
1918 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
1920 tcg_gen_mov_tl(dst
, src
);
1921 tcg_gen_movi_tl(cpu_ca
, 0);
1924 tcg_gen_andi_tl(cpu_ca
, src
, (1ULL << sh
) - 1);
1925 t0
= tcg_temp_new();
1926 tcg_gen_sari_tl(t0
, src
, TARGET_LONG_BITS
- 1);
1927 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
1929 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
1930 tcg_gen_sari_tl(dst
, src
, sh
);
1932 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1933 gen_set_Rc0(ctx
, dst
);
1937 static void gen_sradi0(DisasContext
*ctx
)
1942 static void gen_sradi1(DisasContext
*ctx
)
1948 static void gen_srd(DisasContext
*ctx
)
1952 t0
= tcg_temp_new();
1953 /* AND rS with a mask that is 0 when rB >= 0x40 */
1954 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
1955 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1956 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1957 t1
= tcg_temp_new();
1958 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1959 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1962 if (unlikely(Rc(ctx
->opcode
) != 0))
1963 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1967 /*** Floating-Point arithmetic ***/
1968 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
1969 static void gen_f##name(DisasContext *ctx) \
1971 if (unlikely(!ctx->fpu_enabled)) { \
1972 gen_exception(ctx, POWERPC_EXCP_FPU); \
1975 /* NIP cannot be restored if the memory exception comes from an helper */ \
1976 gen_update_nip(ctx, ctx->nip - 4); \
1977 gen_reset_fpstatus(); \
1978 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1979 cpu_fpr[rA(ctx->opcode)], \
1980 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
1982 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1983 cpu_fpr[rD(ctx->opcode)]); \
1985 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \
1986 Rc(ctx->opcode) != 0); \
1989 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
1990 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
1991 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
1993 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
1994 static void gen_f##name(DisasContext *ctx) \
1996 if (unlikely(!ctx->fpu_enabled)) { \
1997 gen_exception(ctx, POWERPC_EXCP_FPU); \
2000 /* NIP cannot be restored if the memory exception comes from an helper */ \
2001 gen_update_nip(ctx, ctx->nip - 4); \
2002 gen_reset_fpstatus(); \
2003 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2004 cpu_fpr[rA(ctx->opcode)], \
2005 cpu_fpr[rB(ctx->opcode)]); \
2007 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2008 cpu_fpr[rD(ctx->opcode)]); \
2010 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2011 set_fprf, Rc(ctx->opcode) != 0); \
2013 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2014 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2015 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2017 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2018 static void gen_f##name(DisasContext *ctx) \
2020 if (unlikely(!ctx->fpu_enabled)) { \
2021 gen_exception(ctx, POWERPC_EXCP_FPU); \
2024 /* NIP cannot be restored if the memory exception comes from an helper */ \
2025 gen_update_nip(ctx, ctx->nip - 4); \
2026 gen_reset_fpstatus(); \
2027 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2028 cpu_fpr[rA(ctx->opcode)], \
2029 cpu_fpr[rC(ctx->opcode)]); \
2031 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2032 cpu_fpr[rD(ctx->opcode)]); \
2034 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2035 set_fprf, Rc(ctx->opcode) != 0); \
2037 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2038 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2039 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2041 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
2042 static void gen_f##name(DisasContext *ctx) \
2044 if (unlikely(!ctx->fpu_enabled)) { \
2045 gen_exception(ctx, POWERPC_EXCP_FPU); \
2048 /* NIP cannot be restored if the memory exception comes from an helper */ \
2049 gen_update_nip(ctx, ctx->nip - 4); \
2050 gen_reset_fpstatus(); \
2051 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2052 cpu_fpr[rB(ctx->opcode)]); \
2053 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2054 set_fprf, Rc(ctx->opcode) != 0); \
2057 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
2058 static void gen_f##name(DisasContext *ctx) \
2060 if (unlikely(!ctx->fpu_enabled)) { \
2061 gen_exception(ctx, POWERPC_EXCP_FPU); \
2064 /* NIP cannot be restored if the memory exception comes from an helper */ \
2065 gen_update_nip(ctx, ctx->nip - 4); \
2066 gen_reset_fpstatus(); \
2067 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2068 cpu_fpr[rB(ctx->opcode)]); \
2069 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2070 set_fprf, Rc(ctx->opcode) != 0); \
2074 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
);
2076 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
);
2078 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
);
2081 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
);
2084 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
);
2087 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
);
2090 static void gen_frsqrtes(DisasContext
*ctx
)
2092 if (unlikely(!ctx
->fpu_enabled
)) {
2093 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2096 /* NIP cannot be restored if the memory exception comes from an helper */
2097 gen_update_nip(ctx
, ctx
->nip
- 4);
2098 gen_reset_fpstatus();
2099 gen_helper_frsqrte(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2100 cpu_fpr
[rB(ctx
->opcode
)]);
2101 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2102 cpu_fpr
[rD(ctx
->opcode
)]);
2103 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2107 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
);
2109 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
);
2113 static void gen_fsqrt(DisasContext
*ctx
)
2115 if (unlikely(!ctx
->fpu_enabled
)) {
2116 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2119 /* NIP cannot be restored if the memory exception comes from an helper */
2120 gen_update_nip(ctx
, ctx
->nip
- 4);
2121 gen_reset_fpstatus();
2122 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2123 cpu_fpr
[rB(ctx
->opcode
)]);
2124 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2127 static void gen_fsqrts(DisasContext
*ctx
)
2129 if (unlikely(!ctx
->fpu_enabled
)) {
2130 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2133 /* NIP cannot be restored if the memory exception comes from an helper */
2134 gen_update_nip(ctx
, ctx
->nip
- 4);
2135 gen_reset_fpstatus();
2136 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2137 cpu_fpr
[rB(ctx
->opcode
)]);
2138 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2139 cpu_fpr
[rD(ctx
->opcode
)]);
2140 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2143 /*** Floating-Point multiply-and-add ***/
2144 /* fmadd - fmadds */
2145 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
);
2146 /* fmsub - fmsubs */
2147 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
);
2148 /* fnmadd - fnmadds */
2149 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
);
2150 /* fnmsub - fnmsubs */
2151 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
);
2153 /*** Floating-Point round & convert ***/
2155 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
);
2157 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
);
2159 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
);
2160 #if defined(TARGET_PPC64)
2162 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
);
2164 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
);
2166 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
);
2170 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
);
2172 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
);
2174 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
);
2176 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
);
2178 /*** Floating-Point compare ***/
2181 static void gen_fcmpo(DisasContext
*ctx
)
2184 if (unlikely(!ctx
->fpu_enabled
)) {
2185 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2188 /* NIP cannot be restored if the memory exception comes from an helper */
2189 gen_update_nip(ctx
, ctx
->nip
- 4);
2190 gen_reset_fpstatus();
2191 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2192 gen_helper_fcmpo(cpu_env
, cpu_fpr
[rA(ctx
->opcode
)],
2193 cpu_fpr
[rB(ctx
->opcode
)], crf
);
2194 tcg_temp_free_i32(crf
);
2195 gen_helper_float_check_status(cpu_env
);
2199 static void gen_fcmpu(DisasContext
*ctx
)
2202 if (unlikely(!ctx
->fpu_enabled
)) {
2203 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2206 /* NIP cannot be restored if the memory exception comes from an helper */
2207 gen_update_nip(ctx
, ctx
->nip
- 4);
2208 gen_reset_fpstatus();
2209 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2210 gen_helper_fcmpu(cpu_env
, cpu_fpr
[rA(ctx
->opcode
)],
2211 cpu_fpr
[rB(ctx
->opcode
)], crf
);
2212 tcg_temp_free_i32(crf
);
2213 gen_helper_float_check_status(cpu_env
);
2216 /*** Floating-point move ***/
2218 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2219 static void gen_fabs(DisasContext
*ctx
)
2221 if (unlikely(!ctx
->fpu_enabled
)) {
2222 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2225 tcg_gen_andi_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)],
2227 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2231 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2232 static void gen_fmr(DisasContext
*ctx
)
2234 if (unlikely(!ctx
->fpu_enabled
)) {
2235 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2238 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2239 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2243 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2244 static void gen_fnabs(DisasContext
*ctx
)
2246 if (unlikely(!ctx
->fpu_enabled
)) {
2247 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2250 tcg_gen_ori_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)],
2252 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2256 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2257 static void gen_fneg(DisasContext
*ctx
)
2259 if (unlikely(!ctx
->fpu_enabled
)) {
2260 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2263 tcg_gen_xori_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)],
2265 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2268 /* fcpsgn: PowerPC 2.05 specification */
2269 /* XXX: beware that fcpsgn never checks for NaNs nor update FPSCR */
2270 static void gen_fcpsgn(DisasContext
*ctx
)
2272 if (unlikely(!ctx
->fpu_enabled
)) {
2273 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2276 tcg_gen_deposit_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rA(ctx
->opcode
)],
2277 cpu_fpr
[rB(ctx
->opcode
)], 0, 63);
2278 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2281 /*** Floating-Point status & ctrl register ***/
2284 static void gen_mcrfs(DisasContext
*ctx
)
2286 TCGv tmp
= tcg_temp_new();
2289 if (unlikely(!ctx
->fpu_enabled
)) {
2290 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2293 bfa
= 4 * (7 - crfS(ctx
->opcode
));
2294 tcg_gen_shri_tl(tmp
, cpu_fpscr
, bfa
);
2295 tcg_gen_trunc_tl_i32(cpu_crf
[crfD(ctx
->opcode
)], tmp
);
2297 tcg_gen_andi_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfD(ctx
->opcode
)], 0xf);
2298 tcg_gen_andi_tl(cpu_fpscr
, cpu_fpscr
, ~(0xF << bfa
));
2302 static void gen_mffs(DisasContext
*ctx
)
2304 if (unlikely(!ctx
->fpu_enabled
)) {
2305 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2308 gen_reset_fpstatus();
2309 tcg_gen_extu_tl_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpscr
);
2310 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2314 static void gen_mtfsb0(DisasContext
*ctx
)
2318 if (unlikely(!ctx
->fpu_enabled
)) {
2319 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2322 crb
= 31 - crbD(ctx
->opcode
);
2323 gen_reset_fpstatus();
2324 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
)) {
2326 /* NIP cannot be restored if the memory exception comes from an helper */
2327 gen_update_nip(ctx
, ctx
->nip
- 4);
2328 t0
= tcg_const_i32(crb
);
2329 gen_helper_fpscr_clrbit(cpu_env
, t0
);
2330 tcg_temp_free_i32(t0
);
2332 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2333 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2334 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2339 static void gen_mtfsb1(DisasContext
*ctx
)
2343 if (unlikely(!ctx
->fpu_enabled
)) {
2344 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2347 crb
= 31 - crbD(ctx
->opcode
);
2348 gen_reset_fpstatus();
2349 /* XXX: we pretend we can only do IEEE floating-point computations */
2350 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
&& crb
!= FPSCR_NI
)) {
2352 /* NIP cannot be restored if the memory exception comes from an helper */
2353 gen_update_nip(ctx
, ctx
->nip
- 4);
2354 t0
= tcg_const_i32(crb
);
2355 gen_helper_fpscr_setbit(cpu_env
, t0
);
2356 tcg_temp_free_i32(t0
);
2358 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2359 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2360 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2362 /* We can raise a differed exception */
2363 gen_helper_float_check_status(cpu_env
);
2367 static void gen_mtfsf(DisasContext
*ctx
)
2372 if (unlikely(!ctx
->fpu_enabled
)) {
2373 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2376 flm
= FPFLM(ctx
->opcode
);
2377 l
= FPL(ctx
->opcode
);
2378 w
= FPW(ctx
->opcode
);
2379 if (unlikely(w
& !(ctx
->insns_flags2
& PPC2_ISA205
))) {
2380 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2383 /* NIP cannot be restored if the memory exception comes from an helper */
2384 gen_update_nip(ctx
, ctx
->nip
- 4);
2385 gen_reset_fpstatus();
2387 t0
= tcg_const_i32((ctx
->insns_flags2
& PPC2_ISA205
) ? 0xffff : 0xff);
2389 t0
= tcg_const_i32(flm
<< (w
* 8));
2391 gen_helper_store_fpscr(cpu_env
, cpu_fpr
[rB(ctx
->opcode
)], t0
);
2392 tcg_temp_free_i32(t0
);
2393 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2394 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2395 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2397 /* We can raise a differed exception */
2398 gen_helper_float_check_status(cpu_env
);
2402 static void gen_mtfsfi(DisasContext
*ctx
)
2408 if (unlikely(!ctx
->fpu_enabled
)) {
2409 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2412 w
= FPW(ctx
->opcode
);
2413 bf
= FPBF(ctx
->opcode
);
2414 if (unlikely(w
& !(ctx
->insns_flags2
& PPC2_ISA205
))) {
2415 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2418 sh
= (8 * w
) + 7 - bf
;
2419 /* NIP cannot be restored if the memory exception comes from an helper */
2420 gen_update_nip(ctx
, ctx
->nip
- 4);
2421 gen_reset_fpstatus();
2422 t0
= tcg_const_i64(((uint64_t)FPIMM(ctx
->opcode
)) << (4 * sh
));
2423 t1
= tcg_const_i32(1 << sh
);
2424 gen_helper_store_fpscr(cpu_env
, t0
, t1
);
2425 tcg_temp_free_i64(t0
);
2426 tcg_temp_free_i32(t1
);
2427 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2428 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2429 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2431 /* We can raise a differed exception */
2432 gen_helper_float_check_status(cpu_env
);
2435 /*** Addressing modes ***/
2436 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2437 static inline void gen_addr_imm_index(DisasContext
*ctx
, TCGv EA
,
2440 target_long simm
= SIMM(ctx
->opcode
);
2443 if (rA(ctx
->opcode
) == 0) {
2444 if (NARROW_MODE(ctx
)) {
2445 simm
= (uint32_t)simm
;
2447 tcg_gen_movi_tl(EA
, simm
);
2448 } else if (likely(simm
!= 0)) {
2449 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
);
2450 if (NARROW_MODE(ctx
)) {
2451 tcg_gen_ext32u_tl(EA
, EA
);
2454 if (NARROW_MODE(ctx
)) {
2455 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2457 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2462 static inline void gen_addr_reg_index(DisasContext
*ctx
, TCGv EA
)
2464 if (rA(ctx
->opcode
) == 0) {
2465 if (NARROW_MODE(ctx
)) {
2466 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2468 tcg_gen_mov_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2471 tcg_gen_add_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2472 if (NARROW_MODE(ctx
)) {
2473 tcg_gen_ext32u_tl(EA
, EA
);
2478 static inline void gen_addr_register(DisasContext
*ctx
, TCGv EA
)
2480 if (rA(ctx
->opcode
) == 0) {
2481 tcg_gen_movi_tl(EA
, 0);
2482 } else if (NARROW_MODE(ctx
)) {
2483 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2485 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2489 static inline void gen_addr_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
2492 tcg_gen_addi_tl(ret
, arg1
, val
);
2493 if (NARROW_MODE(ctx
)) {
2494 tcg_gen_ext32u_tl(ret
, ret
);
2498 static inline void gen_check_align(DisasContext
*ctx
, TCGv EA
, int mask
)
2500 int l1
= gen_new_label();
2501 TCGv t0
= tcg_temp_new();
2503 /* NIP cannot be restored if the memory exception comes from an helper */
2504 gen_update_nip(ctx
, ctx
->nip
- 4);
2505 tcg_gen_andi_tl(t0
, EA
, mask
);
2506 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2507 t1
= tcg_const_i32(POWERPC_EXCP_ALIGN
);
2508 t2
= tcg_const_i32(0);
2509 gen_helper_raise_exception_err(cpu_env
, t1
, t2
);
2510 tcg_temp_free_i32(t1
);
2511 tcg_temp_free_i32(t2
);
2516 /*** Integer load ***/
2517 static inline void gen_qemu_ld8u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2519 tcg_gen_qemu_ld8u(arg1
, arg2
, ctx
->mem_idx
);
2522 static inline void gen_qemu_ld8s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2524 tcg_gen_qemu_ld8s(arg1
, arg2
, ctx
->mem_idx
);
2527 static inline void gen_qemu_ld16u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2529 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2530 if (unlikely(ctx
->le_mode
)) {
2531 tcg_gen_bswap16_tl(arg1
, arg1
);
2535 static inline void gen_qemu_ld16s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2537 if (unlikely(ctx
->le_mode
)) {
2538 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2539 tcg_gen_bswap16_tl(arg1
, arg1
);
2540 tcg_gen_ext16s_tl(arg1
, arg1
);
2542 tcg_gen_qemu_ld16s(arg1
, arg2
, ctx
->mem_idx
);
2546 static inline void gen_qemu_ld32u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2548 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2549 if (unlikely(ctx
->le_mode
)) {
2550 tcg_gen_bswap32_tl(arg1
, arg1
);
2554 static inline void gen_qemu_ld32s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2556 if (unlikely(ctx
->le_mode
)) {
2557 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2558 tcg_gen_bswap32_tl(arg1
, arg1
);
2559 tcg_gen_ext32s_tl(arg1
, arg1
);
2561 tcg_gen_qemu_ld32s(arg1
, arg2
, ctx
->mem_idx
);
2564 static inline void gen_qemu_ld64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2566 tcg_gen_qemu_ld64(arg1
, arg2
, ctx
->mem_idx
);
2567 if (unlikely(ctx
->le_mode
)) {
2568 tcg_gen_bswap64_i64(arg1
, arg1
);
2572 static inline void gen_qemu_st8(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2574 tcg_gen_qemu_st8(arg1
, arg2
, ctx
->mem_idx
);
2577 static inline void gen_qemu_st16(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2579 if (unlikely(ctx
->le_mode
)) {
2580 TCGv t0
= tcg_temp_new();
2581 tcg_gen_ext16u_tl(t0
, arg1
);
2582 tcg_gen_bswap16_tl(t0
, t0
);
2583 tcg_gen_qemu_st16(t0
, arg2
, ctx
->mem_idx
);
2586 tcg_gen_qemu_st16(arg1
, arg2
, ctx
->mem_idx
);
2590 static inline void gen_qemu_st32(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2592 if (unlikely(ctx
->le_mode
)) {
2593 TCGv t0
= tcg_temp_new();
2594 tcg_gen_ext32u_tl(t0
, arg1
);
2595 tcg_gen_bswap32_tl(t0
, t0
);
2596 tcg_gen_qemu_st32(t0
, arg2
, ctx
->mem_idx
);
2599 tcg_gen_qemu_st32(arg1
, arg2
, ctx
->mem_idx
);
2603 static inline void gen_qemu_st64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2605 if (unlikely(ctx
->le_mode
)) {
2606 TCGv_i64 t0
= tcg_temp_new_i64();
2607 tcg_gen_bswap64_i64(t0
, arg1
);
2608 tcg_gen_qemu_st64(t0
, arg2
, ctx
->mem_idx
);
2609 tcg_temp_free_i64(t0
);
2611 tcg_gen_qemu_st64(arg1
, arg2
, ctx
->mem_idx
);
2614 #define GEN_LD(name, ldop, opc, type) \
2615 static void glue(gen_, name)(DisasContext *ctx) \
2618 gen_set_access_type(ctx, ACCESS_INT); \
2619 EA = tcg_temp_new(); \
2620 gen_addr_imm_index(ctx, EA, 0); \
2621 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2622 tcg_temp_free(EA); \
2625 #define GEN_LDU(name, ldop, opc, type) \
2626 static void glue(gen_, name##u)(DisasContext *ctx) \
2629 if (unlikely(rA(ctx->opcode) == 0 || \
2630 rA(ctx->opcode) == rD(ctx->opcode))) { \
2631 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2634 gen_set_access_type(ctx, ACCESS_INT); \
2635 EA = tcg_temp_new(); \
2636 if (type == PPC_64B) \
2637 gen_addr_imm_index(ctx, EA, 0x03); \
2639 gen_addr_imm_index(ctx, EA, 0); \
2640 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2641 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2642 tcg_temp_free(EA); \
2645 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
2646 static void glue(gen_, name##ux)(DisasContext *ctx) \
2649 if (unlikely(rA(ctx->opcode) == 0 || \
2650 rA(ctx->opcode) == rD(ctx->opcode))) { \
2651 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2654 gen_set_access_type(ctx, ACCESS_INT); \
2655 EA = tcg_temp_new(); \
2656 gen_addr_reg_index(ctx, EA); \
2657 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2658 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2659 tcg_temp_free(EA); \
2662 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
2663 static void glue(gen_, name##x)(DisasContext *ctx) \
2666 gen_set_access_type(ctx, ACCESS_INT); \
2667 EA = tcg_temp_new(); \
2668 gen_addr_reg_index(ctx, EA); \
2669 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2670 tcg_temp_free(EA); \
2672 #define GEN_LDX(name, ldop, opc2, opc3, type) \
2673 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE)
2675 #define GEN_LDS(name, ldop, op, type) \
2676 GEN_LD(name, ldop, op | 0x20, type); \
2677 GEN_LDU(name, ldop, op | 0x21, type); \
2678 GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2679 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
2681 /* lbz lbzu lbzux lbzx */
2682 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
);
2683 /* lha lhau lhaux lhax */
2684 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
);
2685 /* lhz lhzu lhzux lhzx */
2686 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
);
2687 /* lwz lwzu lwzux lwzx */
2688 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
);
2689 #if defined(TARGET_PPC64)
2691 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
);
2693 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
);
2695 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
);
2697 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
);
2699 static void gen_ld(DisasContext
*ctx
)
2702 if (Rc(ctx
->opcode
)) {
2703 if (unlikely(rA(ctx
->opcode
) == 0 ||
2704 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
2705 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2709 gen_set_access_type(ctx
, ACCESS_INT
);
2710 EA
= tcg_temp_new();
2711 gen_addr_imm_index(ctx
, EA
, 0x03);
2712 if (ctx
->opcode
& 0x02) {
2713 /* lwa (lwau is undefined) */
2714 gen_qemu_ld32s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2717 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2719 if (Rc(ctx
->opcode
))
2720 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2725 static void gen_lq(DisasContext
*ctx
)
2727 #if defined(CONFIG_USER_ONLY)
2728 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2733 /* Restore CPU state */
2734 if (unlikely(ctx
->mem_idx
== 0)) {
2735 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2738 ra
= rA(ctx
->opcode
);
2739 rd
= rD(ctx
->opcode
);
2740 if (unlikely((rd
& 1) || rd
== ra
)) {
2741 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2744 if (unlikely(ctx
->le_mode
)) {
2745 /* Little-endian mode is not handled */
2746 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2749 gen_set_access_type(ctx
, ACCESS_INT
);
2750 EA
= tcg_temp_new();
2751 gen_addr_imm_index(ctx
, EA
, 0x0F);
2752 gen_qemu_ld64(ctx
, cpu_gpr
[rd
], EA
);
2753 gen_addr_add(ctx
, EA
, EA
, 8);
2754 gen_qemu_ld64(ctx
, cpu_gpr
[rd
+1], EA
);
2760 /*** Integer store ***/
2761 #define GEN_ST(name, stop, opc, type) \
2762 static void glue(gen_, name)(DisasContext *ctx) \
2765 gen_set_access_type(ctx, ACCESS_INT); \
2766 EA = tcg_temp_new(); \
2767 gen_addr_imm_index(ctx, EA, 0); \
2768 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2769 tcg_temp_free(EA); \
2772 #define GEN_STU(name, stop, opc, type) \
2773 static void glue(gen_, stop##u)(DisasContext *ctx) \
2776 if (unlikely(rA(ctx->opcode) == 0)) { \
2777 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2780 gen_set_access_type(ctx, ACCESS_INT); \
2781 EA = tcg_temp_new(); \
2782 if (type == PPC_64B) \
2783 gen_addr_imm_index(ctx, EA, 0x03); \
2785 gen_addr_imm_index(ctx, EA, 0); \
2786 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2787 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2788 tcg_temp_free(EA); \
2791 #define GEN_STUX(name, stop, opc2, opc3, type) \
2792 static void glue(gen_, name##ux)(DisasContext *ctx) \
2795 if (unlikely(rA(ctx->opcode) == 0)) { \
2796 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2799 gen_set_access_type(ctx, ACCESS_INT); \
2800 EA = tcg_temp_new(); \
2801 gen_addr_reg_index(ctx, EA); \
2802 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2803 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2804 tcg_temp_free(EA); \
2807 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
2808 static void glue(gen_, name##x)(DisasContext *ctx) \
2811 gen_set_access_type(ctx, ACCESS_INT); \
2812 EA = tcg_temp_new(); \
2813 gen_addr_reg_index(ctx, EA); \
2814 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2815 tcg_temp_free(EA); \
2817 #define GEN_STX(name, stop, opc2, opc3, type) \
2818 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE)
2820 #define GEN_STS(name, stop, op, type) \
2821 GEN_ST(name, stop, op | 0x20, type); \
2822 GEN_STU(name, stop, op | 0x21, type); \
2823 GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2824 GEN_STX(name, stop, 0x17, op | 0x00, type)
2826 /* stb stbu stbux stbx */
2827 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
);
2828 /* sth sthu sthux sthx */
2829 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
);
2830 /* stw stwu stwux stwx */
2831 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
);
2832 #if defined(TARGET_PPC64)
2833 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
);
2834 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
);
2836 static void gen_std(DisasContext
*ctx
)
2841 rs
= rS(ctx
->opcode
);
2842 if ((ctx
->opcode
& 0x3) == 0x2) {
2843 #if defined(CONFIG_USER_ONLY)
2844 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2847 if (unlikely(ctx
->mem_idx
== 0)) {
2848 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2851 if (unlikely(rs
& 1)) {
2852 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2855 if (unlikely(ctx
->le_mode
)) {
2856 /* Little-endian mode is not handled */
2857 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2860 gen_set_access_type(ctx
, ACCESS_INT
);
2861 EA
= tcg_temp_new();
2862 gen_addr_imm_index(ctx
, EA
, 0x03);
2863 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
2864 gen_addr_add(ctx
, EA
, EA
, 8);
2865 gen_qemu_st64(ctx
, cpu_gpr
[rs
+1], EA
);
2870 if (Rc(ctx
->opcode
)) {
2871 if (unlikely(rA(ctx
->opcode
) == 0)) {
2872 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2876 gen_set_access_type(ctx
, ACCESS_INT
);
2877 EA
= tcg_temp_new();
2878 gen_addr_imm_index(ctx
, EA
, 0x03);
2879 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
2880 if (Rc(ctx
->opcode
))
2881 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2886 /*** Integer load and store with byte reverse ***/
2888 static inline void gen_qemu_ld16ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2890 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2891 if (likely(!ctx
->le_mode
)) {
2892 tcg_gen_bswap16_tl(arg1
, arg1
);
2895 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
);
2898 static inline void gen_qemu_ld32ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2900 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2901 if (likely(!ctx
->le_mode
)) {
2902 tcg_gen_bswap32_tl(arg1
, arg1
);
2905 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
);
2907 #if defined(TARGET_PPC64)
2909 static inline void gen_qemu_ld64ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2911 tcg_gen_qemu_ld64(arg1
, arg2
, ctx
->mem_idx
);
2912 if (likely(!ctx
->le_mode
)) {
2913 tcg_gen_bswap64_tl(arg1
, arg1
);
2916 GEN_LDX_E(ldbr
, ld64ur
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
);
2917 #endif /* TARGET_PPC64 */
2920 static inline void gen_qemu_st16r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2922 if (likely(!ctx
->le_mode
)) {
2923 TCGv t0
= tcg_temp_new();
2924 tcg_gen_ext16u_tl(t0
, arg1
);
2925 tcg_gen_bswap16_tl(t0
, t0
);
2926 tcg_gen_qemu_st16(t0
, arg2
, ctx
->mem_idx
);
2929 tcg_gen_qemu_st16(arg1
, arg2
, ctx
->mem_idx
);
2932 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
);
2935 static inline void gen_qemu_st32r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2937 if (likely(!ctx
->le_mode
)) {
2938 TCGv t0
= tcg_temp_new();
2939 tcg_gen_ext32u_tl(t0
, arg1
);
2940 tcg_gen_bswap32_tl(t0
, t0
);
2941 tcg_gen_qemu_st32(t0
, arg2
, ctx
->mem_idx
);
2944 tcg_gen_qemu_st32(arg1
, arg2
, ctx
->mem_idx
);
2947 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
);
2949 #if defined(TARGET_PPC64)
2951 static inline void gen_qemu_st64r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2953 if (likely(!ctx
->le_mode
)) {
2954 TCGv t0
= tcg_temp_new();
2955 tcg_gen_bswap64_tl(t0
, arg1
);
2956 tcg_gen_qemu_st64(t0
, arg2
, ctx
->mem_idx
);
2959 tcg_gen_qemu_st64(arg1
, arg2
, ctx
->mem_idx
);
2962 GEN_STX_E(stdbr
, st64r
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
);
2963 #endif /* TARGET_PPC64 */
2965 /*** Integer load and store multiple ***/
2968 static void gen_lmw(DisasContext
*ctx
)
2972 gen_set_access_type(ctx
, ACCESS_INT
);
2973 /* NIP cannot be restored if the memory exception comes from an helper */
2974 gen_update_nip(ctx
, ctx
->nip
- 4);
2975 t0
= tcg_temp_new();
2976 t1
= tcg_const_i32(rD(ctx
->opcode
));
2977 gen_addr_imm_index(ctx
, t0
, 0);
2978 gen_helper_lmw(cpu_env
, t0
, t1
);
2980 tcg_temp_free_i32(t1
);
2984 static void gen_stmw(DisasContext
*ctx
)
2988 gen_set_access_type(ctx
, ACCESS_INT
);
2989 /* NIP cannot be restored if the memory exception comes from an helper */
2990 gen_update_nip(ctx
, ctx
->nip
- 4);
2991 t0
= tcg_temp_new();
2992 t1
= tcg_const_i32(rS(ctx
->opcode
));
2993 gen_addr_imm_index(ctx
, t0
, 0);
2994 gen_helper_stmw(cpu_env
, t0
, t1
);
2996 tcg_temp_free_i32(t1
);
2999 /*** Integer load and store strings ***/
3002 /* PowerPC32 specification says we must generate an exception if
3003 * rA is in the range of registers to be loaded.
3004 * In an other hand, IBM says this is valid, but rA won't be loaded.
3005 * For now, I'll follow the spec...
3007 static void gen_lswi(DisasContext
*ctx
)
3011 int nb
= NB(ctx
->opcode
);
3012 int start
= rD(ctx
->opcode
);
3013 int ra
= rA(ctx
->opcode
);
3019 if (unlikely(((start
+ nr
) > 32 &&
3020 start
<= ra
&& (start
+ nr
- 32) > ra
) ||
3021 ((start
+ nr
) <= 32 && start
<= ra
&& (start
+ nr
) > ra
))) {
3022 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
3025 gen_set_access_type(ctx
, ACCESS_INT
);
3026 /* NIP cannot be restored if the memory exception comes from an helper */
3027 gen_update_nip(ctx
, ctx
->nip
- 4);
3028 t0
= tcg_temp_new();
3029 gen_addr_register(ctx
, t0
);
3030 t1
= tcg_const_i32(nb
);
3031 t2
= tcg_const_i32(start
);
3032 gen_helper_lsw(cpu_env
, t0
, t1
, t2
);
3034 tcg_temp_free_i32(t1
);
3035 tcg_temp_free_i32(t2
);
3039 static void gen_lswx(DisasContext
*ctx
)
3042 TCGv_i32 t1
, t2
, t3
;
3043 gen_set_access_type(ctx
, ACCESS_INT
);
3044 /* NIP cannot be restored if the memory exception comes from an helper */
3045 gen_update_nip(ctx
, ctx
->nip
- 4);
3046 t0
= tcg_temp_new();
3047 gen_addr_reg_index(ctx
, t0
);
3048 t1
= tcg_const_i32(rD(ctx
->opcode
));
3049 t2
= tcg_const_i32(rA(ctx
->opcode
));
3050 t3
= tcg_const_i32(rB(ctx
->opcode
));
3051 gen_helper_lswx(cpu_env
, t0
, t1
, t2
, t3
);
3053 tcg_temp_free_i32(t1
);
3054 tcg_temp_free_i32(t2
);
3055 tcg_temp_free_i32(t3
);
3059 static void gen_stswi(DisasContext
*ctx
)
3063 int nb
= NB(ctx
->opcode
);
3064 gen_set_access_type(ctx
, ACCESS_INT
);
3065 /* NIP cannot be restored if the memory exception comes from an helper */
3066 gen_update_nip(ctx
, ctx
->nip
- 4);
3067 t0
= tcg_temp_new();
3068 gen_addr_register(ctx
, t0
);
3071 t1
= tcg_const_i32(nb
);
3072 t2
= tcg_const_i32(rS(ctx
->opcode
));
3073 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3075 tcg_temp_free_i32(t1
);
3076 tcg_temp_free_i32(t2
);
3080 static void gen_stswx(DisasContext
*ctx
)
3084 gen_set_access_type(ctx
, ACCESS_INT
);
3085 /* NIP cannot be restored if the memory exception comes from an helper */
3086 gen_update_nip(ctx
, ctx
->nip
- 4);
3087 t0
= tcg_temp_new();
3088 gen_addr_reg_index(ctx
, t0
);
3089 t1
= tcg_temp_new_i32();
3090 tcg_gen_trunc_tl_i32(t1
, cpu_xer
);
3091 tcg_gen_andi_i32(t1
, t1
, 0x7F);
3092 t2
= tcg_const_i32(rS(ctx
->opcode
));
3093 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3095 tcg_temp_free_i32(t1
);
3096 tcg_temp_free_i32(t2
);
3099 /*** Memory synchronisation ***/
3101 static void gen_eieio(DisasContext
*ctx
)
3106 static void gen_isync(DisasContext
*ctx
)
3108 gen_stop_exception(ctx
);
3112 static void gen_lwarx(DisasContext
*ctx
)
3115 TCGv gpr
= cpu_gpr
[rD(ctx
->opcode
)];
3116 gen_set_access_type(ctx
, ACCESS_RES
);
3117 t0
= tcg_temp_local_new();
3118 gen_addr_reg_index(ctx
, t0
);
3119 gen_check_align(ctx
, t0
, 0x03);
3120 gen_qemu_ld32u(ctx
, gpr
, t0
);
3121 tcg_gen_mov_tl(cpu_reserve
, t0
);
3122 tcg_gen_st_tl(gpr
, cpu_env
, offsetof(CPUPPCState
, reserve_val
));
3126 #if defined(CONFIG_USER_ONLY)
3127 static void gen_conditional_store (DisasContext
*ctx
, TCGv EA
,
3130 TCGv t0
= tcg_temp_new();
3131 uint32_t save_exception
= ctx
->exception
;
3133 tcg_gen_st_tl(EA
, cpu_env
, offsetof(CPUPPCState
, reserve_ea
));
3134 tcg_gen_movi_tl(t0
, (size
<< 5) | reg
);
3135 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, reserve_info
));
3137 gen_update_nip(ctx
, ctx
->nip
-4);
3138 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3139 gen_exception(ctx
, POWERPC_EXCP_STCX
);
3140 ctx
->exception
= save_exception
;
3145 static void gen_stwcx_(DisasContext
*ctx
)
3148 gen_set_access_type(ctx
, ACCESS_RES
);
3149 t0
= tcg_temp_local_new();
3150 gen_addr_reg_index(ctx
, t0
);
3151 gen_check_align(ctx
, t0
, 0x03);
3152 #if defined(CONFIG_USER_ONLY)
3153 gen_conditional_store(ctx
, t0
, rS(ctx
->opcode
), 4);
3158 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
3159 l1
= gen_new_label();
3160 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
3161 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3162 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3164 tcg_gen_movi_tl(cpu_reserve
, -1);
3170 #if defined(TARGET_PPC64)
3172 static void gen_ldarx(DisasContext
*ctx
)
3175 TCGv gpr
= cpu_gpr
[rD(ctx
->opcode
)];
3176 gen_set_access_type(ctx
, ACCESS_RES
);
3177 t0
= tcg_temp_local_new();
3178 gen_addr_reg_index(ctx
, t0
);
3179 gen_check_align(ctx
, t0
, 0x07);
3180 gen_qemu_ld64(ctx
, gpr
, t0
);
3181 tcg_gen_mov_tl(cpu_reserve
, t0
);
3182 tcg_gen_st_tl(gpr
, cpu_env
, offsetof(CPUPPCState
, reserve_val
));
3187 static void gen_stdcx_(DisasContext
*ctx
)
3190 gen_set_access_type(ctx
, ACCESS_RES
);
3191 t0
= tcg_temp_local_new();
3192 gen_addr_reg_index(ctx
, t0
);
3193 gen_check_align(ctx
, t0
, 0x07);
3194 #if defined(CONFIG_USER_ONLY)
3195 gen_conditional_store(ctx
, t0
, rS(ctx
->opcode
), 8);
3199 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
3200 l1
= gen_new_label();
3201 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
3202 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3203 gen_qemu_st64(ctx
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3205 tcg_gen_movi_tl(cpu_reserve
, -1);
3210 #endif /* defined(TARGET_PPC64) */
3213 static void gen_sync(DisasContext
*ctx
)
3218 static void gen_wait(DisasContext
*ctx
)
3220 TCGv_i32 t0
= tcg_temp_new_i32();
3221 tcg_gen_st_i32(t0
, cpu_env
,
3222 -offsetof(PowerPCCPU
, env
) + offsetof(CPUState
, halted
));
3223 tcg_temp_free_i32(t0
);
3224 /* Stop translation, as the CPU is supposed to sleep from now */
3225 gen_exception_err(ctx
, EXCP_HLT
, 1);
3228 /*** Floating-point load ***/
3229 #define GEN_LDF(name, ldop, opc, type) \
3230 static void glue(gen_, name)(DisasContext *ctx) \
3233 if (unlikely(!ctx->fpu_enabled)) { \
3234 gen_exception(ctx, POWERPC_EXCP_FPU); \
3237 gen_set_access_type(ctx, ACCESS_FLOAT); \
3238 EA = tcg_temp_new(); \
3239 gen_addr_imm_index(ctx, EA, 0); \
3240 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3241 tcg_temp_free(EA); \
3244 #define GEN_LDUF(name, ldop, opc, type) \
3245 static void glue(gen_, name##u)(DisasContext *ctx) \
3248 if (unlikely(!ctx->fpu_enabled)) { \
3249 gen_exception(ctx, POWERPC_EXCP_FPU); \
3252 if (unlikely(rA(ctx->opcode) == 0)) { \
3253 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3256 gen_set_access_type(ctx, ACCESS_FLOAT); \
3257 EA = tcg_temp_new(); \
3258 gen_addr_imm_index(ctx, EA, 0); \
3259 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3260 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3261 tcg_temp_free(EA); \
3264 #define GEN_LDUXF(name, ldop, opc, type) \
3265 static void glue(gen_, name##ux)(DisasContext *ctx) \
3268 if (unlikely(!ctx->fpu_enabled)) { \
3269 gen_exception(ctx, POWERPC_EXCP_FPU); \
3272 if (unlikely(rA(ctx->opcode) == 0)) { \
3273 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3276 gen_set_access_type(ctx, ACCESS_FLOAT); \
3277 EA = tcg_temp_new(); \
3278 gen_addr_reg_index(ctx, EA); \
3279 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3280 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3281 tcg_temp_free(EA); \
3284 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
3285 static void glue(gen_, name##x)(DisasContext *ctx) \
3288 if (unlikely(!ctx->fpu_enabled)) { \
3289 gen_exception(ctx, POWERPC_EXCP_FPU); \
3292 gen_set_access_type(ctx, ACCESS_FLOAT); \
3293 EA = tcg_temp_new(); \
3294 gen_addr_reg_index(ctx, EA); \
3295 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3296 tcg_temp_free(EA); \
3299 #define GEN_LDFS(name, ldop, op, type) \
3300 GEN_LDF(name, ldop, op | 0x20, type); \
3301 GEN_LDUF(name, ldop, op | 0x21, type); \
3302 GEN_LDUXF(name, ldop, op | 0x01, type); \
3303 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3305 static inline void gen_qemu_ld32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3307 TCGv t0
= tcg_temp_new();
3308 TCGv_i32 t1
= tcg_temp_new_i32();
3309 gen_qemu_ld32u(ctx
, t0
, arg2
);
3310 tcg_gen_trunc_tl_i32(t1
, t0
);
3312 gen_helper_float32_to_float64(arg1
, cpu_env
, t1
);
3313 tcg_temp_free_i32(t1
);
3316 /* lfd lfdu lfdux lfdx */
3317 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
);
3318 /* lfs lfsu lfsux lfsx */
3319 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
);
3322 static void gen_lfdp(DisasContext
*ctx
)
3325 if (unlikely(!ctx
->fpu_enabled
)) {
3326 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3329 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3330 EA
= tcg_temp_new();
3331 gen_addr_imm_index(ctx
, EA
, 0); \
3332 if (unlikely(ctx
->le_mode
)) {
3333 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3334 tcg_gen_addi_tl(EA
, EA
, 8);
3335 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3337 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3338 tcg_gen_addi_tl(EA
, EA
, 8);
3339 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3345 static void gen_lfdpx(DisasContext
*ctx
)
3348 if (unlikely(!ctx
->fpu_enabled
)) {
3349 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3352 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3353 EA
= tcg_temp_new();
3354 gen_addr_reg_index(ctx
, EA
);
3355 if (unlikely(ctx
->le_mode
)) {
3356 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3357 tcg_gen_addi_tl(EA
, EA
, 8);
3358 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3360 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3361 tcg_gen_addi_tl(EA
, EA
, 8);
3362 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3368 static void gen_lfiwax(DisasContext
*ctx
)
3372 if (unlikely(!ctx
->fpu_enabled
)) {
3373 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3376 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3377 EA
= tcg_temp_new();
3378 t0
= tcg_temp_new();
3379 gen_addr_reg_index(ctx
, EA
);
3380 gen_qemu_ld32s(ctx
, t0
, EA
);
3381 tcg_gen_ext_tl_i64(cpu_fpr
[rD(ctx
->opcode
)], t0
);
3386 /*** Floating-point store ***/
3387 #define GEN_STF(name, stop, opc, type) \
3388 static void glue(gen_, name)(DisasContext *ctx) \
3391 if (unlikely(!ctx->fpu_enabled)) { \
3392 gen_exception(ctx, POWERPC_EXCP_FPU); \
3395 gen_set_access_type(ctx, ACCESS_FLOAT); \
3396 EA = tcg_temp_new(); \
3397 gen_addr_imm_index(ctx, EA, 0); \
3398 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3399 tcg_temp_free(EA); \
3402 #define GEN_STUF(name, stop, opc, type) \
3403 static void glue(gen_, name##u)(DisasContext *ctx) \
3406 if (unlikely(!ctx->fpu_enabled)) { \
3407 gen_exception(ctx, POWERPC_EXCP_FPU); \
3410 if (unlikely(rA(ctx->opcode) == 0)) { \
3411 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3414 gen_set_access_type(ctx, ACCESS_FLOAT); \
3415 EA = tcg_temp_new(); \
3416 gen_addr_imm_index(ctx, EA, 0); \
3417 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3418 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3419 tcg_temp_free(EA); \
3422 #define GEN_STUXF(name, stop, opc, type) \
3423 static void glue(gen_, name##ux)(DisasContext *ctx) \
3426 if (unlikely(!ctx->fpu_enabled)) { \
3427 gen_exception(ctx, POWERPC_EXCP_FPU); \
3430 if (unlikely(rA(ctx->opcode) == 0)) { \
3431 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3434 gen_set_access_type(ctx, ACCESS_FLOAT); \
3435 EA = tcg_temp_new(); \
3436 gen_addr_reg_index(ctx, EA); \
3437 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3438 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3439 tcg_temp_free(EA); \
3442 #define GEN_STXF(name, stop, opc2, opc3, type) \
3443 static void glue(gen_, name##x)(DisasContext *ctx) \
3446 if (unlikely(!ctx->fpu_enabled)) { \
3447 gen_exception(ctx, POWERPC_EXCP_FPU); \
3450 gen_set_access_type(ctx, ACCESS_FLOAT); \
3451 EA = tcg_temp_new(); \
3452 gen_addr_reg_index(ctx, EA); \
3453 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3454 tcg_temp_free(EA); \
3457 #define GEN_STFS(name, stop, op, type) \
3458 GEN_STF(name, stop, op | 0x20, type); \
3459 GEN_STUF(name, stop, op | 0x21, type); \
3460 GEN_STUXF(name, stop, op | 0x01, type); \
3461 GEN_STXF(name, stop, 0x17, op | 0x00, type)
3463 static inline void gen_qemu_st32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3465 TCGv_i32 t0
= tcg_temp_new_i32();
3466 TCGv t1
= tcg_temp_new();
3467 gen_helper_float64_to_float32(t0
, cpu_env
, arg1
);
3468 tcg_gen_extu_i32_tl(t1
, t0
);
3469 tcg_temp_free_i32(t0
);
3470 gen_qemu_st32(ctx
, t1
, arg2
);
3474 /* stfd stfdu stfdux stfdx */
3475 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
);
3476 /* stfs stfsu stfsux stfsx */
3477 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
);
3480 static void gen_stfdp(DisasContext
*ctx
)
3483 if (unlikely(!ctx
->fpu_enabled
)) {
3484 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3487 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3488 EA
= tcg_temp_new();
3489 gen_addr_imm_index(ctx
, EA
, 0); \
3490 if (unlikely(ctx
->le_mode
)) {
3491 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3492 tcg_gen_addi_tl(EA
, EA
, 8);
3493 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3495 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3496 tcg_gen_addi_tl(EA
, EA
, 8);
3497 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3503 static void gen_stfdpx(DisasContext
*ctx
)
3506 if (unlikely(!ctx
->fpu_enabled
)) {
3507 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3510 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3511 EA
= tcg_temp_new();
3512 gen_addr_reg_index(ctx
, EA
);
3513 if (unlikely(ctx
->le_mode
)) {
3514 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3515 tcg_gen_addi_tl(EA
, EA
, 8);
3516 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3518 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3519 tcg_gen_addi_tl(EA
, EA
, 8);
3520 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3526 static inline void gen_qemu_st32fiw(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3528 TCGv t0
= tcg_temp_new();
3529 tcg_gen_trunc_i64_tl(t0
, arg1
),
3530 gen_qemu_st32(ctx
, t0
, arg2
);
3534 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
);
3536 static inline void gen_update_cfar(DisasContext
*ctx
, target_ulong nip
)
3538 #if defined(TARGET_PPC64)
3540 tcg_gen_movi_tl(cpu_cfar
, nip
);
3545 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
3547 TranslationBlock
*tb
;
3549 if (NARROW_MODE(ctx
)) {
3550 dest
= (uint32_t) dest
;
3552 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
3553 likely(!ctx
->singlestep_enabled
)) {
3555 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3556 tcg_gen_exit_tb((tcg_target_long
)tb
+ n
);
3558 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3559 if (unlikely(ctx
->singlestep_enabled
)) {
3560 if ((ctx
->singlestep_enabled
&
3561 (CPU_BRANCH_STEP
| CPU_SINGLE_STEP
)) &&
3562 (ctx
->exception
== POWERPC_EXCP_BRANCH
||
3563 ctx
->exception
== POWERPC_EXCP_TRACE
)) {
3564 target_ulong tmp
= ctx
->nip
;
3566 gen_exception(ctx
, POWERPC_EXCP_TRACE
);
3569 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
3570 gen_debug_exception(ctx
);
3577 static inline void gen_setlr(DisasContext
*ctx
, target_ulong nip
)
3579 if (NARROW_MODE(ctx
)) {
3580 nip
= (uint32_t)nip
;
3582 tcg_gen_movi_tl(cpu_lr
, nip
);
3586 static void gen_b(DisasContext
*ctx
)
3588 target_ulong li
, target
;
3590 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3591 /* sign extend LI */
3592 li
= LI(ctx
->opcode
);
3593 li
= (li
^ 0x02000000) - 0x02000000;
3594 if (likely(AA(ctx
->opcode
) == 0)) {
3595 target
= ctx
->nip
+ li
- 4;
3599 if (LK(ctx
->opcode
)) {
3600 gen_setlr(ctx
, ctx
->nip
);
3602 gen_update_cfar(ctx
, ctx
->nip
);
3603 gen_goto_tb(ctx
, 0, target
);
3610 static inline void gen_bcond(DisasContext
*ctx
, int type
)
3612 uint32_t bo
= BO(ctx
->opcode
);
3616 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3617 if (type
== BCOND_LR
|| type
== BCOND_CTR
) {
3618 target
= tcg_temp_local_new();
3619 if (type
== BCOND_CTR
)
3620 tcg_gen_mov_tl(target
, cpu_ctr
);
3622 tcg_gen_mov_tl(target
, cpu_lr
);
3624 TCGV_UNUSED(target
);
3626 if (LK(ctx
->opcode
))
3627 gen_setlr(ctx
, ctx
->nip
);
3628 l1
= gen_new_label();
3629 if ((bo
& 0x4) == 0) {
3630 /* Decrement and test CTR */
3631 TCGv temp
= tcg_temp_new();
3632 if (unlikely(type
== BCOND_CTR
)) {
3633 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3636 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
3637 if (NARROW_MODE(ctx
)) {
3638 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
3640 tcg_gen_mov_tl(temp
, cpu_ctr
);
3643 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
3645 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
3647 tcg_temp_free(temp
);
3649 if ((bo
& 0x10) == 0) {
3651 uint32_t bi
= BI(ctx
->opcode
);
3652 uint32_t mask
= 1 << (3 - (bi
& 0x03));
3653 TCGv_i32 temp
= tcg_temp_new_i32();
3656 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3657 tcg_gen_brcondi_i32(TCG_COND_EQ
, temp
, 0, l1
);
3659 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3660 tcg_gen_brcondi_i32(TCG_COND_NE
, temp
, 0, l1
);
3662 tcg_temp_free_i32(temp
);
3664 gen_update_cfar(ctx
, ctx
->nip
);
3665 if (type
== BCOND_IM
) {
3666 target_ulong li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
3667 if (likely(AA(ctx
->opcode
) == 0)) {
3668 gen_goto_tb(ctx
, 0, ctx
->nip
+ li
- 4);
3670 gen_goto_tb(ctx
, 0, li
);
3673 gen_goto_tb(ctx
, 1, ctx
->nip
);
3675 if (NARROW_MODE(ctx
)) {
3676 tcg_gen_andi_tl(cpu_nip
, target
, (uint32_t)~3);
3678 tcg_gen_andi_tl(cpu_nip
, target
, ~3);
3682 gen_update_nip(ctx
, ctx
->nip
);
3687 static void gen_bc(DisasContext
*ctx
)
3689 gen_bcond(ctx
, BCOND_IM
);
3692 static void gen_bcctr(DisasContext
*ctx
)
3694 gen_bcond(ctx
, BCOND_CTR
);
3697 static void gen_bclr(DisasContext
*ctx
)
3699 gen_bcond(ctx
, BCOND_LR
);
3702 /*** Condition register logical ***/
3703 #define GEN_CRLOGIC(name, tcg_op, opc) \
3704 static void glue(gen_, name)(DisasContext *ctx) \
3709 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3710 t0 = tcg_temp_new_i32(); \
3712 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
3714 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
3716 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
3717 t1 = tcg_temp_new_i32(); \
3718 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3720 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
3722 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
3724 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3725 tcg_op(t0, t0, t1); \
3726 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
3727 tcg_gen_andi_i32(t0, t0, bitmask); \
3728 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3729 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
3730 tcg_temp_free_i32(t0); \
3731 tcg_temp_free_i32(t1); \
3735 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08);
3737 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04);
3739 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09);
3741 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07);
3743 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01);
3745 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E);
3747 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D);
3749 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06);
3752 static void gen_mcrf(DisasContext
*ctx
)
3754 tcg_gen_mov_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfS(ctx
->opcode
)]);
3757 /*** System linkage ***/
3759 /* rfi (mem_idx only) */
3760 static void gen_rfi(DisasContext
*ctx
)
3762 #if defined(CONFIG_USER_ONLY)
3763 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3765 /* Restore CPU state */
3766 if (unlikely(!ctx
->mem_idx
)) {
3767 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3770 gen_update_cfar(ctx
, ctx
->nip
);
3771 gen_helper_rfi(cpu_env
);
3772 gen_sync_exception(ctx
);
3776 #if defined(TARGET_PPC64)
3777 static void gen_rfid(DisasContext
*ctx
)
3779 #if defined(CONFIG_USER_ONLY)
3780 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3782 /* Restore CPU state */
3783 if (unlikely(!ctx
->mem_idx
)) {
3784 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3787 gen_update_cfar(ctx
, ctx
->nip
);
3788 gen_helper_rfid(cpu_env
);
3789 gen_sync_exception(ctx
);
3793 static void gen_hrfid(DisasContext
*ctx
)
3795 #if defined(CONFIG_USER_ONLY)
3796 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3798 /* Restore CPU state */
3799 if (unlikely(ctx
->mem_idx
<= 1)) {
3800 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3803 gen_helper_hrfid(cpu_env
);
3804 gen_sync_exception(ctx
);
3810 #if defined(CONFIG_USER_ONLY)
3811 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3813 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3815 static void gen_sc(DisasContext
*ctx
)
3819 lev
= (ctx
->opcode
>> 5) & 0x7F;
3820 gen_exception_err(ctx
, POWERPC_SYSCALL
, lev
);
3826 static void gen_tw(DisasContext
*ctx
)
3828 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3829 /* Update the nip since this might generate a trap exception */
3830 gen_update_nip(ctx
, ctx
->nip
);
3831 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
3833 tcg_temp_free_i32(t0
);
3837 static void gen_twi(DisasContext
*ctx
)
3839 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3840 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
3841 /* Update the nip since this might generate a trap exception */
3842 gen_update_nip(ctx
, ctx
->nip
);
3843 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3845 tcg_temp_free_i32(t1
);
3848 #if defined(TARGET_PPC64)
3850 static void gen_td(DisasContext
*ctx
)
3852 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3853 /* Update the nip since this might generate a trap exception */
3854 gen_update_nip(ctx
, ctx
->nip
);
3855 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
3857 tcg_temp_free_i32(t0
);
3861 static void gen_tdi(DisasContext
*ctx
)
3863 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3864 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
3865 /* Update the nip since this might generate a trap exception */
3866 gen_update_nip(ctx
, ctx
->nip
);
3867 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3869 tcg_temp_free_i32(t1
);
3873 /*** Processor control ***/
3875 static void gen_read_xer(TCGv dst
)
3877 TCGv t0
= tcg_temp_new();
3878 TCGv t1
= tcg_temp_new();
3879 TCGv t2
= tcg_temp_new();
3880 tcg_gen_mov_tl(dst
, cpu_xer
);
3881 tcg_gen_shli_tl(t0
, cpu_so
, XER_SO
);
3882 tcg_gen_shli_tl(t1
, cpu_ov
, XER_OV
);
3883 tcg_gen_shli_tl(t2
, cpu_ca
, XER_CA
);
3884 tcg_gen_or_tl(t0
, t0
, t1
);
3885 tcg_gen_or_tl(dst
, dst
, t2
);
3886 tcg_gen_or_tl(dst
, dst
, t0
);
3892 static void gen_write_xer(TCGv src
)
3894 tcg_gen_andi_tl(cpu_xer
, src
,
3895 ~((1u << XER_SO
) | (1u << XER_OV
) | (1u << XER_CA
)));
3896 tcg_gen_shri_tl(cpu_so
, src
, XER_SO
);
3897 tcg_gen_shri_tl(cpu_ov
, src
, XER_OV
);
3898 tcg_gen_shri_tl(cpu_ca
, src
, XER_CA
);
3899 tcg_gen_andi_tl(cpu_so
, cpu_so
, 1);
3900 tcg_gen_andi_tl(cpu_ov
, cpu_ov
, 1);
3901 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
3905 static void gen_mcrxr(DisasContext
*ctx
)
3907 TCGv_i32 t0
= tcg_temp_new_i32();
3908 TCGv_i32 t1
= tcg_temp_new_i32();
3909 TCGv_i32 dst
= cpu_crf
[crfD(ctx
->opcode
)];
3911 tcg_gen_trunc_tl_i32(t0
, cpu_so
);
3912 tcg_gen_trunc_tl_i32(t1
, cpu_ov
);
3913 tcg_gen_trunc_tl_i32(dst
, cpu_ca
);
3914 tcg_gen_shri_i32(t0
, t0
, 2);
3915 tcg_gen_shri_i32(t1
, t1
, 1);
3916 tcg_gen_or_i32(dst
, dst
, t0
);
3917 tcg_gen_or_i32(dst
, dst
, t1
);
3918 tcg_temp_free_i32(t0
);
3919 tcg_temp_free_i32(t1
);
3921 tcg_gen_movi_tl(cpu_so
, 0);
3922 tcg_gen_movi_tl(cpu_ov
, 0);
3923 tcg_gen_movi_tl(cpu_ca
, 0);
3927 static void gen_mfcr(DisasContext
*ctx
)
3931 if (likely(ctx
->opcode
& 0x00100000)) {
3932 crm
= CRM(ctx
->opcode
);
3933 if (likely(crm
&& ((crm
& (crm
- 1)) == 0))) {
3935 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_crf
[7 - crn
]);
3936 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)],
3937 cpu_gpr
[rD(ctx
->opcode
)], crn
* 4);
3940 TCGv_i32 t0
= tcg_temp_new_i32();
3941 tcg_gen_mov_i32(t0
, cpu_crf
[0]);
3942 tcg_gen_shli_i32(t0
, t0
, 4);
3943 tcg_gen_or_i32(t0
, t0
, cpu_crf
[1]);
3944 tcg_gen_shli_i32(t0
, t0
, 4);
3945 tcg_gen_or_i32(t0
, t0
, cpu_crf
[2]);
3946 tcg_gen_shli_i32(t0
, t0
, 4);
3947 tcg_gen_or_i32(t0
, t0
, cpu_crf
[3]);
3948 tcg_gen_shli_i32(t0
, t0
, 4);
3949 tcg_gen_or_i32(t0
, t0
, cpu_crf
[4]);
3950 tcg_gen_shli_i32(t0
, t0
, 4);
3951 tcg_gen_or_i32(t0
, t0
, cpu_crf
[5]);
3952 tcg_gen_shli_i32(t0
, t0
, 4);
3953 tcg_gen_or_i32(t0
, t0
, cpu_crf
[6]);
3954 tcg_gen_shli_i32(t0
, t0
, 4);
3955 tcg_gen_or_i32(t0
, t0
, cpu_crf
[7]);
3956 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
3957 tcg_temp_free_i32(t0
);
3962 static void gen_mfmsr(DisasContext
*ctx
)
3964 #if defined(CONFIG_USER_ONLY)
3965 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3967 if (unlikely(!ctx
->mem_idx
)) {
3968 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3971 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_msr
);
3975 static void spr_noaccess(void *opaque
, int gprn
, int sprn
)
3978 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
3979 printf("ERROR: try to access SPR %d !\n", sprn
);
3982 #define SPR_NOACCESS (&spr_noaccess)
3985 static inline void gen_op_mfspr(DisasContext
*ctx
)
3987 void (*read_cb
)(void *opaque
, int gprn
, int sprn
);
3988 uint32_t sprn
= SPR(ctx
->opcode
);
3990 #if !defined(CONFIG_USER_ONLY)
3991 if (ctx
->mem_idx
== 2)
3992 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
3993 else if (ctx
->mem_idx
)
3994 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
3997 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
3998 if (likely(read_cb
!= NULL
)) {
3999 if (likely(read_cb
!= SPR_NOACCESS
)) {
4000 (*read_cb
)(ctx
, rD(ctx
->opcode
), sprn
);
4002 /* Privilege exception */
4003 /* This is a hack to avoid warnings when running Linux:
4004 * this OS breaks the PowerPC virtualisation model,
4005 * allowing userland application to read the PVR
4007 if (sprn
!= SPR_PVR
) {
4008 qemu_log("Trying to read privileged spr %d (0x%03x) at "
4009 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4010 printf("Trying to read privileged spr %d (0x%03x) at "
4011 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4013 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4017 qemu_log("Trying to read invalid spr %d (0x%03x) at "
4018 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4019 printf("Trying to read invalid spr %d (0x%03x) at "
4020 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4021 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4025 static void gen_mfspr(DisasContext
*ctx
)
4031 static void gen_mftb(DisasContext
*ctx
)
4037 static void gen_mtcrf(DisasContext
*ctx
)
4041 crm
= CRM(ctx
->opcode
);
4042 if (likely((ctx
->opcode
& 0x00100000))) {
4043 if (crm
&& ((crm
& (crm
- 1)) == 0)) {
4044 TCGv_i32 temp
= tcg_temp_new_i32();
4046 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
4047 tcg_gen_shri_i32(temp
, temp
, crn
* 4);
4048 tcg_gen_andi_i32(cpu_crf
[7 - crn
], temp
, 0xf);
4049 tcg_temp_free_i32(temp
);
4052 TCGv_i32 temp
= tcg_temp_new_i32();
4053 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
4054 for (crn
= 0 ; crn
< 8 ; crn
++) {
4055 if (crm
& (1 << crn
)) {
4056 tcg_gen_shri_i32(cpu_crf
[7 - crn
], temp
, crn
* 4);
4057 tcg_gen_andi_i32(cpu_crf
[7 - crn
], cpu_crf
[7 - crn
], 0xf);
4060 tcg_temp_free_i32(temp
);
4065 #if defined(TARGET_PPC64)
4066 static void gen_mtmsrd(DisasContext
*ctx
)
4068 #if defined(CONFIG_USER_ONLY)
4069 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4071 if (unlikely(!ctx
->mem_idx
)) {
4072 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4075 if (ctx
->opcode
& 0x00010000) {
4076 /* Special form that does not need any synchronisation */
4077 TCGv t0
= tcg_temp_new();
4078 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
4079 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
4080 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
4083 /* XXX: we need to update nip before the store
4084 * if we enter power saving mode, we will exit the loop
4085 * directly from ppc_store_msr
4087 gen_update_nip(ctx
, ctx
->nip
);
4088 gen_helper_store_msr(cpu_env
, cpu_gpr
[rS(ctx
->opcode
)]);
4089 /* Must stop the translation as machine state (may have) changed */
4090 /* Note that mtmsr is not always defined as context-synchronizing */
4091 gen_stop_exception(ctx
);
4097 static void gen_mtmsr(DisasContext
*ctx
)
4099 #if defined(CONFIG_USER_ONLY)
4100 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4102 if (unlikely(!ctx
->mem_idx
)) {
4103 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4106 if (ctx
->opcode
& 0x00010000) {
4107 /* Special form that does not need any synchronisation */
4108 TCGv t0
= tcg_temp_new();
4109 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
4110 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
4111 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
4114 TCGv msr
= tcg_temp_new();
4116 /* XXX: we need to update nip before the store
4117 * if we enter power saving mode, we will exit the loop
4118 * directly from ppc_store_msr
4120 gen_update_nip(ctx
, ctx
->nip
);
4121 #if defined(TARGET_PPC64)
4122 tcg_gen_deposit_tl(msr
, cpu_msr
, cpu_gpr
[rS(ctx
->opcode
)], 0, 32);
4124 tcg_gen_mov_tl(msr
, cpu_gpr
[rS(ctx
->opcode
)]);
4126 gen_helper_store_msr(cpu_env
, msr
);
4127 /* Must stop the translation as machine state (may have) changed */
4128 /* Note that mtmsr is not always defined as context-synchronizing */
4129 gen_stop_exception(ctx
);
4135 static void gen_mtspr(DisasContext
*ctx
)
4137 void (*write_cb
)(void *opaque
, int sprn
, int gprn
);
4138 uint32_t sprn
= SPR(ctx
->opcode
);
4140 #if !defined(CONFIG_USER_ONLY)
4141 if (ctx
->mem_idx
== 2)
4142 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
4143 else if (ctx
->mem_idx
)
4144 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
4147 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
4148 if (likely(write_cb
!= NULL
)) {
4149 if (likely(write_cb
!= SPR_NOACCESS
)) {
4150 (*write_cb
)(ctx
, sprn
, rS(ctx
->opcode
));
4152 /* Privilege exception */
4153 qemu_log("Trying to write privileged spr %d (0x%03x) at "
4154 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4155 printf("Trying to write privileged spr %d (0x%03x) at "
4156 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4157 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4161 qemu_log("Trying to write invalid spr %d (0x%03x) at "
4162 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4163 printf("Trying to write invalid spr %d (0x%03x) at "
4164 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
- 4);
4165 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4169 /*** Cache management ***/
4172 static void gen_dcbf(DisasContext
*ctx
)
4174 /* XXX: specification says this is treated as a load by the MMU */
4176 gen_set_access_type(ctx
, ACCESS_CACHE
);
4177 t0
= tcg_temp_new();
4178 gen_addr_reg_index(ctx
, t0
);
4179 gen_qemu_ld8u(ctx
, t0
, t0
);
4183 /* dcbi (Supervisor only) */
4184 static void gen_dcbi(DisasContext
*ctx
)
4186 #if defined(CONFIG_USER_ONLY)
4187 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4190 if (unlikely(!ctx
->mem_idx
)) {
4191 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4194 EA
= tcg_temp_new();
4195 gen_set_access_type(ctx
, ACCESS_CACHE
);
4196 gen_addr_reg_index(ctx
, EA
);
4197 val
= tcg_temp_new();
4198 /* XXX: specification says this should be treated as a store by the MMU */
4199 gen_qemu_ld8u(ctx
, val
, EA
);
4200 gen_qemu_st8(ctx
, val
, EA
);
4207 static void gen_dcbst(DisasContext
*ctx
)
4209 /* XXX: specification say this is treated as a load by the MMU */
4211 gen_set_access_type(ctx
, ACCESS_CACHE
);
4212 t0
= tcg_temp_new();
4213 gen_addr_reg_index(ctx
, t0
);
4214 gen_qemu_ld8u(ctx
, t0
, t0
);
4219 static void gen_dcbt(DisasContext
*ctx
)
4221 /* interpreted as no-op */
4222 /* XXX: specification say this is treated as a load by the MMU
4223 * but does not generate any exception
4228 static void gen_dcbtst(DisasContext
*ctx
)
4230 /* interpreted as no-op */
4231 /* XXX: specification say this is treated as a load by the MMU
4232 * but does not generate any exception
4237 static void gen_dcbz(DisasContext
*ctx
)
4240 TCGv_i32 tcgv_is_dcbzl
;
4241 int is_dcbzl
= ctx
->opcode
& 0x00200000 ? 1 : 0;
4243 gen_set_access_type(ctx
, ACCESS_CACHE
);
4244 /* NIP cannot be restored if the memory exception comes from an helper */
4245 gen_update_nip(ctx
, ctx
->nip
- 4);
4246 tcgv_addr
= tcg_temp_new();
4247 tcgv_is_dcbzl
= tcg_const_i32(is_dcbzl
);
4249 gen_addr_reg_index(ctx
, tcgv_addr
);
4250 gen_helper_dcbz(cpu_env
, tcgv_addr
, tcgv_is_dcbzl
);
4252 tcg_temp_free(tcgv_addr
);
4253 tcg_temp_free_i32(tcgv_is_dcbzl
);
4257 static void gen_dst(DisasContext
*ctx
)
4259 if (rA(ctx
->opcode
) == 0) {
4260 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
4262 /* interpreted as no-op */
4267 static void gen_dstst(DisasContext
*ctx
)
4269 if (rA(ctx
->opcode
) == 0) {
4270 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
4272 /* interpreted as no-op */
4278 static void gen_dss(DisasContext
*ctx
)
4280 /* interpreted as no-op */
4284 static void gen_icbi(DisasContext
*ctx
)
4287 gen_set_access_type(ctx
, ACCESS_CACHE
);
4288 /* NIP cannot be restored if the memory exception comes from an helper */
4289 gen_update_nip(ctx
, ctx
->nip
- 4);
4290 t0
= tcg_temp_new();
4291 gen_addr_reg_index(ctx
, t0
);
4292 gen_helper_icbi(cpu_env
, t0
);
4298 static void gen_dcba(DisasContext
*ctx
)
4300 /* interpreted as no-op */
4301 /* XXX: specification say this is treated as a store by the MMU
4302 * but does not generate any exception
4306 /*** Segment register manipulation ***/
4307 /* Supervisor only: */
4310 static void gen_mfsr(DisasContext
*ctx
)
4312 #if defined(CONFIG_USER_ONLY)
4313 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4316 if (unlikely(!ctx
->mem_idx
)) {
4317 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4320 t0
= tcg_const_tl(SR(ctx
->opcode
));
4321 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4327 static void gen_mfsrin(DisasContext
*ctx
)
4329 #if defined(CONFIG_USER_ONLY)
4330 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4333 if (unlikely(!ctx
->mem_idx
)) {
4334 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4337 t0
= tcg_temp_new();
4338 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4339 tcg_gen_andi_tl(t0
, t0
, 0xF);
4340 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4346 static void gen_mtsr(DisasContext
*ctx
)
4348 #if defined(CONFIG_USER_ONLY)
4349 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4352 if (unlikely(!ctx
->mem_idx
)) {
4353 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4356 t0
= tcg_const_tl(SR(ctx
->opcode
));
4357 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4363 static void gen_mtsrin(DisasContext
*ctx
)
4365 #if defined(CONFIG_USER_ONLY)
4366 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4369 if (unlikely(!ctx
->mem_idx
)) {
4370 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4373 t0
= tcg_temp_new();
4374 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4375 tcg_gen_andi_tl(t0
, t0
, 0xF);
4376 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rD(ctx
->opcode
)]);
4381 #if defined(TARGET_PPC64)
4382 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4385 static void gen_mfsr_64b(DisasContext
*ctx
)
4387 #if defined(CONFIG_USER_ONLY)
4388 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4391 if (unlikely(!ctx
->mem_idx
)) {
4392 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4395 t0
= tcg_const_tl(SR(ctx
->opcode
));
4396 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4402 static void gen_mfsrin_64b(DisasContext
*ctx
)
4404 #if defined(CONFIG_USER_ONLY)
4405 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4408 if (unlikely(!ctx
->mem_idx
)) {
4409 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4412 t0
= tcg_temp_new();
4413 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4414 tcg_gen_andi_tl(t0
, t0
, 0xF);
4415 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4421 static void gen_mtsr_64b(DisasContext
*ctx
)
4423 #if defined(CONFIG_USER_ONLY)
4424 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4427 if (unlikely(!ctx
->mem_idx
)) {
4428 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4431 t0
= tcg_const_tl(SR(ctx
->opcode
));
4432 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4438 static void gen_mtsrin_64b(DisasContext
*ctx
)
4440 #if defined(CONFIG_USER_ONLY)
4441 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4444 if (unlikely(!ctx
->mem_idx
)) {
4445 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4448 t0
= tcg_temp_new();
4449 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4450 tcg_gen_andi_tl(t0
, t0
, 0xF);
4451 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4457 static void gen_slbmte(DisasContext
*ctx
)
4459 #if defined(CONFIG_USER_ONLY)
4460 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4462 if (unlikely(!ctx
->mem_idx
)) {
4463 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4466 gen_helper_store_slb(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)],
4467 cpu_gpr
[rS(ctx
->opcode
)]);
4471 static void gen_slbmfee(DisasContext
*ctx
)
4473 #if defined(CONFIG_USER_ONLY)
4474 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4476 if (unlikely(!ctx
->mem_idx
)) {
4477 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4480 gen_helper_load_slb_esid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4481 cpu_gpr
[rB(ctx
->opcode
)]);
4485 static void gen_slbmfev(DisasContext
*ctx
)
4487 #if defined(CONFIG_USER_ONLY)
4488 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4490 if (unlikely(!ctx
->mem_idx
)) {
4491 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4494 gen_helper_load_slb_vsid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4495 cpu_gpr
[rB(ctx
->opcode
)]);
4498 #endif /* defined(TARGET_PPC64) */
4500 /*** Lookaside buffer management ***/
4501 /* Optional & mem_idx only: */
4504 static void gen_tlbia(DisasContext
*ctx
)
4506 #if defined(CONFIG_USER_ONLY)
4507 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4509 if (unlikely(!ctx
->mem_idx
)) {
4510 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4513 gen_helper_tlbia(cpu_env
);
4518 static void gen_tlbiel(DisasContext
*ctx
)
4520 #if defined(CONFIG_USER_ONLY)
4521 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4523 if (unlikely(!ctx
->mem_idx
)) {
4524 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4527 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4532 static void gen_tlbie(DisasContext
*ctx
)
4534 #if defined(CONFIG_USER_ONLY)
4535 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4537 if (unlikely(!ctx
->mem_idx
)) {
4538 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4541 if (NARROW_MODE(ctx
)) {
4542 TCGv t0
= tcg_temp_new();
4543 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
4544 gen_helper_tlbie(cpu_env
, t0
);
4547 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4553 static void gen_tlbsync(DisasContext
*ctx
)
4555 #if defined(CONFIG_USER_ONLY)
4556 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4558 if (unlikely(!ctx
->mem_idx
)) {
4559 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4562 /* This has no effect: it should ensure that all previous
4563 * tlbie have completed
4565 gen_stop_exception(ctx
);
4569 #if defined(TARGET_PPC64)
4571 static void gen_slbia(DisasContext
*ctx
)
4573 #if defined(CONFIG_USER_ONLY)
4574 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4576 if (unlikely(!ctx
->mem_idx
)) {
4577 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4580 gen_helper_slbia(cpu_env
);
4585 static void gen_slbie(DisasContext
*ctx
)
4587 #if defined(CONFIG_USER_ONLY)
4588 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4590 if (unlikely(!ctx
->mem_idx
)) {
4591 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4594 gen_helper_slbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4599 /*** External control ***/
4603 static void gen_eciwx(DisasContext
*ctx
)
4606 /* Should check EAR[E] ! */
4607 gen_set_access_type(ctx
, ACCESS_EXT
);
4608 t0
= tcg_temp_new();
4609 gen_addr_reg_index(ctx
, t0
);
4610 gen_check_align(ctx
, t0
, 0x03);
4611 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4616 static void gen_ecowx(DisasContext
*ctx
)
4619 /* Should check EAR[E] ! */
4620 gen_set_access_type(ctx
, ACCESS_EXT
);
4621 t0
= tcg_temp_new();
4622 gen_addr_reg_index(ctx
, t0
);
4623 gen_check_align(ctx
, t0
, 0x03);
4624 gen_qemu_st32(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4628 /* PowerPC 601 specific instructions */
4631 static void gen_abs(DisasContext
*ctx
)
4633 int l1
= gen_new_label();
4634 int l2
= gen_new_label();
4635 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4636 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4639 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4641 if (unlikely(Rc(ctx
->opcode
) != 0))
4642 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4646 static void gen_abso(DisasContext
*ctx
)
4648 int l1
= gen_new_label();
4649 int l2
= gen_new_label();
4650 int l3
= gen_new_label();
4651 /* Start with XER OV disabled, the most likely case */
4652 tcg_gen_movi_tl(cpu_ov
, 0);
4653 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l2
);
4654 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rA(ctx
->opcode
)], 0x80000000, l1
);
4655 tcg_gen_movi_tl(cpu_ov
, 1);
4656 tcg_gen_movi_tl(cpu_so
, 1);
4659 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4662 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4664 if (unlikely(Rc(ctx
->opcode
) != 0))
4665 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4669 static void gen_clcs(DisasContext
*ctx
)
4671 TCGv_i32 t0
= tcg_const_i32(rA(ctx
->opcode
));
4672 gen_helper_clcs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4673 tcg_temp_free_i32(t0
);
4674 /* Rc=1 sets CR0 to an undefined state */
4678 static void gen_div(DisasContext
*ctx
)
4680 gen_helper_div(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4681 cpu_gpr
[rB(ctx
->opcode
)]);
4682 if (unlikely(Rc(ctx
->opcode
) != 0))
4683 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4687 static void gen_divo(DisasContext
*ctx
)
4689 gen_helper_divo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4690 cpu_gpr
[rB(ctx
->opcode
)]);
4691 if (unlikely(Rc(ctx
->opcode
) != 0))
4692 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4696 static void gen_divs(DisasContext
*ctx
)
4698 gen_helper_divs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4699 cpu_gpr
[rB(ctx
->opcode
)]);
4700 if (unlikely(Rc(ctx
->opcode
) != 0))
4701 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4704 /* divso - divso. */
4705 static void gen_divso(DisasContext
*ctx
)
4707 gen_helper_divso(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
4708 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4709 if (unlikely(Rc(ctx
->opcode
) != 0))
4710 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4714 static void gen_doz(DisasContext
*ctx
)
4716 int l1
= gen_new_label();
4717 int l2
= gen_new_label();
4718 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4719 tcg_gen_sub_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4722 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4724 if (unlikely(Rc(ctx
->opcode
) != 0))
4725 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4729 static void gen_dozo(DisasContext
*ctx
)
4731 int l1
= gen_new_label();
4732 int l2
= gen_new_label();
4733 TCGv t0
= tcg_temp_new();
4734 TCGv t1
= tcg_temp_new();
4735 TCGv t2
= tcg_temp_new();
4736 /* Start with XER OV disabled, the most likely case */
4737 tcg_gen_movi_tl(cpu_ov
, 0);
4738 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4739 tcg_gen_sub_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4740 tcg_gen_xor_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4741 tcg_gen_xor_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], t0
);
4742 tcg_gen_andc_tl(t1
, t1
, t2
);
4743 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4744 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
4745 tcg_gen_movi_tl(cpu_ov
, 1);
4746 tcg_gen_movi_tl(cpu_so
, 1);
4749 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4754 if (unlikely(Rc(ctx
->opcode
) != 0))
4755 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4759 static void gen_dozi(DisasContext
*ctx
)
4761 target_long simm
= SIMM(ctx
->opcode
);
4762 int l1
= gen_new_label();
4763 int l2
= gen_new_label();
4764 tcg_gen_brcondi_tl(TCG_COND_LT
, cpu_gpr
[rA(ctx
->opcode
)], simm
, l1
);
4765 tcg_gen_subfi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
, cpu_gpr
[rA(ctx
->opcode
)]);
4768 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4770 if (unlikely(Rc(ctx
->opcode
) != 0))
4771 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4774 /* lscbx - lscbx. */
4775 static void gen_lscbx(DisasContext
*ctx
)
4777 TCGv t0
= tcg_temp_new();
4778 TCGv_i32 t1
= tcg_const_i32(rD(ctx
->opcode
));
4779 TCGv_i32 t2
= tcg_const_i32(rA(ctx
->opcode
));
4780 TCGv_i32 t3
= tcg_const_i32(rB(ctx
->opcode
));
4782 gen_addr_reg_index(ctx
, t0
);
4783 /* NIP cannot be restored if the memory exception comes from an helper */
4784 gen_update_nip(ctx
, ctx
->nip
- 4);
4785 gen_helper_lscbx(t0
, cpu_env
, t0
, t1
, t2
, t3
);
4786 tcg_temp_free_i32(t1
);
4787 tcg_temp_free_i32(t2
);
4788 tcg_temp_free_i32(t3
);
4789 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~0x7F);
4790 tcg_gen_or_tl(cpu_xer
, cpu_xer
, t0
);
4791 if (unlikely(Rc(ctx
->opcode
) != 0))
4792 gen_set_Rc0(ctx
, t0
);
4796 /* maskg - maskg. */
4797 static void gen_maskg(DisasContext
*ctx
)
4799 int l1
= gen_new_label();
4800 TCGv t0
= tcg_temp_new();
4801 TCGv t1
= tcg_temp_new();
4802 TCGv t2
= tcg_temp_new();
4803 TCGv t3
= tcg_temp_new();
4804 tcg_gen_movi_tl(t3
, 0xFFFFFFFF);
4805 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4806 tcg_gen_andi_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 0x1F);
4807 tcg_gen_addi_tl(t2
, t0
, 1);
4808 tcg_gen_shr_tl(t2
, t3
, t2
);
4809 tcg_gen_shr_tl(t3
, t3
, t1
);
4810 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], t2
, t3
);
4811 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
4812 tcg_gen_neg_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4818 if (unlikely(Rc(ctx
->opcode
) != 0))
4819 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4822 /* maskir - maskir. */
4823 static void gen_maskir(DisasContext
*ctx
)
4825 TCGv t0
= tcg_temp_new();
4826 TCGv t1
= tcg_temp_new();
4827 tcg_gen_and_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4828 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4829 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4832 if (unlikely(Rc(ctx
->opcode
) != 0))
4833 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4837 static void gen_mul(DisasContext
*ctx
)
4839 TCGv_i64 t0
= tcg_temp_new_i64();
4840 TCGv_i64 t1
= tcg_temp_new_i64();
4841 TCGv t2
= tcg_temp_new();
4842 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4843 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4844 tcg_gen_mul_i64(t0
, t0
, t1
);
4845 tcg_gen_trunc_i64_tl(t2
, t0
);
4846 gen_store_spr(SPR_MQ
, t2
);
4847 tcg_gen_shri_i64(t1
, t0
, 32);
4848 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4849 tcg_temp_free_i64(t0
);
4850 tcg_temp_free_i64(t1
);
4852 if (unlikely(Rc(ctx
->opcode
) != 0))
4853 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4857 static void gen_mulo(DisasContext
*ctx
)
4859 int l1
= gen_new_label();
4860 TCGv_i64 t0
= tcg_temp_new_i64();
4861 TCGv_i64 t1
= tcg_temp_new_i64();
4862 TCGv t2
= tcg_temp_new();
4863 /* Start with XER OV disabled, the most likely case */
4864 tcg_gen_movi_tl(cpu_ov
, 0);
4865 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4866 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4867 tcg_gen_mul_i64(t0
, t0
, t1
);
4868 tcg_gen_trunc_i64_tl(t2
, t0
);
4869 gen_store_spr(SPR_MQ
, t2
);
4870 tcg_gen_shri_i64(t1
, t0
, 32);
4871 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4872 tcg_gen_ext32s_i64(t1
, t0
);
4873 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
4874 tcg_gen_movi_tl(cpu_ov
, 1);
4875 tcg_gen_movi_tl(cpu_so
, 1);
4877 tcg_temp_free_i64(t0
);
4878 tcg_temp_free_i64(t1
);
4880 if (unlikely(Rc(ctx
->opcode
) != 0))
4881 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4885 static void gen_nabs(DisasContext
*ctx
)
4887 int l1
= gen_new_label();
4888 int l2
= gen_new_label();
4889 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4890 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4893 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4895 if (unlikely(Rc(ctx
->opcode
) != 0))
4896 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4899 /* nabso - nabso. */
4900 static void gen_nabso(DisasContext
*ctx
)
4902 int l1
= gen_new_label();
4903 int l2
= gen_new_label();
4904 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4905 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4908 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4910 /* nabs never overflows */
4911 tcg_gen_movi_tl(cpu_ov
, 0);
4912 if (unlikely(Rc(ctx
->opcode
) != 0))
4913 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4917 static void gen_rlmi(DisasContext
*ctx
)
4919 uint32_t mb
= MB(ctx
->opcode
);
4920 uint32_t me
= ME(ctx
->opcode
);
4921 TCGv t0
= tcg_temp_new();
4922 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4923 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4924 tcg_gen_andi_tl(t0
, t0
, MASK(mb
, me
));
4925 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~MASK(mb
, me
));
4926 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], t0
);
4928 if (unlikely(Rc(ctx
->opcode
) != 0))
4929 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4933 static void gen_rrib(DisasContext
*ctx
)
4935 TCGv t0
= tcg_temp_new();
4936 TCGv t1
= tcg_temp_new();
4937 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4938 tcg_gen_movi_tl(t1
, 0x80000000);
4939 tcg_gen_shr_tl(t1
, t1
, t0
);
4940 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4941 tcg_gen_and_tl(t0
, t0
, t1
);
4942 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], t1
);
4943 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4946 if (unlikely(Rc(ctx
->opcode
) != 0))
4947 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4951 static void gen_sle(DisasContext
*ctx
)
4953 TCGv t0
= tcg_temp_new();
4954 TCGv t1
= tcg_temp_new();
4955 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4956 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4957 tcg_gen_subfi_tl(t1
, 32, t1
);
4958 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4959 tcg_gen_or_tl(t1
, t0
, t1
);
4960 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4961 gen_store_spr(SPR_MQ
, t1
);
4964 if (unlikely(Rc(ctx
->opcode
) != 0))
4965 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4969 static void gen_sleq(DisasContext
*ctx
)
4971 TCGv t0
= tcg_temp_new();
4972 TCGv t1
= tcg_temp_new();
4973 TCGv t2
= tcg_temp_new();
4974 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4975 tcg_gen_movi_tl(t2
, 0xFFFFFFFF);
4976 tcg_gen_shl_tl(t2
, t2
, t0
);
4977 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4978 gen_load_spr(t1
, SPR_MQ
);
4979 gen_store_spr(SPR_MQ
, t0
);
4980 tcg_gen_and_tl(t0
, t0
, t2
);
4981 tcg_gen_andc_tl(t1
, t1
, t2
);
4982 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4986 if (unlikely(Rc(ctx
->opcode
) != 0))
4987 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4991 static void gen_sliq(DisasContext
*ctx
)
4993 int sh
= SH(ctx
->opcode
);
4994 TCGv t0
= tcg_temp_new();
4995 TCGv t1
= tcg_temp_new();
4996 tcg_gen_shli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4997 tcg_gen_shri_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
4998 tcg_gen_or_tl(t1
, t0
, t1
);
4999 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5000 gen_store_spr(SPR_MQ
, t1
);
5003 if (unlikely(Rc(ctx
->opcode
) != 0))
5004 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5007 /* slliq - slliq. */
5008 static void gen_slliq(DisasContext
*ctx
)
5010 int sh
= SH(ctx
->opcode
);
5011 TCGv t0
= tcg_temp_new();
5012 TCGv t1
= tcg_temp_new();
5013 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5014 gen_load_spr(t1
, SPR_MQ
);
5015 gen_store_spr(SPR_MQ
, t0
);
5016 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
<< sh
));
5017 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
<< sh
));
5018 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5021 if (unlikely(Rc(ctx
->opcode
) != 0))
5022 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5026 static void gen_sllq(DisasContext
*ctx
)
5028 int l1
= gen_new_label();
5029 int l2
= gen_new_label();
5030 TCGv t0
= tcg_temp_local_new();
5031 TCGv t1
= tcg_temp_local_new();
5032 TCGv t2
= tcg_temp_local_new();
5033 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5034 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5035 tcg_gen_shl_tl(t1
, t1
, t2
);
5036 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5037 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5038 gen_load_spr(t0
, SPR_MQ
);
5039 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5042 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5043 gen_load_spr(t2
, SPR_MQ
);
5044 tcg_gen_andc_tl(t1
, t2
, t1
);
5045 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5050 if (unlikely(Rc(ctx
->opcode
) != 0))
5051 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5055 static void gen_slq(DisasContext
*ctx
)
5057 int l1
= gen_new_label();
5058 TCGv t0
= tcg_temp_new();
5059 TCGv t1
= tcg_temp_new();
5060 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5061 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5062 tcg_gen_subfi_tl(t1
, 32, t1
);
5063 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5064 tcg_gen_or_tl(t1
, t0
, t1
);
5065 gen_store_spr(SPR_MQ
, t1
);
5066 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5067 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5068 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
5069 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5073 if (unlikely(Rc(ctx
->opcode
) != 0))
5074 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5077 /* sraiq - sraiq. */
5078 static void gen_sraiq(DisasContext
*ctx
)
5080 int sh
= SH(ctx
->opcode
);
5081 int l1
= gen_new_label();
5082 TCGv t0
= tcg_temp_new();
5083 TCGv t1
= tcg_temp_new();
5084 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5085 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5086 tcg_gen_or_tl(t0
, t0
, t1
);
5087 gen_store_spr(SPR_MQ
, t0
);
5088 tcg_gen_movi_tl(cpu_ca
, 0);
5089 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
5090 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
5091 tcg_gen_movi_tl(cpu_ca
, 1);
5093 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
5096 if (unlikely(Rc(ctx
->opcode
) != 0))
5097 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5101 static void gen_sraq(DisasContext
*ctx
)
5103 int l1
= gen_new_label();
5104 int l2
= gen_new_label();
5105 TCGv t0
= tcg_temp_new();
5106 TCGv t1
= tcg_temp_local_new();
5107 TCGv t2
= tcg_temp_local_new();
5108 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5109 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5110 tcg_gen_sar_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5111 tcg_gen_subfi_tl(t2
, 32, t2
);
5112 tcg_gen_shl_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5113 tcg_gen_or_tl(t0
, t0
, t2
);
5114 gen_store_spr(SPR_MQ
, t0
);
5115 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5116 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l1
);
5117 tcg_gen_mov_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
5118 tcg_gen_sari_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 31);
5121 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
);
5122 tcg_gen_movi_tl(cpu_ca
, 0);
5123 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
5124 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l2
);
5125 tcg_gen_movi_tl(cpu_ca
, 1);
5129 if (unlikely(Rc(ctx
->opcode
) != 0))
5130 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5134 static void gen_sre(DisasContext
*ctx
)
5136 TCGv t0
= tcg_temp_new();
5137 TCGv t1
= tcg_temp_new();
5138 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5139 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5140 tcg_gen_subfi_tl(t1
, 32, t1
);
5141 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5142 tcg_gen_or_tl(t1
, t0
, t1
);
5143 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5144 gen_store_spr(SPR_MQ
, t1
);
5147 if (unlikely(Rc(ctx
->opcode
) != 0))
5148 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5152 static void gen_srea(DisasContext
*ctx
)
5154 TCGv t0
= tcg_temp_new();
5155 TCGv t1
= tcg_temp_new();
5156 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5157 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5158 gen_store_spr(SPR_MQ
, t0
);
5159 tcg_gen_sar_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t1
);
5162 if (unlikely(Rc(ctx
->opcode
) != 0))
5163 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5167 static void gen_sreq(DisasContext
*ctx
)
5169 TCGv t0
= tcg_temp_new();
5170 TCGv t1
= tcg_temp_new();
5171 TCGv t2
= tcg_temp_new();
5172 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5173 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5174 tcg_gen_shr_tl(t1
, t1
, t0
);
5175 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5176 gen_load_spr(t2
, SPR_MQ
);
5177 gen_store_spr(SPR_MQ
, t0
);
5178 tcg_gen_and_tl(t0
, t0
, t1
);
5179 tcg_gen_andc_tl(t2
, t2
, t1
);
5180 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5184 if (unlikely(Rc(ctx
->opcode
) != 0))
5185 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5189 static void gen_sriq(DisasContext
*ctx
)
5191 int sh
= SH(ctx
->opcode
);
5192 TCGv t0
= tcg_temp_new();
5193 TCGv t1
= tcg_temp_new();
5194 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5195 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5196 tcg_gen_or_tl(t1
, t0
, t1
);
5197 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5198 gen_store_spr(SPR_MQ
, t1
);
5201 if (unlikely(Rc(ctx
->opcode
) != 0))
5202 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5206 static void gen_srliq(DisasContext
*ctx
)
5208 int sh
= SH(ctx
->opcode
);
5209 TCGv t0
= tcg_temp_new();
5210 TCGv t1
= tcg_temp_new();
5211 tcg_gen_rotri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5212 gen_load_spr(t1
, SPR_MQ
);
5213 gen_store_spr(SPR_MQ
, t0
);
5214 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
>> sh
));
5215 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
>> sh
));
5216 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5219 if (unlikely(Rc(ctx
->opcode
) != 0))
5220 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5224 static void gen_srlq(DisasContext
*ctx
)
5226 int l1
= gen_new_label();
5227 int l2
= gen_new_label();
5228 TCGv t0
= tcg_temp_local_new();
5229 TCGv t1
= tcg_temp_local_new();
5230 TCGv t2
= tcg_temp_local_new();
5231 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5232 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5233 tcg_gen_shr_tl(t2
, t1
, t2
);
5234 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5235 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5236 gen_load_spr(t0
, SPR_MQ
);
5237 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5240 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5241 tcg_gen_and_tl(t0
, t0
, t2
);
5242 gen_load_spr(t1
, SPR_MQ
);
5243 tcg_gen_andc_tl(t1
, t1
, t2
);
5244 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5249 if (unlikely(Rc(ctx
->opcode
) != 0))
5250 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5254 static void gen_srq(DisasContext
*ctx
)
5256 int l1
= gen_new_label();
5257 TCGv t0
= tcg_temp_new();
5258 TCGv t1
= tcg_temp_new();
5259 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5260 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5261 tcg_gen_subfi_tl(t1
, 32, t1
);
5262 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5263 tcg_gen_or_tl(t1
, t0
, t1
);
5264 gen_store_spr(SPR_MQ
, t1
);
5265 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5266 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5267 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5268 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5272 if (unlikely(Rc(ctx
->opcode
) != 0))
5273 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5276 /* PowerPC 602 specific instructions */
5279 static void gen_dsa(DisasContext
*ctx
)
5282 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5286 static void gen_esa(DisasContext
*ctx
)
5289 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5293 static void gen_mfrom(DisasContext
*ctx
)
5295 #if defined(CONFIG_USER_ONLY)
5296 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5298 if (unlikely(!ctx
->mem_idx
)) {
5299 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5302 gen_helper_602_mfrom(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5306 /* 602 - 603 - G2 TLB management */
5309 static void gen_tlbld_6xx(DisasContext
*ctx
)
5311 #if defined(CONFIG_USER_ONLY)
5312 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5314 if (unlikely(!ctx
->mem_idx
)) {
5315 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5318 gen_helper_6xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5323 static void gen_tlbli_6xx(DisasContext
*ctx
)
5325 #if defined(CONFIG_USER_ONLY)
5326 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5328 if (unlikely(!ctx
->mem_idx
)) {
5329 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5332 gen_helper_6xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5336 /* 74xx TLB management */
5339 static void gen_tlbld_74xx(DisasContext
*ctx
)
5341 #if defined(CONFIG_USER_ONLY)
5342 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5344 if (unlikely(!ctx
->mem_idx
)) {
5345 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5348 gen_helper_74xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5353 static void gen_tlbli_74xx(DisasContext
*ctx
)
5355 #if defined(CONFIG_USER_ONLY)
5356 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5358 if (unlikely(!ctx
->mem_idx
)) {
5359 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5362 gen_helper_74xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5366 /* POWER instructions not in PowerPC 601 */
5369 static void gen_clf(DisasContext
*ctx
)
5371 /* Cache line flush: implemented as no-op */
5375 static void gen_cli(DisasContext
*ctx
)
5377 /* Cache line invalidate: privileged and treated as no-op */
5378 #if defined(CONFIG_USER_ONLY)
5379 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5381 if (unlikely(!ctx
->mem_idx
)) {
5382 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5389 static void gen_dclst(DisasContext
*ctx
)
5391 /* Data cache line store: treated as no-op */
5394 static void gen_mfsri(DisasContext
*ctx
)
5396 #if defined(CONFIG_USER_ONLY)
5397 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5399 int ra
= rA(ctx
->opcode
);
5400 int rd
= rD(ctx
->opcode
);
5402 if (unlikely(!ctx
->mem_idx
)) {
5403 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5406 t0
= tcg_temp_new();
5407 gen_addr_reg_index(ctx
, t0
);
5408 tcg_gen_shri_tl(t0
, t0
, 28);
5409 tcg_gen_andi_tl(t0
, t0
, 0xF);
5410 gen_helper_load_sr(cpu_gpr
[rd
], cpu_env
, t0
);
5412 if (ra
!= 0 && ra
!= rd
)
5413 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rd
]);
5417 static void gen_rac(DisasContext
*ctx
)
5419 #if defined(CONFIG_USER_ONLY)
5420 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5423 if (unlikely(!ctx
->mem_idx
)) {
5424 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5427 t0
= tcg_temp_new();
5428 gen_addr_reg_index(ctx
, t0
);
5429 gen_helper_rac(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5434 static void gen_rfsvc(DisasContext
*ctx
)
5436 #if defined(CONFIG_USER_ONLY)
5437 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5439 if (unlikely(!ctx
->mem_idx
)) {
5440 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5443 gen_helper_rfsvc(cpu_env
);
5444 gen_sync_exception(ctx
);
5448 /* svc is not implemented for now */
5450 /* POWER2 specific instructions */
5451 /* Quad manipulation (load/store two floats at a time) */
5454 static void gen_lfq(DisasContext
*ctx
)
5456 int rd
= rD(ctx
->opcode
);
5458 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5459 t0
= tcg_temp_new();
5460 gen_addr_imm_index(ctx
, t0
, 0);
5461 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5462 gen_addr_add(ctx
, t0
, t0
, 8);
5463 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5468 static void gen_lfqu(DisasContext
*ctx
)
5470 int ra
= rA(ctx
->opcode
);
5471 int rd
= rD(ctx
->opcode
);
5473 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5474 t0
= tcg_temp_new();
5475 t1
= tcg_temp_new();
5476 gen_addr_imm_index(ctx
, t0
, 0);
5477 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5478 gen_addr_add(ctx
, t1
, t0
, 8);
5479 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5481 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5487 static void gen_lfqux(DisasContext
*ctx
)
5489 int ra
= rA(ctx
->opcode
);
5490 int rd
= rD(ctx
->opcode
);
5491 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5493 t0
= tcg_temp_new();
5494 gen_addr_reg_index(ctx
, t0
);
5495 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5496 t1
= tcg_temp_new();
5497 gen_addr_add(ctx
, t1
, t0
, 8);
5498 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5501 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5506 static void gen_lfqx(DisasContext
*ctx
)
5508 int rd
= rD(ctx
->opcode
);
5510 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5511 t0
= tcg_temp_new();
5512 gen_addr_reg_index(ctx
, t0
);
5513 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5514 gen_addr_add(ctx
, t0
, t0
, 8);
5515 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5520 static void gen_stfq(DisasContext
*ctx
)
5522 int rd
= rD(ctx
->opcode
);
5524 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5525 t0
= tcg_temp_new();
5526 gen_addr_imm_index(ctx
, t0
, 0);
5527 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5528 gen_addr_add(ctx
, t0
, t0
, 8);
5529 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5534 static void gen_stfqu(DisasContext
*ctx
)
5536 int ra
= rA(ctx
->opcode
);
5537 int rd
= rD(ctx
->opcode
);
5539 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5540 t0
= tcg_temp_new();
5541 gen_addr_imm_index(ctx
, t0
, 0);
5542 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5543 t1
= tcg_temp_new();
5544 gen_addr_add(ctx
, t1
, t0
, 8);
5545 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5548 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5553 static void gen_stfqux(DisasContext
*ctx
)
5555 int ra
= rA(ctx
->opcode
);
5556 int rd
= rD(ctx
->opcode
);
5558 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5559 t0
= tcg_temp_new();
5560 gen_addr_reg_index(ctx
, t0
);
5561 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5562 t1
= tcg_temp_new();
5563 gen_addr_add(ctx
, t1
, t0
, 8);
5564 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5567 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5572 static void gen_stfqx(DisasContext
*ctx
)
5574 int rd
= rD(ctx
->opcode
);
5576 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5577 t0
= tcg_temp_new();
5578 gen_addr_reg_index(ctx
, t0
);
5579 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5580 gen_addr_add(ctx
, t0
, t0
, 8);
5581 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5585 /* BookE specific instructions */
5587 /* XXX: not implemented on 440 ? */
5588 static void gen_mfapidi(DisasContext
*ctx
)
5591 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5594 /* XXX: not implemented on 440 ? */
5595 static void gen_tlbiva(DisasContext
*ctx
)
5597 #if defined(CONFIG_USER_ONLY)
5598 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5601 if (unlikely(!ctx
->mem_idx
)) {
5602 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5605 t0
= tcg_temp_new();
5606 gen_addr_reg_index(ctx
, t0
);
5607 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5612 /* All 405 MAC instructions are translated here */
5613 static inline void gen_405_mulladd_insn(DisasContext
*ctx
, int opc2
, int opc3
,
5614 int ra
, int rb
, int rt
, int Rc
)
5618 t0
= tcg_temp_local_new();
5619 t1
= tcg_temp_local_new();
5621 switch (opc3
& 0x0D) {
5623 /* macchw - macchw. - macchwo - macchwo. */
5624 /* macchws - macchws. - macchwso - macchwso. */
5625 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5626 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5627 /* mulchw - mulchw. */
5628 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5629 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5630 tcg_gen_ext16s_tl(t1
, t1
);
5633 /* macchwu - macchwu. - macchwuo - macchwuo. */
5634 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5635 /* mulchwu - mulchwu. */
5636 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5637 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5638 tcg_gen_ext16u_tl(t1
, t1
);
5641 /* machhw - machhw. - machhwo - machhwo. */
5642 /* machhws - machhws. - machhwso - machhwso. */
5643 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5644 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5645 /* mulhhw - mulhhw. */
5646 tcg_gen_sari_tl(t0
, cpu_gpr
[ra
], 16);
5647 tcg_gen_ext16s_tl(t0
, t0
);
5648 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5649 tcg_gen_ext16s_tl(t1
, t1
);
5652 /* machhwu - machhwu. - machhwuo - machhwuo. */
5653 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5654 /* mulhhwu - mulhhwu. */
5655 tcg_gen_shri_tl(t0
, cpu_gpr
[ra
], 16);
5656 tcg_gen_ext16u_tl(t0
, t0
);
5657 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5658 tcg_gen_ext16u_tl(t1
, t1
);
5661 /* maclhw - maclhw. - maclhwo - maclhwo. */
5662 /* maclhws - maclhws. - maclhwso - maclhwso. */
5663 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5664 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5665 /* mullhw - mullhw. */
5666 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5667 tcg_gen_ext16s_tl(t1
, cpu_gpr
[rb
]);
5670 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5671 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5672 /* mullhwu - mullhwu. */
5673 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5674 tcg_gen_ext16u_tl(t1
, cpu_gpr
[rb
]);
5678 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5679 tcg_gen_mul_tl(t1
, t0
, t1
);
5681 /* nmultiply-and-accumulate (0x0E) */
5682 tcg_gen_sub_tl(t0
, cpu_gpr
[rt
], t1
);
5684 /* multiply-and-accumulate (0x0C) */
5685 tcg_gen_add_tl(t0
, cpu_gpr
[rt
], t1
);
5689 /* Check overflow and/or saturate */
5690 int l1
= gen_new_label();
5693 /* Start with XER OV disabled, the most likely case */
5694 tcg_gen_movi_tl(cpu_ov
, 0);
5698 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t1
);
5699 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
5700 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t0
);
5701 tcg_gen_brcondi_tl(TCG_COND_LT
, t1
, 0, l1
);
5704 tcg_gen_sari_tl(t0
, cpu_gpr
[rt
], 31);
5705 tcg_gen_xori_tl(t0
, t0
, 0x7fffffff);
5709 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
5712 tcg_gen_movi_tl(t0
, UINT32_MAX
);
5716 /* Check overflow */
5717 tcg_gen_movi_tl(cpu_ov
, 1);
5718 tcg_gen_movi_tl(cpu_so
, 1);
5721 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
5724 tcg_gen_mul_tl(cpu_gpr
[rt
], t0
, t1
);
5728 if (unlikely(Rc
) != 0) {
5730 gen_set_Rc0(ctx
, cpu_gpr
[rt
]);
5734 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5735 static void glue(gen_, name)(DisasContext *ctx) \
5737 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5738 rD(ctx->opcode), Rc(ctx->opcode)); \
5741 /* macchw - macchw. */
5742 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
5743 /* macchwo - macchwo. */
5744 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
5745 /* macchws - macchws. */
5746 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
5747 /* macchwso - macchwso. */
5748 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
5749 /* macchwsu - macchwsu. */
5750 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
5751 /* macchwsuo - macchwsuo. */
5752 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
5753 /* macchwu - macchwu. */
5754 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
5755 /* macchwuo - macchwuo. */
5756 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
5757 /* machhw - machhw. */
5758 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
5759 /* machhwo - machhwo. */
5760 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
5761 /* machhws - machhws. */
5762 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
5763 /* machhwso - machhwso. */
5764 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
5765 /* machhwsu - machhwsu. */
5766 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
5767 /* machhwsuo - machhwsuo. */
5768 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
5769 /* machhwu - machhwu. */
5770 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
5771 /* machhwuo - machhwuo. */
5772 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
5773 /* maclhw - maclhw. */
5774 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
5775 /* maclhwo - maclhwo. */
5776 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
5777 /* maclhws - maclhws. */
5778 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
5779 /* maclhwso - maclhwso. */
5780 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
5781 /* maclhwu - maclhwu. */
5782 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
5783 /* maclhwuo - maclhwuo. */
5784 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
5785 /* maclhwsu - maclhwsu. */
5786 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
5787 /* maclhwsuo - maclhwsuo. */
5788 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
5789 /* nmacchw - nmacchw. */
5790 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
5791 /* nmacchwo - nmacchwo. */
5792 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
5793 /* nmacchws - nmacchws. */
5794 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
5795 /* nmacchwso - nmacchwso. */
5796 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
5797 /* nmachhw - nmachhw. */
5798 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
5799 /* nmachhwo - nmachhwo. */
5800 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
5801 /* nmachhws - nmachhws. */
5802 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
5803 /* nmachhwso - nmachhwso. */
5804 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
5805 /* nmaclhw - nmaclhw. */
5806 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
5807 /* nmaclhwo - nmaclhwo. */
5808 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
5809 /* nmaclhws - nmaclhws. */
5810 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
5811 /* nmaclhwso - nmaclhwso. */
5812 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
5814 /* mulchw - mulchw. */
5815 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
5816 /* mulchwu - mulchwu. */
5817 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
5818 /* mulhhw - mulhhw. */
5819 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
5820 /* mulhhwu - mulhhwu. */
5821 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
5822 /* mullhw - mullhw. */
5823 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
5824 /* mullhwu - mullhwu. */
5825 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
5828 static void gen_mfdcr(DisasContext
*ctx
)
5830 #if defined(CONFIG_USER_ONLY)
5831 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5834 if (unlikely(!ctx
->mem_idx
)) {
5835 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5838 /* NIP cannot be restored if the memory exception comes from an helper */
5839 gen_update_nip(ctx
, ctx
->nip
- 4);
5840 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5841 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, dcrn
);
5842 tcg_temp_free(dcrn
);
5847 static void gen_mtdcr(DisasContext
*ctx
)
5849 #if defined(CONFIG_USER_ONLY)
5850 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5853 if (unlikely(!ctx
->mem_idx
)) {
5854 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5857 /* NIP cannot be restored if the memory exception comes from an helper */
5858 gen_update_nip(ctx
, ctx
->nip
- 4);
5859 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5860 gen_helper_store_dcr(cpu_env
, dcrn
, cpu_gpr
[rS(ctx
->opcode
)]);
5861 tcg_temp_free(dcrn
);
5866 /* XXX: not implemented on 440 ? */
5867 static void gen_mfdcrx(DisasContext
*ctx
)
5869 #if defined(CONFIG_USER_ONLY)
5870 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5872 if (unlikely(!ctx
->mem_idx
)) {
5873 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5876 /* NIP cannot be restored if the memory exception comes from an helper */
5877 gen_update_nip(ctx
, ctx
->nip
- 4);
5878 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5879 cpu_gpr
[rA(ctx
->opcode
)]);
5880 /* Note: Rc update flag set leads to undefined state of Rc0 */
5885 /* XXX: not implemented on 440 ? */
5886 static void gen_mtdcrx(DisasContext
*ctx
)
5888 #if defined(CONFIG_USER_ONLY)
5889 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5891 if (unlikely(!ctx
->mem_idx
)) {
5892 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5895 /* NIP cannot be restored if the memory exception comes from an helper */
5896 gen_update_nip(ctx
, ctx
->nip
- 4);
5897 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5898 cpu_gpr
[rS(ctx
->opcode
)]);
5899 /* Note: Rc update flag set leads to undefined state of Rc0 */
5903 /* mfdcrux (PPC 460) : user-mode access to DCR */
5904 static void gen_mfdcrux(DisasContext
*ctx
)
5906 /* NIP cannot be restored if the memory exception comes from an helper */
5907 gen_update_nip(ctx
, ctx
->nip
- 4);
5908 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5909 cpu_gpr
[rA(ctx
->opcode
)]);
5910 /* Note: Rc update flag set leads to undefined state of Rc0 */
5913 /* mtdcrux (PPC 460) : user-mode access to DCR */
5914 static void gen_mtdcrux(DisasContext
*ctx
)
5916 /* NIP cannot be restored if the memory exception comes from an helper */
5917 gen_update_nip(ctx
, ctx
->nip
- 4);
5918 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5919 cpu_gpr
[rS(ctx
->opcode
)]);
5920 /* Note: Rc update flag set leads to undefined state of Rc0 */
5924 static void gen_dccci(DisasContext
*ctx
)
5926 #if defined(CONFIG_USER_ONLY)
5927 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5929 if (unlikely(!ctx
->mem_idx
)) {
5930 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5933 /* interpreted as no-op */
5938 static void gen_dcread(DisasContext
*ctx
)
5940 #if defined(CONFIG_USER_ONLY)
5941 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5944 if (unlikely(!ctx
->mem_idx
)) {
5945 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5948 gen_set_access_type(ctx
, ACCESS_CACHE
);
5949 EA
= tcg_temp_new();
5950 gen_addr_reg_index(ctx
, EA
);
5951 val
= tcg_temp_new();
5952 gen_qemu_ld32u(ctx
, val
, EA
);
5954 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], EA
);
5960 static void gen_icbt_40x(DisasContext
*ctx
)
5962 /* interpreted as no-op */
5963 /* XXX: specification say this is treated as a load by the MMU
5964 * but does not generate any exception
5969 static void gen_iccci(DisasContext
*ctx
)
5971 #if defined(CONFIG_USER_ONLY)
5972 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5974 if (unlikely(!ctx
->mem_idx
)) {
5975 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5978 /* interpreted as no-op */
5983 static void gen_icread(DisasContext
*ctx
)
5985 #if defined(CONFIG_USER_ONLY)
5986 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5988 if (unlikely(!ctx
->mem_idx
)) {
5989 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5992 /* interpreted as no-op */
5996 /* rfci (mem_idx only) */
5997 static void gen_rfci_40x(DisasContext
*ctx
)
5999 #if defined(CONFIG_USER_ONLY)
6000 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6002 if (unlikely(!ctx
->mem_idx
)) {
6003 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6006 /* Restore CPU state */
6007 gen_helper_40x_rfci(cpu_env
);
6008 gen_sync_exception(ctx
);
6012 static void gen_rfci(DisasContext
*ctx
)
6014 #if defined(CONFIG_USER_ONLY)
6015 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6017 if (unlikely(!ctx
->mem_idx
)) {
6018 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6021 /* Restore CPU state */
6022 gen_helper_rfci(cpu_env
);
6023 gen_sync_exception(ctx
);
6027 /* BookE specific */
6029 /* XXX: not implemented on 440 ? */
6030 static void gen_rfdi(DisasContext
*ctx
)
6032 #if defined(CONFIG_USER_ONLY)
6033 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6035 if (unlikely(!ctx
->mem_idx
)) {
6036 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6039 /* Restore CPU state */
6040 gen_helper_rfdi(cpu_env
);
6041 gen_sync_exception(ctx
);
6045 /* XXX: not implemented on 440 ? */
6046 static void gen_rfmci(DisasContext
*ctx
)
6048 #if defined(CONFIG_USER_ONLY)
6049 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6051 if (unlikely(!ctx
->mem_idx
)) {
6052 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6055 /* Restore CPU state */
6056 gen_helper_rfmci(cpu_env
);
6057 gen_sync_exception(ctx
);
6061 /* TLB management - PowerPC 405 implementation */
6064 static void gen_tlbre_40x(DisasContext
*ctx
)
6066 #if defined(CONFIG_USER_ONLY)
6067 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6069 if (unlikely(!ctx
->mem_idx
)) {
6070 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6073 switch (rB(ctx
->opcode
)) {
6075 gen_helper_4xx_tlbre_hi(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6076 cpu_gpr
[rA(ctx
->opcode
)]);
6079 gen_helper_4xx_tlbre_lo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6080 cpu_gpr
[rA(ctx
->opcode
)]);
6083 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6089 /* tlbsx - tlbsx. */
6090 static void gen_tlbsx_40x(DisasContext
*ctx
)
6092 #if defined(CONFIG_USER_ONLY)
6093 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6096 if (unlikely(!ctx
->mem_idx
)) {
6097 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6100 t0
= tcg_temp_new();
6101 gen_addr_reg_index(ctx
, t0
);
6102 gen_helper_4xx_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
6104 if (Rc(ctx
->opcode
)) {
6105 int l1
= gen_new_label();
6106 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
6107 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
6108 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
6115 static void gen_tlbwe_40x(DisasContext
*ctx
)
6117 #if defined(CONFIG_USER_ONLY)
6118 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6120 if (unlikely(!ctx
->mem_idx
)) {
6121 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6124 switch (rB(ctx
->opcode
)) {
6126 gen_helper_4xx_tlbwe_hi(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6127 cpu_gpr
[rS(ctx
->opcode
)]);
6130 gen_helper_4xx_tlbwe_lo(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6131 cpu_gpr
[rS(ctx
->opcode
)]);
6134 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6140 /* TLB management - PowerPC 440 implementation */
6143 static void gen_tlbre_440(DisasContext
*ctx
)
6145 #if defined(CONFIG_USER_ONLY)
6146 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6148 if (unlikely(!ctx
->mem_idx
)) {
6149 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6152 switch (rB(ctx
->opcode
)) {
6157 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
6158 gen_helper_440_tlbre(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6159 t0
, cpu_gpr
[rA(ctx
->opcode
)]);
6160 tcg_temp_free_i32(t0
);
6164 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6170 /* tlbsx - tlbsx. */
6171 static void gen_tlbsx_440(DisasContext
*ctx
)
6173 #if defined(CONFIG_USER_ONLY)
6174 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6177 if (unlikely(!ctx
->mem_idx
)) {
6178 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6181 t0
= tcg_temp_new();
6182 gen_addr_reg_index(ctx
, t0
);
6183 gen_helper_440_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
6185 if (Rc(ctx
->opcode
)) {
6186 int l1
= gen_new_label();
6187 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
6188 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
6189 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
6196 static void gen_tlbwe_440(DisasContext
*ctx
)
6198 #if defined(CONFIG_USER_ONLY)
6199 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6201 if (unlikely(!ctx
->mem_idx
)) {
6202 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6205 switch (rB(ctx
->opcode
)) {
6210 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
6211 gen_helper_440_tlbwe(cpu_env
, t0
, cpu_gpr
[rA(ctx
->opcode
)],
6212 cpu_gpr
[rS(ctx
->opcode
)]);
6213 tcg_temp_free_i32(t0
);
6217 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6223 /* TLB management - PowerPC BookE 2.06 implementation */
6226 static void gen_tlbre_booke206(DisasContext
*ctx
)
6228 #if defined(CONFIG_USER_ONLY)
6229 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6231 if (unlikely(!ctx
->mem_idx
)) {
6232 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6236 gen_helper_booke206_tlbre(cpu_env
);
6240 /* tlbsx - tlbsx. */
6241 static void gen_tlbsx_booke206(DisasContext
*ctx
)
6243 #if defined(CONFIG_USER_ONLY)
6244 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6247 if (unlikely(!ctx
->mem_idx
)) {
6248 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6252 if (rA(ctx
->opcode
)) {
6253 t0
= tcg_temp_new();
6254 tcg_gen_mov_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)]);
6256 t0
= tcg_const_tl(0);
6259 tcg_gen_add_tl(t0
, t0
, cpu_gpr
[rB(ctx
->opcode
)]);
6260 gen_helper_booke206_tlbsx(cpu_env
, t0
);
6265 static void gen_tlbwe_booke206(DisasContext
*ctx
)
6267 #if defined(CONFIG_USER_ONLY)
6268 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6270 if (unlikely(!ctx
->mem_idx
)) {
6271 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6274 gen_update_nip(ctx
, ctx
->nip
- 4);
6275 gen_helper_booke206_tlbwe(cpu_env
);
6279 static void gen_tlbivax_booke206(DisasContext
*ctx
)
6281 #if defined(CONFIG_USER_ONLY)
6282 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6285 if (unlikely(!ctx
->mem_idx
)) {
6286 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6290 t0
= tcg_temp_new();
6291 gen_addr_reg_index(ctx
, t0
);
6293 gen_helper_booke206_tlbivax(cpu_env
, t0
);
6297 static void gen_tlbilx_booke206(DisasContext
*ctx
)
6299 #if defined(CONFIG_USER_ONLY)
6300 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6303 if (unlikely(!ctx
->mem_idx
)) {
6304 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6308 t0
= tcg_temp_new();
6309 gen_addr_reg_index(ctx
, t0
);
6311 switch((ctx
->opcode
>> 21) & 0x3) {
6313 gen_helper_booke206_tlbilx0(cpu_env
, t0
);
6316 gen_helper_booke206_tlbilx1(cpu_env
, t0
);
6319 gen_helper_booke206_tlbilx3(cpu_env
, t0
);
6322 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6332 static void gen_wrtee(DisasContext
*ctx
)
6334 #if defined(CONFIG_USER_ONLY)
6335 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6338 if (unlikely(!ctx
->mem_idx
)) {
6339 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6342 t0
= tcg_temp_new();
6343 tcg_gen_andi_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)], (1 << MSR_EE
));
6344 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6345 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
6347 /* Stop translation to have a chance to raise an exception
6348 * if we just set msr_ee to 1
6350 gen_stop_exception(ctx
);
6355 static void gen_wrteei(DisasContext
*ctx
)
6357 #if defined(CONFIG_USER_ONLY)
6358 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6360 if (unlikely(!ctx
->mem_idx
)) {
6361 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6364 if (ctx
->opcode
& 0x00008000) {
6365 tcg_gen_ori_tl(cpu_msr
, cpu_msr
, (1 << MSR_EE
));
6366 /* Stop translation to have a chance to raise an exception */
6367 gen_stop_exception(ctx
);
6369 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6374 /* PowerPC 440 specific instructions */
6377 static void gen_dlmzb(DisasContext
*ctx
)
6379 TCGv_i32 t0
= tcg_const_i32(Rc(ctx
->opcode
));
6380 gen_helper_dlmzb(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
6381 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
6382 tcg_temp_free_i32(t0
);
6385 /* mbar replaces eieio on 440 */
6386 static void gen_mbar(DisasContext
*ctx
)
6388 /* interpreted as no-op */
6391 /* msync replaces sync on 440 */
6392 static void gen_msync_4xx(DisasContext
*ctx
)
6394 /* interpreted as no-op */
6398 static void gen_icbt_440(DisasContext
*ctx
)
6400 /* interpreted as no-op */
6401 /* XXX: specification say this is treated as a load by the MMU
6402 * but does not generate any exception
6406 /* Embedded.Processor Control */
6408 static void gen_msgclr(DisasContext
*ctx
)
6410 #if defined(CONFIG_USER_ONLY)
6411 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6413 if (unlikely(ctx
->mem_idx
== 0)) {
6414 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6418 gen_helper_msgclr(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6422 static void gen_msgsnd(DisasContext
*ctx
)
6424 #if defined(CONFIG_USER_ONLY)
6425 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6427 if (unlikely(ctx
->mem_idx
== 0)) {
6428 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6432 gen_helper_msgsnd(cpu_gpr
[rB(ctx
->opcode
)]);
6436 /*** Altivec vector extension ***/
6437 /* Altivec registers moves */
6439 static inline TCGv_ptr
gen_avr_ptr(int reg
)
6441 TCGv_ptr r
= tcg_temp_new_ptr();
6442 tcg_gen_addi_ptr(r
, cpu_env
, offsetof(CPUPPCState
, avr
[reg
]));
6446 #define GEN_VR_LDX(name, opc2, opc3) \
6447 static void glue(gen_, name)(DisasContext *ctx) \
6450 if (unlikely(!ctx->altivec_enabled)) { \
6451 gen_exception(ctx, POWERPC_EXCP_VPU); \
6454 gen_set_access_type(ctx, ACCESS_INT); \
6455 EA = tcg_temp_new(); \
6456 gen_addr_reg_index(ctx, EA); \
6457 tcg_gen_andi_tl(EA, EA, ~0xf); \
6458 if (ctx->le_mode) { \
6459 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6460 tcg_gen_addi_tl(EA, EA, 8); \
6461 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6463 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6464 tcg_gen_addi_tl(EA, EA, 8); \
6465 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6467 tcg_temp_free(EA); \
6470 #define GEN_VR_STX(name, opc2, opc3) \
6471 static void gen_st##name(DisasContext *ctx) \
6474 if (unlikely(!ctx->altivec_enabled)) { \
6475 gen_exception(ctx, POWERPC_EXCP_VPU); \
6478 gen_set_access_type(ctx, ACCESS_INT); \
6479 EA = tcg_temp_new(); \
6480 gen_addr_reg_index(ctx, EA); \
6481 tcg_gen_andi_tl(EA, EA, ~0xf); \
6482 if (ctx->le_mode) { \
6483 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6484 tcg_gen_addi_tl(EA, EA, 8); \
6485 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6487 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6488 tcg_gen_addi_tl(EA, EA, 8); \
6489 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6491 tcg_temp_free(EA); \
6494 #define GEN_VR_LVE(name, opc2, opc3) \
6495 static void gen_lve##name(DisasContext *ctx) \
6499 if (unlikely(!ctx->altivec_enabled)) { \
6500 gen_exception(ctx, POWERPC_EXCP_VPU); \
6503 gen_set_access_type(ctx, ACCESS_INT); \
6504 EA = tcg_temp_new(); \
6505 gen_addr_reg_index(ctx, EA); \
6506 rs = gen_avr_ptr(rS(ctx->opcode)); \
6507 gen_helper_lve##name(cpu_env, rs, EA); \
6508 tcg_temp_free(EA); \
6509 tcg_temp_free_ptr(rs); \
6512 #define GEN_VR_STVE(name, opc2, opc3) \
6513 static void gen_stve##name(DisasContext *ctx) \
6517 if (unlikely(!ctx->altivec_enabled)) { \
6518 gen_exception(ctx, POWERPC_EXCP_VPU); \
6521 gen_set_access_type(ctx, ACCESS_INT); \
6522 EA = tcg_temp_new(); \
6523 gen_addr_reg_index(ctx, EA); \
6524 rs = gen_avr_ptr(rS(ctx->opcode)); \
6525 gen_helper_stve##name(cpu_env, rs, EA); \
6526 tcg_temp_free(EA); \
6527 tcg_temp_free_ptr(rs); \
6530 GEN_VR_LDX(lvx
, 0x07, 0x03);
6531 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
6532 GEN_VR_LDX(lvxl
, 0x07, 0x0B);
6534 GEN_VR_LVE(bx
, 0x07, 0x00);
6535 GEN_VR_LVE(hx
, 0x07, 0x01);
6536 GEN_VR_LVE(wx
, 0x07, 0x02);
6538 GEN_VR_STX(svx
, 0x07, 0x07);
6539 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
6540 GEN_VR_STX(svxl
, 0x07, 0x0F);
6542 GEN_VR_STVE(bx
, 0x07, 0x04);
6543 GEN_VR_STVE(hx
, 0x07, 0x05);
6544 GEN_VR_STVE(wx
, 0x07, 0x06);
6546 static void gen_lvsl(DisasContext
*ctx
)
6550 if (unlikely(!ctx
->altivec_enabled
)) {
6551 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6554 EA
= tcg_temp_new();
6555 gen_addr_reg_index(ctx
, EA
);
6556 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6557 gen_helper_lvsl(rd
, EA
);
6559 tcg_temp_free_ptr(rd
);
6562 static void gen_lvsr(DisasContext
*ctx
)
6566 if (unlikely(!ctx
->altivec_enabled
)) {
6567 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6570 EA
= tcg_temp_new();
6571 gen_addr_reg_index(ctx
, EA
);
6572 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6573 gen_helper_lvsr(rd
, EA
);
6575 tcg_temp_free_ptr(rd
);
6578 static void gen_mfvscr(DisasContext
*ctx
)
6581 if (unlikely(!ctx
->altivec_enabled
)) {
6582 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6585 tcg_gen_movi_i64(cpu_avrh
[rD(ctx
->opcode
)], 0);
6586 t
= tcg_temp_new_i32();
6587 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUPPCState
, vscr
));
6588 tcg_gen_extu_i32_i64(cpu_avrl
[rD(ctx
->opcode
)], t
);
6589 tcg_temp_free_i32(t
);
6592 static void gen_mtvscr(DisasContext
*ctx
)
6595 if (unlikely(!ctx
->altivec_enabled
)) {
6596 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6599 p
= gen_avr_ptr(rD(ctx
->opcode
));
6600 gen_helper_mtvscr(cpu_env
, p
);
6601 tcg_temp_free_ptr(p
);
6604 /* Logical operations */
6605 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
6606 static void glue(gen_, name)(DisasContext *ctx) \
6608 if (unlikely(!ctx->altivec_enabled)) { \
6609 gen_exception(ctx, POWERPC_EXCP_VPU); \
6612 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6613 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6616 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16);
6617 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17);
6618 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18);
6619 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19);
6620 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20);
6622 #define GEN_VXFORM(name, opc2, opc3) \
6623 static void glue(gen_, name)(DisasContext *ctx) \
6625 TCGv_ptr ra, rb, rd; \
6626 if (unlikely(!ctx->altivec_enabled)) { \
6627 gen_exception(ctx, POWERPC_EXCP_VPU); \
6630 ra = gen_avr_ptr(rA(ctx->opcode)); \
6631 rb = gen_avr_ptr(rB(ctx->opcode)); \
6632 rd = gen_avr_ptr(rD(ctx->opcode)); \
6633 gen_helper_##name (rd, ra, rb); \
6634 tcg_temp_free_ptr(ra); \
6635 tcg_temp_free_ptr(rb); \
6636 tcg_temp_free_ptr(rd); \
6639 #define GEN_VXFORM_ENV(name, opc2, opc3) \
6640 static void glue(gen_, name)(DisasContext *ctx) \
6642 TCGv_ptr ra, rb, rd; \
6643 if (unlikely(!ctx->altivec_enabled)) { \
6644 gen_exception(ctx, POWERPC_EXCP_VPU); \
6647 ra = gen_avr_ptr(rA(ctx->opcode)); \
6648 rb = gen_avr_ptr(rB(ctx->opcode)); \
6649 rd = gen_avr_ptr(rD(ctx->opcode)); \
6650 gen_helper_##name(cpu_env, rd, ra, rb); \
6651 tcg_temp_free_ptr(ra); \
6652 tcg_temp_free_ptr(rb); \
6653 tcg_temp_free_ptr(rd); \
6656 GEN_VXFORM(vaddubm
, 0, 0);
6657 GEN_VXFORM(vadduhm
, 0, 1);
6658 GEN_VXFORM(vadduwm
, 0, 2);
6659 GEN_VXFORM(vsububm
, 0, 16);
6660 GEN_VXFORM(vsubuhm
, 0, 17);
6661 GEN_VXFORM(vsubuwm
, 0, 18);
6662 GEN_VXFORM(vmaxub
, 1, 0);
6663 GEN_VXFORM(vmaxuh
, 1, 1);
6664 GEN_VXFORM(vmaxuw
, 1, 2);
6665 GEN_VXFORM(vmaxsb
, 1, 4);
6666 GEN_VXFORM(vmaxsh
, 1, 5);
6667 GEN_VXFORM(vmaxsw
, 1, 6);
6668 GEN_VXFORM(vminub
, 1, 8);
6669 GEN_VXFORM(vminuh
, 1, 9);
6670 GEN_VXFORM(vminuw
, 1, 10);
6671 GEN_VXFORM(vminsb
, 1, 12);
6672 GEN_VXFORM(vminsh
, 1, 13);
6673 GEN_VXFORM(vminsw
, 1, 14);
6674 GEN_VXFORM(vavgub
, 1, 16);
6675 GEN_VXFORM(vavguh
, 1, 17);
6676 GEN_VXFORM(vavguw
, 1, 18);
6677 GEN_VXFORM(vavgsb
, 1, 20);
6678 GEN_VXFORM(vavgsh
, 1, 21);
6679 GEN_VXFORM(vavgsw
, 1, 22);
6680 GEN_VXFORM(vmrghb
, 6, 0);
6681 GEN_VXFORM(vmrghh
, 6, 1);
6682 GEN_VXFORM(vmrghw
, 6, 2);
6683 GEN_VXFORM(vmrglb
, 6, 4);
6684 GEN_VXFORM(vmrglh
, 6, 5);
6685 GEN_VXFORM(vmrglw
, 6, 6);
6686 GEN_VXFORM(vmuloub
, 4, 0);
6687 GEN_VXFORM(vmulouh
, 4, 1);
6688 GEN_VXFORM(vmulosb
, 4, 4);
6689 GEN_VXFORM(vmulosh
, 4, 5);
6690 GEN_VXFORM(vmuleub
, 4, 8);
6691 GEN_VXFORM(vmuleuh
, 4, 9);
6692 GEN_VXFORM(vmulesb
, 4, 12);
6693 GEN_VXFORM(vmulesh
, 4, 13);
6694 GEN_VXFORM(vslb
, 2, 4);
6695 GEN_VXFORM(vslh
, 2, 5);
6696 GEN_VXFORM(vslw
, 2, 6);
6697 GEN_VXFORM(vsrb
, 2, 8);
6698 GEN_VXFORM(vsrh
, 2, 9);
6699 GEN_VXFORM(vsrw
, 2, 10);
6700 GEN_VXFORM(vsrab
, 2, 12);
6701 GEN_VXFORM(vsrah
, 2, 13);
6702 GEN_VXFORM(vsraw
, 2, 14);
6703 GEN_VXFORM(vslo
, 6, 16);
6704 GEN_VXFORM(vsro
, 6, 17);
6705 GEN_VXFORM(vaddcuw
, 0, 6);
6706 GEN_VXFORM(vsubcuw
, 0, 22);
6707 GEN_VXFORM_ENV(vaddubs
, 0, 8);
6708 GEN_VXFORM_ENV(vadduhs
, 0, 9);
6709 GEN_VXFORM_ENV(vadduws
, 0, 10);
6710 GEN_VXFORM_ENV(vaddsbs
, 0, 12);
6711 GEN_VXFORM_ENV(vaddshs
, 0, 13);
6712 GEN_VXFORM_ENV(vaddsws
, 0, 14);
6713 GEN_VXFORM_ENV(vsububs
, 0, 24);
6714 GEN_VXFORM_ENV(vsubuhs
, 0, 25);
6715 GEN_VXFORM_ENV(vsubuws
, 0, 26);
6716 GEN_VXFORM_ENV(vsubsbs
, 0, 28);
6717 GEN_VXFORM_ENV(vsubshs
, 0, 29);
6718 GEN_VXFORM_ENV(vsubsws
, 0, 30);
6719 GEN_VXFORM(vrlb
, 2, 0);
6720 GEN_VXFORM(vrlh
, 2, 1);
6721 GEN_VXFORM(vrlw
, 2, 2);
6722 GEN_VXFORM(vsl
, 2, 7);
6723 GEN_VXFORM(vsr
, 2, 11);
6724 GEN_VXFORM_ENV(vpkuhum
, 7, 0);
6725 GEN_VXFORM_ENV(vpkuwum
, 7, 1);
6726 GEN_VXFORM_ENV(vpkuhus
, 7, 2);
6727 GEN_VXFORM_ENV(vpkuwus
, 7, 3);
6728 GEN_VXFORM_ENV(vpkshus
, 7, 4);
6729 GEN_VXFORM_ENV(vpkswus
, 7, 5);
6730 GEN_VXFORM_ENV(vpkshss
, 7, 6);
6731 GEN_VXFORM_ENV(vpkswss
, 7, 7);
6732 GEN_VXFORM(vpkpx
, 7, 12);
6733 GEN_VXFORM_ENV(vsum4ubs
, 4, 24);
6734 GEN_VXFORM_ENV(vsum4sbs
, 4, 28);
6735 GEN_VXFORM_ENV(vsum4shs
, 4, 25);
6736 GEN_VXFORM_ENV(vsum2sws
, 4, 26);
6737 GEN_VXFORM_ENV(vsumsws
, 4, 30);
6738 GEN_VXFORM_ENV(vaddfp
, 5, 0);
6739 GEN_VXFORM_ENV(vsubfp
, 5, 1);
6740 GEN_VXFORM_ENV(vmaxfp
, 5, 16);
6741 GEN_VXFORM_ENV(vminfp
, 5, 17);
6743 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
6744 static void glue(gen_, name)(DisasContext *ctx) \
6746 TCGv_ptr ra, rb, rd; \
6747 if (unlikely(!ctx->altivec_enabled)) { \
6748 gen_exception(ctx, POWERPC_EXCP_VPU); \
6751 ra = gen_avr_ptr(rA(ctx->opcode)); \
6752 rb = gen_avr_ptr(rB(ctx->opcode)); \
6753 rd = gen_avr_ptr(rD(ctx->opcode)); \
6754 gen_helper_##opname(cpu_env, rd, ra, rb); \
6755 tcg_temp_free_ptr(ra); \
6756 tcg_temp_free_ptr(rb); \
6757 tcg_temp_free_ptr(rd); \
6760 #define GEN_VXRFORM(name, opc2, opc3) \
6761 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
6762 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
6764 GEN_VXRFORM(vcmpequb
, 3, 0)
6765 GEN_VXRFORM(vcmpequh
, 3, 1)
6766 GEN_VXRFORM(vcmpequw
, 3, 2)
6767 GEN_VXRFORM(vcmpgtsb
, 3, 12)
6768 GEN_VXRFORM(vcmpgtsh
, 3, 13)
6769 GEN_VXRFORM(vcmpgtsw
, 3, 14)
6770 GEN_VXRFORM(vcmpgtub
, 3, 8)
6771 GEN_VXRFORM(vcmpgtuh
, 3, 9)
6772 GEN_VXRFORM(vcmpgtuw
, 3, 10)
6773 GEN_VXRFORM(vcmpeqfp
, 3, 3)
6774 GEN_VXRFORM(vcmpgefp
, 3, 7)
6775 GEN_VXRFORM(vcmpgtfp
, 3, 11)
6776 GEN_VXRFORM(vcmpbfp
, 3, 15)
6778 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
6779 static void glue(gen_, name)(DisasContext *ctx) \
6783 if (unlikely(!ctx->altivec_enabled)) { \
6784 gen_exception(ctx, POWERPC_EXCP_VPU); \
6787 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6788 rd = gen_avr_ptr(rD(ctx->opcode)); \
6789 gen_helper_##name (rd, simm); \
6790 tcg_temp_free_i32(simm); \
6791 tcg_temp_free_ptr(rd); \
6794 GEN_VXFORM_SIMM(vspltisb
, 6, 12);
6795 GEN_VXFORM_SIMM(vspltish
, 6, 13);
6796 GEN_VXFORM_SIMM(vspltisw
, 6, 14);
6798 #define GEN_VXFORM_NOA(name, opc2, opc3) \
6799 static void glue(gen_, name)(DisasContext *ctx) \
6802 if (unlikely(!ctx->altivec_enabled)) { \
6803 gen_exception(ctx, POWERPC_EXCP_VPU); \
6806 rb = gen_avr_ptr(rB(ctx->opcode)); \
6807 rd = gen_avr_ptr(rD(ctx->opcode)); \
6808 gen_helper_##name (rd, rb); \
6809 tcg_temp_free_ptr(rb); \
6810 tcg_temp_free_ptr(rd); \
6813 #define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
6814 static void glue(gen_, name)(DisasContext *ctx) \
6818 if (unlikely(!ctx->altivec_enabled)) { \
6819 gen_exception(ctx, POWERPC_EXCP_VPU); \
6822 rb = gen_avr_ptr(rB(ctx->opcode)); \
6823 rd = gen_avr_ptr(rD(ctx->opcode)); \
6824 gen_helper_##name(cpu_env, rd, rb); \
6825 tcg_temp_free_ptr(rb); \
6826 tcg_temp_free_ptr(rd); \
6829 GEN_VXFORM_NOA(vupkhsb
, 7, 8);
6830 GEN_VXFORM_NOA(vupkhsh
, 7, 9);
6831 GEN_VXFORM_NOA(vupklsb
, 7, 10);
6832 GEN_VXFORM_NOA(vupklsh
, 7, 11);
6833 GEN_VXFORM_NOA(vupkhpx
, 7, 13);
6834 GEN_VXFORM_NOA(vupklpx
, 7, 15);
6835 GEN_VXFORM_NOA_ENV(vrefp
, 5, 4);
6836 GEN_VXFORM_NOA_ENV(vrsqrtefp
, 5, 5);
6837 GEN_VXFORM_NOA_ENV(vexptefp
, 5, 6);
6838 GEN_VXFORM_NOA_ENV(vlogefp
, 5, 7);
6839 GEN_VXFORM_NOA_ENV(vrfim
, 5, 8);
6840 GEN_VXFORM_NOA_ENV(vrfin
, 5, 9);
6841 GEN_VXFORM_NOA_ENV(vrfip
, 5, 10);
6842 GEN_VXFORM_NOA_ENV(vrfiz
, 5, 11);
6844 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
6845 static void glue(gen_, name)(DisasContext *ctx) \
6849 if (unlikely(!ctx->altivec_enabled)) { \
6850 gen_exception(ctx, POWERPC_EXCP_VPU); \
6853 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6854 rd = gen_avr_ptr(rD(ctx->opcode)); \
6855 gen_helper_##name (rd, simm); \
6856 tcg_temp_free_i32(simm); \
6857 tcg_temp_free_ptr(rd); \
6860 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
6861 static void glue(gen_, name)(DisasContext *ctx) \
6865 if (unlikely(!ctx->altivec_enabled)) { \
6866 gen_exception(ctx, POWERPC_EXCP_VPU); \
6869 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
6870 rb = gen_avr_ptr(rB(ctx->opcode)); \
6871 rd = gen_avr_ptr(rD(ctx->opcode)); \
6872 gen_helper_##name (rd, rb, uimm); \
6873 tcg_temp_free_i32(uimm); \
6874 tcg_temp_free_ptr(rb); \
6875 tcg_temp_free_ptr(rd); \
6878 #define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
6879 static void glue(gen_, name)(DisasContext *ctx) \
6884 if (unlikely(!ctx->altivec_enabled)) { \
6885 gen_exception(ctx, POWERPC_EXCP_VPU); \
6888 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
6889 rb = gen_avr_ptr(rB(ctx->opcode)); \
6890 rd = gen_avr_ptr(rD(ctx->opcode)); \
6891 gen_helper_##name(cpu_env, rd, rb, uimm); \
6892 tcg_temp_free_i32(uimm); \
6893 tcg_temp_free_ptr(rb); \
6894 tcg_temp_free_ptr(rd); \
6897 GEN_VXFORM_UIMM(vspltb
, 6, 8);
6898 GEN_VXFORM_UIMM(vsplth
, 6, 9);
6899 GEN_VXFORM_UIMM(vspltw
, 6, 10);
6900 GEN_VXFORM_UIMM_ENV(vcfux
, 5, 12);
6901 GEN_VXFORM_UIMM_ENV(vcfsx
, 5, 13);
6902 GEN_VXFORM_UIMM_ENV(vctuxs
, 5, 14);
6903 GEN_VXFORM_UIMM_ENV(vctsxs
, 5, 15);
6905 static void gen_vsldoi(DisasContext
*ctx
)
6907 TCGv_ptr ra
, rb
, rd
;
6909 if (unlikely(!ctx
->altivec_enabled
)) {
6910 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6913 ra
= gen_avr_ptr(rA(ctx
->opcode
));
6914 rb
= gen_avr_ptr(rB(ctx
->opcode
));
6915 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6916 sh
= tcg_const_i32(VSH(ctx
->opcode
));
6917 gen_helper_vsldoi (rd
, ra
, rb
, sh
);
6918 tcg_temp_free_ptr(ra
);
6919 tcg_temp_free_ptr(rb
);
6920 tcg_temp_free_ptr(rd
);
6921 tcg_temp_free_i32(sh
);
6924 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
6925 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
6927 TCGv_ptr ra, rb, rc, rd; \
6928 if (unlikely(!ctx->altivec_enabled)) { \
6929 gen_exception(ctx, POWERPC_EXCP_VPU); \
6932 ra = gen_avr_ptr(rA(ctx->opcode)); \
6933 rb = gen_avr_ptr(rB(ctx->opcode)); \
6934 rc = gen_avr_ptr(rC(ctx->opcode)); \
6935 rd = gen_avr_ptr(rD(ctx->opcode)); \
6936 if (Rc(ctx->opcode)) { \
6937 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
6939 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
6941 tcg_temp_free_ptr(ra); \
6942 tcg_temp_free_ptr(rb); \
6943 tcg_temp_free_ptr(rc); \
6944 tcg_temp_free_ptr(rd); \
6947 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16)
6949 static void gen_vmladduhm(DisasContext
*ctx
)
6951 TCGv_ptr ra
, rb
, rc
, rd
;
6952 if (unlikely(!ctx
->altivec_enabled
)) {
6953 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6956 ra
= gen_avr_ptr(rA(ctx
->opcode
));
6957 rb
= gen_avr_ptr(rB(ctx
->opcode
));
6958 rc
= gen_avr_ptr(rC(ctx
->opcode
));
6959 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6960 gen_helper_vmladduhm(rd
, ra
, rb
, rc
);
6961 tcg_temp_free_ptr(ra
);
6962 tcg_temp_free_ptr(rb
);
6963 tcg_temp_free_ptr(rc
);
6964 tcg_temp_free_ptr(rd
);
6967 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18)
6968 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19)
6969 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20)
6970 GEN_VAFORM_PAIRED(vsel
, vperm
, 21)
6971 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23)
6973 /*** SPE extension ***/
6974 /* Register moves */
6977 static inline void gen_evmra(DisasContext
*ctx
)
6980 if (unlikely(!ctx
->spe_enabled
)) {
6981 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
6985 #if defined(TARGET_PPC64)
6987 tcg_gen_mov_i64(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6990 tcg_gen_st_i64(cpu_gpr
[rA(ctx
->opcode
)],
6992 offsetof(CPUPPCState
, spe_acc
));
6994 TCGv_i64 tmp
= tcg_temp_new_i64();
6996 /* tmp := rA_lo + rA_hi << 32 */
6997 tcg_gen_concat_i32_i64(tmp
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6999 /* spe_acc := tmp */
7000 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7001 tcg_temp_free_i64(tmp
);
7004 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7005 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7009 static inline void gen_load_gpr64(TCGv_i64 t
, int reg
)
7011 #if defined(TARGET_PPC64)
7012 tcg_gen_mov_i64(t
, cpu_gpr
[reg
]);
7014 tcg_gen_concat_i32_i64(t
, cpu_gpr
[reg
], cpu_gprh
[reg
]);
7018 static inline void gen_store_gpr64(int reg
, TCGv_i64 t
)
7020 #if defined(TARGET_PPC64)
7021 tcg_gen_mov_i64(cpu_gpr
[reg
], t
);
7023 TCGv_i64 tmp
= tcg_temp_new_i64();
7024 tcg_gen_trunc_i64_i32(cpu_gpr
[reg
], t
);
7025 tcg_gen_shri_i64(tmp
, t
, 32);
7026 tcg_gen_trunc_i64_i32(cpu_gprh
[reg
], tmp
);
7027 tcg_temp_free_i64(tmp
);
7031 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
7032 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7034 if (Rc(ctx->opcode)) \
7040 /* Handler for undefined SPE opcodes */
7041 static inline void gen_speundef(DisasContext
*ctx
)
7043 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
7047 #if defined(TARGET_PPC64)
7048 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
7049 static inline void gen_##name(DisasContext *ctx) \
7051 if (unlikely(!ctx->spe_enabled)) { \
7052 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7055 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7056 cpu_gpr[rB(ctx->opcode)]); \
7059 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
7060 static inline void gen_##name(DisasContext *ctx) \
7062 if (unlikely(!ctx->spe_enabled)) { \
7063 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7066 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7067 cpu_gpr[rB(ctx->opcode)]); \
7068 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7069 cpu_gprh[rB(ctx->opcode)]); \
7073 GEN_SPEOP_LOGIC2(evand
, tcg_gen_and_tl
);
7074 GEN_SPEOP_LOGIC2(evandc
, tcg_gen_andc_tl
);
7075 GEN_SPEOP_LOGIC2(evxor
, tcg_gen_xor_tl
);
7076 GEN_SPEOP_LOGIC2(evor
, tcg_gen_or_tl
);
7077 GEN_SPEOP_LOGIC2(evnor
, tcg_gen_nor_tl
);
7078 GEN_SPEOP_LOGIC2(eveqv
, tcg_gen_eqv_tl
);
7079 GEN_SPEOP_LOGIC2(evorc
, tcg_gen_orc_tl
);
7080 GEN_SPEOP_LOGIC2(evnand
, tcg_gen_nand_tl
);
7082 /* SPE logic immediate */
7083 #if defined(TARGET_PPC64)
7084 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
7085 static inline void gen_##name(DisasContext *ctx) \
7087 if (unlikely(!ctx->spe_enabled)) { \
7088 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7091 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7092 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7093 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7094 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7095 tcg_opi(t0, t0, rB(ctx->opcode)); \
7096 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7097 tcg_gen_trunc_i64_i32(t1, t2); \
7098 tcg_temp_free_i64(t2); \
7099 tcg_opi(t1, t1, rB(ctx->opcode)); \
7100 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7101 tcg_temp_free_i32(t0); \
7102 tcg_temp_free_i32(t1); \
7105 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
7106 static inline void gen_##name(DisasContext *ctx) \
7108 if (unlikely(!ctx->spe_enabled)) { \
7109 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7112 tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7114 tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7118 GEN_SPEOP_TCG_LOGIC_IMM2(evslwi
, tcg_gen_shli_i32
);
7119 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu
, tcg_gen_shri_i32
);
7120 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis
, tcg_gen_sari_i32
);
7121 GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi
, tcg_gen_rotli_i32
);
7123 /* SPE arithmetic */
7124 #if defined(TARGET_PPC64)
7125 #define GEN_SPEOP_ARITH1(name, tcg_op) \
7126 static inline void gen_##name(DisasContext *ctx) \
7128 if (unlikely(!ctx->spe_enabled)) { \
7129 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7132 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7133 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7134 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7135 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7137 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7138 tcg_gen_trunc_i64_i32(t1, t2); \
7139 tcg_temp_free_i64(t2); \
7141 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7142 tcg_temp_free_i32(t0); \
7143 tcg_temp_free_i32(t1); \
7146 #define GEN_SPEOP_ARITH1(name, tcg_op) \
7147 static inline void gen_##name(DisasContext *ctx) \
7149 if (unlikely(!ctx->spe_enabled)) { \
7150 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7153 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
7154 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
7158 static inline void gen_op_evabs(TCGv_i32 ret
, TCGv_i32 arg1
)
7160 int l1
= gen_new_label();
7161 int l2
= gen_new_label();
7163 tcg_gen_brcondi_i32(TCG_COND_GE
, arg1
, 0, l1
);
7164 tcg_gen_neg_i32(ret
, arg1
);
7167 tcg_gen_mov_i32(ret
, arg1
);
7170 GEN_SPEOP_ARITH1(evabs
, gen_op_evabs
);
7171 GEN_SPEOP_ARITH1(evneg
, tcg_gen_neg_i32
);
7172 GEN_SPEOP_ARITH1(evextsb
, tcg_gen_ext8s_i32
);
7173 GEN_SPEOP_ARITH1(evextsh
, tcg_gen_ext16s_i32
);
7174 static inline void gen_op_evrndw(TCGv_i32 ret
, TCGv_i32 arg1
)
7176 tcg_gen_addi_i32(ret
, arg1
, 0x8000);
7177 tcg_gen_ext16u_i32(ret
, ret
);
7179 GEN_SPEOP_ARITH1(evrndw
, gen_op_evrndw
);
7180 GEN_SPEOP_ARITH1(evcntlsw
, gen_helper_cntlsw32
);
7181 GEN_SPEOP_ARITH1(evcntlzw
, gen_helper_cntlzw32
);
7183 #if defined(TARGET_PPC64)
7184 #define GEN_SPEOP_ARITH2(name, tcg_op) \
7185 static inline void gen_##name(DisasContext *ctx) \
7187 if (unlikely(!ctx->spe_enabled)) { \
7188 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7191 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7192 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7193 TCGv_i32 t2 = tcg_temp_local_new_i32(); \
7194 TCGv_i64 t3 = tcg_temp_local_new_i64(); \
7195 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7196 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
7197 tcg_op(t0, t0, t2); \
7198 tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
7199 tcg_gen_trunc_i64_i32(t1, t3); \
7200 tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
7201 tcg_gen_trunc_i64_i32(t2, t3); \
7202 tcg_temp_free_i64(t3); \
7203 tcg_op(t1, t1, t2); \
7204 tcg_temp_free_i32(t2); \
7205 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7206 tcg_temp_free_i32(t0); \
7207 tcg_temp_free_i32(t1); \
7210 #define GEN_SPEOP_ARITH2(name, tcg_op) \
7211 static inline void gen_##name(DisasContext *ctx) \
7213 if (unlikely(!ctx->spe_enabled)) { \
7214 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7217 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7218 cpu_gpr[rB(ctx->opcode)]); \
7219 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7220 cpu_gprh[rB(ctx->opcode)]); \
7224 static inline void gen_op_evsrwu(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7229 l1
= gen_new_label();
7230 l2
= gen_new_label();
7231 t0
= tcg_temp_local_new_i32();
7232 /* No error here: 6 bits are used */
7233 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
7234 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
7235 tcg_gen_shr_i32(ret
, arg1
, t0
);
7238 tcg_gen_movi_i32(ret
, 0);
7240 tcg_temp_free_i32(t0
);
7242 GEN_SPEOP_ARITH2(evsrwu
, gen_op_evsrwu
);
7243 static inline void gen_op_evsrws(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7248 l1
= gen_new_label();
7249 l2
= gen_new_label();
7250 t0
= tcg_temp_local_new_i32();
7251 /* No error here: 6 bits are used */
7252 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
7253 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
7254 tcg_gen_sar_i32(ret
, arg1
, t0
);
7257 tcg_gen_movi_i32(ret
, 0);
7259 tcg_temp_free_i32(t0
);
7261 GEN_SPEOP_ARITH2(evsrws
, gen_op_evsrws
);
7262 static inline void gen_op_evslw(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7267 l1
= gen_new_label();
7268 l2
= gen_new_label();
7269 t0
= tcg_temp_local_new_i32();
7270 /* No error here: 6 bits are used */
7271 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
7272 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
7273 tcg_gen_shl_i32(ret
, arg1
, t0
);
7276 tcg_gen_movi_i32(ret
, 0);
7278 tcg_temp_free_i32(t0
);
7280 GEN_SPEOP_ARITH2(evslw
, gen_op_evslw
);
7281 static inline void gen_op_evrlw(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7283 TCGv_i32 t0
= tcg_temp_new_i32();
7284 tcg_gen_andi_i32(t0
, arg2
, 0x1F);
7285 tcg_gen_rotl_i32(ret
, arg1
, t0
);
7286 tcg_temp_free_i32(t0
);
7288 GEN_SPEOP_ARITH2(evrlw
, gen_op_evrlw
);
7289 static inline void gen_evmergehi(DisasContext
*ctx
)
7291 if (unlikely(!ctx
->spe_enabled
)) {
7292 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7295 #if defined(TARGET_PPC64)
7296 TCGv t0
= tcg_temp_new();
7297 TCGv t1
= tcg_temp_new();
7298 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
7299 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
7300 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7304 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7305 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7308 GEN_SPEOP_ARITH2(evaddw
, tcg_gen_add_i32
);
7309 static inline void gen_op_evsubf(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7311 tcg_gen_sub_i32(ret
, arg2
, arg1
);
7313 GEN_SPEOP_ARITH2(evsubfw
, gen_op_evsubf
);
7315 /* SPE arithmetic immediate */
7316 #if defined(TARGET_PPC64)
7317 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
7318 static inline void gen_##name(DisasContext *ctx) \
7320 if (unlikely(!ctx->spe_enabled)) { \
7321 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7324 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7325 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7326 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7327 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
7328 tcg_op(t0, t0, rA(ctx->opcode)); \
7329 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
7330 tcg_gen_trunc_i64_i32(t1, t2); \
7331 tcg_temp_free_i64(t2); \
7332 tcg_op(t1, t1, rA(ctx->opcode)); \
7333 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7334 tcg_temp_free_i32(t0); \
7335 tcg_temp_free_i32(t1); \
7338 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
7339 static inline void gen_##name(DisasContext *ctx) \
7341 if (unlikely(!ctx->spe_enabled)) { \
7342 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7345 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
7347 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
7351 GEN_SPEOP_ARITH_IMM2(evaddiw
, tcg_gen_addi_i32
);
7352 GEN_SPEOP_ARITH_IMM2(evsubifw
, tcg_gen_subi_i32
);
7354 /* SPE comparison */
7355 #if defined(TARGET_PPC64)
7356 #define GEN_SPEOP_COMP(name, tcg_cond) \
7357 static inline void gen_##name(DisasContext *ctx) \
7359 if (unlikely(!ctx->spe_enabled)) { \
7360 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7363 int l1 = gen_new_label(); \
7364 int l2 = gen_new_label(); \
7365 int l3 = gen_new_label(); \
7366 int l4 = gen_new_label(); \
7367 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7368 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7369 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7370 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7371 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
7372 tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
7373 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
7375 gen_set_label(l1); \
7376 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
7377 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
7378 gen_set_label(l2); \
7379 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7380 tcg_gen_trunc_i64_i32(t0, t2); \
7381 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
7382 tcg_gen_trunc_i64_i32(t1, t2); \
7383 tcg_temp_free_i64(t2); \
7384 tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
7385 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7386 ~(CRF_CH | CRF_CH_AND_CL)); \
7388 gen_set_label(l3); \
7389 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7390 CRF_CH | CRF_CH_OR_CL); \
7391 gen_set_label(l4); \
7392 tcg_temp_free_i32(t0); \
7393 tcg_temp_free_i32(t1); \
7396 #define GEN_SPEOP_COMP(name, tcg_cond) \
7397 static inline void gen_##name(DisasContext *ctx) \
7399 if (unlikely(!ctx->spe_enabled)) { \
7400 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7403 int l1 = gen_new_label(); \
7404 int l2 = gen_new_label(); \
7405 int l3 = gen_new_label(); \
7406 int l4 = gen_new_label(); \
7408 tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
7409 cpu_gpr[rB(ctx->opcode)], l1); \
7410 tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
7412 gen_set_label(l1); \
7413 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
7414 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
7415 gen_set_label(l2); \
7416 tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
7417 cpu_gprh[rB(ctx->opcode)], l3); \
7418 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7419 ~(CRF_CH | CRF_CH_AND_CL)); \
7421 gen_set_label(l3); \
7422 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7423 CRF_CH | CRF_CH_OR_CL); \
7424 gen_set_label(l4); \
7427 GEN_SPEOP_COMP(evcmpgtu
, TCG_COND_GTU
);
7428 GEN_SPEOP_COMP(evcmpgts
, TCG_COND_GT
);
7429 GEN_SPEOP_COMP(evcmpltu
, TCG_COND_LTU
);
7430 GEN_SPEOP_COMP(evcmplts
, TCG_COND_LT
);
7431 GEN_SPEOP_COMP(evcmpeq
, TCG_COND_EQ
);
7434 static inline void gen_brinc(DisasContext
*ctx
)
7436 /* Note: brinc is usable even if SPE is disabled */
7437 gen_helper_brinc(cpu_gpr
[rD(ctx
->opcode
)],
7438 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7440 static inline void gen_evmergelo(DisasContext
*ctx
)
7442 if (unlikely(!ctx
->spe_enabled
)) {
7443 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7446 #if defined(TARGET_PPC64)
7447 TCGv t0
= tcg_temp_new();
7448 TCGv t1
= tcg_temp_new();
7449 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
7450 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
7451 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7455 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7456 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7459 static inline void gen_evmergehilo(DisasContext
*ctx
)
7461 if (unlikely(!ctx
->spe_enabled
)) {
7462 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7465 #if defined(TARGET_PPC64)
7466 TCGv t0
= tcg_temp_new();
7467 TCGv t1
= tcg_temp_new();
7468 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
7469 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
7470 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7474 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7475 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7478 static inline void gen_evmergelohi(DisasContext
*ctx
)
7480 if (unlikely(!ctx
->spe_enabled
)) {
7481 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7484 #if defined(TARGET_PPC64)
7485 TCGv t0
= tcg_temp_new();
7486 TCGv t1
= tcg_temp_new();
7487 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
7488 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
7489 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7493 if (rD(ctx
->opcode
) == rA(ctx
->opcode
)) {
7494 TCGv_i32 tmp
= tcg_temp_new_i32();
7495 tcg_gen_mov_i32(tmp
, cpu_gpr
[rA(ctx
->opcode
)]);
7496 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7497 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], tmp
);
7498 tcg_temp_free_i32(tmp
);
7500 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7501 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7505 static inline void gen_evsplati(DisasContext
*ctx
)
7507 uint64_t imm
= ((int32_t)(rA(ctx
->opcode
) << 27)) >> 27;
7509 #if defined(TARGET_PPC64)
7510 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
7512 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
7513 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
7516 static inline void gen_evsplatfi(DisasContext
*ctx
)
7518 uint64_t imm
= rA(ctx
->opcode
) << 27;
7520 #if defined(TARGET_PPC64)
7521 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
7523 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
7524 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
7528 static inline void gen_evsel(DisasContext
*ctx
)
7530 int l1
= gen_new_label();
7531 int l2
= gen_new_label();
7532 int l3
= gen_new_label();
7533 int l4
= gen_new_label();
7534 TCGv_i32 t0
= tcg_temp_local_new_i32();
7535 #if defined(TARGET_PPC64)
7536 TCGv t1
= tcg_temp_local_new();
7537 TCGv t2
= tcg_temp_local_new();
7539 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 3);
7540 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
7541 #if defined(TARGET_PPC64)
7542 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
7544 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7548 #if defined(TARGET_PPC64)
7549 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
7551 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7554 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 2);
7555 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l3
);
7556 #if defined(TARGET_PPC64)
7557 tcg_gen_ext32u_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)]);
7559 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7563 #if defined(TARGET_PPC64)
7564 tcg_gen_ext32u_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)]);
7566 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7569 tcg_temp_free_i32(t0
);
7570 #if defined(TARGET_PPC64)
7571 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
, t2
);
7577 static void gen_evsel0(DisasContext
*ctx
)
7582 static void gen_evsel1(DisasContext
*ctx
)
7587 static void gen_evsel2(DisasContext
*ctx
)
7592 static void gen_evsel3(DisasContext
*ctx
)
7599 static inline void gen_evmwumi(DisasContext
*ctx
)
7603 if (unlikely(!ctx
->spe_enabled
)) {
7604 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7608 t0
= tcg_temp_new_i64();
7609 t1
= tcg_temp_new_i64();
7611 /* t0 := rA; t1 := rB */
7612 #if defined(TARGET_PPC64)
7613 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7614 tcg_gen_ext32u_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7616 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7617 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7620 tcg_gen_mul_i64(t0
, t0
, t1
); /* t0 := rA * rB */
7622 gen_store_gpr64(rD(ctx
->opcode
), t0
); /* rD := t0 */
7624 tcg_temp_free_i64(t0
);
7625 tcg_temp_free_i64(t1
);
7628 static inline void gen_evmwumia(DisasContext
*ctx
)
7632 if (unlikely(!ctx
->spe_enabled
)) {
7633 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7637 gen_evmwumi(ctx
); /* rD := rA * rB */
7639 tmp
= tcg_temp_new_i64();
7642 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7643 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7644 tcg_temp_free_i64(tmp
);
7647 static inline void gen_evmwumiaa(DisasContext
*ctx
)
7652 if (unlikely(!ctx
->spe_enabled
)) {
7653 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7657 gen_evmwumi(ctx
); /* rD := rA * rB */
7659 acc
= tcg_temp_new_i64();
7660 tmp
= tcg_temp_new_i64();
7663 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7666 tcg_gen_ld_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7668 /* acc := tmp + acc */
7669 tcg_gen_add_i64(acc
, acc
, tmp
);
7672 tcg_gen_st_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7675 gen_store_gpr64(rD(ctx
->opcode
), acc
);
7677 tcg_temp_free_i64(acc
);
7678 tcg_temp_free_i64(tmp
);
7681 static inline void gen_evmwsmi(DisasContext
*ctx
)
7685 if (unlikely(!ctx
->spe_enabled
)) {
7686 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7690 t0
= tcg_temp_new_i64();
7691 t1
= tcg_temp_new_i64();
7693 /* t0 := rA; t1 := rB */
7694 #if defined(TARGET_PPC64)
7695 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7696 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7698 tcg_gen_ext_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7699 tcg_gen_ext_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7702 tcg_gen_mul_i64(t0
, t0
, t1
); /* t0 := rA * rB */
7704 gen_store_gpr64(rD(ctx
->opcode
), t0
); /* rD := t0 */
7706 tcg_temp_free_i64(t0
);
7707 tcg_temp_free_i64(t1
);
7710 static inline void gen_evmwsmia(DisasContext
*ctx
)
7714 gen_evmwsmi(ctx
); /* rD := rA * rB */
7716 tmp
= tcg_temp_new_i64();
7719 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7720 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7722 tcg_temp_free_i64(tmp
);
7725 static inline void gen_evmwsmiaa(DisasContext
*ctx
)
7727 TCGv_i64 acc
= tcg_temp_new_i64();
7728 TCGv_i64 tmp
= tcg_temp_new_i64();
7730 gen_evmwsmi(ctx
); /* rD := rA * rB */
7732 acc
= tcg_temp_new_i64();
7733 tmp
= tcg_temp_new_i64();
7736 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7739 tcg_gen_ld_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7741 /* acc := tmp + acc */
7742 tcg_gen_add_i64(acc
, acc
, tmp
);
7745 tcg_gen_st_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7748 gen_store_gpr64(rD(ctx
->opcode
), acc
);
7750 tcg_temp_free_i64(acc
);
7751 tcg_temp_free_i64(tmp
);
7754 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7755 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7756 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7757 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7758 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
7759 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
7760 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
7761 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE
); //
7762 GEN_SPE(evmra
, speundef
, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE
);
7763 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
); ////
7764 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7765 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7766 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7767 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
7768 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
7769 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
7770 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
); ////
7771 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7772 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7773 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE
);
7774 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7775 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7776 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE
); //
7777 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE
);
7778 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7779 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7780 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE
); ////
7781 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE
); ////
7782 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE
); ////
7784 /* SPE load and stores */
7785 static inline void gen_addr_spe_imm_index(DisasContext
*ctx
, TCGv EA
, int sh
)
7787 target_ulong uimm
= rB(ctx
->opcode
);
7789 if (rA(ctx
->opcode
) == 0) {
7790 tcg_gen_movi_tl(EA
, uimm
<< sh
);
7792 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], uimm
<< sh
);
7793 if (NARROW_MODE(ctx
)) {
7794 tcg_gen_ext32u_tl(EA
, EA
);
7799 static inline void gen_op_evldd(DisasContext
*ctx
, TCGv addr
)
7801 #if defined(TARGET_PPC64)
7802 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7804 TCGv_i64 t0
= tcg_temp_new_i64();
7805 gen_qemu_ld64(ctx
, t0
, addr
);
7806 tcg_gen_trunc_i64_i32(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7807 tcg_gen_shri_i64(t0
, t0
, 32);
7808 tcg_gen_trunc_i64_i32(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7809 tcg_temp_free_i64(t0
);
7813 static inline void gen_op_evldw(DisasContext
*ctx
, TCGv addr
)
7815 #if defined(TARGET_PPC64)
7816 TCGv t0
= tcg_temp_new();
7817 gen_qemu_ld32u(ctx
, t0
, addr
);
7818 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7819 gen_addr_add(ctx
, addr
, addr
, 4);
7820 gen_qemu_ld32u(ctx
, t0
, addr
);
7821 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7824 gen_qemu_ld32u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7825 gen_addr_add(ctx
, addr
, addr
, 4);
7826 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7830 static inline void gen_op_evldh(DisasContext
*ctx
, TCGv addr
)
7832 TCGv t0
= tcg_temp_new();
7833 #if defined(TARGET_PPC64)
7834 gen_qemu_ld16u(ctx
, t0
, addr
);
7835 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7836 gen_addr_add(ctx
, addr
, addr
, 2);
7837 gen_qemu_ld16u(ctx
, t0
, addr
);
7838 tcg_gen_shli_tl(t0
, t0
, 32);
7839 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7840 gen_addr_add(ctx
, addr
, addr
, 2);
7841 gen_qemu_ld16u(ctx
, t0
, addr
);
7842 tcg_gen_shli_tl(t0
, t0
, 16);
7843 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7844 gen_addr_add(ctx
, addr
, addr
, 2);
7845 gen_qemu_ld16u(ctx
, t0
, addr
);
7846 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7848 gen_qemu_ld16u(ctx
, t0
, addr
);
7849 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7850 gen_addr_add(ctx
, addr
, addr
, 2);
7851 gen_qemu_ld16u(ctx
, t0
, addr
);
7852 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
7853 gen_addr_add(ctx
, addr
, addr
, 2);
7854 gen_qemu_ld16u(ctx
, t0
, addr
);
7855 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7856 gen_addr_add(ctx
, addr
, addr
, 2);
7857 gen_qemu_ld16u(ctx
, t0
, addr
);
7858 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7863 static inline void gen_op_evlhhesplat(DisasContext
*ctx
, TCGv addr
)
7865 TCGv t0
= tcg_temp_new();
7866 gen_qemu_ld16u(ctx
, t0
, addr
);
7867 #if defined(TARGET_PPC64)
7868 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7869 tcg_gen_shli_tl(t0
, t0
, 16);
7870 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7872 tcg_gen_shli_tl(t0
, t0
, 16);
7873 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7874 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7879 static inline void gen_op_evlhhousplat(DisasContext
*ctx
, TCGv addr
)
7881 TCGv t0
= tcg_temp_new();
7882 gen_qemu_ld16u(ctx
, t0
, addr
);
7883 #if defined(TARGET_PPC64)
7884 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7885 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7887 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7888 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7893 static inline void gen_op_evlhhossplat(DisasContext
*ctx
, TCGv addr
)
7895 TCGv t0
= tcg_temp_new();
7896 gen_qemu_ld16s(ctx
, t0
, addr
);
7897 #if defined(TARGET_PPC64)
7898 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7899 tcg_gen_ext32u_tl(t0
, t0
);
7900 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7902 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7903 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7908 static inline void gen_op_evlwhe(DisasContext
*ctx
, TCGv addr
)
7910 TCGv t0
= tcg_temp_new();
7911 #if defined(TARGET_PPC64)
7912 gen_qemu_ld16u(ctx
, t0
, addr
);
7913 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7914 gen_addr_add(ctx
, addr
, addr
, 2);
7915 gen_qemu_ld16u(ctx
, t0
, addr
);
7916 tcg_gen_shli_tl(t0
, t0
, 16);
7917 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7919 gen_qemu_ld16u(ctx
, t0
, addr
);
7920 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7921 gen_addr_add(ctx
, addr
, addr
, 2);
7922 gen_qemu_ld16u(ctx
, t0
, addr
);
7923 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
7928 static inline void gen_op_evlwhou(DisasContext
*ctx
, TCGv addr
)
7930 #if defined(TARGET_PPC64)
7931 TCGv t0
= tcg_temp_new();
7932 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7933 gen_addr_add(ctx
, addr
, addr
, 2);
7934 gen_qemu_ld16u(ctx
, t0
, addr
);
7935 tcg_gen_shli_tl(t0
, t0
, 32);
7936 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7939 gen_qemu_ld16u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7940 gen_addr_add(ctx
, addr
, addr
, 2);
7941 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7945 static inline void gen_op_evlwhos(DisasContext
*ctx
, TCGv addr
)
7947 #if defined(TARGET_PPC64)
7948 TCGv t0
= tcg_temp_new();
7949 gen_qemu_ld16s(ctx
, t0
, addr
);
7950 tcg_gen_ext32u_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7951 gen_addr_add(ctx
, addr
, addr
, 2);
7952 gen_qemu_ld16s(ctx
, t0
, addr
);
7953 tcg_gen_shli_tl(t0
, t0
, 32);
7954 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7957 gen_qemu_ld16s(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7958 gen_addr_add(ctx
, addr
, addr
, 2);
7959 gen_qemu_ld16s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7963 static inline void gen_op_evlwwsplat(DisasContext
*ctx
, TCGv addr
)
7965 TCGv t0
= tcg_temp_new();
7966 gen_qemu_ld32u(ctx
, t0
, addr
);
7967 #if defined(TARGET_PPC64)
7968 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7969 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7971 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7972 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7977 static inline void gen_op_evlwhsplat(DisasContext
*ctx
, TCGv addr
)
7979 TCGv t0
= tcg_temp_new();
7980 #if defined(TARGET_PPC64)
7981 gen_qemu_ld16u(ctx
, t0
, addr
);
7982 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7983 tcg_gen_shli_tl(t0
, t0
, 32);
7984 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7985 gen_addr_add(ctx
, addr
, addr
, 2);
7986 gen_qemu_ld16u(ctx
, t0
, addr
);
7987 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7988 tcg_gen_shli_tl(t0
, t0
, 16);
7989 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7991 gen_qemu_ld16u(ctx
, t0
, addr
);
7992 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7993 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
7994 gen_addr_add(ctx
, addr
, addr
, 2);
7995 gen_qemu_ld16u(ctx
, t0
, addr
);
7996 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
7997 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
8002 static inline void gen_op_evstdd(DisasContext
*ctx
, TCGv addr
)
8004 #if defined(TARGET_PPC64)
8005 gen_qemu_st64(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
8007 TCGv_i64 t0
= tcg_temp_new_i64();
8008 tcg_gen_concat_i32_i64(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gprh
[rS(ctx
->opcode
)]);
8009 gen_qemu_st64(ctx
, t0
, addr
);
8010 tcg_temp_free_i64(t0
);
8014 static inline void gen_op_evstdw(DisasContext
*ctx
, TCGv addr
)
8016 #if defined(TARGET_PPC64)
8017 TCGv t0
= tcg_temp_new();
8018 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
8019 gen_qemu_st32(ctx
, t0
, addr
);
8022 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
8024 gen_addr_add(ctx
, addr
, addr
, 4);
8025 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
8028 static inline void gen_op_evstdh(DisasContext
*ctx
, TCGv addr
)
8030 TCGv t0
= tcg_temp_new();
8031 #if defined(TARGET_PPC64)
8032 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
8034 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
8036 gen_qemu_st16(ctx
, t0
, addr
);
8037 gen_addr_add(ctx
, addr
, addr
, 2);
8038 #if defined(TARGET_PPC64)
8039 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
8040 gen_qemu_st16(ctx
, t0
, addr
);
8042 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
8044 gen_addr_add(ctx
, addr
, addr
, 2);
8045 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
8046 gen_qemu_st16(ctx
, t0
, addr
);
8048 gen_addr_add(ctx
, addr
, addr
, 2);
8049 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
8052 static inline void gen_op_evstwhe(DisasContext
*ctx
, TCGv addr
)
8054 TCGv t0
= tcg_temp_new();
8055 #if defined(TARGET_PPC64)
8056 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
8058 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
8060 gen_qemu_st16(ctx
, t0
, addr
);
8061 gen_addr_add(ctx
, addr
, addr
, 2);
8062 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
8063 gen_qemu_st16(ctx
, t0
, addr
);
8067 static inline void gen_op_evstwho(DisasContext
*ctx
, TCGv addr
)
8069 #if defined(TARGET_PPC64)
8070 TCGv t0
= tcg_temp_new();
8071 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
8072 gen_qemu_st16(ctx
, t0
, addr
);
8075 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
8077 gen_addr_add(ctx
, addr
, addr
, 2);
8078 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
8081 static inline void gen_op_evstwwe(DisasContext
*ctx
, TCGv addr
)
8083 #if defined(TARGET_PPC64)
8084 TCGv t0
= tcg_temp_new();
8085 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
8086 gen_qemu_st32(ctx
, t0
, addr
);
8089 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
8093 static inline void gen_op_evstwwo(DisasContext
*ctx
, TCGv addr
)
8095 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
8098 #define GEN_SPEOP_LDST(name, opc2, sh) \
8099 static void glue(gen_, name)(DisasContext *ctx) \
8102 if (unlikely(!ctx->spe_enabled)) { \
8103 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8106 gen_set_access_type(ctx, ACCESS_INT); \
8107 t0 = tcg_temp_new(); \
8108 if (Rc(ctx->opcode)) { \
8109 gen_addr_spe_imm_index(ctx, t0, sh); \
8111 gen_addr_reg_index(ctx, t0); \
8113 gen_op_##name(ctx, t0); \
8114 tcg_temp_free(t0); \
8117 GEN_SPEOP_LDST(evldd
, 0x00, 3);
8118 GEN_SPEOP_LDST(evldw
, 0x01, 3);
8119 GEN_SPEOP_LDST(evldh
, 0x02, 3);
8120 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1);
8121 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1);
8122 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1);
8123 GEN_SPEOP_LDST(evlwhe
, 0x08, 2);
8124 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2);
8125 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2);
8126 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2);
8127 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2);
8129 GEN_SPEOP_LDST(evstdd
, 0x10, 3);
8130 GEN_SPEOP_LDST(evstdw
, 0x11, 3);
8131 GEN_SPEOP_LDST(evstdh
, 0x12, 3);
8132 GEN_SPEOP_LDST(evstwhe
, 0x18, 2);
8133 GEN_SPEOP_LDST(evstwho
, 0x1A, 2);
8134 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2);
8135 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2);
8137 /* Multiply and add - TODO */
8139 GEN_SPE(speundef
, evmhessf
, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);//
8140 GEN_SPE(speundef
, evmhossf
, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8141 GEN_SPE(evmheumi
, evmhesmi
, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
8142 GEN_SPE(speundef
, evmhesmf
, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8143 GEN_SPE(evmhoumi
, evmhosmi
, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
8144 GEN_SPE(speundef
, evmhosmf
, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8145 GEN_SPE(speundef
, evmhessfa
, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8146 GEN_SPE(speundef
, evmhossfa
, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8147 GEN_SPE(evmheumia
, evmhesmia
, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
8148 GEN_SPE(speundef
, evmhesmfa
, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8149 GEN_SPE(evmhoumia
, evmhosmia
, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
8150 GEN_SPE(speundef
, evmhosmfa
, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8152 GEN_SPE(speundef
, evmwhssf
, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8153 GEN_SPE(evmwlumi
, speundef
, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
8154 GEN_SPE(evmwhumi
, evmwhsmi
, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
8155 GEN_SPE(speundef
, evmwhsmf
, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8156 GEN_SPE(speundef
, evmwssf
, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8157 GEN_SPE(speundef
, evmwsmf
, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8158 GEN_SPE(speundef
, evmwhssfa
, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8159 GEN_SPE(evmwlumia
, speundef
, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
8160 GEN_SPE(evmwhumia
, evmwhsmia
, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
8161 GEN_SPE(speundef
, evmwhsmfa
, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8162 GEN_SPE(speundef
, evmwssfa
, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8163 GEN_SPE(speundef
, evmwsmfa
, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8165 GEN_SPE(evadduiaaw
, evaddsiaaw
, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8166 GEN_SPE(evsubfusiaaw
, evsubfssiaaw
, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8167 GEN_SPE(evaddumiaaw
, evaddsmiaaw
, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8168 GEN_SPE(evsubfumiaaw
, evsubfsmiaaw
, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8169 GEN_SPE(evdivws
, evdivwu
, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE
);
8171 GEN_SPE(evmheusiaaw
, evmhessiaaw
, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8172 GEN_SPE(speundef
, evmhessfaaw
, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8173 GEN_SPE(evmhousiaaw
, evmhossiaaw
, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8174 GEN_SPE(speundef
, evmhossfaaw
, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8175 GEN_SPE(evmheumiaaw
, evmhesmiaaw
, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8176 GEN_SPE(speundef
, evmhesmfaaw
, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8177 GEN_SPE(evmhoumiaaw
, evmhosmiaaw
, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8178 GEN_SPE(speundef
, evmhosmfaaw
, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8179 GEN_SPE(evmhegumiaa
, evmhegsmiaa
, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8180 GEN_SPE(speundef
, evmhegsmfaa
, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8181 GEN_SPE(evmhogumiaa
, evmhogsmiaa
, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8182 GEN_SPE(speundef
, evmhogsmfaa
, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8184 GEN_SPE(evmwlusiaaw
, evmwlssiaaw
, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
8185 GEN_SPE(evmwlumiaaw
, evmwlsmiaaw
, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
8186 GEN_SPE(speundef
, evmwssfaa
, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8187 GEN_SPE(speundef
, evmwsmfaa
, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8189 GEN_SPE(evmheusianw
, evmhessianw
, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8190 GEN_SPE(speundef
, evmhessfanw
, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8191 GEN_SPE(evmhousianw
, evmhossianw
, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8192 GEN_SPE(speundef
, evmhossfanw
, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8193 GEN_SPE(evmheumianw
, evmhesmianw
, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8194 GEN_SPE(speundef
, evmhesmfanw
, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8195 GEN_SPE(evmhoumianw
, evmhosmianw
, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8196 GEN_SPE(speundef
, evmhosmfanw
, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8197 GEN_SPE(evmhegumian
, evmhegsmian
, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8198 GEN_SPE(speundef
, evmhegsmfan
, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8199 GEN_SPE(evmhigumian
, evmhigsmian
, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8200 GEN_SPE(speundef
, evmhogsmfan
, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8202 GEN_SPE(evmwlusianw
, evmwlssianw
, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
8203 GEN_SPE(evmwlumianw
, evmwlsmianw
, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
8204 GEN_SPE(speundef
, evmwssfan
, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8205 GEN_SPE(evmwumian
, evmwsmian
, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
8206 GEN_SPE(speundef
, evmwsmfan
, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8209 /*** SPE floating-point extension ***/
8210 #if defined(TARGET_PPC64)
8211 #define GEN_SPEFPUOP_CONV_32_32(name) \
8212 static inline void gen_##name(DisasContext *ctx) \
8216 t0 = tcg_temp_new_i32(); \
8217 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8218 gen_helper_##name(t0, cpu_env, t0); \
8219 t1 = tcg_temp_new(); \
8220 tcg_gen_extu_i32_tl(t1, t0); \
8221 tcg_temp_free_i32(t0); \
8222 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8223 0xFFFFFFFF00000000ULL); \
8224 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
8225 tcg_temp_free(t1); \
8227 #define GEN_SPEFPUOP_CONV_32_64(name) \
8228 static inline void gen_##name(DisasContext *ctx) \
8232 t0 = tcg_temp_new_i32(); \
8233 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
8234 t1 = tcg_temp_new(); \
8235 tcg_gen_extu_i32_tl(t1, t0); \
8236 tcg_temp_free_i32(t0); \
8237 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8238 0xFFFFFFFF00000000ULL); \
8239 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
8240 tcg_temp_free(t1); \
8242 #define GEN_SPEFPUOP_CONV_64_32(name) \
8243 static inline void gen_##name(DisasContext *ctx) \
8245 TCGv_i32 t0 = tcg_temp_new_i32(); \
8246 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8247 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
8248 tcg_temp_free_i32(t0); \
8250 #define GEN_SPEFPUOP_CONV_64_64(name) \
8251 static inline void gen_##name(DisasContext *ctx) \
8253 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8254 cpu_gpr[rB(ctx->opcode)]); \
8256 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
8257 static inline void gen_##name(DisasContext *ctx) \
8261 if (unlikely(!ctx->spe_enabled)) { \
8262 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8265 t0 = tcg_temp_new_i32(); \
8266 t1 = tcg_temp_new_i32(); \
8267 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8268 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8269 gen_helper_##name(t0, cpu_env, t0, t1); \
8270 tcg_temp_free_i32(t1); \
8271 t2 = tcg_temp_new(); \
8272 tcg_gen_extu_i32_tl(t2, t0); \
8273 tcg_temp_free_i32(t0); \
8274 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8275 0xFFFFFFFF00000000ULL); \
8276 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \
8277 tcg_temp_free(t2); \
8279 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
8280 static inline void gen_##name(DisasContext *ctx) \
8282 if (unlikely(!ctx->spe_enabled)) { \
8283 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8286 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8287 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8289 #define GEN_SPEFPUOP_COMP_32(name) \
8290 static inline void gen_##name(DisasContext *ctx) \
8293 if (unlikely(!ctx->spe_enabled)) { \
8294 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8297 t0 = tcg_temp_new_i32(); \
8298 t1 = tcg_temp_new_i32(); \
8299 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8300 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8301 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
8302 tcg_temp_free_i32(t0); \
8303 tcg_temp_free_i32(t1); \
8305 #define GEN_SPEFPUOP_COMP_64(name) \
8306 static inline void gen_##name(DisasContext *ctx) \
8308 if (unlikely(!ctx->spe_enabled)) { \
8309 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8312 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
8313 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8316 #define GEN_SPEFPUOP_CONV_32_32(name) \
8317 static inline void gen_##name(DisasContext *ctx) \
8319 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8320 cpu_gpr[rB(ctx->opcode)]); \
8322 #define GEN_SPEFPUOP_CONV_32_64(name) \
8323 static inline void gen_##name(DisasContext *ctx) \
8325 TCGv_i64 t0 = tcg_temp_new_i64(); \
8326 gen_load_gpr64(t0, rB(ctx->opcode)); \
8327 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
8328 tcg_temp_free_i64(t0); \
8330 #define GEN_SPEFPUOP_CONV_64_32(name) \
8331 static inline void gen_##name(DisasContext *ctx) \
8333 TCGv_i64 t0 = tcg_temp_new_i64(); \
8334 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
8335 gen_store_gpr64(rD(ctx->opcode), t0); \
8336 tcg_temp_free_i64(t0); \
8338 #define GEN_SPEFPUOP_CONV_64_64(name) \
8339 static inline void gen_##name(DisasContext *ctx) \
8341 TCGv_i64 t0 = tcg_temp_new_i64(); \
8342 gen_load_gpr64(t0, rB(ctx->opcode)); \
8343 gen_helper_##name(t0, cpu_env, t0); \
8344 gen_store_gpr64(rD(ctx->opcode), t0); \
8345 tcg_temp_free_i64(t0); \
8347 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
8348 static inline void gen_##name(DisasContext *ctx) \
8350 if (unlikely(!ctx->spe_enabled)) { \
8351 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8354 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8355 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8357 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
8358 static inline void gen_##name(DisasContext *ctx) \
8361 if (unlikely(!ctx->spe_enabled)) { \
8362 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8365 t0 = tcg_temp_new_i64(); \
8366 t1 = tcg_temp_new_i64(); \
8367 gen_load_gpr64(t0, rA(ctx->opcode)); \
8368 gen_load_gpr64(t1, rB(ctx->opcode)); \
8369 gen_helper_##name(t0, cpu_env, t0, t1); \
8370 gen_store_gpr64(rD(ctx->opcode), t0); \
8371 tcg_temp_free_i64(t0); \
8372 tcg_temp_free_i64(t1); \
8374 #define GEN_SPEFPUOP_COMP_32(name) \
8375 static inline void gen_##name(DisasContext *ctx) \
8377 if (unlikely(!ctx->spe_enabled)) { \
8378 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8381 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
8382 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8384 #define GEN_SPEFPUOP_COMP_64(name) \
8385 static inline void gen_##name(DisasContext *ctx) \
8388 if (unlikely(!ctx->spe_enabled)) { \
8389 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8392 t0 = tcg_temp_new_i64(); \
8393 t1 = tcg_temp_new_i64(); \
8394 gen_load_gpr64(t0, rA(ctx->opcode)); \
8395 gen_load_gpr64(t1, rB(ctx->opcode)); \
8396 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
8397 tcg_temp_free_i64(t0); \
8398 tcg_temp_free_i64(t1); \
8402 /* Single precision floating-point vectors operations */
8404 GEN_SPEFPUOP_ARITH2_64_64(evfsadd
);
8405 GEN_SPEFPUOP_ARITH2_64_64(evfssub
);
8406 GEN_SPEFPUOP_ARITH2_64_64(evfsmul
);
8407 GEN_SPEFPUOP_ARITH2_64_64(evfsdiv
);
8408 static inline void gen_evfsabs(DisasContext
*ctx
)
8410 if (unlikely(!ctx
->spe_enabled
)) {
8411 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8414 #if defined(TARGET_PPC64)
8415 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000080000000LL
);
8417 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x80000000);
8418 tcg_gen_andi_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
8421 static inline void gen_evfsnabs(DisasContext
*ctx
)
8423 if (unlikely(!ctx
->spe_enabled
)) {
8424 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8427 #if defined(TARGET_PPC64)
8428 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
8430 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8431 tcg_gen_ori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8434 static inline void gen_evfsneg(DisasContext
*ctx
)
8436 if (unlikely(!ctx
->spe_enabled
)) {
8437 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8440 #if defined(TARGET_PPC64)
8441 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
8443 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8444 tcg_gen_xori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8449 GEN_SPEFPUOP_CONV_64_64(evfscfui
);
8450 GEN_SPEFPUOP_CONV_64_64(evfscfsi
);
8451 GEN_SPEFPUOP_CONV_64_64(evfscfuf
);
8452 GEN_SPEFPUOP_CONV_64_64(evfscfsf
);
8453 GEN_SPEFPUOP_CONV_64_64(evfsctui
);
8454 GEN_SPEFPUOP_CONV_64_64(evfsctsi
);
8455 GEN_SPEFPUOP_CONV_64_64(evfsctuf
);
8456 GEN_SPEFPUOP_CONV_64_64(evfsctsf
);
8457 GEN_SPEFPUOP_CONV_64_64(evfsctuiz
);
8458 GEN_SPEFPUOP_CONV_64_64(evfsctsiz
);
8461 GEN_SPEFPUOP_COMP_64(evfscmpgt
);
8462 GEN_SPEFPUOP_COMP_64(evfscmplt
);
8463 GEN_SPEFPUOP_COMP_64(evfscmpeq
);
8464 GEN_SPEFPUOP_COMP_64(evfststgt
);
8465 GEN_SPEFPUOP_COMP_64(evfststlt
);
8466 GEN_SPEFPUOP_COMP_64(evfststeq
);
8468 /* Opcodes definitions */
8469 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8470 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
); //
8471 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8472 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8473 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8474 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8475 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8476 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8477 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8478 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8479 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8480 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8481 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8482 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8484 /* Single precision floating-point operations */
8486 GEN_SPEFPUOP_ARITH2_32_32(efsadd
);
8487 GEN_SPEFPUOP_ARITH2_32_32(efssub
);
8488 GEN_SPEFPUOP_ARITH2_32_32(efsmul
);
8489 GEN_SPEFPUOP_ARITH2_32_32(efsdiv
);
8490 static inline void gen_efsabs(DisasContext
*ctx
)
8492 if (unlikely(!ctx
->spe_enabled
)) {
8493 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8496 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], (target_long
)~0x80000000LL
);
8498 static inline void gen_efsnabs(DisasContext
*ctx
)
8500 if (unlikely(!ctx
->spe_enabled
)) {
8501 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8504 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8506 static inline void gen_efsneg(DisasContext
*ctx
)
8508 if (unlikely(!ctx
->spe_enabled
)) {
8509 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8512 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8516 GEN_SPEFPUOP_CONV_32_32(efscfui
);
8517 GEN_SPEFPUOP_CONV_32_32(efscfsi
);
8518 GEN_SPEFPUOP_CONV_32_32(efscfuf
);
8519 GEN_SPEFPUOP_CONV_32_32(efscfsf
);
8520 GEN_SPEFPUOP_CONV_32_32(efsctui
);
8521 GEN_SPEFPUOP_CONV_32_32(efsctsi
);
8522 GEN_SPEFPUOP_CONV_32_32(efsctuf
);
8523 GEN_SPEFPUOP_CONV_32_32(efsctsf
);
8524 GEN_SPEFPUOP_CONV_32_32(efsctuiz
);
8525 GEN_SPEFPUOP_CONV_32_32(efsctsiz
);
8526 GEN_SPEFPUOP_CONV_32_64(efscfd
);
8529 GEN_SPEFPUOP_COMP_32(efscmpgt
);
8530 GEN_SPEFPUOP_COMP_32(efscmplt
);
8531 GEN_SPEFPUOP_COMP_32(efscmpeq
);
8532 GEN_SPEFPUOP_COMP_32(efststgt
);
8533 GEN_SPEFPUOP_COMP_32(efststlt
);
8534 GEN_SPEFPUOP_COMP_32(efststeq
);
8536 /* Opcodes definitions */
8537 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8538 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
); //
8539 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8540 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8541 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8542 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE
); //
8543 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8544 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8545 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8546 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8547 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8548 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8549 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8550 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8552 /* Double precision floating-point operations */
8554 GEN_SPEFPUOP_ARITH2_64_64(efdadd
);
8555 GEN_SPEFPUOP_ARITH2_64_64(efdsub
);
8556 GEN_SPEFPUOP_ARITH2_64_64(efdmul
);
8557 GEN_SPEFPUOP_ARITH2_64_64(efddiv
);
8558 static inline void gen_efdabs(DisasContext
*ctx
)
8560 if (unlikely(!ctx
->spe_enabled
)) {
8561 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8564 #if defined(TARGET_PPC64)
8565 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000000000000LL
);
8567 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8568 tcg_gen_andi_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
8571 static inline void gen_efdnabs(DisasContext
*ctx
)
8573 if (unlikely(!ctx
->spe_enabled
)) {
8574 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8577 #if defined(TARGET_PPC64)
8578 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
8580 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8581 tcg_gen_ori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8584 static inline void gen_efdneg(DisasContext
*ctx
)
8586 if (unlikely(!ctx
->spe_enabled
)) {
8587 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8590 #if defined(TARGET_PPC64)
8591 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
8593 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8594 tcg_gen_xori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8599 GEN_SPEFPUOP_CONV_64_32(efdcfui
);
8600 GEN_SPEFPUOP_CONV_64_32(efdcfsi
);
8601 GEN_SPEFPUOP_CONV_64_32(efdcfuf
);
8602 GEN_SPEFPUOP_CONV_64_32(efdcfsf
);
8603 GEN_SPEFPUOP_CONV_32_64(efdctui
);
8604 GEN_SPEFPUOP_CONV_32_64(efdctsi
);
8605 GEN_SPEFPUOP_CONV_32_64(efdctuf
);
8606 GEN_SPEFPUOP_CONV_32_64(efdctsf
);
8607 GEN_SPEFPUOP_CONV_32_64(efdctuiz
);
8608 GEN_SPEFPUOP_CONV_32_64(efdctsiz
);
8609 GEN_SPEFPUOP_CONV_64_32(efdcfs
);
8610 GEN_SPEFPUOP_CONV_64_64(efdcfuid
);
8611 GEN_SPEFPUOP_CONV_64_64(efdcfsid
);
8612 GEN_SPEFPUOP_CONV_64_64(efdctuidz
);
8613 GEN_SPEFPUOP_CONV_64_64(efdctsidz
);
8616 GEN_SPEFPUOP_COMP_64(efdcmpgt
);
8617 GEN_SPEFPUOP_COMP_64(efdcmplt
);
8618 GEN_SPEFPUOP_COMP_64(efdcmpeq
);
8619 GEN_SPEFPUOP_COMP_64(efdtstgt
);
8620 GEN_SPEFPUOP_COMP_64(efdtstlt
);
8621 GEN_SPEFPUOP_COMP_64(efdtsteq
);
8623 /* Opcodes definitions */
8624 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
); //
8625 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8626 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE
); //
8627 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8628 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
); //
8629 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8630 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
); //
8631 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE
); //
8632 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8633 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8634 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8635 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8636 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8637 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8638 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
); //
8639 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8641 static opcode_t opcodes
[] = {
8642 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
),
8643 GEN_HANDLER(cmp
, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER
),
8644 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
8645 GEN_HANDLER(cmpl
, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER
),
8646 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
8647 GEN_HANDLER_E(cmpb
, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE
, PPC2_ISA205
),
8648 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
),
8649 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8650 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8651 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8652 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8653 GEN_HANDLER(mulhw
, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER
),
8654 GEN_HANDLER(mulhwu
, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER
),
8655 GEN_HANDLER(mullw
, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER
),
8656 GEN_HANDLER(mullwo
, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER
),
8657 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8658 #if defined(TARGET_PPC64)
8659 GEN_HANDLER(mulld
, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B
),
8661 GEN_HANDLER(neg
, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER
),
8662 GEN_HANDLER(nego
, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER
),
8663 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8664 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8665 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8666 GEN_HANDLER(cntlzw
, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER
),
8667 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
),
8668 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
),
8669 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8670 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8671 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8672 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8673 GEN_HANDLER(popcntb
, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB
),
8674 GEN_HANDLER(popcntw
, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD
),
8675 GEN_HANDLER_E(prtyw
, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
8676 #if defined(TARGET_PPC64)
8677 GEN_HANDLER(popcntd
, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD
),
8678 GEN_HANDLER(cntlzd
, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B
),
8679 GEN_HANDLER_E(prtyd
, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
8681 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8682 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8683 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8684 GEN_HANDLER(slw
, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER
),
8685 GEN_HANDLER(sraw
, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER
),
8686 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
),
8687 GEN_HANDLER(srw
, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER
),
8688 #if defined(TARGET_PPC64)
8689 GEN_HANDLER(sld
, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B
),
8690 GEN_HANDLER(srad
, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B
),
8691 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
),
8692 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
),
8693 GEN_HANDLER(srd
, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B
),
8695 GEN_HANDLER(frsqrtes
, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES
),
8696 GEN_HANDLER(fsqrt
, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
8697 GEN_HANDLER(fsqrts
, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
8698 GEN_HANDLER(fcmpo
, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT
),
8699 GEN_HANDLER(fcmpu
, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT
),
8700 GEN_HANDLER(fabs
, 0x3F, 0x08, 0x08, 0x001F0000, PPC_FLOAT
),
8701 GEN_HANDLER(fmr
, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT
),
8702 GEN_HANDLER(fnabs
, 0x3F, 0x08, 0x04, 0x001F0000, PPC_FLOAT
),
8703 GEN_HANDLER(fneg
, 0x3F, 0x08, 0x01, 0x001F0000, PPC_FLOAT
),
8704 GEN_HANDLER_E(fcpsgn
, 0x3F, 0x08, 0x00, 0x00000000, PPC_NONE
, PPC2_ISA205
),
8705 GEN_HANDLER(mcrfs
, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT
),
8706 GEN_HANDLER(mffs
, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT
),
8707 GEN_HANDLER(mtfsb0
, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT
),
8708 GEN_HANDLER(mtfsb1
, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT
),
8709 GEN_HANDLER(mtfsf
, 0x3F, 0x07, 0x16, 0x00000000, PPC_FLOAT
),
8710 GEN_HANDLER(mtfsfi
, 0x3F, 0x06, 0x04, 0x006e0800, PPC_FLOAT
),
8711 #if defined(TARGET_PPC64)
8712 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
),
8713 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
),
8714 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
),
8716 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8717 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8718 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
),
8719 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
),
8720 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
),
8721 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
),
8722 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO
),
8723 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
),
8724 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES
),
8725 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
),
8726 #if defined(TARGET_PPC64)
8727 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B
),
8728 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
),
8730 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
),
8731 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
),
8732 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
8733 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
8734 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
),
8735 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
),
8736 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
),
8737 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
),
8738 #if defined(TARGET_PPC64)
8739 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
),
8740 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
),
8742 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW
),
8743 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
),
8744 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
8745 #if defined(TARGET_PPC64)
8746 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
),
8747 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
),
8749 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
),
8750 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
),
8751 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
),
8752 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
),
8753 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
),
8754 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
),
8755 #if defined(TARGET_PPC64)
8756 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
),
8758 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC
),
8759 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC
),
8760 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
),
8761 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
),
8762 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
),
8763 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE
),
8764 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE
),
8765 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ
),
8766 GEN_HANDLER(dst
, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC
),
8767 GEN_HANDLER(dstst
, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC
),
8768 GEN_HANDLER(dss
, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC
),
8769 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
),
8770 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
),
8771 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
),
8772 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
),
8773 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
),
8774 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
),
8775 #if defined(TARGET_PPC64)
8776 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
),
8777 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
8779 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
),
8780 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
8782 GEN_HANDLER2(slbmte
, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B
),
8783 GEN_HANDLER2(slbmfee
, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B
),
8784 GEN_HANDLER2(slbmfev
, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B
),
8786 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
),
8787 GEN_HANDLER(tlbiel
, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE
),
8788 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE
),
8789 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
),
8790 #if defined(TARGET_PPC64)
8791 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI
),
8792 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
),
8794 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
),
8795 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
),
8796 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
),
8797 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
),
8798 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
),
8799 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
),
8800 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
),
8801 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
),
8802 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
),
8803 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
),
8804 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
),
8805 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
8806 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
),
8807 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
),
8808 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
),
8809 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
),
8810 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
),
8811 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
),
8812 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
),
8813 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
8814 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
),
8815 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
),
8816 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
),
8817 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
),
8818 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
),
8819 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
),
8820 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
),
8821 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
),
8822 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
),
8823 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
),
8824 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
),
8825 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
),
8826 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
),
8827 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
),
8828 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
),
8829 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
),
8830 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
),
8831 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
),
8832 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
),
8833 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
),
8834 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
),
8835 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
),
8836 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
),
8837 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
),
8838 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
),
8839 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
),
8840 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
),
8841 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
),
8842 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
),
8843 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8844 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8845 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
),
8846 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
),
8847 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8848 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8849 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
),
8850 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
),
8851 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
),
8852 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
),
8853 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
),
8854 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
),
8855 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
),
8856 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
),
8857 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
),
8858 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
),
8859 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
),
8860 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
),
8861 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
),
8862 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
),
8863 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
),
8864 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
),
8865 GEN_HANDLER_E(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
, PPC2_BOOKE206
),
8866 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
),
8867 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
),
8868 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
),
8869 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
),
8870 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
),
8871 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
),
8872 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
),
8873 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
),
8874 GEN_HANDLER2_E(tlbre_booke206
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
8875 PPC_NONE
, PPC2_BOOKE206
),
8876 GEN_HANDLER2_E(tlbsx_booke206
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
8877 PPC_NONE
, PPC2_BOOKE206
),
8878 GEN_HANDLER2_E(tlbwe_booke206
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
8879 PPC_NONE
, PPC2_BOOKE206
),
8880 GEN_HANDLER2_E(tlbivax_booke206
, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
8881 PPC_NONE
, PPC2_BOOKE206
),
8882 GEN_HANDLER2_E(tlbilx_booke206
, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
8883 PPC_NONE
, PPC2_BOOKE206
),
8884 GEN_HANDLER2_E(msgsnd
, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
8885 PPC_NONE
, PPC2_PRCNTL
),
8886 GEN_HANDLER2_E(msgclr
, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
8887 PPC_NONE
, PPC2_PRCNTL
),
8888 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
),
8889 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE
),
8890 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
),
8891 GEN_HANDLER_E(mbar
, 0x1F, 0x16, 0x1a, 0x001FF801,
8892 PPC_BOOKE
, PPC2_BOOKE206
),
8893 GEN_HANDLER(msync_4xx
, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE
),
8894 GEN_HANDLER2_E(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
8895 PPC_BOOKE
, PPC2_BOOKE206
),
8896 GEN_HANDLER(lvsl
, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC
),
8897 GEN_HANDLER(lvsr
, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC
),
8898 GEN_HANDLER(mfvscr
, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC
),
8899 GEN_HANDLER(mtvscr
, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC
),
8900 GEN_HANDLER(vsldoi
, 0x04, 0x16, 0xFF, 0x00000400, PPC_ALTIVEC
),
8901 GEN_HANDLER(vmladduhm
, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC
),
8902 GEN_HANDLER2(evsel0
, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE
),
8903 GEN_HANDLER2(evsel1
, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE
),
8904 GEN_HANDLER2(evsel2
, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE
),
8905 GEN_HANDLER2(evsel3
, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE
),
8907 #undef GEN_INT_ARITH_ADD
8908 #undef GEN_INT_ARITH_ADD_CONST
8909 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
8910 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
8911 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
8912 add_ca, compute_ca, compute_ov) \
8913 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
8914 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
8915 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
8916 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
8917 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
8918 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
8919 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
8920 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
8921 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
8922 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
8923 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
8925 #undef GEN_INT_ARITH_DIVW
8926 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
8927 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
8928 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0),
8929 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1),
8930 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0),
8931 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1),
8933 #if defined(TARGET_PPC64)
8934 #undef GEN_INT_ARITH_DIVD
8935 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
8936 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8937 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0),
8938 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1),
8939 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0),
8940 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1),
8942 #undef GEN_INT_ARITH_MUL_HELPER
8943 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
8944 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8945 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00),
8946 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02),
8947 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17),
8950 #undef GEN_INT_ARITH_SUBF
8951 #undef GEN_INT_ARITH_SUBF_CONST
8952 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
8953 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
8954 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
8955 add_ca, compute_ca, compute_ov) \
8956 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
8957 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
8958 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
8959 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
8960 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
8961 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
8962 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
8963 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
8964 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
8965 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
8966 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
8970 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
8971 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
8972 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
8973 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
8974 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
),
8975 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
),
8976 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
),
8977 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
),
8978 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
),
8979 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
),
8980 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
),
8981 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
),
8982 #if defined(TARGET_PPC64)
8983 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
),
8986 #if defined(TARGET_PPC64)
8989 #define GEN_PPC64_R2(name, opc1, opc2) \
8990 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8991 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
8993 #define GEN_PPC64_R4(name, opc1, opc2) \
8994 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8995 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
8997 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
8999 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
9001 GEN_PPC64_R4(rldicl
, 0x1E, 0x00),
9002 GEN_PPC64_R4(rldicr
, 0x1E, 0x02),
9003 GEN_PPC64_R4(rldic
, 0x1E, 0x04),
9004 GEN_PPC64_R2(rldcl
, 0x1E, 0x08),
9005 GEN_PPC64_R2(rldcr
, 0x1E, 0x09),
9006 GEN_PPC64_R4(rldimi
, 0x1E, 0x06),
9009 #undef _GEN_FLOAT_ACB
9010 #undef GEN_FLOAT_ACB
9011 #undef _GEN_FLOAT_AB
9013 #undef _GEN_FLOAT_AC
9017 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
9018 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
9019 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
9020 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
9021 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
9022 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
9023 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
9024 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
9025 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
9026 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
9027 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
9028 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
9029 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
9030 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
9031 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
9032 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
9033 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
9034 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
9035 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
9037 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
),
9038 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
),
9039 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
),
9040 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
),
9041 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
),
9042 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
),
9043 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
),
9044 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
),
9045 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
),
9046 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
),
9047 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
),
9048 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
),
9049 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
),
9050 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
),
9051 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
),
9052 #if defined(TARGET_PPC64)
9053 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
),
9054 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
),
9055 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
),
9057 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
),
9058 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
),
9059 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
),
9060 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
),
9067 #define GEN_LD(name, ldop, opc, type) \
9068 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9069 #define GEN_LDU(name, ldop, opc, type) \
9070 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
9071 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
9072 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
9073 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
9074 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
9075 #define GEN_LDS(name, ldop, op, type) \
9076 GEN_LD(name, ldop, op | 0x20, type) \
9077 GEN_LDU(name, ldop, op | 0x21, type) \
9078 GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
9079 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
9081 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
)
9082 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
)
9083 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
)
9084 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
)
9085 #if defined(TARGET_PPC64)
9086 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
)
9087 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
)
9088 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
)
9089 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
)
9090 GEN_LDX_E(ldbr
, ld64ur
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
)
9092 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
)
9093 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
)
9100 #define GEN_ST(name, stop, opc, type) \
9101 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9102 #define GEN_STU(name, stop, opc, type) \
9103 GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
9104 #define GEN_STUX(name, stop, opc2, opc3, type) \
9105 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
9106 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
9107 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
9108 #define GEN_STS(name, stop, op, type) \
9109 GEN_ST(name, stop, op | 0x20, type) \
9110 GEN_STU(name, stop, op | 0x21, type) \
9111 GEN_STUX(name, stop, 0x17, op | 0x01, type) \
9112 GEN_STX(name, stop, 0x17, op | 0x00, type)
9114 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
)
9115 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
)
9116 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
)
9117 #if defined(TARGET_PPC64)
9118 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
)
9119 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
)
9120 GEN_STX_E(stdbr
, st64r
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
)
9122 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
)
9123 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
)
9130 #define GEN_LDF(name, ldop, opc, type) \
9131 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9132 #define GEN_LDUF(name, ldop, opc, type) \
9133 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
9134 #define GEN_LDUXF(name, ldop, opc, type) \
9135 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
9136 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
9137 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
9138 #define GEN_LDFS(name, ldop, op, type) \
9139 GEN_LDF(name, ldop, op | 0x20, type) \
9140 GEN_LDUF(name, ldop, op | 0x21, type) \
9141 GEN_LDUXF(name, ldop, op | 0x01, type) \
9142 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
9144 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
)
9145 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
)
9146 GEN_HANDLER_E(lfiwax
, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE
, PPC2_ISA205
),
9147 GEN_HANDLER_E(lfdp
, 0x39, 0xFF, 0xFF, 0x00200003, PPC_NONE
, PPC2_ISA205
),
9148 GEN_HANDLER_E(lfdpx
, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE
, PPC2_ISA205
),
9155 #define GEN_STF(name, stop, opc, type) \
9156 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9157 #define GEN_STUF(name, stop, opc, type) \
9158 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
9159 #define GEN_STUXF(name, stop, opc, type) \
9160 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
9161 #define GEN_STXF(name, stop, opc2, opc3, type) \
9162 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
9163 #define GEN_STFS(name, stop, op, type) \
9164 GEN_STF(name, stop, op | 0x20, type) \
9165 GEN_STUF(name, stop, op | 0x21, type) \
9166 GEN_STUXF(name, stop, op | 0x01, type) \
9167 GEN_STXF(name, stop, 0x17, op | 0x00, type)
9169 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
)
9170 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
)
9171 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
)
9172 GEN_HANDLER_E(stfdp
, 0x3D, 0xFF, 0xFF, 0x00200003, PPC_NONE
, PPC2_ISA205
),
9173 GEN_HANDLER_E(stfdpx
, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE
, PPC2_ISA205
),
9176 #define GEN_CRLOGIC(name, tcg_op, opc) \
9177 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
9178 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08),
9179 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04),
9180 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09),
9181 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07),
9182 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01),
9183 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E),
9184 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D),
9185 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06),
9187 #undef GEN_MAC_HANDLER
9188 #define GEN_MAC_HANDLER(name, opc2, opc3) \
9189 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
9190 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05),
9191 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15),
9192 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07),
9193 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17),
9194 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06),
9195 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16),
9196 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04),
9197 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14),
9198 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01),
9199 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11),
9200 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03),
9201 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13),
9202 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02),
9203 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12),
9204 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00),
9205 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10),
9206 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D),
9207 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D),
9208 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F),
9209 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F),
9210 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C),
9211 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C),
9212 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E),
9213 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E),
9214 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05),
9215 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15),
9216 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07),
9217 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17),
9218 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01),
9219 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11),
9220 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03),
9221 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13),
9222 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D),
9223 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D),
9224 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F),
9225 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F),
9226 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05),
9227 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04),
9228 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01),
9229 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00),
9230 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D),
9231 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C),
9237 #define GEN_VR_LDX(name, opc2, opc3) \
9238 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9239 #define GEN_VR_STX(name, opc2, opc3) \
9240 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9241 #define GEN_VR_LVE(name, opc2, opc3) \
9242 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9243 #define GEN_VR_STVE(name, opc2, opc3) \
9244 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9245 GEN_VR_LDX(lvx
, 0x07, 0x03),
9246 GEN_VR_LDX(lvxl
, 0x07, 0x0B),
9247 GEN_VR_LVE(bx
, 0x07, 0x00),
9248 GEN_VR_LVE(hx
, 0x07, 0x01),
9249 GEN_VR_LVE(wx
, 0x07, 0x02),
9250 GEN_VR_STX(svx
, 0x07, 0x07),
9251 GEN_VR_STX(svxl
, 0x07, 0x0F),
9252 GEN_VR_STVE(bx
, 0x07, 0x04),
9253 GEN_VR_STVE(hx
, 0x07, 0x05),
9254 GEN_VR_STVE(wx
, 0x07, 0x06),
9256 #undef GEN_VX_LOGICAL
9257 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
9258 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9259 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16),
9260 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17),
9261 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18),
9262 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19),
9263 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20),
9266 #define GEN_VXFORM(name, opc2, opc3) \
9267 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9268 GEN_VXFORM(vaddubm
, 0, 0),
9269 GEN_VXFORM(vadduhm
, 0, 1),
9270 GEN_VXFORM(vadduwm
, 0, 2),
9271 GEN_VXFORM(vsububm
, 0, 16),
9272 GEN_VXFORM(vsubuhm
, 0, 17),
9273 GEN_VXFORM(vsubuwm
, 0, 18),
9274 GEN_VXFORM(vmaxub
, 1, 0),
9275 GEN_VXFORM(vmaxuh
, 1, 1),
9276 GEN_VXFORM(vmaxuw
, 1, 2),
9277 GEN_VXFORM(vmaxsb
, 1, 4),
9278 GEN_VXFORM(vmaxsh
, 1, 5),
9279 GEN_VXFORM(vmaxsw
, 1, 6),
9280 GEN_VXFORM(vminub
, 1, 8),
9281 GEN_VXFORM(vminuh
, 1, 9),
9282 GEN_VXFORM(vminuw
, 1, 10),
9283 GEN_VXFORM(vminsb
, 1, 12),
9284 GEN_VXFORM(vminsh
, 1, 13),
9285 GEN_VXFORM(vminsw
, 1, 14),
9286 GEN_VXFORM(vavgub
, 1, 16),
9287 GEN_VXFORM(vavguh
, 1, 17),
9288 GEN_VXFORM(vavguw
, 1, 18),
9289 GEN_VXFORM(vavgsb
, 1, 20),
9290 GEN_VXFORM(vavgsh
, 1, 21),
9291 GEN_VXFORM(vavgsw
, 1, 22),
9292 GEN_VXFORM(vmrghb
, 6, 0),
9293 GEN_VXFORM(vmrghh
, 6, 1),
9294 GEN_VXFORM(vmrghw
, 6, 2),
9295 GEN_VXFORM(vmrglb
, 6, 4),
9296 GEN_VXFORM(vmrglh
, 6, 5),
9297 GEN_VXFORM(vmrglw
, 6, 6),
9298 GEN_VXFORM(vmuloub
, 4, 0),
9299 GEN_VXFORM(vmulouh
, 4, 1),
9300 GEN_VXFORM(vmulosb
, 4, 4),
9301 GEN_VXFORM(vmulosh
, 4, 5),
9302 GEN_VXFORM(vmuleub
, 4, 8),
9303 GEN_VXFORM(vmuleuh
, 4, 9),
9304 GEN_VXFORM(vmulesb
, 4, 12),
9305 GEN_VXFORM(vmulesh
, 4, 13),
9306 GEN_VXFORM(vslb
, 2, 4),
9307 GEN_VXFORM(vslh
, 2, 5),
9308 GEN_VXFORM(vslw
, 2, 6),
9309 GEN_VXFORM(vsrb
, 2, 8),
9310 GEN_VXFORM(vsrh
, 2, 9),
9311 GEN_VXFORM(vsrw
, 2, 10),
9312 GEN_VXFORM(vsrab
, 2, 12),
9313 GEN_VXFORM(vsrah
, 2, 13),
9314 GEN_VXFORM(vsraw
, 2, 14),
9315 GEN_VXFORM(vslo
, 6, 16),
9316 GEN_VXFORM(vsro
, 6, 17),
9317 GEN_VXFORM(vaddcuw
, 0, 6),
9318 GEN_VXFORM(vsubcuw
, 0, 22),
9319 GEN_VXFORM(vaddubs
, 0, 8),
9320 GEN_VXFORM(vadduhs
, 0, 9),
9321 GEN_VXFORM(vadduws
, 0, 10),
9322 GEN_VXFORM(vaddsbs
, 0, 12),
9323 GEN_VXFORM(vaddshs
, 0, 13),
9324 GEN_VXFORM(vaddsws
, 0, 14),
9325 GEN_VXFORM(vsububs
, 0, 24),
9326 GEN_VXFORM(vsubuhs
, 0, 25),
9327 GEN_VXFORM(vsubuws
, 0, 26),
9328 GEN_VXFORM(vsubsbs
, 0, 28),
9329 GEN_VXFORM(vsubshs
, 0, 29),
9330 GEN_VXFORM(vsubsws
, 0, 30),
9331 GEN_VXFORM(vrlb
, 2, 0),
9332 GEN_VXFORM(vrlh
, 2, 1),
9333 GEN_VXFORM(vrlw
, 2, 2),
9334 GEN_VXFORM(vsl
, 2, 7),
9335 GEN_VXFORM(vsr
, 2, 11),
9336 GEN_VXFORM(vpkuhum
, 7, 0),
9337 GEN_VXFORM(vpkuwum
, 7, 1),
9338 GEN_VXFORM(vpkuhus
, 7, 2),
9339 GEN_VXFORM(vpkuwus
, 7, 3),
9340 GEN_VXFORM(vpkshus
, 7, 4),
9341 GEN_VXFORM(vpkswus
, 7, 5),
9342 GEN_VXFORM(vpkshss
, 7, 6),
9343 GEN_VXFORM(vpkswss
, 7, 7),
9344 GEN_VXFORM(vpkpx
, 7, 12),
9345 GEN_VXFORM(vsum4ubs
, 4, 24),
9346 GEN_VXFORM(vsum4sbs
, 4, 28),
9347 GEN_VXFORM(vsum4shs
, 4, 25),
9348 GEN_VXFORM(vsum2sws
, 4, 26),
9349 GEN_VXFORM(vsumsws
, 4, 30),
9350 GEN_VXFORM(vaddfp
, 5, 0),
9351 GEN_VXFORM(vsubfp
, 5, 1),
9352 GEN_VXFORM(vmaxfp
, 5, 16),
9353 GEN_VXFORM(vminfp
, 5, 17),
9357 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
9358 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
9359 #define GEN_VXRFORM(name, opc2, opc3) \
9360 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
9361 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
9362 GEN_VXRFORM(vcmpequb
, 3, 0)
9363 GEN_VXRFORM(vcmpequh
, 3, 1)
9364 GEN_VXRFORM(vcmpequw
, 3, 2)
9365 GEN_VXRFORM(vcmpgtsb
, 3, 12)
9366 GEN_VXRFORM(vcmpgtsh
, 3, 13)
9367 GEN_VXRFORM(vcmpgtsw
, 3, 14)
9368 GEN_VXRFORM(vcmpgtub
, 3, 8)
9369 GEN_VXRFORM(vcmpgtuh
, 3, 9)
9370 GEN_VXRFORM(vcmpgtuw
, 3, 10)
9371 GEN_VXRFORM(vcmpeqfp
, 3, 3)
9372 GEN_VXRFORM(vcmpgefp
, 3, 7)
9373 GEN_VXRFORM(vcmpgtfp
, 3, 11)
9374 GEN_VXRFORM(vcmpbfp
, 3, 15)
9376 #undef GEN_VXFORM_SIMM
9377 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
9378 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9379 GEN_VXFORM_SIMM(vspltisb
, 6, 12),
9380 GEN_VXFORM_SIMM(vspltish
, 6, 13),
9381 GEN_VXFORM_SIMM(vspltisw
, 6, 14),
9383 #undef GEN_VXFORM_NOA
9384 #define GEN_VXFORM_NOA(name, opc2, opc3) \
9385 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
9386 GEN_VXFORM_NOA(vupkhsb
, 7, 8),
9387 GEN_VXFORM_NOA(vupkhsh
, 7, 9),
9388 GEN_VXFORM_NOA(vupklsb
, 7, 10),
9389 GEN_VXFORM_NOA(vupklsh
, 7, 11),
9390 GEN_VXFORM_NOA(vupkhpx
, 7, 13),
9391 GEN_VXFORM_NOA(vupklpx
, 7, 15),
9392 GEN_VXFORM_NOA(vrefp
, 5, 4),
9393 GEN_VXFORM_NOA(vrsqrtefp
, 5, 5),
9394 GEN_VXFORM_NOA(vexptefp
, 5, 6),
9395 GEN_VXFORM_NOA(vlogefp
, 5, 7),
9396 GEN_VXFORM_NOA(vrfim
, 5, 8),
9397 GEN_VXFORM_NOA(vrfin
, 5, 9),
9398 GEN_VXFORM_NOA(vrfip
, 5, 10),
9399 GEN_VXFORM_NOA(vrfiz
, 5, 11),
9401 #undef GEN_VXFORM_UIMM
9402 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
9403 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9404 GEN_VXFORM_UIMM(vspltb
, 6, 8),
9405 GEN_VXFORM_UIMM(vsplth
, 6, 9),
9406 GEN_VXFORM_UIMM(vspltw
, 6, 10),
9407 GEN_VXFORM_UIMM(vcfux
, 5, 12),
9408 GEN_VXFORM_UIMM(vcfsx
, 5, 13),
9409 GEN_VXFORM_UIMM(vctuxs
, 5, 14),
9410 GEN_VXFORM_UIMM(vctsxs
, 5, 15),
9412 #undef GEN_VAFORM_PAIRED
9413 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
9414 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
9415 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16),
9416 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18),
9417 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19),
9418 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20),
9419 GEN_VAFORM_PAIRED(vsel
, vperm
, 21),
9420 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23),
9423 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
9424 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
9425 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9426 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9427 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9428 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9429 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
9430 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
9431 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
9432 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE
),
9433 GEN_SPE(evmra
, speundef
, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE
),
9434 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
),
9435 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9436 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9437 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9438 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE
),
9439 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE
),
9440 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE
),
9441 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
),
9442 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9443 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9444 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9445 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9446 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9447 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE
),
9448 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE
),
9449 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9450 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9451 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE
),
9452 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE
),
9453 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE
),
9455 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9456 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
),
9457 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9458 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9459 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9460 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9461 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9462 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9463 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9464 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9465 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9466 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9467 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9468 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9470 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9471 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
),
9472 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9473 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9474 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9475 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE
),
9476 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9477 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9478 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9479 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9480 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9481 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9482 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9483 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9485 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
),
9486 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9487 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE
),
9488 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9489 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
),
9490 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9491 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
),
9492 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE
),
9493 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9494 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9495 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9496 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9497 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9498 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9499 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
),
9500 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9502 #undef GEN_SPEOP_LDST
9503 #define GEN_SPEOP_LDST(name, opc2, sh) \
9504 GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
9505 GEN_SPEOP_LDST(evldd
, 0x00, 3),
9506 GEN_SPEOP_LDST(evldw
, 0x01, 3),
9507 GEN_SPEOP_LDST(evldh
, 0x02, 3),
9508 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1),
9509 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1),
9510 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1),
9511 GEN_SPEOP_LDST(evlwhe
, 0x08, 2),
9512 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2),
9513 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2),
9514 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2),
9515 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2),
9517 GEN_SPEOP_LDST(evstdd
, 0x10, 3),
9518 GEN_SPEOP_LDST(evstdw
, 0x11, 3),
9519 GEN_SPEOP_LDST(evstdh
, 0x12, 3),
9520 GEN_SPEOP_LDST(evstwhe
, 0x18, 2),
9521 GEN_SPEOP_LDST(evstwho
, 0x1A, 2),
9522 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2),
9523 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2),
9526 #include "helper_regs.h"
9527 #include "translate_init.c"
9529 /*****************************************************************************/
9530 /* Misc PowerPC helpers */
9531 void cpu_dump_state (CPUPPCState
*env
, FILE *f
, fprintf_function cpu_fprintf
,
9539 cpu_synchronize_state(env
);
9541 cpu_fprintf(f
, "NIP " TARGET_FMT_lx
" LR " TARGET_FMT_lx
" CTR "
9542 TARGET_FMT_lx
" XER " TARGET_FMT_lx
"\n",
9543 env
->nip
, env
->lr
, env
->ctr
, cpu_read_xer(env
));
9544 cpu_fprintf(f
, "MSR " TARGET_FMT_lx
" HID0 " TARGET_FMT_lx
" HF "
9545 TARGET_FMT_lx
" idx %d\n", env
->msr
, env
->spr
[SPR_HID0
],
9546 env
->hflags
, env
->mmu_idx
);
9547 #if !defined(NO_TIMER_DUMP)
9548 cpu_fprintf(f
, "TB %08" PRIu32
" %08" PRIu64
9549 #if !defined(CONFIG_USER_ONLY)
9553 cpu_ppc_load_tbu(env
), cpu_ppc_load_tbl(env
)
9554 #if !defined(CONFIG_USER_ONLY)
9555 , cpu_ppc_load_decr(env
)
9559 for (i
= 0; i
< 32; i
++) {
9560 if ((i
& (RGPL
- 1)) == 0)
9561 cpu_fprintf(f
, "GPR%02d", i
);
9562 cpu_fprintf(f
, " %016" PRIx64
, ppc_dump_gpr(env
, i
));
9563 if ((i
& (RGPL
- 1)) == (RGPL
- 1))
9564 cpu_fprintf(f
, "\n");
9566 cpu_fprintf(f
, "CR ");
9567 for (i
= 0; i
< 8; i
++)
9568 cpu_fprintf(f
, "%01x", env
->crf
[i
]);
9569 cpu_fprintf(f
, " [");
9570 for (i
= 0; i
< 8; i
++) {
9572 if (env
->crf
[i
] & 0x08)
9574 else if (env
->crf
[i
] & 0x04)
9576 else if (env
->crf
[i
] & 0x02)
9578 cpu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
9580 cpu_fprintf(f
, " ] RES " TARGET_FMT_lx
"\n",
9582 for (i
= 0; i
< 32; i
++) {
9583 if ((i
& (RFPL
- 1)) == 0)
9584 cpu_fprintf(f
, "FPR%02d", i
);
9585 cpu_fprintf(f
, " %016" PRIx64
, *((uint64_t *)&env
->fpr
[i
]));
9586 if ((i
& (RFPL
- 1)) == (RFPL
- 1))
9587 cpu_fprintf(f
, "\n");
9589 cpu_fprintf(f
, "FPSCR " TARGET_FMT_lx
"\n", env
->fpscr
);
9590 #if !defined(CONFIG_USER_ONLY)
9591 cpu_fprintf(f
, " SRR0 " TARGET_FMT_lx
" SRR1 " TARGET_FMT_lx
9592 " PVR " TARGET_FMT_lx
" VRSAVE " TARGET_FMT_lx
"\n",
9593 env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
9594 env
->spr
[SPR_PVR
], env
->spr
[SPR_VRSAVE
]);
9596 cpu_fprintf(f
, "SPRG0 " TARGET_FMT_lx
" SPRG1 " TARGET_FMT_lx
9597 " SPRG2 " TARGET_FMT_lx
" SPRG3 " TARGET_FMT_lx
"\n",
9598 env
->spr
[SPR_SPRG0
], env
->spr
[SPR_SPRG1
],
9599 env
->spr
[SPR_SPRG2
], env
->spr
[SPR_SPRG3
]);
9601 cpu_fprintf(f
, "SPRG4 " TARGET_FMT_lx
" SPRG5 " TARGET_FMT_lx
9602 " SPRG6 " TARGET_FMT_lx
" SPRG7 " TARGET_FMT_lx
"\n",
9603 env
->spr
[SPR_SPRG4
], env
->spr
[SPR_SPRG5
],
9604 env
->spr
[SPR_SPRG6
], env
->spr
[SPR_SPRG7
]);
9606 if (env
->excp_model
== POWERPC_EXCP_BOOKE
) {
9607 cpu_fprintf(f
, "CSRR0 " TARGET_FMT_lx
" CSRR1 " TARGET_FMT_lx
9608 " MCSRR0 " TARGET_FMT_lx
" MCSRR1 " TARGET_FMT_lx
"\n",
9609 env
->spr
[SPR_BOOKE_CSRR0
], env
->spr
[SPR_BOOKE_CSRR1
],
9610 env
->spr
[SPR_BOOKE_MCSRR0
], env
->spr
[SPR_BOOKE_MCSRR1
]);
9612 cpu_fprintf(f
, " TCR " TARGET_FMT_lx
" TSR " TARGET_FMT_lx
9613 " ESR " TARGET_FMT_lx
" DEAR " TARGET_FMT_lx
"\n",
9614 env
->spr
[SPR_BOOKE_TCR
], env
->spr
[SPR_BOOKE_TSR
],
9615 env
->spr
[SPR_BOOKE_ESR
], env
->spr
[SPR_BOOKE_DEAR
]);
9617 cpu_fprintf(f
, " PIR " TARGET_FMT_lx
" DECAR " TARGET_FMT_lx
9618 " IVPR " TARGET_FMT_lx
" EPCR " TARGET_FMT_lx
"\n",
9619 env
->spr
[SPR_BOOKE_PIR
], env
->spr
[SPR_BOOKE_DECAR
],
9620 env
->spr
[SPR_BOOKE_IVPR
], env
->spr
[SPR_BOOKE_EPCR
]);
9622 cpu_fprintf(f
, " MCSR " TARGET_FMT_lx
" SPRG8 " TARGET_FMT_lx
9623 " EPR " TARGET_FMT_lx
"\n",
9624 env
->spr
[SPR_BOOKE_MCSR
], env
->spr
[SPR_BOOKE_SPRG8
],
9625 env
->spr
[SPR_BOOKE_EPR
]);
9628 cpu_fprintf(f
, " MCAR " TARGET_FMT_lx
" PID1 " TARGET_FMT_lx
9629 " PID2 " TARGET_FMT_lx
" SVR " TARGET_FMT_lx
"\n",
9630 env
->spr
[SPR_Exxx_MCAR
], env
->spr
[SPR_BOOKE_PID1
],
9631 env
->spr
[SPR_BOOKE_PID2
], env
->spr
[SPR_E500_SVR
]);
9634 * IVORs are left out as they are large and do not change often --
9635 * they can be read with "p $ivor0", "p $ivor1", etc.
9639 #if defined(TARGET_PPC64)
9640 if (env
->flags
& POWERPC_FLAG_CFAR
) {
9641 cpu_fprintf(f
, " CFAR " TARGET_FMT_lx
"\n", env
->cfar
);
9645 switch (env
->mmu_model
) {
9646 case POWERPC_MMU_32B
:
9647 case POWERPC_MMU_601
:
9648 case POWERPC_MMU_SOFT_6xx
:
9649 case POWERPC_MMU_SOFT_74xx
:
9650 #if defined(TARGET_PPC64)
9651 case POWERPC_MMU_64B
:
9653 cpu_fprintf(f
, " SDR1 " TARGET_FMT_lx
"\n", env
->spr
[SPR_SDR1
]);
9655 case POWERPC_MMU_BOOKE206
:
9656 cpu_fprintf(f
, " MAS0 " TARGET_FMT_lx
" MAS1 " TARGET_FMT_lx
9657 " MAS2 " TARGET_FMT_lx
" MAS3 " TARGET_FMT_lx
"\n",
9658 env
->spr
[SPR_BOOKE_MAS0
], env
->spr
[SPR_BOOKE_MAS1
],
9659 env
->spr
[SPR_BOOKE_MAS2
], env
->spr
[SPR_BOOKE_MAS3
]);
9661 cpu_fprintf(f
, " MAS4 " TARGET_FMT_lx
" MAS6 " TARGET_FMT_lx
9662 " MAS7 " TARGET_FMT_lx
" PID " TARGET_FMT_lx
"\n",
9663 env
->spr
[SPR_BOOKE_MAS4
], env
->spr
[SPR_BOOKE_MAS6
],
9664 env
->spr
[SPR_BOOKE_MAS7
], env
->spr
[SPR_BOOKE_PID
]);
9666 cpu_fprintf(f
, "MMUCFG " TARGET_FMT_lx
" TLB0CFG " TARGET_FMT_lx
9667 " TLB1CFG " TARGET_FMT_lx
"\n",
9668 env
->spr
[SPR_MMUCFG
], env
->spr
[SPR_BOOKE_TLB0CFG
],
9669 env
->spr
[SPR_BOOKE_TLB1CFG
]);
9680 void cpu_dump_statistics (CPUPPCState
*env
, FILE*f
, fprintf_function cpu_fprintf
,
9683 #if defined(DO_PPC_STATISTICS)
9684 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
9688 for (op1
= 0; op1
< 64; op1
++) {
9690 if (is_indirect_opcode(handler
)) {
9691 t2
= ind_table(handler
);
9692 for (op2
= 0; op2
< 32; op2
++) {
9694 if (is_indirect_opcode(handler
)) {
9695 t3
= ind_table(handler
);
9696 for (op3
= 0; op3
< 32; op3
++) {
9698 if (handler
->count
== 0)
9700 cpu_fprintf(f
, "%02x %02x %02x (%02x %04d) %16s: "
9701 "%016" PRIx64
" %" PRId64
"\n",
9702 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
9704 handler
->count
, handler
->count
);
9707 if (handler
->count
== 0)
9709 cpu_fprintf(f
, "%02x %02x (%02x %04d) %16s: "
9710 "%016" PRIx64
" %" PRId64
"\n",
9711 op1
, op2
, op1
, op2
, handler
->oname
,
9712 handler
->count
, handler
->count
);
9716 if (handler
->count
== 0)
9718 cpu_fprintf(f
, "%02x (%02x ) %16s: %016" PRIx64
9720 op1
, op1
, handler
->oname
,
9721 handler
->count
, handler
->count
);
9727 /*****************************************************************************/
9728 static inline void gen_intermediate_code_internal(CPUPPCState
*env
,
9729 TranslationBlock
*tb
,
9732 DisasContext ctx
, *ctxp
= &ctx
;
9733 opc_handler_t
**table
, *handler
;
9734 target_ulong pc_start
;
9735 uint16_t *gen_opc_end
;
9742 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
9745 ctx
.exception
= POWERPC_EXCP_NONE
;
9746 ctx
.spr_cb
= env
->spr_cb
;
9747 ctx
.mem_idx
= env
->mmu_idx
;
9748 ctx
.insns_flags
= env
->insns_flags
;
9749 ctx
.insns_flags2
= env
->insns_flags2
;
9750 ctx
.access_type
= -1;
9751 ctx
.le_mode
= env
->hflags
& (1 << MSR_LE
) ? 1 : 0;
9752 #if defined(TARGET_PPC64)
9753 ctx
.sf_mode
= msr_is_64bit(env
, env
->msr
);
9754 ctx
.has_cfar
= !!(env
->flags
& POWERPC_FLAG_CFAR
);
9756 ctx
.fpu_enabled
= msr_fp
;
9757 if ((env
->flags
& POWERPC_FLAG_SPE
) && msr_spe
)
9758 ctx
.spe_enabled
= msr_spe
;
9760 ctx
.spe_enabled
= 0;
9761 if ((env
->flags
& POWERPC_FLAG_VRE
) && msr_vr
)
9762 ctx
.altivec_enabled
= msr_vr
;
9764 ctx
.altivec_enabled
= 0;
9765 if ((env
->flags
& POWERPC_FLAG_SE
) && msr_se
)
9766 ctx
.singlestep_enabled
= CPU_SINGLE_STEP
;
9768 ctx
.singlestep_enabled
= 0;
9769 if ((env
->flags
& POWERPC_FLAG_BE
) && msr_be
)
9770 ctx
.singlestep_enabled
|= CPU_BRANCH_STEP
;
9771 if (unlikely(env
->singlestep_enabled
))
9772 ctx
.singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
9773 #if defined (DO_SINGLE_STEP) && 0
9774 /* Single step trace mode */
9778 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
9780 max_insns
= CF_COUNT_MASK
;
9783 /* Set env in case of segfault during code fetch */
9784 while (ctx
.exception
== POWERPC_EXCP_NONE
9785 && tcg_ctx
.gen_opc_ptr
< gen_opc_end
) {
9786 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
9787 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
9788 if (bp
->pc
== ctx
.nip
) {
9789 gen_debug_exception(ctxp
);
9794 if (unlikely(search_pc
)) {
9795 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
9799 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
9801 tcg_ctx
.gen_opc_pc
[lj
] = ctx
.nip
;
9802 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
9803 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
9805 LOG_DISAS("----------------\n");
9806 LOG_DISAS("nip=" TARGET_FMT_lx
" super=%d ir=%d\n",
9807 ctx
.nip
, ctx
.mem_idx
, (int)msr_ir
);
9808 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
9810 if (unlikely(ctx
.le_mode
)) {
9811 ctx
.opcode
= bswap32(cpu_ldl_code(env
, ctx
.nip
));
9813 ctx
.opcode
= cpu_ldl_code(env
, ctx
.nip
);
9815 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
9816 ctx
.opcode
, opc1(ctx
.opcode
), opc2(ctx
.opcode
),
9817 opc3(ctx
.opcode
), ctx
.le_mode
? "little" : "big");
9818 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
9819 tcg_gen_debug_insn_start(ctx
.nip
);
9822 table
= env
->opcodes
;
9824 handler
= table
[opc1(ctx
.opcode
)];
9825 if (is_indirect_opcode(handler
)) {
9826 table
= ind_table(handler
);
9827 handler
= table
[opc2(ctx
.opcode
)];
9828 if (is_indirect_opcode(handler
)) {
9829 table
= ind_table(handler
);
9830 handler
= table
[opc3(ctx
.opcode
)];
9833 /* Is opcode *REALLY* valid ? */
9834 if (unlikely(handler
->handler
== &gen_invalid
)) {
9835 if (qemu_log_enabled()) {
9836 qemu_log("invalid/unsupported opcode: "
9837 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx
" %d\n",
9838 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
9839 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
9844 if (unlikely(handler
->type
& (PPC_SPE
| PPC_SPE_SINGLE
| PPC_SPE_DOUBLE
) && Rc(ctx
.opcode
))) {
9845 inval
= handler
->inval2
;
9847 inval
= handler
->inval1
;
9850 if (unlikely((ctx
.opcode
& inval
) != 0)) {
9851 if (qemu_log_enabled()) {
9852 qemu_log("invalid bits: %08x for opcode: "
9853 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx
"\n",
9854 ctx
.opcode
& inval
, opc1(ctx
.opcode
),
9855 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
9856 ctx
.opcode
, ctx
.nip
- 4);
9858 gen_inval_exception(ctxp
, POWERPC_EXCP_INVAL_INVAL
);
9862 (*(handler
->handler
))(&ctx
);
9863 #if defined(DO_PPC_STATISTICS)
9866 /* Check trace mode exceptions */
9867 if (unlikely(ctx
.singlestep_enabled
& CPU_SINGLE_STEP
&&
9868 (ctx
.nip
<= 0x100 || ctx
.nip
> 0xF00) &&
9869 ctx
.exception
!= POWERPC_SYSCALL
&&
9870 ctx
.exception
!= POWERPC_EXCP_TRAP
&&
9871 ctx
.exception
!= POWERPC_EXCP_BRANCH
)) {
9872 gen_exception(ctxp
, POWERPC_EXCP_TRACE
);
9873 } else if (unlikely(((ctx
.nip
& (TARGET_PAGE_SIZE
- 1)) == 0) ||
9874 (env
->singlestep_enabled
) ||
9876 num_insns
>= max_insns
)) {
9877 /* if we reach a page boundary or are single stepping, stop
9883 if (tb
->cflags
& CF_LAST_IO
)
9885 if (ctx
.exception
== POWERPC_EXCP_NONE
) {
9886 gen_goto_tb(&ctx
, 0, ctx
.nip
);
9887 } else if (ctx
.exception
!= POWERPC_EXCP_BRANCH
) {
9888 if (unlikely(env
->singlestep_enabled
)) {
9889 gen_debug_exception(ctxp
);
9891 /* Generate the return instruction */
9894 gen_tb_end(tb
, num_insns
);
9895 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
9896 if (unlikely(search_pc
)) {
9897 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
9900 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
9902 tb
->size
= ctx
.nip
- pc_start
;
9903 tb
->icount
= num_insns
;
9905 #if defined(DEBUG_DISAS)
9906 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
9908 flags
= env
->bfd_mach
;
9909 flags
|= ctx
.le_mode
<< 16;
9910 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
9911 log_target_disas(env
, pc_start
, ctx
.nip
- pc_start
, flags
);
9917 void gen_intermediate_code (CPUPPCState
*env
, struct TranslationBlock
*tb
)
9919 gen_intermediate_code_internal(env
, tb
, 0);
9922 void gen_intermediate_code_pc (CPUPPCState
*env
, struct TranslationBlock
*tb
)
9924 gen_intermediate_code_internal(env
, tb
, 1);
9927 void restore_state_to_opc(CPUPPCState
*env
, TranslationBlock
*tb
, int pc_pos
)
9929 env
->nip
= tcg_ctx
.gen_opc_pc
[pc_pos
];