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_i32 cpu_fpscr
;
71 /* dyngen register indexes */
73 #if defined(TARGET_PPC64)
76 static TCGv_i64 cpu_T64
[3];
78 static TCGv_i64 cpu_FT
[3];
79 static TCGv_i64 cpu_AVRh
[3], cpu_AVRl
[3];
81 #include "gen-icount.h"
83 void ppc_translate_init(void)
87 static int done_init
= 0;
92 cpu_env
= tcg_global_reg_new_ptr(TCG_AREG0
, "env");
93 #if TARGET_LONG_BITS > HOST_LONG_BITS
94 cpu_T
[0] = tcg_global_mem_new(TCG_AREG0
, offsetof(CPUState
, t0
), "T0");
95 cpu_T
[1] = tcg_global_mem_new(TCG_AREG0
, offsetof(CPUState
, t1
), "T1");
96 cpu_T
[2] = tcg_global_mem_new(TCG_AREG0
, offsetof(CPUState
, t2
), "T2");
98 cpu_T
[0] = tcg_global_reg_new(TCG_AREG1
, "T0");
99 cpu_T
[1] = tcg_global_reg_new(TCG_AREG2
, "T1");
101 /* XXX: This is a temporary workaround for i386.
102 * On i386 qemu_st32 runs out of registers.
103 * The proper fix is to remove cpu_T.
105 cpu_T
[2] = tcg_global_mem_new(TCG_AREG0
, offsetof(CPUState
, t2
), "T2");
107 cpu_T
[2] = tcg_global_reg_new(TCG_AREG3
, "T2");
110 #if !defined(TARGET_PPC64)
111 cpu_T64
[0] = tcg_global_mem_new_i64(TCG_AREG0
, offsetof(CPUState
, t0_64
),
113 cpu_T64
[1] = tcg_global_mem_new_i64(TCG_AREG0
, offsetof(CPUState
, t1_64
),
115 cpu_T64
[2] = tcg_global_mem_new_i64(TCG_AREG0
, offsetof(CPUState
, t2_64
),
119 cpu_FT
[0] = tcg_global_mem_new_i64(TCG_AREG0
,
120 offsetof(CPUState
, ft0
), "FT0");
121 cpu_FT
[1] = tcg_global_mem_new_i64(TCG_AREG0
,
122 offsetof(CPUState
, ft1
), "FT1");
123 cpu_FT
[2] = tcg_global_mem_new_i64(TCG_AREG0
,
124 offsetof(CPUState
, ft2
), "FT2");
126 cpu_AVRh
[0] = tcg_global_mem_new_i64(TCG_AREG0
,
127 offsetof(CPUState
, avr0
.u64
[0]), "AVR0H");
128 cpu_AVRl
[0] = tcg_global_mem_new_i64(TCG_AREG0
,
129 offsetof(CPUState
, avr0
.u64
[1]), "AVR0L");
130 cpu_AVRh
[1] = tcg_global_mem_new_i64(TCG_AREG0
,
131 offsetof(CPUState
, avr1
.u64
[0]), "AVR1H");
132 cpu_AVRl
[1] = tcg_global_mem_new_i64(TCG_AREG0
,
133 offsetof(CPUState
, avr1
.u64
[1]), "AVR1L");
134 cpu_AVRh
[2] = tcg_global_mem_new_i64(TCG_AREG0
,
135 offsetof(CPUState
, avr2
.u64
[0]), "AVR2H");
136 cpu_AVRl
[2] = tcg_global_mem_new_i64(TCG_AREG0
,
137 offsetof(CPUState
, avr2
.u64
[1]), "AVR2L");
141 for (i
= 0; i
< 8; i
++) {
142 sprintf(p
, "crf%d", i
);
143 cpu_crf
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
144 offsetof(CPUState
, crf
[i
]), p
);
148 for (i
= 0; i
< 32; i
++) {
149 sprintf(p
, "r%d", i
);
150 cpu_gpr
[i
] = tcg_global_mem_new(TCG_AREG0
,
151 offsetof(CPUState
, gpr
[i
]), p
);
152 p
+= (i
< 10) ? 3 : 4;
153 #if !defined(TARGET_PPC64)
154 sprintf(p
, "r%dH", i
);
155 cpu_gprh
[i
] = tcg_global_mem_new_i32(TCG_AREG0
,
156 offsetof(CPUState
, gprh
[i
]), p
);
157 p
+= (i
< 10) ? 4 : 5;
160 sprintf(p
, "fp%d", i
);
161 cpu_fpr
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
162 offsetof(CPUState
, fpr
[i
]), p
);
163 p
+= (i
< 10) ? 4 : 5;
165 sprintf(p
, "avr%dH", i
);
166 cpu_avrh
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
167 offsetof(CPUState
, avr
[i
].u64
[0]), p
);
168 p
+= (i
< 10) ? 6 : 7;
170 sprintf(p
, "avr%dL", i
);
171 cpu_avrl
[i
] = tcg_global_mem_new_i64(TCG_AREG0
,
172 offsetof(CPUState
, avr
[i
].u64
[1]), p
);
173 p
+= (i
< 10) ? 6 : 7;
176 cpu_nip
= tcg_global_mem_new(TCG_AREG0
,
177 offsetof(CPUState
, nip
), "nip");
179 cpu_ctr
= tcg_global_mem_new(TCG_AREG0
,
180 offsetof(CPUState
, ctr
), "ctr");
182 cpu_lr
= tcg_global_mem_new(TCG_AREG0
,
183 offsetof(CPUState
, lr
), "lr");
185 cpu_xer
= tcg_global_mem_new(TCG_AREG0
,
186 offsetof(CPUState
, xer
), "xer");
188 cpu_fpscr
= tcg_global_mem_new_i32(TCG_AREG0
,
189 offsetof(CPUState
, fpscr
), "fpscr");
191 /* register helpers */
198 #if defined(OPTIMIZE_FPRF_UPDATE)
199 static uint16_t *gen_fprf_buf
[OPC_BUF_SIZE
];
200 static uint16_t **gen_fprf_ptr
;
203 /* internal defines */
204 typedef struct DisasContext
{
205 struct TranslationBlock
*tb
;
209 /* Routine used to access memory */
211 /* Translation flags */
212 #if !defined(CONFIG_USER_ONLY)
215 #if defined(TARGET_PPC64)
221 ppc_spr_t
*spr_cb
; /* Needed to check rights for mfspr/mtspr */
222 int singlestep_enabled
;
223 int dcache_line_size
;
226 struct opc_handler_t
{
229 /* instruction type */
232 void (*handler
)(DisasContext
*ctx
);
233 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
236 #if defined(DO_PPC_STATISTICS)
241 static always_inline
void gen_reset_fpstatus (void)
243 #ifdef CONFIG_SOFTFLOAT
244 gen_op_reset_fpstatus();
248 static always_inline
void gen_compute_fprf (int set_fprf
, int set_rc
)
251 /* This case might be optimized later */
252 #if defined(OPTIMIZE_FPRF_UPDATE)
253 *gen_fprf_ptr
++ = gen_opc_ptr
;
255 gen_op_compute_fprf(1);
256 if (unlikely(set_rc
)) {
257 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_T
[0]);
258 tcg_gen_andi_i32(cpu_crf
[1], cpu_crf
[1], 0xf);
260 gen_op_float_check_status();
261 } else if (unlikely(set_rc
)) {
262 /* We always need to compute fpcc */
263 gen_op_compute_fprf(0);
264 tcg_gen_trunc_tl_i32(cpu_crf
[1], cpu_T
[0]);
265 tcg_gen_andi_i32(cpu_crf
[1], cpu_crf
[1], 0xf);
267 gen_op_float_check_status();
271 static always_inline
void gen_optimize_fprf (void)
273 #if defined(OPTIMIZE_FPRF_UPDATE)
276 for (ptr
= gen_fprf_buf
; ptr
!= (gen_fprf_ptr
- 1); ptr
++)
277 *ptr
= INDEX_op_nop1
;
278 gen_fprf_ptr
= gen_fprf_buf
;
282 static always_inline
void gen_update_nip (DisasContext
*ctx
, target_ulong nip
)
284 #if defined(TARGET_PPC64)
286 tcg_gen_movi_tl(cpu_nip
, nip
);
289 tcg_gen_movi_tl(cpu_nip
, (uint32_t)nip
);
292 #define GEN_EXCP(ctx, excp, error) \
294 if ((ctx)->exception == POWERPC_EXCP_NONE) { \
295 gen_update_nip(ctx, (ctx)->nip); \
297 gen_op_raise_exception_err((excp), (error)); \
298 ctx->exception = (excp); \
301 #define GEN_EXCP_INVAL(ctx) \
302 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
303 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_INVAL)
305 #define GEN_EXCP_PRIVOPC(ctx) \
306 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
307 POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_OPC)
309 #define GEN_EXCP_PRIVREG(ctx) \
310 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
311 POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_REG)
313 #define GEN_EXCP_NO_FP(ctx) \
314 GEN_EXCP(ctx, POWERPC_EXCP_FPU, 0)
316 #define GEN_EXCP_NO_AP(ctx) \
317 GEN_EXCP(ctx, POWERPC_EXCP_APU, 0)
319 #define GEN_EXCP_NO_VR(ctx) \
320 GEN_EXCP(ctx, POWERPC_EXCP_VPU, 0)
322 /* Stop translation */
323 static always_inline
void GEN_STOP (DisasContext
*ctx
)
325 gen_update_nip(ctx
, ctx
->nip
);
326 ctx
->exception
= POWERPC_EXCP_STOP
;
329 /* No need to update nip here, as execution flow will change */
330 static always_inline
void GEN_SYNC (DisasContext
*ctx
)
332 ctx
->exception
= POWERPC_EXCP_SYNC
;
335 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
336 static void gen_##name (DisasContext *ctx); \
337 GEN_OPCODE(name, opc1, opc2, opc3, inval, type); \
338 static void gen_##name (DisasContext *ctx)
340 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
341 static void gen_##name (DisasContext *ctx); \
342 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type); \
343 static void gen_##name (DisasContext *ctx)
345 typedef struct opcode_t
{
346 unsigned char opc1
, opc2
, opc3
;
347 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
348 unsigned char pad
[5];
350 unsigned char pad
[1];
352 opc_handler_t handler
;
356 /*****************************************************************************/
357 /*** Instruction decoding ***/
358 #define EXTRACT_HELPER(name, shift, nb) \
359 static always_inline uint32_t name (uint32_t opcode) \
361 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
364 #define EXTRACT_SHELPER(name, shift, nb) \
365 static always_inline int32_t name (uint32_t opcode) \
367 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
371 EXTRACT_HELPER(opc1
, 26, 6);
373 EXTRACT_HELPER(opc2
, 1, 5);
375 EXTRACT_HELPER(opc3
, 6, 5);
376 /* Update Cr0 flags */
377 EXTRACT_HELPER(Rc
, 0, 1);
379 EXTRACT_HELPER(rD
, 21, 5);
381 EXTRACT_HELPER(rS
, 21, 5);
383 EXTRACT_HELPER(rA
, 16, 5);
385 EXTRACT_HELPER(rB
, 11, 5);
387 EXTRACT_HELPER(rC
, 6, 5);
389 EXTRACT_HELPER(crfD
, 23, 3);
390 EXTRACT_HELPER(crfS
, 18, 3);
391 EXTRACT_HELPER(crbD
, 21, 5);
392 EXTRACT_HELPER(crbA
, 16, 5);
393 EXTRACT_HELPER(crbB
, 11, 5);
395 EXTRACT_HELPER(_SPR
, 11, 10);
396 static always_inline
uint32_t SPR (uint32_t opcode
)
398 uint32_t sprn
= _SPR(opcode
);
400 return ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
402 /*** Get constants ***/
403 EXTRACT_HELPER(IMM
, 12, 8);
404 /* 16 bits signed immediate value */
405 EXTRACT_SHELPER(SIMM
, 0, 16);
406 /* 16 bits unsigned immediate value */
407 EXTRACT_HELPER(UIMM
, 0, 16);
409 EXTRACT_HELPER(NB
, 11, 5);
411 EXTRACT_HELPER(SH
, 11, 5);
413 EXTRACT_HELPER(MB
, 6, 5);
415 EXTRACT_HELPER(ME
, 1, 5);
417 EXTRACT_HELPER(TO
, 21, 5);
419 EXTRACT_HELPER(CRM
, 12, 8);
420 EXTRACT_HELPER(FM
, 17, 8);
421 EXTRACT_HELPER(SR
, 16, 4);
422 EXTRACT_HELPER(FPIMM
, 12, 4);
424 /*** Jump target decoding ***/
426 EXTRACT_SHELPER(d
, 0, 16);
427 /* Immediate address */
428 static always_inline target_ulong
LI (uint32_t opcode
)
430 return (opcode
>> 0) & 0x03FFFFFC;
433 static always_inline
uint32_t BD (uint32_t opcode
)
435 return (opcode
>> 0) & 0xFFFC;
438 EXTRACT_HELPER(BO
, 21, 5);
439 EXTRACT_HELPER(BI
, 16, 5);
440 /* Absolute/relative address */
441 EXTRACT_HELPER(AA
, 1, 1);
443 EXTRACT_HELPER(LK
, 0, 1);
445 /* Create a mask between <start> and <end> bits */
446 static always_inline target_ulong
MASK (uint32_t start
, uint32_t end
)
450 #if defined(TARGET_PPC64)
451 if (likely(start
== 0)) {
452 ret
= UINT64_MAX
<< (63 - end
);
453 } else if (likely(end
== 63)) {
454 ret
= UINT64_MAX
>> start
;
457 if (likely(start
== 0)) {
458 ret
= UINT32_MAX
<< (31 - end
);
459 } else if (likely(end
== 31)) {
460 ret
= UINT32_MAX
>> start
;
464 ret
= (((target_ulong
)(-1ULL)) >> (start
)) ^
465 (((target_ulong
)(-1ULL) >> (end
)) >> 1);
466 if (unlikely(start
> end
))
473 /*****************************************************************************/
474 /* PowerPC Instructions types definitions */
476 PPC_NONE
= 0x0000000000000000ULL
,
477 /* PowerPC base instructions set */
478 PPC_INSNS_BASE
= 0x0000000000000001ULL
,
479 /* integer operations instructions */
480 #define PPC_INTEGER PPC_INSNS_BASE
481 /* flow control instructions */
482 #define PPC_FLOW PPC_INSNS_BASE
483 /* virtual memory instructions */
484 #define PPC_MEM PPC_INSNS_BASE
485 /* ld/st with reservation instructions */
486 #define PPC_RES PPC_INSNS_BASE
487 /* spr/msr access instructions */
488 #define PPC_MISC PPC_INSNS_BASE
489 /* Deprecated instruction sets */
490 /* Original POWER instruction set */
491 PPC_POWER
= 0x0000000000000002ULL
,
492 /* POWER2 instruction set extension */
493 PPC_POWER2
= 0x0000000000000004ULL
,
494 /* Power RTC support */
495 PPC_POWER_RTC
= 0x0000000000000008ULL
,
496 /* Power-to-PowerPC bridge (601) */
497 PPC_POWER_BR
= 0x0000000000000010ULL
,
498 /* 64 bits PowerPC instruction set */
499 PPC_64B
= 0x0000000000000020ULL
,
500 /* New 64 bits extensions (PowerPC 2.0x) */
501 PPC_64BX
= 0x0000000000000040ULL
,
502 /* 64 bits hypervisor extensions */
503 PPC_64H
= 0x0000000000000080ULL
,
504 /* New wait instruction (PowerPC 2.0x) */
505 PPC_WAIT
= 0x0000000000000100ULL
,
506 /* Time base mftb instruction */
507 PPC_MFTB
= 0x0000000000000200ULL
,
509 /* Fixed-point unit extensions */
510 /* PowerPC 602 specific */
511 PPC_602_SPEC
= 0x0000000000000400ULL
,
512 /* isel instruction */
513 PPC_ISEL
= 0x0000000000000800ULL
,
514 /* popcntb instruction */
515 PPC_POPCNTB
= 0x0000000000001000ULL
,
516 /* string load / store */
517 PPC_STRING
= 0x0000000000002000ULL
,
519 /* Floating-point unit extensions */
520 /* Optional floating point instructions */
521 PPC_FLOAT
= 0x0000000000010000ULL
,
522 /* New floating-point extensions (PowerPC 2.0x) */
523 PPC_FLOAT_EXT
= 0x0000000000020000ULL
,
524 PPC_FLOAT_FSQRT
= 0x0000000000040000ULL
,
525 PPC_FLOAT_FRES
= 0x0000000000080000ULL
,
526 PPC_FLOAT_FRSQRTE
= 0x0000000000100000ULL
,
527 PPC_FLOAT_FRSQRTES
= 0x0000000000200000ULL
,
528 PPC_FLOAT_FSEL
= 0x0000000000400000ULL
,
529 PPC_FLOAT_STFIWX
= 0x0000000000800000ULL
,
531 /* Vector/SIMD extensions */
532 /* Altivec support */
533 PPC_ALTIVEC
= 0x0000000001000000ULL
,
534 /* PowerPC 2.03 SPE extension */
535 PPC_SPE
= 0x0000000002000000ULL
,
536 /* PowerPC 2.03 SPE floating-point extension */
537 PPC_SPEFPU
= 0x0000000004000000ULL
,
539 /* Optional memory control instructions */
540 PPC_MEM_TLBIA
= 0x0000000010000000ULL
,
541 PPC_MEM_TLBIE
= 0x0000000020000000ULL
,
542 PPC_MEM_TLBSYNC
= 0x0000000040000000ULL
,
543 /* sync instruction */
544 PPC_MEM_SYNC
= 0x0000000080000000ULL
,
545 /* eieio instruction */
546 PPC_MEM_EIEIO
= 0x0000000100000000ULL
,
548 /* Cache control instructions */
549 PPC_CACHE
= 0x0000000200000000ULL
,
550 /* icbi instruction */
551 PPC_CACHE_ICBI
= 0x0000000400000000ULL
,
552 /* dcbz instruction with fixed cache line size */
553 PPC_CACHE_DCBZ
= 0x0000000800000000ULL
,
554 /* dcbz instruction with tunable cache line size */
555 PPC_CACHE_DCBZT
= 0x0000001000000000ULL
,
556 /* dcba instruction */
557 PPC_CACHE_DCBA
= 0x0000002000000000ULL
,
558 /* Freescale cache locking instructions */
559 PPC_CACHE_LOCK
= 0x0000004000000000ULL
,
561 /* MMU related extensions */
562 /* external control instructions */
563 PPC_EXTERN
= 0x0000010000000000ULL
,
564 /* segment register access instructions */
565 PPC_SEGMENT
= 0x0000020000000000ULL
,
566 /* PowerPC 6xx TLB management instructions */
567 PPC_6xx_TLB
= 0x0000040000000000ULL
,
568 /* PowerPC 74xx TLB management instructions */
569 PPC_74xx_TLB
= 0x0000080000000000ULL
,
570 /* PowerPC 40x TLB management instructions */
571 PPC_40x_TLB
= 0x0000100000000000ULL
,
572 /* segment register access instructions for PowerPC 64 "bridge" */
573 PPC_SEGMENT_64B
= 0x0000200000000000ULL
,
575 PPC_SLBI
= 0x0000400000000000ULL
,
577 /* Embedded PowerPC dedicated instructions */
578 PPC_WRTEE
= 0x0001000000000000ULL
,
579 /* PowerPC 40x exception model */
580 PPC_40x_EXCP
= 0x0002000000000000ULL
,
581 /* PowerPC 405 Mac instructions */
582 PPC_405_MAC
= 0x0004000000000000ULL
,
583 /* PowerPC 440 specific instructions */
584 PPC_440_SPEC
= 0x0008000000000000ULL
,
585 /* BookE (embedded) PowerPC specification */
586 PPC_BOOKE
= 0x0010000000000000ULL
,
587 /* mfapidi instruction */
588 PPC_MFAPIDI
= 0x0020000000000000ULL
,
589 /* tlbiva instruction */
590 PPC_TLBIVA
= 0x0040000000000000ULL
,
591 /* tlbivax instruction */
592 PPC_TLBIVAX
= 0x0080000000000000ULL
,
593 /* PowerPC 4xx dedicated instructions */
594 PPC_4xx_COMMON
= 0x0100000000000000ULL
,
595 /* PowerPC 40x ibct instructions */
596 PPC_40x_ICBT
= 0x0200000000000000ULL
,
597 /* rfmci is not implemented in all BookE PowerPC */
598 PPC_RFMCI
= 0x0400000000000000ULL
,
599 /* rfdi instruction */
600 PPC_RFDI
= 0x0800000000000000ULL
,
602 PPC_DCR
= 0x1000000000000000ULL
,
603 /* DCR extended accesse */
604 PPC_DCRX
= 0x2000000000000000ULL
,
605 /* user-mode DCR access, implemented in PowerPC 460 */
606 PPC_DCRUX
= 0x4000000000000000ULL
,
609 /*****************************************************************************/
610 /* PowerPC instructions table */
611 #if HOST_LONG_BITS == 64
616 #if defined(__APPLE__)
617 #define OPCODES_SECTION \
618 __attribute__ ((section("__TEXT,__opcodes"), unused, aligned (OPC_ALIGN) ))
620 #define OPCODES_SECTION \
621 __attribute__ ((section(".opcodes"), unused, aligned (OPC_ALIGN) ))
624 #if defined(DO_PPC_STATISTICS)
625 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
626 OPCODES_SECTION opcode_t opc_##name = { \
634 .handler = &gen_##name, \
635 .oname = stringify(name), \
637 .oname = stringify(name), \
639 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
640 OPCODES_SECTION opcode_t opc_##name = { \
648 .handler = &gen_##name, \
654 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
655 OPCODES_SECTION opcode_t opc_##name = { \
663 .handler = &gen_##name, \
665 .oname = stringify(name), \
667 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
668 OPCODES_SECTION opcode_t opc_##name = { \
676 .handler = &gen_##name, \
682 #define GEN_OPCODE_MARK(name) \
683 OPCODES_SECTION opcode_t opc_##name = { \
689 .inval = 0x00000000, \
693 .oname = stringify(name), \
696 /* Start opcode list */
697 GEN_OPCODE_MARK(start
);
699 /* Invalid instruction */
700 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
)
705 static opc_handler_t invalid_handler
= {
708 .handler
= gen_invalid
,
711 /*** Integer comparison ***/
713 static always_inline
void gen_op_cmp(TCGv arg0
, TCGv arg1
, int s
, int crf
)
717 tcg_gen_trunc_tl_i32(cpu_crf
[crf
], cpu_xer
);
718 tcg_gen_shri_i32(cpu_crf
[crf
], cpu_crf
[crf
], XER_SO
);
719 tcg_gen_andi_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1);
721 l1
= gen_new_label();
722 l2
= gen_new_label();
723 l3
= gen_new_label();
725 tcg_gen_brcond_tl(TCG_COND_LT
, arg0
, arg1
, l1
);
726 tcg_gen_brcond_tl(TCG_COND_GT
, arg0
, arg1
, l2
);
728 tcg_gen_brcond_tl(TCG_COND_LTU
, arg0
, arg1
, l1
);
729 tcg_gen_brcond_tl(TCG_COND_GTU
, arg0
, arg1
, l2
);
731 tcg_gen_ori_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1 << CRF_EQ
);
734 tcg_gen_ori_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1 << CRF_LT
);
737 tcg_gen_ori_i32(cpu_crf
[crf
], cpu_crf
[crf
], 1 << CRF_GT
);
741 static always_inline
void gen_op_cmpi(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
743 TCGv t0
= tcg_const_local_tl(arg1
);
744 gen_op_cmp(arg0
, t0
, s
, crf
);
748 #if defined(TARGET_PPC64)
749 static always_inline
void gen_op_cmp32(TCGv arg0
, TCGv arg1
, int s
, int crf
)
752 t0
= tcg_temp_local_new();
753 t1
= tcg_temp_local_new();
755 tcg_gen_ext32s_tl(t0
, arg0
);
756 tcg_gen_ext32s_tl(t1
, arg1
);
758 tcg_gen_ext32u_tl(t0
, arg0
);
759 tcg_gen_ext32u_tl(t1
, arg1
);
761 gen_op_cmp(t0
, t1
, s
, crf
);
766 static always_inline
void gen_op_cmpi32(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
768 TCGv t0
= tcg_const_local_tl(arg1
);
769 gen_op_cmp32(arg0
, t0
, s
, crf
);
774 static always_inline
void gen_set_Rc0 (DisasContext
*ctx
, TCGv reg
)
776 #if defined(TARGET_PPC64)
778 gen_op_cmpi32(reg
, 0, 1, 0);
781 gen_op_cmpi(reg
, 0, 1, 0);
785 GEN_HANDLER(cmp
, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER
)
787 #if defined(TARGET_PPC64)
788 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
789 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
790 1, crfD(ctx
->opcode
));
793 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
794 1, crfD(ctx
->opcode
));
798 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
)
800 #if defined(TARGET_PPC64)
801 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
802 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
803 1, crfD(ctx
->opcode
));
806 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
807 1, crfD(ctx
->opcode
));
811 GEN_HANDLER(cmpl
, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER
)
813 #if defined(TARGET_PPC64)
814 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
815 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
816 0, crfD(ctx
->opcode
));
819 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
820 0, crfD(ctx
->opcode
));
824 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
)
826 #if defined(TARGET_PPC64)
827 if (!(ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000)))
828 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
829 0, crfD(ctx
->opcode
));
832 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
833 0, crfD(ctx
->opcode
));
836 /* isel (PowerPC 2.03 specification) */
837 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
)
840 uint32_t bi
= rC(ctx
->opcode
);
844 l1
= gen_new_label();
845 l2
= gen_new_label();
847 mask
= 1 << (3 - (bi
& 0x03));
848 t0
= tcg_temp_new_i32();
849 tcg_gen_andi_i32(t0
, cpu_crf
[bi
>> 2], mask
);
850 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
851 if (rA(ctx
->opcode
) == 0)
852 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
854 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
857 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
859 tcg_temp_free_i32(t0
);
862 /*** Integer arithmetic ***/
864 static always_inline
void gen_op_arith_compute_ov(DisasContext
*ctx
, TCGv arg0
, TCGv arg1
, TCGv arg2
, int sub
)
869 l1
= gen_new_label();
870 /* Start with XER OV disabled, the most likely case */
871 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
872 t0
= tcg_temp_local_new();
873 tcg_gen_xor_tl(t0
, arg0
, arg1
);
874 #if defined(TARGET_PPC64)
876 tcg_gen_ext32s_tl(t0
, t0
);
879 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0, l1
);
881 tcg_gen_brcondi_tl(TCG_COND_GE
, t0
, 0, l1
);
882 tcg_gen_xor_tl(t0
, arg1
, arg2
);
883 #if defined(TARGET_PPC64)
885 tcg_gen_ext32s_tl(t0
, t0
);
888 tcg_gen_brcondi_tl(TCG_COND_GE
, t0
, 0, l1
);
890 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0, l1
);
891 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
896 static always_inline
void gen_op_arith_compute_ca(DisasContext
*ctx
, TCGv arg1
, TCGv arg2
, int sub
)
898 int l1
= gen_new_label();
900 #if defined(TARGET_PPC64)
901 if (!(ctx
->sf_mode
)) {
906 tcg_gen_ext32u_tl(t0
, arg1
);
907 tcg_gen_ext32u_tl(t1
, arg2
);
909 tcg_gen_brcond_tl(TCG_COND_GTU
, t0
, t1
, l1
);
911 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
913 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
921 tcg_gen_brcond_tl(TCG_COND_GTU
, arg1
, arg2
, l1
);
923 tcg_gen_brcond_tl(TCG_COND_GEU
, arg1
, arg2
, l1
);
925 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
930 /* Common add function */
931 static always_inline
void gen_op_arith_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
, TCGv arg2
,
932 int add_ca
, int compute_ca
, int compute_ov
)
936 if ((!compute_ca
&& !compute_ov
) ||
937 (!TCGV_EQUAL(ret
,arg1
) && !TCGV_EQUAL(ret
, arg2
))) {
940 t0
= tcg_temp_local_new();
944 t1
= tcg_temp_local_new();
945 tcg_gen_andi_tl(t1
, cpu_xer
, (1 << XER_CA
));
946 tcg_gen_shri_tl(t1
, t1
, XER_CA
);
949 if (compute_ca
&& compute_ov
) {
950 /* Start with XER CA and OV disabled, the most likely case */
951 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~((1 << XER_CA
) | (1 << XER_OV
)));
952 } else if (compute_ca
) {
953 /* Start with XER CA disabled, the most likely case */
954 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
955 } else if (compute_ov
) {
956 /* Start with XER OV disabled, the most likely case */
957 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
960 tcg_gen_add_tl(t0
, arg1
, arg2
);
963 gen_op_arith_compute_ca(ctx
, t0
, arg1
, 0);
966 tcg_gen_add_tl(t0
, t0
, t1
);
967 gen_op_arith_compute_ca(ctx
, t0
, t1
, 0);
971 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 0);
974 if (unlikely(Rc(ctx
->opcode
) != 0))
975 gen_set_Rc0(ctx
, t0
);
977 if (!TCGV_EQUAL(t0
, ret
)) {
978 tcg_gen_mov_tl(ret
, t0
);
982 /* Add functions with two operands */
983 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
984 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER) \
986 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
987 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
988 add_ca, compute_ca, compute_ov); \
990 /* Add functions with one operand and one immediate */
991 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
992 add_ca, compute_ca, compute_ov) \
993 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER) \
995 TCGv t0 = tcg_const_local_tl(const_val); \
996 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
997 cpu_gpr[rA(ctx->opcode)], t0, \
998 add_ca, compute_ca, compute_ov); \
1002 /* add add. addo addo. */
1003 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
1004 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
1005 /* addc addc. addco addco. */
1006 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
1007 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
1008 /* adde adde. addeo addeo. */
1009 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
1010 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
1011 /* addme addme. addmeo addmeo. */
1012 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
1013 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
1014 /* addze addze. addzeo addzeo.*/
1015 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
1016 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
1018 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1020 target_long simm
= SIMM(ctx
->opcode
);
1022 if (rA(ctx
->opcode
) == 0) {
1024 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
);
1026 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], simm
);
1030 static always_inline
void gen_op_addic (DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1033 target_long simm
= SIMM(ctx
->opcode
);
1035 /* Start with XER CA and OV disabled, the most likely case */
1036 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1038 if (likely(simm
!= 0)) {
1039 TCGv t0
= tcg_temp_local_new();
1040 tcg_gen_addi_tl(t0
, arg1
, simm
);
1041 gen_op_arith_compute_ca(ctx
, t0
, arg1
, 0);
1042 tcg_gen_mov_tl(ret
, t0
);
1045 tcg_gen_mov_tl(ret
, arg1
);
1048 gen_set_Rc0(ctx
, ret
);
1051 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1053 gen_op_addic(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0);
1055 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1057 gen_op_addic(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 1);
1060 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1062 target_long simm
= SIMM(ctx
->opcode
);
1064 if (rA(ctx
->opcode
) == 0) {
1066 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
<< 16);
1068 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], simm
<< 16);
1072 static always_inline
void gen_op_arith_divw (DisasContext
*ctx
, TCGv ret
, TCGv arg1
, TCGv arg2
,
1073 int sign
, int compute_ov
)
1075 int l1
= gen_new_label();
1076 int l2
= gen_new_label();
1077 TCGv_i32 t0
= tcg_temp_local_new_i32();
1078 TCGv_i32 t1
= tcg_temp_local_new_i32();
1080 tcg_gen_trunc_tl_i32(t0
, arg1
);
1081 tcg_gen_trunc_tl_i32(t1
, arg2
);
1082 tcg_gen_brcondi_i32(TCG_COND_EQ
, t1
, 0, l1
);
1084 int l3
= gen_new_label();
1085 tcg_gen_brcondi_i32(TCG_COND_NE
, t1
, -1, l3
);
1086 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, INT32_MIN
, l1
);
1088 tcg_gen_div_i32(t0
, t0
, t1
);
1090 tcg_gen_divu_i32(t0
, t0
, t1
);
1093 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1098 tcg_gen_sari_i32(t0
, t0
, 31);
1100 tcg_gen_movi_i32(t0
, 0);
1103 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1106 tcg_gen_extu_i32_tl(ret
, t0
);
1107 tcg_temp_free_i32(t0
);
1108 tcg_temp_free_i32(t1
);
1109 if (unlikely(Rc(ctx
->opcode
) != 0))
1110 gen_set_Rc0(ctx
, ret
);
1113 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
1114 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER) \
1116 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
1117 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1118 sign, compute_ov); \
1120 /* divwu divwu. divwuo divwuo. */
1121 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0);
1122 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1);
1123 /* divw divw. divwo divwo. */
1124 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0);
1125 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1);
1126 #if defined(TARGET_PPC64)
1127 static always_inline
void gen_op_arith_divd (DisasContext
*ctx
, TCGv ret
, TCGv arg1
, TCGv arg2
,
1128 int sign
, int compute_ov
)
1130 int l1
= gen_new_label();
1131 int l2
= gen_new_label();
1133 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg2
, 0, l1
);
1135 int l3
= gen_new_label();
1136 tcg_gen_brcondi_i64(TCG_COND_NE
, arg2
, -1, l3
);
1137 tcg_gen_brcondi_i64(TCG_COND_EQ
, arg1
, INT64_MIN
, l1
);
1139 tcg_gen_div_i64(ret
, arg1
, arg2
);
1141 tcg_gen_divu_i64(ret
, arg1
, arg2
);
1144 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1149 tcg_gen_sari_i64(ret
, arg1
, 63);
1151 tcg_gen_movi_i64(ret
, 0);
1154 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1157 if (unlikely(Rc(ctx
->opcode
) != 0))
1158 gen_set_Rc0(ctx
, ret
);
1160 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1161 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) \
1163 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1164 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1165 sign, compute_ov); \
1167 /* divwu divwu. divwuo divwuo. */
1168 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0);
1169 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1);
1170 /* divw divw. divwo divwo. */
1171 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0);
1172 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1);
1176 GEN_HANDLER(mulhw
, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER
)
1180 t0
= tcg_temp_new_i64();
1181 t1
= tcg_temp_new_i64();
1182 #if defined(TARGET_PPC64)
1183 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1184 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1185 tcg_gen_mul_i64(t0
, t0
, t1
);
1186 tcg_gen_shri_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
1188 tcg_gen_ext_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1189 tcg_gen_ext_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1190 tcg_gen_mul_i64(t0
, t0
, t1
);
1191 tcg_gen_shri_i64(t0
, t0
, 32);
1192 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1194 tcg_temp_free_i64(t0
);
1195 tcg_temp_free_i64(t1
);
1196 if (unlikely(Rc(ctx
->opcode
) != 0))
1197 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1199 /* mulhwu mulhwu. */
1200 GEN_HANDLER(mulhwu
, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER
)
1204 t0
= tcg_temp_new_i64();
1205 t1
= tcg_temp_new_i64();
1206 #if defined(TARGET_PPC64)
1207 tcg_gen_ext32u_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1208 tcg_gen_ext32u_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1209 tcg_gen_mul_i64(t0
, t0
, t1
);
1210 tcg_gen_shri_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, 32);
1212 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1213 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1214 tcg_gen_mul_i64(t0
, t0
, t1
);
1215 tcg_gen_shri_i64(t0
, t0
, 32);
1216 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1218 tcg_temp_free_i64(t0
);
1219 tcg_temp_free_i64(t1
);
1220 if (unlikely(Rc(ctx
->opcode
) != 0))
1221 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1224 GEN_HANDLER(mullw
, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER
)
1226 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1227 cpu_gpr
[rB(ctx
->opcode
)]);
1228 tcg_gen_ext32s_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rD(ctx
->opcode
)]);
1229 if (unlikely(Rc(ctx
->opcode
) != 0))
1230 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1232 /* mullwo mullwo. */
1233 GEN_HANDLER(mullwo
, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER
)
1238 t0
= tcg_temp_new_i64();
1239 t1
= tcg_temp_new_i64();
1240 l1
= gen_new_label();
1241 /* Start with XER OV disabled, the most likely case */
1242 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1243 #if defined(TARGET_PPC64)
1244 tcg_gen_ext32s_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1245 tcg_gen_ext32s_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1247 tcg_gen_ext_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1248 tcg_gen_ext_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1250 tcg_gen_mul_i64(t0
, t0
, t1
);
1251 #if defined(TARGET_PPC64)
1252 tcg_gen_ext32s_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1253 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, cpu_gpr
[rD(ctx
->opcode
)], l1
);
1255 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1256 tcg_gen_ext32s_i64(t1
, t0
);
1257 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
1259 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1261 tcg_temp_free_i64(t0
);
1262 tcg_temp_free_i64(t1
);
1263 if (unlikely(Rc(ctx
->opcode
) != 0))
1264 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1267 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1269 tcg_gen_muli_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1272 #if defined(TARGET_PPC64)
1273 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
1274 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) \
1276 gen_helper_##name (cpu_gpr[rD(ctx->opcode)], \
1277 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \
1278 if (unlikely(Rc(ctx->opcode) != 0)) \
1279 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1282 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00);
1283 /* mulhdu mulhdu. */
1284 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02);
1286 GEN_HANDLER(mulld
, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B
)
1288 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1289 cpu_gpr
[rB(ctx
->opcode
)]);
1290 if (unlikely(Rc(ctx
->opcode
) != 0))
1291 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1293 /* mulldo mulldo. */
1294 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17);
1297 /* neg neg. nego nego. */
1298 static always_inline
void gen_op_arith_neg (DisasContext
*ctx
, TCGv ret
, TCGv arg1
, int ov_check
)
1300 int l1
= gen_new_label();
1301 int l2
= gen_new_label();
1302 TCGv t0
= tcg_temp_local_new();
1303 #if defined(TARGET_PPC64)
1305 tcg_gen_mov_tl(t0
, arg1
);
1306 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, INT64_MIN
, l1
);
1310 tcg_gen_ext32s_tl(t0
, arg1
);
1311 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, INT32_MIN
, l1
);
1313 tcg_gen_neg_tl(ret
, arg1
);
1315 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1319 tcg_gen_mov_tl(ret
, t0
);
1321 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
1325 if (unlikely(Rc(ctx
->opcode
) != 0))
1326 gen_set_Rc0(ctx
, ret
);
1328 GEN_HANDLER(neg
, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER
)
1330 gen_op_arith_neg(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 0);
1332 GEN_HANDLER(nego
, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER
)
1334 gen_op_arith_neg(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 1);
1337 /* Common subf function */
1338 static always_inline
void gen_op_arith_subf(DisasContext
*ctx
, TCGv ret
, TCGv arg1
, TCGv arg2
,
1339 int add_ca
, int compute_ca
, int compute_ov
)
1343 if ((!compute_ca
&& !compute_ov
) ||
1344 (!TCGV_EQUAL(ret
, arg1
) && !TCGV_EQUAL(ret
, arg2
))) {
1347 t0
= tcg_temp_local_new();
1351 t1
= tcg_temp_local_new();
1352 tcg_gen_andi_tl(t1
, cpu_xer
, (1 << XER_CA
));
1353 tcg_gen_shri_tl(t1
, t1
, XER_CA
);
1356 if (compute_ca
&& compute_ov
) {
1357 /* Start with XER CA and OV disabled, the most likely case */
1358 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~((1 << XER_CA
) | (1 << XER_OV
)));
1359 } else if (compute_ca
) {
1360 /* Start with XER CA disabled, the most likely case */
1361 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1362 } else if (compute_ov
) {
1363 /* Start with XER OV disabled, the most likely case */
1364 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
1368 tcg_gen_not_tl(t0
, arg1
);
1369 tcg_gen_add_tl(t0
, t0
, arg2
);
1370 gen_op_arith_compute_ca(ctx
, t0
, arg2
, 0);
1371 tcg_gen_add_tl(t0
, t0
, t1
);
1372 gen_op_arith_compute_ca(ctx
, t0
, t1
, 0);
1375 tcg_gen_sub_tl(t0
, arg2
, arg1
);
1377 gen_op_arith_compute_ca(ctx
, t0
, arg2
, 1);
1381 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 1);
1384 if (unlikely(Rc(ctx
->opcode
) != 0))
1385 gen_set_Rc0(ctx
, t0
);
1387 if (!TCGV_EQUAL(t0
, ret
)) {
1388 tcg_gen_mov_tl(ret
, t0
);
1392 /* Sub functions with Two operands functions */
1393 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
1394 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER) \
1396 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1397 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1398 add_ca, compute_ca, compute_ov); \
1400 /* Sub functions with one operand and one immediate */
1401 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
1402 add_ca, compute_ca, compute_ov) \
1403 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER) \
1405 TCGv t0 = tcg_const_local_tl(const_val); \
1406 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
1407 cpu_gpr[rA(ctx->opcode)], t0, \
1408 add_ca, compute_ca, compute_ov); \
1409 tcg_temp_free(t0); \
1411 /* subf subf. subfo subfo. */
1412 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
1413 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
1414 /* subfc subfc. subfco subfco. */
1415 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
1416 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
1417 /* subfe subfe. subfeo subfo. */
1418 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
1419 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
1420 /* subfme subfme. subfmeo subfmeo. */
1421 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
1422 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
1423 /* subfze subfze. subfzeo subfzeo.*/
1424 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
1425 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
1427 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1429 /* Start with XER CA and OV disabled, the most likely case */
1430 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1431 TCGv t0
= tcg_temp_local_new();
1432 TCGv t1
= tcg_const_local_tl(SIMM(ctx
->opcode
));
1433 tcg_gen_sub_tl(t0
, t1
, cpu_gpr
[rA(ctx
->opcode
)]);
1434 gen_op_arith_compute_ca(ctx
, t0
, t1
, 1);
1436 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1440 /*** Integer logical ***/
1441 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
1442 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type) \
1444 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
1445 cpu_gpr[rB(ctx->opcode)]); \
1446 if (unlikely(Rc(ctx->opcode) != 0)) \
1447 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1450 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
1451 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type) \
1453 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
1454 if (unlikely(Rc(ctx->opcode) != 0)) \
1455 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
1459 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
);
1461 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
);
1463 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1465 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
));
1466 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1469 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1471 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], UIMM(ctx
->opcode
) << 16);
1472 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1475 GEN_HANDLER(cntlzw
, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER
)
1477 gen_helper_cntlzw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1478 if (unlikely(Rc(ctx
->opcode
) != 0))
1479 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1482 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
);
1483 /* extsb & extsb. */
1484 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
);
1485 /* extsh & extsh. */
1486 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
);
1488 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
);
1490 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
);
1492 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
)
1496 rs
= rS(ctx
->opcode
);
1497 ra
= rA(ctx
->opcode
);
1498 rb
= rB(ctx
->opcode
);
1499 /* Optimisation for mr. ri case */
1500 if (rs
!= ra
|| rs
!= rb
) {
1502 tcg_gen_or_tl(cpu_gpr
[ra
], cpu_gpr
[rs
], cpu_gpr
[rb
]);
1504 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rs
]);
1505 if (unlikely(Rc(ctx
->opcode
) != 0))
1506 gen_set_Rc0(ctx
, cpu_gpr
[ra
]);
1507 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
1508 gen_set_Rc0(ctx
, cpu_gpr
[rs
]);
1509 #if defined(TARGET_PPC64)
1515 /* Set process priority to low */
1519 /* Set process priority to medium-low */
1523 /* Set process priority to normal */
1526 #if !defined(CONFIG_USER_ONLY)
1528 if (ctx
->supervisor
> 0) {
1529 /* Set process priority to very low */
1534 if (ctx
->supervisor
> 0) {
1535 /* Set process priority to medium-hight */
1540 if (ctx
->supervisor
> 0) {
1541 /* Set process priority to high */
1546 if (ctx
->supervisor
> 1) {
1547 /* Set process priority to very high */
1557 TCGv t0
= tcg_temp_new();
1558 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUState
, spr
[SPR_PPR
]));
1559 tcg_gen_andi_tl(t0
, t0
, ~0x001C000000000000ULL
);
1560 tcg_gen_ori_tl(t0
, t0
, ((uint64_t)prio
) << 50);
1561 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUState
, spr
[SPR_PPR
]));
1568 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
);
1570 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
)
1572 /* Optimisation for "set to zero" case */
1573 if (rS(ctx
->opcode
) != rB(ctx
->opcode
))
1574 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1576 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1577 if (unlikely(Rc(ctx
->opcode
) != 0))
1578 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1581 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1583 target_ulong uimm
= UIMM(ctx
->opcode
);
1585 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1587 /* XXX: should handle special NOPs for POWER series */
1590 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1593 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1595 target_ulong uimm
= UIMM(ctx
->opcode
);
1597 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1601 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1604 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1606 target_ulong uimm
= UIMM(ctx
->opcode
);
1608 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1612 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
1615 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1617 target_ulong uimm
= UIMM(ctx
->opcode
);
1619 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1623 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
<< 16);
1625 /* popcntb : PowerPC 2.03 specification */
1626 GEN_HANDLER(popcntb
, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB
)
1628 #if defined(TARGET_PPC64)
1630 gen_helper_popcntb_64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1633 gen_helper_popcntb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1636 #if defined(TARGET_PPC64)
1637 /* extsw & extsw. */
1638 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
);
1640 GEN_HANDLER(cntlzd
, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B
)
1642 gen_helper_cntlzd(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1643 if (unlikely(Rc(ctx
->opcode
) != 0))
1644 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1648 /*** Integer rotate ***/
1649 /* rlwimi & rlwimi. */
1650 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1652 uint32_t mb
, me
, sh
;
1654 mb
= MB(ctx
->opcode
);
1655 me
= ME(ctx
->opcode
);
1656 sh
= SH(ctx
->opcode
);
1657 if (likely(sh
== 0 && mb
== 0 && me
== 31)) {
1658 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1662 TCGv t0
= tcg_temp_new();
1663 #if defined(TARGET_PPC64)
1664 TCGv_i32 t2
= tcg_temp_new_i32();
1665 tcg_gen_trunc_i64_i32(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
1666 tcg_gen_rotli_i32(t2
, t2
, sh
);
1667 tcg_gen_extu_i32_i64(t0
, t2
);
1668 tcg_temp_free_i32(t2
);
1670 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1672 #if defined(TARGET_PPC64)
1676 mask
= MASK(mb
, me
);
1677 t1
= tcg_temp_new();
1678 tcg_gen_andi_tl(t0
, t0
, mask
);
1679 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1680 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1684 if (unlikely(Rc(ctx
->opcode
) != 0))
1685 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1687 /* rlwinm & rlwinm. */
1688 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1690 uint32_t mb
, me
, sh
;
1692 sh
= SH(ctx
->opcode
);
1693 mb
= MB(ctx
->opcode
);
1694 me
= ME(ctx
->opcode
);
1696 if (likely(mb
== 0 && me
== (31 - sh
))) {
1697 if (likely(sh
== 0)) {
1698 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1700 TCGv t0
= tcg_temp_new();
1701 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1702 tcg_gen_shli_tl(t0
, t0
, sh
);
1703 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1706 } else if (likely(sh
!= 0 && me
== 31 && sh
== (32 - mb
))) {
1707 TCGv t0
= tcg_temp_new();
1708 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1709 tcg_gen_shri_tl(t0
, t0
, mb
);
1710 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1713 TCGv t0
= tcg_temp_new();
1714 #if defined(TARGET_PPC64)
1715 TCGv_i32 t1
= tcg_temp_new_i32();
1716 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1717 tcg_gen_rotli_i32(t1
, t1
, sh
);
1718 tcg_gen_extu_i32_i64(t0
, t1
);
1719 tcg_temp_free_i32(t1
);
1721 tcg_gen_rotli_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1723 #if defined(TARGET_PPC64)
1727 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1730 if (unlikely(Rc(ctx
->opcode
) != 0))
1731 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1733 /* rlwnm & rlwnm. */
1734 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1738 #if defined(TARGET_PPC64)
1742 mb
= MB(ctx
->opcode
);
1743 me
= ME(ctx
->opcode
);
1744 t0
= tcg_temp_new();
1745 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
1746 #if defined(TARGET_PPC64)
1747 t1
= tcg_temp_new_i32();
1748 t2
= tcg_temp_new_i32();
1749 tcg_gen_trunc_i64_i32(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1750 tcg_gen_trunc_i64_i32(t2
, t0
);
1751 tcg_gen_rotl_i32(t1
, t1
, t2
);
1752 tcg_gen_extu_i32_i64(t0
, t1
);
1753 tcg_temp_free_i32(t1
);
1754 tcg_temp_free_i32(t2
);
1756 tcg_gen_rotl_i32(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1758 if (unlikely(mb
!= 0 || me
!= 31)) {
1759 #if defined(TARGET_PPC64)
1763 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1765 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1768 if (unlikely(Rc(ctx
->opcode
) != 0))
1769 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1772 #if defined(TARGET_PPC64)
1773 #define GEN_PPC64_R2(name, opc1, opc2) \
1774 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1776 gen_##name(ctx, 0); \
1778 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1781 gen_##name(ctx, 1); \
1783 #define GEN_PPC64_R4(name, opc1, opc2) \
1784 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1786 gen_##name(ctx, 0, 0); \
1788 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
1791 gen_##name(ctx, 0, 1); \
1793 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1796 gen_##name(ctx, 1, 0); \
1798 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
1801 gen_##name(ctx, 1, 1); \
1804 static always_inline
void gen_rldinm (DisasContext
*ctx
, uint32_t mb
,
1805 uint32_t me
, uint32_t sh
)
1807 if (likely(sh
!= 0 && mb
== 0 && me
== (63 - sh
))) {
1808 tcg_gen_shli_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
1809 } else if (likely(sh
!= 0 && me
== 63 && sh
== (64 - mb
))) {
1810 tcg_gen_shri_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], mb
);
1812 TCGv t0
= tcg_temp_new();
1813 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1814 if (likely(mb
== 0 && me
== 63)) {
1815 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1817 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1821 if (unlikely(Rc(ctx
->opcode
) != 0))
1822 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1824 /* rldicl - rldicl. */
1825 static always_inline
void gen_rldicl (DisasContext
*ctx
, int mbn
, int shn
)
1829 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1830 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1831 gen_rldinm(ctx
, mb
, 63, sh
);
1833 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
1834 /* rldicr - rldicr. */
1835 static always_inline
void gen_rldicr (DisasContext
*ctx
, int men
, int shn
)
1839 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1840 me
= MB(ctx
->opcode
) | (men
<< 5);
1841 gen_rldinm(ctx
, 0, me
, sh
);
1843 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
1844 /* rldic - rldic. */
1845 static always_inline
void gen_rldic (DisasContext
*ctx
, int mbn
, int shn
)
1849 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1850 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1851 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
1853 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
1855 static always_inline
void gen_rldnm (DisasContext
*ctx
, uint32_t mb
,
1860 mb
= MB(ctx
->opcode
);
1861 me
= ME(ctx
->opcode
);
1862 t0
= tcg_temp_new();
1863 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1864 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
1865 if (unlikely(mb
!= 0 || me
!= 63)) {
1866 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, MASK(mb
, me
));
1868 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
1871 if (unlikely(Rc(ctx
->opcode
) != 0))
1872 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1875 /* rldcl - rldcl. */
1876 static always_inline
void gen_rldcl (DisasContext
*ctx
, int mbn
)
1880 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1881 gen_rldnm(ctx
, mb
, 63);
1883 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
1884 /* rldcr - rldcr. */
1885 static always_inline
void gen_rldcr (DisasContext
*ctx
, int men
)
1889 me
= MB(ctx
->opcode
) | (men
<< 5);
1890 gen_rldnm(ctx
, 0, me
);
1892 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
1893 /* rldimi - rldimi. */
1894 static always_inline
void gen_rldimi (DisasContext
*ctx
, int mbn
, int shn
)
1896 uint32_t sh
, mb
, me
;
1898 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1899 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1901 if (unlikely(sh
== 0 && mb
== 0)) {
1902 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1907 t0
= tcg_temp_new();
1908 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
1909 t1
= tcg_temp_new();
1910 mask
= MASK(mb
, me
);
1911 tcg_gen_andi_tl(t0
, t0
, mask
);
1912 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], ~mask
);
1913 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
1917 if (unlikely(Rc(ctx
->opcode
) != 0))
1918 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1920 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
1923 /*** Integer shift ***/
1925 GEN_HANDLER(slw
, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER
)
1929 l1
= gen_new_label();
1930 l2
= gen_new_label();
1932 t0
= tcg_temp_local_new();
1933 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1934 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0x20, l1
);
1935 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1938 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t0
);
1939 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
1942 if (unlikely(Rc(ctx
->opcode
) != 0))
1943 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1946 GEN_HANDLER(sraw
, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER
)
1948 gen_helper_sraw(cpu_gpr
[rA(ctx
->opcode
)],
1949 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1950 if (unlikely(Rc(ctx
->opcode
) != 0))
1951 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1953 /* srawi & srawi. */
1954 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
)
1956 int sh
= SH(ctx
->opcode
);
1960 l1
= gen_new_label();
1961 l2
= gen_new_label();
1962 t0
= tcg_temp_local_new();
1963 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1964 tcg_gen_brcondi_tl(TCG_COND_GE
, t0
, 0, l1
);
1965 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1ULL << sh
) - 1);
1966 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
1967 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
1970 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1972 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)]);
1973 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, sh
);
1976 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
1977 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
1979 if (unlikely(Rc(ctx
->opcode
) != 0))
1980 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
1983 GEN_HANDLER(srw
, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER
)
1987 l1
= gen_new_label();
1988 l2
= gen_new_label();
1990 t0
= tcg_temp_local_new();
1991 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
1992 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0x20, l1
);
1993 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
1996 t1
= tcg_temp_new();
1997 tcg_gen_ext32u_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)]);
1998 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
, t0
);
2002 if (unlikely(Rc(ctx
->opcode
) != 0))
2003 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2005 #if defined(TARGET_PPC64)
2007 GEN_HANDLER(sld
, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B
)
2011 l1
= gen_new_label();
2012 l2
= gen_new_label();
2014 t0
= tcg_temp_local_new();
2015 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x7f);
2016 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0x40, l1
);
2017 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
2020 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t0
);
2023 if (unlikely(Rc(ctx
->opcode
) != 0))
2024 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2027 GEN_HANDLER(srad
, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B
)
2029 gen_helper_srad(cpu_gpr
[rA(ctx
->opcode
)],
2030 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2031 if (unlikely(Rc(ctx
->opcode
) != 0))
2032 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2034 /* sradi & sradi. */
2035 static always_inline
void gen_sradi (DisasContext
*ctx
, int n
)
2037 int sh
= SH(ctx
->opcode
) + (n
<< 5);
2041 l1
= gen_new_label();
2042 l2
= gen_new_label();
2043 t0
= tcg_temp_local_new();
2044 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
2045 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], (1ULL << sh
) - 1);
2046 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
2047 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, 1 << XER_CA
);
2050 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
2053 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
2055 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
2056 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_CA
));
2058 if (unlikely(Rc(ctx
->opcode
) != 0))
2059 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2061 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
)
2065 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
)
2070 GEN_HANDLER(srd
, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B
)
2074 l1
= gen_new_label();
2075 l2
= gen_new_label();
2077 t0
= tcg_temp_local_new();
2078 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x7f);
2079 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, 0x40, l1
);
2080 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
2083 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t0
);
2086 if (unlikely(Rc(ctx
->opcode
) != 0))
2087 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2091 /*** Floating-Point arithmetic ***/
2092 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
2093 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type) \
2095 if (unlikely(!ctx->fpu_enabled)) { \
2096 GEN_EXCP_NO_FP(ctx); \
2099 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]); \
2100 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rC(ctx->opcode)]); \
2101 tcg_gen_mov_i64(cpu_FT[2], cpu_fpr[rB(ctx->opcode)]); \
2102 gen_reset_fpstatus(); \
2107 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2108 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
2111 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
2112 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
2113 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
2115 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2116 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
2118 if (unlikely(!ctx->fpu_enabled)) { \
2119 GEN_EXCP_NO_FP(ctx); \
2122 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]); \
2123 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rB(ctx->opcode)]); \
2124 gen_reset_fpstatus(); \
2129 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2130 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
2132 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
2133 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2134 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2136 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
2137 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
2139 if (unlikely(!ctx->fpu_enabled)) { \
2140 GEN_EXCP_NO_FP(ctx); \
2143 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]); \
2144 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rC(ctx->opcode)]); \
2145 gen_reset_fpstatus(); \
2150 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2151 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
2153 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
2154 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
2155 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
2157 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
2158 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type) \
2160 if (unlikely(!ctx->fpu_enabled)) { \
2161 GEN_EXCP_NO_FP(ctx); \
2164 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]); \
2165 gen_reset_fpstatus(); \
2167 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2168 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
2171 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
2172 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type) \
2174 if (unlikely(!ctx->fpu_enabled)) { \
2175 GEN_EXCP_NO_FP(ctx); \
2178 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]); \
2179 gen_reset_fpstatus(); \
2181 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2182 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
2186 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
);
2188 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
);
2190 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
);
2193 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
);
2196 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
);
2199 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
);
2202 static always_inline
void gen_op_frsqrtes (void)
2207 GEN_FLOAT_BS(rsqrtes
, 0x3B, 0x1A, 1, PPC_FLOAT_FRSQRTES
);
2210 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
);
2212 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
);
2215 GEN_HANDLER(fsqrt
, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
)
2217 if (unlikely(!ctx
->fpu_enabled
)) {
2218 GEN_EXCP_NO_FP(ctx
);
2221 tcg_gen_mov_i64(cpu_FT
[0], cpu_fpr
[rB(ctx
->opcode
)]);
2222 gen_reset_fpstatus();
2224 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_FT
[0]);
2225 gen_compute_fprf(1, Rc(ctx
->opcode
) != 0);
2228 GEN_HANDLER(fsqrts
, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
)
2230 if (unlikely(!ctx
->fpu_enabled
)) {
2231 GEN_EXCP_NO_FP(ctx
);
2234 tcg_gen_mov_i64(cpu_FT
[0], cpu_fpr
[rB(ctx
->opcode
)]);
2235 gen_reset_fpstatus();
2238 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_FT
[0]);
2239 gen_compute_fprf(1, Rc(ctx
->opcode
) != 0);
2242 /*** Floating-Point multiply-and-add ***/
2243 /* fmadd - fmadds */
2244 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
);
2245 /* fmsub - fmsubs */
2246 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
);
2247 /* fnmadd - fnmadds */
2248 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
);
2249 /* fnmsub - fnmsubs */
2250 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
);
2252 /*** Floating-Point round & convert ***/
2254 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
);
2256 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
);
2258 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
);
2259 #if defined(TARGET_PPC64)
2261 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
);
2263 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
);
2265 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
);
2269 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
);
2271 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
);
2273 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
);
2275 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
);
2277 /*** Floating-Point compare ***/
2279 GEN_HANDLER(fcmpo
, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT
)
2281 if (unlikely(!ctx
->fpu_enabled
)) {
2282 GEN_EXCP_NO_FP(ctx
);
2285 tcg_gen_mov_i64(cpu_FT
[0], cpu_fpr
[rA(ctx
->opcode
)]);
2286 tcg_gen_mov_i64(cpu_FT
[1], cpu_fpr
[rB(ctx
->opcode
)]);
2287 gen_reset_fpstatus();
2288 gen_helper_fcmpo(cpu_crf
[crfD(ctx
->opcode
)]);
2289 gen_op_float_check_status();
2293 GEN_HANDLER(fcmpu
, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT
)
2295 if (unlikely(!ctx
->fpu_enabled
)) {
2296 GEN_EXCP_NO_FP(ctx
);
2299 tcg_gen_mov_i64(cpu_FT
[0], cpu_fpr
[rA(ctx
->opcode
)]);
2300 tcg_gen_mov_i64(cpu_FT
[1], cpu_fpr
[rB(ctx
->opcode
)]);
2301 gen_reset_fpstatus();
2302 gen_helper_fcmpu(cpu_crf
[crfD(ctx
->opcode
)]);
2303 gen_op_float_check_status();
2306 /*** Floating-point move ***/
2308 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2309 GEN_FLOAT_B(abs
, 0x08, 0x08, 0, PPC_FLOAT
);
2312 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2313 GEN_HANDLER(fmr
, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT
)
2315 if (unlikely(!ctx
->fpu_enabled
)) {
2316 GEN_EXCP_NO_FP(ctx
);
2319 tcg_gen_mov_i64(cpu_FT
[0], cpu_fpr
[rB(ctx
->opcode
)]);
2320 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_FT
[0]);
2321 gen_compute_fprf(0, Rc(ctx
->opcode
) != 0);
2325 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2326 GEN_FLOAT_B(nabs
, 0x08, 0x04, 0, PPC_FLOAT
);
2328 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2329 GEN_FLOAT_B(neg
, 0x08, 0x01, 0, PPC_FLOAT
);
2331 /*** Floating-Point status & ctrl register ***/
2333 GEN_HANDLER(mcrfs
, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT
)
2337 if (unlikely(!ctx
->fpu_enabled
)) {
2338 GEN_EXCP_NO_FP(ctx
);
2341 gen_optimize_fprf();
2342 bfa
= 4 * (7 - crfS(ctx
->opcode
));
2343 tcg_gen_shri_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_fpscr
, bfa
);
2344 tcg_gen_andi_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfD(ctx
->opcode
)], 0xf);
2345 gen_op_fpscr_resetbit(~(0xF << bfa
));
2349 GEN_HANDLER(mffs
, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT
)
2351 if (unlikely(!ctx
->fpu_enabled
)) {
2352 GEN_EXCP_NO_FP(ctx
);
2355 gen_optimize_fprf();
2356 gen_reset_fpstatus();
2357 gen_op_load_fpscr_FT0();
2358 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_FT
[0]);
2359 gen_compute_fprf(0, Rc(ctx
->opcode
) != 0);
2363 GEN_HANDLER(mtfsb0
, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT
)
2367 if (unlikely(!ctx
->fpu_enabled
)) {
2368 GEN_EXCP_NO_FP(ctx
);
2371 crb
= 32 - (crbD(ctx
->opcode
) >> 2);
2372 gen_optimize_fprf();
2373 gen_reset_fpstatus();
2374 if (likely(crb
!= 30 && crb
!= 29))
2375 gen_op_fpscr_resetbit(~(1 << crb
));
2376 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2377 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2382 GEN_HANDLER(mtfsb1
, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT
)
2386 if (unlikely(!ctx
->fpu_enabled
)) {
2387 GEN_EXCP_NO_FP(ctx
);
2390 crb
= 32 - (crbD(ctx
->opcode
) >> 2);
2391 gen_optimize_fprf();
2392 gen_reset_fpstatus();
2393 /* XXX: we pretend we can only do IEEE floating-point computations */
2394 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
&& crb
!= FPSCR_NI
))
2395 gen_op_fpscr_setbit(crb
);
2396 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2397 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2399 /* We can raise a differed exception */
2400 gen_op_float_check_status();
2404 GEN_HANDLER(mtfsf
, 0x3F, 0x07, 0x16, 0x02010000, PPC_FLOAT
)
2406 if (unlikely(!ctx
->fpu_enabled
)) {
2407 GEN_EXCP_NO_FP(ctx
);
2410 gen_optimize_fprf();
2411 tcg_gen_mov_i64(cpu_FT
[0], cpu_fpr
[rB(ctx
->opcode
)]);
2412 gen_reset_fpstatus();
2413 gen_op_store_fpscr(FM(ctx
->opcode
));
2414 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2415 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2417 /* We can raise a differed exception */
2418 gen_op_float_check_status();
2422 GEN_HANDLER(mtfsfi
, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT
)
2426 if (unlikely(!ctx
->fpu_enabled
)) {
2427 GEN_EXCP_NO_FP(ctx
);
2430 bf
= crbD(ctx
->opcode
) >> 2;
2432 gen_optimize_fprf();
2433 tcg_gen_movi_i64(cpu_FT
[0], FPIMM(ctx
->opcode
) << (4 * sh
));
2434 gen_reset_fpstatus();
2435 gen_op_store_fpscr(1 << sh
);
2436 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2437 tcg_gen_shri_i32(cpu_crf
[1], cpu_fpscr
, FPSCR_OX
);
2439 /* We can raise a differed exception */
2440 gen_op_float_check_status();
2443 /*** Addressing modes ***/
2444 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2445 static always_inline
void gen_addr_imm_index (TCGv EA
,
2449 target_long simm
= SIMM(ctx
->opcode
);
2452 if (rA(ctx
->opcode
) == 0)
2453 tcg_gen_movi_tl(EA
, simm
);
2454 else if (likely(simm
!= 0))
2455 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
);
2457 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2460 static always_inline
void gen_addr_reg_index (TCGv EA
,
2463 if (rA(ctx
->opcode
) == 0)
2464 tcg_gen_mov_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
2466 tcg_gen_add_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2469 static always_inline
void gen_addr_register (TCGv EA
,
2472 if (rA(ctx
->opcode
) == 0)
2473 tcg_gen_movi_tl(EA
, 0);
2475 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2478 #if defined(TARGET_PPC64)
2479 #define _GEN_MEM_FUNCS(name, mode) \
2480 &gen_op_##name##_##mode, \
2481 &gen_op_##name##_le_##mode, \
2482 &gen_op_##name##_64_##mode, \
2483 &gen_op_##name##_le_64_##mode
2485 #define _GEN_MEM_FUNCS(name, mode) \
2486 &gen_op_##name##_##mode, \
2487 &gen_op_##name##_le_##mode
2489 #if defined(CONFIG_USER_ONLY)
2490 #if defined(TARGET_PPC64)
2491 #define NB_MEM_FUNCS 4
2493 #define NB_MEM_FUNCS 2
2495 #define GEN_MEM_FUNCS(name) \
2496 _GEN_MEM_FUNCS(name, raw)
2498 #if defined(TARGET_PPC64)
2499 #define NB_MEM_FUNCS 12
2501 #define NB_MEM_FUNCS 6
2503 #define GEN_MEM_FUNCS(name) \
2504 _GEN_MEM_FUNCS(name, user), \
2505 _GEN_MEM_FUNCS(name, kernel), \
2506 _GEN_MEM_FUNCS(name, hypv)
2509 /*** Integer load ***/
2510 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
2511 #define OP_LD_TABLE(width) \
2512 static GenOpFunc *gen_op_l##width[NB_MEM_FUNCS] = { \
2513 GEN_MEM_FUNCS(l##width), \
2515 #define OP_ST_TABLE(width) \
2516 static GenOpFunc *gen_op_st##width[NB_MEM_FUNCS] = { \
2517 GEN_MEM_FUNCS(st##width), \
2521 #if defined(TARGET_PPC64)
2522 #define GEN_QEMU_LD_PPC64(width) \
2523 static always_inline void gen_qemu_ld##width##_ppc64(TCGv t0, TCGv t1, int flags)\
2525 if (likely(flags & 2)) \
2526 tcg_gen_qemu_ld##width(t0, t1, flags >> 2); \
2528 TCGv addr = tcg_temp_new(); \
2529 tcg_gen_ext32u_tl(addr, t1); \
2530 tcg_gen_qemu_ld##width(t0, addr, flags >> 2); \
2531 tcg_temp_free(addr); \
2534 GEN_QEMU_LD_PPC64(8u)
2535 GEN_QEMU_LD_PPC64(8s
)
2536 GEN_QEMU_LD_PPC64(16u)
2537 GEN_QEMU_LD_PPC64(16s
)
2538 GEN_QEMU_LD_PPC64(32u)
2539 GEN_QEMU_LD_PPC64(32s
)
2540 GEN_QEMU_LD_PPC64(64)
2542 #define GEN_QEMU_ST_PPC64(width) \
2543 static always_inline void gen_qemu_st##width##_ppc64(TCGv t0, TCGv t1, int flags)\
2545 if (likely(flags & 2)) \
2546 tcg_gen_qemu_st##width(t0, t1, flags >> 2); \
2548 TCGv addr = tcg_temp_new(); \
2549 tcg_gen_ext32u_tl(addr, t1); \
2550 tcg_gen_qemu_st##width(t0, addr, flags >> 2); \
2551 tcg_temp_free(addr); \
2554 GEN_QEMU_ST_PPC64(8)
2555 GEN_QEMU_ST_PPC64(16)
2556 GEN_QEMU_ST_PPC64(32)
2557 GEN_QEMU_ST_PPC64(64)
2559 static always_inline
void gen_qemu_ld8u(TCGv arg0
, TCGv arg1
, int flags
)
2561 gen_qemu_ld8u_ppc64(arg0
, arg1
, flags
);
2564 static always_inline
void gen_qemu_ld8s(TCGv arg0
, TCGv arg1
, int flags
)
2566 gen_qemu_ld8s_ppc64(arg0
, arg1
, flags
);
2569 static always_inline
void gen_qemu_ld16u(TCGv arg0
, TCGv arg1
, int flags
)
2571 if (unlikely(flags
& 1)) {
2573 gen_qemu_ld16u_ppc64(arg0
, arg1
, flags
);
2574 t0
= tcg_temp_new_i32();
2575 tcg_gen_trunc_tl_i32(t0
, arg0
);
2576 tcg_gen_bswap16_i32(t0
, t0
);
2577 tcg_gen_extu_i32_tl(arg0
, t0
);
2578 tcg_temp_free_i32(t0
);
2580 gen_qemu_ld16u_ppc64(arg0
, arg1
, flags
);
2583 static always_inline
void gen_qemu_ld16s(TCGv arg0
, TCGv arg1
, int flags
)
2585 if (unlikely(flags
& 1)) {
2587 gen_qemu_ld16u_ppc64(arg0
, arg1
, flags
);
2588 t0
= tcg_temp_new_i32();
2589 tcg_gen_trunc_tl_i32(t0
, arg0
);
2590 tcg_gen_bswap16_i32(t0
, t0
);
2591 tcg_gen_extu_i32_tl(arg0
, t0
);
2592 tcg_gen_ext16s_tl(arg0
, arg0
);
2593 tcg_temp_free_i32(t0
);
2595 gen_qemu_ld16s_ppc64(arg0
, arg1
, flags
);
2598 static always_inline
void gen_qemu_ld32u(TCGv arg0
, TCGv arg1
, int flags
)
2600 if (unlikely(flags
& 1)) {
2602 gen_qemu_ld32u_ppc64(arg0
, arg1
, flags
);
2603 t0
= tcg_temp_new_i32();
2604 tcg_gen_trunc_tl_i32(t0
, arg0
);
2605 tcg_gen_bswap_i32(t0
, t0
);
2606 tcg_gen_extu_i32_tl(arg0
, t0
);
2607 tcg_temp_free_i32(t0
);
2609 gen_qemu_ld32u_ppc64(arg0
, arg1
, flags
);
2612 static always_inline
void gen_qemu_ld32s(TCGv arg0
, TCGv arg1
, int flags
)
2614 if (unlikely(flags
& 1)) {
2616 gen_qemu_ld32u_ppc64(arg0
, arg1
, flags
);
2617 t0
= tcg_temp_new_i32();
2618 tcg_gen_trunc_tl_i32(t0
, arg0
);
2619 tcg_gen_bswap_i32(t0
, t0
);
2620 tcg_gen_ext_i32_tl(arg0
, t0
);
2621 tcg_temp_free_i32(t0
);
2623 gen_qemu_ld32s_ppc64(arg0
, arg1
, flags
);
2626 static always_inline
void gen_qemu_ld64(TCGv arg0
, TCGv arg1
, int flags
)
2628 gen_qemu_ld64_ppc64(arg0
, arg1
, flags
);
2629 if (unlikely(flags
& 1))
2630 tcg_gen_bswap_i64(arg0
, arg0
);
2633 static always_inline
void gen_qemu_st8(TCGv arg0
, TCGv arg1
, int flags
)
2635 gen_qemu_st8_ppc64(arg0
, arg1
, flags
);
2638 static always_inline
void gen_qemu_st16(TCGv arg0
, TCGv arg1
, int flags
)
2640 if (unlikely(flags
& 1)) {
2643 t0
= tcg_temp_new_i32();
2644 tcg_gen_trunc_tl_i32(t0
, arg0
);
2645 tcg_gen_ext16u_i32(t0
, t0
);
2646 tcg_gen_bswap16_i32(t0
, t0
);
2647 t1
= tcg_temp_new_i64();
2648 tcg_gen_extu_i32_tl(t1
, t0
);
2649 tcg_temp_free_i32(t0
);
2650 gen_qemu_st16_ppc64(t1
, arg1
, flags
);
2651 tcg_temp_free_i64(t1
);
2653 gen_qemu_st16_ppc64(arg0
, arg1
, flags
);
2656 static always_inline
void gen_qemu_st32(TCGv arg0
, TCGv arg1
, int flags
)
2658 if (unlikely(flags
& 1)) {
2661 t0
= tcg_temp_new_i32();
2662 tcg_gen_trunc_tl_i32(t0
, arg0
);
2663 tcg_gen_bswap_i32(t0
, t0
);
2664 t1
= tcg_temp_new_i64();
2665 tcg_gen_extu_i32_tl(t1
, t0
);
2666 tcg_temp_free_i32(t0
);
2667 gen_qemu_st32_ppc64(t1
, arg1
, flags
);
2668 tcg_temp_free_i64(t1
);
2670 gen_qemu_st32_ppc64(arg0
, arg1
, flags
);
2673 static always_inline
void gen_qemu_st64(TCGv arg0
, TCGv arg1
, int flags
)
2675 if (unlikely(flags
& 1)) {
2676 TCGv_i64 t0
= tcg_temp_new_i64();
2677 tcg_gen_bswap_i64(t0
, arg0
);
2678 gen_qemu_st64_ppc64(t0
, arg1
, flags
);
2679 tcg_temp_free_i64(t0
);
2681 gen_qemu_st64_ppc64(arg0
, arg1
, flags
);
2685 #else /* defined(TARGET_PPC64) */
2686 #define GEN_QEMU_LD_PPC32(width) \
2687 static always_inline void gen_qemu_ld##width##_ppc32(TCGv arg0, TCGv arg1, int flags)\
2689 tcg_gen_qemu_ld##width(arg0, arg1, flags >> 1); \
2691 GEN_QEMU_LD_PPC32(8u)
2692 GEN_QEMU_LD_PPC32(8s
)
2693 GEN_QEMU_LD_PPC32(16u)
2694 GEN_QEMU_LD_PPC32(16s
)
2695 GEN_QEMU_LD_PPC32(32u)
2696 GEN_QEMU_LD_PPC32(32s
)
2698 #define GEN_QEMU_ST_PPC32(width) \
2699 static always_inline void gen_qemu_st##width##_ppc32(TCGv arg0, TCGv arg1, int flags)\
2701 tcg_gen_qemu_st##width(arg0, arg1, flags >> 1); \
2703 GEN_QEMU_ST_PPC32(8)
2704 GEN_QEMU_ST_PPC32(16)
2705 GEN_QEMU_ST_PPC32(32)
2707 static always_inline
void gen_qemu_ld8u(TCGv arg0
, TCGv arg1
, int flags
)
2709 gen_qemu_ld8u_ppc32(arg0
, arg1
, flags
>> 1);
2712 static always_inline
void gen_qemu_ld8s(TCGv arg0
, TCGv arg1
, int flags
)
2714 gen_qemu_ld8s_ppc32(arg0
, arg1
, flags
>> 1);
2717 static always_inline
void gen_qemu_ld16u(TCGv arg0
, TCGv arg1
, int flags
)
2719 gen_qemu_ld16u_ppc32(arg0
, arg1
, flags
>> 1);
2720 if (unlikely(flags
& 1))
2721 tcg_gen_bswap16_i32(arg0
, arg0
);
2724 static always_inline
void gen_qemu_ld16s(TCGv arg0
, TCGv arg1
, int flags
)
2726 if (unlikely(flags
& 1)) {
2727 gen_qemu_ld16u_ppc32(arg0
, arg1
, flags
);
2728 tcg_gen_bswap16_i32(arg0
, arg0
);
2729 tcg_gen_ext16s_i32(arg0
, arg0
);
2731 gen_qemu_ld16s_ppc32(arg0
, arg1
, flags
);
2734 static always_inline
void gen_qemu_ld32u(TCGv arg0
, TCGv arg1
, int flags
)
2736 gen_qemu_ld32u_ppc32(arg0
, arg1
, flags
);
2737 if (unlikely(flags
& 1))
2738 tcg_gen_bswap_i32(arg0
, arg0
);
2741 static always_inline
void gen_qemu_st8(TCGv arg0
, TCGv arg1
, int flags
)
2743 gen_qemu_st8_ppc32(arg0
, arg1
, flags
);
2746 static always_inline
void gen_qemu_st16(TCGv arg0
, TCGv arg1
, int flags
)
2748 if (unlikely(flags
& 1)) {
2749 TCGv_i32 temp
= tcg_temp_new_i32();
2750 tcg_gen_ext16u_i32(temp
, arg0
);
2751 tcg_gen_bswap16_i32(temp
, temp
);
2752 gen_qemu_st16_ppc32(temp
, arg1
, flags
);
2753 tcg_temp_free_i32(temp
);
2755 gen_qemu_st16_ppc32(arg0
, arg1
, flags
);
2758 static always_inline
void gen_qemu_st32(TCGv arg0
, TCGv arg1
, int flags
)
2760 if (unlikely(flags
& 1)) {
2761 TCGv_i32 temp
= tcg_temp_new_i32();
2762 tcg_gen_bswap_i32(temp
, arg0
);
2763 gen_qemu_st32_ppc32(temp
, arg1
, flags
);
2764 tcg_temp_free_i32(temp
);
2766 gen_qemu_st32_ppc32(arg0
, arg1
, flags
);
2771 #define GEN_LD(width, opc, type) \
2772 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2774 TCGv EA = tcg_temp_new(); \
2775 gen_addr_imm_index(EA, ctx, 0); \
2776 gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2777 tcg_temp_free(EA); \
2780 #define GEN_LDU(width, opc, type) \
2781 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2784 if (unlikely(rA(ctx->opcode) == 0 || \
2785 rA(ctx->opcode) == rD(ctx->opcode))) { \
2786 GEN_EXCP_INVAL(ctx); \
2789 EA = tcg_temp_new(); \
2790 if (type == PPC_64B) \
2791 gen_addr_imm_index(EA, ctx, 0x03); \
2793 gen_addr_imm_index(EA, ctx, 0); \
2794 gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2795 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2796 tcg_temp_free(EA); \
2799 #define GEN_LDUX(width, opc2, opc3, type) \
2800 GEN_HANDLER(l##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2803 if (unlikely(rA(ctx->opcode) == 0 || \
2804 rA(ctx->opcode) == rD(ctx->opcode))) { \
2805 GEN_EXCP_INVAL(ctx); \
2808 EA = tcg_temp_new(); \
2809 gen_addr_reg_index(EA, ctx); \
2810 gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2811 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2812 tcg_temp_free(EA); \
2815 #define GEN_LDX(width, opc2, opc3, type) \
2816 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2818 TCGv EA = tcg_temp_new(); \
2819 gen_addr_reg_index(EA, ctx); \
2820 gen_qemu_ld##width(cpu_gpr[rD(ctx->opcode)], EA, ctx->mem_idx); \
2821 tcg_temp_free(EA); \
2824 #define GEN_LDS(width, op, type) \
2825 GEN_LD(width, op | 0x20, type); \
2826 GEN_LDU(width, op | 0x21, type); \
2827 GEN_LDUX(width, 0x17, op | 0x01, type); \
2828 GEN_LDX(width, 0x17, op | 0x00, type)
2830 /* lbz lbzu lbzux lbzx */
2831 GEN_LDS(8u, 0x02, PPC_INTEGER
);
2832 /* lha lhau lhaux lhax */
2833 GEN_LDS(16s
, 0x0A, PPC_INTEGER
);
2834 /* lhz lhzu lhzux lhzx */
2835 GEN_LDS(16u, 0x08, PPC_INTEGER
);
2836 /* lwz lwzu lwzux lwzx */
2837 GEN_LDS(32u, 0x00, PPC_INTEGER
);
2838 #if defined(TARGET_PPC64)
2840 GEN_LDUX(32s
, 0x15, 0x0B, PPC_64B
);
2842 GEN_LDX(32s
, 0x15, 0x0A, PPC_64B
);
2844 GEN_LDUX(64, 0x15, 0x01, PPC_64B
);
2846 GEN_LDX(64, 0x15, 0x00, PPC_64B
);
2847 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
)
2850 if (Rc(ctx
->opcode
)) {
2851 if (unlikely(rA(ctx
->opcode
) == 0 ||
2852 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
2853 GEN_EXCP_INVAL(ctx
);
2857 EA
= tcg_temp_new();
2858 gen_addr_imm_index(EA
, ctx
, 0x03);
2859 if (ctx
->opcode
& 0x02) {
2860 /* lwa (lwau is undefined) */
2861 gen_qemu_ld32s(cpu_gpr
[rD(ctx
->opcode
)], EA
, ctx
->mem_idx
);
2864 gen_qemu_ld64(cpu_gpr
[rD(ctx
->opcode
)], EA
, ctx
->mem_idx
);
2866 if (Rc(ctx
->opcode
))
2867 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
2871 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
)
2873 #if defined(CONFIG_USER_ONLY)
2874 GEN_EXCP_PRIVOPC(ctx
);
2879 /* Restore CPU state */
2880 if (unlikely(ctx
->supervisor
== 0)) {
2881 GEN_EXCP_PRIVOPC(ctx
);
2884 ra
= rA(ctx
->opcode
);
2885 rd
= rD(ctx
->opcode
);
2886 if (unlikely((rd
& 1) || rd
== ra
)) {
2887 GEN_EXCP_INVAL(ctx
);
2890 if (unlikely(ctx
->mem_idx
& 1)) {
2891 /* Little-endian mode is not handled */
2892 GEN_EXCP(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2895 EA
= tcg_temp_new();
2896 gen_addr_imm_index(EA
, ctx
, 0x0F);
2897 gen_qemu_ld64(cpu_gpr
[rd
], EA
, ctx
->mem_idx
);
2898 tcg_gen_addi_tl(EA
, EA
, 8);
2899 gen_qemu_ld64(cpu_gpr
[rd
+1], EA
, ctx
->mem_idx
);
2905 /*** Integer store ***/
2906 #define GEN_ST(width, opc, type) \
2907 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2909 TCGv EA = tcg_temp_new(); \
2910 gen_addr_imm_index(EA, ctx, 0); \
2911 gen_qemu_st##width(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
2912 tcg_temp_free(EA); \
2915 #define GEN_STU(width, opc, type) \
2916 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2919 if (unlikely(rA(ctx->opcode) == 0)) { \
2920 GEN_EXCP_INVAL(ctx); \
2923 EA = tcg_temp_new(); \
2924 if (type == PPC_64B) \
2925 gen_addr_imm_index(EA, ctx, 0x03); \
2927 gen_addr_imm_index(EA, ctx, 0); \
2928 gen_qemu_st##width(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
2929 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2930 tcg_temp_free(EA); \
2933 #define GEN_STUX(width, opc2, opc3, type) \
2934 GEN_HANDLER(st##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2937 if (unlikely(rA(ctx->opcode) == 0)) { \
2938 GEN_EXCP_INVAL(ctx); \
2941 EA = tcg_temp_new(); \
2942 gen_addr_reg_index(EA, ctx); \
2943 gen_qemu_st##width(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
2944 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
2945 tcg_temp_free(EA); \
2948 #define GEN_STX(width, opc2, opc3, type) \
2949 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2951 TCGv EA = tcg_temp_new(); \
2952 gen_addr_reg_index(EA, ctx); \
2953 gen_qemu_st##width(cpu_gpr[rS(ctx->opcode)], EA, ctx->mem_idx); \
2954 tcg_temp_free(EA); \
2957 #define GEN_STS(width, op, type) \
2958 GEN_ST(width, op | 0x20, type); \
2959 GEN_STU(width, op | 0x21, type); \
2960 GEN_STUX(width, 0x17, op | 0x01, type); \
2961 GEN_STX(width, 0x17, op | 0x00, type)
2963 /* stb stbu stbux stbx */
2964 GEN_STS(8, 0x06, PPC_INTEGER
);
2965 /* sth sthu sthux sthx */
2966 GEN_STS(16, 0x0C, PPC_INTEGER
);
2967 /* stw stwu stwux stwx */
2968 GEN_STS(32, 0x04, PPC_INTEGER
);
2969 #if defined(TARGET_PPC64)
2970 GEN_STUX(64, 0x15, 0x05, PPC_64B
);
2971 GEN_STX(64, 0x15, 0x04, PPC_64B
);
2972 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
)
2977 rs
= rS(ctx
->opcode
);
2978 if ((ctx
->opcode
& 0x3) == 0x2) {
2979 #if defined(CONFIG_USER_ONLY)
2980 GEN_EXCP_PRIVOPC(ctx
);
2983 if (unlikely(ctx
->supervisor
== 0)) {
2984 GEN_EXCP_PRIVOPC(ctx
);
2987 if (unlikely(rs
& 1)) {
2988 GEN_EXCP_INVAL(ctx
);
2991 if (unlikely(ctx
->mem_idx
& 1)) {
2992 /* Little-endian mode is not handled */
2993 GEN_EXCP(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2996 EA
= tcg_temp_new();
2997 gen_addr_imm_index(EA
, ctx
, 0x03);
2998 gen_qemu_st64(cpu_gpr
[rs
], EA
, ctx
->mem_idx
);
2999 tcg_gen_addi_tl(EA
, EA
, 8);
3000 gen_qemu_st64(cpu_gpr
[rs
+1], EA
, ctx
->mem_idx
);
3005 if (Rc(ctx
->opcode
)) {
3006 if (unlikely(rA(ctx
->opcode
) == 0)) {
3007 GEN_EXCP_INVAL(ctx
);
3011 EA
= tcg_temp_new();
3012 gen_addr_imm_index(EA
, ctx
, 0x03);
3013 gen_qemu_st64(cpu_gpr
[rs
], EA
, ctx
->mem_idx
);
3014 if (Rc(ctx
->opcode
))
3015 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
3020 /*** Integer load and store with byte reverse ***/
3022 void always_inline
gen_qemu_ld16ur(TCGv t0
, TCGv t1
, int flags
)
3024 TCGv_i32 temp
= tcg_temp_new_i32();
3025 gen_qemu_ld16u(t0
, t1
, flags
);
3026 tcg_gen_trunc_tl_i32(temp
, t0
);
3027 tcg_gen_bswap16_i32(temp
, temp
);
3028 tcg_gen_extu_i32_tl(t0
, temp
);
3029 tcg_temp_free_i32(temp
);
3031 GEN_LDX(16ur
, 0x16, 0x18, PPC_INTEGER
);
3034 void always_inline
gen_qemu_ld32ur(TCGv t0
, TCGv t1
, int flags
)
3036 TCGv_i32 temp
= tcg_temp_new_i32();
3037 gen_qemu_ld32u(t0
, t1
, flags
);
3038 tcg_gen_trunc_tl_i32(temp
, t0
);
3039 tcg_gen_bswap_i32(temp
, temp
);
3040 tcg_gen_extu_i32_tl(t0
, temp
);
3041 tcg_temp_free_i32(temp
);
3043 GEN_LDX(32ur
, 0x16, 0x10, PPC_INTEGER
);
3046 void always_inline
gen_qemu_st16r(TCGv t0
, TCGv t1
, int flags
)
3048 TCGv_i32 temp
= tcg_temp_new_i32();
3049 TCGv t2
= tcg_temp_new();
3050 tcg_gen_trunc_tl_i32(temp
, t0
);
3051 tcg_gen_ext16u_i32(temp
, temp
);
3052 tcg_gen_bswap16_i32(temp
, temp
);
3053 tcg_gen_extu_i32_tl(t2
, temp
);
3054 tcg_temp_free_i32(temp
);
3055 gen_qemu_st16(t2
, t1
, flags
);
3058 GEN_STX(16r
, 0x16, 0x1C, PPC_INTEGER
);
3061 void always_inline
gen_qemu_st32r(TCGv t0
, TCGv t1
, int flags
)
3063 TCGv_i32 temp
= tcg_temp_new_i32();
3064 TCGv t2
= tcg_temp_new();
3065 tcg_gen_trunc_tl_i32(temp
, t0
);
3066 tcg_gen_bswap_i32(temp
, temp
);
3067 tcg_gen_extu_i32_tl(t2
, temp
);
3068 tcg_temp_free_i32(temp
);
3069 gen_qemu_st16(t2
, t1
, flags
);
3072 GEN_STX(32r
, 0x16, 0x14, PPC_INTEGER
);
3074 /*** Integer load and store multiple ***/
3075 #define op_ldstm(name, reg) (*gen_op_##name[ctx->mem_idx])(reg)
3076 static GenOpFunc1
*gen_op_lmw
[NB_MEM_FUNCS
] = {
3079 static GenOpFunc1
*gen_op_stmw
[NB_MEM_FUNCS
] = {
3080 GEN_MEM_FUNCS(stmw
),
3084 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
3086 /* NIP cannot be restored if the memory exception comes from an helper */
3087 gen_update_nip(ctx
, ctx
->nip
- 4);
3088 gen_addr_imm_index(cpu_T
[0], ctx
, 0);
3089 op_ldstm(lmw
, rD(ctx
->opcode
));
3093 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
3095 /* NIP cannot be restored if the memory exception comes from an helper */
3096 gen_update_nip(ctx
, ctx
->nip
- 4);
3097 gen_addr_imm_index(cpu_T
[0], ctx
, 0);
3098 op_ldstm(stmw
, rS(ctx
->opcode
));
3101 /*** Integer load and store strings ***/
3102 #define op_ldsts(name, start) (*gen_op_##name[ctx->mem_idx])(start)
3103 #define op_ldstsx(name, rd, ra, rb) (*gen_op_##name[ctx->mem_idx])(rd, ra, rb)
3104 /* string load & stores are by definition endian-safe */
3105 #define gen_op_lswi_le_raw gen_op_lswi_raw
3106 #define gen_op_lswi_le_user gen_op_lswi_user
3107 #define gen_op_lswi_le_kernel gen_op_lswi_kernel
3108 #define gen_op_lswi_le_hypv gen_op_lswi_hypv
3109 #define gen_op_lswi_le_64_raw gen_op_lswi_raw
3110 #define gen_op_lswi_le_64_user gen_op_lswi_user
3111 #define gen_op_lswi_le_64_kernel gen_op_lswi_kernel
3112 #define gen_op_lswi_le_64_hypv gen_op_lswi_hypv
3113 static GenOpFunc1
*gen_op_lswi
[NB_MEM_FUNCS
] = {
3114 GEN_MEM_FUNCS(lswi
),
3116 #define gen_op_lswx_le_raw gen_op_lswx_raw
3117 #define gen_op_lswx_le_user gen_op_lswx_user
3118 #define gen_op_lswx_le_kernel gen_op_lswx_kernel
3119 #define gen_op_lswx_le_hypv gen_op_lswx_hypv
3120 #define gen_op_lswx_le_64_raw gen_op_lswx_raw
3121 #define gen_op_lswx_le_64_user gen_op_lswx_user
3122 #define gen_op_lswx_le_64_kernel gen_op_lswx_kernel
3123 #define gen_op_lswx_le_64_hypv gen_op_lswx_hypv
3124 static GenOpFunc3
*gen_op_lswx
[NB_MEM_FUNCS
] = {
3125 GEN_MEM_FUNCS(lswx
),
3127 #define gen_op_stsw_le_raw gen_op_stsw_raw
3128 #define gen_op_stsw_le_user gen_op_stsw_user
3129 #define gen_op_stsw_le_kernel gen_op_stsw_kernel
3130 #define gen_op_stsw_le_hypv gen_op_stsw_hypv
3131 #define gen_op_stsw_le_64_raw gen_op_stsw_raw
3132 #define gen_op_stsw_le_64_user gen_op_stsw_user
3133 #define gen_op_stsw_le_64_kernel gen_op_stsw_kernel
3134 #define gen_op_stsw_le_64_hypv gen_op_stsw_hypv
3135 static GenOpFunc1
*gen_op_stsw
[NB_MEM_FUNCS
] = {
3136 GEN_MEM_FUNCS(stsw
),
3140 /* PowerPC32 specification says we must generate an exception if
3141 * rA is in the range of registers to be loaded.
3142 * In an other hand, IBM says this is valid, but rA won't be loaded.
3143 * For now, I'll follow the spec...
3145 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
)
3147 int nb
= NB(ctx
->opcode
);
3148 int start
= rD(ctx
->opcode
);
3149 int ra
= rA(ctx
->opcode
);
3155 if (unlikely(((start
+ nr
) > 32 &&
3156 start
<= ra
&& (start
+ nr
- 32) > ra
) ||
3157 ((start
+ nr
) <= 32 && start
<= ra
&& (start
+ nr
) > ra
))) {
3158 GEN_EXCP(ctx
, POWERPC_EXCP_PROGRAM
,
3159 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_LSWX
);
3162 /* NIP cannot be restored if the memory exception comes from an helper */
3163 gen_update_nip(ctx
, ctx
->nip
- 4);
3164 gen_addr_register(cpu_T
[0], ctx
);
3165 tcg_gen_movi_tl(cpu_T
[1], nb
);
3166 op_ldsts(lswi
, start
);
3170 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
)
3172 int ra
= rA(ctx
->opcode
);
3173 int rb
= rB(ctx
->opcode
);
3175 /* NIP cannot be restored if the memory exception comes from an helper */
3176 gen_update_nip(ctx
, ctx
->nip
- 4);
3177 gen_addr_reg_index(cpu_T
[0], ctx
);
3181 tcg_gen_andi_tl(cpu_T
[1], cpu_xer
, 0x7F);
3182 op_ldstsx(lswx
, rD(ctx
->opcode
), ra
, rb
);
3186 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
)
3188 int nb
= NB(ctx
->opcode
);
3190 /* NIP cannot be restored if the memory exception comes from an helper */
3191 gen_update_nip(ctx
, ctx
->nip
- 4);
3192 gen_addr_register(cpu_T
[0], ctx
);
3195 tcg_gen_movi_tl(cpu_T
[1], nb
);
3196 op_ldsts(stsw
, rS(ctx
->opcode
));
3200 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
)
3202 /* NIP cannot be restored if the memory exception comes from an helper */
3203 gen_update_nip(ctx
, ctx
->nip
- 4);
3204 gen_addr_reg_index(cpu_T
[0], ctx
);
3205 tcg_gen_andi_tl(cpu_T
[1], cpu_xer
, 0x7F);
3206 op_ldsts(stsw
, rS(ctx
->opcode
));
3209 /*** Memory synchronisation ***/
3211 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO
)
3216 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
)
3221 #define op_lwarx() (*gen_op_lwarx[ctx->mem_idx])()
3222 #define op_stwcx() (*gen_op_stwcx[ctx->mem_idx])()
3223 static GenOpFunc
*gen_op_lwarx
[NB_MEM_FUNCS
] = {
3224 GEN_MEM_FUNCS(lwarx
),
3226 static GenOpFunc
*gen_op_stwcx
[NB_MEM_FUNCS
] = {
3227 GEN_MEM_FUNCS(stwcx
),
3231 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000001, PPC_RES
)
3233 /* NIP cannot be restored if the memory exception comes from an helper */
3234 gen_update_nip(ctx
, ctx
->nip
- 4);
3235 gen_addr_reg_index(cpu_T
[0], ctx
);
3237 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[1]);
3241 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
)
3243 /* NIP cannot be restored if the memory exception comes from an helper */
3244 gen_update_nip(ctx
, ctx
->nip
- 4);
3245 gen_addr_reg_index(cpu_T
[0], ctx
);
3246 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
3250 #if defined(TARGET_PPC64)
3251 #define op_ldarx() (*gen_op_ldarx[ctx->mem_idx])()
3252 #define op_stdcx() (*gen_op_stdcx[ctx->mem_idx])()
3253 static GenOpFunc
*gen_op_ldarx
[NB_MEM_FUNCS
] = {
3254 GEN_MEM_FUNCS(ldarx
),
3256 static GenOpFunc
*gen_op_stdcx
[NB_MEM_FUNCS
] = {
3257 GEN_MEM_FUNCS(stdcx
),
3261 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000001, PPC_64B
)
3263 /* NIP cannot be restored if the memory exception comes from an helper */
3264 gen_update_nip(ctx
, ctx
->nip
- 4);
3265 gen_addr_reg_index(cpu_T
[0], ctx
);
3267 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[1]);
3271 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
)
3273 /* NIP cannot be restored if the memory exception comes from an helper */
3274 gen_update_nip(ctx
, ctx
->nip
- 4);
3275 gen_addr_reg_index(cpu_T
[0], ctx
);
3276 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
3279 #endif /* defined(TARGET_PPC64) */
3282 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
)
3287 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
)
3289 /* Stop translation, as the CPU is supposed to sleep from now */
3291 GEN_EXCP(ctx
, EXCP_HLT
, 1);
3294 /*** Floating-point load ***/
3295 #define GEN_LDF(width, opc, type) \
3296 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
3298 if (unlikely(!ctx->fpu_enabled)) { \
3299 GEN_EXCP_NO_FP(ctx); \
3302 gen_addr_imm_index(cpu_T[0], ctx, 0); \
3303 op_ldst(l##width); \
3304 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
3307 #define GEN_LDUF(width, opc, type) \
3308 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
3310 if (unlikely(!ctx->fpu_enabled)) { \
3311 GEN_EXCP_NO_FP(ctx); \
3314 if (unlikely(rA(ctx->opcode) == 0)) { \
3315 GEN_EXCP_INVAL(ctx); \
3318 gen_addr_imm_index(cpu_T[0], ctx, 0); \
3319 op_ldst(l##width); \
3320 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
3321 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
3324 #define GEN_LDUXF(width, opc, type) \
3325 GEN_HANDLER(l##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \
3327 if (unlikely(!ctx->fpu_enabled)) { \
3328 GEN_EXCP_NO_FP(ctx); \
3331 if (unlikely(rA(ctx->opcode) == 0)) { \
3332 GEN_EXCP_INVAL(ctx); \
3335 gen_addr_reg_index(cpu_T[0], ctx); \
3336 op_ldst(l##width); \
3337 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
3338 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
3341 #define GEN_LDXF(width, opc2, opc3, type) \
3342 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
3344 if (unlikely(!ctx->fpu_enabled)) { \
3345 GEN_EXCP_NO_FP(ctx); \
3348 gen_addr_reg_index(cpu_T[0], ctx); \
3349 op_ldst(l##width); \
3350 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
3353 #define GEN_LDFS(width, op, type) \
3354 OP_LD_TABLE(width); \
3355 GEN_LDF(width, op | 0x20, type); \
3356 GEN_LDUF(width, op | 0x21, type); \
3357 GEN_LDUXF(width, op | 0x01, type); \
3358 GEN_LDXF(width, 0x17, op | 0x00, type)
3360 /* lfd lfdu lfdux lfdx */
3361 GEN_LDFS(fd
, 0x12, PPC_FLOAT
);
3362 /* lfs lfsu lfsux lfsx */
3363 GEN_LDFS(fs
, 0x10, PPC_FLOAT
);
3365 /*** Floating-point store ***/
3366 #define GEN_STF(width, opc, type) \
3367 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \
3369 if (unlikely(!ctx->fpu_enabled)) { \
3370 GEN_EXCP_NO_FP(ctx); \
3373 gen_addr_imm_index(cpu_T[0], ctx, 0); \
3374 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
3375 op_ldst(st##width); \
3378 #define GEN_STUF(width, opc, type) \
3379 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
3381 if (unlikely(!ctx->fpu_enabled)) { \
3382 GEN_EXCP_NO_FP(ctx); \
3385 if (unlikely(rA(ctx->opcode) == 0)) { \
3386 GEN_EXCP_INVAL(ctx); \
3389 gen_addr_imm_index(cpu_T[0], ctx, 0); \
3390 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
3391 op_ldst(st##width); \
3392 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
3395 #define GEN_STUXF(width, opc, type) \
3396 GEN_HANDLER(st##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \
3398 if (unlikely(!ctx->fpu_enabled)) { \
3399 GEN_EXCP_NO_FP(ctx); \
3402 if (unlikely(rA(ctx->opcode) == 0)) { \
3403 GEN_EXCP_INVAL(ctx); \
3406 gen_addr_reg_index(cpu_T[0], ctx); \
3407 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
3408 op_ldst(st##width); \
3409 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
3412 #define GEN_STXF(width, opc2, opc3, type) \
3413 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
3415 if (unlikely(!ctx->fpu_enabled)) { \
3416 GEN_EXCP_NO_FP(ctx); \
3419 gen_addr_reg_index(cpu_T[0], ctx); \
3420 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
3421 op_ldst(st##width); \
3424 #define GEN_STFS(width, op, type) \
3425 OP_ST_TABLE(width); \
3426 GEN_STF(width, op | 0x20, type); \
3427 GEN_STUF(width, op | 0x21, type); \
3428 GEN_STUXF(width, op | 0x01, type); \
3429 GEN_STXF(width, 0x17, op | 0x00, type)
3431 /* stfd stfdu stfdux stfdx */
3432 GEN_STFS(fd
, 0x16, PPC_FLOAT
);
3433 /* stfs stfsu stfsux stfsx */
3434 GEN_STFS(fs
, 0x14, PPC_FLOAT
);
3439 GEN_STXF(fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
);
3442 static always_inline
void gen_goto_tb (DisasContext
*ctx
, int n
,
3445 TranslationBlock
*tb
;
3447 #if defined(TARGET_PPC64)
3449 dest
= (uint32_t) dest
;
3451 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
3452 likely(!ctx
->singlestep_enabled
)) {
3454 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3455 tcg_gen_exit_tb((long)tb
+ n
);
3457 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
3458 if (unlikely(ctx
->singlestep_enabled
)) {
3459 if ((ctx
->singlestep_enabled
&
3460 (CPU_BRANCH_STEP
| CPU_SINGLE_STEP
)) &&
3461 ctx
->exception
== POWERPC_EXCP_BRANCH
) {
3462 target_ulong tmp
= ctx
->nip
;
3464 GEN_EXCP(ctx
, POWERPC_EXCP_TRACE
, 0);
3467 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
3468 gen_update_nip(ctx
, dest
);
3476 static always_inline
void gen_setlr (DisasContext
*ctx
, target_ulong nip
)
3478 #if defined(TARGET_PPC64)
3479 if (ctx
->sf_mode
== 0)
3480 tcg_gen_movi_tl(cpu_lr
, (uint32_t)nip
);
3483 tcg_gen_movi_tl(cpu_lr
, nip
);
3487 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
3489 target_ulong li
, target
;
3491 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3492 /* sign extend LI */
3493 #if defined(TARGET_PPC64)
3495 li
= ((int64_t)LI(ctx
->opcode
) << 38) >> 38;
3498 li
= ((int32_t)LI(ctx
->opcode
) << 6) >> 6;
3499 if (likely(AA(ctx
->opcode
) == 0))
3500 target
= ctx
->nip
+ li
- 4;
3503 if (LK(ctx
->opcode
))
3504 gen_setlr(ctx
, ctx
->nip
);
3505 gen_goto_tb(ctx
, 0, target
);
3512 static always_inline
void gen_bcond (DisasContext
*ctx
, int type
)
3514 uint32_t bo
= BO(ctx
->opcode
);
3515 int l1
= gen_new_label();
3518 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3519 if (type
== BCOND_LR
|| type
== BCOND_CTR
) {
3520 target
= tcg_temp_local_new();
3521 if (type
== BCOND_CTR
)
3522 tcg_gen_mov_tl(target
, cpu_ctr
);
3524 tcg_gen_mov_tl(target
, cpu_lr
);
3526 if (LK(ctx
->opcode
))
3527 gen_setlr(ctx
, ctx
->nip
);
3528 l1
= gen_new_label();
3529 if ((bo
& 0x4) == 0) {
3530 /* Decrement and test CTR */
3531 TCGv temp
= tcg_temp_new();
3532 if (unlikely(type
== BCOND_CTR
)) {
3533 GEN_EXCP_INVAL(ctx
);
3536 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
3537 #if defined(TARGET_PPC64)
3539 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
3542 tcg_gen_mov_tl(temp
, cpu_ctr
);
3544 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
3546 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
3548 tcg_temp_free(temp
);
3550 if ((bo
& 0x10) == 0) {
3552 uint32_t bi
= BI(ctx
->opcode
);
3553 uint32_t mask
= 1 << (3 - (bi
& 0x03));
3554 TCGv_i32 temp
= tcg_temp_new_i32();
3557 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3558 tcg_gen_brcondi_i32(TCG_COND_EQ
, temp
, 0, l1
);
3560 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
3561 tcg_gen_brcondi_i32(TCG_COND_NE
, temp
, 0, l1
);
3563 tcg_temp_free_i32(temp
);
3565 if (type
== BCOND_IM
) {
3566 target_ulong li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
3567 if (likely(AA(ctx
->opcode
) == 0)) {
3568 gen_goto_tb(ctx
, 0, ctx
->nip
+ li
- 4);
3570 gen_goto_tb(ctx
, 0, li
);
3573 gen_goto_tb(ctx
, 1, ctx
->nip
);
3575 #if defined(TARGET_PPC64)
3576 if (!(ctx
->sf_mode
))
3577 tcg_gen_andi_tl(cpu_nip
, target
, (uint32_t)~3);
3580 tcg_gen_andi_tl(cpu_nip
, target
, ~3);
3583 #if defined(TARGET_PPC64)
3584 if (!(ctx
->sf_mode
))
3585 tcg_gen_movi_tl(cpu_nip
, (uint32_t)ctx
->nip
);
3588 tcg_gen_movi_tl(cpu_nip
, ctx
->nip
);
3593 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
3595 gen_bcond(ctx
, BCOND_IM
);
3598 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
)
3600 gen_bcond(ctx
, BCOND_CTR
);
3603 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
)
3605 gen_bcond(ctx
, BCOND_LR
);
3608 /*** Condition register logical ***/
3609 #define GEN_CRLOGIC(name, tcg_op, opc) \
3610 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) \
3615 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3616 t0 = tcg_temp_new_i32(); \
3618 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
3620 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
3622 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
3623 t1 = tcg_temp_new_i32(); \
3624 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3626 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
3628 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
3630 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
3631 tcg_op(t0, t0, t1); \
3632 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
3633 tcg_gen_andi_i32(t0, t0, bitmask); \
3634 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
3635 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
3636 tcg_temp_free_i32(t0); \
3637 tcg_temp_free_i32(t1); \
3641 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08);
3643 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04);
3645 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09);
3647 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07);
3649 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01);
3651 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E);
3653 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D);
3655 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06);
3657 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
)
3659 tcg_gen_mov_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfS(ctx
->opcode
)]);
3662 /*** System linkage ***/
3663 /* rfi (supervisor only) */
3664 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
)
3666 #if defined(CONFIG_USER_ONLY)
3667 GEN_EXCP_PRIVOPC(ctx
);
3669 /* Restore CPU state */
3670 if (unlikely(!ctx
->supervisor
)) {
3671 GEN_EXCP_PRIVOPC(ctx
);
3679 #if defined(TARGET_PPC64)
3680 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
)
3682 #if defined(CONFIG_USER_ONLY)
3683 GEN_EXCP_PRIVOPC(ctx
);
3685 /* Restore CPU state */
3686 if (unlikely(!ctx
->supervisor
)) {
3687 GEN_EXCP_PRIVOPC(ctx
);
3695 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
)
3697 #if defined(CONFIG_USER_ONLY)
3698 GEN_EXCP_PRIVOPC(ctx
);
3700 /* Restore CPU state */
3701 if (unlikely(ctx
->supervisor
<= 1)) {
3702 GEN_EXCP_PRIVOPC(ctx
);
3712 #if defined(CONFIG_USER_ONLY)
3713 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3715 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3717 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW
)
3721 lev
= (ctx
->opcode
>> 5) & 0x7F;
3722 GEN_EXCP(ctx
, POWERPC_SYSCALL
, lev
);
3727 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
)
3729 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
3730 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
3731 /* Update the nip since this might generate a trap exception */
3732 gen_update_nip(ctx
, ctx
->nip
);
3733 gen_op_tw(TO(ctx
->opcode
));
3737 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
3739 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
3740 tcg_gen_movi_tl(cpu_T
[1], SIMM(ctx
->opcode
));
3741 /* Update the nip since this might generate a trap exception */
3742 gen_update_nip(ctx
, ctx
->nip
);
3743 gen_op_tw(TO(ctx
->opcode
));
3746 #if defined(TARGET_PPC64)
3748 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
)
3750 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
3751 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
3752 /* Update the nip since this might generate a trap exception */
3753 gen_update_nip(ctx
, ctx
->nip
);
3754 gen_op_td(TO(ctx
->opcode
));
3758 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
)
3760 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
3761 tcg_gen_movi_tl(cpu_T
[1], SIMM(ctx
->opcode
));
3762 /* Update the nip since this might generate a trap exception */
3763 gen_update_nip(ctx
, ctx
->nip
);
3764 gen_op_td(TO(ctx
->opcode
));
3768 /*** Processor control ***/
3770 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
)
3772 tcg_gen_trunc_tl_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_xer
);
3773 tcg_gen_shri_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfD(ctx
->opcode
)], XER_CA
);
3774 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_SO
| 1 << XER_OV
| 1 << XER_CA
));
3778 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
)
3782 if (likely(ctx
->opcode
& 0x00100000)) {
3783 crm
= CRM(ctx
->opcode
);
3784 if (likely((crm
^ (crm
- 1)) == 0)) {
3786 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_crf
[7 - crn
]);
3789 gen_helper_load_cr(cpu_gpr
[rD(ctx
->opcode
)]);
3794 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
)
3796 #if defined(CONFIG_USER_ONLY)
3797 GEN_EXCP_PRIVREG(ctx
);
3799 if (unlikely(!ctx
->supervisor
)) {
3800 GEN_EXCP_PRIVREG(ctx
);
3804 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
3809 #define SPR_NOACCESS ((void *)(-1UL))
3811 static void spr_noaccess (void *opaque
, int sprn
)
3813 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
3814 printf("ERROR: try to access SPR %d !\n", sprn
);
3816 #define SPR_NOACCESS (&spr_noaccess)
3820 static always_inline
void gen_op_mfspr (DisasContext
*ctx
)
3822 void (*read_cb
)(void *opaque
, int sprn
);
3823 uint32_t sprn
= SPR(ctx
->opcode
);
3825 #if !defined(CONFIG_USER_ONLY)
3826 if (ctx
->supervisor
== 2)
3827 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
3828 else if (ctx
->supervisor
)
3829 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
3832 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
3833 if (likely(read_cb
!= NULL
)) {
3834 if (likely(read_cb
!= SPR_NOACCESS
)) {
3835 (*read_cb
)(ctx
, sprn
);
3836 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
3838 /* Privilege exception */
3839 /* This is a hack to avoid warnings when running Linux:
3840 * this OS breaks the PowerPC virtualisation model,
3841 * allowing userland application to read the PVR
3843 if (sprn
!= SPR_PVR
) {
3844 if (loglevel
!= 0) {
3845 fprintf(logfile
, "Trying to read privileged spr %d %03x at "
3846 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3848 printf("Trying to read privileged spr %d %03x at " ADDRX
"\n",
3849 sprn
, sprn
, ctx
->nip
);
3851 GEN_EXCP_PRIVREG(ctx
);
3855 if (loglevel
!= 0) {
3856 fprintf(logfile
, "Trying to read invalid spr %d %03x at "
3857 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3859 printf("Trying to read invalid spr %d %03x at " ADDRX
"\n",
3860 sprn
, sprn
, ctx
->nip
);
3861 GEN_EXCP(ctx
, POWERPC_EXCP_PROGRAM
,
3862 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_SPR
);
3866 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
)
3872 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
)
3878 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
)
3882 crm
= CRM(ctx
->opcode
);
3883 if (likely((ctx
->opcode
& 0x00100000) || (crm
^ (crm
- 1)) == 0)) {
3884 TCGv_i32 temp
= tcg_temp_new_i32();
3886 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
3887 tcg_gen_shri_i32(cpu_crf
[7 - crn
], temp
, crn
* 4);
3888 tcg_gen_andi_i32(cpu_crf
[7 - crn
], cpu_crf
[7 - crn
], 0xf);
3889 tcg_temp_free_i32(temp
);
3891 TCGv_i32 temp
= tcg_const_i32(crm
);
3892 gen_helper_store_cr(cpu_gpr
[rS(ctx
->opcode
)], temp
);
3893 tcg_temp_free_i32(temp
);
3898 #if defined(TARGET_PPC64)
3899 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
)
3901 #if defined(CONFIG_USER_ONLY)
3902 GEN_EXCP_PRIVREG(ctx
);
3904 if (unlikely(!ctx
->supervisor
)) {
3905 GEN_EXCP_PRIVREG(ctx
);
3908 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
3909 if (ctx
->opcode
& 0x00010000) {
3910 /* Special form that does not need any synchronisation */
3911 gen_op_update_riee();
3913 /* XXX: we need to update nip before the store
3914 * if we enter power saving mode, we will exit the loop
3915 * directly from ppc_store_msr
3917 gen_update_nip(ctx
, ctx
->nip
);
3919 /* Must stop the translation as machine state (may have) changed */
3920 /* Note that mtmsr is not always defined as context-synchronizing */
3921 ctx
->exception
= POWERPC_EXCP_STOP
;
3927 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC
)
3929 #if defined(CONFIG_USER_ONLY)
3930 GEN_EXCP_PRIVREG(ctx
);
3932 if (unlikely(!ctx
->supervisor
)) {
3933 GEN_EXCP_PRIVREG(ctx
);
3936 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
3937 if (ctx
->opcode
& 0x00010000) {
3938 /* Special form that does not need any synchronisation */
3939 gen_op_update_riee();
3941 /* XXX: we need to update nip before the store
3942 * if we enter power saving mode, we will exit the loop
3943 * directly from ppc_store_msr
3945 gen_update_nip(ctx
, ctx
->nip
);
3946 #if defined(TARGET_PPC64)
3948 gen_op_store_msr_32();
3952 /* Must stop the translation as machine state (may have) changed */
3953 /* Note that mtmsrd is not always defined as context-synchronizing */
3954 ctx
->exception
= POWERPC_EXCP_STOP
;
3960 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC
)
3962 void (*write_cb
)(void *opaque
, int sprn
);
3963 uint32_t sprn
= SPR(ctx
->opcode
);
3965 #if !defined(CONFIG_USER_ONLY)
3966 if (ctx
->supervisor
== 2)
3967 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
3968 else if (ctx
->supervisor
)
3969 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
3972 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
3973 if (likely(write_cb
!= NULL
)) {
3974 if (likely(write_cb
!= SPR_NOACCESS
)) {
3975 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
3976 (*write_cb
)(ctx
, sprn
);
3978 /* Privilege exception */
3979 if (loglevel
!= 0) {
3980 fprintf(logfile
, "Trying to write privileged spr %d %03x at "
3981 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3983 printf("Trying to write privileged spr %d %03x at " ADDRX
"\n",
3984 sprn
, sprn
, ctx
->nip
);
3985 GEN_EXCP_PRIVREG(ctx
);
3989 if (loglevel
!= 0) {
3990 fprintf(logfile
, "Trying to write invalid spr %d %03x at "
3991 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3993 printf("Trying to write invalid spr %d %03x at " ADDRX
"\n",
3994 sprn
, sprn
, ctx
->nip
);
3995 GEN_EXCP(ctx
, POWERPC_EXCP_PROGRAM
,
3996 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_SPR
);
4000 /*** Cache management ***/
4002 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
)
4004 /* XXX: specification says this is treated as a load by the MMU */
4005 TCGv t0
= tcg_temp_new();
4006 gen_addr_reg_index(t0
, ctx
);
4007 gen_qemu_ld8u(t0
, t0
, ctx
->mem_idx
);
4011 /* dcbi (Supervisor only) */
4012 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
)
4014 #if defined(CONFIG_USER_ONLY)
4015 GEN_EXCP_PRIVOPC(ctx
);
4018 if (unlikely(!ctx
->supervisor
)) {
4019 GEN_EXCP_PRIVOPC(ctx
);
4022 EA
= tcg_temp_new();
4023 gen_addr_reg_index(EA
, ctx
);
4024 val
= tcg_temp_new();
4025 /* XXX: specification says this should be treated as a store by the MMU */
4026 gen_qemu_ld8u(val
, EA
, ctx
->mem_idx
);
4027 gen_qemu_st8(val
, EA
, ctx
->mem_idx
);
4034 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
)
4036 /* XXX: specification say this is treated as a load by the MMU */
4037 TCGv t0
= tcg_temp_new();
4038 gen_addr_reg_index(t0
, ctx
);
4039 gen_qemu_ld8u(t0
, t0
, ctx
->mem_idx
);
4044 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE
)
4046 /* interpreted as no-op */
4047 /* XXX: specification say this is treated as a load by the MMU
4048 * but does not generate any exception
4053 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE
)
4055 /* interpreted as no-op */
4056 /* XXX: specification say this is treated as a load by the MMU
4057 * but does not generate any exception
4062 #define op_dcbz(n) (*gen_op_dcbz[n][ctx->mem_idx])()
4063 static GenOpFunc
*gen_op_dcbz
[4][NB_MEM_FUNCS
] = {
4064 /* 32 bytes cache line size */
4066 #define gen_op_dcbz_l32_le_raw gen_op_dcbz_l32_raw
4067 #define gen_op_dcbz_l32_le_user gen_op_dcbz_l32_user
4068 #define gen_op_dcbz_l32_le_kernel gen_op_dcbz_l32_kernel
4069 #define gen_op_dcbz_l32_le_hypv gen_op_dcbz_l32_hypv
4070 #define gen_op_dcbz_l32_le_64_raw gen_op_dcbz_l32_64_raw
4071 #define gen_op_dcbz_l32_le_64_user gen_op_dcbz_l32_64_user
4072 #define gen_op_dcbz_l32_le_64_kernel gen_op_dcbz_l32_64_kernel
4073 #define gen_op_dcbz_l32_le_64_hypv gen_op_dcbz_l32_64_hypv
4074 GEN_MEM_FUNCS(dcbz_l32
),
4076 /* 64 bytes cache line size */
4078 #define gen_op_dcbz_l64_le_raw gen_op_dcbz_l64_raw
4079 #define gen_op_dcbz_l64_le_user gen_op_dcbz_l64_user
4080 #define gen_op_dcbz_l64_le_kernel gen_op_dcbz_l64_kernel
4081 #define gen_op_dcbz_l64_le_hypv gen_op_dcbz_l64_hypv
4082 #define gen_op_dcbz_l64_le_64_raw gen_op_dcbz_l64_64_raw
4083 #define gen_op_dcbz_l64_le_64_user gen_op_dcbz_l64_64_user
4084 #define gen_op_dcbz_l64_le_64_kernel gen_op_dcbz_l64_64_kernel
4085 #define gen_op_dcbz_l64_le_64_hypv gen_op_dcbz_l64_64_hypv
4086 GEN_MEM_FUNCS(dcbz_l64
),
4088 /* 128 bytes cache line size */
4090 #define gen_op_dcbz_l128_le_raw gen_op_dcbz_l128_raw
4091 #define gen_op_dcbz_l128_le_user gen_op_dcbz_l128_user
4092 #define gen_op_dcbz_l128_le_kernel gen_op_dcbz_l128_kernel
4093 #define gen_op_dcbz_l128_le_hypv gen_op_dcbz_l128_hypv
4094 #define gen_op_dcbz_l128_le_64_raw gen_op_dcbz_l128_64_raw
4095 #define gen_op_dcbz_l128_le_64_user gen_op_dcbz_l128_64_user
4096 #define gen_op_dcbz_l128_le_64_kernel gen_op_dcbz_l128_64_kernel
4097 #define gen_op_dcbz_l128_le_64_hypv gen_op_dcbz_l128_64_hypv
4098 GEN_MEM_FUNCS(dcbz_l128
),
4100 /* tunable cache line size */
4102 #define gen_op_dcbz_le_raw gen_op_dcbz_raw
4103 #define gen_op_dcbz_le_user gen_op_dcbz_user
4104 #define gen_op_dcbz_le_kernel gen_op_dcbz_kernel
4105 #define gen_op_dcbz_le_hypv gen_op_dcbz_hypv
4106 #define gen_op_dcbz_le_64_raw gen_op_dcbz_64_raw
4107 #define gen_op_dcbz_le_64_user gen_op_dcbz_64_user
4108 #define gen_op_dcbz_le_64_kernel gen_op_dcbz_64_kernel
4109 #define gen_op_dcbz_le_64_hypv gen_op_dcbz_64_hypv
4110 GEN_MEM_FUNCS(dcbz
),
4114 static always_inline
void handler_dcbz (DisasContext
*ctx
,
4115 int dcache_line_size
)
4119 switch (dcache_line_size
) {
4136 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE_DCBZ
)
4138 gen_addr_reg_index(cpu_T
[0], ctx
);
4139 handler_dcbz(ctx
, ctx
->dcache_line_size
);
4140 gen_op_check_reservation();
4143 GEN_HANDLER2(dcbz_970
, "dcbz", 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZT
)
4145 gen_addr_reg_index(cpu_T
[0], ctx
);
4146 if (ctx
->opcode
& 0x00200000)
4147 handler_dcbz(ctx
, ctx
->dcache_line_size
);
4149 handler_dcbz(ctx
, -1);
4150 gen_op_check_reservation();
4154 #define op_icbi() (*gen_op_icbi[ctx->mem_idx])()
4155 #define gen_op_icbi_le_raw gen_op_icbi_raw
4156 #define gen_op_icbi_le_user gen_op_icbi_user
4157 #define gen_op_icbi_le_kernel gen_op_icbi_kernel
4158 #define gen_op_icbi_le_hypv gen_op_icbi_hypv
4159 #define gen_op_icbi_le_64_raw gen_op_icbi_64_raw
4160 #define gen_op_icbi_le_64_user gen_op_icbi_64_user
4161 #define gen_op_icbi_le_64_kernel gen_op_icbi_64_kernel
4162 #define gen_op_icbi_le_64_hypv gen_op_icbi_64_hypv
4163 static GenOpFunc
*gen_op_icbi
[NB_MEM_FUNCS
] = {
4164 GEN_MEM_FUNCS(icbi
),
4167 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
)
4169 /* NIP cannot be restored if the memory exception comes from an helper */
4170 gen_update_nip(ctx
, ctx
->nip
- 4);
4171 gen_addr_reg_index(cpu_T
[0], ctx
);
4177 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
)
4179 /* interpreted as no-op */
4180 /* XXX: specification say this is treated as a store by the MMU
4181 * but does not generate any exception
4185 /*** Segment register manipulation ***/
4186 /* Supervisor only: */
4188 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
)
4190 #if defined(CONFIG_USER_ONLY)
4191 GEN_EXCP_PRIVREG(ctx
);
4193 if (unlikely(!ctx
->supervisor
)) {
4194 GEN_EXCP_PRIVREG(ctx
);
4197 tcg_gen_movi_tl(cpu_T
[1], SR(ctx
->opcode
));
4199 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4204 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
)
4206 #if defined(CONFIG_USER_ONLY)
4207 GEN_EXCP_PRIVREG(ctx
);
4209 if (unlikely(!ctx
->supervisor
)) {
4210 GEN_EXCP_PRIVREG(ctx
);
4213 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4216 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4221 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
)
4223 #if defined(CONFIG_USER_ONLY)
4224 GEN_EXCP_PRIVREG(ctx
);
4226 if (unlikely(!ctx
->supervisor
)) {
4227 GEN_EXCP_PRIVREG(ctx
);
4230 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4231 tcg_gen_movi_tl(cpu_T
[1], SR(ctx
->opcode
));
4237 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
)
4239 #if defined(CONFIG_USER_ONLY)
4240 GEN_EXCP_PRIVREG(ctx
);
4242 if (unlikely(!ctx
->supervisor
)) {
4243 GEN_EXCP_PRIVREG(ctx
);
4246 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4247 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4253 #if defined(TARGET_PPC64)
4254 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
4256 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
)
4258 #if defined(CONFIG_USER_ONLY)
4259 GEN_EXCP_PRIVREG(ctx
);
4261 if (unlikely(!ctx
->supervisor
)) {
4262 GEN_EXCP_PRIVREG(ctx
);
4265 tcg_gen_movi_tl(cpu_T
[1], SR(ctx
->opcode
));
4267 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4272 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
4275 #if defined(CONFIG_USER_ONLY)
4276 GEN_EXCP_PRIVREG(ctx
);
4278 if (unlikely(!ctx
->supervisor
)) {
4279 GEN_EXCP_PRIVREG(ctx
);
4282 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4285 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4290 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
)
4292 #if defined(CONFIG_USER_ONLY)
4293 GEN_EXCP_PRIVREG(ctx
);
4295 if (unlikely(!ctx
->supervisor
)) {
4296 GEN_EXCP_PRIVREG(ctx
);
4299 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4300 tcg_gen_movi_tl(cpu_T
[1], SR(ctx
->opcode
));
4306 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
4309 #if defined(CONFIG_USER_ONLY)
4310 GEN_EXCP_PRIVREG(ctx
);
4312 if (unlikely(!ctx
->supervisor
)) {
4313 GEN_EXCP_PRIVREG(ctx
);
4316 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4317 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4322 #endif /* defined(TARGET_PPC64) */
4324 /*** Lookaside buffer management ***/
4325 /* Optional & supervisor only: */
4327 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
)
4329 #if defined(CONFIG_USER_ONLY)
4330 GEN_EXCP_PRIVOPC(ctx
);
4332 if (unlikely(!ctx
->supervisor
)) {
4333 GEN_EXCP_PRIVOPC(ctx
);
4341 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE
)
4343 #if defined(CONFIG_USER_ONLY)
4344 GEN_EXCP_PRIVOPC(ctx
);
4346 if (unlikely(!ctx
->supervisor
)) {
4347 GEN_EXCP_PRIVOPC(ctx
);
4350 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rB(ctx
->opcode
)]);
4351 #if defined(TARGET_PPC64)
4361 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
)
4363 #if defined(CONFIG_USER_ONLY)
4364 GEN_EXCP_PRIVOPC(ctx
);
4366 if (unlikely(!ctx
->supervisor
)) {
4367 GEN_EXCP_PRIVOPC(ctx
);
4370 /* This has no effect: it should ensure that all previous
4371 * tlbie have completed
4377 #if defined(TARGET_PPC64)
4379 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI
)
4381 #if defined(CONFIG_USER_ONLY)
4382 GEN_EXCP_PRIVOPC(ctx
);
4384 if (unlikely(!ctx
->supervisor
)) {
4385 GEN_EXCP_PRIVOPC(ctx
);
4393 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
)
4395 #if defined(CONFIG_USER_ONLY)
4396 GEN_EXCP_PRIVOPC(ctx
);
4398 if (unlikely(!ctx
->supervisor
)) {
4399 GEN_EXCP_PRIVOPC(ctx
);
4402 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rB(ctx
->opcode
)]);
4408 /*** External control ***/
4410 #define op_eciwx() (*gen_op_eciwx[ctx->mem_idx])()
4411 #define op_ecowx() (*gen_op_ecowx[ctx->mem_idx])()
4412 static GenOpFunc
*gen_op_eciwx
[NB_MEM_FUNCS
] = {
4413 GEN_MEM_FUNCS(eciwx
),
4415 static GenOpFunc
*gen_op_ecowx
[NB_MEM_FUNCS
] = {
4416 GEN_MEM_FUNCS(ecowx
),
4420 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
)
4422 /* Should check EAR[E] & alignment ! */
4423 gen_addr_reg_index(cpu_T
[0], ctx
);
4425 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4429 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
)
4431 /* Should check EAR[E] & alignment ! */
4432 gen_addr_reg_index(cpu_T
[0], ctx
);
4433 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
4437 /* PowerPC 601 specific instructions */
4439 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
)
4441 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4443 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4444 if (unlikely(Rc(ctx
->opcode
) != 0))
4445 gen_set_Rc0(ctx
, cpu_T
[0]);
4449 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
)
4451 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4452 gen_op_POWER_abso();
4453 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4454 if (unlikely(Rc(ctx
->opcode
) != 0))
4455 gen_set_Rc0(ctx
, cpu_T
[0]);
4459 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
)
4461 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4462 gen_op_POWER_clcs();
4463 /* Rc=1 sets CR0 to an undefined state */
4464 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4468 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
)
4470 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4471 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4473 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4474 if (unlikely(Rc(ctx
->opcode
) != 0))
4475 gen_set_Rc0(ctx
, cpu_T
[0]);
4479 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
)
4481 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4482 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4483 gen_op_POWER_divo();
4484 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4485 if (unlikely(Rc(ctx
->opcode
) != 0))
4486 gen_set_Rc0(ctx
, cpu_T
[0]);
4490 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
)
4492 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4493 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4494 gen_op_POWER_divs();
4495 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4496 if (unlikely(Rc(ctx
->opcode
) != 0))
4497 gen_set_Rc0(ctx
, cpu_T
[0]);
4500 /* divso - divso. */
4501 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
)
4503 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4504 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4505 gen_op_POWER_divso();
4506 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4507 if (unlikely(Rc(ctx
->opcode
) != 0))
4508 gen_set_Rc0(ctx
, cpu_T
[0]);
4512 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
)
4514 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4515 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4517 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4518 if (unlikely(Rc(ctx
->opcode
) != 0))
4519 gen_set_Rc0(ctx
, cpu_T
[0]);
4523 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
)
4525 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4526 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4527 gen_op_POWER_dozo();
4528 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4529 if (unlikely(Rc(ctx
->opcode
) != 0))
4530 gen_set_Rc0(ctx
, cpu_T
[0]);
4534 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
)
4536 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4537 tcg_gen_movi_tl(cpu_T
[1], SIMM(ctx
->opcode
));
4539 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4542 /* As lscbx load from memory byte after byte, it's always endian safe.
4543 * Original POWER is 32 bits only, define 64 bits ops as 32 bits ones
4545 #define op_POWER_lscbx(start, ra, rb) \
4546 (*gen_op_POWER_lscbx[ctx->mem_idx])(start, ra, rb)
4547 #define gen_op_POWER_lscbx_64_raw gen_op_POWER_lscbx_raw
4548 #define gen_op_POWER_lscbx_64_user gen_op_POWER_lscbx_user
4549 #define gen_op_POWER_lscbx_64_kernel gen_op_POWER_lscbx_kernel
4550 #define gen_op_POWER_lscbx_64_hypv gen_op_POWER_lscbx_hypv
4551 #define gen_op_POWER_lscbx_le_raw gen_op_POWER_lscbx_raw
4552 #define gen_op_POWER_lscbx_le_user gen_op_POWER_lscbx_user
4553 #define gen_op_POWER_lscbx_le_kernel gen_op_POWER_lscbx_kernel
4554 #define gen_op_POWER_lscbx_le_hypv gen_op_POWER_lscbx_hypv
4555 #define gen_op_POWER_lscbx_le_64_raw gen_op_POWER_lscbx_raw
4556 #define gen_op_POWER_lscbx_le_64_user gen_op_POWER_lscbx_user
4557 #define gen_op_POWER_lscbx_le_64_kernel gen_op_POWER_lscbx_kernel
4558 #define gen_op_POWER_lscbx_le_64_hypv gen_op_POWER_lscbx_hypv
4559 static GenOpFunc3
*gen_op_POWER_lscbx
[NB_MEM_FUNCS
] = {
4560 GEN_MEM_FUNCS(POWER_lscbx
),
4563 /* lscbx - lscbx. */
4564 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
)
4566 int ra
= rA(ctx
->opcode
);
4567 int rb
= rB(ctx
->opcode
);
4569 gen_addr_reg_index(cpu_T
[0], ctx
);
4573 /* NIP cannot be restored if the memory exception comes from an helper */
4574 gen_update_nip(ctx
, ctx
->nip
- 4);
4575 tcg_gen_andi_tl(cpu_T
[1], cpu_xer
, 0x7F);
4576 tcg_gen_shri_tl(cpu_T
[2], cpu_xer
, XER_CMP
);
4577 tcg_gen_andi_tl(cpu_T
[2], cpu_T
[2], 0xFF);
4578 op_POWER_lscbx(rD(ctx
->opcode
), ra
, rb
);
4579 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~0x7F);
4580 tcg_gen_or_tl(cpu_xer
, cpu_xer
, cpu_T
[0]);
4581 if (unlikely(Rc(ctx
->opcode
) != 0))
4582 gen_set_Rc0(ctx
, cpu_T
[0]);
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 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4871 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4875 /* 602 - 603 - G2 TLB management */
4877 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
)
4879 #if defined(CONFIG_USER_ONLY)
4880 GEN_EXCP_PRIVOPC(ctx
);
4882 if (unlikely(!ctx
->supervisor
)) {
4883 GEN_EXCP_PRIVOPC(ctx
);
4886 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rB(ctx
->opcode
)]);
4892 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
)
4894 #if defined(CONFIG_USER_ONLY)
4895 GEN_EXCP_PRIVOPC(ctx
);
4897 if (unlikely(!ctx
->supervisor
)) {
4898 GEN_EXCP_PRIVOPC(ctx
);
4901 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rB(ctx
->opcode
)]);
4906 /* 74xx TLB management */
4908 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
)
4910 #if defined(CONFIG_USER_ONLY)
4911 GEN_EXCP_PRIVOPC(ctx
);
4913 if (unlikely(!ctx
->supervisor
)) {
4914 GEN_EXCP_PRIVOPC(ctx
);
4917 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rB(ctx
->opcode
)]);
4918 gen_op_74xx_tlbld();
4923 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
)
4925 #if defined(CONFIG_USER_ONLY)
4926 GEN_EXCP_PRIVOPC(ctx
);
4928 if (unlikely(!ctx
->supervisor
)) {
4929 GEN_EXCP_PRIVOPC(ctx
);
4932 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rB(ctx
->opcode
)]);
4933 gen_op_74xx_tlbli();
4937 /* POWER instructions not in PowerPC 601 */
4939 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
)
4941 /* Cache line flush: implemented as no-op */
4945 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
)
4947 /* Cache line invalidate: privileged and treated as no-op */
4948 #if defined(CONFIG_USER_ONLY)
4949 GEN_EXCP_PRIVOPC(ctx
);
4951 if (unlikely(!ctx
->supervisor
)) {
4952 GEN_EXCP_PRIVOPC(ctx
);
4959 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
)
4961 /* Data cache line store: treated as no-op */
4964 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
)
4966 #if defined(CONFIG_USER_ONLY)
4967 GEN_EXCP_PRIVOPC(ctx
);
4969 if (unlikely(!ctx
->supervisor
)) {
4970 GEN_EXCP_PRIVOPC(ctx
);
4973 int ra
= rA(ctx
->opcode
);
4974 int rd
= rD(ctx
->opcode
);
4976 gen_addr_reg_index(cpu_T
[0], ctx
);
4977 gen_op_POWER_mfsri();
4978 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_T
[0]);
4979 if (ra
!= 0 && ra
!= rd
)
4980 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_T
[1]);
4984 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
)
4986 #if defined(CONFIG_USER_ONLY)
4987 GEN_EXCP_PRIVOPC(ctx
);
4989 if (unlikely(!ctx
->supervisor
)) {
4990 GEN_EXCP_PRIVOPC(ctx
);
4993 gen_addr_reg_index(cpu_T
[0], ctx
);
4995 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4999 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
)
5001 #if defined(CONFIG_USER_ONLY)
5002 GEN_EXCP_PRIVOPC(ctx
);
5004 if (unlikely(!ctx
->supervisor
)) {
5005 GEN_EXCP_PRIVOPC(ctx
);
5008 gen_op_POWER_rfsvc();
5013 /* svc is not implemented for now */
5015 /* POWER2 specific instructions */
5016 /* Quad manipulation (load/store two floats at a time) */
5017 /* Original POWER2 is 32 bits only, define 64 bits ops as 32 bits ones */
5018 #define op_POWER2_lfq() (*gen_op_POWER2_lfq[ctx->mem_idx])()
5019 #define op_POWER2_stfq() (*gen_op_POWER2_stfq[ctx->mem_idx])()
5020 #define gen_op_POWER2_lfq_64_raw gen_op_POWER2_lfq_raw
5021 #define gen_op_POWER2_lfq_64_user gen_op_POWER2_lfq_user
5022 #define gen_op_POWER2_lfq_64_kernel gen_op_POWER2_lfq_kernel
5023 #define gen_op_POWER2_lfq_64_hypv gen_op_POWER2_lfq_hypv
5024 #define gen_op_POWER2_lfq_le_64_raw gen_op_POWER2_lfq_le_raw
5025 #define gen_op_POWER2_lfq_le_64_user gen_op_POWER2_lfq_le_user
5026 #define gen_op_POWER2_lfq_le_64_kernel gen_op_POWER2_lfq_le_kernel
5027 #define gen_op_POWER2_lfq_le_64_hypv gen_op_POWER2_lfq_le_hypv
5028 #define gen_op_POWER2_stfq_64_raw gen_op_POWER2_stfq_raw
5029 #define gen_op_POWER2_stfq_64_user gen_op_POWER2_stfq_user
5030 #define gen_op_POWER2_stfq_64_kernel gen_op_POWER2_stfq_kernel
5031 #define gen_op_POWER2_stfq_64_hypv gen_op_POWER2_stfq_hypv
5032 #define gen_op_POWER2_stfq_le_64_raw gen_op_POWER2_stfq_le_raw
5033 #define gen_op_POWER2_stfq_le_64_user gen_op_POWER2_stfq_le_user
5034 #define gen_op_POWER2_stfq_le_64_kernel gen_op_POWER2_stfq_le_kernel
5035 #define gen_op_POWER2_stfq_le_64_hypv gen_op_POWER2_stfq_le_hypv
5036 static GenOpFunc
*gen_op_POWER2_lfq
[NB_MEM_FUNCS
] = {
5037 GEN_MEM_FUNCS(POWER2_lfq
),
5039 static GenOpFunc
*gen_op_POWER2_stfq
[NB_MEM_FUNCS
] = {
5040 GEN_MEM_FUNCS(POWER2_stfq
),
5044 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
5046 /* NIP cannot be restored if the memory exception comes from an helper */
5047 gen_update_nip(ctx
, ctx
->nip
- 4);
5048 gen_addr_imm_index(cpu_T
[0], ctx
, 0);
5050 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_FT
[0]);
5051 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
) + 1], cpu_FT
[1]);
5055 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
5057 int ra
= rA(ctx
->opcode
);
5059 /* NIP cannot be restored if the memory exception comes from an helper */
5060 gen_update_nip(ctx
, ctx
->nip
- 4);
5061 gen_addr_imm_index(cpu_T
[0], ctx
, 0);
5063 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_FT
[0]);
5064 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
) + 1], cpu_FT
[1]);
5066 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_T
[0]);
5070 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
)
5072 int ra
= rA(ctx
->opcode
);
5074 /* NIP cannot be restored if the memory exception comes from an helper */
5075 gen_update_nip(ctx
, ctx
->nip
- 4);
5076 gen_addr_reg_index(cpu_T
[0], ctx
);
5078 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_FT
[0]);
5079 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
) + 1], cpu_FT
[1]);
5081 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_T
[0]);
5085 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
)
5087 /* NIP cannot be restored if the memory exception comes from an helper */
5088 gen_update_nip(ctx
, ctx
->nip
- 4);
5089 gen_addr_reg_index(cpu_T
[0], ctx
);
5091 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_FT
[0]);
5092 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
) + 1], cpu_FT
[1]);
5096 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
5098 /* NIP cannot be restored if the memory exception comes from an helper */
5099 gen_update_nip(ctx
, ctx
->nip
- 4);
5100 gen_addr_imm_index(cpu_T
[0], ctx
, 0);
5101 tcg_gen_mov_i64(cpu_FT
[0], cpu_fpr
[rS(ctx
->opcode
)]);
5102 tcg_gen_mov_i64(cpu_FT
[1], cpu_fpr
[rS(ctx
->opcode
) + 1]);
5107 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
5109 int ra
= rA(ctx
->opcode
);
5111 /* NIP cannot be restored if the memory exception comes from an helper */
5112 gen_update_nip(ctx
, ctx
->nip
- 4);
5113 gen_addr_imm_index(cpu_T
[0], ctx
, 0);
5114 tcg_gen_mov_i64(cpu_FT
[0], cpu_fpr
[rS(ctx
->opcode
)]);
5115 tcg_gen_mov_i64(cpu_FT
[1], cpu_fpr
[rS(ctx
->opcode
) + 1]);
5118 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_T
[0]);
5122 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
)
5124 int ra
= rA(ctx
->opcode
);
5126 /* NIP cannot be restored if the memory exception comes from an helper */
5127 gen_update_nip(ctx
, ctx
->nip
- 4);
5128 gen_addr_reg_index(cpu_T
[0], ctx
);
5129 tcg_gen_mov_i64(cpu_FT
[0], cpu_fpr
[rS(ctx
->opcode
)]);
5130 tcg_gen_mov_i64(cpu_FT
[1], cpu_fpr
[rS(ctx
->opcode
) + 1]);
5133 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_T
[0]);
5137 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
)
5139 /* NIP cannot be restored if the memory exception comes from an helper */
5140 gen_update_nip(ctx
, ctx
->nip
- 4);
5141 gen_addr_reg_index(cpu_T
[0], ctx
);
5142 tcg_gen_mov_i64(cpu_FT
[0], cpu_fpr
[rS(ctx
->opcode
)]);
5143 tcg_gen_mov_i64(cpu_FT
[1], cpu_fpr
[rS(ctx
->opcode
) + 1]);
5147 /* BookE specific instructions */
5148 /* XXX: not implemented on 440 ? */
5149 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
)
5152 GEN_EXCP_INVAL(ctx
);
5155 /* XXX: not implemented on 440 ? */
5156 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
)
5158 #if defined(CONFIG_USER_ONLY)
5159 GEN_EXCP_PRIVOPC(ctx
);
5161 if (unlikely(!ctx
->supervisor
)) {
5162 GEN_EXCP_PRIVOPC(ctx
);
5165 gen_addr_reg_index(cpu_T
[0], ctx
);
5166 /* Use the same micro-ops as for tlbie */
5167 #if defined(TARGET_PPC64)
5176 /* All 405 MAC instructions are translated here */
5177 static always_inline
void gen_405_mulladd_insn (DisasContext
*ctx
,
5179 int ra
, int rb
, int rt
, int Rc
)
5183 t0
= tcg_temp_local_new();
5184 t1
= tcg_temp_local_new();
5186 switch (opc3
& 0x0D) {
5188 /* macchw - macchw. - macchwo - macchwo. */
5189 /* macchws - macchws. - macchwso - macchwso. */
5190 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5191 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5192 /* mulchw - mulchw. */
5193 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5194 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5195 tcg_gen_ext16s_tl(t1
, t1
);
5198 /* macchwu - macchwu. - macchwuo - macchwuo. */
5199 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5200 /* mulchwu - mulchwu. */
5201 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5202 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5203 tcg_gen_ext16u_tl(t1
, t1
);
5206 /* machhw - machhw. - machhwo - machhwo. */
5207 /* machhws - machhws. - machhwso - machhwso. */
5208 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5209 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5210 /* mulhhw - mulhhw. */
5211 tcg_gen_sari_tl(t0
, cpu_gpr
[ra
], 16);
5212 tcg_gen_ext16s_tl(t0
, t0
);
5213 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5214 tcg_gen_ext16s_tl(t1
, t1
);
5217 /* machhwu - machhwu. - machhwuo - machhwuo. */
5218 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5219 /* mulhhwu - mulhhwu. */
5220 tcg_gen_shri_tl(t0
, cpu_gpr
[ra
], 16);
5221 tcg_gen_ext16u_tl(t0
, t0
);
5222 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5223 tcg_gen_ext16u_tl(t1
, t1
);
5226 /* maclhw - maclhw. - maclhwo - maclhwo. */
5227 /* maclhws - maclhws. - maclhwso - maclhwso. */
5228 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5229 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5230 /* mullhw - mullhw. */
5231 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5232 tcg_gen_ext16s_tl(t1
, cpu_gpr
[rb
]);
5235 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5236 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5237 /* mullhwu - mullhwu. */
5238 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5239 tcg_gen_ext16u_tl(t1
, cpu_gpr
[rb
]);
5243 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5244 tcg_gen_mul_tl(t1
, t0
, t1
);
5246 /* nmultiply-and-accumulate (0x0E) */
5247 tcg_gen_sub_tl(t0
, cpu_gpr
[rt
], t1
);
5249 /* multiply-and-accumulate (0x0C) */
5250 tcg_gen_add_tl(t0
, cpu_gpr
[rt
], t1
);
5254 /* Check overflow and/or saturate */
5255 int l1
= gen_new_label();
5258 /* Start with XER OV disabled, the most likely case */
5259 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~(1 << XER_OV
));
5263 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t1
);
5264 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
5265 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t0
);
5266 tcg_gen_brcondi_tl(TCG_COND_LT
, t1
, 0, l1
);
5269 tcg_gen_sari_tl(t0
, cpu_gpr
[rt
], 31);
5270 tcg_gen_xori_tl(t0
, t0
, 0x7fffffff);
5274 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
5277 tcg_gen_movi_tl(t0
, UINT32_MAX
);
5281 /* Check overflow */
5282 tcg_gen_ori_tl(cpu_xer
, cpu_xer
, (1 << XER_OV
) | (1 << XER_SO
));
5285 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
5288 tcg_gen_mul_tl(cpu_gpr
[rt
], t0
, t1
);
5292 if (unlikely(Rc
) != 0) {
5294 gen_set_Rc0(ctx
, cpu_gpr
[rt
]);
5298 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5299 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC) \
5301 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5302 rD(ctx->opcode), Rc(ctx->opcode)); \
5305 /* macchw - macchw. */
5306 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
5307 /* macchwo - macchwo. */
5308 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
5309 /* macchws - macchws. */
5310 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
5311 /* macchwso - macchwso. */
5312 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
5313 /* macchwsu - macchwsu. */
5314 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
5315 /* macchwsuo - macchwsuo. */
5316 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
5317 /* macchwu - macchwu. */
5318 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
5319 /* macchwuo - macchwuo. */
5320 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
5321 /* machhw - machhw. */
5322 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
5323 /* machhwo - machhwo. */
5324 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
5325 /* machhws - machhws. */
5326 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
5327 /* machhwso - machhwso. */
5328 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
5329 /* machhwsu - machhwsu. */
5330 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
5331 /* machhwsuo - machhwsuo. */
5332 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
5333 /* machhwu - machhwu. */
5334 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
5335 /* machhwuo - machhwuo. */
5336 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
5337 /* maclhw - maclhw. */
5338 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
5339 /* maclhwo - maclhwo. */
5340 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
5341 /* maclhws - maclhws. */
5342 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
5343 /* maclhwso - maclhwso. */
5344 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
5345 /* maclhwu - maclhwu. */
5346 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
5347 /* maclhwuo - maclhwuo. */
5348 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
5349 /* maclhwsu - maclhwsu. */
5350 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
5351 /* maclhwsuo - maclhwsuo. */
5352 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
5353 /* nmacchw - nmacchw. */
5354 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
5355 /* nmacchwo - nmacchwo. */
5356 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
5357 /* nmacchws - nmacchws. */
5358 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
5359 /* nmacchwso - nmacchwso. */
5360 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
5361 /* nmachhw - nmachhw. */
5362 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
5363 /* nmachhwo - nmachhwo. */
5364 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
5365 /* nmachhws - nmachhws. */
5366 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
5367 /* nmachhwso - nmachhwso. */
5368 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
5369 /* nmaclhw - nmaclhw. */
5370 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
5371 /* nmaclhwo - nmaclhwo. */
5372 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
5373 /* nmaclhws - nmaclhws. */
5374 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
5375 /* nmaclhwso - nmaclhwso. */
5376 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
5378 /* mulchw - mulchw. */
5379 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
5380 /* mulchwu - mulchwu. */
5381 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
5382 /* mulhhw - mulhhw. */
5383 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
5384 /* mulhhwu - mulhhwu. */
5385 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
5386 /* mullhw - mullhw. */
5387 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
5388 /* mullhwu - mullhwu. */
5389 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
5392 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
)
5394 #if defined(CONFIG_USER_ONLY)
5395 GEN_EXCP_PRIVREG(ctx
);
5397 uint32_t dcrn
= SPR(ctx
->opcode
);
5399 if (unlikely(!ctx
->supervisor
)) {
5400 GEN_EXCP_PRIVREG(ctx
);
5403 tcg_gen_movi_tl(cpu_T
[0], dcrn
);
5405 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
5410 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
)
5412 #if defined(CONFIG_USER_ONLY)
5413 GEN_EXCP_PRIVREG(ctx
);
5415 uint32_t dcrn
= SPR(ctx
->opcode
);
5417 if (unlikely(!ctx
->supervisor
)) {
5418 GEN_EXCP_PRIVREG(ctx
);
5421 tcg_gen_movi_tl(cpu_T
[0], dcrn
);
5422 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
5428 /* XXX: not implemented on 440 ? */
5429 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
)
5431 #if defined(CONFIG_USER_ONLY)
5432 GEN_EXCP_PRIVREG(ctx
);
5434 if (unlikely(!ctx
->supervisor
)) {
5435 GEN_EXCP_PRIVREG(ctx
);
5438 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5440 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
5441 /* Note: Rc update flag set leads to undefined state of Rc0 */
5446 /* XXX: not implemented on 440 ? */
5447 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
)
5449 #if defined(CONFIG_USER_ONLY)
5450 GEN_EXCP_PRIVREG(ctx
);
5452 if (unlikely(!ctx
->supervisor
)) {
5453 GEN_EXCP_PRIVREG(ctx
);
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 /* mfdcrux (PPC 460) : user-mode access to DCR */
5464 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
)
5466 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5468 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
5469 /* Note: Rc update flag set leads to undefined state of Rc0 */
5472 /* mtdcrux (PPC 460) : user-mode access to DCR */
5473 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
)
5475 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5476 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
5478 /* Note: Rc update flag set leads to undefined state of Rc0 */
5482 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
)
5484 #if defined(CONFIG_USER_ONLY)
5485 GEN_EXCP_PRIVOPC(ctx
);
5487 if (unlikely(!ctx
->supervisor
)) {
5488 GEN_EXCP_PRIVOPC(ctx
);
5491 /* interpreted as no-op */
5496 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
)
5498 #if defined(CONFIG_USER_ONLY)
5499 GEN_EXCP_PRIVOPC(ctx
);
5502 if (unlikely(!ctx
->supervisor
)) {
5503 GEN_EXCP_PRIVOPC(ctx
);
5506 EA
= tcg_temp_new();
5507 gen_addr_reg_index(EA
, ctx
);
5508 val
= tcg_temp_new();
5509 gen_qemu_ld32u(val
, EA
, ctx
->mem_idx
);
5511 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], EA
);
5517 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
)
5519 /* interpreted as no-op */
5520 /* XXX: specification say this is treated as a load by the MMU
5521 * but does not generate any exception
5526 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
)
5528 #if defined(CONFIG_USER_ONLY)
5529 GEN_EXCP_PRIVOPC(ctx
);
5531 if (unlikely(!ctx
->supervisor
)) {
5532 GEN_EXCP_PRIVOPC(ctx
);
5535 /* interpreted as no-op */
5540 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
)
5542 #if defined(CONFIG_USER_ONLY)
5543 GEN_EXCP_PRIVOPC(ctx
);
5545 if (unlikely(!ctx
->supervisor
)) {
5546 GEN_EXCP_PRIVOPC(ctx
);
5549 /* interpreted as no-op */
5553 /* rfci (supervisor only) */
5554 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
)
5556 #if defined(CONFIG_USER_ONLY)
5557 GEN_EXCP_PRIVOPC(ctx
);
5559 if (unlikely(!ctx
->supervisor
)) {
5560 GEN_EXCP_PRIVOPC(ctx
);
5563 /* Restore CPU state */
5569 GEN_HANDLER(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
)
5571 #if defined(CONFIG_USER_ONLY)
5572 GEN_EXCP_PRIVOPC(ctx
);
5574 if (unlikely(!ctx
->supervisor
)) {
5575 GEN_EXCP_PRIVOPC(ctx
);
5578 /* Restore CPU state */
5584 /* BookE specific */
5585 /* XXX: not implemented on 440 ? */
5586 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
)
5588 #if defined(CONFIG_USER_ONLY)
5589 GEN_EXCP_PRIVOPC(ctx
);
5591 if (unlikely(!ctx
->supervisor
)) {
5592 GEN_EXCP_PRIVOPC(ctx
);
5595 /* Restore CPU state */
5601 /* XXX: not implemented on 440 ? */
5602 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
)
5604 #if defined(CONFIG_USER_ONLY)
5605 GEN_EXCP_PRIVOPC(ctx
);
5607 if (unlikely(!ctx
->supervisor
)) {
5608 GEN_EXCP_PRIVOPC(ctx
);
5611 /* Restore CPU state */
5617 /* TLB management - PowerPC 405 implementation */
5619 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
)
5621 #if defined(CONFIG_USER_ONLY)
5622 GEN_EXCP_PRIVOPC(ctx
);
5624 if (unlikely(!ctx
->supervisor
)) {
5625 GEN_EXCP_PRIVOPC(ctx
);
5628 switch (rB(ctx
->opcode
)) {
5630 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5631 gen_op_4xx_tlbre_hi();
5632 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
5635 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5636 gen_op_4xx_tlbre_lo();
5637 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
5640 GEN_EXCP_INVAL(ctx
);
5646 /* tlbsx - tlbsx. */
5647 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, 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 gen_addr_reg_index(cpu_T
[0], ctx
);
5658 if (Rc(ctx
->opcode
))
5659 gen_op_4xx_tlbsx_check();
5660 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
5665 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
)
5667 #if defined(CONFIG_USER_ONLY)
5668 GEN_EXCP_PRIVOPC(ctx
);
5670 if (unlikely(!ctx
->supervisor
)) {
5671 GEN_EXCP_PRIVOPC(ctx
);
5674 switch (rB(ctx
->opcode
)) {
5676 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5677 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
5678 gen_op_4xx_tlbwe_hi();
5681 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5682 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
5683 gen_op_4xx_tlbwe_lo();
5686 GEN_EXCP_INVAL(ctx
);
5692 /* TLB management - PowerPC 440 implementation */
5694 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
)
5696 #if defined(CONFIG_USER_ONLY)
5697 GEN_EXCP_PRIVOPC(ctx
);
5699 if (unlikely(!ctx
->supervisor
)) {
5700 GEN_EXCP_PRIVOPC(ctx
);
5703 switch (rB(ctx
->opcode
)) {
5707 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5708 gen_op_440_tlbre(rB(ctx
->opcode
));
5709 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
5712 GEN_EXCP_INVAL(ctx
);
5718 /* tlbsx - tlbsx. */
5719 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
)
5721 #if defined(CONFIG_USER_ONLY)
5722 GEN_EXCP_PRIVOPC(ctx
);
5724 if (unlikely(!ctx
->supervisor
)) {
5725 GEN_EXCP_PRIVOPC(ctx
);
5728 gen_addr_reg_index(cpu_T
[0], ctx
);
5730 if (Rc(ctx
->opcode
))
5731 gen_op_4xx_tlbsx_check();
5732 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
5737 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
)
5739 #if defined(CONFIG_USER_ONLY)
5740 GEN_EXCP_PRIVOPC(ctx
);
5742 if (unlikely(!ctx
->supervisor
)) {
5743 GEN_EXCP_PRIVOPC(ctx
);
5746 switch (rB(ctx
->opcode
)) {
5750 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5751 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
5752 gen_op_440_tlbwe(rB(ctx
->opcode
));
5755 GEN_EXCP_INVAL(ctx
);
5762 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
)
5764 #if defined(CONFIG_USER_ONLY)
5765 GEN_EXCP_PRIVOPC(ctx
);
5767 if (unlikely(!ctx
->supervisor
)) {
5768 GEN_EXCP_PRIVOPC(ctx
);
5771 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rD(ctx
->opcode
)]);
5773 /* Stop translation to have a chance to raise an exception
5774 * if we just set msr_ee to 1
5781 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000EFC01, PPC_WRTEE
)
5783 #if defined(CONFIG_USER_ONLY)
5784 GEN_EXCP_PRIVOPC(ctx
);
5786 if (unlikely(!ctx
->supervisor
)) {
5787 GEN_EXCP_PRIVOPC(ctx
);
5790 tcg_gen_movi_tl(cpu_T
[0], ctx
->opcode
& 0x00010000);
5792 /* Stop translation to have a chance to raise an exception
5793 * if we just set msr_ee to 1
5799 /* PowerPC 440 specific instructions */
5801 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
)
5803 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
5804 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
5806 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
5807 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~0x7F);
5808 tcg_gen_or_tl(cpu_xer
, cpu_xer
, cpu_T
[0]);
5809 if (Rc(ctx
->opcode
)) {
5810 gen_op_440_dlmzb_update_Rc();
5811 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_T
[0]);
5812 tcg_gen_andi_i32(cpu_crf
[0], cpu_crf
[0], 0xf);
5816 /* mbar replaces eieio on 440 */
5817 GEN_HANDLER(mbar
, 0x1F, 0x16, 0x13, 0x001FF801, PPC_BOOKE
)
5819 /* interpreted as no-op */
5822 /* msync replaces sync on 440 */
5823 GEN_HANDLER(msync
, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE
)
5825 /* interpreted as no-op */
5829 GEN_HANDLER2(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001, PPC_BOOKE
)
5831 /* interpreted as no-op */
5832 /* XXX: specification say this is treated as a load by the MMU
5833 * but does not generate any exception
5837 /*** Altivec vector extension ***/
5838 /* Altivec registers moves */
5840 static always_inline
void gen_load_avr(int t
, int reg
) {
5841 tcg_gen_mov_i64(cpu_AVRh
[t
], cpu_avrh
[reg
]);
5842 tcg_gen_mov_i64(cpu_AVRl
[t
], cpu_avrl
[reg
]);
5845 static always_inline
void gen_store_avr(int reg
, int t
) {
5846 tcg_gen_mov_i64(cpu_avrh
[reg
], cpu_AVRh
[t
]);
5847 tcg_gen_mov_i64(cpu_avrl
[reg
], cpu_AVRl
[t
]);
5850 #define op_vr_ldst(name) (*gen_op_##name[ctx->mem_idx])()
5851 #define OP_VR_LD_TABLE(name) \
5852 static GenOpFunc *gen_op_vr_l##name[NB_MEM_FUNCS] = { \
5853 GEN_MEM_FUNCS(vr_l##name), \
5855 #define OP_VR_ST_TABLE(name) \
5856 static GenOpFunc *gen_op_vr_st##name[NB_MEM_FUNCS] = { \
5857 GEN_MEM_FUNCS(vr_st##name), \
5860 #define GEN_VR_LDX(name, opc2, opc3) \
5861 GEN_HANDLER(l##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
5863 if (unlikely(!ctx->altivec_enabled)) { \
5864 GEN_EXCP_NO_VR(ctx); \
5867 gen_addr_reg_index(cpu_T[0], ctx); \
5868 op_vr_ldst(vr_l##name); \
5869 gen_store_avr(rD(ctx->opcode), 0); \
5872 #define GEN_VR_STX(name, opc2, opc3) \
5873 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
5875 if (unlikely(!ctx->altivec_enabled)) { \
5876 GEN_EXCP_NO_VR(ctx); \
5879 gen_addr_reg_index(cpu_T[0], ctx); \
5880 gen_load_avr(0, rS(ctx->opcode)); \
5881 op_vr_ldst(vr_st##name); \
5885 GEN_VR_LDX(vx
, 0x07, 0x03);
5886 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
5887 #define gen_op_vr_lvxl gen_op_vr_lvx
5888 GEN_VR_LDX(vxl
, 0x07, 0x0B);
5891 GEN_VR_STX(vx
, 0x07, 0x07);
5892 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
5893 #define gen_op_vr_stvxl gen_op_vr_stvx
5894 GEN_VR_STX(vxl
, 0x07, 0x0F);
5896 /*** SPE extension ***/
5897 /* Register moves */
5899 static always_inline
void gen_load_gpr64(TCGv_i64 t
, int reg
) {
5900 #if defined(TARGET_PPC64)
5901 tcg_gen_mov_i64(t
, cpu_gpr
[reg
]);
5903 tcg_gen_concat_i32_i64(t
, cpu_gpr
[reg
], cpu_gprh
[reg
]);
5907 static always_inline
void gen_store_gpr64(int reg
, TCGv_i64 t
) {
5908 #if defined(TARGET_PPC64)
5909 tcg_gen_mov_i64(cpu_gpr
[reg
], t
);
5911 TCGv_i64 tmp
= tcg_temp_new_i64();
5912 tcg_gen_trunc_i64_i32(cpu_gpr
[reg
], t
);
5913 tcg_gen_shri_i64(tmp
, t
, 32);
5914 tcg_gen_trunc_i64_i32(cpu_gprh
[reg
], tmp
);
5915 tcg_temp_free_i64(tmp
);
5919 #define GEN_SPE(name0, name1, opc2, opc3, inval, type) \
5920 GEN_HANDLER(name0##_##name1, 0x04, opc2, opc3, inval, type) \
5922 if (Rc(ctx->opcode)) \
5928 /* Handler for undefined SPE opcodes */
5929 static always_inline
void gen_speundef (DisasContext
*ctx
)
5931 GEN_EXCP_INVAL(ctx
);
5934 /* SPE load and stores */
5935 static always_inline
void gen_addr_spe_imm_index (TCGv EA
, DisasContext
*ctx
, int sh
)
5937 target_long simm
= rB(ctx
->opcode
);
5939 if (rA(ctx
->opcode
) == 0)
5940 tcg_gen_movi_tl(EA
, simm
<< sh
);
5941 else if (likely(simm
!= 0))
5942 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
<< sh
);
5944 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
5947 #define op_spe_ldst(name) (*gen_op_##name[ctx->mem_idx])()
5948 #define OP_SPE_LD_TABLE(name) \
5949 static GenOpFunc *gen_op_spe_l##name[NB_MEM_FUNCS] = { \
5950 GEN_MEM_FUNCS(spe_l##name), \
5952 #define OP_SPE_ST_TABLE(name) \
5953 static GenOpFunc *gen_op_spe_st##name[NB_MEM_FUNCS] = { \
5954 GEN_MEM_FUNCS(spe_st##name), \
5957 #define GEN_SPE_LD(name, sh) \
5958 static always_inline void gen_evl##name (DisasContext *ctx) \
5960 if (unlikely(!ctx->spe_enabled)) { \
5961 GEN_EXCP_NO_AP(ctx); \
5964 gen_addr_spe_imm_index(cpu_T[0], ctx, sh); \
5965 op_spe_ldst(spe_l##name); \
5966 gen_store_gpr64(rD(ctx->opcode), cpu_T64[1]); \
5969 #define GEN_SPE_LDX(name) \
5970 static always_inline void gen_evl##name##x (DisasContext *ctx) \
5972 if (unlikely(!ctx->spe_enabled)) { \
5973 GEN_EXCP_NO_AP(ctx); \
5976 gen_addr_reg_index(cpu_T[0], ctx); \
5977 op_spe_ldst(spe_l##name); \
5978 gen_store_gpr64(rD(ctx->opcode), cpu_T64[1]); \
5981 #define GEN_SPEOP_LD(name, sh) \
5982 OP_SPE_LD_TABLE(name); \
5983 GEN_SPE_LD(name, sh); \
5986 #define GEN_SPE_ST(name, sh) \
5987 static always_inline void gen_evst##name (DisasContext *ctx) \
5989 if (unlikely(!ctx->spe_enabled)) { \
5990 GEN_EXCP_NO_AP(ctx); \
5993 gen_addr_spe_imm_index(cpu_T[0], ctx, sh); \
5994 gen_load_gpr64(cpu_T64[1], rS(ctx->opcode)); \
5995 op_spe_ldst(spe_st##name); \
5998 #define GEN_SPE_STX(name) \
5999 static always_inline void gen_evst##name##x (DisasContext *ctx) \
6001 if (unlikely(!ctx->spe_enabled)) { \
6002 GEN_EXCP_NO_AP(ctx); \
6005 gen_addr_reg_index(cpu_T[0], ctx); \
6006 gen_load_gpr64(cpu_T64[1], rS(ctx->opcode)); \
6007 op_spe_ldst(spe_st##name); \
6010 #define GEN_SPEOP_ST(name, sh) \
6011 OP_SPE_ST_TABLE(name); \
6012 GEN_SPE_ST(name, sh); \
6015 #define GEN_SPEOP_LDST(name, sh) \
6016 GEN_SPEOP_LD(name, sh); \
6017 GEN_SPEOP_ST(name, sh)
6020 #if defined(TARGET_PPC64)
6021 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
6022 static always_inline void gen_##name (DisasContext *ctx) \
6024 if (unlikely(!ctx->spe_enabled)) { \
6025 GEN_EXCP_NO_AP(ctx); \
6028 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6029 cpu_gpr[rB(ctx->opcode)]); \
6032 #define GEN_SPEOP_LOGIC2(name, tcg_op) \
6033 static always_inline void gen_##name (DisasContext *ctx) \
6035 if (unlikely(!ctx->spe_enabled)) { \
6036 GEN_EXCP_NO_AP(ctx); \
6039 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6040 cpu_gpr[rB(ctx->opcode)]); \
6041 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6042 cpu_gprh[rB(ctx->opcode)]); \
6046 GEN_SPEOP_LOGIC2(evand
, tcg_gen_and_tl
);
6047 GEN_SPEOP_LOGIC2(evandc
, tcg_gen_andc_tl
);
6048 GEN_SPEOP_LOGIC2(evxor
, tcg_gen_xor_tl
);
6049 GEN_SPEOP_LOGIC2(evor
, tcg_gen_or_tl
);
6050 GEN_SPEOP_LOGIC2(evnor
, tcg_gen_nor_tl
);
6051 GEN_SPEOP_LOGIC2(eveqv
, tcg_gen_eqv_tl
);
6052 GEN_SPEOP_LOGIC2(evorc
, tcg_gen_orc_tl
);
6053 GEN_SPEOP_LOGIC2(evnand
, tcg_gen_nand_tl
);
6055 /* SPE logic immediate */
6056 #if defined(TARGET_PPC64)
6057 #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \
6058 static always_inline void gen_##name (DisasContext *ctx) \
6060 if (unlikely(!ctx->spe_enabled)) { \
6061 GEN_EXCP_NO_AP(ctx); \
6064 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6065 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6066 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6067 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6068 tcg_opi(t0, t0, rB(ctx->opcode)); \
6069 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6070 tcg_gen_trunc_i64_i32(t1, t2); \
6071 tcg_temp_free_i64(t2); \
6072 tcg_opi(t1, t1, rB(ctx->opcode)); \
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_TCG_LOGIC_IMM2(name, tcg_opi) \
6079 static always_inline void gen_##name (DisasContext *ctx) \
6081 if (unlikely(!ctx->spe_enabled)) { \
6082 GEN_EXCP_NO_AP(ctx); \
6085 tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6087 tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6091 GEN_SPEOP_TCG_LOGIC_IMM2(evslwi
, tcg_gen_shli_i32
);
6092 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu
, tcg_gen_shri_i32
);
6093 GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis
, tcg_gen_sari_i32
);
6094 GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi
, tcg_gen_rotli_i32
);
6096 /* SPE arithmetic */
6097 #if defined(TARGET_PPC64)
6098 #define GEN_SPEOP_ARITH1(name, tcg_op) \
6099 static always_inline void gen_##name (DisasContext *ctx) \
6101 if (unlikely(!ctx->spe_enabled)) { \
6102 GEN_EXCP_NO_AP(ctx); \
6105 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6106 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6107 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6108 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6110 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6111 tcg_gen_trunc_i64_i32(t1, t2); \
6112 tcg_temp_free_i64(t2); \
6114 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6115 tcg_temp_free_i32(t0); \
6116 tcg_temp_free_i32(t1); \
6119 #define GEN_SPEOP_ARITH1(name, tcg_op) \
6120 static always_inline void gen_##name (DisasContext *ctx) \
6122 if (unlikely(!ctx->spe_enabled)) { \
6123 GEN_EXCP_NO_AP(ctx); \
6126 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \
6127 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \
6131 static always_inline
void gen_op_evabs (TCGv_i32 ret
, TCGv_i32 arg1
)
6133 int l1
= gen_new_label();
6134 int l2
= gen_new_label();
6136 tcg_gen_brcondi_i32(TCG_COND_GE
, arg1
, 0, l1
);
6137 tcg_gen_neg_i32(ret
, arg1
);
6140 tcg_gen_mov_i32(ret
, arg1
);
6143 GEN_SPEOP_ARITH1(evabs
, gen_op_evabs
);
6144 GEN_SPEOP_ARITH1(evneg
, tcg_gen_neg_i32
);
6145 GEN_SPEOP_ARITH1(evextsb
, tcg_gen_ext8s_i32
);
6146 GEN_SPEOP_ARITH1(evextsh
, tcg_gen_ext16s_i32
);
6147 static always_inline
void gen_op_evrndw (TCGv_i32 ret
, TCGv_i32 arg1
)
6149 tcg_gen_addi_i32(ret
, arg1
, 0x8000);
6150 tcg_gen_ext16u_i32(ret
, ret
);
6152 GEN_SPEOP_ARITH1(evrndw
, gen_op_evrndw
);
6153 GEN_SPEOP_ARITH1(evcntlsw
, gen_helper_cntlsw32
);
6154 GEN_SPEOP_ARITH1(evcntlzw
, gen_helper_cntlzw32
);
6156 #if defined(TARGET_PPC64)
6157 #define GEN_SPEOP_ARITH2(name, tcg_op) \
6158 static always_inline void gen_##name (DisasContext *ctx) \
6160 if (unlikely(!ctx->spe_enabled)) { \
6161 GEN_EXCP_NO_AP(ctx); \
6164 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6165 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6166 TCGv_i32 t2 = tcg_temp_local_new_i32(); \
6167 TCGv_i64 t3 = tcg_temp_local_new(TCG_TYPE_I64); \
6168 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6169 tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \
6170 tcg_op(t0, t0, t2); \
6171 tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \
6172 tcg_gen_trunc_i64_i32(t1, t3); \
6173 tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \
6174 tcg_gen_trunc_i64_i32(t2, t3); \
6175 tcg_temp_free_i64(t3); \
6176 tcg_op(t1, t1, t2); \
6177 tcg_temp_free_i32(t2); \
6178 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6179 tcg_temp_free_i32(t0); \
6180 tcg_temp_free_i32(t1); \
6183 #define GEN_SPEOP_ARITH2(name, tcg_op) \
6184 static always_inline void gen_##name (DisasContext *ctx) \
6186 if (unlikely(!ctx->spe_enabled)) { \
6187 GEN_EXCP_NO_AP(ctx); \
6190 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \
6191 cpu_gpr[rB(ctx->opcode)]); \
6192 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \
6193 cpu_gprh[rB(ctx->opcode)]); \
6197 static always_inline
void gen_op_evsrwu (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6202 l1
= gen_new_label();
6203 l2
= gen_new_label();
6204 t0
= tcg_temp_local_new_i32();
6205 /* No error here: 6 bits are used */
6206 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
6207 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
6208 tcg_gen_shr_i32(ret
, arg1
, t0
);
6211 tcg_gen_movi_i32(ret
, 0);
6213 tcg_temp_free_i32(t0
);
6215 GEN_SPEOP_ARITH2(evsrwu
, gen_op_evsrwu
);
6216 static always_inline
void gen_op_evsrws (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6221 l1
= gen_new_label();
6222 l2
= gen_new_label();
6223 t0
= tcg_temp_local_new_i32();
6224 /* No error here: 6 bits are used */
6225 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
6226 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
6227 tcg_gen_sar_i32(ret
, arg1
, t0
);
6230 tcg_gen_movi_i32(ret
, 0);
6232 tcg_temp_free_i32(t0
);
6234 GEN_SPEOP_ARITH2(evsrws
, gen_op_evsrws
);
6235 static always_inline
void gen_op_evslw (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6240 l1
= gen_new_label();
6241 l2
= gen_new_label();
6242 t0
= tcg_temp_local_new_i32();
6243 /* No error here: 6 bits are used */
6244 tcg_gen_andi_i32(t0
, arg2
, 0x3F);
6245 tcg_gen_brcondi_i32(TCG_COND_GE
, t0
, 32, l1
);
6246 tcg_gen_shl_i32(ret
, arg1
, t0
);
6249 tcg_gen_movi_i32(ret
, 0);
6251 tcg_temp_free_i32(t0
);
6253 GEN_SPEOP_ARITH2(evslw
, gen_op_evslw
);
6254 static always_inline
void gen_op_evrlw (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6256 TCGv_i32 t0
= tcg_temp_new_i32();
6257 tcg_gen_andi_i32(t0
, arg2
, 0x1F);
6258 tcg_gen_rotl_i32(ret
, arg1
, t0
);
6259 tcg_temp_free_i32(t0
);
6261 GEN_SPEOP_ARITH2(evrlw
, gen_op_evrlw
);
6262 static always_inline
void gen_evmergehi (DisasContext
*ctx
)
6264 if (unlikely(!ctx
->spe_enabled
)) {
6265 GEN_EXCP_NO_AP(ctx
);
6268 #if defined(TARGET_PPC64)
6269 TCGv t0
= tcg_temp_new();
6270 TCGv t1
= tcg_temp_new();
6271 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
6272 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
6273 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
6277 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
6278 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6281 GEN_SPEOP_ARITH2(evaddw
, tcg_gen_add_i32
);
6282 static always_inline
void gen_op_evsubf (TCGv_i32 ret
, TCGv_i32 arg1
, TCGv_i32 arg2
)
6284 tcg_gen_sub_i32(ret
, arg2
, arg1
);
6286 GEN_SPEOP_ARITH2(evsubfw
, gen_op_evsubf
);
6288 /* SPE arithmetic immediate */
6289 #if defined(TARGET_PPC64)
6290 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
6291 static always_inline void gen_##name (DisasContext *ctx) \
6293 if (unlikely(!ctx->spe_enabled)) { \
6294 GEN_EXCP_NO_AP(ctx); \
6297 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6298 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6299 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6300 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \
6301 tcg_op(t0, t0, rA(ctx->opcode)); \
6302 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
6303 tcg_gen_trunc_i64_i32(t1, t2); \
6304 tcg_temp_free_i64(t2); \
6305 tcg_op(t1, t1, rA(ctx->opcode)); \
6306 tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \
6307 tcg_temp_free_i32(t0); \
6308 tcg_temp_free_i32(t1); \
6311 #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \
6312 static always_inline void gen_##name (DisasContext *ctx) \
6314 if (unlikely(!ctx->spe_enabled)) { \
6315 GEN_EXCP_NO_AP(ctx); \
6318 tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
6320 tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \
6324 GEN_SPEOP_ARITH_IMM2(evaddiw
, tcg_gen_addi_i32
);
6325 GEN_SPEOP_ARITH_IMM2(evsubifw
, tcg_gen_subi_i32
);
6327 /* SPE comparison */
6328 #if defined(TARGET_PPC64)
6329 #define GEN_SPEOP_COMP(name, tcg_cond) \
6330 static always_inline void gen_##name (DisasContext *ctx) \
6332 if (unlikely(!ctx->spe_enabled)) { \
6333 GEN_EXCP_NO_AP(ctx); \
6336 int l1 = gen_new_label(); \
6337 int l2 = gen_new_label(); \
6338 int l3 = gen_new_label(); \
6339 int l4 = gen_new_label(); \
6340 TCGv_i32 t0 = tcg_temp_local_new_i32(); \
6341 TCGv_i32 t1 = tcg_temp_local_new_i32(); \
6342 TCGv_i64 t2 = tcg_temp_local_new_i64(); \
6343 tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \
6344 tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \
6345 tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \
6346 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \
6348 gen_set_label(l1); \
6349 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
6350 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
6351 gen_set_label(l2); \
6352 tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \
6353 tcg_gen_trunc_i64_i32(t0, t2); \
6354 tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \
6355 tcg_gen_trunc_i64_i32(t1, t2); \
6356 tcg_temp_free_i64(t2); \
6357 tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \
6358 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6359 ~(CRF_CH | CRF_CH_AND_CL)); \
6361 gen_set_label(l3); \
6362 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6363 CRF_CH | CRF_CH_OR_CL); \
6364 gen_set_label(l4); \
6365 tcg_temp_free_i32(t0); \
6366 tcg_temp_free_i32(t1); \
6369 #define GEN_SPEOP_COMP(name, tcg_cond) \
6370 static always_inline void gen_##name (DisasContext *ctx) \
6372 if (unlikely(!ctx->spe_enabled)) { \
6373 GEN_EXCP_NO_AP(ctx); \
6376 int l1 = gen_new_label(); \
6377 int l2 = gen_new_label(); \
6378 int l3 = gen_new_label(); \
6379 int l4 = gen_new_label(); \
6381 tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \
6382 cpu_gpr[rB(ctx->opcode)], l1); \
6383 tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \
6385 gen_set_label(l1); \
6386 tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \
6387 CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \
6388 gen_set_label(l2); \
6389 tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \
6390 cpu_gprh[rB(ctx->opcode)], l3); \
6391 tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6392 ~(CRF_CH | CRF_CH_AND_CL)); \
6394 gen_set_label(l3); \
6395 tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \
6396 CRF_CH | CRF_CH_OR_CL); \
6397 gen_set_label(l4); \
6400 GEN_SPEOP_COMP(evcmpgtu
, TCG_COND_GTU
);
6401 GEN_SPEOP_COMP(evcmpgts
, TCG_COND_GT
);
6402 GEN_SPEOP_COMP(evcmpltu
, TCG_COND_LTU
);
6403 GEN_SPEOP_COMP(evcmplts
, TCG_COND_LT
);
6404 GEN_SPEOP_COMP(evcmpeq
, TCG_COND_EQ
);
6407 static always_inline
void gen_brinc (DisasContext
*ctx
)
6409 /* Note: brinc is usable even if SPE is disabled */
6410 gen_helper_brinc(cpu_gpr
[rD(ctx
->opcode
)],
6411 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6413 static always_inline
void gen_evmergelo (DisasContext
*ctx
)
6415 if (unlikely(!ctx
->spe_enabled
)) {
6416 GEN_EXCP_NO_AP(ctx
);
6419 #if defined(TARGET_PPC64)
6420 TCGv t0
= tcg_temp_new();
6421 TCGv t1
= tcg_temp_new();
6422 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x00000000FFFFFFFFLL
);
6423 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
6424 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
6428 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6429 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6432 static always_inline
void gen_evmergehilo (DisasContext
*ctx
)
6434 if (unlikely(!ctx
->spe_enabled
)) {
6435 GEN_EXCP_NO_AP(ctx
);
6438 #if defined(TARGET_PPC64)
6439 TCGv t0
= tcg_temp_new();
6440 TCGv t1
= tcg_temp_new();
6441 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x00000000FFFFFFFFLL
);
6442 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF0000000ULL
);
6443 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
6447 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6448 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6451 static always_inline
void gen_evmergelohi (DisasContext
*ctx
)
6453 if (unlikely(!ctx
->spe_enabled
)) {
6454 GEN_EXCP_NO_AP(ctx
);
6457 #if defined(TARGET_PPC64)
6458 TCGv t0
= tcg_temp_new();
6459 TCGv t1
= tcg_temp_new();
6460 tcg_gen_shri_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 32);
6461 tcg_gen_shli_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 32);
6462 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
6466 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
6467 tcg_gen_mov_i32(cpu_gprh
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6470 static always_inline
void gen_evsplati (DisasContext
*ctx
)
6472 int32_t imm
= (int32_t)(rA(ctx
->opcode
) << 11) >> 27;
6474 #if defined(TARGET_PPC64)
6475 TCGv t0
= tcg_temp_new();
6476 TCGv t1
= tcg_temp_new();
6477 tcg_gen_movi_tl(t0
, imm
);
6478 tcg_gen_shri_tl(t1
, t0
, 32);
6479 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
6483 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
6484 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
6487 static always_inline
void gen_evsplatfi (DisasContext
*ctx
)
6489 uint32_t imm
= rA(ctx
->opcode
) << 11;
6491 #if defined(TARGET_PPC64)
6492 TCGv t0
= tcg_temp_new();
6493 TCGv t1
= tcg_temp_new();
6494 tcg_gen_movi_tl(t0
, imm
);
6495 tcg_gen_shri_tl(t1
, t0
, 32);
6496 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
6500 tcg_gen_movi_i32(cpu_gpr
[rD(ctx
->opcode
)], imm
);
6501 tcg_gen_movi_i32(cpu_gprh
[rD(ctx
->opcode
)], imm
);
6505 static always_inline
void gen_evsel (DisasContext
*ctx
)
6507 int l1
= gen_new_label();
6508 int l2
= gen_new_label();
6509 int l3
= gen_new_label();
6510 int l4
= gen_new_label();
6511 TCGv_i32 t0
= tcg_temp_local_new_i32();
6512 #if defined(TARGET_PPC64)
6513 TCGv t1
= tcg_temp_local_new();
6514 TCGv t2
= tcg_temp_local_new();
6516 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 3);
6517 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l1
);
6518 #if defined(TARGET_PPC64)
6519 tcg_gen_andi_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
6521 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rA(ctx
->opcode
)]);
6525 #if defined(TARGET_PPC64)
6526 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0xFFFFFFFF00000000ULL
);
6528 tcg_gen_mov_tl(cpu_gprh
[rD(ctx
->opcode
)], cpu_gprh
[rB(ctx
->opcode
)]);
6531 tcg_gen_andi_i32(t0
, cpu_crf
[ctx
->opcode
& 0x07], 1 << 2);
6532 tcg_gen_brcondi_i32(TCG_COND_EQ
, t0
, 0, l3
);
6533 #if defined(TARGET_PPC64)
6534 tcg_gen_andi_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], 0x00000000FFFFFFFFULL
);
6536 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6540 #if defined(TARGET_PPC64)
6541 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x00000000FFFFFFFFULL
);
6543 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6546 tcg_temp_free_i32(t0
);
6547 #if defined(TARGET_PPC64)
6548 tcg_gen_or_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
, t2
);
6553 GEN_HANDLER2(evsel0
, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE
)
6557 GEN_HANDLER2(evsel1
, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE
)
6561 GEN_HANDLER2(evsel2
, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE
)
6565 GEN_HANDLER2(evsel3
, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE
)
6570 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, PPC_SPE
); ////
6571 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, PPC_SPE
);
6572 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, PPC_SPE
); ////
6573 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, PPC_SPE
);
6574 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, PPC_SPE
); ////
6575 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, PPC_SPE
); ////
6576 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, PPC_SPE
); ////
6577 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x00000000, PPC_SPE
); //
6578 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0x00000000, PPC_SPE
); ////
6579 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, PPC_SPE
); ////
6580 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, PPC_SPE
); ////
6581 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, PPC_SPE
); ////
6582 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0x00000000, PPC_SPE
); ////
6583 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, PPC_SPE
); ////
6584 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, PPC_SPE
); ////
6585 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, PPC_SPE
);
6586 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, PPC_SPE
); ////
6587 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, PPC_SPE
);
6588 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, PPC_SPE
); //
6589 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, PPC_SPE
);
6590 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, PPC_SPE
); ////
6591 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, PPC_SPE
); ////
6592 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, PPC_SPE
); ////
6593 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, PPC_SPE
); ////
6594 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, PPC_SPE
); ////
6596 /* Load and stores */
6597 GEN_SPEOP_LDST(dd
, 3);
6598 GEN_SPEOP_LDST(dw
, 3);
6599 GEN_SPEOP_LDST(dh
, 3);
6600 GEN_SPEOP_LDST(whe
, 2);
6601 GEN_SPEOP_LD(whou
, 2);
6602 GEN_SPEOP_LD(whos
, 2);
6603 GEN_SPEOP_ST(who
, 2);
6605 #define _GEN_OP_SPE_STWWE(suffix) \
6606 static always_inline void gen_op_spe_stwwe_##suffix (void) \
6608 gen_op_srli32_T1_64(); \
6609 gen_op_spe_stwwo_##suffix(); \
6611 #define _GEN_OP_SPE_STWWE_LE(suffix) \
6612 static always_inline void gen_op_spe_stwwe_le_##suffix (void) \
6614 gen_op_srli32_T1_64(); \
6615 gen_op_spe_stwwo_le_##suffix(); \
6617 #if defined(TARGET_PPC64)
6618 #define GEN_OP_SPE_STWWE(suffix) \
6619 _GEN_OP_SPE_STWWE(suffix); \
6620 _GEN_OP_SPE_STWWE_LE(suffix); \
6621 static always_inline void gen_op_spe_stwwe_64_##suffix (void) \
6623 gen_op_srli32_T1_64(); \
6624 gen_op_spe_stwwo_64_##suffix(); \
6626 static always_inline void gen_op_spe_stwwe_le_64_##suffix (void) \
6628 gen_op_srli32_T1_64(); \
6629 gen_op_spe_stwwo_le_64_##suffix(); \
6632 #define GEN_OP_SPE_STWWE(suffix) \
6633 _GEN_OP_SPE_STWWE(suffix); \
6634 _GEN_OP_SPE_STWWE_LE(suffix)
6636 #if defined(CONFIG_USER_ONLY)
6637 GEN_OP_SPE_STWWE(raw
);
6638 #else /* defined(CONFIG_USER_ONLY) */
6639 GEN_OP_SPE_STWWE(user
);
6640 GEN_OP_SPE_STWWE(kernel
);
6641 GEN_OP_SPE_STWWE(hypv
);
6642 #endif /* defined(CONFIG_USER_ONLY) */
6643 GEN_SPEOP_ST(wwe
, 2);
6644 GEN_SPEOP_ST(wwo
, 2);
6646 #define GEN_SPE_LDSPLAT(name, op, suffix) \
6647 static always_inline void gen_op_spe_l##name##_##suffix (void) \
6649 gen_op_##op##_##suffix(); \
6650 gen_op_splatw_T1_64(); \
6653 #define GEN_OP_SPE_LHE(suffix) \
6654 static always_inline void gen_op_spe_lhe_##suffix (void) \
6656 gen_op_spe_lh_##suffix(); \
6657 gen_op_sli16_T1_64(); \
6660 #define GEN_OP_SPE_LHX(suffix) \
6661 static always_inline void gen_op_spe_lhx_##suffix (void) \
6663 gen_op_spe_lh_##suffix(); \
6664 gen_op_extsh_T1_64(); \
6667 #if defined(CONFIG_USER_ONLY)
6668 GEN_OP_SPE_LHE(raw
);
6669 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, raw
);
6670 GEN_OP_SPE_LHE(le_raw
);
6671 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_raw
);
6672 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, raw
);
6673 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_raw
);
6674 GEN_OP_SPE_LHX(raw
);
6675 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, raw
);
6676 GEN_OP_SPE_LHX(le_raw
);
6677 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_raw
);
6678 #if defined(TARGET_PPC64)
6679 GEN_OP_SPE_LHE(64_raw
);
6680 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, 64_raw
);
6681 GEN_OP_SPE_LHE(le_64_raw
);
6682 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_64_raw
);
6683 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, 64_raw
);
6684 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_64_raw
);
6685 GEN_OP_SPE_LHX(64_raw
);
6686 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, 64_raw
);
6687 GEN_OP_SPE_LHX(le_64_raw
);
6688 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_64_raw
);
6691 GEN_OP_SPE_LHE(user
);
6692 GEN_OP_SPE_LHE(kernel
);
6693 GEN_OP_SPE_LHE(hypv
);
6694 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, user
);
6695 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, kernel
);
6696 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, hypv
);
6697 GEN_OP_SPE_LHE(le_user
);
6698 GEN_OP_SPE_LHE(le_kernel
);
6699 GEN_OP_SPE_LHE(le_hypv
);
6700 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_user
);
6701 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_kernel
);
6702 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_hypv
);
6703 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, user
);
6704 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, kernel
);
6705 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, hypv
);
6706 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_user
);
6707 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_kernel
);
6708 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_hypv
);
6709 GEN_OP_SPE_LHX(user
);
6710 GEN_OP_SPE_LHX(kernel
);
6711 GEN_OP_SPE_LHX(hypv
);
6712 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, user
);
6713 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, kernel
);
6714 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, hypv
);
6715 GEN_OP_SPE_LHX(le_user
);
6716 GEN_OP_SPE_LHX(le_kernel
);
6717 GEN_OP_SPE_LHX(le_hypv
);
6718 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_user
);
6719 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_kernel
);
6720 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_hypv
);
6721 #if defined(TARGET_PPC64)
6722 GEN_OP_SPE_LHE(64_user
);
6723 GEN_OP_SPE_LHE(64_kernel
);
6724 GEN_OP_SPE_LHE(64_hypv
);
6725 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, 64_user
);
6726 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, 64_kernel
);
6727 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, 64_hypv
);
6728 GEN_OP_SPE_LHE(le_64_user
);
6729 GEN_OP_SPE_LHE(le_64_kernel
);
6730 GEN_OP_SPE_LHE(le_64_hypv
);
6731 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_64_user
);
6732 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_64_kernel
);
6733 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_64_hypv
);
6734 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, 64_user
);
6735 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, 64_kernel
);
6736 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, 64_hypv
);
6737 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_64_user
);
6738 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_64_kernel
);
6739 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_64_hypv
);
6740 GEN_OP_SPE_LHX(64_user
);
6741 GEN_OP_SPE_LHX(64_kernel
);
6742 GEN_OP_SPE_LHX(64_hypv
);
6743 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, 64_user
);
6744 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, 64_kernel
);
6745 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, 64_hypv
);
6746 GEN_OP_SPE_LHX(le_64_user
);
6747 GEN_OP_SPE_LHX(le_64_kernel
);
6748 GEN_OP_SPE_LHX(le_64_hypv
);
6749 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_64_user
);
6750 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_64_kernel
);
6751 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_64_hypv
);
6754 GEN_SPEOP_LD(hhesplat
, 1);
6755 GEN_SPEOP_LD(hhousplat
, 1);
6756 GEN_SPEOP_LD(hhossplat
, 1);
6757 GEN_SPEOP_LD(wwsplat
, 2);
6758 GEN_SPEOP_LD(whsplat
, 2);
6760 GEN_SPE(evlddx
, evldd
, 0x00, 0x0C, 0x00000000, PPC_SPE
); //
6761 GEN_SPE(evldwx
, evldw
, 0x01, 0x0C, 0x00000000, PPC_SPE
); //
6762 GEN_SPE(evldhx
, evldh
, 0x02, 0x0C, 0x00000000, PPC_SPE
); //
6763 GEN_SPE(evlhhesplatx
, evlhhesplat
, 0x04, 0x0C, 0x00000000, PPC_SPE
); //
6764 GEN_SPE(evlhhousplatx
, evlhhousplat
, 0x06, 0x0C, 0x00000000, PPC_SPE
); //
6765 GEN_SPE(evlhhossplatx
, evlhhossplat
, 0x07, 0x0C, 0x00000000, PPC_SPE
); //
6766 GEN_SPE(evlwhex
, evlwhe
, 0x08, 0x0C, 0x00000000, PPC_SPE
); //
6767 GEN_SPE(evlwhoux
, evlwhou
, 0x0A, 0x0C, 0x00000000, PPC_SPE
); //
6768 GEN_SPE(evlwhosx
, evlwhos
, 0x0B, 0x0C, 0x00000000, PPC_SPE
); //
6769 GEN_SPE(evlwwsplatx
, evlwwsplat
, 0x0C, 0x0C, 0x00000000, PPC_SPE
); //
6770 GEN_SPE(evlwhsplatx
, evlwhsplat
, 0x0E, 0x0C, 0x00000000, PPC_SPE
); //
6771 GEN_SPE(evstddx
, evstdd
, 0x10, 0x0C, 0x00000000, PPC_SPE
); //
6772 GEN_SPE(evstdwx
, evstdw
, 0x11, 0x0C, 0x00000000, PPC_SPE
); //
6773 GEN_SPE(evstdhx
, evstdh
, 0x12, 0x0C, 0x00000000, PPC_SPE
); //
6774 GEN_SPE(evstwhex
, evstwhe
, 0x18, 0x0C, 0x00000000, PPC_SPE
); //
6775 GEN_SPE(evstwhox
, evstwho
, 0x1A, 0x0C, 0x00000000, PPC_SPE
); //
6776 GEN_SPE(evstwwex
, evstwwe
, 0x1C, 0x0C, 0x00000000, PPC_SPE
); //
6777 GEN_SPE(evstwwox
, evstwwo
, 0x1E, 0x0C, 0x00000000, PPC_SPE
); //
6779 /* Multiply and add - TODO */
6781 GEN_SPE(speundef
, evmhessf
, 0x01, 0x10, 0x00000000, PPC_SPE
);
6782 GEN_SPE(speundef
, evmhossf
, 0x03, 0x10, 0x00000000, PPC_SPE
);
6783 GEN_SPE(evmheumi
, evmhesmi
, 0x04, 0x10, 0x00000000, PPC_SPE
);
6784 GEN_SPE(speundef
, evmhesmf
, 0x05, 0x10, 0x00000000, PPC_SPE
);
6785 GEN_SPE(evmhoumi
, evmhosmi
, 0x06, 0x10, 0x00000000, PPC_SPE
);
6786 GEN_SPE(speundef
, evmhosmf
, 0x07, 0x10, 0x00000000, PPC_SPE
);
6787 GEN_SPE(speundef
, evmhessfa
, 0x11, 0x10, 0x00000000, PPC_SPE
);
6788 GEN_SPE(speundef
, evmhossfa
, 0x13, 0x10, 0x00000000, PPC_SPE
);
6789 GEN_SPE(evmheumia
, evmhesmia
, 0x14, 0x10, 0x00000000, PPC_SPE
);
6790 GEN_SPE(speundef
, evmhesmfa
, 0x15, 0x10, 0x00000000, PPC_SPE
);
6791 GEN_SPE(evmhoumia
, evmhosmia
, 0x16, 0x10, 0x00000000, PPC_SPE
);
6792 GEN_SPE(speundef
, evmhosmfa
, 0x17, 0x10, 0x00000000, PPC_SPE
);
6794 GEN_SPE(speundef
, evmwhssf
, 0x03, 0x11, 0x00000000, PPC_SPE
);
6795 GEN_SPE(evmwlumi
, speundef
, 0x04, 0x11, 0x00000000, PPC_SPE
);
6796 GEN_SPE(evmwhumi
, evmwhsmi
, 0x06, 0x11, 0x00000000, PPC_SPE
);
6797 GEN_SPE(speundef
, evmwhsmf
, 0x07, 0x11, 0x00000000, PPC_SPE
);
6798 GEN_SPE(speundef
, evmwssf
, 0x09, 0x11, 0x00000000, PPC_SPE
);
6799 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, PPC_SPE
);
6800 GEN_SPE(speundef
, evmwsmf
, 0x0D, 0x11, 0x00000000, PPC_SPE
);
6801 GEN_SPE(speundef
, evmwhssfa
, 0x13, 0x11, 0x00000000, PPC_SPE
);
6802 GEN_SPE(evmwlumia
, speundef
, 0x14, 0x11, 0x00000000, PPC_SPE
);
6803 GEN_SPE(evmwhumia
, evmwhsmia
, 0x16, 0x11, 0x00000000, PPC_SPE
);
6804 GEN_SPE(speundef
, evmwhsmfa
, 0x17, 0x11, 0x00000000, PPC_SPE
);
6805 GEN_SPE(speundef
, evmwssfa
, 0x19, 0x11, 0x00000000, PPC_SPE
);
6806 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, PPC_SPE
);
6807 GEN_SPE(speundef
, evmwsmfa
, 0x1D, 0x11, 0x00000000, PPC_SPE
);
6809 GEN_SPE(evadduiaaw
, evaddsiaaw
, 0x00, 0x13, 0x0000F800, PPC_SPE
);
6810 GEN_SPE(evsubfusiaaw
, evsubfssiaaw
, 0x01, 0x13, 0x0000F800, PPC_SPE
);
6811 GEN_SPE(evaddumiaaw
, evaddsmiaaw
, 0x04, 0x13, 0x0000F800, PPC_SPE
);
6812 GEN_SPE(evsubfumiaaw
, evsubfsmiaaw
, 0x05, 0x13, 0x0000F800, PPC_SPE
);
6813 GEN_SPE(evdivws
, evdivwu
, 0x06, 0x13, 0x00000000, PPC_SPE
);
6814 GEN_SPE(evmra
, speundef
, 0x07, 0x13, 0x0000F800, PPC_SPE
);
6816 GEN_SPE(evmheusiaaw
, evmhessiaaw
, 0x00, 0x14, 0x00000000, PPC_SPE
);
6817 GEN_SPE(speundef
, evmhessfaaw
, 0x01, 0x14, 0x00000000, PPC_SPE
);
6818 GEN_SPE(evmhousiaaw
, evmhossiaaw
, 0x02, 0x14, 0x00000000, PPC_SPE
);
6819 GEN_SPE(speundef
, evmhossfaaw
, 0x03, 0x14, 0x00000000, PPC_SPE
);
6820 GEN_SPE(evmheumiaaw
, evmhesmiaaw
, 0x04, 0x14, 0x00000000, PPC_SPE
);
6821 GEN_SPE(speundef
, evmhesmfaaw
, 0x05, 0x14, 0x00000000, PPC_SPE
);
6822 GEN_SPE(evmhoumiaaw
, evmhosmiaaw
, 0x06, 0x14, 0x00000000, PPC_SPE
);
6823 GEN_SPE(speundef
, evmhosmfaaw
, 0x07, 0x14, 0x00000000, PPC_SPE
);
6824 GEN_SPE(evmhegumiaa
, evmhegsmiaa
, 0x14, 0x14, 0x00000000, PPC_SPE
);
6825 GEN_SPE(speundef
, evmhegsmfaa
, 0x15, 0x14, 0x00000000, PPC_SPE
);
6826 GEN_SPE(evmhogumiaa
, evmhogsmiaa
, 0x16, 0x14, 0x00000000, PPC_SPE
);
6827 GEN_SPE(speundef
, evmhogsmfaa
, 0x17, 0x14, 0x00000000, PPC_SPE
);
6829 GEN_SPE(evmwlusiaaw
, evmwlssiaaw
, 0x00, 0x15, 0x00000000, PPC_SPE
);
6830 GEN_SPE(evmwlumiaaw
, evmwlsmiaaw
, 0x04, 0x15, 0x00000000, PPC_SPE
);
6831 GEN_SPE(speundef
, evmwssfaa
, 0x09, 0x15, 0x00000000, PPC_SPE
);
6832 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, PPC_SPE
);
6833 GEN_SPE(speundef
, evmwsmfaa
, 0x0D, 0x15, 0x00000000, PPC_SPE
);
6835 GEN_SPE(evmheusianw
, evmhessianw
, 0x00, 0x16, 0x00000000, PPC_SPE
);
6836 GEN_SPE(speundef
, evmhessfanw
, 0x01, 0x16, 0x00000000, PPC_SPE
);
6837 GEN_SPE(evmhousianw
, evmhossianw
, 0x02, 0x16, 0x00000000, PPC_SPE
);
6838 GEN_SPE(speundef
, evmhossfanw
, 0x03, 0x16, 0x00000000, PPC_SPE
);
6839 GEN_SPE(evmheumianw
, evmhesmianw
, 0x04, 0x16, 0x00000000, PPC_SPE
);
6840 GEN_SPE(speundef
, evmhesmfanw
, 0x05, 0x16, 0x00000000, PPC_SPE
);
6841 GEN_SPE(evmhoumianw
, evmhosmianw
, 0x06, 0x16, 0x00000000, PPC_SPE
);
6842 GEN_SPE(speundef
, evmhosmfanw
, 0x07, 0x16, 0x00000000, PPC_SPE
);
6843 GEN_SPE(evmhegumian
, evmhegsmian
, 0x14, 0x16, 0x00000000, PPC_SPE
);
6844 GEN_SPE(speundef
, evmhegsmfan
, 0x15, 0x16, 0x00000000, PPC_SPE
);
6845 GEN_SPE(evmhigumian
, evmhigsmian
, 0x16, 0x16, 0x00000000, PPC_SPE
);
6846 GEN_SPE(speundef
, evmhogsmfan
, 0x17, 0x16, 0x00000000, PPC_SPE
);
6848 GEN_SPE(evmwlusianw
, evmwlssianw
, 0x00, 0x17, 0x00000000, PPC_SPE
);
6849 GEN_SPE(evmwlumianw
, evmwlsmianw
, 0x04, 0x17, 0x00000000, PPC_SPE
);
6850 GEN_SPE(speundef
, evmwssfan
, 0x09, 0x17, 0x00000000, PPC_SPE
);
6851 GEN_SPE(evmwumian
, evmwsmian
, 0x0C, 0x17, 0x00000000, PPC_SPE
);
6852 GEN_SPE(speundef
, evmwsmfan
, 0x0D, 0x17, 0x00000000, PPC_SPE
);
6855 /*** SPE floating-point extension ***/
6856 #define GEN_SPEFPUOP_CONV(name) \
6857 static always_inline void gen_##name (DisasContext *ctx) \
6859 gen_load_gpr64(cpu_T64[0], rB(ctx->opcode)); \
6861 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
6864 #define GEN_SPEFPUOP_ARITH1(name) \
6865 static always_inline void gen_##name (DisasContext *ctx) \
6867 if (unlikely(!ctx->spe_enabled)) { \
6868 GEN_EXCP_NO_AP(ctx); \
6871 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode)); \
6873 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
6876 #define GEN_SPEFPUOP_ARITH2(name) \
6877 static always_inline void gen_##name (DisasContext *ctx) \
6879 if (unlikely(!ctx->spe_enabled)) { \
6880 GEN_EXCP_NO_AP(ctx); \
6883 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode)); \
6884 gen_load_gpr64(cpu_T64[1], rB(ctx->opcode)); \
6886 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
6889 #define GEN_SPEFPUOP_COMP(name) \
6890 static always_inline void gen_##name (DisasContext *ctx) \
6892 TCGv_i32 crf = cpu_crf[crfD(ctx->opcode)]; \
6893 if (unlikely(!ctx->spe_enabled)) { \
6894 GEN_EXCP_NO_AP(ctx); \
6897 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode)); \
6898 gen_load_gpr64(cpu_T64[1], rB(ctx->opcode)); \
6900 tcg_gen_trunc_tl_i32(crf, cpu_T[0]); \
6901 tcg_gen_andi_i32(crf, crf, 0xf); \
6904 /* Single precision floating-point vectors operations */
6906 GEN_SPEFPUOP_ARITH2(evfsadd
);
6907 GEN_SPEFPUOP_ARITH2(evfssub
);
6908 GEN_SPEFPUOP_ARITH2(evfsmul
);
6909 GEN_SPEFPUOP_ARITH2(evfsdiv
);
6910 GEN_SPEFPUOP_ARITH1(evfsabs
);
6911 GEN_SPEFPUOP_ARITH1(evfsnabs
);
6912 GEN_SPEFPUOP_ARITH1(evfsneg
);
6914 GEN_SPEFPUOP_CONV(evfscfui
);
6915 GEN_SPEFPUOP_CONV(evfscfsi
);
6916 GEN_SPEFPUOP_CONV(evfscfuf
);
6917 GEN_SPEFPUOP_CONV(evfscfsf
);
6918 GEN_SPEFPUOP_CONV(evfsctui
);
6919 GEN_SPEFPUOP_CONV(evfsctsi
);
6920 GEN_SPEFPUOP_CONV(evfsctuf
);
6921 GEN_SPEFPUOP_CONV(evfsctsf
);
6922 GEN_SPEFPUOP_CONV(evfsctuiz
);
6923 GEN_SPEFPUOP_CONV(evfsctsiz
);
6925 GEN_SPEFPUOP_COMP(evfscmpgt
);
6926 GEN_SPEFPUOP_COMP(evfscmplt
);
6927 GEN_SPEFPUOP_COMP(evfscmpeq
);
6928 GEN_SPEFPUOP_COMP(evfststgt
);
6929 GEN_SPEFPUOP_COMP(evfststlt
);
6930 GEN_SPEFPUOP_COMP(evfststeq
);
6932 /* Opcodes definitions */
6933 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, PPC_SPEFPU
); //
6934 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, PPC_SPEFPU
); //
6935 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, PPC_SPEFPU
); //
6936 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, PPC_SPEFPU
); //
6937 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, PPC_SPEFPU
); //
6938 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, PPC_SPEFPU
); //
6939 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, PPC_SPEFPU
); //
6940 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, PPC_SPEFPU
); //
6941 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, PPC_SPEFPU
); //
6942 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, PPC_SPEFPU
); //
6943 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, PPC_SPEFPU
); //
6944 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, PPC_SPEFPU
); //
6945 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, PPC_SPEFPU
); //
6946 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, PPC_SPEFPU
); //
6948 /* Single precision floating-point operations */
6950 GEN_SPEFPUOP_ARITH2(efsadd
);
6951 GEN_SPEFPUOP_ARITH2(efssub
);
6952 GEN_SPEFPUOP_ARITH2(efsmul
);
6953 GEN_SPEFPUOP_ARITH2(efsdiv
);
6954 GEN_SPEFPUOP_ARITH1(efsabs
);
6955 GEN_SPEFPUOP_ARITH1(efsnabs
);
6956 GEN_SPEFPUOP_ARITH1(efsneg
);
6958 GEN_SPEFPUOP_CONV(efscfui
);
6959 GEN_SPEFPUOP_CONV(efscfsi
);
6960 GEN_SPEFPUOP_CONV(efscfuf
);
6961 GEN_SPEFPUOP_CONV(efscfsf
);
6962 GEN_SPEFPUOP_CONV(efsctui
);
6963 GEN_SPEFPUOP_CONV(efsctsi
);
6964 GEN_SPEFPUOP_CONV(efsctuf
);
6965 GEN_SPEFPUOP_CONV(efsctsf
);
6966 GEN_SPEFPUOP_CONV(efsctuiz
);
6967 GEN_SPEFPUOP_CONV(efsctsiz
);
6968 GEN_SPEFPUOP_CONV(efscfd
);
6970 GEN_SPEFPUOP_COMP(efscmpgt
);
6971 GEN_SPEFPUOP_COMP(efscmplt
);
6972 GEN_SPEFPUOP_COMP(efscmpeq
);
6973 GEN_SPEFPUOP_COMP(efststgt
);
6974 GEN_SPEFPUOP_COMP(efststlt
);
6975 GEN_SPEFPUOP_COMP(efststeq
);
6977 /* Opcodes definitions */
6978 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, PPC_SPEFPU
); //
6979 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, PPC_SPEFPU
); //
6980 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, PPC_SPEFPU
); //
6981 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, PPC_SPEFPU
); //
6982 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, PPC_SPEFPU
); //
6983 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, PPC_SPEFPU
); //
6984 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, PPC_SPEFPU
); //
6985 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, PPC_SPEFPU
); //
6986 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, PPC_SPEFPU
); //
6987 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, PPC_SPEFPU
); //
6988 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, PPC_SPEFPU
); //
6989 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, PPC_SPEFPU
); //
6990 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, PPC_SPEFPU
); //
6991 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, PPC_SPEFPU
); //
6993 /* Double precision floating-point operations */
6995 GEN_SPEFPUOP_ARITH2(efdadd
);
6996 GEN_SPEFPUOP_ARITH2(efdsub
);
6997 GEN_SPEFPUOP_ARITH2(efdmul
);
6998 GEN_SPEFPUOP_ARITH2(efddiv
);
6999 GEN_SPEFPUOP_ARITH1(efdabs
);
7000 GEN_SPEFPUOP_ARITH1(efdnabs
);
7001 GEN_SPEFPUOP_ARITH1(efdneg
);
7004 GEN_SPEFPUOP_CONV(efdcfui
);
7005 GEN_SPEFPUOP_CONV(efdcfsi
);
7006 GEN_SPEFPUOP_CONV(efdcfuf
);
7007 GEN_SPEFPUOP_CONV(efdcfsf
);
7008 GEN_SPEFPUOP_CONV(efdctui
);
7009 GEN_SPEFPUOP_CONV(efdctsi
);
7010 GEN_SPEFPUOP_CONV(efdctuf
);
7011 GEN_SPEFPUOP_CONV(efdctsf
);
7012 GEN_SPEFPUOP_CONV(efdctuiz
);
7013 GEN_SPEFPUOP_CONV(efdctsiz
);
7014 GEN_SPEFPUOP_CONV(efdcfs
);
7015 GEN_SPEFPUOP_CONV(efdcfuid
);
7016 GEN_SPEFPUOP_CONV(efdcfsid
);
7017 GEN_SPEFPUOP_CONV(efdctuidz
);
7018 GEN_SPEFPUOP_CONV(efdctsidz
);
7020 GEN_SPEFPUOP_COMP(efdcmpgt
);
7021 GEN_SPEFPUOP_COMP(efdcmplt
);
7022 GEN_SPEFPUOP_COMP(efdcmpeq
);
7023 GEN_SPEFPUOP_COMP(efdtstgt
);
7024 GEN_SPEFPUOP_COMP(efdtstlt
);
7025 GEN_SPEFPUOP_COMP(efdtsteq
);
7027 /* Opcodes definitions */
7028 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, PPC_SPEFPU
); //
7029 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, PPC_SPEFPU
); //
7030 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, PPC_SPEFPU
); //
7031 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, PPC_SPEFPU
); //
7032 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, PPC_SPEFPU
); //
7033 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, PPC_SPEFPU
); //
7034 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, PPC_SPEFPU
); //
7035 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, PPC_SPEFPU
); //
7036 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, PPC_SPEFPU
); //
7037 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, PPC_SPEFPU
); //
7038 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, PPC_SPEFPU
); //
7039 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, PPC_SPEFPU
); //
7040 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, PPC_SPEFPU
); //
7041 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, PPC_SPEFPU
); //
7042 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, PPC_SPEFPU
); //
7043 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, PPC_SPEFPU
); //
7045 /* End opcode list */
7046 GEN_OPCODE_MARK(end
);
7048 #include "translate_init.c"
7049 #include "helper_regs.h"
7051 /*****************************************************************************/
7052 /* Misc PowerPC helpers */
7053 void cpu_dump_state (CPUState
*env
, FILE *f
,
7054 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
7062 cpu_fprintf(f
, "NIP " ADDRX
" LR " ADDRX
" CTR " ADDRX
" XER %08x\n",
7063 env
->nip
, env
->lr
, env
->ctr
, env
->xer
);
7064 cpu_fprintf(f
, "MSR " ADDRX
" HID0 " ADDRX
" HF " ADDRX
" idx %d\n",
7065 env
->msr
, env
->spr
[SPR_HID0
], env
->hflags
, env
->mmu_idx
);
7066 #if !defined(NO_TIMER_DUMP)
7067 cpu_fprintf(f
, "TB %08x %08x "
7068 #if !defined(CONFIG_USER_ONLY)
7072 cpu_ppc_load_tbu(env
), cpu_ppc_load_tbl(env
)
7073 #if !defined(CONFIG_USER_ONLY)
7074 , cpu_ppc_load_decr(env
)
7078 for (i
= 0; i
< 32; i
++) {
7079 if ((i
& (RGPL
- 1)) == 0)
7080 cpu_fprintf(f
, "GPR%02d", i
);
7081 cpu_fprintf(f
, " " REGX
, ppc_dump_gpr(env
, i
));
7082 if ((i
& (RGPL
- 1)) == (RGPL
- 1))
7083 cpu_fprintf(f
, "\n");
7085 cpu_fprintf(f
, "CR ");
7086 for (i
= 0; i
< 8; i
++)
7087 cpu_fprintf(f
, "%01x", env
->crf
[i
]);
7088 cpu_fprintf(f
, " [");
7089 for (i
= 0; i
< 8; i
++) {
7091 if (env
->crf
[i
] & 0x08)
7093 else if (env
->crf
[i
] & 0x04)
7095 else if (env
->crf
[i
] & 0x02)
7097 cpu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
7099 cpu_fprintf(f
, " ] RES " ADDRX
"\n", env
->reserve
);
7100 for (i
= 0; i
< 32; i
++) {
7101 if ((i
& (RFPL
- 1)) == 0)
7102 cpu_fprintf(f
, "FPR%02d", i
);
7103 cpu_fprintf(f
, " %016" PRIx64
, *((uint64_t *)&env
->fpr
[i
]));
7104 if ((i
& (RFPL
- 1)) == (RFPL
- 1))
7105 cpu_fprintf(f
, "\n");
7107 #if !defined(CONFIG_USER_ONLY)
7108 cpu_fprintf(f
, "SRR0 " ADDRX
" SRR1 " ADDRX
" SDR1 " ADDRX
"\n",
7109 env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
], env
->sdr1
);
7116 void cpu_dump_statistics (CPUState
*env
, FILE*f
,
7117 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
7120 #if defined(DO_PPC_STATISTICS)
7121 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
7125 for (op1
= 0; op1
< 64; op1
++) {
7127 if (is_indirect_opcode(handler
)) {
7128 t2
= ind_table(handler
);
7129 for (op2
= 0; op2
< 32; op2
++) {
7131 if (is_indirect_opcode(handler
)) {
7132 t3
= ind_table(handler
);
7133 for (op3
= 0; op3
< 32; op3
++) {
7135 if (handler
->count
== 0)
7137 cpu_fprintf(f
, "%02x %02x %02x (%02x %04d) %16s: "
7139 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
7141 handler
->count
, handler
->count
);
7144 if (handler
->count
== 0)
7146 cpu_fprintf(f
, "%02x %02x (%02x %04d) %16s: "
7148 op1
, op2
, op1
, op2
, handler
->oname
,
7149 handler
->count
, handler
->count
);
7153 if (handler
->count
== 0)
7155 cpu_fprintf(f
, "%02x (%02x ) %16s: %016llx %lld\n",
7156 op1
, op1
, handler
->oname
,
7157 handler
->count
, handler
->count
);
7163 /*****************************************************************************/
7164 static always_inline
void gen_intermediate_code_internal (CPUState
*env
,
7165 TranslationBlock
*tb
,
7168 DisasContext ctx
, *ctxp
= &ctx
;
7169 opc_handler_t
**table
, *handler
;
7170 target_ulong pc_start
;
7171 uint16_t *gen_opc_end
;
7172 int supervisor
, little_endian
;
7178 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
7179 #if defined(OPTIMIZE_FPRF_UPDATE)
7180 gen_fprf_ptr
= gen_fprf_buf
;
7184 ctx
.exception
= POWERPC_EXCP_NONE
;
7185 ctx
.spr_cb
= env
->spr_cb
;
7186 supervisor
= env
->mmu_idx
;
7187 #if !defined(CONFIG_USER_ONLY)
7188 ctx
.supervisor
= supervisor
;
7190 little_endian
= env
->hflags
& (1 << MSR_LE
) ? 1 : 0;
7191 #if defined(TARGET_PPC64)
7192 ctx
.sf_mode
= msr_sf
;
7193 ctx
.mem_idx
= (supervisor
<< 2) | (msr_sf
<< 1) | little_endian
;
7195 ctx
.mem_idx
= (supervisor
<< 1) | little_endian
;
7197 ctx
.dcache_line_size
= env
->dcache_line_size
;
7198 ctx
.fpu_enabled
= msr_fp
;
7199 if ((env
->flags
& POWERPC_FLAG_SPE
) && msr_spe
)
7200 ctx
.spe_enabled
= msr_spe
;
7202 ctx
.spe_enabled
= 0;
7203 if ((env
->flags
& POWERPC_FLAG_VRE
) && msr_vr
)
7204 ctx
.altivec_enabled
= msr_vr
;
7206 ctx
.altivec_enabled
= 0;
7207 if ((env
->flags
& POWERPC_FLAG_SE
) && msr_se
)
7208 ctx
.singlestep_enabled
= CPU_SINGLE_STEP
;
7210 ctx
.singlestep_enabled
= 0;
7211 if ((env
->flags
& POWERPC_FLAG_BE
) && msr_be
)
7212 ctx
.singlestep_enabled
|= CPU_BRANCH_STEP
;
7213 if (unlikely(env
->singlestep_enabled
))
7214 ctx
.singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
7215 #if defined (DO_SINGLE_STEP) && 0
7216 /* Single step trace mode */
7220 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
7222 max_insns
= CF_COUNT_MASK
;
7225 /* Set env in case of segfault during code fetch */
7226 while (ctx
.exception
== POWERPC_EXCP_NONE
&& gen_opc_ptr
< gen_opc_end
) {
7227 if (unlikely(env
->nb_breakpoints
> 0)) {
7228 for (j
= 0; j
< env
->nb_breakpoints
; j
++) {
7229 if (env
->breakpoints
[j
] == ctx
.nip
) {
7230 gen_update_nip(&ctx
, ctx
.nip
);
7236 if (unlikely(search_pc
)) {
7237 j
= gen_opc_ptr
- gen_opc_buf
;
7241 gen_opc_instr_start
[lj
++] = 0;
7242 gen_opc_pc
[lj
] = ctx
.nip
;
7243 gen_opc_instr_start
[lj
] = 1;
7244 gen_opc_icount
[lj
] = num_insns
;
7247 #if defined PPC_DEBUG_DISAS
7248 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
7249 fprintf(logfile
, "----------------\n");
7250 fprintf(logfile
, "nip=" ADDRX
" super=%d ir=%d\n",
7251 ctx
.nip
, supervisor
, (int)msr_ir
);
7254 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
7256 if (unlikely(little_endian
)) {
7257 ctx
.opcode
= bswap32(ldl_code(ctx
.nip
));
7259 ctx
.opcode
= ldl_code(ctx
.nip
);
7261 #if defined PPC_DEBUG_DISAS
7262 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
7263 fprintf(logfile
, "translate opcode %08x (%02x %02x %02x) (%s)\n",
7264 ctx
.opcode
, opc1(ctx
.opcode
), opc2(ctx
.opcode
),
7265 opc3(ctx
.opcode
), little_endian
? "little" : "big");
7269 table
= env
->opcodes
;
7271 handler
= table
[opc1(ctx
.opcode
)];
7272 if (is_indirect_opcode(handler
)) {
7273 table
= ind_table(handler
);
7274 handler
= table
[opc2(ctx
.opcode
)];
7275 if (is_indirect_opcode(handler
)) {
7276 table
= ind_table(handler
);
7277 handler
= table
[opc3(ctx
.opcode
)];
7280 /* Is opcode *REALLY* valid ? */
7281 if (unlikely(handler
->handler
== &gen_invalid
)) {
7282 if (loglevel
!= 0) {
7283 fprintf(logfile
, "invalid/unsupported opcode: "
7284 "%02x - %02x - %02x (%08x) " ADDRX
" %d\n",
7285 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
7286 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
7288 printf("invalid/unsupported opcode: "
7289 "%02x - %02x - %02x (%08x) " ADDRX
" %d\n",
7290 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
7291 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
7294 if (unlikely((ctx
.opcode
& handler
->inval
) != 0)) {
7295 if (loglevel
!= 0) {
7296 fprintf(logfile
, "invalid bits: %08x for opcode: "
7297 "%02x - %02x - %02x (%08x) " ADDRX
"\n",
7298 ctx
.opcode
& handler
->inval
, opc1(ctx
.opcode
),
7299 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
7300 ctx
.opcode
, ctx
.nip
- 4);
7302 printf("invalid bits: %08x for opcode: "
7303 "%02x - %02x - %02x (%08x) " ADDRX
"\n",
7304 ctx
.opcode
& handler
->inval
, opc1(ctx
.opcode
),
7305 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
7306 ctx
.opcode
, ctx
.nip
- 4);
7308 GEN_EXCP_INVAL(ctxp
);
7312 (*(handler
->handler
))(&ctx
);
7313 #if defined(DO_PPC_STATISTICS)
7316 /* Check trace mode exceptions */
7317 if (unlikely(ctx
.singlestep_enabled
& CPU_SINGLE_STEP
&&
7318 (ctx
.nip
<= 0x100 || ctx
.nip
> 0xF00) &&
7319 ctx
.exception
!= POWERPC_SYSCALL
&&
7320 ctx
.exception
!= POWERPC_EXCP_TRAP
&&
7321 ctx
.exception
!= POWERPC_EXCP_BRANCH
)) {
7322 GEN_EXCP(ctxp
, POWERPC_EXCP_TRACE
, 0);
7323 } else if (unlikely(((ctx
.nip
& (TARGET_PAGE_SIZE
- 1)) == 0) ||
7324 (env
->singlestep_enabled
) ||
7325 num_insns
>= max_insns
)) {
7326 /* if we reach a page boundary or are single stepping, stop
7331 #if defined (DO_SINGLE_STEP)
7335 if (tb
->cflags
& CF_LAST_IO
)
7337 if (ctx
.exception
== POWERPC_EXCP_NONE
) {
7338 gen_goto_tb(&ctx
, 0, ctx
.nip
);
7339 } else if (ctx
.exception
!= POWERPC_EXCP_BRANCH
) {
7340 if (unlikely(env
->singlestep_enabled
)) {
7341 gen_update_nip(&ctx
, ctx
.nip
);
7344 /* Generate the return instruction */
7347 gen_icount_end(tb
, num_insns
);
7348 *gen_opc_ptr
= INDEX_op_end
;
7349 if (unlikely(search_pc
)) {
7350 j
= gen_opc_ptr
- gen_opc_buf
;
7353 gen_opc_instr_start
[lj
++] = 0;
7355 tb
->size
= ctx
.nip
- pc_start
;
7356 tb
->icount
= num_insns
;
7358 #if defined(DEBUG_DISAS)
7359 if (loglevel
& CPU_LOG_TB_CPU
) {
7360 fprintf(logfile
, "---------------- excp: %04x\n", ctx
.exception
);
7361 cpu_dump_state(env
, logfile
, fprintf
, 0);
7363 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
7365 flags
= env
->bfd_mach
;
7366 flags
|= little_endian
<< 16;
7367 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
7368 target_disas(logfile
, pc_start
, ctx
.nip
- pc_start
, flags
);
7369 fprintf(logfile
, "\n");
7374 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
7376 gen_intermediate_code_internal(env
, tb
, 0);
7379 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
7381 gen_intermediate_code_internal(env
, tb
, 1);
7384 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
7385 unsigned long searched_pc
, int pc_pos
, void *puc
)
7388 /* for PPC, we need to look at the micro operation to get the
7390 env
->nip
= gen_opc_pc
[pc_pos
];
7391 c
= gen_opc_buf
[pc_pos
];
7393 #if defined(CONFIG_USER_ONLY)
7395 case INDEX_op_ ## op ## _raw
7398 case INDEX_op_ ## op ## _user:\
7399 case INDEX_op_ ## op ## _kernel:\
7400 case INDEX_op_ ## op ## _hypv
7407 type
= ACCESS_FLOAT
;
7423 env
->access_type
= type
;