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
)
1039 TCGv_i32 t0
= tcg_temp_new_i32();
1040 TCGv_i32 t1
= tcg_temp_new_i32();
1042 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1043 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1044 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1045 tcg_gen_ext_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1047 tcg_gen_sari_i32(t0
, t0
, 31);
1048 tcg_gen_setcond_i32(TCG_COND_NE
, t0
, t0
, t1
);
1049 tcg_gen_extu_i32_tl(cpu_ov
, t0
);
1050 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1052 tcg_temp_free_i32(t0
);
1053 tcg_temp_free_i32(t1
);
1054 if (unlikely(Rc(ctx
->opcode
) != 0))
1055 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1059 static void gen_mulli(DisasContext
*ctx
)
1061 tcg_gen_muli_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1065 #if defined(TARGET_PPC64)
1067 static void gen_mulhd(DisasContext
*ctx
)
1069 TCGv lo
= tcg_temp_new();
1070 tcg_gen_muls2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1071 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1073 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1074 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1078 /* mulhdu mulhdu. */
1079 static void gen_mulhdu(DisasContext
*ctx
)
1081 TCGv lo
= tcg_temp_new();
1082 tcg_gen_mulu2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1083 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1085 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1086 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1091 static void gen_mulld(DisasContext
*ctx
)
1093 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1094 cpu_gpr
[rB(ctx
->opcode
)]);
1095 if (unlikely(Rc(ctx
->opcode
) != 0))
1096 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1099 /* mulldo mulldo. */
1100 static void gen_mulldo(DisasContext
*ctx
)
1102 gen_helper_mulldo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
1103 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1104 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1105 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1110 /* Common subf function */
1111 static inline void gen_op_arith_subf(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1112 TCGv arg2
, bool add_ca
, bool compute_ca
,
1113 bool compute_ov
, bool compute_rc0
)
1117 if (((add_ca
&& compute_ca
) || compute_ov
)
1118 && (TCGV_EQUAL(ret
, arg1
) || TCGV_EQUAL(ret
, arg2
))) {
1119 t0
= tcg_temp_new();
1123 /* dest = ~arg1 + arg2 + ca. */
1125 TCGv zero
, inv1
= tcg_temp_new();
1126 tcg_gen_not_tl(inv1
, arg1
);
1127 zero
= tcg_const_tl(0);
1128 tcg_gen_add2_tl(t0
, cpu_ca
, arg2
, zero
, cpu_ca
, zero
);
1129 tcg_gen_add2_tl(t0
, cpu_ca
, t0
, cpu_ca
, inv1
, zero
);
1130 tcg_temp_free(zero
);
1131 tcg_temp_free(inv1
);
1133 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1134 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
1135 tcg_gen_subi_tl(t0
, t0
, 1);
1139 tcg_gen_setcond_tl(TCG_COND_GEU
, cpu_ca
, arg2
, arg1
);
1141 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1145 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 1);
1147 if (unlikely(compute_rc0
)) {
1148 gen_set_Rc0(ctx
, t0
);
1151 if (!TCGV_EQUAL(t0
, ret
)) {
1152 tcg_gen_mov_tl(ret
, t0
);
1156 /* Sub functions with Two operands functions */
1157 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1158 static void glue(gen_, name)(DisasContext *ctx) \
1160 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1161 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1162 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1164 /* Sub functions with one operand and one immediate */
1165 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1166 add_ca, compute_ca, compute_ov) \
1167 static void glue(gen_, name)(DisasContext *ctx) \
1169 TCGv t0 = tcg_const_tl(const_val); \
1170 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1171 cpu_gpr[rA(ctx->opcode)], t0, \
1172 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1173 tcg_temp_free(t0); \
1175 /* subf subf. subfo subfo. */
1176 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
1177 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
1178 /* subfc subfc. subfco subfco. */
1179 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
1180 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
1181 /* subfe subfe. subfeo subfo. */
1182 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
1183 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
1184 /* subfme subfme. subfmeo subfmeo. */
1185 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
1186 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
1187 /* subfze subfze. subfzeo subfzeo.*/
1188 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
1189 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
1192 static void gen_subfic(DisasContext
*ctx
)
1194 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
1195 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1200 /* neg neg. nego nego. */
1201 static inline void gen_op_arith_neg(DisasContext
*ctx
, bool compute_ov
)
1203 TCGv zero
= tcg_const_tl(0);
1204 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1205 zero
, 0, 0, compute_ov
, Rc(ctx
->opcode
));
1206 tcg_temp_free(zero
);
1209 static void gen_neg(DisasContext
*ctx
)
1211 gen_op_arith_neg(ctx
, 0);
1214 static void gen_nego(DisasContext
*ctx
)
1216 gen_op_arith_neg(ctx
, 1);
1219 /*** Integer logical ***/
1220 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1221 static void glue(gen_, name)(DisasContext *ctx) \
1223 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1224 cpu_gpr[rB(ctx->opcode)]); \
1225 if (unlikely(Rc(ctx->opcode) != 0)) \
1226 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1229 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1230 static void glue(gen_, name)(DisasContext *ctx) \
1232 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1233 if (unlikely(Rc(ctx->opcode) != 0)) \
1234 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1238 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
);
1240 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
);
1243 static void gen_andi_(DisasContext
*ctx
)
1245 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
));
1246 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1250 static void gen_andis_(DisasContext
*ctx
)
1252 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
) << 16);
1253 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1257 static void gen_cntlzw(DisasContext
*ctx
)
1259 gen_helper_cntlzw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1260 if (unlikely(Rc(ctx
->opcode
) != 0))
1261 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1264 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
);
1265 /* extsb & extsb. */
1266 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
);
1267 /* extsh & extsh. */
1268 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
);
1270 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
);
1272 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
);
1275 static void gen_or(DisasContext
*ctx
)
1279 rs
= rS(ctx
->opcode
);
1280 ra
= rA(ctx
->opcode
);
1281 rb
= rB(ctx
->opcode
);
1282 /* Optimisation for mr. ri case */
1283 if (rs
!= ra
|| rs
!= rb
) {
1285 tcg_gen_or_tl(cpu_gpr
[ra
], cpu_gpr
[rs
], cpu_gpr
[rb
]);
1287 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rs
]);
1288 if (unlikely(Rc(ctx
->opcode
) != 0))
1289 gen_set_Rc0(ctx
, cpu_gpr
[ra
]);
1290 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
1291 gen_set_Rc0(ctx
, cpu_gpr
[rs
]);
1292 #if defined(TARGET_PPC64)
1298 /* Set process priority to low */
1302 /* Set process priority to medium-low */
1306 /* Set process priority to normal */
1309 #if !defined(CONFIG_USER_ONLY)
1311 if (ctx
->mem_idx
> 0) {
1312 /* Set process priority to very low */
1317 if (ctx
->mem_idx
> 0) {
1318 /* Set process priority to medium-hight */
1323 if (ctx
->mem_idx
> 0) {
1324 /* Set process priority to high */
1329 if (ctx
->mem_idx
> 1) {
1330 /* Set process priority to very high */
1340 TCGv t0
= tcg_temp_new();
1341 gen_load_spr(t0
, SPR_PPR
);
1342 tcg_gen_andi_tl(t0
, t0
, ~0x001C000000000000ULL
);
1343 tcg_gen_ori_tl(t0
, t0
, ((uint64_t)prio
) << 50);
1344 gen_store_spr(SPR_PPR
, t0
);
1351 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
);
1354 static void gen_xor(DisasContext
*ctx
)
1356 /* Optimisation for "set to zero" case */
1357 if (rS(ctx
->opcode
) != rB(ctx
->opcode
))
1358 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1360 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1361 if (unlikely(Rc(ctx
->opcode
) != 0))
1362 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1366 static void gen_ori(DisasContext
*ctx
)
1368 target_ulong uimm
= UIMM(ctx
->opcode
);
1370 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1372 /* XXX: should handle special NOPs for POWER series */
1375 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1379 static void gen_oris(DisasContext
*ctx
)
1381 target_ulong uimm
= UIMM(ctx
->opcode
);
1383 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1387 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1391 static void gen_xori(DisasContext
*ctx
)
1393 target_ulong uimm
= UIMM(ctx
->opcode
);
1395 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1399 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1403 static void gen_xoris(DisasContext
*ctx
)
1405 target_ulong uimm
= UIMM(ctx
->opcode
);
1407 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1411 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1414 /* popcntb : PowerPC 2.03 specification */
1415 static void gen_popcntb(DisasContext
*ctx
)
1417 gen_helper_popcntb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1420 static void gen_popcntw(DisasContext
*ctx
)
1422 gen_helper_popcntw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1425 #if defined(TARGET_PPC64)
1426 /* popcntd: PowerPC 2.06 specification */
1427 static void gen_popcntd(DisasContext
*ctx
)
1429 gen_helper_popcntd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1433 #if defined(TARGET_PPC64)
1434 /* extsw & extsw. */
1435 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
);
1438 static void gen_cntlzd(DisasContext
*ctx
)
1440 gen_helper_cntlzd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1441 if (unlikely(Rc(ctx
->opcode
) != 0))
1442 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1446 /*** Integer rotate ***/
1448 /* rlwimi & rlwimi. */
1449 static void gen_rlwimi(DisasContext
*ctx
)
1451 uint32_t mb
, me
, sh
;
1453 mb
= MB(ctx
->opcode
);
1454 me
= ME(ctx
->opcode
);
1455 sh
= SH(ctx
->opcode
);
1456 if (likely(sh
== 0 && mb
== 0 && me
== 31)) {
1457 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1461 TCGv t0
= tcg_temp_new();
1462 #if defined(TARGET_PPC64)
1463 TCGv_i32 t2
= tcg_temp_new_i32();
1464 tcg_gen_trunc_i64_i32(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
1465 tcg_gen_rotli_i32(t2
, t2
, sh
);
1466 tcg_gen_extu_i32_i64(t0
, t2
);
1467 tcg_temp_free_i32(t2
);
1469 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1471 #if defined(TARGET_PPC64)
1475 mask
= MASK(mb
, me
);
1476 t1
= tcg_temp_new();
1477 tcg_gen_andi_tl(t0
, t0
, mask
);
1478 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1479 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1483 if (unlikely(Rc(ctx
->opcode
) != 0))
1484 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1487 /* rlwinm & rlwinm. */
1488 static void gen_rlwinm(DisasContext
*ctx
)
1490 uint32_t mb
, me
, sh
;
1492 sh
= SH(ctx
->opcode
);
1493 mb
= MB(ctx
->opcode
);
1494 me
= ME(ctx
->opcode
);
1496 if (likely(mb
== 0 && me
== (31 - sh
))) {
1497 if (likely(sh
== 0)) {
1498 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1500 TCGv t0
= tcg_temp_new();
1501 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1502 tcg_gen_shli_tl(t0
, t0
, sh
);
1503 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1506 } else if (likely(sh
!= 0 && me
== 31 && sh
== (32 - mb
))) {
1507 TCGv t0
= tcg_temp_new();
1508 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1509 tcg_gen_shri_tl(t0
, t0
, mb
);
1510 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1513 TCGv t0
= tcg_temp_new();
1514 #if defined(TARGET_PPC64)
1515 TCGv_i32 t1
= tcg_temp_new_i32();
1516 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1517 tcg_gen_rotli_i32(t1
, t1
, sh
);
1518 tcg_gen_extu_i32_i64(t0
, t1
);
1519 tcg_temp_free_i32(t1
);
1521 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1523 #if defined(TARGET_PPC64)
1527 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1530 if (unlikely(Rc(ctx
->opcode
) != 0))
1531 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1534 /* rlwnm & rlwnm. */
1535 static void gen_rlwnm(DisasContext
*ctx
)
1539 #if defined(TARGET_PPC64)
1543 mb
= MB(ctx
->opcode
);
1544 me
= ME(ctx
->opcode
);
1545 t0
= tcg_temp_new();
1546 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1547 #if defined(TARGET_PPC64)
1548 t1
= tcg_temp_new_i32();
1549 t2
= tcg_temp_new_i32();
1550 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1551 tcg_gen_trunc_i64_i32(t2
, t0
);
1552 tcg_gen_rotl_i32(t1
, t1
, t2
);
1553 tcg_gen_extu_i32_i64(t0
, t1
);
1554 tcg_temp_free_i32(t1
);
1555 tcg_temp_free_i32(t2
);
1557 tcg_gen_rotl_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1559 if (unlikely(mb
!= 0 || me
!= 31)) {
1560 #if defined(TARGET_PPC64)
1564 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1566 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1569 if (unlikely(Rc(ctx
->opcode
) != 0))
1570 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1573 #if defined(TARGET_PPC64)
1574 #define GEN_PPC64_R2(name, opc1, opc2) \
1575 static void glue(gen_, name##0)(DisasContext *ctx) \
1577 gen_##name(ctx, 0); \
1580 static void glue(gen_, name##1)(DisasContext *ctx) \
1582 gen_##name(ctx, 1); \
1584 #define GEN_PPC64_R4(name, opc1, opc2) \
1585 static void glue(gen_, name##0)(DisasContext *ctx) \
1587 gen_##name(ctx, 0, 0); \
1590 static void glue(gen_, name##1)(DisasContext *ctx) \
1592 gen_##name(ctx, 0, 1); \
1595 static void glue(gen_, name##2)(DisasContext *ctx) \
1597 gen_##name(ctx, 1, 0); \
1600 static void glue(gen_, name##3)(DisasContext *ctx) \
1602 gen_##name(ctx, 1, 1); \
1605 static inline void gen_rldinm(DisasContext
*ctx
, uint32_t mb
, uint32_t me
,
1608 if (likely(sh
!= 0 && mb
== 0 && me
== (63 - sh
))) {
1609 tcg_gen_shli_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
1610 } else if (likely(sh
!= 0 && me
== 63 && sh
== (64 - mb
))) {
1611 tcg_gen_shri_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], mb
);
1613 TCGv t0
= tcg_temp_new();
1614 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1615 if (likely(mb
== 0 && me
== 63)) {
1616 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1618 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1622 if (unlikely(Rc(ctx
->opcode
) != 0))
1623 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1625 /* rldicl - rldicl. */
1626 static inline void gen_rldicl(DisasContext
*ctx
, int mbn
, int shn
)
1630 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1631 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1632 gen_rldinm(ctx
, mb
, 63, sh
);
1634 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
1635 /* rldicr - rldicr. */
1636 static inline void gen_rldicr(DisasContext
*ctx
, int men
, int shn
)
1640 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1641 me
= MB(ctx
->opcode
) | (men
<< 5);
1642 gen_rldinm(ctx
, 0, me
, sh
);
1644 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
1645 /* rldic - rldic. */
1646 static inline void gen_rldic(DisasContext
*ctx
, int mbn
, int shn
)
1650 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1651 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1652 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
1654 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
1656 static inline void gen_rldnm(DisasContext
*ctx
, uint32_t mb
, uint32_t me
)
1660 mb
= MB(ctx
->opcode
);
1661 me
= ME(ctx
->opcode
);
1662 t0
= tcg_temp_new();
1663 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1664 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1665 if (unlikely(mb
!= 0 || me
!= 63)) {
1666 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1668 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1671 if (unlikely(Rc(ctx
->opcode
) != 0))
1672 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1675 /* rldcl - rldcl. */
1676 static inline void gen_rldcl(DisasContext
*ctx
, int mbn
)
1680 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1681 gen_rldnm(ctx
, mb
, 63);
1683 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
1684 /* rldcr - rldcr. */
1685 static inline void gen_rldcr(DisasContext
*ctx
, int men
)
1689 me
= MB(ctx
->opcode
) | (men
<< 5);
1690 gen_rldnm(ctx
, 0, me
);
1692 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
1693 /* rldimi - rldimi. */
1694 static inline void gen_rldimi(DisasContext
*ctx
, int mbn
, int shn
)
1696 uint32_t sh
, mb
, me
;
1698 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1699 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1701 if (unlikely(sh
== 0 && mb
== 0)) {
1702 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1707 t0
= tcg_temp_new();
1708 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1709 t1
= tcg_temp_new();
1710 mask
= MASK(mb
, me
);
1711 tcg_gen_andi_tl(t0
, t0
, mask
);
1712 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1713 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1717 if (unlikely(Rc(ctx
->opcode
) != 0))
1718 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1720 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
1723 /*** Integer shift ***/
1726 static void gen_slw(DisasContext
*ctx
)
1730 t0
= tcg_temp_new();
1731 /* AND rS with a mask that is 0 when rB >= 0x20 */
1732 #if defined(TARGET_PPC64)
1733 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
1734 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1736 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
1737 tcg_gen_sari_tl(t0
, t0
, 0x1f);
1739 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1740 t1
= tcg_temp_new();
1741 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1742 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1745 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
1746 if (unlikely(Rc(ctx
->opcode
) != 0))
1747 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1751 static void gen_sraw(DisasContext
*ctx
)
1753 gen_helper_sraw(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
1754 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1755 if (unlikely(Rc(ctx
->opcode
) != 0))
1756 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1759 /* srawi & srawi. */
1760 static void gen_srawi(DisasContext
*ctx
)
1762 int sh
= SH(ctx
->opcode
);
1763 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
1764 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
1766 tcg_gen_mov_tl(dst
, src
);
1767 tcg_gen_movi_tl(cpu_ca
, 0);
1770 tcg_gen_ext32s_tl(dst
, src
);
1771 tcg_gen_andi_tl(cpu_ca
, dst
, (1ULL << sh
) - 1);
1772 t0
= tcg_temp_new();
1773 tcg_gen_sari_tl(t0
, dst
, TARGET_LONG_BITS
- 1);
1774 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
1776 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
1777 tcg_gen_sari_tl(dst
, dst
, sh
);
1779 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1780 gen_set_Rc0(ctx
, dst
);
1785 static void gen_srw(DisasContext
*ctx
)
1789 t0
= tcg_temp_new();
1790 /* AND rS with a mask that is 0 when rB >= 0x20 */
1791 #if defined(TARGET_PPC64)
1792 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
1793 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1795 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
1796 tcg_gen_sari_tl(t0
, t0
, 0x1f);
1798 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1799 tcg_gen_ext32u_tl(t0
, t0
);
1800 t1
= tcg_temp_new();
1801 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1802 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1805 if (unlikely(Rc(ctx
->opcode
) != 0))
1806 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1809 #if defined(TARGET_PPC64)
1811 static void gen_sld(DisasContext
*ctx
)
1815 t0
= tcg_temp_new();
1816 /* AND rS with a mask that is 0 when rB >= 0x40 */
1817 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
1818 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1819 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1820 t1
= tcg_temp_new();
1821 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1822 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1825 if (unlikely(Rc(ctx
->opcode
) != 0))
1826 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1830 static void gen_srad(DisasContext
*ctx
)
1832 gen_helper_srad(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
1833 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1834 if (unlikely(Rc(ctx
->opcode
) != 0))
1835 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1837 /* sradi & sradi. */
1838 static inline void gen_sradi(DisasContext
*ctx
, int n
)
1840 int sh
= SH(ctx
->opcode
) + (n
<< 5);
1841 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
1842 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
1844 tcg_gen_mov_tl(dst
, src
);
1845 tcg_gen_movi_tl(cpu_ca
, 0);
1848 tcg_gen_andi_tl(cpu_ca
, src
, (1ULL << sh
) - 1);
1849 t0
= tcg_temp_new();
1850 tcg_gen_sari_tl(t0
, src
, TARGET_LONG_BITS
- 1);
1851 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
1853 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
1854 tcg_gen_sari_tl(dst
, src
, sh
);
1856 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1857 gen_set_Rc0(ctx
, dst
);
1861 static void gen_sradi0(DisasContext
*ctx
)
1866 static void gen_sradi1(DisasContext
*ctx
)
1872 static void gen_srd(DisasContext
*ctx
)
1876 t0
= tcg_temp_new();
1877 /* AND rS with a mask that is 0 when rB >= 0x40 */
1878 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
1879 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1880 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1881 t1
= tcg_temp_new();
1882 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1883 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1886 if (unlikely(Rc(ctx
->opcode
) != 0))
1887 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1891 /*** Floating-Point arithmetic ***/
1892 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
1893 static void gen_f##name(DisasContext *ctx) \
1895 if (unlikely(!ctx->fpu_enabled)) { \
1896 gen_exception(ctx, POWERPC_EXCP_FPU); \
1899 /* NIP cannot be restored if the memory exception comes from an helper */ \
1900 gen_update_nip(ctx, ctx->nip - 4); \
1901 gen_reset_fpstatus(); \
1902 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1903 cpu_fpr[rA(ctx->opcode)], \
1904 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
1906 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1907 cpu_fpr[rD(ctx->opcode)]); \
1909 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \
1910 Rc(ctx->opcode) != 0); \
1913 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
1914 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
1915 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
1917 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
1918 static void gen_f##name(DisasContext *ctx) \
1920 if (unlikely(!ctx->fpu_enabled)) { \
1921 gen_exception(ctx, POWERPC_EXCP_FPU); \
1924 /* NIP cannot be restored if the memory exception comes from an helper */ \
1925 gen_update_nip(ctx, ctx->nip - 4); \
1926 gen_reset_fpstatus(); \
1927 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1928 cpu_fpr[rA(ctx->opcode)], \
1929 cpu_fpr[rB(ctx->opcode)]); \
1931 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1932 cpu_fpr[rD(ctx->opcode)]); \
1934 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
1935 set_fprf, Rc(ctx->opcode) != 0); \
1937 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
1938 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
1939 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
1941 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
1942 static void gen_f##name(DisasContext *ctx) \
1944 if (unlikely(!ctx->fpu_enabled)) { \
1945 gen_exception(ctx, POWERPC_EXCP_FPU); \
1948 /* NIP cannot be restored if the memory exception comes from an helper */ \
1949 gen_update_nip(ctx, ctx->nip - 4); \
1950 gen_reset_fpstatus(); \
1951 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1952 cpu_fpr[rA(ctx->opcode)], \
1953 cpu_fpr[rC(ctx->opcode)]); \
1955 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1956 cpu_fpr[rD(ctx->opcode)]); \
1958 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
1959 set_fprf, Rc(ctx->opcode) != 0); \
1961 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
1962 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
1963 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
1965 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
1966 static void gen_f##name(DisasContext *ctx) \
1968 if (unlikely(!ctx->fpu_enabled)) { \
1969 gen_exception(ctx, POWERPC_EXCP_FPU); \
1972 /* NIP cannot be restored if the memory exception comes from an helper */ \
1973 gen_update_nip(ctx, ctx->nip - 4); \
1974 gen_reset_fpstatus(); \
1975 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1976 cpu_fpr[rB(ctx->opcode)]); \
1977 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
1978 set_fprf, Rc(ctx->opcode) != 0); \
1981 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
1982 static void gen_f##name(DisasContext *ctx) \
1984 if (unlikely(!ctx->fpu_enabled)) { \
1985 gen_exception(ctx, POWERPC_EXCP_FPU); \
1988 /* NIP cannot be restored if the memory exception comes from an helper */ \
1989 gen_update_nip(ctx, ctx->nip - 4); \
1990 gen_reset_fpstatus(); \
1991 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1992 cpu_fpr[rB(ctx->opcode)]); \
1993 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
1994 set_fprf, Rc(ctx->opcode) != 0); \
1998 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
);
2000 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
);
2002 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
);
2005 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
);
2008 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
);
2011 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
);
2014 static void gen_frsqrtes(DisasContext
*ctx
)
2016 if (unlikely(!ctx
->fpu_enabled
)) {
2017 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2020 /* NIP cannot be restored if the memory exception comes from an helper */
2021 gen_update_nip(ctx
, ctx
->nip
- 4);
2022 gen_reset_fpstatus();
2023 gen_helper_frsqrte(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2024 cpu_fpr
[rB(ctx
->opcode
)]);
2025 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2026 cpu_fpr
[rD(ctx
->opcode
)]);
2027 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2031 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
);
2033 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
);
2037 static void gen_fsqrt(DisasContext
*ctx
)
2039 if (unlikely(!ctx
->fpu_enabled
)) {
2040 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2043 /* NIP cannot be restored if the memory exception comes from an helper */
2044 gen_update_nip(ctx
, ctx
->nip
- 4);
2045 gen_reset_fpstatus();
2046 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2047 cpu_fpr
[rB(ctx
->opcode
)]);
2048 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2051 static void gen_fsqrts(DisasContext
*ctx
)
2053 if (unlikely(!ctx
->fpu_enabled
)) {
2054 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2057 /* NIP cannot be restored if the memory exception comes from an helper */
2058 gen_update_nip(ctx
, ctx
->nip
- 4);
2059 gen_reset_fpstatus();
2060 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2061 cpu_fpr
[rB(ctx
->opcode
)]);
2062 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2063 cpu_fpr
[rD(ctx
->opcode
)]);
2064 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2067 /*** Floating-Point multiply-and-add ***/
2068 /* fmadd - fmadds */
2069 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
);
2070 /* fmsub - fmsubs */
2071 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
);
2072 /* fnmadd - fnmadds */
2073 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
);
2074 /* fnmsub - fnmsubs */
2075 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
);
2077 /*** Floating-Point round & convert ***/
2079 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
);
2081 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
);
2083 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
);
2084 #if defined(TARGET_PPC64)
2086 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
);
2088 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
);
2090 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
);
2094 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
);
2096 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
);
2098 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
);
2100 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
);
2102 /*** Floating-Point compare ***/
2105 static void gen_fcmpo(DisasContext
*ctx
)
2108 if (unlikely(!ctx
->fpu_enabled
)) {
2109 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2112 /* NIP cannot be restored if the memory exception comes from an helper */
2113 gen_update_nip(ctx
, ctx
->nip
- 4);
2114 gen_reset_fpstatus();
2115 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2116 gen_helper_fcmpo(cpu_env
, cpu_fpr
[rA(ctx
->opcode
)],
2117 cpu_fpr
[rB(ctx
->opcode
)], crf
);
2118 tcg_temp_free_i32(crf
);
2119 gen_helper_float_check_status(cpu_env
);
2123 static void gen_fcmpu(DisasContext
*ctx
)
2126 if (unlikely(!ctx
->fpu_enabled
)) {
2127 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2130 /* NIP cannot be restored if the memory exception comes from an helper */
2131 gen_update_nip(ctx
, ctx
->nip
- 4);
2132 gen_reset_fpstatus();
2133 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2134 gen_helper_fcmpu(cpu_env
, cpu_fpr
[rA(ctx
->opcode
)],
2135 cpu_fpr
[rB(ctx
->opcode
)], crf
);
2136 tcg_temp_free_i32(crf
);
2137 gen_helper_float_check_status(cpu_env
);
2140 /*** Floating-point move ***/
2142 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2143 GEN_FLOAT_B(abs
, 0x08, 0x08, 0, PPC_FLOAT
);
2146 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2147 static void gen_fmr(DisasContext
*ctx
)
2149 if (unlikely(!ctx
->fpu_enabled
)) {
2150 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2153 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2154 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2158 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2159 GEN_FLOAT_B(nabs
, 0x08, 0x04, 0, PPC_FLOAT
);
2161 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2162 GEN_FLOAT_B(neg
, 0x08, 0x01, 0, PPC_FLOAT
);
2164 /*** Floating-Point status & ctrl register ***/
2167 static void gen_mcrfs(DisasContext
*ctx
)
2169 TCGv tmp
= tcg_temp_new();
2172 if (unlikely(!ctx
->fpu_enabled
)) {
2173 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2176 bfa
= 4 * (7 - crfS(ctx
->opcode
));
2177 tcg_gen_shri_tl(tmp
, cpu_fpscr
, bfa
);
2178 tcg_gen_trunc_tl_i32(cpu_crf
[crfD(ctx
->opcode
)], tmp
);
2180 tcg_gen_andi_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfD(ctx
->opcode
)], 0xf);
2181 tcg_gen_andi_tl(cpu_fpscr
, cpu_fpscr
, ~(0xF << bfa
));
2185 static void gen_mffs(DisasContext
*ctx
)
2187 if (unlikely(!ctx
->fpu_enabled
)) {
2188 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2191 gen_reset_fpstatus();
2192 tcg_gen_extu_tl_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpscr
);
2193 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2197 static void gen_mtfsb0(DisasContext
*ctx
)
2201 if (unlikely(!ctx
->fpu_enabled
)) {
2202 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2205 crb
= 31 - crbD(ctx
->opcode
);
2206 gen_reset_fpstatus();
2207 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
)) {
2209 /* NIP cannot be restored if the memory exception comes from an helper */
2210 gen_update_nip(ctx
, ctx
->nip
- 4);
2211 t0
= tcg_const_i32(crb
);
2212 gen_helper_fpscr_clrbit(cpu_env
, t0
);
2213 tcg_temp_free_i32(t0
);
2215 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2216 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2217 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2222 static void gen_mtfsb1(DisasContext
*ctx
)
2226 if (unlikely(!ctx
->fpu_enabled
)) {
2227 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2230 crb
= 31 - crbD(ctx
->opcode
);
2231 gen_reset_fpstatus();
2232 /* XXX: we pretend we can only do IEEE floating-point computations */
2233 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
&& crb
!= FPSCR_NI
)) {
2235 /* NIP cannot be restored if the memory exception comes from an helper */
2236 gen_update_nip(ctx
, ctx
->nip
- 4);
2237 t0
= tcg_const_i32(crb
);
2238 gen_helper_fpscr_setbit(cpu_env
, t0
);
2239 tcg_temp_free_i32(t0
);
2241 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2242 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2243 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2245 /* We can raise a differed exception */
2246 gen_helper_float_check_status(cpu_env
);
2250 static void gen_mtfsf(DisasContext
*ctx
)
2253 int L
= ctx
->opcode
& 0x02000000;
2255 if (unlikely(!ctx
->fpu_enabled
)) {
2256 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2259 /* NIP cannot be restored if the memory exception comes from an helper */
2260 gen_update_nip(ctx
, ctx
->nip
- 4);
2261 gen_reset_fpstatus();
2263 t0
= tcg_const_i32(0xff);
2265 t0
= tcg_const_i32(FM(ctx
->opcode
));
2266 gen_helper_store_fpscr(cpu_env
, cpu_fpr
[rB(ctx
->opcode
)], t0
);
2267 tcg_temp_free_i32(t0
);
2268 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2269 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2270 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2272 /* We can raise a differed exception */
2273 gen_helper_float_check_status(cpu_env
);
2277 static void gen_mtfsfi(DisasContext
*ctx
)
2283 if (unlikely(!ctx
->fpu_enabled
)) {
2284 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2287 bf
= crbD(ctx
->opcode
) >> 2;
2289 /* NIP cannot be restored if the memory exception comes from an helper */
2290 gen_update_nip(ctx
, ctx
->nip
- 4);
2291 gen_reset_fpstatus();
2292 t0
= tcg_const_i64(FPIMM(ctx
->opcode
) << (4 * sh
));
2293 t1
= tcg_const_i32(1 << sh
);
2294 gen_helper_store_fpscr(cpu_env
, t0
, t1
);
2295 tcg_temp_free_i64(t0
);
2296 tcg_temp_free_i32(t1
);
2297 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2298 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2299 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2301 /* We can raise a differed exception */
2302 gen_helper_float_check_status(cpu_env
);
2305 /*** Addressing modes ***/
2306 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2307 static inline void gen_addr_imm_index(DisasContext
*ctx
, TCGv EA
,
2310 target_long simm
= SIMM(ctx
->opcode
);
2313 if (rA(ctx
->opcode
) == 0) {
2314 #if defined(TARGET_PPC64)
2315 if (!ctx
->sf_mode
) {
2316 tcg_gen_movi_tl(EA
, (uint32_t)simm
);
2319 tcg_gen_movi_tl(EA
, simm
);
2320 } else if (likely(simm
!= 0)) {
2321 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
);
2322 #if defined(TARGET_PPC64)
2323 if (!ctx
->sf_mode
) {
2324 tcg_gen_ext32u_tl(EA
, EA
);
2328 #if defined(TARGET_PPC64)
2329 if (!ctx
->sf_mode
) {
2330 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2333 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2337 static inline void gen_addr_reg_index(DisasContext
*ctx
, TCGv EA
)
2339 if (rA(ctx
->opcode
) == 0) {
2340 #if defined(TARGET_PPC64)
2341 if (!ctx
->sf_mode
) {
2342 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2345 tcg_gen_mov_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2347 tcg_gen_add_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2348 #if defined(TARGET_PPC64)
2349 if (!ctx
->sf_mode
) {
2350 tcg_gen_ext32u_tl(EA
, EA
);
2356 static inline void gen_addr_register(DisasContext
*ctx
, TCGv EA
)
2358 if (rA(ctx
->opcode
) == 0) {
2359 tcg_gen_movi_tl(EA
, 0);
2361 #if defined(TARGET_PPC64)
2362 if (!ctx
->sf_mode
) {
2363 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2366 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2370 static inline void gen_addr_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
2373 tcg_gen_addi_tl(ret
, arg1
, val
);
2374 #if defined(TARGET_PPC64)
2375 if (!ctx
->sf_mode
) {
2376 tcg_gen_ext32u_tl(ret
, ret
);
2381 static inline void gen_check_align(DisasContext
*ctx
, TCGv EA
, int mask
)
2383 int l1
= gen_new_label();
2384 TCGv t0
= tcg_temp_new();
2386 /* NIP cannot be restored if the memory exception comes from an helper */
2387 gen_update_nip(ctx
, ctx
->nip
- 4);
2388 tcg_gen_andi_tl(t0
, EA
, mask
);
2389 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2390 t1
= tcg_const_i32(POWERPC_EXCP_ALIGN
);
2391 t2
= tcg_const_i32(0);
2392 gen_helper_raise_exception_err(cpu_env
, t1
, t2
);
2393 tcg_temp_free_i32(t1
);
2394 tcg_temp_free_i32(t2
);
2399 /*** Integer load ***/
2400 static inline void gen_qemu_ld8u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2402 tcg_gen_qemu_ld8u(arg1
, arg2
, ctx
->mem_idx
);
2405 static inline void gen_qemu_ld8s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2407 tcg_gen_qemu_ld8s(arg1
, arg2
, ctx
->mem_idx
);
2410 static inline void gen_qemu_ld16u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2412 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2413 if (unlikely(ctx
->le_mode
)) {
2414 tcg_gen_bswap16_tl(arg1
, arg1
);
2418 static inline void gen_qemu_ld16s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2420 if (unlikely(ctx
->le_mode
)) {
2421 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2422 tcg_gen_bswap16_tl(arg1
, arg1
);
2423 tcg_gen_ext16s_tl(arg1
, arg1
);
2425 tcg_gen_qemu_ld16s(arg1
, arg2
, ctx
->mem_idx
);
2429 static inline void gen_qemu_ld32u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2431 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2432 if (unlikely(ctx
->le_mode
)) {
2433 tcg_gen_bswap32_tl(arg1
, arg1
);
2437 #if defined(TARGET_PPC64)
2438 static inline void gen_qemu_ld32s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2440 if (unlikely(ctx
->le_mode
)) {
2441 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2442 tcg_gen_bswap32_tl(arg1
, arg1
);
2443 tcg_gen_ext32s_tl(arg1
, arg1
);
2445 tcg_gen_qemu_ld32s(arg1
, arg2
, ctx
->mem_idx
);
2449 static inline void gen_qemu_ld64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2451 tcg_gen_qemu_ld64(arg1
, arg2
, ctx
->mem_idx
);
2452 if (unlikely(ctx
->le_mode
)) {
2453 tcg_gen_bswap64_i64(arg1
, arg1
);
2457 static inline void gen_qemu_st8(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2459 tcg_gen_qemu_st8(arg1
, arg2
, ctx
->mem_idx
);
2462 static inline void gen_qemu_st16(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2464 if (unlikely(ctx
->le_mode
)) {
2465 TCGv t0
= tcg_temp_new();
2466 tcg_gen_ext16u_tl(t0
, arg1
);
2467 tcg_gen_bswap16_tl(t0
, t0
);
2468 tcg_gen_qemu_st16(t0
, arg2
, ctx
->mem_idx
);
2471 tcg_gen_qemu_st16(arg1
, arg2
, ctx
->mem_idx
);
2475 static inline void gen_qemu_st32(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2477 if (unlikely(ctx
->le_mode
)) {
2478 TCGv t0
= tcg_temp_new();
2479 tcg_gen_ext32u_tl(t0
, arg1
);
2480 tcg_gen_bswap32_tl(t0
, t0
);
2481 tcg_gen_qemu_st32(t0
, arg2
, ctx
->mem_idx
);
2484 tcg_gen_qemu_st32(arg1
, arg2
, ctx
->mem_idx
);
2488 static inline void gen_qemu_st64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2490 if (unlikely(ctx
->le_mode
)) {
2491 TCGv_i64 t0
= tcg_temp_new_i64();
2492 tcg_gen_bswap64_i64(t0
, arg1
);
2493 tcg_gen_qemu_st64(t0
, arg2
, ctx
->mem_idx
);
2494 tcg_temp_free_i64(t0
);
2496 tcg_gen_qemu_st64(arg1
, arg2
, ctx
->mem_idx
);
2499 #define GEN_LD(name, ldop, opc, type) \
2500 static void glue(gen_, name)(DisasContext *ctx) \
2503 gen_set_access_type(ctx, ACCESS_INT); \
2504 EA = tcg_temp_new(); \
2505 gen_addr_imm_index(ctx, EA, 0); \
2506 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2507 tcg_temp_free(EA); \
2510 #define GEN_LDU(name, ldop, opc, type) \
2511 static void glue(gen_, name##u)(DisasContext *ctx) \
2514 if (unlikely(rA(ctx->opcode) == 0 || \
2515 rA(ctx->opcode) == rD(ctx->opcode))) { \
2516 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2519 gen_set_access_type(ctx, ACCESS_INT); \
2520 EA = tcg_temp_new(); \
2521 if (type == PPC_64B) \
2522 gen_addr_imm_index(ctx, EA, 0x03); \
2524 gen_addr_imm_index(ctx, EA, 0); \
2525 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2526 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2527 tcg_temp_free(EA); \
2530 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
2531 static void glue(gen_, name##ux)(DisasContext *ctx) \
2534 if (unlikely(rA(ctx->opcode) == 0 || \
2535 rA(ctx->opcode) == rD(ctx->opcode))) { \
2536 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2539 gen_set_access_type(ctx, ACCESS_INT); \
2540 EA = tcg_temp_new(); \
2541 gen_addr_reg_index(ctx, EA); \
2542 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2543 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2544 tcg_temp_free(EA); \
2547 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
2548 static void glue(gen_, name##x)(DisasContext *ctx) \
2551 gen_set_access_type(ctx, ACCESS_INT); \
2552 EA = tcg_temp_new(); \
2553 gen_addr_reg_index(ctx, EA); \
2554 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2555 tcg_temp_free(EA); \
2557 #define GEN_LDX(name, ldop, opc2, opc3, type) \
2558 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE)
2560 #define GEN_LDS(name, ldop, op, type) \
2561 GEN_LD(name, ldop, op | 0x20, type); \
2562 GEN_LDU(name, ldop, op | 0x21, type); \
2563 GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2564 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
2566 /* lbz lbzu lbzux lbzx */
2567 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
);
2568 /* lha lhau lhaux lhax */
2569 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
);
2570 /* lhz lhzu lhzux lhzx */
2571 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
);
2572 /* lwz lwzu lwzux lwzx */
2573 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
);
2574 #if defined(TARGET_PPC64)
2576 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
);
2578 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
);
2580 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
);
2582 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
);
2584 static void gen_ld(DisasContext
*ctx
)
2587 if (Rc(ctx
->opcode
)) {
2588 if (unlikely(rA(ctx
->opcode
) == 0 ||
2589 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
2590 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2594 gen_set_access_type(ctx
, ACCESS_INT
);
2595 EA
= tcg_temp_new();
2596 gen_addr_imm_index(ctx
, EA
, 0x03);
2597 if (ctx
->opcode
& 0x02) {
2598 /* lwa (lwau is undefined) */
2599 gen_qemu_ld32s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2602 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2604 if (Rc(ctx
->opcode
))
2605 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2610 static void gen_lq(DisasContext
*ctx
)
2612 #if defined(CONFIG_USER_ONLY)
2613 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2618 /* Restore CPU state */
2619 if (unlikely(ctx
->mem_idx
== 0)) {
2620 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2623 ra
= rA(ctx
->opcode
);
2624 rd
= rD(ctx
->opcode
);
2625 if (unlikely((rd
& 1) || rd
== ra
)) {
2626 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2629 if (unlikely(ctx
->le_mode
)) {
2630 /* Little-endian mode is not handled */
2631 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2634 gen_set_access_type(ctx
, ACCESS_INT
);
2635 EA
= tcg_temp_new();
2636 gen_addr_imm_index(ctx
, EA
, 0x0F);
2637 gen_qemu_ld64(ctx
, cpu_gpr
[rd
], EA
);
2638 gen_addr_add(ctx
, EA
, EA
, 8);
2639 gen_qemu_ld64(ctx
, cpu_gpr
[rd
+1], EA
);
2645 /*** Integer store ***/
2646 #define GEN_ST(name, stop, opc, type) \
2647 static void glue(gen_, name)(DisasContext *ctx) \
2650 gen_set_access_type(ctx, ACCESS_INT); \
2651 EA = tcg_temp_new(); \
2652 gen_addr_imm_index(ctx, EA, 0); \
2653 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2654 tcg_temp_free(EA); \
2657 #define GEN_STU(name, stop, opc, type) \
2658 static void glue(gen_, stop##u)(DisasContext *ctx) \
2661 if (unlikely(rA(ctx->opcode) == 0)) { \
2662 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2665 gen_set_access_type(ctx, ACCESS_INT); \
2666 EA = tcg_temp_new(); \
2667 if (type == PPC_64B) \
2668 gen_addr_imm_index(ctx, EA, 0x03); \
2670 gen_addr_imm_index(ctx, EA, 0); \
2671 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2672 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2673 tcg_temp_free(EA); \
2676 #define GEN_STUX(name, stop, opc2, opc3, type) \
2677 static void glue(gen_, name##ux)(DisasContext *ctx) \
2680 if (unlikely(rA(ctx->opcode) == 0)) { \
2681 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2684 gen_set_access_type(ctx, ACCESS_INT); \
2685 EA = tcg_temp_new(); \
2686 gen_addr_reg_index(ctx, EA); \
2687 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2688 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2689 tcg_temp_free(EA); \
2692 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
2693 static void glue(gen_, name##x)(DisasContext *ctx) \
2696 gen_set_access_type(ctx, ACCESS_INT); \
2697 EA = tcg_temp_new(); \
2698 gen_addr_reg_index(ctx, EA); \
2699 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2700 tcg_temp_free(EA); \
2702 #define GEN_STX(name, stop, opc2, opc3, type) \
2703 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE)
2705 #define GEN_STS(name, stop, op, type) \
2706 GEN_ST(name, stop, op | 0x20, type); \
2707 GEN_STU(name, stop, op | 0x21, type); \
2708 GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2709 GEN_STX(name, stop, 0x17, op | 0x00, type)
2711 /* stb stbu stbux stbx */
2712 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
);
2713 /* sth sthu sthux sthx */
2714 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
);
2715 /* stw stwu stwux stwx */
2716 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
);
2717 #if defined(TARGET_PPC64)
2718 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
);
2719 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
);
2721 static void gen_std(DisasContext
*ctx
)
2726 rs
= rS(ctx
->opcode
);
2727 if ((ctx
->opcode
& 0x3) == 0x2) {
2728 #if defined(CONFIG_USER_ONLY)
2729 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2732 if (unlikely(ctx
->mem_idx
== 0)) {
2733 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2736 if (unlikely(rs
& 1)) {
2737 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2740 if (unlikely(ctx
->le_mode
)) {
2741 /* Little-endian mode is not handled */
2742 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2745 gen_set_access_type(ctx
, ACCESS_INT
);
2746 EA
= tcg_temp_new();
2747 gen_addr_imm_index(ctx
, EA
, 0x03);
2748 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
2749 gen_addr_add(ctx
, EA
, EA
, 8);
2750 gen_qemu_st64(ctx
, cpu_gpr
[rs
+1], EA
);
2755 if (Rc(ctx
->opcode
)) {
2756 if (unlikely(rA(ctx
->opcode
) == 0)) {
2757 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2761 gen_set_access_type(ctx
, ACCESS_INT
);
2762 EA
= tcg_temp_new();
2763 gen_addr_imm_index(ctx
, EA
, 0x03);
2764 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
2765 if (Rc(ctx
->opcode
))
2766 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2771 /*** Integer load and store with byte reverse ***/
2773 static inline void gen_qemu_ld16ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2775 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2776 if (likely(!ctx
->le_mode
)) {
2777 tcg_gen_bswap16_tl(arg1
, arg1
);
2780 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
);
2783 static inline void gen_qemu_ld32ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2785 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2786 if (likely(!ctx
->le_mode
)) {
2787 tcg_gen_bswap32_tl(arg1
, arg1
);
2790 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
);
2792 #if defined(TARGET_PPC64)
2794 static inline void gen_qemu_ld64ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2796 tcg_gen_qemu_ld64(arg1
, arg2
, ctx
->mem_idx
);
2797 if (likely(!ctx
->le_mode
)) {
2798 tcg_gen_bswap64_tl(arg1
, arg1
);
2801 GEN_LDX_E(ldbr
, ld64ur
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
);
2802 #endif /* TARGET_PPC64 */
2805 static inline void gen_qemu_st16r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2807 if (likely(!ctx
->le_mode
)) {
2808 TCGv t0
= tcg_temp_new();
2809 tcg_gen_ext16u_tl(t0
, arg1
);
2810 tcg_gen_bswap16_tl(t0
, t0
);
2811 tcg_gen_qemu_st16(t0
, arg2
, ctx
->mem_idx
);
2814 tcg_gen_qemu_st16(arg1
, arg2
, ctx
->mem_idx
);
2817 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
);
2820 static inline void gen_qemu_st32r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2822 if (likely(!ctx
->le_mode
)) {
2823 TCGv t0
= tcg_temp_new();
2824 tcg_gen_ext32u_tl(t0
, arg1
);
2825 tcg_gen_bswap32_tl(t0
, t0
);
2826 tcg_gen_qemu_st32(t0
, arg2
, ctx
->mem_idx
);
2829 tcg_gen_qemu_st32(arg1
, arg2
, ctx
->mem_idx
);
2832 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
);
2834 #if defined(TARGET_PPC64)
2836 static inline void gen_qemu_st64r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2838 if (likely(!ctx
->le_mode
)) {
2839 TCGv t0
= tcg_temp_new();
2840 tcg_gen_bswap64_tl(t0
, arg1
);
2841 tcg_gen_qemu_st64(t0
, arg2
, ctx
->mem_idx
);
2844 tcg_gen_qemu_st64(arg1
, arg2
, ctx
->mem_idx
);
2847 GEN_STX_E(stdbr
, st64r
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
);
2848 #endif /* TARGET_PPC64 */
2850 /*** Integer load and store multiple ***/
2853 static void gen_lmw(DisasContext
*ctx
)
2857 gen_set_access_type(ctx
, ACCESS_INT
);
2858 /* NIP cannot be restored if the memory exception comes from an helper */
2859 gen_update_nip(ctx
, ctx
->nip
- 4);
2860 t0
= tcg_temp_new();
2861 t1
= tcg_const_i32(rD(ctx
->opcode
));
2862 gen_addr_imm_index(ctx
, t0
, 0);
2863 gen_helper_lmw(cpu_env
, t0
, t1
);
2865 tcg_temp_free_i32(t1
);
2869 static void gen_stmw(DisasContext
*ctx
)
2873 gen_set_access_type(ctx
, ACCESS_INT
);
2874 /* NIP cannot be restored if the memory exception comes from an helper */
2875 gen_update_nip(ctx
, ctx
->nip
- 4);
2876 t0
= tcg_temp_new();
2877 t1
= tcg_const_i32(rS(ctx
->opcode
));
2878 gen_addr_imm_index(ctx
, t0
, 0);
2879 gen_helper_stmw(cpu_env
, t0
, t1
);
2881 tcg_temp_free_i32(t1
);
2884 /*** Integer load and store strings ***/
2887 /* PowerPC32 specification says we must generate an exception if
2888 * rA is in the range of registers to be loaded.
2889 * In an other hand, IBM says this is valid, but rA won't be loaded.
2890 * For now, I'll follow the spec...
2892 static void gen_lswi(DisasContext
*ctx
)
2896 int nb
= NB(ctx
->opcode
);
2897 int start
= rD(ctx
->opcode
);
2898 int ra
= rA(ctx
->opcode
);
2904 if (unlikely(((start
+ nr
) > 32 &&
2905 start
<= ra
&& (start
+ nr
- 32) > ra
) ||
2906 ((start
+ nr
) <= 32 && start
<= ra
&& (start
+ nr
) > ra
))) {
2907 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
2910 gen_set_access_type(ctx
, ACCESS_INT
);
2911 /* NIP cannot be restored if the memory exception comes from an helper */
2912 gen_update_nip(ctx
, ctx
->nip
- 4);
2913 t0
= tcg_temp_new();
2914 gen_addr_register(ctx
, t0
);
2915 t1
= tcg_const_i32(nb
);
2916 t2
= tcg_const_i32(start
);
2917 gen_helper_lsw(cpu_env
, t0
, t1
, t2
);
2919 tcg_temp_free_i32(t1
);
2920 tcg_temp_free_i32(t2
);
2924 static void gen_lswx(DisasContext
*ctx
)
2927 TCGv_i32 t1
, t2
, t3
;
2928 gen_set_access_type(ctx
, ACCESS_INT
);
2929 /* NIP cannot be restored if the memory exception comes from an helper */
2930 gen_update_nip(ctx
, ctx
->nip
- 4);
2931 t0
= tcg_temp_new();
2932 gen_addr_reg_index(ctx
, t0
);
2933 t1
= tcg_const_i32(rD(ctx
->opcode
));
2934 t2
= tcg_const_i32(rA(ctx
->opcode
));
2935 t3
= tcg_const_i32(rB(ctx
->opcode
));
2936 gen_helper_lswx(cpu_env
, t0
, t1
, t2
, t3
);
2938 tcg_temp_free_i32(t1
);
2939 tcg_temp_free_i32(t2
);
2940 tcg_temp_free_i32(t3
);
2944 static void gen_stswi(DisasContext
*ctx
)
2948 int nb
= NB(ctx
->opcode
);
2949 gen_set_access_type(ctx
, ACCESS_INT
);
2950 /* NIP cannot be restored if the memory exception comes from an helper */
2951 gen_update_nip(ctx
, ctx
->nip
- 4);
2952 t0
= tcg_temp_new();
2953 gen_addr_register(ctx
, t0
);
2956 t1
= tcg_const_i32(nb
);
2957 t2
= tcg_const_i32(rS(ctx
->opcode
));
2958 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
2960 tcg_temp_free_i32(t1
);
2961 tcg_temp_free_i32(t2
);
2965 static void gen_stswx(DisasContext
*ctx
)
2969 gen_set_access_type(ctx
, ACCESS_INT
);
2970 /* NIP cannot be restored if the memory exception comes from an helper */
2971 gen_update_nip(ctx
, ctx
->nip
- 4);
2972 t0
= tcg_temp_new();
2973 gen_addr_reg_index(ctx
, t0
);
2974 t1
= tcg_temp_new_i32();
2975 tcg_gen_trunc_tl_i32(t1
, cpu_xer
);
2976 tcg_gen_andi_i32(t1
, t1
, 0x7F);
2977 t2
= tcg_const_i32(rS(ctx
->opcode
));
2978 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
2980 tcg_temp_free_i32(t1
);
2981 tcg_temp_free_i32(t2
);
2984 /*** Memory synchronisation ***/
2986 static void gen_eieio(DisasContext
*ctx
)
2991 static void gen_isync(DisasContext
*ctx
)
2993 gen_stop_exception(ctx
);
2997 static void gen_lwarx(DisasContext
*ctx
)
3000 TCGv gpr
= cpu_gpr
[rD(ctx
->opcode
)];
3001 gen_set_access_type(ctx
, ACCESS_RES
);
3002 t0
= tcg_temp_local_new();
3003 gen_addr_reg_index(ctx
, t0
);
3004 gen_check_align(ctx
, t0
, 0x03);
3005 gen_qemu_ld32u(ctx
, gpr
, t0
);
3006 tcg_gen_mov_tl(cpu_reserve
, t0
);
3007 tcg_gen_st_tl(gpr
, cpu_env
, offsetof(CPUPPCState
, reserve_val
));
3011 #if defined(CONFIG_USER_ONLY)
3012 static void gen_conditional_store (DisasContext
*ctx
, TCGv EA
,
3015 TCGv t0
= tcg_temp_new();
3016 uint32_t save_exception
= ctx
->exception
;
3018 tcg_gen_st_tl(EA
, cpu_env
, offsetof(CPUPPCState
, reserve_ea
));
3019 tcg_gen_movi_tl(t0
, (size
<< 5) | reg
);
3020 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, reserve_info
));
3022 gen_update_nip(ctx
, ctx
->nip
-4);
3023 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3024 gen_exception(ctx
, POWERPC_EXCP_STCX
);
3025 ctx
->exception
= save_exception
;
3030 static void gen_stwcx_(DisasContext
*ctx
)
3033 gen_set_access_type(ctx
, ACCESS_RES
);
3034 t0
= tcg_temp_local_new();
3035 gen_addr_reg_index(ctx
, t0
);
3036 gen_check_align(ctx
, t0
, 0x03);
3037 #if defined(CONFIG_USER_ONLY)
3038 gen_conditional_store(ctx
, t0
, rS(ctx
->opcode
), 4);
3043 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
3044 l1
= gen_new_label();
3045 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
3046 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3047 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3049 tcg_gen_movi_tl(cpu_reserve
, -1);
3055 #if defined(TARGET_PPC64)
3057 static void gen_ldarx(DisasContext
*ctx
)
3060 TCGv gpr
= cpu_gpr
[rD(ctx
->opcode
)];
3061 gen_set_access_type(ctx
, ACCESS_RES
);
3062 t0
= tcg_temp_local_new();
3063 gen_addr_reg_index(ctx
, t0
);
3064 gen_check_align(ctx
, t0
, 0x07);
3065 gen_qemu_ld64(ctx
, gpr
, t0
);
3066 tcg_gen_mov_tl(cpu_reserve
, t0
);
3067 tcg_gen_st_tl(gpr
, cpu_env
, offsetof(CPUPPCState
, reserve_val
));
3072 static void gen_stdcx_(DisasContext
*ctx
)
3075 gen_set_access_type(ctx
, ACCESS_RES
);
3076 t0
= tcg_temp_local_new();
3077 gen_addr_reg_index(ctx
, t0
);
3078 gen_check_align(ctx
, t0
, 0x07);
3079 #if defined(CONFIG_USER_ONLY)
3080 gen_conditional_store(ctx
, t0
, rS(ctx
->opcode
), 8);
3084 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
3085 l1
= gen_new_label();
3086 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
3087 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3088 gen_qemu_st64(ctx
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3090 tcg_gen_movi_tl(cpu_reserve
, -1);
3095 #endif /* defined(TARGET_PPC64) */
3098 static void gen_sync(DisasContext
*ctx
)
3103 static void gen_wait(DisasContext
*ctx
)
3105 TCGv_i32 t0
= tcg_temp_new_i32();
3106 tcg_gen_st_i32(t0
, cpu_env
, offsetof(CPUPPCState
, halted
));
3107 tcg_temp_free_i32(t0
);
3108 /* Stop translation, as the CPU is supposed to sleep from now */
3109 gen_exception_err(ctx
, EXCP_HLT
, 1);
3112 /*** Floating-point load ***/
3113 #define GEN_LDF(name, ldop, opc, type) \
3114 static void glue(gen_, name)(DisasContext *ctx) \
3117 if (unlikely(!ctx->fpu_enabled)) { \
3118 gen_exception(ctx, POWERPC_EXCP_FPU); \
3121 gen_set_access_type(ctx, ACCESS_FLOAT); \
3122 EA = tcg_temp_new(); \
3123 gen_addr_imm_index(ctx, EA, 0); \
3124 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3125 tcg_temp_free(EA); \
3128 #define GEN_LDUF(name, ldop, opc, type) \
3129 static void glue(gen_, name##u)(DisasContext *ctx) \
3132 if (unlikely(!ctx->fpu_enabled)) { \
3133 gen_exception(ctx, POWERPC_EXCP_FPU); \
3136 if (unlikely(rA(ctx->opcode) == 0)) { \
3137 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3140 gen_set_access_type(ctx, ACCESS_FLOAT); \
3141 EA = tcg_temp_new(); \
3142 gen_addr_imm_index(ctx, EA, 0); \
3143 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3144 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3145 tcg_temp_free(EA); \
3148 #define GEN_LDUXF(name, ldop, opc, type) \
3149 static void glue(gen_, name##ux)(DisasContext *ctx) \
3152 if (unlikely(!ctx->fpu_enabled)) { \
3153 gen_exception(ctx, POWERPC_EXCP_FPU); \
3156 if (unlikely(rA(ctx->opcode) == 0)) { \
3157 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3160 gen_set_access_type(ctx, ACCESS_FLOAT); \
3161 EA = tcg_temp_new(); \
3162 gen_addr_reg_index(ctx, EA); \
3163 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3164 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3165 tcg_temp_free(EA); \
3168 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
3169 static void glue(gen_, name##x)(DisasContext *ctx) \
3172 if (unlikely(!ctx->fpu_enabled)) { \
3173 gen_exception(ctx, POWERPC_EXCP_FPU); \
3176 gen_set_access_type(ctx, ACCESS_FLOAT); \
3177 EA = tcg_temp_new(); \
3178 gen_addr_reg_index(ctx, EA); \
3179 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3180 tcg_temp_free(EA); \
3183 #define GEN_LDFS(name, ldop, op, type) \
3184 GEN_LDF(name, ldop, op | 0x20, type); \
3185 GEN_LDUF(name, ldop, op | 0x21, type); \
3186 GEN_LDUXF(name, ldop, op | 0x01, type); \
3187 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3189 static inline void gen_qemu_ld32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3191 TCGv t0
= tcg_temp_new();
3192 TCGv_i32 t1
= tcg_temp_new_i32();
3193 gen_qemu_ld32u(ctx
, t0
, arg2
);
3194 tcg_gen_trunc_tl_i32(t1
, t0
);
3196 gen_helper_float32_to_float64(arg1
, cpu_env
, t1
);
3197 tcg_temp_free_i32(t1
);
3200 /* lfd lfdu lfdux lfdx */
3201 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
);
3202 /* lfs lfsu lfsux lfsx */
3203 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
);
3205 /*** Floating-point store ***/
3206 #define GEN_STF(name, stop, opc, type) \
3207 static void glue(gen_, name)(DisasContext *ctx) \
3210 if (unlikely(!ctx->fpu_enabled)) { \
3211 gen_exception(ctx, POWERPC_EXCP_FPU); \
3214 gen_set_access_type(ctx, ACCESS_FLOAT); \
3215 EA = tcg_temp_new(); \
3216 gen_addr_imm_index(ctx, EA, 0); \
3217 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3218 tcg_temp_free(EA); \
3221 #define GEN_STUF(name, stop, opc, type) \
3222 static void glue(gen_, name##u)(DisasContext *ctx) \
3225 if (unlikely(!ctx->fpu_enabled)) { \
3226 gen_exception(ctx, POWERPC_EXCP_FPU); \
3229 if (unlikely(rA(ctx->opcode) == 0)) { \
3230 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3233 gen_set_access_type(ctx, ACCESS_FLOAT); \
3234 EA = tcg_temp_new(); \
3235 gen_addr_imm_index(ctx, EA, 0); \
3236 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3237 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3238 tcg_temp_free(EA); \
3241 #define GEN_STUXF(name, stop, opc, type) \
3242 static void glue(gen_, name##ux)(DisasContext *ctx) \
3245 if (unlikely(!ctx->fpu_enabled)) { \
3246 gen_exception(ctx, POWERPC_EXCP_FPU); \
3249 if (unlikely(rA(ctx->opcode) == 0)) { \
3250 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3253 gen_set_access_type(ctx, ACCESS_FLOAT); \
3254 EA = tcg_temp_new(); \
3255 gen_addr_reg_index(ctx, EA); \
3256 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3257 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3258 tcg_temp_free(EA); \
3261 #define GEN_STXF(name, stop, opc2, opc3, type) \
3262 static void glue(gen_, name##x)(DisasContext *ctx) \
3265 if (unlikely(!ctx->fpu_enabled)) { \
3266 gen_exception(ctx, POWERPC_EXCP_FPU); \
3269 gen_set_access_type(ctx, ACCESS_FLOAT); \
3270 EA = tcg_temp_new(); \
3271 gen_addr_reg_index(ctx, EA); \
3272 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3273 tcg_temp_free(EA); \
3276 #define GEN_STFS(name, stop, op, type) \
3277 GEN_STF(name, stop, op | 0x20, type); \
3278 GEN_STUF(name, stop, op | 0x21, type); \
3279 GEN_STUXF(name, stop, op | 0x01, type); \
3280 GEN_STXF(name, stop, 0x17, op | 0x00, type)
3282 static inline void gen_qemu_st32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3284 TCGv_i32 t0
= tcg_temp_new_i32();
3285 TCGv t1
= tcg_temp_new();
3286 gen_helper_float64_to_float32(t0
, cpu_env
, arg1
);
3287 tcg_gen_extu_i32_tl(t1
, t0
);
3288 tcg_temp_free_i32(t0
);
3289 gen_qemu_st32(ctx
, t1
, arg2
);
3293 /* stfd stfdu stfdux stfdx */
3294 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
);
3295 /* stfs stfsu stfsux stfsx */
3296 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
);
3299 static inline void gen_qemu_st32fiw(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3301 TCGv t0
= tcg_temp_new();
3302 tcg_gen_trunc_i64_tl(t0
, arg1
),
3303 gen_qemu_st32(ctx
, t0
, arg2
);
3307 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
);
3309 static inline void gen_update_cfar(DisasContext
*ctx
, target_ulong nip
)
3311 #if defined(TARGET_PPC64)
3313 tcg_gen_movi_tl(cpu_cfar
, nip
);
3318 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
3320 TranslationBlock
*tb
;
3322 #if defined(TARGET_PPC64)
3324 dest
= (uint32_t) dest
;
3326 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
3327 likely(!ctx
->singlestep_enabled
)) {
3329 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3330 tcg_gen_exit_tb((tcg_target_long
)tb
+ n
);
3332 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3333 if (unlikely(ctx
->singlestep_enabled
)) {
3334 if ((ctx
->singlestep_enabled
&
3335 (CPU_BRANCH_STEP
| CPU_SINGLE_STEP
)) &&
3336 (ctx
->exception
== POWERPC_EXCP_BRANCH
||
3337 ctx
->exception
== POWERPC_EXCP_TRACE
)) {
3338 target_ulong tmp
= ctx
->nip
;
3340 gen_exception(ctx
, POWERPC_EXCP_TRACE
);
3343 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
3344 gen_debug_exception(ctx
);
3351 static inline void gen_setlr(DisasContext
*ctx
, target_ulong nip
)
3353 #if defined(TARGET_PPC64)
3354 if (ctx
->sf_mode
== 0)
3355 tcg_gen_movi_tl(cpu_lr
, (uint32_t)nip
);
3358 tcg_gen_movi_tl(cpu_lr
, nip
);
3362 static void gen_b(DisasContext
*ctx
)
3364 target_ulong li
, target
;
3366 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3367 /* sign extend LI */
3368 #if defined(TARGET_PPC64)
3370 li
= ((int64_t)LI(ctx
->opcode
) << 38) >> 38;
3373 li
= ((int32_t)LI(ctx
->opcode
) << 6) >> 6;
3374 if (likely(AA(ctx
->opcode
) == 0))
3375 target
= ctx
->nip
+ li
- 4;
3378 if (LK(ctx
->opcode
))
3379 gen_setlr(ctx
, ctx
->nip
);
3380 gen_update_cfar(ctx
, ctx
->nip
);
3381 gen_goto_tb(ctx
, 0, target
);
3388 static inline void gen_bcond(DisasContext
*ctx
, int type
)
3390 uint32_t bo
= BO(ctx
->opcode
);
3394 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3395 if (type
== BCOND_LR
|| type
== BCOND_CTR
) {
3396 target
= tcg_temp_local_new();
3397 if (type
== BCOND_CTR
)
3398 tcg_gen_mov_tl(target
, cpu_ctr
);
3400 tcg_gen_mov_tl(target
, cpu_lr
);
3402 TCGV_UNUSED(target
);
3404 if (LK(ctx
->opcode
))
3405 gen_setlr(ctx
, ctx
->nip
);
3406 l1
= gen_new_label();
3407 if ((bo
& 0x4) == 0) {
3408 /* Decrement and test CTR */
3409 TCGv temp
= tcg_temp_new();
3410 if (unlikely(type
== BCOND_CTR
)) {
3411 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3414 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
3415 #if defined(TARGET_PPC64)
3417 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
3420 tcg_gen_mov_tl(temp
, cpu_ctr
);
3422 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
3424 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
3426 tcg_temp_free(temp
);
3428 if ((bo
& 0x10) == 0) {
3430 uint32_t bi
= BI(ctx
->opcode
);
3431 uint32_t mask
= 1 << (3 - (bi
& 0x03));
3432 TCGv_i32 temp
= tcg_temp_new_i32();
3435 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3436 tcg_gen_brcondi_i32(TCG_COND_EQ
, temp
, 0, l1
);
3438 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3439 tcg_gen_brcondi_i32(TCG_COND_NE
, temp
, 0, l1
);
3441 tcg_temp_free_i32(temp
);
3443 gen_update_cfar(ctx
, ctx
->nip
);
3444 if (type
== BCOND_IM
) {
3445 target_ulong li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
3446 if (likely(AA(ctx
->opcode
) == 0)) {
3447 gen_goto_tb(ctx
, 0, ctx
->nip
+ li
- 4);
3449 gen_goto_tb(ctx
, 0, li
);
3452 gen_goto_tb(ctx
, 1, ctx
->nip
);
3454 #if defined(TARGET_PPC64)
3455 if (!(ctx
->sf_mode
))
3456 tcg_gen_andi_tl(cpu_nip
, target
, (uint32_t)~3);
3459 tcg_gen_andi_tl(cpu_nip
, target
, ~3);
3462 #if defined(TARGET_PPC64)
3463 if (!(ctx
->sf_mode
))
3464 tcg_gen_movi_tl(cpu_nip
, (uint32_t)ctx
->nip
);
3467 tcg_gen_movi_tl(cpu_nip
, ctx
->nip
);
3472 static void gen_bc(DisasContext
*ctx
)
3474 gen_bcond(ctx
, BCOND_IM
);
3477 static void gen_bcctr(DisasContext
*ctx
)
3479 gen_bcond(ctx
, BCOND_CTR
);
3482 static void gen_bclr(DisasContext
*ctx
)
3484 gen_bcond(ctx
, BCOND_LR
);
3487 /*** Condition register logical ***/
3488 #define GEN_CRLOGIC(name, tcg_op, opc) \
3489 static void glue(gen_, name)(DisasContext *ctx) \
3494 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3495 t0 = tcg_temp_new_i32(); \
3497 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
3499 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
3501 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
3502 t1 = tcg_temp_new_i32(); \
3503 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3505 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
3507 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
3509 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3510 tcg_op(t0, t0, t1); \
3511 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
3512 tcg_gen_andi_i32(t0, t0, bitmask); \
3513 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3514 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
3515 tcg_temp_free_i32(t0); \
3516 tcg_temp_free_i32(t1); \
3520 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08);
3522 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04);
3524 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09);
3526 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07);
3528 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01);
3530 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E);
3532 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D);
3534 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06);
3537 static void gen_mcrf(DisasContext
*ctx
)
3539 tcg_gen_mov_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfS(ctx
->opcode
)]);
3542 /*** System linkage ***/
3544 /* rfi (mem_idx only) */
3545 static void gen_rfi(DisasContext
*ctx
)
3547 #if defined(CONFIG_USER_ONLY)
3548 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3550 /* Restore CPU state */
3551 if (unlikely(!ctx
->mem_idx
)) {
3552 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3555 gen_update_cfar(ctx
, ctx
->nip
);
3556 gen_helper_rfi(cpu_env
);
3557 gen_sync_exception(ctx
);
3561 #if defined(TARGET_PPC64)
3562 static void gen_rfid(DisasContext
*ctx
)
3564 #if defined(CONFIG_USER_ONLY)
3565 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3567 /* Restore CPU state */
3568 if (unlikely(!ctx
->mem_idx
)) {
3569 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3572 gen_update_cfar(ctx
, ctx
->nip
);
3573 gen_helper_rfid(cpu_env
);
3574 gen_sync_exception(ctx
);
3578 static void gen_hrfid(DisasContext
*ctx
)
3580 #if defined(CONFIG_USER_ONLY)
3581 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3583 /* Restore CPU state */
3584 if (unlikely(ctx
->mem_idx
<= 1)) {
3585 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3588 gen_helper_hrfid(cpu_env
);
3589 gen_sync_exception(ctx
);
3595 #if defined(CONFIG_USER_ONLY)
3596 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3598 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3600 static void gen_sc(DisasContext
*ctx
)
3604 lev
= (ctx
->opcode
>> 5) & 0x7F;
3605 gen_exception_err(ctx
, POWERPC_SYSCALL
, lev
);
3611 static void gen_tw(DisasContext
*ctx
)
3613 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3614 /* Update the nip since this might generate a trap exception */
3615 gen_update_nip(ctx
, ctx
->nip
);
3616 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
3618 tcg_temp_free_i32(t0
);
3622 static void gen_twi(DisasContext
*ctx
)
3624 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3625 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
3626 /* Update the nip since this might generate a trap exception */
3627 gen_update_nip(ctx
, ctx
->nip
);
3628 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3630 tcg_temp_free_i32(t1
);
3633 #if defined(TARGET_PPC64)
3635 static void gen_td(DisasContext
*ctx
)
3637 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3638 /* Update the nip since this might generate a trap exception */
3639 gen_update_nip(ctx
, ctx
->nip
);
3640 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
3642 tcg_temp_free_i32(t0
);
3646 static void gen_tdi(DisasContext
*ctx
)
3648 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3649 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
3650 /* Update the nip since this might generate a trap exception */
3651 gen_update_nip(ctx
, ctx
->nip
);
3652 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3654 tcg_temp_free_i32(t1
);
3658 /*** Processor control ***/
3660 static void gen_read_xer(TCGv dst
)
3662 TCGv t0
= tcg_temp_new();
3663 TCGv t1
= tcg_temp_new();
3664 TCGv t2
= tcg_temp_new();
3665 tcg_gen_mov_tl(dst
, cpu_xer
);
3666 tcg_gen_shli_tl(t0
, cpu_so
, XER_SO
);
3667 tcg_gen_shli_tl(t1
, cpu_ov
, XER_OV
);
3668 tcg_gen_shli_tl(t2
, cpu_ca
, XER_CA
);
3669 tcg_gen_or_tl(t0
, t0
, t1
);
3670 tcg_gen_or_tl(dst
, dst
, t2
);
3671 tcg_gen_or_tl(dst
, dst
, t0
);
3677 static void gen_write_xer(TCGv src
)
3679 tcg_gen_andi_tl(cpu_xer
, src
,
3680 ~((1u << XER_SO
) | (1u << XER_OV
) | (1u << XER_CA
)));
3681 tcg_gen_shri_tl(cpu_so
, src
, XER_SO
);
3682 tcg_gen_shri_tl(cpu_ov
, src
, XER_OV
);
3683 tcg_gen_shri_tl(cpu_ca
, src
, XER_CA
);
3684 tcg_gen_andi_tl(cpu_so
, cpu_so
, 1);
3685 tcg_gen_andi_tl(cpu_ov
, cpu_ov
, 1);
3686 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
3690 static void gen_mcrxr(DisasContext
*ctx
)
3692 TCGv_i32 t0
= tcg_temp_new_i32();
3693 TCGv_i32 t1
= tcg_temp_new_i32();
3694 TCGv_i32 dst
= cpu_crf
[crfD(ctx
->opcode
)];
3696 tcg_gen_trunc_tl_i32(t0
, cpu_so
);
3697 tcg_gen_trunc_tl_i32(t1
, cpu_ov
);
3698 tcg_gen_trunc_tl_i32(dst
, cpu_ca
);
3699 tcg_gen_shri_i32(t0
, t0
, 2);
3700 tcg_gen_shri_i32(t1
, t1
, 1);
3701 tcg_gen_or_i32(dst
, dst
, t0
);
3702 tcg_gen_or_i32(dst
, dst
, t1
);
3703 tcg_temp_free_i32(t0
);
3704 tcg_temp_free_i32(t1
);
3706 tcg_gen_movi_tl(cpu_so
, 0);
3707 tcg_gen_movi_tl(cpu_ov
, 0);
3708 tcg_gen_movi_tl(cpu_ca
, 0);
3712 static void gen_mfcr(DisasContext
*ctx
)
3716 if (likely(ctx
->opcode
& 0x00100000)) {
3717 crm
= CRM(ctx
->opcode
);
3718 if (likely(crm
&& ((crm
& (crm
- 1)) == 0))) {
3720 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_crf
[7 - crn
]);
3721 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)],
3722 cpu_gpr
[rD(ctx
->opcode
)], crn
* 4);
3725 TCGv_i32 t0
= tcg_temp_new_i32();
3726 tcg_gen_mov_i32(t0
, cpu_crf
[0]);
3727 tcg_gen_shli_i32(t0
, t0
, 4);
3728 tcg_gen_or_i32(t0
, t0
, cpu_crf
[1]);
3729 tcg_gen_shli_i32(t0
, t0
, 4);
3730 tcg_gen_or_i32(t0
, t0
, cpu_crf
[2]);
3731 tcg_gen_shli_i32(t0
, t0
, 4);
3732 tcg_gen_or_i32(t0
, t0
, cpu_crf
[3]);
3733 tcg_gen_shli_i32(t0
, t0
, 4);
3734 tcg_gen_or_i32(t0
, t0
, cpu_crf
[4]);
3735 tcg_gen_shli_i32(t0
, t0
, 4);
3736 tcg_gen_or_i32(t0
, t0
, cpu_crf
[5]);
3737 tcg_gen_shli_i32(t0
, t0
, 4);
3738 tcg_gen_or_i32(t0
, t0
, cpu_crf
[6]);
3739 tcg_gen_shli_i32(t0
, t0
, 4);
3740 tcg_gen_or_i32(t0
, t0
, cpu_crf
[7]);
3741 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
3742 tcg_temp_free_i32(t0
);
3747 static void gen_mfmsr(DisasContext
*ctx
)
3749 #if defined(CONFIG_USER_ONLY)
3750 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3752 if (unlikely(!ctx
->mem_idx
)) {
3753 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3756 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_msr
);
3760 static void spr_noaccess(void *opaque
, int gprn
, int sprn
)
3763 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
3764 printf("ERROR: try to access SPR %d !\n", sprn
);
3767 #define SPR_NOACCESS (&spr_noaccess)
3770 static inline void gen_op_mfspr(DisasContext
*ctx
)
3772 void (*read_cb
)(void *opaque
, int gprn
, int sprn
);
3773 uint32_t sprn
= SPR(ctx
->opcode
);
3775 #if !defined(CONFIG_USER_ONLY)
3776 if (ctx
->mem_idx
== 2)
3777 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
3778 else if (ctx
->mem_idx
)
3779 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
3782 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
3783 if (likely(read_cb
!= NULL
)) {
3784 if (likely(read_cb
!= SPR_NOACCESS
)) {
3785 (*read_cb
)(ctx
, rD(ctx
->opcode
), sprn
);
3787 /* Privilege exception */
3788 /* This is a hack to avoid warnings when running Linux:
3789 * this OS breaks the PowerPC virtualisation model,
3790 * allowing userland application to read the PVR
3792 if (sprn
!= SPR_PVR
) {
3793 qemu_log("Trying to read privileged spr %d %03x at "
3794 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
3795 printf("Trying to read privileged spr %d %03x at "
3796 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
3798 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3802 qemu_log("Trying to read invalid spr %d %03x at "
3803 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
3804 printf("Trying to read invalid spr %d %03x at " TARGET_FMT_lx
"\n",
3805 sprn
, sprn
, ctx
->nip
);
3806 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
3810 static void gen_mfspr(DisasContext
*ctx
)
3816 static void gen_mftb(DisasContext
*ctx
)
3822 static void gen_mtcrf(DisasContext
*ctx
)
3826 crm
= CRM(ctx
->opcode
);
3827 if (likely((ctx
->opcode
& 0x00100000))) {
3828 if (crm
&& ((crm
& (crm
- 1)) == 0)) {
3829 TCGv_i32 temp
= tcg_temp_new_i32();
3831 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
3832 tcg_gen_shri_i32(temp
, temp
, crn
* 4);
3833 tcg_gen_andi_i32(cpu_crf
[7 - crn
], temp
, 0xf);
3834 tcg_temp_free_i32(temp
);
3837 TCGv_i32 temp
= tcg_temp_new_i32();
3838 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
3839 for (crn
= 0 ; crn
< 8 ; crn
++) {
3840 if (crm
& (1 << crn
)) {
3841 tcg_gen_shri_i32(cpu_crf
[7 - crn
], temp
, crn
* 4);
3842 tcg_gen_andi_i32(cpu_crf
[7 - crn
], cpu_crf
[7 - crn
], 0xf);
3845 tcg_temp_free_i32(temp
);
3850 #if defined(TARGET_PPC64)
3851 static void gen_mtmsrd(DisasContext
*ctx
)
3853 #if defined(CONFIG_USER_ONLY)
3854 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3856 if (unlikely(!ctx
->mem_idx
)) {
3857 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3860 if (ctx
->opcode
& 0x00010000) {
3861 /* Special form that does not need any synchronisation */
3862 TCGv t0
= tcg_temp_new();
3863 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
3864 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
3865 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
3868 /* XXX: we need to update nip before the store
3869 * if we enter power saving mode, we will exit the loop
3870 * directly from ppc_store_msr
3872 gen_update_nip(ctx
, ctx
->nip
);
3873 gen_helper_store_msr(cpu_env
, cpu_gpr
[rS(ctx
->opcode
)]);
3874 /* Must stop the translation as machine state (may have) changed */
3875 /* Note that mtmsr is not always defined as context-synchronizing */
3876 gen_stop_exception(ctx
);
3882 static void gen_mtmsr(DisasContext
*ctx
)
3884 #if defined(CONFIG_USER_ONLY)
3885 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3887 if (unlikely(!ctx
->mem_idx
)) {
3888 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3891 if (ctx
->opcode
& 0x00010000) {
3892 /* Special form that does not need any synchronisation */
3893 TCGv t0
= tcg_temp_new();
3894 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
3895 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
3896 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
3899 TCGv msr
= tcg_temp_new();
3901 /* XXX: we need to update nip before the store
3902 * if we enter power saving mode, we will exit the loop
3903 * directly from ppc_store_msr
3905 gen_update_nip(ctx
, ctx
->nip
);
3906 #if defined(TARGET_PPC64)
3907 tcg_gen_deposit_tl(msr
, cpu_msr
, cpu_gpr
[rS(ctx
->opcode
)], 0, 32);
3909 tcg_gen_mov_tl(msr
, cpu_gpr
[rS(ctx
->opcode
)]);
3911 gen_helper_store_msr(cpu_env
, msr
);
3912 /* Must stop the translation as machine state (may have) changed */
3913 /* Note that mtmsr is not always defined as context-synchronizing */
3914 gen_stop_exception(ctx
);
3920 static void gen_mtspr(DisasContext
*ctx
)
3922 void (*write_cb
)(void *opaque
, int sprn
, int gprn
);
3923 uint32_t sprn
= SPR(ctx
->opcode
);
3925 #if !defined(CONFIG_USER_ONLY)
3926 if (ctx
->mem_idx
== 2)
3927 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
3928 else if (ctx
->mem_idx
)
3929 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
3932 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
3933 if (likely(write_cb
!= NULL
)) {
3934 if (likely(write_cb
!= SPR_NOACCESS
)) {
3935 (*write_cb
)(ctx
, sprn
, rS(ctx
->opcode
));
3937 /* Privilege exception */
3938 qemu_log("Trying to write privileged spr %d %03x at "
3939 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
3940 printf("Trying to write privileged spr %d %03x at " TARGET_FMT_lx
3941 "\n", sprn
, sprn
, ctx
->nip
);
3942 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3946 qemu_log("Trying to write invalid spr %d %03x at "
3947 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
3948 printf("Trying to write invalid spr %d %03x at " TARGET_FMT_lx
"\n",
3949 sprn
, sprn
, ctx
->nip
);
3950 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
3954 /*** Cache management ***/
3957 static void gen_dcbf(DisasContext
*ctx
)
3959 /* XXX: specification says this is treated as a load by the MMU */
3961 gen_set_access_type(ctx
, ACCESS_CACHE
);
3962 t0
= tcg_temp_new();
3963 gen_addr_reg_index(ctx
, t0
);
3964 gen_qemu_ld8u(ctx
, t0
, t0
);
3968 /* dcbi (Supervisor only) */
3969 static void gen_dcbi(DisasContext
*ctx
)
3971 #if defined(CONFIG_USER_ONLY)
3972 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3975 if (unlikely(!ctx
->mem_idx
)) {
3976 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3979 EA
= tcg_temp_new();
3980 gen_set_access_type(ctx
, ACCESS_CACHE
);
3981 gen_addr_reg_index(ctx
, EA
);
3982 val
= tcg_temp_new();
3983 /* XXX: specification says this should be treated as a store by the MMU */
3984 gen_qemu_ld8u(ctx
, val
, EA
);
3985 gen_qemu_st8(ctx
, val
, EA
);
3992 static void gen_dcbst(DisasContext
*ctx
)
3994 /* XXX: specification say this is treated as a load by the MMU */
3996 gen_set_access_type(ctx
, ACCESS_CACHE
);
3997 t0
= tcg_temp_new();
3998 gen_addr_reg_index(ctx
, t0
);
3999 gen_qemu_ld8u(ctx
, t0
, t0
);
4004 static void gen_dcbt(DisasContext
*ctx
)
4006 /* interpreted as no-op */
4007 /* XXX: specification say this is treated as a load by the MMU
4008 * but does not generate any exception
4013 static void gen_dcbtst(DisasContext
*ctx
)
4015 /* interpreted as no-op */
4016 /* XXX: specification say this is treated as a load by the MMU
4017 * but does not generate any exception
4022 static void gen_dcbz(DisasContext
*ctx
)
4025 TCGv_i32 tcgv_is_dcbzl
;
4026 int is_dcbzl
= ctx
->opcode
& 0x00200000 ? 1 : 0;
4028 gen_set_access_type(ctx
, ACCESS_CACHE
);
4029 /* NIP cannot be restored if the memory exception comes from an helper */
4030 gen_update_nip(ctx
, ctx
->nip
- 4);
4031 tcgv_addr
= tcg_temp_new();
4032 tcgv_is_dcbzl
= tcg_const_i32(is_dcbzl
);
4034 gen_addr_reg_index(ctx
, tcgv_addr
);
4035 gen_helper_dcbz(cpu_env
, tcgv_addr
, tcgv_is_dcbzl
);
4037 tcg_temp_free(tcgv_addr
);
4038 tcg_temp_free_i32(tcgv_is_dcbzl
);
4042 static void gen_dst(DisasContext
*ctx
)
4044 if (rA(ctx
->opcode
) == 0) {
4045 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
4047 /* interpreted as no-op */
4052 static void gen_dstst(DisasContext
*ctx
)
4054 if (rA(ctx
->opcode
) == 0) {
4055 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
4057 /* interpreted as no-op */
4063 static void gen_dss(DisasContext
*ctx
)
4065 /* interpreted as no-op */
4069 static void gen_icbi(DisasContext
*ctx
)
4072 gen_set_access_type(ctx
, ACCESS_CACHE
);
4073 /* NIP cannot be restored if the memory exception comes from an helper */
4074 gen_update_nip(ctx
, ctx
->nip
- 4);
4075 t0
= tcg_temp_new();
4076 gen_addr_reg_index(ctx
, t0
);
4077 gen_helper_icbi(cpu_env
, t0
);
4083 static void gen_dcba(DisasContext
*ctx
)
4085 /* interpreted as no-op */
4086 /* XXX: specification say this is treated as a store by the MMU
4087 * but does not generate any exception
4091 /*** Segment register manipulation ***/
4092 /* Supervisor only: */
4095 static void gen_mfsr(DisasContext
*ctx
)
4097 #if defined(CONFIG_USER_ONLY)
4098 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4101 if (unlikely(!ctx
->mem_idx
)) {
4102 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4105 t0
= tcg_const_tl(SR(ctx
->opcode
));
4106 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4112 static void gen_mfsrin(DisasContext
*ctx
)
4114 #if defined(CONFIG_USER_ONLY)
4115 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4118 if (unlikely(!ctx
->mem_idx
)) {
4119 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4122 t0
= tcg_temp_new();
4123 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4124 tcg_gen_andi_tl(t0
, t0
, 0xF);
4125 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4131 static void gen_mtsr(DisasContext
*ctx
)
4133 #if defined(CONFIG_USER_ONLY)
4134 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4137 if (unlikely(!ctx
->mem_idx
)) {
4138 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4141 t0
= tcg_const_tl(SR(ctx
->opcode
));
4142 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4148 static void gen_mtsrin(DisasContext
*ctx
)
4150 #if defined(CONFIG_USER_ONLY)
4151 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4154 if (unlikely(!ctx
->mem_idx
)) {
4155 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4158 t0
= tcg_temp_new();
4159 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4160 tcg_gen_andi_tl(t0
, t0
, 0xF);
4161 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rD(ctx
->opcode
)]);
4166 #if defined(TARGET_PPC64)
4167 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4170 static void gen_mfsr_64b(DisasContext
*ctx
)
4172 #if defined(CONFIG_USER_ONLY)
4173 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4176 if (unlikely(!ctx
->mem_idx
)) {
4177 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4180 t0
= tcg_const_tl(SR(ctx
->opcode
));
4181 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4187 static void gen_mfsrin_64b(DisasContext
*ctx
)
4189 #if defined(CONFIG_USER_ONLY)
4190 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4193 if (unlikely(!ctx
->mem_idx
)) {
4194 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4197 t0
= tcg_temp_new();
4198 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4199 tcg_gen_andi_tl(t0
, t0
, 0xF);
4200 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4206 static void gen_mtsr_64b(DisasContext
*ctx
)
4208 #if defined(CONFIG_USER_ONLY)
4209 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4212 if (unlikely(!ctx
->mem_idx
)) {
4213 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4216 t0
= tcg_const_tl(SR(ctx
->opcode
));
4217 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4223 static void gen_mtsrin_64b(DisasContext
*ctx
)
4225 #if defined(CONFIG_USER_ONLY)
4226 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4229 if (unlikely(!ctx
->mem_idx
)) {
4230 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4233 t0
= tcg_temp_new();
4234 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4235 tcg_gen_andi_tl(t0
, t0
, 0xF);
4236 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4242 static void gen_slbmte(DisasContext
*ctx
)
4244 #if defined(CONFIG_USER_ONLY)
4245 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4247 if (unlikely(!ctx
->mem_idx
)) {
4248 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4251 gen_helper_store_slb(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)],
4252 cpu_gpr
[rS(ctx
->opcode
)]);
4256 static void gen_slbmfee(DisasContext
*ctx
)
4258 #if defined(CONFIG_USER_ONLY)
4259 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4261 if (unlikely(!ctx
->mem_idx
)) {
4262 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4265 gen_helper_load_slb_esid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4266 cpu_gpr
[rB(ctx
->opcode
)]);
4270 static void gen_slbmfev(DisasContext
*ctx
)
4272 #if defined(CONFIG_USER_ONLY)
4273 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4275 if (unlikely(!ctx
->mem_idx
)) {
4276 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4279 gen_helper_load_slb_vsid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4280 cpu_gpr
[rB(ctx
->opcode
)]);
4283 #endif /* defined(TARGET_PPC64) */
4285 /*** Lookaside buffer management ***/
4286 /* Optional & mem_idx only: */
4289 static void gen_tlbia(DisasContext
*ctx
)
4291 #if defined(CONFIG_USER_ONLY)
4292 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4294 if (unlikely(!ctx
->mem_idx
)) {
4295 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4298 gen_helper_tlbia(cpu_env
);
4303 static void gen_tlbiel(DisasContext
*ctx
)
4305 #if defined(CONFIG_USER_ONLY)
4306 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4308 if (unlikely(!ctx
->mem_idx
)) {
4309 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4312 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4317 static void gen_tlbie(DisasContext
*ctx
)
4319 #if defined(CONFIG_USER_ONLY)
4320 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4322 if (unlikely(!ctx
->mem_idx
)) {
4323 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4326 #if defined(TARGET_PPC64)
4327 if (!ctx
->sf_mode
) {
4328 TCGv t0
= tcg_temp_new();
4329 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
4330 gen_helper_tlbie(cpu_env
, t0
);
4334 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4339 static void gen_tlbsync(DisasContext
*ctx
)
4341 #if defined(CONFIG_USER_ONLY)
4342 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4344 if (unlikely(!ctx
->mem_idx
)) {
4345 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4348 /* This has no effect: it should ensure that all previous
4349 * tlbie have completed
4351 gen_stop_exception(ctx
);
4355 #if defined(TARGET_PPC64)
4357 static void gen_slbia(DisasContext
*ctx
)
4359 #if defined(CONFIG_USER_ONLY)
4360 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4362 if (unlikely(!ctx
->mem_idx
)) {
4363 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4366 gen_helper_slbia(cpu_env
);
4371 static void gen_slbie(DisasContext
*ctx
)
4373 #if defined(CONFIG_USER_ONLY)
4374 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4376 if (unlikely(!ctx
->mem_idx
)) {
4377 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4380 gen_helper_slbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4385 /*** External control ***/
4389 static void gen_eciwx(DisasContext
*ctx
)
4392 /* Should check EAR[E] ! */
4393 gen_set_access_type(ctx
, ACCESS_EXT
);
4394 t0
= tcg_temp_new();
4395 gen_addr_reg_index(ctx
, t0
);
4396 gen_check_align(ctx
, t0
, 0x03);
4397 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4402 static void gen_ecowx(DisasContext
*ctx
)
4405 /* Should check EAR[E] ! */
4406 gen_set_access_type(ctx
, ACCESS_EXT
);
4407 t0
= tcg_temp_new();
4408 gen_addr_reg_index(ctx
, t0
);
4409 gen_check_align(ctx
, t0
, 0x03);
4410 gen_qemu_st32(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4414 /* PowerPC 601 specific instructions */
4417 static void gen_abs(DisasContext
*ctx
)
4419 int l1
= gen_new_label();
4420 int l2
= gen_new_label();
4421 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4422 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4425 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4427 if (unlikely(Rc(ctx
->opcode
) != 0))
4428 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4432 static void gen_abso(DisasContext
*ctx
)
4434 int l1
= gen_new_label();
4435 int l2
= gen_new_label();
4436 int l3
= gen_new_label();
4437 /* Start with XER OV disabled, the most likely case */
4438 tcg_gen_movi_tl(cpu_ov
, 0);
4439 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l2
);
4440 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rA(ctx
->opcode
)], 0x80000000, l1
);
4441 tcg_gen_movi_tl(cpu_ov
, 1);
4442 tcg_gen_movi_tl(cpu_so
, 1);
4445 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4448 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4450 if (unlikely(Rc(ctx
->opcode
) != 0))
4451 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4455 static void gen_clcs(DisasContext
*ctx
)
4457 TCGv_i32 t0
= tcg_const_i32(rA(ctx
->opcode
));
4458 gen_helper_clcs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4459 tcg_temp_free_i32(t0
);
4460 /* Rc=1 sets CR0 to an undefined state */
4464 static void gen_div(DisasContext
*ctx
)
4466 gen_helper_div(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4467 cpu_gpr
[rB(ctx
->opcode
)]);
4468 if (unlikely(Rc(ctx
->opcode
) != 0))
4469 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4473 static void gen_divo(DisasContext
*ctx
)
4475 gen_helper_divo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4476 cpu_gpr
[rB(ctx
->opcode
)]);
4477 if (unlikely(Rc(ctx
->opcode
) != 0))
4478 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4482 static void gen_divs(DisasContext
*ctx
)
4484 gen_helper_divs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4485 cpu_gpr
[rB(ctx
->opcode
)]);
4486 if (unlikely(Rc(ctx
->opcode
) != 0))
4487 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4490 /* divso - divso. */
4491 static void gen_divso(DisasContext
*ctx
)
4493 gen_helper_divso(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
4494 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4495 if (unlikely(Rc(ctx
->opcode
) != 0))
4496 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4500 static void gen_doz(DisasContext
*ctx
)
4502 int l1
= gen_new_label();
4503 int l2
= gen_new_label();
4504 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4505 tcg_gen_sub_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4508 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4510 if (unlikely(Rc(ctx
->opcode
) != 0))
4511 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4515 static void gen_dozo(DisasContext
*ctx
)
4517 int l1
= gen_new_label();
4518 int l2
= gen_new_label();
4519 TCGv t0
= tcg_temp_new();
4520 TCGv t1
= tcg_temp_new();
4521 TCGv t2
= tcg_temp_new();
4522 /* Start with XER OV disabled, the most likely case */
4523 tcg_gen_movi_tl(cpu_ov
, 0);
4524 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4525 tcg_gen_sub_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4526 tcg_gen_xor_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4527 tcg_gen_xor_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], t0
);
4528 tcg_gen_andc_tl(t1
, t1
, t2
);
4529 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4530 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
4531 tcg_gen_movi_tl(cpu_ov
, 1);
4532 tcg_gen_movi_tl(cpu_so
, 1);
4535 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4540 if (unlikely(Rc(ctx
->opcode
) != 0))
4541 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4545 static void gen_dozi(DisasContext
*ctx
)
4547 target_long simm
= SIMM(ctx
->opcode
);
4548 int l1
= gen_new_label();
4549 int l2
= gen_new_label();
4550 tcg_gen_brcondi_tl(TCG_COND_LT
, cpu_gpr
[rA(ctx
->opcode
)], simm
, l1
);
4551 tcg_gen_subfi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
, cpu_gpr
[rA(ctx
->opcode
)]);
4554 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4556 if (unlikely(Rc(ctx
->opcode
) != 0))
4557 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4560 /* lscbx - lscbx. */
4561 static void gen_lscbx(DisasContext
*ctx
)
4563 TCGv t0
= tcg_temp_new();
4564 TCGv_i32 t1
= tcg_const_i32(rD(ctx
->opcode
));
4565 TCGv_i32 t2
= tcg_const_i32(rA(ctx
->opcode
));
4566 TCGv_i32 t3
= tcg_const_i32(rB(ctx
->opcode
));
4568 gen_addr_reg_index(ctx
, t0
);
4569 /* NIP cannot be restored if the memory exception comes from an helper */
4570 gen_update_nip(ctx
, ctx
->nip
- 4);
4571 gen_helper_lscbx(t0
, cpu_env
, t0
, t1
, t2
, t3
);
4572 tcg_temp_free_i32(t1
);
4573 tcg_temp_free_i32(t2
);
4574 tcg_temp_free_i32(t3
);
4575 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~0x7F);
4576 tcg_gen_or_tl(cpu_xer
, cpu_xer
, t0
);
4577 if (unlikely(Rc(ctx
->opcode
) != 0))
4578 gen_set_Rc0(ctx
, t0
);
4582 /* maskg - maskg. */
4583 static void gen_maskg(DisasContext
*ctx
)
4585 int l1
= gen_new_label();
4586 TCGv t0
= tcg_temp_new();
4587 TCGv t1
= tcg_temp_new();
4588 TCGv t2
= tcg_temp_new();
4589 TCGv t3
= tcg_temp_new();
4590 tcg_gen_movi_tl(t3
, 0xFFFFFFFF);
4591 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4592 tcg_gen_andi_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 0x1F);
4593 tcg_gen_addi_tl(t2
, t0
, 1);
4594 tcg_gen_shr_tl(t2
, t3
, t2
);
4595 tcg_gen_shr_tl(t3
, t3
, t1
);
4596 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], t2
, t3
);
4597 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
4598 tcg_gen_neg_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4604 if (unlikely(Rc(ctx
->opcode
) != 0))
4605 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4608 /* maskir - maskir. */
4609 static void gen_maskir(DisasContext
*ctx
)
4611 TCGv t0
= tcg_temp_new();
4612 TCGv t1
= tcg_temp_new();
4613 tcg_gen_and_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4614 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4615 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4618 if (unlikely(Rc(ctx
->opcode
) != 0))
4619 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4623 static void gen_mul(DisasContext
*ctx
)
4625 TCGv_i64 t0
= tcg_temp_new_i64();
4626 TCGv_i64 t1
= tcg_temp_new_i64();
4627 TCGv t2
= tcg_temp_new();
4628 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4629 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4630 tcg_gen_mul_i64(t0
, t0
, t1
);
4631 tcg_gen_trunc_i64_tl(t2
, t0
);
4632 gen_store_spr(SPR_MQ
, t2
);
4633 tcg_gen_shri_i64(t1
, t0
, 32);
4634 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4635 tcg_temp_free_i64(t0
);
4636 tcg_temp_free_i64(t1
);
4638 if (unlikely(Rc(ctx
->opcode
) != 0))
4639 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4643 static void gen_mulo(DisasContext
*ctx
)
4645 int l1
= gen_new_label();
4646 TCGv_i64 t0
= tcg_temp_new_i64();
4647 TCGv_i64 t1
= tcg_temp_new_i64();
4648 TCGv t2
= tcg_temp_new();
4649 /* Start with XER OV disabled, the most likely case */
4650 tcg_gen_movi_tl(cpu_ov
, 0);
4651 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4652 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4653 tcg_gen_mul_i64(t0
, t0
, t1
);
4654 tcg_gen_trunc_i64_tl(t2
, t0
);
4655 gen_store_spr(SPR_MQ
, t2
);
4656 tcg_gen_shri_i64(t1
, t0
, 32);
4657 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4658 tcg_gen_ext32s_i64(t1
, t0
);
4659 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
4660 tcg_gen_movi_tl(cpu_ov
, 1);
4661 tcg_gen_movi_tl(cpu_so
, 1);
4663 tcg_temp_free_i64(t0
);
4664 tcg_temp_free_i64(t1
);
4666 if (unlikely(Rc(ctx
->opcode
) != 0))
4667 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4671 static void gen_nabs(DisasContext
*ctx
)
4673 int l1
= gen_new_label();
4674 int l2
= gen_new_label();
4675 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4676 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4679 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4681 if (unlikely(Rc(ctx
->opcode
) != 0))
4682 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4685 /* nabso - nabso. */
4686 static void gen_nabso(DisasContext
*ctx
)
4688 int l1
= gen_new_label();
4689 int l2
= gen_new_label();
4690 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4691 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4694 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4696 /* nabs never overflows */
4697 tcg_gen_movi_tl(cpu_ov
, 0);
4698 if (unlikely(Rc(ctx
->opcode
) != 0))
4699 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4703 static void gen_rlmi(DisasContext
*ctx
)
4705 uint32_t mb
= MB(ctx
->opcode
);
4706 uint32_t me
= ME(ctx
->opcode
);
4707 TCGv t0
= tcg_temp_new();
4708 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4709 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4710 tcg_gen_andi_tl(t0
, t0
, MASK(mb
, me
));
4711 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~MASK(mb
, me
));
4712 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], t0
);
4714 if (unlikely(Rc(ctx
->opcode
) != 0))
4715 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4719 static void gen_rrib(DisasContext
*ctx
)
4721 TCGv t0
= tcg_temp_new();
4722 TCGv t1
= tcg_temp_new();
4723 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4724 tcg_gen_movi_tl(t1
, 0x80000000);
4725 tcg_gen_shr_tl(t1
, t1
, t0
);
4726 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4727 tcg_gen_and_tl(t0
, t0
, t1
);
4728 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], t1
);
4729 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4732 if (unlikely(Rc(ctx
->opcode
) != 0))
4733 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4737 static void gen_sle(DisasContext
*ctx
)
4739 TCGv t0
= tcg_temp_new();
4740 TCGv t1
= tcg_temp_new();
4741 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4742 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4743 tcg_gen_subfi_tl(t1
, 32, t1
);
4744 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4745 tcg_gen_or_tl(t1
, t0
, t1
);
4746 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4747 gen_store_spr(SPR_MQ
, t1
);
4750 if (unlikely(Rc(ctx
->opcode
) != 0))
4751 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4755 static void gen_sleq(DisasContext
*ctx
)
4757 TCGv t0
= tcg_temp_new();
4758 TCGv t1
= tcg_temp_new();
4759 TCGv t2
= tcg_temp_new();
4760 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4761 tcg_gen_movi_tl(t2
, 0xFFFFFFFF);
4762 tcg_gen_shl_tl(t2
, t2
, t0
);
4763 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4764 gen_load_spr(t1
, SPR_MQ
);
4765 gen_store_spr(SPR_MQ
, t0
);
4766 tcg_gen_and_tl(t0
, t0
, t2
);
4767 tcg_gen_andc_tl(t1
, t1
, t2
);
4768 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4772 if (unlikely(Rc(ctx
->opcode
) != 0))
4773 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4777 static void gen_sliq(DisasContext
*ctx
)
4779 int sh
= SH(ctx
->opcode
);
4780 TCGv t0
= tcg_temp_new();
4781 TCGv t1
= tcg_temp_new();
4782 tcg_gen_shli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4783 tcg_gen_shri_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
4784 tcg_gen_or_tl(t1
, t0
, t1
);
4785 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4786 gen_store_spr(SPR_MQ
, t1
);
4789 if (unlikely(Rc(ctx
->opcode
) != 0))
4790 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4793 /* slliq - slliq. */
4794 static void gen_slliq(DisasContext
*ctx
)
4796 int sh
= SH(ctx
->opcode
);
4797 TCGv t0
= tcg_temp_new();
4798 TCGv t1
= tcg_temp_new();
4799 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4800 gen_load_spr(t1
, SPR_MQ
);
4801 gen_store_spr(SPR_MQ
, t0
);
4802 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
<< sh
));
4803 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
<< sh
));
4804 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4807 if (unlikely(Rc(ctx
->opcode
) != 0))
4808 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4812 static void gen_sllq(DisasContext
*ctx
)
4814 int l1
= gen_new_label();
4815 int l2
= gen_new_label();
4816 TCGv t0
= tcg_temp_local_new();
4817 TCGv t1
= tcg_temp_local_new();
4818 TCGv t2
= tcg_temp_local_new();
4819 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4820 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
4821 tcg_gen_shl_tl(t1
, t1
, t2
);
4822 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4823 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
4824 gen_load_spr(t0
, SPR_MQ
);
4825 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4828 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4829 gen_load_spr(t2
, SPR_MQ
);
4830 tcg_gen_andc_tl(t1
, t2
, t1
);
4831 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4836 if (unlikely(Rc(ctx
->opcode
) != 0))
4837 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4841 static void gen_slq(DisasContext
*ctx
)
4843 int l1
= gen_new_label();
4844 TCGv t0
= tcg_temp_new();
4845 TCGv t1
= tcg_temp_new();
4846 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4847 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4848 tcg_gen_subfi_tl(t1
, 32, t1
);
4849 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4850 tcg_gen_or_tl(t1
, t0
, t1
);
4851 gen_store_spr(SPR_MQ
, t1
);
4852 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4853 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4854 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
4855 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
4859 if (unlikely(Rc(ctx
->opcode
) != 0))
4860 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4863 /* sraiq - sraiq. */
4864 static void gen_sraiq(DisasContext
*ctx
)
4866 int sh
= SH(ctx
->opcode
);
4867 int l1
= gen_new_label();
4868 TCGv t0
= tcg_temp_new();
4869 TCGv t1
= tcg_temp_new();
4870 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4871 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
4872 tcg_gen_or_tl(t0
, t0
, t1
);
4873 gen_store_spr(SPR_MQ
, t0
);
4874 tcg_gen_movi_tl(cpu_ca
, 0);
4875 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
4876 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
4877 tcg_gen_movi_tl(cpu_ca
, 1);
4879 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
4882 if (unlikely(Rc(ctx
->opcode
) != 0))
4883 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4887 static void gen_sraq(DisasContext
*ctx
)
4889 int l1
= gen_new_label();
4890 int l2
= gen_new_label();
4891 TCGv t0
= tcg_temp_new();
4892 TCGv t1
= tcg_temp_local_new();
4893 TCGv t2
= tcg_temp_local_new();
4894 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4895 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4896 tcg_gen_sar_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4897 tcg_gen_subfi_tl(t2
, 32, t2
);
4898 tcg_gen_shl_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4899 tcg_gen_or_tl(t0
, t0
, t2
);
4900 gen_store_spr(SPR_MQ
, t0
);
4901 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4902 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l1
);
4903 tcg_gen_mov_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
4904 tcg_gen_sari_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 31);
4907 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
);
4908 tcg_gen_movi_tl(cpu_ca
, 0);
4909 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
4910 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l2
);
4911 tcg_gen_movi_tl(cpu_ca
, 1);
4915 if (unlikely(Rc(ctx
->opcode
) != 0))
4916 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4920 static void gen_sre(DisasContext
*ctx
)
4922 TCGv t0
= tcg_temp_new();
4923 TCGv t1
= tcg_temp_new();
4924 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4925 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4926 tcg_gen_subfi_tl(t1
, 32, t1
);
4927 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4928 tcg_gen_or_tl(t1
, t0
, t1
);
4929 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4930 gen_store_spr(SPR_MQ
, t1
);
4933 if (unlikely(Rc(ctx
->opcode
) != 0))
4934 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4938 static void gen_srea(DisasContext
*ctx
)
4940 TCGv t0
= tcg_temp_new();
4941 TCGv t1
= tcg_temp_new();
4942 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4943 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4944 gen_store_spr(SPR_MQ
, t0
);
4945 tcg_gen_sar_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t1
);
4948 if (unlikely(Rc(ctx
->opcode
) != 0))
4949 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4953 static void gen_sreq(DisasContext
*ctx
)
4955 TCGv t0
= tcg_temp_new();
4956 TCGv t1
= tcg_temp_new();
4957 TCGv t2
= tcg_temp_new();
4958 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4959 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
4960 tcg_gen_shr_tl(t1
, t1
, t0
);
4961 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4962 gen_load_spr(t2
, SPR_MQ
);
4963 gen_store_spr(SPR_MQ
, t0
);
4964 tcg_gen_and_tl(t0
, t0
, t1
);
4965 tcg_gen_andc_tl(t2
, t2
, t1
);
4966 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
4970 if (unlikely(Rc(ctx
->opcode
) != 0))
4971 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4975 static void gen_sriq(DisasContext
*ctx
)
4977 int sh
= SH(ctx
->opcode
);
4978 TCGv t0
= tcg_temp_new();
4979 TCGv t1
= tcg_temp_new();
4980 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4981 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
4982 tcg_gen_or_tl(t1
, t0
, t1
);
4983 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4984 gen_store_spr(SPR_MQ
, t1
);
4987 if (unlikely(Rc(ctx
->opcode
) != 0))
4988 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4992 static void gen_srliq(DisasContext
*ctx
)
4994 int sh
= SH(ctx
->opcode
);
4995 TCGv t0
= tcg_temp_new();
4996 TCGv t1
= tcg_temp_new();
4997 tcg_gen_rotri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4998 gen_load_spr(t1
, SPR_MQ
);
4999 gen_store_spr(SPR_MQ
, t0
);
5000 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
>> sh
));
5001 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
>> sh
));
5002 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5005 if (unlikely(Rc(ctx
->opcode
) != 0))
5006 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5010 static void gen_srlq(DisasContext
*ctx
)
5012 int l1
= gen_new_label();
5013 int l2
= gen_new_label();
5014 TCGv t0
= tcg_temp_local_new();
5015 TCGv t1
= tcg_temp_local_new();
5016 TCGv t2
= tcg_temp_local_new();
5017 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5018 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5019 tcg_gen_shr_tl(t2
, t1
, t2
);
5020 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5021 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5022 gen_load_spr(t0
, SPR_MQ
);
5023 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5026 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5027 tcg_gen_and_tl(t0
, t0
, t2
);
5028 gen_load_spr(t1
, SPR_MQ
);
5029 tcg_gen_andc_tl(t1
, t1
, t2
);
5030 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5035 if (unlikely(Rc(ctx
->opcode
) != 0))
5036 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5040 static void gen_srq(DisasContext
*ctx
)
5042 int l1
= gen_new_label();
5043 TCGv t0
= tcg_temp_new();
5044 TCGv t1
= tcg_temp_new();
5045 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5046 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5047 tcg_gen_subfi_tl(t1
, 32, t1
);
5048 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5049 tcg_gen_or_tl(t1
, t0
, t1
);
5050 gen_store_spr(SPR_MQ
, t1
);
5051 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5052 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5053 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5054 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5058 if (unlikely(Rc(ctx
->opcode
) != 0))
5059 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5062 /* PowerPC 602 specific instructions */
5065 static void gen_dsa(DisasContext
*ctx
)
5068 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5072 static void gen_esa(DisasContext
*ctx
)
5075 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5079 static void gen_mfrom(DisasContext
*ctx
)
5081 #if defined(CONFIG_USER_ONLY)
5082 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5084 if (unlikely(!ctx
->mem_idx
)) {
5085 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5088 gen_helper_602_mfrom(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5092 /* 602 - 603 - G2 TLB management */
5095 static void gen_tlbld_6xx(DisasContext
*ctx
)
5097 #if defined(CONFIG_USER_ONLY)
5098 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5100 if (unlikely(!ctx
->mem_idx
)) {
5101 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5104 gen_helper_6xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5109 static void gen_tlbli_6xx(DisasContext
*ctx
)
5111 #if defined(CONFIG_USER_ONLY)
5112 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5114 if (unlikely(!ctx
->mem_idx
)) {
5115 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5118 gen_helper_6xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5122 /* 74xx TLB management */
5125 static void gen_tlbld_74xx(DisasContext
*ctx
)
5127 #if defined(CONFIG_USER_ONLY)
5128 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5130 if (unlikely(!ctx
->mem_idx
)) {
5131 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5134 gen_helper_74xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5139 static void gen_tlbli_74xx(DisasContext
*ctx
)
5141 #if defined(CONFIG_USER_ONLY)
5142 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5144 if (unlikely(!ctx
->mem_idx
)) {
5145 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5148 gen_helper_74xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5152 /* POWER instructions not in PowerPC 601 */
5155 static void gen_clf(DisasContext
*ctx
)
5157 /* Cache line flush: implemented as no-op */
5161 static void gen_cli(DisasContext
*ctx
)
5163 /* Cache line invalidate: privileged and treated as no-op */
5164 #if defined(CONFIG_USER_ONLY)
5165 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5167 if (unlikely(!ctx
->mem_idx
)) {
5168 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5175 static void gen_dclst(DisasContext
*ctx
)
5177 /* Data cache line store: treated as no-op */
5180 static void gen_mfsri(DisasContext
*ctx
)
5182 #if defined(CONFIG_USER_ONLY)
5183 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5185 int ra
= rA(ctx
->opcode
);
5186 int rd
= rD(ctx
->opcode
);
5188 if (unlikely(!ctx
->mem_idx
)) {
5189 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5192 t0
= tcg_temp_new();
5193 gen_addr_reg_index(ctx
, t0
);
5194 tcg_gen_shri_tl(t0
, t0
, 28);
5195 tcg_gen_andi_tl(t0
, t0
, 0xF);
5196 gen_helper_load_sr(cpu_gpr
[rd
], cpu_env
, t0
);
5198 if (ra
!= 0 && ra
!= rd
)
5199 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rd
]);
5203 static void gen_rac(DisasContext
*ctx
)
5205 #if defined(CONFIG_USER_ONLY)
5206 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5209 if (unlikely(!ctx
->mem_idx
)) {
5210 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5213 t0
= tcg_temp_new();
5214 gen_addr_reg_index(ctx
, t0
);
5215 gen_helper_rac(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5220 static void gen_rfsvc(DisasContext
*ctx
)
5222 #if defined(CONFIG_USER_ONLY)
5223 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5225 if (unlikely(!ctx
->mem_idx
)) {
5226 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5229 gen_helper_rfsvc(cpu_env
);
5230 gen_sync_exception(ctx
);
5234 /* svc is not implemented for now */
5236 /* POWER2 specific instructions */
5237 /* Quad manipulation (load/store two floats at a time) */
5240 static void gen_lfq(DisasContext
*ctx
)
5242 int rd
= rD(ctx
->opcode
);
5244 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5245 t0
= tcg_temp_new();
5246 gen_addr_imm_index(ctx
, t0
, 0);
5247 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5248 gen_addr_add(ctx
, t0
, t0
, 8);
5249 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5254 static void gen_lfqu(DisasContext
*ctx
)
5256 int ra
= rA(ctx
->opcode
);
5257 int rd
= rD(ctx
->opcode
);
5259 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5260 t0
= tcg_temp_new();
5261 t1
= tcg_temp_new();
5262 gen_addr_imm_index(ctx
, t0
, 0);
5263 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5264 gen_addr_add(ctx
, t1
, t0
, 8);
5265 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5267 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5273 static void gen_lfqux(DisasContext
*ctx
)
5275 int ra
= rA(ctx
->opcode
);
5276 int rd
= rD(ctx
->opcode
);
5277 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5279 t0
= tcg_temp_new();
5280 gen_addr_reg_index(ctx
, t0
);
5281 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5282 t1
= tcg_temp_new();
5283 gen_addr_add(ctx
, t1
, t0
, 8);
5284 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5287 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5292 static void gen_lfqx(DisasContext
*ctx
)
5294 int rd
= rD(ctx
->opcode
);
5296 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5297 t0
= tcg_temp_new();
5298 gen_addr_reg_index(ctx
, t0
);
5299 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5300 gen_addr_add(ctx
, t0
, t0
, 8);
5301 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5306 static void gen_stfq(DisasContext
*ctx
)
5308 int rd
= rD(ctx
->opcode
);
5310 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5311 t0
= tcg_temp_new();
5312 gen_addr_imm_index(ctx
, t0
, 0);
5313 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5314 gen_addr_add(ctx
, t0
, t0
, 8);
5315 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5320 static void gen_stfqu(DisasContext
*ctx
)
5322 int ra
= rA(ctx
->opcode
);
5323 int rd
= rD(ctx
->opcode
);
5325 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5326 t0
= tcg_temp_new();
5327 gen_addr_imm_index(ctx
, t0
, 0);
5328 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5329 t1
= tcg_temp_new();
5330 gen_addr_add(ctx
, t1
, t0
, 8);
5331 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5334 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5339 static void gen_stfqux(DisasContext
*ctx
)
5341 int ra
= rA(ctx
->opcode
);
5342 int rd
= rD(ctx
->opcode
);
5344 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5345 t0
= tcg_temp_new();
5346 gen_addr_reg_index(ctx
, t0
);
5347 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5348 t1
= tcg_temp_new();
5349 gen_addr_add(ctx
, t1
, t0
, 8);
5350 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5353 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5358 static void gen_stfqx(DisasContext
*ctx
)
5360 int rd
= rD(ctx
->opcode
);
5362 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5363 t0
= tcg_temp_new();
5364 gen_addr_reg_index(ctx
, t0
);
5365 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5366 gen_addr_add(ctx
, t0
, t0
, 8);
5367 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5371 /* BookE specific instructions */
5373 /* XXX: not implemented on 440 ? */
5374 static void gen_mfapidi(DisasContext
*ctx
)
5377 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5380 /* XXX: not implemented on 440 ? */
5381 static void gen_tlbiva(DisasContext
*ctx
)
5383 #if defined(CONFIG_USER_ONLY)
5384 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5387 if (unlikely(!ctx
->mem_idx
)) {
5388 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5391 t0
= tcg_temp_new();
5392 gen_addr_reg_index(ctx
, t0
);
5393 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5398 /* All 405 MAC instructions are translated here */
5399 static inline void gen_405_mulladd_insn(DisasContext
*ctx
, int opc2
, int opc3
,
5400 int ra
, int rb
, int rt
, int Rc
)
5404 t0
= tcg_temp_local_new();
5405 t1
= tcg_temp_local_new();
5407 switch (opc3
& 0x0D) {
5409 /* macchw - macchw. - macchwo - macchwo. */
5410 /* macchws - macchws. - macchwso - macchwso. */
5411 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5412 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5413 /* mulchw - mulchw. */
5414 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5415 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5416 tcg_gen_ext16s_tl(t1
, t1
);
5419 /* macchwu - macchwu. - macchwuo - macchwuo. */
5420 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5421 /* mulchwu - mulchwu. */
5422 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5423 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5424 tcg_gen_ext16u_tl(t1
, t1
);
5427 /* machhw - machhw. - machhwo - machhwo. */
5428 /* machhws - machhws. - machhwso - machhwso. */
5429 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5430 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5431 /* mulhhw - mulhhw. */
5432 tcg_gen_sari_tl(t0
, cpu_gpr
[ra
], 16);
5433 tcg_gen_ext16s_tl(t0
, t0
);
5434 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5435 tcg_gen_ext16s_tl(t1
, t1
);
5438 /* machhwu - machhwu. - machhwuo - machhwuo. */
5439 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5440 /* mulhhwu - mulhhwu. */
5441 tcg_gen_shri_tl(t0
, cpu_gpr
[ra
], 16);
5442 tcg_gen_ext16u_tl(t0
, t0
);
5443 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5444 tcg_gen_ext16u_tl(t1
, t1
);
5447 /* maclhw - maclhw. - maclhwo - maclhwo. */
5448 /* maclhws - maclhws. - maclhwso - maclhwso. */
5449 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5450 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5451 /* mullhw - mullhw. */
5452 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5453 tcg_gen_ext16s_tl(t1
, cpu_gpr
[rb
]);
5456 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5457 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5458 /* mullhwu - mullhwu. */
5459 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5460 tcg_gen_ext16u_tl(t1
, cpu_gpr
[rb
]);
5464 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5465 tcg_gen_mul_tl(t1
, t0
, t1
);
5467 /* nmultiply-and-accumulate (0x0E) */
5468 tcg_gen_sub_tl(t0
, cpu_gpr
[rt
], t1
);
5470 /* multiply-and-accumulate (0x0C) */
5471 tcg_gen_add_tl(t0
, cpu_gpr
[rt
], t1
);
5475 /* Check overflow and/or saturate */
5476 int l1
= gen_new_label();
5479 /* Start with XER OV disabled, the most likely case */
5480 tcg_gen_movi_tl(cpu_ov
, 0);
5484 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t1
);
5485 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
5486 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t0
);
5487 tcg_gen_brcondi_tl(TCG_COND_LT
, t1
, 0, l1
);
5490 tcg_gen_sari_tl(t0
, cpu_gpr
[rt
], 31);
5491 tcg_gen_xori_tl(t0
, t0
, 0x7fffffff);
5495 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
5498 tcg_gen_movi_tl(t0
, UINT32_MAX
);
5502 /* Check overflow */
5503 tcg_gen_movi_tl(cpu_ov
, 1);
5504 tcg_gen_movi_tl(cpu_so
, 1);
5507 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
5510 tcg_gen_mul_tl(cpu_gpr
[rt
], t0
, t1
);
5514 if (unlikely(Rc
) != 0) {
5516 gen_set_Rc0(ctx
, cpu_gpr
[rt
]);
5520 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5521 static void glue(gen_, name)(DisasContext *ctx) \
5523 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5524 rD(ctx->opcode), Rc(ctx->opcode)); \
5527 /* macchw - macchw. */
5528 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
5529 /* macchwo - macchwo. */
5530 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
5531 /* macchws - macchws. */
5532 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
5533 /* macchwso - macchwso. */
5534 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
5535 /* macchwsu - macchwsu. */
5536 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
5537 /* macchwsuo - macchwsuo. */
5538 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
5539 /* macchwu - macchwu. */
5540 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
5541 /* macchwuo - macchwuo. */
5542 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
5543 /* machhw - machhw. */
5544 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
5545 /* machhwo - machhwo. */
5546 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
5547 /* machhws - machhws. */
5548 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
5549 /* machhwso - machhwso. */
5550 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
5551 /* machhwsu - machhwsu. */
5552 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
5553 /* machhwsuo - machhwsuo. */
5554 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
5555 /* machhwu - machhwu. */
5556 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
5557 /* machhwuo - machhwuo. */
5558 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
5559 /* maclhw - maclhw. */
5560 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
5561 /* maclhwo - maclhwo. */
5562 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
5563 /* maclhws - maclhws. */
5564 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
5565 /* maclhwso - maclhwso. */
5566 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
5567 /* maclhwu - maclhwu. */
5568 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
5569 /* maclhwuo - maclhwuo. */
5570 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
5571 /* maclhwsu - maclhwsu. */
5572 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
5573 /* maclhwsuo - maclhwsuo. */
5574 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
5575 /* nmacchw - nmacchw. */
5576 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
5577 /* nmacchwo - nmacchwo. */
5578 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
5579 /* nmacchws - nmacchws. */
5580 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
5581 /* nmacchwso - nmacchwso. */
5582 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
5583 /* nmachhw - nmachhw. */
5584 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
5585 /* nmachhwo - nmachhwo. */
5586 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
5587 /* nmachhws - nmachhws. */
5588 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
5589 /* nmachhwso - nmachhwso. */
5590 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
5591 /* nmaclhw - nmaclhw. */
5592 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
5593 /* nmaclhwo - nmaclhwo. */
5594 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
5595 /* nmaclhws - nmaclhws. */
5596 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
5597 /* nmaclhwso - nmaclhwso. */
5598 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
5600 /* mulchw - mulchw. */
5601 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
5602 /* mulchwu - mulchwu. */
5603 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
5604 /* mulhhw - mulhhw. */
5605 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
5606 /* mulhhwu - mulhhwu. */
5607 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
5608 /* mullhw - mullhw. */
5609 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
5610 /* mullhwu - mullhwu. */
5611 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
5614 static void gen_mfdcr(DisasContext
*ctx
)
5616 #if defined(CONFIG_USER_ONLY)
5617 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5620 if (unlikely(!ctx
->mem_idx
)) {
5621 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5624 /* NIP cannot be restored if the memory exception comes from an helper */
5625 gen_update_nip(ctx
, ctx
->nip
- 4);
5626 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5627 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, dcrn
);
5628 tcg_temp_free(dcrn
);
5633 static void gen_mtdcr(DisasContext
*ctx
)
5635 #if defined(CONFIG_USER_ONLY)
5636 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5639 if (unlikely(!ctx
->mem_idx
)) {
5640 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5643 /* NIP cannot be restored if the memory exception comes from an helper */
5644 gen_update_nip(ctx
, ctx
->nip
- 4);
5645 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5646 gen_helper_store_dcr(cpu_env
, dcrn
, cpu_gpr
[rS(ctx
->opcode
)]);
5647 tcg_temp_free(dcrn
);
5652 /* XXX: not implemented on 440 ? */
5653 static void gen_mfdcrx(DisasContext
*ctx
)
5655 #if defined(CONFIG_USER_ONLY)
5656 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5658 if (unlikely(!ctx
->mem_idx
)) {
5659 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5662 /* NIP cannot be restored if the memory exception comes from an helper */
5663 gen_update_nip(ctx
, ctx
->nip
- 4);
5664 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5665 cpu_gpr
[rA(ctx
->opcode
)]);
5666 /* Note: Rc update flag set leads to undefined state of Rc0 */
5671 /* XXX: not implemented on 440 ? */
5672 static void gen_mtdcrx(DisasContext
*ctx
)
5674 #if defined(CONFIG_USER_ONLY)
5675 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5677 if (unlikely(!ctx
->mem_idx
)) {
5678 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5681 /* NIP cannot be restored if the memory exception comes from an helper */
5682 gen_update_nip(ctx
, ctx
->nip
- 4);
5683 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5684 cpu_gpr
[rS(ctx
->opcode
)]);
5685 /* Note: Rc update flag set leads to undefined state of Rc0 */
5689 /* mfdcrux (PPC 460) : user-mode access to DCR */
5690 static void gen_mfdcrux(DisasContext
*ctx
)
5692 /* NIP cannot be restored if the memory exception comes from an helper */
5693 gen_update_nip(ctx
, ctx
->nip
- 4);
5694 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5695 cpu_gpr
[rA(ctx
->opcode
)]);
5696 /* Note: Rc update flag set leads to undefined state of Rc0 */
5699 /* mtdcrux (PPC 460) : user-mode access to DCR */
5700 static void gen_mtdcrux(DisasContext
*ctx
)
5702 /* NIP cannot be restored if the memory exception comes from an helper */
5703 gen_update_nip(ctx
, ctx
->nip
- 4);
5704 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5705 cpu_gpr
[rS(ctx
->opcode
)]);
5706 /* Note: Rc update flag set leads to undefined state of Rc0 */
5710 static void gen_dccci(DisasContext
*ctx
)
5712 #if defined(CONFIG_USER_ONLY)
5713 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5715 if (unlikely(!ctx
->mem_idx
)) {
5716 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5719 /* interpreted as no-op */
5724 static void gen_dcread(DisasContext
*ctx
)
5726 #if defined(CONFIG_USER_ONLY)
5727 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5730 if (unlikely(!ctx
->mem_idx
)) {
5731 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5734 gen_set_access_type(ctx
, ACCESS_CACHE
);
5735 EA
= tcg_temp_new();
5736 gen_addr_reg_index(ctx
, EA
);
5737 val
= tcg_temp_new();
5738 gen_qemu_ld32u(ctx
, val
, EA
);
5740 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], EA
);
5746 static void gen_icbt_40x(DisasContext
*ctx
)
5748 /* interpreted as no-op */
5749 /* XXX: specification say this is treated as a load by the MMU
5750 * but does not generate any exception
5755 static void gen_iccci(DisasContext
*ctx
)
5757 #if defined(CONFIG_USER_ONLY)
5758 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5760 if (unlikely(!ctx
->mem_idx
)) {
5761 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5764 /* interpreted as no-op */
5769 static void gen_icread(DisasContext
*ctx
)
5771 #if defined(CONFIG_USER_ONLY)
5772 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5774 if (unlikely(!ctx
->mem_idx
)) {
5775 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5778 /* interpreted as no-op */
5782 /* rfci (mem_idx only) */
5783 static void gen_rfci_40x(DisasContext
*ctx
)
5785 #if defined(CONFIG_USER_ONLY)
5786 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5788 if (unlikely(!ctx
->mem_idx
)) {
5789 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5792 /* Restore CPU state */
5793 gen_helper_40x_rfci(cpu_env
);
5794 gen_sync_exception(ctx
);
5798 static void gen_rfci(DisasContext
*ctx
)
5800 #if defined(CONFIG_USER_ONLY)
5801 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5803 if (unlikely(!ctx
->mem_idx
)) {
5804 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5807 /* Restore CPU state */
5808 gen_helper_rfci(cpu_env
);
5809 gen_sync_exception(ctx
);
5813 /* BookE specific */
5815 /* XXX: not implemented on 440 ? */
5816 static void gen_rfdi(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 /* Restore CPU state */
5826 gen_helper_rfdi(cpu_env
);
5827 gen_sync_exception(ctx
);
5831 /* XXX: not implemented on 440 ? */
5832 static void gen_rfmci(DisasContext
*ctx
)
5834 #if defined(CONFIG_USER_ONLY)
5835 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5837 if (unlikely(!ctx
->mem_idx
)) {
5838 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5841 /* Restore CPU state */
5842 gen_helper_rfmci(cpu_env
);
5843 gen_sync_exception(ctx
);
5847 /* TLB management - PowerPC 405 implementation */
5850 static void gen_tlbre_40x(DisasContext
*ctx
)
5852 #if defined(CONFIG_USER_ONLY)
5853 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5855 if (unlikely(!ctx
->mem_idx
)) {
5856 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5859 switch (rB(ctx
->opcode
)) {
5861 gen_helper_4xx_tlbre_hi(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5862 cpu_gpr
[rA(ctx
->opcode
)]);
5865 gen_helper_4xx_tlbre_lo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5866 cpu_gpr
[rA(ctx
->opcode
)]);
5869 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5875 /* tlbsx - tlbsx. */
5876 static void gen_tlbsx_40x(DisasContext
*ctx
)
5878 #if defined(CONFIG_USER_ONLY)
5879 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5882 if (unlikely(!ctx
->mem_idx
)) {
5883 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5886 t0
= tcg_temp_new();
5887 gen_addr_reg_index(ctx
, t0
);
5888 gen_helper_4xx_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5890 if (Rc(ctx
->opcode
)) {
5891 int l1
= gen_new_label();
5892 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
5893 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
5894 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
5901 static void gen_tlbwe_40x(DisasContext
*ctx
)
5903 #if defined(CONFIG_USER_ONLY)
5904 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5906 if (unlikely(!ctx
->mem_idx
)) {
5907 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5910 switch (rB(ctx
->opcode
)) {
5912 gen_helper_4xx_tlbwe_hi(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5913 cpu_gpr
[rS(ctx
->opcode
)]);
5916 gen_helper_4xx_tlbwe_lo(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5917 cpu_gpr
[rS(ctx
->opcode
)]);
5920 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5926 /* TLB management - PowerPC 440 implementation */
5929 static void gen_tlbre_440(DisasContext
*ctx
)
5931 #if defined(CONFIG_USER_ONLY)
5932 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5934 if (unlikely(!ctx
->mem_idx
)) {
5935 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5938 switch (rB(ctx
->opcode
)) {
5943 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
5944 gen_helper_440_tlbre(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5945 t0
, cpu_gpr
[rA(ctx
->opcode
)]);
5946 tcg_temp_free_i32(t0
);
5950 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5956 /* tlbsx - tlbsx. */
5957 static void gen_tlbsx_440(DisasContext
*ctx
)
5959 #if defined(CONFIG_USER_ONLY)
5960 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5963 if (unlikely(!ctx
->mem_idx
)) {
5964 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5967 t0
= tcg_temp_new();
5968 gen_addr_reg_index(ctx
, t0
);
5969 gen_helper_440_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5971 if (Rc(ctx
->opcode
)) {
5972 int l1
= gen_new_label();
5973 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
5974 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
5975 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
5982 static void gen_tlbwe_440(DisasContext
*ctx
)
5984 #if defined(CONFIG_USER_ONLY)
5985 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5987 if (unlikely(!ctx
->mem_idx
)) {
5988 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5991 switch (rB(ctx
->opcode
)) {
5996 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
5997 gen_helper_440_tlbwe(cpu_env
, t0
, cpu_gpr
[rA(ctx
->opcode
)],
5998 cpu_gpr
[rS(ctx
->opcode
)]);
5999 tcg_temp_free_i32(t0
);
6003 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6009 /* TLB management - PowerPC BookE 2.06 implementation */
6012 static void gen_tlbre_booke206(DisasContext
*ctx
)
6014 #if defined(CONFIG_USER_ONLY)
6015 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6017 if (unlikely(!ctx
->mem_idx
)) {
6018 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6022 gen_helper_booke206_tlbre(cpu_env
);
6026 /* tlbsx - tlbsx. */
6027 static void gen_tlbsx_booke206(DisasContext
*ctx
)
6029 #if defined(CONFIG_USER_ONLY)
6030 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6033 if (unlikely(!ctx
->mem_idx
)) {
6034 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6038 if (rA(ctx
->opcode
)) {
6039 t0
= tcg_temp_new();
6040 tcg_gen_mov_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)]);
6042 t0
= tcg_const_tl(0);
6045 tcg_gen_add_tl(t0
, t0
, cpu_gpr
[rB(ctx
->opcode
)]);
6046 gen_helper_booke206_tlbsx(cpu_env
, t0
);
6051 static void gen_tlbwe_booke206(DisasContext
*ctx
)
6053 #if defined(CONFIG_USER_ONLY)
6054 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6056 if (unlikely(!ctx
->mem_idx
)) {
6057 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6060 gen_update_nip(ctx
, ctx
->nip
- 4);
6061 gen_helper_booke206_tlbwe(cpu_env
);
6065 static void gen_tlbivax_booke206(DisasContext
*ctx
)
6067 #if defined(CONFIG_USER_ONLY)
6068 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6071 if (unlikely(!ctx
->mem_idx
)) {
6072 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6076 t0
= tcg_temp_new();
6077 gen_addr_reg_index(ctx
, t0
);
6079 gen_helper_booke206_tlbivax(cpu_env
, t0
);
6083 static void gen_tlbilx_booke206(DisasContext
*ctx
)
6085 #if defined(CONFIG_USER_ONLY)
6086 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6089 if (unlikely(!ctx
->mem_idx
)) {
6090 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6094 t0
= tcg_temp_new();
6095 gen_addr_reg_index(ctx
, t0
);
6097 switch((ctx
->opcode
>> 21) & 0x3) {
6099 gen_helper_booke206_tlbilx0(cpu_env
, t0
);
6102 gen_helper_booke206_tlbilx1(cpu_env
, t0
);
6105 gen_helper_booke206_tlbilx3(cpu_env
, t0
);
6108 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6118 static void gen_wrtee(DisasContext
*ctx
)
6120 #if defined(CONFIG_USER_ONLY)
6121 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6124 if (unlikely(!ctx
->mem_idx
)) {
6125 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6128 t0
= tcg_temp_new();
6129 tcg_gen_andi_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)], (1 << MSR_EE
));
6130 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6131 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
6133 /* Stop translation to have a chance to raise an exception
6134 * if we just set msr_ee to 1
6136 gen_stop_exception(ctx
);
6141 static void gen_wrteei(DisasContext
*ctx
)
6143 #if defined(CONFIG_USER_ONLY)
6144 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6146 if (unlikely(!ctx
->mem_idx
)) {
6147 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6150 if (ctx
->opcode
& 0x00008000) {
6151 tcg_gen_ori_tl(cpu_msr
, cpu_msr
, (1 << MSR_EE
));
6152 /* Stop translation to have a chance to raise an exception */
6153 gen_stop_exception(ctx
);
6155 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6160 /* PowerPC 440 specific instructions */
6163 static void gen_dlmzb(DisasContext
*ctx
)
6165 TCGv_i32 t0
= tcg_const_i32(Rc(ctx
->opcode
));
6166 gen_helper_dlmzb(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
6167 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
6168 tcg_temp_free_i32(t0
);
6171 /* mbar replaces eieio on 440 */
6172 static void gen_mbar(DisasContext
*ctx
)
6174 /* interpreted as no-op */
6177 /* msync replaces sync on 440 */
6178 static void gen_msync_4xx(DisasContext
*ctx
)
6180 /* interpreted as no-op */
6184 static void gen_icbt_440(DisasContext
*ctx
)
6186 /* interpreted as no-op */
6187 /* XXX: specification say this is treated as a load by the MMU
6188 * but does not generate any exception
6192 /* Embedded.Processor Control */
6194 static void gen_msgclr(DisasContext
*ctx
)
6196 #if defined(CONFIG_USER_ONLY)
6197 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6199 if (unlikely(ctx
->mem_idx
== 0)) {
6200 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6204 gen_helper_msgclr(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6208 static void gen_msgsnd(DisasContext
*ctx
)
6210 #if defined(CONFIG_USER_ONLY)
6211 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6213 if (unlikely(ctx
->mem_idx
== 0)) {
6214 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6218 gen_helper_msgsnd(cpu_gpr
[rB(ctx
->opcode
)]);
6222 /*** Altivec vector extension ***/
6223 /* Altivec registers moves */
6225 static inline TCGv_ptr
gen_avr_ptr(int reg
)
6227 TCGv_ptr r
= tcg_temp_new_ptr();
6228 tcg_gen_addi_ptr(r
, cpu_env
, offsetof(CPUPPCState
, avr
[reg
]));
6232 #define GEN_VR_LDX(name, opc2, opc3) \
6233 static void glue(gen_, name)(DisasContext *ctx) \
6236 if (unlikely(!ctx->altivec_enabled)) { \
6237 gen_exception(ctx, POWERPC_EXCP_VPU); \
6240 gen_set_access_type(ctx, ACCESS_INT); \
6241 EA = tcg_temp_new(); \
6242 gen_addr_reg_index(ctx, EA); \
6243 tcg_gen_andi_tl(EA, EA, ~0xf); \
6244 if (ctx->le_mode) { \
6245 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6246 tcg_gen_addi_tl(EA, EA, 8); \
6247 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6249 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6250 tcg_gen_addi_tl(EA, EA, 8); \
6251 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6253 tcg_temp_free(EA); \
6256 #define GEN_VR_STX(name, opc2, opc3) \
6257 static void gen_st##name(DisasContext *ctx) \
6260 if (unlikely(!ctx->altivec_enabled)) { \
6261 gen_exception(ctx, POWERPC_EXCP_VPU); \
6264 gen_set_access_type(ctx, ACCESS_INT); \
6265 EA = tcg_temp_new(); \
6266 gen_addr_reg_index(ctx, EA); \
6267 tcg_gen_andi_tl(EA, EA, ~0xf); \
6268 if (ctx->le_mode) { \
6269 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6270 tcg_gen_addi_tl(EA, EA, 8); \
6271 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6273 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6274 tcg_gen_addi_tl(EA, EA, 8); \
6275 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6277 tcg_temp_free(EA); \
6280 #define GEN_VR_LVE(name, opc2, opc3) \
6281 static void gen_lve##name(DisasContext *ctx) \
6285 if (unlikely(!ctx->altivec_enabled)) { \
6286 gen_exception(ctx, POWERPC_EXCP_VPU); \
6289 gen_set_access_type(ctx, ACCESS_INT); \
6290 EA = tcg_temp_new(); \
6291 gen_addr_reg_index(ctx, EA); \
6292 rs = gen_avr_ptr(rS(ctx->opcode)); \
6293 gen_helper_lve##name(cpu_env, rs, EA); \
6294 tcg_temp_free(EA); \
6295 tcg_temp_free_ptr(rs); \
6298 #define GEN_VR_STVE(name, opc2, opc3) \
6299 static void gen_stve##name(DisasContext *ctx) \
6303 if (unlikely(!ctx->altivec_enabled)) { \
6304 gen_exception(ctx, POWERPC_EXCP_VPU); \
6307 gen_set_access_type(ctx, ACCESS_INT); \
6308 EA = tcg_temp_new(); \
6309 gen_addr_reg_index(ctx, EA); \
6310 rs = gen_avr_ptr(rS(ctx->opcode)); \
6311 gen_helper_stve##name(cpu_env, rs, EA); \
6312 tcg_temp_free(EA); \
6313 tcg_temp_free_ptr(rs); \
6316 GEN_VR_LDX(lvx
, 0x07, 0x03);
6317 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
6318 GEN_VR_LDX(lvxl
, 0x07, 0x0B);
6320 GEN_VR_LVE(bx
, 0x07, 0x00);
6321 GEN_VR_LVE(hx
, 0x07, 0x01);
6322 GEN_VR_LVE(wx
, 0x07, 0x02);
6324 GEN_VR_STX(svx
, 0x07, 0x07);
6325 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
6326 GEN_VR_STX(svxl
, 0x07, 0x0F);
6328 GEN_VR_STVE(bx
, 0x07, 0x04);
6329 GEN_VR_STVE(hx
, 0x07, 0x05);
6330 GEN_VR_STVE(wx
, 0x07, 0x06);
6332 static void gen_lvsl(DisasContext
*ctx
)
6336 if (unlikely(!ctx
->altivec_enabled
)) {
6337 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6340 EA
= tcg_temp_new();
6341 gen_addr_reg_index(ctx
, EA
);
6342 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6343 gen_helper_lvsl(rd
, EA
);
6345 tcg_temp_free_ptr(rd
);
6348 static void gen_lvsr(DisasContext
*ctx
)
6352 if (unlikely(!ctx
->altivec_enabled
)) {
6353 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6356 EA
= tcg_temp_new();
6357 gen_addr_reg_index(ctx
, EA
);
6358 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6359 gen_helper_lvsr(rd
, EA
);
6361 tcg_temp_free_ptr(rd
);
6364 static void gen_mfvscr(DisasContext
*ctx
)
6367 if (unlikely(!ctx
->altivec_enabled
)) {
6368 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6371 tcg_gen_movi_i64(cpu_avrh
[rD(ctx
->opcode
)], 0);
6372 t
= tcg_temp_new_i32();
6373 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUPPCState
, vscr
));
6374 tcg_gen_extu_i32_i64(cpu_avrl
[rD(ctx
->opcode
)], t
);
6375 tcg_temp_free_i32(t
);
6378 static void gen_mtvscr(DisasContext
*ctx
)
6381 if (unlikely(!ctx
->altivec_enabled
)) {
6382 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6385 p
= gen_avr_ptr(rD(ctx
->opcode
));
6386 gen_helper_mtvscr(cpu_env
, p
);
6387 tcg_temp_free_ptr(p
);
6390 /* Logical operations */
6391 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
6392 static void glue(gen_, name)(DisasContext *ctx) \
6394 if (unlikely(!ctx->altivec_enabled)) { \
6395 gen_exception(ctx, POWERPC_EXCP_VPU); \
6398 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6399 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6402 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16);
6403 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17);
6404 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18);
6405 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19);
6406 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20);
6408 #define GEN_VXFORM(name, opc2, opc3) \
6409 static void glue(gen_, name)(DisasContext *ctx) \
6411 TCGv_ptr ra, rb, rd; \
6412 if (unlikely(!ctx->altivec_enabled)) { \
6413 gen_exception(ctx, POWERPC_EXCP_VPU); \
6416 ra = gen_avr_ptr(rA(ctx->opcode)); \
6417 rb = gen_avr_ptr(rB(ctx->opcode)); \
6418 rd = gen_avr_ptr(rD(ctx->opcode)); \
6419 gen_helper_##name (rd, ra, rb); \
6420 tcg_temp_free_ptr(ra); \
6421 tcg_temp_free_ptr(rb); \
6422 tcg_temp_free_ptr(rd); \
6425 #define GEN_VXFORM_ENV(name, opc2, opc3) \
6426 static void glue(gen_, name)(DisasContext *ctx) \
6428 TCGv_ptr ra, rb, rd; \
6429 if (unlikely(!ctx->altivec_enabled)) { \
6430 gen_exception(ctx, POWERPC_EXCP_VPU); \
6433 ra = gen_avr_ptr(rA(ctx->opcode)); \
6434 rb = gen_avr_ptr(rB(ctx->opcode)); \
6435 rd = gen_avr_ptr(rD(ctx->opcode)); \
6436 gen_helper_##name(cpu_env, rd, ra, rb); \
6437 tcg_temp_free_ptr(ra); \
6438 tcg_temp_free_ptr(rb); \
6439 tcg_temp_free_ptr(rd); \
6442 GEN_VXFORM(vaddubm
, 0, 0);
6443 GEN_VXFORM(vadduhm
, 0, 1);
6444 GEN_VXFORM(vadduwm
, 0, 2);
6445 GEN_VXFORM(vsububm
, 0, 16);
6446 GEN_VXFORM(vsubuhm
, 0, 17);
6447 GEN_VXFORM(vsubuwm
, 0, 18);
6448 GEN_VXFORM(vmaxub
, 1, 0);
6449 GEN_VXFORM(vmaxuh
, 1, 1);
6450 GEN_VXFORM(vmaxuw
, 1, 2);
6451 GEN_VXFORM(vmaxsb
, 1, 4);
6452 GEN_VXFORM(vmaxsh
, 1, 5);
6453 GEN_VXFORM(vmaxsw
, 1, 6);
6454 GEN_VXFORM(vminub
, 1, 8);
6455 GEN_VXFORM(vminuh
, 1, 9);
6456 GEN_VXFORM(vminuw
, 1, 10);
6457 GEN_VXFORM(vminsb
, 1, 12);
6458 GEN_VXFORM(vminsh
, 1, 13);
6459 GEN_VXFORM(vminsw
, 1, 14);
6460 GEN_VXFORM(vavgub
, 1, 16);
6461 GEN_VXFORM(vavguh
, 1, 17);
6462 GEN_VXFORM(vavguw
, 1, 18);
6463 GEN_VXFORM(vavgsb
, 1, 20);
6464 GEN_VXFORM(vavgsh
, 1, 21);
6465 GEN_VXFORM(vavgsw
, 1, 22);
6466 GEN_VXFORM(vmrghb
, 6, 0);
6467 GEN_VXFORM(vmrghh
, 6, 1);
6468 GEN_VXFORM(vmrghw
, 6, 2);
6469 GEN_VXFORM(vmrglb
, 6, 4);
6470 GEN_VXFORM(vmrglh
, 6, 5);
6471 GEN_VXFORM(vmrglw
, 6, 6);
6472 GEN_VXFORM(vmuloub
, 4, 0);
6473 GEN_VXFORM(vmulouh
, 4, 1);
6474 GEN_VXFORM(vmulosb
, 4, 4);
6475 GEN_VXFORM(vmulosh
, 4, 5);
6476 GEN_VXFORM(vmuleub
, 4, 8);
6477 GEN_VXFORM(vmuleuh
, 4, 9);
6478 GEN_VXFORM(vmulesb
, 4, 12);
6479 GEN_VXFORM(vmulesh
, 4, 13);
6480 GEN_VXFORM(vslb
, 2, 4);
6481 GEN_VXFORM(vslh
, 2, 5);
6482 GEN_VXFORM(vslw
, 2, 6);
6483 GEN_VXFORM(vsrb
, 2, 8);
6484 GEN_VXFORM(vsrh
, 2, 9);
6485 GEN_VXFORM(vsrw
, 2, 10);
6486 GEN_VXFORM(vsrab
, 2, 12);
6487 GEN_VXFORM(vsrah
, 2, 13);
6488 GEN_VXFORM(vsraw
, 2, 14);
6489 GEN_VXFORM(vslo
, 6, 16);
6490 GEN_VXFORM(vsro
, 6, 17);
6491 GEN_VXFORM(vaddcuw
, 0, 6);
6492 GEN_VXFORM(vsubcuw
, 0, 22);
6493 GEN_VXFORM_ENV(vaddubs
, 0, 8);
6494 GEN_VXFORM_ENV(vadduhs
, 0, 9);
6495 GEN_VXFORM_ENV(vadduws
, 0, 10);
6496 GEN_VXFORM_ENV(vaddsbs
, 0, 12);
6497 GEN_VXFORM_ENV(vaddshs
, 0, 13);
6498 GEN_VXFORM_ENV(vaddsws
, 0, 14);
6499 GEN_VXFORM_ENV(vsububs
, 0, 24);
6500 GEN_VXFORM_ENV(vsubuhs
, 0, 25);
6501 GEN_VXFORM_ENV(vsubuws
, 0, 26);
6502 GEN_VXFORM_ENV(vsubsbs
, 0, 28);
6503 GEN_VXFORM_ENV(vsubshs
, 0, 29);
6504 GEN_VXFORM_ENV(vsubsws
, 0, 30);
6505 GEN_VXFORM(vrlb
, 2, 0);
6506 GEN_VXFORM(vrlh
, 2, 1);
6507 GEN_VXFORM(vrlw
, 2, 2);
6508 GEN_VXFORM(vsl
, 2, 7);
6509 GEN_VXFORM(vsr
, 2, 11);
6510 GEN_VXFORM_ENV(vpkuhum
, 7, 0);
6511 GEN_VXFORM_ENV(vpkuwum
, 7, 1);
6512 GEN_VXFORM_ENV(vpkuhus
, 7, 2);
6513 GEN_VXFORM_ENV(vpkuwus
, 7, 3);
6514 GEN_VXFORM_ENV(vpkshus
, 7, 4);
6515 GEN_VXFORM_ENV(vpkswus
, 7, 5);
6516 GEN_VXFORM_ENV(vpkshss
, 7, 6);
6517 GEN_VXFORM_ENV(vpkswss
, 7, 7);
6518 GEN_VXFORM(vpkpx
, 7, 12);
6519 GEN_VXFORM_ENV(vsum4ubs
, 4, 24);
6520 GEN_VXFORM_ENV(vsum4sbs
, 4, 28);
6521 GEN_VXFORM_ENV(vsum4shs
, 4, 25);
6522 GEN_VXFORM_ENV(vsum2sws
, 4, 26);
6523 GEN_VXFORM_ENV(vsumsws
, 4, 30);
6524 GEN_VXFORM_ENV(vaddfp
, 5, 0);
6525 GEN_VXFORM_ENV(vsubfp
, 5, 1);
6526 GEN_VXFORM_ENV(vmaxfp
, 5, 16);
6527 GEN_VXFORM_ENV(vminfp
, 5, 17);
6529 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
6530 static void glue(gen_, name)(DisasContext *ctx) \
6532 TCGv_ptr ra, rb, rd; \
6533 if (unlikely(!ctx->altivec_enabled)) { \
6534 gen_exception(ctx, POWERPC_EXCP_VPU); \
6537 ra = gen_avr_ptr(rA(ctx->opcode)); \
6538 rb = gen_avr_ptr(rB(ctx->opcode)); \
6539 rd = gen_avr_ptr(rD(ctx->opcode)); \
6540 gen_helper_##opname(cpu_env, rd, ra, rb); \
6541 tcg_temp_free_ptr(ra); \
6542 tcg_temp_free_ptr(rb); \
6543 tcg_temp_free_ptr(rd); \
6546 #define GEN_VXRFORM(name, opc2, opc3) \
6547 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
6548 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
6550 GEN_VXRFORM(vcmpequb
, 3, 0)
6551 GEN_VXRFORM(vcmpequh
, 3, 1)
6552 GEN_VXRFORM(vcmpequw
, 3, 2)
6553 GEN_VXRFORM(vcmpgtsb
, 3, 12)
6554 GEN_VXRFORM(vcmpgtsh
, 3, 13)
6555 GEN_VXRFORM(vcmpgtsw
, 3, 14)
6556 GEN_VXRFORM(vcmpgtub
, 3, 8)
6557 GEN_VXRFORM(vcmpgtuh
, 3, 9)
6558 GEN_VXRFORM(vcmpgtuw
, 3, 10)
6559 GEN_VXRFORM(vcmpeqfp
, 3, 3)
6560 GEN_VXRFORM(vcmpgefp
, 3, 7)
6561 GEN_VXRFORM(vcmpgtfp
, 3, 11)
6562 GEN_VXRFORM(vcmpbfp
, 3, 15)
6564 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
6565 static void glue(gen_, name)(DisasContext *ctx) \
6569 if (unlikely(!ctx->altivec_enabled)) { \
6570 gen_exception(ctx, POWERPC_EXCP_VPU); \
6573 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6574 rd = gen_avr_ptr(rD(ctx->opcode)); \
6575 gen_helper_##name (rd, simm); \
6576 tcg_temp_free_i32(simm); \
6577 tcg_temp_free_ptr(rd); \
6580 GEN_VXFORM_SIMM(vspltisb
, 6, 12);
6581 GEN_VXFORM_SIMM(vspltish
, 6, 13);
6582 GEN_VXFORM_SIMM(vspltisw
, 6, 14);
6584 #define GEN_VXFORM_NOA(name, opc2, opc3) \
6585 static void glue(gen_, name)(DisasContext *ctx) \
6588 if (unlikely(!ctx->altivec_enabled)) { \
6589 gen_exception(ctx, POWERPC_EXCP_VPU); \
6592 rb = gen_avr_ptr(rB(ctx->opcode)); \
6593 rd = gen_avr_ptr(rD(ctx->opcode)); \
6594 gen_helper_##name (rd, rb); \
6595 tcg_temp_free_ptr(rb); \
6596 tcg_temp_free_ptr(rd); \
6599 #define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
6600 static void glue(gen_, name)(DisasContext *ctx) \
6604 if (unlikely(!ctx->altivec_enabled)) { \
6605 gen_exception(ctx, POWERPC_EXCP_VPU); \
6608 rb = gen_avr_ptr(rB(ctx->opcode)); \
6609 rd = gen_avr_ptr(rD(ctx->opcode)); \
6610 gen_helper_##name(cpu_env, rd, rb); \
6611 tcg_temp_free_ptr(rb); \
6612 tcg_temp_free_ptr(rd); \
6615 GEN_VXFORM_NOA(vupkhsb
, 7, 8);
6616 GEN_VXFORM_NOA(vupkhsh
, 7, 9);
6617 GEN_VXFORM_NOA(vupklsb
, 7, 10);
6618 GEN_VXFORM_NOA(vupklsh
, 7, 11);
6619 GEN_VXFORM_NOA(vupkhpx
, 7, 13);
6620 GEN_VXFORM_NOA(vupklpx
, 7, 15);
6621 GEN_VXFORM_NOA_ENV(vrefp
, 5, 4);
6622 GEN_VXFORM_NOA_ENV(vrsqrtefp
, 5, 5);
6623 GEN_VXFORM_NOA_ENV(vexptefp
, 5, 6);
6624 GEN_VXFORM_NOA_ENV(vlogefp
, 5, 7);
6625 GEN_VXFORM_NOA_ENV(vrfim
, 5, 8);
6626 GEN_VXFORM_NOA_ENV(vrfin
, 5, 9);
6627 GEN_VXFORM_NOA_ENV(vrfip
, 5, 10);
6628 GEN_VXFORM_NOA_ENV(vrfiz
, 5, 11);
6630 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
6631 static void glue(gen_, name)(DisasContext *ctx) \
6635 if (unlikely(!ctx->altivec_enabled)) { \
6636 gen_exception(ctx, POWERPC_EXCP_VPU); \
6639 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6640 rd = gen_avr_ptr(rD(ctx->opcode)); \
6641 gen_helper_##name (rd, simm); \
6642 tcg_temp_free_i32(simm); \
6643 tcg_temp_free_ptr(rd); \
6646 #define GEN_VXFORM_UIMM(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 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
6656 rb = gen_avr_ptr(rB(ctx->opcode)); \
6657 rd = gen_avr_ptr(rD(ctx->opcode)); \
6658 gen_helper_##name (rd, rb, uimm); \
6659 tcg_temp_free_i32(uimm); \
6660 tcg_temp_free_ptr(rb); \
6661 tcg_temp_free_ptr(rd); \
6664 #define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
6665 static void glue(gen_, name)(DisasContext *ctx) \
6670 if (unlikely(!ctx->altivec_enabled)) { \
6671 gen_exception(ctx, POWERPC_EXCP_VPU); \
6674 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
6675 rb = gen_avr_ptr(rB(ctx->opcode)); \
6676 rd = gen_avr_ptr(rD(ctx->opcode)); \
6677 gen_helper_##name(cpu_env, rd, rb, uimm); \
6678 tcg_temp_free_i32(uimm); \
6679 tcg_temp_free_ptr(rb); \
6680 tcg_temp_free_ptr(rd); \
6683 GEN_VXFORM_UIMM(vspltb
, 6, 8);
6684 GEN_VXFORM_UIMM(vsplth
, 6, 9);
6685 GEN_VXFORM_UIMM(vspltw
, 6, 10);
6686 GEN_VXFORM_UIMM_ENV(vcfux
, 5, 12);
6687 GEN_VXFORM_UIMM_ENV(vcfsx
, 5, 13);
6688 GEN_VXFORM_UIMM_ENV(vctuxs
, 5, 14);
6689 GEN_VXFORM_UIMM_ENV(vctsxs
, 5, 15);
6691 static void gen_vsldoi(DisasContext
*ctx
)
6693 TCGv_ptr ra
, rb
, rd
;
6695 if (unlikely(!ctx
->altivec_enabled
)) {
6696 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6699 ra
= gen_avr_ptr(rA(ctx
->opcode
));
6700 rb
= gen_avr_ptr(rB(ctx
->opcode
));
6701 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6702 sh
= tcg_const_i32(VSH(ctx
->opcode
));
6703 gen_helper_vsldoi (rd
, ra
, rb
, sh
);
6704 tcg_temp_free_ptr(ra
);
6705 tcg_temp_free_ptr(rb
);
6706 tcg_temp_free_ptr(rd
);
6707 tcg_temp_free_i32(sh
);
6710 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
6711 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
6713 TCGv_ptr ra, rb, rc, rd; \
6714 if (unlikely(!ctx->altivec_enabled)) { \
6715 gen_exception(ctx, POWERPC_EXCP_VPU); \
6718 ra = gen_avr_ptr(rA(ctx->opcode)); \
6719 rb = gen_avr_ptr(rB(ctx->opcode)); \
6720 rc = gen_avr_ptr(rC(ctx->opcode)); \
6721 rd = gen_avr_ptr(rD(ctx->opcode)); \
6722 if (Rc(ctx->opcode)) { \
6723 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
6725 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
6727 tcg_temp_free_ptr(ra); \
6728 tcg_temp_free_ptr(rb); \
6729 tcg_temp_free_ptr(rc); \
6730 tcg_temp_free_ptr(rd); \
6733 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16)
6735 static void gen_vmladduhm(DisasContext
*ctx
)
6737 TCGv_ptr ra
, rb
, rc
, rd
;
6738 if (unlikely(!ctx
->altivec_enabled
)) {
6739 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6742 ra
= gen_avr_ptr(rA(ctx
->opcode
));
6743 rb
= gen_avr_ptr(rB(ctx
->opcode
));
6744 rc
= gen_avr_ptr(rC(ctx
->opcode
));
6745 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6746 gen_helper_vmladduhm(rd
, ra
, rb
, rc
);
6747 tcg_temp_free_ptr(ra
);
6748 tcg_temp_free_ptr(rb
);
6749 tcg_temp_free_ptr(rc
);
6750 tcg_temp_free_ptr(rd
);
6753 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18)
6754 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19)
6755 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20)
6756 GEN_VAFORM_PAIRED(vsel
, vperm
, 21)
6757 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23)
6759 /*** SPE extension ***/
6760 /* Register moves */
6763 static inline void gen_evmra(DisasContext
*ctx
)
6766 if (unlikely(!ctx
->spe_enabled
)) {
6767 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
6771 #if defined(TARGET_PPC64)
6773 tcg_gen_mov_i64(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6776 tcg_gen_st_i64(cpu_gpr
[rA(ctx
->opcode
)],
6778 offsetof(CPUPPCState
, spe_acc
));
6780 TCGv_i64 tmp
= tcg_temp_new_i64();
6782 /* tmp := rA_lo + rA_hi << 32 */
6783 tcg_gen_concat_i32_i64(tmp
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6785 /* spe_acc := tmp */
6786 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
6787 tcg_temp_free_i64(tmp
);
6790 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6791 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6795 static inline void gen_load_gpr64(TCGv_i64 t
, int reg
)
6797 #if defined(TARGET_PPC64)
6798 tcg_gen_mov_i64(t
, cpu_gpr
[reg
]);
6800 tcg_gen_concat_i32_i64(t
, cpu_gpr
[reg
], cpu_gprh
[reg
]);
6804 static inline void gen_store_gpr64(int reg
, TCGv_i64 t
)
6806 #if defined(TARGET_PPC64)
6807 tcg_gen_mov_i64(cpu_gpr
[reg
], t
);
6809 TCGv_i64 tmp
= tcg_temp_new_i64();
6810 tcg_gen_trunc_i64_i32(cpu_gpr
[reg
], t
);
6811 tcg_gen_shri_i64(tmp
, t
, 32);
6812 tcg_gen_trunc_i64_i32(cpu_gprh
[reg
], tmp
);
6813 tcg_temp_free_i64(tmp
);
6817 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
6818 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
6820 if (Rc(ctx->opcode)) \
6826 /* Handler for undefined SPE opcodes */
6827 static inline void gen_speundef(DisasContext
*ctx
)
6829 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6833 #if defined(TARGET_PPC64)
6834 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
6835 static inline void gen_##name(DisasContext *ctx) \
6837 if (unlikely(!ctx->spe_enabled)) { \
6838 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6841 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6842 cpu_gpr[rB(ctx->opcode)]); \
6845 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
6846 static inline void gen_##name(DisasContext *ctx) \
6848 if (unlikely(!ctx->spe_enabled)) { \
6849 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6852 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6853 cpu_gpr[rB(ctx->opcode)]); \
6854 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6855 cpu_gprh[rB(ctx->opcode)]); \
6859 GEN_SPEOP_LOGIC2(evand
, tcg_gen_and_tl
);
6860 GEN_SPEOP_LOGIC2(evandc
, tcg_gen_andc_tl
);
6861 GEN_SPEOP_LOGIC2(evxor
, tcg_gen_xor_tl
);
6862 GEN_SPEOP_LOGIC2(evor
, tcg_gen_or_tl
);
6863 GEN_SPEOP_LOGIC2(evnor
, tcg_gen_nor_tl
);
6864 GEN_SPEOP_LOGIC2(eveqv
, tcg_gen_eqv_tl
);
6865 GEN_SPEOP_LOGIC2(evorc
, tcg_gen_orc_tl
);
6866 GEN_SPEOP_LOGIC2(evnand
, tcg_gen_nand_tl
);
6868 /* SPE logic immediate */
6869 #if defined(TARGET_PPC64)
6870 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
6871 static inline void gen_##name(DisasContext *ctx) \
6873 if (unlikely(!ctx->spe_enabled)) { \
6874 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6877 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6878 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6879 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6880 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6881 tcg_opi(t0, t0, rB(ctx->opcode)); \
6882 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6883 tcg_gen_trunc_i64_i32(t1, t2); \
6884 tcg_temp_free_i64(t2); \
6885 tcg_opi(t1, t1, rB(ctx->opcode)); \
6886 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6887 tcg_temp_free_i32(t0); \
6888 tcg_temp_free_i32(t1); \
6891 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
6892 static inline void gen_##name(DisasContext *ctx) \
6894 if (unlikely(!ctx->spe_enabled)) { \
6895 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6898 tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6900 tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6904 GEN_SPEOP_TCG_LOGIC_IMM2(evslwi
, tcg_gen_shli_i32
);
6905 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu
, tcg_gen_shri_i32
);
6906 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis
, tcg_gen_sari_i32
);
6907 GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi
, tcg_gen_rotli_i32
);
6909 /* SPE arithmetic */
6910 #if defined(TARGET_PPC64)
6911 #define GEN_SPEOP_ARITH1(name, tcg_op) \
6912 static inline void gen_##name(DisasContext *ctx) \
6914 if (unlikely(!ctx->spe_enabled)) { \
6915 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6918 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6919 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6920 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6921 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6923 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6924 tcg_gen_trunc_i64_i32(t1, t2); \
6925 tcg_temp_free_i64(t2); \
6927 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6928 tcg_temp_free_i32(t0); \
6929 tcg_temp_free_i32(t1); \
6932 #define GEN_SPEOP_ARITH1(name, tcg_op) \
6933 static inline void gen_##name(DisasContext *ctx) \
6935 if (unlikely(!ctx->spe_enabled)) { \
6936 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6939 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
6940 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
6944 static inline void gen_op_evabs(TCGv_i32 ret
, TCGv_i32 arg1
)
6946 int l1
= gen_new_label();
6947 int l2
= gen_new_label();
6949 tcg_gen_brcondi_i32(TCG_COND_GE
, arg1
, 0, l1
);
6950 tcg_gen_neg_i32(ret
, arg1
);
6953 tcg_gen_mov_i32(ret
, arg1
);
6956 GEN_SPEOP_ARITH1(evabs
, gen_op_evabs
);
6957 GEN_SPEOP_ARITH1(evneg
, tcg_gen_neg_i32
);
6958 GEN_SPEOP_ARITH1(evextsb
, tcg_gen_ext8s_i32
);
6959 GEN_SPEOP_ARITH1(evextsh
, tcg_gen_ext16s_i32
);
6960 static inline void gen_op_evrndw(TCGv_i32 ret
, TCGv_i32 arg1
)
6962 tcg_gen_addi_i32(ret
, arg1
, 0x8000);
6963 tcg_gen_ext16u_i32(ret
, ret
);
6965 GEN_SPEOP_ARITH1(evrndw
, gen_op_evrndw
);
6966 GEN_SPEOP_ARITH1(evcntlsw
, gen_helper_cntlsw32
);
6967 GEN_SPEOP_ARITH1(evcntlzw
, gen_helper_cntlzw32
);
6969 #if defined(TARGET_PPC64)
6970 #define GEN_SPEOP_ARITH2(name, tcg_op) \
6971 static inline void gen_##name(DisasContext *ctx) \
6973 if (unlikely(!ctx->spe_enabled)) { \
6974 gen_exception(ctx, POWERPC_EXCP_SPEU); \
6977 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6978 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6979 TCGv_i32 t2 = tcg_temp_local_new_i32(); \
6980 TCGv_i64 t3 = tcg_temp_local_new_i64(); \
6981 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6982 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
6983 tcg_op(t0, t0, t2); \
6984 tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
6985 tcg_gen_trunc_i64_i32(t1, t3); \
6986 tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
6987 tcg_gen_trunc_i64_i32(t2, t3); \
6988 tcg_temp_free_i64(t3); \
6989 tcg_op(t1, t1, t2); \
6990 tcg_temp_free_i32(t2); \
6991 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6992 tcg_temp_free_i32(t0); \
6993 tcg_temp_free_i32(t1); \
6996 #define GEN_SPEOP_ARITH2(name, tcg_op) \
6997 static inline void gen_##name(DisasContext *ctx) \
6999 if (unlikely(!ctx->spe_enabled)) { \
7000 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7003 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7004 cpu_gpr[rB(ctx->opcode)]); \
7005 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7006 cpu_gprh[rB(ctx->opcode)]); \
7010 static inline void gen_op_evsrwu(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7015 l1
= gen_new_label();
7016 l2
= gen_new_label();
7017 t0
= tcg_temp_local_new_i32();
7018 /* No error here: 6 bits are used */
7019 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
7020 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
7021 tcg_gen_shr_i32(ret
, arg1
, t0
);
7024 tcg_gen_movi_i32(ret
, 0);
7026 tcg_temp_free_i32(t0
);
7028 GEN_SPEOP_ARITH2(evsrwu
, gen_op_evsrwu
);
7029 static inline void gen_op_evsrws(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7034 l1
= gen_new_label();
7035 l2
= gen_new_label();
7036 t0
= tcg_temp_local_new_i32();
7037 /* No error here: 6 bits are used */
7038 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
7039 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
7040 tcg_gen_sar_i32(ret
, arg1
, t0
);
7043 tcg_gen_movi_i32(ret
, 0);
7045 tcg_temp_free_i32(t0
);
7047 GEN_SPEOP_ARITH2(evsrws
, gen_op_evsrws
);
7048 static inline void gen_op_evslw(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7053 l1
= gen_new_label();
7054 l2
= gen_new_label();
7055 t0
= tcg_temp_local_new_i32();
7056 /* No error here: 6 bits are used */
7057 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
7058 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
7059 tcg_gen_shl_i32(ret
, arg1
, t0
);
7062 tcg_gen_movi_i32(ret
, 0);
7064 tcg_temp_free_i32(t0
);
7066 GEN_SPEOP_ARITH2(evslw
, gen_op_evslw
);
7067 static inline void gen_op_evrlw(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7069 TCGv_i32 t0
= tcg_temp_new_i32();
7070 tcg_gen_andi_i32(t0
, arg2
, 0x1F);
7071 tcg_gen_rotl_i32(ret
, arg1
, t0
);
7072 tcg_temp_free_i32(t0
);
7074 GEN_SPEOP_ARITH2(evrlw
, gen_op_evrlw
);
7075 static inline void gen_evmergehi(DisasContext
*ctx
)
7077 if (unlikely(!ctx
->spe_enabled
)) {
7078 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7081 #if defined(TARGET_PPC64)
7082 TCGv t0
= tcg_temp_new();
7083 TCGv t1
= tcg_temp_new();
7084 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
7085 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
7086 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7090 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7091 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7094 GEN_SPEOP_ARITH2(evaddw
, tcg_gen_add_i32
);
7095 static inline void gen_op_evsubf(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7097 tcg_gen_sub_i32(ret
, arg2
, arg1
);
7099 GEN_SPEOP_ARITH2(evsubfw
, gen_op_evsubf
);
7101 /* SPE arithmetic immediate */
7102 #if defined(TARGET_PPC64)
7103 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
7104 static inline void gen_##name(DisasContext *ctx) \
7106 if (unlikely(!ctx->spe_enabled)) { \
7107 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7110 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7111 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7112 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7113 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
7114 tcg_op(t0, t0, rA(ctx->opcode)); \
7115 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
7116 tcg_gen_trunc_i64_i32(t1, t2); \
7117 tcg_temp_free_i64(t2); \
7118 tcg_op(t1, t1, rA(ctx->opcode)); \
7119 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7120 tcg_temp_free_i32(t0); \
7121 tcg_temp_free_i32(t1); \
7124 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
7125 static inline void gen_##name(DisasContext *ctx) \
7127 if (unlikely(!ctx->spe_enabled)) { \
7128 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7131 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
7133 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
7137 GEN_SPEOP_ARITH_IMM2(evaddiw
, tcg_gen_addi_i32
);
7138 GEN_SPEOP_ARITH_IMM2(evsubifw
, tcg_gen_subi_i32
);
7140 /* SPE comparison */
7141 #if defined(TARGET_PPC64)
7142 #define GEN_SPEOP_COMP(name, tcg_cond) \
7143 static inline void gen_##name(DisasContext *ctx) \
7145 if (unlikely(!ctx->spe_enabled)) { \
7146 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7149 int l1 = gen_new_label(); \
7150 int l2 = gen_new_label(); \
7151 int l3 = gen_new_label(); \
7152 int l4 = gen_new_label(); \
7153 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7154 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7155 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7156 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7157 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
7158 tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
7159 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
7161 gen_set_label(l1); \
7162 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
7163 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
7164 gen_set_label(l2); \
7165 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7166 tcg_gen_trunc_i64_i32(t0, t2); \
7167 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
7168 tcg_gen_trunc_i64_i32(t1, t2); \
7169 tcg_temp_free_i64(t2); \
7170 tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
7171 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7172 ~(CRF_CH | CRF_CH_AND_CL)); \
7174 gen_set_label(l3); \
7175 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7176 CRF_CH | CRF_CH_OR_CL); \
7177 gen_set_label(l4); \
7178 tcg_temp_free_i32(t0); \
7179 tcg_temp_free_i32(t1); \
7182 #define GEN_SPEOP_COMP(name, tcg_cond) \
7183 static inline void gen_##name(DisasContext *ctx) \
7185 if (unlikely(!ctx->spe_enabled)) { \
7186 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7189 int l1 = gen_new_label(); \
7190 int l2 = gen_new_label(); \
7191 int l3 = gen_new_label(); \
7192 int l4 = gen_new_label(); \
7194 tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
7195 cpu_gpr[rB(ctx->opcode)], l1); \
7196 tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
7198 gen_set_label(l1); \
7199 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
7200 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
7201 gen_set_label(l2); \
7202 tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
7203 cpu_gprh[rB(ctx->opcode)], l3); \
7204 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7205 ~(CRF_CH | CRF_CH_AND_CL)); \
7207 gen_set_label(l3); \
7208 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7209 CRF_CH | CRF_CH_OR_CL); \
7210 gen_set_label(l4); \
7213 GEN_SPEOP_COMP(evcmpgtu
, TCG_COND_GTU
);
7214 GEN_SPEOP_COMP(evcmpgts
, TCG_COND_GT
);
7215 GEN_SPEOP_COMP(evcmpltu
, TCG_COND_LTU
);
7216 GEN_SPEOP_COMP(evcmplts
, TCG_COND_LT
);
7217 GEN_SPEOP_COMP(evcmpeq
, TCG_COND_EQ
);
7220 static inline void gen_brinc(DisasContext
*ctx
)
7222 /* Note: brinc is usable even if SPE is disabled */
7223 gen_helper_brinc(cpu_gpr
[rD(ctx
->opcode
)],
7224 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7226 static inline void gen_evmergelo(DisasContext
*ctx
)
7228 if (unlikely(!ctx
->spe_enabled
)) {
7229 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7232 #if defined(TARGET_PPC64)
7233 TCGv t0
= tcg_temp_new();
7234 TCGv t1
= tcg_temp_new();
7235 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
7236 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
7237 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7241 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7242 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7245 static inline void gen_evmergehilo(DisasContext
*ctx
)
7247 if (unlikely(!ctx
->spe_enabled
)) {
7248 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7251 #if defined(TARGET_PPC64)
7252 TCGv t0
= tcg_temp_new();
7253 TCGv t1
= tcg_temp_new();
7254 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
7255 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
7256 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7260 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7261 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7264 static inline void gen_evmergelohi(DisasContext
*ctx
)
7266 if (unlikely(!ctx
->spe_enabled
)) {
7267 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7270 #if defined(TARGET_PPC64)
7271 TCGv t0
= tcg_temp_new();
7272 TCGv t1
= tcg_temp_new();
7273 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
7274 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
7275 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7279 if (rD(ctx
->opcode
) == rA(ctx
->opcode
)) {
7280 TCGv_i32 tmp
= tcg_temp_new_i32();
7281 tcg_gen_mov_i32(tmp
, cpu_gpr
[rA(ctx
->opcode
)]);
7282 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7283 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], tmp
);
7284 tcg_temp_free_i32(tmp
);
7286 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7287 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7291 static inline void gen_evsplati(DisasContext
*ctx
)
7293 uint64_t imm
= ((int32_t)(rA(ctx
->opcode
) << 27)) >> 27;
7295 #if defined(TARGET_PPC64)
7296 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
7298 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
7299 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
7302 static inline void gen_evsplatfi(DisasContext
*ctx
)
7304 uint64_t imm
= rA(ctx
->opcode
) << 27;
7306 #if defined(TARGET_PPC64)
7307 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
7309 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
7310 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
7314 static inline void gen_evsel(DisasContext
*ctx
)
7316 int l1
= gen_new_label();
7317 int l2
= gen_new_label();
7318 int l3
= gen_new_label();
7319 int l4
= gen_new_label();
7320 TCGv_i32 t0
= tcg_temp_local_new_i32();
7321 #if defined(TARGET_PPC64)
7322 TCGv t1
= tcg_temp_local_new();
7323 TCGv t2
= tcg_temp_local_new();
7325 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 3);
7326 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
7327 #if defined(TARGET_PPC64)
7328 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
7330 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7334 #if defined(TARGET_PPC64)
7335 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
7337 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7340 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 2);
7341 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l3
);
7342 #if defined(TARGET_PPC64)
7343 tcg_gen_ext32u_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)]);
7345 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7349 #if defined(TARGET_PPC64)
7350 tcg_gen_ext32u_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)]);
7352 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7355 tcg_temp_free_i32(t0
);
7356 #if defined(TARGET_PPC64)
7357 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
, t2
);
7363 static void gen_evsel0(DisasContext
*ctx
)
7368 static void gen_evsel1(DisasContext
*ctx
)
7373 static void gen_evsel2(DisasContext
*ctx
)
7378 static void gen_evsel3(DisasContext
*ctx
)
7385 static inline void gen_evmwumi(DisasContext
*ctx
)
7389 if (unlikely(!ctx
->spe_enabled
)) {
7390 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7394 t0
= tcg_temp_new_i64();
7395 t1
= tcg_temp_new_i64();
7397 /* t0 := rA; t1 := rB */
7398 #if defined(TARGET_PPC64)
7399 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7400 tcg_gen_ext32u_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7402 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7403 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7406 tcg_gen_mul_i64(t0
, t0
, t1
); /* t0 := rA * rB */
7408 gen_store_gpr64(rD(ctx
->opcode
), t0
); /* rD := t0 */
7410 tcg_temp_free_i64(t0
);
7411 tcg_temp_free_i64(t1
);
7414 static inline void gen_evmwumia(DisasContext
*ctx
)
7418 if (unlikely(!ctx
->spe_enabled
)) {
7419 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7423 gen_evmwumi(ctx
); /* rD := rA * rB */
7425 tmp
= tcg_temp_new_i64();
7428 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7429 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7430 tcg_temp_free_i64(tmp
);
7433 static inline void gen_evmwumiaa(DisasContext
*ctx
)
7438 if (unlikely(!ctx
->spe_enabled
)) {
7439 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7443 gen_evmwumi(ctx
); /* rD := rA * rB */
7445 acc
= tcg_temp_new_i64();
7446 tmp
= tcg_temp_new_i64();
7449 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7452 tcg_gen_ld_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7454 /* acc := tmp + acc */
7455 tcg_gen_add_i64(acc
, acc
, tmp
);
7458 tcg_gen_st_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7461 gen_store_gpr64(rD(ctx
->opcode
), acc
);
7463 tcg_temp_free_i64(acc
);
7464 tcg_temp_free_i64(tmp
);
7467 static inline void gen_evmwsmi(DisasContext
*ctx
)
7471 if (unlikely(!ctx
->spe_enabled
)) {
7472 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7476 t0
= tcg_temp_new_i64();
7477 t1
= tcg_temp_new_i64();
7479 /* t0 := rA; t1 := rB */
7480 #if defined(TARGET_PPC64)
7481 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7482 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7484 tcg_gen_ext_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7485 tcg_gen_ext_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7488 tcg_gen_mul_i64(t0
, t0
, t1
); /* t0 := rA * rB */
7490 gen_store_gpr64(rD(ctx
->opcode
), t0
); /* rD := t0 */
7492 tcg_temp_free_i64(t0
);
7493 tcg_temp_free_i64(t1
);
7496 static inline void gen_evmwsmia(DisasContext
*ctx
)
7500 gen_evmwsmi(ctx
); /* rD := rA * rB */
7502 tmp
= tcg_temp_new_i64();
7505 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7506 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7508 tcg_temp_free_i64(tmp
);
7511 static inline void gen_evmwsmiaa(DisasContext
*ctx
)
7513 TCGv_i64 acc
= tcg_temp_new_i64();
7514 TCGv_i64 tmp
= tcg_temp_new_i64();
7516 gen_evmwsmi(ctx
); /* rD := rA * rB */
7518 acc
= tcg_temp_new_i64();
7519 tmp
= tcg_temp_new_i64();
7522 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7525 tcg_gen_ld_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7527 /* acc := tmp + acc */
7528 tcg_gen_add_i64(acc
, acc
, tmp
);
7531 tcg_gen_st_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7534 gen_store_gpr64(rD(ctx
->opcode
), acc
);
7536 tcg_temp_free_i64(acc
);
7537 tcg_temp_free_i64(tmp
);
7540 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7541 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7542 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7543 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7544 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
7545 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
7546 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
7547 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE
); //
7548 GEN_SPE(evmra
, speundef
, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE
);
7549 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
); ////
7550 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7551 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7552 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7553 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
7554 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
7555 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
7556 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
); ////
7557 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7558 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7559 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE
);
7560 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7561 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7562 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE
); //
7563 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE
);
7564 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7565 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7566 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE
); ////
7567 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE
); ////
7568 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE
); ////
7570 /* SPE load and stores */
7571 static inline void gen_addr_spe_imm_index(DisasContext
*ctx
, TCGv EA
, int sh
)
7573 target_ulong uimm
= rB(ctx
->opcode
);
7575 if (rA(ctx
->opcode
) == 0) {
7576 tcg_gen_movi_tl(EA
, uimm
<< sh
);
7578 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], uimm
<< sh
);
7579 #if defined(TARGET_PPC64)
7580 if (!ctx
->sf_mode
) {
7581 tcg_gen_ext32u_tl(EA
, EA
);
7587 static inline void gen_op_evldd(DisasContext
*ctx
, TCGv addr
)
7589 #if defined(TARGET_PPC64)
7590 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7592 TCGv_i64 t0
= tcg_temp_new_i64();
7593 gen_qemu_ld64(ctx
, t0
, addr
);
7594 tcg_gen_trunc_i64_i32(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7595 tcg_gen_shri_i64(t0
, t0
, 32);
7596 tcg_gen_trunc_i64_i32(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7597 tcg_temp_free_i64(t0
);
7601 static inline void gen_op_evldw(DisasContext
*ctx
, TCGv addr
)
7603 #if defined(TARGET_PPC64)
7604 TCGv t0
= tcg_temp_new();
7605 gen_qemu_ld32u(ctx
, t0
, addr
);
7606 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7607 gen_addr_add(ctx
, addr
, addr
, 4);
7608 gen_qemu_ld32u(ctx
, t0
, addr
);
7609 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7612 gen_qemu_ld32u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7613 gen_addr_add(ctx
, addr
, addr
, 4);
7614 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7618 static inline void gen_op_evldh(DisasContext
*ctx
, TCGv addr
)
7620 TCGv t0
= tcg_temp_new();
7621 #if defined(TARGET_PPC64)
7622 gen_qemu_ld16u(ctx
, t0
, addr
);
7623 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7624 gen_addr_add(ctx
, addr
, addr
, 2);
7625 gen_qemu_ld16u(ctx
, t0
, addr
);
7626 tcg_gen_shli_tl(t0
, t0
, 32);
7627 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7628 gen_addr_add(ctx
, addr
, addr
, 2);
7629 gen_qemu_ld16u(ctx
, t0
, addr
);
7630 tcg_gen_shli_tl(t0
, t0
, 16);
7631 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7632 gen_addr_add(ctx
, addr
, addr
, 2);
7633 gen_qemu_ld16u(ctx
, t0
, addr
);
7634 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7636 gen_qemu_ld16u(ctx
, t0
, addr
);
7637 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7638 gen_addr_add(ctx
, addr
, addr
, 2);
7639 gen_qemu_ld16u(ctx
, t0
, addr
);
7640 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
7641 gen_addr_add(ctx
, addr
, addr
, 2);
7642 gen_qemu_ld16u(ctx
, t0
, addr
);
7643 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7644 gen_addr_add(ctx
, addr
, addr
, 2);
7645 gen_qemu_ld16u(ctx
, t0
, addr
);
7646 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7651 static inline void gen_op_evlhhesplat(DisasContext
*ctx
, TCGv addr
)
7653 TCGv t0
= tcg_temp_new();
7654 gen_qemu_ld16u(ctx
, t0
, addr
);
7655 #if defined(TARGET_PPC64)
7656 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7657 tcg_gen_shli_tl(t0
, t0
, 16);
7658 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7660 tcg_gen_shli_tl(t0
, t0
, 16);
7661 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7662 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7667 static inline void gen_op_evlhhousplat(DisasContext
*ctx
, TCGv addr
)
7669 TCGv t0
= tcg_temp_new();
7670 gen_qemu_ld16u(ctx
, t0
, addr
);
7671 #if defined(TARGET_PPC64)
7672 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7673 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7675 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7676 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7681 static inline void gen_op_evlhhossplat(DisasContext
*ctx
, TCGv addr
)
7683 TCGv t0
= tcg_temp_new();
7684 gen_qemu_ld16s(ctx
, t0
, addr
);
7685 #if defined(TARGET_PPC64)
7686 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7687 tcg_gen_ext32u_tl(t0
, t0
);
7688 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7690 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7691 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7696 static inline void gen_op_evlwhe(DisasContext
*ctx
, TCGv addr
)
7698 TCGv t0
= tcg_temp_new();
7699 #if defined(TARGET_PPC64)
7700 gen_qemu_ld16u(ctx
, t0
, addr
);
7701 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7702 gen_addr_add(ctx
, addr
, addr
, 2);
7703 gen_qemu_ld16u(ctx
, t0
, addr
);
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 gen_qemu_ld16u(ctx
, t0
, addr
);
7708 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7709 gen_addr_add(ctx
, addr
, addr
, 2);
7710 gen_qemu_ld16u(ctx
, t0
, addr
);
7711 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
7716 static inline void gen_op_evlwhou(DisasContext
*ctx
, TCGv addr
)
7718 #if defined(TARGET_PPC64)
7719 TCGv t0
= tcg_temp_new();
7720 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7721 gen_addr_add(ctx
, addr
, addr
, 2);
7722 gen_qemu_ld16u(ctx
, t0
, addr
);
7723 tcg_gen_shli_tl(t0
, t0
, 32);
7724 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7727 gen_qemu_ld16u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7728 gen_addr_add(ctx
, addr
, addr
, 2);
7729 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7733 static inline void gen_op_evlwhos(DisasContext
*ctx
, TCGv addr
)
7735 #if defined(TARGET_PPC64)
7736 TCGv t0
= tcg_temp_new();
7737 gen_qemu_ld16s(ctx
, t0
, addr
);
7738 tcg_gen_ext32u_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7739 gen_addr_add(ctx
, addr
, addr
, 2);
7740 gen_qemu_ld16s(ctx
, t0
, addr
);
7741 tcg_gen_shli_tl(t0
, t0
, 32);
7742 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7745 gen_qemu_ld16s(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7746 gen_addr_add(ctx
, addr
, addr
, 2);
7747 gen_qemu_ld16s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7751 static inline void gen_op_evlwwsplat(DisasContext
*ctx
, TCGv addr
)
7753 TCGv t0
= tcg_temp_new();
7754 gen_qemu_ld32u(ctx
, t0
, addr
);
7755 #if defined(TARGET_PPC64)
7756 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7757 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7759 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7760 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7765 static inline void gen_op_evlwhsplat(DisasContext
*ctx
, TCGv addr
)
7767 TCGv t0
= tcg_temp_new();
7768 #if defined(TARGET_PPC64)
7769 gen_qemu_ld16u(ctx
, t0
, addr
);
7770 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7771 tcg_gen_shli_tl(t0
, t0
, 32);
7772 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7773 gen_addr_add(ctx
, addr
, addr
, 2);
7774 gen_qemu_ld16u(ctx
, t0
, addr
);
7775 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7776 tcg_gen_shli_tl(t0
, t0
, 16);
7777 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7779 gen_qemu_ld16u(ctx
, t0
, addr
);
7780 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7781 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
7782 gen_addr_add(ctx
, addr
, addr
, 2);
7783 gen_qemu_ld16u(ctx
, t0
, addr
);
7784 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
7785 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
7790 static inline void gen_op_evstdd(DisasContext
*ctx
, TCGv addr
)
7792 #if defined(TARGET_PPC64)
7793 gen_qemu_st64(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7795 TCGv_i64 t0
= tcg_temp_new_i64();
7796 tcg_gen_concat_i32_i64(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gprh
[rS(ctx
->opcode
)]);
7797 gen_qemu_st64(ctx
, t0
, addr
);
7798 tcg_temp_free_i64(t0
);
7802 static inline void gen_op_evstdw(DisasContext
*ctx
, TCGv addr
)
7804 #if defined(TARGET_PPC64)
7805 TCGv t0
= tcg_temp_new();
7806 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7807 gen_qemu_st32(ctx
, t0
, addr
);
7810 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7812 gen_addr_add(ctx
, addr
, addr
, 4);
7813 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7816 static inline void gen_op_evstdh(DisasContext
*ctx
, TCGv addr
)
7818 TCGv t0
= tcg_temp_new();
7819 #if defined(TARGET_PPC64)
7820 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
7822 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
7824 gen_qemu_st16(ctx
, t0
, addr
);
7825 gen_addr_add(ctx
, addr
, addr
, 2);
7826 #if defined(TARGET_PPC64)
7827 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7828 gen_qemu_st16(ctx
, t0
, addr
);
7830 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7832 gen_addr_add(ctx
, addr
, addr
, 2);
7833 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
7834 gen_qemu_st16(ctx
, t0
, addr
);
7836 gen_addr_add(ctx
, addr
, addr
, 2);
7837 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7840 static inline void gen_op_evstwhe(DisasContext
*ctx
, TCGv addr
)
7842 TCGv t0
= tcg_temp_new();
7843 #if defined(TARGET_PPC64)
7844 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
7846 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
7848 gen_qemu_st16(ctx
, t0
, addr
);
7849 gen_addr_add(ctx
, addr
, addr
, 2);
7850 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
7851 gen_qemu_st16(ctx
, t0
, addr
);
7855 static inline void gen_op_evstwho(DisasContext
*ctx
, TCGv addr
)
7857 #if defined(TARGET_PPC64)
7858 TCGv t0
= tcg_temp_new();
7859 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7860 gen_qemu_st16(ctx
, t0
, addr
);
7863 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7865 gen_addr_add(ctx
, addr
, addr
, 2);
7866 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7869 static inline void gen_op_evstwwe(DisasContext
*ctx
, TCGv addr
)
7871 #if defined(TARGET_PPC64)
7872 TCGv t0
= tcg_temp_new();
7873 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7874 gen_qemu_st32(ctx
, t0
, addr
);
7877 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7881 static inline void gen_op_evstwwo(DisasContext
*ctx
, TCGv addr
)
7883 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7886 #define GEN_SPEOP_LDST(name, opc2, sh) \
7887 static void glue(gen_, name)(DisasContext *ctx) \
7890 if (unlikely(!ctx->spe_enabled)) { \
7891 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7894 gen_set_access_type(ctx, ACCESS_INT); \
7895 t0 = tcg_temp_new(); \
7896 if (Rc(ctx->opcode)) { \
7897 gen_addr_spe_imm_index(ctx, t0, sh); \
7899 gen_addr_reg_index(ctx, t0); \
7901 gen_op_##name(ctx, t0); \
7902 tcg_temp_free(t0); \
7905 GEN_SPEOP_LDST(evldd
, 0x00, 3);
7906 GEN_SPEOP_LDST(evldw
, 0x01, 3);
7907 GEN_SPEOP_LDST(evldh
, 0x02, 3);
7908 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1);
7909 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1);
7910 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1);
7911 GEN_SPEOP_LDST(evlwhe
, 0x08, 2);
7912 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2);
7913 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2);
7914 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2);
7915 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2);
7917 GEN_SPEOP_LDST(evstdd
, 0x10, 3);
7918 GEN_SPEOP_LDST(evstdw
, 0x11, 3);
7919 GEN_SPEOP_LDST(evstdh
, 0x12, 3);
7920 GEN_SPEOP_LDST(evstwhe
, 0x18, 2);
7921 GEN_SPEOP_LDST(evstwho
, 0x1A, 2);
7922 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2);
7923 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2);
7925 /* Multiply and add - TODO */
7927 GEN_SPE(speundef
, evmhessf
, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);//
7928 GEN_SPE(speundef
, evmhossf
, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7929 GEN_SPE(evmheumi
, evmhesmi
, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
7930 GEN_SPE(speundef
, evmhesmf
, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7931 GEN_SPE(evmhoumi
, evmhosmi
, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
7932 GEN_SPE(speundef
, evmhosmf
, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7933 GEN_SPE(speundef
, evmhessfa
, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7934 GEN_SPE(speundef
, evmhossfa
, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7935 GEN_SPE(evmheumia
, evmhesmia
, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
7936 GEN_SPE(speundef
, evmhesmfa
, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7937 GEN_SPE(evmhoumia
, evmhosmia
, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
7938 GEN_SPE(speundef
, evmhosmfa
, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7940 GEN_SPE(speundef
, evmwhssf
, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7941 GEN_SPE(evmwlumi
, speundef
, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7942 GEN_SPE(evmwhumi
, evmwhsmi
, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
7943 GEN_SPE(speundef
, evmwhsmf
, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7944 GEN_SPE(speundef
, evmwssf
, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7945 GEN_SPE(speundef
, evmwsmf
, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7946 GEN_SPE(speundef
, evmwhssfa
, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7947 GEN_SPE(evmwlumia
, speundef
, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7948 GEN_SPE(evmwhumia
, evmwhsmia
, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
7949 GEN_SPE(speundef
, evmwhsmfa
, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7950 GEN_SPE(speundef
, evmwssfa
, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7951 GEN_SPE(speundef
, evmwsmfa
, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7953 GEN_SPE(evadduiaaw
, evaddsiaaw
, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
7954 GEN_SPE(evsubfusiaaw
, evsubfssiaaw
, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
7955 GEN_SPE(evaddumiaaw
, evaddsmiaaw
, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
7956 GEN_SPE(evsubfumiaaw
, evsubfsmiaaw
, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
7957 GEN_SPE(evdivws
, evdivwu
, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE
);
7959 GEN_SPE(evmheusiaaw
, evmhessiaaw
, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
7960 GEN_SPE(speundef
, evmhessfaaw
, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7961 GEN_SPE(evmhousiaaw
, evmhossiaaw
, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
7962 GEN_SPE(speundef
, evmhossfaaw
, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7963 GEN_SPE(evmheumiaaw
, evmhesmiaaw
, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
7964 GEN_SPE(speundef
, evmhesmfaaw
, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7965 GEN_SPE(evmhoumiaaw
, evmhosmiaaw
, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
7966 GEN_SPE(speundef
, evmhosmfaaw
, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7967 GEN_SPE(evmhegumiaa
, evmhegsmiaa
, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
7968 GEN_SPE(speundef
, evmhegsmfaa
, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7969 GEN_SPE(evmhogumiaa
, evmhogsmiaa
, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
7970 GEN_SPE(speundef
, evmhogsmfaa
, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7972 GEN_SPE(evmwlusiaaw
, evmwlssiaaw
, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
7973 GEN_SPE(evmwlumiaaw
, evmwlsmiaaw
, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
7974 GEN_SPE(speundef
, evmwssfaa
, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7975 GEN_SPE(speundef
, evmwsmfaa
, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7977 GEN_SPE(evmheusianw
, evmhessianw
, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
7978 GEN_SPE(speundef
, evmhessfanw
, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7979 GEN_SPE(evmhousianw
, evmhossianw
, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
7980 GEN_SPE(speundef
, evmhossfanw
, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7981 GEN_SPE(evmheumianw
, evmhesmianw
, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
7982 GEN_SPE(speundef
, evmhesmfanw
, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7983 GEN_SPE(evmhoumianw
, evmhosmianw
, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
7984 GEN_SPE(speundef
, evmhosmfanw
, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7985 GEN_SPE(evmhegumian
, evmhegsmian
, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
7986 GEN_SPE(speundef
, evmhegsmfan
, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7987 GEN_SPE(evmhigumian
, evmhigsmian
, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
7988 GEN_SPE(speundef
, evmhogsmfan
, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7990 GEN_SPE(evmwlusianw
, evmwlssianw
, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
7991 GEN_SPE(evmwlumianw
, evmwlsmianw
, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
7992 GEN_SPE(speundef
, evmwssfan
, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7993 GEN_SPE(evmwumian
, evmwsmian
, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
7994 GEN_SPE(speundef
, evmwsmfan
, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
7997 /*** SPE floating-point extension ***/
7998 #if defined(TARGET_PPC64)
7999 #define GEN_SPEFPUOP_CONV_32_32(name) \
8000 static inline void gen_##name(DisasContext *ctx) \
8004 t0 = tcg_temp_new_i32(); \
8005 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8006 gen_helper_##name(t0, cpu_env, t0); \
8007 t1 = tcg_temp_new(); \
8008 tcg_gen_extu_i32_tl(t1, t0); \
8009 tcg_temp_free_i32(t0); \
8010 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8011 0xFFFFFFFF00000000ULL); \
8012 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
8013 tcg_temp_free(t1); \
8015 #define GEN_SPEFPUOP_CONV_32_64(name) \
8016 static inline void gen_##name(DisasContext *ctx) \
8020 t0 = tcg_temp_new_i32(); \
8021 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
8022 t1 = tcg_temp_new(); \
8023 tcg_gen_extu_i32_tl(t1, t0); \
8024 tcg_temp_free_i32(t0); \
8025 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8026 0xFFFFFFFF00000000ULL); \
8027 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
8028 tcg_temp_free(t1); \
8030 #define GEN_SPEFPUOP_CONV_64_32(name) \
8031 static inline void gen_##name(DisasContext *ctx) \
8033 TCGv_i32 t0 = tcg_temp_new_i32(); \
8034 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8035 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
8036 tcg_temp_free_i32(t0); \
8038 #define GEN_SPEFPUOP_CONV_64_64(name) \
8039 static inline void gen_##name(DisasContext *ctx) \
8041 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8042 cpu_gpr[rB(ctx->opcode)]); \
8044 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
8045 static inline void gen_##name(DisasContext *ctx) \
8049 if (unlikely(!ctx->spe_enabled)) { \
8050 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8053 t0 = tcg_temp_new_i32(); \
8054 t1 = tcg_temp_new_i32(); \
8055 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8056 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8057 gen_helper_##name(t0, cpu_env, t0, t1); \
8058 tcg_temp_free_i32(t1); \
8059 t2 = tcg_temp_new(); \
8060 tcg_gen_extu_i32_tl(t2, t0); \
8061 tcg_temp_free_i32(t0); \
8062 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8063 0xFFFFFFFF00000000ULL); \
8064 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \
8065 tcg_temp_free(t2); \
8067 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
8068 static inline void gen_##name(DisasContext *ctx) \
8070 if (unlikely(!ctx->spe_enabled)) { \
8071 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8074 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8075 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8077 #define GEN_SPEFPUOP_COMP_32(name) \
8078 static inline void gen_##name(DisasContext *ctx) \
8081 if (unlikely(!ctx->spe_enabled)) { \
8082 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8085 t0 = tcg_temp_new_i32(); \
8086 t1 = tcg_temp_new_i32(); \
8087 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8088 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8089 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
8090 tcg_temp_free_i32(t0); \
8091 tcg_temp_free_i32(t1); \
8093 #define GEN_SPEFPUOP_COMP_64(name) \
8094 static inline void gen_##name(DisasContext *ctx) \
8096 if (unlikely(!ctx->spe_enabled)) { \
8097 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8100 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
8101 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8104 #define GEN_SPEFPUOP_CONV_32_32(name) \
8105 static inline void gen_##name(DisasContext *ctx) \
8107 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8108 cpu_gpr[rB(ctx->opcode)]); \
8110 #define GEN_SPEFPUOP_CONV_32_64(name) \
8111 static inline void gen_##name(DisasContext *ctx) \
8113 TCGv_i64 t0 = tcg_temp_new_i64(); \
8114 gen_load_gpr64(t0, rB(ctx->opcode)); \
8115 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
8116 tcg_temp_free_i64(t0); \
8118 #define GEN_SPEFPUOP_CONV_64_32(name) \
8119 static inline void gen_##name(DisasContext *ctx) \
8121 TCGv_i64 t0 = tcg_temp_new_i64(); \
8122 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
8123 gen_store_gpr64(rD(ctx->opcode), t0); \
8124 tcg_temp_free_i64(t0); \
8126 #define GEN_SPEFPUOP_CONV_64_64(name) \
8127 static inline void gen_##name(DisasContext *ctx) \
8129 TCGv_i64 t0 = tcg_temp_new_i64(); \
8130 gen_load_gpr64(t0, rB(ctx->opcode)); \
8131 gen_helper_##name(t0, cpu_env, t0); \
8132 gen_store_gpr64(rD(ctx->opcode), t0); \
8133 tcg_temp_free_i64(t0); \
8135 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
8136 static inline void gen_##name(DisasContext *ctx) \
8138 if (unlikely(!ctx->spe_enabled)) { \
8139 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8142 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8143 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8145 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
8146 static inline void gen_##name(DisasContext *ctx) \
8149 if (unlikely(!ctx->spe_enabled)) { \
8150 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8153 t0 = tcg_temp_new_i64(); \
8154 t1 = tcg_temp_new_i64(); \
8155 gen_load_gpr64(t0, rA(ctx->opcode)); \
8156 gen_load_gpr64(t1, rB(ctx->opcode)); \
8157 gen_helper_##name(t0, cpu_env, t0, t1); \
8158 gen_store_gpr64(rD(ctx->opcode), t0); \
8159 tcg_temp_free_i64(t0); \
8160 tcg_temp_free_i64(t1); \
8162 #define GEN_SPEFPUOP_COMP_32(name) \
8163 static inline void gen_##name(DisasContext *ctx) \
8165 if (unlikely(!ctx->spe_enabled)) { \
8166 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8169 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
8170 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8172 #define GEN_SPEFPUOP_COMP_64(name) \
8173 static inline void gen_##name(DisasContext *ctx) \
8176 if (unlikely(!ctx->spe_enabled)) { \
8177 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8180 t0 = tcg_temp_new_i64(); \
8181 t1 = tcg_temp_new_i64(); \
8182 gen_load_gpr64(t0, rA(ctx->opcode)); \
8183 gen_load_gpr64(t1, rB(ctx->opcode)); \
8184 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
8185 tcg_temp_free_i64(t0); \
8186 tcg_temp_free_i64(t1); \
8190 /* Single precision floating-point vectors operations */
8192 GEN_SPEFPUOP_ARITH2_64_64(evfsadd
);
8193 GEN_SPEFPUOP_ARITH2_64_64(evfssub
);
8194 GEN_SPEFPUOP_ARITH2_64_64(evfsmul
);
8195 GEN_SPEFPUOP_ARITH2_64_64(evfsdiv
);
8196 static inline void gen_evfsabs(DisasContext
*ctx
)
8198 if (unlikely(!ctx
->spe_enabled
)) {
8199 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8202 #if defined(TARGET_PPC64)
8203 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000080000000LL
);
8205 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x80000000);
8206 tcg_gen_andi_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
8209 static inline void gen_evfsnabs(DisasContext
*ctx
)
8211 if (unlikely(!ctx
->spe_enabled
)) {
8212 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8215 #if defined(TARGET_PPC64)
8216 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
8218 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8219 tcg_gen_ori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8222 static inline void gen_evfsneg(DisasContext
*ctx
)
8224 if (unlikely(!ctx
->spe_enabled
)) {
8225 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8228 #if defined(TARGET_PPC64)
8229 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
8231 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8232 tcg_gen_xori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8237 GEN_SPEFPUOP_CONV_64_64(evfscfui
);
8238 GEN_SPEFPUOP_CONV_64_64(evfscfsi
);
8239 GEN_SPEFPUOP_CONV_64_64(evfscfuf
);
8240 GEN_SPEFPUOP_CONV_64_64(evfscfsf
);
8241 GEN_SPEFPUOP_CONV_64_64(evfsctui
);
8242 GEN_SPEFPUOP_CONV_64_64(evfsctsi
);
8243 GEN_SPEFPUOP_CONV_64_64(evfsctuf
);
8244 GEN_SPEFPUOP_CONV_64_64(evfsctsf
);
8245 GEN_SPEFPUOP_CONV_64_64(evfsctuiz
);
8246 GEN_SPEFPUOP_CONV_64_64(evfsctsiz
);
8249 GEN_SPEFPUOP_COMP_64(evfscmpgt
);
8250 GEN_SPEFPUOP_COMP_64(evfscmplt
);
8251 GEN_SPEFPUOP_COMP_64(evfscmpeq
);
8252 GEN_SPEFPUOP_COMP_64(evfststgt
);
8253 GEN_SPEFPUOP_COMP_64(evfststlt
);
8254 GEN_SPEFPUOP_COMP_64(evfststeq
);
8256 /* Opcodes definitions */
8257 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8258 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
); //
8259 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8260 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8261 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8262 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8263 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8264 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8265 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8266 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8267 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8268 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8269 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8270 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8272 /* Single precision floating-point operations */
8274 GEN_SPEFPUOP_ARITH2_32_32(efsadd
);
8275 GEN_SPEFPUOP_ARITH2_32_32(efssub
);
8276 GEN_SPEFPUOP_ARITH2_32_32(efsmul
);
8277 GEN_SPEFPUOP_ARITH2_32_32(efsdiv
);
8278 static inline void gen_efsabs(DisasContext
*ctx
)
8280 if (unlikely(!ctx
->spe_enabled
)) {
8281 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8284 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], (target_long
)~0x80000000LL
);
8286 static inline void gen_efsnabs(DisasContext
*ctx
)
8288 if (unlikely(!ctx
->spe_enabled
)) {
8289 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8292 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8294 static inline void gen_efsneg(DisasContext
*ctx
)
8296 if (unlikely(!ctx
->spe_enabled
)) {
8297 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8300 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8304 GEN_SPEFPUOP_CONV_32_32(efscfui
);
8305 GEN_SPEFPUOP_CONV_32_32(efscfsi
);
8306 GEN_SPEFPUOP_CONV_32_32(efscfuf
);
8307 GEN_SPEFPUOP_CONV_32_32(efscfsf
);
8308 GEN_SPEFPUOP_CONV_32_32(efsctui
);
8309 GEN_SPEFPUOP_CONV_32_32(efsctsi
);
8310 GEN_SPEFPUOP_CONV_32_32(efsctuf
);
8311 GEN_SPEFPUOP_CONV_32_32(efsctsf
);
8312 GEN_SPEFPUOP_CONV_32_32(efsctuiz
);
8313 GEN_SPEFPUOP_CONV_32_32(efsctsiz
);
8314 GEN_SPEFPUOP_CONV_32_64(efscfd
);
8317 GEN_SPEFPUOP_COMP_32(efscmpgt
);
8318 GEN_SPEFPUOP_COMP_32(efscmplt
);
8319 GEN_SPEFPUOP_COMP_32(efscmpeq
);
8320 GEN_SPEFPUOP_COMP_32(efststgt
);
8321 GEN_SPEFPUOP_COMP_32(efststlt
);
8322 GEN_SPEFPUOP_COMP_32(efststeq
);
8324 /* Opcodes definitions */
8325 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8326 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
); //
8327 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8328 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8329 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8330 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE
); //
8331 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8332 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8333 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8334 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8335 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8336 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8337 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8338 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8340 /* Double precision floating-point operations */
8342 GEN_SPEFPUOP_ARITH2_64_64(efdadd
);
8343 GEN_SPEFPUOP_ARITH2_64_64(efdsub
);
8344 GEN_SPEFPUOP_ARITH2_64_64(efdmul
);
8345 GEN_SPEFPUOP_ARITH2_64_64(efddiv
);
8346 static inline void gen_efdabs(DisasContext
*ctx
)
8348 if (unlikely(!ctx
->spe_enabled
)) {
8349 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8352 #if defined(TARGET_PPC64)
8353 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000000000000LL
);
8355 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8356 tcg_gen_andi_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
8359 static inline void gen_efdnabs(DisasContext
*ctx
)
8361 if (unlikely(!ctx
->spe_enabled
)) {
8362 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8365 #if defined(TARGET_PPC64)
8366 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
8368 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8369 tcg_gen_ori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8372 static inline void gen_efdneg(DisasContext
*ctx
)
8374 if (unlikely(!ctx
->spe_enabled
)) {
8375 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8378 #if defined(TARGET_PPC64)
8379 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
8381 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8382 tcg_gen_xori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8387 GEN_SPEFPUOP_CONV_64_32(efdcfui
);
8388 GEN_SPEFPUOP_CONV_64_32(efdcfsi
);
8389 GEN_SPEFPUOP_CONV_64_32(efdcfuf
);
8390 GEN_SPEFPUOP_CONV_64_32(efdcfsf
);
8391 GEN_SPEFPUOP_CONV_32_64(efdctui
);
8392 GEN_SPEFPUOP_CONV_32_64(efdctsi
);
8393 GEN_SPEFPUOP_CONV_32_64(efdctuf
);
8394 GEN_SPEFPUOP_CONV_32_64(efdctsf
);
8395 GEN_SPEFPUOP_CONV_32_64(efdctuiz
);
8396 GEN_SPEFPUOP_CONV_32_64(efdctsiz
);
8397 GEN_SPEFPUOP_CONV_64_32(efdcfs
);
8398 GEN_SPEFPUOP_CONV_64_64(efdcfuid
);
8399 GEN_SPEFPUOP_CONV_64_64(efdcfsid
);
8400 GEN_SPEFPUOP_CONV_64_64(efdctuidz
);
8401 GEN_SPEFPUOP_CONV_64_64(efdctsidz
);
8404 GEN_SPEFPUOP_COMP_64(efdcmpgt
);
8405 GEN_SPEFPUOP_COMP_64(efdcmplt
);
8406 GEN_SPEFPUOP_COMP_64(efdcmpeq
);
8407 GEN_SPEFPUOP_COMP_64(efdtstgt
);
8408 GEN_SPEFPUOP_COMP_64(efdtstlt
);
8409 GEN_SPEFPUOP_COMP_64(efdtsteq
);
8411 /* Opcodes definitions */
8412 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
); //
8413 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8414 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE
); //
8415 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8416 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
); //
8417 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8418 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
); //
8419 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE
); //
8420 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8421 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8422 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8423 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8424 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8425 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8426 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
); //
8427 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8429 static opcode_t opcodes
[] = {
8430 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
),
8431 GEN_HANDLER(cmp
, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER
),
8432 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
8433 GEN_HANDLER(cmpl
, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER
),
8434 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
8435 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
),
8436 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8437 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8438 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8439 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8440 GEN_HANDLER(mulhw
, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER
),
8441 GEN_HANDLER(mulhwu
, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER
),
8442 GEN_HANDLER(mullw
, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER
),
8443 GEN_HANDLER(mullwo
, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER
),
8444 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8445 #if defined(TARGET_PPC64)
8446 GEN_HANDLER(mulld
, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B
),
8448 GEN_HANDLER(neg
, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER
),
8449 GEN_HANDLER(nego
, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER
),
8450 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8451 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8452 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8453 GEN_HANDLER(cntlzw
, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER
),
8454 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
),
8455 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
),
8456 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8457 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8458 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8459 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8460 GEN_HANDLER(popcntb
, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB
),
8461 GEN_HANDLER(popcntw
, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD
),
8462 #if defined(TARGET_PPC64)
8463 GEN_HANDLER(popcntd
, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD
),
8464 GEN_HANDLER(cntlzd
, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B
),
8466 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8467 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8468 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8469 GEN_HANDLER(slw
, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER
),
8470 GEN_HANDLER(sraw
, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER
),
8471 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
),
8472 GEN_HANDLER(srw
, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER
),
8473 #if defined(TARGET_PPC64)
8474 GEN_HANDLER(sld
, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B
),
8475 GEN_HANDLER(srad
, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B
),
8476 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
),
8477 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
),
8478 GEN_HANDLER(srd
, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B
),
8480 GEN_HANDLER(frsqrtes
, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES
),
8481 GEN_HANDLER(fsqrt
, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
8482 GEN_HANDLER(fsqrts
, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
8483 GEN_HANDLER(fcmpo
, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT
),
8484 GEN_HANDLER(fcmpu
, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT
),
8485 GEN_HANDLER(fmr
, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT
),
8486 GEN_HANDLER(mcrfs
, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT
),
8487 GEN_HANDLER(mffs
, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT
),
8488 GEN_HANDLER(mtfsb0
, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT
),
8489 GEN_HANDLER(mtfsb1
, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT
),
8490 GEN_HANDLER(mtfsf
, 0x3F, 0x07, 0x16, 0x00010000, PPC_FLOAT
),
8491 GEN_HANDLER(mtfsfi
, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT
),
8492 #if defined(TARGET_PPC64)
8493 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
),
8494 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
),
8495 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
),
8497 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8498 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8499 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
),
8500 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
),
8501 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
),
8502 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
),
8503 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO
),
8504 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
),
8505 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES
),
8506 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
),
8507 #if defined(TARGET_PPC64)
8508 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B
),
8509 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
),
8511 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
),
8512 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
),
8513 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
8514 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
8515 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
),
8516 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
),
8517 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
),
8518 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
),
8519 #if defined(TARGET_PPC64)
8520 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
),
8521 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
),
8523 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW
),
8524 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
),
8525 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
8526 #if defined(TARGET_PPC64)
8527 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
),
8528 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
),
8530 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
),
8531 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
),
8532 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
),
8533 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
),
8534 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
),
8535 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
),
8536 #if defined(TARGET_PPC64)
8537 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
),
8539 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC
),
8540 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC
),
8541 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
),
8542 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
),
8543 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
),
8544 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE
),
8545 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE
),
8546 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ
),
8547 GEN_HANDLER(dst
, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC
),
8548 GEN_HANDLER(dstst
, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC
),
8549 GEN_HANDLER(dss
, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC
),
8550 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
),
8551 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
),
8552 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
),
8553 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
),
8554 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
),
8555 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
),
8556 #if defined(TARGET_PPC64)
8557 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
),
8558 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
8560 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
),
8561 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
8563 GEN_HANDLER2(slbmte
, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B
),
8564 GEN_HANDLER2(slbmfee
, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B
),
8565 GEN_HANDLER2(slbmfev
, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B
),
8567 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
),
8568 GEN_HANDLER(tlbiel
, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE
),
8569 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE
),
8570 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
),
8571 #if defined(TARGET_PPC64)
8572 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI
),
8573 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
),
8575 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
),
8576 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
),
8577 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
),
8578 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
),
8579 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
),
8580 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
),
8581 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
),
8582 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
),
8583 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
),
8584 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
),
8585 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
),
8586 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
8587 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
),
8588 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
),
8589 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
),
8590 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
),
8591 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
),
8592 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
),
8593 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
),
8594 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
8595 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
),
8596 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
),
8597 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
),
8598 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
),
8599 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
),
8600 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
),
8601 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
),
8602 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
),
8603 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
),
8604 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
),
8605 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
),
8606 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
),
8607 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
),
8608 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
),
8609 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
),
8610 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
),
8611 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
),
8612 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
),
8613 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
),
8614 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
),
8615 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
),
8616 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
),
8617 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
),
8618 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
),
8619 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
),
8620 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
),
8621 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
),
8622 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
),
8623 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
),
8624 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8625 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8626 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
),
8627 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
),
8628 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8629 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8630 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
),
8631 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
),
8632 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
),
8633 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
),
8634 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
),
8635 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
),
8636 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
),
8637 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
),
8638 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
),
8639 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
),
8640 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
),
8641 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
),
8642 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
),
8643 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
),
8644 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
),
8645 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
),
8646 GEN_HANDLER_E(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
, PPC2_BOOKE206
),
8647 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
),
8648 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
),
8649 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
),
8650 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
),
8651 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
),
8652 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
),
8653 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
),
8654 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
),
8655 GEN_HANDLER2_E(tlbre_booke206
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
8656 PPC_NONE
, PPC2_BOOKE206
),
8657 GEN_HANDLER2_E(tlbsx_booke206
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
8658 PPC_NONE
, PPC2_BOOKE206
),
8659 GEN_HANDLER2_E(tlbwe_booke206
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
8660 PPC_NONE
, PPC2_BOOKE206
),
8661 GEN_HANDLER2_E(tlbivax_booke206
, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
8662 PPC_NONE
, PPC2_BOOKE206
),
8663 GEN_HANDLER2_E(tlbilx_booke206
, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
8664 PPC_NONE
, PPC2_BOOKE206
),
8665 GEN_HANDLER2_E(msgsnd
, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
8666 PPC_NONE
, PPC2_PRCNTL
),
8667 GEN_HANDLER2_E(msgclr
, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
8668 PPC_NONE
, PPC2_PRCNTL
),
8669 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
),
8670 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE
),
8671 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
),
8672 GEN_HANDLER_E(mbar
, 0x1F, 0x16, 0x1a, 0x001FF801,
8673 PPC_BOOKE
, PPC2_BOOKE206
),
8674 GEN_HANDLER(msync_4xx
, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE
),
8675 GEN_HANDLER2_E(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
8676 PPC_BOOKE
, PPC2_BOOKE206
),
8677 GEN_HANDLER(lvsl
, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC
),
8678 GEN_HANDLER(lvsr
, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC
),
8679 GEN_HANDLER(mfvscr
, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC
),
8680 GEN_HANDLER(mtvscr
, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC
),
8681 GEN_HANDLER(vsldoi
, 0x04, 0x16, 0xFF, 0x00000400, PPC_ALTIVEC
),
8682 GEN_HANDLER(vmladduhm
, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC
),
8683 GEN_HANDLER2(evsel0
, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE
),
8684 GEN_HANDLER2(evsel1
, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE
),
8685 GEN_HANDLER2(evsel2
, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE
),
8686 GEN_HANDLER2(evsel3
, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE
),
8688 #undef GEN_INT_ARITH_ADD
8689 #undef GEN_INT_ARITH_ADD_CONST
8690 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
8691 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
8692 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
8693 add_ca, compute_ca, compute_ov) \
8694 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
8695 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
8696 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
8697 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
8698 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
8699 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
8700 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
8701 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
8702 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
8703 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
8704 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
8706 #undef GEN_INT_ARITH_DIVW
8707 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
8708 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
8709 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0),
8710 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1),
8711 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0),
8712 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1),
8714 #if defined(TARGET_PPC64)
8715 #undef GEN_INT_ARITH_DIVD
8716 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
8717 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8718 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0),
8719 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1),
8720 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0),
8721 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1),
8723 #undef GEN_INT_ARITH_MUL_HELPER
8724 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
8725 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8726 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00),
8727 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02),
8728 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17),
8731 #undef GEN_INT_ARITH_SUBF
8732 #undef GEN_INT_ARITH_SUBF_CONST
8733 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
8734 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
8735 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
8736 add_ca, compute_ca, compute_ov) \
8737 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
8738 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
8739 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
8740 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
8741 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
8742 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
8743 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
8744 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
8745 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
8746 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
8747 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
8751 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
8752 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
8753 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
8754 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
8755 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
),
8756 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
),
8757 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
),
8758 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
),
8759 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
),
8760 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
),
8761 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
),
8762 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
),
8763 #if defined(TARGET_PPC64)
8764 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
),
8767 #if defined(TARGET_PPC64)
8770 #define GEN_PPC64_R2(name, opc1, opc2) \
8771 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8772 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
8774 #define GEN_PPC64_R4(name, opc1, opc2) \
8775 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8776 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
8778 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
8780 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
8782 GEN_PPC64_R4(rldicl
, 0x1E, 0x00),
8783 GEN_PPC64_R4(rldicr
, 0x1E, 0x02),
8784 GEN_PPC64_R4(rldic
, 0x1E, 0x04),
8785 GEN_PPC64_R2(rldcl
, 0x1E, 0x08),
8786 GEN_PPC64_R2(rldcr
, 0x1E, 0x09),
8787 GEN_PPC64_R4(rldimi
, 0x1E, 0x06),
8790 #undef _GEN_FLOAT_ACB
8791 #undef GEN_FLOAT_ACB
8792 #undef _GEN_FLOAT_AB
8794 #undef _GEN_FLOAT_AC
8798 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
8799 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
8800 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
8801 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
8802 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
8803 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
8804 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
8805 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
8806 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
8807 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
8808 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
8809 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
8810 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
8811 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
8812 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
8813 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
8814 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
8815 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
8816 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
8818 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
),
8819 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
),
8820 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
),
8821 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
),
8822 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
),
8823 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
),
8824 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
),
8825 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
),
8826 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
),
8827 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
),
8828 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
),
8829 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
),
8830 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
),
8831 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
),
8832 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
),
8833 #if defined(TARGET_PPC64)
8834 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
),
8835 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
),
8836 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
),
8838 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
),
8839 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
),
8840 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
),
8841 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
),
8842 GEN_FLOAT_B(abs
, 0x08, 0x08, 0, PPC_FLOAT
),
8843 GEN_FLOAT_B(nabs
, 0x08, 0x04, 0, PPC_FLOAT
),
8844 GEN_FLOAT_B(neg
, 0x08, 0x01, 0, PPC_FLOAT
),
8851 #define GEN_LD(name, ldop, opc, type) \
8852 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8853 #define GEN_LDU(name, ldop, opc, type) \
8854 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
8855 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
8856 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
8857 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
8858 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
8859 #define GEN_LDS(name, ldop, op, type) \
8860 GEN_LD(name, ldop, op | 0x20, type) \
8861 GEN_LDU(name, ldop, op | 0x21, type) \
8862 GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
8863 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
8865 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
)
8866 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
)
8867 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
)
8868 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
)
8869 #if defined(TARGET_PPC64)
8870 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
)
8871 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
)
8872 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
)
8873 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
)
8874 GEN_LDX_E(ldbr
, ld64ur
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
)
8876 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
)
8877 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
)
8884 #define GEN_ST(name, stop, opc, type) \
8885 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8886 #define GEN_STU(name, stop, opc, type) \
8887 GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
8888 #define GEN_STUX(name, stop, opc2, opc3, type) \
8889 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
8890 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
8891 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
8892 #define GEN_STS(name, stop, op, type) \
8893 GEN_ST(name, stop, op | 0x20, type) \
8894 GEN_STU(name, stop, op | 0x21, type) \
8895 GEN_STUX(name, stop, 0x17, op | 0x01, type) \
8896 GEN_STX(name, stop, 0x17, op | 0x00, type)
8898 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
)
8899 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
)
8900 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
)
8901 #if defined(TARGET_PPC64)
8902 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
)
8903 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
)
8904 GEN_STX_E(stdbr
, st64r
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
)
8906 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
)
8907 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
)
8914 #define GEN_LDF(name, ldop, opc, type) \
8915 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8916 #define GEN_LDUF(name, ldop, opc, type) \
8917 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
8918 #define GEN_LDUXF(name, ldop, opc, type) \
8919 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
8920 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
8921 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
8922 #define GEN_LDFS(name, ldop, op, type) \
8923 GEN_LDF(name, ldop, op | 0x20, type) \
8924 GEN_LDUF(name, ldop, op | 0x21, type) \
8925 GEN_LDUXF(name, ldop, op | 0x01, type) \
8926 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
8928 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
)
8929 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
)
8936 #define GEN_STF(name, stop, opc, type) \
8937 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8938 #define GEN_STUF(name, stop, opc, type) \
8939 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
8940 #define GEN_STUXF(name, stop, opc, type) \
8941 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
8942 #define GEN_STXF(name, stop, opc2, opc3, type) \
8943 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
8944 #define GEN_STFS(name, stop, op, type) \
8945 GEN_STF(name, stop, op | 0x20, type) \
8946 GEN_STUF(name, stop, op | 0x21, type) \
8947 GEN_STUXF(name, stop, op | 0x01, type) \
8948 GEN_STXF(name, stop, 0x17, op | 0x00, type)
8950 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
)
8951 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
)
8952 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
)
8955 #define GEN_CRLOGIC(name, tcg_op, opc) \
8956 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
8957 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08),
8958 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04),
8959 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09),
8960 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07),
8961 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01),
8962 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E),
8963 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D),
8964 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06),
8966 #undef GEN_MAC_HANDLER
8967 #define GEN_MAC_HANDLER(name, opc2, opc3) \
8968 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
8969 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05),
8970 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15),
8971 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07),
8972 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17),
8973 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06),
8974 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16),
8975 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04),
8976 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14),
8977 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01),
8978 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11),
8979 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03),
8980 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13),
8981 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02),
8982 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12),
8983 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00),
8984 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10),
8985 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D),
8986 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D),
8987 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F),
8988 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F),
8989 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C),
8990 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C),
8991 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E),
8992 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E),
8993 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05),
8994 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15),
8995 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07),
8996 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17),
8997 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01),
8998 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11),
8999 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03),
9000 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13),
9001 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D),
9002 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D),
9003 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F),
9004 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F),
9005 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05),
9006 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04),
9007 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01),
9008 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00),
9009 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D),
9010 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C),
9016 #define GEN_VR_LDX(name, opc2, opc3) \
9017 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9018 #define GEN_VR_STX(name, opc2, opc3) \
9019 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9020 #define GEN_VR_LVE(name, opc2, opc3) \
9021 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9022 #define GEN_VR_STVE(name, opc2, opc3) \
9023 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9024 GEN_VR_LDX(lvx
, 0x07, 0x03),
9025 GEN_VR_LDX(lvxl
, 0x07, 0x0B),
9026 GEN_VR_LVE(bx
, 0x07, 0x00),
9027 GEN_VR_LVE(hx
, 0x07, 0x01),
9028 GEN_VR_LVE(wx
, 0x07, 0x02),
9029 GEN_VR_STX(svx
, 0x07, 0x07),
9030 GEN_VR_STX(svxl
, 0x07, 0x0F),
9031 GEN_VR_STVE(bx
, 0x07, 0x04),
9032 GEN_VR_STVE(hx
, 0x07, 0x05),
9033 GEN_VR_STVE(wx
, 0x07, 0x06),
9035 #undef GEN_VX_LOGICAL
9036 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
9037 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9038 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16),
9039 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17),
9040 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18),
9041 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19),
9042 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20),
9045 #define GEN_VXFORM(name, opc2, opc3) \
9046 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9047 GEN_VXFORM(vaddubm
, 0, 0),
9048 GEN_VXFORM(vadduhm
, 0, 1),
9049 GEN_VXFORM(vadduwm
, 0, 2),
9050 GEN_VXFORM(vsububm
, 0, 16),
9051 GEN_VXFORM(vsubuhm
, 0, 17),
9052 GEN_VXFORM(vsubuwm
, 0, 18),
9053 GEN_VXFORM(vmaxub
, 1, 0),
9054 GEN_VXFORM(vmaxuh
, 1, 1),
9055 GEN_VXFORM(vmaxuw
, 1, 2),
9056 GEN_VXFORM(vmaxsb
, 1, 4),
9057 GEN_VXFORM(vmaxsh
, 1, 5),
9058 GEN_VXFORM(vmaxsw
, 1, 6),
9059 GEN_VXFORM(vminub
, 1, 8),
9060 GEN_VXFORM(vminuh
, 1, 9),
9061 GEN_VXFORM(vminuw
, 1, 10),
9062 GEN_VXFORM(vminsb
, 1, 12),
9063 GEN_VXFORM(vminsh
, 1, 13),
9064 GEN_VXFORM(vminsw
, 1, 14),
9065 GEN_VXFORM(vavgub
, 1, 16),
9066 GEN_VXFORM(vavguh
, 1, 17),
9067 GEN_VXFORM(vavguw
, 1, 18),
9068 GEN_VXFORM(vavgsb
, 1, 20),
9069 GEN_VXFORM(vavgsh
, 1, 21),
9070 GEN_VXFORM(vavgsw
, 1, 22),
9071 GEN_VXFORM(vmrghb
, 6, 0),
9072 GEN_VXFORM(vmrghh
, 6, 1),
9073 GEN_VXFORM(vmrghw
, 6, 2),
9074 GEN_VXFORM(vmrglb
, 6, 4),
9075 GEN_VXFORM(vmrglh
, 6, 5),
9076 GEN_VXFORM(vmrglw
, 6, 6),
9077 GEN_VXFORM(vmuloub
, 4, 0),
9078 GEN_VXFORM(vmulouh
, 4, 1),
9079 GEN_VXFORM(vmulosb
, 4, 4),
9080 GEN_VXFORM(vmulosh
, 4, 5),
9081 GEN_VXFORM(vmuleub
, 4, 8),
9082 GEN_VXFORM(vmuleuh
, 4, 9),
9083 GEN_VXFORM(vmulesb
, 4, 12),
9084 GEN_VXFORM(vmulesh
, 4, 13),
9085 GEN_VXFORM(vslb
, 2, 4),
9086 GEN_VXFORM(vslh
, 2, 5),
9087 GEN_VXFORM(vslw
, 2, 6),
9088 GEN_VXFORM(vsrb
, 2, 8),
9089 GEN_VXFORM(vsrh
, 2, 9),
9090 GEN_VXFORM(vsrw
, 2, 10),
9091 GEN_VXFORM(vsrab
, 2, 12),
9092 GEN_VXFORM(vsrah
, 2, 13),
9093 GEN_VXFORM(vsraw
, 2, 14),
9094 GEN_VXFORM(vslo
, 6, 16),
9095 GEN_VXFORM(vsro
, 6, 17),
9096 GEN_VXFORM(vaddcuw
, 0, 6),
9097 GEN_VXFORM(vsubcuw
, 0, 22),
9098 GEN_VXFORM(vaddubs
, 0, 8),
9099 GEN_VXFORM(vadduhs
, 0, 9),
9100 GEN_VXFORM(vadduws
, 0, 10),
9101 GEN_VXFORM(vaddsbs
, 0, 12),
9102 GEN_VXFORM(vaddshs
, 0, 13),
9103 GEN_VXFORM(vaddsws
, 0, 14),
9104 GEN_VXFORM(vsububs
, 0, 24),
9105 GEN_VXFORM(vsubuhs
, 0, 25),
9106 GEN_VXFORM(vsubuws
, 0, 26),
9107 GEN_VXFORM(vsubsbs
, 0, 28),
9108 GEN_VXFORM(vsubshs
, 0, 29),
9109 GEN_VXFORM(vsubsws
, 0, 30),
9110 GEN_VXFORM(vrlb
, 2, 0),
9111 GEN_VXFORM(vrlh
, 2, 1),
9112 GEN_VXFORM(vrlw
, 2, 2),
9113 GEN_VXFORM(vsl
, 2, 7),
9114 GEN_VXFORM(vsr
, 2, 11),
9115 GEN_VXFORM(vpkuhum
, 7, 0),
9116 GEN_VXFORM(vpkuwum
, 7, 1),
9117 GEN_VXFORM(vpkuhus
, 7, 2),
9118 GEN_VXFORM(vpkuwus
, 7, 3),
9119 GEN_VXFORM(vpkshus
, 7, 4),
9120 GEN_VXFORM(vpkswus
, 7, 5),
9121 GEN_VXFORM(vpkshss
, 7, 6),
9122 GEN_VXFORM(vpkswss
, 7, 7),
9123 GEN_VXFORM(vpkpx
, 7, 12),
9124 GEN_VXFORM(vsum4ubs
, 4, 24),
9125 GEN_VXFORM(vsum4sbs
, 4, 28),
9126 GEN_VXFORM(vsum4shs
, 4, 25),
9127 GEN_VXFORM(vsum2sws
, 4, 26),
9128 GEN_VXFORM(vsumsws
, 4, 30),
9129 GEN_VXFORM(vaddfp
, 5, 0),
9130 GEN_VXFORM(vsubfp
, 5, 1),
9131 GEN_VXFORM(vmaxfp
, 5, 16),
9132 GEN_VXFORM(vminfp
, 5, 17),
9136 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
9137 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
9138 #define GEN_VXRFORM(name, opc2, opc3) \
9139 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
9140 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
9141 GEN_VXRFORM(vcmpequb
, 3, 0)
9142 GEN_VXRFORM(vcmpequh
, 3, 1)
9143 GEN_VXRFORM(vcmpequw
, 3, 2)
9144 GEN_VXRFORM(vcmpgtsb
, 3, 12)
9145 GEN_VXRFORM(vcmpgtsh
, 3, 13)
9146 GEN_VXRFORM(vcmpgtsw
, 3, 14)
9147 GEN_VXRFORM(vcmpgtub
, 3, 8)
9148 GEN_VXRFORM(vcmpgtuh
, 3, 9)
9149 GEN_VXRFORM(vcmpgtuw
, 3, 10)
9150 GEN_VXRFORM(vcmpeqfp
, 3, 3)
9151 GEN_VXRFORM(vcmpgefp
, 3, 7)
9152 GEN_VXRFORM(vcmpgtfp
, 3, 11)
9153 GEN_VXRFORM(vcmpbfp
, 3, 15)
9155 #undef GEN_VXFORM_SIMM
9156 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
9157 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9158 GEN_VXFORM_SIMM(vspltisb
, 6, 12),
9159 GEN_VXFORM_SIMM(vspltish
, 6, 13),
9160 GEN_VXFORM_SIMM(vspltisw
, 6, 14),
9162 #undef GEN_VXFORM_NOA
9163 #define GEN_VXFORM_NOA(name, opc2, opc3) \
9164 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
9165 GEN_VXFORM_NOA(vupkhsb
, 7, 8),
9166 GEN_VXFORM_NOA(vupkhsh
, 7, 9),
9167 GEN_VXFORM_NOA(vupklsb
, 7, 10),
9168 GEN_VXFORM_NOA(vupklsh
, 7, 11),
9169 GEN_VXFORM_NOA(vupkhpx
, 7, 13),
9170 GEN_VXFORM_NOA(vupklpx
, 7, 15),
9171 GEN_VXFORM_NOA(vrefp
, 5, 4),
9172 GEN_VXFORM_NOA(vrsqrtefp
, 5, 5),
9173 GEN_VXFORM_NOA(vexptefp
, 5, 6),
9174 GEN_VXFORM_NOA(vlogefp
, 5, 7),
9175 GEN_VXFORM_NOA(vrfim
, 5, 8),
9176 GEN_VXFORM_NOA(vrfin
, 5, 9),
9177 GEN_VXFORM_NOA(vrfip
, 5, 10),
9178 GEN_VXFORM_NOA(vrfiz
, 5, 11),
9180 #undef GEN_VXFORM_UIMM
9181 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
9182 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9183 GEN_VXFORM_UIMM(vspltb
, 6, 8),
9184 GEN_VXFORM_UIMM(vsplth
, 6, 9),
9185 GEN_VXFORM_UIMM(vspltw
, 6, 10),
9186 GEN_VXFORM_UIMM(vcfux
, 5, 12),
9187 GEN_VXFORM_UIMM(vcfsx
, 5, 13),
9188 GEN_VXFORM_UIMM(vctuxs
, 5, 14),
9189 GEN_VXFORM_UIMM(vctsxs
, 5, 15),
9191 #undef GEN_VAFORM_PAIRED
9192 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
9193 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
9194 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16),
9195 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18),
9196 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19),
9197 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20),
9198 GEN_VAFORM_PAIRED(vsel
, vperm
, 21),
9199 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23),
9202 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
9203 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
9204 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9205 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9206 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9207 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9208 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
9209 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
9210 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
9211 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE
),
9212 GEN_SPE(evmra
, speundef
, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE
),
9213 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
),
9214 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9215 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9216 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9217 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE
),
9218 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE
),
9219 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE
),
9220 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
),
9221 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9222 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9223 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9224 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9225 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9226 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE
),
9227 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE
),
9228 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9229 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9230 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE
),
9231 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE
),
9232 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE
),
9234 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9235 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
),
9236 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9237 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9238 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9239 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9240 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9241 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9242 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9243 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9244 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9245 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9246 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9247 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9249 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9250 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
),
9251 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9252 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9253 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9254 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE
),
9255 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9256 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9257 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9258 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9259 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9260 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9261 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9262 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9264 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
),
9265 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9266 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE
),
9267 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9268 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
),
9269 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9270 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
),
9271 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE
),
9272 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9273 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9274 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9275 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9276 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9277 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9278 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
),
9279 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9281 #undef GEN_SPEOP_LDST
9282 #define GEN_SPEOP_LDST(name, opc2, sh) \
9283 GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
9284 GEN_SPEOP_LDST(evldd
, 0x00, 3),
9285 GEN_SPEOP_LDST(evldw
, 0x01, 3),
9286 GEN_SPEOP_LDST(evldh
, 0x02, 3),
9287 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1),
9288 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1),
9289 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1),
9290 GEN_SPEOP_LDST(evlwhe
, 0x08, 2),
9291 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2),
9292 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2),
9293 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2),
9294 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2),
9296 GEN_SPEOP_LDST(evstdd
, 0x10, 3),
9297 GEN_SPEOP_LDST(evstdw
, 0x11, 3),
9298 GEN_SPEOP_LDST(evstdh
, 0x12, 3),
9299 GEN_SPEOP_LDST(evstwhe
, 0x18, 2),
9300 GEN_SPEOP_LDST(evstwho
, 0x1A, 2),
9301 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2),
9302 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2),
9305 #include "helper_regs.h"
9306 #include "translate_init.c"
9308 /*****************************************************************************/
9309 /* Misc PowerPC helpers */
9310 void cpu_dump_state (CPUPPCState
*env
, FILE *f
, fprintf_function cpu_fprintf
,
9318 cpu_synchronize_state(env
);
9320 cpu_fprintf(f
, "NIP " TARGET_FMT_lx
" LR " TARGET_FMT_lx
" CTR "
9321 TARGET_FMT_lx
" XER " TARGET_FMT_lx
"\n",
9322 env
->nip
, env
->lr
, env
->ctr
, cpu_read_xer(env
));
9323 cpu_fprintf(f
, "MSR " TARGET_FMT_lx
" HID0 " TARGET_FMT_lx
" HF "
9324 TARGET_FMT_lx
" idx %d\n", env
->msr
, env
->spr
[SPR_HID0
],
9325 env
->hflags
, env
->mmu_idx
);
9326 #if !defined(NO_TIMER_DUMP)
9327 cpu_fprintf(f
, "TB %08" PRIu32
" %08" PRIu64
9328 #if !defined(CONFIG_USER_ONLY)
9332 cpu_ppc_load_tbu(env
), cpu_ppc_load_tbl(env
)
9333 #if !defined(CONFIG_USER_ONLY)
9334 , cpu_ppc_load_decr(env
)
9338 for (i
= 0; i
< 32; i
++) {
9339 if ((i
& (RGPL
- 1)) == 0)
9340 cpu_fprintf(f
, "GPR%02d", i
);
9341 cpu_fprintf(f
, " %016" PRIx64
, ppc_dump_gpr(env
, i
));
9342 if ((i
& (RGPL
- 1)) == (RGPL
- 1))
9343 cpu_fprintf(f
, "\n");
9345 cpu_fprintf(f
, "CR ");
9346 for (i
= 0; i
< 8; i
++)
9347 cpu_fprintf(f
, "%01x", env
->crf
[i
]);
9348 cpu_fprintf(f
, " [");
9349 for (i
= 0; i
< 8; i
++) {
9351 if (env
->crf
[i
] & 0x08)
9353 else if (env
->crf
[i
] & 0x04)
9355 else if (env
->crf
[i
] & 0x02)
9357 cpu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
9359 cpu_fprintf(f
, " ] RES " TARGET_FMT_lx
"\n",
9361 for (i
= 0; i
< 32; i
++) {
9362 if ((i
& (RFPL
- 1)) == 0)
9363 cpu_fprintf(f
, "FPR%02d", i
);
9364 cpu_fprintf(f
, " %016" PRIx64
, *((uint64_t *)&env
->fpr
[i
]));
9365 if ((i
& (RFPL
- 1)) == (RFPL
- 1))
9366 cpu_fprintf(f
, "\n");
9368 cpu_fprintf(f
, "FPSCR " TARGET_FMT_lx
"\n", env
->fpscr
);
9369 #if !defined(CONFIG_USER_ONLY)
9370 cpu_fprintf(f
, " SRR0 " TARGET_FMT_lx
" SRR1 " TARGET_FMT_lx
9371 " PVR " TARGET_FMT_lx
" VRSAVE " TARGET_FMT_lx
"\n",
9372 env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
9373 env
->spr
[SPR_PVR
], env
->spr
[SPR_VRSAVE
]);
9375 cpu_fprintf(f
, "SPRG0 " TARGET_FMT_lx
" SPRG1 " TARGET_FMT_lx
9376 " SPRG2 " TARGET_FMT_lx
" SPRG3 " TARGET_FMT_lx
"\n",
9377 env
->spr
[SPR_SPRG0
], env
->spr
[SPR_SPRG1
],
9378 env
->spr
[SPR_SPRG2
], env
->spr
[SPR_SPRG3
]);
9380 cpu_fprintf(f
, "SPRG4 " TARGET_FMT_lx
" SPRG5 " TARGET_FMT_lx
9381 " SPRG6 " TARGET_FMT_lx
" SPRG7 " TARGET_FMT_lx
"\n",
9382 env
->spr
[SPR_SPRG4
], env
->spr
[SPR_SPRG5
],
9383 env
->spr
[SPR_SPRG6
], env
->spr
[SPR_SPRG7
]);
9385 if (env
->excp_model
== POWERPC_EXCP_BOOKE
) {
9386 cpu_fprintf(f
, "CSRR0 " TARGET_FMT_lx
" CSRR1 " TARGET_FMT_lx
9387 " MCSRR0 " TARGET_FMT_lx
" MCSRR1 " TARGET_FMT_lx
"\n",
9388 env
->spr
[SPR_BOOKE_CSRR0
], env
->spr
[SPR_BOOKE_CSRR1
],
9389 env
->spr
[SPR_BOOKE_MCSRR0
], env
->spr
[SPR_BOOKE_MCSRR1
]);
9391 cpu_fprintf(f
, " TCR " TARGET_FMT_lx
" TSR " TARGET_FMT_lx
9392 " ESR " TARGET_FMT_lx
" DEAR " TARGET_FMT_lx
"\n",
9393 env
->spr
[SPR_BOOKE_TCR
], env
->spr
[SPR_BOOKE_TSR
],
9394 env
->spr
[SPR_BOOKE_ESR
], env
->spr
[SPR_BOOKE_DEAR
]);
9396 cpu_fprintf(f
, " PIR " TARGET_FMT_lx
" DECAR " TARGET_FMT_lx
9397 " IVPR " TARGET_FMT_lx
" EPCR " TARGET_FMT_lx
"\n",
9398 env
->spr
[SPR_BOOKE_PIR
], env
->spr
[SPR_BOOKE_DECAR
],
9399 env
->spr
[SPR_BOOKE_IVPR
], env
->spr
[SPR_BOOKE_EPCR
]);
9401 cpu_fprintf(f
, " MCSR " TARGET_FMT_lx
" SPRG8 " TARGET_FMT_lx
9402 " EPR " TARGET_FMT_lx
"\n",
9403 env
->spr
[SPR_BOOKE_MCSR
], env
->spr
[SPR_BOOKE_SPRG8
],
9404 env
->spr
[SPR_BOOKE_EPR
]);
9407 cpu_fprintf(f
, " MCAR " TARGET_FMT_lx
" PID1 " TARGET_FMT_lx
9408 " PID2 " TARGET_FMT_lx
" SVR " TARGET_FMT_lx
"\n",
9409 env
->spr
[SPR_Exxx_MCAR
], env
->spr
[SPR_BOOKE_PID1
],
9410 env
->spr
[SPR_BOOKE_PID2
], env
->spr
[SPR_E500_SVR
]);
9413 * IVORs are left out as they are large and do not change often --
9414 * they can be read with "p $ivor0", "p $ivor1", etc.
9418 #if defined(TARGET_PPC64)
9419 if (env
->flags
& POWERPC_FLAG_CFAR
) {
9420 cpu_fprintf(f
, " CFAR " TARGET_FMT_lx
"\n", env
->cfar
);
9424 switch (env
->mmu_model
) {
9425 case POWERPC_MMU_32B
:
9426 case POWERPC_MMU_601
:
9427 case POWERPC_MMU_SOFT_6xx
:
9428 case POWERPC_MMU_SOFT_74xx
:
9429 #if defined(TARGET_PPC64)
9430 case POWERPC_MMU_620
:
9431 case POWERPC_MMU_64B
:
9433 cpu_fprintf(f
, " SDR1 " TARGET_FMT_lx
"\n", env
->spr
[SPR_SDR1
]);
9435 case POWERPC_MMU_BOOKE206
:
9436 cpu_fprintf(f
, " MAS0 " TARGET_FMT_lx
" MAS1 " TARGET_FMT_lx
9437 " MAS2 " TARGET_FMT_lx
" MAS3 " TARGET_FMT_lx
"\n",
9438 env
->spr
[SPR_BOOKE_MAS0
], env
->spr
[SPR_BOOKE_MAS1
],
9439 env
->spr
[SPR_BOOKE_MAS2
], env
->spr
[SPR_BOOKE_MAS3
]);
9441 cpu_fprintf(f
, " MAS4 " TARGET_FMT_lx
" MAS6 " TARGET_FMT_lx
9442 " MAS7 " TARGET_FMT_lx
" PID " TARGET_FMT_lx
"\n",
9443 env
->spr
[SPR_BOOKE_MAS4
], env
->spr
[SPR_BOOKE_MAS6
],
9444 env
->spr
[SPR_BOOKE_MAS7
], env
->spr
[SPR_BOOKE_PID
]);
9446 cpu_fprintf(f
, "MMUCFG " TARGET_FMT_lx
" TLB0CFG " TARGET_FMT_lx
9447 " TLB1CFG " TARGET_FMT_lx
"\n",
9448 env
->spr
[SPR_MMUCFG
], env
->spr
[SPR_BOOKE_TLB0CFG
],
9449 env
->spr
[SPR_BOOKE_TLB1CFG
]);
9460 void cpu_dump_statistics (CPUPPCState
*env
, FILE*f
, fprintf_function cpu_fprintf
,
9463 #if defined(DO_PPC_STATISTICS)
9464 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
9468 for (op1
= 0; op1
< 64; op1
++) {
9470 if (is_indirect_opcode(handler
)) {
9471 t2
= ind_table(handler
);
9472 for (op2
= 0; op2
< 32; op2
++) {
9474 if (is_indirect_opcode(handler
)) {
9475 t3
= ind_table(handler
);
9476 for (op3
= 0; op3
< 32; op3
++) {
9478 if (handler
->count
== 0)
9480 cpu_fprintf(f
, "%02x %02x %02x (%02x %04d) %16s: "
9481 "%016" PRIx64
" %" PRId64
"\n",
9482 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
9484 handler
->count
, handler
->count
);
9487 if (handler
->count
== 0)
9489 cpu_fprintf(f
, "%02x %02x (%02x %04d) %16s: "
9490 "%016" PRIx64
" %" PRId64
"\n",
9491 op1
, op2
, op1
, op2
, handler
->oname
,
9492 handler
->count
, handler
->count
);
9496 if (handler
->count
== 0)
9498 cpu_fprintf(f
, "%02x (%02x ) %16s: %016" PRIx64
9500 op1
, op1
, handler
->oname
,
9501 handler
->count
, handler
->count
);
9507 /*****************************************************************************/
9508 static inline void gen_intermediate_code_internal(CPUPPCState
*env
,
9509 TranslationBlock
*tb
,
9512 DisasContext ctx
, *ctxp
= &ctx
;
9513 opc_handler_t
**table
, *handler
;
9514 target_ulong pc_start
;
9515 uint16_t *gen_opc_end
;
9522 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
9525 ctx
.exception
= POWERPC_EXCP_NONE
;
9526 ctx
.spr_cb
= env
->spr_cb
;
9527 ctx
.mem_idx
= env
->mmu_idx
;
9528 ctx
.access_type
= -1;
9529 ctx
.le_mode
= env
->hflags
& (1 << MSR_LE
) ? 1 : 0;
9530 #if defined(TARGET_PPC64)
9531 ctx
.sf_mode
= msr_is_64bit(env
, env
->msr
);
9532 ctx
.has_cfar
= !!(env
->flags
& POWERPC_FLAG_CFAR
);
9534 ctx
.fpu_enabled
= msr_fp
;
9535 if ((env
->flags
& POWERPC_FLAG_SPE
) && msr_spe
)
9536 ctx
.spe_enabled
= msr_spe
;
9538 ctx
.spe_enabled
= 0;
9539 if ((env
->flags
& POWERPC_FLAG_VRE
) && msr_vr
)
9540 ctx
.altivec_enabled
= msr_vr
;
9542 ctx
.altivec_enabled
= 0;
9543 if ((env
->flags
& POWERPC_FLAG_SE
) && msr_se
)
9544 ctx
.singlestep_enabled
= CPU_SINGLE_STEP
;
9546 ctx
.singlestep_enabled
= 0;
9547 if ((env
->flags
& POWERPC_FLAG_BE
) && msr_be
)
9548 ctx
.singlestep_enabled
|= CPU_BRANCH_STEP
;
9549 if (unlikely(env
->singlestep_enabled
))
9550 ctx
.singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
9551 #if defined (DO_SINGLE_STEP) && 0
9552 /* Single step trace mode */
9556 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
9558 max_insns
= CF_COUNT_MASK
;
9561 /* Set env in case of segfault during code fetch */
9562 while (ctx
.exception
== POWERPC_EXCP_NONE
9563 && tcg_ctx
.gen_opc_ptr
< gen_opc_end
) {
9564 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
9565 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
9566 if (bp
->pc
== ctx
.nip
) {
9567 gen_debug_exception(ctxp
);
9572 if (unlikely(search_pc
)) {
9573 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
9577 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
9579 tcg_ctx
.gen_opc_pc
[lj
] = ctx
.nip
;
9580 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
9581 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
9583 LOG_DISAS("----------------\n");
9584 LOG_DISAS("nip=" TARGET_FMT_lx
" super=%d ir=%d\n",
9585 ctx
.nip
, ctx
.mem_idx
, (int)msr_ir
);
9586 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
9588 if (unlikely(ctx
.le_mode
)) {
9589 ctx
.opcode
= bswap32(cpu_ldl_code(env
, ctx
.nip
));
9591 ctx
.opcode
= cpu_ldl_code(env
, ctx
.nip
);
9593 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
9594 ctx
.opcode
, opc1(ctx
.opcode
), opc2(ctx
.opcode
),
9595 opc3(ctx
.opcode
), ctx
.le_mode
? "little" : "big");
9596 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
9597 tcg_gen_debug_insn_start(ctx
.nip
);
9600 table
= env
->opcodes
;
9602 handler
= table
[opc1(ctx
.opcode
)];
9603 if (is_indirect_opcode(handler
)) {
9604 table
= ind_table(handler
);
9605 handler
= table
[opc2(ctx
.opcode
)];
9606 if (is_indirect_opcode(handler
)) {
9607 table
= ind_table(handler
);
9608 handler
= table
[opc3(ctx
.opcode
)];
9611 /* Is opcode *REALLY* valid ? */
9612 if (unlikely(handler
->handler
== &gen_invalid
)) {
9613 if (qemu_log_enabled()) {
9614 qemu_log("invalid/unsupported opcode: "
9615 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx
" %d\n",
9616 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
9617 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
9622 if (unlikely(handler
->type
& (PPC_SPE
| PPC_SPE_SINGLE
| PPC_SPE_DOUBLE
) && Rc(ctx
.opcode
))) {
9623 inval
= handler
->inval2
;
9625 inval
= handler
->inval1
;
9628 if (unlikely((ctx
.opcode
& inval
) != 0)) {
9629 if (qemu_log_enabled()) {
9630 qemu_log("invalid bits: %08x for opcode: "
9631 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx
"\n",
9632 ctx
.opcode
& inval
, opc1(ctx
.opcode
),
9633 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
9634 ctx
.opcode
, ctx
.nip
- 4);
9636 gen_inval_exception(ctxp
, POWERPC_EXCP_INVAL_INVAL
);
9640 (*(handler
->handler
))(&ctx
);
9641 #if defined(DO_PPC_STATISTICS)
9644 /* Check trace mode exceptions */
9645 if (unlikely(ctx
.singlestep_enabled
& CPU_SINGLE_STEP
&&
9646 (ctx
.nip
<= 0x100 || ctx
.nip
> 0xF00) &&
9647 ctx
.exception
!= POWERPC_SYSCALL
&&
9648 ctx
.exception
!= POWERPC_EXCP_TRAP
&&
9649 ctx
.exception
!= POWERPC_EXCP_BRANCH
)) {
9650 gen_exception(ctxp
, POWERPC_EXCP_TRACE
);
9651 } else if (unlikely(((ctx
.nip
& (TARGET_PAGE_SIZE
- 1)) == 0) ||
9652 (env
->singlestep_enabled
) ||
9654 num_insns
>= max_insns
)) {
9655 /* if we reach a page boundary or are single stepping, stop
9661 if (tb
->cflags
& CF_LAST_IO
)
9663 if (ctx
.exception
== POWERPC_EXCP_NONE
) {
9664 gen_goto_tb(&ctx
, 0, ctx
.nip
);
9665 } else if (ctx
.exception
!= POWERPC_EXCP_BRANCH
) {
9666 if (unlikely(env
->singlestep_enabled
)) {
9667 gen_debug_exception(ctxp
);
9669 /* Generate the return instruction */
9672 gen_tb_end(tb
, num_insns
);
9673 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
9674 if (unlikely(search_pc
)) {
9675 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
9678 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
9680 tb
->size
= ctx
.nip
- pc_start
;
9681 tb
->icount
= num_insns
;
9683 #if defined(DEBUG_DISAS)
9684 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
9686 flags
= env
->bfd_mach
;
9687 flags
|= ctx
.le_mode
<< 16;
9688 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
9689 log_target_disas(env
, pc_start
, ctx
.nip
- pc_start
, flags
);
9695 void gen_intermediate_code (CPUPPCState
*env
, struct TranslationBlock
*tb
)
9697 gen_intermediate_code_internal(env
, tb
, 0);
9700 void gen_intermediate_code_pc (CPUPPCState
*env
, struct TranslationBlock
*tb
)
9702 gen_intermediate_code_internal(env
, tb
, 1);
9705 void restore_state_to_opc(CPUPPCState
*env
, TranslationBlock
*tb
, int pc_pos
)
9707 env
->nip
= tcg_ctx
.gen_opc_pc
[pc_pos
];