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
;
207 struct opc_handler_t
{
208 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
210 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
212 /* instruction type */
214 /* extended instruction type */
217 void (*handler
)(DisasContext
*ctx
);
218 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
221 #if defined(DO_PPC_STATISTICS)
226 static inline void gen_reset_fpstatus(void)
228 gen_helper_reset_fpstatus(cpu_env
);
231 static inline void gen_compute_fprf(TCGv_i64 arg
, int set_fprf
, int set_rc
)
233 TCGv_i32 t0
= tcg_temp_new_i32();
236 /* This case might be optimized later */
237 tcg_gen_movi_i32(t0
, 1);
238 gen_helper_compute_fprf(t0
, cpu_env
, arg
, t0
);
239 if (unlikely(set_rc
)) {
240 tcg_gen_mov_i32(cpu_crf
[1], t0
);
242 gen_helper_float_check_status(cpu_env
);
243 } else if (unlikely(set_rc
)) {
244 /* We always need to compute fpcc */
245 tcg_gen_movi_i32(t0
, 0);
246 gen_helper_compute_fprf(t0
, cpu_env
, arg
, t0
);
247 tcg_gen_mov_i32(cpu_crf
[1], t0
);
250 tcg_temp_free_i32(t0
);
253 static inline void gen_set_access_type(DisasContext
*ctx
, int access_type
)
255 if (ctx
->access_type
!= access_type
) {
256 tcg_gen_movi_i32(cpu_access_type
, access_type
);
257 ctx
->access_type
= access_type
;
261 static inline void gen_update_nip(DisasContext
*ctx
, target_ulong nip
)
263 #if defined(TARGET_PPC64)
265 tcg_gen_movi_tl(cpu_nip
, nip
);
268 tcg_gen_movi_tl(cpu_nip
, (uint32_t)nip
);
271 static inline void gen_exception_err(DisasContext
*ctx
, uint32_t excp
, uint32_t error
)
274 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
275 gen_update_nip(ctx
, ctx
->nip
);
277 t0
= tcg_const_i32(excp
);
278 t1
= tcg_const_i32(error
);
279 gen_helper_raise_exception_err(cpu_env
, t0
, t1
);
280 tcg_temp_free_i32(t0
);
281 tcg_temp_free_i32(t1
);
282 ctx
->exception
= (excp
);
285 static inline void gen_exception(DisasContext
*ctx
, uint32_t excp
)
288 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
289 gen_update_nip(ctx
, ctx
->nip
);
291 t0
= tcg_const_i32(excp
);
292 gen_helper_raise_exception(cpu_env
, t0
);
293 tcg_temp_free_i32(t0
);
294 ctx
->exception
= (excp
);
297 static inline void gen_debug_exception(DisasContext
*ctx
)
301 if ((ctx
->exception
!= POWERPC_EXCP_BRANCH
) &&
302 (ctx
->exception
!= POWERPC_EXCP_SYNC
)) {
303 gen_update_nip(ctx
, ctx
->nip
);
305 t0
= tcg_const_i32(EXCP_DEBUG
);
306 gen_helper_raise_exception(cpu_env
, t0
);
307 tcg_temp_free_i32(t0
);
310 static inline void gen_inval_exception(DisasContext
*ctx
, uint32_t error
)
312 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_INVAL
| error
);
315 /* Stop translation */
316 static inline void gen_stop_exception(DisasContext
*ctx
)
318 gen_update_nip(ctx
, ctx
->nip
);
319 ctx
->exception
= POWERPC_EXCP_STOP
;
322 /* No need to update nip here, as execution flow will change */
323 static inline void gen_sync_exception(DisasContext
*ctx
)
325 ctx
->exception
= POWERPC_EXCP_SYNC
;
328 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
329 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
331 #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
332 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
334 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
335 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
337 #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
338 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
340 typedef struct opcode_t
{
341 unsigned char opc1
, opc2
, opc3
;
342 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
343 unsigned char pad
[5];
345 unsigned char pad
[1];
347 opc_handler_t handler
;
351 /*****************************************************************************/
352 /*** Instruction decoding ***/
353 #define EXTRACT_HELPER(name, shift, nb) \
354 static inline uint32_t name(uint32_t opcode) \
356 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
359 #define EXTRACT_SHELPER(name, shift, nb) \
360 static inline int32_t name(uint32_t opcode) \
362 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
366 EXTRACT_HELPER(opc1
, 26, 6);
368 EXTRACT_HELPER(opc2
, 1, 5);
370 EXTRACT_HELPER(opc3
, 6, 5);
371 /* Update Cr0 flags */
372 EXTRACT_HELPER(Rc
, 0, 1);
374 EXTRACT_HELPER(rD
, 21, 5);
376 EXTRACT_HELPER(rS
, 21, 5);
378 EXTRACT_HELPER(rA
, 16, 5);
380 EXTRACT_HELPER(rB
, 11, 5);
382 EXTRACT_HELPER(rC
, 6, 5);
384 EXTRACT_HELPER(crfD
, 23, 3);
385 EXTRACT_HELPER(crfS
, 18, 3);
386 EXTRACT_HELPER(crbD
, 21, 5);
387 EXTRACT_HELPER(crbA
, 16, 5);
388 EXTRACT_HELPER(crbB
, 11, 5);
390 EXTRACT_HELPER(_SPR
, 11, 10);
391 static inline uint32_t SPR(uint32_t opcode
)
393 uint32_t sprn
= _SPR(opcode
);
395 return ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
397 /*** Get constants ***/
398 EXTRACT_HELPER(IMM
, 12, 8);
399 /* 16 bits signed immediate value */
400 EXTRACT_SHELPER(SIMM
, 0, 16);
401 /* 16 bits unsigned immediate value */
402 EXTRACT_HELPER(UIMM
, 0, 16);
403 /* 5 bits signed immediate value */
404 EXTRACT_HELPER(SIMM5
, 16, 5);
405 /* 5 bits signed immediate value */
406 EXTRACT_HELPER(UIMM5
, 16, 5);
408 EXTRACT_HELPER(NB
, 11, 5);
410 EXTRACT_HELPER(SH
, 11, 5);
411 /* Vector shift count */
412 EXTRACT_HELPER(VSH
, 6, 4);
414 EXTRACT_HELPER(MB
, 6, 5);
416 EXTRACT_HELPER(ME
, 1, 5);
418 EXTRACT_HELPER(TO
, 21, 5);
420 EXTRACT_HELPER(CRM
, 12, 8);
421 EXTRACT_HELPER(FM
, 17, 8);
422 EXTRACT_HELPER(SR
, 16, 4);
423 EXTRACT_HELPER(FPIMM
, 12, 4);
425 /*** Jump target decoding ***/
427 EXTRACT_SHELPER(d
, 0, 16);
428 /* Immediate address */
429 static inline target_ulong
LI(uint32_t opcode
)
431 return (opcode
>> 0) & 0x03FFFFFC;
434 static inline uint32_t BD(uint32_t opcode
)
436 return (opcode
>> 0) & 0xFFFC;
439 EXTRACT_HELPER(BO
, 21, 5);
440 EXTRACT_HELPER(BI
, 16, 5);
441 /* Absolute/relative address */
442 EXTRACT_HELPER(AA
, 1, 1);
444 EXTRACT_HELPER(LK
, 0, 1);
446 /* Create a mask between <start> and <end> bits */
447 static inline target_ulong
MASK(uint32_t start
, uint32_t end
)
451 #if defined(TARGET_PPC64)
452 if (likely(start
== 0)) {
453 ret
= UINT64_MAX
<< (63 - end
);
454 } else if (likely(end
== 63)) {
455 ret
= UINT64_MAX
>> start
;
458 if (likely(start
== 0)) {
459 ret
= UINT32_MAX
<< (31 - end
);
460 } else if (likely(end
== 31)) {
461 ret
= UINT32_MAX
>> start
;
465 ret
= (((target_ulong
)(-1ULL)) >> (start
)) ^
466 (((target_ulong
)(-1ULL) >> (end
)) >> 1);
467 if (unlikely(start
> end
))
474 /*****************************************************************************/
475 /* PowerPC instructions table */
477 #if defined(DO_PPC_STATISTICS)
478 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
488 .handler = &gen_##name, \
489 .oname = stringify(name), \
491 .oname = stringify(name), \
493 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
504 .handler = &gen_##name, \
505 .oname = stringify(name), \
507 .oname = stringify(name), \
509 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
519 .handler = &gen_##name, \
525 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
535 .handler = &gen_##name, \
537 .oname = stringify(name), \
539 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
550 .handler = &gen_##name, \
552 .oname = stringify(name), \
554 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
564 .handler = &gen_##name, \
570 /* SPR load/store helpers */
571 static inline void gen_load_spr(TCGv t
, int reg
)
573 tcg_gen_ld_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
576 static inline void gen_store_spr(int reg
, TCGv t
)
578 tcg_gen_st_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
581 /* Invalid instruction */
582 static void gen_invalid(DisasContext
*ctx
)
584 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
587 static opc_handler_t invalid_handler
= {
588 .inval1
= 0xFFFFFFFF,
589 .inval2
= 0xFFFFFFFF,
592 .handler
= gen_invalid
,
595 /*** Integer comparison ***/
597 static inline void gen_op_cmp(TCGv arg0
, TCGv arg1
, int s
, int crf
)
599 TCGv t0
= tcg_temp_new();
600 TCGv_i32 t1
= tcg_temp_new_i32();
602 tcg_gen_trunc_tl_i32(cpu_crf
[crf
], cpu_so
);
604 tcg_gen_setcond_tl((s
? TCG_COND_LT
: TCG_COND_LTU
), t0
, arg0
, arg1
);
605 tcg_gen_trunc_tl_i32(t1
, t0
);
606 tcg_gen_shli_i32(t1
, t1
, CRF_LT
);
607 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
609 tcg_gen_setcond_tl((s
? TCG_COND_GT
: TCG_COND_GTU
), t0
, arg0
, arg1
);
610 tcg_gen_trunc_tl_i32(t1
, t0
);
611 tcg_gen_shli_i32(t1
, t1
, CRF_GT
);
612 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
614 tcg_gen_setcond_tl(TCG_COND_EQ
, t0
, arg0
, arg1
);
615 tcg_gen_trunc_tl_i32(t1
, t0
);
616 tcg_gen_shli_i32(t1
, t1
, CRF_EQ
);
617 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
620 tcg_temp_free_i32(t1
);
623 static inline void gen_op_cmpi(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
625 TCGv t0
= tcg_const_tl(arg1
);
626 gen_op_cmp(arg0
, t0
, s
, crf
);
630 #if defined(TARGET_PPC64)
631 static inline void gen_op_cmp32(TCGv arg0
, TCGv arg1
, int s
, int crf
)
637 tcg_gen_ext32s_tl(t0
, arg0
);
638 tcg_gen_ext32s_tl(t1
, arg1
);
640 tcg_gen_ext32u_tl(t0
, arg0
);
641 tcg_gen_ext32u_tl(t1
, arg1
);
643 gen_op_cmp(t0
, t1
, s
, crf
);
648 static inline void gen_op_cmpi32(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
650 TCGv t0
= tcg_const_tl(arg1
);
651 gen_op_cmp32(arg0
, t0
, s
, crf
);
656 static inline void gen_set_Rc0(DisasContext
*ctx
, TCGv reg
)
658 #if defined(TARGET_PPC64)
660 gen_op_cmpi32(reg
, 0, 1, 0);
663 gen_op_cmpi(reg
, 0, 1, 0);
667 static void gen_cmp(DisasContext
*ctx
)
669 #if defined(TARGET_PPC64)
670 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
671 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
672 1, crfD(ctx
->opcode
));
675 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
676 1, crfD(ctx
->opcode
));
680 static void gen_cmpi(DisasContext
*ctx
)
682 #if defined(TARGET_PPC64)
683 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
684 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
685 1, crfD(ctx
->opcode
));
688 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
689 1, crfD(ctx
->opcode
));
693 static void gen_cmpl(DisasContext
*ctx
)
695 #if defined(TARGET_PPC64)
696 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
697 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
698 0, crfD(ctx
->opcode
));
701 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
702 0, crfD(ctx
->opcode
));
706 static void gen_cmpli(DisasContext
*ctx
)
708 #if defined(TARGET_PPC64)
709 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
710 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
711 0, crfD(ctx
->opcode
));
714 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
715 0, crfD(ctx
->opcode
));
718 /* isel (PowerPC 2.03 specification) */
719 static void gen_isel(DisasContext
*ctx
)
722 uint32_t bi
= rC(ctx
->opcode
);
726 l1
= gen_new_label();
727 l2
= gen_new_label();
729 mask
= 1 << (3 - (bi
& 0x03));
730 t0
= tcg_temp_new_i32();
731 tcg_gen_andi_i32(t0
, cpu_crf
[bi
>> 2], mask
);
732 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
733 if (rA(ctx
->opcode
) == 0)
734 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
736 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
739 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
741 tcg_temp_free_i32(t0
);
744 /*** Integer arithmetic ***/
746 static inline void gen_op_arith_compute_ov(DisasContext
*ctx
, TCGv arg0
,
747 TCGv arg1
, TCGv arg2
, int sub
)
749 TCGv t0
= tcg_temp_new();
751 tcg_gen_xor_tl(cpu_ov
, arg0
, arg1
);
752 tcg_gen_xor_tl(t0
, arg1
, arg2
);
754 tcg_gen_and_tl(cpu_ov
, cpu_ov
, t0
);
756 tcg_gen_andc_tl(cpu_ov
, cpu_ov
, t0
);
759 #if defined(TARGET_PPC64)
761 tcg_gen_ext32s_tl(cpu_ov
, cpu_ov
);
764 tcg_gen_shri_tl(cpu_ov
, cpu_ov
, TARGET_LONG_BITS
- 1);
765 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
768 /* Common add function */
769 static inline void gen_op_arith_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
770 TCGv arg2
, bool add_ca
, bool compute_ca
,
771 bool compute_ov
, bool compute_rc0
)
775 if (((compute_ca
&& add_ca
) || compute_ov
)
776 && (TCGV_EQUAL(ret
, arg1
) || TCGV_EQUAL(ret
, arg2
))) {
781 TCGv zero
= tcg_const_tl(0);
783 tcg_gen_add2_tl(t0
, cpu_ca
, arg1
, zero
, cpu_ca
, zero
);
784 tcg_gen_add2_tl(t0
, cpu_ca
, t0
, cpu_ca
, arg2
, zero
);
786 tcg_gen_add2_tl(t0
, cpu_ca
, arg1
, zero
, arg2
, zero
);
790 tcg_gen_add_tl(t0
, arg1
, arg2
);
792 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
797 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 0);
799 if (unlikely(compute_rc0
)) {
800 gen_set_Rc0(ctx
, t0
);
803 if (!TCGV_EQUAL(t0
, ret
)) {
804 tcg_gen_mov_tl(ret
, t0
);
808 /* Add functions with two operands */
809 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
810 static void glue(gen_, name)(DisasContext *ctx) \
812 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
813 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
814 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
816 /* Add functions with one operand and one immediate */
817 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
818 add_ca, compute_ca, compute_ov) \
819 static void glue(gen_, name)(DisasContext *ctx) \
821 TCGv t0 = tcg_const_tl(const_val); \
822 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
823 cpu_gpr[rA(ctx->opcode)], t0, \
824 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
828 /* add add. addo addo. */
829 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
830 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
831 /* addc addc. addco addco. */
832 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
833 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
834 /* adde adde. addeo addeo. */
835 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
836 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
837 /* addme addme. addmeo addmeo. */
838 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
839 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
840 /* addze addze. addzeo addzeo.*/
841 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
842 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
844 static void gen_addi(DisasContext
*ctx
)
846 target_long simm
= SIMM(ctx
->opcode
);
848 if (rA(ctx
->opcode
) == 0) {
850 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
);
852 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)],
853 cpu_gpr
[rA(ctx
->opcode
)], simm
);
857 static inline void gen_op_addic(DisasContext
*ctx
, bool compute_rc0
)
859 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
860 gen_op_arith_add(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
861 c
, 0, 1, 0, compute_rc0
);
865 static void gen_addic(DisasContext
*ctx
)
867 gen_op_addic(ctx
, 0);
870 static void gen_addic_(DisasContext
*ctx
)
872 gen_op_addic(ctx
, 1);
876 static void gen_addis(DisasContext
*ctx
)
878 target_long simm
= SIMM(ctx
->opcode
);
880 if (rA(ctx
->opcode
) == 0) {
882 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
<< 16);
884 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)],
885 cpu_gpr
[rA(ctx
->opcode
)], simm
<< 16);
889 static inline void gen_op_arith_divw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
890 TCGv arg2
, int sign
, int compute_ov
)
892 int l1
= gen_new_label();
893 int l2
= gen_new_label();
894 TCGv_i32 t0
= tcg_temp_local_new_i32();
895 TCGv_i32 t1
= tcg_temp_local_new_i32();
897 tcg_gen_trunc_tl_i32(t0
, arg1
);
898 tcg_gen_trunc_tl_i32(t1
, arg2
);
899 tcg_gen_brcondi_i32(TCG_COND_EQ
, t1
, 0, l1
);
901 int l3
= gen_new_label();
902 tcg_gen_brcondi_i32(TCG_COND_NE
, t1
, -1, l3
);
903 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, INT32_MIN
, l1
);
905 tcg_gen_div_i32(t0
, t0
, t1
);
907 tcg_gen_divu_i32(t0
, t0
, t1
);
910 tcg_gen_movi_tl(cpu_ov
, 0);
915 tcg_gen_sari_i32(t0
, t0
, 31);
917 tcg_gen_movi_i32(t0
, 0);
920 tcg_gen_movi_tl(cpu_ov
, 1);
921 tcg_gen_movi_tl(cpu_so
, 1);
924 tcg_gen_extu_i32_tl(ret
, t0
);
925 tcg_temp_free_i32(t0
);
926 tcg_temp_free_i32(t1
);
927 if (unlikely(Rc(ctx
->opcode
) != 0))
928 gen_set_Rc0(ctx
, ret
);
931 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
932 static void glue(gen_, name)(DisasContext *ctx) \
934 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
935 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
938 /* divwu divwu. divwuo divwuo. */
939 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0);
940 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1);
941 /* divw divw. divwo divwo. */
942 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0);
943 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1);
944 #if defined(TARGET_PPC64)
945 static inline void gen_op_arith_divd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
946 TCGv arg2
, int sign
, int compute_ov
)
948 int l1
= gen_new_label();
949 int l2
= gen_new_label();
951 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg2
, 0, l1
);
953 int l3
= gen_new_label();
954 tcg_gen_brcondi_i64(TCG_COND_NE
, arg2
, -1, l3
);
955 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg1
, INT64_MIN
, l1
);
957 tcg_gen_div_i64(ret
, arg1
, arg2
);
959 tcg_gen_divu_i64(ret
, arg1
, arg2
);
962 tcg_gen_movi_tl(cpu_ov
, 0);
967 tcg_gen_sari_i64(ret
, arg1
, 63);
969 tcg_gen_movi_i64(ret
, 0);
972 tcg_gen_movi_tl(cpu_ov
, 1);
973 tcg_gen_movi_tl(cpu_so
, 1);
976 if (unlikely(Rc(ctx
->opcode
) != 0))
977 gen_set_Rc0(ctx
, ret
);
979 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
980 static void glue(gen_, name)(DisasContext *ctx) \
982 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
983 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
986 /* divwu divwu. divwuo divwuo. */
987 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0);
988 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1);
989 /* divw divw. divwo divwo. */
990 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0);
991 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1);
995 static void gen_mulhw(DisasContext
*ctx
)
997 TCGv_i32 t0
= tcg_temp_new_i32();
998 TCGv_i32 t1
= tcg_temp_new_i32();
1000 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1001 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1002 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1003 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1004 tcg_temp_free_i32(t0
);
1005 tcg_temp_free_i32(t1
);
1006 if (unlikely(Rc(ctx
->opcode
) != 0))
1007 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1010 /* mulhwu mulhwu. */
1011 static void gen_mulhwu(DisasContext
*ctx
)
1013 TCGv_i32 t0
= tcg_temp_new_i32();
1014 TCGv_i32 t1
= tcg_temp_new_i32();
1016 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1017 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1018 tcg_gen_mulu2_i32(t0
, t1
, t0
, t1
);
1019 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1020 tcg_temp_free_i32(t0
);
1021 tcg_temp_free_i32(t1
);
1022 if (unlikely(Rc(ctx
->opcode
) != 0))
1023 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1027 static void gen_mullw(DisasContext
*ctx
)
1029 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1030 cpu_gpr
[rB(ctx
->opcode
)]);
1031 tcg_gen_ext32s_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)]);
1032 if (unlikely(Rc(ctx
->opcode
) != 0))
1033 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1036 /* mullwo mullwo. */
1037 static void gen_mullwo(DisasContext
*ctx
)
1042 t0
= tcg_temp_new_i64();
1043 t1
= tcg_temp_new_i64();
1044 l1
= gen_new_label();
1045 /* Start with XER OV disabled, the most likely case */
1046 tcg_gen_movi_tl(cpu_ov
, 0);
1047 #if defined(TARGET_PPC64)
1048 tcg_gen_ext32s_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1049 tcg_gen_ext32s_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1051 tcg_gen_ext_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1052 tcg_gen_ext_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1054 tcg_gen_mul_i64(t0
, t0
, t1
);
1055 #if defined(TARGET_PPC64)
1056 tcg_gen_ext32s_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1057 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, cpu_gpr
[rD(ctx
->opcode
)], l1
);
1059 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1060 tcg_gen_ext32s_i64(t1
, t0
);
1061 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
1063 tcg_gen_movi_tl(cpu_ov
, 1);
1064 tcg_gen_movi_tl(cpu_so
, 1);
1066 tcg_temp_free_i64(t0
);
1067 tcg_temp_free_i64(t1
);
1068 if (unlikely(Rc(ctx
->opcode
) != 0))
1069 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1073 static void gen_mulli(DisasContext
*ctx
)
1075 tcg_gen_muli_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1079 #if defined(TARGET_PPC64)
1081 static void gen_mulhd(DisasContext
*ctx
)
1083 TCGv lo
= tcg_temp_new();
1084 tcg_gen_muls2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1085 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1087 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1088 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1092 /* mulhdu mulhdu. */
1093 static void gen_mulhdu(DisasContext
*ctx
)
1095 TCGv lo
= tcg_temp_new();
1096 tcg_gen_mulu2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1097 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1099 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1100 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1105 static void gen_mulld(DisasContext
*ctx
)
1107 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1108 cpu_gpr
[rB(ctx
->opcode
)]);
1109 if (unlikely(Rc(ctx
->opcode
) != 0))
1110 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1113 /* mulldo mulldo. */
1114 static void gen_mulldo(DisasContext
*ctx
)
1116 gen_helper_mulldo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
1117 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1118 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1119 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1124 /* neg neg. nego nego. */
1125 static inline void gen_op_arith_neg(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1128 int l1
= gen_new_label();
1129 int l2
= gen_new_label();
1130 TCGv t0
= tcg_temp_local_new();
1131 #if defined(TARGET_PPC64)
1133 tcg_gen_mov_tl(t0
, arg1
);
1134 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, INT64_MIN
, l1
);
1138 tcg_gen_ext32s_tl(t0
, arg1
);
1139 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, INT32_MIN
, l1
);
1141 tcg_gen_neg_tl(ret
, arg1
);
1143 tcg_gen_movi_tl(cpu_ov
, 0);
1147 tcg_gen_mov_tl(ret
, t0
);
1149 tcg_gen_movi_tl(cpu_ov
, 1);
1150 tcg_gen_movi_tl(cpu_so
, 1);
1154 if (unlikely(Rc(ctx
->opcode
) != 0))
1155 gen_set_Rc0(ctx
, ret
);
1158 static void gen_neg(DisasContext
*ctx
)
1160 gen_op_arith_neg(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0);
1163 static void gen_nego(DisasContext
*ctx
)
1165 gen_op_arith_neg(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 1);
1168 /* Common subf function */
1169 static inline void gen_op_arith_subf(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1170 TCGv arg2
, bool add_ca
, bool compute_ca
,
1171 bool compute_ov
, bool compute_rc0
)
1175 if (((add_ca
&& compute_ca
) || compute_ov
)
1176 && (TCGV_EQUAL(ret
, arg1
) || TCGV_EQUAL(ret
, arg2
))) {
1177 t0
= tcg_temp_new();
1181 /* dest = ~arg1 + arg2 + ca = arg2 - arg1 + ca - 1. */
1184 tcg_gen_subi_tl(cpu_ca
, cpu_ca
, 1);
1185 zero
= tcg_const_tl(0);
1186 tcg_gen_add2_tl(t0
, cpu_ca
, arg2
, zero
, cpu_ca
, zero
);
1187 tcg_gen_sub2_tl(t0
, cpu_ca
, t0
, cpu_ca
, arg1
, zero
);
1188 tcg_temp_free(zero
);
1190 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1191 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
1192 tcg_gen_subi_tl(t0
, t0
, 1);
1196 tcg_gen_setcond_tl(TCG_COND_GEU
, cpu_ca
, arg2
, arg1
);
1198 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1202 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 1);
1204 if (unlikely(compute_rc0
)) {
1205 gen_set_Rc0(ctx
, t0
);
1208 if (!TCGV_EQUAL(t0
, ret
)) {
1209 tcg_gen_mov_tl(ret
, t0
);
1213 /* Sub functions with Two operands functions */
1214 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1215 static void glue(gen_, name)(DisasContext *ctx) \
1217 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1218 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1219 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1221 /* Sub functions with one operand and one immediate */
1222 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1223 add_ca, compute_ca, compute_ov) \
1224 static void glue(gen_, name)(DisasContext *ctx) \
1226 TCGv t0 = tcg_const_tl(const_val); \
1227 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1228 cpu_gpr[rA(ctx->opcode)], t0, \
1229 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1230 tcg_temp_free(t0); \
1232 /* subf subf. subfo subfo. */
1233 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
1234 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
1235 /* subfc subfc. subfco subfco. */
1236 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
1237 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
1238 /* subfe subfe. subfeo subfo. */
1239 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
1240 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
1241 /* subfme subfme. subfmeo subfmeo. */
1242 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
1243 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
1244 /* subfze subfze. subfzeo subfzeo.*/
1245 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
1246 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
1249 static void gen_subfic(DisasContext
*ctx
)
1251 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
1252 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1257 /*** Integer logical ***/
1258 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1259 static void glue(gen_, name)(DisasContext *ctx) \
1261 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1262 cpu_gpr[rB(ctx->opcode)]); \
1263 if (unlikely(Rc(ctx->opcode) != 0)) \
1264 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1267 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1268 static void glue(gen_, name)(DisasContext *ctx) \
1270 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1271 if (unlikely(Rc(ctx->opcode) != 0)) \
1272 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1276 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
);
1278 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
);
1281 static void gen_andi_(DisasContext
*ctx
)
1283 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
));
1284 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1288 static void gen_andis_(DisasContext
*ctx
)
1290 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
) << 16);
1291 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1295 static void gen_cntlzw(DisasContext
*ctx
)
1297 gen_helper_cntlzw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1298 if (unlikely(Rc(ctx
->opcode
) != 0))
1299 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1302 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
);
1303 /* extsb & extsb. */
1304 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
);
1305 /* extsh & extsh. */
1306 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
);
1308 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
);
1310 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
);
1313 static void gen_or(DisasContext
*ctx
)
1317 rs
= rS(ctx
->opcode
);
1318 ra
= rA(ctx
->opcode
);
1319 rb
= rB(ctx
->opcode
);
1320 /* Optimisation for mr. ri case */
1321 if (rs
!= ra
|| rs
!= rb
) {
1323 tcg_gen_or_tl(cpu_gpr
[ra
], cpu_gpr
[rs
], cpu_gpr
[rb
]);
1325 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rs
]);
1326 if (unlikely(Rc(ctx
->opcode
) != 0))
1327 gen_set_Rc0(ctx
, cpu_gpr
[ra
]);
1328 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
1329 gen_set_Rc0(ctx
, cpu_gpr
[rs
]);
1330 #if defined(TARGET_PPC64)
1336 /* Set process priority to low */
1340 /* Set process priority to medium-low */
1344 /* Set process priority to normal */
1347 #if !defined(CONFIG_USER_ONLY)
1349 if (ctx
->mem_idx
> 0) {
1350 /* Set process priority to very low */
1355 if (ctx
->mem_idx
> 0) {
1356 /* Set process priority to medium-hight */
1361 if (ctx
->mem_idx
> 0) {
1362 /* Set process priority to high */
1367 if (ctx
->mem_idx
> 1) {
1368 /* Set process priority to very high */
1378 TCGv t0
= tcg_temp_new();
1379 gen_load_spr(t0
, SPR_PPR
);
1380 tcg_gen_andi_tl(t0
, t0
, ~0x001C000000000000ULL
);
1381 tcg_gen_ori_tl(t0
, t0
, ((uint64_t)prio
) << 50);
1382 gen_store_spr(SPR_PPR
, t0
);
1389 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
);
1392 static void gen_xor(DisasContext
*ctx
)
1394 /* Optimisation for "set to zero" case */
1395 if (rS(ctx
->opcode
) != rB(ctx
->opcode
))
1396 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1398 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1399 if (unlikely(Rc(ctx
->opcode
) != 0))
1400 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1404 static void gen_ori(DisasContext
*ctx
)
1406 target_ulong uimm
= UIMM(ctx
->opcode
);
1408 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1410 /* XXX: should handle special NOPs for POWER series */
1413 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1417 static void gen_oris(DisasContext
*ctx
)
1419 target_ulong uimm
= UIMM(ctx
->opcode
);
1421 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1425 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1429 static void gen_xori(DisasContext
*ctx
)
1431 target_ulong uimm
= UIMM(ctx
->opcode
);
1433 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1437 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1441 static void gen_xoris(DisasContext
*ctx
)
1443 target_ulong uimm
= UIMM(ctx
->opcode
);
1445 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1449 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1452 /* popcntb : PowerPC 2.03 specification */
1453 static void gen_popcntb(DisasContext
*ctx
)
1455 gen_helper_popcntb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1458 static void gen_popcntw(DisasContext
*ctx
)
1460 gen_helper_popcntw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1463 #if defined(TARGET_PPC64)
1464 /* popcntd: PowerPC 2.06 specification */
1465 static void gen_popcntd(DisasContext
*ctx
)
1467 gen_helper_popcntd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1471 #if defined(TARGET_PPC64)
1472 /* extsw & extsw. */
1473 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
);
1476 static void gen_cntlzd(DisasContext
*ctx
)
1478 gen_helper_cntlzd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1479 if (unlikely(Rc(ctx
->opcode
) != 0))
1480 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1484 /*** Integer rotate ***/
1486 /* rlwimi & rlwimi. */
1487 static void gen_rlwimi(DisasContext
*ctx
)
1489 uint32_t mb
, me
, sh
;
1491 mb
= MB(ctx
->opcode
);
1492 me
= ME(ctx
->opcode
);
1493 sh
= SH(ctx
->opcode
);
1494 if (likely(sh
== 0 && mb
== 0 && me
== 31)) {
1495 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1499 TCGv t0
= tcg_temp_new();
1500 #if defined(TARGET_PPC64)
1501 TCGv_i32 t2
= tcg_temp_new_i32();
1502 tcg_gen_trunc_i64_i32(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
1503 tcg_gen_rotli_i32(t2
, t2
, sh
);
1504 tcg_gen_extu_i32_i64(t0
, t2
);
1505 tcg_temp_free_i32(t2
);
1507 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1509 #if defined(TARGET_PPC64)
1513 mask
= MASK(mb
, me
);
1514 t1
= tcg_temp_new();
1515 tcg_gen_andi_tl(t0
, t0
, mask
);
1516 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1517 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1521 if (unlikely(Rc(ctx
->opcode
) != 0))
1522 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1525 /* rlwinm & rlwinm. */
1526 static void gen_rlwinm(DisasContext
*ctx
)
1528 uint32_t mb
, me
, sh
;
1530 sh
= SH(ctx
->opcode
);
1531 mb
= MB(ctx
->opcode
);
1532 me
= ME(ctx
->opcode
);
1534 if (likely(mb
== 0 && me
== (31 - sh
))) {
1535 if (likely(sh
== 0)) {
1536 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1538 TCGv t0
= tcg_temp_new();
1539 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1540 tcg_gen_shli_tl(t0
, t0
, sh
);
1541 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1544 } else if (likely(sh
!= 0 && me
== 31 && sh
== (32 - mb
))) {
1545 TCGv t0
= tcg_temp_new();
1546 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1547 tcg_gen_shri_tl(t0
, t0
, mb
);
1548 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1551 TCGv t0
= tcg_temp_new();
1552 #if defined(TARGET_PPC64)
1553 TCGv_i32 t1
= tcg_temp_new_i32();
1554 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1555 tcg_gen_rotli_i32(t1
, t1
, sh
);
1556 tcg_gen_extu_i32_i64(t0
, t1
);
1557 tcg_temp_free_i32(t1
);
1559 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1561 #if defined(TARGET_PPC64)
1565 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1568 if (unlikely(Rc(ctx
->opcode
) != 0))
1569 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1572 /* rlwnm & rlwnm. */
1573 static void gen_rlwnm(DisasContext
*ctx
)
1577 #if defined(TARGET_PPC64)
1581 mb
= MB(ctx
->opcode
);
1582 me
= ME(ctx
->opcode
);
1583 t0
= tcg_temp_new();
1584 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1585 #if defined(TARGET_PPC64)
1586 t1
= tcg_temp_new_i32();
1587 t2
= tcg_temp_new_i32();
1588 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1589 tcg_gen_trunc_i64_i32(t2
, t0
);
1590 tcg_gen_rotl_i32(t1
, t1
, t2
);
1591 tcg_gen_extu_i32_i64(t0
, t1
);
1592 tcg_temp_free_i32(t1
);
1593 tcg_temp_free_i32(t2
);
1595 tcg_gen_rotl_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1597 if (unlikely(mb
!= 0 || me
!= 31)) {
1598 #if defined(TARGET_PPC64)
1602 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1604 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1607 if (unlikely(Rc(ctx
->opcode
) != 0))
1608 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1611 #if defined(TARGET_PPC64)
1612 #define GEN_PPC64_R2(name, opc1, opc2) \
1613 static void glue(gen_, name##0)(DisasContext *ctx) \
1615 gen_##name(ctx, 0); \
1618 static void glue(gen_, name##1)(DisasContext *ctx) \
1620 gen_##name(ctx, 1); \
1622 #define GEN_PPC64_R4(name, opc1, opc2) \
1623 static void glue(gen_, name##0)(DisasContext *ctx) \
1625 gen_##name(ctx, 0, 0); \
1628 static void glue(gen_, name##1)(DisasContext *ctx) \
1630 gen_##name(ctx, 0, 1); \
1633 static void glue(gen_, name##2)(DisasContext *ctx) \
1635 gen_##name(ctx, 1, 0); \
1638 static void glue(gen_, name##3)(DisasContext *ctx) \
1640 gen_##name(ctx, 1, 1); \
1643 static inline void gen_rldinm(DisasContext
*ctx
, uint32_t mb
, uint32_t me
,
1646 if (likely(sh
!= 0 && mb
== 0 && me
== (63 - sh
))) {
1647 tcg_gen_shli_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
1648 } else if (likely(sh
!= 0 && me
== 63 && sh
== (64 - mb
))) {
1649 tcg_gen_shri_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], mb
);
1651 TCGv t0
= tcg_temp_new();
1652 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1653 if (likely(mb
== 0 && me
== 63)) {
1654 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1656 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1660 if (unlikely(Rc(ctx
->opcode
) != 0))
1661 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1663 /* rldicl - rldicl. */
1664 static inline void gen_rldicl(DisasContext
*ctx
, int mbn
, int shn
)
1668 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1669 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1670 gen_rldinm(ctx
, mb
, 63, sh
);
1672 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
1673 /* rldicr - rldicr. */
1674 static inline void gen_rldicr(DisasContext
*ctx
, int men
, int shn
)
1678 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1679 me
= MB(ctx
->opcode
) | (men
<< 5);
1680 gen_rldinm(ctx
, 0, me
, sh
);
1682 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
1683 /* rldic - rldic. */
1684 static inline void gen_rldic(DisasContext
*ctx
, int mbn
, int shn
)
1688 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1689 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1690 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
1692 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
1694 static inline void gen_rldnm(DisasContext
*ctx
, uint32_t mb
, uint32_t me
)
1698 mb
= MB(ctx
->opcode
);
1699 me
= ME(ctx
->opcode
);
1700 t0
= tcg_temp_new();
1701 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1702 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1703 if (unlikely(mb
!= 0 || me
!= 63)) {
1704 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1706 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1709 if (unlikely(Rc(ctx
->opcode
) != 0))
1710 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1713 /* rldcl - rldcl. */
1714 static inline void gen_rldcl(DisasContext
*ctx
, int mbn
)
1718 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1719 gen_rldnm(ctx
, mb
, 63);
1721 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
1722 /* rldcr - rldcr. */
1723 static inline void gen_rldcr(DisasContext
*ctx
, int men
)
1727 me
= MB(ctx
->opcode
) | (men
<< 5);
1728 gen_rldnm(ctx
, 0, me
);
1730 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
1731 /* rldimi - rldimi. */
1732 static inline void gen_rldimi(DisasContext
*ctx
, int mbn
, int shn
)
1734 uint32_t sh
, mb
, me
;
1736 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1737 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1739 if (unlikely(sh
== 0 && mb
== 0)) {
1740 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1745 t0
= tcg_temp_new();
1746 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1747 t1
= tcg_temp_new();
1748 mask
= MASK(mb
, me
);
1749 tcg_gen_andi_tl(t0
, t0
, mask
);
1750 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1751 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1755 if (unlikely(Rc(ctx
->opcode
) != 0))
1756 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1758 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
1761 /*** Integer shift ***/
1764 static void gen_slw(DisasContext
*ctx
)
1768 t0
= tcg_temp_new();
1769 /* AND rS with a mask that is 0 when rB >= 0x20 */
1770 #if defined(TARGET_PPC64)
1771 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
1772 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1774 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
1775 tcg_gen_sari_tl(t0
, t0
, 0x1f);
1777 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1778 t1
= tcg_temp_new();
1779 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1780 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1783 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
1784 if (unlikely(Rc(ctx
->opcode
) != 0))
1785 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1789 static void gen_sraw(DisasContext
*ctx
)
1791 gen_helper_sraw(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
1792 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1793 if (unlikely(Rc(ctx
->opcode
) != 0))
1794 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1797 /* srawi & srawi. */
1798 static void gen_srawi(DisasContext
*ctx
)
1800 int sh
= SH(ctx
->opcode
);
1804 l1
= gen_new_label();
1805 l2
= gen_new_label();
1806 t0
= tcg_temp_local_new();
1807 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1808 tcg_gen_brcondi_tl(TCG_COND_GE
, t0
, 0, l1
);
1809 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1ULL << sh
) - 1);
1810 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
1811 tcg_gen_movi_tl(cpu_ca
, 1);
1814 tcg_gen_movi_tl(cpu_ca
, 0);
1816 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1817 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, sh
);
1820 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1821 tcg_gen_movi_tl(cpu_ca
, 0);
1823 if (unlikely(Rc(ctx
->opcode
) != 0))
1824 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1828 static void gen_srw(DisasContext
*ctx
)
1832 t0
= tcg_temp_new();
1833 /* AND rS with a mask that is 0 when rB >= 0x20 */
1834 #if defined(TARGET_PPC64)
1835 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
1836 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1838 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
1839 tcg_gen_sari_tl(t0
, t0
, 0x1f);
1841 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1842 tcg_gen_ext32u_tl(t0
, t0
);
1843 t1
= tcg_temp_new();
1844 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1845 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1848 if (unlikely(Rc(ctx
->opcode
) != 0))
1849 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1852 #if defined(TARGET_PPC64)
1854 static void gen_sld(DisasContext
*ctx
)
1858 t0
= tcg_temp_new();
1859 /* AND rS with a mask that is 0 when rB >= 0x40 */
1860 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
1861 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1862 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1863 t1
= tcg_temp_new();
1864 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1865 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1868 if (unlikely(Rc(ctx
->opcode
) != 0))
1869 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1873 static void gen_srad(DisasContext
*ctx
)
1875 gen_helper_srad(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
1876 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1877 if (unlikely(Rc(ctx
->opcode
) != 0))
1878 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1880 /* sradi & sradi. */
1881 static inline void gen_sradi(DisasContext
*ctx
, int n
)
1883 int sh
= SH(ctx
->opcode
) + (n
<< 5);
1887 l1
= gen_new_label();
1888 l2
= gen_new_label();
1889 t0
= tcg_temp_local_new();
1890 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
1891 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1ULL << sh
) - 1);
1892 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
1893 tcg_gen_movi_tl(cpu_ca
, 1);
1896 tcg_gen_movi_tl(cpu_ca
, 0);
1899 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
1901 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1902 tcg_gen_movi_tl(cpu_ca
, 0);
1904 if (unlikely(Rc(ctx
->opcode
) != 0))
1905 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1908 static void gen_sradi0(DisasContext
*ctx
)
1913 static void gen_sradi1(DisasContext
*ctx
)
1919 static void gen_srd(DisasContext
*ctx
)
1923 t0
= tcg_temp_new();
1924 /* AND rS with a mask that is 0 when rB >= 0x40 */
1925 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
1926 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1927 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1928 t1
= tcg_temp_new();
1929 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1930 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1933 if (unlikely(Rc(ctx
->opcode
) != 0))
1934 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1938 /*** Floating-Point arithmetic ***/
1939 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
1940 static void gen_f##name(DisasContext *ctx) \
1942 if (unlikely(!ctx->fpu_enabled)) { \
1943 gen_exception(ctx, POWERPC_EXCP_FPU); \
1946 /* NIP cannot be restored if the memory exception comes from an helper */ \
1947 gen_update_nip(ctx, ctx->nip - 4); \
1948 gen_reset_fpstatus(); \
1949 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1950 cpu_fpr[rA(ctx->opcode)], \
1951 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
1953 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1954 cpu_fpr[rD(ctx->opcode)]); \
1956 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \
1957 Rc(ctx->opcode) != 0); \
1960 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
1961 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
1962 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
1964 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
1965 static void gen_f##name(DisasContext *ctx) \
1967 if (unlikely(!ctx->fpu_enabled)) { \
1968 gen_exception(ctx, POWERPC_EXCP_FPU); \
1971 /* NIP cannot be restored if the memory exception comes from an helper */ \
1972 gen_update_nip(ctx, ctx->nip - 4); \
1973 gen_reset_fpstatus(); \
1974 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1975 cpu_fpr[rA(ctx->opcode)], \
1976 cpu_fpr[rB(ctx->opcode)]); \
1978 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1979 cpu_fpr[rD(ctx->opcode)]); \
1981 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
1982 set_fprf, Rc(ctx->opcode) != 0); \
1984 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
1985 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
1986 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
1988 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
1989 static void gen_f##name(DisasContext *ctx) \
1991 if (unlikely(!ctx->fpu_enabled)) { \
1992 gen_exception(ctx, POWERPC_EXCP_FPU); \
1995 /* NIP cannot be restored if the memory exception comes from an helper */ \
1996 gen_update_nip(ctx, ctx->nip - 4); \
1997 gen_reset_fpstatus(); \
1998 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1999 cpu_fpr[rA(ctx->opcode)], \
2000 cpu_fpr[rC(ctx->opcode)]); \
2002 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2003 cpu_fpr[rD(ctx->opcode)]); \
2005 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2006 set_fprf, Rc(ctx->opcode) != 0); \
2008 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2009 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2010 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2012 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
2013 static void gen_f##name(DisasContext *ctx) \
2015 if (unlikely(!ctx->fpu_enabled)) { \
2016 gen_exception(ctx, POWERPC_EXCP_FPU); \
2019 /* NIP cannot be restored if the memory exception comes from an helper */ \
2020 gen_update_nip(ctx, ctx->nip - 4); \
2021 gen_reset_fpstatus(); \
2022 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2023 cpu_fpr[rB(ctx->opcode)]); \
2024 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2025 set_fprf, Rc(ctx->opcode) != 0); \
2028 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
2029 static void gen_f##name(DisasContext *ctx) \
2031 if (unlikely(!ctx->fpu_enabled)) { \
2032 gen_exception(ctx, POWERPC_EXCP_FPU); \
2035 /* NIP cannot be restored if the memory exception comes from an helper */ \
2036 gen_update_nip(ctx, ctx->nip - 4); \
2037 gen_reset_fpstatus(); \
2038 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2039 cpu_fpr[rB(ctx->opcode)]); \
2040 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2041 set_fprf, Rc(ctx->opcode) != 0); \
2045 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
);
2047 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
);
2049 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
);
2052 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
);
2055 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
);
2058 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
);
2061 static void gen_frsqrtes(DisasContext
*ctx
)
2063 if (unlikely(!ctx
->fpu_enabled
)) {
2064 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2067 /* NIP cannot be restored if the memory exception comes from an helper */
2068 gen_update_nip(ctx
, ctx
->nip
- 4);
2069 gen_reset_fpstatus();
2070 gen_helper_frsqrte(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2071 cpu_fpr
[rB(ctx
->opcode
)]);
2072 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2073 cpu_fpr
[rD(ctx
->opcode
)]);
2074 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2078 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
);
2080 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
);
2084 static void gen_fsqrt(DisasContext
*ctx
)
2086 if (unlikely(!ctx
->fpu_enabled
)) {
2087 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2090 /* NIP cannot be restored if the memory exception comes from an helper */
2091 gen_update_nip(ctx
, ctx
->nip
- 4);
2092 gen_reset_fpstatus();
2093 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2094 cpu_fpr
[rB(ctx
->opcode
)]);
2095 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2098 static void gen_fsqrts(DisasContext
*ctx
)
2100 if (unlikely(!ctx
->fpu_enabled
)) {
2101 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2104 /* NIP cannot be restored if the memory exception comes from an helper */
2105 gen_update_nip(ctx
, ctx
->nip
- 4);
2106 gen_reset_fpstatus();
2107 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2108 cpu_fpr
[rB(ctx
->opcode
)]);
2109 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2110 cpu_fpr
[rD(ctx
->opcode
)]);
2111 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2114 /*** Floating-Point multiply-and-add ***/
2115 /* fmadd - fmadds */
2116 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
);
2117 /* fmsub - fmsubs */
2118 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
);
2119 /* fnmadd - fnmadds */
2120 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
);
2121 /* fnmsub - fnmsubs */
2122 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
);
2124 /*** Floating-Point round & convert ***/
2126 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
);
2128 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
);
2130 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
);
2131 #if defined(TARGET_PPC64)
2133 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
);
2135 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
);
2137 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
);
2141 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
);
2143 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
);
2145 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
);
2147 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
);
2149 /*** Floating-Point compare ***/
2152 static void gen_fcmpo(DisasContext
*ctx
)
2155 if (unlikely(!ctx
->fpu_enabled
)) {
2156 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2159 /* NIP cannot be restored if the memory exception comes from an helper */
2160 gen_update_nip(ctx
, ctx
->nip
- 4);
2161 gen_reset_fpstatus();
2162 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2163 gen_helper_fcmpo(cpu_env
, cpu_fpr
[rA(ctx
->opcode
)],
2164 cpu_fpr
[rB(ctx
->opcode
)], crf
);
2165 tcg_temp_free_i32(crf
);
2166 gen_helper_float_check_status(cpu_env
);
2170 static void gen_fcmpu(DisasContext
*ctx
)
2173 if (unlikely(!ctx
->fpu_enabled
)) {
2174 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2177 /* NIP cannot be restored if the memory exception comes from an helper */
2178 gen_update_nip(ctx
, ctx
->nip
- 4);
2179 gen_reset_fpstatus();
2180 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2181 gen_helper_fcmpu(cpu_env
, cpu_fpr
[rA(ctx
->opcode
)],
2182 cpu_fpr
[rB(ctx
->opcode
)], crf
);
2183 tcg_temp_free_i32(crf
);
2184 gen_helper_float_check_status(cpu_env
);
2187 /*** Floating-point move ***/
2189 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2190 GEN_FLOAT_B(abs
, 0x08, 0x08, 0, PPC_FLOAT
);
2193 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2194 static void gen_fmr(DisasContext
*ctx
)
2196 if (unlikely(!ctx
->fpu_enabled
)) {
2197 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2200 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2201 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2205 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2206 GEN_FLOAT_B(nabs
, 0x08, 0x04, 0, PPC_FLOAT
);
2208 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2209 GEN_FLOAT_B(neg
, 0x08, 0x01, 0, PPC_FLOAT
);
2211 /*** Floating-Point status & ctrl register ***/
2214 static void gen_mcrfs(DisasContext
*ctx
)
2216 TCGv tmp
= tcg_temp_new();
2219 if (unlikely(!ctx
->fpu_enabled
)) {
2220 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2223 bfa
= 4 * (7 - crfS(ctx
->opcode
));
2224 tcg_gen_shri_tl(tmp
, cpu_fpscr
, bfa
);
2225 tcg_gen_trunc_tl_i32(cpu_crf
[crfD(ctx
->opcode
)], tmp
);
2227 tcg_gen_andi_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfD(ctx
->opcode
)], 0xf);
2228 tcg_gen_andi_tl(cpu_fpscr
, cpu_fpscr
, ~(0xF << bfa
));
2232 static void gen_mffs(DisasContext
*ctx
)
2234 if (unlikely(!ctx
->fpu_enabled
)) {
2235 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2238 gen_reset_fpstatus();
2239 tcg_gen_extu_tl_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpscr
);
2240 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2244 static void gen_mtfsb0(DisasContext
*ctx
)
2248 if (unlikely(!ctx
->fpu_enabled
)) {
2249 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2252 crb
= 31 - crbD(ctx
->opcode
);
2253 gen_reset_fpstatus();
2254 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
)) {
2256 /* NIP cannot be restored if the memory exception comes from an helper */
2257 gen_update_nip(ctx
, ctx
->nip
- 4);
2258 t0
= tcg_const_i32(crb
);
2259 gen_helper_fpscr_clrbit(cpu_env
, t0
);
2260 tcg_temp_free_i32(t0
);
2262 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2263 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2264 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2269 static void gen_mtfsb1(DisasContext
*ctx
)
2273 if (unlikely(!ctx
->fpu_enabled
)) {
2274 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2277 crb
= 31 - crbD(ctx
->opcode
);
2278 gen_reset_fpstatus();
2279 /* XXX: we pretend we can only do IEEE floating-point computations */
2280 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
&& crb
!= FPSCR_NI
)) {
2282 /* NIP cannot be restored if the memory exception comes from an helper */
2283 gen_update_nip(ctx
, ctx
->nip
- 4);
2284 t0
= tcg_const_i32(crb
);
2285 gen_helper_fpscr_setbit(cpu_env
, t0
);
2286 tcg_temp_free_i32(t0
);
2288 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2289 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2290 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2292 /* We can raise a differed exception */
2293 gen_helper_float_check_status(cpu_env
);
2297 static void gen_mtfsf(DisasContext
*ctx
)
2300 int L
= ctx
->opcode
& 0x02000000;
2302 if (unlikely(!ctx
->fpu_enabled
)) {
2303 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2306 /* NIP cannot be restored if the memory exception comes from an helper */
2307 gen_update_nip(ctx
, ctx
->nip
- 4);
2308 gen_reset_fpstatus();
2310 t0
= tcg_const_i32(0xff);
2312 t0
= tcg_const_i32(FM(ctx
->opcode
));
2313 gen_helper_store_fpscr(cpu_env
, cpu_fpr
[rB(ctx
->opcode
)], t0
);
2314 tcg_temp_free_i32(t0
);
2315 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2316 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2317 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2319 /* We can raise a differed exception */
2320 gen_helper_float_check_status(cpu_env
);
2324 static void gen_mtfsfi(DisasContext
*ctx
)
2330 if (unlikely(!ctx
->fpu_enabled
)) {
2331 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2334 bf
= crbD(ctx
->opcode
) >> 2;
2336 /* NIP cannot be restored if the memory exception comes from an helper */
2337 gen_update_nip(ctx
, ctx
->nip
- 4);
2338 gen_reset_fpstatus();
2339 t0
= tcg_const_i64(FPIMM(ctx
->opcode
) << (4 * sh
));
2340 t1
= tcg_const_i32(1 << sh
);
2341 gen_helper_store_fpscr(cpu_env
, t0
, t1
);
2342 tcg_temp_free_i64(t0
);
2343 tcg_temp_free_i32(t1
);
2344 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2345 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2346 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2348 /* We can raise a differed exception */
2349 gen_helper_float_check_status(cpu_env
);
2352 /*** Addressing modes ***/
2353 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2354 static inline void gen_addr_imm_index(DisasContext
*ctx
, TCGv EA
,
2357 target_long simm
= SIMM(ctx
->opcode
);
2360 if (rA(ctx
->opcode
) == 0) {
2361 #if defined(TARGET_PPC64)
2362 if (!ctx
->sf_mode
) {
2363 tcg_gen_movi_tl(EA
, (uint32_t)simm
);
2366 tcg_gen_movi_tl(EA
, simm
);
2367 } else if (likely(simm
!= 0)) {
2368 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
);
2369 #if defined(TARGET_PPC64)
2370 if (!ctx
->sf_mode
) {
2371 tcg_gen_ext32u_tl(EA
, EA
);
2375 #if defined(TARGET_PPC64)
2376 if (!ctx
->sf_mode
) {
2377 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2380 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2384 static inline void gen_addr_reg_index(DisasContext
*ctx
, TCGv EA
)
2386 if (rA(ctx
->opcode
) == 0) {
2387 #if defined(TARGET_PPC64)
2388 if (!ctx
->sf_mode
) {
2389 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2392 tcg_gen_mov_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2394 tcg_gen_add_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2395 #if defined(TARGET_PPC64)
2396 if (!ctx
->sf_mode
) {
2397 tcg_gen_ext32u_tl(EA
, EA
);
2403 static inline void gen_addr_register(DisasContext
*ctx
, TCGv EA
)
2405 if (rA(ctx
->opcode
) == 0) {
2406 tcg_gen_movi_tl(EA
, 0);
2408 #if defined(TARGET_PPC64)
2409 if (!ctx
->sf_mode
) {
2410 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2413 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2417 static inline void gen_addr_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
2420 tcg_gen_addi_tl(ret
, arg1
, val
);
2421 #if defined(TARGET_PPC64)
2422 if (!ctx
->sf_mode
) {
2423 tcg_gen_ext32u_tl(ret
, ret
);
2428 static inline void gen_check_align(DisasContext
*ctx
, TCGv EA
, int mask
)
2430 int l1
= gen_new_label();
2431 TCGv t0
= tcg_temp_new();
2433 /* NIP cannot be restored if the memory exception comes from an helper */
2434 gen_update_nip(ctx
, ctx
->nip
- 4);
2435 tcg_gen_andi_tl(t0
, EA
, mask
);
2436 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2437 t1
= tcg_const_i32(POWERPC_EXCP_ALIGN
);
2438 t2
= tcg_const_i32(0);
2439 gen_helper_raise_exception_err(cpu_env
, t1
, t2
);
2440 tcg_temp_free_i32(t1
);
2441 tcg_temp_free_i32(t2
);
2446 /*** Integer load ***/
2447 static inline void gen_qemu_ld8u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2449 tcg_gen_qemu_ld8u(arg1
, arg2
, ctx
->mem_idx
);
2452 static inline void gen_qemu_ld8s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2454 tcg_gen_qemu_ld8s(arg1
, arg2
, ctx
->mem_idx
);
2457 static inline void gen_qemu_ld16u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2459 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2460 if (unlikely(ctx
->le_mode
)) {
2461 tcg_gen_bswap16_tl(arg1
, arg1
);
2465 static inline void gen_qemu_ld16s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2467 if (unlikely(ctx
->le_mode
)) {
2468 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2469 tcg_gen_bswap16_tl(arg1
, arg1
);
2470 tcg_gen_ext16s_tl(arg1
, arg1
);
2472 tcg_gen_qemu_ld16s(arg1
, arg2
, ctx
->mem_idx
);
2476 static inline void gen_qemu_ld32u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2478 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2479 if (unlikely(ctx
->le_mode
)) {
2480 tcg_gen_bswap32_tl(arg1
, arg1
);
2484 #if defined(TARGET_PPC64)
2485 static inline void gen_qemu_ld32s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2487 if (unlikely(ctx
->le_mode
)) {
2488 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2489 tcg_gen_bswap32_tl(arg1
, arg1
);
2490 tcg_gen_ext32s_tl(arg1
, arg1
);
2492 tcg_gen_qemu_ld32s(arg1
, arg2
, ctx
->mem_idx
);
2496 static inline void gen_qemu_ld64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2498 tcg_gen_qemu_ld64(arg1
, arg2
, ctx
->mem_idx
);
2499 if (unlikely(ctx
->le_mode
)) {
2500 tcg_gen_bswap64_i64(arg1
, arg1
);
2504 static inline void gen_qemu_st8(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2506 tcg_gen_qemu_st8(arg1
, arg2
, ctx
->mem_idx
);
2509 static inline void gen_qemu_st16(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2511 if (unlikely(ctx
->le_mode
)) {
2512 TCGv t0
= tcg_temp_new();
2513 tcg_gen_ext16u_tl(t0
, arg1
);
2514 tcg_gen_bswap16_tl(t0
, t0
);
2515 tcg_gen_qemu_st16(t0
, arg2
, ctx
->mem_idx
);
2518 tcg_gen_qemu_st16(arg1
, arg2
, ctx
->mem_idx
);
2522 static inline void gen_qemu_st32(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2524 if (unlikely(ctx
->le_mode
)) {
2525 TCGv t0
= tcg_temp_new();
2526 tcg_gen_ext32u_tl(t0
, arg1
);
2527 tcg_gen_bswap32_tl(t0
, t0
);
2528 tcg_gen_qemu_st32(t0
, arg2
, ctx
->mem_idx
);
2531 tcg_gen_qemu_st32(arg1
, arg2
, ctx
->mem_idx
);
2535 static inline void gen_qemu_st64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2537 if (unlikely(ctx
->le_mode
)) {
2538 TCGv_i64 t0
= tcg_temp_new_i64();
2539 tcg_gen_bswap64_i64(t0
, arg1
);
2540 tcg_gen_qemu_st64(t0
, arg2
, ctx
->mem_idx
);
2541 tcg_temp_free_i64(t0
);
2543 tcg_gen_qemu_st64(arg1
, arg2
, ctx
->mem_idx
);
2546 #define GEN_LD(name, ldop, opc, type) \
2547 static void glue(gen_, name)(DisasContext *ctx) \
2550 gen_set_access_type(ctx, ACCESS_INT); \
2551 EA = tcg_temp_new(); \
2552 gen_addr_imm_index(ctx, EA, 0); \
2553 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2554 tcg_temp_free(EA); \
2557 #define GEN_LDU(name, ldop, opc, type) \
2558 static void glue(gen_, name##u)(DisasContext *ctx) \
2561 if (unlikely(rA(ctx->opcode) == 0 || \
2562 rA(ctx->opcode) == rD(ctx->opcode))) { \
2563 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2566 gen_set_access_type(ctx, ACCESS_INT); \
2567 EA = tcg_temp_new(); \
2568 if (type == PPC_64B) \
2569 gen_addr_imm_index(ctx, EA, 0x03); \
2571 gen_addr_imm_index(ctx, EA, 0); \
2572 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2573 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2574 tcg_temp_free(EA); \
2577 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
2578 static void glue(gen_, name##ux)(DisasContext *ctx) \
2581 if (unlikely(rA(ctx->opcode) == 0 || \
2582 rA(ctx->opcode) == rD(ctx->opcode))) { \
2583 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2586 gen_set_access_type(ctx, ACCESS_INT); \
2587 EA = tcg_temp_new(); \
2588 gen_addr_reg_index(ctx, EA); \
2589 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2590 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2591 tcg_temp_free(EA); \
2594 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
2595 static void glue(gen_, name##x)(DisasContext *ctx) \
2598 gen_set_access_type(ctx, ACCESS_INT); \
2599 EA = tcg_temp_new(); \
2600 gen_addr_reg_index(ctx, EA); \
2601 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2602 tcg_temp_free(EA); \
2604 #define GEN_LDX(name, ldop, opc2, opc3, type) \
2605 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE)
2607 #define GEN_LDS(name, ldop, op, type) \
2608 GEN_LD(name, ldop, op | 0x20, type); \
2609 GEN_LDU(name, ldop, op | 0x21, type); \
2610 GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2611 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
2613 /* lbz lbzu lbzux lbzx */
2614 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
);
2615 /* lha lhau lhaux lhax */
2616 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
);
2617 /* lhz lhzu lhzux lhzx */
2618 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
);
2619 /* lwz lwzu lwzux lwzx */
2620 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
);
2621 #if defined(TARGET_PPC64)
2623 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
);
2625 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
);
2627 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
);
2629 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
);
2631 static void gen_ld(DisasContext
*ctx
)
2634 if (Rc(ctx
->opcode
)) {
2635 if (unlikely(rA(ctx
->opcode
) == 0 ||
2636 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
2637 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2641 gen_set_access_type(ctx
, ACCESS_INT
);
2642 EA
= tcg_temp_new();
2643 gen_addr_imm_index(ctx
, EA
, 0x03);
2644 if (ctx
->opcode
& 0x02) {
2645 /* lwa (lwau is undefined) */
2646 gen_qemu_ld32s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2649 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2651 if (Rc(ctx
->opcode
))
2652 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2657 static void gen_lq(DisasContext
*ctx
)
2659 #if defined(CONFIG_USER_ONLY)
2660 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2665 /* Restore CPU state */
2666 if (unlikely(ctx
->mem_idx
== 0)) {
2667 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2670 ra
= rA(ctx
->opcode
);
2671 rd
= rD(ctx
->opcode
);
2672 if (unlikely((rd
& 1) || rd
== ra
)) {
2673 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2676 if (unlikely(ctx
->le_mode
)) {
2677 /* Little-endian mode is not handled */
2678 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2681 gen_set_access_type(ctx
, ACCESS_INT
);
2682 EA
= tcg_temp_new();
2683 gen_addr_imm_index(ctx
, EA
, 0x0F);
2684 gen_qemu_ld64(ctx
, cpu_gpr
[rd
], EA
);
2685 gen_addr_add(ctx
, EA
, EA
, 8);
2686 gen_qemu_ld64(ctx
, cpu_gpr
[rd
+1], EA
);
2692 /*** Integer store ***/
2693 #define GEN_ST(name, stop, opc, type) \
2694 static void glue(gen_, name)(DisasContext *ctx) \
2697 gen_set_access_type(ctx, ACCESS_INT); \
2698 EA = tcg_temp_new(); \
2699 gen_addr_imm_index(ctx, EA, 0); \
2700 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2701 tcg_temp_free(EA); \
2704 #define GEN_STU(name, stop, opc, type) \
2705 static void glue(gen_, stop##u)(DisasContext *ctx) \
2708 if (unlikely(rA(ctx->opcode) == 0)) { \
2709 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2712 gen_set_access_type(ctx, ACCESS_INT); \
2713 EA = tcg_temp_new(); \
2714 if (type == PPC_64B) \
2715 gen_addr_imm_index(ctx, EA, 0x03); \
2717 gen_addr_imm_index(ctx, EA, 0); \
2718 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2719 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2720 tcg_temp_free(EA); \
2723 #define GEN_STUX(name, stop, opc2, opc3, type) \
2724 static void glue(gen_, name##ux)(DisasContext *ctx) \
2727 if (unlikely(rA(ctx->opcode) == 0)) { \
2728 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2731 gen_set_access_type(ctx, ACCESS_INT); \
2732 EA = tcg_temp_new(); \
2733 gen_addr_reg_index(ctx, EA); \
2734 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2735 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2736 tcg_temp_free(EA); \
2739 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
2740 static void glue(gen_, name##x)(DisasContext *ctx) \
2743 gen_set_access_type(ctx, ACCESS_INT); \
2744 EA = tcg_temp_new(); \
2745 gen_addr_reg_index(ctx, EA); \
2746 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2747 tcg_temp_free(EA); \
2749 #define GEN_STX(name, stop, opc2, opc3, type) \
2750 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE)
2752 #define GEN_STS(name, stop, op, type) \
2753 GEN_ST(name, stop, op | 0x20, type); \
2754 GEN_STU(name, stop, op | 0x21, type); \
2755 GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2756 GEN_STX(name, stop, 0x17, op | 0x00, type)
2758 /* stb stbu stbux stbx */
2759 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
);
2760 /* sth sthu sthux sthx */
2761 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
);
2762 /* stw stwu stwux stwx */
2763 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
);
2764 #if defined(TARGET_PPC64)
2765 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
);
2766 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
);
2768 static void gen_std(DisasContext
*ctx
)
2773 rs
= rS(ctx
->opcode
);
2774 if ((ctx
->opcode
& 0x3) == 0x2) {
2775 #if defined(CONFIG_USER_ONLY)
2776 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2779 if (unlikely(ctx
->mem_idx
== 0)) {
2780 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2783 if (unlikely(rs
& 1)) {
2784 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2787 if (unlikely(ctx
->le_mode
)) {
2788 /* Little-endian mode is not handled */
2789 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2792 gen_set_access_type(ctx
, ACCESS_INT
);
2793 EA
= tcg_temp_new();
2794 gen_addr_imm_index(ctx
, EA
, 0x03);
2795 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
2796 gen_addr_add(ctx
, EA
, EA
, 8);
2797 gen_qemu_st64(ctx
, cpu_gpr
[rs
+1], EA
);
2802 if (Rc(ctx
->opcode
)) {
2803 if (unlikely(rA(ctx
->opcode
) == 0)) {
2804 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2808 gen_set_access_type(ctx
, ACCESS_INT
);
2809 EA
= tcg_temp_new();
2810 gen_addr_imm_index(ctx
, EA
, 0x03);
2811 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
2812 if (Rc(ctx
->opcode
))
2813 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2818 /*** Integer load and store with byte reverse ***/
2820 static inline void gen_qemu_ld16ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2822 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2823 if (likely(!ctx
->le_mode
)) {
2824 tcg_gen_bswap16_tl(arg1
, arg1
);
2827 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
);
2830 static inline void gen_qemu_ld32ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2832 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2833 if (likely(!ctx
->le_mode
)) {
2834 tcg_gen_bswap32_tl(arg1
, arg1
);
2837 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
);
2839 #if defined(TARGET_PPC64)
2841 static inline void gen_qemu_ld64ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2843 tcg_gen_qemu_ld64(arg1
, arg2
, ctx
->mem_idx
);
2844 if (likely(!ctx
->le_mode
)) {
2845 tcg_gen_bswap64_tl(arg1
, arg1
);
2848 GEN_LDX_E(ldbr
, ld64ur
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
);
2849 #endif /* TARGET_PPC64 */
2852 static inline void gen_qemu_st16r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2854 if (likely(!ctx
->le_mode
)) {
2855 TCGv t0
= tcg_temp_new();
2856 tcg_gen_ext16u_tl(t0
, arg1
);
2857 tcg_gen_bswap16_tl(t0
, t0
);
2858 tcg_gen_qemu_st16(t0
, arg2
, ctx
->mem_idx
);
2861 tcg_gen_qemu_st16(arg1
, arg2
, ctx
->mem_idx
);
2864 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
);
2867 static inline void gen_qemu_st32r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2869 if (likely(!ctx
->le_mode
)) {
2870 TCGv t0
= tcg_temp_new();
2871 tcg_gen_ext32u_tl(t0
, arg1
);
2872 tcg_gen_bswap32_tl(t0
, t0
);
2873 tcg_gen_qemu_st32(t0
, arg2
, ctx
->mem_idx
);
2876 tcg_gen_qemu_st32(arg1
, arg2
, ctx
->mem_idx
);
2879 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
);
2881 #if defined(TARGET_PPC64)
2883 static inline void gen_qemu_st64r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2885 if (likely(!ctx
->le_mode
)) {
2886 TCGv t0
= tcg_temp_new();
2887 tcg_gen_bswap64_tl(t0
, arg1
);
2888 tcg_gen_qemu_st64(t0
, arg2
, ctx
->mem_idx
);
2891 tcg_gen_qemu_st64(arg1
, arg2
, ctx
->mem_idx
);
2894 GEN_STX_E(stdbr
, st64r
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
);
2895 #endif /* TARGET_PPC64 */
2897 /*** Integer load and store multiple ***/
2900 static void gen_lmw(DisasContext
*ctx
)
2904 gen_set_access_type(ctx
, ACCESS_INT
);
2905 /* NIP cannot be restored if the memory exception comes from an helper */
2906 gen_update_nip(ctx
, ctx
->nip
- 4);
2907 t0
= tcg_temp_new();
2908 t1
= tcg_const_i32(rD(ctx
->opcode
));
2909 gen_addr_imm_index(ctx
, t0
, 0);
2910 gen_helper_lmw(cpu_env
, t0
, t1
);
2912 tcg_temp_free_i32(t1
);
2916 static void gen_stmw(DisasContext
*ctx
)
2920 gen_set_access_type(ctx
, ACCESS_INT
);
2921 /* NIP cannot be restored if the memory exception comes from an helper */
2922 gen_update_nip(ctx
, ctx
->nip
- 4);
2923 t0
= tcg_temp_new();
2924 t1
= tcg_const_i32(rS(ctx
->opcode
));
2925 gen_addr_imm_index(ctx
, t0
, 0);
2926 gen_helper_stmw(cpu_env
, t0
, t1
);
2928 tcg_temp_free_i32(t1
);
2931 /*** Integer load and store strings ***/
2934 /* PowerPC32 specification says we must generate an exception if
2935 * rA is in the range of registers to be loaded.
2936 * In an other hand, IBM says this is valid, but rA won't be loaded.
2937 * For now, I'll follow the spec...
2939 static void gen_lswi(DisasContext
*ctx
)
2943 int nb
= NB(ctx
->opcode
);
2944 int start
= rD(ctx
->opcode
);
2945 int ra
= rA(ctx
->opcode
);
2951 if (unlikely(((start
+ nr
) > 32 &&
2952 start
<= ra
&& (start
+ nr
- 32) > ra
) ||
2953 ((start
+ nr
) <= 32 && start
<= ra
&& (start
+ nr
) > ra
))) {
2954 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
2957 gen_set_access_type(ctx
, ACCESS_INT
);
2958 /* NIP cannot be restored if the memory exception comes from an helper */
2959 gen_update_nip(ctx
, ctx
->nip
- 4);
2960 t0
= tcg_temp_new();
2961 gen_addr_register(ctx
, t0
);
2962 t1
= tcg_const_i32(nb
);
2963 t2
= tcg_const_i32(start
);
2964 gen_helper_lsw(cpu_env
, t0
, t1
, t2
);
2966 tcg_temp_free_i32(t1
);
2967 tcg_temp_free_i32(t2
);
2971 static void gen_lswx(DisasContext
*ctx
)
2974 TCGv_i32 t1
, t2
, t3
;
2975 gen_set_access_type(ctx
, ACCESS_INT
);
2976 /* NIP cannot be restored if the memory exception comes from an helper */
2977 gen_update_nip(ctx
, ctx
->nip
- 4);
2978 t0
= tcg_temp_new();
2979 gen_addr_reg_index(ctx
, t0
);
2980 t1
= tcg_const_i32(rD(ctx
->opcode
));
2981 t2
= tcg_const_i32(rA(ctx
->opcode
));
2982 t3
= tcg_const_i32(rB(ctx
->opcode
));
2983 gen_helper_lswx(cpu_env
, t0
, t1
, t2
, t3
);
2985 tcg_temp_free_i32(t1
);
2986 tcg_temp_free_i32(t2
);
2987 tcg_temp_free_i32(t3
);
2991 static void gen_stswi(DisasContext
*ctx
)
2995 int nb
= NB(ctx
->opcode
);
2996 gen_set_access_type(ctx
, ACCESS_INT
);
2997 /* NIP cannot be restored if the memory exception comes from an helper */
2998 gen_update_nip(ctx
, ctx
->nip
- 4);
2999 t0
= tcg_temp_new();
3000 gen_addr_register(ctx
, t0
);
3003 t1
= tcg_const_i32(nb
);
3004 t2
= tcg_const_i32(rS(ctx
->opcode
));
3005 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3007 tcg_temp_free_i32(t1
);
3008 tcg_temp_free_i32(t2
);
3012 static void gen_stswx(DisasContext
*ctx
)
3016 gen_set_access_type(ctx
, ACCESS_INT
);
3017 /* NIP cannot be restored if the memory exception comes from an helper */
3018 gen_update_nip(ctx
, ctx
->nip
- 4);
3019 t0
= tcg_temp_new();
3020 gen_addr_reg_index(ctx
, t0
);
3021 t1
= tcg_temp_new_i32();
3022 tcg_gen_trunc_tl_i32(t1
, cpu_xer
);
3023 tcg_gen_andi_i32(t1
, t1
, 0x7F);
3024 t2
= tcg_const_i32(rS(ctx
->opcode
));
3025 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3027 tcg_temp_free_i32(t1
);
3028 tcg_temp_free_i32(t2
);
3031 /*** Memory synchronisation ***/
3033 static void gen_eieio(DisasContext
*ctx
)
3038 static void gen_isync(DisasContext
*ctx
)
3040 gen_stop_exception(ctx
);
3044 static void gen_lwarx(DisasContext
*ctx
)
3047 TCGv gpr
= cpu_gpr
[rD(ctx
->opcode
)];
3048 gen_set_access_type(ctx
, ACCESS_RES
);
3049 t0
= tcg_temp_local_new();
3050 gen_addr_reg_index(ctx
, t0
);
3051 gen_check_align(ctx
, t0
, 0x03);
3052 gen_qemu_ld32u(ctx
, gpr
, t0
);
3053 tcg_gen_mov_tl(cpu_reserve
, t0
);
3054 tcg_gen_st_tl(gpr
, cpu_env
, offsetof(CPUPPCState
, reserve_val
));
3058 #if defined(CONFIG_USER_ONLY)
3059 static void gen_conditional_store (DisasContext
*ctx
, TCGv EA
,
3062 TCGv t0
= tcg_temp_new();
3063 uint32_t save_exception
= ctx
->exception
;
3065 tcg_gen_st_tl(EA
, cpu_env
, offsetof(CPUPPCState
, reserve_ea
));
3066 tcg_gen_movi_tl(t0
, (size
<< 5) | reg
);
3067 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, reserve_info
));
3069 gen_update_nip(ctx
, ctx
->nip
-4);
3070 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3071 gen_exception(ctx
, POWERPC_EXCP_STCX
);
3072 ctx
->exception
= save_exception
;
3077 static void gen_stwcx_(DisasContext
*ctx
)
3080 gen_set_access_type(ctx
, ACCESS_RES
);
3081 t0
= tcg_temp_local_new();
3082 gen_addr_reg_index(ctx
, t0
);
3083 gen_check_align(ctx
, t0
, 0x03);
3084 #if defined(CONFIG_USER_ONLY)
3085 gen_conditional_store(ctx
, t0
, rS(ctx
->opcode
), 4);
3090 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
3091 l1
= gen_new_label();
3092 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
3093 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3094 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3096 tcg_gen_movi_tl(cpu_reserve
, -1);
3102 #if defined(TARGET_PPC64)
3104 static void gen_ldarx(DisasContext
*ctx
)
3107 TCGv gpr
= cpu_gpr
[rD(ctx
->opcode
)];
3108 gen_set_access_type(ctx
, ACCESS_RES
);
3109 t0
= tcg_temp_local_new();
3110 gen_addr_reg_index(ctx
, t0
);
3111 gen_check_align(ctx
, t0
, 0x07);
3112 gen_qemu_ld64(ctx
, gpr
, t0
);
3113 tcg_gen_mov_tl(cpu_reserve
, t0
);
3114 tcg_gen_st_tl(gpr
, cpu_env
, offsetof(CPUPPCState
, reserve_val
));
3119 static void gen_stdcx_(DisasContext
*ctx
)
3122 gen_set_access_type(ctx
, ACCESS_RES
);
3123 t0
= tcg_temp_local_new();
3124 gen_addr_reg_index(ctx
, t0
);
3125 gen_check_align(ctx
, t0
, 0x07);
3126 #if defined(CONFIG_USER_ONLY)
3127 gen_conditional_store(ctx
, t0
, rS(ctx
->opcode
), 8);
3131 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
3132 l1
= gen_new_label();
3133 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
3134 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3135 gen_qemu_st64(ctx
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3137 tcg_gen_movi_tl(cpu_reserve
, -1);
3142 #endif /* defined(TARGET_PPC64) */
3145 static void gen_sync(DisasContext
*ctx
)
3150 static void gen_wait(DisasContext
*ctx
)
3152 TCGv_i32 t0
= tcg_temp_new_i32();
3153 tcg_gen_st_i32(t0
, cpu_env
, offsetof(CPUPPCState
, halted
));
3154 tcg_temp_free_i32(t0
);
3155 /* Stop translation, as the CPU is supposed to sleep from now */
3156 gen_exception_err(ctx
, EXCP_HLT
, 1);
3159 /*** Floating-point load ***/
3160 #define GEN_LDF(name, ldop, opc, type) \
3161 static void glue(gen_, name)(DisasContext *ctx) \
3164 if (unlikely(!ctx->fpu_enabled)) { \
3165 gen_exception(ctx, POWERPC_EXCP_FPU); \
3168 gen_set_access_type(ctx, ACCESS_FLOAT); \
3169 EA = tcg_temp_new(); \
3170 gen_addr_imm_index(ctx, EA, 0); \
3171 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3172 tcg_temp_free(EA); \
3175 #define GEN_LDUF(name, ldop, opc, type) \
3176 static void glue(gen_, name##u)(DisasContext *ctx) \
3179 if (unlikely(!ctx->fpu_enabled)) { \
3180 gen_exception(ctx, POWERPC_EXCP_FPU); \
3183 if (unlikely(rA(ctx->opcode) == 0)) { \
3184 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3187 gen_set_access_type(ctx, ACCESS_FLOAT); \
3188 EA = tcg_temp_new(); \
3189 gen_addr_imm_index(ctx, EA, 0); \
3190 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3191 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3192 tcg_temp_free(EA); \
3195 #define GEN_LDUXF(name, ldop, opc, type) \
3196 static void glue(gen_, name##ux)(DisasContext *ctx) \
3199 if (unlikely(!ctx->fpu_enabled)) { \
3200 gen_exception(ctx, POWERPC_EXCP_FPU); \
3203 if (unlikely(rA(ctx->opcode) == 0)) { \
3204 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3207 gen_set_access_type(ctx, ACCESS_FLOAT); \
3208 EA = tcg_temp_new(); \
3209 gen_addr_reg_index(ctx, EA); \
3210 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3211 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3212 tcg_temp_free(EA); \
3215 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
3216 static void glue(gen_, name##x)(DisasContext *ctx) \
3219 if (unlikely(!ctx->fpu_enabled)) { \
3220 gen_exception(ctx, POWERPC_EXCP_FPU); \
3223 gen_set_access_type(ctx, ACCESS_FLOAT); \
3224 EA = tcg_temp_new(); \
3225 gen_addr_reg_index(ctx, EA); \
3226 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3227 tcg_temp_free(EA); \
3230 #define GEN_LDFS(name, ldop, op, type) \
3231 GEN_LDF(name, ldop, op | 0x20, type); \
3232 GEN_LDUF(name, ldop, op | 0x21, type); \
3233 GEN_LDUXF(name, ldop, op | 0x01, type); \
3234 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3236 static inline void gen_qemu_ld32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3238 TCGv t0
= tcg_temp_new();
3239 TCGv_i32 t1
= tcg_temp_new_i32();
3240 gen_qemu_ld32u(ctx
, t0
, arg2
);
3241 tcg_gen_trunc_tl_i32(t1
, t0
);
3243 gen_helper_float32_to_float64(arg1
, cpu_env
, t1
);
3244 tcg_temp_free_i32(t1
);
3247 /* lfd lfdu lfdux lfdx */
3248 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
);
3249 /* lfs lfsu lfsux lfsx */
3250 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
);
3252 /*** Floating-point store ***/
3253 #define GEN_STF(name, stop, opc, type) \
3254 static void glue(gen_, name)(DisasContext *ctx) \
3257 if (unlikely(!ctx->fpu_enabled)) { \
3258 gen_exception(ctx, POWERPC_EXCP_FPU); \
3261 gen_set_access_type(ctx, ACCESS_FLOAT); \
3262 EA = tcg_temp_new(); \
3263 gen_addr_imm_index(ctx, EA, 0); \
3264 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3265 tcg_temp_free(EA); \
3268 #define GEN_STUF(name, stop, opc, type) \
3269 static void glue(gen_, name##u)(DisasContext *ctx) \
3272 if (unlikely(!ctx->fpu_enabled)) { \
3273 gen_exception(ctx, POWERPC_EXCP_FPU); \
3276 if (unlikely(rA(ctx->opcode) == 0)) { \
3277 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3280 gen_set_access_type(ctx, ACCESS_FLOAT); \
3281 EA = tcg_temp_new(); \
3282 gen_addr_imm_index(ctx, EA, 0); \
3283 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3284 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3285 tcg_temp_free(EA); \
3288 #define GEN_STUXF(name, stop, opc, type) \
3289 static void glue(gen_, name##ux)(DisasContext *ctx) \
3292 if (unlikely(!ctx->fpu_enabled)) { \
3293 gen_exception(ctx, POWERPC_EXCP_FPU); \
3296 if (unlikely(rA(ctx->opcode) == 0)) { \
3297 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3300 gen_set_access_type(ctx, ACCESS_FLOAT); \
3301 EA = tcg_temp_new(); \
3302 gen_addr_reg_index(ctx, EA); \
3303 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3304 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3305 tcg_temp_free(EA); \
3308 #define GEN_STXF(name, stop, opc2, opc3, type) \
3309 static void glue(gen_, name##x)(DisasContext *ctx) \
3312 if (unlikely(!ctx->fpu_enabled)) { \
3313 gen_exception(ctx, POWERPC_EXCP_FPU); \
3316 gen_set_access_type(ctx, ACCESS_FLOAT); \
3317 EA = tcg_temp_new(); \
3318 gen_addr_reg_index(ctx, EA); \
3319 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3320 tcg_temp_free(EA); \
3323 #define GEN_STFS(name, stop, op, type) \
3324 GEN_STF(name, stop, op | 0x20, type); \
3325 GEN_STUF(name, stop, op | 0x21, type); \
3326 GEN_STUXF(name, stop, op | 0x01, type); \
3327 GEN_STXF(name, stop, 0x17, op | 0x00, type)
3329 static inline void gen_qemu_st32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3331 TCGv_i32 t0
= tcg_temp_new_i32();
3332 TCGv t1
= tcg_temp_new();
3333 gen_helper_float64_to_float32(t0
, cpu_env
, arg1
);
3334 tcg_gen_extu_i32_tl(t1
, t0
);
3335 tcg_temp_free_i32(t0
);
3336 gen_qemu_st32(ctx
, t1
, arg2
);
3340 /* stfd stfdu stfdux stfdx */
3341 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
);
3342 /* stfs stfsu stfsux stfsx */
3343 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
);
3346 static inline void gen_qemu_st32fiw(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3348 TCGv t0
= tcg_temp_new();
3349 tcg_gen_trunc_i64_tl(t0
, arg1
),
3350 gen_qemu_st32(ctx
, t0
, arg2
);
3354 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
);
3356 static inline void gen_update_cfar(DisasContext
*ctx
, target_ulong nip
)
3358 #if defined(TARGET_PPC64)
3360 tcg_gen_movi_tl(cpu_cfar
, nip
);
3365 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
3367 TranslationBlock
*tb
;
3369 #if defined(TARGET_PPC64)
3371 dest
= (uint32_t) dest
;
3373 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
3374 likely(!ctx
->singlestep_enabled
)) {
3376 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3377 tcg_gen_exit_tb((tcg_target_long
)tb
+ n
);
3379 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3380 if (unlikely(ctx
->singlestep_enabled
)) {
3381 if ((ctx
->singlestep_enabled
&
3382 (CPU_BRANCH_STEP
| CPU_SINGLE_STEP
)) &&
3383 (ctx
->exception
== POWERPC_EXCP_BRANCH
||
3384 ctx
->exception
== POWERPC_EXCP_TRACE
)) {
3385 target_ulong tmp
= ctx
->nip
;
3387 gen_exception(ctx
, POWERPC_EXCP_TRACE
);
3390 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
3391 gen_debug_exception(ctx
);
3398 static inline void gen_setlr(DisasContext
*ctx
, target_ulong nip
)
3400 #if defined(TARGET_PPC64)
3401 if (ctx
->sf_mode
== 0)
3402 tcg_gen_movi_tl(cpu_lr
, (uint32_t)nip
);
3405 tcg_gen_movi_tl(cpu_lr
, nip
);
3409 static void gen_b(DisasContext
*ctx
)
3411 target_ulong li
, target
;
3413 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3414 /* sign extend LI */
3415 #if defined(TARGET_PPC64)
3417 li
= ((int64_t)LI(ctx
->opcode
) << 38) >> 38;
3420 li
= ((int32_t)LI(ctx
->opcode
) << 6) >> 6;
3421 if (likely(AA(ctx
->opcode
) == 0))
3422 target
= ctx
->nip
+ li
- 4;
3425 if (LK(ctx
->opcode
))
3426 gen_setlr(ctx
, ctx
->nip
);
3427 gen_update_cfar(ctx
, ctx
->nip
);
3428 gen_goto_tb(ctx
, 0, target
);
3435 static inline void gen_bcond(DisasContext
*ctx
, int type
)
3437 uint32_t bo
= BO(ctx
->opcode
);
3441 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3442 if (type
== BCOND_LR
|| type
== BCOND_CTR
) {
3443 target
= tcg_temp_local_new();
3444 if (type
== BCOND_CTR
)
3445 tcg_gen_mov_tl(target
, cpu_ctr
);
3447 tcg_gen_mov_tl(target
, cpu_lr
);
3449 TCGV_UNUSED(target
);
3451 if (LK(ctx
->opcode
))
3452 gen_setlr(ctx
, ctx
->nip
);
3453 l1
= gen_new_label();
3454 if ((bo
& 0x4) == 0) {
3455 /* Decrement and test CTR */
3456 TCGv temp
= tcg_temp_new();
3457 if (unlikely(type
== BCOND_CTR
)) {
3458 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3461 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
3462 #if defined(TARGET_PPC64)
3464 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
3467 tcg_gen_mov_tl(temp
, cpu_ctr
);
3469 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
3471 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
3473 tcg_temp_free(temp
);
3475 if ((bo
& 0x10) == 0) {
3477 uint32_t bi
= BI(ctx
->opcode
);
3478 uint32_t mask
= 1 << (3 - (bi
& 0x03));
3479 TCGv_i32 temp
= tcg_temp_new_i32();
3482 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3483 tcg_gen_brcondi_i32(TCG_COND_EQ
, temp
, 0, l1
);
3485 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3486 tcg_gen_brcondi_i32(TCG_COND_NE
, temp
, 0, l1
);
3488 tcg_temp_free_i32(temp
);
3490 gen_update_cfar(ctx
, ctx
->nip
);
3491 if (type
== BCOND_IM
) {
3492 target_ulong li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
3493 if (likely(AA(ctx
->opcode
) == 0)) {
3494 gen_goto_tb(ctx
, 0, ctx
->nip
+ li
- 4);
3496 gen_goto_tb(ctx
, 0, li
);
3499 gen_goto_tb(ctx
, 1, ctx
->nip
);
3501 #if defined(TARGET_PPC64)
3502 if (!(ctx
->sf_mode
))
3503 tcg_gen_andi_tl(cpu_nip
, target
, (uint32_t)~3);
3506 tcg_gen_andi_tl(cpu_nip
, target
, ~3);
3509 #if defined(TARGET_PPC64)
3510 if (!(ctx
->sf_mode
))
3511 tcg_gen_movi_tl(cpu_nip
, (uint32_t)ctx
->nip
);
3514 tcg_gen_movi_tl(cpu_nip
, ctx
->nip
);
3519 static void gen_bc(DisasContext
*ctx
)
3521 gen_bcond(ctx
, BCOND_IM
);
3524 static void gen_bcctr(DisasContext
*ctx
)
3526 gen_bcond(ctx
, BCOND_CTR
);
3529 static void gen_bclr(DisasContext
*ctx
)
3531 gen_bcond(ctx
, BCOND_LR
);
3534 /*** Condition register logical ***/
3535 #define GEN_CRLOGIC(name, tcg_op, opc) \
3536 static void glue(gen_, name)(DisasContext *ctx) \
3541 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3542 t0 = tcg_temp_new_i32(); \
3544 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
3546 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
3548 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
3549 t1 = tcg_temp_new_i32(); \
3550 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3552 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
3554 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
3556 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3557 tcg_op(t0, t0, t1); \
3558 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
3559 tcg_gen_andi_i32(t0, t0, bitmask); \
3560 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3561 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
3562 tcg_temp_free_i32(t0); \
3563 tcg_temp_free_i32(t1); \
3567 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08);
3569 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04);
3571 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09);
3573 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07);
3575 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01);
3577 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E);
3579 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D);
3581 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06);
3584 static void gen_mcrf(DisasContext
*ctx
)
3586 tcg_gen_mov_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfS(ctx
->opcode
)]);
3589 /*** System linkage ***/
3591 /* rfi (mem_idx only) */
3592 static void gen_rfi(DisasContext
*ctx
)
3594 #if defined(CONFIG_USER_ONLY)
3595 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3597 /* Restore CPU state */
3598 if (unlikely(!ctx
->mem_idx
)) {
3599 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3602 gen_update_cfar(ctx
, ctx
->nip
);
3603 gen_helper_rfi(cpu_env
);
3604 gen_sync_exception(ctx
);
3608 #if defined(TARGET_PPC64)
3609 static void gen_rfid(DisasContext
*ctx
)
3611 #if defined(CONFIG_USER_ONLY)
3612 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3614 /* Restore CPU state */
3615 if (unlikely(!ctx
->mem_idx
)) {
3616 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3619 gen_update_cfar(ctx
, ctx
->nip
);
3620 gen_helper_rfid(cpu_env
);
3621 gen_sync_exception(ctx
);
3625 static void gen_hrfid(DisasContext
*ctx
)
3627 #if defined(CONFIG_USER_ONLY)
3628 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3630 /* Restore CPU state */
3631 if (unlikely(ctx
->mem_idx
<= 1)) {
3632 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3635 gen_helper_hrfid(cpu_env
);
3636 gen_sync_exception(ctx
);
3642 #if defined(CONFIG_USER_ONLY)
3643 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3645 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3647 static void gen_sc(DisasContext
*ctx
)
3651 lev
= (ctx
->opcode
>> 5) & 0x7F;
3652 gen_exception_err(ctx
, POWERPC_SYSCALL
, lev
);
3658 static void gen_tw(DisasContext
*ctx
)
3660 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3661 /* Update the nip since this might generate a trap exception */
3662 gen_update_nip(ctx
, ctx
->nip
);
3663 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
3665 tcg_temp_free_i32(t0
);
3669 static void gen_twi(DisasContext
*ctx
)
3671 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3672 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
3673 /* Update the nip since this might generate a trap exception */
3674 gen_update_nip(ctx
, ctx
->nip
);
3675 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3677 tcg_temp_free_i32(t1
);
3680 #if defined(TARGET_PPC64)
3682 static void gen_td(DisasContext
*ctx
)
3684 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3685 /* Update the nip since this might generate a trap exception */
3686 gen_update_nip(ctx
, ctx
->nip
);
3687 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
3689 tcg_temp_free_i32(t0
);
3693 static void gen_tdi(DisasContext
*ctx
)
3695 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3696 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
3697 /* Update the nip since this might generate a trap exception */
3698 gen_update_nip(ctx
, ctx
->nip
);
3699 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3701 tcg_temp_free_i32(t1
);
3705 /*** Processor control ***/
3707 static void gen_read_xer(TCGv dst
)
3709 TCGv t0
= tcg_temp_new();
3710 TCGv t1
= tcg_temp_new();
3711 TCGv t2
= tcg_temp_new();
3712 tcg_gen_mov_tl(dst
, cpu_xer
);
3713 tcg_gen_shli_tl(t0
, cpu_so
, XER_SO
);
3714 tcg_gen_shli_tl(t1
, cpu_ov
, XER_OV
);
3715 tcg_gen_shli_tl(t2
, cpu_ca
, XER_CA
);
3716 tcg_gen_or_tl(t0
, t0
, t1
);
3717 tcg_gen_or_tl(dst
, dst
, t2
);
3718 tcg_gen_or_tl(dst
, dst
, t0
);
3724 static void gen_write_xer(TCGv src
)
3726 tcg_gen_andi_tl(cpu_xer
, src
,
3727 ~((1u << XER_SO
) | (1u << XER_OV
) | (1u << XER_CA
)));
3728 tcg_gen_shri_tl(cpu_so
, src
, XER_SO
);
3729 tcg_gen_shri_tl(cpu_ov
, src
, XER_OV
);
3730 tcg_gen_shri_tl(cpu_ca
, src
, XER_CA
);
3731 tcg_gen_andi_tl(cpu_so
, cpu_so
, 1);
3732 tcg_gen_andi_tl(cpu_ov
, cpu_ov
, 1);
3733 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
3737 static void gen_mcrxr(DisasContext
*ctx
)
3739 TCGv_i32 t0
= tcg_temp_new_i32();
3740 TCGv_i32 t1
= tcg_temp_new_i32();
3741 TCGv_i32 dst
= cpu_crf
[crfD(ctx
->opcode
)];
3743 tcg_gen_trunc_tl_i32(t0
, cpu_so
);
3744 tcg_gen_trunc_tl_i32(t1
, cpu_ov
);
3745 tcg_gen_trunc_tl_i32(dst
, cpu_ca
);
3746 tcg_gen_shri_i32(t0
, t0
, 2);
3747 tcg_gen_shri_i32(t1
, t1
, 1);
3748 tcg_gen_or_i32(dst
, dst
, t0
);
3749 tcg_gen_or_i32(dst
, dst
, t1
);
3750 tcg_temp_free_i32(t0
);
3751 tcg_temp_free_i32(t1
);
3753 tcg_gen_movi_tl(cpu_so
, 0);
3754 tcg_gen_movi_tl(cpu_ov
, 0);
3755 tcg_gen_movi_tl(cpu_ca
, 0);
3759 static void gen_mfcr(DisasContext
*ctx
)
3763 if (likely(ctx
->opcode
& 0x00100000)) {
3764 crm
= CRM(ctx
->opcode
);
3765 if (likely(crm
&& ((crm
& (crm
- 1)) == 0))) {
3767 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_crf
[7 - crn
]);
3768 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)],
3769 cpu_gpr
[rD(ctx
->opcode
)], crn
* 4);
3772 TCGv_i32 t0
= tcg_temp_new_i32();
3773 tcg_gen_mov_i32(t0
, cpu_crf
[0]);
3774 tcg_gen_shli_i32(t0
, t0
, 4);
3775 tcg_gen_or_i32(t0
, t0
, cpu_crf
[1]);
3776 tcg_gen_shli_i32(t0
, t0
, 4);
3777 tcg_gen_or_i32(t0
, t0
, cpu_crf
[2]);
3778 tcg_gen_shli_i32(t0
, t0
, 4);
3779 tcg_gen_or_i32(t0
, t0
, cpu_crf
[3]);
3780 tcg_gen_shli_i32(t0
, t0
, 4);
3781 tcg_gen_or_i32(t0
, t0
, cpu_crf
[4]);
3782 tcg_gen_shli_i32(t0
, t0
, 4);
3783 tcg_gen_or_i32(t0
, t0
, cpu_crf
[5]);
3784 tcg_gen_shli_i32(t0
, t0
, 4);
3785 tcg_gen_or_i32(t0
, t0
, cpu_crf
[6]);
3786 tcg_gen_shli_i32(t0
, t0
, 4);
3787 tcg_gen_or_i32(t0
, t0
, cpu_crf
[7]);
3788 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
3789 tcg_temp_free_i32(t0
);
3794 static void gen_mfmsr(DisasContext
*ctx
)
3796 #if defined(CONFIG_USER_ONLY)
3797 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3799 if (unlikely(!ctx
->mem_idx
)) {
3800 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3803 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_msr
);
3807 static void spr_noaccess(void *opaque
, int gprn
, int sprn
)
3810 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
3811 printf("ERROR: try to access SPR %d !\n", sprn
);
3814 #define SPR_NOACCESS (&spr_noaccess)
3817 static inline void gen_op_mfspr(DisasContext
*ctx
)
3819 void (*read_cb
)(void *opaque
, int gprn
, int sprn
);
3820 uint32_t sprn
= SPR(ctx
->opcode
);
3822 #if !defined(CONFIG_USER_ONLY)
3823 if (ctx
->mem_idx
== 2)
3824 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
3825 else if (ctx
->mem_idx
)
3826 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
3829 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
3830 if (likely(read_cb
!= NULL
)) {
3831 if (likely(read_cb
!= SPR_NOACCESS
)) {
3832 (*read_cb
)(ctx
, rD(ctx
->opcode
), sprn
);
3834 /* Privilege exception */
3835 /* This is a hack to avoid warnings when running Linux:
3836 * this OS breaks the PowerPC virtualisation model,
3837 * allowing userland application to read the PVR
3839 if (sprn
!= SPR_PVR
) {
3840 qemu_log("Trying to read privileged spr %d %03x at "
3841 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
3842 printf("Trying to read privileged spr %d %03x at "
3843 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
3845 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3849 qemu_log("Trying to read invalid spr %d %03x at "
3850 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
3851 printf("Trying to read invalid spr %d %03x at " TARGET_FMT_lx
"\n",
3852 sprn
, sprn
, ctx
->nip
);
3853 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
3857 static void gen_mfspr(DisasContext
*ctx
)
3863 static void gen_mftb(DisasContext
*ctx
)
3869 static void gen_mtcrf(DisasContext
*ctx
)
3873 crm
= CRM(ctx
->opcode
);
3874 if (likely((ctx
->opcode
& 0x00100000))) {
3875 if (crm
&& ((crm
& (crm
- 1)) == 0)) {
3876 TCGv_i32 temp
= tcg_temp_new_i32();
3878 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
3879 tcg_gen_shri_i32(temp
, temp
, crn
* 4);
3880 tcg_gen_andi_i32(cpu_crf
[7 - crn
], temp
, 0xf);
3881 tcg_temp_free_i32(temp
);
3884 TCGv_i32 temp
= tcg_temp_new_i32();
3885 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
3886 for (crn
= 0 ; crn
< 8 ; crn
++) {
3887 if (crm
& (1 << crn
)) {
3888 tcg_gen_shri_i32(cpu_crf
[7 - crn
], temp
, crn
* 4);
3889 tcg_gen_andi_i32(cpu_crf
[7 - crn
], cpu_crf
[7 - crn
], 0xf);
3892 tcg_temp_free_i32(temp
);
3897 #if defined(TARGET_PPC64)
3898 static void gen_mtmsrd(DisasContext
*ctx
)
3900 #if defined(CONFIG_USER_ONLY)
3901 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3903 if (unlikely(!ctx
->mem_idx
)) {
3904 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3907 if (ctx
->opcode
& 0x00010000) {
3908 /* Special form that does not need any synchronisation */
3909 TCGv t0
= tcg_temp_new();
3910 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
3911 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
3912 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
3915 /* XXX: we need to update nip before the store
3916 * if we enter power saving mode, we will exit the loop
3917 * directly from ppc_store_msr
3919 gen_update_nip(ctx
, ctx
->nip
);
3920 gen_helper_store_msr(cpu_env
, cpu_gpr
[rS(ctx
->opcode
)]);
3921 /* Must stop the translation as machine state (may have) changed */
3922 /* Note that mtmsr is not always defined as context-synchronizing */
3923 gen_stop_exception(ctx
);
3929 static void gen_mtmsr(DisasContext
*ctx
)
3931 #if defined(CONFIG_USER_ONLY)
3932 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3934 if (unlikely(!ctx
->mem_idx
)) {
3935 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3938 if (ctx
->opcode
& 0x00010000) {
3939 /* Special form that does not need any synchronisation */
3940 TCGv t0
= tcg_temp_new();
3941 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
3942 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
3943 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
3946 TCGv msr
= tcg_temp_new();
3948 /* XXX: we need to update nip before the store
3949 * if we enter power saving mode, we will exit the loop
3950 * directly from ppc_store_msr
3952 gen_update_nip(ctx
, ctx
->nip
);
3953 #if defined(TARGET_PPC64)
3954 tcg_gen_deposit_tl(msr
, cpu_msr
, cpu_gpr
[rS(ctx
->opcode
)], 0, 32);
3956 tcg_gen_mov_tl(msr
, cpu_gpr
[rS(ctx
->opcode
)]);
3958 gen_helper_store_msr(cpu_env
, msr
);
3959 /* Must stop the translation as machine state (may have) changed */
3960 /* Note that mtmsr is not always defined as context-synchronizing */
3961 gen_stop_exception(ctx
);
3967 static void gen_mtspr(DisasContext
*ctx
)
3969 void (*write_cb
)(void *opaque
, int sprn
, int gprn
);
3970 uint32_t sprn
= SPR(ctx
->opcode
);
3972 #if !defined(CONFIG_USER_ONLY)
3973 if (ctx
->mem_idx
== 2)
3974 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
3975 else if (ctx
->mem_idx
)
3976 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
3979 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
3980 if (likely(write_cb
!= NULL
)) {
3981 if (likely(write_cb
!= SPR_NOACCESS
)) {
3982 (*write_cb
)(ctx
, sprn
, rS(ctx
->opcode
));
3984 /* Privilege exception */
3985 qemu_log("Trying to write privileged spr %d %03x at "
3986 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
3987 printf("Trying to write privileged spr %d %03x at " TARGET_FMT_lx
3988 "\n", sprn
, sprn
, ctx
->nip
);
3989 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3993 qemu_log("Trying to write invalid spr %d %03x at "
3994 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
3995 printf("Trying to write invalid spr %d %03x at " TARGET_FMT_lx
"\n",
3996 sprn
, sprn
, ctx
->nip
);
3997 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4001 /*** Cache management ***/
4004 static void gen_dcbf(DisasContext
*ctx
)
4006 /* XXX: specification says this is treated as a load by the MMU */
4008 gen_set_access_type(ctx
, ACCESS_CACHE
);
4009 t0
= tcg_temp_new();
4010 gen_addr_reg_index(ctx
, t0
);
4011 gen_qemu_ld8u(ctx
, t0
, t0
);
4015 /* dcbi (Supervisor only) */
4016 static void gen_dcbi(DisasContext
*ctx
)
4018 #if defined(CONFIG_USER_ONLY)
4019 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4022 if (unlikely(!ctx
->mem_idx
)) {
4023 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4026 EA
= tcg_temp_new();
4027 gen_set_access_type(ctx
, ACCESS_CACHE
);
4028 gen_addr_reg_index(ctx
, EA
);
4029 val
= tcg_temp_new();
4030 /* XXX: specification says this should be treated as a store by the MMU */
4031 gen_qemu_ld8u(ctx
, val
, EA
);
4032 gen_qemu_st8(ctx
, val
, EA
);
4039 static void gen_dcbst(DisasContext
*ctx
)
4041 /* XXX: specification say this is treated as a load by the MMU */
4043 gen_set_access_type(ctx
, ACCESS_CACHE
);
4044 t0
= tcg_temp_new();
4045 gen_addr_reg_index(ctx
, t0
);
4046 gen_qemu_ld8u(ctx
, t0
, t0
);
4051 static void gen_dcbt(DisasContext
*ctx
)
4053 /* interpreted as no-op */
4054 /* XXX: specification say this is treated as a load by the MMU
4055 * but does not generate any exception
4060 static void gen_dcbtst(DisasContext
*ctx
)
4062 /* interpreted as no-op */
4063 /* XXX: specification say this is treated as a load by the MMU
4064 * but does not generate any exception
4069 static void gen_dcbz(DisasContext
*ctx
)
4072 TCGv_i32 tcgv_is_dcbzl
;
4073 int is_dcbzl
= ctx
->opcode
& 0x00200000 ? 1 : 0;
4075 gen_set_access_type(ctx
, ACCESS_CACHE
);
4076 /* NIP cannot be restored if the memory exception comes from an helper */
4077 gen_update_nip(ctx
, ctx
->nip
- 4);
4078 tcgv_addr
= tcg_temp_new();
4079 tcgv_is_dcbzl
= tcg_const_i32(is_dcbzl
);
4081 gen_addr_reg_index(ctx
, tcgv_addr
);
4082 gen_helper_dcbz(cpu_env
, tcgv_addr
, tcgv_is_dcbzl
);
4084 tcg_temp_free(tcgv_addr
);
4085 tcg_temp_free_i32(tcgv_is_dcbzl
);
4089 static void gen_dst(DisasContext
*ctx
)
4091 if (rA(ctx
->opcode
) == 0) {
4092 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
4094 /* interpreted as no-op */
4099 static void gen_dstst(DisasContext
*ctx
)
4101 if (rA(ctx
->opcode
) == 0) {
4102 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
4104 /* interpreted as no-op */
4110 static void gen_dss(DisasContext
*ctx
)
4112 /* interpreted as no-op */
4116 static void gen_icbi(DisasContext
*ctx
)
4119 gen_set_access_type(ctx
, ACCESS_CACHE
);
4120 /* NIP cannot be restored if the memory exception comes from an helper */
4121 gen_update_nip(ctx
, ctx
->nip
- 4);
4122 t0
= tcg_temp_new();
4123 gen_addr_reg_index(ctx
, t0
);
4124 gen_helper_icbi(cpu_env
, t0
);
4130 static void gen_dcba(DisasContext
*ctx
)
4132 /* interpreted as no-op */
4133 /* XXX: specification say this is treated as a store by the MMU
4134 * but does not generate any exception
4138 /*** Segment register manipulation ***/
4139 /* Supervisor only: */
4142 static void gen_mfsr(DisasContext
*ctx
)
4144 #if defined(CONFIG_USER_ONLY)
4145 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4148 if (unlikely(!ctx
->mem_idx
)) {
4149 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4152 t0
= tcg_const_tl(SR(ctx
->opcode
));
4153 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4159 static void gen_mfsrin(DisasContext
*ctx
)
4161 #if defined(CONFIG_USER_ONLY)
4162 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4165 if (unlikely(!ctx
->mem_idx
)) {
4166 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4169 t0
= tcg_temp_new();
4170 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4171 tcg_gen_andi_tl(t0
, t0
, 0xF);
4172 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4178 static void gen_mtsr(DisasContext
*ctx
)
4180 #if defined(CONFIG_USER_ONLY)
4181 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4184 if (unlikely(!ctx
->mem_idx
)) {
4185 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4188 t0
= tcg_const_tl(SR(ctx
->opcode
));
4189 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4195 static void gen_mtsrin(DisasContext
*ctx
)
4197 #if defined(CONFIG_USER_ONLY)
4198 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4201 if (unlikely(!ctx
->mem_idx
)) {
4202 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4205 t0
= tcg_temp_new();
4206 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4207 tcg_gen_andi_tl(t0
, t0
, 0xF);
4208 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rD(ctx
->opcode
)]);
4213 #if defined(TARGET_PPC64)
4214 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4217 static void gen_mfsr_64b(DisasContext
*ctx
)
4219 #if defined(CONFIG_USER_ONLY)
4220 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4223 if (unlikely(!ctx
->mem_idx
)) {
4224 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4227 t0
= tcg_const_tl(SR(ctx
->opcode
));
4228 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4234 static void gen_mfsrin_64b(DisasContext
*ctx
)
4236 #if defined(CONFIG_USER_ONLY)
4237 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4240 if (unlikely(!ctx
->mem_idx
)) {
4241 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4244 t0
= tcg_temp_new();
4245 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4246 tcg_gen_andi_tl(t0
, t0
, 0xF);
4247 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4253 static void gen_mtsr_64b(DisasContext
*ctx
)
4255 #if defined(CONFIG_USER_ONLY)
4256 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4259 if (unlikely(!ctx
->mem_idx
)) {
4260 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4263 t0
= tcg_const_tl(SR(ctx
->opcode
));
4264 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4270 static void gen_mtsrin_64b(DisasContext
*ctx
)
4272 #if defined(CONFIG_USER_ONLY)
4273 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4276 if (unlikely(!ctx
->mem_idx
)) {
4277 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4280 t0
= tcg_temp_new();
4281 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4282 tcg_gen_andi_tl(t0
, t0
, 0xF);
4283 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4289 static void gen_slbmte(DisasContext
*ctx
)
4291 #if defined(CONFIG_USER_ONLY)
4292 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4294 if (unlikely(!ctx
->mem_idx
)) {
4295 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4298 gen_helper_store_slb(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)],
4299 cpu_gpr
[rS(ctx
->opcode
)]);
4303 static void gen_slbmfee(DisasContext
*ctx
)
4305 #if defined(CONFIG_USER_ONLY)
4306 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4308 if (unlikely(!ctx
->mem_idx
)) {
4309 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4312 gen_helper_load_slb_esid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4313 cpu_gpr
[rB(ctx
->opcode
)]);
4317 static void gen_slbmfev(DisasContext
*ctx
)
4319 #if defined(CONFIG_USER_ONLY)
4320 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4322 if (unlikely(!ctx
->mem_idx
)) {
4323 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4326 gen_helper_load_slb_vsid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4327 cpu_gpr
[rB(ctx
->opcode
)]);
4330 #endif /* defined(TARGET_PPC64) */
4332 /*** Lookaside buffer management ***/
4333 /* Optional & mem_idx only: */
4336 static void gen_tlbia(DisasContext
*ctx
)
4338 #if defined(CONFIG_USER_ONLY)
4339 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4341 if (unlikely(!ctx
->mem_idx
)) {
4342 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4345 gen_helper_tlbia(cpu_env
);
4350 static void gen_tlbiel(DisasContext
*ctx
)
4352 #if defined(CONFIG_USER_ONLY)
4353 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4355 if (unlikely(!ctx
->mem_idx
)) {
4356 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4359 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4364 static void gen_tlbie(DisasContext
*ctx
)
4366 #if defined(CONFIG_USER_ONLY)
4367 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4369 if (unlikely(!ctx
->mem_idx
)) {
4370 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4373 #if defined(TARGET_PPC64)
4374 if (!ctx
->sf_mode
) {
4375 TCGv t0
= tcg_temp_new();
4376 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
4377 gen_helper_tlbie(cpu_env
, t0
);
4381 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4386 static void gen_tlbsync(DisasContext
*ctx
)
4388 #if defined(CONFIG_USER_ONLY)
4389 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4391 if (unlikely(!ctx
->mem_idx
)) {
4392 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4395 /* This has no effect: it should ensure that all previous
4396 * tlbie have completed
4398 gen_stop_exception(ctx
);
4402 #if defined(TARGET_PPC64)
4404 static void gen_slbia(DisasContext
*ctx
)
4406 #if defined(CONFIG_USER_ONLY)
4407 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4409 if (unlikely(!ctx
->mem_idx
)) {
4410 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4413 gen_helper_slbia(cpu_env
);
4418 static void gen_slbie(DisasContext
*ctx
)
4420 #if defined(CONFIG_USER_ONLY)
4421 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4423 if (unlikely(!ctx
->mem_idx
)) {
4424 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4427 gen_helper_slbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4432 /*** External control ***/
4436 static void gen_eciwx(DisasContext
*ctx
)
4439 /* Should check EAR[E] ! */
4440 gen_set_access_type(ctx
, ACCESS_EXT
);
4441 t0
= tcg_temp_new();
4442 gen_addr_reg_index(ctx
, t0
);
4443 gen_check_align(ctx
, t0
, 0x03);
4444 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4449 static void gen_ecowx(DisasContext
*ctx
)
4452 /* Should check EAR[E] ! */
4453 gen_set_access_type(ctx
, ACCESS_EXT
);
4454 t0
= tcg_temp_new();
4455 gen_addr_reg_index(ctx
, t0
);
4456 gen_check_align(ctx
, t0
, 0x03);
4457 gen_qemu_st32(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4461 /* PowerPC 601 specific instructions */
4464 static void gen_abs(DisasContext
*ctx
)
4466 int l1
= gen_new_label();
4467 int l2
= gen_new_label();
4468 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4469 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4472 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4474 if (unlikely(Rc(ctx
->opcode
) != 0))
4475 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4479 static void gen_abso(DisasContext
*ctx
)
4481 int l1
= gen_new_label();
4482 int l2
= gen_new_label();
4483 int l3
= gen_new_label();
4484 /* Start with XER OV disabled, the most likely case */
4485 tcg_gen_movi_tl(cpu_ov
, 0);
4486 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l2
);
4487 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rA(ctx
->opcode
)], 0x80000000, l1
);
4488 tcg_gen_movi_tl(cpu_ov
, 1);
4489 tcg_gen_movi_tl(cpu_so
, 1);
4492 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4495 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4497 if (unlikely(Rc(ctx
->opcode
) != 0))
4498 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4502 static void gen_clcs(DisasContext
*ctx
)
4504 TCGv_i32 t0
= tcg_const_i32(rA(ctx
->opcode
));
4505 gen_helper_clcs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4506 tcg_temp_free_i32(t0
);
4507 /* Rc=1 sets CR0 to an undefined state */
4511 static void gen_div(DisasContext
*ctx
)
4513 gen_helper_div(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4514 cpu_gpr
[rB(ctx
->opcode
)]);
4515 if (unlikely(Rc(ctx
->opcode
) != 0))
4516 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4520 static void gen_divo(DisasContext
*ctx
)
4522 gen_helper_divo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4523 cpu_gpr
[rB(ctx
->opcode
)]);
4524 if (unlikely(Rc(ctx
->opcode
) != 0))
4525 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4529 static void gen_divs(DisasContext
*ctx
)
4531 gen_helper_divs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4532 cpu_gpr
[rB(ctx
->opcode
)]);
4533 if (unlikely(Rc(ctx
->opcode
) != 0))
4534 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4537 /* divso - divso. */
4538 static void gen_divso(DisasContext
*ctx
)
4540 gen_helper_divso(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
4541 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4542 if (unlikely(Rc(ctx
->opcode
) != 0))
4543 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4547 static void gen_doz(DisasContext
*ctx
)
4549 int l1
= gen_new_label();
4550 int l2
= gen_new_label();
4551 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4552 tcg_gen_sub_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4555 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4557 if (unlikely(Rc(ctx
->opcode
) != 0))
4558 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4562 static void gen_dozo(DisasContext
*ctx
)
4564 int l1
= gen_new_label();
4565 int l2
= gen_new_label();
4566 TCGv t0
= tcg_temp_new();
4567 TCGv t1
= tcg_temp_new();
4568 TCGv t2
= tcg_temp_new();
4569 /* Start with XER OV disabled, the most likely case */
4570 tcg_gen_movi_tl(cpu_ov
, 0);
4571 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4572 tcg_gen_sub_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4573 tcg_gen_xor_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4574 tcg_gen_xor_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], t0
);
4575 tcg_gen_andc_tl(t1
, t1
, t2
);
4576 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4577 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
4578 tcg_gen_movi_tl(cpu_ov
, 1);
4579 tcg_gen_movi_tl(cpu_so
, 1);
4582 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4587 if (unlikely(Rc(ctx
->opcode
) != 0))
4588 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4592 static void gen_dozi(DisasContext
*ctx
)
4594 target_long simm
= SIMM(ctx
->opcode
);
4595 int l1
= gen_new_label();
4596 int l2
= gen_new_label();
4597 tcg_gen_brcondi_tl(TCG_COND_LT
, cpu_gpr
[rA(ctx
->opcode
)], simm
, l1
);
4598 tcg_gen_subfi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
, cpu_gpr
[rA(ctx
->opcode
)]);
4601 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4603 if (unlikely(Rc(ctx
->opcode
) != 0))
4604 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4607 /* lscbx - lscbx. */
4608 static void gen_lscbx(DisasContext
*ctx
)
4610 TCGv t0
= tcg_temp_new();
4611 TCGv_i32 t1
= tcg_const_i32(rD(ctx
->opcode
));
4612 TCGv_i32 t2
= tcg_const_i32(rA(ctx
->opcode
));
4613 TCGv_i32 t3
= tcg_const_i32(rB(ctx
->opcode
));
4615 gen_addr_reg_index(ctx
, t0
);
4616 /* NIP cannot be restored if the memory exception comes from an helper */
4617 gen_update_nip(ctx
, ctx
->nip
- 4);
4618 gen_helper_lscbx(t0
, cpu_env
, t0
, t1
, t2
, t3
);
4619 tcg_temp_free_i32(t1
);
4620 tcg_temp_free_i32(t2
);
4621 tcg_temp_free_i32(t3
);
4622 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~0x7F);
4623 tcg_gen_or_tl(cpu_xer
, cpu_xer
, t0
);
4624 if (unlikely(Rc(ctx
->opcode
) != 0))
4625 gen_set_Rc0(ctx
, t0
);
4629 /* maskg - maskg. */
4630 static void gen_maskg(DisasContext
*ctx
)
4632 int l1
= gen_new_label();
4633 TCGv t0
= tcg_temp_new();
4634 TCGv t1
= tcg_temp_new();
4635 TCGv t2
= tcg_temp_new();
4636 TCGv t3
= tcg_temp_new();
4637 tcg_gen_movi_tl(t3
, 0xFFFFFFFF);
4638 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4639 tcg_gen_andi_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 0x1F);
4640 tcg_gen_addi_tl(t2
, t0
, 1);
4641 tcg_gen_shr_tl(t2
, t3
, t2
);
4642 tcg_gen_shr_tl(t3
, t3
, t1
);
4643 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], t2
, t3
);
4644 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
4645 tcg_gen_neg_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4651 if (unlikely(Rc(ctx
->opcode
) != 0))
4652 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4655 /* maskir - maskir. */
4656 static void gen_maskir(DisasContext
*ctx
)
4658 TCGv t0
= tcg_temp_new();
4659 TCGv t1
= tcg_temp_new();
4660 tcg_gen_and_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4661 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4662 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4665 if (unlikely(Rc(ctx
->opcode
) != 0))
4666 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4670 static void gen_mul(DisasContext
*ctx
)
4672 TCGv_i64 t0
= tcg_temp_new_i64();
4673 TCGv_i64 t1
= tcg_temp_new_i64();
4674 TCGv t2
= tcg_temp_new();
4675 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4676 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4677 tcg_gen_mul_i64(t0
, t0
, t1
);
4678 tcg_gen_trunc_i64_tl(t2
, t0
);
4679 gen_store_spr(SPR_MQ
, t2
);
4680 tcg_gen_shri_i64(t1
, t0
, 32);
4681 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4682 tcg_temp_free_i64(t0
);
4683 tcg_temp_free_i64(t1
);
4685 if (unlikely(Rc(ctx
->opcode
) != 0))
4686 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4690 static void gen_mulo(DisasContext
*ctx
)
4692 int l1
= gen_new_label();
4693 TCGv_i64 t0
= tcg_temp_new_i64();
4694 TCGv_i64 t1
= tcg_temp_new_i64();
4695 TCGv t2
= tcg_temp_new();
4696 /* Start with XER OV disabled, the most likely case */
4697 tcg_gen_movi_tl(cpu_ov
, 0);
4698 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4699 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4700 tcg_gen_mul_i64(t0
, t0
, t1
);
4701 tcg_gen_trunc_i64_tl(t2
, t0
);
4702 gen_store_spr(SPR_MQ
, t2
);
4703 tcg_gen_shri_i64(t1
, t0
, 32);
4704 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4705 tcg_gen_ext32s_i64(t1
, t0
);
4706 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
4707 tcg_gen_movi_tl(cpu_ov
, 1);
4708 tcg_gen_movi_tl(cpu_so
, 1);
4710 tcg_temp_free_i64(t0
);
4711 tcg_temp_free_i64(t1
);
4713 if (unlikely(Rc(ctx
->opcode
) != 0))
4714 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4718 static void gen_nabs(DisasContext
*ctx
)
4720 int l1
= gen_new_label();
4721 int l2
= gen_new_label();
4722 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4723 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4726 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4728 if (unlikely(Rc(ctx
->opcode
) != 0))
4729 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4732 /* nabso - nabso. */
4733 static void gen_nabso(DisasContext
*ctx
)
4735 int l1
= gen_new_label();
4736 int l2
= gen_new_label();
4737 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4738 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4741 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4743 /* nabs never overflows */
4744 tcg_gen_movi_tl(cpu_ov
, 0);
4745 if (unlikely(Rc(ctx
->opcode
) != 0))
4746 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4750 static void gen_rlmi(DisasContext
*ctx
)
4752 uint32_t mb
= MB(ctx
->opcode
);
4753 uint32_t me
= ME(ctx
->opcode
);
4754 TCGv t0
= tcg_temp_new();
4755 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4756 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4757 tcg_gen_andi_tl(t0
, t0
, MASK(mb
, me
));
4758 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~MASK(mb
, me
));
4759 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], t0
);
4761 if (unlikely(Rc(ctx
->opcode
) != 0))
4762 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4766 static void gen_rrib(DisasContext
*ctx
)
4768 TCGv t0
= tcg_temp_new();
4769 TCGv t1
= tcg_temp_new();
4770 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4771 tcg_gen_movi_tl(t1
, 0x80000000);
4772 tcg_gen_shr_tl(t1
, t1
, t0
);
4773 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4774 tcg_gen_and_tl(t0
, t0
, t1
);
4775 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], t1
);
4776 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4779 if (unlikely(Rc(ctx
->opcode
) != 0))
4780 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4784 static void gen_sle(DisasContext
*ctx
)
4786 TCGv t0
= tcg_temp_new();
4787 TCGv t1
= tcg_temp_new();
4788 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4789 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4790 tcg_gen_subfi_tl(t1
, 32, t1
);
4791 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4792 tcg_gen_or_tl(t1
, t0
, t1
);
4793 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4794 gen_store_spr(SPR_MQ
, t1
);
4797 if (unlikely(Rc(ctx
->opcode
) != 0))
4798 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4802 static void gen_sleq(DisasContext
*ctx
)
4804 TCGv t0
= tcg_temp_new();
4805 TCGv t1
= tcg_temp_new();
4806 TCGv t2
= tcg_temp_new();
4807 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4808 tcg_gen_movi_tl(t2
, 0xFFFFFFFF);
4809 tcg_gen_shl_tl(t2
, t2
, t0
);
4810 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4811 gen_load_spr(t1
, SPR_MQ
);
4812 gen_store_spr(SPR_MQ
, t0
);
4813 tcg_gen_and_tl(t0
, t0
, t2
);
4814 tcg_gen_andc_tl(t1
, t1
, t2
);
4815 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4819 if (unlikely(Rc(ctx
->opcode
) != 0))
4820 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4824 static void gen_sliq(DisasContext
*ctx
)
4826 int sh
= SH(ctx
->opcode
);
4827 TCGv t0
= tcg_temp_new();
4828 TCGv t1
= tcg_temp_new();
4829 tcg_gen_shli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4830 tcg_gen_shri_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
4831 tcg_gen_or_tl(t1
, t0
, t1
);
4832 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4833 gen_store_spr(SPR_MQ
, t1
);
4836 if (unlikely(Rc(ctx
->opcode
) != 0))
4837 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4840 /* slliq - slliq. */
4841 static void gen_slliq(DisasContext
*ctx
)
4843 int sh
= SH(ctx
->opcode
);
4844 TCGv t0
= tcg_temp_new();
4845 TCGv t1
= tcg_temp_new();
4846 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4847 gen_load_spr(t1
, SPR_MQ
);
4848 gen_store_spr(SPR_MQ
, t0
);
4849 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
<< sh
));
4850 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
<< sh
));
4851 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4854 if (unlikely(Rc(ctx
->opcode
) != 0))
4855 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4859 static void gen_sllq(DisasContext
*ctx
)
4861 int l1
= gen_new_label();
4862 int l2
= gen_new_label();
4863 TCGv t0
= tcg_temp_local_new();
4864 TCGv t1
= tcg_temp_local_new();
4865 TCGv t2
= tcg_temp_local_new();
4866 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4867 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
4868 tcg_gen_shl_tl(t1
, t1
, t2
);
4869 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4870 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
4871 gen_load_spr(t0
, SPR_MQ
);
4872 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4875 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4876 gen_load_spr(t2
, SPR_MQ
);
4877 tcg_gen_andc_tl(t1
, t2
, t1
);
4878 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4883 if (unlikely(Rc(ctx
->opcode
) != 0))
4884 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4888 static void gen_slq(DisasContext
*ctx
)
4890 int l1
= gen_new_label();
4891 TCGv t0
= tcg_temp_new();
4892 TCGv t1
= tcg_temp_new();
4893 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4894 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4895 tcg_gen_subfi_tl(t1
, 32, t1
);
4896 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4897 tcg_gen_or_tl(t1
, t0
, t1
);
4898 gen_store_spr(SPR_MQ
, t1
);
4899 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4900 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4901 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
4902 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
4906 if (unlikely(Rc(ctx
->opcode
) != 0))
4907 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4910 /* sraiq - sraiq. */
4911 static void gen_sraiq(DisasContext
*ctx
)
4913 int sh
= SH(ctx
->opcode
);
4914 int l1
= gen_new_label();
4915 TCGv t0
= tcg_temp_new();
4916 TCGv t1
= tcg_temp_new();
4917 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4918 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
4919 tcg_gen_or_tl(t0
, t0
, t1
);
4920 gen_store_spr(SPR_MQ
, t0
);
4921 tcg_gen_movi_tl(cpu_ca
, 0);
4922 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
4923 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
4924 tcg_gen_movi_tl(cpu_ca
, 1);
4926 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
4929 if (unlikely(Rc(ctx
->opcode
) != 0))
4930 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4934 static void gen_sraq(DisasContext
*ctx
)
4936 int l1
= gen_new_label();
4937 int l2
= gen_new_label();
4938 TCGv t0
= tcg_temp_new();
4939 TCGv t1
= tcg_temp_local_new();
4940 TCGv t2
= tcg_temp_local_new();
4941 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4942 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4943 tcg_gen_sar_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4944 tcg_gen_subfi_tl(t2
, 32, t2
);
4945 tcg_gen_shl_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4946 tcg_gen_or_tl(t0
, t0
, t2
);
4947 gen_store_spr(SPR_MQ
, t0
);
4948 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4949 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l1
);
4950 tcg_gen_mov_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
4951 tcg_gen_sari_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 31);
4954 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
);
4955 tcg_gen_movi_tl(cpu_ca
, 0);
4956 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
4957 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l2
);
4958 tcg_gen_movi_tl(cpu_ca
, 1);
4962 if (unlikely(Rc(ctx
->opcode
) != 0))
4963 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4967 static void gen_sre(DisasContext
*ctx
)
4969 TCGv t0
= tcg_temp_new();
4970 TCGv t1
= tcg_temp_new();
4971 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4972 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4973 tcg_gen_subfi_tl(t1
, 32, t1
);
4974 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4975 tcg_gen_or_tl(t1
, t0
, t1
);
4976 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4977 gen_store_spr(SPR_MQ
, t1
);
4980 if (unlikely(Rc(ctx
->opcode
) != 0))
4981 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4985 static void gen_srea(DisasContext
*ctx
)
4987 TCGv t0
= tcg_temp_new();
4988 TCGv t1
= tcg_temp_new();
4989 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4990 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4991 gen_store_spr(SPR_MQ
, t0
);
4992 tcg_gen_sar_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t1
);
4995 if (unlikely(Rc(ctx
->opcode
) != 0))
4996 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5000 static void gen_sreq(DisasContext
*ctx
)
5002 TCGv t0
= tcg_temp_new();
5003 TCGv t1
= tcg_temp_new();
5004 TCGv t2
= tcg_temp_new();
5005 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5006 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5007 tcg_gen_shr_tl(t1
, t1
, t0
);
5008 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5009 gen_load_spr(t2
, SPR_MQ
);
5010 gen_store_spr(SPR_MQ
, t0
);
5011 tcg_gen_and_tl(t0
, t0
, t1
);
5012 tcg_gen_andc_tl(t2
, t2
, t1
);
5013 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5017 if (unlikely(Rc(ctx
->opcode
) != 0))
5018 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5022 static void gen_sriq(DisasContext
*ctx
)
5024 int sh
= SH(ctx
->opcode
);
5025 TCGv t0
= tcg_temp_new();
5026 TCGv t1
= tcg_temp_new();
5027 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5028 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5029 tcg_gen_or_tl(t1
, t0
, t1
);
5030 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5031 gen_store_spr(SPR_MQ
, t1
);
5034 if (unlikely(Rc(ctx
->opcode
) != 0))
5035 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5039 static void gen_srliq(DisasContext
*ctx
)
5041 int sh
= SH(ctx
->opcode
);
5042 TCGv t0
= tcg_temp_new();
5043 TCGv t1
= tcg_temp_new();
5044 tcg_gen_rotri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5045 gen_load_spr(t1
, SPR_MQ
);
5046 gen_store_spr(SPR_MQ
, t0
);
5047 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
>> sh
));
5048 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
>> sh
));
5049 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5052 if (unlikely(Rc(ctx
->opcode
) != 0))
5053 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5057 static void gen_srlq(DisasContext
*ctx
)
5059 int l1
= gen_new_label();
5060 int l2
= gen_new_label();
5061 TCGv t0
= tcg_temp_local_new();
5062 TCGv t1
= tcg_temp_local_new();
5063 TCGv t2
= tcg_temp_local_new();
5064 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5065 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5066 tcg_gen_shr_tl(t2
, t1
, t2
);
5067 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5068 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5069 gen_load_spr(t0
, SPR_MQ
);
5070 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5073 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5074 tcg_gen_and_tl(t0
, t0
, t2
);
5075 gen_load_spr(t1
, SPR_MQ
);
5076 tcg_gen_andc_tl(t1
, t1
, t2
);
5077 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5082 if (unlikely(Rc(ctx
->opcode
) != 0))
5083 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5087 static void gen_srq(DisasContext
*ctx
)
5089 int l1
= gen_new_label();
5090 TCGv t0
= tcg_temp_new();
5091 TCGv t1
= tcg_temp_new();
5092 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5093 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5094 tcg_gen_subfi_tl(t1
, 32, t1
);
5095 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5096 tcg_gen_or_tl(t1
, t0
, t1
);
5097 gen_store_spr(SPR_MQ
, t1
);
5098 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5099 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5100 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5101 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5105 if (unlikely(Rc(ctx
->opcode
) != 0))
5106 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5109 /* PowerPC 602 specific instructions */
5112 static void gen_dsa(DisasContext
*ctx
)
5115 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5119 static void gen_esa(DisasContext
*ctx
)
5122 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5126 static void gen_mfrom(DisasContext
*ctx
)
5128 #if defined(CONFIG_USER_ONLY)
5129 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5131 if (unlikely(!ctx
->mem_idx
)) {
5132 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5135 gen_helper_602_mfrom(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5139 /* 602 - 603 - G2 TLB management */
5142 static void gen_tlbld_6xx(DisasContext
*ctx
)
5144 #if defined(CONFIG_USER_ONLY)
5145 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5147 if (unlikely(!ctx
->mem_idx
)) {
5148 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5151 gen_helper_6xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5156 static void gen_tlbli_6xx(DisasContext
*ctx
)
5158 #if defined(CONFIG_USER_ONLY)
5159 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5161 if (unlikely(!ctx
->mem_idx
)) {
5162 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5165 gen_helper_6xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5169 /* 74xx TLB management */
5172 static void gen_tlbld_74xx(DisasContext
*ctx
)
5174 #if defined(CONFIG_USER_ONLY)
5175 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5177 if (unlikely(!ctx
->mem_idx
)) {
5178 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5181 gen_helper_74xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5186 static void gen_tlbli_74xx(DisasContext
*ctx
)
5188 #if defined(CONFIG_USER_ONLY)
5189 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5191 if (unlikely(!ctx
->mem_idx
)) {
5192 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5195 gen_helper_74xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5199 /* POWER instructions not in PowerPC 601 */
5202 static void gen_clf(DisasContext
*ctx
)
5204 /* Cache line flush: implemented as no-op */
5208 static void gen_cli(DisasContext
*ctx
)
5210 /* Cache line invalidate: privileged and treated as no-op */
5211 #if defined(CONFIG_USER_ONLY)
5212 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5214 if (unlikely(!ctx
->mem_idx
)) {
5215 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5222 static void gen_dclst(DisasContext
*ctx
)
5224 /* Data cache line store: treated as no-op */
5227 static void gen_mfsri(DisasContext
*ctx
)
5229 #if defined(CONFIG_USER_ONLY)
5230 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5232 int ra
= rA(ctx
->opcode
);
5233 int rd
= rD(ctx
->opcode
);
5235 if (unlikely(!ctx
->mem_idx
)) {
5236 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5239 t0
= tcg_temp_new();
5240 gen_addr_reg_index(ctx
, t0
);
5241 tcg_gen_shri_tl(t0
, t0
, 28);
5242 tcg_gen_andi_tl(t0
, t0
, 0xF);
5243 gen_helper_load_sr(cpu_gpr
[rd
], cpu_env
, t0
);
5245 if (ra
!= 0 && ra
!= rd
)
5246 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rd
]);
5250 static void gen_rac(DisasContext
*ctx
)
5252 #if defined(CONFIG_USER_ONLY)
5253 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5256 if (unlikely(!ctx
->mem_idx
)) {
5257 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5260 t0
= tcg_temp_new();
5261 gen_addr_reg_index(ctx
, t0
);
5262 gen_helper_rac(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5267 static void gen_rfsvc(DisasContext
*ctx
)
5269 #if defined(CONFIG_USER_ONLY)
5270 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5272 if (unlikely(!ctx
->mem_idx
)) {
5273 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5276 gen_helper_rfsvc(cpu_env
);
5277 gen_sync_exception(ctx
);
5281 /* svc is not implemented for now */
5283 /* POWER2 specific instructions */
5284 /* Quad manipulation (load/store two floats at a time) */
5287 static void gen_lfq(DisasContext
*ctx
)
5289 int rd
= rD(ctx
->opcode
);
5291 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5292 t0
= tcg_temp_new();
5293 gen_addr_imm_index(ctx
, t0
, 0);
5294 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5295 gen_addr_add(ctx
, t0
, t0
, 8);
5296 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5301 static void gen_lfqu(DisasContext
*ctx
)
5303 int ra
= rA(ctx
->opcode
);
5304 int rd
= rD(ctx
->opcode
);
5306 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5307 t0
= tcg_temp_new();
5308 t1
= tcg_temp_new();
5309 gen_addr_imm_index(ctx
, t0
, 0);
5310 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5311 gen_addr_add(ctx
, t1
, t0
, 8);
5312 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5314 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5320 static void gen_lfqux(DisasContext
*ctx
)
5322 int ra
= rA(ctx
->opcode
);
5323 int rd
= rD(ctx
->opcode
);
5324 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5326 t0
= tcg_temp_new();
5327 gen_addr_reg_index(ctx
, t0
);
5328 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5329 t1
= tcg_temp_new();
5330 gen_addr_add(ctx
, t1
, t0
, 8);
5331 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5334 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5339 static void gen_lfqx(DisasContext
*ctx
)
5341 int rd
= rD(ctx
->opcode
);
5343 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5344 t0
= tcg_temp_new();
5345 gen_addr_reg_index(ctx
, t0
);
5346 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5347 gen_addr_add(ctx
, t0
, t0
, 8);
5348 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5353 static void gen_stfq(DisasContext
*ctx
)
5355 int rd
= rD(ctx
->opcode
);
5357 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5358 t0
= tcg_temp_new();
5359 gen_addr_imm_index(ctx
, t0
, 0);
5360 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5361 gen_addr_add(ctx
, t0
, t0
, 8);
5362 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5367 static void gen_stfqu(DisasContext
*ctx
)
5369 int ra
= rA(ctx
->opcode
);
5370 int rd
= rD(ctx
->opcode
);
5372 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5373 t0
= tcg_temp_new();
5374 gen_addr_imm_index(ctx
, t0
, 0);
5375 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5376 t1
= tcg_temp_new();
5377 gen_addr_add(ctx
, t1
, t0
, 8);
5378 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5381 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5386 static void gen_stfqux(DisasContext
*ctx
)
5388 int ra
= rA(ctx
->opcode
);
5389 int rd
= rD(ctx
->opcode
);
5391 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5392 t0
= tcg_temp_new();
5393 gen_addr_reg_index(ctx
, t0
);
5394 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5395 t1
= tcg_temp_new();
5396 gen_addr_add(ctx
, t1
, t0
, 8);
5397 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5400 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5405 static void gen_stfqx(DisasContext
*ctx
)
5407 int rd
= rD(ctx
->opcode
);
5409 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5410 t0
= tcg_temp_new();
5411 gen_addr_reg_index(ctx
, t0
);
5412 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5413 gen_addr_add(ctx
, t0
, t0
, 8);
5414 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5418 /* BookE specific instructions */
5420 /* XXX: not implemented on 440 ? */
5421 static void gen_mfapidi(DisasContext
*ctx
)
5424 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5427 /* XXX: not implemented on 440 ? */
5428 static void gen_tlbiva(DisasContext
*ctx
)
5430 #if defined(CONFIG_USER_ONLY)
5431 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5434 if (unlikely(!ctx
->mem_idx
)) {
5435 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5438 t0
= tcg_temp_new();
5439 gen_addr_reg_index(ctx
, t0
);
5440 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5445 /* All 405 MAC instructions are translated here */
5446 static inline void gen_405_mulladd_insn(DisasContext
*ctx
, int opc2
, int opc3
,
5447 int ra
, int rb
, int rt
, int Rc
)
5451 t0
= tcg_temp_local_new();
5452 t1
= tcg_temp_local_new();
5454 switch (opc3
& 0x0D) {
5456 /* macchw - macchw. - macchwo - macchwo. */
5457 /* macchws - macchws. - macchwso - macchwso. */
5458 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5459 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5460 /* mulchw - mulchw. */
5461 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5462 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5463 tcg_gen_ext16s_tl(t1
, t1
);
5466 /* macchwu - macchwu. - macchwuo - macchwuo. */
5467 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5468 /* mulchwu - mulchwu. */
5469 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5470 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5471 tcg_gen_ext16u_tl(t1
, t1
);
5474 /* machhw - machhw. - machhwo - machhwo. */
5475 /* machhws - machhws. - machhwso - machhwso. */
5476 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5477 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5478 /* mulhhw - mulhhw. */
5479 tcg_gen_sari_tl(t0
, cpu_gpr
[ra
], 16);
5480 tcg_gen_ext16s_tl(t0
, t0
);
5481 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5482 tcg_gen_ext16s_tl(t1
, t1
);
5485 /* machhwu - machhwu. - machhwuo - machhwuo. */
5486 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5487 /* mulhhwu - mulhhwu. */
5488 tcg_gen_shri_tl(t0
, cpu_gpr
[ra
], 16);
5489 tcg_gen_ext16u_tl(t0
, t0
);
5490 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5491 tcg_gen_ext16u_tl(t1
, t1
);
5494 /* maclhw - maclhw. - maclhwo - maclhwo. */
5495 /* maclhws - maclhws. - maclhwso - maclhwso. */
5496 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5497 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5498 /* mullhw - mullhw. */
5499 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5500 tcg_gen_ext16s_tl(t1
, cpu_gpr
[rb
]);
5503 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5504 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5505 /* mullhwu - mullhwu. */
5506 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5507 tcg_gen_ext16u_tl(t1
, cpu_gpr
[rb
]);
5511 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5512 tcg_gen_mul_tl(t1
, t0
, t1
);
5514 /* nmultiply-and-accumulate (0x0E) */
5515 tcg_gen_sub_tl(t0
, cpu_gpr
[rt
], t1
);
5517 /* multiply-and-accumulate (0x0C) */
5518 tcg_gen_add_tl(t0
, cpu_gpr
[rt
], t1
);
5522 /* Check overflow and/or saturate */
5523 int l1
= gen_new_label();
5526 /* Start with XER OV disabled, the most likely case */
5527 tcg_gen_movi_tl(cpu_ov
, 0);
5531 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t1
);
5532 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
5533 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t0
);
5534 tcg_gen_brcondi_tl(TCG_COND_LT
, t1
, 0, l1
);
5537 tcg_gen_sari_tl(t0
, cpu_gpr
[rt
], 31);
5538 tcg_gen_xori_tl(t0
, t0
, 0x7fffffff);
5542 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
5545 tcg_gen_movi_tl(t0
, UINT32_MAX
);
5549 /* Check overflow */
5550 tcg_gen_movi_tl(cpu_ov
, 1);
5551 tcg_gen_movi_tl(cpu_so
, 1);
5554 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
5557 tcg_gen_mul_tl(cpu_gpr
[rt
], t0
, t1
);
5561 if (unlikely(Rc
) != 0) {
5563 gen_set_Rc0(ctx
, cpu_gpr
[rt
]);
5567 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5568 static void glue(gen_, name)(DisasContext *ctx) \
5570 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5571 rD(ctx->opcode), Rc(ctx->opcode)); \
5574 /* macchw - macchw. */
5575 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
5576 /* macchwo - macchwo. */
5577 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
5578 /* macchws - macchws. */
5579 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
5580 /* macchwso - macchwso. */
5581 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
5582 /* macchwsu - macchwsu. */
5583 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
5584 /* macchwsuo - macchwsuo. */
5585 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
5586 /* macchwu - macchwu. */
5587 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
5588 /* macchwuo - macchwuo. */
5589 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
5590 /* machhw - machhw. */
5591 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
5592 /* machhwo - machhwo. */
5593 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
5594 /* machhws - machhws. */
5595 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
5596 /* machhwso - machhwso. */
5597 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
5598 /* machhwsu - machhwsu. */
5599 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
5600 /* machhwsuo - machhwsuo. */
5601 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
5602 /* machhwu - machhwu. */
5603 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
5604 /* machhwuo - machhwuo. */
5605 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
5606 /* maclhw - maclhw. */
5607 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
5608 /* maclhwo - maclhwo. */
5609 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
5610 /* maclhws - maclhws. */
5611 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
5612 /* maclhwso - maclhwso. */
5613 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
5614 /* maclhwu - maclhwu. */
5615 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
5616 /* maclhwuo - maclhwuo. */
5617 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
5618 /* maclhwsu - maclhwsu. */
5619 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
5620 /* maclhwsuo - maclhwsuo. */
5621 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
5622 /* nmacchw - nmacchw. */
5623 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
5624 /* nmacchwo - nmacchwo. */
5625 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
5626 /* nmacchws - nmacchws. */
5627 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
5628 /* nmacchwso - nmacchwso. */
5629 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
5630 /* nmachhw - nmachhw. */
5631 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
5632 /* nmachhwo - nmachhwo. */
5633 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
5634 /* nmachhws - nmachhws. */
5635 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
5636 /* nmachhwso - nmachhwso. */
5637 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
5638 /* nmaclhw - nmaclhw. */
5639 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
5640 /* nmaclhwo - nmaclhwo. */
5641 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
5642 /* nmaclhws - nmaclhws. */
5643 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
5644 /* nmaclhwso - nmaclhwso. */
5645 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
5647 /* mulchw - mulchw. */
5648 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
5649 /* mulchwu - mulchwu. */
5650 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
5651 /* mulhhw - mulhhw. */
5652 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
5653 /* mulhhwu - mulhhwu. */
5654 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
5655 /* mullhw - mullhw. */
5656 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
5657 /* mullhwu - mullhwu. */
5658 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
5661 static void gen_mfdcr(DisasContext
*ctx
)
5663 #if defined(CONFIG_USER_ONLY)
5664 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5667 if (unlikely(!ctx
->mem_idx
)) {
5668 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5671 /* NIP cannot be restored if the memory exception comes from an helper */
5672 gen_update_nip(ctx
, ctx
->nip
- 4);
5673 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5674 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, dcrn
);
5675 tcg_temp_free(dcrn
);
5680 static void gen_mtdcr(DisasContext
*ctx
)
5682 #if defined(CONFIG_USER_ONLY)
5683 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5686 if (unlikely(!ctx
->mem_idx
)) {
5687 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5690 /* NIP cannot be restored if the memory exception comes from an helper */
5691 gen_update_nip(ctx
, ctx
->nip
- 4);
5692 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5693 gen_helper_store_dcr(cpu_env
, dcrn
, cpu_gpr
[rS(ctx
->opcode
)]);
5694 tcg_temp_free(dcrn
);
5699 /* XXX: not implemented on 440 ? */
5700 static void gen_mfdcrx(DisasContext
*ctx
)
5702 #if defined(CONFIG_USER_ONLY)
5703 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5705 if (unlikely(!ctx
->mem_idx
)) {
5706 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5709 /* NIP cannot be restored if the memory exception comes from an helper */
5710 gen_update_nip(ctx
, ctx
->nip
- 4);
5711 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5712 cpu_gpr
[rA(ctx
->opcode
)]);
5713 /* Note: Rc update flag set leads to undefined state of Rc0 */
5718 /* XXX: not implemented on 440 ? */
5719 static void gen_mtdcrx(DisasContext
*ctx
)
5721 #if defined(CONFIG_USER_ONLY)
5722 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5724 if (unlikely(!ctx
->mem_idx
)) {
5725 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5728 /* NIP cannot be restored if the memory exception comes from an helper */
5729 gen_update_nip(ctx
, ctx
->nip
- 4);
5730 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5731 cpu_gpr
[rS(ctx
->opcode
)]);
5732 /* Note: Rc update flag set leads to undefined state of Rc0 */
5736 /* mfdcrux (PPC 460) : user-mode access to DCR */
5737 static void gen_mfdcrux(DisasContext
*ctx
)
5739 /* NIP cannot be restored if the memory exception comes from an helper */
5740 gen_update_nip(ctx
, ctx
->nip
- 4);
5741 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5742 cpu_gpr
[rA(ctx
->opcode
)]);
5743 /* Note: Rc update flag set leads to undefined state of Rc0 */
5746 /* mtdcrux (PPC 460) : user-mode access to DCR */
5747 static void gen_mtdcrux(DisasContext
*ctx
)
5749 /* NIP cannot be restored if the memory exception comes from an helper */
5750 gen_update_nip(ctx
, ctx
->nip
- 4);
5751 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5752 cpu_gpr
[rS(ctx
->opcode
)]);
5753 /* Note: Rc update flag set leads to undefined state of Rc0 */
5757 static void gen_dccci(DisasContext
*ctx
)
5759 #if defined(CONFIG_USER_ONLY)
5760 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5762 if (unlikely(!ctx
->mem_idx
)) {
5763 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5766 /* interpreted as no-op */
5771 static void gen_dcread(DisasContext
*ctx
)
5773 #if defined(CONFIG_USER_ONLY)
5774 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5777 if (unlikely(!ctx
->mem_idx
)) {
5778 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5781 gen_set_access_type(ctx
, ACCESS_CACHE
);
5782 EA
= tcg_temp_new();
5783 gen_addr_reg_index(ctx
, EA
);
5784 val
= tcg_temp_new();
5785 gen_qemu_ld32u(ctx
, val
, EA
);
5787 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], EA
);
5793 static void gen_icbt_40x(DisasContext
*ctx
)
5795 /* interpreted as no-op */
5796 /* XXX: specification say this is treated as a load by the MMU
5797 * but does not generate any exception
5802 static void gen_iccci(DisasContext
*ctx
)
5804 #if defined(CONFIG_USER_ONLY)
5805 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5807 if (unlikely(!ctx
->mem_idx
)) {
5808 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5811 /* interpreted as no-op */
5816 static void gen_icread(DisasContext
*ctx
)
5818 #if defined(CONFIG_USER_ONLY)
5819 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5821 if (unlikely(!ctx
->mem_idx
)) {
5822 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5825 /* interpreted as no-op */
5829 /* rfci (mem_idx only) */
5830 static void gen_rfci_40x(DisasContext
*ctx
)
5832 #if defined(CONFIG_USER_ONLY)
5833 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5835 if (unlikely(!ctx
->mem_idx
)) {
5836 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5839 /* Restore CPU state */
5840 gen_helper_40x_rfci(cpu_env
);
5841 gen_sync_exception(ctx
);
5845 static void gen_rfci(DisasContext
*ctx
)
5847 #if defined(CONFIG_USER_ONLY)
5848 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5850 if (unlikely(!ctx
->mem_idx
)) {
5851 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5854 /* Restore CPU state */
5855 gen_helper_rfci(cpu_env
);
5856 gen_sync_exception(ctx
);
5860 /* BookE specific */
5862 /* XXX: not implemented on 440 ? */
5863 static void gen_rfdi(DisasContext
*ctx
)
5865 #if defined(CONFIG_USER_ONLY)
5866 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5868 if (unlikely(!ctx
->mem_idx
)) {
5869 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5872 /* Restore CPU state */
5873 gen_helper_rfdi(cpu_env
);
5874 gen_sync_exception(ctx
);
5878 /* XXX: not implemented on 440 ? */
5879 static void gen_rfmci(DisasContext
*ctx
)
5881 #if defined(CONFIG_USER_ONLY)
5882 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5884 if (unlikely(!ctx
->mem_idx
)) {
5885 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5888 /* Restore CPU state */
5889 gen_helper_rfmci(cpu_env
);
5890 gen_sync_exception(ctx
);
5894 /* TLB management - PowerPC 405 implementation */
5897 static void gen_tlbre_40x(DisasContext
*ctx
)
5899 #if defined(CONFIG_USER_ONLY)
5900 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5902 if (unlikely(!ctx
->mem_idx
)) {
5903 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5906 switch (rB(ctx
->opcode
)) {
5908 gen_helper_4xx_tlbre_hi(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5909 cpu_gpr
[rA(ctx
->opcode
)]);
5912 gen_helper_4xx_tlbre_lo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5913 cpu_gpr
[rA(ctx
->opcode
)]);
5916 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5922 /* tlbsx - tlbsx. */
5923 static void gen_tlbsx_40x(DisasContext
*ctx
)
5925 #if defined(CONFIG_USER_ONLY)
5926 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5929 if (unlikely(!ctx
->mem_idx
)) {
5930 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5933 t0
= tcg_temp_new();
5934 gen_addr_reg_index(ctx
, t0
);
5935 gen_helper_4xx_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5937 if (Rc(ctx
->opcode
)) {
5938 int l1
= gen_new_label();
5939 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
5940 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
5941 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
5948 static void gen_tlbwe_40x(DisasContext
*ctx
)
5950 #if defined(CONFIG_USER_ONLY)
5951 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5953 if (unlikely(!ctx
->mem_idx
)) {
5954 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5957 switch (rB(ctx
->opcode
)) {
5959 gen_helper_4xx_tlbwe_hi(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5960 cpu_gpr
[rS(ctx
->opcode
)]);
5963 gen_helper_4xx_tlbwe_lo(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5964 cpu_gpr
[rS(ctx
->opcode
)]);
5967 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5973 /* TLB management - PowerPC 440 implementation */
5976 static void gen_tlbre_440(DisasContext
*ctx
)
5978 #if defined(CONFIG_USER_ONLY)
5979 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5981 if (unlikely(!ctx
->mem_idx
)) {
5982 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5985 switch (rB(ctx
->opcode
)) {
5990 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
5991 gen_helper_440_tlbre(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5992 t0
, cpu_gpr
[rA(ctx
->opcode
)]);
5993 tcg_temp_free_i32(t0
);
5997 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6003 /* tlbsx - tlbsx. */
6004 static void gen_tlbsx_440(DisasContext
*ctx
)
6006 #if defined(CONFIG_USER_ONLY)
6007 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6010 if (unlikely(!ctx
->mem_idx
)) {
6011 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6014 t0
= tcg_temp_new();
6015 gen_addr_reg_index(ctx
, t0
);
6016 gen_helper_440_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
6018 if (Rc(ctx
->opcode
)) {
6019 int l1
= gen_new_label();
6020 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
6021 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
6022 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
6029 static void gen_tlbwe_440(DisasContext
*ctx
)
6031 #if defined(CONFIG_USER_ONLY)
6032 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6034 if (unlikely(!ctx
->mem_idx
)) {
6035 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6038 switch (rB(ctx
->opcode
)) {
6043 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
6044 gen_helper_440_tlbwe(cpu_env
, t0
, cpu_gpr
[rA(ctx
->opcode
)],
6045 cpu_gpr
[rS(ctx
->opcode
)]);
6046 tcg_temp_free_i32(t0
);
6050 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6056 /* TLB management - PowerPC BookE 2.06 implementation */
6059 static void gen_tlbre_booke206(DisasContext
*ctx
)
6061 #if defined(CONFIG_USER_ONLY)
6062 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6064 if (unlikely(!ctx
->mem_idx
)) {
6065 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6069 gen_helper_booke206_tlbre(cpu_env
);
6073 /* tlbsx - tlbsx. */
6074 static void gen_tlbsx_booke206(DisasContext
*ctx
)
6076 #if defined(CONFIG_USER_ONLY)
6077 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6080 if (unlikely(!ctx
->mem_idx
)) {
6081 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6085 if (rA(ctx
->opcode
)) {
6086 t0
= tcg_temp_new();
6087 tcg_gen_mov_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)]);
6089 t0
= tcg_const_tl(0);
6092 tcg_gen_add_tl(t0
, t0
, cpu_gpr
[rB(ctx
->opcode
)]);
6093 gen_helper_booke206_tlbsx(cpu_env
, t0
);
6098 static void gen_tlbwe_booke206(DisasContext
*ctx
)
6100 #if defined(CONFIG_USER_ONLY)
6101 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6103 if (unlikely(!ctx
->mem_idx
)) {
6104 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6107 gen_update_nip(ctx
, ctx
->nip
- 4);
6108 gen_helper_booke206_tlbwe(cpu_env
);
6112 static void gen_tlbivax_booke206(DisasContext
*ctx
)
6114 #if defined(CONFIG_USER_ONLY)
6115 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6118 if (unlikely(!ctx
->mem_idx
)) {
6119 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6123 t0
= tcg_temp_new();
6124 gen_addr_reg_index(ctx
, t0
);
6126 gen_helper_booke206_tlbivax(cpu_env
, t0
);
6130 static void gen_tlbilx_booke206(DisasContext
*ctx
)
6132 #if defined(CONFIG_USER_ONLY)
6133 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6136 if (unlikely(!ctx
->mem_idx
)) {
6137 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6141 t0
= tcg_temp_new();
6142 gen_addr_reg_index(ctx
, t0
);
6144 switch((ctx
->opcode
>> 21) & 0x3) {
6146 gen_helper_booke206_tlbilx0(cpu_env
, t0
);
6149 gen_helper_booke206_tlbilx1(cpu_env
, t0
);
6152 gen_helper_booke206_tlbilx3(cpu_env
, t0
);
6155 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6165 static void gen_wrtee(DisasContext
*ctx
)
6167 #if defined(CONFIG_USER_ONLY)
6168 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6171 if (unlikely(!ctx
->mem_idx
)) {
6172 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6175 t0
= tcg_temp_new();
6176 tcg_gen_andi_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)], (1 << MSR_EE
));
6177 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6178 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
6180 /* Stop translation to have a chance to raise an exception
6181 * if we just set msr_ee to 1
6183 gen_stop_exception(ctx
);
6188 static void gen_wrteei(DisasContext
*ctx
)
6190 #if defined(CONFIG_USER_ONLY)
6191 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6193 if (unlikely(!ctx
->mem_idx
)) {
6194 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6197 if (ctx
->opcode
& 0x00008000) {
6198 tcg_gen_ori_tl(cpu_msr
, cpu_msr
, (1 << MSR_EE
));
6199 /* Stop translation to have a chance to raise an exception */
6200 gen_stop_exception(ctx
);
6202 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6207 /* PowerPC 440 specific instructions */
6210 static void gen_dlmzb(DisasContext
*ctx
)
6212 TCGv_i32 t0
= tcg_const_i32(Rc(ctx
->opcode
));
6213 gen_helper_dlmzb(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
6214 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
6215 tcg_temp_free_i32(t0
);
6218 /* mbar replaces eieio on 440 */
6219 static void gen_mbar(DisasContext
*ctx
)
6221 /* interpreted as no-op */
6224 /* msync replaces sync on 440 */
6225 static void gen_msync_4xx(DisasContext
*ctx
)
6227 /* interpreted as no-op */
6231 static void gen_icbt_440(DisasContext
*ctx
)
6233 /* interpreted as no-op */
6234 /* XXX: specification say this is treated as a load by the MMU
6235 * but does not generate any exception
6239 /* Embedded.Processor Control */
6241 static void gen_msgclr(DisasContext
*ctx
)
6243 #if defined(CONFIG_USER_ONLY)
6244 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6246 if (unlikely(ctx
->mem_idx
== 0)) {
6247 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6251 gen_helper_msgclr(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6255 static void gen_msgsnd(DisasContext
*ctx
)
6257 #if defined(CONFIG_USER_ONLY)
6258 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6260 if (unlikely(ctx
->mem_idx
== 0)) {
6261 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6265 gen_helper_msgsnd(cpu_gpr
[rB(ctx
->opcode
)]);
6269 /*** Altivec vector extension ***/
6270 /* Altivec registers moves */
6272 static inline TCGv_ptr
gen_avr_ptr(int reg
)
6274 TCGv_ptr r
= tcg_temp_new_ptr();
6275 tcg_gen_addi_ptr(r
, cpu_env
, offsetof(CPUPPCState
, avr
[reg
]));
6279 #define GEN_VR_LDX(name, opc2, opc3) \
6280 static void glue(gen_, name)(DisasContext *ctx) \
6283 if (unlikely(!ctx->altivec_enabled)) { \
6284 gen_exception(ctx, POWERPC_EXCP_VPU); \
6287 gen_set_access_type(ctx, ACCESS_INT); \
6288 EA = tcg_temp_new(); \
6289 gen_addr_reg_index(ctx, EA); \
6290 tcg_gen_andi_tl(EA, EA, ~0xf); \
6291 if (ctx->le_mode) { \
6292 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6293 tcg_gen_addi_tl(EA, EA, 8); \
6294 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6296 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6297 tcg_gen_addi_tl(EA, EA, 8); \
6298 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6300 tcg_temp_free(EA); \
6303 #define GEN_VR_STX(name, opc2, opc3) \
6304 static void gen_st##name(DisasContext *ctx) \
6307 if (unlikely(!ctx->altivec_enabled)) { \
6308 gen_exception(ctx, POWERPC_EXCP_VPU); \
6311 gen_set_access_type(ctx, ACCESS_INT); \
6312 EA = tcg_temp_new(); \
6313 gen_addr_reg_index(ctx, EA); \
6314 tcg_gen_andi_tl(EA, EA, ~0xf); \
6315 if (ctx->le_mode) { \
6316 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6317 tcg_gen_addi_tl(EA, EA, 8); \
6318 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6320 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6321 tcg_gen_addi_tl(EA, EA, 8); \
6322 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6324 tcg_temp_free(EA); \
6327 #define GEN_VR_LVE(name, opc2, opc3) \
6328 static void gen_lve##name(DisasContext *ctx) \
6332 if (unlikely(!ctx->altivec_enabled)) { \
6333 gen_exception(ctx, POWERPC_EXCP_VPU); \
6336 gen_set_access_type(ctx, ACCESS_INT); \
6337 EA = tcg_temp_new(); \
6338 gen_addr_reg_index(ctx, EA); \
6339 rs = gen_avr_ptr(rS(ctx->opcode)); \
6340 gen_helper_lve##name(cpu_env, rs, EA); \
6341 tcg_temp_free(EA); \
6342 tcg_temp_free_ptr(rs); \
6345 #define GEN_VR_STVE(name, opc2, opc3) \
6346 static void gen_stve##name(DisasContext *ctx) \
6350 if (unlikely(!ctx->altivec_enabled)) { \
6351 gen_exception(ctx, POWERPC_EXCP_VPU); \
6354 gen_set_access_type(ctx, ACCESS_INT); \
6355 EA = tcg_temp_new(); \
6356 gen_addr_reg_index(ctx, EA); \
6357 rs = gen_avr_ptr(rS(ctx->opcode)); \
6358 gen_helper_stve##name(cpu_env, rs, EA); \
6359 tcg_temp_free(EA); \
6360 tcg_temp_free_ptr(rs); \
6363 GEN_VR_LDX(lvx
, 0x07, 0x03);
6364 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
6365 GEN_VR_LDX(lvxl
, 0x07, 0x0B);
6367 GEN_VR_LVE(bx
, 0x07, 0x00);
6368 GEN_VR_LVE(hx
, 0x07, 0x01);
6369 GEN_VR_LVE(wx
, 0x07, 0x02);
6371 GEN_VR_STX(svx
, 0x07, 0x07);
6372 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
6373 GEN_VR_STX(svxl
, 0x07, 0x0F);
6375 GEN_VR_STVE(bx
, 0x07, 0x04);
6376 GEN_VR_STVE(hx
, 0x07, 0x05);
6377 GEN_VR_STVE(wx
, 0x07, 0x06);
6379 static void gen_lvsl(DisasContext
*ctx
)
6383 if (unlikely(!ctx
->altivec_enabled
)) {
6384 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6387 EA
= tcg_temp_new();
6388 gen_addr_reg_index(ctx
, EA
);
6389 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6390 gen_helper_lvsl(rd
, EA
);
6392 tcg_temp_free_ptr(rd
);
6395 static void gen_lvsr(DisasContext
*ctx
)
6399 if (unlikely(!ctx
->altivec_enabled
)) {
6400 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6403 EA
= tcg_temp_new();
6404 gen_addr_reg_index(ctx
, EA
);
6405 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6406 gen_helper_lvsr(rd
, EA
);
6408 tcg_temp_free_ptr(rd
);
6411 static void gen_mfvscr(DisasContext
*ctx
)
6414 if (unlikely(!ctx
->altivec_enabled
)) {
6415 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6418 tcg_gen_movi_i64(cpu_avrh
[rD(ctx
->opcode
)], 0);
6419 t
= tcg_temp_new_i32();
6420 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUPPCState
, vscr
));
6421 tcg_gen_extu_i32_i64(cpu_avrl
[rD(ctx
->opcode
)], t
);
6422 tcg_temp_free_i32(t
);
6425 static void gen_mtvscr(DisasContext
*ctx
)
6428 if (unlikely(!ctx
->altivec_enabled
)) {
6429 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6432 p
= gen_avr_ptr(rD(ctx
->opcode
));
6433 gen_helper_mtvscr(cpu_env
, p
);
6434 tcg_temp_free_ptr(p
);
6437 /* Logical operations */
6438 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
6439 static void glue(gen_, name)(DisasContext *ctx) \
6441 if (unlikely(!ctx->altivec_enabled)) { \
6442 gen_exception(ctx, POWERPC_EXCP_VPU); \
6445 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6446 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6449 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16);
6450 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17);
6451 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18);
6452 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19);
6453 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20);
6455 #define GEN_VXFORM(name, opc2, opc3) \
6456 static void glue(gen_, name)(DisasContext *ctx) \
6458 TCGv_ptr ra, rb, rd; \
6459 if (unlikely(!ctx->altivec_enabled)) { \
6460 gen_exception(ctx, POWERPC_EXCP_VPU); \
6463 ra = gen_avr_ptr(rA(ctx->opcode)); \
6464 rb = gen_avr_ptr(rB(ctx->opcode)); \
6465 rd = gen_avr_ptr(rD(ctx->opcode)); \
6466 gen_helper_##name (rd, ra, rb); \
6467 tcg_temp_free_ptr(ra); \
6468 tcg_temp_free_ptr(rb); \
6469 tcg_temp_free_ptr(rd); \
6472 #define GEN_VXFORM_ENV(name, opc2, opc3) \
6473 static void glue(gen_, name)(DisasContext *ctx) \
6475 TCGv_ptr ra, rb, rd; \
6476 if (unlikely(!ctx->altivec_enabled)) { \
6477 gen_exception(ctx, POWERPC_EXCP_VPU); \
6480 ra = gen_avr_ptr(rA(ctx->opcode)); \
6481 rb = gen_avr_ptr(rB(ctx->opcode)); \
6482 rd = gen_avr_ptr(rD(ctx->opcode)); \
6483 gen_helper_##name(cpu_env, rd, ra, rb); \
6484 tcg_temp_free_ptr(ra); \
6485 tcg_temp_free_ptr(rb); \
6486 tcg_temp_free_ptr(rd); \
6489 GEN_VXFORM(vaddubm
, 0, 0);
6490 GEN_VXFORM(vadduhm
, 0, 1);
6491 GEN_VXFORM(vadduwm
, 0, 2);
6492 GEN_VXFORM(vsububm
, 0, 16);
6493 GEN_VXFORM(vsubuhm
, 0, 17);
6494 GEN_VXFORM(vsubuwm
, 0, 18);
6495 GEN_VXFORM(vmaxub
, 1, 0);
6496 GEN_VXFORM(vmaxuh
, 1, 1);
6497 GEN_VXFORM(vmaxuw
, 1, 2);
6498 GEN_VXFORM(vmaxsb
, 1, 4);
6499 GEN_VXFORM(vmaxsh
, 1, 5);
6500 GEN_VXFORM(vmaxsw
, 1, 6);
6501 GEN_VXFORM(vminub
, 1, 8);
6502 GEN_VXFORM(vminuh
, 1, 9);
6503 GEN_VXFORM(vminuw
, 1, 10);
6504 GEN_VXFORM(vminsb
, 1, 12);
6505 GEN_VXFORM(vminsh
, 1, 13);
6506 GEN_VXFORM(vminsw
, 1, 14);
6507 GEN_VXFORM(vavgub
, 1, 16);
6508 GEN_VXFORM(vavguh
, 1, 17);
6509 GEN_VXFORM(vavguw
, 1, 18);
6510 GEN_VXFORM(vavgsb
, 1, 20);
6511 GEN_VXFORM(vavgsh
, 1, 21);
6512 GEN_VXFORM(vavgsw
, 1, 22);
6513 GEN_VXFORM(vmrghb
, 6, 0);
6514 GEN_VXFORM(vmrghh
, 6, 1);
6515 GEN_VXFORM(vmrghw
, 6, 2);
6516 GEN_VXFORM(vmrglb
, 6, 4);
6517 GEN_VXFORM(vmrglh
, 6, 5);
6518 GEN_VXFORM(vmrglw
, 6, 6);
6519 GEN_VXFORM(vmuloub
, 4, 0);
6520 GEN_VXFORM(vmulouh
, 4, 1);
6521 GEN_VXFORM(vmulosb
, 4, 4);
6522 GEN_VXFORM(vmulosh
, 4, 5);
6523 GEN_VXFORM(vmuleub
, 4, 8);
6524 GEN_VXFORM(vmuleuh
, 4, 9);
6525 GEN_VXFORM(vmulesb
, 4, 12);
6526 GEN_VXFORM(vmulesh
, 4, 13);
6527 GEN_VXFORM(vslb
, 2, 4);
6528 GEN_VXFORM(vslh
, 2, 5);
6529 GEN_VXFORM(vslw
, 2, 6);
6530 GEN_VXFORM(vsrb
, 2, 8);
6531 GEN_VXFORM(vsrh
, 2, 9);
6532 GEN_VXFORM(vsrw
, 2, 10);
6533 GEN_VXFORM(vsrab
, 2, 12);
6534 GEN_VXFORM(vsrah
, 2, 13);
6535 GEN_VXFORM(vsraw
, 2, 14);
6536 GEN_VXFORM(vslo
, 6, 16);
6537 GEN_VXFORM(vsro
, 6, 17);
6538 GEN_VXFORM(vaddcuw
, 0, 6);
6539 GEN_VXFORM(vsubcuw
, 0, 22);
6540 GEN_VXFORM_ENV(vaddubs
, 0, 8);
6541 GEN_VXFORM_ENV(vadduhs
, 0, 9);
6542 GEN_VXFORM_ENV(vadduws
, 0, 10);
6543 GEN_VXFORM_ENV(vaddsbs
, 0, 12);
6544 GEN_VXFORM_ENV(vaddshs
, 0, 13);
6545 GEN_VXFORM_ENV(vaddsws
, 0, 14);
6546 GEN_VXFORM_ENV(vsububs
, 0, 24);
6547 GEN_VXFORM_ENV(vsubuhs
, 0, 25);
6548 GEN_VXFORM_ENV(vsubuws
, 0, 26);
6549 GEN_VXFORM_ENV(vsubsbs
, 0, 28);
6550 GEN_VXFORM_ENV(vsubshs
, 0, 29);
6551 GEN_VXFORM_ENV(vsubsws
, 0, 30);
6552 GEN_VXFORM(vrlb
, 2, 0);
6553 GEN_VXFORM(vrlh
, 2, 1);
6554 GEN_VXFORM(vrlw
, 2, 2);
6555 GEN_VXFORM(vsl
, 2, 7);
6556 GEN_VXFORM(vsr
, 2, 11);
6557 GEN_VXFORM_ENV(vpkuhum
, 7, 0);
6558 GEN_VXFORM_ENV(vpkuwum
, 7, 1);
6559 GEN_VXFORM_ENV(vpkuhus
, 7, 2);
6560 GEN_VXFORM_ENV(vpkuwus
, 7, 3);
6561 GEN_VXFORM_ENV(vpkshus
, 7, 4);
6562 GEN_VXFORM_ENV(vpkswus
, 7, 5);
6563 GEN_VXFORM_ENV(vpkshss
, 7, 6);
6564 GEN_VXFORM_ENV(vpkswss
, 7, 7);
6565 GEN_VXFORM(vpkpx
, 7, 12);
6566 GEN_VXFORM_ENV(vsum4ubs
, 4, 24);
6567 GEN_VXFORM_ENV(vsum4sbs
, 4, 28);
6568 GEN_VXFORM_ENV(vsum4shs
, 4, 25);
6569 GEN_VXFORM_ENV(vsum2sws
, 4, 26);
6570 GEN_VXFORM_ENV(vsumsws
, 4, 30);
6571 GEN_VXFORM_ENV(vaddfp
, 5, 0);
6572 GEN_VXFORM_ENV(vsubfp
, 5, 1);
6573 GEN_VXFORM_ENV(vmaxfp
, 5, 16);
6574 GEN_VXFORM_ENV(vminfp
, 5, 17);
6576 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
6577 static void glue(gen_, name)(DisasContext *ctx) \
6579 TCGv_ptr ra, rb, rd; \
6580 if (unlikely(!ctx->altivec_enabled)) { \
6581 gen_exception(ctx, POWERPC_EXCP_VPU); \
6584 ra = gen_avr_ptr(rA(ctx->opcode)); \
6585 rb = gen_avr_ptr(rB(ctx->opcode)); \
6586 rd = gen_avr_ptr(rD(ctx->opcode)); \
6587 gen_helper_##opname(cpu_env, rd, ra, rb); \
6588 tcg_temp_free_ptr(ra); \
6589 tcg_temp_free_ptr(rb); \
6590 tcg_temp_free_ptr(rd); \
6593 #define GEN_VXRFORM(name, opc2, opc3) \
6594 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
6595 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
6597 GEN_VXRFORM(vcmpequb
, 3, 0)
6598 GEN_VXRFORM(vcmpequh
, 3, 1)
6599 GEN_VXRFORM(vcmpequw
, 3, 2)
6600 GEN_VXRFORM(vcmpgtsb
, 3, 12)
6601 GEN_VXRFORM(vcmpgtsh
, 3, 13)
6602 GEN_VXRFORM(vcmpgtsw
, 3, 14)
6603 GEN_VXRFORM(vcmpgtub
, 3, 8)
6604 GEN_VXRFORM(vcmpgtuh
, 3, 9)
6605 GEN_VXRFORM(vcmpgtuw
, 3, 10)
6606 GEN_VXRFORM(vcmpeqfp
, 3, 3)
6607 GEN_VXRFORM(vcmpgefp
, 3, 7)
6608 GEN_VXRFORM(vcmpgtfp
, 3, 11)
6609 GEN_VXRFORM(vcmpbfp
, 3, 15)
6611 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
6612 static void glue(gen_, name)(DisasContext *ctx) \
6616 if (unlikely(!ctx->altivec_enabled)) { \
6617 gen_exception(ctx, POWERPC_EXCP_VPU); \
6620 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6621 rd = gen_avr_ptr(rD(ctx->opcode)); \
6622 gen_helper_##name (rd, simm); \
6623 tcg_temp_free_i32(simm); \
6624 tcg_temp_free_ptr(rd); \
6627 GEN_VXFORM_SIMM(vspltisb
, 6, 12);
6628 GEN_VXFORM_SIMM(vspltish
, 6, 13);
6629 GEN_VXFORM_SIMM(vspltisw
, 6, 14);
6631 #define GEN_VXFORM_NOA(name, opc2, opc3) \
6632 static void glue(gen_, name)(DisasContext *ctx) \
6635 if (unlikely(!ctx->altivec_enabled)) { \
6636 gen_exception(ctx, POWERPC_EXCP_VPU); \
6639 rb = gen_avr_ptr(rB(ctx->opcode)); \
6640 rd = gen_avr_ptr(rD(ctx->opcode)); \
6641 gen_helper_##name (rd, rb); \
6642 tcg_temp_free_ptr(rb); \
6643 tcg_temp_free_ptr(rd); \
6646 #define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
6647 static void glue(gen_, name)(DisasContext *ctx) \
6651 if (unlikely(!ctx->altivec_enabled)) { \
6652 gen_exception(ctx, POWERPC_EXCP_VPU); \
6655 rb = gen_avr_ptr(rB(ctx->opcode)); \
6656 rd = gen_avr_ptr(rD(ctx->opcode)); \
6657 gen_helper_##name(cpu_env, rd, rb); \
6658 tcg_temp_free_ptr(rb); \
6659 tcg_temp_free_ptr(rd); \
6662 GEN_VXFORM_NOA(vupkhsb
, 7, 8);
6663 GEN_VXFORM_NOA(vupkhsh
, 7, 9);
6664 GEN_VXFORM_NOA(vupklsb
, 7, 10);
6665 GEN_VXFORM_NOA(vupklsh
, 7, 11);
6666 GEN_VXFORM_NOA(vupkhpx
, 7, 13);
6667 GEN_VXFORM_NOA(vupklpx
, 7, 15);
6668 GEN_VXFORM_NOA_ENV(vrefp
, 5, 4);
6669 GEN_VXFORM_NOA_ENV(vrsqrtefp
, 5, 5);
6670 GEN_VXFORM_NOA_ENV(vexptefp
, 5, 6);
6671 GEN_VXFORM_NOA_ENV(vlogefp
, 5, 7);
6672 GEN_VXFORM_NOA_ENV(vrfim
, 5, 8);
6673 GEN_VXFORM_NOA_ENV(vrfin
, 5, 9);
6674 GEN_VXFORM_NOA_ENV(vrfip
, 5, 10);
6675 GEN_VXFORM_NOA_ENV(vrfiz
, 5, 11);
6677 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
6678 static void glue(gen_, name)(DisasContext *ctx) \
6682 if (unlikely(!ctx->altivec_enabled)) { \
6683 gen_exception(ctx, POWERPC_EXCP_VPU); \
6686 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6687 rd = gen_avr_ptr(rD(ctx->opcode)); \
6688 gen_helper_##name (rd, simm); \
6689 tcg_temp_free_i32(simm); \
6690 tcg_temp_free_ptr(rd); \
6693 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
6694 static void glue(gen_, name)(DisasContext *ctx) \
6698 if (unlikely(!ctx->altivec_enabled)) { \
6699 gen_exception(ctx, POWERPC_EXCP_VPU); \
6702 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
6703 rb = gen_avr_ptr(rB(ctx->opcode)); \
6704 rd = gen_avr_ptr(rD(ctx->opcode)); \
6705 gen_helper_##name (rd, rb, uimm); \
6706 tcg_temp_free_i32(uimm); \
6707 tcg_temp_free_ptr(rb); \
6708 tcg_temp_free_ptr(rd); \
6711 #define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
6712 static void glue(gen_, name)(DisasContext *ctx) \
6717 if (unlikely(!ctx->altivec_enabled)) { \
6718 gen_exception(ctx, POWERPC_EXCP_VPU); \
6721 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
6722 rb = gen_avr_ptr(rB(ctx->opcode)); \
6723 rd = gen_avr_ptr(rD(ctx->opcode)); \
6724 gen_helper_##name(cpu_env, rd, rb, uimm); \
6725 tcg_temp_free_i32(uimm); \
6726 tcg_temp_free_ptr(rb); \
6727 tcg_temp_free_ptr(rd); \
6730 GEN_VXFORM_UIMM(vspltb
, 6, 8);
6731 GEN_VXFORM_UIMM(vsplth
, 6, 9);
6732 GEN_VXFORM_UIMM(vspltw
, 6, 10);
6733 GEN_VXFORM_UIMM_ENV(vcfux
, 5, 12);
6734 GEN_VXFORM_UIMM_ENV(vcfsx
, 5, 13);
6735 GEN_VXFORM_UIMM_ENV(vctuxs
, 5, 14);
6736 GEN_VXFORM_UIMM_ENV(vctsxs
, 5, 15);
6738 static void gen_vsldoi(DisasContext
*ctx
)
6740 TCGv_ptr ra
, rb
, rd
;
6742 if (unlikely(!ctx
->altivec_enabled
)) {
6743 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6746 ra
= gen_avr_ptr(rA(ctx
->opcode
));
6747 rb
= gen_avr_ptr(rB(ctx
->opcode
));
6748 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6749 sh
= tcg_const_i32(VSH(ctx
->opcode
));
6750 gen_helper_vsldoi (rd
, ra
, rb
, sh
);
6751 tcg_temp_free_ptr(ra
);
6752 tcg_temp_free_ptr(rb
);
6753 tcg_temp_free_ptr(rd
);
6754 tcg_temp_free_i32(sh
);
6757 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
6758 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
6760 TCGv_ptr ra, rb, rc, rd; \
6761 if (unlikely(!ctx->altivec_enabled)) { \
6762 gen_exception(ctx, POWERPC_EXCP_VPU); \
6765 ra = gen_avr_ptr(rA(ctx->opcode)); \
6766 rb = gen_avr_ptr(rB(ctx->opcode)); \
6767 rc = gen_avr_ptr(rC(ctx->opcode)); \
6768 rd = gen_avr_ptr(rD(ctx->opcode)); \
6769 if (Rc(ctx->opcode)) { \
6770 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
6772 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
6774 tcg_temp_free_ptr(ra); \
6775 tcg_temp_free_ptr(rb); \
6776 tcg_temp_free_ptr(rc); \
6777 tcg_temp_free_ptr(rd); \
6780 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16)
6782 static void gen_vmladduhm(DisasContext
*ctx
)
6784 TCGv_ptr ra
, rb
, rc
, rd
;
6785 if (unlikely(!ctx
->altivec_enabled
)) {
6786 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6789 ra
= gen_avr_ptr(rA(ctx
->opcode
));
6790 rb
= gen_avr_ptr(rB(ctx
->opcode
));
6791 rc
= gen_avr_ptr(rC(ctx
->opcode
));
6792 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6793 gen_helper_vmladduhm(rd
, ra
, rb
, rc
);
6794 tcg_temp_free_ptr(ra
);
6795 tcg_temp_free_ptr(rb
);
6796 tcg_temp_free_ptr(rc
);
6797 tcg_temp_free_ptr(rd
);
6800 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18)
6801 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19)
6802 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20)
6803 GEN_VAFORM_PAIRED(vsel
, vperm
, 21)
6804 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23)
6806 /*** SPE extension ***/
6807 /* Register moves */
6810 static inline void gen_evmra(DisasContext
*ctx
)
6813 if (unlikely(!ctx
->spe_enabled
)) {
6814 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
6818 #if defined(TARGET_PPC64)
6820 tcg_gen_mov_i64(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6823 tcg_gen_st_i64(cpu_gpr
[rA(ctx
->opcode
)],
6825 offsetof(CPUPPCState
, spe_acc
));
6827 TCGv_i64 tmp
= tcg_temp_new_i64();
6829 /* tmp := rA_lo + rA_hi << 32 */
6830 tcg_gen_concat_i32_i64(tmp
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6832 /* spe_acc := tmp */
6833 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
6834 tcg_temp_free_i64(tmp
);
6837 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6838 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6842 static inline void gen_load_gpr64(TCGv_i64 t
, int reg
)
6844 #if defined(TARGET_PPC64)
6845 tcg_gen_mov_i64(t
, cpu_gpr
[reg
]);
6847 tcg_gen_concat_i32_i64(t
, cpu_gpr
[reg
], cpu_gprh
[reg
]);
6851 static inline void gen_store_gpr64(int reg
, TCGv_i64 t
)
6853 #if defined(TARGET_PPC64)
6854 tcg_gen_mov_i64(cpu_gpr
[reg
], t
);
6856 TCGv_i64 tmp
= tcg_temp_new_i64();
6857 tcg_gen_trunc_i64_i32(cpu_gpr
[reg
], t
);
6858 tcg_gen_shri_i64(tmp
, t
, 32);
6859 tcg_gen_trunc_i64_i32(cpu_gprh
[reg
], tmp
);
6860 tcg_temp_free_i64(tmp
);
6864 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
6865 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
6867 if (Rc(ctx->opcode)) \
6873 /* Handler for undefined SPE opcodes */
6874 static inline void gen_speundef(DisasContext
*ctx
)
6876 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6880 #if defined(TARGET_PPC64)
6881 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
6882 static inline void gen_##name(DisasContext *ctx) \
6884 if (unlikely(!ctx->spe_enabled)) { \
6885 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6888 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6889 cpu_gpr[rB(ctx->opcode)]); \
6892 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
6893 static inline void gen_##name(DisasContext *ctx) \
6895 if (unlikely(!ctx->spe_enabled)) { \
6896 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6899 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6900 cpu_gpr[rB(ctx->opcode)]); \
6901 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6902 cpu_gprh[rB(ctx->opcode)]); \
6906 GEN_SPEOP_LOGIC2(evand
, tcg_gen_and_tl
);
6907 GEN_SPEOP_LOGIC2(evandc
, tcg_gen_andc_tl
);
6908 GEN_SPEOP_LOGIC2(evxor
, tcg_gen_xor_tl
);
6909 GEN_SPEOP_LOGIC2(evor
, tcg_gen_or_tl
);
6910 GEN_SPEOP_LOGIC2(evnor
, tcg_gen_nor_tl
);
6911 GEN_SPEOP_LOGIC2(eveqv
, tcg_gen_eqv_tl
);
6912 GEN_SPEOP_LOGIC2(evorc
, tcg_gen_orc_tl
);
6913 GEN_SPEOP_LOGIC2(evnand
, tcg_gen_nand_tl
);
6915 /* SPE logic immediate */
6916 #if defined(TARGET_PPC64)
6917 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
6918 static inline void gen_##name(DisasContext *ctx) \
6920 if (unlikely(!ctx->spe_enabled)) { \
6921 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6924 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6925 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6926 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6927 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6928 tcg_opi(t0, t0, rB(ctx->opcode)); \
6929 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6930 tcg_gen_trunc_i64_i32(t1, t2); \
6931 tcg_temp_free_i64(t2); \
6932 tcg_opi(t1, t1, rB(ctx->opcode)); \
6933 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6934 tcg_temp_free_i32(t0); \
6935 tcg_temp_free_i32(t1); \
6938 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
6939 static inline void gen_##name(DisasContext *ctx) \
6941 if (unlikely(!ctx->spe_enabled)) { \
6942 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6945 tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6947 tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6951 GEN_SPEOP_TCG_LOGIC_IMM2(evslwi
, tcg_gen_shli_i32
);
6952 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu
, tcg_gen_shri_i32
);
6953 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis
, tcg_gen_sari_i32
);
6954 GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi
, tcg_gen_rotli_i32
);
6956 /* SPE arithmetic */
6957 #if defined(TARGET_PPC64)
6958 #define GEN_SPEOP_ARITH1(name, tcg_op) \
6959 static inline void gen_##name(DisasContext *ctx) \
6961 if (unlikely(!ctx->spe_enabled)) { \
6962 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6965 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6966 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6967 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6968 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6970 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6971 tcg_gen_trunc_i64_i32(t1, t2); \
6972 tcg_temp_free_i64(t2); \
6974 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6975 tcg_temp_free_i32(t0); \
6976 tcg_temp_free_i32(t1); \
6979 #define GEN_SPEOP_ARITH1(name, tcg_op) \
6980 static inline void gen_##name(DisasContext *ctx) \
6982 if (unlikely(!ctx->spe_enabled)) { \
6983 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6986 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
6987 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
6991 static inline void gen_op_evabs(TCGv_i32 ret
, TCGv_i32 arg1
)
6993 int l1
= gen_new_label();
6994 int l2
= gen_new_label();
6996 tcg_gen_brcondi_i32(TCG_COND_GE
, arg1
, 0, l1
);
6997 tcg_gen_neg_i32(ret
, arg1
);
7000 tcg_gen_mov_i32(ret
, arg1
);
7003 GEN_SPEOP_ARITH1(evabs
, gen_op_evabs
);
7004 GEN_SPEOP_ARITH1(evneg
, tcg_gen_neg_i32
);
7005 GEN_SPEOP_ARITH1(evextsb
, tcg_gen_ext8s_i32
);
7006 GEN_SPEOP_ARITH1(evextsh
, tcg_gen_ext16s_i32
);
7007 static inline void gen_op_evrndw(TCGv_i32 ret
, TCGv_i32 arg1
)
7009 tcg_gen_addi_i32(ret
, arg1
, 0x8000);
7010 tcg_gen_ext16u_i32(ret
, ret
);
7012 GEN_SPEOP_ARITH1(evrndw
, gen_op_evrndw
);
7013 GEN_SPEOP_ARITH1(evcntlsw
, gen_helper_cntlsw32
);
7014 GEN_SPEOP_ARITH1(evcntlzw
, gen_helper_cntlzw32
);
7016 #if defined(TARGET_PPC64)
7017 #define GEN_SPEOP_ARITH2(name, tcg_op) \
7018 static inline void gen_##name(DisasContext *ctx) \
7020 if (unlikely(!ctx->spe_enabled)) { \
7021 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7024 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7025 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7026 TCGv_i32 t2 = tcg_temp_local_new_i32(); \
7027 TCGv_i64 t3 = tcg_temp_local_new_i64(); \
7028 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7029 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
7030 tcg_op(t0, t0, t2); \
7031 tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
7032 tcg_gen_trunc_i64_i32(t1, t3); \
7033 tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
7034 tcg_gen_trunc_i64_i32(t2, t3); \
7035 tcg_temp_free_i64(t3); \
7036 tcg_op(t1, t1, t2); \
7037 tcg_temp_free_i32(t2); \
7038 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7039 tcg_temp_free_i32(t0); \
7040 tcg_temp_free_i32(t1); \
7043 #define GEN_SPEOP_ARITH2(name, tcg_op) \
7044 static inline void gen_##name(DisasContext *ctx) \
7046 if (unlikely(!ctx->spe_enabled)) { \
7047 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7050 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7051 cpu_gpr[rB(ctx->opcode)]); \
7052 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7053 cpu_gprh[rB(ctx->opcode)]); \
7057 static inline void gen_op_evsrwu(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7062 l1
= gen_new_label();
7063 l2
= gen_new_label();
7064 t0
= tcg_temp_local_new_i32();
7065 /* No error here: 6 bits are used */
7066 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
7067 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
7068 tcg_gen_shr_i32(ret
, arg1
, t0
);
7071 tcg_gen_movi_i32(ret
, 0);
7073 tcg_temp_free_i32(t0
);
7075 GEN_SPEOP_ARITH2(evsrwu
, gen_op_evsrwu
);
7076 static inline void gen_op_evsrws(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7081 l1
= gen_new_label();
7082 l2
= gen_new_label();
7083 t0
= tcg_temp_local_new_i32();
7084 /* No error here: 6 bits are used */
7085 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
7086 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
7087 tcg_gen_sar_i32(ret
, arg1
, t0
);
7090 tcg_gen_movi_i32(ret
, 0);
7092 tcg_temp_free_i32(t0
);
7094 GEN_SPEOP_ARITH2(evsrws
, gen_op_evsrws
);
7095 static inline void gen_op_evslw(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7100 l1
= gen_new_label();
7101 l2
= gen_new_label();
7102 t0
= tcg_temp_local_new_i32();
7103 /* No error here: 6 bits are used */
7104 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
7105 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
7106 tcg_gen_shl_i32(ret
, arg1
, t0
);
7109 tcg_gen_movi_i32(ret
, 0);
7111 tcg_temp_free_i32(t0
);
7113 GEN_SPEOP_ARITH2(evslw
, gen_op_evslw
);
7114 static inline void gen_op_evrlw(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7116 TCGv_i32 t0
= tcg_temp_new_i32();
7117 tcg_gen_andi_i32(t0
, arg2
, 0x1F);
7118 tcg_gen_rotl_i32(ret
, arg1
, t0
);
7119 tcg_temp_free_i32(t0
);
7121 GEN_SPEOP_ARITH2(evrlw
, gen_op_evrlw
);
7122 static inline void gen_evmergehi(DisasContext
*ctx
)
7124 if (unlikely(!ctx
->spe_enabled
)) {
7125 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7128 #if defined(TARGET_PPC64)
7129 TCGv t0
= tcg_temp_new();
7130 TCGv t1
= tcg_temp_new();
7131 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
7132 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
7133 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7137 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7138 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7141 GEN_SPEOP_ARITH2(evaddw
, tcg_gen_add_i32
);
7142 static inline void gen_op_evsubf(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7144 tcg_gen_sub_i32(ret
, arg2
, arg1
);
7146 GEN_SPEOP_ARITH2(evsubfw
, gen_op_evsubf
);
7148 /* SPE arithmetic immediate */
7149 #if defined(TARGET_PPC64)
7150 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
7151 static inline void gen_##name(DisasContext *ctx) \
7153 if (unlikely(!ctx->spe_enabled)) { \
7154 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7157 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7158 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7159 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7160 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
7161 tcg_op(t0, t0, rA(ctx->opcode)); \
7162 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
7163 tcg_gen_trunc_i64_i32(t1, t2); \
7164 tcg_temp_free_i64(t2); \
7165 tcg_op(t1, t1, rA(ctx->opcode)); \
7166 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7167 tcg_temp_free_i32(t0); \
7168 tcg_temp_free_i32(t1); \
7171 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
7172 static inline void gen_##name(DisasContext *ctx) \
7174 if (unlikely(!ctx->spe_enabled)) { \
7175 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7178 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
7180 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
7184 GEN_SPEOP_ARITH_IMM2(evaddiw
, tcg_gen_addi_i32
);
7185 GEN_SPEOP_ARITH_IMM2(evsubifw
, tcg_gen_subi_i32
);
7187 /* SPE comparison */
7188 #if defined(TARGET_PPC64)
7189 #define GEN_SPEOP_COMP(name, tcg_cond) \
7190 static inline void gen_##name(DisasContext *ctx) \
7192 if (unlikely(!ctx->spe_enabled)) { \
7193 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7196 int l1 = gen_new_label(); \
7197 int l2 = gen_new_label(); \
7198 int l3 = gen_new_label(); \
7199 int l4 = gen_new_label(); \
7200 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7201 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7202 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7203 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7204 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
7205 tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
7206 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
7208 gen_set_label(l1); \
7209 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
7210 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
7211 gen_set_label(l2); \
7212 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7213 tcg_gen_trunc_i64_i32(t0, t2); \
7214 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
7215 tcg_gen_trunc_i64_i32(t1, t2); \
7216 tcg_temp_free_i64(t2); \
7217 tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
7218 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7219 ~(CRF_CH | CRF_CH_AND_CL)); \
7221 gen_set_label(l3); \
7222 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7223 CRF_CH | CRF_CH_OR_CL); \
7224 gen_set_label(l4); \
7225 tcg_temp_free_i32(t0); \
7226 tcg_temp_free_i32(t1); \
7229 #define GEN_SPEOP_COMP(name, tcg_cond) \
7230 static inline void gen_##name(DisasContext *ctx) \
7232 if (unlikely(!ctx->spe_enabled)) { \
7233 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7236 int l1 = gen_new_label(); \
7237 int l2 = gen_new_label(); \
7238 int l3 = gen_new_label(); \
7239 int l4 = gen_new_label(); \
7241 tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
7242 cpu_gpr[rB(ctx->opcode)], l1); \
7243 tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
7245 gen_set_label(l1); \
7246 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
7247 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
7248 gen_set_label(l2); \
7249 tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
7250 cpu_gprh[rB(ctx->opcode)], l3); \
7251 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7252 ~(CRF_CH | CRF_CH_AND_CL)); \
7254 gen_set_label(l3); \
7255 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7256 CRF_CH | CRF_CH_OR_CL); \
7257 gen_set_label(l4); \
7260 GEN_SPEOP_COMP(evcmpgtu
, TCG_COND_GTU
);
7261 GEN_SPEOP_COMP(evcmpgts
, TCG_COND_GT
);
7262 GEN_SPEOP_COMP(evcmpltu
, TCG_COND_LTU
);
7263 GEN_SPEOP_COMP(evcmplts
, TCG_COND_LT
);
7264 GEN_SPEOP_COMP(evcmpeq
, TCG_COND_EQ
);
7267 static inline void gen_brinc(DisasContext
*ctx
)
7269 /* Note: brinc is usable even if SPE is disabled */
7270 gen_helper_brinc(cpu_gpr
[rD(ctx
->opcode
)],
7271 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7273 static inline void gen_evmergelo(DisasContext
*ctx
)
7275 if (unlikely(!ctx
->spe_enabled
)) {
7276 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7279 #if defined(TARGET_PPC64)
7280 TCGv t0
= tcg_temp_new();
7281 TCGv t1
= tcg_temp_new();
7282 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
7283 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
7284 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7288 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7289 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7292 static inline void gen_evmergehilo(DisasContext
*ctx
)
7294 if (unlikely(!ctx
->spe_enabled
)) {
7295 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7298 #if defined(TARGET_PPC64)
7299 TCGv t0
= tcg_temp_new();
7300 TCGv t1
= tcg_temp_new();
7301 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
7302 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
7303 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7307 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7308 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7311 static inline void gen_evmergelohi(DisasContext
*ctx
)
7313 if (unlikely(!ctx
->spe_enabled
)) {
7314 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7317 #if defined(TARGET_PPC64)
7318 TCGv t0
= tcg_temp_new();
7319 TCGv t1
= tcg_temp_new();
7320 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
7321 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
7322 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7326 if (rD(ctx
->opcode
) == rA(ctx
->opcode
)) {
7327 TCGv_i32 tmp
= tcg_temp_new_i32();
7328 tcg_gen_mov_i32(tmp
, cpu_gpr
[rA(ctx
->opcode
)]);
7329 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7330 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], tmp
);
7331 tcg_temp_free_i32(tmp
);
7333 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7334 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7338 static inline void gen_evsplati(DisasContext
*ctx
)
7340 uint64_t imm
= ((int32_t)(rA(ctx
->opcode
) << 27)) >> 27;
7342 #if defined(TARGET_PPC64)
7343 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
7345 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
7346 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
7349 static inline void gen_evsplatfi(DisasContext
*ctx
)
7351 uint64_t imm
= rA(ctx
->opcode
) << 27;
7353 #if defined(TARGET_PPC64)
7354 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
7356 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
7357 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
7361 static inline void gen_evsel(DisasContext
*ctx
)
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 #if defined(TARGET_PPC64)
7369 TCGv t1
= tcg_temp_local_new();
7370 TCGv t2
= tcg_temp_local_new();
7372 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 3);
7373 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
7374 #if defined(TARGET_PPC64)
7375 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
7377 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7381 #if defined(TARGET_PPC64)
7382 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
7384 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7387 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 2);
7388 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l3
);
7389 #if defined(TARGET_PPC64)
7390 tcg_gen_ext32u_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)]);
7392 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7396 #if defined(TARGET_PPC64)
7397 tcg_gen_ext32u_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)]);
7399 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7402 tcg_temp_free_i32(t0
);
7403 #if defined(TARGET_PPC64)
7404 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
, t2
);
7410 static void gen_evsel0(DisasContext
*ctx
)
7415 static void gen_evsel1(DisasContext
*ctx
)
7420 static void gen_evsel2(DisasContext
*ctx
)
7425 static void gen_evsel3(DisasContext
*ctx
)
7432 static inline void gen_evmwumi(DisasContext
*ctx
)
7436 if (unlikely(!ctx
->spe_enabled
)) {
7437 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7441 t0
= tcg_temp_new_i64();
7442 t1
= tcg_temp_new_i64();
7444 /* t0 := rA; t1 := rB */
7445 #if defined(TARGET_PPC64)
7446 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7447 tcg_gen_ext32u_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7449 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7450 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7453 tcg_gen_mul_i64(t0
, t0
, t1
); /* t0 := rA * rB */
7455 gen_store_gpr64(rD(ctx
->opcode
), t0
); /* rD := t0 */
7457 tcg_temp_free_i64(t0
);
7458 tcg_temp_free_i64(t1
);
7461 static inline void gen_evmwumia(DisasContext
*ctx
)
7465 if (unlikely(!ctx
->spe_enabled
)) {
7466 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7470 gen_evmwumi(ctx
); /* rD := rA * rB */
7472 tmp
= tcg_temp_new_i64();
7475 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7476 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7477 tcg_temp_free_i64(tmp
);
7480 static inline void gen_evmwumiaa(DisasContext
*ctx
)
7485 if (unlikely(!ctx
->spe_enabled
)) {
7486 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7490 gen_evmwumi(ctx
); /* rD := rA * rB */
7492 acc
= tcg_temp_new_i64();
7493 tmp
= tcg_temp_new_i64();
7496 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7499 tcg_gen_ld_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7501 /* acc := tmp + acc */
7502 tcg_gen_add_i64(acc
, acc
, tmp
);
7505 tcg_gen_st_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7508 gen_store_gpr64(rD(ctx
->opcode
), acc
);
7510 tcg_temp_free_i64(acc
);
7511 tcg_temp_free_i64(tmp
);
7514 static inline void gen_evmwsmi(DisasContext
*ctx
)
7518 if (unlikely(!ctx
->spe_enabled
)) {
7519 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7523 t0
= tcg_temp_new_i64();
7524 t1
= tcg_temp_new_i64();
7526 /* t0 := rA; t1 := rB */
7527 #if defined(TARGET_PPC64)
7528 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7529 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7531 tcg_gen_ext_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7532 tcg_gen_ext_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7535 tcg_gen_mul_i64(t0
, t0
, t1
); /* t0 := rA * rB */
7537 gen_store_gpr64(rD(ctx
->opcode
), t0
); /* rD := t0 */
7539 tcg_temp_free_i64(t0
);
7540 tcg_temp_free_i64(t1
);
7543 static inline void gen_evmwsmia(DisasContext
*ctx
)
7547 gen_evmwsmi(ctx
); /* rD := rA * rB */
7549 tmp
= tcg_temp_new_i64();
7552 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7553 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7555 tcg_temp_free_i64(tmp
);
7558 static inline void gen_evmwsmiaa(DisasContext
*ctx
)
7560 TCGv_i64 acc
= tcg_temp_new_i64();
7561 TCGv_i64 tmp
= tcg_temp_new_i64();
7563 gen_evmwsmi(ctx
); /* rD := rA * rB */
7565 acc
= tcg_temp_new_i64();
7566 tmp
= tcg_temp_new_i64();
7569 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7572 tcg_gen_ld_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7574 /* acc := tmp + acc */
7575 tcg_gen_add_i64(acc
, acc
, tmp
);
7578 tcg_gen_st_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7581 gen_store_gpr64(rD(ctx
->opcode
), acc
);
7583 tcg_temp_free_i64(acc
);
7584 tcg_temp_free_i64(tmp
);
7587 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7588 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7589 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7590 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7591 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
7592 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
7593 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
7594 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE
); //
7595 GEN_SPE(evmra
, speundef
, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE
);
7596 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
); ////
7597 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7598 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7599 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7600 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
7601 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
7602 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
7603 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
); ////
7604 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7605 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7606 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE
);
7607 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7608 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7609 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE
); //
7610 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE
);
7611 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7612 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7613 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE
); ////
7614 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE
); ////
7615 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE
); ////
7617 /* SPE load and stores */
7618 static inline void gen_addr_spe_imm_index(DisasContext
*ctx
, TCGv EA
, int sh
)
7620 target_ulong uimm
= rB(ctx
->opcode
);
7622 if (rA(ctx
->opcode
) == 0) {
7623 tcg_gen_movi_tl(EA
, uimm
<< sh
);
7625 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], uimm
<< sh
);
7626 #if defined(TARGET_PPC64)
7627 if (!ctx
->sf_mode
) {
7628 tcg_gen_ext32u_tl(EA
, EA
);
7634 static inline void gen_op_evldd(DisasContext
*ctx
, TCGv addr
)
7636 #if defined(TARGET_PPC64)
7637 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7639 TCGv_i64 t0
= tcg_temp_new_i64();
7640 gen_qemu_ld64(ctx
, t0
, addr
);
7641 tcg_gen_trunc_i64_i32(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7642 tcg_gen_shri_i64(t0
, t0
, 32);
7643 tcg_gen_trunc_i64_i32(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7644 tcg_temp_free_i64(t0
);
7648 static inline void gen_op_evldw(DisasContext
*ctx
, TCGv addr
)
7650 #if defined(TARGET_PPC64)
7651 TCGv t0
= tcg_temp_new();
7652 gen_qemu_ld32u(ctx
, t0
, addr
);
7653 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7654 gen_addr_add(ctx
, addr
, addr
, 4);
7655 gen_qemu_ld32u(ctx
, t0
, addr
);
7656 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7659 gen_qemu_ld32u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7660 gen_addr_add(ctx
, addr
, addr
, 4);
7661 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7665 static inline void gen_op_evldh(DisasContext
*ctx
, TCGv addr
)
7667 TCGv t0
= tcg_temp_new();
7668 #if defined(TARGET_PPC64)
7669 gen_qemu_ld16u(ctx
, t0
, addr
);
7670 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7671 gen_addr_add(ctx
, addr
, addr
, 2);
7672 gen_qemu_ld16u(ctx
, t0
, addr
);
7673 tcg_gen_shli_tl(t0
, t0
, 32);
7674 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7675 gen_addr_add(ctx
, addr
, addr
, 2);
7676 gen_qemu_ld16u(ctx
, t0
, addr
);
7677 tcg_gen_shli_tl(t0
, t0
, 16);
7678 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7679 gen_addr_add(ctx
, addr
, addr
, 2);
7680 gen_qemu_ld16u(ctx
, t0
, addr
);
7681 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7683 gen_qemu_ld16u(ctx
, t0
, addr
);
7684 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7685 gen_addr_add(ctx
, addr
, addr
, 2);
7686 gen_qemu_ld16u(ctx
, t0
, addr
);
7687 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
7688 gen_addr_add(ctx
, addr
, addr
, 2);
7689 gen_qemu_ld16u(ctx
, t0
, addr
);
7690 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7691 gen_addr_add(ctx
, addr
, addr
, 2);
7692 gen_qemu_ld16u(ctx
, t0
, addr
);
7693 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7698 static inline void gen_op_evlhhesplat(DisasContext
*ctx
, TCGv addr
)
7700 TCGv t0
= tcg_temp_new();
7701 gen_qemu_ld16u(ctx
, t0
, addr
);
7702 #if defined(TARGET_PPC64)
7703 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7704 tcg_gen_shli_tl(t0
, t0
, 16);
7705 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7707 tcg_gen_shli_tl(t0
, t0
, 16);
7708 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7709 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7714 static inline void gen_op_evlhhousplat(DisasContext
*ctx
, TCGv addr
)
7716 TCGv t0
= tcg_temp_new();
7717 gen_qemu_ld16u(ctx
, t0
, addr
);
7718 #if defined(TARGET_PPC64)
7719 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7720 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7722 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7723 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7728 static inline void gen_op_evlhhossplat(DisasContext
*ctx
, TCGv addr
)
7730 TCGv t0
= tcg_temp_new();
7731 gen_qemu_ld16s(ctx
, t0
, addr
);
7732 #if defined(TARGET_PPC64)
7733 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7734 tcg_gen_ext32u_tl(t0
, t0
);
7735 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7737 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7738 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7743 static inline void gen_op_evlwhe(DisasContext
*ctx
, TCGv addr
)
7745 TCGv t0
= tcg_temp_new();
7746 #if defined(TARGET_PPC64)
7747 gen_qemu_ld16u(ctx
, t0
, addr
);
7748 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7749 gen_addr_add(ctx
, addr
, addr
, 2);
7750 gen_qemu_ld16u(ctx
, t0
, addr
);
7751 tcg_gen_shli_tl(t0
, t0
, 16);
7752 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7754 gen_qemu_ld16u(ctx
, t0
, addr
);
7755 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7756 gen_addr_add(ctx
, addr
, addr
, 2);
7757 gen_qemu_ld16u(ctx
, t0
, addr
);
7758 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
7763 static inline void gen_op_evlwhou(DisasContext
*ctx
, TCGv addr
)
7765 #if defined(TARGET_PPC64)
7766 TCGv t0
= tcg_temp_new();
7767 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7768 gen_addr_add(ctx
, addr
, addr
, 2);
7769 gen_qemu_ld16u(ctx
, t0
, addr
);
7770 tcg_gen_shli_tl(t0
, t0
, 32);
7771 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7774 gen_qemu_ld16u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7775 gen_addr_add(ctx
, addr
, addr
, 2);
7776 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7780 static inline void gen_op_evlwhos(DisasContext
*ctx
, TCGv addr
)
7782 #if defined(TARGET_PPC64)
7783 TCGv t0
= tcg_temp_new();
7784 gen_qemu_ld16s(ctx
, t0
, addr
);
7785 tcg_gen_ext32u_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7786 gen_addr_add(ctx
, addr
, addr
, 2);
7787 gen_qemu_ld16s(ctx
, t0
, addr
);
7788 tcg_gen_shli_tl(t0
, t0
, 32);
7789 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7792 gen_qemu_ld16s(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7793 gen_addr_add(ctx
, addr
, addr
, 2);
7794 gen_qemu_ld16s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7798 static inline void gen_op_evlwwsplat(DisasContext
*ctx
, TCGv addr
)
7800 TCGv t0
= tcg_temp_new();
7801 gen_qemu_ld32u(ctx
, t0
, addr
);
7802 #if defined(TARGET_PPC64)
7803 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7804 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7806 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7807 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7812 static inline void gen_op_evlwhsplat(DisasContext
*ctx
, TCGv addr
)
7814 TCGv t0
= tcg_temp_new();
7815 #if defined(TARGET_PPC64)
7816 gen_qemu_ld16u(ctx
, t0
, addr
);
7817 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7818 tcg_gen_shli_tl(t0
, t0
, 32);
7819 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7820 gen_addr_add(ctx
, addr
, addr
, 2);
7821 gen_qemu_ld16u(ctx
, t0
, addr
);
7822 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7823 tcg_gen_shli_tl(t0
, t0
, 16);
7824 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7826 gen_qemu_ld16u(ctx
, t0
, addr
);
7827 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7828 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
7829 gen_addr_add(ctx
, addr
, addr
, 2);
7830 gen_qemu_ld16u(ctx
, t0
, addr
);
7831 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
7832 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
7837 static inline void gen_op_evstdd(DisasContext
*ctx
, TCGv addr
)
7839 #if defined(TARGET_PPC64)
7840 gen_qemu_st64(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7842 TCGv_i64 t0
= tcg_temp_new_i64();
7843 tcg_gen_concat_i32_i64(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gprh
[rS(ctx
->opcode
)]);
7844 gen_qemu_st64(ctx
, t0
, addr
);
7845 tcg_temp_free_i64(t0
);
7849 static inline void gen_op_evstdw(DisasContext
*ctx
, TCGv addr
)
7851 #if defined(TARGET_PPC64)
7852 TCGv t0
= tcg_temp_new();
7853 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7854 gen_qemu_st32(ctx
, t0
, addr
);
7857 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7859 gen_addr_add(ctx
, addr
, addr
, 4);
7860 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7863 static inline void gen_op_evstdh(DisasContext
*ctx
, TCGv addr
)
7865 TCGv t0
= tcg_temp_new();
7866 #if defined(TARGET_PPC64)
7867 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
7869 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
7871 gen_qemu_st16(ctx
, t0
, addr
);
7872 gen_addr_add(ctx
, addr
, addr
, 2);
7873 #if defined(TARGET_PPC64)
7874 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7875 gen_qemu_st16(ctx
, t0
, addr
);
7877 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7879 gen_addr_add(ctx
, addr
, addr
, 2);
7880 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
7881 gen_qemu_st16(ctx
, t0
, addr
);
7883 gen_addr_add(ctx
, addr
, addr
, 2);
7884 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7887 static inline void gen_op_evstwhe(DisasContext
*ctx
, TCGv addr
)
7889 TCGv t0
= tcg_temp_new();
7890 #if defined(TARGET_PPC64)
7891 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
7893 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
7895 gen_qemu_st16(ctx
, t0
, addr
);
7896 gen_addr_add(ctx
, addr
, addr
, 2);
7897 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
7898 gen_qemu_st16(ctx
, t0
, addr
);
7902 static inline void gen_op_evstwho(DisasContext
*ctx
, TCGv addr
)
7904 #if defined(TARGET_PPC64)
7905 TCGv t0
= tcg_temp_new();
7906 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7907 gen_qemu_st16(ctx
, t0
, addr
);
7910 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7912 gen_addr_add(ctx
, addr
, addr
, 2);
7913 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7916 static inline void gen_op_evstwwe(DisasContext
*ctx
, TCGv addr
)
7918 #if defined(TARGET_PPC64)
7919 TCGv t0
= tcg_temp_new();
7920 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7921 gen_qemu_st32(ctx
, t0
, addr
);
7924 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7928 static inline void gen_op_evstwwo(DisasContext
*ctx
, TCGv addr
)
7930 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7933 #define GEN_SPEOP_LDST(name, opc2, sh) \
7934 static void glue(gen_, name)(DisasContext *ctx) \
7937 if (unlikely(!ctx->spe_enabled)) { \
7938 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7941 gen_set_access_type(ctx, ACCESS_INT); \
7942 t0 = tcg_temp_new(); \
7943 if (Rc(ctx->opcode)) { \
7944 gen_addr_spe_imm_index(ctx, t0, sh); \
7946 gen_addr_reg_index(ctx, t0); \
7948 gen_op_##name(ctx, t0); \
7949 tcg_temp_free(t0); \
7952 GEN_SPEOP_LDST(evldd
, 0x00, 3);
7953 GEN_SPEOP_LDST(evldw
, 0x01, 3);
7954 GEN_SPEOP_LDST(evldh
, 0x02, 3);
7955 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1);
7956 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1);
7957 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1);
7958 GEN_SPEOP_LDST(evlwhe
, 0x08, 2);
7959 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2);
7960 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2);
7961 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2);
7962 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2);
7964 GEN_SPEOP_LDST(evstdd
, 0x10, 3);
7965 GEN_SPEOP_LDST(evstdw
, 0x11, 3);
7966 GEN_SPEOP_LDST(evstdh
, 0x12, 3);
7967 GEN_SPEOP_LDST(evstwhe
, 0x18, 2);
7968 GEN_SPEOP_LDST(evstwho
, 0x1A, 2);
7969 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2);
7970 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2);
7972 /* Multiply and add - TODO */
7974 GEN_SPE(speundef
, evmhessf
, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);//
7975 GEN_SPE(speundef
, evmhossf
, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7976 GEN_SPE(evmheumi
, evmhesmi
, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
7977 GEN_SPE(speundef
, evmhesmf
, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7978 GEN_SPE(evmhoumi
, evmhosmi
, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
7979 GEN_SPE(speundef
, evmhosmf
, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7980 GEN_SPE(speundef
, evmhessfa
, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7981 GEN_SPE(speundef
, evmhossfa
, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7982 GEN_SPE(evmheumia
, evmhesmia
, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
7983 GEN_SPE(speundef
, evmhesmfa
, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7984 GEN_SPE(evmhoumia
, evmhosmia
, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
7985 GEN_SPE(speundef
, evmhosmfa
, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7987 GEN_SPE(speundef
, evmwhssf
, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7988 GEN_SPE(evmwlumi
, speundef
, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7989 GEN_SPE(evmwhumi
, evmwhsmi
, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
7990 GEN_SPE(speundef
, evmwhsmf
, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7991 GEN_SPE(speundef
, evmwssf
, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7992 GEN_SPE(speundef
, evmwsmf
, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7993 GEN_SPE(speundef
, evmwhssfa
, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7994 GEN_SPE(evmwlumia
, speundef
, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7995 GEN_SPE(evmwhumia
, evmwhsmia
, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
7996 GEN_SPE(speundef
, evmwhsmfa
, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7997 GEN_SPE(speundef
, evmwssfa
, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7998 GEN_SPE(speundef
, evmwsmfa
, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8000 GEN_SPE(evadduiaaw
, evaddsiaaw
, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8001 GEN_SPE(evsubfusiaaw
, evsubfssiaaw
, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8002 GEN_SPE(evaddumiaaw
, evaddsmiaaw
, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8003 GEN_SPE(evsubfumiaaw
, evsubfsmiaaw
, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8004 GEN_SPE(evdivws
, evdivwu
, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE
);
8006 GEN_SPE(evmheusiaaw
, evmhessiaaw
, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8007 GEN_SPE(speundef
, evmhessfaaw
, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8008 GEN_SPE(evmhousiaaw
, evmhossiaaw
, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8009 GEN_SPE(speundef
, evmhossfaaw
, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8010 GEN_SPE(evmheumiaaw
, evmhesmiaaw
, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8011 GEN_SPE(speundef
, evmhesmfaaw
, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8012 GEN_SPE(evmhoumiaaw
, evmhosmiaaw
, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8013 GEN_SPE(speundef
, evmhosmfaaw
, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8014 GEN_SPE(evmhegumiaa
, evmhegsmiaa
, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8015 GEN_SPE(speundef
, evmhegsmfaa
, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8016 GEN_SPE(evmhogumiaa
, evmhogsmiaa
, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8017 GEN_SPE(speundef
, evmhogsmfaa
, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8019 GEN_SPE(evmwlusiaaw
, evmwlssiaaw
, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
8020 GEN_SPE(evmwlumiaaw
, evmwlsmiaaw
, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
8021 GEN_SPE(speundef
, evmwssfaa
, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8022 GEN_SPE(speundef
, evmwsmfaa
, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8024 GEN_SPE(evmheusianw
, evmhessianw
, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8025 GEN_SPE(speundef
, evmhessfanw
, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8026 GEN_SPE(evmhousianw
, evmhossianw
, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8027 GEN_SPE(speundef
, evmhossfanw
, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8028 GEN_SPE(evmheumianw
, evmhesmianw
, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8029 GEN_SPE(speundef
, evmhesmfanw
, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8030 GEN_SPE(evmhoumianw
, evmhosmianw
, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8031 GEN_SPE(speundef
, evmhosmfanw
, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8032 GEN_SPE(evmhegumian
, evmhegsmian
, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8033 GEN_SPE(speundef
, evmhegsmfan
, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8034 GEN_SPE(evmhigumian
, evmhigsmian
, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8035 GEN_SPE(speundef
, evmhogsmfan
, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8037 GEN_SPE(evmwlusianw
, evmwlssianw
, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
8038 GEN_SPE(evmwlumianw
, evmwlsmianw
, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
8039 GEN_SPE(speundef
, evmwssfan
, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8040 GEN_SPE(evmwumian
, evmwsmian
, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
8041 GEN_SPE(speundef
, evmwsmfan
, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8044 /*** SPE floating-point extension ***/
8045 #if defined(TARGET_PPC64)
8046 #define GEN_SPEFPUOP_CONV_32_32(name) \
8047 static inline void gen_##name(DisasContext *ctx) \
8051 t0 = tcg_temp_new_i32(); \
8052 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8053 gen_helper_##name(t0, cpu_env, t0); \
8054 t1 = tcg_temp_new(); \
8055 tcg_gen_extu_i32_tl(t1, t0); \
8056 tcg_temp_free_i32(t0); \
8057 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8058 0xFFFFFFFF00000000ULL); \
8059 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
8060 tcg_temp_free(t1); \
8062 #define GEN_SPEFPUOP_CONV_32_64(name) \
8063 static inline void gen_##name(DisasContext *ctx) \
8067 t0 = tcg_temp_new_i32(); \
8068 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
8069 t1 = tcg_temp_new(); \
8070 tcg_gen_extu_i32_tl(t1, t0); \
8071 tcg_temp_free_i32(t0); \
8072 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8073 0xFFFFFFFF00000000ULL); \
8074 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
8075 tcg_temp_free(t1); \
8077 #define GEN_SPEFPUOP_CONV_64_32(name) \
8078 static inline void gen_##name(DisasContext *ctx) \
8080 TCGv_i32 t0 = tcg_temp_new_i32(); \
8081 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8082 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
8083 tcg_temp_free_i32(t0); \
8085 #define GEN_SPEFPUOP_CONV_64_64(name) \
8086 static inline void gen_##name(DisasContext *ctx) \
8088 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8089 cpu_gpr[rB(ctx->opcode)]); \
8091 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
8092 static inline void gen_##name(DisasContext *ctx) \
8096 if (unlikely(!ctx->spe_enabled)) { \
8097 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8100 t0 = tcg_temp_new_i32(); \
8101 t1 = tcg_temp_new_i32(); \
8102 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8103 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8104 gen_helper_##name(t0, cpu_env, t0, t1); \
8105 tcg_temp_free_i32(t1); \
8106 t2 = tcg_temp_new(); \
8107 tcg_gen_extu_i32_tl(t2, t0); \
8108 tcg_temp_free_i32(t0); \
8109 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8110 0xFFFFFFFF00000000ULL); \
8111 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \
8112 tcg_temp_free(t2); \
8114 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
8115 static inline void gen_##name(DisasContext *ctx) \
8117 if (unlikely(!ctx->spe_enabled)) { \
8118 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8121 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8122 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8124 #define GEN_SPEFPUOP_COMP_32(name) \
8125 static inline void gen_##name(DisasContext *ctx) \
8128 if (unlikely(!ctx->spe_enabled)) { \
8129 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8132 t0 = tcg_temp_new_i32(); \
8133 t1 = tcg_temp_new_i32(); \
8134 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8135 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8136 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
8137 tcg_temp_free_i32(t0); \
8138 tcg_temp_free_i32(t1); \
8140 #define GEN_SPEFPUOP_COMP_64(name) \
8141 static inline void gen_##name(DisasContext *ctx) \
8143 if (unlikely(!ctx->spe_enabled)) { \
8144 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8147 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
8148 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8151 #define GEN_SPEFPUOP_CONV_32_32(name) \
8152 static inline void gen_##name(DisasContext *ctx) \
8154 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8155 cpu_gpr[rB(ctx->opcode)]); \
8157 #define GEN_SPEFPUOP_CONV_32_64(name) \
8158 static inline void gen_##name(DisasContext *ctx) \
8160 TCGv_i64 t0 = tcg_temp_new_i64(); \
8161 gen_load_gpr64(t0, rB(ctx->opcode)); \
8162 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
8163 tcg_temp_free_i64(t0); \
8165 #define GEN_SPEFPUOP_CONV_64_32(name) \
8166 static inline void gen_##name(DisasContext *ctx) \
8168 TCGv_i64 t0 = tcg_temp_new_i64(); \
8169 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
8170 gen_store_gpr64(rD(ctx->opcode), t0); \
8171 tcg_temp_free_i64(t0); \
8173 #define GEN_SPEFPUOP_CONV_64_64(name) \
8174 static inline void gen_##name(DisasContext *ctx) \
8176 TCGv_i64 t0 = tcg_temp_new_i64(); \
8177 gen_load_gpr64(t0, rB(ctx->opcode)); \
8178 gen_helper_##name(t0, cpu_env, t0); \
8179 gen_store_gpr64(rD(ctx->opcode), t0); \
8180 tcg_temp_free_i64(t0); \
8182 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
8183 static inline void gen_##name(DisasContext *ctx) \
8185 if (unlikely(!ctx->spe_enabled)) { \
8186 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8189 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8190 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8192 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
8193 static inline void gen_##name(DisasContext *ctx) \
8196 if (unlikely(!ctx->spe_enabled)) { \
8197 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8200 t0 = tcg_temp_new_i64(); \
8201 t1 = tcg_temp_new_i64(); \
8202 gen_load_gpr64(t0, rA(ctx->opcode)); \
8203 gen_load_gpr64(t1, rB(ctx->opcode)); \
8204 gen_helper_##name(t0, cpu_env, t0, t1); \
8205 gen_store_gpr64(rD(ctx->opcode), t0); \
8206 tcg_temp_free_i64(t0); \
8207 tcg_temp_free_i64(t1); \
8209 #define GEN_SPEFPUOP_COMP_32(name) \
8210 static inline void gen_##name(DisasContext *ctx) \
8212 if (unlikely(!ctx->spe_enabled)) { \
8213 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8216 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
8217 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8219 #define GEN_SPEFPUOP_COMP_64(name) \
8220 static inline void gen_##name(DisasContext *ctx) \
8223 if (unlikely(!ctx->spe_enabled)) { \
8224 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8227 t0 = tcg_temp_new_i64(); \
8228 t1 = tcg_temp_new_i64(); \
8229 gen_load_gpr64(t0, rA(ctx->opcode)); \
8230 gen_load_gpr64(t1, rB(ctx->opcode)); \
8231 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
8232 tcg_temp_free_i64(t0); \
8233 tcg_temp_free_i64(t1); \
8237 /* Single precision floating-point vectors operations */
8239 GEN_SPEFPUOP_ARITH2_64_64(evfsadd
);
8240 GEN_SPEFPUOP_ARITH2_64_64(evfssub
);
8241 GEN_SPEFPUOP_ARITH2_64_64(evfsmul
);
8242 GEN_SPEFPUOP_ARITH2_64_64(evfsdiv
);
8243 static inline void gen_evfsabs(DisasContext
*ctx
)
8245 if (unlikely(!ctx
->spe_enabled
)) {
8246 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8249 #if defined(TARGET_PPC64)
8250 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000080000000LL
);
8252 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x80000000);
8253 tcg_gen_andi_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
8256 static inline void gen_evfsnabs(DisasContext
*ctx
)
8258 if (unlikely(!ctx
->spe_enabled
)) {
8259 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8262 #if defined(TARGET_PPC64)
8263 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
8265 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8266 tcg_gen_ori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8269 static inline void gen_evfsneg(DisasContext
*ctx
)
8271 if (unlikely(!ctx
->spe_enabled
)) {
8272 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8275 #if defined(TARGET_PPC64)
8276 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
8278 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8279 tcg_gen_xori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8284 GEN_SPEFPUOP_CONV_64_64(evfscfui
);
8285 GEN_SPEFPUOP_CONV_64_64(evfscfsi
);
8286 GEN_SPEFPUOP_CONV_64_64(evfscfuf
);
8287 GEN_SPEFPUOP_CONV_64_64(evfscfsf
);
8288 GEN_SPEFPUOP_CONV_64_64(evfsctui
);
8289 GEN_SPEFPUOP_CONV_64_64(evfsctsi
);
8290 GEN_SPEFPUOP_CONV_64_64(evfsctuf
);
8291 GEN_SPEFPUOP_CONV_64_64(evfsctsf
);
8292 GEN_SPEFPUOP_CONV_64_64(evfsctuiz
);
8293 GEN_SPEFPUOP_CONV_64_64(evfsctsiz
);
8296 GEN_SPEFPUOP_COMP_64(evfscmpgt
);
8297 GEN_SPEFPUOP_COMP_64(evfscmplt
);
8298 GEN_SPEFPUOP_COMP_64(evfscmpeq
);
8299 GEN_SPEFPUOP_COMP_64(evfststgt
);
8300 GEN_SPEFPUOP_COMP_64(evfststlt
);
8301 GEN_SPEFPUOP_COMP_64(evfststeq
);
8303 /* Opcodes definitions */
8304 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8305 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
); //
8306 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8307 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8308 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8309 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8310 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8311 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8312 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8313 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8314 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8315 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8316 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8317 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8319 /* Single precision floating-point operations */
8321 GEN_SPEFPUOP_ARITH2_32_32(efsadd
);
8322 GEN_SPEFPUOP_ARITH2_32_32(efssub
);
8323 GEN_SPEFPUOP_ARITH2_32_32(efsmul
);
8324 GEN_SPEFPUOP_ARITH2_32_32(efsdiv
);
8325 static inline void gen_efsabs(DisasContext
*ctx
)
8327 if (unlikely(!ctx
->spe_enabled
)) {
8328 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8331 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], (target_long
)~0x80000000LL
);
8333 static inline void gen_efsnabs(DisasContext
*ctx
)
8335 if (unlikely(!ctx
->spe_enabled
)) {
8336 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8339 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8341 static inline void gen_efsneg(DisasContext
*ctx
)
8343 if (unlikely(!ctx
->spe_enabled
)) {
8344 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8347 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8351 GEN_SPEFPUOP_CONV_32_32(efscfui
);
8352 GEN_SPEFPUOP_CONV_32_32(efscfsi
);
8353 GEN_SPEFPUOP_CONV_32_32(efscfuf
);
8354 GEN_SPEFPUOP_CONV_32_32(efscfsf
);
8355 GEN_SPEFPUOP_CONV_32_32(efsctui
);
8356 GEN_SPEFPUOP_CONV_32_32(efsctsi
);
8357 GEN_SPEFPUOP_CONV_32_32(efsctuf
);
8358 GEN_SPEFPUOP_CONV_32_32(efsctsf
);
8359 GEN_SPEFPUOP_CONV_32_32(efsctuiz
);
8360 GEN_SPEFPUOP_CONV_32_32(efsctsiz
);
8361 GEN_SPEFPUOP_CONV_32_64(efscfd
);
8364 GEN_SPEFPUOP_COMP_32(efscmpgt
);
8365 GEN_SPEFPUOP_COMP_32(efscmplt
);
8366 GEN_SPEFPUOP_COMP_32(efscmpeq
);
8367 GEN_SPEFPUOP_COMP_32(efststgt
);
8368 GEN_SPEFPUOP_COMP_32(efststlt
);
8369 GEN_SPEFPUOP_COMP_32(efststeq
);
8371 /* Opcodes definitions */
8372 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8373 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
); //
8374 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8375 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8376 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8377 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE
); //
8378 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8379 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8380 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8381 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8382 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8383 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8384 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8385 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8387 /* Double precision floating-point operations */
8389 GEN_SPEFPUOP_ARITH2_64_64(efdadd
);
8390 GEN_SPEFPUOP_ARITH2_64_64(efdsub
);
8391 GEN_SPEFPUOP_ARITH2_64_64(efdmul
);
8392 GEN_SPEFPUOP_ARITH2_64_64(efddiv
);
8393 static inline void gen_efdabs(DisasContext
*ctx
)
8395 if (unlikely(!ctx
->spe_enabled
)) {
8396 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8399 #if defined(TARGET_PPC64)
8400 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000000000000LL
);
8402 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8403 tcg_gen_andi_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
8406 static inline void gen_efdnabs(DisasContext
*ctx
)
8408 if (unlikely(!ctx
->spe_enabled
)) {
8409 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8412 #if defined(TARGET_PPC64)
8413 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
8415 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8416 tcg_gen_ori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8419 static inline void gen_efdneg(DisasContext
*ctx
)
8421 if (unlikely(!ctx
->spe_enabled
)) {
8422 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8425 #if defined(TARGET_PPC64)
8426 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
8428 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8429 tcg_gen_xori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8434 GEN_SPEFPUOP_CONV_64_32(efdcfui
);
8435 GEN_SPEFPUOP_CONV_64_32(efdcfsi
);
8436 GEN_SPEFPUOP_CONV_64_32(efdcfuf
);
8437 GEN_SPEFPUOP_CONV_64_32(efdcfsf
);
8438 GEN_SPEFPUOP_CONV_32_64(efdctui
);
8439 GEN_SPEFPUOP_CONV_32_64(efdctsi
);
8440 GEN_SPEFPUOP_CONV_32_64(efdctuf
);
8441 GEN_SPEFPUOP_CONV_32_64(efdctsf
);
8442 GEN_SPEFPUOP_CONV_32_64(efdctuiz
);
8443 GEN_SPEFPUOP_CONV_32_64(efdctsiz
);
8444 GEN_SPEFPUOP_CONV_64_32(efdcfs
);
8445 GEN_SPEFPUOP_CONV_64_64(efdcfuid
);
8446 GEN_SPEFPUOP_CONV_64_64(efdcfsid
);
8447 GEN_SPEFPUOP_CONV_64_64(efdctuidz
);
8448 GEN_SPEFPUOP_CONV_64_64(efdctsidz
);
8451 GEN_SPEFPUOP_COMP_64(efdcmpgt
);
8452 GEN_SPEFPUOP_COMP_64(efdcmplt
);
8453 GEN_SPEFPUOP_COMP_64(efdcmpeq
);
8454 GEN_SPEFPUOP_COMP_64(efdtstgt
);
8455 GEN_SPEFPUOP_COMP_64(efdtstlt
);
8456 GEN_SPEFPUOP_COMP_64(efdtsteq
);
8458 /* Opcodes definitions */
8459 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
); //
8460 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8461 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE
); //
8462 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8463 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
); //
8464 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8465 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
); //
8466 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE
); //
8467 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8468 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8469 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8470 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8471 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8472 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8473 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
); //
8474 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8476 static opcode_t opcodes
[] = {
8477 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
),
8478 GEN_HANDLER(cmp
, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER
),
8479 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
8480 GEN_HANDLER(cmpl
, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER
),
8481 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
8482 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
),
8483 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8484 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8485 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8486 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8487 GEN_HANDLER(mulhw
, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER
),
8488 GEN_HANDLER(mulhwu
, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER
),
8489 GEN_HANDLER(mullw
, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER
),
8490 GEN_HANDLER(mullwo
, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER
),
8491 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8492 #if defined(TARGET_PPC64)
8493 GEN_HANDLER(mulld
, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B
),
8495 GEN_HANDLER(neg
, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER
),
8496 GEN_HANDLER(nego
, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER
),
8497 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8498 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8499 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8500 GEN_HANDLER(cntlzw
, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER
),
8501 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
),
8502 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
),
8503 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8504 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8505 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8506 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8507 GEN_HANDLER(popcntb
, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB
),
8508 GEN_HANDLER(popcntw
, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD
),
8509 #if defined(TARGET_PPC64)
8510 GEN_HANDLER(popcntd
, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD
),
8511 GEN_HANDLER(cntlzd
, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B
),
8513 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8514 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8515 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8516 GEN_HANDLER(slw
, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER
),
8517 GEN_HANDLER(sraw
, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER
),
8518 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
),
8519 GEN_HANDLER(srw
, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER
),
8520 #if defined(TARGET_PPC64)
8521 GEN_HANDLER(sld
, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B
),
8522 GEN_HANDLER(srad
, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B
),
8523 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
),
8524 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
),
8525 GEN_HANDLER(srd
, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B
),
8527 GEN_HANDLER(frsqrtes
, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES
),
8528 GEN_HANDLER(fsqrt
, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
8529 GEN_HANDLER(fsqrts
, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
8530 GEN_HANDLER(fcmpo
, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT
),
8531 GEN_HANDLER(fcmpu
, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT
),
8532 GEN_HANDLER(fmr
, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT
),
8533 GEN_HANDLER(mcrfs
, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT
),
8534 GEN_HANDLER(mffs
, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT
),
8535 GEN_HANDLER(mtfsb0
, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT
),
8536 GEN_HANDLER(mtfsb1
, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT
),
8537 GEN_HANDLER(mtfsf
, 0x3F, 0x07, 0x16, 0x00010000, PPC_FLOAT
),
8538 GEN_HANDLER(mtfsfi
, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT
),
8539 #if defined(TARGET_PPC64)
8540 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
),
8541 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
),
8542 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
),
8544 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8545 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8546 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
),
8547 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
),
8548 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
),
8549 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
),
8550 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO
),
8551 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
),
8552 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES
),
8553 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
),
8554 #if defined(TARGET_PPC64)
8555 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B
),
8556 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
),
8558 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
),
8559 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
),
8560 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
8561 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
8562 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
),
8563 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
),
8564 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
),
8565 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
),
8566 #if defined(TARGET_PPC64)
8567 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
),
8568 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
),
8570 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW
),
8571 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
),
8572 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
8573 #if defined(TARGET_PPC64)
8574 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
),
8575 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
),
8577 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
),
8578 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
),
8579 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
),
8580 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
),
8581 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
),
8582 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
),
8583 #if defined(TARGET_PPC64)
8584 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
),
8586 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC
),
8587 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC
),
8588 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
),
8589 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
),
8590 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
),
8591 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE
),
8592 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE
),
8593 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ
),
8594 GEN_HANDLER(dst
, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC
),
8595 GEN_HANDLER(dstst
, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC
),
8596 GEN_HANDLER(dss
, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC
),
8597 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
),
8598 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
),
8599 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
),
8600 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
),
8601 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
),
8602 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
),
8603 #if defined(TARGET_PPC64)
8604 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
),
8605 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
8607 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
),
8608 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
8610 GEN_HANDLER2(slbmte
, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B
),
8611 GEN_HANDLER2(slbmfee
, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B
),
8612 GEN_HANDLER2(slbmfev
, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B
),
8614 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
),
8615 GEN_HANDLER(tlbiel
, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE
),
8616 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE
),
8617 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
),
8618 #if defined(TARGET_PPC64)
8619 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI
),
8620 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
),
8622 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
),
8623 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
),
8624 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
),
8625 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
),
8626 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
),
8627 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
),
8628 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
),
8629 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
),
8630 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
),
8631 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
),
8632 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
),
8633 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
8634 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
),
8635 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
),
8636 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
),
8637 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
),
8638 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
),
8639 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
),
8640 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
),
8641 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
8642 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
),
8643 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
),
8644 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
),
8645 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
),
8646 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
),
8647 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
),
8648 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
),
8649 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
),
8650 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
),
8651 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
),
8652 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
),
8653 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
),
8654 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
),
8655 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
),
8656 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
),
8657 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
),
8658 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
),
8659 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
),
8660 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
),
8661 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
),
8662 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
),
8663 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
),
8664 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
),
8665 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
),
8666 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
),
8667 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
),
8668 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
),
8669 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
),
8670 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
),
8671 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8672 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8673 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
),
8674 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
),
8675 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8676 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8677 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
),
8678 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
),
8679 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
),
8680 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
),
8681 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
),
8682 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
),
8683 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
),
8684 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
),
8685 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
),
8686 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
),
8687 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
),
8688 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
),
8689 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
),
8690 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
),
8691 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
),
8692 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
),
8693 GEN_HANDLER_E(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
, PPC2_BOOKE206
),
8694 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
),
8695 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
),
8696 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
),
8697 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
),
8698 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
),
8699 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
),
8700 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
),
8701 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
),
8702 GEN_HANDLER2_E(tlbre_booke206
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
8703 PPC_NONE
, PPC2_BOOKE206
),
8704 GEN_HANDLER2_E(tlbsx_booke206
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
8705 PPC_NONE
, PPC2_BOOKE206
),
8706 GEN_HANDLER2_E(tlbwe_booke206
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
8707 PPC_NONE
, PPC2_BOOKE206
),
8708 GEN_HANDLER2_E(tlbivax_booke206
, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
8709 PPC_NONE
, PPC2_BOOKE206
),
8710 GEN_HANDLER2_E(tlbilx_booke206
, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
8711 PPC_NONE
, PPC2_BOOKE206
),
8712 GEN_HANDLER2_E(msgsnd
, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
8713 PPC_NONE
, PPC2_PRCNTL
),
8714 GEN_HANDLER2_E(msgclr
, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
8715 PPC_NONE
, PPC2_PRCNTL
),
8716 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
),
8717 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE
),
8718 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
),
8719 GEN_HANDLER_E(mbar
, 0x1F, 0x16, 0x1a, 0x001FF801,
8720 PPC_BOOKE
, PPC2_BOOKE206
),
8721 GEN_HANDLER(msync_4xx
, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE
),
8722 GEN_HANDLER2_E(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
8723 PPC_BOOKE
, PPC2_BOOKE206
),
8724 GEN_HANDLER(lvsl
, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC
),
8725 GEN_HANDLER(lvsr
, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC
),
8726 GEN_HANDLER(mfvscr
, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC
),
8727 GEN_HANDLER(mtvscr
, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC
),
8728 GEN_HANDLER(vsldoi
, 0x04, 0x16, 0xFF, 0x00000400, PPC_ALTIVEC
),
8729 GEN_HANDLER(vmladduhm
, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC
),
8730 GEN_HANDLER2(evsel0
, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE
),
8731 GEN_HANDLER2(evsel1
, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE
),
8732 GEN_HANDLER2(evsel2
, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE
),
8733 GEN_HANDLER2(evsel3
, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE
),
8735 #undef GEN_INT_ARITH_ADD
8736 #undef GEN_INT_ARITH_ADD_CONST
8737 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
8738 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
8739 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
8740 add_ca, compute_ca, compute_ov) \
8741 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
8742 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
8743 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
8744 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
8745 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
8746 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
8747 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
8748 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
8749 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
8750 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
8751 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
8753 #undef GEN_INT_ARITH_DIVW
8754 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
8755 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
8756 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0),
8757 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1),
8758 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0),
8759 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1),
8761 #if defined(TARGET_PPC64)
8762 #undef GEN_INT_ARITH_DIVD
8763 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
8764 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8765 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0),
8766 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1),
8767 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0),
8768 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1),
8770 #undef GEN_INT_ARITH_MUL_HELPER
8771 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
8772 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8773 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00),
8774 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02),
8775 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17),
8778 #undef GEN_INT_ARITH_SUBF
8779 #undef GEN_INT_ARITH_SUBF_CONST
8780 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
8781 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
8782 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
8783 add_ca, compute_ca, compute_ov) \
8784 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
8785 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
8786 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
8787 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
8788 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
8789 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
8790 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
8791 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
8792 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
8793 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
8794 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
8798 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
8799 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
8800 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
8801 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
8802 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
),
8803 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
),
8804 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
),
8805 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
),
8806 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
),
8807 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
),
8808 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
),
8809 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
),
8810 #if defined(TARGET_PPC64)
8811 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
),
8814 #if defined(TARGET_PPC64)
8817 #define GEN_PPC64_R2(name, opc1, opc2) \
8818 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8819 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
8821 #define GEN_PPC64_R4(name, opc1, opc2) \
8822 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8823 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
8825 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
8827 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
8829 GEN_PPC64_R4(rldicl
, 0x1E, 0x00),
8830 GEN_PPC64_R4(rldicr
, 0x1E, 0x02),
8831 GEN_PPC64_R4(rldic
, 0x1E, 0x04),
8832 GEN_PPC64_R2(rldcl
, 0x1E, 0x08),
8833 GEN_PPC64_R2(rldcr
, 0x1E, 0x09),
8834 GEN_PPC64_R4(rldimi
, 0x1E, 0x06),
8837 #undef _GEN_FLOAT_ACB
8838 #undef GEN_FLOAT_ACB
8839 #undef _GEN_FLOAT_AB
8841 #undef _GEN_FLOAT_AC
8845 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
8846 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
8847 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
8848 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
8849 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
8850 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
8851 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
8852 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
8853 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
8854 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
8855 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
8856 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
8857 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
8858 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
8859 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
8860 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
8861 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
8862 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
8863 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
8865 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
),
8866 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
),
8867 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
),
8868 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
),
8869 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
),
8870 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
),
8871 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
),
8872 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
),
8873 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
),
8874 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
),
8875 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
),
8876 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
),
8877 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
),
8878 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
),
8879 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
),
8880 #if defined(TARGET_PPC64)
8881 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
),
8882 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
),
8883 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
),
8885 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
),
8886 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
),
8887 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
),
8888 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
),
8889 GEN_FLOAT_B(abs
, 0x08, 0x08, 0, PPC_FLOAT
),
8890 GEN_FLOAT_B(nabs
, 0x08, 0x04, 0, PPC_FLOAT
),
8891 GEN_FLOAT_B(neg
, 0x08, 0x01, 0, PPC_FLOAT
),
8898 #define GEN_LD(name, ldop, opc, type) \
8899 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8900 #define GEN_LDU(name, ldop, opc, type) \
8901 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
8902 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
8903 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
8904 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
8905 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
8906 #define GEN_LDS(name, ldop, op, type) \
8907 GEN_LD(name, ldop, op | 0x20, type) \
8908 GEN_LDU(name, ldop, op | 0x21, type) \
8909 GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
8910 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
8912 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
)
8913 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
)
8914 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
)
8915 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
)
8916 #if defined(TARGET_PPC64)
8917 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
)
8918 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
)
8919 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
)
8920 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
)
8921 GEN_LDX_E(ldbr
, ld64ur
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
)
8923 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
)
8924 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
)
8931 #define GEN_ST(name, stop, opc, type) \
8932 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8933 #define GEN_STU(name, stop, opc, type) \
8934 GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
8935 #define GEN_STUX(name, stop, opc2, opc3, type) \
8936 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
8937 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
8938 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
8939 #define GEN_STS(name, stop, op, type) \
8940 GEN_ST(name, stop, op | 0x20, type) \
8941 GEN_STU(name, stop, op | 0x21, type) \
8942 GEN_STUX(name, stop, 0x17, op | 0x01, type) \
8943 GEN_STX(name, stop, 0x17, op | 0x00, type)
8945 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
)
8946 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
)
8947 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
)
8948 #if defined(TARGET_PPC64)
8949 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
)
8950 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
)
8951 GEN_STX_E(stdbr
, st64r
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
)
8953 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
)
8954 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
)
8961 #define GEN_LDF(name, ldop, opc, type) \
8962 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8963 #define GEN_LDUF(name, ldop, opc, type) \
8964 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
8965 #define GEN_LDUXF(name, ldop, opc, type) \
8966 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
8967 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
8968 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
8969 #define GEN_LDFS(name, ldop, op, type) \
8970 GEN_LDF(name, ldop, op | 0x20, type) \
8971 GEN_LDUF(name, ldop, op | 0x21, type) \
8972 GEN_LDUXF(name, ldop, op | 0x01, type) \
8973 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
8975 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
)
8976 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
)
8983 #define GEN_STF(name, stop, opc, type) \
8984 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8985 #define GEN_STUF(name, stop, opc, type) \
8986 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
8987 #define GEN_STUXF(name, stop, opc, type) \
8988 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
8989 #define GEN_STXF(name, stop, opc2, opc3, type) \
8990 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
8991 #define GEN_STFS(name, stop, op, type) \
8992 GEN_STF(name, stop, op | 0x20, type) \
8993 GEN_STUF(name, stop, op | 0x21, type) \
8994 GEN_STUXF(name, stop, op | 0x01, type) \
8995 GEN_STXF(name, stop, 0x17, op | 0x00, type)
8997 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
)
8998 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
)
8999 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
)
9002 #define GEN_CRLOGIC(name, tcg_op, opc) \
9003 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
9004 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08),
9005 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04),
9006 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09),
9007 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07),
9008 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01),
9009 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E),
9010 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D),
9011 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06),
9013 #undef GEN_MAC_HANDLER
9014 #define GEN_MAC_HANDLER(name, opc2, opc3) \
9015 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
9016 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05),
9017 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15),
9018 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07),
9019 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17),
9020 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06),
9021 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16),
9022 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04),
9023 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14),
9024 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01),
9025 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11),
9026 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03),
9027 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13),
9028 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02),
9029 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12),
9030 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00),
9031 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10),
9032 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D),
9033 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D),
9034 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F),
9035 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F),
9036 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C),
9037 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C),
9038 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E),
9039 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E),
9040 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05),
9041 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15),
9042 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07),
9043 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17),
9044 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01),
9045 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11),
9046 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03),
9047 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13),
9048 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D),
9049 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D),
9050 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F),
9051 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F),
9052 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05),
9053 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04),
9054 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01),
9055 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00),
9056 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D),
9057 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C),
9063 #define GEN_VR_LDX(name, opc2, opc3) \
9064 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9065 #define GEN_VR_STX(name, opc2, opc3) \
9066 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9067 #define GEN_VR_LVE(name, opc2, opc3) \
9068 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9069 #define GEN_VR_STVE(name, opc2, opc3) \
9070 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9071 GEN_VR_LDX(lvx
, 0x07, 0x03),
9072 GEN_VR_LDX(lvxl
, 0x07, 0x0B),
9073 GEN_VR_LVE(bx
, 0x07, 0x00),
9074 GEN_VR_LVE(hx
, 0x07, 0x01),
9075 GEN_VR_LVE(wx
, 0x07, 0x02),
9076 GEN_VR_STX(svx
, 0x07, 0x07),
9077 GEN_VR_STX(svxl
, 0x07, 0x0F),
9078 GEN_VR_STVE(bx
, 0x07, 0x04),
9079 GEN_VR_STVE(hx
, 0x07, 0x05),
9080 GEN_VR_STVE(wx
, 0x07, 0x06),
9082 #undef GEN_VX_LOGICAL
9083 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
9084 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9085 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16),
9086 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17),
9087 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18),
9088 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19),
9089 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20),
9092 #define GEN_VXFORM(name, opc2, opc3) \
9093 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9094 GEN_VXFORM(vaddubm
, 0, 0),
9095 GEN_VXFORM(vadduhm
, 0, 1),
9096 GEN_VXFORM(vadduwm
, 0, 2),
9097 GEN_VXFORM(vsububm
, 0, 16),
9098 GEN_VXFORM(vsubuhm
, 0, 17),
9099 GEN_VXFORM(vsubuwm
, 0, 18),
9100 GEN_VXFORM(vmaxub
, 1, 0),
9101 GEN_VXFORM(vmaxuh
, 1, 1),
9102 GEN_VXFORM(vmaxuw
, 1, 2),
9103 GEN_VXFORM(vmaxsb
, 1, 4),
9104 GEN_VXFORM(vmaxsh
, 1, 5),
9105 GEN_VXFORM(vmaxsw
, 1, 6),
9106 GEN_VXFORM(vminub
, 1, 8),
9107 GEN_VXFORM(vminuh
, 1, 9),
9108 GEN_VXFORM(vminuw
, 1, 10),
9109 GEN_VXFORM(vminsb
, 1, 12),
9110 GEN_VXFORM(vminsh
, 1, 13),
9111 GEN_VXFORM(vminsw
, 1, 14),
9112 GEN_VXFORM(vavgub
, 1, 16),
9113 GEN_VXFORM(vavguh
, 1, 17),
9114 GEN_VXFORM(vavguw
, 1, 18),
9115 GEN_VXFORM(vavgsb
, 1, 20),
9116 GEN_VXFORM(vavgsh
, 1, 21),
9117 GEN_VXFORM(vavgsw
, 1, 22),
9118 GEN_VXFORM(vmrghb
, 6, 0),
9119 GEN_VXFORM(vmrghh
, 6, 1),
9120 GEN_VXFORM(vmrghw
, 6, 2),
9121 GEN_VXFORM(vmrglb
, 6, 4),
9122 GEN_VXFORM(vmrglh
, 6, 5),
9123 GEN_VXFORM(vmrglw
, 6, 6),
9124 GEN_VXFORM(vmuloub
, 4, 0),
9125 GEN_VXFORM(vmulouh
, 4, 1),
9126 GEN_VXFORM(vmulosb
, 4, 4),
9127 GEN_VXFORM(vmulosh
, 4, 5),
9128 GEN_VXFORM(vmuleub
, 4, 8),
9129 GEN_VXFORM(vmuleuh
, 4, 9),
9130 GEN_VXFORM(vmulesb
, 4, 12),
9131 GEN_VXFORM(vmulesh
, 4, 13),
9132 GEN_VXFORM(vslb
, 2, 4),
9133 GEN_VXFORM(vslh
, 2, 5),
9134 GEN_VXFORM(vslw
, 2, 6),
9135 GEN_VXFORM(vsrb
, 2, 8),
9136 GEN_VXFORM(vsrh
, 2, 9),
9137 GEN_VXFORM(vsrw
, 2, 10),
9138 GEN_VXFORM(vsrab
, 2, 12),
9139 GEN_VXFORM(vsrah
, 2, 13),
9140 GEN_VXFORM(vsraw
, 2, 14),
9141 GEN_VXFORM(vslo
, 6, 16),
9142 GEN_VXFORM(vsro
, 6, 17),
9143 GEN_VXFORM(vaddcuw
, 0, 6),
9144 GEN_VXFORM(vsubcuw
, 0, 22),
9145 GEN_VXFORM(vaddubs
, 0, 8),
9146 GEN_VXFORM(vadduhs
, 0, 9),
9147 GEN_VXFORM(vadduws
, 0, 10),
9148 GEN_VXFORM(vaddsbs
, 0, 12),
9149 GEN_VXFORM(vaddshs
, 0, 13),
9150 GEN_VXFORM(vaddsws
, 0, 14),
9151 GEN_VXFORM(vsububs
, 0, 24),
9152 GEN_VXFORM(vsubuhs
, 0, 25),
9153 GEN_VXFORM(vsubuws
, 0, 26),
9154 GEN_VXFORM(vsubsbs
, 0, 28),
9155 GEN_VXFORM(vsubshs
, 0, 29),
9156 GEN_VXFORM(vsubsws
, 0, 30),
9157 GEN_VXFORM(vrlb
, 2, 0),
9158 GEN_VXFORM(vrlh
, 2, 1),
9159 GEN_VXFORM(vrlw
, 2, 2),
9160 GEN_VXFORM(vsl
, 2, 7),
9161 GEN_VXFORM(vsr
, 2, 11),
9162 GEN_VXFORM(vpkuhum
, 7, 0),
9163 GEN_VXFORM(vpkuwum
, 7, 1),
9164 GEN_VXFORM(vpkuhus
, 7, 2),
9165 GEN_VXFORM(vpkuwus
, 7, 3),
9166 GEN_VXFORM(vpkshus
, 7, 4),
9167 GEN_VXFORM(vpkswus
, 7, 5),
9168 GEN_VXFORM(vpkshss
, 7, 6),
9169 GEN_VXFORM(vpkswss
, 7, 7),
9170 GEN_VXFORM(vpkpx
, 7, 12),
9171 GEN_VXFORM(vsum4ubs
, 4, 24),
9172 GEN_VXFORM(vsum4sbs
, 4, 28),
9173 GEN_VXFORM(vsum4shs
, 4, 25),
9174 GEN_VXFORM(vsum2sws
, 4, 26),
9175 GEN_VXFORM(vsumsws
, 4, 30),
9176 GEN_VXFORM(vaddfp
, 5, 0),
9177 GEN_VXFORM(vsubfp
, 5, 1),
9178 GEN_VXFORM(vmaxfp
, 5, 16),
9179 GEN_VXFORM(vminfp
, 5, 17),
9183 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
9184 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
9185 #define GEN_VXRFORM(name, opc2, opc3) \
9186 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
9187 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
9188 GEN_VXRFORM(vcmpequb
, 3, 0)
9189 GEN_VXRFORM(vcmpequh
, 3, 1)
9190 GEN_VXRFORM(vcmpequw
, 3, 2)
9191 GEN_VXRFORM(vcmpgtsb
, 3, 12)
9192 GEN_VXRFORM(vcmpgtsh
, 3, 13)
9193 GEN_VXRFORM(vcmpgtsw
, 3, 14)
9194 GEN_VXRFORM(vcmpgtub
, 3, 8)
9195 GEN_VXRFORM(vcmpgtuh
, 3, 9)
9196 GEN_VXRFORM(vcmpgtuw
, 3, 10)
9197 GEN_VXRFORM(vcmpeqfp
, 3, 3)
9198 GEN_VXRFORM(vcmpgefp
, 3, 7)
9199 GEN_VXRFORM(vcmpgtfp
, 3, 11)
9200 GEN_VXRFORM(vcmpbfp
, 3, 15)
9202 #undef GEN_VXFORM_SIMM
9203 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
9204 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9205 GEN_VXFORM_SIMM(vspltisb
, 6, 12),
9206 GEN_VXFORM_SIMM(vspltish
, 6, 13),
9207 GEN_VXFORM_SIMM(vspltisw
, 6, 14),
9209 #undef GEN_VXFORM_NOA
9210 #define GEN_VXFORM_NOA(name, opc2, opc3) \
9211 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
9212 GEN_VXFORM_NOA(vupkhsb
, 7, 8),
9213 GEN_VXFORM_NOA(vupkhsh
, 7, 9),
9214 GEN_VXFORM_NOA(vupklsb
, 7, 10),
9215 GEN_VXFORM_NOA(vupklsh
, 7, 11),
9216 GEN_VXFORM_NOA(vupkhpx
, 7, 13),
9217 GEN_VXFORM_NOA(vupklpx
, 7, 15),
9218 GEN_VXFORM_NOA(vrefp
, 5, 4),
9219 GEN_VXFORM_NOA(vrsqrtefp
, 5, 5),
9220 GEN_VXFORM_NOA(vexptefp
, 5, 6),
9221 GEN_VXFORM_NOA(vlogefp
, 5, 7),
9222 GEN_VXFORM_NOA(vrfim
, 5, 8),
9223 GEN_VXFORM_NOA(vrfin
, 5, 9),
9224 GEN_VXFORM_NOA(vrfip
, 5, 10),
9225 GEN_VXFORM_NOA(vrfiz
, 5, 11),
9227 #undef GEN_VXFORM_UIMM
9228 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
9229 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9230 GEN_VXFORM_UIMM(vspltb
, 6, 8),
9231 GEN_VXFORM_UIMM(vsplth
, 6, 9),
9232 GEN_VXFORM_UIMM(vspltw
, 6, 10),
9233 GEN_VXFORM_UIMM(vcfux
, 5, 12),
9234 GEN_VXFORM_UIMM(vcfsx
, 5, 13),
9235 GEN_VXFORM_UIMM(vctuxs
, 5, 14),
9236 GEN_VXFORM_UIMM(vctsxs
, 5, 15),
9238 #undef GEN_VAFORM_PAIRED
9239 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
9240 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
9241 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16),
9242 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18),
9243 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19),
9244 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20),
9245 GEN_VAFORM_PAIRED(vsel
, vperm
, 21),
9246 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23),
9249 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
9250 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
9251 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9252 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9253 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9254 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9255 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
9256 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
9257 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
9258 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE
),
9259 GEN_SPE(evmra
, speundef
, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE
),
9260 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
),
9261 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9262 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9263 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9264 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE
),
9265 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE
),
9266 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE
),
9267 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
),
9268 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9269 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9270 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9271 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9272 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9273 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE
),
9274 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE
),
9275 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9276 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9277 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE
),
9278 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE
),
9279 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE
),
9281 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9282 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
),
9283 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9284 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9285 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9286 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9287 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9288 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9289 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9290 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9291 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9292 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9293 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9294 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9296 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9297 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
),
9298 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9299 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9300 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9301 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE
),
9302 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9303 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9304 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9305 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9306 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9307 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9308 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9309 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9311 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
),
9312 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9313 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE
),
9314 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9315 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
),
9316 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9317 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
),
9318 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE
),
9319 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9320 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9321 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9322 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9323 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9324 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9325 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
),
9326 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9328 #undef GEN_SPEOP_LDST
9329 #define GEN_SPEOP_LDST(name, opc2, sh) \
9330 GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
9331 GEN_SPEOP_LDST(evldd
, 0x00, 3),
9332 GEN_SPEOP_LDST(evldw
, 0x01, 3),
9333 GEN_SPEOP_LDST(evldh
, 0x02, 3),
9334 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1),
9335 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1),
9336 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1),
9337 GEN_SPEOP_LDST(evlwhe
, 0x08, 2),
9338 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2),
9339 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2),
9340 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2),
9341 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2),
9343 GEN_SPEOP_LDST(evstdd
, 0x10, 3),
9344 GEN_SPEOP_LDST(evstdw
, 0x11, 3),
9345 GEN_SPEOP_LDST(evstdh
, 0x12, 3),
9346 GEN_SPEOP_LDST(evstwhe
, 0x18, 2),
9347 GEN_SPEOP_LDST(evstwho
, 0x1A, 2),
9348 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2),
9349 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2),
9352 #include "helper_regs.h"
9353 #include "translate_init.c"
9355 /*****************************************************************************/
9356 /* Misc PowerPC helpers */
9357 void cpu_dump_state (CPUPPCState
*env
, FILE *f
, fprintf_function cpu_fprintf
,
9365 cpu_synchronize_state(env
);
9367 cpu_fprintf(f
, "NIP " TARGET_FMT_lx
" LR " TARGET_FMT_lx
" CTR "
9368 TARGET_FMT_lx
" XER " TARGET_FMT_lx
"\n",
9369 env
->nip
, env
->lr
, env
->ctr
, cpu_read_xer(env
));
9370 cpu_fprintf(f
, "MSR " TARGET_FMT_lx
" HID0 " TARGET_FMT_lx
" HF "
9371 TARGET_FMT_lx
" idx %d\n", env
->msr
, env
->spr
[SPR_HID0
],
9372 env
->hflags
, env
->mmu_idx
);
9373 #if !defined(NO_TIMER_DUMP)
9374 cpu_fprintf(f
, "TB %08" PRIu32
" %08" PRIu64
9375 #if !defined(CONFIG_USER_ONLY)
9379 cpu_ppc_load_tbu(env
), cpu_ppc_load_tbl(env
)
9380 #if !defined(CONFIG_USER_ONLY)
9381 , cpu_ppc_load_decr(env
)
9385 for (i
= 0; i
< 32; i
++) {
9386 if ((i
& (RGPL
- 1)) == 0)
9387 cpu_fprintf(f
, "GPR%02d", i
);
9388 cpu_fprintf(f
, " %016" PRIx64
, ppc_dump_gpr(env
, i
));
9389 if ((i
& (RGPL
- 1)) == (RGPL
- 1))
9390 cpu_fprintf(f
, "\n");
9392 cpu_fprintf(f
, "CR ");
9393 for (i
= 0; i
< 8; i
++)
9394 cpu_fprintf(f
, "%01x", env
->crf
[i
]);
9395 cpu_fprintf(f
, " [");
9396 for (i
= 0; i
< 8; i
++) {
9398 if (env
->crf
[i
] & 0x08)
9400 else if (env
->crf
[i
] & 0x04)
9402 else if (env
->crf
[i
] & 0x02)
9404 cpu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
9406 cpu_fprintf(f
, " ] RES " TARGET_FMT_lx
"\n",
9408 for (i
= 0; i
< 32; i
++) {
9409 if ((i
& (RFPL
- 1)) == 0)
9410 cpu_fprintf(f
, "FPR%02d", i
);
9411 cpu_fprintf(f
, " %016" PRIx64
, *((uint64_t *)&env
->fpr
[i
]));
9412 if ((i
& (RFPL
- 1)) == (RFPL
- 1))
9413 cpu_fprintf(f
, "\n");
9415 cpu_fprintf(f
, "FPSCR " TARGET_FMT_lx
"\n", env
->fpscr
);
9416 #if !defined(CONFIG_USER_ONLY)
9417 cpu_fprintf(f
, " SRR0 " TARGET_FMT_lx
" SRR1 " TARGET_FMT_lx
9418 " PVR " TARGET_FMT_lx
" VRSAVE " TARGET_FMT_lx
"\n",
9419 env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
9420 env
->spr
[SPR_PVR
], env
->spr
[SPR_VRSAVE
]);
9422 cpu_fprintf(f
, "SPRG0 " TARGET_FMT_lx
" SPRG1 " TARGET_FMT_lx
9423 " SPRG2 " TARGET_FMT_lx
" SPRG3 " TARGET_FMT_lx
"\n",
9424 env
->spr
[SPR_SPRG0
], env
->spr
[SPR_SPRG1
],
9425 env
->spr
[SPR_SPRG2
], env
->spr
[SPR_SPRG3
]);
9427 cpu_fprintf(f
, "SPRG4 " TARGET_FMT_lx
" SPRG5 " TARGET_FMT_lx
9428 " SPRG6 " TARGET_FMT_lx
" SPRG7 " TARGET_FMT_lx
"\n",
9429 env
->spr
[SPR_SPRG4
], env
->spr
[SPR_SPRG5
],
9430 env
->spr
[SPR_SPRG6
], env
->spr
[SPR_SPRG7
]);
9432 if (env
->excp_model
== POWERPC_EXCP_BOOKE
) {
9433 cpu_fprintf(f
, "CSRR0 " TARGET_FMT_lx
" CSRR1 " TARGET_FMT_lx
9434 " MCSRR0 " TARGET_FMT_lx
" MCSRR1 " TARGET_FMT_lx
"\n",
9435 env
->spr
[SPR_BOOKE_CSRR0
], env
->spr
[SPR_BOOKE_CSRR1
],
9436 env
->spr
[SPR_BOOKE_MCSRR0
], env
->spr
[SPR_BOOKE_MCSRR1
]);
9438 cpu_fprintf(f
, " TCR " TARGET_FMT_lx
" TSR " TARGET_FMT_lx
9439 " ESR " TARGET_FMT_lx
" DEAR " TARGET_FMT_lx
"\n",
9440 env
->spr
[SPR_BOOKE_TCR
], env
->spr
[SPR_BOOKE_TSR
],
9441 env
->spr
[SPR_BOOKE_ESR
], env
->spr
[SPR_BOOKE_DEAR
]);
9443 cpu_fprintf(f
, " PIR " TARGET_FMT_lx
" DECAR " TARGET_FMT_lx
9444 " IVPR " TARGET_FMT_lx
" EPCR " TARGET_FMT_lx
"\n",
9445 env
->spr
[SPR_BOOKE_PIR
], env
->spr
[SPR_BOOKE_DECAR
],
9446 env
->spr
[SPR_BOOKE_IVPR
], env
->spr
[SPR_BOOKE_EPCR
]);
9448 cpu_fprintf(f
, " MCSR " TARGET_FMT_lx
" SPRG8 " TARGET_FMT_lx
9449 " EPR " TARGET_FMT_lx
"\n",
9450 env
->spr
[SPR_BOOKE_MCSR
], env
->spr
[SPR_BOOKE_SPRG8
],
9451 env
->spr
[SPR_BOOKE_EPR
]);
9454 cpu_fprintf(f
, " MCAR " TARGET_FMT_lx
" PID1 " TARGET_FMT_lx
9455 " PID2 " TARGET_FMT_lx
" SVR " TARGET_FMT_lx
"\n",
9456 env
->spr
[SPR_Exxx_MCAR
], env
->spr
[SPR_BOOKE_PID1
],
9457 env
->spr
[SPR_BOOKE_PID2
], env
->spr
[SPR_E500_SVR
]);
9460 * IVORs are left out as they are large and do not change often --
9461 * they can be read with "p $ivor0", "p $ivor1", etc.
9465 #if defined(TARGET_PPC64)
9466 if (env
->flags
& POWERPC_FLAG_CFAR
) {
9467 cpu_fprintf(f
, " CFAR " TARGET_FMT_lx
"\n", env
->cfar
);
9471 switch (env
->mmu_model
) {
9472 case POWERPC_MMU_32B
:
9473 case POWERPC_MMU_601
:
9474 case POWERPC_MMU_SOFT_6xx
:
9475 case POWERPC_MMU_SOFT_74xx
:
9476 #if defined(TARGET_PPC64)
9477 case POWERPC_MMU_620
:
9478 case POWERPC_MMU_64B
:
9480 cpu_fprintf(f
, " SDR1 " TARGET_FMT_lx
"\n", env
->spr
[SPR_SDR1
]);
9482 case POWERPC_MMU_BOOKE206
:
9483 cpu_fprintf(f
, " MAS0 " TARGET_FMT_lx
" MAS1 " TARGET_FMT_lx
9484 " MAS2 " TARGET_FMT_lx
" MAS3 " TARGET_FMT_lx
"\n",
9485 env
->spr
[SPR_BOOKE_MAS0
], env
->spr
[SPR_BOOKE_MAS1
],
9486 env
->spr
[SPR_BOOKE_MAS2
], env
->spr
[SPR_BOOKE_MAS3
]);
9488 cpu_fprintf(f
, " MAS4 " TARGET_FMT_lx
" MAS6 " TARGET_FMT_lx
9489 " MAS7 " TARGET_FMT_lx
" PID " TARGET_FMT_lx
"\n",
9490 env
->spr
[SPR_BOOKE_MAS4
], env
->spr
[SPR_BOOKE_MAS6
],
9491 env
->spr
[SPR_BOOKE_MAS7
], env
->spr
[SPR_BOOKE_PID
]);
9493 cpu_fprintf(f
, "MMUCFG " TARGET_FMT_lx
" TLB0CFG " TARGET_FMT_lx
9494 " TLB1CFG " TARGET_FMT_lx
"\n",
9495 env
->spr
[SPR_MMUCFG
], env
->spr
[SPR_BOOKE_TLB0CFG
],
9496 env
->spr
[SPR_BOOKE_TLB1CFG
]);
9507 void cpu_dump_statistics (CPUPPCState
*env
, FILE*f
, fprintf_function cpu_fprintf
,
9510 #if defined(DO_PPC_STATISTICS)
9511 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
9515 for (op1
= 0; op1
< 64; op1
++) {
9517 if (is_indirect_opcode(handler
)) {
9518 t2
= ind_table(handler
);
9519 for (op2
= 0; op2
< 32; op2
++) {
9521 if (is_indirect_opcode(handler
)) {
9522 t3
= ind_table(handler
);
9523 for (op3
= 0; op3
< 32; op3
++) {
9525 if (handler
->count
== 0)
9527 cpu_fprintf(f
, "%02x %02x %02x (%02x %04d) %16s: "
9528 "%016" PRIx64
" %" PRId64
"\n",
9529 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
9531 handler
->count
, handler
->count
);
9534 if (handler
->count
== 0)
9536 cpu_fprintf(f
, "%02x %02x (%02x %04d) %16s: "
9537 "%016" PRIx64
" %" PRId64
"\n",
9538 op1
, op2
, op1
, op2
, handler
->oname
,
9539 handler
->count
, handler
->count
);
9543 if (handler
->count
== 0)
9545 cpu_fprintf(f
, "%02x (%02x ) %16s: %016" PRIx64
9547 op1
, op1
, handler
->oname
,
9548 handler
->count
, handler
->count
);
9554 /*****************************************************************************/
9555 static inline void gen_intermediate_code_internal(CPUPPCState
*env
,
9556 TranslationBlock
*tb
,
9559 DisasContext ctx
, *ctxp
= &ctx
;
9560 opc_handler_t
**table
, *handler
;
9561 target_ulong pc_start
;
9562 uint16_t *gen_opc_end
;
9569 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
9572 ctx
.exception
= POWERPC_EXCP_NONE
;
9573 ctx
.spr_cb
= env
->spr_cb
;
9574 ctx
.mem_idx
= env
->mmu_idx
;
9575 ctx
.access_type
= -1;
9576 ctx
.le_mode
= env
->hflags
& (1 << MSR_LE
) ? 1 : 0;
9577 #if defined(TARGET_PPC64)
9578 ctx
.sf_mode
= msr_is_64bit(env
, env
->msr
);
9579 ctx
.has_cfar
= !!(env
->flags
& POWERPC_FLAG_CFAR
);
9581 ctx
.fpu_enabled
= msr_fp
;
9582 if ((env
->flags
& POWERPC_FLAG_SPE
) && msr_spe
)
9583 ctx
.spe_enabled
= msr_spe
;
9585 ctx
.spe_enabled
= 0;
9586 if ((env
->flags
& POWERPC_FLAG_VRE
) && msr_vr
)
9587 ctx
.altivec_enabled
= msr_vr
;
9589 ctx
.altivec_enabled
= 0;
9590 if ((env
->flags
& POWERPC_FLAG_SE
) && msr_se
)
9591 ctx
.singlestep_enabled
= CPU_SINGLE_STEP
;
9593 ctx
.singlestep_enabled
= 0;
9594 if ((env
->flags
& POWERPC_FLAG_BE
) && msr_be
)
9595 ctx
.singlestep_enabled
|= CPU_BRANCH_STEP
;
9596 if (unlikely(env
->singlestep_enabled
))
9597 ctx
.singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
9598 #if defined (DO_SINGLE_STEP) && 0
9599 /* Single step trace mode */
9603 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
9605 max_insns
= CF_COUNT_MASK
;
9608 /* Set env in case of segfault during code fetch */
9609 while (ctx
.exception
== POWERPC_EXCP_NONE
9610 && tcg_ctx
.gen_opc_ptr
< gen_opc_end
) {
9611 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
9612 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
9613 if (bp
->pc
== ctx
.nip
) {
9614 gen_debug_exception(ctxp
);
9619 if (unlikely(search_pc
)) {
9620 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
9624 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
9626 tcg_ctx
.gen_opc_pc
[lj
] = ctx
.nip
;
9627 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
9628 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
9630 LOG_DISAS("----------------\n");
9631 LOG_DISAS("nip=" TARGET_FMT_lx
" super=%d ir=%d\n",
9632 ctx
.nip
, ctx
.mem_idx
, (int)msr_ir
);
9633 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
9635 if (unlikely(ctx
.le_mode
)) {
9636 ctx
.opcode
= bswap32(cpu_ldl_code(env
, ctx
.nip
));
9638 ctx
.opcode
= cpu_ldl_code(env
, ctx
.nip
);
9640 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
9641 ctx
.opcode
, opc1(ctx
.opcode
), opc2(ctx
.opcode
),
9642 opc3(ctx
.opcode
), ctx
.le_mode
? "little" : "big");
9643 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
9644 tcg_gen_debug_insn_start(ctx
.nip
);
9647 table
= env
->opcodes
;
9649 handler
= table
[opc1(ctx
.opcode
)];
9650 if (is_indirect_opcode(handler
)) {
9651 table
= ind_table(handler
);
9652 handler
= table
[opc2(ctx
.opcode
)];
9653 if (is_indirect_opcode(handler
)) {
9654 table
= ind_table(handler
);
9655 handler
= table
[opc3(ctx
.opcode
)];
9658 /* Is opcode *REALLY* valid ? */
9659 if (unlikely(handler
->handler
== &gen_invalid
)) {
9660 if (qemu_log_enabled()) {
9661 qemu_log("invalid/unsupported opcode: "
9662 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx
" %d\n",
9663 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
9664 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
9669 if (unlikely(handler
->type
& (PPC_SPE
| PPC_SPE_SINGLE
| PPC_SPE_DOUBLE
) && Rc(ctx
.opcode
))) {
9670 inval
= handler
->inval2
;
9672 inval
= handler
->inval1
;
9675 if (unlikely((ctx
.opcode
& inval
) != 0)) {
9676 if (qemu_log_enabled()) {
9677 qemu_log("invalid bits: %08x for opcode: "
9678 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx
"\n",
9679 ctx
.opcode
& inval
, opc1(ctx
.opcode
),
9680 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
9681 ctx
.opcode
, ctx
.nip
- 4);
9683 gen_inval_exception(ctxp
, POWERPC_EXCP_INVAL_INVAL
);
9687 (*(handler
->handler
))(&ctx
);
9688 #if defined(DO_PPC_STATISTICS)
9691 /* Check trace mode exceptions */
9692 if (unlikely(ctx
.singlestep_enabled
& CPU_SINGLE_STEP
&&
9693 (ctx
.nip
<= 0x100 || ctx
.nip
> 0xF00) &&
9694 ctx
.exception
!= POWERPC_SYSCALL
&&
9695 ctx
.exception
!= POWERPC_EXCP_TRAP
&&
9696 ctx
.exception
!= POWERPC_EXCP_BRANCH
)) {
9697 gen_exception(ctxp
, POWERPC_EXCP_TRACE
);
9698 } else if (unlikely(((ctx
.nip
& (TARGET_PAGE_SIZE
- 1)) == 0) ||
9699 (env
->singlestep_enabled
) ||
9701 num_insns
>= max_insns
)) {
9702 /* if we reach a page boundary or are single stepping, stop
9708 if (tb
->cflags
& CF_LAST_IO
)
9710 if (ctx
.exception
== POWERPC_EXCP_NONE
) {
9711 gen_goto_tb(&ctx
, 0, ctx
.nip
);
9712 } else if (ctx
.exception
!= POWERPC_EXCP_BRANCH
) {
9713 if (unlikely(env
->singlestep_enabled
)) {
9714 gen_debug_exception(ctxp
);
9716 /* Generate the return instruction */
9719 gen_icount_end(tb
, num_insns
);
9720 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
9721 if (unlikely(search_pc
)) {
9722 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
9725 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
9727 tb
->size
= ctx
.nip
- pc_start
;
9728 tb
->icount
= num_insns
;
9730 #if defined(DEBUG_DISAS)
9731 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
9733 flags
= env
->bfd_mach
;
9734 flags
|= ctx
.le_mode
<< 16;
9735 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
9736 log_target_disas(env
, pc_start
, ctx
.nip
- pc_start
, flags
);
9742 void gen_intermediate_code (CPUPPCState
*env
, struct TranslationBlock
*tb
)
9744 gen_intermediate_code_internal(env
, tb
, 0);
9747 void gen_intermediate_code_pc (CPUPPCState
*env
, struct TranslationBlock
*tb
)
9749 gen_intermediate_code_internal(env
, tb
, 1);
9752 void restore_state_to_opc(CPUPPCState
*env
, TranslationBlock
*tb
, int pc_pos
)
9754 env
->nip
= tcg_ctx
.gen_opc_pc
[pc_pos
];