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"
32 #define CPU_SINGLE_STEP 0x1
33 #define CPU_BRANCH_STEP 0x2
34 #define GDBSTUB_SINGLE_STEP 0x4
36 /* Include definitions for instructions classes and implementations flags */
37 //#define DO_SINGLE_STEP
38 //#define PPC_DEBUG_DISAS
39 //#define DEBUG_MEMORY_ACCESSES
40 //#define DO_PPC_STATISTICS
41 //#define OPTIMIZE_FPRF_UPDATE
43 /*****************************************************************************/
44 /* Code translation helpers */
48 #include "gen-icount.h"
50 void ppc_translate_init(void)
52 static int done_init
= 0;
55 cpu_env
= tcg_global_reg_new(TCG_TYPE_PTR
, TCG_AREG0
, "env");
59 #if defined(OPTIMIZE_FPRF_UPDATE)
60 static uint16_t *gen_fprf_buf
[OPC_BUF_SIZE
];
61 static uint16_t **gen_fprf_ptr
;
64 static always_inline
void gen_set_T0 (target_ulong val
)
66 #if defined(TARGET_PPC64)
68 gen_op_set_T0_64(val
>> 32, val
);
74 static always_inline
void gen_set_T1 (target_ulong val
)
76 #if defined(TARGET_PPC64)
78 gen_op_set_T1_64(val
>> 32, val
);
84 #define GEN8(func, NAME) \
85 static GenOpFunc *NAME ## _table [8] = { \
86 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
87 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
89 static always_inline void func (int n) \
91 NAME ## _table[n](); \
94 #define GEN16(func, NAME) \
95 static GenOpFunc *NAME ## _table [16] = { \
96 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
97 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
98 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
99 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
101 static always_inline void func (int n) \
103 NAME ## _table[n](); \
106 #define GEN32(func, NAME) \
107 static GenOpFunc *NAME ## _table [32] = { \
108 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
109 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
110 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
111 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
112 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
113 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
114 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
115 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
117 static always_inline void func (int n) \
119 NAME ## _table[n](); \
122 /* Condition register moves */
123 GEN8(gen_op_load_crf_T0
, gen_op_load_crf_T0_crf
);
124 GEN8(gen_op_load_crf_T1
, gen_op_load_crf_T1_crf
);
125 GEN8(gen_op_store_T0_crf
, gen_op_store_T0_crf_crf
);
127 GEN8(gen_op_store_T1_crf
, gen_op_store_T1_crf_crf
);
130 /* General purpose registers moves */
131 GEN32(gen_op_load_gpr_T0
, gen_op_load_gpr_T0_gpr
);
132 GEN32(gen_op_load_gpr_T1
, gen_op_load_gpr_T1_gpr
);
133 GEN32(gen_op_load_gpr_T2
, gen_op_load_gpr_T2_gpr
);
135 GEN32(gen_op_store_T0_gpr
, gen_op_store_T0_gpr_gpr
);
136 GEN32(gen_op_store_T1_gpr
, gen_op_store_T1_gpr_gpr
);
138 GEN32(gen_op_store_T2_gpr
, gen_op_store_T2_gpr_gpr
);
141 /* floating point registers moves */
142 GEN32(gen_op_load_fpr_FT0
, gen_op_load_fpr_FT0_fpr
);
143 GEN32(gen_op_load_fpr_FT1
, gen_op_load_fpr_FT1_fpr
);
144 GEN32(gen_op_load_fpr_FT2
, gen_op_load_fpr_FT2_fpr
);
145 GEN32(gen_op_store_FT0_fpr
, gen_op_store_FT0_fpr_fpr
);
146 GEN32(gen_op_store_FT1_fpr
, gen_op_store_FT1_fpr_fpr
);
148 GEN32(gen_op_store_FT2_fpr
, gen_op_store_FT2_fpr_fpr
);
151 /* internal defines */
152 typedef struct DisasContext
{
153 struct TranslationBlock
*tb
;
157 /* Routine used to access memory */
159 /* Translation flags */
160 #if !defined(CONFIG_USER_ONLY)
163 #if defined(TARGET_PPC64)
169 ppc_spr_t
*spr_cb
; /* Needed to check rights for mfspr/mtspr */
170 int singlestep_enabled
;
171 int dcache_line_size
;
174 struct opc_handler_t
{
177 /* instruction type */
180 void (*handler
)(DisasContext
*ctx
);
181 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
182 const unsigned char *oname
;
184 #if defined(DO_PPC_STATISTICS)
189 static always_inline
void gen_set_Rc0 (DisasContext
*ctx
)
191 #if defined(TARGET_PPC64)
200 static always_inline
void gen_reset_fpstatus (void)
202 #ifdef CONFIG_SOFTFLOAT
203 gen_op_reset_fpstatus();
207 static always_inline
void gen_compute_fprf (int set_fprf
, int set_rc
)
210 /* This case might be optimized later */
211 #if defined(OPTIMIZE_FPRF_UPDATE)
212 *gen_fprf_ptr
++ = gen_opc_ptr
;
214 gen_op_compute_fprf(1);
215 if (unlikely(set_rc
))
216 gen_op_store_T0_crf(1);
217 gen_op_float_check_status();
218 } else if (unlikely(set_rc
)) {
219 /* We always need to compute fpcc */
220 gen_op_compute_fprf(0);
221 gen_op_store_T0_crf(1);
223 gen_op_float_check_status();
227 static always_inline
void gen_optimize_fprf (void)
229 #if defined(OPTIMIZE_FPRF_UPDATE)
232 for (ptr
= gen_fprf_buf
; ptr
!= (gen_fprf_ptr
- 1); ptr
++)
233 *ptr
= INDEX_op_nop1
;
234 gen_fprf_ptr
= gen_fprf_buf
;
238 static always_inline
void gen_update_nip (DisasContext
*ctx
, target_ulong nip
)
240 #if defined(TARGET_PPC64)
242 gen_op_update_nip_64(nip
>> 32, nip
);
245 gen_op_update_nip(nip
);
248 #define GEN_EXCP(ctx, excp, error) \
250 if ((ctx)->exception == POWERPC_EXCP_NONE) { \
251 gen_update_nip(ctx, (ctx)->nip); \
253 gen_op_raise_exception_err((excp), (error)); \
254 ctx->exception = (excp); \
257 #define GEN_EXCP_INVAL(ctx) \
258 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
259 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_INVAL)
261 #define GEN_EXCP_PRIVOPC(ctx) \
262 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
263 POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_OPC)
265 #define GEN_EXCP_PRIVREG(ctx) \
266 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
267 POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_REG)
269 #define GEN_EXCP_NO_FP(ctx) \
270 GEN_EXCP(ctx, POWERPC_EXCP_FPU, 0)
272 #define GEN_EXCP_NO_AP(ctx) \
273 GEN_EXCP(ctx, POWERPC_EXCP_APU, 0)
275 #define GEN_EXCP_NO_VR(ctx) \
276 GEN_EXCP(ctx, POWERPC_EXCP_VPU, 0)
278 /* Stop translation */
279 static always_inline
void GEN_STOP (DisasContext
*ctx
)
281 gen_update_nip(ctx
, ctx
->nip
);
282 ctx
->exception
= POWERPC_EXCP_STOP
;
285 /* No need to update nip here, as execution flow will change */
286 static always_inline
void GEN_SYNC (DisasContext
*ctx
)
288 ctx
->exception
= POWERPC_EXCP_SYNC
;
291 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
292 static void gen_##name (DisasContext *ctx); \
293 GEN_OPCODE(name, opc1, opc2, opc3, inval, type); \
294 static void gen_##name (DisasContext *ctx)
296 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
297 static void gen_##name (DisasContext *ctx); \
298 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type); \
299 static void gen_##name (DisasContext *ctx)
301 typedef struct opcode_t
{
302 unsigned char opc1
, opc2
, opc3
;
303 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
304 unsigned char pad
[5];
306 unsigned char pad
[1];
308 opc_handler_t handler
;
309 const unsigned char *oname
;
312 /*****************************************************************************/
313 /*** Instruction decoding ***/
314 #define EXTRACT_HELPER(name, shift, nb) \
315 static always_inline uint32_t name (uint32_t opcode) \
317 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
320 #define EXTRACT_SHELPER(name, shift, nb) \
321 static always_inline int32_t name (uint32_t opcode) \
323 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
327 EXTRACT_HELPER(opc1
, 26, 6);
329 EXTRACT_HELPER(opc2
, 1, 5);
331 EXTRACT_HELPER(opc3
, 6, 5);
332 /* Update Cr0 flags */
333 EXTRACT_HELPER(Rc
, 0, 1);
335 EXTRACT_HELPER(rD
, 21, 5);
337 EXTRACT_HELPER(rS
, 21, 5);
339 EXTRACT_HELPER(rA
, 16, 5);
341 EXTRACT_HELPER(rB
, 11, 5);
343 EXTRACT_HELPER(rC
, 6, 5);
345 EXTRACT_HELPER(crfD
, 23, 3);
346 EXTRACT_HELPER(crfS
, 18, 3);
347 EXTRACT_HELPER(crbD
, 21, 5);
348 EXTRACT_HELPER(crbA
, 16, 5);
349 EXTRACT_HELPER(crbB
, 11, 5);
351 EXTRACT_HELPER(_SPR
, 11, 10);
352 static always_inline
uint32_t SPR (uint32_t opcode
)
354 uint32_t sprn
= _SPR(opcode
);
356 return ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
358 /*** Get constants ***/
359 EXTRACT_HELPER(IMM
, 12, 8);
360 /* 16 bits signed immediate value */
361 EXTRACT_SHELPER(SIMM
, 0, 16);
362 /* 16 bits unsigned immediate value */
363 EXTRACT_HELPER(UIMM
, 0, 16);
365 EXTRACT_HELPER(NB
, 11, 5);
367 EXTRACT_HELPER(SH
, 11, 5);
369 EXTRACT_HELPER(MB
, 6, 5);
371 EXTRACT_HELPER(ME
, 1, 5);
373 EXTRACT_HELPER(TO
, 21, 5);
375 EXTRACT_HELPER(CRM
, 12, 8);
376 EXTRACT_HELPER(FM
, 17, 8);
377 EXTRACT_HELPER(SR
, 16, 4);
378 EXTRACT_HELPER(FPIMM
, 12, 4);
380 /*** Jump target decoding ***/
382 EXTRACT_SHELPER(d
, 0, 16);
383 /* Immediate address */
384 static always_inline target_ulong
LI (uint32_t opcode
)
386 return (opcode
>> 0) & 0x03FFFFFC;
389 static always_inline
uint32_t BD (uint32_t opcode
)
391 return (opcode
>> 0) & 0xFFFC;
394 EXTRACT_HELPER(BO
, 21, 5);
395 EXTRACT_HELPER(BI
, 16, 5);
396 /* Absolute/relative address */
397 EXTRACT_HELPER(AA
, 1, 1);
399 EXTRACT_HELPER(LK
, 0, 1);
401 /* Create a mask between <start> and <end> bits */
402 static always_inline target_ulong
MASK (uint32_t start
, uint32_t end
)
406 #if defined(TARGET_PPC64)
407 if (likely(start
== 0)) {
408 ret
= UINT64_MAX
<< (63 - end
);
409 } else if (likely(end
== 63)) {
410 ret
= UINT64_MAX
>> start
;
413 if (likely(start
== 0)) {
414 ret
= UINT32_MAX
<< (31 - end
);
415 } else if (likely(end
== 31)) {
416 ret
= UINT32_MAX
>> start
;
420 ret
= (((target_ulong
)(-1ULL)) >> (start
)) ^
421 (((target_ulong
)(-1ULL) >> (end
)) >> 1);
422 if (unlikely(start
> end
))
429 /*****************************************************************************/
430 /* PowerPC Instructions types definitions */
432 PPC_NONE
= 0x0000000000000000ULL
,
433 /* PowerPC base instructions set */
434 PPC_INSNS_BASE
= 0x0000000000000001ULL
,
435 /* integer operations instructions */
436 #define PPC_INTEGER PPC_INSNS_BASE
437 /* flow control instructions */
438 #define PPC_FLOW PPC_INSNS_BASE
439 /* virtual memory instructions */
440 #define PPC_MEM PPC_INSNS_BASE
441 /* ld/st with reservation instructions */
442 #define PPC_RES PPC_INSNS_BASE
443 /* spr/msr access instructions */
444 #define PPC_MISC PPC_INSNS_BASE
445 /* Deprecated instruction sets */
446 /* Original POWER instruction set */
447 PPC_POWER
= 0x0000000000000002ULL
,
448 /* POWER2 instruction set extension */
449 PPC_POWER2
= 0x0000000000000004ULL
,
450 /* Power RTC support */
451 PPC_POWER_RTC
= 0x0000000000000008ULL
,
452 /* Power-to-PowerPC bridge (601) */
453 PPC_POWER_BR
= 0x0000000000000010ULL
,
454 /* 64 bits PowerPC instruction set */
455 PPC_64B
= 0x0000000000000020ULL
,
456 /* New 64 bits extensions (PowerPC 2.0x) */
457 PPC_64BX
= 0x0000000000000040ULL
,
458 /* 64 bits hypervisor extensions */
459 PPC_64H
= 0x0000000000000080ULL
,
460 /* New wait instruction (PowerPC 2.0x) */
461 PPC_WAIT
= 0x0000000000000100ULL
,
462 /* Time base mftb instruction */
463 PPC_MFTB
= 0x0000000000000200ULL
,
465 /* Fixed-point unit extensions */
466 /* PowerPC 602 specific */
467 PPC_602_SPEC
= 0x0000000000000400ULL
,
468 /* isel instruction */
469 PPC_ISEL
= 0x0000000000000800ULL
,
470 /* popcntb instruction */
471 PPC_POPCNTB
= 0x0000000000001000ULL
,
472 /* string load / store */
473 PPC_STRING
= 0x0000000000002000ULL
,
475 /* Floating-point unit extensions */
476 /* Optional floating point instructions */
477 PPC_FLOAT
= 0x0000000000010000ULL
,
478 /* New floating-point extensions (PowerPC 2.0x) */
479 PPC_FLOAT_EXT
= 0x0000000000020000ULL
,
480 PPC_FLOAT_FSQRT
= 0x0000000000040000ULL
,
481 PPC_FLOAT_FRES
= 0x0000000000080000ULL
,
482 PPC_FLOAT_FRSQRTE
= 0x0000000000100000ULL
,
483 PPC_FLOAT_FRSQRTES
= 0x0000000000200000ULL
,
484 PPC_FLOAT_FSEL
= 0x0000000000400000ULL
,
485 PPC_FLOAT_STFIWX
= 0x0000000000800000ULL
,
487 /* Vector/SIMD extensions */
488 /* Altivec support */
489 PPC_ALTIVEC
= 0x0000000001000000ULL
,
490 /* PowerPC 2.03 SPE extension */
491 PPC_SPE
= 0x0000000002000000ULL
,
492 /* PowerPC 2.03 SPE floating-point extension */
493 PPC_SPEFPU
= 0x0000000004000000ULL
,
495 /* Optional memory control instructions */
496 PPC_MEM_TLBIA
= 0x0000000010000000ULL
,
497 PPC_MEM_TLBIE
= 0x0000000020000000ULL
,
498 PPC_MEM_TLBSYNC
= 0x0000000040000000ULL
,
499 /* sync instruction */
500 PPC_MEM_SYNC
= 0x0000000080000000ULL
,
501 /* eieio instruction */
502 PPC_MEM_EIEIO
= 0x0000000100000000ULL
,
504 /* Cache control instructions */
505 PPC_CACHE
= 0x0000000200000000ULL
,
506 /* icbi instruction */
507 PPC_CACHE_ICBI
= 0x0000000400000000ULL
,
508 /* dcbz instruction with fixed cache line size */
509 PPC_CACHE_DCBZ
= 0x0000000800000000ULL
,
510 /* dcbz instruction with tunable cache line size */
511 PPC_CACHE_DCBZT
= 0x0000001000000000ULL
,
512 /* dcba instruction */
513 PPC_CACHE_DCBA
= 0x0000002000000000ULL
,
514 /* Freescale cache locking instructions */
515 PPC_CACHE_LOCK
= 0x0000004000000000ULL
,
517 /* MMU related extensions */
518 /* external control instructions */
519 PPC_EXTERN
= 0x0000010000000000ULL
,
520 /* segment register access instructions */
521 PPC_SEGMENT
= 0x0000020000000000ULL
,
522 /* PowerPC 6xx TLB management instructions */
523 PPC_6xx_TLB
= 0x0000040000000000ULL
,
524 /* PowerPC 74xx TLB management instructions */
525 PPC_74xx_TLB
= 0x0000080000000000ULL
,
526 /* PowerPC 40x TLB management instructions */
527 PPC_40x_TLB
= 0x0000100000000000ULL
,
528 /* segment register access instructions for PowerPC 64 "bridge" */
529 PPC_SEGMENT_64B
= 0x0000200000000000ULL
,
531 PPC_SLBI
= 0x0000400000000000ULL
,
533 /* Embedded PowerPC dedicated instructions */
534 PPC_WRTEE
= 0x0001000000000000ULL
,
535 /* PowerPC 40x exception model */
536 PPC_40x_EXCP
= 0x0002000000000000ULL
,
537 /* PowerPC 405 Mac instructions */
538 PPC_405_MAC
= 0x0004000000000000ULL
,
539 /* PowerPC 440 specific instructions */
540 PPC_440_SPEC
= 0x0008000000000000ULL
,
541 /* BookE (embedded) PowerPC specification */
542 PPC_BOOKE
= 0x0010000000000000ULL
,
543 /* mfapidi instruction */
544 PPC_MFAPIDI
= 0x0020000000000000ULL
,
545 /* tlbiva instruction */
546 PPC_TLBIVA
= 0x0040000000000000ULL
,
547 /* tlbivax instruction */
548 PPC_TLBIVAX
= 0x0080000000000000ULL
,
549 /* PowerPC 4xx dedicated instructions */
550 PPC_4xx_COMMON
= 0x0100000000000000ULL
,
551 /* PowerPC 40x ibct instructions */
552 PPC_40x_ICBT
= 0x0200000000000000ULL
,
553 /* rfmci is not implemented in all BookE PowerPC */
554 PPC_RFMCI
= 0x0400000000000000ULL
,
555 /* rfdi instruction */
556 PPC_RFDI
= 0x0800000000000000ULL
,
558 PPC_DCR
= 0x1000000000000000ULL
,
559 /* DCR extended accesse */
560 PPC_DCRX
= 0x2000000000000000ULL
,
561 /* user-mode DCR access, implemented in PowerPC 460 */
562 PPC_DCRUX
= 0x4000000000000000ULL
,
565 /*****************************************************************************/
566 /* PowerPC instructions table */
567 #if HOST_LONG_BITS == 64
572 #if defined(__APPLE__)
573 #define OPCODES_SECTION \
574 __attribute__ ((section("__TEXT,__opcodes"), unused, aligned (OPC_ALIGN) ))
576 #define OPCODES_SECTION \
577 __attribute__ ((section(".opcodes"), unused, aligned (OPC_ALIGN) ))
580 #if defined(DO_PPC_STATISTICS)
581 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
582 OPCODES_SECTION opcode_t opc_##name = { \
590 .handler = &gen_##name, \
591 .oname = stringify(name), \
593 .oname = stringify(name), \
595 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
596 OPCODES_SECTION opcode_t opc_##name = { \
604 .handler = &gen_##name, \
610 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
611 OPCODES_SECTION opcode_t opc_##name = { \
619 .handler = &gen_##name, \
621 .oname = stringify(name), \
623 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
624 OPCODES_SECTION opcode_t opc_##name = { \
632 .handler = &gen_##name, \
638 #define GEN_OPCODE_MARK(name) \
639 OPCODES_SECTION opcode_t opc_##name = { \
645 .inval = 0x00000000, \
649 .oname = stringify(name), \
652 /* Start opcode list */
653 GEN_OPCODE_MARK(start
);
655 /* Invalid instruction */
656 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
)
661 static opc_handler_t invalid_handler
= {
664 .handler
= gen_invalid
,
667 /*** Integer arithmetic ***/
668 #define __GEN_INT_ARITH2(name, opc1, opc2, opc3, inval, type) \
669 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
671 gen_op_load_gpr_T0(rA(ctx->opcode)); \
672 gen_op_load_gpr_T1(rB(ctx->opcode)); \
674 gen_op_store_T0_gpr(rD(ctx->opcode)); \
675 if (unlikely(Rc(ctx->opcode) != 0)) \
679 #define __GEN_INT_ARITH2_O(name, opc1, opc2, opc3, inval, type) \
680 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
682 gen_op_load_gpr_T0(rA(ctx->opcode)); \
683 gen_op_load_gpr_T1(rB(ctx->opcode)); \
685 gen_op_store_T0_gpr(rD(ctx->opcode)); \
686 if (unlikely(Rc(ctx->opcode) != 0)) \
690 #define __GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
691 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
693 gen_op_load_gpr_T0(rA(ctx->opcode)); \
695 gen_op_store_T0_gpr(rD(ctx->opcode)); \
696 if (unlikely(Rc(ctx->opcode) != 0)) \
699 #define __GEN_INT_ARITH1_O(name, opc1, opc2, opc3, type) \
700 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
702 gen_op_load_gpr_T0(rA(ctx->opcode)); \
704 gen_op_store_T0_gpr(rD(ctx->opcode)); \
705 if (unlikely(Rc(ctx->opcode) != 0)) \
709 /* Two operands arithmetic functions */
710 #define GEN_INT_ARITH2(name, opc1, opc2, opc3, type) \
711 __GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000000, type) \
712 __GEN_INT_ARITH2_O(name##o, opc1, opc2, opc3 | 0x10, 0x00000000, type)
714 /* Two operands arithmetic functions with no overflow allowed */
715 #define GEN_INT_ARITHN(name, opc1, opc2, opc3, type) \
716 __GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000400, type)
718 /* One operand arithmetic functions */
719 #define GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
720 __GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
721 __GEN_INT_ARITH1_O(name##o, opc1, opc2, opc3 | 0x10, type)
723 #if defined(TARGET_PPC64)
724 #define __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, inval, type) \
725 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
727 gen_op_load_gpr_T0(rA(ctx->opcode)); \
728 gen_op_load_gpr_T1(rB(ctx->opcode)); \
730 gen_op_##name##_64(); \
733 gen_op_store_T0_gpr(rD(ctx->opcode)); \
734 if (unlikely(Rc(ctx->opcode) != 0)) \
738 #define __GEN_INT_ARITH2_O_64(name, opc1, opc2, opc3, inval, type) \
739 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
741 gen_op_load_gpr_T0(rA(ctx->opcode)); \
742 gen_op_load_gpr_T1(rB(ctx->opcode)); \
744 gen_op_##name##_64(); \
747 gen_op_store_T0_gpr(rD(ctx->opcode)); \
748 if (unlikely(Rc(ctx->opcode) != 0)) \
752 #define __GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
753 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
755 gen_op_load_gpr_T0(rA(ctx->opcode)); \
757 gen_op_##name##_64(); \
760 gen_op_store_T0_gpr(rD(ctx->opcode)); \
761 if (unlikely(Rc(ctx->opcode) != 0)) \
764 #define __GEN_INT_ARITH1_O_64(name, opc1, opc2, opc3, type) \
765 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
767 gen_op_load_gpr_T0(rA(ctx->opcode)); \
769 gen_op_##name##_64(); \
772 gen_op_store_T0_gpr(rD(ctx->opcode)); \
773 if (unlikely(Rc(ctx->opcode) != 0)) \
777 /* Two operands arithmetic functions */
778 #define GEN_INT_ARITH2_64(name, opc1, opc2, opc3, type) \
779 __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, 0x00000000, type) \
780 __GEN_INT_ARITH2_O_64(name##o, opc1, opc2, opc3 | 0x10, 0x00000000, type)
782 /* Two operands arithmetic functions with no overflow allowed */
783 #define GEN_INT_ARITHN_64(name, opc1, opc2, opc3, type) \
784 __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, 0x00000400, type)
786 /* One operand arithmetic functions */
787 #define GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
788 __GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
789 __GEN_INT_ARITH1_O_64(name##o, opc1, opc2, opc3 | 0x10, type)
791 #define GEN_INT_ARITH2_64 GEN_INT_ARITH2
792 #define GEN_INT_ARITHN_64 GEN_INT_ARITHN
793 #define GEN_INT_ARITH1_64 GEN_INT_ARITH1
796 /* add add. addo addo. */
797 static always_inline
void gen_op_addo (void)
803 #if defined(TARGET_PPC64)
804 #define gen_op_add_64 gen_op_add
805 static always_inline
void gen_op_addo_64 (void)
809 gen_op_check_addo_64();
812 GEN_INT_ARITH2_64 (add
, 0x1F, 0x0A, 0x08, PPC_INTEGER
);
813 /* addc addc. addco addco. */
814 static always_inline
void gen_op_addc (void)
820 static always_inline
void gen_op_addco (void)
827 #if defined(TARGET_PPC64)
828 static always_inline
void gen_op_addc_64 (void)
832 gen_op_check_addc_64();
834 static always_inline
void gen_op_addco_64 (void)
838 gen_op_check_addc_64();
839 gen_op_check_addo_64();
842 GEN_INT_ARITH2_64 (addc
, 0x1F, 0x0A, 0x00, PPC_INTEGER
);
843 /* adde adde. addeo addeo. */
844 static always_inline
void gen_op_addeo (void)
850 #if defined(TARGET_PPC64)
851 static always_inline
void gen_op_addeo_64 (void)
855 gen_op_check_addo_64();
858 GEN_INT_ARITH2_64 (adde
, 0x1F, 0x0A, 0x04, PPC_INTEGER
);
859 /* addme addme. addmeo addmeo. */
860 static always_inline
void gen_op_addme (void)
865 #if defined(TARGET_PPC64)
866 static always_inline
void gen_op_addme_64 (void)
872 GEN_INT_ARITH1_64 (addme
, 0x1F, 0x0A, 0x07, PPC_INTEGER
);
873 /* addze addze. addzeo addzeo. */
874 static always_inline
void gen_op_addze (void)
880 static always_inline
void gen_op_addzeo (void)
887 #if defined(TARGET_PPC64)
888 static always_inline
void gen_op_addze_64 (void)
892 gen_op_check_addc_64();
894 static always_inline
void gen_op_addzeo_64 (void)
898 gen_op_check_addc_64();
899 gen_op_check_addo_64();
902 GEN_INT_ARITH1_64 (addze
, 0x1F, 0x0A, 0x06, PPC_INTEGER
);
903 /* divw divw. divwo divwo. */
904 GEN_INT_ARITH2 (divw
, 0x1F, 0x0B, 0x0F, PPC_INTEGER
);
905 /* divwu divwu. divwuo divwuo. */
906 GEN_INT_ARITH2 (divwu
, 0x1F, 0x0B, 0x0E, PPC_INTEGER
);
908 GEN_INT_ARITHN (mulhw
, 0x1F, 0x0B, 0x02, PPC_INTEGER
);
910 GEN_INT_ARITHN (mulhwu
, 0x1F, 0x0B, 0x00, PPC_INTEGER
);
911 /* mullw mullw. mullwo mullwo. */
912 GEN_INT_ARITH2 (mullw
, 0x1F, 0x0B, 0x07, PPC_INTEGER
);
913 /* neg neg. nego nego. */
914 GEN_INT_ARITH1_64 (neg
, 0x1F, 0x08, 0x03, PPC_INTEGER
);
915 /* subf subf. subfo subfo. */
916 static always_inline
void gen_op_subfo (void)
918 gen_op_moven_T2_T0();
922 #if defined(TARGET_PPC64)
923 #define gen_op_subf_64 gen_op_subf
924 static always_inline
void gen_op_subfo_64 (void)
926 gen_op_moven_T2_T0();
928 gen_op_check_addo_64();
931 GEN_INT_ARITH2_64 (subf
, 0x1F, 0x08, 0x01, PPC_INTEGER
);
932 /* subfc subfc. subfco subfco. */
933 static always_inline
void gen_op_subfc (void)
936 gen_op_check_subfc();
938 static always_inline
void gen_op_subfco (void)
940 gen_op_moven_T2_T0();
942 gen_op_check_subfc();
945 #if defined(TARGET_PPC64)
946 static always_inline
void gen_op_subfc_64 (void)
949 gen_op_check_subfc_64();
951 static always_inline
void gen_op_subfco_64 (void)
953 gen_op_moven_T2_T0();
955 gen_op_check_subfc_64();
956 gen_op_check_addo_64();
959 GEN_INT_ARITH2_64 (subfc
, 0x1F, 0x08, 0x00, PPC_INTEGER
);
960 /* subfe subfe. subfeo subfeo. */
961 static always_inline
void gen_op_subfeo (void)
963 gen_op_moven_T2_T0();
967 #if defined(TARGET_PPC64)
968 #define gen_op_subfe_64 gen_op_subfe
969 static always_inline
void gen_op_subfeo_64 (void)
971 gen_op_moven_T2_T0();
973 gen_op_check_addo_64();
976 GEN_INT_ARITH2_64 (subfe
, 0x1F, 0x08, 0x04, PPC_INTEGER
);
977 /* subfme subfme. subfmeo subfmeo. */
978 GEN_INT_ARITH1_64 (subfme
, 0x1F, 0x08, 0x07, PPC_INTEGER
);
979 /* subfze subfze. subfzeo subfzeo. */
980 GEN_INT_ARITH1_64 (subfze
, 0x1F, 0x08, 0x06, PPC_INTEGER
);
982 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
984 target_long simm
= SIMM(ctx
->opcode
);
986 if (rA(ctx
->opcode
) == 0) {
990 gen_op_load_gpr_T0(rA(ctx
->opcode
));
991 if (likely(simm
!= 0))
994 gen_op_store_T0_gpr(rD(ctx
->opcode
));
997 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
999 target_long simm
= SIMM(ctx
->opcode
);
1001 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1002 if (likely(simm
!= 0)) {
1003 gen_op_move_T2_T0();
1005 #if defined(TARGET_PPC64)
1007 gen_op_check_addc_64();
1010 gen_op_check_addc();
1012 gen_op_clear_xer_ca();
1014 gen_op_store_T0_gpr(rD(ctx
->opcode
));
1017 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1019 target_long simm
= SIMM(ctx
->opcode
);
1021 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1022 if (likely(simm
!= 0)) {
1023 gen_op_move_T2_T0();
1025 #if defined(TARGET_PPC64)
1027 gen_op_check_addc_64();
1030 gen_op_check_addc();
1032 gen_op_clear_xer_ca();
1034 gen_op_store_T0_gpr(rD(ctx
->opcode
));
1038 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1040 target_long simm
= SIMM(ctx
->opcode
);
1042 if (rA(ctx
->opcode
) == 0) {
1044 gen_set_T0(simm
<< 16);
1046 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1047 if (likely(simm
!= 0))
1048 gen_op_addi(simm
<< 16);
1050 gen_op_store_T0_gpr(rD(ctx
->opcode
));
1053 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1055 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1056 gen_op_mulli(SIMM(ctx
->opcode
));
1057 gen_op_store_T0_gpr(rD(ctx
->opcode
));
1060 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1062 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1063 #if defined(TARGET_PPC64)
1065 gen_op_subfic_64(SIMM(ctx
->opcode
));
1068 gen_op_subfic(SIMM(ctx
->opcode
));
1069 gen_op_store_T0_gpr(rD(ctx
->opcode
));
1072 #if defined(TARGET_PPC64)
1074 GEN_INT_ARITHN (mulhd
, 0x1F, 0x09, 0x02, PPC_64B
);
1075 /* mulhdu mulhdu. */
1076 GEN_INT_ARITHN (mulhdu
, 0x1F, 0x09, 0x00, PPC_64B
);
1077 /* mulld mulld. mulldo mulldo. */
1078 GEN_INT_ARITH2 (mulld
, 0x1F, 0x09, 0x07, PPC_64B
);
1079 /* divd divd. divdo divdo. */
1080 GEN_INT_ARITH2 (divd
, 0x1F, 0x09, 0x0F, PPC_64B
);
1081 /* divdu divdu. divduo divduo. */
1082 GEN_INT_ARITH2 (divdu
, 0x1F, 0x09, 0x0E, PPC_64B
);
1085 /*** Integer comparison ***/
1086 #if defined(TARGET_PPC64)
1087 #define GEN_CMP(name, opc, type) \
1088 GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, type) \
1090 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1091 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1092 if (ctx->sf_mode && (ctx->opcode & 0x00200000)) \
1093 gen_op_##name##_64(); \
1096 gen_op_store_T0_crf(crfD(ctx->opcode)); \
1099 #define GEN_CMP(name, opc, type) \
1100 GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, type) \
1102 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1103 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1105 gen_op_store_T0_crf(crfD(ctx->opcode)); \
1110 GEN_CMP(cmp
, 0x00, PPC_INTEGER
);
1112 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
)
1114 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1115 #if defined(TARGET_PPC64)
1116 if (ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000))
1117 gen_op_cmpi_64(SIMM(ctx
->opcode
));
1120 gen_op_cmpi(SIMM(ctx
->opcode
));
1121 gen_op_store_T0_crf(crfD(ctx
->opcode
));
1124 GEN_CMP(cmpl
, 0x01, PPC_INTEGER
);
1126 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
)
1128 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1129 #if defined(TARGET_PPC64)
1130 if (ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000))
1131 gen_op_cmpli_64(UIMM(ctx
->opcode
));
1134 gen_op_cmpli(UIMM(ctx
->opcode
));
1135 gen_op_store_T0_crf(crfD(ctx
->opcode
));
1138 /* isel (PowerPC 2.03 specification) */
1139 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
)
1141 uint32_t bi
= rC(ctx
->opcode
);
1144 if (rA(ctx
->opcode
) == 0) {
1147 gen_op_load_gpr_T1(rA(ctx
->opcode
));
1149 gen_op_load_gpr_T2(rB(ctx
->opcode
));
1150 mask
= 1 << (3 - (bi
& 0x03));
1151 gen_op_load_crf_T0(bi
>> 2);
1152 gen_op_test_true(mask
);
1154 gen_op_store_T0_gpr(rD(ctx
->opcode
));
1157 /*** Integer logical ***/
1158 #define __GEN_LOGICAL2(name, opc2, opc3, type) \
1159 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000000, type) \
1161 gen_op_load_gpr_T0(rS(ctx->opcode)); \
1162 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1164 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1165 if (unlikely(Rc(ctx->opcode) != 0)) \
1168 #define GEN_LOGICAL2(name, opc, type) \
1169 __GEN_LOGICAL2(name, 0x1C, opc, type)
1171 #define GEN_LOGICAL1(name, opc, type) \
1172 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type) \
1174 gen_op_load_gpr_T0(rS(ctx->opcode)); \
1176 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1177 if (unlikely(Rc(ctx->opcode) != 0)) \
1182 GEN_LOGICAL2(and, 0x00, PPC_INTEGER
);
1184 GEN_LOGICAL2(andc
, 0x01, PPC_INTEGER
);
1186 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1188 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1189 gen_op_andi_T0(UIMM(ctx
->opcode
));
1190 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1194 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1196 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1197 gen_op_andi_T0(UIMM(ctx
->opcode
) << 16);
1198 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1203 GEN_LOGICAL1(cntlzw
, 0x00, PPC_INTEGER
);
1205 GEN_LOGICAL2(eqv
, 0x08, PPC_INTEGER
);
1206 /* extsb & extsb. */
1207 GEN_LOGICAL1(extsb
, 0x1D, PPC_INTEGER
);
1208 /* extsh & extsh. */
1209 GEN_LOGICAL1(extsh
, 0x1C, PPC_INTEGER
);
1211 GEN_LOGICAL2(nand
, 0x0E, PPC_INTEGER
);
1213 GEN_LOGICAL2(nor
, 0x03, PPC_INTEGER
);
1216 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
)
1220 rs
= rS(ctx
->opcode
);
1221 ra
= rA(ctx
->opcode
);
1222 rb
= rB(ctx
->opcode
);
1223 /* Optimisation for mr. ri case */
1224 if (rs
!= ra
|| rs
!= rb
) {
1225 gen_op_load_gpr_T0(rs
);
1227 gen_op_load_gpr_T1(rb
);
1230 gen_op_store_T0_gpr(ra
);
1231 if (unlikely(Rc(ctx
->opcode
) != 0))
1233 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
1234 gen_op_load_gpr_T0(rs
);
1236 #if defined(TARGET_PPC64)
1240 /* Set process priority to low */
1241 gen_op_store_pri(2);
1244 /* Set process priority to medium-low */
1245 gen_op_store_pri(3);
1248 /* Set process priority to normal */
1249 gen_op_store_pri(4);
1251 #if !defined(CONFIG_USER_ONLY)
1253 if (ctx
->supervisor
> 0) {
1254 /* Set process priority to very low */
1255 gen_op_store_pri(1);
1259 if (ctx
->supervisor
> 0) {
1260 /* Set process priority to medium-hight */
1261 gen_op_store_pri(5);
1265 if (ctx
->supervisor
> 0) {
1266 /* Set process priority to high */
1267 gen_op_store_pri(6);
1271 if (ctx
->supervisor
> 1) {
1272 /* Set process priority to very high */
1273 gen_op_store_pri(7);
1286 GEN_LOGICAL2(orc
, 0x0C, PPC_INTEGER
);
1288 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
)
1290 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1291 /* Optimisation for "set to zero" case */
1292 if (rS(ctx
->opcode
) != rB(ctx
->opcode
)) {
1293 gen_op_load_gpr_T1(rB(ctx
->opcode
));
1298 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1299 if (unlikely(Rc(ctx
->opcode
) != 0))
1303 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1305 target_ulong uimm
= UIMM(ctx
->opcode
);
1307 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1309 /* XXX: should handle special NOPs for POWER series */
1312 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1313 if (likely(uimm
!= 0))
1315 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1318 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1320 target_ulong uimm
= UIMM(ctx
->opcode
);
1322 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1326 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1327 if (likely(uimm
!= 0))
1328 gen_op_ori(uimm
<< 16);
1329 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1332 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1334 target_ulong uimm
= UIMM(ctx
->opcode
);
1336 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1340 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1341 if (likely(uimm
!= 0))
1343 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1347 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1349 target_ulong uimm
= UIMM(ctx
->opcode
);
1351 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1355 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1356 if (likely(uimm
!= 0))
1357 gen_op_xori(uimm
<< 16);
1358 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1361 /* popcntb : PowerPC 2.03 specification */
1362 GEN_HANDLER(popcntb
, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB
)
1364 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1365 #if defined(TARGET_PPC64)
1367 gen_op_popcntb_64();
1371 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1374 #if defined(TARGET_PPC64)
1375 /* extsw & extsw. */
1376 GEN_LOGICAL1(extsw
, 0x1E, PPC_64B
);
1378 GEN_LOGICAL1(cntlzd
, 0x01, PPC_64B
);
1381 /*** Integer rotate ***/
1382 /* rlwimi & rlwimi. */
1383 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1386 uint32_t mb
, me
, sh
;
1388 mb
= MB(ctx
->opcode
);
1389 me
= ME(ctx
->opcode
);
1390 sh
= SH(ctx
->opcode
);
1391 if (likely(sh
== 0)) {
1392 if (likely(mb
== 0 && me
== 31)) {
1393 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1395 } else if (likely(mb
== 31 && me
== 0)) {
1396 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1399 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1400 gen_op_load_gpr_T1(rA(ctx
->opcode
));
1403 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1404 gen_op_load_gpr_T1(rA(ctx
->opcode
));
1405 gen_op_rotli32_T0(SH(ctx
->opcode
));
1407 #if defined(TARGET_PPC64)
1411 mask
= MASK(mb
, me
);
1412 gen_op_andi_T0(mask
);
1413 gen_op_andi_T1(~mask
);
1416 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1417 if (unlikely(Rc(ctx
->opcode
) != 0))
1420 /* rlwinm & rlwinm. */
1421 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1423 uint32_t mb
, me
, sh
;
1425 sh
= SH(ctx
->opcode
);
1426 mb
= MB(ctx
->opcode
);
1427 me
= ME(ctx
->opcode
);
1428 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1429 if (likely(sh
== 0)) {
1432 if (likely(mb
== 0)) {
1433 if (likely(me
== 31)) {
1434 gen_op_rotli32_T0(sh
);
1436 } else if (likely(me
== (31 - sh
))) {
1440 } else if (likely(me
== 31)) {
1441 if (likely(sh
== (32 - mb
))) {
1446 gen_op_rotli32_T0(sh
);
1448 #if defined(TARGET_PPC64)
1452 gen_op_andi_T0(MASK(mb
, me
));
1454 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1455 if (unlikely(Rc(ctx
->opcode
) != 0))
1458 /* rlwnm & rlwnm. */
1459 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1463 mb
= MB(ctx
->opcode
);
1464 me
= ME(ctx
->opcode
);
1465 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1466 gen_op_load_gpr_T1(rB(ctx
->opcode
));
1467 gen_op_rotl32_T0_T1();
1468 if (unlikely(mb
!= 0 || me
!= 31)) {
1469 #if defined(TARGET_PPC64)
1473 gen_op_andi_T0(MASK(mb
, me
));
1475 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1476 if (unlikely(Rc(ctx
->opcode
) != 0))
1480 #if defined(TARGET_PPC64)
1481 #define GEN_PPC64_R2(name, opc1, opc2) \
1482 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1484 gen_##name(ctx, 0); \
1486 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1489 gen_##name(ctx, 1); \
1491 #define GEN_PPC64_R4(name, opc1, opc2) \
1492 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1494 gen_##name(ctx, 0, 0); \
1496 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
1499 gen_##name(ctx, 0, 1); \
1501 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1504 gen_##name(ctx, 1, 0); \
1506 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
1509 gen_##name(ctx, 1, 1); \
1512 static always_inline
void gen_andi_T0_64 (DisasContext
*ctx
, uint64_t mask
)
1515 gen_op_andi_T0_64(mask
>> 32, mask
& 0xFFFFFFFF);
1517 gen_op_andi_T0(mask
);
1520 static always_inline
void gen_andi_T1_64 (DisasContext
*ctx
, uint64_t mask
)
1523 gen_op_andi_T1_64(mask
>> 32, mask
& 0xFFFFFFFF);
1525 gen_op_andi_T1(mask
);
1528 static always_inline
void gen_rldinm (DisasContext
*ctx
, uint32_t mb
,
1529 uint32_t me
, uint32_t sh
)
1531 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1532 if (likely(sh
== 0)) {
1535 if (likely(mb
== 0)) {
1536 if (likely(me
== 63)) {
1537 gen_op_rotli64_T0(sh
);
1539 } else if (likely(me
== (63 - sh
))) {
1543 } else if (likely(me
== 63)) {
1544 if (likely(sh
== (64 - mb
))) {
1545 gen_op_srli_T0_64(mb
);
1549 gen_op_rotli64_T0(sh
);
1551 gen_andi_T0_64(ctx
, MASK(mb
, me
));
1553 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1554 if (unlikely(Rc(ctx
->opcode
) != 0))
1557 /* rldicl - rldicl. */
1558 static always_inline
void gen_rldicl (DisasContext
*ctx
, int mbn
, int shn
)
1562 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1563 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1564 gen_rldinm(ctx
, mb
, 63, sh
);
1566 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
1567 /* rldicr - rldicr. */
1568 static always_inline
void gen_rldicr (DisasContext
*ctx
, int men
, int shn
)
1572 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1573 me
= MB(ctx
->opcode
) | (men
<< 5);
1574 gen_rldinm(ctx
, 0, me
, sh
);
1576 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
1577 /* rldic - rldic. */
1578 static always_inline
void gen_rldic (DisasContext
*ctx
, int mbn
, int shn
)
1582 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1583 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1584 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
1586 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
1588 static always_inline
void gen_rldnm (DisasContext
*ctx
, uint32_t mb
,
1591 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1592 gen_op_load_gpr_T1(rB(ctx
->opcode
));
1593 gen_op_rotl64_T0_T1();
1594 if (unlikely(mb
!= 0 || me
!= 63)) {
1595 gen_andi_T0_64(ctx
, MASK(mb
, me
));
1597 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1598 if (unlikely(Rc(ctx
->opcode
) != 0))
1602 /* rldcl - rldcl. */
1603 static always_inline
void gen_rldcl (DisasContext
*ctx
, int mbn
)
1607 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1608 gen_rldnm(ctx
, mb
, 63);
1610 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
1611 /* rldcr - rldcr. */
1612 static always_inline
void gen_rldcr (DisasContext
*ctx
, int men
)
1616 me
= MB(ctx
->opcode
) | (men
<< 5);
1617 gen_rldnm(ctx
, 0, me
);
1619 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
1620 /* rldimi - rldimi. */
1621 static always_inline
void gen_rldimi (DisasContext
*ctx
, int mbn
, int shn
)
1624 uint32_t sh
, mb
, me
;
1626 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1627 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1629 if (likely(sh
== 0)) {
1630 if (likely(mb
== 0)) {
1631 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1634 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1635 gen_op_load_gpr_T1(rA(ctx
->opcode
));
1638 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1639 gen_op_load_gpr_T1(rA(ctx
->opcode
));
1640 gen_op_rotli64_T0(sh
);
1642 mask
= MASK(mb
, me
);
1643 gen_andi_T0_64(ctx
, mask
);
1644 gen_andi_T1_64(ctx
, ~mask
);
1647 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1648 if (unlikely(Rc(ctx
->opcode
) != 0))
1651 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
1654 /*** Integer shift ***/
1656 __GEN_LOGICAL2(slw
, 0x18, 0x00, PPC_INTEGER
);
1658 __GEN_LOGICAL2(sraw
, 0x18, 0x18, PPC_INTEGER
);
1659 /* srawi & srawi. */
1660 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
)
1663 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1664 if (SH(ctx
->opcode
) != 0) {
1665 gen_op_move_T1_T0();
1666 mb
= 32 - SH(ctx
->opcode
);
1668 #if defined(TARGET_PPC64)
1672 gen_op_srawi(SH(ctx
->opcode
), MASK(mb
, me
));
1674 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1675 if (unlikely(Rc(ctx
->opcode
) != 0))
1679 __GEN_LOGICAL2(srw
, 0x18, 0x10, PPC_INTEGER
);
1681 #if defined(TARGET_PPC64)
1683 __GEN_LOGICAL2(sld
, 0x1B, 0x00, PPC_64B
);
1685 __GEN_LOGICAL2(srad
, 0x1A, 0x18, PPC_64B
);
1686 /* sradi & sradi. */
1687 static always_inline
void gen_sradi (DisasContext
*ctx
, int n
)
1692 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1693 sh
= SH(ctx
->opcode
) + (n
<< 5);
1695 gen_op_move_T1_T0();
1696 mb
= 64 - SH(ctx
->opcode
);
1698 mask
= MASK(mb
, me
);
1699 gen_op_sradi(sh
, mask
>> 32, mask
);
1701 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1702 if (unlikely(Rc(ctx
->opcode
) != 0))
1705 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
)
1709 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
)
1714 __GEN_LOGICAL2(srd
, 0x1B, 0x10, PPC_64B
);
1717 /*** Floating-Point arithmetic ***/
1718 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
1719 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type) \
1721 if (unlikely(!ctx->fpu_enabled)) { \
1722 GEN_EXCP_NO_FP(ctx); \
1725 gen_op_load_fpr_FT0(rA(ctx->opcode)); \
1726 gen_op_load_fpr_FT1(rC(ctx->opcode)); \
1727 gen_op_load_fpr_FT2(rB(ctx->opcode)); \
1728 gen_reset_fpstatus(); \
1733 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1734 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
1737 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
1738 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
1739 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
1741 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
1742 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
1744 if (unlikely(!ctx->fpu_enabled)) { \
1745 GEN_EXCP_NO_FP(ctx); \
1748 gen_op_load_fpr_FT0(rA(ctx->opcode)); \
1749 gen_op_load_fpr_FT1(rB(ctx->opcode)); \
1750 gen_reset_fpstatus(); \
1755 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1756 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
1758 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
1759 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
1760 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
1762 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
1763 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
1765 if (unlikely(!ctx->fpu_enabled)) { \
1766 GEN_EXCP_NO_FP(ctx); \
1769 gen_op_load_fpr_FT0(rA(ctx->opcode)); \
1770 gen_op_load_fpr_FT1(rC(ctx->opcode)); \
1771 gen_reset_fpstatus(); \
1776 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1777 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
1779 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
1780 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
1781 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
1783 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
1784 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type) \
1786 if (unlikely(!ctx->fpu_enabled)) { \
1787 GEN_EXCP_NO_FP(ctx); \
1790 gen_op_load_fpr_FT0(rB(ctx->opcode)); \
1791 gen_reset_fpstatus(); \
1793 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1794 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
1797 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
1798 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type) \
1800 if (unlikely(!ctx->fpu_enabled)) { \
1801 GEN_EXCP_NO_FP(ctx); \
1804 gen_op_load_fpr_FT0(rB(ctx->opcode)); \
1805 gen_reset_fpstatus(); \
1807 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1808 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
1812 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
);
1814 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
);
1816 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
);
1819 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
);
1822 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
);
1825 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
);
1828 static always_inline
void gen_op_frsqrtes (void)
1833 GEN_FLOAT_BS(rsqrtes
, 0x3B, 0x1A, 1, PPC_FLOAT_FRSQRTES
);
1836 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
);
1838 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
);
1841 GEN_HANDLER(fsqrt
, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
)
1843 if (unlikely(!ctx
->fpu_enabled
)) {
1844 GEN_EXCP_NO_FP(ctx
);
1847 gen_op_load_fpr_FT0(rB(ctx
->opcode
));
1848 gen_reset_fpstatus();
1850 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
1851 gen_compute_fprf(1, Rc(ctx
->opcode
) != 0);
1854 GEN_HANDLER(fsqrts
, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
)
1856 if (unlikely(!ctx
->fpu_enabled
)) {
1857 GEN_EXCP_NO_FP(ctx
);
1860 gen_op_load_fpr_FT0(rB(ctx
->opcode
));
1861 gen_reset_fpstatus();
1864 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
1865 gen_compute_fprf(1, Rc(ctx
->opcode
) != 0);
1868 /*** Floating-Point multiply-and-add ***/
1869 /* fmadd - fmadds */
1870 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
);
1871 /* fmsub - fmsubs */
1872 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
);
1873 /* fnmadd - fnmadds */
1874 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
);
1875 /* fnmsub - fnmsubs */
1876 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
);
1878 /*** Floating-Point round & convert ***/
1880 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
);
1882 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
);
1884 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
);
1885 #if defined(TARGET_PPC64)
1887 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
);
1889 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
);
1891 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
);
1895 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
);
1897 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
);
1899 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
);
1901 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
);
1903 /*** Floating-Point compare ***/
1905 GEN_HANDLER(fcmpo
, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT
)
1907 if (unlikely(!ctx
->fpu_enabled
)) {
1908 GEN_EXCP_NO_FP(ctx
);
1911 gen_op_load_fpr_FT0(rA(ctx
->opcode
));
1912 gen_op_load_fpr_FT1(rB(ctx
->opcode
));
1913 gen_reset_fpstatus();
1915 gen_op_store_T0_crf(crfD(ctx
->opcode
));
1916 gen_op_float_check_status();
1920 GEN_HANDLER(fcmpu
, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT
)
1922 if (unlikely(!ctx
->fpu_enabled
)) {
1923 GEN_EXCP_NO_FP(ctx
);
1926 gen_op_load_fpr_FT0(rA(ctx
->opcode
));
1927 gen_op_load_fpr_FT1(rB(ctx
->opcode
));
1928 gen_reset_fpstatus();
1930 gen_op_store_T0_crf(crfD(ctx
->opcode
));
1931 gen_op_float_check_status();
1934 /*** Floating-point move ***/
1936 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
1937 GEN_FLOAT_B(abs
, 0x08, 0x08, 0, PPC_FLOAT
);
1940 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
1941 GEN_HANDLER(fmr
, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT
)
1943 if (unlikely(!ctx
->fpu_enabled
)) {
1944 GEN_EXCP_NO_FP(ctx
);
1947 gen_op_load_fpr_FT0(rB(ctx
->opcode
));
1948 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
1949 gen_compute_fprf(0, Rc(ctx
->opcode
) != 0);
1953 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
1954 GEN_FLOAT_B(nabs
, 0x08, 0x04, 0, PPC_FLOAT
);
1956 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
1957 GEN_FLOAT_B(neg
, 0x08, 0x01, 0, PPC_FLOAT
);
1959 /*** Floating-Point status & ctrl register ***/
1961 GEN_HANDLER(mcrfs
, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT
)
1965 if (unlikely(!ctx
->fpu_enabled
)) {
1966 GEN_EXCP_NO_FP(ctx
);
1969 gen_optimize_fprf();
1970 bfa
= 4 * (7 - crfS(ctx
->opcode
));
1971 gen_op_load_fpscr_T0(bfa
);
1972 gen_op_store_T0_crf(crfD(ctx
->opcode
));
1973 gen_op_fpscr_resetbit(~(0xF << bfa
));
1977 GEN_HANDLER(mffs
, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT
)
1979 if (unlikely(!ctx
->fpu_enabled
)) {
1980 GEN_EXCP_NO_FP(ctx
);
1983 gen_optimize_fprf();
1984 gen_reset_fpstatus();
1985 gen_op_load_fpscr_FT0();
1986 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
1987 gen_compute_fprf(0, Rc(ctx
->opcode
) != 0);
1991 GEN_HANDLER(mtfsb0
, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT
)
1995 if (unlikely(!ctx
->fpu_enabled
)) {
1996 GEN_EXCP_NO_FP(ctx
);
1999 crb
= 32 - (crbD(ctx
->opcode
) >> 2);
2000 gen_optimize_fprf();
2001 gen_reset_fpstatus();
2002 if (likely(crb
!= 30 && crb
!= 29))
2003 gen_op_fpscr_resetbit(~(1 << crb
));
2004 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2011 GEN_HANDLER(mtfsb1
, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT
)
2015 if (unlikely(!ctx
->fpu_enabled
)) {
2016 GEN_EXCP_NO_FP(ctx
);
2019 crb
= 32 - (crbD(ctx
->opcode
) >> 2);
2020 gen_optimize_fprf();
2021 gen_reset_fpstatus();
2022 /* XXX: we pretend we can only do IEEE floating-point computations */
2023 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
&& crb
!= FPSCR_NI
))
2024 gen_op_fpscr_setbit(crb
);
2025 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2029 /* We can raise a differed exception */
2030 gen_op_float_check_status();
2034 GEN_HANDLER(mtfsf
, 0x3F, 0x07, 0x16, 0x02010000, PPC_FLOAT
)
2036 if (unlikely(!ctx
->fpu_enabled
)) {
2037 GEN_EXCP_NO_FP(ctx
);
2040 gen_optimize_fprf();
2041 gen_op_load_fpr_FT0(rB(ctx
->opcode
));
2042 gen_reset_fpstatus();
2043 gen_op_store_fpscr(FM(ctx
->opcode
));
2044 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2048 /* We can raise a differed exception */
2049 gen_op_float_check_status();
2053 GEN_HANDLER(mtfsfi
, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT
)
2057 if (unlikely(!ctx
->fpu_enabled
)) {
2058 GEN_EXCP_NO_FP(ctx
);
2061 bf
= crbD(ctx
->opcode
) >> 2;
2063 gen_optimize_fprf();
2064 gen_op_set_FT0(FPIMM(ctx
->opcode
) << (4 * sh
));
2065 gen_reset_fpstatus();
2066 gen_op_store_fpscr(1 << sh
);
2067 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2071 /* We can raise a differed exception */
2072 gen_op_float_check_status();
2075 /*** Addressing modes ***/
2076 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2077 static always_inline
void gen_addr_imm_index (DisasContext
*ctx
,
2080 target_long simm
= SIMM(ctx
->opcode
);
2083 if (rA(ctx
->opcode
) == 0) {
2086 gen_op_load_gpr_T0(rA(ctx
->opcode
));
2087 if (likely(simm
!= 0))
2090 #ifdef DEBUG_MEMORY_ACCESSES
2091 gen_op_print_mem_EA();
2095 static always_inline
void gen_addr_reg_index (DisasContext
*ctx
)
2097 if (rA(ctx
->opcode
) == 0) {
2098 gen_op_load_gpr_T0(rB(ctx
->opcode
));
2100 gen_op_load_gpr_T0(rA(ctx
->opcode
));
2101 gen_op_load_gpr_T1(rB(ctx
->opcode
));
2104 #ifdef DEBUG_MEMORY_ACCESSES
2105 gen_op_print_mem_EA();
2109 static always_inline
void gen_addr_register (DisasContext
*ctx
)
2111 if (rA(ctx
->opcode
) == 0) {
2114 gen_op_load_gpr_T0(rA(ctx
->opcode
));
2116 #ifdef DEBUG_MEMORY_ACCESSES
2117 gen_op_print_mem_EA();
2121 #if defined(TARGET_PPC64)
2122 #define _GEN_MEM_FUNCS(name, mode) \
2123 &gen_op_##name##_##mode, \
2124 &gen_op_##name##_le_##mode, \
2125 &gen_op_##name##_64_##mode, \
2126 &gen_op_##name##_le_64_##mode
2128 #define _GEN_MEM_FUNCS(name, mode) \
2129 &gen_op_##name##_##mode, \
2130 &gen_op_##name##_le_##mode
2132 #if defined(CONFIG_USER_ONLY)
2133 #if defined(TARGET_PPC64)
2134 #define NB_MEM_FUNCS 4
2136 #define NB_MEM_FUNCS 2
2138 #define GEN_MEM_FUNCS(name) \
2139 _GEN_MEM_FUNCS(name, raw)
2141 #if defined(TARGET_PPC64)
2142 #define NB_MEM_FUNCS 12
2144 #define NB_MEM_FUNCS 6
2146 #define GEN_MEM_FUNCS(name) \
2147 _GEN_MEM_FUNCS(name, user), \
2148 _GEN_MEM_FUNCS(name, kernel), \
2149 _GEN_MEM_FUNCS(name, hypv)
2152 /*** Integer load ***/
2153 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
2154 /* Byte access routine are endian safe */
2155 #define gen_op_lbz_le_raw gen_op_lbz_raw
2156 #define gen_op_lbz_le_user gen_op_lbz_user
2157 #define gen_op_lbz_le_kernel gen_op_lbz_kernel
2158 #define gen_op_lbz_le_hypv gen_op_lbz_hypv
2159 #define gen_op_lbz_le_64_raw gen_op_lbz_64_raw
2160 #define gen_op_lbz_le_64_user gen_op_lbz_64_user
2161 #define gen_op_lbz_le_64_kernel gen_op_lbz_64_kernel
2162 #define gen_op_lbz_le_64_hypv gen_op_lbz_64_hypv
2163 #define gen_op_stb_le_raw gen_op_stb_raw
2164 #define gen_op_stb_le_user gen_op_stb_user
2165 #define gen_op_stb_le_kernel gen_op_stb_kernel
2166 #define gen_op_stb_le_hypv gen_op_stb_hypv
2167 #define gen_op_stb_le_64_raw gen_op_stb_64_raw
2168 #define gen_op_stb_le_64_user gen_op_stb_64_user
2169 #define gen_op_stb_le_64_kernel gen_op_stb_64_kernel
2170 #define gen_op_stb_le_64_hypv gen_op_stb_64_hypv
2171 #define OP_LD_TABLE(width) \
2172 static GenOpFunc *gen_op_l##width[NB_MEM_FUNCS] = { \
2173 GEN_MEM_FUNCS(l##width), \
2175 #define OP_ST_TABLE(width) \
2176 static GenOpFunc *gen_op_st##width[NB_MEM_FUNCS] = { \
2177 GEN_MEM_FUNCS(st##width), \
2180 #define GEN_LD(width, opc, type) \
2181 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2183 gen_addr_imm_index(ctx, 0); \
2184 op_ldst(l##width); \
2185 gen_op_store_T1_gpr(rD(ctx->opcode)); \
2188 #define GEN_LDU(width, opc, type) \
2189 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2191 if (unlikely(rA(ctx->opcode) == 0 || \
2192 rA(ctx->opcode) == rD(ctx->opcode))) { \
2193 GEN_EXCP_INVAL(ctx); \
2196 if (type == PPC_64B) \
2197 gen_addr_imm_index(ctx, 0x03); \
2199 gen_addr_imm_index(ctx, 0); \
2200 op_ldst(l##width); \
2201 gen_op_store_T1_gpr(rD(ctx->opcode)); \
2202 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2205 #define GEN_LDUX(width, opc2, opc3, type) \
2206 GEN_HANDLER(l##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2208 if (unlikely(rA(ctx->opcode) == 0 || \
2209 rA(ctx->opcode) == rD(ctx->opcode))) { \
2210 GEN_EXCP_INVAL(ctx); \
2213 gen_addr_reg_index(ctx); \
2214 op_ldst(l##width); \
2215 gen_op_store_T1_gpr(rD(ctx->opcode)); \
2216 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2219 #define GEN_LDX(width, opc2, opc3, type) \
2220 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2222 gen_addr_reg_index(ctx); \
2223 op_ldst(l##width); \
2224 gen_op_store_T1_gpr(rD(ctx->opcode)); \
2227 #define GEN_LDS(width, op, type) \
2228 OP_LD_TABLE(width); \
2229 GEN_LD(width, op | 0x20, type); \
2230 GEN_LDU(width, op | 0x21, type); \
2231 GEN_LDUX(width, 0x17, op | 0x01, type); \
2232 GEN_LDX(width, 0x17, op | 0x00, type)
2234 /* lbz lbzu lbzux lbzx */
2235 GEN_LDS(bz
, 0x02, PPC_INTEGER
);
2236 /* lha lhau lhaux lhax */
2237 GEN_LDS(ha
, 0x0A, PPC_INTEGER
);
2238 /* lhz lhzu lhzux lhzx */
2239 GEN_LDS(hz
, 0x08, PPC_INTEGER
);
2240 /* lwz lwzu lwzux lwzx */
2241 GEN_LDS(wz
, 0x00, PPC_INTEGER
);
2242 #if defined(TARGET_PPC64)
2246 GEN_LDUX(wa
, 0x15, 0x0B, PPC_64B
);
2248 GEN_LDX(wa
, 0x15, 0x0A, PPC_64B
);
2250 GEN_LDUX(d
, 0x15, 0x01, PPC_64B
);
2252 GEN_LDX(d
, 0x15, 0x00, PPC_64B
);
2253 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
)
2255 if (Rc(ctx
->opcode
)) {
2256 if (unlikely(rA(ctx
->opcode
) == 0 ||
2257 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
2258 GEN_EXCP_INVAL(ctx
);
2262 gen_addr_imm_index(ctx
, 0x03);
2263 if (ctx
->opcode
& 0x02) {
2264 /* lwa (lwau is undefined) */
2270 gen_op_store_T1_gpr(rD(ctx
->opcode
));
2271 if (Rc(ctx
->opcode
))
2272 gen_op_store_T0_gpr(rA(ctx
->opcode
));
2275 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
)
2277 #if defined(CONFIG_USER_ONLY)
2278 GEN_EXCP_PRIVOPC(ctx
);
2282 /* Restore CPU state */
2283 if (unlikely(ctx
->supervisor
== 0)) {
2284 GEN_EXCP_PRIVOPC(ctx
);
2287 ra
= rA(ctx
->opcode
);
2288 rd
= rD(ctx
->opcode
);
2289 if (unlikely((rd
& 1) || rd
== ra
)) {
2290 GEN_EXCP_INVAL(ctx
);
2293 if (unlikely(ctx
->mem_idx
& 1)) {
2294 /* Little-endian mode is not handled */
2295 GEN_EXCP(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2298 gen_addr_imm_index(ctx
, 0x0F);
2300 gen_op_store_T1_gpr(rd
);
2303 gen_op_store_T1_gpr(rd
+ 1);
2308 /*** Integer store ***/
2309 #define GEN_ST(width, opc, type) \
2310 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2312 gen_addr_imm_index(ctx, 0); \
2313 gen_op_load_gpr_T1(rS(ctx->opcode)); \
2314 op_ldst(st##width); \
2317 #define GEN_STU(width, opc, type) \
2318 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2320 if (unlikely(rA(ctx->opcode) == 0)) { \
2321 GEN_EXCP_INVAL(ctx); \
2324 if (type == PPC_64B) \
2325 gen_addr_imm_index(ctx, 0x03); \
2327 gen_addr_imm_index(ctx, 0); \
2328 gen_op_load_gpr_T1(rS(ctx->opcode)); \
2329 op_ldst(st##width); \
2330 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2333 #define GEN_STUX(width, opc2, opc3, type) \
2334 GEN_HANDLER(st##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2336 if (unlikely(rA(ctx->opcode) == 0)) { \
2337 GEN_EXCP_INVAL(ctx); \
2340 gen_addr_reg_index(ctx); \
2341 gen_op_load_gpr_T1(rS(ctx->opcode)); \
2342 op_ldst(st##width); \
2343 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2346 #define GEN_STX(width, opc2, opc3, type) \
2347 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2349 gen_addr_reg_index(ctx); \
2350 gen_op_load_gpr_T1(rS(ctx->opcode)); \
2351 op_ldst(st##width); \
2354 #define GEN_STS(width, op, type) \
2355 OP_ST_TABLE(width); \
2356 GEN_ST(width, op | 0x20, type); \
2357 GEN_STU(width, op | 0x21, type); \
2358 GEN_STUX(width, 0x17, op | 0x01, type); \
2359 GEN_STX(width, 0x17, op | 0x00, type)
2361 /* stb stbu stbux stbx */
2362 GEN_STS(b
, 0x06, PPC_INTEGER
);
2363 /* sth sthu sthux sthx */
2364 GEN_STS(h
, 0x0C, PPC_INTEGER
);
2365 /* stw stwu stwux stwx */
2366 GEN_STS(w
, 0x04, PPC_INTEGER
);
2367 #if defined(TARGET_PPC64)
2369 GEN_STUX(d
, 0x15, 0x05, PPC_64B
);
2370 GEN_STX(d
, 0x15, 0x04, PPC_64B
);
2371 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
)
2375 rs
= rS(ctx
->opcode
);
2376 if ((ctx
->opcode
& 0x3) == 0x2) {
2377 #if defined(CONFIG_USER_ONLY)
2378 GEN_EXCP_PRIVOPC(ctx
);
2381 if (unlikely(ctx
->supervisor
== 0)) {
2382 GEN_EXCP_PRIVOPC(ctx
);
2385 if (unlikely(rs
& 1)) {
2386 GEN_EXCP_INVAL(ctx
);
2389 if (unlikely(ctx
->mem_idx
& 1)) {
2390 /* Little-endian mode is not handled */
2391 GEN_EXCP(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2394 gen_addr_imm_index(ctx
, 0x03);
2395 gen_op_load_gpr_T1(rs
);
2398 gen_op_load_gpr_T1(rs
+ 1);
2403 if (Rc(ctx
->opcode
)) {
2404 if (unlikely(rA(ctx
->opcode
) == 0)) {
2405 GEN_EXCP_INVAL(ctx
);
2409 gen_addr_imm_index(ctx
, 0x03);
2410 gen_op_load_gpr_T1(rs
);
2412 if (Rc(ctx
->opcode
))
2413 gen_op_store_T0_gpr(rA(ctx
->opcode
));
2417 /*** Integer load and store with byte reverse ***/
2420 GEN_LDX(hbr
, 0x16, 0x18, PPC_INTEGER
);
2423 GEN_LDX(wbr
, 0x16, 0x10, PPC_INTEGER
);
2426 GEN_STX(hbr
, 0x16, 0x1C, PPC_INTEGER
);
2429 GEN_STX(wbr
, 0x16, 0x14, PPC_INTEGER
);
2431 /*** Integer load and store multiple ***/
2432 #define op_ldstm(name, reg) (*gen_op_##name[ctx->mem_idx])(reg)
2433 static GenOpFunc1
*gen_op_lmw
[NB_MEM_FUNCS
] = {
2436 static GenOpFunc1
*gen_op_stmw
[NB_MEM_FUNCS
] = {
2437 GEN_MEM_FUNCS(stmw
),
2441 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
2443 /* NIP cannot be restored if the memory exception comes from an helper */
2444 gen_update_nip(ctx
, ctx
->nip
- 4);
2445 gen_addr_imm_index(ctx
, 0);
2446 op_ldstm(lmw
, rD(ctx
->opcode
));
2450 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
2452 /* NIP cannot be restored if the memory exception comes from an helper */
2453 gen_update_nip(ctx
, ctx
->nip
- 4);
2454 gen_addr_imm_index(ctx
, 0);
2455 op_ldstm(stmw
, rS(ctx
->opcode
));
2458 /*** Integer load and store strings ***/
2459 #define op_ldsts(name, start) (*gen_op_##name[ctx->mem_idx])(start)
2460 #define op_ldstsx(name, rd, ra, rb) (*gen_op_##name[ctx->mem_idx])(rd, ra, rb)
2461 /* string load & stores are by definition endian-safe */
2462 #define gen_op_lswi_le_raw gen_op_lswi_raw
2463 #define gen_op_lswi_le_user gen_op_lswi_user
2464 #define gen_op_lswi_le_kernel gen_op_lswi_kernel
2465 #define gen_op_lswi_le_hypv gen_op_lswi_hypv
2466 #define gen_op_lswi_le_64_raw gen_op_lswi_raw
2467 #define gen_op_lswi_le_64_user gen_op_lswi_user
2468 #define gen_op_lswi_le_64_kernel gen_op_lswi_kernel
2469 #define gen_op_lswi_le_64_hypv gen_op_lswi_hypv
2470 static GenOpFunc1
*gen_op_lswi
[NB_MEM_FUNCS
] = {
2471 GEN_MEM_FUNCS(lswi
),
2473 #define gen_op_lswx_le_raw gen_op_lswx_raw
2474 #define gen_op_lswx_le_user gen_op_lswx_user
2475 #define gen_op_lswx_le_kernel gen_op_lswx_kernel
2476 #define gen_op_lswx_le_hypv gen_op_lswx_hypv
2477 #define gen_op_lswx_le_64_raw gen_op_lswx_raw
2478 #define gen_op_lswx_le_64_user gen_op_lswx_user
2479 #define gen_op_lswx_le_64_kernel gen_op_lswx_kernel
2480 #define gen_op_lswx_le_64_hypv gen_op_lswx_hypv
2481 static GenOpFunc3
*gen_op_lswx
[NB_MEM_FUNCS
] = {
2482 GEN_MEM_FUNCS(lswx
),
2484 #define gen_op_stsw_le_raw gen_op_stsw_raw
2485 #define gen_op_stsw_le_user gen_op_stsw_user
2486 #define gen_op_stsw_le_kernel gen_op_stsw_kernel
2487 #define gen_op_stsw_le_hypv gen_op_stsw_hypv
2488 #define gen_op_stsw_le_64_raw gen_op_stsw_raw
2489 #define gen_op_stsw_le_64_user gen_op_stsw_user
2490 #define gen_op_stsw_le_64_kernel gen_op_stsw_kernel
2491 #define gen_op_stsw_le_64_hypv gen_op_stsw_hypv
2492 static GenOpFunc1
*gen_op_stsw
[NB_MEM_FUNCS
] = {
2493 GEN_MEM_FUNCS(stsw
),
2497 /* PowerPC32 specification says we must generate an exception if
2498 * rA is in the range of registers to be loaded.
2499 * In an other hand, IBM says this is valid, but rA won't be loaded.
2500 * For now, I'll follow the spec...
2502 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
)
2504 int nb
= NB(ctx
->opcode
);
2505 int start
= rD(ctx
->opcode
);
2506 int ra
= rA(ctx
->opcode
);
2512 if (unlikely(((start
+ nr
) > 32 &&
2513 start
<= ra
&& (start
+ nr
- 32) > ra
) ||
2514 ((start
+ nr
) <= 32 && start
<= ra
&& (start
+ nr
) > ra
))) {
2515 GEN_EXCP(ctx
, POWERPC_EXCP_PROGRAM
,
2516 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_LSWX
);
2519 /* NIP cannot be restored if the memory exception comes from an helper */
2520 gen_update_nip(ctx
, ctx
->nip
- 4);
2521 gen_addr_register(ctx
);
2523 op_ldsts(lswi
, start
);
2527 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
)
2529 int ra
= rA(ctx
->opcode
);
2530 int rb
= rB(ctx
->opcode
);
2532 /* NIP cannot be restored if the memory exception comes from an helper */
2533 gen_update_nip(ctx
, ctx
->nip
- 4);
2534 gen_addr_reg_index(ctx
);
2538 gen_op_load_xer_bc();
2539 op_ldstsx(lswx
, rD(ctx
->opcode
), ra
, rb
);
2543 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
)
2545 int nb
= NB(ctx
->opcode
);
2547 /* NIP cannot be restored if the memory exception comes from an helper */
2548 gen_update_nip(ctx
, ctx
->nip
- 4);
2549 gen_addr_register(ctx
);
2553 op_ldsts(stsw
, rS(ctx
->opcode
));
2557 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
)
2559 /* NIP cannot be restored if the memory exception comes from an helper */
2560 gen_update_nip(ctx
, ctx
->nip
- 4);
2561 gen_addr_reg_index(ctx
);
2562 gen_op_load_xer_bc();
2563 op_ldsts(stsw
, rS(ctx
->opcode
));
2566 /*** Memory synchronisation ***/
2568 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO
)
2573 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
)
2578 #define op_lwarx() (*gen_op_lwarx[ctx->mem_idx])()
2579 #define op_stwcx() (*gen_op_stwcx[ctx->mem_idx])()
2580 static GenOpFunc
*gen_op_lwarx
[NB_MEM_FUNCS
] = {
2581 GEN_MEM_FUNCS(lwarx
),
2583 static GenOpFunc
*gen_op_stwcx
[NB_MEM_FUNCS
] = {
2584 GEN_MEM_FUNCS(stwcx
),
2588 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000001, PPC_RES
)
2590 /* NIP cannot be restored if the memory exception comes from an helper */
2591 gen_update_nip(ctx
, ctx
->nip
- 4);
2592 gen_addr_reg_index(ctx
);
2594 gen_op_store_T1_gpr(rD(ctx
->opcode
));
2598 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
)
2600 /* NIP cannot be restored if the memory exception comes from an helper */
2601 gen_update_nip(ctx
, ctx
->nip
- 4);
2602 gen_addr_reg_index(ctx
);
2603 gen_op_load_gpr_T1(rS(ctx
->opcode
));
2607 #if defined(TARGET_PPC64)
2608 #define op_ldarx() (*gen_op_ldarx[ctx->mem_idx])()
2609 #define op_stdcx() (*gen_op_stdcx[ctx->mem_idx])()
2610 static GenOpFunc
*gen_op_ldarx
[NB_MEM_FUNCS
] = {
2611 GEN_MEM_FUNCS(ldarx
),
2613 static GenOpFunc
*gen_op_stdcx
[NB_MEM_FUNCS
] = {
2614 GEN_MEM_FUNCS(stdcx
),
2618 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000001, PPC_64B
)
2620 /* NIP cannot be restored if the memory exception comes from an helper */
2621 gen_update_nip(ctx
, ctx
->nip
- 4);
2622 gen_addr_reg_index(ctx
);
2624 gen_op_store_T1_gpr(rD(ctx
->opcode
));
2628 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
)
2630 /* NIP cannot be restored if the memory exception comes from an helper */
2631 gen_update_nip(ctx
, ctx
->nip
- 4);
2632 gen_addr_reg_index(ctx
);
2633 gen_op_load_gpr_T1(rS(ctx
->opcode
));
2636 #endif /* defined(TARGET_PPC64) */
2639 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
)
2644 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
)
2646 /* Stop translation, as the CPU is supposed to sleep from now */
2648 GEN_EXCP(ctx
, EXCP_HLT
, 1);
2651 /*** Floating-point load ***/
2652 #define GEN_LDF(width, opc, type) \
2653 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2655 if (unlikely(!ctx->fpu_enabled)) { \
2656 GEN_EXCP_NO_FP(ctx); \
2659 gen_addr_imm_index(ctx, 0); \
2660 op_ldst(l##width); \
2661 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
2664 #define GEN_LDUF(width, opc, type) \
2665 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2667 if (unlikely(!ctx->fpu_enabled)) { \
2668 GEN_EXCP_NO_FP(ctx); \
2671 if (unlikely(rA(ctx->opcode) == 0)) { \
2672 GEN_EXCP_INVAL(ctx); \
2675 gen_addr_imm_index(ctx, 0); \
2676 op_ldst(l##width); \
2677 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
2678 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2681 #define GEN_LDUXF(width, opc, type) \
2682 GEN_HANDLER(l##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \
2684 if (unlikely(!ctx->fpu_enabled)) { \
2685 GEN_EXCP_NO_FP(ctx); \
2688 if (unlikely(rA(ctx->opcode) == 0)) { \
2689 GEN_EXCP_INVAL(ctx); \
2692 gen_addr_reg_index(ctx); \
2693 op_ldst(l##width); \
2694 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
2695 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2698 #define GEN_LDXF(width, opc2, opc3, type) \
2699 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2701 if (unlikely(!ctx->fpu_enabled)) { \
2702 GEN_EXCP_NO_FP(ctx); \
2705 gen_addr_reg_index(ctx); \
2706 op_ldst(l##width); \
2707 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
2710 #define GEN_LDFS(width, op, type) \
2711 OP_LD_TABLE(width); \
2712 GEN_LDF(width, op | 0x20, type); \
2713 GEN_LDUF(width, op | 0x21, type); \
2714 GEN_LDUXF(width, op | 0x01, type); \
2715 GEN_LDXF(width, 0x17, op | 0x00, type)
2717 /* lfd lfdu lfdux lfdx */
2718 GEN_LDFS(fd
, 0x12, PPC_FLOAT
);
2719 /* lfs lfsu lfsux lfsx */
2720 GEN_LDFS(fs
, 0x10, PPC_FLOAT
);
2722 /*** Floating-point store ***/
2723 #define GEN_STF(width, opc, type) \
2724 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2726 if (unlikely(!ctx->fpu_enabled)) { \
2727 GEN_EXCP_NO_FP(ctx); \
2730 gen_addr_imm_index(ctx, 0); \
2731 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
2732 op_ldst(st##width); \
2735 #define GEN_STUF(width, opc, type) \
2736 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2738 if (unlikely(!ctx->fpu_enabled)) { \
2739 GEN_EXCP_NO_FP(ctx); \
2742 if (unlikely(rA(ctx->opcode) == 0)) { \
2743 GEN_EXCP_INVAL(ctx); \
2746 gen_addr_imm_index(ctx, 0); \
2747 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
2748 op_ldst(st##width); \
2749 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2752 #define GEN_STUXF(width, opc, type) \
2753 GEN_HANDLER(st##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \
2755 if (unlikely(!ctx->fpu_enabled)) { \
2756 GEN_EXCP_NO_FP(ctx); \
2759 if (unlikely(rA(ctx->opcode) == 0)) { \
2760 GEN_EXCP_INVAL(ctx); \
2763 gen_addr_reg_index(ctx); \
2764 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
2765 op_ldst(st##width); \
2766 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2769 #define GEN_STXF(width, opc2, opc3, type) \
2770 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2772 if (unlikely(!ctx->fpu_enabled)) { \
2773 GEN_EXCP_NO_FP(ctx); \
2776 gen_addr_reg_index(ctx); \
2777 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
2778 op_ldst(st##width); \
2781 #define GEN_STFS(width, op, type) \
2782 OP_ST_TABLE(width); \
2783 GEN_STF(width, op | 0x20, type); \
2784 GEN_STUF(width, op | 0x21, type); \
2785 GEN_STUXF(width, op | 0x01, type); \
2786 GEN_STXF(width, 0x17, op | 0x00, type)
2788 /* stfd stfdu stfdux stfdx */
2789 GEN_STFS(fd
, 0x16, PPC_FLOAT
);
2790 /* stfs stfsu stfsux stfsx */
2791 GEN_STFS(fs
, 0x14, PPC_FLOAT
);
2796 GEN_STXF(fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
);
2799 static always_inline
void gen_goto_tb (DisasContext
*ctx
, int n
,
2802 TranslationBlock
*tb
;
2804 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
2805 likely(!ctx
->singlestep_enabled
)) {
2808 #if defined(TARGET_PPC64)
2814 tcg_gen_exit_tb((long)tb
+ n
);
2817 #if defined(TARGET_PPC64)
2823 if (unlikely(ctx
->singlestep_enabled
)) {
2824 if ((ctx
->singlestep_enabled
&
2825 (CPU_BRANCH_STEP
| CPU_SINGLE_STEP
)) &&
2826 ctx
->exception
== POWERPC_EXCP_BRANCH
) {
2827 target_ulong tmp
= ctx
->nip
;
2829 GEN_EXCP(ctx
, POWERPC_EXCP_TRACE
, 0);
2832 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
2833 gen_update_nip(ctx
, dest
);
2841 static always_inline
void gen_setlr (DisasContext
*ctx
, target_ulong nip
)
2843 #if defined(TARGET_PPC64)
2844 if (ctx
->sf_mode
!= 0 && (nip
>> 32))
2845 gen_op_setlr_64(ctx
->nip
>> 32, ctx
->nip
);
2848 gen_op_setlr(ctx
->nip
);
2852 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
2854 target_ulong li
, target
;
2856 ctx
->exception
= POWERPC_EXCP_BRANCH
;
2857 /* sign extend LI */
2858 #if defined(TARGET_PPC64)
2860 li
= ((int64_t)LI(ctx
->opcode
) << 38) >> 38;
2863 li
= ((int32_t)LI(ctx
->opcode
) << 6) >> 6;
2864 if (likely(AA(ctx
->opcode
) == 0))
2865 target
= ctx
->nip
+ li
- 4;
2868 #if defined(TARGET_PPC64)
2870 target
= (uint32_t)target
;
2872 if (LK(ctx
->opcode
))
2873 gen_setlr(ctx
, ctx
->nip
);
2874 gen_goto_tb(ctx
, 0, target
);
2881 static always_inline
void gen_bcond (DisasContext
*ctx
, int type
)
2883 target_ulong target
= 0;
2885 uint32_t bo
= BO(ctx
->opcode
);
2886 uint32_t bi
= BI(ctx
->opcode
);
2889 ctx
->exception
= POWERPC_EXCP_BRANCH
;
2890 if ((bo
& 0x4) == 0)
2894 li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
2895 if (likely(AA(ctx
->opcode
) == 0)) {
2896 target
= ctx
->nip
+ li
- 4;
2900 #if defined(TARGET_PPC64)
2902 target
= (uint32_t)target
;
2906 gen_op_movl_T1_ctr();
2910 gen_op_movl_T1_lr();
2913 if (LK(ctx
->opcode
))
2914 gen_setlr(ctx
, ctx
->nip
);
2916 /* No CR condition */
2919 #if defined(TARGET_PPC64)
2921 gen_op_test_ctr_64();
2927 #if defined(TARGET_PPC64)
2929 gen_op_test_ctrz_64();
2937 if (type
== BCOND_IM
) {
2938 gen_goto_tb(ctx
, 0, target
);
2941 #if defined(TARGET_PPC64)
2952 mask
= 1 << (3 - (bi
& 0x03));
2953 gen_op_load_crf_T0(bi
>> 2);
2957 #if defined(TARGET_PPC64)
2959 gen_op_test_ctr_true_64(mask
);
2962 gen_op_test_ctr_true(mask
);
2965 #if defined(TARGET_PPC64)
2967 gen_op_test_ctrz_true_64(mask
);
2970 gen_op_test_ctrz_true(mask
);
2975 gen_op_test_true(mask
);
2981 #if defined(TARGET_PPC64)
2983 gen_op_test_ctr_false_64(mask
);
2986 gen_op_test_ctr_false(mask
);
2989 #if defined(TARGET_PPC64)
2991 gen_op_test_ctrz_false_64(mask
);
2994 gen_op_test_ctrz_false(mask
);
2999 gen_op_test_false(mask
);
3004 if (type
== BCOND_IM
) {
3005 int l1
= gen_new_label();
3007 gen_goto_tb(ctx
, 0, target
);
3009 gen_goto_tb(ctx
, 1, ctx
->nip
);
3011 #if defined(TARGET_PPC64)
3013 gen_op_btest_T1_64(ctx
->nip
>> 32, ctx
->nip
);
3016 gen_op_btest_T1(ctx
->nip
);
3018 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
3019 gen_update_nip(ctx
, ctx
->nip
);
3026 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
3028 gen_bcond(ctx
, BCOND_IM
);
3031 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
)
3033 gen_bcond(ctx
, BCOND_CTR
);
3036 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
)
3038 gen_bcond(ctx
, BCOND_LR
);
3041 /*** Condition register logical ***/
3042 #define GEN_CRLOGIC(op, opc) \
3043 GEN_HANDLER(cr##op, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) \
3047 gen_op_load_crf_T0(crbA(ctx->opcode) >> 2); \
3048 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3050 gen_op_srli_T0(sh); \
3052 gen_op_sli_T0(-sh); \
3053 gen_op_load_crf_T1(crbB(ctx->opcode) >> 2); \
3054 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3056 gen_op_srli_T1(sh); \
3058 gen_op_sli_T1(-sh); \
3060 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
3061 gen_op_andi_T0(bitmask); \
3062 gen_op_load_crf_T1(crbD(ctx->opcode) >> 2); \
3063 gen_op_andi_T1(~bitmask); \
3065 gen_op_store_T0_crf(crbD(ctx->opcode) >> 2); \
3069 GEN_CRLOGIC(and, 0x08);
3071 GEN_CRLOGIC(andc
, 0x04);
3073 GEN_CRLOGIC(eqv
, 0x09);
3075 GEN_CRLOGIC(nand
, 0x07);
3077 GEN_CRLOGIC(nor
, 0x01);
3079 GEN_CRLOGIC(or, 0x0E);
3081 GEN_CRLOGIC(orc
, 0x0D);
3083 GEN_CRLOGIC(xor, 0x06);
3085 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
)
3087 gen_op_load_crf_T0(crfS(ctx
->opcode
));
3088 gen_op_store_T0_crf(crfD(ctx
->opcode
));
3091 /*** System linkage ***/
3092 /* rfi (supervisor only) */
3093 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
)
3095 #if defined(CONFIG_USER_ONLY)
3096 GEN_EXCP_PRIVOPC(ctx
);
3098 /* Restore CPU state */
3099 if (unlikely(!ctx
->supervisor
)) {
3100 GEN_EXCP_PRIVOPC(ctx
);
3108 #if defined(TARGET_PPC64)
3109 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
)
3111 #if defined(CONFIG_USER_ONLY)
3112 GEN_EXCP_PRIVOPC(ctx
);
3114 /* Restore CPU state */
3115 if (unlikely(!ctx
->supervisor
)) {
3116 GEN_EXCP_PRIVOPC(ctx
);
3124 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
)
3126 #if defined(CONFIG_USER_ONLY)
3127 GEN_EXCP_PRIVOPC(ctx
);
3129 /* Restore CPU state */
3130 if (unlikely(ctx
->supervisor
<= 1)) {
3131 GEN_EXCP_PRIVOPC(ctx
);
3141 #if defined(CONFIG_USER_ONLY)
3142 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3144 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3146 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW
)
3150 lev
= (ctx
->opcode
>> 5) & 0x7F;
3151 GEN_EXCP(ctx
, POWERPC_SYSCALL
, lev
);
3156 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
)
3158 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3159 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3160 /* Update the nip since this might generate a trap exception */
3161 gen_update_nip(ctx
, ctx
->nip
);
3162 gen_op_tw(TO(ctx
->opcode
));
3166 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
3168 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3169 gen_set_T1(SIMM(ctx
->opcode
));
3170 /* Update the nip since this might generate a trap exception */
3171 gen_update_nip(ctx
, ctx
->nip
);
3172 gen_op_tw(TO(ctx
->opcode
));
3175 #if defined(TARGET_PPC64)
3177 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
)
3179 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3180 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3181 /* Update the nip since this might generate a trap exception */
3182 gen_update_nip(ctx
, ctx
->nip
);
3183 gen_op_td(TO(ctx
->opcode
));
3187 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
)
3189 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3190 gen_set_T1(SIMM(ctx
->opcode
));
3191 /* Update the nip since this might generate a trap exception */
3192 gen_update_nip(ctx
, ctx
->nip
);
3193 gen_op_td(TO(ctx
->opcode
));
3197 /*** Processor control ***/
3199 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
)
3201 gen_op_load_xer_cr();
3202 gen_op_store_T0_crf(crfD(ctx
->opcode
));
3203 gen_op_clear_xer_ov();
3204 gen_op_clear_xer_ca();
3208 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
)
3212 if (likely(ctx
->opcode
& 0x00100000)) {
3213 crm
= CRM(ctx
->opcode
);
3214 if (likely((crm
^ (crm
- 1)) == 0)) {
3216 gen_op_load_cro(7 - crn
);
3221 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3225 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
)
3227 #if defined(CONFIG_USER_ONLY)
3228 GEN_EXCP_PRIVREG(ctx
);
3230 if (unlikely(!ctx
->supervisor
)) {
3231 GEN_EXCP_PRIVREG(ctx
);
3235 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3240 #define SPR_NOACCESS ((void *)(-1UL))
3242 static void spr_noaccess (void *opaque
, int sprn
)
3244 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
3245 printf("ERROR: try to access SPR %d !\n", sprn
);
3247 #define SPR_NOACCESS (&spr_noaccess)
3251 static always_inline
void gen_op_mfspr (DisasContext
*ctx
)
3253 void (*read_cb
)(void *opaque
, int sprn
);
3254 uint32_t sprn
= SPR(ctx
->opcode
);
3256 #if !defined(CONFIG_USER_ONLY)
3257 if (ctx
->supervisor
== 2)
3258 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
3259 else if (ctx
->supervisor
)
3260 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
3263 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
3264 if (likely(read_cb
!= NULL
)) {
3265 if (likely(read_cb
!= SPR_NOACCESS
)) {
3266 (*read_cb
)(ctx
, sprn
);
3267 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3269 /* Privilege exception */
3270 /* This is a hack to avoid warnings when running Linux:
3271 * this OS breaks the PowerPC virtualisation model,
3272 * allowing userland application to read the PVR
3274 if (sprn
!= SPR_PVR
) {
3275 if (loglevel
!= 0) {
3276 fprintf(logfile
, "Trying to read privileged spr %d %03x at "
3277 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3279 printf("Trying to read privileged spr %d %03x at " ADDRX
"\n",
3280 sprn
, sprn
, ctx
->nip
);
3282 GEN_EXCP_PRIVREG(ctx
);
3286 if (loglevel
!= 0) {
3287 fprintf(logfile
, "Trying to read invalid spr %d %03x at "
3288 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3290 printf("Trying to read invalid spr %d %03x at " ADDRX
"\n",
3291 sprn
, sprn
, ctx
->nip
);
3292 GEN_EXCP(ctx
, POWERPC_EXCP_PROGRAM
,
3293 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_SPR
);
3297 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
)
3303 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
)
3309 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
)
3313 gen_op_load_gpr_T0(rS(ctx
->opcode
));
3314 crm
= CRM(ctx
->opcode
);
3315 if (likely((ctx
->opcode
& 0x00100000) || (crm
^ (crm
- 1)) == 0)) {
3317 gen_op_srli_T0(crn
* 4);
3318 gen_op_andi_T0(0xF);
3319 gen_op_store_cro(7 - crn
);
3321 gen_op_store_cr(crm
);
3326 #if defined(TARGET_PPC64)
3327 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
)
3329 #if defined(CONFIG_USER_ONLY)
3330 GEN_EXCP_PRIVREG(ctx
);
3332 if (unlikely(!ctx
->supervisor
)) {
3333 GEN_EXCP_PRIVREG(ctx
);
3336 gen_op_load_gpr_T0(rS(ctx
->opcode
));
3337 if (ctx
->opcode
& 0x00010000) {
3338 /* Special form that does not need any synchronisation */
3339 gen_op_update_riee();
3341 /* XXX: we need to update nip before the store
3342 * if we enter power saving mode, we will exit the loop
3343 * directly from ppc_store_msr
3345 gen_update_nip(ctx
, ctx
->nip
);
3347 /* Must stop the translation as machine state (may have) changed */
3348 /* Note that mtmsr is not always defined as context-synchronizing */
3349 ctx
->exception
= POWERPC_EXCP_STOP
;
3355 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC
)
3357 #if defined(CONFIG_USER_ONLY)
3358 GEN_EXCP_PRIVREG(ctx
);
3360 if (unlikely(!ctx
->supervisor
)) {
3361 GEN_EXCP_PRIVREG(ctx
);
3364 gen_op_load_gpr_T0(rS(ctx
->opcode
));
3365 if (ctx
->opcode
& 0x00010000) {
3366 /* Special form that does not need any synchronisation */
3367 gen_op_update_riee();
3369 /* XXX: we need to update nip before the store
3370 * if we enter power saving mode, we will exit the loop
3371 * directly from ppc_store_msr
3373 gen_update_nip(ctx
, ctx
->nip
);
3374 #if defined(TARGET_PPC64)
3376 gen_op_store_msr_32();
3380 /* Must stop the translation as machine state (may have) changed */
3381 /* Note that mtmsrd is not always defined as context-synchronizing */
3382 ctx
->exception
= POWERPC_EXCP_STOP
;
3388 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC
)
3390 void (*write_cb
)(void *opaque
, int sprn
);
3391 uint32_t sprn
= SPR(ctx
->opcode
);
3393 #if !defined(CONFIG_USER_ONLY)
3394 if (ctx
->supervisor
== 2)
3395 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
3396 else if (ctx
->supervisor
)
3397 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
3400 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
3401 if (likely(write_cb
!= NULL
)) {
3402 if (likely(write_cb
!= SPR_NOACCESS
)) {
3403 gen_op_load_gpr_T0(rS(ctx
->opcode
));
3404 (*write_cb
)(ctx
, sprn
);
3406 /* Privilege exception */
3407 if (loglevel
!= 0) {
3408 fprintf(logfile
, "Trying to write privileged spr %d %03x at "
3409 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3411 printf("Trying to write privileged spr %d %03x at " ADDRX
"\n",
3412 sprn
, sprn
, ctx
->nip
);
3413 GEN_EXCP_PRIVREG(ctx
);
3417 if (loglevel
!= 0) {
3418 fprintf(logfile
, "Trying to write invalid spr %d %03x at "
3419 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3421 printf("Trying to write invalid spr %d %03x at " ADDRX
"\n",
3422 sprn
, sprn
, ctx
->nip
);
3423 GEN_EXCP(ctx
, POWERPC_EXCP_PROGRAM
,
3424 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_SPR
);
3428 /*** Cache management ***/
3430 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
)
3432 /* XXX: specification says this is treated as a load by the MMU */
3433 gen_addr_reg_index(ctx
);
3437 /* dcbi (Supervisor only) */
3438 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
)
3440 #if defined(CONFIG_USER_ONLY)
3441 GEN_EXCP_PRIVOPC(ctx
);
3443 if (unlikely(!ctx
->supervisor
)) {
3444 GEN_EXCP_PRIVOPC(ctx
);
3447 gen_addr_reg_index(ctx
);
3448 /* XXX: specification says this should be treated as a store by the MMU */
3455 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
)
3457 /* XXX: specification say this is treated as a load by the MMU */
3458 gen_addr_reg_index(ctx
);
3463 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE
)
3465 /* interpreted as no-op */
3466 /* XXX: specification say this is treated as a load by the MMU
3467 * but does not generate any exception
3472 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE
)
3474 /* interpreted as no-op */
3475 /* XXX: specification say this is treated as a load by the MMU
3476 * but does not generate any exception
3481 #define op_dcbz(n) (*gen_op_dcbz[n][ctx->mem_idx])()
3482 static GenOpFunc
*gen_op_dcbz
[4][NB_MEM_FUNCS
] = {
3483 /* 32 bytes cache line size */
3485 #define gen_op_dcbz_l32_le_raw gen_op_dcbz_l32_raw
3486 #define gen_op_dcbz_l32_le_user gen_op_dcbz_l32_user
3487 #define gen_op_dcbz_l32_le_kernel gen_op_dcbz_l32_kernel
3488 #define gen_op_dcbz_l32_le_hypv gen_op_dcbz_l32_hypv
3489 #define gen_op_dcbz_l32_le_64_raw gen_op_dcbz_l32_64_raw
3490 #define gen_op_dcbz_l32_le_64_user gen_op_dcbz_l32_64_user
3491 #define gen_op_dcbz_l32_le_64_kernel gen_op_dcbz_l32_64_kernel
3492 #define gen_op_dcbz_l32_le_64_hypv gen_op_dcbz_l32_64_hypv
3493 GEN_MEM_FUNCS(dcbz_l32
),
3495 /* 64 bytes cache line size */
3497 #define gen_op_dcbz_l64_le_raw gen_op_dcbz_l64_raw
3498 #define gen_op_dcbz_l64_le_user gen_op_dcbz_l64_user
3499 #define gen_op_dcbz_l64_le_kernel gen_op_dcbz_l64_kernel
3500 #define gen_op_dcbz_l64_le_hypv gen_op_dcbz_l64_hypv
3501 #define gen_op_dcbz_l64_le_64_raw gen_op_dcbz_l64_64_raw
3502 #define gen_op_dcbz_l64_le_64_user gen_op_dcbz_l64_64_user
3503 #define gen_op_dcbz_l64_le_64_kernel gen_op_dcbz_l64_64_kernel
3504 #define gen_op_dcbz_l64_le_64_hypv gen_op_dcbz_l64_64_hypv
3505 GEN_MEM_FUNCS(dcbz_l64
),
3507 /* 128 bytes cache line size */
3509 #define gen_op_dcbz_l128_le_raw gen_op_dcbz_l128_raw
3510 #define gen_op_dcbz_l128_le_user gen_op_dcbz_l128_user
3511 #define gen_op_dcbz_l128_le_kernel gen_op_dcbz_l128_kernel
3512 #define gen_op_dcbz_l128_le_hypv gen_op_dcbz_l128_hypv
3513 #define gen_op_dcbz_l128_le_64_raw gen_op_dcbz_l128_64_raw
3514 #define gen_op_dcbz_l128_le_64_user gen_op_dcbz_l128_64_user
3515 #define gen_op_dcbz_l128_le_64_kernel gen_op_dcbz_l128_64_kernel
3516 #define gen_op_dcbz_l128_le_64_hypv gen_op_dcbz_l128_64_hypv
3517 GEN_MEM_FUNCS(dcbz_l128
),
3519 /* tunable cache line size */
3521 #define gen_op_dcbz_le_raw gen_op_dcbz_raw
3522 #define gen_op_dcbz_le_user gen_op_dcbz_user
3523 #define gen_op_dcbz_le_kernel gen_op_dcbz_kernel
3524 #define gen_op_dcbz_le_hypv gen_op_dcbz_hypv
3525 #define gen_op_dcbz_le_64_raw gen_op_dcbz_64_raw
3526 #define gen_op_dcbz_le_64_user gen_op_dcbz_64_user
3527 #define gen_op_dcbz_le_64_kernel gen_op_dcbz_64_kernel
3528 #define gen_op_dcbz_le_64_hypv gen_op_dcbz_64_hypv
3529 GEN_MEM_FUNCS(dcbz
),
3533 static always_inline
void handler_dcbz (DisasContext
*ctx
,
3534 int dcache_line_size
)
3538 switch (dcache_line_size
) {
3555 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE_DCBZ
)
3557 gen_addr_reg_index(ctx
);
3558 handler_dcbz(ctx
, ctx
->dcache_line_size
);
3559 gen_op_check_reservation();
3562 GEN_HANDLER2(dcbz_970
, "dcbz", 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZT
)
3564 gen_addr_reg_index(ctx
);
3565 if (ctx
->opcode
& 0x00200000)
3566 handler_dcbz(ctx
, ctx
->dcache_line_size
);
3568 handler_dcbz(ctx
, -1);
3569 gen_op_check_reservation();
3573 #define op_icbi() (*gen_op_icbi[ctx->mem_idx])()
3574 #define gen_op_icbi_le_raw gen_op_icbi_raw
3575 #define gen_op_icbi_le_user gen_op_icbi_user
3576 #define gen_op_icbi_le_kernel gen_op_icbi_kernel
3577 #define gen_op_icbi_le_hypv gen_op_icbi_hypv
3578 #define gen_op_icbi_le_64_raw gen_op_icbi_64_raw
3579 #define gen_op_icbi_le_64_user gen_op_icbi_64_user
3580 #define gen_op_icbi_le_64_kernel gen_op_icbi_64_kernel
3581 #define gen_op_icbi_le_64_hypv gen_op_icbi_64_hypv
3582 static GenOpFunc
*gen_op_icbi
[NB_MEM_FUNCS
] = {
3583 GEN_MEM_FUNCS(icbi
),
3586 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
)
3588 /* NIP cannot be restored if the memory exception comes from an helper */
3589 gen_update_nip(ctx
, ctx
->nip
- 4);
3590 gen_addr_reg_index(ctx
);
3596 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
)
3598 /* interpreted as no-op */
3599 /* XXX: specification say this is treated as a store by the MMU
3600 * but does not generate any exception
3604 /*** Segment register manipulation ***/
3605 /* Supervisor only: */
3607 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
)
3609 #if defined(CONFIG_USER_ONLY)
3610 GEN_EXCP_PRIVREG(ctx
);
3612 if (unlikely(!ctx
->supervisor
)) {
3613 GEN_EXCP_PRIVREG(ctx
);
3616 gen_op_set_T1(SR(ctx
->opcode
));
3618 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3623 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
)
3625 #if defined(CONFIG_USER_ONLY)
3626 GEN_EXCP_PRIVREG(ctx
);
3628 if (unlikely(!ctx
->supervisor
)) {
3629 GEN_EXCP_PRIVREG(ctx
);
3632 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3635 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3640 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
)
3642 #if defined(CONFIG_USER_ONLY)
3643 GEN_EXCP_PRIVREG(ctx
);
3645 if (unlikely(!ctx
->supervisor
)) {
3646 GEN_EXCP_PRIVREG(ctx
);
3649 gen_op_load_gpr_T0(rS(ctx
->opcode
));
3650 gen_op_set_T1(SR(ctx
->opcode
));
3656 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
)
3658 #if defined(CONFIG_USER_ONLY)
3659 GEN_EXCP_PRIVREG(ctx
);
3661 if (unlikely(!ctx
->supervisor
)) {
3662 GEN_EXCP_PRIVREG(ctx
);
3665 gen_op_load_gpr_T0(rS(ctx
->opcode
));
3666 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3672 #if defined(TARGET_PPC64)
3673 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
3675 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
)
3677 #if defined(CONFIG_USER_ONLY)
3678 GEN_EXCP_PRIVREG(ctx
);
3680 if (unlikely(!ctx
->supervisor
)) {
3681 GEN_EXCP_PRIVREG(ctx
);
3684 gen_op_set_T1(SR(ctx
->opcode
));
3686 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3691 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
3694 #if defined(CONFIG_USER_ONLY)
3695 GEN_EXCP_PRIVREG(ctx
);
3697 if (unlikely(!ctx
->supervisor
)) {
3698 GEN_EXCP_PRIVREG(ctx
);
3701 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3704 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3709 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
)
3711 #if defined(CONFIG_USER_ONLY)
3712 GEN_EXCP_PRIVREG(ctx
);
3714 if (unlikely(!ctx
->supervisor
)) {
3715 GEN_EXCP_PRIVREG(ctx
);
3718 gen_op_load_gpr_T0(rS(ctx
->opcode
));
3719 gen_op_set_T1(SR(ctx
->opcode
));
3725 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
3728 #if defined(CONFIG_USER_ONLY)
3729 GEN_EXCP_PRIVREG(ctx
);
3731 if (unlikely(!ctx
->supervisor
)) {
3732 GEN_EXCP_PRIVREG(ctx
);
3735 gen_op_load_gpr_T0(rS(ctx
->opcode
));
3736 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3741 #endif /* defined(TARGET_PPC64) */
3743 /*** Lookaside buffer management ***/
3744 /* Optional & supervisor only: */
3746 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
)
3748 #if defined(CONFIG_USER_ONLY)
3749 GEN_EXCP_PRIVOPC(ctx
);
3751 if (unlikely(!ctx
->supervisor
)) {
3752 GEN_EXCP_PRIVOPC(ctx
);
3760 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE
)
3762 #if defined(CONFIG_USER_ONLY)
3763 GEN_EXCP_PRIVOPC(ctx
);
3765 if (unlikely(!ctx
->supervisor
)) {
3766 GEN_EXCP_PRIVOPC(ctx
);
3769 gen_op_load_gpr_T0(rB(ctx
->opcode
));
3770 #if defined(TARGET_PPC64)
3780 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
)
3782 #if defined(CONFIG_USER_ONLY)
3783 GEN_EXCP_PRIVOPC(ctx
);
3785 if (unlikely(!ctx
->supervisor
)) {
3786 GEN_EXCP_PRIVOPC(ctx
);
3789 /* This has no effect: it should ensure that all previous
3790 * tlbie have completed
3796 #if defined(TARGET_PPC64)
3798 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI
)
3800 #if defined(CONFIG_USER_ONLY)
3801 GEN_EXCP_PRIVOPC(ctx
);
3803 if (unlikely(!ctx
->supervisor
)) {
3804 GEN_EXCP_PRIVOPC(ctx
);
3812 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
)
3814 #if defined(CONFIG_USER_ONLY)
3815 GEN_EXCP_PRIVOPC(ctx
);
3817 if (unlikely(!ctx
->supervisor
)) {
3818 GEN_EXCP_PRIVOPC(ctx
);
3821 gen_op_load_gpr_T0(rB(ctx
->opcode
));
3827 /*** External control ***/
3829 #define op_eciwx() (*gen_op_eciwx[ctx->mem_idx])()
3830 #define op_ecowx() (*gen_op_ecowx[ctx->mem_idx])()
3831 static GenOpFunc
*gen_op_eciwx
[NB_MEM_FUNCS
] = {
3832 GEN_MEM_FUNCS(eciwx
),
3834 static GenOpFunc
*gen_op_ecowx
[NB_MEM_FUNCS
] = {
3835 GEN_MEM_FUNCS(ecowx
),
3839 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
)
3841 /* Should check EAR[E] & alignment ! */
3842 gen_addr_reg_index(ctx
);
3844 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3848 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
)
3850 /* Should check EAR[E] & alignment ! */
3851 gen_addr_reg_index(ctx
);
3852 gen_op_load_gpr_T1(rS(ctx
->opcode
));
3856 /* PowerPC 601 specific instructions */
3858 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
)
3860 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3862 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3863 if (unlikely(Rc(ctx
->opcode
) != 0))
3868 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
)
3870 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3871 gen_op_POWER_abso();
3872 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3873 if (unlikely(Rc(ctx
->opcode
) != 0))
3878 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
)
3880 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3881 gen_op_POWER_clcs();
3882 /* Rc=1 sets CR0 to an undefined state */
3883 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3887 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
)
3889 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3890 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3892 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3893 if (unlikely(Rc(ctx
->opcode
) != 0))
3898 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
)
3900 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3901 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3902 gen_op_POWER_divo();
3903 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3904 if (unlikely(Rc(ctx
->opcode
) != 0))
3909 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
)
3911 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3912 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3913 gen_op_POWER_divs();
3914 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3915 if (unlikely(Rc(ctx
->opcode
) != 0))
3919 /* divso - divso. */
3920 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
)
3922 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3923 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3924 gen_op_POWER_divso();
3925 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3926 if (unlikely(Rc(ctx
->opcode
) != 0))
3931 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
)
3933 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3934 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3936 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3937 if (unlikely(Rc(ctx
->opcode
) != 0))
3942 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
)
3944 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3945 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3946 gen_op_POWER_dozo();
3947 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3948 if (unlikely(Rc(ctx
->opcode
) != 0))
3953 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
)
3955 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3956 gen_op_set_T1(SIMM(ctx
->opcode
));
3958 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3961 /* As lscbx load from memory byte after byte, it's always endian safe.
3962 * Original POWER is 32 bits only, define 64 bits ops as 32 bits ones
3964 #define op_POWER_lscbx(start, ra, rb) \
3965 (*gen_op_POWER_lscbx[ctx->mem_idx])(start, ra, rb)
3966 #define gen_op_POWER_lscbx_64_raw gen_op_POWER_lscbx_raw
3967 #define gen_op_POWER_lscbx_64_user gen_op_POWER_lscbx_user
3968 #define gen_op_POWER_lscbx_64_kernel gen_op_POWER_lscbx_kernel
3969 #define gen_op_POWER_lscbx_64_hypv gen_op_POWER_lscbx_hypv
3970 #define gen_op_POWER_lscbx_le_raw gen_op_POWER_lscbx_raw
3971 #define gen_op_POWER_lscbx_le_user gen_op_POWER_lscbx_user
3972 #define gen_op_POWER_lscbx_le_kernel gen_op_POWER_lscbx_kernel
3973 #define gen_op_POWER_lscbx_le_hypv gen_op_POWER_lscbx_hypv
3974 #define gen_op_POWER_lscbx_le_64_raw gen_op_POWER_lscbx_raw
3975 #define gen_op_POWER_lscbx_le_64_user gen_op_POWER_lscbx_user
3976 #define gen_op_POWER_lscbx_le_64_kernel gen_op_POWER_lscbx_kernel
3977 #define gen_op_POWER_lscbx_le_64_hypv gen_op_POWER_lscbx_hypv
3978 static GenOpFunc3
*gen_op_POWER_lscbx
[NB_MEM_FUNCS
] = {
3979 GEN_MEM_FUNCS(POWER_lscbx
),
3982 /* lscbx - lscbx. */
3983 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
)
3985 int ra
= rA(ctx
->opcode
);
3986 int rb
= rB(ctx
->opcode
);
3988 gen_addr_reg_index(ctx
);
3992 /* NIP cannot be restored if the memory exception comes from an helper */
3993 gen_update_nip(ctx
, ctx
->nip
- 4);
3994 gen_op_load_xer_bc();
3995 gen_op_load_xer_cmp();
3996 op_POWER_lscbx(rD(ctx
->opcode
), ra
, rb
);
3997 gen_op_store_xer_bc();
3998 if (unlikely(Rc(ctx
->opcode
) != 0))
4002 /* maskg - maskg. */
4003 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
)
4005 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4006 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4007 gen_op_POWER_maskg();
4008 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4009 if (unlikely(Rc(ctx
->opcode
) != 0))
4013 /* maskir - maskir. */
4014 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
)
4016 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4017 gen_op_load_gpr_T1(rS(ctx
->opcode
));
4018 gen_op_load_gpr_T2(rB(ctx
->opcode
));
4019 gen_op_POWER_maskir();
4020 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4021 if (unlikely(Rc(ctx
->opcode
) != 0))
4026 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
)
4028 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4029 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4031 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4032 if (unlikely(Rc(ctx
->opcode
) != 0))
4037 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
)
4039 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4040 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4041 gen_op_POWER_mulo();
4042 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4043 if (unlikely(Rc(ctx
->opcode
) != 0))
4048 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
)
4050 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4051 gen_op_POWER_nabs();
4052 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4053 if (unlikely(Rc(ctx
->opcode
) != 0))
4057 /* nabso - nabso. */
4058 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
)
4060 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4061 gen_op_POWER_nabso();
4062 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4063 if (unlikely(Rc(ctx
->opcode
) != 0))
4068 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
)
4072 mb
= MB(ctx
->opcode
);
4073 me
= ME(ctx
->opcode
);
4074 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4075 gen_op_load_gpr_T1(rA(ctx
->opcode
));
4076 gen_op_load_gpr_T2(rB(ctx
->opcode
));
4077 gen_op_POWER_rlmi(MASK(mb
, me
), ~MASK(mb
, me
));
4078 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4079 if (unlikely(Rc(ctx
->opcode
) != 0))
4084 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
)
4086 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4087 gen_op_load_gpr_T1(rA(ctx
->opcode
));
4088 gen_op_load_gpr_T2(rB(ctx
->opcode
));
4089 gen_op_POWER_rrib();
4090 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4091 if (unlikely(Rc(ctx
->opcode
) != 0))
4096 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
)
4098 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4099 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4101 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4102 if (unlikely(Rc(ctx
->opcode
) != 0))
4107 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
)
4109 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4110 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4111 gen_op_POWER_sleq();
4112 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4113 if (unlikely(Rc(ctx
->opcode
) != 0))
4118 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
)
4120 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4121 gen_op_set_T1(SH(ctx
->opcode
));
4123 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4124 if (unlikely(Rc(ctx
->opcode
) != 0))
4128 /* slliq - slliq. */
4129 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
)
4131 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4132 gen_op_set_T1(SH(ctx
->opcode
));
4133 gen_op_POWER_sleq();
4134 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4135 if (unlikely(Rc(ctx
->opcode
) != 0))
4140 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
)
4142 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4143 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4144 gen_op_POWER_sllq();
4145 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4146 if (unlikely(Rc(ctx
->opcode
) != 0))
4151 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
)
4153 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4154 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4156 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4157 if (unlikely(Rc(ctx
->opcode
) != 0))
4161 /* sraiq - sraiq. */
4162 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
)
4164 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4165 gen_op_set_T1(SH(ctx
->opcode
));
4166 gen_op_POWER_sraq();
4167 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4168 if (unlikely(Rc(ctx
->opcode
) != 0))
4173 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
)
4175 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4176 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4177 gen_op_POWER_sraq();
4178 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4179 if (unlikely(Rc(ctx
->opcode
) != 0))
4184 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
)
4186 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4187 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4189 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4190 if (unlikely(Rc(ctx
->opcode
) != 0))
4195 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
)
4197 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4198 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4199 gen_op_POWER_srea();
4200 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4201 if (unlikely(Rc(ctx
->opcode
) != 0))
4206 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
)
4208 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4209 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4210 gen_op_POWER_sreq();
4211 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4212 if (unlikely(Rc(ctx
->opcode
) != 0))
4217 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
)
4219 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4220 gen_op_set_T1(SH(ctx
->opcode
));
4222 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4223 if (unlikely(Rc(ctx
->opcode
) != 0))
4228 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
)
4230 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4231 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4232 gen_op_set_T1(SH(ctx
->opcode
));
4233 gen_op_POWER_srlq();
4234 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4235 if (unlikely(Rc(ctx
->opcode
) != 0))
4240 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
)
4242 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4243 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4244 gen_op_POWER_srlq();
4245 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4246 if (unlikely(Rc(ctx
->opcode
) != 0))
4251 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
)
4253 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4254 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4256 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4257 if (unlikely(Rc(ctx
->opcode
) != 0))
4261 /* PowerPC 602 specific instructions */
4263 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
)
4266 GEN_EXCP_INVAL(ctx
);
4270 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
)
4273 GEN_EXCP_INVAL(ctx
);
4277 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
)
4279 #if defined(CONFIG_USER_ONLY)
4280 GEN_EXCP_PRIVOPC(ctx
);
4282 if (unlikely(!ctx
->supervisor
)) {
4283 GEN_EXCP_PRIVOPC(ctx
);
4286 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4288 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4292 /* 602 - 603 - G2 TLB management */
4294 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
)
4296 #if defined(CONFIG_USER_ONLY)
4297 GEN_EXCP_PRIVOPC(ctx
);
4299 if (unlikely(!ctx
->supervisor
)) {
4300 GEN_EXCP_PRIVOPC(ctx
);
4303 gen_op_load_gpr_T0(rB(ctx
->opcode
));
4309 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
)
4311 #if defined(CONFIG_USER_ONLY)
4312 GEN_EXCP_PRIVOPC(ctx
);
4314 if (unlikely(!ctx
->supervisor
)) {
4315 GEN_EXCP_PRIVOPC(ctx
);
4318 gen_op_load_gpr_T0(rB(ctx
->opcode
));
4323 /* 74xx TLB management */
4325 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
)
4327 #if defined(CONFIG_USER_ONLY)
4328 GEN_EXCP_PRIVOPC(ctx
);
4330 if (unlikely(!ctx
->supervisor
)) {
4331 GEN_EXCP_PRIVOPC(ctx
);
4334 gen_op_load_gpr_T0(rB(ctx
->opcode
));
4335 gen_op_74xx_tlbld();
4340 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
)
4342 #if defined(CONFIG_USER_ONLY)
4343 GEN_EXCP_PRIVOPC(ctx
);
4345 if (unlikely(!ctx
->supervisor
)) {
4346 GEN_EXCP_PRIVOPC(ctx
);
4349 gen_op_load_gpr_T0(rB(ctx
->opcode
));
4350 gen_op_74xx_tlbli();
4354 /* POWER instructions not in PowerPC 601 */
4356 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
)
4358 /* Cache line flush: implemented as no-op */
4362 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
)
4364 /* Cache line invalidate: privileged and treated as no-op */
4365 #if defined(CONFIG_USER_ONLY)
4366 GEN_EXCP_PRIVOPC(ctx
);
4368 if (unlikely(!ctx
->supervisor
)) {
4369 GEN_EXCP_PRIVOPC(ctx
);
4376 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
)
4378 /* Data cache line store: treated as no-op */
4381 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
)
4383 #if defined(CONFIG_USER_ONLY)
4384 GEN_EXCP_PRIVOPC(ctx
);
4386 if (unlikely(!ctx
->supervisor
)) {
4387 GEN_EXCP_PRIVOPC(ctx
);
4390 int ra
= rA(ctx
->opcode
);
4391 int rd
= rD(ctx
->opcode
);
4393 gen_addr_reg_index(ctx
);
4394 gen_op_POWER_mfsri();
4395 gen_op_store_T0_gpr(rd
);
4396 if (ra
!= 0 && ra
!= rd
)
4397 gen_op_store_T1_gpr(ra
);
4401 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
)
4403 #if defined(CONFIG_USER_ONLY)
4404 GEN_EXCP_PRIVOPC(ctx
);
4406 if (unlikely(!ctx
->supervisor
)) {
4407 GEN_EXCP_PRIVOPC(ctx
);
4410 gen_addr_reg_index(ctx
);
4412 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4416 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
)
4418 #if defined(CONFIG_USER_ONLY)
4419 GEN_EXCP_PRIVOPC(ctx
);
4421 if (unlikely(!ctx
->supervisor
)) {
4422 GEN_EXCP_PRIVOPC(ctx
);
4425 gen_op_POWER_rfsvc();
4430 /* svc is not implemented for now */
4432 /* POWER2 specific instructions */
4433 /* Quad manipulation (load/store two floats at a time) */
4434 /* Original POWER2 is 32 bits only, define 64 bits ops as 32 bits ones */
4435 #define op_POWER2_lfq() (*gen_op_POWER2_lfq[ctx->mem_idx])()
4436 #define op_POWER2_stfq() (*gen_op_POWER2_stfq[ctx->mem_idx])()
4437 #define gen_op_POWER2_lfq_64_raw gen_op_POWER2_lfq_raw
4438 #define gen_op_POWER2_lfq_64_user gen_op_POWER2_lfq_user
4439 #define gen_op_POWER2_lfq_64_kernel gen_op_POWER2_lfq_kernel
4440 #define gen_op_POWER2_lfq_64_hypv gen_op_POWER2_lfq_hypv
4441 #define gen_op_POWER2_lfq_le_64_raw gen_op_POWER2_lfq_le_raw
4442 #define gen_op_POWER2_lfq_le_64_user gen_op_POWER2_lfq_le_user
4443 #define gen_op_POWER2_lfq_le_64_kernel gen_op_POWER2_lfq_le_kernel
4444 #define gen_op_POWER2_lfq_le_64_hypv gen_op_POWER2_lfq_le_hypv
4445 #define gen_op_POWER2_stfq_64_raw gen_op_POWER2_stfq_raw
4446 #define gen_op_POWER2_stfq_64_user gen_op_POWER2_stfq_user
4447 #define gen_op_POWER2_stfq_64_kernel gen_op_POWER2_stfq_kernel
4448 #define gen_op_POWER2_stfq_64_hypv gen_op_POWER2_stfq_hypv
4449 #define gen_op_POWER2_stfq_le_64_raw gen_op_POWER2_stfq_le_raw
4450 #define gen_op_POWER2_stfq_le_64_user gen_op_POWER2_stfq_le_user
4451 #define gen_op_POWER2_stfq_le_64_kernel gen_op_POWER2_stfq_le_kernel
4452 #define gen_op_POWER2_stfq_le_64_hypv gen_op_POWER2_stfq_le_hypv
4453 static GenOpFunc
*gen_op_POWER2_lfq
[NB_MEM_FUNCS
] = {
4454 GEN_MEM_FUNCS(POWER2_lfq
),
4456 static GenOpFunc
*gen_op_POWER2_stfq
[NB_MEM_FUNCS
] = {
4457 GEN_MEM_FUNCS(POWER2_stfq
),
4461 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
4463 /* NIP cannot be restored if the memory exception comes from an helper */
4464 gen_update_nip(ctx
, ctx
->nip
- 4);
4465 gen_addr_imm_index(ctx
, 0);
4467 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
4468 gen_op_store_FT1_fpr(rD(ctx
->opcode
) + 1);
4472 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
4474 int ra
= rA(ctx
->opcode
);
4476 /* NIP cannot be restored if the memory exception comes from an helper */
4477 gen_update_nip(ctx
, ctx
->nip
- 4);
4478 gen_addr_imm_index(ctx
, 0);
4480 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
4481 gen_op_store_FT1_fpr(rD(ctx
->opcode
) + 1);
4483 gen_op_store_T0_gpr(ra
);
4487 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
)
4489 int ra
= rA(ctx
->opcode
);
4491 /* NIP cannot be restored if the memory exception comes from an helper */
4492 gen_update_nip(ctx
, ctx
->nip
- 4);
4493 gen_addr_reg_index(ctx
);
4495 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
4496 gen_op_store_FT1_fpr(rD(ctx
->opcode
) + 1);
4498 gen_op_store_T0_gpr(ra
);
4502 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
)
4504 /* NIP cannot be restored if the memory exception comes from an helper */
4505 gen_update_nip(ctx
, ctx
->nip
- 4);
4506 gen_addr_reg_index(ctx
);
4508 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
4509 gen_op_store_FT1_fpr(rD(ctx
->opcode
) + 1);
4513 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
4515 /* NIP cannot be restored if the memory exception comes from an helper */
4516 gen_update_nip(ctx
, ctx
->nip
- 4);
4517 gen_addr_imm_index(ctx
, 0);
4518 gen_op_load_fpr_FT0(rS(ctx
->opcode
));
4519 gen_op_load_fpr_FT1(rS(ctx
->opcode
) + 1);
4524 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
4526 int ra
= rA(ctx
->opcode
);
4528 /* NIP cannot be restored if the memory exception comes from an helper */
4529 gen_update_nip(ctx
, ctx
->nip
- 4);
4530 gen_addr_imm_index(ctx
, 0);
4531 gen_op_load_fpr_FT0(rS(ctx
->opcode
));
4532 gen_op_load_fpr_FT1(rS(ctx
->opcode
) + 1);
4535 gen_op_store_T0_gpr(ra
);
4539 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
)
4541 int ra
= rA(ctx
->opcode
);
4543 /* NIP cannot be restored if the memory exception comes from an helper */
4544 gen_update_nip(ctx
, ctx
->nip
- 4);
4545 gen_addr_reg_index(ctx
);
4546 gen_op_load_fpr_FT0(rS(ctx
->opcode
));
4547 gen_op_load_fpr_FT1(rS(ctx
->opcode
) + 1);
4550 gen_op_store_T0_gpr(ra
);
4554 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
)
4556 /* NIP cannot be restored if the memory exception comes from an helper */
4557 gen_update_nip(ctx
, ctx
->nip
- 4);
4558 gen_addr_reg_index(ctx
);
4559 gen_op_load_fpr_FT0(rS(ctx
->opcode
));
4560 gen_op_load_fpr_FT1(rS(ctx
->opcode
) + 1);
4564 /* BookE specific instructions */
4565 /* XXX: not implemented on 440 ? */
4566 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
)
4569 GEN_EXCP_INVAL(ctx
);
4572 /* XXX: not implemented on 440 ? */
4573 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
)
4575 #if defined(CONFIG_USER_ONLY)
4576 GEN_EXCP_PRIVOPC(ctx
);
4578 if (unlikely(!ctx
->supervisor
)) {
4579 GEN_EXCP_PRIVOPC(ctx
);
4582 gen_addr_reg_index(ctx
);
4583 /* Use the same micro-ops as for tlbie */
4584 #if defined(TARGET_PPC64)
4593 /* All 405 MAC instructions are translated here */
4594 static always_inline
void gen_405_mulladd_insn (DisasContext
*ctx
,
4596 int ra
, int rb
, int rt
, int Rc
)
4598 gen_op_load_gpr_T0(ra
);
4599 gen_op_load_gpr_T1(rb
);
4600 switch (opc3
& 0x0D) {
4602 /* macchw - macchw. - macchwo - macchwo. */
4603 /* macchws - macchws. - macchwso - macchwso. */
4604 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
4605 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
4606 /* mulchw - mulchw. */
4607 gen_op_405_mulchw();
4610 /* macchwu - macchwu. - macchwuo - macchwuo. */
4611 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
4612 /* mulchwu - mulchwu. */
4613 gen_op_405_mulchwu();
4616 /* machhw - machhw. - machhwo - machhwo. */
4617 /* machhws - machhws. - machhwso - machhwso. */
4618 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
4619 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
4620 /* mulhhw - mulhhw. */
4621 gen_op_405_mulhhw();
4624 /* machhwu - machhwu. - machhwuo - machhwuo. */
4625 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
4626 /* mulhhwu - mulhhwu. */
4627 gen_op_405_mulhhwu();
4630 /* maclhw - maclhw. - maclhwo - maclhwo. */
4631 /* maclhws - maclhws. - maclhwso - maclhwso. */
4632 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
4633 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
4634 /* mullhw - mullhw. */
4635 gen_op_405_mullhw();
4638 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
4639 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
4640 /* mullhwu - mullhwu. */
4641 gen_op_405_mullhwu();
4645 /* nmultiply-and-accumulate (0x0E) */
4649 /* (n)multiply-and-accumulate (0x0C - 0x0E) */
4650 gen_op_load_gpr_T2(rt
);
4651 gen_op_move_T1_T0();
4652 gen_op_405_add_T0_T2();
4655 /* Check overflow */
4657 gen_op_check_addo();
4659 gen_op_405_check_ovu();
4664 gen_op_405_check_sat();
4666 gen_op_405_check_satu();
4668 gen_op_store_T0_gpr(rt
);
4669 if (unlikely(Rc
) != 0) {
4675 #define GEN_MAC_HANDLER(name, opc2, opc3) \
4676 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC) \
4678 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
4679 rD(ctx->opcode), Rc(ctx->opcode)); \
4682 /* macchw - macchw. */
4683 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
4684 /* macchwo - macchwo. */
4685 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
4686 /* macchws - macchws. */
4687 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
4688 /* macchwso - macchwso. */
4689 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
4690 /* macchwsu - macchwsu. */
4691 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
4692 /* macchwsuo - macchwsuo. */
4693 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
4694 /* macchwu - macchwu. */
4695 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
4696 /* macchwuo - macchwuo. */
4697 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
4698 /* machhw - machhw. */
4699 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
4700 /* machhwo - machhwo. */
4701 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
4702 /* machhws - machhws. */
4703 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
4704 /* machhwso - machhwso. */
4705 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
4706 /* machhwsu - machhwsu. */
4707 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
4708 /* machhwsuo - machhwsuo. */
4709 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
4710 /* machhwu - machhwu. */
4711 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
4712 /* machhwuo - machhwuo. */
4713 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
4714 /* maclhw - maclhw. */
4715 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
4716 /* maclhwo - maclhwo. */
4717 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
4718 /* maclhws - maclhws. */
4719 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
4720 /* maclhwso - maclhwso. */
4721 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
4722 /* maclhwu - maclhwu. */
4723 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
4724 /* maclhwuo - maclhwuo. */
4725 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
4726 /* maclhwsu - maclhwsu. */
4727 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
4728 /* maclhwsuo - maclhwsuo. */
4729 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
4730 /* nmacchw - nmacchw. */
4731 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
4732 /* nmacchwo - nmacchwo. */
4733 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
4734 /* nmacchws - nmacchws. */
4735 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
4736 /* nmacchwso - nmacchwso. */
4737 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
4738 /* nmachhw - nmachhw. */
4739 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
4740 /* nmachhwo - nmachhwo. */
4741 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
4742 /* nmachhws - nmachhws. */
4743 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
4744 /* nmachhwso - nmachhwso. */
4745 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
4746 /* nmaclhw - nmaclhw. */
4747 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
4748 /* nmaclhwo - nmaclhwo. */
4749 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
4750 /* nmaclhws - nmaclhws. */
4751 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
4752 /* nmaclhwso - nmaclhwso. */
4753 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
4755 /* mulchw - mulchw. */
4756 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
4757 /* mulchwu - mulchwu. */
4758 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
4759 /* mulhhw - mulhhw. */
4760 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
4761 /* mulhhwu - mulhhwu. */
4762 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
4763 /* mullhw - mullhw. */
4764 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
4765 /* mullhwu - mullhwu. */
4766 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
4769 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
)
4771 #if defined(CONFIG_USER_ONLY)
4772 GEN_EXCP_PRIVREG(ctx
);
4774 uint32_t dcrn
= SPR(ctx
->opcode
);
4776 if (unlikely(!ctx
->supervisor
)) {
4777 GEN_EXCP_PRIVREG(ctx
);
4780 gen_op_set_T0(dcrn
);
4782 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4787 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
)
4789 #if defined(CONFIG_USER_ONLY)
4790 GEN_EXCP_PRIVREG(ctx
);
4792 uint32_t dcrn
= SPR(ctx
->opcode
);
4794 if (unlikely(!ctx
->supervisor
)) {
4795 GEN_EXCP_PRIVREG(ctx
);
4798 gen_op_set_T0(dcrn
);
4799 gen_op_load_gpr_T1(rS(ctx
->opcode
));
4805 /* XXX: not implemented on 440 ? */
4806 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
)
4808 #if defined(CONFIG_USER_ONLY)
4809 GEN_EXCP_PRIVREG(ctx
);
4811 if (unlikely(!ctx
->supervisor
)) {
4812 GEN_EXCP_PRIVREG(ctx
);
4815 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4817 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4818 /* Note: Rc update flag set leads to undefined state of Rc0 */
4823 /* XXX: not implemented on 440 ? */
4824 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
)
4826 #if defined(CONFIG_USER_ONLY)
4827 GEN_EXCP_PRIVREG(ctx
);
4829 if (unlikely(!ctx
->supervisor
)) {
4830 GEN_EXCP_PRIVREG(ctx
);
4833 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4834 gen_op_load_gpr_T1(rS(ctx
->opcode
));
4836 /* Note: Rc update flag set leads to undefined state of Rc0 */
4840 /* mfdcrux (PPC 460) : user-mode access to DCR */
4841 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
)
4843 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4845 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4846 /* Note: Rc update flag set leads to undefined state of Rc0 */
4849 /* mtdcrux (PPC 460) : user-mode access to DCR */
4850 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
)
4852 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4853 gen_op_load_gpr_T1(rS(ctx
->opcode
));
4855 /* Note: Rc update flag set leads to undefined state of Rc0 */
4859 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
)
4861 #if defined(CONFIG_USER_ONLY)
4862 GEN_EXCP_PRIVOPC(ctx
);
4864 if (unlikely(!ctx
->supervisor
)) {
4865 GEN_EXCP_PRIVOPC(ctx
);
4868 /* interpreted as no-op */
4873 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
)
4875 #if defined(CONFIG_USER_ONLY)
4876 GEN_EXCP_PRIVOPC(ctx
);
4878 if (unlikely(!ctx
->supervisor
)) {
4879 GEN_EXCP_PRIVOPC(ctx
);
4882 gen_addr_reg_index(ctx
);
4884 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4889 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
)
4891 /* interpreted as no-op */
4892 /* XXX: specification say this is treated as a load by the MMU
4893 * but does not generate any exception
4898 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
)
4900 #if defined(CONFIG_USER_ONLY)
4901 GEN_EXCP_PRIVOPC(ctx
);
4903 if (unlikely(!ctx
->supervisor
)) {
4904 GEN_EXCP_PRIVOPC(ctx
);
4907 /* interpreted as no-op */
4912 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
)
4914 #if defined(CONFIG_USER_ONLY)
4915 GEN_EXCP_PRIVOPC(ctx
);
4917 if (unlikely(!ctx
->supervisor
)) {
4918 GEN_EXCP_PRIVOPC(ctx
);
4921 /* interpreted as no-op */
4925 /* rfci (supervisor only) */
4926 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
)
4928 #if defined(CONFIG_USER_ONLY)
4929 GEN_EXCP_PRIVOPC(ctx
);
4931 if (unlikely(!ctx
->supervisor
)) {
4932 GEN_EXCP_PRIVOPC(ctx
);
4935 /* Restore CPU state */
4941 GEN_HANDLER(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
)
4943 #if defined(CONFIG_USER_ONLY)
4944 GEN_EXCP_PRIVOPC(ctx
);
4946 if (unlikely(!ctx
->supervisor
)) {
4947 GEN_EXCP_PRIVOPC(ctx
);
4950 /* Restore CPU state */
4956 /* BookE specific */
4957 /* XXX: not implemented on 440 ? */
4958 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
)
4960 #if defined(CONFIG_USER_ONLY)
4961 GEN_EXCP_PRIVOPC(ctx
);
4963 if (unlikely(!ctx
->supervisor
)) {
4964 GEN_EXCP_PRIVOPC(ctx
);
4967 /* Restore CPU state */
4973 /* XXX: not implemented on 440 ? */
4974 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
)
4976 #if defined(CONFIG_USER_ONLY)
4977 GEN_EXCP_PRIVOPC(ctx
);
4979 if (unlikely(!ctx
->supervisor
)) {
4980 GEN_EXCP_PRIVOPC(ctx
);
4983 /* Restore CPU state */
4989 /* TLB management - PowerPC 405 implementation */
4991 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
)
4993 #if defined(CONFIG_USER_ONLY)
4994 GEN_EXCP_PRIVOPC(ctx
);
4996 if (unlikely(!ctx
->supervisor
)) {
4997 GEN_EXCP_PRIVOPC(ctx
);
5000 switch (rB(ctx
->opcode
)) {
5002 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5003 gen_op_4xx_tlbre_hi();
5004 gen_op_store_T0_gpr(rD(ctx
->opcode
));
5007 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5008 gen_op_4xx_tlbre_lo();
5009 gen_op_store_T0_gpr(rD(ctx
->opcode
));
5012 GEN_EXCP_INVAL(ctx
);
5018 /* tlbsx - tlbsx. */
5019 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
)
5021 #if defined(CONFIG_USER_ONLY)
5022 GEN_EXCP_PRIVOPC(ctx
);
5024 if (unlikely(!ctx
->supervisor
)) {
5025 GEN_EXCP_PRIVOPC(ctx
);
5028 gen_addr_reg_index(ctx
);
5030 if (Rc(ctx
->opcode
))
5031 gen_op_4xx_tlbsx_check();
5032 gen_op_store_T0_gpr(rD(ctx
->opcode
));
5037 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
)
5039 #if defined(CONFIG_USER_ONLY)
5040 GEN_EXCP_PRIVOPC(ctx
);
5042 if (unlikely(!ctx
->supervisor
)) {
5043 GEN_EXCP_PRIVOPC(ctx
);
5046 switch (rB(ctx
->opcode
)) {
5048 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5049 gen_op_load_gpr_T1(rS(ctx
->opcode
));
5050 gen_op_4xx_tlbwe_hi();
5053 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5054 gen_op_load_gpr_T1(rS(ctx
->opcode
));
5055 gen_op_4xx_tlbwe_lo();
5058 GEN_EXCP_INVAL(ctx
);
5064 /* TLB management - PowerPC 440 implementation */
5066 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
)
5068 #if defined(CONFIG_USER_ONLY)
5069 GEN_EXCP_PRIVOPC(ctx
);
5071 if (unlikely(!ctx
->supervisor
)) {
5072 GEN_EXCP_PRIVOPC(ctx
);
5075 switch (rB(ctx
->opcode
)) {
5079 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5080 gen_op_440_tlbre(rB(ctx
->opcode
));
5081 gen_op_store_T0_gpr(rD(ctx
->opcode
));
5084 GEN_EXCP_INVAL(ctx
);
5090 /* tlbsx - tlbsx. */
5091 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
)
5093 #if defined(CONFIG_USER_ONLY)
5094 GEN_EXCP_PRIVOPC(ctx
);
5096 if (unlikely(!ctx
->supervisor
)) {
5097 GEN_EXCP_PRIVOPC(ctx
);
5100 gen_addr_reg_index(ctx
);
5102 if (Rc(ctx
->opcode
))
5103 gen_op_4xx_tlbsx_check();
5104 gen_op_store_T0_gpr(rD(ctx
->opcode
));
5109 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
)
5111 #if defined(CONFIG_USER_ONLY)
5112 GEN_EXCP_PRIVOPC(ctx
);
5114 if (unlikely(!ctx
->supervisor
)) {
5115 GEN_EXCP_PRIVOPC(ctx
);
5118 switch (rB(ctx
->opcode
)) {
5122 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5123 gen_op_load_gpr_T1(rS(ctx
->opcode
));
5124 gen_op_440_tlbwe(rB(ctx
->opcode
));
5127 GEN_EXCP_INVAL(ctx
);
5134 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
)
5136 #if defined(CONFIG_USER_ONLY)
5137 GEN_EXCP_PRIVOPC(ctx
);
5139 if (unlikely(!ctx
->supervisor
)) {
5140 GEN_EXCP_PRIVOPC(ctx
);
5143 gen_op_load_gpr_T0(rD(ctx
->opcode
));
5145 /* Stop translation to have a chance to raise an exception
5146 * if we just set msr_ee to 1
5153 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000EFC01, PPC_WRTEE
)
5155 #if defined(CONFIG_USER_ONLY)
5156 GEN_EXCP_PRIVOPC(ctx
);
5158 if (unlikely(!ctx
->supervisor
)) {
5159 GEN_EXCP_PRIVOPC(ctx
);
5162 gen_op_set_T0(ctx
->opcode
& 0x00010000);
5164 /* Stop translation to have a chance to raise an exception
5165 * if we just set msr_ee to 1
5171 /* PowerPC 440 specific instructions */
5173 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
)
5175 gen_op_load_gpr_T0(rS(ctx
->opcode
));
5176 gen_op_load_gpr_T1(rB(ctx
->opcode
));
5178 gen_op_store_T0_gpr(rA(ctx
->opcode
));
5179 gen_op_store_xer_bc();
5180 if (Rc(ctx
->opcode
)) {
5181 gen_op_440_dlmzb_update_Rc();
5182 gen_op_store_T0_crf(0);
5186 /* mbar replaces eieio on 440 */
5187 GEN_HANDLER(mbar
, 0x1F, 0x16, 0x13, 0x001FF801, PPC_BOOKE
)
5189 /* interpreted as no-op */
5192 /* msync replaces sync on 440 */
5193 GEN_HANDLER(msync
, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE
)
5195 /* interpreted as no-op */
5199 GEN_HANDLER2(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001, PPC_BOOKE
)
5201 /* interpreted as no-op */
5202 /* XXX: specification say this is treated as a load by the MMU
5203 * but does not generate any exception
5207 /*** Altivec vector extension ***/
5208 /* Altivec registers moves */
5209 GEN32(gen_op_load_avr_A0
, gen_op_load_avr_A0_avr
);
5210 GEN32(gen_op_load_avr_A1
, gen_op_load_avr_A1_avr
);
5211 GEN32(gen_op_load_avr_A2
, gen_op_load_avr_A2_avr
);
5213 GEN32(gen_op_store_A0_avr
, gen_op_store_A0_avr_avr
);
5214 GEN32(gen_op_store_A1_avr
, gen_op_store_A1_avr_avr
);
5216 GEN32(gen_op_store_A2_avr
, gen_op_store_A2_avr_avr
);
5219 #define op_vr_ldst(name) (*gen_op_##name[ctx->mem_idx])()
5220 #define OP_VR_LD_TABLE(name) \
5221 static GenOpFunc *gen_op_vr_l##name[NB_MEM_FUNCS] = { \
5222 GEN_MEM_FUNCS(vr_l##name), \
5224 #define OP_VR_ST_TABLE(name) \
5225 static GenOpFunc *gen_op_vr_st##name[NB_MEM_FUNCS] = { \
5226 GEN_MEM_FUNCS(vr_st##name), \
5229 #define GEN_VR_LDX(name, opc2, opc3) \
5230 GEN_HANDLER(l##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
5232 if (unlikely(!ctx->altivec_enabled)) { \
5233 GEN_EXCP_NO_VR(ctx); \
5236 gen_addr_reg_index(ctx); \
5237 op_vr_ldst(vr_l##name); \
5238 gen_op_store_A0_avr(rD(ctx->opcode)); \
5241 #define GEN_VR_STX(name, opc2, opc3) \
5242 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
5244 if (unlikely(!ctx->altivec_enabled)) { \
5245 GEN_EXCP_NO_VR(ctx); \
5248 gen_addr_reg_index(ctx); \
5249 gen_op_load_avr_A0(rS(ctx->opcode)); \
5250 op_vr_ldst(vr_st##name); \
5254 GEN_VR_LDX(vx
, 0x07, 0x03);
5255 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
5256 #define gen_op_vr_lvxl gen_op_vr_lvx
5257 GEN_VR_LDX(vxl
, 0x07, 0x0B);
5260 GEN_VR_STX(vx
, 0x07, 0x07);
5261 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
5262 #define gen_op_vr_stvxl gen_op_vr_stvx
5263 GEN_VR_STX(vxl
, 0x07, 0x0F);
5265 /*** SPE extension ***/
5266 /* Register moves */
5267 #if !defined(TARGET_PPC64)
5269 GEN32(gen_op_load_gpr64_T0
, gen_op_load_gpr64_T0_gpr
);
5270 GEN32(gen_op_load_gpr64_T1
, gen_op_load_gpr64_T1_gpr
);
5272 GEN32(gen_op_load_gpr64_T2
, gen_op_load_gpr64_T2_gpr
);
5275 GEN32(gen_op_store_T0_gpr64
, gen_op_store_T0_gpr64_gpr
);
5276 GEN32(gen_op_store_T1_gpr64
, gen_op_store_T1_gpr64_gpr
);
5278 GEN32(gen_op_store_T2_gpr64
, gen_op_store_T2_gpr64_gpr
);
5281 #else /* !defined(TARGET_PPC64) */
5283 /* No specific load/store functions: GPRs are already 64 bits */
5284 #define gen_op_load_gpr64_T0 gen_op_load_gpr_T0
5285 #define gen_op_load_gpr64_T1 gen_op_load_gpr_T1
5287 #define gen_op_load_gpr64_T2 gen_op_load_gpr_T2
5290 #define gen_op_store_T0_gpr64 gen_op_store_T0_gpr
5291 #define gen_op_store_T1_gpr64 gen_op_store_T1_gpr
5293 #define gen_op_store_T2_gpr64 gen_op_store_T2_gpr
5296 #endif /* !defined(TARGET_PPC64) */
5298 #define GEN_SPE(name0, name1, opc2, opc3, inval, type) \
5299 GEN_HANDLER(name0##_##name1, 0x04, opc2, opc3, inval, type) \
5301 if (Rc(ctx->opcode)) \
5307 /* Handler for undefined SPE opcodes */
5308 static always_inline
void gen_speundef (DisasContext
*ctx
)
5310 GEN_EXCP_INVAL(ctx
);
5313 /* SPE load and stores */
5314 static always_inline
void gen_addr_spe_imm_index (DisasContext
*ctx
, int sh
)
5316 target_long simm
= rB(ctx
->opcode
);
5318 if (rA(ctx
->opcode
) == 0) {
5319 gen_set_T0(simm
<< sh
);
5321 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5322 if (likely(simm
!= 0))
5323 gen_op_addi(simm
<< sh
);
5327 #define op_spe_ldst(name) (*gen_op_##name[ctx->mem_idx])()
5328 #define OP_SPE_LD_TABLE(name) \
5329 static GenOpFunc *gen_op_spe_l##name[NB_MEM_FUNCS] = { \
5330 GEN_MEM_FUNCS(spe_l##name), \
5332 #define OP_SPE_ST_TABLE(name) \
5333 static GenOpFunc *gen_op_spe_st##name[NB_MEM_FUNCS] = { \
5334 GEN_MEM_FUNCS(spe_st##name), \
5337 #define GEN_SPE_LD(name, sh) \
5338 static always_inline void gen_evl##name (DisasContext *ctx) \
5340 if (unlikely(!ctx->spe_enabled)) { \
5341 GEN_EXCP_NO_AP(ctx); \
5344 gen_addr_spe_imm_index(ctx, sh); \
5345 op_spe_ldst(spe_l##name); \
5346 gen_op_store_T1_gpr64(rD(ctx->opcode)); \
5349 #define GEN_SPE_LDX(name) \
5350 static always_inline void gen_evl##name##x (DisasContext *ctx) \
5352 if (unlikely(!ctx->spe_enabled)) { \
5353 GEN_EXCP_NO_AP(ctx); \
5356 gen_addr_reg_index(ctx); \
5357 op_spe_ldst(spe_l##name); \
5358 gen_op_store_T1_gpr64(rD(ctx->opcode)); \
5361 #define GEN_SPEOP_LD(name, sh) \
5362 OP_SPE_LD_TABLE(name); \
5363 GEN_SPE_LD(name, sh); \
5366 #define GEN_SPE_ST(name, sh) \
5367 static always_inline void gen_evst##name (DisasContext *ctx) \
5369 if (unlikely(!ctx->spe_enabled)) { \
5370 GEN_EXCP_NO_AP(ctx); \
5373 gen_addr_spe_imm_index(ctx, sh); \
5374 gen_op_load_gpr64_T1(rS(ctx->opcode)); \
5375 op_spe_ldst(spe_st##name); \
5378 #define GEN_SPE_STX(name) \
5379 static always_inline void gen_evst##name##x (DisasContext *ctx) \
5381 if (unlikely(!ctx->spe_enabled)) { \
5382 GEN_EXCP_NO_AP(ctx); \
5385 gen_addr_reg_index(ctx); \
5386 gen_op_load_gpr64_T1(rS(ctx->opcode)); \
5387 op_spe_ldst(spe_st##name); \
5390 #define GEN_SPEOP_ST(name, sh) \
5391 OP_SPE_ST_TABLE(name); \
5392 GEN_SPE_ST(name, sh); \
5395 #define GEN_SPEOP_LDST(name, sh) \
5396 GEN_SPEOP_LD(name, sh); \
5397 GEN_SPEOP_ST(name, sh)
5399 /* SPE arithmetic and logic */
5400 #define GEN_SPEOP_ARITH2(name) \
5401 static always_inline void gen_##name (DisasContext *ctx) \
5403 if (unlikely(!ctx->spe_enabled)) { \
5404 GEN_EXCP_NO_AP(ctx); \
5407 gen_op_load_gpr64_T0(rA(ctx->opcode)); \
5408 gen_op_load_gpr64_T1(rB(ctx->opcode)); \
5410 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5413 #define GEN_SPEOP_ARITH1(name) \
5414 static always_inline void gen_##name (DisasContext *ctx) \
5416 if (unlikely(!ctx->spe_enabled)) { \
5417 GEN_EXCP_NO_AP(ctx); \
5420 gen_op_load_gpr64_T0(rA(ctx->opcode)); \
5422 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5425 #define GEN_SPEOP_COMP(name) \
5426 static always_inline void gen_##name (DisasContext *ctx) \
5428 if (unlikely(!ctx->spe_enabled)) { \
5429 GEN_EXCP_NO_AP(ctx); \
5432 gen_op_load_gpr64_T0(rA(ctx->opcode)); \
5433 gen_op_load_gpr64_T1(rB(ctx->opcode)); \
5435 gen_op_store_T0_crf(crfD(ctx->opcode)); \
5439 GEN_SPEOP_ARITH2(evand
);
5440 GEN_SPEOP_ARITH2(evandc
);
5441 GEN_SPEOP_ARITH2(evxor
);
5442 GEN_SPEOP_ARITH2(evor
);
5443 GEN_SPEOP_ARITH2(evnor
);
5444 GEN_SPEOP_ARITH2(eveqv
);
5445 GEN_SPEOP_ARITH2(evorc
);
5446 GEN_SPEOP_ARITH2(evnand
);
5447 GEN_SPEOP_ARITH2(evsrwu
);
5448 GEN_SPEOP_ARITH2(evsrws
);
5449 GEN_SPEOP_ARITH2(evslw
);
5450 GEN_SPEOP_ARITH2(evrlw
);
5451 GEN_SPEOP_ARITH2(evmergehi
);
5452 GEN_SPEOP_ARITH2(evmergelo
);
5453 GEN_SPEOP_ARITH2(evmergehilo
);
5454 GEN_SPEOP_ARITH2(evmergelohi
);
5457 GEN_SPEOP_ARITH2(evaddw
);
5458 GEN_SPEOP_ARITH2(evsubfw
);
5459 GEN_SPEOP_ARITH1(evabs
);
5460 GEN_SPEOP_ARITH1(evneg
);
5461 GEN_SPEOP_ARITH1(evextsb
);
5462 GEN_SPEOP_ARITH1(evextsh
);
5463 GEN_SPEOP_ARITH1(evrndw
);
5464 GEN_SPEOP_ARITH1(evcntlzw
);
5465 GEN_SPEOP_ARITH1(evcntlsw
);
5466 static always_inline
void gen_brinc (DisasContext
*ctx
)
5468 /* Note: brinc is usable even if SPE is disabled */
5469 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5470 gen_op_load_gpr_T1(rB(ctx
->opcode
));
5472 gen_op_store_T0_gpr(rD(ctx
->opcode
));
5475 #define GEN_SPEOP_ARITH_IMM2(name) \
5476 static always_inline void gen_##name##i (DisasContext *ctx) \
5478 if (unlikely(!ctx->spe_enabled)) { \
5479 GEN_EXCP_NO_AP(ctx); \
5482 gen_op_load_gpr64_T0(rB(ctx->opcode)); \
5483 gen_op_splatwi_T1_64(rA(ctx->opcode)); \
5485 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5488 #define GEN_SPEOP_LOGIC_IMM2(name) \
5489 static always_inline void gen_##name##i (DisasContext *ctx) \
5491 if (unlikely(!ctx->spe_enabled)) { \
5492 GEN_EXCP_NO_AP(ctx); \
5495 gen_op_load_gpr64_T0(rA(ctx->opcode)); \
5496 gen_op_splatwi_T1_64(rB(ctx->opcode)); \
5498 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5501 GEN_SPEOP_ARITH_IMM2(evaddw
);
5502 #define gen_evaddiw gen_evaddwi
5503 GEN_SPEOP_ARITH_IMM2(evsubfw
);
5504 #define gen_evsubifw gen_evsubfwi
5505 GEN_SPEOP_LOGIC_IMM2(evslw
);
5506 GEN_SPEOP_LOGIC_IMM2(evsrwu
);
5507 #define gen_evsrwis gen_evsrwsi
5508 GEN_SPEOP_LOGIC_IMM2(evsrws
);
5509 #define gen_evsrwiu gen_evsrwui
5510 GEN_SPEOP_LOGIC_IMM2(evrlw
);
5512 static always_inline
void gen_evsplati (DisasContext
*ctx
)
5514 int32_t imm
= (int32_t)(rA(ctx
->opcode
) << 27) >> 27;
5516 gen_op_splatwi_T0_64(imm
);
5517 gen_op_store_T0_gpr64(rD(ctx
->opcode
));
5520 static always_inline
void gen_evsplatfi (DisasContext
*ctx
)
5522 uint32_t imm
= rA(ctx
->opcode
) << 27;
5524 gen_op_splatwi_T0_64(imm
);
5525 gen_op_store_T0_gpr64(rD(ctx
->opcode
));
5529 GEN_SPEOP_COMP(evcmpgtu
);
5530 GEN_SPEOP_COMP(evcmpgts
);
5531 GEN_SPEOP_COMP(evcmpltu
);
5532 GEN_SPEOP_COMP(evcmplts
);
5533 GEN_SPEOP_COMP(evcmpeq
);
5535 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, PPC_SPE
); ////
5536 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, PPC_SPE
);
5537 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, PPC_SPE
); ////
5538 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, PPC_SPE
);
5539 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, PPC_SPE
); ////
5540 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, PPC_SPE
); ////
5541 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, PPC_SPE
); ////
5542 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x00000000, PPC_SPE
); //
5543 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0x00000000, PPC_SPE
); ////
5544 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, PPC_SPE
); ////
5545 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, PPC_SPE
); ////
5546 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, PPC_SPE
); ////
5547 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0x00000000, PPC_SPE
); ////
5548 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, PPC_SPE
); ////
5549 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, PPC_SPE
); ////
5550 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, PPC_SPE
);
5551 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, PPC_SPE
); ////
5552 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, PPC_SPE
);
5553 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, PPC_SPE
); //
5554 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, PPC_SPE
);
5555 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, PPC_SPE
); ////
5556 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, PPC_SPE
); ////
5557 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, PPC_SPE
); ////
5558 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, PPC_SPE
); ////
5559 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, PPC_SPE
); ////
5561 static always_inline
void gen_evsel (DisasContext
*ctx
)
5563 if (unlikely(!ctx
->spe_enabled
)) {
5564 GEN_EXCP_NO_AP(ctx
);
5567 gen_op_load_crf_T0(ctx
->opcode
& 0x7);
5568 gen_op_load_gpr64_T0(rA(ctx
->opcode
));
5569 gen_op_load_gpr64_T1(rB(ctx
->opcode
));
5571 gen_op_store_T0_gpr64(rD(ctx
->opcode
));
5574 GEN_HANDLER2(evsel0
, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE
)
5578 GEN_HANDLER2(evsel1
, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE
)
5582 GEN_HANDLER2(evsel2
, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE
)
5586 GEN_HANDLER2(evsel3
, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE
)
5591 /* Load and stores */
5592 #if defined(TARGET_PPC64)
5593 /* In that case, we already have 64 bits load & stores
5594 * so, spe_ldd is equivalent to ld and spe_std is equivalent to std
5596 #define gen_op_spe_ldd_raw gen_op_ld_raw
5597 #define gen_op_spe_ldd_user gen_op_ld_user
5598 #define gen_op_spe_ldd_kernel gen_op_ld_kernel
5599 #define gen_op_spe_ldd_hypv gen_op_ld_hypv
5600 #define gen_op_spe_ldd_64_raw gen_op_ld_64_raw
5601 #define gen_op_spe_ldd_64_user gen_op_ld_64_user
5602 #define gen_op_spe_ldd_64_kernel gen_op_ld_64_kernel
5603 #define gen_op_spe_ldd_64_hypv gen_op_ld_64_hypv
5604 #define gen_op_spe_ldd_le_raw gen_op_ld_le_raw
5605 #define gen_op_spe_ldd_le_user gen_op_ld_le_user
5606 #define gen_op_spe_ldd_le_kernel gen_op_ld_le_kernel
5607 #define gen_op_spe_ldd_le_hypv gen_op_ld_le_hypv
5608 #define gen_op_spe_ldd_le_64_raw gen_op_ld_le_64_raw
5609 #define gen_op_spe_ldd_le_64_user gen_op_ld_le_64_user
5610 #define gen_op_spe_ldd_le_64_kernel gen_op_ld_le_64_kernel
5611 #define gen_op_spe_ldd_le_64_hypv gen_op_ld_le_64_hypv
5612 #define gen_op_spe_stdd_raw gen_op_std_raw
5613 #define gen_op_spe_stdd_user gen_op_std_user
5614 #define gen_op_spe_stdd_kernel gen_op_std_kernel
5615 #define gen_op_spe_stdd_hypv gen_op_std_hypv
5616 #define gen_op_spe_stdd_64_raw gen_op_std_64_raw
5617 #define gen_op_spe_stdd_64_user gen_op_std_64_user
5618 #define gen_op_spe_stdd_64_kernel gen_op_std_64_kernel
5619 #define gen_op_spe_stdd_64_hypv gen_op_std_64_hypv
5620 #define gen_op_spe_stdd_le_raw gen_op_std_le_raw
5621 #define gen_op_spe_stdd_le_user gen_op_std_le_user
5622 #define gen_op_spe_stdd_le_kernel gen_op_std_le_kernel
5623 #define gen_op_spe_stdd_le_hypv gen_op_std_le_hypv
5624 #define gen_op_spe_stdd_le_64_raw gen_op_std_le_64_raw
5625 #define gen_op_spe_stdd_le_64_user gen_op_std_le_64_user
5626 #define gen_op_spe_stdd_le_64_kernel gen_op_std_le_64_kernel
5627 #define gen_op_spe_stdd_le_64_hypv gen_op_std_le_64_hypv
5628 #endif /* defined(TARGET_PPC64) */
5629 GEN_SPEOP_LDST(dd
, 3);
5630 GEN_SPEOP_LDST(dw
, 3);
5631 GEN_SPEOP_LDST(dh
, 3);
5632 GEN_SPEOP_LDST(whe
, 2);
5633 GEN_SPEOP_LD(whou
, 2);
5634 GEN_SPEOP_LD(whos
, 2);
5635 GEN_SPEOP_ST(who
, 2);
5637 #if defined(TARGET_PPC64)
5638 /* In that case, spe_stwwo is equivalent to stw */
5639 #define gen_op_spe_stwwo_raw gen_op_stw_raw
5640 #define gen_op_spe_stwwo_user gen_op_stw_user
5641 #define gen_op_spe_stwwo_kernel gen_op_stw_kernel
5642 #define gen_op_spe_stwwo_hypv gen_op_stw_hypv
5643 #define gen_op_spe_stwwo_le_raw gen_op_stw_le_raw
5644 #define gen_op_spe_stwwo_le_user gen_op_stw_le_user
5645 #define gen_op_spe_stwwo_le_kernel gen_op_stw_le_kernel
5646 #define gen_op_spe_stwwo_le_hypv gen_op_stw_le_hypv
5647 #define gen_op_spe_stwwo_64_raw gen_op_stw_64_raw
5648 #define gen_op_spe_stwwo_64_user gen_op_stw_64_user
5649 #define gen_op_spe_stwwo_64_kernel gen_op_stw_64_kernel
5650 #define gen_op_spe_stwwo_64_hypv gen_op_stw_64_hypv
5651 #define gen_op_spe_stwwo_le_64_raw gen_op_stw_le_64_raw
5652 #define gen_op_spe_stwwo_le_64_user gen_op_stw_le_64_user
5653 #define gen_op_spe_stwwo_le_64_kernel gen_op_stw_le_64_kernel
5654 #define gen_op_spe_stwwo_le_64_hypv gen_op_stw_le_64_hypv
5656 #define _GEN_OP_SPE_STWWE(suffix) \
5657 static always_inline void gen_op_spe_stwwe_##suffix (void) \
5659 gen_op_srli32_T1_64(); \
5660 gen_op_spe_stwwo_##suffix(); \
5662 #define _GEN_OP_SPE_STWWE_LE(suffix) \
5663 static always_inline void gen_op_spe_stwwe_le_##suffix (void) \
5665 gen_op_srli32_T1_64(); \
5666 gen_op_spe_stwwo_le_##suffix(); \
5668 #if defined(TARGET_PPC64)
5669 #define GEN_OP_SPE_STWWE(suffix) \
5670 _GEN_OP_SPE_STWWE(suffix); \
5671 _GEN_OP_SPE_STWWE_LE(suffix); \
5672 static always_inline void gen_op_spe_stwwe_64_##suffix (void) \
5674 gen_op_srli32_T1_64(); \
5675 gen_op_spe_stwwo_64_##suffix(); \
5677 static always_inline void gen_op_spe_stwwe_le_64_##suffix (void) \
5679 gen_op_srli32_T1_64(); \
5680 gen_op_spe_stwwo_le_64_##suffix(); \
5683 #define GEN_OP_SPE_STWWE(suffix) \
5684 _GEN_OP_SPE_STWWE(suffix); \
5685 _GEN_OP_SPE_STWWE_LE(suffix)
5687 #if defined(CONFIG_USER_ONLY)
5688 GEN_OP_SPE_STWWE(raw
);
5689 #else /* defined(CONFIG_USER_ONLY) */
5690 GEN_OP_SPE_STWWE(user
);
5691 GEN_OP_SPE_STWWE(kernel
);
5692 GEN_OP_SPE_STWWE(hypv
);
5693 #endif /* defined(CONFIG_USER_ONLY) */
5694 GEN_SPEOP_ST(wwe
, 2);
5695 GEN_SPEOP_ST(wwo
, 2);
5697 #define GEN_SPE_LDSPLAT(name, op, suffix) \
5698 static always_inline void gen_op_spe_l##name##_##suffix (void) \
5700 gen_op_##op##_##suffix(); \
5701 gen_op_splatw_T1_64(); \
5704 #define GEN_OP_SPE_LHE(suffix) \
5705 static always_inline void gen_op_spe_lhe_##suffix (void) \
5707 gen_op_spe_lh_##suffix(); \
5708 gen_op_sli16_T1_64(); \
5711 #define GEN_OP_SPE_LHX(suffix) \
5712 static always_inline void gen_op_spe_lhx_##suffix (void) \
5714 gen_op_spe_lh_##suffix(); \
5715 gen_op_extsh_T1_64(); \
5718 #if defined(CONFIG_USER_ONLY)
5719 GEN_OP_SPE_LHE(raw
);
5720 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, raw
);
5721 GEN_OP_SPE_LHE(le_raw
);
5722 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_raw
);
5723 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, raw
);
5724 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_raw
);
5725 GEN_OP_SPE_LHX(raw
);
5726 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, raw
);
5727 GEN_OP_SPE_LHX(le_raw
);
5728 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_raw
);
5729 #if defined(TARGET_PPC64)
5730 GEN_OP_SPE_LHE(64_raw
);
5731 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, 64_raw
);
5732 GEN_OP_SPE_LHE(le_64_raw
);
5733 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_64_raw
);
5734 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, 64_raw
);
5735 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_64_raw
);
5736 GEN_OP_SPE_LHX(64_raw
);
5737 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, 64_raw
);
5738 GEN_OP_SPE_LHX(le_64_raw
);
5739 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_64_raw
);
5742 GEN_OP_SPE_LHE(user
);
5743 GEN_OP_SPE_LHE(kernel
);
5744 GEN_OP_SPE_LHE(hypv
);
5745 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, user
);
5746 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, kernel
);
5747 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, hypv
);
5748 GEN_OP_SPE_LHE(le_user
);
5749 GEN_OP_SPE_LHE(le_kernel
);
5750 GEN_OP_SPE_LHE(le_hypv
);
5751 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_user
);
5752 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_kernel
);
5753 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_hypv
);
5754 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, user
);
5755 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, kernel
);
5756 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, hypv
);
5757 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_user
);
5758 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_kernel
);
5759 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_hypv
);
5760 GEN_OP_SPE_LHX(user
);
5761 GEN_OP_SPE_LHX(kernel
);
5762 GEN_OP_SPE_LHX(hypv
);
5763 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, user
);
5764 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, kernel
);
5765 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, hypv
);
5766 GEN_OP_SPE_LHX(le_user
);
5767 GEN_OP_SPE_LHX(le_kernel
);
5768 GEN_OP_SPE_LHX(le_hypv
);
5769 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_user
);
5770 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_kernel
);
5771 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_hypv
);
5772 #if defined(TARGET_PPC64)
5773 GEN_OP_SPE_LHE(64_user
);
5774 GEN_OP_SPE_LHE(64_kernel
);
5775 GEN_OP_SPE_LHE(64_hypv
);
5776 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, 64_user
);
5777 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, 64_kernel
);
5778 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, 64_hypv
);
5779 GEN_OP_SPE_LHE(le_64_user
);
5780 GEN_OP_SPE_LHE(le_64_kernel
);
5781 GEN_OP_SPE_LHE(le_64_hypv
);
5782 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_64_user
);
5783 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_64_kernel
);
5784 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_64_hypv
);
5785 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, 64_user
);
5786 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, 64_kernel
);
5787 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, 64_hypv
);
5788 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_64_user
);
5789 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_64_kernel
);
5790 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_64_hypv
);
5791 GEN_OP_SPE_LHX(64_user
);
5792 GEN_OP_SPE_LHX(64_kernel
);
5793 GEN_OP_SPE_LHX(64_hypv
);
5794 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, 64_user
);
5795 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, 64_kernel
);
5796 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, 64_hypv
);
5797 GEN_OP_SPE_LHX(le_64_user
);
5798 GEN_OP_SPE_LHX(le_64_kernel
);
5799 GEN_OP_SPE_LHX(le_64_hypv
);
5800 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_64_user
);
5801 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_64_kernel
);
5802 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_64_hypv
);
5805 GEN_SPEOP_LD(hhesplat
, 1);
5806 GEN_SPEOP_LD(hhousplat
, 1);
5807 GEN_SPEOP_LD(hhossplat
, 1);
5808 GEN_SPEOP_LD(wwsplat
, 2);
5809 GEN_SPEOP_LD(whsplat
, 2);
5811 GEN_SPE(evlddx
, evldd
, 0x00, 0x0C, 0x00000000, PPC_SPE
); //
5812 GEN_SPE(evldwx
, evldw
, 0x01, 0x0C, 0x00000000, PPC_SPE
); //
5813 GEN_SPE(evldhx
, evldh
, 0x02, 0x0C, 0x00000000, PPC_SPE
); //
5814 GEN_SPE(evlhhesplatx
, evlhhesplat
, 0x04, 0x0C, 0x00000000, PPC_SPE
); //
5815 GEN_SPE(evlhhousplatx
, evlhhousplat
, 0x06, 0x0C, 0x00000000, PPC_SPE
); //
5816 GEN_SPE(evlhhossplatx
, evlhhossplat
, 0x07, 0x0C, 0x00000000, PPC_SPE
); //
5817 GEN_SPE(evlwhex
, evlwhe
, 0x08, 0x0C, 0x00000000, PPC_SPE
); //
5818 GEN_SPE(evlwhoux
, evlwhou
, 0x0A, 0x0C, 0x00000000, PPC_SPE
); //
5819 GEN_SPE(evlwhosx
, evlwhos
, 0x0B, 0x0C, 0x00000000, PPC_SPE
); //
5820 GEN_SPE(evlwwsplatx
, evlwwsplat
, 0x0C, 0x0C, 0x00000000, PPC_SPE
); //
5821 GEN_SPE(evlwhsplatx
, evlwhsplat
, 0x0E, 0x0C, 0x00000000, PPC_SPE
); //
5822 GEN_SPE(evstddx
, evstdd
, 0x10, 0x0C, 0x00000000, PPC_SPE
); //
5823 GEN_SPE(evstdwx
, evstdw
, 0x11, 0x0C, 0x00000000, PPC_SPE
); //
5824 GEN_SPE(evstdhx
, evstdh
, 0x12, 0x0C, 0x00000000, PPC_SPE
); //
5825 GEN_SPE(evstwhex
, evstwhe
, 0x18, 0x0C, 0x00000000, PPC_SPE
); //
5826 GEN_SPE(evstwhox
, evstwho
, 0x1A, 0x0C, 0x00000000, PPC_SPE
); //
5827 GEN_SPE(evstwwex
, evstwwe
, 0x1C, 0x0C, 0x00000000, PPC_SPE
); //
5828 GEN_SPE(evstwwox
, evstwwo
, 0x1E, 0x0C, 0x00000000, PPC_SPE
); //
5830 /* Multiply and add - TODO */
5832 GEN_SPE(speundef
, evmhessf
, 0x01, 0x10, 0x00000000, PPC_SPE
);
5833 GEN_SPE(speundef
, evmhossf
, 0x03, 0x10, 0x00000000, PPC_SPE
);
5834 GEN_SPE(evmheumi
, evmhesmi
, 0x04, 0x10, 0x00000000, PPC_SPE
);
5835 GEN_SPE(speundef
, evmhesmf
, 0x05, 0x10, 0x00000000, PPC_SPE
);
5836 GEN_SPE(evmhoumi
, evmhosmi
, 0x06, 0x10, 0x00000000, PPC_SPE
);
5837 GEN_SPE(speundef
, evmhosmf
, 0x07, 0x10, 0x00000000, PPC_SPE
);
5838 GEN_SPE(speundef
, evmhessfa
, 0x11, 0x10, 0x00000000, PPC_SPE
);
5839 GEN_SPE(speundef
, evmhossfa
, 0x13, 0x10, 0x00000000, PPC_SPE
);
5840 GEN_SPE(evmheumia
, evmhesmia
, 0x14, 0x10, 0x00000000, PPC_SPE
);
5841 GEN_SPE(speundef
, evmhesmfa
, 0x15, 0x10, 0x00000000, PPC_SPE
);
5842 GEN_SPE(evmhoumia
, evmhosmia
, 0x16, 0x10, 0x00000000, PPC_SPE
);
5843 GEN_SPE(speundef
, evmhosmfa
, 0x17, 0x10, 0x00000000, PPC_SPE
);
5845 GEN_SPE(speundef
, evmwhssf
, 0x03, 0x11, 0x00000000, PPC_SPE
);
5846 GEN_SPE(evmwlumi
, speundef
, 0x04, 0x11, 0x00000000, PPC_SPE
);
5847 GEN_SPE(evmwhumi
, evmwhsmi
, 0x06, 0x11, 0x00000000, PPC_SPE
);
5848 GEN_SPE(speundef
, evmwhsmf
, 0x07, 0x11, 0x00000000, PPC_SPE
);
5849 GEN_SPE(speundef
, evmwssf
, 0x09, 0x11, 0x00000000, PPC_SPE
);
5850 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, PPC_SPE
);
5851 GEN_SPE(speundef
, evmwsmf
, 0x0D, 0x11, 0x00000000, PPC_SPE
);
5852 GEN_SPE(speundef
, evmwhssfa
, 0x13, 0x11, 0x00000000, PPC_SPE
);
5853 GEN_SPE(evmwlumia
, speundef
, 0x14, 0x11, 0x00000000, PPC_SPE
);
5854 GEN_SPE(evmwhumia
, evmwhsmia
, 0x16, 0x11, 0x00000000, PPC_SPE
);
5855 GEN_SPE(speundef
, evmwhsmfa
, 0x17, 0x11, 0x00000000, PPC_SPE
);
5856 GEN_SPE(speundef
, evmwssfa
, 0x19, 0x11, 0x00000000, PPC_SPE
);
5857 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, PPC_SPE
);
5858 GEN_SPE(speundef
, evmwsmfa
, 0x1D, 0x11, 0x00000000, PPC_SPE
);
5860 GEN_SPE(evadduiaaw
, evaddsiaaw
, 0x00, 0x13, 0x0000F800, PPC_SPE
);
5861 GEN_SPE(evsubfusiaaw
, evsubfssiaaw
, 0x01, 0x13, 0x0000F800, PPC_SPE
);
5862 GEN_SPE(evaddumiaaw
, evaddsmiaaw
, 0x04, 0x13, 0x0000F800, PPC_SPE
);
5863 GEN_SPE(evsubfumiaaw
, evsubfsmiaaw
, 0x05, 0x13, 0x0000F800, PPC_SPE
);
5864 GEN_SPE(evdivws
, evdivwu
, 0x06, 0x13, 0x00000000, PPC_SPE
);
5865 GEN_SPE(evmra
, speundef
, 0x07, 0x13, 0x0000F800, PPC_SPE
);
5867 GEN_SPE(evmheusiaaw
, evmhessiaaw
, 0x00, 0x14, 0x00000000, PPC_SPE
);
5868 GEN_SPE(speundef
, evmhessfaaw
, 0x01, 0x14, 0x00000000, PPC_SPE
);
5869 GEN_SPE(evmhousiaaw
, evmhossiaaw
, 0x02, 0x14, 0x00000000, PPC_SPE
);
5870 GEN_SPE(speundef
, evmhossfaaw
, 0x03, 0x14, 0x00000000, PPC_SPE
);
5871 GEN_SPE(evmheumiaaw
, evmhesmiaaw
, 0x04, 0x14, 0x00000000, PPC_SPE
);
5872 GEN_SPE(speundef
, evmhesmfaaw
, 0x05, 0x14, 0x00000000, PPC_SPE
);
5873 GEN_SPE(evmhoumiaaw
, evmhosmiaaw
, 0x06, 0x14, 0x00000000, PPC_SPE
);
5874 GEN_SPE(speundef
, evmhosmfaaw
, 0x07, 0x14, 0x00000000, PPC_SPE
);
5875 GEN_SPE(evmhegumiaa
, evmhegsmiaa
, 0x14, 0x14, 0x00000000, PPC_SPE
);
5876 GEN_SPE(speundef
, evmhegsmfaa
, 0x15, 0x14, 0x00000000, PPC_SPE
);
5877 GEN_SPE(evmhogumiaa
, evmhogsmiaa
, 0x16, 0x14, 0x00000000, PPC_SPE
);
5878 GEN_SPE(speundef
, evmhogsmfaa
, 0x17, 0x14, 0x00000000, PPC_SPE
);
5880 GEN_SPE(evmwlusiaaw
, evmwlssiaaw
, 0x00, 0x15, 0x00000000, PPC_SPE
);
5881 GEN_SPE(evmwlumiaaw
, evmwlsmiaaw
, 0x04, 0x15, 0x00000000, PPC_SPE
);
5882 GEN_SPE(speundef
, evmwssfaa
, 0x09, 0x15, 0x00000000, PPC_SPE
);
5883 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, PPC_SPE
);
5884 GEN_SPE(speundef
, evmwsmfaa
, 0x0D, 0x15, 0x00000000, PPC_SPE
);
5886 GEN_SPE(evmheusianw
, evmhessianw
, 0x00, 0x16, 0x00000000, PPC_SPE
);
5887 GEN_SPE(speundef
, evmhessfanw
, 0x01, 0x16, 0x00000000, PPC_SPE
);
5888 GEN_SPE(evmhousianw
, evmhossianw
, 0x02, 0x16, 0x00000000, PPC_SPE
);
5889 GEN_SPE(speundef
, evmhossfanw
, 0x03, 0x16, 0x00000000, PPC_SPE
);
5890 GEN_SPE(evmheumianw
, evmhesmianw
, 0x04, 0x16, 0x00000000, PPC_SPE
);
5891 GEN_SPE(speundef
, evmhesmfanw
, 0x05, 0x16, 0x00000000, PPC_SPE
);
5892 GEN_SPE(evmhoumianw
, evmhosmianw
, 0x06, 0x16, 0x00000000, PPC_SPE
);
5893 GEN_SPE(speundef
, evmhosmfanw
, 0x07, 0x16, 0x00000000, PPC_SPE
);
5894 GEN_SPE(evmhegumian
, evmhegsmian
, 0x14, 0x16, 0x00000000, PPC_SPE
);
5895 GEN_SPE(speundef
, evmhegsmfan
, 0x15, 0x16, 0x00000000, PPC_SPE
);
5896 GEN_SPE(evmhigumian
, evmhigsmian
, 0x16, 0x16, 0x00000000, PPC_SPE
);
5897 GEN_SPE(speundef
, evmhogsmfan
, 0x17, 0x16, 0x00000000, PPC_SPE
);
5899 GEN_SPE(evmwlusianw
, evmwlssianw
, 0x00, 0x17, 0x00000000, PPC_SPE
);
5900 GEN_SPE(evmwlumianw
, evmwlsmianw
, 0x04, 0x17, 0x00000000, PPC_SPE
);
5901 GEN_SPE(speundef
, evmwssfan
, 0x09, 0x17, 0x00000000, PPC_SPE
);
5902 GEN_SPE(evmwumian
, evmwsmian
, 0x0C, 0x17, 0x00000000, PPC_SPE
);
5903 GEN_SPE(speundef
, evmwsmfan
, 0x0D, 0x17, 0x00000000, PPC_SPE
);
5906 /*** SPE floating-point extension ***/
5907 #define GEN_SPEFPUOP_CONV(name) \
5908 static always_inline void gen_##name (DisasContext *ctx) \
5910 gen_op_load_gpr64_T0(rB(ctx->opcode)); \
5912 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5915 /* Single precision floating-point vectors operations */
5917 GEN_SPEOP_ARITH2(evfsadd
);
5918 GEN_SPEOP_ARITH2(evfssub
);
5919 GEN_SPEOP_ARITH2(evfsmul
);
5920 GEN_SPEOP_ARITH2(evfsdiv
);
5921 GEN_SPEOP_ARITH1(evfsabs
);
5922 GEN_SPEOP_ARITH1(evfsnabs
);
5923 GEN_SPEOP_ARITH1(evfsneg
);
5925 GEN_SPEFPUOP_CONV(evfscfui
);
5926 GEN_SPEFPUOP_CONV(evfscfsi
);
5927 GEN_SPEFPUOP_CONV(evfscfuf
);
5928 GEN_SPEFPUOP_CONV(evfscfsf
);
5929 GEN_SPEFPUOP_CONV(evfsctui
);
5930 GEN_SPEFPUOP_CONV(evfsctsi
);
5931 GEN_SPEFPUOP_CONV(evfsctuf
);
5932 GEN_SPEFPUOP_CONV(evfsctsf
);
5933 GEN_SPEFPUOP_CONV(evfsctuiz
);
5934 GEN_SPEFPUOP_CONV(evfsctsiz
);
5936 GEN_SPEOP_COMP(evfscmpgt
);
5937 GEN_SPEOP_COMP(evfscmplt
);
5938 GEN_SPEOP_COMP(evfscmpeq
);
5939 GEN_SPEOP_COMP(evfststgt
);
5940 GEN_SPEOP_COMP(evfststlt
);
5941 GEN_SPEOP_COMP(evfststeq
);
5943 /* Opcodes definitions */
5944 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, PPC_SPEFPU
); //
5945 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, PPC_SPEFPU
); //
5946 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, PPC_SPEFPU
); //
5947 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, PPC_SPEFPU
); //
5948 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, PPC_SPEFPU
); //
5949 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, PPC_SPEFPU
); //
5950 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, PPC_SPEFPU
); //
5951 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, PPC_SPEFPU
); //
5952 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, PPC_SPEFPU
); //
5953 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, PPC_SPEFPU
); //
5954 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, PPC_SPEFPU
); //
5955 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, PPC_SPEFPU
); //
5956 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, PPC_SPEFPU
); //
5957 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, PPC_SPEFPU
); //
5959 /* Single precision floating-point operations */
5961 GEN_SPEOP_ARITH2(efsadd
);
5962 GEN_SPEOP_ARITH2(efssub
);
5963 GEN_SPEOP_ARITH2(efsmul
);
5964 GEN_SPEOP_ARITH2(efsdiv
);
5965 GEN_SPEOP_ARITH1(efsabs
);
5966 GEN_SPEOP_ARITH1(efsnabs
);
5967 GEN_SPEOP_ARITH1(efsneg
);
5969 GEN_SPEFPUOP_CONV(efscfui
);
5970 GEN_SPEFPUOP_CONV(efscfsi
);
5971 GEN_SPEFPUOP_CONV(efscfuf
);
5972 GEN_SPEFPUOP_CONV(efscfsf
);
5973 GEN_SPEFPUOP_CONV(efsctui
);
5974 GEN_SPEFPUOP_CONV(efsctsi
);
5975 GEN_SPEFPUOP_CONV(efsctuf
);
5976 GEN_SPEFPUOP_CONV(efsctsf
);
5977 GEN_SPEFPUOP_CONV(efsctuiz
);
5978 GEN_SPEFPUOP_CONV(efsctsiz
);
5979 GEN_SPEFPUOP_CONV(efscfd
);
5981 GEN_SPEOP_COMP(efscmpgt
);
5982 GEN_SPEOP_COMP(efscmplt
);
5983 GEN_SPEOP_COMP(efscmpeq
);
5984 GEN_SPEOP_COMP(efststgt
);
5985 GEN_SPEOP_COMP(efststlt
);
5986 GEN_SPEOP_COMP(efststeq
);
5988 /* Opcodes definitions */
5989 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, PPC_SPEFPU
); //
5990 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, PPC_SPEFPU
); //
5991 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, PPC_SPEFPU
); //
5992 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, PPC_SPEFPU
); //
5993 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, PPC_SPEFPU
); //
5994 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, PPC_SPEFPU
); //
5995 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, PPC_SPEFPU
); //
5996 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, PPC_SPEFPU
); //
5997 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, PPC_SPEFPU
); //
5998 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, PPC_SPEFPU
); //
5999 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, PPC_SPEFPU
); //
6000 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, PPC_SPEFPU
); //
6001 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, PPC_SPEFPU
); //
6002 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, PPC_SPEFPU
); //
6004 /* Double precision floating-point operations */
6006 GEN_SPEOP_ARITH2(efdadd
);
6007 GEN_SPEOP_ARITH2(efdsub
);
6008 GEN_SPEOP_ARITH2(efdmul
);
6009 GEN_SPEOP_ARITH2(efddiv
);
6010 GEN_SPEOP_ARITH1(efdabs
);
6011 GEN_SPEOP_ARITH1(efdnabs
);
6012 GEN_SPEOP_ARITH1(efdneg
);
6015 GEN_SPEFPUOP_CONV(efdcfui
);
6016 GEN_SPEFPUOP_CONV(efdcfsi
);
6017 GEN_SPEFPUOP_CONV(efdcfuf
);
6018 GEN_SPEFPUOP_CONV(efdcfsf
);
6019 GEN_SPEFPUOP_CONV(efdctui
);
6020 GEN_SPEFPUOP_CONV(efdctsi
);
6021 GEN_SPEFPUOP_CONV(efdctuf
);
6022 GEN_SPEFPUOP_CONV(efdctsf
);
6023 GEN_SPEFPUOP_CONV(efdctuiz
);
6024 GEN_SPEFPUOP_CONV(efdctsiz
);
6025 GEN_SPEFPUOP_CONV(efdcfs
);
6026 GEN_SPEFPUOP_CONV(efdcfuid
);
6027 GEN_SPEFPUOP_CONV(efdcfsid
);
6028 GEN_SPEFPUOP_CONV(efdctuidz
);
6029 GEN_SPEFPUOP_CONV(efdctsidz
);
6031 GEN_SPEOP_COMP(efdcmpgt
);
6032 GEN_SPEOP_COMP(efdcmplt
);
6033 GEN_SPEOP_COMP(efdcmpeq
);
6034 GEN_SPEOP_COMP(efdtstgt
);
6035 GEN_SPEOP_COMP(efdtstlt
);
6036 GEN_SPEOP_COMP(efdtsteq
);
6038 /* Opcodes definitions */
6039 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, PPC_SPEFPU
); //
6040 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, PPC_SPEFPU
); //
6041 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, PPC_SPEFPU
); //
6042 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, PPC_SPEFPU
); //
6043 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, PPC_SPEFPU
); //
6044 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, PPC_SPEFPU
); //
6045 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, PPC_SPEFPU
); //
6046 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, PPC_SPEFPU
); //
6047 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, PPC_SPEFPU
); //
6048 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, PPC_SPEFPU
); //
6049 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, PPC_SPEFPU
); //
6050 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, PPC_SPEFPU
); //
6051 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, PPC_SPEFPU
); //
6052 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, PPC_SPEFPU
); //
6053 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, PPC_SPEFPU
); //
6054 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, PPC_SPEFPU
); //
6056 /* End opcode list */
6057 GEN_OPCODE_MARK(end
);
6059 #include "translate_init.c"
6060 #include "helper_regs.h"
6062 /*****************************************************************************/
6063 /* Misc PowerPC helpers */
6064 void cpu_dump_state (CPUState
*env
, FILE *f
,
6065 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6073 cpu_fprintf(f
, "NIP " ADDRX
" LR " ADDRX
" CTR " ADDRX
" XER %08x\n",
6074 env
->nip
, env
->lr
, env
->ctr
, hreg_load_xer(env
));
6075 cpu_fprintf(f
, "MSR " ADDRX
" HID0 " ADDRX
" HF " ADDRX
" idx %d\n",
6076 env
->msr
, env
->spr
[SPR_HID0
], env
->hflags
, env
->mmu_idx
);
6077 #if !defined(NO_TIMER_DUMP)
6078 cpu_fprintf(f
, "TB %08x %08x "
6079 #if !defined(CONFIG_USER_ONLY)
6083 cpu_ppc_load_tbu(env
), cpu_ppc_load_tbl(env
)
6084 #if !defined(CONFIG_USER_ONLY)
6085 , cpu_ppc_load_decr(env
)
6089 for (i
= 0; i
< 32; i
++) {
6090 if ((i
& (RGPL
- 1)) == 0)
6091 cpu_fprintf(f
, "GPR%02d", i
);
6092 cpu_fprintf(f
, " " REGX
, ppc_dump_gpr(env
, i
));
6093 if ((i
& (RGPL
- 1)) == (RGPL
- 1))
6094 cpu_fprintf(f
, "\n");
6096 cpu_fprintf(f
, "CR ");
6097 for (i
= 0; i
< 8; i
++)
6098 cpu_fprintf(f
, "%01x", env
->crf
[i
]);
6099 cpu_fprintf(f
, " [");
6100 for (i
= 0; i
< 8; i
++) {
6102 if (env
->crf
[i
] & 0x08)
6104 else if (env
->crf
[i
] & 0x04)
6106 else if (env
->crf
[i
] & 0x02)
6108 cpu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
6110 cpu_fprintf(f
, " ] RES " ADDRX
"\n", env
->reserve
);
6111 for (i
= 0; i
< 32; i
++) {
6112 if ((i
& (RFPL
- 1)) == 0)
6113 cpu_fprintf(f
, "FPR%02d", i
);
6114 cpu_fprintf(f
, " %016" PRIx64
, *((uint64_t *)&env
->fpr
[i
]));
6115 if ((i
& (RFPL
- 1)) == (RFPL
- 1))
6116 cpu_fprintf(f
, "\n");
6118 #if !defined(CONFIG_USER_ONLY)
6119 cpu_fprintf(f
, "SRR0 " ADDRX
" SRR1 " ADDRX
" SDR1 " ADDRX
"\n",
6120 env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
], env
->sdr1
);
6127 void cpu_dump_statistics (CPUState
*env
, FILE*f
,
6128 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6131 #if defined(DO_PPC_STATISTICS)
6132 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
6136 for (op1
= 0; op1
< 64; op1
++) {
6138 if (is_indirect_opcode(handler
)) {
6139 t2
= ind_table(handler
);
6140 for (op2
= 0; op2
< 32; op2
++) {
6142 if (is_indirect_opcode(handler
)) {
6143 t3
= ind_table(handler
);
6144 for (op3
= 0; op3
< 32; op3
++) {
6146 if (handler
->count
== 0)
6148 cpu_fprintf(f
, "%02x %02x %02x (%02x %04d) %16s: "
6150 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
6152 handler
->count
, handler
->count
);
6155 if (handler
->count
== 0)
6157 cpu_fprintf(f
, "%02x %02x (%02x %04d) %16s: "
6159 op1
, op2
, op1
, op2
, handler
->oname
,
6160 handler
->count
, handler
->count
);
6164 if (handler
->count
== 0)
6166 cpu_fprintf(f
, "%02x (%02x ) %16s: %016llx %lld\n",
6167 op1
, op1
, handler
->oname
,
6168 handler
->count
, handler
->count
);
6174 /*****************************************************************************/
6175 static always_inline
void gen_intermediate_code_internal (CPUState
*env
,
6176 TranslationBlock
*tb
,
6179 DisasContext ctx
, *ctxp
= &ctx
;
6180 opc_handler_t
**table
, *handler
;
6181 target_ulong pc_start
;
6182 uint16_t *gen_opc_end
;
6183 int supervisor
, little_endian
;
6189 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
6190 #if defined(OPTIMIZE_FPRF_UPDATE)
6191 gen_fprf_ptr
= gen_fprf_buf
;
6195 ctx
.exception
= POWERPC_EXCP_NONE
;
6196 ctx
.spr_cb
= env
->spr_cb
;
6197 supervisor
= env
->mmu_idx
;
6198 #if !defined(CONFIG_USER_ONLY)
6199 ctx
.supervisor
= supervisor
;
6201 little_endian
= env
->hflags
& (1 << MSR_LE
) ? 1 : 0;
6202 #if defined(TARGET_PPC64)
6203 ctx
.sf_mode
= msr_sf
;
6204 ctx
.mem_idx
= (supervisor
<< 2) | (msr_sf
<< 1) | little_endian
;
6206 ctx
.mem_idx
= (supervisor
<< 1) | little_endian
;
6208 ctx
.dcache_line_size
= env
->dcache_line_size
;
6209 ctx
.fpu_enabled
= msr_fp
;
6210 if ((env
->flags
& POWERPC_FLAG_SPE
) && msr_spe
)
6211 ctx
.spe_enabled
= msr_spe
;
6213 ctx
.spe_enabled
= 0;
6214 if ((env
->flags
& POWERPC_FLAG_VRE
) && msr_vr
)
6215 ctx
.altivec_enabled
= msr_vr
;
6217 ctx
.altivec_enabled
= 0;
6218 if ((env
->flags
& POWERPC_FLAG_SE
) && msr_se
)
6219 ctx
.singlestep_enabled
= CPU_SINGLE_STEP
;
6221 ctx
.singlestep_enabled
= 0;
6222 if ((env
->flags
& POWERPC_FLAG_BE
) && msr_be
)
6223 ctx
.singlestep_enabled
|= CPU_BRANCH_STEP
;
6224 if (unlikely(env
->singlestep_enabled
))
6225 ctx
.singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
6226 #if defined (DO_SINGLE_STEP) && 0
6227 /* Single step trace mode */
6231 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
6233 max_insns
= CF_COUNT_MASK
;
6236 /* Set env in case of segfault during code fetch */
6237 while (ctx
.exception
== POWERPC_EXCP_NONE
&& gen_opc_ptr
< gen_opc_end
) {
6238 if (unlikely(env
->nb_breakpoints
> 0)) {
6239 for (j
= 0; j
< env
->nb_breakpoints
; j
++) {
6240 if (env
->breakpoints
[j
] == ctx
.nip
) {
6241 gen_update_nip(&ctx
, ctx
.nip
);
6247 if (unlikely(search_pc
)) {
6248 j
= gen_opc_ptr
- gen_opc_buf
;
6252 gen_opc_instr_start
[lj
++] = 0;
6253 gen_opc_pc
[lj
] = ctx
.nip
;
6254 gen_opc_instr_start
[lj
] = 1;
6255 gen_opc_icount
[lj
] = num_insns
;
6258 #if defined PPC_DEBUG_DISAS
6259 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
6260 fprintf(logfile
, "----------------\n");
6261 fprintf(logfile
, "nip=" ADDRX
" super=%d ir=%d\n",
6262 ctx
.nip
, supervisor
, (int)msr_ir
);
6265 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
6267 if (unlikely(little_endian
)) {
6268 ctx
.opcode
= bswap32(ldl_code(ctx
.nip
));
6270 ctx
.opcode
= ldl_code(ctx
.nip
);
6272 #if defined PPC_DEBUG_DISAS
6273 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
6274 fprintf(logfile
, "translate opcode %08x (%02x %02x %02x) (%s)\n",
6275 ctx
.opcode
, opc1(ctx
.opcode
), opc2(ctx
.opcode
),
6276 opc3(ctx
.opcode
), little_endian
? "little" : "big");
6280 table
= env
->opcodes
;
6282 handler
= table
[opc1(ctx
.opcode
)];
6283 if (is_indirect_opcode(handler
)) {
6284 table
= ind_table(handler
);
6285 handler
= table
[opc2(ctx
.opcode
)];
6286 if (is_indirect_opcode(handler
)) {
6287 table
= ind_table(handler
);
6288 handler
= table
[opc3(ctx
.opcode
)];
6291 /* Is opcode *REALLY* valid ? */
6292 if (unlikely(handler
->handler
== &gen_invalid
)) {
6293 if (loglevel
!= 0) {
6294 fprintf(logfile
, "invalid/unsupported opcode: "
6295 "%02x - %02x - %02x (%08x) " ADDRX
" %d\n",
6296 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
6297 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
6299 printf("invalid/unsupported opcode: "
6300 "%02x - %02x - %02x (%08x) " ADDRX
" %d\n",
6301 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
6302 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
6305 if (unlikely((ctx
.opcode
& handler
->inval
) != 0)) {
6306 if (loglevel
!= 0) {
6307 fprintf(logfile
, "invalid bits: %08x for opcode: "
6308 "%02x - %02x - %02x (%08x) " ADDRX
"\n",
6309 ctx
.opcode
& handler
->inval
, opc1(ctx
.opcode
),
6310 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
6311 ctx
.opcode
, ctx
.nip
- 4);
6313 printf("invalid bits: %08x for opcode: "
6314 "%02x - %02x - %02x (%08x) " ADDRX
"\n",
6315 ctx
.opcode
& handler
->inval
, opc1(ctx
.opcode
),
6316 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
6317 ctx
.opcode
, ctx
.nip
- 4);
6319 GEN_EXCP_INVAL(ctxp
);
6323 (*(handler
->handler
))(&ctx
);
6324 #if defined(DO_PPC_STATISTICS)
6327 /* Check trace mode exceptions */
6328 if (unlikely(ctx
.singlestep_enabled
& CPU_SINGLE_STEP
&&
6329 (ctx
.nip
<= 0x100 || ctx
.nip
> 0xF00) &&
6330 ctx
.exception
!= POWERPC_SYSCALL
&&
6331 ctx
.exception
!= POWERPC_EXCP_TRAP
&&
6332 ctx
.exception
!= POWERPC_EXCP_BRANCH
)) {
6333 GEN_EXCP(ctxp
, POWERPC_EXCP_TRACE
, 0);
6334 } else if (unlikely(((ctx
.nip
& (TARGET_PAGE_SIZE
- 1)) == 0) ||
6335 (env
->singlestep_enabled
) ||
6336 num_insns
>= max_insns
)) {
6337 /* if we reach a page boundary or are single stepping, stop
6342 #if defined (DO_SINGLE_STEP)
6346 if (tb
->cflags
& CF_LAST_IO
)
6348 if (ctx
.exception
== POWERPC_EXCP_NONE
) {
6349 gen_goto_tb(&ctx
, 0, ctx
.nip
);
6350 } else if (ctx
.exception
!= POWERPC_EXCP_BRANCH
) {
6351 if (unlikely(env
->singlestep_enabled
)) {
6352 gen_update_nip(&ctx
, ctx
.nip
);
6355 /* Generate the return instruction */
6358 gen_icount_end(tb
, num_insns
);
6359 *gen_opc_ptr
= INDEX_op_end
;
6360 if (unlikely(search_pc
)) {
6361 j
= gen_opc_ptr
- gen_opc_buf
;
6364 gen_opc_instr_start
[lj
++] = 0;
6366 tb
->size
= ctx
.nip
- pc_start
;
6367 tb
->icount
= num_insns
;
6369 #if defined(DEBUG_DISAS)
6370 if (loglevel
& CPU_LOG_TB_CPU
) {
6371 fprintf(logfile
, "---------------- excp: %04x\n", ctx
.exception
);
6372 cpu_dump_state(env
, logfile
, fprintf
, 0);
6374 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
6376 flags
= env
->bfd_mach
;
6377 flags
|= little_endian
<< 16;
6378 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
6379 target_disas(logfile
, pc_start
, ctx
.nip
- pc_start
, flags
);
6380 fprintf(logfile
, "\n");
6385 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
6387 gen_intermediate_code_internal(env
, tb
, 0);
6390 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
6392 gen_intermediate_code_internal(env
, tb
, 1);
6395 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
6396 unsigned long searched_pc
, int pc_pos
, void *puc
)
6399 /* for PPC, we need to look at the micro operation to get the
6401 env
->nip
= gen_opc_pc
[pc_pos
];
6402 c
= gen_opc_buf
[pc_pos
];
6404 #if defined(CONFIG_USER_ONLY)
6406 case INDEX_op_ ## op ## _raw
6409 case INDEX_op_ ## op ## _user:\
6410 case INDEX_op_ ## op ## _kernel:\
6411 case INDEX_op_ ## op ## _hypv
6418 type
= ACCESS_FLOAT
;
6434 env
->access_type
= type
;