2 * PowerPC emulation for qemu: main translation routines.
4 * Copyright (c) 2003-2007 Jocelyn Mayer
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 /* Include definitions for instructions classes and implementations flags */
31 //#define DO_SINGLE_STEP
32 //#define PPC_DEBUG_DISAS
33 //#define DEBUG_MEMORY_ACCESSES
34 //#define DO_PPC_STATISTICS
36 /*****************************************************************************/
37 /* Code translation helpers */
38 #if defined(USE_DIRECT_JUMP)
41 #define TBPARAM(x) (long)(x)
45 #define DEF(s, n, copy_size) INDEX_op_ ## s,
51 static uint16_t *gen_opc_ptr
;
52 static uint32_t *gen_opparam_ptr
;
56 static always_inline
void gen_set_T0 (target_ulong val
)
58 #if defined(TARGET_PPC64)
60 gen_op_set_T0_64(val
>> 32, val
);
66 static always_inline
void gen_set_T1 (target_ulong val
)
68 #if defined(TARGET_PPC64)
70 gen_op_set_T1_64(val
>> 32, val
);
76 #define GEN8(func, NAME) \
77 static GenOpFunc *NAME ## _table [8] = { \
78 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
79 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
81 static always_inline void func (int n) \
83 NAME ## _table[n](); \
86 #define GEN16(func, NAME) \
87 static GenOpFunc *NAME ## _table [16] = { \
88 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
89 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
90 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
91 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
93 static always_inline void func (int n) \
95 NAME ## _table[n](); \
98 #define GEN32(func, NAME) \
99 static GenOpFunc *NAME ## _table [32] = { \
100 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
101 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
102 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
103 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
104 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
105 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
106 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
107 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
109 static always_inline void func (int n) \
111 NAME ## _table[n](); \
114 /* Condition register moves */
115 GEN8(gen_op_load_crf_T0
, gen_op_load_crf_T0_crf
);
116 GEN8(gen_op_load_crf_T1
, gen_op_load_crf_T1_crf
);
117 GEN8(gen_op_store_T0_crf
, gen_op_store_T0_crf_crf
);
118 GEN8(gen_op_store_T1_crf
, gen_op_store_T1_crf_crf
);
120 /* Floating point condition and status register moves */
121 GEN8(gen_op_load_fpscr_T0
, gen_op_load_fpscr_T0_fpscr
);
122 GEN8(gen_op_store_T0_fpscr
, gen_op_store_T0_fpscr_fpscr
);
123 GEN8(gen_op_clear_fpscr
, gen_op_clear_fpscr_fpscr
);
124 static always_inline
void gen_op_store_T0_fpscri (int n
, uint8_t param
)
126 gen_op_set_T0(param
);
127 gen_op_store_T0_fpscr(n
);
130 /* General purpose registers moves */
131 GEN32(gen_op_load_gpr_T0
, gen_op_load_gpr_T0_gpr
);
132 GEN32(gen_op_load_gpr_T1
, gen_op_load_gpr_T1_gpr
);
133 GEN32(gen_op_load_gpr_T2
, gen_op_load_gpr_T2_gpr
);
135 GEN32(gen_op_store_T0_gpr
, gen_op_store_T0_gpr_gpr
);
136 GEN32(gen_op_store_T1_gpr
, gen_op_store_T1_gpr_gpr
);
138 GEN32(gen_op_store_T2_gpr
, gen_op_store_T2_gpr_gpr
);
141 /* floating point registers moves */
142 GEN32(gen_op_load_fpr_FT0
, gen_op_load_fpr_FT0_fpr
);
143 GEN32(gen_op_load_fpr_FT1
, gen_op_load_fpr_FT1_fpr
);
144 GEN32(gen_op_load_fpr_FT2
, gen_op_load_fpr_FT2_fpr
);
145 GEN32(gen_op_store_FT0_fpr
, gen_op_store_FT0_fpr_fpr
);
146 GEN32(gen_op_store_FT1_fpr
, gen_op_store_FT1_fpr_fpr
);
148 GEN32(gen_op_store_FT2_fpr
, gen_op_store_FT2_fpr_fpr
);
151 /* internal defines */
152 typedef struct DisasContext
{
153 struct TranslationBlock
*tb
;
157 /* Routine used to access memory */
159 /* Translation flags */
160 #if !defined(CONFIG_USER_ONLY)
163 #if defined(TARGET_PPC64)
168 #if defined(TARGET_PPCEMB)
171 ppc_spr_t
*spr_cb
; /* Needed to check rights for mfspr/mtspr */
172 int singlestep_enabled
;
173 int dcache_line_size
;
176 struct opc_handler_t
{
179 /* instruction type */
182 void (*handler
)(DisasContext
*ctx
);
183 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
184 const unsigned char *oname
;
186 #if defined(DO_PPC_STATISTICS)
191 static always_inline
void gen_set_Rc0 (DisasContext
*ctx
)
193 #if defined(TARGET_PPC64)
202 static always_inline
void gen_update_nip (DisasContext
*ctx
, target_ulong nip
)
204 #if defined(TARGET_PPC64)
206 gen_op_update_nip_64(nip
>> 32, nip
);
209 gen_op_update_nip(nip
);
212 #define GEN_EXCP(ctx, excp, error) \
214 if ((ctx)->exception == POWERPC_EXCP_NONE) { \
215 gen_update_nip(ctx, (ctx)->nip); \
217 gen_op_raise_exception_err((excp), (error)); \
218 ctx->exception = (excp); \
221 #define GEN_EXCP_INVAL(ctx) \
222 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
223 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_INVAL)
225 #define GEN_EXCP_PRIVOPC(ctx) \
226 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
227 POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_OPC)
229 #define GEN_EXCP_PRIVREG(ctx) \
230 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
231 POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_REG)
233 #define GEN_EXCP_NO_FP(ctx) \
234 GEN_EXCP(ctx, POWERPC_EXCP_FPU, 0)
236 #define GEN_EXCP_NO_AP(ctx) \
237 GEN_EXCP(ctx, POWERPC_EXCP_APU, 0)
239 #define GEN_EXCP_NO_VR(ctx) \
240 GEN_EXCP(ctx, POWERPC_EXCP_VPU, 0)
242 /* Stop translation */
243 static always_inline
void GEN_STOP (DisasContext
*ctx
)
245 gen_update_nip(ctx
, ctx
->nip
);
246 ctx
->exception
= POWERPC_EXCP_STOP
;
249 /* No need to update nip here, as execution flow will change */
250 static always_inline
void GEN_SYNC (DisasContext
*ctx
)
252 ctx
->exception
= POWERPC_EXCP_SYNC
;
255 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
256 static void gen_##name (DisasContext *ctx); \
257 GEN_OPCODE(name, opc1, opc2, opc3, inval, type); \
258 static void gen_##name (DisasContext *ctx)
260 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
261 static void gen_##name (DisasContext *ctx); \
262 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type); \
263 static void gen_##name (DisasContext *ctx)
266 typedef struct opcode_t
{
267 unsigned char opc1
, opc2
, opc3
;
268 #if HOST_LONG_BITS == 64 /* Explicitely align to 64 bits */
269 unsigned char pad
[5];
271 unsigned char pad
[1];
273 opc_handler_t handler
;
274 const unsigned char *oname
;
277 /*****************************************************************************/
278 /*** Instruction decoding ***/
279 #define EXTRACT_HELPER(name, shift, nb) \
280 static always_inline uint32_t name (uint32_t opcode) \
282 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
285 #define EXTRACT_SHELPER(name, shift, nb) \
286 static always_inline int32_t name (uint32_t opcode) \
288 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
292 EXTRACT_HELPER(opc1
, 26, 6);
294 EXTRACT_HELPER(opc2
, 1, 5);
296 EXTRACT_HELPER(opc3
, 6, 5);
297 /* Update Cr0 flags */
298 EXTRACT_HELPER(Rc
, 0, 1);
300 EXTRACT_HELPER(rD
, 21, 5);
302 EXTRACT_HELPER(rS
, 21, 5);
304 EXTRACT_HELPER(rA
, 16, 5);
306 EXTRACT_HELPER(rB
, 11, 5);
308 EXTRACT_HELPER(rC
, 6, 5);
310 EXTRACT_HELPER(crfD
, 23, 3);
311 EXTRACT_HELPER(crfS
, 18, 3);
312 EXTRACT_HELPER(crbD
, 21, 5);
313 EXTRACT_HELPER(crbA
, 16, 5);
314 EXTRACT_HELPER(crbB
, 11, 5);
316 EXTRACT_HELPER(_SPR
, 11, 10);
317 static always_inline
uint32_t SPR (uint32_t opcode
)
319 uint32_t sprn
= _SPR(opcode
);
321 return ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
323 /*** Get constants ***/
324 EXTRACT_HELPER(IMM
, 12, 8);
325 /* 16 bits signed immediate value */
326 EXTRACT_SHELPER(SIMM
, 0, 16);
327 /* 16 bits unsigned immediate value */
328 EXTRACT_HELPER(UIMM
, 0, 16);
330 EXTRACT_HELPER(NB
, 11, 5);
332 EXTRACT_HELPER(SH
, 11, 5);
334 EXTRACT_HELPER(MB
, 6, 5);
336 EXTRACT_HELPER(ME
, 1, 5);
338 EXTRACT_HELPER(TO
, 21, 5);
340 EXTRACT_HELPER(CRM
, 12, 8);
341 EXTRACT_HELPER(FM
, 17, 8);
342 EXTRACT_HELPER(SR
, 16, 4);
343 EXTRACT_HELPER(FPIMM
, 20, 4);
345 /*** Jump target decoding ***/
347 EXTRACT_SHELPER(d
, 0, 16);
348 /* Immediate address */
349 static always_inline target_ulong
LI (uint32_t opcode
)
351 return (opcode
>> 0) & 0x03FFFFFC;
354 static always_inline
uint32_t BD (uint32_t opcode
)
356 return (opcode
>> 0) & 0xFFFC;
359 EXTRACT_HELPER(BO
, 21, 5);
360 EXTRACT_HELPER(BI
, 16, 5);
361 /* Absolute/relative address */
362 EXTRACT_HELPER(AA
, 1, 1);
364 EXTRACT_HELPER(LK
, 0, 1);
366 /* Create a mask between <start> and <end> bits */
367 static always_inline target_ulong
MASK (uint32_t start
, uint32_t end
)
371 #if defined(TARGET_PPC64)
372 if (likely(start
== 0)) {
373 ret
= (uint64_t)(-1ULL) << (63 - end
);
374 } else if (likely(end
== 63)) {
375 ret
= (uint64_t)(-1ULL) >> start
;
378 if (likely(start
== 0)) {
379 ret
= (uint32_t)(-1ULL) << (31 - end
);
380 } else if (likely(end
== 31)) {
381 ret
= (uint32_t)(-1ULL) >> start
;
385 ret
= (((target_ulong
)(-1ULL)) >> (start
)) ^
386 (((target_ulong
)(-1ULL) >> (end
)) >> 1);
387 if (unlikely(start
> end
))
394 /*****************************************************************************/
395 /* PowerPC Instructions types definitions */
397 PPC_NONE
= 0x0000000000000000ULL
,
398 /* PowerPC base instructions set */
399 PPC_INSNS_BASE
= 0x0000000000000001ULL
,
400 /* integer operations instructions */
401 #define PPC_INTEGER PPC_INSNS_BASE
402 /* flow control instructions */
403 #define PPC_FLOW PPC_INSNS_BASE
404 /* virtual memory instructions */
405 #define PPC_MEM PPC_INSNS_BASE
406 /* ld/st with reservation instructions */
407 #define PPC_RES PPC_INSNS_BASE
408 /* cache control instructions */
409 #define PPC_CACHE PPC_INSNS_BASE
410 /* spr/msr access instructions */
411 #define PPC_MISC PPC_INSNS_BASE
412 /* Optional floating point instructions */
413 PPC_FLOAT
= 0x0000000000000002ULL
,
414 PPC_FLOAT_FSQRT
= 0x0000000000000004ULL
,
415 PPC_FLOAT_FRES
= 0x0000000000000008ULL
,
416 PPC_FLOAT_FRSQRTE
= 0x0000000000000010ULL
,
417 PPC_FLOAT_FSEL
= 0x0000000000000020ULL
,
418 PPC_FLOAT_STFIWX
= 0x0000000000000040ULL
,
419 /* external control instructions */
420 PPC_EXTERN
= 0x0000000000000080ULL
,
421 /* segment register access instructions */
422 PPC_SEGMENT
= 0x0000000000000100ULL
,
423 /* Optional cache control instruction */
424 PPC_CACHE_DCBA
= 0x0000000000000200ULL
,
425 /* Optional memory control instructions */
426 PPC_MEM_TLBIA
= 0x0000000000000400ULL
,
427 PPC_MEM_TLBIE
= 0x0000000000000800ULL
,
428 PPC_MEM_TLBSYNC
= 0x0000000000001000ULL
,
430 PPC_MEM_SYNC
= 0x0000000000002000ULL
,
431 /* PowerPC 6xx TLB management instructions */
432 PPC_6xx_TLB
= 0x0000000000004000ULL
,
433 /* Altivec support */
434 PPC_ALTIVEC
= 0x0000000000008000ULL
,
435 /* Time base mftb instruction */
436 PPC_MFTB
= 0x0000000000010000ULL
,
437 /* Embedded PowerPC dedicated instructions */
438 PPC_EMB_COMMON
= 0x0000000000020000ULL
,
439 /* PowerPC 40x exception model */
440 PPC_40x_EXCP
= 0x0000000000040000ULL
,
441 /* PowerPC 40x TLB management instructions */
442 PPC_40x_TLB
= 0x0000000000080000ULL
,
443 /* PowerPC 405 Mac instructions */
444 PPC_405_MAC
= 0x0000000000100000ULL
,
445 /* PowerPC 440 specific instructions */
446 PPC_440_SPEC
= 0x0000000000200000ULL
,
447 /* Power-to-PowerPC bridge (601) */
448 PPC_POWER_BR
= 0x0000000000400000ULL
,
449 /* PowerPC 602 specific */
450 PPC_602_SPEC
= 0x0000000000800000ULL
,
451 /* Deprecated instructions */
452 /* Original POWER instruction set */
453 PPC_POWER
= 0x0000000001000000ULL
,
454 /* POWER2 instruction set extension */
455 PPC_POWER2
= 0x0000000002000000ULL
,
456 /* Power RTC support */
457 PPC_POWER_RTC
= 0x0000000004000000ULL
,
458 /* 64 bits PowerPC instruction set */
459 PPC_64B
= 0x0000000008000000ULL
,
460 /* 64 bits hypervisor extensions */
461 PPC_64H
= 0x0000000010000000ULL
,
462 /* segment register access instructions for PowerPC 64 "bridge" */
463 PPC_SEGMENT_64B
= 0x0000000020000000ULL
,
464 /* BookE (embedded) PowerPC specification */
465 PPC_BOOKE
= 0x0000000040000000ULL
,
467 PPC_MEM_EIEIO
= 0x0000000080000000ULL
,
468 /* e500 vector instructions */
469 PPC_E500_VECTOR
= 0x0000000100000000ULL
,
470 /* PowerPC 4xx dedicated instructions */
471 PPC_4xx_COMMON
= 0x0000000200000000ULL
,
472 /* PowerPC 2.03 specification extensions */
473 PPC_203
= 0x0000000400000000ULL
,
474 /* PowerPC 2.03 SPE extension */
475 PPC_SPE
= 0x0000000800000000ULL
,
476 /* PowerPC 2.03 SPE floating-point extension */
477 PPC_SPEFPU
= 0x0000001000000000ULL
,
479 PPC_SLBI
= 0x0000002000000000ULL
,
480 /* PowerPC 40x ibct instructions */
481 PPC_40x_ICBT
= 0x0000004000000000ULL
,
482 /* PowerPC 74xx TLB management instructions */
483 PPC_74xx_TLB
= 0x0000008000000000ULL
,
484 /* More BookE (embedded) instructions... */
485 PPC_BOOKE_EXT
= 0x0000010000000000ULL
,
486 /* rfmci is not implemented in all BookE PowerPC */
487 PPC_RFMCI
= 0x0000020000000000ULL
,
488 /* user-mode DCR access, implemented in PowerPC 460 */
489 PPC_DCRUX
= 0x0000040000000000ULL
,
490 /* New floating-point extensions (PowerPC 2.0x) */
491 PPC_FLOAT_EXT
= 0x0000080000000000ULL
,
492 /* New wait instruction (PowerPC 2.0x) */
493 PPC_WAIT
= 0x0000100000000000ULL
,
494 /* New 64 bits extensions (PowerPC 2.0x) */
495 PPC_64BX
= 0x0000200000000000ULL
,
496 /* dcbz instruction with fixed cache line size */
497 PPC_CACHE_DCBZ
= 0x0000400000000000ULL
,
498 /* dcbz instruction with tunable cache line size */
499 PPC_CACHE_DCBZT
= 0x0000800000000000ULL
,
502 /*****************************************************************************/
503 /* PowerPC instructions table */
504 #if HOST_LONG_BITS == 64
509 #if defined(__APPLE__)
510 #define OPCODES_SECTION \
511 __attribute__ ((section("__TEXT,__opcodes"), unused, aligned (OPC_ALIGN) ))
513 #define OPCODES_SECTION \
514 __attribute__ ((section(".opcodes"), unused, aligned (OPC_ALIGN) ))
517 #if defined(DO_PPC_STATISTICS)
518 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
519 OPCODES_SECTION opcode_t opc_##name = { \
527 .handler = &gen_##name, \
528 .oname = stringify(name), \
530 .oname = stringify(name), \
532 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
533 OPCODES_SECTION opcode_t opc_##name = { \
541 .handler = &gen_##name, \
547 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
548 OPCODES_SECTION opcode_t opc_##name = { \
556 .handler = &gen_##name, \
558 .oname = stringify(name), \
560 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
561 OPCODES_SECTION opcode_t opc_##name = { \
569 .handler = &gen_##name, \
575 #define GEN_OPCODE_MARK(name) \
576 OPCODES_SECTION opcode_t opc_##name = { \
582 .inval = 0x00000000, \
586 .oname = stringify(name), \
589 /* Start opcode list */
590 GEN_OPCODE_MARK(start
);
592 /* Invalid instruction */
593 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
)
598 static opc_handler_t invalid_handler
= {
601 .handler
= gen_invalid
,
604 /*** Integer arithmetic ***/
605 #define __GEN_INT_ARITH2(name, opc1, opc2, opc3, inval, type) \
606 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
608 gen_op_load_gpr_T0(rA(ctx->opcode)); \
609 gen_op_load_gpr_T1(rB(ctx->opcode)); \
611 gen_op_store_T0_gpr(rD(ctx->opcode)); \
612 if (unlikely(Rc(ctx->opcode) != 0)) \
616 #define __GEN_INT_ARITH2_O(name, opc1, opc2, opc3, inval, type) \
617 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
619 gen_op_load_gpr_T0(rA(ctx->opcode)); \
620 gen_op_load_gpr_T1(rB(ctx->opcode)); \
622 gen_op_store_T0_gpr(rD(ctx->opcode)); \
623 if (unlikely(Rc(ctx->opcode) != 0)) \
627 #define __GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
628 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
630 gen_op_load_gpr_T0(rA(ctx->opcode)); \
632 gen_op_store_T0_gpr(rD(ctx->opcode)); \
633 if (unlikely(Rc(ctx->opcode) != 0)) \
636 #define __GEN_INT_ARITH1_O(name, opc1, opc2, opc3, type) \
637 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
639 gen_op_load_gpr_T0(rA(ctx->opcode)); \
641 gen_op_store_T0_gpr(rD(ctx->opcode)); \
642 if (unlikely(Rc(ctx->opcode) != 0)) \
646 /* Two operands arithmetic functions */
647 #define GEN_INT_ARITH2(name, opc1, opc2, opc3, type) \
648 __GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000000, type) \
649 __GEN_INT_ARITH2_O(name##o, opc1, opc2, opc3 | 0x10, 0x00000000, type)
651 /* Two operands arithmetic functions with no overflow allowed */
652 #define GEN_INT_ARITHN(name, opc1, opc2, opc3, type) \
653 __GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000400, type)
655 /* One operand arithmetic functions */
656 #define GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
657 __GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
658 __GEN_INT_ARITH1_O(name##o, opc1, opc2, opc3 | 0x10, type)
660 #if defined(TARGET_PPC64)
661 #define __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, inval, type) \
662 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
664 gen_op_load_gpr_T0(rA(ctx->opcode)); \
665 gen_op_load_gpr_T1(rB(ctx->opcode)); \
667 gen_op_##name##_64(); \
670 gen_op_store_T0_gpr(rD(ctx->opcode)); \
671 if (unlikely(Rc(ctx->opcode) != 0)) \
675 #define __GEN_INT_ARITH2_O_64(name, opc1, opc2, opc3, inval, type) \
676 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
678 gen_op_load_gpr_T0(rA(ctx->opcode)); \
679 gen_op_load_gpr_T1(rB(ctx->opcode)); \
681 gen_op_##name##_64(); \
684 gen_op_store_T0_gpr(rD(ctx->opcode)); \
685 if (unlikely(Rc(ctx->opcode) != 0)) \
689 #define __GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
690 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
692 gen_op_load_gpr_T0(rA(ctx->opcode)); \
694 gen_op_##name##_64(); \
697 gen_op_store_T0_gpr(rD(ctx->opcode)); \
698 if (unlikely(Rc(ctx->opcode) != 0)) \
701 #define __GEN_INT_ARITH1_O_64(name, opc1, opc2, opc3, type) \
702 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
704 gen_op_load_gpr_T0(rA(ctx->opcode)); \
706 gen_op_##name##_64(); \
709 gen_op_store_T0_gpr(rD(ctx->opcode)); \
710 if (unlikely(Rc(ctx->opcode) != 0)) \
714 /* Two operands arithmetic functions */
715 #define GEN_INT_ARITH2_64(name, opc1, opc2, opc3, type) \
716 __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, 0x00000000, type) \
717 __GEN_INT_ARITH2_O_64(name##o, opc1, opc2, opc3 | 0x10, 0x00000000, type)
719 /* Two operands arithmetic functions with no overflow allowed */
720 #define GEN_INT_ARITHN_64(name, opc1, opc2, opc3, type) \
721 __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, 0x00000400, type)
723 /* One operand arithmetic functions */
724 #define GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
725 __GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
726 __GEN_INT_ARITH1_O_64(name##o, opc1, opc2, opc3 | 0x10, type)
728 #define GEN_INT_ARITH2_64 GEN_INT_ARITH2
729 #define GEN_INT_ARITHN_64 GEN_INT_ARITHN
730 #define GEN_INT_ARITH1_64 GEN_INT_ARITH1
733 /* add add. addo addo. */
734 static always_inline
void gen_op_addo (void)
740 #if defined(TARGET_PPC64)
741 #define gen_op_add_64 gen_op_add
742 static always_inline
void gen_op_addo_64 (void)
746 gen_op_check_addo_64();
749 GEN_INT_ARITH2_64 (add
, 0x1F, 0x0A, 0x08, PPC_INTEGER
);
750 /* addc addc. addco addco. */
751 static always_inline
void gen_op_addc (void)
757 static always_inline
void gen_op_addco (void)
764 #if defined(TARGET_PPC64)
765 static always_inline
void gen_op_addc_64 (void)
769 gen_op_check_addc_64();
771 static always_inline
void gen_op_addco_64 (void)
775 gen_op_check_addc_64();
776 gen_op_check_addo_64();
779 GEN_INT_ARITH2_64 (addc
, 0x1F, 0x0A, 0x00, PPC_INTEGER
);
780 /* adde adde. addeo addeo. */
781 static always_inline
void gen_op_addeo (void)
787 #if defined(TARGET_PPC64)
788 static always_inline
void gen_op_addeo_64 (void)
792 gen_op_check_addo_64();
795 GEN_INT_ARITH2_64 (adde
, 0x1F, 0x0A, 0x04, PPC_INTEGER
);
796 /* addme addme. addmeo addmeo. */
797 static always_inline
void gen_op_addme (void)
802 #if defined(TARGET_PPC64)
803 static always_inline
void gen_op_addme_64 (void)
809 GEN_INT_ARITH1_64 (addme
, 0x1F, 0x0A, 0x07, PPC_INTEGER
);
810 /* addze addze. addzeo addzeo. */
811 static always_inline
void gen_op_addze (void)
817 static always_inline
void gen_op_addzeo (void)
824 #if defined(TARGET_PPC64)
825 static always_inline
void gen_op_addze_64 (void)
829 gen_op_check_addc_64();
831 static always_inline
void gen_op_addzeo_64 (void)
835 gen_op_check_addc_64();
836 gen_op_check_addo_64();
839 GEN_INT_ARITH1_64 (addze
, 0x1F, 0x0A, 0x06, PPC_INTEGER
);
840 /* divw divw. divwo divwo. */
841 GEN_INT_ARITH2 (divw
, 0x1F, 0x0B, 0x0F, PPC_INTEGER
);
842 /* divwu divwu. divwuo divwuo. */
843 GEN_INT_ARITH2 (divwu
, 0x1F, 0x0B, 0x0E, PPC_INTEGER
);
845 GEN_INT_ARITHN (mulhw
, 0x1F, 0x0B, 0x02, PPC_INTEGER
);
847 GEN_INT_ARITHN (mulhwu
, 0x1F, 0x0B, 0x00, PPC_INTEGER
);
848 /* mullw mullw. mullwo mullwo. */
849 GEN_INT_ARITH2 (mullw
, 0x1F, 0x0B, 0x07, PPC_INTEGER
);
850 /* neg neg. nego nego. */
851 GEN_INT_ARITH1_64 (neg
, 0x1F, 0x08, 0x03, PPC_INTEGER
);
852 /* subf subf. subfo subfo. */
853 static always_inline
void gen_op_subfo (void)
857 gen_op_check_subfo();
859 #if defined(TARGET_PPC64)
860 #define gen_op_subf_64 gen_op_subf
861 static always_inline
void gen_op_subfo_64 (void)
865 gen_op_check_subfo_64();
868 GEN_INT_ARITH2_64 (subf
, 0x1F, 0x08, 0x01, PPC_INTEGER
);
869 /* subfc subfc. subfco subfco. */
870 static always_inline
void gen_op_subfc (void)
873 gen_op_check_subfc();
875 static always_inline
void gen_op_subfco (void)
879 gen_op_check_subfc();
880 gen_op_check_subfo();
882 #if defined(TARGET_PPC64)
883 static always_inline
void gen_op_subfc_64 (void)
886 gen_op_check_subfc_64();
888 static always_inline
void gen_op_subfco_64 (void)
892 gen_op_check_subfc_64();
893 gen_op_check_subfo_64();
896 GEN_INT_ARITH2_64 (subfc
, 0x1F, 0x08, 0x00, PPC_INTEGER
);
897 /* subfe subfe. subfeo subfeo. */
898 static always_inline
void gen_op_subfeo (void)
902 gen_op_check_subfo();
904 #if defined(TARGET_PPC64)
905 #define gen_op_subfe_64 gen_op_subfe
906 static always_inline
void gen_op_subfeo_64 (void)
910 gen_op_check_subfo_64();
913 GEN_INT_ARITH2_64 (subfe
, 0x1F, 0x08, 0x04, PPC_INTEGER
);
914 /* subfme subfme. subfmeo subfmeo. */
915 GEN_INT_ARITH1_64 (subfme
, 0x1F, 0x08, 0x07, PPC_INTEGER
);
916 /* subfze subfze. subfzeo subfzeo. */
917 GEN_INT_ARITH1_64 (subfze
, 0x1F, 0x08, 0x06, PPC_INTEGER
);
919 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
921 target_long simm
= SIMM(ctx
->opcode
);
923 if (rA(ctx
->opcode
) == 0) {
927 gen_op_load_gpr_T0(rA(ctx
->opcode
));
928 if (likely(simm
!= 0))
931 gen_op_store_T0_gpr(rD(ctx
->opcode
));
934 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
936 target_long simm
= SIMM(ctx
->opcode
);
938 gen_op_load_gpr_T0(rA(ctx
->opcode
));
939 if (likely(simm
!= 0)) {
942 #if defined(TARGET_PPC64)
944 gen_op_check_addc_64();
949 gen_op_clear_xer_ca();
951 gen_op_store_T0_gpr(rD(ctx
->opcode
));
954 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
956 target_long simm
= SIMM(ctx
->opcode
);
958 gen_op_load_gpr_T0(rA(ctx
->opcode
));
959 if (likely(simm
!= 0)) {
962 #if defined(TARGET_PPC64)
964 gen_op_check_addc_64();
969 gen_op_clear_xer_ca();
971 gen_op_store_T0_gpr(rD(ctx
->opcode
));
975 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
977 target_long simm
= SIMM(ctx
->opcode
);
979 if (rA(ctx
->opcode
) == 0) {
981 gen_set_T0(simm
<< 16);
983 gen_op_load_gpr_T0(rA(ctx
->opcode
));
984 if (likely(simm
!= 0))
985 gen_op_addi(simm
<< 16);
987 gen_op_store_T0_gpr(rD(ctx
->opcode
));
990 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
992 gen_op_load_gpr_T0(rA(ctx
->opcode
));
993 gen_op_mulli(SIMM(ctx
->opcode
));
994 gen_op_store_T0_gpr(rD(ctx
->opcode
));
997 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
999 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1000 #if defined(TARGET_PPC64)
1002 gen_op_subfic_64(SIMM(ctx
->opcode
));
1005 gen_op_subfic(SIMM(ctx
->opcode
));
1006 gen_op_store_T0_gpr(rD(ctx
->opcode
));
1009 #if defined(TARGET_PPC64)
1011 GEN_INT_ARITHN (mulhd
, 0x1F, 0x09, 0x02, PPC_64B
);
1012 /* mulhdu mulhdu. */
1013 GEN_INT_ARITHN (mulhdu
, 0x1F, 0x09, 0x00, PPC_64B
);
1014 /* mulld mulld. mulldo mulldo. */
1015 GEN_INT_ARITH2 (mulld
, 0x1F, 0x09, 0x07, PPC_64B
);
1016 /* divd divd. divdo divdo. */
1017 GEN_INT_ARITH2 (divd
, 0x1F, 0x09, 0x0F, PPC_64B
);
1018 /* divdu divdu. divduo divduo. */
1019 GEN_INT_ARITH2 (divdu
, 0x1F, 0x09, 0x0E, PPC_64B
);
1022 /*** Integer comparison ***/
1023 #if defined(TARGET_PPC64)
1024 #define GEN_CMP(name, opc, type) \
1025 GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, type) \
1027 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1028 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1029 if (ctx->sf_mode && (ctx->opcode & 0x00200000)) \
1030 gen_op_##name##_64(); \
1033 gen_op_store_T0_crf(crfD(ctx->opcode)); \
1036 #define GEN_CMP(name, opc, type) \
1037 GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, type) \
1039 gen_op_load_gpr_T0(rA(ctx->opcode)); \
1040 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1042 gen_op_store_T0_crf(crfD(ctx->opcode)); \
1047 GEN_CMP(cmp
, 0x00, PPC_INTEGER
);
1049 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
)
1051 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1052 #if defined(TARGET_PPC64)
1053 if (ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000))
1054 gen_op_cmpi_64(SIMM(ctx
->opcode
));
1057 gen_op_cmpi(SIMM(ctx
->opcode
));
1058 gen_op_store_T0_crf(crfD(ctx
->opcode
));
1061 GEN_CMP(cmpl
, 0x01, PPC_INTEGER
);
1063 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
)
1065 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1066 #if defined(TARGET_PPC64)
1067 if (ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000))
1068 gen_op_cmpli_64(UIMM(ctx
->opcode
));
1071 gen_op_cmpli(UIMM(ctx
->opcode
));
1072 gen_op_store_T0_crf(crfD(ctx
->opcode
));
1075 /* isel (PowerPC 2.03 specification) */
1076 GEN_HANDLER(isel
, 0x1F, 0x0F, 0x00, 0x00000001, PPC_203
)
1078 uint32_t bi
= rC(ctx
->opcode
);
1081 if (rA(ctx
->opcode
) == 0) {
1084 gen_op_load_gpr_T1(rA(ctx
->opcode
));
1086 gen_op_load_gpr_T2(rB(ctx
->opcode
));
1087 mask
= 1 << (3 - (bi
& 0x03));
1088 gen_op_load_crf_T0(bi
>> 2);
1089 gen_op_test_true(mask
);
1091 gen_op_store_T0_gpr(rD(ctx
->opcode
));
1094 /*** Integer logical ***/
1095 #define __GEN_LOGICAL2(name, opc2, opc3, type) \
1096 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000000, type) \
1098 gen_op_load_gpr_T0(rS(ctx->opcode)); \
1099 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1101 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1102 if (unlikely(Rc(ctx->opcode) != 0)) \
1105 #define GEN_LOGICAL2(name, opc, type) \
1106 __GEN_LOGICAL2(name, 0x1C, opc, type)
1108 #define GEN_LOGICAL1(name, opc, type) \
1109 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type) \
1111 gen_op_load_gpr_T0(rS(ctx->opcode)); \
1113 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1114 if (unlikely(Rc(ctx->opcode) != 0)) \
1119 GEN_LOGICAL2(and, 0x00, PPC_INTEGER
);
1121 GEN_LOGICAL2(andc
, 0x01, PPC_INTEGER
);
1123 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1125 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1126 gen_op_andi_T0(UIMM(ctx
->opcode
));
1127 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1131 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1133 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1134 gen_op_andi_T0(UIMM(ctx
->opcode
) << 16);
1135 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1140 GEN_LOGICAL1(cntlzw
, 0x00, PPC_INTEGER
);
1142 GEN_LOGICAL2(eqv
, 0x08, PPC_INTEGER
);
1143 /* extsb & extsb. */
1144 GEN_LOGICAL1(extsb
, 0x1D, PPC_INTEGER
);
1145 /* extsh & extsh. */
1146 GEN_LOGICAL1(extsh
, 0x1C, PPC_INTEGER
);
1148 GEN_LOGICAL2(nand
, 0x0E, PPC_INTEGER
);
1150 GEN_LOGICAL2(nor
, 0x03, PPC_INTEGER
);
1153 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
)
1157 rs
= rS(ctx
->opcode
);
1158 ra
= rA(ctx
->opcode
);
1159 rb
= rB(ctx
->opcode
);
1160 /* Optimisation for mr. ri case */
1161 if (rs
!= ra
|| rs
!= rb
) {
1162 gen_op_load_gpr_T0(rs
);
1164 gen_op_load_gpr_T1(rb
);
1167 gen_op_store_T0_gpr(ra
);
1168 if (unlikely(Rc(ctx
->opcode
) != 0))
1170 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
1171 gen_op_load_gpr_T0(rs
);
1173 #if defined(TARGET_PPC64)
1177 /* Set process priority to low */
1178 gen_op_store_pri(2);
1181 /* Set process priority to medium-low */
1182 gen_op_store_pri(3);
1185 /* Set process priority to normal */
1186 gen_op_store_pri(4);
1188 #if !defined(CONFIG_USER_ONLY)
1190 if (ctx
->supervisor
> 0) {
1191 /* Set process priority to very low */
1192 gen_op_store_pri(1);
1196 if (ctx
->supervisor
> 0) {
1197 /* Set process priority to medium-hight */
1198 gen_op_store_pri(5);
1202 if (ctx
->supervisor
> 0) {
1203 /* Set process priority to high */
1204 gen_op_store_pri(6);
1207 #if defined(TARGET_PPC64H)
1209 if (ctx
->supervisor
> 1) {
1210 /* Set process priority to very high */
1211 gen_op_store_pri(7);
1225 GEN_LOGICAL2(orc
, 0x0C, PPC_INTEGER
);
1227 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
)
1229 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1230 /* Optimisation for "set to zero" case */
1231 if (rS(ctx
->opcode
) != rB(ctx
->opcode
)) {
1232 gen_op_load_gpr_T1(rB(ctx
->opcode
));
1237 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1238 if (unlikely(Rc(ctx
->opcode
) != 0))
1242 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1244 target_ulong uimm
= UIMM(ctx
->opcode
);
1246 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1248 /* XXX: should handle special NOPs for POWER series */
1251 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1252 if (likely(uimm
!= 0))
1254 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1257 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1259 target_ulong uimm
= UIMM(ctx
->opcode
);
1261 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1265 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1266 if (likely(uimm
!= 0))
1267 gen_op_ori(uimm
<< 16);
1268 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1271 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1273 target_ulong uimm
= UIMM(ctx
->opcode
);
1275 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1279 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1280 if (likely(uimm
!= 0))
1282 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1286 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1288 target_ulong uimm
= UIMM(ctx
->opcode
);
1290 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1294 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1295 if (likely(uimm
!= 0))
1296 gen_op_xori(uimm
<< 16);
1297 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1300 /* popcntb : PowerPC 2.03 specification */
1301 GEN_HANDLER(popcntb
, 0x1F, 0x03, 0x03, 0x0000F801, PPC_203
)
1303 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1304 #if defined(TARGET_PPC64)
1306 gen_op_popcntb_64();
1310 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1313 #if defined(TARGET_PPC64)
1314 /* extsw & extsw. */
1315 GEN_LOGICAL1(extsw
, 0x1E, PPC_64B
);
1317 GEN_LOGICAL1(cntlzd
, 0x01, PPC_64B
);
1320 /*** Integer rotate ***/
1321 /* rlwimi & rlwimi. */
1322 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1325 uint32_t mb
, me
, sh
;
1327 mb
= MB(ctx
->opcode
);
1328 me
= ME(ctx
->opcode
);
1329 sh
= SH(ctx
->opcode
);
1330 if (likely(sh
== 0)) {
1331 if (likely(mb
== 0 && me
== 31)) {
1332 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1334 } else if (likely(mb
== 31 && me
== 0)) {
1335 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1338 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1339 gen_op_load_gpr_T1(rA(ctx
->opcode
));
1342 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1343 gen_op_load_gpr_T1(rA(ctx
->opcode
));
1344 gen_op_rotli32_T0(SH(ctx
->opcode
));
1346 #if defined(TARGET_PPC64)
1350 mask
= MASK(mb
, me
);
1351 gen_op_andi_T0(mask
);
1352 gen_op_andi_T1(~mask
);
1355 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1356 if (unlikely(Rc(ctx
->opcode
) != 0))
1359 /* rlwinm & rlwinm. */
1360 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1362 uint32_t mb
, me
, sh
;
1364 sh
= SH(ctx
->opcode
);
1365 mb
= MB(ctx
->opcode
);
1366 me
= ME(ctx
->opcode
);
1367 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1368 if (likely(sh
== 0)) {
1371 if (likely(mb
== 0)) {
1372 if (likely(me
== 31)) {
1373 gen_op_rotli32_T0(sh
);
1375 } else if (likely(me
== (31 - sh
))) {
1379 } else if (likely(me
== 31)) {
1380 if (likely(sh
== (32 - mb
))) {
1385 gen_op_rotli32_T0(sh
);
1387 #if defined(TARGET_PPC64)
1391 gen_op_andi_T0(MASK(mb
, me
));
1393 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1394 if (unlikely(Rc(ctx
->opcode
) != 0))
1397 /* rlwnm & rlwnm. */
1398 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1402 mb
= MB(ctx
->opcode
);
1403 me
= ME(ctx
->opcode
);
1404 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1405 gen_op_load_gpr_T1(rB(ctx
->opcode
));
1406 gen_op_rotl32_T0_T1();
1407 if (unlikely(mb
!= 0 || me
!= 31)) {
1408 #if defined(TARGET_PPC64)
1412 gen_op_andi_T0(MASK(mb
, me
));
1414 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1415 if (unlikely(Rc(ctx
->opcode
) != 0))
1419 #if defined(TARGET_PPC64)
1420 #define GEN_PPC64_R2(name, opc1, opc2) \
1421 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1423 gen_##name(ctx, 0); \
1425 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1428 gen_##name(ctx, 1); \
1430 #define GEN_PPC64_R4(name, opc1, opc2) \
1431 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1433 gen_##name(ctx, 0, 0); \
1435 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
1438 gen_##name(ctx, 0, 1); \
1440 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1443 gen_##name(ctx, 1, 0); \
1445 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
1448 gen_##name(ctx, 1, 1); \
1451 static always_inline
void gen_andi_T0_64 (DisasContext
*ctx
, uint64_t mask
)
1454 gen_op_andi_T0_64(mask
>> 32, mask
& 0xFFFFFFFF);
1456 gen_op_andi_T0(mask
);
1459 static always_inline
void gen_andi_T1_64 (DisasContext
*ctx
, uint64_t mask
)
1462 gen_op_andi_T1_64(mask
>> 32, mask
& 0xFFFFFFFF);
1464 gen_op_andi_T1(mask
);
1467 static always_inline
void gen_rldinm (DisasContext
*ctx
, uint32_t mb
,
1468 uint32_t me
, uint32_t sh
)
1470 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1471 if (likely(sh
== 0)) {
1474 if (likely(mb
== 0)) {
1475 if (likely(me
== 63)) {
1476 gen_op_rotli64_T0(sh
);
1478 } else if (likely(me
== (63 - sh
))) {
1482 } else if (likely(me
== 63)) {
1483 if (likely(sh
== (64 - mb
))) {
1484 gen_op_srli_T0_64(mb
);
1488 gen_op_rotli64_T0(sh
);
1490 gen_andi_T0_64(ctx
, MASK(mb
, me
));
1492 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1493 if (unlikely(Rc(ctx
->opcode
) != 0))
1496 /* rldicl - rldicl. */
1497 static always_inline
void gen_rldicl (DisasContext
*ctx
, int mbn
, int shn
)
1501 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1502 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1503 gen_rldinm(ctx
, mb
, 63, sh
);
1505 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
1506 /* rldicr - rldicr. */
1507 static always_inline
void gen_rldicr (DisasContext
*ctx
, int men
, int shn
)
1511 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1512 me
= MB(ctx
->opcode
) | (men
<< 5);
1513 gen_rldinm(ctx
, 0, me
, sh
);
1515 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
1516 /* rldic - rldic. */
1517 static always_inline
void gen_rldic (DisasContext
*ctx
, int mbn
, int shn
)
1521 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1522 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1523 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
1525 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
1527 static always_inline
void gen_rldnm (DisasContext
*ctx
, uint32_t mb
,
1530 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1531 gen_op_load_gpr_T1(rB(ctx
->opcode
));
1532 gen_op_rotl64_T0_T1();
1533 if (unlikely(mb
!= 0 || me
!= 63)) {
1534 gen_andi_T0_64(ctx
, MASK(mb
, me
));
1536 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1537 if (unlikely(Rc(ctx
->opcode
) != 0))
1541 /* rldcl - rldcl. */
1542 static always_inline
void gen_rldcl (DisasContext
*ctx
, int mbn
)
1546 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1547 gen_rldnm(ctx
, mb
, 63);
1549 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
1550 /* rldcr - rldcr. */
1551 static always_inline
void gen_rldcr (DisasContext
*ctx
, int men
)
1555 me
= MB(ctx
->opcode
) | (men
<< 5);
1556 gen_rldnm(ctx
, 0, me
);
1558 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
1559 /* rldimi - rldimi. */
1560 static always_inline
void gen_rldimi (DisasContext
*ctx
, int mbn
, int shn
)
1565 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1566 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1567 if (likely(sh
== 0)) {
1568 if (likely(mb
== 0)) {
1569 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1571 } else if (likely(mb
== 63)) {
1572 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1575 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1576 gen_op_load_gpr_T1(rA(ctx
->opcode
));
1579 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1580 gen_op_load_gpr_T1(rA(ctx
->opcode
));
1581 gen_op_rotli64_T0(sh
);
1583 mask
= MASK(mb
, 63 - sh
);
1584 gen_andi_T0_64(ctx
, mask
);
1585 gen_andi_T1_64(ctx
, ~mask
);
1588 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1589 if (unlikely(Rc(ctx
->opcode
) != 0))
1592 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
1595 /*** Integer shift ***/
1597 __GEN_LOGICAL2(slw
, 0x18, 0x00, PPC_INTEGER
);
1599 __GEN_LOGICAL2(sraw
, 0x18, 0x18, PPC_INTEGER
);
1600 /* srawi & srawi. */
1601 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
)
1604 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1605 if (SH(ctx
->opcode
) != 0) {
1606 gen_op_move_T1_T0();
1607 mb
= 32 - SH(ctx
->opcode
);
1609 #if defined(TARGET_PPC64)
1613 gen_op_srawi(SH(ctx
->opcode
), MASK(mb
, me
));
1615 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1616 if (unlikely(Rc(ctx
->opcode
) != 0))
1620 __GEN_LOGICAL2(srw
, 0x18, 0x10, PPC_INTEGER
);
1622 #if defined(TARGET_PPC64)
1624 __GEN_LOGICAL2(sld
, 0x1B, 0x00, PPC_64B
);
1626 __GEN_LOGICAL2(srad
, 0x1A, 0x18, PPC_64B
);
1627 /* sradi & sradi. */
1628 static always_inline
void gen_sradi (DisasContext
*ctx
, int n
)
1633 gen_op_load_gpr_T0(rS(ctx
->opcode
));
1634 sh
= SH(ctx
->opcode
) + (n
<< 5);
1636 gen_op_move_T1_T0();
1637 mb
= 64 - SH(ctx
->opcode
);
1639 mask
= MASK(mb
, me
);
1640 gen_op_sradi(sh
, mask
>> 32, mask
);
1642 gen_op_store_T0_gpr(rA(ctx
->opcode
));
1643 if (unlikely(Rc(ctx
->opcode
) != 0))
1646 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
)
1650 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
)
1655 __GEN_LOGICAL2(srd
, 0x1B, 0x10, PPC_64B
);
1658 /*** Floating-Point arithmetic ***/
1659 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, type) \
1660 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type) \
1662 if (unlikely(!ctx->fpu_enabled)) { \
1663 GEN_EXCP_NO_FP(ctx); \
1666 gen_op_reset_scrfx(); \
1667 gen_op_load_fpr_FT0(rA(ctx->opcode)); \
1668 gen_op_load_fpr_FT1(rC(ctx->opcode)); \
1669 gen_op_load_fpr_FT2(rB(ctx->opcode)); \
1674 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1675 if (unlikely(Rc(ctx->opcode) != 0)) \
1679 #define GEN_FLOAT_ACB(name, op2, type) \
1680 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, type); \
1681 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, type);
1683 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat) \
1684 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, PPC_FLOAT) \
1686 if (unlikely(!ctx->fpu_enabled)) { \
1687 GEN_EXCP_NO_FP(ctx); \
1690 gen_op_reset_scrfx(); \
1691 gen_op_load_fpr_FT0(rA(ctx->opcode)); \
1692 gen_op_load_fpr_FT1(rB(ctx->opcode)); \
1697 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1698 if (unlikely(Rc(ctx->opcode) != 0)) \
1701 #define GEN_FLOAT_AB(name, op2, inval) \
1702 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0); \
1703 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1);
1705 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat) \
1706 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, PPC_FLOAT) \
1708 if (unlikely(!ctx->fpu_enabled)) { \
1709 GEN_EXCP_NO_FP(ctx); \
1712 gen_op_reset_scrfx(); \
1713 gen_op_load_fpr_FT0(rA(ctx->opcode)); \
1714 gen_op_load_fpr_FT1(rC(ctx->opcode)); \
1719 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1720 if (unlikely(Rc(ctx->opcode) != 0)) \
1723 #define GEN_FLOAT_AC(name, op2, inval) \
1724 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0); \
1725 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1);
1727 #define GEN_FLOAT_B(name, op2, op3, type) \
1728 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type) \
1730 if (unlikely(!ctx->fpu_enabled)) { \
1731 GEN_EXCP_NO_FP(ctx); \
1734 gen_op_reset_scrfx(); \
1735 gen_op_load_fpr_FT0(rB(ctx->opcode)); \
1737 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1738 if (unlikely(Rc(ctx->opcode) != 0)) \
1742 #define GEN_FLOAT_BS(name, op1, op2, type) \
1743 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type) \
1745 if (unlikely(!ctx->fpu_enabled)) { \
1746 GEN_EXCP_NO_FP(ctx); \
1749 gen_op_reset_scrfx(); \
1750 gen_op_load_fpr_FT0(rB(ctx->opcode)); \
1752 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1753 if (unlikely(Rc(ctx->opcode) != 0)) \
1758 GEN_FLOAT_AB(add
, 0x15, 0x000007C0);
1760 GEN_FLOAT_AB(div
, 0x12, 0x000007C0);
1762 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800);
1765 GEN_FLOAT_BS(re
, 0x3F, 0x18, PPC_FLOAT_EXT
);
1768 GEN_FLOAT_BS(res
, 0x3B, 0x18, PPC_FLOAT_FRES
);
1771 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, PPC_FLOAT_FRSQRTE
);
1774 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, PPC_FLOAT_FSEL
);
1776 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0);
1779 GEN_HANDLER(fsqrt
, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
)
1781 if (unlikely(!ctx
->fpu_enabled
)) {
1782 GEN_EXCP_NO_FP(ctx
);
1785 gen_op_reset_scrfx();
1786 gen_op_load_fpr_FT0(rB(ctx
->opcode
));
1788 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
1789 if (unlikely(Rc(ctx
->opcode
) != 0))
1793 GEN_HANDLER(fsqrts
, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
)
1795 if (unlikely(!ctx
->fpu_enabled
)) {
1796 GEN_EXCP_NO_FP(ctx
);
1799 gen_op_reset_scrfx();
1800 gen_op_load_fpr_FT0(rB(ctx
->opcode
));
1803 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
1804 if (unlikely(Rc(ctx
->opcode
) != 0))
1808 /*** Floating-Point multiply-and-add ***/
1809 /* fmadd - fmadds */
1810 GEN_FLOAT_ACB(madd
, 0x1D, PPC_FLOAT
);
1811 /* fmsub - fmsubs */
1812 GEN_FLOAT_ACB(msub
, 0x1C, PPC_FLOAT
);
1813 /* fnmadd - fnmadds */
1814 GEN_FLOAT_ACB(nmadd
, 0x1F, PPC_FLOAT
);
1815 /* fnmsub - fnmsubs */
1816 GEN_FLOAT_ACB(nmsub
, 0x1E, PPC_FLOAT
);
1818 /*** Floating-Point round & convert ***/
1820 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, PPC_FLOAT
);
1822 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, PPC_FLOAT
);
1824 GEN_FLOAT_B(rsp
, 0x0C, 0x00, PPC_FLOAT
);
1825 #if defined(TARGET_PPC64)
1827 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, PPC_64B
);
1829 GEN_FLOAT_B(ctid
, 0x0E, 0x19, PPC_64B
);
1831 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, PPC_64B
);
1835 GEN_FLOAT_B(rin
, 0x08, 0x0C, PPC_FLOAT_EXT
);
1837 GEN_FLOAT_B(riz
, 0x08, 0x0D, PPC_FLOAT_EXT
);
1839 GEN_FLOAT_B(rip
, 0x08, 0x0E, PPC_FLOAT_EXT
);
1841 GEN_FLOAT_B(rim
, 0x08, 0x0F, PPC_FLOAT_EXT
);
1843 /*** Floating-Point compare ***/
1845 GEN_HANDLER(fcmpo
, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT
)
1847 if (unlikely(!ctx
->fpu_enabled
)) {
1848 GEN_EXCP_NO_FP(ctx
);
1851 gen_op_reset_scrfx();
1852 gen_op_load_fpr_FT0(rA(ctx
->opcode
));
1853 gen_op_load_fpr_FT1(rB(ctx
->opcode
));
1855 gen_op_store_T0_crf(crfD(ctx
->opcode
));
1859 GEN_HANDLER(fcmpu
, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT
)
1861 if (unlikely(!ctx
->fpu_enabled
)) {
1862 GEN_EXCP_NO_FP(ctx
);
1865 gen_op_reset_scrfx();
1866 gen_op_load_fpr_FT0(rA(ctx
->opcode
));
1867 gen_op_load_fpr_FT1(rB(ctx
->opcode
));
1869 gen_op_store_T0_crf(crfD(ctx
->opcode
));
1872 /*** Floating-point move ***/
1874 GEN_FLOAT_B(abs
, 0x08, 0x08, PPC_FLOAT
);
1877 GEN_HANDLER(fmr
, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT
)
1879 if (unlikely(!ctx
->fpu_enabled
)) {
1880 GEN_EXCP_NO_FP(ctx
);
1883 gen_op_reset_scrfx();
1884 gen_op_load_fpr_FT0(rB(ctx
->opcode
));
1885 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
1886 if (unlikely(Rc(ctx
->opcode
) != 0))
1891 GEN_FLOAT_B(nabs
, 0x08, 0x04, PPC_FLOAT
);
1893 GEN_FLOAT_B(neg
, 0x08, 0x01, PPC_FLOAT
);
1895 /*** Floating-Point status & ctrl register ***/
1897 GEN_HANDLER(mcrfs
, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT
)
1899 if (unlikely(!ctx
->fpu_enabled
)) {
1900 GEN_EXCP_NO_FP(ctx
);
1903 gen_op_load_fpscr_T0(crfS(ctx
->opcode
));
1904 gen_op_store_T0_crf(crfD(ctx
->opcode
));
1905 gen_op_clear_fpscr(crfS(ctx
->opcode
));
1909 GEN_HANDLER(mffs
, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT
)
1911 if (unlikely(!ctx
->fpu_enabled
)) {
1912 GEN_EXCP_NO_FP(ctx
);
1915 gen_op_load_fpscr();
1916 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
1917 if (unlikely(Rc(ctx
->opcode
) != 0))
1922 GEN_HANDLER(mtfsb0
, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT
)
1926 if (unlikely(!ctx
->fpu_enabled
)) {
1927 GEN_EXCP_NO_FP(ctx
);
1930 crb
= crbD(ctx
->opcode
) >> 2;
1931 gen_op_load_fpscr_T0(crb
);
1932 gen_op_andi_T0(~(1 << (crbD(ctx
->opcode
) & 0x03)));
1933 gen_op_store_T0_fpscr(crb
);
1934 if (unlikely(Rc(ctx
->opcode
) != 0))
1939 GEN_HANDLER(mtfsb1
, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT
)
1943 if (unlikely(!ctx
->fpu_enabled
)) {
1944 GEN_EXCP_NO_FP(ctx
);
1947 crb
= crbD(ctx
->opcode
) >> 2;
1948 gen_op_load_fpscr_T0(crb
);
1949 gen_op_ori(1 << (crbD(ctx
->opcode
) & 0x03));
1950 gen_op_store_T0_fpscr(crb
);
1951 if (unlikely(Rc(ctx
->opcode
) != 0))
1956 GEN_HANDLER(mtfsf
, 0x3F, 0x07, 0x16, 0x02010000, PPC_FLOAT
)
1958 if (unlikely(!ctx
->fpu_enabled
)) {
1959 GEN_EXCP_NO_FP(ctx
);
1962 gen_op_load_fpr_FT0(rB(ctx
->opcode
));
1963 gen_op_store_fpscr(FM(ctx
->opcode
));
1964 if (unlikely(Rc(ctx
->opcode
) != 0))
1969 GEN_HANDLER(mtfsfi
, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT
)
1971 if (unlikely(!ctx
->fpu_enabled
)) {
1972 GEN_EXCP_NO_FP(ctx
);
1975 gen_op_store_T0_fpscri(crbD(ctx
->opcode
) >> 2, FPIMM(ctx
->opcode
));
1976 if (unlikely(Rc(ctx
->opcode
) != 0))
1980 /*** Addressing modes ***/
1981 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
1982 static always_inline
void gen_addr_imm_index (DisasContext
*ctx
,
1985 target_long simm
= SIMM(ctx
->opcode
);
1988 if (rA(ctx
->opcode
) == 0) {
1991 gen_op_load_gpr_T0(rA(ctx
->opcode
));
1992 if (likely(simm
!= 0))
1995 #ifdef DEBUG_MEMORY_ACCESSES
1996 gen_op_print_mem_EA();
2000 static always_inline
void gen_addr_reg_index (DisasContext
*ctx
)
2002 if (rA(ctx
->opcode
) == 0) {
2003 gen_op_load_gpr_T0(rB(ctx
->opcode
));
2005 gen_op_load_gpr_T0(rA(ctx
->opcode
));
2006 gen_op_load_gpr_T1(rB(ctx
->opcode
));
2009 #ifdef DEBUG_MEMORY_ACCESSES
2010 gen_op_print_mem_EA();
2014 static always_inline
void gen_addr_register (DisasContext
*ctx
)
2016 if (rA(ctx
->opcode
) == 0) {
2019 gen_op_load_gpr_T0(rA(ctx
->opcode
));
2021 #ifdef DEBUG_MEMORY_ACCESSES
2022 gen_op_print_mem_EA();
2026 /*** Integer load ***/
2027 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
2028 #if defined(CONFIG_USER_ONLY)
2029 #if defined(TARGET_PPC64)
2030 /* User mode only - 64 bits */
2031 #define OP_LD_TABLE(width) \
2032 static GenOpFunc *gen_op_l##width[] = { \
2033 &gen_op_l##width##_raw, \
2034 &gen_op_l##width##_le_raw, \
2035 &gen_op_l##width##_64_raw, \
2036 &gen_op_l##width##_le_64_raw, \
2038 #define OP_ST_TABLE(width) \
2039 static GenOpFunc *gen_op_st##width[] = { \
2040 &gen_op_st##width##_raw, \
2041 &gen_op_st##width##_le_raw, \
2042 &gen_op_st##width##_64_raw, \
2043 &gen_op_st##width##_le_64_raw, \
2045 /* Byte access routine are endian safe */
2046 #define gen_op_stb_le_64_raw gen_op_stb_64_raw
2047 #define gen_op_lbz_le_64_raw gen_op_lbz_64_raw
2049 /* User mode only - 32 bits */
2050 #define OP_LD_TABLE(width) \
2051 static GenOpFunc *gen_op_l##width[] = { \
2052 &gen_op_l##width##_raw, \
2053 &gen_op_l##width##_le_raw, \
2055 #define OP_ST_TABLE(width) \
2056 static GenOpFunc *gen_op_st##width[] = { \
2057 &gen_op_st##width##_raw, \
2058 &gen_op_st##width##_le_raw, \
2061 /* Byte access routine are endian safe */
2062 #define gen_op_stb_le_raw gen_op_stb_raw
2063 #define gen_op_lbz_le_raw gen_op_lbz_raw
2065 #if defined(TARGET_PPC64)
2066 #if defined(TARGET_PPC64H)
2067 /* Full system - 64 bits with hypervisor mode */
2068 #define OP_LD_TABLE(width) \
2069 static GenOpFunc *gen_op_l##width[] = { \
2070 &gen_op_l##width##_user, \
2071 &gen_op_l##width##_le_user, \
2072 &gen_op_l##width##_64_user, \
2073 &gen_op_l##width##_le_64_user, \
2074 &gen_op_l##width##_kernel, \
2075 &gen_op_l##width##_le_kernel, \
2076 &gen_op_l##width##_64_kernel, \
2077 &gen_op_l##width##_le_64_kernel, \
2078 &gen_op_l##width##_hypv, \
2079 &gen_op_l##width##_le_hypv, \
2080 &gen_op_l##width##_64_hypv, \
2081 &gen_op_l##width##_le_64_hypv, \
2083 #define OP_ST_TABLE(width) \
2084 static GenOpFunc *gen_op_st##width[] = { \
2085 &gen_op_st##width##_user, \
2086 &gen_op_st##width##_le_user, \
2087 &gen_op_st##width##_64_user, \
2088 &gen_op_st##width##_le_64_user, \
2089 &gen_op_st##width##_kernel, \
2090 &gen_op_st##width##_le_kernel, \
2091 &gen_op_st##width##_64_kernel, \
2092 &gen_op_st##width##_le_64_kernel, \
2093 &gen_op_st##width##_hypv, \
2094 &gen_op_st##width##_le_hypv, \
2095 &gen_op_st##width##_64_hypv, \
2096 &gen_op_st##width##_le_64_hypv, \
2098 /* Byte access routine are endian safe */
2099 #define gen_op_stb_le_hypv gen_op_stb_64_hypv
2100 #define gen_op_lbz_le_hypv gen_op_lbz_64_hypv
2101 #define gen_op_stb_le_64_hypv gen_op_stb_64_hypv
2102 #define gen_op_lbz_le_64_hypv gen_op_lbz_64_hypv
2104 /* Full system - 64 bits */
2105 #define OP_LD_TABLE(width) \
2106 static GenOpFunc *gen_op_l##width[] = { \
2107 &gen_op_l##width##_user, \
2108 &gen_op_l##width##_le_user, \
2109 &gen_op_l##width##_64_user, \
2110 &gen_op_l##width##_le_64_user, \
2111 &gen_op_l##width##_kernel, \
2112 &gen_op_l##width##_le_kernel, \
2113 &gen_op_l##width##_64_kernel, \
2114 &gen_op_l##width##_le_64_kernel, \
2116 #define OP_ST_TABLE(width) \
2117 static GenOpFunc *gen_op_st##width[] = { \
2118 &gen_op_st##width##_user, \
2119 &gen_op_st##width##_le_user, \
2120 &gen_op_st##width##_64_user, \
2121 &gen_op_st##width##_le_64_user, \
2122 &gen_op_st##width##_kernel, \
2123 &gen_op_st##width##_le_kernel, \
2124 &gen_op_st##width##_64_kernel, \
2125 &gen_op_st##width##_le_64_kernel, \
2128 /* Byte access routine are endian safe */
2129 #define gen_op_stb_le_64_user gen_op_stb_64_user
2130 #define gen_op_lbz_le_64_user gen_op_lbz_64_user
2131 #define gen_op_stb_le_64_kernel gen_op_stb_64_kernel
2132 #define gen_op_lbz_le_64_kernel gen_op_lbz_64_kernel
2134 /* Full system - 32 bits */
2135 #define OP_LD_TABLE(width) \
2136 static GenOpFunc *gen_op_l##width[] = { \
2137 &gen_op_l##width##_user, \
2138 &gen_op_l##width##_le_user, \
2139 &gen_op_l##width##_kernel, \
2140 &gen_op_l##width##_le_kernel, \
2142 #define OP_ST_TABLE(width) \
2143 static GenOpFunc *gen_op_st##width[] = { \
2144 &gen_op_st##width##_user, \
2145 &gen_op_st##width##_le_user, \
2146 &gen_op_st##width##_kernel, \
2147 &gen_op_st##width##_le_kernel, \
2150 /* Byte access routine are endian safe */
2151 #define gen_op_stb_le_user gen_op_stb_user
2152 #define gen_op_lbz_le_user gen_op_lbz_user
2153 #define gen_op_stb_le_kernel gen_op_stb_kernel
2154 #define gen_op_lbz_le_kernel gen_op_lbz_kernel
2157 #define GEN_LD(width, opc, type) \
2158 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2160 gen_addr_imm_index(ctx, 0); \
2161 op_ldst(l##width); \
2162 gen_op_store_T1_gpr(rD(ctx->opcode)); \
2165 #define GEN_LDU(width, opc, type) \
2166 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2168 if (unlikely(rA(ctx->opcode) == 0 || \
2169 rA(ctx->opcode) == rD(ctx->opcode))) { \
2170 GEN_EXCP_INVAL(ctx); \
2173 if (type == PPC_64B) \
2174 gen_addr_imm_index(ctx, 0x03); \
2176 gen_addr_imm_index(ctx, 0); \
2177 op_ldst(l##width); \
2178 gen_op_store_T1_gpr(rD(ctx->opcode)); \
2179 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2182 #define GEN_LDUX(width, opc2, opc3, type) \
2183 GEN_HANDLER(l##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2185 if (unlikely(rA(ctx->opcode) == 0 || \
2186 rA(ctx->opcode) == rD(ctx->opcode))) { \
2187 GEN_EXCP_INVAL(ctx); \
2190 gen_addr_reg_index(ctx); \
2191 op_ldst(l##width); \
2192 gen_op_store_T1_gpr(rD(ctx->opcode)); \
2193 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2196 #define GEN_LDX(width, opc2, opc3, type) \
2197 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2199 gen_addr_reg_index(ctx); \
2200 op_ldst(l##width); \
2201 gen_op_store_T1_gpr(rD(ctx->opcode)); \
2204 #define GEN_LDS(width, op, type) \
2205 OP_LD_TABLE(width); \
2206 GEN_LD(width, op | 0x20, type); \
2207 GEN_LDU(width, op | 0x21, type); \
2208 GEN_LDUX(width, 0x17, op | 0x01, type); \
2209 GEN_LDX(width, 0x17, op | 0x00, type)
2211 /* lbz lbzu lbzux lbzx */
2212 GEN_LDS(bz
, 0x02, PPC_INTEGER
);
2213 /* lha lhau lhaux lhax */
2214 GEN_LDS(ha
, 0x0A, PPC_INTEGER
);
2215 /* lhz lhzu lhzux lhzx */
2216 GEN_LDS(hz
, 0x08, PPC_INTEGER
);
2217 /* lwz lwzu lwzux lwzx */
2218 GEN_LDS(wz
, 0x00, PPC_INTEGER
);
2219 #if defined(TARGET_PPC64)
2223 GEN_LDUX(wa
, 0x15, 0x0B, PPC_64B
);
2225 GEN_LDX(wa
, 0x15, 0x0A, PPC_64B
);
2227 GEN_LDUX(d
, 0x15, 0x01, PPC_64B
);
2229 GEN_LDX(d
, 0x15, 0x00, PPC_64B
);
2230 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
)
2232 if (Rc(ctx
->opcode
)) {
2233 if (unlikely(rA(ctx
->opcode
) == 0 ||
2234 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
2235 GEN_EXCP_INVAL(ctx
);
2239 gen_addr_imm_index(ctx
, 0x03);
2240 if (ctx
->opcode
& 0x02) {
2241 /* lwa (lwau is undefined) */
2247 gen_op_store_T1_gpr(rD(ctx
->opcode
));
2248 if (Rc(ctx
->opcode
))
2249 gen_op_store_T0_gpr(rA(ctx
->opcode
));
2252 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
)
2254 #if defined(CONFIG_USER_ONLY)
2255 GEN_EXCP_PRIVOPC(ctx
);
2259 /* Restore CPU state */
2260 if (unlikely(ctx
->supervisor
== 0)) {
2261 GEN_EXCP_PRIVOPC(ctx
);
2264 ra
= rA(ctx
->opcode
);
2265 rd
= rD(ctx
->opcode
);
2266 if (unlikely((rd
& 1) || rd
== ra
)) {
2267 GEN_EXCP_INVAL(ctx
);
2270 if (unlikely(ctx
->mem_idx
& 1)) {
2271 /* Little-endian mode is not handled */
2272 GEN_EXCP(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2275 gen_addr_imm_index(ctx
, 0x0F);
2277 gen_op_store_T1_gpr(rd
);
2280 gen_op_store_T1_gpr(rd
+ 1);
2285 /*** Integer store ***/
2286 #define GEN_ST(width, opc, type) \
2287 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2289 gen_addr_imm_index(ctx, 0); \
2290 gen_op_load_gpr_T1(rS(ctx->opcode)); \
2291 op_ldst(st##width); \
2294 #define GEN_STU(width, opc, type) \
2295 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2297 if (unlikely(rA(ctx->opcode) == 0)) { \
2298 GEN_EXCP_INVAL(ctx); \
2301 if (type == PPC_64B) \
2302 gen_addr_imm_index(ctx, 0x03); \
2304 gen_addr_imm_index(ctx, 0); \
2305 gen_op_load_gpr_T1(rS(ctx->opcode)); \
2306 op_ldst(st##width); \
2307 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2310 #define GEN_STUX(width, opc2, opc3, type) \
2311 GEN_HANDLER(st##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2313 if (unlikely(rA(ctx->opcode) == 0)) { \
2314 GEN_EXCP_INVAL(ctx); \
2317 gen_addr_reg_index(ctx); \
2318 gen_op_load_gpr_T1(rS(ctx->opcode)); \
2319 op_ldst(st##width); \
2320 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2323 #define GEN_STX(width, opc2, opc3, type) \
2324 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2326 gen_addr_reg_index(ctx); \
2327 gen_op_load_gpr_T1(rS(ctx->opcode)); \
2328 op_ldst(st##width); \
2331 #define GEN_STS(width, op, type) \
2332 OP_ST_TABLE(width); \
2333 GEN_ST(width, op | 0x20, type); \
2334 GEN_STU(width, op | 0x21, type); \
2335 GEN_STUX(width, 0x17, op | 0x01, type); \
2336 GEN_STX(width, 0x17, op | 0x00, type)
2338 /* stb stbu stbux stbx */
2339 GEN_STS(b
, 0x06, PPC_INTEGER
);
2340 /* sth sthu sthux sthx */
2341 GEN_STS(h
, 0x0C, PPC_INTEGER
);
2342 /* stw stwu stwux stwx */
2343 GEN_STS(w
, 0x04, PPC_INTEGER
);
2344 #if defined(TARGET_PPC64)
2346 GEN_STUX(d
, 0x15, 0x05, PPC_64B
);
2347 GEN_STX(d
, 0x15, 0x04, PPC_64B
);
2348 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
)
2352 rs
= rS(ctx
->opcode
);
2353 if ((ctx
->opcode
& 0x3) == 0x2) {
2354 #if defined(CONFIG_USER_ONLY)
2355 GEN_EXCP_PRIVOPC(ctx
);
2358 if (unlikely(ctx
->supervisor
== 0)) {
2359 GEN_EXCP_PRIVOPC(ctx
);
2362 if (unlikely(rs
& 1)) {
2363 GEN_EXCP_INVAL(ctx
);
2366 if (unlikely(ctx
->mem_idx
& 1)) {
2367 /* Little-endian mode is not handled */
2368 GEN_EXCP(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2371 gen_addr_imm_index(ctx
, 0x03);
2372 gen_op_load_gpr_T1(rs
);
2375 gen_op_load_gpr_T1(rs
+ 1);
2380 if (Rc(ctx
->opcode
)) {
2381 if (unlikely(rA(ctx
->opcode
) == 0)) {
2382 GEN_EXCP_INVAL(ctx
);
2386 gen_addr_imm_index(ctx
, 0x03);
2387 gen_op_load_gpr_T1(rs
);
2389 if (Rc(ctx
->opcode
))
2390 gen_op_store_T0_gpr(rA(ctx
->opcode
));
2394 /*** Integer load and store with byte reverse ***/
2397 GEN_LDX(hbr
, 0x16, 0x18, PPC_INTEGER
);
2400 GEN_LDX(wbr
, 0x16, 0x10, PPC_INTEGER
);
2403 GEN_STX(hbr
, 0x16, 0x1C, PPC_INTEGER
);
2406 GEN_STX(wbr
, 0x16, 0x14, PPC_INTEGER
);
2408 /*** Integer load and store multiple ***/
2409 #define op_ldstm(name, reg) (*gen_op_##name[ctx->mem_idx])(reg)
2410 #if defined(CONFIG_USER_ONLY)
2411 /* User-mode only */
2412 static GenOpFunc1
*gen_op_lmw
[] = {
2415 #if defined(TARGET_PPC64)
2417 &gen_op_lmw_le_64_raw
,
2420 static GenOpFunc1
*gen_op_stmw
[] = {
2422 &gen_op_stmw_le_raw
,
2423 #if defined(TARGET_PPC64)
2424 &gen_op_stmw_64_raw
,
2425 &gen_op_stmw_le_64_raw
,
2429 #if defined(TARGET_PPC64)
2430 /* Full system - 64 bits mode */
2431 static GenOpFunc1
*gen_op_lmw
[] = {
2433 &gen_op_lmw_le_user
,
2434 &gen_op_lmw_64_user
,
2435 &gen_op_lmw_le_64_user
,
2437 &gen_op_lmw_le_kernel
,
2438 &gen_op_lmw_64_kernel
,
2439 &gen_op_lmw_le_64_kernel
,
2440 #if defined(TARGET_PPC64H)
2442 &gen_op_lmw_le_hypv
,
2443 &gen_op_lmw_64_hypv
,
2444 &gen_op_lmw_le_64_hypv
,
2447 static GenOpFunc1
*gen_op_stmw
[] = {
2449 &gen_op_stmw_le_user
,
2450 &gen_op_stmw_64_user
,
2451 &gen_op_stmw_le_64_user
,
2452 &gen_op_stmw_kernel
,
2453 &gen_op_stmw_le_kernel
,
2454 &gen_op_stmw_64_kernel
,
2455 &gen_op_stmw_le_64_kernel
,
2456 #if defined(TARGET_PPC64H)
2458 &gen_op_stmw_le_hypv
,
2459 &gen_op_stmw_64_hypv
,
2460 &gen_op_stmw_le_64_hypv
,
2464 /* Full system - 32 bits mode */
2465 static GenOpFunc1
*gen_op_lmw
[] = {
2467 &gen_op_lmw_le_user
,
2469 &gen_op_lmw_le_kernel
,
2471 static GenOpFunc1
*gen_op_stmw
[] = {
2473 &gen_op_stmw_le_user
,
2474 &gen_op_stmw_kernel
,
2475 &gen_op_stmw_le_kernel
,
2481 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
2483 /* NIP cannot be restored if the memory exception comes from an helper */
2484 gen_update_nip(ctx
, ctx
->nip
- 4);
2485 gen_addr_imm_index(ctx
, 0);
2486 op_ldstm(lmw
, rD(ctx
->opcode
));
2490 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
2492 /* NIP cannot be restored if the memory exception comes from an helper */
2493 gen_update_nip(ctx
, ctx
->nip
- 4);
2494 gen_addr_imm_index(ctx
, 0);
2495 op_ldstm(stmw
, rS(ctx
->opcode
));
2498 /*** Integer load and store strings ***/
2499 #define op_ldsts(name, start) (*gen_op_##name[ctx->mem_idx])(start)
2500 #define op_ldstsx(name, rd, ra, rb) (*gen_op_##name[ctx->mem_idx])(rd, ra, rb)
2501 #if defined(CONFIG_USER_ONLY)
2502 /* User-mode only */
2503 static GenOpFunc1
*gen_op_lswi
[] = {
2505 &gen_op_lswi_le_raw
,
2506 #if defined(TARGET_PPC64)
2507 &gen_op_lswi_64_raw
,
2508 &gen_op_lswi_le_64_raw
,
2511 static GenOpFunc3
*gen_op_lswx
[] = {
2513 &gen_op_lswx_le_raw
,
2514 #if defined(TARGET_PPC64)
2515 &gen_op_lswx_64_raw
,
2516 &gen_op_lswx_le_64_raw
,
2519 static GenOpFunc1
*gen_op_stsw
[] = {
2521 &gen_op_stsw_le_raw
,
2522 #if defined(TARGET_PPC64)
2523 &gen_op_stsw_64_raw
,
2524 &gen_op_stsw_le_64_raw
,
2528 #if defined(TARGET_PPC64)
2529 /* Full system - 64 bits mode */
2530 static GenOpFunc1
*gen_op_lswi
[] = {
2532 &gen_op_lswi_le_user
,
2533 &gen_op_lswi_64_user
,
2534 &gen_op_lswi_le_64_user
,
2535 &gen_op_lswi_kernel
,
2536 &gen_op_lswi_le_kernel
,
2537 &gen_op_lswi_64_kernel
,
2538 &gen_op_lswi_le_64_kernel
,
2539 #if defined(TARGET_PPC64H)
2541 &gen_op_lswi_le_hypv
,
2542 &gen_op_lswi_64_hypv
,
2543 &gen_op_lswi_le_64_hypv
,
2546 static GenOpFunc3
*gen_op_lswx
[] = {
2548 &gen_op_lswx_le_user
,
2549 &gen_op_lswx_64_user
,
2550 &gen_op_lswx_le_64_user
,
2551 &gen_op_lswx_kernel
,
2552 &gen_op_lswx_le_kernel
,
2553 &gen_op_lswx_64_kernel
,
2554 &gen_op_lswx_le_64_kernel
,
2555 #if defined(TARGET_PPC64H)
2557 &gen_op_lswx_le_hypv
,
2558 &gen_op_lswx_64_hypv
,
2559 &gen_op_lswx_le_64_hypv
,
2562 static GenOpFunc1
*gen_op_stsw
[] = {
2564 &gen_op_stsw_le_user
,
2565 &gen_op_stsw_64_user
,
2566 &gen_op_stsw_le_64_user
,
2567 &gen_op_stsw_kernel
,
2568 &gen_op_stsw_le_kernel
,
2569 &gen_op_stsw_64_kernel
,
2570 &gen_op_stsw_le_64_kernel
,
2571 #if defined(TARGET_PPC64H)
2573 &gen_op_stsw_le_hypv
,
2574 &gen_op_stsw_64_hypv
,
2575 &gen_op_stsw_le_64_hypv
,
2579 /* Full system - 32 bits mode */
2580 static GenOpFunc1
*gen_op_lswi
[] = {
2582 &gen_op_lswi_le_user
,
2583 &gen_op_lswi_kernel
,
2584 &gen_op_lswi_le_kernel
,
2586 static GenOpFunc3
*gen_op_lswx
[] = {
2588 &gen_op_lswx_le_user
,
2589 &gen_op_lswx_kernel
,
2590 &gen_op_lswx_le_kernel
,
2592 static GenOpFunc1
*gen_op_stsw
[] = {
2594 &gen_op_stsw_le_user
,
2595 &gen_op_stsw_kernel
,
2596 &gen_op_stsw_le_kernel
,
2602 /* PowerPC32 specification says we must generate an exception if
2603 * rA is in the range of registers to be loaded.
2604 * In an other hand, IBM says this is valid, but rA won't be loaded.
2605 * For now, I'll follow the spec...
2607 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_INTEGER
)
2609 int nb
= NB(ctx
->opcode
);
2610 int start
= rD(ctx
->opcode
);
2611 int ra
= rA(ctx
->opcode
);
2617 if (unlikely(((start
+ nr
) > 32 &&
2618 start
<= ra
&& (start
+ nr
- 32) > ra
) ||
2619 ((start
+ nr
) <= 32 && start
<= ra
&& (start
+ nr
) > ra
))) {
2620 GEN_EXCP(ctx
, POWERPC_EXCP_PROGRAM
,
2621 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_LSWX
);
2624 /* NIP cannot be restored if the memory exception comes from an helper */
2625 gen_update_nip(ctx
, ctx
->nip
- 4);
2626 gen_addr_register(ctx
);
2628 op_ldsts(lswi
, start
);
2632 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_INTEGER
)
2634 int ra
= rA(ctx
->opcode
);
2635 int rb
= rB(ctx
->opcode
);
2637 /* NIP cannot be restored if the memory exception comes from an helper */
2638 gen_update_nip(ctx
, ctx
->nip
- 4);
2639 gen_addr_reg_index(ctx
);
2643 gen_op_load_xer_bc();
2644 op_ldstsx(lswx
, rD(ctx
->opcode
), ra
, rb
);
2648 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_INTEGER
)
2650 int nb
= NB(ctx
->opcode
);
2652 /* NIP cannot be restored if the memory exception comes from an helper */
2653 gen_update_nip(ctx
, ctx
->nip
- 4);
2654 gen_addr_register(ctx
);
2658 op_ldsts(stsw
, rS(ctx
->opcode
));
2662 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_INTEGER
)
2664 /* NIP cannot be restored if the memory exception comes from an helper */
2665 gen_update_nip(ctx
, ctx
->nip
- 4);
2666 gen_addr_reg_index(ctx
);
2667 gen_op_load_xer_bc();
2668 op_ldsts(stsw
, rS(ctx
->opcode
));
2671 /*** Memory synchronisation ***/
2673 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO
)
2678 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
)
2683 #define op_lwarx() (*gen_op_lwarx[ctx->mem_idx])()
2684 #define op_stwcx() (*gen_op_stwcx[ctx->mem_idx])()
2685 #if defined(CONFIG_USER_ONLY)
2686 /* User-mode only */
2687 static GenOpFunc
*gen_op_lwarx
[] = {
2689 &gen_op_lwarx_le_raw
,
2690 #if defined(TARGET_PPC64)
2691 &gen_op_lwarx_64_raw
,
2692 &gen_op_lwarx_le_64_raw
,
2695 static GenOpFunc
*gen_op_stwcx
[] = {
2697 &gen_op_stwcx_le_raw
,
2698 #if defined(TARGET_PPC64)
2699 &gen_op_stwcx_64_raw
,
2700 &gen_op_stwcx_le_64_raw
,
2704 #if defined(TARGET_PPC64)
2705 /* Full system - 64 bits mode */
2706 static GenOpFunc
*gen_op_lwarx
[] = {
2708 &gen_op_lwarx_le_user
,
2709 &gen_op_lwarx_64_user
,
2710 &gen_op_lwarx_le_64_user
,
2711 &gen_op_lwarx_kernel
,
2712 &gen_op_lwarx_le_kernel
,
2713 &gen_op_lwarx_64_kernel
,
2714 &gen_op_lwarx_le_64_kernel
,
2715 #if defined(TARGET_PPC64H)
2717 &gen_op_lwarx_le_hypv
,
2718 &gen_op_lwarx_64_hypv
,
2719 &gen_op_lwarx_le_64_hypv
,
2722 static GenOpFunc
*gen_op_stwcx
[] = {
2724 &gen_op_stwcx_le_user
,
2725 &gen_op_stwcx_64_user
,
2726 &gen_op_stwcx_le_64_user
,
2727 &gen_op_stwcx_kernel
,
2728 &gen_op_stwcx_le_kernel
,
2729 &gen_op_stwcx_64_kernel
,
2730 &gen_op_stwcx_le_64_kernel
,
2731 #if defined(TARGET_PPC64H)
2733 &gen_op_stwcx_le_hypv
,
2734 &gen_op_stwcx_64_hypv
,
2735 &gen_op_stwcx_le_64_hypv
,
2739 /* Full system - 32 bits mode */
2740 static GenOpFunc
*gen_op_lwarx
[] = {
2742 &gen_op_lwarx_le_user
,
2743 &gen_op_lwarx_kernel
,
2744 &gen_op_lwarx_le_kernel
,
2746 static GenOpFunc
*gen_op_stwcx
[] = {
2748 &gen_op_stwcx_le_user
,
2749 &gen_op_stwcx_kernel
,
2750 &gen_op_stwcx_le_kernel
,
2756 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000001, PPC_RES
)
2758 /* NIP cannot be restored if the memory exception comes from an helper */
2759 gen_update_nip(ctx
, ctx
->nip
- 4);
2760 gen_addr_reg_index(ctx
);
2762 gen_op_store_T1_gpr(rD(ctx
->opcode
));
2766 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
)
2768 /* NIP cannot be restored if the memory exception comes from an helper */
2769 gen_update_nip(ctx
, ctx
->nip
- 4);
2770 gen_addr_reg_index(ctx
);
2771 gen_op_load_gpr_T1(rS(ctx
->opcode
));
2775 #if defined(TARGET_PPC64)
2776 #define op_ldarx() (*gen_op_ldarx[ctx->mem_idx])()
2777 #define op_stdcx() (*gen_op_stdcx[ctx->mem_idx])()
2778 #if defined(CONFIG_USER_ONLY)
2779 /* User-mode only */
2780 static GenOpFunc
*gen_op_ldarx
[] = {
2782 &gen_op_ldarx_le_raw
,
2783 &gen_op_ldarx_64_raw
,
2784 &gen_op_ldarx_le_64_raw
,
2786 static GenOpFunc
*gen_op_stdcx
[] = {
2788 &gen_op_stdcx_le_raw
,
2789 &gen_op_stdcx_64_raw
,
2790 &gen_op_stdcx_le_64_raw
,
2794 static GenOpFunc
*gen_op_ldarx
[] = {
2796 &gen_op_ldarx_le_user
,
2797 &gen_op_ldarx_64_user
,
2798 &gen_op_ldarx_le_64_user
,
2799 &gen_op_ldarx_kernel
,
2800 &gen_op_ldarx_le_kernel
,
2801 &gen_op_ldarx_64_kernel
,
2802 &gen_op_ldarx_le_64_kernel
,
2803 #if defined(TARGET_PPC64H)
2805 &gen_op_ldarx_le_hypv
,
2806 &gen_op_ldarx_64_hypv
,
2807 &gen_op_ldarx_le_64_hypv
,
2810 static GenOpFunc
*gen_op_stdcx
[] = {
2812 &gen_op_stdcx_le_user
,
2813 &gen_op_stdcx_64_user
,
2814 &gen_op_stdcx_le_64_user
,
2815 &gen_op_stdcx_kernel
,
2816 &gen_op_stdcx_le_kernel
,
2817 &gen_op_stdcx_64_kernel
,
2818 &gen_op_stdcx_le_64_kernel
,
2819 #if defined(TARGET_PPC64H)
2821 &gen_op_stdcx_le_hypv
,
2822 &gen_op_stdcx_64_hypv
,
2823 &gen_op_stdcx_le_64_hypv
,
2829 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000001, PPC_64B
)
2831 /* NIP cannot be restored if the memory exception comes from an helper */
2832 gen_update_nip(ctx
, ctx
->nip
- 4);
2833 gen_addr_reg_index(ctx
);
2835 gen_op_store_T1_gpr(rD(ctx
->opcode
));
2839 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
)
2841 /* NIP cannot be restored if the memory exception comes from an helper */
2842 gen_update_nip(ctx
, ctx
->nip
- 4);
2843 gen_addr_reg_index(ctx
);
2844 gen_op_load_gpr_T1(rS(ctx
->opcode
));
2847 #endif /* defined(TARGET_PPC64) */
2850 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
)
2855 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
)
2857 /* Stop translation, as the CPU is supposed to sleep from now */
2859 GEN_EXCP(ctx
, EXCP_HLT
, 1);
2862 /*** Floating-point load ***/
2863 #define GEN_LDF(width, opc, type) \
2864 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2866 if (unlikely(!ctx->fpu_enabled)) { \
2867 GEN_EXCP_NO_FP(ctx); \
2870 gen_addr_imm_index(ctx, 0); \
2871 op_ldst(l##width); \
2872 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
2875 #define GEN_LDUF(width, opc, type) \
2876 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2878 if (unlikely(!ctx->fpu_enabled)) { \
2879 GEN_EXCP_NO_FP(ctx); \
2882 if (unlikely(rA(ctx->opcode) == 0)) { \
2883 GEN_EXCP_INVAL(ctx); \
2886 gen_addr_imm_index(ctx, 0); \
2887 op_ldst(l##width); \
2888 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
2889 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2892 #define GEN_LDUXF(width, opc, type) \
2893 GEN_HANDLER(l##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \
2895 if (unlikely(!ctx->fpu_enabled)) { \
2896 GEN_EXCP_NO_FP(ctx); \
2899 if (unlikely(rA(ctx->opcode) == 0)) { \
2900 GEN_EXCP_INVAL(ctx); \
2903 gen_addr_reg_index(ctx); \
2904 op_ldst(l##width); \
2905 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
2906 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2909 #define GEN_LDXF(width, opc2, opc3, type) \
2910 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2912 if (unlikely(!ctx->fpu_enabled)) { \
2913 GEN_EXCP_NO_FP(ctx); \
2916 gen_addr_reg_index(ctx); \
2917 op_ldst(l##width); \
2918 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
2921 #define GEN_LDFS(width, op, type) \
2922 OP_LD_TABLE(width); \
2923 GEN_LDF(width, op | 0x20, type); \
2924 GEN_LDUF(width, op | 0x21, type); \
2925 GEN_LDUXF(width, op | 0x01, type); \
2926 GEN_LDXF(width, 0x17, op | 0x00, type)
2928 /* lfd lfdu lfdux lfdx */
2929 GEN_LDFS(fd
, 0x12, PPC_FLOAT
);
2930 /* lfs lfsu lfsux lfsx */
2931 GEN_LDFS(fs
, 0x10, PPC_FLOAT
);
2933 /*** Floating-point store ***/
2934 #define GEN_STF(width, opc, type) \
2935 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2937 if (unlikely(!ctx->fpu_enabled)) { \
2938 GEN_EXCP_NO_FP(ctx); \
2941 gen_addr_imm_index(ctx, 0); \
2942 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
2943 op_ldst(st##width); \
2946 #define GEN_STUF(width, opc, type) \
2947 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2949 if (unlikely(!ctx->fpu_enabled)) { \
2950 GEN_EXCP_NO_FP(ctx); \
2953 if (unlikely(rA(ctx->opcode) == 0)) { \
2954 GEN_EXCP_INVAL(ctx); \
2957 gen_addr_imm_index(ctx, 0); \
2958 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
2959 op_ldst(st##width); \
2960 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2963 #define GEN_STUXF(width, opc, type) \
2964 GEN_HANDLER(st##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \
2966 if (unlikely(!ctx->fpu_enabled)) { \
2967 GEN_EXCP_NO_FP(ctx); \
2970 if (unlikely(rA(ctx->opcode) == 0)) { \
2971 GEN_EXCP_INVAL(ctx); \
2974 gen_addr_reg_index(ctx); \
2975 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
2976 op_ldst(st##width); \
2977 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2980 #define GEN_STXF(width, opc2, opc3, type) \
2981 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2983 if (unlikely(!ctx->fpu_enabled)) { \
2984 GEN_EXCP_NO_FP(ctx); \
2987 gen_addr_reg_index(ctx); \
2988 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
2989 op_ldst(st##width); \
2992 #define GEN_STFS(width, op, type) \
2993 OP_ST_TABLE(width); \
2994 GEN_STF(width, op | 0x20, type); \
2995 GEN_STUF(width, op | 0x21, type); \
2996 GEN_STUXF(width, op | 0x01, type); \
2997 GEN_STXF(width, 0x17, op | 0x00, type)
2999 /* stfd stfdu stfdux stfdx */
3000 GEN_STFS(fd
, 0x16, PPC_FLOAT
);
3001 /* stfs stfsu stfsux stfsx */
3002 GEN_STFS(fs
, 0x14, PPC_FLOAT
);
3007 GEN_STXF(fiwx
, 0x17, 0x1E, PPC_FLOAT_STFIWX
);
3010 static always_inline
void gen_goto_tb (DisasContext
*ctx
, int n
,
3013 TranslationBlock
*tb
;
3015 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
)) {
3017 gen_op_goto_tb0(TBPARAM(tb
));
3019 gen_op_goto_tb1(TBPARAM(tb
));
3021 #if defined(TARGET_PPC64)
3027 gen_op_set_T0((long)tb
+ n
);
3028 if (ctx
->singlestep_enabled
)
3033 #if defined(TARGET_PPC64)
3040 if (ctx
->singlestep_enabled
)
3046 static always_inline
void gen_setlr (DisasContext
*ctx
, target_ulong nip
)
3048 #if defined(TARGET_PPC64)
3049 if (ctx
->sf_mode
!= 0 && (nip
>> 32))
3050 gen_op_setlr_64(ctx
->nip
>> 32, ctx
->nip
);
3053 gen_op_setlr(ctx
->nip
);
3057 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
3059 target_ulong li
, target
;
3061 /* sign extend LI */
3062 #if defined(TARGET_PPC64)
3064 li
= ((int64_t)LI(ctx
->opcode
) << 38) >> 38;
3067 li
= ((int32_t)LI(ctx
->opcode
) << 6) >> 6;
3068 if (likely(AA(ctx
->opcode
) == 0))
3069 target
= ctx
->nip
+ li
- 4;
3072 #if defined(TARGET_PPC64)
3074 target
= (uint32_t)target
;
3076 if (LK(ctx
->opcode
))
3077 gen_setlr(ctx
, ctx
->nip
);
3078 gen_goto_tb(ctx
, 0, target
);
3079 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3086 static always_inline
void gen_bcond (DisasContext
*ctx
, int type
)
3088 target_ulong target
= 0;
3090 uint32_t bo
= BO(ctx
->opcode
);
3091 uint32_t bi
= BI(ctx
->opcode
);
3094 if ((bo
& 0x4) == 0)
3098 li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
3099 if (likely(AA(ctx
->opcode
) == 0)) {
3100 target
= ctx
->nip
+ li
- 4;
3104 #if defined(TARGET_PPC64)
3106 target
= (uint32_t)target
;
3110 gen_op_movl_T1_ctr();
3114 gen_op_movl_T1_lr();
3117 if (LK(ctx
->opcode
))
3118 gen_setlr(ctx
, ctx
->nip
);
3120 /* No CR condition */
3123 #if defined(TARGET_PPC64)
3125 gen_op_test_ctr_64();
3131 #if defined(TARGET_PPC64)
3133 gen_op_test_ctrz_64();
3141 if (type
== BCOND_IM
) {
3142 gen_goto_tb(ctx
, 0, target
);
3145 #if defined(TARGET_PPC64)
3157 mask
= 1 << (3 - (bi
& 0x03));
3158 gen_op_load_crf_T0(bi
>> 2);
3162 #if defined(TARGET_PPC64)
3164 gen_op_test_ctr_true_64(mask
);
3167 gen_op_test_ctr_true(mask
);
3170 #if defined(TARGET_PPC64)
3172 gen_op_test_ctrz_true_64(mask
);
3175 gen_op_test_ctrz_true(mask
);
3180 gen_op_test_true(mask
);
3186 #if defined(TARGET_PPC64)
3188 gen_op_test_ctr_false_64(mask
);
3191 gen_op_test_ctr_false(mask
);
3194 #if defined(TARGET_PPC64)
3196 gen_op_test_ctrz_false_64(mask
);
3199 gen_op_test_ctrz_false(mask
);
3204 gen_op_test_false(mask
);
3209 if (type
== BCOND_IM
) {
3210 int l1
= gen_new_label();
3212 gen_goto_tb(ctx
, 0, target
);
3214 gen_goto_tb(ctx
, 1, ctx
->nip
);
3216 #if defined(TARGET_PPC64)
3218 gen_op_btest_T1_64(ctx
->nip
>> 32, ctx
->nip
);
3221 gen_op_btest_T1(ctx
->nip
);
3224 if (ctx
->singlestep_enabled
)
3229 ctx
->exception
= POWERPC_EXCP_BRANCH
;
3232 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
3234 gen_bcond(ctx
, BCOND_IM
);
3237 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
)
3239 gen_bcond(ctx
, BCOND_CTR
);
3242 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
)
3244 gen_bcond(ctx
, BCOND_LR
);
3247 /*** Condition register logical ***/
3248 #define GEN_CRLOGIC(op, opc) \
3249 GEN_HANDLER(cr##op, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) \
3251 gen_op_load_crf_T0(crbA(ctx->opcode) >> 2); \
3252 gen_op_getbit_T0(3 - (crbA(ctx->opcode) & 0x03)); \
3253 gen_op_load_crf_T1(crbB(ctx->opcode) >> 2); \
3254 gen_op_getbit_T1(3 - (crbB(ctx->opcode) & 0x03)); \
3256 gen_op_load_crf_T1(crbD(ctx->opcode) >> 2); \
3257 gen_op_setcrfbit(~(1 << (3 - (crbD(ctx->opcode) & 0x03))), \
3258 3 - (crbD(ctx->opcode) & 0x03)); \
3259 gen_op_store_T1_crf(crbD(ctx->opcode) >> 2); \
3263 GEN_CRLOGIC(and, 0x08);
3265 GEN_CRLOGIC(andc
, 0x04);
3267 GEN_CRLOGIC(eqv
, 0x09);
3269 GEN_CRLOGIC(nand
, 0x07);
3271 GEN_CRLOGIC(nor
, 0x01);
3273 GEN_CRLOGIC(or, 0x0E);
3275 GEN_CRLOGIC(orc
, 0x0D);
3277 GEN_CRLOGIC(xor, 0x06);
3279 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
)
3281 gen_op_load_crf_T0(crfS(ctx
->opcode
));
3282 gen_op_store_T0_crf(crfD(ctx
->opcode
));
3285 /*** System linkage ***/
3286 /* rfi (supervisor only) */
3287 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
)
3289 #if defined(CONFIG_USER_ONLY)
3290 GEN_EXCP_PRIVOPC(ctx
);
3292 /* Restore CPU state */
3293 if (unlikely(!ctx
->supervisor
)) {
3294 GEN_EXCP_PRIVOPC(ctx
);
3302 #if defined(TARGET_PPC64)
3303 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
)
3305 #if defined(CONFIG_USER_ONLY)
3306 GEN_EXCP_PRIVOPC(ctx
);
3308 /* Restore CPU state */
3309 if (unlikely(!ctx
->supervisor
)) {
3310 GEN_EXCP_PRIVOPC(ctx
);
3319 #if defined(TARGET_PPC64H)
3320 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64B
)
3322 #if defined(CONFIG_USER_ONLY)
3323 GEN_EXCP_PRIVOPC(ctx
);
3325 /* Restore CPU state */
3326 if (unlikely(ctx
->supervisor
<= 1)) {
3327 GEN_EXCP_PRIVOPC(ctx
);
3337 #if defined(CONFIG_USER_ONLY)
3338 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3340 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3342 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW
)
3346 lev
= (ctx
->opcode
>> 5) & 0x7F;
3347 GEN_EXCP(ctx
, POWERPC_SYSCALL
, lev
);
3352 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
)
3354 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3355 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3356 /* Update the nip since this might generate a trap exception */
3357 gen_update_nip(ctx
, ctx
->nip
);
3358 gen_op_tw(TO(ctx
->opcode
));
3362 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
3364 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3365 gen_set_T1(SIMM(ctx
->opcode
));
3366 /* Update the nip since this might generate a trap exception */
3367 gen_update_nip(ctx
, ctx
->nip
);
3368 gen_op_tw(TO(ctx
->opcode
));
3371 #if defined(TARGET_PPC64)
3373 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
)
3375 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3376 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3377 /* Update the nip since this might generate a trap exception */
3378 gen_update_nip(ctx
, ctx
->nip
);
3379 gen_op_td(TO(ctx
->opcode
));
3383 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
)
3385 gen_op_load_gpr_T0(rA(ctx
->opcode
));
3386 gen_set_T1(SIMM(ctx
->opcode
));
3387 /* Update the nip since this might generate a trap exception */
3388 gen_update_nip(ctx
, ctx
->nip
);
3389 gen_op_td(TO(ctx
->opcode
));
3393 /*** Processor control ***/
3395 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
)
3397 gen_op_load_xer_cr();
3398 gen_op_store_T0_crf(crfD(ctx
->opcode
));
3399 gen_op_clear_xer_ov();
3400 gen_op_clear_xer_ca();
3404 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
)
3408 if (likely(ctx
->opcode
& 0x00100000)) {
3409 crm
= CRM(ctx
->opcode
);
3410 if (likely((crm
^ (crm
- 1)) == 0)) {
3412 gen_op_load_cro(7 - crn
);
3417 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3421 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
)
3423 #if defined(CONFIG_USER_ONLY)
3424 GEN_EXCP_PRIVREG(ctx
);
3426 if (unlikely(!ctx
->supervisor
)) {
3427 GEN_EXCP_PRIVREG(ctx
);
3431 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3436 #define SPR_NOACCESS ((void *)(-1))
3438 static void spr_noaccess (void *opaque
, int sprn
)
3440 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
3441 printf("ERROR: try to access SPR %d !\n", sprn
);
3443 #define SPR_NOACCESS (&spr_noaccess)
3447 static always_inline
void gen_op_mfspr (DisasContext
*ctx
)
3449 void (*read_cb
)(void *opaque
, int sprn
);
3450 uint32_t sprn
= SPR(ctx
->opcode
);
3452 #if !defined(CONFIG_USER_ONLY)
3453 #if defined(TARGET_PPC64H)
3454 if (ctx
->supervisor
== 2)
3455 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
3458 if (ctx
->supervisor
)
3459 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
3462 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
3463 if (likely(read_cb
!= NULL
)) {
3464 if (likely(read_cb
!= SPR_NOACCESS
)) {
3465 (*read_cb
)(ctx
, sprn
);
3466 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3468 /* Privilege exception */
3469 if (loglevel
!= 0) {
3470 fprintf(logfile
, "Trying to read privileged spr %d %03x\n",
3473 printf("Trying to read privileged spr %d %03x\n", sprn
, sprn
);
3474 GEN_EXCP_PRIVREG(ctx
);
3478 if (loglevel
!= 0) {
3479 fprintf(logfile
, "Trying to read invalid spr %d %03x\n",
3482 printf("Trying to read invalid spr %d %03x\n", sprn
, sprn
);
3483 GEN_EXCP(ctx
, POWERPC_EXCP_PROGRAM
,
3484 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_SPR
);
3488 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
)
3494 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
)
3500 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
)
3504 gen_op_load_gpr_T0(rS(ctx
->opcode
));
3505 crm
= CRM(ctx
->opcode
);
3506 if (likely((ctx
->opcode
& 0x00100000) || (crm
^ (crm
- 1)) == 0)) {
3508 gen_op_srli_T0(crn
* 4);
3509 gen_op_andi_T0(0xF);
3510 gen_op_store_cro(7 - crn
);
3512 gen_op_store_cr(crm
);
3517 #if defined(TARGET_PPC64)
3518 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
)
3520 #if defined(CONFIG_USER_ONLY)
3521 GEN_EXCP_PRIVREG(ctx
);
3523 if (unlikely(!ctx
->supervisor
)) {
3524 GEN_EXCP_PRIVREG(ctx
);
3527 gen_op_load_gpr_T0(rS(ctx
->opcode
));
3528 if (ctx
->opcode
& 0x00010000) {
3529 /* Special form that does not need any synchronisation */
3530 gen_op_update_riee();
3532 /* XXX: we need to update nip before the store
3533 * if we enter power saving mode, we will exit the loop
3534 * directly from ppc_store_msr
3536 gen_update_nip(ctx
, ctx
->nip
);
3538 /* Must stop the translation as machine state (may have) changed */
3539 /* Note that mtmsr is not always defined as context-synchronizing */
3540 ctx
->exception
= POWERPC_EXCP_STOP
;
3546 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC
)
3548 #if defined(CONFIG_USER_ONLY)
3549 GEN_EXCP_PRIVREG(ctx
);
3551 if (unlikely(!ctx
->supervisor
)) {
3552 GEN_EXCP_PRIVREG(ctx
);
3555 gen_op_load_gpr_T0(rS(ctx
->opcode
));
3556 if (ctx
->opcode
& 0x00010000) {
3557 /* Special form that does not need any synchronisation */
3558 gen_op_update_riee();
3560 /* XXX: we need to update nip before the store
3561 * if we enter power saving mode, we will exit the loop
3562 * directly from ppc_store_msr
3564 gen_update_nip(ctx
, ctx
->nip
);
3565 #if defined(TARGET_PPC64)
3567 gen_op_store_msr_32();
3571 /* Must stop the translation as machine state (may have) changed */
3572 /* Note that mtmsrd is not always defined as context-synchronizing */
3573 ctx
->exception
= POWERPC_EXCP_STOP
;
3579 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC
)
3581 void (*write_cb
)(void *opaque
, int sprn
);
3582 uint32_t sprn
= SPR(ctx
->opcode
);
3584 #if !defined(CONFIG_USER_ONLY)
3585 #if defined(TARGET_PPC64H)
3586 if (ctx
->supervisor
== 2)
3587 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
3590 if (ctx
->supervisor
)
3591 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
3594 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
3595 if (likely(write_cb
!= NULL
)) {
3596 if (likely(write_cb
!= SPR_NOACCESS
)) {
3597 gen_op_load_gpr_T0(rS(ctx
->opcode
));
3598 (*write_cb
)(ctx
, sprn
);
3600 /* Privilege exception */
3601 if (loglevel
!= 0) {
3602 fprintf(logfile
, "Trying to write privileged spr %d %03x\n",
3605 printf("Trying to write privileged spr %d %03x\n", sprn
, sprn
);
3606 GEN_EXCP_PRIVREG(ctx
);
3610 if (loglevel
!= 0) {
3611 fprintf(logfile
, "Trying to write invalid spr %d %03x\n",
3614 printf("Trying to write invalid spr %d %03x\n", sprn
, sprn
);
3615 GEN_EXCP(ctx
, POWERPC_EXCP_PROGRAM
,
3616 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_SPR
);
3620 /*** Cache management ***/
3621 /* For now, all those will be implemented as nop:
3622 * this is valid, regarding the PowerPC specs...
3623 * We just have to flush tb while invalidating instruction cache lines...
3626 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
)
3628 gen_addr_reg_index(ctx
);
3632 /* dcbi (Supervisor only) */
3633 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
)
3635 #if defined(CONFIG_USER_ONLY)
3636 GEN_EXCP_PRIVOPC(ctx
);
3638 if (unlikely(!ctx
->supervisor
)) {
3639 GEN_EXCP_PRIVOPC(ctx
);
3642 gen_addr_reg_index(ctx
);
3643 /* XXX: specification says this should be treated as a store by the MMU */
3650 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
)
3652 /* XXX: specification say this is treated as a load by the MMU */
3653 gen_addr_reg_index(ctx
);
3658 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE
)
3660 /* interpreted as no-op */
3661 /* XXX: specification say this is treated as a load by the MMU
3662 * but does not generate any exception
3667 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE
)
3669 /* interpreted as no-op */
3670 /* XXX: specification say this is treated as a load by the MMU
3671 * but does not generate any exception
3676 #define op_dcbz(n) (*gen_op_dcbz[n][ctx->mem_idx])()
3677 #if defined(CONFIG_USER_ONLY)
3678 /* User-mode only */
3679 static GenOpFunc
*gen_op_dcbz
[4][4] = {
3681 &gen_op_dcbz_l32_raw
,
3682 &gen_op_dcbz_l32_raw
,
3683 #if defined(TARGET_PPC64)
3684 &gen_op_dcbz_l32_64_raw
,
3685 &gen_op_dcbz_l32_64_raw
,
3689 &gen_op_dcbz_l64_raw
,
3690 &gen_op_dcbz_l64_raw
,
3691 #if defined(TARGET_PPC64)
3692 &gen_op_dcbz_l64_64_raw
,
3693 &gen_op_dcbz_l64_64_raw
,
3697 &gen_op_dcbz_l128_raw
,
3698 &gen_op_dcbz_l128_raw
,
3699 #if defined(TARGET_PPC64)
3700 &gen_op_dcbz_l128_64_raw
,
3701 &gen_op_dcbz_l128_64_raw
,
3707 #if defined(TARGET_PPC64)
3708 &gen_op_dcbz_64_raw
,
3709 &gen_op_dcbz_64_raw
,
3714 #if defined(TARGET_PPC64)
3715 /* Full system - 64 bits mode */
3716 static GenOpFunc
*gen_op_dcbz
[4][12] = {
3718 &gen_op_dcbz_l32_user
,
3719 &gen_op_dcbz_l32_user
,
3720 &gen_op_dcbz_l32_64_user
,
3721 &gen_op_dcbz_l32_64_user
,
3722 &gen_op_dcbz_l32_kernel
,
3723 &gen_op_dcbz_l32_kernel
,
3724 &gen_op_dcbz_l32_64_kernel
,
3725 &gen_op_dcbz_l32_64_kernel
,
3726 #if defined(TARGET_PPC64H)
3727 &gen_op_dcbz_l32_hypv
,
3728 &gen_op_dcbz_l32_hypv
,
3729 &gen_op_dcbz_l32_64_hypv
,
3730 &gen_op_dcbz_l32_64_hypv
,
3734 &gen_op_dcbz_l64_user
,
3735 &gen_op_dcbz_l64_user
,
3736 &gen_op_dcbz_l64_64_user
,
3737 &gen_op_dcbz_l64_64_user
,
3738 &gen_op_dcbz_l64_kernel
,
3739 &gen_op_dcbz_l64_kernel
,
3740 &gen_op_dcbz_l64_64_kernel
,
3741 &gen_op_dcbz_l64_64_kernel
,
3742 #if defined(TARGET_PPC64H)
3743 &gen_op_dcbz_l64_hypv
,
3744 &gen_op_dcbz_l64_hypv
,
3745 &gen_op_dcbz_l64_64_hypv
,
3746 &gen_op_dcbz_l64_64_hypv
,
3750 &gen_op_dcbz_l128_user
,
3751 &gen_op_dcbz_l128_user
,
3752 &gen_op_dcbz_l128_64_user
,
3753 &gen_op_dcbz_l128_64_user
,
3754 &gen_op_dcbz_l128_kernel
,
3755 &gen_op_dcbz_l128_kernel
,
3756 &gen_op_dcbz_l128_64_kernel
,
3757 &gen_op_dcbz_l128_64_kernel
,
3758 #if defined(TARGET_PPC64H)
3759 &gen_op_dcbz_l128_hypv
,
3760 &gen_op_dcbz_l128_hypv
,
3761 &gen_op_dcbz_l128_64_hypv
,
3762 &gen_op_dcbz_l128_64_hypv
,
3768 &gen_op_dcbz_64_user
,
3769 &gen_op_dcbz_64_user
,
3770 &gen_op_dcbz_kernel
,
3771 &gen_op_dcbz_kernel
,
3772 &gen_op_dcbz_64_kernel
,
3773 &gen_op_dcbz_64_kernel
,
3774 #if defined(TARGET_PPC64H)
3777 &gen_op_dcbz_64_hypv
,
3778 &gen_op_dcbz_64_hypv
,
3783 /* Full system - 32 bits mode */
3784 static GenOpFunc
*gen_op_dcbz
[4][4] = {
3786 &gen_op_dcbz_l32_user
,
3787 &gen_op_dcbz_l32_user
,
3788 &gen_op_dcbz_l32_kernel
,
3789 &gen_op_dcbz_l32_kernel
,
3792 &gen_op_dcbz_l64_user
,
3793 &gen_op_dcbz_l64_user
,
3794 &gen_op_dcbz_l64_kernel
,
3795 &gen_op_dcbz_l64_kernel
,
3798 &gen_op_dcbz_l128_user
,
3799 &gen_op_dcbz_l128_user
,
3800 &gen_op_dcbz_l128_kernel
,
3801 &gen_op_dcbz_l128_kernel
,
3806 &gen_op_dcbz_kernel
,
3807 &gen_op_dcbz_kernel
,
3813 static always_inline
void handler_dcbz (DisasContext
*ctx
,
3814 int dcache_line_size
)
3818 switch (dcache_line_size
) {
3835 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE_DCBZ
)
3837 gen_addr_reg_index(ctx
);
3838 handler_dcbz(ctx
, ctx
->dcache_line_size
);
3839 gen_op_check_reservation();
3842 GEN_HANDLER2(dcbz_970
, "dcbz", 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZT
)
3844 gen_addr_reg_index(ctx
);
3845 if (ctx
->opcode
& 0x00200000)
3846 handler_dcbz(ctx
, ctx
->dcache_line_size
);
3848 handler_dcbz(ctx
, -1);
3849 gen_op_check_reservation();
3853 #define op_icbi() (*gen_op_icbi[ctx->mem_idx])()
3854 #if defined(CONFIG_USER_ONLY)
3855 /* User-mode only */
3856 static GenOpFunc
*gen_op_icbi
[] = {
3859 #if defined(TARGET_PPC64)
3860 &gen_op_icbi_64_raw
,
3861 &gen_op_icbi_64_raw
,
3865 /* Full system - 64 bits mode */
3866 #if defined(TARGET_PPC64)
3867 static GenOpFunc
*gen_op_icbi
[] = {
3870 &gen_op_icbi_64_user
,
3871 &gen_op_icbi_64_user
,
3872 &gen_op_icbi_kernel
,
3873 &gen_op_icbi_kernel
,
3874 &gen_op_icbi_64_kernel
,
3875 &gen_op_icbi_64_kernel
,
3876 #if defined(TARGET_PPC64H)
3879 &gen_op_icbi_64_hypv
,
3880 &gen_op_icbi_64_hypv
,
3884 /* Full system - 32 bits mode */
3885 static GenOpFunc
*gen_op_icbi
[] = {
3888 &gen_op_icbi_kernel
,
3889 &gen_op_icbi_kernel
,
3894 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE
)
3896 /* NIP cannot be restored if the memory exception comes from an helper */
3897 gen_update_nip(ctx
, ctx
->nip
- 4);
3898 gen_addr_reg_index(ctx
);
3904 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
)
3906 /* interpreted as no-op */
3907 /* XXX: specification say this is treated as a store by the MMU
3908 * but does not generate any exception
3912 /*** Segment register manipulation ***/
3913 /* Supervisor only: */
3915 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
)
3917 #if defined(CONFIG_USER_ONLY)
3918 GEN_EXCP_PRIVREG(ctx
);
3920 if (unlikely(!ctx
->supervisor
)) {
3921 GEN_EXCP_PRIVREG(ctx
);
3924 gen_op_set_T1(SR(ctx
->opcode
));
3926 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3931 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
)
3933 #if defined(CONFIG_USER_ONLY)
3934 GEN_EXCP_PRIVREG(ctx
);
3936 if (unlikely(!ctx
->supervisor
)) {
3937 GEN_EXCP_PRIVREG(ctx
);
3940 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3943 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3948 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
)
3950 #if defined(CONFIG_USER_ONLY)
3951 GEN_EXCP_PRIVREG(ctx
);
3953 if (unlikely(!ctx
->supervisor
)) {
3954 GEN_EXCP_PRIVREG(ctx
);
3957 gen_op_load_gpr_T0(rS(ctx
->opcode
));
3958 gen_op_set_T1(SR(ctx
->opcode
));
3964 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
)
3966 #if defined(CONFIG_USER_ONLY)
3967 GEN_EXCP_PRIVREG(ctx
);
3969 if (unlikely(!ctx
->supervisor
)) {
3970 GEN_EXCP_PRIVREG(ctx
);
3973 gen_op_load_gpr_T0(rS(ctx
->opcode
));
3974 gen_op_load_gpr_T1(rB(ctx
->opcode
));
3980 #if defined(TARGET_PPC64)
3981 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
3983 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
)
3985 #if defined(CONFIG_USER_ONLY)
3986 GEN_EXCP_PRIVREG(ctx
);
3988 if (unlikely(!ctx
->supervisor
)) {
3989 GEN_EXCP_PRIVREG(ctx
);
3992 gen_op_set_T1(SR(ctx
->opcode
));
3994 gen_op_store_T0_gpr(rD(ctx
->opcode
));
3999 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
4002 #if defined(CONFIG_USER_ONLY)
4003 GEN_EXCP_PRIVREG(ctx
);
4005 if (unlikely(!ctx
->supervisor
)) {
4006 GEN_EXCP_PRIVREG(ctx
);
4009 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4012 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4017 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
)
4019 #if defined(CONFIG_USER_ONLY)
4020 GEN_EXCP_PRIVREG(ctx
);
4022 if (unlikely(!ctx
->supervisor
)) {
4023 GEN_EXCP_PRIVREG(ctx
);
4026 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4027 gen_op_set_T1(SR(ctx
->opcode
));
4033 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
4036 #if defined(CONFIG_USER_ONLY)
4037 GEN_EXCP_PRIVREG(ctx
);
4039 if (unlikely(!ctx
->supervisor
)) {
4040 GEN_EXCP_PRIVREG(ctx
);
4043 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4044 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4049 #endif /* defined(TARGET_PPC64) */
4051 /*** Lookaside buffer management ***/
4052 /* Optional & supervisor only: */
4054 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
)
4056 #if defined(CONFIG_USER_ONLY)
4057 GEN_EXCP_PRIVOPC(ctx
);
4059 if (unlikely(!ctx
->supervisor
)) {
4061 fprintf(logfile
, "%s: ! supervisor\n", __func__
);
4062 GEN_EXCP_PRIVOPC(ctx
);
4070 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE
)
4072 #if defined(CONFIG_USER_ONLY)
4073 GEN_EXCP_PRIVOPC(ctx
);
4075 if (unlikely(!ctx
->supervisor
)) {
4076 GEN_EXCP_PRIVOPC(ctx
);
4079 gen_op_load_gpr_T0(rB(ctx
->opcode
));
4080 #if defined(TARGET_PPC64)
4090 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
)
4092 #if defined(CONFIG_USER_ONLY)
4093 GEN_EXCP_PRIVOPC(ctx
);
4095 if (unlikely(!ctx
->supervisor
)) {
4096 GEN_EXCP_PRIVOPC(ctx
);
4099 /* This has no effect: it should ensure that all previous
4100 * tlbie have completed
4106 #if defined(TARGET_PPC64)
4108 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI
)
4110 #if defined(CONFIG_USER_ONLY)
4111 GEN_EXCP_PRIVOPC(ctx
);
4113 if (unlikely(!ctx
->supervisor
)) {
4115 fprintf(logfile
, "%s: ! supervisor\n", __func__
);
4116 GEN_EXCP_PRIVOPC(ctx
);
4124 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
)
4126 #if defined(CONFIG_USER_ONLY)
4127 GEN_EXCP_PRIVOPC(ctx
);
4129 if (unlikely(!ctx
->supervisor
)) {
4130 GEN_EXCP_PRIVOPC(ctx
);
4133 gen_op_load_gpr_T0(rB(ctx
->opcode
));
4139 /*** External control ***/
4141 #define op_eciwx() (*gen_op_eciwx[ctx->mem_idx])()
4142 #define op_ecowx() (*gen_op_ecowx[ctx->mem_idx])()
4143 #if defined(CONFIG_USER_ONLY)
4144 /* User-mode only */
4145 static GenOpFunc
*gen_op_eciwx
[] = {
4147 &gen_op_eciwx_le_raw
,
4148 #if defined(TARGET_PPC64)
4149 &gen_op_eciwx_64_raw
,
4150 &gen_op_eciwx_le_64_raw
,
4153 static GenOpFunc
*gen_op_ecowx
[] = {
4155 &gen_op_ecowx_le_raw
,
4156 #if defined(TARGET_PPC64)
4157 &gen_op_ecowx_64_raw
,
4158 &gen_op_ecowx_le_64_raw
,
4162 #if defined(TARGET_PPC64)
4163 /* Full system - 64 bits mode */
4164 static GenOpFunc
*gen_op_eciwx
[] = {
4166 &gen_op_eciwx_le_user
,
4167 &gen_op_eciwx_64_user
,
4168 &gen_op_eciwx_le_64_user
,
4169 &gen_op_eciwx_kernel
,
4170 &gen_op_eciwx_le_kernel
,
4171 &gen_op_eciwx_64_kernel
,
4172 &gen_op_eciwx_le_64_kernel
,
4173 #if defined(TARGET_PPC64H)
4175 &gen_op_eciwx_le_hypv
,
4176 &gen_op_eciwx_64_hypv
,
4177 &gen_op_eciwx_le_64_hypv
,
4180 static GenOpFunc
*gen_op_ecowx
[] = {
4182 &gen_op_ecowx_le_user
,
4183 &gen_op_ecowx_64_user
,
4184 &gen_op_ecowx_le_64_user
,
4185 &gen_op_ecowx_kernel
,
4186 &gen_op_ecowx_le_kernel
,
4187 &gen_op_ecowx_64_kernel
,
4188 &gen_op_ecowx_le_64_kernel
,
4189 #if defined(TARGET_PPC64H)
4191 &gen_op_ecowx_le_hypv
,
4192 &gen_op_ecowx_64_hypv
,
4193 &gen_op_ecowx_le_64_hypv
,
4197 /* Full system - 32 bits mode */
4198 static GenOpFunc
*gen_op_eciwx
[] = {
4200 &gen_op_eciwx_le_user
,
4201 &gen_op_eciwx_kernel
,
4202 &gen_op_eciwx_le_kernel
,
4204 static GenOpFunc
*gen_op_ecowx
[] = {
4206 &gen_op_ecowx_le_user
,
4207 &gen_op_ecowx_kernel
,
4208 &gen_op_ecowx_le_kernel
,
4214 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
)
4216 /* Should check EAR[E] & alignment ! */
4217 gen_addr_reg_index(ctx
);
4219 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4223 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
)
4225 /* Should check EAR[E] & alignment ! */
4226 gen_addr_reg_index(ctx
);
4227 gen_op_load_gpr_T1(rS(ctx
->opcode
));
4231 /* PowerPC 601 specific instructions */
4233 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
)
4235 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4237 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4238 if (unlikely(Rc(ctx
->opcode
) != 0))
4243 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
)
4245 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4246 gen_op_POWER_abso();
4247 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4248 if (unlikely(Rc(ctx
->opcode
) != 0))
4253 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
)
4255 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4256 gen_op_POWER_clcs();
4257 /* Rc=1 sets CR0 to an undefined state */
4258 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4262 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
)
4264 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4265 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4267 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4268 if (unlikely(Rc(ctx
->opcode
) != 0))
4273 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
)
4275 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4276 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4277 gen_op_POWER_divo();
4278 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4279 if (unlikely(Rc(ctx
->opcode
) != 0))
4284 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
)
4286 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4287 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4288 gen_op_POWER_divs();
4289 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4290 if (unlikely(Rc(ctx
->opcode
) != 0))
4294 /* divso - divso. */
4295 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
)
4297 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4298 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4299 gen_op_POWER_divso();
4300 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4301 if (unlikely(Rc(ctx
->opcode
) != 0))
4306 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
)
4308 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4309 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4311 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4312 if (unlikely(Rc(ctx
->opcode
) != 0))
4317 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
)
4319 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4320 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4321 gen_op_POWER_dozo();
4322 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4323 if (unlikely(Rc(ctx
->opcode
) != 0))
4328 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
)
4330 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4331 gen_op_set_T1(SIMM(ctx
->opcode
));
4333 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4336 /* As lscbx load from memory byte after byte, it's always endian safe */
4337 #define op_POWER_lscbx(start, ra, rb) \
4338 (*gen_op_POWER_lscbx[ctx->mem_idx])(start, ra, rb)
4339 #if defined(CONFIG_USER_ONLY)
4340 static GenOpFunc3
*gen_op_POWER_lscbx
[] = {
4341 &gen_op_POWER_lscbx_raw
,
4342 &gen_op_POWER_lscbx_raw
,
4345 static GenOpFunc3
*gen_op_POWER_lscbx
[] = {
4346 &gen_op_POWER_lscbx_user
,
4347 &gen_op_POWER_lscbx_user
,
4348 &gen_op_POWER_lscbx_kernel
,
4349 &gen_op_POWER_lscbx_kernel
,
4353 /* lscbx - lscbx. */
4354 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
)
4356 int ra
= rA(ctx
->opcode
);
4357 int rb
= rB(ctx
->opcode
);
4359 gen_addr_reg_index(ctx
);
4363 /* NIP cannot be restored if the memory exception comes from an helper */
4364 gen_update_nip(ctx
, ctx
->nip
- 4);
4365 gen_op_load_xer_bc();
4366 gen_op_load_xer_cmp();
4367 op_POWER_lscbx(rD(ctx
->opcode
), ra
, rb
);
4368 gen_op_store_xer_bc();
4369 if (unlikely(Rc(ctx
->opcode
) != 0))
4373 /* maskg - maskg. */
4374 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
)
4376 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4377 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4378 gen_op_POWER_maskg();
4379 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4380 if (unlikely(Rc(ctx
->opcode
) != 0))
4384 /* maskir - maskir. */
4385 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
)
4387 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4388 gen_op_load_gpr_T1(rS(ctx
->opcode
));
4389 gen_op_load_gpr_T2(rB(ctx
->opcode
));
4390 gen_op_POWER_maskir();
4391 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4392 if (unlikely(Rc(ctx
->opcode
) != 0))
4397 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
)
4399 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4400 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4402 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4403 if (unlikely(Rc(ctx
->opcode
) != 0))
4408 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
)
4410 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4411 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4412 gen_op_POWER_mulo();
4413 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4414 if (unlikely(Rc(ctx
->opcode
) != 0))
4419 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
)
4421 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4422 gen_op_POWER_nabs();
4423 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4424 if (unlikely(Rc(ctx
->opcode
) != 0))
4428 /* nabso - nabso. */
4429 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
)
4431 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4432 gen_op_POWER_nabso();
4433 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4434 if (unlikely(Rc(ctx
->opcode
) != 0))
4439 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
)
4443 mb
= MB(ctx
->opcode
);
4444 me
= ME(ctx
->opcode
);
4445 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4446 gen_op_load_gpr_T1(rA(ctx
->opcode
));
4447 gen_op_load_gpr_T2(rB(ctx
->opcode
));
4448 gen_op_POWER_rlmi(MASK(mb
, me
), ~MASK(mb
, me
));
4449 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4450 if (unlikely(Rc(ctx
->opcode
) != 0))
4455 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
)
4457 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4458 gen_op_load_gpr_T1(rA(ctx
->opcode
));
4459 gen_op_load_gpr_T2(rB(ctx
->opcode
));
4460 gen_op_POWER_rrib();
4461 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4462 if (unlikely(Rc(ctx
->opcode
) != 0))
4467 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
)
4469 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4470 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4472 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4473 if (unlikely(Rc(ctx
->opcode
) != 0))
4478 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
)
4480 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4481 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4482 gen_op_POWER_sleq();
4483 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4484 if (unlikely(Rc(ctx
->opcode
) != 0))
4489 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
)
4491 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4492 gen_op_set_T1(SH(ctx
->opcode
));
4494 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4495 if (unlikely(Rc(ctx
->opcode
) != 0))
4499 /* slliq - slliq. */
4500 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
)
4502 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4503 gen_op_set_T1(SH(ctx
->opcode
));
4504 gen_op_POWER_sleq();
4505 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4506 if (unlikely(Rc(ctx
->opcode
) != 0))
4511 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
)
4513 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4514 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4515 gen_op_POWER_sllq();
4516 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4517 if (unlikely(Rc(ctx
->opcode
) != 0))
4522 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
)
4524 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4525 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4527 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4528 if (unlikely(Rc(ctx
->opcode
) != 0))
4532 /* sraiq - sraiq. */
4533 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
)
4535 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4536 gen_op_set_T1(SH(ctx
->opcode
));
4537 gen_op_POWER_sraq();
4538 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4539 if (unlikely(Rc(ctx
->opcode
) != 0))
4544 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
)
4546 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4547 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4548 gen_op_POWER_sraq();
4549 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4550 if (unlikely(Rc(ctx
->opcode
) != 0))
4555 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
)
4557 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4558 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4560 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4561 if (unlikely(Rc(ctx
->opcode
) != 0))
4566 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
)
4568 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4569 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4570 gen_op_POWER_srea();
4571 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4572 if (unlikely(Rc(ctx
->opcode
) != 0))
4577 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
)
4579 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4580 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4581 gen_op_POWER_sreq();
4582 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4583 if (unlikely(Rc(ctx
->opcode
) != 0))
4588 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
)
4590 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4591 gen_op_set_T1(SH(ctx
->opcode
));
4593 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4594 if (unlikely(Rc(ctx
->opcode
) != 0))
4599 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
)
4601 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4602 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4603 gen_op_set_T1(SH(ctx
->opcode
));
4604 gen_op_POWER_srlq();
4605 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4606 if (unlikely(Rc(ctx
->opcode
) != 0))
4611 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
)
4613 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4614 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4615 gen_op_POWER_srlq();
4616 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4617 if (unlikely(Rc(ctx
->opcode
) != 0))
4622 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
)
4624 gen_op_load_gpr_T0(rS(ctx
->opcode
));
4625 gen_op_load_gpr_T1(rB(ctx
->opcode
));
4627 gen_op_store_T0_gpr(rA(ctx
->opcode
));
4628 if (unlikely(Rc(ctx
->opcode
) != 0))
4632 /* PowerPC 602 specific instructions */
4634 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
)
4637 GEN_EXCP_INVAL(ctx
);
4641 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
)
4644 GEN_EXCP_INVAL(ctx
);
4648 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
)
4650 #if defined(CONFIG_USER_ONLY)
4651 GEN_EXCP_PRIVOPC(ctx
);
4653 if (unlikely(!ctx
->supervisor
)) {
4654 GEN_EXCP_PRIVOPC(ctx
);
4657 gen_op_load_gpr_T0(rA(ctx
->opcode
));
4659 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4663 /* 602 - 603 - G2 TLB management */
4665 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
)
4667 #if defined(CONFIG_USER_ONLY)
4668 GEN_EXCP_PRIVOPC(ctx
);
4670 if (unlikely(!ctx
->supervisor
)) {
4671 GEN_EXCP_PRIVOPC(ctx
);
4674 gen_op_load_gpr_T0(rB(ctx
->opcode
));
4680 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
)
4682 #if defined(CONFIG_USER_ONLY)
4683 GEN_EXCP_PRIVOPC(ctx
);
4685 if (unlikely(!ctx
->supervisor
)) {
4686 GEN_EXCP_PRIVOPC(ctx
);
4689 gen_op_load_gpr_T0(rB(ctx
->opcode
));
4694 /* 74xx TLB management */
4696 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
)
4698 #if defined(CONFIG_USER_ONLY)
4699 GEN_EXCP_PRIVOPC(ctx
);
4701 if (unlikely(!ctx
->supervisor
)) {
4702 GEN_EXCP_PRIVOPC(ctx
);
4705 gen_op_load_gpr_T0(rB(ctx
->opcode
));
4706 gen_op_74xx_tlbld();
4711 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
)
4713 #if defined(CONFIG_USER_ONLY)
4714 GEN_EXCP_PRIVOPC(ctx
);
4716 if (unlikely(!ctx
->supervisor
)) {
4717 GEN_EXCP_PRIVOPC(ctx
);
4720 gen_op_load_gpr_T0(rB(ctx
->opcode
));
4721 gen_op_74xx_tlbli();
4725 /* POWER instructions not in PowerPC 601 */
4727 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
)
4729 /* Cache line flush: implemented as no-op */
4733 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
)
4735 /* Cache line invalidate: privileged and treated as no-op */
4736 #if defined(CONFIG_USER_ONLY)
4737 GEN_EXCP_PRIVOPC(ctx
);
4739 if (unlikely(!ctx
->supervisor
)) {
4740 GEN_EXCP_PRIVOPC(ctx
);
4747 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
)
4749 /* Data cache line store: treated as no-op */
4752 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
)
4754 #if defined(CONFIG_USER_ONLY)
4755 GEN_EXCP_PRIVOPC(ctx
);
4757 if (unlikely(!ctx
->supervisor
)) {
4758 GEN_EXCP_PRIVOPC(ctx
);
4761 int ra
= rA(ctx
->opcode
);
4762 int rd
= rD(ctx
->opcode
);
4764 gen_addr_reg_index(ctx
);
4765 gen_op_POWER_mfsri();
4766 gen_op_store_T0_gpr(rd
);
4767 if (ra
!= 0 && ra
!= rd
)
4768 gen_op_store_T1_gpr(ra
);
4772 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
)
4774 #if defined(CONFIG_USER_ONLY)
4775 GEN_EXCP_PRIVOPC(ctx
);
4777 if (unlikely(!ctx
->supervisor
)) {
4778 GEN_EXCP_PRIVOPC(ctx
);
4781 gen_addr_reg_index(ctx
);
4783 gen_op_store_T0_gpr(rD(ctx
->opcode
));
4787 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
)
4789 #if defined(CONFIG_USER_ONLY)
4790 GEN_EXCP_PRIVOPC(ctx
);
4792 if (unlikely(!ctx
->supervisor
)) {
4793 GEN_EXCP_PRIVOPC(ctx
);
4796 gen_op_POWER_rfsvc();
4801 /* svc is not implemented for now */
4803 /* POWER2 specific instructions */
4804 /* Quad manipulation (load/store two floats at a time) */
4805 #define op_POWER2_lfq() (*gen_op_POWER2_lfq[ctx->mem_idx])()
4806 #define op_POWER2_stfq() (*gen_op_POWER2_stfq[ctx->mem_idx])()
4807 #if defined(CONFIG_USER_ONLY)
4808 static GenOpFunc
*gen_op_POWER2_lfq
[] = {
4809 &gen_op_POWER2_lfq_le_raw
,
4810 &gen_op_POWER2_lfq_raw
,
4812 static GenOpFunc
*gen_op_POWER2_stfq
[] = {
4813 &gen_op_POWER2_stfq_le_raw
,
4814 &gen_op_POWER2_stfq_raw
,
4817 static GenOpFunc
*gen_op_POWER2_lfq
[] = {
4818 &gen_op_POWER2_lfq_le_user
,
4819 &gen_op_POWER2_lfq_user
,
4820 &gen_op_POWER2_lfq_le_kernel
,
4821 &gen_op_POWER2_lfq_kernel
,
4823 static GenOpFunc
*gen_op_POWER2_stfq
[] = {
4824 &gen_op_POWER2_stfq_le_user
,
4825 &gen_op_POWER2_stfq_user
,
4826 &gen_op_POWER2_stfq_le_kernel
,
4827 &gen_op_POWER2_stfq_kernel
,
4832 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
4834 /* NIP cannot be restored if the memory exception comes from an helper */
4835 gen_update_nip(ctx
, ctx
->nip
- 4);
4836 gen_addr_imm_index(ctx
, 0);
4838 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
4839 gen_op_store_FT1_fpr(rD(ctx
->opcode
) + 1);
4843 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
4845 int ra
= rA(ctx
->opcode
);
4847 /* NIP cannot be restored if the memory exception comes from an helper */
4848 gen_update_nip(ctx
, ctx
->nip
- 4);
4849 gen_addr_imm_index(ctx
, 0);
4851 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
4852 gen_op_store_FT1_fpr(rD(ctx
->opcode
) + 1);
4854 gen_op_store_T0_gpr(ra
);
4858 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
)
4860 int ra
= rA(ctx
->opcode
);
4862 /* NIP cannot be restored if the memory exception comes from an helper */
4863 gen_update_nip(ctx
, ctx
->nip
- 4);
4864 gen_addr_reg_index(ctx
);
4866 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
4867 gen_op_store_FT1_fpr(rD(ctx
->opcode
) + 1);
4869 gen_op_store_T0_gpr(ra
);
4873 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
)
4875 /* NIP cannot be restored if the memory exception comes from an helper */
4876 gen_update_nip(ctx
, ctx
->nip
- 4);
4877 gen_addr_reg_index(ctx
);
4879 gen_op_store_FT0_fpr(rD(ctx
->opcode
));
4880 gen_op_store_FT1_fpr(rD(ctx
->opcode
) + 1);
4884 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
4886 /* NIP cannot be restored if the memory exception comes from an helper */
4887 gen_update_nip(ctx
, ctx
->nip
- 4);
4888 gen_addr_imm_index(ctx
, 0);
4889 gen_op_load_fpr_FT0(rS(ctx
->opcode
));
4890 gen_op_load_fpr_FT1(rS(ctx
->opcode
) + 1);
4895 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
4897 int ra
= rA(ctx
->opcode
);
4899 /* NIP cannot be restored if the memory exception comes from an helper */
4900 gen_update_nip(ctx
, ctx
->nip
- 4);
4901 gen_addr_imm_index(ctx
, 0);
4902 gen_op_load_fpr_FT0(rS(ctx
->opcode
));
4903 gen_op_load_fpr_FT1(rS(ctx
->opcode
) + 1);
4906 gen_op_store_T0_gpr(ra
);
4910 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
)
4912 int ra
= rA(ctx
->opcode
);
4914 /* NIP cannot be restored if the memory exception comes from an helper */
4915 gen_update_nip(ctx
, ctx
->nip
- 4);
4916 gen_addr_reg_index(ctx
);
4917 gen_op_load_fpr_FT0(rS(ctx
->opcode
));
4918 gen_op_load_fpr_FT1(rS(ctx
->opcode
) + 1);
4921 gen_op_store_T0_gpr(ra
);
4925 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
)
4927 /* NIP cannot be restored if the memory exception comes from an helper */
4928 gen_update_nip(ctx
, ctx
->nip
- 4);
4929 gen_addr_reg_index(ctx
);
4930 gen_op_load_fpr_FT0(rS(ctx
->opcode
));
4931 gen_op_load_fpr_FT1(rS(ctx
->opcode
) + 1);
4935 /* BookE specific instructions */
4936 /* XXX: not implemented on 440 ? */
4937 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_BOOKE_EXT
)
4940 GEN_EXCP_INVAL(ctx
);
4943 /* XXX: not implemented on 440 ? */
4944 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_BOOKE_EXT
)
4946 #if defined(CONFIG_USER_ONLY)
4947 GEN_EXCP_PRIVOPC(ctx
);
4949 if (unlikely(!ctx
->supervisor
)) {
4950 GEN_EXCP_PRIVOPC(ctx
);
4953 gen_addr_reg_index(ctx
);
4954 /* Use the same micro-ops as for tlbie */
4955 #if defined(TARGET_PPC64)
4964 /* All 405 MAC instructions are translated here */
4965 static always_inline
void gen_405_mulladd_insn (DisasContext
*ctx
,
4967 int ra
, int rb
, int rt
, int Rc
)
4969 gen_op_load_gpr_T0(ra
);
4970 gen_op_load_gpr_T1(rb
);
4971 switch (opc3
& 0x0D) {
4973 /* macchw - macchw. - macchwo - macchwo. */
4974 /* macchws - macchws. - macchwso - macchwso. */
4975 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
4976 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
4977 /* mulchw - mulchw. */
4978 gen_op_405_mulchw();
4981 /* macchwu - macchwu. - macchwuo - macchwuo. */
4982 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
4983 /* mulchwu - mulchwu. */
4984 gen_op_405_mulchwu();
4987 /* machhw - machhw. - machhwo - machhwo. */
4988 /* machhws - machhws. - machhwso - machhwso. */
4989 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
4990 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
4991 /* mulhhw - mulhhw. */
4992 gen_op_405_mulhhw();
4995 /* machhwu - machhwu. - machhwuo - machhwuo. */
4996 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
4997 /* mulhhwu - mulhhwu. */
4998 gen_op_405_mulhhwu();
5001 /* maclhw - maclhw. - maclhwo - maclhwo. */
5002 /* maclhws - maclhws. - maclhwso - maclhwso. */
5003 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5004 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5005 /* mullhw - mullhw. */
5006 gen_op_405_mullhw();
5009 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5010 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5011 /* mullhwu - mullhwu. */
5012 gen_op_405_mullhwu();
5016 /* nmultiply-and-accumulate (0x0E) */
5020 /* (n)multiply-and-accumulate (0x0C - 0x0E) */
5021 gen_op_load_gpr_T2(rt
);
5022 gen_op_move_T1_T0();
5023 gen_op_405_add_T0_T2();
5026 /* Check overflow */
5028 gen_op_405_check_ov();
5030 gen_op_405_check_ovu();
5035 gen_op_405_check_sat();
5037 gen_op_405_check_satu();
5039 gen_op_store_T0_gpr(rt
);
5040 if (unlikely(Rc
) != 0) {
5046 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5047 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC) \
5049 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5050 rD(ctx->opcode), Rc(ctx->opcode)); \
5053 /* macchw - macchw. */
5054 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
5055 /* macchwo - macchwo. */
5056 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
5057 /* macchws - macchws. */
5058 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
5059 /* macchwso - macchwso. */
5060 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
5061 /* macchwsu - macchwsu. */
5062 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
5063 /* macchwsuo - macchwsuo. */
5064 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
5065 /* macchwu - macchwu. */
5066 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
5067 /* macchwuo - macchwuo. */
5068 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
5069 /* machhw - machhw. */
5070 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
5071 /* machhwo - machhwo. */
5072 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
5073 /* machhws - machhws. */
5074 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
5075 /* machhwso - machhwso. */
5076 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
5077 /* machhwsu - machhwsu. */
5078 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
5079 /* machhwsuo - machhwsuo. */
5080 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
5081 /* machhwu - machhwu. */
5082 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
5083 /* machhwuo - machhwuo. */
5084 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
5085 /* maclhw - maclhw. */
5086 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
5087 /* maclhwo - maclhwo. */
5088 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
5089 /* maclhws - maclhws. */
5090 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
5091 /* maclhwso - maclhwso. */
5092 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
5093 /* maclhwu - maclhwu. */
5094 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
5095 /* maclhwuo - maclhwuo. */
5096 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
5097 /* maclhwsu - maclhwsu. */
5098 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
5099 /* maclhwsuo - maclhwsuo. */
5100 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
5101 /* nmacchw - nmacchw. */
5102 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
5103 /* nmacchwo - nmacchwo. */
5104 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
5105 /* nmacchws - nmacchws. */
5106 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
5107 /* nmacchwso - nmacchwso. */
5108 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
5109 /* nmachhw - nmachhw. */
5110 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
5111 /* nmachhwo - nmachhwo. */
5112 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
5113 /* nmachhws - nmachhws. */
5114 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
5115 /* nmachhwso - nmachhwso. */
5116 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
5117 /* nmaclhw - nmaclhw. */
5118 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
5119 /* nmaclhwo - nmaclhwo. */
5120 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
5121 /* nmaclhws - nmaclhws. */
5122 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
5123 /* nmaclhwso - nmaclhwso. */
5124 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
5126 /* mulchw - mulchw. */
5127 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
5128 /* mulchwu - mulchwu. */
5129 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
5130 /* mulhhw - mulhhw. */
5131 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
5132 /* mulhhwu - mulhhwu. */
5133 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
5134 /* mullhw - mullhw. */
5135 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
5136 /* mullhwu - mullhwu. */
5137 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
5140 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_EMB_COMMON
)
5142 #if defined(CONFIG_USER_ONLY)
5143 GEN_EXCP_PRIVREG(ctx
);
5145 uint32_t dcrn
= SPR(ctx
->opcode
);
5147 if (unlikely(!ctx
->supervisor
)) {
5148 GEN_EXCP_PRIVREG(ctx
);
5151 gen_op_set_T0(dcrn
);
5153 gen_op_store_T0_gpr(rD(ctx
->opcode
));
5158 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_EMB_COMMON
)
5160 #if defined(CONFIG_USER_ONLY)
5161 GEN_EXCP_PRIVREG(ctx
);
5163 uint32_t dcrn
= SPR(ctx
->opcode
);
5165 if (unlikely(!ctx
->supervisor
)) {
5166 GEN_EXCP_PRIVREG(ctx
);
5169 gen_op_set_T0(dcrn
);
5170 gen_op_load_gpr_T1(rS(ctx
->opcode
));
5176 /* XXX: not implemented on 440 ? */
5177 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_BOOKE_EXT
)
5179 #if defined(CONFIG_USER_ONLY)
5180 GEN_EXCP_PRIVREG(ctx
);
5182 if (unlikely(!ctx
->supervisor
)) {
5183 GEN_EXCP_PRIVREG(ctx
);
5186 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5188 gen_op_store_T0_gpr(rD(ctx
->opcode
));
5189 /* Note: Rc update flag set leads to undefined state of Rc0 */
5194 /* XXX: not implemented on 440 ? */
5195 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_BOOKE_EXT
)
5197 #if defined(CONFIG_USER_ONLY)
5198 GEN_EXCP_PRIVREG(ctx
);
5200 if (unlikely(!ctx
->supervisor
)) {
5201 GEN_EXCP_PRIVREG(ctx
);
5204 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5205 gen_op_load_gpr_T1(rS(ctx
->opcode
));
5207 /* Note: Rc update flag set leads to undefined state of Rc0 */
5211 /* mfdcrux (PPC 460) : user-mode access to DCR */
5212 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
)
5214 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5216 gen_op_store_T0_gpr(rD(ctx
->opcode
));
5217 /* Note: Rc update flag set leads to undefined state of Rc0 */
5220 /* mtdcrux (PPC 460) : user-mode access to DCR */
5221 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
)
5223 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5224 gen_op_load_gpr_T1(rS(ctx
->opcode
));
5226 /* Note: Rc update flag set leads to undefined state of Rc0 */
5230 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
)
5232 #if defined(CONFIG_USER_ONLY)
5233 GEN_EXCP_PRIVOPC(ctx
);
5235 if (unlikely(!ctx
->supervisor
)) {
5236 GEN_EXCP_PRIVOPC(ctx
);
5239 /* interpreted as no-op */
5244 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
)
5246 #if defined(CONFIG_USER_ONLY)
5247 GEN_EXCP_PRIVOPC(ctx
);
5249 if (unlikely(!ctx
->supervisor
)) {
5250 GEN_EXCP_PRIVOPC(ctx
);
5253 gen_addr_reg_index(ctx
);
5255 gen_op_store_T0_gpr(rD(ctx
->opcode
));
5260 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
)
5262 /* interpreted as no-op */
5263 /* XXX: specification say this is treated as a load by the MMU
5264 * but does not generate any exception
5269 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
)
5271 #if defined(CONFIG_USER_ONLY)
5272 GEN_EXCP_PRIVOPC(ctx
);
5274 if (unlikely(!ctx
->supervisor
)) {
5275 GEN_EXCP_PRIVOPC(ctx
);
5278 /* interpreted as no-op */
5283 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
)
5285 #if defined(CONFIG_USER_ONLY)
5286 GEN_EXCP_PRIVOPC(ctx
);
5288 if (unlikely(!ctx
->supervisor
)) {
5289 GEN_EXCP_PRIVOPC(ctx
);
5292 /* interpreted as no-op */
5296 /* rfci (supervisor only) */
5297 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
)
5299 #if defined(CONFIG_USER_ONLY)
5300 GEN_EXCP_PRIVOPC(ctx
);
5302 if (unlikely(!ctx
->supervisor
)) {
5303 GEN_EXCP_PRIVOPC(ctx
);
5306 /* Restore CPU state */
5312 GEN_HANDLER(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
)
5314 #if defined(CONFIG_USER_ONLY)
5315 GEN_EXCP_PRIVOPC(ctx
);
5317 if (unlikely(!ctx
->supervisor
)) {
5318 GEN_EXCP_PRIVOPC(ctx
);
5321 /* Restore CPU state */
5327 /* BookE specific */
5328 /* XXX: not implemented on 440 ? */
5329 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_BOOKE_EXT
)
5331 #if defined(CONFIG_USER_ONLY)
5332 GEN_EXCP_PRIVOPC(ctx
);
5334 if (unlikely(!ctx
->supervisor
)) {
5335 GEN_EXCP_PRIVOPC(ctx
);
5338 /* Restore CPU state */
5344 /* XXX: not implemented on 440 ? */
5345 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
)
5347 #if defined(CONFIG_USER_ONLY)
5348 GEN_EXCP_PRIVOPC(ctx
);
5350 if (unlikely(!ctx
->supervisor
)) {
5351 GEN_EXCP_PRIVOPC(ctx
);
5354 /* Restore CPU state */
5360 /* TLB management - PowerPC 405 implementation */
5362 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
)
5364 #if defined(CONFIG_USER_ONLY)
5365 GEN_EXCP_PRIVOPC(ctx
);
5367 if (unlikely(!ctx
->supervisor
)) {
5368 GEN_EXCP_PRIVOPC(ctx
);
5371 switch (rB(ctx
->opcode
)) {
5373 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5374 gen_op_4xx_tlbre_hi();
5375 gen_op_store_T0_gpr(rD(ctx
->opcode
));
5378 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5379 gen_op_4xx_tlbre_lo();
5380 gen_op_store_T0_gpr(rD(ctx
->opcode
));
5383 GEN_EXCP_INVAL(ctx
);
5389 /* tlbsx - tlbsx. */
5390 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
)
5392 #if defined(CONFIG_USER_ONLY)
5393 GEN_EXCP_PRIVOPC(ctx
);
5395 if (unlikely(!ctx
->supervisor
)) {
5396 GEN_EXCP_PRIVOPC(ctx
);
5399 gen_addr_reg_index(ctx
);
5401 if (Rc(ctx
->opcode
))
5402 gen_op_4xx_tlbsx_check();
5403 gen_op_store_T0_gpr(rD(ctx
->opcode
));
5408 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
)
5410 #if defined(CONFIG_USER_ONLY)
5411 GEN_EXCP_PRIVOPC(ctx
);
5413 if (unlikely(!ctx
->supervisor
)) {
5414 GEN_EXCP_PRIVOPC(ctx
);
5417 switch (rB(ctx
->opcode
)) {
5419 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5420 gen_op_load_gpr_T1(rS(ctx
->opcode
));
5421 gen_op_4xx_tlbwe_hi();
5424 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5425 gen_op_load_gpr_T1(rS(ctx
->opcode
));
5426 gen_op_4xx_tlbwe_lo();
5429 GEN_EXCP_INVAL(ctx
);
5435 /* TLB management - PowerPC 440 implementation */
5437 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
)
5439 #if defined(CONFIG_USER_ONLY)
5440 GEN_EXCP_PRIVOPC(ctx
);
5442 if (unlikely(!ctx
->supervisor
)) {
5443 GEN_EXCP_PRIVOPC(ctx
);
5446 switch (rB(ctx
->opcode
)) {
5450 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5451 gen_op_440_tlbre(rB(ctx
->opcode
));
5452 gen_op_store_T0_gpr(rD(ctx
->opcode
));
5455 GEN_EXCP_INVAL(ctx
);
5461 /* tlbsx - tlbsx. */
5462 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
)
5464 #if defined(CONFIG_USER_ONLY)
5465 GEN_EXCP_PRIVOPC(ctx
);
5467 if (unlikely(!ctx
->supervisor
)) {
5468 GEN_EXCP_PRIVOPC(ctx
);
5471 gen_addr_reg_index(ctx
);
5473 if (Rc(ctx
->opcode
))
5474 gen_op_4xx_tlbsx_check();
5475 gen_op_store_T0_gpr(rD(ctx
->opcode
));
5480 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
)
5482 #if defined(CONFIG_USER_ONLY)
5483 GEN_EXCP_PRIVOPC(ctx
);
5485 if (unlikely(!ctx
->supervisor
)) {
5486 GEN_EXCP_PRIVOPC(ctx
);
5489 switch (rB(ctx
->opcode
)) {
5493 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5494 gen_op_load_gpr_T1(rS(ctx
->opcode
));
5495 gen_op_440_tlbwe(rB(ctx
->opcode
));
5498 GEN_EXCP_INVAL(ctx
);
5505 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_EMB_COMMON
)
5507 #if defined(CONFIG_USER_ONLY)
5508 GEN_EXCP_PRIVOPC(ctx
);
5510 if (unlikely(!ctx
->supervisor
)) {
5511 GEN_EXCP_PRIVOPC(ctx
);
5514 gen_op_load_gpr_T0(rD(ctx
->opcode
));
5516 /* Stop translation to have a chance to raise an exception
5517 * if we just set msr_ee to 1
5524 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000EFC01, PPC_EMB_COMMON
)
5526 #if defined(CONFIG_USER_ONLY)
5527 GEN_EXCP_PRIVOPC(ctx
);
5529 if (unlikely(!ctx
->supervisor
)) {
5530 GEN_EXCP_PRIVOPC(ctx
);
5533 gen_op_set_T0(ctx
->opcode
& 0x00010000);
5535 /* Stop translation to have a chance to raise an exception
5536 * if we just set msr_ee to 1
5542 /* PowerPC 440 specific instructions */
5544 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
)
5546 gen_op_load_gpr_T0(rS(ctx
->opcode
));
5547 gen_op_load_gpr_T1(rB(ctx
->opcode
));
5549 gen_op_store_T0_gpr(rA(ctx
->opcode
));
5550 gen_op_store_xer_bc();
5551 if (Rc(ctx
->opcode
)) {
5552 gen_op_440_dlmzb_update_Rc();
5553 gen_op_store_T0_crf(0);
5557 /* mbar replaces eieio on 440 */
5558 GEN_HANDLER(mbar
, 0x1F, 0x16, 0x13, 0x001FF801, PPC_BOOKE
)
5560 /* interpreted as no-op */
5563 /* msync replaces sync on 440 */
5564 GEN_HANDLER(msync
, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE
)
5566 /* interpreted as no-op */
5570 GEN_HANDLER2(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001, PPC_BOOKE
)
5572 /* interpreted as no-op */
5573 /* XXX: specification say this is treated as a load by the MMU
5574 * but does not generate any exception
5578 /*** Altivec vector extension ***/
5579 /* Altivec registers moves */
5580 GEN32(gen_op_load_avr_A0
, gen_op_load_avr_A0_avr
);
5581 GEN32(gen_op_load_avr_A1
, gen_op_load_avr_A1_avr
);
5582 GEN32(gen_op_load_avr_A2
, gen_op_load_avr_A2_avr
);
5584 GEN32(gen_op_store_A0_avr
, gen_op_store_A0_avr_avr
);
5585 GEN32(gen_op_store_A1_avr
, gen_op_store_A1_avr_avr
);
5587 GEN32(gen_op_store_A2_avr
, gen_op_store_A2_avr_avr
);
5590 #define op_vr_ldst(name) (*gen_op_##name[ctx->mem_idx])()
5591 #if defined(CONFIG_USER_ONLY)
5592 #if defined(TARGET_PPC64)
5593 /* User-mode only - 64 bits mode */
5594 #define OP_VR_LD_TABLE(name) \
5595 static GenOpFunc *gen_op_vr_l##name[] = { \
5596 &gen_op_vr_l##name##_raw, \
5597 &gen_op_vr_l##name##_le_raw, \
5598 &gen_op_vr_l##name##_64_raw, \
5599 &gen_op_vr_l##name##_le_64_raw, \
5601 #define OP_VR_ST_TABLE(name) \
5602 static GenOpFunc *gen_op_vr_st##name[] = { \
5603 &gen_op_vr_st##name##_raw, \
5604 &gen_op_vr_st##name##_le_raw, \
5605 &gen_op_vr_st##name##_64_raw, \
5606 &gen_op_vr_st##name##_le_64_raw, \
5608 #else /* defined(TARGET_PPC64) */
5609 /* User-mode only - 32 bits mode */
5610 #define OP_VR_LD_TABLE(name) \
5611 static GenOpFunc *gen_op_vr_l##name[] = { \
5612 &gen_op_vr_l##name##_raw, \
5613 &gen_op_vr_l##name##_le_raw, \
5615 #define OP_VR_ST_TABLE(name) \
5616 static GenOpFunc *gen_op_vr_st##name[] = { \
5617 &gen_op_vr_st##name##_raw, \
5618 &gen_op_vr_st##name##_le_raw, \
5620 #endif /* defined(TARGET_PPC64) */
5621 #else /* defined(CONFIG_USER_ONLY) */
5622 #if defined(TARGET_PPC64H)
5623 /* Full system with hypervisor mode */
5624 #define OP_VR_LD_TABLE(name) \
5625 static GenOpFunc *gen_op_vr_l##name[] = { \
5626 &gen_op_vr_l##name##_user, \
5627 &gen_op_vr_l##name##_le_user, \
5628 &gen_op_vr_l##name##_64_user, \
5629 &gen_op_vr_l##name##_le_64_user, \
5630 &gen_op_vr_l##name##_kernel, \
5631 &gen_op_vr_l##name##_le_kernel, \
5632 &gen_op_vr_l##name##_64_kernel, \
5633 &gen_op_vr_l##name##_le_64_kernel, \
5634 &gen_op_vr_l##name##_hypv, \
5635 &gen_op_vr_l##name##_le_hypv, \
5636 &gen_op_vr_l##name##_64_hypv, \
5637 &gen_op_vr_l##name##_le_64_hypv, \
5639 #define OP_VR_ST_TABLE(name) \
5640 static GenOpFunc *gen_op_vr_st##name[] = { \
5641 &gen_op_vr_st##name##_user, \
5642 &gen_op_vr_st##name##_le_user, \
5643 &gen_op_vr_st##name##_64_user, \
5644 &gen_op_vr_st##name##_le_64_user, \
5645 &gen_op_vr_st##name##_kernel, \
5646 &gen_op_vr_st##name##_le_kernel, \
5647 &gen_op_vr_st##name##_64_kernel, \
5648 &gen_op_vr_st##name##_le_64_kernel, \
5649 &gen_op_vr_st##name##_hypv, \
5650 &gen_op_vr_st##name##_le_hypv, \
5651 &gen_op_vr_st##name##_64_hypv, \
5652 &gen_op_vr_st##name##_le_64_hypv, \
5654 #elif defined(TARGET_PPC64)
5655 /* Full system - 64 bits mode */
5656 #define OP_VR_LD_TABLE(name) \
5657 static GenOpFunc *gen_op_vr_l##name[] = { \
5658 &gen_op_vr_l##name##_user, \
5659 &gen_op_vr_l##name##_le_user, \
5660 &gen_op_vr_l##name##_64_user, \
5661 &gen_op_vr_l##name##_le_64_user, \
5662 &gen_op_vr_l##name##_kernel, \
5663 &gen_op_vr_l##name##_le_kernel, \
5664 &gen_op_vr_l##name##_64_kernel, \
5665 &gen_op_vr_l##name##_le_64_kernel, \
5667 #define OP_VR_ST_TABLE(name) \
5668 static GenOpFunc *gen_op_vr_st##name[] = { \
5669 &gen_op_vr_st##name##_user, \
5670 &gen_op_vr_st##name##_le_user, \
5671 &gen_op_vr_st##name##_64_user, \
5672 &gen_op_vr_st##name##_le_64_user, \
5673 &gen_op_vr_st##name##_kernel, \
5674 &gen_op_vr_st##name##_le_kernel, \
5675 &gen_op_vr_st##name##_64_kernel, \
5676 &gen_op_vr_st##name##_le_64_kernel, \
5678 #else /* defined(TARGET_PPC64) */
5679 /* Full system - 32 bits mode */
5680 #define OP_VR_LD_TABLE(name) \
5681 static GenOpFunc *gen_op_vr_l##name[] = { \
5682 &gen_op_vr_l##name##_user, \
5683 &gen_op_vr_l##name##_le_user, \
5684 &gen_op_vr_l##name##_kernel, \
5685 &gen_op_vr_l##name##_le_kernel, \
5687 #define OP_VR_ST_TABLE(name) \
5688 static GenOpFunc *gen_op_vr_st##name[] = { \
5689 &gen_op_vr_st##name##_user, \
5690 &gen_op_vr_st##name##_le_user, \
5691 &gen_op_vr_st##name##_kernel, \
5692 &gen_op_vr_st##name##_le_kernel, \
5694 #endif /* defined(TARGET_PPC64) */
5695 #endif /* defined(CONFIG_USER_ONLY) */
5697 #define GEN_VR_LDX(name, opc2, opc3) \
5698 GEN_HANDLER(l##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
5700 if (unlikely(!ctx->altivec_enabled)) { \
5701 GEN_EXCP_NO_VR(ctx); \
5704 gen_addr_reg_index(ctx); \
5705 op_vr_ldst(vr_l##name); \
5706 gen_op_store_A0_avr(rD(ctx->opcode)); \
5709 #define GEN_VR_STX(name, opc2, opc3) \
5710 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
5712 if (unlikely(!ctx->altivec_enabled)) { \
5713 GEN_EXCP_NO_VR(ctx); \
5716 gen_addr_reg_index(ctx); \
5717 gen_op_load_avr_A0(rS(ctx->opcode)); \
5718 op_vr_ldst(vr_st##name); \
5722 GEN_VR_LDX(vx
, 0x07, 0x03);
5723 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
5724 #define gen_op_vr_lvxl gen_op_vr_lvx
5725 GEN_VR_LDX(vxl
, 0x07, 0x0B);
5728 GEN_VR_STX(vx
, 0x07, 0x07);
5729 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
5730 #define gen_op_vr_stvxl gen_op_vr_stvx
5731 GEN_VR_STX(vxl
, 0x07, 0x0F);
5733 #if defined(TARGET_PPCEMB)
5734 /*** SPE extension ***/
5736 /* Register moves */
5737 GEN32(gen_op_load_gpr64_T0
, gen_op_load_gpr64_T0_gpr
);
5738 GEN32(gen_op_load_gpr64_T1
, gen_op_load_gpr64_T1_gpr
);
5740 GEN32(gen_op_load_gpr64_T2
, gen_op_load_gpr64_T2_gpr
);
5743 GEN32(gen_op_store_T0_gpr64
, gen_op_store_T0_gpr64_gpr
);
5744 GEN32(gen_op_store_T1_gpr64
, gen_op_store_T1_gpr64_gpr
);
5746 GEN32(gen_op_store_T2_gpr64
, gen_op_store_T2_gpr64_gpr
);
5749 #define GEN_SPE(name0, name1, opc2, opc3, inval, type) \
5750 GEN_HANDLER(name0##_##name1, 0x04, opc2, opc3, inval, type) \
5752 if (Rc(ctx->opcode)) \
5758 /* Handler for undefined SPE opcodes */
5759 static always_inline
void gen_speundef (DisasContext
*ctx
)
5761 GEN_EXCP_INVAL(ctx
);
5764 /* SPE load and stores */
5765 static always_inline
void gen_addr_spe_imm_index (DisasContext
*ctx
, int sh
)
5767 target_long simm
= rB(ctx
->opcode
);
5769 if (rA(ctx
->opcode
) == 0) {
5770 gen_set_T0(simm
<< sh
);
5772 gen_op_load_gpr_T0(rA(ctx
->opcode
));
5773 if (likely(simm
!= 0))
5774 gen_op_addi(simm
<< sh
);
5778 #define op_spe_ldst(name) (*gen_op_##name[ctx->mem_idx])()
5779 #if defined(CONFIG_USER_ONLY)
5780 #if defined(TARGET_PPC64)
5781 /* User-mode only - 64 bits mode */
5782 #define OP_SPE_LD_TABLE(name) \
5783 static GenOpFunc *gen_op_spe_l##name[] = { \
5784 &gen_op_spe_l##name##_raw, \
5785 &gen_op_spe_l##name##_le_raw, \
5786 &gen_op_spe_l##name##_64_raw, \
5787 &gen_op_spe_l##name##_le_64_raw, \
5789 #define OP_SPE_ST_TABLE(name) \
5790 static GenOpFunc *gen_op_spe_st##name[] = { \
5791 &gen_op_spe_st##name##_raw, \
5792 &gen_op_spe_st##name##_le_raw, \
5793 &gen_op_spe_st##name##_64_raw, \
5794 &gen_op_spe_st##name##_le_64_raw, \
5796 #else /* defined(TARGET_PPC64) */
5797 /* User-mode only - 32 bits mode */
5798 #define OP_SPE_LD_TABLE(name) \
5799 static GenOpFunc *gen_op_spe_l##name[] = { \
5800 &gen_op_spe_l##name##_raw, \
5801 &gen_op_spe_l##name##_le_raw, \
5803 #define OP_SPE_ST_TABLE(name) \
5804 static GenOpFunc *gen_op_spe_st##name[] = { \
5805 &gen_op_spe_st##name##_raw, \
5806 &gen_op_spe_st##name##_le_raw, \
5808 #endif /* defined(TARGET_PPC64) */
5809 #else /* defined(CONFIG_USER_ONLY) */
5810 #if defined(TARGET_PPC64H)
5811 /* Full system with hypervisor mode */
5812 #define OP_SPE_LD_TABLE(name) \
5813 static GenOpFunc *gen_op_spe_l##name[] = { \
5814 &gen_op_spe_l##name##_user, \
5815 &gen_op_spe_l##name##_le_user, \
5816 &gen_op_spe_l##name##_64_user, \
5817 &gen_op_spe_l##name##_le_64_user, \
5818 &gen_op_spe_l##name##_kernel, \
5819 &gen_op_spe_l##name##_le_kernel, \
5820 &gen_op_spe_l##name##_64_kernel, \
5821 &gen_op_spe_l##name##_le_64_kernel, \
5822 &gen_op_spe_l##name##_hypv, \
5823 &gen_op_spe_l##name##_le_hypv, \
5824 &gen_op_spe_l##name##_64_hypv, \
5825 &gen_op_spe_l##name##_le_64_hypv, \
5827 #define OP_SPE_ST_TABLE(name) \
5828 static GenOpFunc *gen_op_spe_st##name[] = { \
5829 &gen_op_spe_st##name##_user, \
5830 &gen_op_spe_st##name##_le_user, \
5831 &gen_op_spe_st##name##_64_user, \
5832 &gen_op_spe_st##name##_le_64_user, \
5833 &gen_op_spe_st##name##_kernel, \
5834 &gen_op_spe_st##name##_le_kernel, \
5835 &gen_op_spe_st##name##_64_kernel, \
5836 &gen_op_spe_st##name##_le_64_kernel, \
5837 &gen_op_spe_st##name##_hypv, \
5838 &gen_op_spe_st##name##_le_hypv, \
5839 &gen_op_spe_st##name##_64_hypv, \
5840 &gen_op_spe_st##name##_le_64_hypv, \
5842 #elif defined(TARGET_PPC64)
5843 /* Full system - 64 bits mode */
5844 #define OP_SPE_LD_TABLE(name) \
5845 static GenOpFunc *gen_op_spe_l##name[] = { \
5846 &gen_op_spe_l##name##_user, \
5847 &gen_op_spe_l##name##_le_user, \
5848 &gen_op_spe_l##name##_64_user, \
5849 &gen_op_spe_l##name##_le_64_user, \
5850 &gen_op_spe_l##name##_kernel, \
5851 &gen_op_spe_l##name##_le_kernel, \
5852 &gen_op_spe_l##name##_64_kernel, \
5853 &gen_op_spe_l##name##_le_64_kernel, \
5855 #define OP_SPE_ST_TABLE(name) \
5856 static GenOpFunc *gen_op_spe_st##name[] = { \
5857 &gen_op_spe_st##name##_user, \
5858 &gen_op_spe_st##name##_le_user, \
5859 &gen_op_spe_st##name##_64_user, \
5860 &gen_op_spe_st##name##_le_64_user, \
5861 &gen_op_spe_st##name##_kernel, \
5862 &gen_op_spe_st##name##_le_kernel, \
5863 &gen_op_spe_st##name##_64_kernel, \
5864 &gen_op_spe_st##name##_le_64_kernel, \
5866 #else /* defined(TARGET_PPC64) */
5867 /* Full system - 32 bits mode */
5868 #define OP_SPE_LD_TABLE(name) \
5869 static GenOpFunc *gen_op_spe_l##name[] = { \
5870 &gen_op_spe_l##name##_user, \
5871 &gen_op_spe_l##name##_le_user, \
5872 &gen_op_spe_l##name##_kernel, \
5873 &gen_op_spe_l##name##_le_kernel, \
5875 #define OP_SPE_ST_TABLE(name) \
5876 static GenOpFunc *gen_op_spe_st##name[] = { \
5877 &gen_op_spe_st##name##_user, \
5878 &gen_op_spe_st##name##_le_user, \
5879 &gen_op_spe_st##name##_kernel, \
5880 &gen_op_spe_st##name##_le_kernel, \
5882 #endif /* defined(TARGET_PPC64) */
5883 #endif /* defined(CONFIG_USER_ONLY) */
5885 #define GEN_SPE_LD(name, sh) \
5886 static always_inline void gen_evl##name (DisasContext *ctx) \
5888 if (unlikely(!ctx->spe_enabled)) { \
5889 GEN_EXCP_NO_AP(ctx); \
5892 gen_addr_spe_imm_index(ctx, sh); \
5893 op_spe_ldst(spe_l##name); \
5894 gen_op_store_T1_gpr64(rD(ctx->opcode)); \
5897 #define GEN_SPE_LDX(name) \
5898 static always_inline void gen_evl##name##x (DisasContext *ctx) \
5900 if (unlikely(!ctx->spe_enabled)) { \
5901 GEN_EXCP_NO_AP(ctx); \
5904 gen_addr_reg_index(ctx); \
5905 op_spe_ldst(spe_l##name); \
5906 gen_op_store_T1_gpr64(rD(ctx->opcode)); \
5909 #define GEN_SPEOP_LD(name, sh) \
5910 OP_SPE_LD_TABLE(name); \
5911 GEN_SPE_LD(name, sh); \
5914 #define GEN_SPE_ST(name, sh) \
5915 static always_inline void gen_evst##name (DisasContext *ctx) \
5917 if (unlikely(!ctx->spe_enabled)) { \
5918 GEN_EXCP_NO_AP(ctx); \
5921 gen_addr_spe_imm_index(ctx, sh); \
5922 gen_op_load_gpr64_T1(rS(ctx->opcode)); \
5923 op_spe_ldst(spe_st##name); \
5926 #define GEN_SPE_STX(name) \
5927 static always_inline void gen_evst##name##x (DisasContext *ctx) \
5929 if (unlikely(!ctx->spe_enabled)) { \
5930 GEN_EXCP_NO_AP(ctx); \
5933 gen_addr_reg_index(ctx); \
5934 gen_op_load_gpr64_T1(rS(ctx->opcode)); \
5935 op_spe_ldst(spe_st##name); \
5938 #define GEN_SPEOP_ST(name, sh) \
5939 OP_SPE_ST_TABLE(name); \
5940 GEN_SPE_ST(name, sh); \
5943 #define GEN_SPEOP_LDST(name, sh) \
5944 GEN_SPEOP_LD(name, sh); \
5945 GEN_SPEOP_ST(name, sh)
5947 /* SPE arithmetic and logic */
5948 #define GEN_SPEOP_ARITH2(name) \
5949 static always_inline void gen_##name (DisasContext *ctx) \
5951 if (unlikely(!ctx->spe_enabled)) { \
5952 GEN_EXCP_NO_AP(ctx); \
5955 gen_op_load_gpr64_T0(rA(ctx->opcode)); \
5956 gen_op_load_gpr64_T1(rB(ctx->opcode)); \
5958 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5961 #define GEN_SPEOP_ARITH1(name) \
5962 static always_inline void gen_##name (DisasContext *ctx) \
5964 if (unlikely(!ctx->spe_enabled)) { \
5965 GEN_EXCP_NO_AP(ctx); \
5968 gen_op_load_gpr64_T0(rA(ctx->opcode)); \
5970 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5973 #define GEN_SPEOP_COMP(name) \
5974 static always_inline void gen_##name (DisasContext *ctx) \
5976 if (unlikely(!ctx->spe_enabled)) { \
5977 GEN_EXCP_NO_AP(ctx); \
5980 gen_op_load_gpr64_T0(rA(ctx->opcode)); \
5981 gen_op_load_gpr64_T1(rB(ctx->opcode)); \
5983 gen_op_store_T0_crf(crfD(ctx->opcode)); \
5987 GEN_SPEOP_ARITH2(evand
);
5988 GEN_SPEOP_ARITH2(evandc
);
5989 GEN_SPEOP_ARITH2(evxor
);
5990 GEN_SPEOP_ARITH2(evor
);
5991 GEN_SPEOP_ARITH2(evnor
);
5992 GEN_SPEOP_ARITH2(eveqv
);
5993 GEN_SPEOP_ARITH2(evorc
);
5994 GEN_SPEOP_ARITH2(evnand
);
5995 GEN_SPEOP_ARITH2(evsrwu
);
5996 GEN_SPEOP_ARITH2(evsrws
);
5997 GEN_SPEOP_ARITH2(evslw
);
5998 GEN_SPEOP_ARITH2(evrlw
);
5999 GEN_SPEOP_ARITH2(evmergehi
);
6000 GEN_SPEOP_ARITH2(evmergelo
);
6001 GEN_SPEOP_ARITH2(evmergehilo
);
6002 GEN_SPEOP_ARITH2(evmergelohi
);
6005 GEN_SPEOP_ARITH2(evaddw
);
6006 GEN_SPEOP_ARITH2(evsubfw
);
6007 GEN_SPEOP_ARITH1(evabs
);
6008 GEN_SPEOP_ARITH1(evneg
);
6009 GEN_SPEOP_ARITH1(evextsb
);
6010 GEN_SPEOP_ARITH1(evextsh
);
6011 GEN_SPEOP_ARITH1(evrndw
);
6012 GEN_SPEOP_ARITH1(evcntlzw
);
6013 GEN_SPEOP_ARITH1(evcntlsw
);
6014 static always_inline
void gen_brinc (DisasContext
*ctx
)
6016 /* Note: brinc is usable even if SPE is disabled */
6017 gen_op_load_gpr64_T0(rA(ctx
->opcode
));
6018 gen_op_load_gpr64_T1(rB(ctx
->opcode
));
6020 gen_op_store_T0_gpr64(rD(ctx
->opcode
));
6023 #define GEN_SPEOP_ARITH_IMM2(name) \
6024 static always_inline void gen_##name##i (DisasContext *ctx) \
6026 if (unlikely(!ctx->spe_enabled)) { \
6027 GEN_EXCP_NO_AP(ctx); \
6030 gen_op_load_gpr64_T0(rB(ctx->opcode)); \
6031 gen_op_splatwi_T1_64(rA(ctx->opcode)); \
6033 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
6036 #define GEN_SPEOP_LOGIC_IMM2(name) \
6037 static always_inline void gen_##name##i (DisasContext *ctx) \
6039 if (unlikely(!ctx->spe_enabled)) { \
6040 GEN_EXCP_NO_AP(ctx); \
6043 gen_op_load_gpr64_T0(rA(ctx->opcode)); \
6044 gen_op_splatwi_T1_64(rB(ctx->opcode)); \
6046 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
6049 GEN_SPEOP_ARITH_IMM2(evaddw
);
6050 #define gen_evaddiw gen_evaddwi
6051 GEN_SPEOP_ARITH_IMM2(evsubfw
);
6052 #define gen_evsubifw gen_evsubfwi
6053 GEN_SPEOP_LOGIC_IMM2(evslw
);
6054 GEN_SPEOP_LOGIC_IMM2(evsrwu
);
6055 #define gen_evsrwis gen_evsrwsi
6056 GEN_SPEOP_LOGIC_IMM2(evsrws
);
6057 #define gen_evsrwiu gen_evsrwui
6058 GEN_SPEOP_LOGIC_IMM2(evrlw
);
6060 static always_inline
void gen_evsplati (DisasContext
*ctx
)
6062 int32_t imm
= (int32_t)(rA(ctx
->opcode
) << 27) >> 27;
6064 gen_op_splatwi_T0_64(imm
);
6065 gen_op_store_T0_gpr64(rD(ctx
->opcode
));
6068 static always_inline
void gen_evsplatfi (DisasContext
*ctx
)
6070 uint32_t imm
= rA(ctx
->opcode
) << 27;
6072 gen_op_splatwi_T0_64(imm
);
6073 gen_op_store_T0_gpr64(rD(ctx
->opcode
));
6077 GEN_SPEOP_COMP(evcmpgtu
);
6078 GEN_SPEOP_COMP(evcmpgts
);
6079 GEN_SPEOP_COMP(evcmpltu
);
6080 GEN_SPEOP_COMP(evcmplts
);
6081 GEN_SPEOP_COMP(evcmpeq
);
6083 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, PPC_SPE
); ////
6084 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, PPC_SPE
);
6085 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, PPC_SPE
); ////
6086 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, PPC_SPE
);
6087 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, PPC_SPE
); ////
6088 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, PPC_SPE
); ////
6089 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, PPC_SPE
); ////
6090 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x00000000, PPC_SPE
); //
6091 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0x00000000, PPC_SPE
); ////
6092 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, PPC_SPE
); ////
6093 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, PPC_SPE
); ////
6094 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, PPC_SPE
); ////
6095 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0x00000000, PPC_SPE
); ////
6096 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, PPC_SPE
); ////
6097 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, PPC_SPE
); ////
6098 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, PPC_SPE
);
6099 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, PPC_SPE
); ////
6100 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, PPC_SPE
);
6101 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, PPC_SPE
); //
6102 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, PPC_SPE
);
6103 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, PPC_SPE
); ////
6104 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, PPC_SPE
); ////
6105 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, PPC_SPE
); ////
6106 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, PPC_SPE
); ////
6107 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, PPC_SPE
); ////
6109 static always_inline
void gen_evsel (DisasContext
*ctx
)
6111 if (unlikely(!ctx
->spe_enabled
)) {
6112 GEN_EXCP_NO_AP(ctx
);
6115 gen_op_load_crf_T0(ctx
->opcode
& 0x7);
6116 gen_op_load_gpr64_T0(rA(ctx
->opcode
));
6117 gen_op_load_gpr64_T1(rB(ctx
->opcode
));
6119 gen_op_store_T0_gpr64(rD(ctx
->opcode
));
6122 GEN_HANDLER2(evsel0
, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE
)
6126 GEN_HANDLER2(evsel1
, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE
)
6130 GEN_HANDLER2(evsel2
, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE
)
6134 GEN_HANDLER2(evsel3
, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE
)
6139 /* Load and stores */
6140 #if defined(TARGET_PPC64)
6141 /* In that case, we already have 64 bits load & stores
6142 * so, spe_ldd is equivalent to ld and spe_std is equivalent to std
6144 #if defined(CONFIG_USER_ONLY)
6145 #define gen_op_spe_ldd_raw gen_op_ld_raw
6146 #define gen_op_spe_ldd_64_raw gen_op_ld_64_raw
6147 #define gen_op_spe_ldd_le_raw gen_op_ld_le_raw
6148 #define gen_op_spe_ldd_le_64_raw gen_op_ld_le_64_raw
6149 #define gen_op_spe_stdd_raw gen_op_ld_raw
6150 #define gen_op_spe_stdd_64_raw gen_op_std_64_raw
6151 #define gen_op_spe_stdd_le_raw gen_op_std_le_raw
6152 #define gen_op_spe_stdd_le_64_raw gen_op_std_le_64_raw
6153 #else /* defined(CONFIG_USER_ONLY) */
6154 #define gen_op_spe_ldd_kernel gen_op_ld_kernel
6155 #define gen_op_spe_ldd_64_kernel gen_op_ld_64_kernel
6156 #define gen_op_spe_ldd_le_kernel gen_op_ld_kernel
6157 #define gen_op_spe_ldd_le_64_kernel gen_op_ld_64_kernel
6158 #define gen_op_spe_ldd_user gen_op_ld_user
6159 #define gen_op_spe_ldd_64_user gen_op_ld_64_user
6160 #define gen_op_spe_ldd_le_user gen_op_ld_le_user
6161 #define gen_op_spe_ldd_le_64_user gen_op_ld_le_64_user
6162 #define gen_op_spe_stdd_kernel gen_op_std_kernel
6163 #define gen_op_spe_stdd_64_kernel gen_op_std_64_kernel
6164 #define gen_op_spe_stdd_le_kernel gen_op_std_kernel
6165 #define gen_op_spe_stdd_le_64_kernel gen_op_std_64_kernel
6166 #define gen_op_spe_stdd_user gen_op_std_user
6167 #define gen_op_spe_stdd_64_user gen_op_std_64_user
6168 #define gen_op_spe_stdd_le_user gen_op_std_le_user
6169 #define gen_op_spe_stdd_le_64_user gen_op_std_le_64_user
6170 #endif /* defined(CONFIG_USER_ONLY) */
6171 #endif /* defined(TARGET_PPC64) */
6172 GEN_SPEOP_LDST(dd
, 3);
6173 GEN_SPEOP_LDST(dw
, 3);
6174 GEN_SPEOP_LDST(dh
, 3);
6175 GEN_SPEOP_LDST(whe
, 2);
6176 GEN_SPEOP_LD(whou
, 2);
6177 GEN_SPEOP_LD(whos
, 2);
6178 GEN_SPEOP_ST(who
, 2);
6180 #if defined(TARGET_PPC64)
6181 /* In that case, spe_stwwo is equivalent to stw */
6182 #if defined(CONFIG_USER_ONLY)
6183 #define gen_op_spe_stwwo_raw gen_op_stw_raw
6184 #define gen_op_spe_stwwo_le_raw gen_op_stw_le_raw
6185 #define gen_op_spe_stwwo_64_raw gen_op_stw_64_raw
6186 #define gen_op_spe_stwwo_le_64_raw gen_op_stw_le_64_raw
6188 #define gen_op_spe_stwwo_user gen_op_stw_user
6189 #define gen_op_spe_stwwo_le_user gen_op_stw_le_user
6190 #define gen_op_spe_stwwo_64_user gen_op_stw_64_user
6191 #define gen_op_spe_stwwo_le_64_user gen_op_stw_le_64_user
6192 #define gen_op_spe_stwwo_kernel gen_op_stw_kernel
6193 #define gen_op_spe_stwwo_le_kernel gen_op_stw_le_kernel
6194 #define gen_op_spe_stwwo_64_kernel gen_op_stw_64_kernel
6195 #define gen_op_spe_stwwo_le_64_kernel gen_op_stw_le_64_kernel
6198 #define _GEN_OP_SPE_STWWE(suffix) \
6199 static always_inline void gen_op_spe_stwwe_##suffix (void) \
6201 gen_op_srli32_T1_64(); \
6202 gen_op_spe_stwwo_##suffix(); \
6204 #define _GEN_OP_SPE_STWWE_LE(suffix) \
6205 static always_inline void gen_op_spe_stwwe_le_##suffix (void) \
6207 gen_op_srli32_T1_64(); \
6208 gen_op_spe_stwwo_le_##suffix(); \
6210 #if defined(TARGET_PPC64)
6211 #define GEN_OP_SPE_STWWE(suffix) \
6212 _GEN_OP_SPE_STWWE(suffix); \
6213 _GEN_OP_SPE_STWWE_LE(suffix); \
6214 static always_inline void gen_op_spe_stwwe_64_##suffix (void) \
6216 gen_op_srli32_T1_64(); \
6217 gen_op_spe_stwwo_64_##suffix(); \
6219 static always_inline void gen_op_spe_stwwe_le_64_##suffix (void) \
6221 gen_op_srli32_T1_64(); \
6222 gen_op_spe_stwwo_le_64_##suffix(); \
6225 #define GEN_OP_SPE_STWWE(suffix) \
6226 _GEN_OP_SPE_STWWE(suffix); \
6227 _GEN_OP_SPE_STWWE_LE(suffix)
6229 #if defined(CONFIG_USER_ONLY)
6230 GEN_OP_SPE_STWWE(raw
);
6231 #else /* defined(CONFIG_USER_ONLY) */
6232 GEN_OP_SPE_STWWE(kernel
);
6233 GEN_OP_SPE_STWWE(user
);
6234 #endif /* defined(CONFIG_USER_ONLY) */
6235 GEN_SPEOP_ST(wwe
, 2);
6236 GEN_SPEOP_ST(wwo
, 2);
6238 #define GEN_SPE_LDSPLAT(name, op, suffix) \
6239 static always_inline void gen_op_spe_l##name##_##suffix (void) \
6241 gen_op_##op##_##suffix(); \
6242 gen_op_splatw_T1_64(); \
6245 #define GEN_OP_SPE_LHE(suffix) \
6246 static always_inline void gen_op_spe_lhe_##suffix (void) \
6248 gen_op_spe_lh_##suffix(); \
6249 gen_op_sli16_T1_64(); \
6252 #define GEN_OP_SPE_LHX(suffix) \
6253 static always_inline void gen_op_spe_lhx_##suffix (void) \
6255 gen_op_spe_lh_##suffix(); \
6256 gen_op_extsh_T1_64(); \
6259 #if defined(CONFIG_USER_ONLY)
6260 GEN_OP_SPE_LHE(raw
);
6261 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, raw
);
6262 GEN_OP_SPE_LHE(le_raw
);
6263 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_raw
);
6264 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, raw
);
6265 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_raw
);
6266 GEN_OP_SPE_LHX(raw
);
6267 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, raw
);
6268 GEN_OP_SPE_LHX(le_raw
);
6269 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_raw
);
6270 #if defined(TARGET_PPC64)
6271 GEN_OP_SPE_LHE(64_raw
);
6272 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, 64_raw
);
6273 GEN_OP_SPE_LHE(le_64_raw
);
6274 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_64_raw
);
6275 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, 64_raw
);
6276 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_64_raw
);
6277 GEN_OP_SPE_LHX(64_raw
);
6278 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, 64_raw
);
6279 GEN_OP_SPE_LHX(le_64_raw
);
6280 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_64_raw
);
6283 GEN_OP_SPE_LHE(kernel
);
6284 GEN_OP_SPE_LHE(user
);
6285 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, kernel
);
6286 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, user
);
6287 GEN_OP_SPE_LHE(le_kernel
);
6288 GEN_OP_SPE_LHE(le_user
);
6289 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_kernel
);
6290 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_user
);
6291 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, kernel
);
6292 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, user
);
6293 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_kernel
);
6294 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_user
);
6295 GEN_OP_SPE_LHX(kernel
);
6296 GEN_OP_SPE_LHX(user
);
6297 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, kernel
);
6298 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, user
);
6299 GEN_OP_SPE_LHX(le_kernel
);
6300 GEN_OP_SPE_LHX(le_user
);
6301 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_kernel
);
6302 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_user
);
6303 #if defined(TARGET_PPC64)
6304 GEN_OP_SPE_LHE(64_kernel
);
6305 GEN_OP_SPE_LHE(64_user
);
6306 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, 64_kernel
);
6307 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, 64_user
);
6308 GEN_OP_SPE_LHE(le_64_kernel
);
6309 GEN_OP_SPE_LHE(le_64_user
);
6310 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_64_kernel
);
6311 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_64_user
);
6312 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, 64_kernel
);
6313 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, 64_user
);
6314 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_64_kernel
);
6315 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_64_user
);
6316 GEN_OP_SPE_LHX(64_kernel
);
6317 GEN_OP_SPE_LHX(64_user
);
6318 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, 64_kernel
);
6319 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, 64_user
);
6320 GEN_OP_SPE_LHX(le_64_kernel
);
6321 GEN_OP_SPE_LHX(le_64_user
);
6322 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_64_kernel
);
6323 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_64_user
);
6326 GEN_SPEOP_LD(hhesplat
, 1);
6327 GEN_SPEOP_LD(hhousplat
, 1);
6328 GEN_SPEOP_LD(hhossplat
, 1);
6329 GEN_SPEOP_LD(wwsplat
, 2);
6330 GEN_SPEOP_LD(whsplat
, 2);
6332 GEN_SPE(evlddx
, evldd
, 0x00, 0x0C, 0x00000000, PPC_SPE
); //
6333 GEN_SPE(evldwx
, evldw
, 0x01, 0x0C, 0x00000000, PPC_SPE
); //
6334 GEN_SPE(evldhx
, evldh
, 0x02, 0x0C, 0x00000000, PPC_SPE
); //
6335 GEN_SPE(evlhhesplatx
, evlhhesplat
, 0x04, 0x0C, 0x00000000, PPC_SPE
); //
6336 GEN_SPE(evlhhousplatx
, evlhhousplat
, 0x06, 0x0C, 0x00000000, PPC_SPE
); //
6337 GEN_SPE(evlhhossplatx
, evlhhossplat
, 0x07, 0x0C, 0x00000000, PPC_SPE
); //
6338 GEN_SPE(evlwhex
, evlwhe
, 0x08, 0x0C, 0x00000000, PPC_SPE
); //
6339 GEN_SPE(evlwhoux
, evlwhou
, 0x0A, 0x0C, 0x00000000, PPC_SPE
); //
6340 GEN_SPE(evlwhosx
, evlwhos
, 0x0B, 0x0C, 0x00000000, PPC_SPE
); //
6341 GEN_SPE(evlwwsplatx
, evlwwsplat
, 0x0C, 0x0C, 0x00000000, PPC_SPE
); //
6342 GEN_SPE(evlwhsplatx
, evlwhsplat
, 0x0E, 0x0C, 0x00000000, PPC_SPE
); //
6343 GEN_SPE(evstddx
, evstdd
, 0x10, 0x0C, 0x00000000, PPC_SPE
); //
6344 GEN_SPE(evstdwx
, evstdw
, 0x11, 0x0C, 0x00000000, PPC_SPE
); //
6345 GEN_SPE(evstdhx
, evstdh
, 0x12, 0x0C, 0x00000000, PPC_SPE
); //
6346 GEN_SPE(evstwhex
, evstwhe
, 0x18, 0x0C, 0x00000000, PPC_SPE
); //
6347 GEN_SPE(evstwhox
, evstwho
, 0x1A, 0x0C, 0x00000000, PPC_SPE
); //
6348 GEN_SPE(evstwwex
, evstwwe
, 0x1C, 0x0C, 0x00000000, PPC_SPE
); //
6349 GEN_SPE(evstwwox
, evstwwo
, 0x1E, 0x0C, 0x00000000, PPC_SPE
); //
6351 /* Multiply and add - TODO */
6353 GEN_SPE(speundef
, evmhessf
, 0x01, 0x10, 0x00000000, PPC_SPE
);
6354 GEN_SPE(speundef
, evmhossf
, 0x03, 0x10, 0x00000000, PPC_SPE
);
6355 GEN_SPE(evmheumi
, evmhesmi
, 0x04, 0x10, 0x00000000, PPC_SPE
);
6356 GEN_SPE(speundef
, evmhesmf
, 0x05, 0x10, 0x00000000, PPC_SPE
);
6357 GEN_SPE(evmhoumi
, evmhosmi
, 0x06, 0x10, 0x00000000, PPC_SPE
);
6358 GEN_SPE(speundef
, evmhosmf
, 0x07, 0x10, 0x00000000, PPC_SPE
);
6359 GEN_SPE(speundef
, evmhessfa
, 0x11, 0x10, 0x00000000, PPC_SPE
);
6360 GEN_SPE(speundef
, evmhossfa
, 0x13, 0x10, 0x00000000, PPC_SPE
);
6361 GEN_SPE(evmheumia
, evmhesmia
, 0x14, 0x10, 0x00000000, PPC_SPE
);
6362 GEN_SPE(speundef
, evmhesmfa
, 0x15, 0x10, 0x00000000, PPC_SPE
);
6363 GEN_SPE(evmhoumia
, evmhosmia
, 0x16, 0x10, 0x00000000, PPC_SPE
);
6364 GEN_SPE(speundef
, evmhosmfa
, 0x17, 0x10, 0x00000000, PPC_SPE
);
6366 GEN_SPE(speundef
, evmwhssf
, 0x03, 0x11, 0x00000000, PPC_SPE
);
6367 GEN_SPE(evmwlumi
, speundef
, 0x04, 0x11, 0x00000000, PPC_SPE
);
6368 GEN_SPE(evmwhumi
, evmwhsmi
, 0x06, 0x11, 0x00000000, PPC_SPE
);
6369 GEN_SPE(speundef
, evmwhsmf
, 0x07, 0x11, 0x00000000, PPC_SPE
);
6370 GEN_SPE(speundef
, evmwssf
, 0x09, 0x11, 0x00000000, PPC_SPE
);
6371 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, PPC_SPE
);
6372 GEN_SPE(speundef
, evmwsmf
, 0x0D, 0x11, 0x00000000, PPC_SPE
);
6373 GEN_SPE(speundef
, evmwhssfa
, 0x13, 0x11, 0x00000000, PPC_SPE
);
6374 GEN_SPE(evmwlumia
, speundef
, 0x14, 0x11, 0x00000000, PPC_SPE
);
6375 GEN_SPE(evmwhumia
, evmwhsmia
, 0x16, 0x11, 0x00000000, PPC_SPE
);
6376 GEN_SPE(speundef
, evmwhsmfa
, 0x17, 0x11, 0x00000000, PPC_SPE
);
6377 GEN_SPE(speundef
, evmwssfa
, 0x19, 0x11, 0x00000000, PPC_SPE
);
6378 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, PPC_SPE
);
6379 GEN_SPE(speundef
, evmwsmfa
, 0x1D, 0x11, 0x00000000, PPC_SPE
);
6381 GEN_SPE(evadduiaaw
, evaddsiaaw
, 0x00, 0x13, 0x0000F800, PPC_SPE
);
6382 GEN_SPE(evsubfusiaaw
, evsubfssiaaw
, 0x01, 0x13, 0x0000F800, PPC_SPE
);
6383 GEN_SPE(evaddumiaaw
, evaddsmiaaw
, 0x04, 0x13, 0x0000F800, PPC_SPE
);
6384 GEN_SPE(evsubfumiaaw
, evsubfsmiaaw
, 0x05, 0x13, 0x0000F800, PPC_SPE
);
6385 GEN_SPE(evdivws
, evdivwu
, 0x06, 0x13, 0x00000000, PPC_SPE
);
6386 GEN_SPE(evmra
, speundef
, 0x07, 0x13, 0x0000F800, PPC_SPE
);
6388 GEN_SPE(evmheusiaaw
, evmhessiaaw
, 0x00, 0x14, 0x00000000, PPC_SPE
);
6389 GEN_SPE(speundef
, evmhessfaaw
, 0x01, 0x14, 0x00000000, PPC_SPE
);
6390 GEN_SPE(evmhousiaaw
, evmhossiaaw
, 0x02, 0x14, 0x00000000, PPC_SPE
);
6391 GEN_SPE(speundef
, evmhossfaaw
, 0x03, 0x14, 0x00000000, PPC_SPE
);
6392 GEN_SPE(evmheumiaaw
, evmhesmiaaw
, 0x04, 0x14, 0x00000000, PPC_SPE
);
6393 GEN_SPE(speundef
, evmhesmfaaw
, 0x05, 0x14, 0x00000000, PPC_SPE
);
6394 GEN_SPE(evmhoumiaaw
, evmhosmiaaw
, 0x06, 0x14, 0x00000000, PPC_SPE
);
6395 GEN_SPE(speundef
, evmhosmfaaw
, 0x07, 0x14, 0x00000000, PPC_SPE
);
6396 GEN_SPE(evmhegumiaa
, evmhegsmiaa
, 0x14, 0x14, 0x00000000, PPC_SPE
);
6397 GEN_SPE(speundef
, evmhegsmfaa
, 0x15, 0x14, 0x00000000, PPC_SPE
);
6398 GEN_SPE(evmhogumiaa
, evmhogsmiaa
, 0x16, 0x14, 0x00000000, PPC_SPE
);
6399 GEN_SPE(speundef
, evmhogsmfaa
, 0x17, 0x14, 0x00000000, PPC_SPE
);
6401 GEN_SPE(evmwlusiaaw
, evmwlssiaaw
, 0x00, 0x15, 0x00000000, PPC_SPE
);
6402 GEN_SPE(evmwlumiaaw
, evmwlsmiaaw
, 0x04, 0x15, 0x00000000, PPC_SPE
);
6403 GEN_SPE(speundef
, evmwssfaa
, 0x09, 0x15, 0x00000000, PPC_SPE
);
6404 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, PPC_SPE
);
6405 GEN_SPE(speundef
, evmwsmfaa
, 0x0D, 0x15, 0x00000000, PPC_SPE
);
6407 GEN_SPE(evmheusianw
, evmhessianw
, 0x00, 0x16, 0x00000000, PPC_SPE
);
6408 GEN_SPE(speundef
, evmhessfanw
, 0x01, 0x16, 0x00000000, PPC_SPE
);
6409 GEN_SPE(evmhousianw
, evmhossianw
, 0x02, 0x16, 0x00000000, PPC_SPE
);
6410 GEN_SPE(speundef
, evmhossfanw
, 0x03, 0x16, 0x00000000, PPC_SPE
);
6411 GEN_SPE(evmheumianw
, evmhesmianw
, 0x04, 0x16, 0x00000000, PPC_SPE
);
6412 GEN_SPE(speundef
, evmhesmfanw
, 0x05, 0x16, 0x00000000, PPC_SPE
);
6413 GEN_SPE(evmhoumianw
, evmhosmianw
, 0x06, 0x16, 0x00000000, PPC_SPE
);
6414 GEN_SPE(speundef
, evmhosmfanw
, 0x07, 0x16, 0x00000000, PPC_SPE
);
6415 GEN_SPE(evmhegumian
, evmhegsmian
, 0x14, 0x16, 0x00000000, PPC_SPE
);
6416 GEN_SPE(speundef
, evmhegsmfan
, 0x15, 0x16, 0x00000000, PPC_SPE
);
6417 GEN_SPE(evmhigumian
, evmhigsmian
, 0x16, 0x16, 0x00000000, PPC_SPE
);
6418 GEN_SPE(speundef
, evmhogsmfan
, 0x17, 0x16, 0x00000000, PPC_SPE
);
6420 GEN_SPE(evmwlusianw
, evmwlssianw
, 0x00, 0x17, 0x00000000, PPC_SPE
);
6421 GEN_SPE(evmwlumianw
, evmwlsmianw
, 0x04, 0x17, 0x00000000, PPC_SPE
);
6422 GEN_SPE(speundef
, evmwssfan
, 0x09, 0x17, 0x00000000, PPC_SPE
);
6423 GEN_SPE(evmwumian
, evmwsmian
, 0x0C, 0x17, 0x00000000, PPC_SPE
);
6424 GEN_SPE(speundef
, evmwsmfan
, 0x0D, 0x17, 0x00000000, PPC_SPE
);
6427 /*** SPE floating-point extension ***/
6428 #define GEN_SPEFPUOP_CONV(name) \
6429 static always_inline void gen_##name (DisasContext *ctx) \
6431 gen_op_load_gpr64_T0(rB(ctx->opcode)); \
6433 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
6436 /* Single precision floating-point vectors operations */
6438 GEN_SPEOP_ARITH2(evfsadd
);
6439 GEN_SPEOP_ARITH2(evfssub
);
6440 GEN_SPEOP_ARITH2(evfsmul
);
6441 GEN_SPEOP_ARITH2(evfsdiv
);
6442 GEN_SPEOP_ARITH1(evfsabs
);
6443 GEN_SPEOP_ARITH1(evfsnabs
);
6444 GEN_SPEOP_ARITH1(evfsneg
);
6446 GEN_SPEFPUOP_CONV(evfscfui
);
6447 GEN_SPEFPUOP_CONV(evfscfsi
);
6448 GEN_SPEFPUOP_CONV(evfscfuf
);
6449 GEN_SPEFPUOP_CONV(evfscfsf
);
6450 GEN_SPEFPUOP_CONV(evfsctui
);
6451 GEN_SPEFPUOP_CONV(evfsctsi
);
6452 GEN_SPEFPUOP_CONV(evfsctuf
);
6453 GEN_SPEFPUOP_CONV(evfsctsf
);
6454 GEN_SPEFPUOP_CONV(evfsctuiz
);
6455 GEN_SPEFPUOP_CONV(evfsctsiz
);
6457 GEN_SPEOP_COMP(evfscmpgt
);
6458 GEN_SPEOP_COMP(evfscmplt
);
6459 GEN_SPEOP_COMP(evfscmpeq
);
6460 GEN_SPEOP_COMP(evfststgt
);
6461 GEN_SPEOP_COMP(evfststlt
);
6462 GEN_SPEOP_COMP(evfststeq
);
6464 /* Opcodes definitions */
6465 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, PPC_SPEFPU
); //
6466 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, PPC_SPEFPU
); //
6467 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, PPC_SPEFPU
); //
6468 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, PPC_SPEFPU
); //
6469 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, PPC_SPEFPU
); //
6470 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, PPC_SPEFPU
); //
6471 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, PPC_SPEFPU
); //
6472 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, PPC_SPEFPU
); //
6473 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, PPC_SPEFPU
); //
6474 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, PPC_SPEFPU
); //
6475 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, PPC_SPEFPU
); //
6476 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, PPC_SPEFPU
); //
6477 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, PPC_SPEFPU
); //
6478 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, PPC_SPEFPU
); //
6480 /* Single precision floating-point operations */
6482 GEN_SPEOP_ARITH2(efsadd
);
6483 GEN_SPEOP_ARITH2(efssub
);
6484 GEN_SPEOP_ARITH2(efsmul
);
6485 GEN_SPEOP_ARITH2(efsdiv
);
6486 GEN_SPEOP_ARITH1(efsabs
);
6487 GEN_SPEOP_ARITH1(efsnabs
);
6488 GEN_SPEOP_ARITH1(efsneg
);
6490 GEN_SPEFPUOP_CONV(efscfui
);
6491 GEN_SPEFPUOP_CONV(efscfsi
);
6492 GEN_SPEFPUOP_CONV(efscfuf
);
6493 GEN_SPEFPUOP_CONV(efscfsf
);
6494 GEN_SPEFPUOP_CONV(efsctui
);
6495 GEN_SPEFPUOP_CONV(efsctsi
);
6496 GEN_SPEFPUOP_CONV(efsctuf
);
6497 GEN_SPEFPUOP_CONV(efsctsf
);
6498 GEN_SPEFPUOP_CONV(efsctuiz
);
6499 GEN_SPEFPUOP_CONV(efsctsiz
);
6500 GEN_SPEFPUOP_CONV(efscfd
);
6502 GEN_SPEOP_COMP(efscmpgt
);
6503 GEN_SPEOP_COMP(efscmplt
);
6504 GEN_SPEOP_COMP(efscmpeq
);
6505 GEN_SPEOP_COMP(efststgt
);
6506 GEN_SPEOP_COMP(efststlt
);
6507 GEN_SPEOP_COMP(efststeq
);
6509 /* Opcodes definitions */
6510 GEN_SPE(efsadd
, efssub
, 0x00, 0x0A, 0x00000000, PPC_SPEFPU
); //
6511 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, PPC_SPEFPU
); //
6512 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, PPC_SPEFPU
); //
6513 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, PPC_SPEFPU
); //
6514 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, PPC_SPEFPU
); //
6515 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, PPC_SPEFPU
); //
6516 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, PPC_SPEFPU
); //
6517 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, PPC_SPEFPU
); //
6518 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, PPC_SPEFPU
); //
6519 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, PPC_SPEFPU
); //
6520 GEN_SPE(efsctuiz
, efsctsiz
, 0x0C, 0x0B, 0x00180000, PPC_SPEFPU
); //
6521 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, PPC_SPEFPU
); //
6522 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, PPC_SPEFPU
); //
6524 /* Double precision floating-point operations */
6526 GEN_SPEOP_ARITH2(efdadd
);
6527 GEN_SPEOP_ARITH2(efdsub
);
6528 GEN_SPEOP_ARITH2(efdmul
);
6529 GEN_SPEOP_ARITH2(efddiv
);
6530 GEN_SPEOP_ARITH1(efdabs
);
6531 GEN_SPEOP_ARITH1(efdnabs
);
6532 GEN_SPEOP_ARITH1(efdneg
);
6535 GEN_SPEFPUOP_CONV(efdcfui
);
6536 GEN_SPEFPUOP_CONV(efdcfsi
);
6537 GEN_SPEFPUOP_CONV(efdcfuf
);
6538 GEN_SPEFPUOP_CONV(efdcfsf
);
6539 GEN_SPEFPUOP_CONV(efdctui
);
6540 GEN_SPEFPUOP_CONV(efdctsi
);
6541 GEN_SPEFPUOP_CONV(efdctuf
);
6542 GEN_SPEFPUOP_CONV(efdctsf
);
6543 GEN_SPEFPUOP_CONV(efdctuiz
);
6544 GEN_SPEFPUOP_CONV(efdctsiz
);
6545 GEN_SPEFPUOP_CONV(efdcfs
);
6546 GEN_SPEFPUOP_CONV(efdcfuid
);
6547 GEN_SPEFPUOP_CONV(efdcfsid
);
6548 GEN_SPEFPUOP_CONV(efdctuidz
);
6549 GEN_SPEFPUOP_CONV(efdctsidz
);
6551 GEN_SPEOP_COMP(efdcmpgt
);
6552 GEN_SPEOP_COMP(efdcmplt
);
6553 GEN_SPEOP_COMP(efdcmpeq
);
6554 GEN_SPEOP_COMP(efdtstgt
);
6555 GEN_SPEOP_COMP(efdtstlt
);
6556 GEN_SPEOP_COMP(efdtsteq
);
6558 /* Opcodes definitions */
6559 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, PPC_SPEFPU
); //
6560 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, PPC_SPEFPU
); //
6561 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, PPC_SPEFPU
); //
6562 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, PPC_SPEFPU
); //
6563 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, PPC_SPEFPU
); //
6564 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, PPC_SPEFPU
); //
6565 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, PPC_SPEFPU
); //
6566 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, PPC_SPEFPU
); //
6567 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, PPC_SPEFPU
); //
6568 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, PPC_SPEFPU
); //
6569 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, PPC_SPEFPU
); //
6570 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, PPC_SPEFPU
); //
6571 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, PPC_SPEFPU
); //
6572 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, PPC_SPEFPU
); //
6573 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, PPC_SPEFPU
); //
6574 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, PPC_SPEFPU
); //
6577 /* End opcode list */
6578 GEN_OPCODE_MARK(end
);
6580 #include "translate_init.c"
6581 #include "helper_regs.h"
6583 /*****************************************************************************/
6584 /* Misc PowerPC helpers */
6585 void cpu_dump_state (CPUState
*env
, FILE *f
,
6586 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6589 #if defined(TARGET_PPC64) || 1
6601 cpu_fprintf(f
, "NIP " ADDRX
" LR " ADDRX
" CTR " ADDRX
" idx %d\n",
6602 env
->nip
, env
->lr
, env
->ctr
, env
->mmu_idx
);
6603 cpu_fprintf(f
, "MSR " REGX FILL
" XER %08x "
6604 #if !defined(NO_TIMER_DUMP)
6606 #if !defined(CONFIG_USER_ONLY)
6611 env
->msr
, hreg_load_xer(env
)
6612 #if !defined(NO_TIMER_DUMP)
6613 , cpu_ppc_load_tbu(env
), cpu_ppc_load_tbl(env
)
6614 #if !defined(CONFIG_USER_ONLY)
6615 , cpu_ppc_load_decr(env
)
6619 for (i
= 0; i
< 32; i
++) {
6620 if ((i
& (RGPL
- 1)) == 0)
6621 cpu_fprintf(f
, "GPR%02d", i
);
6622 cpu_fprintf(f
, " " REGX
, (target_ulong
)env
->gpr
[i
]);
6623 if ((i
& (RGPL
- 1)) == (RGPL
- 1))
6624 cpu_fprintf(f
, "\n");
6626 cpu_fprintf(f
, "CR ");
6627 for (i
= 0; i
< 8; i
++)
6628 cpu_fprintf(f
, "%01x", env
->crf
[i
]);
6629 cpu_fprintf(f
, " [");
6630 for (i
= 0; i
< 8; i
++) {
6632 if (env
->crf
[i
] & 0x08)
6634 else if (env
->crf
[i
] & 0x04)
6636 else if (env
->crf
[i
] & 0x02)
6638 cpu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
6640 cpu_fprintf(f
, " ] " FILL
"RES " REGX
"\n", env
->reserve
);
6641 for (i
= 0; i
< 32; i
++) {
6642 if ((i
& (RFPL
- 1)) == 0)
6643 cpu_fprintf(f
, "FPR%02d", i
);
6644 cpu_fprintf(f
, " %016" PRIx64
, *((uint64_t *)&env
->fpr
[i
]));
6645 if ((i
& (RFPL
- 1)) == (RFPL
- 1))
6646 cpu_fprintf(f
, "\n");
6648 #if !defined(CONFIG_USER_ONLY)
6649 cpu_fprintf(f
, "SRR0 " REGX
" SRR1 " REGX
" " FILL FILL FILL
6651 env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
], env
->sdr1
);
6659 void cpu_dump_statistics (CPUState
*env
, FILE*f
,
6660 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6663 #if defined(DO_PPC_STATISTICS)
6664 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
6668 for (op1
= 0; op1
< 64; op1
++) {
6670 if (is_indirect_opcode(handler
)) {
6671 t2
= ind_table(handler
);
6672 for (op2
= 0; op2
< 32; op2
++) {
6674 if (is_indirect_opcode(handler
)) {
6675 t3
= ind_table(handler
);
6676 for (op3
= 0; op3
< 32; op3
++) {
6678 if (handler
->count
== 0)
6680 cpu_fprintf(f
, "%02x %02x %02x (%02x %04d) %16s: "
6682 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
6684 handler
->count
, handler
->count
);
6687 if (handler
->count
== 0)
6689 cpu_fprintf(f
, "%02x %02x (%02x %04d) %16s: "
6691 op1
, op2
, op1
, op2
, handler
->oname
,
6692 handler
->count
, handler
->count
);
6696 if (handler
->count
== 0)
6698 cpu_fprintf(f
, "%02x (%02x ) %16s: %016llx %lld\n",
6699 op1
, op1
, handler
->oname
,
6700 handler
->count
, handler
->count
);
6706 /*****************************************************************************/
6707 static always_inline
int gen_intermediate_code_internal (CPUState
*env
,
6708 TranslationBlock
*tb
,
6711 DisasContext ctx
, *ctxp
= &ctx
;
6712 opc_handler_t
**table
, *handler
;
6713 target_ulong pc_start
;
6714 uint16_t *gen_opc_end
;
6716 int single_step
, branch_step
;
6720 gen_opc_ptr
= gen_opc_buf
;
6721 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
6722 gen_opparam_ptr
= gen_opparam_buf
;
6726 ctx
.exception
= POWERPC_EXCP_NONE
;
6727 ctx
.spr_cb
= env
->spr_cb
;
6728 supervisor
= env
->mmu_idx
;
6729 #if !defined(CONFIG_USER_ONLY)
6730 ctx
.supervisor
= supervisor
;
6732 #if defined(TARGET_PPC64)
6733 ctx
.sf_mode
= msr_sf
;
6734 ctx
.mem_idx
= (supervisor
<< 2) | (msr_sf
<< 1) | msr_le
;
6736 ctx
.mem_idx
= (supervisor
<< 1) | msr_le
;
6738 ctx
.dcache_line_size
= env
->dcache_line_size
;
6739 ctx
.fpu_enabled
= msr_fp
;
6740 #if defined(TARGET_PPCEMB)
6741 if ((env
->flags
& POWERPC_FLAG_SPE
) && msr_spe
)
6742 ctx
.spe_enabled
= msr_spe
;
6744 ctx
.spe_enabled
= 0;
6746 if ((env
->flags
& POWERPC_FLAG_VRE
) && msr_vr
)
6747 ctx
.altivec_enabled
= msr_vr
;
6749 ctx
.altivec_enabled
= 0;
6750 if ((env
->flags
& POWERPC_FLAG_SE
) && msr_se
)
6754 if ((env
->flags
& POWERPC_FLAG_BE
) && msr_be
)
6758 ctx
.singlestep_enabled
= env
->singlestep_enabled
|| single_step
== 1;
6759 #if defined (DO_SINGLE_STEP) && 0
6760 /* Single step trace mode */
6763 /* Set env in case of segfault during code fetch */
6764 while (ctx
.exception
== POWERPC_EXCP_NONE
&& gen_opc_ptr
< gen_opc_end
) {
6765 if (unlikely(env
->nb_breakpoints
> 0)) {
6766 for (j
= 0; j
< env
->nb_breakpoints
; j
++) {
6767 if (env
->breakpoints
[j
] == ctx
.nip
) {
6768 gen_update_nip(&ctx
, ctx
.nip
);
6774 if (unlikely(search_pc
)) {
6775 j
= gen_opc_ptr
- gen_opc_buf
;
6779 gen_opc_instr_start
[lj
++] = 0;
6780 gen_opc_pc
[lj
] = ctx
.nip
;
6781 gen_opc_instr_start
[lj
] = 1;
6784 #if defined PPC_DEBUG_DISAS
6785 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
6786 fprintf(logfile
, "----------------\n");
6787 fprintf(logfile
, "nip=" ADDRX
" super=%d ir=%d\n",
6788 ctx
.nip
, supervisor
, (int)msr_ir
);
6791 ctx
.opcode
= ldl_code(ctx
.nip
);
6793 ctx
.opcode
= ((ctx
.opcode
& 0xFF000000) >> 24) |
6794 ((ctx
.opcode
& 0x00FF0000) >> 8) |
6795 ((ctx
.opcode
& 0x0000FF00) << 8) |
6796 ((ctx
.opcode
& 0x000000FF) << 24);
6798 #if defined PPC_DEBUG_DISAS
6799 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
6800 fprintf(logfile
, "translate opcode %08x (%02x %02x %02x) (%s)\n",
6801 ctx
.opcode
, opc1(ctx
.opcode
), opc2(ctx
.opcode
),
6802 opc3(ctx
.opcode
), msr_le
? "little" : "big");
6806 table
= env
->opcodes
;
6807 handler
= table
[opc1(ctx
.opcode
)];
6808 if (is_indirect_opcode(handler
)) {
6809 table
= ind_table(handler
);
6810 handler
= table
[opc2(ctx
.opcode
)];
6811 if (is_indirect_opcode(handler
)) {
6812 table
= ind_table(handler
);
6813 handler
= table
[opc3(ctx
.opcode
)];
6816 /* Is opcode *REALLY* valid ? */
6817 if (unlikely(handler
->handler
== &gen_invalid
)) {
6818 if (loglevel
!= 0) {
6819 fprintf(logfile
, "invalid/unsupported opcode: "
6820 "%02x - %02x - %02x (%08x) 0x" ADDRX
" %d\n",
6821 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
6822 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
6824 printf("invalid/unsupported opcode: "
6825 "%02x - %02x - %02x (%08x) 0x" ADDRX
" %d\n",
6826 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
6827 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
6830 if (unlikely((ctx
.opcode
& handler
->inval
) != 0)) {
6831 if (loglevel
!= 0) {
6832 fprintf(logfile
, "invalid bits: %08x for opcode: "
6833 "%02x - %02x - %02x (%08x) 0x" ADDRX
"\n",
6834 ctx
.opcode
& handler
->inval
, opc1(ctx
.opcode
),
6835 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
6836 ctx
.opcode
, ctx
.nip
- 4);
6838 printf("invalid bits: %08x for opcode: "
6839 "%02x - %02x - %02x (%08x) 0x" ADDRX
"\n",
6840 ctx
.opcode
& handler
->inval
, opc1(ctx
.opcode
),
6841 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
6842 ctx
.opcode
, ctx
.nip
- 4);
6844 GEN_EXCP_INVAL(ctxp
);
6848 (*(handler
->handler
))(&ctx
);
6849 #if defined(DO_PPC_STATISTICS)
6852 /* Check trace mode exceptions */
6853 if (unlikely(branch_step
!= 0 &&
6854 ctx
.exception
== POWERPC_EXCP_BRANCH
)) {
6855 GEN_EXCP(ctxp
, POWERPC_EXCP_TRACE
, 0);
6856 } else if (unlikely(single_step
!= 0 &&
6857 (ctx
.nip
<= 0x100 || ctx
.nip
> 0xF00 ||
6858 (ctx
.nip
& 0xFC) != 0x04) &&
6859 ctx
.exception
!= POWERPC_SYSCALL
&&
6860 ctx
.exception
!= POWERPC_EXCP_TRAP
)) {
6861 GEN_EXCP(ctxp
, POWERPC_EXCP_TRACE
, 0);
6862 } else if (unlikely(((ctx
.nip
& (TARGET_PAGE_SIZE
- 1)) == 0) ||
6863 (env
->singlestep_enabled
))) {
6864 /* if we reach a page boundary or are single stepping, stop
6869 #if defined (DO_SINGLE_STEP)
6873 if (ctx
.exception
== POWERPC_EXCP_NONE
) {
6874 gen_goto_tb(&ctx
, 0, ctx
.nip
);
6875 } else if (ctx
.exception
!= POWERPC_EXCP_BRANCH
) {
6877 /* Generate the return instruction */
6880 *gen_opc_ptr
= INDEX_op_end
;
6881 if (unlikely(search_pc
)) {
6882 j
= gen_opc_ptr
- gen_opc_buf
;
6885 gen_opc_instr_start
[lj
++] = 0;
6887 tb
->size
= ctx
.nip
- pc_start
;
6889 #if defined(DEBUG_DISAS)
6890 if (loglevel
& CPU_LOG_TB_CPU
) {
6891 fprintf(logfile
, "---------------- excp: %04x\n", ctx
.exception
);
6892 cpu_dump_state(env
, logfile
, fprintf
, 0);
6894 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
6896 flags
= env
->bfd_mach
;
6897 flags
|= msr_le
<< 16;
6898 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
6899 target_disas(logfile
, pc_start
, ctx
.nip
- pc_start
, flags
);
6900 fprintf(logfile
, "\n");
6902 if (loglevel
& CPU_LOG_TB_OP
) {
6903 fprintf(logfile
, "OP:\n");
6904 dump_ops(gen_opc_buf
, gen_opparam_buf
);
6905 fprintf(logfile
, "\n");
6911 int gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
6913 return gen_intermediate_code_internal(env
, tb
, 0);
6916 int gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
6918 return gen_intermediate_code_internal(env
, tb
, 1);