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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 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);
373 /* 5 bits signed immediate value */
374 EXTRACT_HELPER(SIMM5
, 16, 5);
375 /* 5 bits signed immediate value */
376 EXTRACT_HELPER(UIMM5
, 16, 5);
378 EXTRACT_HELPER(NB
, 11, 5);
380 EXTRACT_HELPER(SH
, 11, 5);
381 /* Vector shift count */
382 EXTRACT_HELPER(VSH
, 6, 4);
384 EXTRACT_HELPER(MB
, 6, 5);
386 EXTRACT_HELPER(ME
, 1, 5);
388 EXTRACT_HELPER(TO
, 21, 5);
390 EXTRACT_HELPER(CRM
, 12, 8);
391 EXTRACT_HELPER(FM
, 17, 8);
392 EXTRACT_HELPER(SR
, 16, 4);
393 EXTRACT_HELPER(FPIMM
, 12, 4);
395 /*** Jump target decoding ***/
397 EXTRACT_SHELPER(d
, 0, 16);
398 /* Immediate address */
399 static always_inline target_ulong
LI (uint32_t opcode
)
401 return (opcode
>> 0) & 0x03FFFFFC;
404 static always_inline
uint32_t BD (uint32_t opcode
)
406 return (opcode
>> 0) & 0xFFFC;
409 EXTRACT_HELPER(BO
, 21, 5);
410 EXTRACT_HELPER(BI
, 16, 5);
411 /* Absolute/relative address */
412 EXTRACT_HELPER(AA
, 1, 1);
414 EXTRACT_HELPER(LK
, 0, 1);
416 /* Create a mask between <start> and <end> bits */
417 static always_inline target_ulong
MASK (uint32_t start
, uint32_t end
)
421 #if defined(TARGET_PPC64)
422 if (likely(start
== 0)) {
423 ret
= UINT64_MAX
<< (63 - end
);
424 } else if (likely(end
== 63)) {
425 ret
= UINT64_MAX
>> start
;
428 if (likely(start
== 0)) {
429 ret
= UINT32_MAX
<< (31 - end
);
430 } else if (likely(end
== 31)) {
431 ret
= UINT32_MAX
>> start
;
435 ret
= (((target_ulong
)(-1ULL)) >> (start
)) ^
436 (((target_ulong
)(-1ULL) >> (end
)) >> 1);
437 if (unlikely(start
> end
))
444 /*****************************************************************************/
445 /* PowerPC Instructions types definitions */
447 PPC_NONE
= 0x0000000000000000ULL
,
448 /* PowerPC base instructions set */
449 PPC_INSNS_BASE
= 0x0000000000000001ULL
,
450 /* integer operations instructions */
451 #define PPC_INTEGER PPC_INSNS_BASE
452 /* flow control instructions */
453 #define PPC_FLOW PPC_INSNS_BASE
454 /* virtual memory instructions */
455 #define PPC_MEM PPC_INSNS_BASE
456 /* ld/st with reservation instructions */
457 #define PPC_RES PPC_INSNS_BASE
458 /* spr/msr access instructions */
459 #define PPC_MISC PPC_INSNS_BASE
460 /* Deprecated instruction sets */
461 /* Original POWER instruction set */
462 PPC_POWER
= 0x0000000000000002ULL
,
463 /* POWER2 instruction set extension */
464 PPC_POWER2
= 0x0000000000000004ULL
,
465 /* Power RTC support */
466 PPC_POWER_RTC
= 0x0000000000000008ULL
,
467 /* Power-to-PowerPC bridge (601) */
468 PPC_POWER_BR
= 0x0000000000000010ULL
,
469 /* 64 bits PowerPC instruction set */
470 PPC_64B
= 0x0000000000000020ULL
,
471 /* New 64 bits extensions (PowerPC 2.0x) */
472 PPC_64BX
= 0x0000000000000040ULL
,
473 /* 64 bits hypervisor extensions */
474 PPC_64H
= 0x0000000000000080ULL
,
475 /* New wait instruction (PowerPC 2.0x) */
476 PPC_WAIT
= 0x0000000000000100ULL
,
477 /* Time base mftb instruction */
478 PPC_MFTB
= 0x0000000000000200ULL
,
480 /* Fixed-point unit extensions */
481 /* PowerPC 602 specific */
482 PPC_602_SPEC
= 0x0000000000000400ULL
,
483 /* isel instruction */
484 PPC_ISEL
= 0x0000000000000800ULL
,
485 /* popcntb instruction */
486 PPC_POPCNTB
= 0x0000000000001000ULL
,
487 /* string load / store */
488 PPC_STRING
= 0x0000000000002000ULL
,
490 /* Floating-point unit extensions */
491 /* Optional floating point instructions */
492 PPC_FLOAT
= 0x0000000000010000ULL
,
493 /* New floating-point extensions (PowerPC 2.0x) */
494 PPC_FLOAT_EXT
= 0x0000000000020000ULL
,
495 PPC_FLOAT_FSQRT
= 0x0000000000040000ULL
,
496 PPC_FLOAT_FRES
= 0x0000000000080000ULL
,
497 PPC_FLOAT_FRSQRTE
= 0x0000000000100000ULL
,
498 PPC_FLOAT_FRSQRTES
= 0x0000000000200000ULL
,
499 PPC_FLOAT_FSEL
= 0x0000000000400000ULL
,
500 PPC_FLOAT_STFIWX
= 0x0000000000800000ULL
,
502 /* Vector/SIMD extensions */
503 /* Altivec support */
504 PPC_ALTIVEC
= 0x0000000001000000ULL
,
505 /* PowerPC 2.03 SPE extension */
506 PPC_SPE
= 0x0000000002000000ULL
,
507 /* PowerPC 2.03 SPE floating-point extension */
508 PPC_SPEFPU
= 0x0000000004000000ULL
,
510 /* Optional memory control instructions */
511 PPC_MEM_TLBIA
= 0x0000000010000000ULL
,
512 PPC_MEM_TLBIE
= 0x0000000020000000ULL
,
513 PPC_MEM_TLBSYNC
= 0x0000000040000000ULL
,
514 /* sync instruction */
515 PPC_MEM_SYNC
= 0x0000000080000000ULL
,
516 /* eieio instruction */
517 PPC_MEM_EIEIO
= 0x0000000100000000ULL
,
519 /* Cache control instructions */
520 PPC_CACHE
= 0x0000000200000000ULL
,
521 /* icbi instruction */
522 PPC_CACHE_ICBI
= 0x0000000400000000ULL
,
523 /* dcbz instruction with fixed cache line size */
524 PPC_CACHE_DCBZ
= 0x0000000800000000ULL
,
525 /* dcbz instruction with tunable cache line size */
526 PPC_CACHE_DCBZT
= 0x0000001000000000ULL
,
527 /* dcba instruction */
528 PPC_CACHE_DCBA
= 0x0000002000000000ULL
,
529 /* Freescale cache locking instructions */
530 PPC_CACHE_LOCK
= 0x0000004000000000ULL
,
532 /* MMU related extensions */
533 /* external control instructions */
534 PPC_EXTERN
= 0x0000010000000000ULL
,
535 /* segment register access instructions */
536 PPC_SEGMENT
= 0x0000020000000000ULL
,
537 /* PowerPC 6xx TLB management instructions */
538 PPC_6xx_TLB
= 0x0000040000000000ULL
,
539 /* PowerPC 74xx TLB management instructions */
540 PPC_74xx_TLB
= 0x0000080000000000ULL
,
541 /* PowerPC 40x TLB management instructions */
542 PPC_40x_TLB
= 0x0000100000000000ULL
,
543 /* segment register access instructions for PowerPC 64 "bridge" */
544 PPC_SEGMENT_64B
= 0x0000200000000000ULL
,
546 PPC_SLBI
= 0x0000400000000000ULL
,
548 /* Embedded PowerPC dedicated instructions */
549 PPC_WRTEE
= 0x0001000000000000ULL
,
550 /* PowerPC 40x exception model */
551 PPC_40x_EXCP
= 0x0002000000000000ULL
,
552 /* PowerPC 405 Mac instructions */
553 PPC_405_MAC
= 0x0004000000000000ULL
,
554 /* PowerPC 440 specific instructions */
555 PPC_440_SPEC
= 0x0008000000000000ULL
,
556 /* BookE (embedded) PowerPC specification */
557 PPC_BOOKE
= 0x0010000000000000ULL
,
558 /* mfapidi instruction */
559 PPC_MFAPIDI
= 0x0020000000000000ULL
,
560 /* tlbiva instruction */
561 PPC_TLBIVA
= 0x0040000000000000ULL
,
562 /* tlbivax instruction */
563 PPC_TLBIVAX
= 0x0080000000000000ULL
,
564 /* PowerPC 4xx dedicated instructions */
565 PPC_4xx_COMMON
= 0x0100000000000000ULL
,
566 /* PowerPC 40x ibct instructions */
567 PPC_40x_ICBT
= 0x0200000000000000ULL
,
568 /* rfmci is not implemented in all BookE PowerPC */
569 PPC_RFMCI
= 0x0400000000000000ULL
,
570 /* rfdi instruction */
571 PPC_RFDI
= 0x0800000000000000ULL
,
573 PPC_DCR
= 0x1000000000000000ULL
,
574 /* DCR extended accesse */
575 PPC_DCRX
= 0x2000000000000000ULL
,
576 /* user-mode DCR access, implemented in PowerPC 460 */
577 PPC_DCRUX
= 0x4000000000000000ULL
,
580 /*****************************************************************************/
581 /* PowerPC instructions table */
582 #if HOST_LONG_BITS == 64
587 #if defined(__APPLE__)
588 #define OPCODES_SECTION \
589 __attribute__ ((section("__TEXT,__opcodes"), unused, aligned (OPC_ALIGN) ))
591 #define OPCODES_SECTION \
592 __attribute__ ((section(".opcodes"), unused, aligned (OPC_ALIGN) ))
595 #if defined(DO_PPC_STATISTICS)
596 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
597 OPCODES_SECTION opcode_t opc_##name = { \
605 .handler = &gen_##name, \
606 .oname = stringify(name), \
608 .oname = stringify(name), \
610 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
611 OPCODES_SECTION opcode_t opc_##name = { \
619 .handler = &gen_##name, \
625 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
626 OPCODES_SECTION opcode_t opc_##name = { \
634 .handler = &gen_##name, \
636 .oname = stringify(name), \
638 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
639 OPCODES_SECTION opcode_t opc_##name = { \
647 .handler = &gen_##name, \
653 #define GEN_OPCODE_MARK(name) \
654 OPCODES_SECTION opcode_t opc_##name = { \
660 .inval = 0x00000000, \
664 .oname = stringify(name), \
667 /* SPR load/store helpers */
668 static always_inline
void gen_load_spr(TCGv t
, int reg
)
670 tcg_gen_ld_tl(t
, cpu_env
, offsetof(CPUState
, spr
[reg
]));
673 static always_inline
void gen_store_spr(int reg
, TCGv t
)
675 tcg_gen_st_tl(t
, cpu_env
, offsetof(CPUState
, spr
[reg
]));
678 /* Start opcode list */
679 GEN_OPCODE_MARK(start
);
681 /* Invalid instruction */
682 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
)
684 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
687 static opc_handler_t invalid_handler
= {
690 .handler
= gen_invalid
,
693 /*** Integer comparison ***/
695 static always_inline
void gen_op_cmp(TCGv arg0
, TCGv arg1
, int s
, int crf
)
699 tcg_gen_trunc_tl_i32(cpu_crf
[crf
], cpu_xer
);
700 tcg_gen_shri_i32(cpu_crf
[crf
], cpu_crf
[crf
], XER_SO
);
701 tcg_gen_andi_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1);
703 l1
= gen_new_label();
704 l2
= gen_new_label();
705 l3
= gen_new_label();
707 tcg_gen_brcond_tl(TCG_COND_LT
, arg0
, arg1
, l1
);
708 tcg_gen_brcond_tl(TCG_COND_GT
, arg0
, arg1
, l2
);
710 tcg_gen_brcond_tl(TCG_COND_LTU
, arg0
, arg1
, l1
);
711 tcg_gen_brcond_tl(TCG_COND_GTU
, arg0
, arg1
, l2
);
713 tcg_gen_ori_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1 << CRF_EQ
);
716 tcg_gen_ori_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1 << CRF_LT
);
719 tcg_gen_ori_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1 << CRF_GT
);
723 static always_inline
void gen_op_cmpi(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
725 TCGv t0
= tcg_const_local_tl(arg1
);
726 gen_op_cmp(arg0
, t0
, s
, crf
);
730 #if defined(TARGET_PPC64)
731 static always_inline
void gen_op_cmp32(TCGv arg0
, TCGv arg1
, int s
, int crf
)
734 t0
= tcg_temp_local_new();
735 t1
= tcg_temp_local_new();
737 tcg_gen_ext32s_tl(t0
, arg0
);
738 tcg_gen_ext32s_tl(t1
, arg1
);
740 tcg_gen_ext32u_tl(t0
, arg0
);
741 tcg_gen_ext32u_tl(t1
, arg1
);
743 gen_op_cmp(t0
, t1
, s
, crf
);
748 static always_inline
void gen_op_cmpi32(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
750 TCGv t0
= tcg_const_local_tl(arg1
);
751 gen_op_cmp32(arg0
, t0
, s
, crf
);
756 static always_inline
void gen_set_Rc0 (DisasContext
*ctx
, TCGv reg
)
758 #if defined(TARGET_PPC64)
760 gen_op_cmpi32(reg
, 0, 1, 0);
763 gen_op_cmpi(reg
, 0, 1, 0);
767 GEN_HANDLER(cmp
, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER
)
769 #if defined(TARGET_PPC64)
770 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
771 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
772 1, crfD(ctx
->opcode
));
775 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
776 1, crfD(ctx
->opcode
));
780 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
)
782 #if defined(TARGET_PPC64)
783 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
784 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
785 1, crfD(ctx
->opcode
));
788 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
789 1, crfD(ctx
->opcode
));
793 GEN_HANDLER(cmpl
, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER
)
795 #if defined(TARGET_PPC64)
796 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
797 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
798 0, crfD(ctx
->opcode
));
801 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
802 0, crfD(ctx
->opcode
));
806 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
)
808 #if defined(TARGET_PPC64)
809 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
810 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
811 0, crfD(ctx
->opcode
));
814 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
815 0, crfD(ctx
->opcode
));
818 /* isel (PowerPC 2.03 specification) */
819 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
)
822 uint32_t bi
= rC(ctx
->opcode
);
826 l1
= gen_new_label();
827 l2
= gen_new_label();
829 mask
= 1 << (3 - (bi
& 0x03));
830 t0
= tcg_temp_new_i32();
831 tcg_gen_andi_i32(t0
, cpu_crf
[bi
>> 2], mask
);
832 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
833 if (rA(ctx
->opcode
) == 0)
834 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
836 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
839 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
841 tcg_temp_free_i32(t0
);
844 /*** Integer arithmetic ***/
846 static always_inline
void gen_op_arith_compute_ov(DisasContext
*ctx
, TCGv arg0
, TCGv arg1
, TCGv arg2
, int sub
)
851 l1
= gen_new_label();
852 /* Start with XER OV disabled, the most likely case */
853 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
854 t0
= tcg_temp_local_new();
855 tcg_gen_xor_tl(t0
, arg0
, arg1
);
856 #if defined(TARGET_PPC64)
858 tcg_gen_ext32s_tl(t0
, t0
);
861 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0, l1
);
863 tcg_gen_brcondi_tl(TCG_COND_GE
, t0
, 0, l1
);
864 tcg_gen_xor_tl(t0
, arg1
, arg2
);
865 #if defined(TARGET_PPC64)
867 tcg_gen_ext32s_tl(t0
, t0
);
870 tcg_gen_brcondi_tl(TCG_COND_GE
, t0
, 0, l1
);
872 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0, l1
);
873 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
878 static always_inline
void gen_op_arith_compute_ca(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
, int sub
)
880 int l1
= gen_new_label();
882 #if defined(TARGET_PPC64)
883 if (!(ctx
->sf_mode
)) {
888 tcg_gen_ext32u_tl(t0
, arg1
);
889 tcg_gen_ext32u_tl(t1
, arg2
);
891 tcg_gen_brcond_tl(TCG_COND_GTU
, t0
, t1
, l1
);
893 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
895 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
903 tcg_gen_brcond_tl(TCG_COND_GTU
, arg1
, arg2
, l1
);
905 tcg_gen_brcond_tl(TCG_COND_GEU
, arg1
, arg2
, l1
);
907 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
912 /* Common add function */
913 static always_inline
void gen_op_arith_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
, TCGv arg2
,
914 int add_ca
, int compute_ca
, int compute_ov
)
918 if ((!compute_ca
&& !compute_ov
) ||
919 (!TCGV_EQUAL(ret
,arg1
) && !TCGV_EQUAL(ret
, arg2
))) {
922 t0
= tcg_temp_local_new();
926 t1
= tcg_temp_local_new();
927 tcg_gen_andi_tl(t1
, cpu_xer
, (1 << XER_CA
));
928 tcg_gen_shri_tl(t1
, t1
, XER_CA
);
931 if (compute_ca
&& compute_ov
) {
932 /* Start with XER CA and OV disabled, the most likely case */
933 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~((1 << XER_CA
) | (1 << XER_OV
)));
934 } else if (compute_ca
) {
935 /* Start with XER CA disabled, the most likely case */
936 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
937 } else if (compute_ov
) {
938 /* Start with XER OV disabled, the most likely case */
939 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
942 tcg_gen_add_tl(t0
, arg1
, arg2
);
945 gen_op_arith_compute_ca(ctx
, t0
, arg1
, 0);
948 tcg_gen_add_tl(t0
, t0
, t1
);
949 gen_op_arith_compute_ca(ctx
, t0
, t1
, 0);
953 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 0);
956 if (unlikely(Rc(ctx
->opcode
) != 0))
957 gen_set_Rc0(ctx
, t0
);
959 if (!TCGV_EQUAL(t0
, ret
)) {
960 tcg_gen_mov_tl(ret
, t0
);
964 /* Add functions with two operands */
965 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
966 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER) \
968 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
969 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
970 add_ca, compute_ca, compute_ov); \
972 /* Add functions with one operand and one immediate */
973 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
974 add_ca, compute_ca, compute_ov) \
975 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER) \
977 TCGv t0 = tcg_const_local_tl(const_val); \
978 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
979 cpu_gpr[rA(ctx->opcode)], t0, \
980 add_ca, compute_ca, compute_ov); \
984 /* add add. addo addo. */
985 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
986 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
987 /* addc addc. addco addco. */
988 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
989 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
990 /* adde adde. addeo addeo. */
991 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
992 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
993 /* addme addme. addmeo addmeo. */
994 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
995 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
996 /* addze addze. addzeo addzeo.*/
997 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
998 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
1000 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1002 target_long simm
= SIMM(ctx
->opcode
);
1004 if (rA(ctx
->opcode
) == 0) {
1006 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
);
1008 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], simm
);
1012 static always_inline
void gen_op_addic (DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1015 target_long simm
= SIMM(ctx
->opcode
);
1017 /* Start with XER CA and OV disabled, the most likely case */
1018 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1020 if (likely(simm
!= 0)) {
1021 TCGv t0
= tcg_temp_local_new();
1022 tcg_gen_addi_tl(t0
, arg1
, simm
);
1023 gen_op_arith_compute_ca(ctx
, t0
, arg1
, 0);
1024 tcg_gen_mov_tl(ret
, t0
);
1027 tcg_gen_mov_tl(ret
, arg1
);
1030 gen_set_Rc0(ctx
, ret
);
1033 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1035 gen_op_addic(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0);
1037 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1039 gen_op_addic(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 1);
1042 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1044 target_long simm
= SIMM(ctx
->opcode
);
1046 if (rA(ctx
->opcode
) == 0) {
1048 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
<< 16);
1050 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], simm
<< 16);
1054 static always_inline
void gen_op_arith_divw (DisasContext
*ctx
, TCGv ret
, TCGv arg1
, TCGv arg2
,
1055 int sign
, int compute_ov
)
1057 int l1
= gen_new_label();
1058 int l2
= gen_new_label();
1059 TCGv_i32 t0
= tcg_temp_local_new_i32();
1060 TCGv_i32 t1
= tcg_temp_local_new_i32();
1062 tcg_gen_trunc_tl_i32(t0
, arg1
);
1063 tcg_gen_trunc_tl_i32(t1
, arg2
);
1064 tcg_gen_brcondi_i32(TCG_COND_EQ
, t1
, 0, l1
);
1066 int l3
= gen_new_label();
1067 tcg_gen_brcondi_i32(TCG_COND_NE
, t1
, -1, l3
);
1068 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, INT32_MIN
, l1
);
1070 tcg_gen_div_i32(t0
, t0
, t1
);
1072 tcg_gen_divu_i32(t0
, t0
, t1
);
1075 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1080 tcg_gen_sari_i32(t0
, t0
, 31);
1082 tcg_gen_movi_i32(t0
, 0);
1085 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1088 tcg_gen_extu_i32_tl(ret
, t0
);
1089 tcg_temp_free_i32(t0
);
1090 tcg_temp_free_i32(t1
);
1091 if (unlikely(Rc(ctx
->opcode
) != 0))
1092 gen_set_Rc0(ctx
, ret
);
1095 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
1096 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER) \
1098 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
1099 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1100 sign, compute_ov); \
1102 /* divwu divwu. divwuo divwuo. */
1103 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0);
1104 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1);
1105 /* divw divw. divwo divwo. */
1106 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0);
1107 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1);
1108 #if defined(TARGET_PPC64)
1109 static always_inline
void gen_op_arith_divd (DisasContext
*ctx
, TCGv ret
, TCGv arg1
, TCGv arg2
,
1110 int sign
, int compute_ov
)
1112 int l1
= gen_new_label();
1113 int l2
= gen_new_label();
1115 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg2
, 0, l1
);
1117 int l3
= gen_new_label();
1118 tcg_gen_brcondi_i64(TCG_COND_NE
, arg2
, -1, l3
);
1119 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg1
, INT64_MIN
, l1
);
1121 tcg_gen_div_i64(ret
, arg1
, arg2
);
1123 tcg_gen_divu_i64(ret
, arg1
, arg2
);
1126 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1131 tcg_gen_sari_i64(ret
, arg1
, 63);
1133 tcg_gen_movi_i64(ret
, 0);
1136 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1139 if (unlikely(Rc(ctx
->opcode
) != 0))
1140 gen_set_Rc0(ctx
, ret
);
1142 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1143 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) \
1145 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1146 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1147 sign, compute_ov); \
1149 /* divwu divwu. divwuo divwuo. */
1150 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0);
1151 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1);
1152 /* divw divw. divwo divwo. */
1153 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0);
1154 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1);
1158 GEN_HANDLER(mulhw
, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER
)
1162 t0
= tcg_temp_new_i64();
1163 t1
= tcg_temp_new_i64();
1164 #if defined(TARGET_PPC64)
1165 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1166 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1167 tcg_gen_mul_i64(t0
, t0
, t1
);
1168 tcg_gen_shri_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
1170 tcg_gen_ext_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1171 tcg_gen_ext_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1172 tcg_gen_mul_i64(t0
, t0
, t1
);
1173 tcg_gen_shri_i64(t0
, t0
, 32);
1174 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1176 tcg_temp_free_i64(t0
);
1177 tcg_temp_free_i64(t1
);
1178 if (unlikely(Rc(ctx
->opcode
) != 0))
1179 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1181 /* mulhwu mulhwu. */
1182 GEN_HANDLER(mulhwu
, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER
)
1186 t0
= tcg_temp_new_i64();
1187 t1
= tcg_temp_new_i64();
1188 #if defined(TARGET_PPC64)
1189 tcg_gen_ext32u_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1190 tcg_gen_ext32u_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1191 tcg_gen_mul_i64(t0
, t0
, t1
);
1192 tcg_gen_shri_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
1194 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1195 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1196 tcg_gen_mul_i64(t0
, t0
, t1
);
1197 tcg_gen_shri_i64(t0
, t0
, 32);
1198 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1200 tcg_temp_free_i64(t0
);
1201 tcg_temp_free_i64(t1
);
1202 if (unlikely(Rc(ctx
->opcode
) != 0))
1203 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1206 GEN_HANDLER(mullw
, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER
)
1208 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1209 cpu_gpr
[rB(ctx
->opcode
)]);
1210 tcg_gen_ext32s_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)]);
1211 if (unlikely(Rc(ctx
->opcode
) != 0))
1212 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1214 /* mullwo mullwo. */
1215 GEN_HANDLER(mullwo
, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER
)
1220 t0
= tcg_temp_new_i64();
1221 t1
= tcg_temp_new_i64();
1222 l1
= gen_new_label();
1223 /* Start with XER OV disabled, the most likely case */
1224 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1225 #if defined(TARGET_PPC64)
1226 tcg_gen_ext32s_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1227 tcg_gen_ext32s_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1229 tcg_gen_ext_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1230 tcg_gen_ext_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1232 tcg_gen_mul_i64(t0
, t0
, t1
);
1233 #if defined(TARGET_PPC64)
1234 tcg_gen_ext32s_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1235 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, cpu_gpr
[rD(ctx
->opcode
)], l1
);
1237 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1238 tcg_gen_ext32s_i64(t1
, t0
);
1239 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
1241 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1243 tcg_temp_free_i64(t0
);
1244 tcg_temp_free_i64(t1
);
1245 if (unlikely(Rc(ctx
->opcode
) != 0))
1246 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1249 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1251 tcg_gen_muli_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1254 #if defined(TARGET_PPC64)
1255 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
1256 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) \
1258 gen_helper_##name (cpu_gpr[rD(ctx->opcode)], \
1259 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
1260 if (unlikely(Rc(ctx->opcode) != 0)) \
1261 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1264 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00);
1265 /* mulhdu mulhdu. */
1266 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02);
1268 GEN_HANDLER(mulld
, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B
)
1270 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1271 cpu_gpr
[rB(ctx
->opcode
)]);
1272 if (unlikely(Rc(ctx
->opcode
) != 0))
1273 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1275 /* mulldo mulldo. */
1276 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17);
1279 /* neg neg. nego nego. */
1280 static always_inline
void gen_op_arith_neg (DisasContext
*ctx
, TCGv ret
, TCGv arg1
, int ov_check
)
1282 int l1
= gen_new_label();
1283 int l2
= gen_new_label();
1284 TCGv t0
= tcg_temp_local_new();
1285 #if defined(TARGET_PPC64)
1287 tcg_gen_mov_tl(t0
, arg1
);
1288 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, INT64_MIN
, l1
);
1292 tcg_gen_ext32s_tl(t0
, arg1
);
1293 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, INT32_MIN
, l1
);
1295 tcg_gen_neg_tl(ret
, arg1
);
1297 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1301 tcg_gen_mov_tl(ret
, t0
);
1303 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1307 if (unlikely(Rc(ctx
->opcode
) != 0))
1308 gen_set_Rc0(ctx
, ret
);
1310 GEN_HANDLER(neg
, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER
)
1312 gen_op_arith_neg(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0);
1314 GEN_HANDLER(nego
, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER
)
1316 gen_op_arith_neg(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 1);
1319 /* Common subf function */
1320 static always_inline
void gen_op_arith_subf(DisasContext
*ctx
, TCGv ret
, TCGv arg1
, TCGv arg2
,
1321 int add_ca
, int compute_ca
, int compute_ov
)
1325 if ((!compute_ca
&& !compute_ov
) ||
1326 (!TCGV_EQUAL(ret
, arg1
) && !TCGV_EQUAL(ret
, arg2
))) {
1329 t0
= tcg_temp_local_new();
1333 t1
= tcg_temp_local_new();
1334 tcg_gen_andi_tl(t1
, cpu_xer
, (1 << XER_CA
));
1335 tcg_gen_shri_tl(t1
, t1
, XER_CA
);
1338 if (compute_ca
&& compute_ov
) {
1339 /* Start with XER CA and OV disabled, the most likely case */
1340 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~((1 << XER_CA
) | (1 << XER_OV
)));
1341 } else if (compute_ca
) {
1342 /* Start with XER CA disabled, the most likely case */
1343 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1344 } else if (compute_ov
) {
1345 /* Start with XER OV disabled, the most likely case */
1346 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1350 tcg_gen_not_tl(t0
, arg1
);
1351 tcg_gen_add_tl(t0
, t0
, arg2
);
1352 gen_op_arith_compute_ca(ctx
, t0
, arg2
, 0);
1353 tcg_gen_add_tl(t0
, t0
, t1
);
1354 gen_op_arith_compute_ca(ctx
, t0
, t1
, 0);
1357 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1359 gen_op_arith_compute_ca(ctx
, t0
, arg2
, 1);
1363 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 1);
1366 if (unlikely(Rc(ctx
->opcode
) != 0))
1367 gen_set_Rc0(ctx
, t0
);
1369 if (!TCGV_EQUAL(t0
, ret
)) {
1370 tcg_gen_mov_tl(ret
, t0
);
1374 /* Sub functions with Two operands functions */
1375 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1376 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER) \
1378 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1379 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1380 add_ca, compute_ca, compute_ov); \
1382 /* Sub functions with one operand and one immediate */
1383 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1384 add_ca, compute_ca, compute_ov) \
1385 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER) \
1387 TCGv t0 = tcg_const_local_tl(const_val); \
1388 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1389 cpu_gpr[rA(ctx->opcode)], t0, \
1390 add_ca, compute_ca, compute_ov); \
1391 tcg_temp_free(t0); \
1393 /* subf subf. subfo subfo. */
1394 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
1395 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
1396 /* subfc subfc. subfco subfco. */
1397 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
1398 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
1399 /* subfe subfe. subfeo subfo. */
1400 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
1401 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
1402 /* subfme subfme. subfmeo subfmeo. */
1403 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
1404 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
1405 /* subfze subfze. subfzeo subfzeo.*/
1406 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
1407 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
1409 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1411 /* Start with XER CA and OV disabled, the most likely case */
1412 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1413 TCGv t0
= tcg_temp_local_new();
1414 TCGv t1
= tcg_const_local_tl(SIMM(ctx
->opcode
));
1415 tcg_gen_sub_tl(t0
, t1
, cpu_gpr
[rA(ctx
->opcode
)]);
1416 gen_op_arith_compute_ca(ctx
, t0
, t1
, 1);
1418 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1422 /*** Integer logical ***/
1423 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1424 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type) \
1426 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1427 cpu_gpr[rB(ctx->opcode)]); \
1428 if (unlikely(Rc(ctx->opcode) != 0)) \
1429 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1432 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1433 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type) \
1435 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1436 if (unlikely(Rc(ctx->opcode) != 0)) \
1437 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1441 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
);
1443 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
);
1445 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1447 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
));
1448 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1451 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1453 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
) << 16);
1454 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1457 GEN_HANDLER(cntlzw
, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER
)
1459 gen_helper_cntlzw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1460 if (unlikely(Rc(ctx
->opcode
) != 0))
1461 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1464 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
);
1465 /* extsb & extsb. */
1466 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
);
1467 /* extsh & extsh. */
1468 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
);
1470 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
);
1472 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
);
1474 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
)
1478 rs
= rS(ctx
->opcode
);
1479 ra
= rA(ctx
->opcode
);
1480 rb
= rB(ctx
->opcode
);
1481 /* Optimisation for mr. ri case */
1482 if (rs
!= ra
|| rs
!= rb
) {
1484 tcg_gen_or_tl(cpu_gpr
[ra
], cpu_gpr
[rs
], cpu_gpr
[rb
]);
1486 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rs
]);
1487 if (unlikely(Rc(ctx
->opcode
) != 0))
1488 gen_set_Rc0(ctx
, cpu_gpr
[ra
]);
1489 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
1490 gen_set_Rc0(ctx
, cpu_gpr
[rs
]);
1491 #if defined(TARGET_PPC64)
1497 /* Set process priority to low */
1501 /* Set process priority to medium-low */
1505 /* Set process priority to normal */
1508 #if !defined(CONFIG_USER_ONLY)
1510 if (ctx
->mem_idx
> 0) {
1511 /* Set process priority to very low */
1516 if (ctx
->mem_idx
> 0) {
1517 /* Set process priority to medium-hight */
1522 if (ctx
->mem_idx
> 0) {
1523 /* Set process priority to high */
1528 if (ctx
->mem_idx
> 1) {
1529 /* Set process priority to very high */
1539 TCGv t0
= tcg_temp_new();
1540 gen_load_spr(t0
, SPR_PPR
);
1541 tcg_gen_andi_tl(t0
, t0
, ~0x001C000000000000ULL
);
1542 tcg_gen_ori_tl(t0
, t0
, ((uint64_t)prio
) << 50);
1543 gen_store_spr(SPR_PPR
, t0
);
1550 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
);
1552 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
)
1554 /* Optimisation for "set to zero" case */
1555 if (rS(ctx
->opcode
) != rB(ctx
->opcode
))
1556 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1558 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1559 if (unlikely(Rc(ctx
->opcode
) != 0))
1560 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1563 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1565 target_ulong uimm
= UIMM(ctx
->opcode
);
1567 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1569 /* XXX: should handle special NOPs for POWER series */
1572 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1575 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1577 target_ulong uimm
= UIMM(ctx
->opcode
);
1579 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1583 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1586 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1588 target_ulong uimm
= UIMM(ctx
->opcode
);
1590 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1594 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1597 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1599 target_ulong uimm
= UIMM(ctx
->opcode
);
1601 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1605 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1607 /* popcntb : PowerPC 2.03 specification */
1608 GEN_HANDLER(popcntb
, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB
)
1610 #if defined(TARGET_PPC64)
1612 gen_helper_popcntb_64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1615 gen_helper_popcntb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1618 #if defined(TARGET_PPC64)
1619 /* extsw & extsw. */
1620 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
);
1622 GEN_HANDLER(cntlzd
, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B
)
1624 gen_helper_cntlzd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1625 if (unlikely(Rc(ctx
->opcode
) != 0))
1626 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1630 /*** Integer rotate ***/
1631 /* rlwimi & rlwimi. */
1632 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1634 uint32_t mb
, me
, sh
;
1636 mb
= MB(ctx
->opcode
);
1637 me
= ME(ctx
->opcode
);
1638 sh
= SH(ctx
->opcode
);
1639 if (likely(sh
== 0 && mb
== 0 && me
== 31)) {
1640 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1644 TCGv t0
= tcg_temp_new();
1645 #if defined(TARGET_PPC64)
1646 TCGv_i32 t2
= tcg_temp_new_i32();
1647 tcg_gen_trunc_i64_i32(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
1648 tcg_gen_rotli_i32(t2
, t2
, sh
);
1649 tcg_gen_extu_i32_i64(t0
, t2
);
1650 tcg_temp_free_i32(t2
);
1652 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1654 #if defined(TARGET_PPC64)
1658 mask
= MASK(mb
, me
);
1659 t1
= tcg_temp_new();
1660 tcg_gen_andi_tl(t0
, t0
, mask
);
1661 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1662 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1666 if (unlikely(Rc(ctx
->opcode
) != 0))
1667 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1669 /* rlwinm & rlwinm. */
1670 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1672 uint32_t mb
, me
, sh
;
1674 sh
= SH(ctx
->opcode
);
1675 mb
= MB(ctx
->opcode
);
1676 me
= ME(ctx
->opcode
);
1678 if (likely(mb
== 0 && me
== (31 - sh
))) {
1679 if (likely(sh
== 0)) {
1680 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1682 TCGv t0
= tcg_temp_new();
1683 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1684 tcg_gen_shli_tl(t0
, t0
, sh
);
1685 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1688 } else if (likely(sh
!= 0 && me
== 31 && sh
== (32 - mb
))) {
1689 TCGv t0
= tcg_temp_new();
1690 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1691 tcg_gen_shri_tl(t0
, t0
, mb
);
1692 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1695 TCGv t0
= tcg_temp_new();
1696 #if defined(TARGET_PPC64)
1697 TCGv_i32 t1
= tcg_temp_new_i32();
1698 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1699 tcg_gen_rotli_i32(t1
, t1
, sh
);
1700 tcg_gen_extu_i32_i64(t0
, t1
);
1701 tcg_temp_free_i32(t1
);
1703 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1705 #if defined(TARGET_PPC64)
1709 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1712 if (unlikely(Rc(ctx
->opcode
) != 0))
1713 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1715 /* rlwnm & rlwnm. */
1716 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1720 #if defined(TARGET_PPC64)
1724 mb
= MB(ctx
->opcode
);
1725 me
= ME(ctx
->opcode
);
1726 t0
= tcg_temp_new();
1727 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1728 #if defined(TARGET_PPC64)
1729 t1
= tcg_temp_new_i32();
1730 t2
= tcg_temp_new_i32();
1731 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1732 tcg_gen_trunc_i64_i32(t2
, t0
);
1733 tcg_gen_rotl_i32(t1
, t1
, t2
);
1734 tcg_gen_extu_i32_i64(t0
, t1
);
1735 tcg_temp_free_i32(t1
);
1736 tcg_temp_free_i32(t2
);
1738 tcg_gen_rotl_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1740 if (unlikely(mb
!= 0 || me
!= 31)) {
1741 #if defined(TARGET_PPC64)
1745 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1747 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1750 if (unlikely(Rc(ctx
->opcode
) != 0))
1751 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1754 #if defined(TARGET_PPC64)
1755 #define GEN_PPC64_R2(name, opc1, opc2) \
1756 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1758 gen_##name(ctx, 0); \
1760 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1763 gen_##name(ctx, 1); \
1765 #define GEN_PPC64_R4(name, opc1, opc2) \
1766 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1768 gen_##name(ctx, 0, 0); \
1770 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
1773 gen_##name(ctx, 0, 1); \
1775 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1778 gen_##name(ctx, 1, 0); \
1780 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
1783 gen_##name(ctx, 1, 1); \
1786 static always_inline
void gen_rldinm (DisasContext
*ctx
, uint32_t mb
,
1787 uint32_t me
, uint32_t sh
)
1789 if (likely(sh
!= 0 && mb
== 0 && me
== (63 - sh
))) {
1790 tcg_gen_shli_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
1791 } else if (likely(sh
!= 0 && me
== 63 && sh
== (64 - mb
))) {
1792 tcg_gen_shri_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], mb
);
1794 TCGv t0
= tcg_temp_new();
1795 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1796 if (likely(mb
== 0 && me
== 63)) {
1797 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1799 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1803 if (unlikely(Rc(ctx
->opcode
) != 0))
1804 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1806 /* rldicl - rldicl. */
1807 static always_inline
void gen_rldicl (DisasContext
*ctx
, int mbn
, int shn
)
1811 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1812 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1813 gen_rldinm(ctx
, mb
, 63, sh
);
1815 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
1816 /* rldicr - rldicr. */
1817 static always_inline
void gen_rldicr (DisasContext
*ctx
, int men
, int shn
)
1821 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1822 me
= MB(ctx
->opcode
) | (men
<< 5);
1823 gen_rldinm(ctx
, 0, me
, sh
);
1825 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
1826 /* rldic - rldic. */
1827 static always_inline
void gen_rldic (DisasContext
*ctx
, int mbn
, int shn
)
1831 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1832 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1833 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
1835 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
1837 static always_inline
void gen_rldnm (DisasContext
*ctx
, uint32_t mb
,
1842 mb
= MB(ctx
->opcode
);
1843 me
= ME(ctx
->opcode
);
1844 t0
= tcg_temp_new();
1845 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1846 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1847 if (unlikely(mb
!= 0 || me
!= 63)) {
1848 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1850 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1853 if (unlikely(Rc(ctx
->opcode
) != 0))
1854 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1857 /* rldcl - rldcl. */
1858 static always_inline
void gen_rldcl (DisasContext
*ctx
, int mbn
)
1862 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1863 gen_rldnm(ctx
, mb
, 63);
1865 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
1866 /* rldcr - rldcr. */
1867 static always_inline
void gen_rldcr (DisasContext
*ctx
, int men
)
1871 me
= MB(ctx
->opcode
) | (men
<< 5);
1872 gen_rldnm(ctx
, 0, me
);
1874 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
1875 /* rldimi - rldimi. */
1876 static always_inline
void gen_rldimi (DisasContext
*ctx
, int mbn
, int shn
)
1878 uint32_t sh
, mb
, me
;
1880 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1881 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1883 if (unlikely(sh
== 0 && mb
== 0)) {
1884 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1889 t0
= tcg_temp_new();
1890 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1891 t1
= tcg_temp_new();
1892 mask
= MASK(mb
, me
);
1893 tcg_gen_andi_tl(t0
, t0
, mask
);
1894 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1895 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1899 if (unlikely(Rc(ctx
->opcode
) != 0))
1900 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1902 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
1905 /*** Integer shift ***/
1907 GEN_HANDLER(slw
, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER
)
1911 l1
= gen_new_label();
1912 l2
= gen_new_label();
1914 t0
= tcg_temp_local_new();
1915 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1916 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0x20, l1
);
1917 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1920 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t0
);
1921 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
1924 if (unlikely(Rc(ctx
->opcode
) != 0))
1925 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1928 GEN_HANDLER(sraw
, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER
)
1930 gen_helper_sraw(cpu_gpr
[rA(ctx
->opcode
)],
1931 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1932 if (unlikely(Rc(ctx
->opcode
) != 0))
1933 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1935 /* srawi & srawi. */
1936 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
)
1938 int sh
= SH(ctx
->opcode
);
1942 l1
= gen_new_label();
1943 l2
= gen_new_label();
1944 t0
= tcg_temp_local_new();
1945 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1946 tcg_gen_brcondi_tl(TCG_COND_GE
, t0
, 0, l1
);
1947 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1ULL << sh
) - 1);
1948 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
1949 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
1952 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1954 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1955 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, sh
);
1958 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1959 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1961 if (unlikely(Rc(ctx
->opcode
) != 0))
1962 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1965 GEN_HANDLER(srw
, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER
)
1969 l1
= gen_new_label();
1970 l2
= gen_new_label();
1972 t0
= tcg_temp_local_new();
1973 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1974 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0x20, l1
);
1975 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1978 t1
= tcg_temp_new();
1979 tcg_gen_ext32u_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1980 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
, t0
);
1984 if (unlikely(Rc(ctx
->opcode
) != 0))
1985 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1987 #if defined(TARGET_PPC64)
1989 GEN_HANDLER(sld
, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B
)
1993 l1
= gen_new_label();
1994 l2
= gen_new_label();
1996 t0
= tcg_temp_local_new();
1997 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x7f);
1998 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0x40, l1
);
1999 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
2002 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t0
);
2005 if (unlikely(Rc(ctx
->opcode
) != 0))
2006 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2009 GEN_HANDLER(srad
, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B
)
2011 gen_helper_srad(cpu_gpr
[rA(ctx
->opcode
)],
2012 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2013 if (unlikely(Rc(ctx
->opcode
) != 0))
2014 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2016 /* sradi & sradi. */
2017 static always_inline
void gen_sradi (DisasContext
*ctx
, int n
)
2019 int sh
= SH(ctx
->opcode
) + (n
<< 5);
2023 l1
= gen_new_label();
2024 l2
= gen_new_label();
2025 t0
= tcg_temp_local_new();
2026 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
2027 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1ULL << sh
) - 1);
2028 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2029 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
2032 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
2035 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
2037 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
2038 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
2040 if (unlikely(Rc(ctx
->opcode
) != 0))
2041 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2043 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
)
2047 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
)
2052 GEN_HANDLER(srd
, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B
)
2056 l1
= gen_new_label();
2057 l2
= gen_new_label();
2059 t0
= tcg_temp_local_new();
2060 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x7f);
2061 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0x40, l1
);
2062 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
2065 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t0
);
2068 if (unlikely(Rc(ctx
->opcode
) != 0))
2069 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2073 /*** Floating-Point arithmetic ***/
2074 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
2075 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type) \
2077 if (unlikely(!ctx->fpu_enabled)) { \
2078 gen_exception(ctx, POWERPC_EXCP_FPU); \
2081 /* NIP cannot be restored if the memory exception comes from an helper */ \
2082 gen_update_nip(ctx, ctx->nip - 4); \
2083 gen_reset_fpstatus(); \
2084 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], \
2085 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2087 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]); \
2089 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \
2090 Rc(ctx->opcode) != 0); \
2093 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2094 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2095 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
2097 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2098 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
2100 if (unlikely(!ctx->fpu_enabled)) { \
2101 gen_exception(ctx, POWERPC_EXCP_FPU); \
2104 /* NIP cannot be restored if the memory exception comes from an helper */ \
2105 gen_update_nip(ctx, ctx->nip - 4); \
2106 gen_reset_fpstatus(); \
2107 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], \
2108 cpu_fpr[rB(ctx->opcode)]); \
2110 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]); \
2112 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2113 set_fprf, Rc(ctx->opcode) != 0); \
2115 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2116 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2117 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2119 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2120 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
2122 if (unlikely(!ctx->fpu_enabled)) { \
2123 gen_exception(ctx, POWERPC_EXCP_FPU); \
2126 /* NIP cannot be restored if the memory exception comes from an helper */ \
2127 gen_update_nip(ctx, ctx->nip - 4); \
2128 gen_reset_fpstatus(); \
2129 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], \
2130 cpu_fpr[rC(ctx->opcode)]); \
2132 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]); \
2134 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2135 set_fprf, Rc(ctx->opcode) != 0); \
2137 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2138 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2139 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2141 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
2142 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type) \
2144 if (unlikely(!ctx->fpu_enabled)) { \
2145 gen_exception(ctx, POWERPC_EXCP_FPU); \
2148 /* NIP cannot be restored if the memory exception comes from an helper */ \
2149 gen_update_nip(ctx, ctx->nip - 4); \
2150 gen_reset_fpstatus(); \
2151 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2152 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2153 set_fprf, Rc(ctx->opcode) != 0); \
2156 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
2157 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type) \
2159 if (unlikely(!ctx->fpu_enabled)) { \
2160 gen_exception(ctx, POWERPC_EXCP_FPU); \
2163 /* NIP cannot be restored if the memory exception comes from an helper */ \
2164 gen_update_nip(ctx, ctx->nip - 4); \
2165 gen_reset_fpstatus(); \
2166 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2167 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2168 set_fprf, Rc(ctx->opcode) != 0); \
2172 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
);
2174 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
);
2176 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
);
2179 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
);
2182 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
);
2185 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
);
2188 GEN_HANDLER(frsqrtes
, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES
)
2190 if (unlikely(!ctx
->fpu_enabled
)) {
2191 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2194 /* NIP cannot be restored if the memory exception comes from an helper */
2195 gen_update_nip(ctx
, ctx
->nip
- 4);
2196 gen_reset_fpstatus();
2197 gen_helper_frsqrte(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2198 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rD(ctx
->opcode
)]);
2199 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2203 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
);
2205 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
);
2208 GEN_HANDLER(fsqrt
, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
)
2210 if (unlikely(!ctx
->fpu_enabled
)) {
2211 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2214 /* NIP cannot be restored if the memory exception comes from an helper */
2215 gen_update_nip(ctx
, ctx
->nip
- 4);
2216 gen_reset_fpstatus();
2217 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2218 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2221 GEN_HANDLER(fsqrts
, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
)
2223 if (unlikely(!ctx
->fpu_enabled
)) {
2224 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2227 /* NIP cannot be restored if the memory exception comes from an helper */
2228 gen_update_nip(ctx
, ctx
->nip
- 4);
2229 gen_reset_fpstatus();
2230 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2231 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rD(ctx
->opcode
)]);
2232 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2235 /*** Floating-Point multiply-and-add ***/
2236 /* fmadd - fmadds */
2237 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
);
2238 /* fmsub - fmsubs */
2239 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
);
2240 /* fnmadd - fnmadds */
2241 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
);
2242 /* fnmsub - fnmsubs */
2243 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
);
2245 /*** Floating-Point round & convert ***/
2247 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
);
2249 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
);
2251 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
);
2252 #if defined(TARGET_PPC64)
2254 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
);
2256 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
);
2258 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
);
2262 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
);
2264 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
);
2266 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
);
2268 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
);
2270 /*** Floating-Point compare ***/
2272 GEN_HANDLER(fcmpo
, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT
)
2275 if (unlikely(!ctx
->fpu_enabled
)) {
2276 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2279 /* NIP cannot be restored if the memory exception comes from an helper */
2280 gen_update_nip(ctx
, ctx
->nip
- 4);
2281 gen_reset_fpstatus();
2282 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2283 gen_helper_fcmpo(cpu_fpr
[rA(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)], crf
);
2284 tcg_temp_free_i32(crf
);
2285 gen_helper_float_check_status();
2289 GEN_HANDLER(fcmpu
, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT
)
2292 if (unlikely(!ctx
->fpu_enabled
)) {
2293 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2296 /* NIP cannot be restored if the memory exception comes from an helper */
2297 gen_update_nip(ctx
, ctx
->nip
- 4);
2298 gen_reset_fpstatus();
2299 crf
= tcg_const_i32(crfD(ctx
->opcode
));
2300 gen_helper_fcmpu(cpu_fpr
[rA(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)], crf
);
2301 tcg_temp_free_i32(crf
);
2302 gen_helper_float_check_status();
2305 /*** Floating-point move ***/
2307 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2308 GEN_FLOAT_B(abs
, 0x08, 0x08, 0, PPC_FLOAT
);
2311 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2312 GEN_HANDLER(fmr
, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT
)
2314 if (unlikely(!ctx
->fpu_enabled
)) {
2315 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2318 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2319 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2323 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2324 GEN_FLOAT_B(nabs
, 0x08, 0x04, 0, PPC_FLOAT
);
2326 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2327 GEN_FLOAT_B(neg
, 0x08, 0x01, 0, PPC_FLOAT
);
2329 /*** Floating-Point status & ctrl register ***/
2331 GEN_HANDLER(mcrfs
, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT
)
2335 if (unlikely(!ctx
->fpu_enabled
)) {
2336 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2339 bfa
= 4 * (7 - crfS(ctx
->opcode
));
2340 tcg_gen_shri_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_fpscr
, bfa
);
2341 tcg_gen_andi_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfD(ctx
->opcode
)], 0xf);
2342 tcg_gen_andi_i32(cpu_fpscr
, cpu_fpscr
, ~(0xF << bfa
));
2346 GEN_HANDLER(mffs
, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT
)
2348 if (unlikely(!ctx
->fpu_enabled
)) {
2349 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2352 gen_reset_fpstatus();
2353 tcg_gen_extu_i32_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpscr
);
2354 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2358 GEN_HANDLER(mtfsb0
, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT
)
2362 if (unlikely(!ctx
->fpu_enabled
)) {
2363 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2366 crb
= 31 - crbD(ctx
->opcode
);
2367 gen_reset_fpstatus();
2368 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
)) {
2370 /* NIP cannot be restored if the memory exception comes from an helper */
2371 gen_update_nip(ctx
, ctx
->nip
- 4);
2372 t0
= tcg_const_i32(crb
);
2373 gen_helper_fpscr_clrbit(t0
);
2374 tcg_temp_free_i32(t0
);
2376 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2377 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2382 GEN_HANDLER(mtfsb1
, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT
)
2386 if (unlikely(!ctx
->fpu_enabled
)) {
2387 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2390 crb
= 31 - crbD(ctx
->opcode
);
2391 gen_reset_fpstatus();
2392 /* XXX: we pretend we can only do IEEE floating-point computations */
2393 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
&& crb
!= FPSCR_NI
)) {
2395 /* NIP cannot be restored if the memory exception comes from an helper */
2396 gen_update_nip(ctx
, ctx
->nip
- 4);
2397 t0
= tcg_const_i32(crb
);
2398 gen_helper_fpscr_setbit(t0
);
2399 tcg_temp_free_i32(t0
);
2401 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2402 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2404 /* We can raise a differed exception */
2405 gen_helper_float_check_status();
2409 GEN_HANDLER(mtfsf
, 0x3F, 0x07, 0x16, 0x02010000, PPC_FLOAT
)
2413 if (unlikely(!ctx
->fpu_enabled
)) {
2414 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2417 /* NIP cannot be restored if the memory exception comes from an helper */
2418 gen_update_nip(ctx
, ctx
->nip
- 4);
2419 gen_reset_fpstatus();
2420 t0
= tcg_const_i32(FM(ctx
->opcode
));
2421 gen_helper_store_fpscr(cpu_fpr
[rB(ctx
->opcode
)], t0
);
2422 tcg_temp_free_i32(t0
);
2423 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2424 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2426 /* We can raise a differed exception */
2427 gen_helper_float_check_status();
2431 GEN_HANDLER(mtfsfi
, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT
)
2437 if (unlikely(!ctx
->fpu_enabled
)) {
2438 gen_exception(ctx
, POWERPC_EXCP_FPU
);
2441 bf
= crbD(ctx
->opcode
) >> 2;
2443 /* NIP cannot be restored if the memory exception comes from an helper */
2444 gen_update_nip(ctx
, ctx
->nip
- 4);
2445 gen_reset_fpstatus();
2446 t0
= tcg_const_i64(FPIMM(ctx
->opcode
) << (4 * sh
));
2447 t1
= tcg_const_i32(1 << sh
);
2448 gen_helper_store_fpscr(t0
, t1
);
2449 tcg_temp_free_i64(t0
);
2450 tcg_temp_free_i32(t1
);
2451 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2452 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2454 /* We can raise a differed exception */
2455 gen_helper_float_check_status();
2458 /*** Addressing modes ***/
2459 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2460 static always_inline
void gen_addr_imm_index (DisasContext
*ctx
, TCGv EA
, target_long maskl
)
2462 target_long simm
= SIMM(ctx
->opcode
);
2465 if (rA(ctx
->opcode
) == 0) {
2466 #if defined(TARGET_PPC64)
2467 if (!ctx
->sf_mode
) {
2468 tcg_gen_movi_tl(EA
, (uint32_t)simm
);
2471 tcg_gen_movi_tl(EA
, simm
);
2472 } else if (likely(simm
!= 0)) {
2473 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
);
2474 #if defined(TARGET_PPC64)
2475 if (!ctx
->sf_mode
) {
2476 tcg_gen_ext32u_tl(EA
, EA
);
2480 #if defined(TARGET_PPC64)
2481 if (!ctx
->sf_mode
) {
2482 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2485 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2489 static always_inline
void gen_addr_reg_index (DisasContext
*ctx
, TCGv EA
)
2491 if (rA(ctx
->opcode
) == 0) {
2492 #if defined(TARGET_PPC64)
2493 if (!ctx
->sf_mode
) {
2494 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2497 tcg_gen_mov_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2499 tcg_gen_add_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2500 #if defined(TARGET_PPC64)
2501 if (!ctx
->sf_mode
) {
2502 tcg_gen_ext32u_tl(EA
, EA
);
2508 static always_inline
void gen_addr_register (DisasContext
*ctx
, TCGv EA
)
2510 if (rA(ctx
->opcode
) == 0) {
2511 tcg_gen_movi_tl(EA
, 0);
2513 #if defined(TARGET_PPC64)
2514 if (!ctx
->sf_mode
) {
2515 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2518 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2522 static always_inline
void gen_addr_add (DisasContext
*ctx
, TCGv ret
, TCGv arg1
, target_long val
)
2524 tcg_gen_addi_tl(ret
, arg1
, val
);
2525 #if defined(TARGET_PPC64)
2526 if (!ctx
->sf_mode
) {
2527 tcg_gen_ext32u_tl(ret
, ret
);
2532 static always_inline
void gen_check_align (DisasContext
*ctx
, TCGv EA
, int mask
)
2534 int l1
= gen_new_label();
2535 TCGv t0
= tcg_temp_new();
2537 /* NIP cannot be restored if the memory exception comes from an helper */
2538 gen_update_nip(ctx
, ctx
->nip
- 4);
2539 tcg_gen_andi_tl(t0
, EA
, mask
);
2540 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2541 t1
= tcg_const_i32(POWERPC_EXCP_ALIGN
);
2542 t2
= tcg_const_i32(0);
2543 gen_helper_raise_exception_err(t1
, t2
);
2544 tcg_temp_free_i32(t1
);
2545 tcg_temp_free_i32(t2
);
2550 /*** Integer load ***/
2551 static always_inline
void gen_qemu_ld8u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2553 tcg_gen_qemu_ld8u(arg1
, arg2
, ctx
->mem_idx
);
2556 static always_inline
void gen_qemu_ld8s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2558 tcg_gen_qemu_ld8s(arg1
, arg2
, ctx
->mem_idx
);
2561 static always_inline
void gen_qemu_ld16u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2563 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2564 if (unlikely(ctx
->le_mode
)) {
2565 #if defined(TARGET_PPC64)
2566 TCGv_i32 t0
= tcg_temp_new_i32();
2567 tcg_gen_trunc_tl_i32(t0
, arg1
);
2568 tcg_gen_bswap16_i32(t0
, t0
);
2569 tcg_gen_extu_i32_tl(arg1
, t0
);
2570 tcg_temp_free_i32(t0
);
2572 tcg_gen_bswap16_i32(arg1
, arg1
);
2577 static always_inline
void gen_qemu_ld16s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2579 if (unlikely(ctx
->le_mode
)) {
2580 #if defined(TARGET_PPC64)
2582 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2583 t0
= tcg_temp_new_i32();
2584 tcg_gen_trunc_tl_i32(t0
, arg1
);
2585 tcg_gen_bswap16_i32(t0
, t0
);
2586 tcg_gen_extu_i32_tl(arg1
, t0
);
2587 tcg_gen_ext16s_tl(arg1
, arg1
);
2588 tcg_temp_free_i32(t0
);
2590 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2591 tcg_gen_bswap16_i32(arg1
, arg1
);
2592 tcg_gen_ext16s_i32(arg1
, arg1
);
2595 tcg_gen_qemu_ld16s(arg1
, arg2
, ctx
->mem_idx
);
2599 static always_inline
void gen_qemu_ld32u(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2601 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2602 if (unlikely(ctx
->le_mode
)) {
2603 #if defined(TARGET_PPC64)
2604 TCGv_i32 t0
= tcg_temp_new_i32();
2605 tcg_gen_trunc_tl_i32(t0
, arg1
);
2606 tcg_gen_bswap_i32(t0
, t0
);
2607 tcg_gen_extu_i32_tl(arg1
, t0
);
2608 tcg_temp_free_i32(t0
);
2610 tcg_gen_bswap_i32(arg1
, arg1
);
2615 #if defined(TARGET_PPC64)
2616 static always_inline
void gen_qemu_ld32s(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2618 if (unlikely(ctx
->mem_idx
)) {
2620 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2621 t0
= tcg_temp_new_i32();
2622 tcg_gen_trunc_tl_i32(t0
, arg1
);
2623 tcg_gen_bswap_i32(t0
, t0
);
2624 tcg_gen_ext_i32_tl(arg1
, t0
);
2625 tcg_temp_free_i32(t0
);
2627 tcg_gen_qemu_ld32s(arg1
, arg2
, ctx
->mem_idx
);
2631 static always_inline
void gen_qemu_ld64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2633 tcg_gen_qemu_ld64(arg1
, arg2
, ctx
->mem_idx
);
2634 if (unlikely(ctx
->le_mode
)) {
2635 tcg_gen_bswap_i64(arg1
, arg1
);
2639 static always_inline
void gen_qemu_st8(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2641 tcg_gen_qemu_st8(arg1
, arg2
, ctx
->mem_idx
);
2644 static always_inline
void gen_qemu_st16(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2646 if (unlikely(ctx
->le_mode
)) {
2647 #if defined(TARGET_PPC64)
2650 t0
= tcg_temp_new_i32();
2651 tcg_gen_trunc_tl_i32(t0
, arg1
);
2652 tcg_gen_ext16u_i32(t0
, t0
);
2653 tcg_gen_bswap16_i32(t0
, t0
);
2654 t1
= tcg_temp_new();
2655 tcg_gen_extu_i32_tl(t1
, t0
);
2656 tcg_temp_free_i32(t0
);
2657 tcg_gen_qemu_st16(t1
, arg2
, ctx
->mem_idx
);
2660 TCGv t0
= tcg_temp_new();
2661 tcg_gen_ext16u_tl(t0
, arg1
);
2662 tcg_gen_bswap16_i32(t0
, t0
);
2663 tcg_gen_qemu_st16(t0
, arg2
, ctx
->mem_idx
);
2667 tcg_gen_qemu_st16(arg1
, arg2
, ctx
->mem_idx
);
2671 static always_inline
void gen_qemu_st32(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2673 if (unlikely(ctx
->le_mode
)) {
2674 #if defined(TARGET_PPC64)
2677 t0
= tcg_temp_new_i32();
2678 tcg_gen_trunc_tl_i32(t0
, arg1
);
2679 tcg_gen_bswap_i32(t0
, t0
);
2680 t1
= tcg_temp_new();
2681 tcg_gen_extu_i32_tl(t1
, t0
);
2682 tcg_temp_free_i32(t0
);
2683 tcg_gen_qemu_st32(t1
, arg2
, ctx
->mem_idx
);
2686 TCGv t0
= tcg_temp_new_i32();
2687 tcg_gen_bswap_i32(t0
, arg1
);
2688 tcg_gen_qemu_st32(t0
, arg2
, ctx
->mem_idx
);
2692 tcg_gen_qemu_st32(arg1
, arg2
, ctx
->mem_idx
);
2696 static always_inline
void gen_qemu_st64(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
2698 if (unlikely(ctx
->le_mode
)) {
2699 TCGv_i64 t0
= tcg_temp_new_i64();
2700 tcg_gen_bswap_i64(t0
, arg1
);
2701 tcg_gen_qemu_st64(t0
, arg2
, ctx
->mem_idx
);
2702 tcg_temp_free_i64(t0
);
2704 tcg_gen_qemu_st64(arg1
, arg2
, ctx
->mem_idx
);
2707 #define GEN_LD(name, ldop, opc, type) \
2708 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type) \
2711 gen_set_access_type(ctx, ACCESS_INT); \
2712 EA = tcg_temp_new(); \
2713 gen_addr_imm_index(ctx, EA, 0); \
2714 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2715 tcg_temp_free(EA); \
2718 #define GEN_LDU(name, ldop, opc, type) \
2719 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2722 if (unlikely(rA(ctx->opcode) == 0 || \
2723 rA(ctx->opcode) == rD(ctx->opcode))) { \
2724 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2727 gen_set_access_type(ctx, ACCESS_INT); \
2728 EA = tcg_temp_new(); \
2729 if (type == PPC_64B) \
2730 gen_addr_imm_index(ctx, EA, 0x03); \
2732 gen_addr_imm_index(ctx, EA, 0); \
2733 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2734 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2735 tcg_temp_free(EA); \
2738 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
2739 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2742 if (unlikely(rA(ctx->opcode) == 0 || \
2743 rA(ctx->opcode) == rD(ctx->opcode))) { \
2744 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2747 gen_set_access_type(ctx, ACCESS_INT); \
2748 EA = tcg_temp_new(); \
2749 gen_addr_reg_index(ctx, EA); \
2750 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2751 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2752 tcg_temp_free(EA); \
2755 #define GEN_LDX(name, ldop, opc2, opc3, type) \
2756 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type) \
2759 gen_set_access_type(ctx, ACCESS_INT); \
2760 EA = tcg_temp_new(); \
2761 gen_addr_reg_index(ctx, EA); \
2762 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
2763 tcg_temp_free(EA); \
2766 #define GEN_LDS(name, ldop, op, type) \
2767 GEN_LD(name, ldop, op | 0x20, type); \
2768 GEN_LDU(name, ldop, op | 0x21, type); \
2769 GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2770 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
2772 /* lbz lbzu lbzux lbzx */
2773 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
);
2774 /* lha lhau lhaux lhax */
2775 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
);
2776 /* lhz lhzu lhzux lhzx */
2777 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
);
2778 /* lwz lwzu lwzux lwzx */
2779 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
);
2780 #if defined(TARGET_PPC64)
2782 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
);
2784 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
);
2786 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
);
2788 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
);
2789 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
)
2792 if (Rc(ctx
->opcode
)) {
2793 if (unlikely(rA(ctx
->opcode
) == 0 ||
2794 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
2795 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2799 gen_set_access_type(ctx
, ACCESS_INT
);
2800 EA
= tcg_temp_new();
2801 gen_addr_imm_index(ctx
, EA
, 0x03);
2802 if (ctx
->opcode
& 0x02) {
2803 /* lwa (lwau is undefined) */
2804 gen_qemu_ld32s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2807 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
2809 if (Rc(ctx
->opcode
))
2810 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2814 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
)
2816 #if defined(CONFIG_USER_ONLY)
2817 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2822 /* Restore CPU state */
2823 if (unlikely(ctx
->mem_idx
== 0)) {
2824 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2827 ra
= rA(ctx
->opcode
);
2828 rd
= rD(ctx
->opcode
);
2829 if (unlikely((rd
& 1) || rd
== ra
)) {
2830 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2833 if (unlikely(ctx
->le_mode
)) {
2834 /* Little-endian mode is not handled */
2835 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2838 gen_set_access_type(ctx
, ACCESS_INT
);
2839 EA
= tcg_temp_new();
2840 gen_addr_imm_index(ctx
, EA
, 0x0F);
2841 gen_qemu_ld64(ctx
, cpu_gpr
[rd
], EA
);
2842 gen_addr_add(ctx
, EA
, EA
, 8);
2843 gen_qemu_ld64(ctx
, cpu_gpr
[rd
+1], EA
);
2849 /*** Integer store ***/
2850 #define GEN_ST(name, stop, opc, type) \
2851 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type) \
2854 gen_set_access_type(ctx, ACCESS_INT); \
2855 EA = tcg_temp_new(); \
2856 gen_addr_imm_index(ctx, EA, 0); \
2857 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2858 tcg_temp_free(EA); \
2861 #define GEN_STU(name, stop, opc, type) \
2862 GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2865 if (unlikely(rA(ctx->opcode) == 0)) { \
2866 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2869 gen_set_access_type(ctx, ACCESS_INT); \
2870 EA = tcg_temp_new(); \
2871 if (type == PPC_64B) \
2872 gen_addr_imm_index(ctx, EA, 0x03); \
2874 gen_addr_imm_index(ctx, EA, 0); \
2875 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2876 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2877 tcg_temp_free(EA); \
2880 #define GEN_STUX(name, stop, opc2, opc3, type) \
2881 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2884 if (unlikely(rA(ctx->opcode) == 0)) { \
2885 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
2888 gen_set_access_type(ctx, ACCESS_INT); \
2889 EA = tcg_temp_new(); \
2890 gen_addr_reg_index(ctx, EA); \
2891 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2892 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2893 tcg_temp_free(EA); \
2896 #define GEN_STX(name, stop, opc2, opc3, type) \
2897 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type) \
2900 gen_set_access_type(ctx, ACCESS_INT); \
2901 EA = tcg_temp_new(); \
2902 gen_addr_reg_index(ctx, EA); \
2903 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
2904 tcg_temp_free(EA); \
2907 #define GEN_STS(name, stop, op, type) \
2908 GEN_ST(name, stop, op | 0x20, type); \
2909 GEN_STU(name, stop, op | 0x21, type); \
2910 GEN_STUX(name, stop, 0x17, op | 0x01, type); \
2911 GEN_STX(name, stop, 0x17, op | 0x00, type)
2913 /* stb stbu stbux stbx */
2914 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
);
2915 /* sth sthu sthux sthx */
2916 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
);
2917 /* stw stwu stwux stwx */
2918 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
);
2919 #if defined(TARGET_PPC64)
2920 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
);
2921 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
);
2922 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
)
2927 rs
= rS(ctx
->opcode
);
2928 if ((ctx
->opcode
& 0x3) == 0x2) {
2929 #if defined(CONFIG_USER_ONLY)
2930 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2933 if (unlikely(ctx
->mem_idx
== 0)) {
2934 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
2937 if (unlikely(rs
& 1)) {
2938 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2941 if (unlikely(ctx
->le_mode
)) {
2942 /* Little-endian mode is not handled */
2943 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2946 gen_set_access_type(ctx
, ACCESS_INT
);
2947 EA
= tcg_temp_new();
2948 gen_addr_imm_index(ctx
, EA
, 0x03);
2949 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
2950 gen_addr_add(ctx
, EA
, EA
, 8);
2951 gen_qemu_st64(ctx
, cpu_gpr
[rs
+1], EA
);
2956 if (Rc(ctx
->opcode
)) {
2957 if (unlikely(rA(ctx
->opcode
) == 0)) {
2958 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
2962 gen_set_access_type(ctx
, ACCESS_INT
);
2963 EA
= tcg_temp_new();
2964 gen_addr_imm_index(ctx
, EA
, 0x03);
2965 gen_qemu_st64(ctx
, cpu_gpr
[rs
], EA
);
2966 if (Rc(ctx
->opcode
))
2967 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2972 /*** Integer load and store with byte reverse ***/
2974 static void always_inline
gen_qemu_ld16ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2976 tcg_gen_qemu_ld16u(arg1
, arg2
, ctx
->mem_idx
);
2977 if (likely(!ctx
->le_mode
)) {
2978 #if defined(TARGET_PPC64)
2979 TCGv_i32 t0
= tcg_temp_new_i32();
2980 tcg_gen_trunc_tl_i32(t0
, arg1
);
2981 tcg_gen_bswap16_i32(t0
, t0
);
2982 tcg_gen_extu_i32_tl(arg1
, t0
);
2983 tcg_temp_free_i32(t0
);
2985 tcg_gen_bswap16_i32(arg1
, arg1
);
2989 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
);
2992 static void always_inline
gen_qemu_ld32ur(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
2994 tcg_gen_qemu_ld32u(arg1
, arg2
, ctx
->mem_idx
);
2995 if (likely(!ctx
->le_mode
)) {
2996 #if defined(TARGET_PPC64)
2997 TCGv_i32 t0
= tcg_temp_new_i32();
2998 tcg_gen_trunc_tl_i32(t0
, arg1
);
2999 tcg_gen_bswap_i32(t0
, t0
);
3000 tcg_gen_extu_i32_tl(arg1
, t0
);
3001 tcg_temp_free_i32(t0
);
3003 tcg_gen_bswap_i32(arg1
, arg1
);
3007 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
);
3010 static void always_inline
gen_qemu_st16r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3012 if (likely(!ctx
->le_mode
)) {
3013 #if defined(TARGET_PPC64)
3016 t0
= tcg_temp_new_i32();
3017 tcg_gen_trunc_tl_i32(t0
, arg1
);
3018 tcg_gen_ext16u_i32(t0
, t0
);
3019 tcg_gen_bswap16_i32(t0
, t0
);
3020 t1
= tcg_temp_new();
3021 tcg_gen_extu_i32_tl(t1
, t0
);
3022 tcg_temp_free_i32(t0
);
3023 tcg_gen_qemu_st16(t1
, arg2
, ctx
->mem_idx
);
3026 TCGv t0
= tcg_temp_new();
3027 tcg_gen_ext16u_tl(t0
, arg1
);
3028 tcg_gen_bswap16_i32(t0
, t0
);
3029 tcg_gen_qemu_st16(t0
, arg2
, ctx
->mem_idx
);
3033 tcg_gen_qemu_st16(arg1
, arg2
, ctx
->mem_idx
);
3036 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
);
3039 static void always_inline
gen_qemu_st32r(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
)
3041 if (likely(!ctx
->le_mode
)) {
3042 #if defined(TARGET_PPC64)
3045 t0
= tcg_temp_new_i32();
3046 tcg_gen_trunc_tl_i32(t0
, arg1
);
3047 tcg_gen_bswap_i32(t0
, t0
);
3048 t1
= tcg_temp_new();
3049 tcg_gen_extu_i32_tl(t1
, t0
);
3050 tcg_temp_free_i32(t0
);
3051 tcg_gen_qemu_st32(t1
, arg2
, ctx
->mem_idx
);
3054 TCGv t0
= tcg_temp_new_i32();
3055 tcg_gen_bswap_i32(t0
, arg1
);
3056 tcg_gen_qemu_st32(t0
, arg2
, ctx
->mem_idx
);
3060 tcg_gen_qemu_st32(arg1
, arg2
, ctx
->mem_idx
);
3063 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
);
3065 /*** Integer load and store multiple ***/
3067 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
3071 gen_set_access_type(ctx
, ACCESS_INT
);
3072 /* NIP cannot be restored if the memory exception comes from an helper */
3073 gen_update_nip(ctx
, ctx
->nip
- 4);
3074 t0
= tcg_temp_new();
3075 t1
= tcg_const_i32(rD(ctx
->opcode
));
3076 gen_addr_imm_index(ctx
, t0
, 0);
3077 gen_helper_lmw(t0
, t1
);
3079 tcg_temp_free_i32(t1
);
3083 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
3087 gen_set_access_type(ctx
, ACCESS_INT
);
3088 /* NIP cannot be restored if the memory exception comes from an helper */
3089 gen_update_nip(ctx
, ctx
->nip
- 4);
3090 t0
= tcg_temp_new();
3091 t1
= tcg_const_i32(rS(ctx
->opcode
));
3092 gen_addr_imm_index(ctx
, t0
, 0);
3093 gen_helper_stmw(t0
, t1
);
3095 tcg_temp_free_i32(t1
);
3098 /*** Integer load and store strings ***/
3100 /* PowerPC32 specification says we must generate an exception if
3101 * rA is in the range of registers to be loaded.
3102 * In an other hand, IBM says this is valid, but rA won't be loaded.
3103 * For now, I'll follow the spec...
3105 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
)
3109 int nb
= NB(ctx
->opcode
);
3110 int start
= rD(ctx
->opcode
);
3111 int ra
= rA(ctx
->opcode
);
3117 if (unlikely(((start
+ nr
) > 32 &&
3118 start
<= ra
&& (start
+ nr
- 32) > ra
) ||
3119 ((start
+ nr
) <= 32 && start
<= ra
&& (start
+ nr
) > ra
))) {
3120 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
3123 gen_set_access_type(ctx
, ACCESS_INT
);
3124 /* NIP cannot be restored if the memory exception comes from an helper */
3125 gen_update_nip(ctx
, ctx
->nip
- 4);
3126 t0
= tcg_temp_new();
3127 gen_addr_register(ctx
, t0
);
3128 t1
= tcg_const_i32(nb
);
3129 t2
= tcg_const_i32(start
);
3130 gen_helper_lsw(t0
, t1
, t2
);
3132 tcg_temp_free_i32(t1
);
3133 tcg_temp_free_i32(t2
);
3137 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
)
3140 TCGv_i32 t1
, t2
, t3
;
3141 gen_set_access_type(ctx
, ACCESS_INT
);
3142 /* NIP cannot be restored if the memory exception comes from an helper */
3143 gen_update_nip(ctx
, ctx
->nip
- 4);
3144 t0
= tcg_temp_new();
3145 gen_addr_reg_index(ctx
, t0
);
3146 t1
= tcg_const_i32(rD(ctx
->opcode
));
3147 t2
= tcg_const_i32(rA(ctx
->opcode
));
3148 t3
= tcg_const_i32(rB(ctx
->opcode
));
3149 gen_helper_lswx(t0
, t1
, t2
, t3
);
3151 tcg_temp_free_i32(t1
);
3152 tcg_temp_free_i32(t2
);
3153 tcg_temp_free_i32(t3
);
3157 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
)
3161 int nb
= NB(ctx
->opcode
);
3162 gen_set_access_type(ctx
, ACCESS_INT
);
3163 /* NIP cannot be restored if the memory exception comes from an helper */
3164 gen_update_nip(ctx
, ctx
->nip
- 4);
3165 t0
= tcg_temp_new();
3166 gen_addr_register(ctx
, t0
);
3169 t1
= tcg_const_i32(nb
);
3170 t2
= tcg_const_i32(rS(ctx
->opcode
));
3171 gen_helper_stsw(t0
, t1
, t2
);
3173 tcg_temp_free_i32(t1
);
3174 tcg_temp_free_i32(t2
);
3178 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
)
3182 gen_set_access_type(ctx
, ACCESS_INT
);
3183 /* NIP cannot be restored if the memory exception comes from an helper */
3184 gen_update_nip(ctx
, ctx
->nip
- 4);
3185 t0
= tcg_temp_new();
3186 gen_addr_reg_index(ctx
, t0
);
3187 t1
= tcg_temp_new_i32();
3188 tcg_gen_trunc_tl_i32(t1
, cpu_xer
);
3189 tcg_gen_andi_i32(t1
, t1
, 0x7F);
3190 t2
= tcg_const_i32(rS(ctx
->opcode
));
3191 gen_helper_stsw(t0
, t1
, t2
);
3193 tcg_temp_free_i32(t1
);
3194 tcg_temp_free_i32(t2
);
3197 /*** Memory synchronisation ***/
3199 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO
)
3204 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
)
3206 gen_stop_exception(ctx
);
3210 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000001, PPC_RES
)
3213 gen_set_access_type(ctx
, ACCESS_RES
);
3214 t0
= tcg_temp_local_new();
3215 gen_addr_reg_index(ctx
, t0
);
3216 gen_check_align(ctx
, t0
, 0x03);
3217 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
3218 tcg_gen_mov_tl(cpu_reserve
, t0
);
3223 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
)
3227 gen_set_access_type(ctx
, ACCESS_RES
);
3228 t0
= tcg_temp_local_new();
3229 gen_addr_reg_index(ctx
, t0
);
3230 gen_check_align(ctx
, t0
, 0x03);
3231 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_xer
);
3232 tcg_gen_shri_i32(cpu_crf
[0], cpu_crf
[0], XER_SO
);
3233 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 1);
3234 l1
= gen_new_label();
3235 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
3236 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3237 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3239 tcg_gen_movi_tl(cpu_reserve
, -1);
3243 #if defined(TARGET_PPC64)
3245 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000001, PPC_64B
)
3248 gen_set_access_type(ctx
, ACCESS_RES
);
3249 t0
= tcg_temp_local_new();
3250 gen_addr_reg_index(ctx
, t0
);
3251 gen_check_align(ctx
, t0
, 0x07);
3252 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
3253 tcg_gen_mov_tl(cpu_reserve
, t0
);
3258 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
)
3262 gen_set_access_type(ctx
, ACCESS_RES
);
3263 t0
= tcg_temp_local_new();
3264 gen_addr_reg_index(ctx
, t0
);
3265 gen_check_align(ctx
, t0
, 0x07);
3266 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_xer
);
3267 tcg_gen_shri_i32(cpu_crf
[0], cpu_crf
[0], XER_SO
);
3268 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 1);
3269 l1
= gen_new_label();
3270 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
3271 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3272 gen_qemu_st64(ctx
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3274 tcg_gen_movi_tl(cpu_reserve
, -1);
3277 #endif /* defined(TARGET_PPC64) */
3280 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
)
3285 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
)
3287 TCGv_i32 t0
= tcg_temp_new_i32();
3288 tcg_gen_st_i32(t0
, cpu_env
, offsetof(CPUState
, halted
));
3289 tcg_temp_free_i32(t0
);
3290 /* Stop translation, as the CPU is supposed to sleep from now */
3291 gen_exception_err(ctx
, EXCP_HLT
, 1);
3294 /*** Floating-point load ***/
3295 #define GEN_LDF(name, ldop, opc, type) \
3296 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type) \
3299 if (unlikely(!ctx->fpu_enabled)) { \
3300 gen_exception(ctx, POWERPC_EXCP_FPU); \
3303 gen_set_access_type(ctx, ACCESS_FLOAT); \
3304 EA = tcg_temp_new(); \
3305 gen_addr_imm_index(ctx, EA, 0); \
3306 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3307 tcg_temp_free(EA); \
3310 #define GEN_LDUF(name, ldop, opc, type) \
3311 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type) \
3314 if (unlikely(!ctx->fpu_enabled)) { \
3315 gen_exception(ctx, POWERPC_EXCP_FPU); \
3318 if (unlikely(rA(ctx->opcode) == 0)) { \
3319 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3322 gen_set_access_type(ctx, ACCESS_FLOAT); \
3323 EA = tcg_temp_new(); \
3324 gen_addr_imm_index(ctx, EA, 0); \
3325 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3326 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3327 tcg_temp_free(EA); \
3330 #define GEN_LDUXF(name, ldop, opc, type) \
3331 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type) \
3334 if (unlikely(!ctx->fpu_enabled)) { \
3335 gen_exception(ctx, POWERPC_EXCP_FPU); \
3338 if (unlikely(rA(ctx->opcode) == 0)) { \
3339 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3342 gen_set_access_type(ctx, ACCESS_FLOAT); \
3343 EA = tcg_temp_new(); \
3344 gen_addr_reg_index(ctx, EA); \
3345 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3346 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3347 tcg_temp_free(EA); \
3350 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
3351 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type) \
3354 if (unlikely(!ctx->fpu_enabled)) { \
3355 gen_exception(ctx, POWERPC_EXCP_FPU); \
3358 gen_set_access_type(ctx, ACCESS_FLOAT); \
3359 EA = tcg_temp_new(); \
3360 gen_addr_reg_index(ctx, EA); \
3361 gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \
3362 tcg_temp_free(EA); \
3365 #define GEN_LDFS(name, ldop, op, type) \
3366 GEN_LDF(name, ldop, op | 0x20, type); \
3367 GEN_LDUF(name, ldop, op | 0x21, type); \
3368 GEN_LDUXF(name, ldop, op | 0x01, type); \
3369 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3371 static always_inline
void gen_qemu_ld32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3373 TCGv t0
= tcg_temp_new();
3374 TCGv_i32 t1
= tcg_temp_new_i32();
3375 gen_qemu_ld32u(ctx
, t0
, arg2
);
3376 tcg_gen_trunc_tl_i32(t1
, t0
);
3378 gen_helper_float32_to_float64(arg1
, t1
);
3379 tcg_temp_free_i32(t1
);
3382 /* lfd lfdu lfdux lfdx */
3383 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
);
3384 /* lfs lfsu lfsux lfsx */
3385 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
);
3387 /*** Floating-point store ***/
3388 #define GEN_STF(name, stop, opc, type) \
3389 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type) \
3392 if (unlikely(!ctx->fpu_enabled)) { \
3393 gen_exception(ctx, POWERPC_EXCP_FPU); \
3396 gen_set_access_type(ctx, ACCESS_FLOAT); \
3397 EA = tcg_temp_new(); \
3398 gen_addr_imm_index(ctx, EA, 0); \
3399 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3400 tcg_temp_free(EA); \
3403 #define GEN_STUF(name, stop, opc, type) \
3404 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type) \
3407 if (unlikely(!ctx->fpu_enabled)) { \
3408 gen_exception(ctx, POWERPC_EXCP_FPU); \
3411 if (unlikely(rA(ctx->opcode) == 0)) { \
3412 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3415 gen_set_access_type(ctx, ACCESS_FLOAT); \
3416 EA = tcg_temp_new(); \
3417 gen_addr_imm_index(ctx, EA, 0); \
3418 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3419 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3420 tcg_temp_free(EA); \
3423 #define GEN_STUXF(name, stop, opc, type) \
3424 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type) \
3427 if (unlikely(!ctx->fpu_enabled)) { \
3428 gen_exception(ctx, POWERPC_EXCP_FPU); \
3431 if (unlikely(rA(ctx->opcode) == 0)) { \
3432 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3435 gen_set_access_type(ctx, ACCESS_FLOAT); \
3436 EA = tcg_temp_new(); \
3437 gen_addr_reg_index(ctx, EA); \
3438 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3439 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3440 tcg_temp_free(EA); \
3443 #define GEN_STXF(name, stop, opc2, opc3, type) \
3444 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type) \
3447 if (unlikely(!ctx->fpu_enabled)) { \
3448 gen_exception(ctx, POWERPC_EXCP_FPU); \
3451 gen_set_access_type(ctx, ACCESS_FLOAT); \
3452 EA = tcg_temp_new(); \
3453 gen_addr_reg_index(ctx, EA); \
3454 gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \
3455 tcg_temp_free(EA); \
3458 #define GEN_STFS(name, stop, op, type) \
3459 GEN_STF(name, stop, op | 0x20, type); \
3460 GEN_STUF(name, stop, op | 0x21, type); \
3461 GEN_STUXF(name, stop, op | 0x01, type); \
3462 GEN_STXF(name, stop, 0x17, op | 0x00, type)
3464 static always_inline
void gen_qemu_st32fs(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3466 TCGv_i32 t0
= tcg_temp_new_i32();
3467 TCGv t1
= tcg_temp_new();
3468 gen_helper_float64_to_float32(t0
, arg1
);
3469 tcg_gen_extu_i32_tl(t1
, t0
);
3470 tcg_temp_free_i32(t0
);
3471 gen_qemu_st32(ctx
, t1
, arg2
);
3475 /* stfd stfdu stfdux stfdx */
3476 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
);
3477 /* stfs stfsu stfsux stfsx */
3478 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
);
3481 static always_inline
void gen_qemu_st32fiw(DisasContext
*ctx
, TCGv_i64 arg1
, TCGv arg2
)
3483 TCGv t0
= tcg_temp_new();
3484 tcg_gen_trunc_i64_tl(t0
, arg1
),
3485 gen_qemu_st32(ctx
, t0
, arg2
);
3489 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
);
3492 static always_inline
void gen_goto_tb (DisasContext
*ctx
, int n
,
3495 TranslationBlock
*tb
;
3497 #if defined(TARGET_PPC64)
3499 dest
= (uint32_t) dest
;
3501 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
3502 likely(!ctx
->singlestep_enabled
)) {
3504 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3505 tcg_gen_exit_tb((long)tb
+ n
);
3507 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3508 if (unlikely(ctx
->singlestep_enabled
)) {
3509 if ((ctx
->singlestep_enabled
&
3510 (CPU_BRANCH_STEP
| CPU_SINGLE_STEP
)) &&
3511 ctx
->exception
== POWERPC_EXCP_BRANCH
) {
3512 target_ulong tmp
= ctx
->nip
;
3514 gen_exception(ctx
, POWERPC_EXCP_TRACE
);
3517 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
3518 gen_debug_exception(ctx
);
3525 static always_inline
void gen_setlr (DisasContext
*ctx
, target_ulong nip
)
3527 #if defined(TARGET_PPC64)
3528 if (ctx
->sf_mode
== 0)
3529 tcg_gen_movi_tl(cpu_lr
, (uint32_t)nip
);
3532 tcg_gen_movi_tl(cpu_lr
, nip
);
3536 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
3538 target_ulong li
, target
;
3540 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3541 /* sign extend LI */
3542 #if defined(TARGET_PPC64)
3544 li
= ((int64_t)LI(ctx
->opcode
) << 38) >> 38;
3547 li
= ((int32_t)LI(ctx
->opcode
) << 6) >> 6;
3548 if (likely(AA(ctx
->opcode
) == 0))
3549 target
= ctx
->nip
+ li
- 4;
3552 if (LK(ctx
->opcode
))
3553 gen_setlr(ctx
, ctx
->nip
);
3554 gen_goto_tb(ctx
, 0, target
);
3561 static always_inline
void gen_bcond (DisasContext
*ctx
, int type
)
3563 uint32_t bo
= BO(ctx
->opcode
);
3564 int l1
= gen_new_label();
3567 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3568 if (type
== BCOND_LR
|| type
== BCOND_CTR
) {
3569 target
= tcg_temp_local_new();
3570 if (type
== BCOND_CTR
)
3571 tcg_gen_mov_tl(target
, cpu_ctr
);
3573 tcg_gen_mov_tl(target
, cpu_lr
);
3575 if (LK(ctx
->opcode
))
3576 gen_setlr(ctx
, ctx
->nip
);
3577 l1
= gen_new_label();
3578 if ((bo
& 0x4) == 0) {
3579 /* Decrement and test CTR */
3580 TCGv temp
= tcg_temp_new();
3581 if (unlikely(type
== BCOND_CTR
)) {
3582 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3585 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
3586 #if defined(TARGET_PPC64)
3588 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
3591 tcg_gen_mov_tl(temp
, cpu_ctr
);
3593 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
3595 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
3597 tcg_temp_free(temp
);
3599 if ((bo
& 0x10) == 0) {
3601 uint32_t bi
= BI(ctx
->opcode
);
3602 uint32_t mask
= 1 << (3 - (bi
& 0x03));
3603 TCGv_i32 temp
= tcg_temp_new_i32();
3606 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3607 tcg_gen_brcondi_i32(TCG_COND_EQ
, temp
, 0, l1
);
3609 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3610 tcg_gen_brcondi_i32(TCG_COND_NE
, temp
, 0, l1
);
3612 tcg_temp_free_i32(temp
);
3614 if (type
== BCOND_IM
) {
3615 target_ulong li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
3616 if (likely(AA(ctx
->opcode
) == 0)) {
3617 gen_goto_tb(ctx
, 0, ctx
->nip
+ li
- 4);
3619 gen_goto_tb(ctx
, 0, li
);
3622 gen_goto_tb(ctx
, 1, ctx
->nip
);
3624 #if defined(TARGET_PPC64)
3625 if (!(ctx
->sf_mode
))
3626 tcg_gen_andi_tl(cpu_nip
, target
, (uint32_t)~3);
3629 tcg_gen_andi_tl(cpu_nip
, target
, ~3);
3632 #if defined(TARGET_PPC64)
3633 if (!(ctx
->sf_mode
))
3634 tcg_gen_movi_tl(cpu_nip
, (uint32_t)ctx
->nip
);
3637 tcg_gen_movi_tl(cpu_nip
, ctx
->nip
);
3642 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
3644 gen_bcond(ctx
, BCOND_IM
);
3647 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
)
3649 gen_bcond(ctx
, BCOND_CTR
);
3652 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
)
3654 gen_bcond(ctx
, BCOND_LR
);
3657 /*** Condition register logical ***/
3658 #define GEN_CRLOGIC(name, tcg_op, opc) \
3659 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) \
3664 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3665 t0 = tcg_temp_new_i32(); \
3667 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
3669 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
3671 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
3672 t1 = tcg_temp_new_i32(); \
3673 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3675 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
3677 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
3679 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3680 tcg_op(t0, t0, t1); \
3681 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
3682 tcg_gen_andi_i32(t0, t0, bitmask); \
3683 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3684 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
3685 tcg_temp_free_i32(t0); \
3686 tcg_temp_free_i32(t1); \
3690 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08);
3692 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04);
3694 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09);
3696 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07);
3698 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01);
3700 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E);
3702 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D);
3704 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06);
3706 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
)
3708 tcg_gen_mov_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfS(ctx
->opcode
)]);
3711 /*** System linkage ***/
3712 /* rfi (mem_idx only) */
3713 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
)
3715 #if defined(CONFIG_USER_ONLY)
3716 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3718 /* Restore CPU state */
3719 if (unlikely(!ctx
->mem_idx
)) {
3720 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3724 gen_sync_exception(ctx
);
3728 #if defined(TARGET_PPC64)
3729 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
)
3731 #if defined(CONFIG_USER_ONLY)
3732 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3734 /* Restore CPU state */
3735 if (unlikely(!ctx
->mem_idx
)) {
3736 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3740 gen_sync_exception(ctx
);
3744 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
)
3746 #if defined(CONFIG_USER_ONLY)
3747 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3749 /* Restore CPU state */
3750 if (unlikely(ctx
->mem_idx
<= 1)) {
3751 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3755 gen_sync_exception(ctx
);
3761 #if defined(CONFIG_USER_ONLY)
3762 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3764 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3766 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW
)
3770 lev
= (ctx
->opcode
>> 5) & 0x7F;
3771 gen_exception_err(ctx
, POWERPC_SYSCALL
, lev
);
3776 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
)
3778 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3779 /* Update the nip since this might generate a trap exception */
3780 gen_update_nip(ctx
, ctx
->nip
);
3781 gen_helper_tw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
3782 tcg_temp_free_i32(t0
);
3786 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
3788 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3789 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
3790 /* Update the nip since this might generate a trap exception */
3791 gen_update_nip(ctx
, ctx
->nip
);
3792 gen_helper_tw(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3794 tcg_temp_free_i32(t1
);
3797 #if defined(TARGET_PPC64)
3799 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
)
3801 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3802 /* Update the nip since this might generate a trap exception */
3803 gen_update_nip(ctx
, ctx
->nip
);
3804 gen_helper_td(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
3805 tcg_temp_free_i32(t0
);
3809 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
)
3811 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3812 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
3813 /* Update the nip since this might generate a trap exception */
3814 gen_update_nip(ctx
, ctx
->nip
);
3815 gen_helper_td(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3817 tcg_temp_free_i32(t1
);
3821 /*** Processor control ***/
3823 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
)
3825 tcg_gen_trunc_tl_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_xer
);
3826 tcg_gen_shri_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfD(ctx
->opcode
)], XER_CA
);
3827 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_SO
| 1 << XER_OV
| 1 << XER_CA
));
3831 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
)
3835 if (likely(ctx
->opcode
& 0x00100000)) {
3836 crm
= CRM(ctx
->opcode
);
3837 if (likely((crm
^ (crm
- 1)) == 0)) {
3839 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_crf
[7 - crn
]);
3842 gen_helper_load_cr(cpu_gpr
[rD(ctx
->opcode
)]);
3847 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
)
3849 #if defined(CONFIG_USER_ONLY)
3850 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3852 if (unlikely(!ctx
->mem_idx
)) {
3853 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3856 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_msr
);
3861 #define SPR_NOACCESS ((void *)(-1UL))
3863 static void spr_noaccess (void *opaque
, int sprn
)
3865 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
3866 printf("ERROR: try to access SPR %d !\n", sprn
);
3868 #define SPR_NOACCESS (&spr_noaccess)
3872 static always_inline
void gen_op_mfspr (DisasContext
*ctx
)
3874 void (*read_cb
)(void *opaque
, int gprn
, int sprn
);
3875 uint32_t sprn
= SPR(ctx
->opcode
);
3877 #if !defined(CONFIG_USER_ONLY)
3878 if (ctx
->mem_idx
== 2)
3879 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
3880 else if (ctx
->mem_idx
)
3881 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
3884 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
3885 if (likely(read_cb
!= NULL
)) {
3886 if (likely(read_cb
!= SPR_NOACCESS
)) {
3887 (*read_cb
)(ctx
, rD(ctx
->opcode
), sprn
);
3889 /* Privilege exception */
3890 /* This is a hack to avoid warnings when running Linux:
3891 * this OS breaks the PowerPC virtualisation model,
3892 * allowing userland application to read the PVR
3894 if (sprn
!= SPR_PVR
) {
3895 if (loglevel
!= 0) {
3896 fprintf(logfile
, "Trying to read privileged spr %d %03x at "
3897 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3899 printf("Trying to read privileged spr %d %03x at " ADDRX
"\n",
3900 sprn
, sprn
, ctx
->nip
);
3902 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3906 if (loglevel
!= 0) {
3907 fprintf(logfile
, "Trying to read invalid spr %d %03x at "
3908 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3910 printf("Trying to read invalid spr %d %03x at " ADDRX
"\n",
3911 sprn
, sprn
, ctx
->nip
);
3912 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
3916 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
)
3922 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
)
3928 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
)
3932 crm
= CRM(ctx
->opcode
);
3933 if (likely((ctx
->opcode
& 0x00100000) || (crm
^ (crm
- 1)) == 0)) {
3934 TCGv_i32 temp
= tcg_temp_new_i32();
3936 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
3937 tcg_gen_shri_i32(cpu_crf
[7 - crn
], temp
, crn
* 4);
3938 tcg_gen_andi_i32(cpu_crf
[7 - crn
], cpu_crf
[7 - crn
], 0xf);
3939 tcg_temp_free_i32(temp
);
3941 TCGv_i32 temp
= tcg_const_i32(crm
);
3942 gen_helper_store_cr(cpu_gpr
[rS(ctx
->opcode
)], temp
);
3943 tcg_temp_free_i32(temp
);
3948 #if defined(TARGET_PPC64)
3949 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
)
3951 #if defined(CONFIG_USER_ONLY)
3952 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3954 if (unlikely(!ctx
->mem_idx
)) {
3955 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3958 if (ctx
->opcode
& 0x00010000) {
3959 /* Special form that does not need any synchronisation */
3960 TCGv t0
= tcg_temp_new();
3961 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
3962 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
3963 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
3966 /* XXX: we need to update nip before the store
3967 * if we enter power saving mode, we will exit the loop
3968 * directly from ppc_store_msr
3970 gen_update_nip(ctx
, ctx
->nip
);
3971 gen_helper_store_msr(cpu_gpr
[rS(ctx
->opcode
)]);
3972 /* Must stop the translation as machine state (may have) changed */
3973 /* Note that mtmsr is not always defined as context-synchronizing */
3974 gen_stop_exception(ctx
);
3980 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC
)
3982 #if defined(CONFIG_USER_ONLY)
3983 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3985 if (unlikely(!ctx
->mem_idx
)) {
3986 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
3989 if (ctx
->opcode
& 0x00010000) {
3990 /* Special form that does not need any synchronisation */
3991 TCGv t0
= tcg_temp_new();
3992 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1 << MSR_RI
) | (1 << MSR_EE
));
3993 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~((1 << MSR_RI
) | (1 << MSR_EE
)));
3994 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
3997 /* XXX: we need to update nip before the store
3998 * if we enter power saving mode, we will exit the loop
3999 * directly from ppc_store_msr
4001 gen_update_nip(ctx
, ctx
->nip
);
4002 #if defined(TARGET_PPC64)
4003 if (!ctx
->sf_mode
) {
4004 TCGv t0
= tcg_temp_new();
4005 TCGv t1
= tcg_temp_new();
4006 tcg_gen_andi_tl(t0
, cpu_msr
, 0xFFFFFFFF00000000ULL
);
4007 tcg_gen_ext32u_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
4008 tcg_gen_or_tl(t0
, t0
, t1
);
4010 gen_helper_store_msr(t0
);
4014 gen_helper_store_msr(cpu_gpr
[rS(ctx
->opcode
)]);
4015 /* Must stop the translation as machine state (may have) changed */
4016 /* Note that mtmsr is not always defined as context-synchronizing */
4017 gen_stop_exception(ctx
);
4023 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC
)
4025 void (*write_cb
)(void *opaque
, int sprn
, int gprn
);
4026 uint32_t sprn
= SPR(ctx
->opcode
);
4028 #if !defined(CONFIG_USER_ONLY)
4029 if (ctx
->mem_idx
== 2)
4030 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
4031 else if (ctx
->mem_idx
)
4032 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
4035 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
4036 if (likely(write_cb
!= NULL
)) {
4037 if (likely(write_cb
!= SPR_NOACCESS
)) {
4038 (*write_cb
)(ctx
, sprn
, rS(ctx
->opcode
));
4040 /* Privilege exception */
4041 if (loglevel
!= 0) {
4042 fprintf(logfile
, "Trying to write privileged spr %d %03x at "
4043 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
4045 printf("Trying to write privileged spr %d %03x at " ADDRX
"\n",
4046 sprn
, sprn
, ctx
->nip
);
4047 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4051 if (loglevel
!= 0) {
4052 fprintf(logfile
, "Trying to write invalid spr %d %03x at "
4053 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
4055 printf("Trying to write invalid spr %d %03x at " ADDRX
"\n",
4056 sprn
, sprn
, ctx
->nip
);
4057 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4061 /*** Cache management ***/
4063 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
)
4065 /* XXX: specification says this is treated as a load by the MMU */
4067 gen_set_access_type(ctx
, ACCESS_CACHE
);
4068 t0
= tcg_temp_new();
4069 gen_addr_reg_index(ctx
, t0
);
4070 gen_qemu_ld8u(ctx
, t0
, t0
);
4074 /* dcbi (Supervisor only) */
4075 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
)
4077 #if defined(CONFIG_USER_ONLY)
4078 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4081 if (unlikely(!ctx
->mem_idx
)) {
4082 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4085 EA
= tcg_temp_new();
4086 gen_set_access_type(ctx
, ACCESS_CACHE
);
4087 gen_addr_reg_index(ctx
, EA
);
4088 val
= tcg_temp_new();
4089 /* XXX: specification says this should be treated as a store by the MMU */
4090 gen_qemu_ld8u(ctx
, val
, EA
);
4091 gen_qemu_st8(ctx
, val
, EA
);
4098 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
)
4100 /* XXX: specification say this is treated as a load by the MMU */
4102 gen_set_access_type(ctx
, ACCESS_CACHE
);
4103 t0
= tcg_temp_new();
4104 gen_addr_reg_index(ctx
, t0
);
4105 gen_qemu_ld8u(ctx
, t0
, t0
);
4110 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE
)
4112 /* interpreted as no-op */
4113 /* XXX: specification say this is treated as a load by the MMU
4114 * but does not generate any exception
4119 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE
)
4121 /* interpreted as no-op */
4122 /* XXX: specification say this is treated as a load by the MMU
4123 * but does not generate any exception
4128 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE_DCBZ
)
4131 gen_set_access_type(ctx
, ACCESS_CACHE
);
4132 /* NIP cannot be restored if the memory exception comes from an helper */
4133 gen_update_nip(ctx
, ctx
->nip
- 4);
4134 t0
= tcg_temp_new();
4135 gen_addr_reg_index(ctx
, t0
);
4136 gen_helper_dcbz(t0
);
4140 GEN_HANDLER2(dcbz_970
, "dcbz", 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZT
)
4143 gen_set_access_type(ctx
, ACCESS_CACHE
);
4144 /* NIP cannot be restored if the memory exception comes from an helper */
4145 gen_update_nip(ctx
, ctx
->nip
- 4);
4146 t0
= tcg_temp_new();
4147 gen_addr_reg_index(ctx
, t0
);
4148 if (ctx
->opcode
& 0x00200000)
4149 gen_helper_dcbz(t0
);
4151 gen_helper_dcbz_970(t0
);
4156 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
)
4159 gen_set_access_type(ctx
, ACCESS_CACHE
);
4160 /* NIP cannot be restored if the memory exception comes from an helper */
4161 gen_update_nip(ctx
, ctx
->nip
- 4);
4162 t0
= tcg_temp_new();
4163 gen_addr_reg_index(ctx
, t0
);
4164 gen_helper_icbi(t0
);
4170 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
)
4172 /* interpreted as no-op */
4173 /* XXX: specification say this is treated as a store by the MMU
4174 * but does not generate any exception
4178 /*** Segment register manipulation ***/
4179 /* Supervisor only: */
4181 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
)
4183 #if defined(CONFIG_USER_ONLY)
4184 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4187 if (unlikely(!ctx
->mem_idx
)) {
4188 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4191 t0
= tcg_const_tl(SR(ctx
->opcode
));
4192 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4198 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
)
4200 #if defined(CONFIG_USER_ONLY)
4201 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4204 if (unlikely(!ctx
->mem_idx
)) {
4205 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4208 t0
= tcg_temp_new();
4209 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4210 tcg_gen_andi_tl(t0
, t0
, 0xF);
4211 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4217 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
)
4219 #if defined(CONFIG_USER_ONLY)
4220 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4223 if (unlikely(!ctx
->mem_idx
)) {
4224 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4227 t0
= tcg_const_tl(SR(ctx
->opcode
));
4228 gen_helper_store_sr(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4234 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
)
4236 #if defined(CONFIG_USER_ONLY)
4237 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4240 if (unlikely(!ctx
->mem_idx
)) {
4241 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4244 t0
= tcg_temp_new();
4245 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4246 tcg_gen_andi_tl(t0
, t0
, 0xF);
4247 gen_helper_store_sr(t0
, cpu_gpr
[rD(ctx
->opcode
)]);
4252 #if defined(TARGET_PPC64)
4253 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4255 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
)
4257 #if defined(CONFIG_USER_ONLY)
4258 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4261 if (unlikely(!ctx
->mem_idx
)) {
4262 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4265 t0
= tcg_const_tl(SR(ctx
->opcode
));
4266 gen_helper_load_slb(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4272 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
4275 #if defined(CONFIG_USER_ONLY)
4276 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4279 if (unlikely(!ctx
->mem_idx
)) {
4280 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4283 t0
= tcg_temp_new();
4284 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4285 tcg_gen_andi_tl(t0
, t0
, 0xF);
4286 gen_helper_load_slb(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4292 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
)
4294 #if defined(CONFIG_USER_ONLY)
4295 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4298 if (unlikely(!ctx
->mem_idx
)) {
4299 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4302 t0
= tcg_const_tl(SR(ctx
->opcode
));
4303 gen_helper_store_slb(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4309 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
4312 #if defined(CONFIG_USER_ONLY)
4313 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4316 if (unlikely(!ctx
->mem_idx
)) {
4317 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4320 t0
= tcg_temp_new();
4321 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28);
4322 tcg_gen_andi_tl(t0
, t0
, 0xF);
4323 gen_helper_store_slb(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
4327 #endif /* defined(TARGET_PPC64) */
4329 /*** Lookaside buffer management ***/
4330 /* Optional & mem_idx only: */
4332 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
)
4334 #if defined(CONFIG_USER_ONLY)
4335 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4337 if (unlikely(!ctx
->mem_idx
)) {
4338 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4346 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE
)
4348 #if defined(CONFIG_USER_ONLY)
4349 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4351 if (unlikely(!ctx
->mem_idx
)) {
4352 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4355 #if defined(TARGET_PPC64)
4356 if (!ctx
->sf_mode
) {
4357 TCGv t0
= tcg_temp_new();
4358 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
4359 gen_helper_tlbie(t0
);
4363 gen_helper_tlbie(cpu_gpr
[rB(ctx
->opcode
)]);
4368 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
)
4370 #if defined(CONFIG_USER_ONLY)
4371 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4373 if (unlikely(!ctx
->mem_idx
)) {
4374 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4377 /* This has no effect: it should ensure that all previous
4378 * tlbie have completed
4380 gen_stop_exception(ctx
);
4384 #if defined(TARGET_PPC64)
4386 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI
)
4388 #if defined(CONFIG_USER_ONLY)
4389 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4391 if (unlikely(!ctx
->mem_idx
)) {
4392 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4400 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
)
4402 #if defined(CONFIG_USER_ONLY)
4403 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4405 if (unlikely(!ctx
->mem_idx
)) {
4406 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
4409 gen_helper_slbie(cpu_gpr
[rB(ctx
->opcode
)]);
4414 /*** External control ***/
4417 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
)
4420 /* Should check EAR[E] ! */
4421 gen_set_access_type(ctx
, ACCESS_EXT
);
4422 t0
= tcg_temp_new();
4423 gen_addr_reg_index(ctx
, t0
);
4424 gen_check_align(ctx
, t0
, 0x03);
4425 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4430 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
)
4433 /* Should check EAR[E] ! */
4434 gen_set_access_type(ctx
, ACCESS_EXT
);
4435 t0
= tcg_temp_new();
4436 gen_addr_reg_index(ctx
, t0
);
4437 gen_check_align(ctx
, t0
, 0x03);
4438 gen_qemu_st32(ctx
, cpu_gpr
[rD(ctx
->opcode
)], t0
);
4442 /* PowerPC 601 specific instructions */
4444 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
)
4446 int l1
= gen_new_label();
4447 int l2
= gen_new_label();
4448 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4449 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4452 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4454 if (unlikely(Rc(ctx
->opcode
) != 0))
4455 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4459 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
)
4461 int l1
= gen_new_label();
4462 int l2
= gen_new_label();
4463 int l3
= gen_new_label();
4464 /* Start with XER OV disabled, the most likely case */
4465 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
4466 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rA(ctx
->opcode
)], 0, l2
);
4467 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_gpr
[rA(ctx
->opcode
)], 0x80000000, l1
);
4468 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
4471 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4474 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4476 if (unlikely(Rc(ctx
->opcode
) != 0))
4477 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4481 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
)
4483 TCGv_i32 t0
= tcg_const_i32(rA(ctx
->opcode
));
4484 gen_helper_clcs(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4485 tcg_temp_free_i32(t0
);
4486 /* Rc=1 sets CR0 to an undefined state */
4490 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
)
4492 gen_helper_div(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4493 if (unlikely(Rc(ctx
->opcode
) != 0))
4494 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4498 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
)
4500 gen_helper_divo(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4501 if (unlikely(Rc(ctx
->opcode
) != 0))
4502 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4506 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
)
4508 gen_helper_divs(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4509 if (unlikely(Rc(ctx
->opcode
) != 0))
4510 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4513 /* divso - divso. */
4514 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
)
4516 gen_helper_divso(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4517 if (unlikely(Rc(ctx
->opcode
) != 0))
4518 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4522 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
)
4524 int l1
= gen_new_label();
4525 int l2
= gen_new_label();
4526 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4527 tcg_gen_sub_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4530 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4532 if (unlikely(Rc(ctx
->opcode
) != 0))
4533 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4537 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
)
4539 int l1
= gen_new_label();
4540 int l2
= gen_new_label();
4541 TCGv t0
= tcg_temp_new();
4542 TCGv t1
= tcg_temp_new();
4543 TCGv t2
= tcg_temp_new();
4544 /* Start with XER OV disabled, the most likely case */
4545 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
4546 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], l1
);
4547 tcg_gen_sub_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4548 tcg_gen_xor_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4549 tcg_gen_xor_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], t0
);
4550 tcg_gen_andc_tl(t1
, t1
, t2
);
4551 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4552 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
4553 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
4556 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4561 if (unlikely(Rc(ctx
->opcode
) != 0))
4562 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4566 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
)
4568 target_long simm
= SIMM(ctx
->opcode
);
4569 int l1
= gen_new_label();
4570 int l2
= gen_new_label();
4571 tcg_gen_brcondi_tl(TCG_COND_LT
, cpu_gpr
[rA(ctx
->opcode
)], simm
, l1
);
4572 tcg_gen_subfi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
, cpu_gpr
[rA(ctx
->opcode
)]);
4575 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
4577 if (unlikely(Rc(ctx
->opcode
) != 0))
4578 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4581 /* lscbx - lscbx. */
4582 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
)
4584 TCGv t0
= tcg_temp_new();
4585 TCGv_i32 t1
= tcg_const_i32(rD(ctx
->opcode
));
4586 TCGv_i32 t2
= tcg_const_i32(rA(ctx
->opcode
));
4587 TCGv_i32 t3
= tcg_const_i32(rB(ctx
->opcode
));
4589 gen_addr_reg_index(ctx
, t0
);
4590 /* NIP cannot be restored if the memory exception comes from an helper */
4591 gen_update_nip(ctx
, ctx
->nip
- 4);
4592 gen_helper_lscbx(t0
, t0
, t1
, t2
, t3
);
4593 tcg_temp_free_i32(t1
);
4594 tcg_temp_free_i32(t2
);
4595 tcg_temp_free_i32(t3
);
4596 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~0x7F);
4597 tcg_gen_or_tl(cpu_xer
, cpu_xer
, t0
);
4598 if (unlikely(Rc(ctx
->opcode
) != 0))
4599 gen_set_Rc0(ctx
, t0
);
4603 /* maskg - maskg. */
4604 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
)
4606 int l1
= gen_new_label();
4607 TCGv t0
= tcg_temp_new();
4608 TCGv t1
= tcg_temp_new();
4609 TCGv t2
= tcg_temp_new();
4610 TCGv t3
= tcg_temp_new();
4611 tcg_gen_movi_tl(t3
, 0xFFFFFFFF);
4612 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4613 tcg_gen_andi_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 0x1F);
4614 tcg_gen_addi_tl(t2
, t0
, 1);
4615 tcg_gen_shr_tl(t2
, t3
, t2
);
4616 tcg_gen_shr_tl(t3
, t3
, t1
);
4617 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], t2
, t3
);
4618 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
4619 tcg_gen_neg_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4625 if (unlikely(Rc(ctx
->opcode
) != 0))
4626 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4629 /* maskir - maskir. */
4630 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
)
4632 TCGv t0
= tcg_temp_new();
4633 TCGv t1
= tcg_temp_new();
4634 tcg_gen_and_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4635 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
4636 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4639 if (unlikely(Rc(ctx
->opcode
) != 0))
4640 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4644 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
)
4646 TCGv_i64 t0
= tcg_temp_new_i64();
4647 TCGv_i64 t1
= tcg_temp_new_i64();
4648 TCGv t2
= tcg_temp_new();
4649 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4650 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4651 tcg_gen_mul_i64(t0
, t0
, t1
);
4652 tcg_gen_trunc_i64_tl(t2
, t0
);
4653 gen_store_spr(SPR_MQ
, t2
);
4654 tcg_gen_shri_i64(t1
, t0
, 32);
4655 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4656 tcg_temp_free_i64(t0
);
4657 tcg_temp_free_i64(t1
);
4659 if (unlikely(Rc(ctx
->opcode
) != 0))
4660 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4664 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
)
4666 int l1
= gen_new_label();
4667 TCGv_i64 t0
= tcg_temp_new_i64();
4668 TCGv_i64 t1
= tcg_temp_new_i64();
4669 TCGv t2
= tcg_temp_new();
4670 /* Start with XER OV disabled, the most likely case */
4671 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
4672 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
4673 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
4674 tcg_gen_mul_i64(t0
, t0
, t1
);
4675 tcg_gen_trunc_i64_tl(t2
, t0
);
4676 gen_store_spr(SPR_MQ
, t2
);
4677 tcg_gen_shri_i64(t1
, t0
, 32);
4678 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
4679 tcg_gen_ext32s_i64(t1
, t0
);
4680 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
4681 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
4683 tcg_temp_free_i64(t0
);
4684 tcg_temp_free_i64(t1
);
4686 if (unlikely(Rc(ctx
->opcode
) != 0))
4687 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4691 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
)
4693 int l1
= gen_new_label();
4694 int l2
= gen_new_label();
4695 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4696 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4699 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4701 if (unlikely(Rc(ctx
->opcode
) != 0))
4702 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4705 /* nabso - nabso. */
4706 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
)
4708 int l1
= gen_new_label();
4709 int l2
= gen_new_label();
4710 tcg_gen_brcondi_tl(TCG_COND_GT
, cpu_gpr
[rA(ctx
->opcode
)], 0, l1
);
4711 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4714 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4716 /* nabs never overflows */
4717 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
4718 if (unlikely(Rc(ctx
->opcode
) != 0))
4719 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
4723 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
)
4725 uint32_t mb
= MB(ctx
->opcode
);
4726 uint32_t me
= ME(ctx
->opcode
);
4727 TCGv t0
= tcg_temp_new();
4728 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4729 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4730 tcg_gen_andi_tl(t0
, t0
, MASK(mb
, me
));
4731 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~MASK(mb
, me
));
4732 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], t0
);
4734 if (unlikely(Rc(ctx
->opcode
) != 0))
4735 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4739 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
)
4741 TCGv t0
= tcg_temp_new();
4742 TCGv t1
= tcg_temp_new();
4743 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4744 tcg_gen_movi_tl(t1
, 0x80000000);
4745 tcg_gen_shr_tl(t1
, t1
, t0
);
4746 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4747 tcg_gen_and_tl(t0
, t0
, t1
);
4748 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], t1
);
4749 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4752 if (unlikely(Rc(ctx
->opcode
) != 0))
4753 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4757 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
)
4759 TCGv t0
= tcg_temp_new();
4760 TCGv t1
= tcg_temp_new();
4761 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4762 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4763 tcg_gen_subfi_tl(t1
, 32, t1
);
4764 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4765 tcg_gen_or_tl(t1
, t0
, t1
);
4766 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4767 gen_store_spr(SPR_MQ
, t1
);
4770 if (unlikely(Rc(ctx
->opcode
) != 0))
4771 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4775 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
)
4777 TCGv t0
= tcg_temp_new();
4778 TCGv t1
= tcg_temp_new();
4779 TCGv t2
= tcg_temp_new();
4780 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4781 tcg_gen_movi_tl(t2
, 0xFFFFFFFF);
4782 tcg_gen_shl_tl(t2
, t2
, t0
);
4783 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4784 gen_load_spr(t1
, SPR_MQ
);
4785 gen_store_spr(SPR_MQ
, t0
);
4786 tcg_gen_and_tl(t0
, t0
, t2
);
4787 tcg_gen_andc_tl(t1
, t1
, t2
);
4788 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4792 if (unlikely(Rc(ctx
->opcode
) != 0))
4793 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4797 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
)
4799 int sh
= SH(ctx
->opcode
);
4800 TCGv t0
= tcg_temp_new();
4801 TCGv t1
= tcg_temp_new();
4802 tcg_gen_shli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4803 tcg_gen_shri_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
4804 tcg_gen_or_tl(t1
, t0
, t1
);
4805 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4806 gen_store_spr(SPR_MQ
, t1
);
4809 if (unlikely(Rc(ctx
->opcode
) != 0))
4810 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4813 /* slliq - slliq. */
4814 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
)
4816 int sh
= SH(ctx
->opcode
);
4817 TCGv t0
= tcg_temp_new();
4818 TCGv t1
= tcg_temp_new();
4819 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4820 gen_load_spr(t1
, SPR_MQ
);
4821 gen_store_spr(SPR_MQ
, t0
);
4822 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
<< sh
));
4823 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
<< sh
));
4824 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4827 if (unlikely(Rc(ctx
->opcode
) != 0))
4828 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4832 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
)
4834 int l1
= gen_new_label();
4835 int l2
= gen_new_label();
4836 TCGv t0
= tcg_temp_local_new();
4837 TCGv t1
= tcg_temp_local_new();
4838 TCGv t2
= tcg_temp_local_new();
4839 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4840 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
4841 tcg_gen_shl_tl(t1
, t1
, t2
);
4842 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4843 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
4844 gen_load_spr(t0
, SPR_MQ
);
4845 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4848 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4849 gen_load_spr(t2
, SPR_MQ
);
4850 tcg_gen_andc_tl(t1
, t2
, t1
);
4851 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4856 if (unlikely(Rc(ctx
->opcode
) != 0))
4857 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4861 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
)
4863 int l1
= gen_new_label();
4864 TCGv t0
= tcg_temp_new();
4865 TCGv t1
= tcg_temp_new();
4866 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4867 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4868 tcg_gen_subfi_tl(t1
, 32, t1
);
4869 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4870 tcg_gen_or_tl(t1
, t0
, t1
);
4871 gen_store_spr(SPR_MQ
, t1
);
4872 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4873 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4874 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
4875 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
4879 if (unlikely(Rc(ctx
->opcode
) != 0))
4880 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4883 /* sraiq - sraiq. */
4884 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
)
4886 int sh
= SH(ctx
->opcode
);
4887 int l1
= gen_new_label();
4888 TCGv t0
= tcg_temp_new();
4889 TCGv t1
= tcg_temp_new();
4890 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
4891 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
4892 tcg_gen_or_tl(t0
, t0
, t1
);
4893 gen_store_spr(SPR_MQ
, t0
);
4894 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
4895 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
4896 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
4897 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_CA
));
4899 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
4902 if (unlikely(Rc(ctx
->opcode
) != 0))
4903 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4907 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
)
4909 int l1
= gen_new_label();
4910 int l2
= gen_new_label();
4911 TCGv t0
= tcg_temp_new();
4912 TCGv t1
= tcg_temp_local_new();
4913 TCGv t2
= tcg_temp_local_new();
4914 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4915 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4916 tcg_gen_sar_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4917 tcg_gen_subfi_tl(t2
, 32, t2
);
4918 tcg_gen_shl_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
4919 tcg_gen_or_tl(t0
, t0
, t2
);
4920 gen_store_spr(SPR_MQ
, t0
);
4921 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
4922 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l1
);
4923 tcg_gen_mov_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
4924 tcg_gen_sari_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 31);
4927 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
);
4928 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
4929 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
4930 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l2
);
4931 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_CA
));
4935 if (unlikely(Rc(ctx
->opcode
) != 0))
4936 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4940 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
)
4942 TCGv t0
= tcg_temp_new();
4943 TCGv t1
= tcg_temp_new();
4944 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4945 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4946 tcg_gen_subfi_tl(t1
, 32, t1
);
4947 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4948 tcg_gen_or_tl(t1
, t0
, t1
);
4949 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
4950 gen_store_spr(SPR_MQ
, t1
);
4953 if (unlikely(Rc(ctx
->opcode
) != 0))
4954 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4958 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
)
4960 TCGv t0
= tcg_temp_new();
4961 TCGv t1
= tcg_temp_new();
4962 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4963 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
4964 gen_store_spr(SPR_MQ
, t0
);
4965 tcg_gen_sar_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t1
);
4968 if (unlikely(Rc(ctx
->opcode
) != 0))
4969 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4973 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
)
4975 TCGv t0
= tcg_temp_new();
4976 TCGv t1
= tcg_temp_new();
4977 TCGv t2
= tcg_temp_new();
4978 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
4979 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
4980 tcg_gen_shr_tl(t1
, t1
, t0
);
4981 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
4982 gen_load_spr(t2
, SPR_MQ
);
4983 gen_store_spr(SPR_MQ
, t0
);
4984 tcg_gen_and_tl(t0
, t0
, t1
);
4985 tcg_gen_andc_tl(t2
, t2
, t1
);
4986 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
4990 if (unlikely(Rc(ctx
->opcode
) != 0))
4991 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
4995 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
)
4997 int sh
= SH(ctx
->opcode
);
4998 TCGv t0
= tcg_temp_new();
4999 TCGv t1
= tcg_temp_new();
5000 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5001 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
5002 tcg_gen_or_tl(t1
, t0
, t1
);
5003 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5004 gen_store_spr(SPR_MQ
, t1
);
5007 if (unlikely(Rc(ctx
->opcode
) != 0))
5008 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5012 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
)
5014 int sh
= SH(ctx
->opcode
);
5015 TCGv t0
= tcg_temp_new();
5016 TCGv t1
= tcg_temp_new();
5017 tcg_gen_rotri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
5018 gen_load_spr(t1
, SPR_MQ
);
5019 gen_store_spr(SPR_MQ
, t0
);
5020 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
>> sh
));
5021 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
>> sh
));
5022 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5025 if (unlikely(Rc(ctx
->opcode
) != 0))
5026 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5030 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
)
5032 int l1
= gen_new_label();
5033 int l2
= gen_new_label();
5034 TCGv t0
= tcg_temp_local_new();
5035 TCGv t1
= tcg_temp_local_new();
5036 TCGv t2
= tcg_temp_local_new();
5037 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5038 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
5039 tcg_gen_shr_tl(t2
, t1
, t2
);
5040 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5041 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5042 gen_load_spr(t0
, SPR_MQ
);
5043 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
5046 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
5047 tcg_gen_and_tl(t0
, t0
, t2
);
5048 gen_load_spr(t1
, SPR_MQ
);
5049 tcg_gen_andc_tl(t1
, t1
, t2
);
5050 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5055 if (unlikely(Rc(ctx
->opcode
) != 0))
5056 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5060 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
)
5062 int l1
= gen_new_label();
5063 TCGv t0
= tcg_temp_new();
5064 TCGv t1
= tcg_temp_new();
5065 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5066 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5067 tcg_gen_subfi_tl(t1
, 32, t1
);
5068 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
5069 tcg_gen_or_tl(t1
, t0
, t1
);
5070 gen_store_spr(SPR_MQ
, t1
);
5071 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
5072 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
5073 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
5074 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
5078 if (unlikely(Rc(ctx
->opcode
) != 0))
5079 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5082 /* PowerPC 602 specific instructions */
5084 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
)
5087 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5091 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
)
5094 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5098 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
)
5100 #if defined(CONFIG_USER_ONLY)
5101 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5103 if (unlikely(!ctx
->mem_idx
)) {
5104 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5107 gen_helper_602_mfrom(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5111 /* 602 - 603 - G2 TLB management */
5113 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
)
5115 #if defined(CONFIG_USER_ONLY)
5116 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5118 if (unlikely(!ctx
->mem_idx
)) {
5119 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5122 gen_helper_6xx_tlbd(cpu_gpr
[rB(ctx
->opcode
)]);
5127 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
)
5129 #if defined(CONFIG_USER_ONLY)
5130 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5132 if (unlikely(!ctx
->mem_idx
)) {
5133 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5136 gen_helper_6xx_tlbi(cpu_gpr
[rB(ctx
->opcode
)]);
5140 /* 74xx TLB management */
5142 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
)
5144 #if defined(CONFIG_USER_ONLY)
5145 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5147 if (unlikely(!ctx
->mem_idx
)) {
5148 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5151 gen_helper_74xx_tlbd(cpu_gpr
[rB(ctx
->opcode
)]);
5156 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
)
5158 #if defined(CONFIG_USER_ONLY)
5159 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5161 if (unlikely(!ctx
->mem_idx
)) {
5162 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5165 gen_helper_74xx_tlbi(cpu_gpr
[rB(ctx
->opcode
)]);
5169 /* POWER instructions not in PowerPC 601 */
5171 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
)
5173 /* Cache line flush: implemented as no-op */
5177 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
)
5179 /* Cache line invalidate: privileged and treated as no-op */
5180 #if defined(CONFIG_USER_ONLY)
5181 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5183 if (unlikely(!ctx
->mem_idx
)) {
5184 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5191 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
)
5193 /* Data cache line store: treated as no-op */
5196 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
)
5198 #if defined(CONFIG_USER_ONLY)
5199 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5201 int ra
= rA(ctx
->opcode
);
5202 int rd
= rD(ctx
->opcode
);
5204 if (unlikely(!ctx
->mem_idx
)) {
5205 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5208 t0
= tcg_temp_new();
5209 gen_addr_reg_index(ctx
, t0
);
5210 tcg_gen_shri_tl(t0
, t0
, 28);
5211 tcg_gen_andi_tl(t0
, t0
, 0xF);
5212 gen_helper_load_sr(cpu_gpr
[rd
], t0
);
5214 if (ra
!= 0 && ra
!= rd
)
5215 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rd
]);
5219 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
)
5221 #if defined(CONFIG_USER_ONLY)
5222 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5225 if (unlikely(!ctx
->mem_idx
)) {
5226 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5229 t0
= tcg_temp_new();
5230 gen_addr_reg_index(ctx
, t0
);
5231 gen_helper_rac(cpu_gpr
[rD(ctx
->opcode
)], t0
);
5236 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
)
5238 #if defined(CONFIG_USER_ONLY)
5239 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5241 if (unlikely(!ctx
->mem_idx
)) {
5242 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5246 gen_sync_exception(ctx
);
5250 /* svc is not implemented for now */
5252 /* POWER2 specific instructions */
5253 /* Quad manipulation (load/store two floats at a time) */
5256 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
5258 int rd
= rD(ctx
->opcode
);
5260 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5261 t0
= tcg_temp_new();
5262 gen_addr_imm_index(ctx
, t0
, 0);
5263 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5264 gen_addr_add(ctx
, t0
, t0
, 8);
5265 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5270 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
5272 int ra
= rA(ctx
->opcode
);
5273 int rd
= rD(ctx
->opcode
);
5275 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5276 t0
= tcg_temp_new();
5277 t1
= tcg_temp_new();
5278 gen_addr_imm_index(ctx
, t0
, 0);
5279 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5280 gen_addr_add(ctx
, t1
, t0
, 8);
5281 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5283 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5289 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
)
5291 int ra
= rA(ctx
->opcode
);
5292 int rd
= rD(ctx
->opcode
);
5293 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5295 t0
= tcg_temp_new();
5296 gen_addr_reg_index(ctx
, t0
);
5297 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5298 t1
= tcg_temp_new();
5299 gen_addr_add(ctx
, t1
, t0
, 8);
5300 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5303 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5308 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
)
5310 int rd
= rD(ctx
->opcode
);
5312 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5313 t0
= tcg_temp_new();
5314 gen_addr_reg_index(ctx
, t0
);
5315 gen_qemu_ld64(ctx
, cpu_fpr
[rd
], t0
);
5316 gen_addr_add(ctx
, t0
, t0
, 8);
5317 gen_qemu_ld64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5322 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
5324 int rd
= rD(ctx
->opcode
);
5326 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5327 t0
= tcg_temp_new();
5328 gen_addr_imm_index(ctx
, t0
, 0);
5329 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5330 gen_addr_add(ctx
, t0
, t0
, 8);
5331 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5336 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
5338 int ra
= rA(ctx
->opcode
);
5339 int rd
= rD(ctx
->opcode
);
5341 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5342 t0
= tcg_temp_new();
5343 gen_addr_imm_index(ctx
, t0
, 0);
5344 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5345 t1
= tcg_temp_new();
5346 gen_addr_add(ctx
, t1
, t0
, 8);
5347 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5350 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5355 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
)
5357 int ra
= rA(ctx
->opcode
);
5358 int rd
= rD(ctx
->opcode
);
5360 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5361 t0
= tcg_temp_new();
5362 gen_addr_reg_index(ctx
, t0
);
5363 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5364 t1
= tcg_temp_new();
5365 gen_addr_add(ctx
, t1
, t0
, 8);
5366 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t1
);
5369 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5374 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
)
5376 int rd
= rD(ctx
->opcode
);
5378 gen_set_access_type(ctx
, ACCESS_FLOAT
);
5379 t0
= tcg_temp_new();
5380 gen_addr_reg_index(ctx
, t0
);
5381 gen_qemu_st64(ctx
, cpu_fpr
[rd
], t0
);
5382 gen_addr_add(ctx
, t0
, t0
, 8);
5383 gen_qemu_st64(ctx
, cpu_fpr
[(rd
+ 1) % 32], t0
);
5387 /* BookE specific instructions */
5388 /* XXX: not implemented on 440 ? */
5389 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
)
5392 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5395 /* XXX: not implemented on 440 ? */
5396 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
)
5398 #if defined(CONFIG_USER_ONLY)
5399 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5402 if (unlikely(!ctx
->mem_idx
)) {
5403 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5406 t0
= tcg_temp_new();
5407 gen_addr_reg_index(ctx
, t0
);
5408 gen_helper_tlbie(cpu_gpr
[rB(ctx
->opcode
)]);
5413 /* All 405 MAC instructions are translated here */
5414 static always_inline
void gen_405_mulladd_insn (DisasContext
*ctx
,
5416 int ra
, int rb
, int rt
, int Rc
)
5420 t0
= tcg_temp_local_new();
5421 t1
= tcg_temp_local_new();
5423 switch (opc3
& 0x0D) {
5425 /* macchw - macchw. - macchwo - macchwo. */
5426 /* macchws - macchws. - macchwso - macchwso. */
5427 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5428 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5429 /* mulchw - mulchw. */
5430 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5431 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5432 tcg_gen_ext16s_tl(t1
, t1
);
5435 /* macchwu - macchwu. - macchwuo - macchwuo. */
5436 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5437 /* mulchwu - mulchwu. */
5438 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5439 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5440 tcg_gen_ext16u_tl(t1
, t1
);
5443 /* machhw - machhw. - machhwo - machhwo. */
5444 /* machhws - machhws. - machhwso - machhwso. */
5445 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5446 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5447 /* mulhhw - mulhhw. */
5448 tcg_gen_sari_tl(t0
, cpu_gpr
[ra
], 16);
5449 tcg_gen_ext16s_tl(t0
, t0
);
5450 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5451 tcg_gen_ext16s_tl(t1
, t1
);
5454 /* machhwu - machhwu. - machhwuo - machhwuo. */
5455 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5456 /* mulhhwu - mulhhwu. */
5457 tcg_gen_shri_tl(t0
, cpu_gpr
[ra
], 16);
5458 tcg_gen_ext16u_tl(t0
, t0
);
5459 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5460 tcg_gen_ext16u_tl(t1
, t1
);
5463 /* maclhw - maclhw. - maclhwo - maclhwo. */
5464 /* maclhws - maclhws. - maclhwso - maclhwso. */
5465 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5466 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5467 /* mullhw - mullhw. */
5468 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5469 tcg_gen_ext16s_tl(t1
, cpu_gpr
[rb
]);
5472 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5473 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5474 /* mullhwu - mullhwu. */
5475 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5476 tcg_gen_ext16u_tl(t1
, cpu_gpr
[rb
]);
5480 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5481 tcg_gen_mul_tl(t1
, t0
, t1
);
5483 /* nmultiply-and-accumulate (0x0E) */
5484 tcg_gen_sub_tl(t0
, cpu_gpr
[rt
], t1
);
5486 /* multiply-and-accumulate (0x0C) */
5487 tcg_gen_add_tl(t0
, cpu_gpr
[rt
], t1
);
5491 /* Check overflow and/or saturate */
5492 int l1
= gen_new_label();
5495 /* Start with XER OV disabled, the most likely case */
5496 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
5500 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t1
);
5501 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
5502 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t0
);
5503 tcg_gen_brcondi_tl(TCG_COND_LT
, t1
, 0, l1
);
5506 tcg_gen_sari_tl(t0
, cpu_gpr
[rt
], 31);
5507 tcg_gen_xori_tl(t0
, t0
, 0x7fffffff);
5511 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
5514 tcg_gen_movi_tl(t0
, UINT32_MAX
);
5518 /* Check overflow */
5519 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
5522 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
5525 tcg_gen_mul_tl(cpu_gpr
[rt
], t0
, t1
);
5529 if (unlikely(Rc
) != 0) {
5531 gen_set_Rc0(ctx
, cpu_gpr
[rt
]);
5535 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5536 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC) \
5538 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5539 rD(ctx->opcode), Rc(ctx->opcode)); \
5542 /* macchw - macchw. */
5543 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
5544 /* macchwo - macchwo. */
5545 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
5546 /* macchws - macchws. */
5547 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
5548 /* macchwso - macchwso. */
5549 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
5550 /* macchwsu - macchwsu. */
5551 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
5552 /* macchwsuo - macchwsuo. */
5553 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
5554 /* macchwu - macchwu. */
5555 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
5556 /* macchwuo - macchwuo. */
5557 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
5558 /* machhw - machhw. */
5559 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
5560 /* machhwo - machhwo. */
5561 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
5562 /* machhws - machhws. */
5563 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
5564 /* machhwso - machhwso. */
5565 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
5566 /* machhwsu - machhwsu. */
5567 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
5568 /* machhwsuo - machhwsuo. */
5569 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
5570 /* machhwu - machhwu. */
5571 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
5572 /* machhwuo - machhwuo. */
5573 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
5574 /* maclhw - maclhw. */
5575 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
5576 /* maclhwo - maclhwo. */
5577 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
5578 /* maclhws - maclhws. */
5579 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
5580 /* maclhwso - maclhwso. */
5581 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
5582 /* maclhwu - maclhwu. */
5583 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
5584 /* maclhwuo - maclhwuo. */
5585 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
5586 /* maclhwsu - maclhwsu. */
5587 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
5588 /* maclhwsuo - maclhwsuo. */
5589 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
5590 /* nmacchw - nmacchw. */
5591 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
5592 /* nmacchwo - nmacchwo. */
5593 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
5594 /* nmacchws - nmacchws. */
5595 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
5596 /* nmacchwso - nmacchwso. */
5597 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
5598 /* nmachhw - nmachhw. */
5599 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
5600 /* nmachhwo - nmachhwo. */
5601 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
5602 /* nmachhws - nmachhws. */
5603 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
5604 /* nmachhwso - nmachhwso. */
5605 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
5606 /* nmaclhw - nmaclhw. */
5607 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
5608 /* nmaclhwo - nmaclhwo. */
5609 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
5610 /* nmaclhws - nmaclhws. */
5611 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
5612 /* nmaclhwso - nmaclhwso. */
5613 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
5615 /* mulchw - mulchw. */
5616 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
5617 /* mulchwu - mulchwu. */
5618 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
5619 /* mulhhw - mulhhw. */
5620 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
5621 /* mulhhwu - mulhhwu. */
5622 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
5623 /* mullhw - mullhw. */
5624 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
5625 /* mullhwu - mullhwu. */
5626 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
5629 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
)
5631 #if defined(CONFIG_USER_ONLY)
5632 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5635 if (unlikely(!ctx
->mem_idx
)) {
5636 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5639 /* NIP cannot be restored if the memory exception comes from an helper */
5640 gen_update_nip(ctx
, ctx
->nip
- 4);
5641 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5642 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], dcrn
);
5643 tcg_temp_free(dcrn
);
5648 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
)
5650 #if defined(CONFIG_USER_ONLY)
5651 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5654 if (unlikely(!ctx
->mem_idx
)) {
5655 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5658 /* NIP cannot be restored if the memory exception comes from an helper */
5659 gen_update_nip(ctx
, ctx
->nip
- 4);
5660 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
5661 gen_helper_store_dcr(dcrn
, cpu_gpr
[rS(ctx
->opcode
)]);
5662 tcg_temp_free(dcrn
);
5667 /* XXX: not implemented on 440 ? */
5668 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
)
5670 #if defined(CONFIG_USER_ONLY)
5671 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5673 if (unlikely(!ctx
->mem_idx
)) {
5674 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5677 /* NIP cannot be restored if the memory exception comes from an helper */
5678 gen_update_nip(ctx
, ctx
->nip
- 4);
5679 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5680 /* Note: Rc update flag set leads to undefined state of Rc0 */
5685 /* XXX: not implemented on 440 ? */
5686 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
)
5688 #if defined(CONFIG_USER_ONLY)
5689 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5691 if (unlikely(!ctx
->mem_idx
)) {
5692 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5695 /* NIP cannot be restored if the memory exception comes from an helper */
5696 gen_update_nip(ctx
, ctx
->nip
- 4);
5697 gen_helper_store_dcr(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
5698 /* Note: Rc update flag set leads to undefined state of Rc0 */
5702 /* mfdcrux (PPC 460) : user-mode access to DCR */
5703 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
)
5705 /* NIP cannot be restored if the memory exception comes from an helper */
5706 gen_update_nip(ctx
, ctx
->nip
- 4);
5707 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5708 /* Note: Rc update flag set leads to undefined state of Rc0 */
5711 /* mtdcrux (PPC 460) : user-mode access to DCR */
5712 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
)
5714 /* NIP cannot be restored if the memory exception comes from an helper */
5715 gen_update_nip(ctx
, ctx
->nip
- 4);
5716 gen_helper_store_dcr(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
5717 /* Note: Rc update flag set leads to undefined state of Rc0 */
5721 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
)
5723 #if defined(CONFIG_USER_ONLY)
5724 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5726 if (unlikely(!ctx
->mem_idx
)) {
5727 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5730 /* interpreted as no-op */
5735 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
)
5737 #if defined(CONFIG_USER_ONLY)
5738 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5741 if (unlikely(!ctx
->mem_idx
)) {
5742 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5745 gen_set_access_type(ctx
, ACCESS_CACHE
);
5746 EA
= tcg_temp_new();
5747 gen_addr_reg_index(ctx
, EA
);
5748 val
= tcg_temp_new();
5749 gen_qemu_ld32u(ctx
, val
, EA
);
5751 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], EA
);
5757 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
)
5759 /* interpreted as no-op */
5760 /* XXX: specification say this is treated as a load by the MMU
5761 * but does not generate any exception
5766 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
)
5768 #if defined(CONFIG_USER_ONLY)
5769 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5771 if (unlikely(!ctx
->mem_idx
)) {
5772 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5775 /* interpreted as no-op */
5780 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
)
5782 #if defined(CONFIG_USER_ONLY)
5783 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5785 if (unlikely(!ctx
->mem_idx
)) {
5786 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5789 /* interpreted as no-op */
5793 /* rfci (mem_idx only) */
5794 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
)
5796 #if defined(CONFIG_USER_ONLY)
5797 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5799 if (unlikely(!ctx
->mem_idx
)) {
5800 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5803 /* Restore CPU state */
5804 gen_helper_40x_rfci();
5805 gen_sync_exception(ctx
);
5809 GEN_HANDLER(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
)
5811 #if defined(CONFIG_USER_ONLY)
5812 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5814 if (unlikely(!ctx
->mem_idx
)) {
5815 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5818 /* Restore CPU state */
5820 gen_sync_exception(ctx
);
5824 /* BookE specific */
5825 /* XXX: not implemented on 440 ? */
5826 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
)
5828 #if defined(CONFIG_USER_ONLY)
5829 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5831 if (unlikely(!ctx
->mem_idx
)) {
5832 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5835 /* Restore CPU state */
5837 gen_sync_exception(ctx
);
5841 /* XXX: not implemented on 440 ? */
5842 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
)
5844 #if defined(CONFIG_USER_ONLY)
5845 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5847 if (unlikely(!ctx
->mem_idx
)) {
5848 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5851 /* Restore CPU state */
5853 gen_sync_exception(ctx
);
5857 /* TLB management - PowerPC 405 implementation */
5859 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
)
5861 #if defined(CONFIG_USER_ONLY)
5862 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5864 if (unlikely(!ctx
->mem_idx
)) {
5865 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5868 switch (rB(ctx
->opcode
)) {
5870 gen_helper_4xx_tlbre_hi(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5873 gen_helper_4xx_tlbre_lo(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5876 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5882 /* tlbsx - tlbsx. */
5883 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
)
5885 #if defined(CONFIG_USER_ONLY)
5886 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5889 if (unlikely(!ctx
->mem_idx
)) {
5890 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5893 t0
= tcg_temp_new();
5894 gen_addr_reg_index(ctx
, t0
);
5895 gen_helper_4xx_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], t0
);
5897 if (Rc(ctx
->opcode
)) {
5898 int l1
= gen_new_label();
5899 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_xer
);
5900 tcg_gen_shri_i32(cpu_crf
[0], cpu_crf
[0], XER_SO
);
5901 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 1);
5902 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
5903 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
5910 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
)
5912 #if defined(CONFIG_USER_ONLY)
5913 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5915 if (unlikely(!ctx
->mem_idx
)) {
5916 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5919 switch (rB(ctx
->opcode
)) {
5921 gen_helper_4xx_tlbwe_hi(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
5924 gen_helper_4xx_tlbwe_lo(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
5927 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5933 /* TLB management - PowerPC 440 implementation */
5935 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
)
5937 #if defined(CONFIG_USER_ONLY)
5938 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5940 if (unlikely(!ctx
->mem_idx
)) {
5941 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5944 switch (rB(ctx
->opcode
)) {
5949 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
5950 gen_helper_440_tlbwe(t0
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5951 tcg_temp_free_i32(t0
);
5955 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5961 /* tlbsx - tlbsx. */
5962 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
)
5964 #if defined(CONFIG_USER_ONLY)
5965 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5968 if (unlikely(!ctx
->mem_idx
)) {
5969 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5972 t0
= tcg_temp_new();
5973 gen_addr_reg_index(ctx
, t0
);
5974 gen_helper_440_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], t0
);
5976 if (Rc(ctx
->opcode
)) {
5977 int l1
= gen_new_label();
5978 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_xer
);
5979 tcg_gen_shri_i32(cpu_crf
[0], cpu_crf
[0], XER_SO
);
5980 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 1);
5981 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
5982 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
5989 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
)
5991 #if defined(CONFIG_USER_ONLY)
5992 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5994 if (unlikely(!ctx
->mem_idx
)) {
5995 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
5998 switch (rB(ctx
->opcode
)) {
6003 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
6004 gen_helper_440_tlbwe(t0
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
6005 tcg_temp_free_i32(t0
);
6009 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6016 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
)
6018 #if defined(CONFIG_USER_ONLY)
6019 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6022 if (unlikely(!ctx
->mem_idx
)) {
6023 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6026 t0
= tcg_temp_new();
6027 tcg_gen_andi_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)], (1 << MSR_EE
));
6028 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
6029 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
6031 /* Stop translation to have a chance to raise an exception
6032 * if we just set msr_ee to 1
6034 gen_stop_exception(ctx
);
6039 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000EFC01, PPC_WRTEE
)
6041 #if defined(CONFIG_USER_ONLY)
6042 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6044 if (unlikely(!ctx
->mem_idx
)) {
6045 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
6048 if (ctx
->opcode
& 0x00010000) {
6049 tcg_gen_ori_tl(cpu_msr
, cpu_msr
, (1 << MSR_EE
));
6050 /* Stop translation to have a chance to raise an exception */
6051 gen_stop_exception(ctx
);
6053 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, (1 << MSR_EE
));
6058 /* PowerPC 440 specific instructions */
6060 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
)
6062 TCGv_i32 t0
= tcg_const_i32(Rc(ctx
->opcode
));
6063 gen_helper_dlmzb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
6064 cpu_gpr
[rB(ctx
->opcode
)], t0
);
6065 tcg_temp_free_i32(t0
);
6068 /* mbar replaces eieio on 440 */
6069 GEN_HANDLER(mbar
, 0x1F, 0x16, 0x1a, 0x001FF801, PPC_BOOKE
)
6071 /* interpreted as no-op */
6074 /* msync replaces sync on 440 */
6075 GEN_HANDLER(msync
, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE
)
6077 /* interpreted as no-op */
6081 GEN_HANDLER2(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001, PPC_BOOKE
)
6083 /* interpreted as no-op */
6084 /* XXX: specification say this is treated as a load by the MMU
6085 * but does not generate any exception
6089 /*** Altivec vector extension ***/
6090 /* Altivec registers moves */
6092 static always_inline TCGv_ptr
gen_avr_ptr(int reg
)
6094 TCGv_ptr r
= tcg_temp_new_ptr();
6095 tcg_gen_addi_ptr(r
, cpu_env
, offsetof(CPUPPCState
, avr
[reg
]));
6099 #define GEN_VR_LDX(name, opc2, opc3) \
6100 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
6103 if (unlikely(!ctx->altivec_enabled)) { \
6104 gen_exception(ctx, POWERPC_EXCP_VPU); \
6107 gen_set_access_type(ctx, ACCESS_INT); \
6108 EA = tcg_temp_new(); \
6109 gen_addr_reg_index(ctx, EA); \
6110 tcg_gen_andi_tl(EA, EA, ~0xf); \
6111 if (ctx->le_mode) { \
6112 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6113 tcg_gen_addi_tl(EA, EA, 8); \
6114 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6116 gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6117 tcg_gen_addi_tl(EA, EA, 8); \
6118 gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6120 tcg_temp_free(EA); \
6123 #define GEN_VR_STX(name, opc2, opc3) \
6124 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
6127 if (unlikely(!ctx->altivec_enabled)) { \
6128 gen_exception(ctx, POWERPC_EXCP_VPU); \
6131 gen_set_access_type(ctx, ACCESS_INT); \
6132 EA = tcg_temp_new(); \
6133 gen_addr_reg_index(ctx, EA); \
6134 tcg_gen_andi_tl(EA, EA, ~0xf); \
6135 if (ctx->le_mode) { \
6136 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6137 tcg_gen_addi_tl(EA, EA, 8); \
6138 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6140 gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \
6141 tcg_gen_addi_tl(EA, EA, 8); \
6142 gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \
6144 tcg_temp_free(EA); \
6147 GEN_VR_LDX(lvx
, 0x07, 0x03);
6148 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
6149 GEN_VR_LDX(lvxl
, 0x07, 0x0B);
6151 GEN_VR_STX(svx
, 0x07, 0x07);
6152 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
6153 GEN_VR_STX(svxl
, 0x07, 0x0F);
6155 GEN_HANDLER(lvsl
, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC
)
6159 if (unlikely(!ctx
->altivec_enabled
)) {
6160 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6163 EA
= tcg_temp_new();
6164 gen_addr_reg_index(ctx
, EA
);
6165 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6166 gen_helper_lvsl(rd
, EA
);
6168 tcg_temp_free_ptr(rd
);
6171 GEN_HANDLER(lvsr
, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC
)
6175 if (unlikely(!ctx
->altivec_enabled
)) {
6176 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6179 EA
= tcg_temp_new();
6180 gen_addr_reg_index(ctx
, EA
);
6181 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6182 gen_helper_lvsr(rd
, EA
);
6184 tcg_temp_free_ptr(rd
);
6187 /* Logical operations */
6188 #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \
6189 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) \
6191 if (unlikely(!ctx->altivec_enabled)) { \
6192 gen_exception(ctx, POWERPC_EXCP_VPU); \
6195 tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \
6196 tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \
6199 GEN_VX_LOGICAL(vand
, tcg_gen_and_i64
, 2, 16);
6200 GEN_VX_LOGICAL(vandc
, tcg_gen_andc_i64
, 2, 17);
6201 GEN_VX_LOGICAL(vor
, tcg_gen_or_i64
, 2, 18);
6202 GEN_VX_LOGICAL(vxor
, tcg_gen_xor_i64
, 2, 19);
6203 GEN_VX_LOGICAL(vnor
, tcg_gen_nor_i64
, 2, 20);
6205 #define GEN_VXFORM(name, opc2, opc3) \
6206 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) \
6208 TCGv_ptr ra, rb, rd; \
6209 if (unlikely(!ctx->altivec_enabled)) { \
6210 gen_exception(ctx, POWERPC_EXCP_VPU); \
6213 ra = gen_avr_ptr(rA(ctx->opcode)); \
6214 rb = gen_avr_ptr(rB(ctx->opcode)); \
6215 rd = gen_avr_ptr(rD(ctx->opcode)); \
6216 gen_helper_##name (rd, ra, rb); \
6217 tcg_temp_free_ptr(ra); \
6218 tcg_temp_free_ptr(rb); \
6219 tcg_temp_free_ptr(rd); \
6222 GEN_VXFORM(vaddubm
, 0, 0);
6223 GEN_VXFORM(vadduhm
, 0, 1);
6224 GEN_VXFORM(vadduwm
, 0, 2);
6225 GEN_VXFORM(vsububm
, 0, 16);
6226 GEN_VXFORM(vsubuhm
, 0, 17);
6227 GEN_VXFORM(vsubuwm
, 0, 18);
6228 GEN_VXFORM(vmaxub
, 1, 0);
6229 GEN_VXFORM(vmaxuh
, 1, 1);
6230 GEN_VXFORM(vmaxuw
, 1, 2);
6231 GEN_VXFORM(vmaxsb
, 1, 4);
6232 GEN_VXFORM(vmaxsh
, 1, 5);
6233 GEN_VXFORM(vmaxsw
, 1, 6);
6234 GEN_VXFORM(vminub
, 1, 8);
6235 GEN_VXFORM(vminuh
, 1, 9);
6236 GEN_VXFORM(vminuw
, 1, 10);
6237 GEN_VXFORM(vminsb
, 1, 12);
6238 GEN_VXFORM(vminsh
, 1, 13);
6239 GEN_VXFORM(vminsw
, 1, 14);
6240 GEN_VXFORM(vavgub
, 1, 16);
6241 GEN_VXFORM(vavguh
, 1, 17);
6242 GEN_VXFORM(vavguw
, 1, 18);
6243 GEN_VXFORM(vavgsb
, 1, 20);
6244 GEN_VXFORM(vavgsh
, 1, 21);
6245 GEN_VXFORM(vavgsw
, 1, 22);
6246 GEN_VXFORM(vmrghb
, 6, 0);
6247 GEN_VXFORM(vmrghh
, 6, 1);
6248 GEN_VXFORM(vmrghw
, 6, 2);
6249 GEN_VXFORM(vmrglb
, 6, 4);
6250 GEN_VXFORM(vmrglh
, 6, 5);
6251 GEN_VXFORM(vmrglw
, 6, 6);
6252 GEN_VXFORM(vmuloub
, 4, 0);
6253 GEN_VXFORM(vmulouh
, 4, 1);
6254 GEN_VXFORM(vmulosb
, 4, 4);
6255 GEN_VXFORM(vmulosh
, 4, 5);
6256 GEN_VXFORM(vmuleub
, 4, 8);
6257 GEN_VXFORM(vmuleuh
, 4, 9);
6258 GEN_VXFORM(vmulesb
, 4, 12);
6259 GEN_VXFORM(vmulesh
, 4, 13);
6260 GEN_VXFORM(vslb
, 2, 4);
6261 GEN_VXFORM(vslh
, 2, 5);
6262 GEN_VXFORM(vslw
, 2, 6);
6263 GEN_VXFORM(vsrb
, 2, 8);
6264 GEN_VXFORM(vsrh
, 2, 9);
6265 GEN_VXFORM(vsrw
, 2, 10);
6266 GEN_VXFORM(vsrab
, 2, 12);
6267 GEN_VXFORM(vsrah
, 2, 13);
6268 GEN_VXFORM(vsraw
, 2, 14);
6269 GEN_VXFORM(vslo
, 6, 16);
6270 GEN_VXFORM(vsro
, 6, 17);
6271 GEN_VXFORM(vaddcuw
, 0, 6);
6272 GEN_VXFORM(vsubcuw
, 0, 22);
6273 GEN_VXFORM(vrlb
, 2, 0);
6274 GEN_VXFORM(vrlh
, 2, 1);
6275 GEN_VXFORM(vrlw
, 2, 2);
6276 GEN_VXFORM(vpkuhum
, 7, 0);
6277 GEN_VXFORM(vpkuwum
, 7, 1);
6278 GEN_VXFORM(vpkuhus
, 7, 2);
6279 GEN_VXFORM(vpkuwus
, 7, 3);
6280 GEN_VXFORM(vpkshus
, 7, 4);
6281 GEN_VXFORM(vpkswus
, 7, 5);
6282 GEN_VXFORM(vpkshss
, 7, 6);
6283 GEN_VXFORM(vpkswss
, 7, 7);
6284 GEN_VXFORM(vpkpx
, 7, 12);
6286 #define GEN_VXFORM_NOA(name, opc2, opc3) \
6287 GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC) \
6290 if (unlikely(!ctx->altivec_enabled)) { \
6291 gen_exception(ctx, POWERPC_EXCP_VPU); \
6294 rb = gen_avr_ptr(rB(ctx->opcode)); \
6295 rd = gen_avr_ptr(rD(ctx->opcode)); \
6296 gen_helper_##name (rd, rb); \
6297 tcg_temp_free_ptr(rb); \
6298 tcg_temp_free_ptr(rd); \
6301 GEN_VXFORM_NOA(vupkhsb
, 7, 8);
6302 GEN_VXFORM_NOA(vupkhsh
, 7, 9);
6303 GEN_VXFORM_NOA(vupklsb
, 7, 10);
6304 GEN_VXFORM_NOA(vupklsh
, 7, 11);
6305 GEN_VXFORM_NOA(vupkhpx
, 7, 13);
6306 GEN_VXFORM_NOA(vupklpx
, 7, 15);
6308 #define GEN_VXFORM_SIMM(name, opc2, opc3) \
6309 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) \
6313 if (unlikely(!ctx->altivec_enabled)) { \
6314 gen_exception(ctx, POWERPC_EXCP_VPU); \
6317 simm = tcg_const_i32(SIMM5(ctx->opcode)); \
6318 rd = gen_avr_ptr(rD(ctx->opcode)); \
6319 gen_helper_##name (rd, simm); \
6320 tcg_temp_free_i32(simm); \
6321 tcg_temp_free_ptr(rd); \
6324 #define GEN_VXFORM_UIMM(name, opc2, opc3) \
6325 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) \
6329 if (unlikely(!ctx->altivec_enabled)) { \
6330 gen_exception(ctx, POWERPC_EXCP_VPU); \
6333 uimm = tcg_const_i32(UIMM5(ctx->opcode)); \
6334 rb = gen_avr_ptr(rB(ctx->opcode)); \
6335 rd = gen_avr_ptr(rD(ctx->opcode)); \
6336 gen_helper_##name (rd, rb, uimm); \
6337 tcg_temp_free_i32(uimm); \
6338 tcg_temp_free_ptr(rb); \
6339 tcg_temp_free_ptr(rd); \
6342 GEN_VXFORM_UIMM(vspltb
, 6, 8);
6343 GEN_VXFORM_UIMM(vsplth
, 6, 9);
6344 GEN_VXFORM_UIMM(vspltw
, 6, 10);
6346 GEN_HANDLER(vsldoi
, 0x04, 0x16, 0xFF, 0x00000400, PPC_ALTIVEC
)
6348 TCGv_ptr ra
, rb
, rd
;
6350 if (unlikely(!ctx
->altivec_enabled
)) {
6351 gen_exception(ctx
, POWERPC_EXCP_VPU
);
6354 ra
= gen_avr_ptr(rA(ctx
->opcode
));
6355 rb
= gen_avr_ptr(rB(ctx
->opcode
));
6356 rd
= gen_avr_ptr(rD(ctx
->opcode
));
6357 sh
= tcg_const_i32(VSH(ctx
->opcode
));
6358 gen_helper_vsldoi (rd
, ra
, rb
, sh
);
6359 tcg_temp_free_ptr(ra
);
6360 tcg_temp_free_ptr(rb
);
6361 tcg_temp_free_ptr(rd
);
6365 #define GEN_VAFORM_PAIRED(name0, name1, opc2) \
6366 GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC) \
6368 TCGv_ptr ra, rb, rc, rd; \
6369 if (unlikely(!ctx->altivec_enabled)) { \
6370 gen_exception(ctx, POWERPC_EXCP_VPU); \
6373 ra = gen_avr_ptr(rA(ctx->opcode)); \
6374 rb = gen_avr_ptr(rB(ctx->opcode)); \
6375 rc = gen_avr_ptr(rC(ctx->opcode)); \
6376 rd = gen_avr_ptr(rD(ctx->opcode)); \
6377 if (Rc(ctx->opcode)) { \
6378 gen_helper_##name1 (rd, ra, rb, rc); \
6380 gen_helper_##name0 (rd, ra, rb, rc); \
6382 tcg_temp_free_ptr(ra); \
6383 tcg_temp_free_ptr(rb); \
6384 tcg_temp_free_ptr(rc); \
6385 tcg_temp_free_ptr(rd); \
6388 GEN_VAFORM_PAIRED(vmhaddshs
, vmhraddshs
, 16)
6390 GEN_VAFORM_PAIRED(vmsumubm
, vmsummbm
, 18)
6391 GEN_VAFORM_PAIRED(vmsumuhm
, vmsumuhs
, 19)
6392 GEN_VAFORM_PAIRED(vmsumshm
, vmsumshs
, 20)
6393 GEN_VAFORM_PAIRED(vsel
, vperm
, 21)
6395 /*** SPE extension ***/
6396 /* Register moves */
6398 static always_inline
void gen_load_gpr64(TCGv_i64 t
, int reg
) {
6399 #if defined(TARGET_PPC64)
6400 tcg_gen_mov_i64(t
, cpu_gpr
[reg
]);
6402 tcg_gen_concat_i32_i64(t
, cpu_gpr
[reg
], cpu_gprh
[reg
]);
6406 static always_inline
void gen_store_gpr64(int reg
, TCGv_i64 t
) {
6407 #if defined(TARGET_PPC64)
6408 tcg_gen_mov_i64(cpu_gpr
[reg
], t
);
6410 TCGv_i64 tmp
= tcg_temp_new_i64();
6411 tcg_gen_trunc_i64_i32(cpu_gpr
[reg
], t
);
6412 tcg_gen_shri_i64(tmp
, t
, 32);
6413 tcg_gen_trunc_i64_i32(cpu_gprh
[reg
], tmp
);
6414 tcg_temp_free_i64(tmp
);
6418 #define GEN_SPE(name0, name1, opc2, opc3, inval, type) \
6419 GEN_HANDLER(name0##_##name1, 0x04, opc2, opc3, inval, type) \
6421 if (Rc(ctx->opcode)) \
6427 /* Handler for undefined SPE opcodes */
6428 static always_inline
void gen_speundef (DisasContext
*ctx
)
6430 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6434 #if defined(TARGET_PPC64)
6435 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
6436 static always_inline void gen_##name (DisasContext *ctx) \
6438 if (unlikely(!ctx->spe_enabled)) { \
6439 gen_exception(ctx, POWERPC_EXCP_APU); \
6442 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6443 cpu_gpr[rB(ctx->opcode)]); \
6446 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
6447 static always_inline void gen_##name (DisasContext *ctx) \
6449 if (unlikely(!ctx->spe_enabled)) { \
6450 gen_exception(ctx, POWERPC_EXCP_APU); \
6453 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6454 cpu_gpr[rB(ctx->opcode)]); \
6455 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6456 cpu_gprh[rB(ctx->opcode)]); \
6460 GEN_SPEOP_LOGIC2(evand
, tcg_gen_and_tl
);
6461 GEN_SPEOP_LOGIC2(evandc
, tcg_gen_andc_tl
);
6462 GEN_SPEOP_LOGIC2(evxor
, tcg_gen_xor_tl
);
6463 GEN_SPEOP_LOGIC2(evor
, tcg_gen_or_tl
);
6464 GEN_SPEOP_LOGIC2(evnor
, tcg_gen_nor_tl
);
6465 GEN_SPEOP_LOGIC2(eveqv
, tcg_gen_eqv_tl
);
6466 GEN_SPEOP_LOGIC2(evorc
, tcg_gen_orc_tl
);
6467 GEN_SPEOP_LOGIC2(evnand
, tcg_gen_nand_tl
);
6469 /* SPE logic immediate */
6470 #if defined(TARGET_PPC64)
6471 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
6472 static always_inline void gen_##name (DisasContext *ctx) \
6474 if (unlikely(!ctx->spe_enabled)) { \
6475 gen_exception(ctx, POWERPC_EXCP_APU); \
6478 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6479 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6480 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6481 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6482 tcg_opi(t0, t0, rB(ctx->opcode)); \
6483 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6484 tcg_gen_trunc_i64_i32(t1, t2); \
6485 tcg_temp_free_i64(t2); \
6486 tcg_opi(t1, t1, rB(ctx->opcode)); \
6487 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6488 tcg_temp_free_i32(t0); \
6489 tcg_temp_free_i32(t1); \
6492 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
6493 static always_inline void gen_##name (DisasContext *ctx) \
6495 if (unlikely(!ctx->spe_enabled)) { \
6496 gen_exception(ctx, POWERPC_EXCP_APU); \
6499 tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6501 tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6505 GEN_SPEOP_TCG_LOGIC_IMM2(evslwi
, tcg_gen_shli_i32
);
6506 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu
, tcg_gen_shri_i32
);
6507 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis
, tcg_gen_sari_i32
);
6508 GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi
, tcg_gen_rotli_i32
);
6510 /* SPE arithmetic */
6511 #if defined(TARGET_PPC64)
6512 #define GEN_SPEOP_ARITH1(name, tcg_op) \
6513 static always_inline void gen_##name (DisasContext *ctx) \
6515 if (unlikely(!ctx->spe_enabled)) { \
6516 gen_exception(ctx, POWERPC_EXCP_APU); \
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)]); \
6524 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6525 tcg_gen_trunc_i64_i32(t1, t2); \
6526 tcg_temp_free_i64(t2); \
6528 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6529 tcg_temp_free_i32(t0); \
6530 tcg_temp_free_i32(t1); \
6533 #define GEN_SPEOP_ARITH1(name, tcg_op) \
6534 static always_inline void gen_##name (DisasContext *ctx) \
6536 if (unlikely(!ctx->spe_enabled)) { \
6537 gen_exception(ctx, POWERPC_EXCP_APU); \
6540 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
6541 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
6545 static always_inline
void gen_op_evabs (TCGv_i32 ret
, TCGv_i32 arg1
)
6547 int l1
= gen_new_label();
6548 int l2
= gen_new_label();
6550 tcg_gen_brcondi_i32(TCG_COND_GE
, arg1
, 0, l1
);
6551 tcg_gen_neg_i32(ret
, arg1
);
6554 tcg_gen_mov_i32(ret
, arg1
);
6557 GEN_SPEOP_ARITH1(evabs
, gen_op_evabs
);
6558 GEN_SPEOP_ARITH1(evneg
, tcg_gen_neg_i32
);
6559 GEN_SPEOP_ARITH1(evextsb
, tcg_gen_ext8s_i32
);
6560 GEN_SPEOP_ARITH1(evextsh
, tcg_gen_ext16s_i32
);
6561 static always_inline
void gen_op_evrndw (TCGv_i32 ret
, TCGv_i32 arg1
)
6563 tcg_gen_addi_i32(ret
, arg1
, 0x8000);
6564 tcg_gen_ext16u_i32(ret
, ret
);
6566 GEN_SPEOP_ARITH1(evrndw
, gen_op_evrndw
);
6567 GEN_SPEOP_ARITH1(evcntlsw
, gen_helper_cntlsw32
);
6568 GEN_SPEOP_ARITH1(evcntlzw
, gen_helper_cntlzw32
);
6570 #if defined(TARGET_PPC64)
6571 #define GEN_SPEOP_ARITH2(name, tcg_op) \
6572 static always_inline void gen_##name (DisasContext *ctx) \
6574 if (unlikely(!ctx->spe_enabled)) { \
6575 gen_exception(ctx, POWERPC_EXCP_APU); \
6578 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6579 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6580 TCGv_i32 t2 = tcg_temp_local_new_i32(); \
6581 TCGv_i64 t3 = tcg_temp_local_new_i64(); \
6582 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6583 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
6584 tcg_op(t0, t0, t2); \
6585 tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
6586 tcg_gen_trunc_i64_i32(t1, t3); \
6587 tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
6588 tcg_gen_trunc_i64_i32(t2, t3); \
6589 tcg_temp_free_i64(t3); \
6590 tcg_op(t1, t1, t2); \
6591 tcg_temp_free_i32(t2); \
6592 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6593 tcg_temp_free_i32(t0); \
6594 tcg_temp_free_i32(t1); \
6597 #define GEN_SPEOP_ARITH2(name, tcg_op) \
6598 static always_inline void gen_##name (DisasContext *ctx) \
6600 if (unlikely(!ctx->spe_enabled)) { \
6601 gen_exception(ctx, POWERPC_EXCP_APU); \
6604 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6605 cpu_gpr[rB(ctx->opcode)]); \
6606 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6607 cpu_gprh[rB(ctx->opcode)]); \
6611 static always_inline
void gen_op_evsrwu (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6616 l1
= gen_new_label();
6617 l2
= gen_new_label();
6618 t0
= tcg_temp_local_new_i32();
6619 /* No error here: 6 bits are used */
6620 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
6621 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
6622 tcg_gen_shr_i32(ret
, arg1
, t0
);
6625 tcg_gen_movi_i32(ret
, 0);
6627 tcg_temp_free_i32(t0
);
6629 GEN_SPEOP_ARITH2(evsrwu
, gen_op_evsrwu
);
6630 static always_inline
void gen_op_evsrws (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6635 l1
= gen_new_label();
6636 l2
= gen_new_label();
6637 t0
= tcg_temp_local_new_i32();
6638 /* No error here: 6 bits are used */
6639 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
6640 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
6641 tcg_gen_sar_i32(ret
, arg1
, t0
);
6644 tcg_gen_movi_i32(ret
, 0);
6646 tcg_temp_free_i32(t0
);
6648 GEN_SPEOP_ARITH2(evsrws
, gen_op_evsrws
);
6649 static always_inline
void gen_op_evslw (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6654 l1
= gen_new_label();
6655 l2
= gen_new_label();
6656 t0
= tcg_temp_local_new_i32();
6657 /* No error here: 6 bits are used */
6658 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
6659 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
6660 tcg_gen_shl_i32(ret
, arg1
, t0
);
6663 tcg_gen_movi_i32(ret
, 0);
6665 tcg_temp_free_i32(t0
);
6667 GEN_SPEOP_ARITH2(evslw
, gen_op_evslw
);
6668 static always_inline
void gen_op_evrlw (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6670 TCGv_i32 t0
= tcg_temp_new_i32();
6671 tcg_gen_andi_i32(t0
, arg2
, 0x1F);
6672 tcg_gen_rotl_i32(ret
, arg1
, t0
);
6673 tcg_temp_free_i32(t0
);
6675 GEN_SPEOP_ARITH2(evrlw
, gen_op_evrlw
);
6676 static always_inline
void gen_evmergehi (DisasContext
*ctx
)
6678 if (unlikely(!ctx
->spe_enabled
)) {
6679 gen_exception(ctx
, POWERPC_EXCP_APU
);
6682 #if defined(TARGET_PPC64)
6683 TCGv t0
= tcg_temp_new();
6684 TCGv t1
= tcg_temp_new();
6685 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
6686 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
6687 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
6691 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
6692 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6695 GEN_SPEOP_ARITH2(evaddw
, tcg_gen_add_i32
);
6696 static always_inline
void gen_op_evsubf (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6698 tcg_gen_sub_i32(ret
, arg2
, arg1
);
6700 GEN_SPEOP_ARITH2(evsubfw
, gen_op_evsubf
);
6702 /* SPE arithmetic immediate */
6703 #if defined(TARGET_PPC64)
6704 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
6705 static always_inline void gen_##name (DisasContext *ctx) \
6707 if (unlikely(!ctx->spe_enabled)) { \
6708 gen_exception(ctx, POWERPC_EXCP_APU); \
6711 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6712 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6713 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6714 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
6715 tcg_op(t0, t0, rA(ctx->opcode)); \
6716 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
6717 tcg_gen_trunc_i64_i32(t1, t2); \
6718 tcg_temp_free_i64(t2); \
6719 tcg_op(t1, t1, rA(ctx->opcode)); \
6720 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6721 tcg_temp_free_i32(t0); \
6722 tcg_temp_free_i32(t1); \
6725 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
6726 static always_inline void gen_##name (DisasContext *ctx) \
6728 if (unlikely(!ctx->spe_enabled)) { \
6729 gen_exception(ctx, POWERPC_EXCP_APU); \
6732 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
6734 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
6738 GEN_SPEOP_ARITH_IMM2(evaddiw
, tcg_gen_addi_i32
);
6739 GEN_SPEOP_ARITH_IMM2(evsubifw
, tcg_gen_subi_i32
);
6741 /* SPE comparison */
6742 #if defined(TARGET_PPC64)
6743 #define GEN_SPEOP_COMP(name, tcg_cond) \
6744 static always_inline void gen_##name (DisasContext *ctx) \
6746 if (unlikely(!ctx->spe_enabled)) { \
6747 gen_exception(ctx, POWERPC_EXCP_APU); \
6750 int l1 = gen_new_label(); \
6751 int l2 = gen_new_label(); \
6752 int l3 = gen_new_label(); \
6753 int l4 = gen_new_label(); \
6754 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6755 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6756 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6757 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6758 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
6759 tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
6760 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
6762 gen_set_label(l1); \
6763 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
6764 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
6765 gen_set_label(l2); \
6766 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6767 tcg_gen_trunc_i64_i32(t0, t2); \
6768 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
6769 tcg_gen_trunc_i64_i32(t1, t2); \
6770 tcg_temp_free_i64(t2); \
6771 tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
6772 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6773 ~(CRF_CH | CRF_CH_AND_CL)); \
6775 gen_set_label(l3); \
6776 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6777 CRF_CH | CRF_CH_OR_CL); \
6778 gen_set_label(l4); \
6779 tcg_temp_free_i32(t0); \
6780 tcg_temp_free_i32(t1); \
6783 #define GEN_SPEOP_COMP(name, tcg_cond) \
6784 static always_inline void gen_##name (DisasContext *ctx) \
6786 if (unlikely(!ctx->spe_enabled)) { \
6787 gen_exception(ctx, POWERPC_EXCP_APU); \
6790 int l1 = gen_new_label(); \
6791 int l2 = gen_new_label(); \
6792 int l3 = gen_new_label(); \
6793 int l4 = gen_new_label(); \
6795 tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
6796 cpu_gpr[rB(ctx->opcode)], l1); \
6797 tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
6799 gen_set_label(l1); \
6800 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
6801 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
6802 gen_set_label(l2); \
6803 tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
6804 cpu_gprh[rB(ctx->opcode)], l3); \
6805 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6806 ~(CRF_CH | CRF_CH_AND_CL)); \
6808 gen_set_label(l3); \
6809 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6810 CRF_CH | CRF_CH_OR_CL); \
6811 gen_set_label(l4); \
6814 GEN_SPEOP_COMP(evcmpgtu
, TCG_COND_GTU
);
6815 GEN_SPEOP_COMP(evcmpgts
, TCG_COND_GT
);
6816 GEN_SPEOP_COMP(evcmpltu
, TCG_COND_LTU
);
6817 GEN_SPEOP_COMP(evcmplts
, TCG_COND_LT
);
6818 GEN_SPEOP_COMP(evcmpeq
, TCG_COND_EQ
);
6821 static always_inline
void gen_brinc (DisasContext
*ctx
)
6823 /* Note: brinc is usable even if SPE is disabled */
6824 gen_helper_brinc(cpu_gpr
[rD(ctx
->opcode
)],
6825 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6827 static always_inline
void gen_evmergelo (DisasContext
*ctx
)
6829 if (unlikely(!ctx
->spe_enabled
)) {
6830 gen_exception(ctx
, POWERPC_EXCP_APU
);
6833 #if defined(TARGET_PPC64)
6834 TCGv t0
= tcg_temp_new();
6835 TCGv t1
= tcg_temp_new();
6836 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x00000000FFFFFFFFLL
);
6837 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
6838 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
6842 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6843 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6846 static always_inline
void gen_evmergehilo (DisasContext
*ctx
)
6848 if (unlikely(!ctx
->spe_enabled
)) {
6849 gen_exception(ctx
, POWERPC_EXCP_APU
);
6852 #if defined(TARGET_PPC64)
6853 TCGv t0
= tcg_temp_new();
6854 TCGv t1
= tcg_temp_new();
6855 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x00000000FFFFFFFFLL
);
6856 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
6857 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
6861 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6862 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6865 static always_inline
void gen_evmergelohi (DisasContext
*ctx
)
6867 if (unlikely(!ctx
->spe_enabled
)) {
6868 gen_exception(ctx
, POWERPC_EXCP_APU
);
6871 #if defined(TARGET_PPC64)
6872 TCGv t0
= tcg_temp_new();
6873 TCGv t1
= tcg_temp_new();
6874 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
6875 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
6876 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
6880 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
6881 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6884 static always_inline
void gen_evsplati (DisasContext
*ctx
)
6886 uint64_t imm
= ((int32_t)(rA(ctx
->opcode
) << 11)) >> 27;
6888 #if defined(TARGET_PPC64)
6889 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
6891 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
6892 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
6895 static always_inline
void gen_evsplatfi (DisasContext
*ctx
)
6897 uint64_t imm
= rA(ctx
->opcode
) << 11;
6899 #if defined(TARGET_PPC64)
6900 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
6902 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
6903 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
6907 static always_inline
void gen_evsel (DisasContext
*ctx
)
6909 int l1
= gen_new_label();
6910 int l2
= gen_new_label();
6911 int l3
= gen_new_label();
6912 int l4
= gen_new_label();
6913 TCGv_i32 t0
= tcg_temp_local_new_i32();
6914 #if defined(TARGET_PPC64)
6915 TCGv t1
= tcg_temp_local_new();
6916 TCGv t2
= tcg_temp_local_new();
6918 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 3);
6919 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
6920 #if defined(TARGET_PPC64)
6921 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
6923 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6927 #if defined(TARGET_PPC64)
6928 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
6930 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
6933 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 2);
6934 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l3
);
6935 #if defined(TARGET_PPC64)
6936 tcg_gen_andi_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], 0x00000000FFFFFFFFULL
);
6938 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6942 #if defined(TARGET_PPC64)
6943 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x00000000FFFFFFFFULL
);
6945 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6948 tcg_temp_free_i32(t0
);
6949 #if defined(TARGET_PPC64)
6950 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
, t2
);
6955 GEN_HANDLER2(evsel0
, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE
)
6959 GEN_HANDLER2(evsel1
, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE
)
6963 GEN_HANDLER2(evsel2
, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE
)
6967 GEN_HANDLER2(evsel3
, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE
)
6972 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, PPC_SPE
); ////
6973 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, PPC_SPE
);
6974 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, PPC_SPE
); ////
6975 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, PPC_SPE
);
6976 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, PPC_SPE
); ////
6977 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, PPC_SPE
); ////
6978 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, PPC_SPE
); ////
6979 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x00000000, PPC_SPE
); //
6980 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0x00000000, PPC_SPE
); ////
6981 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, PPC_SPE
); ////
6982 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, PPC_SPE
); ////
6983 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, PPC_SPE
); ////
6984 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0x00000000, PPC_SPE
); ////
6985 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, PPC_SPE
); ////
6986 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, PPC_SPE
); ////
6987 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, PPC_SPE
);
6988 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, PPC_SPE
); ////
6989 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, PPC_SPE
);
6990 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, PPC_SPE
); //
6991 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, PPC_SPE
);
6992 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, PPC_SPE
); ////
6993 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, PPC_SPE
); ////
6994 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, PPC_SPE
); ////
6995 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, PPC_SPE
); ////
6996 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, PPC_SPE
); ////
6998 /* SPE load and stores */
6999 static always_inline
void gen_addr_spe_imm_index (DisasContext
*ctx
, TCGv EA
, int sh
)
7001 target_ulong uimm
= rB(ctx
->opcode
);
7003 if (rA(ctx
->opcode
) == 0) {
7004 tcg_gen_movi_tl(EA
, uimm
<< sh
);
7006 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], uimm
<< sh
);
7007 #if defined(TARGET_PPC64)
7008 if (!ctx
->sf_mode
) {
7009 tcg_gen_ext32u_tl(EA
, EA
);
7015 static always_inline
void gen_op_evldd(DisasContext
*ctx
, TCGv addr
)
7017 #if defined(TARGET_PPC64)
7018 gen_qemu_ld64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7020 TCGv_i64 t0
= tcg_temp_new_i64();
7021 gen_qemu_ld64(ctx
, t0
, addr
);
7022 tcg_gen_trunc_i64_i32(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7023 tcg_gen_shri_i64(t0
, t0
, 32);
7024 tcg_gen_trunc_i64_i32(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7025 tcg_temp_free_i64(t0
);
7029 static always_inline
void gen_op_evldw(DisasContext
*ctx
, TCGv addr
)
7031 #if defined(TARGET_PPC64)
7032 TCGv t0
= tcg_temp_new();
7033 gen_qemu_ld32u(ctx
, t0
, addr
);
7034 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7035 gen_addr_add(ctx
, addr
, addr
, 4);
7036 gen_qemu_ld32u(ctx
, t0
, addr
);
7037 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7040 gen_qemu_ld32u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7041 gen_addr_add(ctx
, addr
, addr
, 4);
7042 gen_qemu_ld32u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7046 static always_inline
void gen_op_evldh(DisasContext
*ctx
, TCGv addr
)
7048 TCGv t0
= tcg_temp_new();
7049 #if defined(TARGET_PPC64)
7050 gen_qemu_ld16u(ctx
, t0
, addr
);
7051 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7052 gen_addr_add(ctx
, addr
, addr
, 2);
7053 gen_qemu_ld16u(ctx
, t0
, addr
);
7054 tcg_gen_shli_tl(t0
, t0
, 32);
7055 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7056 gen_addr_add(ctx
, addr
, addr
, 2);
7057 gen_qemu_ld16u(ctx
, t0
, addr
);
7058 tcg_gen_shli_tl(t0
, t0
, 16);
7059 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7060 gen_addr_add(ctx
, addr
, addr
, 2);
7061 gen_qemu_ld16u(ctx
, t0
, addr
);
7062 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7064 gen_qemu_ld16u(ctx
, t0
, addr
);
7065 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7066 gen_addr_add(ctx
, addr
, addr
, 2);
7067 gen_qemu_ld16u(ctx
, t0
, addr
);
7068 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
7069 gen_addr_add(ctx
, addr
, addr
, 2);
7070 gen_qemu_ld16u(ctx
, t0
, addr
);
7071 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7072 gen_addr_add(ctx
, addr
, addr
, 2);
7073 gen_qemu_ld16u(ctx
, t0
, addr
);
7074 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7079 static always_inline
void gen_op_evlhhesplat(DisasContext
*ctx
, TCGv addr
)
7081 TCGv t0
= tcg_temp_new();
7082 gen_qemu_ld16u(ctx
, t0
, addr
);
7083 #if defined(TARGET_PPC64)
7084 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7085 tcg_gen_shli_tl(t0
, t0
, 16);
7086 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7088 tcg_gen_shli_tl(t0
, t0
, 16);
7089 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7090 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7095 static always_inline
void gen_op_evlhhousplat(DisasContext
*ctx
, TCGv addr
)
7097 TCGv t0
= tcg_temp_new();
7098 gen_qemu_ld16u(ctx
, t0
, addr
);
7099 #if defined(TARGET_PPC64)
7100 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7101 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7103 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7104 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7109 static always_inline
void gen_op_evlhhossplat(DisasContext
*ctx
, TCGv addr
)
7111 TCGv t0
= tcg_temp_new();
7112 gen_qemu_ld16s(ctx
, t0
, addr
);
7113 #if defined(TARGET_PPC64)
7114 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7115 tcg_gen_ext32u_tl(t0
, t0
);
7116 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7118 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7119 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7124 static always_inline
void gen_op_evlwhe(DisasContext
*ctx
, TCGv addr
)
7126 TCGv t0
= tcg_temp_new();
7127 #if defined(TARGET_PPC64)
7128 gen_qemu_ld16u(ctx
, t0
, addr
);
7129 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7130 gen_addr_add(ctx
, addr
, addr
, 2);
7131 gen_qemu_ld16u(ctx
, t0
, addr
);
7132 tcg_gen_shli_tl(t0
, t0
, 16);
7133 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7135 gen_qemu_ld16u(ctx
, t0
, addr
);
7136 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7137 gen_addr_add(ctx
, addr
, addr
, 2);
7138 gen_qemu_ld16u(ctx
, t0
, addr
);
7139 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
7144 static always_inline
void gen_op_evlwhou(DisasContext
*ctx
, TCGv addr
)
7146 #if defined(TARGET_PPC64)
7147 TCGv t0
= tcg_temp_new();
7148 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7149 gen_addr_add(ctx
, addr
, addr
, 2);
7150 gen_qemu_ld16u(ctx
, t0
, addr
);
7151 tcg_gen_shli_tl(t0
, t0
, 32);
7152 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7155 gen_qemu_ld16u(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7156 gen_addr_add(ctx
, addr
, addr
, 2);
7157 gen_qemu_ld16u(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7161 static always_inline
void gen_op_evlwhos(DisasContext
*ctx
, TCGv addr
)
7163 #if defined(TARGET_PPC64)
7164 TCGv t0
= tcg_temp_new();
7165 gen_qemu_ld16s(ctx
, t0
, addr
);
7166 tcg_gen_ext32u_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7167 gen_addr_add(ctx
, addr
, addr
, 2);
7168 gen_qemu_ld16s(ctx
, t0
, addr
);
7169 tcg_gen_shli_tl(t0
, t0
, 32);
7170 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7173 gen_qemu_ld16s(ctx
, cpu_gprh
[rD(ctx
->opcode
)], addr
);
7174 gen_addr_add(ctx
, addr
, addr
, 2);
7175 gen_qemu_ld16s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], addr
);
7179 static always_inline
void gen_op_evlwwsplat(DisasContext
*ctx
, TCGv addr
)
7181 TCGv t0
= tcg_temp_new();
7182 gen_qemu_ld32u(ctx
, t0
, addr
);
7183 #if defined(TARGET_PPC64)
7184 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
7185 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7187 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
7188 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
7193 static always_inline
void gen_op_evlwhsplat(DisasContext
*ctx
, TCGv addr
)
7195 TCGv t0
= tcg_temp_new();
7196 #if defined(TARGET_PPC64)
7197 gen_qemu_ld16u(ctx
, t0
, addr
);
7198 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
7199 tcg_gen_shli_tl(t0
, t0
, 32);
7200 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7201 gen_addr_add(ctx
, addr
, addr
, 2);
7202 gen_qemu_ld16u(ctx
, t0
, addr
);
7203 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7204 tcg_gen_shli_tl(t0
, t0
, 16);
7205 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
7207 gen_qemu_ld16u(ctx
, t0
, addr
);
7208 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
7209 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
7210 gen_addr_add(ctx
, addr
, addr
, 2);
7211 gen_qemu_ld16u(ctx
, t0
, addr
);
7212 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
7213 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
7218 static always_inline
void gen_op_evstdd(DisasContext
*ctx
, TCGv addr
)
7220 #if defined(TARGET_PPC64)
7221 gen_qemu_st64(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7223 TCGv_i64 t0
= tcg_temp_new_i64();
7224 tcg_gen_concat_i32_i64(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gprh
[rS(ctx
->opcode
)]);
7225 gen_qemu_st64(ctx
, t0
, addr
);
7226 tcg_temp_free_i64(t0
);
7230 static always_inline
void gen_op_evstdw(DisasContext
*ctx
, TCGv addr
)
7232 #if defined(TARGET_PPC64)
7233 TCGv t0
= tcg_temp_new();
7234 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7235 gen_qemu_st32(ctx
, t0
, addr
);
7238 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7240 gen_addr_add(ctx
, addr
, addr
, 4);
7241 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7244 static always_inline
void gen_op_evstdh(DisasContext
*ctx
, TCGv addr
)
7246 TCGv t0
= tcg_temp_new();
7247 #if defined(TARGET_PPC64)
7248 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
7250 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
7252 gen_qemu_st16(ctx
, t0
, addr
);
7253 gen_addr_add(ctx
, addr
, addr
, 2);
7254 #if defined(TARGET_PPC64)
7255 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7256 gen_qemu_st16(ctx
, t0
, addr
);
7258 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7260 gen_addr_add(ctx
, addr
, addr
, 2);
7261 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
7262 gen_qemu_st16(ctx
, t0
, addr
);
7264 gen_addr_add(ctx
, addr
, addr
, 2);
7265 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7268 static always_inline
void gen_op_evstwhe(DisasContext
*ctx
, TCGv addr
)
7270 TCGv t0
= tcg_temp_new();
7271 #if defined(TARGET_PPC64)
7272 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
7274 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
7276 gen_qemu_st16(ctx
, t0
, addr
);
7277 gen_addr_add(ctx
, addr
, addr
, 2);
7278 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
7279 gen_qemu_st16(ctx
, t0
, addr
);
7283 static always_inline
void gen_op_evstwho(DisasContext
*ctx
, TCGv addr
)
7285 #if defined(TARGET_PPC64)
7286 TCGv t0
= tcg_temp_new();
7287 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7288 gen_qemu_st16(ctx
, t0
, addr
);
7291 gen_qemu_st16(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7293 gen_addr_add(ctx
, addr
, addr
, 2);
7294 gen_qemu_st16(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7297 static always_inline
void gen_op_evstwwe(DisasContext
*ctx
, TCGv addr
)
7299 #if defined(TARGET_PPC64)
7300 TCGv t0
= tcg_temp_new();
7301 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
7302 gen_qemu_st32(ctx
, t0
, addr
);
7305 gen_qemu_st32(ctx
, cpu_gprh
[rS(ctx
->opcode
)], addr
);
7309 static always_inline
void gen_op_evstwwo(DisasContext
*ctx
, TCGv addr
)
7311 gen_qemu_st32(ctx
, cpu_gpr
[rS(ctx
->opcode
)], addr
);
7314 #define GEN_SPEOP_LDST(name, opc2, sh) \
7315 GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE) \
7318 if (unlikely(!ctx->spe_enabled)) { \
7319 gen_exception(ctx, POWERPC_EXCP_APU); \
7322 gen_set_access_type(ctx, ACCESS_INT); \
7323 t0 = tcg_temp_new(); \
7324 if (Rc(ctx->opcode)) { \
7325 gen_addr_spe_imm_index(ctx, t0, sh); \
7327 gen_addr_reg_index(ctx, t0); \
7329 gen_op_##name(ctx, t0); \
7330 tcg_temp_free(t0); \
7333 GEN_SPEOP_LDST(evldd
, 0x00, 3);
7334 GEN_SPEOP_LDST(evldw
, 0x01, 3);
7335 GEN_SPEOP_LDST(evldh
, 0x02, 3);
7336 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1);
7337 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1);
7338 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1);
7339 GEN_SPEOP_LDST(evlwhe
, 0x08, 2);
7340 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2);
7341 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2);
7342 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2);
7343 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2);
7345 GEN_SPEOP_LDST(evstdd
, 0x10, 3);
7346 GEN_SPEOP_LDST(evstdw
, 0x11, 3);
7347 GEN_SPEOP_LDST(evstdh
, 0x12, 3);
7348 GEN_SPEOP_LDST(evstwhe
, 0x18, 2);
7349 GEN_SPEOP_LDST(evstwho
, 0x1A, 2);
7350 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2);
7351 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2);
7353 /* Multiply and add - TODO */
7355 GEN_SPE(speundef
, evmhessf
, 0x01, 0x10, 0x00000000, PPC_SPE
);
7356 GEN_SPE(speundef
, evmhossf
, 0x03, 0x10, 0x00000000, PPC_SPE
);
7357 GEN_SPE(evmheumi
, evmhesmi
, 0x04, 0x10, 0x00000000, PPC_SPE
);
7358 GEN_SPE(speundef
, evmhesmf
, 0x05, 0x10, 0x00000000, PPC_SPE
);
7359 GEN_SPE(evmhoumi
, evmhosmi
, 0x06, 0x10, 0x00000000, PPC_SPE
);
7360 GEN_SPE(speundef
, evmhosmf
, 0x07, 0x10, 0x00000000, PPC_SPE
);
7361 GEN_SPE(speundef
, evmhessfa
, 0x11, 0x10, 0x00000000, PPC_SPE
);
7362 GEN_SPE(speundef
, evmhossfa
, 0x13, 0x10, 0x00000000, PPC_SPE
);
7363 GEN_SPE(evmheumia
, evmhesmia
, 0x14, 0x10, 0x00000000, PPC_SPE
);
7364 GEN_SPE(speundef
, evmhesmfa
, 0x15, 0x10, 0x00000000, PPC_SPE
);
7365 GEN_SPE(evmhoumia
, evmhosmia
, 0x16, 0x10, 0x00000000, PPC_SPE
);
7366 GEN_SPE(speundef
, evmhosmfa
, 0x17, 0x10, 0x00000000, PPC_SPE
);
7368 GEN_SPE(speundef
, evmwhssf
, 0x03, 0x11, 0x00000000, PPC_SPE
);
7369 GEN_SPE(evmwlumi
, speundef
, 0x04, 0x11, 0x00000000, PPC_SPE
);
7370 GEN_SPE(evmwhumi
, evmwhsmi
, 0x06, 0x11, 0x00000000, PPC_SPE
);
7371 GEN_SPE(speundef
, evmwhsmf
, 0x07, 0x11, 0x00000000, PPC_SPE
);
7372 GEN_SPE(speundef
, evmwssf
, 0x09, 0x11, 0x00000000, PPC_SPE
);
7373 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, PPC_SPE
);
7374 GEN_SPE(speundef
, evmwsmf
, 0x0D, 0x11, 0x00000000, PPC_SPE
);
7375 GEN_SPE(speundef
, evmwhssfa
, 0x13, 0x11, 0x00000000, PPC_SPE
);
7376 GEN_SPE(evmwlumia
, speundef
, 0x14, 0x11, 0x00000000, PPC_SPE
);
7377 GEN_SPE(evmwhumia
, evmwhsmia
, 0x16, 0x11, 0x00000000, PPC_SPE
);
7378 GEN_SPE(speundef
, evmwhsmfa
, 0x17, 0x11, 0x00000000, PPC_SPE
);
7379 GEN_SPE(speundef
, evmwssfa
, 0x19, 0x11, 0x00000000, PPC_SPE
);
7380 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, PPC_SPE
);
7381 GEN_SPE(speundef
, evmwsmfa
, 0x1D, 0x11, 0x00000000, PPC_SPE
);
7383 GEN_SPE(evadduiaaw
, evaddsiaaw
, 0x00, 0x13, 0x0000F800, PPC_SPE
);
7384 GEN_SPE(evsubfusiaaw
, evsubfssiaaw
, 0x01, 0x13, 0x0000F800, PPC_SPE
);
7385 GEN_SPE(evaddumiaaw
, evaddsmiaaw
, 0x04, 0x13, 0x0000F800, PPC_SPE
);
7386 GEN_SPE(evsubfumiaaw
, evsubfsmiaaw
, 0x05, 0x13, 0x0000F800, PPC_SPE
);
7387 GEN_SPE(evdivws
, evdivwu
, 0x06, 0x13, 0x00000000, PPC_SPE
);
7388 GEN_SPE(evmra
, speundef
, 0x07, 0x13, 0x0000F800, PPC_SPE
);
7390 GEN_SPE(evmheusiaaw
, evmhessiaaw
, 0x00, 0x14, 0x00000000, PPC_SPE
);
7391 GEN_SPE(speundef
, evmhessfaaw
, 0x01, 0x14, 0x00000000, PPC_SPE
);
7392 GEN_SPE(evmhousiaaw
, evmhossiaaw
, 0x02, 0x14, 0x00000000, PPC_SPE
);
7393 GEN_SPE(speundef
, evmhossfaaw
, 0x03, 0x14, 0x00000000, PPC_SPE
);
7394 GEN_SPE(evmheumiaaw
, evmhesmiaaw
, 0x04, 0x14, 0x00000000, PPC_SPE
);
7395 GEN_SPE(speundef
, evmhesmfaaw
, 0x05, 0x14, 0x00000000, PPC_SPE
);
7396 GEN_SPE(evmhoumiaaw
, evmhosmiaaw
, 0x06, 0x14, 0x00000000, PPC_SPE
);
7397 GEN_SPE(speundef
, evmhosmfaaw
, 0x07, 0x14, 0x00000000, PPC_SPE
);
7398 GEN_SPE(evmhegumiaa
, evmhegsmiaa
, 0x14, 0x14, 0x00000000, PPC_SPE
);
7399 GEN_SPE(speundef
, evmhegsmfaa
, 0x15, 0x14, 0x00000000, PPC_SPE
);
7400 GEN_SPE(evmhogumiaa
, evmhogsmiaa
, 0x16, 0x14, 0x00000000, PPC_SPE
);
7401 GEN_SPE(speundef
, evmhogsmfaa
, 0x17, 0x14, 0x00000000, PPC_SPE
);
7403 GEN_SPE(evmwlusiaaw
, evmwlssiaaw
, 0x00, 0x15, 0x00000000, PPC_SPE
);
7404 GEN_SPE(evmwlumiaaw
, evmwlsmiaaw
, 0x04, 0x15, 0x00000000, PPC_SPE
);
7405 GEN_SPE(speundef
, evmwssfaa
, 0x09, 0x15, 0x00000000, PPC_SPE
);
7406 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, PPC_SPE
);
7407 GEN_SPE(speundef
, evmwsmfaa
, 0x0D, 0x15, 0x00000000, PPC_SPE
);
7409 GEN_SPE(evmheusianw
, evmhessianw
, 0x00, 0x16, 0x00000000, PPC_SPE
);
7410 GEN_SPE(speundef
, evmhessfanw
, 0x01, 0x16, 0x00000000, PPC_SPE
);
7411 GEN_SPE(evmhousianw
, evmhossianw
, 0x02, 0x16, 0x00000000, PPC_SPE
);
7412 GEN_SPE(speundef
, evmhossfanw
, 0x03, 0x16, 0x00000000, PPC_SPE
);
7413 GEN_SPE(evmheumianw
, evmhesmianw
, 0x04, 0x16, 0x00000000, PPC_SPE
);
7414 GEN_SPE(speundef
, evmhesmfanw
, 0x05, 0x16, 0x00000000, PPC_SPE
);
7415 GEN_SPE(evmhoumianw
, evmhosmianw
, 0x06, 0x16, 0x00000000, PPC_SPE
);
7416 GEN_SPE(speundef
, evmhosmfanw
, 0x07, 0x16, 0x00000000, PPC_SPE
);
7417 GEN_SPE(evmhegumian
, evmhegsmian
, 0x14, 0x16, 0x00000000, PPC_SPE
);
7418 GEN_SPE(speundef
, evmhegsmfan
, 0x15, 0x16, 0x00000000, PPC_SPE
);
7419 GEN_SPE(evmhigumian
, evmhigsmian
, 0x16, 0x16, 0x00000000, PPC_SPE
);
7420 GEN_SPE(speundef
, evmhogsmfan
, 0x17, 0x16, 0x00000000, PPC_SPE
);
7422 GEN_SPE(evmwlusianw
, evmwlssianw
, 0x00, 0x17, 0x00000000, PPC_SPE
);
7423 GEN_SPE(evmwlumianw
, evmwlsmianw
, 0x04, 0x17, 0x00000000, PPC_SPE
);
7424 GEN_SPE(speundef
, evmwssfan
, 0x09, 0x17, 0x00000000, PPC_SPE
);
7425 GEN_SPE(evmwumian
, evmwsmian
, 0x0C, 0x17, 0x00000000, PPC_SPE
);
7426 GEN_SPE(speundef
, evmwsmfan
, 0x0D, 0x17, 0x00000000, PPC_SPE
);
7429 /*** SPE floating-point extension ***/
7430 #if defined(TARGET_PPC64)
7431 #define GEN_SPEFPUOP_CONV_32_32(name) \
7432 static always_inline void gen_##name (DisasContext *ctx) \
7436 t0 = tcg_temp_new_i32(); \
7437 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
7438 gen_helper_##name(t0, t0); \
7439 t1 = tcg_temp_new(); \
7440 tcg_gen_extu_i32_tl(t1, t0); \
7441 tcg_temp_free_i32(t0); \
7442 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
7443 0xFFFFFFFF00000000ULL); \
7444 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
7445 tcg_temp_free(t1); \
7447 #define GEN_SPEFPUOP_CONV_32_64(name) \
7448 static always_inline void gen_##name (DisasContext *ctx) \
7452 t0 = tcg_temp_new_i32(); \
7453 gen_helper_##name(t0, cpu_gpr[rB(ctx->opcode)]); \
7454 t1 = tcg_temp_new(); \
7455 tcg_gen_extu_i32_tl(t1, t0); \
7456 tcg_temp_free_i32(t0); \
7457 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
7458 0xFFFFFFFF00000000ULL); \
7459 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
7460 tcg_temp_free(t1); \
7462 #define GEN_SPEFPUOP_CONV_64_32(name) \
7463 static always_inline void gen_##name (DisasContext *ctx) \
7465 TCGv_i32 t0 = tcg_temp_new_i32(); \
7466 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
7467 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], t0); \
7468 tcg_temp_free_i32(t0); \
7470 #define GEN_SPEFPUOP_CONV_64_64(name) \
7471 static always_inline void gen_##name (DisasContext *ctx) \
7473 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
7475 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
7476 static always_inline void gen_##name (DisasContext *ctx) \
7480 if (unlikely(!ctx->spe_enabled)) { \
7481 gen_exception(ctx, POWERPC_EXCP_APU); \
7484 t0 = tcg_temp_new_i32(); \
7485 t1 = tcg_temp_new_i32(); \
7486 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7487 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
7488 gen_helper_##name(t0, t0, t1); \
7489 tcg_temp_free_i32(t1); \
7490 t2 = tcg_temp_new(); \
7491 tcg_gen_extu_i32_tl(t2, t0); \
7492 tcg_temp_free_i32(t0); \
7493 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
7494 0xFFFFFFFF00000000ULL); \
7495 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \
7496 tcg_temp_free(t2); \
7498 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
7499 static always_inline void gen_##name (DisasContext *ctx) \
7501 if (unlikely(!ctx->spe_enabled)) { \
7502 gen_exception(ctx, POWERPC_EXCP_APU); \
7505 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
7506 cpu_gpr[rB(ctx->opcode)]); \
7508 #define GEN_SPEFPUOP_COMP_32(name) \
7509 static always_inline void gen_##name (DisasContext *ctx) \
7512 if (unlikely(!ctx->spe_enabled)) { \
7513 gen_exception(ctx, POWERPC_EXCP_APU); \
7516 t0 = tcg_temp_new_i32(); \
7517 t1 = tcg_temp_new_i32(); \
7518 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
7519 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
7520 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], t0, t1); \
7521 tcg_temp_free_i32(t0); \
7522 tcg_temp_free_i32(t1); \
7524 #define GEN_SPEFPUOP_COMP_64(name) \
7525 static always_inline void gen_##name (DisasContext *ctx) \
7527 if (unlikely(!ctx->spe_enabled)) { \
7528 gen_exception(ctx, POWERPC_EXCP_APU); \
7531 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
7532 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
7535 #define GEN_SPEFPUOP_CONV_32_32(name) \
7536 static always_inline void gen_##name (DisasContext *ctx) \
7538 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
7540 #define GEN_SPEFPUOP_CONV_32_64(name) \
7541 static always_inline void gen_##name (DisasContext *ctx) \
7543 TCGv_i64 t0 = tcg_temp_new_i64(); \
7544 gen_load_gpr64(t0, rB(ctx->opcode)); \
7545 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], t0); \
7546 tcg_temp_free_i64(t0); \
7548 #define GEN_SPEFPUOP_CONV_64_32(name) \
7549 static always_inline void gen_##name (DisasContext *ctx) \
7551 TCGv_i64 t0 = tcg_temp_new_i64(); \
7552 gen_helper_##name(t0, cpu_gpr[rB(ctx->opcode)]); \
7553 gen_store_gpr64(rD(ctx->opcode), t0); \
7554 tcg_temp_free_i64(t0); \
7556 #define GEN_SPEFPUOP_CONV_64_64(name) \
7557 static always_inline void gen_##name (DisasContext *ctx) \
7559 TCGv_i64 t0 = tcg_temp_new_i64(); \
7560 gen_load_gpr64(t0, rB(ctx->opcode)); \
7561 gen_helper_##name(t0, t0); \
7562 gen_store_gpr64(rD(ctx->opcode), t0); \
7563 tcg_temp_free_i64(t0); \
7565 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
7566 static always_inline void gen_##name (DisasContext *ctx) \
7568 if (unlikely(!ctx->spe_enabled)) { \
7569 gen_exception(ctx, POWERPC_EXCP_APU); \
7572 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], \
7573 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
7575 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
7576 static always_inline void gen_##name (DisasContext *ctx) \
7579 if (unlikely(!ctx->spe_enabled)) { \
7580 gen_exception(ctx, POWERPC_EXCP_APU); \
7583 t0 = tcg_temp_new_i64(); \
7584 t1 = tcg_temp_new_i64(); \
7585 gen_load_gpr64(t0, rA(ctx->opcode)); \
7586 gen_load_gpr64(t1, rB(ctx->opcode)); \
7587 gen_helper_##name(t0, t0, t1); \
7588 gen_store_gpr64(rD(ctx->opcode), t0); \
7589 tcg_temp_free_i64(t0); \
7590 tcg_temp_free_i64(t1); \
7592 #define GEN_SPEFPUOP_COMP_32(name) \
7593 static always_inline void gen_##name (DisasContext *ctx) \
7595 if (unlikely(!ctx->spe_enabled)) { \
7596 gen_exception(ctx, POWERPC_EXCP_APU); \
7599 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
7600 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
7602 #define GEN_SPEFPUOP_COMP_64(name) \
7603 static always_inline void gen_##name (DisasContext *ctx) \
7606 if (unlikely(!ctx->spe_enabled)) { \
7607 gen_exception(ctx, POWERPC_EXCP_APU); \
7610 t0 = tcg_temp_new_i64(); \
7611 t1 = tcg_temp_new_i64(); \
7612 gen_load_gpr64(t0, rA(ctx->opcode)); \
7613 gen_load_gpr64(t1, rB(ctx->opcode)); \
7614 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], t0, t1); \
7615 tcg_temp_free_i64(t0); \
7616 tcg_temp_free_i64(t1); \
7620 /* Single precision floating-point vectors operations */
7622 GEN_SPEFPUOP_ARITH2_64_64(evfsadd
);
7623 GEN_SPEFPUOP_ARITH2_64_64(evfssub
);
7624 GEN_SPEFPUOP_ARITH2_64_64(evfsmul
);
7625 GEN_SPEFPUOP_ARITH2_64_64(evfsdiv
);
7626 static always_inline
void gen_evfsabs (DisasContext
*ctx
)
7628 if (unlikely(!ctx
->spe_enabled
)) {
7629 gen_exception(ctx
, POWERPC_EXCP_APU
);
7632 #if defined(TARGET_PPC64)
7633 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000080000000LL
);
7635 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x80000000);
7636 tcg_gen_andi_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
7639 static always_inline
void gen_evfsnabs (DisasContext
*ctx
)
7641 if (unlikely(!ctx
->spe_enabled
)) {
7642 gen_exception(ctx
, POWERPC_EXCP_APU
);
7645 #if defined(TARGET_PPC64)
7646 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
7648 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
7649 tcg_gen_ori_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
7652 static always_inline
void gen_evfsneg (DisasContext
*ctx
)
7654 if (unlikely(!ctx
->spe_enabled
)) {
7655 gen_exception(ctx
, POWERPC_EXCP_APU
);
7658 #if defined(TARGET_PPC64)
7659 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
7661 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
7662 tcg_gen_xori_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
7667 GEN_SPEFPUOP_CONV_64_64(evfscfui
);
7668 GEN_SPEFPUOP_CONV_64_64(evfscfsi
);
7669 GEN_SPEFPUOP_CONV_64_64(evfscfuf
);
7670 GEN_SPEFPUOP_CONV_64_64(evfscfsf
);
7671 GEN_SPEFPUOP_CONV_64_64(evfsctui
);
7672 GEN_SPEFPUOP_CONV_64_64(evfsctsi
);
7673 GEN_SPEFPUOP_CONV_64_64(evfsctuf
);
7674 GEN_SPEFPUOP_CONV_64_64(evfsctsf
);
7675 GEN_SPEFPUOP_CONV_64_64(evfsctuiz
);
7676 GEN_SPEFPUOP_CONV_64_64(evfsctsiz
);
7679 GEN_SPEFPUOP_COMP_64(evfscmpgt
);
7680 GEN_SPEFPUOP_COMP_64(evfscmplt
);
7681 GEN_SPEFPUOP_COMP_64(evfscmpeq
);
7682 GEN_SPEFPUOP_COMP_64(evfststgt
);
7683 GEN_SPEFPUOP_COMP_64(evfststlt
);
7684 GEN_SPEFPUOP_COMP_64(evfststeq
);
7686 /* Opcodes definitions */
7687 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, PPC_SPEFPU
); //
7688 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, PPC_SPEFPU
); //
7689 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, PPC_SPEFPU
); //
7690 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, PPC_SPEFPU
); //
7691 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, PPC_SPEFPU
); //
7692 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, PPC_SPEFPU
); //
7693 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, PPC_SPEFPU
); //
7694 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, PPC_SPEFPU
); //
7695 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, PPC_SPEFPU
); //
7696 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, PPC_SPEFPU
); //
7697 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, PPC_SPEFPU
); //
7698 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, PPC_SPEFPU
); //
7699 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, PPC_SPEFPU
); //
7700 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, PPC_SPEFPU
); //
7702 /* Single precision floating-point operations */
7704 GEN_SPEFPUOP_ARITH2_32_32(efsadd
);
7705 GEN_SPEFPUOP_ARITH2_32_32(efssub
);
7706 GEN_SPEFPUOP_ARITH2_32_32(efsmul
);
7707 GEN_SPEFPUOP_ARITH2_32_32(efsdiv
);
7708 static always_inline
void gen_efsabs (DisasContext
*ctx
)
7710 if (unlikely(!ctx
->spe_enabled
)) {
7711 gen_exception(ctx
, POWERPC_EXCP_APU
);
7714 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], (target_long
)~0x80000000LL
);
7716 static always_inline
void gen_efsnabs (DisasContext
*ctx
)
7718 if (unlikely(!ctx
->spe_enabled
)) {
7719 gen_exception(ctx
, POWERPC_EXCP_APU
);
7722 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
7724 static always_inline
void gen_efsneg (DisasContext
*ctx
)
7726 if (unlikely(!ctx
->spe_enabled
)) {
7727 gen_exception(ctx
, POWERPC_EXCP_APU
);
7730 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
7734 GEN_SPEFPUOP_CONV_32_32(efscfui
);
7735 GEN_SPEFPUOP_CONV_32_32(efscfsi
);
7736 GEN_SPEFPUOP_CONV_32_32(efscfuf
);
7737 GEN_SPEFPUOP_CONV_32_32(efscfsf
);
7738 GEN_SPEFPUOP_CONV_32_32(efsctui
);
7739 GEN_SPEFPUOP_CONV_32_32(efsctsi
);
7740 GEN_SPEFPUOP_CONV_32_32(efsctuf
);
7741 GEN_SPEFPUOP_CONV_32_32(efsctsf
);
7742 GEN_SPEFPUOP_CONV_32_32(efsctuiz
);
7743 GEN_SPEFPUOP_CONV_32_32(efsctsiz
);
7744 GEN_SPEFPUOP_CONV_32_64(efscfd
);
7747 GEN_SPEFPUOP_COMP_32(efscmpgt
);
7748 GEN_SPEFPUOP_COMP_32(efscmplt
);
7749 GEN_SPEFPUOP_COMP_32(efscmpeq
);
7750 GEN_SPEFPUOP_COMP_32(efststgt
);
7751 GEN_SPEFPUOP_COMP_32(efststlt
);
7752 GEN_SPEFPUOP_COMP_32(efststeq
);
7754 /* Opcodes definitions */
7755 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, PPC_SPEFPU
); //
7756 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, PPC_SPEFPU
); //
7757 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, PPC_SPEFPU
); //
7758 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, PPC_SPEFPU
); //
7759 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, PPC_SPEFPU
); //
7760 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, PPC_SPEFPU
); //
7761 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, PPC_SPEFPU
); //
7762 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, PPC_SPEFPU
); //
7763 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, PPC_SPEFPU
); //
7764 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, PPC_SPEFPU
); //
7765 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, PPC_SPEFPU
); //
7766 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, PPC_SPEFPU
); //
7767 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, PPC_SPEFPU
); //
7768 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, PPC_SPEFPU
); //
7770 /* Double precision floating-point operations */
7772 GEN_SPEFPUOP_ARITH2_64_64(efdadd
);
7773 GEN_SPEFPUOP_ARITH2_64_64(efdsub
);
7774 GEN_SPEFPUOP_ARITH2_64_64(efdmul
);
7775 GEN_SPEFPUOP_ARITH2_64_64(efddiv
);
7776 static always_inline
void gen_efdabs (DisasContext
*ctx
)
7778 if (unlikely(!ctx
->spe_enabled
)) {
7779 gen_exception(ctx
, POWERPC_EXCP_APU
);
7782 #if defined(TARGET_PPC64)
7783 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000000000000LL
);
7785 tcg_gen_andi_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
7788 static always_inline
void gen_efdnabs (DisasContext
*ctx
)
7790 if (unlikely(!ctx
->spe_enabled
)) {
7791 gen_exception(ctx
, POWERPC_EXCP_APU
);
7794 #if defined(TARGET_PPC64)
7795 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
7797 tcg_gen_ori_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
7800 static always_inline
void gen_efdneg (DisasContext
*ctx
)
7802 if (unlikely(!ctx
->spe_enabled
)) {
7803 gen_exception(ctx
, POWERPC_EXCP_APU
);
7806 #if defined(TARGET_PPC64)
7807 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
7809 tcg_gen_xori_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
7814 GEN_SPEFPUOP_CONV_64_32(efdcfui
);
7815 GEN_SPEFPUOP_CONV_64_32(efdcfsi
);
7816 GEN_SPEFPUOP_CONV_64_32(efdcfuf
);
7817 GEN_SPEFPUOP_CONV_64_32(efdcfsf
);
7818 GEN_SPEFPUOP_CONV_32_64(efdctui
);
7819 GEN_SPEFPUOP_CONV_32_64(efdctsi
);
7820 GEN_SPEFPUOP_CONV_32_64(efdctuf
);
7821 GEN_SPEFPUOP_CONV_32_64(efdctsf
);
7822 GEN_SPEFPUOP_CONV_32_64(efdctuiz
);
7823 GEN_SPEFPUOP_CONV_32_64(efdctsiz
);
7824 GEN_SPEFPUOP_CONV_64_32(efdcfs
);
7825 GEN_SPEFPUOP_CONV_64_64(efdcfuid
);
7826 GEN_SPEFPUOP_CONV_64_64(efdcfsid
);
7827 GEN_SPEFPUOP_CONV_64_64(efdctuidz
);
7828 GEN_SPEFPUOP_CONV_64_64(efdctsidz
);
7831 GEN_SPEFPUOP_COMP_64(efdcmpgt
);
7832 GEN_SPEFPUOP_COMP_64(efdcmplt
);
7833 GEN_SPEFPUOP_COMP_64(efdcmpeq
);
7834 GEN_SPEFPUOP_COMP_64(efdtstgt
);
7835 GEN_SPEFPUOP_COMP_64(efdtstlt
);
7836 GEN_SPEFPUOP_COMP_64(efdtsteq
);
7838 /* Opcodes definitions */
7839 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, PPC_SPEFPU
); //
7840 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, PPC_SPEFPU
); //
7841 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, PPC_SPEFPU
); //
7842 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, PPC_SPEFPU
); //
7843 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, PPC_SPEFPU
); //
7844 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, PPC_SPEFPU
); //
7845 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, PPC_SPEFPU
); //
7846 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, PPC_SPEFPU
); //
7847 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, PPC_SPEFPU
); //
7848 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, PPC_SPEFPU
); //
7849 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, PPC_SPEFPU
); //
7850 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, PPC_SPEFPU
); //
7851 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, PPC_SPEFPU
); //
7852 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, PPC_SPEFPU
); //
7853 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, PPC_SPEFPU
); //
7854 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, PPC_SPEFPU
); //
7856 /* End opcode list */
7857 GEN_OPCODE_MARK(end
);
7859 #include "translate_init.c"
7860 #include "helper_regs.h"
7862 /*****************************************************************************/
7863 /* Misc PowerPC helpers */
7864 void cpu_dump_state (CPUState
*env
, FILE *f
,
7865 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
7873 cpu_fprintf(f
, "NIP " ADDRX
" LR " ADDRX
" CTR " ADDRX
" XER %08x\n",
7874 env
->nip
, env
->lr
, env
->ctr
, env
->xer
);
7875 cpu_fprintf(f
, "MSR " ADDRX
" HID0 " ADDRX
" HF " ADDRX
" idx %d\n",
7876 env
->msr
, env
->spr
[SPR_HID0
], env
->hflags
, env
->mmu_idx
);
7877 #if !defined(NO_TIMER_DUMP)
7878 cpu_fprintf(f
, "TB %08x %08x "
7879 #if !defined(CONFIG_USER_ONLY)
7883 cpu_ppc_load_tbu(env
), cpu_ppc_load_tbl(env
)
7884 #if !defined(CONFIG_USER_ONLY)
7885 , cpu_ppc_load_decr(env
)
7889 for (i
= 0; i
< 32; i
++) {
7890 if ((i
& (RGPL
- 1)) == 0)
7891 cpu_fprintf(f
, "GPR%02d", i
);
7892 cpu_fprintf(f
, " " REGX
, ppc_dump_gpr(env
, i
));
7893 if ((i
& (RGPL
- 1)) == (RGPL
- 1))
7894 cpu_fprintf(f
, "\n");
7896 cpu_fprintf(f
, "CR ");
7897 for (i
= 0; i
< 8; i
++)
7898 cpu_fprintf(f
, "%01x", env
->crf
[i
]);
7899 cpu_fprintf(f
, " [");
7900 for (i
= 0; i
< 8; i
++) {
7902 if (env
->crf
[i
] & 0x08)
7904 else if (env
->crf
[i
] & 0x04)
7906 else if (env
->crf
[i
] & 0x02)
7908 cpu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
7910 cpu_fprintf(f
, " ] RES " ADDRX
"\n", env
->reserve
);
7911 for (i
= 0; i
< 32; i
++) {
7912 if ((i
& (RFPL
- 1)) == 0)
7913 cpu_fprintf(f
, "FPR%02d", i
);
7914 cpu_fprintf(f
, " %016" PRIx64
, *((uint64_t *)&env
->fpr
[i
]));
7915 if ((i
& (RFPL
- 1)) == (RFPL
- 1))
7916 cpu_fprintf(f
, "\n");
7918 cpu_fprintf(f
, "FPSCR %08x\n", env
->fpscr
);
7919 #if !defined(CONFIG_USER_ONLY)
7920 cpu_fprintf(f
, "SRR0 " ADDRX
" SRR1 " ADDRX
" SDR1 " ADDRX
"\n",
7921 env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
], env
->sdr1
);
7928 void cpu_dump_statistics (CPUState
*env
, FILE*f
,
7929 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
7932 #if defined(DO_PPC_STATISTICS)
7933 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
7937 for (op1
= 0; op1
< 64; op1
++) {
7939 if (is_indirect_opcode(handler
)) {
7940 t2
= ind_table(handler
);
7941 for (op2
= 0; op2
< 32; op2
++) {
7943 if (is_indirect_opcode(handler
)) {
7944 t3
= ind_table(handler
);
7945 for (op3
= 0; op3
< 32; op3
++) {
7947 if (handler
->count
== 0)
7949 cpu_fprintf(f
, "%02x %02x %02x (%02x %04d) %16s: "
7951 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
7953 handler
->count
, handler
->count
);
7956 if (handler
->count
== 0)
7958 cpu_fprintf(f
, "%02x %02x (%02x %04d) %16s: "
7960 op1
, op2
, op1
, op2
, handler
->oname
,
7961 handler
->count
, handler
->count
);
7965 if (handler
->count
== 0)
7967 cpu_fprintf(f
, "%02x (%02x ) %16s: %016llx %lld\n",
7968 op1
, op1
, handler
->oname
,
7969 handler
->count
, handler
->count
);
7975 /*****************************************************************************/
7976 static always_inline
void gen_intermediate_code_internal (CPUState
*env
,
7977 TranslationBlock
*tb
,
7980 DisasContext ctx
, *ctxp
= &ctx
;
7981 opc_handler_t
**table
, *handler
;
7982 target_ulong pc_start
;
7983 uint16_t *gen_opc_end
;
7990 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
7993 ctx
.exception
= POWERPC_EXCP_NONE
;
7994 ctx
.spr_cb
= env
->spr_cb
;
7995 ctx
.mem_idx
= env
->mmu_idx
;
7996 ctx
.access_type
= -1;
7997 ctx
.le_mode
= env
->hflags
& (1 << MSR_LE
) ? 1 : 0;
7998 #if defined(TARGET_PPC64)
7999 ctx
.sf_mode
= msr_sf
;
8001 ctx
.fpu_enabled
= msr_fp
;
8002 if ((env
->flags
& POWERPC_FLAG_SPE
) && msr_spe
)
8003 ctx
.spe_enabled
= msr_spe
;
8005 ctx
.spe_enabled
= 0;
8006 if ((env
->flags
& POWERPC_FLAG_VRE
) && msr_vr
)
8007 ctx
.altivec_enabled
= msr_vr
;
8009 ctx
.altivec_enabled
= 0;
8010 if ((env
->flags
& POWERPC_FLAG_SE
) && msr_se
)
8011 ctx
.singlestep_enabled
= CPU_SINGLE_STEP
;
8013 ctx
.singlestep_enabled
= 0;
8014 if ((env
->flags
& POWERPC_FLAG_BE
) && msr_be
)
8015 ctx
.singlestep_enabled
|= CPU_BRANCH_STEP
;
8016 if (unlikely(env
->singlestep_enabled
))
8017 ctx
.singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
8018 #if defined (DO_SINGLE_STEP) && 0
8019 /* Single step trace mode */
8023 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
8025 max_insns
= CF_COUNT_MASK
;
8028 /* Set env in case of segfault during code fetch */
8029 while (ctx
.exception
== POWERPC_EXCP_NONE
&& gen_opc_ptr
< gen_opc_end
) {
8030 if (unlikely(!TAILQ_EMPTY(&env
->breakpoints
))) {
8031 TAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
8032 if (bp
->pc
== ctx
.nip
) {
8033 gen_debug_exception(ctxp
);
8038 if (unlikely(search_pc
)) {
8039 j
= gen_opc_ptr
- gen_opc_buf
;
8043 gen_opc_instr_start
[lj
++] = 0;
8044 gen_opc_pc
[lj
] = ctx
.nip
;
8045 gen_opc_instr_start
[lj
] = 1;
8046 gen_opc_icount
[lj
] = num_insns
;
8049 #if defined PPC_DEBUG_DISAS
8050 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
8051 fprintf(logfile
, "----------------\n");
8052 fprintf(logfile
, "nip=" ADDRX
" super=%d ir=%d\n",
8053 ctx
.nip
, ctx
.mem_idx
, (int)msr_ir
);
8056 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
8058 if (unlikely(ctx
.le_mode
)) {
8059 ctx
.opcode
= bswap32(ldl_code(ctx
.nip
));
8061 ctx
.opcode
= ldl_code(ctx
.nip
);
8063 #if defined PPC_DEBUG_DISAS
8064 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
8065 fprintf(logfile
, "translate opcode %08x (%02x %02x %02x) (%s)\n",
8066 ctx
.opcode
, opc1(ctx
.opcode
), opc2(ctx
.opcode
),
8067 opc3(ctx
.opcode
), little_endian
? "little" : "big");
8071 table
= env
->opcodes
;
8073 handler
= table
[opc1(ctx
.opcode
)];
8074 if (is_indirect_opcode(handler
)) {
8075 table
= ind_table(handler
);
8076 handler
= table
[opc2(ctx
.opcode
)];
8077 if (is_indirect_opcode(handler
)) {
8078 table
= ind_table(handler
);
8079 handler
= table
[opc3(ctx
.opcode
)];
8082 /* Is opcode *REALLY* valid ? */
8083 if (unlikely(handler
->handler
== &gen_invalid
)) {
8084 if (loglevel
!= 0) {
8085 fprintf(logfile
, "invalid/unsupported opcode: "
8086 "%02x - %02x - %02x (%08x) " ADDRX
" %d\n",
8087 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
8088 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
8090 printf("invalid/unsupported opcode: "
8091 "%02x - %02x - %02x (%08x) " ADDRX
" %d\n",
8092 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
8093 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
8096 if (unlikely((ctx
.opcode
& handler
->inval
) != 0)) {
8097 if (loglevel
!= 0) {
8098 fprintf(logfile
, "invalid bits: %08x for opcode: "
8099 "%02x - %02x - %02x (%08x) " ADDRX
"\n",
8100 ctx
.opcode
& handler
->inval
, opc1(ctx
.opcode
),
8101 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
8102 ctx
.opcode
, ctx
.nip
- 4);
8104 printf("invalid bits: %08x for opcode: "
8105 "%02x - %02x - %02x (%08x) " ADDRX
"\n",
8106 ctx
.opcode
& handler
->inval
, opc1(ctx
.opcode
),
8107 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
8108 ctx
.opcode
, ctx
.nip
- 4);
8110 gen_inval_exception(ctxp
, POWERPC_EXCP_INVAL_INVAL
);
8114 (*(handler
->handler
))(&ctx
);
8115 #if defined(DO_PPC_STATISTICS)
8118 /* Check trace mode exceptions */
8119 if (unlikely(ctx
.singlestep_enabled
& CPU_SINGLE_STEP
&&
8120 (ctx
.nip
<= 0x100 || ctx
.nip
> 0xF00) &&
8121 ctx
.exception
!= POWERPC_SYSCALL
&&
8122 ctx
.exception
!= POWERPC_EXCP_TRAP
&&
8123 ctx
.exception
!= POWERPC_EXCP_BRANCH
)) {
8124 gen_exception(ctxp
, POWERPC_EXCP_TRACE
);
8125 } else if (unlikely(((ctx
.nip
& (TARGET_PAGE_SIZE
- 1)) == 0) ||
8126 (env
->singlestep_enabled
) ||
8127 num_insns
>= max_insns
)) {
8128 /* if we reach a page boundary or are single stepping, stop
8133 #if defined (DO_SINGLE_STEP)
8137 if (tb
->cflags
& CF_LAST_IO
)
8139 if (ctx
.exception
== POWERPC_EXCP_NONE
) {
8140 gen_goto_tb(&ctx
, 0, ctx
.nip
);
8141 } else if (ctx
.exception
!= POWERPC_EXCP_BRANCH
) {
8142 if (unlikely(env
->singlestep_enabled
)) {
8143 gen_debug_exception(ctxp
);
8145 /* Generate the return instruction */
8148 gen_icount_end(tb
, num_insns
);
8149 *gen_opc_ptr
= INDEX_op_end
;
8150 if (unlikely(search_pc
)) {
8151 j
= gen_opc_ptr
- gen_opc_buf
;
8154 gen_opc_instr_start
[lj
++] = 0;
8156 tb
->size
= ctx
.nip
- pc_start
;
8157 tb
->icount
= num_insns
;
8159 #if defined(DEBUG_DISAS)
8160 if (loglevel
& CPU_LOG_TB_CPU
) {
8161 fprintf(logfile
, "---------------- excp: %04x\n", ctx
.exception
);
8162 cpu_dump_state(env
, logfile
, fprintf
, 0);
8164 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
8166 flags
= env
->bfd_mach
;
8167 flags
|= ctx
.le_mode
<< 16;
8168 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
8169 target_disas(logfile
, pc_start
, ctx
.nip
- pc_start
, flags
);
8170 fprintf(logfile
, "\n");
8175 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
8177 gen_intermediate_code_internal(env
, tb
, 0);
8180 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
8182 gen_intermediate_code_internal(env
, tb
, 1);
8185 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
8186 unsigned long searched_pc
, int pc_pos
, void *puc
)
8188 env
->nip
= gen_opc_pc
[pc_pos
];