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, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "qemu-common.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 DO_SINGLE_STEP
42 //#define PPC_DEBUG_DISAS
43 //#define DO_PPC_STATISTICS
45 /*****************************************************************************/
46 /* Code translation helpers */
48 /* global register indexes */
49 static TCGv_ptr cpu_env
;
50 static char cpu_reg_names
[10*3 + 22*4 /* GPR */
51 #if !defined(TARGET_PPC64)
52 + 10*4 + 22*5 /* SPE GPRh */
54 + 10*4 + 22*5 /* FPR */
55 + 2*(10*6 + 22*7) /* AVRh, AVRl */
57 static TCGv cpu_gpr
[32];
58 #if !defined(TARGET_PPC64)
59 static TCGv cpu_gprh
[32];
61 static TCGv_i64 cpu_fpr
[32];
62 static TCGv_i64 cpu_avrh
[32], cpu_avrl
[32];
63 static TCGv_i32 cpu_crf
[8];
69 static TCGv cpu_reserve
;
70 static TCGv_i32 cpu_fpscr
;
71 static TCGv_i32 cpu_access_type
;
73 #include "gen-icount.h"
75 void ppc_translate_init(void)
79 static int done_init
= 0;
84 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
88 for (i
= 0; i
< 8; i
++) {
89 sprintf(p
, "crf%d", i
);
90 cpu_crf
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
91 offsetof(CPUState
, crf
[i
]), p
);
95 for (i
= 0; i
< 32; i
++) {
97 cpu_gpr
[i
] = tcg_global_mem_new(TCG_AREG0
,
98 offsetof(CPUState
, gpr
[i
]), p
);
99 p
+= (i
< 10) ? 3 : 4;
100 #if !defined(TARGET_PPC64)
101 sprintf(p
, "r%dH", i
);
102 cpu_gprh
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
103 offsetof(CPUState
, gprh
[i
]), p
);
104 p
+= (i
< 10) ? 4 : 5;
107 sprintf(p
, "fp%d", i
);
108 cpu_fpr
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
109 offsetof(CPUState
, fpr
[i
]), p
);
110 p
+= (i
< 10) ? 4 : 5;
112 sprintf(p
, "avr%dH", i
);
113 #ifdef WORDS_BIGENDIAN
114 cpu_avrh
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
115 offsetof(CPUState
, avr
[i
].u64
[0]), p
);
117 cpu_avrh
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
118 offsetof(CPUState
, avr
[i
].u64
[1]), p
);
120 p
+= (i
< 10) ? 6 : 7;
122 sprintf(p
, "avr%dL", i
);
123 #ifdef WORDS_BIGENDIAN
124 cpu_avrl
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
125 offsetof(CPUState
, avr
[i
].u64
[1]), p
);
127 cpu_avrl
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
128 offsetof(CPUState
, avr
[i
].u64
[0]), p
);
130 p
+= (i
< 10) ? 6 : 7;
133 cpu_nip
= tcg_global_mem_new(TCG_AREG0
,
134 offsetof(CPUState
, nip
), "nip");
136 cpu_msr
= tcg_global_mem_new(TCG_AREG0
,
137 offsetof(CPUState
, msr
), "msr");
139 cpu_ctr
= tcg_global_mem_new(TCG_AREG0
,
140 offsetof(CPUState
, ctr
), "ctr");
142 cpu_lr
= tcg_global_mem_new(TCG_AREG0
,
143 offsetof(CPUState
, lr
), "lr");
145 cpu_xer
= tcg_global_mem_new(TCG_AREG0
,
146 offsetof(CPUState
, xer
), "xer");
148 cpu_reserve
= tcg_global_mem_new(TCG_AREG0
,
149 offsetof(CPUState
, reserve
), "reserve");
151 cpu_fpscr
= tcg_global_mem_new_i32(TCG_AREG0
,
152 offsetof(CPUState
, fpscr
), "fpscr");
154 cpu_access_type
= tcg_global_mem_new_i32(TCG_AREG0
,
155 offsetof(CPUState
, access_type
), "access_type");
157 /* register helpers */
164 /* internal defines */
165 typedef struct DisasContext
{
166 struct TranslationBlock
*tb
;
170 /* Routine used to access memory */
173 /* Translation flags */
175 #if defined(TARGET_PPC64)
181 ppc_spr_t
*spr_cb
; /* Needed to check rights for mfspr/mtspr */
182 int singlestep_enabled
;
185 struct opc_handler_t
{
188 /* instruction type */
191 void (*handler
)(DisasContext
*ctx
);
192 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
195 #if defined(DO_PPC_STATISTICS)
200 static always_inline
void gen_reset_fpstatus (void)
202 #ifdef CONFIG_SOFTFLOAT
203 gen_helper_reset_fpstatus();
207 static always_inline
void gen_compute_fprf (TCGv_i64 arg
, int set_fprf
, int set_rc
)
209 TCGv_i32 t0
= tcg_temp_new_i32();
212 /* This case might be optimized later */
213 tcg_gen_movi_i32(t0
, 1);
214 gen_helper_compute_fprf(t0
, arg
, t0
);
215 if (unlikely(set_rc
)) {
216 tcg_gen_mov_i32(cpu_crf
[1], t0
);
218 gen_helper_float_check_status();
219 } else if (unlikely(set_rc
)) {
220 /* We always need to compute fpcc */
221 tcg_gen_movi_i32(t0
, 0);
222 gen_helper_compute_fprf(t0
, arg
, t0
);
223 tcg_gen_mov_i32(cpu_crf
[1], t0
);
226 tcg_temp_free_i32(t0
);
229 static always_inline
void gen_set_access_type (DisasContext
*ctx
, int access_type
)
231 if (ctx
->access_type
!= access_type
) {
232 tcg_gen_movi_i32(cpu_access_type
, access_type
);
233 ctx
->access_type
= access_type
;
237 static always_inline
void gen_update_nip (DisasContext
*ctx
, target_ulong nip
)
239 #if defined(TARGET_PPC64)
241 tcg_gen_movi_tl(cpu_nip
, nip
);
244 tcg_gen_movi_tl(cpu_nip
, (uint32_t)nip
);
247 static always_inline
void gen_exception_err (DisasContext
*ctx
, uint32_t excp
, uint32_t error
)
250 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
251 gen_update_nip(ctx
, ctx
->nip
);
253 t0
= tcg_const_i32(excp
);
254 t1
= tcg_const_i32(error
);
255 gen_helper_raise_exception_err(t0
, t1
);
256 tcg_temp_free_i32(t0
);
257 tcg_temp_free_i32(t1
);
258 ctx
->exception
= (excp
);
261 static always_inline
void gen_exception (DisasContext
*ctx
, uint32_t excp
)
264 if (ctx
->exception
== POWERPC_EXCP_NONE
) {
265 gen_update_nip(ctx
, ctx
->nip
);
267 t0
= tcg_const_i32(excp
);
268 gen_helper_raise_exception(t0
);
269 tcg_temp_free_i32(t0
);
270 ctx
->exception
= (excp
);
273 static always_inline
void gen_debug_exception (DisasContext
*ctx
)
276 gen_update_nip(ctx
, ctx
->nip
);
277 t0
= tcg_const_i32(EXCP_DEBUG
);
278 gen_helper_raise_exception(t0
);
279 tcg_temp_free_i32(t0
);
282 static always_inline
void gen_inval_exception (DisasContext
*ctx
, uint32_t error
)
284 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_INVAL
| error
);
287 /* Stop translation */
288 static always_inline
void gen_stop_exception (DisasContext
*ctx
)
290 gen_update_nip(ctx
, ctx
->nip
);
291 ctx
->exception
= POWERPC_EXCP_STOP
;
294 /* No need to update nip here, as execution flow will change */
295 static always_inline
void gen_sync_exception (DisasContext
*ctx
)
297 ctx
->exception
= POWERPC_EXCP_SYNC
;
300 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
301 static void gen_##name (DisasContext *ctx); \
302 GEN_OPCODE(name, opc1, opc2, opc3, inval, type); \
303 static void gen_##name (DisasContext *ctx)
305 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
306 static void gen_##name (DisasContext *ctx); \
307 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type); \
308 static void gen_##name (DisasContext *ctx)
310 typedef struct opcode_t
{
311 unsigned char opc1
, opc2
, opc3
;
312 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
313 unsigned char pad
[5];
315 unsigned char pad
[1];
317 opc_handler_t handler
;
321 /*****************************************************************************/
322 /*** Instruction decoding ***/
323 #define EXTRACT_HELPER(name, shift, nb) \
324 static always_inline uint32_t name (uint32_t opcode) \
326 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
329 #define EXTRACT_SHELPER(name, shift, nb) \
330 static always_inline int32_t name (uint32_t opcode) \
332 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
336 EXTRACT_HELPER(opc1
, 26, 6);
338 EXTRACT_HELPER(opc2
, 1, 5);
340 EXTRACT_HELPER(opc3
, 6, 5);
341 /* Update Cr0 flags */
342 EXTRACT_HELPER(Rc
, 0, 1);
344 EXTRACT_HELPER(rD
, 21, 5);
346 EXTRACT_HELPER(rS
, 21, 5);
348 EXTRACT_HELPER(rA
, 16, 5);
350 EXTRACT_HELPER(rB
, 11, 5);
352 EXTRACT_HELPER(rC
, 6, 5);
354 EXTRACT_HELPER(crfD
, 23, 3);
355 EXTRACT_HELPER(crfS
, 18, 3);
356 EXTRACT_HELPER(crbD
, 21, 5);
357 EXTRACT_HELPER(crbA
, 16, 5);
358 EXTRACT_HELPER(crbB
, 11, 5);
360 EXTRACT_HELPER(_SPR
, 11, 10);
361 static always_inline
uint32_t SPR (uint32_t opcode
)
363 uint32_t sprn
= _SPR(opcode
);
365 return ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
367 /*** Get constants ***/
368 EXTRACT_HELPER(IMM
, 12, 8);
369 /* 16 bits signed immediate value */
370 EXTRACT_SHELPER(SIMM
, 0, 16);
371 /* 16 bits unsigned immediate value */
372 EXTRACT_HELPER(UIMM
, 0, 16);
374 EXTRACT_HELPER(NB
, 11, 5);
376 EXTRACT_HELPER(SH
, 11, 5);
378 EXTRACT_HELPER(MB
, 6, 5);
380 EXTRACT_HELPER(ME
, 1, 5);
382 EXTRACT_HELPER(TO
, 21, 5);
384 EXTRACT_HELPER(CRM
, 12, 8);
385 EXTRACT_HELPER(FM
, 17, 8);
386 EXTRACT_HELPER(SR
, 16, 4);
387 EXTRACT_HELPER(FPIMM
, 12, 4);
389 /*** Jump target decoding ***/
391 EXTRACT_SHELPER(d
, 0, 16);
392 /* Immediate address */
393 static always_inline target_ulong
LI (uint32_t opcode
)
395 return (opcode
>> 0) & 0x03FFFFFC;
398 static always_inline
uint32_t BD (uint32_t opcode
)
400 return (opcode
>> 0) & 0xFFFC;
403 EXTRACT_HELPER(BO
, 21, 5);
404 EXTRACT_HELPER(BI
, 16, 5);
405 /* Absolute/relative address */
406 EXTRACT_HELPER(AA
, 1, 1);
408 EXTRACT_HELPER(LK
, 0, 1);
410 /* Create a mask between <start> and <end> bits */
411 static always_inline target_ulong
MASK (uint32_t start
, uint32_t end
)
415 #if defined(TARGET_PPC64)
416 if (likely(start
== 0)) {
417 ret
= UINT64_MAX
<< (63 - end
);
418 } else if (likely(end
== 63)) {
419 ret
= UINT64_MAX
>> start
;
422 if (likely(start
== 0)) {
423 ret
= UINT32_MAX
<< (31 - end
);
424 } else if (likely(end
== 31)) {
425 ret
= UINT32_MAX
>> start
;
429 ret
= (((target_ulong
)(-1ULL)) >> (start
)) ^
430 (((target_ulong
)(-1ULL) >> (end
)) >> 1);
431 if (unlikely(start
> end
))
438 /*****************************************************************************/
439 /* PowerPC Instructions types definitions */
441 PPC_NONE
= 0x0000000000000000ULL
,
442 /* PowerPC base instructions set */
443 PPC_INSNS_BASE
= 0x0000000000000001ULL
,
444 /* integer operations instructions */
445 #define PPC_INTEGER PPC_INSNS_BASE
446 /* flow control instructions */
447 #define PPC_FLOW PPC_INSNS_BASE
448 /* virtual memory instructions */
449 #define PPC_MEM PPC_INSNS_BASE
450 /* ld/st with reservation instructions */
451 #define PPC_RES PPC_INSNS_BASE
452 /* spr/msr access instructions */
453 #define PPC_MISC PPC_INSNS_BASE
454 /* Deprecated instruction sets */
455 /* Original POWER instruction set */
456 PPC_POWER
= 0x0000000000000002ULL
,
457 /* POWER2 instruction set extension */
458 PPC_POWER2
= 0x0000000000000004ULL
,
459 /* Power RTC support */
460 PPC_POWER_RTC
= 0x0000000000000008ULL
,
461 /* Power-to-PowerPC bridge (601) */
462 PPC_POWER_BR
= 0x0000000000000010ULL
,
463 /* 64 bits PowerPC instruction set */
464 PPC_64B
= 0x0000000000000020ULL
,
465 /* New 64 bits extensions (PowerPC 2.0x) */
466 PPC_64BX
= 0x0000000000000040ULL
,
467 /* 64 bits hypervisor extensions */
468 PPC_64H
= 0x0000000000000080ULL
,
469 /* New wait instruction (PowerPC 2.0x) */
470 PPC_WAIT
= 0x0000000000000100ULL
,
471 /* Time base mftb instruction */
472 PPC_MFTB
= 0x0000000000000200ULL
,
474 /* Fixed-point unit extensions */
475 /* PowerPC 602 specific */
476 PPC_602_SPEC
= 0x0000000000000400ULL
,
477 /* isel instruction */
478 PPC_ISEL
= 0x0000000000000800ULL
,
479 /* popcntb instruction */
480 PPC_POPCNTB
= 0x0000000000001000ULL
,
481 /* string load / store */
482 PPC_STRING
= 0x0000000000002000ULL
,
484 /* Floating-point unit extensions */
485 /* Optional floating point instructions */
486 PPC_FLOAT
= 0x0000000000010000ULL
,
487 /* New floating-point extensions (PowerPC 2.0x) */
488 PPC_FLOAT_EXT
= 0x0000000000020000ULL
,
489 PPC_FLOAT_FSQRT
= 0x0000000000040000ULL
,
490 PPC_FLOAT_FRES
= 0x0000000000080000ULL
,
491 PPC_FLOAT_FRSQRTE
= 0x0000000000100000ULL
,
492 PPC_FLOAT_FRSQRTES
= 0x0000000000200000ULL
,
493 PPC_FLOAT_FSEL
= 0x0000000000400000ULL
,
494 PPC_FLOAT_STFIWX
= 0x0000000000800000ULL
,
496 /* Vector/SIMD extensions */
497 /* Altivec support */
498 PPC_ALTIVEC
= 0x0000000001000000ULL
,
499 /* PowerPC 2.03 SPE extension */
500 PPC_SPE
= 0x0000000002000000ULL
,
501 /* PowerPC 2.03 SPE floating-point extension */
502 PPC_SPEFPU
= 0x0000000004000000ULL
,
504 /* Optional memory control instructions */
505 PPC_MEM_TLBIA
= 0x0000000010000000ULL
,
506 PPC_MEM_TLBIE
= 0x0000000020000000ULL
,
507 PPC_MEM_TLBSYNC
= 0x0000000040000000ULL
,
508 /* sync instruction */
509 PPC_MEM_SYNC
= 0x0000000080000000ULL
,
510 /* eieio instruction */
511 PPC_MEM_EIEIO
= 0x0000000100000000ULL
,
513 /* Cache control instructions */
514 PPC_CACHE
= 0x0000000200000000ULL
,
515 /* icbi instruction */
516 PPC_CACHE_ICBI
= 0x0000000400000000ULL
,
517 /* dcbz instruction with fixed cache line size */
518 PPC_CACHE_DCBZ
= 0x0000000800000000ULL
,
519 /* dcbz instruction with tunable cache line size */
520 PPC_CACHE_DCBZT
= 0x0000001000000000ULL
,
521 /* dcba instruction */
522 PPC_CACHE_DCBA
= 0x0000002000000000ULL
,
523 /* Freescale cache locking instructions */
524 PPC_CACHE_LOCK
= 0x0000004000000000ULL
,
526 /* MMU related extensions */
527 /* external control instructions */
528 PPC_EXTERN
= 0x0000010000000000ULL
,
529 /* segment register access instructions */
530 PPC_SEGMENT
= 0x0000020000000000ULL
,
531 /* PowerPC 6xx TLB management instructions */
532 PPC_6xx_TLB
= 0x0000040000000000ULL
,
533 /* PowerPC 74xx TLB management instructions */
534 PPC_74xx_TLB
= 0x0000080000000000ULL
,
535 /* PowerPC 40x TLB management instructions */
536 PPC_40x_TLB
= 0x0000100000000000ULL
,
537 /* segment register access instructions for PowerPC 64 "bridge" */
538 PPC_SEGMENT_64B
= 0x0000200000000000ULL
,
540 PPC_SLBI
= 0x0000400000000000ULL
,
542 /* Embedded PowerPC dedicated instructions */
543 PPC_WRTEE
= 0x0001000000000000ULL
,
544 /* PowerPC 40x exception model */
545 PPC_40x_EXCP
= 0x0002000000000000ULL
,
546 /* PowerPC 405 Mac instructions */
547 PPC_405_MAC
= 0x0004000000000000ULL
,
548 /* PowerPC 440 specific instructions */
549 PPC_440_SPEC
= 0x0008000000000000ULL
,
550 /* BookE (embedded) PowerPC specification */
551 PPC_BOOKE
= 0x0010000000000000ULL
,
552 /* mfapidi instruction */
553 PPC_MFAPIDI
= 0x0020000000000000ULL
,
554 /* tlbiva instruction */
555 PPC_TLBIVA
= 0x0040000000000000ULL
,
556 /* tlbivax instruction */
557 PPC_TLBIVAX
= 0x0080000000000000ULL
,
558 /* PowerPC 4xx dedicated instructions */
559 PPC_4xx_COMMON
= 0x0100000000000000ULL
,
560 /* PowerPC 40x ibct instructions */
561 PPC_40x_ICBT
= 0x0200000000000000ULL
,
562 /* rfmci is not implemented in all BookE PowerPC */
563 PPC_RFMCI
= 0x0400000000000000ULL
,
564 /* rfdi instruction */
565 PPC_RFDI
= 0x0800000000000000ULL
,
567 PPC_DCR
= 0x1000000000000000ULL
,
568 /* DCR extended accesse */
569 PPC_DCRX
= 0x2000000000000000ULL
,
570 /* user-mode DCR access, implemented in PowerPC 460 */
571 PPC_DCRUX
= 0x4000000000000000ULL
,
574 /*****************************************************************************/
575 /* PowerPC instructions table */
576 #if HOST_LONG_BITS == 64
581 #if defined(__APPLE__)
582 #define OPCODES_SECTION \
583 __attribute__ ((section("__TEXT,__opcodes"), unused, aligned (OPC_ALIGN) ))
585 #define OPCODES_SECTION \
586 __attribute__ ((section(".opcodes"), unused, aligned (OPC_ALIGN) ))
589 #if defined(DO_PPC_STATISTICS)
590 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
591 OPCODES_SECTION opcode_t opc_##name = { \
599 .handler = &gen_##name, \
600 .oname = stringify(name), \
602 .oname = stringify(name), \
604 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
605 OPCODES_SECTION opcode_t opc_##name = { \
613 .handler = &gen_##name, \
619 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
620 OPCODES_SECTION opcode_t opc_##name = { \
628 .handler = &gen_##name, \
630 .oname = stringify(name), \
632 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
633 OPCODES_SECTION opcode_t opc_##name = { \
641 .handler = &gen_##name, \
647 #define GEN_OPCODE_MARK(name) \
648 OPCODES_SECTION opcode_t opc_##name = { \
654 .inval = 0x00000000, \
658 .oname = stringify(name), \
661 /* SPR load/store helpers */
662 static always_inline
void gen_load_spr(TCGv t
, int reg
)
664 tcg_gen_ld_tl(t
, cpu_env
, offsetof(CPUState
, spr
[reg
]));
667 static always_inline
void gen_store_spr(int reg
, TCGv t
)
669 tcg_gen_st_tl(t
, cpu_env
, offsetof(CPUState
, spr
[reg
]));
672 /* Start opcode list */
673 GEN_OPCODE_MARK(start
);
675 /* Invalid instruction */
676 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
)
678 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
681 static opc_handler_t invalid_handler
= {
684 .handler
= gen_invalid
,
687 /*** Integer comparison ***/
689 static always_inline
void gen_op_cmp(TCGv arg0
, TCGv arg1
, int s
, int crf
)
693 tcg_gen_trunc_tl_i32(cpu_crf
[crf
], cpu_xer
);
694 tcg_gen_shri_i32(cpu_crf
[crf
], cpu_crf
[crf
], XER_SO
);
695 tcg_gen_andi_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1);
697 l1
= gen_new_label();
698 l2
= gen_new_label();
699 l3
= gen_new_label();
701 tcg_gen_brcond_tl(TCG_COND_LT
, arg0
, arg1
, l1
);
702 tcg_gen_brcond_tl(TCG_COND_GT
, arg0
, arg1
, l2
);
704 tcg_gen_brcond_tl(TCG_COND_LTU
, arg0
, arg1
, l1
);
705 tcg_gen_brcond_tl(TCG_COND_GTU
, arg0
, arg1
, l2
);
707 tcg_gen_ori_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1 << CRF_EQ
);
710 tcg_gen_ori_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1 << CRF_LT
);
713 tcg_gen_ori_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1 << CRF_GT
);
717 static always_inline
void gen_op_cmpi(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
719 TCGv t0
= tcg_const_local_tl(arg1
);
720 gen_op_cmp(arg0
, t0
, s
, crf
);
724 #if defined(TARGET_PPC64)
725 static always_inline
void gen_op_cmp32(TCGv arg0
, TCGv arg1
, int s
, int crf
)
728 t0
= tcg_temp_local_new();
729 t1
= tcg_temp_local_new();
731 tcg_gen_ext32s_tl(t0
, arg0
);
732 tcg_gen_ext32s_tl(t1
, arg1
);
734 tcg_gen_ext32u_tl(t0
, arg0
);
735 tcg_gen_ext32u_tl(t1
, arg1
);
737 gen_op_cmp(t0
, t1
, s
, crf
);
742 static always_inline
void gen_op_cmpi32(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
744 TCGv t0
= tcg_const_local_tl(arg1
);
745 gen_op_cmp32(arg0
, t0
, s
, crf
);
750 static always_inline
void gen_set_Rc0 (DisasContext
*ctx
, TCGv reg
)
752 #if defined(TARGET_PPC64)
754 gen_op_cmpi32(reg
, 0, 1, 0);
757 gen_op_cmpi(reg
, 0, 1, 0);
761 GEN_HANDLER(cmp
, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER
)
763 #if defined(TARGET_PPC64)
764 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
765 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
766 1, crfD(ctx
->opcode
));
769 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
770 1, crfD(ctx
->opcode
));
774 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
)
776 #if defined(TARGET_PPC64)
777 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
778 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
779 1, crfD(ctx
->opcode
));
782 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
783 1, crfD(ctx
->opcode
));
787 GEN_HANDLER(cmpl
, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER
)
789 #if defined(TARGET_PPC64)
790 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
791 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
792 0, crfD(ctx
->opcode
));
795 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
796 0, crfD(ctx
->opcode
));
800 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
)
802 #if defined(TARGET_PPC64)
803 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
804 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
805 0, crfD(ctx
->opcode
));
808 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
809 0, crfD(ctx
->opcode
));
812 /* isel (PowerPC 2.03 specification) */
813 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
)
816 uint32_t bi
= rC(ctx
->opcode
);
820 l1
= gen_new_label();
821 l2
= gen_new_label();
823 mask
= 1 << (3 - (bi
& 0x03));
824 t0
= tcg_temp_new_i32();
825 tcg_gen_andi_i32(t0
, cpu_crf
[bi
>> 2], mask
);
826 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
827 if (rA(ctx
->opcode
) == 0)
828 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
830 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
833 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
835 tcg_temp_free_i32(t0
);
838 /*** Integer arithmetic ***/
840 static always_inline
void gen_op_arith_compute_ov(DisasContext
*ctx
, TCGv arg0
, TCGv arg1
, TCGv arg2
, int sub
)
845 l1
= gen_new_label();
846 /* Start with XER OV disabled, the most likely case */
847 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
848 t0
= tcg_temp_local_new();
849 tcg_gen_xor_tl(t0
, arg0
, arg1
);
850 #if defined(TARGET_PPC64)
852 tcg_gen_ext32s_tl(t0
, t0
);
855 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0, l1
);
857 tcg_gen_brcondi_tl(TCG_COND_GE
, t0
, 0, l1
);
858 tcg_gen_xor_tl(t0
, arg1
, arg2
);
859 #if defined(TARGET_PPC64)
861 tcg_gen_ext32s_tl(t0
, t0
);
864 tcg_gen_brcondi_tl(TCG_COND_GE
, t0
, 0, l1
);
866 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0, l1
);
867 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
872 static always_inline
void gen_op_arith_compute_ca(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
, int sub
)
874 int l1
= gen_new_label();
876 #if defined(TARGET_PPC64)
877 if (!(ctx
->sf_mode
)) {
882 tcg_gen_ext32u_tl(t0
, arg1
);
883 tcg_gen_ext32u_tl(t1
, arg2
);
885 tcg_gen_brcond_tl(TCG_COND_GTU
, t0
, t1
, l1
);
887 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
889 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
897 tcg_gen_brcond_tl(TCG_COND_GTU
, arg1
, arg2
, l1
);
899 tcg_gen_brcond_tl(TCG_COND_GEU
, arg1
, arg2
, l1
);
901 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
906 /* Common add function */
907 static always_inline
void gen_op_arith_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
, TCGv arg2
,
908 int add_ca
, int compute_ca
, int compute_ov
)
912 if ((!compute_ca
&& !compute_ov
) ||
913 (!TCGV_EQUAL(ret
,arg1
) && !TCGV_EQUAL(ret
, arg2
))) {
916 t0
= tcg_temp_local_new();
920 t1
= tcg_temp_local_new();
921 tcg_gen_andi_tl(t1
, cpu_xer
, (1 << XER_CA
));
922 tcg_gen_shri_tl(t1
, t1
, XER_CA
);
925 if (compute_ca
&& compute_ov
) {
926 /* Start with XER CA and OV disabled, the most likely case */
927 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~((1 << XER_CA
) | (1 << XER_OV
)));
928 } else if (compute_ca
) {
929 /* Start with XER CA disabled, the most likely case */
930 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
931 } else if (compute_ov
) {
932 /* Start with XER OV disabled, the most likely case */
933 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
936 tcg_gen_add_tl(t0
, arg1
, arg2
);
939 gen_op_arith_compute_ca(ctx
, t0
, arg1
, 0);
942 tcg_gen_add_tl(t0
, t0
, t1
);
943 gen_op_arith_compute_ca(ctx
, t0
, t1
, 0);
947 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 0);
950 if (unlikely(Rc(ctx
->opcode
) != 0))
951 gen_set_Rc0(ctx
, t0
);
953 if (!TCGV_EQUAL(t0
, ret
)) {
954 tcg_gen_mov_tl(ret
, t0
);
958 /* Add functions with two operands */
959 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
960 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER) \
962 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
963 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
964 add_ca, compute_ca, compute_ov); \
966 /* Add functions with one operand and one immediate */
967 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
968 add_ca, compute_ca, compute_ov) \
969 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER) \
971 TCGv t0 = tcg_const_local_tl(const_val); \
972 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
973 cpu_gpr[rA(ctx->opcode)], t0, \
974 add_ca, compute_ca, compute_ov); \
978 /* add add. addo addo. */
979 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
980 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
981 /* addc addc. addco addco. */
982 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
983 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
984 /* adde adde. addeo addeo. */
985 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
986 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
987 /* addme addme. addmeo addmeo. */
988 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
989 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
990 /* addze addze. addzeo addzeo.*/
991 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
992 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
994 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
996 target_long simm
= SIMM(ctx
->opcode
);
998 if (rA(ctx
->opcode
) == 0) {
1000 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
);
1002 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], simm
);
1006 static always_inline
void gen_op_addic (DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1009 target_long simm
= SIMM(ctx
->opcode
);
1011 /* Start with XER CA and OV disabled, the most likely case */
1012 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1014 if (likely(simm
!= 0)) {
1015 TCGv t0
= tcg_temp_local_new();
1016 tcg_gen_addi_tl(t0
, arg1
, simm
);
1017 gen_op_arith_compute_ca(ctx
, t0
, arg1
, 0);
1018 tcg_gen_mov_tl(ret
, t0
);
1021 tcg_gen_mov_tl(ret
, arg1
);
1024 gen_set_Rc0(ctx
, ret
);
1027 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1029 gen_op_addic(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0);
1031 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1033 gen_op_addic(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 1);
1036 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1038 target_long simm
= SIMM(ctx
->opcode
);
1040 if (rA(ctx
->opcode
) == 0) {
1042 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
<< 16);
1044 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], simm
<< 16);
1048 static always_inline
void gen_op_arith_divw (DisasContext
*ctx
, TCGv ret
, TCGv arg1
, TCGv arg2
,
1049 int sign
, int compute_ov
)
1051 int l1
= gen_new_label();
1052 int l2
= gen_new_label();
1053 TCGv_i32 t0
= tcg_temp_local_new_i32();
1054 TCGv_i32 t1
= tcg_temp_local_new_i32();
1056 tcg_gen_trunc_tl_i32(t0
, arg1
);
1057 tcg_gen_trunc_tl_i32(t1
, arg2
);
1058 tcg_gen_brcondi_i32(TCG_COND_EQ
, t1
, 0, l1
);
1060 int l3
= gen_new_label();
1061 tcg_gen_brcondi_i32(TCG_COND_NE
, t1
, -1, l3
);
1062 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, INT32_MIN
, l1
);
1064 tcg_gen_div_i32(t0
, t0
, t1
);
1066 tcg_gen_divu_i32(t0
, t0
, t1
);
1069 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1074 tcg_gen_sari_i32(t0
, t0
, 31);
1076 tcg_gen_movi_i32(t0
, 0);
1079 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1082 tcg_gen_extu_i32_tl(ret
, t0
);
1083 tcg_temp_free_i32(t0
);
1084 tcg_temp_free_i32(t1
);
1085 if (unlikely(Rc(ctx
->opcode
) != 0))
1086 gen_set_Rc0(ctx
, ret
);
1089 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
1090 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER) \
1092 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
1093 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1094 sign, compute_ov); \
1096 /* divwu divwu. divwuo divwuo. */
1097 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0);
1098 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1);
1099 /* divw divw. divwo divwo. */
1100 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0);
1101 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1);
1102 #if defined(TARGET_PPC64)
1103 static always_inline
void gen_op_arith_divd (DisasContext
*ctx
, TCGv ret
, TCGv arg1
, TCGv arg2
,
1104 int sign
, int compute_ov
)
1106 int l1
= gen_new_label();
1107 int l2
= gen_new_label();
1109 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg2
, 0, l1
);
1111 int l3
= gen_new_label();
1112 tcg_gen_brcondi_i64(TCG_COND_NE
, arg2
, -1, l3
);
1113 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg1
, INT64_MIN
, l1
);
1115 tcg_gen_div_i64(ret
, arg1
, arg2
);
1117 tcg_gen_divu_i64(ret
, arg1
, arg2
);
1120 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1125 tcg_gen_sari_i64(ret
, arg1
, 63);
1127 tcg_gen_movi_i64(ret
, 0);
1130 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1133 if (unlikely(Rc(ctx
->opcode
) != 0))
1134 gen_set_Rc0(ctx
, ret
);
1136 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1137 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) \
1139 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1140 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1141 sign, compute_ov); \
1143 /* divwu divwu. divwuo divwuo. */
1144 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0);
1145 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1);
1146 /* divw divw. divwo divwo. */
1147 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0);
1148 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1);
1152 GEN_HANDLER(mulhw
, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER
)
1156 t0
= tcg_temp_new_i64();
1157 t1
= tcg_temp_new_i64();
1158 #if defined(TARGET_PPC64)
1159 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1160 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1161 tcg_gen_mul_i64(t0
, t0
, t1
);
1162 tcg_gen_shri_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
1164 tcg_gen_ext_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1165 tcg_gen_ext_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1166 tcg_gen_mul_i64(t0
, t0
, t1
);
1167 tcg_gen_shri_i64(t0
, t0
, 32);
1168 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1170 tcg_temp_free_i64(t0
);
1171 tcg_temp_free_i64(t1
);
1172 if (unlikely(Rc(ctx
->opcode
) != 0))
1173 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1175 /* mulhwu mulhwu. */
1176 GEN_HANDLER(mulhwu
, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER
)
1180 t0
= tcg_temp_new_i64();
1181 t1
= tcg_temp_new_i64();
1182 #if defined(TARGET_PPC64)
1183 tcg_gen_ext32u_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1184 tcg_gen_ext32u_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1185 tcg_gen_mul_i64(t0
, t0
, t1
);
1186 tcg_gen_shri_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
1188 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1189 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1190 tcg_gen_mul_i64(t0
, t0
, t1
);
1191 tcg_gen_shri_i64(t0
, t0
, 32);
1192 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1194 tcg_temp_free_i64(t0
);
1195 tcg_temp_free_i64(t1
);
1196 if (unlikely(Rc(ctx
->opcode
) != 0))
1197 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1200 GEN_HANDLER(mullw
, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER
)
1202 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1203 cpu_gpr
[rB(ctx
->opcode
)]);
1204 tcg_gen_ext32s_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)]);
1205 if (unlikely(Rc(ctx
->opcode
) != 0))
1206 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1208 /* mullwo mullwo. */
1209 GEN_HANDLER(mullwo
, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER
)
1214 t0
= tcg_temp_new_i64();
1215 t1
= tcg_temp_new_i64();
1216 l1
= gen_new_label();
1217 /* Start with XER OV disabled, the most likely case */
1218 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1219 #if defined(TARGET_PPC64)
1220 tcg_gen_ext32s_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1221 tcg_gen_ext32s_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1223 tcg_gen_ext_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1224 tcg_gen_ext_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1226 tcg_gen_mul_i64(t0
, t0
, t1
);
1227 #if defined(TARGET_PPC64)
1228 tcg_gen_ext32s_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1229 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, cpu_gpr
[rD(ctx
->opcode
)], l1
);
1231 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1232 tcg_gen_ext32s_i64(t1
, t0
);
1233 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
1235 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1237 tcg_temp_free_i64(t0
);
1238 tcg_temp_free_i64(t1
);
1239 if (unlikely(Rc(ctx
->opcode
) != 0))
1240 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1243 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1245 tcg_gen_muli_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1248 #if defined(TARGET_PPC64)
1249 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
1250 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) \
1252 gen_helper_##name (cpu_gpr[rD(ctx->opcode)], \
1253 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
1254 if (unlikely(Rc(ctx->opcode) != 0)) \
1255 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1258 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00);
1259 /* mulhdu mulhdu. */
1260 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02);
1262 GEN_HANDLER(mulld
, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B
)
1264 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1265 cpu_gpr
[rB(ctx
->opcode
)]);
1266 if (unlikely(Rc(ctx
->opcode
) != 0))
1267 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1269 /* mulldo mulldo. */
1270 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17);
1273 /* neg neg. nego nego. */
1274 static always_inline
void gen_op_arith_neg (DisasContext
*ctx
, TCGv ret
, TCGv arg1
, int ov_check
)
1276 int l1
= gen_new_label();
1277 int l2
= gen_new_label();
1278 TCGv t0
= tcg_temp_local_new();
1279 #if defined(TARGET_PPC64)
1281 tcg_gen_mov_tl(t0
, arg1
);
1282 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, INT64_MIN
, l1
);
1286 tcg_gen_ext32s_tl(t0
, arg1
);
1287 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, INT32_MIN
, l1
);
1289 tcg_gen_neg_tl(ret
, arg1
);
1291 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1295 tcg_gen_mov_tl(ret
, t0
);
1297 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1301 if (unlikely(Rc(ctx
->opcode
) != 0))
1302 gen_set_Rc0(ctx
, ret
);
1304 GEN_HANDLER(neg
, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER
)
1306 gen_op_arith_neg(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0);
1308 GEN_HANDLER(nego
, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER
)
1310 gen_op_arith_neg(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 1);
1313 /* Common subf function */
1314 static always_inline
void gen_op_arith_subf(DisasContext
*ctx
, TCGv ret
, TCGv arg1
, TCGv arg2
,
1315 int add_ca
, int compute_ca
, int compute_ov
)
1319 if ((!compute_ca
&& !compute_ov
) ||
1320 (!TCGV_EQUAL(ret
, arg1
) && !TCGV_EQUAL(ret
, arg2
))) {
1323 t0
= tcg_temp_local_new();
1327 t1
= tcg_temp_local_new();
1328 tcg_gen_andi_tl(t1
, cpu_xer
, (1 << XER_CA
));
1329 tcg_gen_shri_tl(t1
, t1
, XER_CA
);
1332 if (compute_ca
&& compute_ov
) {
1333 /* Start with XER CA and OV disabled, the most likely case */
1334 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~((1 << XER_CA
) | (1 << XER_OV
)));
1335 } else if (compute_ca
) {
1336 /* Start with XER CA disabled, the most likely case */
1337 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1338 } else if (compute_ov
) {
1339 /* Start with XER OV disabled, the most likely case */
1340 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1344 tcg_gen_not_tl(t0
, arg1
);
1345 tcg_gen_add_tl(t0
, t0
, arg2
);
1346 gen_op_arith_compute_ca(ctx
, t0
, arg2
, 0);
1347 tcg_gen_add_tl(t0
, t0
, t1
);
1348 gen_op_arith_compute_ca(ctx
, t0
, t1
, 0);
1351 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1353 gen_op_arith_compute_ca(ctx
, t0
, arg2
, 1);
1357 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 1);
1360 if (unlikely(Rc(ctx
->opcode
) != 0))
1361 gen_set_Rc0(ctx
, t0
);
1363 if (!TCGV_EQUAL(t0
, ret
)) {
1364 tcg_gen_mov_tl(ret
, t0
);
1368 /* Sub functions with Two operands functions */
1369 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1370 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER) \
1372 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1373 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1374 add_ca, compute_ca, compute_ov); \
1376 /* Sub functions with one operand and one immediate */
1377 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1378 add_ca, compute_ca, compute_ov) \
1379 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER) \
1381 TCGv t0 = tcg_const_local_tl(const_val); \
1382 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1383 cpu_gpr[rA(ctx->opcode)], t0, \
1384 add_ca, compute_ca, compute_ov); \
1385 tcg_temp_free(t0); \
1387 /* subf subf. subfo subfo. */
1388 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
1389 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
1390 /* subfc subfc. subfco subfco. */
1391 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
1392 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
1393 /* subfe subfe. subfeo subfo. */
1394 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
1395 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
1396 /* subfme subfme. subfmeo subfmeo. */
1397 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
1398 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
1399 /* subfze subfze. subfzeo subfzeo.*/
1400 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
1401 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
1403 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1405 /* Start with XER CA and OV disabled, the most likely case */
1406 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1407 TCGv t0
= tcg_temp_local_new();
1408 TCGv t1
= tcg_const_local_tl(SIMM(ctx
->opcode
));
1409 tcg_gen_sub_tl(t0
, t1
, cpu_gpr
[rA(ctx
->opcode
)]);
1410 gen_op_arith_compute_ca(ctx
, t0
, t1
, 1);
1412 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1416 /*** Integer logical ***/
1417 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1418 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type) \
1420 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1421 cpu_gpr[rB(ctx->opcode)]); \
1422 if (unlikely(Rc(ctx->opcode) != 0)) \
1423 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1426 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1427 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type) \
1429 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1430 if (unlikely(Rc(ctx->opcode) != 0)) \
1431 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1435 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
);
1437 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
);
1439 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1441 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
));
1442 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1445 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1447 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
) << 16);
1448 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1451 GEN_HANDLER(cntlzw
, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER
)
1453 gen_helper_cntlzw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1454 if (unlikely(Rc(ctx
->opcode
) != 0))
1455 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1458 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
);
1459 /* extsb & extsb. */
1460 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
);
1461 /* extsh & extsh. */
1462 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
);
1464 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
);
1466 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
);
1468 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
)
1472 rs
= rS(ctx
->opcode
);
1473 ra
= rA(ctx
->opcode
);
1474 rb
= rB(ctx
->opcode
);
1475 /* Optimisation for mr. ri case */
1476 if (rs
!= ra
|| rs
!= rb
) {
1478 tcg_gen_or_tl(cpu_gpr
[ra
], cpu_gpr
[rs
], cpu_gpr
[rb
]);
1480 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rs
]);
1481 if (unlikely(Rc(ctx
->opcode
) != 0))
1482 gen_set_Rc0(ctx
, cpu_gpr
[ra
]);
1483 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
1484 gen_set_Rc0(ctx
, cpu_gpr
[rs
]);
1485 #if defined(TARGET_PPC64)
1491 /* Set process priority to low */
1495 /* Set process priority to medium-low */
1499 /* Set process priority to normal */
1502 #if !defined(CONFIG_USER_ONLY)
1504 if (ctx
->mem_idx
> 0) {
1505 /* Set process priority to very low */
1510 if (ctx
->mem_idx
> 0) {
1511 /* Set process priority to medium-hight */
1516 if (ctx
->mem_idx
> 0) {
1517 /* Set process priority to high */
1522 if (ctx
->mem_idx
> 1) {
1523 /* Set process priority to very high */
1533 TCGv t0
= tcg_temp_new();
1534 gen_load_spr(t0
, SPR_PPR
);
1535 tcg_gen_andi_tl(t0
, t0
, ~0x001C000000000000ULL
);
1536 tcg_gen_ori_tl(t0
, t0
, ((uint64_t)prio
) << 50);
1537 gen_store_spr(SPR_PPR
, t0
);
1544 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
);
1546 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
)
1548 /* Optimisation for "set to zero" case */
1549 if (rS(ctx
->opcode
) != rB(ctx
->opcode
))
1550 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1552 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1553 if (unlikely(Rc(ctx
->opcode
) != 0))
1554 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1557 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1559 target_ulong uimm
= UIMM(ctx
->opcode
);
1561 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1563 /* XXX: should handle special NOPs for POWER series */
1566 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1569 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1571 target_ulong uimm
= UIMM(ctx
->opcode
);
1573 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1577 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1580 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1582 target_ulong uimm
= UIMM(ctx
->opcode
);
1584 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1588 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1591 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1593 target_ulong uimm
= UIMM(ctx
->opcode
);
1595 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1599 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1601 /* popcntb : PowerPC 2.03 specification */
1602 GEN_HANDLER(popcntb
, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB
)
1604 #if defined(TARGET_PPC64)
1606 gen_helper_popcntb_64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1609 gen_helper_popcntb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1612 #if defined(TARGET_PPC64)
1613 /* extsw & extsw. */
1614 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
);
1616 GEN_HANDLER(cntlzd
, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B
)
1618 gen_helper_cntlzd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1619 if (unlikely(Rc(ctx
->opcode
) != 0))
1620 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1624 /*** Integer rotate ***/
1625 /* rlwimi & rlwimi. */
1626 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1628 uint32_t mb
, me
, sh
;
1630 mb
= MB(ctx
->opcode
);
1631 me
= ME(ctx
->opcode
);
1632 sh
= SH(ctx
->opcode
);
1633 if (likely(sh
== 0 && mb
== 0 && me
== 31)) {
1634 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1638 TCGv t0
= tcg_temp_new();
1639 #if defined(TARGET_PPC64)
1640 TCGv_i32 t2
= tcg_temp_new_i32();
1641 tcg_gen_trunc_i64_i32(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
1642 tcg_gen_rotli_i32(t2
, t2
, sh
);
1643 tcg_gen_extu_i32_i64(t0
, t2
);
1644 tcg_temp_free_i32(t2
);
1646 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1648 #if defined(TARGET_PPC64)
1652 mask
= MASK(mb
, me
);
1653 t1
= tcg_temp_new();
1654 tcg_gen_andi_tl(t0
, t0
, mask
);
1655 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1656 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1660 if (unlikely(Rc(ctx
->opcode
) != 0))
1661 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1663 /* rlwinm & rlwinm. */
1664 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1666 uint32_t mb
, me
, sh
;
1668 sh
= SH(ctx
->opcode
);
1669 mb
= MB(ctx
->opcode
);
1670 me
= ME(ctx
->opcode
);
1672 if (likely(mb
== 0 && me
== (31 - sh
))) {
1673 if (likely(sh
== 0)) {
1674 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1676 TCGv t0
= tcg_temp_new();
1677 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1678 tcg_gen_shli_tl(t0
, t0
, sh
);
1679 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1682 } else if (likely(sh
!= 0 && me
== 31 && sh
== (32 - mb
))) {
1683 TCGv t0
= tcg_temp_new();
1684 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1685 tcg_gen_shri_tl(t0
, t0
, mb
);
1686 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1689 TCGv t0
= tcg_temp_new();
1690 #if defined(TARGET_PPC64)
1691 TCGv_i32 t1
= tcg_temp_new_i32();
1692 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1693 tcg_gen_rotli_i32(t1
, t1
, sh
);
1694 tcg_gen_extu_i32_i64(t0
, t1
);
1695 tcg_temp_free_i32(t1
);
1697 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1699 #if defined(TARGET_PPC64)
1703 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1706 if (unlikely(Rc(ctx
->opcode
) != 0))
1707 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1709 /* rlwnm & rlwnm. */
1710 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1714 #if defined(TARGET_PPC64)
1718 mb
= MB(ctx
->opcode
);
1719 me
= ME(ctx
->opcode
);
1720 t0
= tcg_temp_new();
1721 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1722 #if defined(TARGET_PPC64)
1723 t1
= tcg_temp_new_i32();
1724 t2
= tcg_temp_new_i32();
1725 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1726 tcg_gen_trunc_i64_i32(t2
, t0
);
1727 tcg_gen_rotl_i32(t1
, t1
, t2
);
1728 tcg_gen_extu_i32_i64(t0
, t1
);
1729 tcg_temp_free_i32(t1
);
1730 tcg_temp_free_i32(t2
);
1732 tcg_gen_rotl_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1734 if (unlikely(mb
!= 0 || me
!= 31)) {
1735 #if defined(TARGET_PPC64)
1739 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1741 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1744 if (unlikely(Rc(ctx
->opcode
) != 0))
1745 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1748 #if defined(TARGET_PPC64)
1749 #define GEN_PPC64_R2(name, opc1, opc2) \
1750 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1752 gen_##name(ctx, 0); \
1754 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1757 gen_##name(ctx, 1); \
1759 #define GEN_PPC64_R4(name, opc1, opc2) \
1760 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1762 gen_##name(ctx, 0, 0); \
1764 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
1767 gen_##name(ctx, 0, 1); \
1769 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1772 gen_##name(ctx, 1, 0); \
1774 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
1777 gen_##name(ctx, 1, 1); \
1780 static always_inline
void gen_rldinm (DisasContext
*ctx
, uint32_t mb
,
1781 uint32_t me
, uint32_t sh
)
1783 if (likely(sh
!= 0 && mb
== 0 && me
== (63 - sh
))) {
1784 tcg_gen_shli_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
1785 } else if (likely(sh
!= 0 && me
== 63 && sh
== (64 - mb
))) {
1786 tcg_gen_shri_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], mb
);
1788 TCGv t0
= tcg_temp_new();
1789 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1790 if (likely(mb
== 0 && me
== 63)) {
1791 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1793 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1797 if (unlikely(Rc(ctx
->opcode
) != 0))
1798 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1800 /* rldicl - rldicl. */
1801 static always_inline
void gen_rldicl (DisasContext
*ctx
, int mbn
, int shn
)
1805 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1806 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1807 gen_rldinm(ctx
, mb
, 63, sh
);
1809 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
1810 /* rldicr - rldicr. */
1811 static always_inline
void gen_rldicr (DisasContext
*ctx
, int men
, int shn
)
1815 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1816 me
= MB(ctx
->opcode
) | (men
<< 5);
1817 gen_rldinm(ctx
, 0, me
, sh
);
1819 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
1820 /* rldic - rldic. */
1821 static always_inline
void gen_rldic (DisasContext
*ctx
, int mbn
, int shn
)
1825 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1826 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1827 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
1829 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
1831 static always_inline
void gen_rldnm (DisasContext
*ctx
, uint32_t mb
,
1836 mb
= MB(ctx
->opcode
);
1837 me
= ME(ctx
->opcode
);
1838 t0
= tcg_temp_new();
1839 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1840 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1841 if (unlikely(mb
!= 0 || me
!= 63)) {
1842 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1844 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1847 if (unlikely(Rc(ctx
->opcode
) != 0))
1848 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1851 /* rldcl - rldcl. */
1852 static always_inline
void gen_rldcl (DisasContext
*ctx
, int mbn
)
1856 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1857 gen_rldnm(ctx
, mb
, 63);
1859 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
1860 /* rldcr - rldcr. */
1861 static always_inline
void gen_rldcr (DisasContext
*ctx
, int men
)
1865 me
= MB(ctx
->opcode
) | (men
<< 5);
1866 gen_rldnm(ctx
, 0, me
);
1868 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
1869 /* rldimi - rldimi. */
1870 static always_inline
void gen_rldimi (DisasContext
*ctx
, int mbn
, int shn
)
1872 uint32_t sh
, mb
, me
;
1874 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1875 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1877 if (unlikely(sh
== 0 && mb
== 0)) {
1878 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1883 t0
= tcg_temp_new();
1884 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1885 t1
= tcg_temp_new();
1886 mask
= MASK(mb
, me
);
1887 tcg_gen_andi_tl(t0
, t0
, mask
);
1888 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1889 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1893 if (unlikely(Rc(ctx
->opcode
) != 0))
1894 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1896 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
1899 /*** Integer shift ***/
1901 GEN_HANDLER(slw
, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER
)
1905 l1
= gen_new_label();
1906 l2
= gen_new_label();
1908 t0
= tcg_temp_local_new();
1909 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1910 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0x20, l1
);
1911 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1914 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t0
);
1915 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
1918 if (unlikely(Rc(ctx
->opcode
) != 0))
1919 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1922 GEN_HANDLER(sraw
, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER
)
1924 gen_helper_sraw(cpu_gpr
[rA(ctx
->opcode
)],
1925 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1926 if (unlikely(Rc(ctx
->opcode
) != 0))
1927 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1929 /* srawi & srawi. */
1930 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
)
1932 int sh
= SH(ctx
->opcode
);
1936 l1
= gen_new_label();
1937 l2
= gen_new_label();
1938 t0
= tcg_temp_local_new();
1939 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1940 tcg_gen_brcondi_tl(TCG_COND_GE
, t0
, 0, l1
);
1941 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1ULL << sh
) - 1);
1942 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
1943 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
1946 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1948 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1949 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, sh
);
1952 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1953 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1955 if (unlikely(Rc(ctx
->opcode
) != 0))
1956 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1959 GEN_HANDLER(srw
, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER
)
1963 l1
= gen_new_label();
1964 l2
= gen_new_label();
1966 t0
= tcg_temp_local_new();
1967 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1968 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0x20, l1
);
1969 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1972 t1
= tcg_temp_new();
1973 tcg_gen_ext32u_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1974 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
, t0
);
1978 if (unlikely(Rc(ctx
->opcode
) != 0))
1979 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1981 #if defined(TARGET_PPC64)
1983 GEN_HANDLER(sld
, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B
)
1987 l1
= gen_new_label();
1988 l2
= gen_new_label();
1990 t0
= tcg_temp_local_new();
1991 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x7f);
1992 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0x40, l1
);
1993 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1996 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t0
);
1999 if (unlikely(Rc(ctx
->opcode
) != 0))
2000 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2003 GEN_HANDLER(srad
, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B
)
2005 gen_helper_srad(cpu_gpr
[rA(ctx
->opcode
)],
2006 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2007 if (unlikely(Rc(ctx
->opcode
) != 0))
2008 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2010 /* sradi & sradi. */
2011 static always_inline
void gen_sradi (DisasContext
*ctx
, int n
)
2013 int sh
= SH(ctx
->opcode
) + (n
<< 5);
2017 l1
= gen_new_label();
2018 l2
= gen_new_label();
2019 t0
= tcg_temp_local_new();
2020 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
2021 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1ULL << sh
) - 1);
2022 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2023 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
2026 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
2029 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
2031 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
2032 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
2034 if (unlikely(Rc(ctx
->opcode
) != 0))
2035 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2037 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
)
2041 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
)
2046 GEN_HANDLER(srd
, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B
)
2050 l1
= gen_new_label();
2051 l2
= gen_new_label();
2053 t0
= tcg_temp_local_new();
2054 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x7f);
2055 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0x40, l1
);
2056 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
2059 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t0
);
2062 if (unlikely(Rc(ctx
->opcode
) != 0))
2063 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2067 /*** Floating-Point arithmetic ***/
2068 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
2069 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type) \
2071 if (unlikely(!ctx->fpu_enabled)) { \
2072 gen_exception(ctx, POWERPC_EXCP_FPU); \
2075 /* NIP cannot be restored if the memory exception comes from an helper */ \
2076 gen_update_nip(ctx, ctx->nip - 4); \
2077 gen_reset_fpstatus(); \
2078 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], \
2079 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2081 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]); \
2083 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \
2084 Rc(ctx->opcode) != 0); \
2087 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2088 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2089 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
2091 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2092 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
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_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], \
2102 cpu_fpr[rB(ctx->opcode)]); \
2104 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]); \
2106 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2107 set_fprf, Rc(ctx->opcode) != 0); \
2109 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2110 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2111 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2113 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2114 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
2116 if (unlikely(!ctx->fpu_enabled)) { \
2117 gen_exception(ctx, POWERPC_EXCP_FPU); \
2120 /* NIP cannot be restored if the memory exception comes from an helper */ \
2121 gen_update_nip(ctx, ctx->nip - 4); \
2122 gen_reset_fpstatus(); \
2123 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], \
2124 cpu_fpr[rC(ctx->opcode)]); \
2126 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]); \
2128 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2129 set_fprf, Rc(ctx->opcode) != 0); \
2131 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2132 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2133 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2135 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
2136 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type) \
2138 if (unlikely(!ctx->fpu_enabled)) { \
2139 gen_exception(ctx, POWERPC_EXCP_FPU); \
2142 /* NIP cannot be restored if the memory exception comes from an helper */ \
2143 gen_update_nip(ctx, ctx->nip - 4); \
2144 gen_reset_fpstatus(); \
2145 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2146 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2147 set_fprf, Rc(ctx->opcode) != 0); \
2150 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
2151 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type) \
2153 if (unlikely(!ctx->fpu_enabled)) { \
2154 gen_exception(ctx, POWERPC_EXCP_FPU); \
2157 /* NIP cannot be restored if the memory exception comes from an helper */ \
2158 gen_update_nip(ctx, ctx->nip - 4); \
2159 gen_reset_fpstatus(); \
2160 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2161 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2162 set_fprf, Rc(ctx->opcode) != 0); \
2166 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
);
2168 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
);
2170 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
);
2173 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
);
2176 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
);
2179 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
);
2182 GEN_HANDLER(frsqrtes
, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES
)
2184 if (unlikely(!ctx
->fpu_enabled
)) {
2185 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2188 /* NIP cannot be restored if the memory exception comes from an helper */
2189 gen_update_nip(ctx
, ctx
->nip
- 4);
2190 gen_reset_fpstatus();
2191 gen_helper_frsqrte(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2192 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rD(ctx
->opcode
)]);
2193 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2197 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
);
2199 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
);
2202 GEN_HANDLER(fsqrt
, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
)
2204 if (unlikely(!ctx
->fpu_enabled
)) {
2205 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2208 /* NIP cannot be restored if the memory exception comes from an helper */
2209 gen_update_nip(ctx
, ctx
->nip
- 4);
2210 gen_reset_fpstatus();
2211 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2212 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2215 GEN_HANDLER(fsqrts
, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
)
2217 if (unlikely(!ctx
->fpu_enabled
)) {
2218 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2221 /* NIP cannot be restored if the memory exception comes from an helper */
2222 gen_update_nip(ctx
, ctx
->nip
- 4);
2223 gen_reset_fpstatus();
2224 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2225 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rD(ctx
->opcode
)]);
2226 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2229 /*** Floating-Point multiply-and-add ***/
2230 /* fmadd - fmadds */
2231 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
);
2232 /* fmsub - fmsubs */
2233 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
);
2234 /* fnmadd - fnmadds */
2235 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
);
2236 /* fnmsub - fnmsubs */
2237 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
);
2239 /*** Floating-Point round & convert ***/
2241 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
);
2243 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
);
2245 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
);
2246 #if defined(TARGET_PPC64)
2248 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
);
2250 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
);
2252 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
);
2256 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
);
2258 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
);
2260 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
);
2262 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
);
2264 /*** Floating-Point compare ***/
2266 GEN_HANDLER(fcmpo
, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT
)
2269 if (unlikely(!ctx
->fpu_enabled
)) {
2270 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2273 /* NIP cannot be restored if the memory exception comes from an helper */
2274 gen_update_nip(ctx
, ctx
->nip
- 4);
2275 gen_reset_fpstatus();
2276 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2277 gen_helper_fcmpo(cpu_fpr
[rA(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)], crf
);
2278 tcg_temp_free_i32(crf
);
2279 gen_helper_float_check_status();
2283 GEN_HANDLER(fcmpu
, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT
)
2286 if (unlikely(!ctx
->fpu_enabled
)) {
2287 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2290 /* NIP cannot be restored if the memory exception comes from an helper */
2291 gen_update_nip(ctx
, ctx
->nip
- 4);
2292 gen_reset_fpstatus();
2293 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2294 gen_helper_fcmpu(cpu_fpr
[rA(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)], crf
);
2295 tcg_temp_free_i32(crf
);
2296 gen_helper_float_check_status();
2299 /*** Floating-point move ***/
2301 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2302 GEN_FLOAT_B(abs
, 0x08, 0x08, 0, PPC_FLOAT
);
2305 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2306 GEN_HANDLER(fmr
, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT
)
2308 if (unlikely(!ctx
->fpu_enabled
)) {
2309 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2312 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2313 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2317 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2318 GEN_FLOAT_B(nabs
, 0x08, 0x04, 0, PPC_FLOAT
);
2320 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2321 GEN_FLOAT_B(neg
, 0x08, 0x01, 0, PPC_FLOAT
);
2323 /*** Floating-Point status & ctrl register ***/
2325 GEN_HANDLER(mcrfs
, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT
)
2329 if (unlikely(!ctx
->fpu_enabled
)) {
2330 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2333 bfa
= 4 * (7 - crfS(ctx
->opcode
));
2334 tcg_gen_shri_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_fpscr
, bfa
);
2335 tcg_gen_andi_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfD(ctx
->opcode
)], 0xf);
2336 tcg_gen_andi_i32(cpu_fpscr
, cpu_fpscr
, ~(0xF << bfa
));
2340 GEN_HANDLER(mffs
, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT
)
2342 if (unlikely(!ctx
->fpu_enabled
)) {
2343 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2346 gen_reset_fpstatus();
2347 tcg_gen_extu_i32_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpscr
);
2348 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2352 GEN_HANDLER(mtfsb0
, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT
)
2356 if (unlikely(!ctx
->fpu_enabled
)) {
2357 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2360 crb
= 31 - crbD(ctx
->opcode
);
2361 gen_reset_fpstatus();
2362 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
)) {
2364 /* NIP cannot be restored if the memory exception comes from an helper */
2365 gen_update_nip(ctx
, ctx
->nip
- 4);
2366 t0
= tcg_const_i32(crb
);
2367 gen_helper_fpscr_clrbit(t0
);
2368 tcg_temp_free_i32(t0
);
2370 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2371 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2376 GEN_HANDLER(mtfsb1
, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT
)
2380 if (unlikely(!ctx
->fpu_enabled
)) {
2381 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2384 crb
= 31 - crbD(ctx
->opcode
);
2385 gen_reset_fpstatus();
2386 /* XXX: we pretend we can only do IEEE floating-point computations */
2387 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
&& crb
!= FPSCR_NI
)) {
2389 /* NIP cannot be restored if the memory exception comes from an helper */
2390 gen_update_nip(ctx
, ctx
->nip
- 4);
2391 t0
= tcg_const_i32(crb
);
2392 gen_helper_fpscr_setbit(t0
);
2393 tcg_temp_free_i32(t0
);
2395 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2396 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2398 /* We can raise a differed exception */
2399 gen_helper_float_check_status();
2403 GEN_HANDLER(mtfsf
, 0x3F, 0x07, 0x16, 0x02010000, PPC_FLOAT
)
2407 if (unlikely(!ctx
->fpu_enabled
)) {
2408 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2411 /* NIP cannot be restored if the memory exception comes from an helper */
2412 gen_update_nip(ctx
, ctx
->nip
- 4);
2413 gen_reset_fpstatus();
2414 t0
= tcg_const_i32(FM(ctx
->opcode
));
2415 gen_helper_store_fpscr(cpu_fpr
[rB(ctx
->opcode
)], t0
);
2416 tcg_temp_free_i32(t0
);
2417 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2418 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2420 /* We can raise a differed exception */
2421 gen_helper_float_check_status();
2425 GEN_HANDLER(mtfsfi
, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT
)
2431 if (unlikely(!ctx
->fpu_enabled
)) {
2432 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2435 bf
= crbD(ctx
->opcode
) >> 2;
2437 /* NIP cannot be restored if the memory exception comes from an helper */
2438 gen_update_nip(ctx
, ctx
->nip
- 4);
2439 gen_reset_fpstatus();
2440 t0
= tcg_const_i64(FPIMM(ctx
->opcode
) << (4 * sh
));
2441 t1
= tcg_const_i32(1 << sh
);
2442 gen_helper_store_fpscr(t0
, t1
);
2443 tcg_temp_free_i64(t0
);
2444 tcg_temp_free_i32(t1
);
2445 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2446 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2448 /* We can raise a differed exception */
2449 gen_helper_float_check_status();
2452 /*** Addressing modes ***/
2453 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2454 static always_inline
void gen_addr_imm_index (DisasContext
*ctx
, TCGv EA
, target_long maskl
)
2456 target_long simm
= SIMM(ctx
->opcode
);
2459 if (rA(ctx
->opcode
) == 0) {
2460 #if defined(TARGET_PPC64)
2461 if (!ctx
->sf_mode
) {
2462 tcg_gen_movi_tl(EA
, (uint32_t)simm
);
2465 tcg_gen_movi_tl(EA
, simm
);
2466 } else if (likely(simm
!= 0)) {
2467 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
);
2468 #if defined(TARGET_PPC64)
2469 if (!ctx
->sf_mode
) {
2470 tcg_gen_ext32u_tl(EA
, EA
);
2474 #if defined(TARGET_PPC64)
2475 if (!ctx
->sf_mode
) {
2476 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2479 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2483 static always_inline
void gen_addr_reg_index (DisasContext
*ctx
, TCGv EA
)
2485 if (rA(ctx
->opcode
) == 0) {
2486 #if defined(TARGET_PPC64)
2487 if (!ctx
->sf_mode
) {
2488 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2491 tcg_gen_mov_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2493 tcg_gen_add_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2494 #if defined(TARGET_PPC64)
2495 if (!ctx
->sf_mode
) {
2496 tcg_gen_ext32u_tl(EA
, EA
);
2502 static always_inline
void gen_addr_register (DisasContext
*ctx
, TCGv EA
)
2504 if (rA(ctx
->opcode
) == 0) {
2505 tcg_gen_movi_tl(EA
, 0);
2507 #if defined(TARGET_PPC64)
2508 if (!ctx
->sf_mode
) {
2509 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2512 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2516 static always_inline
void gen_addr_add (DisasContext
*ctx
, TCGv ret
, TCGv arg1
, target_long val
)
2518 tcg_gen_addi_tl(ret
, arg1
, val
);
2519 #if defined(TARGET_PPC64)
2520 if (!ctx
->sf_mode
) {
2521 tcg_gen_ext32u_tl(ret
, ret
);
2526 static always_inline
void gen_check_align (DisasContext
*ctx
, TCGv EA
, int mask
)
2528 int l1
= gen_new_label();
2529 TCGv t0
= tcg_temp_new();
2531 /* NIP cannot be restored if the memory exception comes from an helper */
2532 gen_update_nip(ctx
, ctx
->nip
- 4);
2533 tcg_gen_andi_tl(t0
, EA
, mask
);
2534 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2535 t1
= tcg_const_i32(POWERPC_EXCP_ALIGN
);
2536 t2
= tcg_const_i32(0);
2537 gen_helper_raise_exception_err(t1
, t2
);
2538 tcg_temp_free_i32(t1
);
2539 tcg_temp_free_i32(t2
);
2544 /*** Integer load ***/
2545 static always_inline
void gen_qemu_ld8u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2547 tcg_gen_qemu_ld8u(arg1
, arg2
, ctx
->mem_idx
);
2550 static always_inline
void gen_qemu_ld8s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2552 tcg_gen_qemu_ld8s(arg1
, arg2
, ctx
->mem_idx
);
2555 static always_inline
void gen_qemu_ld16u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2557 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2558 if (unlikely(ctx
->le_mode
)) {
2559 #if defined(TARGET_PPC64)
2560 TCGv_i32 t0
= tcg_temp_new_i32();
2561 tcg_gen_trunc_tl_i32(t0
, arg1
);
2562 tcg_gen_bswap16_i32(t0
, t0
);
2563 tcg_gen_extu_i32_tl(arg1
, t0
);
2564 tcg_temp_free_i32(t0
);
2566 tcg_gen_bswap16_i32(arg1
, arg1
);
2571 static always_inline
void gen_qemu_ld16s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2573 if (unlikely(ctx
->le_mode
)) {
2574 #if defined(TARGET_PPC64)
2576 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2577 t0
= tcg_temp_new_i32();
2578 tcg_gen_trunc_tl_i32(t0
, arg1
);
2579 tcg_gen_bswap16_i32(t0
, t0
);
2580 tcg_gen_extu_i32_tl(arg1
, t0
);
2581 tcg_gen_ext16s_tl(arg1
, arg1
);
2582 tcg_temp_free_i32(t0
);
2584 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2585 tcg_gen_bswap16_i32(arg1
, arg1
);
2586 tcg_gen_ext16s_i32(arg1
, arg1
);
2589 tcg_gen_qemu_ld16s(arg1
, arg2
, ctx
->mem_idx
);
2593 static always_inline
void gen_qemu_ld32u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2595 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2596 if (unlikely(ctx
->le_mode
)) {
2597 #if defined(TARGET_PPC64)
2598 TCGv_i32 t0
= tcg_temp_new_i32();
2599 tcg_gen_trunc_tl_i32(t0
, arg1
);
2600 tcg_gen_bswap_i32(t0
, t0
);
2601 tcg_gen_extu_i32_tl(arg1
, t0
);
2602 tcg_temp_free_i32(t0
);
2604 tcg_gen_bswap_i32(arg1
, arg1
);
2609 #if defined(TARGET_PPC64)
2610 static always_inline
void gen_qemu_ld32s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2612 if (unlikely(ctx
->mem_idx
)) {
2614 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2615 t0
= tcg_temp_new_i32();
2616 tcg_gen_trunc_tl_i32(t0
, arg1
);
2617 tcg_gen_bswap_i32(t0
, t0
);
2618 tcg_gen_ext_i32_tl(arg1
, t0
);
2619 tcg_temp_free_i32(t0
);
2621 tcg_gen_qemu_ld32s(arg1
, arg2
, ctx
->mem_idx
);
2625 static always_inline
void gen_qemu_ld64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2627 tcg_gen_qemu_ld64(arg1
, arg2
, ctx
->mem_idx
);
2628 if (unlikely(ctx
->le_mode
)) {
2629 tcg_gen_bswap_i64(arg1
, arg1
);
2633 static always_inline
void gen_qemu_st8(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2635 tcg_gen_qemu_st8(arg1
, arg2
, ctx
->mem_idx
);
2638 static always_inline
void gen_qemu_st16(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2640 if (unlikely(ctx
->le_mode
)) {
2641 #if defined(TARGET_PPC64)
2644 t0
= tcg_temp_new_i32();
2645 tcg_gen_trunc_tl_i32(t0
, arg1
);
2646 tcg_gen_ext16u_i32(t0
, t0
);
2647 tcg_gen_bswap16_i32(t0
, t0
);
2648 t1
= tcg_temp_new();
2649 tcg_gen_extu_i32_tl(t1
, t0
);
2650 tcg_temp_free_i32(t0
);
2651 tcg_gen_qemu_st16(t1
, arg2
, ctx
->mem_idx
);
2654 TCGv t0
= tcg_temp_new();
2655 tcg_gen_ext16u_tl(t0
, arg1
);
2656 tcg_gen_bswap16_i32(t0
, t0
);
2657 tcg_gen_qemu_st16(t0
, arg2
, ctx
->mem_idx
);
2661 tcg_gen_qemu_st16(arg1
, arg2
, ctx
->mem_idx
);
2665 static always_inline
void gen_qemu_st32(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2667 if (unlikely(ctx
->le_mode
)) {
2668 #if defined(TARGET_PPC64)
2671 t0
= tcg_temp_new_i32();
2672 tcg_gen_trunc_tl_i32(t0
, arg1
);
2673 tcg_gen_bswap_i32(t0
, t0
);
2674 t1
= tcg_temp_new();
2675 tcg_gen_extu_i32_tl(t1
, t0
);
2676 tcg_temp_free_i32(t0
);
2677 tcg_gen_qemu_st32(t1
, arg2
, ctx
->mem_idx
);
2680 TCGv t0
= tcg_temp_new_i32();
2681 tcg_gen_bswap_i32(t0
, arg1
);
2682 tcg_gen_qemu_st32(t0
, arg2
, ctx
->mem_idx
);
2686 tcg_gen_qemu_st32(arg1
, arg2
, ctx
->mem_idx
);
2690 static always_inline
void gen_qemu_st64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2692 if (unlikely(ctx
->le_mode
)) {
2693 TCGv_i64 t0
= tcg_temp_new_i64();
2694 tcg_gen_bswap_i64(t0
, arg1
);
2695 tcg_gen_qemu_st64(t0
, arg2
, ctx
->mem_idx
);
2696 tcg_temp_free_i64(t0
);
2698 tcg_gen_qemu_st64(arg1
, arg2
, ctx
->mem_idx
);
2701 #define GEN_LD(name, ldop, opc, type) \
2702 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type) \
2705 gen_set_access_type(ctx, ACCESS_INT); \
2706 EA = tcg_temp_new(); \
2707 gen_addr_imm_index(ctx, EA, 0); \
2708 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2709 tcg_temp_free(EA); \
2712 #define GEN_LDU(name, ldop, opc, type) \
2713 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2716 if (unlikely(rA(ctx->opcode) == 0 || \
2717 rA(ctx->opcode) == rD(ctx->opcode))) { \
2718 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2721 gen_set_access_type(ctx, ACCESS_INT); \
2722 EA = tcg_temp_new(); \
2723 if (type == PPC_64B) \
2724 gen_addr_imm_index(ctx, EA, 0x03); \
2726 gen_addr_imm_index(ctx, EA, 0); \
2727 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2728 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2729 tcg_temp_free(EA); \
2732 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
2733 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2736 if (unlikely(rA(ctx->opcode) == 0 || \
2737 rA(ctx->opcode) == rD(ctx->opcode))) { \
2738 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2741 gen_set_access_type(ctx, ACCESS_INT); \
2742 EA = tcg_temp_new(); \
2743 gen_addr_reg_index(ctx, EA); \
2744 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2745 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2746 tcg_temp_free(EA); \
2749 #define GEN_LDX(name, ldop, opc2, opc3, type) \
2750 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type) \
2753 gen_set_access_type(ctx, ACCESS_INT); \
2754 EA = tcg_temp_new(); \
2755 gen_addr_reg_index(ctx, EA); \
2756 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2757 tcg_temp_free(EA); \
2760 #define GEN_LDS(name, ldop, op, type) \
2761 GEN_LD(name, ldop, op | 0x20, type); \
2762 GEN_LDU(name, ldop, op | 0x21, type); \
2763 GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2764 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
2766 /* lbz lbzu lbzux lbzx */
2767 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
);
2768 /* lha lhau lhaux lhax */
2769 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
);
2770 /* lhz lhzu lhzux lhzx */
2771 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
);
2772 /* lwz lwzu lwzux lwzx */
2773 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
);
2774 #if defined(TARGET_PPC64)
2776 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
);
2778 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
);
2780 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
);
2782 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
);
2783 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
)
2786 if (Rc(ctx
->opcode
)) {
2787 if (unlikely(rA(ctx
->opcode
) == 0 ||
2788 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
2789 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2793 gen_set_access_type(ctx
, ACCESS_INT
);
2794 EA
= tcg_temp_new();
2795 gen_addr_imm_index(ctx
, EA
, 0x03);
2796 if (ctx
->opcode
& 0x02) {
2797 /* lwa (lwau is undefined) */
2798 gen_qemu_ld32s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2801 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2803 if (Rc(ctx
->opcode
))
2804 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2808 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
)
2810 #if defined(CONFIG_USER_ONLY)
2811 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2816 /* Restore CPU state */
2817 if (unlikely(ctx
->mem_idx
== 0)) {
2818 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2821 ra
= rA(ctx
->opcode
);
2822 rd
= rD(ctx
->opcode
);
2823 if (unlikely((rd
& 1) || rd
== ra
)) {
2824 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2827 if (unlikely(ctx
->le_mode
)) {
2828 /* Little-endian mode is not handled */
2829 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2832 gen_set_access_type(ctx
, ACCESS_INT
);
2833 EA
= tcg_temp_new();
2834 gen_addr_imm_index(ctx
, EA
, 0x0F);
2835 gen_qemu_ld64(ctx
, cpu_gpr
[rd
], EA
);
2836 gen_addr_add(ctx
, EA
, EA
, 8);
2837 gen_qemu_ld64(ctx
, cpu_gpr
[rd
+1], EA
);
2843 /*** Integer store ***/
2844 #define GEN_ST(name, stop, opc, type) \
2845 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type) \
2848 gen_set_access_type(ctx, ACCESS_INT); \
2849 EA = tcg_temp_new(); \
2850 gen_addr_imm_index(ctx, EA, 0); \
2851 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2852 tcg_temp_free(EA); \
2855 #define GEN_STU(name, stop, opc, type) \
2856 GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2859 if (unlikely(rA(ctx->opcode) == 0)) { \
2860 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2863 gen_set_access_type(ctx, ACCESS_INT); \
2864 EA = tcg_temp_new(); \
2865 if (type == PPC_64B) \
2866 gen_addr_imm_index(ctx, EA, 0x03); \
2868 gen_addr_imm_index(ctx, EA, 0); \
2869 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2870 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2871 tcg_temp_free(EA); \
2874 #define GEN_STUX(name, stop, opc2, opc3, type) \
2875 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2878 if (unlikely(rA(ctx->opcode) == 0)) { \
2879 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2882 gen_set_access_type(ctx, ACCESS_INT); \
2883 EA = tcg_temp_new(); \
2884 gen_addr_reg_index(ctx, EA); \
2885 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2886 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2887 tcg_temp_free(EA); \
2890 #define GEN_STX(name, stop, opc2, opc3, type) \
2891 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type) \
2894 gen_set_access_type(ctx, ACCESS_INT); \
2895 EA = tcg_temp_new(); \
2896 gen_addr_reg_index(ctx, EA); \
2897 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2898 tcg_temp_free(EA); \
2901 #define GEN_STS(name, stop, op, type) \
2902 GEN_ST(name, stop, op | 0x20, type); \
2903 GEN_STU(name, stop, op | 0x21, type); \
2904 GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2905 GEN_STX(name, stop, 0x17, op | 0x00, type)
2907 /* stb stbu stbux stbx */
2908 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
);
2909 /* sth sthu sthux sthx */
2910 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
);
2911 /* stw stwu stwux stwx */
2912 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
);
2913 #if defined(TARGET_PPC64)
2914 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
);
2915 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
);
2916 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
)
2921 rs
= rS(ctx
->opcode
);
2922 if ((ctx
->opcode
& 0x3) == 0x2) {
2923 #if defined(CONFIG_USER_ONLY)
2924 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2927 if (unlikely(ctx
->mem_idx
== 0)) {
2928 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2931 if (unlikely(rs
& 1)) {
2932 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2935 if (unlikely(ctx
->le_mode
)) {
2936 /* Little-endian mode is not handled */
2937 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2940 gen_set_access_type(ctx
, ACCESS_INT
);
2941 EA
= tcg_temp_new();
2942 gen_addr_imm_index(ctx
, EA
, 0x03);
2943 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
2944 gen_addr_add(ctx
, EA
, EA
, 8);
2945 gen_qemu_st64(ctx
, cpu_gpr
[rs
+1], EA
);
2950 if (Rc(ctx
->opcode
)) {
2951 if (unlikely(rA(ctx
->opcode
) == 0)) {
2952 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2956 gen_set_access_type(ctx
, ACCESS_INT
);
2957 EA
= tcg_temp_new();
2958 gen_addr_imm_index(ctx
, EA
, 0x03);
2959 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
2960 if (Rc(ctx
->opcode
))
2961 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2966 /*** Integer load and store with byte reverse ***/
2968 static void always_inline
gen_qemu_ld16ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2970 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2971 if (likely(!ctx
->le_mode
)) {
2972 #if defined(TARGET_PPC64)
2973 TCGv_i32 t0
= tcg_temp_new_i32();
2974 tcg_gen_trunc_tl_i32(t0
, arg1
);
2975 tcg_gen_bswap16_i32(t0
, t0
);
2976 tcg_gen_extu_i32_tl(arg1
, t0
);
2977 tcg_temp_free_i32(t0
);
2979 tcg_gen_bswap16_i32(arg1
, arg1
);
2983 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
);
2986 static void always_inline
gen_qemu_ld32ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2988 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2989 if (likely(!ctx
->le_mode
)) {
2990 #if defined(TARGET_PPC64)
2991 TCGv_i32 t0
= tcg_temp_new_i32();
2992 tcg_gen_trunc_tl_i32(t0
, arg1
);
2993 tcg_gen_bswap_i32(t0
, t0
);
2994 tcg_gen_extu_i32_tl(arg1
, t0
);
2995 tcg_temp_free_i32(t0
);
2997 tcg_gen_bswap_i32(arg1
, arg1
);
3001 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
);
3004 static void always_inline
gen_qemu_st16r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3006 if (likely(!ctx
->le_mode
)) {
3007 #if defined(TARGET_PPC64)
3010 t0
= tcg_temp_new_i32();
3011 tcg_gen_trunc_tl_i32(t0
, arg1
);
3012 tcg_gen_ext16u_i32(t0
, t0
);
3013 tcg_gen_bswap16_i32(t0
, t0
);
3014 t1
= tcg_temp_new();
3015 tcg_gen_extu_i32_tl(t1
, t0
);
3016 tcg_temp_free_i32(t0
);
3017 tcg_gen_qemu_st16(t1
, arg2
, ctx
->mem_idx
);
3020 TCGv t0
= tcg_temp_new();
3021 tcg_gen_ext16u_tl(t0
, arg1
);
3022 tcg_gen_bswap16_i32(t0
, t0
);
3023 tcg_gen_qemu_st16(t0
, arg2
, ctx
->mem_idx
);
3027 tcg_gen_qemu_st16(arg1
, arg2
, ctx
->mem_idx
);
3030 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
);
3033 static void always_inline
gen_qemu_st32r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3035 if (likely(!ctx
->le_mode
)) {
3036 #if defined(TARGET_PPC64)
3039 t0
= tcg_temp_new_i32();
3040 tcg_gen_trunc_tl_i32(t0
, arg1
);
3041 tcg_gen_bswap_i32(t0
, t0
);
3042 t1
= tcg_temp_new();
3043 tcg_gen_extu_i32_tl(t1
, t0
);
3044 tcg_temp_free_i32(t0
);
3045 tcg_gen_qemu_st32(t1
, arg2
, ctx
->mem_idx
);
3048 TCGv t0
= tcg_temp_new_i32();
3049 tcg_gen_bswap_i32(t0
, arg1
);
3050 tcg_gen_qemu_st32(t0
, arg2
, ctx
->mem_idx
);
3054 tcg_gen_qemu_st32(arg1
, arg2
, ctx
->mem_idx
);
3057 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
);
3059 /*** Integer load and store multiple ***/
3061 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
3065 gen_set_access_type(ctx
, ACCESS_INT
);
3066 /* NIP cannot be restored if the memory exception comes from an helper */
3067 gen_update_nip(ctx
, ctx
->nip
- 4);
3068 t0
= tcg_temp_new();
3069 t1
= tcg_const_i32(rD(ctx
->opcode
));
3070 gen_addr_imm_index(ctx
, t0
, 0);
3071 gen_helper_lmw(t0
, t1
);
3073 tcg_temp_free_i32(t1
);
3077 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
3081 gen_set_access_type(ctx
, ACCESS_INT
);
3082 /* NIP cannot be restored if the memory exception comes from an helper */
3083 gen_update_nip(ctx
, ctx
->nip
- 4);
3084 t0
= tcg_temp_new();
3085 t1
= tcg_const_i32(rS(ctx
->opcode
));
3086 gen_addr_imm_index(ctx
, t0
, 0);
3087 gen_helper_stmw(t0
, t1
);
3089 tcg_temp_free_i32(t1
);
3092 /*** Integer load and store strings ***/
3094 /* PowerPC32 specification says we must generate an exception if
3095 * rA is in the range of registers to be loaded.
3096 * In an other hand, IBM says this is valid, but rA won't be loaded.
3097 * For now, I'll follow the spec...
3099 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
)
3103 int nb
= NB(ctx
->opcode
);
3104 int start
= rD(ctx
->opcode
);
3105 int ra
= rA(ctx
->opcode
);
3111 if (unlikely(((start
+ nr
) > 32 &&
3112 start
<= ra
&& (start
+ nr
- 32) > ra
) ||
3113 ((start
+ nr
) <= 32 && start
<= ra
&& (start
+ nr
) > ra
))) {
3114 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
3117 gen_set_access_type(ctx
, ACCESS_INT
);
3118 /* NIP cannot be restored if the memory exception comes from an helper */
3119 gen_update_nip(ctx
, ctx
->nip
- 4);
3120 t0
= tcg_temp_new();
3121 gen_addr_register(ctx
, t0
);
3122 t1
= tcg_const_i32(nb
);
3123 t2
= tcg_const_i32(start
);
3124 gen_helper_lsw(t0
, t1
, t2
);
3126 tcg_temp_free_i32(t1
);
3127 tcg_temp_free_i32(t2
);
3131 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
)
3134 TCGv_i32 t1
, t2
, t3
;
3135 gen_set_access_type(ctx
, ACCESS_INT
);
3136 /* NIP cannot be restored if the memory exception comes from an helper */
3137 gen_update_nip(ctx
, ctx
->nip
- 4);
3138 t0
= tcg_temp_new();
3139 gen_addr_reg_index(ctx
, t0
);
3140 t1
= tcg_const_i32(rD(ctx
->opcode
));
3141 t2
= tcg_const_i32(rA(ctx
->opcode
));
3142 t3
= tcg_const_i32(rB(ctx
->opcode
));
3143 gen_helper_lswx(t0
, t1
, t2
, t3
);
3145 tcg_temp_free_i32(t1
);
3146 tcg_temp_free_i32(t2
);
3147 tcg_temp_free_i32(t3
);
3151 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
)
3155 int nb
= NB(ctx
->opcode
);
3156 gen_set_access_type(ctx
, ACCESS_INT
);
3157 /* NIP cannot be restored if the memory exception comes from an helper */
3158 gen_update_nip(ctx
, ctx
->nip
- 4);
3159 t0
= tcg_temp_new();
3160 gen_addr_register(ctx
, t0
);
3163 t1
= tcg_const_i32(nb
);
3164 t2
= tcg_const_i32(rS(ctx
->opcode
));
3165 gen_helper_stsw(t0
, t1
, t2
);
3167 tcg_temp_free_i32(t1
);
3168 tcg_temp_free_i32(t2
);
3172 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
)
3176 gen_set_access_type(ctx
, ACCESS_INT
);
3177 /* NIP cannot be restored if the memory exception comes from an helper */
3178 gen_update_nip(ctx
, ctx
->nip
- 4);
3179 t0
= tcg_temp_new();
3180 gen_addr_reg_index(ctx
, t0
);
3181 t1
= tcg_temp_new_i32();
3182 tcg_gen_trunc_tl_i32(t1
, cpu_xer
);
3183 tcg_gen_andi_i32(t1
, t1
, 0x7F);
3184 t2
= tcg_const_i32(rS(ctx
->opcode
));
3185 gen_helper_stsw(t0
, t1
, t2
);
3187 tcg_temp_free_i32(t1
);
3188 tcg_temp_free_i32(t2
);
3191 /*** Memory synchronisation ***/
3193 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO
)
3198 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
)
3200 gen_stop_exception(ctx
);
3204 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000001, PPC_RES
)
3207 gen_set_access_type(ctx
, ACCESS_RES
);
3208 t0
= tcg_temp_local_new();
3209 gen_addr_reg_index(ctx
, t0
);
3210 gen_check_align(ctx
, t0
, 0x03);
3211 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
3212 tcg_gen_mov_tl(cpu_reserve
, t0
);
3217 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
)
3221 gen_set_access_type(ctx
, ACCESS_RES
);
3222 t0
= tcg_temp_local_new();
3223 gen_addr_reg_index(ctx
, t0
);
3224 gen_check_align(ctx
, t0
, 0x03);
3225 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_xer
);
3226 tcg_gen_shri_i32(cpu_crf
[0], cpu_crf
[0], XER_SO
);
3227 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 1);
3228 l1
= gen_new_label();
3229 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
3230 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3231 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3233 tcg_gen_movi_tl(cpu_reserve
, -1);
3237 #if defined(TARGET_PPC64)
3239 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000001, PPC_64B
)
3242 gen_set_access_type(ctx
, ACCESS_RES
);
3243 t0
= tcg_temp_local_new();
3244 gen_addr_reg_index(ctx
, t0
);
3245 gen_check_align(ctx
, t0
, 0x07);
3246 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
3247 tcg_gen_mov_tl(cpu_reserve
, t0
);
3252 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
)
3256 gen_set_access_type(ctx
, ACCESS_RES
);
3257 t0
= tcg_temp_local_new();
3258 gen_addr_reg_index(ctx
, t0
);
3259 gen_check_align(ctx
, t0
, 0x07);
3260 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_xer
);
3261 tcg_gen_shri_i32(cpu_crf
[0], cpu_crf
[0], XER_SO
);
3262 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 1);
3263 l1
= gen_new_label();
3264 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
3265 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3266 gen_qemu_st64(ctx
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3268 tcg_gen_movi_tl(cpu_reserve
, -1);
3271 #endif /* defined(TARGET_PPC64) */
3274 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
)
3279 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
)
3281 TCGv_i32 t0
= tcg_temp_new_i32();
3282 tcg_gen_st_i32(t0
, cpu_env
, offsetof(CPUState
, halted
));
3283 tcg_temp_free_i32(t0
);
3284 /* Stop translation, as the CPU is supposed to sleep from now */
3285 gen_exception_err(ctx
, EXCP_HLT
, 1);
3288 /*** Floating-point load ***/
3289 #define GEN_LDF(name, ldop, opc, type) \
3290 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type) \
3293 if (unlikely(!ctx->fpu_enabled)) { \
3294 gen_exception(ctx, POWERPC_EXCP_FPU); \
3297 gen_set_access_type(ctx, ACCESS_FLOAT); \
3298 EA = tcg_temp_new(); \
3299 gen_addr_imm_index(ctx, EA, 0); \
3300 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3301 tcg_temp_free(EA); \
3304 #define GEN_LDUF(name, ldop, opc, type) \
3305 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type) \
3308 if (unlikely(!ctx->fpu_enabled)) { \
3309 gen_exception(ctx, POWERPC_EXCP_FPU); \
3312 if (unlikely(rA(ctx->opcode) == 0)) { \
3313 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3316 gen_set_access_type(ctx, ACCESS_FLOAT); \
3317 EA = tcg_temp_new(); \
3318 gen_addr_imm_index(ctx, EA, 0); \
3319 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3320 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3321 tcg_temp_free(EA); \
3324 #define GEN_LDUXF(name, ldop, opc, type) \
3325 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type) \
3328 if (unlikely(!ctx->fpu_enabled)) { \
3329 gen_exception(ctx, POWERPC_EXCP_FPU); \
3332 if (unlikely(rA(ctx->opcode) == 0)) { \
3333 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3336 gen_set_access_type(ctx, ACCESS_FLOAT); \
3337 EA = tcg_temp_new(); \
3338 gen_addr_reg_index(ctx, EA); \
3339 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3340 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3341 tcg_temp_free(EA); \
3344 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
3345 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type) \
3348 if (unlikely(!ctx->fpu_enabled)) { \
3349 gen_exception(ctx, POWERPC_EXCP_FPU); \
3352 gen_set_access_type(ctx, ACCESS_FLOAT); \
3353 EA = tcg_temp_new(); \
3354 gen_addr_reg_index(ctx, EA); \
3355 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3356 tcg_temp_free(EA); \
3359 #define GEN_LDFS(name, ldop, op, type) \
3360 GEN_LDF(name, ldop, op | 0x20, type); \
3361 GEN_LDUF(name, ldop, op | 0x21, type); \
3362 GEN_LDUXF(name, ldop, op | 0x01, type); \
3363 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3365 static always_inline
void gen_qemu_ld32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3367 TCGv t0
= tcg_temp_new();
3368 TCGv_i32 t1
= tcg_temp_new_i32();
3369 gen_qemu_ld32u(ctx
, t0
, arg2
);
3370 tcg_gen_trunc_tl_i32(t1
, t0
);
3372 gen_helper_float32_to_float64(arg1
, t1
);
3373 tcg_temp_free_i32(t1
);
3376 /* lfd lfdu lfdux lfdx */
3377 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
);
3378 /* lfs lfsu lfsux lfsx */
3379 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
);
3381 /*** Floating-point store ***/
3382 #define GEN_STF(name, stop, opc, type) \
3383 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type) \
3386 if (unlikely(!ctx->fpu_enabled)) { \
3387 gen_exception(ctx, POWERPC_EXCP_FPU); \
3390 gen_set_access_type(ctx, ACCESS_FLOAT); \
3391 EA = tcg_temp_new(); \
3392 gen_addr_imm_index(ctx, EA, 0); \
3393 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3394 tcg_temp_free(EA); \
3397 #define GEN_STUF(name, stop, opc, type) \
3398 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type) \
3401 if (unlikely(!ctx->fpu_enabled)) { \
3402 gen_exception(ctx, POWERPC_EXCP_FPU); \
3405 if (unlikely(rA(ctx->opcode) == 0)) { \
3406 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3409 gen_set_access_type(ctx, ACCESS_FLOAT); \
3410 EA = tcg_temp_new(); \
3411 gen_addr_imm_index(ctx, EA, 0); \
3412 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3413 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3414 tcg_temp_free(EA); \
3417 #define GEN_STUXF(name, stop, opc, type) \
3418 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type) \
3421 if (unlikely(!ctx->fpu_enabled)) { \
3422 gen_exception(ctx, POWERPC_EXCP_FPU); \
3425 if (unlikely(rA(ctx->opcode) == 0)) { \
3426 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3429 gen_set_access_type(ctx, ACCESS_FLOAT); \
3430 EA = tcg_temp_new(); \
3431 gen_addr_reg_index(ctx, EA); \
3432 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3433 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3434 tcg_temp_free(EA); \
3437 #define GEN_STXF(name, stop, opc2, opc3, type) \
3438 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type) \
3441 if (unlikely(!ctx->fpu_enabled)) { \
3442 gen_exception(ctx, POWERPC_EXCP_FPU); \
3445 gen_set_access_type(ctx, ACCESS_FLOAT); \
3446 EA = tcg_temp_new(); \
3447 gen_addr_reg_index(ctx, EA); \
3448 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3449 tcg_temp_free(EA); \
3452 #define GEN_STFS(name, stop, op, type) \
3453 GEN_STF(name, stop, op | 0x20, type); \
3454 GEN_STUF(name, stop, op | 0x21, type); \
3455 GEN_STUXF(name, stop, op | 0x01, type); \
3456 GEN_STXF(name, stop, 0x17, op | 0x00, type)
3458 static always_inline
void gen_qemu_st32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3460 TCGv_i32 t0
= tcg_temp_new_i32();
3461 TCGv t1
= tcg_temp_new();
3462 gen_helper_float64_to_float32(t0
, arg1
);
3463 tcg_gen_extu_i32_tl(t1
, t0
);
3464 tcg_temp_free_i32(t0
);
3465 gen_qemu_st32(ctx
, t1
, arg2
);
3469 /* stfd stfdu stfdux stfdx */
3470 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
);
3471 /* stfs stfsu stfsux stfsx */
3472 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
);
3475 static always_inline
void gen_qemu_st32fiw(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3477 TCGv t0
= tcg_temp_new();
3478 tcg_gen_trunc_i64_tl(t0
, arg1
),
3479 gen_qemu_st32(ctx
, t0
, arg2
);
3483 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
);
3486 static always_inline
void gen_goto_tb (DisasContext
*ctx
, int n
,
3489 TranslationBlock
*tb
;
3491 #if defined(TARGET_PPC64)
3493 dest
= (uint32_t) dest
;
3495 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
3496 likely(!ctx
->singlestep_enabled
)) {
3498 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3499 tcg_gen_exit_tb((long)tb
+ n
);
3501 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3502 if (unlikely(ctx
->singlestep_enabled
)) {
3503 if ((ctx
->singlestep_enabled
&
3504 (CPU_BRANCH_STEP
| CPU_SINGLE_STEP
)) &&
3505 ctx
->exception
== POWERPC_EXCP_BRANCH
) {
3506 target_ulong tmp
= ctx
->nip
;
3508 gen_exception(ctx
, POWERPC_EXCP_TRACE
);
3511 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
3512 gen_debug_exception(ctx
);
3519 static always_inline
void gen_setlr (DisasContext
*ctx
, target_ulong nip
)
3521 #if defined(TARGET_PPC64)
3522 if (ctx
->sf_mode
== 0)
3523 tcg_gen_movi_tl(cpu_lr
, (uint32_t)nip
);
3526 tcg_gen_movi_tl(cpu_lr
, nip
);
3530 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
3532 target_ulong li
, target
;
3534 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3535 /* sign extend LI */
3536 #if defined(TARGET_PPC64)
3538 li
= ((int64_t)LI(ctx
->opcode
) << 38) >> 38;
3541 li
= ((int32_t)LI(ctx
->opcode
) << 6) >> 6;
3542 if (likely(AA(ctx
->opcode
) == 0))
3543 target
= ctx
->nip
+ li
- 4;
3546 if (LK(ctx
->opcode
))
3547 gen_setlr(ctx
, ctx
->nip
);
3548 gen_goto_tb(ctx
, 0, target
);
3555 static always_inline
void gen_bcond (DisasContext
*ctx
, int type
)
3557 uint32_t bo
= BO(ctx
->opcode
);
3558 int l1
= gen_new_label();
3561 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3562 if (type
== BCOND_LR
|| type
== BCOND_CTR
) {
3563 target
= tcg_temp_local_new();
3564 if (type
== BCOND_CTR
)
3565 tcg_gen_mov_tl(target
, cpu_ctr
);
3567 tcg_gen_mov_tl(target
, cpu_lr
);
3569 if (LK(ctx
->opcode
))
3570 gen_setlr(ctx
, ctx
->nip
);
3571 l1
= gen_new_label();
3572 if ((bo
& 0x4) == 0) {
3573 /* Decrement and test CTR */
3574 TCGv temp
= tcg_temp_new();
3575 if (unlikely(type
== BCOND_CTR
)) {
3576 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3579 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
3580 #if defined(TARGET_PPC64)
3582 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
3585 tcg_gen_mov_tl(temp
, cpu_ctr
);
3587 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
3589 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
3591 tcg_temp_free(temp
);
3593 if ((bo
& 0x10) == 0) {
3595 uint32_t bi
= BI(ctx
->opcode
);
3596 uint32_t mask
= 1 << (3 - (bi
& 0x03));
3597 TCGv_i32 temp
= tcg_temp_new_i32();
3600 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3601 tcg_gen_brcondi_i32(TCG_COND_EQ
, temp
, 0, l1
);
3603 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3604 tcg_gen_brcondi_i32(TCG_COND_NE
, temp
, 0, l1
);
3606 tcg_temp_free_i32(temp
);
3608 if (type
== BCOND_IM
) {
3609 target_ulong li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
3610 if (likely(AA(ctx
->opcode
) == 0)) {
3611 gen_goto_tb(ctx
, 0, ctx
->nip
+ li
- 4);
3613 gen_goto_tb(ctx
, 0, li
);
3616 gen_goto_tb(ctx
, 1, ctx
->nip
);
3618 #if defined(TARGET_PPC64)
3619 if (!(ctx
->sf_mode
))
3620 tcg_gen_andi_tl(cpu_nip
, target
, (uint32_t)~3);
3623 tcg_gen_andi_tl(cpu_nip
, target
, ~3);
3626 #if defined(TARGET_PPC64)
3627 if (!(ctx
->sf_mode
))
3628 tcg_gen_movi_tl(cpu_nip
, (uint32_t)ctx
->nip
);
3631 tcg_gen_movi_tl(cpu_nip
, ctx
->nip
);
3636 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
3638 gen_bcond(ctx
, BCOND_IM
);
3641 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
)
3643 gen_bcond(ctx
, BCOND_CTR
);
3646 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
)
3648 gen_bcond(ctx
, BCOND_LR
);
3651 /*** Condition register logical ***/
3652 #define GEN_CRLOGIC(name, tcg_op, opc) \
3653 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) \
3658 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3659 t0 = tcg_temp_new_i32(); \
3661 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
3663 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
3665 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
3666 t1 = tcg_temp_new_i32(); \
3667 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3669 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
3671 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
3673 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3674 tcg_op(t0, t0, t1); \
3675 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
3676 tcg_gen_andi_i32(t0, t0, bitmask); \
3677 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3678 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
3679 tcg_temp_free_i32(t0); \
3680 tcg_temp_free_i32(t1); \
3684 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08);
3686 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04);
3688 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09);
3690 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07);
3692 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01);
3694 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E);
3696 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D);
3698 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06);
3700 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
)
3702 tcg_gen_mov_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfS(ctx
->opcode
)]);
3705 /*** System linkage ***/
3706 /* rfi (mem_idx only) */
3707 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
)
3709 #if defined(CONFIG_USER_ONLY)
3710 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3712 /* Restore CPU state */
3713 if (unlikely(!ctx
->mem_idx
)) {
3714 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3718 gen_sync_exception(ctx
);
3722 #if defined(TARGET_PPC64)
3723 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
)
3725 #if defined(CONFIG_USER_ONLY)
3726 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3728 /* Restore CPU state */
3729 if (unlikely(!ctx
->mem_idx
)) {
3730 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3734 gen_sync_exception(ctx
);
3738 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
)
3740 #if defined(CONFIG_USER_ONLY)
3741 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3743 /* Restore CPU state */
3744 if (unlikely(ctx
->mem_idx
<= 1)) {
3745 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3749 gen_sync_exception(ctx
);
3755 #if defined(CONFIG_USER_ONLY)
3756 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3758 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3760 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW
)
3764 lev
= (ctx
->opcode
>> 5) & 0x7F;
3765 gen_exception_err(ctx
, POWERPC_SYSCALL
, lev
);
3770 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
)
3772 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3773 /* Update the nip since this might generate a trap exception */
3774 gen_update_nip(ctx
, ctx
->nip
);
3775 gen_helper_tw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
3776 tcg_temp_free_i32(t0
);
3780 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
3782 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3783 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
3784 /* Update the nip since this might generate a trap exception */
3785 gen_update_nip(ctx
, ctx
->nip
);
3786 gen_helper_tw(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3788 tcg_temp_free_i32(t1
);
3791 #if defined(TARGET_PPC64)
3793 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
)
3795 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3796 /* Update the nip since this might generate a trap exception */
3797 gen_update_nip(ctx
, ctx
->nip
);
3798 gen_helper_td(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
3799 tcg_temp_free_i32(t0
);
3803 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
)
3805 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3806 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
3807 /* Update the nip since this might generate a trap exception */
3808 gen_update_nip(ctx
, ctx
->nip
);
3809 gen_helper_td(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3811 tcg_temp_free_i32(t1
);
3815 /*** Processor control ***/
3817 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
)
3819 tcg_gen_trunc_tl_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_xer
);
3820 tcg_gen_shri_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfD(ctx
->opcode
)], XER_CA
);
3821 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_SO
| 1 << XER_OV
| 1 << XER_CA
));
3825 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
)
3829 if (likely(ctx
->opcode
& 0x00100000)) {
3830 crm
= CRM(ctx
->opcode
);
3831 if (likely((crm
^ (crm
- 1)) == 0)) {
3833 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_crf
[7 - crn
]);
3836 gen_helper_load_cr(cpu_gpr
[rD(ctx
->opcode
)]);
3841 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
)
3843 #if defined(CONFIG_USER_ONLY)
3844 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3846 if (unlikely(!ctx
->mem_idx
)) {
3847 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3850 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_msr
);
3855 #define SPR_NOACCESS ((void *)(-1UL))
3857 static void spr_noaccess (void *opaque
, int sprn
)
3859 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
3860 printf("ERROR: try to access SPR %d !\n", sprn
);
3862 #define SPR_NOACCESS (&spr_noaccess)
3866 static always_inline
void gen_op_mfspr (DisasContext
*ctx
)
3868 void (*read_cb
)(void *opaque
, int gprn
, int sprn
);
3869 uint32_t sprn
= SPR(ctx
->opcode
);
3871 #if !defined(CONFIG_USER_ONLY)
3872 if (ctx
->mem_idx
== 2)
3873 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
3874 else if (ctx
->mem_idx
)
3875 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
3878 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
3879 if (likely(read_cb
!= NULL
)) {
3880 if (likely(read_cb
!= SPR_NOACCESS
)) {
3881 (*read_cb
)(ctx
, rD(ctx
->opcode
), sprn
);
3883 /* Privilege exception */
3884 /* This is a hack to avoid warnings when running Linux:
3885 * this OS breaks the PowerPC virtualisation model,
3886 * allowing userland application to read the PVR
3888 if (sprn
!= SPR_PVR
) {
3889 if (loglevel
!= 0) {
3890 fprintf(logfile
, "Trying to read privileged spr %d %03x at "
3891 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3893 printf("Trying to read privileged spr %d %03x at " ADDRX
"\n",
3894 sprn
, sprn
, ctx
->nip
);
3896 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3900 if (loglevel
!= 0) {
3901 fprintf(logfile
, "Trying to read invalid spr %d %03x at "
3902 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3904 printf("Trying to read invalid spr %d %03x at " ADDRX
"\n",
3905 sprn
, sprn
, ctx
->nip
);
3906 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
3910 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
)
3916 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
)
3922 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
)
3926 crm
= CRM(ctx
->opcode
);
3927 if (likely((ctx
->opcode
& 0x00100000) || (crm
^ (crm
- 1)) == 0)) {
3928 TCGv_i32 temp
= tcg_temp_new_i32();
3930 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
3931 tcg_gen_shri_i32(cpu_crf
[7 - crn
], temp
, crn
* 4);
3932 tcg_gen_andi_i32(cpu_crf
[7 - crn
], cpu_crf
[7 - crn
], 0xf);
3933 tcg_temp_free_i32(temp
);
3935 TCGv_i32 temp
= tcg_const_i32(crm
);
3936 gen_helper_store_cr(cpu_gpr
[rS(ctx
->opcode
)], temp
);
3937 tcg_temp_free_i32(temp
);
3942 #if defined(TARGET_PPC64)
3943 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
)
3945 #if defined(CONFIG_USER_ONLY)
3946 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3948 if (unlikely(!ctx
->mem_idx
)) {
3949 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3952 if (ctx
->opcode
& 0x00010000) {
3953 /* Special form that does not need any synchronisation */
3954 TCGv t0
= tcg_temp_new();
3955 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
3956 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
3957 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
3960 /* XXX: we need to update nip before the store
3961 * if we enter power saving mode, we will exit the loop
3962 * directly from ppc_store_msr
3964 gen_update_nip(ctx
, ctx
->nip
);
3965 gen_helper_store_msr(cpu_gpr
[rS(ctx
->opcode
)]);
3966 /* Must stop the translation as machine state (may have) changed */
3967 /* Note that mtmsr is not always defined as context-synchronizing */
3968 gen_stop_exception(ctx
);
3974 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC
)
3976 #if defined(CONFIG_USER_ONLY)
3977 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3979 if (unlikely(!ctx
->mem_idx
)) {
3980 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3983 if (ctx
->opcode
& 0x00010000) {
3984 /* Special form that does not need any synchronisation */
3985 TCGv t0
= tcg_temp_new();
3986 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
3987 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
3988 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
3991 /* XXX: we need to update nip before the store
3992 * if we enter power saving mode, we will exit the loop
3993 * directly from ppc_store_msr
3995 gen_update_nip(ctx
, ctx
->nip
);
3996 #if defined(TARGET_PPC64)
3997 if (!ctx
->sf_mode
) {
3998 TCGv t0
= tcg_temp_new();
3999 TCGv t1
= tcg_temp_new();
4000 tcg_gen_andi_tl(t0
, cpu_msr
, 0xFFFFFFFF00000000ULL
);
4001 tcg_gen_ext32u_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
4002 tcg_gen_or_tl(t0
, t0
, t1
);
4004 gen_helper_store_msr(t0
);
4008 gen_helper_store_msr(cpu_gpr
[rS(ctx
->opcode
)]);
4009 /* Must stop the translation as machine state (may have) changed */
4010 /* Note that mtmsr is not always defined as context-synchronizing */
4011 gen_stop_exception(ctx
);
4017 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC
)
4019 void (*write_cb
)(void *opaque
, int sprn
, int gprn
);
4020 uint32_t sprn
= SPR(ctx
->opcode
);
4022 #if !defined(CONFIG_USER_ONLY)
4023 if (ctx
->mem_idx
== 2)
4024 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
4025 else if (ctx
->mem_idx
)
4026 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
4029 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
4030 if (likely(write_cb
!= NULL
)) {
4031 if (likely(write_cb
!= SPR_NOACCESS
)) {
4032 (*write_cb
)(ctx
, sprn
, rS(ctx
->opcode
));
4034 /* Privilege exception */
4035 if (loglevel
!= 0) {
4036 fprintf(logfile
, "Trying to write privileged spr %d %03x at "
4037 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
4039 printf("Trying to write privileged spr %d %03x at " ADDRX
"\n",
4040 sprn
, sprn
, ctx
->nip
);
4041 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4045 if (loglevel
!= 0) {
4046 fprintf(logfile
, "Trying to write invalid spr %d %03x at "
4047 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
4049 printf("Trying to write invalid spr %d %03x at " ADDRX
"\n",
4050 sprn
, sprn
, ctx
->nip
);
4051 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4055 /*** Cache management ***/
4057 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
)
4059 /* XXX: specification says this is treated as a load by the MMU */
4061 gen_set_access_type(ctx
, ACCESS_CACHE
);
4062 t0
= tcg_temp_new();
4063 gen_addr_reg_index(ctx
, t0
);
4064 gen_qemu_ld8u(ctx
, t0
, t0
);
4068 /* dcbi (Supervisor only) */
4069 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
)
4071 #if defined(CONFIG_USER_ONLY)
4072 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4075 if (unlikely(!ctx
->mem_idx
)) {
4076 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4079 EA
= tcg_temp_new();
4080 gen_set_access_type(ctx
, ACCESS_CACHE
);
4081 gen_addr_reg_index(ctx
, EA
);
4082 val
= tcg_temp_new();
4083 /* XXX: specification says this should be treated as a store by the MMU */
4084 gen_qemu_ld8u(ctx
, val
, EA
);
4085 gen_qemu_st8(ctx
, val
, EA
);
4092 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
)
4094 /* XXX: specification say this is treated as a load by the MMU */
4096 gen_set_access_type(ctx
, ACCESS_CACHE
);
4097 t0
= tcg_temp_new();
4098 gen_addr_reg_index(ctx
, t0
);
4099 gen_qemu_ld8u(ctx
, t0
, t0
);
4104 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE
)
4106 /* interpreted as no-op */
4107 /* XXX: specification say this is treated as a load by the MMU
4108 * but does not generate any exception
4113 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE
)
4115 /* interpreted as no-op */
4116 /* XXX: specification say this is treated as a load by the MMU
4117 * but does not generate any exception
4122 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE_DCBZ
)
4125 gen_set_access_type(ctx
, ACCESS_CACHE
);
4126 /* NIP cannot be restored if the memory exception comes from an helper */
4127 gen_update_nip(ctx
, ctx
->nip
- 4);
4128 t0
= tcg_temp_new();
4129 gen_addr_reg_index(ctx
, t0
);
4130 gen_helper_dcbz(t0
);
4134 GEN_HANDLER2(dcbz_970
, "dcbz", 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZT
)
4137 gen_set_access_type(ctx
, ACCESS_CACHE
);
4138 /* NIP cannot be restored if the memory exception comes from an helper */
4139 gen_update_nip(ctx
, ctx
->nip
- 4);
4140 t0
= tcg_temp_new();
4141 gen_addr_reg_index(ctx
, t0
);
4142 if (ctx
->opcode
& 0x00200000)
4143 gen_helper_dcbz(t0
);
4145 gen_helper_dcbz_970(t0
);
4150 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
)
4153 gen_set_access_type(ctx
, ACCESS_CACHE
);
4154 /* NIP cannot be restored if the memory exception comes from an helper */
4155 gen_update_nip(ctx
, ctx
->nip
- 4);
4156 t0
= tcg_temp_new();
4157 gen_addr_reg_index(ctx
, t0
);
4158 gen_helper_icbi(t0
);
4164 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
)
4166 /* interpreted as no-op */
4167 /* XXX: specification say this is treated as a store by the MMU
4168 * but does not generate any exception
4172 /*** Segment register manipulation ***/
4173 /* Supervisor only: */
4175 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
)
4177 #if defined(CONFIG_USER_ONLY)
4178 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4181 if (unlikely(!ctx
->mem_idx
)) {
4182 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4185 t0
= tcg_const_tl(SR(ctx
->opcode
));
4186 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4192 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
)
4194 #if defined(CONFIG_USER_ONLY)
4195 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4198 if (unlikely(!ctx
->mem_idx
)) {
4199 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4202 t0
= tcg_temp_new();
4203 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4204 tcg_gen_andi_tl(t0
, t0
, 0xF);
4205 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4211 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
)
4213 #if defined(CONFIG_USER_ONLY)
4214 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4217 if (unlikely(!ctx
->mem_idx
)) {
4218 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4221 t0
= tcg_const_tl(SR(ctx
->opcode
));
4222 gen_helper_store_sr(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4228 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
)
4230 #if defined(CONFIG_USER_ONLY)
4231 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4234 if (unlikely(!ctx
->mem_idx
)) {
4235 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4238 t0
= tcg_temp_new();
4239 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4240 tcg_gen_andi_tl(t0
, t0
, 0xF);
4241 gen_helper_store_sr(t0
, cpu_gpr
[rD(ctx
->opcode
)]);
4246 #if defined(TARGET_PPC64)
4247 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4249 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
)
4251 #if defined(CONFIG_USER_ONLY)
4252 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4255 if (unlikely(!ctx
->mem_idx
)) {
4256 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4259 t0
= tcg_const_tl(SR(ctx
->opcode
));
4260 gen_helper_load_slb(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4266 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
4269 #if defined(CONFIG_USER_ONLY)
4270 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4273 if (unlikely(!ctx
->mem_idx
)) {
4274 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4277 t0
= tcg_temp_new();
4278 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4279 tcg_gen_andi_tl(t0
, t0
, 0xF);
4280 gen_helper_load_slb(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4286 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
)
4288 #if defined(CONFIG_USER_ONLY)
4289 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4292 if (unlikely(!ctx
->mem_idx
)) {
4293 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4296 t0
= tcg_const_tl(SR(ctx
->opcode
));
4297 gen_helper_store_slb(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4303 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
4306 #if defined(CONFIG_USER_ONLY)
4307 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4310 if (unlikely(!ctx
->mem_idx
)) {
4311 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4314 t0
= tcg_temp_new();
4315 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4316 tcg_gen_andi_tl(t0
, t0
, 0xF);
4317 gen_helper_store_slb(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4321 #endif /* defined(TARGET_PPC64) */
4323 /*** Lookaside buffer management ***/
4324 /* Optional & mem_idx only: */
4326 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
)
4328 #if defined(CONFIG_USER_ONLY)
4329 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4331 if (unlikely(!ctx
->mem_idx
)) {
4332 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4340 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE
)
4342 #if defined(CONFIG_USER_ONLY)
4343 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4345 if (unlikely(!ctx
->mem_idx
)) {
4346 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4349 #if defined(TARGET_PPC64)
4350 if (!ctx
->sf_mode
) {
4351 TCGv t0
= tcg_temp_new();
4352 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
4353 gen_helper_tlbie(t0
);
4357 gen_helper_tlbie(cpu_gpr
[rB(ctx
->opcode
)]);
4362 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
)
4364 #if defined(CONFIG_USER_ONLY)
4365 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4367 if (unlikely(!ctx
->mem_idx
)) {
4368 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4371 /* This has no effect: it should ensure that all previous
4372 * tlbie have completed
4374 gen_stop_exception(ctx
);
4378 #if defined(TARGET_PPC64)
4380 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI
)
4382 #if defined(CONFIG_USER_ONLY)
4383 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4385 if (unlikely(!ctx
->mem_idx
)) {
4386 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4394 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
)
4396 #if defined(CONFIG_USER_ONLY)
4397 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4399 if (unlikely(!ctx
->mem_idx
)) {
4400 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4403 gen_helper_slbie(cpu_gpr
[rB(ctx
->opcode
)]);
4408 /*** External control ***/
4411 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
)
4414 /* Should check EAR[E] ! */
4415 gen_set_access_type(ctx
, ACCESS_EXT
);
4416 t0
= tcg_temp_new();
4417 gen_addr_reg_index(ctx
, t0
);
4418 gen_check_align(ctx
, t0
, 0x03);
4419 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4424 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
)
4427 /* Should check EAR[E] ! */
4428 gen_set_access_type(ctx
, ACCESS_EXT
);
4429 t0
= tcg_temp_new();
4430 gen_addr_reg_index(ctx
, t0
);
4431 gen_check_align(ctx
, t0
, 0x03);
4432 gen_qemu_st32(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4436 /* PowerPC 601 specific instructions */
4438 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
)
4440 int l1
= gen_new_label();
4441 int l2
= gen_new_label();
4442 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4443 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4446 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4448 if (unlikely(Rc(ctx
->opcode
) != 0))
4449 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4453 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
)
4455 int l1
= gen_new_label();
4456 int l2
= gen_new_label();
4457 int l3
= gen_new_label();
4458 /* Start with XER OV disabled, the most likely case */
4459 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
4460 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l2
);
4461 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rA(ctx
->opcode
)], 0x80000000, l1
);
4462 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
4465 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4468 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4470 if (unlikely(Rc(ctx
->opcode
) != 0))
4471 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4475 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
)
4477 TCGv_i32 t0
= tcg_const_i32(rA(ctx
->opcode
));
4478 gen_helper_clcs(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4479 tcg_temp_free_i32(t0
);
4480 /* Rc=1 sets CR0 to an undefined state */
4484 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
)
4486 gen_helper_div(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4487 if (unlikely(Rc(ctx
->opcode
) != 0))
4488 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4492 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
)
4494 gen_helper_divo(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4495 if (unlikely(Rc(ctx
->opcode
) != 0))
4496 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4500 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
)
4502 gen_helper_divs(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4503 if (unlikely(Rc(ctx
->opcode
) != 0))
4504 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4507 /* divso - divso. */
4508 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
)
4510 gen_helper_divso(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4511 if (unlikely(Rc(ctx
->opcode
) != 0))
4512 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4516 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
)
4518 int l1
= gen_new_label();
4519 int l2
= gen_new_label();
4520 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4521 tcg_gen_sub_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4524 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4526 if (unlikely(Rc(ctx
->opcode
) != 0))
4527 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4531 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
)
4533 int l1
= gen_new_label();
4534 int l2
= gen_new_label();
4535 TCGv t0
= tcg_temp_new();
4536 TCGv t1
= tcg_temp_new();
4537 TCGv t2
= tcg_temp_new();
4538 /* Start with XER OV disabled, the most likely case */
4539 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
4540 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4541 tcg_gen_sub_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4542 tcg_gen_xor_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4543 tcg_gen_xor_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], t0
);
4544 tcg_gen_andc_tl(t1
, t1
, t2
);
4545 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4546 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
4547 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
4550 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4555 if (unlikely(Rc(ctx
->opcode
) != 0))
4556 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4560 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
)
4562 target_long simm
= SIMM(ctx
->opcode
);
4563 int l1
= gen_new_label();
4564 int l2
= gen_new_label();
4565 tcg_gen_brcondi_tl(TCG_COND_LT
, cpu_gpr
[rA(ctx
->opcode
)], simm
, l1
);
4566 tcg_gen_subfi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
, cpu_gpr
[rA(ctx
->opcode
)]);
4569 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4571 if (unlikely(Rc(ctx
->opcode
) != 0))
4572 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4575 /* lscbx - lscbx. */
4576 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
)
4578 TCGv t0
= tcg_temp_new();
4579 TCGv_i32 t1
= tcg_const_i32(rD(ctx
->opcode
));
4580 TCGv_i32 t2
= tcg_const_i32(rA(ctx
->opcode
));
4581 TCGv_i32 t3
= tcg_const_i32(rB(ctx
->opcode
));
4583 gen_addr_reg_index(ctx
, t0
);
4584 /* NIP cannot be restored if the memory exception comes from an helper */
4585 gen_update_nip(ctx
, ctx
->nip
- 4);
4586 gen_helper_lscbx(t0
, t0
, t1
, t2
, t3
);
4587 tcg_temp_free_i32(t1
);
4588 tcg_temp_free_i32(t2
);
4589 tcg_temp_free_i32(t3
);
4590 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~0x7F);
4591 tcg_gen_or_tl(cpu_xer
, cpu_xer
, t0
);
4592 if (unlikely(Rc(ctx
->opcode
) != 0))
4593 gen_set_Rc0(ctx
, t0
);
4597 /* maskg - maskg. */
4598 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
)
4600 int l1
= gen_new_label();
4601 TCGv t0
= tcg_temp_new();
4602 TCGv t1
= tcg_temp_new();
4603 TCGv t2
= tcg_temp_new();
4604 TCGv t3
= tcg_temp_new();
4605 tcg_gen_movi_tl(t3
, 0xFFFFFFFF);
4606 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4607 tcg_gen_andi_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 0x1F);
4608 tcg_gen_addi_tl(t2
, t0
, 1);
4609 tcg_gen_shr_tl(t2
, t3
, t2
);
4610 tcg_gen_shr_tl(t3
, t3
, t1
);
4611 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], t2
, t3
);
4612 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
4613 tcg_gen_neg_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4619 if (unlikely(Rc(ctx
->opcode
) != 0))
4620 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4623 /* maskir - maskir. */
4624 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
)
4626 TCGv t0
= tcg_temp_new();
4627 TCGv t1
= tcg_temp_new();
4628 tcg_gen_and_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4629 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
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 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
)
4640 TCGv_i64 t0
= tcg_temp_new_i64();
4641 TCGv_i64 t1
= tcg_temp_new_i64();
4642 TCGv t2
= tcg_temp_new();
4643 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4644 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4645 tcg_gen_mul_i64(t0
, t0
, t1
);
4646 tcg_gen_trunc_i64_tl(t2
, t0
);
4647 gen_store_spr(SPR_MQ
, t2
);
4648 tcg_gen_shri_i64(t1
, t0
, 32);
4649 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4650 tcg_temp_free_i64(t0
);
4651 tcg_temp_free_i64(t1
);
4653 if (unlikely(Rc(ctx
->opcode
) != 0))
4654 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4658 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
)
4660 int l1
= gen_new_label();
4661 TCGv_i64 t0
= tcg_temp_new_i64();
4662 TCGv_i64 t1
= tcg_temp_new_i64();
4663 TCGv t2
= tcg_temp_new();
4664 /* Start with XER OV disabled, the most likely case */
4665 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
4666 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4667 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4668 tcg_gen_mul_i64(t0
, t0
, t1
);
4669 tcg_gen_trunc_i64_tl(t2
, t0
);
4670 gen_store_spr(SPR_MQ
, t2
);
4671 tcg_gen_shri_i64(t1
, t0
, 32);
4672 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4673 tcg_gen_ext32s_i64(t1
, t0
);
4674 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
4675 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
4677 tcg_temp_free_i64(t0
);
4678 tcg_temp_free_i64(t1
);
4680 if (unlikely(Rc(ctx
->opcode
) != 0))
4681 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4685 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
)
4687 int l1
= gen_new_label();
4688 int l2
= gen_new_label();
4689 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4690 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4693 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4695 if (unlikely(Rc(ctx
->opcode
) != 0))
4696 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4699 /* nabso - nabso. */
4700 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
)
4702 int l1
= gen_new_label();
4703 int l2
= gen_new_label();
4704 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4705 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4708 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4710 /* nabs never overflows */
4711 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
4712 if (unlikely(Rc(ctx
->opcode
) != 0))
4713 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4717 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
)
4719 uint32_t mb
= MB(ctx
->opcode
);
4720 uint32_t me
= ME(ctx
->opcode
);
4721 TCGv t0
= tcg_temp_new();
4722 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4723 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4724 tcg_gen_andi_tl(t0
, t0
, MASK(mb
, me
));
4725 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~MASK(mb
, me
));
4726 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], t0
);
4728 if (unlikely(Rc(ctx
->opcode
) != 0))
4729 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4733 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
)
4735 TCGv t0
= tcg_temp_new();
4736 TCGv t1
= tcg_temp_new();
4737 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4738 tcg_gen_movi_tl(t1
, 0x80000000);
4739 tcg_gen_shr_tl(t1
, t1
, t0
);
4740 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4741 tcg_gen_and_tl(t0
, t0
, t1
);
4742 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], t1
);
4743 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4746 if (unlikely(Rc(ctx
->opcode
) != 0))
4747 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4751 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
)
4753 TCGv t0
= tcg_temp_new();
4754 TCGv t1
= tcg_temp_new();
4755 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4756 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4757 tcg_gen_subfi_tl(t1
, 32, t1
);
4758 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4759 tcg_gen_or_tl(t1
, t0
, t1
);
4760 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4761 gen_store_spr(SPR_MQ
, t1
);
4764 if (unlikely(Rc(ctx
->opcode
) != 0))
4765 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4769 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
)
4771 TCGv t0
= tcg_temp_new();
4772 TCGv t1
= tcg_temp_new();
4773 TCGv t2
= tcg_temp_new();
4774 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4775 tcg_gen_movi_tl(t2
, 0xFFFFFFFF);
4776 tcg_gen_shl_tl(t2
, t2
, t0
);
4777 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4778 gen_load_spr(t1
, SPR_MQ
);
4779 gen_store_spr(SPR_MQ
, t0
);
4780 tcg_gen_and_tl(t0
, t0
, t2
);
4781 tcg_gen_andc_tl(t1
, t1
, t2
);
4782 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4786 if (unlikely(Rc(ctx
->opcode
) != 0))
4787 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4791 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
)
4793 int sh
= SH(ctx
->opcode
);
4794 TCGv t0
= tcg_temp_new();
4795 TCGv t1
= tcg_temp_new();
4796 tcg_gen_shli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4797 tcg_gen_shri_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
4798 tcg_gen_or_tl(t1
, t0
, t1
);
4799 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4800 gen_store_spr(SPR_MQ
, t1
);
4803 if (unlikely(Rc(ctx
->opcode
) != 0))
4804 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4807 /* slliq - slliq. */
4808 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
)
4810 int sh
= SH(ctx
->opcode
);
4811 TCGv t0
= tcg_temp_new();
4812 TCGv t1
= tcg_temp_new();
4813 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4814 gen_load_spr(t1
, SPR_MQ
);
4815 gen_store_spr(SPR_MQ
, t0
);
4816 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
<< sh
));
4817 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
<< sh
));
4818 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4821 if (unlikely(Rc(ctx
->opcode
) != 0))
4822 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4826 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
)
4828 int l1
= gen_new_label();
4829 int l2
= gen_new_label();
4830 TCGv t0
= tcg_temp_local_new();
4831 TCGv t1
= tcg_temp_local_new();
4832 TCGv t2
= tcg_temp_local_new();
4833 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4834 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
4835 tcg_gen_shl_tl(t1
, t1
, t2
);
4836 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4837 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
4838 gen_load_spr(t0
, SPR_MQ
);
4839 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4842 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4843 gen_load_spr(t2
, SPR_MQ
);
4844 tcg_gen_andc_tl(t1
, t2
, t1
);
4845 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4850 if (unlikely(Rc(ctx
->opcode
) != 0))
4851 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4855 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
)
4857 int l1
= gen_new_label();
4858 TCGv t0
= tcg_temp_new();
4859 TCGv t1
= tcg_temp_new();
4860 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4861 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4862 tcg_gen_subfi_tl(t1
, 32, t1
);
4863 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4864 tcg_gen_or_tl(t1
, t0
, t1
);
4865 gen_store_spr(SPR_MQ
, t1
);
4866 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4867 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4868 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
4869 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
4873 if (unlikely(Rc(ctx
->opcode
) != 0))
4874 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4877 /* sraiq - sraiq. */
4878 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
)
4880 int sh
= SH(ctx
->opcode
);
4881 int l1
= gen_new_label();
4882 TCGv t0
= tcg_temp_new();
4883 TCGv t1
= tcg_temp_new();
4884 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4885 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
4886 tcg_gen_or_tl(t0
, t0
, t1
);
4887 gen_store_spr(SPR_MQ
, t0
);
4888 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
4889 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
4890 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
4891 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_CA
));
4893 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
4896 if (unlikely(Rc(ctx
->opcode
) != 0))
4897 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4901 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
)
4903 int l1
= gen_new_label();
4904 int l2
= gen_new_label();
4905 TCGv t0
= tcg_temp_new();
4906 TCGv t1
= tcg_temp_local_new();
4907 TCGv t2
= tcg_temp_local_new();
4908 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4909 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4910 tcg_gen_sar_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4911 tcg_gen_subfi_tl(t2
, 32, t2
);
4912 tcg_gen_shl_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4913 tcg_gen_or_tl(t0
, t0
, t2
);
4914 gen_store_spr(SPR_MQ
, t0
);
4915 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4916 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l1
);
4917 tcg_gen_mov_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
4918 tcg_gen_sari_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 31);
4921 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
);
4922 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
4923 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
4924 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l2
);
4925 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_CA
));
4929 if (unlikely(Rc(ctx
->opcode
) != 0))
4930 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4934 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
)
4936 TCGv t0
= tcg_temp_new();
4937 TCGv t1
= tcg_temp_new();
4938 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4939 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4940 tcg_gen_subfi_tl(t1
, 32, t1
);
4941 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4942 tcg_gen_or_tl(t1
, t0
, t1
);
4943 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4944 gen_store_spr(SPR_MQ
, t1
);
4947 if (unlikely(Rc(ctx
->opcode
) != 0))
4948 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4952 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
)
4954 TCGv t0
= tcg_temp_new();
4955 TCGv t1
= tcg_temp_new();
4956 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4957 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4958 gen_store_spr(SPR_MQ
, t0
);
4959 tcg_gen_sar_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t1
);
4962 if (unlikely(Rc(ctx
->opcode
) != 0))
4963 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4967 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
)
4969 TCGv t0
= tcg_temp_new();
4970 TCGv t1
= tcg_temp_new();
4971 TCGv t2
= tcg_temp_new();
4972 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4973 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
4974 tcg_gen_shr_tl(t1
, t1
, t0
);
4975 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4976 gen_load_spr(t2
, SPR_MQ
);
4977 gen_store_spr(SPR_MQ
, t0
);
4978 tcg_gen_and_tl(t0
, t0
, t1
);
4979 tcg_gen_andc_tl(t2
, t2
, t1
);
4980 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
4984 if (unlikely(Rc(ctx
->opcode
) != 0))
4985 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4989 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
)
4991 int sh
= SH(ctx
->opcode
);
4992 TCGv t0
= tcg_temp_new();
4993 TCGv t1
= tcg_temp_new();
4994 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4995 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
4996 tcg_gen_or_tl(t1
, t0
, t1
);
4997 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4998 gen_store_spr(SPR_MQ
, t1
);
5001 if (unlikely(Rc(ctx
->opcode
) != 0))
5002 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5006 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
)
5008 int sh
= SH(ctx
->opcode
);
5009 TCGv t0
= tcg_temp_new();
5010 TCGv t1
= tcg_temp_new();
5011 tcg_gen_rotri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5012 gen_load_spr(t1
, SPR_MQ
);
5013 gen_store_spr(SPR_MQ
, t0
);
5014 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
>> sh
));
5015 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
>> sh
));
5016 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5019 if (unlikely(Rc(ctx
->opcode
) != 0))
5020 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5024 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
)
5026 int l1
= gen_new_label();
5027 int l2
= gen_new_label();
5028 TCGv t0
= tcg_temp_local_new();
5029 TCGv t1
= tcg_temp_local_new();
5030 TCGv t2
= tcg_temp_local_new();
5031 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5032 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5033 tcg_gen_shr_tl(t2
, t1
, t2
);
5034 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5035 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5036 gen_load_spr(t0
, SPR_MQ
);
5037 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5040 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5041 tcg_gen_and_tl(t0
, t0
, t2
);
5042 gen_load_spr(t1
, SPR_MQ
);
5043 tcg_gen_andc_tl(t1
, t1
, t2
);
5044 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5049 if (unlikely(Rc(ctx
->opcode
) != 0))
5050 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5054 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
)
5056 int l1
= gen_new_label();
5057 TCGv t0
= tcg_temp_new();
5058 TCGv t1
= tcg_temp_new();
5059 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5060 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5061 tcg_gen_subfi_tl(t1
, 32, t1
);
5062 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5063 tcg_gen_or_tl(t1
, t0
, t1
);
5064 gen_store_spr(SPR_MQ
, t1
);
5065 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5066 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5067 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5068 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5072 if (unlikely(Rc(ctx
->opcode
) != 0))
5073 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5076 /* PowerPC 602 specific instructions */
5078 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
)
5081 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5085 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
)
5088 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5092 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
)
5094 #if defined(CONFIG_USER_ONLY)
5095 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5097 if (unlikely(!ctx
->mem_idx
)) {
5098 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5101 gen_helper_602_mfrom(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5105 /* 602 - 603 - G2 TLB management */
5107 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
)
5109 #if defined(CONFIG_USER_ONLY)
5110 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5112 if (unlikely(!ctx
->mem_idx
)) {
5113 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5116 gen_helper_6xx_tlbd(cpu_gpr
[rB(ctx
->opcode
)]);
5121 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
)
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
);
5130 gen_helper_6xx_tlbi(cpu_gpr
[rB(ctx
->opcode
)]);
5134 /* 74xx TLB management */
5136 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
)
5138 #if defined(CONFIG_USER_ONLY)
5139 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5141 if (unlikely(!ctx
->mem_idx
)) {
5142 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5145 gen_helper_74xx_tlbd(cpu_gpr
[rB(ctx
->opcode
)]);
5150 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
)
5152 #if defined(CONFIG_USER_ONLY)
5153 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5155 if (unlikely(!ctx
->mem_idx
)) {
5156 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5159 gen_helper_74xx_tlbi(cpu_gpr
[rB(ctx
->opcode
)]);
5163 /* POWER instructions not in PowerPC 601 */
5165 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
)
5167 /* Cache line flush: implemented as no-op */
5171 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
)
5173 /* Cache line invalidate: privileged and treated as no-op */
5174 #if defined(CONFIG_USER_ONLY)
5175 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5177 if (unlikely(!ctx
->mem_idx
)) {
5178 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5185 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
)
5187 /* Data cache line store: treated as no-op */
5190 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
)
5192 #if defined(CONFIG_USER_ONLY)
5193 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5195 int ra
= rA(ctx
->opcode
);
5196 int rd
= rD(ctx
->opcode
);
5198 if (unlikely(!ctx
->mem_idx
)) {
5199 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5202 t0
= tcg_temp_new();
5203 gen_addr_reg_index(ctx
, t0
);
5204 tcg_gen_shri_tl(t0
, t0
, 28);
5205 tcg_gen_andi_tl(t0
, t0
, 0xF);
5206 gen_helper_load_sr(cpu_gpr
[rd
], t0
);
5208 if (ra
!= 0 && ra
!= rd
)
5209 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rd
]);
5213 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
)
5215 #if defined(CONFIG_USER_ONLY)
5216 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5219 if (unlikely(!ctx
->mem_idx
)) {
5220 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5223 t0
= tcg_temp_new();
5224 gen_addr_reg_index(ctx
, t0
);
5225 gen_helper_rac(cpu_gpr
[rD(ctx
->opcode
)], t0
);
5230 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
)
5232 #if defined(CONFIG_USER_ONLY)
5233 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5235 if (unlikely(!ctx
->mem_idx
)) {
5236 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5240 gen_sync_exception(ctx
);
5244 /* svc is not implemented for now */
5246 /* POWER2 specific instructions */
5247 /* Quad manipulation (load/store two floats at a time) */
5250 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
5252 int rd
= rD(ctx
->opcode
);
5254 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5255 t0
= tcg_temp_new();
5256 gen_addr_imm_index(ctx
, t0
, 0);
5257 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5258 gen_addr_add(ctx
, t0
, t0
, 8);
5259 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5264 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
5266 int ra
= rA(ctx
->opcode
);
5267 int rd
= rD(ctx
->opcode
);
5269 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5270 t0
= tcg_temp_new();
5271 t1
= tcg_temp_new();
5272 gen_addr_imm_index(ctx
, t0
, 0);
5273 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5274 gen_addr_add(ctx
, t1
, t0
, 8);
5275 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5277 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5283 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
)
5285 int ra
= rA(ctx
->opcode
);
5286 int rd
= rD(ctx
->opcode
);
5287 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5289 t0
= tcg_temp_new();
5290 gen_addr_reg_index(ctx
, t0
);
5291 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5292 t1
= tcg_temp_new();
5293 gen_addr_add(ctx
, t1
, t0
, 8);
5294 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5297 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5302 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
)
5304 int rd
= rD(ctx
->opcode
);
5306 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5307 t0
= tcg_temp_new();
5308 gen_addr_reg_index(ctx
, t0
);
5309 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5310 gen_addr_add(ctx
, t0
, t0
, 8);
5311 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5316 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
5318 int rd
= rD(ctx
->opcode
);
5320 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5321 t0
= tcg_temp_new();
5322 gen_addr_imm_index(ctx
, t0
, 0);
5323 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5324 gen_addr_add(ctx
, t0
, t0
, 8);
5325 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5330 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
5332 int ra
= rA(ctx
->opcode
);
5333 int rd
= rD(ctx
->opcode
);
5335 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5336 t0
= tcg_temp_new();
5337 gen_addr_imm_index(ctx
, t0
, 0);
5338 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5339 t1
= tcg_temp_new();
5340 gen_addr_add(ctx
, t1
, t0
, 8);
5341 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5344 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5349 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
)
5351 int ra
= rA(ctx
->opcode
);
5352 int rd
= rD(ctx
->opcode
);
5354 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5355 t0
= tcg_temp_new();
5356 gen_addr_reg_index(ctx
, t0
);
5357 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5358 t1
= tcg_temp_new();
5359 gen_addr_add(ctx
, t1
, t0
, 8);
5360 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5363 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5368 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
)
5370 int rd
= rD(ctx
->opcode
);
5372 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5373 t0
= tcg_temp_new();
5374 gen_addr_reg_index(ctx
, t0
);
5375 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5376 gen_addr_add(ctx
, t0
, t0
, 8);
5377 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5381 /* BookE specific instructions */
5382 /* XXX: not implemented on 440 ? */
5383 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
)
5386 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5389 /* XXX: not implemented on 440 ? */
5390 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
)
5392 #if defined(CONFIG_USER_ONLY)
5393 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5396 if (unlikely(!ctx
->mem_idx
)) {
5397 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5400 t0
= tcg_temp_new();
5401 gen_addr_reg_index(ctx
, t0
);
5402 gen_helper_tlbie(cpu_gpr
[rB(ctx
->opcode
)]);
5407 /* All 405 MAC instructions are translated here */
5408 static always_inline
void gen_405_mulladd_insn (DisasContext
*ctx
,
5410 int ra
, int rb
, int rt
, int Rc
)
5414 t0
= tcg_temp_local_new();
5415 t1
= tcg_temp_local_new();
5417 switch (opc3
& 0x0D) {
5419 /* macchw - macchw. - macchwo - macchwo. */
5420 /* macchws - macchws. - macchwso - macchwso. */
5421 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5422 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5423 /* mulchw - mulchw. */
5424 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5425 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5426 tcg_gen_ext16s_tl(t1
, t1
);
5429 /* macchwu - macchwu. - macchwuo - macchwuo. */
5430 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5431 /* mulchwu - mulchwu. */
5432 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5433 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5434 tcg_gen_ext16u_tl(t1
, t1
);
5437 /* machhw - machhw. - machhwo - machhwo. */
5438 /* machhws - machhws. - machhwso - machhwso. */
5439 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5440 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5441 /* mulhhw - mulhhw. */
5442 tcg_gen_sari_tl(t0
, cpu_gpr
[ra
], 16);
5443 tcg_gen_ext16s_tl(t0
, t0
);
5444 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5445 tcg_gen_ext16s_tl(t1
, t1
);
5448 /* machhwu - machhwu. - machhwuo - machhwuo. */
5449 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5450 /* mulhhwu - mulhhwu. */
5451 tcg_gen_shri_tl(t0
, cpu_gpr
[ra
], 16);
5452 tcg_gen_ext16u_tl(t0
, t0
);
5453 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5454 tcg_gen_ext16u_tl(t1
, t1
);
5457 /* maclhw - maclhw. - maclhwo - maclhwo. */
5458 /* maclhws - maclhws. - maclhwso - maclhwso. */
5459 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5460 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5461 /* mullhw - mullhw. */
5462 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5463 tcg_gen_ext16s_tl(t1
, cpu_gpr
[rb
]);
5466 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5467 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5468 /* mullhwu - mullhwu. */
5469 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5470 tcg_gen_ext16u_tl(t1
, cpu_gpr
[rb
]);
5474 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5475 tcg_gen_mul_tl(t1
, t0
, t1
);
5477 /* nmultiply-and-accumulate (0x0E) */
5478 tcg_gen_sub_tl(t0
, cpu_gpr
[rt
], t1
);
5480 /* multiply-and-accumulate (0x0C) */
5481 tcg_gen_add_tl(t0
, cpu_gpr
[rt
], t1
);
5485 /* Check overflow and/or saturate */
5486 int l1
= gen_new_label();
5489 /* Start with XER OV disabled, the most likely case */
5490 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
5494 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t1
);
5495 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
5496 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t0
);
5497 tcg_gen_brcondi_tl(TCG_COND_LT
, t1
, 0, l1
);
5500 tcg_gen_sari_tl(t0
, cpu_gpr
[rt
], 31);
5501 tcg_gen_xori_tl(t0
, t0
, 0x7fffffff);
5505 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
5508 tcg_gen_movi_tl(t0
, UINT32_MAX
);
5512 /* Check overflow */
5513 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
5516 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
5519 tcg_gen_mul_tl(cpu_gpr
[rt
], t0
, t1
);
5523 if (unlikely(Rc
) != 0) {
5525 gen_set_Rc0(ctx
, cpu_gpr
[rt
]);
5529 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5530 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC) \
5532 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5533 rD(ctx->opcode), Rc(ctx->opcode)); \
5536 /* macchw - macchw. */
5537 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
5538 /* macchwo - macchwo. */
5539 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
5540 /* macchws - macchws. */
5541 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
5542 /* macchwso - macchwso. */
5543 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
5544 /* macchwsu - macchwsu. */
5545 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
5546 /* macchwsuo - macchwsuo. */
5547 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
5548 /* macchwu - macchwu. */
5549 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
5550 /* macchwuo - macchwuo. */
5551 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
5552 /* machhw - machhw. */
5553 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
5554 /* machhwo - machhwo. */
5555 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
5556 /* machhws - machhws. */
5557 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
5558 /* machhwso - machhwso. */
5559 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
5560 /* machhwsu - machhwsu. */
5561 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
5562 /* machhwsuo - machhwsuo. */
5563 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
5564 /* machhwu - machhwu. */
5565 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
5566 /* machhwuo - machhwuo. */
5567 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
5568 /* maclhw - maclhw. */
5569 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
5570 /* maclhwo - maclhwo. */
5571 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
5572 /* maclhws - maclhws. */
5573 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
5574 /* maclhwso - maclhwso. */
5575 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
5576 /* maclhwu - maclhwu. */
5577 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
5578 /* maclhwuo - maclhwuo. */
5579 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
5580 /* maclhwsu - maclhwsu. */
5581 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
5582 /* maclhwsuo - maclhwsuo. */
5583 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
5584 /* nmacchw - nmacchw. */
5585 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
5586 /* nmacchwo - nmacchwo. */
5587 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
5588 /* nmacchws - nmacchws. */
5589 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
5590 /* nmacchwso - nmacchwso. */
5591 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
5592 /* nmachhw - nmachhw. */
5593 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
5594 /* nmachhwo - nmachhwo. */
5595 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
5596 /* nmachhws - nmachhws. */
5597 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
5598 /* nmachhwso - nmachhwso. */
5599 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
5600 /* nmaclhw - nmaclhw. */
5601 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
5602 /* nmaclhwo - nmaclhwo. */
5603 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
5604 /* nmaclhws - nmaclhws. */
5605 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
5606 /* nmaclhwso - nmaclhwso. */
5607 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
5609 /* mulchw - mulchw. */
5610 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
5611 /* mulchwu - mulchwu. */
5612 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
5613 /* mulhhw - mulhhw. */
5614 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
5615 /* mulhhwu - mulhhwu. */
5616 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
5617 /* mullhw - mullhw. */
5618 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
5619 /* mullhwu - mullhwu. */
5620 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
5623 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
)
5625 #if defined(CONFIG_USER_ONLY)
5626 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5629 if (unlikely(!ctx
->mem_idx
)) {
5630 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5633 /* NIP cannot be restored if the memory exception comes from an helper */
5634 gen_update_nip(ctx
, ctx
->nip
- 4);
5635 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5636 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], dcrn
);
5637 tcg_temp_free(dcrn
);
5642 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
)
5644 #if defined(CONFIG_USER_ONLY)
5645 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5648 if (unlikely(!ctx
->mem_idx
)) {
5649 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5652 /* NIP cannot be restored if the memory exception comes from an helper */
5653 gen_update_nip(ctx
, ctx
->nip
- 4);
5654 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5655 gen_helper_store_dcr(dcrn
, cpu_gpr
[rS(ctx
->opcode
)]);
5656 tcg_temp_free(dcrn
);
5661 /* XXX: not implemented on 440 ? */
5662 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
)
5664 #if defined(CONFIG_USER_ONLY)
5665 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5667 if (unlikely(!ctx
->mem_idx
)) {
5668 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5671 /* NIP cannot be restored if the memory exception comes from an helper */
5672 gen_update_nip(ctx
, ctx
->nip
- 4);
5673 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5674 /* Note: Rc update flag set leads to undefined state of Rc0 */
5679 /* XXX: not implemented on 440 ? */
5680 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
)
5682 #if defined(CONFIG_USER_ONLY)
5683 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5685 if (unlikely(!ctx
->mem_idx
)) {
5686 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5689 /* NIP cannot be restored if the memory exception comes from an helper */
5690 gen_update_nip(ctx
, ctx
->nip
- 4);
5691 gen_helper_store_dcr(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
5692 /* Note: Rc update flag set leads to undefined state of Rc0 */
5696 /* mfdcrux (PPC 460) : user-mode access to DCR */
5697 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
)
5699 /* NIP cannot be restored if the memory exception comes from an helper */
5700 gen_update_nip(ctx
, ctx
->nip
- 4);
5701 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5702 /* Note: Rc update flag set leads to undefined state of Rc0 */
5705 /* mtdcrux (PPC 460) : user-mode access to DCR */
5706 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
)
5708 /* NIP cannot be restored if the memory exception comes from an helper */
5709 gen_update_nip(ctx
, ctx
->nip
- 4);
5710 gen_helper_store_dcr(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
5711 /* Note: Rc update flag set leads to undefined state of Rc0 */
5715 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
)
5717 #if defined(CONFIG_USER_ONLY)
5718 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5720 if (unlikely(!ctx
->mem_idx
)) {
5721 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5724 /* interpreted as no-op */
5729 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
)
5731 #if defined(CONFIG_USER_ONLY)
5732 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5735 if (unlikely(!ctx
->mem_idx
)) {
5736 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5739 gen_set_access_type(ctx
, ACCESS_CACHE
);
5740 EA
= tcg_temp_new();
5741 gen_addr_reg_index(ctx
, EA
);
5742 val
= tcg_temp_new();
5743 gen_qemu_ld32u(ctx
, val
, EA
);
5745 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], EA
);
5751 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
)
5753 /* interpreted as no-op */
5754 /* XXX: specification say this is treated as a load by the MMU
5755 * but does not generate any exception
5760 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
)
5762 #if defined(CONFIG_USER_ONLY)
5763 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5765 if (unlikely(!ctx
->mem_idx
)) {
5766 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5769 /* interpreted as no-op */
5774 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
)
5776 #if defined(CONFIG_USER_ONLY)
5777 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5779 if (unlikely(!ctx
->mem_idx
)) {
5780 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5783 /* interpreted as no-op */
5787 /* rfci (mem_idx only) */
5788 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
)
5790 #if defined(CONFIG_USER_ONLY)
5791 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5793 if (unlikely(!ctx
->mem_idx
)) {
5794 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5797 /* Restore CPU state */
5798 gen_helper_40x_rfci();
5799 gen_sync_exception(ctx
);
5803 GEN_HANDLER(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
)
5805 #if defined(CONFIG_USER_ONLY)
5806 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5808 if (unlikely(!ctx
->mem_idx
)) {
5809 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5812 /* Restore CPU state */
5814 gen_sync_exception(ctx
);
5818 /* BookE specific */
5819 /* XXX: not implemented on 440 ? */
5820 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
)
5822 #if defined(CONFIG_USER_ONLY)
5823 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5825 if (unlikely(!ctx
->mem_idx
)) {
5826 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5829 /* Restore CPU state */
5831 gen_sync_exception(ctx
);
5835 /* XXX: not implemented on 440 ? */
5836 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
)
5838 #if defined(CONFIG_USER_ONLY)
5839 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5841 if (unlikely(!ctx
->mem_idx
)) {
5842 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5845 /* Restore CPU state */
5847 gen_sync_exception(ctx
);
5851 /* TLB management - PowerPC 405 implementation */
5853 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
)
5855 #if defined(CONFIG_USER_ONLY)
5856 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5858 if (unlikely(!ctx
->mem_idx
)) {
5859 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5862 switch (rB(ctx
->opcode
)) {
5864 gen_helper_4xx_tlbre_hi(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5867 gen_helper_4xx_tlbre_lo(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5870 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5876 /* tlbsx - tlbsx. */
5877 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
)
5879 #if defined(CONFIG_USER_ONLY)
5880 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5883 if (unlikely(!ctx
->mem_idx
)) {
5884 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5887 t0
= tcg_temp_new();
5888 gen_addr_reg_index(ctx
, t0
);
5889 gen_helper_4xx_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], t0
);
5891 if (Rc(ctx
->opcode
)) {
5892 int l1
= gen_new_label();
5893 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_xer
);
5894 tcg_gen_shri_i32(cpu_crf
[0], cpu_crf
[0], XER_SO
);
5895 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 1);
5896 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
5897 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
5904 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
)
5906 #if defined(CONFIG_USER_ONLY)
5907 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5909 if (unlikely(!ctx
->mem_idx
)) {
5910 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5913 switch (rB(ctx
->opcode
)) {
5915 gen_helper_4xx_tlbwe_hi(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
5918 gen_helper_4xx_tlbwe_lo(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
5921 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5927 /* TLB management - PowerPC 440 implementation */
5929 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
)
5931 #if defined(CONFIG_USER_ONLY)
5932 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5934 if (unlikely(!ctx
->mem_idx
)) {
5935 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5938 switch (rB(ctx
->opcode
)) {
5943 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
5944 gen_helper_440_tlbwe(t0
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5945 tcg_temp_free_i32(t0
);
5949 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5955 /* tlbsx - tlbsx. */
5956 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
)
5958 #if defined(CONFIG_USER_ONLY)
5959 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5962 if (unlikely(!ctx
->mem_idx
)) {
5963 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5966 t0
= tcg_temp_new();
5967 gen_addr_reg_index(ctx
, t0
);
5968 gen_helper_440_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], t0
);
5970 if (Rc(ctx
->opcode
)) {
5971 int l1
= gen_new_label();
5972 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_xer
);
5973 tcg_gen_shri_i32(cpu_crf
[0], cpu_crf
[0], XER_SO
);
5974 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 1);
5975 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
5976 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
5983 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
)
5985 #if defined(CONFIG_USER_ONLY)
5986 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5988 if (unlikely(!ctx
->mem_idx
)) {
5989 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5992 switch (rB(ctx
->opcode
)) {
5997 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
5998 gen_helper_440_tlbwe(t0
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
5999 tcg_temp_free_i32(t0
);
6003 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6010 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
)
6012 #if defined(CONFIG_USER_ONLY)
6013 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6016 if (unlikely(!ctx
->mem_idx
)) {
6017 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6020 t0
= tcg_temp_new();
6021 tcg_gen_andi_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)], (1 << MSR_EE
));
6022 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6023 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
6025 /* Stop translation to have a chance to raise an exception
6026 * if we just set msr_ee to 1
6028 gen_stop_exception(ctx
);
6033 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000EFC01, PPC_WRTEE
)
6035 #if defined(CONFIG_USER_ONLY)
6036 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6038 if (unlikely(!ctx
->mem_idx
)) {
6039 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6042 if (ctx
->opcode
& 0x00010000) {
6043 tcg_gen_ori_tl(cpu_msr
, cpu_msr
, (1 << MSR_EE
));
6044 /* Stop translation to have a chance to raise an exception */
6045 gen_stop_exception(ctx
);
6047 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, (1 << MSR_EE
));
6052 /* PowerPC 440 specific instructions */
6054 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
)
6056 TCGv_i32 t0
= tcg_const_i32(Rc(ctx
->opcode
));
6057 gen_helper_dlmzb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
6058 cpu_gpr
[rB(ctx
->opcode
)], t0
);
6059 tcg_temp_free_i32(t0
);
6062 /* mbar replaces eieio on 440 */
6063 GEN_HANDLER(mbar
, 0x1F, 0x16, 0x1a, 0x001FF801, PPC_BOOKE
)
6065 /* interpreted as no-op */
6068 /* msync replaces sync on 440 */
6069 GEN_HANDLER(msync
, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE
)
6071 /* interpreted as no-op */
6075 GEN_HANDLER2(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001, PPC_BOOKE
)
6077 /* interpreted as no-op */
6078 /* XXX: specification say this is treated as a load by the MMU
6079 * but does not generate any exception
6083 /*** Altivec vector extension ***/
6084 /* Altivec registers moves */
6086 #define GEN_VR_LDX(name, opc2, opc3) \
6087 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
6090 if (unlikely(!ctx->altivec_enabled)) { \
6091 gen_exception(ctx, POWERPC_EXCP_VPU); \
6094 gen_set_access_type(ctx, ACCESS_INT); \
6095 EA = tcg_temp_new(); \
6096 gen_addr_reg_index(ctx, EA); \
6097 tcg_gen_andi_tl(EA, EA, ~0xf); \
6098 if (ctx->le_mode) { \
6099 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6100 tcg_gen_addi_tl(EA, EA, 8); \
6101 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6103 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6104 tcg_gen_addi_tl(EA, EA, 8); \
6105 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6107 tcg_temp_free(EA); \
6110 #define GEN_VR_STX(name, opc2, opc3) \
6111 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
6114 if (unlikely(!ctx->altivec_enabled)) { \
6115 gen_exception(ctx, POWERPC_EXCP_VPU); \
6118 gen_set_access_type(ctx, ACCESS_INT); \
6119 EA = tcg_temp_new(); \
6120 gen_addr_reg_index(ctx, EA); \
6121 tcg_gen_andi_tl(EA, EA, ~0xf); \
6122 if (ctx->le_mode) { \
6123 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6124 tcg_gen_addi_tl(EA, EA, 8); \
6125 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6127 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6128 tcg_gen_addi_tl(EA, EA, 8); \
6129 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6131 tcg_temp_free(EA); \
6134 GEN_VR_LDX(lvx
, 0x07, 0x03);
6135 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
6136 GEN_VR_LDX(lvxl
, 0x07, 0x0B);
6138 GEN_VR_STX(svx
, 0x07, 0x07);
6139 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
6140 GEN_VR_STX(svxl
, 0x07, 0x0F);
6142 /* Logical operations */
6143 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
6144 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) \
6146 if (unlikely(!ctx->altivec_enabled)) { \
6147 gen_exception(ctx, POWERPC_EXCP_VPU); \
6150 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6151 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6154 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16);
6155 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17);
6156 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18);
6157 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19);
6158 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20);
6160 /*** SPE extension ***/
6161 /* Register moves */
6163 static always_inline
void gen_load_gpr64(TCGv_i64 t
, int reg
) {
6164 #if defined(TARGET_PPC64)
6165 tcg_gen_mov_i64(t
, cpu_gpr
[reg
]);
6167 tcg_gen_concat_i32_i64(t
, cpu_gpr
[reg
], cpu_gprh
[reg
]);
6171 static always_inline
void gen_store_gpr64(int reg
, TCGv_i64 t
) {
6172 #if defined(TARGET_PPC64)
6173 tcg_gen_mov_i64(cpu_gpr
[reg
], t
);
6175 TCGv_i64 tmp
= tcg_temp_new_i64();
6176 tcg_gen_trunc_i64_i32(cpu_gpr
[reg
], t
);
6177 tcg_gen_shri_i64(tmp
, t
, 32);
6178 tcg_gen_trunc_i64_i32(cpu_gprh
[reg
], tmp
);
6179 tcg_temp_free_i64(tmp
);
6183 #define GEN_SPE(name0, name1, opc2, opc3, inval, type) \
6184 GEN_HANDLER(name0##_##name1, 0x04, opc2, opc3, inval, type) \
6186 if (Rc(ctx->opcode)) \
6192 /* Handler for undefined SPE opcodes */
6193 static always_inline
void gen_speundef (DisasContext
*ctx
)
6195 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6199 #if defined(TARGET_PPC64)
6200 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
6201 static always_inline void gen_##name (DisasContext *ctx) \
6203 if (unlikely(!ctx->spe_enabled)) { \
6204 gen_exception(ctx, POWERPC_EXCP_APU); \
6207 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6208 cpu_gpr[rB(ctx->opcode)]); \
6211 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
6212 static always_inline void gen_##name (DisasContext *ctx) \
6214 if (unlikely(!ctx->spe_enabled)) { \
6215 gen_exception(ctx, POWERPC_EXCP_APU); \
6218 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6219 cpu_gpr[rB(ctx->opcode)]); \
6220 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6221 cpu_gprh[rB(ctx->opcode)]); \
6225 GEN_SPEOP_LOGIC2(evand
, tcg_gen_and_tl
);
6226 GEN_SPEOP_LOGIC2(evandc
, tcg_gen_andc_tl
);
6227 GEN_SPEOP_LOGIC2(evxor
, tcg_gen_xor_tl
);
6228 GEN_SPEOP_LOGIC2(evor
, tcg_gen_or_tl
);
6229 GEN_SPEOP_LOGIC2(evnor
, tcg_gen_nor_tl
);
6230 GEN_SPEOP_LOGIC2(eveqv
, tcg_gen_eqv_tl
);
6231 GEN_SPEOP_LOGIC2(evorc
, tcg_gen_orc_tl
);
6232 GEN_SPEOP_LOGIC2(evnand
, tcg_gen_nand_tl
);
6234 /* SPE logic immediate */
6235 #if defined(TARGET_PPC64)
6236 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
6237 static always_inline void gen_##name (DisasContext *ctx) \
6239 if (unlikely(!ctx->spe_enabled)) { \
6240 gen_exception(ctx, POWERPC_EXCP_APU); \
6243 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6244 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6245 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6246 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6247 tcg_opi(t0, t0, rB(ctx->opcode)); \
6248 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6249 tcg_gen_trunc_i64_i32(t1, t2); \
6250 tcg_temp_free_i64(t2); \
6251 tcg_opi(t1, t1, rB(ctx->opcode)); \
6252 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6253 tcg_temp_free_i32(t0); \
6254 tcg_temp_free_i32(t1); \
6257 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
6258 static always_inline void gen_##name (DisasContext *ctx) \
6260 if (unlikely(!ctx->spe_enabled)) { \
6261 gen_exception(ctx, POWERPC_EXCP_APU); \
6264 tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6266 tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6270 GEN_SPEOP_TCG_LOGIC_IMM2(evslwi
, tcg_gen_shli_i32
);
6271 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu
, tcg_gen_shri_i32
);
6272 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis
, tcg_gen_sari_i32
);
6273 GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi
, tcg_gen_rotli_i32
);
6275 /* SPE arithmetic */
6276 #if defined(TARGET_PPC64)
6277 #define GEN_SPEOP_ARITH1(name, tcg_op) \
6278 static always_inline void gen_##name (DisasContext *ctx) \
6280 if (unlikely(!ctx->spe_enabled)) { \
6281 gen_exception(ctx, POWERPC_EXCP_APU); \
6284 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6285 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6286 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6287 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6289 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6290 tcg_gen_trunc_i64_i32(t1, t2); \
6291 tcg_temp_free_i64(t2); \
6293 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6294 tcg_temp_free_i32(t0); \
6295 tcg_temp_free_i32(t1); \
6298 #define GEN_SPEOP_ARITH1(name, tcg_op) \
6299 static always_inline void gen_##name (DisasContext *ctx) \
6301 if (unlikely(!ctx->spe_enabled)) { \
6302 gen_exception(ctx, POWERPC_EXCP_APU); \
6305 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
6306 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
6310 static always_inline
void gen_op_evabs (TCGv_i32 ret
, TCGv_i32 arg1
)
6312 int l1
= gen_new_label();
6313 int l2
= gen_new_label();
6315 tcg_gen_brcondi_i32(TCG_COND_GE
, arg1
, 0, l1
);
6316 tcg_gen_neg_i32(ret
, arg1
);
6319 tcg_gen_mov_i32(ret
, arg1
);
6322 GEN_SPEOP_ARITH1(evabs
, gen_op_evabs
);
6323 GEN_SPEOP_ARITH1(evneg
, tcg_gen_neg_i32
);
6324 GEN_SPEOP_ARITH1(evextsb
, tcg_gen_ext8s_i32
);
6325 GEN_SPEOP_ARITH1(evextsh
, tcg_gen_ext16s_i32
);
6326 static always_inline
void gen_op_evrndw (TCGv_i32 ret
, TCGv_i32 arg1
)
6328 tcg_gen_addi_i32(ret
, arg1
, 0x8000);
6329 tcg_gen_ext16u_i32(ret
, ret
);
6331 GEN_SPEOP_ARITH1(evrndw
, gen_op_evrndw
);
6332 GEN_SPEOP_ARITH1(evcntlsw
, gen_helper_cntlsw32
);
6333 GEN_SPEOP_ARITH1(evcntlzw
, gen_helper_cntlzw32
);
6335 #if defined(TARGET_PPC64)
6336 #define GEN_SPEOP_ARITH2(name, tcg_op) \
6337 static always_inline void gen_##name (DisasContext *ctx) \
6339 if (unlikely(!ctx->spe_enabled)) { \
6340 gen_exception(ctx, POWERPC_EXCP_APU); \
6343 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6344 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6345 TCGv_i32 t2 = tcg_temp_local_new_i32(); \
6346 TCGv_i64 t3 = tcg_temp_local_new(TCG_TYPE_I64); \
6347 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6348 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
6349 tcg_op(t0, t0, t2); \
6350 tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
6351 tcg_gen_trunc_i64_i32(t1, t3); \
6352 tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
6353 tcg_gen_trunc_i64_i32(t2, t3); \
6354 tcg_temp_free_i64(t3); \
6355 tcg_op(t1, t1, t2); \
6356 tcg_temp_free_i32(t2); \
6357 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6358 tcg_temp_free_i32(t0); \
6359 tcg_temp_free_i32(t1); \
6362 #define GEN_SPEOP_ARITH2(name, tcg_op) \
6363 static always_inline void gen_##name (DisasContext *ctx) \
6365 if (unlikely(!ctx->spe_enabled)) { \
6366 gen_exception(ctx, POWERPC_EXCP_APU); \
6369 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6370 cpu_gpr[rB(ctx->opcode)]); \
6371 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6372 cpu_gprh[rB(ctx->opcode)]); \
6376 static always_inline
void gen_op_evsrwu (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6381 l1
= gen_new_label();
6382 l2
= gen_new_label();
6383 t0
= tcg_temp_local_new_i32();
6384 /* No error here: 6 bits are used */
6385 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
6386 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
6387 tcg_gen_shr_i32(ret
, arg1
, t0
);
6390 tcg_gen_movi_i32(ret
, 0);
6392 tcg_temp_free_i32(t0
);
6394 GEN_SPEOP_ARITH2(evsrwu
, gen_op_evsrwu
);
6395 static always_inline
void gen_op_evsrws (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6400 l1
= gen_new_label();
6401 l2
= gen_new_label();
6402 t0
= tcg_temp_local_new_i32();
6403 /* No error here: 6 bits are used */
6404 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
6405 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
6406 tcg_gen_sar_i32(ret
, arg1
, t0
);
6409 tcg_gen_movi_i32(ret
, 0);
6411 tcg_temp_free_i32(t0
);
6413 GEN_SPEOP_ARITH2(evsrws
, gen_op_evsrws
);
6414 static always_inline
void gen_op_evslw (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6419 l1
= gen_new_label();
6420 l2
= gen_new_label();
6421 t0
= tcg_temp_local_new_i32();
6422 /* No error here: 6 bits are used */
6423 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
6424 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
6425 tcg_gen_shl_i32(ret
, arg1
, t0
);
6428 tcg_gen_movi_i32(ret
, 0);
6430 tcg_temp_free_i32(t0
);
6432 GEN_SPEOP_ARITH2(evslw
, gen_op_evslw
);
6433 static always_inline
void gen_op_evrlw (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6435 TCGv_i32 t0
= tcg_temp_new_i32();
6436 tcg_gen_andi_i32(t0
, arg2
, 0x1F);
6437 tcg_gen_rotl_i32(ret
, arg1
, t0
);
6438 tcg_temp_free_i32(t0
);
6440 GEN_SPEOP_ARITH2(evrlw
, gen_op_evrlw
);
6441 static always_inline
void gen_evmergehi (DisasContext
*ctx
)
6443 if (unlikely(!ctx
->spe_enabled
)) {
6444 gen_exception(ctx
, POWERPC_EXCP_APU
);
6447 #if defined(TARGET_PPC64)
6448 TCGv t0
= tcg_temp_new();
6449 TCGv t1
= tcg_temp_new();
6450 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
6451 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
6452 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
6456 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
6457 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6460 GEN_SPEOP_ARITH2(evaddw
, tcg_gen_add_i32
);
6461 static always_inline
void gen_op_evsubf (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6463 tcg_gen_sub_i32(ret
, arg2
, arg1
);
6465 GEN_SPEOP_ARITH2(evsubfw
, gen_op_evsubf
);
6467 /* SPE arithmetic immediate */
6468 #if defined(TARGET_PPC64)
6469 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
6470 static always_inline void gen_##name (DisasContext *ctx) \
6472 if (unlikely(!ctx->spe_enabled)) { \
6473 gen_exception(ctx, POWERPC_EXCP_APU); \
6476 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6477 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6478 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6479 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
6480 tcg_op(t0, t0, rA(ctx->opcode)); \
6481 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
6482 tcg_gen_trunc_i64_i32(t1, t2); \
6483 tcg_temp_free_i64(t2); \
6484 tcg_op(t1, t1, rA(ctx->opcode)); \
6485 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6486 tcg_temp_free_i32(t0); \
6487 tcg_temp_free_i32(t1); \
6490 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
6491 static always_inline void gen_##name (DisasContext *ctx) \
6493 if (unlikely(!ctx->spe_enabled)) { \
6494 gen_exception(ctx, POWERPC_EXCP_APU); \
6497 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
6499 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
6503 GEN_SPEOP_ARITH_IMM2(evaddiw
, tcg_gen_addi_i32
);
6504 GEN_SPEOP_ARITH_IMM2(evsubifw
, tcg_gen_subi_i32
);
6506 /* SPE comparison */
6507 #if defined(TARGET_PPC64)
6508 #define GEN_SPEOP_COMP(name, tcg_cond) \
6509 static always_inline void gen_##name (DisasContext *ctx) \
6511 if (unlikely(!ctx->spe_enabled)) { \
6512 gen_exception(ctx, POWERPC_EXCP_APU); \
6515 int l1 = gen_new_label(); \
6516 int l2 = gen_new_label(); \
6517 int l3 = gen_new_label(); \
6518 int l4 = gen_new_label(); \
6519 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6520 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6521 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6522 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6523 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
6524 tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
6525 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
6527 gen_set_label(l1); \
6528 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
6529 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
6530 gen_set_label(l2); \
6531 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6532 tcg_gen_trunc_i64_i32(t0, t2); \
6533 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
6534 tcg_gen_trunc_i64_i32(t1, t2); \
6535 tcg_temp_free_i64(t2); \
6536 tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
6537 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6538 ~(CRF_CH | CRF_CH_AND_CL)); \
6540 gen_set_label(l3); \
6541 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6542 CRF_CH | CRF_CH_OR_CL); \
6543 gen_set_label(l4); \
6544 tcg_temp_free_i32(t0); \
6545 tcg_temp_free_i32(t1); \
6548 #define GEN_SPEOP_COMP(name, tcg_cond) \
6549 static always_inline void gen_##name (DisasContext *ctx) \
6551 if (unlikely(!ctx->spe_enabled)) { \
6552 gen_exception(ctx, POWERPC_EXCP_APU); \
6555 int l1 = gen_new_label(); \
6556 int l2 = gen_new_label(); \
6557 int l3 = gen_new_label(); \
6558 int l4 = gen_new_label(); \
6560 tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
6561 cpu_gpr[rB(ctx->opcode)], l1); \
6562 tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
6564 gen_set_label(l1); \
6565 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
6566 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
6567 gen_set_label(l2); \
6568 tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
6569 cpu_gprh[rB(ctx->opcode)], l3); \
6570 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6571 ~(CRF_CH | CRF_CH_AND_CL)); \
6573 gen_set_label(l3); \
6574 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6575 CRF_CH | CRF_CH_OR_CL); \
6576 gen_set_label(l4); \
6579 GEN_SPEOP_COMP(evcmpgtu
, TCG_COND_GTU
);
6580 GEN_SPEOP_COMP(evcmpgts
, TCG_COND_GT
);
6581 GEN_SPEOP_COMP(evcmpltu
, TCG_COND_LTU
);
6582 GEN_SPEOP_COMP(evcmplts
, TCG_COND_LT
);
6583 GEN_SPEOP_COMP(evcmpeq
, TCG_COND_EQ
);
6586 static always_inline
void gen_brinc (DisasContext
*ctx
)
6588 /* Note: brinc is usable even if SPE is disabled */
6589 gen_helper_brinc(cpu_gpr
[rD(ctx
->opcode
)],
6590 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6592 static always_inline
void gen_evmergelo (DisasContext
*ctx
)
6594 if (unlikely(!ctx
->spe_enabled
)) {
6595 gen_exception(ctx
, POWERPC_EXCP_APU
);
6598 #if defined(TARGET_PPC64)
6599 TCGv t0
= tcg_temp_new();
6600 TCGv t1
= tcg_temp_new();
6601 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x00000000FFFFFFFFLL
);
6602 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
6603 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
6607 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6608 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6611 static always_inline
void gen_evmergehilo (DisasContext
*ctx
)
6613 if (unlikely(!ctx
->spe_enabled
)) {
6614 gen_exception(ctx
, POWERPC_EXCP_APU
);
6617 #if defined(TARGET_PPC64)
6618 TCGv t0
= tcg_temp_new();
6619 TCGv t1
= tcg_temp_new();
6620 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x00000000FFFFFFFFLL
);
6621 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
6622 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
6626 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6627 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6630 static always_inline
void gen_evmergelohi (DisasContext
*ctx
)
6632 if (unlikely(!ctx
->spe_enabled
)) {
6633 gen_exception(ctx
, POWERPC_EXCP_APU
);
6636 #if defined(TARGET_PPC64)
6637 TCGv t0
= tcg_temp_new();
6638 TCGv t1
= tcg_temp_new();
6639 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
6640 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
6641 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
6645 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
6646 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6649 static always_inline
void gen_evsplati (DisasContext
*ctx
)
6651 uint64_t imm
= ((int32_t)(rA(ctx
->opcode
) << 11)) >> 27;
6653 #if defined(TARGET_PPC64)
6654 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
6656 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
6657 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
6660 static always_inline
void gen_evsplatfi (DisasContext
*ctx
)
6662 uint64_t imm
= rA(ctx
->opcode
) << 11;
6664 #if defined(TARGET_PPC64)
6665 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
6667 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
6668 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
6672 static always_inline
void gen_evsel (DisasContext
*ctx
)
6674 int l1
= gen_new_label();
6675 int l2
= gen_new_label();
6676 int l3
= gen_new_label();
6677 int l4
= gen_new_label();
6678 TCGv_i32 t0
= tcg_temp_local_new_i32();
6679 #if defined(TARGET_PPC64)
6680 TCGv t1
= tcg_temp_local_new();
6681 TCGv t2
= tcg_temp_local_new();
6683 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 3);
6684 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
6685 #if defined(TARGET_PPC64)
6686 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
6688 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6692 #if defined(TARGET_PPC64)
6693 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
6695 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
6698 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 2);
6699 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l3
);
6700 #if defined(TARGET_PPC64)
6701 tcg_gen_andi_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], 0x00000000FFFFFFFFULL
);
6703 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6707 #if defined(TARGET_PPC64)
6708 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x00000000FFFFFFFFULL
);
6710 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6713 tcg_temp_free_i32(t0
);
6714 #if defined(TARGET_PPC64)
6715 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
, t2
);
6720 GEN_HANDLER2(evsel0
, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE
)
6724 GEN_HANDLER2(evsel1
, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE
)
6728 GEN_HANDLER2(evsel2
, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE
)
6732 GEN_HANDLER2(evsel3
, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE
)
6737 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, PPC_SPE
); ////
6738 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, PPC_SPE
);
6739 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, PPC_SPE
); ////
6740 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, PPC_SPE
);
6741 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, PPC_SPE
); ////
6742 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, PPC_SPE
); ////
6743 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, PPC_SPE
); ////
6744 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x00000000, PPC_SPE
); //
6745 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0x00000000, PPC_SPE
); ////
6746 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, PPC_SPE
); ////
6747 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, PPC_SPE
); ////
6748 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, PPC_SPE
); ////
6749 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0x00000000, PPC_SPE
); ////
6750 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, PPC_SPE
); ////
6751 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, PPC_SPE
); ////
6752 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, PPC_SPE
);
6753 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, PPC_SPE
); ////
6754 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, PPC_SPE
);
6755 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, PPC_SPE
); //
6756 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, PPC_SPE
);
6757 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, PPC_SPE
); ////
6758 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, PPC_SPE
); ////
6759 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, PPC_SPE
); ////
6760 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, PPC_SPE
); ////
6761 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, PPC_SPE
); ////
6763 /* SPE load and stores */
6764 static always_inline
void gen_addr_spe_imm_index (DisasContext
*ctx
, TCGv EA
, int sh
)
6766 target_ulong uimm
= rB(ctx
->opcode
);
6768 if (rA(ctx
->opcode
) == 0) {
6769 tcg_gen_movi_tl(EA
, uimm
<< sh
);
6771 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], uimm
<< sh
);
6772 #if defined(TARGET_PPC64)
6773 if (!ctx
->sf_mode
) {
6774 tcg_gen_ext32u_tl(EA
, EA
);
6780 static always_inline
void gen_op_evldd(DisasContext
*ctx
, TCGv addr
)
6782 #if defined(TARGET_PPC64)
6783 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
6785 TCGv_i64 t0
= tcg_temp_new_i64();
6786 gen_qemu_ld64(ctx
, t0
, addr
);
6787 tcg_gen_trunc_i64_i32(cpu_gpr
[rD(ctx
->opcode
)], t0
);
6788 tcg_gen_shri_i64(t0
, t0
, 32);
6789 tcg_gen_trunc_i64_i32(cpu_gprh
[rD(ctx
->opcode
)], t0
);
6790 tcg_temp_free_i64(t0
);
6794 static always_inline
void gen_op_evldw(DisasContext
*ctx
, TCGv addr
)
6796 #if defined(TARGET_PPC64)
6797 TCGv t0
= tcg_temp_new();
6798 gen_qemu_ld32u(ctx
, t0
, addr
);
6799 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
6800 gen_addr_add(ctx
, addr
, addr
, 4);
6801 gen_qemu_ld32u(ctx
, t0
, addr
);
6802 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6805 gen_qemu_ld32u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
6806 gen_addr_add(ctx
, addr
, addr
, 4);
6807 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
6811 static always_inline
void gen_op_evldh(DisasContext
*ctx
, TCGv addr
)
6813 TCGv t0
= tcg_temp_new();
6814 #if defined(TARGET_PPC64)
6815 gen_qemu_ld16u(ctx
, t0
, addr
);
6816 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
6817 gen_addr_add(ctx
, addr
, addr
, 2);
6818 gen_qemu_ld16u(ctx
, t0
, addr
);
6819 tcg_gen_shli_tl(t0
, t0
, 32);
6820 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6821 gen_addr_add(ctx
, addr
, addr
, 2);
6822 gen_qemu_ld16u(ctx
, t0
, addr
);
6823 tcg_gen_shli_tl(t0
, t0
, 16);
6824 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6825 gen_addr_add(ctx
, addr
, addr
, 2);
6826 gen_qemu_ld16u(ctx
, t0
, addr
);
6827 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6829 gen_qemu_ld16u(ctx
, t0
, addr
);
6830 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
6831 gen_addr_add(ctx
, addr
, addr
, 2);
6832 gen_qemu_ld16u(ctx
, t0
, addr
);
6833 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
6834 gen_addr_add(ctx
, addr
, addr
, 2);
6835 gen_qemu_ld16u(ctx
, t0
, addr
);
6836 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
6837 gen_addr_add(ctx
, addr
, addr
, 2);
6838 gen_qemu_ld16u(ctx
, t0
, addr
);
6839 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6844 static always_inline
void gen_op_evlhhesplat(DisasContext
*ctx
, TCGv addr
)
6846 TCGv t0
= tcg_temp_new();
6847 gen_qemu_ld16u(ctx
, t0
, addr
);
6848 #if defined(TARGET_PPC64)
6849 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
6850 tcg_gen_shli_tl(t0
, t0
, 16);
6851 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6853 tcg_gen_shli_tl(t0
, t0
, 16);
6854 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
6855 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
6860 static always_inline
void gen_op_evlhhousplat(DisasContext
*ctx
, TCGv addr
)
6862 TCGv t0
= tcg_temp_new();
6863 gen_qemu_ld16u(ctx
, t0
, addr
);
6864 #if defined(TARGET_PPC64)
6865 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
6866 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6868 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
6869 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
6874 static always_inline
void gen_op_evlhhossplat(DisasContext
*ctx
, TCGv addr
)
6876 TCGv t0
= tcg_temp_new();
6877 gen_qemu_ld16s(ctx
, t0
, addr
);
6878 #if defined(TARGET_PPC64)
6879 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
6880 tcg_gen_ext32u_tl(t0
, t0
);
6881 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6883 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
6884 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
6889 static always_inline
void gen_op_evlwhe(DisasContext
*ctx
, TCGv addr
)
6891 TCGv t0
= tcg_temp_new();
6892 #if defined(TARGET_PPC64)
6893 gen_qemu_ld16u(ctx
, t0
, addr
);
6894 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
6895 gen_addr_add(ctx
, addr
, addr
, 2);
6896 gen_qemu_ld16u(ctx
, t0
, addr
);
6897 tcg_gen_shli_tl(t0
, t0
, 16);
6898 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6900 gen_qemu_ld16u(ctx
, t0
, addr
);
6901 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
6902 gen_addr_add(ctx
, addr
, addr
, 2);
6903 gen_qemu_ld16u(ctx
, t0
, addr
);
6904 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
6909 static always_inline
void gen_op_evlwhou(DisasContext
*ctx
, TCGv addr
)
6911 #if defined(TARGET_PPC64)
6912 TCGv t0
= tcg_temp_new();
6913 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
6914 gen_addr_add(ctx
, addr
, addr
, 2);
6915 gen_qemu_ld16u(ctx
, t0
, addr
);
6916 tcg_gen_shli_tl(t0
, t0
, 32);
6917 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6920 gen_qemu_ld16u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
6921 gen_addr_add(ctx
, addr
, addr
, 2);
6922 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
6926 static always_inline
void gen_op_evlwhos(DisasContext
*ctx
, TCGv addr
)
6928 #if defined(TARGET_PPC64)
6929 TCGv t0
= tcg_temp_new();
6930 gen_qemu_ld16s(ctx
, t0
, addr
);
6931 tcg_gen_ext32u_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
6932 gen_addr_add(ctx
, addr
, addr
, 2);
6933 gen_qemu_ld16s(ctx
, t0
, addr
);
6934 tcg_gen_shli_tl(t0
, t0
, 32);
6935 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6938 gen_qemu_ld16s(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
6939 gen_addr_add(ctx
, addr
, addr
, 2);
6940 gen_qemu_ld16s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
6944 static always_inline
void gen_op_evlwwsplat(DisasContext
*ctx
, TCGv addr
)
6946 TCGv t0
= tcg_temp_new();
6947 gen_qemu_ld32u(ctx
, t0
, addr
);
6948 #if defined(TARGET_PPC64)
6949 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
6950 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6952 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
6953 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
6958 static always_inline
void gen_op_evlwhsplat(DisasContext
*ctx
, TCGv addr
)
6960 TCGv t0
= tcg_temp_new();
6961 #if defined(TARGET_PPC64)
6962 gen_qemu_ld16u(ctx
, t0
, addr
);
6963 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
6964 tcg_gen_shli_tl(t0
, t0
, 32);
6965 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6966 gen_addr_add(ctx
, addr
, addr
, 2);
6967 gen_qemu_ld16u(ctx
, t0
, addr
);
6968 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6969 tcg_gen_shli_tl(t0
, t0
, 16);
6970 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6972 gen_qemu_ld16u(ctx
, t0
, addr
);
6973 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
6974 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
6975 gen_addr_add(ctx
, addr
, addr
, 2);
6976 gen_qemu_ld16u(ctx
, t0
, addr
);
6977 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
6978 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
6983 static always_inline
void gen_op_evstdd(DisasContext
*ctx
, TCGv addr
)
6985 #if defined(TARGET_PPC64)
6986 gen_qemu_st64(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
6988 TCGv_i64 t0
= tcg_temp_new_i64();
6989 tcg_gen_concat_i32_i64(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gprh
[rS(ctx
->opcode
)]);
6990 gen_qemu_st64(ctx
, t0
, addr
);
6991 tcg_temp_free_i64(t0
);
6995 static always_inline
void gen_op_evstdw(DisasContext
*ctx
, TCGv addr
)
6997 #if defined(TARGET_PPC64)
6998 TCGv t0
= tcg_temp_new();
6999 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7000 gen_qemu_st32(ctx
, t0
, addr
);
7003 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7005 gen_addr_add(ctx
, addr
, addr
, 4);
7006 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7009 static always_inline
void gen_op_evstdh(DisasContext
*ctx
, TCGv addr
)
7011 TCGv t0
= tcg_temp_new();
7012 #if defined(TARGET_PPC64)
7013 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
7015 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
7017 gen_qemu_st16(ctx
, t0
, addr
);
7018 gen_addr_add(ctx
, addr
, addr
, 2);
7019 #if defined(TARGET_PPC64)
7020 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7021 gen_qemu_st16(ctx
, t0
, addr
);
7023 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7025 gen_addr_add(ctx
, addr
, addr
, 2);
7026 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
7027 gen_qemu_st16(ctx
, t0
, addr
);
7029 gen_addr_add(ctx
, addr
, addr
, 2);
7030 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7033 static always_inline
void gen_op_evstwhe(DisasContext
*ctx
, TCGv addr
)
7035 TCGv t0
= tcg_temp_new();
7036 #if defined(TARGET_PPC64)
7037 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
7039 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
7041 gen_qemu_st16(ctx
, t0
, addr
);
7042 gen_addr_add(ctx
, addr
, addr
, 2);
7043 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
7044 gen_qemu_st16(ctx
, t0
, addr
);
7048 static always_inline
void gen_op_evstwho(DisasContext
*ctx
, TCGv addr
)
7050 #if defined(TARGET_PPC64)
7051 TCGv t0
= tcg_temp_new();
7052 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7053 gen_qemu_st16(ctx
, t0
, addr
);
7056 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7058 gen_addr_add(ctx
, addr
, addr
, 2);
7059 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7062 static always_inline
void gen_op_evstwwe(DisasContext
*ctx
, TCGv addr
)
7064 #if defined(TARGET_PPC64)
7065 TCGv t0
= tcg_temp_new();
7066 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7067 gen_qemu_st32(ctx
, t0
, addr
);
7070 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7074 static always_inline
void gen_op_evstwwo(DisasContext
*ctx
, TCGv addr
)
7076 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7079 #define GEN_SPEOP_LDST(name, opc2, sh) \
7080 GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE) \
7083 if (unlikely(!ctx->spe_enabled)) { \
7084 gen_exception(ctx, POWERPC_EXCP_APU); \
7087 gen_set_access_type(ctx, ACCESS_INT); \
7088 t0 = tcg_temp_new(); \
7089 if (Rc(ctx->opcode)) { \
7090 gen_addr_spe_imm_index(ctx, t0, sh); \
7092 gen_addr_reg_index(ctx, t0); \
7094 gen_op_##name(ctx, t0); \
7095 tcg_temp_free(t0); \
7098 GEN_SPEOP_LDST(evldd
, 0x00, 3);
7099 GEN_SPEOP_LDST(evldw
, 0x01, 3);
7100 GEN_SPEOP_LDST(evldh
, 0x02, 3);
7101 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1);
7102 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1);
7103 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1);
7104 GEN_SPEOP_LDST(evlwhe
, 0x08, 2);
7105 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2);
7106 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2);
7107 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2);
7108 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2);
7110 GEN_SPEOP_LDST(evstdd
, 0x10, 3);
7111 GEN_SPEOP_LDST(evstdw
, 0x11, 3);
7112 GEN_SPEOP_LDST(evstdh
, 0x12, 3);
7113 GEN_SPEOP_LDST(evstwhe
, 0x18, 2);
7114 GEN_SPEOP_LDST(evstwho
, 0x1A, 2);
7115 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2);
7116 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2);
7118 /* Multiply and add - TODO */
7120 GEN_SPE(speundef
, evmhessf
, 0x01, 0x10, 0x00000000, PPC_SPE
);
7121 GEN_SPE(speundef
, evmhossf
, 0x03, 0x10, 0x00000000, PPC_SPE
);
7122 GEN_SPE(evmheumi
, evmhesmi
, 0x04, 0x10, 0x00000000, PPC_SPE
);
7123 GEN_SPE(speundef
, evmhesmf
, 0x05, 0x10, 0x00000000, PPC_SPE
);
7124 GEN_SPE(evmhoumi
, evmhosmi
, 0x06, 0x10, 0x00000000, PPC_SPE
);
7125 GEN_SPE(speundef
, evmhosmf
, 0x07, 0x10, 0x00000000, PPC_SPE
);
7126 GEN_SPE(speundef
, evmhessfa
, 0x11, 0x10, 0x00000000, PPC_SPE
);
7127 GEN_SPE(speundef
, evmhossfa
, 0x13, 0x10, 0x00000000, PPC_SPE
);
7128 GEN_SPE(evmheumia
, evmhesmia
, 0x14, 0x10, 0x00000000, PPC_SPE
);
7129 GEN_SPE(speundef
, evmhesmfa
, 0x15, 0x10, 0x00000000, PPC_SPE
);
7130 GEN_SPE(evmhoumia
, evmhosmia
, 0x16, 0x10, 0x00000000, PPC_SPE
);
7131 GEN_SPE(speundef
, evmhosmfa
, 0x17, 0x10, 0x00000000, PPC_SPE
);
7133 GEN_SPE(speundef
, evmwhssf
, 0x03, 0x11, 0x00000000, PPC_SPE
);
7134 GEN_SPE(evmwlumi
, speundef
, 0x04, 0x11, 0x00000000, PPC_SPE
);
7135 GEN_SPE(evmwhumi
, evmwhsmi
, 0x06, 0x11, 0x00000000, PPC_SPE
);
7136 GEN_SPE(speundef
, evmwhsmf
, 0x07, 0x11, 0x00000000, PPC_SPE
);
7137 GEN_SPE(speundef
, evmwssf
, 0x09, 0x11, 0x00000000, PPC_SPE
);
7138 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, PPC_SPE
);
7139 GEN_SPE(speundef
, evmwsmf
, 0x0D, 0x11, 0x00000000, PPC_SPE
);
7140 GEN_SPE(speundef
, evmwhssfa
, 0x13, 0x11, 0x00000000, PPC_SPE
);
7141 GEN_SPE(evmwlumia
, speundef
, 0x14, 0x11, 0x00000000, PPC_SPE
);
7142 GEN_SPE(evmwhumia
, evmwhsmia
, 0x16, 0x11, 0x00000000, PPC_SPE
);
7143 GEN_SPE(speundef
, evmwhsmfa
, 0x17, 0x11, 0x00000000, PPC_SPE
);
7144 GEN_SPE(speundef
, evmwssfa
, 0x19, 0x11, 0x00000000, PPC_SPE
);
7145 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, PPC_SPE
);
7146 GEN_SPE(speundef
, evmwsmfa
, 0x1D, 0x11, 0x00000000, PPC_SPE
);
7148 GEN_SPE(evadduiaaw
, evaddsiaaw
, 0x00, 0x13, 0x0000F800, PPC_SPE
);
7149 GEN_SPE(evsubfusiaaw
, evsubfssiaaw
, 0x01, 0x13, 0x0000F800, PPC_SPE
);
7150 GEN_SPE(evaddumiaaw
, evaddsmiaaw
, 0x04, 0x13, 0x0000F800, PPC_SPE
);
7151 GEN_SPE(evsubfumiaaw
, evsubfsmiaaw
, 0x05, 0x13, 0x0000F800, PPC_SPE
);
7152 GEN_SPE(evdivws
, evdivwu
, 0x06, 0x13, 0x00000000, PPC_SPE
);
7153 GEN_SPE(evmra
, speundef
, 0x07, 0x13, 0x0000F800, PPC_SPE
);
7155 GEN_SPE(evmheusiaaw
, evmhessiaaw
, 0x00, 0x14, 0x00000000, PPC_SPE
);
7156 GEN_SPE(speundef
, evmhessfaaw
, 0x01, 0x14, 0x00000000, PPC_SPE
);
7157 GEN_SPE(evmhousiaaw
, evmhossiaaw
, 0x02, 0x14, 0x00000000, PPC_SPE
);
7158 GEN_SPE(speundef
, evmhossfaaw
, 0x03, 0x14, 0x00000000, PPC_SPE
);
7159 GEN_SPE(evmheumiaaw
, evmhesmiaaw
, 0x04, 0x14, 0x00000000, PPC_SPE
);
7160 GEN_SPE(speundef
, evmhesmfaaw
, 0x05, 0x14, 0x00000000, PPC_SPE
);
7161 GEN_SPE(evmhoumiaaw
, evmhosmiaaw
, 0x06, 0x14, 0x00000000, PPC_SPE
);
7162 GEN_SPE(speundef
, evmhosmfaaw
, 0x07, 0x14, 0x00000000, PPC_SPE
);
7163 GEN_SPE(evmhegumiaa
, evmhegsmiaa
, 0x14, 0x14, 0x00000000, PPC_SPE
);
7164 GEN_SPE(speundef
, evmhegsmfaa
, 0x15, 0x14, 0x00000000, PPC_SPE
);
7165 GEN_SPE(evmhogumiaa
, evmhogsmiaa
, 0x16, 0x14, 0x00000000, PPC_SPE
);
7166 GEN_SPE(speundef
, evmhogsmfaa
, 0x17, 0x14, 0x00000000, PPC_SPE
);
7168 GEN_SPE(evmwlusiaaw
, evmwlssiaaw
, 0x00, 0x15, 0x00000000, PPC_SPE
);
7169 GEN_SPE(evmwlumiaaw
, evmwlsmiaaw
, 0x04, 0x15, 0x00000000, PPC_SPE
);
7170 GEN_SPE(speundef
, evmwssfaa
, 0x09, 0x15, 0x00000000, PPC_SPE
);
7171 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, PPC_SPE
);
7172 GEN_SPE(speundef
, evmwsmfaa
, 0x0D, 0x15, 0x00000000, PPC_SPE
);
7174 GEN_SPE(evmheusianw
, evmhessianw
, 0x00, 0x16, 0x00000000, PPC_SPE
);
7175 GEN_SPE(speundef
, evmhessfanw
, 0x01, 0x16, 0x00000000, PPC_SPE
);
7176 GEN_SPE(evmhousianw
, evmhossianw
, 0x02, 0x16, 0x00000000, PPC_SPE
);
7177 GEN_SPE(speundef
, evmhossfanw
, 0x03, 0x16, 0x00000000, PPC_SPE
);
7178 GEN_SPE(evmheumianw
, evmhesmianw
, 0x04, 0x16, 0x00000000, PPC_SPE
);
7179 GEN_SPE(speundef
, evmhesmfanw
, 0x05, 0x16, 0x00000000, PPC_SPE
);
7180 GEN_SPE(evmhoumianw
, evmhosmianw
, 0x06, 0x16, 0x00000000, PPC_SPE
);
7181 GEN_SPE(speundef
, evmhosmfanw
, 0x07, 0x16, 0x00000000, PPC_SPE
);
7182 GEN_SPE(evmhegumian
, evmhegsmian
, 0x14, 0x16, 0x00000000, PPC_SPE
);
7183 GEN_SPE(speundef
, evmhegsmfan
, 0x15, 0x16, 0x00000000, PPC_SPE
);
7184 GEN_SPE(evmhigumian
, evmhigsmian
, 0x16, 0x16, 0x00000000, PPC_SPE
);
7185 GEN_SPE(speundef
, evmhogsmfan
, 0x17, 0x16, 0x00000000, PPC_SPE
);
7187 GEN_SPE(evmwlusianw
, evmwlssianw
, 0x00, 0x17, 0x00000000, PPC_SPE
);
7188 GEN_SPE(evmwlumianw
, evmwlsmianw
, 0x04, 0x17, 0x00000000, PPC_SPE
);
7189 GEN_SPE(speundef
, evmwssfan
, 0x09, 0x17, 0x00000000, PPC_SPE
);
7190 GEN_SPE(evmwumian
, evmwsmian
, 0x0C, 0x17, 0x00000000, PPC_SPE
);
7191 GEN_SPE(speundef
, evmwsmfan
, 0x0D, 0x17, 0x00000000, PPC_SPE
);
7194 /*** SPE floating-point extension ***/
7195 #if defined(TARGET_PPC64)
7196 #define GEN_SPEFPUOP_CONV_32_32(name) \
7197 static always_inline void gen_##name (DisasContext *ctx) \
7201 t0 = tcg_temp_new_i32(); \
7202 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
7203 gen_helper_##name(t0, t0); \
7204 t1 = tcg_temp_new(); \
7205 tcg_gen_extu_i32_tl(t1, t0); \
7206 tcg_temp_free_i32(t0); \
7207 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
7208 0xFFFFFFFF00000000ULL); \
7209 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
7210 tcg_temp_free(t1); \
7212 #define GEN_SPEFPUOP_CONV_32_64(name) \
7213 static always_inline void gen_##name (DisasContext *ctx) \
7217 t0 = tcg_temp_new_i32(); \
7218 gen_helper_##name(t0, cpu_gpr[rB(ctx->opcode)]); \
7219 t1 = tcg_temp_new(); \
7220 tcg_gen_extu_i32_tl(t1, t0); \
7221 tcg_temp_free_i32(t0); \
7222 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
7223 0xFFFFFFFF00000000ULL); \
7224 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
7225 tcg_temp_free(t1); \
7227 #define GEN_SPEFPUOP_CONV_64_32(name) \
7228 static always_inline void gen_##name (DisasContext *ctx) \
7230 TCGv_i32 t0 = tcg_temp_new_i32(); \
7231 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
7232 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], t0); \
7233 tcg_temp_free_i32(t0); \
7235 #define GEN_SPEFPUOP_CONV_64_64(name) \
7236 static always_inline void gen_##name (DisasContext *ctx) \
7238 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
7240 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
7241 static always_inline void gen_##name (DisasContext *ctx) \
7245 if (unlikely(!ctx->spe_enabled)) { \
7246 gen_exception(ctx, POWERPC_EXCP_APU); \
7249 t0 = tcg_temp_new_i32(); \
7250 t1 = tcg_temp_new_i32(); \
7251 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7252 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
7253 gen_helper_##name(t0, t0, t1); \
7254 tcg_temp_free_i32(t1); \
7255 t2 = tcg_temp_new(); \
7256 tcg_gen_extu_i32_tl(t2, t0); \
7257 tcg_temp_free_i32(t0); \
7258 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
7259 0xFFFFFFFF00000000ULL); \
7260 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \
7261 tcg_temp_free(t2); \
7263 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
7264 static always_inline void gen_##name (DisasContext *ctx) \
7266 if (unlikely(!ctx->spe_enabled)) { \
7267 gen_exception(ctx, POWERPC_EXCP_APU); \
7270 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7271 cpu_gpr[rB(ctx->opcode)]); \
7273 #define GEN_SPEFPUOP_COMP_32(name) \
7274 static always_inline void gen_##name (DisasContext *ctx) \
7277 if (unlikely(!ctx->spe_enabled)) { \
7278 gen_exception(ctx, POWERPC_EXCP_APU); \
7281 t0 = tcg_temp_new_i32(); \
7282 t1 = tcg_temp_new_i32(); \
7283 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7284 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
7285 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], t0, t1); \
7286 tcg_temp_free_i32(t0); \
7287 tcg_temp_free_i32(t1); \
7289 #define GEN_SPEFPUOP_COMP_64(name) \
7290 static always_inline void gen_##name (DisasContext *ctx) \
7292 if (unlikely(!ctx->spe_enabled)) { \
7293 gen_exception(ctx, POWERPC_EXCP_APU); \
7296 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
7297 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
7300 #define GEN_SPEFPUOP_CONV_32_32(name) \
7301 static always_inline void gen_##name (DisasContext *ctx) \
7303 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
7305 #define GEN_SPEFPUOP_CONV_32_64(name) \
7306 static always_inline void gen_##name (DisasContext *ctx) \
7308 TCGv_i64 t0 = tcg_temp_new_i64(); \
7309 gen_load_gpr64(t0, rB(ctx->opcode)); \
7310 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], t0); \
7311 tcg_temp_free_i64(t0); \
7313 #define GEN_SPEFPUOP_CONV_64_32(name) \
7314 static always_inline void gen_##name (DisasContext *ctx) \
7316 TCGv_i64 t0 = tcg_temp_new_i64(); \
7317 gen_helper_##name(t0, cpu_gpr[rB(ctx->opcode)]); \
7318 gen_store_gpr64(rD(ctx->opcode), t0); \
7319 tcg_temp_free_i64(t0); \
7321 #define GEN_SPEFPUOP_CONV_64_64(name) \
7322 static always_inline void gen_##name (DisasContext *ctx) \
7324 TCGv_i64 t0 = tcg_temp_new_i64(); \
7325 gen_load_gpr64(t0, rB(ctx->opcode)); \
7326 gen_helper_##name(t0, t0); \
7327 gen_store_gpr64(rD(ctx->opcode), t0); \
7328 tcg_temp_free_i64(t0); \
7330 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
7331 static always_inline void gen_##name (DisasContext *ctx) \
7333 if (unlikely(!ctx->spe_enabled)) { \
7334 gen_exception(ctx, POWERPC_EXCP_APU); \
7337 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], \
7338 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
7340 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
7341 static always_inline void gen_##name (DisasContext *ctx) \
7344 if (unlikely(!ctx->spe_enabled)) { \
7345 gen_exception(ctx, POWERPC_EXCP_APU); \
7348 t0 = tcg_temp_new_i64(); \
7349 t1 = tcg_temp_new_i64(); \
7350 gen_load_gpr64(t0, rA(ctx->opcode)); \
7351 gen_load_gpr64(t1, rB(ctx->opcode)); \
7352 gen_helper_##name(t0, t0, t1); \
7353 gen_store_gpr64(rD(ctx->opcode), t0); \
7354 tcg_temp_free_i64(t0); \
7355 tcg_temp_free_i64(t1); \
7357 #define GEN_SPEFPUOP_COMP_32(name) \
7358 static always_inline void gen_##name (DisasContext *ctx) \
7360 if (unlikely(!ctx->spe_enabled)) { \
7361 gen_exception(ctx, POWERPC_EXCP_APU); \
7364 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
7365 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
7367 #define GEN_SPEFPUOP_COMP_64(name) \
7368 static always_inline void gen_##name (DisasContext *ctx) \
7371 if (unlikely(!ctx->spe_enabled)) { \
7372 gen_exception(ctx, POWERPC_EXCP_APU); \
7375 t0 = tcg_temp_new_i64(); \
7376 t1 = tcg_temp_new_i64(); \
7377 gen_load_gpr64(t0, rA(ctx->opcode)); \
7378 gen_load_gpr64(t1, rB(ctx->opcode)); \
7379 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], t0, t1); \
7380 tcg_temp_free_i64(t0); \
7381 tcg_temp_free_i64(t1); \
7385 /* Single precision floating-point vectors operations */
7387 GEN_SPEFPUOP_ARITH2_64_64(evfsadd
);
7388 GEN_SPEFPUOP_ARITH2_64_64(evfssub
);
7389 GEN_SPEFPUOP_ARITH2_64_64(evfsmul
);
7390 GEN_SPEFPUOP_ARITH2_64_64(evfsdiv
);
7391 static always_inline
void gen_evfsabs (DisasContext
*ctx
)
7393 if (unlikely(!ctx
->spe_enabled
)) {
7394 gen_exception(ctx
, POWERPC_EXCP_APU
);
7397 #if defined(TARGET_PPC64)
7398 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000080000000LL
);
7400 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x80000000);
7401 tcg_gen_andi_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
7404 static always_inline
void gen_evfsnabs (DisasContext
*ctx
)
7406 if (unlikely(!ctx
->spe_enabled
)) {
7407 gen_exception(ctx
, POWERPC_EXCP_APU
);
7410 #if defined(TARGET_PPC64)
7411 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
7413 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
7414 tcg_gen_ori_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
7417 static always_inline
void gen_evfsneg (DisasContext
*ctx
)
7419 if (unlikely(!ctx
->spe_enabled
)) {
7420 gen_exception(ctx
, POWERPC_EXCP_APU
);
7423 #if defined(TARGET_PPC64)
7424 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
7426 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
7427 tcg_gen_xori_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
7432 GEN_SPEFPUOP_CONV_64_64(evfscfui
);
7433 GEN_SPEFPUOP_CONV_64_64(evfscfsi
);
7434 GEN_SPEFPUOP_CONV_64_64(evfscfuf
);
7435 GEN_SPEFPUOP_CONV_64_64(evfscfsf
);
7436 GEN_SPEFPUOP_CONV_64_64(evfsctui
);
7437 GEN_SPEFPUOP_CONV_64_64(evfsctsi
);
7438 GEN_SPEFPUOP_CONV_64_64(evfsctuf
);
7439 GEN_SPEFPUOP_CONV_64_64(evfsctsf
);
7440 GEN_SPEFPUOP_CONV_64_64(evfsctuiz
);
7441 GEN_SPEFPUOP_CONV_64_64(evfsctsiz
);
7444 GEN_SPEFPUOP_COMP_64(evfscmpgt
);
7445 GEN_SPEFPUOP_COMP_64(evfscmplt
);
7446 GEN_SPEFPUOP_COMP_64(evfscmpeq
);
7447 GEN_SPEFPUOP_COMP_64(evfststgt
);
7448 GEN_SPEFPUOP_COMP_64(evfststlt
);
7449 GEN_SPEFPUOP_COMP_64(evfststeq
);
7451 /* Opcodes definitions */
7452 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, PPC_SPEFPU
); //
7453 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, PPC_SPEFPU
); //
7454 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, PPC_SPEFPU
); //
7455 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, PPC_SPEFPU
); //
7456 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, PPC_SPEFPU
); //
7457 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, PPC_SPEFPU
); //
7458 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, PPC_SPEFPU
); //
7459 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, PPC_SPEFPU
); //
7460 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, PPC_SPEFPU
); //
7461 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, PPC_SPEFPU
); //
7462 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, PPC_SPEFPU
); //
7463 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, PPC_SPEFPU
); //
7464 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, PPC_SPEFPU
); //
7465 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, PPC_SPEFPU
); //
7467 /* Single precision floating-point operations */
7469 GEN_SPEFPUOP_ARITH2_32_32(efsadd
);
7470 GEN_SPEFPUOP_ARITH2_32_32(efssub
);
7471 GEN_SPEFPUOP_ARITH2_32_32(efsmul
);
7472 GEN_SPEFPUOP_ARITH2_32_32(efsdiv
);
7473 static always_inline
void gen_efsabs (DisasContext
*ctx
)
7475 if (unlikely(!ctx
->spe_enabled
)) {
7476 gen_exception(ctx
, POWERPC_EXCP_APU
);
7479 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], (target_long
)~0x80000000LL
);
7481 static always_inline
void gen_efsnabs (DisasContext
*ctx
)
7483 if (unlikely(!ctx
->spe_enabled
)) {
7484 gen_exception(ctx
, POWERPC_EXCP_APU
);
7487 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
7489 static always_inline
void gen_efsneg (DisasContext
*ctx
)
7491 if (unlikely(!ctx
->spe_enabled
)) {
7492 gen_exception(ctx
, POWERPC_EXCP_APU
);
7495 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
7499 GEN_SPEFPUOP_CONV_32_32(efscfui
);
7500 GEN_SPEFPUOP_CONV_32_32(efscfsi
);
7501 GEN_SPEFPUOP_CONV_32_32(efscfuf
);
7502 GEN_SPEFPUOP_CONV_32_32(efscfsf
);
7503 GEN_SPEFPUOP_CONV_32_32(efsctui
);
7504 GEN_SPEFPUOP_CONV_32_32(efsctsi
);
7505 GEN_SPEFPUOP_CONV_32_32(efsctuf
);
7506 GEN_SPEFPUOP_CONV_32_32(efsctsf
);
7507 GEN_SPEFPUOP_CONV_32_32(efsctuiz
);
7508 GEN_SPEFPUOP_CONV_32_32(efsctsiz
);
7509 GEN_SPEFPUOP_CONV_32_64(efscfd
);
7512 GEN_SPEFPUOP_COMP_32(efscmpgt
);
7513 GEN_SPEFPUOP_COMP_32(efscmplt
);
7514 GEN_SPEFPUOP_COMP_32(efscmpeq
);
7515 GEN_SPEFPUOP_COMP_32(efststgt
);
7516 GEN_SPEFPUOP_COMP_32(efststlt
);
7517 GEN_SPEFPUOP_COMP_32(efststeq
);
7519 /* Opcodes definitions */
7520 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, PPC_SPEFPU
); //
7521 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, PPC_SPEFPU
); //
7522 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, PPC_SPEFPU
); //
7523 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, PPC_SPEFPU
); //
7524 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, PPC_SPEFPU
); //
7525 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, PPC_SPEFPU
); //
7526 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, PPC_SPEFPU
); //
7527 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, PPC_SPEFPU
); //
7528 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, PPC_SPEFPU
); //
7529 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, PPC_SPEFPU
); //
7530 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, PPC_SPEFPU
); //
7531 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, PPC_SPEFPU
); //
7532 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, PPC_SPEFPU
); //
7533 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, PPC_SPEFPU
); //
7535 /* Double precision floating-point operations */
7537 GEN_SPEFPUOP_ARITH2_64_64(efdadd
);
7538 GEN_SPEFPUOP_ARITH2_64_64(efdsub
);
7539 GEN_SPEFPUOP_ARITH2_64_64(efdmul
);
7540 GEN_SPEFPUOP_ARITH2_64_64(efddiv
);
7541 static always_inline
void gen_efdabs (DisasContext
*ctx
)
7543 if (unlikely(!ctx
->spe_enabled
)) {
7544 gen_exception(ctx
, POWERPC_EXCP_APU
);
7547 #if defined(TARGET_PPC64)
7548 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000000000000LL
);
7550 tcg_gen_andi_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
7553 static always_inline
void gen_efdnabs (DisasContext
*ctx
)
7555 if (unlikely(!ctx
->spe_enabled
)) {
7556 gen_exception(ctx
, POWERPC_EXCP_APU
);
7559 #if defined(TARGET_PPC64)
7560 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
7562 tcg_gen_ori_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
7565 static always_inline
void gen_efdneg (DisasContext
*ctx
)
7567 if (unlikely(!ctx
->spe_enabled
)) {
7568 gen_exception(ctx
, POWERPC_EXCP_APU
);
7571 #if defined(TARGET_PPC64)
7572 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
7574 tcg_gen_xori_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
7579 GEN_SPEFPUOP_CONV_64_32(efdcfui
);
7580 GEN_SPEFPUOP_CONV_64_32(efdcfsi
);
7581 GEN_SPEFPUOP_CONV_64_32(efdcfuf
);
7582 GEN_SPEFPUOP_CONV_64_32(efdcfsf
);
7583 GEN_SPEFPUOP_CONV_32_64(efdctui
);
7584 GEN_SPEFPUOP_CONV_32_64(efdctsi
);
7585 GEN_SPEFPUOP_CONV_32_64(efdctuf
);
7586 GEN_SPEFPUOP_CONV_32_64(efdctsf
);
7587 GEN_SPEFPUOP_CONV_32_64(efdctuiz
);
7588 GEN_SPEFPUOP_CONV_32_64(efdctsiz
);
7589 GEN_SPEFPUOP_CONV_64_32(efdcfs
);
7590 GEN_SPEFPUOP_CONV_64_64(efdcfuid
);
7591 GEN_SPEFPUOP_CONV_64_64(efdcfsid
);
7592 GEN_SPEFPUOP_CONV_64_64(efdctuidz
);
7593 GEN_SPEFPUOP_CONV_64_64(efdctsidz
);
7596 GEN_SPEFPUOP_COMP_64(efdcmpgt
);
7597 GEN_SPEFPUOP_COMP_64(efdcmplt
);
7598 GEN_SPEFPUOP_COMP_64(efdcmpeq
);
7599 GEN_SPEFPUOP_COMP_64(efdtstgt
);
7600 GEN_SPEFPUOP_COMP_64(efdtstlt
);
7601 GEN_SPEFPUOP_COMP_64(efdtsteq
);
7603 /* Opcodes definitions */
7604 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, PPC_SPEFPU
); //
7605 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, PPC_SPEFPU
); //
7606 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, PPC_SPEFPU
); //
7607 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, PPC_SPEFPU
); //
7608 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, PPC_SPEFPU
); //
7609 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, PPC_SPEFPU
); //
7610 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, PPC_SPEFPU
); //
7611 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, PPC_SPEFPU
); //
7612 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, PPC_SPEFPU
); //
7613 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, PPC_SPEFPU
); //
7614 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, PPC_SPEFPU
); //
7615 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, PPC_SPEFPU
); //
7616 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, PPC_SPEFPU
); //
7617 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, PPC_SPEFPU
); //
7618 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, PPC_SPEFPU
); //
7619 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, PPC_SPEFPU
); //
7621 /* End opcode list */
7622 GEN_OPCODE_MARK(end
);
7624 #include "translate_init.c"
7625 #include "helper_regs.h"
7627 /*****************************************************************************/
7628 /* Misc PowerPC helpers */
7629 void cpu_dump_state (CPUState
*env
, FILE *f
,
7630 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
7638 cpu_fprintf(f
, "NIP " ADDRX
" LR " ADDRX
" CTR " ADDRX
" XER %08x\n",
7639 env
->nip
, env
->lr
, env
->ctr
, env
->xer
);
7640 cpu_fprintf(f
, "MSR " ADDRX
" HID0 " ADDRX
" HF " ADDRX
" idx %d\n",
7641 env
->msr
, env
->spr
[SPR_HID0
], env
->hflags
, env
->mmu_idx
);
7642 #if !defined(NO_TIMER_DUMP)
7643 cpu_fprintf(f
, "TB %08x %08x "
7644 #if !defined(CONFIG_USER_ONLY)
7648 cpu_ppc_load_tbu(env
), cpu_ppc_load_tbl(env
)
7649 #if !defined(CONFIG_USER_ONLY)
7650 , cpu_ppc_load_decr(env
)
7654 for (i
= 0; i
< 32; i
++) {
7655 if ((i
& (RGPL
- 1)) == 0)
7656 cpu_fprintf(f
, "GPR%02d", i
);
7657 cpu_fprintf(f
, " " REGX
, ppc_dump_gpr(env
, i
));
7658 if ((i
& (RGPL
- 1)) == (RGPL
- 1))
7659 cpu_fprintf(f
, "\n");
7661 cpu_fprintf(f
, "CR ");
7662 for (i
= 0; i
< 8; i
++)
7663 cpu_fprintf(f
, "%01x", env
->crf
[i
]);
7664 cpu_fprintf(f
, " [");
7665 for (i
= 0; i
< 8; i
++) {
7667 if (env
->crf
[i
] & 0x08)
7669 else if (env
->crf
[i
] & 0x04)
7671 else if (env
->crf
[i
] & 0x02)
7673 cpu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
7675 cpu_fprintf(f
, " ] RES " ADDRX
"\n", env
->reserve
);
7676 for (i
= 0; i
< 32; i
++) {
7677 if ((i
& (RFPL
- 1)) == 0)
7678 cpu_fprintf(f
, "FPR%02d", i
);
7679 cpu_fprintf(f
, " %016" PRIx64
, *((uint64_t *)&env
->fpr
[i
]));
7680 if ((i
& (RFPL
- 1)) == (RFPL
- 1))
7681 cpu_fprintf(f
, "\n");
7683 cpu_fprintf(f
, "FPSCR %08x\n", env
->fpscr
);
7684 #if !defined(CONFIG_USER_ONLY)
7685 cpu_fprintf(f
, "SRR0 " ADDRX
" SRR1 " ADDRX
" SDR1 " ADDRX
"\n",
7686 env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
], env
->sdr1
);
7693 void cpu_dump_statistics (CPUState
*env
, FILE*f
,
7694 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
7697 #if defined(DO_PPC_STATISTICS)
7698 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
7702 for (op1
= 0; op1
< 64; op1
++) {
7704 if (is_indirect_opcode(handler
)) {
7705 t2
= ind_table(handler
);
7706 for (op2
= 0; op2
< 32; op2
++) {
7708 if (is_indirect_opcode(handler
)) {
7709 t3
= ind_table(handler
);
7710 for (op3
= 0; op3
< 32; op3
++) {
7712 if (handler
->count
== 0)
7714 cpu_fprintf(f
, "%02x %02x %02x (%02x %04d) %16s: "
7716 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
7718 handler
->count
, handler
->count
);
7721 if (handler
->count
== 0)
7723 cpu_fprintf(f
, "%02x %02x (%02x %04d) %16s: "
7725 op1
, op2
, op1
, op2
, handler
->oname
,
7726 handler
->count
, handler
->count
);
7730 if (handler
->count
== 0)
7732 cpu_fprintf(f
, "%02x (%02x ) %16s: %016llx %lld\n",
7733 op1
, op1
, handler
->oname
,
7734 handler
->count
, handler
->count
);
7740 /*****************************************************************************/
7741 static always_inline
void gen_intermediate_code_internal (CPUState
*env
,
7742 TranslationBlock
*tb
,
7745 DisasContext ctx
, *ctxp
= &ctx
;
7746 opc_handler_t
**table
, *handler
;
7747 target_ulong pc_start
;
7748 uint16_t *gen_opc_end
;
7755 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
7758 ctx
.exception
= POWERPC_EXCP_NONE
;
7759 ctx
.spr_cb
= env
->spr_cb
;
7760 ctx
.mem_idx
= env
->mmu_idx
;
7761 ctx
.access_type
= -1;
7762 ctx
.le_mode
= env
->hflags
& (1 << MSR_LE
) ? 1 : 0;
7763 #if defined(TARGET_PPC64)
7764 ctx
.sf_mode
= msr_sf
;
7766 ctx
.fpu_enabled
= msr_fp
;
7767 if ((env
->flags
& POWERPC_FLAG_SPE
) && msr_spe
)
7768 ctx
.spe_enabled
= msr_spe
;
7770 ctx
.spe_enabled
= 0;
7771 if ((env
->flags
& POWERPC_FLAG_VRE
) && msr_vr
)
7772 ctx
.altivec_enabled
= msr_vr
;
7774 ctx
.altivec_enabled
= 0;
7775 if ((env
->flags
& POWERPC_FLAG_SE
) && msr_se
)
7776 ctx
.singlestep_enabled
= CPU_SINGLE_STEP
;
7778 ctx
.singlestep_enabled
= 0;
7779 if ((env
->flags
& POWERPC_FLAG_BE
) && msr_be
)
7780 ctx
.singlestep_enabled
|= CPU_BRANCH_STEP
;
7781 if (unlikely(env
->singlestep_enabled
))
7782 ctx
.singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
7783 #if defined (DO_SINGLE_STEP) && 0
7784 /* Single step trace mode */
7788 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
7790 max_insns
= CF_COUNT_MASK
;
7793 /* Set env in case of segfault during code fetch */
7794 while (ctx
.exception
== POWERPC_EXCP_NONE
&& gen_opc_ptr
< gen_opc_end
) {
7795 if (unlikely(!TAILQ_EMPTY(&env
->breakpoints
))) {
7796 TAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
7797 if (bp
->pc
== ctx
.nip
) {
7798 gen_debug_exception(ctxp
);
7803 if (unlikely(search_pc
)) {
7804 j
= gen_opc_ptr
- gen_opc_buf
;
7808 gen_opc_instr_start
[lj
++] = 0;
7809 gen_opc_pc
[lj
] = ctx
.nip
;
7810 gen_opc_instr_start
[lj
] = 1;
7811 gen_opc_icount
[lj
] = num_insns
;
7814 #if defined PPC_DEBUG_DISAS
7815 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
7816 fprintf(logfile
, "----------------\n");
7817 fprintf(logfile
, "nip=" ADDRX
" super=%d ir=%d\n",
7818 ctx
.nip
, ctx
.mem_idx
, (int)msr_ir
);
7821 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
7823 if (unlikely(ctx
.le_mode
)) {
7824 ctx
.opcode
= bswap32(ldl_code(ctx
.nip
));
7826 ctx
.opcode
= ldl_code(ctx
.nip
);
7828 #if defined PPC_DEBUG_DISAS
7829 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
7830 fprintf(logfile
, "translate opcode %08x (%02x %02x %02x) (%s)\n",
7831 ctx
.opcode
, opc1(ctx
.opcode
), opc2(ctx
.opcode
),
7832 opc3(ctx
.opcode
), little_endian
? "little" : "big");
7836 table
= env
->opcodes
;
7838 handler
= table
[opc1(ctx
.opcode
)];
7839 if (is_indirect_opcode(handler
)) {
7840 table
= ind_table(handler
);
7841 handler
= table
[opc2(ctx
.opcode
)];
7842 if (is_indirect_opcode(handler
)) {
7843 table
= ind_table(handler
);
7844 handler
= table
[opc3(ctx
.opcode
)];
7847 /* Is opcode *REALLY* valid ? */
7848 if (unlikely(handler
->handler
== &gen_invalid
)) {
7849 if (loglevel
!= 0) {
7850 fprintf(logfile
, "invalid/unsupported opcode: "
7851 "%02x - %02x - %02x (%08x) " ADDRX
" %d\n",
7852 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
7853 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
7855 printf("invalid/unsupported opcode: "
7856 "%02x - %02x - %02x (%08x) " ADDRX
" %d\n",
7857 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
7858 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
7861 if (unlikely((ctx
.opcode
& handler
->inval
) != 0)) {
7862 if (loglevel
!= 0) {
7863 fprintf(logfile
, "invalid bits: %08x for opcode: "
7864 "%02x - %02x - %02x (%08x) " ADDRX
"\n",
7865 ctx
.opcode
& handler
->inval
, opc1(ctx
.opcode
),
7866 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
7867 ctx
.opcode
, ctx
.nip
- 4);
7869 printf("invalid bits: %08x for opcode: "
7870 "%02x - %02x - %02x (%08x) " ADDRX
"\n",
7871 ctx
.opcode
& handler
->inval
, opc1(ctx
.opcode
),
7872 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
7873 ctx
.opcode
, ctx
.nip
- 4);
7875 gen_inval_exception(ctxp
, POWERPC_EXCP_INVAL_INVAL
);
7879 (*(handler
->handler
))(&ctx
);
7880 #if defined(DO_PPC_STATISTICS)
7883 /* Check trace mode exceptions */
7884 if (unlikely(ctx
.singlestep_enabled
& CPU_SINGLE_STEP
&&
7885 (ctx
.nip
<= 0x100 || ctx
.nip
> 0xF00) &&
7886 ctx
.exception
!= POWERPC_SYSCALL
&&
7887 ctx
.exception
!= POWERPC_EXCP_TRAP
&&
7888 ctx
.exception
!= POWERPC_EXCP_BRANCH
)) {
7889 gen_exception(ctxp
, POWERPC_EXCP_TRACE
);
7890 } else if (unlikely(((ctx
.nip
& (TARGET_PAGE_SIZE
- 1)) == 0) ||
7891 (env
->singlestep_enabled
) ||
7892 num_insns
>= max_insns
)) {
7893 /* if we reach a page boundary or are single stepping, stop
7898 #if defined (DO_SINGLE_STEP)
7902 if (tb
->cflags
& CF_LAST_IO
)
7904 if (ctx
.exception
== POWERPC_EXCP_NONE
) {
7905 gen_goto_tb(&ctx
, 0, ctx
.nip
);
7906 } else if (ctx
.exception
!= POWERPC_EXCP_BRANCH
) {
7907 if (unlikely(env
->singlestep_enabled
)) {
7908 gen_debug_exception(ctxp
);
7910 /* Generate the return instruction */
7913 gen_icount_end(tb
, num_insns
);
7914 *gen_opc_ptr
= INDEX_op_end
;
7915 if (unlikely(search_pc
)) {
7916 j
= gen_opc_ptr
- gen_opc_buf
;
7919 gen_opc_instr_start
[lj
++] = 0;
7921 tb
->size
= ctx
.nip
- pc_start
;
7922 tb
->icount
= num_insns
;
7924 #if defined(DEBUG_DISAS)
7925 if (loglevel
& CPU_LOG_TB_CPU
) {
7926 fprintf(logfile
, "---------------- excp: %04x\n", ctx
.exception
);
7927 cpu_dump_state(env
, logfile
, fprintf
, 0);
7929 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
7931 flags
= env
->bfd_mach
;
7932 flags
|= ctx
.le_mode
<< 16;
7933 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
7934 target_disas(logfile
, pc_start
, ctx
.nip
- pc_start
, flags
);
7935 fprintf(logfile
, "\n");
7940 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
7942 gen_intermediate_code_internal(env
, tb
, 0);
7945 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
7947 gen_intermediate_code_internal(env
, tb
, 1);
7950 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
7951 unsigned long searched_pc
, int pc_pos
, void *puc
)
7953 env
->nip
= gen_opc_pc
[pc_pos
];