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,
481 /* New wait instruction (PowerPC 2.0x) */
482 PPC_WAIT = 0x0000100000000000ULL,
485 /*****************************************************************************/
486 /* PowerPC instructions table */
487 #if HOST_LONG_BITS == 64
492 #if defined(__APPLE__)
493 #define OPCODES_SECTION \
494 __attribute__ ((section("__TEXT,__opcodes"), unused, aligned (OPC_ALIGN) ))
496 #define OPCODES_SECTION \
497 __attribute__ ((section(".opcodes"), unused, aligned (OPC_ALIGN) ))
500 #if defined(DO_PPC_STATISTICS)
501 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
502 OPCODES_SECTION opcode_t opc_##name = { \
510 .handler = &gen_##name, \
511 .oname = stringify(name), \
513 .oname = stringify(name), \
516 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
517 OPCODES_SECTION opcode_t opc_##name = { \
525 .handler = &gen_##name, \
527 .oname = stringify(name), \
531 #define GEN_OPCODE_MARK(name) \
532 OPCODES_SECTION opcode_t opc_##name = { \
538 .inval = 0x00000000, \
542 .oname = stringify(name), \
545 /* Start opcode list */
546 GEN_OPCODE_MARK(start);
548 /* Invalid instruction */
549 GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE)
554 static opc_handler_t invalid_handler = {
557 .handler = gen_invalid,
560 /*** Integer arithmetic ***/
561 #define __GEN_INT_ARITH2(name, opc1, opc2, opc3, inval, type) \
562 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
564 gen_op_load_gpr_T0(rA(ctx->opcode)); \
565 gen_op_load_gpr_T1(rB(ctx->opcode)); \
567 gen_op_store_T0_gpr(rD(ctx->opcode)); \
568 if (unlikely(Rc(ctx->opcode) != 0)) \
572 #define __GEN_INT_ARITH2_O(name, opc1, opc2, opc3, inval, type) \
573 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
575 gen_op_load_gpr_T0(rA(ctx->opcode)); \
576 gen_op_load_gpr_T1(rB(ctx->opcode)); \
578 gen_op_store_T0_gpr(rD(ctx->opcode)); \
579 if (unlikely(Rc(ctx->opcode) != 0)) \
583 #define __GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
584 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
586 gen_op_load_gpr_T0(rA(ctx->opcode)); \
588 gen_op_store_T0_gpr(rD(ctx->opcode)); \
589 if (unlikely(Rc(ctx->opcode) != 0)) \
592 #define __GEN_INT_ARITH1_O(name, opc1, opc2, opc3, type) \
593 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
595 gen_op_load_gpr_T0(rA(ctx->opcode)); \
597 gen_op_store_T0_gpr(rD(ctx->opcode)); \
598 if (unlikely(Rc(ctx->opcode) != 0)) \
602 /* Two operands arithmetic functions */
603 #define GEN_INT_ARITH2(name, opc1, opc2, opc3, type) \
604 __GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000000, type) \
605 __GEN_INT_ARITH2_O(name##o, opc1, opc2, opc3 | 0x10, 0x00000000, type)
607 /* Two operands arithmetic functions with no overflow allowed */
608 #define GEN_INT_ARITHN(name, opc1, opc2, opc3, type) \
609 __GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000400, type)
611 /* One operand arithmetic functions */
612 #define GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
613 __GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
614 __GEN_INT_ARITH1_O(name##o, opc1, opc2, opc3 | 0x10, type)
616 #if defined(TARGET_PPC64)
617 #define __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, inval, type) \
618 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
620 gen_op_load_gpr_T0(rA(ctx->opcode)); \
621 gen_op_load_gpr_T1(rB(ctx->opcode)); \
623 gen_op_##name##_64(); \
626 gen_op_store_T0_gpr(rD(ctx->opcode)); \
627 if (unlikely(Rc(ctx->opcode) != 0)) \
631 #define __GEN_INT_ARITH2_O_64(name, opc1, opc2, opc3, inval, type) \
632 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
634 gen_op_load_gpr_T0(rA(ctx->opcode)); \
635 gen_op_load_gpr_T1(rB(ctx->opcode)); \
637 gen_op_##name##_64(); \
640 gen_op_store_T0_gpr(rD(ctx->opcode)); \
641 if (unlikely(Rc(ctx->opcode) != 0)) \
645 #define __GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
646 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
648 gen_op_load_gpr_T0(rA(ctx->opcode)); \
650 gen_op_##name##_64(); \
653 gen_op_store_T0_gpr(rD(ctx->opcode)); \
654 if (unlikely(Rc(ctx->opcode) != 0)) \
657 #define __GEN_INT_ARITH1_O_64(name, opc1, opc2, opc3, type) \
658 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
660 gen_op_load_gpr_T0(rA(ctx->opcode)); \
662 gen_op_##name##_64(); \
665 gen_op_store_T0_gpr(rD(ctx->opcode)); \
666 if (unlikely(Rc(ctx->opcode) != 0)) \
670 /* Two operands arithmetic functions */
671 #define GEN_INT_ARITH2_64(name, opc1, opc2, opc3, type) \
672 __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, 0x00000000, type) \
673 __GEN_INT_ARITH2_O_64(name##o, opc1, opc2, opc3 | 0x10, 0x00000000, type)
675 /* Two operands arithmetic functions with no overflow allowed */
676 #define GEN_INT_ARITHN_64(name, opc1, opc2, opc3, type) \
677 __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, 0x00000400, type)
679 /* One operand arithmetic functions */
680 #define GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
681 __GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
682 __GEN_INT_ARITH1_O_64(name##o, opc1, opc2, opc3 | 0x10, type)
684 #define GEN_INT_ARITH2_64 GEN_INT_ARITH2
685 #define GEN_INT_ARITHN_64 GEN_INT_ARITHN
686 #define GEN_INT_ARITH1_64 GEN_INT_ARITH1
689 /* add add. addo addo. */
690 static inline void gen_op_addo (void)
696 #if defined(TARGET_PPC64)
697 #define gen_op_add_64 gen_op_add
698 static inline void gen_op_addo_64 (void)
702 gen_op_check_addo_64();
705 GEN_INT_ARITH2_64 (add, 0x1F, 0x0A, 0x08, PPC_INTEGER);
706 /* addc addc. addco addco. */
707 static inline void gen_op_addc (void)
713 static inline void gen_op_addco (void)
720 #if defined(TARGET_PPC64)
721 static inline void gen_op_addc_64 (void)
725 gen_op_check_addc_64();
727 static inline void gen_op_addco_64 (void)
731 gen_op_check_addc_64();
732 gen_op_check_addo_64();
735 GEN_INT_ARITH2_64 (addc, 0x1F, 0x0A, 0x00, PPC_INTEGER);
736 /* adde adde. addeo addeo. */
737 static inline void gen_op_addeo (void)
743 #if defined(TARGET_PPC64)
744 static inline void gen_op_addeo_64 (void)
748 gen_op_check_addo_64();
751 GEN_INT_ARITH2_64 (adde, 0x1F, 0x0A, 0x04, PPC_INTEGER);
752 /* addme addme. addmeo addmeo. */
753 static inline void gen_op_addme (void)
758 #if defined(TARGET_PPC64)
759 static inline void gen_op_addme_64 (void)
765 GEN_INT_ARITH1_64 (addme, 0x1F, 0x0A, 0x07, PPC_INTEGER);
766 /* addze addze. addzeo addzeo. */
767 static inline void gen_op_addze (void)
773 static inline void gen_op_addzeo (void)
780 #if defined(TARGET_PPC64)
781 static inline void gen_op_addze_64 (void)
785 gen_op_check_addc_64();
787 static inline void gen_op_addzeo_64 (void)
791 gen_op_check_addc_64();
792 gen_op_check_addo_64();
795 GEN_INT_ARITH1_64 (addze, 0x1F, 0x0A, 0x06, PPC_INTEGER);
796 /* divw divw. divwo divwo. */
797 GEN_INT_ARITH2 (divw, 0x1F, 0x0B, 0x0F, PPC_INTEGER);
798 /* divwu divwu. divwuo divwuo. */
799 GEN_INT_ARITH2 (divwu, 0x1F, 0x0B, 0x0E, PPC_INTEGER);
801 GEN_INT_ARITHN (mulhw, 0x1F, 0x0B, 0x02, PPC_INTEGER);
803 GEN_INT_ARITHN (mulhwu, 0x1F, 0x0B, 0x00, PPC_INTEGER);
804 /* mullw mullw. mullwo mullwo. */
805 GEN_INT_ARITH2 (mullw, 0x1F, 0x0B, 0x07, PPC_INTEGER);
806 /* neg neg. nego nego. */
807 GEN_INT_ARITH1_64 (neg, 0x1F, 0x08, 0x03, PPC_INTEGER);
808 /* subf subf. subfo subfo. */
809 static inline void gen_op_subfo (void)
813 gen_op_check_subfo();
815 #if defined(TARGET_PPC64)
816 #define gen_op_subf_64 gen_op_subf
817 static inline void gen_op_subfo_64 (void)
821 gen_op_check_subfo_64();
824 GEN_INT_ARITH2_64 (subf, 0x1F, 0x08, 0x01, PPC_INTEGER);
825 /* subfc subfc. subfco subfco. */
826 static inline void gen_op_subfc (void)
829 gen_op_check_subfc();
831 static inline void gen_op_subfco (void)
835 gen_op_check_subfc();
836 gen_op_check_subfo();
838 #if defined(TARGET_PPC64)
839 static inline void gen_op_subfc_64 (void)
842 gen_op_check_subfc_64();
844 static inline void gen_op_subfco_64 (void)
848 gen_op_check_subfc_64();
849 gen_op_check_subfo_64();
852 GEN_INT_ARITH2_64 (subfc, 0x1F, 0x08, 0x00, PPC_INTEGER);
853 /* subfe subfe. subfeo subfeo. */
854 static inline void gen_op_subfeo (void)
858 gen_op_check_subfo();
860 #if defined(TARGET_PPC64)
861 #define gen_op_subfe_64 gen_op_subfe
862 static inline void gen_op_subfeo_64 (void)
866 gen_op_check_subfo_64();
869 GEN_INT_ARITH2_64 (subfe, 0x1F, 0x08, 0x04, PPC_INTEGER);
870 /* subfme subfme. subfmeo subfmeo. */
871 GEN_INT_ARITH1_64 (subfme, 0x1F, 0x08, 0x07, PPC_INTEGER);
872 /* subfze subfze. subfzeo subfzeo. */
873 GEN_INT_ARITH1_64 (subfze, 0x1F, 0x08, 0x06, PPC_INTEGER);
875 GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
877 target_long simm = SIMM(ctx->opcode);
879 if (rA(ctx->opcode) == 0) {
883 gen_op_load_gpr_T0(rA(ctx->opcode));
884 if (likely(simm != 0))
887 gen_op_store_T0_gpr(rD(ctx->opcode));
890 GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
892 target_long simm = SIMM(ctx->opcode);
894 gen_op_load_gpr_T0(rA(ctx->opcode));
895 if (likely(simm != 0)) {
898 #if defined(TARGET_PPC64)
900 gen_op_check_addc_64();
905 gen_op_clear_xer_ca();
907 gen_op_store_T0_gpr(rD(ctx->opcode));
910 GEN_HANDLER(addic_, 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
912 target_long simm = SIMM(ctx->opcode);
914 gen_op_load_gpr_T0(rA(ctx->opcode));
915 if (likely(simm != 0)) {
918 #if defined(TARGET_PPC64)
920 gen_op_check_addc_64();
925 gen_op_clear_xer_ca();
927 gen_op_store_T0_gpr(rD(ctx->opcode));
931 GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
933 target_long simm = SIMM(ctx->opcode);
935 if (rA(ctx->opcode) == 0) {
937 gen_set_T0(simm << 16);
939 gen_op_load_gpr_T0(rA(ctx->opcode));
940 if (likely(simm != 0))
941 gen_op_addi(simm << 16);
943 gen_op_store_T0_gpr(rD(ctx->opcode));
946 GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
948 gen_op_load_gpr_T0(rA(ctx->opcode));
949 gen_op_mulli(SIMM(ctx->opcode));
950 gen_op_store_T0_gpr(rD(ctx->opcode));
953 GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
955 gen_op_load_gpr_T0(rA(ctx->opcode));
956 #if defined(TARGET_PPC64)
958 gen_op_subfic_64(SIMM(ctx->opcode));
961 gen_op_subfic(SIMM(ctx->opcode));
962 gen_op_store_T0_gpr(rD(ctx->opcode));
965 #if defined(TARGET_PPC64)
967 GEN_INT_ARITHN (mulhd, 0x1F, 0x09, 0x02, PPC_64B);
969 GEN_INT_ARITHN (mulhdu, 0x1F, 0x09, 0x00, PPC_64B);
970 /* mulld mulld. mulldo mulldo. */
971 GEN_INT_ARITH2 (mulld, 0x1F, 0x09, 0x07, PPC_64B);
972 /* divd divd. divdo divdo. */
973 GEN_INT_ARITH2 (divd, 0x1F, 0x09, 0x0F, PPC_64B);
974 /* divdu divdu. divduo divduo. */
975 GEN_INT_ARITH2 (divdu, 0x1F, 0x09, 0x0E, PPC_64B);
978 /*** Integer comparison ***/
979 #if defined(TARGET_PPC64)
980 #define GEN_CMP(name, opc, type) \
981 GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, type) \
983 gen_op_load_gpr_T0(rA(ctx->opcode)); \
984 gen_op_load_gpr_T1(rB(ctx->opcode)); \
985 if (ctx->sf_mode && (ctx->opcode & 0x00200000)) \
986 gen_op_##name##_64(); \
989 gen_op_store_T0_crf(crfD(ctx->opcode)); \
992 #define GEN_CMP(name, opc, type) \
993 GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, type) \
995 gen_op_load_gpr_T0(rA(ctx->opcode)); \
996 gen_op_load_gpr_T1(rB(ctx->opcode)); \
998 gen_op_store_T0_crf(crfD(ctx->opcode)); \
1003 GEN_CMP(cmp, 0x00, PPC_INTEGER);
1005 GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER)
1007 gen_op_load_gpr_T0(rA(ctx->opcode));
1008 #if defined(TARGET_PPC64)
1009 if (ctx->sf_mode && (ctx->opcode & 0x00200000))
1010 gen_op_cmpi_64(SIMM(ctx->opcode));
1013 gen_op_cmpi(SIMM(ctx->opcode));
1014 gen_op_store_T0_crf(crfD(ctx->opcode));
1017 GEN_CMP(cmpl, 0x01, PPC_INTEGER);
1019 GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER)
1021 gen_op_load_gpr_T0(rA(ctx->opcode));
1022 #if defined(TARGET_PPC64)
1023 if (ctx->sf_mode && (ctx->opcode & 0x00200000))
1024 gen_op_cmpli_64(UIMM(ctx->opcode));
1027 gen_op_cmpli(UIMM(ctx->opcode));
1028 gen_op_store_T0_crf(crfD(ctx->opcode));
1031 /* isel (PowerPC 2.03 specification) */
1032 GEN_HANDLER(isel, 0x1F, 0x0F, 0x00, 0x00000001, PPC_203)
1034 uint32_t bi = rC(ctx->opcode);
1037 if (rA(ctx->opcode) == 0) {
1040 gen_op_load_gpr_T1(rA(ctx->opcode));
1042 gen_op_load_gpr_T2(rB(ctx->opcode));
1043 mask = 1 << (3 - (bi & 0x03));
1044 gen_op_load_crf_T0(bi >> 2);
1045 gen_op_test_true(mask);
1047 gen_op_store_T0_gpr(rD(ctx->opcode));
1050 /*** Integer logical ***/
1051 #define __GEN_LOGICAL2(name, opc2, opc3, type) \
1052 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000000, type) \
1054 gen_op_load_gpr_T0(rS(ctx->opcode)); \
1055 gen_op_load_gpr_T1(rB(ctx->opcode)); \
1057 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1058 if (unlikely(Rc(ctx->opcode) != 0)) \
1061 #define GEN_LOGICAL2(name, opc, type) \
1062 __GEN_LOGICAL2(name, 0x1C, opc, type)
1064 #define GEN_LOGICAL1(name, opc, type) \
1065 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type) \
1067 gen_op_load_gpr_T0(rS(ctx->opcode)); \
1069 gen_op_store_T0_gpr(rA(ctx->opcode)); \
1070 if (unlikely(Rc(ctx->opcode) != 0)) \
1075 GEN_LOGICAL2(and, 0x00, PPC_INTEGER);
1077 GEN_LOGICAL2(andc, 0x01, PPC_INTEGER);
1079 GEN_HANDLER(andi_, 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1081 gen_op_load_gpr_T0(rS(ctx->opcode));
1082 gen_op_andi_T0(UIMM(ctx->opcode));
1083 gen_op_store_T0_gpr(rA(ctx->opcode));
1087 GEN_HANDLER(andis_, 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1089 gen_op_load_gpr_T0(rS(ctx->opcode));
1090 gen_op_andi_T0(UIMM(ctx->opcode) << 16);
1091 gen_op_store_T0_gpr(rA(ctx->opcode));
1096 GEN_LOGICAL1(cntlzw, 0x00, PPC_INTEGER);
1098 GEN_LOGICAL2(eqv, 0x08, PPC_INTEGER);
1099 /* extsb & extsb. */
1100 GEN_LOGICAL1(extsb, 0x1D, PPC_INTEGER);
1101 /* extsh & extsh. */
1102 GEN_LOGICAL1(extsh, 0x1C, PPC_INTEGER);
1104 GEN_LOGICAL2(nand, 0x0E, PPC_INTEGER);
1106 GEN_LOGICAL2(nor, 0x03, PPC_INTEGER);
1109 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER)
1113 rs = rS(ctx->opcode);
1114 ra = rA(ctx->opcode);
1115 rb = rB(ctx->opcode);
1116 /* Optimisation for mr. ri case */
1117 if (rs != ra || rs != rb) {
1118 gen_op_load_gpr_T0(rs);
1120 gen_op_load_gpr_T1(rb);
1123 gen_op_store_T0_gpr(ra);
1124 if (unlikely(Rc(ctx->opcode) != 0))
1126 } else if (unlikely(Rc(ctx->opcode) != 0)) {
1127 gen_op_load_gpr_T0(rs);
1129 #if defined(TARGET_PPC64)
1133 /* Set process priority to low */
1134 gen_op_store_pri(2);
1137 /* Set process priority to medium-low */
1138 gen_op_store_pri(3);
1141 /* Set process priority to normal */
1142 gen_op_store_pri(4);
1153 GEN_LOGICAL2(orc, 0x0C, PPC_INTEGER);
1155 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER)
1157 gen_op_load_gpr_T0(rS(ctx->opcode));
1158 /* Optimisation for "set to zero" case */
1159 if (rS(ctx->opcode) != rB(ctx->opcode)) {
1160 gen_op_load_gpr_T1(rB(ctx->opcode));
1165 gen_op_store_T0_gpr(rA(ctx->opcode));
1166 if (unlikely(Rc(ctx->opcode) != 0))
1170 GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1172 target_ulong uimm = UIMM(ctx->opcode);
1174 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1176 /* XXX: should handle special NOPs for POWER series */
1179 gen_op_load_gpr_T0(rS(ctx->opcode));
1180 if (likely(uimm != 0))
1182 gen_op_store_T0_gpr(rA(ctx->opcode));
1185 GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1187 target_ulong uimm = UIMM(ctx->opcode);
1189 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1193 gen_op_load_gpr_T0(rS(ctx->opcode));
1194 if (likely(uimm != 0))
1195 gen_op_ori(uimm << 16);
1196 gen_op_store_T0_gpr(rA(ctx->opcode));
1199 GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1201 target_ulong uimm = UIMM(ctx->opcode);
1203 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1207 gen_op_load_gpr_T0(rS(ctx->opcode));
1208 if (likely(uimm != 0))
1210 gen_op_store_T0_gpr(rA(ctx->opcode));
1214 GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1216 target_ulong uimm = UIMM(ctx->opcode);
1218 if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) {
1222 gen_op_load_gpr_T0(rS(ctx->opcode));
1223 if (likely(uimm != 0))
1224 gen_op_xori(uimm << 16);
1225 gen_op_store_T0_gpr(rA(ctx->opcode));
1228 /* popcntb : PowerPC 2.03 specification */
1229 GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_203)
1231 gen_op_load_gpr_T0(rS(ctx->opcode));
1232 #if defined(TARGET_PPC64)
1234 gen_op_popcntb_64();
1238 gen_op_store_T0_gpr(rA(ctx->opcode));
1241 #if defined(TARGET_PPC64)
1242 /* extsw & extsw. */
1243 GEN_LOGICAL1(extsw, 0x1E, PPC_64B);
1245 GEN_LOGICAL1(cntlzd, 0x01, PPC_64B);
1248 /*** Integer rotate ***/
1249 /* rlwimi & rlwimi. */
1250 GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1253 uint32_t mb, me, sh;
1255 mb = MB(ctx->opcode);
1256 me = ME(ctx->opcode);
1257 sh = SH(ctx->opcode);
1258 if (likely(sh == 0)) {
1259 if (likely(mb == 0 && me == 31)) {
1260 gen_op_load_gpr_T0(rS(ctx->opcode));
1262 } else if (likely(mb == 31 && me == 0)) {
1263 gen_op_load_gpr_T0(rA(ctx->opcode));
1266 gen_op_load_gpr_T0(rS(ctx->opcode));
1267 gen_op_load_gpr_T1(rA(ctx->opcode));
1270 gen_op_load_gpr_T0(rS(ctx->opcode));
1271 gen_op_load_gpr_T1(rA(ctx->opcode));
1272 gen_op_rotli32_T0(SH(ctx->opcode));
1274 #if defined(TARGET_PPC64)
1278 mask = MASK(mb, me);
1279 gen_op_andi_T0(mask);
1280 gen_op_andi_T1(~mask);
1283 gen_op_store_T0_gpr(rA(ctx->opcode));
1284 if (unlikely(Rc(ctx->opcode) != 0))
1287 /* rlwinm & rlwinm. */
1288 GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1290 uint32_t mb, me, sh;
1292 sh = SH(ctx->opcode);
1293 mb = MB(ctx->opcode);
1294 me = ME(ctx->opcode);
1295 gen_op_load_gpr_T0(rS(ctx->opcode));
1296 if (likely(sh == 0)) {
1299 if (likely(mb == 0)) {
1300 if (likely(me == 31)) {
1301 gen_op_rotli32_T0(sh);
1303 } else if (likely(me == (31 - sh))) {
1307 } else if (likely(me == 31)) {
1308 if (likely(sh == (32 - mb))) {
1313 gen_op_rotli32_T0(sh);
1315 #if defined(TARGET_PPC64)
1319 gen_op_andi_T0(MASK(mb, me));
1321 gen_op_store_T0_gpr(rA(ctx->opcode));
1322 if (unlikely(Rc(ctx->opcode) != 0))
1325 /* rlwnm & rlwnm. */
1326 GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
1330 mb = MB(ctx->opcode);
1331 me = ME(ctx->opcode);
1332 gen_op_load_gpr_T0(rS(ctx->opcode));
1333 gen_op_load_gpr_T1(rB(ctx->opcode));
1334 gen_op_rotl32_T0_T1();
1335 if (unlikely(mb != 0 || me != 31)) {
1336 #if defined(TARGET_PPC64)
1340 gen_op_andi_T0(MASK(mb, me));
1342 gen_op_store_T0_gpr(rA(ctx->opcode));
1343 if (unlikely(Rc(ctx->opcode) != 0))
1347 #if defined(TARGET_PPC64)
1348 #define GEN_PPC64_R2(name, opc1, opc2) \
1349 GEN_HANDLER(name##0, opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1351 gen_##name(ctx, 0); \
1353 GEN_HANDLER(name##1, opc1, opc2 | 0x10, 0xFF, 0x00000000, PPC_64B) \
1355 gen_##name(ctx, 1); \
1357 #define GEN_PPC64_R4(name, opc1, opc2) \
1358 GEN_HANDLER(name##0, opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1360 gen_##name(ctx, 0, 0); \
1362 GEN_HANDLER(name##1, opc1, opc2 | 0x01, 0xFF, 0x00000000, PPC_64B) \
1364 gen_##name(ctx, 0, 1); \
1366 GEN_HANDLER(name##2, opc1, opc2 | 0x10, 0xFF, 0x00000000, PPC_64B) \
1368 gen_##name(ctx, 1, 0); \
1370 GEN_HANDLER(name##3, opc1, opc2 | 0x11, 0xFF, 0x00000000, PPC_64B) \
1372 gen_##name(ctx, 1, 1); \
1375 static inline void gen_andi_T0_64 (DisasContext *ctx, uint64_t mask)
1378 gen_op_andi_T0_64(mask >> 32, mask & 0xFFFFFFFF);
1380 gen_op_andi_T0(mask);
1383 static inline void gen_andi_T1_64 (DisasContext *ctx, uint64_t mask)
1386 gen_op_andi_T1_64(mask >> 32, mask & 0xFFFFFFFF);
1388 gen_op_andi_T1(mask);
1391 static inline void gen_rldinm (DisasContext *ctx, uint32_t mb, uint32_t me,
1394 gen_op_load_gpr_T0(rS(ctx->opcode));
1395 if (likely(sh == 0)) {
1398 if (likely(mb == 0)) {
1399 if (likely(me == 63)) {
1400 gen_op_rotli64_T0(sh);
1402 } else if (likely(me == (63 - sh))) {
1406 } else if (likely(me == 63)) {
1407 if (likely(sh == (64 - mb))) {
1408 gen_op_srli_T0_64(mb);
1412 gen_op_rotli64_T0(sh);
1414 gen_andi_T0_64(ctx, MASK(mb, me));
1416 gen_op_store_T0_gpr(rA(ctx->opcode));
1417 if (unlikely(Rc(ctx->opcode) != 0))
1420 /* rldicl - rldicl. */
1421 static inline void gen_rldicl (DisasContext *ctx, int mbn, int shn)
1425 sh = SH(ctx->opcode) | (shn << 5);
1426 mb = MB(ctx->opcode) | (mbn << 5);
1427 gen_rldinm(ctx, mb, 63, sh);
1429 GEN_PPC64_R4(rldicl, 0x1E, 0x00);
1430 /* rldicr - rldicr. */
1431 static inline void gen_rldicr (DisasContext *ctx, int men, int shn)
1435 sh = SH(ctx->opcode) | (shn << 5);
1436 me = MB(ctx->opcode) | (men << 5);
1437 gen_rldinm(ctx, 0, me, sh);
1439 GEN_PPC64_R4(rldicr, 0x1E, 0x02);
1440 /* rldic - rldic. */
1441 static inline void gen_rldic (DisasContext *ctx, int mbn, int shn)
1445 sh = SH(ctx->opcode) | (shn << 5);
1446 mb = MB(ctx->opcode) | (mbn << 5);
1447 gen_rldinm(ctx, mb, 63 - sh, sh);
1449 GEN_PPC64_R4(rldic, 0x1E, 0x04);
1451 static inline void gen_rldnm (DisasContext *ctx, uint32_t mb, uint32_t me)
1453 gen_op_load_gpr_T0(rS(ctx->opcode));
1454 gen_op_load_gpr_T1(rB(ctx->opcode));
1455 gen_op_rotl64_T0_T1();
1456 if (unlikely(mb != 0 || me != 63)) {
1457 gen_andi_T0_64(ctx, MASK(mb, me));
1459 gen_op_store_T0_gpr(rA(ctx->opcode));
1460 if (unlikely(Rc(ctx->opcode) != 0))
1464 /* rldcl - rldcl. */
1465 static inline void gen_rldcl (DisasContext *ctx, int mbn)
1469 mb = MB(ctx->opcode) | (mbn << 5);
1470 gen_rldnm(ctx, mb, 63);
1472 GEN_PPC64_R2(rldcl, 0x1E, 0x08);
1473 /* rldcr - rldcr. */
1474 static inline void gen_rldcr (DisasContext *ctx, int men)
1478 me = MB(ctx->opcode) | (men << 5);
1479 gen_rldnm(ctx, 0, me);
1481 GEN_PPC64_R2(rldcr, 0x1E, 0x09);
1482 /* rldimi - rldimi. */
1483 static inline void gen_rldimi (DisasContext *ctx, int mbn, int shn)
1488 sh = SH(ctx->opcode) | (shn << 5);
1489 mb = MB(ctx->opcode) | (mbn << 5);
1490 if (likely(sh == 0)) {
1491 if (likely(mb == 0)) {
1492 gen_op_load_gpr_T0(rS(ctx->opcode));
1494 } else if (likely(mb == 63)) {
1495 gen_op_load_gpr_T0(rA(ctx->opcode));
1498 gen_op_load_gpr_T0(rS(ctx->opcode));
1499 gen_op_load_gpr_T1(rA(ctx->opcode));
1502 gen_op_load_gpr_T0(rS(ctx->opcode));
1503 gen_op_load_gpr_T1(rA(ctx->opcode));
1504 gen_op_rotli64_T0(sh);
1506 mask = MASK(mb, 63 - sh);
1507 gen_andi_T0_64(ctx, mask);
1508 gen_andi_T1_64(ctx, ~mask);
1511 gen_op_store_T0_gpr(rA(ctx->opcode));
1512 if (unlikely(Rc(ctx->opcode) != 0))
1515 GEN_PPC64_R4(rldimi, 0x1E, 0x06);
1518 /*** Integer shift ***/
1520 __GEN_LOGICAL2(slw, 0x18, 0x00, PPC_INTEGER);
1522 __GEN_LOGICAL2(sraw, 0x18, 0x18, PPC_INTEGER);
1523 /* srawi & srawi. */
1524 GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER)
1527 gen_op_load_gpr_T0(rS(ctx->opcode));
1528 if (SH(ctx->opcode) != 0) {
1529 gen_op_move_T1_T0();
1530 mb = 32 - SH(ctx->opcode);
1532 #if defined(TARGET_PPC64)
1536 gen_op_srawi(SH(ctx->opcode), MASK(mb, me));
1538 gen_op_store_T0_gpr(rA(ctx->opcode));
1539 if (unlikely(Rc(ctx->opcode) != 0))
1543 __GEN_LOGICAL2(srw, 0x18, 0x10, PPC_INTEGER);
1545 #if defined(TARGET_PPC64)
1547 __GEN_LOGICAL2(sld, 0x1B, 0x00, PPC_64B);
1549 __GEN_LOGICAL2(srad, 0x1A, 0x18, PPC_64B);
1550 /* sradi & sradi. */
1551 static inline void gen_sradi (DisasContext *ctx, int n)
1556 gen_op_load_gpr_T0(rS(ctx->opcode));
1557 sh = SH(ctx->opcode) + (n << 5);
1559 gen_op_move_T1_T0();
1560 mb = 64 - SH(ctx->opcode);
1562 mask = MASK(mb, me);
1563 gen_op_sradi(sh, mask >> 32, mask);
1565 gen_op_store_T0_gpr(rA(ctx->opcode));
1566 if (unlikely(Rc(ctx->opcode) != 0))
1569 GEN_HANDLER(sradi0, 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B)
1573 GEN_HANDLER(sradi1, 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B)
1578 __GEN_LOGICAL2(srd, 0x1B, 0x10, PPC_64B);
1581 /*** Floating-Point arithmetic ***/
1582 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, type) \
1583 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type) \
1585 if (unlikely(!ctx->fpu_enabled)) { \
1586 GEN_EXCP_NO_FP(ctx); \
1589 gen_op_reset_scrfx(); \
1590 gen_op_load_fpr_FT0(rA(ctx->opcode)); \
1591 gen_op_load_fpr_FT1(rC(ctx->opcode)); \
1592 gen_op_load_fpr_FT2(rB(ctx->opcode)); \
1597 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1598 if (unlikely(Rc(ctx->opcode) != 0)) \
1602 #define GEN_FLOAT_ACB(name, op2, type) \
1603 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, type); \
1604 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, type);
1606 #define _GEN_FLOAT_AB(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(rB(ctx->opcode)); \
1620 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1621 if (unlikely(Rc(ctx->opcode) != 0)) \
1624 #define GEN_FLOAT_AB(name, op2, inval) \
1625 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0); \
1626 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1);
1628 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat) \
1629 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, PPC_FLOAT) \
1631 if (unlikely(!ctx->fpu_enabled)) { \
1632 GEN_EXCP_NO_FP(ctx); \
1635 gen_op_reset_scrfx(); \
1636 gen_op_load_fpr_FT0(rA(ctx->opcode)); \
1637 gen_op_load_fpr_FT1(rC(ctx->opcode)); \
1642 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1643 if (unlikely(Rc(ctx->opcode) != 0)) \
1646 #define GEN_FLOAT_AC(name, op2, inval) \
1647 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0); \
1648 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1);
1650 #define GEN_FLOAT_B(name, op2, op3, type) \
1651 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type) \
1653 if (unlikely(!ctx->fpu_enabled)) { \
1654 GEN_EXCP_NO_FP(ctx); \
1657 gen_op_reset_scrfx(); \
1658 gen_op_load_fpr_FT0(rB(ctx->opcode)); \
1660 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1661 if (unlikely(Rc(ctx->opcode) != 0)) \
1665 #define GEN_FLOAT_BS(name, op1, op2, type) \
1666 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type) \
1668 if (unlikely(!ctx->fpu_enabled)) { \
1669 GEN_EXCP_NO_FP(ctx); \
1672 gen_op_reset_scrfx(); \
1673 gen_op_load_fpr_FT0(rB(ctx->opcode)); \
1675 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
1676 if (unlikely(Rc(ctx->opcode) != 0)) \
1681 GEN_FLOAT_AB(add, 0x15, 0x000007C0);
1683 GEN_FLOAT_AB(div, 0x12, 0x000007C0);
1685 GEN_FLOAT_AC(mul, 0x19, 0x0000F800);
1688 GEN_FLOAT_BS(re, 0x3F, 0x18, PPC_FLOAT_EXT);
1691 GEN_FLOAT_BS(res, 0x3B, 0x18, PPC_FLOAT_FRES);
1694 GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, PPC_FLOAT_FRSQRTE);
1697 _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, PPC_FLOAT_FSEL);
1699 GEN_FLOAT_AB(sub, 0x14, 0x000007C0);
1702 GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT)
1704 if (unlikely(!ctx->fpu_enabled)) {
1705 GEN_EXCP_NO_FP(ctx);
1708 gen_op_reset_scrfx();
1709 gen_op_load_fpr_FT0(rB(ctx->opcode));
1711 gen_op_store_FT0_fpr(rD(ctx->opcode));
1712 if (unlikely(Rc(ctx->opcode) != 0))
1716 GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT)
1718 if (unlikely(!ctx->fpu_enabled)) {
1719 GEN_EXCP_NO_FP(ctx);
1722 gen_op_reset_scrfx();
1723 gen_op_load_fpr_FT0(rB(ctx->opcode));
1726 gen_op_store_FT0_fpr(rD(ctx->opcode));
1727 if (unlikely(Rc(ctx->opcode) != 0))
1731 /*** Floating-Point multiply-and-add ***/
1732 /* fmadd - fmadds */
1733 GEN_FLOAT_ACB(madd, 0x1D, PPC_FLOAT);
1734 /* fmsub - fmsubs */
1735 GEN_FLOAT_ACB(msub, 0x1C, PPC_FLOAT);
1736 /* fnmadd - fnmadds */
1737 GEN_FLOAT_ACB(nmadd, 0x1F, PPC_FLOAT);
1738 /* fnmsub - fnmsubs */
1739 GEN_FLOAT_ACB(nmsub, 0x1E, PPC_FLOAT);
1741 /*** Floating-Point round & convert ***/
1743 GEN_FLOAT_B(ctiw, 0x0E, 0x00, PPC_FLOAT);
1745 GEN_FLOAT_B(ctiwz, 0x0F, 0x00, PPC_FLOAT);
1747 GEN_FLOAT_B(rsp, 0x0C, 0x00, PPC_FLOAT);
1748 #if defined(TARGET_PPC64)
1750 GEN_FLOAT_B(cfid, 0x0E, 0x1A, PPC_64B);
1752 GEN_FLOAT_B(ctid, 0x0E, 0x19, PPC_64B);
1754 GEN_FLOAT_B(ctidz, 0x0F, 0x19, PPC_64B);
1758 GEN_FLOAT_B(rin, 0x08, 0x0C, PPC_FLOAT_EXT);
1760 GEN_FLOAT_B(riz, 0x08, 0x0D, PPC_FLOAT_EXT);
1762 GEN_FLOAT_B(rip, 0x08, 0x0E, PPC_FLOAT_EXT);
1764 GEN_FLOAT_B(rim, 0x08, 0x0F, PPC_FLOAT_EXT);
1766 /*** Floating-Point compare ***/
1768 GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT)
1770 if (unlikely(!ctx->fpu_enabled)) {
1771 GEN_EXCP_NO_FP(ctx);
1774 gen_op_reset_scrfx();
1775 gen_op_load_fpr_FT0(rA(ctx->opcode));
1776 gen_op_load_fpr_FT1(rB(ctx->opcode));
1778 gen_op_store_T0_crf(crfD(ctx->opcode));
1782 GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT)
1784 if (unlikely(!ctx->fpu_enabled)) {
1785 GEN_EXCP_NO_FP(ctx);
1788 gen_op_reset_scrfx();
1789 gen_op_load_fpr_FT0(rA(ctx->opcode));
1790 gen_op_load_fpr_FT1(rB(ctx->opcode));
1792 gen_op_store_T0_crf(crfD(ctx->opcode));
1795 /*** Floating-point move ***/
1797 GEN_FLOAT_B(abs, 0x08, 0x08, PPC_FLOAT);
1800 GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT)
1802 if (unlikely(!ctx->fpu_enabled)) {
1803 GEN_EXCP_NO_FP(ctx);
1806 gen_op_reset_scrfx();
1807 gen_op_load_fpr_FT0(rB(ctx->opcode));
1808 gen_op_store_FT0_fpr(rD(ctx->opcode));
1809 if (unlikely(Rc(ctx->opcode) != 0))
1814 GEN_FLOAT_B(nabs, 0x08, 0x04, PPC_FLOAT);
1816 GEN_FLOAT_B(neg, 0x08, 0x01, PPC_FLOAT);
1818 /*** Floating-Point status & ctrl register ***/
1820 GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT)
1822 if (unlikely(!ctx->fpu_enabled)) {
1823 GEN_EXCP_NO_FP(ctx);
1826 gen_op_load_fpscr_T0(crfS(ctx->opcode));
1827 gen_op_store_T0_crf(crfD(ctx->opcode));
1828 gen_op_clear_fpscr(crfS(ctx->opcode));
1832 GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT)
1834 if (unlikely(!ctx->fpu_enabled)) {
1835 GEN_EXCP_NO_FP(ctx);
1838 gen_op_load_fpscr();
1839 gen_op_store_FT0_fpr(rD(ctx->opcode));
1840 if (unlikely(Rc(ctx->opcode) != 0))
1845 GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT)
1849 if (unlikely(!ctx->fpu_enabled)) {
1850 GEN_EXCP_NO_FP(ctx);
1853 crb = crbD(ctx->opcode) >> 2;
1854 gen_op_load_fpscr_T0(crb);
1855 gen_op_andi_T0(~(1 << (crbD(ctx->opcode) & 0x03)));
1856 gen_op_store_T0_fpscr(crb);
1857 if (unlikely(Rc(ctx->opcode) != 0))
1862 GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT)
1866 if (unlikely(!ctx->fpu_enabled)) {
1867 GEN_EXCP_NO_FP(ctx);
1870 crb = crbD(ctx->opcode) >> 2;
1871 gen_op_load_fpscr_T0(crb);
1872 gen_op_ori(1 << (crbD(ctx->opcode) & 0x03));
1873 gen_op_store_T0_fpscr(crb);
1874 if (unlikely(Rc(ctx->opcode) != 0))
1879 GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x02010000, PPC_FLOAT)
1881 if (unlikely(!ctx->fpu_enabled)) {
1882 GEN_EXCP_NO_FP(ctx);
1885 gen_op_load_fpr_FT0(rB(ctx->opcode));
1886 gen_op_store_fpscr(FM(ctx->opcode));
1887 if (unlikely(Rc(ctx->opcode) != 0))
1892 GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT)
1894 if (unlikely(!ctx->fpu_enabled)) {
1895 GEN_EXCP_NO_FP(ctx);
1898 gen_op_store_T0_fpscri(crbD(ctx->opcode) >> 2, FPIMM(ctx->opcode));
1899 if (unlikely(Rc(ctx->opcode) != 0))
1903 /*** Addressing modes ***/
1904 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
1905 static inline void gen_addr_imm_index (DisasContext *ctx, int maskl)
1907 target_long simm = SIMM(ctx->opcode);
1911 if (rA(ctx->opcode) == 0) {
1914 gen_op_load_gpr_T0(rA(ctx->opcode));
1915 if (likely(simm != 0))
1918 #ifdef DEBUG_MEMORY_ACCESSES
1919 gen_op_print_mem_EA();
1923 static inline void gen_addr_reg_index (DisasContext *ctx)
1925 if (rA(ctx->opcode) == 0) {
1926 gen_op_load_gpr_T0(rB(ctx->opcode));
1928 gen_op_load_gpr_T0(rA(ctx->opcode));
1929 gen_op_load_gpr_T1(rB(ctx->opcode));
1932 #ifdef DEBUG_MEMORY_ACCESSES
1933 gen_op_print_mem_EA();
1937 static inline void gen_addr_register (DisasContext *ctx)
1939 if (rA(ctx->opcode) == 0) {
1942 gen_op_load_gpr_T0(rA(ctx->opcode));
1944 #ifdef DEBUG_MEMORY_ACCESSES
1945 gen_op_print_mem_EA();
1949 /*** Integer load ***/
1950 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
1951 #if defined(CONFIG_USER_ONLY)
1952 #if defined(TARGET_PPC64)
1953 #define OP_LD_TABLE(width) \
1954 static GenOpFunc *gen_op_l##width[] = { \
1955 &gen_op_l##width##_raw, \
1956 &gen_op_l##width##_le_raw, \
1957 &gen_op_l##width##_64_raw, \
1958 &gen_op_l##width##_le_64_raw, \
1960 #define OP_ST_TABLE(width) \
1961 static GenOpFunc *gen_op_st##width[] = { \
1962 &gen_op_st##width##_raw, \
1963 &gen_op_st##width##_le_raw, \
1964 &gen_op_st##width##_64_raw, \
1965 &gen_op_st##width##_le_64_raw, \
1967 /* Byte access routine are endian safe */
1968 #define gen_op_stb_le_64_raw gen_op_stb_64_raw
1969 #define gen_op_lbz_le_64_raw gen_op_lbz_64_raw
1971 #define OP_LD_TABLE(width) \
1972 static GenOpFunc *gen_op_l##width[] = { \
1973 &gen_op_l##width##_raw, \
1974 &gen_op_l##width##_le_raw, \
1976 #define OP_ST_TABLE(width) \
1977 static GenOpFunc *gen_op_st##width[] = { \
1978 &gen_op_st##width##_raw, \
1979 &gen_op_st##width##_le_raw, \
1982 /* Byte access routine are endian safe */
1983 #define gen_op_stb_le_raw gen_op_stb_raw
1984 #define gen_op_lbz_le_raw gen_op_lbz_raw
1986 #if defined(TARGET_PPC64)
1987 #define OP_LD_TABLE(width) \
1988 static GenOpFunc *gen_op_l##width[] = { \
1989 &gen_op_l##width##_user, \
1990 &gen_op_l##width##_le_user, \
1991 &gen_op_l##width##_kernel, \
1992 &gen_op_l##width##_le_kernel, \
1993 &gen_op_l##width##_64_user, \
1994 &gen_op_l##width##_le_64_user, \
1995 &gen_op_l##width##_64_kernel, \
1996 &gen_op_l##width##_le_64_kernel, \
1998 #define OP_ST_TABLE(width) \
1999 static GenOpFunc *gen_op_st##width[] = { \
2000 &gen_op_st##width##_user, \
2001 &gen_op_st##width##_le_user, \
2002 &gen_op_st##width##_kernel, \
2003 &gen_op_st##width##_le_kernel, \
2004 &gen_op_st##width##_64_user, \
2005 &gen_op_st##width##_le_64_user, \
2006 &gen_op_st##width##_64_kernel, \
2007 &gen_op_st##width##_le_64_kernel, \
2009 /* Byte access routine are endian safe */
2010 #define gen_op_stb_le_64_user gen_op_stb_64_user
2011 #define gen_op_lbz_le_64_user gen_op_lbz_64_user
2012 #define gen_op_stb_le_64_kernel gen_op_stb_64_kernel
2013 #define gen_op_lbz_le_64_kernel gen_op_lbz_64_kernel
2015 #define OP_LD_TABLE(width) \
2016 static GenOpFunc *gen_op_l##width[] = { \
2017 &gen_op_l##width##_user, \
2018 &gen_op_l##width##_le_user, \
2019 &gen_op_l##width##_kernel, \
2020 &gen_op_l##width##_le_kernel, \
2022 #define OP_ST_TABLE(width) \
2023 static GenOpFunc *gen_op_st##width[] = { \
2024 &gen_op_st##width##_user, \
2025 &gen_op_st##width##_le_user, \
2026 &gen_op_st##width##_kernel, \
2027 &gen_op_st##width##_le_kernel, \
2030 /* Byte access routine are endian safe */
2031 #define gen_op_stb_le_user gen_op_stb_user
2032 #define gen_op_lbz_le_user gen_op_lbz_user
2033 #define gen_op_stb_le_kernel gen_op_stb_kernel
2034 #define gen_op_lbz_le_kernel gen_op_lbz_kernel
2037 #define GEN_LD(width, opc, type) \
2038 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2040 gen_addr_imm_index(ctx, 0); \
2041 op_ldst(l##width); \
2042 gen_op_store_T1_gpr(rD(ctx->opcode)); \
2045 #define GEN_LDU(width, opc, type) \
2046 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2048 if (unlikely(rA(ctx->opcode) == 0 || \
2049 rA(ctx->opcode) == rD(ctx->opcode))) { \
2050 GEN_EXCP_INVAL(ctx); \
2053 if (type == PPC_64B) \
2054 gen_addr_imm_index(ctx, 1); \
2056 gen_addr_imm_index(ctx, 0); \
2057 op_ldst(l##width); \
2058 gen_op_store_T1_gpr(rD(ctx->opcode)); \
2059 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2062 #define GEN_LDUX(width, opc2, opc3, type) \
2063 GEN_HANDLER(l##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2065 if (unlikely(rA(ctx->opcode) == 0 || \
2066 rA(ctx->opcode) == rD(ctx->opcode))) { \
2067 GEN_EXCP_INVAL(ctx); \
2070 gen_addr_reg_index(ctx); \
2071 op_ldst(l##width); \
2072 gen_op_store_T1_gpr(rD(ctx->opcode)); \
2073 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2076 #define GEN_LDX(width, opc2, opc3, type) \
2077 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2079 gen_addr_reg_index(ctx); \
2080 op_ldst(l##width); \
2081 gen_op_store_T1_gpr(rD(ctx->opcode)); \
2084 #define GEN_LDS(width, op, type) \
2085 OP_LD_TABLE(width); \
2086 GEN_LD(width, op | 0x20, type); \
2087 GEN_LDU(width, op | 0x21, type); \
2088 GEN_LDUX(width, 0x17, op | 0x01, type); \
2089 GEN_LDX(width, 0x17, op | 0x00, type)
2091 /* lbz lbzu lbzux lbzx */
2092 GEN_LDS(bz, 0x02, PPC_INTEGER);
2093 /* lha lhau lhaux lhax */
2094 GEN_LDS(ha, 0x0A, PPC_INTEGER);
2095 /* lhz lhzu lhzux lhzx */
2096 GEN_LDS(hz, 0x08, PPC_INTEGER);
2097 /* lwz lwzu lwzux lwzx */
2098 GEN_LDS(wz, 0x00, PPC_INTEGER);
2099 #if defined(TARGET_PPC64)
2103 GEN_LDUX(wa, 0x15, 0x0B, PPC_64B);
2105 GEN_LDX(wa, 0x15, 0x0A, PPC_64B);
2107 GEN_LDUX(d, 0x15, 0x01, PPC_64B);
2109 GEN_LDX(d, 0x15, 0x00, PPC_64B);
2110 GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B)
2112 if (Rc(ctx->opcode)) {
2113 if (unlikely(rA(ctx->opcode) == 0 ||
2114 rA(ctx->opcode) == rD(ctx->opcode))) {
2115 GEN_EXCP_INVAL(ctx);
2119 gen_addr_imm_index(ctx, 1);
2120 if (ctx->opcode & 0x02) {
2121 /* lwa (lwau is undefined) */
2127 gen_op_store_T1_gpr(rD(ctx->opcode));
2128 if (Rc(ctx->opcode))
2129 gen_op_store_T0_gpr(rA(ctx->opcode));
2133 /*** Integer store ***/
2134 #define GEN_ST(width, opc, type) \
2135 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2137 gen_addr_imm_index(ctx, 0); \
2138 gen_op_load_gpr_T1(rS(ctx->opcode)); \
2139 op_ldst(st##width); \
2142 #define GEN_STU(width, opc, type) \
2143 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2145 if (unlikely(rA(ctx->opcode) == 0)) { \
2146 GEN_EXCP_INVAL(ctx); \
2149 if (type == PPC_64B) \
2150 gen_addr_imm_index(ctx, 1); \
2152 gen_addr_imm_index(ctx, 0); \
2153 gen_op_load_gpr_T1(rS(ctx->opcode)); \
2154 op_ldst(st##width); \
2155 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2158 #define GEN_STUX(width, opc2, opc3, type) \
2159 GEN_HANDLER(st##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2161 if (unlikely(rA(ctx->opcode) == 0)) { \
2162 GEN_EXCP_INVAL(ctx); \
2165 gen_addr_reg_index(ctx); \
2166 gen_op_load_gpr_T1(rS(ctx->opcode)); \
2167 op_ldst(st##width); \
2168 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2171 #define GEN_STX(width, opc2, opc3, type) \
2172 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2174 gen_addr_reg_index(ctx); \
2175 gen_op_load_gpr_T1(rS(ctx->opcode)); \
2176 op_ldst(st##width); \
2179 #define GEN_STS(width, op, type) \
2180 OP_ST_TABLE(width); \
2181 GEN_ST(width, op | 0x20, type); \
2182 GEN_STU(width, op | 0x21, type); \
2183 GEN_STUX(width, 0x17, op | 0x01, type); \
2184 GEN_STX(width, 0x17, op | 0x00, type)
2186 /* stb stbu stbux stbx */
2187 GEN_STS(b, 0x06, PPC_INTEGER);
2188 /* sth sthu sthux sthx */
2189 GEN_STS(h, 0x0C, PPC_INTEGER);
2190 /* stw stwu stwux stwx */
2191 GEN_STS(w, 0x04, PPC_INTEGER);
2192 #if defined(TARGET_PPC64)
2194 GEN_STUX(d, 0x15, 0x05, PPC_64B);
2195 GEN_STX(d, 0x15, 0x04, PPC_64B);
2196 GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000002, PPC_64B)
2198 if (Rc(ctx->opcode)) {
2199 if (unlikely(rA(ctx->opcode) == 0)) {
2200 GEN_EXCP_INVAL(ctx);
2204 gen_addr_imm_index(ctx, 1);
2205 gen_op_load_gpr_T1(rS(ctx->opcode));
2207 if (Rc(ctx->opcode))
2208 gen_op_store_T0_gpr(rA(ctx->opcode));
2211 /*** Integer load and store with byte reverse ***/
2214 GEN_LDX(hbr, 0x16, 0x18, PPC_INTEGER);
2217 GEN_LDX(wbr, 0x16, 0x10, PPC_INTEGER);
2220 GEN_STX(hbr, 0x16, 0x1C, PPC_INTEGER);
2223 GEN_STX(wbr, 0x16, 0x14, PPC_INTEGER);
2225 /*** Integer load and store multiple ***/
2226 #define op_ldstm(name, reg) (*gen_op_##name[ctx->mem_idx])(reg)
2227 #if defined(TARGET_PPC64)
2228 #if defined(CONFIG_USER_ONLY)
2229 static GenOpFunc1 *gen_op_lmw[] = {
2233 &gen_op_lmw_le_64_raw,
2235 static GenOpFunc1 *gen_op_stmw[] = {
2236 &gen_op_stmw_64_raw,
2237 &gen_op_stmw_le_64_raw,
2240 static GenOpFunc1 *gen_op_lmw[] = {
2242 &gen_op_lmw_le_user,
2244 &gen_op_lmw_le_kernel,
2245 &gen_op_lmw_64_user,
2246 &gen_op_lmw_le_64_user,
2247 &gen_op_lmw_64_kernel,
2248 &gen_op_lmw_le_64_kernel,
2250 static GenOpFunc1 *gen_op_stmw[] = {
2252 &gen_op_stmw_le_user,
2253 &gen_op_stmw_kernel,
2254 &gen_op_stmw_le_kernel,
2255 &gen_op_stmw_64_user,
2256 &gen_op_stmw_le_64_user,
2257 &gen_op_stmw_64_kernel,
2258 &gen_op_stmw_le_64_kernel,
2262 #if defined(CONFIG_USER_ONLY)
2263 static GenOpFunc1 *gen_op_lmw[] = {
2267 static GenOpFunc1 *gen_op_stmw[] = {
2269 &gen_op_stmw_le_raw,
2272 static GenOpFunc1 *gen_op_lmw[] = {
2274 &gen_op_lmw_le_user,
2276 &gen_op_lmw_le_kernel,
2278 static GenOpFunc1 *gen_op_stmw[] = {
2280 &gen_op_stmw_le_user,
2281 &gen_op_stmw_kernel,
2282 &gen_op_stmw_le_kernel,
2288 GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
2290 /* NIP cannot be restored if the memory exception comes from an helper */
2291 gen_update_nip(ctx, ctx->nip - 4);
2292 gen_addr_imm_index(ctx, 0);
2293 op_ldstm(lmw, rD(ctx->opcode));
2297 GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER)
2299 /* NIP cannot be restored if the memory exception comes from an helper */
2300 gen_update_nip(ctx, ctx->nip - 4);
2301 gen_addr_imm_index(ctx, 0);
2302 op_ldstm(stmw, rS(ctx->opcode));
2305 /*** Integer load and store strings ***/
2306 #define op_ldsts(name, start) (*gen_op_##name[ctx->mem_idx])(start)
2307 #define op_ldstsx(name, rd, ra, rb) (*gen_op_##name[ctx->mem_idx])(rd, ra, rb)
2308 #if defined(TARGET_PPC64)
2309 #if defined(CONFIG_USER_ONLY)
2310 static GenOpFunc1 *gen_op_lswi[] = {
2312 &gen_op_lswi_le_raw,
2313 &gen_op_lswi_64_raw,
2314 &gen_op_lswi_le_64_raw,
2316 static GenOpFunc3 *gen_op_lswx[] = {
2318 &gen_op_lswx_le_raw,
2319 &gen_op_lswx_64_raw,
2320 &gen_op_lswx_le_64_raw,
2322 static GenOpFunc1 *gen_op_stsw[] = {
2324 &gen_op_stsw_le_raw,
2325 &gen_op_stsw_64_raw,
2326 &gen_op_stsw_le_64_raw,
2329 static GenOpFunc1 *gen_op_lswi[] = {
2331 &gen_op_lswi_le_user,
2332 &gen_op_lswi_kernel,
2333 &gen_op_lswi_le_kernel,
2334 &gen_op_lswi_64_user,
2335 &gen_op_lswi_le_64_user,
2336 &gen_op_lswi_64_kernel,
2337 &gen_op_lswi_le_64_kernel,
2339 static GenOpFunc3 *gen_op_lswx[] = {
2341 &gen_op_lswx_le_user,
2342 &gen_op_lswx_kernel,
2343 &gen_op_lswx_le_kernel,
2344 &gen_op_lswx_64_user,
2345 &gen_op_lswx_le_64_user,
2346 &gen_op_lswx_64_kernel,
2347 &gen_op_lswx_le_64_kernel,
2349 static GenOpFunc1 *gen_op_stsw[] = {
2351 &gen_op_stsw_le_user,
2352 &gen_op_stsw_kernel,
2353 &gen_op_stsw_le_kernel,
2354 &gen_op_stsw_64_user,
2355 &gen_op_stsw_le_64_user,
2356 &gen_op_stsw_64_kernel,
2357 &gen_op_stsw_le_64_kernel,
2361 #if defined(CONFIG_USER_ONLY)
2362 static GenOpFunc1 *gen_op_lswi[] = {
2364 &gen_op_lswi_le_raw,
2366 static GenOpFunc3 *gen_op_lswx[] = {
2368 &gen_op_lswx_le_raw,
2370 static GenOpFunc1 *gen_op_stsw[] = {
2372 &gen_op_stsw_le_raw,
2375 static GenOpFunc1 *gen_op_lswi[] = {
2377 &gen_op_lswi_le_user,
2378 &gen_op_lswi_kernel,
2379 &gen_op_lswi_le_kernel,
2381 static GenOpFunc3 *gen_op_lswx[] = {
2383 &gen_op_lswx_le_user,
2384 &gen_op_lswx_kernel,
2385 &gen_op_lswx_le_kernel,
2387 static GenOpFunc1 *gen_op_stsw[] = {
2389 &gen_op_stsw_le_user,
2390 &gen_op_stsw_kernel,
2391 &gen_op_stsw_le_kernel,
2397 /* PowerPC32 specification says we must generate an exception if
2398 * rA is in the range of registers to be loaded.
2399 * In an other hand, IBM says this is valid, but rA won't be loaded.
2400 * For now, I'll follow the spec...
2402 GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_INTEGER)
2404 int nb = NB(ctx->opcode);
2405 int start = rD(ctx->opcode);
2406 int ra = rA(ctx->opcode);
2412 if (unlikely(((start + nr) > 32 &&
2413 start <= ra && (start + nr - 32) > ra) ||
2414 ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) {
2415 GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM,
2416 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_LSWX);
2419 /* NIP cannot be restored if the memory exception comes from an helper */
2420 gen_update_nip(ctx, ctx->nip - 4);
2421 gen_addr_register(ctx);
2423 op_ldsts(lswi, start);
2427 GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_INTEGER)
2429 int ra = rA(ctx->opcode);
2430 int rb = rB(ctx->opcode);
2432 /* NIP cannot be restored if the memory exception comes from an helper */
2433 gen_update_nip(ctx, ctx->nip - 4);
2434 gen_addr_reg_index(ctx);
2438 gen_op_load_xer_bc();
2439 op_ldstsx(lswx, rD(ctx->opcode), ra, rb);
2443 GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_INTEGER)
2445 int nb = NB(ctx->opcode);
2447 /* NIP cannot be restored if the memory exception comes from an helper */
2448 gen_update_nip(ctx, ctx->nip - 4);
2449 gen_addr_register(ctx);
2453 op_ldsts(stsw, rS(ctx->opcode));
2457 GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_INTEGER)
2459 /* NIP cannot be restored if the memory exception comes from an helper */
2460 gen_update_nip(ctx, ctx->nip - 4);
2461 gen_addr_reg_index(ctx);
2462 gen_op_load_xer_bc();
2463 op_ldsts(stsw, rS(ctx->opcode));
2466 /*** Memory synchronisation ***/
2468 GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO)
2473 GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM)
2478 #define op_lwarx() (*gen_op_lwarx[ctx->mem_idx])()
2479 #define op_stwcx() (*gen_op_stwcx[ctx->mem_idx])()
2480 #if defined(TARGET_PPC64)
2481 #if defined(CONFIG_USER_ONLY)
2482 static GenOpFunc *gen_op_lwarx[] = {
2484 &gen_op_lwarx_le_raw,
2485 &gen_op_lwarx_64_raw,
2486 &gen_op_lwarx_le_64_raw,
2488 static GenOpFunc *gen_op_stwcx[] = {
2490 &gen_op_stwcx_le_raw,
2491 &gen_op_stwcx_64_raw,
2492 &gen_op_stwcx_le_64_raw,
2495 static GenOpFunc *gen_op_lwarx[] = {
2497 &gen_op_lwarx_le_user,
2498 &gen_op_lwarx_kernel,
2499 &gen_op_lwarx_le_kernel,
2500 &gen_op_lwarx_64_user,
2501 &gen_op_lwarx_le_64_user,
2502 &gen_op_lwarx_64_kernel,
2503 &gen_op_lwarx_le_64_kernel,
2505 static GenOpFunc *gen_op_stwcx[] = {
2507 &gen_op_stwcx_le_user,
2508 &gen_op_stwcx_kernel,
2509 &gen_op_stwcx_le_kernel,
2510 &gen_op_stwcx_64_user,
2511 &gen_op_stwcx_le_64_user,
2512 &gen_op_stwcx_64_kernel,
2513 &gen_op_stwcx_le_64_kernel,
2517 #if defined(CONFIG_USER_ONLY)
2518 static GenOpFunc *gen_op_lwarx[] = {
2520 &gen_op_lwarx_le_raw,
2522 static GenOpFunc *gen_op_stwcx[] = {
2524 &gen_op_stwcx_le_raw,
2527 static GenOpFunc *gen_op_lwarx[] = {
2529 &gen_op_lwarx_le_user,
2530 &gen_op_lwarx_kernel,
2531 &gen_op_lwarx_le_kernel,
2533 static GenOpFunc *gen_op_stwcx[] = {
2535 &gen_op_stwcx_le_user,
2536 &gen_op_stwcx_kernel,
2537 &gen_op_stwcx_le_kernel,
2543 GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000001, PPC_RES)
2545 gen_addr_reg_index(ctx);
2547 gen_op_store_T1_gpr(rD(ctx->opcode));
2551 GEN_HANDLER(stwcx_, 0x1F, 0x16, 0x04, 0x00000000, PPC_RES)
2553 gen_addr_reg_index(ctx);
2554 gen_op_load_gpr_T1(rS(ctx->opcode));
2558 #if defined(TARGET_PPC64)
2559 #define op_ldarx() (*gen_op_ldarx[ctx->mem_idx])()
2560 #define op_stdcx() (*gen_op_stdcx[ctx->mem_idx])()
2561 #if defined(CONFIG_USER_ONLY)
2562 static GenOpFunc *gen_op_ldarx[] = {
2564 &gen_op_ldarx_le_raw,
2565 &gen_op_ldarx_64_raw,
2566 &gen_op_ldarx_le_64_raw,
2568 static GenOpFunc *gen_op_stdcx[] = {
2570 &gen_op_stdcx_le_raw,
2571 &gen_op_stdcx_64_raw,
2572 &gen_op_stdcx_le_64_raw,
2575 static GenOpFunc *gen_op_ldarx[] = {
2577 &gen_op_ldarx_le_user,
2578 &gen_op_ldarx_kernel,
2579 &gen_op_ldarx_le_kernel,
2580 &gen_op_ldarx_64_user,
2581 &gen_op_ldarx_le_64_user,
2582 &gen_op_ldarx_64_kernel,
2583 &gen_op_ldarx_le_64_kernel,
2585 static GenOpFunc *gen_op_stdcx[] = {
2587 &gen_op_stdcx_le_user,
2588 &gen_op_stdcx_kernel,
2589 &gen_op_stdcx_le_kernel,
2590 &gen_op_stdcx_64_user,
2591 &gen_op_stdcx_le_64_user,
2592 &gen_op_stdcx_64_kernel,
2593 &gen_op_stdcx_le_64_kernel,
2598 GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000001, PPC_64B)
2600 gen_addr_reg_index(ctx);
2602 gen_op_store_T1_gpr(rD(ctx->opcode));
2606 GEN_HANDLER(stdcx_, 0x1F, 0x16, 0x06, 0x00000000, PPC_64B)
2608 gen_addr_reg_index(ctx);
2609 gen_op_load_gpr_T1(rS(ctx->opcode));
2612 #endif /* defined(TARGET_PPC64) */
2615 GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x03BFF801, PPC_MEM_SYNC)
2620 GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT)
2622 /* Stop translation, as the CPU is supposed to sleep from now */
2623 /* XXX: TODO: handle this idle CPU case */
2627 /*** Floating-point load ***/
2628 #define GEN_LDF(width, opc, type) \
2629 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2631 if (unlikely(!ctx->fpu_enabled)) { \
2632 GEN_EXCP_NO_FP(ctx); \
2635 gen_addr_imm_index(ctx, 0); \
2636 op_ldst(l##width); \
2637 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
2640 #define GEN_LDUF(width, opc, type) \
2641 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2643 if (unlikely(!ctx->fpu_enabled)) { \
2644 GEN_EXCP_NO_FP(ctx); \
2647 if (unlikely(rA(ctx->opcode) == 0)) { \
2648 GEN_EXCP_INVAL(ctx); \
2651 gen_addr_imm_index(ctx, 0); \
2652 op_ldst(l##width); \
2653 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
2654 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2657 #define GEN_LDUXF(width, opc, type) \
2658 GEN_HANDLER(l##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \
2660 if (unlikely(!ctx->fpu_enabled)) { \
2661 GEN_EXCP_NO_FP(ctx); \
2664 if (unlikely(rA(ctx->opcode) == 0)) { \
2665 GEN_EXCP_INVAL(ctx); \
2668 gen_addr_reg_index(ctx); \
2669 op_ldst(l##width); \
2670 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
2671 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2674 #define GEN_LDXF(width, opc2, opc3, type) \
2675 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2677 if (unlikely(!ctx->fpu_enabled)) { \
2678 GEN_EXCP_NO_FP(ctx); \
2681 gen_addr_reg_index(ctx); \
2682 op_ldst(l##width); \
2683 gen_op_store_FT0_fpr(rD(ctx->opcode)); \
2686 #define GEN_LDFS(width, op, type) \
2687 OP_LD_TABLE(width); \
2688 GEN_LDF(width, op | 0x20, type); \
2689 GEN_LDUF(width, op | 0x21, type); \
2690 GEN_LDUXF(width, op | 0x01, type); \
2691 GEN_LDXF(width, 0x17, op | 0x00, type)
2693 /* lfd lfdu lfdux lfdx */
2694 GEN_LDFS(fd, 0x12, PPC_FLOAT);
2695 /* lfs lfsu lfsux lfsx */
2696 GEN_LDFS(fs, 0x10, PPC_FLOAT);
2698 /*** Floating-point store ***/
2699 #define GEN_STF(width, opc, type) \
2700 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2702 if (unlikely(!ctx->fpu_enabled)) { \
2703 GEN_EXCP_NO_FP(ctx); \
2706 gen_addr_imm_index(ctx, 0); \
2707 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
2708 op_ldst(st##width); \
2711 #define GEN_STUF(width, opc, type) \
2712 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2714 if (unlikely(!ctx->fpu_enabled)) { \
2715 GEN_EXCP_NO_FP(ctx); \
2718 if (unlikely(rA(ctx->opcode) == 0)) { \
2719 GEN_EXCP_INVAL(ctx); \
2722 gen_addr_imm_index(ctx, 0); \
2723 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
2724 op_ldst(st##width); \
2725 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2728 #define GEN_STUXF(width, opc, type) \
2729 GEN_HANDLER(st##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \
2731 if (unlikely(!ctx->fpu_enabled)) { \
2732 GEN_EXCP_NO_FP(ctx); \
2735 if (unlikely(rA(ctx->opcode) == 0)) { \
2736 GEN_EXCP_INVAL(ctx); \
2739 gen_addr_reg_index(ctx); \
2740 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
2741 op_ldst(st##width); \
2742 gen_op_store_T0_gpr(rA(ctx->opcode)); \
2745 #define GEN_STXF(width, opc2, opc3, type) \
2746 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2748 if (unlikely(!ctx->fpu_enabled)) { \
2749 GEN_EXCP_NO_FP(ctx); \
2752 gen_addr_reg_index(ctx); \
2753 gen_op_load_fpr_FT0(rS(ctx->opcode)); \
2754 op_ldst(st##width); \
2757 #define GEN_STFS(width, op, type) \
2758 OP_ST_TABLE(width); \
2759 GEN_STF(width, op | 0x20, type); \
2760 GEN_STUF(width, op | 0x21, type); \
2761 GEN_STUXF(width, op | 0x01, type); \
2762 GEN_STXF(width, 0x17, op | 0x00, type)
2764 /* stfd stfdu stfdux stfdx */
2765 GEN_STFS(fd, 0x16, PPC_FLOAT);
2766 /* stfs stfsu stfsux stfsx */
2767 GEN_STFS(fs, 0x14, PPC_FLOAT);
2772 GEN_STXF(fiwx, 0x17, 0x1E, PPC_FLOAT_STFIWX);
2775 static inline void gen_goto_tb (DisasContext *ctx, int n, target_ulong dest)
2777 TranslationBlock *tb;
2779 if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK)) {
2781 gen_op_goto_tb0(TBPARAM(tb));
2783 gen_op_goto_tb1(TBPARAM(tb));
2785 #if defined(TARGET_PPC64)
2791 gen_op_set_T0((long)tb + n);
2792 if (ctx->singlestep_enabled)
2797 #if defined(TARGET_PPC64)
2804 if (ctx->singlestep_enabled)
2810 static inline void gen_setlr (DisasContext *ctx, target_ulong nip)
2812 #if defined(TARGET_PPC64)
2813 if (ctx->sf_mode != 0 && (nip >> 32))
2814 gen_op_setlr_64(ctx->nip >> 32, ctx->nip);
2817 gen_op_setlr(ctx->nip);
2821 GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
2823 target_ulong li, target;
2825 /* sign extend LI */
2826 #if defined(TARGET_PPC64)
2828 li = ((int64_t)LI(ctx->opcode) << 38) >> 38;
2831 li = ((int32_t)LI(ctx->opcode) << 6) >> 6;
2832 if (likely(AA(ctx->opcode) == 0))
2833 target = ctx->nip + li - 4;
2836 #if defined(TARGET_PPC64)
2838 target = (uint32_t)target;
2840 if (LK(ctx->opcode))
2841 gen_setlr(ctx, ctx->nip);
2842 gen_goto_tb(ctx, 0, target);
2843 ctx->exception = POWERPC_EXCP_BRANCH;
2850 static inline void gen_bcond (DisasContext *ctx, int type)
2852 target_ulong target = 0;
2854 uint32_t bo = BO(ctx->opcode);
2855 uint32_t bi = BI(ctx->opcode);
2858 if ((bo & 0x4) == 0)
2862 li = (target_long)((int16_t)(BD(ctx->opcode)));
2863 if (likely(AA(ctx->opcode) == 0)) {
2864 target = ctx->nip + li - 4;
2868 #if defined(TARGET_PPC64)
2870 target = (uint32_t)target;
2874 gen_op_movl_T1_ctr();
2878 gen_op_movl_T1_lr();
2881 if (LK(ctx->opcode))
2882 gen_setlr(ctx, ctx->nip);
2884 /* No CR condition */
2887 #if defined(TARGET_PPC64)
2889 gen_op_test_ctr_64();
2895 #if defined(TARGET_PPC64)
2897 gen_op_test_ctrz_64();
2905 if (type == BCOND_IM) {
2906 gen_goto_tb(ctx, 0, target);
2908 #if defined(TARGET_PPC64)
2919 mask = 1 << (3 - (bi & 0x03));
2920 gen_op_load_crf_T0(bi >> 2);
2924 #if defined(TARGET_PPC64)
2926 gen_op_test_ctr_true_64(mask);
2929 gen_op_test_ctr_true(mask);
2932 #if defined(TARGET_PPC64)
2934 gen_op_test_ctrz_true_64(mask);
2937 gen_op_test_ctrz_true(mask);
2942 gen_op_test_true(mask);
2948 #if defined(TARGET_PPC64)
2950 gen_op_test_ctr_false_64(mask);
2953 gen_op_test_ctr_false(mask);
2956 #if defined(TARGET_PPC64)
2958 gen_op_test_ctrz_false_64(mask);
2961 gen_op_test_ctrz_false(mask);
2966 gen_op_test_false(mask);
2971 if (type == BCOND_IM) {
2972 int l1 = gen_new_label();
2974 gen_goto_tb(ctx, 0, target);
2976 gen_goto_tb(ctx, 1, ctx->nip);
2978 #if defined(TARGET_PPC64)
2980 gen_op_btest_T1_64(ctx->nip >> 32, ctx->nip);
2983 gen_op_btest_T1(ctx->nip);
2986 if (ctx->singlestep_enabled)
2990 ctx->exception = POWERPC_EXCP_BRANCH;
2993 GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
2995 gen_bcond(ctx, BCOND_IM);
2998 GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW)
3000 gen_bcond(ctx, BCOND_CTR);
3003 GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW)
3005 gen_bcond(ctx, BCOND_LR);
3008 /*** Condition register logical ***/
3009 #define GEN_CRLOGIC(op, opc) \
3010 GEN_HANDLER(cr##op, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) \
3012 gen_op_load_crf_T0(crbA(ctx->opcode) >> 2); \
3013 gen_op_getbit_T0(3 - (crbA(ctx->opcode) & 0x03)); \
3014 gen_op_load_crf_T1(crbB(ctx->opcode) >> 2); \
3015 gen_op_getbit_T1(3 - (crbB(ctx->opcode) & 0x03)); \
3017 gen_op_load_crf_T1(crbD(ctx->opcode) >> 2); \
3018 gen_op_setcrfbit(~(1 << (3 - (crbD(ctx->opcode) & 0x03))), \
3019 3 - (crbD(ctx->opcode) & 0x03)); \
3020 gen_op_store_T1_crf(crbD(ctx->opcode) >> 2); \
3024 GEN_CRLOGIC(and, 0x08);
3026 GEN_CRLOGIC(andc, 0x04);
3028 GEN_CRLOGIC(eqv, 0x09);
3030 GEN_CRLOGIC(nand, 0x07);
3032 GEN_CRLOGIC(nor, 0x01);
3034 GEN_CRLOGIC(or, 0x0E);
3036 GEN_CRLOGIC(orc, 0x0D);
3038 GEN_CRLOGIC(xor, 0x06);
3040 GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER)
3042 gen_op_load_crf_T0(crfS(ctx->opcode));
3043 gen_op_store_T0_crf(crfD(ctx->opcode));
3046 /*** System linkage ***/
3047 /* rfi (supervisor only) */
3048 GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW)
3050 #if defined(CONFIG_USER_ONLY)
3051 GEN_EXCP_PRIVOPC(ctx);
3053 /* Restore CPU state */
3054 if (unlikely(!ctx->supervisor)) {
3055 GEN_EXCP_PRIVOPC(ctx);
3063 #if defined(TARGET_PPC64)
3064 GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B)
3066 #if defined(CONFIG_USER_ONLY)
3067 GEN_EXCP_PRIVOPC(ctx);
3069 /* Restore CPU state */
3070 if (unlikely(!ctx->supervisor)) {
3071 GEN_EXCP_PRIVOPC(ctx);
3081 GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW)
3085 lev = (ctx->opcode >> 5) & 0x7F;
3086 #if defined(CONFIG_USER_ONLY)
3087 GEN_EXCP(ctx, POWERPC_EXCP_SYSCALL_USER, lev);
3089 GEN_EXCP(ctx, POWERPC_EXCP_SYSCALL, lev);
3095 GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW)
3097 gen_op_load_gpr_T0(rA(ctx->opcode));
3098 gen_op_load_gpr_T1(rB(ctx->opcode));
3099 /* Update the nip since this might generate a trap exception */
3100 gen_update_nip(ctx, ctx->nip);
3101 gen_op_tw(TO(ctx->opcode));
3105 GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW)
3107 gen_op_load_gpr_T0(rA(ctx->opcode));
3108 gen_set_T1(SIMM(ctx->opcode));
3109 /* Update the nip since this might generate a trap exception */
3110 gen_update_nip(ctx, ctx->nip);
3111 gen_op_tw(TO(ctx->opcode));
3114 #if defined(TARGET_PPC64)
3116 GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B)
3118 gen_op_load_gpr_T0(rA(ctx->opcode));
3119 gen_op_load_gpr_T1(rB(ctx->opcode));
3120 /* Update the nip since this might generate a trap exception */
3121 gen_update_nip(ctx, ctx->nip);
3122 gen_op_td(TO(ctx->opcode));
3126 GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B)
3128 gen_op_load_gpr_T0(rA(ctx->opcode));
3129 gen_set_T1(SIMM(ctx->opcode));
3130 /* Update the nip since this might generate a trap exception */
3131 gen_update_nip(ctx, ctx->nip);
3132 gen_op_td(TO(ctx->opcode));
3136 /*** Processor control ***/
3138 GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC)
3140 gen_op_load_xer_cr();
3141 gen_op_store_T0_crf(crfD(ctx->opcode));
3142 gen_op_clear_xer_ov();
3143 gen_op_clear_xer_ca();
3147 GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC)
3151 if (likely(ctx->opcode & 0x00100000)) {
3152 crm = CRM(ctx->opcode);
3153 if (likely((crm ^ (crm - 1)) == 0)) {
3155 gen_op_load_cro(7 - crn);
3160 gen_op_store_T0_gpr(rD(ctx->opcode));
3164 GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC)
3166 #if defined(CONFIG_USER_ONLY)
3167 GEN_EXCP_PRIVREG(ctx);
3169 if (unlikely(!ctx->supervisor)) {
3170 GEN_EXCP_PRIVREG(ctx);
3174 gen_op_store_T0_gpr(rD(ctx->opcode));
3179 #define SPR_NOACCESS ((void *)(-1))
3181 static void spr_noaccess (void *opaque, int sprn)
3183 sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5);
3184 printf("ERROR: try to access SPR %d !\n", sprn);
3186 #define SPR_NOACCESS (&spr_noaccess)
3190 static inline void gen_op_mfspr (DisasContext *ctx)
3192 void (*read_cb)(void *opaque, int sprn);
3193 uint32_t sprn = SPR(ctx->opcode);
3195 #if !defined(CONFIG_USER_ONLY)
3196 if (ctx->supervisor)
3197 read_cb = ctx->spr_cb[sprn].oea_read;
3200 read_cb = ctx->spr_cb[sprn].uea_read;
3201 if (likely(read_cb != NULL)) {
3202 if (likely(read_cb != SPR_NOACCESS)) {
3203 (*read_cb)(ctx, sprn);
3204 gen_op_store_T0_gpr(rD(ctx->opcode));
3206 /* Privilege exception */
3207 if (loglevel != 0) {
3208 fprintf(logfile, "Trying to read privileged spr %d %03x\n",
3211 printf("Trying to read privileged spr %d %03x\n", sprn, sprn);
3212 GEN_EXCP_PRIVREG(ctx);
3216 if (loglevel != 0) {
3217 fprintf(logfile, "Trying to read invalid spr %d %03x\n",
3220 printf("Trying to read invalid spr %d %03x\n", sprn, sprn);
3221 GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM,
3222 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_SPR);
3226 GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC)
3232 GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB)
3238 GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC)
3242 gen_op_load_gpr_T0(rS(ctx->opcode));
3243 crm = CRM(ctx->opcode);
3244 if (likely((ctx->opcode & 0x00100000) || (crm ^ (crm - 1)) == 0)) {
3246 gen_op_srli_T0(crn * 4);
3247 gen_op_andi_T0(0xF);
3248 gen_op_store_cro(7 - crn);
3250 gen_op_store_cr(crm);
3255 #if defined(TARGET_PPC64)
3256 GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001FF801, PPC_64B)
3258 #if defined(CONFIG_USER_ONLY)
3259 GEN_EXCP_PRIVREG(ctx);
3261 if (unlikely(!ctx->supervisor)) {
3262 GEN_EXCP_PRIVREG(ctx);
3265 gen_update_nip(ctx, ctx->nip);
3266 gen_op_load_gpr_T0(rS(ctx->opcode));
3268 /* Must stop the translation as machine state (may have) changed */
3269 /* Note that mtmsr is not always defined as context-synchronizing */
3275 GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC)
3277 #if defined(CONFIG_USER_ONLY)
3278 GEN_EXCP_PRIVREG(ctx);
3280 if (unlikely(!ctx->supervisor)) {
3281 GEN_EXCP_PRIVREG(ctx);
3284 gen_update_nip(ctx, ctx->nip);
3285 gen_op_load_gpr_T0(rS(ctx->opcode));
3286 #if defined(TARGET_PPC64)
3288 gen_op_store_msr_32();
3292 /* Must stop the translation as machine state (may have) changed */
3293 /* Note that mtmsrd is not always defined as context-synchronizing */
3299 GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC)
3301 void (*write_cb)(void *opaque, int sprn);
3302 uint32_t sprn = SPR(ctx->opcode);
3304 #if !defined(CONFIG_USER_ONLY)
3305 if (ctx->supervisor)
3306 write_cb = ctx->spr_cb[sprn].oea_write;
3309 write_cb = ctx->spr_cb[sprn].uea_write;
3310 if (likely(write_cb != NULL)) {
3311 if (likely(write_cb != SPR_NOACCESS)) {
3312 gen_op_load_gpr_T0(rS(ctx->opcode));
3313 (*write_cb)(ctx, sprn);
3315 /* Privilege exception */
3316 if (loglevel != 0) {
3317 fprintf(logfile, "Trying to write privileged spr %d %03x\n",
3320 printf("Trying to write privileged spr %d %03x\n", sprn, sprn);
3321 GEN_EXCP_PRIVREG(ctx);
3325 if (loglevel != 0) {
3326 fprintf(logfile, "Trying to write invalid spr %d %03x\n",
3329 printf("Trying to write invalid spr %d %03x\n", sprn, sprn);
3330 GEN_EXCP(ctx, POWERPC_EXCP_PROGRAM,
3331 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_SPR);
3335 /*** Cache management ***/
3336 /* For now, all those will be implemented as nop:
3337 * this is valid, regarding the PowerPC specs...
3338 * We just have to flush tb while invalidating instruction cache lines...
3341 GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE)
3343 gen_addr_reg_index(ctx);
3347 /* dcbi (Supervisor only) */
3348 GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE)
3350 #if defined(CONFIG_USER_ONLY)
3351 GEN_EXCP_PRIVOPC(ctx);
3353 if (unlikely(!ctx->supervisor)) {
3354 GEN_EXCP_PRIVOPC(ctx);
3357 gen_addr_reg_index(ctx);
3358 /* XXX: specification says this should be treated as a store by the MMU */
3365 GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE)
3367 /* XXX: specification say this is treated as a load by the MMU */
3368 gen_addr_reg_index(ctx);
3373 GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE)
3375 /* interpreted as no-op */
3376 /* XXX: specification say this is treated as a load by the MMU
3377 * but does not generate any exception
3382 GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE)
3384 /* interpreted as no-op */
3385 /* XXX: specification say this is treated as a load by the MMU
3386 * but does not generate any exception
3391 #define op_dcbz() (*gen_op_dcbz[ctx->mem_idx])()
3392 #if defined(TARGET_PPC64)
3393 #if defined(CONFIG_USER_ONLY)
3394 static GenOpFunc *gen_op_dcbz[] = {
3397 &gen_op_dcbz_64_raw,
3398 &gen_op_dcbz_64_raw,
3401 static GenOpFunc *gen_op_dcbz[] = {
3404 &gen_op_dcbz_kernel,
3405 &gen_op_dcbz_kernel,
3406 &gen_op_dcbz_64_user,
3407 &gen_op_dcbz_64_user,
3408 &gen_op_dcbz_64_kernel,
3409 &gen_op_dcbz_64_kernel,
3413 #if defined(CONFIG_USER_ONLY)
3414 static GenOpFunc *gen_op_dcbz[] = {
3419 static GenOpFunc *gen_op_dcbz[] = {
3422 &gen_op_dcbz_kernel,
3423 &gen_op_dcbz_kernel,
3428 GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE)
3430 gen_addr_reg_index(ctx);
3432 gen_op_check_reservation();
3436 #define op_icbi() (*gen_op_icbi[ctx->mem_idx])()
3437 #if defined(TARGET_PPC64)
3438 #if defined(CONFIG_USER_ONLY)
3439 static GenOpFunc *gen_op_icbi[] = {
3442 &gen_op_icbi_64_raw,
3443 &gen_op_icbi_64_raw,
3446 static GenOpFunc *gen_op_icbi[] = {
3449 &gen_op_icbi_kernel,
3450 &gen_op_icbi_kernel,
3451 &gen_op_icbi_64_user,
3452 &gen_op_icbi_64_user,
3453 &gen_op_icbi_64_kernel,
3454 &gen_op_icbi_64_kernel,
3458 #if defined(CONFIG_USER_ONLY)
3459 static GenOpFunc *gen_op_icbi[] = {
3464 static GenOpFunc *gen_op_icbi[] = {
3467 &gen_op_icbi_kernel,
3468 &gen_op_icbi_kernel,
3473 GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE)
3475 gen_addr_reg_index(ctx);
3481 GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA)
3483 /* interpreted as no-op */
3484 /* XXX: specification say this is treated as a store by the MMU
3485 * but does not generate any exception
3489 /*** Segment register manipulation ***/
3490 /* Supervisor only: */
3492 GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT)
3494 #if defined(CONFIG_USER_ONLY)
3495 GEN_EXCP_PRIVREG(ctx);
3497 if (unlikely(!ctx->supervisor)) {
3498 GEN_EXCP_PRIVREG(ctx);
3501 gen_op_set_T1(SR(ctx->opcode));
3503 gen_op_store_T0_gpr(rD(ctx->opcode));
3508 GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT)
3510 #if defined(CONFIG_USER_ONLY)
3511 GEN_EXCP_PRIVREG(ctx);
3513 if (unlikely(!ctx->supervisor)) {
3514 GEN_EXCP_PRIVREG(ctx);
3517 gen_op_load_gpr_T1(rB(ctx->opcode));
3520 gen_op_store_T0_gpr(rD(ctx->opcode));
3525 GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT)
3527 #if defined(CONFIG_USER_ONLY)
3528 GEN_EXCP_PRIVREG(ctx);
3530 if (unlikely(!ctx->supervisor)) {
3531 GEN_EXCP_PRIVREG(ctx);
3534 gen_op_load_gpr_T0(rS(ctx->opcode));
3535 gen_op_set_T1(SR(ctx->opcode));
3541 GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT)
3543 #if defined(CONFIG_USER_ONLY)
3544 GEN_EXCP_PRIVREG(ctx);
3546 if (unlikely(!ctx->supervisor)) {
3547 GEN_EXCP_PRIVREG(ctx);
3550 gen_op_load_gpr_T0(rS(ctx->opcode));
3551 gen_op_load_gpr_T1(rB(ctx->opcode));
3557 /*** Lookaside buffer management ***/
3558 /* Optional & supervisor only: */
3560 GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA)
3562 #if defined(CONFIG_USER_ONLY)
3563 GEN_EXCP_PRIVOPC(ctx);
3565 if (unlikely(!ctx->supervisor)) {
3567 fprintf(logfile, "%s: ! supervisor\n", __func__);
3568 GEN_EXCP_PRIVOPC(ctx);
3576 GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE)
3578 #if defined(CONFIG_USER_ONLY)
3579 GEN_EXCP_PRIVOPC(ctx);
3581 if (unlikely(!ctx->supervisor)) {
3582 GEN_EXCP_PRIVOPC(ctx);
3585 gen_op_load_gpr_T0(rB(ctx->opcode));
3586 #if defined(TARGET_PPC64)
3596 GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC)
3598 #if defined(CONFIG_USER_ONLY)
3599 GEN_EXCP_PRIVOPC(ctx);
3601 if (unlikely(!ctx->supervisor)) {
3602 GEN_EXCP_PRIVOPC(ctx);
3605 /* This has no effect: it should ensure that all previous
3606 * tlbie have completed
3612 #if defined(TARGET_PPC64)
3614 GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI)
3616 #if defined(CONFIG_USER_ONLY)
3617 GEN_EXCP_PRIVOPC(ctx);
3619 if (unlikely(!ctx->supervisor)) {
3621 fprintf(logfile, "%s: ! supervisor\n", __func__);
3622 GEN_EXCP_PRIVOPC(ctx);
3630 GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI)
3632 #if defined(CONFIG_USER_ONLY)
3633 GEN_EXCP_PRIVOPC(ctx);
3635 if (unlikely(!ctx->supervisor)) {
3636 GEN_EXCP_PRIVOPC(ctx);
3639 gen_op_load_gpr_T0(rB(ctx->opcode));
3645 /*** External control ***/
3647 #define op_eciwx() (*gen_op_eciwx[ctx->mem_idx])()
3648 #define op_ecowx() (*gen_op_ecowx[ctx->mem_idx])()
3649 #if defined(TARGET_PPC64)
3650 #if defined(CONFIG_USER_ONLY)
3651 static GenOpFunc *gen_op_eciwx[] = {
3653 &gen_op_eciwx_le_raw,
3654 &gen_op_eciwx_64_raw,
3655 &gen_op_eciwx_le_64_raw,
3657 static GenOpFunc *gen_op_ecowx[] = {
3659 &gen_op_ecowx_le_raw,
3660 &gen_op_ecowx_64_raw,
3661 &gen_op_ecowx_le_64_raw,
3664 static GenOpFunc *gen_op_eciwx[] = {
3666 &gen_op_eciwx_le_user,
3667 &gen_op_eciwx_kernel,
3668 &gen_op_eciwx_le_kernel,
3669 &gen_op_eciwx_64_user,
3670 &gen_op_eciwx_le_64_user,
3671 &gen_op_eciwx_64_kernel,
3672 &gen_op_eciwx_le_64_kernel,
3674 static GenOpFunc *gen_op_ecowx[] = {
3676 &gen_op_ecowx_le_user,
3677 &gen_op_ecowx_kernel,
3678 &gen_op_ecowx_le_kernel,
3679 &gen_op_ecowx_64_user,
3680 &gen_op_ecowx_le_64_user,
3681 &gen_op_ecowx_64_kernel,
3682 &gen_op_ecowx_le_64_kernel,
3686 #if defined(CONFIG_USER_ONLY)
3687 static GenOpFunc *gen_op_eciwx[] = {
3689 &gen_op_eciwx_le_raw,
3691 static GenOpFunc *gen_op_ecowx[] = {
3693 &gen_op_ecowx_le_raw,
3696 static GenOpFunc *gen_op_eciwx[] = {
3698 &gen_op_eciwx_le_user,
3699 &gen_op_eciwx_kernel,
3700 &gen_op_eciwx_le_kernel,
3702 static GenOpFunc *gen_op_ecowx[] = {
3704 &gen_op_ecowx_le_user,
3705 &gen_op_ecowx_kernel,
3706 &gen_op_ecowx_le_kernel,
3712 GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN)
3714 /* Should check EAR[E] & alignment ! */
3715 gen_addr_reg_index(ctx);
3717 gen_op_store_T0_gpr(rD(ctx->opcode));
3721 GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN)
3723 /* Should check EAR[E] & alignment ! */
3724 gen_addr_reg_index(ctx);
3725 gen_op_load_gpr_T1(rS(ctx->opcode));
3729 /* PowerPC 601 specific instructions */
3731 GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR)
3733 gen_op_load_gpr_T0(rA(ctx->opcode));
3735 gen_op_store_T0_gpr(rD(ctx->opcode));
3736 if (unlikely(Rc(ctx->opcode) != 0))
3741 GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR)
3743 gen_op_load_gpr_T0(rA(ctx->opcode));
3744 gen_op_POWER_abso();
3745 gen_op_store_T0_gpr(rD(ctx->opcode));
3746 if (unlikely(Rc(ctx->opcode) != 0))
3751 GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR)
3753 gen_op_load_gpr_T0(rA(ctx->opcode));
3754 gen_op_POWER_clcs();
3755 gen_op_store_T0_gpr(rD(ctx->opcode));
3759 GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR)
3761 gen_op_load_gpr_T0(rA(ctx->opcode));
3762 gen_op_load_gpr_T1(rB(ctx->opcode));
3764 gen_op_store_T0_gpr(rD(ctx->opcode));
3765 if (unlikely(Rc(ctx->opcode) != 0))
3770 GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR)
3772 gen_op_load_gpr_T0(rA(ctx->opcode));
3773 gen_op_load_gpr_T1(rB(ctx->opcode));
3774 gen_op_POWER_divo();
3775 gen_op_store_T0_gpr(rD(ctx->opcode));
3776 if (unlikely(Rc(ctx->opcode) != 0))
3781 GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR)
3783 gen_op_load_gpr_T0(rA(ctx->opcode));
3784 gen_op_load_gpr_T1(rB(ctx->opcode));
3785 gen_op_POWER_divs();
3786 gen_op_store_T0_gpr(rD(ctx->opcode));
3787 if (unlikely(Rc(ctx->opcode) != 0))
3791 /* divso - divso. */
3792 GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR)
3794 gen_op_load_gpr_T0(rA(ctx->opcode));
3795 gen_op_load_gpr_T1(rB(ctx->opcode));
3796 gen_op_POWER_divso();
3797 gen_op_store_T0_gpr(rD(ctx->opcode));
3798 if (unlikely(Rc(ctx->opcode) != 0))
3803 GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR)
3805 gen_op_load_gpr_T0(rA(ctx->opcode));
3806 gen_op_load_gpr_T1(rB(ctx->opcode));
3808 gen_op_store_T0_gpr(rD(ctx->opcode));
3809 if (unlikely(Rc(ctx->opcode) != 0))
3814 GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR)
3816 gen_op_load_gpr_T0(rA(ctx->opcode));
3817 gen_op_load_gpr_T1(rB(ctx->opcode));
3818 gen_op_POWER_dozo();
3819 gen_op_store_T0_gpr(rD(ctx->opcode));
3820 if (unlikely(Rc(ctx->opcode) != 0))
3825 GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR)
3827 gen_op_load_gpr_T0(rA(ctx->opcode));
3828 gen_op_set_T1(SIMM(ctx->opcode));
3830 gen_op_store_T0_gpr(rD(ctx->opcode));
3833 /* As lscbx load from memory byte after byte, it's always endian safe */
3834 #define op_POWER_lscbx(start, ra, rb) \
3835 (*gen_op_POWER_lscbx[ctx->mem_idx])(start, ra, rb)
3836 #if defined(CONFIG_USER_ONLY)
3837 static GenOpFunc3 *gen_op_POWER_lscbx[] = {
3838 &gen_op_POWER_lscbx_raw,
3839 &gen_op_POWER_lscbx_raw,
3842 static GenOpFunc3 *gen_op_POWER_lscbx[] = {
3843 &gen_op_POWER_lscbx_user,
3844 &gen_op_POWER_lscbx_user,
3845 &gen_op_POWER_lscbx_kernel,
3846 &gen_op_POWER_lscbx_kernel,
3850 /* lscbx - lscbx. */
3851 GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR)
3853 int ra = rA(ctx->opcode);
3854 int rb = rB(ctx->opcode);
3856 gen_addr_reg_index(ctx);
3860 /* NIP cannot be restored if the memory exception comes from an helper */
3861 gen_update_nip(ctx, ctx->nip - 4);
3862 gen_op_load_xer_bc();
3863 gen_op_load_xer_cmp();
3864 op_POWER_lscbx(rD(ctx->opcode), ra, rb);
3865 gen_op_store_xer_bc();
3866 if (unlikely(Rc(ctx->opcode) != 0))
3870 /* maskg - maskg. */
3871 GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR)
3873 gen_op_load_gpr_T0(rS(ctx->opcode));
3874 gen_op_load_gpr_T1(rB(ctx->opcode));
3875 gen_op_POWER_maskg();
3876 gen_op_store_T0_gpr(rA(ctx->opcode));
3877 if (unlikely(Rc(ctx->opcode) != 0))
3881 /* maskir - maskir. */
3882 GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR)
3884 gen_op_load_gpr_T0(rA(ctx->opcode));
3885 gen_op_load_gpr_T1(rS(ctx->opcode));
3886 gen_op_load_gpr_T2(rB(ctx->opcode));
3887 gen_op_POWER_maskir();
3888 gen_op_store_T0_gpr(rA(ctx->opcode));
3889 if (unlikely(Rc(ctx->opcode) != 0))
3894 GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR)
3896 gen_op_load_gpr_T0(rA(ctx->opcode));
3897 gen_op_load_gpr_T1(rB(ctx->opcode));
3899 gen_op_store_T0_gpr(rD(ctx->opcode));
3900 if (unlikely(Rc(ctx->opcode) != 0))
3905 GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR)
3907 gen_op_load_gpr_T0(rA(ctx->opcode));
3908 gen_op_load_gpr_T1(rB(ctx->opcode));
3909 gen_op_POWER_mulo();
3910 gen_op_store_T0_gpr(rD(ctx->opcode));
3911 if (unlikely(Rc(ctx->opcode) != 0))
3916 GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR)
3918 gen_op_load_gpr_T0(rA(ctx->opcode));
3919 gen_op_POWER_nabs();
3920 gen_op_store_T0_gpr(rD(ctx->opcode));
3921 if (unlikely(Rc(ctx->opcode) != 0))
3925 /* nabso - nabso. */
3926 GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR)
3928 gen_op_load_gpr_T0(rA(ctx->opcode));
3929 gen_op_POWER_nabso();
3930 gen_op_store_T0_gpr(rD(ctx->opcode));
3931 if (unlikely(Rc(ctx->opcode) != 0))
3936 GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR)
3940 mb = MB(ctx->opcode);
3941 me = ME(ctx->opcode);
3942 gen_op_load_gpr_T0(rS(ctx->opcode));
3943 gen_op_load_gpr_T1(rA(ctx->opcode));
3944 gen_op_load_gpr_T2(rB(ctx->opcode));
3945 gen_op_POWER_rlmi(MASK(mb, me), ~MASK(mb, me));
3946 gen_op_store_T0_gpr(rA(ctx->opcode));
3947 if (unlikely(Rc(ctx->opcode) != 0))
3952 GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR)
3954 gen_op_load_gpr_T0(rS(ctx->opcode));
3955 gen_op_load_gpr_T1(rA(ctx->opcode));
3956 gen_op_load_gpr_T2(rB(ctx->opcode));
3957 gen_op_POWER_rrib();
3958 gen_op_store_T0_gpr(rA(ctx->opcode));
3959 if (unlikely(Rc(ctx->opcode) != 0))
3964 GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR)
3966 gen_op_load_gpr_T0(rS(ctx->opcode));
3967 gen_op_load_gpr_T1(rB(ctx->opcode));
3969 gen_op_store_T0_gpr(rA(ctx->opcode));
3970 if (unlikely(Rc(ctx->opcode) != 0))
3975 GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR)
3977 gen_op_load_gpr_T0(rS(ctx->opcode));
3978 gen_op_load_gpr_T1(rB(ctx->opcode));
3979 gen_op_POWER_sleq();
3980 gen_op_store_T0_gpr(rA(ctx->opcode));
3981 if (unlikely(Rc(ctx->opcode) != 0))
3986 GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR)
3988 gen_op_load_gpr_T0(rS(ctx->opcode));
3989 gen_op_set_T1(SH(ctx->opcode));
3991 gen_op_store_T0_gpr(rA(ctx->opcode));
3992 if (unlikely(Rc(ctx->opcode) != 0))
3996 /* slliq - slliq. */
3997 GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR)
3999 gen_op_load_gpr_T0(rS(ctx->opcode));
4000 gen_op_set_T1(SH(ctx->opcode));
4001 gen_op_POWER_sleq();
4002 gen_op_store_T0_gpr(rA(ctx->opcode));
4003 if (unlikely(Rc(ctx->opcode) != 0))
4008 GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR)
4010 gen_op_load_gpr_T0(rS(ctx->opcode));
4011 gen_op_load_gpr_T1(rB(ctx->opcode));
4012 gen_op_POWER_sllq();
4013 gen_op_store_T0_gpr(rA(ctx->opcode));
4014 if (unlikely(Rc(ctx->opcode) != 0))
4019 GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR)
4021 gen_op_load_gpr_T0(rS(ctx->opcode));
4022 gen_op_load_gpr_T1(rB(ctx->opcode));
4024 gen_op_store_T0_gpr(rA(ctx->opcode));
4025 if (unlikely(Rc(ctx->opcode) != 0))
4029 /* sraiq - sraiq. */
4030 GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR)
4032 gen_op_load_gpr_T0(rS(ctx->opcode));
4033 gen_op_set_T1(SH(ctx->opcode));
4034 gen_op_POWER_sraq();
4035 gen_op_store_T0_gpr(rA(ctx->opcode));
4036 if (unlikely(Rc(ctx->opcode) != 0))
4041 GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR)
4043 gen_op_load_gpr_T0(rS(ctx->opcode));
4044 gen_op_load_gpr_T1(rB(ctx->opcode));
4045 gen_op_POWER_sraq();
4046 gen_op_store_T0_gpr(rA(ctx->opcode));
4047 if (unlikely(Rc(ctx->opcode) != 0))
4052 GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR)
4054 gen_op_load_gpr_T0(rS(ctx->opcode));
4055 gen_op_load_gpr_T1(rB(ctx->opcode));
4057 gen_op_store_T0_gpr(rA(ctx->opcode));
4058 if (unlikely(Rc(ctx->opcode) != 0))
4063 GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR)
4065 gen_op_load_gpr_T0(rS(ctx->opcode));
4066 gen_op_load_gpr_T1(rB(ctx->opcode));
4067 gen_op_POWER_srea();
4068 gen_op_store_T0_gpr(rA(ctx->opcode));
4069 if (unlikely(Rc(ctx->opcode) != 0))
4074 GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR)
4076 gen_op_load_gpr_T0(rS(ctx->opcode));
4077 gen_op_load_gpr_T1(rB(ctx->opcode));
4078 gen_op_POWER_sreq();
4079 gen_op_store_T0_gpr(rA(ctx->opcode));
4080 if (unlikely(Rc(ctx->opcode) != 0))
4085 GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR)
4087 gen_op_load_gpr_T0(rS(ctx->opcode));
4088 gen_op_set_T1(SH(ctx->opcode));
4090 gen_op_store_T0_gpr(rA(ctx->opcode));
4091 if (unlikely(Rc(ctx->opcode) != 0))
4096 GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR)
4098 gen_op_load_gpr_T0(rS(ctx->opcode));
4099 gen_op_load_gpr_T1(rB(ctx->opcode));
4100 gen_op_set_T1(SH(ctx->opcode));
4101 gen_op_POWER_srlq();
4102 gen_op_store_T0_gpr(rA(ctx->opcode));
4103 if (unlikely(Rc(ctx->opcode) != 0))
4108 GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR)
4110 gen_op_load_gpr_T0(rS(ctx->opcode));
4111 gen_op_load_gpr_T1(rB(ctx->opcode));
4112 gen_op_POWER_srlq();
4113 gen_op_store_T0_gpr(rA(ctx->opcode));
4114 if (unlikely(Rc(ctx->opcode) != 0))
4119 GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR)
4121 gen_op_load_gpr_T0(rS(ctx->opcode));
4122 gen_op_load_gpr_T1(rB(ctx->opcode));
4124 gen_op_store_T0_gpr(rA(ctx->opcode));
4125 if (unlikely(Rc(ctx->opcode) != 0))
4129 /* PowerPC 602 specific instructions */
4131 GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC)
4134 GEN_EXCP_INVAL(ctx);
4138 GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC)
4141 GEN_EXCP_INVAL(ctx);
4145 GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC)
4147 #if defined(CONFIG_USER_ONLY)
4148 GEN_EXCP_PRIVOPC(ctx);
4150 if (unlikely(!ctx->supervisor)) {
4151 GEN_EXCP_PRIVOPC(ctx);
4154 gen_op_load_gpr_T0(rA(ctx->opcode));
4156 gen_op_store_T0_gpr(rD(ctx->opcode));
4160 /* 602 - 603 - G2 TLB management */
4162 GEN_HANDLER(tlbld, 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB)
4164 #if defined(CONFIG_USER_ONLY)
4165 GEN_EXCP_PRIVOPC(ctx);
4167 if (unlikely(!ctx->supervisor)) {
4168 GEN_EXCP_PRIVOPC(ctx);
4171 gen_op_load_gpr_T0(rB(ctx->opcode));
4177 GEN_HANDLER(tlbli, 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB)
4179 #if defined(CONFIG_USER_ONLY)
4180 GEN_EXCP_PRIVOPC(ctx);
4182 if (unlikely(!ctx->supervisor)) {
4183 GEN_EXCP_PRIVOPC(ctx);
4186 gen_op_load_gpr_T0(rB(ctx->opcode));
4191 /* POWER instructions not in PowerPC 601 */
4193 GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER)
4195 /* Cache line flush: implemented as no-op */
4199 GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER)
4201 /* Cache line invalidate: privileged and treated as no-op */
4202 #if defined(CONFIG_USER_ONLY)
4203 GEN_EXCP_PRIVOPC(ctx);
4205 if (unlikely(!ctx->supervisor)) {
4206 GEN_EXCP_PRIVOPC(ctx);
4213 GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER)
4215 /* Data cache line store: treated as no-op */
4218 GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER)
4220 #if defined(CONFIG_USER_ONLY)
4221 GEN_EXCP_PRIVOPC(ctx);
4223 if (unlikely(!ctx->supervisor)) {
4224 GEN_EXCP_PRIVOPC(ctx);
4227 int ra = rA(ctx->opcode);
4228 int rd = rD(ctx->opcode);
4230 gen_addr_reg_index(ctx);
4231 gen_op_POWER_mfsri();
4232 gen_op_store_T0_gpr(rd);
4233 if (ra != 0 && ra != rd)
4234 gen_op_store_T1_gpr(ra);
4238 GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER)
4240 #if defined(CONFIG_USER_ONLY)
4241 GEN_EXCP_PRIVOPC(ctx);
4243 if (unlikely(!ctx->supervisor)) {
4244 GEN_EXCP_PRIVOPC(ctx);
4247 gen_addr_reg_index(ctx);
4249 gen_op_store_T0_gpr(rD(ctx->opcode));
4253 GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER)
4255 #if defined(CONFIG_USER_ONLY)
4256 GEN_EXCP_PRIVOPC(ctx);
4258 if (unlikely(!ctx->supervisor)) {
4259 GEN_EXCP_PRIVOPC(ctx);
4262 gen_op_POWER_rfsvc();
4267 /* svc is not implemented for now */
4269 /* POWER2 specific instructions */
4270 /* Quad manipulation (load/store two floats at a time) */
4271 #define op_POWER2_lfq() (*gen_op_POWER2_lfq[ctx->mem_idx])()
4272 #define op_POWER2_stfq() (*gen_op_POWER2_stfq[ctx->mem_idx])()
4273 #if defined(CONFIG_USER_ONLY)
4274 static GenOpFunc *gen_op_POWER2_lfq[] = {
4275 &gen_op_POWER2_lfq_le_raw,
4276 &gen_op_POWER2_lfq_raw,
4278 static GenOpFunc *gen_op_POWER2_stfq[] = {
4279 &gen_op_POWER2_stfq_le_raw,
4280 &gen_op_POWER2_stfq_raw,
4283 static GenOpFunc *gen_op_POWER2_lfq[] = {
4284 &gen_op_POWER2_lfq_le_user,
4285 &gen_op_POWER2_lfq_user,
4286 &gen_op_POWER2_lfq_le_kernel,
4287 &gen_op_POWER2_lfq_kernel,
4289 static GenOpFunc *gen_op_POWER2_stfq[] = {
4290 &gen_op_POWER2_stfq_le_user,
4291 &gen_op_POWER2_stfq_user,
4292 &gen_op_POWER2_stfq_le_kernel,
4293 &gen_op_POWER2_stfq_kernel,
4298 GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
4300 /* NIP cannot be restored if the memory exception comes from an helper */
4301 gen_update_nip(ctx, ctx->nip - 4);
4302 gen_addr_imm_index(ctx, 0);
4304 gen_op_store_FT0_fpr(rD(ctx->opcode));
4305 gen_op_store_FT1_fpr(rD(ctx->opcode) + 1);
4309 GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
4311 int ra = rA(ctx->opcode);
4313 /* NIP cannot be restored if the memory exception comes from an helper */
4314 gen_update_nip(ctx, ctx->nip - 4);
4315 gen_addr_imm_index(ctx, 0);
4317 gen_op_store_FT0_fpr(rD(ctx->opcode));
4318 gen_op_store_FT1_fpr(rD(ctx->opcode) + 1);
4320 gen_op_store_T0_gpr(ra);
4324 GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2)
4326 int ra = rA(ctx->opcode);
4328 /* NIP cannot be restored if the memory exception comes from an helper */
4329 gen_update_nip(ctx, ctx->nip - 4);
4330 gen_addr_reg_index(ctx);
4332 gen_op_store_FT0_fpr(rD(ctx->opcode));
4333 gen_op_store_FT1_fpr(rD(ctx->opcode) + 1);
4335 gen_op_store_T0_gpr(ra);
4339 GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2)
4341 /* NIP cannot be restored if the memory exception comes from an helper */
4342 gen_update_nip(ctx, ctx->nip - 4);
4343 gen_addr_reg_index(ctx);
4345 gen_op_store_FT0_fpr(rD(ctx->opcode));
4346 gen_op_store_FT1_fpr(rD(ctx->opcode) + 1);
4350 GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
4352 /* NIP cannot be restored if the memory exception comes from an helper */
4353 gen_update_nip(ctx, ctx->nip - 4);
4354 gen_addr_imm_index(ctx, 0);
4355 gen_op_load_fpr_FT0(rS(ctx->opcode));
4356 gen_op_load_fpr_FT1(rS(ctx->opcode) + 1);
4361 GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2)
4363 int ra = rA(ctx->opcode);
4365 /* NIP cannot be restored if the memory exception comes from an helper */
4366 gen_update_nip(ctx, ctx->nip - 4);
4367 gen_addr_imm_index(ctx, 0);
4368 gen_op_load_fpr_FT0(rS(ctx->opcode));
4369 gen_op_load_fpr_FT1(rS(ctx->opcode) + 1);
4372 gen_op_store_T0_gpr(ra);
4376 GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2)
4378 int ra = rA(ctx->opcode);
4380 /* NIP cannot be restored if the memory exception comes from an helper */
4381 gen_update_nip(ctx, ctx->nip - 4);
4382 gen_addr_reg_index(ctx);
4383 gen_op_load_fpr_FT0(rS(ctx->opcode));
4384 gen_op_load_fpr_FT1(rS(ctx->opcode) + 1);
4387 gen_op_store_T0_gpr(ra);
4391 GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2)
4393 /* NIP cannot be restored if the memory exception comes from an helper */
4394 gen_update_nip(ctx, ctx->nip - 4);
4395 gen_addr_reg_index(ctx);
4396 gen_op_load_fpr_FT0(rS(ctx->opcode));
4397 gen_op_load_fpr_FT1(rS(ctx->opcode) + 1);
4401 /* BookE specific instructions */
4402 /* XXX: not implemented on 440 ? */
4403 GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_BOOKE_EXT)
4406 GEN_EXCP_INVAL(ctx);
4409 /* XXX: not implemented on 440 ? */
4410 GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_BOOKE_EXT)
4412 #if defined(CONFIG_USER_ONLY)
4413 GEN_EXCP_PRIVOPC(ctx);
4415 if (unlikely(!ctx->supervisor)) {
4416 GEN_EXCP_PRIVOPC(ctx);
4419 gen_addr_reg_index(ctx);
4420 /* Use the same micro-ops as for tlbie */
4421 #if defined(TARGET_PPC64)
4430 /* All 405 MAC instructions are translated here */
4431 static inline void gen_405_mulladd_insn (DisasContext *ctx, int opc2, int opc3,
4432 int ra, int rb, int rt, int Rc)
4434 gen_op_load_gpr_T0(ra);
4435 gen_op_load_gpr_T1(rb);
4436 switch (opc3 & 0x0D) {
4438 /* macchw - macchw. - macchwo - macchwo. */
4439 /* macchws - macchws. - macchwso - macchwso. */
4440 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
4441 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
4442 /* mulchw - mulchw. */
4443 gen_op_405_mulchw();
4446 /* macchwu - macchwu. - macchwuo - macchwuo. */
4447 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
4448 /* mulchwu - mulchwu. */
4449 gen_op_405_mulchwu();
4452 /* machhw - machhw. - machhwo - machhwo. */
4453 /* machhws - machhws. - machhwso - machhwso. */
4454 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
4455 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
4456 /* mulhhw - mulhhw. */
4457 gen_op_405_mulhhw();
4460 /* machhwu - machhwu. - machhwuo - machhwuo. */
4461 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
4462 /* mulhhwu - mulhhwu. */
4463 gen_op_405_mulhhwu();
4466 /* maclhw - maclhw. - maclhwo - maclhwo. */
4467 /* maclhws - maclhws. - maclhwso - maclhwso. */
4468 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
4469 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
4470 /* mullhw - mullhw. */
4471 gen_op_405_mullhw();
4474 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
4475 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
4476 /* mullhwu - mullhwu. */
4477 gen_op_405_mullhwu();
4481 /* nmultiply-and-accumulate (0x0E) */
4485 /* (n)multiply-and-accumulate (0x0C - 0x0E) */
4486 gen_op_load_gpr_T2(rt);
4487 gen_op_move_T1_T0();
4488 gen_op_405_add_T0_T2();
4491 /* Check overflow */
4493 gen_op_405_check_ov();
4495 gen_op_405_check_ovu();
4500 gen_op_405_check_sat();
4502 gen_op_405_check_satu();
4504 gen_op_store_T0_gpr(rt);
4505 if (unlikely(Rc) != 0) {
4511 #define GEN_MAC_HANDLER(name, opc2, opc3) \
4512 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC) \
4514 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
4515 rD(ctx->opcode), Rc(ctx->opcode)); \
4518 /* macchw - macchw. */
4519 GEN_MAC_HANDLER(macchw, 0x0C, 0x05);
4520 /* macchwo - macchwo. */
4521 GEN_MAC_HANDLER(macchwo, 0x0C, 0x15);
4522 /* macchws - macchws. */
4523 GEN_MAC_HANDLER(macchws, 0x0C, 0x07);
4524 /* macchwso - macchwso. */
4525 GEN_MAC_HANDLER(macchwso, 0x0C, 0x17);
4526 /* macchwsu - macchwsu. */
4527 GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06);
4528 /* macchwsuo - macchwsuo. */
4529 GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16);
4530 /* macchwu - macchwu. */
4531 GEN_MAC_HANDLER(macchwu, 0x0C, 0x04);
4532 /* macchwuo - macchwuo. */
4533 GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14);
4534 /* machhw - machhw. */
4535 GEN_MAC_HANDLER(machhw, 0x0C, 0x01);
4536 /* machhwo - machhwo. */
4537 GEN_MAC_HANDLER(machhwo, 0x0C, 0x11);
4538 /* machhws - machhws. */
4539 GEN_MAC_HANDLER(machhws, 0x0C, 0x03);
4540 /* machhwso - machhwso. */
4541 GEN_MAC_HANDLER(machhwso, 0x0C, 0x13);
4542 /* machhwsu - machhwsu. */
4543 GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02);
4544 /* machhwsuo - machhwsuo. */
4545 GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12);
4546 /* machhwu - machhwu. */
4547 GEN_MAC_HANDLER(machhwu, 0x0C, 0x00);
4548 /* machhwuo - machhwuo. */
4549 GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10);
4550 /* maclhw - maclhw. */
4551 GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D);
4552 /* maclhwo - maclhwo. */
4553 GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D);
4554 /* maclhws - maclhws. */
4555 GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F);
4556 /* maclhwso - maclhwso. */
4557 GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F);
4558 /* maclhwu - maclhwu. */
4559 GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C);
4560 /* maclhwuo - maclhwuo. */
4561 GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C);
4562 /* maclhwsu - maclhwsu. */
4563 GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E);
4564 /* maclhwsuo - maclhwsuo. */
4565 GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E);
4566 /* nmacchw - nmacchw. */
4567 GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05);
4568 /* nmacchwo - nmacchwo. */
4569 GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15);
4570 /* nmacchws - nmacchws. */
4571 GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07);
4572 /* nmacchwso - nmacchwso. */
4573 GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17);
4574 /* nmachhw - nmachhw. */
4575 GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01);
4576 /* nmachhwo - nmachhwo. */
4577 GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11);
4578 /* nmachhws - nmachhws. */
4579 GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03);
4580 /* nmachhwso - nmachhwso. */
4581 GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13);
4582 /* nmaclhw - nmaclhw. */
4583 GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D);
4584 /* nmaclhwo - nmaclhwo. */
4585 GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D);
4586 /* nmaclhws - nmaclhws. */
4587 GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F);
4588 /* nmaclhwso - nmaclhwso. */
4589 GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F);
4591 /* mulchw - mulchw. */
4592 GEN_MAC_HANDLER(mulchw, 0x08, 0x05);
4593 /* mulchwu - mulchwu. */
4594 GEN_MAC_HANDLER(mulchwu, 0x08, 0x04);
4595 /* mulhhw - mulhhw. */
4596 GEN_MAC_HANDLER(mulhhw, 0x08, 0x01);
4597 /* mulhhwu - mulhhwu. */
4598 GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00);
4599 /* mullhw - mullhw. */
4600 GEN_MAC_HANDLER(mullhw, 0x08, 0x0D);
4601 /* mullhwu - mullhwu. */
4602 GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C);
4605 GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_EMB_COMMON)
4607 #if defined(CONFIG_USER_ONLY)
4608 GEN_EXCP_PRIVREG(ctx);
4610 uint32_t dcrn = SPR(ctx->opcode);
4612 if (unlikely(!ctx->supervisor)) {
4613 GEN_EXCP_PRIVREG(ctx);
4616 gen_op_set_T0(dcrn);
4618 gen_op_store_T0_gpr(rD(ctx->opcode));
4623 GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_EMB_COMMON)
4625 #if defined(CONFIG_USER_ONLY)
4626 GEN_EXCP_PRIVREG(ctx);
4628 uint32_t dcrn = SPR(ctx->opcode);
4630 if (unlikely(!ctx->supervisor)) {
4631 GEN_EXCP_PRIVREG(ctx);
4634 gen_op_set_T0(dcrn);
4635 gen_op_load_gpr_T1(rS(ctx->opcode));
4641 /* XXX: not implemented on 440 ? */
4642 GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_BOOKE_EXT)
4644 #if defined(CONFIG_USER_ONLY)
4645 GEN_EXCP_PRIVREG(ctx);
4647 if (unlikely(!ctx->supervisor)) {
4648 GEN_EXCP_PRIVREG(ctx);
4651 gen_op_load_gpr_T0(rA(ctx->opcode));
4653 gen_op_store_T0_gpr(rD(ctx->opcode));
4654 /* Note: Rc update flag set leads to undefined state of Rc0 */
4659 /* XXX: not implemented on 440 ? */
4660 GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_BOOKE_EXT)
4662 #if defined(CONFIG_USER_ONLY)
4663 GEN_EXCP_PRIVREG(ctx);
4665 if (unlikely(!ctx->supervisor)) {
4666 GEN_EXCP_PRIVREG(ctx);
4669 gen_op_load_gpr_T0(rA(ctx->opcode));
4670 gen_op_load_gpr_T1(rS(ctx->opcode));
4672 /* Note: Rc update flag set leads to undefined state of Rc0 */
4676 /* mfdcrux (PPC 460) : user-mode access to DCR */
4677 GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX)
4679 gen_op_load_gpr_T0(rA(ctx->opcode));
4681 gen_op_store_T0_gpr(rD(ctx->opcode));
4682 /* Note: Rc update flag set leads to undefined state of Rc0 */
4685 /* mtdcrux (PPC 460) : user-mode access to DCR */
4686 GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX)
4688 gen_op_load_gpr_T0(rA(ctx->opcode));
4689 gen_op_load_gpr_T1(rS(ctx->opcode));
4691 /* Note: Rc update flag set leads to undefined state of Rc0 */
4695 GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON)
4697 #if defined(CONFIG_USER_ONLY)
4698 GEN_EXCP_PRIVOPC(ctx);
4700 if (unlikely(!ctx->supervisor)) {
4701 GEN_EXCP_PRIVOPC(ctx);
4704 /* interpreted as no-op */
4709 GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON)
4711 #if defined(CONFIG_USER_ONLY)
4712 GEN_EXCP_PRIVOPC(ctx);
4714 if (unlikely(!ctx->supervisor)) {
4715 GEN_EXCP_PRIVOPC(ctx);
4718 gen_addr_reg_index(ctx);
4720 gen_op_store_T0_gpr(rD(ctx->opcode));
4725 GEN_HANDLER(icbt_40x, 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT)
4727 /* interpreted as no-op */
4728 /* XXX: specification say this is treated as a load by the MMU
4729 * but does not generate any exception
4734 GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON)
4736 #if defined(CONFIG_USER_ONLY)
4737 GEN_EXCP_PRIVOPC(ctx);
4739 if (unlikely(!ctx->supervisor)) {
4740 GEN_EXCP_PRIVOPC(ctx);
4743 /* interpreted as no-op */
4748 GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON)
4750 #if defined(CONFIG_USER_ONLY)
4751 GEN_EXCP_PRIVOPC(ctx);
4753 if (unlikely(!ctx->supervisor)) {
4754 GEN_EXCP_PRIVOPC(ctx);
4757 /* interpreted as no-op */
4761 /* rfci (supervisor only) */
4762 GEN_HANDLER(rfci_40x, 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP)
4764 #if defined(CONFIG_USER_ONLY)
4765 GEN_EXCP_PRIVOPC(ctx);
4767 if (unlikely(!ctx->supervisor)) {
4768 GEN_EXCP_PRIVOPC(ctx);
4771 /* Restore CPU state */
4777 GEN_HANDLER(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE)
4779 #if defined(CONFIG_USER_ONLY)
4780 GEN_EXCP_PRIVOPC(ctx);
4782 if (unlikely(!ctx->supervisor)) {
4783 GEN_EXCP_PRIVOPC(ctx);
4786 /* Restore CPU state */
4792 /* BookE specific */
4793 /* XXX: not implemented on 440 ? */
4794 GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_BOOKE_EXT)
4796 #if defined(CONFIG_USER_ONLY)
4797 GEN_EXCP_PRIVOPC(ctx);
4799 if (unlikely(!ctx->supervisor)) {
4800 GEN_EXCP_PRIVOPC(ctx);
4803 /* Restore CPU state */
4809 /* XXX: not implemented on 440 ? */
4810 GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI)
4812 #if defined(CONFIG_USER_ONLY)
4813 GEN_EXCP_PRIVOPC(ctx);
4815 if (unlikely(!ctx->supervisor)) {
4816 GEN_EXCP_PRIVOPC(ctx);
4819 /* Restore CPU state */
4825 /* TLB management - PowerPC 405 implementation */
4827 GEN_HANDLER(tlbre_40x, 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB)
4829 #if defined(CONFIG_USER_ONLY)
4830 GEN_EXCP_PRIVOPC(ctx);
4832 if (unlikely(!ctx->supervisor)) {
4833 GEN_EXCP_PRIVOPC(ctx);
4836 switch (rB(ctx->opcode)) {
4838 gen_op_load_gpr_T0(rA(ctx->opcode));
4839 gen_op_4xx_tlbre_hi();
4840 gen_op_store_T0_gpr(rD(ctx->opcode));
4843 gen_op_load_gpr_T0(rA(ctx->opcode));
4844 gen_op_4xx_tlbre_lo();
4845 gen_op_store_T0_gpr(rD(ctx->opcode));
4848 GEN_EXCP_INVAL(ctx);
4854 /* tlbsx - tlbsx. */
4855 GEN_HANDLER(tlbsx_40x, 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB)
4857 #if defined(CONFIG_USER_ONLY)
4858 GEN_EXCP_PRIVOPC(ctx);
4860 if (unlikely(!ctx->supervisor)) {
4861 GEN_EXCP_PRIVOPC(ctx);
4864 gen_addr_reg_index(ctx);
4865 if (Rc(ctx->opcode))
4866 gen_op_4xx_tlbsx_();
4869 gen_op_store_T0_gpr(rD(ctx->opcode));
4874 GEN_HANDLER(tlbwe_40x, 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB)
4876 #if defined(CONFIG_USER_ONLY)
4877 GEN_EXCP_PRIVOPC(ctx);
4879 if (unlikely(!ctx->supervisor)) {
4880 GEN_EXCP_PRIVOPC(ctx);
4883 switch (rB(ctx->opcode)) {
4885 gen_op_load_gpr_T0(rA(ctx->opcode));
4886 gen_op_load_gpr_T1(rS(ctx->opcode));
4887 gen_op_4xx_tlbwe_hi();
4890 gen_op_load_gpr_T0(rA(ctx->opcode));
4891 gen_op_load_gpr_T1(rS(ctx->opcode));
4892 gen_op_4xx_tlbwe_lo();
4895 GEN_EXCP_INVAL(ctx);
4901 /* TLB management - PowerPC 440 implementation */
4903 GEN_HANDLER(tlbre_440, 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE)
4905 #if defined(CONFIG_USER_ONLY)
4906 GEN_EXCP_PRIVOPC(ctx);
4908 if (unlikely(!ctx->supervisor)) {
4909 GEN_EXCP_PRIVOPC(ctx);
4912 switch (rB(ctx->opcode)) {
4916 gen_op_load_gpr_T0(rA(ctx->opcode));
4917 gen_op_440_tlbre(rB(ctx->opcode));
4918 gen_op_store_T0_gpr(rD(ctx->opcode));
4921 GEN_EXCP_INVAL(ctx);
4927 /* tlbsx - tlbsx. */
4928 GEN_HANDLER(tlbsx_440, 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE)
4930 #if defined(CONFIG_USER_ONLY)
4931 GEN_EXCP_PRIVOPC(ctx);
4933 if (unlikely(!ctx->supervisor)) {
4934 GEN_EXCP_PRIVOPC(ctx);
4937 gen_addr_reg_index(ctx);
4938 if (Rc(ctx->opcode))
4939 gen_op_440_tlbsx_();
4942 gen_op_store_T0_gpr(rD(ctx->opcode));
4947 GEN_HANDLER(tlbwe_440, 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE)
4949 #if defined(CONFIG_USER_ONLY)
4950 GEN_EXCP_PRIVOPC(ctx);
4952 if (unlikely(!ctx->supervisor)) {
4953 GEN_EXCP_PRIVOPC(ctx);
4956 switch (rB(ctx->opcode)) {
4960 gen_op_load_gpr_T0(rA(ctx->opcode));
4961 gen_op_load_gpr_T1(rS(ctx->opcode));
4962 gen_op_440_tlbwe(rB(ctx->opcode));
4965 GEN_EXCP_INVAL(ctx);
4972 GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_EMB_COMMON)
4974 #if defined(CONFIG_USER_ONLY)
4975 GEN_EXCP_PRIVOPC(ctx);
4977 if (unlikely(!ctx->supervisor)) {
4978 GEN_EXCP_PRIVOPC(ctx);
4981 gen_op_load_gpr_T0(rD(ctx->opcode));
4983 /* Stop translation to have a chance to raise an exception
4984 * if we just set msr_ee to 1
4991 GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000EFC01, PPC_EMB_COMMON)
4993 #if defined(CONFIG_USER_ONLY)
4994 GEN_EXCP_PRIVOPC(ctx);
4996 if (unlikely(!ctx->supervisor)) {
4997 GEN_EXCP_PRIVOPC(ctx);
5000 gen_op_set_T0(ctx->opcode & 0x00010000);
5002 /* Stop translation to have a chance to raise an exception
5003 * if we just set msr_ee to 1
5009 /* PowerPC 440 specific instructions */
5011 GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC)
5013 gen_op_load_gpr_T0(rS(ctx->opcode));
5014 gen_op_load_gpr_T1(rB(ctx->opcode));
5016 gen_op_store_T0_gpr(rA(ctx->opcode));
5017 gen_op_store_xer_bc();
5018 if (Rc(ctx->opcode)) {
5019 gen_op_440_dlmzb_update_Rc();
5020 gen_op_store_T0_crf(0);
5024 /* mbar replaces eieio on 440 */
5025 GEN_HANDLER(mbar, 0x1F, 0x16, 0x13, 0x001FF801, PPC_BOOKE)
5027 /* interpreted as no-op */
5030 /* msync replaces sync on 440 */
5031 GEN_HANDLER(msync, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE)
5033 /* interpreted as no-op */
5037 GEN_HANDLER(icbt_440, 0x1F, 0x16, 0x00, 0x03E00001, PPC_BOOKE)
5039 /* interpreted as no-op */
5040 /* XXX: specification say this is treated as a load by the MMU
5041 * but does not generate any exception
5045 #if defined(TARGET_PPCEMB)
5046 /*** SPE extension ***/
5048 /* Register moves */
5049 GEN32(gen_op_load_gpr64_T0, gen_op_load_gpr64_T0_gpr);
5050 GEN32(gen_op_load_gpr64_T1, gen_op_load_gpr64_T1_gpr);
5052 GEN32(gen_op_load_gpr64_T2, gen_op_load_gpr64_T2_gpr);
5055 GEN32(gen_op_store_T0_gpr64, gen_op_store_T0_gpr64_gpr);
5056 GEN32(gen_op_store_T1_gpr64, gen_op_store_T1_gpr64_gpr);
5058 GEN32(gen_op_store_T2_gpr64, gen_op_store_T2_gpr64_gpr);
5061 #define GEN_SPE(name0, name1, opc2, opc3, inval, type) \
5062 GEN_HANDLER(name0##_##name1, 0x04, opc2, opc3, inval, type) \
5064 if (Rc(ctx->opcode)) \
5070 /* Handler for undefined SPE opcodes */
5071 static inline void gen_speundef (DisasContext *ctx)
5073 GEN_EXCP_INVAL(ctx);
5076 /* SPE load and stores */
5077 static inline void gen_addr_spe_imm_index (DisasContext *ctx, int sh)
5079 target_long simm = rB(ctx->opcode);
5081 if (rA(ctx->opcode) == 0) {
5082 gen_set_T0(simm << sh);
5084 gen_op_load_gpr_T0(rA(ctx->opcode));
5085 if (likely(simm != 0))
5086 gen_op_addi(simm << sh);
5090 #define op_spe_ldst(name) (*gen_op_##name[ctx->mem_idx])()
5091 #if defined(CONFIG_USER_ONLY)
5092 #if defined(TARGET_PPC64)
5093 #define OP_SPE_LD_TABLE(name) \
5094 static GenOpFunc *gen_op_spe_l##name[] = { \
5095 &gen_op_spe_l##name##_raw, \
5096 &gen_op_spe_l##name##_le_raw, \
5097 &gen_op_spe_l##name##_64_raw, \
5098 &gen_op_spe_l##name##_le_64_raw, \
5100 #define OP_SPE_ST_TABLE(name) \
5101 static GenOpFunc *gen_op_spe_st##name[] = { \
5102 &gen_op_spe_st##name##_raw, \
5103 &gen_op_spe_st##name##_le_raw, \
5104 &gen_op_spe_st##name##_64_raw, \
5105 &gen_op_spe_st##name##_le_64_raw, \
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##_raw, \
5111 &gen_op_spe_l##name##_le_raw, \
5113 #define OP_SPE_ST_TABLE(name) \
5114 static GenOpFunc *gen_op_spe_st##name[] = { \
5115 &gen_op_spe_st##name##_raw, \
5116 &gen_op_spe_st##name##_le_raw, \
5118 #endif /* defined(TARGET_PPC64) */
5119 #else /* defined(CONFIG_USER_ONLY) */
5120 #if defined(TARGET_PPC64)
5121 #define OP_SPE_LD_TABLE(name) \
5122 static GenOpFunc *gen_op_spe_l##name[] = { \
5123 &gen_op_spe_l##name##_user, \
5124 &gen_op_spe_l##name##_le_user, \
5125 &gen_op_spe_l##name##_kernel, \
5126 &gen_op_spe_l##name##_le_kernel, \
5127 &gen_op_spe_l##name##_64_user, \
5128 &gen_op_spe_l##name##_le_64_user, \
5129 &gen_op_spe_l##name##_64_kernel, \
5130 &gen_op_spe_l##name##_le_64_kernel, \
5132 #define OP_SPE_ST_TABLE(name) \
5133 static GenOpFunc *gen_op_spe_st##name[] = { \
5134 &gen_op_spe_st##name##_user, \
5135 &gen_op_spe_st##name##_le_user, \
5136 &gen_op_spe_st##name##_kernel, \
5137 &gen_op_spe_st##name##_le_kernel, \
5138 &gen_op_spe_st##name##_64_user, \
5139 &gen_op_spe_st##name##_le_64_user, \
5140 &gen_op_spe_st##name##_64_kernel, \
5141 &gen_op_spe_st##name##_le_64_kernel, \
5143 #else /* defined(TARGET_PPC64) */
5144 #define OP_SPE_LD_TABLE(name) \
5145 static GenOpFunc *gen_op_spe_l##name[] = { \
5146 &gen_op_spe_l##name##_user, \
5147 &gen_op_spe_l##name##_le_user, \
5148 &gen_op_spe_l##name##_kernel, \
5149 &gen_op_spe_l##name##_le_kernel, \
5151 #define OP_SPE_ST_TABLE(name) \
5152 static GenOpFunc *gen_op_spe_st##name[] = { \
5153 &gen_op_spe_st##name##_user, \
5154 &gen_op_spe_st##name##_le_user, \
5155 &gen_op_spe_st##name##_kernel, \
5156 &gen_op_spe_st##name##_le_kernel, \
5158 #endif /* defined(TARGET_PPC64) */
5159 #endif /* defined(CONFIG_USER_ONLY) */
5161 #define GEN_SPE_LD(name, sh) \
5162 static inline void gen_evl##name (DisasContext *ctx) \
5164 if (unlikely(!ctx->spe_enabled)) { \
5165 GEN_EXCP_NO_AP(ctx); \
5168 gen_addr_spe_imm_index(ctx, sh); \
5169 op_spe_ldst(spe_l##name); \
5170 gen_op_store_T1_gpr64(rD(ctx->opcode)); \
5173 #define GEN_SPE_LDX(name) \
5174 static inline void gen_evl##name##x (DisasContext *ctx) \
5176 if (unlikely(!ctx->spe_enabled)) { \
5177 GEN_EXCP_NO_AP(ctx); \
5180 gen_addr_reg_index(ctx); \
5181 op_spe_ldst(spe_l##name); \
5182 gen_op_store_T1_gpr64(rD(ctx->opcode)); \
5185 #define GEN_SPEOP_LD(name, sh) \
5186 OP_SPE_LD_TABLE(name); \
5187 GEN_SPE_LD(name, sh); \
5190 #define GEN_SPE_ST(name, sh) \
5191 static inline void gen_evst##name (DisasContext *ctx) \
5193 if (unlikely(!ctx->spe_enabled)) { \
5194 GEN_EXCP_NO_AP(ctx); \
5197 gen_addr_spe_imm_index(ctx, sh); \
5198 gen_op_load_gpr64_T1(rS(ctx->opcode)); \
5199 op_spe_ldst(spe_st##name); \
5202 #define GEN_SPE_STX(name) \
5203 static inline void gen_evst##name##x (DisasContext *ctx) \
5205 if (unlikely(!ctx->spe_enabled)) { \
5206 GEN_EXCP_NO_AP(ctx); \
5209 gen_addr_reg_index(ctx); \
5210 gen_op_load_gpr64_T1(rS(ctx->opcode)); \
5211 op_spe_ldst(spe_st##name); \
5214 #define GEN_SPEOP_ST(name, sh) \
5215 OP_SPE_ST_TABLE(name); \
5216 GEN_SPE_ST(name, sh); \
5219 #define GEN_SPEOP_LDST(name, sh) \
5220 GEN_SPEOP_LD(name, sh); \
5221 GEN_SPEOP_ST(name, sh)
5223 /* SPE arithmetic and logic */
5224 #define GEN_SPEOP_ARITH2(name) \
5225 static inline void gen_##name (DisasContext *ctx) \
5227 if (unlikely(!ctx->spe_enabled)) { \
5228 GEN_EXCP_NO_AP(ctx); \
5231 gen_op_load_gpr64_T0(rA(ctx->opcode)); \
5232 gen_op_load_gpr64_T1(rB(ctx->opcode)); \
5234 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5237 #define GEN_SPEOP_ARITH1(name) \
5238 static inline void gen_##name (DisasContext *ctx) \
5240 if (unlikely(!ctx->spe_enabled)) { \
5241 GEN_EXCP_NO_AP(ctx); \
5244 gen_op_load_gpr64_T0(rA(ctx->opcode)); \
5246 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5249 #define GEN_SPEOP_COMP(name) \
5250 static inline void gen_##name (DisasContext *ctx) \
5252 if (unlikely(!ctx->spe_enabled)) { \
5253 GEN_EXCP_NO_AP(ctx); \
5256 gen_op_load_gpr64_T0(rA(ctx->opcode)); \
5257 gen_op_load_gpr64_T1(rB(ctx->opcode)); \
5259 gen_op_store_T0_crf(crfD(ctx->opcode)); \
5263 GEN_SPEOP_ARITH2(evand);
5264 GEN_SPEOP_ARITH2(evandc);
5265 GEN_SPEOP_ARITH2(evxor);
5266 GEN_SPEOP_ARITH2(evor);
5267 GEN_SPEOP_ARITH2(evnor);
5268 GEN_SPEOP_ARITH2(eveqv);
5269 GEN_SPEOP_ARITH2(evorc);
5270 GEN_SPEOP_ARITH2(evnand);
5271 GEN_SPEOP_ARITH2(evsrwu);
5272 GEN_SPEOP_ARITH2(evsrws);
5273 GEN_SPEOP_ARITH2(evslw);
5274 GEN_SPEOP_ARITH2(evrlw);
5275 GEN_SPEOP_ARITH2(evmergehi);
5276 GEN_SPEOP_ARITH2(evmergelo);
5277 GEN_SPEOP_ARITH2(evmergehilo);
5278 GEN_SPEOP_ARITH2(evmergelohi);
5281 GEN_SPEOP_ARITH2(evaddw);
5282 GEN_SPEOP_ARITH2(evsubfw);
5283 GEN_SPEOP_ARITH1(evabs);
5284 GEN_SPEOP_ARITH1(evneg);
5285 GEN_SPEOP_ARITH1(evextsb);
5286 GEN_SPEOP_ARITH1(evextsh);
5287 GEN_SPEOP_ARITH1(evrndw);
5288 GEN_SPEOP_ARITH1(evcntlzw);
5289 GEN_SPEOP_ARITH1(evcntlsw);
5290 static inline void gen_brinc (DisasContext *ctx)
5292 /* Note: brinc is usable even if SPE is disabled */
5293 gen_op_load_gpr64_T0(rA(ctx->opcode));
5294 gen_op_load_gpr64_T1(rB(ctx->opcode));
5296 gen_op_store_T0_gpr64(rD(ctx->opcode));
5299 #define GEN_SPEOP_ARITH_IMM2(name) \
5300 static inline void gen_##name##i (DisasContext *ctx) \
5302 if (unlikely(!ctx->spe_enabled)) { \
5303 GEN_EXCP_NO_AP(ctx); \
5306 gen_op_load_gpr64_T0(rB(ctx->opcode)); \
5307 gen_op_splatwi_T1_64(rA(ctx->opcode)); \
5309 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5312 #define GEN_SPEOP_LOGIC_IMM2(name) \
5313 static inline void gen_##name##i (DisasContext *ctx) \
5315 if (unlikely(!ctx->spe_enabled)) { \
5316 GEN_EXCP_NO_AP(ctx); \
5319 gen_op_load_gpr64_T0(rA(ctx->opcode)); \
5320 gen_op_splatwi_T1_64(rB(ctx->opcode)); \
5322 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5325 GEN_SPEOP_ARITH_IMM2(evaddw);
5326 #define gen_evaddiw gen_evaddwi
5327 GEN_SPEOP_ARITH_IMM2(evsubfw);
5328 #define gen_evsubifw gen_evsubfwi
5329 GEN_SPEOP_LOGIC_IMM2(evslw);
5330 GEN_SPEOP_LOGIC_IMM2(evsrwu);
5331 #define gen_evsrwis gen_evsrwsi
5332 GEN_SPEOP_LOGIC_IMM2(evsrws);
5333 #define gen_evsrwiu gen_evsrwui
5334 GEN_SPEOP_LOGIC_IMM2(evrlw);
5336 static inline void gen_evsplati (DisasContext *ctx)
5338 int32_t imm = (int32_t)(rA(ctx->opcode) << 27) >> 27;
5340 gen_op_splatwi_T0_64(imm);
5341 gen_op_store_T0_gpr64(rD(ctx->opcode));
5344 static inline void gen_evsplatfi (DisasContext *ctx)
5346 uint32_t imm = rA(ctx->opcode) << 27;
5348 gen_op_splatwi_T0_64(imm);
5349 gen_op_store_T0_gpr64(rD(ctx->opcode));
5353 GEN_SPEOP_COMP(evcmpgtu);
5354 GEN_SPEOP_COMP(evcmpgts);
5355 GEN_SPEOP_COMP(evcmpltu);
5356 GEN_SPEOP_COMP(evcmplts);
5357 GEN_SPEOP_COMP(evcmpeq);
5359 GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, PPC_SPE); ////
5360 GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, PPC_SPE);
5361 GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, PPC_SPE); ////
5362 GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, PPC_SPE);
5363 GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, PPC_SPE); ////
5364 GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, PPC_SPE); ////
5365 GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, PPC_SPE); ////
5366 GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x00000000, PPC_SPE); //
5367 GEN_SPE(speundef, evand, 0x08, 0x08, 0x00000000, PPC_SPE); ////
5368 GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, PPC_SPE); ////
5369 GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, PPC_SPE); ////
5370 GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, PPC_SPE); ////
5371 GEN_SPE(speundef, evorc, 0x0D, 0x08, 0x00000000, PPC_SPE); ////
5372 GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, PPC_SPE); ////
5373 GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, PPC_SPE); ////
5374 GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, PPC_SPE);
5375 GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, PPC_SPE); ////
5376 GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, PPC_SPE);
5377 GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, PPC_SPE); //
5378 GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, PPC_SPE);
5379 GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, PPC_SPE); ////
5380 GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, PPC_SPE); ////
5381 GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, PPC_SPE); ////
5382 GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, PPC_SPE); ////
5383 GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, PPC_SPE); ////
5385 static inline void gen_evsel (DisasContext *ctx)
5387 if (unlikely(!ctx->spe_enabled)) {
5388 GEN_EXCP_NO_AP(ctx);
5391 gen_op_load_crf_T0(ctx->opcode & 0x7);
5392 gen_op_load_gpr64_T0(rA(ctx->opcode));
5393 gen_op_load_gpr64_T1(rB(ctx->opcode));
5395 gen_op_store_T0_gpr64(rD(ctx->opcode));
5398 GEN_HANDLER(evsel0, 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE)
5402 GEN_HANDLER(evsel1, 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE)
5406 GEN_HANDLER(evsel2, 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE)
5410 GEN_HANDLER(evsel3, 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE)
5415 /* Load and stores */
5416 #if defined(TARGET_PPC64)
5417 /* In that case, we already have 64 bits load & stores
5418 * so, spe_ldd is equivalent to ld and spe_std is equivalent to std
5420 #if defined(CONFIG_USER_ONLY)
5421 #define gen_op_spe_ldd_raw gen_op_ld_raw
5422 #define gen_op_spe_ldd_64_raw gen_op_ld_64_raw
5423 #define gen_op_spe_ldd_le_raw gen_op_ld_le_raw
5424 #define gen_op_spe_ldd_le_64_raw gen_op_ld_le_64_raw
5425 #define gen_op_spe_stdd_raw gen_op_ld_raw
5426 #define gen_op_spe_stdd_64_raw gen_op_std_64_raw
5427 #define gen_op_spe_stdd_le_raw gen_op_std_le_raw
5428 #define gen_op_spe_stdd_le_64_raw gen_op_std_le_64_raw
5429 #else /* defined(CONFIG_USER_ONLY) */
5430 #define gen_op_spe_ldd_kernel gen_op_ld_kernel
5431 #define gen_op_spe_ldd_64_kernel gen_op_ld_64_kernel
5432 #define gen_op_spe_ldd_le_kernel gen_op_ld_kernel
5433 #define gen_op_spe_ldd_le_64_kernel gen_op_ld_64_kernel
5434 #define gen_op_spe_ldd_user gen_op_ld_user
5435 #define gen_op_spe_ldd_64_user gen_op_ld_64_user
5436 #define gen_op_spe_ldd_le_user gen_op_ld_le_user
5437 #define gen_op_spe_ldd_le_64_user gen_op_ld_le_64_user
5438 #define gen_op_spe_stdd_kernel gen_op_std_kernel
5439 #define gen_op_spe_stdd_64_kernel gen_op_std_64_kernel
5440 #define gen_op_spe_stdd_le_kernel gen_op_std_kernel
5441 #define gen_op_spe_stdd_le_64_kernel gen_op_std_64_kernel
5442 #define gen_op_spe_stdd_user gen_op_std_user
5443 #define gen_op_spe_stdd_64_user gen_op_std_64_user
5444 #define gen_op_spe_stdd_le_user gen_op_std_le_user
5445 #define gen_op_spe_stdd_le_64_user gen_op_std_le_64_user
5446 #endif /* defined(CONFIG_USER_ONLY) */
5447 #endif /* defined(TARGET_PPC64) */
5448 GEN_SPEOP_LDST(dd, 3);
5449 GEN_SPEOP_LDST(dw, 3);
5450 GEN_SPEOP_LDST(dh, 3);
5451 GEN_SPEOP_LDST(whe, 2);
5452 GEN_SPEOP_LD(whou, 2);
5453 GEN_SPEOP_LD(whos, 2);
5454 GEN_SPEOP_ST(who, 2);
5456 #if defined(TARGET_PPC64)
5457 /* In that case, spe_stwwo is equivalent to stw */
5458 #if defined(CONFIG_USER_ONLY)
5459 #define gen_op_spe_stwwo_raw gen_op_stw_raw
5460 #define gen_op_spe_stwwo_le_raw gen_op_stw_le_raw
5461 #define gen_op_spe_stwwo_64_raw gen_op_stw_64_raw
5462 #define gen_op_spe_stwwo_le_64_raw gen_op_stw_le_64_raw
5464 #define gen_op_spe_stwwo_user gen_op_stw_user
5465 #define gen_op_spe_stwwo_le_user gen_op_stw_le_user
5466 #define gen_op_spe_stwwo_64_user gen_op_stw_64_user
5467 #define gen_op_spe_stwwo_le_64_user gen_op_stw_le_64_user
5468 #define gen_op_spe_stwwo_kernel gen_op_stw_kernel
5469 #define gen_op_spe_stwwo_le_kernel gen_op_stw_le_kernel
5470 #define gen_op_spe_stwwo_64_kernel gen_op_stw_64_kernel
5471 #define gen_op_spe_stwwo_le_64_kernel gen_op_stw_le_64_kernel
5474 #define _GEN_OP_SPE_STWWE(suffix) \
5475 static inline void gen_op_spe_stwwe_##suffix (void) \
5477 gen_op_srli32_T1_64(); \
5478 gen_op_spe_stwwo_##suffix(); \
5480 #define _GEN_OP_SPE_STWWE_LE(suffix) \
5481 static inline void gen_op_spe_stwwe_le_##suffix (void) \
5483 gen_op_srli32_T1_64(); \
5484 gen_op_spe_stwwo_le_##suffix(); \
5486 #if defined(TARGET_PPC64)
5487 #define GEN_OP_SPE_STWWE(suffix) \
5488 _GEN_OP_SPE_STWWE(suffix); \
5489 _GEN_OP_SPE_STWWE_LE(suffix); \
5490 static inline void gen_op_spe_stwwe_64_##suffix (void) \
5492 gen_op_srli32_T1_64(); \
5493 gen_op_spe_stwwo_64_##suffix(); \
5495 static inline void gen_op_spe_stwwe_le_64_##suffix (void) \
5497 gen_op_srli32_T1_64(); \
5498 gen_op_spe_stwwo_le_64_##suffix(); \
5501 #define GEN_OP_SPE_STWWE(suffix) \
5502 _GEN_OP_SPE_STWWE(suffix); \
5503 _GEN_OP_SPE_STWWE_LE(suffix)
5505 #if defined(CONFIG_USER_ONLY)
5506 GEN_OP_SPE_STWWE(raw);
5507 #else /* defined(CONFIG_USER_ONLY) */
5508 GEN_OP_SPE_STWWE(kernel);
5509 GEN_OP_SPE_STWWE(user);
5510 #endif /* defined(CONFIG_USER_ONLY) */
5511 GEN_SPEOP_ST(wwe, 2);
5512 GEN_SPEOP_ST(wwo, 2);
5514 #define GEN_SPE_LDSPLAT(name, op, suffix) \
5515 static inline void gen_op_spe_l##name##_##suffix (void) \
5517 gen_op_##op##_##suffix(); \
5518 gen_op_splatw_T1_64(); \
5521 #define GEN_OP_SPE_LHE(suffix) \
5522 static inline void gen_op_spe_lhe_##suffix (void) \
5524 gen_op_spe_lh_##suffix(); \
5525 gen_op_sli16_T1_64(); \
5528 #define GEN_OP_SPE_LHX(suffix) \
5529 static inline void gen_op_spe_lhx_##suffix (void) \
5531 gen_op_spe_lh_##suffix(); \
5532 gen_op_extsh_T1_64(); \
5535 #if defined(CONFIG_USER_ONLY)
5536 GEN_OP_SPE_LHE(raw);
5537 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, raw);
5538 GEN_OP_SPE_LHE(le_raw);
5539 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_raw);
5540 GEN_SPE_LDSPLAT(hhousplat, spe_lh, raw);
5541 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_raw);
5542 GEN_OP_SPE_LHX(raw);
5543 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, raw);
5544 GEN_OP_SPE_LHX(le_raw);
5545 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_raw);
5546 #if defined(TARGET_PPC64)
5547 GEN_OP_SPE_LHE(64_raw);
5548 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_raw);
5549 GEN_OP_SPE_LHE(le_64_raw);
5550 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_raw);
5551 GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_raw);
5552 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_raw);
5553 GEN_OP_SPE_LHX(64_raw);
5554 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_raw);
5555 GEN_OP_SPE_LHX(le_64_raw);
5556 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_raw);
5559 GEN_OP_SPE_LHE(kernel);
5560 GEN_OP_SPE_LHE(user);
5561 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, kernel);
5562 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, user);
5563 GEN_OP_SPE_LHE(le_kernel);
5564 GEN_OP_SPE_LHE(le_user);
5565 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_kernel);
5566 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_user);
5567 GEN_SPE_LDSPLAT(hhousplat, spe_lh, kernel);
5568 GEN_SPE_LDSPLAT(hhousplat, spe_lh, user);
5569 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_kernel);
5570 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_user);
5571 GEN_OP_SPE_LHX(kernel);
5572 GEN_OP_SPE_LHX(user);
5573 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, kernel);
5574 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, user);
5575 GEN_OP_SPE_LHX(le_kernel);
5576 GEN_OP_SPE_LHX(le_user);
5577 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_kernel);
5578 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_user);
5579 #if defined(TARGET_PPC64)
5580 GEN_OP_SPE_LHE(64_kernel);
5581 GEN_OP_SPE_LHE(64_user);
5582 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_kernel);
5583 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, 64_user);
5584 GEN_OP_SPE_LHE(le_64_kernel);
5585 GEN_OP_SPE_LHE(le_64_user);
5586 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_kernel);
5587 GEN_SPE_LDSPLAT(hhesplat, spe_lhe, le_64_user);
5588 GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_kernel);
5589 GEN_SPE_LDSPLAT(hhousplat, spe_lh, 64_user);
5590 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_kernel);
5591 GEN_SPE_LDSPLAT(hhousplat, spe_lh, le_64_user);
5592 GEN_OP_SPE_LHX(64_kernel);
5593 GEN_OP_SPE_LHX(64_user);
5594 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_kernel);
5595 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, 64_user);
5596 GEN_OP_SPE_LHX(le_64_kernel);
5597 GEN_OP_SPE_LHX(le_64_user);
5598 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_kernel);
5599 GEN_SPE_LDSPLAT(hhossplat, spe_lhx, le_64_user);
5602 GEN_SPEOP_LD(hhesplat, 1);
5603 GEN_SPEOP_LD(hhousplat, 1);
5604 GEN_SPEOP_LD(hhossplat, 1);
5605 GEN_SPEOP_LD(wwsplat, 2);
5606 GEN_SPEOP_LD(whsplat, 2);
5608 GEN_SPE(evlddx, evldd, 0x00, 0x0C, 0x00000000, PPC_SPE); //
5609 GEN_SPE(evldwx, evldw, 0x01, 0x0C, 0x00000000, PPC_SPE); //
5610 GEN_SPE(evldhx, evldh, 0x02, 0x0C, 0x00000000, PPC_SPE); //
5611 GEN_SPE(evlhhesplatx, evlhhesplat, 0x04, 0x0C, 0x00000000, PPC_SPE); //
5612 GEN_SPE(evlhhousplatx, evlhhousplat, 0x06, 0x0C, 0x00000000, PPC_SPE); //
5613 GEN_SPE(evlhhossplatx, evlhhossplat, 0x07, 0x0C, 0x00000000, PPC_SPE); //
5614 GEN_SPE(evlwhex, evlwhe, 0x08, 0x0C, 0x00000000, PPC_SPE); //
5615 GEN_SPE(evlwhoux, evlwhou, 0x0A, 0x0C, 0x00000000, PPC_SPE); //
5616 GEN_SPE(evlwhosx, evlwhos, 0x0B, 0x0C, 0x00000000, PPC_SPE); //
5617 GEN_SPE(evlwwsplatx, evlwwsplat, 0x0C, 0x0C, 0x00000000, PPC_SPE); //
5618 GEN_SPE(evlwhsplatx, evlwhsplat, 0x0E, 0x0C, 0x00000000, PPC_SPE); //
5619 GEN_SPE(evstddx, evstdd, 0x10, 0x0C, 0x00000000, PPC_SPE); //
5620 GEN_SPE(evstdwx, evstdw, 0x11, 0x0C, 0x00000000, PPC_SPE); //
5621 GEN_SPE(evstdhx, evstdh, 0x12, 0x0C, 0x00000000, PPC_SPE); //
5622 GEN_SPE(evstwhex, evstwhe, 0x18, 0x0C, 0x00000000, PPC_SPE); //
5623 GEN_SPE(evstwhox, evstwho, 0x1A, 0x0C, 0x00000000, PPC_SPE); //
5624 GEN_SPE(evstwwex, evstwwe, 0x1C, 0x0C, 0x00000000, PPC_SPE); //
5625 GEN_SPE(evstwwox, evstwwo, 0x1E, 0x0C, 0x00000000, PPC_SPE); //
5627 /* Multiply and add - TODO */
5629 GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0x00000000, PPC_SPE);
5630 GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0x00000000, PPC_SPE);
5631 GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, PPC_SPE);
5632 GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0x00000000, PPC_SPE);
5633 GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, PPC_SPE);
5634 GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0x00000000, PPC_SPE);
5635 GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0x00000000, PPC_SPE);
5636 GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0x00000000, PPC_SPE);
5637 GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, PPC_SPE);
5638 GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0x00000000, PPC_SPE);
5639 GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, PPC_SPE);
5640 GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0x00000000, PPC_SPE);
5642 GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0x00000000, PPC_SPE);
5643 GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, PPC_SPE);
5644 GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, PPC_SPE);
5645 GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0x00000000, PPC_SPE);
5646 GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0x00000000, PPC_SPE);
5647 GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, PPC_SPE);
5648 GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0x00000000, PPC_SPE);
5649 GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0x00000000, PPC_SPE);
5650 GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, PPC_SPE);
5651 GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, PPC_SPE);
5652 GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0x00000000, PPC_SPE);
5653 GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0x00000000, PPC_SPE);
5654 GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, PPC_SPE);
5655 GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0x00000000, PPC_SPE);
5657 GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, PPC_SPE);
5658 GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, PPC_SPE);
5659 GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, PPC_SPE);
5660 GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, PPC_SPE);
5661 GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, PPC_SPE);
5662 GEN_SPE(evmra, speundef, 0x07, 0x13, 0x0000F800, PPC_SPE);
5664 GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, PPC_SPE);
5665 GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0x00000000, PPC_SPE);
5666 GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, PPC_SPE);
5667 GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0x00000000, PPC_SPE);
5668 GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, PPC_SPE);
5669 GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0x00000000, PPC_SPE);
5670 GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, PPC_SPE);
5671 GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0x00000000, PPC_SPE);
5672 GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, PPC_SPE);
5673 GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0x00000000, PPC_SPE);
5674 GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, PPC_SPE);
5675 GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0x00000000, PPC_SPE);
5677 GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, PPC_SPE);
5678 GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, PPC_SPE);
5679 GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0x00000000, PPC_SPE);
5680 GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, PPC_SPE);
5681 GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0x00000000, PPC_SPE);
5683 GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, PPC_SPE);
5684 GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0x00000000, PPC_SPE);
5685 GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, PPC_SPE);
5686 GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0x00000000, PPC_SPE);
5687 GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, PPC_SPE);
5688 GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0x00000000, PPC_SPE);
5689 GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, PPC_SPE);
5690 GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0x00000000, PPC_SPE);
5691 GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, PPC_SPE);
5692 GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0x00000000, PPC_SPE);
5693 GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, PPC_SPE);
5694 GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0x00000000, PPC_SPE);
5696 GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, PPC_SPE);
5697 GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, PPC_SPE);
5698 GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0x00000000, PPC_SPE);
5699 GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, PPC_SPE);
5700 GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0x00000000, PPC_SPE);
5703 /*** SPE floating-point extension ***/
5704 #define GEN_SPEFPUOP_CONV(name) \
5705 static inline void gen_##name (DisasContext *ctx) \
5707 gen_op_load_gpr64_T0(rB(ctx->opcode)); \
5709 gen_op_store_T0_gpr64(rD(ctx->opcode)); \
5712 /* Single precision floating-point vectors operations */
5714 GEN_SPEOP_ARITH2(evfsadd);
5715 GEN_SPEOP_ARITH2(evfssub);
5716 GEN_SPEOP_ARITH2(evfsmul);
5717 GEN_SPEOP_ARITH2(evfsdiv);
5718 GEN_SPEOP_ARITH1(evfsabs);
5719 GEN_SPEOP_ARITH1(evfsnabs);
5720 GEN_SPEOP_ARITH1(evfsneg);
5722 GEN_SPEFPUOP_CONV(evfscfui);
5723 GEN_SPEFPUOP_CONV(evfscfsi);
5724 GEN_SPEFPUOP_CONV(evfscfuf);
5725 GEN_SPEFPUOP_CONV(evfscfsf);
5726 GEN_SPEFPUOP_CONV(evfsctui);
5727 GEN_SPEFPUOP_CONV(evfsctsi);
5728 GEN_SPEFPUOP_CONV(evfsctuf);
5729 GEN_SPEFPUOP_CONV(evfsctsf);
5730 GEN_SPEFPUOP_CONV(evfsctuiz);
5731 GEN_SPEFPUOP_CONV(evfsctsiz);
5733 GEN_SPEOP_COMP(evfscmpgt);
5734 GEN_SPEOP_COMP(evfscmplt);
5735 GEN_SPEOP_COMP(evfscmpeq);
5736 GEN_SPEOP_COMP(evfststgt);
5737 GEN_SPEOP_COMP(evfststlt);
5738 GEN_SPEOP_COMP(evfststeq);
5740 /* Opcodes definitions */
5741 GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, PPC_SPEFPU); //
5742 GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, PPC_SPEFPU); //
5743 GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, PPC_SPEFPU); //
5744 GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, PPC_SPEFPU); //
5745 GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, PPC_SPEFPU); //
5746 GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, PPC_SPEFPU); //
5747 GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, PPC_SPEFPU); //
5748 GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, PPC_SPEFPU); //
5749 GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, PPC_SPEFPU); //
5750 GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, PPC_SPEFPU); //
5751 GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, PPC_SPEFPU); //
5752 GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, PPC_SPEFPU); //
5753 GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, PPC_SPEFPU); //
5754 GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, PPC_SPEFPU); //
5756 /* Single precision floating-point operations */
5758 GEN_SPEOP_ARITH2(efsadd);
5759 GEN_SPEOP_ARITH2(efssub);
5760 GEN_SPEOP_ARITH2(efsmul);
5761 GEN_SPEOP_ARITH2(efsdiv);
5762 GEN_SPEOP_ARITH1(efsabs);
5763 GEN_SPEOP_ARITH1(efsnabs);
5764 GEN_SPEOP_ARITH1(efsneg);
5766 GEN_SPEFPUOP_CONV(efscfui);
5767 GEN_SPEFPUOP_CONV(efscfsi);
5768 GEN_SPEFPUOP_CONV(efscfuf);
5769 GEN_SPEFPUOP_CONV(efscfsf);
5770 GEN_SPEFPUOP_CONV(efsctui);
5771 GEN_SPEFPUOP_CONV(efsctsi);
5772 GEN_SPEFPUOP_CONV(efsctuf);
5773 GEN_SPEFPUOP_CONV(efsctsf);
5774 GEN_SPEFPUOP_CONV(efsctuiz);
5775 GEN_SPEFPUOP_CONV(efsctsiz);
5776 GEN_SPEFPUOP_CONV(efscfd);
5778 GEN_SPEOP_COMP(efscmpgt);
5779 GEN_SPEOP_COMP(efscmplt);
5780 GEN_SPEOP_COMP(efscmpeq);
5781 GEN_SPEOP_COMP(efststgt);
5782 GEN_SPEOP_COMP(efststlt);
5783 GEN_SPEOP_COMP(efststeq);
5785 /* Opcodes definitions */
5786 GEN_SPE(efsadd, efssub, 0x00, 0x0A, 0x00000000, PPC_SPEFPU); //
5787 GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, PPC_SPEFPU); //
5788 GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, PPC_SPEFPU); //
5789 GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, PPC_SPEFPU); //
5790 GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, PPC_SPEFPU); //
5791 GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, PPC_SPEFPU); //
5792 GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, PPC_SPEFPU); //
5793 GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, PPC_SPEFPU); //
5794 GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, PPC_SPEFPU); //
5795 GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, PPC_SPEFPU); //
5796 GEN_SPE(efsctuiz, efsctsiz, 0x0C, 0x0B, 0x00180000, PPC_SPEFPU); //
5797 GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, PPC_SPEFPU); //
5798 GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, PPC_SPEFPU); //
5800 /* Double precision floating-point operations */
5802 GEN_SPEOP_ARITH2(efdadd);
5803 GEN_SPEOP_ARITH2(efdsub);
5804 GEN_SPEOP_ARITH2(efdmul);
5805 GEN_SPEOP_ARITH2(efddiv);
5806 GEN_SPEOP_ARITH1(efdabs);
5807 GEN_SPEOP_ARITH1(efdnabs);
5808 GEN_SPEOP_ARITH1(efdneg);
5811 GEN_SPEFPUOP_CONV(efdcfui);
5812 GEN_SPEFPUOP_CONV(efdcfsi);
5813 GEN_SPEFPUOP_CONV(efdcfuf);
5814 GEN_SPEFPUOP_CONV(efdcfsf);
5815 GEN_SPEFPUOP_CONV(efdctui);
5816 GEN_SPEFPUOP_CONV(efdctsi);
5817 GEN_SPEFPUOP_CONV(efdctuf);
5818 GEN_SPEFPUOP_CONV(efdctsf);
5819 GEN_SPEFPUOP_CONV(efdctuiz);
5820 GEN_SPEFPUOP_CONV(efdctsiz);
5821 GEN_SPEFPUOP_CONV(efdcfs);
5822 GEN_SPEFPUOP_CONV(efdcfuid);
5823 GEN_SPEFPUOP_CONV(efdcfsid);
5824 GEN_SPEFPUOP_CONV(efdctuidz);
5825 GEN_SPEFPUOP_CONV(efdctsidz);
5827 GEN_SPEOP_COMP(efdcmpgt);
5828 GEN_SPEOP_COMP(efdcmplt);
5829 GEN_SPEOP_COMP(efdcmpeq);
5830 GEN_SPEOP_COMP(efdtstgt);
5831 GEN_SPEOP_COMP(efdtstlt);
5832 GEN_SPEOP_COMP(efdtsteq);
5834 /* Opcodes definitions */
5835 GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, PPC_SPEFPU); //
5836 GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, PPC_SPEFPU); //
5837 GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, PPC_SPEFPU); //
5838 GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, PPC_SPEFPU); //
5839 GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, PPC_SPEFPU); //
5840 GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, PPC_SPEFPU); //
5841 GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, PPC_SPEFPU); //
5842 GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, PPC_SPEFPU); //
5843 GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, PPC_SPEFPU); //
5844 GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, PPC_SPEFPU); //
5845 GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, PPC_SPEFPU); //
5846 GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, PPC_SPEFPU); //
5847 GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, PPC_SPEFPU); //
5848 GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, PPC_SPEFPU); //
5849 GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, PPC_SPEFPU); //
5850 GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, PPC_SPEFPU); //
5853 /* End opcode list */
5854 GEN_OPCODE_MARK(end);
5856 #include "translate_init.c"
5858 /*****************************************************************************/
5859 /* Misc PowerPC helpers */
5860 static inline uint32_t load_xer (CPUState *env)
5862 return (xer_so << XER_SO) |
5863 (xer_ov << XER_OV) |
5864 (xer_ca << XER_CA) |
5865 (xer_bc << XER_BC) |
5866 (xer_cmp << XER_CMP);
5869 void cpu_dump_state (CPUState *env, FILE *f,
5870 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
5873 #if defined(TARGET_PPC64) || 1
5885 cpu_fprintf(f, "NIP " ADDRX " LR " ADDRX " CTR " ADDRX "\n",
5886 env->nip, env->lr, env->ctr);
5887 cpu_fprintf(f, "MSR " REGX FILL " XER %08x "
5888 #if !defined(NO_TIMER_DUMP)
5890 #if !defined(CONFIG_USER_ONLY)
5895 do_load_msr(env), load_xer(env)
5896 #if !defined(NO_TIMER_DUMP)
5897 , cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env)
5898 #if !defined(CONFIG_USER_ONLY)
5899 , cpu_ppc_load_decr(env)
5903 for (i = 0; i < 32; i++) {
5904 if ((i & (RGPL - 1)) == 0)
5905 cpu_fprintf(f, "GPR%02d", i);
5906 cpu_fprintf(f, " " REGX, (target_ulong)env->gpr[i]);
5907 if ((i & (RGPL - 1)) == (RGPL - 1))
5908 cpu_fprintf(f, "\n");
5910 cpu_fprintf(f, "CR ");
5911 for (i = 0; i < 8; i++)
5912 cpu_fprintf(f, "%01x", env->crf[i]);
5913 cpu_fprintf(f, " [");
5914 for (i = 0; i < 8; i++) {
5916 if (env->crf[i] & 0x08)
5918 else if (env->crf[i] & 0x04)
5920 else if (env->crf[i] & 0x02)
5922 cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' ');
5924 cpu_fprintf(f, " ] " FILL "RES " REGX "\n", env->reserve);
5925 for (i = 0; i < 32; i++) {
5926 if ((i & (RFPL - 1)) == 0)
5927 cpu_fprintf(f, "FPR%02d", i);
5928 cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i]));
5929 if ((i & (RFPL - 1)) == (RFPL - 1))
5930 cpu_fprintf(f, "\n");
5932 cpu_fprintf(f, "SRR0 " REGX " SRR1 " REGX " " FILL FILL FILL
5934 env->spr[SPR_SRR0], env->spr[SPR_SRR1], env->sdr1);
5941 void cpu_dump_statistics (CPUState *env, FILE*f,
5942 int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
5945 #if defined(DO_PPC_STATISTICS)
5946 opc_handler_t **t1, **t2, **t3, *handler;
5950 for (op1 = 0; op1 < 64; op1++) {
5952 if (is_indirect_opcode(handler)) {
5953 t2 = ind_table(handler);
5954 for (op2 = 0; op2 < 32; op2++) {
5956 if (is_indirect_opcode(handler)) {
5957 t3 = ind_table(handler);
5958 for (op3 = 0; op3 < 32; op3++) {
5960 if (handler->count == 0)
5962 cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: "
5964 op1, op2, op3, op1, (op3 << 5) | op2,
5966 handler->count, handler->count);
5969 if (handler->count == 0)
5971 cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: "
5973 op1, op2, op1, op2, handler->oname,
5974 handler->count, handler->count);
5978 if (handler->count == 0)
5980 cpu_fprintf(f, "%02x (%02x ) %16s: %016llx %lld\n",
5981 op1, op1, handler->oname,
5982 handler->count, handler->count);
5988 /*****************************************************************************/
5989 static inline int gen_intermediate_code_internal (CPUState *env,
5990 TranslationBlock *tb,
5993 DisasContext ctx, *ctxp = &ctx;
5994 opc_handler_t **table, *handler;
5995 target_ulong pc_start;
5996 uint16_t *gen_opc_end;
6000 gen_opc_ptr = gen_opc_buf;
6001 gen_opc_end = gen_opc_buf + OPC_MAX_SIZE;
6002 gen_opparam_ptr = gen_opparam_buf;
6006 ctx.exception = POWERPC_EXCP_NONE;
6007 ctx.spr_cb = env->spr_cb;
6008 #if defined(CONFIG_USER_ONLY)
6009 ctx.mem_idx = msr_le;
6010 #if defined(TARGET_PPC64)
6011 ctx.mem_idx |= msr_sf << 1;
6014 ctx.supervisor = 1 - msr_pr;
6015 ctx.mem_idx = ((1 - msr_pr) << 1) | msr_le;
6016 #if defined(TARGET_PPC64)
6017 ctx.mem_idx |= msr_sf << 2;
6020 #if defined(TARGET_PPC64)
6021 ctx.sf_mode = msr_sf;
6023 ctx.fpu_enabled = msr_fp;
6024 #if defined(TARGET_PPCEMB)
6025 ctx.spe_enabled = msr_spe;
6027 ctx.singlestep_enabled = env->singlestep_enabled;
6028 #if defined (DO_SINGLE_STEP) && 0
6029 /* Single step trace mode */
6032 /* Set env in case of segfault during code fetch */
6033 while (ctx.exception == POWERPC_EXCP_NONE && gen_opc_ptr < gen_opc_end) {
6034 if (unlikely(env->nb_breakpoints > 0)) {
6035 for (j = 0; j < env->nb_breakpoints; j++) {
6036 if (env->breakpoints[j] == ctx.nip) {
6037 gen_update_nip(&ctx, ctx.nip);
6043 if (unlikely(search_pc)) {
6044 j = gen_opc_ptr - gen_opc_buf;
6048 gen_opc_instr_start[lj++] = 0;
6049 gen_opc_pc[lj] = ctx.nip;
6050 gen_opc_instr_start[lj] = 1;
6053 #if defined PPC_DEBUG_DISAS
6054 if (loglevel & CPU_LOG_TB_IN_ASM) {
6055 fprintf(logfile, "----------------\n");
6056 fprintf(logfile, "nip=" ADDRX " super=%d ir=%d\n",
6057 ctx.nip, 1 - msr_pr, msr_ir);
6060 ctx.opcode = ldl_code(ctx.nip);
6062 ctx.opcode = ((ctx.opcode & 0xFF000000) >> 24) |
6063 ((ctx.opcode & 0x00FF0000) >> 8) |
6064 ((ctx.opcode & 0x0000FF00) << 8) |
6065 ((ctx.opcode & 0x000000FF) << 24);
6067 #if defined PPC_DEBUG_DISAS
6068 if (loglevel & CPU_LOG_TB_IN_ASM) {
6069 fprintf(logfile, "translate opcode %08x (%02x %02x %02x) (%s)\n",
6070 ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode),
6071 opc3(ctx.opcode), msr_le ? "little" : "big");
6075 table = env->opcodes;
6076 handler = table[opc1(ctx.opcode)];
6077 if (is_indirect_opcode(handler)) {
6078 table = ind_table(handler);
6079 handler = table[opc2(ctx.opcode)];
6080 if (is_indirect_opcode(handler)) {
6081 table = ind_table(handler);
6082 handler = table[opc3(ctx.opcode)];
6085 /* Is opcode *REALLY* valid ? */
6086 if (unlikely(handler->handler == &gen_invalid)) {
6087 if (loglevel != 0) {
6088 fprintf(logfile, "invalid/unsupported opcode: "
6089 "%02x - %02x - %02x (%08x) 0x" ADDRX " %d\n",
6090 opc1(ctx.opcode), opc2(ctx.opcode),
6091 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, msr_ir);
6093 printf("invalid/unsupported opcode: "
6094 "%02x - %02x - %02x (%08x) 0x" ADDRX " %d\n",
6095 opc1(ctx.opcode), opc2(ctx.opcode),
6096 opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, msr_ir);
6099 if (unlikely((ctx.opcode & handler->inval) != 0)) {
6100 if (loglevel != 0) {
6101 fprintf(logfile, "invalid bits: %08x for opcode: "
6102 "%02x - %02x - %02x (%08x) 0x" ADDRX "\n",
6103 ctx.opcode & handler->inval, opc1(ctx.opcode),
6104 opc2(ctx.opcode), opc3(ctx.opcode),
6105 ctx.opcode, ctx.nip - 4);
6107 printf("invalid bits: %08x for opcode: "
6108 "%02x - %02x - %02x (%08x) 0x" ADDRX "\n",
6109 ctx.opcode & handler->inval, opc1(ctx.opcode),
6110 opc2(ctx.opcode), opc3(ctx.opcode),
6111 ctx.opcode, ctx.nip - 4);
6113 GEN_EXCP_INVAL(ctxp);
6117 (*(handler->handler))(&ctx);
6118 #if defined(DO_PPC_STATISTICS)
6121 /* Check trace mode exceptions */
6122 #if 0 // XXX: buggy on embedded PowerPC
6123 if (unlikely((msr_be && ctx.exception == POWERPC_EXCP_BRANCH) ||
6124 /* Check in single step trace mode
6125 * we need to stop except if:
6126 * - rfi, trap or syscall
6127 * - first instruction of an exception handler
6129 (msr_se && (ctx.nip < 0x100 ||
6131 (ctx.nip & 0xFC) != 0x04) &&
6132 #if defined(CONFIG_USER_ONLY)
6133 ctx.exception != POWERPC_EXCP_SYSCALL_USER &&
6135 ctx.exception != POWERPC_EXCP_SYSCALL &&
6137 ctx.exception != POWERPC_EXCP_TRAP))) {
6138 GEN_EXCP(ctxp, POWERPC_EXCP_TRACE, 0);
6141 /* if we reach a page boundary or are single stepping, stop
6144 if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) ||
6145 (env->singlestep_enabled))) {
6148 #if defined (DO_SINGLE_STEP)
6152 if (ctx.exception == POWERPC_EXCP_NONE) {
6153 gen_goto_tb(&ctx, 0, ctx.nip);
6154 } else if (ctx.exception != POWERPC_EXCP_BRANCH) {
6156 /* Generate the return instruction */
6159 *gen_opc_ptr = INDEX_op_end;
6160 if (unlikely(search_pc)) {
6161 j = gen_opc_ptr - gen_opc_buf;
6164 gen_opc_instr_start[lj++] = 0;
6166 tb->size = ctx.nip - pc_start;
6168 #if defined(DEBUG_DISAS)
6169 if (loglevel & CPU_LOG_TB_CPU) {
6170 fprintf(logfile, "---------------- excp: %04x\n", ctx.exception);
6171 cpu_dump_state(env, logfile, fprintf, 0);
6173 if (loglevel & CPU_LOG_TB_IN_ASM) {
6175 flags = env->bfd_mach;
6176 flags |= msr_le << 16;
6177 fprintf(logfile, "IN: %s\n", lookup_symbol(pc_start));
6178 target_disas(logfile, pc_start, ctx.nip - pc_start, flags);
6179 fprintf(logfile, "\n");
6181 if (loglevel & CPU_LOG_TB_OP) {
6182 fprintf(logfile, "OP:\n");
6183 dump_ops(gen_opc_buf, gen_opparam_buf);
6184 fprintf(logfile, "\n");
6190 int gen_intermediate_code (CPUState *env, struct TranslationBlock *tb)
6192 return gen_intermediate_code_internal(env, tb, 0);
6195 int gen_intermediate_code_pc (CPUState *env, struct TranslationBlock *tb)
6197 return gen_intermediate_code_internal(env, tb, 1);