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
31 #include "qemu-common.h"
33 #define CPU_SINGLE_STEP 0x1
34 #define CPU_BRANCH_STEP 0x2
35 #define GDBSTUB_SINGLE_STEP 0x4
37 /* Include definitions for instructions classes and implementations flags */
38 //#define DO_SINGLE_STEP
39 //#define PPC_DEBUG_DISAS
40 //#define DEBUG_MEMORY_ACCESSES
41 //#define DO_PPC_STATISTICS
42 //#define OPTIMIZE_FPRF_UPDATE
44 /*****************************************************************************/
45 /* Code translation helpers */
47 static TCGv cpu_env
, cpu_T
[3];
49 #include "gen-icount.h"
51 void ppc_translate_init(void)
53 static int done_init
= 0;
56 cpu_env
= tcg_global_reg_new(TCG_TYPE_PTR
, TCG_AREG0
, "env");
57 #if TARGET_LONG_BITS > HOST_LONG_BITS
58 cpu_T
[0] = tcg_global_mem_new(TCG_TYPE_TL
,
59 TCG_AREG0
, offsetof(CPUState
, t0
), "T0");
60 cpu_T
[1] = tcg_global_mem_new(TCG_TYPE_TL
,
61 TCG_AREG0
, offsetof(CPUState
, t1
), "T1");
62 cpu_T
[2] = tcg_global_mem_new(TCG_TYPE_TL
,
63 TCG_AREG0
, offsetof(CPUState
, t2
), "T2");
65 cpu_T
[0] = tcg_global_reg_new(TCG_TYPE_TL
, TCG_AREG1
, "T0");
66 cpu_T
[1] = tcg_global_reg_new(TCG_TYPE_TL
, TCG_AREG2
, "T1");
67 cpu_T
[2] = tcg_global_reg_new(TCG_TYPE_TL
, TCG_AREG3
, "T2");
70 /* register helpers */
72 #define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
78 #if defined(OPTIMIZE_FPRF_UPDATE)
79 static uint16_t *gen_fprf_buf
[OPC_BUF_SIZE
];
80 static uint16_t **gen_fprf_ptr
;
83 static always_inline
void gen_set_T0 (target_ulong val
)
85 #if defined(TARGET_PPC64)
87 gen_op_set_T0_64(val
>> 32, val
);
93 static always_inline
void gen_set_T1 (target_ulong val
)
95 #if defined(TARGET_PPC64)
97 gen_op_set_T1_64(val
>> 32, val
);
103 #define GEN8(func, NAME) \
104 static GenOpFunc *NAME ## _table [8] = { \
105 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
106 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
108 static always_inline void func (int n) \
110 NAME ## _table[n](); \
113 #define GEN16(func, NAME) \
114 static GenOpFunc *NAME ## _table [16] = { \
115 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
116 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
117 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
118 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
120 static always_inline void func (int n) \
122 NAME ## _table[n](); \
125 #define GEN32(func, NAME) \
126 static GenOpFunc *NAME ## _table [32] = { \
127 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
128 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
129 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
130 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
131 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
132 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
133 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
134 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
136 static always_inline void func (int n) \
138 NAME ## _table[n](); \
141 /* Condition register moves */
142 GEN8(gen_op_load_crf_T0
, gen_op_load_crf_T0_crf
);
143 GEN8(gen_op_load_crf_T1
, gen_op_load_crf_T1_crf
);
144 GEN8(gen_op_store_T0_crf
, gen_op_store_T0_crf_crf
);
146 GEN8(gen_op_store_T1_crf
, gen_op_store_T1_crf_crf
);
149 /* General purpose registers moves */
150 GEN32(gen_op_load_gpr_T0
, gen_op_load_gpr_T0_gpr
);
151 GEN32(gen_op_load_gpr_T1
, gen_op_load_gpr_T1_gpr
);
152 GEN32(gen_op_load_gpr_T2
, gen_op_load_gpr_T2_gpr
);
154 GEN32(gen_op_store_T0_gpr
, gen_op_store_T0_gpr_gpr
);
155 GEN32(gen_op_store_T1_gpr
, gen_op_store_T1_gpr_gpr
);
157 GEN32(gen_op_store_T2_gpr
, gen_op_store_T2_gpr_gpr
);
160 /* floating point registers moves */
161 GEN32(gen_op_load_fpr_FT0
, gen_op_load_fpr_FT0_fpr
);
162 GEN32(gen_op_load_fpr_FT1
, gen_op_load_fpr_FT1_fpr
);
163 GEN32(gen_op_load_fpr_FT2
, gen_op_load_fpr_FT2_fpr
);
164 GEN32(gen_op_store_FT0_fpr
, gen_op_store_FT0_fpr_fpr
);
165 GEN32(gen_op_store_FT1_fpr
, gen_op_store_FT1_fpr_fpr
);
167 GEN32(gen_op_store_FT2_fpr
, gen_op_store_FT2_fpr_fpr
);
170 /* internal defines */
171 typedef struct DisasContext
{
172 struct TranslationBlock
*tb
;
176 /* Routine used to access memory */
178 /* Translation flags */
179 #if !defined(CONFIG_USER_ONLY)
182 #if defined(TARGET_PPC64)
188 ppc_spr_t
*spr_cb
; /* Needed to check rights for mfspr/mtspr */
189 int singlestep_enabled
;
190 int dcache_line_size
;
193 struct opc_handler_t
{
196 /* instruction type */
199 void (*handler
)(DisasContext
*ctx
);
200 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
201 const unsigned char *oname
;
203 #if defined(DO_PPC_STATISTICS)
208 static always_inline
void gen_set_Rc0 (DisasContext
*ctx
)
210 #if defined(TARGET_PPC64)
219 static always_inline
void gen_reset_fpstatus (void)
221 #ifdef CONFIG_SOFTFLOAT
222 gen_op_reset_fpstatus();
226 static always_inline
void gen_compute_fprf (int set_fprf
, int set_rc
)
229 /* This case might be optimized later */
230 #if defined(OPTIMIZE_FPRF_UPDATE)
231 *gen_fprf_ptr
++ = gen_opc_ptr
;
233 gen_op_compute_fprf(1);
234 if (unlikely(set_rc
))
235 gen_op_store_T0_crf(1);
236 gen_op_float_check_status();
237 } else if (unlikely(set_rc
)) {
238 /* We always need to compute fpcc */
239 gen_op_compute_fprf(0);
240 gen_op_store_T0_crf(1);
242 gen_op_float_check_status();
246 static always_inline
void gen_optimize_fprf (void)
248 #if defined(OPTIMIZE_FPRF_UPDATE)
251 for (ptr
= gen_fprf_buf
; ptr
!= (gen_fprf_ptr
- 1); ptr
++)
252 *ptr
= INDEX_op_nop1
;
253 gen_fprf_ptr
= gen_fprf_buf
;
257 static always_inline
void gen_update_nip (DisasContext
*ctx
, target_ulong nip
)
259 #if defined(TARGET_PPC64)
261 gen_op_update_nip_64(nip
>> 32, nip
);
264 gen_op_update_nip(nip
);
267 #define GEN_EXCP(ctx, excp, error) \
269 if ((ctx)->exception == POWERPC_EXCP_NONE) { \
270 gen_update_nip(ctx, (ctx)->nip); \
272 gen_op_raise_exception_err((excp), (error)); \
273 ctx->exception = (excp); \
276 #define GEN_EXCP_INVAL(ctx) \
277 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
278 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_INVAL)
280 #define GEN_EXCP_PRIVOPC(ctx) \
281 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
282 POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_OPC)
284 #define GEN_EXCP_PRIVREG(ctx) \
285 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
286 POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_REG)
288 #define GEN_EXCP_NO_FP(ctx) \
289 GEN_EXCP(ctx, POWERPC_EXCP_FPU, 0)
291 #define GEN_EXCP_NO_AP(ctx) \
292 GEN_EXCP(ctx, POWERPC_EXCP_APU, 0)
294 #define GEN_EXCP_NO_VR(ctx) \
295 GEN_EXCP(ctx, POWERPC_EXCP_VPU, 0)
297 /* Stop translation */
298 static always_inline
void GEN_STOP (DisasContext
*ctx
)
300 gen_update_nip(ctx
, ctx
->nip
);
301 ctx
->exception
= POWERPC_EXCP_STOP
;
304 /* No need to update nip here, as execution flow will change */
305 static always_inline
void GEN_SYNC (DisasContext
*ctx
)
307 ctx
->exception
= POWERPC_EXCP_SYNC
;
310 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
311 static void gen_##name (DisasContext *ctx); \
312 GEN_OPCODE(name, opc1, opc2, opc3, inval, type); \
313 static void gen_##name (DisasContext *ctx)
315 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
316 static void gen_##name (DisasContext *ctx); \
317 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type); \
318 static void gen_##name (DisasContext *ctx)
320 typedef struct opcode_t
{
321 unsigned char opc1
, opc2
, opc3
;
322 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
323 unsigned char pad
[5];
325 unsigned char pad
[1];
327 opc_handler_t handler
;
328 const unsigned char *oname
;
331 /*****************************************************************************/
332 /*** Instruction decoding ***/
333 #define EXTRACT_HELPER(name, shift, nb) \
334 static always_inline uint32_t name (uint32_t opcode) \
336 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
339 #define EXTRACT_SHELPER(name, shift, nb) \
340 static always_inline int32_t name (uint32_t opcode) \
342 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
346 EXTRACT_HELPER(opc1
, 26, 6);
348 EXTRACT_HELPER(opc2
, 1, 5);
350 EXTRACT_HELPER(opc3
, 6, 5);
351 /* Update Cr0 flags */
352 EXTRACT_HELPER(Rc
, 0, 1);
354 EXTRACT_HELPER(rD
, 21, 5);
356 EXTRACT_HELPER(rS
, 21, 5);
358 EXTRACT_HELPER(rA
, 16, 5);
360 EXTRACT_HELPER(rB
, 11, 5);
362 EXTRACT_HELPER(rC
, 6, 5);
364 EXTRACT_HELPER(crfD
, 23, 3);
365 EXTRACT_HELPER(crfS
, 18, 3);
366 EXTRACT_HELPER(crbD
, 21, 5);
367 EXTRACT_HELPER(crbA
, 16, 5);
368 EXTRACT_HELPER(crbB
, 11, 5);
370 EXTRACT_HELPER(_SPR
, 11, 10);
371 static always_inline
uint32_t SPR (uint32_t opcode
)
373 uint32_t sprn
= _SPR(opcode
);
375 return ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
377 /*** Get constants ***/
378 EXTRACT_HELPER(IMM
, 12, 8);
379 /* 16 bits signed immediate value */
380 EXTRACT_SHELPER(SIMM
, 0, 16);
381 /* 16 bits unsigned immediate value */
382 EXTRACT_HELPER(UIMM
, 0, 16);
384 EXTRACT_HELPER(NB
, 11, 5);
386 EXTRACT_HELPER(SH
, 11, 5);
388 EXTRACT_HELPER(MB
, 6, 5);
390 EXTRACT_HELPER(ME
, 1, 5);
392 EXTRACT_HELPER(TO
, 21, 5);
394 EXTRACT_HELPER(CRM
, 12, 8);
395 EXTRACT_HELPER(FM
, 17, 8);
396 EXTRACT_HELPER(SR
, 16, 4);
397 EXTRACT_HELPER(FPIMM
, 12, 4);
399 /*** Jump target decoding ***/
401 EXTRACT_SHELPER(d
, 0, 16);
402 /* Immediate address */
403 static always_inline target_ulong
LI (uint32_t opcode
)
405 return (opcode
>> 0) & 0x03FFFFFC;
408 static always_inline
uint32_t BD (uint32_t opcode
)
410 return (opcode
>> 0) & 0xFFFC;
413 EXTRACT_HELPER(BO
, 21, 5);
414 EXTRACT_HELPER(BI
, 16, 5);
415 /* Absolute/relative address */
416 EXTRACT_HELPER(AA
, 1, 1);
418 EXTRACT_HELPER(LK
, 0, 1);
420 /* Create a mask between <start> and <end> bits */
421 static always_inline target_ulong
MASK (uint32_t start
, uint32_t end
)
425 #if defined(TARGET_PPC64)
426 if (likely(start
== 0)) {
427 ret
= UINT64_MAX
<< (63 - end
);
428 } else if (likely(end
== 63)) {
429 ret
= UINT64_MAX
>> start
;
432 if (likely(start
== 0)) {
433 ret
= UINT32_MAX
<< (31 - end
);
434 } else if (likely(end
== 31)) {
435 ret
= UINT32_MAX
>> start
;
439 ret
= (((target_ulong
)(-1ULL)) >> (start
)) ^
440 (((target_ulong
)(-1ULL) >> (end
)) >> 1);
441 if (unlikely(start
> end
))
448 /*****************************************************************************/
449 /* PowerPC Instructions types definitions */
451 PPC_NONE
= 0x0000000000000000ULL
,
452 /* PowerPC base instructions set */
453 PPC_INSNS_BASE
= 0x0000000000000001ULL
,
454 /* integer operations instructions */
455 #define PPC_INTEGER PPC_INSNS_BASE
456 /* flow control instructions */
457 #define PPC_FLOW PPC_INSNS_BASE
458 /* virtual memory instructions */
459 #define PPC_MEM PPC_INSNS_BASE
460 /* ld/st with reservation instructions */
461 #define PPC_RES PPC_INSNS_BASE
462 /* spr/msr access instructions */
463 #define PPC_MISC PPC_INSNS_BASE
464 /* Deprecated instruction sets */
465 /* Original POWER instruction set */
466 PPC_POWER
= 0x0000000000000002ULL
,
467 /* POWER2 instruction set extension */
468 PPC_POWER2
= 0x0000000000000004ULL
,
469 /* Power RTC support */
470 PPC_POWER_RTC
= 0x0000000000000008ULL
,
471 /* Power-to-PowerPC bridge (601) */
472 PPC_POWER_BR
= 0x0000000000000010ULL
,
473 /* 64 bits PowerPC instruction set */
474 PPC_64B
= 0x0000000000000020ULL
,
475 /* New 64 bits extensions (PowerPC 2.0x) */
476 PPC_64BX
= 0x0000000000000040ULL
,
477 /* 64 bits hypervisor extensions */
478 PPC_64H
= 0x0000000000000080ULL
,
479 /* New wait instruction (PowerPC 2.0x) */
480 PPC_WAIT
= 0x0000000000000100ULL
,
481 /* Time base mftb instruction */
482 PPC_MFTB
= 0x0000000000000200ULL
,
484 /* Fixed-point unit extensions */
485 /* PowerPC 602 specific */
486 PPC_602_SPEC
= 0x0000000000000400ULL
,
487 /* isel instruction */
488 PPC_ISEL
= 0x0000000000000800ULL
,
489 /* popcntb instruction */
490 PPC_POPCNTB
= 0x0000000000001000ULL
,
491 /* string load / store */
492 PPC_STRING
= 0x0000000000002000ULL
,
494 /* Floating-point unit extensions */
495 /* Optional floating point instructions */
496 PPC_FLOAT
= 0x0000000000010000ULL
,
497 /* New floating-point extensions (PowerPC 2.0x) */
498 PPC_FLOAT_EXT
= 0x0000000000020000ULL
,
499 PPC_FLOAT_FSQRT
= 0x0000000000040000ULL
,
500 PPC_FLOAT_FRES
= 0x0000000000080000ULL
,
501 PPC_FLOAT_FRSQRTE
= 0x0000000000100000ULL
,
502 PPC_FLOAT_FRSQRTES
= 0x0000000000200000ULL
,
503 PPC_FLOAT_FSEL
= 0x0000000000400000ULL
,
504 PPC_FLOAT_STFIWX
= 0x0000000000800000ULL
,
506 /* Vector/SIMD extensions */
507 /* Altivec support */
508 PPC_ALTIVEC
= 0x0000000001000000ULL
,
509 /* PowerPC 2.03 SPE extension */
510 PPC_SPE
= 0x0000000002000000ULL
,
511 /* PowerPC 2.03 SPE floating-point extension */
512 PPC_SPEFPU
= 0x0000000004000000ULL
,
514 /* Optional memory control instructions */
515 PPC_MEM_TLBIA
= 0x0000000010000000ULL
,
516 PPC_MEM_TLBIE
= 0x0000000020000000ULL
,
517 PPC_MEM_TLBSYNC
= 0x0000000040000000ULL
,
518 /* sync instruction */
519 PPC_MEM_SYNC
= 0x0000000080000000ULL
,
520 /* eieio instruction */
521 PPC_MEM_EIEIO
= 0x0000000100000000ULL
,
523 /* Cache control instructions */
524 PPC_CACHE
= 0x0000000200000000ULL
,
525 /* icbi instruction */
526 PPC_CACHE_ICBI
= 0x0000000400000000ULL
,
527 /* dcbz instruction with fixed cache line size */
528 PPC_CACHE_DCBZ
= 0x0000000800000000ULL
,
529 /* dcbz instruction with tunable cache line size */
530 PPC_CACHE_DCBZT
= 0x0000001000000000ULL
,
531 /* dcba instruction */
532 PPC_CACHE_DCBA
= 0x0000002000000000ULL
,
533 /* Freescale cache locking instructions */
534 PPC_CACHE_LOCK
= 0x0000004000000000ULL
,
536 /* MMU related extensions */
537 /* external control instructions */
538 PPC_EXTERN
= 0x0000010000000000ULL
,
539 /* segment register access instructions */
540 PPC_SEGMENT
= 0x0000020000000000ULL
,
541 /* PowerPC 6xx TLB management instructions */
542 PPC_6xx_TLB
= 0x0000040000000000ULL
,
543 /* PowerPC 74xx TLB management instructions */
544 PPC_74xx_TLB
= 0x0000080000000000ULL
,
545 /* PowerPC 40x TLB management instructions */
546 PPC_40x_TLB
= 0x0000100000000000ULL
,
547 /* segment register access instructions for PowerPC 64 "bridge" */
548 PPC_SEGMENT_64B
= 0x0000200000000000ULL
,
550 PPC_SLBI
= 0x0000400000000000ULL
,
552 /* Embedded PowerPC dedicated instructions */
553 PPC_WRTEE
= 0x0001000000000000ULL
,
554 /* PowerPC 40x exception model */
555 PPC_40x_EXCP
= 0x0002000000000000ULL
,
556 /* PowerPC 405 Mac instructions */
557 PPC_405_MAC
= 0x0004000000000000ULL
,
558 /* PowerPC 440 specific instructions */
559 PPC_440_SPEC
= 0x0008000000000000ULL
,
560 /* BookE (embedded) PowerPC specification */
561 PPC_BOOKE
= 0x0010000000000000ULL
,
562 /* mfapidi instruction */
563 PPC_MFAPIDI
= 0x0020000000000000ULL
,
564 /* tlbiva instruction */
565 PPC_TLBIVA
= 0x0040000000000000ULL
,
566 /* tlbivax instruction */
567 PPC_TLBIVAX
= 0x0080000000000000ULL
,
568 /* PowerPC 4xx dedicated instructions */
569 PPC_4xx_COMMON
= 0x0100000000000000ULL
,
570 /* PowerPC 40x ibct instructions */
571 PPC_40x_ICBT
= 0x0200000000000000ULL
,
572 /* rfmci is not implemented in all BookE PowerPC */
573 PPC_RFMCI
= 0x0400000000000000ULL
,
574 /* rfdi instruction */
575 PPC_RFDI
= 0x0800000000000000ULL
,
577 PPC_DCR
= 0x1000000000000000ULL
,
578 /* DCR extended accesse */
579 PPC_DCRX
= 0x2000000000000000ULL
,
580 /* user-mode DCR access, implemented in PowerPC 460 */
581 PPC_DCRUX
= 0x4000000000000000ULL
,
584 /*****************************************************************************/
585 /* PowerPC instructions table */
586 #if HOST_LONG_BITS == 64
591 #if defined(__APPLE__)
592 #define OPCODES_SECTION \
593 __attribute__ ((section("__TEXT,__opcodes"), unused, aligned (OPC_ALIGN) ))
595 #define OPCODES_SECTION \
596 __attribute__ ((section(".opcodes"), unused, aligned (OPC_ALIGN) ))
599 #if defined(DO_PPC_STATISTICS)
600 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
601 OPCODES_SECTION opcode_t opc_##name = { \
609 .handler = &gen_##name, \
610 .oname = stringify(name), \
612 .oname = stringify(name), \
614 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
615 OPCODES_SECTION opcode_t opc_##name = { \
623 .handler = &gen_##name, \
629 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
630 OPCODES_SECTION opcode_t opc_##name = { \
638 .handler = &gen_##name, \
640 .oname = stringify(name), \
642 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
643 OPCODES_SECTION opcode_t opc_##name = { \
651 .handler = &gen_##name, \
657 #define GEN_OPCODE_MARK(name) \
658 OPCODES_SECTION opcode_t opc_##name = { \
664 .inval = 0x00000000, \
668 .oname = stringify(name), \
671 /* Start opcode list */
672 GEN_OPCODE_MARK(start
);
674 /* Invalid instruction */
675 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
)
680 static opc_handler_t invalid_handler
= {
683 .handler
= gen_invalid
,
686 /*** Integer arithmetic ***/
687 #define __GEN_INT_ARITH2(name, opc1, opc2, opc3, inval, type) \
688 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
690 gen_op_load_gpr_T0(rA(ctx->opcode)); \
691 gen_op_load_gpr_T1(rB(ctx->opcode)); \
693 gen_op_store_T0_gpr(rD(ctx->opcode)); \
694 if (unlikely(Rc(ctx->opcode) != 0)) \
698 #define __GEN_INT_ARITH2_O(name, opc1, opc2, opc3, inval, type) \
699 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
701 gen_op_load_gpr_T0(rA(ctx->opcode)); \
702 gen_op_load_gpr_T1(rB(ctx->opcode)); \
704 gen_op_store_T0_gpr(rD(ctx->opcode)); \
705 if (unlikely(Rc(ctx->opcode) != 0)) \
709 #define __GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
710 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
712 gen_op_load_gpr_T0(rA(ctx->opcode)); \
714 gen_op_store_T0_gpr(rD(ctx->opcode)); \
715 if (unlikely(Rc(ctx->opcode) != 0)) \
718 #define __GEN_INT_ARITH1_O(name, opc1, opc2, opc3, type) \
719 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
721 gen_op_load_gpr_T0(rA(ctx->opcode)); \
723 gen_op_store_T0_gpr(rD(ctx->opcode)); \
724 if (unlikely(Rc(ctx->opcode) != 0)) \
728 /* Two operands arithmetic functions */
729 #define GEN_INT_ARITH2(name, opc1, opc2, opc3, type) \
730 __GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000000, type) \
731 __GEN_INT_ARITH2_O(name##o, opc1, opc2, opc3 | 0x10, 0x00000000, type)
733 /* Two operands arithmetic functions with no overflow allowed */
734 #define GEN_INT_ARITHN(name, opc1, opc2, opc3, type) \
735 __GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000400, type)
737 /* One operand arithmetic functions */
738 #define GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
739 __GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
740 __GEN_INT_ARITH1_O(name##o, opc1, opc2, opc3 | 0x10, type)
742 #if defined(TARGET_PPC64)
743 #define __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, inval, type) \
744 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
746 gen_op_load_gpr_T0(rA(ctx->opcode)); \
747 gen_op_load_gpr_T1(rB(ctx->opcode)); \
749 gen_op_##name##_64(); \
752 gen_op_store_T0_gpr(rD(ctx->opcode)); \
753 if (unlikely(Rc(ctx->opcode) != 0)) \
757 #define __GEN_INT_ARITH2_O_64(name, opc1, opc2, opc3, inval, type) \
758 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
760 gen_op_load_gpr_T0(rA(ctx->opcode)); \
761 gen_op_load_gpr_T1(rB(ctx->opcode)); \
763 gen_op_##name##_64(); \
766 gen_op_store_T0_gpr(rD(ctx->opcode)); \
767 if (unlikely(Rc(ctx->opcode) != 0)) \
771 #define __GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
772 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
774 gen_op_load_gpr_T0(rA(ctx->opcode)); \
776 gen_op_##name##_64(); \
779 gen_op_store_T0_gpr(rD(ctx->opcode)); \
780 if (unlikely(Rc(ctx->opcode) != 0)) \
783 #define __GEN_INT_ARITH1_O_64(name, opc1, opc2, opc3, type) \
784 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
786 gen_op_load_gpr_T0(rA(ctx->opcode)); \
788 gen_op_##name##_64(); \
791 gen_op_store_T0_gpr(rD(ctx->opcode)); \
792 if (unlikely(Rc(ctx->opcode) != 0)) \
796 /* Two operands arithmetic functions */
797 #define GEN_INT_ARITH2_64(name, opc1, opc2, opc3, type) \
798 __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, 0x00000000, type) \
799 __GEN_INT_ARITH2_O_64(name##o, opc1, opc2, opc3 | 0x10, 0x00000000, type)
801 /* Two operands arithmetic functions with no overflow allowed */
802 #define GEN_INT_ARITHN_64(name, opc1, opc2, opc3, type) \
803 __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, 0x00000400, type)
805 /* One operand arithmetic functions */
806 #define GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
807 __GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
808 __GEN_INT_ARITH1_O_64(name##o, opc1, opc2, opc3 | 0x10, type)
810 #define GEN_INT_ARITH2_64 GEN_INT_ARITH2
811 #define GEN_INT_ARITHN_64 GEN_INT_ARITHN
812 #define GEN_INT_ARITH1_64 GEN_INT_ARITH1
815 /* add add. addo addo. */
816 static always_inline
void gen_op_addo (void)
822 #if defined(TARGET_PPC64)
823 #define gen_op_add_64 gen_op_add
824 static always_inline
void gen_op_addo_64 (void)
828 gen_op_check_addo_64();
831 GEN_INT_ARITH2_64 (add
, 0x1F, 0x0A, 0x08, PPC_INTEGER
);
832 /* addc addc. addco addco. */
833 static always_inline
void gen_op_addc (void)
839 static always_inline
void gen_op_addco (void)
846 #if defined(TARGET_PPC64)
847 static always_inline
void gen_op_addc_64 (void)
851 gen_op_check_addc_64();
853 static always_inline
void gen_op_addco_64 (void)
857 gen_op_check_addc_64();
858 gen_op_check_addo_64();
861 GEN_INT_ARITH2_64 (addc
, 0x1F, 0x0A, 0x00, PPC_INTEGER
);
862 /* adde adde. addeo addeo. */
863 static always_inline
void gen_op_addeo (void)
869 #if defined(TARGET_PPC64)
870 static always_inline
void gen_op_addeo_64 (void)
874 gen_op_check_addo_64();
877 GEN_INT_ARITH2_64 (adde
, 0x1F, 0x0A, 0x04, PPC_INTEGER
);
878 /* addme addme. addmeo addmeo. */
879 static always_inline
void gen_op_addme (void)
884 #if defined(TARGET_PPC64)
885 static always_inline
void gen_op_addme_64 (void)
891 GEN_INT_ARITH1_64 (addme
, 0x1F, 0x0A, 0x07, PPC_INTEGER
);
892 /* addze addze. addzeo addzeo. */
893 static always_inline
void gen_op_addze (void)
899 static always_inline
void gen_op_addzeo (void)
906 #if defined(TARGET_PPC64)
907 static always_inline
void gen_op_addze_64 (void)
911 gen_op_check_addc_64();
913 static always_inline
void gen_op_addzeo_64 (void)
917 gen_op_check_addc_64();
918 gen_op_check_addo_64();
921 GEN_INT_ARITH1_64 (addze
, 0x1F, 0x0A, 0x06, PPC_INTEGER
);
922 /* divw divw. divwo divwo. */
923 GEN_INT_ARITH2 (divw
, 0x1F, 0x0B, 0x0F, PPC_INTEGER
);
924 /* divwu divwu. divwuo divwuo. */
925 GEN_INT_ARITH2 (divwu
, 0x1F, 0x0B, 0x0E, PPC_INTEGER
);
927 GEN_INT_ARITHN (mulhw
, 0x1F, 0x0B, 0x02, PPC_INTEGER
);
929 GEN_INT_ARITHN (mulhwu
, 0x1F, 0x0B, 0x00, PPC_INTEGER
);
930 /* mullw mullw. mullwo mullwo. */
931 GEN_INT_ARITH2 (mullw
, 0x1F, 0x0B, 0x07, PPC_INTEGER
);
932 /* neg neg. nego nego. */
933 GEN_INT_ARITH1_64 (neg
, 0x1F, 0x08, 0x03, PPC_INTEGER
);
934 /* subf subf. subfo subfo. */
935 static always_inline
void gen_op_subfo (void)
937 gen_op_moven_T2_T0();
941 #if defined(TARGET_PPC64)
942 #define gen_op_subf_64 gen_op_subf
943 static always_inline
void gen_op_subfo_64 (void)
945 gen_op_moven_T2_T0();
947 gen_op_check_addo_64();
950 GEN_INT_ARITH2_64 (subf
, 0x1F, 0x08, 0x01, PPC_INTEGER
);
951 /* subfc subfc. subfco subfco. */
952 static always_inline
void gen_op_subfc (void)
955 gen_op_check_subfc();
957 static always_inline
void gen_op_subfco (void)
959 gen_op_moven_T2_T0();
961 gen_op_check_subfc();
964 #if defined(TARGET_PPC64)
965 static always_inline
void gen_op_subfc_64 (void)
968 gen_op_check_subfc_64();
970 static always_inline
void gen_op_subfco_64 (void)
972 gen_op_moven_T2_T0();
974 gen_op_check_subfc_64();
975 gen_op_check_addo_64();
978 GEN_INT_ARITH2_64 (subfc
, 0x1F, 0x08, 0x00, PPC_INTEGER
);
979 /* subfe subfe. subfeo subfeo. */
980 static always_inline
void gen_op_subfeo (void)
982 gen_op_moven_T2_T0();
986 #if defined(TARGET_PPC64)
987 #define gen_op_subfe_64 gen_op_subfe
988 static always_inline
void gen_op_subfeo_64 (void)
990 gen_op_moven_T2_T0();
992 gen_op_check_addo_64();
995 GEN_INT_ARITH2_64 (subfe
, 0x1F, 0x08, 0x04, PPC_INTEGER
);
996 /* subfme subfme. subfmeo subfmeo. */
997 GEN_INT_ARITH1_64 (subfme
, 0x1F, 0x08, 0x07, PPC_INTEGER
);
998 /* subfze subfze. subfzeo subfzeo. */
999 GEN_INT_ARITH1_64 (subfze
, 0x1F, 0x08, 0x06, PPC_INTEGER
);
1001 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1003 target_long simm
= SIMM(ctx
->opcode
);
1005 if (rA(ctx
->opcode
) == 0) {
1009 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1010 if (likely(simm
!= 0))
1013 gen_op_store_T0_gpr(rD(ctx
->opcode
));
1016 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1018 target_long simm
= SIMM(ctx
->opcode
);
1020 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1021 if (likely(simm
!= 0)) {
1022 gen_op_move_T2_T0();
1024 #if defined(TARGET_PPC64)
1026 gen_op_check_addc_64();
1029 gen_op_check_addc();
1031 gen_op_clear_xer_ca();
1033 gen_op_store_T0_gpr(rD(ctx
->opcode
));
1036 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1038 target_long simm
= SIMM(ctx
->opcode
);
1040 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1041 if (likely(simm
!= 0)) {
1042 gen_op_move_T2_T0();
1044 #if defined(TARGET_PPC64)
1046 gen_op_check_addc_64();
1049 gen_op_check_addc();
1051 gen_op_clear_xer_ca();
1053 gen_op_store_T0_gpr(rD(ctx
->opcode
));
1057 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1059 target_long simm
= SIMM(ctx
->opcode
);
1061 if (rA(ctx
->opcode
) == 0) {
1063 gen_set_T0(simm
<< 16);
1065 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1066 if (likely(simm
!= 0))
1067 gen_op_addi(simm
<< 16);
1069 gen_op_store_T0_gpr(rD(ctx
->opcode
));
1072 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1074 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1075 gen_op_mulli(SIMM(ctx
->opcode
));
1076 gen_op_store_T0_gpr(rD(ctx
->opcode
));
1079 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1081 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1082 #if defined(TARGET_PPC64)
1084 gen_op_subfic_64(SIMM(ctx
->opcode
));
1087 gen_op_subfic(SIMM(ctx
->opcode
));
1088 gen_op_store_T0_gpr(rD(ctx
->opcode
));
1091 #if defined(TARGET_PPC64)
1093 GEN_INT_ARITHN (mulhd
, 0x1F, 0x09, 0x02, PPC_64B
);
1094 /* mulhdu mulhdu. */
1095 GEN_INT_ARITHN (mulhdu
, 0x1F, 0x09, 0x00, PPC_64B
);
1096 /* mulld mulld. mulldo mulldo. */
1097 GEN_INT_ARITH2 (mulld
, 0x1F, 0x09, 0x07, PPC_64B
);
1098 /* divd divd. divdo divdo. */
1099 GEN_INT_ARITH2 (divd
, 0x1F, 0x09, 0x0F, PPC_64B
);
1100 /* divdu divdu. divduo divduo. */
1101 GEN_INT_ARITH2 (divdu
, 0x1F, 0x09, 0x0E, PPC_64B
);
1104 /*** Integer comparison ***/
1105 #if defined(TARGET_PPC64)
1106 #define GEN_CMP(name, opc, type) \
1107 GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, type) \
1109 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1110 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1111 if (ctx->sf_mode && (ctx->opcode & 0x00200000)) \
1112 gen_op_##name##_64(); \
1115 gen_op_store_T0_crf(crfD(ctx->opcode)); \
1118 #define GEN_CMP(name, opc, type) \
1119 GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, type) \
1121 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1122 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1124 gen_op_store_T0_crf(crfD(ctx->opcode)); \
1129 GEN_CMP(cmp
, 0x00, PPC_INTEGER
);
1131 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
)
1133 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1134 #if defined(TARGET_PPC64)
1135 if (ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000))
1136 gen_op_cmpi_64(SIMM(ctx
->opcode
));
1139 gen_op_cmpi(SIMM(ctx
->opcode
));
1140 gen_op_store_T0_crf(crfD(ctx
->opcode
));
1143 GEN_CMP(cmpl
, 0x01, PPC_INTEGER
);
1145 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
)
1147 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1148 #if defined(TARGET_PPC64)
1149 if (ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000))
1150 gen_op_cmpli_64(UIMM(ctx
->opcode
));
1153 gen_op_cmpli(UIMM(ctx
->opcode
));
1154 gen_op_store_T0_crf(crfD(ctx
->opcode
));
1157 /* isel (PowerPC 2.03 specification) */
1158 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
)
1160 uint32_t bi
= rC(ctx
->opcode
);
1163 if (rA(ctx
->opcode
) == 0) {
1166 gen_op_load_gpr_T1(rA(ctx
->opcode
));
1168 gen_op_load_gpr_T2(rB(ctx
->opcode
));
1169 mask
= 1 << (3 - (bi
& 0x03));
1170 gen_op_load_crf_T0(bi
>> 2);
1171 gen_op_test_true(mask
);
1173 gen_op_store_T0_gpr(rD(ctx
->opcode
));
1176 /*** Integer logical ***/
1177 #define __GEN_LOGICAL2(name, opc2, opc3, type) \
1178 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000000, type) \
1180 gen_op_load_gpr_T0(rS(ctx->opcode)); \
1181 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1183 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1184 if (unlikely(Rc(ctx->opcode) != 0)) \
1187 #define GEN_LOGICAL2(name, opc, type) \
1188 __GEN_LOGICAL2(name, 0x1C, opc, type)
1190 #define GEN_LOGICAL1(name, opc, type) \
1191 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type) \
1193 gen_op_load_gpr_T0(rS(ctx->opcode)); \
1195 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1196 if (unlikely(Rc(ctx->opcode) != 0)) \
1201 GEN_LOGICAL2(and, 0x00, PPC_INTEGER
);
1203 GEN_LOGICAL2(andc
, 0x01, PPC_INTEGER
);
1205 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1207 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1208 gen_op_andi_T0(UIMM(ctx
->opcode
));
1209 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1213 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1215 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1216 gen_op_andi_T0(UIMM(ctx
->opcode
) << 16);
1217 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1222 GEN_LOGICAL1(cntlzw
, 0x00, PPC_INTEGER
);
1224 GEN_LOGICAL2(eqv
, 0x08, PPC_INTEGER
);
1225 /* extsb & extsb. */
1226 GEN_LOGICAL1(extsb
, 0x1D, PPC_INTEGER
);
1227 /* extsh & extsh. */
1228 GEN_LOGICAL1(extsh
, 0x1C, PPC_INTEGER
);
1230 GEN_LOGICAL2(nand
, 0x0E, PPC_INTEGER
);
1232 GEN_LOGICAL2(nor
, 0x03, PPC_INTEGER
);
1235 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
)
1239 rs
= rS(ctx
->opcode
);
1240 ra
= rA(ctx
->opcode
);
1241 rb
= rB(ctx
->opcode
);
1242 /* Optimisation for mr. ri case */
1243 if (rs
!= ra
|| rs
!= rb
) {
1244 gen_op_load_gpr_T0(rs
);
1246 gen_op_load_gpr_T1(rb
);
1249 gen_op_store_T0_gpr(ra
);
1250 if (unlikely(Rc(ctx
->opcode
) != 0))
1252 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
1253 gen_op_load_gpr_T0(rs
);
1255 #if defined(TARGET_PPC64)
1259 /* Set process priority to low */
1260 gen_op_store_pri(2);
1263 /* Set process priority to medium-low */
1264 gen_op_store_pri(3);
1267 /* Set process priority to normal */
1268 gen_op_store_pri(4);
1270 #if !defined(CONFIG_USER_ONLY)
1272 if (ctx
->supervisor
> 0) {
1273 /* Set process priority to very low */
1274 gen_op_store_pri(1);
1278 if (ctx
->supervisor
> 0) {
1279 /* Set process priority to medium-hight */
1280 gen_op_store_pri(5);
1284 if (ctx
->supervisor
> 0) {
1285 /* Set process priority to high */
1286 gen_op_store_pri(6);
1290 if (ctx
->supervisor
> 1) {
1291 /* Set process priority to very high */
1292 gen_op_store_pri(7);
1305 GEN_LOGICAL2(orc
, 0x0C, PPC_INTEGER
);
1307 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
)
1309 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1310 /* Optimisation for "set to zero" case */
1311 if (rS(ctx
->opcode
) != rB(ctx
->opcode
)) {
1312 gen_op_load_gpr_T1(rB(ctx
->opcode
));
1317 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1318 if (unlikely(Rc(ctx
->opcode
) != 0))
1322 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1324 target_ulong uimm
= UIMM(ctx
->opcode
);
1326 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1328 /* XXX: should handle special NOPs for POWER series */
1331 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1332 if (likely(uimm
!= 0))
1334 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1337 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1339 target_ulong uimm
= UIMM(ctx
->opcode
);
1341 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1345 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1346 if (likely(uimm
!= 0))
1347 gen_op_ori(uimm
<< 16);
1348 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1351 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1353 target_ulong uimm
= UIMM(ctx
->opcode
);
1355 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1359 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1360 if (likely(uimm
!= 0))
1362 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1366 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1368 target_ulong uimm
= UIMM(ctx
->opcode
);
1370 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1374 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1375 if (likely(uimm
!= 0))
1376 gen_op_xori(uimm
<< 16);
1377 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1380 /* popcntb : PowerPC 2.03 specification */
1381 GEN_HANDLER(popcntb
, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB
)
1383 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1384 #if defined(TARGET_PPC64)
1386 gen_op_popcntb_64();
1390 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1393 #if defined(TARGET_PPC64)
1394 /* extsw & extsw. */
1395 GEN_LOGICAL1(extsw
, 0x1E, PPC_64B
);
1397 GEN_LOGICAL1(cntlzd
, 0x01, PPC_64B
);
1400 /*** Integer rotate ***/
1401 /* rlwimi & rlwimi. */
1402 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1405 uint32_t mb
, me
, sh
;
1407 mb
= MB(ctx
->opcode
);
1408 me
= ME(ctx
->opcode
);
1409 sh
= SH(ctx
->opcode
);
1410 if (likely(sh
== 0)) {
1411 if (likely(mb
== 0 && me
== 31)) {
1412 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1414 } else if (likely(mb
== 31 && me
== 0)) {
1415 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1418 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1419 gen_op_load_gpr_T1(rA(ctx
->opcode
));
1422 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1423 gen_op_load_gpr_T1(rA(ctx
->opcode
));
1424 gen_op_rotli32_T0(SH(ctx
->opcode
));
1426 #if defined(TARGET_PPC64)
1430 mask
= MASK(mb
, me
);
1431 gen_op_andi_T0(mask
);
1432 gen_op_andi_T1(~mask
);
1435 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1436 if (unlikely(Rc(ctx
->opcode
) != 0))
1439 /* rlwinm & rlwinm. */
1440 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1442 uint32_t mb
, me
, sh
;
1444 sh
= SH(ctx
->opcode
);
1445 mb
= MB(ctx
->opcode
);
1446 me
= ME(ctx
->opcode
);
1447 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1448 if (likely(sh
== 0)) {
1451 if (likely(mb
== 0)) {
1452 if (likely(me
== 31)) {
1453 gen_op_rotli32_T0(sh
);
1455 } else if (likely(me
== (31 - sh
))) {
1459 } else if (likely(me
== 31)) {
1460 if (likely(sh
== (32 - mb
))) {
1465 gen_op_rotli32_T0(sh
);
1467 #if defined(TARGET_PPC64)
1471 gen_op_andi_T0(MASK(mb
, me
));
1473 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1474 if (unlikely(Rc(ctx
->opcode
) != 0))
1477 /* rlwnm & rlwnm. */
1478 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1482 mb
= MB(ctx
->opcode
);
1483 me
= ME(ctx
->opcode
);
1484 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1485 gen_op_load_gpr_T1(rB(ctx
->opcode
));
1486 gen_op_rotl32_T0_T1();
1487 if (unlikely(mb
!= 0 || me
!= 31)) {
1488 #if defined(TARGET_PPC64)
1492 gen_op_andi_T0(MASK(mb
, me
));
1494 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1495 if (unlikely(Rc(ctx
->opcode
) != 0))
1499 #if defined(TARGET_PPC64)
1500 #define GEN_PPC64_R2(name, opc1, opc2) \
1501 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1503 gen_##name(ctx, 0); \
1505 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1508 gen_##name(ctx, 1); \
1510 #define GEN_PPC64_R4(name, opc1, opc2) \
1511 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1513 gen_##name(ctx, 0, 0); \
1515 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
1518 gen_##name(ctx, 0, 1); \
1520 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1523 gen_##name(ctx, 1, 0); \
1525 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
1528 gen_##name(ctx, 1, 1); \
1531 static always_inline
void gen_andi_T0_64 (DisasContext
*ctx
, uint64_t mask
)
1534 gen_op_andi_T0_64(mask
>> 32, mask
& 0xFFFFFFFF);
1536 gen_op_andi_T0(mask
);
1539 static always_inline
void gen_andi_T1_64 (DisasContext
*ctx
, uint64_t mask
)
1542 gen_op_andi_T1_64(mask
>> 32, mask
& 0xFFFFFFFF);
1544 gen_op_andi_T1(mask
);
1547 static always_inline
void gen_rldinm (DisasContext
*ctx
, uint32_t mb
,
1548 uint32_t me
, uint32_t sh
)
1550 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1551 if (likely(sh
== 0)) {
1554 if (likely(mb
== 0)) {
1555 if (likely(me
== 63)) {
1556 gen_op_rotli64_T0(sh
);
1558 } else if (likely(me
== (63 - sh
))) {
1562 } else if (likely(me
== 63)) {
1563 if (likely(sh
== (64 - mb
))) {
1564 gen_op_srli_T0_64(mb
);
1568 gen_op_rotli64_T0(sh
);
1570 gen_andi_T0_64(ctx
, MASK(mb
, me
));
1572 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1573 if (unlikely(Rc(ctx
->opcode
) != 0))
1576 /* rldicl - rldicl. */
1577 static always_inline
void gen_rldicl (DisasContext
*ctx
, int mbn
, int shn
)
1581 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1582 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1583 gen_rldinm(ctx
, mb
, 63, sh
);
1585 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
1586 /* rldicr - rldicr. */
1587 static always_inline
void gen_rldicr (DisasContext
*ctx
, int men
, int shn
)
1591 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1592 me
= MB(ctx
->opcode
) | (men
<< 5);
1593 gen_rldinm(ctx
, 0, me
, sh
);
1595 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
1596 /* rldic - rldic. */
1597 static always_inline
void gen_rldic (DisasContext
*ctx
, int mbn
, int shn
)
1601 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1602 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1603 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
1605 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
1607 static always_inline
void gen_rldnm (DisasContext
*ctx
, uint32_t mb
,
1610 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1611 gen_op_load_gpr_T1(rB(ctx
->opcode
));
1612 gen_op_rotl64_T0_T1();
1613 if (unlikely(mb
!= 0 || me
!= 63)) {
1614 gen_andi_T0_64(ctx
, MASK(mb
, me
));
1616 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1617 if (unlikely(Rc(ctx
->opcode
) != 0))
1621 /* rldcl - rldcl. */
1622 static always_inline
void gen_rldcl (DisasContext
*ctx
, int mbn
)
1626 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1627 gen_rldnm(ctx
, mb
, 63);
1629 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
1630 /* rldcr - rldcr. */
1631 static always_inline
void gen_rldcr (DisasContext
*ctx
, int men
)
1635 me
= MB(ctx
->opcode
) | (men
<< 5);
1636 gen_rldnm(ctx
, 0, me
);
1638 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
1639 /* rldimi - rldimi. */
1640 static always_inline
void gen_rldimi (DisasContext
*ctx
, int mbn
, int shn
)
1643 uint32_t sh
, mb
, me
;
1645 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1646 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1648 if (likely(sh
== 0)) {
1649 if (likely(mb
== 0)) {
1650 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1653 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1654 gen_op_load_gpr_T1(rA(ctx
->opcode
));
1657 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1658 gen_op_load_gpr_T1(rA(ctx
->opcode
));
1659 gen_op_rotli64_T0(sh
);
1661 mask
= MASK(mb
, me
);
1662 gen_andi_T0_64(ctx
, mask
);
1663 gen_andi_T1_64(ctx
, ~mask
);
1666 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1667 if (unlikely(Rc(ctx
->opcode
) != 0))
1670 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
1673 /*** Integer shift ***/
1675 __GEN_LOGICAL2(slw
, 0x18, 0x00, PPC_INTEGER
);
1677 __GEN_LOGICAL2(sraw
, 0x18, 0x18, PPC_INTEGER
);
1678 /* srawi & srawi. */
1679 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
)
1682 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1683 if (SH(ctx
->opcode
) != 0) {
1684 gen_op_move_T1_T0();
1685 mb
= 32 - SH(ctx
->opcode
);
1687 #if defined(TARGET_PPC64)
1691 gen_op_srawi(SH(ctx
->opcode
), MASK(mb
, me
));
1693 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1694 if (unlikely(Rc(ctx
->opcode
) != 0))
1698 __GEN_LOGICAL2(srw
, 0x18, 0x10, PPC_INTEGER
);
1700 #if defined(TARGET_PPC64)
1702 __GEN_LOGICAL2(sld
, 0x1B, 0x00, PPC_64B
);
1704 __GEN_LOGICAL2(srad
, 0x1A, 0x18, PPC_64B
);
1705 /* sradi & sradi. */
1706 static always_inline
void gen_sradi (DisasContext
*ctx
, int n
)
1711 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1712 sh
= SH(ctx
->opcode
) + (n
<< 5);
1714 gen_op_move_T1_T0();
1715 mb
= 64 - SH(ctx
->opcode
);
1717 mask
= MASK(mb
, me
);
1718 gen_op_sradi(sh
, mask
>> 32, mask
);
1720 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1721 if (unlikely(Rc(ctx
->opcode
) != 0))
1724 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
)
1728 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
)
1733 __GEN_LOGICAL2(srd
, 0x1B, 0x10, PPC_64B
);
1736 /*** Floating-Point arithmetic ***/
1737 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
1738 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type) \
1740 if (unlikely(!ctx->fpu_enabled)) { \
1741 GEN_EXCP_NO_FP(ctx); \
1744 gen_op_load_fpr_FT0(rA(ctx->opcode)); \
1745 gen_op_load_fpr_FT1(rC(ctx->opcode)); \
1746 gen_op_load_fpr_FT2(rB(ctx->opcode)); \
1747 gen_reset_fpstatus(); \
1752 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1753 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
1756 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
1757 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
1758 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
1760 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
1761 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
1763 if (unlikely(!ctx->fpu_enabled)) { \
1764 GEN_EXCP_NO_FP(ctx); \
1767 gen_op_load_fpr_FT0(rA(ctx->opcode)); \
1768 gen_op_load_fpr_FT1(rB(ctx->opcode)); \
1769 gen_reset_fpstatus(); \
1774 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1775 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
1777 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
1778 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
1779 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
1781 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
1782 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
1784 if (unlikely(!ctx->fpu_enabled)) { \
1785 GEN_EXCP_NO_FP(ctx); \
1788 gen_op_load_fpr_FT0(rA(ctx->opcode)); \
1789 gen_op_load_fpr_FT1(rC(ctx->opcode)); \
1790 gen_reset_fpstatus(); \
1795 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1796 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
1798 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
1799 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
1800 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
1802 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
1803 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type) \
1805 if (unlikely(!ctx->fpu_enabled)) { \
1806 GEN_EXCP_NO_FP(ctx); \
1809 gen_op_load_fpr_FT0(rB(ctx->opcode)); \
1810 gen_reset_fpstatus(); \
1812 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1813 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
1816 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
1817 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type) \
1819 if (unlikely(!ctx->fpu_enabled)) { \
1820 GEN_EXCP_NO_FP(ctx); \
1823 gen_op_load_fpr_FT0(rB(ctx->opcode)); \
1824 gen_reset_fpstatus(); \
1826 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1827 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
1831 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
);
1833 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
);
1835 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
);
1838 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
);
1841 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
);
1844 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
);
1847 static always_inline
void gen_op_frsqrtes (void)
1852 GEN_FLOAT_BS(rsqrtes
, 0x3B, 0x1A, 1, PPC_FLOAT_FRSQRTES
);
1855 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
);
1857 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
);
1860 GEN_HANDLER(fsqrt
, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
)
1862 if (unlikely(!ctx
->fpu_enabled
)) {
1863 GEN_EXCP_NO_FP(ctx
);
1866 gen_op_load_fpr_FT0(rB(ctx
->opcode
));
1867 gen_reset_fpstatus();
1869 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
1870 gen_compute_fprf(1, Rc(ctx
->opcode
) != 0);
1873 GEN_HANDLER(fsqrts
, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
)
1875 if (unlikely(!ctx
->fpu_enabled
)) {
1876 GEN_EXCP_NO_FP(ctx
);
1879 gen_op_load_fpr_FT0(rB(ctx
->opcode
));
1880 gen_reset_fpstatus();
1883 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
1884 gen_compute_fprf(1, Rc(ctx
->opcode
) != 0);
1887 /*** Floating-Point multiply-and-add ***/
1888 /* fmadd - fmadds */
1889 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
);
1890 /* fmsub - fmsubs */
1891 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
);
1892 /* fnmadd - fnmadds */
1893 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
);
1894 /* fnmsub - fnmsubs */
1895 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
);
1897 /*** Floating-Point round & convert ***/
1899 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
);
1901 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
);
1903 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
);
1904 #if defined(TARGET_PPC64)
1906 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
);
1908 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
);
1910 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
);
1914 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
);
1916 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
);
1918 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
);
1920 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
);
1922 /*** Floating-Point compare ***/
1924 GEN_HANDLER(fcmpo
, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT
)
1926 if (unlikely(!ctx
->fpu_enabled
)) {
1927 GEN_EXCP_NO_FP(ctx
);
1930 gen_op_load_fpr_FT0(rA(ctx
->opcode
));
1931 gen_op_load_fpr_FT1(rB(ctx
->opcode
));
1932 gen_reset_fpstatus();
1934 gen_op_store_T0_crf(crfD(ctx
->opcode
));
1935 gen_op_float_check_status();
1939 GEN_HANDLER(fcmpu
, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT
)
1941 if (unlikely(!ctx
->fpu_enabled
)) {
1942 GEN_EXCP_NO_FP(ctx
);
1945 gen_op_load_fpr_FT0(rA(ctx
->opcode
));
1946 gen_op_load_fpr_FT1(rB(ctx
->opcode
));
1947 gen_reset_fpstatus();
1949 gen_op_store_T0_crf(crfD(ctx
->opcode
));
1950 gen_op_float_check_status();
1953 /*** Floating-point move ***/
1955 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
1956 GEN_FLOAT_B(abs
, 0x08, 0x08, 0, PPC_FLOAT
);
1959 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
1960 GEN_HANDLER(fmr
, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT
)
1962 if (unlikely(!ctx
->fpu_enabled
)) {
1963 GEN_EXCP_NO_FP(ctx
);
1966 gen_op_load_fpr_FT0(rB(ctx
->opcode
));
1967 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
1968 gen_compute_fprf(0, Rc(ctx
->opcode
) != 0);
1972 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
1973 GEN_FLOAT_B(nabs
, 0x08, 0x04, 0, PPC_FLOAT
);
1975 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
1976 GEN_FLOAT_B(neg
, 0x08, 0x01, 0, PPC_FLOAT
);
1978 /*** Floating-Point status & ctrl register ***/
1980 GEN_HANDLER(mcrfs
, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT
)
1984 if (unlikely(!ctx
->fpu_enabled
)) {
1985 GEN_EXCP_NO_FP(ctx
);
1988 gen_optimize_fprf();
1989 bfa
= 4 * (7 - crfS(ctx
->opcode
));
1990 gen_op_load_fpscr_T0(bfa
);
1991 gen_op_store_T0_crf(crfD(ctx
->opcode
));
1992 gen_op_fpscr_resetbit(~(0xF << bfa
));
1996 GEN_HANDLER(mffs
, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT
)
1998 if (unlikely(!ctx
->fpu_enabled
)) {
1999 GEN_EXCP_NO_FP(ctx
);
2002 gen_optimize_fprf();
2003 gen_reset_fpstatus();
2004 gen_op_load_fpscr_FT0();
2005 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
2006 gen_compute_fprf(0, Rc(ctx
->opcode
) != 0);
2010 GEN_HANDLER(mtfsb0
, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT
)
2014 if (unlikely(!ctx
->fpu_enabled
)) {
2015 GEN_EXCP_NO_FP(ctx
);
2018 crb
= 32 - (crbD(ctx
->opcode
) >> 2);
2019 gen_optimize_fprf();
2020 gen_reset_fpstatus();
2021 if (likely(crb
!= 30 && crb
!= 29))
2022 gen_op_fpscr_resetbit(~(1 << crb
));
2023 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2030 GEN_HANDLER(mtfsb1
, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT
)
2034 if (unlikely(!ctx
->fpu_enabled
)) {
2035 GEN_EXCP_NO_FP(ctx
);
2038 crb
= 32 - (crbD(ctx
->opcode
) >> 2);
2039 gen_optimize_fprf();
2040 gen_reset_fpstatus();
2041 /* XXX: we pretend we can only do IEEE floating-point computations */
2042 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
&& crb
!= FPSCR_NI
))
2043 gen_op_fpscr_setbit(crb
);
2044 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2048 /* We can raise a differed exception */
2049 gen_op_float_check_status();
2053 GEN_HANDLER(mtfsf
, 0x3F, 0x07, 0x16, 0x02010000, PPC_FLOAT
)
2055 if (unlikely(!ctx
->fpu_enabled
)) {
2056 GEN_EXCP_NO_FP(ctx
);
2059 gen_optimize_fprf();
2060 gen_op_load_fpr_FT0(rB(ctx
->opcode
));
2061 gen_reset_fpstatus();
2062 gen_op_store_fpscr(FM(ctx
->opcode
));
2063 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2067 /* We can raise a differed exception */
2068 gen_op_float_check_status();
2072 GEN_HANDLER(mtfsfi
, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT
)
2076 if (unlikely(!ctx
->fpu_enabled
)) {
2077 GEN_EXCP_NO_FP(ctx
);
2080 bf
= crbD(ctx
->opcode
) >> 2;
2082 gen_optimize_fprf();
2083 gen_op_set_FT0(FPIMM(ctx
->opcode
) << (4 * sh
));
2084 gen_reset_fpstatus();
2085 gen_op_store_fpscr(1 << sh
);
2086 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2090 /* We can raise a differed exception */
2091 gen_op_float_check_status();
2094 /*** Addressing modes ***/
2095 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2096 static always_inline
void gen_addr_imm_index (DisasContext
*ctx
,
2099 target_long simm
= SIMM(ctx
->opcode
);
2102 if (rA(ctx
->opcode
) == 0) {
2105 gen_op_load_gpr_T0(rA(ctx
->opcode
));
2106 if (likely(simm
!= 0))
2109 #ifdef DEBUG_MEMORY_ACCESSES
2110 gen_op_print_mem_EA();
2114 static always_inline
void gen_addr_reg_index (DisasContext
*ctx
)
2116 if (rA(ctx
->opcode
) == 0) {
2117 gen_op_load_gpr_T0(rB(ctx
->opcode
));
2119 gen_op_load_gpr_T0(rA(ctx
->opcode
));
2120 gen_op_load_gpr_T1(rB(ctx
->opcode
));
2123 #ifdef DEBUG_MEMORY_ACCESSES
2124 gen_op_print_mem_EA();
2128 static always_inline
void gen_addr_register (DisasContext
*ctx
)
2130 if (rA(ctx
->opcode
) == 0) {
2133 gen_op_load_gpr_T0(rA(ctx
->opcode
));
2135 #ifdef DEBUG_MEMORY_ACCESSES
2136 gen_op_print_mem_EA();
2140 #if defined(TARGET_PPC64)
2141 #define _GEN_MEM_FUNCS(name, mode) \
2142 &gen_op_##name##_##mode, \
2143 &gen_op_##name##_le_##mode, \
2144 &gen_op_##name##_64_##mode, \
2145 &gen_op_##name##_le_64_##mode
2147 #define _GEN_MEM_FUNCS(name, mode) \
2148 &gen_op_##name##_##mode, \
2149 &gen_op_##name##_le_##mode
2151 #if defined(CONFIG_USER_ONLY)
2152 #if defined(TARGET_PPC64)
2153 #define NB_MEM_FUNCS 4
2155 #define NB_MEM_FUNCS 2
2157 #define GEN_MEM_FUNCS(name) \
2158 _GEN_MEM_FUNCS(name, raw)
2160 #if defined(TARGET_PPC64)
2161 #define NB_MEM_FUNCS 12
2163 #define NB_MEM_FUNCS 6
2165 #define GEN_MEM_FUNCS(name) \
2166 _GEN_MEM_FUNCS(name, user), \
2167 _GEN_MEM_FUNCS(name, kernel), \
2168 _GEN_MEM_FUNCS(name, hypv)
2171 /*** Integer load ***/
2172 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
2173 /* Byte access routine are endian safe */
2174 #define gen_op_lbz_le_raw gen_op_lbz_raw
2175 #define gen_op_lbz_le_user gen_op_lbz_user
2176 #define gen_op_lbz_le_kernel gen_op_lbz_kernel
2177 #define gen_op_lbz_le_hypv gen_op_lbz_hypv
2178 #define gen_op_lbz_le_64_raw gen_op_lbz_64_raw
2179 #define gen_op_lbz_le_64_user gen_op_lbz_64_user
2180 #define gen_op_lbz_le_64_kernel gen_op_lbz_64_kernel
2181 #define gen_op_lbz_le_64_hypv gen_op_lbz_64_hypv
2182 #define gen_op_stb_le_raw gen_op_stb_raw
2183 #define gen_op_stb_le_user gen_op_stb_user
2184 #define gen_op_stb_le_kernel gen_op_stb_kernel
2185 #define gen_op_stb_le_hypv gen_op_stb_hypv
2186 #define gen_op_stb_le_64_raw gen_op_stb_64_raw
2187 #define gen_op_stb_le_64_user gen_op_stb_64_user
2188 #define gen_op_stb_le_64_kernel gen_op_stb_64_kernel
2189 #define gen_op_stb_le_64_hypv gen_op_stb_64_hypv
2190 #define OP_LD_TABLE(width) \
2191 static GenOpFunc *gen_op_l##width[NB_MEM_FUNCS] = { \
2192 GEN_MEM_FUNCS(l##width), \
2194 #define OP_ST_TABLE(width) \
2195 static GenOpFunc *gen_op_st##width[NB_MEM_FUNCS] = { \
2196 GEN_MEM_FUNCS(st##width), \
2199 #define GEN_LD(width, opc, type) \
2200 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2202 gen_addr_imm_index(ctx, 0); \
2203 op_ldst(l##width); \
2204 gen_op_store_T1_gpr(rD(ctx->opcode)); \
2207 #define GEN_LDU(width, opc, type) \
2208 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2210 if (unlikely(rA(ctx->opcode) == 0 || \
2211 rA(ctx->opcode) == rD(ctx->opcode))) { \
2212 GEN_EXCP_INVAL(ctx); \
2215 if (type == PPC_64B) \
2216 gen_addr_imm_index(ctx, 0x03); \
2218 gen_addr_imm_index(ctx, 0); \
2219 op_ldst(l##width); \
2220 gen_op_store_T1_gpr(rD(ctx->opcode)); \
2221 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2224 #define GEN_LDUX(width, opc2, opc3, type) \
2225 GEN_HANDLER(l##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2227 if (unlikely(rA(ctx->opcode) == 0 || \
2228 rA(ctx->opcode) == rD(ctx->opcode))) { \
2229 GEN_EXCP_INVAL(ctx); \
2232 gen_addr_reg_index(ctx); \
2233 op_ldst(l##width); \
2234 gen_op_store_T1_gpr(rD(ctx->opcode)); \
2235 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2238 #define GEN_LDX(width, opc2, opc3, type) \
2239 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2241 gen_addr_reg_index(ctx); \
2242 op_ldst(l##width); \
2243 gen_op_store_T1_gpr(rD(ctx->opcode)); \
2246 #define GEN_LDS(width, op, type) \
2247 OP_LD_TABLE(width); \
2248 GEN_LD(width, op | 0x20, type); \
2249 GEN_LDU(width, op | 0x21, type); \
2250 GEN_LDUX(width, 0x17, op | 0x01, type); \
2251 GEN_LDX(width, 0x17, op | 0x00, type)
2253 /* lbz lbzu lbzux lbzx */
2254 GEN_LDS(bz
, 0x02, PPC_INTEGER
);
2255 /* lha lhau lhaux lhax */
2256 GEN_LDS(ha
, 0x0A, PPC_INTEGER
);
2257 /* lhz lhzu lhzux lhzx */
2258 GEN_LDS(hz
, 0x08, PPC_INTEGER
);
2259 /* lwz lwzu lwzux lwzx */
2260 GEN_LDS(wz
, 0x00, PPC_INTEGER
);
2261 #if defined(TARGET_PPC64)
2265 GEN_LDUX(wa
, 0x15, 0x0B, PPC_64B
);
2267 GEN_LDX(wa
, 0x15, 0x0A, PPC_64B
);
2269 GEN_LDUX(d
, 0x15, 0x01, PPC_64B
);
2271 GEN_LDX(d
, 0x15, 0x00, PPC_64B
);
2272 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
)
2274 if (Rc(ctx
->opcode
)) {
2275 if (unlikely(rA(ctx
->opcode
) == 0 ||
2276 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
2277 GEN_EXCP_INVAL(ctx
);
2281 gen_addr_imm_index(ctx
, 0x03);
2282 if (ctx
->opcode
& 0x02) {
2283 /* lwa (lwau is undefined) */
2289 gen_op_store_T1_gpr(rD(ctx
->opcode
));
2290 if (Rc(ctx
->opcode
))
2291 gen_op_store_T0_gpr(rA(ctx
->opcode
));
2294 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
)
2296 #if defined(CONFIG_USER_ONLY)
2297 GEN_EXCP_PRIVOPC(ctx
);
2301 /* Restore CPU state */
2302 if (unlikely(ctx
->supervisor
== 0)) {
2303 GEN_EXCP_PRIVOPC(ctx
);
2306 ra
= rA(ctx
->opcode
);
2307 rd
= rD(ctx
->opcode
);
2308 if (unlikely((rd
& 1) || rd
== ra
)) {
2309 GEN_EXCP_INVAL(ctx
);
2312 if (unlikely(ctx
->mem_idx
& 1)) {
2313 /* Little-endian mode is not handled */
2314 GEN_EXCP(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2317 gen_addr_imm_index(ctx
, 0x0F);
2319 gen_op_store_T1_gpr(rd
);
2322 gen_op_store_T1_gpr(rd
+ 1);
2327 /*** Integer store ***/
2328 #define GEN_ST(width, opc, type) \
2329 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2331 gen_addr_imm_index(ctx, 0); \
2332 gen_op_load_gpr_T1(rS(ctx->opcode)); \
2333 op_ldst(st##width); \
2336 #define GEN_STU(width, opc, type) \
2337 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2339 if (unlikely(rA(ctx->opcode) == 0)) { \
2340 GEN_EXCP_INVAL(ctx); \
2343 if (type == PPC_64B) \
2344 gen_addr_imm_index(ctx, 0x03); \
2346 gen_addr_imm_index(ctx, 0); \
2347 gen_op_load_gpr_T1(rS(ctx->opcode)); \
2348 op_ldst(st##width); \
2349 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2352 #define GEN_STUX(width, opc2, opc3, type) \
2353 GEN_HANDLER(st##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2355 if (unlikely(rA(ctx->opcode) == 0)) { \
2356 GEN_EXCP_INVAL(ctx); \
2359 gen_addr_reg_index(ctx); \
2360 gen_op_load_gpr_T1(rS(ctx->opcode)); \
2361 op_ldst(st##width); \
2362 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2365 #define GEN_STX(width, opc2, opc3, type) \
2366 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2368 gen_addr_reg_index(ctx); \
2369 gen_op_load_gpr_T1(rS(ctx->opcode)); \
2370 op_ldst(st##width); \
2373 #define GEN_STS(width, op, type) \
2374 OP_ST_TABLE(width); \
2375 GEN_ST(width, op | 0x20, type); \
2376 GEN_STU(width, op | 0x21, type); \
2377 GEN_STUX(width, 0x17, op | 0x01, type); \
2378 GEN_STX(width, 0x17, op | 0x00, type)
2380 /* stb stbu stbux stbx */
2381 GEN_STS(b
, 0x06, PPC_INTEGER
);
2382 /* sth sthu sthux sthx */
2383 GEN_STS(h
, 0x0C, PPC_INTEGER
);
2384 /* stw stwu stwux stwx */
2385 GEN_STS(w
, 0x04, PPC_INTEGER
);
2386 #if defined(TARGET_PPC64)
2388 GEN_STUX(d
, 0x15, 0x05, PPC_64B
);
2389 GEN_STX(d
, 0x15, 0x04, PPC_64B
);
2390 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
)
2394 rs
= rS(ctx
->opcode
);
2395 if ((ctx
->opcode
& 0x3) == 0x2) {
2396 #if defined(CONFIG_USER_ONLY)
2397 GEN_EXCP_PRIVOPC(ctx
);
2400 if (unlikely(ctx
->supervisor
== 0)) {
2401 GEN_EXCP_PRIVOPC(ctx
);
2404 if (unlikely(rs
& 1)) {
2405 GEN_EXCP_INVAL(ctx
);
2408 if (unlikely(ctx
->mem_idx
& 1)) {
2409 /* Little-endian mode is not handled */
2410 GEN_EXCP(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2413 gen_addr_imm_index(ctx
, 0x03);
2414 gen_op_load_gpr_T1(rs
);
2417 gen_op_load_gpr_T1(rs
+ 1);
2422 if (Rc(ctx
->opcode
)) {
2423 if (unlikely(rA(ctx
->opcode
) == 0)) {
2424 GEN_EXCP_INVAL(ctx
);
2428 gen_addr_imm_index(ctx
, 0x03);
2429 gen_op_load_gpr_T1(rs
);
2431 if (Rc(ctx
->opcode
))
2432 gen_op_store_T0_gpr(rA(ctx
->opcode
));
2436 /*** Integer load and store with byte reverse ***/
2439 GEN_LDX(hbr
, 0x16, 0x18, PPC_INTEGER
);
2442 GEN_LDX(wbr
, 0x16, 0x10, PPC_INTEGER
);
2445 GEN_STX(hbr
, 0x16, 0x1C, PPC_INTEGER
);
2448 GEN_STX(wbr
, 0x16, 0x14, PPC_INTEGER
);
2450 /*** Integer load and store multiple ***/
2451 #define op_ldstm(name, reg) (*gen_op_##name[ctx->mem_idx])(reg)
2452 static GenOpFunc1
*gen_op_lmw
[NB_MEM_FUNCS
] = {
2455 static GenOpFunc1
*gen_op_stmw
[NB_MEM_FUNCS
] = {
2456 GEN_MEM_FUNCS(stmw
),
2460 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
2462 /* NIP cannot be restored if the memory exception comes from an helper */
2463 gen_update_nip(ctx
, ctx
->nip
- 4);
2464 gen_addr_imm_index(ctx
, 0);
2465 op_ldstm(lmw
, rD(ctx
->opcode
));
2469 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
2471 /* NIP cannot be restored if the memory exception comes from an helper */
2472 gen_update_nip(ctx
, ctx
->nip
- 4);
2473 gen_addr_imm_index(ctx
, 0);
2474 op_ldstm(stmw
, rS(ctx
->opcode
));
2477 /*** Integer load and store strings ***/
2478 #define op_ldsts(name, start) (*gen_op_##name[ctx->mem_idx])(start)
2479 #define op_ldstsx(name, rd, ra, rb) (*gen_op_##name[ctx->mem_idx])(rd, ra, rb)
2480 /* string load & stores are by definition endian-safe */
2481 #define gen_op_lswi_le_raw gen_op_lswi_raw
2482 #define gen_op_lswi_le_user gen_op_lswi_user
2483 #define gen_op_lswi_le_kernel gen_op_lswi_kernel
2484 #define gen_op_lswi_le_hypv gen_op_lswi_hypv
2485 #define gen_op_lswi_le_64_raw gen_op_lswi_raw
2486 #define gen_op_lswi_le_64_user gen_op_lswi_user
2487 #define gen_op_lswi_le_64_kernel gen_op_lswi_kernel
2488 #define gen_op_lswi_le_64_hypv gen_op_lswi_hypv
2489 static GenOpFunc1
*gen_op_lswi
[NB_MEM_FUNCS
] = {
2490 GEN_MEM_FUNCS(lswi
),
2492 #define gen_op_lswx_le_raw gen_op_lswx_raw
2493 #define gen_op_lswx_le_user gen_op_lswx_user
2494 #define gen_op_lswx_le_kernel gen_op_lswx_kernel
2495 #define gen_op_lswx_le_hypv gen_op_lswx_hypv
2496 #define gen_op_lswx_le_64_raw gen_op_lswx_raw
2497 #define gen_op_lswx_le_64_user gen_op_lswx_user
2498 #define gen_op_lswx_le_64_kernel gen_op_lswx_kernel
2499 #define gen_op_lswx_le_64_hypv gen_op_lswx_hypv
2500 static GenOpFunc3
*gen_op_lswx
[NB_MEM_FUNCS
] = {
2501 GEN_MEM_FUNCS(lswx
),
2503 #define gen_op_stsw_le_raw gen_op_stsw_raw
2504 #define gen_op_stsw_le_user gen_op_stsw_user
2505 #define gen_op_stsw_le_kernel gen_op_stsw_kernel
2506 #define gen_op_stsw_le_hypv gen_op_stsw_hypv
2507 #define gen_op_stsw_le_64_raw gen_op_stsw_raw
2508 #define gen_op_stsw_le_64_user gen_op_stsw_user
2509 #define gen_op_stsw_le_64_kernel gen_op_stsw_kernel
2510 #define gen_op_stsw_le_64_hypv gen_op_stsw_hypv
2511 static GenOpFunc1
*gen_op_stsw
[NB_MEM_FUNCS
] = {
2512 GEN_MEM_FUNCS(stsw
),
2516 /* PowerPC32 specification says we must generate an exception if
2517 * rA is in the range of registers to be loaded.
2518 * In an other hand, IBM says this is valid, but rA won't be loaded.
2519 * For now, I'll follow the spec...
2521 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
)
2523 int nb
= NB(ctx
->opcode
);
2524 int start
= rD(ctx
->opcode
);
2525 int ra
= rA(ctx
->opcode
);
2531 if (unlikely(((start
+ nr
) > 32 &&
2532 start
<= ra
&& (start
+ nr
- 32) > ra
) ||
2533 ((start
+ nr
) <= 32 && start
<= ra
&& (start
+ nr
) > ra
))) {
2534 GEN_EXCP(ctx
, POWERPC_EXCP_PROGRAM
,
2535 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_LSWX
);
2538 /* NIP cannot be restored if the memory exception comes from an helper */
2539 gen_update_nip(ctx
, ctx
->nip
- 4);
2540 gen_addr_register(ctx
);
2542 op_ldsts(lswi
, start
);
2546 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
)
2548 int ra
= rA(ctx
->opcode
);
2549 int rb
= rB(ctx
->opcode
);
2551 /* NIP cannot be restored if the memory exception comes from an helper */
2552 gen_update_nip(ctx
, ctx
->nip
- 4);
2553 gen_addr_reg_index(ctx
);
2557 gen_op_load_xer_bc();
2558 op_ldstsx(lswx
, rD(ctx
->opcode
), ra
, rb
);
2562 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
)
2564 int nb
= NB(ctx
->opcode
);
2566 /* NIP cannot be restored if the memory exception comes from an helper */
2567 gen_update_nip(ctx
, ctx
->nip
- 4);
2568 gen_addr_register(ctx
);
2572 op_ldsts(stsw
, rS(ctx
->opcode
));
2576 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
)
2578 /* NIP cannot be restored if the memory exception comes from an helper */
2579 gen_update_nip(ctx
, ctx
->nip
- 4);
2580 gen_addr_reg_index(ctx
);
2581 gen_op_load_xer_bc();
2582 op_ldsts(stsw
, rS(ctx
->opcode
));
2585 /*** Memory synchronisation ***/
2587 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO
)
2592 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
)
2597 #define op_lwarx() (*gen_op_lwarx[ctx->mem_idx])()
2598 #define op_stwcx() (*gen_op_stwcx[ctx->mem_idx])()
2599 static GenOpFunc
*gen_op_lwarx
[NB_MEM_FUNCS
] = {
2600 GEN_MEM_FUNCS(lwarx
),
2602 static GenOpFunc
*gen_op_stwcx
[NB_MEM_FUNCS
] = {
2603 GEN_MEM_FUNCS(stwcx
),
2607 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000001, PPC_RES
)
2609 /* NIP cannot be restored if the memory exception comes from an helper */
2610 gen_update_nip(ctx
, ctx
->nip
- 4);
2611 gen_addr_reg_index(ctx
);
2613 gen_op_store_T1_gpr(rD(ctx
->opcode
));
2617 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
)
2619 /* NIP cannot be restored if the memory exception comes from an helper */
2620 gen_update_nip(ctx
, ctx
->nip
- 4);
2621 gen_addr_reg_index(ctx
);
2622 gen_op_load_gpr_T1(rS(ctx
->opcode
));
2626 #if defined(TARGET_PPC64)
2627 #define op_ldarx() (*gen_op_ldarx[ctx->mem_idx])()
2628 #define op_stdcx() (*gen_op_stdcx[ctx->mem_idx])()
2629 static GenOpFunc
*gen_op_ldarx
[NB_MEM_FUNCS
] = {
2630 GEN_MEM_FUNCS(ldarx
),
2632 static GenOpFunc
*gen_op_stdcx
[NB_MEM_FUNCS
] = {
2633 GEN_MEM_FUNCS(stdcx
),
2637 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000001, PPC_64B
)
2639 /* NIP cannot be restored if the memory exception comes from an helper */
2640 gen_update_nip(ctx
, ctx
->nip
- 4);
2641 gen_addr_reg_index(ctx
);
2643 gen_op_store_T1_gpr(rD(ctx
->opcode
));
2647 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
)
2649 /* NIP cannot be restored if the memory exception comes from an helper */
2650 gen_update_nip(ctx
, ctx
->nip
- 4);
2651 gen_addr_reg_index(ctx
);
2652 gen_op_load_gpr_T1(rS(ctx
->opcode
));
2655 #endif /* defined(TARGET_PPC64) */
2658 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
)
2663 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
)
2665 /* Stop translation, as the CPU is supposed to sleep from now */
2667 GEN_EXCP(ctx
, EXCP_HLT
, 1);
2670 /*** Floating-point load ***/
2671 #define GEN_LDF(width, opc, type) \
2672 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2674 if (unlikely(!ctx->fpu_enabled)) { \
2675 GEN_EXCP_NO_FP(ctx); \
2678 gen_addr_imm_index(ctx, 0); \
2679 op_ldst(l##width); \
2680 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
2683 #define GEN_LDUF(width, opc, type) \
2684 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2686 if (unlikely(!ctx->fpu_enabled)) { \
2687 GEN_EXCP_NO_FP(ctx); \
2690 if (unlikely(rA(ctx->opcode) == 0)) { \
2691 GEN_EXCP_INVAL(ctx); \
2694 gen_addr_imm_index(ctx, 0); \
2695 op_ldst(l##width); \
2696 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
2697 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2700 #define GEN_LDUXF(width, opc, type) \
2701 GEN_HANDLER(l##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \
2703 if (unlikely(!ctx->fpu_enabled)) { \
2704 GEN_EXCP_NO_FP(ctx); \
2707 if (unlikely(rA(ctx->opcode) == 0)) { \
2708 GEN_EXCP_INVAL(ctx); \
2711 gen_addr_reg_index(ctx); \
2712 op_ldst(l##width); \
2713 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
2714 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2717 #define GEN_LDXF(width, opc2, opc3, type) \
2718 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2720 if (unlikely(!ctx->fpu_enabled)) { \
2721 GEN_EXCP_NO_FP(ctx); \
2724 gen_addr_reg_index(ctx); \
2725 op_ldst(l##width); \
2726 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
2729 #define GEN_LDFS(width, op, type) \
2730 OP_LD_TABLE(width); \
2731 GEN_LDF(width, op | 0x20, type); \
2732 GEN_LDUF(width, op | 0x21, type); \
2733 GEN_LDUXF(width, op | 0x01, type); \
2734 GEN_LDXF(width, 0x17, op | 0x00, type)
2736 /* lfd lfdu lfdux lfdx */
2737 GEN_LDFS(fd
, 0x12, PPC_FLOAT
);
2738 /* lfs lfsu lfsux lfsx */
2739 GEN_LDFS(fs
, 0x10, PPC_FLOAT
);
2741 /*** Floating-point store ***/
2742 #define GEN_STF(width, opc, type) \
2743 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2745 if (unlikely(!ctx->fpu_enabled)) { \
2746 GEN_EXCP_NO_FP(ctx); \
2749 gen_addr_imm_index(ctx, 0); \
2750 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
2751 op_ldst(st##width); \
2754 #define GEN_STUF(width, opc, type) \
2755 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2757 if (unlikely(!ctx->fpu_enabled)) { \
2758 GEN_EXCP_NO_FP(ctx); \
2761 if (unlikely(rA(ctx->opcode) == 0)) { \
2762 GEN_EXCP_INVAL(ctx); \
2765 gen_addr_imm_index(ctx, 0); \
2766 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
2767 op_ldst(st##width); \
2768 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2771 #define GEN_STUXF(width, opc, type) \
2772 GEN_HANDLER(st##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \
2774 if (unlikely(!ctx->fpu_enabled)) { \
2775 GEN_EXCP_NO_FP(ctx); \
2778 if (unlikely(rA(ctx->opcode) == 0)) { \
2779 GEN_EXCP_INVAL(ctx); \
2782 gen_addr_reg_index(ctx); \
2783 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
2784 op_ldst(st##width); \
2785 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2788 #define GEN_STXF(width, opc2, opc3, type) \
2789 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2791 if (unlikely(!ctx->fpu_enabled)) { \
2792 GEN_EXCP_NO_FP(ctx); \
2795 gen_addr_reg_index(ctx); \
2796 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
2797 op_ldst(st##width); \
2800 #define GEN_STFS(width, op, type) \
2801 OP_ST_TABLE(width); \
2802 GEN_STF(width, op | 0x20, type); \
2803 GEN_STUF(width, op | 0x21, type); \
2804 GEN_STUXF(width, op | 0x01, type); \
2805 GEN_STXF(width, 0x17, op | 0x00, type)
2807 /* stfd stfdu stfdux stfdx */
2808 GEN_STFS(fd
, 0x16, PPC_FLOAT
);
2809 /* stfs stfsu stfsux stfsx */
2810 GEN_STFS(fs
, 0x14, PPC_FLOAT
);
2815 GEN_STXF(fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
);
2818 static always_inline
void gen_goto_tb (DisasContext
*ctx
, int n
,
2821 TranslationBlock
*tb
;
2823 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
2824 likely(!ctx
->singlestep_enabled
)) {
2827 #if defined(TARGET_PPC64)
2833 tcg_gen_exit_tb((long)tb
+ n
);
2836 #if defined(TARGET_PPC64)
2842 if (unlikely(ctx
->singlestep_enabled
)) {
2843 if ((ctx
->singlestep_enabled
&
2844 (CPU_BRANCH_STEP
| CPU_SINGLE_STEP
)) &&
2845 ctx
->exception
== POWERPC_EXCP_BRANCH
) {
2846 target_ulong tmp
= ctx
->nip
;
2848 GEN_EXCP(ctx
, POWERPC_EXCP_TRACE
, 0);
2851 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
2852 gen_update_nip(ctx
, dest
);
2860 static always_inline
void gen_setlr (DisasContext
*ctx
, target_ulong nip
)
2862 #if defined(TARGET_PPC64)
2863 if (ctx
->sf_mode
!= 0 && (nip
>> 32))
2864 gen_op_setlr_64(ctx
->nip
>> 32, ctx
->nip
);
2867 gen_op_setlr(ctx
->nip
);
2871 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
2873 target_ulong li
, target
;
2875 ctx
->exception
= POWERPC_EXCP_BRANCH
;
2876 /* sign extend LI */
2877 #if defined(TARGET_PPC64)
2879 li
= ((int64_t)LI(ctx
->opcode
) << 38) >> 38;
2882 li
= ((int32_t)LI(ctx
->opcode
) << 6) >> 6;
2883 if (likely(AA(ctx
->opcode
) == 0))
2884 target
= ctx
->nip
+ li
- 4;
2887 #if defined(TARGET_PPC64)
2889 target
= (uint32_t)target
;
2891 if (LK(ctx
->opcode
))
2892 gen_setlr(ctx
, ctx
->nip
);
2893 gen_goto_tb(ctx
, 0, target
);
2900 static always_inline
void gen_bcond (DisasContext
*ctx
, int type
)
2902 target_ulong target
= 0;
2904 uint32_t bo
= BO(ctx
->opcode
);
2905 uint32_t bi
= BI(ctx
->opcode
);
2908 ctx
->exception
= POWERPC_EXCP_BRANCH
;
2909 if ((bo
& 0x4) == 0)
2913 li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
2914 if (likely(AA(ctx
->opcode
) == 0)) {
2915 target
= ctx
->nip
+ li
- 4;
2919 #if defined(TARGET_PPC64)
2921 target
= (uint32_t)target
;
2925 gen_op_movl_T1_ctr();
2929 gen_op_movl_T1_lr();
2932 if (LK(ctx
->opcode
))
2933 gen_setlr(ctx
, ctx
->nip
);
2935 /* No CR condition */
2938 #if defined(TARGET_PPC64)
2940 gen_op_test_ctr_64();
2946 #if defined(TARGET_PPC64)
2948 gen_op_test_ctrz_64();
2956 if (type
== BCOND_IM
) {
2957 gen_goto_tb(ctx
, 0, target
);
2960 #if defined(TARGET_PPC64)
2971 mask
= 1 << (3 - (bi
& 0x03));
2972 gen_op_load_crf_T0(bi
>> 2);
2976 #if defined(TARGET_PPC64)
2978 gen_op_test_ctr_true_64(mask
);
2981 gen_op_test_ctr_true(mask
);
2984 #if defined(TARGET_PPC64)
2986 gen_op_test_ctrz_true_64(mask
);
2989 gen_op_test_ctrz_true(mask
);
2994 gen_op_test_true(mask
);
3000 #if defined(TARGET_PPC64)
3002 gen_op_test_ctr_false_64(mask
);
3005 gen_op_test_ctr_false(mask
);
3008 #if defined(TARGET_PPC64)
3010 gen_op_test_ctrz_false_64(mask
);
3013 gen_op_test_ctrz_false(mask
);
3018 gen_op_test_false(mask
);
3023 if (type
== BCOND_IM
) {
3024 int l1
= gen_new_label();
3026 gen_goto_tb(ctx
, 0, target
);
3028 gen_goto_tb(ctx
, 1, ctx
->nip
);
3030 #if defined(TARGET_PPC64)
3032 gen_op_btest_T1_64(ctx
->nip
>> 32, ctx
->nip
);
3035 gen_op_btest_T1(ctx
->nip
);
3037 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
3038 gen_update_nip(ctx
, ctx
->nip
);
3045 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
3047 gen_bcond(ctx
, BCOND_IM
);
3050 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
)
3052 gen_bcond(ctx
, BCOND_CTR
);
3055 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
)
3057 gen_bcond(ctx
, BCOND_LR
);
3060 /*** Condition register logical ***/
3061 #define GEN_CRLOGIC(op, opc) \
3062 GEN_HANDLER(cr##op, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) \
3066 gen_op_load_crf_T0(crbA(ctx->opcode) >> 2); \
3067 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3069 gen_op_srli_T0(sh); \
3071 gen_op_sli_T0(-sh); \
3072 gen_op_load_crf_T1(crbB(ctx->opcode) >> 2); \
3073 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3075 gen_op_srli_T1(sh); \
3077 gen_op_sli_T1(-sh); \
3079 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
3080 gen_op_andi_T0(bitmask); \
3081 gen_op_load_crf_T1(crbD(ctx->opcode) >> 2); \
3082 gen_op_andi_T1(~bitmask); \
3084 gen_op_store_T0_crf(crbD(ctx->opcode) >> 2); \
3088 GEN_CRLOGIC(and, 0x08);
3090 GEN_CRLOGIC(andc
, 0x04);
3092 GEN_CRLOGIC(eqv
, 0x09);
3094 GEN_CRLOGIC(nand
, 0x07);
3096 GEN_CRLOGIC(nor
, 0x01);
3098 GEN_CRLOGIC(or, 0x0E);
3100 GEN_CRLOGIC(orc
, 0x0D);
3102 GEN_CRLOGIC(xor, 0x06);
3104 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
)
3106 gen_op_load_crf_T0(crfS(ctx
->opcode
));
3107 gen_op_store_T0_crf(crfD(ctx
->opcode
));
3110 /*** System linkage ***/
3111 /* rfi (supervisor only) */
3112 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
)
3114 #if defined(CONFIG_USER_ONLY)
3115 GEN_EXCP_PRIVOPC(ctx
);
3117 /* Restore CPU state */
3118 if (unlikely(!ctx
->supervisor
)) {
3119 GEN_EXCP_PRIVOPC(ctx
);
3127 #if defined(TARGET_PPC64)
3128 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
)
3130 #if defined(CONFIG_USER_ONLY)
3131 GEN_EXCP_PRIVOPC(ctx
);
3133 /* Restore CPU state */
3134 if (unlikely(!ctx
->supervisor
)) {
3135 GEN_EXCP_PRIVOPC(ctx
);
3143 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
)
3145 #if defined(CONFIG_USER_ONLY)
3146 GEN_EXCP_PRIVOPC(ctx
);
3148 /* Restore CPU state */
3149 if (unlikely(ctx
->supervisor
<= 1)) {
3150 GEN_EXCP_PRIVOPC(ctx
);
3160 #if defined(CONFIG_USER_ONLY)
3161 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3163 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3165 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW
)
3169 lev
= (ctx
->opcode
>> 5) & 0x7F;
3170 GEN_EXCP(ctx
, POWERPC_SYSCALL
, lev
);
3175 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
)
3177 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3178 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3179 /* Update the nip since this might generate a trap exception */
3180 gen_update_nip(ctx
, ctx
->nip
);
3181 gen_op_tw(TO(ctx
->opcode
));
3185 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
3187 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3188 gen_set_T1(SIMM(ctx
->opcode
));
3189 /* Update the nip since this might generate a trap exception */
3190 gen_update_nip(ctx
, ctx
->nip
);
3191 gen_op_tw(TO(ctx
->opcode
));
3194 #if defined(TARGET_PPC64)
3196 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
)
3198 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3199 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3200 /* Update the nip since this might generate a trap exception */
3201 gen_update_nip(ctx
, ctx
->nip
);
3202 gen_op_td(TO(ctx
->opcode
));
3206 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
)
3208 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3209 gen_set_T1(SIMM(ctx
->opcode
));
3210 /* Update the nip since this might generate a trap exception */
3211 gen_update_nip(ctx
, ctx
->nip
);
3212 gen_op_td(TO(ctx
->opcode
));
3216 /*** Processor control ***/
3218 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
)
3220 gen_op_load_xer_cr();
3221 gen_op_store_T0_crf(crfD(ctx
->opcode
));
3222 gen_op_clear_xer_ov();
3223 gen_op_clear_xer_ca();
3227 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
)
3231 if (likely(ctx
->opcode
& 0x00100000)) {
3232 crm
= CRM(ctx
->opcode
);
3233 if (likely((crm
^ (crm
- 1)) == 0)) {
3235 gen_op_load_cro(7 - crn
);
3240 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3244 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
)
3246 #if defined(CONFIG_USER_ONLY)
3247 GEN_EXCP_PRIVREG(ctx
);
3249 if (unlikely(!ctx
->supervisor
)) {
3250 GEN_EXCP_PRIVREG(ctx
);
3254 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3259 #define SPR_NOACCESS ((void *)(-1UL))
3261 static void spr_noaccess (void *opaque
, int sprn
)
3263 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
3264 printf("ERROR: try to access SPR %d !\n", sprn
);
3266 #define SPR_NOACCESS (&spr_noaccess)
3270 static always_inline
void gen_op_mfspr (DisasContext
*ctx
)
3272 void (*read_cb
)(void *opaque
, int sprn
);
3273 uint32_t sprn
= SPR(ctx
->opcode
);
3275 #if !defined(CONFIG_USER_ONLY)
3276 if (ctx
->supervisor
== 2)
3277 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
3278 else if (ctx
->supervisor
)
3279 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
3282 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
3283 if (likely(read_cb
!= NULL
)) {
3284 if (likely(read_cb
!= SPR_NOACCESS
)) {
3285 (*read_cb
)(ctx
, sprn
);
3286 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3288 /* Privilege exception */
3289 /* This is a hack to avoid warnings when running Linux:
3290 * this OS breaks the PowerPC virtualisation model,
3291 * allowing userland application to read the PVR
3293 if (sprn
!= SPR_PVR
) {
3294 if (loglevel
!= 0) {
3295 fprintf(logfile
, "Trying to read privileged spr %d %03x at "
3296 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3298 printf("Trying to read privileged spr %d %03x at " ADDRX
"\n",
3299 sprn
, sprn
, ctx
->nip
);
3301 GEN_EXCP_PRIVREG(ctx
);
3305 if (loglevel
!= 0) {
3306 fprintf(logfile
, "Trying to read invalid spr %d %03x at "
3307 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3309 printf("Trying to read invalid spr %d %03x at " ADDRX
"\n",
3310 sprn
, sprn
, ctx
->nip
);
3311 GEN_EXCP(ctx
, POWERPC_EXCP_PROGRAM
,
3312 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_SPR
);
3316 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
)
3322 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
)
3328 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
)
3332 gen_op_load_gpr_T0(rS(ctx
->opcode
));
3333 crm
= CRM(ctx
->opcode
);
3334 if (likely((ctx
->opcode
& 0x00100000) || (crm
^ (crm
- 1)) == 0)) {
3336 gen_op_srli_T0(crn
* 4);
3337 gen_op_andi_T0(0xF);
3338 gen_op_store_cro(7 - crn
);
3340 gen_op_store_cr(crm
);
3345 #if defined(TARGET_PPC64)
3346 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
)
3348 #if defined(CONFIG_USER_ONLY)
3349 GEN_EXCP_PRIVREG(ctx
);
3351 if (unlikely(!ctx
->supervisor
)) {
3352 GEN_EXCP_PRIVREG(ctx
);
3355 gen_op_load_gpr_T0(rS(ctx
->opcode
));
3356 if (ctx
->opcode
& 0x00010000) {
3357 /* Special form that does not need any synchronisation */
3358 gen_op_update_riee();
3360 /* XXX: we need to update nip before the store
3361 * if we enter power saving mode, we will exit the loop
3362 * directly from ppc_store_msr
3364 gen_update_nip(ctx
, ctx
->nip
);
3366 /* Must stop the translation as machine state (may have) changed */
3367 /* Note that mtmsr is not always defined as context-synchronizing */
3368 ctx
->exception
= POWERPC_EXCP_STOP
;
3374 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC
)
3376 #if defined(CONFIG_USER_ONLY)
3377 GEN_EXCP_PRIVREG(ctx
);
3379 if (unlikely(!ctx
->supervisor
)) {
3380 GEN_EXCP_PRIVREG(ctx
);
3383 gen_op_load_gpr_T0(rS(ctx
->opcode
));
3384 if (ctx
->opcode
& 0x00010000) {
3385 /* Special form that does not need any synchronisation */
3386 gen_op_update_riee();
3388 /* XXX: we need to update nip before the store
3389 * if we enter power saving mode, we will exit the loop
3390 * directly from ppc_store_msr
3392 gen_update_nip(ctx
, ctx
->nip
);
3393 #if defined(TARGET_PPC64)
3395 gen_op_store_msr_32();
3399 /* Must stop the translation as machine state (may have) changed */
3400 /* Note that mtmsrd is not always defined as context-synchronizing */
3401 ctx
->exception
= POWERPC_EXCP_STOP
;
3407 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC
)
3409 void (*write_cb
)(void *opaque
, int sprn
);
3410 uint32_t sprn
= SPR(ctx
->opcode
);
3412 #if !defined(CONFIG_USER_ONLY)
3413 if (ctx
->supervisor
== 2)
3414 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
3415 else if (ctx
->supervisor
)
3416 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
3419 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
3420 if (likely(write_cb
!= NULL
)) {
3421 if (likely(write_cb
!= SPR_NOACCESS
)) {
3422 gen_op_load_gpr_T0(rS(ctx
->opcode
));
3423 (*write_cb
)(ctx
, sprn
);
3425 /* Privilege exception */
3426 if (loglevel
!= 0) {
3427 fprintf(logfile
, "Trying to write privileged spr %d %03x at "
3428 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3430 printf("Trying to write privileged spr %d %03x at " ADDRX
"\n",
3431 sprn
, sprn
, ctx
->nip
);
3432 GEN_EXCP_PRIVREG(ctx
);
3436 if (loglevel
!= 0) {
3437 fprintf(logfile
, "Trying to write invalid spr %d %03x at "
3438 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3440 printf("Trying to write invalid spr %d %03x at " ADDRX
"\n",
3441 sprn
, sprn
, ctx
->nip
);
3442 GEN_EXCP(ctx
, POWERPC_EXCP_PROGRAM
,
3443 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_SPR
);
3447 /*** Cache management ***/
3449 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
)
3451 /* XXX: specification says this is treated as a load by the MMU */
3452 gen_addr_reg_index(ctx
);
3456 /* dcbi (Supervisor only) */
3457 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
)
3459 #if defined(CONFIG_USER_ONLY)
3460 GEN_EXCP_PRIVOPC(ctx
);
3462 if (unlikely(!ctx
->supervisor
)) {
3463 GEN_EXCP_PRIVOPC(ctx
);
3466 gen_addr_reg_index(ctx
);
3467 /* XXX: specification says this should be treated as a store by the MMU */
3474 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
)
3476 /* XXX: specification say this is treated as a load by the MMU */
3477 gen_addr_reg_index(ctx
);
3482 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE
)
3484 /* interpreted as no-op */
3485 /* XXX: specification say this is treated as a load by the MMU
3486 * but does not generate any exception
3491 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE
)
3493 /* interpreted as no-op */
3494 /* XXX: specification say this is treated as a load by the MMU
3495 * but does not generate any exception
3500 #define op_dcbz(n) (*gen_op_dcbz[n][ctx->mem_idx])()
3501 static GenOpFunc
*gen_op_dcbz
[4][NB_MEM_FUNCS
] = {
3502 /* 32 bytes cache line size */
3504 #define gen_op_dcbz_l32_le_raw gen_op_dcbz_l32_raw
3505 #define gen_op_dcbz_l32_le_user gen_op_dcbz_l32_user
3506 #define gen_op_dcbz_l32_le_kernel gen_op_dcbz_l32_kernel
3507 #define gen_op_dcbz_l32_le_hypv gen_op_dcbz_l32_hypv
3508 #define gen_op_dcbz_l32_le_64_raw gen_op_dcbz_l32_64_raw
3509 #define gen_op_dcbz_l32_le_64_user gen_op_dcbz_l32_64_user
3510 #define gen_op_dcbz_l32_le_64_kernel gen_op_dcbz_l32_64_kernel
3511 #define gen_op_dcbz_l32_le_64_hypv gen_op_dcbz_l32_64_hypv
3512 GEN_MEM_FUNCS(dcbz_l32
),
3514 /* 64 bytes cache line size */
3516 #define gen_op_dcbz_l64_le_raw gen_op_dcbz_l64_raw
3517 #define gen_op_dcbz_l64_le_user gen_op_dcbz_l64_user
3518 #define gen_op_dcbz_l64_le_kernel gen_op_dcbz_l64_kernel
3519 #define gen_op_dcbz_l64_le_hypv gen_op_dcbz_l64_hypv
3520 #define gen_op_dcbz_l64_le_64_raw gen_op_dcbz_l64_64_raw
3521 #define gen_op_dcbz_l64_le_64_user gen_op_dcbz_l64_64_user
3522 #define gen_op_dcbz_l64_le_64_kernel gen_op_dcbz_l64_64_kernel
3523 #define gen_op_dcbz_l64_le_64_hypv gen_op_dcbz_l64_64_hypv
3524 GEN_MEM_FUNCS(dcbz_l64
),
3526 /* 128 bytes cache line size */
3528 #define gen_op_dcbz_l128_le_raw gen_op_dcbz_l128_raw
3529 #define gen_op_dcbz_l128_le_user gen_op_dcbz_l128_user
3530 #define gen_op_dcbz_l128_le_kernel gen_op_dcbz_l128_kernel
3531 #define gen_op_dcbz_l128_le_hypv gen_op_dcbz_l128_hypv
3532 #define gen_op_dcbz_l128_le_64_raw gen_op_dcbz_l128_64_raw
3533 #define gen_op_dcbz_l128_le_64_user gen_op_dcbz_l128_64_user
3534 #define gen_op_dcbz_l128_le_64_kernel gen_op_dcbz_l128_64_kernel
3535 #define gen_op_dcbz_l128_le_64_hypv gen_op_dcbz_l128_64_hypv
3536 GEN_MEM_FUNCS(dcbz_l128
),
3538 /* tunable cache line size */
3540 #define gen_op_dcbz_le_raw gen_op_dcbz_raw
3541 #define gen_op_dcbz_le_user gen_op_dcbz_user
3542 #define gen_op_dcbz_le_kernel gen_op_dcbz_kernel
3543 #define gen_op_dcbz_le_hypv gen_op_dcbz_hypv
3544 #define gen_op_dcbz_le_64_raw gen_op_dcbz_64_raw
3545 #define gen_op_dcbz_le_64_user gen_op_dcbz_64_user
3546 #define gen_op_dcbz_le_64_kernel gen_op_dcbz_64_kernel
3547 #define gen_op_dcbz_le_64_hypv gen_op_dcbz_64_hypv
3548 GEN_MEM_FUNCS(dcbz
),
3552 static always_inline
void handler_dcbz (DisasContext
*ctx
,
3553 int dcache_line_size
)
3557 switch (dcache_line_size
) {
3574 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE_DCBZ
)
3576 gen_addr_reg_index(ctx
);
3577 handler_dcbz(ctx
, ctx
->dcache_line_size
);
3578 gen_op_check_reservation();
3581 GEN_HANDLER2(dcbz_970
, "dcbz", 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZT
)
3583 gen_addr_reg_index(ctx
);
3584 if (ctx
->opcode
& 0x00200000)
3585 handler_dcbz(ctx
, ctx
->dcache_line_size
);
3587 handler_dcbz(ctx
, -1);
3588 gen_op_check_reservation();
3592 #define op_icbi() (*gen_op_icbi[ctx->mem_idx])()
3593 #define gen_op_icbi_le_raw gen_op_icbi_raw
3594 #define gen_op_icbi_le_user gen_op_icbi_user
3595 #define gen_op_icbi_le_kernel gen_op_icbi_kernel
3596 #define gen_op_icbi_le_hypv gen_op_icbi_hypv
3597 #define gen_op_icbi_le_64_raw gen_op_icbi_64_raw
3598 #define gen_op_icbi_le_64_user gen_op_icbi_64_user
3599 #define gen_op_icbi_le_64_kernel gen_op_icbi_64_kernel
3600 #define gen_op_icbi_le_64_hypv gen_op_icbi_64_hypv
3601 static GenOpFunc
*gen_op_icbi
[NB_MEM_FUNCS
] = {
3602 GEN_MEM_FUNCS(icbi
),
3605 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
)
3607 /* NIP cannot be restored if the memory exception comes from an helper */
3608 gen_update_nip(ctx
, ctx
->nip
- 4);
3609 gen_addr_reg_index(ctx
);
3615 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
)
3617 /* interpreted as no-op */
3618 /* XXX: specification say this is treated as a store by the MMU
3619 * but does not generate any exception
3623 /*** Segment register manipulation ***/
3624 /* Supervisor only: */
3626 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
)
3628 #if defined(CONFIG_USER_ONLY)
3629 GEN_EXCP_PRIVREG(ctx
);
3631 if (unlikely(!ctx
->supervisor
)) {
3632 GEN_EXCP_PRIVREG(ctx
);
3635 gen_op_set_T1(SR(ctx
->opcode
));
3637 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3642 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
)
3644 #if defined(CONFIG_USER_ONLY)
3645 GEN_EXCP_PRIVREG(ctx
);
3647 if (unlikely(!ctx
->supervisor
)) {
3648 GEN_EXCP_PRIVREG(ctx
);
3651 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3654 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3659 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
)
3661 #if defined(CONFIG_USER_ONLY)
3662 GEN_EXCP_PRIVREG(ctx
);
3664 if (unlikely(!ctx
->supervisor
)) {
3665 GEN_EXCP_PRIVREG(ctx
);
3668 gen_op_load_gpr_T0(rS(ctx
->opcode
));
3669 gen_op_set_T1(SR(ctx
->opcode
));
3675 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
)
3677 #if defined(CONFIG_USER_ONLY)
3678 GEN_EXCP_PRIVREG(ctx
);
3680 if (unlikely(!ctx
->supervisor
)) {
3681 GEN_EXCP_PRIVREG(ctx
);
3684 gen_op_load_gpr_T0(rS(ctx
->opcode
));
3685 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3691 #if defined(TARGET_PPC64)
3692 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
3694 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
)
3696 #if defined(CONFIG_USER_ONLY)
3697 GEN_EXCP_PRIVREG(ctx
);
3699 if (unlikely(!ctx
->supervisor
)) {
3700 GEN_EXCP_PRIVREG(ctx
);
3703 gen_op_set_T1(SR(ctx
->opcode
));
3705 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3710 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
3713 #if defined(CONFIG_USER_ONLY)
3714 GEN_EXCP_PRIVREG(ctx
);
3716 if (unlikely(!ctx
->supervisor
)) {
3717 GEN_EXCP_PRIVREG(ctx
);
3720 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3723 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3728 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
)
3730 #if defined(CONFIG_USER_ONLY)
3731 GEN_EXCP_PRIVREG(ctx
);
3733 if (unlikely(!ctx
->supervisor
)) {
3734 GEN_EXCP_PRIVREG(ctx
);
3737 gen_op_load_gpr_T0(rS(ctx
->opcode
));
3738 gen_op_set_T1(SR(ctx
->opcode
));
3744 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
3747 #if defined(CONFIG_USER_ONLY)
3748 GEN_EXCP_PRIVREG(ctx
);
3750 if (unlikely(!ctx
->supervisor
)) {
3751 GEN_EXCP_PRIVREG(ctx
);
3754 gen_op_load_gpr_T0(rS(ctx
->opcode
));
3755 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3760 #endif /* defined(TARGET_PPC64) */
3762 /*** Lookaside buffer management ***/
3763 /* Optional & supervisor only: */
3765 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
)
3767 #if defined(CONFIG_USER_ONLY)
3768 GEN_EXCP_PRIVOPC(ctx
);
3770 if (unlikely(!ctx
->supervisor
)) {
3771 GEN_EXCP_PRIVOPC(ctx
);
3779 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE
)
3781 #if defined(CONFIG_USER_ONLY)
3782 GEN_EXCP_PRIVOPC(ctx
);
3784 if (unlikely(!ctx
->supervisor
)) {
3785 GEN_EXCP_PRIVOPC(ctx
);
3788 gen_op_load_gpr_T0(rB(ctx
->opcode
));
3789 #if defined(TARGET_PPC64)
3799 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
)
3801 #if defined(CONFIG_USER_ONLY)
3802 GEN_EXCP_PRIVOPC(ctx
);
3804 if (unlikely(!ctx
->supervisor
)) {
3805 GEN_EXCP_PRIVOPC(ctx
);
3808 /* This has no effect: it should ensure that all previous
3809 * tlbie have completed
3815 #if defined(TARGET_PPC64)
3817 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI
)
3819 #if defined(CONFIG_USER_ONLY)
3820 GEN_EXCP_PRIVOPC(ctx
);
3822 if (unlikely(!ctx
->supervisor
)) {
3823 GEN_EXCP_PRIVOPC(ctx
);
3831 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
)
3833 #if defined(CONFIG_USER_ONLY)
3834 GEN_EXCP_PRIVOPC(ctx
);
3836 if (unlikely(!ctx
->supervisor
)) {
3837 GEN_EXCP_PRIVOPC(ctx
);
3840 gen_op_load_gpr_T0(rB(ctx
->opcode
));
3846 /*** External control ***/
3848 #define op_eciwx() (*gen_op_eciwx[ctx->mem_idx])()
3849 #define op_ecowx() (*gen_op_ecowx[ctx->mem_idx])()
3850 static GenOpFunc
*gen_op_eciwx
[NB_MEM_FUNCS
] = {
3851 GEN_MEM_FUNCS(eciwx
),
3853 static GenOpFunc
*gen_op_ecowx
[NB_MEM_FUNCS
] = {
3854 GEN_MEM_FUNCS(ecowx
),
3858 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
)
3860 /* Should check EAR[E] & alignment ! */
3861 gen_addr_reg_index(ctx
);
3863 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3867 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
)
3869 /* Should check EAR[E] & alignment ! */
3870 gen_addr_reg_index(ctx
);
3871 gen_op_load_gpr_T1(rS(ctx
->opcode
));
3875 /* PowerPC 601 specific instructions */
3877 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
)
3879 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3881 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3882 if (unlikely(Rc(ctx
->opcode
) != 0))
3887 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
)
3889 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3890 gen_op_POWER_abso();
3891 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3892 if (unlikely(Rc(ctx
->opcode
) != 0))
3897 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
)
3899 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3900 gen_op_POWER_clcs();
3901 /* Rc=1 sets CR0 to an undefined state */
3902 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3906 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
)
3908 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3909 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3911 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3912 if (unlikely(Rc(ctx
->opcode
) != 0))
3917 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
)
3919 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3920 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3921 gen_op_POWER_divo();
3922 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3923 if (unlikely(Rc(ctx
->opcode
) != 0))
3928 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
)
3930 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3931 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3932 gen_op_POWER_divs();
3933 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3934 if (unlikely(Rc(ctx
->opcode
) != 0))
3938 /* divso - divso. */
3939 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
)
3941 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3942 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3943 gen_op_POWER_divso();
3944 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3945 if (unlikely(Rc(ctx
->opcode
) != 0))
3950 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
)
3952 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3953 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3955 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3956 if (unlikely(Rc(ctx
->opcode
) != 0))
3961 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
)
3963 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3964 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3965 gen_op_POWER_dozo();
3966 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3967 if (unlikely(Rc(ctx
->opcode
) != 0))
3972 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
)
3974 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3975 gen_op_set_T1(SIMM(ctx
->opcode
));
3977 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3980 /* As lscbx load from memory byte after byte, it's always endian safe.
3981 * Original POWER is 32 bits only, define 64 bits ops as 32 bits ones
3983 #define op_POWER_lscbx(start, ra, rb) \
3984 (*gen_op_POWER_lscbx[ctx->mem_idx])(start, ra, rb)
3985 #define gen_op_POWER_lscbx_64_raw gen_op_POWER_lscbx_raw
3986 #define gen_op_POWER_lscbx_64_user gen_op_POWER_lscbx_user
3987 #define gen_op_POWER_lscbx_64_kernel gen_op_POWER_lscbx_kernel
3988 #define gen_op_POWER_lscbx_64_hypv gen_op_POWER_lscbx_hypv
3989 #define gen_op_POWER_lscbx_le_raw gen_op_POWER_lscbx_raw
3990 #define gen_op_POWER_lscbx_le_user gen_op_POWER_lscbx_user
3991 #define gen_op_POWER_lscbx_le_kernel gen_op_POWER_lscbx_kernel
3992 #define gen_op_POWER_lscbx_le_hypv gen_op_POWER_lscbx_hypv
3993 #define gen_op_POWER_lscbx_le_64_raw gen_op_POWER_lscbx_raw
3994 #define gen_op_POWER_lscbx_le_64_user gen_op_POWER_lscbx_user
3995 #define gen_op_POWER_lscbx_le_64_kernel gen_op_POWER_lscbx_kernel
3996 #define gen_op_POWER_lscbx_le_64_hypv gen_op_POWER_lscbx_hypv
3997 static GenOpFunc3
*gen_op_POWER_lscbx
[NB_MEM_FUNCS
] = {
3998 GEN_MEM_FUNCS(POWER_lscbx
),
4001 /* lscbx - lscbx. */
4002 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
)
4004 int ra
= rA(ctx
->opcode
);
4005 int rb
= rB(ctx
->opcode
);
4007 gen_addr_reg_index(ctx
);
4011 /* NIP cannot be restored if the memory exception comes from an helper */
4012 gen_update_nip(ctx
, ctx
->nip
- 4);
4013 gen_op_load_xer_bc();
4014 gen_op_load_xer_cmp();
4015 op_POWER_lscbx(rD(ctx
->opcode
), ra
, rb
);
4016 gen_op_store_xer_bc();
4017 if (unlikely(Rc(ctx
->opcode
) != 0))
4021 /* maskg - maskg. */
4022 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
)
4024 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4025 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4026 gen_op_POWER_maskg();
4027 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4028 if (unlikely(Rc(ctx
->opcode
) != 0))
4032 /* maskir - maskir. */
4033 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
)
4035 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4036 gen_op_load_gpr_T1(rS(ctx
->opcode
));
4037 gen_op_load_gpr_T2(rB(ctx
->opcode
));
4038 gen_op_POWER_maskir();
4039 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4040 if (unlikely(Rc(ctx
->opcode
) != 0))
4045 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
)
4047 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4048 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4050 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4051 if (unlikely(Rc(ctx
->opcode
) != 0))
4056 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
)
4058 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4059 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4060 gen_op_POWER_mulo();
4061 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4062 if (unlikely(Rc(ctx
->opcode
) != 0))
4067 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
)
4069 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4070 gen_op_POWER_nabs();
4071 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4072 if (unlikely(Rc(ctx
->opcode
) != 0))
4076 /* nabso - nabso. */
4077 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
)
4079 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4080 gen_op_POWER_nabso();
4081 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4082 if (unlikely(Rc(ctx
->opcode
) != 0))
4087 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
)
4091 mb
= MB(ctx
->opcode
);
4092 me
= ME(ctx
->opcode
);
4093 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4094 gen_op_load_gpr_T1(rA(ctx
->opcode
));
4095 gen_op_load_gpr_T2(rB(ctx
->opcode
));
4096 gen_op_POWER_rlmi(MASK(mb
, me
), ~MASK(mb
, me
));
4097 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4098 if (unlikely(Rc(ctx
->opcode
) != 0))
4103 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
)
4105 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4106 gen_op_load_gpr_T1(rA(ctx
->opcode
));
4107 gen_op_load_gpr_T2(rB(ctx
->opcode
));
4108 gen_op_POWER_rrib();
4109 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4110 if (unlikely(Rc(ctx
->opcode
) != 0))
4115 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
)
4117 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4118 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4120 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4121 if (unlikely(Rc(ctx
->opcode
) != 0))
4126 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
)
4128 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4129 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4130 gen_op_POWER_sleq();
4131 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4132 if (unlikely(Rc(ctx
->opcode
) != 0))
4137 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
)
4139 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4140 gen_op_set_T1(SH(ctx
->opcode
));
4142 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4143 if (unlikely(Rc(ctx
->opcode
) != 0))
4147 /* slliq - slliq. */
4148 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
)
4150 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4151 gen_op_set_T1(SH(ctx
->opcode
));
4152 gen_op_POWER_sleq();
4153 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4154 if (unlikely(Rc(ctx
->opcode
) != 0))
4159 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
)
4161 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4162 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4163 gen_op_POWER_sllq();
4164 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4165 if (unlikely(Rc(ctx
->opcode
) != 0))
4170 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
)
4172 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4173 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4175 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4176 if (unlikely(Rc(ctx
->opcode
) != 0))
4180 /* sraiq - sraiq. */
4181 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
)
4183 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4184 gen_op_set_T1(SH(ctx
->opcode
));
4185 gen_op_POWER_sraq();
4186 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4187 if (unlikely(Rc(ctx
->opcode
) != 0))
4192 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
)
4194 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4195 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4196 gen_op_POWER_sraq();
4197 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4198 if (unlikely(Rc(ctx
->opcode
) != 0))
4203 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
)
4205 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4206 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4208 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4209 if (unlikely(Rc(ctx
->opcode
) != 0))
4214 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
)
4216 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4217 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4218 gen_op_POWER_srea();
4219 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4220 if (unlikely(Rc(ctx
->opcode
) != 0))
4225 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
)
4227 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4228 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4229 gen_op_POWER_sreq();
4230 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4231 if (unlikely(Rc(ctx
->opcode
) != 0))
4236 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
)
4238 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4239 gen_op_set_T1(SH(ctx
->opcode
));
4241 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4242 if (unlikely(Rc(ctx
->opcode
) != 0))
4247 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
)
4249 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4250 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4251 gen_op_set_T1(SH(ctx
->opcode
));
4252 gen_op_POWER_srlq();
4253 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4254 if (unlikely(Rc(ctx
->opcode
) != 0))
4259 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
)
4261 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4262 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4263 gen_op_POWER_srlq();
4264 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4265 if (unlikely(Rc(ctx
->opcode
) != 0))
4270 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
)
4272 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4273 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4275 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4276 if (unlikely(Rc(ctx
->opcode
) != 0))
4280 /* PowerPC 602 specific instructions */
4282 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
)
4285 GEN_EXCP_INVAL(ctx
);
4289 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
)
4292 GEN_EXCP_INVAL(ctx
);
4296 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
)
4298 #if defined(CONFIG_USER_ONLY)
4299 GEN_EXCP_PRIVOPC(ctx
);
4301 if (unlikely(!ctx
->supervisor
)) {
4302 GEN_EXCP_PRIVOPC(ctx
);
4305 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4307 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4311 /* 602 - 603 - G2 TLB management */
4313 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
)
4315 #if defined(CONFIG_USER_ONLY)
4316 GEN_EXCP_PRIVOPC(ctx
);
4318 if (unlikely(!ctx
->supervisor
)) {
4319 GEN_EXCP_PRIVOPC(ctx
);
4322 gen_op_load_gpr_T0(rB(ctx
->opcode
));
4328 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
)
4330 #if defined(CONFIG_USER_ONLY)
4331 GEN_EXCP_PRIVOPC(ctx
);
4333 if (unlikely(!ctx
->supervisor
)) {
4334 GEN_EXCP_PRIVOPC(ctx
);
4337 gen_op_load_gpr_T0(rB(ctx
->opcode
));
4342 /* 74xx TLB management */
4344 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
)
4346 #if defined(CONFIG_USER_ONLY)
4347 GEN_EXCP_PRIVOPC(ctx
);
4349 if (unlikely(!ctx
->supervisor
)) {
4350 GEN_EXCP_PRIVOPC(ctx
);
4353 gen_op_load_gpr_T0(rB(ctx
->opcode
));
4354 gen_op_74xx_tlbld();
4359 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
)
4361 #if defined(CONFIG_USER_ONLY)
4362 GEN_EXCP_PRIVOPC(ctx
);
4364 if (unlikely(!ctx
->supervisor
)) {
4365 GEN_EXCP_PRIVOPC(ctx
);
4368 gen_op_load_gpr_T0(rB(ctx
->opcode
));
4369 gen_op_74xx_tlbli();
4373 /* POWER instructions not in PowerPC 601 */
4375 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
)
4377 /* Cache line flush: implemented as no-op */
4381 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
)
4383 /* Cache line invalidate: privileged and treated as no-op */
4384 #if defined(CONFIG_USER_ONLY)
4385 GEN_EXCP_PRIVOPC(ctx
);
4387 if (unlikely(!ctx
->supervisor
)) {
4388 GEN_EXCP_PRIVOPC(ctx
);
4395 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
)
4397 /* Data cache line store: treated as no-op */
4400 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
)
4402 #if defined(CONFIG_USER_ONLY)
4403 GEN_EXCP_PRIVOPC(ctx
);
4405 if (unlikely(!ctx
->supervisor
)) {
4406 GEN_EXCP_PRIVOPC(ctx
);
4409 int ra
= rA(ctx
->opcode
);
4410 int rd
= rD(ctx
->opcode
);
4412 gen_addr_reg_index(ctx
);
4413 gen_op_POWER_mfsri();
4414 gen_op_store_T0_gpr(rd
);
4415 if (ra
!= 0 && ra
!= rd
)
4416 gen_op_store_T1_gpr(ra
);
4420 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
)
4422 #if defined(CONFIG_USER_ONLY)
4423 GEN_EXCP_PRIVOPC(ctx
);
4425 if (unlikely(!ctx
->supervisor
)) {
4426 GEN_EXCP_PRIVOPC(ctx
);
4429 gen_addr_reg_index(ctx
);
4431 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4435 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
)
4437 #if defined(CONFIG_USER_ONLY)
4438 GEN_EXCP_PRIVOPC(ctx
);
4440 if (unlikely(!ctx
->supervisor
)) {
4441 GEN_EXCP_PRIVOPC(ctx
);
4444 gen_op_POWER_rfsvc();
4449 /* svc is not implemented for now */
4451 /* POWER2 specific instructions */
4452 /* Quad manipulation (load/store two floats at a time) */
4453 /* Original POWER2 is 32 bits only, define 64 bits ops as 32 bits ones */
4454 #define op_POWER2_lfq() (*gen_op_POWER2_lfq[ctx->mem_idx])()
4455 #define op_POWER2_stfq() (*gen_op_POWER2_stfq[ctx->mem_idx])()
4456 #define gen_op_POWER2_lfq_64_raw gen_op_POWER2_lfq_raw
4457 #define gen_op_POWER2_lfq_64_user gen_op_POWER2_lfq_user
4458 #define gen_op_POWER2_lfq_64_kernel gen_op_POWER2_lfq_kernel
4459 #define gen_op_POWER2_lfq_64_hypv gen_op_POWER2_lfq_hypv
4460 #define gen_op_POWER2_lfq_le_64_raw gen_op_POWER2_lfq_le_raw
4461 #define gen_op_POWER2_lfq_le_64_user gen_op_POWER2_lfq_le_user
4462 #define gen_op_POWER2_lfq_le_64_kernel gen_op_POWER2_lfq_le_kernel
4463 #define gen_op_POWER2_lfq_le_64_hypv gen_op_POWER2_lfq_le_hypv
4464 #define gen_op_POWER2_stfq_64_raw gen_op_POWER2_stfq_raw
4465 #define gen_op_POWER2_stfq_64_user gen_op_POWER2_stfq_user
4466 #define gen_op_POWER2_stfq_64_kernel gen_op_POWER2_stfq_kernel
4467 #define gen_op_POWER2_stfq_64_hypv gen_op_POWER2_stfq_hypv
4468 #define gen_op_POWER2_stfq_le_64_raw gen_op_POWER2_stfq_le_raw
4469 #define gen_op_POWER2_stfq_le_64_user gen_op_POWER2_stfq_le_user
4470 #define gen_op_POWER2_stfq_le_64_kernel gen_op_POWER2_stfq_le_kernel
4471 #define gen_op_POWER2_stfq_le_64_hypv gen_op_POWER2_stfq_le_hypv
4472 static GenOpFunc
*gen_op_POWER2_lfq
[NB_MEM_FUNCS
] = {
4473 GEN_MEM_FUNCS(POWER2_lfq
),
4475 static GenOpFunc
*gen_op_POWER2_stfq
[NB_MEM_FUNCS
] = {
4476 GEN_MEM_FUNCS(POWER2_stfq
),
4480 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
4482 /* NIP cannot be restored if the memory exception comes from an helper */
4483 gen_update_nip(ctx
, ctx
->nip
- 4);
4484 gen_addr_imm_index(ctx
, 0);
4486 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
4487 gen_op_store_FT1_fpr(rD(ctx
->opcode
) + 1);
4491 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
4493 int ra
= rA(ctx
->opcode
);
4495 /* NIP cannot be restored if the memory exception comes from an helper */
4496 gen_update_nip(ctx
, ctx
->nip
- 4);
4497 gen_addr_imm_index(ctx
, 0);
4499 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
4500 gen_op_store_FT1_fpr(rD(ctx
->opcode
) + 1);
4502 gen_op_store_T0_gpr(ra
);
4506 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
)
4508 int ra
= rA(ctx
->opcode
);
4510 /* NIP cannot be restored if the memory exception comes from an helper */
4511 gen_update_nip(ctx
, ctx
->nip
- 4);
4512 gen_addr_reg_index(ctx
);
4514 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
4515 gen_op_store_FT1_fpr(rD(ctx
->opcode
) + 1);
4517 gen_op_store_T0_gpr(ra
);
4521 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
)
4523 /* NIP cannot be restored if the memory exception comes from an helper */
4524 gen_update_nip(ctx
, ctx
->nip
- 4);
4525 gen_addr_reg_index(ctx
);
4527 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
4528 gen_op_store_FT1_fpr(rD(ctx
->opcode
) + 1);
4532 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
4534 /* NIP cannot be restored if the memory exception comes from an helper */
4535 gen_update_nip(ctx
, ctx
->nip
- 4);
4536 gen_addr_imm_index(ctx
, 0);
4537 gen_op_load_fpr_FT0(rS(ctx
->opcode
));
4538 gen_op_load_fpr_FT1(rS(ctx
->opcode
) + 1);
4543 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
4545 int ra
= rA(ctx
->opcode
);
4547 /* NIP cannot be restored if the memory exception comes from an helper */
4548 gen_update_nip(ctx
, ctx
->nip
- 4);
4549 gen_addr_imm_index(ctx
, 0);
4550 gen_op_load_fpr_FT0(rS(ctx
->opcode
));
4551 gen_op_load_fpr_FT1(rS(ctx
->opcode
) + 1);
4554 gen_op_store_T0_gpr(ra
);
4558 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
)
4560 int ra
= rA(ctx
->opcode
);
4562 /* NIP cannot be restored if the memory exception comes from an helper */
4563 gen_update_nip(ctx
, ctx
->nip
- 4);
4564 gen_addr_reg_index(ctx
);
4565 gen_op_load_fpr_FT0(rS(ctx
->opcode
));
4566 gen_op_load_fpr_FT1(rS(ctx
->opcode
) + 1);
4569 gen_op_store_T0_gpr(ra
);
4573 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
)
4575 /* NIP cannot be restored if the memory exception comes from an helper */
4576 gen_update_nip(ctx
, ctx
->nip
- 4);
4577 gen_addr_reg_index(ctx
);
4578 gen_op_load_fpr_FT0(rS(ctx
->opcode
));
4579 gen_op_load_fpr_FT1(rS(ctx
->opcode
) + 1);
4583 /* BookE specific instructions */
4584 /* XXX: not implemented on 440 ? */
4585 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
)
4588 GEN_EXCP_INVAL(ctx
);
4591 /* XXX: not implemented on 440 ? */
4592 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
)
4594 #if defined(CONFIG_USER_ONLY)
4595 GEN_EXCP_PRIVOPC(ctx
);
4597 if (unlikely(!ctx
->supervisor
)) {
4598 GEN_EXCP_PRIVOPC(ctx
);
4601 gen_addr_reg_index(ctx
);
4602 /* Use the same micro-ops as for tlbie */
4603 #if defined(TARGET_PPC64)
4612 /* All 405 MAC instructions are translated here */
4613 static always_inline
void gen_405_mulladd_insn (DisasContext
*ctx
,
4615 int ra
, int rb
, int rt
, int Rc
)
4617 gen_op_load_gpr_T0(ra
);
4618 gen_op_load_gpr_T1(rb
);
4619 switch (opc3
& 0x0D) {
4621 /* macchw - macchw. - macchwo - macchwo. */
4622 /* macchws - macchws. - macchwso - macchwso. */
4623 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
4624 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
4625 /* mulchw - mulchw. */
4626 gen_op_405_mulchw();
4629 /* macchwu - macchwu. - macchwuo - macchwuo. */
4630 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
4631 /* mulchwu - mulchwu. */
4632 gen_op_405_mulchwu();
4635 /* machhw - machhw. - machhwo - machhwo. */
4636 /* machhws - machhws. - machhwso - machhwso. */
4637 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
4638 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
4639 /* mulhhw - mulhhw. */
4640 gen_op_405_mulhhw();
4643 /* machhwu - machhwu. - machhwuo - machhwuo. */
4644 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
4645 /* mulhhwu - mulhhwu. */
4646 gen_op_405_mulhhwu();
4649 /* maclhw - maclhw. - maclhwo - maclhwo. */
4650 /* maclhws - maclhws. - maclhwso - maclhwso. */
4651 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
4652 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
4653 /* mullhw - mullhw. */
4654 gen_op_405_mullhw();
4657 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
4658 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
4659 /* mullhwu - mullhwu. */
4660 gen_op_405_mullhwu();
4664 /* nmultiply-and-accumulate (0x0E) */
4668 /* (n)multiply-and-accumulate (0x0C - 0x0E) */
4669 gen_op_load_gpr_T2(rt
);
4670 gen_op_move_T1_T0();
4671 gen_op_405_add_T0_T2();
4674 /* Check overflow */
4676 gen_op_check_addo();
4678 gen_op_405_check_ovu();
4683 gen_op_405_check_sat();
4685 gen_op_405_check_satu();
4687 gen_op_store_T0_gpr(rt
);
4688 if (unlikely(Rc
) != 0) {
4694 #define GEN_MAC_HANDLER(name, opc2, opc3) \
4695 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC) \
4697 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
4698 rD(ctx->opcode), Rc(ctx->opcode)); \
4701 /* macchw - macchw. */
4702 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
4703 /* macchwo - macchwo. */
4704 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
4705 /* macchws - macchws. */
4706 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
4707 /* macchwso - macchwso. */
4708 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
4709 /* macchwsu - macchwsu. */
4710 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
4711 /* macchwsuo - macchwsuo. */
4712 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
4713 /* macchwu - macchwu. */
4714 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
4715 /* macchwuo - macchwuo. */
4716 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
4717 /* machhw - machhw. */
4718 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
4719 /* machhwo - machhwo. */
4720 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
4721 /* machhws - machhws. */
4722 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
4723 /* machhwso - machhwso. */
4724 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
4725 /* machhwsu - machhwsu. */
4726 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
4727 /* machhwsuo - machhwsuo. */
4728 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
4729 /* machhwu - machhwu. */
4730 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
4731 /* machhwuo - machhwuo. */
4732 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
4733 /* maclhw - maclhw. */
4734 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
4735 /* maclhwo - maclhwo. */
4736 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
4737 /* maclhws - maclhws. */
4738 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
4739 /* maclhwso - maclhwso. */
4740 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
4741 /* maclhwu - maclhwu. */
4742 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
4743 /* maclhwuo - maclhwuo. */
4744 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
4745 /* maclhwsu - maclhwsu. */
4746 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
4747 /* maclhwsuo - maclhwsuo. */
4748 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
4749 /* nmacchw - nmacchw. */
4750 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
4751 /* nmacchwo - nmacchwo. */
4752 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
4753 /* nmacchws - nmacchws. */
4754 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
4755 /* nmacchwso - nmacchwso. */
4756 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
4757 /* nmachhw - nmachhw. */
4758 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
4759 /* nmachhwo - nmachhwo. */
4760 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
4761 /* nmachhws - nmachhws. */
4762 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
4763 /* nmachhwso - nmachhwso. */
4764 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
4765 /* nmaclhw - nmaclhw. */
4766 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
4767 /* nmaclhwo - nmaclhwo. */
4768 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
4769 /* nmaclhws - nmaclhws. */
4770 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
4771 /* nmaclhwso - nmaclhwso. */
4772 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
4774 /* mulchw - mulchw. */
4775 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
4776 /* mulchwu - mulchwu. */
4777 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
4778 /* mulhhw - mulhhw. */
4779 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
4780 /* mulhhwu - mulhhwu. */
4781 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
4782 /* mullhw - mullhw. */
4783 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
4784 /* mullhwu - mullhwu. */
4785 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
4788 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
)
4790 #if defined(CONFIG_USER_ONLY)
4791 GEN_EXCP_PRIVREG(ctx
);
4793 uint32_t dcrn
= SPR(ctx
->opcode
);
4795 if (unlikely(!ctx
->supervisor
)) {
4796 GEN_EXCP_PRIVREG(ctx
);
4799 gen_op_set_T0(dcrn
);
4801 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4806 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
)
4808 #if defined(CONFIG_USER_ONLY)
4809 GEN_EXCP_PRIVREG(ctx
);
4811 uint32_t dcrn
= SPR(ctx
->opcode
);
4813 if (unlikely(!ctx
->supervisor
)) {
4814 GEN_EXCP_PRIVREG(ctx
);
4817 gen_op_set_T0(dcrn
);
4818 gen_op_load_gpr_T1(rS(ctx
->opcode
));
4824 /* XXX: not implemented on 440 ? */
4825 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
)
4827 #if defined(CONFIG_USER_ONLY)
4828 GEN_EXCP_PRIVREG(ctx
);
4830 if (unlikely(!ctx
->supervisor
)) {
4831 GEN_EXCP_PRIVREG(ctx
);
4834 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4836 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4837 /* Note: Rc update flag set leads to undefined state of Rc0 */
4842 /* XXX: not implemented on 440 ? */
4843 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
)
4845 #if defined(CONFIG_USER_ONLY)
4846 GEN_EXCP_PRIVREG(ctx
);
4848 if (unlikely(!ctx
->supervisor
)) {
4849 GEN_EXCP_PRIVREG(ctx
);
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 /* mfdcrux (PPC 460) : user-mode access to DCR */
4860 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
)
4862 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4864 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4865 /* Note: Rc update flag set leads to undefined state of Rc0 */
4868 /* mtdcrux (PPC 460) : user-mode access to DCR */
4869 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
)
4871 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4872 gen_op_load_gpr_T1(rS(ctx
->opcode
));
4874 /* Note: Rc update flag set leads to undefined state of Rc0 */
4878 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
)
4880 #if defined(CONFIG_USER_ONLY)
4881 GEN_EXCP_PRIVOPC(ctx
);
4883 if (unlikely(!ctx
->supervisor
)) {
4884 GEN_EXCP_PRIVOPC(ctx
);
4887 /* interpreted as no-op */
4892 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
)
4894 #if defined(CONFIG_USER_ONLY)
4895 GEN_EXCP_PRIVOPC(ctx
);
4897 if (unlikely(!ctx
->supervisor
)) {
4898 GEN_EXCP_PRIVOPC(ctx
);
4901 gen_addr_reg_index(ctx
);
4903 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4908 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
)
4910 /* interpreted as no-op */
4911 /* XXX: specification say this is treated as a load by the MMU
4912 * but does not generate any exception
4917 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
)
4919 #if defined(CONFIG_USER_ONLY)
4920 GEN_EXCP_PRIVOPC(ctx
);
4922 if (unlikely(!ctx
->supervisor
)) {
4923 GEN_EXCP_PRIVOPC(ctx
);
4926 /* interpreted as no-op */
4931 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
)
4933 #if defined(CONFIG_USER_ONLY)
4934 GEN_EXCP_PRIVOPC(ctx
);
4936 if (unlikely(!ctx
->supervisor
)) {
4937 GEN_EXCP_PRIVOPC(ctx
);
4940 /* interpreted as no-op */
4944 /* rfci (supervisor only) */
4945 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
)
4947 #if defined(CONFIG_USER_ONLY)
4948 GEN_EXCP_PRIVOPC(ctx
);
4950 if (unlikely(!ctx
->supervisor
)) {
4951 GEN_EXCP_PRIVOPC(ctx
);
4954 /* Restore CPU state */
4960 GEN_HANDLER(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
)
4962 #if defined(CONFIG_USER_ONLY)
4963 GEN_EXCP_PRIVOPC(ctx
);
4965 if (unlikely(!ctx
->supervisor
)) {
4966 GEN_EXCP_PRIVOPC(ctx
);
4969 /* Restore CPU state */
4975 /* BookE specific */
4976 /* XXX: not implemented on 440 ? */
4977 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
)
4979 #if defined(CONFIG_USER_ONLY)
4980 GEN_EXCP_PRIVOPC(ctx
);
4982 if (unlikely(!ctx
->supervisor
)) {
4983 GEN_EXCP_PRIVOPC(ctx
);
4986 /* Restore CPU state */
4992 /* XXX: not implemented on 440 ? */
4993 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
)
4995 #if defined(CONFIG_USER_ONLY)
4996 GEN_EXCP_PRIVOPC(ctx
);
4998 if (unlikely(!ctx
->supervisor
)) {
4999 GEN_EXCP_PRIVOPC(ctx
);
5002 /* Restore CPU state */
5008 /* TLB management - PowerPC 405 implementation */
5010 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
)
5012 #if defined(CONFIG_USER_ONLY)
5013 GEN_EXCP_PRIVOPC(ctx
);
5015 if (unlikely(!ctx
->supervisor
)) {
5016 GEN_EXCP_PRIVOPC(ctx
);
5019 switch (rB(ctx
->opcode
)) {
5021 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5022 gen_op_4xx_tlbre_hi();
5023 gen_op_store_T0_gpr(rD(ctx
->opcode
));
5026 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5027 gen_op_4xx_tlbre_lo();
5028 gen_op_store_T0_gpr(rD(ctx
->opcode
));
5031 GEN_EXCP_INVAL(ctx
);
5037 /* tlbsx - tlbsx. */
5038 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
)
5040 #if defined(CONFIG_USER_ONLY)
5041 GEN_EXCP_PRIVOPC(ctx
);
5043 if (unlikely(!ctx
->supervisor
)) {
5044 GEN_EXCP_PRIVOPC(ctx
);
5047 gen_addr_reg_index(ctx
);
5049 if (Rc(ctx
->opcode
))
5050 gen_op_4xx_tlbsx_check();
5051 gen_op_store_T0_gpr(rD(ctx
->opcode
));
5056 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
)
5058 #if defined(CONFIG_USER_ONLY)
5059 GEN_EXCP_PRIVOPC(ctx
);
5061 if (unlikely(!ctx
->supervisor
)) {
5062 GEN_EXCP_PRIVOPC(ctx
);
5065 switch (rB(ctx
->opcode
)) {
5067 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5068 gen_op_load_gpr_T1(rS(ctx
->opcode
));
5069 gen_op_4xx_tlbwe_hi();
5072 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5073 gen_op_load_gpr_T1(rS(ctx
->opcode
));
5074 gen_op_4xx_tlbwe_lo();
5077 GEN_EXCP_INVAL(ctx
);
5083 /* TLB management - PowerPC 440 implementation */
5085 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
)
5087 #if defined(CONFIG_USER_ONLY)
5088 GEN_EXCP_PRIVOPC(ctx
);
5090 if (unlikely(!ctx
->supervisor
)) {
5091 GEN_EXCP_PRIVOPC(ctx
);
5094 switch (rB(ctx
->opcode
)) {
5098 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5099 gen_op_440_tlbre(rB(ctx
->opcode
));
5100 gen_op_store_T0_gpr(rD(ctx
->opcode
));
5103 GEN_EXCP_INVAL(ctx
);
5109 /* tlbsx - tlbsx. */
5110 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
)
5112 #if defined(CONFIG_USER_ONLY)
5113 GEN_EXCP_PRIVOPC(ctx
);
5115 if (unlikely(!ctx
->supervisor
)) {
5116 GEN_EXCP_PRIVOPC(ctx
);
5119 gen_addr_reg_index(ctx
);
5121 if (Rc(ctx
->opcode
))
5122 gen_op_4xx_tlbsx_check();
5123 gen_op_store_T0_gpr(rD(ctx
->opcode
));
5128 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
)
5130 #if defined(CONFIG_USER_ONLY)
5131 GEN_EXCP_PRIVOPC(ctx
);
5133 if (unlikely(!ctx
->supervisor
)) {
5134 GEN_EXCP_PRIVOPC(ctx
);
5137 switch (rB(ctx
->opcode
)) {
5141 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5142 gen_op_load_gpr_T1(rS(ctx
->opcode
));
5143 gen_op_440_tlbwe(rB(ctx
->opcode
));
5146 GEN_EXCP_INVAL(ctx
);
5153 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, 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_load_gpr_T0(rD(ctx
->opcode
));
5164 /* Stop translation to have a chance to raise an exception
5165 * if we just set msr_ee to 1
5172 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000EFC01, PPC_WRTEE
)
5174 #if defined(CONFIG_USER_ONLY)
5175 GEN_EXCP_PRIVOPC(ctx
);
5177 if (unlikely(!ctx
->supervisor
)) {
5178 GEN_EXCP_PRIVOPC(ctx
);
5181 gen_op_set_T0(ctx
->opcode
& 0x00010000);
5183 /* Stop translation to have a chance to raise an exception
5184 * if we just set msr_ee to 1
5190 /* PowerPC 440 specific instructions */
5192 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
)
5194 gen_op_load_gpr_T0(rS(ctx
->opcode
));
5195 gen_op_load_gpr_T1(rB(ctx
->opcode
));
5197 gen_op_store_T0_gpr(rA(ctx
->opcode
));
5198 gen_op_store_xer_bc();
5199 if (Rc(ctx
->opcode
)) {
5200 gen_op_440_dlmzb_update_Rc();
5201 gen_op_store_T0_crf(0);
5205 /* mbar replaces eieio on 440 */
5206 GEN_HANDLER(mbar
, 0x1F, 0x16, 0x13, 0x001FF801, PPC_BOOKE
)
5208 /* interpreted as no-op */
5211 /* msync replaces sync on 440 */
5212 GEN_HANDLER(msync
, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE
)
5214 /* interpreted as no-op */
5218 GEN_HANDLER2(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001, PPC_BOOKE
)
5220 /* interpreted as no-op */
5221 /* XXX: specification say this is treated as a load by the MMU
5222 * but does not generate any exception
5226 /*** Altivec vector extension ***/
5227 /* Altivec registers moves */
5228 GEN32(gen_op_load_avr_A0
, gen_op_load_avr_A0_avr
);
5229 GEN32(gen_op_load_avr_A1
, gen_op_load_avr_A1_avr
);
5230 GEN32(gen_op_load_avr_A2
, gen_op_load_avr_A2_avr
);
5232 GEN32(gen_op_store_A0_avr
, gen_op_store_A0_avr_avr
);
5233 GEN32(gen_op_store_A1_avr
, gen_op_store_A1_avr_avr
);
5235 GEN32(gen_op_store_A2_avr
, gen_op_store_A2_avr_avr
);
5238 #define op_vr_ldst(name) (*gen_op_##name[ctx->mem_idx])()
5239 #define OP_VR_LD_TABLE(name) \
5240 static GenOpFunc *gen_op_vr_l##name[NB_MEM_FUNCS] = { \
5241 GEN_MEM_FUNCS(vr_l##name), \
5243 #define OP_VR_ST_TABLE(name) \
5244 static GenOpFunc *gen_op_vr_st##name[NB_MEM_FUNCS] = { \
5245 GEN_MEM_FUNCS(vr_st##name), \
5248 #define GEN_VR_LDX(name, opc2, opc3) \
5249 GEN_HANDLER(l##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
5251 if (unlikely(!ctx->altivec_enabled)) { \
5252 GEN_EXCP_NO_VR(ctx); \
5255 gen_addr_reg_index(ctx); \
5256 op_vr_ldst(vr_l##name); \
5257 gen_op_store_A0_avr(rD(ctx->opcode)); \
5260 #define GEN_VR_STX(name, opc2, opc3) \
5261 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
5263 if (unlikely(!ctx->altivec_enabled)) { \
5264 GEN_EXCP_NO_VR(ctx); \
5267 gen_addr_reg_index(ctx); \
5268 gen_op_load_avr_A0(rS(ctx->opcode)); \
5269 op_vr_ldst(vr_st##name); \
5273 GEN_VR_LDX(vx
, 0x07, 0x03);
5274 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
5275 #define gen_op_vr_lvxl gen_op_vr_lvx
5276 GEN_VR_LDX(vxl
, 0x07, 0x0B);
5279 GEN_VR_STX(vx
, 0x07, 0x07);
5280 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
5281 #define gen_op_vr_stvxl gen_op_vr_stvx
5282 GEN_VR_STX(vxl
, 0x07, 0x0F);
5284 /*** SPE extension ***/
5285 /* Register moves */
5286 #if !defined(TARGET_PPC64)
5288 GEN32(gen_op_load_gpr64_T0
, gen_op_load_gpr64_T0_gpr
);
5289 GEN32(gen_op_load_gpr64_T1
, gen_op_load_gpr64_T1_gpr
);
5291 GEN32(gen_op_load_gpr64_T2
, gen_op_load_gpr64_T2_gpr
);
5294 GEN32(gen_op_store_T0_gpr64
, gen_op_store_T0_gpr64_gpr
);
5295 GEN32(gen_op_store_T1_gpr64
, gen_op_store_T1_gpr64_gpr
);
5297 GEN32(gen_op_store_T2_gpr64
, gen_op_store_T2_gpr64_gpr
);
5300 #else /* !defined(TARGET_PPC64) */
5302 /* No specific load/store functions: GPRs are already 64 bits */
5303 #define gen_op_load_gpr64_T0 gen_op_load_gpr_T0
5304 #define gen_op_load_gpr64_T1 gen_op_load_gpr_T1
5306 #define gen_op_load_gpr64_T2 gen_op_load_gpr_T2
5309 #define gen_op_store_T0_gpr64 gen_op_store_T0_gpr
5310 #define gen_op_store_T1_gpr64 gen_op_store_T1_gpr
5312 #define gen_op_store_T2_gpr64 gen_op_store_T2_gpr
5315 #endif /* !defined(TARGET_PPC64) */
5317 #define GEN_SPE(name0, name1, opc2, opc3, inval, type) \
5318 GEN_HANDLER(name0##_##name1, 0x04, opc2, opc3, inval, type) \
5320 if (Rc(ctx->opcode)) \
5326 /* Handler for undefined SPE opcodes */
5327 static always_inline
void gen_speundef (DisasContext
*ctx
)
5329 GEN_EXCP_INVAL(ctx
);
5332 /* SPE load and stores */
5333 static always_inline
void gen_addr_spe_imm_index (DisasContext
*ctx
, int sh
)
5335 target_long simm
= rB(ctx
->opcode
);
5337 if (rA(ctx
->opcode
) == 0) {
5338 gen_set_T0(simm
<< sh
);
5340 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5341 if (likely(simm
!= 0))
5342 gen_op_addi(simm
<< sh
);
5346 #define op_spe_ldst(name) (*gen_op_##name[ctx->mem_idx])()
5347 #define OP_SPE_LD_TABLE(name) \
5348 static GenOpFunc *gen_op_spe_l##name[NB_MEM_FUNCS] = { \
5349 GEN_MEM_FUNCS(spe_l##name), \
5351 #define OP_SPE_ST_TABLE(name) \
5352 static GenOpFunc *gen_op_spe_st##name[NB_MEM_FUNCS] = { \
5353 GEN_MEM_FUNCS(spe_st##name), \
5356 #define GEN_SPE_LD(name, sh) \
5357 static always_inline void gen_evl##name (DisasContext *ctx) \
5359 if (unlikely(!ctx->spe_enabled)) { \
5360 GEN_EXCP_NO_AP(ctx); \
5363 gen_addr_spe_imm_index(ctx, sh); \
5364 op_spe_ldst(spe_l##name); \
5365 gen_op_store_T1_gpr64(rD(ctx->opcode)); \
5368 #define GEN_SPE_LDX(name) \
5369 static always_inline void gen_evl##name##x (DisasContext *ctx) \
5371 if (unlikely(!ctx->spe_enabled)) { \
5372 GEN_EXCP_NO_AP(ctx); \
5375 gen_addr_reg_index(ctx); \
5376 op_spe_ldst(spe_l##name); \
5377 gen_op_store_T1_gpr64(rD(ctx->opcode)); \
5380 #define GEN_SPEOP_LD(name, sh) \
5381 OP_SPE_LD_TABLE(name); \
5382 GEN_SPE_LD(name, sh); \
5385 #define GEN_SPE_ST(name, sh) \
5386 static always_inline void gen_evst##name (DisasContext *ctx) \
5388 if (unlikely(!ctx->spe_enabled)) { \
5389 GEN_EXCP_NO_AP(ctx); \
5392 gen_addr_spe_imm_index(ctx, sh); \
5393 gen_op_load_gpr64_T1(rS(ctx->opcode)); \
5394 op_spe_ldst(spe_st##name); \
5397 #define GEN_SPE_STX(name) \
5398 static always_inline void gen_evst##name##x (DisasContext *ctx) \
5400 if (unlikely(!ctx->spe_enabled)) { \
5401 GEN_EXCP_NO_AP(ctx); \
5404 gen_addr_reg_index(ctx); \
5405 gen_op_load_gpr64_T1(rS(ctx->opcode)); \
5406 op_spe_ldst(spe_st##name); \
5409 #define GEN_SPEOP_ST(name, sh) \
5410 OP_SPE_ST_TABLE(name); \
5411 GEN_SPE_ST(name, sh); \
5414 #define GEN_SPEOP_LDST(name, sh) \
5415 GEN_SPEOP_LD(name, sh); \
5416 GEN_SPEOP_ST(name, sh)
5418 /* SPE arithmetic and logic */
5419 #define GEN_SPEOP_ARITH2(name) \
5420 static always_inline void gen_##name (DisasContext *ctx) \
5422 if (unlikely(!ctx->spe_enabled)) { \
5423 GEN_EXCP_NO_AP(ctx); \
5426 gen_op_load_gpr64_T0(rA(ctx->opcode)); \
5427 gen_op_load_gpr64_T1(rB(ctx->opcode)); \
5429 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5432 #define GEN_SPEOP_ARITH1(name) \
5433 static always_inline void gen_##name (DisasContext *ctx) \
5435 if (unlikely(!ctx->spe_enabled)) { \
5436 GEN_EXCP_NO_AP(ctx); \
5439 gen_op_load_gpr64_T0(rA(ctx->opcode)); \
5441 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5444 #define GEN_SPEOP_COMP(name) \
5445 static always_inline void gen_##name (DisasContext *ctx) \
5447 if (unlikely(!ctx->spe_enabled)) { \
5448 GEN_EXCP_NO_AP(ctx); \
5451 gen_op_load_gpr64_T0(rA(ctx->opcode)); \
5452 gen_op_load_gpr64_T1(rB(ctx->opcode)); \
5454 gen_op_store_T0_crf(crfD(ctx->opcode)); \
5458 GEN_SPEOP_ARITH2(evand
);
5459 GEN_SPEOP_ARITH2(evandc
);
5460 GEN_SPEOP_ARITH2(evxor
);
5461 GEN_SPEOP_ARITH2(evor
);
5462 GEN_SPEOP_ARITH2(evnor
);
5463 GEN_SPEOP_ARITH2(eveqv
);
5464 GEN_SPEOP_ARITH2(evorc
);
5465 GEN_SPEOP_ARITH2(evnand
);
5466 GEN_SPEOP_ARITH2(evsrwu
);
5467 GEN_SPEOP_ARITH2(evsrws
);
5468 GEN_SPEOP_ARITH2(evslw
);
5469 GEN_SPEOP_ARITH2(evrlw
);
5470 GEN_SPEOP_ARITH2(evmergehi
);
5471 GEN_SPEOP_ARITH2(evmergelo
);
5472 GEN_SPEOP_ARITH2(evmergehilo
);
5473 GEN_SPEOP_ARITH2(evmergelohi
);
5476 GEN_SPEOP_ARITH2(evaddw
);
5477 GEN_SPEOP_ARITH2(evsubfw
);
5478 GEN_SPEOP_ARITH1(evabs
);
5479 GEN_SPEOP_ARITH1(evneg
);
5480 GEN_SPEOP_ARITH1(evextsb
);
5481 GEN_SPEOP_ARITH1(evextsh
);
5482 GEN_SPEOP_ARITH1(evrndw
);
5483 GEN_SPEOP_ARITH1(evcntlzw
);
5484 GEN_SPEOP_ARITH1(evcntlsw
);
5485 static always_inline
void gen_brinc (DisasContext
*ctx
)
5487 /* Note: brinc is usable even if SPE is disabled */
5488 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5489 gen_op_load_gpr_T1(rB(ctx
->opcode
));
5491 gen_op_store_T0_gpr(rD(ctx
->opcode
));
5494 #define GEN_SPEOP_ARITH_IMM2(name) \
5495 static always_inline void gen_##name##i (DisasContext *ctx) \
5497 if (unlikely(!ctx->spe_enabled)) { \
5498 GEN_EXCP_NO_AP(ctx); \
5501 gen_op_load_gpr64_T0(rB(ctx->opcode)); \
5502 gen_op_splatwi_T1_64(rA(ctx->opcode)); \
5504 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5507 #define GEN_SPEOP_LOGIC_IMM2(name) \
5508 static always_inline void gen_##name##i (DisasContext *ctx) \
5510 if (unlikely(!ctx->spe_enabled)) { \
5511 GEN_EXCP_NO_AP(ctx); \
5514 gen_op_load_gpr64_T0(rA(ctx->opcode)); \
5515 gen_op_splatwi_T1_64(rB(ctx->opcode)); \
5517 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5520 GEN_SPEOP_ARITH_IMM2(evaddw
);
5521 #define gen_evaddiw gen_evaddwi
5522 GEN_SPEOP_ARITH_IMM2(evsubfw
);
5523 #define gen_evsubifw gen_evsubfwi
5524 GEN_SPEOP_LOGIC_IMM2(evslw
);
5525 GEN_SPEOP_LOGIC_IMM2(evsrwu
);
5526 #define gen_evsrwis gen_evsrwsi
5527 GEN_SPEOP_LOGIC_IMM2(evsrws
);
5528 #define gen_evsrwiu gen_evsrwui
5529 GEN_SPEOP_LOGIC_IMM2(evrlw
);
5531 static always_inline
void gen_evsplati (DisasContext
*ctx
)
5533 int32_t imm
= (int32_t)(rA(ctx
->opcode
) << 27) >> 27;
5535 gen_op_splatwi_T0_64(imm
);
5536 gen_op_store_T0_gpr64(rD(ctx
->opcode
));
5539 static always_inline
void gen_evsplatfi (DisasContext
*ctx
)
5541 uint32_t imm
= rA(ctx
->opcode
) << 27;
5543 gen_op_splatwi_T0_64(imm
);
5544 gen_op_store_T0_gpr64(rD(ctx
->opcode
));
5548 GEN_SPEOP_COMP(evcmpgtu
);
5549 GEN_SPEOP_COMP(evcmpgts
);
5550 GEN_SPEOP_COMP(evcmpltu
);
5551 GEN_SPEOP_COMP(evcmplts
);
5552 GEN_SPEOP_COMP(evcmpeq
);
5554 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, PPC_SPE
); ////
5555 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, PPC_SPE
);
5556 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, PPC_SPE
); ////
5557 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, PPC_SPE
);
5558 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, PPC_SPE
); ////
5559 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, PPC_SPE
); ////
5560 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, PPC_SPE
); ////
5561 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x00000000, PPC_SPE
); //
5562 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0x00000000, PPC_SPE
); ////
5563 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, PPC_SPE
); ////
5564 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, PPC_SPE
); ////
5565 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, PPC_SPE
); ////
5566 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0x00000000, PPC_SPE
); ////
5567 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, PPC_SPE
); ////
5568 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, PPC_SPE
); ////
5569 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, PPC_SPE
);
5570 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, PPC_SPE
); ////
5571 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, PPC_SPE
);
5572 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, PPC_SPE
); //
5573 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, PPC_SPE
);
5574 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, PPC_SPE
); ////
5575 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, PPC_SPE
); ////
5576 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, PPC_SPE
); ////
5577 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, PPC_SPE
); ////
5578 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, PPC_SPE
); ////
5580 static always_inline
void gen_evsel (DisasContext
*ctx
)
5582 if (unlikely(!ctx
->spe_enabled
)) {
5583 GEN_EXCP_NO_AP(ctx
);
5586 gen_op_load_crf_T0(ctx
->opcode
& 0x7);
5587 gen_op_load_gpr64_T0(rA(ctx
->opcode
));
5588 gen_op_load_gpr64_T1(rB(ctx
->opcode
));
5590 gen_op_store_T0_gpr64(rD(ctx
->opcode
));
5593 GEN_HANDLER2(evsel0
, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE
)
5597 GEN_HANDLER2(evsel1
, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE
)
5601 GEN_HANDLER2(evsel2
, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE
)
5605 GEN_HANDLER2(evsel3
, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE
)
5610 /* Load and stores */
5611 #if defined(TARGET_PPC64)
5612 /* In that case, we already have 64 bits load & stores
5613 * so, spe_ldd is equivalent to ld and spe_std is equivalent to std
5615 #define gen_op_spe_ldd_raw gen_op_ld_raw
5616 #define gen_op_spe_ldd_user gen_op_ld_user
5617 #define gen_op_spe_ldd_kernel gen_op_ld_kernel
5618 #define gen_op_spe_ldd_hypv gen_op_ld_hypv
5619 #define gen_op_spe_ldd_64_raw gen_op_ld_64_raw
5620 #define gen_op_spe_ldd_64_user gen_op_ld_64_user
5621 #define gen_op_spe_ldd_64_kernel gen_op_ld_64_kernel
5622 #define gen_op_spe_ldd_64_hypv gen_op_ld_64_hypv
5623 #define gen_op_spe_ldd_le_raw gen_op_ld_le_raw
5624 #define gen_op_spe_ldd_le_user gen_op_ld_le_user
5625 #define gen_op_spe_ldd_le_kernel gen_op_ld_le_kernel
5626 #define gen_op_spe_ldd_le_hypv gen_op_ld_le_hypv
5627 #define gen_op_spe_ldd_le_64_raw gen_op_ld_le_64_raw
5628 #define gen_op_spe_ldd_le_64_user gen_op_ld_le_64_user
5629 #define gen_op_spe_ldd_le_64_kernel gen_op_ld_le_64_kernel
5630 #define gen_op_spe_ldd_le_64_hypv gen_op_ld_le_64_hypv
5631 #define gen_op_spe_stdd_raw gen_op_std_raw
5632 #define gen_op_spe_stdd_user gen_op_std_user
5633 #define gen_op_spe_stdd_kernel gen_op_std_kernel
5634 #define gen_op_spe_stdd_hypv gen_op_std_hypv
5635 #define gen_op_spe_stdd_64_raw gen_op_std_64_raw
5636 #define gen_op_spe_stdd_64_user gen_op_std_64_user
5637 #define gen_op_spe_stdd_64_kernel gen_op_std_64_kernel
5638 #define gen_op_spe_stdd_64_hypv gen_op_std_64_hypv
5639 #define gen_op_spe_stdd_le_raw gen_op_std_le_raw
5640 #define gen_op_spe_stdd_le_user gen_op_std_le_user
5641 #define gen_op_spe_stdd_le_kernel gen_op_std_le_kernel
5642 #define gen_op_spe_stdd_le_hypv gen_op_std_le_hypv
5643 #define gen_op_spe_stdd_le_64_raw gen_op_std_le_64_raw
5644 #define gen_op_spe_stdd_le_64_user gen_op_std_le_64_user
5645 #define gen_op_spe_stdd_le_64_kernel gen_op_std_le_64_kernel
5646 #define gen_op_spe_stdd_le_64_hypv gen_op_std_le_64_hypv
5647 #endif /* defined(TARGET_PPC64) */
5648 GEN_SPEOP_LDST(dd
, 3);
5649 GEN_SPEOP_LDST(dw
, 3);
5650 GEN_SPEOP_LDST(dh
, 3);
5651 GEN_SPEOP_LDST(whe
, 2);
5652 GEN_SPEOP_LD(whou
, 2);
5653 GEN_SPEOP_LD(whos
, 2);
5654 GEN_SPEOP_ST(who
, 2);
5656 #if defined(TARGET_PPC64)
5657 /* In that case, spe_stwwo is equivalent to stw */
5658 #define gen_op_spe_stwwo_raw gen_op_stw_raw
5659 #define gen_op_spe_stwwo_user gen_op_stw_user
5660 #define gen_op_spe_stwwo_kernel gen_op_stw_kernel
5661 #define gen_op_spe_stwwo_hypv gen_op_stw_hypv
5662 #define gen_op_spe_stwwo_le_raw gen_op_stw_le_raw
5663 #define gen_op_spe_stwwo_le_user gen_op_stw_le_user
5664 #define gen_op_spe_stwwo_le_kernel gen_op_stw_le_kernel
5665 #define gen_op_spe_stwwo_le_hypv gen_op_stw_le_hypv
5666 #define gen_op_spe_stwwo_64_raw gen_op_stw_64_raw
5667 #define gen_op_spe_stwwo_64_user gen_op_stw_64_user
5668 #define gen_op_spe_stwwo_64_kernel gen_op_stw_64_kernel
5669 #define gen_op_spe_stwwo_64_hypv gen_op_stw_64_hypv
5670 #define gen_op_spe_stwwo_le_64_raw gen_op_stw_le_64_raw
5671 #define gen_op_spe_stwwo_le_64_user gen_op_stw_le_64_user
5672 #define gen_op_spe_stwwo_le_64_kernel gen_op_stw_le_64_kernel
5673 #define gen_op_spe_stwwo_le_64_hypv gen_op_stw_le_64_hypv
5675 #define _GEN_OP_SPE_STWWE(suffix) \
5676 static always_inline void gen_op_spe_stwwe_##suffix (void) \
5678 gen_op_srli32_T1_64(); \
5679 gen_op_spe_stwwo_##suffix(); \
5681 #define _GEN_OP_SPE_STWWE_LE(suffix) \
5682 static always_inline void gen_op_spe_stwwe_le_##suffix (void) \
5684 gen_op_srli32_T1_64(); \
5685 gen_op_spe_stwwo_le_##suffix(); \
5687 #if defined(TARGET_PPC64)
5688 #define GEN_OP_SPE_STWWE(suffix) \
5689 _GEN_OP_SPE_STWWE(suffix); \
5690 _GEN_OP_SPE_STWWE_LE(suffix); \
5691 static always_inline void gen_op_spe_stwwe_64_##suffix (void) \
5693 gen_op_srli32_T1_64(); \
5694 gen_op_spe_stwwo_64_##suffix(); \
5696 static always_inline void gen_op_spe_stwwe_le_64_##suffix (void) \
5698 gen_op_srli32_T1_64(); \
5699 gen_op_spe_stwwo_le_64_##suffix(); \
5702 #define GEN_OP_SPE_STWWE(suffix) \
5703 _GEN_OP_SPE_STWWE(suffix); \
5704 _GEN_OP_SPE_STWWE_LE(suffix)
5706 #if defined(CONFIG_USER_ONLY)
5707 GEN_OP_SPE_STWWE(raw
);
5708 #else /* defined(CONFIG_USER_ONLY) */
5709 GEN_OP_SPE_STWWE(user
);
5710 GEN_OP_SPE_STWWE(kernel
);
5711 GEN_OP_SPE_STWWE(hypv
);
5712 #endif /* defined(CONFIG_USER_ONLY) */
5713 GEN_SPEOP_ST(wwe
, 2);
5714 GEN_SPEOP_ST(wwo
, 2);
5716 #define GEN_SPE_LDSPLAT(name, op, suffix) \
5717 static always_inline void gen_op_spe_l##name##_##suffix (void) \
5719 gen_op_##op##_##suffix(); \
5720 gen_op_splatw_T1_64(); \
5723 #define GEN_OP_SPE_LHE(suffix) \
5724 static always_inline void gen_op_spe_lhe_##suffix (void) \
5726 gen_op_spe_lh_##suffix(); \
5727 gen_op_sli16_T1_64(); \
5730 #define GEN_OP_SPE_LHX(suffix) \
5731 static always_inline void gen_op_spe_lhx_##suffix (void) \
5733 gen_op_spe_lh_##suffix(); \
5734 gen_op_extsh_T1_64(); \
5737 #if defined(CONFIG_USER_ONLY)
5738 GEN_OP_SPE_LHE(raw
);
5739 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, raw
);
5740 GEN_OP_SPE_LHE(le_raw
);
5741 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_raw
);
5742 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, raw
);
5743 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_raw
);
5744 GEN_OP_SPE_LHX(raw
);
5745 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, raw
);
5746 GEN_OP_SPE_LHX(le_raw
);
5747 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_raw
);
5748 #if defined(TARGET_PPC64)
5749 GEN_OP_SPE_LHE(64_raw
);
5750 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, 64_raw
);
5751 GEN_OP_SPE_LHE(le_64_raw
);
5752 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_64_raw
);
5753 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, 64_raw
);
5754 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_64_raw
);
5755 GEN_OP_SPE_LHX(64_raw
);
5756 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, 64_raw
);
5757 GEN_OP_SPE_LHX(le_64_raw
);
5758 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_64_raw
);
5761 GEN_OP_SPE_LHE(user
);
5762 GEN_OP_SPE_LHE(kernel
);
5763 GEN_OP_SPE_LHE(hypv
);
5764 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, user
);
5765 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, kernel
);
5766 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, hypv
);
5767 GEN_OP_SPE_LHE(le_user
);
5768 GEN_OP_SPE_LHE(le_kernel
);
5769 GEN_OP_SPE_LHE(le_hypv
);
5770 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_user
);
5771 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_kernel
);
5772 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_hypv
);
5773 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, user
);
5774 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, kernel
);
5775 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, hypv
);
5776 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_user
);
5777 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_kernel
);
5778 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_hypv
);
5779 GEN_OP_SPE_LHX(user
);
5780 GEN_OP_SPE_LHX(kernel
);
5781 GEN_OP_SPE_LHX(hypv
);
5782 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, user
);
5783 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, kernel
);
5784 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, hypv
);
5785 GEN_OP_SPE_LHX(le_user
);
5786 GEN_OP_SPE_LHX(le_kernel
);
5787 GEN_OP_SPE_LHX(le_hypv
);
5788 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_user
);
5789 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_kernel
);
5790 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_hypv
);
5791 #if defined(TARGET_PPC64)
5792 GEN_OP_SPE_LHE(64_user
);
5793 GEN_OP_SPE_LHE(64_kernel
);
5794 GEN_OP_SPE_LHE(64_hypv
);
5795 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, 64_user
);
5796 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, 64_kernel
);
5797 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, 64_hypv
);
5798 GEN_OP_SPE_LHE(le_64_user
);
5799 GEN_OP_SPE_LHE(le_64_kernel
);
5800 GEN_OP_SPE_LHE(le_64_hypv
);
5801 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_64_user
);
5802 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_64_kernel
);
5803 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_64_hypv
);
5804 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, 64_user
);
5805 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, 64_kernel
);
5806 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, 64_hypv
);
5807 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_64_user
);
5808 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_64_kernel
);
5809 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_64_hypv
);
5810 GEN_OP_SPE_LHX(64_user
);
5811 GEN_OP_SPE_LHX(64_kernel
);
5812 GEN_OP_SPE_LHX(64_hypv
);
5813 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, 64_user
);
5814 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, 64_kernel
);
5815 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, 64_hypv
);
5816 GEN_OP_SPE_LHX(le_64_user
);
5817 GEN_OP_SPE_LHX(le_64_kernel
);
5818 GEN_OP_SPE_LHX(le_64_hypv
);
5819 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_64_user
);
5820 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_64_kernel
);
5821 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_64_hypv
);
5824 GEN_SPEOP_LD(hhesplat
, 1);
5825 GEN_SPEOP_LD(hhousplat
, 1);
5826 GEN_SPEOP_LD(hhossplat
, 1);
5827 GEN_SPEOP_LD(wwsplat
, 2);
5828 GEN_SPEOP_LD(whsplat
, 2);
5830 GEN_SPE(evlddx
, evldd
, 0x00, 0x0C, 0x00000000, PPC_SPE
); //
5831 GEN_SPE(evldwx
, evldw
, 0x01, 0x0C, 0x00000000, PPC_SPE
); //
5832 GEN_SPE(evldhx
, evldh
, 0x02, 0x0C, 0x00000000, PPC_SPE
); //
5833 GEN_SPE(evlhhesplatx
, evlhhesplat
, 0x04, 0x0C, 0x00000000, PPC_SPE
); //
5834 GEN_SPE(evlhhousplatx
, evlhhousplat
, 0x06, 0x0C, 0x00000000, PPC_SPE
); //
5835 GEN_SPE(evlhhossplatx
, evlhhossplat
, 0x07, 0x0C, 0x00000000, PPC_SPE
); //
5836 GEN_SPE(evlwhex
, evlwhe
, 0x08, 0x0C, 0x00000000, PPC_SPE
); //
5837 GEN_SPE(evlwhoux
, evlwhou
, 0x0A, 0x0C, 0x00000000, PPC_SPE
); //
5838 GEN_SPE(evlwhosx
, evlwhos
, 0x0B, 0x0C, 0x00000000, PPC_SPE
); //
5839 GEN_SPE(evlwwsplatx
, evlwwsplat
, 0x0C, 0x0C, 0x00000000, PPC_SPE
); //
5840 GEN_SPE(evlwhsplatx
, evlwhsplat
, 0x0E, 0x0C, 0x00000000, PPC_SPE
); //
5841 GEN_SPE(evstddx
, evstdd
, 0x10, 0x0C, 0x00000000, PPC_SPE
); //
5842 GEN_SPE(evstdwx
, evstdw
, 0x11, 0x0C, 0x00000000, PPC_SPE
); //
5843 GEN_SPE(evstdhx
, evstdh
, 0x12, 0x0C, 0x00000000, PPC_SPE
); //
5844 GEN_SPE(evstwhex
, evstwhe
, 0x18, 0x0C, 0x00000000, PPC_SPE
); //
5845 GEN_SPE(evstwhox
, evstwho
, 0x1A, 0x0C, 0x00000000, PPC_SPE
); //
5846 GEN_SPE(evstwwex
, evstwwe
, 0x1C, 0x0C, 0x00000000, PPC_SPE
); //
5847 GEN_SPE(evstwwox
, evstwwo
, 0x1E, 0x0C, 0x00000000, PPC_SPE
); //
5849 /* Multiply and add - TODO */
5851 GEN_SPE(speundef
, evmhessf
, 0x01, 0x10, 0x00000000, PPC_SPE
);
5852 GEN_SPE(speundef
, evmhossf
, 0x03, 0x10, 0x00000000, PPC_SPE
);
5853 GEN_SPE(evmheumi
, evmhesmi
, 0x04, 0x10, 0x00000000, PPC_SPE
);
5854 GEN_SPE(speundef
, evmhesmf
, 0x05, 0x10, 0x00000000, PPC_SPE
);
5855 GEN_SPE(evmhoumi
, evmhosmi
, 0x06, 0x10, 0x00000000, PPC_SPE
);
5856 GEN_SPE(speundef
, evmhosmf
, 0x07, 0x10, 0x00000000, PPC_SPE
);
5857 GEN_SPE(speundef
, evmhessfa
, 0x11, 0x10, 0x00000000, PPC_SPE
);
5858 GEN_SPE(speundef
, evmhossfa
, 0x13, 0x10, 0x00000000, PPC_SPE
);
5859 GEN_SPE(evmheumia
, evmhesmia
, 0x14, 0x10, 0x00000000, PPC_SPE
);
5860 GEN_SPE(speundef
, evmhesmfa
, 0x15, 0x10, 0x00000000, PPC_SPE
);
5861 GEN_SPE(evmhoumia
, evmhosmia
, 0x16, 0x10, 0x00000000, PPC_SPE
);
5862 GEN_SPE(speundef
, evmhosmfa
, 0x17, 0x10, 0x00000000, PPC_SPE
);
5864 GEN_SPE(speundef
, evmwhssf
, 0x03, 0x11, 0x00000000, PPC_SPE
);
5865 GEN_SPE(evmwlumi
, speundef
, 0x04, 0x11, 0x00000000, PPC_SPE
);
5866 GEN_SPE(evmwhumi
, evmwhsmi
, 0x06, 0x11, 0x00000000, PPC_SPE
);
5867 GEN_SPE(speundef
, evmwhsmf
, 0x07, 0x11, 0x00000000, PPC_SPE
);
5868 GEN_SPE(speundef
, evmwssf
, 0x09, 0x11, 0x00000000, PPC_SPE
);
5869 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, PPC_SPE
);
5870 GEN_SPE(speundef
, evmwsmf
, 0x0D, 0x11, 0x00000000, PPC_SPE
);
5871 GEN_SPE(speundef
, evmwhssfa
, 0x13, 0x11, 0x00000000, PPC_SPE
);
5872 GEN_SPE(evmwlumia
, speundef
, 0x14, 0x11, 0x00000000, PPC_SPE
);
5873 GEN_SPE(evmwhumia
, evmwhsmia
, 0x16, 0x11, 0x00000000, PPC_SPE
);
5874 GEN_SPE(speundef
, evmwhsmfa
, 0x17, 0x11, 0x00000000, PPC_SPE
);
5875 GEN_SPE(speundef
, evmwssfa
, 0x19, 0x11, 0x00000000, PPC_SPE
);
5876 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, PPC_SPE
);
5877 GEN_SPE(speundef
, evmwsmfa
, 0x1D, 0x11, 0x00000000, PPC_SPE
);
5879 GEN_SPE(evadduiaaw
, evaddsiaaw
, 0x00, 0x13, 0x0000F800, PPC_SPE
);
5880 GEN_SPE(evsubfusiaaw
, evsubfssiaaw
, 0x01, 0x13, 0x0000F800, PPC_SPE
);
5881 GEN_SPE(evaddumiaaw
, evaddsmiaaw
, 0x04, 0x13, 0x0000F800, PPC_SPE
);
5882 GEN_SPE(evsubfumiaaw
, evsubfsmiaaw
, 0x05, 0x13, 0x0000F800, PPC_SPE
);
5883 GEN_SPE(evdivws
, evdivwu
, 0x06, 0x13, 0x00000000, PPC_SPE
);
5884 GEN_SPE(evmra
, speundef
, 0x07, 0x13, 0x0000F800, PPC_SPE
);
5886 GEN_SPE(evmheusiaaw
, evmhessiaaw
, 0x00, 0x14, 0x00000000, PPC_SPE
);
5887 GEN_SPE(speundef
, evmhessfaaw
, 0x01, 0x14, 0x00000000, PPC_SPE
);
5888 GEN_SPE(evmhousiaaw
, evmhossiaaw
, 0x02, 0x14, 0x00000000, PPC_SPE
);
5889 GEN_SPE(speundef
, evmhossfaaw
, 0x03, 0x14, 0x00000000, PPC_SPE
);
5890 GEN_SPE(evmheumiaaw
, evmhesmiaaw
, 0x04, 0x14, 0x00000000, PPC_SPE
);
5891 GEN_SPE(speundef
, evmhesmfaaw
, 0x05, 0x14, 0x00000000, PPC_SPE
);
5892 GEN_SPE(evmhoumiaaw
, evmhosmiaaw
, 0x06, 0x14, 0x00000000, PPC_SPE
);
5893 GEN_SPE(speundef
, evmhosmfaaw
, 0x07, 0x14, 0x00000000, PPC_SPE
);
5894 GEN_SPE(evmhegumiaa
, evmhegsmiaa
, 0x14, 0x14, 0x00000000, PPC_SPE
);
5895 GEN_SPE(speundef
, evmhegsmfaa
, 0x15, 0x14, 0x00000000, PPC_SPE
);
5896 GEN_SPE(evmhogumiaa
, evmhogsmiaa
, 0x16, 0x14, 0x00000000, PPC_SPE
);
5897 GEN_SPE(speundef
, evmhogsmfaa
, 0x17, 0x14, 0x00000000, PPC_SPE
);
5899 GEN_SPE(evmwlusiaaw
, evmwlssiaaw
, 0x00, 0x15, 0x00000000, PPC_SPE
);
5900 GEN_SPE(evmwlumiaaw
, evmwlsmiaaw
, 0x04, 0x15, 0x00000000, PPC_SPE
);
5901 GEN_SPE(speundef
, evmwssfaa
, 0x09, 0x15, 0x00000000, PPC_SPE
);
5902 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, PPC_SPE
);
5903 GEN_SPE(speundef
, evmwsmfaa
, 0x0D, 0x15, 0x00000000, PPC_SPE
);
5905 GEN_SPE(evmheusianw
, evmhessianw
, 0x00, 0x16, 0x00000000, PPC_SPE
);
5906 GEN_SPE(speundef
, evmhessfanw
, 0x01, 0x16, 0x00000000, PPC_SPE
);
5907 GEN_SPE(evmhousianw
, evmhossianw
, 0x02, 0x16, 0x00000000, PPC_SPE
);
5908 GEN_SPE(speundef
, evmhossfanw
, 0x03, 0x16, 0x00000000, PPC_SPE
);
5909 GEN_SPE(evmheumianw
, evmhesmianw
, 0x04, 0x16, 0x00000000, PPC_SPE
);
5910 GEN_SPE(speundef
, evmhesmfanw
, 0x05, 0x16, 0x00000000, PPC_SPE
);
5911 GEN_SPE(evmhoumianw
, evmhosmianw
, 0x06, 0x16, 0x00000000, PPC_SPE
);
5912 GEN_SPE(speundef
, evmhosmfanw
, 0x07, 0x16, 0x00000000, PPC_SPE
);
5913 GEN_SPE(evmhegumian
, evmhegsmian
, 0x14, 0x16, 0x00000000, PPC_SPE
);
5914 GEN_SPE(speundef
, evmhegsmfan
, 0x15, 0x16, 0x00000000, PPC_SPE
);
5915 GEN_SPE(evmhigumian
, evmhigsmian
, 0x16, 0x16, 0x00000000, PPC_SPE
);
5916 GEN_SPE(speundef
, evmhogsmfan
, 0x17, 0x16, 0x00000000, PPC_SPE
);
5918 GEN_SPE(evmwlusianw
, evmwlssianw
, 0x00, 0x17, 0x00000000, PPC_SPE
);
5919 GEN_SPE(evmwlumianw
, evmwlsmianw
, 0x04, 0x17, 0x00000000, PPC_SPE
);
5920 GEN_SPE(speundef
, evmwssfan
, 0x09, 0x17, 0x00000000, PPC_SPE
);
5921 GEN_SPE(evmwumian
, evmwsmian
, 0x0C, 0x17, 0x00000000, PPC_SPE
);
5922 GEN_SPE(speundef
, evmwsmfan
, 0x0D, 0x17, 0x00000000, PPC_SPE
);
5925 /*** SPE floating-point extension ***/
5926 #define GEN_SPEFPUOP_CONV(name) \
5927 static always_inline void gen_##name (DisasContext *ctx) \
5929 gen_op_load_gpr64_T0(rB(ctx->opcode)); \
5931 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5934 /* Single precision floating-point vectors operations */
5936 GEN_SPEOP_ARITH2(evfsadd
);
5937 GEN_SPEOP_ARITH2(evfssub
);
5938 GEN_SPEOP_ARITH2(evfsmul
);
5939 GEN_SPEOP_ARITH2(evfsdiv
);
5940 GEN_SPEOP_ARITH1(evfsabs
);
5941 GEN_SPEOP_ARITH1(evfsnabs
);
5942 GEN_SPEOP_ARITH1(evfsneg
);
5944 GEN_SPEFPUOP_CONV(evfscfui
);
5945 GEN_SPEFPUOP_CONV(evfscfsi
);
5946 GEN_SPEFPUOP_CONV(evfscfuf
);
5947 GEN_SPEFPUOP_CONV(evfscfsf
);
5948 GEN_SPEFPUOP_CONV(evfsctui
);
5949 GEN_SPEFPUOP_CONV(evfsctsi
);
5950 GEN_SPEFPUOP_CONV(evfsctuf
);
5951 GEN_SPEFPUOP_CONV(evfsctsf
);
5952 GEN_SPEFPUOP_CONV(evfsctuiz
);
5953 GEN_SPEFPUOP_CONV(evfsctsiz
);
5955 GEN_SPEOP_COMP(evfscmpgt
);
5956 GEN_SPEOP_COMP(evfscmplt
);
5957 GEN_SPEOP_COMP(evfscmpeq
);
5958 GEN_SPEOP_COMP(evfststgt
);
5959 GEN_SPEOP_COMP(evfststlt
);
5960 GEN_SPEOP_COMP(evfststeq
);
5962 /* Opcodes definitions */
5963 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, PPC_SPEFPU
); //
5964 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, PPC_SPEFPU
); //
5965 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, PPC_SPEFPU
); //
5966 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, PPC_SPEFPU
); //
5967 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, PPC_SPEFPU
); //
5968 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, PPC_SPEFPU
); //
5969 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, PPC_SPEFPU
); //
5970 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, PPC_SPEFPU
); //
5971 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, PPC_SPEFPU
); //
5972 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, PPC_SPEFPU
); //
5973 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, PPC_SPEFPU
); //
5974 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, PPC_SPEFPU
); //
5975 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, PPC_SPEFPU
); //
5976 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, PPC_SPEFPU
); //
5978 /* Single precision floating-point operations */
5980 GEN_SPEOP_ARITH2(efsadd
);
5981 GEN_SPEOP_ARITH2(efssub
);
5982 GEN_SPEOP_ARITH2(efsmul
);
5983 GEN_SPEOP_ARITH2(efsdiv
);
5984 GEN_SPEOP_ARITH1(efsabs
);
5985 GEN_SPEOP_ARITH1(efsnabs
);
5986 GEN_SPEOP_ARITH1(efsneg
);
5988 GEN_SPEFPUOP_CONV(efscfui
);
5989 GEN_SPEFPUOP_CONV(efscfsi
);
5990 GEN_SPEFPUOP_CONV(efscfuf
);
5991 GEN_SPEFPUOP_CONV(efscfsf
);
5992 GEN_SPEFPUOP_CONV(efsctui
);
5993 GEN_SPEFPUOP_CONV(efsctsi
);
5994 GEN_SPEFPUOP_CONV(efsctuf
);
5995 GEN_SPEFPUOP_CONV(efsctsf
);
5996 GEN_SPEFPUOP_CONV(efsctuiz
);
5997 GEN_SPEFPUOP_CONV(efsctsiz
);
5998 GEN_SPEFPUOP_CONV(efscfd
);
6000 GEN_SPEOP_COMP(efscmpgt
);
6001 GEN_SPEOP_COMP(efscmplt
);
6002 GEN_SPEOP_COMP(efscmpeq
);
6003 GEN_SPEOP_COMP(efststgt
);
6004 GEN_SPEOP_COMP(efststlt
);
6005 GEN_SPEOP_COMP(efststeq
);
6007 /* Opcodes definitions */
6008 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, PPC_SPEFPU
); //
6009 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, PPC_SPEFPU
); //
6010 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, PPC_SPEFPU
); //
6011 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, PPC_SPEFPU
); //
6012 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, PPC_SPEFPU
); //
6013 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, PPC_SPEFPU
); //
6014 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, PPC_SPEFPU
); //
6015 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, PPC_SPEFPU
); //
6016 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, PPC_SPEFPU
); //
6017 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, PPC_SPEFPU
); //
6018 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, PPC_SPEFPU
); //
6019 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, PPC_SPEFPU
); //
6020 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, PPC_SPEFPU
); //
6021 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, PPC_SPEFPU
); //
6023 /* Double precision floating-point operations */
6025 GEN_SPEOP_ARITH2(efdadd
);
6026 GEN_SPEOP_ARITH2(efdsub
);
6027 GEN_SPEOP_ARITH2(efdmul
);
6028 GEN_SPEOP_ARITH2(efddiv
);
6029 GEN_SPEOP_ARITH1(efdabs
);
6030 GEN_SPEOP_ARITH1(efdnabs
);
6031 GEN_SPEOP_ARITH1(efdneg
);
6034 GEN_SPEFPUOP_CONV(efdcfui
);
6035 GEN_SPEFPUOP_CONV(efdcfsi
);
6036 GEN_SPEFPUOP_CONV(efdcfuf
);
6037 GEN_SPEFPUOP_CONV(efdcfsf
);
6038 GEN_SPEFPUOP_CONV(efdctui
);
6039 GEN_SPEFPUOP_CONV(efdctsi
);
6040 GEN_SPEFPUOP_CONV(efdctuf
);
6041 GEN_SPEFPUOP_CONV(efdctsf
);
6042 GEN_SPEFPUOP_CONV(efdctuiz
);
6043 GEN_SPEFPUOP_CONV(efdctsiz
);
6044 GEN_SPEFPUOP_CONV(efdcfs
);
6045 GEN_SPEFPUOP_CONV(efdcfuid
);
6046 GEN_SPEFPUOP_CONV(efdcfsid
);
6047 GEN_SPEFPUOP_CONV(efdctuidz
);
6048 GEN_SPEFPUOP_CONV(efdctsidz
);
6050 GEN_SPEOP_COMP(efdcmpgt
);
6051 GEN_SPEOP_COMP(efdcmplt
);
6052 GEN_SPEOP_COMP(efdcmpeq
);
6053 GEN_SPEOP_COMP(efdtstgt
);
6054 GEN_SPEOP_COMP(efdtstlt
);
6055 GEN_SPEOP_COMP(efdtsteq
);
6057 /* Opcodes definitions */
6058 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, PPC_SPEFPU
); //
6059 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, PPC_SPEFPU
); //
6060 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, PPC_SPEFPU
); //
6061 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, PPC_SPEFPU
); //
6062 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, PPC_SPEFPU
); //
6063 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, PPC_SPEFPU
); //
6064 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, PPC_SPEFPU
); //
6065 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, PPC_SPEFPU
); //
6066 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, PPC_SPEFPU
); //
6067 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, PPC_SPEFPU
); //
6068 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, PPC_SPEFPU
); //
6069 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, PPC_SPEFPU
); //
6070 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, PPC_SPEFPU
); //
6071 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, PPC_SPEFPU
); //
6072 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, PPC_SPEFPU
); //
6073 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, PPC_SPEFPU
); //
6075 /* End opcode list */
6076 GEN_OPCODE_MARK(end
);
6078 #include "translate_init.c"
6079 #include "helper_regs.h"
6081 /*****************************************************************************/
6082 /* Misc PowerPC helpers */
6083 void cpu_dump_state (CPUState
*env
, FILE *f
,
6084 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6092 cpu_fprintf(f
, "NIP " ADDRX
" LR " ADDRX
" CTR " ADDRX
" XER %08x\n",
6093 env
->nip
, env
->lr
, env
->ctr
, hreg_load_xer(env
));
6094 cpu_fprintf(f
, "MSR " ADDRX
" HID0 " ADDRX
" HF " ADDRX
" idx %d\n",
6095 env
->msr
, env
->spr
[SPR_HID0
], env
->hflags
, env
->mmu_idx
);
6096 #if !defined(NO_TIMER_DUMP)
6097 cpu_fprintf(f
, "TB %08x %08x "
6098 #if !defined(CONFIG_USER_ONLY)
6102 cpu_ppc_load_tbu(env
), cpu_ppc_load_tbl(env
)
6103 #if !defined(CONFIG_USER_ONLY)
6104 , cpu_ppc_load_decr(env
)
6108 for (i
= 0; i
< 32; i
++) {
6109 if ((i
& (RGPL
- 1)) == 0)
6110 cpu_fprintf(f
, "GPR%02d", i
);
6111 cpu_fprintf(f
, " " REGX
, ppc_dump_gpr(env
, i
));
6112 if ((i
& (RGPL
- 1)) == (RGPL
- 1))
6113 cpu_fprintf(f
, "\n");
6115 cpu_fprintf(f
, "CR ");
6116 for (i
= 0; i
< 8; i
++)
6117 cpu_fprintf(f
, "%01x", env
->crf
[i
]);
6118 cpu_fprintf(f
, " [");
6119 for (i
= 0; i
< 8; i
++) {
6121 if (env
->crf
[i
] & 0x08)
6123 else if (env
->crf
[i
] & 0x04)
6125 else if (env
->crf
[i
] & 0x02)
6127 cpu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
6129 cpu_fprintf(f
, " ] RES " ADDRX
"\n", env
->reserve
);
6130 for (i
= 0; i
< 32; i
++) {
6131 if ((i
& (RFPL
- 1)) == 0)
6132 cpu_fprintf(f
, "FPR%02d", i
);
6133 cpu_fprintf(f
, " %016" PRIx64
, *((uint64_t *)&env
->fpr
[i
]));
6134 if ((i
& (RFPL
- 1)) == (RFPL
- 1))
6135 cpu_fprintf(f
, "\n");
6137 #if !defined(CONFIG_USER_ONLY)
6138 cpu_fprintf(f
, "SRR0 " ADDRX
" SRR1 " ADDRX
" SDR1 " ADDRX
"\n",
6139 env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
], env
->sdr1
);
6146 void cpu_dump_statistics (CPUState
*env
, FILE*f
,
6147 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6150 #if defined(DO_PPC_STATISTICS)
6151 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
6155 for (op1
= 0; op1
< 64; op1
++) {
6157 if (is_indirect_opcode(handler
)) {
6158 t2
= ind_table(handler
);
6159 for (op2
= 0; op2
< 32; op2
++) {
6161 if (is_indirect_opcode(handler
)) {
6162 t3
= ind_table(handler
);
6163 for (op3
= 0; op3
< 32; op3
++) {
6165 if (handler
->count
== 0)
6167 cpu_fprintf(f
, "%02x %02x %02x (%02x %04d) %16s: "
6169 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
6171 handler
->count
, handler
->count
);
6174 if (handler
->count
== 0)
6176 cpu_fprintf(f
, "%02x %02x (%02x %04d) %16s: "
6178 op1
, op2
, op1
, op2
, handler
->oname
,
6179 handler
->count
, handler
->count
);
6183 if (handler
->count
== 0)
6185 cpu_fprintf(f
, "%02x (%02x ) %16s: %016llx %lld\n",
6186 op1
, op1
, handler
->oname
,
6187 handler
->count
, handler
->count
);
6193 /*****************************************************************************/
6194 static always_inline
void gen_intermediate_code_internal (CPUState
*env
,
6195 TranslationBlock
*tb
,
6198 DisasContext ctx
, *ctxp
= &ctx
;
6199 opc_handler_t
**table
, *handler
;
6200 target_ulong pc_start
;
6201 uint16_t *gen_opc_end
;
6202 int supervisor
, little_endian
;
6208 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
6209 #if defined(OPTIMIZE_FPRF_UPDATE)
6210 gen_fprf_ptr
= gen_fprf_buf
;
6214 ctx
.exception
= POWERPC_EXCP_NONE
;
6215 ctx
.spr_cb
= env
->spr_cb
;
6216 supervisor
= env
->mmu_idx
;
6217 #if !defined(CONFIG_USER_ONLY)
6218 ctx
.supervisor
= supervisor
;
6220 little_endian
= env
->hflags
& (1 << MSR_LE
) ? 1 : 0;
6221 #if defined(TARGET_PPC64)
6222 ctx
.sf_mode
= msr_sf
;
6223 ctx
.mem_idx
= (supervisor
<< 2) | (msr_sf
<< 1) | little_endian
;
6225 ctx
.mem_idx
= (supervisor
<< 1) | little_endian
;
6227 ctx
.dcache_line_size
= env
->dcache_line_size
;
6228 ctx
.fpu_enabled
= msr_fp
;
6229 if ((env
->flags
& POWERPC_FLAG_SPE
) && msr_spe
)
6230 ctx
.spe_enabled
= msr_spe
;
6232 ctx
.spe_enabled
= 0;
6233 if ((env
->flags
& POWERPC_FLAG_VRE
) && msr_vr
)
6234 ctx
.altivec_enabled
= msr_vr
;
6236 ctx
.altivec_enabled
= 0;
6237 if ((env
->flags
& POWERPC_FLAG_SE
) && msr_se
)
6238 ctx
.singlestep_enabled
= CPU_SINGLE_STEP
;
6240 ctx
.singlestep_enabled
= 0;
6241 if ((env
->flags
& POWERPC_FLAG_BE
) && msr_be
)
6242 ctx
.singlestep_enabled
|= CPU_BRANCH_STEP
;
6243 if (unlikely(env
->singlestep_enabled
))
6244 ctx
.singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
6245 #if defined (DO_SINGLE_STEP) && 0
6246 /* Single step trace mode */
6250 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
6252 max_insns
= CF_COUNT_MASK
;
6255 /* Set env in case of segfault during code fetch */
6256 while (ctx
.exception
== POWERPC_EXCP_NONE
&& gen_opc_ptr
< gen_opc_end
) {
6257 if (unlikely(env
->nb_breakpoints
> 0)) {
6258 for (j
= 0; j
< env
->nb_breakpoints
; j
++) {
6259 if (env
->breakpoints
[j
] == ctx
.nip
) {
6260 gen_update_nip(&ctx
, ctx
.nip
);
6266 if (unlikely(search_pc
)) {
6267 j
= gen_opc_ptr
- gen_opc_buf
;
6271 gen_opc_instr_start
[lj
++] = 0;
6272 gen_opc_pc
[lj
] = ctx
.nip
;
6273 gen_opc_instr_start
[lj
] = 1;
6274 gen_opc_icount
[lj
] = num_insns
;
6277 #if defined PPC_DEBUG_DISAS
6278 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
6279 fprintf(logfile
, "----------------\n");
6280 fprintf(logfile
, "nip=" ADDRX
" super=%d ir=%d\n",
6281 ctx
.nip
, supervisor
, (int)msr_ir
);
6284 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
6286 if (unlikely(little_endian
)) {
6287 ctx
.opcode
= bswap32(ldl_code(ctx
.nip
));
6289 ctx
.opcode
= ldl_code(ctx
.nip
);
6291 #if defined PPC_DEBUG_DISAS
6292 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
6293 fprintf(logfile
, "translate opcode %08x (%02x %02x %02x) (%s)\n",
6294 ctx
.opcode
, opc1(ctx
.opcode
), opc2(ctx
.opcode
),
6295 opc3(ctx
.opcode
), little_endian
? "little" : "big");
6299 table
= env
->opcodes
;
6301 handler
= table
[opc1(ctx
.opcode
)];
6302 if (is_indirect_opcode(handler
)) {
6303 table
= ind_table(handler
);
6304 handler
= table
[opc2(ctx
.opcode
)];
6305 if (is_indirect_opcode(handler
)) {
6306 table
= ind_table(handler
);
6307 handler
= table
[opc3(ctx
.opcode
)];
6310 /* Is opcode *REALLY* valid ? */
6311 if (unlikely(handler
->handler
== &gen_invalid
)) {
6312 if (loglevel
!= 0) {
6313 fprintf(logfile
, "invalid/unsupported opcode: "
6314 "%02x - %02x - %02x (%08x) " ADDRX
" %d\n",
6315 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
6316 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
6318 printf("invalid/unsupported opcode: "
6319 "%02x - %02x - %02x (%08x) " ADDRX
" %d\n",
6320 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
6321 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
6324 if (unlikely((ctx
.opcode
& handler
->inval
) != 0)) {
6325 if (loglevel
!= 0) {
6326 fprintf(logfile
, "invalid bits: %08x for opcode: "
6327 "%02x - %02x - %02x (%08x) " ADDRX
"\n",
6328 ctx
.opcode
& handler
->inval
, opc1(ctx
.opcode
),
6329 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
6330 ctx
.opcode
, ctx
.nip
- 4);
6332 printf("invalid bits: %08x for opcode: "
6333 "%02x - %02x - %02x (%08x) " ADDRX
"\n",
6334 ctx
.opcode
& handler
->inval
, opc1(ctx
.opcode
),
6335 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
6336 ctx
.opcode
, ctx
.nip
- 4);
6338 GEN_EXCP_INVAL(ctxp
);
6342 (*(handler
->handler
))(&ctx
);
6343 #if defined(DO_PPC_STATISTICS)
6346 /* Check trace mode exceptions */
6347 if (unlikely(ctx
.singlestep_enabled
& CPU_SINGLE_STEP
&&
6348 (ctx
.nip
<= 0x100 || ctx
.nip
> 0xF00) &&
6349 ctx
.exception
!= POWERPC_SYSCALL
&&
6350 ctx
.exception
!= POWERPC_EXCP_TRAP
&&
6351 ctx
.exception
!= POWERPC_EXCP_BRANCH
)) {
6352 GEN_EXCP(ctxp
, POWERPC_EXCP_TRACE
, 0);
6353 } else if (unlikely(((ctx
.nip
& (TARGET_PAGE_SIZE
- 1)) == 0) ||
6354 (env
->singlestep_enabled
) ||
6355 num_insns
>= max_insns
)) {
6356 /* if we reach a page boundary or are single stepping, stop
6361 #if defined (DO_SINGLE_STEP)
6365 if (tb
->cflags
& CF_LAST_IO
)
6367 if (ctx
.exception
== POWERPC_EXCP_NONE
) {
6368 gen_goto_tb(&ctx
, 0, ctx
.nip
);
6369 } else if (ctx
.exception
!= POWERPC_EXCP_BRANCH
) {
6370 if (unlikely(env
->singlestep_enabled
)) {
6371 gen_update_nip(&ctx
, ctx
.nip
);
6374 /* Generate the return instruction */
6377 gen_icount_end(tb
, num_insns
);
6378 *gen_opc_ptr
= INDEX_op_end
;
6379 if (unlikely(search_pc
)) {
6380 j
= gen_opc_ptr
- gen_opc_buf
;
6383 gen_opc_instr_start
[lj
++] = 0;
6385 tb
->size
= ctx
.nip
- pc_start
;
6386 tb
->icount
= num_insns
;
6388 #if defined(DEBUG_DISAS)
6389 if (loglevel
& CPU_LOG_TB_CPU
) {
6390 fprintf(logfile
, "---------------- excp: %04x\n", ctx
.exception
);
6391 cpu_dump_state(env
, logfile
, fprintf
, 0);
6393 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
6395 flags
= env
->bfd_mach
;
6396 flags
|= little_endian
<< 16;
6397 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
6398 target_disas(logfile
, pc_start
, ctx
.nip
- pc_start
, flags
);
6399 fprintf(logfile
, "\n");
6404 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
6406 gen_intermediate_code_internal(env
, tb
, 0);
6409 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
6411 gen_intermediate_code_internal(env
, tb
, 1);
6414 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
6415 unsigned long searched_pc
, int pc_pos
, void *puc
)
6418 /* for PPC, we need to look at the micro operation to get the
6420 env
->nip
= gen_opc_pc
[pc_pos
];
6421 c
= gen_opc_buf
[pc_pos
];
6423 #if defined(CONFIG_USER_ONLY)
6425 case INDEX_op_ ## op ## _raw
6428 case INDEX_op_ ## op ## _user:\
6429 case INDEX_op_ ## op ## _kernel:\
6430 case INDEX_op_ ## op ## _hypv
6437 type
= ACCESS_FLOAT
;
6453 env
->access_type
= type
;