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 inline void gen_set_T0 (target_ulong val)
58 #if defined(TARGET_PPC64)
60 gen_op_set_T0_64(val >> 32, val);
66 static 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 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 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 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 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)
167 #if defined(TARGET_PPCEMB)
170 ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */
171 int singlestep_enabled;
174 struct opc_handler_t {
177 /* instruction type */
180 void (*handler)(DisasContext *ctx);
181 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
182 const unsigned char *oname;
184 #if defined(DO_PPC_STATISTICS)
189 static inline void gen_set_Rc0 (DisasContext *ctx)
191 #if defined(TARGET_PPC64)
200 static inline void gen_update_nip (DisasContext *ctx, target_ulong nip)
202 #if defined(TARGET_PPC64)
204 gen_op_update_nip_64(nip >> 32, nip);
207 gen_op_update_nip(nip);
210 #define GEN_EXCP(ctx, excp, error) \
212 if ((ctx)->exception == POWERPC_EXCP_NONE) { \
213 gen_update_nip(ctx, (ctx)->nip); \
215 gen_op_raise_exception_err((excp), (error)); \
216 ctx->exception = (excp); \
219 #define GEN_EXCP_INVAL(ctx) \
220 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
221 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_INVAL)
223 #define GEN_EXCP_PRIVOPC(ctx) \
224 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
225 POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_OPC)
227 #define GEN_EXCP_PRIVREG(ctx) \
228 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
229 POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_REG)
231 #define GEN_EXCP_NO_FP(ctx) \
232 GEN_EXCP(ctx, POWERPC_EXCP_FPU, 0)
234 #define GEN_EXCP_NO_AP(ctx) \
235 GEN_EXCP(ctx, POWERPC_EXCP_APU, 0)
237 /* Stop translation */
238 static inline void GEN_STOP (DisasContext *ctx)
240 gen_update_nip(ctx, ctx->nip);
241 ctx->exception = POWERPC_EXCP_STOP;
244 /* No need to update nip here, as execution flow will change */
245 static inline void GEN_SYNC (DisasContext *ctx)
247 ctx->exception = POWERPC_EXCP_SYNC;
250 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
251 static void gen_##name (DisasContext *ctx); \
252 GEN_OPCODE(name, opc1, opc2, opc3, inval, type); \
253 static void gen_##name (DisasContext *ctx)
255 typedef struct opcode_t {
256 unsigned char opc1, opc2, opc3;
257 #if HOST_LONG_BITS == 64 /* Explicitely align to 64 bits */
258 unsigned char pad[5];
260 unsigned char pad[1];
262 opc_handler_t handler;
263 const unsigned char *oname;
266 /*****************************************************************************/
267 /*** Instruction decoding ***/
268 #define EXTRACT_HELPER(name, shift, nb) \
269 static inline uint32_t name (uint32_t opcode) \
271 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
274 #define EXTRACT_SHELPER(name, shift, nb) \
275 static inline int32_t name (uint32_t opcode) \
277 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
281 EXTRACT_HELPER(opc1, 26, 6);
283 EXTRACT_HELPER(opc2, 1, 5);
285 EXTRACT_HELPER(opc3, 6, 5);
286 /* Update Cr0 flags */
287 EXTRACT_HELPER(Rc, 0, 1);
289 EXTRACT_HELPER(rD, 21, 5);
291 EXTRACT_HELPER(rS, 21, 5);
293 EXTRACT_HELPER(rA, 16, 5);
295 EXTRACT_HELPER(rB, 11, 5);
297 EXTRACT_HELPER(rC, 6, 5);
299 EXTRACT_HELPER(crfD, 23, 3);
300 EXTRACT_HELPER(crfS, 18, 3);
301 EXTRACT_HELPER(crbD, 21, 5);
302 EXTRACT_HELPER(crbA, 16, 5);
303 EXTRACT_HELPER(crbB, 11, 5);
305 EXTRACT_HELPER(_SPR, 11, 10);
306 static inline uint32_t SPR (uint32_t opcode)
308 uint32_t sprn = _SPR(opcode);
310 return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
312 /*** Get constants ***/
313 EXTRACT_HELPER(IMM, 12, 8);
314 /* 16 bits signed immediate value */
315 EXTRACT_SHELPER(SIMM, 0, 16);
316 /* 16 bits unsigned immediate value */
317 EXTRACT_HELPER(UIMM, 0, 16);
319 EXTRACT_HELPER(NB, 11, 5);
321 EXTRACT_HELPER(SH, 11, 5);
323 EXTRACT_HELPER(MB, 6, 5);
325 EXTRACT_HELPER(ME, 1, 5);
327 EXTRACT_HELPER(TO, 21, 5);
329 EXTRACT_HELPER(CRM, 12, 8);
330 EXTRACT_HELPER(FM, 17, 8);
331 EXTRACT_HELPER(SR, 16, 4);
332 EXTRACT_HELPER(FPIMM, 20, 4);
334 /*** Jump target decoding ***/
336 EXTRACT_SHELPER(d, 0, 16);
337 /* Immediate address */
338 static inline target_ulong LI (uint32_t opcode)
340 return (opcode >> 0) & 0x03FFFFFC;
343 static inline uint32_t BD (uint32_t opcode)
345 return (opcode >> 0) & 0xFFFC;
348 EXTRACT_HELPER(BO, 21, 5);
349 EXTRACT_HELPER(BI, 16, 5);
350 /* Absolute/relative address */
351 EXTRACT_HELPER(AA, 1, 1);
353 EXTRACT_HELPER(LK, 0, 1);
355 /* Create a mask between <start> and <end> bits */
356 static inline target_ulong MASK (uint32_t start, uint32_t end)
360 #if defined(TARGET_PPC64)
361 if (likely(start == 0)) {
362 ret = (uint64_t)(-1ULL) << (63 - end);
363 } else if (likely(end == 63)) {
364 ret = (uint64_t)(-1ULL) >> start;
367 if (likely(start == 0)) {
368 ret = (uint32_t)(-1ULL) << (31 - end);
369 } else if (likely(end == 31)) {
370 ret = (uint32_t)(-1ULL) >> start;
374 ret = (((target_ulong)(-1ULL)) >> (start)) ^
375 (((target_ulong)(-1ULL) >> (end)) >> 1);
376 if (unlikely(start > end))
383 /*****************************************************************************/
384 /* PowerPC Instructions types definitions */
386 PPC_NONE = 0x0000000000000000ULL,
387 /* integer operations instructions */
388 /* flow control instructions */
389 /* virtual memory instructions */
390 /* ld/st with reservation instructions */
391 /* cache control instructions */
392 /* spr/msr access instructions */
393 PPC_INSNS_BASE = 0x0000000000000001ULL,
394 #define PPC_INTEGER PPC_INSNS_BASE
395 #define PPC_FLOW PPC_INSNS_BASE
396 #define PPC_MEM PPC_INSNS_BASE
397 #define PPC_RES PPC_INSNS_BASE
398 #define PPC_CACHE PPC_INSNS_BASE
399 #define PPC_MISC PPC_INSNS_BASE
400 /* Optional floating point instructions */
401 PPC_FLOAT = 0x0000000000000002ULL,
402 PPC_FLOAT_FSQRT = 0x0000000000000004ULL,
403 PPC_FLOAT_FRES = 0x0000000000000008ULL,
404 PPC_FLOAT_FRSQRTE = 0x0000000000000010ULL,
405 PPC_FLOAT_FSEL = 0x0000000000000020ULL,
406 PPC_FLOAT_STFIWX = 0x0000000000000040ULL,
407 /* external control instructions */
408 PPC_EXTERN = 0x0000000000000080ULL,
409 /* segment register access instructions */
410 PPC_SEGMENT = 0x0000000000000100ULL,
411 /* Optional cache control instruction */
412 PPC_CACHE_DCBA = 0x0000000000000200ULL,
413 /* Optional memory control instructions */
414 PPC_MEM_TLBIA = 0x0000000000000400ULL,
415 PPC_MEM_TLBIE = 0x0000000000000800ULL,
416 PPC_MEM_TLBSYNC = 0x0000000000001000ULL,
418 PPC_MEM_SYNC = 0x0000000000002000ULL,
419 /* PowerPC 6xx TLB management instructions */
420 PPC_6xx_TLB = 0x0000000000004000ULL,
421 /* Altivec support */
422 PPC_ALTIVEC = 0x0000000000008000ULL,
423 /* Time base mftb instruction */
424 PPC_MFTB = 0x0000000000010000ULL,
425 /* Embedded PowerPC dedicated instructions */
426 PPC_EMB_COMMON = 0x0000000000020000ULL,
427 /* PowerPC 40x exception model */
428 PPC_40x_EXCP = 0x0000000000040000ULL,
429 /* PowerPC 40x TLB management instructions */
430 PPC_40x_TLB = 0x0000000000080000ULL,
431 /* PowerPC 405 Mac instructions */
432 PPC_405_MAC = 0x0000000000100000ULL,
433 /* PowerPC 440 specific instructions */
434 PPC_440_SPEC = 0x0000000000200000ULL,
435 /* Power-to-PowerPC bridge (601) */
436 PPC_POWER_BR = 0x0000000000400000ULL,
437 /* PowerPC 602 specific */
438 PPC_602_SPEC = 0x0000000000800000ULL,
439 /* Deprecated instructions */
440 /* Original POWER instruction set */
441 PPC_POWER = 0x0000000001000000ULL,
442 /* POWER2 instruction set extension */
443 PPC_POWER2 = 0x0000000002000000ULL,
444 /* Power RTC support */
445 PPC_POWER_RTC = 0x0000000004000000ULL,
446 /* 64 bits PowerPC instructions */
447 /* 64 bits PowerPC instruction set */
448 PPC_64B = 0x0000000008000000ULL,
449 /* 64 bits hypervisor extensions */
450 PPC_64H = 0x0000000010000000ULL,
451 /* 64 bits PowerPC "bridge" features */
452 PPC_64_BRIDGE = 0x0000000020000000ULL,
453 /* BookE (embedded) PowerPC specification */
454 PPC_BOOKE = 0x0000000040000000ULL,
456 PPC_MEM_EIEIO = 0x0000000080000000ULL,
457 /* e500 vector instructions */
458 PPC_E500_VECTOR = 0x0000000100000000ULL,
459 /* PowerPC 4xx dedicated instructions */
460 PPC_4xx_COMMON = 0x0000000200000000ULL,
461 /* PowerPC 2.03 specification extensions */
462 PPC_203 = 0x0000000400000000ULL,
463 /* PowerPC 2.03 SPE extension */
464 PPC_SPE = 0x0000000800000000ULL,
465 /* PowerPC 2.03 SPE floating-point extension */
466 PPC_SPEFPU = 0x0000001000000000ULL,
468 PPC_SLBI = 0x0000002000000000ULL,
469 /* PowerPC 40x ibct instructions */
470 PPC_40x_ICBT = 0x0000004000000000ULL,
471 /* PowerPC 74xx TLB management instructions */
472 PPC_74xx_TLB = 0x0000008000000000ULL,
473 /* More BookE (embedded) instructions... */
474 PPC_BOOKE_EXT = 0x0000010000000000ULL,
475 /* rfmci is not implemented in all BookE PowerPC */
476 PPC_RFMCI = 0x0000020000000000ULL,
477 /* user-mode DCR access, implemented in PowerPC 460 */
478 PPC_DCRUX = 0x0000040000000000ULL,
479 /* New floating-point extensions (PowerPC 2.0x) */
480 PPC_FLOAT_EXT = 0x0000080000000000ULL,
483 /*****************************************************************************/
484 /* PowerPC instructions table */
485 #if HOST_LONG_BITS == 64
490 #if defined(__APPLE__)
491 #define OPCODES_SECTION \
492 __attribute__ ((section("__TEXT,__opcodes"), unused, aligned (OPC_ALIGN) ))
494 #define OPCODES_SECTION \
495 __attribute__ ((section(".opcodes"), unused, aligned (OPC_ALIGN) ))
498 #if defined(DO_PPC_STATISTICS)
499 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
500 OPCODES_SECTION opcode_t opc_##name = { \
508 .handler = &gen_##name, \
509 .oname = stringify(name), \
511 .oname = stringify(name), \
514 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
515 OPCODES_SECTION opcode_t opc_##name = { \
523 .handler = &gen_##name, \
525 .oname = stringify(name), \
529 #define GEN_OPCODE_MARK(name) \
530 OPCODES_SECTION opcode_t opc_##name = { \
536 .inval = 0x00000000, \
540 .oname = stringify(name), \
543 /* Start opcode list */
544 GEN_OPCODE_MARK(start);
546 /* Invalid instruction */
547 GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE)
552 static opc_handler_t invalid_handler = {
555 .handler = gen_invalid,
558 /*** Integer arithmetic ***/
559 #define __GEN_INT_ARITH2(name, opc1, opc2, opc3, inval, type) \
560 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
562 gen_op_load_gpr_T0(rA(ctx->opcode)); \
563 gen_op_load_gpr_T1(rB(ctx->opcode)); \
565 gen_op_store_T0_gpr(rD(ctx->opcode)); \
566 if (unlikely(Rc(ctx->opcode) != 0)) \
570 #define __GEN_INT_ARITH2_O(name, opc1, opc2, opc3, inval, type) \
571 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
573 gen_op_load_gpr_T0(rA(ctx->opcode)); \
574 gen_op_load_gpr_T1(rB(ctx->opcode)); \
576 gen_op_store_T0_gpr(rD(ctx->opcode)); \
577 if (unlikely(Rc(ctx->opcode) != 0)) \
581 #define __GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
582 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
584 gen_op_load_gpr_T0(rA(ctx->opcode)); \
586 gen_op_store_T0_gpr(rD(ctx->opcode)); \
587 if (unlikely(Rc(ctx->opcode) != 0)) \
590 #define __GEN_INT_ARITH1_O(name, opc1, opc2, opc3, type) \
591 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
593 gen_op_load_gpr_T0(rA(ctx->opcode)); \
595 gen_op_store_T0_gpr(rD(ctx->opcode)); \
596 if (unlikely(Rc(ctx->opcode) != 0)) \
600 /* Two operands arithmetic functions */
601 #define GEN_INT_ARITH2(name, opc1, opc2, opc3, type) \
602 __GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000000, type) \
603 __GEN_INT_ARITH2_O(name##o, opc1, opc2, opc3 | 0x10, 0x00000000, type)
605 /* Two operands arithmetic functions with no overflow allowed */
606 #define GEN_INT_ARITHN(name, opc1, opc2, opc3, type) \
607 __GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000400, type)
609 /* One operand arithmetic functions */
610 #define GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
611 __GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
612 __GEN_INT_ARITH1_O(name##o, opc1, opc2, opc3 | 0x10, type)
614 #if defined(TARGET_PPC64)
615 #define __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, inval, type) \
616 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
618 gen_op_load_gpr_T0(rA(ctx->opcode)); \
619 gen_op_load_gpr_T1(rB(ctx->opcode)); \
621 gen_op_##name##_64(); \
624 gen_op_store_T0_gpr(rD(ctx->opcode)); \
625 if (unlikely(Rc(ctx->opcode) != 0)) \
629 #define __GEN_INT_ARITH2_O_64(name, opc1, opc2, opc3, inval, type) \
630 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
632 gen_op_load_gpr_T0(rA(ctx->opcode)); \
633 gen_op_load_gpr_T1(rB(ctx->opcode)); \
635 gen_op_##name##_64(); \
638 gen_op_store_T0_gpr(rD(ctx->opcode)); \
639 if (unlikely(Rc(ctx->opcode) != 0)) \
643 #define __GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
644 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
646 gen_op_load_gpr_T0(rA(ctx->opcode)); \
648 gen_op_##name##_64(); \
651 gen_op_store_T0_gpr(rD(ctx->opcode)); \
652 if (unlikely(Rc(ctx->opcode) != 0)) \
655 #define __GEN_INT_ARITH1_O_64(name, opc1, opc2, opc3, type) \
656 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
658 gen_op_load_gpr_T0(rA(ctx->opcode)); \
660 gen_op_##name##_64(); \
663 gen_op_store_T0_gpr(rD(ctx->opcode)); \
664 if (unlikely(Rc(ctx->opcode) != 0)) \
668 /* Two operands arithmetic functions */
669 #define GEN_INT_ARITH2_64(name, opc1, opc2, opc3, type) \
670 __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, 0x00000000, type) \
671 __GEN_INT_ARITH2_O_64(name##o, opc1, opc2, opc3 | 0x10, 0x00000000, type)
673 /* Two operands arithmetic functions with no overflow allowed */
674 #define GEN_INT_ARITHN_64(name, opc1, opc2, opc3, type) \
675 __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, 0x00000400, type)
677 /* One operand arithmetic functions */
678 #define GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
679 __GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
680 __GEN_INT_ARITH1_O_64(name##o, opc1, opc2, opc3 | 0x10, type)
682 #define GEN_INT_ARITH2_64 GEN_INT_ARITH2
683 #define GEN_INT_ARITHN_64 GEN_INT_ARITHN
684 #define GEN_INT_ARITH1_64 GEN_INT_ARITH1
687 /* add add. addo addo. */
688 static inline void gen_op_addo (void)
694 #if defined(TARGET_PPC64)
695 #define gen_op_add_64 gen_op_add
696 static inline void gen_op_addo_64 (void)
700 gen_op_check_addo_64();
703 GEN_INT_ARITH2_64 (add, 0x1F, 0x0A, 0x08, PPC_INTEGER);
704 /* addc addc. addco addco. */
705 static inline void gen_op_addc (void)
711 static inline void gen_op_addco (void)
718 #if defined(TARGET_PPC64)
719 static inline void gen_op_addc_64 (void)
723 gen_op_check_addc_64();
725 static inline void gen_op_addco_64 (void)
729 gen_op_check_addc_64();
730 gen_op_check_addo_64();
733 GEN_INT_ARITH2_64 (addc, 0x1F, 0x0A, 0x00, PPC_INTEGER);
734 /* adde adde. addeo addeo. */
735 static inline void gen_op_addeo (void)
741 #if defined(TARGET_PPC64)
742 static inline void gen_op_addeo_64 (void)
746 gen_op_check_addo_64();
749 GEN_INT_ARITH2_64 (adde, 0x1F, 0x0A, 0x04, PPC_INTEGER);
750 /* addme addme. addmeo addmeo. */
751 static inline void gen_op_addme (void)
756 #if defined(TARGET_PPC64)
757 static inline void gen_op_addme_64 (void)
763 GEN_INT_ARITH1_64 (addme, 0x1F, 0x0A, 0x07, PPC_INTEGER);
764 /* addze addze. addzeo addzeo. */
765 static inline void gen_op_addze (void)
771 static inline void gen_op_addzeo (void)
778 #if defined(TARGET_PPC64)
779 static inline void gen_op_addze_64 (void)
783 gen_op_check_addc_64();
785 static inline void gen_op_addzeo_64 (void)
789 gen_op_check_addc_64();
790 gen_op_check_addo_64();
793 GEN_INT_ARITH1_64 (addze, 0x1F, 0x0A, 0x06, PPC_INTEGER);
794 /* divw divw. divwo divwo. */
795 GEN_INT_ARITH2 (divw, 0x1F, 0x0B, 0x0F, PPC_INTEGER);
796 /* divwu divwu. divwuo divwuo. */
797 GEN_INT_ARITH2 (divwu, 0x1F, 0x0B, 0x0E, PPC_INTEGER);
799 GEN_INT_ARITHN (mulhw, 0x1F, 0x0B, 0x02, PPC_INTEGER);
801 GEN_INT_ARITHN (mulhwu, 0x1F, 0x0B, 0x00, PPC_INTEGER);
802 /* mullw mullw. mullwo mullwo. */
803 GEN_INT_ARITH2 (mullw, 0x1F, 0x0B, 0x07, PPC_INTEGER);
804 /* neg neg. nego nego. */
805 GEN_INT_ARITH1_64 (neg, 0x1F, 0x08, 0x03, PPC_INTEGER);
806 /* subf subf. subfo subfo. */
807 static inline void gen_op_subfo (void)
811 gen_op_check_subfo();
813 #if defined(TARGET_PPC64)
814 #define gen_op_subf_64 gen_op_subf
815 static inline void gen_op_subfo_64 (void)
819 gen_op_check_subfo_64();
822 GEN_INT_ARITH2_64 (subf, 0x1F, 0x08, 0x01, PPC_INTEGER);
823 /* subfc subfc. subfco subfco. */
824 static inline void gen_op_subfc (void)
827 gen_op_check_subfc();
829 static inline void gen_op_subfco (void)
833 gen_op_check_subfc();
834 gen_op_check_subfo();
836 #if defined(TARGET_PPC64)
837 static inline void gen_op_subfc_64 (void)
840 gen_op_check_subfc_64();
842 static inline void gen_op_subfco_64 (void)
846 gen_op_check_subfc_64();
847 gen_op_check_subfo_64();
850 GEN_INT_ARITH2_64 (subfc, 0x1F, 0x08, 0x00, PPC_INTEGER);
851 /* subfe subfe. subfeo subfeo. */
852 static inline void gen_op_subfeo (void)
856 gen_op_check_subfo();
858 #if defined(TARGET_PPC64)
859 #define gen_op_subfe_64 gen_op_subfe
860 static inline void gen_op_subfeo_64 (void)
864 gen_op_check_subfo_64();
867 GEN_INT_ARITH2_64 (subfe, 0x1F, 0x08, 0x04, PPC_INTEGER);
868 /* subfme subfme. subfmeo subfmeo. */
869 GEN_INT_ARITH1_64 (subfme, 0x1F, 0x08, 0x07, PPC_INTEGER);
870 /* subfze subfze. subfzeo subfzeo. */
871 GEN_INT_ARITH1_64 (subfze, 0x1F, 0x08, 0x06, PPC_INTEGER);
873 GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
875 target_long simm = SIMM(ctx->opcode);
877 if (rA(ctx->opcode) == 0) {
881 gen_op_load_gpr_T0(rA(ctx->opcode));
882 if (likely(simm != 0))
885 gen_op_store_T0_gpr(rD(ctx->opcode));
888 GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
890 target_long simm = SIMM(ctx->opcode);
892 gen_op_load_gpr_T0(rA(ctx->opcode));
893 if (likely(simm != 0)) {
896 #if defined(TARGET_PPC64)
898 gen_op_check_addc_64();
903 gen_op_clear_xer_ca();
905 gen_op_store_T0_gpr(rD(ctx->opcode));
908 GEN_HANDLER(addic_, 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
910 target_long simm = SIMM(ctx->opcode);
912 gen_op_load_gpr_T0(rA(ctx->opcode));
913 if (likely(simm != 0)) {
916 #if defined(TARGET_PPC64)
918 gen_op_check_addc_64();
923 gen_op_clear_xer_ca();
925 gen_op_store_T0_gpr(rD(ctx->opcode));
929 GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
931 target_long simm = SIMM(ctx->opcode);
933 if (rA(ctx->opcode) == 0) {
935 gen_set_T0(simm << 16);
937 gen_op_load_gpr_T0(rA(ctx->opcode));
938 if (likely(simm != 0))
939 gen_op_addi(simm << 16);
941 gen_op_store_T0_gpr(rD(ctx->opcode));
944 GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
946 gen_op_load_gpr_T0(rA(ctx->opcode));
947 gen_op_mulli(SIMM(ctx->opcode));
948 gen_op_store_T0_gpr(rD(ctx->opcode));
951 GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
953 gen_op_load_gpr_T0(rA(ctx->opcode));
954 #if defined(TARGET_PPC64)
956 gen_op_subfic_64(SIMM(ctx->opcode));
959 gen_op_subfic(SIMM(ctx->opcode));
960 gen_op_store_T0_gpr(rD(ctx->opcode));
963 #if defined(TARGET_PPC64)
965 GEN_INT_ARITHN (mulhd, 0x1F, 0x09, 0x02, PPC_64B);
967 GEN_INT_ARITHN (mulhdu, 0x1F, 0x09, 0x00, PPC_64B);
968 /* mulld mulld. mulldo mulldo. */
969 GEN_INT_ARITH2 (mulld, 0x1F, 0x09, 0x07, PPC_64B);
970 /* divd divd. divdo divdo. */
971 GEN_INT_ARITH2 (divd, 0x1F, 0x09, 0x0F, PPC_64B);
972 /* divdu divdu. divduo divduo. */
973 GEN_INT_ARITH2 (divdu, 0x1F, 0x09, 0x0E, PPC_64B);
976 /*** Integer comparison ***/
977 #if defined(TARGET_PPC64)
978 #define GEN_CMP(name, opc, type) \
979 GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, type) \
981 gen_op_load_gpr_T0(rA(ctx->opcode)); \
982 gen_op_load_gpr_T1(rB(ctx->opcode)); \
983 if (ctx->sf_mode && (ctx->opcode & 0x00200000)) \
984 gen_op_##name##_64(); \
987 gen_op_store_T0_crf(crfD(ctx->opcode)); \
990 #define GEN_CMP(name, opc, type) \
991 GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, type) \
993 gen_op_load_gpr_T0(rA(ctx->opcode)); \
994 gen_op_load_gpr_T1(rB(ctx->opcode)); \
996 gen_op_store_T0_crf(crfD(ctx->opcode)); \
1001 GEN_CMP(cmp, 0x00, PPC_INTEGER);
1003 GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER)
1005 gen_op_load_gpr_T0(rA(ctx->opcode));
1006 #if defined(TARGET_PPC64)
1007 if (ctx->sf_mode && (ctx->opcode & 0x00200000))
1008 gen_op_cmpi_64(SIMM(ctx->opcode));
1011 gen_op_cmpi(SIMM(ctx->opcode));
1012 gen_op_store_T0_crf(crfD(ctx->opcode));
1015 GEN_CMP(cmpl, 0x01, PPC_INTEGER);
1017 GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER)
1019 gen_op_load_gpr_T0(rA(ctx->opcode));
1020 #if defined(TARGET_PPC64)
1021 if (ctx->sf_mode && (ctx->opcode & 0x00200000))
1022 gen_op_cmpli_64(UIMM(ctx->opcode));
1025 gen_op_cmpli(UIMM(ctx->opcode));
1026 gen_op_store_T0_crf(crfD(ctx->opcode));
1029 /* isel (PowerPC 2.03 specification) */
1030 GEN_HANDLER(isel, 0x1F, 0x0F, 0x00, 0x00000001, PPC_203)
1032 uint32_t bi = rC(ctx->opcode);
1035 if (rA(ctx->opcode) == 0) {
1038 gen_op_load_gpr_T1(rA(ctx->opcode));
1040 gen_op_load_gpr_T2(rB(ctx->opcode));
1041 mask = 1 << (3 - (bi & 0x03));
1042 gen_op_load_crf_T0(bi >> 2);
1043 gen_op_test_true(mask);
1045 gen_op_store_T0_gpr(rD(ctx->opcode));
1048 /*** Integer logical ***/
1049 #define __GEN_LOGICAL2(name, opc2, opc3, type) \
1050 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000000, type) \
1052 gen_op_load_gpr_T0(rS(ctx->opcode)); \
1053 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1055 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1056 if (unlikely(Rc(ctx->opcode) != 0)) \
1059 #define GEN_LOGICAL2(name, opc, type) \
1060 __GEN_LOGICAL2(name, 0x1C, opc, type)
1062 #define GEN_LOGICAL1(name, opc, type) \
1063 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type) \
1065 gen_op_load_gpr_T0(rS(ctx->opcode)); \
1067 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1068 if (unlikely(Rc(ctx->opcode) != 0)) \
1073 GEN_LOGICAL2(and, 0x00, PPC_INTEGER);
1075 GEN_LOGICAL2(andc, 0x01, PPC_INTEGER);
1077 GEN_HANDLER(andi_, 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1079 gen_op_load_gpr_T0(rS(ctx->opcode));
1080 gen_op_andi_T0(UIMM(ctx->opcode));
1081 gen_op_store_T0_gpr(rA(ctx->opcode));
1085 GEN_HANDLER(andis_, 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1087 gen_op_load_gpr_T0(rS(ctx->opcode));
1088 gen_op_andi_T0(UIMM(ctx->opcode) << 16);
1089 gen_op_store_T0_gpr(rA(ctx->opcode));
1094 GEN_LOGICAL1(cntlzw, 0x00, PPC_INTEGER);
1096 GEN_LOGICAL2(eqv, 0x08, PPC_INTEGER);
1097 /* extsb & extsb. */
1098 GEN_LOGICAL1(extsb, 0x1D, PPC_INTEGER);
1099 /* extsh & extsh. */
1100 GEN_LOGICAL1(extsh, 0x1C, PPC_INTEGER);
1102 GEN_LOGICAL2(nand, 0x0E, PPC_INTEGER);
1104 GEN_LOGICAL2(nor, 0x03, PPC_INTEGER);
1107 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER)
1111 rs = rS(ctx->opcode);
1112 ra = rA(ctx->opcode);
1113 rb = rB(ctx->opcode);
1114 /* Optimisation for mr. ri case */
1115 if (rs != ra || rs != rb) {
1116 gen_op_load_gpr_T0(rs);
1118 gen_op_load_gpr_T1(rb);
1121 gen_op_store_T0_gpr(ra);
1122 if (unlikely(Rc(ctx->opcode) != 0))
1124 } else if (unlikely(Rc(ctx->opcode) != 0)) {
1125 gen_op_load_gpr_T0(rs);
1131 GEN_LOGICAL2(orc, 0x0C, PPC_INTEGER);
1133 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER)
1135 gen_op_load_gpr_T0(rS(ctx->opcode));
1136 /* Optimisation for "set to zero" case */
1137 if (rS(ctx->opcode) != rB(ctx->opcode)) {
1138 gen_op_load_gpr_T1(rB(ctx->opcode));
1143 gen_op_store_T0_gpr(rA(ctx->opcode));
1144 if (unlikely(Rc(ctx->opcode) != 0))
1148 GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1150 target_ulong uimm = UIMM(ctx->opcode);
1152 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1154 /* XXX: should handle special NOPs for POWER series */
1157 gen_op_load_gpr_T0(rS(ctx->opcode));
1158 if (likely(uimm != 0))
1160 gen_op_store_T0_gpr(rA(ctx->opcode));
1163 GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1165 target_ulong uimm = UIMM(ctx->opcode);
1167 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1171 gen_op_load_gpr_T0(rS(ctx->opcode));
1172 if (likely(uimm != 0))
1173 gen_op_ori(uimm << 16);
1174 gen_op_store_T0_gpr(rA(ctx->opcode));
1177 GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1179 target_ulong uimm = UIMM(ctx->opcode);
1181 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1185 gen_op_load_gpr_T0(rS(ctx->opcode));
1186 if (likely(uimm != 0))
1188 gen_op_store_T0_gpr(rA(ctx->opcode));
1192 GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1194 target_ulong uimm = UIMM(ctx->opcode);
1196 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1200 gen_op_load_gpr_T0(rS(ctx->opcode));
1201 if (likely(uimm != 0))
1202 gen_op_xori(uimm << 16);
1203 gen_op_store_T0_gpr(rA(ctx->opcode));
1206 /* popcntb : PowerPC 2.03 specification */
1207 GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_203)
1209 gen_op_load_gpr_T0(rS(ctx->opcode));
1210 #if defined(TARGET_PPC64)
1212 gen_op_popcntb_64();
1216 gen_op_store_T0_gpr(rA(ctx->opcode));
1219 #if defined(TARGET_PPC64)
1220 /* extsw & extsw. */
1221 GEN_LOGICAL1(extsw, 0x1E, PPC_64B);
1223 GEN_LOGICAL1(cntlzd, 0x01, PPC_64B);
1226 /*** Integer rotate ***/
1227 /* rlwimi & rlwimi. */
1228 GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1231 uint32_t mb, me, sh;
1233 mb = MB(ctx->opcode);
1234 me = ME(ctx->opcode);
1235 sh = SH(ctx->opcode);
1236 if (likely(sh == 0)) {
1237 if (likely(mb == 0 && me == 31)) {
1238 gen_op_load_gpr_T0(rS(ctx->opcode));
1240 } else if (likely(mb == 31 && me == 0)) {
1241 gen_op_load_gpr_T0(rA(ctx->opcode));
1244 gen_op_load_gpr_T0(rS(ctx->opcode));
1245 gen_op_load_gpr_T1(rA(ctx->opcode));
1248 gen_op_load_gpr_T0(rS(ctx->opcode));
1249 gen_op_load_gpr_T1(rA(ctx->opcode));
1250 gen_op_rotli32_T0(SH(ctx->opcode));
1252 #if defined(TARGET_PPC64)
1256 mask = MASK(mb, me);
1257 gen_op_andi_T0(mask);
1258 gen_op_andi_T1(~mask);
1261 gen_op_store_T0_gpr(rA(ctx->opcode));
1262 if (unlikely(Rc(ctx->opcode) != 0))
1265 /* rlwinm & rlwinm. */
1266 GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1268 uint32_t mb, me, sh;
1270 sh = SH(ctx->opcode);
1271 mb = MB(ctx->opcode);
1272 me = ME(ctx->opcode);
1273 gen_op_load_gpr_T0(rS(ctx->opcode));
1274 if (likely(sh == 0)) {
1277 if (likely(mb == 0)) {
1278 if (likely(me == 31)) {
1279 gen_op_rotli32_T0(sh);
1281 } else if (likely(me == (31 - sh))) {
1285 } else if (likely(me == 31)) {
1286 if (likely(sh == (32 - mb))) {
1291 gen_op_rotli32_T0(sh);
1293 #if defined(TARGET_PPC64)
1297 gen_op_andi_T0(MASK(mb, me));
1299 gen_op_store_T0_gpr(rA(ctx->opcode));
1300 if (unlikely(Rc(ctx->opcode) != 0))
1303 /* rlwnm & rlwnm. */
1304 GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1308 mb = MB(ctx->opcode);
1309 me = ME(ctx->opcode);
1310 gen_op_load_gpr_T0(rS(ctx->opcode));
1311 gen_op_load_gpr_T1(rB(ctx->opcode));
1312 gen_op_rotl32_T0_T1();
1313 if (unlikely(mb != 0 || me != 31)) {
1314 #if defined(TARGET_PPC64)
1318 gen_op_andi_T0(MASK(mb, me));
1320 gen_op_store_T0_gpr(rA(ctx->opcode));
1321 if (unlikely(Rc(ctx->opcode) != 0))
1325 #if defined(TARGET_PPC64)
1326 #define GEN_PPC64_R2(name, opc1, opc2) \
1327 GEN_HANDLER(name##0, opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1329 gen_##name(ctx, 0); \
1331 GEN_HANDLER(name##1, opc1, opc2 | 0x10, 0xFF, 0x00000000, PPC_64B) \
1333 gen_##name(ctx, 1); \
1335 #define GEN_PPC64_R4(name, opc1, opc2) \
1336 GEN_HANDLER(name##0, opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1338 gen_##name(ctx, 0, 0); \
1340 GEN_HANDLER(name##1, opc1, opc2 | 0x01, 0xFF, 0x00000000, PPC_64B) \
1342 gen_##name(ctx, 0, 1); \
1344 GEN_HANDLER(name##2, opc1, opc2 | 0x10, 0xFF, 0x00000000, PPC_64B) \
1346 gen_##name(ctx, 1, 0); \
1348 GEN_HANDLER(name##3, opc1, opc2 | 0x11, 0xFF, 0x00000000, PPC_64B) \
1350 gen_##name(ctx, 1, 1); \
1353 static inline void gen_andi_T0_64 (DisasContext *ctx, uint64_t mask)
1356 gen_op_andi_T0_64(mask >> 32, mask & 0xFFFFFFFF);
1358 gen_op_andi_T0(mask);
1361 static inline void gen_andi_T1_64 (DisasContext *ctx, uint64_t mask)
1364 gen_op_andi_T1_64(mask >> 32, mask & 0xFFFFFFFF);
1366 gen_op_andi_T1(mask);
1369 static inline void gen_rldinm (DisasContext *ctx, uint32_t mb, uint32_t me,
1372 gen_op_load_gpr_T0(rS(ctx->opcode));
1373 if (likely(sh == 0)) {
1376 if (likely(mb == 0)) {
1377 if (likely(me == 63)) {
1378 gen_op_rotli64_T0(sh);
1380 } else if (likely(me == (63 - sh))) {
1384 } else if (likely(me == 63)) {
1385 if (likely(sh == (64 - mb))) {
1386 gen_op_srli_T0_64(mb);
1390 gen_op_rotli64_T0(sh);
1392 gen_andi_T0_64(ctx, MASK(mb, me));
1394 gen_op_store_T0_gpr(rA(ctx->opcode));
1395 if (unlikely(Rc(ctx->opcode) != 0))
1398 /* rldicl - rldicl. */
1399 static inline void gen_rldicl (DisasContext *ctx, int mbn, int shn)
1403 sh = SH(ctx->opcode) | (shn << 5);
1404 mb = MB(ctx->opcode) | (mbn << 5);
1405 gen_rldinm(ctx, mb, 63, sh);
1407 GEN_PPC64_R4(rldicl, 0x1E, 0x00);
1408 /* rldicr - rldicr. */
1409 static inline void gen_rldicr (DisasContext *ctx, int men, int shn)
1413 sh = SH(ctx->opcode) | (shn << 5);
1414 me = MB(ctx->opcode) | (men << 5);
1415 gen_rldinm(ctx, 0, me, sh);
1417 GEN_PPC64_R4(rldicr, 0x1E, 0x02);
1418 /* rldic - rldic. */
1419 static inline void gen_rldic (DisasContext *ctx, int mbn, int shn)
1423 sh = SH(ctx->opcode) | (shn << 5);
1424 mb = MB(ctx->opcode) | (mbn << 5);
1425 gen_rldinm(ctx, mb, 63 - sh, sh);
1427 GEN_PPC64_R4(rldic, 0x1E, 0x04);
1429 static inline void gen_rldnm (DisasContext *ctx, uint32_t mb, uint32_t me)
1431 gen_op_load_gpr_T0(rS(ctx->opcode));
1432 gen_op_load_gpr_T1(rB(ctx->opcode));
1433 gen_op_rotl64_T0_T1();
1434 if (unlikely(mb != 0 || me != 63)) {
1435 gen_andi_T0_64(ctx, MASK(mb, me));
1437 gen_op_store_T0_gpr(rA(ctx->opcode));
1438 if (unlikely(Rc(ctx->opcode) != 0))
1442 /* rldcl - rldcl. */
1443 static inline void gen_rldcl (DisasContext *ctx, int mbn)
1447 mb = MB(ctx->opcode) | (mbn << 5);
1448 gen_rldnm(ctx, mb, 63);
1450 GEN_PPC64_R2(rldcl, 0x1E, 0x08);
1451 /* rldcr - rldcr. */
1452 static inline void gen_rldcr (DisasContext *ctx, int men)
1456 me = MB(ctx->opcode) | (men << 5);
1457 gen_rldnm(ctx, 0, me);
1459 GEN_PPC64_R2(rldcr, 0x1E, 0x09);
1460 /* rldimi - rldimi. */
1461 static inline void gen_rldimi (DisasContext *ctx, int mbn, int shn)
1466 sh = SH(ctx->opcode) | (shn << 5);
1467 mb = MB(ctx->opcode) | (mbn << 5);
1468 if (likely(sh == 0)) {
1469 if (likely(mb == 0)) {
1470 gen_op_load_gpr_T0(rS(ctx->opcode));
1472 } else if (likely(mb == 63)) {
1473 gen_op_load_gpr_T0(rA(ctx->opcode));
1476 gen_op_load_gpr_T0(rS(ctx->opcode));
1477 gen_op_load_gpr_T1(rA(ctx->opcode));
1480 gen_op_load_gpr_T0(rS(ctx->opcode));
1481 gen_op_load_gpr_T1(rA(ctx->opcode));
1482 gen_op_rotli64_T0(sh);
1484 mask = MASK(mb, 63 - sh);
1485 gen_andi_T0_64(ctx, mask);
1486 gen_andi_T1_64(ctx, ~mask);
1489 gen_op_store_T0_gpr(rA(ctx->opcode));
1490 if (unlikely(Rc(ctx->opcode) != 0))
1493 GEN_PPC64_R4(rldimi, 0x1E, 0x06);
1496 /*** Integer shift ***/
1498 __GEN_LOGICAL2(slw, 0x18, 0x00, PPC_INTEGER);
1500 __GEN_LOGICAL2(sraw, 0x18, 0x18, PPC_INTEGER);
1501 /* srawi & srawi. */
1502 GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER)
1505 gen_op_load_gpr_T0(rS(ctx->opcode));
1506 if (SH(ctx->opcode) != 0) {
1507 gen_op_move_T1_T0();
1508 mb = 32 - SH(ctx->opcode);
1510 #if defined(TARGET_PPC64)
1514 gen_op_srawi(SH(ctx->opcode), MASK(mb, me));
1516 gen_op_store_T0_gpr(rA(ctx->opcode));
1517 if (unlikely(Rc(ctx->opcode) != 0))
1521 __GEN_LOGICAL2(srw, 0x18, 0x10, PPC_INTEGER);
1523 #if defined(TARGET_PPC64)
1525 __GEN_LOGICAL2(sld, 0x1B, 0x00, PPC_64B);
1527 __GEN_LOGICAL2(srad, 0x1A, 0x18, PPC_64B);
1528 /* sradi & sradi. */
1529 static inline void gen_sradi (DisasContext *ctx, int n)
1534 gen_op_load_gpr_T0(rS(ctx->opcode));
1535 sh = SH(ctx->opcode) + (n << 5);
1537 gen_op_move_T1_T0();
1538 mb = 64 - SH(ctx->opcode);
1540 mask = MASK(mb, me);
1541 gen_op_sradi(sh, mask >> 32, mask);
1543 gen_op_store_T0_gpr(rA(ctx->opcode));
1544 if (unlikely(Rc(ctx->opcode) != 0))
1547 GEN_HANDLER(sradi0, 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B)
1551 GEN_HANDLER(sradi1, 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B)
1556 __GEN_LOGICAL2(srd, 0x1B, 0x10, PPC_64B);
1559 /*** Floating-Point arithmetic ***/
1560 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, type) \
1561 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type) \
1563 if (unlikely(!ctx->fpu_enabled)) { \
1564 GEN_EXCP_NO_FP(ctx); \
1567 gen_op_reset_scrfx(); \
1568 gen_op_load_fpr_FT0(rA(ctx->opcode)); \
1569 gen_op_load_fpr_FT1(rC(ctx->opcode)); \
1570 gen_op_load_fpr_FT2(rB(ctx->opcode)); \
1575 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1576 if (unlikely(Rc(ctx->opcode) != 0)) \
1580 #define GEN_FLOAT_ACB(name, op2, type) \
1581 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, type); \
1582 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, type);
1584 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat) \
1585 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, PPC_FLOAT) \
1587 if (unlikely(!ctx->fpu_enabled)) { \
1588 GEN_EXCP_NO_FP(ctx); \
1591 gen_op_reset_scrfx(); \
1592 gen_op_load_fpr_FT0(rA(ctx->opcode)); \
1593 gen_op_load_fpr_FT1(rB(ctx->opcode)); \
1598 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1599 if (unlikely(Rc(ctx->opcode) != 0)) \
1602 #define GEN_FLOAT_AB(name, op2, inval) \
1603 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0); \
1604 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1);
1606 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat) \
1607 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, PPC_FLOAT) \
1609 if (unlikely(!ctx->fpu_enabled)) { \
1610 GEN_EXCP_NO_FP(ctx); \
1613 gen_op_reset_scrfx(); \
1614 gen_op_load_fpr_FT0(rA(ctx->opcode)); \
1615 gen_op_load_fpr_FT1(rC(ctx->opcode)); \
1620 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1621 if (unlikely(Rc(ctx->opcode) != 0)) \
1624 #define GEN_FLOAT_AC(name, op2, inval) \
1625 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0); \
1626 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1);
1628 #define GEN_FLOAT_B(name, op2, op3, type) \
1629 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type) \
1631 if (unlikely(!ctx->fpu_enabled)) { \
1632 GEN_EXCP_NO_FP(ctx); \
1635 gen_op_reset_scrfx(); \
1636 gen_op_load_fpr_FT0(rB(ctx->opcode)); \
1638 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1639 if (unlikely(Rc(ctx->opcode) != 0)) \
1643 #define GEN_FLOAT_BS(name, op1, op2, type) \
1644 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type) \
1646 if (unlikely(!ctx->fpu_enabled)) { \
1647 GEN_EXCP_NO_FP(ctx); \
1650 gen_op_reset_scrfx(); \
1651 gen_op_load_fpr_FT0(rB(ctx->opcode)); \
1653 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1654 if (unlikely(Rc(ctx->opcode) != 0)) \
1659 GEN_FLOAT_AB(add, 0x15, 0x000007C0);
1661 GEN_FLOAT_AB(div, 0x12, 0x000007C0);
1663 GEN_FLOAT_AC(mul, 0x19, 0x0000F800);
1666 GEN_FLOAT_BS(re, 0x3F, 0x18, PPC_FLOAT_EXT);
1669 GEN_FLOAT_BS(res, 0x3B, 0x18, PPC_FLOAT_FRES);
1672 GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, PPC_FLOAT_FRSQRTE);
1675 _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, PPC_FLOAT_FSEL);
1677 GEN_FLOAT_AB(sub, 0x14, 0x000007C0);
1680 GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT)
1682 if (unlikely(!ctx->fpu_enabled)) {
1683 GEN_EXCP_NO_FP(ctx);
1686 gen_op_reset_scrfx();
1687 gen_op_load_fpr_FT0(rB(ctx->opcode));
1689 gen_op_store_FT0_fpr(rD(ctx->opcode));
1690 if (unlikely(Rc(ctx->opcode) != 0))
1694 GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT)
1696 if (unlikely(!ctx->fpu_enabled)) {
1697 GEN_EXCP_NO_FP(ctx);
1700 gen_op_reset_scrfx();
1701 gen_op_load_fpr_FT0(rB(ctx->opcode));
1704 gen_op_store_FT0_fpr(rD(ctx->opcode));
1705 if (unlikely(Rc(ctx->opcode) != 0))
1709 /*** Floating-Point multiply-and-add ***/
1710 /* fmadd - fmadds */
1711 GEN_FLOAT_ACB(madd, 0x1D, PPC_FLOAT);
1712 /* fmsub - fmsubs */
1713 GEN_FLOAT_ACB(msub, 0x1C, PPC_FLOAT);
1714 /* fnmadd - fnmadds */
1715 GEN_FLOAT_ACB(nmadd, 0x1F, PPC_FLOAT);
1716 /* fnmsub - fnmsubs */
1717 GEN_FLOAT_ACB(nmsub, 0x1E, PPC_FLOAT);
1719 /*** Floating-Point round & convert ***/
1721 GEN_FLOAT_B(ctiw, 0x0E, 0x00, PPC_FLOAT);
1723 GEN_FLOAT_B(ctiwz, 0x0F, 0x00, PPC_FLOAT);
1725 GEN_FLOAT_B(rsp, 0x0C, 0x00, PPC_FLOAT);
1726 #if defined(TARGET_PPC64)
1728 GEN_FLOAT_B(cfid, 0x0E, 0x1A, PPC_64B);
1730 GEN_FLOAT_B(ctid, 0x0E, 0x19, PPC_64B);
1732 GEN_FLOAT_B(ctidz, 0x0F, 0x19, PPC_64B);
1736 GEN_FLOAT_B(rin, 0x08, 0x0C, PPC_FLOAT_EXT);
1738 GEN_FLOAT_B(riz, 0x08, 0x0D, PPC_FLOAT_EXT);
1740 GEN_FLOAT_B(rip, 0x08, 0x0E, PPC_FLOAT_EXT);
1742 GEN_FLOAT_B(rim, 0x08, 0x0F, PPC_FLOAT_EXT);
1744 /*** Floating-Point compare ***/
1746 GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT)
1748 if (unlikely(!ctx->fpu_enabled)) {
1749 GEN_EXCP_NO_FP(ctx);
1752 gen_op_reset_scrfx();
1753 gen_op_load_fpr_FT0(rA(ctx->opcode));
1754 gen_op_load_fpr_FT1(rB(ctx->opcode));
1756 gen_op_store_T0_crf(crfD(ctx->opcode));
1760 GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT)
1762 if (unlikely(!ctx->fpu_enabled)) {
1763 GEN_EXCP_NO_FP(ctx);
1766 gen_op_reset_scrfx();
1767 gen_op_load_fpr_FT0(rA(ctx->opcode));
1768 gen_op_load_fpr_FT1(rB(ctx->opcode));
1770 gen_op_store_T0_crf(crfD(ctx->opcode));
1773 /*** Floating-point move ***/
1775 GEN_FLOAT_B(abs, 0x08, 0x08, PPC_FLOAT);
1778 GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT)
1780 if (unlikely(!ctx->fpu_enabled)) {
1781 GEN_EXCP_NO_FP(ctx);
1784 gen_op_reset_scrfx();
1785 gen_op_load_fpr_FT0(rB(ctx->opcode));
1786 gen_op_store_FT0_fpr(rD(ctx->opcode));
1787 if (unlikely(Rc(ctx->opcode) != 0))
1792 GEN_FLOAT_B(nabs, 0x08, 0x04, PPC_FLOAT);
1794 GEN_FLOAT_B(neg, 0x08, 0x01, PPC_FLOAT);
1796 /*** Floating-Point status & ctrl register ***/
1798 GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT)
1800 if (unlikely(!ctx->fpu_enabled)) {
1801 GEN_EXCP_NO_FP(ctx);
1804 gen_op_load_fpscr_T0(crfS(ctx->opcode));
1805 gen_op_store_T0_crf(crfD(ctx->opcode));
1806 gen_op_clear_fpscr(crfS(ctx->opcode));
1810 GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT)
1812 if (unlikely(!ctx->fpu_enabled)) {
1813 GEN_EXCP_NO_FP(ctx);
1816 gen_op_load_fpscr();
1817 gen_op_store_FT0_fpr(rD(ctx->opcode));
1818 if (unlikely(Rc(ctx->opcode) != 0))
1823 GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT)
1827 if (unlikely(!ctx->fpu_enabled)) {
1828 GEN_EXCP_NO_FP(ctx);
1831 crb = crbD(ctx->opcode) >> 2;
1832 gen_op_load_fpscr_T0(crb);
1833 gen_op_andi_T0(~(1 << (crbD(ctx->opcode) & 0x03)));
1834 gen_op_store_T0_fpscr(crb);
1835 if (unlikely(Rc(ctx->opcode) != 0))
1840 GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT)
1844 if (unlikely(!ctx->fpu_enabled)) {
1845 GEN_EXCP_NO_FP(ctx);
1848 crb = crbD(ctx->opcode) >> 2;
1849 gen_op_load_fpscr_T0(crb);
1850 gen_op_ori(1 << (crbD(ctx->opcode) & 0x03));
1851 gen_op_store_T0_fpscr(crb);
1852 if (unlikely(Rc(ctx->opcode) != 0))
1857 GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x02010000, PPC_FLOAT)
1859 if (unlikely(!ctx->fpu_enabled)) {
1860 GEN_EXCP_NO_FP(ctx);
1863 gen_op_load_fpr_FT0(rB(ctx->opcode));
1864 gen_op_store_fpscr(FM(ctx->opcode));
1865 if (unlikely(Rc(ctx->opcode) != 0))
1870 GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT)
1872 if (unlikely(!ctx->fpu_enabled)) {
1873 GEN_EXCP_NO_FP(ctx);
1876 gen_op_store_T0_fpscri(crbD(ctx->opcode) >> 2, FPIMM(ctx->opcode));
1877 if (unlikely(Rc(ctx->opcode) != 0))
1881 /*** Addressing modes ***/
1882 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
1883 static inline void gen_addr_imm_index (DisasContext *ctx, int maskl)
1885 target_long simm = SIMM(ctx->opcode);
1889 if (rA(ctx->opcode) == 0) {
1892 gen_op_load_gpr_T0(rA(ctx->opcode));
1893 if (likely(simm != 0))
1896 #ifdef DEBUG_MEMORY_ACCESSES
1897 gen_op_print_mem_EA();
1901 static inline void gen_addr_reg_index (DisasContext *ctx)
1903 if (rA(ctx->opcode) == 0) {
1904 gen_op_load_gpr_T0(rB(ctx->opcode));
1906 gen_op_load_gpr_T0(rA(ctx->opcode));
1907 gen_op_load_gpr_T1(rB(ctx->opcode));
1910 #ifdef DEBUG_MEMORY_ACCESSES
1911 gen_op_print_mem_EA();
1915 static inline void gen_addr_register (DisasContext *ctx)
1917 if (rA(ctx->opcode) == 0) {
1920 gen_op_load_gpr_T0(rA(ctx->opcode));
1922 #ifdef DEBUG_MEMORY_ACCESSES
1923 gen_op_print_mem_EA();
1927 /*** Integer load ***/
1928 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
1929 #if defined(CONFIG_USER_ONLY)
1930 #if defined(TARGET_PPC64)
1931 #define OP_LD_TABLE(width) \
1932 static GenOpFunc *gen_op_l##width[] = { \
1933 &gen_op_l##width##_raw, \
1934 &gen_op_l##width##_le_raw, \
1935 &gen_op_l##width##_64_raw, \
1936 &gen_op_l##width##_le_64_raw, \
1938 #define OP_ST_TABLE(width) \
1939 static GenOpFunc *gen_op_st##width[] = { \
1940 &gen_op_st##width##_raw, \
1941 &gen_op_st##width##_le_raw, \
1942 &gen_op_st##width##_64_raw, \
1943 &gen_op_st##width##_le_64_raw, \
1945 /* Byte access routine are endian safe */
1946 #define gen_op_stb_le_64_raw gen_op_stb_64_raw
1947 #define gen_op_lbz_le_64_raw gen_op_lbz_64_raw
1949 #define OP_LD_TABLE(width) \
1950 static GenOpFunc *gen_op_l##width[] = { \
1951 &gen_op_l##width##_raw, \
1952 &gen_op_l##width##_le_raw, \
1954 #define OP_ST_TABLE(width) \
1955 static GenOpFunc *gen_op_st##width[] = { \
1956 &gen_op_st##width##_raw, \
1957 &gen_op_st##width##_le_raw, \
1960 /* Byte access routine are endian safe */
1961 #define gen_op_stb_le_raw gen_op_stb_raw
1962 #define gen_op_lbz_le_raw gen_op_lbz_raw
1964 #if defined(TARGET_PPC64)
1965 #define OP_LD_TABLE(width) \
1966 static GenOpFunc *gen_op_l##width[] = { \
1967 &gen_op_l##width##_user, \
1968 &gen_op_l##width##_le_user, \
1969 &gen_op_l##width##_kernel, \
1970 &gen_op_l##width##_le_kernel, \
1971 &gen_op_l##width##_64_user, \
1972 &gen_op_l##width##_le_64_user, \
1973 &gen_op_l##width##_64_kernel, \
1974 &gen_op_l##width##_le_64_kernel, \
1976 #define OP_ST_TABLE(width) \
1977 static GenOpFunc *gen_op_st##width[] = { \
1978 &gen_op_st##width##_user, \
1979 &gen_op_st##width##_le_user, \
1980 &gen_op_st##width##_kernel, \
1981 &gen_op_st##width##_le_kernel, \
1982 &gen_op_st##width##_64_user, \
1983 &gen_op_st##width##_le_64_user, \
1984 &gen_op_st##width##_64_kernel, \
1985 &gen_op_st##width##_le_64_kernel, \
1987 /* Byte access routine are endian safe */
1988 #define gen_op_stb_le_64_user gen_op_stb_64_user
1989 #define gen_op_lbz_le_64_user gen_op_lbz_64_user
1990 #define gen_op_stb_le_64_kernel gen_op_stb_64_kernel
1991 #define gen_op_lbz_le_64_kernel gen_op_lbz_64_kernel
1993 #define OP_LD_TABLE(width) \
1994 static GenOpFunc *gen_op_l##width[] = { \
1995 &gen_op_l##width##_user, \
1996 &gen_op_l##width##_le_user, \
1997 &gen_op_l##width##_kernel, \
1998 &gen_op_l##width##_le_kernel, \
2000 #define OP_ST_TABLE(width) \
2001 static GenOpFunc *gen_op_st##width[] = { \
2002 &gen_op_st##width##_user, \
2003 &gen_op_st##width##_le_user, \
2004 &gen_op_st##width##_kernel, \
2005 &gen_op_st##width##_le_kernel, \
2008 /* Byte access routine are endian safe */
2009 #define gen_op_stb_le_user gen_op_stb_user
2010 #define gen_op_lbz_le_user gen_op_lbz_user
2011 #define gen_op_stb_le_kernel gen_op_stb_kernel
2012 #define gen_op_lbz_le_kernel gen_op_lbz_kernel
2015 #define GEN_LD(width, opc, type) \
2016 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2018 gen_addr_imm_index(ctx, 0); \
2019 op_ldst(l##width); \
2020 gen_op_store_T1_gpr(rD(ctx->opcode)); \
2023 #define GEN_LDU(width, opc, type) \
2024 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2026 if (unlikely(rA(ctx->opcode) == 0 || \
2027 rA(ctx->opcode) == rD(ctx->opcode))) { \
2028 GEN_EXCP_INVAL(ctx); \
2031 if (type == PPC_64B) \
2032 gen_addr_imm_index(ctx, 1); \
2034 gen_addr_imm_index(ctx, 0); \
2035 op_ldst(l##width); \
2036 gen_op_store_T1_gpr(rD(ctx->opcode)); \
2037 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2040 #define GEN_LDUX(width, opc2, opc3, type) \
2041 GEN_HANDLER(l##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2043 if (unlikely(rA(ctx->opcode) == 0 || \
2044 rA(ctx->opcode) == rD(ctx->opcode))) { \
2045 GEN_EXCP_INVAL(ctx); \
2048 gen_addr_reg_index(ctx); \
2049 op_ldst(l##width); \
2050 gen_op_store_T1_gpr(rD(ctx->opcode)); \
2051 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2054 #define GEN_LDX(width, opc2, opc3, type) \
2055 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2057 gen_addr_reg_index(ctx); \
2058 op_ldst(l##width); \
2059 gen_op_store_T1_gpr(rD(ctx->opcode)); \
2062 #define GEN_LDS(width, op, type) \
2063 OP_LD_TABLE(width); \
2064 GEN_LD(width, op | 0x20, type); \
2065 GEN_LDU(width, op | 0x21, type); \
2066 GEN_LDUX(width, 0x17, op | 0x01, type); \
2067 GEN_LDX(width, 0x17, op | 0x00, type)
2069 /* lbz lbzu lbzux lbzx */
2070 GEN_LDS(bz, 0x02, PPC_INTEGER);
2071 /* lha lhau lhaux lhax */
2072 GEN_LDS(ha, 0x0A, PPC_INTEGER);
2073 /* lhz lhzu lhzux lhzx */
2074 GEN_LDS(hz, 0x08, PPC_INTEGER);
2075 /* lwz lwzu lwzux lwzx */
2076 GEN_LDS(wz, 0x00, PPC_INTEGER);
2077 #if defined(TARGET_PPC64)
2081 GEN_LDUX(wa, 0x15, 0x0B, PPC_64B);
2083 GEN_LDX(wa, 0x15, 0x0A, PPC_64B);
2085 GEN_LDUX(d, 0x15, 0x01, PPC_64B);
2087 GEN_LDX(d, 0x15, 0x00, PPC_64B);
2088 GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B)
2090 if (Rc(ctx->opcode)) {
2091 if (unlikely(rA(ctx->opcode) == 0 ||
2092 rA(ctx->opcode) == rD(ctx->opcode))) {
2093 GEN_EXCP_INVAL(ctx);
2097 gen_addr_imm_index(ctx, 1);
2098 if (ctx->opcode & 0x02) {
2099 /* lwa (lwau is undefined) */
2105 gen_op_store_T1_gpr(rD(ctx->opcode));
2106 if (Rc(ctx->opcode))
2107 gen_op_store_T0_gpr(rA(ctx->opcode));
2111 /*** Integer store ***/
2112 #define GEN_ST(width, opc, type) \
2113 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2115 gen_addr_imm_index(ctx, 0); \
2116 gen_op_load_gpr_T1(rS(ctx->opcode)); \
2117 op_ldst(st##width); \
2120 #define GEN_STU(width, opc, type) \
2121 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2123 if (unlikely(rA(ctx->opcode) == 0)) { \
2124 GEN_EXCP_INVAL(ctx); \
2127 if (type == PPC_64B) \
2128 gen_addr_imm_index(ctx, 1); \
2130 gen_addr_imm_index(ctx, 0); \
2131 gen_op_load_gpr_T1(rS(ctx->opcode)); \
2132 op_ldst(st##width); \
2133 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2136 #define GEN_STUX(width, opc2, opc3, type) \
2137 GEN_HANDLER(st##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2139 if (unlikely(rA(ctx->opcode) == 0)) { \
2140 GEN_EXCP_INVAL(ctx); \
2143 gen_addr_reg_index(ctx); \
2144 gen_op_load_gpr_T1(rS(ctx->opcode)); \
2145 op_ldst(st##width); \
2146 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2149 #define GEN_STX(width, opc2, opc3, type) \
2150 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2152 gen_addr_reg_index(ctx); \
2153 gen_op_load_gpr_T1(rS(ctx->opcode)); \
2154 op_ldst(st##width); \
2157 #define GEN_STS(width, op, type) \
2158 OP_ST_TABLE(width); \
2159 GEN_ST(width, op | 0x20, type); \
2160 GEN_STU(width, op | 0x21, type); \
2161 GEN_STUX(width, 0x17, op | 0x01, type); \
2162 GEN_STX(width, 0x17, op | 0x00, type)
2164 /* stb stbu stbux stbx */
2165 GEN_STS(b, 0x06, PPC_INTEGER);
2166 /* sth sthu sthux sthx */
2167 GEN_STS(h, 0x0C, PPC_INTEGER);
2168 /* stw stwu stwux stwx */
2169 GEN_STS(w, 0x04, PPC_INTEGER);
2170 #if defined(TARGET_PPC64)
2172 GEN_STUX(d, 0x15, 0x05, PPC_64B);
2173 GEN_STX(d, 0x15, 0x04, PPC_64B);
2174 GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000002, PPC_64B)
2176 if (Rc(ctx->opcode)) {
2177 if (unlikely(rA(ctx->opcode) == 0)) {
2178 GEN_EXCP_INVAL(ctx);
2182 gen_addr_imm_index(ctx, 1);
2183 gen_op_load_gpr_T1(rS(ctx->opcode));
2185 if (Rc(ctx->opcode))
2186 gen_op_store_T0_gpr(rA(ctx->opcode));
2189 /*** Integer load and store with byte reverse ***/
2192 GEN_LDX(hbr, 0x16, 0x18, PPC_INTEGER);
2195 GEN_LDX(wbr, 0x16, 0x10, PPC_INTEGER);
2198 GEN_STX(hbr, 0x16, 0x1C, PPC_INTEGER);
2201 GEN_STX(wbr, 0x16, 0x14, PPC_INTEGER);
2203 /*** Integer load and store multiple ***/
2204 #define op_ldstm(name, reg) (*gen_op_##name[ctx->mem_idx])(reg)
2205 #if defined(TARGET_PPC64)
2206 #if defined(CONFIG_USER_ONLY)
2207 static GenOpFunc1 *gen_op_lmw[] = {
2211 &gen_op_lmw_le_64_raw,
2213 static GenOpFunc1 *gen_op_stmw[] = {
2214 &gen_op_stmw_64_raw,
2215 &gen_op_stmw_le_64_raw,
2218 static GenOpFunc1 *gen_op_lmw[] = {
2220 &gen_op_lmw_le_user,
2222 &gen_op_lmw_le_kernel,
2223 &gen_op_lmw_64_user,
2224 &gen_op_lmw_le_64_user,
2225 &gen_op_lmw_64_kernel,
2226 &gen_op_lmw_le_64_kernel,
2228 static GenOpFunc1 *gen_op_stmw[] = {
2230 &gen_op_stmw_le_user,
2231 &gen_op_stmw_kernel,
2232 &gen_op_stmw_le_kernel,
2233 &gen_op_stmw_64_user,
2234 &gen_op_stmw_le_64_user,
2235 &gen_op_stmw_64_kernel,
2236 &gen_op_stmw_le_64_kernel,
2240 #if defined(CONFIG_USER_ONLY)
2241 static GenOpFunc1 *gen_op_lmw[] = {
2245 static GenOpFunc1 *gen_op_stmw[] = {
2247 &gen_op_stmw_le_raw,
2250 static GenOpFunc1 *gen_op_lmw[] = {
2252 &gen_op_lmw_le_user,
2254 &gen_op_lmw_le_kernel,
2256 static GenOpFunc1 *gen_op_stmw[] = {
2258 &gen_op_stmw_le_user,
2259 &gen_op_stmw_kernel,
2260 &gen_op_stmw_le_kernel,
2266 GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
2268 /* NIP cannot be restored if the memory exception comes from an helper */
2269 gen_update_nip(ctx, ctx->nip - 4);
2270 gen_addr_imm_index(ctx, 0);
2271 op_ldstm(lmw, rD(ctx->opcode));
2275 GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
2277 /* NIP cannot be restored if the memory exception comes from an helper */
2278 gen_update_nip(ctx, ctx->nip - 4);
2279 gen_addr_imm_index(ctx, 0);
2280 op_ldstm(stmw, rS(ctx->opcode));
2283 /*** Integer load and store strings ***/
2284 #define op_ldsts(name, start) (*gen_op_##name[ctx->mem_idx])(start)
2285 #define op_ldstsx(name, rd, ra, rb) (*gen_op_##name[ctx->mem_idx])(rd, ra, rb)
2286 #if defined(TARGET_PPC64)
2287 #if defined(CONFIG_USER_ONLY)
2288 static GenOpFunc1 *gen_op_lswi[] = {
2290 &gen_op_lswi_le_raw,
2291 &gen_op_lswi_64_raw,
2292 &gen_op_lswi_le_64_raw,
2294 static GenOpFunc3 *gen_op_lswx[] = {
2296 &gen_op_lswx_le_raw,
2297 &gen_op_lswx_64_raw,
2298 &gen_op_lswx_le_64_raw,
2300 static GenOpFunc1 *gen_op_stsw[] = {
2302 &gen_op_stsw_le_raw,
2303 &gen_op_stsw_64_raw,
2304 &gen_op_stsw_le_64_raw,
2307 static GenOpFunc1 *gen_op_lswi[] = {
2309 &gen_op_lswi_le_user,
2310 &gen_op_lswi_kernel,
2311 &gen_op_lswi_le_kernel,
2312 &gen_op_lswi_64_user,
2313 &gen_op_lswi_le_64_user,
2314 &gen_op_lswi_64_kernel,
2315 &gen_op_lswi_le_64_kernel,
2317 static GenOpFunc3 *gen_op_lswx[] = {
2319 &gen_op_lswx_le_user,
2320 &gen_op_lswx_kernel,
2321 &gen_op_lswx_le_kernel,
2322 &gen_op_lswx_64_user,
2323 &gen_op_lswx_le_64_user,
2324 &gen_op_lswx_64_kernel,
2325 &gen_op_lswx_le_64_kernel,
2327 static GenOpFunc1 *gen_op_stsw[] = {
2329 &gen_op_stsw_le_user,
2330 &gen_op_stsw_kernel,
2331 &gen_op_stsw_le_kernel,
2332 &gen_op_stsw_64_user,
2333 &gen_op_stsw_le_64_user,
2334 &gen_op_stsw_64_kernel,
2335 &gen_op_stsw_le_64_kernel,
2339 #if defined(CONFIG_USER_ONLY)
2340 static GenOpFunc1 *gen_op_lswi[] = {
2342 &gen_op_lswi_le_raw,
2344 static GenOpFunc3 *gen_op_lswx[] = {
2346 &gen_op_lswx_le_raw,
2348 static GenOpFunc1 *gen_op_stsw[] = {
2350 &gen_op_stsw_le_raw,
2353 static GenOpFunc1 *gen_op_lswi[] = {
2355 &gen_op_lswi_le_user,
2356 &gen_op_lswi_kernel,
2357 &gen_op_lswi_le_kernel,
2359 static GenOpFunc3 *gen_op_lswx[] = {
2361 &gen_op_lswx_le_user,
2362 &gen_op_lswx_kernel,
2363 &gen_op_lswx_le_kernel,
2365 static GenOpFunc1 *gen_op_stsw[] = {
2367 &gen_op_stsw_le_user,
2368 &gen_op_stsw_kernel,
2369 &gen_op_stsw_le_kernel,
2375 /* PowerPC32 specification says we must generate an exception if
2376 * rA is in the range of registers to be loaded.
2377 * In an other hand, IBM says this is valid, but rA won't be loaded.
2378 * For now, I'll follow the spec...
2380 GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_INTEGER)
2382 int nb = NB(ctx->opcode);
2383 int start = rD(ctx->opcode);
2384 int ra = rA(ctx->opcode);
2390 if (unlikely(((start + nr) > 32 &&
2391 start <= ra && (start + nr - 32) > ra) ||
2392 ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) {
2393 GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM,
2394 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_LSWX);
2397 /* NIP cannot be restored if the memory exception comes from an helper */
2398 gen_update_nip(ctx, ctx->nip - 4);
2399 gen_addr_register(ctx);
2401 op_ldsts(lswi, start);
2405 GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_INTEGER)
2407 int ra = rA(ctx->opcode);
2408 int rb = rB(ctx->opcode);
2410 /* NIP cannot be restored if the memory exception comes from an helper */
2411 gen_update_nip(ctx, ctx->nip - 4);
2412 gen_addr_reg_index(ctx);
2416 gen_op_load_xer_bc();
2417 op_ldstsx(lswx, rD(ctx->opcode), ra, rb);
2421 GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_INTEGER)
2423 int nb = NB(ctx->opcode);
2425 /* NIP cannot be restored if the memory exception comes from an helper */
2426 gen_update_nip(ctx, ctx->nip - 4);
2427 gen_addr_register(ctx);
2431 op_ldsts(stsw, rS(ctx->opcode));
2435 GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_INTEGER)
2437 /* NIP cannot be restored if the memory exception comes from an helper */
2438 gen_update_nip(ctx, ctx->nip - 4);
2439 gen_addr_reg_index(ctx);
2440 gen_op_load_xer_bc();
2441 op_ldsts(stsw, rS(ctx->opcode));
2444 /*** Memory synchronisation ***/
2446 GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FF0801, PPC_MEM_EIEIO)
2451 GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FF0801, PPC_MEM)
2456 #define op_lwarx() (*gen_op_lwarx[ctx->mem_idx])()
2457 #define op_stwcx() (*gen_op_stwcx[ctx->mem_idx])()
2458 #if defined(TARGET_PPC64)
2459 #if defined(CONFIG_USER_ONLY)
2460 static GenOpFunc *gen_op_lwarx[] = {
2462 &gen_op_lwarx_le_raw,
2463 &gen_op_lwarx_64_raw,
2464 &gen_op_lwarx_le_64_raw,
2466 static GenOpFunc *gen_op_stwcx[] = {
2468 &gen_op_stwcx_le_raw,
2469 &gen_op_stwcx_64_raw,
2470 &gen_op_stwcx_le_64_raw,
2473 static GenOpFunc *gen_op_lwarx[] = {
2475 &gen_op_lwarx_le_user,
2476 &gen_op_lwarx_kernel,
2477 &gen_op_lwarx_le_kernel,
2478 &gen_op_lwarx_64_user,
2479 &gen_op_lwarx_le_64_user,
2480 &gen_op_lwarx_64_kernel,
2481 &gen_op_lwarx_le_64_kernel,
2483 static GenOpFunc *gen_op_stwcx[] = {
2485 &gen_op_stwcx_le_user,
2486 &gen_op_stwcx_kernel,
2487 &gen_op_stwcx_le_kernel,
2488 &gen_op_stwcx_64_user,
2489 &gen_op_stwcx_le_64_user,
2490 &gen_op_stwcx_64_kernel,
2491 &gen_op_stwcx_le_64_kernel,
2495 #if defined(CONFIG_USER_ONLY)
2496 static GenOpFunc *gen_op_lwarx[] = {
2498 &gen_op_lwarx_le_raw,
2500 static GenOpFunc *gen_op_stwcx[] = {
2502 &gen_op_stwcx_le_raw,
2505 static GenOpFunc *gen_op_lwarx[] = {
2507 &gen_op_lwarx_le_user,
2508 &gen_op_lwarx_kernel,
2509 &gen_op_lwarx_le_kernel,
2511 static GenOpFunc *gen_op_stwcx[] = {
2513 &gen_op_stwcx_le_user,
2514 &gen_op_stwcx_kernel,
2515 &gen_op_stwcx_le_kernel,
2521 GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000001, PPC_RES)
2523 gen_addr_reg_index(ctx);
2525 gen_op_store_T1_gpr(rD(ctx->opcode));
2529 GEN_HANDLER(stwcx_, 0x1F, 0x16, 0x04, 0x00000000, PPC_RES)
2531 gen_addr_reg_index(ctx);
2532 gen_op_load_gpr_T1(rS(ctx->opcode));
2536 #if defined(TARGET_PPC64)
2537 #define op_ldarx() (*gen_op_ldarx[ctx->mem_idx])()
2538 #define op_stdcx() (*gen_op_stdcx[ctx->mem_idx])()
2539 #if defined(CONFIG_USER_ONLY)
2540 static GenOpFunc *gen_op_ldarx[] = {
2542 &gen_op_ldarx_le_raw,
2543 &gen_op_ldarx_64_raw,
2544 &gen_op_ldarx_le_64_raw,
2546 static GenOpFunc *gen_op_stdcx[] = {
2548 &gen_op_stdcx_le_raw,
2549 &gen_op_stdcx_64_raw,
2550 &gen_op_stdcx_le_64_raw,
2553 static GenOpFunc *gen_op_ldarx[] = {
2555 &gen_op_ldarx_le_user,
2556 &gen_op_ldarx_kernel,
2557 &gen_op_ldarx_le_kernel,
2558 &gen_op_ldarx_64_user,
2559 &gen_op_ldarx_le_64_user,
2560 &gen_op_ldarx_64_kernel,
2561 &gen_op_ldarx_le_64_kernel,
2563 static GenOpFunc *gen_op_stdcx[] = {
2565 &gen_op_stdcx_le_user,
2566 &gen_op_stdcx_kernel,
2567 &gen_op_stdcx_le_kernel,
2568 &gen_op_stdcx_64_user,
2569 &gen_op_stdcx_le_64_user,
2570 &gen_op_stdcx_64_kernel,
2571 &gen_op_stdcx_le_64_kernel,
2576 GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000001, PPC_64B)
2578 gen_addr_reg_index(ctx);
2580 gen_op_store_T1_gpr(rD(ctx->opcode));
2584 GEN_HANDLER(stdcx_, 0x1F, 0x16, 0x06, 0x00000000, PPC_64B)
2586 gen_addr_reg_index(ctx);
2587 gen_op_load_gpr_T1(rS(ctx->opcode));
2590 #endif /* defined(TARGET_PPC64) */
2593 GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x03CF0801, PPC_MEM_SYNC)
2597 /*** Floating-point load ***/
2598 #define GEN_LDF(width, opc, type) \
2599 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2601 if (unlikely(!ctx->fpu_enabled)) { \
2602 GEN_EXCP_NO_FP(ctx); \
2605 gen_addr_imm_index(ctx, 0); \
2606 op_ldst(l##width); \
2607 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
2610 #define GEN_LDUF(width, opc, type) \
2611 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2613 if (unlikely(!ctx->fpu_enabled)) { \
2614 GEN_EXCP_NO_FP(ctx); \
2617 if (unlikely(rA(ctx->opcode) == 0)) { \
2618 GEN_EXCP_INVAL(ctx); \
2621 gen_addr_imm_index(ctx, 0); \
2622 op_ldst(l##width); \
2623 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
2624 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2627 #define GEN_LDUXF(width, opc, type) \
2628 GEN_HANDLER(l##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \
2630 if (unlikely(!ctx->fpu_enabled)) { \
2631 GEN_EXCP_NO_FP(ctx); \
2634 if (unlikely(rA(ctx->opcode) == 0)) { \
2635 GEN_EXCP_INVAL(ctx); \
2638 gen_addr_reg_index(ctx); \
2639 op_ldst(l##width); \
2640 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
2641 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2644 #define GEN_LDXF(width, opc2, opc3, type) \
2645 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2647 if (unlikely(!ctx->fpu_enabled)) { \
2648 GEN_EXCP_NO_FP(ctx); \
2651 gen_addr_reg_index(ctx); \
2652 op_ldst(l##width); \
2653 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
2656 #define GEN_LDFS(width, op, type) \
2657 OP_LD_TABLE(width); \
2658 GEN_LDF(width, op | 0x20, type); \
2659 GEN_LDUF(width, op | 0x21, type); \
2660 GEN_LDUXF(width, op | 0x01, type); \
2661 GEN_LDXF(width, 0x17, op | 0x00, type)
2663 /* lfd lfdu lfdux lfdx */
2664 GEN_LDFS(fd, 0x12, PPC_FLOAT);
2665 /* lfs lfsu lfsux lfsx */
2666 GEN_LDFS(fs, 0x10, PPC_FLOAT);
2668 /*** Floating-point store ***/
2669 #define GEN_STF(width, opc, type) \
2670 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2672 if (unlikely(!ctx->fpu_enabled)) { \
2673 GEN_EXCP_NO_FP(ctx); \
2676 gen_addr_imm_index(ctx, 0); \
2677 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
2678 op_ldst(st##width); \
2681 #define GEN_STUF(width, opc, type) \
2682 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2684 if (unlikely(!ctx->fpu_enabled)) { \
2685 GEN_EXCP_NO_FP(ctx); \
2688 if (unlikely(rA(ctx->opcode) == 0)) { \
2689 GEN_EXCP_INVAL(ctx); \
2692 gen_addr_imm_index(ctx, 0); \
2693 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
2694 op_ldst(st##width); \
2695 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2698 #define GEN_STUXF(width, opc, type) \
2699 GEN_HANDLER(st##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \
2701 if (unlikely(!ctx->fpu_enabled)) { \
2702 GEN_EXCP_NO_FP(ctx); \
2705 if (unlikely(rA(ctx->opcode) == 0)) { \
2706 GEN_EXCP_INVAL(ctx); \
2709 gen_addr_reg_index(ctx); \
2710 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
2711 op_ldst(st##width); \
2712 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2715 #define GEN_STXF(width, opc2, opc3, type) \
2716 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2718 if (unlikely(!ctx->fpu_enabled)) { \
2719 GEN_EXCP_NO_FP(ctx); \
2722 gen_addr_reg_index(ctx); \
2723 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
2724 op_ldst(st##width); \
2727 #define GEN_STFS(width, op, type) \
2728 OP_ST_TABLE(width); \
2729 GEN_STF(width, op | 0x20, type); \
2730 GEN_STUF(width, op | 0x21, type); \
2731 GEN_STUXF(width, op | 0x01, type); \
2732 GEN_STXF(width, 0x17, op | 0x00, type)
2734 /* stfd stfdu stfdux stfdx */
2735 GEN_STFS(fd, 0x16, PPC_FLOAT);
2736 /* stfs stfsu stfsux stfsx */
2737 GEN_STFS(fs, 0x14, PPC_FLOAT);
2742 GEN_STXF(fiwx, 0x17, 0x1E, PPC_FLOAT_STFIWX);
2745 static inline void gen_goto_tb (DisasContext *ctx, int n, target_ulong dest)
2747 TranslationBlock *tb;
2749 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
2751 gen_op_goto_tb0(TBPARAM(tb));
2753 gen_op_goto_tb1(TBPARAM(tb));
2755 #if defined(TARGET_PPC64)
2761 gen_op_set_T0((long)tb + n);
2762 if (ctx->singlestep_enabled)
2767 #if defined(TARGET_PPC64)
2774 if (ctx->singlestep_enabled)
2780 static inline void gen_setlr (DisasContext *ctx, target_ulong nip)
2782 #if defined(TARGET_PPC64)
2783 if (ctx->sf_mode != 0 && (nip >> 32))
2784 gen_op_setlr_64(ctx->nip >> 32, ctx->nip);
2787 gen_op_setlr(ctx->nip);
2791 GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
2793 target_ulong li, target;
2795 /* sign extend LI */
2796 #if defined(TARGET_PPC64)
2798 li = ((int64_t)LI(ctx->opcode) << 38) >> 38;
2801 li = ((int32_t)LI(ctx->opcode) << 6) >> 6;
2802 if (likely(AA(ctx->opcode) == 0))
2803 target = ctx->nip + li - 4;
2806 #if defined(TARGET_PPC64)
2808 target = (uint32_t)target;
2810 if (LK(ctx->opcode))
2811 gen_setlr(ctx, ctx->nip);
2812 gen_goto_tb(ctx, 0, target);
2813 ctx->exception = POWERPC_EXCP_BRANCH;
2820 static inline void gen_bcond (DisasContext *ctx, int type)
2822 target_ulong target = 0;
2824 uint32_t bo = BO(ctx->opcode);
2825 uint32_t bi = BI(ctx->opcode);
2828 if ((bo & 0x4) == 0)
2832 li = (target_long)((int16_t)(BD(ctx->opcode)));
2833 if (likely(AA(ctx->opcode) == 0)) {
2834 target = ctx->nip + li - 4;
2838 #if defined(TARGET_PPC64)
2840 target = (uint32_t)target;
2844 gen_op_movl_T1_ctr();
2848 gen_op_movl_T1_lr();
2851 if (LK(ctx->opcode))
2852 gen_setlr(ctx, ctx->nip);
2854 /* No CR condition */
2857 #if defined(TARGET_PPC64)
2859 gen_op_test_ctr_64();
2865 #if defined(TARGET_PPC64)
2867 gen_op_test_ctrz_64();
2875 if (type == BCOND_IM) {
2876 gen_goto_tb(ctx, 0, target);
2878 #if defined(TARGET_PPC64)
2889 mask = 1 << (3 - (bi & 0x03));
2890 gen_op_load_crf_T0(bi >> 2);
2894 #if defined(TARGET_PPC64)
2896 gen_op_test_ctr_true_64(mask);
2899 gen_op_test_ctr_true(mask);
2902 #if defined(TARGET_PPC64)
2904 gen_op_test_ctrz_true_64(mask);
2907 gen_op_test_ctrz_true(mask);
2912 gen_op_test_true(mask);
2918 #if defined(TARGET_PPC64)
2920 gen_op_test_ctr_false_64(mask);
2923 gen_op_test_ctr_false(mask);
2926 #if defined(TARGET_PPC64)
2928 gen_op_test_ctrz_false_64(mask);
2931 gen_op_test_ctrz_false(mask);
2936 gen_op_test_false(mask);
2941 if (type == BCOND_IM) {
2942 int l1 = gen_new_label();
2944 gen_goto_tb(ctx, 0, target);
2946 gen_goto_tb(ctx, 1, ctx->nip);
2948 #if defined(TARGET_PPC64)
2950 gen_op_btest_T1_64(ctx->nip >> 32, ctx->nip);
2953 gen_op_btest_T1(ctx->nip);
2956 if (ctx->singlestep_enabled)
2960 ctx->exception = POWERPC_EXCP_BRANCH;
2963 GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
2965 gen_bcond(ctx, BCOND_IM);
2968 GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW)
2970 gen_bcond(ctx, BCOND_CTR);
2973 GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW)
2975 gen_bcond(ctx, BCOND_LR);
2978 /*** Condition register logical ***/
2979 #define GEN_CRLOGIC(op, opc) \
2980 GEN_HANDLER(cr##op, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) \
2982 gen_op_load_crf_T0(crbA(ctx->opcode) >> 2); \
2983 gen_op_getbit_T0(3 - (crbA(ctx->opcode) & 0x03)); \
2984 gen_op_load_crf_T1(crbB(ctx->opcode) >> 2); \
2985 gen_op_getbit_T1(3 - (crbB(ctx->opcode) & 0x03)); \
2987 gen_op_load_crf_T1(crbD(ctx->opcode) >> 2); \
2988 gen_op_setcrfbit(~(1 << (3 - (crbD(ctx->opcode) & 0x03))), \
2989 3 - (crbD(ctx->opcode) & 0x03)); \
2990 gen_op_store_T1_crf(crbD(ctx->opcode) >> 2); \
2994 GEN_CRLOGIC(and, 0x08);
2996 GEN_CRLOGIC(andc, 0x04);
2998 GEN_CRLOGIC(eqv, 0x09);
3000 GEN_CRLOGIC(nand, 0x07);
3002 GEN_CRLOGIC(nor, 0x01);
3004 GEN_CRLOGIC(or, 0x0E);
3006 GEN_CRLOGIC(orc, 0x0D);
3008 GEN_CRLOGIC(xor, 0x06);
3010 GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER)
3012 gen_op_load_crf_T0(crfS(ctx->opcode));
3013 gen_op_store_T0_crf(crfD(ctx->opcode));
3016 /*** System linkage ***/
3017 /* rfi (supervisor only) */
3018 GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW)
3020 #if defined(CONFIG_USER_ONLY)
3021 GEN_EXCP_PRIVOPC(ctx);
3023 /* Restore CPU state */
3024 if (unlikely(!ctx->supervisor)) {
3025 GEN_EXCP_PRIVOPC(ctx);
3033 #if defined(TARGET_PPC64)
3034 GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B)
3036 #if defined(CONFIG_USER_ONLY)
3037 GEN_EXCP_PRIVOPC(ctx);
3039 /* Restore CPU state */
3040 if (unlikely(!ctx->supervisor)) {
3041 GEN_EXCP_PRIVOPC(ctx);
3051 GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW)
3055 lev = (ctx->opcode >> 5) & 0x7F;
3056 #if defined(CONFIG_USER_ONLY)
3057 GEN_EXCP(ctx, POWERPC_EXCP_SYSCALL_USER, lev);
3059 GEN_EXCP(ctx, POWERPC_EXCP_SYSCALL, lev);
3065 GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW)
3067 gen_op_load_gpr_T0(rA(ctx->opcode));
3068 gen_op_load_gpr_T1(rB(ctx->opcode));
3069 /* Update the nip since this might generate a trap exception */
3070 gen_update_nip(ctx, ctx->nip);
3071 gen_op_tw(TO(ctx->opcode));
3075 GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
3077 gen_op_load_gpr_T0(rA(ctx->opcode));
3078 gen_set_T1(SIMM(ctx->opcode));
3079 /* Update the nip since this might generate a trap exception */
3080 gen_update_nip(ctx, ctx->nip);
3081 gen_op_tw(TO(ctx->opcode));
3084 #if defined(TARGET_PPC64)
3086 GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B)
3088 gen_op_load_gpr_T0(rA(ctx->opcode));
3089 gen_op_load_gpr_T1(rB(ctx->opcode));
3090 /* Update the nip since this might generate a trap exception */
3091 gen_update_nip(ctx, ctx->nip);
3092 gen_op_td(TO(ctx->opcode));
3096 GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B)
3098 gen_op_load_gpr_T0(rA(ctx->opcode));
3099 gen_set_T1(SIMM(ctx->opcode));
3100 /* Update the nip since this might generate a trap exception */
3101 gen_update_nip(ctx, ctx->nip);
3102 gen_op_td(TO(ctx->opcode));
3106 /*** Processor control ***/
3108 GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC)
3110 gen_op_load_xer_cr();
3111 gen_op_store_T0_crf(crfD(ctx->opcode));
3112 gen_op_clear_xer_ov();
3113 gen_op_clear_xer_ca();
3117 GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC)
3121 if (likely(ctx->opcode & 0x00100000)) {
3122 crm = CRM(ctx->opcode);
3123 if (likely((crm ^ (crm - 1)) == 0)) {
3125 gen_op_load_cro(7 - crn);
3130 gen_op_store_T0_gpr(rD(ctx->opcode));
3134 GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC)
3136 #if defined(CONFIG_USER_ONLY)
3137 GEN_EXCP_PRIVREG(ctx);
3139 if (unlikely(!ctx->supervisor)) {
3140 GEN_EXCP_PRIVREG(ctx);
3144 gen_op_store_T0_gpr(rD(ctx->opcode));
3149 #define SPR_NOACCESS ((void *)(-1))
3151 static void spr_noaccess (void *opaque, int sprn)
3153 sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
3154 printf("ERROR: try to access SPR %d !\n", sprn);
3156 #define SPR_NOACCESS (&spr_noaccess)
3160 static inline void gen_op_mfspr (DisasContext *ctx)
3162 void (*read_cb)(void *opaque, int sprn);
3163 uint32_t sprn = SPR(ctx->opcode);
3165 #if !defined(CONFIG_USER_ONLY)
3166 if (ctx->supervisor)
3167 read_cb = ctx->spr_cb[sprn].oea_read;
3170 read_cb = ctx->spr_cb[sprn].uea_read;
3171 if (likely(read_cb != NULL)) {
3172 if (likely(read_cb != SPR_NOACCESS)) {
3173 (*read_cb)(ctx, sprn);
3174 gen_op_store_T0_gpr(rD(ctx->opcode));
3176 /* Privilege exception */
3177 if (loglevel != 0) {
3178 fprintf(logfile, "Trying to read privileged spr %d %03x\n",
3181 printf("Trying to read privileged spr %d %03x\n", sprn, sprn);
3182 GEN_EXCP_PRIVREG(ctx);
3186 if (loglevel != 0) {
3187 fprintf(logfile, "Trying to read invalid spr %d %03x\n",
3190 printf("Trying to read invalid spr %d %03x\n", sprn, sprn);
3191 GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM,
3192 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_SPR);
3196 GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC)
3202 GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB)
3208 GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC)
3212 gen_op_load_gpr_T0(rS(ctx->opcode));
3213 crm = CRM(ctx->opcode);
3214 if (likely((ctx->opcode & 0x00100000) || (crm ^ (crm - 1)) == 0)) {
3216 gen_op_srli_T0(crn * 4);
3217 gen_op_andi_T0(0xF);
3218 gen_op_store_cro(7 - crn);
3220 gen_op_store_cr(crm);
3225 #if defined(TARGET_PPC64)
3226 GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001FF801, PPC_64B)
3228 #if defined(CONFIG_USER_ONLY)
3229 GEN_EXCP_PRIVREG(ctx);
3231 if (unlikely(!ctx->supervisor)) {
3232 GEN_EXCP_PRIVREG(ctx);
3235 gen_update_nip(ctx, ctx->nip);
3236 gen_op_load_gpr_T0(rS(ctx->opcode));
3238 /* Must stop the translation as machine state (may have) changed */
3239 /* Note that mtmsr is not always defined as context-synchronizing */
3245 GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC)
3247 #if defined(CONFIG_USER_ONLY)
3248 GEN_EXCP_PRIVREG(ctx);
3250 if (unlikely(!ctx->supervisor)) {
3251 GEN_EXCP_PRIVREG(ctx);
3254 gen_update_nip(ctx, ctx->nip);
3255 gen_op_load_gpr_T0(rS(ctx->opcode));
3256 #if defined(TARGET_PPC64)
3258 gen_op_store_msr_32();
3262 /* Must stop the translation as machine state (may have) changed */
3263 /* Note that mtmsrd is not always defined as context-synchronizing */
3269 GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC)
3271 void (*write_cb)(void *opaque, int sprn);
3272 uint32_t sprn = SPR(ctx->opcode);
3274 #if !defined(CONFIG_USER_ONLY)
3275 if (ctx->supervisor)
3276 write_cb = ctx->spr_cb[sprn].oea_write;
3279 write_cb = ctx->spr_cb[sprn].uea_write;
3280 if (likely(write_cb != NULL)) {
3281 if (likely(write_cb != SPR_NOACCESS)) {
3282 gen_op_load_gpr_T0(rS(ctx->opcode));
3283 (*write_cb)(ctx, sprn);
3285 /* Privilege exception */
3286 if (loglevel != 0) {
3287 fprintf(logfile, "Trying to write privileged spr %d %03x\n",
3290 printf("Trying to write privileged spr %d %03x\n", sprn, sprn);
3291 GEN_EXCP_PRIVREG(ctx);
3295 if (loglevel != 0) {
3296 fprintf(logfile, "Trying to write invalid spr %d %03x\n",
3299 printf("Trying to write invalid spr %d %03x\n", sprn, sprn);
3300 GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM,
3301 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_SPR);
3305 /*** Cache management ***/
3306 /* For now, all those will be implemented as nop:
3307 * this is valid, regarding the PowerPC specs...
3308 * We just have to flush tb while invalidating instruction cache lines...
3311 GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03E00001, PPC_CACHE)
3313 gen_addr_reg_index(ctx);
3317 /* dcbi (Supervisor only) */
3318 GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE)
3320 #if defined(CONFIG_USER_ONLY)
3321 GEN_EXCP_PRIVOPC(ctx);
3323 if (unlikely(!ctx->supervisor)) {
3324 GEN_EXCP_PRIVOPC(ctx);
3327 gen_addr_reg_index(ctx);
3328 /* XXX: specification says this should be treated as a store by the MMU */
3335 GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE)
3337 /* XXX: specification say this is treated as a load by the MMU */
3338 gen_addr_reg_index(ctx);
3343 GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x03E00001, PPC_CACHE)
3345 /* XXX: specification say this is treated as a load by the MMU
3346 * but does not generate any exception
3351 GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x03E00001, PPC_CACHE)
3353 /* XXX: specification say this is treated as a load by the MMU
3354 * but does not generate any exception
3359 #define op_dcbz() (*gen_op_dcbz[ctx->mem_idx])()
3360 #if defined(TARGET_PPC64)
3361 #if defined(CONFIG_USER_ONLY)
3362 static GenOpFunc *gen_op_dcbz[] = {
3365 &gen_op_dcbz_64_raw,
3366 &gen_op_dcbz_64_raw,
3369 static GenOpFunc *gen_op_dcbz[] = {
3372 &gen_op_dcbz_kernel,
3373 &gen_op_dcbz_kernel,
3374 &gen_op_dcbz_64_user,
3375 &gen_op_dcbz_64_user,
3376 &gen_op_dcbz_64_kernel,
3377 &gen_op_dcbz_64_kernel,
3381 #if defined(CONFIG_USER_ONLY)
3382 static GenOpFunc *gen_op_dcbz[] = {
3387 static GenOpFunc *gen_op_dcbz[] = {
3390 &gen_op_dcbz_kernel,
3391 &gen_op_dcbz_kernel,
3396 GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE)
3398 gen_addr_reg_index(ctx);
3400 gen_op_check_reservation();
3404 #define op_icbi() (*gen_op_icbi[ctx->mem_idx])()
3405 #if defined(TARGET_PPC64)
3406 #if defined(CONFIG_USER_ONLY)
3407 static GenOpFunc *gen_op_icbi[] = {
3410 &gen_op_icbi_64_raw,
3411 &gen_op_icbi_64_raw,
3414 static GenOpFunc *gen_op_icbi[] = {
3417 &gen_op_icbi_kernel,
3418 &gen_op_icbi_kernel,
3419 &gen_op_icbi_64_user,
3420 &gen_op_icbi_64_user,
3421 &gen_op_icbi_64_kernel,
3422 &gen_op_icbi_64_kernel,
3426 #if defined(CONFIG_USER_ONLY)
3427 static GenOpFunc *gen_op_icbi[] = {
3432 static GenOpFunc *gen_op_icbi[] = {
3435 &gen_op_icbi_kernel,
3436 &gen_op_icbi_kernel,
3441 GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE)
3443 gen_addr_reg_index(ctx);
3449 GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA)
3453 /*** Segment register manipulation ***/
3454 /* Supervisor only: */
3456 GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT)
3458 #if defined(CONFIG_USER_ONLY)
3459 GEN_EXCP_PRIVREG(ctx);
3461 if (unlikely(!ctx->supervisor)) {
3462 GEN_EXCP_PRIVREG(ctx);
3465 gen_op_set_T1(SR(ctx->opcode));
3467 gen_op_store_T0_gpr(rD(ctx->opcode));
3472 GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT)
3474 #if defined(CONFIG_USER_ONLY)
3475 GEN_EXCP_PRIVREG(ctx);
3477 if (unlikely(!ctx->supervisor)) {
3478 GEN_EXCP_PRIVREG(ctx);
3481 gen_op_load_gpr_T1(rB(ctx->opcode));
3484 gen_op_store_T0_gpr(rD(ctx->opcode));
3489 GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT)
3491 #if defined(CONFIG_USER_ONLY)
3492 GEN_EXCP_PRIVREG(ctx);
3494 if (unlikely(!ctx->supervisor)) {
3495 GEN_EXCP_PRIVREG(ctx);
3498 gen_op_load_gpr_T0(rS(ctx->opcode));
3499 gen_op_set_T1(SR(ctx->opcode));
3505 GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT)
3507 #if defined(CONFIG_USER_ONLY)
3508 GEN_EXCP_PRIVREG(ctx);
3510 if (unlikely(!ctx->supervisor)) {
3511 GEN_EXCP_PRIVREG(ctx);
3514 gen_op_load_gpr_T0(rS(ctx->opcode));
3515 gen_op_load_gpr_T1(rB(ctx->opcode));
3521 /*** Lookaside buffer management ***/
3522 /* Optional & supervisor only: */
3524 GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA)
3526 #if defined(CONFIG_USER_ONLY)
3527 GEN_EXCP_PRIVOPC(ctx);
3529 if (unlikely(!ctx->supervisor)) {
3531 fprintf(logfile, "%s: ! supervisor\n", __func__);
3532 GEN_EXCP_PRIVOPC(ctx);
3540 GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE)
3542 #if defined(CONFIG_USER_ONLY)
3543 GEN_EXCP_PRIVOPC(ctx);
3545 if (unlikely(!ctx->supervisor)) {
3546 GEN_EXCP_PRIVOPC(ctx);
3549 gen_op_load_gpr_T0(rB(ctx->opcode));
3550 #if defined(TARGET_PPC64)
3560 GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC)
3562 #if defined(CONFIG_USER_ONLY)
3563 GEN_EXCP_PRIVOPC(ctx);
3565 if (unlikely(!ctx->supervisor)) {
3566 GEN_EXCP_PRIVOPC(ctx);
3569 /* This has no effect: it should ensure that all previous
3570 * tlbie have completed
3576 #if defined(TARGET_PPC64)
3578 GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI)
3580 #if defined(CONFIG_USER_ONLY)
3581 GEN_EXCP_PRIVOPC(ctx);
3583 if (unlikely(!ctx->supervisor)) {
3585 fprintf(logfile, "%s: ! supervisor\n", __func__);
3586 GEN_EXCP_PRIVOPC(ctx);
3594 GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI)
3596 #if defined(CONFIG_USER_ONLY)
3597 GEN_EXCP_PRIVOPC(ctx);
3599 if (unlikely(!ctx->supervisor)) {
3600 GEN_EXCP_PRIVOPC(ctx);
3603 gen_op_load_gpr_T0(rB(ctx->opcode));
3609 /*** External control ***/
3611 #define op_eciwx() (*gen_op_eciwx[ctx->mem_idx])()
3612 #define op_ecowx() (*gen_op_ecowx[ctx->mem_idx])()
3613 #if defined(TARGET_PPC64)
3614 #if defined(CONFIG_USER_ONLY)
3615 static GenOpFunc *gen_op_eciwx[] = {
3617 &gen_op_eciwx_le_raw,
3618 &gen_op_eciwx_64_raw,
3619 &gen_op_eciwx_le_64_raw,
3621 static GenOpFunc *gen_op_ecowx[] = {
3623 &gen_op_ecowx_le_raw,
3624 &gen_op_ecowx_64_raw,
3625 &gen_op_ecowx_le_64_raw,
3628 static GenOpFunc *gen_op_eciwx[] = {
3630 &gen_op_eciwx_le_user,
3631 &gen_op_eciwx_kernel,
3632 &gen_op_eciwx_le_kernel,
3633 &gen_op_eciwx_64_user,
3634 &gen_op_eciwx_le_64_user,
3635 &gen_op_eciwx_64_kernel,
3636 &gen_op_eciwx_le_64_kernel,
3638 static GenOpFunc *gen_op_ecowx[] = {
3640 &gen_op_ecowx_le_user,
3641 &gen_op_ecowx_kernel,
3642 &gen_op_ecowx_le_kernel,
3643 &gen_op_ecowx_64_user,
3644 &gen_op_ecowx_le_64_user,
3645 &gen_op_ecowx_64_kernel,
3646 &gen_op_ecowx_le_64_kernel,
3650 #if defined(CONFIG_USER_ONLY)
3651 static GenOpFunc *gen_op_eciwx[] = {
3653 &gen_op_eciwx_le_raw,
3655 static GenOpFunc *gen_op_ecowx[] = {
3657 &gen_op_ecowx_le_raw,
3660 static GenOpFunc *gen_op_eciwx[] = {
3662 &gen_op_eciwx_le_user,
3663 &gen_op_eciwx_kernel,
3664 &gen_op_eciwx_le_kernel,
3666 static GenOpFunc *gen_op_ecowx[] = {
3668 &gen_op_ecowx_le_user,
3669 &gen_op_ecowx_kernel,
3670 &gen_op_ecowx_le_kernel,
3676 GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN)
3678 /* Should check EAR[E] & alignment ! */
3679 gen_addr_reg_index(ctx);
3681 gen_op_store_T0_gpr(rD(ctx->opcode));
3685 GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN)
3687 /* Should check EAR[E] & alignment ! */
3688 gen_addr_reg_index(ctx);
3689 gen_op_load_gpr_T1(rS(ctx->opcode));
3693 /* PowerPC 601 specific instructions */
3695 GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR)
3697 gen_op_load_gpr_T0(rA(ctx->opcode));
3699 gen_op_store_T0_gpr(rD(ctx->opcode));
3700 if (unlikely(Rc(ctx->opcode) != 0))
3705 GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR)
3707 gen_op_load_gpr_T0(rA(ctx->opcode));
3708 gen_op_POWER_abso();
3709 gen_op_store_T0_gpr(rD(ctx->opcode));
3710 if (unlikely(Rc(ctx->opcode) != 0))
3715 GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR)
3717 gen_op_load_gpr_T0(rA(ctx->opcode));
3718 gen_op_POWER_clcs();
3719 gen_op_store_T0_gpr(rD(ctx->opcode));
3723 GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR)
3725 gen_op_load_gpr_T0(rA(ctx->opcode));
3726 gen_op_load_gpr_T1(rB(ctx->opcode));
3728 gen_op_store_T0_gpr(rD(ctx->opcode));
3729 if (unlikely(Rc(ctx->opcode) != 0))
3734 GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR)
3736 gen_op_load_gpr_T0(rA(ctx->opcode));
3737 gen_op_load_gpr_T1(rB(ctx->opcode));
3738 gen_op_POWER_divo();
3739 gen_op_store_T0_gpr(rD(ctx->opcode));
3740 if (unlikely(Rc(ctx->opcode) != 0))
3745 GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR)
3747 gen_op_load_gpr_T0(rA(ctx->opcode));
3748 gen_op_load_gpr_T1(rB(ctx->opcode));
3749 gen_op_POWER_divs();
3750 gen_op_store_T0_gpr(rD(ctx->opcode));
3751 if (unlikely(Rc(ctx->opcode) != 0))
3755 /* divso - divso. */
3756 GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR)
3758 gen_op_load_gpr_T0(rA(ctx->opcode));
3759 gen_op_load_gpr_T1(rB(ctx->opcode));
3760 gen_op_POWER_divso();
3761 gen_op_store_T0_gpr(rD(ctx->opcode));
3762 if (unlikely(Rc(ctx->opcode) != 0))
3767 GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR)
3769 gen_op_load_gpr_T0(rA(ctx->opcode));
3770 gen_op_load_gpr_T1(rB(ctx->opcode));
3772 gen_op_store_T0_gpr(rD(ctx->opcode));
3773 if (unlikely(Rc(ctx->opcode) != 0))
3778 GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR)
3780 gen_op_load_gpr_T0(rA(ctx->opcode));
3781 gen_op_load_gpr_T1(rB(ctx->opcode));
3782 gen_op_POWER_dozo();
3783 gen_op_store_T0_gpr(rD(ctx->opcode));
3784 if (unlikely(Rc(ctx->opcode) != 0))
3789 GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR)
3791 gen_op_load_gpr_T0(rA(ctx->opcode));
3792 gen_op_set_T1(SIMM(ctx->opcode));
3794 gen_op_store_T0_gpr(rD(ctx->opcode));
3797 /* As lscbx load from memory byte after byte, it's always endian safe */
3798 #define op_POWER_lscbx(start, ra, rb) \
3799 (*gen_op_POWER_lscbx[ctx->mem_idx])(start, ra, rb)
3800 #if defined(CONFIG_USER_ONLY)
3801 static GenOpFunc3 *gen_op_POWER_lscbx[] = {
3802 &gen_op_POWER_lscbx_raw,
3803 &gen_op_POWER_lscbx_raw,
3806 static GenOpFunc3 *gen_op_POWER_lscbx[] = {
3807 &gen_op_POWER_lscbx_user,
3808 &gen_op_POWER_lscbx_user,
3809 &gen_op_POWER_lscbx_kernel,
3810 &gen_op_POWER_lscbx_kernel,
3814 /* lscbx - lscbx. */
3815 GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR)
3817 int ra = rA(ctx->opcode);
3818 int rb = rB(ctx->opcode);
3820 gen_addr_reg_index(ctx);
3824 /* NIP cannot be restored if the memory exception comes from an helper */
3825 gen_update_nip(ctx, ctx->nip - 4);
3826 gen_op_load_xer_bc();
3827 gen_op_load_xer_cmp();
3828 op_POWER_lscbx(rD(ctx->opcode), ra, rb);
3829 gen_op_store_xer_bc();
3830 if (unlikely(Rc(ctx->opcode) != 0))
3834 /* maskg - maskg. */
3835 GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR)
3837 gen_op_load_gpr_T0(rS(ctx->opcode));
3838 gen_op_load_gpr_T1(rB(ctx->opcode));
3839 gen_op_POWER_maskg();
3840 gen_op_store_T0_gpr(rA(ctx->opcode));
3841 if (unlikely(Rc(ctx->opcode) != 0))
3845 /* maskir - maskir. */
3846 GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR)
3848 gen_op_load_gpr_T0(rA(ctx->opcode));
3849 gen_op_load_gpr_T1(rS(ctx->opcode));
3850 gen_op_load_gpr_T2(rB(ctx->opcode));
3851 gen_op_POWER_maskir();
3852 gen_op_store_T0_gpr(rA(ctx->opcode));
3853 if (unlikely(Rc(ctx->opcode) != 0))
3858 GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR)
3860 gen_op_load_gpr_T0(rA(ctx->opcode));
3861 gen_op_load_gpr_T1(rB(ctx->opcode));
3863 gen_op_store_T0_gpr(rD(ctx->opcode));
3864 if (unlikely(Rc(ctx->opcode) != 0))
3869 GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR)
3871 gen_op_load_gpr_T0(rA(ctx->opcode));
3872 gen_op_load_gpr_T1(rB(ctx->opcode));
3873 gen_op_POWER_mulo();
3874 gen_op_store_T0_gpr(rD(ctx->opcode));
3875 if (unlikely(Rc(ctx->opcode) != 0))
3880 GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR)
3882 gen_op_load_gpr_T0(rA(ctx->opcode));
3883 gen_op_POWER_nabs();
3884 gen_op_store_T0_gpr(rD(ctx->opcode));
3885 if (unlikely(Rc(ctx->opcode) != 0))
3889 /* nabso - nabso. */
3890 GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR)
3892 gen_op_load_gpr_T0(rA(ctx->opcode));
3893 gen_op_POWER_nabso();
3894 gen_op_store_T0_gpr(rD(ctx->opcode));
3895 if (unlikely(Rc(ctx->opcode) != 0))
3900 GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR)
3904 mb = MB(ctx->opcode);
3905 me = ME(ctx->opcode);
3906 gen_op_load_gpr_T0(rS(ctx->opcode));
3907 gen_op_load_gpr_T1(rA(ctx->opcode));
3908 gen_op_load_gpr_T2(rB(ctx->opcode));
3909 gen_op_POWER_rlmi(MASK(mb, me), ~MASK(mb, me));
3910 gen_op_store_T0_gpr(rA(ctx->opcode));
3911 if (unlikely(Rc(ctx->opcode) != 0))
3916 GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR)
3918 gen_op_load_gpr_T0(rS(ctx->opcode));
3919 gen_op_load_gpr_T1(rA(ctx->opcode));
3920 gen_op_load_gpr_T2(rB(ctx->opcode));
3921 gen_op_POWER_rrib();
3922 gen_op_store_T0_gpr(rA(ctx->opcode));
3923 if (unlikely(Rc(ctx->opcode) != 0))
3928 GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR)
3930 gen_op_load_gpr_T0(rS(ctx->opcode));
3931 gen_op_load_gpr_T1(rB(ctx->opcode));
3933 gen_op_store_T0_gpr(rA(ctx->opcode));
3934 if (unlikely(Rc(ctx->opcode) != 0))
3939 GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR)
3941 gen_op_load_gpr_T0(rS(ctx->opcode));
3942 gen_op_load_gpr_T1(rB(ctx->opcode));
3943 gen_op_POWER_sleq();
3944 gen_op_store_T0_gpr(rA(ctx->opcode));
3945 if (unlikely(Rc(ctx->opcode) != 0))
3950 GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR)
3952 gen_op_load_gpr_T0(rS(ctx->opcode));
3953 gen_op_set_T1(SH(ctx->opcode));
3955 gen_op_store_T0_gpr(rA(ctx->opcode));
3956 if (unlikely(Rc(ctx->opcode) != 0))
3960 /* slliq - slliq. */
3961 GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR)
3963 gen_op_load_gpr_T0(rS(ctx->opcode));
3964 gen_op_set_T1(SH(ctx->opcode));
3965 gen_op_POWER_sleq();
3966 gen_op_store_T0_gpr(rA(ctx->opcode));
3967 if (unlikely(Rc(ctx->opcode) != 0))
3972 GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR)
3974 gen_op_load_gpr_T0(rS(ctx->opcode));
3975 gen_op_load_gpr_T1(rB(ctx->opcode));
3976 gen_op_POWER_sllq();
3977 gen_op_store_T0_gpr(rA(ctx->opcode));
3978 if (unlikely(Rc(ctx->opcode) != 0))
3983 GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR)
3985 gen_op_load_gpr_T0(rS(ctx->opcode));
3986 gen_op_load_gpr_T1(rB(ctx->opcode));
3988 gen_op_store_T0_gpr(rA(ctx->opcode));
3989 if (unlikely(Rc(ctx->opcode) != 0))
3993 /* sraiq - sraiq. */
3994 GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR)
3996 gen_op_load_gpr_T0(rS(ctx->opcode));
3997 gen_op_set_T1(SH(ctx->opcode));
3998 gen_op_POWER_sraq();
3999 gen_op_store_T0_gpr(rA(ctx->opcode));
4000 if (unlikely(Rc(ctx->opcode) != 0))
4005 GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR)
4007 gen_op_load_gpr_T0(rS(ctx->opcode));
4008 gen_op_load_gpr_T1(rB(ctx->opcode));
4009 gen_op_POWER_sraq();
4010 gen_op_store_T0_gpr(rA(ctx->opcode));
4011 if (unlikely(Rc(ctx->opcode) != 0))
4016 GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR)
4018 gen_op_load_gpr_T0(rS(ctx->opcode));
4019 gen_op_load_gpr_T1(rB(ctx->opcode));
4021 gen_op_store_T0_gpr(rA(ctx->opcode));
4022 if (unlikely(Rc(ctx->opcode) != 0))
4027 GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR)
4029 gen_op_load_gpr_T0(rS(ctx->opcode));
4030 gen_op_load_gpr_T1(rB(ctx->opcode));
4031 gen_op_POWER_srea();
4032 gen_op_store_T0_gpr(rA(ctx->opcode));
4033 if (unlikely(Rc(ctx->opcode) != 0))
4038 GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR)
4040 gen_op_load_gpr_T0(rS(ctx->opcode));
4041 gen_op_load_gpr_T1(rB(ctx->opcode));
4042 gen_op_POWER_sreq();
4043 gen_op_store_T0_gpr(rA(ctx->opcode));
4044 if (unlikely(Rc(ctx->opcode) != 0))
4049 GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR)
4051 gen_op_load_gpr_T0(rS(ctx->opcode));
4052 gen_op_set_T1(SH(ctx->opcode));
4054 gen_op_store_T0_gpr(rA(ctx->opcode));
4055 if (unlikely(Rc(ctx->opcode) != 0))
4060 GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR)
4062 gen_op_load_gpr_T0(rS(ctx->opcode));
4063 gen_op_load_gpr_T1(rB(ctx->opcode));
4064 gen_op_set_T1(SH(ctx->opcode));
4065 gen_op_POWER_srlq();
4066 gen_op_store_T0_gpr(rA(ctx->opcode));
4067 if (unlikely(Rc(ctx->opcode) != 0))
4072 GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR)
4074 gen_op_load_gpr_T0(rS(ctx->opcode));
4075 gen_op_load_gpr_T1(rB(ctx->opcode));
4076 gen_op_POWER_srlq();
4077 gen_op_store_T0_gpr(rA(ctx->opcode));
4078 if (unlikely(Rc(ctx->opcode) != 0))
4083 GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR)
4085 gen_op_load_gpr_T0(rS(ctx->opcode));
4086 gen_op_load_gpr_T1(rB(ctx->opcode));
4088 gen_op_store_T0_gpr(rA(ctx->opcode));
4089 if (unlikely(Rc(ctx->opcode) != 0))
4093 /* PowerPC 602 specific instructions */
4095 GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC)
4098 GEN_EXCP_INVAL(ctx);
4102 GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC)
4105 GEN_EXCP_INVAL(ctx);
4109 GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC)
4111 #if defined(CONFIG_USER_ONLY)
4112 GEN_EXCP_PRIVOPC(ctx);
4114 if (unlikely(!ctx->supervisor)) {
4115 GEN_EXCP_PRIVOPC(ctx);
4118 gen_op_load_gpr_T0(rA(ctx->opcode));
4120 gen_op_store_T0_gpr(rD(ctx->opcode));
4124 /* 602 - 603 - G2 TLB management */
4126 GEN_HANDLER(tlbld, 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB)
4128 #if defined(CONFIG_USER_ONLY)
4129 GEN_EXCP_PRIVOPC(ctx);
4131 if (unlikely(!ctx->supervisor)) {
4132 GEN_EXCP_PRIVOPC(ctx);
4135 gen_op_load_gpr_T0(rB(ctx->opcode));
4141 GEN_HANDLER(tlbli, 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB)
4143 #if defined(CONFIG_USER_ONLY)
4144 GEN_EXCP_PRIVOPC(ctx);
4146 if (unlikely(!ctx->supervisor)) {
4147 GEN_EXCP_PRIVOPC(ctx);
4150 gen_op_load_gpr_T0(rB(ctx->opcode));
4155 /* POWER instructions not in PowerPC 601 */
4157 GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER)
4159 /* Cache line flush: implemented as no-op */
4163 GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER)
4165 /* Cache line invalidate: privileged and treated as no-op */
4166 #if defined(CONFIG_USER_ONLY)
4167 GEN_EXCP_PRIVOPC(ctx);
4169 if (unlikely(!ctx->supervisor)) {
4170 GEN_EXCP_PRIVOPC(ctx);
4177 GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER)
4179 /* Data cache line store: treated as no-op */
4182 GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER)
4184 #if defined(CONFIG_USER_ONLY)
4185 GEN_EXCP_PRIVOPC(ctx);
4187 if (unlikely(!ctx->supervisor)) {
4188 GEN_EXCP_PRIVOPC(ctx);
4191 int ra = rA(ctx->opcode);
4192 int rd = rD(ctx->opcode);
4194 gen_addr_reg_index(ctx);
4195 gen_op_POWER_mfsri();
4196 gen_op_store_T0_gpr(rd);
4197 if (ra != 0 && ra != rd)
4198 gen_op_store_T1_gpr(ra);
4202 GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER)
4204 #if defined(CONFIG_USER_ONLY)
4205 GEN_EXCP_PRIVOPC(ctx);
4207 if (unlikely(!ctx->supervisor)) {
4208 GEN_EXCP_PRIVOPC(ctx);
4211 gen_addr_reg_index(ctx);
4213 gen_op_store_T0_gpr(rD(ctx->opcode));
4217 GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER)
4219 #if defined(CONFIG_USER_ONLY)
4220 GEN_EXCP_PRIVOPC(ctx);
4222 if (unlikely(!ctx->supervisor)) {
4223 GEN_EXCP_PRIVOPC(ctx);
4226 gen_op_POWER_rfsvc();
4231 /* svc is not implemented for now */
4233 /* POWER2 specific instructions */
4234 /* Quad manipulation (load/store two floats at a time) */
4235 #define op_POWER2_lfq() (*gen_op_POWER2_lfq[ctx->mem_idx])()
4236 #define op_POWER2_stfq() (*gen_op_POWER2_stfq[ctx->mem_idx])()
4237 #if defined(CONFIG_USER_ONLY)
4238 static GenOpFunc *gen_op_POWER2_lfq[] = {
4239 &gen_op_POWER2_lfq_le_raw,
4240 &gen_op_POWER2_lfq_raw,
4242 static GenOpFunc *gen_op_POWER2_stfq[] = {
4243 &gen_op_POWER2_stfq_le_raw,
4244 &gen_op_POWER2_stfq_raw,
4247 static GenOpFunc *gen_op_POWER2_lfq[] = {
4248 &gen_op_POWER2_lfq_le_user,
4249 &gen_op_POWER2_lfq_user,
4250 &gen_op_POWER2_lfq_le_kernel,
4251 &gen_op_POWER2_lfq_kernel,
4253 static GenOpFunc *gen_op_POWER2_stfq[] = {
4254 &gen_op_POWER2_stfq_le_user,
4255 &gen_op_POWER2_stfq_user,
4256 &gen_op_POWER2_stfq_le_kernel,
4257 &gen_op_POWER2_stfq_kernel,
4262 GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
4264 /* NIP cannot be restored if the memory exception comes from an helper */
4265 gen_update_nip(ctx, ctx->nip - 4);
4266 gen_addr_imm_index(ctx, 0);
4268 gen_op_store_FT0_fpr(rD(ctx->opcode));
4269 gen_op_store_FT1_fpr(rD(ctx->opcode) + 1);
4273 GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
4275 int ra = rA(ctx->opcode);
4277 /* NIP cannot be restored if the memory exception comes from an helper */
4278 gen_update_nip(ctx, ctx->nip - 4);
4279 gen_addr_imm_index(ctx, 0);
4281 gen_op_store_FT0_fpr(rD(ctx->opcode));
4282 gen_op_store_FT1_fpr(rD(ctx->opcode) + 1);
4284 gen_op_store_T0_gpr(ra);
4288 GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2)
4290 int ra = rA(ctx->opcode);
4292 /* NIP cannot be restored if the memory exception comes from an helper */
4293 gen_update_nip(ctx, ctx->nip - 4);
4294 gen_addr_reg_index(ctx);
4296 gen_op_store_FT0_fpr(rD(ctx->opcode));
4297 gen_op_store_FT1_fpr(rD(ctx->opcode) + 1);
4299 gen_op_store_T0_gpr(ra);
4303 GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2)
4305 /* NIP cannot be restored if the memory exception comes from an helper */
4306 gen_update_nip(ctx, ctx->nip - 4);
4307 gen_addr_reg_index(ctx);
4309 gen_op_store_FT0_fpr(rD(ctx->opcode));
4310 gen_op_store_FT1_fpr(rD(ctx->opcode) + 1);
4314 GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
4316 /* NIP cannot be restored if the memory exception comes from an helper */
4317 gen_update_nip(ctx, ctx->nip - 4);
4318 gen_addr_imm_index(ctx, 0);
4319 gen_op_load_fpr_FT0(rS(ctx->opcode));
4320 gen_op_load_fpr_FT1(rS(ctx->opcode) + 1);
4325 GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
4327 int ra = rA(ctx->opcode);
4329 /* NIP cannot be restored if the memory exception comes from an helper */
4330 gen_update_nip(ctx, ctx->nip - 4);
4331 gen_addr_imm_index(ctx, 0);
4332 gen_op_load_fpr_FT0(rS(ctx->opcode));
4333 gen_op_load_fpr_FT1(rS(ctx->opcode) + 1);
4336 gen_op_store_T0_gpr(ra);
4340 GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2)
4342 int ra = rA(ctx->opcode);
4344 /* NIP cannot be restored if the memory exception comes from an helper */
4345 gen_update_nip(ctx, ctx->nip - 4);
4346 gen_addr_reg_index(ctx);
4347 gen_op_load_fpr_FT0(rS(ctx->opcode));
4348 gen_op_load_fpr_FT1(rS(ctx->opcode) + 1);
4351 gen_op_store_T0_gpr(ra);
4355 GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2)
4357 /* NIP cannot be restored if the memory exception comes from an helper */
4358 gen_update_nip(ctx, ctx->nip - 4);
4359 gen_addr_reg_index(ctx);
4360 gen_op_load_fpr_FT0(rS(ctx->opcode));
4361 gen_op_load_fpr_FT1(rS(ctx->opcode) + 1);
4365 /* BookE specific instructions */
4366 /* XXX: not implemented on 440 ? */
4367 GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_BOOKE_EXT)
4370 GEN_EXCP_INVAL(ctx);
4373 /* XXX: not implemented on 440 ? */
4374 GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_BOOKE_EXT)
4376 #if defined(CONFIG_USER_ONLY)
4377 GEN_EXCP_PRIVOPC(ctx);
4379 if (unlikely(!ctx->supervisor)) {
4380 GEN_EXCP_PRIVOPC(ctx);
4383 gen_addr_reg_index(ctx);
4384 /* Use the same micro-ops as for tlbie */
4385 #if defined(TARGET_PPC64)
4394 /* All 405 MAC instructions are translated here */
4395 static inline void gen_405_mulladd_insn (DisasContext *ctx, int opc2, int opc3,
4396 int ra, int rb, int rt, int Rc)
4398 gen_op_load_gpr_T0(ra);
4399 gen_op_load_gpr_T1(rb);
4400 switch (opc3 & 0x0D) {
4402 /* macchw - macchw. - macchwo - macchwo. */
4403 /* macchws - macchws. - macchwso - macchwso. */
4404 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
4405 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
4406 /* mulchw - mulchw. */
4407 gen_op_405_mulchw();
4410 /* macchwu - macchwu. - macchwuo - macchwuo. */
4411 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
4412 /* mulchwu - mulchwu. */
4413 gen_op_405_mulchwu();
4416 /* machhw - machhw. - machhwo - machhwo. */
4417 /* machhws - machhws. - machhwso - machhwso. */
4418 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
4419 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
4420 /* mulhhw - mulhhw. */
4421 gen_op_405_mulhhw();
4424 /* machhwu - machhwu. - machhwuo - machhwuo. */
4425 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
4426 /* mulhhwu - mulhhwu. */
4427 gen_op_405_mulhhwu();
4430 /* maclhw - maclhw. - maclhwo - maclhwo. */
4431 /* maclhws - maclhws. - maclhwso - maclhwso. */
4432 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
4433 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
4434 /* mullhw - mullhw. */
4435 gen_op_405_mullhw();
4438 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
4439 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
4440 /* mullhwu - mullhwu. */
4441 gen_op_405_mullhwu();
4445 /* nmultiply-and-accumulate (0x0E) */
4449 /* (n)multiply-and-accumulate (0x0C - 0x0E) */
4450 gen_op_load_gpr_T2(rt);
4451 gen_op_move_T1_T0();
4452 gen_op_405_add_T0_T2();
4455 /* Check overflow */
4457 gen_op_405_check_ov();
4459 gen_op_405_check_ovu();
4464 gen_op_405_check_sat();
4466 gen_op_405_check_satu();
4468 gen_op_store_T0_gpr(rt);
4469 if (unlikely(Rc) != 0) {
4475 #define GEN_MAC_HANDLER(name, opc2, opc3) \
4476 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC) \
4478 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
4479 rD(ctx->opcode), Rc(ctx->opcode)); \
4482 /* macchw - macchw. */
4483 GEN_MAC_HANDLER(macchw, 0x0C, 0x05);
4484 /* macchwo - macchwo. */
4485 GEN_MAC_HANDLER(macchwo, 0x0C, 0x15);
4486 /* macchws - macchws. */
4487 GEN_MAC_HANDLER(macchws, 0x0C, 0x07);
4488 /* macchwso - macchwso. */
4489 GEN_MAC_HANDLER(macchwso, 0x0C, 0x17);
4490 /* macchwsu - macchwsu. */
4491 GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06);
4492 /* macchwsuo - macchwsuo. */
4493 GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16);
4494 /* macchwu - macchwu. */
4495 GEN_MAC_HANDLER(macchwu, 0x0C, 0x04);
4496 /* macchwuo - macchwuo. */
4497 GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14);
4498 /* machhw - machhw. */
4499 GEN_MAC_HANDLER(machhw, 0x0C, 0x01);
4500 /* machhwo - machhwo. */
4501 GEN_MAC_HANDLER(machhwo, 0x0C, 0x11);
4502 /* machhws - machhws. */
4503 GEN_MAC_HANDLER(machhws, 0x0C, 0x03);
4504 /* machhwso - machhwso. */
4505 GEN_MAC_HANDLER(machhwso, 0x0C, 0x13);
4506 /* machhwsu - machhwsu. */
4507 GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02);
4508 /* machhwsuo - machhwsuo. */
4509 GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12);
4510 /* machhwu - machhwu. */
4511 GEN_MAC_HANDLER(machhwu, 0x0C, 0x00);
4512 /* machhwuo - machhwuo. */
4513 GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10);
4514 /* maclhw - maclhw. */
4515 GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D);
4516 /* maclhwo - maclhwo. */
4517 GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D);
4518 /* maclhws - maclhws. */
4519 GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F);
4520 /* maclhwso - maclhwso. */
4521 GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F);
4522 /* maclhwu - maclhwu. */
4523 GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C);
4524 /* maclhwuo - maclhwuo. */
4525 GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C);
4526 /* maclhwsu - maclhwsu. */
4527 GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E);
4528 /* maclhwsuo - maclhwsuo. */
4529 GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E);
4530 /* nmacchw - nmacchw. */
4531 GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05);
4532 /* nmacchwo - nmacchwo. */
4533 GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15);
4534 /* nmacchws - nmacchws. */
4535 GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07);
4536 /* nmacchwso - nmacchwso. */
4537 GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17);
4538 /* nmachhw - nmachhw. */
4539 GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01);
4540 /* nmachhwo - nmachhwo. */
4541 GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11);
4542 /* nmachhws - nmachhws. */
4543 GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03);
4544 /* nmachhwso - nmachhwso. */
4545 GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13);
4546 /* nmaclhw - nmaclhw. */
4547 GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D);
4548 /* nmaclhwo - nmaclhwo. */
4549 GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D);
4550 /* nmaclhws - nmaclhws. */
4551 GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F);
4552 /* nmaclhwso - nmaclhwso. */
4553 GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F);
4555 /* mulchw - mulchw. */
4556 GEN_MAC_HANDLER(mulchw, 0x08, 0x05);
4557 /* mulchwu - mulchwu. */
4558 GEN_MAC_HANDLER(mulchwu, 0x08, 0x04);
4559 /* mulhhw - mulhhw. */
4560 GEN_MAC_HANDLER(mulhhw, 0x08, 0x01);
4561 /* mulhhwu - mulhhwu. */
4562 GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00);
4563 /* mullhw - mullhw. */
4564 GEN_MAC_HANDLER(mullhw, 0x08, 0x0D);
4565 /* mullhwu - mullhwu. */
4566 GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
4569 GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_EMB_COMMON)
4571 #if defined(CONFIG_USER_ONLY)
4572 GEN_EXCP_PRIVREG(ctx);
4574 uint32_t dcrn = SPR(ctx->opcode);
4576 if (unlikely(!ctx->supervisor)) {
4577 GEN_EXCP_PRIVREG(ctx);
4580 gen_op_set_T0(dcrn);
4582 gen_op_store_T0_gpr(rD(ctx->opcode));
4587 GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_EMB_COMMON)
4589 #if defined(CONFIG_USER_ONLY)
4590 GEN_EXCP_PRIVREG(ctx);
4592 uint32_t dcrn = SPR(ctx->opcode);
4594 if (unlikely(!ctx->supervisor)) {
4595 GEN_EXCP_PRIVREG(ctx);
4598 gen_op_set_T0(dcrn);
4599 gen_op_load_gpr_T1(rS(ctx->opcode));
4605 /* XXX: not implemented on 440 ? */
4606 GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_BOOKE_EXT)
4608 #if defined(CONFIG_USER_ONLY)
4609 GEN_EXCP_PRIVREG(ctx);
4611 if (unlikely(!ctx->supervisor)) {
4612 GEN_EXCP_PRIVREG(ctx);
4615 gen_op_load_gpr_T0(rA(ctx->opcode));
4617 gen_op_store_T0_gpr(rD(ctx->opcode));
4618 /* Note: Rc update flag set leads to undefined state of Rc0 */
4623 /* XXX: not implemented on 440 ? */
4624 GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_BOOKE_EXT)
4626 #if defined(CONFIG_USER_ONLY)
4627 GEN_EXCP_PRIVREG(ctx);
4629 if (unlikely(!ctx->supervisor)) {
4630 GEN_EXCP_PRIVREG(ctx);
4633 gen_op_load_gpr_T0(rA(ctx->opcode));
4634 gen_op_load_gpr_T1(rS(ctx->opcode));
4636 /* Note: Rc update flag set leads to undefined state of Rc0 */
4640 /* mfdcrux (PPC 460) : user-mode access to DCR */
4641 GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX)
4643 gen_op_load_gpr_T0(rA(ctx->opcode));
4645 gen_op_store_T0_gpr(rD(ctx->opcode));
4646 /* Note: Rc update flag set leads to undefined state of Rc0 */
4649 /* mtdcrux (PPC 460) : user-mode access to DCR */
4650 GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX)
4652 gen_op_load_gpr_T0(rA(ctx->opcode));
4653 gen_op_load_gpr_T1(rS(ctx->opcode));
4655 /* Note: Rc update flag set leads to undefined state of Rc0 */
4659 GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON)
4661 #if defined(CONFIG_USER_ONLY)
4662 GEN_EXCP_PRIVOPC(ctx);
4664 if (unlikely(!ctx->supervisor)) {
4665 GEN_EXCP_PRIVOPC(ctx);
4668 /* interpreted as no-op */
4673 GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON)
4675 #if defined(CONFIG_USER_ONLY)
4676 GEN_EXCP_PRIVOPC(ctx);
4678 if (unlikely(!ctx->supervisor)) {
4679 GEN_EXCP_PRIVOPC(ctx);
4682 gen_addr_reg_index(ctx);
4684 gen_op_store_T0_gpr(rD(ctx->opcode));
4689 GEN_HANDLER(icbt_40x, 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT)
4691 /* interpreted as no-op */
4692 /* XXX: specification say this is treated as a load by the MMU
4693 * but does not generate any exception
4698 GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON)
4700 #if defined(CONFIG_USER_ONLY)
4701 GEN_EXCP_PRIVOPC(ctx);
4703 if (unlikely(!ctx->supervisor)) {
4704 GEN_EXCP_PRIVOPC(ctx);
4707 /* interpreted as no-op */
4712 GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON)
4714 #if defined(CONFIG_USER_ONLY)
4715 GEN_EXCP_PRIVOPC(ctx);
4717 if (unlikely(!ctx->supervisor)) {
4718 GEN_EXCP_PRIVOPC(ctx);
4721 /* interpreted as no-op */
4725 /* rfci (supervisor only) */
4726 GEN_HANDLER(rfci_40x, 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP)
4728 #if defined(CONFIG_USER_ONLY)
4729 GEN_EXCP_PRIVOPC(ctx);
4731 if (unlikely(!ctx->supervisor)) {
4732 GEN_EXCP_PRIVOPC(ctx);
4735 /* Restore CPU state */
4741 GEN_HANDLER(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE)
4743 #if defined(CONFIG_USER_ONLY)
4744 GEN_EXCP_PRIVOPC(ctx);
4746 if (unlikely(!ctx->supervisor)) {
4747 GEN_EXCP_PRIVOPC(ctx);
4750 /* Restore CPU state */
4756 /* BookE specific */
4757 /* XXX: not implemented on 440 ? */
4758 GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_BOOKE_EXT)
4760 #if defined(CONFIG_USER_ONLY)
4761 GEN_EXCP_PRIVOPC(ctx);
4763 if (unlikely(!ctx->supervisor)) {
4764 GEN_EXCP_PRIVOPC(ctx);
4767 /* Restore CPU state */
4773 /* XXX: not implemented on 440 ? */
4774 GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI)
4776 #if defined(CONFIG_USER_ONLY)
4777 GEN_EXCP_PRIVOPC(ctx);
4779 if (unlikely(!ctx->supervisor)) {
4780 GEN_EXCP_PRIVOPC(ctx);
4783 /* Restore CPU state */
4789 /* TLB management - PowerPC 405 implementation */
4791 GEN_HANDLER(tlbre_40x, 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB)
4793 #if defined(CONFIG_USER_ONLY)
4794 GEN_EXCP_PRIVOPC(ctx);
4796 if (unlikely(!ctx->supervisor)) {
4797 GEN_EXCP_PRIVOPC(ctx);
4800 switch (rB(ctx->opcode)) {
4802 gen_op_load_gpr_T0(rA(ctx->opcode));
4803 gen_op_4xx_tlbre_hi();
4804 gen_op_store_T0_gpr(rD(ctx->opcode));
4807 gen_op_load_gpr_T0(rA(ctx->opcode));
4808 gen_op_4xx_tlbre_lo();
4809 gen_op_store_T0_gpr(rD(ctx->opcode));
4812 GEN_EXCP_INVAL(ctx);
4818 /* tlbsx - tlbsx. */
4819 GEN_HANDLER(tlbsx_40x, 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB)
4821 #if defined(CONFIG_USER_ONLY)
4822 GEN_EXCP_PRIVOPC(ctx);
4824 if (unlikely(!ctx->supervisor)) {
4825 GEN_EXCP_PRIVOPC(ctx);
4828 gen_addr_reg_index(ctx);
4829 if (Rc(ctx->opcode))
4830 gen_op_4xx_tlbsx_();
4833 gen_op_store_T0_gpr(rD(ctx->opcode));
4838 GEN_HANDLER(tlbwe_40x, 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB)
4840 #if defined(CONFIG_USER_ONLY)
4841 GEN_EXCP_PRIVOPC(ctx);
4843 if (unlikely(!ctx->supervisor)) {
4844 GEN_EXCP_PRIVOPC(ctx);
4847 switch (rB(ctx->opcode)) {
4849 gen_op_load_gpr_T0(rA(ctx->opcode));
4850 gen_op_load_gpr_T1(rS(ctx->opcode));
4851 gen_op_4xx_tlbwe_hi();
4854 gen_op_load_gpr_T0(rA(ctx->opcode));
4855 gen_op_load_gpr_T1(rS(ctx->opcode));
4856 gen_op_4xx_tlbwe_lo();
4859 GEN_EXCP_INVAL(ctx);
4865 /* TLB management - PowerPC 440 implementation */
4867 GEN_HANDLER(tlbre_440, 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE)
4869 #if defined(CONFIG_USER_ONLY)
4870 GEN_EXCP_PRIVOPC(ctx);
4872 if (unlikely(!ctx->supervisor)) {
4873 GEN_EXCP_PRIVOPC(ctx);
4876 switch (rB(ctx->opcode)) {
4880 gen_op_load_gpr_T0(rA(ctx->opcode));
4881 gen_op_440_tlbre(rB(ctx->opcode));
4882 gen_op_store_T0_gpr(rD(ctx->opcode));
4885 GEN_EXCP_INVAL(ctx);
4891 /* tlbsx - tlbsx. */
4892 GEN_HANDLER(tlbsx_440, 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE)
4894 #if defined(CONFIG_USER_ONLY)
4895 GEN_EXCP_PRIVOPC(ctx);
4897 if (unlikely(!ctx->supervisor)) {
4898 GEN_EXCP_PRIVOPC(ctx);
4901 gen_addr_reg_index(ctx);
4902 if (Rc(ctx->opcode))
4903 gen_op_440_tlbsx_();
4906 gen_op_store_T0_gpr(rD(ctx->opcode));
4911 GEN_HANDLER(tlbwe_440, 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE)
4913 #if defined(CONFIG_USER_ONLY)
4914 GEN_EXCP_PRIVOPC(ctx);
4916 if (unlikely(!ctx->supervisor)) {
4917 GEN_EXCP_PRIVOPC(ctx);
4920 switch (rB(ctx->opcode)) {
4924 gen_op_load_gpr_T0(rA(ctx->opcode));
4925 gen_op_load_gpr_T1(rS(ctx->opcode));
4926 gen_op_440_tlbwe(rB(ctx->opcode));
4929 GEN_EXCP_INVAL(ctx);
4936 GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_EMB_COMMON)
4938 #if defined(CONFIG_USER_ONLY)
4939 GEN_EXCP_PRIVOPC(ctx);
4941 if (unlikely(!ctx->supervisor)) {
4942 GEN_EXCP_PRIVOPC(ctx);
4945 gen_op_load_gpr_T0(rD(ctx->opcode));
4947 /* Stop translation to have a chance to raise an exception
4948 * if we just set msr_ee to 1
4955 GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000EFC01, PPC_EMB_COMMON)
4957 #if defined(CONFIG_USER_ONLY)
4958 GEN_EXCP_PRIVOPC(ctx);
4960 if (unlikely(!ctx->supervisor)) {
4961 GEN_EXCP_PRIVOPC(ctx);
4964 gen_op_set_T0(ctx->opcode & 0x00010000);
4966 /* Stop translation to have a chance to raise an exception
4967 * if we just set msr_ee to 1
4973 /* PowerPC 440 specific instructions */
4975 GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC)
4977 gen_op_load_gpr_T0(rS(ctx->opcode));
4978 gen_op_load_gpr_T1(rB(ctx->opcode));
4980 gen_op_store_T0_gpr(rA(ctx->opcode));
4981 gen_op_store_xer_bc();
4982 if (Rc(ctx->opcode)) {
4983 gen_op_440_dlmzb_update_Rc();
4984 gen_op_store_T0_crf(0);
4988 /* mbar replaces eieio on 440 */
4989 GEN_HANDLER(mbar, 0x1F, 0x16, 0x13, 0x001FF801, PPC_BOOKE)
4991 /* interpreted as no-op */
4994 /* msync replaces sync on 440 */
4995 GEN_HANDLER(msync, 0x1F, 0x16, 0x12, 0x03FF0801, PPC_BOOKE)
4997 /* interpreted as no-op */
5001 GEN_HANDLER(icbt_440, 0x1F, 0x16, 0x00, 0x03E00001, PPC_BOOKE)
5003 /* interpreted as no-op */
5004 /* XXX: specification say this is treated as a load by the MMU
5005 * but does not generate any exception
5009 #if defined(TARGET_PPCEMB)
5010 /*** SPE extension ***/
5012 /* Register moves */
5013 GEN32(gen_op_load_gpr64_T0, gen_op_load_gpr64_T0_gpr);
5014 GEN32(gen_op_load_gpr64_T1, gen_op_load_gpr64_T1_gpr);
5016 GEN32(gen_op_load_gpr64_T2, gen_op_load_gpr64_T2_gpr);
5019 GEN32(gen_op_store_T0_gpr64, gen_op_store_T0_gpr64_gpr);
5020 GEN32(gen_op_store_T1_gpr64, gen_op_store_T1_gpr64_gpr);
5022 GEN32(gen_op_store_T2_gpr64, gen_op_store_T2_gpr64_gpr);
5025 #define GEN_SPE(name0, name1, opc2, opc3, inval, type) \
5026 GEN_HANDLER(name0##_##name1, 0x04, opc2, opc3, inval, type) \
5028 if (Rc(ctx->opcode)) \
5034 /* Handler for undefined SPE opcodes */
5035 static inline void gen_speundef (DisasContext *ctx)
5037 GEN_EXCP_INVAL(ctx);
5040 /* SPE load and stores */
5041 static inline void gen_addr_spe_imm_index (DisasContext *ctx, int sh)
5043 target_long simm = rB(ctx->opcode);
5045 if (rA(ctx->opcode) == 0) {
5046 gen_set_T0(simm << sh);
5048 gen_op_load_gpr_T0(rA(ctx->opcode));
5049 if (likely(simm != 0))
5050 gen_op_addi(simm << sh);
5054 #define op_spe_ldst(name) (*gen_op_##name[ctx->mem_idx])()
5055 #if defined(CONFIG_USER_ONLY)
5056 #if defined(TARGET_PPC64)
5057 #define OP_SPE_LD_TABLE(name) \
5058 static GenOpFunc *gen_op_spe_l##name[] = { \
5059 &gen_op_spe_l##name##_raw, \
5060 &gen_op_spe_l##name##_le_raw, \
5061 &gen_op_spe_l##name##_64_raw, \
5062 &gen_op_spe_l##name##_le_64_raw, \
5064 #define OP_SPE_ST_TABLE(name) \
5065 static GenOpFunc *gen_op_spe_st##name[] = { \
5066 &gen_op_spe_st##name##_raw, \
5067 &gen_op_spe_st##name##_le_raw, \
5068 &gen_op_spe_st##name##_64_raw, \
5069 &gen_op_spe_st##name##_le_64_raw, \
5071 #else /* defined(TARGET_PPC64) */
5072 #define OP_SPE_LD_TABLE(name) \
5073 static GenOpFunc *gen_op_spe_l##name[] = { \
5074 &gen_op_spe_l##name##_raw, \
5075 &gen_op_spe_l##name##_le_raw, \
5077 #define OP_SPE_ST_TABLE(name) \
5078 static GenOpFunc *gen_op_spe_st##name[] = { \
5079 &gen_op_spe_st##name##_raw, \
5080 &gen_op_spe_st##name##_le_raw, \
5082 #endif /* defined(TARGET_PPC64) */
5083 #else /* defined(CONFIG_USER_ONLY) */
5084 #if defined(TARGET_PPC64)
5085 #define OP_SPE_LD_TABLE(name) \
5086 static GenOpFunc *gen_op_spe_l##name[] = { \
5087 &gen_op_spe_l##name##_user, \
5088 &gen_op_spe_l##name##_le_user, \
5089 &gen_op_spe_l##name##_kernel, \
5090 &gen_op_spe_l##name##_le_kernel, \
5091 &gen_op_spe_l##name##_64_user, \
5092 &gen_op_spe_l##name##_le_64_user, \
5093 &gen_op_spe_l##name##_64_kernel, \
5094 &gen_op_spe_l##name##_le_64_kernel, \
5096 #define OP_SPE_ST_TABLE(name) \
5097 static GenOpFunc *gen_op_spe_st##name[] = { \
5098 &gen_op_spe_st##name##_user, \
5099 &gen_op_spe_st##name##_le_user, \
5100 &gen_op_spe_st##name##_kernel, \
5101 &gen_op_spe_st##name##_le_kernel, \
5102 &gen_op_spe_st##name##_64_user, \
5103 &gen_op_spe_st##name##_le_64_user, \
5104 &gen_op_spe_st##name##_64_kernel, \
5105 &gen_op_spe_st##name##_le_64_kernel, \
5107 #else /* defined(TARGET_PPC64) */
5108 #define OP_SPE_LD_TABLE(name) \
5109 static GenOpFunc *gen_op_spe_l##name[] = { \
5110 &gen_op_spe_l##name##_user, \
5111 &gen_op_spe_l##name##_le_user, \
5112 &gen_op_spe_l##name##_kernel, \
5113 &gen_op_spe_l##name##_le_kernel, \
5115 #define OP_SPE_ST_TABLE(name) \
5116 static GenOpFunc *gen_op_spe_st##name[] = { \
5117 &gen_op_spe_st##name##_user, \
5118 &gen_op_spe_st##name##_le_user, \
5119 &gen_op_spe_st##name##_kernel, \
5120 &gen_op_spe_st##name##_le_kernel, \
5122 #endif /* defined(TARGET_PPC64) */
5123 #endif /* defined(CONFIG_USER_ONLY) */
5125 #define GEN_SPE_LD(name, sh) \
5126 static inline void gen_evl##name (DisasContext *ctx) \
5128 if (unlikely(!ctx->spe_enabled)) { \
5129 GEN_EXCP_NO_AP(ctx); \
5132 gen_addr_spe_imm_index(ctx, sh); \
5133 op_spe_ldst(spe_l##name); \
5134 gen_op_store_T1_gpr64(rD(ctx->opcode)); \
5137 #define GEN_SPE_LDX(name) \
5138 static inline void gen_evl##name##x (DisasContext *ctx) \
5140 if (unlikely(!ctx->spe_enabled)) { \
5141 GEN_EXCP_NO_AP(ctx); \
5144 gen_addr_reg_index(ctx); \
5145 op_spe_ldst(spe_l##name); \
5146 gen_op_store_T1_gpr64(rD(ctx->opcode)); \
5149 #define GEN_SPEOP_LD(name, sh) \
5150 OP_SPE_LD_TABLE(name); \
5151 GEN_SPE_LD(name, sh); \
5154 #define GEN_SPE_ST(name, sh) \
5155 static inline void gen_evst##name (DisasContext *ctx) \
5157 if (unlikely(!ctx->spe_enabled)) { \
5158 GEN_EXCP_NO_AP(ctx); \
5161 gen_addr_spe_imm_index(ctx, sh); \
5162 gen_op_load_gpr64_T1(rS(ctx->opcode)); \
5163 op_spe_ldst(spe_st##name); \
5166 #define GEN_SPE_STX(name) \
5167 static inline void gen_evst##name##x (DisasContext *ctx) \
5169 if (unlikely(!ctx->spe_enabled)) { \
5170 GEN_EXCP_NO_AP(ctx); \
5173 gen_addr_reg_index(ctx); \
5174 gen_op_load_gpr64_T1(rS(ctx->opcode)); \
5175 op_spe_ldst(spe_st##name); \
5178 #define GEN_SPEOP_ST(name, sh) \
5179 OP_SPE_ST_TABLE(name); \
5180 GEN_SPE_ST(name, sh); \
5183 #define GEN_SPEOP_LDST(name, sh) \
5184 GEN_SPEOP_LD(name, sh); \
5185 GEN_SPEOP_ST(name, sh)
5187 /* SPE arithmetic and logic */
5188 #define GEN_SPEOP_ARITH2(name) \
5189 static inline void gen_##name (DisasContext *ctx) \
5191 if (unlikely(!ctx->spe_enabled)) { \
5192 GEN_EXCP_NO_AP(ctx); \
5195 gen_op_load_gpr64_T0(rA(ctx->opcode)); \
5196 gen_op_load_gpr64_T1(rB(ctx->opcode)); \
5198 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5201 #define GEN_SPEOP_ARITH1(name) \
5202 static inline void gen_##name (DisasContext *ctx) \
5204 if (unlikely(!ctx->spe_enabled)) { \
5205 GEN_EXCP_NO_AP(ctx); \
5208 gen_op_load_gpr64_T0(rA(ctx->opcode)); \
5210 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5213 #define GEN_SPEOP_COMP(name) \
5214 static inline void gen_##name (DisasContext *ctx) \
5216 if (unlikely(!ctx->spe_enabled)) { \
5217 GEN_EXCP_NO_AP(ctx); \
5220 gen_op_load_gpr64_T0(rA(ctx->opcode)); \
5221 gen_op_load_gpr64_T1(rB(ctx->opcode)); \
5223 gen_op_store_T0_crf(crfD(ctx->opcode)); \
5227 GEN_SPEOP_ARITH2(evand);
5228 GEN_SPEOP_ARITH2(evandc);
5229 GEN_SPEOP_ARITH2(evxor);
5230 GEN_SPEOP_ARITH2(evor);
5231 GEN_SPEOP_ARITH2(evnor);
5232 GEN_SPEOP_ARITH2(eveqv);
5233 GEN_SPEOP_ARITH2(evorc);
5234 GEN_SPEOP_ARITH2(evnand);
5235 GEN_SPEOP_ARITH2(evsrwu);
5236 GEN_SPEOP_ARITH2(evsrws);
5237 GEN_SPEOP_ARITH2(evslw);
5238 GEN_SPEOP_ARITH2(evrlw);
5239 GEN_SPEOP_ARITH2(evmergehi);
5240 GEN_SPEOP_ARITH2(evmergelo);
5241 GEN_SPEOP_ARITH2(evmergehilo);
5242 GEN_SPEOP_ARITH2(evmergelohi);
5245 GEN_SPEOP_ARITH2(evaddw);
5246 GEN_SPEOP_ARITH2(evsubfw);
5247 GEN_SPEOP_ARITH1(evabs);
5248 GEN_SPEOP_ARITH1(evneg);
5249 GEN_SPEOP_ARITH1(evextsb);
5250 GEN_SPEOP_ARITH1(evextsh);
5251 GEN_SPEOP_ARITH1(evrndw);
5252 GEN_SPEOP_ARITH1(evcntlzw);
5253 GEN_SPEOP_ARITH1(evcntlsw);
5254 static inline void gen_brinc (DisasContext *ctx)
5256 /* Note: brinc is usable even if SPE is disabled */
5257 gen_op_load_gpr64_T0(rA(ctx->opcode));
5258 gen_op_load_gpr64_T1(rB(ctx->opcode));
5260 gen_op_store_T0_gpr64(rD(ctx->opcode));
5263 #define GEN_SPEOP_ARITH_IMM2(name) \
5264 static inline void gen_##name##i (DisasContext *ctx) \
5266 if (unlikely(!ctx->spe_enabled)) { \
5267 GEN_EXCP_NO_AP(ctx); \
5270 gen_op_load_gpr64_T0(rB(ctx->opcode)); \
5271 gen_op_splatwi_T1_64(rA(ctx->opcode)); \
5273 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5276 #define GEN_SPEOP_LOGIC_IMM2(name) \
5277 static inline void gen_##name##i (DisasContext *ctx) \
5279 if (unlikely(!ctx->spe_enabled)) { \
5280 GEN_EXCP_NO_AP(ctx); \
5283 gen_op_load_gpr64_T0(rA(ctx->opcode)); \
5284 gen_op_splatwi_T1_64(rB(ctx->opcode)); \
5286 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5289 GEN_SPEOP_ARITH_IMM2(evaddw);
5290 #define gen_evaddiw gen_evaddwi
5291 GEN_SPEOP_ARITH_IMM2(evsubfw);
5292 #define gen_evsubifw gen_evsubfwi
5293 GEN_SPEOP_LOGIC_IMM2(evslw);
5294 GEN_SPEOP_LOGIC_IMM2(evsrwu);
5295 #define gen_evsrwis gen_evsrwsi
5296 GEN_SPEOP_LOGIC_IMM2(evsrws);
5297 #define gen_evsrwiu gen_evsrwui
5298 GEN_SPEOP_LOGIC_IMM2(evrlw);
5300 static inline void gen_evsplati (DisasContext *ctx)
5302 int32_t imm = (int32_t)(rA(ctx->opcode) << 27) >> 27;
5304 gen_op_splatwi_T0_64(imm);
5305 gen_op_store_T0_gpr64(rD(ctx->opcode));
5308 static inline void gen_evsplatfi (DisasContext *ctx)
5310 uint32_t imm = rA(ctx->opcode) << 27;
5312 gen_op_splatwi_T0_64(imm);
5313 gen_op_store_T0_gpr64(rD(ctx->opcode));
5317 GEN_SPEOP_COMP(evcmpgtu);
5318 GEN_SPEOP_COMP(evcmpgts);
5319 GEN_SPEOP_COMP(evcmpltu);
5320 GEN_SPEOP_COMP(evcmplts);
5321 GEN_SPEOP_COMP(evcmpeq);
5323 GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, PPC_SPE); ////
5324 GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, PPC_SPE);
5325 GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, PPC_SPE); ////
5326 GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, PPC_SPE);
5327 GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, PPC_SPE); ////
5328 GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, PPC_SPE); ////
5329 GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, PPC_SPE); ////
5330 GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x00000000, PPC_SPE); //
5331 GEN_SPE(speundef, evand, 0x08, 0x08, 0x00000000, PPC_SPE); ////
5332 GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, PPC_SPE); ////
5333 GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, PPC_SPE); ////
5334 GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, PPC_SPE); ////
5335 GEN_SPE(speundef, evorc, 0x0D, 0x08, 0x00000000, PPC_SPE); ////
5336 GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, PPC_SPE); ////
5337 GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, PPC_SPE); ////
5338 GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, PPC_SPE);
5339 GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, PPC_SPE); ////
5340 GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, PPC_SPE);
5341 GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, PPC_SPE); //
5342 GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, PPC_SPE);
5343 GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, PPC_SPE); ////
5344 GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, PPC_SPE); ////
5345 GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, PPC_SPE); ////
5346 GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, PPC_SPE); ////
5347 GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, PPC_SPE); ////
5349 static inline void gen_evsel (DisasContext *ctx)
5351 if (unlikely(!ctx->spe_enabled)) {
5352 GEN_EXCP_NO_AP(ctx);
5355 gen_op_load_crf_T0(ctx->opcode & 0x7);
5356 gen_op_load_gpr64_T0(rA(ctx->opcode));
5357 gen_op_load_gpr64_T1(rB(ctx->opcode));
5359 gen_op_store_T0_gpr64(rD(ctx->opcode));
5362 GEN_HANDLER(evsel0, 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE)
5366 GEN_HANDLER(evsel1, 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE)
5370 GEN_HANDLER(evsel2, 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE)
5374 GEN_HANDLER(evsel3, 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE)
5379 /* Load and stores */
5380 #if defined(TARGET_PPC64)
5381 /* In that case, we already have 64 bits load & stores
5382 * so, spe_ldd is equivalent to ld and spe_std is equivalent to std
5384 #if defined(CONFIG_USER_ONLY)
5385 #define gen_op_spe_ldd_raw gen_op_ld_raw
5386 #define gen_op_spe_ldd_64_raw gen_op_ld_64_raw
5387 #define gen_op_spe_ldd_le_raw gen_op_ld_le_raw
5388 #define gen_op_spe_ldd_le_64_raw gen_op_ld_le_64_raw
5389 #define gen_op_spe_stdd_raw gen_op_ld_raw
5390 #define gen_op_spe_stdd_64_raw gen_op_std_64_raw
5391 #define gen_op_spe_stdd_le_raw gen_op_std_le_raw
5392 #define gen_op_spe_stdd_le_64_raw gen_op_std_le_64_raw
5393 #else /* defined(CONFIG_USER_ONLY) */
5394 #define gen_op_spe_ldd_kernel gen_op_ld_kernel
5395 #define gen_op_spe_ldd_64_kernel gen_op_ld_64_kernel
5396 #define gen_op_spe_ldd_le_kernel gen_op_ld_kernel
5397 #define gen_op_spe_ldd_le_64_kernel gen_op_ld_64_kernel
5398 #define gen_op_spe_ldd_user gen_op_ld_user
5399 #define gen_op_spe_ldd_64_user gen_op_ld_64_user
5400 #define gen_op_spe_ldd_le_user gen_op_ld_le_user
5401 #define gen_op_spe_ldd_le_64_user gen_op_ld_le_64_user
5402 #define gen_op_spe_stdd_kernel gen_op_std_kernel
5403 #define gen_op_spe_stdd_64_kernel gen_op_std_64_kernel
5404 #define gen_op_spe_stdd_le_kernel gen_op_std_kernel
5405 #define gen_op_spe_stdd_le_64_kernel gen_op_std_64_kernel
5406 #define gen_op_spe_stdd_user gen_op_std_user
5407 #define gen_op_spe_stdd_64_user gen_op_std_64_user
5408 #define gen_op_spe_stdd_le_user gen_op_std_le_user
5409 #define gen_op_spe_stdd_le_64_user gen_op_std_le_64_user
5410 #endif /* defined(CONFIG_USER_ONLY) */
5411 #endif /* defined(TARGET_PPC64) */
5412 GEN_SPEOP_LDST(dd, 3);
5413 GEN_SPEOP_LDST(dw, 3);
5414 GEN_SPEOP_LDST(dh, 3);
5415 GEN_SPEOP_LDST(whe, 2);
5416 GEN_SPEOP_LD(whou, 2);
5417 GEN_SPEOP_LD(whos, 2);
5418 GEN_SPEOP_ST(who, 2);
5420 #if defined(TARGET_PPC64)
5421 /* In that case, spe_stwwo is equivalent to stw */
5422 #if defined(CONFIG_USER_ONLY)
5423 #define gen_op_spe_stwwo_raw gen_op_stw_raw
5424 #define gen_op_spe_stwwo_le_raw gen_op_stw_le_raw
5425 #define gen_op_spe_stwwo_64_raw gen_op_stw_64_raw
5426 #define gen_op_spe_stwwo_le_64_raw gen_op_stw_le_64_raw
5428 #define gen_op_spe_stwwo_user gen_op_stw_user
5429 #define gen_op_spe_stwwo_le_user gen_op_stw_le_user
5430 #define gen_op_spe_stwwo_64_user gen_op_stw_64_user
5431 #define gen_op_spe_stwwo_le_64_user gen_op_stw_le_64_user
5432 #define gen_op_spe_stwwo_kernel gen_op_stw_kernel
5433 #define gen_op_spe_stwwo_le_kernel gen_op_stw_le_kernel
5434 #define gen_op_spe_stwwo_64_kernel gen_op_stw_64_kernel
5435 #define gen_op_spe_stwwo_le_64_kernel gen_op_stw_le_64_kernel
5438 #define _GEN_OP_SPE_STWWE(suffix) \
5439 static inline void gen_op_spe_stwwe_##suffix (void) \
5441 gen_op_srli32_T1_64(); \
5442 gen_op_spe_stwwo_##suffix(); \
5444 #define _GEN_OP_SPE_STWWE_LE(suffix) \
5445 static inline void gen_op_spe_stwwe_le_##suffix (void) \
5447 gen_op_srli32_T1_64(); \
5448 gen_op_spe_stwwo_le_##suffix(); \
5450 #if defined(TARGET_PPC64)
5451 #define GEN_OP_SPE_STWWE(suffix) \
5452 _GEN_OP_SPE_STWWE(suffix); \
5453 _GEN_OP_SPE_STWWE_LE(suffix); \
5454 static inline void gen_op_spe_stwwe_64_##suffix (void) \
5456 gen_op_srli32_T1_64(); \
5457 gen_op_spe_stwwo_64_##suffix(); \
5459 static inline void gen_op_spe_stwwe_le_64_##suffix (void) \
5461 gen_op_srli32_T1_64(); \
5462 gen_op_spe_stwwo_le_64_##suffix(); \
5465 #define GEN_OP_SPE_STWWE(suffix) \
5466 _GEN_OP_SPE_STWWE(suffix); \
5467 _GEN_OP_SPE_STWWE_LE(suffix)
5469 #if defined(CONFIG_USER_ONLY)
5470 GEN_OP_SPE_STWWE(raw);
5471 #else /* defined(CONFIG_USER_ONLY) */
5472 GEN_OP_SPE_STWWE(kernel);
5473 GEN_OP_SPE_STWWE(user);
5474 #endif /* defined(CONFIG_USER_ONLY) */
5475 GEN_SPEOP_ST(wwe, 2);
5476 GEN_SPEOP_ST(wwo, 2);
5478 #define GEN_SPE_LDSPLAT(name, op, suffix) \
5479 static inline void gen_op_spe_l##name##_##suffix (void) \
5481 gen_op_##op##_##suffix(); \
5482 gen_op_splatw_T1_64(); \
5485 #define GEN_OP_SPE_LHE(suffix) \
5486 static inline void gen_op_spe_lhe_##suffix (void) \
5488 gen_op_spe_lh_##suffix(); \
5489 gen_op_sli16_T1_64(); \
5492 #define GEN_OP_SPE_LHX(suffix) \
5493 static inline void gen_op_spe_lhx_##suffix (void) \
5495 gen_op_spe_lh_##suffix(); \
5496 gen_op_extsh_T1_64(); \
5499 #if defined(CONFIG_USER_ONLY)
5500 GEN_OP_SPE_LHE(raw);
5501 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, raw);
5502 GEN_OP_SPE_LHE(le_raw);
5503 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_raw);
5504 GEN_SPE_LDSPLAT(hhousplat, spe_lh, raw);
5505 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_raw);
5506 GEN_OP_SPE_LHX(raw);
5507 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, raw);
5508 GEN_OP_SPE_LHX(le_raw);
5509 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_raw);
5510 #if defined(TARGET_PPC64)
5511 GEN_OP_SPE_LHE(64_raw);
5512 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_raw);
5513 GEN_OP_SPE_LHE(le_64_raw);
5514 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_raw);
5515 GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_raw);
5516 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_raw);
5517 GEN_OP_SPE_LHX(64_raw);
5518 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_raw);
5519 GEN_OP_SPE_LHX(le_64_raw);
5520 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_raw);
5523 GEN_OP_SPE_LHE(kernel);
5524 GEN_OP_SPE_LHE(user);
5525 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, kernel);
5526 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, user);
5527 GEN_OP_SPE_LHE(le_kernel);
5528 GEN_OP_SPE_LHE(le_user);
5529 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_kernel);
5530 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_user);
5531 GEN_SPE_LDSPLAT(hhousplat, spe_lh, kernel);
5532 GEN_SPE_LDSPLAT(hhousplat, spe_lh, user);
5533 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_kernel);
5534 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_user);
5535 GEN_OP_SPE_LHX(kernel);
5536 GEN_OP_SPE_LHX(user);
5537 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, kernel);
5538 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, user);
5539 GEN_OP_SPE_LHX(le_kernel);
5540 GEN_OP_SPE_LHX(le_user);
5541 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_kernel);
5542 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_user);
5543 #if defined(TARGET_PPC64)
5544 GEN_OP_SPE_LHE(64_kernel);
5545 GEN_OP_SPE_LHE(64_user);
5546 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_kernel);
5547 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_user);
5548 GEN_OP_SPE_LHE(le_64_kernel);
5549 GEN_OP_SPE_LHE(le_64_user);
5550 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_kernel);
5551 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_user);
5552 GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_kernel);
5553 GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_user);
5554 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_kernel);
5555 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_user);
5556 GEN_OP_SPE_LHX(64_kernel);
5557 GEN_OP_SPE_LHX(64_user);
5558 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_kernel);
5559 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_user);
5560 GEN_OP_SPE_LHX(le_64_kernel);
5561 GEN_OP_SPE_LHX(le_64_user);
5562 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_kernel);
5563 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_user);
5566 GEN_SPEOP_LD(hhesplat, 1);
5567 GEN_SPEOP_LD(hhousplat, 1);
5568 GEN_SPEOP_LD(hhossplat, 1);
5569 GEN_SPEOP_LD(wwsplat, 2);
5570 GEN_SPEOP_LD(whsplat, 2);
5572 GEN_SPE(evlddx, evldd, 0x00, 0x0C, 0x00000000, PPC_SPE); //
5573 GEN_SPE(evldwx, evldw, 0x01, 0x0C, 0x00000000, PPC_SPE); //
5574 GEN_SPE(evldhx, evldh, 0x02, 0x0C, 0x00000000, PPC_SPE); //
5575 GEN_SPE(evlhhesplatx, evlhhesplat, 0x04, 0x0C, 0x00000000, PPC_SPE); //
5576 GEN_SPE(evlhhousplatx, evlhhousplat, 0x06, 0x0C, 0x00000000, PPC_SPE); //
5577 GEN_SPE(evlhhossplatx, evlhhossplat, 0x07, 0x0C, 0x00000000, PPC_SPE); //
5578 GEN_SPE(evlwhex, evlwhe, 0x08, 0x0C, 0x00000000, PPC_SPE); //
5579 GEN_SPE(evlwhoux, evlwhou, 0x0A, 0x0C, 0x00000000, PPC_SPE); //
5580 GEN_SPE(evlwhosx, evlwhos, 0x0B, 0x0C, 0x00000000, PPC_SPE); //
5581 GEN_SPE(evlwwsplatx, evlwwsplat, 0x0C, 0x0C, 0x00000000, PPC_SPE); //
5582 GEN_SPE(evlwhsplatx, evlwhsplat, 0x0E, 0x0C, 0x00000000, PPC_SPE); //
5583 GEN_SPE(evstddx, evstdd, 0x10, 0x0C, 0x00000000, PPC_SPE); //
5584 GEN_SPE(evstdwx, evstdw, 0x11, 0x0C, 0x00000000, PPC_SPE); //
5585 GEN_SPE(evstdhx, evstdh, 0x12, 0x0C, 0x00000000, PPC_SPE); //
5586 GEN_SPE(evstwhex, evstwhe, 0x18, 0x0C, 0x00000000, PPC_SPE); //
5587 GEN_SPE(evstwhox, evstwho, 0x1A, 0x0C, 0x00000000, PPC_SPE); //
5588 GEN_SPE(evstwwex, evstwwe, 0x1C, 0x0C, 0x00000000, PPC_SPE); //
5589 GEN_SPE(evstwwox, evstwwo, 0x1E, 0x0C, 0x00000000, PPC_SPE); //
5591 /* Multiply and add - TODO */
5593 GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0x00000000, PPC_SPE);
5594 GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0x00000000, PPC_SPE);
5595 GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, PPC_SPE);
5596 GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0x00000000, PPC_SPE);
5597 GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, PPC_SPE);
5598 GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0x00000000, PPC_SPE);
5599 GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0x00000000, PPC_SPE);
5600 GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0x00000000, PPC_SPE);
5601 GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, PPC_SPE);
5602 GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0x00000000, PPC_SPE);
5603 GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, PPC_SPE);
5604 GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0x00000000, PPC_SPE);
5606 GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0x00000000, PPC_SPE);
5607 GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, PPC_SPE);
5608 GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, PPC_SPE);
5609 GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0x00000000, PPC_SPE);
5610 GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0x00000000, PPC_SPE);
5611 GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, PPC_SPE);
5612 GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0x00000000, PPC_SPE);
5613 GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0x00000000, PPC_SPE);
5614 GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, PPC_SPE);
5615 GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, PPC_SPE);
5616 GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0x00000000, PPC_SPE);
5617 GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0x00000000, PPC_SPE);
5618 GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, PPC_SPE);
5619 GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0x00000000, PPC_SPE);
5621 GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, PPC_SPE);
5622 GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, PPC_SPE);
5623 GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, PPC_SPE);
5624 GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, PPC_SPE);
5625 GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, PPC_SPE);
5626 GEN_SPE(evmra, speundef, 0x07, 0x13, 0x0000F800, PPC_SPE);
5628 GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, PPC_SPE);
5629 GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0x00000000, PPC_SPE);
5630 GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, PPC_SPE);
5631 GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0x00000000, PPC_SPE);
5632 GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, PPC_SPE);
5633 GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0x00000000, PPC_SPE);
5634 GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, PPC_SPE);
5635 GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0x00000000, PPC_SPE);
5636 GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, PPC_SPE);
5637 GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0x00000000, PPC_SPE);
5638 GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, PPC_SPE);
5639 GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0x00000000, PPC_SPE);
5641 GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, PPC_SPE);
5642 GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, PPC_SPE);
5643 GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0x00000000, PPC_SPE);
5644 GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, PPC_SPE);
5645 GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0x00000000, PPC_SPE);
5647 GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, PPC_SPE);
5648 GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0x00000000, PPC_SPE);
5649 GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, PPC_SPE);
5650 GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0x00000000, PPC_SPE);
5651 GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, PPC_SPE);
5652 GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0x00000000, PPC_SPE);
5653 GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, PPC_SPE);
5654 GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0x00000000, PPC_SPE);
5655 GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, PPC_SPE);
5656 GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0x00000000, PPC_SPE);
5657 GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, PPC_SPE);
5658 GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0x00000000, PPC_SPE);
5660 GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, PPC_SPE);
5661 GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, PPC_SPE);
5662 GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0x00000000, PPC_SPE);
5663 GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, PPC_SPE);
5664 GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0x00000000, PPC_SPE);
5667 /*** SPE floating-point extension ***/
5668 #define GEN_SPEFPUOP_CONV(name) \
5669 static inline void gen_##name (DisasContext *ctx) \
5671 gen_op_load_gpr64_T0(rB(ctx->opcode)); \
5673 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5676 /* Single precision floating-point vectors operations */
5678 GEN_SPEOP_ARITH2(evfsadd);
5679 GEN_SPEOP_ARITH2(evfssub);
5680 GEN_SPEOP_ARITH2(evfsmul);
5681 GEN_SPEOP_ARITH2(evfsdiv);
5682 GEN_SPEOP_ARITH1(evfsabs);
5683 GEN_SPEOP_ARITH1(evfsnabs);
5684 GEN_SPEOP_ARITH1(evfsneg);
5686 GEN_SPEFPUOP_CONV(evfscfui);
5687 GEN_SPEFPUOP_CONV(evfscfsi);
5688 GEN_SPEFPUOP_CONV(evfscfuf);
5689 GEN_SPEFPUOP_CONV(evfscfsf);
5690 GEN_SPEFPUOP_CONV(evfsctui);
5691 GEN_SPEFPUOP_CONV(evfsctsi);
5692 GEN_SPEFPUOP_CONV(evfsctuf);
5693 GEN_SPEFPUOP_CONV(evfsctsf);
5694 GEN_SPEFPUOP_CONV(evfsctuiz);
5695 GEN_SPEFPUOP_CONV(evfsctsiz);
5697 GEN_SPEOP_COMP(evfscmpgt);
5698 GEN_SPEOP_COMP(evfscmplt);
5699 GEN_SPEOP_COMP(evfscmpeq);
5700 GEN_SPEOP_COMP(evfststgt);
5701 GEN_SPEOP_COMP(evfststlt);
5702 GEN_SPEOP_COMP(evfststeq);
5704 /* Opcodes definitions */
5705 GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, PPC_SPEFPU); //
5706 GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, PPC_SPEFPU); //
5707 GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, PPC_SPEFPU); //
5708 GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, PPC_SPEFPU); //
5709 GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, PPC_SPEFPU); //
5710 GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, PPC_SPEFPU); //
5711 GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, PPC_SPEFPU); //
5712 GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, PPC_SPEFPU); //
5713 GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, PPC_SPEFPU); //
5714 GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, PPC_SPEFPU); //
5715 GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, PPC_SPEFPU); //
5716 GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, PPC_SPEFPU); //
5717 GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, PPC_SPEFPU); //
5718 GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, PPC_SPEFPU); //
5720 /* Single precision floating-point operations */
5722 GEN_SPEOP_ARITH2(efsadd);
5723 GEN_SPEOP_ARITH2(efssub);
5724 GEN_SPEOP_ARITH2(efsmul);
5725 GEN_SPEOP_ARITH2(efsdiv);
5726 GEN_SPEOP_ARITH1(efsabs);
5727 GEN_SPEOP_ARITH1(efsnabs);
5728 GEN_SPEOP_ARITH1(efsneg);
5730 GEN_SPEFPUOP_CONV(efscfui);
5731 GEN_SPEFPUOP_CONV(efscfsi);
5732 GEN_SPEFPUOP_CONV(efscfuf);
5733 GEN_SPEFPUOP_CONV(efscfsf);
5734 GEN_SPEFPUOP_CONV(efsctui);
5735 GEN_SPEFPUOP_CONV(efsctsi);
5736 GEN_SPEFPUOP_CONV(efsctuf);
5737 GEN_SPEFPUOP_CONV(efsctsf);
5738 GEN_SPEFPUOP_CONV(efsctuiz);
5739 GEN_SPEFPUOP_CONV(efsctsiz);
5740 GEN_SPEFPUOP_CONV(efscfd);
5742 GEN_SPEOP_COMP(efscmpgt);
5743 GEN_SPEOP_COMP(efscmplt);
5744 GEN_SPEOP_COMP(efscmpeq);
5745 GEN_SPEOP_COMP(efststgt);
5746 GEN_SPEOP_COMP(efststlt);
5747 GEN_SPEOP_COMP(efststeq);
5749 /* Opcodes definitions */
5750 GEN_SPE(efsadd, efssub, 0x00, 0x0A, 0x00000000, PPC_SPEFPU); //
5751 GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, PPC_SPEFPU); //
5752 GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, PPC_SPEFPU); //
5753 GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, PPC_SPEFPU); //
5754 GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, PPC_SPEFPU); //
5755 GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, PPC_SPEFPU); //
5756 GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, PPC_SPEFPU); //
5757 GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, PPC_SPEFPU); //
5758 GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, PPC_SPEFPU); //
5759 GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, PPC_SPEFPU); //
5760 GEN_SPE(efsctuiz, efsctsiz, 0x0C, 0x0B, 0x00180000, PPC_SPEFPU); //
5761 GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, PPC_SPEFPU); //
5762 GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, PPC_SPEFPU); //
5764 /* Double precision floating-point operations */
5766 GEN_SPEOP_ARITH2(efdadd);
5767 GEN_SPEOP_ARITH2(efdsub);
5768 GEN_SPEOP_ARITH2(efdmul);
5769 GEN_SPEOP_ARITH2(efddiv);
5770 GEN_SPEOP_ARITH1(efdabs);
5771 GEN_SPEOP_ARITH1(efdnabs);
5772 GEN_SPEOP_ARITH1(efdneg);
5775 GEN_SPEFPUOP_CONV(efdcfui);
5776 GEN_SPEFPUOP_CONV(efdcfsi);
5777 GEN_SPEFPUOP_CONV(efdcfuf);
5778 GEN_SPEFPUOP_CONV(efdcfsf);
5779 GEN_SPEFPUOP_CONV(efdctui);
5780 GEN_SPEFPUOP_CONV(efdctsi);
5781 GEN_SPEFPUOP_CONV(efdctuf);
5782 GEN_SPEFPUOP_CONV(efdctsf);
5783 GEN_SPEFPUOP_CONV(efdctuiz);
5784 GEN_SPEFPUOP_CONV(efdctsiz);
5785 GEN_SPEFPUOP_CONV(efdcfs);
5786 GEN_SPEFPUOP_CONV(efdcfuid);
5787 GEN_SPEFPUOP_CONV(efdcfsid);
5788 GEN_SPEFPUOP_CONV(efdctuidz);
5789 GEN_SPEFPUOP_CONV(efdctsidz);
5791 GEN_SPEOP_COMP(efdcmpgt);
5792 GEN_SPEOP_COMP(efdcmplt);
5793 GEN_SPEOP_COMP(efdcmpeq);
5794 GEN_SPEOP_COMP(efdtstgt);
5795 GEN_SPEOP_COMP(efdtstlt);
5796 GEN_SPEOP_COMP(efdtsteq);
5798 /* Opcodes definitions */
5799 GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, PPC_SPEFPU); //
5800 GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, PPC_SPEFPU); //
5801 GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, PPC_SPEFPU); //
5802 GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, PPC_SPEFPU); //
5803 GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, PPC_SPEFPU); //
5804 GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, PPC_SPEFPU); //
5805 GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, PPC_SPEFPU); //
5806 GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, PPC_SPEFPU); //
5807 GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, PPC_SPEFPU); //
5808 GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, PPC_SPEFPU); //
5809 GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, PPC_SPEFPU); //
5810 GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, PPC_SPEFPU); //
5811 GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, PPC_SPEFPU); //
5812 GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, PPC_SPEFPU); //
5813 GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, PPC_SPEFPU); //
5814 GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, PPC_SPEFPU); //
5817 /* End opcode list */
5818 GEN_OPCODE_MARK(end);
5820 #include "translate_init.c"
5822 /*****************************************************************************/
5823 /* Misc PowerPC helpers */
5824 static inline uint32_t load_xer (CPUState *env)
5826 return (xer_so << XER_SO) |
5827 (xer_ov << XER_OV) |
5828 (xer_ca << XER_CA) |
5829 (xer_bc << XER_BC) |
5830 (xer_cmp << XER_CMP);
5833 void cpu_dump_state (CPUState *env, FILE *f,
5834 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
5837 #if defined(TARGET_PPC64) || 1
5849 cpu_fprintf(f, "NIP " ADDRX " LR " ADDRX " CTR " ADDRX "\n",
5850 env->nip, env->lr, env->ctr);
5851 cpu_fprintf(f, "MSR " REGX FILL " XER %08x "
5852 #if !defined(NO_TIMER_DUMP)
5854 #if !defined(CONFIG_USER_ONLY)
5859 do_load_msr(env), load_xer(env)
5860 #if !defined(NO_TIMER_DUMP)
5861 , cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
5862 #if !defined(CONFIG_USER_ONLY)
5863 , cpu_ppc_load_decr(env)
5867 for (i = 0; i < 32; i++) {
5868 if ((i & (RGPL - 1)) == 0)
5869 cpu_fprintf(f, "GPR%02d", i);
5870 cpu_fprintf(f, " " REGX, (target_ulong)env->gpr[i]);
5871 if ((i & (RGPL - 1)) == (RGPL - 1))
5872 cpu_fprintf(f, "\n");
5874 cpu_fprintf(f, "CR ");
5875 for (i = 0; i < 8; i++)
5876 cpu_fprintf(f, "%01x", env->crf[i]);
5877 cpu_fprintf(f, " [");
5878 for (i = 0; i < 8; i++) {
5880 if (env->crf[i] & 0x08)
5882 else if (env->crf[i] & 0x04)
5884 else if (env->crf[i] & 0x02)
5886 cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
5888 cpu_fprintf(f, " ] " FILL "RES " REGX "\n", env->reserve);
5889 for (i = 0; i < 32; i++) {
5890 if ((i & (RFPL - 1)) == 0)
5891 cpu_fprintf(f, "FPR%02d", i);
5892 cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
5893 if ((i & (RFPL - 1)) == (RFPL - 1))
5894 cpu_fprintf(f, "\n");
5896 cpu_fprintf(f, "SRR0 " REGX " SRR1 " REGX " " FILL FILL FILL
5898 env->spr[SPR_SRR0], env->spr[SPR_SRR1], env->sdr1);
5905 void cpu_dump_statistics (CPUState *env, FILE*f,
5906 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
5909 #if defined(DO_PPC_STATISTICS)
5910 opc_handler_t **t1, **t2, **t3, *handler;
5914 for (op1 = 0; op1 < 64; op1++) {
5916 if (is_indirect_opcode(handler)) {
5917 t2 = ind_table(handler);
5918 for (op2 = 0; op2 < 32; op2++) {
5920 if (is_indirect_opcode(handler)) {
5921 t3 = ind_table(handler);
5922 for (op3 = 0; op3 < 32; op3++) {
5924 if (handler->count == 0)
5926 cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
5928 op1, op2, op3, op1, (op3 << 5) | op2,
5930 handler->count, handler->count);
5933 if (handler->count == 0)
5935 cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: "
5937 op1, op2, op1, op2, handler->oname,
5938 handler->count, handler->count);
5942 if (handler->count == 0)
5944 cpu_fprintf(f, "%02x (%02x ) %16s: %016llx %lld\n",
5945 op1, op1, handler->oname,
5946 handler->count, handler->count);
5952 /*****************************************************************************/
5953 static inline int gen_intermediate_code_internal (CPUState *env,
5954 TranslationBlock *tb,
5957 DisasContext ctx, *ctxp = &ctx;
5958 opc_handler_t **table, *handler;
5959 target_ulong pc_start;
5960 uint16_t *gen_opc_end;
5964 gen_opc_ptr = gen_opc_buf;
5965 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
5966 gen_opparam_ptr = gen_opparam_buf;
5970 ctx.exception = POWERPC_EXCP_NONE;
5971 ctx.spr_cb = env->spr_cb;
5972 #if defined(CONFIG_USER_ONLY)
5973 ctx.mem_idx = msr_le;
5974 #if defined(TARGET_PPC64)
5975 ctx.mem_idx |= msr_sf << 1;
5978 ctx.supervisor = 1 - msr_pr;
5979 ctx.mem_idx = ((1 - msr_pr) << 1) | msr_le;
5980 #if defined(TARGET_PPC64)
5981 ctx.mem_idx |= msr_sf << 2;
5984 #if defined(TARGET_PPC64)
5985 ctx.sf_mode = msr_sf;
5987 ctx.fpu_enabled = msr_fp;
5988 #if defined(TARGET_PPCEMB)
5989 ctx.spe_enabled = msr_spe;
5991 ctx.singlestep_enabled = env->singlestep_enabled;
5992 #if defined (DO_SINGLE_STEP) && 0
5993 /* Single step trace mode */
5996 /* Set env in case of segfault during code fetch */
5997 while (ctx.exception == POWERPC_EXCP_NONE && gen_opc_ptr < gen_opc_end) {
5998 if (unlikely(env->nb_breakpoints > 0)) {
5999 for (j = 0; j < env->nb_breakpoints; j++) {
6000 if (env->breakpoints[j] == ctx.nip) {
6001 gen_update_nip(&ctx, ctx.nip);
6007 if (unlikely(search_pc)) {
6008 j = gen_opc_ptr - gen_opc_buf;
6012 gen_opc_instr_start[lj++] = 0;
6013 gen_opc_pc[lj] = ctx.nip;
6014 gen_opc_instr_start[lj] = 1;
6017 #if defined PPC_DEBUG_DISAS
6018 if (loglevel & CPU_LOG_TB_IN_ASM) {
6019 fprintf(logfile, "----------------\n");
6020 fprintf(logfile, "nip=" ADDRX " super=%d ir=%d\n",
6021 ctx.nip, 1 - msr_pr, msr_ir);
6024 ctx.opcode = ldl_code(ctx.nip);
6026 ctx.opcode = ((ctx.opcode & 0xFF000000) >> 24) |
6027 ((ctx.opcode & 0x00FF0000) >> 8) |
6028 ((ctx.opcode & 0x0000FF00) << 8) |
6029 ((ctx.opcode & 0x000000FF) << 24);
6031 #if defined PPC_DEBUG_DISAS
6032 if (loglevel & CPU_LOG_TB_IN_ASM) {
6033 fprintf(logfile, "translate opcode %08x (%02x %02x %02x) (%s)\n",
6034 ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
6035 opc3(ctx.opcode), msr_le ? "little" : "big");
6039 table = env->opcodes;
6040 handler = table[opc1(ctx.opcode)];
6041 if (is_indirect_opcode(handler)) {
6042 table = ind_table(handler);
6043 handler = table[opc2(ctx.opcode)];
6044 if (is_indirect_opcode(handler)) {
6045 table = ind_table(handler);
6046 handler = table[opc3(ctx.opcode)];
6049 /* Is opcode *REALLY* valid ? */
6050 if (unlikely(handler->handler == &gen_invalid)) {
6051 if (loglevel != 0) {
6052 fprintf(logfile, "invalid/unsupported opcode: "
6053 "%02x - %02x - %02x (%08x) 0x" ADDRX " %d\n",
6054 opc1(ctx.opcode), opc2(ctx.opcode),
6055 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, msr_ir);
6057 printf("invalid/unsupported opcode: "
6058 "%02x - %02x - %02x (%08x) 0x" ADDRX " %d\n",
6059 opc1(ctx.opcode), opc2(ctx.opcode),
6060 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, msr_ir);
6063 if (unlikely((ctx.opcode & handler->inval) != 0)) {
6064 if (loglevel != 0) {
6065 fprintf(logfile, "invalid bits: %08x for opcode: "
6066 "%02x - %02x - %02x (%08x) 0x" ADDRX "\n",
6067 ctx.opcode & handler->inval, opc1(ctx.opcode),
6068 opc2(ctx.opcode), opc3(ctx.opcode),
6069 ctx.opcode, ctx.nip - 4);
6071 printf("invalid bits: %08x for opcode: "
6072 "%02x - %02x - %02x (%08x) 0x" ADDRX "\n",
6073 ctx.opcode & handler->inval, opc1(ctx.opcode),
6074 opc2(ctx.opcode), opc3(ctx.opcode),
6075 ctx.opcode, ctx.nip - 4);
6077 GEN_EXCP_INVAL(ctxp);
6081 (*(handler->handler))(&ctx);
6082 #if defined(DO_PPC_STATISTICS)
6085 /* Check trace mode exceptions */
6086 #if 0 // XXX: buggy on embedded PowerPC
6087 if (unlikely((msr_be && ctx.exception == POWERPC_EXCP_BRANCH) ||
6088 /* Check in single step trace mode
6089 * we need to stop except if:
6090 * - rfi, trap or syscall
6091 * - first instruction of an exception handler
6093 (msr_se && (ctx.nip < 0x100 ||
6095 (ctx.nip & 0xFC) != 0x04) &&
6096 #if defined(CONFIG_USER_ONLY)
6097 ctx.exception != POWERPC_EXCP_SYSCALL_USER &&
6099 ctx.exception != POWERPC_EXCP_SYSCALL &&
6101 ctx.exception != POWERPC_EXCP_TRAP))) {
6102 GEN_EXCP(ctxp, POWERPC_EXCP_TRACE, 0);
6105 /* if we reach a page boundary or are single stepping, stop
6108 if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
6109 (env->singlestep_enabled))) {
6112 #if defined (DO_SINGLE_STEP)
6116 if (ctx.exception == POWERPC_EXCP_NONE) {
6117 gen_goto_tb(&ctx, 0, ctx.nip);
6118 } else if (ctx.exception != POWERPC_EXCP_BRANCH) {
6120 /* Generate the return instruction */
6123 *gen_opc_ptr = INDEX_op_end;
6124 if (unlikely(search_pc)) {
6125 j = gen_opc_ptr - gen_opc_buf;
6128 gen_opc_instr_start[lj++] = 0;
6130 tb->size = ctx.nip - pc_start;
6132 #if defined(DEBUG_DISAS)
6133 if (loglevel & CPU_LOG_TB_CPU) {
6134 fprintf(logfile, "---------------- excp: %04x\n", ctx.exception);
6135 cpu_dump_state(env, logfile, fprintf, 0);
6137 if (loglevel & CPU_LOG_TB_IN_ASM) {
6139 flags = env->bfd_mach;
6140 flags |= msr_le << 16;
6141 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
6142 target_disas(logfile, pc_start, ctx.nip - pc_start, flags);
6143 fprintf(logfile, "\n");
6145 if (loglevel & CPU_LOG_TB_OP) {
6146 fprintf(logfile, "OP:\n");
6147 dump_ops(gen_opc_buf, gen_opparam_buf);
6148 fprintf(logfile, "\n");
6154 int gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
6156 return gen_intermediate_code_internal(env, tb, 0);
6159 int gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
6161 return gen_intermediate_code_internal(env, tb, 1);