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 /* True when active word size < size of target_long. */
209 # define NARROW_MODE(C) (!(C)->sf_mode)
211 # define NARROW_MODE(C) 0
214 struct opc_handler_t
{
215 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
217 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
219 /* instruction type */
221 /* extended instruction type */
224 void (*handler
)(DisasContext
*ctx
);
225 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
228 #if defined(DO_PPC_STATISTICS)
233 static inline void gen_reset_fpstatus(void)
235 gen_helper_reset_fpstatus(cpu_env
);
238 static inline void gen_compute_fprf(TCGv_i64 arg
, int set_fprf
, int set_rc
)
240 TCGv_i32 t0
= tcg_temp_new_i32();
243 /* This case might be optimized later */
244 tcg_gen_movi_i32(t0
, 1);
245 gen_helper_compute_fprf(t0
, cpu_env
, arg
, t0
);
246 if (unlikely(set_rc
)) {
247 tcg_gen_mov_i32(cpu_crf
[1], t0
);
249 gen_helper_float_check_status(cpu_env
);
250 } else if (unlikely(set_rc
)) {
251 /* We always need to compute fpcc */
252 tcg_gen_movi_i32(t0
, 0);
253 gen_helper_compute_fprf(t0
, cpu_env
, arg
, t0
);
254 tcg_gen_mov_i32(cpu_crf
[1], t0
);
257 tcg_temp_free_i32(t0
);
260 static inline void gen_set_access_type(DisasContext
*ctx
, int access_type
)
262 if (ctx
->access_type
!= access_type
) {
263 tcg_gen_movi_i32(cpu_access_type
, access_type
);
264 ctx
->access_type
= access_type
;
268 static inline void gen_update_nip(DisasContext
*ctx
, target_ulong nip
)
270 if (NARROW_MODE(ctx
)) {
273 tcg_gen_movi_tl(cpu_nip
, nip
);
276 static inline void gen_exception_err(DisasContext
*ctx
, uint32_t excp
, uint32_t error
)
279 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
280 gen_update_nip(ctx
, ctx
->nip
);
282 t0
= tcg_const_i32(excp
);
283 t1
= tcg_const_i32(error
);
284 gen_helper_raise_exception_err(cpu_env
, t0
, t1
);
285 tcg_temp_free_i32(t0
);
286 tcg_temp_free_i32(t1
);
287 ctx
->exception
= (excp
);
290 static inline void gen_exception(DisasContext
*ctx
, uint32_t excp
)
293 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
294 gen_update_nip(ctx
, ctx
->nip
);
296 t0
= tcg_const_i32(excp
);
297 gen_helper_raise_exception(cpu_env
, t0
);
298 tcg_temp_free_i32(t0
);
299 ctx
->exception
= (excp
);
302 static inline void gen_debug_exception(DisasContext
*ctx
)
306 if ((ctx
->exception
!= POWERPC_EXCP_BRANCH
) &&
307 (ctx
->exception
!= POWERPC_EXCP_SYNC
)) {
308 gen_update_nip(ctx
, ctx
->nip
);
310 t0
= tcg_const_i32(EXCP_DEBUG
);
311 gen_helper_raise_exception(cpu_env
, t0
);
312 tcg_temp_free_i32(t0
);
315 static inline void gen_inval_exception(DisasContext
*ctx
, uint32_t error
)
317 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_INVAL
| error
);
320 /* Stop translation */
321 static inline void gen_stop_exception(DisasContext
*ctx
)
323 gen_update_nip(ctx
, ctx
->nip
);
324 ctx
->exception
= POWERPC_EXCP_STOP
;
327 /* No need to update nip here, as execution flow will change */
328 static inline void gen_sync_exception(DisasContext
*ctx
)
330 ctx
->exception
= POWERPC_EXCP_SYNC
;
333 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
334 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
336 #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
337 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
339 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
340 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
342 #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
343 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
345 typedef struct opcode_t
{
346 unsigned char opc1
, opc2
, opc3
;
347 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
348 unsigned char pad
[5];
350 unsigned char pad
[1];
352 opc_handler_t handler
;
356 /*****************************************************************************/
357 /*** Instruction decoding ***/
358 #define EXTRACT_HELPER(name, shift, nb) \
359 static inline uint32_t name(uint32_t opcode) \
361 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
364 #define EXTRACT_SHELPER(name, shift, nb) \
365 static inline int32_t name(uint32_t opcode) \
367 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
371 EXTRACT_HELPER(opc1
, 26, 6);
373 EXTRACT_HELPER(opc2
, 1, 5);
375 EXTRACT_HELPER(opc3
, 6, 5);
376 /* Update Cr0 flags */
377 EXTRACT_HELPER(Rc
, 0, 1);
379 EXTRACT_HELPER(rD
, 21, 5);
381 EXTRACT_HELPER(rS
, 21, 5);
383 EXTRACT_HELPER(rA
, 16, 5);
385 EXTRACT_HELPER(rB
, 11, 5);
387 EXTRACT_HELPER(rC
, 6, 5);
389 EXTRACT_HELPER(crfD
, 23, 3);
390 EXTRACT_HELPER(crfS
, 18, 3);
391 EXTRACT_HELPER(crbD
, 21, 5);
392 EXTRACT_HELPER(crbA
, 16, 5);
393 EXTRACT_HELPER(crbB
, 11, 5);
395 EXTRACT_HELPER(_SPR
, 11, 10);
396 static inline uint32_t SPR(uint32_t opcode
)
398 uint32_t sprn
= _SPR(opcode
);
400 return ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
402 /*** Get constants ***/
403 EXTRACT_HELPER(IMM
, 12, 8);
404 /* 16 bits signed immediate value */
405 EXTRACT_SHELPER(SIMM
, 0, 16);
406 /* 16 bits unsigned immediate value */
407 EXTRACT_HELPER(UIMM
, 0, 16);
408 /* 5 bits signed immediate value */
409 EXTRACT_HELPER(SIMM5
, 16, 5);
410 /* 5 bits signed immediate value */
411 EXTRACT_HELPER(UIMM5
, 16, 5);
413 EXTRACT_HELPER(NB
, 11, 5);
415 EXTRACT_HELPER(SH
, 11, 5);
416 /* Vector shift count */
417 EXTRACT_HELPER(VSH
, 6, 4);
419 EXTRACT_HELPER(MB
, 6, 5);
421 EXTRACT_HELPER(ME
, 1, 5);
423 EXTRACT_HELPER(TO
, 21, 5);
425 EXTRACT_HELPER(CRM
, 12, 8);
426 EXTRACT_HELPER(FM
, 17, 8);
427 EXTRACT_HELPER(SR
, 16, 4);
428 EXTRACT_HELPER(FPIMM
, 12, 4);
430 /*** Jump target decoding ***/
432 EXTRACT_SHELPER(d
, 0, 16);
433 /* Immediate address */
434 static inline target_ulong
LI(uint32_t opcode
)
436 return (opcode
>> 0) & 0x03FFFFFC;
439 static inline uint32_t BD(uint32_t opcode
)
441 return (opcode
>> 0) & 0xFFFC;
444 EXTRACT_HELPER(BO
, 21, 5);
445 EXTRACT_HELPER(BI
, 16, 5);
446 /* Absolute/relative address */
447 EXTRACT_HELPER(AA
, 1, 1);
449 EXTRACT_HELPER(LK
, 0, 1);
451 /* Create a mask between <start> and <end> bits */
452 static inline target_ulong
MASK(uint32_t start
, uint32_t end
)
456 #if defined(TARGET_PPC64)
457 if (likely(start
== 0)) {
458 ret
= UINT64_MAX
<< (63 - end
);
459 } else if (likely(end
== 63)) {
460 ret
= UINT64_MAX
>> start
;
463 if (likely(start
== 0)) {
464 ret
= UINT32_MAX
<< (31 - end
);
465 } else if (likely(end
== 31)) {
466 ret
= UINT32_MAX
>> start
;
470 ret
= (((target_ulong
)(-1ULL)) >> (start
)) ^
471 (((target_ulong
)(-1ULL) >> (end
)) >> 1);
472 if (unlikely(start
> end
))
479 /*****************************************************************************/
480 /* PowerPC instructions table */
482 #if defined(DO_PPC_STATISTICS)
483 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
493 .handler = &gen_##name, \
494 .oname = stringify(name), \
496 .oname = stringify(name), \
498 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
509 .handler = &gen_##name, \
510 .oname = stringify(name), \
512 .oname = stringify(name), \
514 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
524 .handler = &gen_##name, \
530 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
540 .handler = &gen_##name, \
542 .oname = stringify(name), \
544 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
555 .handler = &gen_##name, \
557 .oname = stringify(name), \
559 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
569 .handler = &gen_##name, \
575 /* SPR load/store helpers */
576 static inline void gen_load_spr(TCGv t
, int reg
)
578 tcg_gen_ld_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
581 static inline void gen_store_spr(int reg
, TCGv t
)
583 tcg_gen_st_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
586 /* Invalid instruction */
587 static void gen_invalid(DisasContext
*ctx
)
589 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
592 static opc_handler_t invalid_handler
= {
593 .inval1
= 0xFFFFFFFF,
594 .inval2
= 0xFFFFFFFF,
597 .handler
= gen_invalid
,
600 /*** Integer comparison ***/
602 static inline void gen_op_cmp(TCGv arg0
, TCGv arg1
, int s
, int crf
)
604 TCGv t0
= tcg_temp_new();
605 TCGv_i32 t1
= tcg_temp_new_i32();
607 tcg_gen_trunc_tl_i32(cpu_crf
[crf
], cpu_so
);
609 tcg_gen_setcond_tl((s
? TCG_COND_LT
: TCG_COND_LTU
), t0
, arg0
, arg1
);
610 tcg_gen_trunc_tl_i32(t1
, t0
);
611 tcg_gen_shli_i32(t1
, t1
, CRF_LT
);
612 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
614 tcg_gen_setcond_tl((s
? TCG_COND_GT
: TCG_COND_GTU
), t0
, arg0
, arg1
);
615 tcg_gen_trunc_tl_i32(t1
, t0
);
616 tcg_gen_shli_i32(t1
, t1
, CRF_GT
);
617 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
619 tcg_gen_setcond_tl(TCG_COND_EQ
, t0
, arg0
, arg1
);
620 tcg_gen_trunc_tl_i32(t1
, t0
);
621 tcg_gen_shli_i32(t1
, t1
, CRF_EQ
);
622 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t1
);
625 tcg_temp_free_i32(t1
);
628 static inline void gen_op_cmpi(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
630 TCGv t0
= tcg_const_tl(arg1
);
631 gen_op_cmp(arg0
, t0
, s
, crf
);
635 static inline void gen_op_cmp32(TCGv arg0
, TCGv arg1
, int s
, int crf
)
641 tcg_gen_ext32s_tl(t0
, arg0
);
642 tcg_gen_ext32s_tl(t1
, arg1
);
644 tcg_gen_ext32u_tl(t0
, arg0
);
645 tcg_gen_ext32u_tl(t1
, arg1
);
647 gen_op_cmp(t0
, t1
, s
, crf
);
652 static inline void gen_op_cmpi32(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
654 TCGv t0
= tcg_const_tl(arg1
);
655 gen_op_cmp32(arg0
, t0
, s
, crf
);
659 static inline void gen_set_Rc0(DisasContext
*ctx
, TCGv reg
)
661 if (NARROW_MODE(ctx
)) {
662 gen_op_cmpi32(reg
, 0, 1, 0);
664 gen_op_cmpi(reg
, 0, 1, 0);
669 static void gen_cmp(DisasContext
*ctx
)
671 if (NARROW_MODE(ctx
) || !(ctx
->opcode
& 0x00200000)) {
672 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
673 1, crfD(ctx
->opcode
));
675 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
676 1, crfD(ctx
->opcode
));
681 static void gen_cmpi(DisasContext
*ctx
)
683 if (NARROW_MODE(ctx
) || !(ctx
->opcode
& 0x00200000)) {
684 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
685 1, crfD(ctx
->opcode
));
687 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
688 1, crfD(ctx
->opcode
));
693 static void gen_cmpl(DisasContext
*ctx
)
695 if (NARROW_MODE(ctx
) || !(ctx
->opcode
& 0x00200000)) {
696 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
697 0, crfD(ctx
->opcode
));
699 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
700 0, crfD(ctx
->opcode
));
705 static void gen_cmpli(DisasContext
*ctx
)
707 if (NARROW_MODE(ctx
) || !(ctx
->opcode
& 0x00200000)) {
708 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
709 0, crfD(ctx
->opcode
));
711 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
712 0, crfD(ctx
->opcode
));
716 /* isel (PowerPC 2.03 specification) */
717 static void gen_isel(DisasContext
*ctx
)
720 uint32_t bi
= rC(ctx
->opcode
);
724 l1
= gen_new_label();
725 l2
= gen_new_label();
727 mask
= 1 << (3 - (bi
& 0x03));
728 t0
= tcg_temp_new_i32();
729 tcg_gen_andi_i32(t0
, cpu_crf
[bi
>> 2], mask
);
730 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
731 if (rA(ctx
->opcode
) == 0)
732 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
734 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
737 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
739 tcg_temp_free_i32(t0
);
742 /* cmpb: PowerPC 2.05 specification */
743 static void gen_cmpb(DisasContext
*ctx
)
745 gen_helper_cmpb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
746 cpu_gpr
[rB(ctx
->opcode
)]);
749 /*** Integer arithmetic ***/
751 static inline void gen_op_arith_compute_ov(DisasContext
*ctx
, TCGv arg0
,
752 TCGv arg1
, TCGv arg2
, int sub
)
754 TCGv t0
= tcg_temp_new();
756 tcg_gen_xor_tl(cpu_ov
, arg0
, arg2
);
757 tcg_gen_xor_tl(t0
, arg1
, arg2
);
759 tcg_gen_and_tl(cpu_ov
, cpu_ov
, t0
);
761 tcg_gen_andc_tl(cpu_ov
, cpu_ov
, t0
);
764 if (NARROW_MODE(ctx
)) {
765 tcg_gen_ext32s_tl(cpu_ov
, cpu_ov
);
767 tcg_gen_shri_tl(cpu_ov
, cpu_ov
, TARGET_LONG_BITS
- 1);
768 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
771 /* Common add function */
772 static inline void gen_op_arith_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
773 TCGv arg2
, bool add_ca
, bool compute_ca
,
774 bool compute_ov
, bool compute_rc0
)
778 if (compute_ca
|| compute_ov
) {
783 if (NARROW_MODE(ctx
)) {
784 /* Caution: a non-obvious corner case of the spec is that we
785 must produce the *entire* 64-bit addition, but produce the
786 carry into bit 32. */
787 TCGv t1
= tcg_temp_new();
788 tcg_gen_xor_tl(t1
, arg1
, arg2
); /* add without carry */
789 tcg_gen_add_tl(t0
, arg1
, arg2
);
791 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
793 tcg_gen_xor_tl(cpu_ca
, t0
, t1
); /* bits changed w/ carry */
795 tcg_gen_shri_tl(cpu_ca
, cpu_ca
, 32); /* extract bit 32 */
796 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
798 TCGv zero
= tcg_const_tl(0);
800 tcg_gen_add2_tl(t0
, cpu_ca
, arg1
, zero
, cpu_ca
, zero
);
801 tcg_gen_add2_tl(t0
, cpu_ca
, t0
, cpu_ca
, arg2
, zero
);
803 tcg_gen_add2_tl(t0
, cpu_ca
, arg1
, zero
, arg2
, zero
);
808 tcg_gen_add_tl(t0
, arg1
, arg2
);
810 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
815 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 0);
817 if (unlikely(compute_rc0
)) {
818 gen_set_Rc0(ctx
, t0
);
821 if (!TCGV_EQUAL(t0
, ret
)) {
822 tcg_gen_mov_tl(ret
, t0
);
826 /* Add functions with two operands */
827 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
828 static void glue(gen_, name)(DisasContext *ctx) \
830 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
831 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
832 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
834 /* Add functions with one operand and one immediate */
835 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
836 add_ca, compute_ca, compute_ov) \
837 static void glue(gen_, name)(DisasContext *ctx) \
839 TCGv t0 = tcg_const_tl(const_val); \
840 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
841 cpu_gpr[rA(ctx->opcode)], t0, \
842 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
846 /* add add. addo addo. */
847 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
848 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
849 /* addc addc. addco addco. */
850 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
851 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
852 /* adde adde. addeo addeo. */
853 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
854 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
855 /* addme addme. addmeo addmeo. */
856 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
857 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
858 /* addze addze. addzeo addzeo.*/
859 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
860 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
862 static void gen_addi(DisasContext
*ctx
)
864 target_long simm
= SIMM(ctx
->opcode
);
866 if (rA(ctx
->opcode
) == 0) {
868 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
);
870 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)],
871 cpu_gpr
[rA(ctx
->opcode
)], simm
);
875 static inline void gen_op_addic(DisasContext
*ctx
, bool compute_rc0
)
877 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
878 gen_op_arith_add(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
879 c
, 0, 1, 0, compute_rc0
);
883 static void gen_addic(DisasContext
*ctx
)
885 gen_op_addic(ctx
, 0);
888 static void gen_addic_(DisasContext
*ctx
)
890 gen_op_addic(ctx
, 1);
894 static void gen_addis(DisasContext
*ctx
)
896 target_long simm
= SIMM(ctx
->opcode
);
898 if (rA(ctx
->opcode
) == 0) {
900 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
<< 16);
902 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)],
903 cpu_gpr
[rA(ctx
->opcode
)], simm
<< 16);
907 static inline void gen_op_arith_divw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
908 TCGv arg2
, int sign
, int compute_ov
)
910 int l1
= gen_new_label();
911 int l2
= gen_new_label();
912 TCGv_i32 t0
= tcg_temp_local_new_i32();
913 TCGv_i32 t1
= tcg_temp_local_new_i32();
915 tcg_gen_trunc_tl_i32(t0
, arg1
);
916 tcg_gen_trunc_tl_i32(t1
, arg2
);
917 tcg_gen_brcondi_i32(TCG_COND_EQ
, t1
, 0, l1
);
919 int l3
= gen_new_label();
920 tcg_gen_brcondi_i32(TCG_COND_NE
, t1
, -1, l3
);
921 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, INT32_MIN
, l1
);
923 tcg_gen_div_i32(t0
, t0
, t1
);
925 tcg_gen_divu_i32(t0
, t0
, t1
);
928 tcg_gen_movi_tl(cpu_ov
, 0);
933 tcg_gen_sari_i32(t0
, t0
, 31);
935 tcg_gen_movi_i32(t0
, 0);
938 tcg_gen_movi_tl(cpu_ov
, 1);
939 tcg_gen_movi_tl(cpu_so
, 1);
942 tcg_gen_extu_i32_tl(ret
, t0
);
943 tcg_temp_free_i32(t0
);
944 tcg_temp_free_i32(t1
);
945 if (unlikely(Rc(ctx
->opcode
) != 0))
946 gen_set_Rc0(ctx
, ret
);
949 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
950 static void glue(gen_, name)(DisasContext *ctx) \
952 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
953 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
956 /* divwu divwu. divwuo divwuo. */
957 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0);
958 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1);
959 /* divw divw. divwo divwo. */
960 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0);
961 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1);
962 #if defined(TARGET_PPC64)
963 static inline void gen_op_arith_divd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
964 TCGv arg2
, int sign
, int compute_ov
)
966 int l1
= gen_new_label();
967 int l2
= gen_new_label();
969 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg2
, 0, l1
);
971 int l3
= gen_new_label();
972 tcg_gen_brcondi_i64(TCG_COND_NE
, arg2
, -1, l3
);
973 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg1
, INT64_MIN
, l1
);
975 tcg_gen_div_i64(ret
, arg1
, arg2
);
977 tcg_gen_divu_i64(ret
, arg1
, arg2
);
980 tcg_gen_movi_tl(cpu_ov
, 0);
985 tcg_gen_sari_i64(ret
, arg1
, 63);
987 tcg_gen_movi_i64(ret
, 0);
990 tcg_gen_movi_tl(cpu_ov
, 1);
991 tcg_gen_movi_tl(cpu_so
, 1);
994 if (unlikely(Rc(ctx
->opcode
) != 0))
995 gen_set_Rc0(ctx
, ret
);
997 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
998 static void glue(gen_, name)(DisasContext *ctx) \
1000 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1001 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1002 sign, compute_ov); \
1004 /* divwu divwu. divwuo divwuo. */
1005 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0);
1006 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1);
1007 /* divw divw. divwo divwo. */
1008 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0);
1009 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1);
1013 static void gen_mulhw(DisasContext
*ctx
)
1015 TCGv_i32 t0
= tcg_temp_new_i32();
1016 TCGv_i32 t1
= tcg_temp_new_i32();
1018 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1019 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1020 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1021 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1022 tcg_temp_free_i32(t0
);
1023 tcg_temp_free_i32(t1
);
1024 if (unlikely(Rc(ctx
->opcode
) != 0))
1025 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1028 /* mulhwu mulhwu. */
1029 static void gen_mulhwu(DisasContext
*ctx
)
1031 TCGv_i32 t0
= tcg_temp_new_i32();
1032 TCGv_i32 t1
= tcg_temp_new_i32();
1034 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1035 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1036 tcg_gen_mulu2_i32(t0
, t1
, t0
, t1
);
1037 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1038 tcg_temp_free_i32(t0
);
1039 tcg_temp_free_i32(t1
);
1040 if (unlikely(Rc(ctx
->opcode
) != 0))
1041 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1045 static void gen_mullw(DisasContext
*ctx
)
1047 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1048 cpu_gpr
[rB(ctx
->opcode
)]);
1049 tcg_gen_ext32s_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)]);
1050 if (unlikely(Rc(ctx
->opcode
) != 0))
1051 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1054 /* mullwo mullwo. */
1055 static void gen_mullwo(DisasContext
*ctx
)
1057 TCGv_i32 t0
= tcg_temp_new_i32();
1058 TCGv_i32 t1
= tcg_temp_new_i32();
1060 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1061 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1062 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1063 tcg_gen_ext_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1065 tcg_gen_sari_i32(t0
, t0
, 31);
1066 tcg_gen_setcond_i32(TCG_COND_NE
, t0
, t0
, t1
);
1067 tcg_gen_extu_i32_tl(cpu_ov
, t0
);
1068 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1070 tcg_temp_free_i32(t0
);
1071 tcg_temp_free_i32(t1
);
1072 if (unlikely(Rc(ctx
->opcode
) != 0))
1073 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1077 static void gen_mulli(DisasContext
*ctx
)
1079 tcg_gen_muli_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1083 #if defined(TARGET_PPC64)
1085 static void gen_mulhd(DisasContext
*ctx
)
1087 TCGv lo
= tcg_temp_new();
1088 tcg_gen_muls2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1089 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1091 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1092 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1096 /* mulhdu mulhdu. */
1097 static void gen_mulhdu(DisasContext
*ctx
)
1099 TCGv lo
= tcg_temp_new();
1100 tcg_gen_mulu2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1101 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1103 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1104 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1109 static void gen_mulld(DisasContext
*ctx
)
1111 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1112 cpu_gpr
[rB(ctx
->opcode
)]);
1113 if (unlikely(Rc(ctx
->opcode
) != 0))
1114 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1117 /* mulldo mulldo. */
1118 static void gen_mulldo(DisasContext
*ctx
)
1120 gen_helper_mulldo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
1121 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1122 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1123 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1128 /* Common subf function */
1129 static inline void gen_op_arith_subf(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1130 TCGv arg2
, bool add_ca
, bool compute_ca
,
1131 bool compute_ov
, bool compute_rc0
)
1135 if (compute_ca
|| compute_ov
) {
1136 t0
= tcg_temp_new();
1140 /* dest = ~arg1 + arg2 [+ ca]. */
1141 if (NARROW_MODE(ctx
)) {
1142 /* Caution: a non-obvious corner case of the spec is that we
1143 must produce the *entire* 64-bit addition, but produce the
1144 carry into bit 32. */
1145 TCGv inv1
= tcg_temp_new();
1146 TCGv t1
= tcg_temp_new();
1147 tcg_gen_not_tl(inv1
, arg1
);
1149 tcg_gen_add_tl(t0
, arg2
, cpu_ca
);
1151 tcg_gen_addi_tl(t0
, arg2
, 1);
1153 tcg_gen_xor_tl(t1
, arg2
, inv1
); /* add without carry */
1154 tcg_gen_add_tl(t0
, t0
, inv1
);
1155 tcg_gen_xor_tl(cpu_ca
, t0
, t1
); /* bits changes w/ carry */
1157 tcg_gen_shri_tl(cpu_ca
, cpu_ca
, 32); /* extract bit 32 */
1158 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
1159 } else if (add_ca
) {
1160 TCGv zero
, inv1
= tcg_temp_new();
1161 tcg_gen_not_tl(inv1
, arg1
);
1162 zero
= tcg_const_tl(0);
1163 tcg_gen_add2_tl(t0
, cpu_ca
, arg2
, zero
, cpu_ca
, zero
);
1164 tcg_gen_add2_tl(t0
, cpu_ca
, t0
, cpu_ca
, inv1
, zero
);
1165 tcg_temp_free(zero
);
1166 tcg_temp_free(inv1
);
1168 tcg_gen_setcond_tl(TCG_COND_GEU
, cpu_ca
, arg2
, arg1
);
1169 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1171 } else if (add_ca
) {
1172 /* Since we're ignoring carry-out, we can simplify the
1173 standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1. */
1174 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1175 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
1176 tcg_gen_subi_tl(t0
, t0
, 1);
1178 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1182 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 1);
1184 if (unlikely(compute_rc0
)) {
1185 gen_set_Rc0(ctx
, t0
);
1188 if (!TCGV_EQUAL(t0
, ret
)) {
1189 tcg_gen_mov_tl(ret
, t0
);
1193 /* Sub functions with Two operands functions */
1194 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1195 static void glue(gen_, name)(DisasContext *ctx) \
1197 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1198 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1199 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1201 /* Sub functions with one operand and one immediate */
1202 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1203 add_ca, compute_ca, compute_ov) \
1204 static void glue(gen_, name)(DisasContext *ctx) \
1206 TCGv t0 = tcg_const_tl(const_val); \
1207 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1208 cpu_gpr[rA(ctx->opcode)], t0, \
1209 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1210 tcg_temp_free(t0); \
1212 /* subf subf. subfo subfo. */
1213 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
1214 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
1215 /* subfc subfc. subfco subfco. */
1216 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
1217 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
1218 /* subfe subfe. subfeo subfo. */
1219 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
1220 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
1221 /* subfme subfme. subfmeo subfmeo. */
1222 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
1223 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
1224 /* subfze subfze. subfzeo subfzeo.*/
1225 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
1226 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
1229 static void gen_subfic(DisasContext
*ctx
)
1231 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
1232 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1237 /* neg neg. nego nego. */
1238 static inline void gen_op_arith_neg(DisasContext
*ctx
, bool compute_ov
)
1240 TCGv zero
= tcg_const_tl(0);
1241 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1242 zero
, 0, 0, compute_ov
, Rc(ctx
->opcode
));
1243 tcg_temp_free(zero
);
1246 static void gen_neg(DisasContext
*ctx
)
1248 gen_op_arith_neg(ctx
, 0);
1251 static void gen_nego(DisasContext
*ctx
)
1253 gen_op_arith_neg(ctx
, 1);
1256 /*** Integer logical ***/
1257 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1258 static void glue(gen_, name)(DisasContext *ctx) \
1260 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1261 cpu_gpr[rB(ctx->opcode)]); \
1262 if (unlikely(Rc(ctx->opcode) != 0)) \
1263 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1266 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1267 static void glue(gen_, name)(DisasContext *ctx) \
1269 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1270 if (unlikely(Rc(ctx->opcode) != 0)) \
1271 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1275 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
);
1277 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
);
1280 static void gen_andi_(DisasContext
*ctx
)
1282 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
));
1283 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1287 static void gen_andis_(DisasContext
*ctx
)
1289 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
) << 16);
1290 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1294 static void gen_cntlzw(DisasContext
*ctx
)
1296 gen_helper_cntlzw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1297 if (unlikely(Rc(ctx
->opcode
) != 0))
1298 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1301 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
);
1302 /* extsb & extsb. */
1303 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
);
1304 /* extsh & extsh. */
1305 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
);
1307 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
);
1309 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
);
1312 static void gen_or(DisasContext
*ctx
)
1316 rs
= rS(ctx
->opcode
);
1317 ra
= rA(ctx
->opcode
);
1318 rb
= rB(ctx
->opcode
);
1319 /* Optimisation for mr. ri case */
1320 if (rs
!= ra
|| rs
!= rb
) {
1322 tcg_gen_or_tl(cpu_gpr
[ra
], cpu_gpr
[rs
], cpu_gpr
[rb
]);
1324 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rs
]);
1325 if (unlikely(Rc(ctx
->opcode
) != 0))
1326 gen_set_Rc0(ctx
, cpu_gpr
[ra
]);
1327 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
1328 gen_set_Rc0(ctx
, cpu_gpr
[rs
]);
1329 #if defined(TARGET_PPC64)
1335 /* Set process priority to low */
1339 /* Set process priority to medium-low */
1343 /* Set process priority to normal */
1346 #if !defined(CONFIG_USER_ONLY)
1348 if (ctx
->mem_idx
> 0) {
1349 /* Set process priority to very low */
1354 if (ctx
->mem_idx
> 0) {
1355 /* Set process priority to medium-hight */
1360 if (ctx
->mem_idx
> 0) {
1361 /* Set process priority to high */
1366 if (ctx
->mem_idx
> 1) {
1367 /* Set process priority to very high */
1377 TCGv t0
= tcg_temp_new();
1378 gen_load_spr(t0
, SPR_PPR
);
1379 tcg_gen_andi_tl(t0
, t0
, ~0x001C000000000000ULL
);
1380 tcg_gen_ori_tl(t0
, t0
, ((uint64_t)prio
) << 50);
1381 gen_store_spr(SPR_PPR
, t0
);
1388 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
);
1391 static void gen_xor(DisasContext
*ctx
)
1393 /* Optimisation for "set to zero" case */
1394 if (rS(ctx
->opcode
) != rB(ctx
->opcode
))
1395 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1397 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1398 if (unlikely(Rc(ctx
->opcode
) != 0))
1399 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1403 static void gen_ori(DisasContext
*ctx
)
1405 target_ulong uimm
= UIMM(ctx
->opcode
);
1407 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1409 /* XXX: should handle special NOPs for POWER series */
1412 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1416 static void gen_oris(DisasContext
*ctx
)
1418 target_ulong uimm
= UIMM(ctx
->opcode
);
1420 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1424 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1428 static void gen_xori(DisasContext
*ctx
)
1430 target_ulong uimm
= UIMM(ctx
->opcode
);
1432 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1436 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1440 static void gen_xoris(DisasContext
*ctx
)
1442 target_ulong uimm
= UIMM(ctx
->opcode
);
1444 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1448 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1451 /* popcntb : PowerPC 2.03 specification */
1452 static void gen_popcntb(DisasContext
*ctx
)
1454 gen_helper_popcntb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1457 static void gen_popcntw(DisasContext
*ctx
)
1459 gen_helper_popcntw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1462 #if defined(TARGET_PPC64)
1463 /* popcntd: PowerPC 2.06 specification */
1464 static void gen_popcntd(DisasContext
*ctx
)
1466 gen_helper_popcntd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1470 /* prtyw: PowerPC 2.05 specification */
1471 static void gen_prtyw(DisasContext
*ctx
)
1473 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
1474 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
1475 TCGv t0
= tcg_temp_new();
1476 tcg_gen_shri_tl(t0
, rs
, 16);
1477 tcg_gen_xor_tl(ra
, rs
, t0
);
1478 tcg_gen_shri_tl(t0
, ra
, 8);
1479 tcg_gen_xor_tl(ra
, ra
, t0
);
1480 tcg_gen_andi_tl(ra
, ra
, (target_ulong
)0x100000001ULL
);
1484 #if defined(TARGET_PPC64)
1485 /* prtyd: PowerPC 2.05 specification */
1486 static void gen_prtyd(DisasContext
*ctx
)
1488 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
1489 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
1490 TCGv t0
= tcg_temp_new();
1491 tcg_gen_shri_tl(t0
, rs
, 32);
1492 tcg_gen_xor_tl(ra
, rs
, t0
);
1493 tcg_gen_shri_tl(t0
, ra
, 16);
1494 tcg_gen_xor_tl(ra
, ra
, t0
);
1495 tcg_gen_shri_tl(t0
, ra
, 8);
1496 tcg_gen_xor_tl(ra
, ra
, t0
);
1497 tcg_gen_andi_tl(ra
, ra
, 1);
1502 #if defined(TARGET_PPC64)
1503 /* extsw & extsw. */
1504 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
);
1507 static void gen_cntlzd(DisasContext
*ctx
)
1509 gen_helper_cntlzd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1510 if (unlikely(Rc(ctx
->opcode
) != 0))
1511 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1515 /*** Integer rotate ***/
1517 /* rlwimi & rlwimi. */
1518 static void gen_rlwimi(DisasContext
*ctx
)
1520 uint32_t mb
, me
, sh
;
1522 mb
= MB(ctx
->opcode
);
1523 me
= ME(ctx
->opcode
);
1524 sh
= SH(ctx
->opcode
);
1525 if (likely(sh
== 0 && mb
== 0 && me
== 31)) {
1526 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1530 TCGv t0
= tcg_temp_new();
1531 #if defined(TARGET_PPC64)
1532 TCGv_i32 t2
= tcg_temp_new_i32();
1533 tcg_gen_trunc_i64_i32(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
1534 tcg_gen_rotli_i32(t2
, t2
, sh
);
1535 tcg_gen_extu_i32_i64(t0
, t2
);
1536 tcg_temp_free_i32(t2
);
1538 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1540 #if defined(TARGET_PPC64)
1544 mask
= MASK(mb
, me
);
1545 t1
= tcg_temp_new();
1546 tcg_gen_andi_tl(t0
, t0
, mask
);
1547 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1548 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1552 if (unlikely(Rc(ctx
->opcode
) != 0))
1553 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1556 /* rlwinm & rlwinm. */
1557 static void gen_rlwinm(DisasContext
*ctx
)
1559 uint32_t mb
, me
, sh
;
1561 sh
= SH(ctx
->opcode
);
1562 mb
= MB(ctx
->opcode
);
1563 me
= ME(ctx
->opcode
);
1565 if (likely(mb
== 0 && me
== (31 - sh
))) {
1566 if (likely(sh
== 0)) {
1567 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1569 TCGv t0
= tcg_temp_new();
1570 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1571 tcg_gen_shli_tl(t0
, t0
, sh
);
1572 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1575 } else if (likely(sh
!= 0 && me
== 31 && sh
== (32 - mb
))) {
1576 TCGv t0
= tcg_temp_new();
1577 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1578 tcg_gen_shri_tl(t0
, t0
, mb
);
1579 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1582 TCGv t0
= tcg_temp_new();
1583 #if defined(TARGET_PPC64)
1584 TCGv_i32 t1
= tcg_temp_new_i32();
1585 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1586 tcg_gen_rotli_i32(t1
, t1
, sh
);
1587 tcg_gen_extu_i32_i64(t0
, t1
);
1588 tcg_temp_free_i32(t1
);
1590 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1592 #if defined(TARGET_PPC64)
1596 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1599 if (unlikely(Rc(ctx
->opcode
) != 0))
1600 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1603 /* rlwnm & rlwnm. */
1604 static void gen_rlwnm(DisasContext
*ctx
)
1608 #if defined(TARGET_PPC64)
1612 mb
= MB(ctx
->opcode
);
1613 me
= ME(ctx
->opcode
);
1614 t0
= tcg_temp_new();
1615 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1616 #if defined(TARGET_PPC64)
1617 t1
= tcg_temp_new_i32();
1618 t2
= tcg_temp_new_i32();
1619 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1620 tcg_gen_trunc_i64_i32(t2
, t0
);
1621 tcg_gen_rotl_i32(t1
, t1
, t2
);
1622 tcg_gen_extu_i32_i64(t0
, t1
);
1623 tcg_temp_free_i32(t1
);
1624 tcg_temp_free_i32(t2
);
1626 tcg_gen_rotl_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1628 if (unlikely(mb
!= 0 || me
!= 31)) {
1629 #if defined(TARGET_PPC64)
1633 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1635 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1638 if (unlikely(Rc(ctx
->opcode
) != 0))
1639 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1642 #if defined(TARGET_PPC64)
1643 #define GEN_PPC64_R2(name, opc1, opc2) \
1644 static void glue(gen_, name##0)(DisasContext *ctx) \
1646 gen_##name(ctx, 0); \
1649 static void glue(gen_, name##1)(DisasContext *ctx) \
1651 gen_##name(ctx, 1); \
1653 #define GEN_PPC64_R4(name, opc1, opc2) \
1654 static void glue(gen_, name##0)(DisasContext *ctx) \
1656 gen_##name(ctx, 0, 0); \
1659 static void glue(gen_, name##1)(DisasContext *ctx) \
1661 gen_##name(ctx, 0, 1); \
1664 static void glue(gen_, name##2)(DisasContext *ctx) \
1666 gen_##name(ctx, 1, 0); \
1669 static void glue(gen_, name##3)(DisasContext *ctx) \
1671 gen_##name(ctx, 1, 1); \
1674 static inline void gen_rldinm(DisasContext
*ctx
, uint32_t mb
, uint32_t me
,
1677 if (likely(sh
!= 0 && mb
== 0 && me
== (63 - sh
))) {
1678 tcg_gen_shli_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
1679 } else if (likely(sh
!= 0 && me
== 63 && sh
== (64 - mb
))) {
1680 tcg_gen_shri_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], mb
);
1682 TCGv t0
= tcg_temp_new();
1683 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1684 if (likely(mb
== 0 && me
== 63)) {
1685 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1687 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1691 if (unlikely(Rc(ctx
->opcode
) != 0))
1692 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1694 /* rldicl - rldicl. */
1695 static inline void gen_rldicl(DisasContext
*ctx
, int mbn
, int shn
)
1699 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1700 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1701 gen_rldinm(ctx
, mb
, 63, sh
);
1703 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
1704 /* rldicr - rldicr. */
1705 static inline void gen_rldicr(DisasContext
*ctx
, int men
, int shn
)
1709 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1710 me
= MB(ctx
->opcode
) | (men
<< 5);
1711 gen_rldinm(ctx
, 0, me
, sh
);
1713 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
1714 /* rldic - rldic. */
1715 static inline void gen_rldic(DisasContext
*ctx
, int mbn
, int shn
)
1719 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1720 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1721 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
1723 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
1725 static inline void gen_rldnm(DisasContext
*ctx
, uint32_t mb
, uint32_t me
)
1729 mb
= MB(ctx
->opcode
);
1730 me
= ME(ctx
->opcode
);
1731 t0
= tcg_temp_new();
1732 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1733 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1734 if (unlikely(mb
!= 0 || me
!= 63)) {
1735 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1737 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1740 if (unlikely(Rc(ctx
->opcode
) != 0))
1741 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1744 /* rldcl - rldcl. */
1745 static inline void gen_rldcl(DisasContext
*ctx
, int mbn
)
1749 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1750 gen_rldnm(ctx
, mb
, 63);
1752 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
1753 /* rldcr - rldcr. */
1754 static inline void gen_rldcr(DisasContext
*ctx
, int men
)
1758 me
= MB(ctx
->opcode
) | (men
<< 5);
1759 gen_rldnm(ctx
, 0, me
);
1761 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
1762 /* rldimi - rldimi. */
1763 static inline void gen_rldimi(DisasContext
*ctx
, int mbn
, int shn
)
1765 uint32_t sh
, mb
, me
;
1767 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1768 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1770 if (unlikely(sh
== 0 && mb
== 0)) {
1771 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1776 t0
= tcg_temp_new();
1777 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1778 t1
= tcg_temp_new();
1779 mask
= MASK(mb
, me
);
1780 tcg_gen_andi_tl(t0
, t0
, mask
);
1781 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1782 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1786 if (unlikely(Rc(ctx
->opcode
) != 0))
1787 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1789 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
1792 /*** Integer shift ***/
1795 static void gen_slw(DisasContext
*ctx
)
1799 t0
= tcg_temp_new();
1800 /* AND rS with a mask that is 0 when rB >= 0x20 */
1801 #if defined(TARGET_PPC64)
1802 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
1803 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1805 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
1806 tcg_gen_sari_tl(t0
, t0
, 0x1f);
1808 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1809 t1
= tcg_temp_new();
1810 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1811 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1814 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
1815 if (unlikely(Rc(ctx
->opcode
) != 0))
1816 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1820 static void gen_sraw(DisasContext
*ctx
)
1822 gen_helper_sraw(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
1823 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1824 if (unlikely(Rc(ctx
->opcode
) != 0))
1825 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1828 /* srawi & srawi. */
1829 static void gen_srawi(DisasContext
*ctx
)
1831 int sh
= SH(ctx
->opcode
);
1832 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
1833 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
1835 tcg_gen_mov_tl(dst
, src
);
1836 tcg_gen_movi_tl(cpu_ca
, 0);
1839 tcg_gen_ext32s_tl(dst
, src
);
1840 tcg_gen_andi_tl(cpu_ca
, dst
, (1ULL << sh
) - 1);
1841 t0
= tcg_temp_new();
1842 tcg_gen_sari_tl(t0
, dst
, TARGET_LONG_BITS
- 1);
1843 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
1845 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
1846 tcg_gen_sari_tl(dst
, dst
, sh
);
1848 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1849 gen_set_Rc0(ctx
, dst
);
1854 static void gen_srw(DisasContext
*ctx
)
1858 t0
= tcg_temp_new();
1859 /* AND rS with a mask that is 0 when rB >= 0x20 */
1860 #if defined(TARGET_PPC64)
1861 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
1862 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1864 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
1865 tcg_gen_sari_tl(t0
, t0
, 0x1f);
1867 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1868 tcg_gen_ext32u_tl(t0
, t0
);
1869 t1
= tcg_temp_new();
1870 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1871 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1874 if (unlikely(Rc(ctx
->opcode
) != 0))
1875 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1878 #if defined(TARGET_PPC64)
1880 static void gen_sld(DisasContext
*ctx
)
1884 t0
= tcg_temp_new();
1885 /* AND rS with a mask that is 0 when rB >= 0x40 */
1886 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
1887 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1888 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1889 t1
= tcg_temp_new();
1890 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1891 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1894 if (unlikely(Rc(ctx
->opcode
) != 0))
1895 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1899 static void gen_srad(DisasContext
*ctx
)
1901 gen_helper_srad(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
1902 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1903 if (unlikely(Rc(ctx
->opcode
) != 0))
1904 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1906 /* sradi & sradi. */
1907 static inline void gen_sradi(DisasContext
*ctx
, int n
)
1909 int sh
= SH(ctx
->opcode
) + (n
<< 5);
1910 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
1911 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
1913 tcg_gen_mov_tl(dst
, src
);
1914 tcg_gen_movi_tl(cpu_ca
, 0);
1917 tcg_gen_andi_tl(cpu_ca
, src
, (1ULL << sh
) - 1);
1918 t0
= tcg_temp_new();
1919 tcg_gen_sari_tl(t0
, src
, TARGET_LONG_BITS
- 1);
1920 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
1922 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
1923 tcg_gen_sari_tl(dst
, src
, sh
);
1925 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1926 gen_set_Rc0(ctx
, dst
);
1930 static void gen_sradi0(DisasContext
*ctx
)
1935 static void gen_sradi1(DisasContext
*ctx
)
1941 static void gen_srd(DisasContext
*ctx
)
1945 t0
= tcg_temp_new();
1946 /* AND rS with a mask that is 0 when rB >= 0x40 */
1947 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
1948 tcg_gen_sari_tl(t0
, t0
, 0x3f);
1949 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1950 t1
= tcg_temp_new();
1951 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1952 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1955 if (unlikely(Rc(ctx
->opcode
) != 0))
1956 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1960 /*** Floating-Point arithmetic ***/
1961 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
1962 static void gen_f##name(DisasContext *ctx) \
1964 if (unlikely(!ctx->fpu_enabled)) { \
1965 gen_exception(ctx, POWERPC_EXCP_FPU); \
1968 /* NIP cannot be restored if the memory exception comes from an helper */ \
1969 gen_update_nip(ctx, ctx->nip - 4); \
1970 gen_reset_fpstatus(); \
1971 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1972 cpu_fpr[rA(ctx->opcode)], \
1973 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
1975 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1976 cpu_fpr[rD(ctx->opcode)]); \
1978 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \
1979 Rc(ctx->opcode) != 0); \
1982 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
1983 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
1984 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
1986 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
1987 static void gen_f##name(DisasContext *ctx) \
1989 if (unlikely(!ctx->fpu_enabled)) { \
1990 gen_exception(ctx, POWERPC_EXCP_FPU); \
1993 /* NIP cannot be restored if the memory exception comes from an helper */ \
1994 gen_update_nip(ctx, ctx->nip - 4); \
1995 gen_reset_fpstatus(); \
1996 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
1997 cpu_fpr[rA(ctx->opcode)], \
1998 cpu_fpr[rB(ctx->opcode)]); \
2000 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2001 cpu_fpr[rD(ctx->opcode)]); \
2003 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2004 set_fprf, Rc(ctx->opcode) != 0); \
2006 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2007 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2008 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2010 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2011 static void gen_f##name(DisasContext *ctx) \
2013 if (unlikely(!ctx->fpu_enabled)) { \
2014 gen_exception(ctx, POWERPC_EXCP_FPU); \
2017 /* NIP cannot be restored if the memory exception comes from an helper */ \
2018 gen_update_nip(ctx, ctx->nip - 4); \
2019 gen_reset_fpstatus(); \
2020 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2021 cpu_fpr[rA(ctx->opcode)], \
2022 cpu_fpr[rC(ctx->opcode)]); \
2024 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2025 cpu_fpr[rD(ctx->opcode)]); \
2027 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2028 set_fprf, Rc(ctx->opcode) != 0); \
2030 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2031 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2032 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2034 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
2035 static void gen_f##name(DisasContext *ctx) \
2037 if (unlikely(!ctx->fpu_enabled)) { \
2038 gen_exception(ctx, POWERPC_EXCP_FPU); \
2041 /* NIP cannot be restored if the memory exception comes from an helper */ \
2042 gen_update_nip(ctx, ctx->nip - 4); \
2043 gen_reset_fpstatus(); \
2044 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2045 cpu_fpr[rB(ctx->opcode)]); \
2046 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2047 set_fprf, Rc(ctx->opcode) != 0); \
2050 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
2051 static void gen_f##name(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_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \
2061 cpu_fpr[rB(ctx->opcode)]); \
2062 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2063 set_fprf, Rc(ctx->opcode) != 0); \
2067 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
);
2069 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
);
2071 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
);
2074 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
);
2077 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
);
2080 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
);
2083 static void gen_frsqrtes(DisasContext
*ctx
)
2085 if (unlikely(!ctx
->fpu_enabled
)) {
2086 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2089 /* NIP cannot be restored if the memory exception comes from an helper */
2090 gen_update_nip(ctx
, ctx
->nip
- 4);
2091 gen_reset_fpstatus();
2092 gen_helper_frsqrte(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2093 cpu_fpr
[rB(ctx
->opcode
)]);
2094 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2095 cpu_fpr
[rD(ctx
->opcode
)]);
2096 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2100 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
);
2102 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
);
2106 static void gen_fsqrt(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 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2116 cpu_fpr
[rB(ctx
->opcode
)]);
2117 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2120 static void gen_fsqrts(DisasContext
*ctx
)
2122 if (unlikely(!ctx
->fpu_enabled
)) {
2123 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2126 /* NIP cannot be restored if the memory exception comes from an helper */
2127 gen_update_nip(ctx
, ctx
->nip
- 4);
2128 gen_reset_fpstatus();
2129 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2130 cpu_fpr
[rB(ctx
->opcode
)]);
2131 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_env
,
2132 cpu_fpr
[rD(ctx
->opcode
)]);
2133 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2136 /*** Floating-Point multiply-and-add ***/
2137 /* fmadd - fmadds */
2138 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
);
2139 /* fmsub - fmsubs */
2140 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
);
2141 /* fnmadd - fnmadds */
2142 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
);
2143 /* fnmsub - fnmsubs */
2144 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
);
2146 /*** Floating-Point round & convert ***/
2148 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
);
2150 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
);
2152 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
);
2153 #if defined(TARGET_PPC64)
2155 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
);
2157 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
);
2159 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
);
2163 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
);
2165 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
);
2167 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
);
2169 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
);
2171 /*** Floating-Point compare ***/
2174 static void gen_fcmpo(DisasContext
*ctx
)
2177 if (unlikely(!ctx
->fpu_enabled
)) {
2178 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2181 /* NIP cannot be restored if the memory exception comes from an helper */
2182 gen_update_nip(ctx
, ctx
->nip
- 4);
2183 gen_reset_fpstatus();
2184 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2185 gen_helper_fcmpo(cpu_env
, cpu_fpr
[rA(ctx
->opcode
)],
2186 cpu_fpr
[rB(ctx
->opcode
)], crf
);
2187 tcg_temp_free_i32(crf
);
2188 gen_helper_float_check_status(cpu_env
);
2192 static void gen_fcmpu(DisasContext
*ctx
)
2195 if (unlikely(!ctx
->fpu_enabled
)) {
2196 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2199 /* NIP cannot be restored if the memory exception comes from an helper */
2200 gen_update_nip(ctx
, ctx
->nip
- 4);
2201 gen_reset_fpstatus();
2202 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2203 gen_helper_fcmpu(cpu_env
, cpu_fpr
[rA(ctx
->opcode
)],
2204 cpu_fpr
[rB(ctx
->opcode
)], crf
);
2205 tcg_temp_free_i32(crf
);
2206 gen_helper_float_check_status(cpu_env
);
2209 /*** Floating-point move ***/
2211 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2212 static void gen_fabs(DisasContext
*ctx
)
2214 if (unlikely(!ctx
->fpu_enabled
)) {
2215 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2218 tcg_gen_andi_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)],
2220 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2224 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2225 static void gen_fmr(DisasContext
*ctx
)
2227 if (unlikely(!ctx
->fpu_enabled
)) {
2228 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2231 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2232 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2236 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2237 static void gen_fnabs(DisasContext
*ctx
)
2239 if (unlikely(!ctx
->fpu_enabled
)) {
2240 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2243 tcg_gen_ori_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)],
2245 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2249 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2250 static void gen_fneg(DisasContext
*ctx
)
2252 if (unlikely(!ctx
->fpu_enabled
)) {
2253 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2256 tcg_gen_xori_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)],
2258 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2261 /* fcpsgn: PowerPC 2.05 specification */
2262 /* XXX: beware that fcpsgn never checks for NaNs nor update FPSCR */
2263 static void gen_fcpsgn(DisasContext
*ctx
)
2265 if (unlikely(!ctx
->fpu_enabled
)) {
2266 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2269 tcg_gen_deposit_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rA(ctx
->opcode
)],
2270 cpu_fpr
[rB(ctx
->opcode
)], 0, 63);
2271 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2274 /*** Floating-Point status & ctrl register ***/
2277 static void gen_mcrfs(DisasContext
*ctx
)
2279 TCGv tmp
= tcg_temp_new();
2282 if (unlikely(!ctx
->fpu_enabled
)) {
2283 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2286 bfa
= 4 * (7 - crfS(ctx
->opcode
));
2287 tcg_gen_shri_tl(tmp
, cpu_fpscr
, bfa
);
2288 tcg_gen_trunc_tl_i32(cpu_crf
[crfD(ctx
->opcode
)], tmp
);
2290 tcg_gen_andi_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfD(ctx
->opcode
)], 0xf);
2291 tcg_gen_andi_tl(cpu_fpscr
, cpu_fpscr
, ~(0xF << bfa
));
2295 static void gen_mffs(DisasContext
*ctx
)
2297 if (unlikely(!ctx
->fpu_enabled
)) {
2298 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2301 gen_reset_fpstatus();
2302 tcg_gen_extu_tl_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpscr
);
2303 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2307 static void gen_mtfsb0(DisasContext
*ctx
)
2311 if (unlikely(!ctx
->fpu_enabled
)) {
2312 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2315 crb
= 31 - crbD(ctx
->opcode
);
2316 gen_reset_fpstatus();
2317 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
)) {
2319 /* NIP cannot be restored if the memory exception comes from an helper */
2320 gen_update_nip(ctx
, ctx
->nip
- 4);
2321 t0
= tcg_const_i32(crb
);
2322 gen_helper_fpscr_clrbit(cpu_env
, t0
);
2323 tcg_temp_free_i32(t0
);
2325 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2326 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2327 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2332 static void gen_mtfsb1(DisasContext
*ctx
)
2336 if (unlikely(!ctx
->fpu_enabled
)) {
2337 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2340 crb
= 31 - crbD(ctx
->opcode
);
2341 gen_reset_fpstatus();
2342 /* XXX: we pretend we can only do IEEE floating-point computations */
2343 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
&& crb
!= FPSCR_NI
)) {
2345 /* NIP cannot be restored if the memory exception comes from an helper */
2346 gen_update_nip(ctx
, ctx
->nip
- 4);
2347 t0
= tcg_const_i32(crb
);
2348 gen_helper_fpscr_setbit(cpu_env
, t0
);
2349 tcg_temp_free_i32(t0
);
2351 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2352 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2353 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2355 /* We can raise a differed exception */
2356 gen_helper_float_check_status(cpu_env
);
2360 static void gen_mtfsf(DisasContext
*ctx
)
2363 int L
= ctx
->opcode
& 0x02000000;
2365 if (unlikely(!ctx
->fpu_enabled
)) {
2366 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2369 /* NIP cannot be restored if the memory exception comes from an helper */
2370 gen_update_nip(ctx
, ctx
->nip
- 4);
2371 gen_reset_fpstatus();
2373 t0
= tcg_const_i32(0xff);
2375 t0
= tcg_const_i32(FM(ctx
->opcode
));
2376 gen_helper_store_fpscr(cpu_env
, cpu_fpr
[rB(ctx
->opcode
)], t0
);
2377 tcg_temp_free_i32(t0
);
2378 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2379 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2380 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2382 /* We can raise a differed exception */
2383 gen_helper_float_check_status(cpu_env
);
2387 static void gen_mtfsfi(DisasContext
*ctx
)
2393 if (unlikely(!ctx
->fpu_enabled
)) {
2394 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2397 bf
= crbD(ctx
->opcode
) >> 2;
2399 /* NIP cannot be restored if the memory exception comes from an helper */
2400 gen_update_nip(ctx
, ctx
->nip
- 4);
2401 gen_reset_fpstatus();
2402 t0
= tcg_const_i64(FPIMM(ctx
->opcode
) << (4 * sh
));
2403 t1
= tcg_const_i32(1 << sh
);
2404 gen_helper_store_fpscr(cpu_env
, t0
, t1
);
2405 tcg_temp_free_i64(t0
);
2406 tcg_temp_free_i32(t1
);
2407 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2408 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_fpscr
);
2409 tcg_gen_shri_i32(cpu_crf
[1], cpu_crf
[1], FPSCR_OX
);
2411 /* We can raise a differed exception */
2412 gen_helper_float_check_status(cpu_env
);
2415 /*** Addressing modes ***/
2416 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2417 static inline void gen_addr_imm_index(DisasContext
*ctx
, TCGv EA
,
2420 target_long simm
= SIMM(ctx
->opcode
);
2423 if (rA(ctx
->opcode
) == 0) {
2424 if (NARROW_MODE(ctx
)) {
2425 simm
= (uint32_t)simm
;
2427 tcg_gen_movi_tl(EA
, simm
);
2428 } else if (likely(simm
!= 0)) {
2429 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
);
2430 if (NARROW_MODE(ctx
)) {
2431 tcg_gen_ext32u_tl(EA
, EA
);
2434 if (NARROW_MODE(ctx
)) {
2435 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2437 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2442 static inline void gen_addr_reg_index(DisasContext
*ctx
, TCGv EA
)
2444 if (rA(ctx
->opcode
) == 0) {
2445 if (NARROW_MODE(ctx
)) {
2446 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2448 tcg_gen_mov_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2451 tcg_gen_add_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2452 if (NARROW_MODE(ctx
)) {
2453 tcg_gen_ext32u_tl(EA
, EA
);
2458 static inline void gen_addr_register(DisasContext
*ctx
, TCGv EA
)
2460 if (rA(ctx
->opcode
) == 0) {
2461 tcg_gen_movi_tl(EA
, 0);
2462 } else if (NARROW_MODE(ctx
)) {
2463 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2465 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2469 static inline void gen_addr_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
2472 tcg_gen_addi_tl(ret
, arg1
, val
);
2473 if (NARROW_MODE(ctx
)) {
2474 tcg_gen_ext32u_tl(ret
, ret
);
2478 static inline void gen_check_align(DisasContext
*ctx
, TCGv EA
, int mask
)
2480 int l1
= gen_new_label();
2481 TCGv t0
= tcg_temp_new();
2483 /* NIP cannot be restored if the memory exception comes from an helper */
2484 gen_update_nip(ctx
, ctx
->nip
- 4);
2485 tcg_gen_andi_tl(t0
, EA
, mask
);
2486 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2487 t1
= tcg_const_i32(POWERPC_EXCP_ALIGN
);
2488 t2
= tcg_const_i32(0);
2489 gen_helper_raise_exception_err(cpu_env
, t1
, t2
);
2490 tcg_temp_free_i32(t1
);
2491 tcg_temp_free_i32(t2
);
2496 /*** Integer load ***/
2497 static inline void gen_qemu_ld8u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2499 tcg_gen_qemu_ld8u(arg1
, arg2
, ctx
->mem_idx
);
2502 static inline void gen_qemu_ld8s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2504 tcg_gen_qemu_ld8s(arg1
, arg2
, ctx
->mem_idx
);
2507 static inline void gen_qemu_ld16u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2509 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2510 if (unlikely(ctx
->le_mode
)) {
2511 tcg_gen_bswap16_tl(arg1
, arg1
);
2515 static inline void gen_qemu_ld16s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2517 if (unlikely(ctx
->le_mode
)) {
2518 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2519 tcg_gen_bswap16_tl(arg1
, arg1
);
2520 tcg_gen_ext16s_tl(arg1
, arg1
);
2522 tcg_gen_qemu_ld16s(arg1
, arg2
, ctx
->mem_idx
);
2526 static inline void gen_qemu_ld32u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2528 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2529 if (unlikely(ctx
->le_mode
)) {
2530 tcg_gen_bswap32_tl(arg1
, arg1
);
2534 #if defined(TARGET_PPC64)
2535 static inline void gen_qemu_ld32s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2537 if (unlikely(ctx
->le_mode
)) {
2538 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2539 tcg_gen_bswap32_tl(arg1
, arg1
);
2540 tcg_gen_ext32s_tl(arg1
, arg1
);
2542 tcg_gen_qemu_ld32s(arg1
, arg2
, ctx
->mem_idx
);
2546 static inline void gen_qemu_ld64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2548 tcg_gen_qemu_ld64(arg1
, arg2
, ctx
->mem_idx
);
2549 if (unlikely(ctx
->le_mode
)) {
2550 tcg_gen_bswap64_i64(arg1
, arg1
);
2554 static inline void gen_qemu_st8(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2556 tcg_gen_qemu_st8(arg1
, arg2
, ctx
->mem_idx
);
2559 static inline void gen_qemu_st16(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2561 if (unlikely(ctx
->le_mode
)) {
2562 TCGv t0
= tcg_temp_new();
2563 tcg_gen_ext16u_tl(t0
, arg1
);
2564 tcg_gen_bswap16_tl(t0
, t0
);
2565 tcg_gen_qemu_st16(t0
, arg2
, ctx
->mem_idx
);
2568 tcg_gen_qemu_st16(arg1
, arg2
, ctx
->mem_idx
);
2572 static inline void gen_qemu_st32(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2574 if (unlikely(ctx
->le_mode
)) {
2575 TCGv t0
= tcg_temp_new();
2576 tcg_gen_ext32u_tl(t0
, arg1
);
2577 tcg_gen_bswap32_tl(t0
, t0
);
2578 tcg_gen_qemu_st32(t0
, arg2
, ctx
->mem_idx
);
2581 tcg_gen_qemu_st32(arg1
, arg2
, ctx
->mem_idx
);
2585 static inline void gen_qemu_st64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2587 if (unlikely(ctx
->le_mode
)) {
2588 TCGv_i64 t0
= tcg_temp_new_i64();
2589 tcg_gen_bswap64_i64(t0
, arg1
);
2590 tcg_gen_qemu_st64(t0
, arg2
, ctx
->mem_idx
);
2591 tcg_temp_free_i64(t0
);
2593 tcg_gen_qemu_st64(arg1
, arg2
, ctx
->mem_idx
);
2596 #define GEN_LD(name, ldop, opc, type) \
2597 static void glue(gen_, name)(DisasContext *ctx) \
2600 gen_set_access_type(ctx, ACCESS_INT); \
2601 EA = tcg_temp_new(); \
2602 gen_addr_imm_index(ctx, EA, 0); \
2603 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2604 tcg_temp_free(EA); \
2607 #define GEN_LDU(name, ldop, opc, type) \
2608 static void glue(gen_, name##u)(DisasContext *ctx) \
2611 if (unlikely(rA(ctx->opcode) == 0 || \
2612 rA(ctx->opcode) == rD(ctx->opcode))) { \
2613 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2616 gen_set_access_type(ctx, ACCESS_INT); \
2617 EA = tcg_temp_new(); \
2618 if (type == PPC_64B) \
2619 gen_addr_imm_index(ctx, EA, 0x03); \
2621 gen_addr_imm_index(ctx, EA, 0); \
2622 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2623 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2624 tcg_temp_free(EA); \
2627 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
2628 static void glue(gen_, name##ux)(DisasContext *ctx) \
2631 if (unlikely(rA(ctx->opcode) == 0 || \
2632 rA(ctx->opcode) == rD(ctx->opcode))) { \
2633 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2636 gen_set_access_type(ctx, ACCESS_INT); \
2637 EA = tcg_temp_new(); \
2638 gen_addr_reg_index(ctx, EA); \
2639 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2640 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2641 tcg_temp_free(EA); \
2644 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
2645 static void glue(gen_, name##x)(DisasContext *ctx) \
2648 gen_set_access_type(ctx, ACCESS_INT); \
2649 EA = tcg_temp_new(); \
2650 gen_addr_reg_index(ctx, EA); \
2651 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2652 tcg_temp_free(EA); \
2654 #define GEN_LDX(name, ldop, opc2, opc3, type) \
2655 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE)
2657 #define GEN_LDS(name, ldop, op, type) \
2658 GEN_LD(name, ldop, op | 0x20, type); \
2659 GEN_LDU(name, ldop, op | 0x21, type); \
2660 GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2661 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
2663 /* lbz lbzu lbzux lbzx */
2664 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
);
2665 /* lha lhau lhaux lhax */
2666 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
);
2667 /* lhz lhzu lhzux lhzx */
2668 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
);
2669 /* lwz lwzu lwzux lwzx */
2670 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
);
2671 #if defined(TARGET_PPC64)
2673 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
);
2675 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
);
2677 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
);
2679 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
);
2681 static void gen_ld(DisasContext
*ctx
)
2684 if (Rc(ctx
->opcode
)) {
2685 if (unlikely(rA(ctx
->opcode
) == 0 ||
2686 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
2687 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2691 gen_set_access_type(ctx
, ACCESS_INT
);
2692 EA
= tcg_temp_new();
2693 gen_addr_imm_index(ctx
, EA
, 0x03);
2694 if (ctx
->opcode
& 0x02) {
2695 /* lwa (lwau is undefined) */
2696 gen_qemu_ld32s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2699 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2701 if (Rc(ctx
->opcode
))
2702 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2707 static void gen_lq(DisasContext
*ctx
)
2709 #if defined(CONFIG_USER_ONLY)
2710 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2715 /* Restore CPU state */
2716 if (unlikely(ctx
->mem_idx
== 0)) {
2717 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2720 ra
= rA(ctx
->opcode
);
2721 rd
= rD(ctx
->opcode
);
2722 if (unlikely((rd
& 1) || rd
== ra
)) {
2723 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2726 if (unlikely(ctx
->le_mode
)) {
2727 /* Little-endian mode is not handled */
2728 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2731 gen_set_access_type(ctx
, ACCESS_INT
);
2732 EA
= tcg_temp_new();
2733 gen_addr_imm_index(ctx
, EA
, 0x0F);
2734 gen_qemu_ld64(ctx
, cpu_gpr
[rd
], EA
);
2735 gen_addr_add(ctx
, EA
, EA
, 8);
2736 gen_qemu_ld64(ctx
, cpu_gpr
[rd
+1], EA
);
2742 /*** Integer store ***/
2743 #define GEN_ST(name, stop, opc, type) \
2744 static void glue(gen_, name)(DisasContext *ctx) \
2747 gen_set_access_type(ctx, ACCESS_INT); \
2748 EA = tcg_temp_new(); \
2749 gen_addr_imm_index(ctx, EA, 0); \
2750 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2751 tcg_temp_free(EA); \
2754 #define GEN_STU(name, stop, opc, type) \
2755 static void glue(gen_, stop##u)(DisasContext *ctx) \
2758 if (unlikely(rA(ctx->opcode) == 0)) { \
2759 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2762 gen_set_access_type(ctx, ACCESS_INT); \
2763 EA = tcg_temp_new(); \
2764 if (type == PPC_64B) \
2765 gen_addr_imm_index(ctx, EA, 0x03); \
2767 gen_addr_imm_index(ctx, EA, 0); \
2768 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2769 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2770 tcg_temp_free(EA); \
2773 #define GEN_STUX(name, stop, opc2, opc3, type) \
2774 static void glue(gen_, name##ux)(DisasContext *ctx) \
2777 if (unlikely(rA(ctx->opcode) == 0)) { \
2778 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2781 gen_set_access_type(ctx, ACCESS_INT); \
2782 EA = tcg_temp_new(); \
2783 gen_addr_reg_index(ctx, EA); \
2784 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2785 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2786 tcg_temp_free(EA); \
2789 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
2790 static void glue(gen_, name##x)(DisasContext *ctx) \
2793 gen_set_access_type(ctx, ACCESS_INT); \
2794 EA = tcg_temp_new(); \
2795 gen_addr_reg_index(ctx, EA); \
2796 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2797 tcg_temp_free(EA); \
2799 #define GEN_STX(name, stop, opc2, opc3, type) \
2800 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE)
2802 #define GEN_STS(name, stop, op, type) \
2803 GEN_ST(name, stop, op | 0x20, type); \
2804 GEN_STU(name, stop, op | 0x21, type); \
2805 GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2806 GEN_STX(name, stop, 0x17, op | 0x00, type)
2808 /* stb stbu stbux stbx */
2809 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
);
2810 /* sth sthu sthux sthx */
2811 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
);
2812 /* stw stwu stwux stwx */
2813 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
);
2814 #if defined(TARGET_PPC64)
2815 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
);
2816 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
);
2818 static void gen_std(DisasContext
*ctx
)
2823 rs
= rS(ctx
->opcode
);
2824 if ((ctx
->opcode
& 0x3) == 0x2) {
2825 #if defined(CONFIG_USER_ONLY)
2826 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2829 if (unlikely(ctx
->mem_idx
== 0)) {
2830 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2833 if (unlikely(rs
& 1)) {
2834 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2837 if (unlikely(ctx
->le_mode
)) {
2838 /* Little-endian mode is not handled */
2839 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2842 gen_set_access_type(ctx
, ACCESS_INT
);
2843 EA
= tcg_temp_new();
2844 gen_addr_imm_index(ctx
, EA
, 0x03);
2845 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
2846 gen_addr_add(ctx
, EA
, EA
, 8);
2847 gen_qemu_st64(ctx
, cpu_gpr
[rs
+1], EA
);
2852 if (Rc(ctx
->opcode
)) {
2853 if (unlikely(rA(ctx
->opcode
) == 0)) {
2854 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2858 gen_set_access_type(ctx
, ACCESS_INT
);
2859 EA
= tcg_temp_new();
2860 gen_addr_imm_index(ctx
, EA
, 0x03);
2861 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
2862 if (Rc(ctx
->opcode
))
2863 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2868 /*** Integer load and store with byte reverse ***/
2870 static inline void gen_qemu_ld16ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2872 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2873 if (likely(!ctx
->le_mode
)) {
2874 tcg_gen_bswap16_tl(arg1
, arg1
);
2877 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
);
2880 static inline void gen_qemu_ld32ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2882 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2883 if (likely(!ctx
->le_mode
)) {
2884 tcg_gen_bswap32_tl(arg1
, arg1
);
2887 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
);
2889 #if defined(TARGET_PPC64)
2891 static inline void gen_qemu_ld64ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2893 tcg_gen_qemu_ld64(arg1
, arg2
, ctx
->mem_idx
);
2894 if (likely(!ctx
->le_mode
)) {
2895 tcg_gen_bswap64_tl(arg1
, arg1
);
2898 GEN_LDX_E(ldbr
, ld64ur
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
);
2899 #endif /* TARGET_PPC64 */
2902 static inline void gen_qemu_st16r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2904 if (likely(!ctx
->le_mode
)) {
2905 TCGv t0
= tcg_temp_new();
2906 tcg_gen_ext16u_tl(t0
, arg1
);
2907 tcg_gen_bswap16_tl(t0
, t0
);
2908 tcg_gen_qemu_st16(t0
, arg2
, ctx
->mem_idx
);
2911 tcg_gen_qemu_st16(arg1
, arg2
, ctx
->mem_idx
);
2914 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
);
2917 static inline void gen_qemu_st32r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2919 if (likely(!ctx
->le_mode
)) {
2920 TCGv t0
= tcg_temp_new();
2921 tcg_gen_ext32u_tl(t0
, arg1
);
2922 tcg_gen_bswap32_tl(t0
, t0
);
2923 tcg_gen_qemu_st32(t0
, arg2
, ctx
->mem_idx
);
2926 tcg_gen_qemu_st32(arg1
, arg2
, ctx
->mem_idx
);
2929 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
);
2931 #if defined(TARGET_PPC64)
2933 static inline void gen_qemu_st64r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2935 if (likely(!ctx
->le_mode
)) {
2936 TCGv t0
= tcg_temp_new();
2937 tcg_gen_bswap64_tl(t0
, arg1
);
2938 tcg_gen_qemu_st64(t0
, arg2
, ctx
->mem_idx
);
2941 tcg_gen_qemu_st64(arg1
, arg2
, ctx
->mem_idx
);
2944 GEN_STX_E(stdbr
, st64r
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
);
2945 #endif /* TARGET_PPC64 */
2947 /*** Integer load and store multiple ***/
2950 static void gen_lmw(DisasContext
*ctx
)
2954 gen_set_access_type(ctx
, ACCESS_INT
);
2955 /* NIP cannot be restored if the memory exception comes from an helper */
2956 gen_update_nip(ctx
, ctx
->nip
- 4);
2957 t0
= tcg_temp_new();
2958 t1
= tcg_const_i32(rD(ctx
->opcode
));
2959 gen_addr_imm_index(ctx
, t0
, 0);
2960 gen_helper_lmw(cpu_env
, t0
, t1
);
2962 tcg_temp_free_i32(t1
);
2966 static void gen_stmw(DisasContext
*ctx
)
2970 gen_set_access_type(ctx
, ACCESS_INT
);
2971 /* NIP cannot be restored if the memory exception comes from an helper */
2972 gen_update_nip(ctx
, ctx
->nip
- 4);
2973 t0
= tcg_temp_new();
2974 t1
= tcg_const_i32(rS(ctx
->opcode
));
2975 gen_addr_imm_index(ctx
, t0
, 0);
2976 gen_helper_stmw(cpu_env
, t0
, t1
);
2978 tcg_temp_free_i32(t1
);
2981 /*** Integer load and store strings ***/
2984 /* PowerPC32 specification says we must generate an exception if
2985 * rA is in the range of registers to be loaded.
2986 * In an other hand, IBM says this is valid, but rA won't be loaded.
2987 * For now, I'll follow the spec...
2989 static void gen_lswi(DisasContext
*ctx
)
2993 int nb
= NB(ctx
->opcode
);
2994 int start
= rD(ctx
->opcode
);
2995 int ra
= rA(ctx
->opcode
);
3001 if (unlikely(((start
+ nr
) > 32 &&
3002 start
<= ra
&& (start
+ nr
- 32) > ra
) ||
3003 ((start
+ nr
) <= 32 && start
<= ra
&& (start
+ nr
) > ra
))) {
3004 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
3007 gen_set_access_type(ctx
, ACCESS_INT
);
3008 /* NIP cannot be restored if the memory exception comes from an helper */
3009 gen_update_nip(ctx
, ctx
->nip
- 4);
3010 t0
= tcg_temp_new();
3011 gen_addr_register(ctx
, t0
);
3012 t1
= tcg_const_i32(nb
);
3013 t2
= tcg_const_i32(start
);
3014 gen_helper_lsw(cpu_env
, t0
, t1
, t2
);
3016 tcg_temp_free_i32(t1
);
3017 tcg_temp_free_i32(t2
);
3021 static void gen_lswx(DisasContext
*ctx
)
3024 TCGv_i32 t1
, t2
, t3
;
3025 gen_set_access_type(ctx
, ACCESS_INT
);
3026 /* NIP cannot be restored if the memory exception comes from an helper */
3027 gen_update_nip(ctx
, ctx
->nip
- 4);
3028 t0
= tcg_temp_new();
3029 gen_addr_reg_index(ctx
, t0
);
3030 t1
= tcg_const_i32(rD(ctx
->opcode
));
3031 t2
= tcg_const_i32(rA(ctx
->opcode
));
3032 t3
= tcg_const_i32(rB(ctx
->opcode
));
3033 gen_helper_lswx(cpu_env
, t0
, t1
, t2
, t3
);
3035 tcg_temp_free_i32(t1
);
3036 tcg_temp_free_i32(t2
);
3037 tcg_temp_free_i32(t3
);
3041 static void gen_stswi(DisasContext
*ctx
)
3045 int nb
= NB(ctx
->opcode
);
3046 gen_set_access_type(ctx
, ACCESS_INT
);
3047 /* NIP cannot be restored if the memory exception comes from an helper */
3048 gen_update_nip(ctx
, ctx
->nip
- 4);
3049 t0
= tcg_temp_new();
3050 gen_addr_register(ctx
, t0
);
3053 t1
= tcg_const_i32(nb
);
3054 t2
= tcg_const_i32(rS(ctx
->opcode
));
3055 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3057 tcg_temp_free_i32(t1
);
3058 tcg_temp_free_i32(t2
);
3062 static void gen_stswx(DisasContext
*ctx
)
3066 gen_set_access_type(ctx
, ACCESS_INT
);
3067 /* NIP cannot be restored if the memory exception comes from an helper */
3068 gen_update_nip(ctx
, ctx
->nip
- 4);
3069 t0
= tcg_temp_new();
3070 gen_addr_reg_index(ctx
, t0
);
3071 t1
= tcg_temp_new_i32();
3072 tcg_gen_trunc_tl_i32(t1
, cpu_xer
);
3073 tcg_gen_andi_i32(t1
, t1
, 0x7F);
3074 t2
= tcg_const_i32(rS(ctx
->opcode
));
3075 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3077 tcg_temp_free_i32(t1
);
3078 tcg_temp_free_i32(t2
);
3081 /*** Memory synchronisation ***/
3083 static void gen_eieio(DisasContext
*ctx
)
3088 static void gen_isync(DisasContext
*ctx
)
3090 gen_stop_exception(ctx
);
3094 static void gen_lwarx(DisasContext
*ctx
)
3097 TCGv gpr
= cpu_gpr
[rD(ctx
->opcode
)];
3098 gen_set_access_type(ctx
, ACCESS_RES
);
3099 t0
= tcg_temp_local_new();
3100 gen_addr_reg_index(ctx
, t0
);
3101 gen_check_align(ctx
, t0
, 0x03);
3102 gen_qemu_ld32u(ctx
, gpr
, t0
);
3103 tcg_gen_mov_tl(cpu_reserve
, t0
);
3104 tcg_gen_st_tl(gpr
, cpu_env
, offsetof(CPUPPCState
, reserve_val
));
3108 #if defined(CONFIG_USER_ONLY)
3109 static void gen_conditional_store (DisasContext
*ctx
, TCGv EA
,
3112 TCGv t0
= tcg_temp_new();
3113 uint32_t save_exception
= ctx
->exception
;
3115 tcg_gen_st_tl(EA
, cpu_env
, offsetof(CPUPPCState
, reserve_ea
));
3116 tcg_gen_movi_tl(t0
, (size
<< 5) | reg
);
3117 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, reserve_info
));
3119 gen_update_nip(ctx
, ctx
->nip
-4);
3120 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3121 gen_exception(ctx
, POWERPC_EXCP_STCX
);
3122 ctx
->exception
= save_exception
;
3127 static void gen_stwcx_(DisasContext
*ctx
)
3130 gen_set_access_type(ctx
, ACCESS_RES
);
3131 t0
= tcg_temp_local_new();
3132 gen_addr_reg_index(ctx
, t0
);
3133 gen_check_align(ctx
, t0
, 0x03);
3134 #if defined(CONFIG_USER_ONLY)
3135 gen_conditional_store(ctx
, t0
, rS(ctx
->opcode
), 4);
3140 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
3141 l1
= gen_new_label();
3142 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
3143 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3144 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3146 tcg_gen_movi_tl(cpu_reserve
, -1);
3152 #if defined(TARGET_PPC64)
3154 static void gen_ldarx(DisasContext
*ctx
)
3157 TCGv gpr
= cpu_gpr
[rD(ctx
->opcode
)];
3158 gen_set_access_type(ctx
, ACCESS_RES
);
3159 t0
= tcg_temp_local_new();
3160 gen_addr_reg_index(ctx
, t0
);
3161 gen_check_align(ctx
, t0
, 0x07);
3162 gen_qemu_ld64(ctx
, gpr
, t0
);
3163 tcg_gen_mov_tl(cpu_reserve
, t0
);
3164 tcg_gen_st_tl(gpr
, cpu_env
, offsetof(CPUPPCState
, reserve_val
));
3169 static void gen_stdcx_(DisasContext
*ctx
)
3172 gen_set_access_type(ctx
, ACCESS_RES
);
3173 t0
= tcg_temp_local_new();
3174 gen_addr_reg_index(ctx
, t0
);
3175 gen_check_align(ctx
, t0
, 0x07);
3176 #if defined(CONFIG_USER_ONLY)
3177 gen_conditional_store(ctx
, t0
, rS(ctx
->opcode
), 8);
3181 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
3182 l1
= gen_new_label();
3183 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
3184 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3185 gen_qemu_st64(ctx
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3187 tcg_gen_movi_tl(cpu_reserve
, -1);
3192 #endif /* defined(TARGET_PPC64) */
3195 static void gen_sync(DisasContext
*ctx
)
3200 static void gen_wait(DisasContext
*ctx
)
3202 TCGv_i32 t0
= tcg_temp_new_i32();
3203 tcg_gen_st_i32(t0
, cpu_env
,
3204 -offsetof(PowerPCCPU
, env
) + offsetof(CPUState
, halted
));
3205 tcg_temp_free_i32(t0
);
3206 /* Stop translation, as the CPU is supposed to sleep from now */
3207 gen_exception_err(ctx
, EXCP_HLT
, 1);
3210 /*** Floating-point load ***/
3211 #define GEN_LDF(name, ldop, opc, type) \
3212 static void glue(gen_, name)(DisasContext *ctx) \
3215 if (unlikely(!ctx->fpu_enabled)) { \
3216 gen_exception(ctx, POWERPC_EXCP_FPU); \
3219 gen_set_access_type(ctx, ACCESS_FLOAT); \
3220 EA = tcg_temp_new(); \
3221 gen_addr_imm_index(ctx, EA, 0); \
3222 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3223 tcg_temp_free(EA); \
3226 #define GEN_LDUF(name, ldop, opc, type) \
3227 static void glue(gen_, name##u)(DisasContext *ctx) \
3230 if (unlikely(!ctx->fpu_enabled)) { \
3231 gen_exception(ctx, POWERPC_EXCP_FPU); \
3234 if (unlikely(rA(ctx->opcode) == 0)) { \
3235 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3238 gen_set_access_type(ctx, ACCESS_FLOAT); \
3239 EA = tcg_temp_new(); \
3240 gen_addr_imm_index(ctx, EA, 0); \
3241 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3242 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3243 tcg_temp_free(EA); \
3246 #define GEN_LDUXF(name, ldop, opc, type) \
3247 static void glue(gen_, name##ux)(DisasContext *ctx) \
3250 if (unlikely(!ctx->fpu_enabled)) { \
3251 gen_exception(ctx, POWERPC_EXCP_FPU); \
3254 if (unlikely(rA(ctx->opcode) == 0)) { \
3255 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3258 gen_set_access_type(ctx, ACCESS_FLOAT); \
3259 EA = tcg_temp_new(); \
3260 gen_addr_reg_index(ctx, EA); \
3261 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3262 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3263 tcg_temp_free(EA); \
3266 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
3267 static void glue(gen_, name##x)(DisasContext *ctx) \
3270 if (unlikely(!ctx->fpu_enabled)) { \
3271 gen_exception(ctx, POWERPC_EXCP_FPU); \
3274 gen_set_access_type(ctx, ACCESS_FLOAT); \
3275 EA = tcg_temp_new(); \
3276 gen_addr_reg_index(ctx, EA); \
3277 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3278 tcg_temp_free(EA); \
3281 #define GEN_LDFS(name, ldop, op, type) \
3282 GEN_LDF(name, ldop, op | 0x20, type); \
3283 GEN_LDUF(name, ldop, op | 0x21, type); \
3284 GEN_LDUXF(name, ldop, op | 0x01, type); \
3285 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3287 static inline void gen_qemu_ld32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3289 TCGv t0
= tcg_temp_new();
3290 TCGv_i32 t1
= tcg_temp_new_i32();
3291 gen_qemu_ld32u(ctx
, t0
, arg2
);
3292 tcg_gen_trunc_tl_i32(t1
, t0
);
3294 gen_helper_float32_to_float64(arg1
, cpu_env
, t1
);
3295 tcg_temp_free_i32(t1
);
3298 /* lfd lfdu lfdux lfdx */
3299 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
);
3300 /* lfs lfsu lfsux lfsx */
3301 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
);
3304 static void gen_lfdp(DisasContext
*ctx
)
3307 if (unlikely(!ctx
->fpu_enabled
)) {
3308 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3311 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3312 EA
= tcg_temp_new();
3313 gen_addr_imm_index(ctx
, EA
, 0); \
3314 if (unlikely(ctx
->le_mode
)) {
3315 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3316 tcg_gen_addi_tl(EA
, EA
, 8);
3317 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3319 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3320 tcg_gen_addi_tl(EA
, EA
, 8);
3321 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3327 static void gen_lfdpx(DisasContext
*ctx
)
3330 if (unlikely(!ctx
->fpu_enabled
)) {
3331 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3334 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3335 EA
= tcg_temp_new();
3336 gen_addr_reg_index(ctx
, EA
);
3337 if (unlikely(ctx
->le_mode
)) {
3338 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3339 tcg_gen_addi_tl(EA
, EA
, 8);
3340 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3342 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3343 tcg_gen_addi_tl(EA
, EA
, 8);
3344 gen_qemu_ld64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3350 static void gen_lfiwax(DisasContext
*ctx
)
3354 if (unlikely(!ctx
->fpu_enabled
)) {
3355 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3358 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3359 EA
= tcg_temp_new();
3360 t0
= tcg_temp_new();
3361 gen_addr_reg_index(ctx
, EA
);
3362 gen_qemu_ld32u(ctx
, t0
, EA
);
3363 tcg_gen_ext_tl_i64(cpu_fpr
[rD(ctx
->opcode
)], t0
);
3364 tcg_gen_ext32s_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rD(ctx
->opcode
)]);
3369 /*** Floating-point store ***/
3370 #define GEN_STF(name, stop, opc, type) \
3371 static void glue(gen_, name)(DisasContext *ctx) \
3374 if (unlikely(!ctx->fpu_enabled)) { \
3375 gen_exception(ctx, POWERPC_EXCP_FPU); \
3378 gen_set_access_type(ctx, ACCESS_FLOAT); \
3379 EA = tcg_temp_new(); \
3380 gen_addr_imm_index(ctx, EA, 0); \
3381 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3382 tcg_temp_free(EA); \
3385 #define GEN_STUF(name, stop, opc, type) \
3386 static void glue(gen_, name##u)(DisasContext *ctx) \
3389 if (unlikely(!ctx->fpu_enabled)) { \
3390 gen_exception(ctx, POWERPC_EXCP_FPU); \
3393 if (unlikely(rA(ctx->opcode) == 0)) { \
3394 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3397 gen_set_access_type(ctx, ACCESS_FLOAT); \
3398 EA = tcg_temp_new(); \
3399 gen_addr_imm_index(ctx, EA, 0); \
3400 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3401 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3402 tcg_temp_free(EA); \
3405 #define GEN_STUXF(name, stop, opc, type) \
3406 static void glue(gen_, name##ux)(DisasContext *ctx) \
3409 if (unlikely(!ctx->fpu_enabled)) { \
3410 gen_exception(ctx, POWERPC_EXCP_FPU); \
3413 if (unlikely(rA(ctx->opcode) == 0)) { \
3414 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3417 gen_set_access_type(ctx, ACCESS_FLOAT); \
3418 EA = tcg_temp_new(); \
3419 gen_addr_reg_index(ctx, EA); \
3420 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3421 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3422 tcg_temp_free(EA); \
3425 #define GEN_STXF(name, stop, opc2, opc3, type) \
3426 static void glue(gen_, name##x)(DisasContext *ctx) \
3429 if (unlikely(!ctx->fpu_enabled)) { \
3430 gen_exception(ctx, POWERPC_EXCP_FPU); \
3433 gen_set_access_type(ctx, ACCESS_FLOAT); \
3434 EA = tcg_temp_new(); \
3435 gen_addr_reg_index(ctx, EA); \
3436 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3437 tcg_temp_free(EA); \
3440 #define GEN_STFS(name, stop, op, type) \
3441 GEN_STF(name, stop, op | 0x20, type); \
3442 GEN_STUF(name, stop, op | 0x21, type); \
3443 GEN_STUXF(name, stop, op | 0x01, type); \
3444 GEN_STXF(name, stop, 0x17, op | 0x00, type)
3446 static inline void gen_qemu_st32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3448 TCGv_i32 t0
= tcg_temp_new_i32();
3449 TCGv t1
= tcg_temp_new();
3450 gen_helper_float64_to_float32(t0
, cpu_env
, arg1
);
3451 tcg_gen_extu_i32_tl(t1
, t0
);
3452 tcg_temp_free_i32(t0
);
3453 gen_qemu_st32(ctx
, t1
, arg2
);
3457 /* stfd stfdu stfdux stfdx */
3458 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
);
3459 /* stfs stfsu stfsux stfsx */
3460 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
);
3463 static void gen_stfdp(DisasContext
*ctx
)
3466 if (unlikely(!ctx
->fpu_enabled
)) {
3467 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3470 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3471 EA
= tcg_temp_new();
3472 gen_addr_imm_index(ctx
, EA
, 0); \
3473 if (unlikely(ctx
->le_mode
)) {
3474 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3475 tcg_gen_addi_tl(EA
, EA
, 8);
3476 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3478 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3479 tcg_gen_addi_tl(EA
, EA
, 8);
3480 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3486 static void gen_stfdpx(DisasContext
*ctx
)
3489 if (unlikely(!ctx
->fpu_enabled
)) {
3490 gen_exception(ctx
, POWERPC_EXCP_FPU
);
3493 gen_set_access_type(ctx
, ACCESS_FLOAT
);
3494 EA
= tcg_temp_new();
3495 gen_addr_reg_index(ctx
, EA
);
3496 if (unlikely(ctx
->le_mode
)) {
3497 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3498 tcg_gen_addi_tl(EA
, EA
, 8);
3499 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3501 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
)], EA
);
3502 tcg_gen_addi_tl(EA
, EA
, 8);
3503 gen_qemu_st64(ctx
, cpu_fpr
[rD(ctx
->opcode
) + 1], EA
);
3509 static inline void gen_qemu_st32fiw(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3511 TCGv t0
= tcg_temp_new();
3512 tcg_gen_trunc_i64_tl(t0
, arg1
),
3513 gen_qemu_st32(ctx
, t0
, arg2
);
3517 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
);
3519 static inline void gen_update_cfar(DisasContext
*ctx
, target_ulong nip
)
3521 #if defined(TARGET_PPC64)
3523 tcg_gen_movi_tl(cpu_cfar
, nip
);
3528 static inline void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
3530 TranslationBlock
*tb
;
3532 if (NARROW_MODE(ctx
)) {
3533 dest
= (uint32_t) dest
;
3535 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
3536 likely(!ctx
->singlestep_enabled
)) {
3538 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3539 tcg_gen_exit_tb((tcg_target_long
)tb
+ n
);
3541 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3542 if (unlikely(ctx
->singlestep_enabled
)) {
3543 if ((ctx
->singlestep_enabled
&
3544 (CPU_BRANCH_STEP
| CPU_SINGLE_STEP
)) &&
3545 (ctx
->exception
== POWERPC_EXCP_BRANCH
||
3546 ctx
->exception
== POWERPC_EXCP_TRACE
)) {
3547 target_ulong tmp
= ctx
->nip
;
3549 gen_exception(ctx
, POWERPC_EXCP_TRACE
);
3552 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
3553 gen_debug_exception(ctx
);
3560 static inline void gen_setlr(DisasContext
*ctx
, target_ulong nip
)
3562 if (NARROW_MODE(ctx
)) {
3563 nip
= (uint32_t)nip
;
3565 tcg_gen_movi_tl(cpu_lr
, nip
);
3569 static void gen_b(DisasContext
*ctx
)
3571 target_ulong li
, target
;
3573 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3574 /* sign extend LI */
3575 li
= LI(ctx
->opcode
);
3576 li
= (li
^ 0x02000000) - 0x02000000;
3577 if (likely(AA(ctx
->opcode
) == 0)) {
3578 target
= ctx
->nip
+ li
- 4;
3582 if (LK(ctx
->opcode
)) {
3583 gen_setlr(ctx
, ctx
->nip
);
3585 gen_update_cfar(ctx
, ctx
->nip
);
3586 gen_goto_tb(ctx
, 0, target
);
3593 static inline void gen_bcond(DisasContext
*ctx
, int type
)
3595 uint32_t bo
= BO(ctx
->opcode
);
3599 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3600 if (type
== BCOND_LR
|| type
== BCOND_CTR
) {
3601 target
= tcg_temp_local_new();
3602 if (type
== BCOND_CTR
)
3603 tcg_gen_mov_tl(target
, cpu_ctr
);
3605 tcg_gen_mov_tl(target
, cpu_lr
);
3607 TCGV_UNUSED(target
);
3609 if (LK(ctx
->opcode
))
3610 gen_setlr(ctx
, ctx
->nip
);
3611 l1
= gen_new_label();
3612 if ((bo
& 0x4) == 0) {
3613 /* Decrement and test CTR */
3614 TCGv temp
= tcg_temp_new();
3615 if (unlikely(type
== BCOND_CTR
)) {
3616 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3619 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
3620 if (NARROW_MODE(ctx
)) {
3621 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
3623 tcg_gen_mov_tl(temp
, cpu_ctr
);
3626 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
3628 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
3630 tcg_temp_free(temp
);
3632 if ((bo
& 0x10) == 0) {
3634 uint32_t bi
= BI(ctx
->opcode
);
3635 uint32_t mask
= 1 << (3 - (bi
& 0x03));
3636 TCGv_i32 temp
= tcg_temp_new_i32();
3639 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3640 tcg_gen_brcondi_i32(TCG_COND_EQ
, temp
, 0, l1
);
3642 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3643 tcg_gen_brcondi_i32(TCG_COND_NE
, temp
, 0, l1
);
3645 tcg_temp_free_i32(temp
);
3647 gen_update_cfar(ctx
, ctx
->nip
);
3648 if (type
== BCOND_IM
) {
3649 target_ulong li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
3650 if (likely(AA(ctx
->opcode
) == 0)) {
3651 gen_goto_tb(ctx
, 0, ctx
->nip
+ li
- 4);
3653 gen_goto_tb(ctx
, 0, li
);
3656 gen_goto_tb(ctx
, 1, ctx
->nip
);
3658 if (NARROW_MODE(ctx
)) {
3659 tcg_gen_andi_tl(cpu_nip
, target
, (uint32_t)~3);
3661 tcg_gen_andi_tl(cpu_nip
, target
, ~3);
3665 gen_update_nip(ctx
, ctx
->nip
);
3670 static void gen_bc(DisasContext
*ctx
)
3672 gen_bcond(ctx
, BCOND_IM
);
3675 static void gen_bcctr(DisasContext
*ctx
)
3677 gen_bcond(ctx
, BCOND_CTR
);
3680 static void gen_bclr(DisasContext
*ctx
)
3682 gen_bcond(ctx
, BCOND_LR
);
3685 /*** Condition register logical ***/
3686 #define GEN_CRLOGIC(name, tcg_op, opc) \
3687 static void glue(gen_, name)(DisasContext *ctx) \
3692 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3693 t0 = tcg_temp_new_i32(); \
3695 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
3697 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
3699 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
3700 t1 = tcg_temp_new_i32(); \
3701 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3703 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
3705 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
3707 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3708 tcg_op(t0, t0, t1); \
3709 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
3710 tcg_gen_andi_i32(t0, t0, bitmask); \
3711 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3712 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
3713 tcg_temp_free_i32(t0); \
3714 tcg_temp_free_i32(t1); \
3718 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08);
3720 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04);
3722 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09);
3724 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07);
3726 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01);
3728 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E);
3730 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D);
3732 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06);
3735 static void gen_mcrf(DisasContext
*ctx
)
3737 tcg_gen_mov_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfS(ctx
->opcode
)]);
3740 /*** System linkage ***/
3742 /* rfi (mem_idx only) */
3743 static void gen_rfi(DisasContext
*ctx
)
3745 #if defined(CONFIG_USER_ONLY)
3746 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3748 /* Restore CPU state */
3749 if (unlikely(!ctx
->mem_idx
)) {
3750 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3753 gen_update_cfar(ctx
, ctx
->nip
);
3754 gen_helper_rfi(cpu_env
);
3755 gen_sync_exception(ctx
);
3759 #if defined(TARGET_PPC64)
3760 static void gen_rfid(DisasContext
*ctx
)
3762 #if defined(CONFIG_USER_ONLY)
3763 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3765 /* Restore CPU state */
3766 if (unlikely(!ctx
->mem_idx
)) {
3767 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3770 gen_update_cfar(ctx
, ctx
->nip
);
3771 gen_helper_rfid(cpu_env
);
3772 gen_sync_exception(ctx
);
3776 static void gen_hrfid(DisasContext
*ctx
)
3778 #if defined(CONFIG_USER_ONLY)
3779 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3781 /* Restore CPU state */
3782 if (unlikely(ctx
->mem_idx
<= 1)) {
3783 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3786 gen_helper_hrfid(cpu_env
);
3787 gen_sync_exception(ctx
);
3793 #if defined(CONFIG_USER_ONLY)
3794 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3796 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3798 static void gen_sc(DisasContext
*ctx
)
3802 lev
= (ctx
->opcode
>> 5) & 0x7F;
3803 gen_exception_err(ctx
, POWERPC_SYSCALL
, lev
);
3809 static void gen_tw(DisasContext
*ctx
)
3811 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3812 /* Update the nip since this might generate a trap exception */
3813 gen_update_nip(ctx
, ctx
->nip
);
3814 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
3816 tcg_temp_free_i32(t0
);
3820 static void gen_twi(DisasContext
*ctx
)
3822 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3823 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
3824 /* Update the nip since this might generate a trap exception */
3825 gen_update_nip(ctx
, ctx
->nip
);
3826 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3828 tcg_temp_free_i32(t1
);
3831 #if defined(TARGET_PPC64)
3833 static void gen_td(DisasContext
*ctx
)
3835 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3836 /* Update the nip since this might generate a trap exception */
3837 gen_update_nip(ctx
, ctx
->nip
);
3838 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
3840 tcg_temp_free_i32(t0
);
3844 static void gen_tdi(DisasContext
*ctx
)
3846 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3847 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
3848 /* Update the nip since this might generate a trap exception */
3849 gen_update_nip(ctx
, ctx
->nip
);
3850 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3852 tcg_temp_free_i32(t1
);
3856 /*** Processor control ***/
3858 static void gen_read_xer(TCGv dst
)
3860 TCGv t0
= tcg_temp_new();
3861 TCGv t1
= tcg_temp_new();
3862 TCGv t2
= tcg_temp_new();
3863 tcg_gen_mov_tl(dst
, cpu_xer
);
3864 tcg_gen_shli_tl(t0
, cpu_so
, XER_SO
);
3865 tcg_gen_shli_tl(t1
, cpu_ov
, XER_OV
);
3866 tcg_gen_shli_tl(t2
, cpu_ca
, XER_CA
);
3867 tcg_gen_or_tl(t0
, t0
, t1
);
3868 tcg_gen_or_tl(dst
, dst
, t2
);
3869 tcg_gen_or_tl(dst
, dst
, t0
);
3875 static void gen_write_xer(TCGv src
)
3877 tcg_gen_andi_tl(cpu_xer
, src
,
3878 ~((1u << XER_SO
) | (1u << XER_OV
) | (1u << XER_CA
)));
3879 tcg_gen_shri_tl(cpu_so
, src
, XER_SO
);
3880 tcg_gen_shri_tl(cpu_ov
, src
, XER_OV
);
3881 tcg_gen_shri_tl(cpu_ca
, src
, XER_CA
);
3882 tcg_gen_andi_tl(cpu_so
, cpu_so
, 1);
3883 tcg_gen_andi_tl(cpu_ov
, cpu_ov
, 1);
3884 tcg_gen_andi_tl(cpu_ca
, cpu_ca
, 1);
3888 static void gen_mcrxr(DisasContext
*ctx
)
3890 TCGv_i32 t0
= tcg_temp_new_i32();
3891 TCGv_i32 t1
= tcg_temp_new_i32();
3892 TCGv_i32 dst
= cpu_crf
[crfD(ctx
->opcode
)];
3894 tcg_gen_trunc_tl_i32(t0
, cpu_so
);
3895 tcg_gen_trunc_tl_i32(t1
, cpu_ov
);
3896 tcg_gen_trunc_tl_i32(dst
, cpu_ca
);
3897 tcg_gen_shri_i32(t0
, t0
, 2);
3898 tcg_gen_shri_i32(t1
, t1
, 1);
3899 tcg_gen_or_i32(dst
, dst
, t0
);
3900 tcg_gen_or_i32(dst
, dst
, t1
);
3901 tcg_temp_free_i32(t0
);
3902 tcg_temp_free_i32(t1
);
3904 tcg_gen_movi_tl(cpu_so
, 0);
3905 tcg_gen_movi_tl(cpu_ov
, 0);
3906 tcg_gen_movi_tl(cpu_ca
, 0);
3910 static void gen_mfcr(DisasContext
*ctx
)
3914 if (likely(ctx
->opcode
& 0x00100000)) {
3915 crm
= CRM(ctx
->opcode
);
3916 if (likely(crm
&& ((crm
& (crm
- 1)) == 0))) {
3918 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_crf
[7 - crn
]);
3919 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)],
3920 cpu_gpr
[rD(ctx
->opcode
)], crn
* 4);
3923 TCGv_i32 t0
= tcg_temp_new_i32();
3924 tcg_gen_mov_i32(t0
, cpu_crf
[0]);
3925 tcg_gen_shli_i32(t0
, t0
, 4);
3926 tcg_gen_or_i32(t0
, t0
, cpu_crf
[1]);
3927 tcg_gen_shli_i32(t0
, t0
, 4);
3928 tcg_gen_or_i32(t0
, t0
, cpu_crf
[2]);
3929 tcg_gen_shli_i32(t0
, t0
, 4);
3930 tcg_gen_or_i32(t0
, t0
, cpu_crf
[3]);
3931 tcg_gen_shli_i32(t0
, t0
, 4);
3932 tcg_gen_or_i32(t0
, t0
, cpu_crf
[4]);
3933 tcg_gen_shli_i32(t0
, t0
, 4);
3934 tcg_gen_or_i32(t0
, t0
, cpu_crf
[5]);
3935 tcg_gen_shli_i32(t0
, t0
, 4);
3936 tcg_gen_or_i32(t0
, t0
, cpu_crf
[6]);
3937 tcg_gen_shli_i32(t0
, t0
, 4);
3938 tcg_gen_or_i32(t0
, t0
, cpu_crf
[7]);
3939 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
3940 tcg_temp_free_i32(t0
);
3945 static void gen_mfmsr(DisasContext
*ctx
)
3947 #if defined(CONFIG_USER_ONLY)
3948 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3950 if (unlikely(!ctx
->mem_idx
)) {
3951 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3954 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_msr
);
3958 static void spr_noaccess(void *opaque
, int gprn
, int sprn
)
3961 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
3962 printf("ERROR: try to access SPR %d !\n", sprn
);
3965 #define SPR_NOACCESS (&spr_noaccess)
3968 static inline void gen_op_mfspr(DisasContext
*ctx
)
3970 void (*read_cb
)(void *opaque
, int gprn
, int sprn
);
3971 uint32_t sprn
= SPR(ctx
->opcode
);
3973 #if !defined(CONFIG_USER_ONLY)
3974 if (ctx
->mem_idx
== 2)
3975 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
3976 else if (ctx
->mem_idx
)
3977 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
3980 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
3981 if (likely(read_cb
!= NULL
)) {
3982 if (likely(read_cb
!= SPR_NOACCESS
)) {
3983 (*read_cb
)(ctx
, rD(ctx
->opcode
), sprn
);
3985 /* Privilege exception */
3986 /* This is a hack to avoid warnings when running Linux:
3987 * this OS breaks the PowerPC virtualisation model,
3988 * allowing userland application to read the PVR
3990 if (sprn
!= SPR_PVR
) {
3991 qemu_log("Trying to read privileged spr %d %03x at "
3992 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
3993 printf("Trying to read privileged spr %d %03x at "
3994 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
3996 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4000 qemu_log("Trying to read invalid spr %d %03x at "
4001 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
4002 printf("Trying to read invalid spr %d %03x at " TARGET_FMT_lx
"\n",
4003 sprn
, sprn
, ctx
->nip
);
4004 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4008 static void gen_mfspr(DisasContext
*ctx
)
4014 static void gen_mftb(DisasContext
*ctx
)
4020 static void gen_mtcrf(DisasContext
*ctx
)
4024 crm
= CRM(ctx
->opcode
);
4025 if (likely((ctx
->opcode
& 0x00100000))) {
4026 if (crm
&& ((crm
& (crm
- 1)) == 0)) {
4027 TCGv_i32 temp
= tcg_temp_new_i32();
4029 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
4030 tcg_gen_shri_i32(temp
, temp
, crn
* 4);
4031 tcg_gen_andi_i32(cpu_crf
[7 - crn
], temp
, 0xf);
4032 tcg_temp_free_i32(temp
);
4035 TCGv_i32 temp
= tcg_temp_new_i32();
4036 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
4037 for (crn
= 0 ; crn
< 8 ; crn
++) {
4038 if (crm
& (1 << crn
)) {
4039 tcg_gen_shri_i32(cpu_crf
[7 - crn
], temp
, crn
* 4);
4040 tcg_gen_andi_i32(cpu_crf
[7 - crn
], cpu_crf
[7 - crn
], 0xf);
4043 tcg_temp_free_i32(temp
);
4048 #if defined(TARGET_PPC64)
4049 static void gen_mtmsrd(DisasContext
*ctx
)
4051 #if defined(CONFIG_USER_ONLY)
4052 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4054 if (unlikely(!ctx
->mem_idx
)) {
4055 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4058 if (ctx
->opcode
& 0x00010000) {
4059 /* Special form that does not need any synchronisation */
4060 TCGv t0
= tcg_temp_new();
4061 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
4062 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
4063 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
4066 /* XXX: we need to update nip before the store
4067 * if we enter power saving mode, we will exit the loop
4068 * directly from ppc_store_msr
4070 gen_update_nip(ctx
, ctx
->nip
);
4071 gen_helper_store_msr(cpu_env
, cpu_gpr
[rS(ctx
->opcode
)]);
4072 /* Must stop the translation as machine state (may have) changed */
4073 /* Note that mtmsr is not always defined as context-synchronizing */
4074 gen_stop_exception(ctx
);
4080 static void gen_mtmsr(DisasContext
*ctx
)
4082 #if defined(CONFIG_USER_ONLY)
4083 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4085 if (unlikely(!ctx
->mem_idx
)) {
4086 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4089 if (ctx
->opcode
& 0x00010000) {
4090 /* Special form that does not need any synchronisation */
4091 TCGv t0
= tcg_temp_new();
4092 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
4093 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
4094 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
4097 TCGv msr
= tcg_temp_new();
4099 /* XXX: we need to update nip before the store
4100 * if we enter power saving mode, we will exit the loop
4101 * directly from ppc_store_msr
4103 gen_update_nip(ctx
, ctx
->nip
);
4104 #if defined(TARGET_PPC64)
4105 tcg_gen_deposit_tl(msr
, cpu_msr
, cpu_gpr
[rS(ctx
->opcode
)], 0, 32);
4107 tcg_gen_mov_tl(msr
, cpu_gpr
[rS(ctx
->opcode
)]);
4109 gen_helper_store_msr(cpu_env
, msr
);
4110 /* Must stop the translation as machine state (may have) changed */
4111 /* Note that mtmsr is not always defined as context-synchronizing */
4112 gen_stop_exception(ctx
);
4118 static void gen_mtspr(DisasContext
*ctx
)
4120 void (*write_cb
)(void *opaque
, int sprn
, int gprn
);
4121 uint32_t sprn
= SPR(ctx
->opcode
);
4123 #if !defined(CONFIG_USER_ONLY)
4124 if (ctx
->mem_idx
== 2)
4125 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
4126 else if (ctx
->mem_idx
)
4127 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
4130 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
4131 if (likely(write_cb
!= NULL
)) {
4132 if (likely(write_cb
!= SPR_NOACCESS
)) {
4133 (*write_cb
)(ctx
, sprn
, rS(ctx
->opcode
));
4135 /* Privilege exception */
4136 qemu_log("Trying to write privileged spr %d %03x at "
4137 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
4138 printf("Trying to write privileged spr %d %03x at " TARGET_FMT_lx
4139 "\n", sprn
, sprn
, ctx
->nip
);
4140 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4144 qemu_log("Trying to write invalid spr %d %03x at "
4145 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->nip
);
4146 printf("Trying to write invalid spr %d %03x at " TARGET_FMT_lx
"\n",
4147 sprn
, sprn
, ctx
->nip
);
4148 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4152 /*** Cache management ***/
4155 static void gen_dcbf(DisasContext
*ctx
)
4157 /* XXX: specification says this is treated as a load by the MMU */
4159 gen_set_access_type(ctx
, ACCESS_CACHE
);
4160 t0
= tcg_temp_new();
4161 gen_addr_reg_index(ctx
, t0
);
4162 gen_qemu_ld8u(ctx
, t0
, t0
);
4166 /* dcbi (Supervisor only) */
4167 static void gen_dcbi(DisasContext
*ctx
)
4169 #if defined(CONFIG_USER_ONLY)
4170 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4173 if (unlikely(!ctx
->mem_idx
)) {
4174 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4177 EA
= tcg_temp_new();
4178 gen_set_access_type(ctx
, ACCESS_CACHE
);
4179 gen_addr_reg_index(ctx
, EA
);
4180 val
= tcg_temp_new();
4181 /* XXX: specification says this should be treated as a store by the MMU */
4182 gen_qemu_ld8u(ctx
, val
, EA
);
4183 gen_qemu_st8(ctx
, val
, EA
);
4190 static void gen_dcbst(DisasContext
*ctx
)
4192 /* XXX: specification say this is treated as a load by the MMU */
4194 gen_set_access_type(ctx
, ACCESS_CACHE
);
4195 t0
= tcg_temp_new();
4196 gen_addr_reg_index(ctx
, t0
);
4197 gen_qemu_ld8u(ctx
, t0
, t0
);
4202 static void gen_dcbt(DisasContext
*ctx
)
4204 /* interpreted as no-op */
4205 /* XXX: specification say this is treated as a load by the MMU
4206 * but does not generate any exception
4211 static void gen_dcbtst(DisasContext
*ctx
)
4213 /* interpreted as no-op */
4214 /* XXX: specification say this is treated as a load by the MMU
4215 * but does not generate any exception
4220 static void gen_dcbz(DisasContext
*ctx
)
4223 TCGv_i32 tcgv_is_dcbzl
;
4224 int is_dcbzl
= ctx
->opcode
& 0x00200000 ? 1 : 0;
4226 gen_set_access_type(ctx
, ACCESS_CACHE
);
4227 /* NIP cannot be restored if the memory exception comes from an helper */
4228 gen_update_nip(ctx
, ctx
->nip
- 4);
4229 tcgv_addr
= tcg_temp_new();
4230 tcgv_is_dcbzl
= tcg_const_i32(is_dcbzl
);
4232 gen_addr_reg_index(ctx
, tcgv_addr
);
4233 gen_helper_dcbz(cpu_env
, tcgv_addr
, tcgv_is_dcbzl
);
4235 tcg_temp_free(tcgv_addr
);
4236 tcg_temp_free_i32(tcgv_is_dcbzl
);
4240 static void gen_dst(DisasContext
*ctx
)
4242 if (rA(ctx
->opcode
) == 0) {
4243 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
4245 /* interpreted as no-op */
4250 static void gen_dstst(DisasContext
*ctx
)
4252 if (rA(ctx
->opcode
) == 0) {
4253 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
4255 /* interpreted as no-op */
4261 static void gen_dss(DisasContext
*ctx
)
4263 /* interpreted as no-op */
4267 static void gen_icbi(DisasContext
*ctx
)
4270 gen_set_access_type(ctx
, ACCESS_CACHE
);
4271 /* NIP cannot be restored if the memory exception comes from an helper */
4272 gen_update_nip(ctx
, ctx
->nip
- 4);
4273 t0
= tcg_temp_new();
4274 gen_addr_reg_index(ctx
, t0
);
4275 gen_helper_icbi(cpu_env
, t0
);
4281 static void gen_dcba(DisasContext
*ctx
)
4283 /* interpreted as no-op */
4284 /* XXX: specification say this is treated as a store by the MMU
4285 * but does not generate any exception
4289 /*** Segment register manipulation ***/
4290 /* Supervisor only: */
4293 static void gen_mfsr(DisasContext
*ctx
)
4295 #if defined(CONFIG_USER_ONLY)
4296 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4299 if (unlikely(!ctx
->mem_idx
)) {
4300 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4303 t0
= tcg_const_tl(SR(ctx
->opcode
));
4304 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4310 static void gen_mfsrin(DisasContext
*ctx
)
4312 #if defined(CONFIG_USER_ONLY)
4313 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4316 if (unlikely(!ctx
->mem_idx
)) {
4317 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4320 t0
= tcg_temp_new();
4321 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4322 tcg_gen_andi_tl(t0
, t0
, 0xF);
4323 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4329 static void gen_mtsr(DisasContext
*ctx
)
4331 #if defined(CONFIG_USER_ONLY)
4332 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4335 if (unlikely(!ctx
->mem_idx
)) {
4336 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4339 t0
= tcg_const_tl(SR(ctx
->opcode
));
4340 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4346 static void gen_mtsrin(DisasContext
*ctx
)
4348 #if defined(CONFIG_USER_ONLY)
4349 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4352 if (unlikely(!ctx
->mem_idx
)) {
4353 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4356 t0
= tcg_temp_new();
4357 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4358 tcg_gen_andi_tl(t0
, t0
, 0xF);
4359 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rD(ctx
->opcode
)]);
4364 #if defined(TARGET_PPC64)
4365 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4368 static void gen_mfsr_64b(DisasContext
*ctx
)
4370 #if defined(CONFIG_USER_ONLY)
4371 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4374 if (unlikely(!ctx
->mem_idx
)) {
4375 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4378 t0
= tcg_const_tl(SR(ctx
->opcode
));
4379 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4385 static void gen_mfsrin_64b(DisasContext
*ctx
)
4387 #if defined(CONFIG_USER_ONLY)
4388 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4391 if (unlikely(!ctx
->mem_idx
)) {
4392 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4395 t0
= tcg_temp_new();
4396 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4397 tcg_gen_andi_tl(t0
, t0
, 0xF);
4398 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4404 static void gen_mtsr_64b(DisasContext
*ctx
)
4406 #if defined(CONFIG_USER_ONLY)
4407 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4410 if (unlikely(!ctx
->mem_idx
)) {
4411 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4414 t0
= tcg_const_tl(SR(ctx
->opcode
));
4415 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4421 static void gen_mtsrin_64b(DisasContext
*ctx
)
4423 #if defined(CONFIG_USER_ONLY)
4424 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4427 if (unlikely(!ctx
->mem_idx
)) {
4428 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4431 t0
= tcg_temp_new();
4432 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4433 tcg_gen_andi_tl(t0
, t0
, 0xF);
4434 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4440 static void gen_slbmte(DisasContext
*ctx
)
4442 #if defined(CONFIG_USER_ONLY)
4443 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4445 if (unlikely(!ctx
->mem_idx
)) {
4446 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4449 gen_helper_store_slb(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)],
4450 cpu_gpr
[rS(ctx
->opcode
)]);
4454 static void gen_slbmfee(DisasContext
*ctx
)
4456 #if defined(CONFIG_USER_ONLY)
4457 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4459 if (unlikely(!ctx
->mem_idx
)) {
4460 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4463 gen_helper_load_slb_esid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4464 cpu_gpr
[rB(ctx
->opcode
)]);
4468 static void gen_slbmfev(DisasContext
*ctx
)
4470 #if defined(CONFIG_USER_ONLY)
4471 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4473 if (unlikely(!ctx
->mem_idx
)) {
4474 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4477 gen_helper_load_slb_vsid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
4478 cpu_gpr
[rB(ctx
->opcode
)]);
4481 #endif /* defined(TARGET_PPC64) */
4483 /*** Lookaside buffer management ***/
4484 /* Optional & mem_idx only: */
4487 static void gen_tlbia(DisasContext
*ctx
)
4489 #if defined(CONFIG_USER_ONLY)
4490 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4492 if (unlikely(!ctx
->mem_idx
)) {
4493 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4496 gen_helper_tlbia(cpu_env
);
4501 static void gen_tlbiel(DisasContext
*ctx
)
4503 #if defined(CONFIG_USER_ONLY)
4504 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4506 if (unlikely(!ctx
->mem_idx
)) {
4507 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4510 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4515 static void gen_tlbie(DisasContext
*ctx
)
4517 #if defined(CONFIG_USER_ONLY)
4518 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4520 if (unlikely(!ctx
->mem_idx
)) {
4521 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4524 if (NARROW_MODE(ctx
)) {
4525 TCGv t0
= tcg_temp_new();
4526 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
4527 gen_helper_tlbie(cpu_env
, t0
);
4530 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4536 static void gen_tlbsync(DisasContext
*ctx
)
4538 #if defined(CONFIG_USER_ONLY)
4539 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4541 if (unlikely(!ctx
->mem_idx
)) {
4542 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4545 /* This has no effect: it should ensure that all previous
4546 * tlbie have completed
4548 gen_stop_exception(ctx
);
4552 #if defined(TARGET_PPC64)
4554 static void gen_slbia(DisasContext
*ctx
)
4556 #if defined(CONFIG_USER_ONLY)
4557 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4559 if (unlikely(!ctx
->mem_idx
)) {
4560 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4563 gen_helper_slbia(cpu_env
);
4568 static void gen_slbie(DisasContext
*ctx
)
4570 #if defined(CONFIG_USER_ONLY)
4571 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4573 if (unlikely(!ctx
->mem_idx
)) {
4574 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4577 gen_helper_slbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
4582 /*** External control ***/
4586 static void gen_eciwx(DisasContext
*ctx
)
4589 /* Should check EAR[E] ! */
4590 gen_set_access_type(ctx
, ACCESS_EXT
);
4591 t0
= tcg_temp_new();
4592 gen_addr_reg_index(ctx
, t0
);
4593 gen_check_align(ctx
, t0
, 0x03);
4594 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4599 static void gen_ecowx(DisasContext
*ctx
)
4602 /* Should check EAR[E] ! */
4603 gen_set_access_type(ctx
, ACCESS_EXT
);
4604 t0
= tcg_temp_new();
4605 gen_addr_reg_index(ctx
, t0
);
4606 gen_check_align(ctx
, t0
, 0x03);
4607 gen_qemu_st32(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4611 /* PowerPC 601 specific instructions */
4614 static void gen_abs(DisasContext
*ctx
)
4616 int l1
= gen_new_label();
4617 int l2
= gen_new_label();
4618 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4619 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4622 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4624 if (unlikely(Rc(ctx
->opcode
) != 0))
4625 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4629 static void gen_abso(DisasContext
*ctx
)
4631 int l1
= gen_new_label();
4632 int l2
= gen_new_label();
4633 int l3
= gen_new_label();
4634 /* Start with XER OV disabled, the most likely case */
4635 tcg_gen_movi_tl(cpu_ov
, 0);
4636 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l2
);
4637 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rA(ctx
->opcode
)], 0x80000000, l1
);
4638 tcg_gen_movi_tl(cpu_ov
, 1);
4639 tcg_gen_movi_tl(cpu_so
, 1);
4642 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4645 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4647 if (unlikely(Rc(ctx
->opcode
) != 0))
4648 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4652 static void gen_clcs(DisasContext
*ctx
)
4654 TCGv_i32 t0
= tcg_const_i32(rA(ctx
->opcode
));
4655 gen_helper_clcs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
4656 tcg_temp_free_i32(t0
);
4657 /* Rc=1 sets CR0 to an undefined state */
4661 static void gen_div(DisasContext
*ctx
)
4663 gen_helper_div(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4664 cpu_gpr
[rB(ctx
->opcode
)]);
4665 if (unlikely(Rc(ctx
->opcode
) != 0))
4666 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4670 static void gen_divo(DisasContext
*ctx
)
4672 gen_helper_divo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4673 cpu_gpr
[rB(ctx
->opcode
)]);
4674 if (unlikely(Rc(ctx
->opcode
) != 0))
4675 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4679 static void gen_divs(DisasContext
*ctx
)
4681 gen_helper_divs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
4682 cpu_gpr
[rB(ctx
->opcode
)]);
4683 if (unlikely(Rc(ctx
->opcode
) != 0))
4684 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4687 /* divso - divso. */
4688 static void gen_divso(DisasContext
*ctx
)
4690 gen_helper_divso(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
4691 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4692 if (unlikely(Rc(ctx
->opcode
) != 0))
4693 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4697 static void gen_doz(DisasContext
*ctx
)
4699 int l1
= gen_new_label();
4700 int l2
= gen_new_label();
4701 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4702 tcg_gen_sub_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4705 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4707 if (unlikely(Rc(ctx
->opcode
) != 0))
4708 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4712 static void gen_dozo(DisasContext
*ctx
)
4714 int l1
= gen_new_label();
4715 int l2
= gen_new_label();
4716 TCGv t0
= tcg_temp_new();
4717 TCGv t1
= tcg_temp_new();
4718 TCGv t2
= tcg_temp_new();
4719 /* Start with XER OV disabled, the most likely case */
4720 tcg_gen_movi_tl(cpu_ov
, 0);
4721 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4722 tcg_gen_sub_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4723 tcg_gen_xor_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4724 tcg_gen_xor_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], t0
);
4725 tcg_gen_andc_tl(t1
, t1
, t2
);
4726 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4727 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
4728 tcg_gen_movi_tl(cpu_ov
, 1);
4729 tcg_gen_movi_tl(cpu_so
, 1);
4732 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4737 if (unlikely(Rc(ctx
->opcode
) != 0))
4738 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4742 static void gen_dozi(DisasContext
*ctx
)
4744 target_long simm
= SIMM(ctx
->opcode
);
4745 int l1
= gen_new_label();
4746 int l2
= gen_new_label();
4747 tcg_gen_brcondi_tl(TCG_COND_LT
, cpu_gpr
[rA(ctx
->opcode
)], simm
, l1
);
4748 tcg_gen_subfi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
, cpu_gpr
[rA(ctx
->opcode
)]);
4751 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4753 if (unlikely(Rc(ctx
->opcode
) != 0))
4754 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4757 /* lscbx - lscbx. */
4758 static void gen_lscbx(DisasContext
*ctx
)
4760 TCGv t0
= tcg_temp_new();
4761 TCGv_i32 t1
= tcg_const_i32(rD(ctx
->opcode
));
4762 TCGv_i32 t2
= tcg_const_i32(rA(ctx
->opcode
));
4763 TCGv_i32 t3
= tcg_const_i32(rB(ctx
->opcode
));
4765 gen_addr_reg_index(ctx
, t0
);
4766 /* NIP cannot be restored if the memory exception comes from an helper */
4767 gen_update_nip(ctx
, ctx
->nip
- 4);
4768 gen_helper_lscbx(t0
, cpu_env
, t0
, t1
, t2
, t3
);
4769 tcg_temp_free_i32(t1
);
4770 tcg_temp_free_i32(t2
);
4771 tcg_temp_free_i32(t3
);
4772 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~0x7F);
4773 tcg_gen_or_tl(cpu_xer
, cpu_xer
, t0
);
4774 if (unlikely(Rc(ctx
->opcode
) != 0))
4775 gen_set_Rc0(ctx
, t0
);
4779 /* maskg - maskg. */
4780 static void gen_maskg(DisasContext
*ctx
)
4782 int l1
= gen_new_label();
4783 TCGv t0
= tcg_temp_new();
4784 TCGv t1
= tcg_temp_new();
4785 TCGv t2
= tcg_temp_new();
4786 TCGv t3
= tcg_temp_new();
4787 tcg_gen_movi_tl(t3
, 0xFFFFFFFF);
4788 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4789 tcg_gen_andi_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 0x1F);
4790 tcg_gen_addi_tl(t2
, t0
, 1);
4791 tcg_gen_shr_tl(t2
, t3
, t2
);
4792 tcg_gen_shr_tl(t3
, t3
, t1
);
4793 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], t2
, t3
);
4794 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
4795 tcg_gen_neg_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4801 if (unlikely(Rc(ctx
->opcode
) != 0))
4802 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4805 /* maskir - maskir. */
4806 static void gen_maskir(DisasContext
*ctx
)
4808 TCGv t0
= tcg_temp_new();
4809 TCGv t1
= tcg_temp_new();
4810 tcg_gen_and_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4811 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4812 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4815 if (unlikely(Rc(ctx
->opcode
) != 0))
4816 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4820 static void gen_mul(DisasContext
*ctx
)
4822 TCGv_i64 t0
= tcg_temp_new_i64();
4823 TCGv_i64 t1
= tcg_temp_new_i64();
4824 TCGv t2
= tcg_temp_new();
4825 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4826 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4827 tcg_gen_mul_i64(t0
, t0
, t1
);
4828 tcg_gen_trunc_i64_tl(t2
, t0
);
4829 gen_store_spr(SPR_MQ
, t2
);
4830 tcg_gen_shri_i64(t1
, t0
, 32);
4831 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4832 tcg_temp_free_i64(t0
);
4833 tcg_temp_free_i64(t1
);
4835 if (unlikely(Rc(ctx
->opcode
) != 0))
4836 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4840 static void gen_mulo(DisasContext
*ctx
)
4842 int l1
= gen_new_label();
4843 TCGv_i64 t0
= tcg_temp_new_i64();
4844 TCGv_i64 t1
= tcg_temp_new_i64();
4845 TCGv t2
= tcg_temp_new();
4846 /* Start with XER OV disabled, the most likely case */
4847 tcg_gen_movi_tl(cpu_ov
, 0);
4848 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4849 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4850 tcg_gen_mul_i64(t0
, t0
, t1
);
4851 tcg_gen_trunc_i64_tl(t2
, t0
);
4852 gen_store_spr(SPR_MQ
, t2
);
4853 tcg_gen_shri_i64(t1
, t0
, 32);
4854 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4855 tcg_gen_ext32s_i64(t1
, t0
);
4856 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
4857 tcg_gen_movi_tl(cpu_ov
, 1);
4858 tcg_gen_movi_tl(cpu_so
, 1);
4860 tcg_temp_free_i64(t0
);
4861 tcg_temp_free_i64(t1
);
4863 if (unlikely(Rc(ctx
->opcode
) != 0))
4864 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4868 static void gen_nabs(DisasContext
*ctx
)
4870 int l1
= gen_new_label();
4871 int l2
= gen_new_label();
4872 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4873 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4876 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4878 if (unlikely(Rc(ctx
->opcode
) != 0))
4879 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4882 /* nabso - nabso. */
4883 static void gen_nabso(DisasContext
*ctx
)
4885 int l1
= gen_new_label();
4886 int l2
= gen_new_label();
4887 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4888 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4891 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4893 /* nabs never overflows */
4894 tcg_gen_movi_tl(cpu_ov
, 0);
4895 if (unlikely(Rc(ctx
->opcode
) != 0))
4896 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4900 static void gen_rlmi(DisasContext
*ctx
)
4902 uint32_t mb
= MB(ctx
->opcode
);
4903 uint32_t me
= ME(ctx
->opcode
);
4904 TCGv t0
= tcg_temp_new();
4905 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4906 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4907 tcg_gen_andi_tl(t0
, t0
, MASK(mb
, me
));
4908 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~MASK(mb
, me
));
4909 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], t0
);
4911 if (unlikely(Rc(ctx
->opcode
) != 0))
4912 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4916 static void gen_rrib(DisasContext
*ctx
)
4918 TCGv t0
= tcg_temp_new();
4919 TCGv t1
= tcg_temp_new();
4920 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4921 tcg_gen_movi_tl(t1
, 0x80000000);
4922 tcg_gen_shr_tl(t1
, t1
, t0
);
4923 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4924 tcg_gen_and_tl(t0
, t0
, t1
);
4925 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], t1
);
4926 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4929 if (unlikely(Rc(ctx
->opcode
) != 0))
4930 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4934 static void gen_sle(DisasContext
*ctx
)
4936 TCGv t0
= tcg_temp_new();
4937 TCGv t1
= tcg_temp_new();
4938 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4939 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4940 tcg_gen_subfi_tl(t1
, 32, t1
);
4941 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4942 tcg_gen_or_tl(t1
, t0
, t1
);
4943 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4944 gen_store_spr(SPR_MQ
, t1
);
4947 if (unlikely(Rc(ctx
->opcode
) != 0))
4948 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4952 static void gen_sleq(DisasContext
*ctx
)
4954 TCGv t0
= tcg_temp_new();
4955 TCGv t1
= tcg_temp_new();
4956 TCGv t2
= tcg_temp_new();
4957 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4958 tcg_gen_movi_tl(t2
, 0xFFFFFFFF);
4959 tcg_gen_shl_tl(t2
, t2
, t0
);
4960 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4961 gen_load_spr(t1
, SPR_MQ
);
4962 gen_store_spr(SPR_MQ
, t0
);
4963 tcg_gen_and_tl(t0
, t0
, t2
);
4964 tcg_gen_andc_tl(t1
, t1
, t2
);
4965 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4969 if (unlikely(Rc(ctx
->opcode
) != 0))
4970 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4974 static void gen_sliq(DisasContext
*ctx
)
4976 int sh
= SH(ctx
->opcode
);
4977 TCGv t0
= tcg_temp_new();
4978 TCGv t1
= tcg_temp_new();
4979 tcg_gen_shli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4980 tcg_gen_shri_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
4981 tcg_gen_or_tl(t1
, t0
, t1
);
4982 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4983 gen_store_spr(SPR_MQ
, t1
);
4986 if (unlikely(Rc(ctx
->opcode
) != 0))
4987 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4990 /* slliq - slliq. */
4991 static void gen_slliq(DisasContext
*ctx
)
4993 int sh
= SH(ctx
->opcode
);
4994 TCGv t0
= tcg_temp_new();
4995 TCGv t1
= tcg_temp_new();
4996 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4997 gen_load_spr(t1
, SPR_MQ
);
4998 gen_store_spr(SPR_MQ
, t0
);
4999 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
<< sh
));
5000 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
<< sh
));
5001 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5004 if (unlikely(Rc(ctx
->opcode
) != 0))
5005 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5009 static void gen_sllq(DisasContext
*ctx
)
5011 int l1
= gen_new_label();
5012 int l2
= gen_new_label();
5013 TCGv t0
= tcg_temp_local_new();
5014 TCGv t1
= tcg_temp_local_new();
5015 TCGv t2
= tcg_temp_local_new();
5016 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5017 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5018 tcg_gen_shl_tl(t1
, t1
, t2
);
5019 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5020 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5021 gen_load_spr(t0
, SPR_MQ
);
5022 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5025 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5026 gen_load_spr(t2
, SPR_MQ
);
5027 tcg_gen_andc_tl(t1
, t2
, t1
);
5028 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5033 if (unlikely(Rc(ctx
->opcode
) != 0))
5034 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5038 static void gen_slq(DisasContext
*ctx
)
5040 int l1
= gen_new_label();
5041 TCGv t0
= tcg_temp_new();
5042 TCGv t1
= tcg_temp_new();
5043 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5044 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5045 tcg_gen_subfi_tl(t1
, 32, t1
);
5046 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5047 tcg_gen_or_tl(t1
, t0
, t1
);
5048 gen_store_spr(SPR_MQ
, t1
);
5049 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5050 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5051 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
5052 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5056 if (unlikely(Rc(ctx
->opcode
) != 0))
5057 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5060 /* sraiq - sraiq. */
5061 static void gen_sraiq(DisasContext
*ctx
)
5063 int sh
= SH(ctx
->opcode
);
5064 int l1
= gen_new_label();
5065 TCGv t0
= tcg_temp_new();
5066 TCGv t1
= tcg_temp_new();
5067 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5068 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5069 tcg_gen_or_tl(t0
, t0
, t1
);
5070 gen_store_spr(SPR_MQ
, t0
);
5071 tcg_gen_movi_tl(cpu_ca
, 0);
5072 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
5073 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
5074 tcg_gen_movi_tl(cpu_ca
, 1);
5076 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
5079 if (unlikely(Rc(ctx
->opcode
) != 0))
5080 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5084 static void gen_sraq(DisasContext
*ctx
)
5086 int l1
= gen_new_label();
5087 int l2
= gen_new_label();
5088 TCGv t0
= tcg_temp_new();
5089 TCGv t1
= tcg_temp_local_new();
5090 TCGv t2
= tcg_temp_local_new();
5091 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5092 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5093 tcg_gen_sar_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5094 tcg_gen_subfi_tl(t2
, 32, t2
);
5095 tcg_gen_shl_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5096 tcg_gen_or_tl(t0
, t0
, t2
);
5097 gen_store_spr(SPR_MQ
, t0
);
5098 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5099 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l1
);
5100 tcg_gen_mov_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
5101 tcg_gen_sari_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 31);
5104 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
);
5105 tcg_gen_movi_tl(cpu_ca
, 0);
5106 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
5107 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l2
);
5108 tcg_gen_movi_tl(cpu_ca
, 1);
5112 if (unlikely(Rc(ctx
->opcode
) != 0))
5113 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5117 static void gen_sre(DisasContext
*ctx
)
5119 TCGv t0
= tcg_temp_new();
5120 TCGv t1
= tcg_temp_new();
5121 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5122 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5123 tcg_gen_subfi_tl(t1
, 32, t1
);
5124 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5125 tcg_gen_or_tl(t1
, t0
, t1
);
5126 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5127 gen_store_spr(SPR_MQ
, t1
);
5130 if (unlikely(Rc(ctx
->opcode
) != 0))
5131 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5135 static void gen_srea(DisasContext
*ctx
)
5137 TCGv t0
= tcg_temp_new();
5138 TCGv t1
= tcg_temp_new();
5139 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5140 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5141 gen_store_spr(SPR_MQ
, t0
);
5142 tcg_gen_sar_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t1
);
5145 if (unlikely(Rc(ctx
->opcode
) != 0))
5146 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5150 static void gen_sreq(DisasContext
*ctx
)
5152 TCGv t0
= tcg_temp_new();
5153 TCGv t1
= tcg_temp_new();
5154 TCGv t2
= tcg_temp_new();
5155 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5156 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5157 tcg_gen_shr_tl(t1
, t1
, t0
);
5158 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5159 gen_load_spr(t2
, SPR_MQ
);
5160 gen_store_spr(SPR_MQ
, t0
);
5161 tcg_gen_and_tl(t0
, t0
, t1
);
5162 tcg_gen_andc_tl(t2
, t2
, t1
);
5163 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5167 if (unlikely(Rc(ctx
->opcode
) != 0))
5168 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5172 static void gen_sriq(DisasContext
*ctx
)
5174 int sh
= SH(ctx
->opcode
);
5175 TCGv t0
= tcg_temp_new();
5176 TCGv t1
= tcg_temp_new();
5177 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5178 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5179 tcg_gen_or_tl(t1
, t0
, t1
);
5180 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5181 gen_store_spr(SPR_MQ
, t1
);
5184 if (unlikely(Rc(ctx
->opcode
) != 0))
5185 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5189 static void gen_srliq(DisasContext
*ctx
)
5191 int sh
= SH(ctx
->opcode
);
5192 TCGv t0
= tcg_temp_new();
5193 TCGv t1
= tcg_temp_new();
5194 tcg_gen_rotri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5195 gen_load_spr(t1
, SPR_MQ
);
5196 gen_store_spr(SPR_MQ
, t0
);
5197 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
>> sh
));
5198 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
>> sh
));
5199 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5202 if (unlikely(Rc(ctx
->opcode
) != 0))
5203 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5207 static void gen_srlq(DisasContext
*ctx
)
5209 int l1
= gen_new_label();
5210 int l2
= gen_new_label();
5211 TCGv t0
= tcg_temp_local_new();
5212 TCGv t1
= tcg_temp_local_new();
5213 TCGv t2
= tcg_temp_local_new();
5214 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5215 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5216 tcg_gen_shr_tl(t2
, t1
, t2
);
5217 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5218 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5219 gen_load_spr(t0
, SPR_MQ
);
5220 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5223 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5224 tcg_gen_and_tl(t0
, t0
, t2
);
5225 gen_load_spr(t1
, SPR_MQ
);
5226 tcg_gen_andc_tl(t1
, t1
, t2
);
5227 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5232 if (unlikely(Rc(ctx
->opcode
) != 0))
5233 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5237 static void gen_srq(DisasContext
*ctx
)
5239 int l1
= gen_new_label();
5240 TCGv t0
= tcg_temp_new();
5241 TCGv t1
= tcg_temp_new();
5242 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5243 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5244 tcg_gen_subfi_tl(t1
, 32, t1
);
5245 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5246 tcg_gen_or_tl(t1
, t0
, t1
);
5247 gen_store_spr(SPR_MQ
, t1
);
5248 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5249 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5250 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5251 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5255 if (unlikely(Rc(ctx
->opcode
) != 0))
5256 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5259 /* PowerPC 602 specific instructions */
5262 static void gen_dsa(DisasContext
*ctx
)
5265 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5269 static void gen_esa(DisasContext
*ctx
)
5272 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5276 static void gen_mfrom(DisasContext
*ctx
)
5278 #if defined(CONFIG_USER_ONLY)
5279 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5281 if (unlikely(!ctx
->mem_idx
)) {
5282 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5285 gen_helper_602_mfrom(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5289 /* 602 - 603 - G2 TLB management */
5292 static void gen_tlbld_6xx(DisasContext
*ctx
)
5294 #if defined(CONFIG_USER_ONLY)
5295 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5297 if (unlikely(!ctx
->mem_idx
)) {
5298 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5301 gen_helper_6xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5306 static void gen_tlbli_6xx(DisasContext
*ctx
)
5308 #if defined(CONFIG_USER_ONLY)
5309 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5311 if (unlikely(!ctx
->mem_idx
)) {
5312 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5315 gen_helper_6xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5319 /* 74xx TLB management */
5322 static void gen_tlbld_74xx(DisasContext
*ctx
)
5324 #if defined(CONFIG_USER_ONLY)
5325 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5327 if (unlikely(!ctx
->mem_idx
)) {
5328 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5331 gen_helper_74xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5336 static void gen_tlbli_74xx(DisasContext
*ctx
)
5338 #if defined(CONFIG_USER_ONLY)
5339 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5341 if (unlikely(!ctx
->mem_idx
)) {
5342 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5345 gen_helper_74xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5349 /* POWER instructions not in PowerPC 601 */
5352 static void gen_clf(DisasContext
*ctx
)
5354 /* Cache line flush: implemented as no-op */
5358 static void gen_cli(DisasContext
*ctx
)
5360 /* Cache line invalidate: privileged and treated as no-op */
5361 #if defined(CONFIG_USER_ONLY)
5362 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5364 if (unlikely(!ctx
->mem_idx
)) {
5365 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5372 static void gen_dclst(DisasContext
*ctx
)
5374 /* Data cache line store: treated as no-op */
5377 static void gen_mfsri(DisasContext
*ctx
)
5379 #if defined(CONFIG_USER_ONLY)
5380 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5382 int ra
= rA(ctx
->opcode
);
5383 int rd
= rD(ctx
->opcode
);
5385 if (unlikely(!ctx
->mem_idx
)) {
5386 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5389 t0
= tcg_temp_new();
5390 gen_addr_reg_index(ctx
, t0
);
5391 tcg_gen_shri_tl(t0
, t0
, 28);
5392 tcg_gen_andi_tl(t0
, t0
, 0xF);
5393 gen_helper_load_sr(cpu_gpr
[rd
], cpu_env
, t0
);
5395 if (ra
!= 0 && ra
!= rd
)
5396 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rd
]);
5400 static void gen_rac(DisasContext
*ctx
)
5402 #if defined(CONFIG_USER_ONLY)
5403 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5406 if (unlikely(!ctx
->mem_idx
)) {
5407 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5410 t0
= tcg_temp_new();
5411 gen_addr_reg_index(ctx
, t0
);
5412 gen_helper_rac(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5417 static void gen_rfsvc(DisasContext
*ctx
)
5419 #if defined(CONFIG_USER_ONLY)
5420 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5422 if (unlikely(!ctx
->mem_idx
)) {
5423 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5426 gen_helper_rfsvc(cpu_env
);
5427 gen_sync_exception(ctx
);
5431 /* svc is not implemented for now */
5433 /* POWER2 specific instructions */
5434 /* Quad manipulation (load/store two floats at a time) */
5437 static void gen_lfq(DisasContext
*ctx
)
5439 int rd
= rD(ctx
->opcode
);
5441 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5442 t0
= tcg_temp_new();
5443 gen_addr_imm_index(ctx
, t0
, 0);
5444 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5445 gen_addr_add(ctx
, t0
, t0
, 8);
5446 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5451 static void gen_lfqu(DisasContext
*ctx
)
5453 int ra
= rA(ctx
->opcode
);
5454 int rd
= rD(ctx
->opcode
);
5456 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5457 t0
= tcg_temp_new();
5458 t1
= tcg_temp_new();
5459 gen_addr_imm_index(ctx
, t0
, 0);
5460 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5461 gen_addr_add(ctx
, t1
, t0
, 8);
5462 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5464 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5470 static void gen_lfqux(DisasContext
*ctx
)
5472 int ra
= rA(ctx
->opcode
);
5473 int rd
= rD(ctx
->opcode
);
5474 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5476 t0
= tcg_temp_new();
5477 gen_addr_reg_index(ctx
, t0
);
5478 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5479 t1
= tcg_temp_new();
5480 gen_addr_add(ctx
, t1
, t0
, 8);
5481 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5484 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5489 static void gen_lfqx(DisasContext
*ctx
)
5491 int rd
= rD(ctx
->opcode
);
5493 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5494 t0
= tcg_temp_new();
5495 gen_addr_reg_index(ctx
, t0
);
5496 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5497 gen_addr_add(ctx
, t0
, t0
, 8);
5498 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5503 static void gen_stfq(DisasContext
*ctx
)
5505 int rd
= rD(ctx
->opcode
);
5507 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5508 t0
= tcg_temp_new();
5509 gen_addr_imm_index(ctx
, t0
, 0);
5510 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5511 gen_addr_add(ctx
, t0
, t0
, 8);
5512 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5517 static void gen_stfqu(DisasContext
*ctx
)
5519 int ra
= rA(ctx
->opcode
);
5520 int rd
= rD(ctx
->opcode
);
5522 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5523 t0
= tcg_temp_new();
5524 gen_addr_imm_index(ctx
, t0
, 0);
5525 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5526 t1
= tcg_temp_new();
5527 gen_addr_add(ctx
, t1
, t0
, 8);
5528 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5531 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5536 static void gen_stfqux(DisasContext
*ctx
)
5538 int ra
= rA(ctx
->opcode
);
5539 int rd
= rD(ctx
->opcode
);
5541 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5542 t0
= tcg_temp_new();
5543 gen_addr_reg_index(ctx
, t0
);
5544 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5545 t1
= tcg_temp_new();
5546 gen_addr_add(ctx
, t1
, t0
, 8);
5547 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5550 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5555 static void gen_stfqx(DisasContext
*ctx
)
5557 int rd
= rD(ctx
->opcode
);
5559 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5560 t0
= tcg_temp_new();
5561 gen_addr_reg_index(ctx
, t0
);
5562 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5563 gen_addr_add(ctx
, t0
, t0
, 8);
5564 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5568 /* BookE specific instructions */
5570 /* XXX: not implemented on 440 ? */
5571 static void gen_mfapidi(DisasContext
*ctx
)
5574 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5577 /* XXX: not implemented on 440 ? */
5578 static void gen_tlbiva(DisasContext
*ctx
)
5580 #if defined(CONFIG_USER_ONLY)
5581 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5584 if (unlikely(!ctx
->mem_idx
)) {
5585 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5588 t0
= tcg_temp_new();
5589 gen_addr_reg_index(ctx
, t0
);
5590 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5595 /* All 405 MAC instructions are translated here */
5596 static inline void gen_405_mulladd_insn(DisasContext
*ctx
, int opc2
, int opc3
,
5597 int ra
, int rb
, int rt
, int Rc
)
5601 t0
= tcg_temp_local_new();
5602 t1
= tcg_temp_local_new();
5604 switch (opc3
& 0x0D) {
5606 /* macchw - macchw. - macchwo - macchwo. */
5607 /* macchws - macchws. - macchwso - macchwso. */
5608 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5609 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5610 /* mulchw - mulchw. */
5611 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5612 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5613 tcg_gen_ext16s_tl(t1
, t1
);
5616 /* macchwu - macchwu. - macchwuo - macchwuo. */
5617 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5618 /* mulchwu - mulchwu. */
5619 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5620 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5621 tcg_gen_ext16u_tl(t1
, t1
);
5624 /* machhw - machhw. - machhwo - machhwo. */
5625 /* machhws - machhws. - machhwso - machhwso. */
5626 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5627 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5628 /* mulhhw - mulhhw. */
5629 tcg_gen_sari_tl(t0
, cpu_gpr
[ra
], 16);
5630 tcg_gen_ext16s_tl(t0
, t0
);
5631 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5632 tcg_gen_ext16s_tl(t1
, t1
);
5635 /* machhwu - machhwu. - machhwuo - machhwuo. */
5636 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5637 /* mulhhwu - mulhhwu. */
5638 tcg_gen_shri_tl(t0
, cpu_gpr
[ra
], 16);
5639 tcg_gen_ext16u_tl(t0
, t0
);
5640 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5641 tcg_gen_ext16u_tl(t1
, t1
);
5644 /* maclhw - maclhw. - maclhwo - maclhwo. */
5645 /* maclhws - maclhws. - maclhwso - maclhwso. */
5646 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5647 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5648 /* mullhw - mullhw. */
5649 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5650 tcg_gen_ext16s_tl(t1
, cpu_gpr
[rb
]);
5653 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5654 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5655 /* mullhwu - mullhwu. */
5656 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5657 tcg_gen_ext16u_tl(t1
, cpu_gpr
[rb
]);
5661 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5662 tcg_gen_mul_tl(t1
, t0
, t1
);
5664 /* nmultiply-and-accumulate (0x0E) */
5665 tcg_gen_sub_tl(t0
, cpu_gpr
[rt
], t1
);
5667 /* multiply-and-accumulate (0x0C) */
5668 tcg_gen_add_tl(t0
, cpu_gpr
[rt
], t1
);
5672 /* Check overflow and/or saturate */
5673 int l1
= gen_new_label();
5676 /* Start with XER OV disabled, the most likely case */
5677 tcg_gen_movi_tl(cpu_ov
, 0);
5681 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t1
);
5682 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
5683 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t0
);
5684 tcg_gen_brcondi_tl(TCG_COND_LT
, t1
, 0, l1
);
5687 tcg_gen_sari_tl(t0
, cpu_gpr
[rt
], 31);
5688 tcg_gen_xori_tl(t0
, t0
, 0x7fffffff);
5692 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
5695 tcg_gen_movi_tl(t0
, UINT32_MAX
);
5699 /* Check overflow */
5700 tcg_gen_movi_tl(cpu_ov
, 1);
5701 tcg_gen_movi_tl(cpu_so
, 1);
5704 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
5707 tcg_gen_mul_tl(cpu_gpr
[rt
], t0
, t1
);
5711 if (unlikely(Rc
) != 0) {
5713 gen_set_Rc0(ctx
, cpu_gpr
[rt
]);
5717 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5718 static void glue(gen_, name)(DisasContext *ctx) \
5720 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5721 rD(ctx->opcode), Rc(ctx->opcode)); \
5724 /* macchw - macchw. */
5725 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
5726 /* macchwo - macchwo. */
5727 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
5728 /* macchws - macchws. */
5729 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
5730 /* macchwso - macchwso. */
5731 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
5732 /* macchwsu - macchwsu. */
5733 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
5734 /* macchwsuo - macchwsuo. */
5735 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
5736 /* macchwu - macchwu. */
5737 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
5738 /* macchwuo - macchwuo. */
5739 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
5740 /* machhw - machhw. */
5741 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
5742 /* machhwo - machhwo. */
5743 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
5744 /* machhws - machhws. */
5745 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
5746 /* machhwso - machhwso. */
5747 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
5748 /* machhwsu - machhwsu. */
5749 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
5750 /* machhwsuo - machhwsuo. */
5751 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
5752 /* machhwu - machhwu. */
5753 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
5754 /* machhwuo - machhwuo. */
5755 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
5756 /* maclhw - maclhw. */
5757 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
5758 /* maclhwo - maclhwo. */
5759 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
5760 /* maclhws - maclhws. */
5761 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
5762 /* maclhwso - maclhwso. */
5763 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
5764 /* maclhwu - maclhwu. */
5765 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
5766 /* maclhwuo - maclhwuo. */
5767 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
5768 /* maclhwsu - maclhwsu. */
5769 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
5770 /* maclhwsuo - maclhwsuo. */
5771 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
5772 /* nmacchw - nmacchw. */
5773 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
5774 /* nmacchwo - nmacchwo. */
5775 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
5776 /* nmacchws - nmacchws. */
5777 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
5778 /* nmacchwso - nmacchwso. */
5779 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
5780 /* nmachhw - nmachhw. */
5781 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
5782 /* nmachhwo - nmachhwo. */
5783 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
5784 /* nmachhws - nmachhws. */
5785 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
5786 /* nmachhwso - nmachhwso. */
5787 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
5788 /* nmaclhw - nmaclhw. */
5789 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
5790 /* nmaclhwo - nmaclhwo. */
5791 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
5792 /* nmaclhws - nmaclhws. */
5793 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
5794 /* nmaclhwso - nmaclhwso. */
5795 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
5797 /* mulchw - mulchw. */
5798 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
5799 /* mulchwu - mulchwu. */
5800 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
5801 /* mulhhw - mulhhw. */
5802 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
5803 /* mulhhwu - mulhhwu. */
5804 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
5805 /* mullhw - mullhw. */
5806 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
5807 /* mullhwu - mullhwu. */
5808 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
5811 static void gen_mfdcr(DisasContext
*ctx
)
5813 #if defined(CONFIG_USER_ONLY)
5814 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5817 if (unlikely(!ctx
->mem_idx
)) {
5818 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5821 /* NIP cannot be restored if the memory exception comes from an helper */
5822 gen_update_nip(ctx
, ctx
->nip
- 4);
5823 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5824 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, dcrn
);
5825 tcg_temp_free(dcrn
);
5830 static void gen_mtdcr(DisasContext
*ctx
)
5832 #if defined(CONFIG_USER_ONLY)
5833 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5836 if (unlikely(!ctx
->mem_idx
)) {
5837 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5840 /* NIP cannot be restored if the memory exception comes from an helper */
5841 gen_update_nip(ctx
, ctx
->nip
- 4);
5842 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5843 gen_helper_store_dcr(cpu_env
, dcrn
, cpu_gpr
[rS(ctx
->opcode
)]);
5844 tcg_temp_free(dcrn
);
5849 /* XXX: not implemented on 440 ? */
5850 static void gen_mfdcrx(DisasContext
*ctx
)
5852 #if defined(CONFIG_USER_ONLY)
5853 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5855 if (unlikely(!ctx
->mem_idx
)) {
5856 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5859 /* NIP cannot be restored if the memory exception comes from an helper */
5860 gen_update_nip(ctx
, ctx
->nip
- 4);
5861 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5862 cpu_gpr
[rA(ctx
->opcode
)]);
5863 /* Note: Rc update flag set leads to undefined state of Rc0 */
5868 /* XXX: not implemented on 440 ? */
5869 static void gen_mtdcrx(DisasContext
*ctx
)
5871 #if defined(CONFIG_USER_ONLY)
5872 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5874 if (unlikely(!ctx
->mem_idx
)) {
5875 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5878 /* NIP cannot be restored if the memory exception comes from an helper */
5879 gen_update_nip(ctx
, ctx
->nip
- 4);
5880 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5881 cpu_gpr
[rS(ctx
->opcode
)]);
5882 /* Note: Rc update flag set leads to undefined state of Rc0 */
5886 /* mfdcrux (PPC 460) : user-mode access to DCR */
5887 static void gen_mfdcrux(DisasContext
*ctx
)
5889 /* NIP cannot be restored if the memory exception comes from an helper */
5890 gen_update_nip(ctx
, ctx
->nip
- 4);
5891 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5892 cpu_gpr
[rA(ctx
->opcode
)]);
5893 /* Note: Rc update flag set leads to undefined state of Rc0 */
5896 /* mtdcrux (PPC 460) : user-mode access to DCR */
5897 static void gen_mtdcrux(DisasContext
*ctx
)
5899 /* NIP cannot be restored if the memory exception comes from an helper */
5900 gen_update_nip(ctx
, ctx
->nip
- 4);
5901 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5902 cpu_gpr
[rS(ctx
->opcode
)]);
5903 /* Note: Rc update flag set leads to undefined state of Rc0 */
5907 static void gen_dccci(DisasContext
*ctx
)
5909 #if defined(CONFIG_USER_ONLY)
5910 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5912 if (unlikely(!ctx
->mem_idx
)) {
5913 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5916 /* interpreted as no-op */
5921 static void gen_dcread(DisasContext
*ctx
)
5923 #if defined(CONFIG_USER_ONLY)
5924 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5927 if (unlikely(!ctx
->mem_idx
)) {
5928 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5931 gen_set_access_type(ctx
, ACCESS_CACHE
);
5932 EA
= tcg_temp_new();
5933 gen_addr_reg_index(ctx
, EA
);
5934 val
= tcg_temp_new();
5935 gen_qemu_ld32u(ctx
, val
, EA
);
5937 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], EA
);
5943 static void gen_icbt_40x(DisasContext
*ctx
)
5945 /* interpreted as no-op */
5946 /* XXX: specification say this is treated as a load by the MMU
5947 * but does not generate any exception
5952 static void gen_iccci(DisasContext
*ctx
)
5954 #if defined(CONFIG_USER_ONLY)
5955 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5957 if (unlikely(!ctx
->mem_idx
)) {
5958 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5961 /* interpreted as no-op */
5966 static void gen_icread(DisasContext
*ctx
)
5968 #if defined(CONFIG_USER_ONLY)
5969 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5971 if (unlikely(!ctx
->mem_idx
)) {
5972 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5975 /* interpreted as no-op */
5979 /* rfci (mem_idx only) */
5980 static void gen_rfci_40x(DisasContext
*ctx
)
5982 #if defined(CONFIG_USER_ONLY)
5983 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5985 if (unlikely(!ctx
->mem_idx
)) {
5986 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5989 /* Restore CPU state */
5990 gen_helper_40x_rfci(cpu_env
);
5991 gen_sync_exception(ctx
);
5995 static void gen_rfci(DisasContext
*ctx
)
5997 #if defined(CONFIG_USER_ONLY)
5998 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6000 if (unlikely(!ctx
->mem_idx
)) {
6001 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6004 /* Restore CPU state */
6005 gen_helper_rfci(cpu_env
);
6006 gen_sync_exception(ctx
);
6010 /* BookE specific */
6012 /* XXX: not implemented on 440 ? */
6013 static void gen_rfdi(DisasContext
*ctx
)
6015 #if defined(CONFIG_USER_ONLY)
6016 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6018 if (unlikely(!ctx
->mem_idx
)) {
6019 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6022 /* Restore CPU state */
6023 gen_helper_rfdi(cpu_env
);
6024 gen_sync_exception(ctx
);
6028 /* XXX: not implemented on 440 ? */
6029 static void gen_rfmci(DisasContext
*ctx
)
6031 #if defined(CONFIG_USER_ONLY)
6032 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6034 if (unlikely(!ctx
->mem_idx
)) {
6035 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6038 /* Restore CPU state */
6039 gen_helper_rfmci(cpu_env
);
6040 gen_sync_exception(ctx
);
6044 /* TLB management - PowerPC 405 implementation */
6047 static void gen_tlbre_40x(DisasContext
*ctx
)
6049 #if defined(CONFIG_USER_ONLY)
6050 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6052 if (unlikely(!ctx
->mem_idx
)) {
6053 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6056 switch (rB(ctx
->opcode
)) {
6058 gen_helper_4xx_tlbre_hi(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6059 cpu_gpr
[rA(ctx
->opcode
)]);
6062 gen_helper_4xx_tlbre_lo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6063 cpu_gpr
[rA(ctx
->opcode
)]);
6066 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6072 /* tlbsx - tlbsx. */
6073 static void gen_tlbsx_40x(DisasContext
*ctx
)
6075 #if defined(CONFIG_USER_ONLY)
6076 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6079 if (unlikely(!ctx
->mem_idx
)) {
6080 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6083 t0
= tcg_temp_new();
6084 gen_addr_reg_index(ctx
, t0
);
6085 gen_helper_4xx_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
6087 if (Rc(ctx
->opcode
)) {
6088 int l1
= gen_new_label();
6089 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
6090 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
6091 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
6098 static void gen_tlbwe_40x(DisasContext
*ctx
)
6100 #if defined(CONFIG_USER_ONLY)
6101 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6103 if (unlikely(!ctx
->mem_idx
)) {
6104 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6107 switch (rB(ctx
->opcode
)) {
6109 gen_helper_4xx_tlbwe_hi(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6110 cpu_gpr
[rS(ctx
->opcode
)]);
6113 gen_helper_4xx_tlbwe_lo(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6114 cpu_gpr
[rS(ctx
->opcode
)]);
6117 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6123 /* TLB management - PowerPC 440 implementation */
6126 static void gen_tlbre_440(DisasContext
*ctx
)
6128 #if defined(CONFIG_USER_ONLY)
6129 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6131 if (unlikely(!ctx
->mem_idx
)) {
6132 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6135 switch (rB(ctx
->opcode
)) {
6140 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
6141 gen_helper_440_tlbre(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6142 t0
, cpu_gpr
[rA(ctx
->opcode
)]);
6143 tcg_temp_free_i32(t0
);
6147 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6153 /* tlbsx - tlbsx. */
6154 static void gen_tlbsx_440(DisasContext
*ctx
)
6156 #if defined(CONFIG_USER_ONLY)
6157 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6160 if (unlikely(!ctx
->mem_idx
)) {
6161 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6164 t0
= tcg_temp_new();
6165 gen_addr_reg_index(ctx
, t0
);
6166 gen_helper_440_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
6168 if (Rc(ctx
->opcode
)) {
6169 int l1
= gen_new_label();
6170 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
6171 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
6172 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
6179 static void gen_tlbwe_440(DisasContext
*ctx
)
6181 #if defined(CONFIG_USER_ONLY)
6182 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6184 if (unlikely(!ctx
->mem_idx
)) {
6185 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6188 switch (rB(ctx
->opcode
)) {
6193 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
6194 gen_helper_440_tlbwe(cpu_env
, t0
, cpu_gpr
[rA(ctx
->opcode
)],
6195 cpu_gpr
[rS(ctx
->opcode
)]);
6196 tcg_temp_free_i32(t0
);
6200 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6206 /* TLB management - PowerPC BookE 2.06 implementation */
6209 static void gen_tlbre_booke206(DisasContext
*ctx
)
6211 #if defined(CONFIG_USER_ONLY)
6212 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6214 if (unlikely(!ctx
->mem_idx
)) {
6215 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6219 gen_helper_booke206_tlbre(cpu_env
);
6223 /* tlbsx - tlbsx. */
6224 static void gen_tlbsx_booke206(DisasContext
*ctx
)
6226 #if defined(CONFIG_USER_ONLY)
6227 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6230 if (unlikely(!ctx
->mem_idx
)) {
6231 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6235 if (rA(ctx
->opcode
)) {
6236 t0
= tcg_temp_new();
6237 tcg_gen_mov_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)]);
6239 t0
= tcg_const_tl(0);
6242 tcg_gen_add_tl(t0
, t0
, cpu_gpr
[rB(ctx
->opcode
)]);
6243 gen_helper_booke206_tlbsx(cpu_env
, t0
);
6248 static void gen_tlbwe_booke206(DisasContext
*ctx
)
6250 #if defined(CONFIG_USER_ONLY)
6251 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6253 if (unlikely(!ctx
->mem_idx
)) {
6254 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6257 gen_update_nip(ctx
, ctx
->nip
- 4);
6258 gen_helper_booke206_tlbwe(cpu_env
);
6262 static void gen_tlbivax_booke206(DisasContext
*ctx
)
6264 #if defined(CONFIG_USER_ONLY)
6265 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6268 if (unlikely(!ctx
->mem_idx
)) {
6269 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6273 t0
= tcg_temp_new();
6274 gen_addr_reg_index(ctx
, t0
);
6276 gen_helper_booke206_tlbivax(cpu_env
, t0
);
6280 static void gen_tlbilx_booke206(DisasContext
*ctx
)
6282 #if defined(CONFIG_USER_ONLY)
6283 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6286 if (unlikely(!ctx
->mem_idx
)) {
6287 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6291 t0
= tcg_temp_new();
6292 gen_addr_reg_index(ctx
, t0
);
6294 switch((ctx
->opcode
>> 21) & 0x3) {
6296 gen_helper_booke206_tlbilx0(cpu_env
, t0
);
6299 gen_helper_booke206_tlbilx1(cpu_env
, t0
);
6302 gen_helper_booke206_tlbilx3(cpu_env
, t0
);
6305 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6315 static void gen_wrtee(DisasContext
*ctx
)
6317 #if defined(CONFIG_USER_ONLY)
6318 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6321 if (unlikely(!ctx
->mem_idx
)) {
6322 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6325 t0
= tcg_temp_new();
6326 tcg_gen_andi_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)], (1 << MSR_EE
));
6327 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6328 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
6330 /* Stop translation to have a chance to raise an exception
6331 * if we just set msr_ee to 1
6333 gen_stop_exception(ctx
);
6338 static void gen_wrteei(DisasContext
*ctx
)
6340 #if defined(CONFIG_USER_ONLY)
6341 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6343 if (unlikely(!ctx
->mem_idx
)) {
6344 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6347 if (ctx
->opcode
& 0x00008000) {
6348 tcg_gen_ori_tl(cpu_msr
, cpu_msr
, (1 << MSR_EE
));
6349 /* Stop translation to have a chance to raise an exception */
6350 gen_stop_exception(ctx
);
6352 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6357 /* PowerPC 440 specific instructions */
6360 static void gen_dlmzb(DisasContext
*ctx
)
6362 TCGv_i32 t0
= tcg_const_i32(Rc(ctx
->opcode
));
6363 gen_helper_dlmzb(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
6364 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
6365 tcg_temp_free_i32(t0
);
6368 /* mbar replaces eieio on 440 */
6369 static void gen_mbar(DisasContext
*ctx
)
6371 /* interpreted as no-op */
6374 /* msync replaces sync on 440 */
6375 static void gen_msync_4xx(DisasContext
*ctx
)
6377 /* interpreted as no-op */
6381 static void gen_icbt_440(DisasContext
*ctx
)
6383 /* interpreted as no-op */
6384 /* XXX: specification say this is treated as a load by the MMU
6385 * but does not generate any exception
6389 /* Embedded.Processor Control */
6391 static void gen_msgclr(DisasContext
*ctx
)
6393 #if defined(CONFIG_USER_ONLY)
6394 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6396 if (unlikely(ctx
->mem_idx
== 0)) {
6397 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6401 gen_helper_msgclr(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6405 static void gen_msgsnd(DisasContext
*ctx
)
6407 #if defined(CONFIG_USER_ONLY)
6408 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6410 if (unlikely(ctx
->mem_idx
== 0)) {
6411 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6415 gen_helper_msgsnd(cpu_gpr
[rB(ctx
->opcode
)]);
6419 /*** Altivec vector extension ***/
6420 /* Altivec registers moves */
6422 static inline TCGv_ptr
gen_avr_ptr(int reg
)
6424 TCGv_ptr r
= tcg_temp_new_ptr();
6425 tcg_gen_addi_ptr(r
, cpu_env
, offsetof(CPUPPCState
, avr
[reg
]));
6429 #define GEN_VR_LDX(name, opc2, opc3) \
6430 static void glue(gen_, name)(DisasContext *ctx) \
6433 if (unlikely(!ctx->altivec_enabled)) { \
6434 gen_exception(ctx, POWERPC_EXCP_VPU); \
6437 gen_set_access_type(ctx, ACCESS_INT); \
6438 EA = tcg_temp_new(); \
6439 gen_addr_reg_index(ctx, EA); \
6440 tcg_gen_andi_tl(EA, EA, ~0xf); \
6441 if (ctx->le_mode) { \
6442 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6443 tcg_gen_addi_tl(EA, EA, 8); \
6444 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6446 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6447 tcg_gen_addi_tl(EA, EA, 8); \
6448 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6450 tcg_temp_free(EA); \
6453 #define GEN_VR_STX(name, opc2, opc3) \
6454 static void gen_st##name(DisasContext *ctx) \
6457 if (unlikely(!ctx->altivec_enabled)) { \
6458 gen_exception(ctx, POWERPC_EXCP_VPU); \
6461 gen_set_access_type(ctx, ACCESS_INT); \
6462 EA = tcg_temp_new(); \
6463 gen_addr_reg_index(ctx, EA); \
6464 tcg_gen_andi_tl(EA, EA, ~0xf); \
6465 if (ctx->le_mode) { \
6466 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6467 tcg_gen_addi_tl(EA, EA, 8); \
6468 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6470 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6471 tcg_gen_addi_tl(EA, EA, 8); \
6472 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6474 tcg_temp_free(EA); \
6477 #define GEN_VR_LVE(name, opc2, opc3) \
6478 static void gen_lve##name(DisasContext *ctx) \
6482 if (unlikely(!ctx->altivec_enabled)) { \
6483 gen_exception(ctx, POWERPC_EXCP_VPU); \
6486 gen_set_access_type(ctx, ACCESS_INT); \
6487 EA = tcg_temp_new(); \
6488 gen_addr_reg_index(ctx, EA); \
6489 rs = gen_avr_ptr(rS(ctx->opcode)); \
6490 gen_helper_lve##name(cpu_env, rs, EA); \
6491 tcg_temp_free(EA); \
6492 tcg_temp_free_ptr(rs); \
6495 #define GEN_VR_STVE(name, opc2, opc3) \
6496 static void gen_stve##name(DisasContext *ctx) \
6500 if (unlikely(!ctx->altivec_enabled)) { \
6501 gen_exception(ctx, POWERPC_EXCP_VPU); \
6504 gen_set_access_type(ctx, ACCESS_INT); \
6505 EA = tcg_temp_new(); \
6506 gen_addr_reg_index(ctx, EA); \
6507 rs = gen_avr_ptr(rS(ctx->opcode)); \
6508 gen_helper_stve##name(cpu_env, rs, EA); \
6509 tcg_temp_free(EA); \
6510 tcg_temp_free_ptr(rs); \
6513 GEN_VR_LDX(lvx
, 0x07, 0x03);
6514 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
6515 GEN_VR_LDX(lvxl
, 0x07, 0x0B);
6517 GEN_VR_LVE(bx
, 0x07, 0x00);
6518 GEN_VR_LVE(hx
, 0x07, 0x01);
6519 GEN_VR_LVE(wx
, 0x07, 0x02);
6521 GEN_VR_STX(svx
, 0x07, 0x07);
6522 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
6523 GEN_VR_STX(svxl
, 0x07, 0x0F);
6525 GEN_VR_STVE(bx
, 0x07, 0x04);
6526 GEN_VR_STVE(hx
, 0x07, 0x05);
6527 GEN_VR_STVE(wx
, 0x07, 0x06);
6529 static void gen_lvsl(DisasContext
*ctx
)
6533 if (unlikely(!ctx
->altivec_enabled
)) {
6534 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6537 EA
= tcg_temp_new();
6538 gen_addr_reg_index(ctx
, EA
);
6539 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6540 gen_helper_lvsl(rd
, EA
);
6542 tcg_temp_free_ptr(rd
);
6545 static void gen_lvsr(DisasContext
*ctx
)
6549 if (unlikely(!ctx
->altivec_enabled
)) {
6550 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6553 EA
= tcg_temp_new();
6554 gen_addr_reg_index(ctx
, EA
);
6555 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6556 gen_helper_lvsr(rd
, EA
);
6558 tcg_temp_free_ptr(rd
);
6561 static void gen_mfvscr(DisasContext
*ctx
)
6564 if (unlikely(!ctx
->altivec_enabled
)) {
6565 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6568 tcg_gen_movi_i64(cpu_avrh
[rD(ctx
->opcode
)], 0);
6569 t
= tcg_temp_new_i32();
6570 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUPPCState
, vscr
));
6571 tcg_gen_extu_i32_i64(cpu_avrl
[rD(ctx
->opcode
)], t
);
6572 tcg_temp_free_i32(t
);
6575 static void gen_mtvscr(DisasContext
*ctx
)
6578 if (unlikely(!ctx
->altivec_enabled
)) {
6579 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6582 p
= gen_avr_ptr(rD(ctx
->opcode
));
6583 gen_helper_mtvscr(cpu_env
, p
);
6584 tcg_temp_free_ptr(p
);
6587 /* Logical operations */
6588 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
6589 static void glue(gen_, name)(DisasContext *ctx) \
6591 if (unlikely(!ctx->altivec_enabled)) { \
6592 gen_exception(ctx, POWERPC_EXCP_VPU); \
6595 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6596 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6599 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16);
6600 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17);
6601 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18);
6602 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19);
6603 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20);
6605 #define GEN_VXFORM(name, opc2, opc3) \
6606 static void glue(gen_, name)(DisasContext *ctx) \
6608 TCGv_ptr ra, rb, rd; \
6609 if (unlikely(!ctx->altivec_enabled)) { \
6610 gen_exception(ctx, POWERPC_EXCP_VPU); \
6613 ra = gen_avr_ptr(rA(ctx->opcode)); \
6614 rb = gen_avr_ptr(rB(ctx->opcode)); \
6615 rd = gen_avr_ptr(rD(ctx->opcode)); \
6616 gen_helper_##name (rd, ra, rb); \
6617 tcg_temp_free_ptr(ra); \
6618 tcg_temp_free_ptr(rb); \
6619 tcg_temp_free_ptr(rd); \
6622 #define GEN_VXFORM_ENV(name, opc2, opc3) \
6623 static void glue(gen_, name)(DisasContext *ctx) \
6625 TCGv_ptr ra, rb, rd; \
6626 if (unlikely(!ctx->altivec_enabled)) { \
6627 gen_exception(ctx, POWERPC_EXCP_VPU); \
6630 ra = gen_avr_ptr(rA(ctx->opcode)); \
6631 rb = gen_avr_ptr(rB(ctx->opcode)); \
6632 rd = gen_avr_ptr(rD(ctx->opcode)); \
6633 gen_helper_##name(cpu_env, rd, ra, rb); \
6634 tcg_temp_free_ptr(ra); \
6635 tcg_temp_free_ptr(rb); \
6636 tcg_temp_free_ptr(rd); \
6639 GEN_VXFORM(vaddubm
, 0, 0);
6640 GEN_VXFORM(vadduhm
, 0, 1);
6641 GEN_VXFORM(vadduwm
, 0, 2);
6642 GEN_VXFORM(vsububm
, 0, 16);
6643 GEN_VXFORM(vsubuhm
, 0, 17);
6644 GEN_VXFORM(vsubuwm
, 0, 18);
6645 GEN_VXFORM(vmaxub
, 1, 0);
6646 GEN_VXFORM(vmaxuh
, 1, 1);
6647 GEN_VXFORM(vmaxuw
, 1, 2);
6648 GEN_VXFORM(vmaxsb
, 1, 4);
6649 GEN_VXFORM(vmaxsh
, 1, 5);
6650 GEN_VXFORM(vmaxsw
, 1, 6);
6651 GEN_VXFORM(vminub
, 1, 8);
6652 GEN_VXFORM(vminuh
, 1, 9);
6653 GEN_VXFORM(vminuw
, 1, 10);
6654 GEN_VXFORM(vminsb
, 1, 12);
6655 GEN_VXFORM(vminsh
, 1, 13);
6656 GEN_VXFORM(vminsw
, 1, 14);
6657 GEN_VXFORM(vavgub
, 1, 16);
6658 GEN_VXFORM(vavguh
, 1, 17);
6659 GEN_VXFORM(vavguw
, 1, 18);
6660 GEN_VXFORM(vavgsb
, 1, 20);
6661 GEN_VXFORM(vavgsh
, 1, 21);
6662 GEN_VXFORM(vavgsw
, 1, 22);
6663 GEN_VXFORM(vmrghb
, 6, 0);
6664 GEN_VXFORM(vmrghh
, 6, 1);
6665 GEN_VXFORM(vmrghw
, 6, 2);
6666 GEN_VXFORM(vmrglb
, 6, 4);
6667 GEN_VXFORM(vmrglh
, 6, 5);
6668 GEN_VXFORM(vmrglw
, 6, 6);
6669 GEN_VXFORM(vmuloub
, 4, 0);
6670 GEN_VXFORM(vmulouh
, 4, 1);
6671 GEN_VXFORM(vmulosb
, 4, 4);
6672 GEN_VXFORM(vmulosh
, 4, 5);
6673 GEN_VXFORM(vmuleub
, 4, 8);
6674 GEN_VXFORM(vmuleuh
, 4, 9);
6675 GEN_VXFORM(vmulesb
, 4, 12);
6676 GEN_VXFORM(vmulesh
, 4, 13);
6677 GEN_VXFORM(vslb
, 2, 4);
6678 GEN_VXFORM(vslh
, 2, 5);
6679 GEN_VXFORM(vslw
, 2, 6);
6680 GEN_VXFORM(vsrb
, 2, 8);
6681 GEN_VXFORM(vsrh
, 2, 9);
6682 GEN_VXFORM(vsrw
, 2, 10);
6683 GEN_VXFORM(vsrab
, 2, 12);
6684 GEN_VXFORM(vsrah
, 2, 13);
6685 GEN_VXFORM(vsraw
, 2, 14);
6686 GEN_VXFORM(vslo
, 6, 16);
6687 GEN_VXFORM(vsro
, 6, 17);
6688 GEN_VXFORM(vaddcuw
, 0, 6);
6689 GEN_VXFORM(vsubcuw
, 0, 22);
6690 GEN_VXFORM_ENV(vaddubs
, 0, 8);
6691 GEN_VXFORM_ENV(vadduhs
, 0, 9);
6692 GEN_VXFORM_ENV(vadduws
, 0, 10);
6693 GEN_VXFORM_ENV(vaddsbs
, 0, 12);
6694 GEN_VXFORM_ENV(vaddshs
, 0, 13);
6695 GEN_VXFORM_ENV(vaddsws
, 0, 14);
6696 GEN_VXFORM_ENV(vsububs
, 0, 24);
6697 GEN_VXFORM_ENV(vsubuhs
, 0, 25);
6698 GEN_VXFORM_ENV(vsubuws
, 0, 26);
6699 GEN_VXFORM_ENV(vsubsbs
, 0, 28);
6700 GEN_VXFORM_ENV(vsubshs
, 0, 29);
6701 GEN_VXFORM_ENV(vsubsws
, 0, 30);
6702 GEN_VXFORM(vrlb
, 2, 0);
6703 GEN_VXFORM(vrlh
, 2, 1);
6704 GEN_VXFORM(vrlw
, 2, 2);
6705 GEN_VXFORM(vsl
, 2, 7);
6706 GEN_VXFORM(vsr
, 2, 11);
6707 GEN_VXFORM_ENV(vpkuhum
, 7, 0);
6708 GEN_VXFORM_ENV(vpkuwum
, 7, 1);
6709 GEN_VXFORM_ENV(vpkuhus
, 7, 2);
6710 GEN_VXFORM_ENV(vpkuwus
, 7, 3);
6711 GEN_VXFORM_ENV(vpkshus
, 7, 4);
6712 GEN_VXFORM_ENV(vpkswus
, 7, 5);
6713 GEN_VXFORM_ENV(vpkshss
, 7, 6);
6714 GEN_VXFORM_ENV(vpkswss
, 7, 7);
6715 GEN_VXFORM(vpkpx
, 7, 12);
6716 GEN_VXFORM_ENV(vsum4ubs
, 4, 24);
6717 GEN_VXFORM_ENV(vsum4sbs
, 4, 28);
6718 GEN_VXFORM_ENV(vsum4shs
, 4, 25);
6719 GEN_VXFORM_ENV(vsum2sws
, 4, 26);
6720 GEN_VXFORM_ENV(vsumsws
, 4, 30);
6721 GEN_VXFORM_ENV(vaddfp
, 5, 0);
6722 GEN_VXFORM_ENV(vsubfp
, 5, 1);
6723 GEN_VXFORM_ENV(vmaxfp
, 5, 16);
6724 GEN_VXFORM_ENV(vminfp
, 5, 17);
6726 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
6727 static void glue(gen_, name)(DisasContext *ctx) \
6729 TCGv_ptr ra, rb, rd; \
6730 if (unlikely(!ctx->altivec_enabled)) { \
6731 gen_exception(ctx, POWERPC_EXCP_VPU); \
6734 ra = gen_avr_ptr(rA(ctx->opcode)); \
6735 rb = gen_avr_ptr(rB(ctx->opcode)); \
6736 rd = gen_avr_ptr(rD(ctx->opcode)); \
6737 gen_helper_##opname(cpu_env, rd, ra, rb); \
6738 tcg_temp_free_ptr(ra); \
6739 tcg_temp_free_ptr(rb); \
6740 tcg_temp_free_ptr(rd); \
6743 #define GEN_VXRFORM(name, opc2, opc3) \
6744 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
6745 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
6747 GEN_VXRFORM(vcmpequb
, 3, 0)
6748 GEN_VXRFORM(vcmpequh
, 3, 1)
6749 GEN_VXRFORM(vcmpequw
, 3, 2)
6750 GEN_VXRFORM(vcmpgtsb
, 3, 12)
6751 GEN_VXRFORM(vcmpgtsh
, 3, 13)
6752 GEN_VXRFORM(vcmpgtsw
, 3, 14)
6753 GEN_VXRFORM(vcmpgtub
, 3, 8)
6754 GEN_VXRFORM(vcmpgtuh
, 3, 9)
6755 GEN_VXRFORM(vcmpgtuw
, 3, 10)
6756 GEN_VXRFORM(vcmpeqfp
, 3, 3)
6757 GEN_VXRFORM(vcmpgefp
, 3, 7)
6758 GEN_VXRFORM(vcmpgtfp
, 3, 11)
6759 GEN_VXRFORM(vcmpbfp
, 3, 15)
6761 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
6762 static void glue(gen_, name)(DisasContext *ctx) \
6766 if (unlikely(!ctx->altivec_enabled)) { \
6767 gen_exception(ctx, POWERPC_EXCP_VPU); \
6770 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6771 rd = gen_avr_ptr(rD(ctx->opcode)); \
6772 gen_helper_##name (rd, simm); \
6773 tcg_temp_free_i32(simm); \
6774 tcg_temp_free_ptr(rd); \
6777 GEN_VXFORM_SIMM(vspltisb
, 6, 12);
6778 GEN_VXFORM_SIMM(vspltish
, 6, 13);
6779 GEN_VXFORM_SIMM(vspltisw
, 6, 14);
6781 #define GEN_VXFORM_NOA(name, opc2, opc3) \
6782 static void glue(gen_, name)(DisasContext *ctx) \
6785 if (unlikely(!ctx->altivec_enabled)) { \
6786 gen_exception(ctx, POWERPC_EXCP_VPU); \
6789 rb = gen_avr_ptr(rB(ctx->opcode)); \
6790 rd = gen_avr_ptr(rD(ctx->opcode)); \
6791 gen_helper_##name (rd, rb); \
6792 tcg_temp_free_ptr(rb); \
6793 tcg_temp_free_ptr(rd); \
6796 #define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \
6797 static void glue(gen_, name)(DisasContext *ctx) \
6801 if (unlikely(!ctx->altivec_enabled)) { \
6802 gen_exception(ctx, POWERPC_EXCP_VPU); \
6805 rb = gen_avr_ptr(rB(ctx->opcode)); \
6806 rd = gen_avr_ptr(rD(ctx->opcode)); \
6807 gen_helper_##name(cpu_env, rd, rb); \
6808 tcg_temp_free_ptr(rb); \
6809 tcg_temp_free_ptr(rd); \
6812 GEN_VXFORM_NOA(vupkhsb
, 7, 8);
6813 GEN_VXFORM_NOA(vupkhsh
, 7, 9);
6814 GEN_VXFORM_NOA(vupklsb
, 7, 10);
6815 GEN_VXFORM_NOA(vupklsh
, 7, 11);
6816 GEN_VXFORM_NOA(vupkhpx
, 7, 13);
6817 GEN_VXFORM_NOA(vupklpx
, 7, 15);
6818 GEN_VXFORM_NOA_ENV(vrefp
, 5, 4);
6819 GEN_VXFORM_NOA_ENV(vrsqrtefp
, 5, 5);
6820 GEN_VXFORM_NOA_ENV(vexptefp
, 5, 6);
6821 GEN_VXFORM_NOA_ENV(vlogefp
, 5, 7);
6822 GEN_VXFORM_NOA_ENV(vrfim
, 5, 8);
6823 GEN_VXFORM_NOA_ENV(vrfin
, 5, 9);
6824 GEN_VXFORM_NOA_ENV(vrfip
, 5, 10);
6825 GEN_VXFORM_NOA_ENV(vrfiz
, 5, 11);
6827 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
6828 static void glue(gen_, name)(DisasContext *ctx) \
6832 if (unlikely(!ctx->altivec_enabled)) { \
6833 gen_exception(ctx, POWERPC_EXCP_VPU); \
6836 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6837 rd = gen_avr_ptr(rD(ctx->opcode)); \
6838 gen_helper_##name (rd, simm); \
6839 tcg_temp_free_i32(simm); \
6840 tcg_temp_free_ptr(rd); \
6843 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
6844 static void glue(gen_, name)(DisasContext *ctx) \
6848 if (unlikely(!ctx->altivec_enabled)) { \
6849 gen_exception(ctx, POWERPC_EXCP_VPU); \
6852 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
6853 rb = gen_avr_ptr(rB(ctx->opcode)); \
6854 rd = gen_avr_ptr(rD(ctx->opcode)); \
6855 gen_helper_##name (rd, rb, uimm); \
6856 tcg_temp_free_i32(uimm); \
6857 tcg_temp_free_ptr(rb); \
6858 tcg_temp_free_ptr(rd); \
6861 #define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \
6862 static void glue(gen_, name)(DisasContext *ctx) \
6867 if (unlikely(!ctx->altivec_enabled)) { \
6868 gen_exception(ctx, POWERPC_EXCP_VPU); \
6871 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
6872 rb = gen_avr_ptr(rB(ctx->opcode)); \
6873 rd = gen_avr_ptr(rD(ctx->opcode)); \
6874 gen_helper_##name(cpu_env, rd, rb, uimm); \
6875 tcg_temp_free_i32(uimm); \
6876 tcg_temp_free_ptr(rb); \
6877 tcg_temp_free_ptr(rd); \
6880 GEN_VXFORM_UIMM(vspltb
, 6, 8);
6881 GEN_VXFORM_UIMM(vsplth
, 6, 9);
6882 GEN_VXFORM_UIMM(vspltw
, 6, 10);
6883 GEN_VXFORM_UIMM_ENV(vcfux
, 5, 12);
6884 GEN_VXFORM_UIMM_ENV(vcfsx
, 5, 13);
6885 GEN_VXFORM_UIMM_ENV(vctuxs
, 5, 14);
6886 GEN_VXFORM_UIMM_ENV(vctsxs
, 5, 15);
6888 static void gen_vsldoi(DisasContext
*ctx
)
6890 TCGv_ptr ra
, rb
, rd
;
6892 if (unlikely(!ctx
->altivec_enabled
)) {
6893 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6896 ra
= gen_avr_ptr(rA(ctx
->opcode
));
6897 rb
= gen_avr_ptr(rB(ctx
->opcode
));
6898 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6899 sh
= tcg_const_i32(VSH(ctx
->opcode
));
6900 gen_helper_vsldoi (rd
, ra
, rb
, sh
);
6901 tcg_temp_free_ptr(ra
);
6902 tcg_temp_free_ptr(rb
);
6903 tcg_temp_free_ptr(rd
);
6904 tcg_temp_free_i32(sh
);
6907 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
6908 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
6910 TCGv_ptr ra, rb, rc, rd; \
6911 if (unlikely(!ctx->altivec_enabled)) { \
6912 gen_exception(ctx, POWERPC_EXCP_VPU); \
6915 ra = gen_avr_ptr(rA(ctx->opcode)); \
6916 rb = gen_avr_ptr(rB(ctx->opcode)); \
6917 rc = gen_avr_ptr(rC(ctx->opcode)); \
6918 rd = gen_avr_ptr(rD(ctx->opcode)); \
6919 if (Rc(ctx->opcode)) { \
6920 gen_helper_##name1(cpu_env, rd, ra, rb, rc); \
6922 gen_helper_##name0(cpu_env, rd, ra, rb, rc); \
6924 tcg_temp_free_ptr(ra); \
6925 tcg_temp_free_ptr(rb); \
6926 tcg_temp_free_ptr(rc); \
6927 tcg_temp_free_ptr(rd); \
6930 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16)
6932 static void gen_vmladduhm(DisasContext
*ctx
)
6934 TCGv_ptr ra
, rb
, rc
, rd
;
6935 if (unlikely(!ctx
->altivec_enabled
)) {
6936 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6939 ra
= gen_avr_ptr(rA(ctx
->opcode
));
6940 rb
= gen_avr_ptr(rB(ctx
->opcode
));
6941 rc
= gen_avr_ptr(rC(ctx
->opcode
));
6942 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6943 gen_helper_vmladduhm(rd
, ra
, rb
, rc
);
6944 tcg_temp_free_ptr(ra
);
6945 tcg_temp_free_ptr(rb
);
6946 tcg_temp_free_ptr(rc
);
6947 tcg_temp_free_ptr(rd
);
6950 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18)
6951 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19)
6952 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20)
6953 GEN_VAFORM_PAIRED(vsel
, vperm
, 21)
6954 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23)
6956 /*** SPE extension ***/
6957 /* Register moves */
6960 static inline void gen_evmra(DisasContext
*ctx
)
6963 if (unlikely(!ctx
->spe_enabled
)) {
6964 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
6968 #if defined(TARGET_PPC64)
6970 tcg_gen_mov_i64(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6973 tcg_gen_st_i64(cpu_gpr
[rA(ctx
->opcode
)],
6975 offsetof(CPUPPCState
, spe_acc
));
6977 TCGv_i64 tmp
= tcg_temp_new_i64();
6979 /* tmp := rA_lo + rA_hi << 32 */
6980 tcg_gen_concat_i32_i64(tmp
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6982 /* spe_acc := tmp */
6983 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
6984 tcg_temp_free_i64(tmp
);
6987 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6988 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6992 static inline void gen_load_gpr64(TCGv_i64 t
, int reg
)
6994 #if defined(TARGET_PPC64)
6995 tcg_gen_mov_i64(t
, cpu_gpr
[reg
]);
6997 tcg_gen_concat_i32_i64(t
, cpu_gpr
[reg
], cpu_gprh
[reg
]);
7001 static inline void gen_store_gpr64(int reg
, TCGv_i64 t
)
7003 #if defined(TARGET_PPC64)
7004 tcg_gen_mov_i64(cpu_gpr
[reg
], t
);
7006 TCGv_i64 tmp
= tcg_temp_new_i64();
7007 tcg_gen_trunc_i64_i32(cpu_gpr
[reg
], t
);
7008 tcg_gen_shri_i64(tmp
, t
, 32);
7009 tcg_gen_trunc_i64_i32(cpu_gprh
[reg
], tmp
);
7010 tcg_temp_free_i64(tmp
);
7014 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
7015 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
7017 if (Rc(ctx->opcode)) \
7023 /* Handler for undefined SPE opcodes */
7024 static inline void gen_speundef(DisasContext
*ctx
)
7026 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
7030 #if defined(TARGET_PPC64)
7031 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
7032 static inline void gen_##name(DisasContext *ctx) \
7034 if (unlikely(!ctx->spe_enabled)) { \
7035 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7038 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7039 cpu_gpr[rB(ctx->opcode)]); \
7042 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
7043 static inline void gen_##name(DisasContext *ctx) \
7045 if (unlikely(!ctx->spe_enabled)) { \
7046 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7049 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7050 cpu_gpr[rB(ctx->opcode)]); \
7051 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7052 cpu_gprh[rB(ctx->opcode)]); \
7056 GEN_SPEOP_LOGIC2(evand
, tcg_gen_and_tl
);
7057 GEN_SPEOP_LOGIC2(evandc
, tcg_gen_andc_tl
);
7058 GEN_SPEOP_LOGIC2(evxor
, tcg_gen_xor_tl
);
7059 GEN_SPEOP_LOGIC2(evor
, tcg_gen_or_tl
);
7060 GEN_SPEOP_LOGIC2(evnor
, tcg_gen_nor_tl
);
7061 GEN_SPEOP_LOGIC2(eveqv
, tcg_gen_eqv_tl
);
7062 GEN_SPEOP_LOGIC2(evorc
, tcg_gen_orc_tl
);
7063 GEN_SPEOP_LOGIC2(evnand
, tcg_gen_nand_tl
);
7065 /* SPE logic immediate */
7066 #if defined(TARGET_PPC64)
7067 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
7068 static inline void gen_##name(DisasContext *ctx) \
7070 if (unlikely(!ctx->spe_enabled)) { \
7071 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7074 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7075 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7076 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7077 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7078 tcg_opi(t0, t0, rB(ctx->opcode)); \
7079 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7080 tcg_gen_trunc_i64_i32(t1, t2); \
7081 tcg_temp_free_i64(t2); \
7082 tcg_opi(t1, t1, rB(ctx->opcode)); \
7083 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7084 tcg_temp_free_i32(t0); \
7085 tcg_temp_free_i32(t1); \
7088 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
7089 static inline void gen_##name(DisasContext *ctx) \
7091 if (unlikely(!ctx->spe_enabled)) { \
7092 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7095 tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7097 tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7101 GEN_SPEOP_TCG_LOGIC_IMM2(evslwi
, tcg_gen_shli_i32
);
7102 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu
, tcg_gen_shri_i32
);
7103 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis
, tcg_gen_sari_i32
);
7104 GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi
, tcg_gen_rotli_i32
);
7106 /* SPE arithmetic */
7107 #if defined(TARGET_PPC64)
7108 #define GEN_SPEOP_ARITH1(name, tcg_op) \
7109 static inline void gen_##name(DisasContext *ctx) \
7111 if (unlikely(!ctx->spe_enabled)) { \
7112 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7115 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7116 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7117 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7118 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7120 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7121 tcg_gen_trunc_i64_i32(t1, t2); \
7122 tcg_temp_free_i64(t2); \
7124 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7125 tcg_temp_free_i32(t0); \
7126 tcg_temp_free_i32(t1); \
7129 #define GEN_SPEOP_ARITH1(name, tcg_op) \
7130 static inline void gen_##name(DisasContext *ctx) \
7132 if (unlikely(!ctx->spe_enabled)) { \
7133 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7136 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
7137 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
7141 static inline void gen_op_evabs(TCGv_i32 ret
, TCGv_i32 arg1
)
7143 int l1
= gen_new_label();
7144 int l2
= gen_new_label();
7146 tcg_gen_brcondi_i32(TCG_COND_GE
, arg1
, 0, l1
);
7147 tcg_gen_neg_i32(ret
, arg1
);
7150 tcg_gen_mov_i32(ret
, arg1
);
7153 GEN_SPEOP_ARITH1(evabs
, gen_op_evabs
);
7154 GEN_SPEOP_ARITH1(evneg
, tcg_gen_neg_i32
);
7155 GEN_SPEOP_ARITH1(evextsb
, tcg_gen_ext8s_i32
);
7156 GEN_SPEOP_ARITH1(evextsh
, tcg_gen_ext16s_i32
);
7157 static inline void gen_op_evrndw(TCGv_i32 ret
, TCGv_i32 arg1
)
7159 tcg_gen_addi_i32(ret
, arg1
, 0x8000);
7160 tcg_gen_ext16u_i32(ret
, ret
);
7162 GEN_SPEOP_ARITH1(evrndw
, gen_op_evrndw
);
7163 GEN_SPEOP_ARITH1(evcntlsw
, gen_helper_cntlsw32
);
7164 GEN_SPEOP_ARITH1(evcntlzw
, gen_helper_cntlzw32
);
7166 #if defined(TARGET_PPC64)
7167 #define GEN_SPEOP_ARITH2(name, tcg_op) \
7168 static inline void gen_##name(DisasContext *ctx) \
7170 if (unlikely(!ctx->spe_enabled)) { \
7171 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7174 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7175 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7176 TCGv_i32 t2 = tcg_temp_local_new_i32(); \
7177 TCGv_i64 t3 = tcg_temp_local_new_i64(); \
7178 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7179 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
7180 tcg_op(t0, t0, t2); \
7181 tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
7182 tcg_gen_trunc_i64_i32(t1, t3); \
7183 tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
7184 tcg_gen_trunc_i64_i32(t2, t3); \
7185 tcg_temp_free_i64(t3); \
7186 tcg_op(t1, t1, t2); \
7187 tcg_temp_free_i32(t2); \
7188 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7189 tcg_temp_free_i32(t0); \
7190 tcg_temp_free_i32(t1); \
7193 #define GEN_SPEOP_ARITH2(name, tcg_op) \
7194 static inline void gen_##name(DisasContext *ctx) \
7196 if (unlikely(!ctx->spe_enabled)) { \
7197 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7200 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7201 cpu_gpr[rB(ctx->opcode)]); \
7202 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
7203 cpu_gprh[rB(ctx->opcode)]); \
7207 static inline void gen_op_evsrwu(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7212 l1
= gen_new_label();
7213 l2
= gen_new_label();
7214 t0
= tcg_temp_local_new_i32();
7215 /* No error here: 6 bits are used */
7216 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
7217 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
7218 tcg_gen_shr_i32(ret
, arg1
, t0
);
7221 tcg_gen_movi_i32(ret
, 0);
7223 tcg_temp_free_i32(t0
);
7225 GEN_SPEOP_ARITH2(evsrwu
, gen_op_evsrwu
);
7226 static inline void gen_op_evsrws(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7231 l1
= gen_new_label();
7232 l2
= gen_new_label();
7233 t0
= tcg_temp_local_new_i32();
7234 /* No error here: 6 bits are used */
7235 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
7236 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
7237 tcg_gen_sar_i32(ret
, arg1
, t0
);
7240 tcg_gen_movi_i32(ret
, 0);
7242 tcg_temp_free_i32(t0
);
7244 GEN_SPEOP_ARITH2(evsrws
, gen_op_evsrws
);
7245 static inline void gen_op_evslw(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7250 l1
= gen_new_label();
7251 l2
= gen_new_label();
7252 t0
= tcg_temp_local_new_i32();
7253 /* No error here: 6 bits are used */
7254 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
7255 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
7256 tcg_gen_shl_i32(ret
, arg1
, t0
);
7259 tcg_gen_movi_i32(ret
, 0);
7261 tcg_temp_free_i32(t0
);
7263 GEN_SPEOP_ARITH2(evslw
, gen_op_evslw
);
7264 static inline void gen_op_evrlw(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7266 TCGv_i32 t0
= tcg_temp_new_i32();
7267 tcg_gen_andi_i32(t0
, arg2
, 0x1F);
7268 tcg_gen_rotl_i32(ret
, arg1
, t0
);
7269 tcg_temp_free_i32(t0
);
7271 GEN_SPEOP_ARITH2(evrlw
, gen_op_evrlw
);
7272 static inline void gen_evmergehi(DisasContext
*ctx
)
7274 if (unlikely(!ctx
->spe_enabled
)) {
7275 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7278 #if defined(TARGET_PPC64)
7279 TCGv t0
= tcg_temp_new();
7280 TCGv t1
= tcg_temp_new();
7281 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
7282 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
7283 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7287 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7288 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7291 GEN_SPEOP_ARITH2(evaddw
, tcg_gen_add_i32
);
7292 static inline void gen_op_evsubf(TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
7294 tcg_gen_sub_i32(ret
, arg2
, arg1
);
7296 GEN_SPEOP_ARITH2(evsubfw
, gen_op_evsubf
);
7298 /* SPE arithmetic immediate */
7299 #if defined(TARGET_PPC64)
7300 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
7301 static inline void gen_##name(DisasContext *ctx) \
7303 if (unlikely(!ctx->spe_enabled)) { \
7304 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7307 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7308 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7309 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7310 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
7311 tcg_op(t0, t0, rA(ctx->opcode)); \
7312 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
7313 tcg_gen_trunc_i64_i32(t1, t2); \
7314 tcg_temp_free_i64(t2); \
7315 tcg_op(t1, t1, rA(ctx->opcode)); \
7316 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
7317 tcg_temp_free_i32(t0); \
7318 tcg_temp_free_i32(t1); \
7321 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
7322 static inline void gen_##name(DisasContext *ctx) \
7324 if (unlikely(!ctx->spe_enabled)) { \
7325 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7328 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
7330 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
7334 GEN_SPEOP_ARITH_IMM2(evaddiw
, tcg_gen_addi_i32
);
7335 GEN_SPEOP_ARITH_IMM2(evsubifw
, tcg_gen_subi_i32
);
7337 /* SPE comparison */
7338 #if defined(TARGET_PPC64)
7339 #define GEN_SPEOP_COMP(name, tcg_cond) \
7340 static inline void gen_##name(DisasContext *ctx) \
7342 if (unlikely(!ctx->spe_enabled)) { \
7343 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7346 int l1 = gen_new_label(); \
7347 int l2 = gen_new_label(); \
7348 int l3 = gen_new_label(); \
7349 int l4 = gen_new_label(); \
7350 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
7351 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
7352 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
7353 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7354 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
7355 tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
7356 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
7358 gen_set_label(l1); \
7359 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
7360 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
7361 gen_set_label(l2); \
7362 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
7363 tcg_gen_trunc_i64_i32(t0, t2); \
7364 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
7365 tcg_gen_trunc_i64_i32(t1, t2); \
7366 tcg_temp_free_i64(t2); \
7367 tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
7368 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7369 ~(CRF_CH | CRF_CH_AND_CL)); \
7371 gen_set_label(l3); \
7372 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7373 CRF_CH | CRF_CH_OR_CL); \
7374 gen_set_label(l4); \
7375 tcg_temp_free_i32(t0); \
7376 tcg_temp_free_i32(t1); \
7379 #define GEN_SPEOP_COMP(name, tcg_cond) \
7380 static inline void gen_##name(DisasContext *ctx) \
7382 if (unlikely(!ctx->spe_enabled)) { \
7383 gen_exception(ctx, POWERPC_EXCP_SPEU); \
7386 int l1 = gen_new_label(); \
7387 int l2 = gen_new_label(); \
7388 int l3 = gen_new_label(); \
7389 int l4 = gen_new_label(); \
7391 tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
7392 cpu_gpr[rB(ctx->opcode)], l1); \
7393 tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
7395 gen_set_label(l1); \
7396 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
7397 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
7398 gen_set_label(l2); \
7399 tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
7400 cpu_gprh[rB(ctx->opcode)], l3); \
7401 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7402 ~(CRF_CH | CRF_CH_AND_CL)); \
7404 gen_set_label(l3); \
7405 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
7406 CRF_CH | CRF_CH_OR_CL); \
7407 gen_set_label(l4); \
7410 GEN_SPEOP_COMP(evcmpgtu
, TCG_COND_GTU
);
7411 GEN_SPEOP_COMP(evcmpgts
, TCG_COND_GT
);
7412 GEN_SPEOP_COMP(evcmpltu
, TCG_COND_LTU
);
7413 GEN_SPEOP_COMP(evcmplts
, TCG_COND_LT
);
7414 GEN_SPEOP_COMP(evcmpeq
, TCG_COND_EQ
);
7417 static inline void gen_brinc(DisasContext
*ctx
)
7419 /* Note: brinc is usable even if SPE is disabled */
7420 gen_helper_brinc(cpu_gpr
[rD(ctx
->opcode
)],
7421 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7423 static inline void gen_evmergelo(DisasContext
*ctx
)
7425 if (unlikely(!ctx
->spe_enabled
)) {
7426 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7429 #if defined(TARGET_PPC64)
7430 TCGv t0
= tcg_temp_new();
7431 TCGv t1
= tcg_temp_new();
7432 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
7433 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
7434 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7438 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7439 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7442 static inline void gen_evmergehilo(DisasContext
*ctx
)
7444 if (unlikely(!ctx
->spe_enabled
)) {
7445 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7448 #if defined(TARGET_PPC64)
7449 TCGv t0
= tcg_temp_new();
7450 TCGv t1
= tcg_temp_new();
7451 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
7452 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
7453 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7457 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7458 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7461 static inline void gen_evmergelohi(DisasContext
*ctx
)
7463 if (unlikely(!ctx
->spe_enabled
)) {
7464 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7467 #if defined(TARGET_PPC64)
7468 TCGv t0
= tcg_temp_new();
7469 TCGv t1
= tcg_temp_new();
7470 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
7471 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
7472 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
7476 if (rD(ctx
->opcode
) == rA(ctx
->opcode
)) {
7477 TCGv_i32 tmp
= tcg_temp_new_i32();
7478 tcg_gen_mov_i32(tmp
, cpu_gpr
[rA(ctx
->opcode
)]);
7479 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7480 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], tmp
);
7481 tcg_temp_free_i32(tmp
);
7483 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7484 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7488 static inline void gen_evsplati(DisasContext
*ctx
)
7490 uint64_t imm
= ((int32_t)(rA(ctx
->opcode
) << 27)) >> 27;
7492 #if defined(TARGET_PPC64)
7493 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
7495 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
7496 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
7499 static inline void gen_evsplatfi(DisasContext
*ctx
)
7501 uint64_t imm
= rA(ctx
->opcode
) << 27;
7503 #if defined(TARGET_PPC64)
7504 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
7506 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
7507 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
7511 static inline void gen_evsel(DisasContext
*ctx
)
7513 int l1
= gen_new_label();
7514 int l2
= gen_new_label();
7515 int l3
= gen_new_label();
7516 int l4
= gen_new_label();
7517 TCGv_i32 t0
= tcg_temp_local_new_i32();
7518 #if defined(TARGET_PPC64)
7519 TCGv t1
= tcg_temp_local_new();
7520 TCGv t2
= tcg_temp_local_new();
7522 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 3);
7523 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
7524 #if defined(TARGET_PPC64)
7525 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
7527 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7531 #if defined(TARGET_PPC64)
7532 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
7534 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7537 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 2);
7538 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l3
);
7539 #if defined(TARGET_PPC64)
7540 tcg_gen_ext32u_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)]);
7542 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7546 #if defined(TARGET_PPC64)
7547 tcg_gen_ext32u_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)]);
7549 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7552 tcg_temp_free_i32(t0
);
7553 #if defined(TARGET_PPC64)
7554 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
, t2
);
7560 static void gen_evsel0(DisasContext
*ctx
)
7565 static void gen_evsel1(DisasContext
*ctx
)
7570 static void gen_evsel2(DisasContext
*ctx
)
7575 static void gen_evsel3(DisasContext
*ctx
)
7582 static inline void gen_evmwumi(DisasContext
*ctx
)
7586 if (unlikely(!ctx
->spe_enabled
)) {
7587 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7591 t0
= tcg_temp_new_i64();
7592 t1
= tcg_temp_new_i64();
7594 /* t0 := rA; t1 := rB */
7595 #if defined(TARGET_PPC64)
7596 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7597 tcg_gen_ext32u_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7599 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7600 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7603 tcg_gen_mul_i64(t0
, t0
, t1
); /* t0 := rA * rB */
7605 gen_store_gpr64(rD(ctx
->opcode
), t0
); /* rD := t0 */
7607 tcg_temp_free_i64(t0
);
7608 tcg_temp_free_i64(t1
);
7611 static inline void gen_evmwumia(DisasContext
*ctx
)
7615 if (unlikely(!ctx
->spe_enabled
)) {
7616 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7620 gen_evmwumi(ctx
); /* rD := rA * rB */
7622 tmp
= tcg_temp_new_i64();
7625 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7626 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7627 tcg_temp_free_i64(tmp
);
7630 static inline void gen_evmwumiaa(DisasContext
*ctx
)
7635 if (unlikely(!ctx
->spe_enabled
)) {
7636 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7640 gen_evmwumi(ctx
); /* rD := rA * rB */
7642 acc
= tcg_temp_new_i64();
7643 tmp
= tcg_temp_new_i64();
7646 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7649 tcg_gen_ld_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7651 /* acc := tmp + acc */
7652 tcg_gen_add_i64(acc
, acc
, tmp
);
7655 tcg_gen_st_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7658 gen_store_gpr64(rD(ctx
->opcode
), acc
);
7660 tcg_temp_free_i64(acc
);
7661 tcg_temp_free_i64(tmp
);
7664 static inline void gen_evmwsmi(DisasContext
*ctx
)
7668 if (unlikely(!ctx
->spe_enabled
)) {
7669 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
7673 t0
= tcg_temp_new_i64();
7674 t1
= tcg_temp_new_i64();
7676 /* t0 := rA; t1 := rB */
7677 #if defined(TARGET_PPC64)
7678 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7679 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7681 tcg_gen_ext_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7682 tcg_gen_ext_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
7685 tcg_gen_mul_i64(t0
, t0
, t1
); /* t0 := rA * rB */
7687 gen_store_gpr64(rD(ctx
->opcode
), t0
); /* rD := t0 */
7689 tcg_temp_free_i64(t0
);
7690 tcg_temp_free_i64(t1
);
7693 static inline void gen_evmwsmia(DisasContext
*ctx
)
7697 gen_evmwsmi(ctx
); /* rD := rA * rB */
7699 tmp
= tcg_temp_new_i64();
7702 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7703 tcg_gen_st_i64(tmp
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7705 tcg_temp_free_i64(tmp
);
7708 static inline void gen_evmwsmiaa(DisasContext
*ctx
)
7710 TCGv_i64 acc
= tcg_temp_new_i64();
7711 TCGv_i64 tmp
= tcg_temp_new_i64();
7713 gen_evmwsmi(ctx
); /* rD := rA * rB */
7715 acc
= tcg_temp_new_i64();
7716 tmp
= tcg_temp_new_i64();
7719 gen_load_gpr64(tmp
, rD(ctx
->opcode
));
7722 tcg_gen_ld_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7724 /* acc := tmp + acc */
7725 tcg_gen_add_i64(acc
, acc
, tmp
);
7728 tcg_gen_st_i64(acc
, cpu_env
, offsetof(CPUPPCState
, spe_acc
));
7731 gen_store_gpr64(rD(ctx
->opcode
), acc
);
7733 tcg_temp_free_i64(acc
);
7734 tcg_temp_free_i64(tmp
);
7737 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7738 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7739 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7740 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7741 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
7742 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
7743 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
); ////
7744 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE
); //
7745 GEN_SPE(evmra
, speundef
, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE
);
7746 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
); ////
7747 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7748 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7749 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7750 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
7751 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
7752 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
7753 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
); ////
7754 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7755 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7756 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE
);
7757 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
); ////
7758 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
7759 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE
); //
7760 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE
);
7761 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7762 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE
); ////
7763 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE
); ////
7764 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE
); ////
7765 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE
); ////
7767 /* SPE load and stores */
7768 static inline void gen_addr_spe_imm_index(DisasContext
*ctx
, TCGv EA
, int sh
)
7770 target_ulong uimm
= rB(ctx
->opcode
);
7772 if (rA(ctx
->opcode
) == 0) {
7773 tcg_gen_movi_tl(EA
, uimm
<< sh
);
7775 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], uimm
<< sh
);
7776 if (NARROW_MODE(ctx
)) {
7777 tcg_gen_ext32u_tl(EA
, EA
);
7782 static inline void gen_op_evldd(DisasContext
*ctx
, TCGv addr
)
7784 #if defined(TARGET_PPC64)
7785 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7787 TCGv_i64 t0
= tcg_temp_new_i64();
7788 gen_qemu_ld64(ctx
, t0
, addr
);
7789 tcg_gen_trunc_i64_i32(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7790 tcg_gen_shri_i64(t0
, t0
, 32);
7791 tcg_gen_trunc_i64_i32(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7792 tcg_temp_free_i64(t0
);
7796 static inline void gen_op_evldw(DisasContext
*ctx
, TCGv addr
)
7798 #if defined(TARGET_PPC64)
7799 TCGv t0
= tcg_temp_new();
7800 gen_qemu_ld32u(ctx
, t0
, addr
);
7801 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7802 gen_addr_add(ctx
, addr
, addr
, 4);
7803 gen_qemu_ld32u(ctx
, t0
, addr
);
7804 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7807 gen_qemu_ld32u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7808 gen_addr_add(ctx
, addr
, addr
, 4);
7809 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7813 static inline void gen_op_evldh(DisasContext
*ctx
, TCGv addr
)
7815 TCGv t0
= tcg_temp_new();
7816 #if defined(TARGET_PPC64)
7817 gen_qemu_ld16u(ctx
, t0
, addr
);
7818 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7819 gen_addr_add(ctx
, addr
, addr
, 2);
7820 gen_qemu_ld16u(ctx
, t0
, addr
);
7821 tcg_gen_shli_tl(t0
, t0
, 32);
7822 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7823 gen_addr_add(ctx
, addr
, addr
, 2);
7824 gen_qemu_ld16u(ctx
, t0
, addr
);
7825 tcg_gen_shli_tl(t0
, t0
, 16);
7826 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7827 gen_addr_add(ctx
, addr
, addr
, 2);
7828 gen_qemu_ld16u(ctx
, t0
, addr
);
7829 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7831 gen_qemu_ld16u(ctx
, t0
, addr
);
7832 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7833 gen_addr_add(ctx
, addr
, addr
, 2);
7834 gen_qemu_ld16u(ctx
, t0
, addr
);
7835 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
7836 gen_addr_add(ctx
, addr
, addr
, 2);
7837 gen_qemu_ld16u(ctx
, t0
, addr
);
7838 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7839 gen_addr_add(ctx
, addr
, addr
, 2);
7840 gen_qemu_ld16u(ctx
, t0
, addr
);
7841 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7846 static inline void gen_op_evlhhesplat(DisasContext
*ctx
, TCGv addr
)
7848 TCGv t0
= tcg_temp_new();
7849 gen_qemu_ld16u(ctx
, t0
, addr
);
7850 #if defined(TARGET_PPC64)
7851 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7852 tcg_gen_shli_tl(t0
, t0
, 16);
7853 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7855 tcg_gen_shli_tl(t0
, t0
, 16);
7856 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7857 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7862 static inline void gen_op_evlhhousplat(DisasContext
*ctx
, TCGv addr
)
7864 TCGv t0
= tcg_temp_new();
7865 gen_qemu_ld16u(ctx
, t0
, addr
);
7866 #if defined(TARGET_PPC64)
7867 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7868 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7870 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7871 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7876 static inline void gen_op_evlhhossplat(DisasContext
*ctx
, TCGv addr
)
7878 TCGv t0
= tcg_temp_new();
7879 gen_qemu_ld16s(ctx
, t0
, addr
);
7880 #if defined(TARGET_PPC64)
7881 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7882 tcg_gen_ext32u_tl(t0
, t0
);
7883 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7885 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7886 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7891 static inline void gen_op_evlwhe(DisasContext
*ctx
, TCGv addr
)
7893 TCGv t0
= tcg_temp_new();
7894 #if defined(TARGET_PPC64)
7895 gen_qemu_ld16u(ctx
, t0
, addr
);
7896 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7897 gen_addr_add(ctx
, addr
, addr
, 2);
7898 gen_qemu_ld16u(ctx
, t0
, addr
);
7899 tcg_gen_shli_tl(t0
, t0
, 16);
7900 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7902 gen_qemu_ld16u(ctx
, t0
, addr
);
7903 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7904 gen_addr_add(ctx
, addr
, addr
, 2);
7905 gen_qemu_ld16u(ctx
, t0
, addr
);
7906 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
7911 static inline void gen_op_evlwhou(DisasContext
*ctx
, TCGv addr
)
7913 #if defined(TARGET_PPC64)
7914 TCGv t0
= tcg_temp_new();
7915 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7916 gen_addr_add(ctx
, addr
, addr
, 2);
7917 gen_qemu_ld16u(ctx
, t0
, addr
);
7918 tcg_gen_shli_tl(t0
, t0
, 32);
7919 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7922 gen_qemu_ld16u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7923 gen_addr_add(ctx
, addr
, addr
, 2);
7924 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7928 static inline void gen_op_evlwhos(DisasContext
*ctx
, TCGv addr
)
7930 #if defined(TARGET_PPC64)
7931 TCGv t0
= tcg_temp_new();
7932 gen_qemu_ld16s(ctx
, t0
, addr
);
7933 tcg_gen_ext32u_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7934 gen_addr_add(ctx
, addr
, addr
, 2);
7935 gen_qemu_ld16s(ctx
, t0
, addr
);
7936 tcg_gen_shli_tl(t0
, t0
, 32);
7937 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7940 gen_qemu_ld16s(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7941 gen_addr_add(ctx
, addr
, addr
, 2);
7942 gen_qemu_ld16s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7946 static inline void gen_op_evlwwsplat(DisasContext
*ctx
, TCGv addr
)
7948 TCGv t0
= tcg_temp_new();
7949 gen_qemu_ld32u(ctx
, t0
, addr
);
7950 #if defined(TARGET_PPC64)
7951 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7952 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7954 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7955 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7960 static inline void gen_op_evlwhsplat(DisasContext
*ctx
, TCGv addr
)
7962 TCGv t0
= tcg_temp_new();
7963 #if defined(TARGET_PPC64)
7964 gen_qemu_ld16u(ctx
, t0
, addr
);
7965 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7966 tcg_gen_shli_tl(t0
, t0
, 32);
7967 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7968 gen_addr_add(ctx
, addr
, addr
, 2);
7969 gen_qemu_ld16u(ctx
, t0
, addr
);
7970 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7971 tcg_gen_shli_tl(t0
, t0
, 16);
7972 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7974 gen_qemu_ld16u(ctx
, t0
, addr
);
7975 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7976 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
7977 gen_addr_add(ctx
, addr
, addr
, 2);
7978 gen_qemu_ld16u(ctx
, t0
, addr
);
7979 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
7980 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
7985 static inline void gen_op_evstdd(DisasContext
*ctx
, TCGv addr
)
7987 #if defined(TARGET_PPC64)
7988 gen_qemu_st64(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7990 TCGv_i64 t0
= tcg_temp_new_i64();
7991 tcg_gen_concat_i32_i64(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gprh
[rS(ctx
->opcode
)]);
7992 gen_qemu_st64(ctx
, t0
, addr
);
7993 tcg_temp_free_i64(t0
);
7997 static inline void gen_op_evstdw(DisasContext
*ctx
, TCGv addr
)
7999 #if defined(TARGET_PPC64)
8000 TCGv t0
= tcg_temp_new();
8001 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
8002 gen_qemu_st32(ctx
, t0
, addr
);
8005 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
8007 gen_addr_add(ctx
, addr
, addr
, 4);
8008 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
8011 static inline void gen_op_evstdh(DisasContext
*ctx
, TCGv addr
)
8013 TCGv t0
= tcg_temp_new();
8014 #if defined(TARGET_PPC64)
8015 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
8017 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
8019 gen_qemu_st16(ctx
, t0
, addr
);
8020 gen_addr_add(ctx
, addr
, addr
, 2);
8021 #if defined(TARGET_PPC64)
8022 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
8023 gen_qemu_st16(ctx
, t0
, addr
);
8025 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
8027 gen_addr_add(ctx
, addr
, addr
, 2);
8028 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
8029 gen_qemu_st16(ctx
, t0
, addr
);
8031 gen_addr_add(ctx
, addr
, addr
, 2);
8032 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
8035 static inline void gen_op_evstwhe(DisasContext
*ctx
, TCGv addr
)
8037 TCGv t0
= tcg_temp_new();
8038 #if defined(TARGET_PPC64)
8039 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
8041 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
8043 gen_qemu_st16(ctx
, t0
, addr
);
8044 gen_addr_add(ctx
, addr
, addr
, 2);
8045 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
8046 gen_qemu_st16(ctx
, t0
, addr
);
8050 static inline void gen_op_evstwho(DisasContext
*ctx
, TCGv addr
)
8052 #if defined(TARGET_PPC64)
8053 TCGv t0
= tcg_temp_new();
8054 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
8055 gen_qemu_st16(ctx
, t0
, addr
);
8058 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
8060 gen_addr_add(ctx
, addr
, addr
, 2);
8061 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
8064 static inline void gen_op_evstwwe(DisasContext
*ctx
, TCGv addr
)
8066 #if defined(TARGET_PPC64)
8067 TCGv t0
= tcg_temp_new();
8068 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
8069 gen_qemu_st32(ctx
, t0
, addr
);
8072 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
8076 static inline void gen_op_evstwwo(DisasContext
*ctx
, TCGv addr
)
8078 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
8081 #define GEN_SPEOP_LDST(name, opc2, sh) \
8082 static void glue(gen_, name)(DisasContext *ctx) \
8085 if (unlikely(!ctx->spe_enabled)) { \
8086 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8089 gen_set_access_type(ctx, ACCESS_INT); \
8090 t0 = tcg_temp_new(); \
8091 if (Rc(ctx->opcode)) { \
8092 gen_addr_spe_imm_index(ctx, t0, sh); \
8094 gen_addr_reg_index(ctx, t0); \
8096 gen_op_##name(ctx, t0); \
8097 tcg_temp_free(t0); \
8100 GEN_SPEOP_LDST(evldd
, 0x00, 3);
8101 GEN_SPEOP_LDST(evldw
, 0x01, 3);
8102 GEN_SPEOP_LDST(evldh
, 0x02, 3);
8103 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1);
8104 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1);
8105 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1);
8106 GEN_SPEOP_LDST(evlwhe
, 0x08, 2);
8107 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2);
8108 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2);
8109 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2);
8110 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2);
8112 GEN_SPEOP_LDST(evstdd
, 0x10, 3);
8113 GEN_SPEOP_LDST(evstdw
, 0x11, 3);
8114 GEN_SPEOP_LDST(evstdh
, 0x12, 3);
8115 GEN_SPEOP_LDST(evstwhe
, 0x18, 2);
8116 GEN_SPEOP_LDST(evstwho
, 0x1A, 2);
8117 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2);
8118 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2);
8120 /* Multiply and add - TODO */
8122 GEN_SPE(speundef
, evmhessf
, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);//
8123 GEN_SPE(speundef
, evmhossf
, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8124 GEN_SPE(evmheumi
, evmhesmi
, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
8125 GEN_SPE(speundef
, evmhesmf
, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8126 GEN_SPE(evmhoumi
, evmhosmi
, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
8127 GEN_SPE(speundef
, evmhosmf
, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8128 GEN_SPE(speundef
, evmhessfa
, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8129 GEN_SPE(speundef
, evmhossfa
, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8130 GEN_SPE(evmheumia
, evmhesmia
, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
8131 GEN_SPE(speundef
, evmhesmfa
, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8132 GEN_SPE(evmhoumia
, evmhosmia
, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE
);
8133 GEN_SPE(speundef
, evmhosmfa
, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8135 GEN_SPE(speundef
, evmwhssf
, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8136 GEN_SPE(evmwlumi
, speundef
, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
8137 GEN_SPE(evmwhumi
, evmwhsmi
, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
8138 GEN_SPE(speundef
, evmwhsmf
, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8139 GEN_SPE(speundef
, evmwssf
, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8140 GEN_SPE(speundef
, evmwsmf
, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8141 GEN_SPE(speundef
, evmwhssfa
, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8142 GEN_SPE(evmwlumia
, speundef
, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE
);
8143 GEN_SPE(evmwhumia
, evmwhsmia
, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE
);
8144 GEN_SPE(speundef
, evmwhsmfa
, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8145 GEN_SPE(speundef
, evmwssfa
, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8146 GEN_SPE(speundef
, evmwsmfa
, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8148 GEN_SPE(evadduiaaw
, evaddsiaaw
, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8149 GEN_SPE(evsubfusiaaw
, evsubfssiaaw
, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8150 GEN_SPE(evaddumiaaw
, evaddsmiaaw
, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8151 GEN_SPE(evsubfumiaaw
, evsubfsmiaaw
, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE
);
8152 GEN_SPE(evdivws
, evdivwu
, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE
);
8154 GEN_SPE(evmheusiaaw
, evmhessiaaw
, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8155 GEN_SPE(speundef
, evmhessfaaw
, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8156 GEN_SPE(evmhousiaaw
, evmhossiaaw
, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8157 GEN_SPE(speundef
, evmhossfaaw
, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8158 GEN_SPE(evmheumiaaw
, evmhesmiaaw
, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8159 GEN_SPE(speundef
, evmhesmfaaw
, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8160 GEN_SPE(evmhoumiaaw
, evmhosmiaaw
, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8161 GEN_SPE(speundef
, evmhosmfaaw
, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8162 GEN_SPE(evmhegumiaa
, evmhegsmiaa
, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8163 GEN_SPE(speundef
, evmhegsmfaa
, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8164 GEN_SPE(evmhogumiaa
, evmhogsmiaa
, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE
);
8165 GEN_SPE(speundef
, evmhogsmfaa
, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8167 GEN_SPE(evmwlusiaaw
, evmwlssiaaw
, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
8168 GEN_SPE(evmwlumiaaw
, evmwlsmiaaw
, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE
);
8169 GEN_SPE(speundef
, evmwssfaa
, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8170 GEN_SPE(speundef
, evmwsmfaa
, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8172 GEN_SPE(evmheusianw
, evmhessianw
, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8173 GEN_SPE(speundef
, evmhessfanw
, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8174 GEN_SPE(evmhousianw
, evmhossianw
, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8175 GEN_SPE(speundef
, evmhossfanw
, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8176 GEN_SPE(evmheumianw
, evmhesmianw
, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8177 GEN_SPE(speundef
, evmhesmfanw
, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8178 GEN_SPE(evmhoumianw
, evmhosmianw
, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8179 GEN_SPE(speundef
, evmhosmfanw
, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8180 GEN_SPE(evmhegumian
, evmhegsmian
, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8181 GEN_SPE(speundef
, evmhegsmfan
, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8182 GEN_SPE(evmhigumian
, evmhigsmian
, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE
);
8183 GEN_SPE(speundef
, evmhogsmfan
, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8185 GEN_SPE(evmwlusianw
, evmwlssianw
, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
8186 GEN_SPE(evmwlumianw
, evmwlsmianw
, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
8187 GEN_SPE(speundef
, evmwssfan
, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8188 GEN_SPE(evmwumian
, evmwsmian
, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE
);
8189 GEN_SPE(speundef
, evmwsmfan
, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE
);
8192 /*** SPE floating-point extension ***/
8193 #if defined(TARGET_PPC64)
8194 #define GEN_SPEFPUOP_CONV_32_32(name) \
8195 static inline void gen_##name(DisasContext *ctx) \
8199 t0 = tcg_temp_new_i32(); \
8200 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8201 gen_helper_##name(t0, cpu_env, t0); \
8202 t1 = tcg_temp_new(); \
8203 tcg_gen_extu_i32_tl(t1, t0); \
8204 tcg_temp_free_i32(t0); \
8205 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8206 0xFFFFFFFF00000000ULL); \
8207 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
8208 tcg_temp_free(t1); \
8210 #define GEN_SPEFPUOP_CONV_32_64(name) \
8211 static inline void gen_##name(DisasContext *ctx) \
8215 t0 = tcg_temp_new_i32(); \
8216 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
8217 t1 = tcg_temp_new(); \
8218 tcg_gen_extu_i32_tl(t1, t0); \
8219 tcg_temp_free_i32(t0); \
8220 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8221 0xFFFFFFFF00000000ULL); \
8222 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
8223 tcg_temp_free(t1); \
8225 #define GEN_SPEFPUOP_CONV_64_32(name) \
8226 static inline void gen_##name(DisasContext *ctx) \
8228 TCGv_i32 t0 = tcg_temp_new_i32(); \
8229 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
8230 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
8231 tcg_temp_free_i32(t0); \
8233 #define GEN_SPEFPUOP_CONV_64_64(name) \
8234 static inline void gen_##name(DisasContext *ctx) \
8236 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8237 cpu_gpr[rB(ctx->opcode)]); \
8239 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
8240 static inline void gen_##name(DisasContext *ctx) \
8244 if (unlikely(!ctx->spe_enabled)) { \
8245 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8248 t0 = tcg_temp_new_i32(); \
8249 t1 = tcg_temp_new_i32(); \
8250 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8251 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8252 gen_helper_##name(t0, cpu_env, t0, t1); \
8253 tcg_temp_free_i32(t1); \
8254 t2 = tcg_temp_new(); \
8255 tcg_gen_extu_i32_tl(t2, t0); \
8256 tcg_temp_free_i32(t0); \
8257 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
8258 0xFFFFFFFF00000000ULL); \
8259 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \
8260 tcg_temp_free(t2); \
8262 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
8263 static inline void gen_##name(DisasContext *ctx) \
8265 if (unlikely(!ctx->spe_enabled)) { \
8266 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8269 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8270 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8272 #define GEN_SPEFPUOP_COMP_32(name) \
8273 static inline void gen_##name(DisasContext *ctx) \
8276 if (unlikely(!ctx->spe_enabled)) { \
8277 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8280 t0 = tcg_temp_new_i32(); \
8281 t1 = tcg_temp_new_i32(); \
8282 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
8283 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
8284 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
8285 tcg_temp_free_i32(t0); \
8286 tcg_temp_free_i32(t1); \
8288 #define GEN_SPEFPUOP_COMP_64(name) \
8289 static inline void gen_##name(DisasContext *ctx) \
8291 if (unlikely(!ctx->spe_enabled)) { \
8292 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8295 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
8296 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8299 #define GEN_SPEFPUOP_CONV_32_32(name) \
8300 static inline void gen_##name(DisasContext *ctx) \
8302 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8303 cpu_gpr[rB(ctx->opcode)]); \
8305 #define GEN_SPEFPUOP_CONV_32_64(name) \
8306 static inline void gen_##name(DisasContext *ctx) \
8308 TCGv_i64 t0 = tcg_temp_new_i64(); \
8309 gen_load_gpr64(t0, rB(ctx->opcode)); \
8310 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \
8311 tcg_temp_free_i64(t0); \
8313 #define GEN_SPEFPUOP_CONV_64_32(name) \
8314 static inline void gen_##name(DisasContext *ctx) \
8316 TCGv_i64 t0 = tcg_temp_new_i64(); \
8317 gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \
8318 gen_store_gpr64(rD(ctx->opcode), t0); \
8319 tcg_temp_free_i64(t0); \
8321 #define GEN_SPEFPUOP_CONV_64_64(name) \
8322 static inline void gen_##name(DisasContext *ctx) \
8324 TCGv_i64 t0 = tcg_temp_new_i64(); \
8325 gen_load_gpr64(t0, rB(ctx->opcode)); \
8326 gen_helper_##name(t0, cpu_env, t0); \
8327 gen_store_gpr64(rD(ctx->opcode), t0); \
8328 tcg_temp_free_i64(t0); \
8330 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
8331 static inline void gen_##name(DisasContext *ctx) \
8333 if (unlikely(!ctx->spe_enabled)) { \
8334 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8337 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \
8338 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8340 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
8341 static inline void gen_##name(DisasContext *ctx) \
8344 if (unlikely(!ctx->spe_enabled)) { \
8345 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8348 t0 = tcg_temp_new_i64(); \
8349 t1 = tcg_temp_new_i64(); \
8350 gen_load_gpr64(t0, rA(ctx->opcode)); \
8351 gen_load_gpr64(t1, rB(ctx->opcode)); \
8352 gen_helper_##name(t0, cpu_env, t0, t1); \
8353 gen_store_gpr64(rD(ctx->opcode), t0); \
8354 tcg_temp_free_i64(t0); \
8355 tcg_temp_free_i64(t1); \
8357 #define GEN_SPEFPUOP_COMP_32(name) \
8358 static inline void gen_##name(DisasContext *ctx) \
8360 if (unlikely(!ctx->spe_enabled)) { \
8361 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8364 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \
8365 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
8367 #define GEN_SPEFPUOP_COMP_64(name) \
8368 static inline void gen_##name(DisasContext *ctx) \
8371 if (unlikely(!ctx->spe_enabled)) { \
8372 gen_exception(ctx, POWERPC_EXCP_SPEU); \
8375 t0 = tcg_temp_new_i64(); \
8376 t1 = tcg_temp_new_i64(); \
8377 gen_load_gpr64(t0, rA(ctx->opcode)); \
8378 gen_load_gpr64(t1, rB(ctx->opcode)); \
8379 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \
8380 tcg_temp_free_i64(t0); \
8381 tcg_temp_free_i64(t1); \
8385 /* Single precision floating-point vectors operations */
8387 GEN_SPEFPUOP_ARITH2_64_64(evfsadd
);
8388 GEN_SPEFPUOP_ARITH2_64_64(evfssub
);
8389 GEN_SPEFPUOP_ARITH2_64_64(evfsmul
);
8390 GEN_SPEFPUOP_ARITH2_64_64(evfsdiv
);
8391 static inline void gen_evfsabs(DisasContext
*ctx
)
8393 if (unlikely(!ctx
->spe_enabled
)) {
8394 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8397 #if defined(TARGET_PPC64)
8398 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000080000000LL
);
8400 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x80000000);
8401 tcg_gen_andi_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
8404 static inline void gen_evfsnabs(DisasContext
*ctx
)
8406 if (unlikely(!ctx
->spe_enabled
)) {
8407 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8410 #if defined(TARGET_PPC64)
8411 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
8413 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8414 tcg_gen_ori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8417 static inline void gen_evfsneg(DisasContext
*ctx
)
8419 if (unlikely(!ctx
->spe_enabled
)) {
8420 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8423 #if defined(TARGET_PPC64)
8424 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
8426 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8427 tcg_gen_xori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8432 GEN_SPEFPUOP_CONV_64_64(evfscfui
);
8433 GEN_SPEFPUOP_CONV_64_64(evfscfsi
);
8434 GEN_SPEFPUOP_CONV_64_64(evfscfuf
);
8435 GEN_SPEFPUOP_CONV_64_64(evfscfsf
);
8436 GEN_SPEFPUOP_CONV_64_64(evfsctui
);
8437 GEN_SPEFPUOP_CONV_64_64(evfsctsi
);
8438 GEN_SPEFPUOP_CONV_64_64(evfsctuf
);
8439 GEN_SPEFPUOP_CONV_64_64(evfsctsf
);
8440 GEN_SPEFPUOP_CONV_64_64(evfsctuiz
);
8441 GEN_SPEFPUOP_CONV_64_64(evfsctsiz
);
8444 GEN_SPEFPUOP_COMP_64(evfscmpgt
);
8445 GEN_SPEFPUOP_COMP_64(evfscmplt
);
8446 GEN_SPEFPUOP_COMP_64(evfscmpeq
);
8447 GEN_SPEFPUOP_COMP_64(evfststgt
);
8448 GEN_SPEFPUOP_COMP_64(evfststlt
);
8449 GEN_SPEFPUOP_COMP_64(evfststeq
);
8451 /* Opcodes definitions */
8452 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8453 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
); //
8454 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8455 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8456 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8457 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8458 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8459 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8460 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8461 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8462 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8463 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8464 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8465 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8467 /* Single precision floating-point operations */
8469 GEN_SPEFPUOP_ARITH2_32_32(efsadd
);
8470 GEN_SPEFPUOP_ARITH2_32_32(efssub
);
8471 GEN_SPEFPUOP_ARITH2_32_32(efsmul
);
8472 GEN_SPEFPUOP_ARITH2_32_32(efsdiv
);
8473 static inline void gen_efsabs(DisasContext
*ctx
)
8475 if (unlikely(!ctx
->spe_enabled
)) {
8476 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8479 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], (target_long
)~0x80000000LL
);
8481 static inline void gen_efsnabs(DisasContext
*ctx
)
8483 if (unlikely(!ctx
->spe_enabled
)) {
8484 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8487 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8489 static inline void gen_efsneg(DisasContext
*ctx
)
8491 if (unlikely(!ctx
->spe_enabled
)) {
8492 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8495 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
8499 GEN_SPEFPUOP_CONV_32_32(efscfui
);
8500 GEN_SPEFPUOP_CONV_32_32(efscfsi
);
8501 GEN_SPEFPUOP_CONV_32_32(efscfuf
);
8502 GEN_SPEFPUOP_CONV_32_32(efscfsf
);
8503 GEN_SPEFPUOP_CONV_32_32(efsctui
);
8504 GEN_SPEFPUOP_CONV_32_32(efsctsi
);
8505 GEN_SPEFPUOP_CONV_32_32(efsctuf
);
8506 GEN_SPEFPUOP_CONV_32_32(efsctsf
);
8507 GEN_SPEFPUOP_CONV_32_32(efsctuiz
);
8508 GEN_SPEFPUOP_CONV_32_32(efsctsiz
);
8509 GEN_SPEFPUOP_CONV_32_64(efscfd
);
8512 GEN_SPEFPUOP_COMP_32(efscmpgt
);
8513 GEN_SPEFPUOP_COMP_32(efscmplt
);
8514 GEN_SPEFPUOP_COMP_32(efscmpeq
);
8515 GEN_SPEFPUOP_COMP_32(efststgt
);
8516 GEN_SPEFPUOP_COMP_32(efststlt
);
8517 GEN_SPEFPUOP_COMP_32(efststeq
);
8519 /* Opcodes definitions */
8520 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8521 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
); //
8522 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8523 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
); //
8524 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8525 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE
); //
8526 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8527 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8528 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8529 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
); //
8530 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8531 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8532 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
); //
8533 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
); //
8535 /* Double precision floating-point operations */
8537 GEN_SPEFPUOP_ARITH2_64_64(efdadd
);
8538 GEN_SPEFPUOP_ARITH2_64_64(efdsub
);
8539 GEN_SPEFPUOP_ARITH2_64_64(efdmul
);
8540 GEN_SPEFPUOP_ARITH2_64_64(efddiv
);
8541 static inline void gen_efdabs(DisasContext
*ctx
)
8543 if (unlikely(!ctx
->spe_enabled
)) {
8544 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8547 #if defined(TARGET_PPC64)
8548 tcg_gen_andi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000000000000LL
);
8550 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8551 tcg_gen_andi_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
8554 static inline void gen_efdnabs(DisasContext
*ctx
)
8556 if (unlikely(!ctx
->spe_enabled
)) {
8557 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8560 #if defined(TARGET_PPC64)
8561 tcg_gen_ori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
8563 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8564 tcg_gen_ori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8567 static inline void gen_efdneg(DisasContext
*ctx
)
8569 if (unlikely(!ctx
->spe_enabled
)) {
8570 gen_exception(ctx
, POWERPC_EXCP_SPEU
);
8573 #if defined(TARGET_PPC64)
8574 tcg_gen_xori_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
8576 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
8577 tcg_gen_xori_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
8582 GEN_SPEFPUOP_CONV_64_32(efdcfui
);
8583 GEN_SPEFPUOP_CONV_64_32(efdcfsi
);
8584 GEN_SPEFPUOP_CONV_64_32(efdcfuf
);
8585 GEN_SPEFPUOP_CONV_64_32(efdcfsf
);
8586 GEN_SPEFPUOP_CONV_32_64(efdctui
);
8587 GEN_SPEFPUOP_CONV_32_64(efdctsi
);
8588 GEN_SPEFPUOP_CONV_32_64(efdctuf
);
8589 GEN_SPEFPUOP_CONV_32_64(efdctsf
);
8590 GEN_SPEFPUOP_CONV_32_64(efdctuiz
);
8591 GEN_SPEFPUOP_CONV_32_64(efdctsiz
);
8592 GEN_SPEFPUOP_CONV_64_32(efdcfs
);
8593 GEN_SPEFPUOP_CONV_64_64(efdcfuid
);
8594 GEN_SPEFPUOP_CONV_64_64(efdcfsid
);
8595 GEN_SPEFPUOP_CONV_64_64(efdctuidz
);
8596 GEN_SPEFPUOP_CONV_64_64(efdctsidz
);
8599 GEN_SPEFPUOP_COMP_64(efdcmpgt
);
8600 GEN_SPEFPUOP_COMP_64(efdcmplt
);
8601 GEN_SPEFPUOP_COMP_64(efdcmpeq
);
8602 GEN_SPEFPUOP_COMP_64(efdtstgt
);
8603 GEN_SPEFPUOP_COMP_64(efdtstlt
);
8604 GEN_SPEFPUOP_COMP_64(efdtsteq
);
8606 /* Opcodes definitions */
8607 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
); //
8608 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8609 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE
); //
8610 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8611 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
); //
8612 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8613 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
); //
8614 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE
); //
8615 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8616 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8617 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8618 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
); //
8619 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8620 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8621 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
); //
8622 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE
); //
8624 static opcode_t opcodes
[] = {
8625 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
),
8626 GEN_HANDLER(cmp
, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER
),
8627 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
8628 GEN_HANDLER(cmpl
, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER
),
8629 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
8630 GEN_HANDLER_E(cmpb
, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE
, PPC2_ISA205
),
8631 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
),
8632 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8633 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8634 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8635 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8636 GEN_HANDLER(mulhw
, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER
),
8637 GEN_HANDLER(mulhwu
, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER
),
8638 GEN_HANDLER(mullw
, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER
),
8639 GEN_HANDLER(mullwo
, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER
),
8640 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8641 #if defined(TARGET_PPC64)
8642 GEN_HANDLER(mulld
, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B
),
8644 GEN_HANDLER(neg
, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER
),
8645 GEN_HANDLER(nego
, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER
),
8646 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8647 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8648 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8649 GEN_HANDLER(cntlzw
, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER
),
8650 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
),
8651 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
),
8652 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8653 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8654 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8655 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8656 GEN_HANDLER(popcntb
, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB
),
8657 GEN_HANDLER(popcntw
, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD
),
8658 GEN_HANDLER_E(prtyw
, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
8659 #if defined(TARGET_PPC64)
8660 GEN_HANDLER(popcntd
, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD
),
8661 GEN_HANDLER(cntlzd
, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B
),
8662 GEN_HANDLER_E(prtyd
, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
8664 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8665 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8666 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8667 GEN_HANDLER(slw
, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER
),
8668 GEN_HANDLER(sraw
, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER
),
8669 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
),
8670 GEN_HANDLER(srw
, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER
),
8671 #if defined(TARGET_PPC64)
8672 GEN_HANDLER(sld
, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B
),
8673 GEN_HANDLER(srad
, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B
),
8674 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
),
8675 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
),
8676 GEN_HANDLER(srd
, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B
),
8678 GEN_HANDLER(frsqrtes
, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES
),
8679 GEN_HANDLER(fsqrt
, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
8680 GEN_HANDLER(fsqrts
, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
8681 GEN_HANDLER(fcmpo
, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT
),
8682 GEN_HANDLER(fcmpu
, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT
),
8683 GEN_HANDLER(fabs
, 0x3F, 0x08, 0x08, 0x001F0000, PPC_FLOAT
),
8684 GEN_HANDLER(fmr
, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT
),
8685 GEN_HANDLER(fnabs
, 0x3F, 0x08, 0x04, 0x001F0000, PPC_FLOAT
),
8686 GEN_HANDLER(fneg
, 0x3F, 0x08, 0x01, 0x001F0000, PPC_FLOAT
),
8687 GEN_HANDLER_E(fcpsgn
, 0x3F, 0x08, 0x00, 0x00000000, PPC_NONE
, PPC2_ISA205
),
8688 GEN_HANDLER(mcrfs
, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT
),
8689 GEN_HANDLER(mffs
, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT
),
8690 GEN_HANDLER(mtfsb0
, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT
),
8691 GEN_HANDLER(mtfsb1
, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT
),
8692 GEN_HANDLER(mtfsf
, 0x3F, 0x07, 0x16, 0x00010000, PPC_FLOAT
),
8693 GEN_HANDLER(mtfsfi
, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT
),
8694 #if defined(TARGET_PPC64)
8695 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
),
8696 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
),
8697 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
),
8699 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8700 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8701 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
),
8702 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
),
8703 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
),
8704 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
),
8705 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO
),
8706 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
),
8707 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES
),
8708 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
),
8709 #if defined(TARGET_PPC64)
8710 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B
),
8711 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
),
8713 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
),
8714 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
),
8715 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
8716 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
8717 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
),
8718 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
),
8719 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
),
8720 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
),
8721 #if defined(TARGET_PPC64)
8722 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
),
8723 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
),
8725 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW
),
8726 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
),
8727 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
8728 #if defined(TARGET_PPC64)
8729 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
),
8730 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
),
8732 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
),
8733 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
),
8734 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
),
8735 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
),
8736 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
),
8737 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
),
8738 #if defined(TARGET_PPC64)
8739 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
),
8741 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC
),
8742 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC
),
8743 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
),
8744 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
),
8745 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
),
8746 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE
),
8747 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE
),
8748 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ
),
8749 GEN_HANDLER(dst
, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC
),
8750 GEN_HANDLER(dstst
, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC
),
8751 GEN_HANDLER(dss
, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC
),
8752 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
),
8753 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
),
8754 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
),
8755 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
),
8756 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
),
8757 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
),
8758 #if defined(TARGET_PPC64)
8759 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
),
8760 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
8762 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
),
8763 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
8765 GEN_HANDLER2(slbmte
, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B
),
8766 GEN_HANDLER2(slbmfee
, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B
),
8767 GEN_HANDLER2(slbmfev
, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B
),
8769 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
),
8770 GEN_HANDLER(tlbiel
, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE
),
8771 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE
),
8772 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
),
8773 #if defined(TARGET_PPC64)
8774 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI
),
8775 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
),
8777 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
),
8778 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
),
8779 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
),
8780 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
),
8781 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
),
8782 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
),
8783 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
),
8784 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
),
8785 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
),
8786 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
),
8787 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
),
8788 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
8789 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
),
8790 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
),
8791 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
),
8792 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
),
8793 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
),
8794 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
),
8795 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
),
8796 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
8797 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
),
8798 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
),
8799 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
),
8800 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
),
8801 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
),
8802 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
),
8803 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
),
8804 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
),
8805 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
),
8806 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
),
8807 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
),
8808 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
),
8809 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
),
8810 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
),
8811 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
),
8812 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
),
8813 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
),
8814 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
),
8815 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
),
8816 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
),
8817 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
),
8818 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
),
8819 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
),
8820 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
),
8821 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
),
8822 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
),
8823 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
),
8824 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
),
8825 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
),
8826 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8827 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8828 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
),
8829 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
),
8830 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8831 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8832 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
),
8833 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
),
8834 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
),
8835 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
),
8836 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
),
8837 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
),
8838 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
),
8839 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
),
8840 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
),
8841 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
),
8842 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
),
8843 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
),
8844 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
),
8845 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
),
8846 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
),
8847 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
),
8848 GEN_HANDLER_E(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
, PPC2_BOOKE206
),
8849 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
),
8850 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
),
8851 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
),
8852 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
),
8853 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
),
8854 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
),
8855 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
),
8856 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
),
8857 GEN_HANDLER2_E(tlbre_booke206
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
8858 PPC_NONE
, PPC2_BOOKE206
),
8859 GEN_HANDLER2_E(tlbsx_booke206
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
8860 PPC_NONE
, PPC2_BOOKE206
),
8861 GEN_HANDLER2_E(tlbwe_booke206
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
8862 PPC_NONE
, PPC2_BOOKE206
),
8863 GEN_HANDLER2_E(tlbivax_booke206
, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
8864 PPC_NONE
, PPC2_BOOKE206
),
8865 GEN_HANDLER2_E(tlbilx_booke206
, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
8866 PPC_NONE
, PPC2_BOOKE206
),
8867 GEN_HANDLER2_E(msgsnd
, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
8868 PPC_NONE
, PPC2_PRCNTL
),
8869 GEN_HANDLER2_E(msgclr
, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
8870 PPC_NONE
, PPC2_PRCNTL
),
8871 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
),
8872 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE
),
8873 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
),
8874 GEN_HANDLER_E(mbar
, 0x1F, 0x16, 0x1a, 0x001FF801,
8875 PPC_BOOKE
, PPC2_BOOKE206
),
8876 GEN_HANDLER(msync_4xx
, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE
),
8877 GEN_HANDLER2_E(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
8878 PPC_BOOKE
, PPC2_BOOKE206
),
8879 GEN_HANDLER(lvsl
, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC
),
8880 GEN_HANDLER(lvsr
, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC
),
8881 GEN_HANDLER(mfvscr
, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC
),
8882 GEN_HANDLER(mtvscr
, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC
),
8883 GEN_HANDLER(vsldoi
, 0x04, 0x16, 0xFF, 0x00000400, PPC_ALTIVEC
),
8884 GEN_HANDLER(vmladduhm
, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC
),
8885 GEN_HANDLER2(evsel0
, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE
),
8886 GEN_HANDLER2(evsel1
, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE
),
8887 GEN_HANDLER2(evsel2
, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE
),
8888 GEN_HANDLER2(evsel3
, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE
),
8890 #undef GEN_INT_ARITH_ADD
8891 #undef GEN_INT_ARITH_ADD_CONST
8892 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
8893 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
8894 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
8895 add_ca, compute_ca, compute_ov) \
8896 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
8897 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
8898 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
8899 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
8900 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
8901 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
8902 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
8903 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
8904 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
8905 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
8906 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
8908 #undef GEN_INT_ARITH_DIVW
8909 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
8910 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
8911 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0),
8912 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1),
8913 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0),
8914 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1),
8916 #if defined(TARGET_PPC64)
8917 #undef GEN_INT_ARITH_DIVD
8918 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
8919 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8920 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0),
8921 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1),
8922 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0),
8923 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1),
8925 #undef GEN_INT_ARITH_MUL_HELPER
8926 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
8927 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8928 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00),
8929 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02),
8930 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17),
8933 #undef GEN_INT_ARITH_SUBF
8934 #undef GEN_INT_ARITH_SUBF_CONST
8935 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
8936 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
8937 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
8938 add_ca, compute_ca, compute_ov) \
8939 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
8940 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
8941 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
8942 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
8943 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
8944 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
8945 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
8946 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
8947 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
8948 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
8949 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
8953 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
8954 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
8955 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
8956 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
8957 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
),
8958 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
),
8959 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
),
8960 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
),
8961 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
),
8962 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
),
8963 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
),
8964 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
),
8965 #if defined(TARGET_PPC64)
8966 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
),
8969 #if defined(TARGET_PPC64)
8972 #define GEN_PPC64_R2(name, opc1, opc2) \
8973 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8974 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
8976 #define GEN_PPC64_R4(name, opc1, opc2) \
8977 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8978 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
8980 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
8982 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
8984 GEN_PPC64_R4(rldicl
, 0x1E, 0x00),
8985 GEN_PPC64_R4(rldicr
, 0x1E, 0x02),
8986 GEN_PPC64_R4(rldic
, 0x1E, 0x04),
8987 GEN_PPC64_R2(rldcl
, 0x1E, 0x08),
8988 GEN_PPC64_R2(rldcr
, 0x1E, 0x09),
8989 GEN_PPC64_R4(rldimi
, 0x1E, 0x06),
8992 #undef _GEN_FLOAT_ACB
8993 #undef GEN_FLOAT_ACB
8994 #undef _GEN_FLOAT_AB
8996 #undef _GEN_FLOAT_AC
9000 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
9001 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
9002 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
9003 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
9004 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
9005 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
9006 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
9007 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
9008 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
9009 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
9010 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
9011 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
9012 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
9013 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
9014 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
9015 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
9016 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
9017 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
9018 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
9020 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
),
9021 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
),
9022 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
),
9023 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
),
9024 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
),
9025 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
),
9026 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
),
9027 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
),
9028 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
),
9029 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
),
9030 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
),
9031 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
),
9032 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
),
9033 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
),
9034 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
),
9035 #if defined(TARGET_PPC64)
9036 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
),
9037 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
),
9038 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
),
9040 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
),
9041 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
),
9042 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
),
9043 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
),
9050 #define GEN_LD(name, ldop, opc, type) \
9051 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9052 #define GEN_LDU(name, ldop, opc, type) \
9053 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
9054 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
9055 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
9056 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \
9057 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
9058 #define GEN_LDS(name, ldop, op, type) \
9059 GEN_LD(name, ldop, op | 0x20, type) \
9060 GEN_LDU(name, ldop, op | 0x21, type) \
9061 GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
9062 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
9064 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
)
9065 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
)
9066 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
)
9067 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
)
9068 #if defined(TARGET_PPC64)
9069 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
)
9070 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
)
9071 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
)
9072 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
)
9073 GEN_LDX_E(ldbr
, ld64ur
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
)
9075 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
)
9076 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
)
9083 #define GEN_ST(name, stop, opc, type) \
9084 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9085 #define GEN_STU(name, stop, opc, type) \
9086 GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
9087 #define GEN_STUX(name, stop, opc2, opc3, type) \
9088 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
9089 #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \
9090 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
9091 #define GEN_STS(name, stop, op, type) \
9092 GEN_ST(name, stop, op | 0x20, type) \
9093 GEN_STU(name, stop, op | 0x21, type) \
9094 GEN_STUX(name, stop, 0x17, op | 0x01, type) \
9095 GEN_STX(name, stop, 0x17, op | 0x00, type)
9097 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
)
9098 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
)
9099 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
)
9100 #if defined(TARGET_PPC64)
9101 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
)
9102 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
)
9103 GEN_STX_E(stdbr
, st64r
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
)
9105 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
)
9106 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
)
9113 #define GEN_LDF(name, ldop, opc, type) \
9114 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9115 #define GEN_LDUF(name, ldop, opc, type) \
9116 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
9117 #define GEN_LDUXF(name, ldop, opc, type) \
9118 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
9119 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
9120 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
9121 #define GEN_LDFS(name, ldop, op, type) \
9122 GEN_LDF(name, ldop, op | 0x20, type) \
9123 GEN_LDUF(name, ldop, op | 0x21, type) \
9124 GEN_LDUXF(name, ldop, op | 0x01, type) \
9125 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
9127 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
)
9128 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
)
9129 GEN_HANDLER_E(lfiwax
, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE
, PPC2_ISA205
),
9130 GEN_HANDLER_E(lfdp
, 0x39, 0xFF, 0xFF, 0x00200003, PPC_NONE
, PPC2_ISA205
),
9131 GEN_HANDLER_E(lfdpx
, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE
, PPC2_ISA205
),
9138 #define GEN_STF(name, stop, opc, type) \
9139 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
9140 #define GEN_STUF(name, stop, opc, type) \
9141 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
9142 #define GEN_STUXF(name, stop, opc, type) \
9143 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
9144 #define GEN_STXF(name, stop, opc2, opc3, type) \
9145 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
9146 #define GEN_STFS(name, stop, op, type) \
9147 GEN_STF(name, stop, op | 0x20, type) \
9148 GEN_STUF(name, stop, op | 0x21, type) \
9149 GEN_STUXF(name, stop, op | 0x01, type) \
9150 GEN_STXF(name, stop, 0x17, op | 0x00, type)
9152 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
)
9153 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
)
9154 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
)
9155 GEN_HANDLER_E(stfdp
, 0x3D, 0xFF, 0xFF, 0x00200003, PPC_NONE
, PPC2_ISA205
),
9156 GEN_HANDLER_E(stfdpx
, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE
, PPC2_ISA205
),
9159 #define GEN_CRLOGIC(name, tcg_op, opc) \
9160 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
9161 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08),
9162 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04),
9163 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09),
9164 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07),
9165 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01),
9166 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E),
9167 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D),
9168 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06),
9170 #undef GEN_MAC_HANDLER
9171 #define GEN_MAC_HANDLER(name, opc2, opc3) \
9172 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
9173 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05),
9174 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15),
9175 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07),
9176 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17),
9177 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06),
9178 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16),
9179 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04),
9180 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14),
9181 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01),
9182 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11),
9183 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03),
9184 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13),
9185 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02),
9186 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12),
9187 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00),
9188 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10),
9189 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D),
9190 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D),
9191 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F),
9192 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F),
9193 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C),
9194 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C),
9195 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E),
9196 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E),
9197 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05),
9198 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15),
9199 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07),
9200 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17),
9201 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01),
9202 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11),
9203 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03),
9204 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13),
9205 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D),
9206 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D),
9207 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F),
9208 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F),
9209 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05),
9210 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04),
9211 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01),
9212 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00),
9213 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D),
9214 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C),
9220 #define GEN_VR_LDX(name, opc2, opc3) \
9221 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9222 #define GEN_VR_STX(name, opc2, opc3) \
9223 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9224 #define GEN_VR_LVE(name, opc2, opc3) \
9225 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9226 #define GEN_VR_STVE(name, opc2, opc3) \
9227 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
9228 GEN_VR_LDX(lvx
, 0x07, 0x03),
9229 GEN_VR_LDX(lvxl
, 0x07, 0x0B),
9230 GEN_VR_LVE(bx
, 0x07, 0x00),
9231 GEN_VR_LVE(hx
, 0x07, 0x01),
9232 GEN_VR_LVE(wx
, 0x07, 0x02),
9233 GEN_VR_STX(svx
, 0x07, 0x07),
9234 GEN_VR_STX(svxl
, 0x07, 0x0F),
9235 GEN_VR_STVE(bx
, 0x07, 0x04),
9236 GEN_VR_STVE(hx
, 0x07, 0x05),
9237 GEN_VR_STVE(wx
, 0x07, 0x06),
9239 #undef GEN_VX_LOGICAL
9240 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
9241 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9242 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16),
9243 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17),
9244 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18),
9245 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19),
9246 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20),
9249 #define GEN_VXFORM(name, opc2, opc3) \
9250 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9251 GEN_VXFORM(vaddubm
, 0, 0),
9252 GEN_VXFORM(vadduhm
, 0, 1),
9253 GEN_VXFORM(vadduwm
, 0, 2),
9254 GEN_VXFORM(vsububm
, 0, 16),
9255 GEN_VXFORM(vsubuhm
, 0, 17),
9256 GEN_VXFORM(vsubuwm
, 0, 18),
9257 GEN_VXFORM(vmaxub
, 1, 0),
9258 GEN_VXFORM(vmaxuh
, 1, 1),
9259 GEN_VXFORM(vmaxuw
, 1, 2),
9260 GEN_VXFORM(vmaxsb
, 1, 4),
9261 GEN_VXFORM(vmaxsh
, 1, 5),
9262 GEN_VXFORM(vmaxsw
, 1, 6),
9263 GEN_VXFORM(vminub
, 1, 8),
9264 GEN_VXFORM(vminuh
, 1, 9),
9265 GEN_VXFORM(vminuw
, 1, 10),
9266 GEN_VXFORM(vminsb
, 1, 12),
9267 GEN_VXFORM(vminsh
, 1, 13),
9268 GEN_VXFORM(vminsw
, 1, 14),
9269 GEN_VXFORM(vavgub
, 1, 16),
9270 GEN_VXFORM(vavguh
, 1, 17),
9271 GEN_VXFORM(vavguw
, 1, 18),
9272 GEN_VXFORM(vavgsb
, 1, 20),
9273 GEN_VXFORM(vavgsh
, 1, 21),
9274 GEN_VXFORM(vavgsw
, 1, 22),
9275 GEN_VXFORM(vmrghb
, 6, 0),
9276 GEN_VXFORM(vmrghh
, 6, 1),
9277 GEN_VXFORM(vmrghw
, 6, 2),
9278 GEN_VXFORM(vmrglb
, 6, 4),
9279 GEN_VXFORM(vmrglh
, 6, 5),
9280 GEN_VXFORM(vmrglw
, 6, 6),
9281 GEN_VXFORM(vmuloub
, 4, 0),
9282 GEN_VXFORM(vmulouh
, 4, 1),
9283 GEN_VXFORM(vmulosb
, 4, 4),
9284 GEN_VXFORM(vmulosh
, 4, 5),
9285 GEN_VXFORM(vmuleub
, 4, 8),
9286 GEN_VXFORM(vmuleuh
, 4, 9),
9287 GEN_VXFORM(vmulesb
, 4, 12),
9288 GEN_VXFORM(vmulesh
, 4, 13),
9289 GEN_VXFORM(vslb
, 2, 4),
9290 GEN_VXFORM(vslh
, 2, 5),
9291 GEN_VXFORM(vslw
, 2, 6),
9292 GEN_VXFORM(vsrb
, 2, 8),
9293 GEN_VXFORM(vsrh
, 2, 9),
9294 GEN_VXFORM(vsrw
, 2, 10),
9295 GEN_VXFORM(vsrab
, 2, 12),
9296 GEN_VXFORM(vsrah
, 2, 13),
9297 GEN_VXFORM(vsraw
, 2, 14),
9298 GEN_VXFORM(vslo
, 6, 16),
9299 GEN_VXFORM(vsro
, 6, 17),
9300 GEN_VXFORM(vaddcuw
, 0, 6),
9301 GEN_VXFORM(vsubcuw
, 0, 22),
9302 GEN_VXFORM(vaddubs
, 0, 8),
9303 GEN_VXFORM(vadduhs
, 0, 9),
9304 GEN_VXFORM(vadduws
, 0, 10),
9305 GEN_VXFORM(vaddsbs
, 0, 12),
9306 GEN_VXFORM(vaddshs
, 0, 13),
9307 GEN_VXFORM(vaddsws
, 0, 14),
9308 GEN_VXFORM(vsububs
, 0, 24),
9309 GEN_VXFORM(vsubuhs
, 0, 25),
9310 GEN_VXFORM(vsubuws
, 0, 26),
9311 GEN_VXFORM(vsubsbs
, 0, 28),
9312 GEN_VXFORM(vsubshs
, 0, 29),
9313 GEN_VXFORM(vsubsws
, 0, 30),
9314 GEN_VXFORM(vrlb
, 2, 0),
9315 GEN_VXFORM(vrlh
, 2, 1),
9316 GEN_VXFORM(vrlw
, 2, 2),
9317 GEN_VXFORM(vsl
, 2, 7),
9318 GEN_VXFORM(vsr
, 2, 11),
9319 GEN_VXFORM(vpkuhum
, 7, 0),
9320 GEN_VXFORM(vpkuwum
, 7, 1),
9321 GEN_VXFORM(vpkuhus
, 7, 2),
9322 GEN_VXFORM(vpkuwus
, 7, 3),
9323 GEN_VXFORM(vpkshus
, 7, 4),
9324 GEN_VXFORM(vpkswus
, 7, 5),
9325 GEN_VXFORM(vpkshss
, 7, 6),
9326 GEN_VXFORM(vpkswss
, 7, 7),
9327 GEN_VXFORM(vpkpx
, 7, 12),
9328 GEN_VXFORM(vsum4ubs
, 4, 24),
9329 GEN_VXFORM(vsum4sbs
, 4, 28),
9330 GEN_VXFORM(vsum4shs
, 4, 25),
9331 GEN_VXFORM(vsum2sws
, 4, 26),
9332 GEN_VXFORM(vsumsws
, 4, 30),
9333 GEN_VXFORM(vaddfp
, 5, 0),
9334 GEN_VXFORM(vsubfp
, 5, 1),
9335 GEN_VXFORM(vmaxfp
, 5, 16),
9336 GEN_VXFORM(vminfp
, 5, 17),
9340 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
9341 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
9342 #define GEN_VXRFORM(name, opc2, opc3) \
9343 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
9344 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
9345 GEN_VXRFORM(vcmpequb
, 3, 0)
9346 GEN_VXRFORM(vcmpequh
, 3, 1)
9347 GEN_VXRFORM(vcmpequw
, 3, 2)
9348 GEN_VXRFORM(vcmpgtsb
, 3, 12)
9349 GEN_VXRFORM(vcmpgtsh
, 3, 13)
9350 GEN_VXRFORM(vcmpgtsw
, 3, 14)
9351 GEN_VXRFORM(vcmpgtub
, 3, 8)
9352 GEN_VXRFORM(vcmpgtuh
, 3, 9)
9353 GEN_VXRFORM(vcmpgtuw
, 3, 10)
9354 GEN_VXRFORM(vcmpeqfp
, 3, 3)
9355 GEN_VXRFORM(vcmpgefp
, 3, 7)
9356 GEN_VXRFORM(vcmpgtfp
, 3, 11)
9357 GEN_VXRFORM(vcmpbfp
, 3, 15)
9359 #undef GEN_VXFORM_SIMM
9360 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
9361 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9362 GEN_VXFORM_SIMM(vspltisb
, 6, 12),
9363 GEN_VXFORM_SIMM(vspltish
, 6, 13),
9364 GEN_VXFORM_SIMM(vspltisw
, 6, 14),
9366 #undef GEN_VXFORM_NOA
9367 #define GEN_VXFORM_NOA(name, opc2, opc3) \
9368 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
9369 GEN_VXFORM_NOA(vupkhsb
, 7, 8),
9370 GEN_VXFORM_NOA(vupkhsh
, 7, 9),
9371 GEN_VXFORM_NOA(vupklsb
, 7, 10),
9372 GEN_VXFORM_NOA(vupklsh
, 7, 11),
9373 GEN_VXFORM_NOA(vupkhpx
, 7, 13),
9374 GEN_VXFORM_NOA(vupklpx
, 7, 15),
9375 GEN_VXFORM_NOA(vrefp
, 5, 4),
9376 GEN_VXFORM_NOA(vrsqrtefp
, 5, 5),
9377 GEN_VXFORM_NOA(vexptefp
, 5, 6),
9378 GEN_VXFORM_NOA(vlogefp
, 5, 7),
9379 GEN_VXFORM_NOA(vrfim
, 5, 8),
9380 GEN_VXFORM_NOA(vrfin
, 5, 9),
9381 GEN_VXFORM_NOA(vrfip
, 5, 10),
9382 GEN_VXFORM_NOA(vrfiz
, 5, 11),
9384 #undef GEN_VXFORM_UIMM
9385 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
9386 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
9387 GEN_VXFORM_UIMM(vspltb
, 6, 8),
9388 GEN_VXFORM_UIMM(vsplth
, 6, 9),
9389 GEN_VXFORM_UIMM(vspltw
, 6, 10),
9390 GEN_VXFORM_UIMM(vcfux
, 5, 12),
9391 GEN_VXFORM_UIMM(vcfsx
, 5, 13),
9392 GEN_VXFORM_UIMM(vctuxs
, 5, 14),
9393 GEN_VXFORM_UIMM(vctsxs
, 5, 15),
9395 #undef GEN_VAFORM_PAIRED
9396 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
9397 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
9398 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16),
9399 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18),
9400 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19),
9401 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20),
9402 GEN_VAFORM_PAIRED(vsel
, vperm
, 21),
9403 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23),
9406 #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \
9407 GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE)
9408 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9409 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9410 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9411 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9412 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
9413 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
9414 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE
),
9415 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE
),
9416 GEN_SPE(evmra
, speundef
, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE
),
9417 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
),
9418 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9419 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9420 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9421 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE
),
9422 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE
),
9423 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE
),
9424 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE
),
9425 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9426 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9427 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9428 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9429 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE
),
9430 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE
),
9431 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE
),
9432 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9433 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE
),
9434 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE
),
9435 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE
),
9436 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE
),
9438 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9439 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
),
9440 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9441 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9442 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9443 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9444 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9445 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9446 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9447 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9448 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9449 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9450 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9451 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9453 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9454 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE
),
9455 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9456 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE
),
9457 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9458 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE
),
9459 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9460 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9461 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9462 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE
),
9463 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9464 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9465 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE
),
9466 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE
),
9468 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
),
9469 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9470 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE
),
9471 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9472 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE
),
9473 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9474 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
),
9475 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE
),
9476 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9477 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9478 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9479 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE
),
9480 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9481 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9482 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE
),
9483 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE
),
9485 #undef GEN_SPEOP_LDST
9486 #define GEN_SPEOP_LDST(name, opc2, sh) \
9487 GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
9488 GEN_SPEOP_LDST(evldd
, 0x00, 3),
9489 GEN_SPEOP_LDST(evldw
, 0x01, 3),
9490 GEN_SPEOP_LDST(evldh
, 0x02, 3),
9491 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1),
9492 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1),
9493 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1),
9494 GEN_SPEOP_LDST(evlwhe
, 0x08, 2),
9495 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2),
9496 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2),
9497 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2),
9498 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2),
9500 GEN_SPEOP_LDST(evstdd
, 0x10, 3),
9501 GEN_SPEOP_LDST(evstdw
, 0x11, 3),
9502 GEN_SPEOP_LDST(evstdh
, 0x12, 3),
9503 GEN_SPEOP_LDST(evstwhe
, 0x18, 2),
9504 GEN_SPEOP_LDST(evstwho
, 0x1A, 2),
9505 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2),
9506 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2),
9509 #include "helper_regs.h"
9510 #include "translate_init.c"
9512 /*****************************************************************************/
9513 /* Misc PowerPC helpers */
9514 void cpu_dump_state (CPUPPCState
*env
, FILE *f
, fprintf_function cpu_fprintf
,
9522 cpu_synchronize_state(env
);
9524 cpu_fprintf(f
, "NIP " TARGET_FMT_lx
" LR " TARGET_FMT_lx
" CTR "
9525 TARGET_FMT_lx
" XER " TARGET_FMT_lx
"\n",
9526 env
->nip
, env
->lr
, env
->ctr
, cpu_read_xer(env
));
9527 cpu_fprintf(f
, "MSR " TARGET_FMT_lx
" HID0 " TARGET_FMT_lx
" HF "
9528 TARGET_FMT_lx
" idx %d\n", env
->msr
, env
->spr
[SPR_HID0
],
9529 env
->hflags
, env
->mmu_idx
);
9530 #if !defined(NO_TIMER_DUMP)
9531 cpu_fprintf(f
, "TB %08" PRIu32
" %08" PRIu64
9532 #if !defined(CONFIG_USER_ONLY)
9536 cpu_ppc_load_tbu(env
), cpu_ppc_load_tbl(env
)
9537 #if !defined(CONFIG_USER_ONLY)
9538 , cpu_ppc_load_decr(env
)
9542 for (i
= 0; i
< 32; i
++) {
9543 if ((i
& (RGPL
- 1)) == 0)
9544 cpu_fprintf(f
, "GPR%02d", i
);
9545 cpu_fprintf(f
, " %016" PRIx64
, ppc_dump_gpr(env
, i
));
9546 if ((i
& (RGPL
- 1)) == (RGPL
- 1))
9547 cpu_fprintf(f
, "\n");
9549 cpu_fprintf(f
, "CR ");
9550 for (i
= 0; i
< 8; i
++)
9551 cpu_fprintf(f
, "%01x", env
->crf
[i
]);
9552 cpu_fprintf(f
, " [");
9553 for (i
= 0; i
< 8; i
++) {
9555 if (env
->crf
[i
] & 0x08)
9557 else if (env
->crf
[i
] & 0x04)
9559 else if (env
->crf
[i
] & 0x02)
9561 cpu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
9563 cpu_fprintf(f
, " ] RES " TARGET_FMT_lx
"\n",
9565 for (i
= 0; i
< 32; i
++) {
9566 if ((i
& (RFPL
- 1)) == 0)
9567 cpu_fprintf(f
, "FPR%02d", i
);
9568 cpu_fprintf(f
, " %016" PRIx64
, *((uint64_t *)&env
->fpr
[i
]));
9569 if ((i
& (RFPL
- 1)) == (RFPL
- 1))
9570 cpu_fprintf(f
, "\n");
9572 cpu_fprintf(f
, "FPSCR " TARGET_FMT_lx
"\n", env
->fpscr
);
9573 #if !defined(CONFIG_USER_ONLY)
9574 cpu_fprintf(f
, " SRR0 " TARGET_FMT_lx
" SRR1 " TARGET_FMT_lx
9575 " PVR " TARGET_FMT_lx
" VRSAVE " TARGET_FMT_lx
"\n",
9576 env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
],
9577 env
->spr
[SPR_PVR
], env
->spr
[SPR_VRSAVE
]);
9579 cpu_fprintf(f
, "SPRG0 " TARGET_FMT_lx
" SPRG1 " TARGET_FMT_lx
9580 " SPRG2 " TARGET_FMT_lx
" SPRG3 " TARGET_FMT_lx
"\n",
9581 env
->spr
[SPR_SPRG0
], env
->spr
[SPR_SPRG1
],
9582 env
->spr
[SPR_SPRG2
], env
->spr
[SPR_SPRG3
]);
9584 cpu_fprintf(f
, "SPRG4 " TARGET_FMT_lx
" SPRG5 " TARGET_FMT_lx
9585 " SPRG6 " TARGET_FMT_lx
" SPRG7 " TARGET_FMT_lx
"\n",
9586 env
->spr
[SPR_SPRG4
], env
->spr
[SPR_SPRG5
],
9587 env
->spr
[SPR_SPRG6
], env
->spr
[SPR_SPRG7
]);
9589 if (env
->excp_model
== POWERPC_EXCP_BOOKE
) {
9590 cpu_fprintf(f
, "CSRR0 " TARGET_FMT_lx
" CSRR1 " TARGET_FMT_lx
9591 " MCSRR0 " TARGET_FMT_lx
" MCSRR1 " TARGET_FMT_lx
"\n",
9592 env
->spr
[SPR_BOOKE_CSRR0
], env
->spr
[SPR_BOOKE_CSRR1
],
9593 env
->spr
[SPR_BOOKE_MCSRR0
], env
->spr
[SPR_BOOKE_MCSRR1
]);
9595 cpu_fprintf(f
, " TCR " TARGET_FMT_lx
" TSR " TARGET_FMT_lx
9596 " ESR " TARGET_FMT_lx
" DEAR " TARGET_FMT_lx
"\n",
9597 env
->spr
[SPR_BOOKE_TCR
], env
->spr
[SPR_BOOKE_TSR
],
9598 env
->spr
[SPR_BOOKE_ESR
], env
->spr
[SPR_BOOKE_DEAR
]);
9600 cpu_fprintf(f
, " PIR " TARGET_FMT_lx
" DECAR " TARGET_FMT_lx
9601 " IVPR " TARGET_FMT_lx
" EPCR " TARGET_FMT_lx
"\n",
9602 env
->spr
[SPR_BOOKE_PIR
], env
->spr
[SPR_BOOKE_DECAR
],
9603 env
->spr
[SPR_BOOKE_IVPR
], env
->spr
[SPR_BOOKE_EPCR
]);
9605 cpu_fprintf(f
, " MCSR " TARGET_FMT_lx
" SPRG8 " TARGET_FMT_lx
9606 " EPR " TARGET_FMT_lx
"\n",
9607 env
->spr
[SPR_BOOKE_MCSR
], env
->spr
[SPR_BOOKE_SPRG8
],
9608 env
->spr
[SPR_BOOKE_EPR
]);
9611 cpu_fprintf(f
, " MCAR " TARGET_FMT_lx
" PID1 " TARGET_FMT_lx
9612 " PID2 " TARGET_FMT_lx
" SVR " TARGET_FMT_lx
"\n",
9613 env
->spr
[SPR_Exxx_MCAR
], env
->spr
[SPR_BOOKE_PID1
],
9614 env
->spr
[SPR_BOOKE_PID2
], env
->spr
[SPR_E500_SVR
]);
9617 * IVORs are left out as they are large and do not change often --
9618 * they can be read with "p $ivor0", "p $ivor1", etc.
9622 #if defined(TARGET_PPC64)
9623 if (env
->flags
& POWERPC_FLAG_CFAR
) {
9624 cpu_fprintf(f
, " CFAR " TARGET_FMT_lx
"\n", env
->cfar
);
9628 switch (env
->mmu_model
) {
9629 case POWERPC_MMU_32B
:
9630 case POWERPC_MMU_601
:
9631 case POWERPC_MMU_SOFT_6xx
:
9632 case POWERPC_MMU_SOFT_74xx
:
9633 #if defined(TARGET_PPC64)
9634 case POWERPC_MMU_64B
:
9636 cpu_fprintf(f
, " SDR1 " TARGET_FMT_lx
"\n", env
->spr
[SPR_SDR1
]);
9638 case POWERPC_MMU_BOOKE206
:
9639 cpu_fprintf(f
, " MAS0 " TARGET_FMT_lx
" MAS1 " TARGET_FMT_lx
9640 " MAS2 " TARGET_FMT_lx
" MAS3 " TARGET_FMT_lx
"\n",
9641 env
->spr
[SPR_BOOKE_MAS0
], env
->spr
[SPR_BOOKE_MAS1
],
9642 env
->spr
[SPR_BOOKE_MAS2
], env
->spr
[SPR_BOOKE_MAS3
]);
9644 cpu_fprintf(f
, " MAS4 " TARGET_FMT_lx
" MAS6 " TARGET_FMT_lx
9645 " MAS7 " TARGET_FMT_lx
" PID " TARGET_FMT_lx
"\n",
9646 env
->spr
[SPR_BOOKE_MAS4
], env
->spr
[SPR_BOOKE_MAS6
],
9647 env
->spr
[SPR_BOOKE_MAS7
], env
->spr
[SPR_BOOKE_PID
]);
9649 cpu_fprintf(f
, "MMUCFG " TARGET_FMT_lx
" TLB0CFG " TARGET_FMT_lx
9650 " TLB1CFG " TARGET_FMT_lx
"\n",
9651 env
->spr
[SPR_MMUCFG
], env
->spr
[SPR_BOOKE_TLB0CFG
],
9652 env
->spr
[SPR_BOOKE_TLB1CFG
]);
9663 void cpu_dump_statistics (CPUPPCState
*env
, FILE*f
, fprintf_function cpu_fprintf
,
9666 #if defined(DO_PPC_STATISTICS)
9667 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
9671 for (op1
= 0; op1
< 64; op1
++) {
9673 if (is_indirect_opcode(handler
)) {
9674 t2
= ind_table(handler
);
9675 for (op2
= 0; op2
< 32; op2
++) {
9677 if (is_indirect_opcode(handler
)) {
9678 t3
= ind_table(handler
);
9679 for (op3
= 0; op3
< 32; op3
++) {
9681 if (handler
->count
== 0)
9683 cpu_fprintf(f
, "%02x %02x %02x (%02x %04d) %16s: "
9684 "%016" PRIx64
" %" PRId64
"\n",
9685 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
9687 handler
->count
, handler
->count
);
9690 if (handler
->count
== 0)
9692 cpu_fprintf(f
, "%02x %02x (%02x %04d) %16s: "
9693 "%016" PRIx64
" %" PRId64
"\n",
9694 op1
, op2
, op1
, op2
, handler
->oname
,
9695 handler
->count
, handler
->count
);
9699 if (handler
->count
== 0)
9701 cpu_fprintf(f
, "%02x (%02x ) %16s: %016" PRIx64
9703 op1
, op1
, handler
->oname
,
9704 handler
->count
, handler
->count
);
9710 /*****************************************************************************/
9711 static inline void gen_intermediate_code_internal(CPUPPCState
*env
,
9712 TranslationBlock
*tb
,
9715 DisasContext ctx
, *ctxp
= &ctx
;
9716 opc_handler_t
**table
, *handler
;
9717 target_ulong pc_start
;
9718 uint16_t *gen_opc_end
;
9725 gen_opc_end
= tcg_ctx
.gen_opc_buf
+ OPC_MAX_SIZE
;
9728 ctx
.exception
= POWERPC_EXCP_NONE
;
9729 ctx
.spr_cb
= env
->spr_cb
;
9730 ctx
.mem_idx
= env
->mmu_idx
;
9731 ctx
.access_type
= -1;
9732 ctx
.le_mode
= env
->hflags
& (1 << MSR_LE
) ? 1 : 0;
9733 #if defined(TARGET_PPC64)
9734 ctx
.sf_mode
= msr_is_64bit(env
, env
->msr
);
9735 ctx
.has_cfar
= !!(env
->flags
& POWERPC_FLAG_CFAR
);
9737 ctx
.fpu_enabled
= msr_fp
;
9738 if ((env
->flags
& POWERPC_FLAG_SPE
) && msr_spe
)
9739 ctx
.spe_enabled
= msr_spe
;
9741 ctx
.spe_enabled
= 0;
9742 if ((env
->flags
& POWERPC_FLAG_VRE
) && msr_vr
)
9743 ctx
.altivec_enabled
= msr_vr
;
9745 ctx
.altivec_enabled
= 0;
9746 if ((env
->flags
& POWERPC_FLAG_SE
) && msr_se
)
9747 ctx
.singlestep_enabled
= CPU_SINGLE_STEP
;
9749 ctx
.singlestep_enabled
= 0;
9750 if ((env
->flags
& POWERPC_FLAG_BE
) && msr_be
)
9751 ctx
.singlestep_enabled
|= CPU_BRANCH_STEP
;
9752 if (unlikely(env
->singlestep_enabled
))
9753 ctx
.singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
9754 #if defined (DO_SINGLE_STEP) && 0
9755 /* Single step trace mode */
9759 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
9761 max_insns
= CF_COUNT_MASK
;
9764 /* Set env in case of segfault during code fetch */
9765 while (ctx
.exception
== POWERPC_EXCP_NONE
9766 && tcg_ctx
.gen_opc_ptr
< gen_opc_end
) {
9767 if (unlikely(!QTAILQ_EMPTY(&env
->breakpoints
))) {
9768 QTAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
9769 if (bp
->pc
== ctx
.nip
) {
9770 gen_debug_exception(ctxp
);
9775 if (unlikely(search_pc
)) {
9776 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
9780 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
9782 tcg_ctx
.gen_opc_pc
[lj
] = ctx
.nip
;
9783 tcg_ctx
.gen_opc_instr_start
[lj
] = 1;
9784 tcg_ctx
.gen_opc_icount
[lj
] = num_insns
;
9786 LOG_DISAS("----------------\n");
9787 LOG_DISAS("nip=" TARGET_FMT_lx
" super=%d ir=%d\n",
9788 ctx
.nip
, ctx
.mem_idx
, (int)msr_ir
);
9789 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
9791 if (unlikely(ctx
.le_mode
)) {
9792 ctx
.opcode
= bswap32(cpu_ldl_code(env
, ctx
.nip
));
9794 ctx
.opcode
= cpu_ldl_code(env
, ctx
.nip
);
9796 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
9797 ctx
.opcode
, opc1(ctx
.opcode
), opc2(ctx
.opcode
),
9798 opc3(ctx
.opcode
), ctx
.le_mode
? "little" : "big");
9799 if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP
| CPU_LOG_TB_OP_OPT
))) {
9800 tcg_gen_debug_insn_start(ctx
.nip
);
9803 table
= env
->opcodes
;
9805 handler
= table
[opc1(ctx
.opcode
)];
9806 if (is_indirect_opcode(handler
)) {
9807 table
= ind_table(handler
);
9808 handler
= table
[opc2(ctx
.opcode
)];
9809 if (is_indirect_opcode(handler
)) {
9810 table
= ind_table(handler
);
9811 handler
= table
[opc3(ctx
.opcode
)];
9814 /* Is opcode *REALLY* valid ? */
9815 if (unlikely(handler
->handler
== &gen_invalid
)) {
9816 if (qemu_log_enabled()) {
9817 qemu_log("invalid/unsupported opcode: "
9818 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx
" %d\n",
9819 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
9820 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
9825 if (unlikely(handler
->type
& (PPC_SPE
| PPC_SPE_SINGLE
| PPC_SPE_DOUBLE
) && Rc(ctx
.opcode
))) {
9826 inval
= handler
->inval2
;
9828 inval
= handler
->inval1
;
9831 if (unlikely((ctx
.opcode
& inval
) != 0)) {
9832 if (qemu_log_enabled()) {
9833 qemu_log("invalid bits: %08x for opcode: "
9834 "%02x - %02x - %02x (%08x) " TARGET_FMT_lx
"\n",
9835 ctx
.opcode
& inval
, opc1(ctx
.opcode
),
9836 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
9837 ctx
.opcode
, ctx
.nip
- 4);
9839 gen_inval_exception(ctxp
, POWERPC_EXCP_INVAL_INVAL
);
9843 (*(handler
->handler
))(&ctx
);
9844 #if defined(DO_PPC_STATISTICS)
9847 /* Check trace mode exceptions */
9848 if (unlikely(ctx
.singlestep_enabled
& CPU_SINGLE_STEP
&&
9849 (ctx
.nip
<= 0x100 || ctx
.nip
> 0xF00) &&
9850 ctx
.exception
!= POWERPC_SYSCALL
&&
9851 ctx
.exception
!= POWERPC_EXCP_TRAP
&&
9852 ctx
.exception
!= POWERPC_EXCP_BRANCH
)) {
9853 gen_exception(ctxp
, POWERPC_EXCP_TRACE
);
9854 } else if (unlikely(((ctx
.nip
& (TARGET_PAGE_SIZE
- 1)) == 0) ||
9855 (env
->singlestep_enabled
) ||
9857 num_insns
>= max_insns
)) {
9858 /* if we reach a page boundary or are single stepping, stop
9864 if (tb
->cflags
& CF_LAST_IO
)
9866 if (ctx
.exception
== POWERPC_EXCP_NONE
) {
9867 gen_goto_tb(&ctx
, 0, ctx
.nip
);
9868 } else if (ctx
.exception
!= POWERPC_EXCP_BRANCH
) {
9869 if (unlikely(env
->singlestep_enabled
)) {
9870 gen_debug_exception(ctxp
);
9872 /* Generate the return instruction */
9875 gen_tb_end(tb
, num_insns
);
9876 *tcg_ctx
.gen_opc_ptr
= INDEX_op_end
;
9877 if (unlikely(search_pc
)) {
9878 j
= tcg_ctx
.gen_opc_ptr
- tcg_ctx
.gen_opc_buf
;
9881 tcg_ctx
.gen_opc_instr_start
[lj
++] = 0;
9883 tb
->size
= ctx
.nip
- pc_start
;
9884 tb
->icount
= num_insns
;
9886 #if defined(DEBUG_DISAS)
9887 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
9889 flags
= env
->bfd_mach
;
9890 flags
|= ctx
.le_mode
<< 16;
9891 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
9892 log_target_disas(env
, pc_start
, ctx
.nip
- pc_start
, flags
);
9898 void gen_intermediate_code (CPUPPCState
*env
, struct TranslationBlock
*tb
)
9900 gen_intermediate_code_internal(env
, tb
, 0);
9903 void gen_intermediate_code_pc (CPUPPCState
*env
, struct TranslationBlock
*tb
)
9905 gen_intermediate_code_internal(env
, tb
, 1);
9908 void restore_state_to_opc(CPUPPCState
*env
, TranslationBlock
*tb
, int pc_pos
)
9910 env
->nip
= tcg_ctx
.gen_opc_pc
[pc_pos
];