2 * PowerPC emulation for qemu: main translation routines.
4 * Copyright (c) 2003-2007 Jocelyn Mayer
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #include "qemu-common.h"
36 #define CPU_SINGLE_STEP 0x1
37 #define CPU_BRANCH_STEP 0x2
38 #define GDBSTUB_SINGLE_STEP 0x4
40 /* Include definitions for instructions classes and implementations flags */
41 //#define DO_SINGLE_STEP
42 //#define PPC_DEBUG_DISAS
43 //#define DO_PPC_STATISTICS
44 //#define OPTIMIZE_FPRF_UPDATE
46 /*****************************************************************************/
47 /* Code translation helpers */
49 /* global register indexes */
50 static TCGv_ptr cpu_env
;
51 static char cpu_reg_names
[10*3 + 22*4 /* GPR */
52 #if !defined(TARGET_PPC64)
53 + 10*4 + 22*5 /* SPE GPRh */
55 + 10*4 + 22*5 /* FPR */
56 + 2*(10*6 + 22*7) /* AVRh, AVRl */
58 static TCGv cpu_gpr
[32];
59 #if !defined(TARGET_PPC64)
60 static TCGv cpu_gprh
[32];
62 static TCGv_i64 cpu_fpr
[32];
63 static TCGv_i64 cpu_avrh
[32], cpu_avrl
[32];
64 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 /* dyngen register indexes */
76 #include "gen-icount.h"
78 void ppc_translate_init(void)
82 static int done_init
= 0;
87 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
88 #if TARGET_LONG_BITS > HOST_LONG_BITS
89 cpu_T
[0] = tcg_global_mem_new(TCG_AREG0
, offsetof(CPUState
, t0
), "T0");
90 cpu_T
[1] = tcg_global_mem_new(TCG_AREG0
, offsetof(CPUState
, t1
), "T1");
91 cpu_T
[2] = tcg_global_mem_new(TCG_AREG0
, offsetof(CPUState
, t2
), "T2");
93 cpu_T
[0] = tcg_global_reg_new(TCG_AREG1
, "T0");
94 cpu_T
[1] = tcg_global_reg_new(TCG_AREG2
, "T1");
96 /* XXX: This is a temporary workaround for i386.
97 * On i386 qemu_st32 runs out of registers.
98 * The proper fix is to remove cpu_T.
100 cpu_T
[2] = tcg_global_mem_new(TCG_AREG0
, offsetof(CPUState
, t2
), "T2");
102 cpu_T
[2] = tcg_global_reg_new(TCG_AREG3
, "T2");
108 for (i
= 0; i
< 8; i
++) {
109 sprintf(p
, "crf%d", i
);
110 cpu_crf
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
111 offsetof(CPUState
, crf
[i
]), p
);
115 for (i
= 0; i
< 32; i
++) {
116 sprintf(p
, "r%d", i
);
117 cpu_gpr
[i
] = tcg_global_mem_new(TCG_AREG0
,
118 offsetof(CPUState
, gpr
[i
]), p
);
119 p
+= (i
< 10) ? 3 : 4;
120 #if !defined(TARGET_PPC64)
121 sprintf(p
, "r%dH", i
);
122 cpu_gprh
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
123 offsetof(CPUState
, gprh
[i
]), p
);
124 p
+= (i
< 10) ? 4 : 5;
127 sprintf(p
, "fp%d", i
);
128 cpu_fpr
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
129 offsetof(CPUState
, fpr
[i
]), p
);
130 p
+= (i
< 10) ? 4 : 5;
132 sprintf(p
, "avr%dH", i
);
133 #ifdef WORDS_BIGENDIAN
134 cpu_avrh
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
135 offsetof(CPUState
, avr
[i
].u64
[0]), p
);
137 cpu_avrh
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
138 offsetof(CPUState
, avr
[i
].u64
[1]), p
);
140 p
+= (i
< 10) ? 6 : 7;
142 sprintf(p
, "avr%dL", i
);
143 #ifdef WORDS_BIGENDIAN
144 cpu_avrl
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
145 offsetof(CPUState
, avr
[i
].u64
[1]), p
);
147 cpu_avrl
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
148 offsetof(CPUState
, avr
[i
].u64
[0]), p
);
150 p
+= (i
< 10) ? 6 : 7;
153 cpu_nip
= tcg_global_mem_new(TCG_AREG0
,
154 offsetof(CPUState
, nip
), "nip");
156 cpu_ctr
= tcg_global_mem_new(TCG_AREG0
,
157 offsetof(CPUState
, ctr
), "ctr");
159 cpu_lr
= tcg_global_mem_new(TCG_AREG0
,
160 offsetof(CPUState
, lr
), "lr");
162 cpu_xer
= tcg_global_mem_new(TCG_AREG0
,
163 offsetof(CPUState
, xer
), "xer");
165 cpu_reserve
= tcg_global_mem_new(TCG_AREG0
,
166 offsetof(CPUState
, reserve
), "reserve");
168 cpu_fpscr
= tcg_global_mem_new_i32(TCG_AREG0
,
169 offsetof(CPUState
, fpscr
), "fpscr");
171 cpu_access_type
= tcg_global_mem_new_i32(TCG_AREG0
,
172 offsetof(CPUState
, access_type
), "access_type");
174 /* register helpers */
181 #if defined(OPTIMIZE_FPRF_UPDATE)
182 static uint16_t *gen_fprf_buf
[OPC_BUF_SIZE
];
183 static uint16_t **gen_fprf_ptr
;
186 /* internal defines */
187 typedef struct DisasContext
{
188 struct TranslationBlock
*tb
;
192 /* Routine used to access memory */
194 /* Translation flags */
195 #if !defined(CONFIG_USER_ONLY)
198 #if defined(TARGET_PPC64)
204 ppc_spr_t
*spr_cb
; /* Needed to check rights for mfspr/mtspr */
205 int singlestep_enabled
;
208 struct opc_handler_t
{
211 /* instruction type */
214 void (*handler
)(DisasContext
*ctx
);
215 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
218 #if defined(DO_PPC_STATISTICS)
223 static always_inline
void gen_reset_fpstatus (void)
225 #ifdef CONFIG_SOFTFLOAT
226 gen_op_reset_fpstatus();
230 static always_inline
void gen_compute_fprf (TCGv_i64 arg
, int set_fprf
, int set_rc
)
232 TCGv_i32 t0
= tcg_temp_new_i32();
235 /* This case might be optimized later */
236 #if defined(OPTIMIZE_FPRF_UPDATE)
237 *gen_fprf_ptr
++ = gen_opc_ptr
;
239 tcg_gen_movi_i32(t0
, 1);
240 gen_helper_compute_fprf(t0
, arg
, t0
);
241 if (unlikely(set_rc
)) {
242 tcg_gen_mov_i32(cpu_crf
[1], t0
);
244 gen_helper_float_check_status();
245 } else if (unlikely(set_rc
)) {
246 /* We always need to compute fpcc */
247 tcg_gen_movi_i32(t0
, 0);
248 gen_helper_compute_fprf(t0
, arg
, t0
);
249 tcg_gen_mov_i32(cpu_crf
[1], t0
);
251 gen_helper_float_check_status();
254 tcg_temp_free_i32(t0
);
257 static always_inline
void gen_optimize_fprf (void)
259 #if defined(OPTIMIZE_FPRF_UPDATE)
262 for (ptr
= gen_fprf_buf
; ptr
!= (gen_fprf_ptr
- 1); ptr
++)
263 *ptr
= INDEX_op_nop1
;
264 gen_fprf_ptr
= gen_fprf_buf
;
268 static always_inline
void gen_set_access_type(int access_type
)
270 tcg_gen_movi_i32(cpu_access_type
, access_type
);
273 static always_inline
void gen_update_nip (DisasContext
*ctx
, target_ulong nip
)
275 #if defined(TARGET_PPC64)
277 tcg_gen_movi_tl(cpu_nip
, nip
);
280 tcg_gen_movi_tl(cpu_nip
, (uint32_t)nip
);
283 #define GEN_EXCP(ctx, excp, error) \
285 TCGv_i32 t0 = tcg_const_i32(excp); \
286 TCGv_i32 t1 = tcg_const_i32(error); \
287 if ((ctx)->exception == POWERPC_EXCP_NONE) { \
288 gen_update_nip(ctx, (ctx)->nip); \
290 gen_helper_raise_exception_err(t0, t1); \
291 tcg_temp_free_i32(t0); \
292 tcg_temp_free_i32(t1); \
293 ctx->exception = (excp); \
296 #define GEN_EXCP_INVAL(ctx) \
297 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
298 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_INVAL)
300 #define GEN_EXCP_PRIVOPC(ctx) \
301 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
302 POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_OPC)
304 #define GEN_EXCP_PRIVREG(ctx) \
305 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
306 POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_REG)
308 #define GEN_EXCP_NO_FP(ctx) \
309 GEN_EXCP(ctx, POWERPC_EXCP_FPU, 0)
311 #define GEN_EXCP_NO_AP(ctx) \
312 GEN_EXCP(ctx, POWERPC_EXCP_APU, 0)
314 #define GEN_EXCP_NO_VR(ctx) \
315 GEN_EXCP(ctx, POWERPC_EXCP_VPU, 0)
317 /* Stop translation */
318 static always_inline
void GEN_STOP (DisasContext
*ctx
)
320 gen_update_nip(ctx
, ctx
->nip
);
321 ctx
->exception
= POWERPC_EXCP_STOP
;
324 /* No need to update nip here, as execution flow will change */
325 static always_inline
void GEN_SYNC (DisasContext
*ctx
)
327 ctx
->exception
= POWERPC_EXCP_SYNC
;
330 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
331 static void gen_##name (DisasContext *ctx); \
332 GEN_OPCODE(name, opc1, opc2, opc3, inval, type); \
333 static void gen_##name (DisasContext *ctx)
335 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
336 static void gen_##name (DisasContext *ctx); \
337 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type); \
338 static void gen_##name (DisasContext *ctx)
340 typedef struct opcode_t
{
341 unsigned char opc1
, opc2
, opc3
;
342 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
343 unsigned char pad
[5];
345 unsigned char pad
[1];
347 opc_handler_t handler
;
351 /*****************************************************************************/
352 /*** Instruction decoding ***/
353 #define EXTRACT_HELPER(name, shift, nb) \
354 static always_inline uint32_t name (uint32_t opcode) \
356 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
359 #define EXTRACT_SHELPER(name, shift, nb) \
360 static always_inline int32_t name (uint32_t opcode) \
362 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
366 EXTRACT_HELPER(opc1
, 26, 6);
368 EXTRACT_HELPER(opc2
, 1, 5);
370 EXTRACT_HELPER(opc3
, 6, 5);
371 /* Update Cr0 flags */
372 EXTRACT_HELPER(Rc
, 0, 1);
374 EXTRACT_HELPER(rD
, 21, 5);
376 EXTRACT_HELPER(rS
, 21, 5);
378 EXTRACT_HELPER(rA
, 16, 5);
380 EXTRACT_HELPER(rB
, 11, 5);
382 EXTRACT_HELPER(rC
, 6, 5);
384 EXTRACT_HELPER(crfD
, 23, 3);
385 EXTRACT_HELPER(crfS
, 18, 3);
386 EXTRACT_HELPER(crbD
, 21, 5);
387 EXTRACT_HELPER(crbA
, 16, 5);
388 EXTRACT_HELPER(crbB
, 11, 5);
390 EXTRACT_HELPER(_SPR
, 11, 10);
391 static always_inline
uint32_t SPR (uint32_t opcode
)
393 uint32_t sprn
= _SPR(opcode
);
395 return ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
397 /*** Get constants ***/
398 EXTRACT_HELPER(IMM
, 12, 8);
399 /* 16 bits signed immediate value */
400 EXTRACT_SHELPER(SIMM
, 0, 16);
401 /* 16 bits unsigned immediate value */
402 EXTRACT_HELPER(UIMM
, 0, 16);
404 EXTRACT_HELPER(NB
, 11, 5);
406 EXTRACT_HELPER(SH
, 11, 5);
408 EXTRACT_HELPER(MB
, 6, 5);
410 EXTRACT_HELPER(ME
, 1, 5);
412 EXTRACT_HELPER(TO
, 21, 5);
414 EXTRACT_HELPER(CRM
, 12, 8);
415 EXTRACT_HELPER(FM
, 17, 8);
416 EXTRACT_HELPER(SR
, 16, 4);
417 EXTRACT_HELPER(FPIMM
, 12, 4);
419 /*** Jump target decoding ***/
421 EXTRACT_SHELPER(d
, 0, 16);
422 /* Immediate address */
423 static always_inline target_ulong
LI (uint32_t opcode
)
425 return (opcode
>> 0) & 0x03FFFFFC;
428 static always_inline
uint32_t BD (uint32_t opcode
)
430 return (opcode
>> 0) & 0xFFFC;
433 EXTRACT_HELPER(BO
, 21, 5);
434 EXTRACT_HELPER(BI
, 16, 5);
435 /* Absolute/relative address */
436 EXTRACT_HELPER(AA
, 1, 1);
438 EXTRACT_HELPER(LK
, 0, 1);
440 /* Create a mask between <start> and <end> bits */
441 static always_inline target_ulong
MASK (uint32_t start
, uint32_t end
)
445 #if defined(TARGET_PPC64)
446 if (likely(start
== 0)) {
447 ret
= UINT64_MAX
<< (63 - end
);
448 } else if (likely(end
== 63)) {
449 ret
= UINT64_MAX
>> start
;
452 if (likely(start
== 0)) {
453 ret
= UINT32_MAX
<< (31 - end
);
454 } else if (likely(end
== 31)) {
455 ret
= UINT32_MAX
>> start
;
459 ret
= (((target_ulong
)(-1ULL)) >> (start
)) ^
460 (((target_ulong
)(-1ULL) >> (end
)) >> 1);
461 if (unlikely(start
> end
))
468 /*****************************************************************************/
469 /* PowerPC Instructions types definitions */
471 PPC_NONE
= 0x0000000000000000ULL
,
472 /* PowerPC base instructions set */
473 PPC_INSNS_BASE
= 0x0000000000000001ULL
,
474 /* integer operations instructions */
475 #define PPC_INTEGER PPC_INSNS_BASE
476 /* flow control instructions */
477 #define PPC_FLOW PPC_INSNS_BASE
478 /* virtual memory instructions */
479 #define PPC_MEM PPC_INSNS_BASE
480 /* ld/st with reservation instructions */
481 #define PPC_RES PPC_INSNS_BASE
482 /* spr/msr access instructions */
483 #define PPC_MISC PPC_INSNS_BASE
484 /* Deprecated instruction sets */
485 /* Original POWER instruction set */
486 PPC_POWER
= 0x0000000000000002ULL
,
487 /* POWER2 instruction set extension */
488 PPC_POWER2
= 0x0000000000000004ULL
,
489 /* Power RTC support */
490 PPC_POWER_RTC
= 0x0000000000000008ULL
,
491 /* Power-to-PowerPC bridge (601) */
492 PPC_POWER_BR
= 0x0000000000000010ULL
,
493 /* 64 bits PowerPC instruction set */
494 PPC_64B
= 0x0000000000000020ULL
,
495 /* New 64 bits extensions (PowerPC 2.0x) */
496 PPC_64BX
= 0x0000000000000040ULL
,
497 /* 64 bits hypervisor extensions */
498 PPC_64H
= 0x0000000000000080ULL
,
499 /* New wait instruction (PowerPC 2.0x) */
500 PPC_WAIT
= 0x0000000000000100ULL
,
501 /* Time base mftb instruction */
502 PPC_MFTB
= 0x0000000000000200ULL
,
504 /* Fixed-point unit extensions */
505 /* PowerPC 602 specific */
506 PPC_602_SPEC
= 0x0000000000000400ULL
,
507 /* isel instruction */
508 PPC_ISEL
= 0x0000000000000800ULL
,
509 /* popcntb instruction */
510 PPC_POPCNTB
= 0x0000000000001000ULL
,
511 /* string load / store */
512 PPC_STRING
= 0x0000000000002000ULL
,
514 /* Floating-point unit extensions */
515 /* Optional floating point instructions */
516 PPC_FLOAT
= 0x0000000000010000ULL
,
517 /* New floating-point extensions (PowerPC 2.0x) */
518 PPC_FLOAT_EXT
= 0x0000000000020000ULL
,
519 PPC_FLOAT_FSQRT
= 0x0000000000040000ULL
,
520 PPC_FLOAT_FRES
= 0x0000000000080000ULL
,
521 PPC_FLOAT_FRSQRTE
= 0x0000000000100000ULL
,
522 PPC_FLOAT_FRSQRTES
= 0x0000000000200000ULL
,
523 PPC_FLOAT_FSEL
= 0x0000000000400000ULL
,
524 PPC_FLOAT_STFIWX
= 0x0000000000800000ULL
,
526 /* Vector/SIMD extensions */
527 /* Altivec support */
528 PPC_ALTIVEC
= 0x0000000001000000ULL
,
529 /* PowerPC 2.03 SPE extension */
530 PPC_SPE
= 0x0000000002000000ULL
,
531 /* PowerPC 2.03 SPE floating-point extension */
532 PPC_SPEFPU
= 0x0000000004000000ULL
,
534 /* Optional memory control instructions */
535 PPC_MEM_TLBIA
= 0x0000000010000000ULL
,
536 PPC_MEM_TLBIE
= 0x0000000020000000ULL
,
537 PPC_MEM_TLBSYNC
= 0x0000000040000000ULL
,
538 /* sync instruction */
539 PPC_MEM_SYNC
= 0x0000000080000000ULL
,
540 /* eieio instruction */
541 PPC_MEM_EIEIO
= 0x0000000100000000ULL
,
543 /* Cache control instructions */
544 PPC_CACHE
= 0x0000000200000000ULL
,
545 /* icbi instruction */
546 PPC_CACHE_ICBI
= 0x0000000400000000ULL
,
547 /* dcbz instruction with fixed cache line size */
548 PPC_CACHE_DCBZ
= 0x0000000800000000ULL
,
549 /* dcbz instruction with tunable cache line size */
550 PPC_CACHE_DCBZT
= 0x0000001000000000ULL
,
551 /* dcba instruction */
552 PPC_CACHE_DCBA
= 0x0000002000000000ULL
,
553 /* Freescale cache locking instructions */
554 PPC_CACHE_LOCK
= 0x0000004000000000ULL
,
556 /* MMU related extensions */
557 /* external control instructions */
558 PPC_EXTERN
= 0x0000010000000000ULL
,
559 /* segment register access instructions */
560 PPC_SEGMENT
= 0x0000020000000000ULL
,
561 /* PowerPC 6xx TLB management instructions */
562 PPC_6xx_TLB
= 0x0000040000000000ULL
,
563 /* PowerPC 74xx TLB management instructions */
564 PPC_74xx_TLB
= 0x0000080000000000ULL
,
565 /* PowerPC 40x TLB management instructions */
566 PPC_40x_TLB
= 0x0000100000000000ULL
,
567 /* segment register access instructions for PowerPC 64 "bridge" */
568 PPC_SEGMENT_64B
= 0x0000200000000000ULL
,
570 PPC_SLBI
= 0x0000400000000000ULL
,
572 /* Embedded PowerPC dedicated instructions */
573 PPC_WRTEE
= 0x0001000000000000ULL
,
574 /* PowerPC 40x exception model */
575 PPC_40x_EXCP
= 0x0002000000000000ULL
,
576 /* PowerPC 405 Mac instructions */
577 PPC_405_MAC
= 0x0004000000000000ULL
,
578 /* PowerPC 440 specific instructions */
579 PPC_440_SPEC
= 0x0008000000000000ULL
,
580 /* BookE (embedded) PowerPC specification */
581 PPC_BOOKE
= 0x0010000000000000ULL
,
582 /* mfapidi instruction */
583 PPC_MFAPIDI
= 0x0020000000000000ULL
,
584 /* tlbiva instruction */
585 PPC_TLBIVA
= 0x0040000000000000ULL
,
586 /* tlbivax instruction */
587 PPC_TLBIVAX
= 0x0080000000000000ULL
,
588 /* PowerPC 4xx dedicated instructions */
589 PPC_4xx_COMMON
= 0x0100000000000000ULL
,
590 /* PowerPC 40x ibct instructions */
591 PPC_40x_ICBT
= 0x0200000000000000ULL
,
592 /* rfmci is not implemented in all BookE PowerPC */
593 PPC_RFMCI
= 0x0400000000000000ULL
,
594 /* rfdi instruction */
595 PPC_RFDI
= 0x0800000000000000ULL
,
597 PPC_DCR
= 0x1000000000000000ULL
,
598 /* DCR extended accesse */
599 PPC_DCRX
= 0x2000000000000000ULL
,
600 /* user-mode DCR access, implemented in PowerPC 460 */
601 PPC_DCRUX
= 0x4000000000000000ULL
,
604 /*****************************************************************************/
605 /* PowerPC instructions table */
606 #if HOST_LONG_BITS == 64
611 #if defined(__APPLE__)
612 #define OPCODES_SECTION \
613 __attribute__ ((section("__TEXT,__opcodes"), unused, aligned (OPC_ALIGN) ))
615 #define OPCODES_SECTION \
616 __attribute__ ((section(".opcodes"), unused, aligned (OPC_ALIGN) ))
619 #if defined(DO_PPC_STATISTICS)
620 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
621 OPCODES_SECTION opcode_t opc_##name = { \
629 .handler = &gen_##name, \
630 .oname = stringify(name), \
632 .oname = stringify(name), \
634 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
635 OPCODES_SECTION opcode_t opc_##name = { \
643 .handler = &gen_##name, \
649 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
650 OPCODES_SECTION opcode_t opc_##name = { \
658 .handler = &gen_##name, \
660 .oname = stringify(name), \
662 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
663 OPCODES_SECTION opcode_t opc_##name = { \
671 .handler = &gen_##name, \
677 #define GEN_OPCODE_MARK(name) \
678 OPCODES_SECTION opcode_t opc_##name = { \
684 .inval = 0x00000000, \
688 .oname = stringify(name), \
691 /* Start opcode list */
692 GEN_OPCODE_MARK(start
);
694 /* Invalid instruction */
695 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
)
700 static opc_handler_t invalid_handler
= {
703 .handler
= gen_invalid
,
706 /*** Integer comparison ***/
708 static always_inline
void gen_op_cmp(TCGv arg0
, TCGv arg1
, int s
, int crf
)
712 tcg_gen_trunc_tl_i32(cpu_crf
[crf
], cpu_xer
);
713 tcg_gen_shri_i32(cpu_crf
[crf
], cpu_crf
[crf
], XER_SO
);
714 tcg_gen_andi_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1);
716 l1
= gen_new_label();
717 l2
= gen_new_label();
718 l3
= gen_new_label();
720 tcg_gen_brcond_tl(TCG_COND_LT
, arg0
, arg1
, l1
);
721 tcg_gen_brcond_tl(TCG_COND_GT
, arg0
, arg1
, l2
);
723 tcg_gen_brcond_tl(TCG_COND_LTU
, arg0
, arg1
, l1
);
724 tcg_gen_brcond_tl(TCG_COND_GTU
, arg0
, arg1
, l2
);
726 tcg_gen_ori_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1 << CRF_EQ
);
729 tcg_gen_ori_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1 << CRF_LT
);
732 tcg_gen_ori_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1 << CRF_GT
);
736 static always_inline
void gen_op_cmpi(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
738 TCGv t0
= tcg_const_local_tl(arg1
);
739 gen_op_cmp(arg0
, t0
, s
, crf
);
743 #if defined(TARGET_PPC64)
744 static always_inline
void gen_op_cmp32(TCGv arg0
, TCGv arg1
, int s
, int crf
)
747 t0
= tcg_temp_local_new();
748 t1
= tcg_temp_local_new();
750 tcg_gen_ext32s_tl(t0
, arg0
);
751 tcg_gen_ext32s_tl(t1
, arg1
);
753 tcg_gen_ext32u_tl(t0
, arg0
);
754 tcg_gen_ext32u_tl(t1
, arg1
);
756 gen_op_cmp(t0
, t1
, s
, crf
);
761 static always_inline
void gen_op_cmpi32(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
763 TCGv t0
= tcg_const_local_tl(arg1
);
764 gen_op_cmp32(arg0
, t0
, s
, crf
);
769 static always_inline
void gen_set_Rc0 (DisasContext
*ctx
, TCGv reg
)
771 #if defined(TARGET_PPC64)
773 gen_op_cmpi32(reg
, 0, 1, 0);
776 gen_op_cmpi(reg
, 0, 1, 0);
780 GEN_HANDLER(cmp
, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER
)
782 #if defined(TARGET_PPC64)
783 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
784 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
785 1, crfD(ctx
->opcode
));
788 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
789 1, crfD(ctx
->opcode
));
793 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
)
795 #if defined(TARGET_PPC64)
796 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
797 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
798 1, crfD(ctx
->opcode
));
801 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
802 1, crfD(ctx
->opcode
));
806 GEN_HANDLER(cmpl
, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER
)
808 #if defined(TARGET_PPC64)
809 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
810 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
811 0, crfD(ctx
->opcode
));
814 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
815 0, crfD(ctx
->opcode
));
819 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
)
821 #if defined(TARGET_PPC64)
822 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
823 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
824 0, crfD(ctx
->opcode
));
827 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
828 0, crfD(ctx
->opcode
));
831 /* isel (PowerPC 2.03 specification) */
832 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
)
835 uint32_t bi
= rC(ctx
->opcode
);
839 l1
= gen_new_label();
840 l2
= gen_new_label();
842 mask
= 1 << (3 - (bi
& 0x03));
843 t0
= tcg_temp_new_i32();
844 tcg_gen_andi_i32(t0
, cpu_crf
[bi
>> 2], mask
);
845 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
846 if (rA(ctx
->opcode
) == 0)
847 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
849 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
852 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
854 tcg_temp_free_i32(t0
);
857 /*** Integer arithmetic ***/
859 static always_inline
void gen_op_arith_compute_ov(DisasContext
*ctx
, TCGv arg0
, TCGv arg1
, TCGv arg2
, int sub
)
864 l1
= gen_new_label();
865 /* Start with XER OV disabled, the most likely case */
866 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
867 t0
= tcg_temp_local_new();
868 tcg_gen_xor_tl(t0
, arg0
, arg1
);
869 #if defined(TARGET_PPC64)
871 tcg_gen_ext32s_tl(t0
, t0
);
874 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0, l1
);
876 tcg_gen_brcondi_tl(TCG_COND_GE
, t0
, 0, l1
);
877 tcg_gen_xor_tl(t0
, arg1
, arg2
);
878 #if defined(TARGET_PPC64)
880 tcg_gen_ext32s_tl(t0
, t0
);
883 tcg_gen_brcondi_tl(TCG_COND_GE
, t0
, 0, l1
);
885 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0, l1
);
886 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
891 static always_inline
void gen_op_arith_compute_ca(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
, int sub
)
893 int l1
= gen_new_label();
895 #if defined(TARGET_PPC64)
896 if (!(ctx
->sf_mode
)) {
901 tcg_gen_ext32u_tl(t0
, arg1
);
902 tcg_gen_ext32u_tl(t1
, arg2
);
904 tcg_gen_brcond_tl(TCG_COND_GTU
, t0
, t1
, l1
);
906 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
908 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
916 tcg_gen_brcond_tl(TCG_COND_GTU
, arg1
, arg2
, l1
);
918 tcg_gen_brcond_tl(TCG_COND_GEU
, arg1
, arg2
, l1
);
920 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
925 /* Common add function */
926 static always_inline
void gen_op_arith_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
, TCGv arg2
,
927 int add_ca
, int compute_ca
, int compute_ov
)
931 if ((!compute_ca
&& !compute_ov
) ||
932 (!TCGV_EQUAL(ret
,arg1
) && !TCGV_EQUAL(ret
, arg2
))) {
935 t0
= tcg_temp_local_new();
939 t1
= tcg_temp_local_new();
940 tcg_gen_andi_tl(t1
, cpu_xer
, (1 << XER_CA
));
941 tcg_gen_shri_tl(t1
, t1
, XER_CA
);
944 if (compute_ca
&& compute_ov
) {
945 /* Start with XER CA and OV disabled, the most likely case */
946 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~((1 << XER_CA
) | (1 << XER_OV
)));
947 } else if (compute_ca
) {
948 /* Start with XER CA disabled, the most likely case */
949 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
950 } else if (compute_ov
) {
951 /* Start with XER OV disabled, the most likely case */
952 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
955 tcg_gen_add_tl(t0
, arg1
, arg2
);
958 gen_op_arith_compute_ca(ctx
, t0
, arg1
, 0);
961 tcg_gen_add_tl(t0
, t0
, t1
);
962 gen_op_arith_compute_ca(ctx
, t0
, t1
, 0);
966 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 0);
969 if (unlikely(Rc(ctx
->opcode
) != 0))
970 gen_set_Rc0(ctx
, t0
);
972 if (!TCGV_EQUAL(t0
, ret
)) {
973 tcg_gen_mov_tl(ret
, t0
);
977 /* Add functions with two operands */
978 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
979 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER) \
981 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
982 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
983 add_ca, compute_ca, compute_ov); \
985 /* Add functions with one operand and one immediate */
986 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
987 add_ca, compute_ca, compute_ov) \
988 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER) \
990 TCGv t0 = tcg_const_local_tl(const_val); \
991 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
992 cpu_gpr[rA(ctx->opcode)], t0, \
993 add_ca, compute_ca, compute_ov); \
997 /* add add. addo addo. */
998 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
999 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
1000 /* addc addc. addco addco. */
1001 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
1002 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
1003 /* adde adde. addeo addeo. */
1004 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
1005 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
1006 /* addme addme. addmeo addmeo. */
1007 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
1008 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
1009 /* addze addze. addzeo addzeo.*/
1010 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
1011 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
1013 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1015 target_long simm
= SIMM(ctx
->opcode
);
1017 if (rA(ctx
->opcode
) == 0) {
1019 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
);
1021 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], simm
);
1025 static always_inline
void gen_op_addic (DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1028 target_long simm
= SIMM(ctx
->opcode
);
1030 /* Start with XER CA and OV disabled, the most likely case */
1031 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1033 if (likely(simm
!= 0)) {
1034 TCGv t0
= tcg_temp_local_new();
1035 tcg_gen_addi_tl(t0
, arg1
, simm
);
1036 gen_op_arith_compute_ca(ctx
, t0
, arg1
, 0);
1037 tcg_gen_mov_tl(ret
, t0
);
1040 tcg_gen_mov_tl(ret
, arg1
);
1043 gen_set_Rc0(ctx
, ret
);
1046 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1048 gen_op_addic(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0);
1050 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1052 gen_op_addic(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 1);
1055 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1057 target_long simm
= SIMM(ctx
->opcode
);
1059 if (rA(ctx
->opcode
) == 0) {
1061 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
<< 16);
1063 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], simm
<< 16);
1067 static always_inline
void gen_op_arith_divw (DisasContext
*ctx
, TCGv ret
, TCGv arg1
, TCGv arg2
,
1068 int sign
, int compute_ov
)
1070 int l1
= gen_new_label();
1071 int l2
= gen_new_label();
1072 TCGv_i32 t0
= tcg_temp_local_new_i32();
1073 TCGv_i32 t1
= tcg_temp_local_new_i32();
1075 tcg_gen_trunc_tl_i32(t0
, arg1
);
1076 tcg_gen_trunc_tl_i32(t1
, arg2
);
1077 tcg_gen_brcondi_i32(TCG_COND_EQ
, t1
, 0, l1
);
1079 int l3
= gen_new_label();
1080 tcg_gen_brcondi_i32(TCG_COND_NE
, t1
, -1, l3
);
1081 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, INT32_MIN
, l1
);
1083 tcg_gen_div_i32(t0
, t0
, t1
);
1085 tcg_gen_divu_i32(t0
, t0
, t1
);
1088 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1093 tcg_gen_sari_i32(t0
, t0
, 31);
1095 tcg_gen_movi_i32(t0
, 0);
1098 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1101 tcg_gen_extu_i32_tl(ret
, t0
);
1102 tcg_temp_free_i32(t0
);
1103 tcg_temp_free_i32(t1
);
1104 if (unlikely(Rc(ctx
->opcode
) != 0))
1105 gen_set_Rc0(ctx
, ret
);
1108 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
1109 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER) \
1111 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
1112 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1113 sign, compute_ov); \
1115 /* divwu divwu. divwuo divwuo. */
1116 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0);
1117 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1);
1118 /* divw divw. divwo divwo. */
1119 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0);
1120 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1);
1121 #if defined(TARGET_PPC64)
1122 static always_inline
void gen_op_arith_divd (DisasContext
*ctx
, TCGv ret
, TCGv arg1
, TCGv arg2
,
1123 int sign
, int compute_ov
)
1125 int l1
= gen_new_label();
1126 int l2
= gen_new_label();
1128 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg2
, 0, l1
);
1130 int l3
= gen_new_label();
1131 tcg_gen_brcondi_i64(TCG_COND_NE
, arg2
, -1, l3
);
1132 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg1
, INT64_MIN
, l1
);
1134 tcg_gen_div_i64(ret
, arg1
, arg2
);
1136 tcg_gen_divu_i64(ret
, arg1
, arg2
);
1139 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1144 tcg_gen_sari_i64(ret
, arg1
, 63);
1146 tcg_gen_movi_i64(ret
, 0);
1149 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1152 if (unlikely(Rc(ctx
->opcode
) != 0))
1153 gen_set_Rc0(ctx
, ret
);
1155 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1156 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) \
1158 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1159 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1160 sign, compute_ov); \
1162 /* divwu divwu. divwuo divwuo. */
1163 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0);
1164 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1);
1165 /* divw divw. divwo divwo. */
1166 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0);
1167 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1);
1171 GEN_HANDLER(mulhw
, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER
)
1175 t0
= tcg_temp_new_i64();
1176 t1
= tcg_temp_new_i64();
1177 #if defined(TARGET_PPC64)
1178 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1179 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1180 tcg_gen_mul_i64(t0
, t0
, t1
);
1181 tcg_gen_shri_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
1183 tcg_gen_ext_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1184 tcg_gen_ext_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1185 tcg_gen_mul_i64(t0
, t0
, t1
);
1186 tcg_gen_shri_i64(t0
, t0
, 32);
1187 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1189 tcg_temp_free_i64(t0
);
1190 tcg_temp_free_i64(t1
);
1191 if (unlikely(Rc(ctx
->opcode
) != 0))
1192 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1194 /* mulhwu mulhwu. */
1195 GEN_HANDLER(mulhwu
, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER
)
1199 t0
= tcg_temp_new_i64();
1200 t1
= tcg_temp_new_i64();
1201 #if defined(TARGET_PPC64)
1202 tcg_gen_ext32u_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1203 tcg_gen_ext32u_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1204 tcg_gen_mul_i64(t0
, t0
, t1
);
1205 tcg_gen_shri_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
1207 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1208 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1209 tcg_gen_mul_i64(t0
, t0
, t1
);
1210 tcg_gen_shri_i64(t0
, t0
, 32);
1211 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1213 tcg_temp_free_i64(t0
);
1214 tcg_temp_free_i64(t1
);
1215 if (unlikely(Rc(ctx
->opcode
) != 0))
1216 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1219 GEN_HANDLER(mullw
, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER
)
1221 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1222 cpu_gpr
[rB(ctx
->opcode
)]);
1223 tcg_gen_ext32s_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)]);
1224 if (unlikely(Rc(ctx
->opcode
) != 0))
1225 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1227 /* mullwo mullwo. */
1228 GEN_HANDLER(mullwo
, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER
)
1233 t0
= tcg_temp_new_i64();
1234 t1
= tcg_temp_new_i64();
1235 l1
= gen_new_label();
1236 /* Start with XER OV disabled, the most likely case */
1237 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1238 #if defined(TARGET_PPC64)
1239 tcg_gen_ext32s_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1240 tcg_gen_ext32s_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1242 tcg_gen_ext_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1243 tcg_gen_ext_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1245 tcg_gen_mul_i64(t0
, t0
, t1
);
1246 #if defined(TARGET_PPC64)
1247 tcg_gen_ext32s_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1248 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, cpu_gpr
[rD(ctx
->opcode
)], l1
);
1250 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1251 tcg_gen_ext32s_i64(t1
, t0
);
1252 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
1254 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1256 tcg_temp_free_i64(t0
);
1257 tcg_temp_free_i64(t1
);
1258 if (unlikely(Rc(ctx
->opcode
) != 0))
1259 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1262 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1264 tcg_gen_muli_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1267 #if defined(TARGET_PPC64)
1268 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
1269 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) \
1271 gen_helper_##name (cpu_gpr[rD(ctx->opcode)], \
1272 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
1273 if (unlikely(Rc(ctx->opcode) != 0)) \
1274 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1277 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00);
1278 /* mulhdu mulhdu. */
1279 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02);
1281 GEN_HANDLER(mulld
, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B
)
1283 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1284 cpu_gpr
[rB(ctx
->opcode
)]);
1285 if (unlikely(Rc(ctx
->opcode
) != 0))
1286 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1288 /* mulldo mulldo. */
1289 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17);
1292 /* neg neg. nego nego. */
1293 static always_inline
void gen_op_arith_neg (DisasContext
*ctx
, TCGv ret
, TCGv arg1
, int ov_check
)
1295 int l1
= gen_new_label();
1296 int l2
= gen_new_label();
1297 TCGv t0
= tcg_temp_local_new();
1298 #if defined(TARGET_PPC64)
1300 tcg_gen_mov_tl(t0
, arg1
);
1301 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, INT64_MIN
, l1
);
1305 tcg_gen_ext32s_tl(t0
, arg1
);
1306 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, INT32_MIN
, l1
);
1308 tcg_gen_neg_tl(ret
, arg1
);
1310 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1314 tcg_gen_mov_tl(ret
, t0
);
1316 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1320 if (unlikely(Rc(ctx
->opcode
) != 0))
1321 gen_set_Rc0(ctx
, ret
);
1323 GEN_HANDLER(neg
, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER
)
1325 gen_op_arith_neg(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0);
1327 GEN_HANDLER(nego
, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER
)
1329 gen_op_arith_neg(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 1);
1332 /* Common subf function */
1333 static always_inline
void gen_op_arith_subf(DisasContext
*ctx
, TCGv ret
, TCGv arg1
, TCGv arg2
,
1334 int add_ca
, int compute_ca
, int compute_ov
)
1338 if ((!compute_ca
&& !compute_ov
) ||
1339 (!TCGV_EQUAL(ret
, arg1
) && !TCGV_EQUAL(ret
, arg2
))) {
1342 t0
= tcg_temp_local_new();
1346 t1
= tcg_temp_local_new();
1347 tcg_gen_andi_tl(t1
, cpu_xer
, (1 << XER_CA
));
1348 tcg_gen_shri_tl(t1
, t1
, XER_CA
);
1351 if (compute_ca
&& compute_ov
) {
1352 /* Start with XER CA and OV disabled, the most likely case */
1353 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~((1 << XER_CA
) | (1 << XER_OV
)));
1354 } else if (compute_ca
) {
1355 /* Start with XER CA disabled, the most likely case */
1356 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1357 } else if (compute_ov
) {
1358 /* Start with XER OV disabled, the most likely case */
1359 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1363 tcg_gen_not_tl(t0
, arg1
);
1364 tcg_gen_add_tl(t0
, t0
, arg2
);
1365 gen_op_arith_compute_ca(ctx
, t0
, arg2
, 0);
1366 tcg_gen_add_tl(t0
, t0
, t1
);
1367 gen_op_arith_compute_ca(ctx
, t0
, t1
, 0);
1370 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1372 gen_op_arith_compute_ca(ctx
, t0
, arg2
, 1);
1376 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 1);
1379 if (unlikely(Rc(ctx
->opcode
) != 0))
1380 gen_set_Rc0(ctx
, t0
);
1382 if (!TCGV_EQUAL(t0
, ret
)) {
1383 tcg_gen_mov_tl(ret
, t0
);
1387 /* Sub functions with Two operands functions */
1388 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1389 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER) \
1391 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1392 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1393 add_ca, compute_ca, compute_ov); \
1395 /* Sub functions with one operand and one immediate */
1396 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1397 add_ca, compute_ca, compute_ov) \
1398 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER) \
1400 TCGv t0 = tcg_const_local_tl(const_val); \
1401 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1402 cpu_gpr[rA(ctx->opcode)], t0, \
1403 add_ca, compute_ca, compute_ov); \
1404 tcg_temp_free(t0); \
1406 /* subf subf. subfo subfo. */
1407 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
1408 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
1409 /* subfc subfc. subfco subfco. */
1410 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
1411 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
1412 /* subfe subfe. subfeo subfo. */
1413 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
1414 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
1415 /* subfme subfme. subfmeo subfmeo. */
1416 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
1417 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
1418 /* subfze subfze. subfzeo subfzeo.*/
1419 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
1420 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
1422 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1424 /* Start with XER CA and OV disabled, the most likely case */
1425 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1426 TCGv t0
= tcg_temp_local_new();
1427 TCGv t1
= tcg_const_local_tl(SIMM(ctx
->opcode
));
1428 tcg_gen_sub_tl(t0
, t1
, cpu_gpr
[rA(ctx
->opcode
)]);
1429 gen_op_arith_compute_ca(ctx
, t0
, t1
, 1);
1431 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1435 /*** Integer logical ***/
1436 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1437 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type) \
1439 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1440 cpu_gpr[rB(ctx->opcode)]); \
1441 if (unlikely(Rc(ctx->opcode) != 0)) \
1442 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1445 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1446 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type) \
1448 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1449 if (unlikely(Rc(ctx->opcode) != 0)) \
1450 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1454 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
);
1456 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
);
1458 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1460 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
));
1461 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1464 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1466 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
) << 16);
1467 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1470 GEN_HANDLER(cntlzw
, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER
)
1472 gen_helper_cntlzw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1473 if (unlikely(Rc(ctx
->opcode
) != 0))
1474 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1477 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
);
1478 /* extsb & extsb. */
1479 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
);
1480 /* extsh & extsh. */
1481 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
);
1483 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
);
1485 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
);
1487 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
)
1491 rs
= rS(ctx
->opcode
);
1492 ra
= rA(ctx
->opcode
);
1493 rb
= rB(ctx
->opcode
);
1494 /* Optimisation for mr. ri case */
1495 if (rs
!= ra
|| rs
!= rb
) {
1497 tcg_gen_or_tl(cpu_gpr
[ra
], cpu_gpr
[rs
], cpu_gpr
[rb
]);
1499 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rs
]);
1500 if (unlikely(Rc(ctx
->opcode
) != 0))
1501 gen_set_Rc0(ctx
, cpu_gpr
[ra
]);
1502 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
1503 gen_set_Rc0(ctx
, cpu_gpr
[rs
]);
1504 #if defined(TARGET_PPC64)
1510 /* Set process priority to low */
1514 /* Set process priority to medium-low */
1518 /* Set process priority to normal */
1521 #if !defined(CONFIG_USER_ONLY)
1523 if (ctx
->supervisor
> 0) {
1524 /* Set process priority to very low */
1529 if (ctx
->supervisor
> 0) {
1530 /* Set process priority to medium-hight */
1535 if (ctx
->supervisor
> 0) {
1536 /* Set process priority to high */
1541 if (ctx
->supervisor
> 1) {
1542 /* Set process priority to very high */
1552 TCGv t0
= tcg_temp_new();
1553 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, spr
[SPR_PPR
]));
1554 tcg_gen_andi_tl(t0
, t0
, ~0x001C000000000000ULL
);
1555 tcg_gen_ori_tl(t0
, t0
, ((uint64_t)prio
) << 50);
1556 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, spr
[SPR_PPR
]));
1563 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
);
1565 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
)
1567 /* Optimisation for "set to zero" case */
1568 if (rS(ctx
->opcode
) != rB(ctx
->opcode
))
1569 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1571 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1572 if (unlikely(Rc(ctx
->opcode
) != 0))
1573 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1576 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1578 target_ulong uimm
= UIMM(ctx
->opcode
);
1580 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1582 /* XXX: should handle special NOPs for POWER series */
1585 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1588 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1590 target_ulong uimm
= UIMM(ctx
->opcode
);
1592 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1596 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1599 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1601 target_ulong uimm
= UIMM(ctx
->opcode
);
1603 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1607 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1610 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1612 target_ulong uimm
= UIMM(ctx
->opcode
);
1614 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1618 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1620 /* popcntb : PowerPC 2.03 specification */
1621 GEN_HANDLER(popcntb
, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB
)
1623 #if defined(TARGET_PPC64)
1625 gen_helper_popcntb_64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1628 gen_helper_popcntb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1631 #if defined(TARGET_PPC64)
1632 /* extsw & extsw. */
1633 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
);
1635 GEN_HANDLER(cntlzd
, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B
)
1637 gen_helper_cntlzd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1638 if (unlikely(Rc(ctx
->opcode
) != 0))
1639 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1643 /*** Integer rotate ***/
1644 /* rlwimi & rlwimi. */
1645 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1647 uint32_t mb
, me
, sh
;
1649 mb
= MB(ctx
->opcode
);
1650 me
= ME(ctx
->opcode
);
1651 sh
= SH(ctx
->opcode
);
1652 if (likely(sh
== 0 && mb
== 0 && me
== 31)) {
1653 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1657 TCGv t0
= tcg_temp_new();
1658 #if defined(TARGET_PPC64)
1659 TCGv_i32 t2
= tcg_temp_new_i32();
1660 tcg_gen_trunc_i64_i32(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
1661 tcg_gen_rotli_i32(t2
, t2
, sh
);
1662 tcg_gen_extu_i32_i64(t0
, t2
);
1663 tcg_temp_free_i32(t2
);
1665 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1667 #if defined(TARGET_PPC64)
1671 mask
= MASK(mb
, me
);
1672 t1
= tcg_temp_new();
1673 tcg_gen_andi_tl(t0
, t0
, mask
);
1674 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1675 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1679 if (unlikely(Rc(ctx
->opcode
) != 0))
1680 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1682 /* rlwinm & rlwinm. */
1683 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1685 uint32_t mb
, me
, sh
;
1687 sh
= SH(ctx
->opcode
);
1688 mb
= MB(ctx
->opcode
);
1689 me
= ME(ctx
->opcode
);
1691 if (likely(mb
== 0 && me
== (31 - sh
))) {
1692 if (likely(sh
== 0)) {
1693 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1695 TCGv t0
= tcg_temp_new();
1696 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1697 tcg_gen_shli_tl(t0
, t0
, sh
);
1698 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1701 } else if (likely(sh
!= 0 && me
== 31 && sh
== (32 - mb
))) {
1702 TCGv t0
= tcg_temp_new();
1703 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1704 tcg_gen_shri_tl(t0
, t0
, mb
);
1705 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1708 TCGv t0
= tcg_temp_new();
1709 #if defined(TARGET_PPC64)
1710 TCGv_i32 t1
= tcg_temp_new_i32();
1711 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1712 tcg_gen_rotli_i32(t1
, t1
, sh
);
1713 tcg_gen_extu_i32_i64(t0
, t1
);
1714 tcg_temp_free_i32(t1
);
1716 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1718 #if defined(TARGET_PPC64)
1722 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1725 if (unlikely(Rc(ctx
->opcode
) != 0))
1726 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1728 /* rlwnm & rlwnm. */
1729 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1733 #if defined(TARGET_PPC64)
1737 mb
= MB(ctx
->opcode
);
1738 me
= ME(ctx
->opcode
);
1739 t0
= tcg_temp_new();
1740 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1741 #if defined(TARGET_PPC64)
1742 t1
= tcg_temp_new_i32();
1743 t2
= tcg_temp_new_i32();
1744 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1745 tcg_gen_trunc_i64_i32(t2
, t0
);
1746 tcg_gen_rotl_i32(t1
, t1
, t2
);
1747 tcg_gen_extu_i32_i64(t0
, t1
);
1748 tcg_temp_free_i32(t1
);
1749 tcg_temp_free_i32(t2
);
1751 tcg_gen_rotl_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1753 if (unlikely(mb
!= 0 || me
!= 31)) {
1754 #if defined(TARGET_PPC64)
1758 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1760 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1763 if (unlikely(Rc(ctx
->opcode
) != 0))
1764 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1767 #if defined(TARGET_PPC64)
1768 #define GEN_PPC64_R2(name, opc1, opc2) \
1769 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1771 gen_##name(ctx, 0); \
1773 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1776 gen_##name(ctx, 1); \
1778 #define GEN_PPC64_R4(name, opc1, opc2) \
1779 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1781 gen_##name(ctx, 0, 0); \
1783 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
1786 gen_##name(ctx, 0, 1); \
1788 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1791 gen_##name(ctx, 1, 0); \
1793 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
1796 gen_##name(ctx, 1, 1); \
1799 static always_inline
void gen_rldinm (DisasContext
*ctx
, uint32_t mb
,
1800 uint32_t me
, uint32_t sh
)
1802 if (likely(sh
!= 0 && mb
== 0 && me
== (63 - sh
))) {
1803 tcg_gen_shli_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
1804 } else if (likely(sh
!= 0 && me
== 63 && sh
== (64 - mb
))) {
1805 tcg_gen_shri_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], mb
);
1807 TCGv t0
= tcg_temp_new();
1808 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1809 if (likely(mb
== 0 && me
== 63)) {
1810 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1812 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1816 if (unlikely(Rc(ctx
->opcode
) != 0))
1817 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1819 /* rldicl - rldicl. */
1820 static always_inline
void gen_rldicl (DisasContext
*ctx
, int mbn
, int shn
)
1824 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1825 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1826 gen_rldinm(ctx
, mb
, 63, sh
);
1828 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
1829 /* rldicr - rldicr. */
1830 static always_inline
void gen_rldicr (DisasContext
*ctx
, int men
, int shn
)
1834 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1835 me
= MB(ctx
->opcode
) | (men
<< 5);
1836 gen_rldinm(ctx
, 0, me
, sh
);
1838 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
1839 /* rldic - rldic. */
1840 static always_inline
void gen_rldic (DisasContext
*ctx
, int mbn
, int shn
)
1844 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1845 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1846 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
1848 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
1850 static always_inline
void gen_rldnm (DisasContext
*ctx
, uint32_t mb
,
1855 mb
= MB(ctx
->opcode
);
1856 me
= ME(ctx
->opcode
);
1857 t0
= tcg_temp_new();
1858 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1859 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1860 if (unlikely(mb
!= 0 || me
!= 63)) {
1861 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1863 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1866 if (unlikely(Rc(ctx
->opcode
) != 0))
1867 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1870 /* rldcl - rldcl. */
1871 static always_inline
void gen_rldcl (DisasContext
*ctx
, int mbn
)
1875 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1876 gen_rldnm(ctx
, mb
, 63);
1878 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
1879 /* rldcr - rldcr. */
1880 static always_inline
void gen_rldcr (DisasContext
*ctx
, int men
)
1884 me
= MB(ctx
->opcode
) | (men
<< 5);
1885 gen_rldnm(ctx
, 0, me
);
1887 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
1888 /* rldimi - rldimi. */
1889 static always_inline
void gen_rldimi (DisasContext
*ctx
, int mbn
, int shn
)
1891 uint32_t sh
, mb
, me
;
1893 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1894 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1896 if (unlikely(sh
== 0 && mb
== 0)) {
1897 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1902 t0
= tcg_temp_new();
1903 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1904 t1
= tcg_temp_new();
1905 mask
= MASK(mb
, me
);
1906 tcg_gen_andi_tl(t0
, t0
, mask
);
1907 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1908 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1912 if (unlikely(Rc(ctx
->opcode
) != 0))
1913 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1915 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
1918 /*** Integer shift ***/
1920 GEN_HANDLER(slw
, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER
)
1924 l1
= gen_new_label();
1925 l2
= gen_new_label();
1927 t0
= tcg_temp_local_new();
1928 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1929 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0x20, l1
);
1930 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1933 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t0
);
1934 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
1937 if (unlikely(Rc(ctx
->opcode
) != 0))
1938 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1941 GEN_HANDLER(sraw
, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER
)
1943 gen_helper_sraw(cpu_gpr
[rA(ctx
->opcode
)],
1944 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1945 if (unlikely(Rc(ctx
->opcode
) != 0))
1946 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1948 /* srawi & srawi. */
1949 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
)
1951 int sh
= SH(ctx
->opcode
);
1955 l1
= gen_new_label();
1956 l2
= gen_new_label();
1957 t0
= tcg_temp_local_new();
1958 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1959 tcg_gen_brcondi_tl(TCG_COND_GE
, t0
, 0, l1
);
1960 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1ULL << sh
) - 1);
1961 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
1962 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
1965 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1967 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1968 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, sh
);
1971 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1972 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1974 if (unlikely(Rc(ctx
->opcode
) != 0))
1975 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1978 GEN_HANDLER(srw
, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER
)
1982 l1
= gen_new_label();
1983 l2
= gen_new_label();
1985 t0
= tcg_temp_local_new();
1986 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1987 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0x20, l1
);
1988 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1991 t1
= tcg_temp_new();
1992 tcg_gen_ext32u_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1993 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
, t0
);
1997 if (unlikely(Rc(ctx
->opcode
) != 0))
1998 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2000 #if defined(TARGET_PPC64)
2002 GEN_HANDLER(sld
, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B
)
2006 l1
= gen_new_label();
2007 l2
= gen_new_label();
2009 t0
= tcg_temp_local_new();
2010 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x7f);
2011 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0x40, l1
);
2012 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
2015 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t0
);
2018 if (unlikely(Rc(ctx
->opcode
) != 0))
2019 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2022 GEN_HANDLER(srad
, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B
)
2024 gen_helper_srad(cpu_gpr
[rA(ctx
->opcode
)],
2025 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2026 if (unlikely(Rc(ctx
->opcode
) != 0))
2027 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2029 /* sradi & sradi. */
2030 static always_inline
void gen_sradi (DisasContext
*ctx
, int n
)
2032 int sh
= SH(ctx
->opcode
) + (n
<< 5);
2036 l1
= gen_new_label();
2037 l2
= gen_new_label();
2038 t0
= tcg_temp_local_new();
2039 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
2040 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1ULL << sh
) - 1);
2041 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2042 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
2045 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
2048 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
2050 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
2051 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
2053 if (unlikely(Rc(ctx
->opcode
) != 0))
2054 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2056 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
)
2060 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
)
2065 GEN_HANDLER(srd
, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B
)
2069 l1
= gen_new_label();
2070 l2
= gen_new_label();
2072 t0
= tcg_temp_local_new();
2073 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x7f);
2074 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0x40, l1
);
2075 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
2078 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t0
);
2081 if (unlikely(Rc(ctx
->opcode
) != 0))
2082 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2086 /*** Floating-Point arithmetic ***/
2087 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
2088 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type) \
2090 if (unlikely(!ctx->fpu_enabled)) { \
2091 GEN_EXCP_NO_FP(ctx); \
2094 gen_reset_fpstatus(); \
2095 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], \
2096 cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2098 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]); \
2100 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \
2101 Rc(ctx->opcode) != 0); \
2104 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2105 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2106 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
2108 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2109 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
2111 if (unlikely(!ctx->fpu_enabled)) { \
2112 GEN_EXCP_NO_FP(ctx); \
2115 gen_reset_fpstatus(); \
2116 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], \
2117 cpu_fpr[rB(ctx->opcode)]); \
2119 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]); \
2121 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2122 set_fprf, Rc(ctx->opcode) != 0); \
2124 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2125 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2126 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2128 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2129 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
2131 if (unlikely(!ctx->fpu_enabled)) { \
2132 GEN_EXCP_NO_FP(ctx); \
2135 gen_reset_fpstatus(); \
2136 gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], \
2137 cpu_fpr[rC(ctx->opcode)]); \
2139 gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rD(ctx->opcode)]); \
2141 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2142 set_fprf, Rc(ctx->opcode) != 0); \
2144 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2145 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2146 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2148 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
2149 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type) \
2151 if (unlikely(!ctx->fpu_enabled)) { \
2152 GEN_EXCP_NO_FP(ctx); \
2155 gen_reset_fpstatus(); \
2156 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2157 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2158 set_fprf, Rc(ctx->opcode) != 0); \
2161 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
2162 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type) \
2164 if (unlikely(!ctx->fpu_enabled)) { \
2165 GEN_EXCP_NO_FP(ctx); \
2168 gen_reset_fpstatus(); \
2169 gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \
2170 gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \
2171 set_fprf, Rc(ctx->opcode) != 0); \
2175 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
);
2177 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
);
2179 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
);
2182 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
);
2185 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
);
2188 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
);
2191 GEN_HANDLER(frsqrtes
, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES
)
2193 if (unlikely(!ctx
->fpu_enabled
)) {
2194 GEN_EXCP_NO_FP(ctx
);
2197 gen_reset_fpstatus();
2198 gen_helper_frsqrte(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2199 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rD(ctx
->opcode
)]);
2200 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2204 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
);
2206 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
);
2209 GEN_HANDLER(fsqrt
, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
)
2211 if (unlikely(!ctx
->fpu_enabled
)) {
2212 GEN_EXCP_NO_FP(ctx
);
2215 gen_reset_fpstatus();
2216 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2217 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2220 GEN_HANDLER(fsqrts
, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
)
2222 if (unlikely(!ctx
->fpu_enabled
)) {
2223 GEN_EXCP_NO_FP(ctx
);
2226 gen_reset_fpstatus();
2227 gen_helper_fsqrt(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2228 gen_helper_frsp(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rD(ctx
->opcode
)]);
2229 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 1, Rc(ctx
->opcode
) != 0);
2232 /*** Floating-Point multiply-and-add ***/
2233 /* fmadd - fmadds */
2234 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
);
2235 /* fmsub - fmsubs */
2236 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
);
2237 /* fnmadd - fnmadds */
2238 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
);
2239 /* fnmsub - fnmsubs */
2240 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
);
2242 /*** Floating-Point round & convert ***/
2244 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
);
2246 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
);
2248 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
);
2249 #if defined(TARGET_PPC64)
2251 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
);
2253 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
);
2255 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
);
2259 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
);
2261 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
);
2263 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
);
2265 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
);
2267 /*** Floating-Point compare ***/
2269 GEN_HANDLER(fcmpo
, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT
)
2271 if (unlikely(!ctx
->fpu_enabled
)) {
2272 GEN_EXCP_NO_FP(ctx
);
2275 gen_reset_fpstatus();
2276 gen_helper_fcmpo(cpu_crf
[crfD(ctx
->opcode
)],
2277 cpu_fpr
[rA(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2278 gen_helper_float_check_status();
2282 GEN_HANDLER(fcmpu
, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT
)
2284 if (unlikely(!ctx
->fpu_enabled
)) {
2285 GEN_EXCP_NO_FP(ctx
);
2288 gen_reset_fpstatus();
2289 gen_helper_fcmpu(cpu_crf
[crfD(ctx
->opcode
)],
2290 cpu_fpr
[rA(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2291 gen_helper_float_check_status();
2294 /*** Floating-point move ***/
2296 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2297 GEN_FLOAT_B(abs
, 0x08, 0x08, 0, PPC_FLOAT
);
2300 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2301 GEN_HANDLER(fmr
, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT
)
2303 if (unlikely(!ctx
->fpu_enabled
)) {
2304 GEN_EXCP_NO_FP(ctx
);
2307 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpr
[rB(ctx
->opcode
)]);
2308 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2312 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2313 GEN_FLOAT_B(nabs
, 0x08, 0x04, 0, PPC_FLOAT
);
2315 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2316 GEN_FLOAT_B(neg
, 0x08, 0x01, 0, PPC_FLOAT
);
2318 /*** Floating-Point status & ctrl register ***/
2320 GEN_HANDLER(mcrfs
, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT
)
2324 if (unlikely(!ctx
->fpu_enabled
)) {
2325 GEN_EXCP_NO_FP(ctx
);
2328 gen_optimize_fprf();
2329 bfa
= 4 * (7 - crfS(ctx
->opcode
));
2330 tcg_gen_shri_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_fpscr
, bfa
);
2331 tcg_gen_andi_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfD(ctx
->opcode
)], 0xf);
2332 tcg_gen_andi_i32(cpu_fpscr
, cpu_fpscr
, ~(0xF << bfa
));
2336 GEN_HANDLER(mffs
, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT
)
2338 if (unlikely(!ctx
->fpu_enabled
)) {
2339 GEN_EXCP_NO_FP(ctx
);
2342 gen_optimize_fprf();
2343 gen_reset_fpstatus();
2344 tcg_gen_extu_i32_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_fpscr
);
2345 gen_compute_fprf(cpu_fpr
[rD(ctx
->opcode
)], 0, Rc(ctx
->opcode
) != 0);
2349 GEN_HANDLER(mtfsb0
, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT
)
2353 if (unlikely(!ctx
->fpu_enabled
)) {
2354 GEN_EXCP_NO_FP(ctx
);
2357 crb
= 32 - (crbD(ctx
->opcode
) >> 2);
2358 gen_optimize_fprf();
2359 gen_reset_fpstatus();
2360 if (likely(crb
!= 30 && crb
!= 29))
2361 tcg_gen_andi_i32(cpu_fpscr
, cpu_fpscr
, ~(1 << crb
));
2362 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2363 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2368 GEN_HANDLER(mtfsb1
, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT
)
2372 if (unlikely(!ctx
->fpu_enabled
)) {
2373 GEN_EXCP_NO_FP(ctx
);
2376 crb
= 32 - (crbD(ctx
->opcode
) >> 2);
2377 gen_optimize_fprf();
2378 gen_reset_fpstatus();
2379 /* XXX: we pretend we can only do IEEE floating-point computations */
2380 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
&& crb
!= FPSCR_NI
)) {
2381 TCGv_i32 t0
= tcg_const_i32(crb
);
2382 gen_helper_fpscr_setbit(t0
);
2383 tcg_temp_free_i32(t0
);
2385 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2386 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2388 /* We can raise a differed exception */
2389 gen_helper_float_check_status();
2393 GEN_HANDLER(mtfsf
, 0x3F, 0x07, 0x16, 0x02010000, PPC_FLOAT
)
2397 if (unlikely(!ctx
->fpu_enabled
)) {
2398 GEN_EXCP_NO_FP(ctx
);
2401 gen_optimize_fprf();
2402 gen_reset_fpstatus();
2403 t0
= tcg_const_i32(FM(ctx
->opcode
));
2404 gen_helper_store_fpscr(cpu_fpr
[rB(ctx
->opcode
)], t0
);
2405 tcg_temp_free_i32(t0
);
2406 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2407 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2409 /* We can raise a differed exception */
2410 gen_helper_float_check_status();
2414 GEN_HANDLER(mtfsfi
, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT
)
2420 if (unlikely(!ctx
->fpu_enabled
)) {
2421 GEN_EXCP_NO_FP(ctx
);
2424 bf
= crbD(ctx
->opcode
) >> 2;
2426 gen_optimize_fprf();
2427 gen_reset_fpstatus();
2428 t0
= tcg_const_i64(FPIMM(ctx
->opcode
) << (4 * sh
));
2429 t1
= tcg_const_i32(1 << sh
);
2430 gen_helper_store_fpscr(t0
, t1
);
2431 tcg_temp_free_i64(t0
);
2432 tcg_temp_free_i32(t1
);
2433 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2434 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2436 /* We can raise a differed exception */
2437 gen_helper_float_check_status();
2440 /*** Addressing modes ***/
2441 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2442 static always_inline
void gen_addr_imm_index (TCGv EA
,
2446 target_long simm
= SIMM(ctx
->opcode
);
2449 if (rA(ctx
->opcode
) == 0)
2450 tcg_gen_movi_tl(EA
, simm
);
2451 else if (likely(simm
!= 0))
2452 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
);
2454 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2457 static always_inline
void gen_addr_reg_index (TCGv EA
,
2460 if (rA(ctx
->opcode
) == 0)
2461 tcg_gen_mov_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2463 tcg_gen_add_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2466 static always_inline
void gen_addr_register (TCGv EA
,
2469 if (rA(ctx
->opcode
) == 0)
2470 tcg_gen_movi_tl(EA
, 0);
2472 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2475 static always_inline
void gen_check_align (DisasContext
*ctx
, TCGv EA
, int mask
)
2477 int l1
= gen_new_label();
2478 TCGv t0
= tcg_temp_new();
2480 /* NIP cannot be restored if the memory exception comes from an helper */
2481 gen_update_nip(ctx
, ctx
->nip
- 4);
2482 tcg_gen_andi_tl(t0
, EA
, mask
);
2483 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2484 t1
= tcg_const_i32(POWERPC_EXCP_ALIGN
);
2485 t2
= tcg_const_i32(0);
2486 gen_helper_raise_exception_err(t1
, t2
);
2487 tcg_temp_free_i32(t1
);
2488 tcg_temp_free_i32(t2
);
2493 #if defined(TARGET_PPC64)
2494 #define _GEN_MEM_FUNCS(name, mode) \
2495 &gen_op_##name##_##mode, \
2496 &gen_op_##name##_le_##mode, \
2497 &gen_op_##name##_64_##mode, \
2498 &gen_op_##name##_le_64_##mode
2500 #define _GEN_MEM_FUNCS(name, mode) \
2501 &gen_op_##name##_##mode, \
2502 &gen_op_##name##_le_##mode
2504 #if defined(CONFIG_USER_ONLY)
2505 #if defined(TARGET_PPC64)
2506 #define NB_MEM_FUNCS 4
2508 #define NB_MEM_FUNCS 2
2510 #define GEN_MEM_FUNCS(name) \
2511 _GEN_MEM_FUNCS(name, raw)
2513 #if defined(TARGET_PPC64)
2514 #define NB_MEM_FUNCS 12
2516 #define NB_MEM_FUNCS 6
2518 #define GEN_MEM_FUNCS(name) \
2519 _GEN_MEM_FUNCS(name, user), \
2520 _GEN_MEM_FUNCS(name, kernel), \
2521 _GEN_MEM_FUNCS(name, hypv)
2524 /*** Integer load ***/
2525 #if defined(TARGET_PPC64)
2526 #define GEN_QEMU_LD_PPC64(width) \
2527 static always_inline void gen_qemu_ld##width##_ppc64(TCGv t0, TCGv t1, int flags)\
2529 if (likely(flags & 2)) \
2530 tcg_gen_qemu_ld##width(t0, t1, flags >> 2); \
2532 TCGv addr = tcg_temp_new(); \
2533 tcg_gen_ext32u_tl(addr, t1); \
2534 tcg_gen_qemu_ld##width(t0, addr, flags >> 2); \
2535 tcg_temp_free(addr); \
2538 GEN_QEMU_LD_PPC64(8u)
2539 GEN_QEMU_LD_PPC64(8s
)
2540 GEN_QEMU_LD_PPC64(16u)
2541 GEN_QEMU_LD_PPC64(16s
)
2542 GEN_QEMU_LD_PPC64(32u)
2543 GEN_QEMU_LD_PPC64(32s
)
2544 GEN_QEMU_LD_PPC64(64)
2546 #define GEN_QEMU_ST_PPC64(width) \
2547 static always_inline void gen_qemu_st##width##_ppc64(TCGv t0, TCGv t1, int flags)\
2549 if (likely(flags & 2)) \
2550 tcg_gen_qemu_st##width(t0, t1, flags >> 2); \
2552 TCGv addr = tcg_temp_new(); \
2553 tcg_gen_ext32u_tl(addr, t1); \
2554 tcg_gen_qemu_st##width(t0, addr, flags >> 2); \
2555 tcg_temp_free(addr); \
2558 GEN_QEMU_ST_PPC64(8)
2559 GEN_QEMU_ST_PPC64(16)
2560 GEN_QEMU_ST_PPC64(32)
2561 GEN_QEMU_ST_PPC64(64)
2563 static always_inline
void gen_qemu_ld8u(TCGv arg0
, TCGv arg1
, int flags
)
2565 gen_qemu_ld8u_ppc64(arg0
, arg1
, flags
);
2568 static always_inline
void gen_qemu_ld8s(TCGv arg0
, TCGv arg1
, int flags
)
2570 gen_qemu_ld8s_ppc64(arg0
, arg1
, flags
);
2573 static always_inline
void gen_qemu_ld16u(TCGv arg0
, TCGv arg1
, int flags
)
2575 if (unlikely(flags
& 1)) {
2577 gen_qemu_ld16u_ppc64(arg0
, arg1
, flags
);
2578 t0
= tcg_temp_new_i32();
2579 tcg_gen_trunc_tl_i32(t0
, arg0
);
2580 tcg_gen_bswap16_i32(t0
, t0
);
2581 tcg_gen_extu_i32_tl(arg0
, t0
);
2582 tcg_temp_free_i32(t0
);
2584 gen_qemu_ld16u_ppc64(arg0
, arg1
, flags
);
2587 static always_inline
void gen_qemu_ld16s(TCGv arg0
, TCGv arg1
, int flags
)
2589 if (unlikely(flags
& 1)) {
2591 gen_qemu_ld16u_ppc64(arg0
, arg1
, flags
);
2592 t0
= tcg_temp_new_i32();
2593 tcg_gen_trunc_tl_i32(t0
, arg0
);
2594 tcg_gen_bswap16_i32(t0
, t0
);
2595 tcg_gen_extu_i32_tl(arg0
, t0
);
2596 tcg_gen_ext16s_tl(arg0
, arg0
);
2597 tcg_temp_free_i32(t0
);
2599 gen_qemu_ld16s_ppc64(arg0
, arg1
, flags
);
2602 static always_inline
void gen_qemu_ld32u(TCGv arg0
, TCGv arg1
, int flags
)
2604 if (unlikely(flags
& 1)) {
2606 gen_qemu_ld32u_ppc64(arg0
, arg1
, flags
);
2607 t0
= tcg_temp_new_i32();
2608 tcg_gen_trunc_tl_i32(t0
, arg0
);
2609 tcg_gen_bswap_i32(t0
, t0
);
2610 tcg_gen_extu_i32_tl(arg0
, t0
);
2611 tcg_temp_free_i32(t0
);
2613 gen_qemu_ld32u_ppc64(arg0
, arg1
, flags
);
2616 static always_inline
void gen_qemu_ld32s(TCGv arg0
, TCGv arg1
, int flags
)
2618 if (unlikely(flags
& 1)) {
2620 gen_qemu_ld32u_ppc64(arg0
, arg1
, flags
);
2621 t0
= tcg_temp_new_i32();
2622 tcg_gen_trunc_tl_i32(t0
, arg0
);
2623 tcg_gen_bswap_i32(t0
, t0
);
2624 tcg_gen_ext_i32_tl(arg0
, t0
);
2625 tcg_temp_free_i32(t0
);
2627 gen_qemu_ld32s_ppc64(arg0
, arg1
, flags
);
2630 static always_inline
void gen_qemu_ld64(TCGv arg0
, TCGv arg1
, int flags
)
2632 gen_qemu_ld64_ppc64(arg0
, arg1
, flags
);
2633 if (unlikely(flags
& 1))
2634 tcg_gen_bswap_i64(arg0
, arg0
);
2637 static always_inline
void gen_qemu_st8(TCGv arg0
, TCGv arg1
, int flags
)
2639 gen_qemu_st8_ppc64(arg0
, arg1
, flags
);
2642 static always_inline
void gen_qemu_st16(TCGv arg0
, TCGv arg1
, int flags
)
2644 if (unlikely(flags
& 1)) {
2647 t0
= tcg_temp_new_i32();
2648 tcg_gen_trunc_tl_i32(t0
, arg0
);
2649 tcg_gen_ext16u_i32(t0
, t0
);
2650 tcg_gen_bswap16_i32(t0
, t0
);
2651 t1
= tcg_temp_new_i64();
2652 tcg_gen_extu_i32_tl(t1
, t0
);
2653 tcg_temp_free_i32(t0
);
2654 gen_qemu_st16_ppc64(t1
, arg1
, flags
);
2655 tcg_temp_free_i64(t1
);
2657 gen_qemu_st16_ppc64(arg0
, arg1
, flags
);
2660 static always_inline
void gen_qemu_st32(TCGv arg0
, TCGv arg1
, int flags
)
2662 if (unlikely(flags
& 1)) {
2665 t0
= tcg_temp_new_i32();
2666 tcg_gen_trunc_tl_i32(t0
, arg0
);
2667 tcg_gen_bswap_i32(t0
, t0
);
2668 t1
= tcg_temp_new_i64();
2669 tcg_gen_extu_i32_tl(t1
, t0
);
2670 tcg_temp_free_i32(t0
);
2671 gen_qemu_st32_ppc64(t1
, arg1
, flags
);
2672 tcg_temp_free_i64(t1
);
2674 gen_qemu_st32_ppc64(arg0
, arg1
, flags
);
2677 static always_inline
void gen_qemu_st64(TCGv arg0
, TCGv arg1
, int flags
)
2679 if (unlikely(flags
& 1)) {
2680 TCGv_i64 t0
= tcg_temp_new_i64();
2681 tcg_gen_bswap_i64(t0
, arg0
);
2682 gen_qemu_st64_ppc64(t0
, arg1
, flags
);
2683 tcg_temp_free_i64(t0
);
2685 gen_qemu_st64_ppc64(arg0
, arg1
, flags
);
2689 #else /* defined(TARGET_PPC64) */
2690 #define GEN_QEMU_LD_PPC32(width) \
2691 static always_inline void gen_qemu_ld##width##_ppc32(TCGv arg0, TCGv arg1, int flags) \
2693 tcg_gen_qemu_ld##width(arg0, arg1, flags >> 1); \
2695 GEN_QEMU_LD_PPC32(8u)
2696 GEN_QEMU_LD_PPC32(8s
)
2697 GEN_QEMU_LD_PPC32(16u)
2698 GEN_QEMU_LD_PPC32(16s
)
2699 GEN_QEMU_LD_PPC32(32u)
2700 GEN_QEMU_LD_PPC32(32s
)
2701 static always_inline
void gen_qemu_ld64_ppc32(TCGv_i64 arg0
, TCGv arg1
, int flags
)
2703 tcg_gen_qemu_ld64(arg0
, arg1
, flags
>> 1);
2706 #define GEN_QEMU_ST_PPC32(width) \
2707 static always_inline void gen_qemu_st##width##_ppc32(TCGv arg0, TCGv arg1, int flags) \
2709 tcg_gen_qemu_st##width(arg0, arg1, flags >> 1); \
2711 GEN_QEMU_ST_PPC32(8)
2712 GEN_QEMU_ST_PPC32(16)
2713 GEN_QEMU_ST_PPC32(32)
2714 static always_inline
void gen_qemu_st64_ppc32(TCGv_i64 arg0
, TCGv arg1
, int flags
)
2716 tcg_gen_qemu_st64(arg0
, arg1
, flags
>> 1);
2719 static always_inline
void gen_qemu_ld8u(TCGv arg0
, TCGv arg1
, int flags
)
2721 gen_qemu_ld8u_ppc32(arg0
, arg1
, flags
>> 1);
2724 static always_inline
void gen_qemu_ld8s(TCGv arg0
, TCGv arg1
, int flags
)
2726 gen_qemu_ld8s_ppc32(arg0
, arg1
, flags
>> 1);
2729 static always_inline
void gen_qemu_ld16u(TCGv arg0
, TCGv arg1
, int flags
)
2731 gen_qemu_ld16u_ppc32(arg0
, arg1
, flags
>> 1);
2732 if (unlikely(flags
& 1))
2733 tcg_gen_bswap16_i32(arg0
, arg0
);
2736 static always_inline
void gen_qemu_ld16s(TCGv arg0
, TCGv arg1
, int flags
)
2738 if (unlikely(flags
& 1)) {
2739 gen_qemu_ld16u_ppc32(arg0
, arg1
, flags
);
2740 tcg_gen_bswap16_i32(arg0
, arg0
);
2741 tcg_gen_ext16s_i32(arg0
, arg0
);
2743 gen_qemu_ld16s_ppc32(arg0
, arg1
, flags
);
2746 static always_inline
void gen_qemu_ld32u(TCGv arg0
, TCGv arg1
, int flags
)
2748 gen_qemu_ld32u_ppc32(arg0
, arg1
, flags
);
2749 if (unlikely(flags
& 1))
2750 tcg_gen_bswap_i32(arg0
, arg0
);
2753 static always_inline
void gen_qemu_ld64(TCGv_i64 arg0
, TCGv arg1
, int flags
)
2755 gen_qemu_ld64_ppc32(arg0
, arg1
, flags
);
2756 if (unlikely(flags
& 1))
2757 tcg_gen_bswap_i64(arg0
, arg0
);
2760 static always_inline
void gen_qemu_st8(TCGv arg0
, TCGv arg1
, int flags
)
2762 gen_qemu_st8_ppc32(arg0
, arg1
, flags
);
2765 static always_inline
void gen_qemu_st16(TCGv arg0
, TCGv arg1
, int flags
)
2767 if (unlikely(flags
& 1)) {
2768 TCGv_i32 temp
= tcg_temp_new_i32();
2769 tcg_gen_ext16u_i32(temp
, arg0
);
2770 tcg_gen_bswap16_i32(temp
, temp
);
2771 gen_qemu_st16_ppc32(temp
, arg1
, flags
);
2772 tcg_temp_free_i32(temp
);
2774 gen_qemu_st16_ppc32(arg0
, arg1
, flags
);
2777 static always_inline
void gen_qemu_st32(TCGv arg0
, TCGv arg1
, int flags
)
2779 if (unlikely(flags
& 1)) {
2780 TCGv_i32 temp
= tcg_temp_new_i32();
2781 tcg_gen_bswap_i32(temp
, arg0
);
2782 gen_qemu_st32_ppc32(temp
, arg1
, flags
);
2783 tcg_temp_free_i32(temp
);
2785 gen_qemu_st32_ppc32(arg0
, arg1
, flags
);
2788 static always_inline
void gen_qemu_st64(TCGv_i64 arg0
, TCGv arg1
, int flags
)
2790 if (unlikely(flags
& 1)) {
2791 TCGv_i64 temp
= tcg_temp_new_i64();
2792 tcg_gen_bswap_i64(temp
, arg0
);
2793 gen_qemu_st64_ppc32(temp
, arg1
, flags
);
2794 tcg_temp_free_i64(temp
);
2796 gen_qemu_st64_ppc32(arg0
, arg1
, flags
);
2800 #define GEN_LD(name, ldop, opc, type) \
2801 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type) \
2803 TCGv EA = tcg_temp_new(); \
2804 gen_set_access_type(ACCESS_INT); \
2805 gen_addr_imm_index(EA, ctx, 0); \
2806 gen_qemu_##ldop(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2807 tcg_temp_free(EA); \
2810 #define GEN_LDU(name, ldop, opc, type) \
2811 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2814 if (unlikely(rA(ctx->opcode) == 0 || \
2815 rA(ctx->opcode) == rD(ctx->opcode))) { \
2816 GEN_EXCP_INVAL(ctx); \
2819 EA = tcg_temp_new(); \
2820 gen_set_access_type(ACCESS_INT); \
2821 if (type == PPC_64B) \
2822 gen_addr_imm_index(EA, ctx, 0x03); \
2824 gen_addr_imm_index(EA, ctx, 0); \
2825 gen_qemu_##ldop(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2826 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2827 tcg_temp_free(EA); \
2830 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
2831 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2834 if (unlikely(rA(ctx->opcode) == 0 || \
2835 rA(ctx->opcode) == rD(ctx->opcode))) { \
2836 GEN_EXCP_INVAL(ctx); \
2839 EA = tcg_temp_new(); \
2840 gen_set_access_type(ACCESS_INT); \
2841 gen_addr_reg_index(EA, ctx); \
2842 gen_qemu_##ldop(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2843 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2844 tcg_temp_free(EA); \
2847 #define GEN_LDX(name, ldop, opc2, opc3, type) \
2848 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type) \
2850 TCGv EA = tcg_temp_new(); \
2851 gen_set_access_type(ACCESS_INT); \
2852 gen_addr_reg_index(EA, ctx); \
2853 gen_qemu_##ldop(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2854 tcg_temp_free(EA); \
2857 #define GEN_LDS(name, ldop, op, type) \
2858 GEN_LD(name, ldop, op | 0x20, type); \
2859 GEN_LDU(name, ldop, op | 0x21, type); \
2860 GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
2861 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
2863 /* lbz lbzu lbzux lbzx */
2864 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
);
2865 /* lha lhau lhaux lhax */
2866 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
);
2867 /* lhz lhzu lhzux lhzx */
2868 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
);
2869 /* lwz lwzu lwzux lwzx */
2870 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
);
2871 #if defined(TARGET_PPC64)
2873 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
);
2875 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
);
2877 GEN_LDUX(ld
, ld64
, 0x15, 0x01, PPC_64B
);
2879 GEN_LDX(ld
, ld64
, 0x15, 0x00, PPC_64B
);
2880 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
)
2883 if (Rc(ctx
->opcode
)) {
2884 if (unlikely(rA(ctx
->opcode
) == 0 ||
2885 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
2886 GEN_EXCP_INVAL(ctx
);
2890 EA
= tcg_temp_new();
2891 gen_set_access_type(ACCESS_INT
);
2892 gen_addr_imm_index(EA
, ctx
, 0x03);
2893 if (ctx
->opcode
& 0x02) {
2894 /* lwa (lwau is undefined) */
2895 gen_qemu_ld32s(cpu_gpr
[rD(ctx
->opcode
)], EA
, ctx
->mem_idx
);
2898 gen_qemu_ld64(cpu_gpr
[rD(ctx
->opcode
)], EA
, ctx
->mem_idx
);
2900 if (Rc(ctx
->opcode
))
2901 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2905 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
)
2907 #if defined(CONFIG_USER_ONLY)
2908 GEN_EXCP_PRIVOPC(ctx
);
2913 /* Restore CPU state */
2914 if (unlikely(ctx
->supervisor
== 0)) {
2915 GEN_EXCP_PRIVOPC(ctx
);
2918 ra
= rA(ctx
->opcode
);
2919 rd
= rD(ctx
->opcode
);
2920 if (unlikely((rd
& 1) || rd
== ra
)) {
2921 GEN_EXCP_INVAL(ctx
);
2924 if (unlikely(ctx
->mem_idx
& 1)) {
2925 /* Little-endian mode is not handled */
2926 GEN_EXCP(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2929 EA
= tcg_temp_new();
2930 gen_set_access_type(ACCESS_INT
);
2931 gen_addr_imm_index(EA
, ctx
, 0x0F);
2932 gen_qemu_ld64(cpu_gpr
[rd
], EA
, ctx
->mem_idx
);
2933 tcg_gen_addi_tl(EA
, EA
, 8);
2934 gen_qemu_ld64(cpu_gpr
[rd
+1], EA
, ctx
->mem_idx
);
2940 /*** Integer store ***/
2941 #define GEN_ST(name, stop, opc, type) \
2942 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type) \
2944 TCGv EA = tcg_temp_new(); \
2945 gen_set_access_type(ACCESS_INT); \
2946 gen_addr_imm_index(EA, ctx, 0); \
2947 gen_qemu_##stop(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
2948 tcg_temp_free(EA); \
2951 #define GEN_STU(name, stop, opc, type) \
2952 GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2955 if (unlikely(rA(ctx->opcode) == 0)) { \
2956 GEN_EXCP_INVAL(ctx); \
2959 EA = tcg_temp_new(); \
2960 gen_set_access_type(ACCESS_INT); \
2961 if (type == PPC_64B) \
2962 gen_addr_imm_index(EA, ctx, 0x03); \
2964 gen_addr_imm_index(EA, ctx, 0); \
2965 gen_qemu_##stop(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
2966 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2967 tcg_temp_free(EA); \
2970 #define GEN_STUX(name, stop, opc2, opc3, type) \
2971 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2974 if (unlikely(rA(ctx->opcode) == 0)) { \
2975 GEN_EXCP_INVAL(ctx); \
2978 EA = tcg_temp_new(); \
2979 gen_set_access_type(ACCESS_INT); \
2980 gen_addr_reg_index(EA, ctx); \
2981 gen_qemu_##stop(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
2982 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2983 tcg_temp_free(EA); \
2986 #define GEN_STX(name, stop, opc2, opc3, type) \
2987 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type) \
2989 TCGv EA = tcg_temp_new(); \
2990 gen_set_access_type(ACCESS_INT); \
2991 gen_addr_reg_index(EA, ctx); \
2992 gen_qemu_##stop(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
2993 tcg_temp_free(EA); \
2996 #define GEN_STS(name, stop, op, type) \
2997 GEN_ST(name, stop, op | 0x20, type); \
2998 GEN_STU(name, stop, op | 0x21, type); \
2999 GEN_STUX(name, stop, 0x17, op | 0x01, type); \
3000 GEN_STX(name, stop, 0x17, op | 0x00, type)
3002 /* stb stbu stbux stbx */
3003 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
);
3004 /* sth sthu sthux sthx */
3005 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
);
3006 /* stw stwu stwux stwx */
3007 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
);
3008 #if defined(TARGET_PPC64)
3009 GEN_STUX(std
, st64
, 0x15, 0x05, PPC_64B
);
3010 GEN_STX(std
, st64
, 0x15, 0x04, PPC_64B
);
3011 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
)
3016 rs
= rS(ctx
->opcode
);
3017 if ((ctx
->opcode
& 0x3) == 0x2) {
3018 #if defined(CONFIG_USER_ONLY)
3019 GEN_EXCP_PRIVOPC(ctx
);
3022 if (unlikely(ctx
->supervisor
== 0)) {
3023 GEN_EXCP_PRIVOPC(ctx
);
3026 if (unlikely(rs
& 1)) {
3027 GEN_EXCP_INVAL(ctx
);
3030 if (unlikely(ctx
->mem_idx
& 1)) {
3031 /* Little-endian mode is not handled */
3032 GEN_EXCP(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
3035 EA
= tcg_temp_new();
3036 gen_set_access_type(ACCESS_INT
);
3037 gen_addr_imm_index(EA
, ctx
, 0x03);
3038 gen_qemu_st64(cpu_gpr
[rs
], EA
, ctx
->mem_idx
);
3039 tcg_gen_addi_tl(EA
, EA
, 8);
3040 gen_qemu_st64(cpu_gpr
[rs
+1], EA
, ctx
->mem_idx
);
3045 if (Rc(ctx
->opcode
)) {
3046 if (unlikely(rA(ctx
->opcode
) == 0)) {
3047 GEN_EXCP_INVAL(ctx
);
3051 EA
= tcg_temp_new();
3052 gen_set_access_type(ACCESS_INT
);
3053 gen_addr_imm_index(EA
, ctx
, 0x03);
3054 gen_qemu_st64(cpu_gpr
[rs
], EA
, ctx
->mem_idx
);
3055 if (Rc(ctx
->opcode
))
3056 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
3061 /*** Integer load and store with byte reverse ***/
3063 void always_inline
gen_qemu_ld16ur(TCGv t0
, TCGv t1
, int flags
)
3065 TCGv_i32 temp
= tcg_temp_new_i32();
3066 gen_qemu_ld16u(t0
, t1
, flags
);
3067 tcg_gen_trunc_tl_i32(temp
, t0
);
3068 tcg_gen_bswap16_i32(temp
, temp
);
3069 tcg_gen_extu_i32_tl(t0
, temp
);
3070 tcg_temp_free_i32(temp
);
3072 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
);
3075 void always_inline
gen_qemu_ld32ur(TCGv t0
, TCGv t1
, int flags
)
3077 TCGv_i32 temp
= tcg_temp_new_i32();
3078 gen_qemu_ld32u(t0
, t1
, flags
);
3079 tcg_gen_trunc_tl_i32(temp
, t0
);
3080 tcg_gen_bswap_i32(temp
, temp
);
3081 tcg_gen_extu_i32_tl(t0
, temp
);
3082 tcg_temp_free_i32(temp
);
3084 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
);
3087 void always_inline
gen_qemu_st16r(TCGv t0
, TCGv t1
, int flags
)
3089 TCGv_i32 temp
= tcg_temp_new_i32();
3090 TCGv t2
= tcg_temp_new();
3091 tcg_gen_trunc_tl_i32(temp
, t0
);
3092 tcg_gen_ext16u_i32(temp
, temp
);
3093 tcg_gen_bswap16_i32(temp
, temp
);
3094 tcg_gen_extu_i32_tl(t2
, temp
);
3095 tcg_temp_free_i32(temp
);
3096 gen_qemu_st16(t2
, t1
, flags
);
3099 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
);
3102 void always_inline
gen_qemu_st32r(TCGv t0
, TCGv t1
, int flags
)
3104 TCGv_i32 temp
= tcg_temp_new_i32();
3105 TCGv t2
= tcg_temp_new();
3106 tcg_gen_trunc_tl_i32(temp
, t0
);
3107 tcg_gen_bswap_i32(temp
, temp
);
3108 tcg_gen_extu_i32_tl(t2
, temp
);
3109 tcg_temp_free_i32(temp
);
3110 gen_qemu_st32(t2
, t1
, flags
);
3113 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
);
3115 /*** Integer load and store multiple ***/
3117 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
3119 TCGv t0
= tcg_temp_new();
3120 TCGv_i32 t1
= tcg_const_i32(rD(ctx
->opcode
));
3121 /* NIP cannot be restored if the memory exception comes from an helper */
3122 gen_update_nip(ctx
, ctx
->nip
- 4);
3123 gen_addr_imm_index(t0
, ctx
, 0);
3124 gen_helper_lmw(t0
, t1
);
3126 tcg_temp_free_i32(t1
);
3130 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
3132 TCGv t0
= tcg_temp_new();
3133 TCGv_i32 t1
= tcg_const_i32(rS(ctx
->opcode
));
3134 /* NIP cannot be restored if the memory exception comes from an helper */
3135 gen_update_nip(ctx
, ctx
->nip
- 4);
3136 gen_addr_imm_index(t0
, ctx
, 0);
3137 gen_helper_stmw(t0
, t1
);
3139 tcg_temp_free_i32(t1
);
3142 /*** Integer load and store strings ***/
3144 /* PowerPC32 specification says we must generate an exception if
3145 * rA is in the range of registers to be loaded.
3146 * In an other hand, IBM says this is valid, but rA won't be loaded.
3147 * For now, I'll follow the spec...
3149 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
)
3153 int nb
= NB(ctx
->opcode
);
3154 int start
= rD(ctx
->opcode
);
3155 int ra
= rA(ctx
->opcode
);
3161 if (unlikely(((start
+ nr
) > 32 &&
3162 start
<= ra
&& (start
+ nr
- 32) > ra
) ||
3163 ((start
+ nr
) <= 32 && start
<= ra
&& (start
+ nr
) > ra
))) {
3164 GEN_EXCP(ctx
, POWERPC_EXCP_PROGRAM
,
3165 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_LSWX
);
3168 /* NIP cannot be restored if the memory exception comes from an helper */
3169 gen_update_nip(ctx
, ctx
->nip
- 4);
3170 t0
= tcg_temp_new();
3171 gen_addr_register(t0
, ctx
);
3172 t1
= tcg_const_i32(nb
);
3173 t2
= tcg_const_i32(start
);
3174 gen_helper_lsw(t0
, t1
, t2
);
3176 tcg_temp_free_i32(t1
);
3177 tcg_temp_free_i32(t2
);
3181 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
)
3183 TCGv t0
= tcg_temp_new();
3184 TCGv_i32 t1
= tcg_const_i32(rD(ctx
->opcode
));
3185 TCGv_i32 t2
= tcg_const_i32(rA(ctx
->opcode
));
3186 TCGv_i32 t3
= tcg_const_i32(rB(ctx
->opcode
));
3187 /* NIP cannot be restored if the memory exception comes from an helper */
3188 gen_update_nip(ctx
, ctx
->nip
- 4);
3189 gen_addr_reg_index(t0
, ctx
);
3190 gen_helper_lswx(t0
, t1
, t2
, t3
);
3192 tcg_temp_free_i32(t1
);
3193 tcg_temp_free_i32(t2
);
3194 tcg_temp_free_i32(t3
);
3198 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
)
3200 int nb
= NB(ctx
->opcode
);
3201 TCGv t0
= tcg_temp_new();
3203 TCGv_i32 t2
= tcg_const_i32(rS(ctx
->opcode
));
3204 /* NIP cannot be restored if the memory exception comes from an helper */
3205 gen_update_nip(ctx
, ctx
->nip
- 4);
3206 gen_addr_register(t0
, ctx
);
3209 t1
= tcg_const_i32(nb
);
3210 gen_helper_stsw(t0
, t1
, t2
);
3212 tcg_temp_free_i32(t1
);
3213 tcg_temp_free_i32(t2
);
3217 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
)
3219 TCGv t0
= tcg_temp_new();
3220 TCGv_i32 t1
= tcg_temp_new_i32();
3221 TCGv_i32 t2
= tcg_const_i32(rS(ctx
->opcode
));
3222 /* NIP cannot be restored if the memory exception comes from an helper */
3223 gen_update_nip(ctx
, ctx
->nip
- 4);
3224 gen_addr_reg_index(t0
, ctx
);
3225 tcg_gen_trunc_tl_i32(t1
, cpu_xer
);
3226 tcg_gen_andi_i32(t1
, t1
, 0x7F);
3227 gen_helper_stsw(t0
, t1
, t2
);
3229 tcg_temp_free_i32(t1
);
3230 tcg_temp_free_i32(t2
);
3233 /*** Memory synchronisation ***/
3235 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO
)
3240 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
)
3246 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000001, PPC_RES
)
3248 TCGv t0
= tcg_temp_local_new();
3249 gen_set_access_type(ACCESS_RES
);
3250 gen_addr_reg_index(t0
, ctx
);
3251 gen_check_align(ctx
, t0
, 0x03);
3252 #if defined(TARGET_PPC64)
3254 tcg_gen_ext32u_tl(t0
, t0
);
3256 gen_qemu_ld32u(cpu_gpr
[rD(ctx
->opcode
)], t0
, ctx
->mem_idx
);
3257 tcg_gen_mov_tl(cpu_reserve
, t0
);
3262 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
)
3264 int l1
= gen_new_label();
3265 TCGv t0
= tcg_temp_local_new();
3266 gen_set_access_type(ACCESS_RES
);
3267 gen_addr_reg_index(t0
, ctx
);
3268 gen_check_align(ctx
, t0
, 0x03);
3269 #if defined(TARGET_PPC64)
3271 tcg_gen_ext32u_tl(t0
, t0
);
3273 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_xer
);
3274 tcg_gen_shri_i32(cpu_crf
[0], cpu_crf
[0], XER_SO
);
3275 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 1);
3276 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
3277 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3278 gen_qemu_st32(cpu_gpr
[rS(ctx
->opcode
)], t0
, ctx
->mem_idx
);
3280 tcg_gen_movi_tl(cpu_reserve
, -1);
3284 #if defined(TARGET_PPC64)
3286 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000001, PPC_64B
)
3288 TCGv t0
= tcg_temp_local_new();
3289 gen_set_access_type(ACCESS_RES
);
3290 gen_addr_reg_index(t0
, ctx
);
3291 gen_check_align(ctx
, t0
, 0x07);
3293 tcg_gen_ext32u_tl(t0
, t0
);
3294 gen_qemu_ld64(cpu_gpr
[rD(ctx
->opcode
)], t0
, ctx
->mem_idx
);
3295 tcg_gen_mov_tl(cpu_reserve
, t0
);
3300 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
)
3302 int l1
= gen_new_label();
3303 TCGv t0
= tcg_temp_local_new();
3304 gen_set_access_type(ACCESS_RES
);
3305 gen_addr_reg_index(t0
, ctx
);
3306 gen_check_align(ctx
, t0
, 0x07);
3308 tcg_gen_ext32u_tl(t0
, t0
);
3309 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_xer
);
3310 tcg_gen_shri_i32(cpu_crf
[0], cpu_crf
[0], XER_SO
);
3311 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 1);
3312 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
3313 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 1 << CRF_EQ
);
3314 gen_qemu_st64(cpu_gpr
[rS(ctx
->opcode
)], t0
, ctx
->mem_idx
);
3316 tcg_gen_movi_tl(cpu_reserve
, -1);
3319 #endif /* defined(TARGET_PPC64) */
3322 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
)
3327 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
)
3329 TCGv_i32 t0
= tcg_temp_new_i32();
3330 tcg_gen_st_i32(t0
, cpu_env
, offsetof(CPUState
, halted
));
3331 tcg_temp_free_i32(t0
);
3332 /* Stop translation, as the CPU is supposed to sleep from now */
3333 GEN_EXCP(ctx
, EXCP_HLT
, 1);
3336 /*** Floating-point load ***/
3337 #define GEN_LDF(name, ldop, opc, type) \
3338 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type) \
3341 if (unlikely(!ctx->fpu_enabled)) { \
3342 GEN_EXCP_NO_FP(ctx); \
3345 gen_set_access_type(ACCESS_FLOAT); \
3346 EA = tcg_temp_new(); \
3347 gen_addr_imm_index(EA, ctx, 0); \
3348 gen_qemu_##ldop(cpu_fpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
3349 tcg_temp_free(EA); \
3352 #define GEN_LDUF(name, ldop, opc, type) \
3353 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type) \
3356 if (unlikely(!ctx->fpu_enabled)) { \
3357 GEN_EXCP_NO_FP(ctx); \
3360 if (unlikely(rA(ctx->opcode) == 0)) { \
3361 GEN_EXCP_INVAL(ctx); \
3364 gen_set_access_type(ACCESS_FLOAT); \
3365 EA = tcg_temp_new(); \
3366 gen_addr_imm_index(EA, ctx, 0); \
3367 gen_qemu_##ldop(cpu_fpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
3368 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3369 tcg_temp_free(EA); \
3372 #define GEN_LDUXF(name, ldop, opc, type) \
3373 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type) \
3376 if (unlikely(!ctx->fpu_enabled)) { \
3377 GEN_EXCP_NO_FP(ctx); \
3380 if (unlikely(rA(ctx->opcode) == 0)) { \
3381 GEN_EXCP_INVAL(ctx); \
3384 gen_set_access_type(ACCESS_FLOAT); \
3385 EA = tcg_temp_new(); \
3386 gen_addr_reg_index(EA, ctx); \
3387 gen_qemu_##ldop(cpu_fpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
3388 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3389 tcg_temp_free(EA); \
3392 #define GEN_LDXF(name, ldop, opc2, opc3, type) \
3393 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type) \
3396 if (unlikely(!ctx->fpu_enabled)) { \
3397 GEN_EXCP_NO_FP(ctx); \
3400 gen_set_access_type(ACCESS_FLOAT); \
3401 EA = tcg_temp_new(); \
3402 gen_addr_reg_index(EA, ctx); \
3403 gen_qemu_##ldop(cpu_fpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
3404 tcg_temp_free(EA); \
3407 #define GEN_LDFS(name, ldop, op, type) \
3408 GEN_LDF(name, ldop, op | 0x20, type); \
3409 GEN_LDUF(name, ldop, op | 0x21, type); \
3410 GEN_LDUXF(name, ldop, op | 0x01, type); \
3411 GEN_LDXF(name, ldop, 0x17, op | 0x00, type)
3413 static always_inline
void gen_qemu_ld32fs(TCGv_i64 arg1
, TCGv arg2
, int flags
)
3415 TCGv t0
= tcg_temp_new();
3416 TCGv_i32 t1
= tcg_temp_new_i32();
3417 gen_qemu_ld32u(t0
, arg2
, flags
);
3418 tcg_gen_trunc_tl_i32(t1
, t0
);
3420 gen_helper_float32_to_float64(arg1
, t1
);
3421 tcg_temp_free_i32(t1
);
3424 /* lfd lfdu lfdux lfdx */
3425 GEN_LDFS(lfd
, ld64
, 0x12, PPC_FLOAT
);
3426 /* lfs lfsu lfsux lfsx */
3427 GEN_LDFS(lfs
, ld32fs
, 0x10, PPC_FLOAT
);
3429 /*** Floating-point store ***/
3430 #define GEN_STF(name, stop, opc, type) \
3431 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type) \
3434 if (unlikely(!ctx->fpu_enabled)) { \
3435 GEN_EXCP_NO_FP(ctx); \
3438 gen_set_access_type(ACCESS_FLOAT); \
3439 EA = tcg_temp_new(); \
3440 gen_addr_imm_index(EA, ctx, 0); \
3441 gen_qemu_##stop(cpu_fpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
3442 tcg_temp_free(EA); \
3445 #define GEN_STUF(name, stop, opc, type) \
3446 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type) \
3449 if (unlikely(!ctx->fpu_enabled)) { \
3450 GEN_EXCP_NO_FP(ctx); \
3453 if (unlikely(rA(ctx->opcode) == 0)) { \
3454 GEN_EXCP_INVAL(ctx); \
3457 gen_set_access_type(ACCESS_FLOAT); \
3458 EA = tcg_temp_new(); \
3459 gen_addr_imm_index(EA, ctx, 0); \
3460 gen_qemu_##stop(cpu_fpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
3461 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3462 tcg_temp_free(EA); \
3465 #define GEN_STUXF(name, stop, opc, type) \
3466 GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type) \
3469 if (unlikely(!ctx->fpu_enabled)) { \
3470 GEN_EXCP_NO_FP(ctx); \
3473 if (unlikely(rA(ctx->opcode) == 0)) { \
3474 GEN_EXCP_INVAL(ctx); \
3477 gen_set_access_type(ACCESS_FLOAT); \
3478 EA = tcg_temp_new(); \
3479 gen_addr_reg_index(EA, ctx); \
3480 gen_qemu_##stop(cpu_fpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
3481 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3482 tcg_temp_free(EA); \
3485 #define GEN_STXF(name, stop, opc2, opc3, type) \
3486 GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type) \
3489 if (unlikely(!ctx->fpu_enabled)) { \
3490 GEN_EXCP_NO_FP(ctx); \
3493 gen_set_access_type(ACCESS_FLOAT); \
3494 EA = tcg_temp_new(); \
3495 gen_addr_reg_index(EA, ctx); \
3496 gen_qemu_##stop(cpu_fpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
3497 tcg_temp_free(EA); \
3500 #define GEN_STFS(name, stop, op, type) \
3501 GEN_STF(name, stop, op | 0x20, type); \
3502 GEN_STUF(name, stop, op | 0x21, type); \
3503 GEN_STUXF(name, stop, op | 0x01, type); \
3504 GEN_STXF(name, stop, 0x17, op | 0x00, type)
3506 static always_inline
void gen_qemu_st32fs(TCGv_i64 arg1
, TCGv arg2
, int flags
)
3508 TCGv_i32 t0
= tcg_temp_new_i32();
3509 TCGv t1
= tcg_temp_new();
3510 gen_helper_float64_to_float32(t0
, arg1
);
3511 tcg_gen_extu_i32_tl(t1
, t0
);
3512 tcg_temp_free_i32(t0
);
3513 gen_qemu_st32(t1
, arg2
, flags
);
3517 /* stfd stfdu stfdux stfdx */
3518 GEN_STFS(stfd
, st64
, 0x16, PPC_FLOAT
);
3519 /* stfs stfsu stfsux stfsx */
3520 GEN_STFS(stfs
, st32fs
, 0x14, PPC_FLOAT
);
3523 static always_inline
void gen_qemu_st32fiw(TCGv_i64 arg1
, TCGv arg2
, int flags
)
3525 TCGv t0
= tcg_temp_new();
3526 tcg_gen_trunc_i64_tl(t0
, arg1
),
3527 gen_qemu_st32(t0
, arg2
, flags
);
3531 GEN_STXF(stfiw
, st32fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
);
3534 static always_inline
void gen_goto_tb (DisasContext
*ctx
, int n
,
3537 TranslationBlock
*tb
;
3539 #if defined(TARGET_PPC64)
3541 dest
= (uint32_t) dest
;
3543 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
3544 likely(!ctx
->singlestep_enabled
)) {
3546 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3547 tcg_gen_exit_tb((long)tb
+ n
);
3549 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3550 if (unlikely(ctx
->singlestep_enabled
)) {
3551 if ((ctx
->singlestep_enabled
&
3552 (CPU_BRANCH_STEP
| CPU_SINGLE_STEP
)) &&
3553 ctx
->exception
== POWERPC_EXCP_BRANCH
) {
3554 target_ulong tmp
= ctx
->nip
;
3556 GEN_EXCP(ctx
, POWERPC_EXCP_TRACE
, 0);
3559 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
3560 gen_update_nip(ctx
, dest
);
3561 gen_helper_raise_debug();
3568 static always_inline
void gen_setlr (DisasContext
*ctx
, target_ulong nip
)
3570 #if defined(TARGET_PPC64)
3571 if (ctx
->sf_mode
== 0)
3572 tcg_gen_movi_tl(cpu_lr
, (uint32_t)nip
);
3575 tcg_gen_movi_tl(cpu_lr
, nip
);
3579 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
3581 target_ulong li
, target
;
3583 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3584 /* sign extend LI */
3585 #if defined(TARGET_PPC64)
3587 li
= ((int64_t)LI(ctx
->opcode
) << 38) >> 38;
3590 li
= ((int32_t)LI(ctx
->opcode
) << 6) >> 6;
3591 if (likely(AA(ctx
->opcode
) == 0))
3592 target
= ctx
->nip
+ li
- 4;
3595 if (LK(ctx
->opcode
))
3596 gen_setlr(ctx
, ctx
->nip
);
3597 gen_goto_tb(ctx
, 0, target
);
3604 static always_inline
void gen_bcond (DisasContext
*ctx
, int type
)
3606 uint32_t bo
= BO(ctx
->opcode
);
3607 int l1
= gen_new_label();
3610 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3611 if (type
== BCOND_LR
|| type
== BCOND_CTR
) {
3612 target
= tcg_temp_local_new();
3613 if (type
== BCOND_CTR
)
3614 tcg_gen_mov_tl(target
, cpu_ctr
);
3616 tcg_gen_mov_tl(target
, cpu_lr
);
3618 if (LK(ctx
->opcode
))
3619 gen_setlr(ctx
, ctx
->nip
);
3620 l1
= gen_new_label();
3621 if ((bo
& 0x4) == 0) {
3622 /* Decrement and test CTR */
3623 TCGv temp
= tcg_temp_new();
3624 if (unlikely(type
== BCOND_CTR
)) {
3625 GEN_EXCP_INVAL(ctx
);
3628 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
3629 #if defined(TARGET_PPC64)
3631 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
3634 tcg_gen_mov_tl(temp
, cpu_ctr
);
3636 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
3638 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
3640 tcg_temp_free(temp
);
3642 if ((bo
& 0x10) == 0) {
3644 uint32_t bi
= BI(ctx
->opcode
);
3645 uint32_t mask
= 1 << (3 - (bi
& 0x03));
3646 TCGv_i32 temp
= tcg_temp_new_i32();
3649 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3650 tcg_gen_brcondi_i32(TCG_COND_EQ
, temp
, 0, l1
);
3652 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3653 tcg_gen_brcondi_i32(TCG_COND_NE
, temp
, 0, l1
);
3655 tcg_temp_free_i32(temp
);
3657 if (type
== BCOND_IM
) {
3658 target_ulong li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
3659 if (likely(AA(ctx
->opcode
) == 0)) {
3660 gen_goto_tb(ctx
, 0, ctx
->nip
+ li
- 4);
3662 gen_goto_tb(ctx
, 0, li
);
3665 gen_goto_tb(ctx
, 1, ctx
->nip
);
3667 #if defined(TARGET_PPC64)
3668 if (!(ctx
->sf_mode
))
3669 tcg_gen_andi_tl(cpu_nip
, target
, (uint32_t)~3);
3672 tcg_gen_andi_tl(cpu_nip
, target
, ~3);
3675 #if defined(TARGET_PPC64)
3676 if (!(ctx
->sf_mode
))
3677 tcg_gen_movi_tl(cpu_nip
, (uint32_t)ctx
->nip
);
3680 tcg_gen_movi_tl(cpu_nip
, ctx
->nip
);
3685 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
3687 gen_bcond(ctx
, BCOND_IM
);
3690 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
)
3692 gen_bcond(ctx
, BCOND_CTR
);
3695 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
)
3697 gen_bcond(ctx
, BCOND_LR
);
3700 /*** Condition register logical ***/
3701 #define GEN_CRLOGIC(name, tcg_op, opc) \
3702 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) \
3707 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3708 t0 = tcg_temp_new_i32(); \
3710 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
3712 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
3714 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
3715 t1 = tcg_temp_new_i32(); \
3716 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3718 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
3720 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
3722 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3723 tcg_op(t0, t0, t1); \
3724 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
3725 tcg_gen_andi_i32(t0, t0, bitmask); \
3726 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3727 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
3728 tcg_temp_free_i32(t0); \
3729 tcg_temp_free_i32(t1); \
3733 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08);
3735 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04);
3737 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09);
3739 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07);
3741 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01);
3743 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E);
3745 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D);
3747 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06);
3749 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
)
3751 tcg_gen_mov_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfS(ctx
->opcode
)]);
3754 /*** System linkage ***/
3755 /* rfi (supervisor only) */
3756 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
)
3758 #if defined(CONFIG_USER_ONLY)
3759 GEN_EXCP_PRIVOPC(ctx
);
3761 /* Restore CPU state */
3762 if (unlikely(!ctx
->supervisor
)) {
3763 GEN_EXCP_PRIVOPC(ctx
);
3771 #if defined(TARGET_PPC64)
3772 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
)
3774 #if defined(CONFIG_USER_ONLY)
3775 GEN_EXCP_PRIVOPC(ctx
);
3777 /* Restore CPU state */
3778 if (unlikely(!ctx
->supervisor
)) {
3779 GEN_EXCP_PRIVOPC(ctx
);
3787 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
)
3789 #if defined(CONFIG_USER_ONLY)
3790 GEN_EXCP_PRIVOPC(ctx
);
3792 /* Restore CPU state */
3793 if (unlikely(ctx
->supervisor
<= 1)) {
3794 GEN_EXCP_PRIVOPC(ctx
);
3804 #if defined(CONFIG_USER_ONLY)
3805 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3807 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3809 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW
)
3813 lev
= (ctx
->opcode
>> 5) & 0x7F;
3814 GEN_EXCP(ctx
, POWERPC_SYSCALL
, lev
);
3819 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
)
3821 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3822 /* Update the nip since this might generate a trap exception */
3823 gen_update_nip(ctx
, ctx
->nip
);
3824 gen_helper_tw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
3825 tcg_temp_free_i32(t0
);
3829 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
3831 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3832 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
3833 /* Update the nip since this might generate a trap exception */
3834 gen_update_nip(ctx
, ctx
->nip
);
3835 gen_helper_tw(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3837 tcg_temp_free_i32(t1
);
3840 #if defined(TARGET_PPC64)
3842 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
)
3844 TCGv_i32 t0
= tcg_const_i32(TO(ctx
->opcode
));
3845 /* Update the nip since this might generate a trap exception */
3846 gen_update_nip(ctx
, ctx
->nip
);
3847 gen_helper_td(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
3848 tcg_temp_free_i32(t0
);
3852 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
)
3854 TCGv t0
= tcg_const_tl(SIMM(ctx
->opcode
));
3855 TCGv_i32 t1
= tcg_const_i32(TO(ctx
->opcode
));
3856 /* Update the nip since this might generate a trap exception */
3857 gen_update_nip(ctx
, ctx
->nip
);
3858 gen_helper_td(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3860 tcg_temp_free_i32(t1
);
3864 /*** Processor control ***/
3866 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
)
3868 tcg_gen_trunc_tl_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_xer
);
3869 tcg_gen_shri_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfD(ctx
->opcode
)], XER_CA
);
3870 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_SO
| 1 << XER_OV
| 1 << XER_CA
));
3874 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
)
3878 if (likely(ctx
->opcode
& 0x00100000)) {
3879 crm
= CRM(ctx
->opcode
);
3880 if (likely((crm
^ (crm
- 1)) == 0)) {
3882 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_crf
[7 - crn
]);
3885 gen_helper_load_cr(cpu_gpr
[rD(ctx
->opcode
)]);
3890 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
)
3892 #if defined(CONFIG_USER_ONLY)
3893 GEN_EXCP_PRIVREG(ctx
);
3895 if (unlikely(!ctx
->supervisor
)) {
3896 GEN_EXCP_PRIVREG(ctx
);
3900 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
3905 #define SPR_NOACCESS ((void *)(-1UL))
3907 static void spr_noaccess (void *opaque
, int sprn
)
3909 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
3910 printf("ERROR: try to access SPR %d !\n", sprn
);
3912 #define SPR_NOACCESS (&spr_noaccess)
3916 static always_inline
void gen_op_mfspr (DisasContext
*ctx
)
3918 void (*read_cb
)(void *opaque
, int sprn
);
3919 uint32_t sprn
= SPR(ctx
->opcode
);
3921 #if !defined(CONFIG_USER_ONLY)
3922 if (ctx
->supervisor
== 2)
3923 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
3924 else if (ctx
->supervisor
)
3925 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
3928 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
3929 if (likely(read_cb
!= NULL
)) {
3930 if (likely(read_cb
!= SPR_NOACCESS
)) {
3931 (*read_cb
)(ctx
, sprn
);
3932 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
3934 /* Privilege exception */
3935 /* This is a hack to avoid warnings when running Linux:
3936 * this OS breaks the PowerPC virtualisation model,
3937 * allowing userland application to read the PVR
3939 if (sprn
!= SPR_PVR
) {
3940 if (loglevel
!= 0) {
3941 fprintf(logfile
, "Trying to read privileged spr %d %03x at "
3942 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3944 printf("Trying to read privileged spr %d %03x at " ADDRX
"\n",
3945 sprn
, sprn
, ctx
->nip
);
3947 GEN_EXCP_PRIVREG(ctx
);
3951 if (loglevel
!= 0) {
3952 fprintf(logfile
, "Trying to read invalid spr %d %03x at "
3953 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3955 printf("Trying to read invalid spr %d %03x at " ADDRX
"\n",
3956 sprn
, sprn
, ctx
->nip
);
3957 GEN_EXCP(ctx
, POWERPC_EXCP_PROGRAM
,
3958 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_SPR
);
3962 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
)
3968 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
)
3974 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
)
3978 crm
= CRM(ctx
->opcode
);
3979 if (likely((ctx
->opcode
& 0x00100000) || (crm
^ (crm
- 1)) == 0)) {
3980 TCGv_i32 temp
= tcg_temp_new_i32();
3982 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
3983 tcg_gen_shri_i32(cpu_crf
[7 - crn
], temp
, crn
* 4);
3984 tcg_gen_andi_i32(cpu_crf
[7 - crn
], cpu_crf
[7 - crn
], 0xf);
3985 tcg_temp_free_i32(temp
);
3987 TCGv_i32 temp
= tcg_const_i32(crm
);
3988 gen_helper_store_cr(cpu_gpr
[rS(ctx
->opcode
)], temp
);
3989 tcg_temp_free_i32(temp
);
3994 #if defined(TARGET_PPC64)
3995 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
)
3997 #if defined(CONFIG_USER_ONLY)
3998 GEN_EXCP_PRIVREG(ctx
);
4000 if (unlikely(!ctx
->supervisor
)) {
4001 GEN_EXCP_PRIVREG(ctx
);
4004 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4005 if (ctx
->opcode
& 0x00010000) {
4006 /* Special form that does not need any synchronisation */
4007 gen_op_update_riee();
4009 /* XXX: we need to update nip before the store
4010 * if we enter power saving mode, we will exit the loop
4011 * directly from ppc_store_msr
4013 gen_update_nip(ctx
, ctx
->nip
);
4015 /* Must stop the translation as machine state (may have) changed */
4016 /* Note that mtmsr is not always defined as context-synchronizing */
4017 ctx
->exception
= POWERPC_EXCP_STOP
;
4023 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC
)
4025 #if defined(CONFIG_USER_ONLY)
4026 GEN_EXCP_PRIVREG(ctx
);
4028 if (unlikely(!ctx
->supervisor
)) {
4029 GEN_EXCP_PRIVREG(ctx
);
4032 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4033 if (ctx
->opcode
& 0x00010000) {
4034 /* Special form that does not need any synchronisation */
4035 gen_op_update_riee();
4037 /* XXX: we need to update nip before the store
4038 * if we enter power saving mode, we will exit the loop
4039 * directly from ppc_store_msr
4041 gen_update_nip(ctx
, ctx
->nip
);
4042 #if defined(TARGET_PPC64)
4044 gen_op_store_msr_32();
4048 /* Must stop the translation as machine state (may have) changed */
4049 /* Note that mtmsrd is not always defined as context-synchronizing */
4050 ctx
->exception
= POWERPC_EXCP_STOP
;
4056 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC
)
4058 void (*write_cb
)(void *opaque
, int sprn
);
4059 uint32_t sprn
= SPR(ctx
->opcode
);
4061 #if !defined(CONFIG_USER_ONLY)
4062 if (ctx
->supervisor
== 2)
4063 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
4064 else if (ctx
->supervisor
)
4065 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
4068 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
4069 if (likely(write_cb
!= NULL
)) {
4070 if (likely(write_cb
!= SPR_NOACCESS
)) {
4071 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4072 (*write_cb
)(ctx
, sprn
);
4074 /* Privilege exception */
4075 if (loglevel
!= 0) {
4076 fprintf(logfile
, "Trying to write privileged spr %d %03x at "
4077 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
4079 printf("Trying to write privileged spr %d %03x at " ADDRX
"\n",
4080 sprn
, sprn
, ctx
->nip
);
4081 GEN_EXCP_PRIVREG(ctx
);
4085 if (loglevel
!= 0) {
4086 fprintf(logfile
, "Trying to write invalid spr %d %03x at "
4087 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
4089 printf("Trying to write invalid spr %d %03x at " ADDRX
"\n",
4090 sprn
, sprn
, ctx
->nip
);
4091 GEN_EXCP(ctx
, POWERPC_EXCP_PROGRAM
,
4092 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_SPR
);
4096 /*** Cache management ***/
4098 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
)
4100 /* XXX: specification says this is treated as a load by the MMU */
4101 TCGv t0
= tcg_temp_new();
4102 gen_set_access_type(ACCESS_CACHE
);
4103 gen_addr_reg_index(t0
, ctx
);
4104 gen_qemu_ld8u(t0
, t0
, ctx
->mem_idx
);
4108 /* dcbi (Supervisor only) */
4109 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
)
4111 #if defined(CONFIG_USER_ONLY)
4112 GEN_EXCP_PRIVOPC(ctx
);
4115 if (unlikely(!ctx
->supervisor
)) {
4116 GEN_EXCP_PRIVOPC(ctx
);
4119 EA
= tcg_temp_new();
4120 gen_set_access_type(ACCESS_CACHE
);
4121 gen_addr_reg_index(EA
, ctx
);
4122 val
= tcg_temp_new();
4123 /* XXX: specification says this should be treated as a store by the MMU */
4124 gen_qemu_ld8u(val
, EA
, ctx
->mem_idx
);
4125 gen_qemu_st8(val
, EA
, ctx
->mem_idx
);
4132 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
)
4134 /* XXX: specification say this is treated as a load by the MMU */
4135 TCGv t0
= tcg_temp_new();
4136 gen_set_access_type(ACCESS_CACHE
);
4137 gen_addr_reg_index(t0
, ctx
);
4138 gen_qemu_ld8u(t0
, t0
, ctx
->mem_idx
);
4143 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE
)
4145 /* interpreted as no-op */
4146 /* XXX: specification say this is treated as a load by the MMU
4147 * but does not generate any exception
4152 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE
)
4154 /* interpreted as no-op */
4155 /* XXX: specification say this is treated as a load by the MMU
4156 * but does not generate any exception
4161 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE_DCBZ
)
4163 TCGv t0
= tcg_temp_new();
4164 gen_addr_reg_index(t0
, ctx
);
4165 /* NIP cannot be restored if the memory exception comes from an helper */
4166 gen_update_nip(ctx
, ctx
->nip
- 4);
4167 gen_helper_dcbz(t0
);
4171 GEN_HANDLER2(dcbz_970
, "dcbz", 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZT
)
4173 TCGv t0
= tcg_temp_new();
4174 gen_addr_reg_index(t0
, ctx
);
4175 /* NIP cannot be restored if the memory exception comes from an helper */
4176 gen_update_nip(ctx
, ctx
->nip
- 4);
4177 if (ctx
->opcode
& 0x00200000)
4178 gen_helper_dcbz(t0
);
4180 gen_helper_dcbz_970(t0
);
4185 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
)
4187 TCGv t0
= tcg_temp_new();
4188 /* NIP cannot be restored if the memory exception comes from an helper */
4189 gen_update_nip(ctx
, ctx
->nip
- 4);
4190 gen_addr_reg_index(t0
, ctx
);
4191 gen_helper_icbi(t0
);
4197 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
)
4199 /* interpreted as no-op */
4200 /* XXX: specification say this is treated as a store by the MMU
4201 * but does not generate any exception
4205 /*** Segment register manipulation ***/
4206 /* Supervisor only: */
4208 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
)
4210 #if defined(CONFIG_USER_ONLY)
4211 GEN_EXCP_PRIVREG(ctx
);
4213 if (unlikely(!ctx
->supervisor
)) {
4214 GEN_EXCP_PRIVREG(ctx
);
4217 tcg_gen_movi_tl(cpu_T
[1], SR(ctx
->opcode
));
4219 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4224 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
)
4226 #if defined(CONFIG_USER_ONLY)
4227 GEN_EXCP_PRIVREG(ctx
);
4229 if (unlikely(!ctx
->supervisor
)) {
4230 GEN_EXCP_PRIVREG(ctx
);
4233 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4236 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4241 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
)
4243 #if defined(CONFIG_USER_ONLY)
4244 GEN_EXCP_PRIVREG(ctx
);
4246 if (unlikely(!ctx
->supervisor
)) {
4247 GEN_EXCP_PRIVREG(ctx
);
4250 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4251 tcg_gen_movi_tl(cpu_T
[1], SR(ctx
->opcode
));
4257 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
)
4259 #if defined(CONFIG_USER_ONLY)
4260 GEN_EXCP_PRIVREG(ctx
);
4262 if (unlikely(!ctx
->supervisor
)) {
4263 GEN_EXCP_PRIVREG(ctx
);
4266 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4267 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4273 #if defined(TARGET_PPC64)
4274 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4276 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
)
4278 #if defined(CONFIG_USER_ONLY)
4279 GEN_EXCP_PRIVREG(ctx
);
4281 if (unlikely(!ctx
->supervisor
)) {
4282 GEN_EXCP_PRIVREG(ctx
);
4285 tcg_gen_movi_tl(cpu_T
[1], SR(ctx
->opcode
));
4287 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4292 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
4295 #if defined(CONFIG_USER_ONLY)
4296 GEN_EXCP_PRIVREG(ctx
);
4298 if (unlikely(!ctx
->supervisor
)) {
4299 GEN_EXCP_PRIVREG(ctx
);
4302 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4305 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4310 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
)
4312 #if defined(CONFIG_USER_ONLY)
4313 GEN_EXCP_PRIVREG(ctx
);
4315 if (unlikely(!ctx
->supervisor
)) {
4316 GEN_EXCP_PRIVREG(ctx
);
4319 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4320 tcg_gen_movi_tl(cpu_T
[1], SR(ctx
->opcode
));
4326 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
4329 #if defined(CONFIG_USER_ONLY)
4330 GEN_EXCP_PRIVREG(ctx
);
4332 if (unlikely(!ctx
->supervisor
)) {
4333 GEN_EXCP_PRIVREG(ctx
);
4336 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4337 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4342 #endif /* defined(TARGET_PPC64) */
4344 /*** Lookaside buffer management ***/
4345 /* Optional & supervisor only: */
4347 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
)
4349 #if defined(CONFIG_USER_ONLY)
4350 GEN_EXCP_PRIVOPC(ctx
);
4352 if (unlikely(!ctx
->supervisor
)) {
4353 GEN_EXCP_PRIVOPC(ctx
);
4361 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE
)
4363 #if defined(CONFIG_USER_ONLY)
4364 GEN_EXCP_PRIVOPC(ctx
);
4366 if (unlikely(!ctx
->supervisor
)) {
4367 GEN_EXCP_PRIVOPC(ctx
);
4370 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rB(ctx
->opcode
)]);
4371 #if defined(TARGET_PPC64)
4381 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
)
4383 #if defined(CONFIG_USER_ONLY)
4384 GEN_EXCP_PRIVOPC(ctx
);
4386 if (unlikely(!ctx
->supervisor
)) {
4387 GEN_EXCP_PRIVOPC(ctx
);
4390 /* This has no effect: it should ensure that all previous
4391 * tlbie have completed
4397 #if defined(TARGET_PPC64)
4399 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI
)
4401 #if defined(CONFIG_USER_ONLY)
4402 GEN_EXCP_PRIVOPC(ctx
);
4404 if (unlikely(!ctx
->supervisor
)) {
4405 GEN_EXCP_PRIVOPC(ctx
);
4413 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
)
4415 #if defined(CONFIG_USER_ONLY)
4416 GEN_EXCP_PRIVOPC(ctx
);
4418 if (unlikely(!ctx
->supervisor
)) {
4419 GEN_EXCP_PRIVOPC(ctx
);
4422 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rB(ctx
->opcode
)]);
4428 /*** External control ***/
4430 #define op_eciwx() (*gen_op_eciwx[ctx->mem_idx])()
4431 #define op_ecowx() (*gen_op_ecowx[ctx->mem_idx])()
4432 static GenOpFunc
*gen_op_eciwx
[NB_MEM_FUNCS
] = {
4433 GEN_MEM_FUNCS(eciwx
),
4435 static GenOpFunc
*gen_op_ecowx
[NB_MEM_FUNCS
] = {
4436 GEN_MEM_FUNCS(ecowx
),
4440 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
)
4442 /* Should check EAR[E] & alignment ! */
4443 gen_set_access_type(ACCESS_RES
);
4444 gen_addr_reg_index(cpu_T
[0], ctx
);
4446 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4450 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
)
4452 /* Should check EAR[E] & alignment ! */
4453 gen_addr_reg_index(cpu_T
[0], ctx
);
4454 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
4458 /* PowerPC 601 specific instructions */
4460 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
)
4462 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4464 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4465 if (unlikely(Rc(ctx
->opcode
) != 0))
4466 gen_set_Rc0(ctx
, cpu_T
[0]);
4470 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
)
4472 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4473 gen_op_POWER_abso();
4474 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4475 if (unlikely(Rc(ctx
->opcode
) != 0))
4476 gen_set_Rc0(ctx
, cpu_T
[0]);
4480 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
)
4482 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4483 gen_op_POWER_clcs();
4484 /* Rc=1 sets CR0 to an undefined state */
4485 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4489 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
)
4491 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4492 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4494 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4495 if (unlikely(Rc(ctx
->opcode
) != 0))
4496 gen_set_Rc0(ctx
, cpu_T
[0]);
4500 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
)
4502 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4503 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4504 gen_op_POWER_divo();
4505 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4506 if (unlikely(Rc(ctx
->opcode
) != 0))
4507 gen_set_Rc0(ctx
, cpu_T
[0]);
4511 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
)
4513 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4514 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4515 gen_op_POWER_divs();
4516 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4517 if (unlikely(Rc(ctx
->opcode
) != 0))
4518 gen_set_Rc0(ctx
, cpu_T
[0]);
4521 /* divso - divso. */
4522 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
)
4524 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4525 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4526 gen_op_POWER_divso();
4527 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4528 if (unlikely(Rc(ctx
->opcode
) != 0))
4529 gen_set_Rc0(ctx
, cpu_T
[0]);
4533 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
)
4535 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4536 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4538 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4539 if (unlikely(Rc(ctx
->opcode
) != 0))
4540 gen_set_Rc0(ctx
, cpu_T
[0]);
4544 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
)
4546 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4547 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4548 gen_op_POWER_dozo();
4549 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4550 if (unlikely(Rc(ctx
->opcode
) != 0))
4551 gen_set_Rc0(ctx
, cpu_T
[0]);
4555 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
)
4557 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4558 tcg_gen_movi_tl(cpu_T
[1], SIMM(ctx
->opcode
));
4560 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4563 /* lscbx - lscbx. */
4564 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
)
4566 TCGv t0
= tcg_temp_new();
4567 TCGv_i32 t1
= tcg_const_i32(rD(ctx
->opcode
));
4568 TCGv_i32 t2
= tcg_const_i32(rA(ctx
->opcode
));
4569 TCGv_i32 t3
= tcg_const_i32(rB(ctx
->opcode
));
4571 gen_addr_reg_index(t0
, ctx
);
4572 /* NIP cannot be restored if the memory exception comes from an helper */
4573 gen_update_nip(ctx
, ctx
->nip
- 4);
4574 gen_helper_lscbx(t0
, t0
, t1
, t2
, t3
);
4575 tcg_temp_free_i32(t1
);
4576 tcg_temp_free_i32(t2
);
4577 tcg_temp_free_i32(t3
);
4578 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~0x7F);
4579 tcg_gen_or_tl(cpu_xer
, cpu_xer
, t0
);
4580 if (unlikely(Rc(ctx
->opcode
) != 0))
4581 gen_set_Rc0(ctx
, t0
);
4585 /* maskg - maskg. */
4586 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
)
4588 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4589 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4590 gen_op_POWER_maskg();
4591 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4592 if (unlikely(Rc(ctx
->opcode
) != 0))
4593 gen_set_Rc0(ctx
, cpu_T
[0]);
4596 /* maskir - maskir. */
4597 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
)
4599 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4600 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
4601 tcg_gen_mov_tl(cpu_T
[2], cpu_gpr
[rB(ctx
->opcode
)]);
4602 gen_op_POWER_maskir();
4603 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4604 if (unlikely(Rc(ctx
->opcode
) != 0))
4605 gen_set_Rc0(ctx
, cpu_T
[0]);
4609 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
)
4611 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4612 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4614 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4615 if (unlikely(Rc(ctx
->opcode
) != 0))
4616 gen_set_Rc0(ctx
, cpu_T
[0]);
4620 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
)
4622 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4623 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4624 gen_op_POWER_mulo();
4625 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4626 if (unlikely(Rc(ctx
->opcode
) != 0))
4627 gen_set_Rc0(ctx
, cpu_T
[0]);
4631 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
)
4633 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4634 gen_op_POWER_nabs();
4635 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4636 if (unlikely(Rc(ctx
->opcode
) != 0))
4637 gen_set_Rc0(ctx
, cpu_T
[0]);
4640 /* nabso - nabso. */
4641 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
)
4643 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4644 gen_op_POWER_nabso();
4645 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4646 if (unlikely(Rc(ctx
->opcode
) != 0))
4647 gen_set_Rc0(ctx
, cpu_T
[0]);
4651 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
)
4655 mb
= MB(ctx
->opcode
);
4656 me
= ME(ctx
->opcode
);
4657 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4658 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rA(ctx
->opcode
)]);
4659 tcg_gen_mov_tl(cpu_T
[2], cpu_gpr
[rB(ctx
->opcode
)]);
4660 gen_op_POWER_rlmi(MASK(mb
, me
), ~MASK(mb
, me
));
4661 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4662 if (unlikely(Rc(ctx
->opcode
) != 0))
4663 gen_set_Rc0(ctx
, cpu_T
[0]);
4667 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
)
4669 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4670 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rA(ctx
->opcode
)]);
4671 tcg_gen_mov_tl(cpu_T
[2], cpu_gpr
[rB(ctx
->opcode
)]);
4672 gen_op_POWER_rrib();
4673 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4674 if (unlikely(Rc(ctx
->opcode
) != 0))
4675 gen_set_Rc0(ctx
, cpu_T
[0]);
4679 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
)
4681 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4682 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4684 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4685 if (unlikely(Rc(ctx
->opcode
) != 0))
4686 gen_set_Rc0(ctx
, cpu_T
[0]);
4690 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
)
4692 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4693 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4694 gen_op_POWER_sleq();
4695 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4696 if (unlikely(Rc(ctx
->opcode
) != 0))
4697 gen_set_Rc0(ctx
, cpu_T
[0]);
4701 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
)
4703 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4704 tcg_gen_movi_tl(cpu_T
[1], SH(ctx
->opcode
));
4706 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4707 if (unlikely(Rc(ctx
->opcode
) != 0))
4708 gen_set_Rc0(ctx
, cpu_T
[0]);
4711 /* slliq - slliq. */
4712 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
)
4714 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4715 tcg_gen_movi_tl(cpu_T
[1], SH(ctx
->opcode
));
4716 gen_op_POWER_sleq();
4717 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4718 if (unlikely(Rc(ctx
->opcode
) != 0))
4719 gen_set_Rc0(ctx
, cpu_T
[0]);
4723 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
)
4725 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4726 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4727 gen_op_POWER_sllq();
4728 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4729 if (unlikely(Rc(ctx
->opcode
) != 0))
4730 gen_set_Rc0(ctx
, cpu_T
[0]);
4734 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
)
4736 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4737 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4739 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4740 if (unlikely(Rc(ctx
->opcode
) != 0))
4741 gen_set_Rc0(ctx
, cpu_T
[0]);
4744 /* sraiq - sraiq. */
4745 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
)
4747 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4748 tcg_gen_movi_tl(cpu_T
[1], SH(ctx
->opcode
));
4749 gen_op_POWER_sraq();
4750 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4751 if (unlikely(Rc(ctx
->opcode
) != 0))
4752 gen_set_Rc0(ctx
, cpu_T
[0]);
4756 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
)
4758 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4759 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4760 gen_op_POWER_sraq();
4761 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4762 if (unlikely(Rc(ctx
->opcode
) != 0))
4763 gen_set_Rc0(ctx
, cpu_T
[0]);
4767 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
)
4769 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4770 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4772 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4773 if (unlikely(Rc(ctx
->opcode
) != 0))
4774 gen_set_Rc0(ctx
, cpu_T
[0]);
4778 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
)
4780 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4781 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4782 gen_op_POWER_srea();
4783 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4784 if (unlikely(Rc(ctx
->opcode
) != 0))
4785 gen_set_Rc0(ctx
, cpu_T
[0]);
4789 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
)
4791 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4792 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4793 gen_op_POWER_sreq();
4794 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4795 if (unlikely(Rc(ctx
->opcode
) != 0))
4796 gen_set_Rc0(ctx
, cpu_T
[0]);
4800 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
)
4802 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4803 tcg_gen_movi_tl(cpu_T
[1], SH(ctx
->opcode
));
4805 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4806 if (unlikely(Rc(ctx
->opcode
) != 0))
4807 gen_set_Rc0(ctx
, cpu_T
[0]);
4811 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
)
4813 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4814 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4815 tcg_gen_movi_tl(cpu_T
[1], SH(ctx
->opcode
));
4816 gen_op_POWER_srlq();
4817 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4818 if (unlikely(Rc(ctx
->opcode
) != 0))
4819 gen_set_Rc0(ctx
, cpu_T
[0]);
4823 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
)
4825 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4826 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4827 gen_op_POWER_srlq();
4828 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4829 if (unlikely(Rc(ctx
->opcode
) != 0))
4830 gen_set_Rc0(ctx
, cpu_T
[0]);
4834 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
)
4836 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4837 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4839 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4840 if (unlikely(Rc(ctx
->opcode
) != 0))
4841 gen_set_Rc0(ctx
, cpu_T
[0]);
4844 /* PowerPC 602 specific instructions */
4846 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
)
4849 GEN_EXCP_INVAL(ctx
);
4853 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
)
4856 GEN_EXCP_INVAL(ctx
);
4860 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
)
4862 #if defined(CONFIG_USER_ONLY)
4863 GEN_EXCP_PRIVOPC(ctx
);
4865 if (unlikely(!ctx
->supervisor
)) {
4866 GEN_EXCP_PRIVOPC(ctx
);
4869 gen_helper_602_mfrom(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
4873 /* 602 - 603 - G2 TLB management */
4875 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
)
4877 #if defined(CONFIG_USER_ONLY)
4878 GEN_EXCP_PRIVOPC(ctx
);
4880 if (unlikely(!ctx
->supervisor
)) {
4881 GEN_EXCP_PRIVOPC(ctx
);
4884 gen_helper_load_6xx_tlbd(cpu_gpr
[rB(ctx
->opcode
)]);
4889 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
)
4891 #if defined(CONFIG_USER_ONLY)
4892 GEN_EXCP_PRIVOPC(ctx
);
4894 if (unlikely(!ctx
->supervisor
)) {
4895 GEN_EXCP_PRIVOPC(ctx
);
4898 gen_helper_load_6xx_tlbi(cpu_gpr
[rB(ctx
->opcode
)]);
4902 /* 74xx TLB management */
4904 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
)
4906 #if defined(CONFIG_USER_ONLY)
4907 GEN_EXCP_PRIVOPC(ctx
);
4909 if (unlikely(!ctx
->supervisor
)) {
4910 GEN_EXCP_PRIVOPC(ctx
);
4913 gen_helper_load_74xx_tlbd(cpu_gpr
[rB(ctx
->opcode
)]);
4918 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
)
4920 #if defined(CONFIG_USER_ONLY)
4921 GEN_EXCP_PRIVOPC(ctx
);
4923 if (unlikely(!ctx
->supervisor
)) {
4924 GEN_EXCP_PRIVOPC(ctx
);
4927 gen_helper_load_74xx_tlbi(cpu_gpr
[rB(ctx
->opcode
)]);
4931 /* POWER instructions not in PowerPC 601 */
4933 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
)
4935 /* Cache line flush: implemented as no-op */
4939 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
)
4941 /* Cache line invalidate: privileged and treated as no-op */
4942 #if defined(CONFIG_USER_ONLY)
4943 GEN_EXCP_PRIVOPC(ctx
);
4945 if (unlikely(!ctx
->supervisor
)) {
4946 GEN_EXCP_PRIVOPC(ctx
);
4953 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
)
4955 /* Data cache line store: treated as no-op */
4958 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
)
4960 #if defined(CONFIG_USER_ONLY)
4961 GEN_EXCP_PRIVOPC(ctx
);
4963 if (unlikely(!ctx
->supervisor
)) {
4964 GEN_EXCP_PRIVOPC(ctx
);
4967 int ra
= rA(ctx
->opcode
);
4968 int rd
= rD(ctx
->opcode
);
4970 gen_addr_reg_index(cpu_T
[0], ctx
);
4971 gen_op_POWER_mfsri();
4972 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_T
[0]);
4973 if (ra
!= 0 && ra
!= rd
)
4974 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_T
[1]);
4978 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
)
4980 #if defined(CONFIG_USER_ONLY)
4981 GEN_EXCP_PRIVOPC(ctx
);
4983 if (unlikely(!ctx
->supervisor
)) {
4984 GEN_EXCP_PRIVOPC(ctx
);
4987 gen_addr_reg_index(cpu_T
[0], ctx
);
4989 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4993 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
)
4995 #if defined(CONFIG_USER_ONLY)
4996 GEN_EXCP_PRIVOPC(ctx
);
4998 if (unlikely(!ctx
->supervisor
)) {
4999 GEN_EXCP_PRIVOPC(ctx
);
5002 gen_op_POWER_rfsvc();
5007 /* svc is not implemented for now */
5009 /* POWER2 specific instructions */
5010 /* Quad manipulation (load/store two floats at a time) */
5013 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
5015 int rd
= rD(ctx
->opcode
);
5016 TCGv t0
= tcg_temp_new();
5017 gen_addr_imm_index(t0
, ctx
, 0);
5018 gen_qemu_ld64(cpu_fpr
[rd
], t0
, ctx
->mem_idx
);
5019 tcg_gen_addi_tl(t0
, t0
, 8);
5020 gen_qemu_ld64(cpu_fpr
[(rd
+ 1) % 32], t0
, ctx
->mem_idx
);
5025 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
5027 int ra
= rA(ctx
->opcode
);
5028 int rd
= rD(ctx
->opcode
);
5029 TCGv t0
= tcg_temp_new();
5030 TCGv t1
= tcg_temp_new();
5031 gen_addr_imm_index(t0
, ctx
, 0);
5032 gen_qemu_ld64(cpu_fpr
[rd
], t0
, ctx
->mem_idx
);
5033 tcg_gen_addi_tl(t1
, t0
, 8);
5034 gen_qemu_ld64(cpu_fpr
[(rd
+ 1) % 32], t1
, ctx
->mem_idx
);
5036 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5042 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
)
5044 int ra
= rA(ctx
->opcode
);
5045 int rd
= rD(ctx
->opcode
);
5046 TCGv t0
= tcg_temp_new();
5047 TCGv t1
= tcg_temp_new();
5048 gen_addr_reg_index(t0
, ctx
);
5049 gen_qemu_ld64(cpu_fpr
[rd
], t0
, ctx
->mem_idx
);
5050 tcg_gen_addi_tl(t1
, t0
, 8);
5051 gen_qemu_ld64(cpu_fpr
[(rd
+ 1) % 32], t1
, ctx
->mem_idx
);
5053 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5059 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
)
5061 int rd
= rD(ctx
->opcode
);
5062 TCGv t0
= tcg_temp_new();
5063 gen_addr_reg_index(t0
, ctx
);
5064 gen_qemu_ld64(cpu_fpr
[rd
], t0
, ctx
->mem_idx
);
5065 tcg_gen_addi_tl(t0
, t0
, 8);
5066 gen_qemu_ld64(cpu_fpr
[(rd
+ 1) % 32], t0
, ctx
->mem_idx
);
5071 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
5073 int rd
= rD(ctx
->opcode
);
5074 TCGv t0
= tcg_temp_new();
5075 gen_addr_imm_index(t0
, ctx
, 0);
5076 gen_qemu_st64(cpu_fpr
[rd
], t0
, ctx
->mem_idx
);
5077 tcg_gen_addi_tl(t0
, t0
, 8);
5078 gen_qemu_st64(cpu_fpr
[(rd
+ 1) % 32], t0
, ctx
->mem_idx
);
5083 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
5085 int ra
= rA(ctx
->opcode
);
5086 int rd
= rD(ctx
->opcode
);
5087 TCGv t0
= tcg_temp_new();
5088 TCGv t1
= tcg_temp_new();
5089 gen_addr_imm_index(t0
, ctx
, 0);
5090 gen_qemu_st64(cpu_fpr
[rd
], t0
, ctx
->mem_idx
);
5091 tcg_gen_addi_tl(t1
, t0
, 8);
5092 gen_qemu_st64(cpu_fpr
[(rd
+ 1) % 32], t1
, ctx
->mem_idx
);
5094 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5100 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
)
5102 int ra
= rA(ctx
->opcode
);
5103 int rd
= rD(ctx
->opcode
);
5104 TCGv t0
= tcg_temp_new();
5105 TCGv t1
= tcg_temp_new();
5106 gen_addr_reg_index(t0
, ctx
);
5107 gen_qemu_st64(cpu_fpr
[rd
], t0
, ctx
->mem_idx
);
5108 tcg_gen_addi_tl(t1
, t0
, 8);
5109 gen_qemu_st64(cpu_fpr
[(rd
+ 1) % 32], t1
, ctx
->mem_idx
);
5111 tcg_gen_mov_tl(cpu_gpr
[ra
], t0
);
5117 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
)
5119 int rd
= rD(ctx
->opcode
);
5120 TCGv t0
= tcg_temp_new();
5121 gen_addr_reg_index(t0
, ctx
);
5122 gen_qemu_st64(cpu_fpr
[rd
], t0
, ctx
->mem_idx
);
5123 tcg_gen_addi_tl(t0
, t0
, 8);
5124 gen_qemu_st64(cpu_fpr
[(rd
+ 1) % 32], t0
, ctx
->mem_idx
);
5128 /* BookE specific instructions */
5129 /* XXX: not implemented on 440 ? */
5130 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
)
5133 GEN_EXCP_INVAL(ctx
);
5136 /* XXX: not implemented on 440 ? */
5137 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
)
5139 #if defined(CONFIG_USER_ONLY)
5140 GEN_EXCP_PRIVOPC(ctx
);
5142 if (unlikely(!ctx
->supervisor
)) {
5143 GEN_EXCP_PRIVOPC(ctx
);
5146 gen_addr_reg_index(cpu_T
[0], ctx
);
5147 /* Use the same micro-ops as for tlbie */
5148 #if defined(TARGET_PPC64)
5157 /* All 405 MAC instructions are translated here */
5158 static always_inline
void gen_405_mulladd_insn (DisasContext
*ctx
,
5160 int ra
, int rb
, int rt
, int Rc
)
5164 t0
= tcg_temp_local_new();
5165 t1
= tcg_temp_local_new();
5167 switch (opc3
& 0x0D) {
5169 /* macchw - macchw. - macchwo - macchwo. */
5170 /* macchws - macchws. - macchwso - macchwso. */
5171 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5172 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5173 /* mulchw - mulchw. */
5174 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5175 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5176 tcg_gen_ext16s_tl(t1
, t1
);
5179 /* macchwu - macchwu. - macchwuo - macchwuo. */
5180 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5181 /* mulchwu - mulchwu. */
5182 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5183 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5184 tcg_gen_ext16u_tl(t1
, t1
);
5187 /* machhw - machhw. - machhwo - machhwo. */
5188 /* machhws - machhws. - machhwso - machhwso. */
5189 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5190 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5191 /* mulhhw - mulhhw. */
5192 tcg_gen_sari_tl(t0
, cpu_gpr
[ra
], 16);
5193 tcg_gen_ext16s_tl(t0
, t0
);
5194 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5195 tcg_gen_ext16s_tl(t1
, t1
);
5198 /* machhwu - machhwu. - machhwuo - machhwuo. */
5199 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5200 /* mulhhwu - mulhhwu. */
5201 tcg_gen_shri_tl(t0
, cpu_gpr
[ra
], 16);
5202 tcg_gen_ext16u_tl(t0
, t0
);
5203 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5204 tcg_gen_ext16u_tl(t1
, t1
);
5207 /* maclhw - maclhw. - maclhwo - maclhwo. */
5208 /* maclhws - maclhws. - maclhwso - maclhwso. */
5209 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5210 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5211 /* mullhw - mullhw. */
5212 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5213 tcg_gen_ext16s_tl(t1
, cpu_gpr
[rb
]);
5216 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5217 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5218 /* mullhwu - mullhwu. */
5219 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5220 tcg_gen_ext16u_tl(t1
, cpu_gpr
[rb
]);
5224 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5225 tcg_gen_mul_tl(t1
, t0
, t1
);
5227 /* nmultiply-and-accumulate (0x0E) */
5228 tcg_gen_sub_tl(t0
, cpu_gpr
[rt
], t1
);
5230 /* multiply-and-accumulate (0x0C) */
5231 tcg_gen_add_tl(t0
, cpu_gpr
[rt
], t1
);
5235 /* Check overflow and/or saturate */
5236 int l1
= gen_new_label();
5239 /* Start with XER OV disabled, the most likely case */
5240 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
5244 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t1
);
5245 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
5246 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t0
);
5247 tcg_gen_brcondi_tl(TCG_COND_LT
, t1
, 0, l1
);
5250 tcg_gen_sari_tl(t0
, cpu_gpr
[rt
], 31);
5251 tcg_gen_xori_tl(t0
, t0
, 0x7fffffff);
5255 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
5258 tcg_gen_movi_tl(t0
, UINT32_MAX
);
5262 /* Check overflow */
5263 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
5266 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
5269 tcg_gen_mul_tl(cpu_gpr
[rt
], t0
, t1
);
5273 if (unlikely(Rc
) != 0) {
5275 gen_set_Rc0(ctx
, cpu_gpr
[rt
]);
5279 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5280 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC) \
5282 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5283 rD(ctx->opcode), Rc(ctx->opcode)); \
5286 /* macchw - macchw. */
5287 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
5288 /* macchwo - macchwo. */
5289 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
5290 /* macchws - macchws. */
5291 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
5292 /* macchwso - macchwso. */
5293 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
5294 /* macchwsu - macchwsu. */
5295 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
5296 /* macchwsuo - macchwsuo. */
5297 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
5298 /* macchwu - macchwu. */
5299 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
5300 /* macchwuo - macchwuo. */
5301 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
5302 /* machhw - machhw. */
5303 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
5304 /* machhwo - machhwo. */
5305 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
5306 /* machhws - machhws. */
5307 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
5308 /* machhwso - machhwso. */
5309 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
5310 /* machhwsu - machhwsu. */
5311 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
5312 /* machhwsuo - machhwsuo. */
5313 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
5314 /* machhwu - machhwu. */
5315 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
5316 /* machhwuo - machhwuo. */
5317 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
5318 /* maclhw - maclhw. */
5319 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
5320 /* maclhwo - maclhwo. */
5321 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
5322 /* maclhws - maclhws. */
5323 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
5324 /* maclhwso - maclhwso. */
5325 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
5326 /* maclhwu - maclhwu. */
5327 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
5328 /* maclhwuo - maclhwuo. */
5329 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
5330 /* maclhwsu - maclhwsu. */
5331 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
5332 /* maclhwsuo - maclhwsuo. */
5333 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
5334 /* nmacchw - nmacchw. */
5335 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
5336 /* nmacchwo - nmacchwo. */
5337 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
5338 /* nmacchws - nmacchws. */
5339 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
5340 /* nmacchwso - nmacchwso. */
5341 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
5342 /* nmachhw - nmachhw. */
5343 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
5344 /* nmachhwo - nmachhwo. */
5345 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
5346 /* nmachhws - nmachhws. */
5347 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
5348 /* nmachhwso - nmachhwso. */
5349 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
5350 /* nmaclhw - nmaclhw. */
5351 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
5352 /* nmaclhwo - nmaclhwo. */
5353 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
5354 /* nmaclhws - nmaclhws. */
5355 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
5356 /* nmaclhwso - nmaclhwso. */
5357 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
5359 /* mulchw - mulchw. */
5360 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
5361 /* mulchwu - mulchwu. */
5362 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
5363 /* mulhhw - mulhhw. */
5364 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
5365 /* mulhhwu - mulhhwu. */
5366 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
5367 /* mullhw - mullhw. */
5368 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
5369 /* mullhwu - mullhwu. */
5370 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
5373 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
)
5375 #if defined(CONFIG_USER_ONLY)
5376 GEN_EXCP_PRIVREG(ctx
);
5378 uint32_t dcrn
= SPR(ctx
->opcode
);
5380 if (unlikely(!ctx
->supervisor
)) {
5381 GEN_EXCP_PRIVREG(ctx
);
5384 tcg_gen_movi_tl(cpu_T
[0], dcrn
);
5386 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
5391 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
)
5393 #if defined(CONFIG_USER_ONLY)
5394 GEN_EXCP_PRIVREG(ctx
);
5396 uint32_t dcrn
= SPR(ctx
->opcode
);
5398 if (unlikely(!ctx
->supervisor
)) {
5399 GEN_EXCP_PRIVREG(ctx
);
5402 tcg_gen_movi_tl(cpu_T
[0], dcrn
);
5403 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
5409 /* XXX: not implemented on 440 ? */
5410 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
)
5412 #if defined(CONFIG_USER_ONLY)
5413 GEN_EXCP_PRIVREG(ctx
);
5415 if (unlikely(!ctx
->supervisor
)) {
5416 GEN_EXCP_PRIVREG(ctx
);
5419 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5421 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
5422 /* Note: Rc update flag set leads to undefined state of Rc0 */
5427 /* XXX: not implemented on 440 ? */
5428 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
)
5430 #if defined(CONFIG_USER_ONLY)
5431 GEN_EXCP_PRIVREG(ctx
);
5433 if (unlikely(!ctx
->supervisor
)) {
5434 GEN_EXCP_PRIVREG(ctx
);
5437 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5438 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
5440 /* Note: Rc update flag set leads to undefined state of Rc0 */
5444 /* mfdcrux (PPC 460) : user-mode access to DCR */
5445 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
)
5447 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5449 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
5450 /* Note: Rc update flag set leads to undefined state of Rc0 */
5453 /* mtdcrux (PPC 460) : user-mode access to DCR */
5454 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
)
5456 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5457 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
5459 /* Note: Rc update flag set leads to undefined state of Rc0 */
5463 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
)
5465 #if defined(CONFIG_USER_ONLY)
5466 GEN_EXCP_PRIVOPC(ctx
);
5468 if (unlikely(!ctx
->supervisor
)) {
5469 GEN_EXCP_PRIVOPC(ctx
);
5472 /* interpreted as no-op */
5477 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
)
5479 #if defined(CONFIG_USER_ONLY)
5480 GEN_EXCP_PRIVOPC(ctx
);
5483 if (unlikely(!ctx
->supervisor
)) {
5484 GEN_EXCP_PRIVOPC(ctx
);
5487 EA
= tcg_temp_new();
5488 gen_set_access_type(ACCESS_CACHE
);
5489 gen_addr_reg_index(EA
, ctx
);
5490 val
= tcg_temp_new();
5491 gen_qemu_ld32u(val
, EA
, ctx
->mem_idx
);
5493 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], EA
);
5499 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
)
5501 /* interpreted as no-op */
5502 /* XXX: specification say this is treated as a load by the MMU
5503 * but does not generate any exception
5508 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
)
5510 #if defined(CONFIG_USER_ONLY)
5511 GEN_EXCP_PRIVOPC(ctx
);
5513 if (unlikely(!ctx
->supervisor
)) {
5514 GEN_EXCP_PRIVOPC(ctx
);
5517 /* interpreted as no-op */
5522 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
)
5524 #if defined(CONFIG_USER_ONLY)
5525 GEN_EXCP_PRIVOPC(ctx
);
5527 if (unlikely(!ctx
->supervisor
)) {
5528 GEN_EXCP_PRIVOPC(ctx
);
5531 /* interpreted as no-op */
5535 /* rfci (supervisor only) */
5536 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
)
5538 #if defined(CONFIG_USER_ONLY)
5539 GEN_EXCP_PRIVOPC(ctx
);
5541 if (unlikely(!ctx
->supervisor
)) {
5542 GEN_EXCP_PRIVOPC(ctx
);
5545 /* Restore CPU state */
5551 GEN_HANDLER(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
)
5553 #if defined(CONFIG_USER_ONLY)
5554 GEN_EXCP_PRIVOPC(ctx
);
5556 if (unlikely(!ctx
->supervisor
)) {
5557 GEN_EXCP_PRIVOPC(ctx
);
5560 /* Restore CPU state */
5566 /* BookE specific */
5567 /* XXX: not implemented on 440 ? */
5568 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
)
5570 #if defined(CONFIG_USER_ONLY)
5571 GEN_EXCP_PRIVOPC(ctx
);
5573 if (unlikely(!ctx
->supervisor
)) {
5574 GEN_EXCP_PRIVOPC(ctx
);
5577 /* Restore CPU state */
5583 /* XXX: not implemented on 440 ? */
5584 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
)
5586 #if defined(CONFIG_USER_ONLY)
5587 GEN_EXCP_PRIVOPC(ctx
);
5589 if (unlikely(!ctx
->supervisor
)) {
5590 GEN_EXCP_PRIVOPC(ctx
);
5593 /* Restore CPU state */
5599 /* TLB management - PowerPC 405 implementation */
5601 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
)
5603 #if defined(CONFIG_USER_ONLY)
5604 GEN_EXCP_PRIVOPC(ctx
);
5606 if (unlikely(!ctx
->supervisor
)) {
5607 GEN_EXCP_PRIVOPC(ctx
);
5610 switch (rB(ctx
->opcode
)) {
5612 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5613 gen_op_4xx_tlbre_hi();
5614 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
5617 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5618 gen_op_4xx_tlbre_lo();
5619 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
5622 GEN_EXCP_INVAL(ctx
);
5628 /* tlbsx - tlbsx. */
5629 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
)
5631 #if defined(CONFIG_USER_ONLY)
5632 GEN_EXCP_PRIVOPC(ctx
);
5634 if (unlikely(!ctx
->supervisor
)) {
5635 GEN_EXCP_PRIVOPC(ctx
);
5638 gen_addr_reg_index(cpu_T
[0], ctx
);
5640 if (Rc(ctx
->opcode
))
5641 gen_op_4xx_tlbsx_check();
5642 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
5647 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
)
5649 #if defined(CONFIG_USER_ONLY)
5650 GEN_EXCP_PRIVOPC(ctx
);
5652 if (unlikely(!ctx
->supervisor
)) {
5653 GEN_EXCP_PRIVOPC(ctx
);
5656 switch (rB(ctx
->opcode
)) {
5658 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5659 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
5660 gen_op_4xx_tlbwe_hi();
5663 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5664 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
5665 gen_op_4xx_tlbwe_lo();
5668 GEN_EXCP_INVAL(ctx
);
5674 /* TLB management - PowerPC 440 implementation */
5676 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
)
5678 #if defined(CONFIG_USER_ONLY)
5679 GEN_EXCP_PRIVOPC(ctx
);
5681 if (unlikely(!ctx
->supervisor
)) {
5682 GEN_EXCP_PRIVOPC(ctx
);
5685 switch (rB(ctx
->opcode
)) {
5689 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5690 gen_op_440_tlbre(rB(ctx
->opcode
));
5691 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
5694 GEN_EXCP_INVAL(ctx
);
5700 /* tlbsx - tlbsx. */
5701 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
)
5703 #if defined(CONFIG_USER_ONLY)
5704 GEN_EXCP_PRIVOPC(ctx
);
5706 if (unlikely(!ctx
->supervisor
)) {
5707 GEN_EXCP_PRIVOPC(ctx
);
5710 gen_addr_reg_index(cpu_T
[0], ctx
);
5712 if (Rc(ctx
->opcode
))
5713 gen_op_4xx_tlbsx_check();
5714 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
5719 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
)
5721 #if defined(CONFIG_USER_ONLY)
5722 GEN_EXCP_PRIVOPC(ctx
);
5724 if (unlikely(!ctx
->supervisor
)) {
5725 GEN_EXCP_PRIVOPC(ctx
);
5728 switch (rB(ctx
->opcode
)) {
5732 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5733 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
5734 gen_op_440_tlbwe(rB(ctx
->opcode
));
5737 GEN_EXCP_INVAL(ctx
);
5744 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
)
5746 #if defined(CONFIG_USER_ONLY)
5747 GEN_EXCP_PRIVOPC(ctx
);
5749 if (unlikely(!ctx
->supervisor
)) {
5750 GEN_EXCP_PRIVOPC(ctx
);
5753 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rD(ctx
->opcode
)]);
5755 /* Stop translation to have a chance to raise an exception
5756 * if we just set msr_ee to 1
5763 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000EFC01, PPC_WRTEE
)
5765 #if defined(CONFIG_USER_ONLY)
5766 GEN_EXCP_PRIVOPC(ctx
);
5768 if (unlikely(!ctx
->supervisor
)) {
5769 GEN_EXCP_PRIVOPC(ctx
);
5772 tcg_gen_movi_tl(cpu_T
[0], ctx
->opcode
& 0x00010000);
5774 /* Stop translation to have a chance to raise an exception
5775 * if we just set msr_ee to 1
5781 /* PowerPC 440 specific instructions */
5783 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
)
5785 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
5786 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
5788 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
5789 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~0x7F);
5790 tcg_gen_or_tl(cpu_xer
, cpu_xer
, cpu_T
[0]);
5791 if (Rc(ctx
->opcode
)) {
5792 gen_op_440_dlmzb_update_Rc();
5793 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_T
[0]);
5794 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 0xf);
5798 /* mbar replaces eieio on 440 */
5799 GEN_HANDLER(mbar
, 0x1F, 0x16, 0x13, 0x001FF801, PPC_BOOKE
)
5801 /* interpreted as no-op */
5804 /* msync replaces sync on 440 */
5805 GEN_HANDLER(msync
, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE
)
5807 /* interpreted as no-op */
5811 GEN_HANDLER2(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001, PPC_BOOKE
)
5813 /* interpreted as no-op */
5814 /* XXX: specification say this is treated as a load by the MMU
5815 * but does not generate any exception
5819 /*** Altivec vector extension ***/
5820 /* Altivec registers moves */
5822 #define GEN_VR_LDX(name, opc2, opc3) \
5823 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
5826 if (unlikely(!ctx->altivec_enabled)) { \
5827 GEN_EXCP_NO_VR(ctx); \
5830 EA = tcg_temp_new(); \
5831 gen_addr_reg_index(EA, ctx); \
5832 tcg_gen_andi_tl(EA, EA, ~0xf); \
5833 if (ctx->mem_idx & 1) { \
5834 gen_qemu_ld64(cpu_avrl[rD(ctx->opcode)], EA, ctx->mem_idx); \
5835 tcg_gen_addi_tl(EA, EA, 8); \
5836 gen_qemu_ld64(cpu_avrh[rD(ctx->opcode)], EA, ctx->mem_idx); \
5838 gen_qemu_ld64(cpu_avrh[rD(ctx->opcode)], EA, ctx->mem_idx); \
5839 tcg_gen_addi_tl(EA, EA, 8); \
5840 gen_qemu_ld64(cpu_avrl[rD(ctx->opcode)], EA, ctx->mem_idx); \
5842 tcg_temp_free(EA); \
5845 #define GEN_VR_STX(name, opc2, opc3) \
5846 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
5849 if (unlikely(!ctx->altivec_enabled)) { \
5850 GEN_EXCP_NO_VR(ctx); \
5853 EA = tcg_temp_new(); \
5854 gen_addr_reg_index(EA, ctx); \
5855 tcg_gen_andi_tl(EA, EA, ~0xf); \
5856 if (ctx->mem_idx & 1) { \
5857 gen_qemu_st64(cpu_avrl[rD(ctx->opcode)], EA, ctx->mem_idx); \
5858 tcg_gen_addi_tl(EA, EA, 8); \
5859 gen_qemu_st64(cpu_avrh[rD(ctx->opcode)], EA, ctx->mem_idx); \
5861 gen_qemu_st64(cpu_avrh[rD(ctx->opcode)], EA, ctx->mem_idx); \
5862 tcg_gen_addi_tl(EA, EA, 8); \
5863 gen_qemu_st64(cpu_avrl[rD(ctx->opcode)], EA, ctx->mem_idx); \
5865 tcg_temp_free(EA); \
5868 GEN_VR_LDX(lvx
, 0x07, 0x03);
5869 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
5870 GEN_VR_LDX(lvxl
, 0x07, 0x0B);
5872 GEN_VR_STX(svx
, 0x07, 0x07);
5873 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
5874 GEN_VR_STX(svxl
, 0x07, 0x0F);
5876 /*** SPE extension ***/
5877 /* Register moves */
5879 static always_inline
void gen_load_gpr64(TCGv_i64 t
, int reg
) {
5880 #if defined(TARGET_PPC64)
5881 tcg_gen_mov_i64(t
, cpu_gpr
[reg
]);
5883 tcg_gen_concat_i32_i64(t
, cpu_gpr
[reg
], cpu_gprh
[reg
]);
5887 static always_inline
void gen_store_gpr64(int reg
, TCGv_i64 t
) {
5888 #if defined(TARGET_PPC64)
5889 tcg_gen_mov_i64(cpu_gpr
[reg
], t
);
5891 TCGv_i64 tmp
= tcg_temp_new_i64();
5892 tcg_gen_trunc_i64_i32(cpu_gpr
[reg
], t
);
5893 tcg_gen_shri_i64(tmp
, t
, 32);
5894 tcg_gen_trunc_i64_i32(cpu_gprh
[reg
], tmp
);
5895 tcg_temp_free_i64(tmp
);
5899 #define GEN_SPE(name0, name1, opc2, opc3, inval, type) \
5900 GEN_HANDLER(name0##_##name1, 0x04, opc2, opc3, inval, type) \
5902 if (Rc(ctx->opcode)) \
5908 /* Handler for undefined SPE opcodes */
5909 static always_inline
void gen_speundef (DisasContext
*ctx
)
5911 GEN_EXCP_INVAL(ctx
);
5915 #if defined(TARGET_PPC64)
5916 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
5917 static always_inline void gen_##name (DisasContext *ctx) \
5919 if (unlikely(!ctx->spe_enabled)) { \
5920 GEN_EXCP_NO_AP(ctx); \
5923 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
5924 cpu_gpr[rB(ctx->opcode)]); \
5927 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
5928 static always_inline void gen_##name (DisasContext *ctx) \
5930 if (unlikely(!ctx->spe_enabled)) { \
5931 GEN_EXCP_NO_AP(ctx); \
5934 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
5935 cpu_gpr[rB(ctx->opcode)]); \
5936 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
5937 cpu_gprh[rB(ctx->opcode)]); \
5941 GEN_SPEOP_LOGIC2(evand
, tcg_gen_and_tl
);
5942 GEN_SPEOP_LOGIC2(evandc
, tcg_gen_andc_tl
);
5943 GEN_SPEOP_LOGIC2(evxor
, tcg_gen_xor_tl
);
5944 GEN_SPEOP_LOGIC2(evor
, tcg_gen_or_tl
);
5945 GEN_SPEOP_LOGIC2(evnor
, tcg_gen_nor_tl
);
5946 GEN_SPEOP_LOGIC2(eveqv
, tcg_gen_eqv_tl
);
5947 GEN_SPEOP_LOGIC2(evorc
, tcg_gen_orc_tl
);
5948 GEN_SPEOP_LOGIC2(evnand
, tcg_gen_nand_tl
);
5950 /* SPE logic immediate */
5951 #if defined(TARGET_PPC64)
5952 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
5953 static always_inline void gen_##name (DisasContext *ctx) \
5955 if (unlikely(!ctx->spe_enabled)) { \
5956 GEN_EXCP_NO_AP(ctx); \
5959 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
5960 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
5961 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
5962 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
5963 tcg_opi(t0, t0, rB(ctx->opcode)); \
5964 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
5965 tcg_gen_trunc_i64_i32(t1, t2); \
5966 tcg_temp_free_i64(t2); \
5967 tcg_opi(t1, t1, rB(ctx->opcode)); \
5968 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
5969 tcg_temp_free_i32(t0); \
5970 tcg_temp_free_i32(t1); \
5973 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
5974 static always_inline void gen_##name (DisasContext *ctx) \
5976 if (unlikely(!ctx->spe_enabled)) { \
5977 GEN_EXCP_NO_AP(ctx); \
5980 tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
5982 tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
5986 GEN_SPEOP_TCG_LOGIC_IMM2(evslwi
, tcg_gen_shli_i32
);
5987 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu
, tcg_gen_shri_i32
);
5988 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis
, tcg_gen_sari_i32
);
5989 GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi
, tcg_gen_rotli_i32
);
5991 /* SPE arithmetic */
5992 #if defined(TARGET_PPC64)
5993 #define GEN_SPEOP_ARITH1(name, tcg_op) \
5994 static always_inline void gen_##name (DisasContext *ctx) \
5996 if (unlikely(!ctx->spe_enabled)) { \
5997 GEN_EXCP_NO_AP(ctx); \
6000 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6001 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6002 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6003 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6005 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6006 tcg_gen_trunc_i64_i32(t1, t2); \
6007 tcg_temp_free_i64(t2); \
6009 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6010 tcg_temp_free_i32(t0); \
6011 tcg_temp_free_i32(t1); \
6014 #define GEN_SPEOP_ARITH1(name, tcg_op) \
6015 static always_inline void gen_##name (DisasContext *ctx) \
6017 if (unlikely(!ctx->spe_enabled)) { \
6018 GEN_EXCP_NO_AP(ctx); \
6021 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
6022 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
6026 static always_inline
void gen_op_evabs (TCGv_i32 ret
, TCGv_i32 arg1
)
6028 int l1
= gen_new_label();
6029 int l2
= gen_new_label();
6031 tcg_gen_brcondi_i32(TCG_COND_GE
, arg1
, 0, l1
);
6032 tcg_gen_neg_i32(ret
, arg1
);
6035 tcg_gen_mov_i32(ret
, arg1
);
6038 GEN_SPEOP_ARITH1(evabs
, gen_op_evabs
);
6039 GEN_SPEOP_ARITH1(evneg
, tcg_gen_neg_i32
);
6040 GEN_SPEOP_ARITH1(evextsb
, tcg_gen_ext8s_i32
);
6041 GEN_SPEOP_ARITH1(evextsh
, tcg_gen_ext16s_i32
);
6042 static always_inline
void gen_op_evrndw (TCGv_i32 ret
, TCGv_i32 arg1
)
6044 tcg_gen_addi_i32(ret
, arg1
, 0x8000);
6045 tcg_gen_ext16u_i32(ret
, ret
);
6047 GEN_SPEOP_ARITH1(evrndw
, gen_op_evrndw
);
6048 GEN_SPEOP_ARITH1(evcntlsw
, gen_helper_cntlsw32
);
6049 GEN_SPEOP_ARITH1(evcntlzw
, gen_helper_cntlzw32
);
6051 #if defined(TARGET_PPC64)
6052 #define GEN_SPEOP_ARITH2(name, tcg_op) \
6053 static always_inline void gen_##name (DisasContext *ctx) \
6055 if (unlikely(!ctx->spe_enabled)) { \
6056 GEN_EXCP_NO_AP(ctx); \
6059 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6060 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6061 TCGv_i32 t2 = tcg_temp_local_new_i32(); \
6062 TCGv_i64 t3 = tcg_temp_local_new(TCG_TYPE_I64); \
6063 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6064 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
6065 tcg_op(t0, t0, t2); \
6066 tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
6067 tcg_gen_trunc_i64_i32(t1, t3); \
6068 tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
6069 tcg_gen_trunc_i64_i32(t2, t3); \
6070 tcg_temp_free_i64(t3); \
6071 tcg_op(t1, t1, t2); \
6072 tcg_temp_free_i32(t2); \
6073 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6074 tcg_temp_free_i32(t0); \
6075 tcg_temp_free_i32(t1); \
6078 #define GEN_SPEOP_ARITH2(name, tcg_op) \
6079 static always_inline void gen_##name (DisasContext *ctx) \
6081 if (unlikely(!ctx->spe_enabled)) { \
6082 GEN_EXCP_NO_AP(ctx); \
6085 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6086 cpu_gpr[rB(ctx->opcode)]); \
6087 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6088 cpu_gprh[rB(ctx->opcode)]); \
6092 static always_inline
void gen_op_evsrwu (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6097 l1
= gen_new_label();
6098 l2
= gen_new_label();
6099 t0
= tcg_temp_local_new_i32();
6100 /* No error here: 6 bits are used */
6101 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
6102 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
6103 tcg_gen_shr_i32(ret
, arg1
, t0
);
6106 tcg_gen_movi_i32(ret
, 0);
6108 tcg_temp_free_i32(t0
);
6110 GEN_SPEOP_ARITH2(evsrwu
, gen_op_evsrwu
);
6111 static always_inline
void gen_op_evsrws (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6116 l1
= gen_new_label();
6117 l2
= gen_new_label();
6118 t0
= tcg_temp_local_new_i32();
6119 /* No error here: 6 bits are used */
6120 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
6121 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
6122 tcg_gen_sar_i32(ret
, arg1
, t0
);
6125 tcg_gen_movi_i32(ret
, 0);
6127 tcg_temp_free_i32(t0
);
6129 GEN_SPEOP_ARITH2(evsrws
, gen_op_evsrws
);
6130 static always_inline
void gen_op_evslw (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6135 l1
= gen_new_label();
6136 l2
= gen_new_label();
6137 t0
= tcg_temp_local_new_i32();
6138 /* No error here: 6 bits are used */
6139 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
6140 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
6141 tcg_gen_shl_i32(ret
, arg1
, t0
);
6144 tcg_gen_movi_i32(ret
, 0);
6146 tcg_temp_free_i32(t0
);
6148 GEN_SPEOP_ARITH2(evslw
, gen_op_evslw
);
6149 static always_inline
void gen_op_evrlw (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6151 TCGv_i32 t0
= tcg_temp_new_i32();
6152 tcg_gen_andi_i32(t0
, arg2
, 0x1F);
6153 tcg_gen_rotl_i32(ret
, arg1
, t0
);
6154 tcg_temp_free_i32(t0
);
6156 GEN_SPEOP_ARITH2(evrlw
, gen_op_evrlw
);
6157 static always_inline
void gen_evmergehi (DisasContext
*ctx
)
6159 if (unlikely(!ctx
->spe_enabled
)) {
6160 GEN_EXCP_NO_AP(ctx
);
6163 #if defined(TARGET_PPC64)
6164 TCGv t0
= tcg_temp_new();
6165 TCGv t1
= tcg_temp_new();
6166 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
6167 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
6168 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
6172 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
6173 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6176 GEN_SPEOP_ARITH2(evaddw
, tcg_gen_add_i32
);
6177 static always_inline
void gen_op_evsubf (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6179 tcg_gen_sub_i32(ret
, arg2
, arg1
);
6181 GEN_SPEOP_ARITH2(evsubfw
, gen_op_evsubf
);
6183 /* SPE arithmetic immediate */
6184 #if defined(TARGET_PPC64)
6185 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
6186 static always_inline void gen_##name (DisasContext *ctx) \
6188 if (unlikely(!ctx->spe_enabled)) { \
6189 GEN_EXCP_NO_AP(ctx); \
6192 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6193 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6194 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6195 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
6196 tcg_op(t0, t0, rA(ctx->opcode)); \
6197 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
6198 tcg_gen_trunc_i64_i32(t1, t2); \
6199 tcg_temp_free_i64(t2); \
6200 tcg_op(t1, t1, rA(ctx->opcode)); \
6201 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6202 tcg_temp_free_i32(t0); \
6203 tcg_temp_free_i32(t1); \
6206 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
6207 static always_inline void gen_##name (DisasContext *ctx) \
6209 if (unlikely(!ctx->spe_enabled)) { \
6210 GEN_EXCP_NO_AP(ctx); \
6213 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
6215 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
6219 GEN_SPEOP_ARITH_IMM2(evaddiw
, tcg_gen_addi_i32
);
6220 GEN_SPEOP_ARITH_IMM2(evsubifw
, tcg_gen_subi_i32
);
6222 /* SPE comparison */
6223 #if defined(TARGET_PPC64)
6224 #define GEN_SPEOP_COMP(name, tcg_cond) \
6225 static always_inline void gen_##name (DisasContext *ctx) \
6227 if (unlikely(!ctx->spe_enabled)) { \
6228 GEN_EXCP_NO_AP(ctx); \
6231 int l1 = gen_new_label(); \
6232 int l2 = gen_new_label(); \
6233 int l3 = gen_new_label(); \
6234 int l4 = gen_new_label(); \
6235 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6236 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6237 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6238 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6239 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
6240 tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
6241 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
6243 gen_set_label(l1); \
6244 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
6245 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
6246 gen_set_label(l2); \
6247 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6248 tcg_gen_trunc_i64_i32(t0, t2); \
6249 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
6250 tcg_gen_trunc_i64_i32(t1, t2); \
6251 tcg_temp_free_i64(t2); \
6252 tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
6253 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6254 ~(CRF_CH | CRF_CH_AND_CL)); \
6256 gen_set_label(l3); \
6257 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6258 CRF_CH | CRF_CH_OR_CL); \
6259 gen_set_label(l4); \
6260 tcg_temp_free_i32(t0); \
6261 tcg_temp_free_i32(t1); \
6264 #define GEN_SPEOP_COMP(name, tcg_cond) \
6265 static always_inline void gen_##name (DisasContext *ctx) \
6267 if (unlikely(!ctx->spe_enabled)) { \
6268 GEN_EXCP_NO_AP(ctx); \
6271 int l1 = gen_new_label(); \
6272 int l2 = gen_new_label(); \
6273 int l3 = gen_new_label(); \
6274 int l4 = gen_new_label(); \
6276 tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
6277 cpu_gpr[rB(ctx->opcode)], l1); \
6278 tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
6280 gen_set_label(l1); \
6281 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
6282 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
6283 gen_set_label(l2); \
6284 tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
6285 cpu_gprh[rB(ctx->opcode)], l3); \
6286 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6287 ~(CRF_CH | CRF_CH_AND_CL)); \
6289 gen_set_label(l3); \
6290 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6291 CRF_CH | CRF_CH_OR_CL); \
6292 gen_set_label(l4); \
6295 GEN_SPEOP_COMP(evcmpgtu
, TCG_COND_GTU
);
6296 GEN_SPEOP_COMP(evcmpgts
, TCG_COND_GT
);
6297 GEN_SPEOP_COMP(evcmpltu
, TCG_COND_LTU
);
6298 GEN_SPEOP_COMP(evcmplts
, TCG_COND_LT
);
6299 GEN_SPEOP_COMP(evcmpeq
, TCG_COND_EQ
);
6302 static always_inline
void gen_brinc (DisasContext
*ctx
)
6304 /* Note: brinc is usable even if SPE is disabled */
6305 gen_helper_brinc(cpu_gpr
[rD(ctx
->opcode
)],
6306 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6308 static always_inline
void gen_evmergelo (DisasContext
*ctx
)
6310 if (unlikely(!ctx
->spe_enabled
)) {
6311 GEN_EXCP_NO_AP(ctx
);
6314 #if defined(TARGET_PPC64)
6315 TCGv t0
= tcg_temp_new();
6316 TCGv t1
= tcg_temp_new();
6317 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x00000000FFFFFFFFLL
);
6318 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
6319 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
6323 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6324 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6327 static always_inline
void gen_evmergehilo (DisasContext
*ctx
)
6329 if (unlikely(!ctx
->spe_enabled
)) {
6330 GEN_EXCP_NO_AP(ctx
);
6333 #if defined(TARGET_PPC64)
6334 TCGv t0
= tcg_temp_new();
6335 TCGv t1
= tcg_temp_new();
6336 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x00000000FFFFFFFFLL
);
6337 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
6338 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
6342 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6343 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6346 static always_inline
void gen_evmergelohi (DisasContext
*ctx
)
6348 if (unlikely(!ctx
->spe_enabled
)) {
6349 GEN_EXCP_NO_AP(ctx
);
6352 #if defined(TARGET_PPC64)
6353 TCGv t0
= tcg_temp_new();
6354 TCGv t1
= tcg_temp_new();
6355 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
6356 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
6357 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
6361 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
6362 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6365 static always_inline
void gen_evsplati (DisasContext
*ctx
)
6367 uint64_t imm
= ((int32_t)(rA(ctx
->opcode
) << 11)) >> 27;
6369 #if defined(TARGET_PPC64)
6370 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
6372 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
6373 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
6376 static always_inline
void gen_evsplatfi (DisasContext
*ctx
)
6378 uint64_t imm
= rA(ctx
->opcode
) << 11;
6380 #if defined(TARGET_PPC64)
6381 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], (imm
<< 32) | imm
);
6383 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
6384 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
6388 static always_inline
void gen_evsel (DisasContext
*ctx
)
6390 int l1
= gen_new_label();
6391 int l2
= gen_new_label();
6392 int l3
= gen_new_label();
6393 int l4
= gen_new_label();
6394 TCGv_i32 t0
= tcg_temp_local_new_i32();
6395 #if defined(TARGET_PPC64)
6396 TCGv t1
= tcg_temp_local_new();
6397 TCGv t2
= tcg_temp_local_new();
6399 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 3);
6400 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
6401 #if defined(TARGET_PPC64)
6402 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
6404 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6408 #if defined(TARGET_PPC64)
6409 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
6411 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
6414 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 2);
6415 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l3
);
6416 #if defined(TARGET_PPC64)
6417 tcg_gen_andi_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], 0x00000000FFFFFFFFULL
);
6419 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6423 #if defined(TARGET_PPC64)
6424 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x00000000FFFFFFFFULL
);
6426 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6429 tcg_temp_free_i32(t0
);
6430 #if defined(TARGET_PPC64)
6431 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
, t2
);
6436 GEN_HANDLER2(evsel0
, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE
)
6440 GEN_HANDLER2(evsel1
, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE
)
6444 GEN_HANDLER2(evsel2
, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE
)
6448 GEN_HANDLER2(evsel3
, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE
)
6453 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, PPC_SPE
); ////
6454 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, PPC_SPE
);
6455 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, PPC_SPE
); ////
6456 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, PPC_SPE
);
6457 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, PPC_SPE
); ////
6458 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, PPC_SPE
); ////
6459 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, PPC_SPE
); ////
6460 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x00000000, PPC_SPE
); //
6461 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0x00000000, PPC_SPE
); ////
6462 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, PPC_SPE
); ////
6463 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, PPC_SPE
); ////
6464 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, PPC_SPE
); ////
6465 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0x00000000, PPC_SPE
); ////
6466 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, PPC_SPE
); ////
6467 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, PPC_SPE
); ////
6468 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, PPC_SPE
);
6469 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, PPC_SPE
); ////
6470 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, PPC_SPE
);
6471 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, PPC_SPE
); //
6472 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, PPC_SPE
);
6473 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, PPC_SPE
); ////
6474 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, PPC_SPE
); ////
6475 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, PPC_SPE
); ////
6476 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, PPC_SPE
); ////
6477 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, PPC_SPE
); ////
6479 /* SPE load and stores */
6480 static always_inline
void gen_addr_spe_imm_index (TCGv EA
, DisasContext
*ctx
, int sh
)
6482 target_ulong uimm
= rB(ctx
->opcode
);
6484 if (rA(ctx
->opcode
) == 0)
6485 tcg_gen_movi_tl(EA
, uimm
<< sh
);
6487 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], uimm
<< sh
);
6490 static always_inline
void gen_op_evldd(DisasContext
*ctx
, TCGv addr
)
6492 #if defined(TARGET_PPC64)
6493 gen_qemu_ld64(cpu_gpr
[rD(ctx
->opcode
)], addr
, ctx
->mem_idx
);
6495 TCGv_i64 t0
= tcg_temp_new_i64();
6496 gen_qemu_ld64(t0
, addr
, ctx
->mem_idx
);
6497 tcg_gen_trunc_i64_i32(cpu_gpr
[rD(ctx
->opcode
)], t0
);
6498 tcg_gen_shri_i64(t0
, t0
, 32);
6499 tcg_gen_trunc_i64_i32(cpu_gprh
[rD(ctx
->opcode
)], t0
);
6500 tcg_temp_free_i64(t0
);
6504 static always_inline
void gen_op_evldw(DisasContext
*ctx
, TCGv addr
)
6506 #if defined(TARGET_PPC64)
6507 TCGv t0
= tcg_temp_new();
6508 gen_qemu_ld32u(t0
, addr
, ctx
->mem_idx
);
6509 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
6510 tcg_gen_addi_tl(addr
, addr
, 4);
6511 gen_qemu_ld32u(t0
, addr
, ctx
->mem_idx
);
6512 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6515 gen_qemu_ld32u(cpu_gprh
[rD(ctx
->opcode
)], addr
, ctx
->mem_idx
);
6516 tcg_gen_addi_tl(addr
, addr
, 4);
6517 gen_qemu_ld32u(cpu_gpr
[rD(ctx
->opcode
)], addr
, ctx
->mem_idx
);
6521 static always_inline
void gen_op_evldh(DisasContext
*ctx
, TCGv addr
)
6523 TCGv t0
= tcg_temp_new();
6524 #if defined(TARGET_PPC64)
6525 gen_qemu_ld16u(t0
, addr
, ctx
->mem_idx
);
6526 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
6527 tcg_gen_addi_tl(addr
, addr
, 2);
6528 gen_qemu_ld16u(t0
, addr
, ctx
->mem_idx
);
6529 tcg_gen_shli_tl(t0
, t0
, 32);
6530 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6531 tcg_gen_addi_tl(addr
, addr
, 2);
6532 gen_qemu_ld16u(t0
, addr
, ctx
->mem_idx
);
6533 tcg_gen_shli_tl(t0
, t0
, 16);
6534 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6535 tcg_gen_addi_tl(addr
, addr
, 2);
6536 gen_qemu_ld16u(t0
, addr
, ctx
->mem_idx
);
6537 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6539 gen_qemu_ld16u(t0
, addr
, ctx
->mem_idx
);
6540 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
6541 tcg_gen_addi_tl(addr
, addr
, 2);
6542 gen_qemu_ld16u(t0
, addr
, ctx
->mem_idx
);
6543 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
6544 tcg_gen_addi_tl(addr
, addr
, 2);
6545 gen_qemu_ld16u(t0
, addr
, ctx
->mem_idx
);
6546 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
6547 tcg_gen_addi_tl(addr
, addr
, 2);
6548 gen_qemu_ld16u(t0
, addr
, ctx
->mem_idx
);
6549 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6554 static always_inline
void gen_op_evlhhesplat(DisasContext
*ctx
, TCGv addr
)
6556 TCGv t0
= tcg_temp_new();
6557 gen_qemu_ld16u(t0
, addr
, ctx
->mem_idx
);
6558 #if defined(TARGET_PPC64)
6559 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
6560 tcg_gen_shli_tl(t0
, t0
, 16);
6561 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6563 tcg_gen_shli_tl(t0
, t0
, 16);
6564 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
6565 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
6570 static always_inline
void gen_op_evlhhousplat(DisasContext
*ctx
, TCGv addr
)
6572 TCGv t0
= tcg_temp_new();
6573 gen_qemu_ld16u(t0
, addr
, ctx
->mem_idx
);
6574 #if defined(TARGET_PPC64)
6575 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
6576 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6578 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
6579 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
6584 static always_inline
void gen_op_evlhhossplat(DisasContext
*ctx
, TCGv addr
)
6586 TCGv t0
= tcg_temp_new();
6587 gen_qemu_ld16s(t0
, addr
, ctx
->mem_idx
);
6588 #if defined(TARGET_PPC64)
6589 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
6590 tcg_gen_ext32u_tl(t0
, t0
);
6591 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6593 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
6594 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
6599 static always_inline
void gen_op_evlwhe(DisasContext
*ctx
, TCGv addr
)
6601 TCGv t0
= tcg_temp_new();
6602 #if defined(TARGET_PPC64)
6603 gen_qemu_ld16u(t0
, addr
, ctx
->mem_idx
);
6604 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
6605 gen_qemu_ld16u(t0
, addr
, ctx
->mem_idx
);
6606 tcg_gen_shli_tl(t0
, t0
, 16);
6607 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6609 gen_qemu_ld16u(t0
, addr
, ctx
->mem_idx
);
6610 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
6611 tcg_gen_addi_tl(addr
, addr
, 2);
6612 gen_qemu_ld16u(t0
, addr
, ctx
->mem_idx
);
6613 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
6618 static always_inline
void gen_op_evlwhou(DisasContext
*ctx
, TCGv addr
)
6620 #if defined(TARGET_PPC64)
6621 TCGv t0
= tcg_temp_new();
6622 gen_qemu_ld16u(cpu_gpr
[rD(ctx
->opcode
)], addr
, ctx
->mem_idx
);
6623 tcg_gen_addi_tl(addr
, addr
, 2);
6624 gen_qemu_ld16u(t0
, addr
, ctx
->mem_idx
);
6625 tcg_gen_shli_tl(t0
, t0
, 32);
6626 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6629 gen_qemu_ld16u(cpu_gprh
[rD(ctx
->opcode
)], addr
, ctx
->mem_idx
);
6630 tcg_gen_addi_tl(addr
, addr
, 2);
6631 gen_qemu_ld16u(cpu_gpr
[rD(ctx
->opcode
)], addr
, ctx
->mem_idx
);
6635 static always_inline
void gen_op_evlwhos(DisasContext
*ctx
, TCGv addr
)
6637 #if defined(TARGET_PPC64)
6638 TCGv t0
= tcg_temp_new();
6639 gen_qemu_ld16s(t0
, addr
, ctx
->mem_idx
);
6640 tcg_gen_ext32u_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
6641 tcg_gen_addi_tl(addr
, addr
, 2);
6642 gen_qemu_ld16s(t0
, addr
, ctx
->mem_idx
);
6643 tcg_gen_shli_tl(t0
, t0
, 32);
6644 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6647 gen_qemu_ld16s(cpu_gprh
[rD(ctx
->opcode
)], addr
, ctx
->mem_idx
);
6648 tcg_gen_addi_tl(addr
, addr
, 2);
6649 gen_qemu_ld16s(cpu_gpr
[rD(ctx
->opcode
)], addr
, ctx
->mem_idx
);
6653 static always_inline
void gen_op_evlwwsplat(DisasContext
*ctx
, TCGv addr
)
6655 TCGv t0
= tcg_temp_new();
6656 gen_qemu_ld32u(t0
, addr
, ctx
->mem_idx
);
6657 #if defined(TARGET_PPC64)
6658 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
6659 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6661 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
);
6662 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
6667 static always_inline
void gen_op_evlwhsplat(DisasContext
*ctx
, TCGv addr
)
6669 TCGv t0
= tcg_temp_new();
6670 #if defined(TARGET_PPC64)
6671 gen_qemu_ld16u(t0
, addr
, ctx
->mem_idx
);
6672 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 48);
6673 tcg_gen_shli_tl(t0
, t0
, 32);
6674 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6675 tcg_gen_addi_tl(addr
, addr
, 2);
6676 gen_qemu_ld16u(t0
, addr
, ctx
->mem_idx
);
6677 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6678 tcg_gen_shli_tl(t0
, t0
, 16);
6679 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)], t0
);
6681 gen_qemu_ld16u(t0
, addr
, ctx
->mem_idx
);
6682 tcg_gen_shli_tl(cpu_gprh
[rD(ctx
->opcode
)], t0
, 16);
6683 tcg_gen_or_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
6684 tcg_gen_addi_tl(addr
, addr
, 2);
6685 gen_qemu_ld16u(t0
, addr
, ctx
->mem_idx
);
6686 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, 16);
6687 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rD(ctx
->opcode
)], t0
);
6692 static always_inline
void gen_op_evstdd(DisasContext
*ctx
, TCGv addr
)
6694 #if defined(TARGET_PPC64)
6695 gen_qemu_st64(cpu_gpr
[rS(ctx
->opcode
)], addr
, ctx
->mem_idx
);
6697 TCGv_i64 t0
= tcg_temp_new_i64();
6698 tcg_gen_concat_i32_i64(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gprh
[rS(ctx
->opcode
)]);
6699 gen_qemu_st64(t0
, addr
, ctx
->mem_idx
);
6700 tcg_temp_free_i64(t0
);
6704 static always_inline
void gen_op_evstdw(DisasContext
*ctx
, TCGv addr
)
6706 #if defined(TARGET_PPC64)
6707 TCGv t0
= tcg_temp_new();
6708 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
6709 gen_qemu_st32(t0
, addr
, ctx
->mem_idx
);
6712 gen_qemu_st32(cpu_gprh
[rS(ctx
->opcode
)], addr
, ctx
->mem_idx
);
6714 tcg_gen_addi_tl(addr
, addr
, 4);
6715 gen_qemu_st32(cpu_gpr
[rS(ctx
->opcode
)], addr
, ctx
->mem_idx
);
6718 static always_inline
void gen_op_evstdh(DisasContext
*ctx
, TCGv addr
)
6720 TCGv t0
= tcg_temp_new();
6721 #if defined(TARGET_PPC64)
6722 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
6724 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
6726 gen_qemu_st16(t0
, addr
, ctx
->mem_idx
);
6727 tcg_gen_addi_tl(addr
, addr
, 2);
6728 #if defined(TARGET_PPC64)
6729 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
6730 gen_qemu_st16(t0
, addr
, ctx
->mem_idx
);
6732 gen_qemu_st16(cpu_gprh
[rS(ctx
->opcode
)], addr
, ctx
->mem_idx
);
6734 tcg_gen_addi_tl(addr
, addr
, 2);
6735 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
6736 gen_qemu_st16(t0
, addr
, ctx
->mem_idx
);
6738 tcg_gen_addi_tl(addr
, addr
, 2);
6739 gen_qemu_st16(cpu_gpr
[rS(ctx
->opcode
)], addr
, ctx
->mem_idx
);
6742 static always_inline
void gen_op_evstwhe(DisasContext
*ctx
, TCGv addr
)
6744 TCGv t0
= tcg_temp_new();
6745 #if defined(TARGET_PPC64)
6746 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 48);
6748 tcg_gen_shri_tl(t0
, cpu_gprh
[rS(ctx
->opcode
)], 16);
6750 gen_qemu_st16(t0
, addr
, ctx
->mem_idx
);
6751 tcg_gen_addi_tl(addr
, addr
, 2);
6752 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 16);
6753 gen_qemu_st16(t0
, addr
, ctx
->mem_idx
);
6757 static always_inline
void gen_op_evstwho(DisasContext
*ctx
, TCGv addr
)
6759 #if defined(TARGET_PPC64)
6760 TCGv t0
= tcg_temp_new();
6761 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
6762 gen_qemu_st16(t0
, addr
, ctx
->mem_idx
);
6765 gen_qemu_st16(cpu_gprh
[rS(ctx
->opcode
)], addr
, ctx
->mem_idx
);
6767 tcg_gen_addi_tl(addr
, addr
, 2);
6768 gen_qemu_st16(cpu_gpr
[rS(ctx
->opcode
)], addr
, ctx
->mem_idx
);
6771 static always_inline
void gen_op_evstwwe(DisasContext
*ctx
, TCGv addr
)
6773 #if defined(TARGET_PPC64)
6774 TCGv t0
= tcg_temp_new();
6775 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], 32);
6776 gen_qemu_st32(t0
, addr
, ctx
->mem_idx
);
6779 gen_qemu_st32(cpu_gprh
[rS(ctx
->opcode
)], addr
, ctx
->mem_idx
);
6783 static always_inline
void gen_op_evstwwo(DisasContext
*ctx
, TCGv addr
)
6785 gen_qemu_st32(cpu_gpr
[rS(ctx
->opcode
)], addr
, ctx
->mem_idx
);
6788 #define GEN_SPEOP_LDST(name, opc2, sh) \
6789 GEN_HANDLER(gen_##name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE) \
6792 if (unlikely(!ctx->spe_enabled)) { \
6793 GEN_EXCP_NO_AP(ctx); \
6796 t0 = tcg_temp_new(); \
6797 if (Rc(ctx->opcode)) { \
6798 gen_addr_spe_imm_index(t0, ctx, sh); \
6800 gen_addr_reg_index(t0, ctx); \
6802 gen_op_##name(ctx, t0); \
6803 tcg_temp_free(t0); \
6806 GEN_SPEOP_LDST(evldd
, 0x00, 3);
6807 GEN_SPEOP_LDST(evldw
, 0x01, 3);
6808 GEN_SPEOP_LDST(evldh
, 0x02, 3);
6809 GEN_SPEOP_LDST(evlhhesplat
, 0x04, 1);
6810 GEN_SPEOP_LDST(evlhhousplat
, 0x06, 1);
6811 GEN_SPEOP_LDST(evlhhossplat
, 0x07, 1);
6812 GEN_SPEOP_LDST(evlwhe
, 0x08, 2);
6813 GEN_SPEOP_LDST(evlwhou
, 0x0A, 2);
6814 GEN_SPEOP_LDST(evlwhos
, 0x0B, 2);
6815 GEN_SPEOP_LDST(evlwwsplat
, 0x0C, 2);
6816 GEN_SPEOP_LDST(evlwhsplat
, 0x0E, 2);
6818 GEN_SPEOP_LDST(evstdd
, 0x10, 3);
6819 GEN_SPEOP_LDST(evstdw
, 0x11, 3);
6820 GEN_SPEOP_LDST(evstdh
, 0x12, 3);
6821 GEN_SPEOP_LDST(evstwhe
, 0x18, 2);
6822 GEN_SPEOP_LDST(evstwho
, 0x1A, 2);
6823 GEN_SPEOP_LDST(evstwwe
, 0x1C, 2);
6824 GEN_SPEOP_LDST(evstwwo
, 0x1E, 2);
6826 /* Multiply and add - TODO */
6828 GEN_SPE(speundef
, evmhessf
, 0x01, 0x10, 0x00000000, PPC_SPE
);
6829 GEN_SPE(speundef
, evmhossf
, 0x03, 0x10, 0x00000000, PPC_SPE
);
6830 GEN_SPE(evmheumi
, evmhesmi
, 0x04, 0x10, 0x00000000, PPC_SPE
);
6831 GEN_SPE(speundef
, evmhesmf
, 0x05, 0x10, 0x00000000, PPC_SPE
);
6832 GEN_SPE(evmhoumi
, evmhosmi
, 0x06, 0x10, 0x00000000, PPC_SPE
);
6833 GEN_SPE(speundef
, evmhosmf
, 0x07, 0x10, 0x00000000, PPC_SPE
);
6834 GEN_SPE(speundef
, evmhessfa
, 0x11, 0x10, 0x00000000, PPC_SPE
);
6835 GEN_SPE(speundef
, evmhossfa
, 0x13, 0x10, 0x00000000, PPC_SPE
);
6836 GEN_SPE(evmheumia
, evmhesmia
, 0x14, 0x10, 0x00000000, PPC_SPE
);
6837 GEN_SPE(speundef
, evmhesmfa
, 0x15, 0x10, 0x00000000, PPC_SPE
);
6838 GEN_SPE(evmhoumia
, evmhosmia
, 0x16, 0x10, 0x00000000, PPC_SPE
);
6839 GEN_SPE(speundef
, evmhosmfa
, 0x17, 0x10, 0x00000000, PPC_SPE
);
6841 GEN_SPE(speundef
, evmwhssf
, 0x03, 0x11, 0x00000000, PPC_SPE
);
6842 GEN_SPE(evmwlumi
, speundef
, 0x04, 0x11, 0x00000000, PPC_SPE
);
6843 GEN_SPE(evmwhumi
, evmwhsmi
, 0x06, 0x11, 0x00000000, PPC_SPE
);
6844 GEN_SPE(speundef
, evmwhsmf
, 0x07, 0x11, 0x00000000, PPC_SPE
);
6845 GEN_SPE(speundef
, evmwssf
, 0x09, 0x11, 0x00000000, PPC_SPE
);
6846 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, PPC_SPE
);
6847 GEN_SPE(speundef
, evmwsmf
, 0x0D, 0x11, 0x00000000, PPC_SPE
);
6848 GEN_SPE(speundef
, evmwhssfa
, 0x13, 0x11, 0x00000000, PPC_SPE
);
6849 GEN_SPE(evmwlumia
, speundef
, 0x14, 0x11, 0x00000000, PPC_SPE
);
6850 GEN_SPE(evmwhumia
, evmwhsmia
, 0x16, 0x11, 0x00000000, PPC_SPE
);
6851 GEN_SPE(speundef
, evmwhsmfa
, 0x17, 0x11, 0x00000000, PPC_SPE
);
6852 GEN_SPE(speundef
, evmwssfa
, 0x19, 0x11, 0x00000000, PPC_SPE
);
6853 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, PPC_SPE
);
6854 GEN_SPE(speundef
, evmwsmfa
, 0x1D, 0x11, 0x00000000, PPC_SPE
);
6856 GEN_SPE(evadduiaaw
, evaddsiaaw
, 0x00, 0x13, 0x0000F800, PPC_SPE
);
6857 GEN_SPE(evsubfusiaaw
, evsubfssiaaw
, 0x01, 0x13, 0x0000F800, PPC_SPE
);
6858 GEN_SPE(evaddumiaaw
, evaddsmiaaw
, 0x04, 0x13, 0x0000F800, PPC_SPE
);
6859 GEN_SPE(evsubfumiaaw
, evsubfsmiaaw
, 0x05, 0x13, 0x0000F800, PPC_SPE
);
6860 GEN_SPE(evdivws
, evdivwu
, 0x06, 0x13, 0x00000000, PPC_SPE
);
6861 GEN_SPE(evmra
, speundef
, 0x07, 0x13, 0x0000F800, PPC_SPE
);
6863 GEN_SPE(evmheusiaaw
, evmhessiaaw
, 0x00, 0x14, 0x00000000, PPC_SPE
);
6864 GEN_SPE(speundef
, evmhessfaaw
, 0x01, 0x14, 0x00000000, PPC_SPE
);
6865 GEN_SPE(evmhousiaaw
, evmhossiaaw
, 0x02, 0x14, 0x00000000, PPC_SPE
);
6866 GEN_SPE(speundef
, evmhossfaaw
, 0x03, 0x14, 0x00000000, PPC_SPE
);
6867 GEN_SPE(evmheumiaaw
, evmhesmiaaw
, 0x04, 0x14, 0x00000000, PPC_SPE
);
6868 GEN_SPE(speundef
, evmhesmfaaw
, 0x05, 0x14, 0x00000000, PPC_SPE
);
6869 GEN_SPE(evmhoumiaaw
, evmhosmiaaw
, 0x06, 0x14, 0x00000000, PPC_SPE
);
6870 GEN_SPE(speundef
, evmhosmfaaw
, 0x07, 0x14, 0x00000000, PPC_SPE
);
6871 GEN_SPE(evmhegumiaa
, evmhegsmiaa
, 0x14, 0x14, 0x00000000, PPC_SPE
);
6872 GEN_SPE(speundef
, evmhegsmfaa
, 0x15, 0x14, 0x00000000, PPC_SPE
);
6873 GEN_SPE(evmhogumiaa
, evmhogsmiaa
, 0x16, 0x14, 0x00000000, PPC_SPE
);
6874 GEN_SPE(speundef
, evmhogsmfaa
, 0x17, 0x14, 0x00000000, PPC_SPE
);
6876 GEN_SPE(evmwlusiaaw
, evmwlssiaaw
, 0x00, 0x15, 0x00000000, PPC_SPE
);
6877 GEN_SPE(evmwlumiaaw
, evmwlsmiaaw
, 0x04, 0x15, 0x00000000, PPC_SPE
);
6878 GEN_SPE(speundef
, evmwssfaa
, 0x09, 0x15, 0x00000000, PPC_SPE
);
6879 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, PPC_SPE
);
6880 GEN_SPE(speundef
, evmwsmfaa
, 0x0D, 0x15, 0x00000000, PPC_SPE
);
6882 GEN_SPE(evmheusianw
, evmhessianw
, 0x00, 0x16, 0x00000000, PPC_SPE
);
6883 GEN_SPE(speundef
, evmhessfanw
, 0x01, 0x16, 0x00000000, PPC_SPE
);
6884 GEN_SPE(evmhousianw
, evmhossianw
, 0x02, 0x16, 0x00000000, PPC_SPE
);
6885 GEN_SPE(speundef
, evmhossfanw
, 0x03, 0x16, 0x00000000, PPC_SPE
);
6886 GEN_SPE(evmheumianw
, evmhesmianw
, 0x04, 0x16, 0x00000000, PPC_SPE
);
6887 GEN_SPE(speundef
, evmhesmfanw
, 0x05, 0x16, 0x00000000, PPC_SPE
);
6888 GEN_SPE(evmhoumianw
, evmhosmianw
, 0x06, 0x16, 0x00000000, PPC_SPE
);
6889 GEN_SPE(speundef
, evmhosmfanw
, 0x07, 0x16, 0x00000000, PPC_SPE
);
6890 GEN_SPE(evmhegumian
, evmhegsmian
, 0x14, 0x16, 0x00000000, PPC_SPE
);
6891 GEN_SPE(speundef
, evmhegsmfan
, 0x15, 0x16, 0x00000000, PPC_SPE
);
6892 GEN_SPE(evmhigumian
, evmhigsmian
, 0x16, 0x16, 0x00000000, PPC_SPE
);
6893 GEN_SPE(speundef
, evmhogsmfan
, 0x17, 0x16, 0x00000000, PPC_SPE
);
6895 GEN_SPE(evmwlusianw
, evmwlssianw
, 0x00, 0x17, 0x00000000, PPC_SPE
);
6896 GEN_SPE(evmwlumianw
, evmwlsmianw
, 0x04, 0x17, 0x00000000, PPC_SPE
);
6897 GEN_SPE(speundef
, evmwssfan
, 0x09, 0x17, 0x00000000, PPC_SPE
);
6898 GEN_SPE(evmwumian
, evmwsmian
, 0x0C, 0x17, 0x00000000, PPC_SPE
);
6899 GEN_SPE(speundef
, evmwsmfan
, 0x0D, 0x17, 0x00000000, PPC_SPE
);
6902 /*** SPE floating-point extension ***/
6903 #if defined(TARGET_PPC64)
6904 #define GEN_SPEFPUOP_CONV_32_32(name) \
6905 static always_inline void gen_##name (DisasContext *ctx) \
6909 t0 = tcg_temp_new_i32(); \
6910 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
6911 gen_helper_##name(t0, t0); \
6912 t1 = tcg_temp_new(); \
6913 tcg_gen_extu_i32_tl(t1, t0); \
6914 tcg_temp_free_i32(t0); \
6915 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
6916 0xFFFFFFFF00000000ULL); \
6917 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
6918 tcg_temp_free(t1); \
6920 #define GEN_SPEFPUOP_CONV_32_64(name) \
6921 static always_inline void gen_##name (DisasContext *ctx) \
6925 t0 = tcg_temp_new_i32(); \
6926 gen_helper_##name(t0, cpu_gpr[rB(ctx->opcode)]); \
6927 t1 = tcg_temp_new(); \
6928 tcg_gen_extu_i32_tl(t1, t0); \
6929 tcg_temp_free_i32(t0); \
6930 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
6931 0xFFFFFFFF00000000ULL); \
6932 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \
6933 tcg_temp_free(t1); \
6935 #define GEN_SPEFPUOP_CONV_64_32(name) \
6936 static always_inline void gen_##name (DisasContext *ctx) \
6938 TCGv_i32 t0 = tcg_temp_new_i32(); \
6939 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
6940 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], t0); \
6941 tcg_temp_free_i32(t0); \
6943 #define GEN_SPEFPUOP_CONV_64_64(name) \
6944 static always_inline void gen_##name (DisasContext *ctx) \
6946 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
6948 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
6949 static always_inline void gen_##name (DisasContext *ctx) \
6953 if (unlikely(!ctx->spe_enabled)) { \
6954 GEN_EXCP_NO_AP(ctx); \
6957 t0 = tcg_temp_new_i32(); \
6958 t1 = tcg_temp_new_i32(); \
6959 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6960 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
6961 gen_helper_##name(t0, t0, t1); \
6962 tcg_temp_free_i32(t1); \
6963 t2 = tcg_temp_new(); \
6964 tcg_gen_extu_i32_tl(t2, t0); \
6965 tcg_temp_free_i32(t0); \
6966 tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \
6967 0xFFFFFFFF00000000ULL); \
6968 tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \
6969 tcg_temp_free(t2); \
6971 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
6972 static always_inline void gen_##name (DisasContext *ctx) \
6974 if (unlikely(!ctx->spe_enabled)) { \
6975 GEN_EXCP_NO_AP(ctx); \
6978 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6979 cpu_gpr[rB(ctx->opcode)]); \
6981 #define GEN_SPEFPUOP_COMP_32(name) \
6982 static always_inline void gen_##name (DisasContext *ctx) \
6985 if (unlikely(!ctx->spe_enabled)) { \
6986 GEN_EXCP_NO_AP(ctx); \
6989 t0 = tcg_temp_new_i32(); \
6990 t1 = tcg_temp_new_i32(); \
6991 tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6992 tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
6993 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], t0, t1); \
6994 tcg_temp_free_i32(t0); \
6995 tcg_temp_free_i32(t1); \
6997 #define GEN_SPEFPUOP_COMP_64(name) \
6998 static always_inline void gen_##name (DisasContext *ctx) \
7000 if (unlikely(!ctx->spe_enabled)) { \
7001 GEN_EXCP_NO_AP(ctx); \
7004 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
7005 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
7008 #define GEN_SPEFPUOP_CONV_32_32(name) \
7009 static always_inline void gen_##name (DisasContext *ctx) \
7011 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
7013 #define GEN_SPEFPUOP_CONV_32_64(name) \
7014 static always_inline void gen_##name (DisasContext *ctx) \
7016 TCGv_i64 t0 = tcg_temp_new_i64(); \
7017 gen_load_gpr64(t0, rB(ctx->opcode)); \
7018 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], t0); \
7019 tcg_temp_free_i64(t0); \
7021 #define GEN_SPEFPUOP_CONV_64_32(name) \
7022 static always_inline void gen_##name (DisasContext *ctx) \
7024 TCGv_i64 t0 = tcg_temp_new_i64(); \
7025 gen_helper_##name(t0, cpu_gpr[rB(ctx->opcode)]); \
7026 gen_store_gpr64(rD(ctx->opcode), t0); \
7027 tcg_temp_free_i64(t0); \
7029 #define GEN_SPEFPUOP_CONV_64_64(name) \
7030 static always_inline void gen_##name (DisasContext *ctx) \
7032 TCGv_i64 t0 = tcg_temp_new_i64(); \
7033 gen_load_gpr64(t0, rB(ctx->opcode)); \
7034 gen_helper_##name(t0, t0); \
7035 gen_store_gpr64(rD(ctx->opcode), t0); \
7036 tcg_temp_free_i64(t0); \
7038 #define GEN_SPEFPUOP_ARITH2_32_32(name) \
7039 static always_inline void gen_##name (DisasContext *ctx) \
7041 if (unlikely(!ctx->spe_enabled)) { \
7042 GEN_EXCP_NO_AP(ctx); \
7045 gen_helper_##name(cpu_gpr[rD(ctx->opcode)], \
7046 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
7048 #define GEN_SPEFPUOP_ARITH2_64_64(name) \
7049 static always_inline void gen_##name (DisasContext *ctx) \
7052 if (unlikely(!ctx->spe_enabled)) { \
7053 GEN_EXCP_NO_AP(ctx); \
7056 t0 = tcg_temp_new_i64(); \
7057 t1 = tcg_temp_new_i64(); \
7058 gen_load_gpr64(t0, rA(ctx->opcode)); \
7059 gen_load_gpr64(t1, rB(ctx->opcode)); \
7060 gen_helper_##name(t0, t0, t1); \
7061 gen_store_gpr64(rD(ctx->opcode), t0); \
7062 tcg_temp_free_i64(t0); \
7063 tcg_temp_free_i64(t1); \
7065 #define GEN_SPEFPUOP_COMP_32(name) \
7066 static always_inline void gen_##name (DisasContext *ctx) \
7068 if (unlikely(!ctx->spe_enabled)) { \
7069 GEN_EXCP_NO_AP(ctx); \
7072 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], \
7073 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
7075 #define GEN_SPEFPUOP_COMP_64(name) \
7076 static always_inline void gen_##name (DisasContext *ctx) \
7079 if (unlikely(!ctx->spe_enabled)) { \
7080 GEN_EXCP_NO_AP(ctx); \
7083 t0 = tcg_temp_new_i64(); \
7084 t1 = tcg_temp_new_i64(); \
7085 gen_load_gpr64(t0, rA(ctx->opcode)); \
7086 gen_load_gpr64(t1, rB(ctx->opcode)); \
7087 gen_helper_##name(cpu_crf[crfD(ctx->opcode)], t0, t1); \
7088 tcg_temp_free_i64(t0); \
7089 tcg_temp_free_i64(t1); \
7093 /* Single precision floating-point vectors operations */
7095 GEN_SPEFPUOP_ARITH2_64_64(evfsadd
);
7096 GEN_SPEFPUOP_ARITH2_64_64(evfssub
);
7097 GEN_SPEFPUOP_ARITH2_64_64(evfsmul
);
7098 GEN_SPEFPUOP_ARITH2_64_64(evfsdiv
);
7099 static always_inline
void gen_evfsabs (DisasContext
*ctx
)
7101 if (unlikely(!ctx
->spe_enabled
)) {
7102 GEN_EXCP_NO_AP(ctx
);
7105 #if defined(TARGET_PPC64)
7106 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000080000000LL
);
7108 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x80000000);
7109 tcg_gen_andi_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
7112 static always_inline
void gen_evfsnabs (DisasContext
*ctx
)
7114 if (unlikely(!ctx
->spe_enabled
)) {
7115 GEN_EXCP_NO_AP(ctx
);
7118 #if defined(TARGET_PPC64)
7119 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
7121 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
7122 tcg_gen_ori_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
7125 static always_inline
void gen_evfsneg (DisasContext
*ctx
)
7127 if (unlikely(!ctx
->spe_enabled
)) {
7128 GEN_EXCP_NO_AP(ctx
);
7131 #if defined(TARGET_PPC64)
7132 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000080000000LL
);
7134 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
7135 tcg_gen_xori_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
7140 GEN_SPEFPUOP_CONV_64_64(evfscfui
);
7141 GEN_SPEFPUOP_CONV_64_64(evfscfsi
);
7142 GEN_SPEFPUOP_CONV_64_64(evfscfuf
);
7143 GEN_SPEFPUOP_CONV_64_64(evfscfsf
);
7144 GEN_SPEFPUOP_CONV_64_64(evfsctui
);
7145 GEN_SPEFPUOP_CONV_64_64(evfsctsi
);
7146 GEN_SPEFPUOP_CONV_64_64(evfsctuf
);
7147 GEN_SPEFPUOP_CONV_64_64(evfsctsf
);
7148 GEN_SPEFPUOP_CONV_64_64(evfsctuiz
);
7149 GEN_SPEFPUOP_CONV_64_64(evfsctsiz
);
7152 GEN_SPEFPUOP_COMP_64(evfscmpgt
);
7153 GEN_SPEFPUOP_COMP_64(evfscmplt
);
7154 GEN_SPEFPUOP_COMP_64(evfscmpeq
);
7155 GEN_SPEFPUOP_COMP_64(evfststgt
);
7156 GEN_SPEFPUOP_COMP_64(evfststlt
);
7157 GEN_SPEFPUOP_COMP_64(evfststeq
);
7159 /* Opcodes definitions */
7160 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, PPC_SPEFPU
); //
7161 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, PPC_SPEFPU
); //
7162 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, PPC_SPEFPU
); //
7163 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, PPC_SPEFPU
); //
7164 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, PPC_SPEFPU
); //
7165 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, PPC_SPEFPU
); //
7166 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, PPC_SPEFPU
); //
7167 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, PPC_SPEFPU
); //
7168 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, PPC_SPEFPU
); //
7169 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, PPC_SPEFPU
); //
7170 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, PPC_SPEFPU
); //
7171 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, PPC_SPEFPU
); //
7172 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, PPC_SPEFPU
); //
7173 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, PPC_SPEFPU
); //
7175 /* Single precision floating-point operations */
7177 GEN_SPEFPUOP_ARITH2_32_32(efsadd
);
7178 GEN_SPEFPUOP_ARITH2_32_32(efssub
);
7179 GEN_SPEFPUOP_ARITH2_32_32(efsmul
);
7180 GEN_SPEFPUOP_ARITH2_32_32(efsdiv
);
7181 static always_inline
void gen_efsabs (DisasContext
*ctx
)
7183 if (unlikely(!ctx
->spe_enabled
)) {
7184 GEN_EXCP_NO_AP(ctx
);
7187 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], (target_long
)~0x80000000LL
);
7189 static always_inline
void gen_efsnabs (DisasContext
*ctx
)
7191 if (unlikely(!ctx
->spe_enabled
)) {
7192 GEN_EXCP_NO_AP(ctx
);
7195 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
7197 static always_inline
void gen_efsneg (DisasContext
*ctx
)
7199 if (unlikely(!ctx
->spe_enabled
)) {
7200 GEN_EXCP_NO_AP(ctx
);
7203 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x80000000);
7207 GEN_SPEFPUOP_CONV_32_32(efscfui
);
7208 GEN_SPEFPUOP_CONV_32_32(efscfsi
);
7209 GEN_SPEFPUOP_CONV_32_32(efscfuf
);
7210 GEN_SPEFPUOP_CONV_32_32(efscfsf
);
7211 GEN_SPEFPUOP_CONV_32_32(efsctui
);
7212 GEN_SPEFPUOP_CONV_32_32(efsctsi
);
7213 GEN_SPEFPUOP_CONV_32_32(efsctuf
);
7214 GEN_SPEFPUOP_CONV_32_32(efsctsf
);
7215 GEN_SPEFPUOP_CONV_32_32(efsctuiz
);
7216 GEN_SPEFPUOP_CONV_32_32(efsctsiz
);
7217 GEN_SPEFPUOP_CONV_32_64(efscfd
);
7220 GEN_SPEFPUOP_COMP_32(efscmpgt
);
7221 GEN_SPEFPUOP_COMP_32(efscmplt
);
7222 GEN_SPEFPUOP_COMP_32(efscmpeq
);
7223 GEN_SPEFPUOP_COMP_32(efststgt
);
7224 GEN_SPEFPUOP_COMP_32(efststlt
);
7225 GEN_SPEFPUOP_COMP_32(efststeq
);
7227 /* Opcodes definitions */
7228 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, PPC_SPEFPU
); //
7229 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, PPC_SPEFPU
); //
7230 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, PPC_SPEFPU
); //
7231 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, PPC_SPEFPU
); //
7232 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, PPC_SPEFPU
); //
7233 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, PPC_SPEFPU
); //
7234 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, PPC_SPEFPU
); //
7235 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, PPC_SPEFPU
); //
7236 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, PPC_SPEFPU
); //
7237 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, PPC_SPEFPU
); //
7238 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, PPC_SPEFPU
); //
7239 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, PPC_SPEFPU
); //
7240 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, PPC_SPEFPU
); //
7241 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, PPC_SPEFPU
); //
7243 /* Double precision floating-point operations */
7245 GEN_SPEFPUOP_ARITH2_64_64(efdadd
);
7246 GEN_SPEFPUOP_ARITH2_64_64(efdsub
);
7247 GEN_SPEFPUOP_ARITH2_64_64(efdmul
);
7248 GEN_SPEFPUOP_ARITH2_64_64(efddiv
);
7249 static always_inline
void gen_efdabs (DisasContext
*ctx
)
7251 if (unlikely(!ctx
->spe_enabled
)) {
7252 GEN_EXCP_NO_AP(ctx
);
7255 #if defined(TARGET_PPC64)
7256 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], ~0x8000000000000000LL
);
7258 tcg_gen_andi_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], ~0x80000000);
7261 static always_inline
void gen_efdnabs (DisasContext
*ctx
)
7263 if (unlikely(!ctx
->spe_enabled
)) {
7264 GEN_EXCP_NO_AP(ctx
);
7267 #if defined(TARGET_PPC64)
7268 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
7270 tcg_gen_ori_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
7273 static always_inline
void gen_efdneg (DisasContext
*ctx
)
7275 if (unlikely(!ctx
->spe_enabled
)) {
7276 GEN_EXCP_NO_AP(ctx
);
7279 #if defined(TARGET_PPC64)
7280 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0x8000000000000000LL
);
7282 tcg_gen_xori_tl(cpu_gprh
[rA(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)], 0x80000000);
7287 GEN_SPEFPUOP_CONV_64_32(efdcfui
);
7288 GEN_SPEFPUOP_CONV_64_32(efdcfsi
);
7289 GEN_SPEFPUOP_CONV_64_32(efdcfuf
);
7290 GEN_SPEFPUOP_CONV_64_32(efdcfsf
);
7291 GEN_SPEFPUOP_CONV_32_64(efdctui
);
7292 GEN_SPEFPUOP_CONV_32_64(efdctsi
);
7293 GEN_SPEFPUOP_CONV_32_64(efdctuf
);
7294 GEN_SPEFPUOP_CONV_32_64(efdctsf
);
7295 GEN_SPEFPUOP_CONV_32_64(efdctuiz
);
7296 GEN_SPEFPUOP_CONV_32_64(efdctsiz
);
7297 GEN_SPEFPUOP_CONV_64_32(efdcfs
);
7298 GEN_SPEFPUOP_CONV_64_64(efdcfuid
);
7299 GEN_SPEFPUOP_CONV_64_64(efdcfsid
);
7300 GEN_SPEFPUOP_CONV_64_64(efdctuidz
);
7301 GEN_SPEFPUOP_CONV_64_64(efdctsidz
);
7304 GEN_SPEFPUOP_COMP_64(efdcmpgt
);
7305 GEN_SPEFPUOP_COMP_64(efdcmplt
);
7306 GEN_SPEFPUOP_COMP_64(efdcmpeq
);
7307 GEN_SPEFPUOP_COMP_64(efdtstgt
);
7308 GEN_SPEFPUOP_COMP_64(efdtstlt
);
7309 GEN_SPEFPUOP_COMP_64(efdtsteq
);
7311 /* Opcodes definitions */
7312 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, PPC_SPEFPU
); //
7313 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, PPC_SPEFPU
); //
7314 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, PPC_SPEFPU
); //
7315 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, PPC_SPEFPU
); //
7316 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, PPC_SPEFPU
); //
7317 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, PPC_SPEFPU
); //
7318 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, PPC_SPEFPU
); //
7319 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, PPC_SPEFPU
); //
7320 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, PPC_SPEFPU
); //
7321 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, PPC_SPEFPU
); //
7322 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, PPC_SPEFPU
); //
7323 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, PPC_SPEFPU
); //
7324 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, PPC_SPEFPU
); //
7325 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, PPC_SPEFPU
); //
7326 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, PPC_SPEFPU
); //
7327 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, PPC_SPEFPU
); //
7329 /* End opcode list */
7330 GEN_OPCODE_MARK(end
);
7332 #include "translate_init.c"
7333 #include "helper_regs.h"
7335 /*****************************************************************************/
7336 /* Misc PowerPC helpers */
7337 void cpu_dump_state (CPUState
*env
, FILE *f
,
7338 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
7346 cpu_fprintf(f
, "NIP " ADDRX
" LR " ADDRX
" CTR " ADDRX
" XER %08x\n",
7347 env
->nip
, env
->lr
, env
->ctr
, env
->xer
);
7348 cpu_fprintf(f
, "MSR " ADDRX
" HID0 " ADDRX
" HF " ADDRX
" idx %d\n",
7349 env
->msr
, env
->spr
[SPR_HID0
], env
->hflags
, env
->mmu_idx
);
7350 #if !defined(NO_TIMER_DUMP)
7351 cpu_fprintf(f
, "TB %08x %08x "
7352 #if !defined(CONFIG_USER_ONLY)
7356 cpu_ppc_load_tbu(env
), cpu_ppc_load_tbl(env
)
7357 #if !defined(CONFIG_USER_ONLY)
7358 , cpu_ppc_load_decr(env
)
7362 for (i
= 0; i
< 32; i
++) {
7363 if ((i
& (RGPL
- 1)) == 0)
7364 cpu_fprintf(f
, "GPR%02d", i
);
7365 cpu_fprintf(f
, " " REGX
, ppc_dump_gpr(env
, i
));
7366 if ((i
& (RGPL
- 1)) == (RGPL
- 1))
7367 cpu_fprintf(f
, "\n");
7369 cpu_fprintf(f
, "CR ");
7370 for (i
= 0; i
< 8; i
++)
7371 cpu_fprintf(f
, "%01x", env
->crf
[i
]);
7372 cpu_fprintf(f
, " [");
7373 for (i
= 0; i
< 8; i
++) {
7375 if (env
->crf
[i
] & 0x08)
7377 else if (env
->crf
[i
] & 0x04)
7379 else if (env
->crf
[i
] & 0x02)
7381 cpu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
7383 cpu_fprintf(f
, " ] RES " ADDRX
"\n", env
->reserve
);
7384 for (i
= 0; i
< 32; i
++) {
7385 if ((i
& (RFPL
- 1)) == 0)
7386 cpu_fprintf(f
, "FPR%02d", i
);
7387 cpu_fprintf(f
, " %016" PRIx64
, *((uint64_t *)&env
->fpr
[i
]));
7388 if ((i
& (RFPL
- 1)) == (RFPL
- 1))
7389 cpu_fprintf(f
, "\n");
7391 #if !defined(CONFIG_USER_ONLY)
7392 cpu_fprintf(f
, "SRR0 " ADDRX
" SRR1 " ADDRX
" SDR1 " ADDRX
"\n",
7393 env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
], env
->sdr1
);
7400 void cpu_dump_statistics (CPUState
*env
, FILE*f
,
7401 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
7404 #if defined(DO_PPC_STATISTICS)
7405 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
7409 for (op1
= 0; op1
< 64; op1
++) {
7411 if (is_indirect_opcode(handler
)) {
7412 t2
= ind_table(handler
);
7413 for (op2
= 0; op2
< 32; op2
++) {
7415 if (is_indirect_opcode(handler
)) {
7416 t3
= ind_table(handler
);
7417 for (op3
= 0; op3
< 32; op3
++) {
7419 if (handler
->count
== 0)
7421 cpu_fprintf(f
, "%02x %02x %02x (%02x %04d) %16s: "
7423 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
7425 handler
->count
, handler
->count
);
7428 if (handler
->count
== 0)
7430 cpu_fprintf(f
, "%02x %02x (%02x %04d) %16s: "
7432 op1
, op2
, op1
, op2
, handler
->oname
,
7433 handler
->count
, handler
->count
);
7437 if (handler
->count
== 0)
7439 cpu_fprintf(f
, "%02x (%02x ) %16s: %016llx %lld\n",
7440 op1
, op1
, handler
->oname
,
7441 handler
->count
, handler
->count
);
7447 /*****************************************************************************/
7448 static always_inline
void gen_intermediate_code_internal (CPUState
*env
,
7449 TranslationBlock
*tb
,
7452 DisasContext ctx
, *ctxp
= &ctx
;
7453 opc_handler_t
**table
, *handler
;
7454 target_ulong pc_start
;
7455 uint16_t *gen_opc_end
;
7456 int supervisor
, little_endian
;
7463 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
7464 #if defined(OPTIMIZE_FPRF_UPDATE)
7465 gen_fprf_ptr
= gen_fprf_buf
;
7469 ctx
.exception
= POWERPC_EXCP_NONE
;
7470 ctx
.spr_cb
= env
->spr_cb
;
7471 supervisor
= env
->mmu_idx
;
7472 #if !defined(CONFIG_USER_ONLY)
7473 ctx
.supervisor
= supervisor
;
7475 little_endian
= env
->hflags
& (1 << MSR_LE
) ? 1 : 0;
7476 #if defined(TARGET_PPC64)
7477 ctx
.sf_mode
= msr_sf
;
7478 ctx
.mem_idx
= (supervisor
<< 2) | (msr_sf
<< 1) | little_endian
;
7480 ctx
.mem_idx
= (supervisor
<< 1) | little_endian
;
7482 ctx
.fpu_enabled
= msr_fp
;
7483 if ((env
->flags
& POWERPC_FLAG_SPE
) && msr_spe
)
7484 ctx
.spe_enabled
= msr_spe
;
7486 ctx
.spe_enabled
= 0;
7487 if ((env
->flags
& POWERPC_FLAG_VRE
) && msr_vr
)
7488 ctx
.altivec_enabled
= msr_vr
;
7490 ctx
.altivec_enabled
= 0;
7491 if ((env
->flags
& POWERPC_FLAG_SE
) && msr_se
)
7492 ctx
.singlestep_enabled
= CPU_SINGLE_STEP
;
7494 ctx
.singlestep_enabled
= 0;
7495 if ((env
->flags
& POWERPC_FLAG_BE
) && msr_be
)
7496 ctx
.singlestep_enabled
|= CPU_BRANCH_STEP
;
7497 if (unlikely(env
->singlestep_enabled
))
7498 ctx
.singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
7499 #if defined (DO_SINGLE_STEP) && 0
7500 /* Single step trace mode */
7504 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
7506 max_insns
= CF_COUNT_MASK
;
7509 /* Set env in case of segfault during code fetch */
7510 while (ctx
.exception
== POWERPC_EXCP_NONE
&& gen_opc_ptr
< gen_opc_end
) {
7511 if (unlikely(!TAILQ_EMPTY(&env
->breakpoints
))) {
7512 TAILQ_FOREACH(bp
, &env
->breakpoints
, entry
) {
7513 if (bp
->pc
== ctx
.nip
) {
7514 gen_update_nip(&ctx
, ctx
.nip
);
7515 gen_helper_raise_debug();
7520 if (unlikely(search_pc
)) {
7521 j
= gen_opc_ptr
- gen_opc_buf
;
7525 gen_opc_instr_start
[lj
++] = 0;
7526 gen_opc_pc
[lj
] = ctx
.nip
;
7527 gen_opc_instr_start
[lj
] = 1;
7528 gen_opc_icount
[lj
] = num_insns
;
7531 #if defined PPC_DEBUG_DISAS
7532 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
7533 fprintf(logfile
, "----------------\n");
7534 fprintf(logfile
, "nip=" ADDRX
" super=%d ir=%d\n",
7535 ctx
.nip
, supervisor
, (int)msr_ir
);
7538 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
7540 if (unlikely(little_endian
)) {
7541 ctx
.opcode
= bswap32(ldl_code(ctx
.nip
));
7543 ctx
.opcode
= ldl_code(ctx
.nip
);
7545 #if defined PPC_DEBUG_DISAS
7546 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
7547 fprintf(logfile
, "translate opcode %08x (%02x %02x %02x) (%s)\n",
7548 ctx
.opcode
, opc1(ctx
.opcode
), opc2(ctx
.opcode
),
7549 opc3(ctx
.opcode
), little_endian
? "little" : "big");
7553 table
= env
->opcodes
;
7555 handler
= table
[opc1(ctx
.opcode
)];
7556 if (is_indirect_opcode(handler
)) {
7557 table
= ind_table(handler
);
7558 handler
= table
[opc2(ctx
.opcode
)];
7559 if (is_indirect_opcode(handler
)) {
7560 table
= ind_table(handler
);
7561 handler
= table
[opc3(ctx
.opcode
)];
7564 /* Is opcode *REALLY* valid ? */
7565 if (unlikely(handler
->handler
== &gen_invalid
)) {
7566 if (loglevel
!= 0) {
7567 fprintf(logfile
, "invalid/unsupported opcode: "
7568 "%02x - %02x - %02x (%08x) " ADDRX
" %d\n",
7569 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
7570 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
7572 printf("invalid/unsupported opcode: "
7573 "%02x - %02x - %02x (%08x) " ADDRX
" %d\n",
7574 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
7575 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
7578 if (unlikely((ctx
.opcode
& handler
->inval
) != 0)) {
7579 if (loglevel
!= 0) {
7580 fprintf(logfile
, "invalid bits: %08x for opcode: "
7581 "%02x - %02x - %02x (%08x) " ADDRX
"\n",
7582 ctx
.opcode
& handler
->inval
, opc1(ctx
.opcode
),
7583 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
7584 ctx
.opcode
, ctx
.nip
- 4);
7586 printf("invalid bits: %08x for opcode: "
7587 "%02x - %02x - %02x (%08x) " ADDRX
"\n",
7588 ctx
.opcode
& handler
->inval
, opc1(ctx
.opcode
),
7589 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
7590 ctx
.opcode
, ctx
.nip
- 4);
7592 GEN_EXCP_INVAL(ctxp
);
7596 (*(handler
->handler
))(&ctx
);
7597 #if defined(DO_PPC_STATISTICS)
7600 /* Check trace mode exceptions */
7601 if (unlikely(ctx
.singlestep_enabled
& CPU_SINGLE_STEP
&&
7602 (ctx
.nip
<= 0x100 || ctx
.nip
> 0xF00) &&
7603 ctx
.exception
!= POWERPC_SYSCALL
&&
7604 ctx
.exception
!= POWERPC_EXCP_TRAP
&&
7605 ctx
.exception
!= POWERPC_EXCP_BRANCH
)) {
7606 GEN_EXCP(ctxp
, POWERPC_EXCP_TRACE
, 0);
7607 } else if (unlikely(((ctx
.nip
& (TARGET_PAGE_SIZE
- 1)) == 0) ||
7608 (env
->singlestep_enabled
) ||
7609 num_insns
>= max_insns
)) {
7610 /* if we reach a page boundary or are single stepping, stop
7615 #if defined (DO_SINGLE_STEP)
7619 if (tb
->cflags
& CF_LAST_IO
)
7621 if (ctx
.exception
== POWERPC_EXCP_NONE
) {
7622 gen_goto_tb(&ctx
, 0, ctx
.nip
);
7623 } else if (ctx
.exception
!= POWERPC_EXCP_BRANCH
) {
7624 if (unlikely(env
->singlestep_enabled
)) {
7625 gen_update_nip(&ctx
, ctx
.nip
);
7626 gen_helper_raise_debug();
7628 /* Generate the return instruction */
7631 gen_icount_end(tb
, num_insns
);
7632 *gen_opc_ptr
= INDEX_op_end
;
7633 if (unlikely(search_pc
)) {
7634 j
= gen_opc_ptr
- gen_opc_buf
;
7637 gen_opc_instr_start
[lj
++] = 0;
7639 tb
->size
= ctx
.nip
- pc_start
;
7640 tb
->icount
= num_insns
;
7642 #if defined(DEBUG_DISAS)
7643 if (loglevel
& CPU_LOG_TB_CPU
) {
7644 fprintf(logfile
, "---------------- excp: %04x\n", ctx
.exception
);
7645 cpu_dump_state(env
, logfile
, fprintf
, 0);
7647 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
7649 flags
= env
->bfd_mach
;
7650 flags
|= little_endian
<< 16;
7651 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
7652 target_disas(logfile
, pc_start
, ctx
.nip
- pc_start
, flags
);
7653 fprintf(logfile
, "\n");
7658 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
7660 gen_intermediate_code_internal(env
, tb
, 0);
7663 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
7665 gen_intermediate_code_internal(env
, tb
, 1);
7668 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
7669 unsigned long searched_pc
, int pc_pos
, void *puc
)
7671 env
->nip
= gen_opc_pc
[pc_pos
];