2 * PowerPC emulation for qemu: main translation routines.
4 * Copyright (c) 2003-2007 Jocelyn Mayer
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
29 #include "qemu-common.h"
30 #include "host-utils.h"
36 #define CPU_SINGLE_STEP 0x1
37 #define CPU_BRANCH_STEP 0x2
38 #define GDBSTUB_SINGLE_STEP 0x4
40 /* Include definitions for instructions classes and implementations flags */
41 //#define PPC_DEBUG_DISAS
42 //#define DO_PPC_STATISTICS
44 #ifdef PPC_DEBUG_DISAS
45 # define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
47 # define LOG_DISAS(...) do { } while (0)
49 /*****************************************************************************/
50 /* Code translation helpers */
52 /* global register indexes */
53 static TCGv_ptr cpu_env
;
54 static char cpu_reg_names
[10*3 + 22*4 /* GPR */
55 #if !defined(TARGET_PPC64)
56 + 10*4 + 22*5 /* SPE GPRh */
58 + 10*4 + 22*5 /* FPR */
59 + 2*(10*6 + 22*7) /* AVRh, AVRl */
61 static TCGv cpu_gpr
[32];
62 #if !defined(TARGET_PPC64)
63 static TCGv cpu_gprh
[32];
65 static TCGv_i64 cpu_fpr
[32];
66 static TCGv_i64 cpu_avrh
[32], cpu_avrl
[32];
67 static TCGv_i32 cpu_crf
[8];
73 static TCGv cpu_reserve
;
74 static TCGv_i32 cpu_fpscr
;
75 static TCGv_i32 cpu_access_type
;
77 #include "gen-icount.h"
79 void ppc_translate_init(void)
83 size_t cpu_reg_names_size
;
84 static int done_init
= 0;
89 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
92 cpu_reg_names_size
= sizeof(cpu_reg_names
);
94 for (i
= 0; i
< 8; i
++) {
95 snprintf(p
, cpu_reg_names_size
, "crf%d", i
);
96 cpu_crf
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
97 offsetof(CPUState
, crf
[i
]), p
);
99 cpu_reg_names_size
-= 5;
102 for (i
= 0; i
< 32; i
++) {
103 snprintf(p
, cpu_reg_names_size
, "r%d", i
);
104 cpu_gpr
[i
] = tcg_global_mem_new(TCG_AREG0
,
105 offsetof(CPUState
, gpr
[i
]), p
);
106 p
+= (i
< 10) ? 3 : 4;
107 cpu_reg_names_size
-= (i
< 10) ? 3 : 4;
108 #if !defined(TARGET_PPC64)
109 snprintf(p
, cpu_reg_names_size
, "r%dH", i
);
110 cpu_gprh
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
111 offsetof(CPUState
, gprh
[i
]), p
);
112 p
+= (i
< 10) ? 4 : 5;
113 cpu_reg_names_size
-= (i
< 10) ? 4 : 5;
116 snprintf(p
, cpu_reg_names_size
, "fp%d", i
);
117 cpu_fpr
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
118 offsetof(CPUState
, fpr
[i
]), p
);
119 p
+= (i
< 10) ? 4 : 5;
120 cpu_reg_names_size
-= (i
< 10) ? 4 : 5;
122 snprintf(p
, cpu_reg_names_size
, "avr%dH", i
);
123 #ifdef WORDS_BIGENDIAN
124 cpu_avrh
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
125 offsetof(CPUState
, avr
[i
].u64
[0]), p
);
127 cpu_avrh
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
128 offsetof(CPUState
, avr
[i
].u64
[1]), p
);
130 p
+= (i
< 10) ? 6 : 7;
131 cpu_reg_names_size
-= (i
< 10) ? 6 : 7;
133 snprintf(p
, cpu_reg_names_size
, "avr%dL", i
);
134 #ifdef WORDS_BIGENDIAN
135 cpu_avrl
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
136 offsetof(CPUState
, avr
[i
].u64
[1]), p
);
138 cpu_avrl
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
139 offsetof(CPUState
, avr
[i
].u64
[0]), p
);
141 p
+= (i
< 10) ? 6 : 7;
142 cpu_reg_names_size
-= (i
< 10) ? 6 : 7;
145 cpu_nip
= tcg_global_mem_new(TCG_AREG0
,
146 offsetof(CPUState
, nip
), "nip");
148 cpu_msr
= tcg_global_mem_new(TCG_AREG0
,
149 offsetof(CPUState
, msr
), "msr");
151 cpu_ctr
= tcg_global_mem_new(TCG_AREG0
,
152 offsetof(CPUState
, ctr
), "ctr");
154 cpu_lr
= tcg_global_mem_new(TCG_AREG0
,
155 offsetof(CPUState
, lr
), "lr");
157 cpu_xer
= tcg_global_mem_new(TCG_AREG0
,
158 offsetof(CPUState
, xer
), "xer");
160 cpu_reserve
= tcg_global_mem_new(TCG_AREG0
,
161 offsetof(CPUState
, reserve
), "reserve");
163 cpu_fpscr
= tcg_global_mem_new_i32(TCG_AREG0
,
164 offsetof(CPUState
, fpscr
), "fpscr");
166 cpu_access_type
= tcg_global_mem_new_i32(TCG_AREG0
,
167 offsetof(CPUState
, access_type
), "access_type");
169 /* register helpers */
176 /* internal defines */
177 typedef struct DisasContext
{
178 struct TranslationBlock
*tb
;
182 /* Routine used to access memory */
185 /* Translation flags */
187 #if defined(TARGET_PPC64)
193 ppc_spr_t
*spr_cb
; /* Needed to check rights for mfspr/mtspr */
194 int singlestep_enabled
;
197 struct opc_handler_t
{
200 /* instruction type */
203 void (*handler
)(DisasContext
*ctx
);
204 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
207 #if defined(DO_PPC_STATISTICS)
212 static always_inline
void gen_reset_fpstatus (void)
214 #ifdef CONFIG_SOFTFLOAT
215 gen_helper_reset_fpstatus();
219 static always_inline
void gen_compute_fprf (TCGv_i64 arg
, int set_fprf
, int set_rc
)
221 TCGv_i32 t0
= tcg_temp_new_i32();
224 /* This case might be optimized later */
225 tcg_gen_movi_i32(t0
, 1);
226 gen_helper_compute_fprf(t0
, arg
, t0
);
227 if (unlikely(set_rc
)) {
228 tcg_gen_mov_i32(cpu_crf
[1], t0
);
230 gen_helper_float_check_status();
231 } else if (unlikely(set_rc
)) {
232 /* We always need to compute fpcc */
233 tcg_gen_movi_i32(t0
, 0);
234 gen_helper_compute_fprf(t0
, arg
, t0
);
235 tcg_gen_mov_i32(cpu_crf
[1], t0
);
238 tcg_temp_free_i32(t0
);
241 static always_inline
void gen_set_access_type (DisasContext
*ctx
, int access_type
)
243 if (ctx
->access_type
!= access_type
) {
244 tcg_gen_movi_i32(cpu_access_type
, access_type
);
245 ctx
->access_type
= access_type
;
249 static always_inline
void gen_update_nip (DisasContext
*ctx
, target_ulong nip
)
251 #if defined(TARGET_PPC64)
253 tcg_gen_movi_tl(cpu_nip
, nip
);
256 tcg_gen_movi_tl(cpu_nip
, (uint32_t)nip
);
259 static always_inline
void gen_exception_err (DisasContext
*ctx
, uint32_t excp
, uint32_t error
)
262 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
263 gen_update_nip(ctx
, ctx
->nip
);
265 t0
= tcg_const_i32(excp
);
266 t1
= tcg_const_i32(error
);
267 gen_helper_raise_exception_err(t0
, t1
);
268 tcg_temp_free_i32(t0
);
269 tcg_temp_free_i32(t1
);
270 ctx
->exception
= (excp
);
273 static always_inline
void gen_exception (DisasContext
*ctx
, uint32_t excp
)
276 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
277 gen_update_nip(ctx
, ctx
->nip
);
279 t0
= tcg_const_i32(excp
);
280 gen_helper_raise_exception(t0
);
281 tcg_temp_free_i32(t0
);
282 ctx
->exception
= (excp
);
285 static always_inline
void gen_debug_exception (DisasContext
*ctx
)
289 if (ctx
->exception
!= POWERPC_EXCP_BRANCH
)
290 gen_update_nip(ctx
, ctx
->nip
);
291 t0
= tcg_const_i32(EXCP_DEBUG
);
292 gen_helper_raise_exception(t0
);
293 tcg_temp_free_i32(t0
);
296 static always_inline
void gen_inval_exception (DisasContext
*ctx
, uint32_t error
)
298 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_INVAL
| error
);
301 /* Stop translation */
302 static always_inline
void gen_stop_exception (DisasContext
*ctx
)
304 gen_update_nip(ctx
, ctx
->nip
);
305 ctx
->exception
= POWERPC_EXCP_STOP
;
308 /* No need to update nip here, as execution flow will change */
309 static always_inline
void gen_sync_exception (DisasContext
*ctx
)
311 ctx
->exception
= POWERPC_EXCP_SYNC
;
314 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
315 GEN_OPCODE(name, opc1, opc2, opc3, inval, type)
317 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
318 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type)
320 typedef struct opcode_t
{
321 unsigned char opc1
, opc2
, opc3
;
322 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
323 unsigned char pad
[5];
325 unsigned char pad
[1];
327 opc_handler_t handler
;
331 /*****************************************************************************/
332 /*** Instruction decoding ***/
333 #define EXTRACT_HELPER(name, shift, nb) \
334 static always_inline uint32_t name (uint32_t opcode) \
336 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
339 #define EXTRACT_SHELPER(name, shift, nb) \
340 static always_inline int32_t name (uint32_t opcode) \
342 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
346 EXTRACT_HELPER(opc1
, 26, 6);
348 EXTRACT_HELPER(opc2
, 1, 5);
350 EXTRACT_HELPER(opc3
, 6, 5);
351 /* Update Cr0 flags */
352 EXTRACT_HELPER(Rc
, 0, 1);
354 EXTRACT_HELPER(rD
, 21, 5);
356 EXTRACT_HELPER(rS
, 21, 5);
358 EXTRACT_HELPER(rA
, 16, 5);
360 EXTRACT_HELPER(rB
, 11, 5);
362 EXTRACT_HELPER(rC
, 6, 5);
364 EXTRACT_HELPER(crfD
, 23, 3);
365 EXTRACT_HELPER(crfS
, 18, 3);
366 EXTRACT_HELPER(crbD
, 21, 5);
367 EXTRACT_HELPER(crbA
, 16, 5);
368 EXTRACT_HELPER(crbB
, 11, 5);
370 EXTRACT_HELPER(_SPR
, 11, 10);
371 static always_inline
uint32_t SPR (uint32_t opcode
)
373 uint32_t sprn
= _SPR(opcode
);
375 return ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
377 /*** Get constants ***/
378 EXTRACT_HELPER(IMM
, 12, 8);
379 /* 16 bits signed immediate value */
380 EXTRACT_SHELPER(SIMM
, 0, 16);
381 /* 16 bits unsigned immediate value */
382 EXTRACT_HELPER(UIMM
, 0, 16);
383 /* 5 bits signed immediate value */
384 EXTRACT_HELPER(SIMM5
, 16, 5);
385 /* 5 bits signed immediate value */
386 EXTRACT_HELPER(UIMM5
, 16, 5);
388 EXTRACT_HELPER(NB
, 11, 5);
390 EXTRACT_HELPER(SH
, 11, 5);
391 /* Vector shift count */
392 EXTRACT_HELPER(VSH
, 6, 4);
394 EXTRACT_HELPER(MB
, 6, 5);
396 EXTRACT_HELPER(ME
, 1, 5);
398 EXTRACT_HELPER(TO
, 21, 5);
400 EXTRACT_HELPER(CRM
, 12, 8);
401 EXTRACT_HELPER(FM
, 17, 8);
402 EXTRACT_HELPER(SR
, 16, 4);
403 EXTRACT_HELPER(FPIMM
, 12, 4);
405 /*** Jump target decoding ***/
407 EXTRACT_SHELPER(d
, 0, 16);
408 /* Immediate address */
409 static always_inline target_ulong
LI (uint32_t opcode
)
411 return (opcode
>> 0) & 0x03FFFFFC;
414 static always_inline
uint32_t BD (uint32_t opcode
)
416 return (opcode
>> 0) & 0xFFFC;
419 EXTRACT_HELPER(BO
, 21, 5);
420 EXTRACT_HELPER(BI
, 16, 5);
421 /* Absolute/relative address */
422 EXTRACT_HELPER(AA
, 1, 1);
424 EXTRACT_HELPER(LK
, 0, 1);
426 /* Create a mask between <start> and <end> bits */
427 static always_inline target_ulong
MASK (uint32_t start
, uint32_t end
)
431 #if defined(TARGET_PPC64)
432 if (likely(start
== 0)) {
433 ret
= UINT64_MAX
<< (63 - end
);
434 } else if (likely(end
== 63)) {
435 ret
= UINT64_MAX
>> start
;
438 if (likely(start
== 0)) {
439 ret
= UINT32_MAX
<< (31 - end
);
440 } else if (likely(end
== 31)) {
441 ret
= UINT32_MAX
>> start
;
445 ret
= (((target_ulong
)(-1ULL)) >> (start
)) ^
446 (((target_ulong
)(-1ULL) >> (end
)) >> 1);
447 if (unlikely(start
> end
))
454 /*****************************************************************************/
455 /* PowerPC instructions table */
457 #if defined(DO_PPC_STATISTICS)
458 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
467 .handler = &gen_##name, \
468 .oname = stringify(name), \
470 .oname = stringify(name), \
472 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
481 .handler = &gen_##name, \
487 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
496 .handler = &gen_##name, \
498 .oname = stringify(name), \
500 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
509 .handler = &gen_##name, \
515 /* SPR load/store helpers */
516 static always_inline
void gen_load_spr(TCGv t
, int reg
)
518 tcg_gen_ld_tl(t
, cpu_env
, offsetof(CPUState
, spr
[reg
]));
521 static always_inline
void gen_store_spr(int reg
, TCGv t
)
523 tcg_gen_st_tl(t
, cpu_env
, offsetof(CPUState
, spr
[reg
]));
526 /* Invalid instruction */
527 static void gen_invalid(DisasContext
*ctx
)
529 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
532 static opc_handler_t invalid_handler
= {
535 .handler
= gen_invalid
,
538 /*** Integer comparison ***/
540 static always_inline
void gen_op_cmp(TCGv arg0
, TCGv arg1
, int s
, int crf
)
544 tcg_gen_trunc_tl_i32(cpu_crf
[crf
], cpu_xer
);
545 tcg_gen_shri_i32(cpu_crf
[crf
], cpu_crf
[crf
], XER_SO
);
546 tcg_gen_andi_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1);
548 l1
= gen_new_label();
549 l2
= gen_new_label();
550 l3
= gen_new_label();
552 tcg_gen_brcond_tl(TCG_COND_LT
, arg0
, arg1
, l1
);
553 tcg_gen_brcond_tl(TCG_COND_GT
, arg0
, arg1
, l2
);
555 tcg_gen_brcond_tl(TCG_COND_LTU
, arg0
, arg1
, l1
);
556 tcg_gen_brcond_tl(TCG_COND_GTU
, arg0
, arg1
, l2
);
558 tcg_gen_ori_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1 << CRF_EQ
);
561 tcg_gen_ori_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1 << CRF_LT
);
564 tcg_gen_ori_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1 << CRF_GT
);
568 static always_inline
void gen_op_cmpi(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
570 TCGv t0
= tcg_const_local_tl(arg1
);
571 gen_op_cmp(arg0
, t0
, s
, crf
);
575 #if defined(TARGET_PPC64)
576 static always_inline
void gen_op_cmp32(TCGv arg0
, TCGv arg1
, int s
, int crf
)
579 t0
= tcg_temp_local_new();
580 t1
= tcg_temp_local_new();
582 tcg_gen_ext32s_tl(t0
, arg0
);
583 tcg_gen_ext32s_tl(t1
, arg1
);
585 tcg_gen_ext32u_tl(t0
, arg0
);
586 tcg_gen_ext32u_tl(t1
, arg1
);
588 gen_op_cmp(t0
, t1
, s
, crf
);
593 static always_inline
void gen_op_cmpi32(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
595 TCGv t0
= tcg_const_local_tl(arg1
);
596 gen_op_cmp32(arg0
, t0
, s
, crf
);
601 static always_inline
void gen_set_Rc0 (DisasContext
*ctx
, TCGv reg
)
603 #if defined(TARGET_PPC64)
605 gen_op_cmpi32(reg
, 0, 1, 0);
608 gen_op_cmpi(reg
, 0, 1, 0);
612 static void gen_cmp(DisasContext
*ctx
)
614 #if defined(TARGET_PPC64)
615 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
616 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
617 1, crfD(ctx
->opcode
));
620 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
621 1, crfD(ctx
->opcode
));
625 static void gen_cmpi(DisasContext
*ctx
)
627 #if defined(TARGET_PPC64)
628 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
629 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
630 1, crfD(ctx
->opcode
));
633 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
634 1, crfD(ctx
->opcode
));
638 static void gen_cmpl(DisasContext
*ctx
)
640 #if defined(TARGET_PPC64)
641 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
642 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
643 0, crfD(ctx
->opcode
));
646 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
647 0, crfD(ctx
->opcode
));
651 static void gen_cmpli(DisasContext
*ctx
)
653 #if defined(TARGET_PPC64)
654 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
655 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
656 0, crfD(ctx
->opcode
));
659 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
660 0, crfD(ctx
->opcode
));
663 /* isel (PowerPC 2.03 specification) */
664 static void gen_isel(DisasContext
*ctx
)
667 uint32_t bi
= rC(ctx
->opcode
);
671 l1
= gen_new_label();
672 l2
= gen_new_label();
674 mask
= 1 << (3 - (bi
& 0x03));
675 t0
= tcg_temp_new_i32();
676 tcg_gen_andi_i32(t0
, cpu_crf
[bi
>> 2], mask
);
677 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
678 if (rA(ctx
->opcode
) == 0)
679 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
681 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
684 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
686 tcg_temp_free_i32(t0
);
689 /*** Integer arithmetic ***/
691 static always_inline
void gen_op_arith_compute_ov(DisasContext
*ctx
, TCGv arg0
, TCGv arg1
, TCGv arg2
, int sub
)
696 l1
= gen_new_label();
697 /* Start with XER OV disabled, the most likely case */
698 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
699 t0
= tcg_temp_local_new();
700 tcg_gen_xor_tl(t0
, arg0
, arg1
);
701 #if defined(TARGET_PPC64)
703 tcg_gen_ext32s_tl(t0
, t0
);
706 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0, l1
);
708 tcg_gen_brcondi_tl(TCG_COND_GE
, t0
, 0, l1
);
709 tcg_gen_xor_tl(t0
, arg1
, arg2
);
710 #if defined(TARGET_PPC64)
712 tcg_gen_ext32s_tl(t0
, t0
);
715 tcg_gen_brcondi_tl(TCG_COND_GE
, t0
, 0, l1
);
717 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0, l1
);
718 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
723 static always_inline
void gen_op_arith_compute_ca(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
, int sub
)
725 int l1
= gen_new_label();
727 #if defined(TARGET_PPC64)
728 if (!(ctx
->sf_mode
)) {
733 tcg_gen_ext32u_tl(t0
, arg1
);
734 tcg_gen_ext32u_tl(t1
, arg2
);
736 tcg_gen_brcond_tl(TCG_COND_GTU
, t0
, t1
, l1
);
738 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
740 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
748 tcg_gen_brcond_tl(TCG_COND_GTU
, arg1
, arg2
, l1
);
750 tcg_gen_brcond_tl(TCG_COND_GEU
, arg1
, arg2
, l1
);
752 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
757 /* Common add function */
758 static always_inline
void gen_op_arith_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
, TCGv arg2
,
759 int add_ca
, int compute_ca
, int compute_ov
)
763 if ((!compute_ca
&& !compute_ov
) ||
764 (!TCGV_EQUAL(ret
,arg1
) && !TCGV_EQUAL(ret
, arg2
))) {
767 t0
= tcg_temp_local_new();
771 t1
= tcg_temp_local_new();
772 tcg_gen_andi_tl(t1
, cpu_xer
, (1 << XER_CA
));
773 tcg_gen_shri_tl(t1
, t1
, XER_CA
);
778 if (compute_ca
&& compute_ov
) {
779 /* Start with XER CA and OV disabled, the most likely case */
780 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~((1 << XER_CA
) | (1 << XER_OV
)));
781 } else if (compute_ca
) {
782 /* Start with XER CA disabled, the most likely case */
783 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
784 } else if (compute_ov
) {
785 /* Start with XER OV disabled, the most likely case */
786 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
789 tcg_gen_add_tl(t0
, arg1
, arg2
);
792 gen_op_arith_compute_ca(ctx
, t0
, arg1
, 0);
795 tcg_gen_add_tl(t0
, t0
, t1
);
796 gen_op_arith_compute_ca(ctx
, t0
, t1
, 0);
800 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 0);
803 if (unlikely(Rc(ctx
->opcode
) != 0))
804 gen_set_Rc0(ctx
, t0
);
806 if (!TCGV_EQUAL(t0
, ret
)) {
807 tcg_gen_mov_tl(ret
, t0
);
811 /* Add functions with two operands */
812 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
813 static void glue(gen_, name)(DisasContext *ctx) \
815 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
816 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
817 add_ca, compute_ca, compute_ov); \
819 /* Add functions with one operand and one immediate */
820 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
821 add_ca, compute_ca, compute_ov) \
822 static void glue(gen_, name)(DisasContext *ctx) \
824 TCGv t0 = tcg_const_local_tl(const_val); \
825 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
826 cpu_gpr[rA(ctx->opcode)], t0, \
827 add_ca, compute_ca, compute_ov); \
831 /* add add. addo addo. */
832 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
833 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
834 /* addc addc. addco addco. */
835 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
836 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
837 /* adde adde. addeo addeo. */
838 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
839 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
840 /* addme addme. addmeo addmeo. */
841 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
842 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
843 /* addze addze. addzeo addzeo.*/
844 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
845 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
847 static void gen_addi(DisasContext
*ctx
)
849 target_long simm
= SIMM(ctx
->opcode
);
851 if (rA(ctx
->opcode
) == 0) {
853 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
);
855 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], simm
);
859 static always_inline
void gen_op_addic (DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
862 target_long simm
= SIMM(ctx
->opcode
);
864 /* Start with XER CA and OV disabled, the most likely case */
865 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
867 if (likely(simm
!= 0)) {
868 TCGv t0
= tcg_temp_local_new();
869 tcg_gen_addi_tl(t0
, arg1
, simm
);
870 gen_op_arith_compute_ca(ctx
, t0
, arg1
, 0);
871 tcg_gen_mov_tl(ret
, t0
);
874 tcg_gen_mov_tl(ret
, arg1
);
877 gen_set_Rc0(ctx
, ret
);
881 static void gen_addic(DisasContext
*ctx
)
883 gen_op_addic(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0);
886 static void gen_addic_(DisasContext
*ctx
)
888 gen_op_addic(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 1);
892 static void gen_addis(DisasContext
*ctx
)
894 target_long simm
= SIMM(ctx
->opcode
);
896 if (rA(ctx
->opcode
) == 0) {
898 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
<< 16);
900 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], simm
<< 16);
904 static always_inline
void gen_op_arith_divw (DisasContext
*ctx
, TCGv ret
, TCGv arg1
, TCGv arg2
,
905 int sign
, int compute_ov
)
907 int l1
= gen_new_label();
908 int l2
= gen_new_label();
909 TCGv_i32 t0
= tcg_temp_local_new_i32();
910 TCGv_i32 t1
= tcg_temp_local_new_i32();
912 tcg_gen_trunc_tl_i32(t0
, arg1
);
913 tcg_gen_trunc_tl_i32(t1
, arg2
);
914 tcg_gen_brcondi_i32(TCG_COND_EQ
, t1
, 0, l1
);
916 int l3
= gen_new_label();
917 tcg_gen_brcondi_i32(TCG_COND_NE
, t1
, -1, l3
);
918 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, INT32_MIN
, l1
);
920 tcg_gen_div_i32(t0
, t0
, t1
);
922 tcg_gen_divu_i32(t0
, t0
, t1
);
925 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
930 tcg_gen_sari_i32(t0
, t0
, 31);
932 tcg_gen_movi_i32(t0
, 0);
935 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
938 tcg_gen_extu_i32_tl(ret
, t0
);
939 tcg_temp_free_i32(t0
);
940 tcg_temp_free_i32(t1
);
941 if (unlikely(Rc(ctx
->opcode
) != 0))
942 gen_set_Rc0(ctx
, ret
);
945 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
946 static void glue(gen_, name)(DisasContext *ctx) \
948 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
949 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
952 /* divwu divwu. divwuo divwuo. */
953 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0);
954 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1);
955 /* divw divw. divwo divwo. */
956 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0);
957 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1);
958 #if defined(TARGET_PPC64)
959 static always_inline
void gen_op_arith_divd (DisasContext
*ctx
, TCGv ret
, TCGv arg1
, TCGv arg2
,
960 int sign
, int compute_ov
)
962 int l1
= gen_new_label();
963 int l2
= gen_new_label();
965 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg2
, 0, l1
);
967 int l3
= gen_new_label();
968 tcg_gen_brcondi_i64(TCG_COND_NE
, arg2
, -1, l3
);
969 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg1
, INT64_MIN
, l1
);
971 tcg_gen_div_i64(ret
, arg1
, arg2
);
973 tcg_gen_divu_i64(ret
, arg1
, arg2
);
976 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
981 tcg_gen_sari_i64(ret
, arg1
, 63);
983 tcg_gen_movi_i64(ret
, 0);
986 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
989 if (unlikely(Rc(ctx
->opcode
) != 0))
990 gen_set_Rc0(ctx
, ret
);
992 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
993 static void glue(gen_, name)(DisasContext *ctx) \
995 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
996 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
999 /* divwu divwu. divwuo divwuo. */
1000 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0);
1001 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1);
1002 /* divw divw. divwo divwo. */
1003 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0);
1004 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1);
1008 static void gen_mulhw(DisasContext
*ctx
)
1012 t0
= tcg_temp_new_i64();
1013 t1
= tcg_temp_new_i64();
1014 #if defined(TARGET_PPC64)
1015 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1016 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1017 tcg_gen_mul_i64(t0
, t0
, t1
);
1018 tcg_gen_shri_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
1020 tcg_gen_ext_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1021 tcg_gen_ext_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1022 tcg_gen_mul_i64(t0
, t0
, t1
);
1023 tcg_gen_shri_i64(t0
, t0
, 32);
1024 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1026 tcg_temp_free_i64(t0
);
1027 tcg_temp_free_i64(t1
);
1028 if (unlikely(Rc(ctx
->opcode
) != 0))
1029 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1032 /* mulhwu mulhwu. */
1033 static void gen_mulhwu(DisasContext
*ctx
)
1037 t0
= tcg_temp_new_i64();
1038 t1
= tcg_temp_new_i64();
1039 #if defined(TARGET_PPC64)
1040 tcg_gen_ext32u_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1041 tcg_gen_ext32u_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1042 tcg_gen_mul_i64(t0
, t0
, t1
);
1043 tcg_gen_shri_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
1045 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1046 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1047 tcg_gen_mul_i64(t0
, t0
, t1
);
1048 tcg_gen_shri_i64(t0
, t0
, 32);
1049 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1051 tcg_temp_free_i64(t0
);
1052 tcg_temp_free_i64(t1
);
1053 if (unlikely(Rc(ctx
->opcode
) != 0))
1054 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1058 static void gen_mullw(DisasContext
*ctx
)
1060 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1061 cpu_gpr
[rB(ctx
->opcode
)]);
1062 tcg_gen_ext32s_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)]);
1063 if (unlikely(Rc(ctx
->opcode
) != 0))
1064 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1067 /* mullwo mullwo. */
1068 static void gen_mullwo(DisasContext
*ctx
)
1073 t0
= tcg_temp_new_i64();
1074 t1
= tcg_temp_new_i64();
1075 l1
= gen_new_label();
1076 /* Start with XER OV disabled, the most likely case */
1077 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1078 #if defined(TARGET_PPC64)
1079 tcg_gen_ext32s_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1080 tcg_gen_ext32s_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1082 tcg_gen_ext_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1083 tcg_gen_ext_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1085 tcg_gen_mul_i64(t0
, t0
, t1
);
1086 #if defined(TARGET_PPC64)
1087 tcg_gen_ext32s_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1088 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, cpu_gpr
[rD(ctx
->opcode
)], l1
);
1090 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1091 tcg_gen_ext32s_i64(t1
, t0
);
1092 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
1094 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1096 tcg_temp_free_i64(t0
);
1097 tcg_temp_free_i64(t1
);
1098 if (unlikely(Rc(ctx
->opcode
) != 0))
1099 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1103 static void gen_mulli(DisasContext
*ctx
)
1105 tcg_gen_muli_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1108 #if defined(TARGET_PPC64)
1109 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
1110 static void glue(gen_, name)(DisasContext *ctx) \
1112 gen_helper_##name (cpu_gpr[rD(ctx->opcode)], \
1113 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
1114 if (unlikely(Rc(ctx->opcode) != 0)) \
1115 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1118 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00);
1119 /* mulhdu mulhdu. */
1120 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02);
1123 static void gen_mulld(DisasContext
*ctx
)
1125 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1126 cpu_gpr
[rB(ctx
->opcode
)]);
1127 if (unlikely(Rc(ctx
->opcode
) != 0))
1128 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1130 /* mulldo mulldo. */
1131 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17);
1134 /* neg neg. nego nego. */
1135 static always_inline
void gen_op_arith_neg (DisasContext
*ctx
, TCGv ret
, TCGv arg1
, int ov_check
)
1137 int l1
= gen_new_label();
1138 int l2
= gen_new_label();
1139 TCGv t0
= tcg_temp_local_new();
1140 #if defined(TARGET_PPC64)
1142 tcg_gen_mov_tl(t0
, arg1
);
1143 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, INT64_MIN
, l1
);
1147 tcg_gen_ext32s_tl(t0
, arg1
);
1148 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, INT32_MIN
, l1
);
1150 tcg_gen_neg_tl(ret
, arg1
);
1152 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1156 tcg_gen_mov_tl(ret
, t0
);
1158 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1162 if (unlikely(Rc(ctx
->opcode
) != 0))
1163 gen_set_Rc0(ctx
, ret
);
1166 static void gen_neg(DisasContext
*ctx
)
1168 gen_op_arith_neg(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0);
1171 static void gen_nego(DisasContext
*ctx
)
1173 gen_op_arith_neg(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 1);
1176 /* Common subf function */
1177 static always_inline
void gen_op_arith_subf(DisasContext
*ctx
, TCGv ret
, TCGv arg1
, TCGv arg2
,
1178 int add_ca
, int compute_ca
, int compute_ov
)
1182 if ((!compute_ca
&& !compute_ov
) ||
1183 (!TCGV_EQUAL(ret
, arg1
) && !TCGV_EQUAL(ret
, arg2
))) {
1186 t0
= tcg_temp_local_new();
1190 t1
= tcg_temp_local_new();
1191 tcg_gen_andi_tl(t1
, cpu_xer
, (1 << XER_CA
));
1192 tcg_gen_shri_tl(t1
, t1
, XER_CA
);
1197 if (compute_ca
&& compute_ov
) {
1198 /* Start with XER CA and OV disabled, the most likely case */
1199 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~((1 << XER_CA
) | (1 << XER_OV
)));
1200 } else if (compute_ca
) {
1201 /* Start with XER CA disabled, the most likely case */
1202 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1203 } else if (compute_ov
) {
1204 /* Start with XER OV disabled, the most likely case */
1205 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1209 tcg_gen_not_tl(t0
, arg1
);
1210 tcg_gen_add_tl(t0
, t0
, arg2
);
1211 gen_op_arith_compute_ca(ctx
, t0
, arg2
, 0);
1212 tcg_gen_add_tl(t0
, t0
, t1
);
1213 gen_op_arith_compute_ca(ctx
, t0
, t1
, 0);
1216 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1218 gen_op_arith_compute_ca(ctx
, t0
, arg2
, 1);
1222 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 1);
1225 if (unlikely(Rc(ctx
->opcode
) != 0))
1226 gen_set_Rc0(ctx
, t0
);
1228 if (!TCGV_EQUAL(t0
, ret
)) {
1229 tcg_gen_mov_tl(ret
, t0
);
1233 /* Sub functions with Two operands functions */
1234 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1235 static void glue(gen_, name)(DisasContext *ctx) \
1237 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1238 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1239 add_ca, compute_ca, compute_ov); \
1241 /* Sub functions with one operand and one immediate */
1242 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1243 add_ca, compute_ca, compute_ov) \
1244 static void glue(gen_, name)(DisasContext *ctx) \
1246 TCGv t0 = tcg_const_local_tl(const_val); \
1247 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1248 cpu_gpr[rA(ctx->opcode)], t0, \
1249 add_ca, compute_ca, compute_ov); \
1250 tcg_temp_free(t0); \
1252 /* subf subf. subfo subfo. */
1253 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
1254 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
1255 /* subfc subfc. subfco subfco. */
1256 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
1257 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
1258 /* subfe subfe. subfeo subfo. */
1259 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
1260 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
1261 /* subfme subfme. subfmeo subfmeo. */
1262 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
1263 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
1264 /* subfze subfze. subfzeo subfzeo.*/
1265 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
1266 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
1269 static void gen_subfic(DisasContext
*ctx
)
1271 /* Start with XER CA and OV disabled, the most likely case */
1272 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1273 TCGv t0
= tcg_temp_local_new();
1274 TCGv t1
= tcg_const_local_tl(SIMM(ctx
->opcode
));
1275 tcg_gen_sub_tl(t0
, t1
, cpu_gpr
[rA(ctx
->opcode
)]);
1276 gen_op_arith_compute_ca(ctx
, t0
, t1
, 1);
1278 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1282 /*** Integer logical ***/
1283 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1284 static void glue(gen_, name)(DisasContext *ctx) \
1286 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1287 cpu_gpr[rB(ctx->opcode)]); \
1288 if (unlikely(Rc(ctx->opcode) != 0)) \
1289 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1292 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1293 static void glue(gen_, name)(DisasContext *ctx) \
1295 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1296 if (unlikely(Rc(ctx->opcode) != 0)) \
1297 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1301 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
);
1303 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
);
1306 static void gen_andi_(DisasContext
*ctx
)
1308 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
));
1309 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1313 static void gen_andis_(DisasContext
*ctx
)
1315 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
) << 16);
1316 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1320 static void gen_cntlzw(DisasContext
*ctx
)
1322 gen_helper_cntlzw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1323 if (unlikely(Rc(ctx
->opcode
) != 0))
1324 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1327 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
);
1328 /* extsb & extsb. */
1329 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
);
1330 /* extsh & extsh. */
1331 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
);
1333 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
);
1335 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
);
1338 static void gen_or(DisasContext
*ctx
)
1342 rs
= rS(ctx
->opcode
);
1343 ra
= rA(ctx
->opcode
);
1344 rb
= rB(ctx
->opcode
);
1345 /* Optimisation for mr. ri case */
1346 if (rs
!= ra
|| rs
!= rb
) {
1348 tcg_gen_or_tl(cpu_gpr
[ra
], cpu_gpr
[rs
], cpu_gpr
[rb
]);
1350 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rs
]);
1351 if (unlikely(Rc(ctx
->opcode
) != 0))
1352 gen_set_Rc0(ctx
, cpu_gpr
[ra
]);
1353 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
1354 gen_set_Rc0(ctx
, cpu_gpr
[rs
]);
1355 #if defined(TARGET_PPC64)
1361 /* Set process priority to low */
1365 /* Set process priority to medium-low */
1369 /* Set process priority to normal */
1372 #if !defined(CONFIG_USER_ONLY)
1374 if (ctx
->mem_idx
> 0) {
1375 /* Set process priority to very low */
1380 if (ctx
->mem_idx
> 0) {
1381 /* Set process priority to medium-hight */
1386 if (ctx
->mem_idx
> 0) {
1387 /* Set process priority to high */
1392 if (ctx
->mem_idx
> 1) {
1393 /* Set process priority to very high */
1403 TCGv t0
= tcg_temp_new();
1404 gen_load_spr(t0
, SPR_PPR
);
1405 tcg_gen_andi_tl(t0
, t0
, ~0x001C000000000000ULL
);
1406 tcg_gen_ori_tl(t0
, t0
, ((uint64_t)prio
) << 50);
1407 gen_store_spr(SPR_PPR
, t0
);
1414 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
);
1417 static void gen_xor(DisasContext
*ctx
)
1419 /* Optimisation for "set to zero" case */
1420 if (rS(ctx
->opcode
) != rB(ctx
->opcode
))
1421 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1423 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1424 if (unlikely(Rc(ctx
->opcode
) != 0))
1425 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1429 static void gen_ori(DisasContext
*ctx
)
1431 target_ulong uimm
= UIMM(ctx
->opcode
);
1433 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1435 /* XXX: should handle special NOPs for POWER series */
1438 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1442 static void gen_oris(DisasContext
*ctx
)
1444 target_ulong uimm
= UIMM(ctx
->opcode
);
1446 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1450 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1454 static void gen_xori(DisasContext
*ctx
)
1456 target_ulong uimm
= UIMM(ctx
->opcode
);
1458 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1462 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1466 static void gen_xoris(DisasContext
*ctx
)
1468 target_ulong uimm
= UIMM(ctx
->opcode
);
1470 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1474 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1477 /* popcntb : PowerPC 2.03 specification */
1478 static void gen_popcntb(DisasContext
*ctx
)
1480 #if defined(TARGET_PPC64)
1482 gen_helper_popcntb_64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1485 gen_helper_popcntb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1488 #if defined(TARGET_PPC64)
1489 /* extsw & extsw. */
1490 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
);
1493 static void gen_cntlzd(DisasContext
*ctx
)
1495 gen_helper_cntlzd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1496 if (unlikely(Rc(ctx
->opcode
) != 0))
1497 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1501 /*** Integer rotate ***/
1503 /* rlwimi & rlwimi. */
1504 static void gen_rlwimi(DisasContext
*ctx
)
1506 uint32_t mb
, me
, sh
;
1508 mb
= MB(ctx
->opcode
);
1509 me
= ME(ctx
->opcode
);
1510 sh
= SH(ctx
->opcode
);
1511 if (likely(sh
== 0 && mb
== 0 && me
== 31)) {
1512 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1516 TCGv t0
= tcg_temp_new();
1517 #if defined(TARGET_PPC64)
1518 TCGv_i32 t2
= tcg_temp_new_i32();
1519 tcg_gen_trunc_i64_i32(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
1520 tcg_gen_rotli_i32(t2
, t2
, sh
);
1521 tcg_gen_extu_i32_i64(t0
, t2
);
1522 tcg_temp_free_i32(t2
);
1524 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1526 #if defined(TARGET_PPC64)
1530 mask
= MASK(mb
, me
);
1531 t1
= tcg_temp_new();
1532 tcg_gen_andi_tl(t0
, t0
, mask
);
1533 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1534 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1538 if (unlikely(Rc(ctx
->opcode
) != 0))
1539 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1542 /* rlwinm & rlwinm. */
1543 static void gen_rlwinm(DisasContext
*ctx
)
1545 uint32_t mb
, me
, sh
;
1547 sh
= SH(ctx
->opcode
);
1548 mb
= MB(ctx
->opcode
);
1549 me
= ME(ctx
->opcode
);
1551 if (likely(mb
== 0 && me
== (31 - sh
))) {
1552 if (likely(sh
== 0)) {
1553 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1555 TCGv t0
= tcg_temp_new();
1556 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1557 tcg_gen_shli_tl(t0
, t0
, sh
);
1558 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1561 } else if (likely(sh
!= 0 && me
== 31 && sh
== (32 - mb
))) {
1562 TCGv t0
= tcg_temp_new();
1563 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1564 tcg_gen_shri_tl(t0
, t0
, mb
);
1565 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1568 TCGv t0
= tcg_temp_new();
1569 #if defined(TARGET_PPC64)
1570 TCGv_i32 t1
= tcg_temp_new_i32();
1571 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1572 tcg_gen_rotli_i32(t1
, t1
, sh
);
1573 tcg_gen_extu_i32_i64(t0
, t1
);
1574 tcg_temp_free_i32(t1
);
1576 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1578 #if defined(TARGET_PPC64)
1582 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1585 if (unlikely(Rc(ctx
->opcode
) != 0))
1586 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1589 /* rlwnm & rlwnm. */
1590 static void gen_rlwnm(DisasContext
*ctx
)
1594 #if defined(TARGET_PPC64)
1598 mb
= MB(ctx
->opcode
);
1599 me
= ME(ctx
->opcode
);
1600 t0
= tcg_temp_new();
1601 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1602 #if defined(TARGET_PPC64)
1603 t1
= tcg_temp_new_i32();
1604 t2
= tcg_temp_new_i32();
1605 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1606 tcg_gen_trunc_i64_i32(t2
, t0
);
1607 tcg_gen_rotl_i32(t1
, t1
, t2
);
1608 tcg_gen_extu_i32_i64(t0
, t1
);
1609 tcg_temp_free_i32(t1
);
1610 tcg_temp_free_i32(t2
);
1612 tcg_gen_rotl_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1614 if (unlikely(mb
!= 0 || me
!= 31)) {
1615 #if defined(TARGET_PPC64)
1619 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1621 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1624 if (unlikely(Rc(ctx
->opcode
) != 0))
1625 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1628 #if defined(TARGET_PPC64)
1629 #define GEN_PPC64_R2(name, opc1, opc2) \
1630 static void glue(gen_, name##0)(DisasContext *ctx) \
1632 gen_##name(ctx, 0); \
1635 static void glue(gen_, name##1)(DisasContext *ctx) \
1637 gen_##name(ctx, 1); \
1639 #define GEN_PPC64_R4(name, opc1, opc2) \
1640 static void glue(gen_, name##0)(DisasContext *ctx) \
1642 gen_##name(ctx, 0, 0); \
1645 static void glue(gen_, name##1)(DisasContext *ctx) \
1647 gen_##name(ctx, 0, 1); \
1650 static void glue(gen_, name##2)(DisasContext *ctx) \
1652 gen_##name(ctx, 1, 0); \
1655 static void glue(gen_, name##3)(DisasContext *ctx) \
1657 gen_##name(ctx, 1, 1); \
1660 static always_inline
void gen_rldinm (DisasContext
*ctx
, uint32_t mb
,
1661 uint32_t me
, uint32_t sh
)
1663 if (likely(sh
!= 0 && mb
== 0 && me
== (63 - sh
))) {
1664 tcg_gen_shli_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
1665 } else if (likely(sh
!= 0 && me
== 63 && sh
== (64 - mb
))) {
1666 tcg_gen_shri_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], mb
);
1668 TCGv t0
= tcg_temp_new();
1669 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1670 if (likely(mb
== 0 && me
== 63)) {
1671 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1673 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1677 if (unlikely(Rc(ctx
->opcode
) != 0))
1678 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1680 /* rldicl - rldicl. */
1681 static always_inline
void gen_rldicl (DisasContext
*ctx
, int mbn
, int shn
)
1685 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1686 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1687 gen_rldinm(ctx
, mb
, 63, sh
);
1689 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
1690 /* rldicr - rldicr. */
1691 static always_inline
void gen_rldicr (DisasContext
*ctx
, int men
, int shn
)
1695 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1696 me
= MB(ctx
->opcode
) | (men
<< 5);
1697 gen_rldinm(ctx
, 0, me
, sh
);
1699 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
1700 /* rldic - rldic. */
1701 static always_inline
void gen_rldic (DisasContext
*ctx
, int mbn
, int shn
)
1705 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1706 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1707 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
1709 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
1711 static always_inline
void gen_rldnm (DisasContext
*ctx
, uint32_t mb
,
1716 mb
= MB(ctx
->opcode
);
1717 me
= ME(ctx
->opcode
);
1718 t0
= tcg_temp_new();
1719 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1720 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1721 if (unlikely(mb
!= 0 || me
!= 63)) {
1722 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1724 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1727 if (unlikely(Rc(ctx
->opcode
) != 0))
1728 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1731 /* rldcl - rldcl. */
1732 static always_inline
void gen_rldcl (DisasContext
*ctx
, int mbn
)
1736 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1737 gen_rldnm(ctx
, mb
, 63);
1739 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
1740 /* rldcr - rldcr. */
1741 static always_inline
void gen_rldcr (DisasContext
*ctx
, int men
)
1745 me
= MB(ctx
->opcode
) | (men
<< 5);
1746 gen_rldnm(ctx
, 0, me
);
1748 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
1749 /* rldimi - rldimi. */
1750 static always_inline
void gen_rldimi (DisasContext
*ctx
, int mbn
, int shn
)
1752 uint32_t sh
, mb
, me
;
1754 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1755 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1757 if (unlikely(sh
== 0 && mb
== 0)) {
1758 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1763 t0
= tcg_temp_new();
1764 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1765 t1
= tcg_temp_new();
1766 mask
= MASK(mb
, me
);
1767 tcg_gen_andi_tl(t0
, t0
, mask
);
1768 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1769 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1773 if (unlikely(Rc(ctx
->opcode
) != 0))
1774 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1776 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
1779 /*** Integer shift ***/
1782 static void gen_slw(DisasContext
*ctx
)
1786 l1
= gen_new_label();
1787 l2
= gen_new_label();
1789 t0
= tcg_temp_local_new();
1790 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1791 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0x20, l1
);
1792 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1795 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t0
);
1796 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
1799 if (unlikely(Rc(ctx
->opcode
) != 0))
1800 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1804 static void gen_sraw(DisasContext
*ctx
)
1806 gen_helper_sraw(cpu_gpr
[rA(ctx
->opcode
)],
1807 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1808 if (unlikely(Rc(ctx
->opcode
) != 0))
1809 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1812 /* srawi & srawi. */
1813 static void gen_srawi(DisasContext
*ctx
)
1815 int sh
= SH(ctx
->opcode
);
1819 l1
= gen_new_label();
1820 l2
= gen_new_label();
1821 t0
= tcg_temp_local_new();
1822 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1823 tcg_gen_brcondi_tl(TCG_COND_GE
, t0
, 0, l1
);
1824 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1ULL << sh
) - 1);
1825 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
1826 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
1829 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1831 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1832 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, sh
);
1835 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1836 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1838 if (unlikely(Rc(ctx
->opcode
) != 0))
1839 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1843 static void gen_srw(DisasContext
*ctx
)
1847 l1
= gen_new_label();
1848 l2
= gen_new_label();
1850 t0
= tcg_temp_local_new();
1851 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1852 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0x20, l1
);
1853 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1856 t1
= tcg_temp_new();
1857 tcg_gen_ext32u_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1858 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
, t0
);
1862 if (unlikely(Rc(ctx
->opcode
) != 0))
1863 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1866 #if defined(TARGET_PPC64)
1868 static void gen_sld(DisasContext
*ctx
)
1872 l1
= gen_new_label();
1873 l2
= gen_new_label();
1875 t0
= tcg_temp_local_new();
1876 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x7f);
1877 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0x40, l1
);
1878 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1881 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t0
);
1884 if (unlikely(Rc(ctx
->opcode
) != 0))
1885 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1889 static void gen_srad(DisasContext
*ctx
)
1891 gen_helper_srad(cpu_gpr
[rA(ctx
->opcode
)],
1892 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1893 if (unlikely(Rc(ctx
->opcode
) != 0))
1894 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1896 /* sradi & sradi. */
1897 static always_inline
void gen_sradi (DisasContext
*ctx
, int n
)
1899 int sh
= SH(ctx
->opcode
) + (n
<< 5);
1903 l1
= gen_new_label();
1904 l2
= gen_new_label();
1905 t0
= tcg_temp_local_new();
1906 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
1907 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1ULL << sh
) - 1);
1908 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
1909 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
1912 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1915 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
1917 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1918 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1920 if (unlikely(Rc(ctx
->opcode
) != 0))
1921 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1924 static void gen_sradi0(DisasContext
*ctx
)
1929 static void gen_sradi1(DisasContext
*ctx
)
1935 static void gen_srd(DisasContext
*ctx
)
1939 l1
= gen_new_label();
1940 l2
= gen_new_label();
1942 t0
= tcg_temp_local_new();
1943 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x7f);
1944 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0x40, l1
);
1945 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1948 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t0
);
1951 if (unlikely(Rc(ctx
->opcode
) != 0))
1952 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1956 /*** Floating-Point arithmetic ***/
1957 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
1958 static void gen_f##name(DisasContext *ctx) \
1960 if (unlikely(!ctx->fpu_enabled)) { \
1961 gen_exception(ctx, POWERPC_EXCP_FPU); \
1964 /* NIP cannot be restored if the memory exception comes from an helper */ \
1965 gen_update_nip(ctx, ctx->nip - 4); \
1966 gen_reset_fpstatus(); \
1967 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], \
1968 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
1970 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]); \
1972 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \
1973 Rc(ctx->opcode) != 0); \
1976 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
1977 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
1978 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
1980 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
1981 static void gen_f##name(DisasContext *ctx) \
1983 if (unlikely(!ctx->fpu_enabled)) { \
1984 gen_exception(ctx, POWERPC_EXCP_FPU); \
1987 /* NIP cannot be restored if the memory exception comes from an helper */ \
1988 gen_update_nip(ctx, ctx->nip - 4); \
1989 gen_reset_fpstatus(); \
1990 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], \
1991 cpu_fpr[rB(ctx->opcode)]); \
1993 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]); \
1995 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
1996 set_fprf, Rc(ctx->opcode) != 0); \
1998 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
1999 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2000 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2002 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2003 static void gen_f##name(DisasContext *ctx) \
2005 if (unlikely(!ctx->fpu_enabled)) { \
2006 gen_exception(ctx, POWERPC_EXCP_FPU); \
2009 /* NIP cannot be restored if the memory exception comes from an helper */ \
2010 gen_update_nip(ctx, ctx->nip - 4); \
2011 gen_reset_fpstatus(); \
2012 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], \
2013 cpu_fpr[rC(ctx->opcode)]); \
2015 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]); \
2017 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2018 set_fprf, Rc(ctx->opcode) != 0); \
2020 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2021 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2022 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2024 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
2025 static void gen_f##name(DisasContext *ctx) \
2027 if (unlikely(!ctx->fpu_enabled)) { \
2028 gen_exception(ctx, POWERPC_EXCP_FPU); \
2031 /* NIP cannot be restored if the memory exception comes from an helper */ \
2032 gen_update_nip(ctx, ctx->nip - 4); \
2033 gen_reset_fpstatus(); \
2034 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2035 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2036 set_fprf, Rc(ctx->opcode) != 0); \
2039 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
2040 static void gen_f##name(DisasContext *ctx) \
2042 if (unlikely(!ctx->fpu_enabled)) { \
2043 gen_exception(ctx, POWERPC_EXCP_FPU); \
2046 /* NIP cannot be restored if the memory exception comes from an helper */ \
2047 gen_update_nip(ctx, ctx->nip - 4); \
2048 gen_reset_fpstatus(); \
2049 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2050 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2051 set_fprf, Rc(ctx->opcode) != 0); \
2055 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
);
2057 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
);
2059 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
);
2062 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
);
2065 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
);
2068 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
);
2071 static void gen_frsqrtes(DisasContext
*ctx
)
2073 if (unlikely(!ctx
->fpu_enabled
)) {
2074 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2077 /* NIP cannot be restored if the memory exception comes from an helper */
2078 gen_update_nip(ctx
, ctx
->nip
- 4);
2079 gen_reset_fpstatus();
2080 gen_helper_frsqrte(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2081 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rD(ctx
->opcode
)]);
2082 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2086 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
);
2088 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
);
2092 static void gen_fsqrt(DisasContext
*ctx
)
2094 if (unlikely(!ctx
->fpu_enabled
)) {
2095 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2098 /* NIP cannot be restored if the memory exception comes from an helper */
2099 gen_update_nip(ctx
, ctx
->nip
- 4);
2100 gen_reset_fpstatus();
2101 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2102 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2105 static void gen_fsqrts(DisasContext
*ctx
)
2107 if (unlikely(!ctx
->fpu_enabled
)) {
2108 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2111 /* NIP cannot be restored if the memory exception comes from an helper */
2112 gen_update_nip(ctx
, ctx
->nip
- 4);
2113 gen_reset_fpstatus();
2114 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2115 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rD(ctx
->opcode
)]);
2116 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2119 /*** Floating-Point multiply-and-add ***/
2120 /* fmadd - fmadds */
2121 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
);
2122 /* fmsub - fmsubs */
2123 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
);
2124 /* fnmadd - fnmadds */
2125 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
);
2126 /* fnmsub - fnmsubs */
2127 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
);
2129 /*** Floating-Point round & convert ***/
2131 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
);
2133 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
);
2135 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
);
2136 #if defined(TARGET_PPC64)
2138 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
);
2140 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
);
2142 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
);
2146 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
);
2148 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
);
2150 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
);
2152 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
);
2154 /*** Floating-Point compare ***/
2157 static void gen_fcmpo(DisasContext
*ctx
)
2160 if (unlikely(!ctx
->fpu_enabled
)) {
2161 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2164 /* NIP cannot be restored if the memory exception comes from an helper */
2165 gen_update_nip(ctx
, ctx
->nip
- 4);
2166 gen_reset_fpstatus();
2167 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2168 gen_helper_fcmpo(cpu_fpr
[rA(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)], crf
);
2169 tcg_temp_free_i32(crf
);
2170 gen_helper_float_check_status();
2174 static void gen_fcmpu(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_fcmpu(cpu_fpr
[rA(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)], crf
);
2186 tcg_temp_free_i32(crf
);
2187 gen_helper_float_check_status();
2190 /*** Floating-point move ***/
2192 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2193 GEN_FLOAT_B(abs
, 0x08, 0x08, 0, PPC_FLOAT
);
2196 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2197 static void gen_fmr(DisasContext
*ctx
)
2199 if (unlikely(!ctx
->fpu_enabled
)) {
2200 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2203 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2204 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2208 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2209 GEN_FLOAT_B(nabs
, 0x08, 0x04, 0, PPC_FLOAT
);
2211 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2212 GEN_FLOAT_B(neg
, 0x08, 0x01, 0, PPC_FLOAT
);
2214 /*** Floating-Point status & ctrl register ***/
2217 static void gen_mcrfs(DisasContext
*ctx
)
2221 if (unlikely(!ctx
->fpu_enabled
)) {
2222 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2225 bfa
= 4 * (7 - crfS(ctx
->opcode
));
2226 tcg_gen_shri_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_fpscr
, bfa
);
2227 tcg_gen_andi_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfD(ctx
->opcode
)], 0xf);
2228 tcg_gen_andi_i32(cpu_fpscr
, cpu_fpscr
, ~(0xF << bfa
));
2232 static void gen_mffs(DisasContext
*ctx
)
2234 if (unlikely(!ctx
->fpu_enabled
)) {
2235 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2238 gen_reset_fpstatus();
2239 tcg_gen_extu_i32_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpscr
);
2240 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2244 static void gen_mtfsb0(DisasContext
*ctx
)
2248 if (unlikely(!ctx
->fpu_enabled
)) {
2249 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2252 crb
= 31 - crbD(ctx
->opcode
);
2253 gen_reset_fpstatus();
2254 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
)) {
2256 /* NIP cannot be restored if the memory exception comes from an helper */
2257 gen_update_nip(ctx
, ctx
->nip
- 4);
2258 t0
= tcg_const_i32(crb
);
2259 gen_helper_fpscr_clrbit(t0
);
2260 tcg_temp_free_i32(t0
);
2262 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2263 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2268 static void gen_mtfsb1(DisasContext
*ctx
)
2272 if (unlikely(!ctx
->fpu_enabled
)) {
2273 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2276 crb
= 31 - crbD(ctx
->opcode
);
2277 gen_reset_fpstatus();
2278 /* XXX: we pretend we can only do IEEE floating-point computations */
2279 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
&& crb
!= FPSCR_NI
)) {
2281 /* NIP cannot be restored if the memory exception comes from an helper */
2282 gen_update_nip(ctx
, ctx
->nip
- 4);
2283 t0
= tcg_const_i32(crb
);
2284 gen_helper_fpscr_setbit(t0
);
2285 tcg_temp_free_i32(t0
);
2287 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2288 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2290 /* We can raise a differed exception */
2291 gen_helper_float_check_status();
2295 static void gen_mtfsf(DisasContext
*ctx
)
2298 int L
= ctx
->opcode
& 0x02000000;
2300 if (unlikely(!ctx
->fpu_enabled
)) {
2301 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2304 /* NIP cannot be restored if the memory exception comes from an helper */
2305 gen_update_nip(ctx
, ctx
->nip
- 4);
2306 gen_reset_fpstatus();
2308 t0
= tcg_const_i32(0xff);
2310 t0
= tcg_const_i32(FM(ctx
->opcode
));
2311 gen_helper_store_fpscr(cpu_fpr
[rB(ctx
->opcode
)], t0
);
2312 tcg_temp_free_i32(t0
);
2313 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2314 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2316 /* We can raise a differed exception */
2317 gen_helper_float_check_status();
2321 static void gen_mtfsfi(DisasContext
*ctx
)
2327 if (unlikely(!ctx
->fpu_enabled
)) {
2328 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2331 bf
= crbD(ctx
->opcode
) >> 2;
2333 /* NIP cannot be restored if the memory exception comes from an helper */
2334 gen_update_nip(ctx
, ctx
->nip
- 4);
2335 gen_reset_fpstatus();
2336 t0
= tcg_const_i64(FPIMM(ctx
->opcode
) << (4 * sh
));
2337 t1
= tcg_const_i32(1 << sh
);
2338 gen_helper_store_fpscr(t0
, t1
);
2339 tcg_temp_free_i64(t0
);
2340 tcg_temp_free_i32(t1
);
2341 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2342 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2344 /* We can raise a differed exception */
2345 gen_helper_float_check_status();
2348 /*** Addressing modes ***/
2349 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2350 static always_inline
void gen_addr_imm_index (DisasContext
*ctx
, TCGv EA
, target_long maskl
)
2352 target_long simm
= SIMM(ctx
->opcode
);
2355 if (rA(ctx
->opcode
) == 0) {
2356 #if defined(TARGET_PPC64)
2357 if (!ctx
->sf_mode
) {
2358 tcg_gen_movi_tl(EA
, (uint32_t)simm
);
2361 tcg_gen_movi_tl(EA
, simm
);
2362 } else if (likely(simm
!= 0)) {
2363 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
);
2364 #if defined(TARGET_PPC64)
2365 if (!ctx
->sf_mode
) {
2366 tcg_gen_ext32u_tl(EA
, EA
);
2370 #if defined(TARGET_PPC64)
2371 if (!ctx
->sf_mode
) {
2372 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2375 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2379 static always_inline
void gen_addr_reg_index (DisasContext
*ctx
, TCGv EA
)
2381 if (rA(ctx
->opcode
) == 0) {
2382 #if defined(TARGET_PPC64)
2383 if (!ctx
->sf_mode
) {
2384 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2387 tcg_gen_mov_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2389 tcg_gen_add_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2390 #if defined(TARGET_PPC64)
2391 if (!ctx
->sf_mode
) {
2392 tcg_gen_ext32u_tl(EA
, EA
);
2398 static always_inline
void gen_addr_register (DisasContext
*ctx
, TCGv EA
)
2400 if (rA(ctx
->opcode
) == 0) {
2401 tcg_gen_movi_tl(EA
, 0);
2403 #if defined(TARGET_PPC64)
2404 if (!ctx
->sf_mode
) {
2405 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2408 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2412 static always_inline
void gen_addr_add (DisasContext
*ctx
, TCGv ret
, TCGv arg1
, target_long val
)
2414 tcg_gen_addi_tl(ret
, arg1
, val
);
2415 #if defined(TARGET_PPC64)
2416 if (!ctx
->sf_mode
) {
2417 tcg_gen_ext32u_tl(ret
, ret
);
2422 static always_inline
void gen_check_align (DisasContext
*ctx
, TCGv EA
, int mask
)
2424 int l1
= gen_new_label();
2425 TCGv t0
= tcg_temp_new();
2427 /* NIP cannot be restored if the memory exception comes from an helper */
2428 gen_update_nip(ctx
, ctx
->nip
- 4);
2429 tcg_gen_andi_tl(t0
, EA
, mask
);
2430 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2431 t1
= tcg_const_i32(POWERPC_EXCP_ALIGN
);
2432 t2
= tcg_const_i32(0);
2433 gen_helper_raise_exception_err(t1
, t2
);
2434 tcg_temp_free_i32(t1
);
2435 tcg_temp_free_i32(t2
);
2440 /*** Integer load ***/
2441 static always_inline
void gen_qemu_ld8u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2443 tcg_gen_qemu_ld8u(arg1
, arg2
, ctx
->mem_idx
);
2446 static always_inline
void gen_qemu_ld8s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2448 tcg_gen_qemu_ld8s(arg1
, arg2
, ctx
->mem_idx
);
2451 static always_inline
void gen_qemu_ld16u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2453 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2454 if (unlikely(ctx
->le_mode
)) {
2455 tcg_gen_bswap16_tl(arg1
, arg1
);
2459 static always_inline
void gen_qemu_ld16s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2461 if (unlikely(ctx
->le_mode
)) {
2462 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2463 tcg_gen_bswap16_tl(arg1
, arg1
);
2464 tcg_gen_ext16s_tl(arg1
, arg1
);
2466 tcg_gen_qemu_ld16s(arg1
, arg2
, ctx
->mem_idx
);
2470 static always_inline
void gen_qemu_ld32u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2472 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2473 if (unlikely(ctx
->le_mode
)) {
2474 tcg_gen_bswap32_tl(arg1
, arg1
);
2478 #if defined(TARGET_PPC64)
2479 static always_inline
void gen_qemu_ld32s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2481 if (unlikely(ctx
->le_mode
)) {
2482 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2483 tcg_gen_bswap32_tl(arg1
, arg1
);
2484 tcg_gen_ext32s_tl(arg1
, arg1
);
2486 tcg_gen_qemu_ld32s(arg1
, arg2
, ctx
->mem_idx
);
2490 static always_inline
void gen_qemu_ld64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2492 tcg_gen_qemu_ld64(arg1
, arg2
, ctx
->mem_idx
);
2493 if (unlikely(ctx
->le_mode
)) {
2494 tcg_gen_bswap64_i64(arg1
, arg1
);
2498 static always_inline
void gen_qemu_st8(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2500 tcg_gen_qemu_st8(arg1
, arg2
, ctx
->mem_idx
);
2503 static always_inline
void gen_qemu_st16(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2505 if (unlikely(ctx
->le_mode
)) {
2506 TCGv t0
= tcg_temp_new();
2507 tcg_gen_ext16u_tl(t0
, arg1
);
2508 tcg_gen_bswap16_tl(t0
, t0
);
2509 tcg_gen_qemu_st16(t0
, arg2
, ctx
->mem_idx
);
2512 tcg_gen_qemu_st16(arg1
, arg2
, ctx
->mem_idx
);
2516 static always_inline
void gen_qemu_st32(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2518 if (unlikely(ctx
->le_mode
)) {
2519 TCGv t0
= tcg_temp_new();
2520 tcg_gen_ext32u_tl(t0
, arg1
);
2521 tcg_gen_bswap32_tl(t0
, t0
);
2522 tcg_gen_qemu_st32(t0
, arg2
, ctx
->mem_idx
);
2525 tcg_gen_qemu_st32(arg1
, arg2
, ctx
->mem_idx
);
2529 static always_inline
void gen_qemu_st64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2531 if (unlikely(ctx
->le_mode
)) {
2532 TCGv_i64 t0
= tcg_temp_new_i64();
2533 tcg_gen_bswap64_i64(t0
, arg1
);
2534 tcg_gen_qemu_st64(t0
, arg2
, ctx
->mem_idx
);
2535 tcg_temp_free_i64(t0
);
2537 tcg_gen_qemu_st64(arg1
, arg2
, ctx
->mem_idx
);
2540 #define GEN_LD(name, ldop, opc, type) \
2541 static void glue(gen_, name)(DisasContext *ctx) \
2544 gen_set_access_type(ctx, ACCESS_INT); \
2545 EA = tcg_temp_new(); \
2546 gen_addr_imm_index(ctx, EA, 0); \
2547 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2548 tcg_temp_free(EA); \
2551 #define GEN_LDU(name, ldop, opc, type) \
2552 static void glue(gen_, name##u)(DisasContext *ctx) \
2555 if (unlikely(rA(ctx->opcode) == 0 || \
2556 rA(ctx->opcode) == rD(ctx->opcode))) { \
2557 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2560 gen_set_access_type(ctx, ACCESS_INT); \
2561 EA = tcg_temp_new(); \
2562 if (type == PPC_64B) \
2563 gen_addr_imm_index(ctx, EA, 0x03); \
2565 gen_addr_imm_index(ctx, EA, 0); \
2566 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2567 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2568 tcg_temp_free(EA); \
2571 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
2572 static void glue(gen_, name##ux)(DisasContext *ctx) \
2575 if (unlikely(rA(ctx->opcode) == 0 || \
2576 rA(ctx->opcode) == rD(ctx->opcode))) { \
2577 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2580 gen_set_access_type(ctx, ACCESS_INT); \
2581 EA = tcg_temp_new(); \
2582 gen_addr_reg_index(ctx, EA); \
2583 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2584 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2585 tcg_temp_free(EA); \
2588 #define GEN_LDX(name, ldop, opc2, opc3, type) \
2589 static void glue(gen_, name##x)(DisasContext *ctx) \
2592 gen_set_access_type(ctx, ACCESS_INT); \
2593 EA = tcg_temp_new(); \
2594 gen_addr_reg_index(ctx, EA); \
2595 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2596 tcg_temp_free(EA); \
2599 #define GEN_LDS(name, ldop, op, type) \
2600 GEN_LD(name, ldop, op | 0x20, type); \
2601 GEN_LDU(name, ldop, op | 0x21, type); \
2602 GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2603 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
2605 /* lbz lbzu lbzux lbzx */
2606 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
);
2607 /* lha lhau lhaux lhax */
2608 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
);
2609 /* lhz lhzu lhzux lhzx */
2610 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
);
2611 /* lwz lwzu lwzux lwzx */
2612 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
);
2613 #if defined(TARGET_PPC64)
2615 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
);
2617 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
);
2619 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
);
2621 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
);
2623 static void gen_ld(DisasContext
*ctx
)
2626 if (Rc(ctx
->opcode
)) {
2627 if (unlikely(rA(ctx
->opcode
) == 0 ||
2628 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
2629 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2633 gen_set_access_type(ctx
, ACCESS_INT
);
2634 EA
= tcg_temp_new();
2635 gen_addr_imm_index(ctx
, EA
, 0x03);
2636 if (ctx
->opcode
& 0x02) {
2637 /* lwa (lwau is undefined) */
2638 gen_qemu_ld32s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2641 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2643 if (Rc(ctx
->opcode
))
2644 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2649 static void gen_lq(DisasContext
*ctx
)
2651 #if defined(CONFIG_USER_ONLY)
2652 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2657 /* Restore CPU state */
2658 if (unlikely(ctx
->mem_idx
== 0)) {
2659 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2662 ra
= rA(ctx
->opcode
);
2663 rd
= rD(ctx
->opcode
);
2664 if (unlikely((rd
& 1) || rd
== ra
)) {
2665 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2668 if (unlikely(ctx
->le_mode
)) {
2669 /* Little-endian mode is not handled */
2670 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2673 gen_set_access_type(ctx
, ACCESS_INT
);
2674 EA
= tcg_temp_new();
2675 gen_addr_imm_index(ctx
, EA
, 0x0F);
2676 gen_qemu_ld64(ctx
, cpu_gpr
[rd
], EA
);
2677 gen_addr_add(ctx
, EA
, EA
, 8);
2678 gen_qemu_ld64(ctx
, cpu_gpr
[rd
+1], EA
);
2684 /*** Integer store ***/
2685 #define GEN_ST(name, stop, opc, type) \
2686 static void glue(gen_, name)(DisasContext *ctx) \
2689 gen_set_access_type(ctx, ACCESS_INT); \
2690 EA = tcg_temp_new(); \
2691 gen_addr_imm_index(ctx, EA, 0); \
2692 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2693 tcg_temp_free(EA); \
2696 #define GEN_STU(name, stop, opc, type) \
2697 static void glue(gen_, stop##u)(DisasContext *ctx) \
2700 if (unlikely(rA(ctx->opcode) == 0)) { \
2701 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2704 gen_set_access_type(ctx, ACCESS_INT); \
2705 EA = tcg_temp_new(); \
2706 if (type == PPC_64B) \
2707 gen_addr_imm_index(ctx, EA, 0x03); \
2709 gen_addr_imm_index(ctx, EA, 0); \
2710 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2711 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2712 tcg_temp_free(EA); \
2715 #define GEN_STUX(name, stop, opc2, opc3, type) \
2716 static void glue(gen_, name##ux)(DisasContext *ctx) \
2719 if (unlikely(rA(ctx->opcode) == 0)) { \
2720 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2723 gen_set_access_type(ctx, ACCESS_INT); \
2724 EA = tcg_temp_new(); \
2725 gen_addr_reg_index(ctx, EA); \
2726 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2727 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2728 tcg_temp_free(EA); \
2731 #define GEN_STX(name, stop, opc2, opc3, type) \
2732 static void glue(gen_, name##x)(DisasContext *ctx) \
2735 gen_set_access_type(ctx, ACCESS_INT); \
2736 EA = tcg_temp_new(); \
2737 gen_addr_reg_index(ctx, EA); \
2738 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2739 tcg_temp_free(EA); \
2742 #define GEN_STS(name, stop, op, type) \
2743 GEN_ST(name, stop, op | 0x20, type); \
2744 GEN_STU(name, stop, op | 0x21, type); \
2745 GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2746 GEN_STX(name, stop, 0x17, op | 0x00, type)
2748 /* stb stbu stbux stbx */
2749 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
);
2750 /* sth sthu sthux sthx */
2751 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
);
2752 /* stw stwu stwux stwx */
2753 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
);
2754 #if defined(TARGET_PPC64)
2755 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
);
2756 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
);
2758 static void gen_std(DisasContext
*ctx
)
2763 rs
= rS(ctx
->opcode
);
2764 if ((ctx
->opcode
& 0x3) == 0x2) {
2765 #if defined(CONFIG_USER_ONLY)
2766 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2769 if (unlikely(ctx
->mem_idx
== 0)) {
2770 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2773 if (unlikely(rs
& 1)) {
2774 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2777 if (unlikely(ctx
->le_mode
)) {
2778 /* Little-endian mode is not handled */
2779 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2782 gen_set_access_type(ctx
, ACCESS_INT
);
2783 EA
= tcg_temp_new();
2784 gen_addr_imm_index(ctx
, EA
, 0x03);
2785 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
2786 gen_addr_add(ctx
, EA
, EA
, 8);
2787 gen_qemu_st64(ctx
, cpu_gpr
[rs
+1], EA
);
2792 if (Rc(ctx
->opcode
)) {
2793 if (unlikely(rA(ctx
->opcode
) == 0)) {
2794 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2798 gen_set_access_type(ctx
, ACCESS_INT
);
2799 EA
= tcg_temp_new();
2800 gen_addr_imm_index(ctx
, EA
, 0x03);
2801 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
2802 if (Rc(ctx
->opcode
))
2803 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2808 /*** Integer load and store with byte reverse ***/
2810 static void always_inline
gen_qemu_ld16ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2812 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2813 if (likely(!ctx
->le_mode
)) {
2814 tcg_gen_bswap16_tl(arg1
, arg1
);
2817 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
);
2820 static void always_inline
gen_qemu_ld32ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2822 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2823 if (likely(!ctx
->le_mode
)) {
2824 tcg_gen_bswap32_tl(arg1
, arg1
);
2827 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
);
2830 static void always_inline
gen_qemu_st16r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2832 if (likely(!ctx
->le_mode
)) {
2833 TCGv t0
= tcg_temp_new();
2834 tcg_gen_ext16u_tl(t0
, arg1
);
2835 tcg_gen_bswap16_tl(t0
, t0
);
2836 tcg_gen_qemu_st16(t0
, arg2
, ctx
->mem_idx
);
2839 tcg_gen_qemu_st16(arg1
, arg2
, ctx
->mem_idx
);
2842 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
);
2845 static void always_inline
gen_qemu_st32r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2847 if (likely(!ctx
->le_mode
)) {
2848 TCGv t0
= tcg_temp_new();
2849 tcg_gen_ext32u_tl(t0
, arg1
);
2850 tcg_gen_bswap32_tl(t0
, t0
);
2851 tcg_gen_qemu_st32(t0
, arg2
, ctx
->mem_idx
);
2854 tcg_gen_qemu_st32(arg1
, arg2
, ctx
->mem_idx
);
2857 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
);
2859 /*** Integer load and store multiple ***/
2862 static void gen_lmw(DisasContext
*ctx
)
2866 gen_set_access_type(ctx
, ACCESS_INT
);
2867 /* NIP cannot be restored if the memory exception comes from an helper */
2868 gen_update_nip(ctx
, ctx
->nip
- 4);
2869 t0
= tcg_temp_new();
2870 t1
= tcg_const_i32(rD(ctx
->opcode
));
2871 gen_addr_imm_index(ctx
, t0
, 0);
2872 gen_helper_lmw(t0
, t1
);
2874 tcg_temp_free_i32(t1
);
2878 static void gen_stmw(DisasContext
*ctx
)
2882 gen_set_access_type(ctx
, ACCESS_INT
);
2883 /* NIP cannot be restored if the memory exception comes from an helper */
2884 gen_update_nip(ctx
, ctx
->nip
- 4);
2885 t0
= tcg_temp_new();
2886 t1
= tcg_const_i32(rS(ctx
->opcode
));
2887 gen_addr_imm_index(ctx
, t0
, 0);
2888 gen_helper_stmw(t0
, t1
);
2890 tcg_temp_free_i32(t1
);
2893 /*** Integer load and store strings ***/
2896 /* PowerPC32 specification says we must generate an exception if
2897 * rA is in the range of registers to be loaded.
2898 * In an other hand, IBM says this is valid, but rA won't be loaded.
2899 * For now, I'll follow the spec...
2901 static void gen_lswi(DisasContext
*ctx
)
2905 int nb
= NB(ctx
->opcode
);
2906 int start
= rD(ctx
->opcode
);
2907 int ra
= rA(ctx
->opcode
);
2913 if (unlikely(((start
+ nr
) > 32 &&
2914 start
<= ra
&& (start
+ nr
- 32) > ra
) ||
2915 ((start
+ nr
) <= 32 && start
<= ra
&& (start
+ nr
) > ra
))) {
2916 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
2919 gen_set_access_type(ctx
, ACCESS_INT
);
2920 /* NIP cannot be restored if the memory exception comes from an helper */
2921 gen_update_nip(ctx
, ctx
->nip
- 4);
2922 t0
= tcg_temp_new();
2923 gen_addr_register(ctx
, t0
);
2924 t1
= tcg_const_i32(nb
);
2925 t2
= tcg_const_i32(start
);
2926 gen_helper_lsw(t0
, t1
, t2
);
2928 tcg_temp_free_i32(t1
);
2929 tcg_temp_free_i32(t2
);
2933 static void gen_lswx(DisasContext
*ctx
)
2936 TCGv_i32 t1
, t2
, t3
;
2937 gen_set_access_type(ctx
, ACCESS_INT
);
2938 /* NIP cannot be restored if the memory exception comes from an helper */
2939 gen_update_nip(ctx
, ctx
->nip
- 4);
2940 t0
= tcg_temp_new();
2941 gen_addr_reg_index(ctx
, t0
);
2942 t1
= tcg_const_i32(rD(ctx
->opcode
));
2943 t2
= tcg_const_i32(rA(ctx
->opcode
));
2944 t3
= tcg_const_i32(rB(ctx
->opcode
));
2945 gen_helper_lswx(t0
, t1
, t2
, t3
);
2947 tcg_temp_free_i32(t1
);
2948 tcg_temp_free_i32(t2
);
2949 tcg_temp_free_i32(t3
);
2953 static void gen_stswi(DisasContext
*ctx
)
2957 int nb
= NB(ctx
->opcode
);
2958 gen_set_access_type(ctx
, ACCESS_INT
);
2959 /* NIP cannot be restored if the memory exception comes from an helper */
2960 gen_update_nip(ctx
, ctx
->nip
- 4);
2961 t0
= tcg_temp_new();
2962 gen_addr_register(ctx
, t0
);
2965 t1
= tcg_const_i32(nb
);
2966 t2
= tcg_const_i32(rS(ctx
->opcode
));
2967 gen_helper_stsw(t0
, t1
, t2
);
2969 tcg_temp_free_i32(t1
);
2970 tcg_temp_free_i32(t2
);
2974 static void gen_stswx(DisasContext
*ctx
)
2978 gen_set_access_type(ctx
, ACCESS_INT
);
2979 /* NIP cannot be restored if the memory exception comes from an helper */
2980 gen_update_nip(ctx
, ctx
->nip
- 4);
2981 t0
= tcg_temp_new();
2982 gen_addr_reg_index(ctx
, t0
);
2983 t1
= tcg_temp_new_i32();
2984 tcg_gen_trunc_tl_i32(t1
, cpu_xer
);
2985 tcg_gen_andi_i32(t1
, t1
, 0x7F);
2986 t2
= tcg_const_i32(rS(ctx
->opcode
));
2987 gen_helper_stsw(t0
, t1
, t2
);
2989 tcg_temp_free_i32(t1
);
2990 tcg_temp_free_i32(t2
);
2993 /*** Memory synchronisation ***/
2995 static void gen_eieio(DisasContext
*ctx
)
3000 static void gen_isync(DisasContext
*ctx
)
3002 gen_stop_exception(ctx
);
3006 static void gen_lwarx(DisasContext
*ctx
)
3009 gen_set_access_type(ctx
, ACCESS_RES
);
3010 t0
= tcg_temp_local_new();
3011 gen_addr_reg_index(ctx
, t0
);
3012 gen_check_align(ctx
, t0
, 0x03);
3013 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
3014 tcg_gen_mov_tl(cpu_reserve
, t0
);
3019 static void gen_stwcx_(DisasContext
*ctx
)
3023 gen_set_access_type(ctx
, ACCESS_RES
);
3024 t0
= tcg_temp_local_new();
3025 gen_addr_reg_index(ctx
, t0
);
3026 gen_check_align(ctx
, t0
, 0x03);
3027 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_xer
);
3028 tcg_gen_shri_i32(cpu_crf
[0], cpu_crf
[0], XER_SO
);
3029 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 1);
3030 l1
= gen_new_label();
3031 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
3032 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3033 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3035 tcg_gen_movi_tl(cpu_reserve
, -1);
3039 #if defined(TARGET_PPC64)
3041 static void gen_ldarx(DisasContext
*ctx
)
3044 gen_set_access_type(ctx
, ACCESS_RES
);
3045 t0
= tcg_temp_local_new();
3046 gen_addr_reg_index(ctx
, t0
);
3047 gen_check_align(ctx
, t0
, 0x07);
3048 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
3049 tcg_gen_mov_tl(cpu_reserve
, t0
);
3054 static void gen_stdcx_(DisasContext
*ctx
)
3058 gen_set_access_type(ctx
, ACCESS_RES
);
3059 t0
= tcg_temp_local_new();
3060 gen_addr_reg_index(ctx
, t0
);
3061 gen_check_align(ctx
, t0
, 0x07);
3062 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_xer
);
3063 tcg_gen_shri_i32(cpu_crf
[0], cpu_crf
[0], XER_SO
);
3064 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 1);
3065 l1
= gen_new_label();
3066 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
3067 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3068 gen_qemu_st64(ctx
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3070 tcg_gen_movi_tl(cpu_reserve
, -1);
3073 #endif /* defined(TARGET_PPC64) */
3076 static void gen_sync(DisasContext
*ctx
)
3081 static void gen_wait(DisasContext
*ctx
)
3083 TCGv_i32 t0
= tcg_temp_new_i32();
3084 tcg_gen_st_i32(t0
, cpu_env
, offsetof(CPUState
, halted
));
3085 tcg_temp_free_i32(t0
);
3086 /* Stop translation, as the CPU is supposed to sleep from now */
3087 gen_exception_err(ctx
, EXCP_HLT
, 1);
3090 /*** Floating-point load ***/
3091 #define GEN_LDF(name, ldop, opc, type) \
3092 static void glue(gen_, name)(DisasContext *ctx) \
3095 if (unlikely(!ctx->fpu_enabled)) { \
3096 gen_exception(ctx, POWERPC_EXCP_FPU); \
3099 gen_set_access_type(ctx, ACCESS_FLOAT); \
3100 EA = tcg_temp_new(); \
3101 gen_addr_imm_index(ctx, EA, 0); \
3102 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3103 tcg_temp_free(EA); \
3106 #define GEN_LDUF(name, ldop, opc, type) \
3107 static void glue(gen_, name##u)(DisasContext *ctx) \
3110 if (unlikely(!ctx->fpu_enabled)) { \
3111 gen_exception(ctx, POWERPC_EXCP_FPU); \
3114 if (unlikely(rA(ctx->opcode) == 0)) { \
3115 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3118 gen_set_access_type(ctx, ACCESS_FLOAT); \
3119 EA = tcg_temp_new(); \
3120 gen_addr_imm_index(ctx, EA, 0); \
3121 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3122 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3123 tcg_temp_free(EA); \
3126 #define GEN_LDUXF(name, ldop, opc, type) \
3127 static void glue(gen_, name##ux)(DisasContext *ctx) \
3130 if (unlikely(!ctx->fpu_enabled)) { \
3131 gen_exception(ctx, POWERPC_EXCP_FPU); \
3134 if (unlikely(rA(ctx->opcode) == 0)) { \
3135 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3138 gen_set_access_type(ctx, ACCESS_FLOAT); \
3139 EA = tcg_temp_new(); \
3140 gen_addr_reg_index(ctx, EA); \
3141 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3142 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3143 tcg_temp_free(EA); \
3146 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
3147 static void glue(gen_, name##x)(DisasContext *ctx) \
3150 if (unlikely(!ctx->fpu_enabled)) { \
3151 gen_exception(ctx, POWERPC_EXCP_FPU); \
3154 gen_set_access_type(ctx, ACCESS_FLOAT); \
3155 EA = tcg_temp_new(); \
3156 gen_addr_reg_index(ctx, EA); \
3157 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3158 tcg_temp_free(EA); \
3161 #define GEN_LDFS(name, ldop, op, type) \
3162 GEN_LDF(name, ldop, op | 0x20, type); \
3163 GEN_LDUF(name, ldop, op | 0x21, type); \
3164 GEN_LDUXF(name, ldop, op | 0x01, type); \
3165 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3167 static always_inline
void gen_qemu_ld32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3169 TCGv t0
= tcg_temp_new();
3170 TCGv_i32 t1
= tcg_temp_new_i32();
3171 gen_qemu_ld32u(ctx
, t0
, arg2
);
3172 tcg_gen_trunc_tl_i32(t1
, t0
);
3174 gen_helper_float32_to_float64(arg1
, t1
);
3175 tcg_temp_free_i32(t1
);
3178 /* lfd lfdu lfdux lfdx */
3179 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
);
3180 /* lfs lfsu lfsux lfsx */
3181 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
);
3183 /*** Floating-point store ***/
3184 #define GEN_STF(name, stop, opc, type) \
3185 static void glue(gen_, name)(DisasContext *ctx) \
3188 if (unlikely(!ctx->fpu_enabled)) { \
3189 gen_exception(ctx, POWERPC_EXCP_FPU); \
3192 gen_set_access_type(ctx, ACCESS_FLOAT); \
3193 EA = tcg_temp_new(); \
3194 gen_addr_imm_index(ctx, EA, 0); \
3195 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3196 tcg_temp_free(EA); \
3199 #define GEN_STUF(name, stop, opc, type) \
3200 static void glue(gen_, name##u)(DisasContext *ctx) \
3203 if (unlikely(!ctx->fpu_enabled)) { \
3204 gen_exception(ctx, POWERPC_EXCP_FPU); \
3207 if (unlikely(rA(ctx->opcode) == 0)) { \
3208 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3211 gen_set_access_type(ctx, ACCESS_FLOAT); \
3212 EA = tcg_temp_new(); \
3213 gen_addr_imm_index(ctx, EA, 0); \
3214 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3215 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3216 tcg_temp_free(EA); \
3219 #define GEN_STUXF(name, stop, opc, type) \
3220 static void glue(gen_, name##ux)(DisasContext *ctx) \
3223 if (unlikely(!ctx->fpu_enabled)) { \
3224 gen_exception(ctx, POWERPC_EXCP_FPU); \
3227 if (unlikely(rA(ctx->opcode) == 0)) { \
3228 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3231 gen_set_access_type(ctx, ACCESS_FLOAT); \
3232 EA = tcg_temp_new(); \
3233 gen_addr_reg_index(ctx, EA); \
3234 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3235 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3236 tcg_temp_free(EA); \
3239 #define GEN_STXF(name, stop, opc2, opc3, type) \
3240 static void glue(gen_, name##x)(DisasContext *ctx) \
3243 if (unlikely(!ctx->fpu_enabled)) { \
3244 gen_exception(ctx, POWERPC_EXCP_FPU); \
3247 gen_set_access_type(ctx, ACCESS_FLOAT); \
3248 EA = tcg_temp_new(); \
3249 gen_addr_reg_index(ctx, EA); \
3250 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3251 tcg_temp_free(EA); \
3254 #define GEN_STFS(name, stop, op, type) \
3255 GEN_STF(name, stop, op | 0x20, type); \
3256 GEN_STUF(name, stop, op | 0x21, type); \
3257 GEN_STUXF(name, stop, op | 0x01, type); \
3258 GEN_STXF(name, stop, 0x17, op | 0x00, type)
3260 static always_inline
void gen_qemu_st32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3262 TCGv_i32 t0
= tcg_temp_new_i32();
3263 TCGv t1
= tcg_temp_new();
3264 gen_helper_float64_to_float32(t0
, arg1
);
3265 tcg_gen_extu_i32_tl(t1
, t0
);
3266 tcg_temp_free_i32(t0
);
3267 gen_qemu_st32(ctx
, t1
, arg2
);
3271 /* stfd stfdu stfdux stfdx */
3272 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
);
3273 /* stfs stfsu stfsux stfsx */
3274 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
);
3277 static always_inline
void gen_qemu_st32fiw(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3279 TCGv t0
= tcg_temp_new();
3280 tcg_gen_trunc_i64_tl(t0
, arg1
),
3281 gen_qemu_st32(ctx
, t0
, arg2
);
3285 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
);
3288 static always_inline
void gen_goto_tb (DisasContext
*ctx
, int n
,
3291 TranslationBlock
*tb
;
3293 #if defined(TARGET_PPC64)
3295 dest
= (uint32_t) dest
;
3297 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
3298 likely(!ctx
->singlestep_enabled
)) {
3300 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3301 tcg_gen_exit_tb((long)tb
+ n
);
3303 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3304 if (unlikely(ctx
->singlestep_enabled
)) {
3305 if ((ctx
->singlestep_enabled
&
3306 (CPU_BRANCH_STEP
| CPU_SINGLE_STEP
)) &&
3307 ctx
->exception
== POWERPC_EXCP_BRANCH
) {
3308 target_ulong tmp
= ctx
->nip
;
3310 gen_exception(ctx
, POWERPC_EXCP_TRACE
);
3313 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
3314 gen_debug_exception(ctx
);
3321 static always_inline
void gen_setlr (DisasContext
*ctx
, target_ulong nip
)
3323 #if defined(TARGET_PPC64)
3324 if (ctx
->sf_mode
== 0)
3325 tcg_gen_movi_tl(cpu_lr
, (uint32_t)nip
);
3328 tcg_gen_movi_tl(cpu_lr
, nip
);
3332 static void gen_b(DisasContext
*ctx
)
3334 target_ulong li
, target
;
3336 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3337 /* sign extend LI */
3338 #if defined(TARGET_PPC64)
3340 li
= ((int64_t)LI(ctx
->opcode
) << 38) >> 38;
3343 li
= ((int32_t)LI(ctx
->opcode
) << 6) >> 6;
3344 if (likely(AA(ctx
->opcode
) == 0))
3345 target
= ctx
->nip
+ li
- 4;
3348 if (LK(ctx
->opcode
))
3349 gen_setlr(ctx
, ctx
->nip
);
3350 gen_goto_tb(ctx
, 0, target
);
3357 static always_inline
void gen_bcond (DisasContext
*ctx
, int type
)
3359 uint32_t bo
= BO(ctx
->opcode
);
3360 int l1
= gen_new_label();
3363 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3364 if (type
== BCOND_LR
|| type
== BCOND_CTR
) {
3365 target
= tcg_temp_local_new();
3366 if (type
== BCOND_CTR
)
3367 tcg_gen_mov_tl(target
, cpu_ctr
);
3369 tcg_gen_mov_tl(target
, cpu_lr
);
3371 TCGV_UNUSED(target
);
3373 if (LK(ctx
->opcode
))
3374 gen_setlr(ctx
, ctx
->nip
);
3375 l1
= gen_new_label();
3376 if ((bo
& 0x4) == 0) {
3377 /* Decrement and test CTR */
3378 TCGv temp
= tcg_temp_new();
3379 if (unlikely(type
== BCOND_CTR
)) {
3380 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3383 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
3384 #if defined(TARGET_PPC64)
3386 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
3389 tcg_gen_mov_tl(temp
, cpu_ctr
);
3391 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
3393 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
3395 tcg_temp_free(temp
);
3397 if ((bo
& 0x10) == 0) {
3399 uint32_t bi
= BI(ctx
->opcode
);
3400 uint32_t mask
= 1 << (3 - (bi
& 0x03));
3401 TCGv_i32 temp
= tcg_temp_new_i32();
3404 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3405 tcg_gen_brcondi_i32(TCG_COND_EQ
, temp
, 0, l1
);
3407 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3408 tcg_gen_brcondi_i32(TCG_COND_NE
, temp
, 0, l1
);
3410 tcg_temp_free_i32(temp
);
3412 if (type
== BCOND_IM
) {
3413 target_ulong li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
3414 if (likely(AA(ctx
->opcode
) == 0)) {
3415 gen_goto_tb(ctx
, 0, ctx
->nip
+ li
- 4);
3417 gen_goto_tb(ctx
, 0, li
);
3420 gen_goto_tb(ctx
, 1, ctx
->nip
);
3422 #if defined(TARGET_PPC64)
3423 if (!(ctx
->sf_mode
))
3424 tcg_gen_andi_tl(cpu_nip
, target
, (uint32_t)~3);
3427 tcg_gen_andi_tl(cpu_nip
, target
, ~3);
3430 #if defined(TARGET_PPC64)
3431 if (!(ctx
->sf_mode
))
3432 tcg_gen_movi_tl(cpu_nip
, (uint32_t)ctx
->nip
);
3435 tcg_gen_movi_tl(cpu_nip
, ctx
->nip
);
3440 static void gen_bc(DisasContext
*ctx
)
3442 gen_bcond(ctx
, BCOND_IM
);
3445 static void gen_bcctr(DisasContext
*ctx
)
3447 gen_bcond(ctx
, BCOND_CTR
);
3450 static void gen_bclr(DisasContext
*ctx
)
3452 gen_bcond(ctx
, BCOND_LR
);
3455 /*** Condition register logical ***/
3456 #define GEN_CRLOGIC(name, tcg_op, opc) \
3457 static void glue(gen_, name)(DisasContext *ctx) \
3462 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3463 t0 = tcg_temp_new_i32(); \
3465 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
3467 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
3469 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
3470 t1 = tcg_temp_new_i32(); \
3471 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3473 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
3475 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
3477 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3478 tcg_op(t0, t0, t1); \
3479 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
3480 tcg_gen_andi_i32(t0, t0, bitmask); \
3481 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3482 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
3483 tcg_temp_free_i32(t0); \
3484 tcg_temp_free_i32(t1); \
3488 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08);
3490 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04);
3492 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09);
3494 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07);
3496 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01);
3498 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E);
3500 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D);
3502 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06);
3505 static void gen_mcrf(DisasContext
*ctx
)
3507 tcg_gen_mov_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfS(ctx
->opcode
)]);
3510 /*** System linkage ***/
3512 /* rfi (mem_idx only) */
3513 static void gen_rfi(DisasContext
*ctx
)
3515 #if defined(CONFIG_USER_ONLY)
3516 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3518 /* Restore CPU state */
3519 if (unlikely(!ctx
->mem_idx
)) {
3520 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3524 gen_sync_exception(ctx
);
3528 #if defined(TARGET_PPC64)
3529 static void gen_rfid(DisasContext
*ctx
)
3531 #if defined(CONFIG_USER_ONLY)
3532 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3534 /* Restore CPU state */
3535 if (unlikely(!ctx
->mem_idx
)) {
3536 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3540 gen_sync_exception(ctx
);
3544 static void gen_hrfid(DisasContext
*ctx
)
3546 #if defined(CONFIG_USER_ONLY)
3547 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3549 /* Restore CPU state */
3550 if (unlikely(ctx
->mem_idx
<= 1)) {
3551 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3555 gen_sync_exception(ctx
);
3561 #if defined(CONFIG_USER_ONLY)
3562 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3564 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3566 static void gen_sc(DisasContext
*ctx
)
3570 lev
= (ctx
->opcode
>> 5) & 0x7F;
3571 gen_exception_err(ctx
, POWERPC_SYSCALL
, lev
);
3577 static void gen_tw(DisasContext
*ctx
)
3579 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3580 /* Update the nip since this might generate a trap exception */
3581 gen_update_nip(ctx
, ctx
->nip
);
3582 gen_helper_tw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
3583 tcg_temp_free_i32(t0
);
3587 static void gen_twi(DisasContext
*ctx
)
3589 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3590 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
3591 /* Update the nip since this might generate a trap exception */
3592 gen_update_nip(ctx
, ctx
->nip
);
3593 gen_helper_tw(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3595 tcg_temp_free_i32(t1
);
3598 #if defined(TARGET_PPC64)
3600 static void gen_td(DisasContext
*ctx
)
3602 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3603 /* Update the nip since this might generate a trap exception */
3604 gen_update_nip(ctx
, ctx
->nip
);
3605 gen_helper_td(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
3606 tcg_temp_free_i32(t0
);
3610 static void gen_tdi(DisasContext
*ctx
)
3612 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3613 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
3614 /* Update the nip since this might generate a trap exception */
3615 gen_update_nip(ctx
, ctx
->nip
);
3616 gen_helper_td(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3618 tcg_temp_free_i32(t1
);
3622 /*** Processor control ***/
3625 static void gen_mcrxr(DisasContext
*ctx
)
3627 tcg_gen_trunc_tl_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_xer
);
3628 tcg_gen_shri_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfD(ctx
->opcode
)], XER_CA
);
3629 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_SO
| 1 << XER_OV
| 1 << XER_CA
));
3633 static void gen_mfcr(DisasContext
*ctx
)
3637 if (likely(ctx
->opcode
& 0x00100000)) {
3638 crm
= CRM(ctx
->opcode
);
3639 if (likely(crm
&& ((crm
& (crm
- 1)) == 0))) {
3641 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_crf
[7 - crn
]);
3642 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)],
3643 cpu_gpr
[rD(ctx
->opcode
)], crn
* 4);
3646 TCGv_i32 t0
= tcg_temp_new_i32();
3647 tcg_gen_mov_i32(t0
, cpu_crf
[0]);
3648 tcg_gen_shli_i32(t0
, t0
, 4);
3649 tcg_gen_or_i32(t0
, t0
, cpu_crf
[1]);
3650 tcg_gen_shli_i32(t0
, t0
, 4);
3651 tcg_gen_or_i32(t0
, t0
, cpu_crf
[2]);
3652 tcg_gen_shli_i32(t0
, t0
, 4);
3653 tcg_gen_or_i32(t0
, t0
, cpu_crf
[3]);
3654 tcg_gen_shli_i32(t0
, t0
, 4);
3655 tcg_gen_or_i32(t0
, t0
, cpu_crf
[4]);
3656 tcg_gen_shli_i32(t0
, t0
, 4);
3657 tcg_gen_or_i32(t0
, t0
, cpu_crf
[5]);
3658 tcg_gen_shli_i32(t0
, t0
, 4);
3659 tcg_gen_or_i32(t0
, t0
, cpu_crf
[6]);
3660 tcg_gen_shli_i32(t0
, t0
, 4);
3661 tcg_gen_or_i32(t0
, t0
, cpu_crf
[7]);
3662 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
3663 tcg_temp_free_i32(t0
);
3668 static void gen_mfmsr(DisasContext
*ctx
)
3670 #if defined(CONFIG_USER_ONLY)
3671 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3673 if (unlikely(!ctx
->mem_idx
)) {
3674 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3677 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_msr
);
3682 #define SPR_NOACCESS ((void *)(-1UL))
3684 static void spr_noaccess (void *opaque
, int sprn
)
3686 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
3687 printf("ERROR: try to access SPR %d !\n", sprn
);
3689 #define SPR_NOACCESS (&spr_noaccess)
3693 static always_inline
void gen_op_mfspr (DisasContext
*ctx
)
3695 void (*read_cb
)(void *opaque
, int gprn
, int sprn
);
3696 uint32_t sprn
= SPR(ctx
->opcode
);
3698 #if !defined(CONFIG_USER_ONLY)
3699 if (ctx
->mem_idx
== 2)
3700 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
3701 else if (ctx
->mem_idx
)
3702 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
3705 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
3706 if (likely(read_cb
!= NULL
)) {
3707 if (likely(read_cb
!= SPR_NOACCESS
)) {
3708 (*read_cb
)(ctx
, rD(ctx
->opcode
), sprn
);
3710 /* Privilege exception */
3711 /* This is a hack to avoid warnings when running Linux:
3712 * this OS breaks the PowerPC virtualisation model,
3713 * allowing userland application to read the PVR
3715 if (sprn
!= SPR_PVR
) {
3716 qemu_log("Trying to read privileged spr %d %03x at "
3717 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3718 printf("Trying to read privileged spr %d %03x at " ADDRX
"\n",
3719 sprn
, sprn
, ctx
->nip
);
3721 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3725 qemu_log("Trying to read invalid spr %d %03x at "
3726 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3727 printf("Trying to read invalid spr %d %03x at " ADDRX
"\n",
3728 sprn
, sprn
, ctx
->nip
);
3729 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
3733 static void gen_mfspr(DisasContext
*ctx
)
3739 static void gen_mftb(DisasContext
*ctx
)
3745 static void gen_mtcrf(DisasContext
*ctx
)
3749 crm
= CRM(ctx
->opcode
);
3750 if (likely((ctx
->opcode
& 0x00100000))) {
3751 if (crm
&& ((crm
& (crm
- 1)) == 0)) {
3752 TCGv_i32 temp
= tcg_temp_new_i32();
3754 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
3755 tcg_gen_shri_i32(temp
, temp
, crn
* 4);
3756 tcg_gen_andi_i32(cpu_crf
[7 - crn
], temp
, 0xf);
3757 tcg_temp_free_i32(temp
);
3760 TCGv_i32 temp
= tcg_temp_new_i32();
3761 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
3762 for (crn
= 0 ; crn
< 8 ; crn
++) {
3763 if (crm
& (1 << crn
)) {
3764 tcg_gen_shri_i32(cpu_crf
[7 - crn
], temp
, crn
* 4);
3765 tcg_gen_andi_i32(cpu_crf
[7 - crn
], cpu_crf
[7 - crn
], 0xf);
3768 tcg_temp_free_i32(temp
);
3773 #if defined(TARGET_PPC64)
3774 static void gen_mtmsrd(DisasContext
*ctx
)
3776 #if defined(CONFIG_USER_ONLY)
3777 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3779 if (unlikely(!ctx
->mem_idx
)) {
3780 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3783 if (ctx
->opcode
& 0x00010000) {
3784 /* Special form that does not need any synchronisation */
3785 TCGv t0
= tcg_temp_new();
3786 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
3787 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
3788 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
3791 /* XXX: we need to update nip before the store
3792 * if we enter power saving mode, we will exit the loop
3793 * directly from ppc_store_msr
3795 gen_update_nip(ctx
, ctx
->nip
);
3796 gen_helper_store_msr(cpu_gpr
[rS(ctx
->opcode
)]);
3797 /* Must stop the translation as machine state (may have) changed */
3798 /* Note that mtmsr is not always defined as context-synchronizing */
3799 gen_stop_exception(ctx
);
3805 static void gen_mtmsr(DisasContext
*ctx
)
3807 #if defined(CONFIG_USER_ONLY)
3808 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3810 if (unlikely(!ctx
->mem_idx
)) {
3811 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3814 if (ctx
->opcode
& 0x00010000) {
3815 /* Special form that does not need any synchronisation */
3816 TCGv t0
= tcg_temp_new();
3817 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
3818 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
3819 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
3822 /* XXX: we need to update nip before the store
3823 * if we enter power saving mode, we will exit the loop
3824 * directly from ppc_store_msr
3826 gen_update_nip(ctx
, ctx
->nip
);
3827 #if defined(TARGET_PPC64)
3828 if (!ctx
->sf_mode
) {
3829 TCGv t0
= tcg_temp_new();
3830 TCGv t1
= tcg_temp_new();
3831 tcg_gen_andi_tl(t0
, cpu_msr
, 0xFFFFFFFF00000000ULL
);
3832 tcg_gen_ext32u_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
3833 tcg_gen_or_tl(t0
, t0
, t1
);
3835 gen_helper_store_msr(t0
);
3839 gen_helper_store_msr(cpu_gpr
[rS(ctx
->opcode
)]);
3840 /* Must stop the translation as machine state (may have) changed */
3841 /* Note that mtmsr is not always defined as context-synchronizing */
3842 gen_stop_exception(ctx
);
3848 static void gen_mtspr(DisasContext
*ctx
)
3850 void (*write_cb
)(void *opaque
, int sprn
, int gprn
);
3851 uint32_t sprn
= SPR(ctx
->opcode
);
3853 #if !defined(CONFIG_USER_ONLY)
3854 if (ctx
->mem_idx
== 2)
3855 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
3856 else if (ctx
->mem_idx
)
3857 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
3860 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
3861 if (likely(write_cb
!= NULL
)) {
3862 if (likely(write_cb
!= SPR_NOACCESS
)) {
3863 (*write_cb
)(ctx
, sprn
, rS(ctx
->opcode
));
3865 /* Privilege exception */
3866 qemu_log("Trying to write privileged spr %d %03x at "
3867 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3868 printf("Trying to write privileged spr %d %03x at " ADDRX
"\n",
3869 sprn
, sprn
, ctx
->nip
);
3870 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3874 qemu_log("Trying to write invalid spr %d %03x at "
3875 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3876 printf("Trying to write invalid spr %d %03x at " ADDRX
"\n",
3877 sprn
, sprn
, ctx
->nip
);
3878 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
3882 /*** Cache management ***/
3885 static void gen_dcbf(DisasContext
*ctx
)
3887 /* XXX: specification says this is treated as a load by the MMU */
3889 gen_set_access_type(ctx
, ACCESS_CACHE
);
3890 t0
= tcg_temp_new();
3891 gen_addr_reg_index(ctx
, t0
);
3892 gen_qemu_ld8u(ctx
, t0
, t0
);
3896 /* dcbi (Supervisor only) */
3897 static void gen_dcbi(DisasContext
*ctx
)
3899 #if defined(CONFIG_USER_ONLY)
3900 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3903 if (unlikely(!ctx
->mem_idx
)) {
3904 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3907 EA
= tcg_temp_new();
3908 gen_set_access_type(ctx
, ACCESS_CACHE
);
3909 gen_addr_reg_index(ctx
, EA
);
3910 val
= tcg_temp_new();
3911 /* XXX: specification says this should be treated as a store by the MMU */
3912 gen_qemu_ld8u(ctx
, val
, EA
);
3913 gen_qemu_st8(ctx
, val
, EA
);
3920 static void gen_dcbst(DisasContext
*ctx
)
3922 /* XXX: specification say this is treated as a load by the MMU */
3924 gen_set_access_type(ctx
, ACCESS_CACHE
);
3925 t0
= tcg_temp_new();
3926 gen_addr_reg_index(ctx
, t0
);
3927 gen_qemu_ld8u(ctx
, t0
, t0
);
3932 static void gen_dcbt(DisasContext
*ctx
)
3934 /* interpreted as no-op */
3935 /* XXX: specification say this is treated as a load by the MMU
3936 * but does not generate any exception
3941 static void gen_dcbtst(DisasContext
*ctx
)
3943 /* interpreted as no-op */
3944 /* XXX: specification say this is treated as a load by the MMU
3945 * but does not generate any exception
3950 static void gen_dcbz(DisasContext
*ctx
)
3953 gen_set_access_type(ctx
, ACCESS_CACHE
);
3954 /* NIP cannot be restored if the memory exception comes from an helper */
3955 gen_update_nip(ctx
, ctx
->nip
- 4);
3956 t0
= tcg_temp_new();
3957 gen_addr_reg_index(ctx
, t0
);
3958 gen_helper_dcbz(t0
);
3962 static void gen_dcbz_970(DisasContext
*ctx
)
3965 gen_set_access_type(ctx
, ACCESS_CACHE
);
3966 /* NIP cannot be restored if the memory exception comes from an helper */
3967 gen_update_nip(ctx
, ctx
->nip
- 4);
3968 t0
= tcg_temp_new();
3969 gen_addr_reg_index(ctx
, t0
);
3970 if (ctx
->opcode
& 0x00200000)
3971 gen_helper_dcbz(t0
);
3973 gen_helper_dcbz_970(t0
);
3978 static void gen_dst(DisasContext
*ctx
)
3980 if (rA(ctx
->opcode
) == 0) {
3981 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
3983 /* interpreted as no-op */
3988 static void gen_dstst(DisasContext
*ctx
)
3990 if (rA(ctx
->opcode
) == 0) {
3991 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
3993 /* interpreted as no-op */
3999 static void gen_dss(DisasContext
*ctx
)
4001 /* interpreted as no-op */
4005 static void gen_icbi(DisasContext
*ctx
)
4008 gen_set_access_type(ctx
, ACCESS_CACHE
);
4009 /* NIP cannot be restored if the memory exception comes from an helper */
4010 gen_update_nip(ctx
, ctx
->nip
- 4);
4011 t0
= tcg_temp_new();
4012 gen_addr_reg_index(ctx
, t0
);
4013 gen_helper_icbi(t0
);
4019 static void gen_dcba(DisasContext
*ctx
)
4021 /* interpreted as no-op */
4022 /* XXX: specification say this is treated as a store by the MMU
4023 * but does not generate any exception
4027 /*** Segment register manipulation ***/
4028 /* Supervisor only: */
4031 static void gen_mfsr(DisasContext
*ctx
)
4033 #if defined(CONFIG_USER_ONLY)
4034 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4037 if (unlikely(!ctx
->mem_idx
)) {
4038 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4041 t0
= tcg_const_tl(SR(ctx
->opcode
));
4042 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4048 static void gen_mfsrin(DisasContext
*ctx
)
4050 #if defined(CONFIG_USER_ONLY)
4051 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4054 if (unlikely(!ctx
->mem_idx
)) {
4055 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4058 t0
= tcg_temp_new();
4059 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4060 tcg_gen_andi_tl(t0
, t0
, 0xF);
4061 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4067 static void gen_mtsr(DisasContext
*ctx
)
4069 #if defined(CONFIG_USER_ONLY)
4070 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4073 if (unlikely(!ctx
->mem_idx
)) {
4074 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4077 t0
= tcg_const_tl(SR(ctx
->opcode
));
4078 gen_helper_store_sr(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4084 static void gen_mtsrin(DisasContext
*ctx
)
4086 #if defined(CONFIG_USER_ONLY)
4087 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4090 if (unlikely(!ctx
->mem_idx
)) {
4091 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4094 t0
= tcg_temp_new();
4095 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4096 tcg_gen_andi_tl(t0
, t0
, 0xF);
4097 gen_helper_store_sr(t0
, cpu_gpr
[rD(ctx
->opcode
)]);
4102 #if defined(TARGET_PPC64)
4103 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4106 static void gen_mfsr_64b(DisasContext
*ctx
)
4108 #if defined(CONFIG_USER_ONLY)
4109 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4112 if (unlikely(!ctx
->mem_idx
)) {
4113 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4116 t0
= tcg_const_tl(SR(ctx
->opcode
));
4117 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4123 static void gen_mfsrin_64b(DisasContext
*ctx
)
4125 #if defined(CONFIG_USER_ONLY)
4126 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4129 if (unlikely(!ctx
->mem_idx
)) {
4130 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4133 t0
= tcg_temp_new();
4134 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4135 tcg_gen_andi_tl(t0
, t0
, 0xF);
4136 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4142 static void gen_mtsr_64b(DisasContext
*ctx
)
4144 #if defined(CONFIG_USER_ONLY)
4145 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4148 if (unlikely(!ctx
->mem_idx
)) {
4149 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4152 t0
= tcg_const_tl(SR(ctx
->opcode
));
4153 gen_helper_store_sr(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4159 static void gen_mtsrin_64b(DisasContext
*ctx
)
4161 #if defined(CONFIG_USER_ONLY)
4162 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4165 if (unlikely(!ctx
->mem_idx
)) {
4166 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4169 t0
= tcg_temp_new();
4170 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4171 tcg_gen_andi_tl(t0
, t0
, 0xF);
4172 gen_helper_store_sr(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4178 static void gen_slbmte(DisasContext
*ctx
)
4180 #if defined(CONFIG_USER_ONLY)
4181 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4183 if (unlikely(!ctx
->mem_idx
)) {
4184 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4187 gen_helper_store_slb(cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
4191 #endif /* defined(TARGET_PPC64) */
4193 /*** Lookaside buffer management ***/
4194 /* Optional & mem_idx only: */
4197 static void gen_tlbia(DisasContext
*ctx
)
4199 #if defined(CONFIG_USER_ONLY)
4200 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4202 if (unlikely(!ctx
->mem_idx
)) {
4203 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4211 static void gen_tlbiel(DisasContext
*ctx
)
4213 #if defined(CONFIG_USER_ONLY)
4214 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4216 if (unlikely(!ctx
->mem_idx
)) {
4217 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4220 gen_helper_tlbie(cpu_gpr
[rB(ctx
->opcode
)]);
4225 static void gen_tlbie(DisasContext
*ctx
)
4227 #if defined(CONFIG_USER_ONLY)
4228 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4230 if (unlikely(!ctx
->mem_idx
)) {
4231 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4234 #if defined(TARGET_PPC64)
4235 if (!ctx
->sf_mode
) {
4236 TCGv t0
= tcg_temp_new();
4237 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
4238 gen_helper_tlbie(t0
);
4242 gen_helper_tlbie(cpu_gpr
[rB(ctx
->opcode
)]);
4247 static void gen_tlbsync(DisasContext
*ctx
)
4249 #if defined(CONFIG_USER_ONLY)
4250 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4252 if (unlikely(!ctx
->mem_idx
)) {
4253 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4256 /* This has no effect: it should ensure that all previous
4257 * tlbie have completed
4259 gen_stop_exception(ctx
);
4263 #if defined(TARGET_PPC64)
4265 static void gen_slbia(DisasContext
*ctx
)
4267 #if defined(CONFIG_USER_ONLY)
4268 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4270 if (unlikely(!ctx
->mem_idx
)) {
4271 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4279 static void gen_slbie(DisasContext
*ctx
)
4281 #if defined(CONFIG_USER_ONLY)
4282 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4284 if (unlikely(!ctx
->mem_idx
)) {
4285 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4288 gen_helper_slbie(cpu_gpr
[rB(ctx
->opcode
)]);
4293 /*** External control ***/
4297 static void gen_eciwx(DisasContext
*ctx
)
4300 /* Should check EAR[E] ! */
4301 gen_set_access_type(ctx
, ACCESS_EXT
);
4302 t0
= tcg_temp_new();
4303 gen_addr_reg_index(ctx
, t0
);
4304 gen_check_align(ctx
, t0
, 0x03);
4305 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4310 static void gen_ecowx(DisasContext
*ctx
)
4313 /* Should check EAR[E] ! */
4314 gen_set_access_type(ctx
, ACCESS_EXT
);
4315 t0
= tcg_temp_new();
4316 gen_addr_reg_index(ctx
, t0
);
4317 gen_check_align(ctx
, t0
, 0x03);
4318 gen_qemu_st32(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4322 /* PowerPC 601 specific instructions */
4325 static void gen_abs(DisasContext
*ctx
)
4327 int l1
= gen_new_label();
4328 int l2
= gen_new_label();
4329 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4330 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4333 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4335 if (unlikely(Rc(ctx
->opcode
) != 0))
4336 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4340 static void gen_abso(DisasContext
*ctx
)
4342 int l1
= gen_new_label();
4343 int l2
= gen_new_label();
4344 int l3
= gen_new_label();
4345 /* Start with XER OV disabled, the most likely case */
4346 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
4347 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l2
);
4348 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rA(ctx
->opcode
)], 0x80000000, l1
);
4349 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
4352 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4355 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4357 if (unlikely(Rc(ctx
->opcode
) != 0))
4358 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4362 static void gen_clcs(DisasContext
*ctx
)
4364 TCGv_i32 t0
= tcg_const_i32(rA(ctx
->opcode
));
4365 gen_helper_clcs(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4366 tcg_temp_free_i32(t0
);
4367 /* Rc=1 sets CR0 to an undefined state */
4371 static void gen_div(DisasContext
*ctx
)
4373 gen_helper_div(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4374 if (unlikely(Rc(ctx
->opcode
) != 0))
4375 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4379 static void gen_divo(DisasContext
*ctx
)
4381 gen_helper_divo(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4382 if (unlikely(Rc(ctx
->opcode
) != 0))
4383 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4387 static void gen_divs(DisasContext
*ctx
)
4389 gen_helper_divs(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4390 if (unlikely(Rc(ctx
->opcode
) != 0))
4391 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4394 /* divso - divso. */
4395 static void gen_divso(DisasContext
*ctx
)
4397 gen_helper_divso(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4398 if (unlikely(Rc(ctx
->opcode
) != 0))
4399 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4403 static void gen_doz(DisasContext
*ctx
)
4405 int l1
= gen_new_label();
4406 int l2
= gen_new_label();
4407 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4408 tcg_gen_sub_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4411 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4413 if (unlikely(Rc(ctx
->opcode
) != 0))
4414 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4418 static void gen_dozo(DisasContext
*ctx
)
4420 int l1
= gen_new_label();
4421 int l2
= gen_new_label();
4422 TCGv t0
= tcg_temp_new();
4423 TCGv t1
= tcg_temp_new();
4424 TCGv t2
= tcg_temp_new();
4425 /* Start with XER OV disabled, the most likely case */
4426 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
4427 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4428 tcg_gen_sub_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4429 tcg_gen_xor_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4430 tcg_gen_xor_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], t0
);
4431 tcg_gen_andc_tl(t1
, t1
, t2
);
4432 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4433 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
4434 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
4437 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4442 if (unlikely(Rc(ctx
->opcode
) != 0))
4443 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4447 static void gen_dozi(DisasContext
*ctx
)
4449 target_long simm
= SIMM(ctx
->opcode
);
4450 int l1
= gen_new_label();
4451 int l2
= gen_new_label();
4452 tcg_gen_brcondi_tl(TCG_COND_LT
, cpu_gpr
[rA(ctx
->opcode
)], simm
, l1
);
4453 tcg_gen_subfi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
, cpu_gpr
[rA(ctx
->opcode
)]);
4456 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4458 if (unlikely(Rc(ctx
->opcode
) != 0))
4459 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4462 /* lscbx - lscbx. */
4463 static void gen_lscbx(DisasContext
*ctx
)
4465 TCGv t0
= tcg_temp_new();
4466 TCGv_i32 t1
= tcg_const_i32(rD(ctx
->opcode
));
4467 TCGv_i32 t2
= tcg_const_i32(rA(ctx
->opcode
));
4468 TCGv_i32 t3
= tcg_const_i32(rB(ctx
->opcode
));
4470 gen_addr_reg_index(ctx
, t0
);
4471 /* NIP cannot be restored if the memory exception comes from an helper */
4472 gen_update_nip(ctx
, ctx
->nip
- 4);
4473 gen_helper_lscbx(t0
, t0
, t1
, t2
, t3
);
4474 tcg_temp_free_i32(t1
);
4475 tcg_temp_free_i32(t2
);
4476 tcg_temp_free_i32(t3
);
4477 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~0x7F);
4478 tcg_gen_or_tl(cpu_xer
, cpu_xer
, t0
);
4479 if (unlikely(Rc(ctx
->opcode
) != 0))
4480 gen_set_Rc0(ctx
, t0
);
4484 /* maskg - maskg. */
4485 static void gen_maskg(DisasContext
*ctx
)
4487 int l1
= gen_new_label();
4488 TCGv t0
= tcg_temp_new();
4489 TCGv t1
= tcg_temp_new();
4490 TCGv t2
= tcg_temp_new();
4491 TCGv t3
= tcg_temp_new();
4492 tcg_gen_movi_tl(t3
, 0xFFFFFFFF);
4493 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4494 tcg_gen_andi_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 0x1F);
4495 tcg_gen_addi_tl(t2
, t0
, 1);
4496 tcg_gen_shr_tl(t2
, t3
, t2
);
4497 tcg_gen_shr_tl(t3
, t3
, t1
);
4498 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], t2
, t3
);
4499 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
4500 tcg_gen_neg_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4506 if (unlikely(Rc(ctx
->opcode
) != 0))
4507 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4510 /* maskir - maskir. */
4511 static void gen_maskir(DisasContext
*ctx
)
4513 TCGv t0
= tcg_temp_new();
4514 TCGv t1
= tcg_temp_new();
4515 tcg_gen_and_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4516 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4517 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4520 if (unlikely(Rc(ctx
->opcode
) != 0))
4521 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4525 static void gen_mul(DisasContext
*ctx
)
4527 TCGv_i64 t0
= tcg_temp_new_i64();
4528 TCGv_i64 t1
= tcg_temp_new_i64();
4529 TCGv t2
= tcg_temp_new();
4530 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4531 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4532 tcg_gen_mul_i64(t0
, t0
, t1
);
4533 tcg_gen_trunc_i64_tl(t2
, t0
);
4534 gen_store_spr(SPR_MQ
, t2
);
4535 tcg_gen_shri_i64(t1
, t0
, 32);
4536 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4537 tcg_temp_free_i64(t0
);
4538 tcg_temp_free_i64(t1
);
4540 if (unlikely(Rc(ctx
->opcode
) != 0))
4541 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4545 static void gen_mulo(DisasContext
*ctx
)
4547 int l1
= gen_new_label();
4548 TCGv_i64 t0
= tcg_temp_new_i64();
4549 TCGv_i64 t1
= tcg_temp_new_i64();
4550 TCGv t2
= tcg_temp_new();
4551 /* Start with XER OV disabled, the most likely case */
4552 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
4553 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4554 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4555 tcg_gen_mul_i64(t0
, t0
, t1
);
4556 tcg_gen_trunc_i64_tl(t2
, t0
);
4557 gen_store_spr(SPR_MQ
, t2
);
4558 tcg_gen_shri_i64(t1
, t0
, 32);
4559 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4560 tcg_gen_ext32s_i64(t1
, t0
);
4561 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
4562 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
4564 tcg_temp_free_i64(t0
);
4565 tcg_temp_free_i64(t1
);
4567 if (unlikely(Rc(ctx
->opcode
) != 0))
4568 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4572 static void gen_nabs(DisasContext
*ctx
)
4574 int l1
= gen_new_label();
4575 int l2
= gen_new_label();
4576 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4577 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4580 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4582 if (unlikely(Rc(ctx
->opcode
) != 0))
4583 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4586 /* nabso - nabso. */
4587 static void gen_nabso(DisasContext
*ctx
)
4589 int l1
= gen_new_label();
4590 int l2
= gen_new_label();
4591 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4592 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4595 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4597 /* nabs never overflows */
4598 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
4599 if (unlikely(Rc(ctx
->opcode
) != 0))
4600 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4604 static void gen_rlmi(DisasContext
*ctx
)
4606 uint32_t mb
= MB(ctx
->opcode
);
4607 uint32_t me
= ME(ctx
->opcode
);
4608 TCGv t0
= tcg_temp_new();
4609 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4610 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4611 tcg_gen_andi_tl(t0
, t0
, MASK(mb
, me
));
4612 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~MASK(mb
, me
));
4613 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], t0
);
4615 if (unlikely(Rc(ctx
->opcode
) != 0))
4616 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4620 static void gen_rrib(DisasContext
*ctx
)
4622 TCGv t0
= tcg_temp_new();
4623 TCGv t1
= tcg_temp_new();
4624 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4625 tcg_gen_movi_tl(t1
, 0x80000000);
4626 tcg_gen_shr_tl(t1
, t1
, t0
);
4627 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4628 tcg_gen_and_tl(t0
, t0
, t1
);
4629 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], t1
);
4630 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4633 if (unlikely(Rc(ctx
->opcode
) != 0))
4634 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4638 static void gen_sle(DisasContext
*ctx
)
4640 TCGv t0
= tcg_temp_new();
4641 TCGv t1
= tcg_temp_new();
4642 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4643 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4644 tcg_gen_subfi_tl(t1
, 32, t1
);
4645 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4646 tcg_gen_or_tl(t1
, t0
, t1
);
4647 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4648 gen_store_spr(SPR_MQ
, t1
);
4651 if (unlikely(Rc(ctx
->opcode
) != 0))
4652 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4656 static void gen_sleq(DisasContext
*ctx
)
4658 TCGv t0
= tcg_temp_new();
4659 TCGv t1
= tcg_temp_new();
4660 TCGv t2
= tcg_temp_new();
4661 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4662 tcg_gen_movi_tl(t2
, 0xFFFFFFFF);
4663 tcg_gen_shl_tl(t2
, t2
, t0
);
4664 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4665 gen_load_spr(t1
, SPR_MQ
);
4666 gen_store_spr(SPR_MQ
, t0
);
4667 tcg_gen_and_tl(t0
, t0
, t2
);
4668 tcg_gen_andc_tl(t1
, t1
, t2
);
4669 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4673 if (unlikely(Rc(ctx
->opcode
) != 0))
4674 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4678 static void gen_sliq(DisasContext
*ctx
)
4680 int sh
= SH(ctx
->opcode
);
4681 TCGv t0
= tcg_temp_new();
4682 TCGv t1
= tcg_temp_new();
4683 tcg_gen_shli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4684 tcg_gen_shri_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
4685 tcg_gen_or_tl(t1
, t0
, t1
);
4686 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4687 gen_store_spr(SPR_MQ
, t1
);
4690 if (unlikely(Rc(ctx
->opcode
) != 0))
4691 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4694 /* slliq - slliq. */
4695 static void gen_slliq(DisasContext
*ctx
)
4697 int sh
= SH(ctx
->opcode
);
4698 TCGv t0
= tcg_temp_new();
4699 TCGv t1
= tcg_temp_new();
4700 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4701 gen_load_spr(t1
, SPR_MQ
);
4702 gen_store_spr(SPR_MQ
, t0
);
4703 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
<< sh
));
4704 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
<< sh
));
4705 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4708 if (unlikely(Rc(ctx
->opcode
) != 0))
4709 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4713 static void gen_sllq(DisasContext
*ctx
)
4715 int l1
= gen_new_label();
4716 int l2
= gen_new_label();
4717 TCGv t0
= tcg_temp_local_new();
4718 TCGv t1
= tcg_temp_local_new();
4719 TCGv t2
= tcg_temp_local_new();
4720 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4721 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
4722 tcg_gen_shl_tl(t1
, t1
, t2
);
4723 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4724 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
4725 gen_load_spr(t0
, SPR_MQ
);
4726 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4729 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4730 gen_load_spr(t2
, SPR_MQ
);
4731 tcg_gen_andc_tl(t1
, t2
, t1
);
4732 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4737 if (unlikely(Rc(ctx
->opcode
) != 0))
4738 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4742 static void gen_slq(DisasContext
*ctx
)
4744 int l1
= gen_new_label();
4745 TCGv t0
= tcg_temp_new();
4746 TCGv t1
= tcg_temp_new();
4747 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4748 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4749 tcg_gen_subfi_tl(t1
, 32, t1
);
4750 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4751 tcg_gen_or_tl(t1
, t0
, t1
);
4752 gen_store_spr(SPR_MQ
, t1
);
4753 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4754 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4755 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
4756 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
4760 if (unlikely(Rc(ctx
->opcode
) != 0))
4761 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4764 /* sraiq - sraiq. */
4765 static void gen_sraiq(DisasContext
*ctx
)
4767 int sh
= SH(ctx
->opcode
);
4768 int l1
= gen_new_label();
4769 TCGv t0
= tcg_temp_new();
4770 TCGv t1
= tcg_temp_new();
4771 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4772 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
4773 tcg_gen_or_tl(t0
, t0
, t1
);
4774 gen_store_spr(SPR_MQ
, t0
);
4775 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
4776 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
4777 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
4778 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_CA
));
4780 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
4783 if (unlikely(Rc(ctx
->opcode
) != 0))
4784 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4788 static void gen_sraq(DisasContext
*ctx
)
4790 int l1
= gen_new_label();
4791 int l2
= gen_new_label();
4792 TCGv t0
= tcg_temp_new();
4793 TCGv t1
= tcg_temp_local_new();
4794 TCGv t2
= tcg_temp_local_new();
4795 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4796 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4797 tcg_gen_sar_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4798 tcg_gen_subfi_tl(t2
, 32, t2
);
4799 tcg_gen_shl_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4800 tcg_gen_or_tl(t0
, t0
, t2
);
4801 gen_store_spr(SPR_MQ
, t0
);
4802 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4803 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l1
);
4804 tcg_gen_mov_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
4805 tcg_gen_sari_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 31);
4808 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
);
4809 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
4810 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
4811 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l2
);
4812 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_CA
));
4816 if (unlikely(Rc(ctx
->opcode
) != 0))
4817 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4821 static void gen_sre(DisasContext
*ctx
)
4823 TCGv t0
= tcg_temp_new();
4824 TCGv t1
= tcg_temp_new();
4825 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4826 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4827 tcg_gen_subfi_tl(t1
, 32, t1
);
4828 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4829 tcg_gen_or_tl(t1
, t0
, t1
);
4830 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4831 gen_store_spr(SPR_MQ
, t1
);
4834 if (unlikely(Rc(ctx
->opcode
) != 0))
4835 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4839 static void gen_srea(DisasContext
*ctx
)
4841 TCGv t0
= tcg_temp_new();
4842 TCGv t1
= tcg_temp_new();
4843 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4844 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4845 gen_store_spr(SPR_MQ
, t0
);
4846 tcg_gen_sar_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t1
);
4849 if (unlikely(Rc(ctx
->opcode
) != 0))
4850 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4854 static void gen_sreq(DisasContext
*ctx
)
4856 TCGv t0
= tcg_temp_new();
4857 TCGv t1
= tcg_temp_new();
4858 TCGv t2
= tcg_temp_new();
4859 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4860 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
4861 tcg_gen_shr_tl(t1
, t1
, t0
);
4862 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4863 gen_load_spr(t2
, SPR_MQ
);
4864 gen_store_spr(SPR_MQ
, t0
);
4865 tcg_gen_and_tl(t0
, t0
, t1
);
4866 tcg_gen_andc_tl(t2
, t2
, t1
);
4867 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
4871 if (unlikely(Rc(ctx
->opcode
) != 0))
4872 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4876 static void gen_sriq(DisasContext
*ctx
)
4878 int sh
= SH(ctx
->opcode
);
4879 TCGv t0
= tcg_temp_new();
4880 TCGv t1
= tcg_temp_new();
4881 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4882 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
4883 tcg_gen_or_tl(t1
, t0
, t1
);
4884 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4885 gen_store_spr(SPR_MQ
, t1
);
4888 if (unlikely(Rc(ctx
->opcode
) != 0))
4889 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4893 static void gen_srliq(DisasContext
*ctx
)
4895 int sh
= SH(ctx
->opcode
);
4896 TCGv t0
= tcg_temp_new();
4897 TCGv t1
= tcg_temp_new();
4898 tcg_gen_rotri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4899 gen_load_spr(t1
, SPR_MQ
);
4900 gen_store_spr(SPR_MQ
, t0
);
4901 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
>> sh
));
4902 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
>> sh
));
4903 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4906 if (unlikely(Rc(ctx
->opcode
) != 0))
4907 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4911 static void gen_srlq(DisasContext
*ctx
)
4913 int l1
= gen_new_label();
4914 int l2
= gen_new_label();
4915 TCGv t0
= tcg_temp_local_new();
4916 TCGv t1
= tcg_temp_local_new();
4917 TCGv t2
= tcg_temp_local_new();
4918 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4919 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
4920 tcg_gen_shr_tl(t2
, t1
, t2
);
4921 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4922 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
4923 gen_load_spr(t0
, SPR_MQ
);
4924 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
4927 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4928 tcg_gen_and_tl(t0
, t0
, t2
);
4929 gen_load_spr(t1
, SPR_MQ
);
4930 tcg_gen_andc_tl(t1
, t1
, t2
);
4931 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4936 if (unlikely(Rc(ctx
->opcode
) != 0))
4937 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4941 static void gen_srq(DisasContext
*ctx
)
4943 int l1
= gen_new_label();
4944 TCGv t0
= tcg_temp_new();
4945 TCGv t1
= tcg_temp_new();
4946 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4947 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4948 tcg_gen_subfi_tl(t1
, 32, t1
);
4949 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4950 tcg_gen_or_tl(t1
, t0
, t1
);
4951 gen_store_spr(SPR_MQ
, t1
);
4952 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4953 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4954 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
4955 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
4959 if (unlikely(Rc(ctx
->opcode
) != 0))
4960 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4963 /* PowerPC 602 specific instructions */
4966 static void gen_dsa(DisasContext
*ctx
)
4969 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
4973 static void gen_esa(DisasContext
*ctx
)
4976 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
4980 static void gen_mfrom(DisasContext
*ctx
)
4982 #if defined(CONFIG_USER_ONLY)
4983 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4985 if (unlikely(!ctx
->mem_idx
)) {
4986 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4989 gen_helper_602_mfrom(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4993 /* 602 - 603 - G2 TLB management */
4996 static void gen_tlbld_6xx(DisasContext
*ctx
)
4998 #if defined(CONFIG_USER_ONLY)
4999 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5001 if (unlikely(!ctx
->mem_idx
)) {
5002 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5005 gen_helper_6xx_tlbd(cpu_gpr
[rB(ctx
->opcode
)]);
5010 static void gen_tlbli_6xx(DisasContext
*ctx
)
5012 #if defined(CONFIG_USER_ONLY)
5013 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5015 if (unlikely(!ctx
->mem_idx
)) {
5016 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5019 gen_helper_6xx_tlbi(cpu_gpr
[rB(ctx
->opcode
)]);
5023 /* 74xx TLB management */
5026 static void gen_tlbld_74xx(DisasContext
*ctx
)
5028 #if defined(CONFIG_USER_ONLY)
5029 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5031 if (unlikely(!ctx
->mem_idx
)) {
5032 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5035 gen_helper_74xx_tlbd(cpu_gpr
[rB(ctx
->opcode
)]);
5040 static void gen_tlbli_74xx(DisasContext
*ctx
)
5042 #if defined(CONFIG_USER_ONLY)
5043 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5045 if (unlikely(!ctx
->mem_idx
)) {
5046 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5049 gen_helper_74xx_tlbi(cpu_gpr
[rB(ctx
->opcode
)]);
5053 /* POWER instructions not in PowerPC 601 */
5056 static void gen_clf(DisasContext
*ctx
)
5058 /* Cache line flush: implemented as no-op */
5062 static void gen_cli(DisasContext
*ctx
)
5064 /* Cache line invalidate: privileged and treated as no-op */
5065 #if defined(CONFIG_USER_ONLY)
5066 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5068 if (unlikely(!ctx
->mem_idx
)) {
5069 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5076 static void gen_dclst(DisasContext
*ctx
)
5078 /* Data cache line store: treated as no-op */
5081 static void gen_mfsri(DisasContext
*ctx
)
5083 #if defined(CONFIG_USER_ONLY)
5084 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5086 int ra
= rA(ctx
->opcode
);
5087 int rd
= rD(ctx
->opcode
);
5089 if (unlikely(!ctx
->mem_idx
)) {
5090 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5093 t0
= tcg_temp_new();
5094 gen_addr_reg_index(ctx
, t0
);
5095 tcg_gen_shri_tl(t0
, t0
, 28);
5096 tcg_gen_andi_tl(t0
, t0
, 0xF);
5097 gen_helper_load_sr(cpu_gpr
[rd
], t0
);
5099 if (ra
!= 0 && ra
!= rd
)
5100 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rd
]);
5104 static void gen_rac(DisasContext
*ctx
)
5106 #if defined(CONFIG_USER_ONLY)
5107 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5110 if (unlikely(!ctx
->mem_idx
)) {
5111 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5114 t0
= tcg_temp_new();
5115 gen_addr_reg_index(ctx
, t0
);
5116 gen_helper_rac(cpu_gpr
[rD(ctx
->opcode
)], t0
);
5121 static void gen_rfsvc(DisasContext
*ctx
)
5123 #if defined(CONFIG_USER_ONLY)
5124 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5126 if (unlikely(!ctx
->mem_idx
)) {
5127 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5131 gen_sync_exception(ctx
);
5135 /* svc is not implemented for now */
5137 /* POWER2 specific instructions */
5138 /* Quad manipulation (load/store two floats at a time) */
5141 static void gen_lfq(DisasContext
*ctx
)
5143 int rd
= rD(ctx
->opcode
);
5145 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5146 t0
= tcg_temp_new();
5147 gen_addr_imm_index(ctx
, t0
, 0);
5148 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5149 gen_addr_add(ctx
, t0
, t0
, 8);
5150 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5155 static void gen_lfqu(DisasContext
*ctx
)
5157 int ra
= rA(ctx
->opcode
);
5158 int rd
= rD(ctx
->opcode
);
5160 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5161 t0
= tcg_temp_new();
5162 t1
= tcg_temp_new();
5163 gen_addr_imm_index(ctx
, t0
, 0);
5164 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5165 gen_addr_add(ctx
, t1
, t0
, 8);
5166 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5168 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5174 static void gen_lfqux(DisasContext
*ctx
)
5176 int ra
= rA(ctx
->opcode
);
5177 int rd
= rD(ctx
->opcode
);
5178 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5180 t0
= tcg_temp_new();
5181 gen_addr_reg_index(ctx
, t0
);
5182 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5183 t1
= tcg_temp_new();
5184 gen_addr_add(ctx
, t1
, t0
, 8);
5185 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5188 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5193 static void gen_lfqx(DisasContext
*ctx
)
5195 int rd
= rD(ctx
->opcode
);
5197 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5198 t0
= tcg_temp_new();
5199 gen_addr_reg_index(ctx
, t0
);
5200 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5201 gen_addr_add(ctx
, t0
, t0
, 8);
5202 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5207 static void gen_stfq(DisasContext
*ctx
)
5209 int rd
= rD(ctx
->opcode
);
5211 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5212 t0
= tcg_temp_new();
5213 gen_addr_imm_index(ctx
, t0
, 0);
5214 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5215 gen_addr_add(ctx
, t0
, t0
, 8);
5216 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5221 static void gen_stfqu(DisasContext
*ctx
)
5223 int ra
= rA(ctx
->opcode
);
5224 int rd
= rD(ctx
->opcode
);
5226 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5227 t0
= tcg_temp_new();
5228 gen_addr_imm_index(ctx
, t0
, 0);
5229 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5230 t1
= tcg_temp_new();
5231 gen_addr_add(ctx
, t1
, t0
, 8);
5232 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5235 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5240 static void gen_stfqux(DisasContext
*ctx
)
5242 int ra
= rA(ctx
->opcode
);
5243 int rd
= rD(ctx
->opcode
);
5245 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5246 t0
= tcg_temp_new();
5247 gen_addr_reg_index(ctx
, t0
);
5248 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5249 t1
= tcg_temp_new();
5250 gen_addr_add(ctx
, t1
, t0
, 8);
5251 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5254 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5259 static void gen_stfqx(DisasContext
*ctx
)
5261 int rd
= rD(ctx
->opcode
);
5263 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5264 t0
= tcg_temp_new();
5265 gen_addr_reg_index(ctx
, t0
);
5266 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5267 gen_addr_add(ctx
, t0
, t0
, 8);
5268 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5272 /* BookE specific instructions */
5274 /* XXX: not implemented on 440 ? */
5275 static void gen_mfapidi(DisasContext
*ctx
)
5278 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5281 /* XXX: not implemented on 440 ? */
5282 static void gen_tlbiva(DisasContext
*ctx
)
5284 #if defined(CONFIG_USER_ONLY)
5285 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5288 if (unlikely(!ctx
->mem_idx
)) {
5289 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5292 t0
= tcg_temp_new();
5293 gen_addr_reg_index(ctx
, t0
);
5294 gen_helper_tlbie(cpu_gpr
[rB(ctx
->opcode
)]);
5299 /* All 405 MAC instructions are translated here */
5300 static always_inline
void gen_405_mulladd_insn (DisasContext
*ctx
,
5302 int ra
, int rb
, int rt
, int Rc
)
5306 t0
= tcg_temp_local_new();
5307 t1
= tcg_temp_local_new();
5309 switch (opc3
& 0x0D) {
5311 /* macchw - macchw. - macchwo - macchwo. */
5312 /* macchws - macchws. - macchwso - macchwso. */
5313 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5314 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5315 /* mulchw - mulchw. */
5316 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5317 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5318 tcg_gen_ext16s_tl(t1
, t1
);
5321 /* macchwu - macchwu. - macchwuo - macchwuo. */
5322 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5323 /* mulchwu - mulchwu. */
5324 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5325 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5326 tcg_gen_ext16u_tl(t1
, t1
);
5329 /* machhw - machhw. - machhwo - machhwo. */
5330 /* machhws - machhws. - machhwso - machhwso. */
5331 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5332 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5333 /* mulhhw - mulhhw. */
5334 tcg_gen_sari_tl(t0
, cpu_gpr
[ra
], 16);
5335 tcg_gen_ext16s_tl(t0
, t0
);
5336 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5337 tcg_gen_ext16s_tl(t1
, t1
);
5340 /* machhwu - machhwu. - machhwuo - machhwuo. */
5341 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5342 /* mulhhwu - mulhhwu. */
5343 tcg_gen_shri_tl(t0
, cpu_gpr
[ra
], 16);
5344 tcg_gen_ext16u_tl(t0
, t0
);
5345 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5346 tcg_gen_ext16u_tl(t1
, t1
);
5349 /* maclhw - maclhw. - maclhwo - maclhwo. */
5350 /* maclhws - maclhws. - maclhwso - maclhwso. */
5351 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5352 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5353 /* mullhw - mullhw. */
5354 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5355 tcg_gen_ext16s_tl(t1
, cpu_gpr
[rb
]);
5358 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5359 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5360 /* mullhwu - mullhwu. */
5361 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5362 tcg_gen_ext16u_tl(t1
, cpu_gpr
[rb
]);
5366 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5367 tcg_gen_mul_tl(t1
, t0
, t1
);
5369 /* nmultiply-and-accumulate (0x0E) */
5370 tcg_gen_sub_tl(t0
, cpu_gpr
[rt
], t1
);
5372 /* multiply-and-accumulate (0x0C) */
5373 tcg_gen_add_tl(t0
, cpu_gpr
[rt
], t1
);
5377 /* Check overflow and/or saturate */
5378 int l1
= gen_new_label();
5381 /* Start with XER OV disabled, the most likely case */
5382 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
5386 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t1
);
5387 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
5388 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t0
);
5389 tcg_gen_brcondi_tl(TCG_COND_LT
, t1
, 0, l1
);
5392 tcg_gen_sari_tl(t0
, cpu_gpr
[rt
], 31);
5393 tcg_gen_xori_tl(t0
, t0
, 0x7fffffff);
5397 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
5400 tcg_gen_movi_tl(t0
, UINT32_MAX
);
5404 /* Check overflow */
5405 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
5408 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
5411 tcg_gen_mul_tl(cpu_gpr
[rt
], t0
, t1
);
5415 if (unlikely(Rc
) != 0) {
5417 gen_set_Rc0(ctx
, cpu_gpr
[rt
]);
5421 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5422 static void glue(gen_, name)(DisasContext *ctx) \
5424 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5425 rD(ctx->opcode), Rc(ctx->opcode)); \
5428 /* macchw - macchw. */
5429 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
5430 /* macchwo - macchwo. */
5431 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
5432 /* macchws - macchws. */
5433 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
5434 /* macchwso - macchwso. */
5435 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
5436 /* macchwsu - macchwsu. */
5437 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
5438 /* macchwsuo - macchwsuo. */
5439 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
5440 /* macchwu - macchwu. */
5441 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
5442 /* macchwuo - macchwuo. */
5443 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
5444 /* machhw - machhw. */
5445 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
5446 /* machhwo - machhwo. */
5447 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
5448 /* machhws - machhws. */
5449 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
5450 /* machhwso - machhwso. */
5451 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
5452 /* machhwsu - machhwsu. */
5453 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
5454 /* machhwsuo - machhwsuo. */
5455 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
5456 /* machhwu - machhwu. */
5457 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
5458 /* machhwuo - machhwuo. */
5459 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
5460 /* maclhw - maclhw. */
5461 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
5462 /* maclhwo - maclhwo. */
5463 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
5464 /* maclhws - maclhws. */
5465 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
5466 /* maclhwso - maclhwso. */
5467 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
5468 /* maclhwu - maclhwu. */
5469 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
5470 /* maclhwuo - maclhwuo. */
5471 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
5472 /* maclhwsu - maclhwsu. */
5473 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
5474 /* maclhwsuo - maclhwsuo. */
5475 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
5476 /* nmacchw - nmacchw. */
5477 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
5478 /* nmacchwo - nmacchwo. */
5479 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
5480 /* nmacchws - nmacchws. */
5481 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
5482 /* nmacchwso - nmacchwso. */
5483 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
5484 /* nmachhw - nmachhw. */
5485 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
5486 /* nmachhwo - nmachhwo. */
5487 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
5488 /* nmachhws - nmachhws. */
5489 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
5490 /* nmachhwso - nmachhwso. */
5491 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
5492 /* nmaclhw - nmaclhw. */
5493 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
5494 /* nmaclhwo - nmaclhwo. */
5495 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
5496 /* nmaclhws - nmaclhws. */
5497 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
5498 /* nmaclhwso - nmaclhwso. */
5499 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
5501 /* mulchw - mulchw. */
5502 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
5503 /* mulchwu - mulchwu. */
5504 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
5505 /* mulhhw - mulhhw. */
5506 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
5507 /* mulhhwu - mulhhwu. */
5508 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
5509 /* mullhw - mullhw. */
5510 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
5511 /* mullhwu - mullhwu. */
5512 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
5515 static void gen_mfdcr(DisasContext
*ctx
)
5517 #if defined(CONFIG_USER_ONLY)
5518 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5521 if (unlikely(!ctx
->mem_idx
)) {
5522 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5525 /* NIP cannot be restored if the memory exception comes from an helper */
5526 gen_update_nip(ctx
, ctx
->nip
- 4);
5527 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5528 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], dcrn
);
5529 tcg_temp_free(dcrn
);
5534 static void gen_mtdcr(DisasContext
*ctx
)
5536 #if defined(CONFIG_USER_ONLY)
5537 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5540 if (unlikely(!ctx
->mem_idx
)) {
5541 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5544 /* NIP cannot be restored if the memory exception comes from an helper */
5545 gen_update_nip(ctx
, ctx
->nip
- 4);
5546 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5547 gen_helper_store_dcr(dcrn
, cpu_gpr
[rS(ctx
->opcode
)]);
5548 tcg_temp_free(dcrn
);
5553 /* XXX: not implemented on 440 ? */
5554 static void gen_mfdcrx(DisasContext
*ctx
)
5556 #if defined(CONFIG_USER_ONLY)
5557 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5559 if (unlikely(!ctx
->mem_idx
)) {
5560 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5563 /* NIP cannot be restored if the memory exception comes from an helper */
5564 gen_update_nip(ctx
, ctx
->nip
- 4);
5565 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5566 /* Note: Rc update flag set leads to undefined state of Rc0 */
5571 /* XXX: not implemented on 440 ? */
5572 static void gen_mtdcrx(DisasContext
*ctx
)
5574 #if defined(CONFIG_USER_ONLY)
5575 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5577 if (unlikely(!ctx
->mem_idx
)) {
5578 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5581 /* NIP cannot be restored if the memory exception comes from an helper */
5582 gen_update_nip(ctx
, ctx
->nip
- 4);
5583 gen_helper_store_dcr(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
5584 /* Note: Rc update flag set leads to undefined state of Rc0 */
5588 /* mfdcrux (PPC 460) : user-mode access to DCR */
5589 static void gen_mfdcrux(DisasContext
*ctx
)
5591 /* NIP cannot be restored if the memory exception comes from an helper */
5592 gen_update_nip(ctx
, ctx
->nip
- 4);
5593 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5594 /* Note: Rc update flag set leads to undefined state of Rc0 */
5597 /* mtdcrux (PPC 460) : user-mode access to DCR */
5598 static void gen_mtdcrux(DisasContext
*ctx
)
5600 /* NIP cannot be restored if the memory exception comes from an helper */
5601 gen_update_nip(ctx
, ctx
->nip
- 4);
5602 gen_helper_store_dcr(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
5603 /* Note: Rc update flag set leads to undefined state of Rc0 */
5607 static void gen_dccci(DisasContext
*ctx
)
5609 #if defined(CONFIG_USER_ONLY)
5610 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5612 if (unlikely(!ctx
->mem_idx
)) {
5613 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5616 /* interpreted as no-op */
5621 static void gen_dcread(DisasContext
*ctx
)
5623 #if defined(CONFIG_USER_ONLY)
5624 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5627 if (unlikely(!ctx
->mem_idx
)) {
5628 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5631 gen_set_access_type(ctx
, ACCESS_CACHE
);
5632 EA
= tcg_temp_new();
5633 gen_addr_reg_index(ctx
, EA
);
5634 val
= tcg_temp_new();
5635 gen_qemu_ld32u(ctx
, val
, EA
);
5637 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], EA
);
5643 static void gen_icbt_40x(DisasContext
*ctx
)
5645 /* interpreted as no-op */
5646 /* XXX: specification say this is treated as a load by the MMU
5647 * but does not generate any exception
5652 static void gen_iccci(DisasContext
*ctx
)
5654 #if defined(CONFIG_USER_ONLY)
5655 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5657 if (unlikely(!ctx
->mem_idx
)) {
5658 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5661 /* interpreted as no-op */
5666 static void gen_icread(DisasContext
*ctx
)
5668 #if defined(CONFIG_USER_ONLY)
5669 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5671 if (unlikely(!ctx
->mem_idx
)) {
5672 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5675 /* interpreted as no-op */
5679 /* rfci (mem_idx only) */
5680 static void gen_rfci_40x(DisasContext
*ctx
)
5682 #if defined(CONFIG_USER_ONLY)
5683 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5685 if (unlikely(!ctx
->mem_idx
)) {
5686 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5689 /* Restore CPU state */
5690 gen_helper_40x_rfci();
5691 gen_sync_exception(ctx
);
5695 static void gen_rfci(DisasContext
*ctx
)
5697 #if defined(CONFIG_USER_ONLY)
5698 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5700 if (unlikely(!ctx
->mem_idx
)) {
5701 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5704 /* Restore CPU state */
5706 gen_sync_exception(ctx
);
5710 /* BookE specific */
5712 /* XXX: not implemented on 440 ? */
5713 static void gen_rfdi(DisasContext
*ctx
)
5715 #if defined(CONFIG_USER_ONLY)
5716 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5718 if (unlikely(!ctx
->mem_idx
)) {
5719 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5722 /* Restore CPU state */
5724 gen_sync_exception(ctx
);
5728 /* XXX: not implemented on 440 ? */
5729 static void gen_rfmci(DisasContext
*ctx
)
5731 #if defined(CONFIG_USER_ONLY)
5732 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5734 if (unlikely(!ctx
->mem_idx
)) {
5735 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5738 /* Restore CPU state */
5740 gen_sync_exception(ctx
);
5744 /* TLB management - PowerPC 405 implementation */
5747 static void gen_tlbre_40x(DisasContext
*ctx
)
5749 #if defined(CONFIG_USER_ONLY)
5750 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5752 if (unlikely(!ctx
->mem_idx
)) {
5753 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5756 switch (rB(ctx
->opcode
)) {
5758 gen_helper_4xx_tlbre_hi(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5761 gen_helper_4xx_tlbre_lo(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5764 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5770 /* tlbsx - tlbsx. */
5771 static void gen_tlbsx_40x(DisasContext
*ctx
)
5773 #if defined(CONFIG_USER_ONLY)
5774 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5777 if (unlikely(!ctx
->mem_idx
)) {
5778 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5781 t0
= tcg_temp_new();
5782 gen_addr_reg_index(ctx
, t0
);
5783 gen_helper_4xx_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], t0
);
5785 if (Rc(ctx
->opcode
)) {
5786 int l1
= gen_new_label();
5787 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_xer
);
5788 tcg_gen_shri_i32(cpu_crf
[0], cpu_crf
[0], XER_SO
);
5789 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 1);
5790 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
5791 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
5798 static void gen_tlbwe_40x(DisasContext
*ctx
)
5800 #if defined(CONFIG_USER_ONLY)
5801 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5803 if (unlikely(!ctx
->mem_idx
)) {
5804 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5807 switch (rB(ctx
->opcode
)) {
5809 gen_helper_4xx_tlbwe_hi(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
5812 gen_helper_4xx_tlbwe_lo(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
5815 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5821 /* TLB management - PowerPC 440 implementation */
5824 static void gen_tlbre_440(DisasContext
*ctx
)
5826 #if defined(CONFIG_USER_ONLY)
5827 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5829 if (unlikely(!ctx
->mem_idx
)) {
5830 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5833 switch (rB(ctx
->opcode
)) {
5838 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
5839 gen_helper_440_tlbwe(t0
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5840 tcg_temp_free_i32(t0
);
5844 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5850 /* tlbsx - tlbsx. */
5851 static void gen_tlbsx_440(DisasContext
*ctx
)
5853 #if defined(CONFIG_USER_ONLY)
5854 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5857 if (unlikely(!ctx
->mem_idx
)) {
5858 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5861 t0
= tcg_temp_new();
5862 gen_addr_reg_index(ctx
, t0
);
5863 gen_helper_440_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], t0
);
5865 if (Rc(ctx
->opcode
)) {
5866 int l1
= gen_new_label();
5867 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_xer
);
5868 tcg_gen_shri_i32(cpu_crf
[0], cpu_crf
[0], XER_SO
);
5869 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 1);
5870 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
5871 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
5878 static void gen_tlbwe_440(DisasContext
*ctx
)
5880 #if defined(CONFIG_USER_ONLY)
5881 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5883 if (unlikely(!ctx
->mem_idx
)) {
5884 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5887 switch (rB(ctx
->opcode
)) {
5892 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
5893 gen_helper_440_tlbwe(t0
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
5894 tcg_temp_free_i32(t0
);
5898 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5905 static void gen_wrtee(DisasContext
*ctx
)
5907 #if defined(CONFIG_USER_ONLY)
5908 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5911 if (unlikely(!ctx
->mem_idx
)) {
5912 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5915 t0
= tcg_temp_new();
5916 tcg_gen_andi_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)], (1 << MSR_EE
));
5917 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
5918 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
5920 /* Stop translation to have a chance to raise an exception
5921 * if we just set msr_ee to 1
5923 gen_stop_exception(ctx
);
5928 static void gen_wrteei(DisasContext
*ctx
)
5930 #if defined(CONFIG_USER_ONLY)
5931 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5933 if (unlikely(!ctx
->mem_idx
)) {
5934 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5937 if (ctx
->opcode
& 0x00008000) {
5938 tcg_gen_ori_tl(cpu_msr
, cpu_msr
, (1 << MSR_EE
));
5939 /* Stop translation to have a chance to raise an exception */
5940 gen_stop_exception(ctx
);
5942 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
5947 /* PowerPC 440 specific instructions */
5950 static void gen_dlmzb(DisasContext
*ctx
)
5952 TCGv_i32 t0
= tcg_const_i32(Rc(ctx
->opcode
));
5953 gen_helper_dlmzb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
5954 cpu_gpr
[rB(ctx
->opcode
)], t0
);
5955 tcg_temp_free_i32(t0
);
5958 /* mbar replaces eieio on 440 */
5959 static void gen_mbar(DisasContext
*ctx
)
5961 /* interpreted as no-op */
5964 /* msync replaces sync on 440 */
5965 static void gen_msync(DisasContext
*ctx
)
5967 /* interpreted as no-op */
5971 static void gen_icbt_440(DisasContext
*ctx
)
5973 /* interpreted as no-op */
5974 /* XXX: specification say this is treated as a load by the MMU
5975 * but does not generate any exception
5979 /*** Altivec vector extension ***/
5980 /* Altivec registers moves */
5982 static always_inline TCGv_ptr
gen_avr_ptr(int reg
)
5984 TCGv_ptr r
= tcg_temp_new_ptr();
5985 tcg_gen_addi_ptr(r
, cpu_env
, offsetof(CPUPPCState
, avr
[reg
]));
5989 #define GEN_VR_LDX(name, opc2, opc3) \
5990 static void glue(gen_, name)(DisasContext *ctx) \
5993 if (unlikely(!ctx->altivec_enabled)) { \
5994 gen_exception(ctx, POWERPC_EXCP_VPU); \
5997 gen_set_access_type(ctx, ACCESS_INT); \
5998 EA = tcg_temp_new(); \
5999 gen_addr_reg_index(ctx, EA); \
6000 tcg_gen_andi_tl(EA, EA, ~0xf); \
6001 if (ctx->le_mode) { \
6002 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6003 tcg_gen_addi_tl(EA, EA, 8); \
6004 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6006 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6007 tcg_gen_addi_tl(EA, EA, 8); \
6008 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6010 tcg_temp_free(EA); \
6013 #define GEN_VR_STX(name, opc2, opc3) \
6014 static void gen_st##name(DisasContext *ctx) \
6017 if (unlikely(!ctx->altivec_enabled)) { \
6018 gen_exception(ctx, POWERPC_EXCP_VPU); \
6021 gen_set_access_type(ctx, ACCESS_INT); \
6022 EA = tcg_temp_new(); \
6023 gen_addr_reg_index(ctx, EA); \
6024 tcg_gen_andi_tl(EA, EA, ~0xf); \
6025 if (ctx->le_mode) { \
6026 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6027 tcg_gen_addi_tl(EA, EA, 8); \
6028 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6030 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6031 tcg_gen_addi_tl(EA, EA, 8); \
6032 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6034 tcg_temp_free(EA); \
6037 #define GEN_VR_LVE(name, opc2, opc3) \
6038 static void gen_lve##name(DisasContext *ctx) \
6042 if (unlikely(!ctx->altivec_enabled)) { \
6043 gen_exception(ctx, POWERPC_EXCP_VPU); \
6046 gen_set_access_type(ctx, ACCESS_INT); \
6047 EA = tcg_temp_new(); \
6048 gen_addr_reg_index(ctx, EA); \
6049 rs = gen_avr_ptr(rS(ctx->opcode)); \
6050 gen_helper_lve##name (rs, EA); \
6051 tcg_temp_free(EA); \
6052 tcg_temp_free_ptr(rs); \
6055 #define GEN_VR_STVE(name, opc2, opc3) \
6056 static void gen_stve##name(DisasContext *ctx) \
6060 if (unlikely(!ctx->altivec_enabled)) { \
6061 gen_exception(ctx, POWERPC_EXCP_VPU); \
6064 gen_set_access_type(ctx, ACCESS_INT); \
6065 EA = tcg_temp_new(); \
6066 gen_addr_reg_index(ctx, EA); \
6067 rs = gen_avr_ptr(rS(ctx->opcode)); \
6068 gen_helper_stve##name (rs, EA); \
6069 tcg_temp_free(EA); \
6070 tcg_temp_free_ptr(rs); \
6073 GEN_VR_LDX(lvx
, 0x07, 0x03);
6074 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
6075 GEN_VR_LDX(lvxl
, 0x07, 0x0B);
6077 GEN_VR_LVE(bx
, 0x07, 0x00);
6078 GEN_VR_LVE(hx
, 0x07, 0x01);
6079 GEN_VR_LVE(wx
, 0x07, 0x02);
6081 GEN_VR_STX(svx
, 0x07, 0x07);
6082 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
6083 GEN_VR_STX(svxl
, 0x07, 0x0F);
6085 GEN_VR_STVE(bx
, 0x07, 0x04);
6086 GEN_VR_STVE(hx
, 0x07, 0x05);
6087 GEN_VR_STVE(wx
, 0x07, 0x06);
6089 static void gen_lvsl(DisasContext
*ctx
)
6093 if (unlikely(!ctx
->altivec_enabled
)) {
6094 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6097 EA
= tcg_temp_new();
6098 gen_addr_reg_index(ctx
, EA
);
6099 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6100 gen_helper_lvsl(rd
, EA
);
6102 tcg_temp_free_ptr(rd
);
6105 static void gen_lvsr(DisasContext
*ctx
)
6109 if (unlikely(!ctx
->altivec_enabled
)) {
6110 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6113 EA
= tcg_temp_new();
6114 gen_addr_reg_index(ctx
, EA
);
6115 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6116 gen_helper_lvsr(rd
, EA
);
6118 tcg_temp_free_ptr(rd
);
6121 static void gen_mfvscr(DisasContext
*ctx
)
6124 if (unlikely(!ctx
->altivec_enabled
)) {
6125 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6128 tcg_gen_movi_i64(cpu_avrh
[rD(ctx
->opcode
)], 0);
6129 t
= tcg_temp_new_i32();
6130 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUState
, vscr
));
6131 tcg_gen_extu_i32_i64(cpu_avrl
[rD(ctx
->opcode
)], t
);
6132 tcg_temp_free_i32(t
);
6135 static void gen_mtvscr(DisasContext
*ctx
)
6138 if (unlikely(!ctx
->altivec_enabled
)) {
6139 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6142 p
= gen_avr_ptr(rD(ctx
->opcode
));
6143 gen_helper_mtvscr(p
);
6144 tcg_temp_free_ptr(p
);
6147 /* Logical operations */
6148 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
6149 static void glue(gen_, name)(DisasContext *ctx) \
6151 if (unlikely(!ctx->altivec_enabled)) { \
6152 gen_exception(ctx, POWERPC_EXCP_VPU); \
6155 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6156 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6159 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16);
6160 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17);
6161 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18);
6162 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19);
6163 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20);
6165 #define GEN_VXFORM(name, opc2, opc3) \
6166 static void glue(gen_, name)(DisasContext *ctx) \
6168 TCGv_ptr ra, rb, rd; \
6169 if (unlikely(!ctx->altivec_enabled)) { \
6170 gen_exception(ctx, POWERPC_EXCP_VPU); \
6173 ra = gen_avr_ptr(rA(ctx->opcode)); \
6174 rb = gen_avr_ptr(rB(ctx->opcode)); \
6175 rd = gen_avr_ptr(rD(ctx->opcode)); \
6176 gen_helper_##name (rd, ra, rb); \
6177 tcg_temp_free_ptr(ra); \
6178 tcg_temp_free_ptr(rb); \
6179 tcg_temp_free_ptr(rd); \
6182 GEN_VXFORM(vaddubm
, 0, 0);
6183 GEN_VXFORM(vadduhm
, 0, 1);
6184 GEN_VXFORM(vadduwm
, 0, 2);
6185 GEN_VXFORM(vsububm
, 0, 16);
6186 GEN_VXFORM(vsubuhm
, 0, 17);
6187 GEN_VXFORM(vsubuwm
, 0, 18);
6188 GEN_VXFORM(vmaxub
, 1, 0);
6189 GEN_VXFORM(vmaxuh
, 1, 1);
6190 GEN_VXFORM(vmaxuw
, 1, 2);
6191 GEN_VXFORM(vmaxsb
, 1, 4);
6192 GEN_VXFORM(vmaxsh
, 1, 5);
6193 GEN_VXFORM(vmaxsw
, 1, 6);
6194 GEN_VXFORM(vminub
, 1, 8);
6195 GEN_VXFORM(vminuh
, 1, 9);
6196 GEN_VXFORM(vminuw
, 1, 10);
6197 GEN_VXFORM(vminsb
, 1, 12);
6198 GEN_VXFORM(vminsh
, 1, 13);
6199 GEN_VXFORM(vminsw
, 1, 14);
6200 GEN_VXFORM(vavgub
, 1, 16);
6201 GEN_VXFORM(vavguh
, 1, 17);
6202 GEN_VXFORM(vavguw
, 1, 18);
6203 GEN_VXFORM(vavgsb
, 1, 20);
6204 GEN_VXFORM(vavgsh
, 1, 21);
6205 GEN_VXFORM(vavgsw
, 1, 22);
6206 GEN_VXFORM(vmrghb
, 6, 0);
6207 GEN_VXFORM(vmrghh
, 6, 1);
6208 GEN_VXFORM(vmrghw
, 6, 2);
6209 GEN_VXFORM(vmrglb
, 6, 4);
6210 GEN_VXFORM(vmrglh
, 6, 5);
6211 GEN_VXFORM(vmrglw
, 6, 6);
6212 GEN_VXFORM(vmuloub
, 4, 0);
6213 GEN_VXFORM(vmulouh
, 4, 1);
6214 GEN_VXFORM(vmulosb
, 4, 4);
6215 GEN_VXFORM(vmulosh
, 4, 5);
6216 GEN_VXFORM(vmuleub
, 4, 8);
6217 GEN_VXFORM(vmuleuh
, 4, 9);
6218 GEN_VXFORM(vmulesb
, 4, 12);
6219 GEN_VXFORM(vmulesh
, 4, 13);
6220 GEN_VXFORM(vslb
, 2, 4);
6221 GEN_VXFORM(vslh
, 2, 5);
6222 GEN_VXFORM(vslw
, 2, 6);
6223 GEN_VXFORM(vsrb
, 2, 8);
6224 GEN_VXFORM(vsrh
, 2, 9);
6225 GEN_VXFORM(vsrw
, 2, 10);
6226 GEN_VXFORM(vsrab
, 2, 12);
6227 GEN_VXFORM(vsrah
, 2, 13);
6228 GEN_VXFORM(vsraw
, 2, 14);
6229 GEN_VXFORM(vslo
, 6, 16);
6230 GEN_VXFORM(vsro
, 6, 17);
6231 GEN_VXFORM(vaddcuw
, 0, 6);
6232 GEN_VXFORM(vsubcuw
, 0, 22);
6233 GEN_VXFORM(vaddubs
, 0, 8);
6234 GEN_VXFORM(vadduhs
, 0, 9);
6235 GEN_VXFORM(vadduws
, 0, 10);
6236 GEN_VXFORM(vaddsbs
, 0, 12);
6237 GEN_VXFORM(vaddshs
, 0, 13);
6238 GEN_VXFORM(vaddsws
, 0, 14);
6239 GEN_VXFORM(vsububs
, 0, 24);
6240 GEN_VXFORM(vsubuhs
, 0, 25);
6241 GEN_VXFORM(vsubuws
, 0, 26);
6242 GEN_VXFORM(vsubsbs
, 0, 28);
6243 GEN_VXFORM(vsubshs
, 0, 29);
6244 GEN_VXFORM(vsubsws
, 0, 30);
6245 GEN_VXFORM(vrlb
, 2, 0);
6246 GEN_VXFORM(vrlh
, 2, 1);
6247 GEN_VXFORM(vrlw
, 2, 2);
6248 GEN_VXFORM(vsl
, 2, 7);
6249 GEN_VXFORM(vsr
, 2, 11);
6250 GEN_VXFORM(vpkuhum
, 7, 0);
6251 GEN_VXFORM(vpkuwum
, 7, 1);
6252 GEN_VXFORM(vpkuhus
, 7, 2);
6253 GEN_VXFORM(vpkuwus
, 7, 3);
6254 GEN_VXFORM(vpkshus
, 7, 4);
6255 GEN_VXFORM(vpkswus
, 7, 5);
6256 GEN_VXFORM(vpkshss
, 7, 6);
6257 GEN_VXFORM(vpkswss
, 7, 7);
6258 GEN_VXFORM(vpkpx
, 7, 12);
6259 GEN_VXFORM(vsum4ubs
, 4, 24);
6260 GEN_VXFORM(vsum4sbs
, 4, 28);
6261 GEN_VXFORM(vsum4shs
, 4, 25);
6262 GEN_VXFORM(vsum2sws
, 4, 26);
6263 GEN_VXFORM(vsumsws
, 4, 30);
6264 GEN_VXFORM(vaddfp
, 5, 0);
6265 GEN_VXFORM(vsubfp
, 5, 1);
6266 GEN_VXFORM(vmaxfp
, 5, 16);
6267 GEN_VXFORM(vminfp
, 5, 17);
6269 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
6270 static void glue(gen_, name)(DisasContext *ctx) \
6272 TCGv_ptr ra, rb, rd; \
6273 if (unlikely(!ctx->altivec_enabled)) { \
6274 gen_exception(ctx, POWERPC_EXCP_VPU); \
6277 ra = gen_avr_ptr(rA(ctx->opcode)); \
6278 rb = gen_avr_ptr(rB(ctx->opcode)); \
6279 rd = gen_avr_ptr(rD(ctx->opcode)); \
6280 gen_helper_##opname (rd, ra, rb); \
6281 tcg_temp_free_ptr(ra); \
6282 tcg_temp_free_ptr(rb); \
6283 tcg_temp_free_ptr(rd); \
6286 #define GEN_VXRFORM(name, opc2, opc3) \
6287 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
6288 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
6290 GEN_VXRFORM(vcmpequb
, 3, 0)
6291 GEN_VXRFORM(vcmpequh
, 3, 1)
6292 GEN_VXRFORM(vcmpequw
, 3, 2)
6293 GEN_VXRFORM(vcmpgtsb
, 3, 12)
6294 GEN_VXRFORM(vcmpgtsh
, 3, 13)
6295 GEN_VXRFORM(vcmpgtsw
, 3, 14)
6296 GEN_VXRFORM(vcmpgtub
, 3, 8)
6297 GEN_VXRFORM(vcmpgtuh
, 3, 9)
6298 GEN_VXRFORM(vcmpgtuw
, 3, 10)
6299 GEN_VXRFORM(vcmpeqfp
, 3, 3)
6300 GEN_VXRFORM(vcmpgefp
, 3, 7)
6301 GEN_VXRFORM(vcmpgtfp
, 3, 11)
6302 GEN_VXRFORM(vcmpbfp
, 3, 15)
6304 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
6305 static void glue(gen_, name)(DisasContext *ctx) \
6309 if (unlikely(!ctx->altivec_enabled)) { \
6310 gen_exception(ctx, POWERPC_EXCP_VPU); \
6313 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6314 rd = gen_avr_ptr(rD(ctx->opcode)); \
6315 gen_helper_##name (rd, simm); \
6316 tcg_temp_free_i32(simm); \
6317 tcg_temp_free_ptr(rd); \
6320 GEN_VXFORM_SIMM(vspltisb
, 6, 12);
6321 GEN_VXFORM_SIMM(vspltish
, 6, 13);
6322 GEN_VXFORM_SIMM(vspltisw
, 6, 14);
6324 #define GEN_VXFORM_NOA(name, opc2, opc3) \
6325 static void glue(gen_, name)(DisasContext *ctx) \
6328 if (unlikely(!ctx->altivec_enabled)) { \
6329 gen_exception(ctx, POWERPC_EXCP_VPU); \
6332 rb = gen_avr_ptr(rB(ctx->opcode)); \
6333 rd = gen_avr_ptr(rD(ctx->opcode)); \
6334 gen_helper_##name (rd, rb); \
6335 tcg_temp_free_ptr(rb); \
6336 tcg_temp_free_ptr(rd); \
6339 GEN_VXFORM_NOA(vupkhsb
, 7, 8);
6340 GEN_VXFORM_NOA(vupkhsh
, 7, 9);
6341 GEN_VXFORM_NOA(vupklsb
, 7, 10);
6342 GEN_VXFORM_NOA(vupklsh
, 7, 11);
6343 GEN_VXFORM_NOA(vupkhpx
, 7, 13);
6344 GEN_VXFORM_NOA(vupklpx
, 7, 15);
6345 GEN_VXFORM_NOA(vrefp
, 5, 4);
6346 GEN_VXFORM_NOA(vrsqrtefp
, 5, 5);
6347 GEN_VXFORM_NOA(vlogefp
, 5, 7);
6348 GEN_VXFORM_NOA(vrfim
, 5, 8);
6349 GEN_VXFORM_NOA(vrfin
, 5, 9);
6350 GEN_VXFORM_NOA(vrfip
, 5, 10);
6351 GEN_VXFORM_NOA(vrfiz
, 5, 11);
6353 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
6354 static void glue(gen_, name)(DisasContext *ctx) \
6358 if (unlikely(!ctx->altivec_enabled)) { \
6359 gen_exception(ctx, POWERPC_EXCP_VPU); \
6362 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6363 rd = gen_avr_ptr(rD(ctx->opcode)); \
6364 gen_helper_##name (rd, simm); \
6365 tcg_temp_free_i32(simm); \
6366 tcg_temp_free_ptr(rd); \
6369 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
6370 static void glue(gen_, name)(DisasContext *ctx) \
6374 if (unlikely(!ctx->altivec_enabled)) { \
6375 gen_exception(ctx, POWERPC_EXCP_VPU); \
6378 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
6379 rb = gen_avr_ptr(rB(ctx->opcode)); \
6380 rd = gen_avr_ptr(rD(ctx->opcode)); \
6381 gen_helper_##name (rd, rb, uimm); \
6382 tcg_temp_free_i32(uimm); \
6383 tcg_temp_free_ptr(rb); \
6384 tcg_temp_free_ptr(rd); \
6387 GEN_VXFORM_UIMM(vspltb
, 6, 8);
6388 GEN_VXFORM_UIMM(vsplth
, 6, 9);
6389 GEN_VXFORM_UIMM(vspltw
, 6, 10);
6390 GEN_VXFORM_UIMM(vcfux
, 5, 12);
6391 GEN_VXFORM_UIMM(vcfsx
, 5, 13);
6392 GEN_VXFORM_UIMM(vctuxs
, 5, 14);
6393 GEN_VXFORM_UIMM(vctsxs
, 5, 15);
6395 static void gen_vsldoi(DisasContext
*ctx
)
6397 TCGv_ptr ra
, rb
, rd
;
6399 if (unlikely(!ctx
->altivec_enabled
)) {
6400 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6403 ra
= gen_avr_ptr(rA(ctx
->opcode
));
6404 rb
= gen_avr_ptr(rB(ctx
->opcode
));
6405 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6406 sh
= tcg_const_i32(VSH(ctx
->opcode
));
6407 gen_helper_vsldoi (rd
, ra
, rb
, sh
);
6408 tcg_temp_free_ptr(ra
);
6409 tcg_temp_free_ptr(rb
);
6410 tcg_temp_free_ptr(rd
);
6411 tcg_temp_free_i32(sh
);
6414 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
6415 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
6417 TCGv_ptr ra, rb, rc, rd; \
6418 if (unlikely(!ctx->altivec_enabled)) { \
6419 gen_exception(ctx, POWERPC_EXCP_VPU); \
6422 ra = gen_avr_ptr(rA(ctx->opcode)); \
6423 rb = gen_avr_ptr(rB(ctx->opcode)); \
6424 rc = gen_avr_ptr(rC(ctx->opcode)); \
6425 rd = gen_avr_ptr(rD(ctx->opcode)); \
6426 if (Rc(ctx->opcode)) { \
6427 gen_helper_##name1 (rd, ra, rb, rc); \
6429 gen_helper_##name0 (rd, ra, rb, rc); \
6431 tcg_temp_free_ptr(ra); \
6432 tcg_temp_free_ptr(rb); \
6433 tcg_temp_free_ptr(rc); \
6434 tcg_temp_free_ptr(rd); \
6437 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16)
6439 static void gen_vmladduhm(DisasContext
*ctx
)
6441 TCGv_ptr ra
, rb
, rc
, rd
;
6442 if (unlikely(!ctx
->altivec_enabled
)) {
6443 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6446 ra
= gen_avr_ptr(rA(ctx
->opcode
));
6447 rb
= gen_avr_ptr(rB(ctx
->opcode
));
6448 rc
= gen_avr_ptr(rC(ctx
->opcode
));
6449 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6450 gen_helper_vmladduhm(rd
, ra
, rb
, rc
);
6451 tcg_temp_free_ptr(ra
);
6452 tcg_temp_free_ptr(rb
);
6453 tcg_temp_free_ptr(rc
);
6454 tcg_temp_free_ptr(rd
);
6457 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18)
6458 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19)
6459 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20)
6460 GEN_VAFORM_PAIRED(vsel
, vperm
, 21)
6461 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23)
6463 /*** SPE extension ***/
6464 /* Register moves */
6466 static always_inline
void gen_load_gpr64(TCGv_i64 t
, int reg
) {
6467 #if defined(TARGET_PPC64)
6468 tcg_gen_mov_i64(t
, cpu_gpr
[reg
]);
6470 tcg_gen_concat_i32_i64(t
, cpu_gpr
[reg
], cpu_gprh
[reg
]);
6474 static always_inline
void gen_store_gpr64(int reg
, TCGv_i64 t
) {
6475 #if defined(TARGET_PPC64)
6476 tcg_gen_mov_i64(cpu_gpr
[reg
], t
);
6478 TCGv_i64 tmp
= tcg_temp_new_i64();
6479 tcg_gen_trunc_i64_i32(cpu_gpr
[reg
], t
);
6480 tcg_gen_shri_i64(tmp
, t
, 32);
6481 tcg_gen_trunc_i64_i32(cpu_gprh
[reg
], tmp
);
6482 tcg_temp_free_i64(tmp
);
6486 #define GEN_SPE(name0, name1, opc2, opc3, inval, type) \
6487 static void glue(gen_, name0##_##name1)(DisasContext *ctx) \
6489 if (Rc(ctx->opcode)) \
6495 /* Handler for undefined SPE opcodes */
6496 static always_inline
void gen_speundef (DisasContext
*ctx
)
6498 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6502 #if defined(TARGET_PPC64)
6503 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
6504 static always_inline void gen_##name (DisasContext *ctx) \
6506 if (unlikely(!ctx->spe_enabled)) { \
6507 gen_exception(ctx, POWERPC_EXCP_APU); \
6510 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6511 cpu_gpr[rB(ctx->opcode)]); \
6514 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
6515 static always_inline void gen_##name (DisasContext *ctx) \
6517 if (unlikely(!ctx->spe_enabled)) { \
6518 gen_exception(ctx, POWERPC_EXCP_APU); \
6521 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6522 cpu_gpr[rB(ctx->opcode)]); \
6523 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6524 cpu_gprh[rB(ctx->opcode)]); \
6528 GEN_SPEOP_LOGIC2(evand
, tcg_gen_and_tl
);
6529 GEN_SPEOP_LOGIC2(evandc
, tcg_gen_andc_tl
);
6530 GEN_SPEOP_LOGIC2(evxor
, tcg_gen_xor_tl
);
6531 GEN_SPEOP_LOGIC2(evor
, tcg_gen_or_tl
);
6532 GEN_SPEOP_LOGIC2(evnor
, tcg_gen_nor_tl
);
6533 GEN_SPEOP_LOGIC2(eveqv
, tcg_gen_eqv_tl
);
6534 GEN_SPEOP_LOGIC2(evorc
, tcg_gen_orc_tl
);
6535 GEN_SPEOP_LOGIC2(evnand
, tcg_gen_nand_tl
);
6537 /* SPE logic immediate */
6538 #if defined(TARGET_PPC64)
6539 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
6540 static always_inline void gen_##name (DisasContext *ctx) \
6542 if (unlikely(!ctx->spe_enabled)) { \
6543 gen_exception(ctx, POWERPC_EXCP_APU); \
6546 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6547 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6548 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6549 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6550 tcg_opi(t0, t0, rB(ctx->opcode)); \
6551 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6552 tcg_gen_trunc_i64_i32(t1, t2); \
6553 tcg_temp_free_i64(t2); \
6554 tcg_opi(t1, t1, rB(ctx->opcode)); \
6555 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6556 tcg_temp_free_i32(t0); \
6557 tcg_temp_free_i32(t1); \
6560 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
6561 static always_inline void gen_##name (DisasContext *ctx) \
6563 if (unlikely(!ctx->spe_enabled)) { \
6564 gen_exception(ctx, POWERPC_EXCP_APU); \
6567 tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6569 tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6573 GEN_SPEOP_TCG_LOGIC_IMM2(evslwi
, tcg_gen_shli_i32
);
6574 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu
, tcg_gen_shri_i32
);
6575 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis
, tcg_gen_sari_i32
);
6576 GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi
, tcg_gen_rotli_i32
);
6578 /* SPE arithmetic */
6579 #if defined(TARGET_PPC64)
6580 #define GEN_SPEOP_ARITH1(name, tcg_op) \
6581 static always_inline void gen_##name (DisasContext *ctx) \
6583 if (unlikely(!ctx->spe_enabled)) { \
6584 gen_exception(ctx, POWERPC_EXCP_APU); \
6587 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6588 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6589 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6590 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6592 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6593 tcg_gen_trunc_i64_i32(t1, t2); \
6594 tcg_temp_free_i64(t2); \
6596 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6597 tcg_temp_free_i32(t0); \
6598 tcg_temp_free_i32(t1); \
6601 #define GEN_SPEOP_ARITH1(name, tcg_op) \
6602 static always_inline void gen_##name (DisasContext *ctx) \
6604 if (unlikely(!ctx->spe_enabled)) { \
6605 gen_exception(ctx, POWERPC_EXCP_APU); \
6608 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
6609 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
6613 static always_inline
void gen_op_evabs (TCGv_i32 ret
, TCGv_i32 arg1
)
6615 int l1
= gen_new_label();
6616 int l2
= gen_new_label();
6618 tcg_gen_brcondi_i32(TCG_COND_GE
, arg1
, 0, l1
);
6619 tcg_gen_neg_i32(ret
, arg1
);
6622 tcg_gen_mov_i32(ret
, arg1
);
6625 GEN_SPEOP_ARITH1(evabs
, gen_op_evabs
);
6626 GEN_SPEOP_ARITH1(evneg
, tcg_gen_neg_i32
);
6627 GEN_SPEOP_ARITH1(evextsb
, tcg_gen_ext8s_i32
);
6628 GEN_SPEOP_ARITH1(evextsh
, tcg_gen_ext16s_i32
);
6629 static always_inline
void gen_op_evrndw (TCGv_i32 ret
, TCGv_i32 arg1
)
6631 tcg_gen_addi_i32(ret
, arg1
, 0x8000);
6632 tcg_gen_ext16u_i32(ret
, ret
);
6634 GEN_SPEOP_ARITH1(evrndw
, gen_op_evrndw
);
6635 GEN_SPEOP_ARITH1(evcntlsw
, gen_helper_cntlsw32
);
6636 GEN_SPEOP_ARITH1(evcntlzw
, gen_helper_cntlzw32
);
6638 #if defined(TARGET_PPC64)
6639 #define GEN_SPEOP_ARITH2(name, tcg_op) \
6640 static always_inline void gen_##name (DisasContext *ctx) \
6642 if (unlikely(!ctx->spe_enabled)) { \
6643 gen_exception(ctx, POWERPC_EXCP_APU); \
6646 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6647 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6648 TCGv_i32 t2 = tcg_temp_local_new_i32(); \
6649 TCGv_i64 t3 = tcg_temp_local_new_i64(); \
6650 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6651 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
6652 tcg_op(t0, t0, t2); \
6653 tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
6654 tcg_gen_trunc_i64_i32(t1, t3); \
6655 tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
6656 tcg_gen_trunc_i64_i32(t2, t3); \
6657 tcg_temp_free_i64(t3); \
6658 tcg_op(t1, t1, t2); \
6659 tcg_temp_free_i32(t2); \
6660 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6661 tcg_temp_free_i32(t0); \
6662 tcg_temp_free_i32(t1); \
6665 #define GEN_SPEOP_ARITH2(name, tcg_op) \
6666 static always_inline void gen_##name (DisasContext *ctx) \
6668 if (unlikely(!ctx->spe_enabled)) { \
6669 gen_exception(ctx, POWERPC_EXCP_APU); \
6672 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6673 cpu_gpr[rB(ctx->opcode)]); \
6674 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6675 cpu_gprh[rB(ctx->opcode)]); \
6679 static always_inline
void gen_op_evsrwu (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6684 l1
= gen_new_label();
6685 l2
= gen_new_label();
6686 t0
= tcg_temp_local_new_i32();
6687 /* No error here: 6 bits are used */
6688 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
6689 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
6690 tcg_gen_shr_i32(ret
, arg1
, t0
);
6693 tcg_gen_movi_i32(ret
, 0);
6695 tcg_temp_free_i32(t0
);
6697 GEN_SPEOP_ARITH2(evsrwu
, gen_op_evsrwu
);
6698 static always_inline
void gen_op_evsrws (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6703 l1
= gen_new_label();
6704 l2
= gen_new_label();
6705 t0
= tcg_temp_local_new_i32();
6706 /* No error here: 6 bits are used */
6707 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
6708 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
6709 tcg_gen_sar_i32(ret
, arg1
, t0
);
6712 tcg_gen_movi_i32(ret
, 0);
6714 tcg_temp_free_i32(t0
);
6716 GEN_SPEOP_ARITH2(evsrws
, gen_op_evsrws
);
6717 static always_inline
void gen_op_evslw (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6722 l1
= gen_new_label();
6723 l2
= gen_new_label();
6724 t0
= tcg_temp_local_new_i32();
6725 /* No error here: 6 bits are used */
6726 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
6727 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
6728 tcg_gen_shl_i32(ret
, arg1
, t0
);
6731 tcg_gen_movi_i32(ret
, 0);
6733 tcg_temp_free_i32(t0
);
6735 GEN_SPEOP_ARITH2(evslw
, gen_op_evslw
);
6736 static always_inline
void gen_op_evrlw (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6738 TCGv_i32 t0
= tcg_temp_new_i32();
6739 tcg_gen_andi_i32(t0
, arg2
, 0x1F);
6740 tcg_gen_rotl_i32(ret
, arg1
, t0
);
6741 tcg_temp_free_i32(t0
);
6743 GEN_SPEOP_ARITH2(evrlw
, gen_op_evrlw
);
6744 static always_inline
void gen_evmergehi (DisasContext
*ctx
)
6746 if (unlikely(!ctx
->spe_enabled
)) {
6747 gen_exception(ctx
, POWERPC_EXCP_APU
);
6750 #if defined(TARGET_PPC64)
6751 TCGv t0
= tcg_temp_new();
6752 TCGv t1
= tcg_temp_new();
6753 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
6754 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
6755 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
6759 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
6760 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6763 GEN_SPEOP_ARITH2(evaddw
, tcg_gen_add_i32
);
6764 static always_inline
void gen_op_evsubf (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6766 tcg_gen_sub_i32(ret
, arg2
, arg1
);
6768 GEN_SPEOP_ARITH2(evsubfw
, gen_op_evsubf
);
6770 /* SPE arithmetic immediate */
6771 #if defined(TARGET_PPC64)
6772 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
6773 static always_inline void gen_##name (DisasContext *ctx) \
6775 if (unlikely(!ctx->spe_enabled)) { \
6776 gen_exception(ctx, POWERPC_EXCP_APU); \
6779 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6780 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6781 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6782 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
6783 tcg_op(t0, t0, rA(ctx->opcode)); \
6784 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
6785 tcg_gen_trunc_i64_i32(t1, t2); \
6786 tcg_temp_free_i64(t2); \
6787 tcg_op(t1, t1, rA(ctx->opcode)); \
6788 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6789 tcg_temp_free_i32(t0); \
6790 tcg_temp_free_i32(t1); \
6793 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
6794 static always_inline void gen_##name (DisasContext *ctx) \
6796 if (unlikely(!ctx->spe_enabled)) { \
6797 gen_exception(ctx, POWERPC_EXCP_APU); \
6800 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
6802 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
6806 GEN_SPEOP_ARITH_IMM2(evaddiw
, tcg_gen_addi_i32
);
6807 GEN_SPEOP_ARITH_IMM2(evsubifw
, tcg_gen_subi_i32
);
6809 /* SPE comparison */
6810 #if defined(TARGET_PPC64)
6811 #define GEN_SPEOP_COMP(name, tcg_cond) \
6812 static always_inline void gen_##name (DisasContext *ctx) \
6814 if (unlikely(!ctx->spe_enabled)) { \
6815 gen_exception(ctx, POWERPC_EXCP_APU); \
6818 int l1 = gen_new_label(); \
6819 int l2 = gen_new_label(); \
6820 int l3 = gen_new_label(); \
6821 int l4 = gen_new_label(); \
6822 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6823 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6824 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6825 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6826 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
6827 tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
6828 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
6830 gen_set_label(l1); \
6831 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
6832 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
6833 gen_set_label(l2); \
6834 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6835 tcg_gen_trunc_i64_i32(t0, t2); \
6836 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
6837 tcg_gen_trunc_i64_i32(t1, t2); \
6838 tcg_temp_free_i64(t2); \
6839 tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
6840 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6841 ~(CRF_CH | CRF_CH_AND_CL)); \
6843 gen_set_label(l3); \
6844 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6845 CRF_CH | CRF_CH_OR_CL); \
6846 gen_set_label(l4); \
6847 tcg_temp_free_i32(t0); \
6848 tcg_temp_free_i32(t1); \
6851 #define GEN_SPEOP_COMP(name, tcg_cond) \
6852 static always_inline void gen_##name (DisasContext *ctx) \
6854 if (unlikely(!ctx->spe_enabled)) { \
6855 gen_exception(ctx, POWERPC_EXCP_APU); \
6858 int l1 = gen_new_label(); \
6859 int l2 = gen_new_label(); \
6860 int l3 = gen_new_label(); \
6861 int l4 = gen_new_label(); \
6863 tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
6864 cpu_gpr[rB(ctx->opcode)], l1); \
6865 tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
6867 gen_set_label(l1); \
6868 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
6869 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
6870 gen_set_label(l2); \
6871 tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
6872 cpu_gprh[rB(ctx->opcode)], l3); \
6873 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6874 ~(CRF_CH | CRF_CH_AND_CL)); \
6876 gen_set_label(l3); \
6877 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6878 CRF_CH | CRF_CH_OR_CL); \
6879 gen_set_label(l4); \
6882 GEN_SPEOP_COMP(evcmpgtu
, TCG_COND_GTU
);
6883 GEN_SPEOP_COMP(evcmpgts
, TCG_COND_GT
);
6884 GEN_SPEOP_COMP(evcmpltu
, TCG_COND_LTU
);
6885 GEN_SPEOP_COMP(evcmplts
, TCG_COND_LT
);
6886 GEN_SPEOP_COMP(evcmpeq
, TCG_COND_EQ
);
6889 static always_inline
void gen_brinc (DisasContext
*ctx
)
6891 /* Note: brinc is usable even if SPE is disabled */
6892 gen_helper_brinc(cpu_gpr
[rD(ctx
->opcode
)],
6893 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6895 static always_inline
void gen_evmergelo (DisasContext
*ctx
)
6897 if (unlikely(!ctx
->spe_enabled
)) {
6898 gen_exception(ctx
, POWERPC_EXCP_APU
);
6901 #if defined(TARGET_PPC64)
6902 TCGv t0
= tcg_temp_new();
6903 TCGv t1
= tcg_temp_new();
6904 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x00000000FFFFFFFFLL
);
6905 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
6906 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
6910 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6911 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6914 static always_inline
void gen_evmergehilo (DisasContext
*ctx
)
6916 if (unlikely(!ctx
->spe_enabled
)) {
6917 gen_exception(ctx
, POWERPC_EXCP_APU
);
6920 #if defined(TARGET_PPC64)
6921 TCGv t0
= tcg_temp_new();
6922 TCGv t1
= tcg_temp_new();
6923 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x00000000FFFFFFFFLL
);
6924 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
6925 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
6929 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6930 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6933 static always_inline
void gen_evmergelohi (DisasContext
*ctx
)
6935 if (unlikely(!ctx
->spe_enabled
)) {
6936 gen_exception(ctx
, POWERPC_EXCP_APU
);
6939 #if defined(TARGET_PPC64)
6940 TCGv t0
= tcg_temp_new();
6941 TCGv t1
= tcg_temp_new();
6942 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
6943 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
6944 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
6948 if (rD(ctx
->opcode
) == rA(ctx
->opcode
)) {
6949 TCGv_i32 tmp
= tcg_temp_new_i32();
6950 tcg_gen_mov_i32(tmp
, cpu_gpr
[rA(ctx
->opcode
)]);
6951 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
6952 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], tmp
);
6953 tcg_temp_free_i32(tmp
);
6955 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
6956 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6960 static always_inline
void gen_evsplati (DisasContext
*ctx
)
6962 uint64_t imm
= ((int32_t)(rA(ctx
->opcode
) << 11)) >> 27;
6964 #if defined(TARGET_PPC64)
6965 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
6967 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
6968 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
6971 static always_inline
void gen_evsplatfi (DisasContext
*ctx
)
6973 uint64_t imm
= rA(ctx
->opcode
) << 11;
6975 #if defined(TARGET_PPC64)
6976 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
6978 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
6979 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
6983 static always_inline
void gen_evsel (DisasContext
*ctx
)
6985 int l1
= gen_new_label();
6986 int l2
= gen_new_label();
6987 int l3
= gen_new_label();
6988 int l4
= gen_new_label();
6989 TCGv_i32 t0
= tcg_temp_local_new_i32();
6990 #if defined(TARGET_PPC64)
6991 TCGv t1
= tcg_temp_local_new();
6992 TCGv t2
= tcg_temp_local_new();
6994 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 3);
6995 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
6996 #if defined(TARGET_PPC64)
6997 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
6999 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
7003 #if defined(TARGET_PPC64)
7004 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
7006 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
7009 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 2);
7010 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l3
);
7011 #if defined(TARGET_PPC64)
7012 tcg_gen_andi_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], 0x00000000FFFFFFFFULL
);
7014 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
7018 #if defined(TARGET_PPC64)
7019 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x00000000FFFFFFFFULL
);
7021 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7024 tcg_temp_free_i32(t0
);
7025 #if defined(TARGET_PPC64)
7026 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
, t2
);
7032 static void gen_evsel0(DisasContext
*ctx
)
7037 static void gen_evsel1(DisasContext
*ctx
)
7042 static void gen_evsel2(DisasContext
*ctx
)
7047 static void gen_evsel3(DisasContext
*ctx
)
7052 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, PPC_SPE
); ////
7053 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, PPC_SPE
);
7054 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, PPC_SPE
); ////
7055 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, PPC_SPE
);
7056 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, PPC_SPE
); ////
7057 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, PPC_SPE
); ////
7058 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, PPC_SPE
); ////
7059 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x00000000, PPC_SPE
); //
7060 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0x00000000, PPC_SPE
); ////
7061 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, PPC_SPE
); ////
7062 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, PPC_SPE
); ////
7063 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, PPC_SPE
); ////
7064 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0x00000000, PPC_SPE
); ////
7065 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, PPC_SPE
); ////
7066 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, PPC_SPE
); ////
7067 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, PPC_SPE
);
7068 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, PPC_SPE
); ////
7069 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, PPC_SPE
);
7070 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, PPC_SPE
); //
7071 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, PPC_SPE
);
7072 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, PPC_SPE
); ////
7073 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, PPC_SPE
); ////
7074 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, PPC_SPE
); ////
7075 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, PPC_SPE
); ////
7076 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, PPC_SPE
); ////
7078 /* SPE load and stores */
7079 static always_inline
void gen_addr_spe_imm_index (DisasContext
*ctx
, TCGv EA
, int sh
)
7081 target_ulong uimm
= rB(ctx
->opcode
);
7083 if (rA(ctx
->opcode
) == 0) {
7084 tcg_gen_movi_tl(EA
, uimm
<< sh
);
7086 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], uimm
<< sh
);
7087 #if defined(TARGET_PPC64)
7088 if (!ctx
->sf_mode
) {
7089 tcg_gen_ext32u_tl(EA
, EA
);
7095 static always_inline
void gen_op_evldd(DisasContext
*ctx
, TCGv addr
)
7097 #if defined(TARGET_PPC64)
7098 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7100 TCGv_i64 t0
= tcg_temp_new_i64();
7101 gen_qemu_ld64(ctx
, t0
, addr
);
7102 tcg_gen_trunc_i64_i32(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7103 tcg_gen_shri_i64(t0
, t0
, 32);
7104 tcg_gen_trunc_i64_i32(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7105 tcg_temp_free_i64(t0
);
7109 static always_inline
void gen_op_evldw(DisasContext
*ctx
, TCGv addr
)
7111 #if defined(TARGET_PPC64)
7112 TCGv t0
= tcg_temp_new();
7113 gen_qemu_ld32u(ctx
, t0
, addr
);
7114 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7115 gen_addr_add(ctx
, addr
, addr
, 4);
7116 gen_qemu_ld32u(ctx
, t0
, addr
);
7117 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7120 gen_qemu_ld32u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7121 gen_addr_add(ctx
, addr
, addr
, 4);
7122 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7126 static always_inline
void gen_op_evldh(DisasContext
*ctx
, TCGv addr
)
7128 TCGv t0
= tcg_temp_new();
7129 #if defined(TARGET_PPC64)
7130 gen_qemu_ld16u(ctx
, t0
, addr
);
7131 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7132 gen_addr_add(ctx
, addr
, addr
, 2);
7133 gen_qemu_ld16u(ctx
, t0
, addr
);
7134 tcg_gen_shli_tl(t0
, t0
, 32);
7135 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7136 gen_addr_add(ctx
, addr
, addr
, 2);
7137 gen_qemu_ld16u(ctx
, t0
, addr
);
7138 tcg_gen_shli_tl(t0
, t0
, 16);
7139 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7140 gen_addr_add(ctx
, addr
, addr
, 2);
7141 gen_qemu_ld16u(ctx
, t0
, addr
);
7142 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7144 gen_qemu_ld16u(ctx
, t0
, addr
);
7145 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7146 gen_addr_add(ctx
, addr
, addr
, 2);
7147 gen_qemu_ld16u(ctx
, t0
, addr
);
7148 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
7149 gen_addr_add(ctx
, addr
, addr
, 2);
7150 gen_qemu_ld16u(ctx
, t0
, addr
);
7151 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7152 gen_addr_add(ctx
, addr
, addr
, 2);
7153 gen_qemu_ld16u(ctx
, t0
, addr
);
7154 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7159 static always_inline
void gen_op_evlhhesplat(DisasContext
*ctx
, TCGv addr
)
7161 TCGv t0
= tcg_temp_new();
7162 gen_qemu_ld16u(ctx
, t0
, addr
);
7163 #if defined(TARGET_PPC64)
7164 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7165 tcg_gen_shli_tl(t0
, t0
, 16);
7166 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7168 tcg_gen_shli_tl(t0
, t0
, 16);
7169 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7170 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7175 static always_inline
void gen_op_evlhhousplat(DisasContext
*ctx
, TCGv addr
)
7177 TCGv t0
= tcg_temp_new();
7178 gen_qemu_ld16u(ctx
, t0
, addr
);
7179 #if defined(TARGET_PPC64)
7180 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7181 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7183 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7184 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7189 static always_inline
void gen_op_evlhhossplat(DisasContext
*ctx
, TCGv addr
)
7191 TCGv t0
= tcg_temp_new();
7192 gen_qemu_ld16s(ctx
, t0
, addr
);
7193 #if defined(TARGET_PPC64)
7194 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7195 tcg_gen_ext32u_tl(t0
, t0
);
7196 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7198 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7199 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7204 static always_inline
void gen_op_evlwhe(DisasContext
*ctx
, TCGv addr
)
7206 TCGv t0
= tcg_temp_new();
7207 #if defined(TARGET_PPC64)
7208 gen_qemu_ld16u(ctx
, t0
, addr
);
7209 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7210 gen_addr_add(ctx
, addr
, addr
, 2);
7211 gen_qemu_ld16u(ctx
, t0
, addr
);
7212 tcg_gen_shli_tl(t0
, t0
, 16);
7213 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7215 gen_qemu_ld16u(ctx
, t0
, addr
);
7216 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7217 gen_addr_add(ctx
, addr
, addr
, 2);
7218 gen_qemu_ld16u(ctx
, t0
, addr
);
7219 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
7224 static always_inline
void gen_op_evlwhou(DisasContext
*ctx
, TCGv addr
)
7226 #if defined(TARGET_PPC64)
7227 TCGv t0
= tcg_temp_new();
7228 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7229 gen_addr_add(ctx
, addr
, addr
, 2);
7230 gen_qemu_ld16u(ctx
, t0
, addr
);
7231 tcg_gen_shli_tl(t0
, t0
, 32);
7232 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7235 gen_qemu_ld16u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7236 gen_addr_add(ctx
, addr
, addr
, 2);
7237 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7241 static always_inline
void gen_op_evlwhos(DisasContext
*ctx
, TCGv addr
)
7243 #if defined(TARGET_PPC64)
7244 TCGv t0
= tcg_temp_new();
7245 gen_qemu_ld16s(ctx
, t0
, addr
);
7246 tcg_gen_ext32u_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7247 gen_addr_add(ctx
, addr
, addr
, 2);
7248 gen_qemu_ld16s(ctx
, t0
, addr
);
7249 tcg_gen_shli_tl(t0
, t0
, 32);
7250 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7253 gen_qemu_ld16s(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7254 gen_addr_add(ctx
, addr
, addr
, 2);
7255 gen_qemu_ld16s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7259 static always_inline
void gen_op_evlwwsplat(DisasContext
*ctx
, TCGv addr
)
7261 TCGv t0
= tcg_temp_new();
7262 gen_qemu_ld32u(ctx
, t0
, addr
);
7263 #if defined(TARGET_PPC64)
7264 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7265 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7267 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7268 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7273 static always_inline
void gen_op_evlwhsplat(DisasContext
*ctx
, TCGv addr
)
7275 TCGv t0
= tcg_temp_new();
7276 #if defined(TARGET_PPC64)
7277 gen_qemu_ld16u(ctx
, t0
, addr
);
7278 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7279 tcg_gen_shli_tl(t0
, t0
, 32);
7280 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7281 gen_addr_add(ctx
, addr
, addr
, 2);
7282 gen_qemu_ld16u(ctx
, t0
, addr
);
7283 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7284 tcg_gen_shli_tl(t0
, t0
, 16);
7285 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7287 gen_qemu_ld16u(ctx
, t0
, addr
);
7288 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7289 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
7290 gen_addr_add(ctx
, addr
, addr
, 2);
7291 gen_qemu_ld16u(ctx
, t0
, addr
);
7292 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
7293 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
7298 static always_inline
void gen_op_evstdd(DisasContext
*ctx
, TCGv addr
)
7300 #if defined(TARGET_PPC64)
7301 gen_qemu_st64(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7303 TCGv_i64 t0
= tcg_temp_new_i64();
7304 tcg_gen_concat_i32_i64(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gprh
[rS(ctx
->opcode
)]);
7305 gen_qemu_st64(ctx
, t0
, addr
);
7306 tcg_temp_free_i64(t0
);
7310 static always_inline
void gen_op_evstdw(DisasContext
*ctx
, TCGv addr
)
7312 #if defined(TARGET_PPC64)
7313 TCGv t0
= tcg_temp_new();
7314 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7315 gen_qemu_st32(ctx
, t0
, addr
);
7318 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7320 gen_addr_add(ctx
, addr
, addr
, 4);
7321 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7324 static always_inline
void gen_op_evstdh(DisasContext
*ctx
, TCGv addr
)
7326 TCGv t0
= tcg_temp_new();
7327 #if defined(TARGET_PPC64)
7328 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
7330 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
7332 gen_qemu_st16(ctx
, t0
, addr
);
7333 gen_addr_add(ctx
, addr
, addr
, 2);
7334 #if defined(TARGET_PPC64)
7335 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7336 gen_qemu_st16(ctx
, t0
, addr
);
7338 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7340 gen_addr_add(ctx
, addr
, addr
, 2);
7341 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
7342 gen_qemu_st16(ctx
, t0
, addr
);
7344 gen_addr_add(ctx
, addr
, addr
, 2);
7345 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7348 static always_inline
void gen_op_evstwhe(DisasContext
*ctx
, TCGv addr
)
7350 TCGv t0
= tcg_temp_new();
7351 #if defined(TARGET_PPC64)
7352 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
7354 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
7356 gen_qemu_st16(ctx
, t0
, addr
);
7357 gen_addr_add(ctx
, addr
, addr
, 2);
7358 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
7359 gen_qemu_st16(ctx
, t0
, addr
);
7363 static always_inline
void gen_op_evstwho(DisasContext
*ctx
, TCGv addr
)
7365 #if defined(TARGET_PPC64)
7366 TCGv t0
= tcg_temp_new();
7367 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7368 gen_qemu_st16(ctx
, t0
, addr
);
7371 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7373 gen_addr_add(ctx
, addr
, addr
, 2);
7374 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7377 static always_inline
void gen_op_evstwwe(DisasContext
*ctx
, TCGv addr
)
7379 #if defined(TARGET_PPC64)
7380 TCGv t0
= tcg_temp_new();
7381 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7382 gen_qemu_st32(ctx
, t0
, addr
);
7385 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7389 static always_inline
void gen_op_evstwwo(DisasContext
*ctx
, TCGv addr
)
7391 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7394 #define GEN_SPEOP_LDST(name, opc2, sh) \
7395 static void glue(gen_, name)(DisasContext *ctx) \
7398 if (unlikely(!ctx->spe_enabled)) { \
7399 gen_exception(ctx, POWERPC_EXCP_APU); \
7402 gen_set_access_type(ctx, ACCESS_INT); \
7403 t0 = tcg_temp_new(); \
7404 if (Rc(ctx->opcode)) { \
7405 gen_addr_spe_imm_index(ctx, t0, sh); \
7407 gen_addr_reg_index(ctx, t0); \
7409 gen_op_##name(ctx, t0); \
7410 tcg_temp_free(t0); \
7413 GEN_SPEOP_LDST(evldd
, 0x00, 3);
7414 GEN_SPEOP_LDST(evldw
, 0x01, 3);
7415 GEN_SPEOP_LDST(evldh
, 0x02, 3);
7416 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1);
7417 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1);
7418 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1);
7419 GEN_SPEOP_LDST(evlwhe
, 0x08, 2);
7420 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2);
7421 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2);
7422 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2);
7423 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2);
7425 GEN_SPEOP_LDST(evstdd
, 0x10, 3);
7426 GEN_SPEOP_LDST(evstdw
, 0x11, 3);
7427 GEN_SPEOP_LDST(evstdh
, 0x12, 3);
7428 GEN_SPEOP_LDST(evstwhe
, 0x18, 2);
7429 GEN_SPEOP_LDST(evstwho
, 0x1A, 2);
7430 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2);
7431 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2);
7433 /* Multiply and add - TODO */
7435 GEN_SPE(speundef
, evmhessf
, 0x01, 0x10, 0x00000000, PPC_SPE
);
7436 GEN_SPE(speundef
, evmhossf
, 0x03, 0x10, 0x00000000, PPC_SPE
);
7437 GEN_SPE(evmheumi
, evmhesmi
, 0x04, 0x10, 0x00000000, PPC_SPE
);
7438 GEN_SPE(speundef
, evmhesmf
, 0x05, 0x10, 0x00000000, PPC_SPE
);
7439 GEN_SPE(evmhoumi
, evmhosmi
, 0x06, 0x10, 0x00000000, PPC_SPE
);
7440 GEN_SPE(speundef
, evmhosmf
, 0x07, 0x10, 0x00000000, PPC_SPE
);
7441 GEN_SPE(speundef
, evmhessfa
, 0x11, 0x10, 0x00000000, PPC_SPE
);
7442 GEN_SPE(speundef
, evmhossfa
, 0x13, 0x10, 0x00000000, PPC_SPE
);
7443 GEN_SPE(evmheumia
, evmhesmia
, 0x14, 0x10, 0x00000000, PPC_SPE
);
7444 GEN_SPE(speundef
, evmhesmfa
, 0x15, 0x10, 0x00000000, PPC_SPE
);
7445 GEN_SPE(evmhoumia
, evmhosmia
, 0x16, 0x10, 0x00000000, PPC_SPE
);
7446 GEN_SPE(speundef
, evmhosmfa
, 0x17, 0x10, 0x00000000, PPC_SPE
);
7448 GEN_SPE(speundef
, evmwhssf
, 0x03, 0x11, 0x00000000, PPC_SPE
);
7449 GEN_SPE(evmwlumi
, speundef
, 0x04, 0x11, 0x00000000, PPC_SPE
);
7450 GEN_SPE(evmwhumi
, evmwhsmi
, 0x06, 0x11, 0x00000000, PPC_SPE
);
7451 GEN_SPE(speundef
, evmwhsmf
, 0x07, 0x11, 0x00000000, PPC_SPE
);
7452 GEN_SPE(speundef
, evmwssf
, 0x09, 0x11, 0x00000000, PPC_SPE
);
7453 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, PPC_SPE
);
7454 GEN_SPE(speundef
, evmwsmf
, 0x0D, 0x11, 0x00000000, PPC_SPE
);
7455 GEN_SPE(speundef
, evmwhssfa
, 0x13, 0x11, 0x00000000, PPC_SPE
);
7456 GEN_SPE(evmwlumia
, speundef
, 0x14, 0x11, 0x00000000, PPC_SPE
);
7457 GEN_SPE(evmwhumia
, evmwhsmia
, 0x16, 0x11, 0x00000000, PPC_SPE
);
7458 GEN_SPE(speundef
, evmwhsmfa
, 0x17, 0x11, 0x00000000, PPC_SPE
);
7459 GEN_SPE(speundef
, evmwssfa
, 0x19, 0x11, 0x00000000, PPC_SPE
);
7460 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, PPC_SPE
);
7461 GEN_SPE(speundef
, evmwsmfa
, 0x1D, 0x11, 0x00000000, PPC_SPE
);
7463 GEN_SPE(evadduiaaw
, evaddsiaaw
, 0x00, 0x13, 0x0000F800, PPC_SPE
);
7464 GEN_SPE(evsubfusiaaw
, evsubfssiaaw
, 0x01, 0x13, 0x0000F800, PPC_SPE
);
7465 GEN_SPE(evaddumiaaw
, evaddsmiaaw
, 0x04, 0x13, 0x0000F800, PPC_SPE
);
7466 GEN_SPE(evsubfumiaaw
, evsubfsmiaaw
, 0x05, 0x13, 0x0000F800, PPC_SPE
);
7467 GEN_SPE(evdivws
, evdivwu
, 0x06, 0x13, 0x00000000, PPC_SPE
);
7468 GEN_SPE(evmra
, speundef
, 0x07, 0x13, 0x0000F800, PPC_SPE
);
7470 GEN_SPE(evmheusiaaw
, evmhessiaaw
, 0x00, 0x14, 0x00000000, PPC_SPE
);
7471 GEN_SPE(speundef
, evmhessfaaw
, 0x01, 0x14, 0x00000000, PPC_SPE
);
7472 GEN_SPE(evmhousiaaw
, evmhossiaaw
, 0x02, 0x14, 0x00000000, PPC_SPE
);
7473 GEN_SPE(speundef
, evmhossfaaw
, 0x03, 0x14, 0x00000000, PPC_SPE
);
7474 GEN_SPE(evmheumiaaw
, evmhesmiaaw
, 0x04, 0x14, 0x00000000, PPC_SPE
);
7475 GEN_SPE(speundef
, evmhesmfaaw
, 0x05, 0x14, 0x00000000, PPC_SPE
);
7476 GEN_SPE(evmhoumiaaw
, evmhosmiaaw
, 0x06, 0x14, 0x00000000, PPC_SPE
);
7477 GEN_SPE(speundef
, evmhosmfaaw
, 0x07, 0x14, 0x00000000, PPC_SPE
);
7478 GEN_SPE(evmhegumiaa
, evmhegsmiaa
, 0x14, 0x14, 0x00000000, PPC_SPE
);
7479 GEN_SPE(speundef
, evmhegsmfaa
, 0x15, 0x14, 0x00000000, PPC_SPE
);
7480 GEN_SPE(evmhogumiaa
, evmhogsmiaa
, 0x16, 0x14, 0x00000000, PPC_SPE
);
7481 GEN_SPE(speundef
, evmhogsmfaa
, 0x17, 0x14, 0x00000000, PPC_SPE
);
7483 GEN_SPE(evmwlusiaaw
, evmwlssiaaw
, 0x00, 0x15, 0x00000000, PPC_SPE
);
7484 GEN_SPE(evmwlumiaaw
, evmwlsmiaaw
, 0x04, 0x15, 0x00000000, PPC_SPE
);
7485 GEN_SPE(speundef
, evmwssfaa
, 0x09, 0x15, 0x00000000, PPC_SPE
);
7486 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, PPC_SPE
);
7487 GEN_SPE(speundef
, evmwsmfaa
, 0x0D, 0x15, 0x00000000, PPC_SPE
);
7489 GEN_SPE(evmheusianw
, evmhessianw
, 0x00, 0x16, 0x00000000, PPC_SPE
);
7490 GEN_SPE(speundef
, evmhessfanw
, 0x01, 0x16, 0x00000000, PPC_SPE
);
7491 GEN_SPE(evmhousianw
, evmhossianw
, 0x02, 0x16, 0x00000000, PPC_SPE
);
7492 GEN_SPE(speundef
, evmhossfanw
, 0x03, 0x16, 0x00000000, PPC_SPE
);
7493 GEN_SPE(evmheumianw
, evmhesmianw
, 0x04, 0x16, 0x00000000, PPC_SPE
);
7494 GEN_SPE(speundef
, evmhesmfanw
, 0x05, 0x16, 0x00000000, PPC_SPE
);
7495 GEN_SPE(evmhoumianw
, evmhosmianw
, 0x06, 0x16, 0x00000000, PPC_SPE
);
7496 GEN_SPE(speundef
, evmhosmfanw
, 0x07, 0x16, 0x00000000, PPC_SPE
);
7497 GEN_SPE(evmhegumian
, evmhegsmian
, 0x14, 0x16, 0x00000000, PPC_SPE
);
7498 GEN_SPE(speundef
, evmhegsmfan
, 0x15, 0x16, 0x00000000, PPC_SPE
);
7499 GEN_SPE(evmhigumian
, evmhigsmian
, 0x16, 0x16, 0x00000000, PPC_SPE
);
7500 GEN_SPE(speundef
, evmhogsmfan
, 0x17, 0x16, 0x00000000, PPC_SPE
);
7502 GEN_SPE(evmwlusianw
, evmwlssianw
, 0x00, 0x17, 0x00000000, PPC_SPE
);
7503 GEN_SPE(evmwlumianw
, evmwlsmianw
, 0x04, 0x17, 0x00000000, PPC_SPE
);
7504 GEN_SPE(speundef
, evmwssfan
, 0x09, 0x17, 0x00000000, PPC_SPE
);
7505 GEN_SPE(evmwumian
, evmwsmian
, 0x0C, 0x17, 0x00000000, PPC_SPE
);
7506 GEN_SPE(speundef
, evmwsmfan
, 0x0D, 0x17, 0x00000000, PPC_SPE
);
7509 /*** SPE floating-point extension ***/
7510 #if defined(TARGET_PPC64)
7511 #define GEN_SPEFPUOP_CONV_32_32(name) \
7512 static always_inline void gen_##name (DisasContext *ctx) \
7516 t0 = tcg_temp_new_i32(); \
7517 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
7518 gen_helper_##name(t0, t0); \
7519 t1 = tcg_temp_new(); \
7520 tcg_gen_extu_i32_tl(t1, t0); \
7521 tcg_temp_free_i32(t0); \
7522 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
7523 0xFFFFFFFF00000000ULL); \
7524 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
7525 tcg_temp_free(t1); \
7527 #define GEN_SPEFPUOP_CONV_32_64(name) \
7528 static always_inline void gen_##name (DisasContext *ctx) \
7532 t0 = tcg_temp_new_i32(); \
7533 gen_helper_##name(t0, cpu_gpr[rB(ctx->opcode)]); \
7534 t1 = tcg_temp_new(); \
7535 tcg_gen_extu_i32_tl(t1, t0); \
7536 tcg_temp_free_i32(t0); \
7537 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
7538 0xFFFFFFFF00000000ULL); \
7539 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
7540 tcg_temp_free(t1); \
7542 #define GEN_SPEFPUOP_CONV_64_32(name) \
7543 static always_inline void gen_##name (DisasContext *ctx) \
7545 TCGv_i32 t0 = tcg_temp_new_i32(); \
7546 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
7547 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], t0); \
7548 tcg_temp_free_i32(t0); \
7550 #define GEN_SPEFPUOP_CONV_64_64(name) \
7551 static always_inline void gen_##name (DisasContext *ctx) \
7553 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
7555 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
7556 static always_inline void gen_##name (DisasContext *ctx) \
7560 if (unlikely(!ctx->spe_enabled)) { \
7561 gen_exception(ctx, POWERPC_EXCP_APU); \
7564 t0 = tcg_temp_new_i32(); \
7565 t1 = tcg_temp_new_i32(); \
7566 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7567 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
7568 gen_helper_##name(t0, t0, t1); \
7569 tcg_temp_free_i32(t1); \
7570 t2 = tcg_temp_new(); \
7571 tcg_gen_extu_i32_tl(t2, t0); \
7572 tcg_temp_free_i32(t0); \
7573 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
7574 0xFFFFFFFF00000000ULL); \
7575 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \
7576 tcg_temp_free(t2); \
7578 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
7579 static always_inline void gen_##name (DisasContext *ctx) \
7581 if (unlikely(!ctx->spe_enabled)) { \
7582 gen_exception(ctx, POWERPC_EXCP_APU); \
7585 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7586 cpu_gpr[rB(ctx->opcode)]); \
7588 #define GEN_SPEFPUOP_COMP_32(name) \
7589 static always_inline void gen_##name (DisasContext *ctx) \
7592 if (unlikely(!ctx->spe_enabled)) { \
7593 gen_exception(ctx, POWERPC_EXCP_APU); \
7596 t0 = tcg_temp_new_i32(); \
7597 t1 = tcg_temp_new_i32(); \
7598 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7599 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
7600 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], t0, t1); \
7601 tcg_temp_free_i32(t0); \
7602 tcg_temp_free_i32(t1); \
7604 #define GEN_SPEFPUOP_COMP_64(name) \
7605 static always_inline void gen_##name (DisasContext *ctx) \
7607 if (unlikely(!ctx->spe_enabled)) { \
7608 gen_exception(ctx, POWERPC_EXCP_APU); \
7611 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
7612 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
7615 #define GEN_SPEFPUOP_CONV_32_32(name) \
7616 static always_inline void gen_##name (DisasContext *ctx) \
7618 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
7620 #define GEN_SPEFPUOP_CONV_32_64(name) \
7621 static always_inline void gen_##name (DisasContext *ctx) \
7623 TCGv_i64 t0 = tcg_temp_new_i64(); \
7624 gen_load_gpr64(t0, rB(ctx->opcode)); \
7625 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], t0); \
7626 tcg_temp_free_i64(t0); \
7628 #define GEN_SPEFPUOP_CONV_64_32(name) \
7629 static always_inline void gen_##name (DisasContext *ctx) \
7631 TCGv_i64 t0 = tcg_temp_new_i64(); \
7632 gen_helper_##name(t0, cpu_gpr[rB(ctx->opcode)]); \
7633 gen_store_gpr64(rD(ctx->opcode), t0); \
7634 tcg_temp_free_i64(t0); \
7636 #define GEN_SPEFPUOP_CONV_64_64(name) \
7637 static always_inline void gen_##name (DisasContext *ctx) \
7639 TCGv_i64 t0 = tcg_temp_new_i64(); \
7640 gen_load_gpr64(t0, rB(ctx->opcode)); \
7641 gen_helper_##name(t0, t0); \
7642 gen_store_gpr64(rD(ctx->opcode), t0); \
7643 tcg_temp_free_i64(t0); \
7645 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
7646 static always_inline void gen_##name (DisasContext *ctx) \
7648 if (unlikely(!ctx->spe_enabled)) { \
7649 gen_exception(ctx, POWERPC_EXCP_APU); \
7652 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], \
7653 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
7655 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
7656 static always_inline void gen_##name (DisasContext *ctx) \
7659 if (unlikely(!ctx->spe_enabled)) { \
7660 gen_exception(ctx, POWERPC_EXCP_APU); \
7663 t0 = tcg_temp_new_i64(); \
7664 t1 = tcg_temp_new_i64(); \
7665 gen_load_gpr64(t0, rA(ctx->opcode)); \
7666 gen_load_gpr64(t1, rB(ctx->opcode)); \
7667 gen_helper_##name(t0, t0, t1); \
7668 gen_store_gpr64(rD(ctx->opcode), t0); \
7669 tcg_temp_free_i64(t0); \
7670 tcg_temp_free_i64(t1); \
7672 #define GEN_SPEFPUOP_COMP_32(name) \
7673 static always_inline void gen_##name (DisasContext *ctx) \
7675 if (unlikely(!ctx->spe_enabled)) { \
7676 gen_exception(ctx, POWERPC_EXCP_APU); \
7679 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
7680 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
7682 #define GEN_SPEFPUOP_COMP_64(name) \
7683 static always_inline void gen_##name (DisasContext *ctx) \
7686 if (unlikely(!ctx->spe_enabled)) { \
7687 gen_exception(ctx, POWERPC_EXCP_APU); \
7690 t0 = tcg_temp_new_i64(); \
7691 t1 = tcg_temp_new_i64(); \
7692 gen_load_gpr64(t0, rA(ctx->opcode)); \
7693 gen_load_gpr64(t1, rB(ctx->opcode)); \
7694 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], t0, t1); \
7695 tcg_temp_free_i64(t0); \
7696 tcg_temp_free_i64(t1); \
7700 /* Single precision floating-point vectors operations */
7702 GEN_SPEFPUOP_ARITH2_64_64(evfsadd
);
7703 GEN_SPEFPUOP_ARITH2_64_64(evfssub
);
7704 GEN_SPEFPUOP_ARITH2_64_64(evfsmul
);
7705 GEN_SPEFPUOP_ARITH2_64_64(evfsdiv
);
7706 static always_inline
void gen_evfsabs (DisasContext
*ctx
)
7708 if (unlikely(!ctx
->spe_enabled
)) {
7709 gen_exception(ctx
, POWERPC_EXCP_APU
);
7712 #if defined(TARGET_PPC64)
7713 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000080000000LL
);
7715 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x80000000);
7716 tcg_gen_andi_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
7719 static always_inline
void gen_evfsnabs (DisasContext
*ctx
)
7721 if (unlikely(!ctx
->spe_enabled
)) {
7722 gen_exception(ctx
, POWERPC_EXCP_APU
);
7725 #if defined(TARGET_PPC64)
7726 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
7728 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
7729 tcg_gen_ori_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
7732 static always_inline
void gen_evfsneg (DisasContext
*ctx
)
7734 if (unlikely(!ctx
->spe_enabled
)) {
7735 gen_exception(ctx
, POWERPC_EXCP_APU
);
7738 #if defined(TARGET_PPC64)
7739 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
7741 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
7742 tcg_gen_xori_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
7747 GEN_SPEFPUOP_CONV_64_64(evfscfui
);
7748 GEN_SPEFPUOP_CONV_64_64(evfscfsi
);
7749 GEN_SPEFPUOP_CONV_64_64(evfscfuf
);
7750 GEN_SPEFPUOP_CONV_64_64(evfscfsf
);
7751 GEN_SPEFPUOP_CONV_64_64(evfsctui
);
7752 GEN_SPEFPUOP_CONV_64_64(evfsctsi
);
7753 GEN_SPEFPUOP_CONV_64_64(evfsctuf
);
7754 GEN_SPEFPUOP_CONV_64_64(evfsctsf
);
7755 GEN_SPEFPUOP_CONV_64_64(evfsctuiz
);
7756 GEN_SPEFPUOP_CONV_64_64(evfsctsiz
);
7759 GEN_SPEFPUOP_COMP_64(evfscmpgt
);
7760 GEN_SPEFPUOP_COMP_64(evfscmplt
);
7761 GEN_SPEFPUOP_COMP_64(evfscmpeq
);
7762 GEN_SPEFPUOP_COMP_64(evfststgt
);
7763 GEN_SPEFPUOP_COMP_64(evfststlt
);
7764 GEN_SPEFPUOP_COMP_64(evfststeq
);
7766 /* Opcodes definitions */
7767 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, PPC_SPE_SINGLE
); //
7768 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, PPC_SPE_SINGLE
); //
7769 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, PPC_SPE_SINGLE
); //
7770 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, PPC_SPE_SINGLE
); //
7771 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, PPC_SPE_SINGLE
); //
7772 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, PPC_SPE_SINGLE
); //
7773 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, PPC_SPE_SINGLE
); //
7774 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, PPC_SPE_SINGLE
); //
7775 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, PPC_SPE_SINGLE
); //
7776 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, PPC_SPE_SINGLE
); //
7777 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, PPC_SPE_SINGLE
); //
7778 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, PPC_SPE_SINGLE
); //
7779 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, PPC_SPE_SINGLE
); //
7780 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, PPC_SPE_SINGLE
); //
7782 /* Single precision floating-point operations */
7784 GEN_SPEFPUOP_ARITH2_32_32(efsadd
);
7785 GEN_SPEFPUOP_ARITH2_32_32(efssub
);
7786 GEN_SPEFPUOP_ARITH2_32_32(efsmul
);
7787 GEN_SPEFPUOP_ARITH2_32_32(efsdiv
);
7788 static always_inline
void gen_efsabs (DisasContext
*ctx
)
7790 if (unlikely(!ctx
->spe_enabled
)) {
7791 gen_exception(ctx
, POWERPC_EXCP_APU
);
7794 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], (target_long
)~0x80000000LL
);
7796 static always_inline
void gen_efsnabs (DisasContext
*ctx
)
7798 if (unlikely(!ctx
->spe_enabled
)) {
7799 gen_exception(ctx
, POWERPC_EXCP_APU
);
7802 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
7804 static always_inline
void gen_efsneg (DisasContext
*ctx
)
7806 if (unlikely(!ctx
->spe_enabled
)) {
7807 gen_exception(ctx
, POWERPC_EXCP_APU
);
7810 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
7814 GEN_SPEFPUOP_CONV_32_32(efscfui
);
7815 GEN_SPEFPUOP_CONV_32_32(efscfsi
);
7816 GEN_SPEFPUOP_CONV_32_32(efscfuf
);
7817 GEN_SPEFPUOP_CONV_32_32(efscfsf
);
7818 GEN_SPEFPUOP_CONV_32_32(efsctui
);
7819 GEN_SPEFPUOP_CONV_32_32(efsctsi
);
7820 GEN_SPEFPUOP_CONV_32_32(efsctuf
);
7821 GEN_SPEFPUOP_CONV_32_32(efsctsf
);
7822 GEN_SPEFPUOP_CONV_32_32(efsctuiz
);
7823 GEN_SPEFPUOP_CONV_32_32(efsctsiz
);
7824 GEN_SPEFPUOP_CONV_32_64(efscfd
);
7827 GEN_SPEFPUOP_COMP_32(efscmpgt
);
7828 GEN_SPEFPUOP_COMP_32(efscmplt
);
7829 GEN_SPEFPUOP_COMP_32(efscmpeq
);
7830 GEN_SPEFPUOP_COMP_32(efststgt
);
7831 GEN_SPEFPUOP_COMP_32(efststlt
);
7832 GEN_SPEFPUOP_COMP_32(efststeq
);
7834 /* Opcodes definitions */
7835 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, PPC_SPE_SINGLE
); //
7836 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, PPC_SPE_SINGLE
); //
7837 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, PPC_SPE_SINGLE
); //
7838 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, PPC_SPE_SINGLE
); //
7839 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, PPC_SPE_SINGLE
); //
7840 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, PPC_SPE_SINGLE
); //
7841 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, PPC_SPE_SINGLE
); //
7842 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, PPC_SPE_SINGLE
); //
7843 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, PPC_SPE_SINGLE
); //
7844 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, PPC_SPE_SINGLE
); //
7845 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, PPC_SPE_SINGLE
); //
7846 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, PPC_SPE_SINGLE
); //
7847 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, PPC_SPE_SINGLE
); //
7848 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, PPC_SPE_SINGLE
); //
7850 /* Double precision floating-point operations */
7852 GEN_SPEFPUOP_ARITH2_64_64(efdadd
);
7853 GEN_SPEFPUOP_ARITH2_64_64(efdsub
);
7854 GEN_SPEFPUOP_ARITH2_64_64(efdmul
);
7855 GEN_SPEFPUOP_ARITH2_64_64(efddiv
);
7856 static always_inline
void gen_efdabs (DisasContext
*ctx
)
7858 if (unlikely(!ctx
->spe_enabled
)) {
7859 gen_exception(ctx
, POWERPC_EXCP_APU
);
7862 #if defined(TARGET_PPC64)
7863 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000000000000LL
);
7865 tcg_gen_andi_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
7868 static always_inline
void gen_efdnabs (DisasContext
*ctx
)
7870 if (unlikely(!ctx
->spe_enabled
)) {
7871 gen_exception(ctx
, POWERPC_EXCP_APU
);
7874 #if defined(TARGET_PPC64)
7875 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
7877 tcg_gen_ori_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
7880 static always_inline
void gen_efdneg (DisasContext
*ctx
)
7882 if (unlikely(!ctx
->spe_enabled
)) {
7883 gen_exception(ctx
, POWERPC_EXCP_APU
);
7886 #if defined(TARGET_PPC64)
7887 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
7889 tcg_gen_xori_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
7894 GEN_SPEFPUOP_CONV_64_32(efdcfui
);
7895 GEN_SPEFPUOP_CONV_64_32(efdcfsi
);
7896 GEN_SPEFPUOP_CONV_64_32(efdcfuf
);
7897 GEN_SPEFPUOP_CONV_64_32(efdcfsf
);
7898 GEN_SPEFPUOP_CONV_32_64(efdctui
);
7899 GEN_SPEFPUOP_CONV_32_64(efdctsi
);
7900 GEN_SPEFPUOP_CONV_32_64(efdctuf
);
7901 GEN_SPEFPUOP_CONV_32_64(efdctsf
);
7902 GEN_SPEFPUOP_CONV_32_64(efdctuiz
);
7903 GEN_SPEFPUOP_CONV_32_64(efdctsiz
);
7904 GEN_SPEFPUOP_CONV_64_32(efdcfs
);
7905 GEN_SPEFPUOP_CONV_64_64(efdcfuid
);
7906 GEN_SPEFPUOP_CONV_64_64(efdcfsid
);
7907 GEN_SPEFPUOP_CONV_64_64(efdctuidz
);
7908 GEN_SPEFPUOP_CONV_64_64(efdctsidz
);
7911 GEN_SPEFPUOP_COMP_64(efdcmpgt
);
7912 GEN_SPEFPUOP_COMP_64(efdcmplt
);
7913 GEN_SPEFPUOP_COMP_64(efdcmpeq
);
7914 GEN_SPEFPUOP_COMP_64(efdtstgt
);
7915 GEN_SPEFPUOP_COMP_64(efdtstlt
);
7916 GEN_SPEFPUOP_COMP_64(efdtsteq
);
7918 /* Opcodes definitions */
7919 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, PPC_SPE_DOUBLE
); //
7920 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, PPC_SPE_DOUBLE
); //
7921 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, PPC_SPE_DOUBLE
); //
7922 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, PPC_SPE_DOUBLE
); //
7923 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, PPC_SPE_DOUBLE
); //
7924 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, PPC_SPE_DOUBLE
); //
7925 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, PPC_SPE_DOUBLE
); //
7926 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, PPC_SPE_DOUBLE
); //
7927 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, PPC_SPE_DOUBLE
); //
7928 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, PPC_SPE_DOUBLE
); //
7929 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, PPC_SPE_DOUBLE
); //
7930 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, PPC_SPE_DOUBLE
); //
7931 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, PPC_SPE_DOUBLE
); //
7932 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, PPC_SPE_DOUBLE
); //
7933 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, PPC_SPE_DOUBLE
); //
7934 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, PPC_SPE_DOUBLE
); //
7936 static opcode_t opcodes
[] = {
7937 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
),
7938 GEN_HANDLER(cmp
, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER
),
7939 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
7940 GEN_HANDLER(cmpl
, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER
),
7941 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
7942 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
),
7943 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7944 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7945 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7946 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7947 GEN_HANDLER(mulhw
, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER
),
7948 GEN_HANDLER(mulhwu
, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER
),
7949 GEN_HANDLER(mullw
, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER
),
7950 GEN_HANDLER(mullwo
, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER
),
7951 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7952 #if defined(TARGET_PPC64)
7953 GEN_HANDLER(mulld
, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B
),
7955 GEN_HANDLER(neg
, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER
),
7956 GEN_HANDLER(nego
, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER
),
7957 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7958 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7959 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7960 GEN_HANDLER(cntlzw
, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER
),
7961 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
),
7962 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
),
7963 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7964 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7965 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7966 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7967 GEN_HANDLER(popcntb
, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB
),
7968 #if defined(TARGET_PPC64)
7969 GEN_HANDLER(cntlzd
, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B
),
7971 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7972 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7973 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7974 GEN_HANDLER(slw
, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER
),
7975 GEN_HANDLER(sraw
, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER
),
7976 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
),
7977 GEN_HANDLER(srw
, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER
),
7978 #if defined(TARGET_PPC64)
7979 GEN_HANDLER(sld
, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B
),
7980 GEN_HANDLER(srad
, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B
),
7981 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
),
7982 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
),
7983 GEN_HANDLER(srd
, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B
),
7985 GEN_HANDLER(frsqrtes
, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES
),
7986 GEN_HANDLER(fsqrt
, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
7987 GEN_HANDLER(fsqrts
, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
),
7988 GEN_HANDLER(fcmpo
, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT
),
7989 GEN_HANDLER(fcmpu
, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT
),
7990 GEN_HANDLER(fmr
, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT
),
7991 GEN_HANDLER(mcrfs
, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT
),
7992 GEN_HANDLER(mffs
, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT
),
7993 GEN_HANDLER(mtfsb0
, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT
),
7994 GEN_HANDLER(mtfsb1
, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT
),
7995 GEN_HANDLER(mtfsf
, 0x3F, 0x07, 0x16, 0x00010000, PPC_FLOAT
),
7996 GEN_HANDLER(mtfsfi
, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT
),
7997 #if defined(TARGET_PPC64)
7998 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
),
7999 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
),
8000 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
),
8002 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8003 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
8004 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
),
8005 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
),
8006 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
),
8007 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
),
8008 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO
),
8009 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
),
8010 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000001, PPC_RES
),
8011 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
),
8012 #if defined(TARGET_PPC64)
8013 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000001, PPC_64B
),
8014 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
),
8016 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
),
8017 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
),
8018 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
8019 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
8020 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
),
8021 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
),
8022 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
),
8023 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
),
8024 #if defined(TARGET_PPC64)
8025 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
),
8026 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
),
8028 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW
),
8029 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
),
8030 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
8031 #if defined(TARGET_PPC64)
8032 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
),
8033 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
),
8035 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
),
8036 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
),
8037 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
),
8038 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
),
8039 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
),
8040 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
),
8041 #if defined(TARGET_PPC64)
8042 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
),
8044 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC
),
8045 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC
),
8046 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
),
8047 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
),
8048 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
),
8049 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE
),
8050 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE
),
8051 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE_DCBZ
),
8052 GEN_HANDLER2(dcbz_970
, "dcbz", 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZT
),
8053 GEN_HANDLER(dst
, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC
),
8054 GEN_HANDLER(dstst
, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC
),
8055 GEN_HANDLER(dss
, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC
),
8056 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
),
8057 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
),
8058 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
),
8059 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
),
8060 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
),
8061 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
),
8062 #if defined(TARGET_PPC64)
8063 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
),
8064 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
8066 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
),
8067 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
8069 GEN_HANDLER2(slbmte
, "slbmte", 0x1F, 0x12, 0x0C, 0x00000000, PPC_SEGMENT_64B
),
8071 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
),
8072 GEN_HANDLER(tlbiel
, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE
),
8073 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE
),
8074 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
),
8075 #if defined(TARGET_PPC64)
8076 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI
),
8077 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
),
8079 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
),
8080 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
),
8081 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
),
8082 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
),
8083 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
),
8084 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
),
8085 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
),
8086 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
),
8087 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
),
8088 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
),
8089 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
),
8090 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
8091 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
),
8092 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
),
8093 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
),
8094 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
),
8095 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
),
8096 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
),
8097 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
),
8098 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
8099 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
),
8100 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
),
8101 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
),
8102 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
),
8103 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
),
8104 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
),
8105 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
),
8106 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
),
8107 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
),
8108 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
),
8109 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
),
8110 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
),
8111 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
),
8112 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
),
8113 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
),
8114 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
),
8115 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
),
8116 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
),
8117 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
),
8118 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
),
8119 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
),
8120 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
),
8121 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
),
8122 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
),
8123 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
),
8124 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
),
8125 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
),
8126 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
),
8127 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
),
8128 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8129 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8130 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
),
8131 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
),
8132 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8133 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8134 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
),
8135 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
),
8136 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
),
8137 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
),
8138 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
),
8139 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
),
8140 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
),
8141 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
),
8142 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
),
8143 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
),
8144 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
),
8145 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
),
8146 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
),
8147 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
),
8148 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
),
8149 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
),
8150 GEN_HANDLER(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
),
8151 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
),
8152 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
),
8153 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
),
8154 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
),
8155 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
),
8156 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
),
8157 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
),
8158 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
),
8159 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
),
8160 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE
),
8161 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
),
8162 GEN_HANDLER(mbar
, 0x1F, 0x16, 0x1a, 0x001FF801, PPC_BOOKE
),
8163 GEN_HANDLER(msync
, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE
),
8164 GEN_HANDLER2(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001, PPC_BOOKE
),
8165 GEN_HANDLER(lvsl
, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC
),
8166 GEN_HANDLER(lvsr
, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC
),
8167 GEN_HANDLER(mfvscr
, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC
),
8168 GEN_HANDLER(mtvscr
, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC
),
8169 GEN_HANDLER(vsldoi
, 0x04, 0x16, 0xFF, 0x00000400, PPC_ALTIVEC
),
8170 GEN_HANDLER(vmladduhm
, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC
),
8171 GEN_HANDLER2(evsel0
, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE
),
8172 GEN_HANDLER2(evsel1
, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE
),
8173 GEN_HANDLER2(evsel2
, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE
),
8174 GEN_HANDLER2(evsel3
, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE
),
8176 #undef GEN_INT_ARITH_ADD
8177 #undef GEN_INT_ARITH_ADD_CONST
8178 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
8179 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
8180 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
8181 add_ca, compute_ca, compute_ov) \
8182 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
8183 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
8184 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
8185 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
8186 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
8187 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
8188 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
8189 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
8190 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
8191 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
8192 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
8194 #undef GEN_INT_ARITH_DIVW
8195 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
8196 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
8197 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0),
8198 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1),
8199 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0),
8200 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1),
8202 #if defined(TARGET_PPC64)
8203 #undef GEN_INT_ARITH_DIVD
8204 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
8205 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8206 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0),
8207 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1),
8208 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0),
8209 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1),
8211 #undef GEN_INT_ARITH_MUL_HELPER
8212 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
8213 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8214 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00),
8215 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02),
8216 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17),
8219 #undef GEN_INT_ARITH_SUBF
8220 #undef GEN_INT_ARITH_SUBF_CONST
8221 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
8222 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
8223 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
8224 add_ca, compute_ca, compute_ov) \
8225 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
8226 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
8227 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
8228 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
8229 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
8230 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
8231 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
8232 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
8233 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
8234 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
8235 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
8239 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
8240 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
8241 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
8242 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
8243 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
),
8244 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
),
8245 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
),
8246 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
),
8247 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
),
8248 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
),
8249 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
),
8250 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
),
8251 #if defined(TARGET_PPC64)
8252 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
),
8255 #if defined(TARGET_PPC64)
8258 #define GEN_PPC64_R2(name, opc1, opc2) \
8259 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8260 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
8262 #define GEN_PPC64_R4(name, opc1, opc2) \
8263 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8264 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
8266 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
8268 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
8270 GEN_PPC64_R4(rldicl
, 0x1E, 0x00),
8271 GEN_PPC64_R4(rldicr
, 0x1E, 0x02),
8272 GEN_PPC64_R4(rldic
, 0x1E, 0x04),
8273 GEN_PPC64_R2(rldcl
, 0x1E, 0x08),
8274 GEN_PPC64_R2(rldcr
, 0x1E, 0x09),
8275 GEN_PPC64_R4(rldimi
, 0x1E, 0x06),
8278 #undef _GEN_FLOAT_ACB
8279 #undef GEN_FLOAT_ACB
8280 #undef _GEN_FLOAT_AB
8282 #undef _GEN_FLOAT_AC
8286 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
8287 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type)
8288 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
8289 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \
8290 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type)
8291 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
8292 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
8293 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
8294 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
8295 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
8296 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
8297 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type)
8298 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
8299 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \
8300 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type)
8301 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
8302 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type)
8303 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
8304 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type)
8306 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
),
8307 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
),
8308 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
),
8309 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
),
8310 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
),
8311 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
),
8312 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
),
8313 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
),
8314 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
),
8315 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
),
8316 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
),
8317 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
),
8318 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
),
8319 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
),
8320 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
),
8321 #if defined(TARGET_PPC64)
8322 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
),
8323 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
),
8324 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
),
8326 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
),
8327 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
),
8328 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
),
8329 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
),
8330 GEN_FLOAT_B(abs
, 0x08, 0x08, 0, PPC_FLOAT
),
8331 GEN_FLOAT_B(nabs
, 0x08, 0x04, 0, PPC_FLOAT
),
8332 GEN_FLOAT_B(neg
, 0x08, 0x01, 0, PPC_FLOAT
),
8339 #define GEN_LD(name, ldop, opc, type) \
8340 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8341 #define GEN_LDU(name, ldop, opc, type) \
8342 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
8343 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
8344 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
8345 #define GEN_LDX(name, ldop, opc2, opc3, type) \
8346 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
8347 #define GEN_LDS(name, ldop, op, type) \
8348 GEN_LD(name, ldop, op | 0x20, type) \
8349 GEN_LDU(name, ldop, op | 0x21, type) \
8350 GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
8351 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
8353 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
)
8354 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
)
8355 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
)
8356 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
)
8357 #if defined(TARGET_PPC64)
8358 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
)
8359 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
)
8360 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
)
8361 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
)
8363 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
)
8364 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
)
8371 #define GEN_ST(name, stop, opc, type) \
8372 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8373 #define GEN_STU(name, stop, opc, type) \
8374 GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
8375 #define GEN_STUX(name, stop, opc2, opc3, type) \
8376 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
8377 #define GEN_STX(name, stop, opc2, opc3, type) \
8378 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
8379 #define GEN_STS(name, stop, op, type) \
8380 GEN_ST(name, stop, op | 0x20, type) \
8381 GEN_STU(name, stop, op | 0x21, type) \
8382 GEN_STUX(name, stop, 0x17, op | 0x01, type) \
8383 GEN_STX(name, stop, 0x17, op | 0x00, type)
8385 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
)
8386 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
)
8387 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
)
8388 #if defined(TARGET_PPC64)
8389 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
)
8390 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
)
8392 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
)
8393 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
)
8400 #define GEN_LDF(name, ldop, opc, type) \
8401 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8402 #define GEN_LDUF(name, ldop, opc, type) \
8403 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
8404 #define GEN_LDUXF(name, ldop, opc, type) \
8405 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
8406 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
8407 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
8408 #define GEN_LDFS(name, ldop, op, type) \
8409 GEN_LDF(name, ldop, op | 0x20, type) \
8410 GEN_LDUF(name, ldop, op | 0x21, type) \
8411 GEN_LDUXF(name, ldop, op | 0x01, type) \
8412 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
8414 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
)
8415 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
)
8422 #define GEN_STF(name, stop, opc, type) \
8423 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8424 #define GEN_STUF(name, stop, opc, type) \
8425 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
8426 #define GEN_STUXF(name, stop, opc, type) \
8427 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type),
8428 #define GEN_STXF(name, stop, opc2, opc3, type) \
8429 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type),
8430 #define GEN_STFS(name, stop, op, type) \
8431 GEN_STF(name, stop, op | 0x20, type) \
8432 GEN_STUF(name, stop, op | 0x21, type) \
8433 GEN_STUXF(name, stop, op | 0x01, type) \
8434 GEN_STXF(name, stop, 0x17, op | 0x00, type)
8436 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
)
8437 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
)
8438 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
)
8441 #define GEN_CRLOGIC(name, tcg_op, opc) \
8442 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
8443 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08),
8444 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04),
8445 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09),
8446 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07),
8447 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01),
8448 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E),
8449 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D),
8450 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06),
8452 #undef GEN_MAC_HANDLER
8453 #define GEN_MAC_HANDLER(name, opc2, opc3) \
8454 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
8455 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05),
8456 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15),
8457 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07),
8458 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17),
8459 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06),
8460 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16),
8461 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04),
8462 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14),
8463 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01),
8464 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11),
8465 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03),
8466 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13),
8467 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02),
8468 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12),
8469 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00),
8470 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10),
8471 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D),
8472 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D),
8473 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F),
8474 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F),
8475 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C),
8476 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C),
8477 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E),
8478 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E),
8479 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05),
8480 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15),
8481 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07),
8482 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17),
8483 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01),
8484 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11),
8485 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03),
8486 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13),
8487 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D),
8488 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D),
8489 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F),
8490 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F),
8491 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05),
8492 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04),
8493 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01),
8494 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00),
8495 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D),
8496 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C),
8502 #define GEN_VR_LDX(name, opc2, opc3) \
8503 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
8504 #define GEN_VR_STX(name, opc2, opc3) \
8505 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
8506 #define GEN_VR_LVE(name, opc2, opc3) \
8507 GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
8508 #define GEN_VR_STVE(name, opc2, opc3) \
8509 GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC)
8510 GEN_VR_LDX(lvx
, 0x07, 0x03),
8511 GEN_VR_LDX(lvxl
, 0x07, 0x0B),
8512 GEN_VR_LVE(bx
, 0x07, 0x00),
8513 GEN_VR_LVE(hx
, 0x07, 0x01),
8514 GEN_VR_LVE(wx
, 0x07, 0x02),
8515 GEN_VR_STX(svx
, 0x07, 0x07),
8516 GEN_VR_STX(svxl
, 0x07, 0x0F),
8517 GEN_VR_STVE(bx
, 0x07, 0x04),
8518 GEN_VR_STVE(hx
, 0x07, 0x05),
8519 GEN_VR_STVE(wx
, 0x07, 0x06),
8521 #undef GEN_VX_LOGICAL
8522 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
8523 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
8524 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16),
8525 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17),
8526 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18),
8527 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19),
8528 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20),
8531 #define GEN_VXFORM(name, opc2, opc3) \
8532 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
8533 GEN_VXFORM(vaddubm
, 0, 0),
8534 GEN_VXFORM(vadduhm
, 0, 1),
8535 GEN_VXFORM(vadduwm
, 0, 2),
8536 GEN_VXFORM(vsububm
, 0, 16),
8537 GEN_VXFORM(vsubuhm
, 0, 17),
8538 GEN_VXFORM(vsubuwm
, 0, 18),
8539 GEN_VXFORM(vmaxub
, 1, 0),
8540 GEN_VXFORM(vmaxuh
, 1, 1),
8541 GEN_VXFORM(vmaxuw
, 1, 2),
8542 GEN_VXFORM(vmaxsb
, 1, 4),
8543 GEN_VXFORM(vmaxsh
, 1, 5),
8544 GEN_VXFORM(vmaxsw
, 1, 6),
8545 GEN_VXFORM(vminub
, 1, 8),
8546 GEN_VXFORM(vminuh
, 1, 9),
8547 GEN_VXFORM(vminuw
, 1, 10),
8548 GEN_VXFORM(vminsb
, 1, 12),
8549 GEN_VXFORM(vminsh
, 1, 13),
8550 GEN_VXFORM(vminsw
, 1, 14),
8551 GEN_VXFORM(vavgub
, 1, 16),
8552 GEN_VXFORM(vavguh
, 1, 17),
8553 GEN_VXFORM(vavguw
, 1, 18),
8554 GEN_VXFORM(vavgsb
, 1, 20),
8555 GEN_VXFORM(vavgsh
, 1, 21),
8556 GEN_VXFORM(vavgsw
, 1, 22),
8557 GEN_VXFORM(vmrghb
, 6, 0),
8558 GEN_VXFORM(vmrghh
, 6, 1),
8559 GEN_VXFORM(vmrghw
, 6, 2),
8560 GEN_VXFORM(vmrglb
, 6, 4),
8561 GEN_VXFORM(vmrglh
, 6, 5),
8562 GEN_VXFORM(vmrglw
, 6, 6),
8563 GEN_VXFORM(vmuloub
, 4, 0),
8564 GEN_VXFORM(vmulouh
, 4, 1),
8565 GEN_VXFORM(vmulosb
, 4, 4),
8566 GEN_VXFORM(vmulosh
, 4, 5),
8567 GEN_VXFORM(vmuleub
, 4, 8),
8568 GEN_VXFORM(vmuleuh
, 4, 9),
8569 GEN_VXFORM(vmulesb
, 4, 12),
8570 GEN_VXFORM(vmulesh
, 4, 13),
8571 GEN_VXFORM(vslb
, 2, 4),
8572 GEN_VXFORM(vslh
, 2, 5),
8573 GEN_VXFORM(vslw
, 2, 6),
8574 GEN_VXFORM(vsrb
, 2, 8),
8575 GEN_VXFORM(vsrh
, 2, 9),
8576 GEN_VXFORM(vsrw
, 2, 10),
8577 GEN_VXFORM(vsrab
, 2, 12),
8578 GEN_VXFORM(vsrah
, 2, 13),
8579 GEN_VXFORM(vsraw
, 2, 14),
8580 GEN_VXFORM(vslo
, 6, 16),
8581 GEN_VXFORM(vsro
, 6, 17),
8582 GEN_VXFORM(vaddcuw
, 0, 6),
8583 GEN_VXFORM(vsubcuw
, 0, 22),
8584 GEN_VXFORM(vaddubs
, 0, 8),
8585 GEN_VXFORM(vadduhs
, 0, 9),
8586 GEN_VXFORM(vadduws
, 0, 10),
8587 GEN_VXFORM(vaddsbs
, 0, 12),
8588 GEN_VXFORM(vaddshs
, 0, 13),
8589 GEN_VXFORM(vaddsws
, 0, 14),
8590 GEN_VXFORM(vsububs
, 0, 24),
8591 GEN_VXFORM(vsubuhs
, 0, 25),
8592 GEN_VXFORM(vsubuws
, 0, 26),
8593 GEN_VXFORM(vsubsbs
, 0, 28),
8594 GEN_VXFORM(vsubshs
, 0, 29),
8595 GEN_VXFORM(vsubsws
, 0, 30),
8596 GEN_VXFORM(vrlb
, 2, 0),
8597 GEN_VXFORM(vrlh
, 2, 1),
8598 GEN_VXFORM(vrlw
, 2, 2),
8599 GEN_VXFORM(vsl
, 2, 7),
8600 GEN_VXFORM(vsr
, 2, 11),
8601 GEN_VXFORM(vpkuhum
, 7, 0),
8602 GEN_VXFORM(vpkuwum
, 7, 1),
8603 GEN_VXFORM(vpkuhus
, 7, 2),
8604 GEN_VXFORM(vpkuwus
, 7, 3),
8605 GEN_VXFORM(vpkshus
, 7, 4),
8606 GEN_VXFORM(vpkswus
, 7, 5),
8607 GEN_VXFORM(vpkshss
, 7, 6),
8608 GEN_VXFORM(vpkswss
, 7, 7),
8609 GEN_VXFORM(vpkpx
, 7, 12),
8610 GEN_VXFORM(vsum4ubs
, 4, 24),
8611 GEN_VXFORM(vsum4sbs
, 4, 28),
8612 GEN_VXFORM(vsum4shs
, 4, 25),
8613 GEN_VXFORM(vsum2sws
, 4, 26),
8614 GEN_VXFORM(vsumsws
, 4, 30),
8615 GEN_VXFORM(vaddfp
, 5, 0),
8616 GEN_VXFORM(vsubfp
, 5, 1),
8617 GEN_VXFORM(vmaxfp
, 5, 16),
8618 GEN_VXFORM(vminfp
, 5, 17),
8622 #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \
8623 GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC),
8624 #define GEN_VXRFORM(name, opc2, opc3) \
8625 GEN_VXRFORM1(name, name, #name, opc2, opc3) \
8626 GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4)))
8627 GEN_VXRFORM(vcmpequb
, 3, 0)
8628 GEN_VXRFORM(vcmpequh
, 3, 1)
8629 GEN_VXRFORM(vcmpequw
, 3, 2)
8630 GEN_VXRFORM(vcmpgtsb
, 3, 12)
8631 GEN_VXRFORM(vcmpgtsh
, 3, 13)
8632 GEN_VXRFORM(vcmpgtsw
, 3, 14)
8633 GEN_VXRFORM(vcmpgtub
, 3, 8)
8634 GEN_VXRFORM(vcmpgtuh
, 3, 9)
8635 GEN_VXRFORM(vcmpgtuw
, 3, 10)
8636 GEN_VXRFORM(vcmpeqfp
, 3, 3)
8637 GEN_VXRFORM(vcmpgefp
, 3, 7)
8638 GEN_VXRFORM(vcmpgtfp
, 3, 11)
8639 GEN_VXRFORM(vcmpbfp
, 3, 15)
8641 #undef GEN_VXFORM_SIMM
8642 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
8643 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
8644 GEN_VXFORM_SIMM(vspltisb
, 6, 12),
8645 GEN_VXFORM_SIMM(vspltish
, 6, 13),
8646 GEN_VXFORM_SIMM(vspltisw
, 6, 14),
8648 #undef GEN_VXFORM_NOA
8649 #define GEN_VXFORM_NOA(name, opc2, opc3) \
8650 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC)
8651 GEN_VXFORM_NOA(vupkhsb
, 7, 8),
8652 GEN_VXFORM_NOA(vupkhsh
, 7, 9),
8653 GEN_VXFORM_NOA(vupklsb
, 7, 10),
8654 GEN_VXFORM_NOA(vupklsh
, 7, 11),
8655 GEN_VXFORM_NOA(vupkhpx
, 7, 13),
8656 GEN_VXFORM_NOA(vupklpx
, 7, 15),
8657 GEN_VXFORM_NOA(vrefp
, 5, 4),
8658 GEN_VXFORM_NOA(vrsqrtefp
, 5, 5),
8659 GEN_VXFORM_NOA(vlogefp
, 5, 7),
8660 GEN_VXFORM_NOA(vrfim
, 5, 8),
8661 GEN_VXFORM_NOA(vrfin
, 5, 9),
8662 GEN_VXFORM_NOA(vrfip
, 5, 10),
8663 GEN_VXFORM_NOA(vrfiz
, 5, 11),
8665 #undef GEN_VXFORM_UIMM
8666 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
8667 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC)
8668 GEN_VXFORM_UIMM(vspltb
, 6, 8),
8669 GEN_VXFORM_UIMM(vsplth
, 6, 9),
8670 GEN_VXFORM_UIMM(vspltw
, 6, 10),
8671 GEN_VXFORM_UIMM(vcfux
, 5, 12),
8672 GEN_VXFORM_UIMM(vcfsx
, 5, 13),
8673 GEN_VXFORM_UIMM(vctuxs
, 5, 14),
8674 GEN_VXFORM_UIMM(vctsxs
, 5, 15),
8676 #undef GEN_VAFORM_PAIRED
8677 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
8678 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC)
8679 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16),
8680 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18),
8681 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19),
8682 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20),
8683 GEN_VAFORM_PAIRED(vsel
, vperm
, 21),
8684 GEN_VAFORM_PAIRED(vmaddfp
, vnmsubfp
, 23),
8687 #define GEN_SPE(name0, name1, opc2, opc3, inval, type) \
8688 GEN_HANDLER(name0##_##name1, 0x04, opc2, opc3, inval, type)
8689 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, PPC_SPE
),
8690 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, PPC_SPE
),
8691 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, PPC_SPE
),
8692 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, PPC_SPE
),
8693 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, PPC_SPE
),
8694 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, PPC_SPE
),
8695 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, PPC_SPE
),
8696 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x00000000, PPC_SPE
),
8697 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0x00000000, PPC_SPE
),
8698 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, PPC_SPE
),
8699 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, PPC_SPE
),
8700 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, PPC_SPE
),
8701 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0x00000000, PPC_SPE
),
8702 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, PPC_SPE
),
8703 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, PPC_SPE
),
8704 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, PPC_SPE
),
8705 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, PPC_SPE
),
8706 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, PPC_SPE
),
8707 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, PPC_SPE
),
8708 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, PPC_SPE
),
8709 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, PPC_SPE
),
8710 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, PPC_SPE
),
8711 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, PPC_SPE
),
8712 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, PPC_SPE
),
8713 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, PPC_SPE
),
8715 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, PPC_SPE_SINGLE
),
8716 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, PPC_SPE_SINGLE
),
8717 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, PPC_SPE_SINGLE
),
8718 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, PPC_SPE_SINGLE
),
8719 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, PPC_SPE_SINGLE
),
8720 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, PPC_SPE_SINGLE
),
8721 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, PPC_SPE_SINGLE
),
8722 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, PPC_SPE_SINGLE
),
8723 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, PPC_SPE_SINGLE
),
8724 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, PPC_SPE_SINGLE
),
8725 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, PPC_SPE_SINGLE
),
8726 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, PPC_SPE_SINGLE
),
8727 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, PPC_SPE_SINGLE
),
8728 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, PPC_SPE_SINGLE
),
8730 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, PPC_SPE_SINGLE
),
8731 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, PPC_SPE_SINGLE
),
8732 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, PPC_SPE_SINGLE
),
8733 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, PPC_SPE_SINGLE
),
8734 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, PPC_SPE_SINGLE
),
8735 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, PPC_SPE_SINGLE
),
8736 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, PPC_SPE_SINGLE
),
8737 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, PPC_SPE_SINGLE
),
8738 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, PPC_SPE_SINGLE
),
8739 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, PPC_SPE_SINGLE
),
8740 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, PPC_SPE_SINGLE
),
8741 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, PPC_SPE_SINGLE
),
8742 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, PPC_SPE_SINGLE
),
8743 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, PPC_SPE_SINGLE
),
8745 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, PPC_SPE_DOUBLE
),
8746 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, PPC_SPE_DOUBLE
),
8747 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, PPC_SPE_DOUBLE
),
8748 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, PPC_SPE_DOUBLE
),
8749 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, PPC_SPE_DOUBLE
),
8750 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, PPC_SPE_DOUBLE
),
8751 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, PPC_SPE_DOUBLE
),
8752 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, PPC_SPE_DOUBLE
),
8753 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, PPC_SPE_DOUBLE
),
8754 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, PPC_SPE_DOUBLE
),
8755 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, PPC_SPE_DOUBLE
),
8756 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, PPC_SPE_DOUBLE
),
8757 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, PPC_SPE_DOUBLE
),
8758 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, PPC_SPE_DOUBLE
),
8759 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, PPC_SPE_DOUBLE
),
8760 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, PPC_SPE_DOUBLE
),
8762 #undef GEN_SPEOP_LDST
8763 #define GEN_SPEOP_LDST(name, opc2, sh) \
8764 GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE)
8765 GEN_SPEOP_LDST(evldd
, 0x00, 3),
8766 GEN_SPEOP_LDST(evldw
, 0x01, 3),
8767 GEN_SPEOP_LDST(evldh
, 0x02, 3),
8768 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1),
8769 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1),
8770 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1),
8771 GEN_SPEOP_LDST(evlwhe
, 0x08, 2),
8772 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2),
8773 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2),
8774 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2),
8775 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2),
8777 GEN_SPEOP_LDST(evstdd
, 0x10, 3),
8778 GEN_SPEOP_LDST(evstdw
, 0x11, 3),
8779 GEN_SPEOP_LDST(evstdh
, 0x12, 3),
8780 GEN_SPEOP_LDST(evstwhe
, 0x18, 2),
8781 GEN_SPEOP_LDST(evstwho
, 0x1A, 2),
8782 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2),
8783 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2),
8786 #include "translate_init.c"
8787 #include "helper_regs.h"
8789 /*****************************************************************************/
8790 /* Misc PowerPC helpers */
8791 void cpu_dump_state (CPUState
*env
, FILE *f
,
8792 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8800 cpu_fprintf(f
, "NIP " ADDRX
" LR " ADDRX
" CTR " ADDRX
" XER %08x\n",
8801 env
->nip
, env
->lr
, env
->ctr
, env
->xer
);
8802 cpu_fprintf(f
, "MSR " ADDRX
" HID0 " ADDRX
" HF " ADDRX
" idx %d\n",
8803 env
->msr
, env
->spr
[SPR_HID0
], env
->hflags
, env
->mmu_idx
);
8804 #if !defined(NO_TIMER_DUMP)
8805 cpu_fprintf(f
, "TB %08x %08x "
8806 #if !defined(CONFIG_USER_ONLY)
8810 cpu_ppc_load_tbu(env
), cpu_ppc_load_tbl(env
)
8811 #if !defined(CONFIG_USER_ONLY)
8812 , cpu_ppc_load_decr(env
)
8816 for (i
= 0; i
< 32; i
++) {
8817 if ((i
& (RGPL
- 1)) == 0)
8818 cpu_fprintf(f
, "GPR%02d", i
);
8819 cpu_fprintf(f
, " " REGX
, ppc_dump_gpr(env
, i
));
8820 if ((i
& (RGPL
- 1)) == (RGPL
- 1))
8821 cpu_fprintf(f
, "\n");
8823 cpu_fprintf(f
, "CR ");
8824 for (i
= 0; i
< 8; i
++)
8825 cpu_fprintf(f
, "%01x", env
->crf
[i
]);
8826 cpu_fprintf(f
, " [");
8827 for (i
= 0; i
< 8; i
++) {
8829 if (env
->crf
[i
] & 0x08)
8831 else if (env
->crf
[i
] & 0x04)
8833 else if (env
->crf
[i
] & 0x02)
8835 cpu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
8837 cpu_fprintf(f
, " ] RES " ADDRX
"\n", env
->reserve
);
8838 for (i
= 0; i
< 32; i
++) {
8839 if ((i
& (RFPL
- 1)) == 0)
8840 cpu_fprintf(f
, "FPR%02d", i
);
8841 cpu_fprintf(f
, " %016" PRIx64
, *((uint64_t *)&env
->fpr
[i
]));
8842 if ((i
& (RFPL
- 1)) == (RFPL
- 1))
8843 cpu_fprintf(f
, "\n");
8845 cpu_fprintf(f
, "FPSCR %08x\n", env
->fpscr
);
8846 #if !defined(CONFIG_USER_ONLY)
8847 cpu_fprintf(f
, "SRR0 " ADDRX
" SRR1 " ADDRX
" SDR1 " ADDRX
"\n",
8848 env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
], env
->sdr1
);
8855 void cpu_dump_statistics (CPUState
*env
, FILE*f
,
8856 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
8859 #if defined(DO_PPC_STATISTICS)
8860 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
8864 for (op1
= 0; op1
< 64; op1
++) {
8866 if (is_indirect_opcode(handler
)) {
8867 t2
= ind_table(handler
);
8868 for (op2
= 0; op2
< 32; op2
++) {
8870 if (is_indirect_opcode(handler
)) {
8871 t3
= ind_table(handler
);
8872 for (op3
= 0; op3
< 32; op3
++) {
8874 if (handler
->count
== 0)
8876 cpu_fprintf(f
, "%02x %02x %02x (%02x %04d) %16s: "
8878 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
8880 handler
->count
, handler
->count
);
8883 if (handler
->count
== 0)
8885 cpu_fprintf(f
, "%02x %02x (%02x %04d) %16s: "
8887 op1
, op2
, op1
, op2
, handler
->oname
,
8888 handler
->count
, handler
->count
);
8892 if (handler
->count
== 0)
8894 cpu_fprintf(f
, "%02x (%02x ) %16s: %016llx %lld\n",
8895 op1
, op1
, handler
->oname
,
8896 handler
->count
, handler
->count
);
8902 /*****************************************************************************/
8903 static always_inline
void gen_intermediate_code_internal (CPUState
*env
,
8904 TranslationBlock
*tb
,
8907 DisasContext ctx
, *ctxp
= &ctx
;
8908 opc_handler_t
**table
, *handler
;
8909 target_ulong pc_start
;
8910 uint16_t *gen_opc_end
;
8917 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
8920 ctx
.exception
= POWERPC_EXCP_NONE
;
8921 ctx
.spr_cb
= env
->spr_cb
;
8922 ctx
.mem_idx
= env
->mmu_idx
;
8923 ctx
.access_type
= -1;
8924 ctx
.le_mode
= env
->hflags
& (1 << MSR_LE
) ? 1 : 0;
8925 #if defined(TARGET_PPC64)
8926 ctx
.sf_mode
= msr_sf
;
8928 ctx
.fpu_enabled
= msr_fp
;
8929 if ((env
->flags
& POWERPC_FLAG_SPE
) && msr_spe
)
8930 ctx
.spe_enabled
= msr_spe
;
8932 ctx
.spe_enabled
= 0;
8933 if ((env
->flags
& POWERPC_FLAG_VRE
) && msr_vr
)
8934 ctx
.altivec_enabled
= msr_vr
;
8936 ctx
.altivec_enabled
= 0;
8937 if ((env
->flags
& POWERPC_FLAG_SE
) && msr_se
)
8938 ctx
.singlestep_enabled
= CPU_SINGLE_STEP
;
8940 ctx
.singlestep_enabled
= 0;
8941 if ((env
->flags
& POWERPC_FLAG_BE
) && msr_be
)
8942 ctx
.singlestep_enabled
|= CPU_BRANCH_STEP
;
8943 if (unlikely(env
->singlestep_enabled
))
8944 ctx
.singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
8945 #if defined (DO_SINGLE_STEP) && 0
8946 /* Single step trace mode */
8950 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
8952 max_insns
= CF_COUNT_MASK
;
8955 /* Set env in case of segfault during code fetch */
8956 while (ctx
.exception
== POWERPC_EXCP_NONE
&& gen_opc_ptr
< gen_opc_end
) {
8957 if (unlikely(!TAILQ_EMPTY(&env
->breakpoints
))) {
8958 TAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
8959 if (bp
->pc
== ctx
.nip
) {
8960 gen_debug_exception(ctxp
);
8965 if (unlikely(search_pc
)) {
8966 j
= gen_opc_ptr
- gen_opc_buf
;
8970 gen_opc_instr_start
[lj
++] = 0;
8972 gen_opc_pc
[lj
] = ctx
.nip
;
8973 gen_opc_instr_start
[lj
] = 1;
8974 gen_opc_icount
[lj
] = num_insns
;
8976 LOG_DISAS("----------------\n");
8977 LOG_DISAS("nip=" ADDRX
" super=%d ir=%d\n",
8978 ctx
.nip
, ctx
.mem_idx
, (int)msr_ir
);
8979 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
8981 if (unlikely(ctx
.le_mode
)) {
8982 ctx
.opcode
= bswap32(ldl_code(ctx
.nip
));
8984 ctx
.opcode
= ldl_code(ctx
.nip
);
8986 LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n",
8987 ctx
.opcode
, opc1(ctx
.opcode
), opc2(ctx
.opcode
),
8988 opc3(ctx
.opcode
), little_endian
? "little" : "big");
8990 table
= env
->opcodes
;
8992 handler
= table
[opc1(ctx
.opcode
)];
8993 if (is_indirect_opcode(handler
)) {
8994 table
= ind_table(handler
);
8995 handler
= table
[opc2(ctx
.opcode
)];
8996 if (is_indirect_opcode(handler
)) {
8997 table
= ind_table(handler
);
8998 handler
= table
[opc3(ctx
.opcode
)];
9001 /* Is opcode *REALLY* valid ? */
9002 if (unlikely(handler
->handler
== &gen_invalid
)) {
9003 if (qemu_log_enabled()) {
9004 qemu_log("invalid/unsupported opcode: "
9005 "%02x - %02x - %02x (%08x) " ADDRX
" %d\n",
9006 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
9007 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
9009 printf("invalid/unsupported opcode: "
9010 "%02x - %02x - %02x (%08x) " ADDRX
" %d\n",
9011 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
9012 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
9015 if (unlikely((ctx
.opcode
& handler
->inval
) != 0)) {
9016 if (qemu_log_enabled()) {
9017 qemu_log("invalid bits: %08x for opcode: "
9018 "%02x - %02x - %02x (%08x) " ADDRX
"\n",
9019 ctx
.opcode
& handler
->inval
, opc1(ctx
.opcode
),
9020 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
9021 ctx
.opcode
, ctx
.nip
- 4);
9023 printf("invalid bits: %08x for opcode: "
9024 "%02x - %02x - %02x (%08x) " ADDRX
"\n",
9025 ctx
.opcode
& handler
->inval
, opc1(ctx
.opcode
),
9026 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
9027 ctx
.opcode
, ctx
.nip
- 4);
9029 gen_inval_exception(ctxp
, POWERPC_EXCP_INVAL_INVAL
);
9033 (*(handler
->handler
))(&ctx
);
9034 #if defined(DO_PPC_STATISTICS)
9037 /* Check trace mode exceptions */
9038 if (unlikely(ctx
.singlestep_enabled
& CPU_SINGLE_STEP
&&
9039 (ctx
.nip
<= 0x100 || ctx
.nip
> 0xF00) &&
9040 ctx
.exception
!= POWERPC_SYSCALL
&&
9041 ctx
.exception
!= POWERPC_EXCP_TRAP
&&
9042 ctx
.exception
!= POWERPC_EXCP_BRANCH
)) {
9043 gen_exception(ctxp
, POWERPC_EXCP_TRACE
);
9044 } else if (unlikely(((ctx
.nip
& (TARGET_PAGE_SIZE
- 1)) == 0) ||
9045 (env
->singlestep_enabled
) ||
9047 num_insns
>= max_insns
)) {
9048 /* if we reach a page boundary or are single stepping, stop
9054 if (tb
->cflags
& CF_LAST_IO
)
9056 if (ctx
.exception
== POWERPC_EXCP_NONE
) {
9057 gen_goto_tb(&ctx
, 0, ctx
.nip
);
9058 } else if (ctx
.exception
!= POWERPC_EXCP_BRANCH
) {
9059 if (unlikely(env
->singlestep_enabled
)) {
9060 gen_debug_exception(ctxp
);
9062 /* Generate the return instruction */
9065 gen_icount_end(tb
, num_insns
);
9066 *gen_opc_ptr
= INDEX_op_end
;
9067 if (unlikely(search_pc
)) {
9068 j
= gen_opc_ptr
- gen_opc_buf
;
9071 gen_opc_instr_start
[lj
++] = 0;
9073 tb
->size
= ctx
.nip
- pc_start
;
9074 tb
->icount
= num_insns
;
9076 #if defined(DEBUG_DISAS)
9077 qemu_log_mask(CPU_LOG_TB_CPU
, "---------------- excp: %04x\n", ctx
.exception
);
9078 log_cpu_state_mask(CPU_LOG_TB_CPU
, env
, 0);
9079 if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM
)) {
9081 flags
= env
->bfd_mach
;
9082 flags
|= ctx
.le_mode
<< 16;
9083 qemu_log("IN: %s\n", lookup_symbol(pc_start
));
9084 log_target_disas(pc_start
, ctx
.nip
- pc_start
, flags
);
9090 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
9092 gen_intermediate_code_internal(env
, tb
, 0);
9095 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
9097 gen_intermediate_code_internal(env
, tb
, 1);
9100 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
9101 unsigned long searched_pc
, int pc_pos
, void *puc
)
9103 env
->nip
= gen_opc_pc
[pc_pos
];