2 * PowerPC emulation for qemu: main translation routines.
4 * Copyright (c) 2003-2007 Jocelyn Mayer
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "qemu-common.h"
33 #define CPU_SINGLE_STEP 0x1
34 #define CPU_BRANCH_STEP 0x2
35 #define GDBSTUB_SINGLE_STEP 0x4
37 /* Include definitions for instructions classes and implementations flags */
38 //#define DO_SINGLE_STEP
39 //#define PPC_DEBUG_DISAS
40 //#define DEBUG_MEMORY_ACCESSES
41 //#define DO_PPC_STATISTICS
42 //#define OPTIMIZE_FPRF_UPDATE
44 /*****************************************************************************/
45 /* Code translation helpers */
47 /* global register indexes */
49 static char cpu_reg_names
[10*3 + 22*4 /* GPR */
50 #if !defined(TARGET_PPC64)
51 + 10*4 + 22*5 /* SPE GPRh */
53 + 10*4 + 22*5 /* FPR */
54 + 2*(10*6 + 22*7) /* AVRh, AVRl */];
55 static TCGv cpu_gpr
[32];
56 #if !defined(TARGET_PPC64)
57 static TCGv cpu_gprh
[32];
59 static TCGv cpu_fpr
[32];
60 static TCGv cpu_avrh
[32], cpu_avrl
[32];
62 /* dyngen register indexes */
64 #if defined(TARGET_PPC64)
67 static TCGv cpu_T64
[3];
69 static TCGv cpu_FT
[3];
70 static TCGv cpu_AVRh
[3], cpu_AVRl
[3];
72 #include "gen-icount.h"
74 void ppc_translate_init(void)
78 static int done_init
= 0;
83 cpu_env
= tcg_global_reg_new(TCG_TYPE_PTR
, TCG_AREG0
, "env");
84 #if TARGET_LONG_BITS > HOST_LONG_BITS
85 cpu_T
[0] = tcg_global_mem_new(TCG_TYPE_TL
,
86 TCG_AREG0
, offsetof(CPUState
, t0
), "T0");
87 cpu_T
[1] = tcg_global_mem_new(TCG_TYPE_TL
,
88 TCG_AREG0
, offsetof(CPUState
, t1
), "T1");
89 cpu_T
[2] = tcg_global_mem_new(TCG_TYPE_TL
,
90 TCG_AREG0
, offsetof(CPUState
, t2
), "T2");
92 cpu_T
[0] = tcg_global_reg_new(TCG_TYPE_TL
, TCG_AREG1
, "T0");
93 cpu_T
[1] = tcg_global_reg_new(TCG_TYPE_TL
, TCG_AREG2
, "T1");
94 cpu_T
[2] = tcg_global_reg_new(TCG_TYPE_TL
, TCG_AREG3
, "T2");
96 #if !defined(TARGET_PPC64)
97 cpu_T64
[0] = tcg_global_mem_new(TCG_TYPE_I64
,
98 TCG_AREG0
, offsetof(CPUState
, t0_64
),
100 cpu_T64
[1] = tcg_global_mem_new(TCG_TYPE_I64
,
101 TCG_AREG0
, offsetof(CPUState
, t1_64
),
103 cpu_T64
[2] = tcg_global_mem_new(TCG_TYPE_I64
,
104 TCG_AREG0
, offsetof(CPUState
, t2_64
),
108 cpu_FT
[0] = tcg_global_mem_new(TCG_TYPE_I64
, TCG_AREG0
,
109 offsetof(CPUState
, ft0
), "FT0");
110 cpu_FT
[1] = tcg_global_mem_new(TCG_TYPE_I64
, TCG_AREG0
,
111 offsetof(CPUState
, ft1
), "FT1");
112 cpu_FT
[2] = tcg_global_mem_new(TCG_TYPE_I64
, TCG_AREG0
,
113 offsetof(CPUState
, ft2
), "FT2");
115 cpu_AVRh
[0] = tcg_global_mem_new(TCG_TYPE_I64
, TCG_AREG0
,
116 offsetof(CPUState
, avr0
.u64
[0]), "AVR0H");
117 cpu_AVRl
[0] = tcg_global_mem_new(TCG_TYPE_I64
, TCG_AREG0
,
118 offsetof(CPUState
, avr0
.u64
[1]), "AVR0L");
119 cpu_AVRh
[1] = tcg_global_mem_new(TCG_TYPE_I64
, TCG_AREG0
,
120 offsetof(CPUState
, avr1
.u64
[0]), "AVR1H");
121 cpu_AVRl
[1] = tcg_global_mem_new(TCG_TYPE_I64
, TCG_AREG0
,
122 offsetof(CPUState
, avr1
.u64
[1]), "AVR1L");
123 cpu_AVRh
[2] = tcg_global_mem_new(TCG_TYPE_I64
, TCG_AREG0
,
124 offsetof(CPUState
, avr2
.u64
[0]), "AVR2H");
125 cpu_AVRl
[2] = tcg_global_mem_new(TCG_TYPE_I64
, TCG_AREG0
,
126 offsetof(CPUState
, avr2
.u64
[1]), "AVR2L");
129 for (i
= 0; i
< 32; i
++) {
130 sprintf(p
, "r%d", i
);
131 cpu_gpr
[i
] = tcg_global_mem_new(TCG_TYPE_TL
, TCG_AREG0
,
132 offsetof(CPUState
, gpr
[i
]), p
);
133 p
+= (i
< 10) ? 3 : 4;
134 #if !defined(TARGET_PPC64)
135 sprintf(p
, "r%dH", i
);
136 cpu_gprh
[i
] = tcg_global_mem_new(TCG_TYPE_I32
, TCG_AREG0
,
137 offsetof(CPUState
, gprh
[i
]), p
);
138 p
+= (i
< 10) ? 4 : 5;
141 sprintf(p
, "fp%d", i
);
142 cpu_fpr
[i
] = tcg_global_mem_new(TCG_TYPE_I64
, TCG_AREG0
,
143 offsetof(CPUState
, fpr
[i
]), p
);
145 sprintf(p
, "avr%dH", i
);
146 cpu_avrh
[i
] = tcg_global_mem_new(TCG_TYPE_I64
, TCG_AREG0
,
147 offsetof(CPUState
, avr
[i
].u64
[0]), p
);
148 p
+= (i
< 10) ? 6 : 7;
149 sprintf(p
, "avr%dL", i
);
150 cpu_avrl
[i
] = tcg_global_mem_new(TCG_TYPE_I64
, TCG_AREG0
,
151 offsetof(CPUState
, avr
[i
].u64
[1]), p
);
152 p
+= (i
< 10) ? 6 : 7;
155 /* register helpers */
157 #define DEF_HELPER(ret, name, params) tcg_register_helper(name, #name);
163 #if defined(OPTIMIZE_FPRF_UPDATE)
164 static uint16_t *gen_fprf_buf
[OPC_BUF_SIZE
];
165 static uint16_t **gen_fprf_ptr
;
168 #define GEN8(func, NAME) \
169 static GenOpFunc *NAME ## _table [8] = { \
170 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
171 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
173 static always_inline void func (int n) \
175 NAME ## _table[n](); \
178 #define GEN16(func, NAME) \
179 static GenOpFunc *NAME ## _table [16] = { \
180 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
181 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
182 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
183 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
185 static always_inline void func (int n) \
187 NAME ## _table[n](); \
190 #define GEN32(func, NAME) \
191 static GenOpFunc *NAME ## _table [32] = { \
192 NAME ## 0, NAME ## 1, NAME ## 2, NAME ## 3, \
193 NAME ## 4, NAME ## 5, NAME ## 6, NAME ## 7, \
194 NAME ## 8, NAME ## 9, NAME ## 10, NAME ## 11, \
195 NAME ## 12, NAME ## 13, NAME ## 14, NAME ## 15, \
196 NAME ## 16, NAME ## 17, NAME ## 18, NAME ## 19, \
197 NAME ## 20, NAME ## 21, NAME ## 22, NAME ## 23, \
198 NAME ## 24, NAME ## 25, NAME ## 26, NAME ## 27, \
199 NAME ## 28, NAME ## 29, NAME ## 30, NAME ## 31, \
201 static always_inline void func (int n) \
203 NAME ## _table[n](); \
206 /* Condition register moves */
207 GEN8(gen_op_load_crf_T0
, gen_op_load_crf_T0_crf
);
208 GEN8(gen_op_load_crf_T1
, gen_op_load_crf_T1_crf
);
209 GEN8(gen_op_store_T0_crf
, gen_op_store_T0_crf_crf
);
211 GEN8(gen_op_store_T1_crf
, gen_op_store_T1_crf_crf
);
214 /* internal defines */
215 typedef struct DisasContext
{
216 struct TranslationBlock
*tb
;
220 /* Routine used to access memory */
222 /* Translation flags */
223 #if !defined(CONFIG_USER_ONLY)
226 #if defined(TARGET_PPC64)
232 ppc_spr_t
*spr_cb
; /* Needed to check rights for mfspr/mtspr */
233 int singlestep_enabled
;
234 int dcache_line_size
;
237 struct opc_handler_t
{
240 /* instruction type */
243 void (*handler
)(DisasContext
*ctx
);
244 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
245 const unsigned char *oname
;
247 #if defined(DO_PPC_STATISTICS)
252 static always_inline
void gen_set_Rc0 (DisasContext
*ctx
)
254 #if defined(TARGET_PPC64)
263 static always_inline
void gen_reset_fpstatus (void)
265 #ifdef CONFIG_SOFTFLOAT
266 gen_op_reset_fpstatus();
270 static always_inline
void gen_compute_fprf (int set_fprf
, int set_rc
)
273 /* This case might be optimized later */
274 #if defined(OPTIMIZE_FPRF_UPDATE)
275 *gen_fprf_ptr
++ = gen_opc_ptr
;
277 gen_op_compute_fprf(1);
278 if (unlikely(set_rc
))
279 gen_op_store_T0_crf(1);
280 gen_op_float_check_status();
281 } else if (unlikely(set_rc
)) {
282 /* We always need to compute fpcc */
283 gen_op_compute_fprf(0);
284 gen_op_store_T0_crf(1);
286 gen_op_float_check_status();
290 static always_inline
void gen_optimize_fprf (void)
292 #if defined(OPTIMIZE_FPRF_UPDATE)
295 for (ptr
= gen_fprf_buf
; ptr
!= (gen_fprf_ptr
- 1); ptr
++)
296 *ptr
= INDEX_op_nop1
;
297 gen_fprf_ptr
= gen_fprf_buf
;
301 static always_inline
void gen_update_nip (DisasContext
*ctx
, target_ulong nip
)
303 #if defined(TARGET_PPC64)
305 gen_op_update_nip_64(nip
>> 32, nip
);
308 gen_op_update_nip(nip
);
311 #define GEN_EXCP(ctx, excp, error) \
313 if ((ctx)->exception == POWERPC_EXCP_NONE) { \
314 gen_update_nip(ctx, (ctx)->nip); \
316 gen_op_raise_exception_err((excp), (error)); \
317 ctx->exception = (excp); \
320 #define GEN_EXCP_INVAL(ctx) \
321 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
322 POWERPC_EXCP_INVAL | POWERPC_EXCP_INVAL_INVAL)
324 #define GEN_EXCP_PRIVOPC(ctx) \
325 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
326 POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_OPC)
328 #define GEN_EXCP_PRIVREG(ctx) \
329 GEN_EXCP((ctx), POWERPC_EXCP_PROGRAM, \
330 POWERPC_EXCP_INVAL | POWERPC_EXCP_PRIV_REG)
332 #define GEN_EXCP_NO_FP(ctx) \
333 GEN_EXCP(ctx, POWERPC_EXCP_FPU, 0)
335 #define GEN_EXCP_NO_AP(ctx) \
336 GEN_EXCP(ctx, POWERPC_EXCP_APU, 0)
338 #define GEN_EXCP_NO_VR(ctx) \
339 GEN_EXCP(ctx, POWERPC_EXCP_VPU, 0)
341 /* Stop translation */
342 static always_inline
void GEN_STOP (DisasContext
*ctx
)
344 gen_update_nip(ctx
, ctx
->nip
);
345 ctx
->exception
= POWERPC_EXCP_STOP
;
348 /* No need to update nip here, as execution flow will change */
349 static always_inline
void GEN_SYNC (DisasContext
*ctx
)
351 ctx
->exception
= POWERPC_EXCP_SYNC
;
354 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
355 static void gen_##name (DisasContext *ctx); \
356 GEN_OPCODE(name, opc1, opc2, opc3, inval, type); \
357 static void gen_##name (DisasContext *ctx)
359 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
360 static void gen_##name (DisasContext *ctx); \
361 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type); \
362 static void gen_##name (DisasContext *ctx)
364 typedef struct opcode_t
{
365 unsigned char opc1
, opc2
, opc3
;
366 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
367 unsigned char pad
[5];
369 unsigned char pad
[1];
371 opc_handler_t handler
;
372 const unsigned char *oname
;
375 /*****************************************************************************/
376 /*** Instruction decoding ***/
377 #define EXTRACT_HELPER(name, shift, nb) \
378 static always_inline uint32_t name (uint32_t opcode) \
380 return (opcode >> (shift)) & ((1 << (nb)) - 1); \
383 #define EXTRACT_SHELPER(name, shift, nb) \
384 static always_inline int32_t name (uint32_t opcode) \
386 return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \
390 EXTRACT_HELPER(opc1
, 26, 6);
392 EXTRACT_HELPER(opc2
, 1, 5);
394 EXTRACT_HELPER(opc3
, 6, 5);
395 /* Update Cr0 flags */
396 EXTRACT_HELPER(Rc
, 0, 1);
398 EXTRACT_HELPER(rD
, 21, 5);
400 EXTRACT_HELPER(rS
, 21, 5);
402 EXTRACT_HELPER(rA
, 16, 5);
404 EXTRACT_HELPER(rB
, 11, 5);
406 EXTRACT_HELPER(rC
, 6, 5);
408 EXTRACT_HELPER(crfD
, 23, 3);
409 EXTRACT_HELPER(crfS
, 18, 3);
410 EXTRACT_HELPER(crbD
, 21, 5);
411 EXTRACT_HELPER(crbA
, 16, 5);
412 EXTRACT_HELPER(crbB
, 11, 5);
414 EXTRACT_HELPER(_SPR
, 11, 10);
415 static always_inline
uint32_t SPR (uint32_t opcode
)
417 uint32_t sprn
= _SPR(opcode
);
419 return ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
421 /*** Get constants ***/
422 EXTRACT_HELPER(IMM
, 12, 8);
423 /* 16 bits signed immediate value */
424 EXTRACT_SHELPER(SIMM
, 0, 16);
425 /* 16 bits unsigned immediate value */
426 EXTRACT_HELPER(UIMM
, 0, 16);
428 EXTRACT_HELPER(NB
, 11, 5);
430 EXTRACT_HELPER(SH
, 11, 5);
432 EXTRACT_HELPER(MB
, 6, 5);
434 EXTRACT_HELPER(ME
, 1, 5);
436 EXTRACT_HELPER(TO
, 21, 5);
438 EXTRACT_HELPER(CRM
, 12, 8);
439 EXTRACT_HELPER(FM
, 17, 8);
440 EXTRACT_HELPER(SR
, 16, 4);
441 EXTRACT_HELPER(FPIMM
, 12, 4);
443 /*** Jump target decoding ***/
445 EXTRACT_SHELPER(d
, 0, 16);
446 /* Immediate address */
447 static always_inline target_ulong
LI (uint32_t opcode
)
449 return (opcode
>> 0) & 0x03FFFFFC;
452 static always_inline
uint32_t BD (uint32_t opcode
)
454 return (opcode
>> 0) & 0xFFFC;
457 EXTRACT_HELPER(BO
, 21, 5);
458 EXTRACT_HELPER(BI
, 16, 5);
459 /* Absolute/relative address */
460 EXTRACT_HELPER(AA
, 1, 1);
462 EXTRACT_HELPER(LK
, 0, 1);
464 /* Create a mask between <start> and <end> bits */
465 static always_inline target_ulong
MASK (uint32_t start
, uint32_t end
)
469 #if defined(TARGET_PPC64)
470 if (likely(start
== 0)) {
471 ret
= UINT64_MAX
<< (63 - end
);
472 } else if (likely(end
== 63)) {
473 ret
= UINT64_MAX
>> start
;
476 if (likely(start
== 0)) {
477 ret
= UINT32_MAX
<< (31 - end
);
478 } else if (likely(end
== 31)) {
479 ret
= UINT32_MAX
>> start
;
483 ret
= (((target_ulong
)(-1ULL)) >> (start
)) ^
484 (((target_ulong
)(-1ULL) >> (end
)) >> 1);
485 if (unlikely(start
> end
))
492 /*****************************************************************************/
493 /* PowerPC Instructions types definitions */
495 PPC_NONE
= 0x0000000000000000ULL
,
496 /* PowerPC base instructions set */
497 PPC_INSNS_BASE
= 0x0000000000000001ULL
,
498 /* integer operations instructions */
499 #define PPC_INTEGER PPC_INSNS_BASE
500 /* flow control instructions */
501 #define PPC_FLOW PPC_INSNS_BASE
502 /* virtual memory instructions */
503 #define PPC_MEM PPC_INSNS_BASE
504 /* ld/st with reservation instructions */
505 #define PPC_RES PPC_INSNS_BASE
506 /* spr/msr access instructions */
507 #define PPC_MISC PPC_INSNS_BASE
508 /* Deprecated instruction sets */
509 /* Original POWER instruction set */
510 PPC_POWER
= 0x0000000000000002ULL
,
511 /* POWER2 instruction set extension */
512 PPC_POWER2
= 0x0000000000000004ULL
,
513 /* Power RTC support */
514 PPC_POWER_RTC
= 0x0000000000000008ULL
,
515 /* Power-to-PowerPC bridge (601) */
516 PPC_POWER_BR
= 0x0000000000000010ULL
,
517 /* 64 bits PowerPC instruction set */
518 PPC_64B
= 0x0000000000000020ULL
,
519 /* New 64 bits extensions (PowerPC 2.0x) */
520 PPC_64BX
= 0x0000000000000040ULL
,
521 /* 64 bits hypervisor extensions */
522 PPC_64H
= 0x0000000000000080ULL
,
523 /* New wait instruction (PowerPC 2.0x) */
524 PPC_WAIT
= 0x0000000000000100ULL
,
525 /* Time base mftb instruction */
526 PPC_MFTB
= 0x0000000000000200ULL
,
528 /* Fixed-point unit extensions */
529 /* PowerPC 602 specific */
530 PPC_602_SPEC
= 0x0000000000000400ULL
,
531 /* isel instruction */
532 PPC_ISEL
= 0x0000000000000800ULL
,
533 /* popcntb instruction */
534 PPC_POPCNTB
= 0x0000000000001000ULL
,
535 /* string load / store */
536 PPC_STRING
= 0x0000000000002000ULL
,
538 /* Floating-point unit extensions */
539 /* Optional floating point instructions */
540 PPC_FLOAT
= 0x0000000000010000ULL
,
541 /* New floating-point extensions (PowerPC 2.0x) */
542 PPC_FLOAT_EXT
= 0x0000000000020000ULL
,
543 PPC_FLOAT_FSQRT
= 0x0000000000040000ULL
,
544 PPC_FLOAT_FRES
= 0x0000000000080000ULL
,
545 PPC_FLOAT_FRSQRTE
= 0x0000000000100000ULL
,
546 PPC_FLOAT_FRSQRTES
= 0x0000000000200000ULL
,
547 PPC_FLOAT_FSEL
= 0x0000000000400000ULL
,
548 PPC_FLOAT_STFIWX
= 0x0000000000800000ULL
,
550 /* Vector/SIMD extensions */
551 /* Altivec support */
552 PPC_ALTIVEC
= 0x0000000001000000ULL
,
553 /* PowerPC 2.03 SPE extension */
554 PPC_SPE
= 0x0000000002000000ULL
,
555 /* PowerPC 2.03 SPE floating-point extension */
556 PPC_SPEFPU
= 0x0000000004000000ULL
,
558 /* Optional memory control instructions */
559 PPC_MEM_TLBIA
= 0x0000000010000000ULL
,
560 PPC_MEM_TLBIE
= 0x0000000020000000ULL
,
561 PPC_MEM_TLBSYNC
= 0x0000000040000000ULL
,
562 /* sync instruction */
563 PPC_MEM_SYNC
= 0x0000000080000000ULL
,
564 /* eieio instruction */
565 PPC_MEM_EIEIO
= 0x0000000100000000ULL
,
567 /* Cache control instructions */
568 PPC_CACHE
= 0x0000000200000000ULL
,
569 /* icbi instruction */
570 PPC_CACHE_ICBI
= 0x0000000400000000ULL
,
571 /* dcbz instruction with fixed cache line size */
572 PPC_CACHE_DCBZ
= 0x0000000800000000ULL
,
573 /* dcbz instruction with tunable cache line size */
574 PPC_CACHE_DCBZT
= 0x0000001000000000ULL
,
575 /* dcba instruction */
576 PPC_CACHE_DCBA
= 0x0000002000000000ULL
,
577 /* Freescale cache locking instructions */
578 PPC_CACHE_LOCK
= 0x0000004000000000ULL
,
580 /* MMU related extensions */
581 /* external control instructions */
582 PPC_EXTERN
= 0x0000010000000000ULL
,
583 /* segment register access instructions */
584 PPC_SEGMENT
= 0x0000020000000000ULL
,
585 /* PowerPC 6xx TLB management instructions */
586 PPC_6xx_TLB
= 0x0000040000000000ULL
,
587 /* PowerPC 74xx TLB management instructions */
588 PPC_74xx_TLB
= 0x0000080000000000ULL
,
589 /* PowerPC 40x TLB management instructions */
590 PPC_40x_TLB
= 0x0000100000000000ULL
,
591 /* segment register access instructions for PowerPC 64 "bridge" */
592 PPC_SEGMENT_64B
= 0x0000200000000000ULL
,
594 PPC_SLBI
= 0x0000400000000000ULL
,
596 /* Embedded PowerPC dedicated instructions */
597 PPC_WRTEE
= 0x0001000000000000ULL
,
598 /* PowerPC 40x exception model */
599 PPC_40x_EXCP
= 0x0002000000000000ULL
,
600 /* PowerPC 405 Mac instructions */
601 PPC_405_MAC
= 0x0004000000000000ULL
,
602 /* PowerPC 440 specific instructions */
603 PPC_440_SPEC
= 0x0008000000000000ULL
,
604 /* BookE (embedded) PowerPC specification */
605 PPC_BOOKE
= 0x0010000000000000ULL
,
606 /* mfapidi instruction */
607 PPC_MFAPIDI
= 0x0020000000000000ULL
,
608 /* tlbiva instruction */
609 PPC_TLBIVA
= 0x0040000000000000ULL
,
610 /* tlbivax instruction */
611 PPC_TLBIVAX
= 0x0080000000000000ULL
,
612 /* PowerPC 4xx dedicated instructions */
613 PPC_4xx_COMMON
= 0x0100000000000000ULL
,
614 /* PowerPC 40x ibct instructions */
615 PPC_40x_ICBT
= 0x0200000000000000ULL
,
616 /* rfmci is not implemented in all BookE PowerPC */
617 PPC_RFMCI
= 0x0400000000000000ULL
,
618 /* rfdi instruction */
619 PPC_RFDI
= 0x0800000000000000ULL
,
621 PPC_DCR
= 0x1000000000000000ULL
,
622 /* DCR extended accesse */
623 PPC_DCRX
= 0x2000000000000000ULL
,
624 /* user-mode DCR access, implemented in PowerPC 460 */
625 PPC_DCRUX
= 0x4000000000000000ULL
,
628 /*****************************************************************************/
629 /* PowerPC instructions table */
630 #if HOST_LONG_BITS == 64
635 #if defined(__APPLE__)
636 #define OPCODES_SECTION \
637 __attribute__ ((section("__TEXT,__opcodes"), unused, aligned (OPC_ALIGN) ))
639 #define OPCODES_SECTION \
640 __attribute__ ((section(".opcodes"), unused, aligned (OPC_ALIGN) ))
643 #if defined(DO_PPC_STATISTICS)
644 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
645 OPCODES_SECTION opcode_t opc_##name = { \
653 .handler = &gen_##name, \
654 .oname = stringify(name), \
656 .oname = stringify(name), \
658 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
659 OPCODES_SECTION opcode_t opc_##name = { \
667 .handler = &gen_##name, \
673 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ) \
674 OPCODES_SECTION opcode_t opc_##name = { \
682 .handler = &gen_##name, \
684 .oname = stringify(name), \
686 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ) \
687 OPCODES_SECTION opcode_t opc_##name = { \
695 .handler = &gen_##name, \
701 #define GEN_OPCODE_MARK(name) \
702 OPCODES_SECTION opcode_t opc_##name = { \
708 .inval = 0x00000000, \
712 .oname = stringify(name), \
715 /* Start opcode list */
716 GEN_OPCODE_MARK(start
);
718 /* Invalid instruction */
719 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
)
724 static opc_handler_t invalid_handler
= {
727 .handler
= gen_invalid
,
730 /*** Integer arithmetic ***/
731 #define __GEN_INT_ARITH2(name, opc1, opc2, opc3, inval, type) \
732 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
734 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]); \
735 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]); \
737 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]); \
738 if (unlikely(Rc(ctx->opcode) != 0)) \
742 #define __GEN_INT_ARITH2_O(name, opc1, opc2, opc3, inval, type) \
743 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
745 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]); \
746 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]); \
748 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]); \
749 if (unlikely(Rc(ctx->opcode) != 0)) \
753 #define __GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
754 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
756 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]); \
758 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]); \
759 if (unlikely(Rc(ctx->opcode) != 0)) \
762 #define __GEN_INT_ARITH1_O(name, opc1, opc2, opc3, type) \
763 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
765 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]); \
767 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]); \
768 if (unlikely(Rc(ctx->opcode) != 0)) \
772 /* Two operands arithmetic functions */
773 #define GEN_INT_ARITH2(name, opc1, opc2, opc3, type) \
774 __GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000000, type) \
775 __GEN_INT_ARITH2_O(name##o, opc1, opc2, opc3 | 0x10, 0x00000000, type)
777 /* Two operands arithmetic functions with no overflow allowed */
778 #define GEN_INT_ARITHN(name, opc1, opc2, opc3, type) \
779 __GEN_INT_ARITH2(name, opc1, opc2, opc3, 0x00000400, type)
781 /* One operand arithmetic functions */
782 #define GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
783 __GEN_INT_ARITH1(name, opc1, opc2, opc3, type) \
784 __GEN_INT_ARITH1_O(name##o, opc1, opc2, opc3 | 0x10, type)
786 #if defined(TARGET_PPC64)
787 #define __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, inval, type) \
788 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
790 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]); \
791 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]); \
793 gen_op_##name##_64(); \
796 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]); \
797 if (unlikely(Rc(ctx->opcode) != 0)) \
801 #define __GEN_INT_ARITH2_O_64(name, opc1, opc2, opc3, inval, type) \
802 GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
804 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]); \
805 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]); \
807 gen_op_##name##_64(); \
810 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]); \
811 if (unlikely(Rc(ctx->opcode) != 0)) \
815 #define __GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
816 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
818 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]); \
820 gen_op_##name##_64(); \
823 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]); \
824 if (unlikely(Rc(ctx->opcode) != 0)) \
827 #define __GEN_INT_ARITH1_O_64(name, opc1, opc2, opc3, type) \
828 GEN_HANDLER(name, opc1, opc2, opc3, 0x0000F800, type) \
830 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]); \
832 gen_op_##name##_64(); \
835 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[0]); \
836 if (unlikely(Rc(ctx->opcode) != 0)) \
840 /* Two operands arithmetic functions */
841 #define GEN_INT_ARITH2_64(name, opc1, opc2, opc3, type) \
842 __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, 0x00000000, type) \
843 __GEN_INT_ARITH2_O_64(name##o, opc1, opc2, opc3 | 0x10, 0x00000000, type)
845 /* Two operands arithmetic functions with no overflow allowed */
846 #define GEN_INT_ARITHN_64(name, opc1, opc2, opc3, type) \
847 __GEN_INT_ARITH2_64(name, opc1, opc2, opc3, 0x00000400, type)
849 /* One operand arithmetic functions */
850 #define GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
851 __GEN_INT_ARITH1_64(name, opc1, opc2, opc3, type) \
852 __GEN_INT_ARITH1_O_64(name##o, opc1, opc2, opc3 | 0x10, type)
854 #define GEN_INT_ARITH2_64 GEN_INT_ARITH2
855 #define GEN_INT_ARITHN_64 GEN_INT_ARITHN
856 #define GEN_INT_ARITH1_64 GEN_INT_ARITH1
859 /* add add. addo addo. */
860 static always_inline
void gen_op_addo (void)
862 tcg_gen_mov_tl(cpu_T
[2], cpu_T
[0]);
866 #if defined(TARGET_PPC64)
867 #define gen_op_add_64 gen_op_add
868 static always_inline
void gen_op_addo_64 (void)
870 tcg_gen_mov_tl(cpu_T
[2], cpu_T
[0]);
872 gen_op_check_addo_64();
875 GEN_INT_ARITH2_64 (add
, 0x1F, 0x0A, 0x08, PPC_INTEGER
);
876 /* addc addc. addco addco. */
877 static always_inline
void gen_op_addc (void)
879 tcg_gen_mov_tl(cpu_T
[2], cpu_T
[0]);
883 static always_inline
void gen_op_addco (void)
885 tcg_gen_mov_tl(cpu_T
[2], cpu_T
[0]);
890 #if defined(TARGET_PPC64)
891 static always_inline
void gen_op_addc_64 (void)
893 tcg_gen_mov_tl(cpu_T
[2], cpu_T
[0]);
895 gen_op_check_addc_64();
897 static always_inline
void gen_op_addco_64 (void)
899 tcg_gen_mov_tl(cpu_T
[2], cpu_T
[0]);
901 gen_op_check_addc_64();
902 gen_op_check_addo_64();
905 GEN_INT_ARITH2_64 (addc
, 0x1F, 0x0A, 0x00, PPC_INTEGER
);
906 /* adde adde. addeo addeo. */
907 static always_inline
void gen_op_addeo (void)
909 tcg_gen_mov_tl(cpu_T
[2], cpu_T
[0]);
913 #if defined(TARGET_PPC64)
914 static always_inline
void gen_op_addeo_64 (void)
916 tcg_gen_mov_tl(cpu_T
[2], cpu_T
[0]);
918 gen_op_check_addo_64();
921 GEN_INT_ARITH2_64 (adde
, 0x1F, 0x0A, 0x04, PPC_INTEGER
);
922 /* addme addme. addmeo addmeo. */
923 static always_inline
void gen_op_addme (void)
925 tcg_gen_mov_tl(cpu_T
[1], cpu_T
[0]);
928 #if defined(TARGET_PPC64)
929 static always_inline
void gen_op_addme_64 (void)
931 tcg_gen_mov_tl(cpu_T
[1], cpu_T
[0]);
935 GEN_INT_ARITH1_64 (addme
, 0x1F, 0x0A, 0x07, PPC_INTEGER
);
936 /* addze addze. addzeo addzeo. */
937 static always_inline
void gen_op_addze (void)
939 tcg_gen_mov_tl(cpu_T
[2], cpu_T
[0]);
943 static always_inline
void gen_op_addzeo (void)
945 tcg_gen_mov_tl(cpu_T
[2], cpu_T
[0]);
950 #if defined(TARGET_PPC64)
951 static always_inline
void gen_op_addze_64 (void)
953 tcg_gen_mov_tl(cpu_T
[2], cpu_T
[0]);
955 gen_op_check_addc_64();
957 static always_inline
void gen_op_addzeo_64 (void)
959 tcg_gen_mov_tl(cpu_T
[2], cpu_T
[0]);
961 gen_op_check_addc_64();
962 gen_op_check_addo_64();
965 GEN_INT_ARITH1_64 (addze
, 0x1F, 0x0A, 0x06, PPC_INTEGER
);
966 /* divw divw. divwo divwo. */
967 GEN_INT_ARITH2 (divw
, 0x1F, 0x0B, 0x0F, PPC_INTEGER
);
968 /* divwu divwu. divwuo divwuo. */
969 GEN_INT_ARITH2 (divwu
, 0x1F, 0x0B, 0x0E, PPC_INTEGER
);
971 GEN_INT_ARITHN (mulhw
, 0x1F, 0x0B, 0x02, PPC_INTEGER
);
973 GEN_INT_ARITHN (mulhwu
, 0x1F, 0x0B, 0x00, PPC_INTEGER
);
974 /* mullw mullw. mullwo mullwo. */
975 GEN_INT_ARITH2 (mullw
, 0x1F, 0x0B, 0x07, PPC_INTEGER
);
976 /* neg neg. nego nego. */
977 GEN_INT_ARITH1_64 (neg
, 0x1F, 0x08, 0x03, PPC_INTEGER
);
978 /* subf subf. subfo subfo. */
979 static always_inline
void gen_op_subfo (void)
981 tcg_gen_not_tl(cpu_T
[2], cpu_T
[0]);
985 #if defined(TARGET_PPC64)
986 #define gen_op_subf_64 gen_op_subf
987 static always_inline
void gen_op_subfo_64 (void)
989 tcg_gen_not_i64(cpu_T
[2], cpu_T
[0]);
991 gen_op_check_addo_64();
994 GEN_INT_ARITH2_64 (subf
, 0x1F, 0x08, 0x01, PPC_INTEGER
);
995 /* subfc subfc. subfco subfco. */
996 static always_inline
void gen_op_subfc (void)
999 gen_op_check_subfc();
1001 static always_inline
void gen_op_subfco (void)
1003 tcg_gen_not_tl(cpu_T
[2], cpu_T
[0]);
1005 gen_op_check_subfc();
1006 gen_op_check_addo();
1008 #if defined(TARGET_PPC64)
1009 static always_inline
void gen_op_subfc_64 (void)
1012 gen_op_check_subfc_64();
1014 static always_inline
void gen_op_subfco_64 (void)
1016 tcg_gen_not_i64(cpu_T
[2], cpu_T
[0]);
1018 gen_op_check_subfc_64();
1019 gen_op_check_addo_64();
1022 GEN_INT_ARITH2_64 (subfc
, 0x1F, 0x08, 0x00, PPC_INTEGER
);
1023 /* subfe subfe. subfeo subfeo. */
1024 static always_inline
void gen_op_subfeo (void)
1026 tcg_gen_not_tl(cpu_T
[2], cpu_T
[0]);
1028 gen_op_check_addo();
1030 #if defined(TARGET_PPC64)
1031 #define gen_op_subfe_64 gen_op_subfe
1032 static always_inline
void gen_op_subfeo_64 (void)
1034 tcg_gen_not_i64(cpu_T
[2], cpu_T
[0]);
1036 gen_op_check_addo_64();
1039 GEN_INT_ARITH2_64 (subfe
, 0x1F, 0x08, 0x04, PPC_INTEGER
);
1040 /* subfme subfme. subfmeo subfmeo. */
1041 GEN_INT_ARITH1_64 (subfme
, 0x1F, 0x08, 0x07, PPC_INTEGER
);
1042 /* subfze subfze. subfzeo subfzeo. */
1043 GEN_INT_ARITH1_64 (subfze
, 0x1F, 0x08, 0x06, PPC_INTEGER
);
1045 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1047 target_long simm
= SIMM(ctx
->opcode
);
1049 if (rA(ctx
->opcode
) == 0) {
1051 tcg_gen_movi_tl(cpu_T
[0], simm
);
1053 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
1054 if (likely(simm
!= 0))
1057 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
1060 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1062 target_long simm
= SIMM(ctx
->opcode
);
1064 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
1065 if (likely(simm
!= 0)) {
1066 tcg_gen_mov_tl(cpu_T
[2], cpu_T
[0]);
1068 #if defined(TARGET_PPC64)
1070 gen_op_check_addc_64();
1073 gen_op_check_addc();
1075 gen_op_clear_xer_ca();
1077 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
1080 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1082 target_long simm
= SIMM(ctx
->opcode
);
1084 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
1085 if (likely(simm
!= 0)) {
1086 tcg_gen_mov_tl(cpu_T
[2], cpu_T
[0]);
1088 #if defined(TARGET_PPC64)
1090 gen_op_check_addc_64();
1093 gen_op_check_addc();
1095 gen_op_clear_xer_ca();
1097 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
1101 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1103 target_long simm
= SIMM(ctx
->opcode
);
1105 if (rA(ctx
->opcode
) == 0) {
1107 tcg_gen_movi_tl(cpu_T
[0], simm
<< 16);
1109 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
1110 if (likely(simm
!= 0))
1111 gen_op_addi(simm
<< 16);
1113 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
1116 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1118 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
1119 gen_op_mulli(SIMM(ctx
->opcode
));
1120 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
1123 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1125 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
1126 #if defined(TARGET_PPC64)
1128 gen_op_subfic_64(SIMM(ctx
->opcode
));
1131 gen_op_subfic(SIMM(ctx
->opcode
));
1132 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
1135 #if defined(TARGET_PPC64)
1137 GEN_INT_ARITHN (mulhd
, 0x1F, 0x09, 0x02, PPC_64B
);
1138 /* mulhdu mulhdu. */
1139 GEN_INT_ARITHN (mulhdu
, 0x1F, 0x09, 0x00, PPC_64B
);
1140 /* mulld mulld. mulldo mulldo. */
1141 GEN_INT_ARITH2 (mulld
, 0x1F, 0x09, 0x07, PPC_64B
);
1142 /* divd divd. divdo divdo. */
1143 GEN_INT_ARITH2 (divd
, 0x1F, 0x09, 0x0F, PPC_64B
);
1144 /* divdu divdu. divduo divduo. */
1145 GEN_INT_ARITH2 (divdu
, 0x1F, 0x09, 0x0E, PPC_64B
);
1148 /*** Integer comparison ***/
1149 #if defined(TARGET_PPC64)
1150 #define GEN_CMP(name, opc, type) \
1151 GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, type) \
1153 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]); \
1154 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]); \
1155 if (ctx->sf_mode && (ctx->opcode & 0x00200000)) \
1156 gen_op_##name##_64(); \
1159 gen_op_store_T0_crf(crfD(ctx->opcode)); \
1162 #define GEN_CMP(name, opc, type) \
1163 GEN_HANDLER(name, 0x1F, 0x00, opc, 0x00400000, type) \
1165 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rA(ctx->opcode)]); \
1166 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]); \
1168 gen_op_store_T0_crf(crfD(ctx->opcode)); \
1173 GEN_CMP(cmp
, 0x00, PPC_INTEGER
);
1175 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
)
1177 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
1178 #if defined(TARGET_PPC64)
1179 if (ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000))
1180 gen_op_cmpi_64(SIMM(ctx
->opcode
));
1183 gen_op_cmpi(SIMM(ctx
->opcode
));
1184 gen_op_store_T0_crf(crfD(ctx
->opcode
));
1187 GEN_CMP(cmpl
, 0x01, PPC_INTEGER
);
1189 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
)
1191 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
1192 #if defined(TARGET_PPC64)
1193 if (ctx
->sf_mode
&& (ctx
->opcode
& 0x00200000))
1194 gen_op_cmpli_64(UIMM(ctx
->opcode
));
1197 gen_op_cmpli(UIMM(ctx
->opcode
));
1198 gen_op_store_T0_crf(crfD(ctx
->opcode
));
1201 /* isel (PowerPC 2.03 specification) */
1202 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
)
1204 uint32_t bi
= rC(ctx
->opcode
);
1207 if (rA(ctx
->opcode
) == 0) {
1208 tcg_gen_movi_tl(cpu_T
[0], 0);
1210 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rA(ctx
->opcode
)]);
1212 tcg_gen_mov_tl(cpu_T
[2], cpu_gpr
[rB(ctx
->opcode
)]);
1213 mask
= 1 << (3 - (bi
& 0x03));
1214 gen_op_load_crf_T0(bi
>> 2);
1215 gen_op_test_true(mask
);
1217 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
1220 /*** Integer logical ***/
1221 #define __GEN_LOGICAL2(name, opc2, opc3, type) \
1222 GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000000, type) \
1224 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]); \
1225 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rB(ctx->opcode)]); \
1227 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
1228 if (unlikely(Rc(ctx->opcode) != 0)) \
1231 #define GEN_LOGICAL2(name, opc, type) \
1232 __GEN_LOGICAL2(name, 0x1C, opc, type)
1234 #define GEN_LOGICAL1(name, opc, type) \
1235 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type) \
1237 tcg_gen_mov_tl(cpu_T[0], cpu_gpr[rS(ctx->opcode)]); \
1239 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
1240 if (unlikely(Rc(ctx->opcode) != 0)) \
1245 GEN_LOGICAL2(and, 0x00, PPC_INTEGER
);
1247 GEN_LOGICAL2(andc
, 0x01, PPC_INTEGER
);
1249 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1251 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
1252 gen_op_andi_T0(UIMM(ctx
->opcode
));
1253 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
1257 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1259 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
1260 gen_op_andi_T0(UIMM(ctx
->opcode
) << 16);
1261 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
1266 GEN_LOGICAL1(cntlzw
, 0x00, PPC_INTEGER
);
1268 GEN_LOGICAL2(eqv
, 0x08, PPC_INTEGER
);
1269 /* extsb & extsb. */
1270 GEN_LOGICAL1(extsb
, 0x1D, PPC_INTEGER
);
1271 /* extsh & extsh. */
1272 GEN_LOGICAL1(extsh
, 0x1C, PPC_INTEGER
);
1274 GEN_LOGICAL2(nand
, 0x0E, PPC_INTEGER
);
1276 GEN_LOGICAL2(nor
, 0x03, PPC_INTEGER
);
1279 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
)
1283 rs
= rS(ctx
->opcode
);
1284 ra
= rA(ctx
->opcode
);
1285 rb
= rB(ctx
->opcode
);
1286 /* Optimisation for mr. ri case */
1287 if (rs
!= ra
|| rs
!= rb
) {
1288 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rs
]);
1290 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rb
]);
1293 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_T
[0]);
1294 if (unlikely(Rc(ctx
->opcode
) != 0))
1296 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
1297 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rs
]);
1299 #if defined(TARGET_PPC64)
1303 /* Set process priority to low */
1304 gen_op_store_pri(2);
1307 /* Set process priority to medium-low */
1308 gen_op_store_pri(3);
1311 /* Set process priority to normal */
1312 gen_op_store_pri(4);
1314 #if !defined(CONFIG_USER_ONLY)
1316 if (ctx
->supervisor
> 0) {
1317 /* Set process priority to very low */
1318 gen_op_store_pri(1);
1322 if (ctx
->supervisor
> 0) {
1323 /* Set process priority to medium-hight */
1324 gen_op_store_pri(5);
1328 if (ctx
->supervisor
> 0) {
1329 /* Set process priority to high */
1330 gen_op_store_pri(6);
1334 if (ctx
->supervisor
> 1) {
1335 /* Set process priority to very high */
1336 gen_op_store_pri(7);
1349 GEN_LOGICAL2(orc
, 0x0C, PPC_INTEGER
);
1351 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
)
1353 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
1354 /* Optimisation for "set to zero" case */
1355 if (rS(ctx
->opcode
) != rB(ctx
->opcode
)) {
1356 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
1359 tcg_gen_movi_tl(cpu_T
[0], 0);
1361 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
1362 if (unlikely(Rc(ctx
->opcode
) != 0))
1366 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1368 target_ulong uimm
= UIMM(ctx
->opcode
);
1370 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1372 /* XXX: should handle special NOPs for POWER series */
1375 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
1376 if (likely(uimm
!= 0))
1378 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
1381 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1383 target_ulong uimm
= UIMM(ctx
->opcode
);
1385 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1389 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
1390 if (likely(uimm
!= 0))
1391 gen_op_ori(uimm
<< 16);
1392 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
1395 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1397 target_ulong uimm
= UIMM(ctx
->opcode
);
1399 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1403 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
1404 if (likely(uimm
!= 0))
1406 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
1410 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1412 target_ulong uimm
= UIMM(ctx
->opcode
);
1414 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
1418 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
1419 if (likely(uimm
!= 0))
1420 gen_op_xori(uimm
<< 16);
1421 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
1424 /* popcntb : PowerPC 2.03 specification */
1425 GEN_HANDLER(popcntb
, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB
)
1427 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
1428 #if defined(TARGET_PPC64)
1430 gen_op_popcntb_64();
1434 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
1437 #if defined(TARGET_PPC64)
1438 /* extsw & extsw. */
1439 GEN_LOGICAL1(extsw
, 0x1E, PPC_64B
);
1441 GEN_LOGICAL1(cntlzd
, 0x01, PPC_64B
);
1444 /*** Integer rotate ***/
1445 /* rlwimi & rlwimi. */
1446 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1449 uint32_t mb
, me
, sh
;
1451 mb
= MB(ctx
->opcode
);
1452 me
= ME(ctx
->opcode
);
1453 sh
= SH(ctx
->opcode
);
1454 if (likely(sh
== 0)) {
1455 if (likely(mb
== 0 && me
== 31)) {
1456 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
1458 } else if (likely(mb
== 31 && me
== 0)) {
1459 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
1462 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
1463 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rA(ctx
->opcode
)]);
1466 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
1467 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rA(ctx
->opcode
)]);
1468 gen_op_rotli32_T0(SH(ctx
->opcode
));
1470 #if defined(TARGET_PPC64)
1474 mask
= MASK(mb
, me
);
1475 gen_op_andi_T0(mask
);
1476 gen_op_andi_T1(~mask
);
1479 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
1480 if (unlikely(Rc(ctx
->opcode
) != 0))
1483 /* rlwinm & rlwinm. */
1484 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1486 uint32_t mb
, me
, sh
;
1488 sh
= SH(ctx
->opcode
);
1489 mb
= MB(ctx
->opcode
);
1490 me
= ME(ctx
->opcode
);
1491 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
1492 if (likely(sh
== 0)) {
1495 if (likely(mb
== 0)) {
1496 if (likely(me
== 31)) {
1497 gen_op_rotli32_T0(sh
);
1499 } else if (likely(me
== (31 - sh
))) {
1503 } else if (likely(me
== 31)) {
1504 if (likely(sh
== (32 - mb
))) {
1509 gen_op_rotli32_T0(sh
);
1511 #if defined(TARGET_PPC64)
1515 gen_op_andi_T0(MASK(mb
, me
));
1517 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
1518 if (unlikely(Rc(ctx
->opcode
) != 0))
1521 /* rlwnm & rlwnm. */
1522 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
1526 mb
= MB(ctx
->opcode
);
1527 me
= ME(ctx
->opcode
);
1528 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
1529 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
1530 gen_op_rotl32_T0_T1();
1531 if (unlikely(mb
!= 0 || me
!= 31)) {
1532 #if defined(TARGET_PPC64)
1536 gen_op_andi_T0(MASK(mb
, me
));
1538 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
1539 if (unlikely(Rc(ctx
->opcode
) != 0))
1543 #if defined(TARGET_PPC64)
1544 #define GEN_PPC64_R2(name, opc1, opc2) \
1545 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1547 gen_##name(ctx, 0); \
1549 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1552 gen_##name(ctx, 1); \
1554 #define GEN_PPC64_R4(name, opc1, opc2) \
1555 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B) \
1557 gen_##name(ctx, 0, 0); \
1559 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
1562 gen_##name(ctx, 0, 1); \
1564 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
1567 gen_##name(ctx, 1, 0); \
1569 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
1572 gen_##name(ctx, 1, 1); \
1575 static always_inline
void gen_andi_T0_64 (DisasContext
*ctx
, uint64_t mask
)
1578 gen_op_andi_T0_64(mask
>> 32, mask
& 0xFFFFFFFF);
1580 gen_op_andi_T0(mask
);
1583 static always_inline
void gen_andi_T1_64 (DisasContext
*ctx
, uint64_t mask
)
1586 gen_op_andi_T1_64(mask
>> 32, mask
& 0xFFFFFFFF);
1588 gen_op_andi_T1(mask
);
1591 static always_inline
void gen_rldinm (DisasContext
*ctx
, uint32_t mb
,
1592 uint32_t me
, uint32_t sh
)
1594 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
1595 if (likely(sh
== 0)) {
1598 if (likely(mb
== 0)) {
1599 if (likely(me
== 63)) {
1600 gen_op_rotli64_T0(sh
);
1602 } else if (likely(me
== (63 - sh
))) {
1606 } else if (likely(me
== 63)) {
1607 if (likely(sh
== (64 - mb
))) {
1608 gen_op_srli_T0_64(mb
);
1612 gen_op_rotli64_T0(sh
);
1614 gen_andi_T0_64(ctx
, MASK(mb
, me
));
1616 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
1617 if (unlikely(Rc(ctx
->opcode
) != 0))
1620 /* rldicl - rldicl. */
1621 static always_inline
void gen_rldicl (DisasContext
*ctx
, int mbn
, int shn
)
1625 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1626 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1627 gen_rldinm(ctx
, mb
, 63, sh
);
1629 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
1630 /* rldicr - rldicr. */
1631 static always_inline
void gen_rldicr (DisasContext
*ctx
, int men
, int shn
)
1635 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1636 me
= MB(ctx
->opcode
) | (men
<< 5);
1637 gen_rldinm(ctx
, 0, me
, sh
);
1639 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
1640 /* rldic - rldic. */
1641 static always_inline
void gen_rldic (DisasContext
*ctx
, int mbn
, int shn
)
1645 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1646 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1647 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
1649 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
1651 static always_inline
void gen_rldnm (DisasContext
*ctx
, uint32_t mb
,
1654 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
1655 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
1656 gen_op_rotl64_T0_T1();
1657 if (unlikely(mb
!= 0 || me
!= 63)) {
1658 gen_andi_T0_64(ctx
, MASK(mb
, me
));
1660 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
1661 if (unlikely(Rc(ctx
->opcode
) != 0))
1665 /* rldcl - rldcl. */
1666 static always_inline
void gen_rldcl (DisasContext
*ctx
, int mbn
)
1670 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1671 gen_rldnm(ctx
, mb
, 63);
1673 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
1674 /* rldcr - rldcr. */
1675 static always_inline
void gen_rldcr (DisasContext
*ctx
, int men
)
1679 me
= MB(ctx
->opcode
) | (men
<< 5);
1680 gen_rldnm(ctx
, 0, me
);
1682 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
1683 /* rldimi - rldimi. */
1684 static always_inline
void gen_rldimi (DisasContext
*ctx
, int mbn
, int shn
)
1687 uint32_t sh
, mb
, me
;
1689 sh
= SH(ctx
->opcode
) | (shn
<< 5);
1690 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
1692 if (likely(sh
== 0)) {
1693 if (likely(mb
== 0)) {
1694 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
1697 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
1698 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rA(ctx
->opcode
)]);
1701 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
1702 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rA(ctx
->opcode
)]);
1703 gen_op_rotli64_T0(sh
);
1705 mask
= MASK(mb
, me
);
1706 gen_andi_T0_64(ctx
, mask
);
1707 gen_andi_T1_64(ctx
, ~mask
);
1710 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
1711 if (unlikely(Rc(ctx
->opcode
) != 0))
1714 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
1717 /*** Integer shift ***/
1719 __GEN_LOGICAL2(slw
, 0x18, 0x00, PPC_INTEGER
);
1721 __GEN_LOGICAL2(sraw
, 0x18, 0x18, PPC_INTEGER
);
1722 /* srawi & srawi. */
1723 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
)
1726 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
1727 if (SH(ctx
->opcode
) != 0) {
1728 tcg_gen_mov_tl(cpu_T
[1], cpu_T
[0]);
1729 mb
= 32 - SH(ctx
->opcode
);
1731 #if defined(TARGET_PPC64)
1735 gen_op_srawi(SH(ctx
->opcode
), MASK(mb
, me
));
1737 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
1738 if (unlikely(Rc(ctx
->opcode
) != 0))
1742 __GEN_LOGICAL2(srw
, 0x18, 0x10, PPC_INTEGER
);
1744 #if defined(TARGET_PPC64)
1746 __GEN_LOGICAL2(sld
, 0x1B, 0x00, PPC_64B
);
1748 __GEN_LOGICAL2(srad
, 0x1A, 0x18, PPC_64B
);
1749 /* sradi & sradi. */
1750 static always_inline
void gen_sradi (DisasContext
*ctx
, int n
)
1755 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
1756 sh
= SH(ctx
->opcode
) + (n
<< 5);
1758 tcg_gen_mov_tl(cpu_T
[1], cpu_T
[0]);
1759 mb
= 64 - SH(ctx
->opcode
);
1761 mask
= MASK(mb
, me
);
1762 gen_op_sradi(sh
, mask
>> 32, mask
);
1764 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
1765 if (unlikely(Rc(ctx
->opcode
) != 0))
1768 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
)
1772 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
)
1777 __GEN_LOGICAL2(srd
, 0x1B, 0x10, PPC_64B
);
1780 /*** Floating-Point arithmetic ***/
1781 #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \
1782 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type) \
1784 if (unlikely(!ctx->fpu_enabled)) { \
1785 GEN_EXCP_NO_FP(ctx); \
1788 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]); \
1789 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rC(ctx->opcode)]); \
1790 tcg_gen_mov_i64(cpu_FT[2], cpu_fpr[rB(ctx->opcode)]); \
1791 gen_reset_fpstatus(); \
1796 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
1797 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
1800 #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \
1801 _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \
1802 _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type);
1804 #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \
1805 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
1807 if (unlikely(!ctx->fpu_enabled)) { \
1808 GEN_EXCP_NO_FP(ctx); \
1811 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]); \
1812 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rB(ctx->opcode)]); \
1813 gen_reset_fpstatus(); \
1818 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
1819 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
1821 #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \
1822 _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
1823 _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
1825 #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \
1826 GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) \
1828 if (unlikely(!ctx->fpu_enabled)) { \
1829 GEN_EXCP_NO_FP(ctx); \
1832 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rA(ctx->opcode)]); \
1833 tcg_gen_mov_i64(cpu_FT[1], cpu_fpr[rC(ctx->opcode)]); \
1834 gen_reset_fpstatus(); \
1839 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
1840 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
1842 #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \
1843 _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \
1844 _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type);
1846 #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \
1847 GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type) \
1849 if (unlikely(!ctx->fpu_enabled)) { \
1850 GEN_EXCP_NO_FP(ctx); \
1853 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]); \
1854 gen_reset_fpstatus(); \
1856 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
1857 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
1860 #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \
1861 GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type) \
1863 if (unlikely(!ctx->fpu_enabled)) { \
1864 GEN_EXCP_NO_FP(ctx); \
1867 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rB(ctx->opcode)]); \
1868 gen_reset_fpstatus(); \
1870 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
1871 gen_compute_fprf(set_fprf, Rc(ctx->opcode) != 0); \
1875 GEN_FLOAT_AB(add
, 0x15, 0x000007C0, 1, PPC_FLOAT
);
1877 GEN_FLOAT_AB(div
, 0x12, 0x000007C0, 1, PPC_FLOAT
);
1879 GEN_FLOAT_AC(mul
, 0x19, 0x0000F800, 1, PPC_FLOAT
);
1882 GEN_FLOAT_BS(re
, 0x3F, 0x18, 1, PPC_FLOAT_EXT
);
1885 GEN_FLOAT_BS(res
, 0x3B, 0x18, 1, PPC_FLOAT_FRES
);
1888 GEN_FLOAT_BS(rsqrte
, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE
);
1891 static always_inline
void gen_op_frsqrtes (void)
1896 GEN_FLOAT_BS(rsqrtes
, 0x3B, 0x1A, 1, PPC_FLOAT_FRSQRTES
);
1899 _GEN_FLOAT_ACB(sel
, sel
, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL
);
1901 GEN_FLOAT_AB(sub
, 0x14, 0x000007C0, 1, PPC_FLOAT
);
1904 GEN_HANDLER(fsqrt
, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
)
1906 if (unlikely(!ctx
->fpu_enabled
)) {
1907 GEN_EXCP_NO_FP(ctx
);
1910 tcg_gen_mov_i64(cpu_FT
[0], cpu_fpr
[rB(ctx
->opcode
)]);
1911 gen_reset_fpstatus();
1913 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_FT
[0]);
1914 gen_compute_fprf(1, Rc(ctx
->opcode
) != 0);
1917 GEN_HANDLER(fsqrts
, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT
)
1919 if (unlikely(!ctx
->fpu_enabled
)) {
1920 GEN_EXCP_NO_FP(ctx
);
1923 tcg_gen_mov_i64(cpu_FT
[0], cpu_fpr
[rB(ctx
->opcode
)]);
1924 gen_reset_fpstatus();
1927 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_FT
[0]);
1928 gen_compute_fprf(1, Rc(ctx
->opcode
) != 0);
1931 /*** Floating-Point multiply-and-add ***/
1932 /* fmadd - fmadds */
1933 GEN_FLOAT_ACB(madd
, 0x1D, 1, PPC_FLOAT
);
1934 /* fmsub - fmsubs */
1935 GEN_FLOAT_ACB(msub
, 0x1C, 1, PPC_FLOAT
);
1936 /* fnmadd - fnmadds */
1937 GEN_FLOAT_ACB(nmadd
, 0x1F, 1, PPC_FLOAT
);
1938 /* fnmsub - fnmsubs */
1939 GEN_FLOAT_ACB(nmsub
, 0x1E, 1, PPC_FLOAT
);
1941 /*** Floating-Point round & convert ***/
1943 GEN_FLOAT_B(ctiw
, 0x0E, 0x00, 0, PPC_FLOAT
);
1945 GEN_FLOAT_B(ctiwz
, 0x0F, 0x00, 0, PPC_FLOAT
);
1947 GEN_FLOAT_B(rsp
, 0x0C, 0x00, 1, PPC_FLOAT
);
1948 #if defined(TARGET_PPC64)
1950 GEN_FLOAT_B(cfid
, 0x0E, 0x1A, 1, PPC_64B
);
1952 GEN_FLOAT_B(ctid
, 0x0E, 0x19, 0, PPC_64B
);
1954 GEN_FLOAT_B(ctidz
, 0x0F, 0x19, 0, PPC_64B
);
1958 GEN_FLOAT_B(rin
, 0x08, 0x0C, 1, PPC_FLOAT_EXT
);
1960 GEN_FLOAT_B(riz
, 0x08, 0x0D, 1, PPC_FLOAT_EXT
);
1962 GEN_FLOAT_B(rip
, 0x08, 0x0E, 1, PPC_FLOAT_EXT
);
1964 GEN_FLOAT_B(rim
, 0x08, 0x0F, 1, PPC_FLOAT_EXT
);
1966 /*** Floating-Point compare ***/
1968 GEN_HANDLER(fcmpo
, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT
)
1970 if (unlikely(!ctx
->fpu_enabled
)) {
1971 GEN_EXCP_NO_FP(ctx
);
1974 tcg_gen_mov_i64(cpu_FT
[0], cpu_fpr
[rA(ctx
->opcode
)]);
1975 tcg_gen_mov_i64(cpu_FT
[1], cpu_fpr
[rB(ctx
->opcode
)]);
1976 gen_reset_fpstatus();
1978 gen_op_store_T0_crf(crfD(ctx
->opcode
));
1979 gen_op_float_check_status();
1983 GEN_HANDLER(fcmpu
, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT
)
1985 if (unlikely(!ctx
->fpu_enabled
)) {
1986 GEN_EXCP_NO_FP(ctx
);
1989 tcg_gen_mov_i64(cpu_FT
[0], cpu_fpr
[rA(ctx
->opcode
)]);
1990 tcg_gen_mov_i64(cpu_FT
[1], cpu_fpr
[rB(ctx
->opcode
)]);
1991 gen_reset_fpstatus();
1993 gen_op_store_T0_crf(crfD(ctx
->opcode
));
1994 gen_op_float_check_status();
1997 /*** Floating-point move ***/
1999 /* XXX: beware that fabs never checks for NaNs nor update FPSCR */
2000 GEN_FLOAT_B(abs
, 0x08, 0x08, 0, PPC_FLOAT
);
2003 /* XXX: beware that fmr never checks for NaNs nor update FPSCR */
2004 GEN_HANDLER(fmr
, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT
)
2006 if (unlikely(!ctx
->fpu_enabled
)) {
2007 GEN_EXCP_NO_FP(ctx
);
2010 tcg_gen_mov_i64(cpu_FT
[0], cpu_fpr
[rB(ctx
->opcode
)]);
2011 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_FT
[0]);
2012 gen_compute_fprf(0, Rc(ctx
->opcode
) != 0);
2016 /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */
2017 GEN_FLOAT_B(nabs
, 0x08, 0x04, 0, PPC_FLOAT
);
2019 /* XXX: beware that fneg never checks for NaNs nor update FPSCR */
2020 GEN_FLOAT_B(neg
, 0x08, 0x01, 0, PPC_FLOAT
);
2022 /*** Floating-Point status & ctrl register ***/
2024 GEN_HANDLER(mcrfs
, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT
)
2028 if (unlikely(!ctx
->fpu_enabled
)) {
2029 GEN_EXCP_NO_FP(ctx
);
2032 gen_optimize_fprf();
2033 bfa
= 4 * (7 - crfS(ctx
->opcode
));
2034 gen_op_load_fpscr_T0(bfa
);
2035 gen_op_store_T0_crf(crfD(ctx
->opcode
));
2036 gen_op_fpscr_resetbit(~(0xF << bfa
));
2040 GEN_HANDLER(mffs
, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT
)
2042 if (unlikely(!ctx
->fpu_enabled
)) {
2043 GEN_EXCP_NO_FP(ctx
);
2046 gen_optimize_fprf();
2047 gen_reset_fpstatus();
2048 gen_op_load_fpscr_FT0();
2049 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_FT
[0]);
2050 gen_compute_fprf(0, Rc(ctx
->opcode
) != 0);
2054 GEN_HANDLER(mtfsb0
, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT
)
2058 if (unlikely(!ctx
->fpu_enabled
)) {
2059 GEN_EXCP_NO_FP(ctx
);
2062 crb
= 32 - (crbD(ctx
->opcode
) >> 2);
2063 gen_optimize_fprf();
2064 gen_reset_fpstatus();
2065 if (likely(crb
!= 30 && crb
!= 29))
2066 gen_op_fpscr_resetbit(~(1 << crb
));
2067 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2074 GEN_HANDLER(mtfsb1
, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT
)
2078 if (unlikely(!ctx
->fpu_enabled
)) {
2079 GEN_EXCP_NO_FP(ctx
);
2082 crb
= 32 - (crbD(ctx
->opcode
) >> 2);
2083 gen_optimize_fprf();
2084 gen_reset_fpstatus();
2085 /* XXX: we pretend we can only do IEEE floating-point computations */
2086 if (likely(crb
!= FPSCR_FEX
&& crb
!= FPSCR_VX
&& crb
!= FPSCR_NI
))
2087 gen_op_fpscr_setbit(crb
);
2088 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2092 /* We can raise a differed exception */
2093 gen_op_float_check_status();
2097 GEN_HANDLER(mtfsf
, 0x3F, 0x07, 0x16, 0x02010000, PPC_FLOAT
)
2099 if (unlikely(!ctx
->fpu_enabled
)) {
2100 GEN_EXCP_NO_FP(ctx
);
2103 gen_optimize_fprf();
2104 tcg_gen_mov_i64(cpu_FT
[0], cpu_fpr
[rB(ctx
->opcode
)]);
2105 gen_reset_fpstatus();
2106 gen_op_store_fpscr(FM(ctx
->opcode
));
2107 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2111 /* We can raise a differed exception */
2112 gen_op_float_check_status();
2116 GEN_HANDLER(mtfsfi
, 0x3F, 0x06, 0x04, 0x006f0800, PPC_FLOAT
)
2120 if (unlikely(!ctx
->fpu_enabled
)) {
2121 GEN_EXCP_NO_FP(ctx
);
2124 bf
= crbD(ctx
->opcode
) >> 2;
2126 gen_optimize_fprf();
2127 gen_op_set_FT0(FPIMM(ctx
->opcode
) << (4 * sh
));
2128 gen_reset_fpstatus();
2129 gen_op_store_fpscr(1 << sh
);
2130 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2134 /* We can raise a differed exception */
2135 gen_op_float_check_status();
2138 /*** Addressing modes ***/
2139 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2140 static always_inline
void gen_addr_imm_index (DisasContext
*ctx
,
2143 target_long simm
= SIMM(ctx
->opcode
);
2146 if (rA(ctx
->opcode
) == 0) {
2147 tcg_gen_movi_tl(cpu_T
[0], simm
);
2149 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
2150 if (likely(simm
!= 0))
2153 #ifdef DEBUG_MEMORY_ACCESSES
2154 gen_op_print_mem_EA();
2158 static always_inline
void gen_addr_reg_index (DisasContext
*ctx
)
2160 if (rA(ctx
->opcode
) == 0) {
2161 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rB(ctx
->opcode
)]);
2163 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
2164 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
2167 #ifdef DEBUG_MEMORY_ACCESSES
2168 gen_op_print_mem_EA();
2172 static always_inline
void gen_addr_register (DisasContext
*ctx
)
2174 if (rA(ctx
->opcode
) == 0) {
2175 tcg_gen_movi_tl(cpu_T
[0], 0);
2177 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
2179 #ifdef DEBUG_MEMORY_ACCESSES
2180 gen_op_print_mem_EA();
2184 #if defined(TARGET_PPC64)
2185 #define _GEN_MEM_FUNCS(name, mode) \
2186 &gen_op_##name##_##mode, \
2187 &gen_op_##name##_le_##mode, \
2188 &gen_op_##name##_64_##mode, \
2189 &gen_op_##name##_le_64_##mode
2191 #define _GEN_MEM_FUNCS(name, mode) \
2192 &gen_op_##name##_##mode, \
2193 &gen_op_##name##_le_##mode
2195 #if defined(CONFIG_USER_ONLY)
2196 #if defined(TARGET_PPC64)
2197 #define NB_MEM_FUNCS 4
2199 #define NB_MEM_FUNCS 2
2201 #define GEN_MEM_FUNCS(name) \
2202 _GEN_MEM_FUNCS(name, raw)
2204 #if defined(TARGET_PPC64)
2205 #define NB_MEM_FUNCS 12
2207 #define NB_MEM_FUNCS 6
2209 #define GEN_MEM_FUNCS(name) \
2210 _GEN_MEM_FUNCS(name, user), \
2211 _GEN_MEM_FUNCS(name, kernel), \
2212 _GEN_MEM_FUNCS(name, hypv)
2215 /*** Integer load ***/
2216 #define op_ldst(name) (*gen_op_##name[ctx->mem_idx])()
2217 /* Byte access routine are endian safe */
2218 #define gen_op_lbz_le_raw gen_op_lbz_raw
2219 #define gen_op_lbz_le_user gen_op_lbz_user
2220 #define gen_op_lbz_le_kernel gen_op_lbz_kernel
2221 #define gen_op_lbz_le_hypv gen_op_lbz_hypv
2222 #define gen_op_lbz_le_64_raw gen_op_lbz_64_raw
2223 #define gen_op_lbz_le_64_user gen_op_lbz_64_user
2224 #define gen_op_lbz_le_64_kernel gen_op_lbz_64_kernel
2225 #define gen_op_lbz_le_64_hypv gen_op_lbz_64_hypv
2226 #define gen_op_stb_le_raw gen_op_stb_raw
2227 #define gen_op_stb_le_user gen_op_stb_user
2228 #define gen_op_stb_le_kernel gen_op_stb_kernel
2229 #define gen_op_stb_le_hypv gen_op_stb_hypv
2230 #define gen_op_stb_le_64_raw gen_op_stb_64_raw
2231 #define gen_op_stb_le_64_user gen_op_stb_64_user
2232 #define gen_op_stb_le_64_kernel gen_op_stb_64_kernel
2233 #define gen_op_stb_le_64_hypv gen_op_stb_64_hypv
2234 #define OP_LD_TABLE(width) \
2235 static GenOpFunc *gen_op_l##width[NB_MEM_FUNCS] = { \
2236 GEN_MEM_FUNCS(l##width), \
2238 #define OP_ST_TABLE(width) \
2239 static GenOpFunc *gen_op_st##width[NB_MEM_FUNCS] = { \
2240 GEN_MEM_FUNCS(st##width), \
2243 #define GEN_LD(width, opc, type) \
2244 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2246 gen_addr_imm_index(ctx, 0); \
2247 op_ldst(l##width); \
2248 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[1]); \
2251 #define GEN_LDU(width, opc, type) \
2252 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2254 if (unlikely(rA(ctx->opcode) == 0 || \
2255 rA(ctx->opcode) == rD(ctx->opcode))) { \
2256 GEN_EXCP_INVAL(ctx); \
2259 if (type == PPC_64B) \
2260 gen_addr_imm_index(ctx, 0x03); \
2262 gen_addr_imm_index(ctx, 0); \
2263 op_ldst(l##width); \
2264 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[1]); \
2265 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
2268 #define GEN_LDUX(width, opc2, opc3, type) \
2269 GEN_HANDLER(l##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2271 if (unlikely(rA(ctx->opcode) == 0 || \
2272 rA(ctx->opcode) == rD(ctx->opcode))) { \
2273 GEN_EXCP_INVAL(ctx); \
2276 gen_addr_reg_index(ctx); \
2277 op_ldst(l##width); \
2278 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[1]); \
2279 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
2282 #define GEN_LDX(width, opc2, opc3, type) \
2283 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2285 gen_addr_reg_index(ctx); \
2286 op_ldst(l##width); \
2287 tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_T[1]); \
2290 #define GEN_LDS(width, op, type) \
2291 OP_LD_TABLE(width); \
2292 GEN_LD(width, op | 0x20, type); \
2293 GEN_LDU(width, op | 0x21, type); \
2294 GEN_LDUX(width, 0x17, op | 0x01, type); \
2295 GEN_LDX(width, 0x17, op | 0x00, type)
2297 /* lbz lbzu lbzux lbzx */
2298 GEN_LDS(bz
, 0x02, PPC_INTEGER
);
2299 /* lha lhau lhaux lhax */
2300 GEN_LDS(ha
, 0x0A, PPC_INTEGER
);
2301 /* lhz lhzu lhzux lhzx */
2302 GEN_LDS(hz
, 0x08, PPC_INTEGER
);
2303 /* lwz lwzu lwzux lwzx */
2304 GEN_LDS(wz
, 0x00, PPC_INTEGER
);
2305 #if defined(TARGET_PPC64)
2309 GEN_LDUX(wa
, 0x15, 0x0B, PPC_64B
);
2311 GEN_LDX(wa
, 0x15, 0x0A, PPC_64B
);
2313 GEN_LDUX(d
, 0x15, 0x01, PPC_64B
);
2315 GEN_LDX(d
, 0x15, 0x00, PPC_64B
);
2316 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
)
2318 if (Rc(ctx
->opcode
)) {
2319 if (unlikely(rA(ctx
->opcode
) == 0 ||
2320 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
2321 GEN_EXCP_INVAL(ctx
);
2325 gen_addr_imm_index(ctx
, 0x03);
2326 if (ctx
->opcode
& 0x02) {
2327 /* lwa (lwau is undefined) */
2333 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[1]);
2334 if (Rc(ctx
->opcode
))
2335 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
2338 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
)
2340 #if defined(CONFIG_USER_ONLY)
2341 GEN_EXCP_PRIVOPC(ctx
);
2345 /* Restore CPU state */
2346 if (unlikely(ctx
->supervisor
== 0)) {
2347 GEN_EXCP_PRIVOPC(ctx
);
2350 ra
= rA(ctx
->opcode
);
2351 rd
= rD(ctx
->opcode
);
2352 if (unlikely((rd
& 1) || rd
== ra
)) {
2353 GEN_EXCP_INVAL(ctx
);
2356 if (unlikely(ctx
->mem_idx
& 1)) {
2357 /* Little-endian mode is not handled */
2358 GEN_EXCP(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2361 gen_addr_imm_index(ctx
, 0x0F);
2363 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_T
[1]);
2366 tcg_gen_mov_tl(cpu_gpr
[rd
+ 1], cpu_T
[1]);
2371 /*** Integer store ***/
2372 #define GEN_ST(width, opc, type) \
2373 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2375 gen_addr_imm_index(ctx, 0); \
2376 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]); \
2377 op_ldst(st##width); \
2380 #define GEN_STU(width, opc, type) \
2381 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2383 if (unlikely(rA(ctx->opcode) == 0)) { \
2384 GEN_EXCP_INVAL(ctx); \
2387 if (type == PPC_64B) \
2388 gen_addr_imm_index(ctx, 0x03); \
2390 gen_addr_imm_index(ctx, 0); \
2391 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]); \
2392 op_ldst(st##width); \
2393 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
2396 #define GEN_STUX(width, opc2, opc3, type) \
2397 GEN_HANDLER(st##width##ux, 0x1F, opc2, opc3, 0x00000001, type) \
2399 if (unlikely(rA(ctx->opcode) == 0)) { \
2400 GEN_EXCP_INVAL(ctx); \
2403 gen_addr_reg_index(ctx); \
2404 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]); \
2405 op_ldst(st##width); \
2406 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
2409 #define GEN_STX(width, opc2, opc3, type) \
2410 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2412 gen_addr_reg_index(ctx); \
2413 tcg_gen_mov_tl(cpu_T[1], cpu_gpr[rS(ctx->opcode)]); \
2414 op_ldst(st##width); \
2417 #define GEN_STS(width, op, type) \
2418 OP_ST_TABLE(width); \
2419 GEN_ST(width, op | 0x20, type); \
2420 GEN_STU(width, op | 0x21, type); \
2421 GEN_STUX(width, 0x17, op | 0x01, type); \
2422 GEN_STX(width, 0x17, op | 0x00, type)
2424 /* stb stbu stbux stbx */
2425 GEN_STS(b
, 0x06, PPC_INTEGER
);
2426 /* sth sthu sthux sthx */
2427 GEN_STS(h
, 0x0C, PPC_INTEGER
);
2428 /* stw stwu stwux stwx */
2429 GEN_STS(w
, 0x04, PPC_INTEGER
);
2430 #if defined(TARGET_PPC64)
2432 GEN_STUX(d
, 0x15, 0x05, PPC_64B
);
2433 GEN_STX(d
, 0x15, 0x04, PPC_64B
);
2434 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
)
2438 rs
= rS(ctx
->opcode
);
2439 if ((ctx
->opcode
& 0x3) == 0x2) {
2440 #if defined(CONFIG_USER_ONLY)
2441 GEN_EXCP_PRIVOPC(ctx
);
2444 if (unlikely(ctx
->supervisor
== 0)) {
2445 GEN_EXCP_PRIVOPC(ctx
);
2448 if (unlikely(rs
& 1)) {
2449 GEN_EXCP_INVAL(ctx
);
2452 if (unlikely(ctx
->mem_idx
& 1)) {
2453 /* Little-endian mode is not handled */
2454 GEN_EXCP(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_LE
);
2457 gen_addr_imm_index(ctx
, 0x03);
2458 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rs
]);
2461 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rs
+ 1]);
2466 if (Rc(ctx
->opcode
)) {
2467 if (unlikely(rA(ctx
->opcode
) == 0)) {
2468 GEN_EXCP_INVAL(ctx
);
2472 gen_addr_imm_index(ctx
, 0x03);
2473 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rs
]);
2475 if (Rc(ctx
->opcode
))
2476 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
2480 /*** Integer load and store with byte reverse ***/
2483 GEN_LDX(hbr
, 0x16, 0x18, PPC_INTEGER
);
2486 GEN_LDX(wbr
, 0x16, 0x10, PPC_INTEGER
);
2489 GEN_STX(hbr
, 0x16, 0x1C, PPC_INTEGER
);
2492 GEN_STX(wbr
, 0x16, 0x14, PPC_INTEGER
);
2494 /*** Integer load and store multiple ***/
2495 #define op_ldstm(name, reg) (*gen_op_##name[ctx->mem_idx])(reg)
2496 static GenOpFunc1
*gen_op_lmw
[NB_MEM_FUNCS
] = {
2499 static GenOpFunc1
*gen_op_stmw
[NB_MEM_FUNCS
] = {
2500 GEN_MEM_FUNCS(stmw
),
2504 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
2506 /* NIP cannot be restored if the memory exception comes from an helper */
2507 gen_update_nip(ctx
, ctx
->nip
- 4);
2508 gen_addr_imm_index(ctx
, 0);
2509 op_ldstm(lmw
, rD(ctx
->opcode
));
2513 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
)
2515 /* NIP cannot be restored if the memory exception comes from an helper */
2516 gen_update_nip(ctx
, ctx
->nip
- 4);
2517 gen_addr_imm_index(ctx
, 0);
2518 op_ldstm(stmw
, rS(ctx
->opcode
));
2521 /*** Integer load and store strings ***/
2522 #define op_ldsts(name, start) (*gen_op_##name[ctx->mem_idx])(start)
2523 #define op_ldstsx(name, rd, ra, rb) (*gen_op_##name[ctx->mem_idx])(rd, ra, rb)
2524 /* string load & stores are by definition endian-safe */
2525 #define gen_op_lswi_le_raw gen_op_lswi_raw
2526 #define gen_op_lswi_le_user gen_op_lswi_user
2527 #define gen_op_lswi_le_kernel gen_op_lswi_kernel
2528 #define gen_op_lswi_le_hypv gen_op_lswi_hypv
2529 #define gen_op_lswi_le_64_raw gen_op_lswi_raw
2530 #define gen_op_lswi_le_64_user gen_op_lswi_user
2531 #define gen_op_lswi_le_64_kernel gen_op_lswi_kernel
2532 #define gen_op_lswi_le_64_hypv gen_op_lswi_hypv
2533 static GenOpFunc1
*gen_op_lswi
[NB_MEM_FUNCS
] = {
2534 GEN_MEM_FUNCS(lswi
),
2536 #define gen_op_lswx_le_raw gen_op_lswx_raw
2537 #define gen_op_lswx_le_user gen_op_lswx_user
2538 #define gen_op_lswx_le_kernel gen_op_lswx_kernel
2539 #define gen_op_lswx_le_hypv gen_op_lswx_hypv
2540 #define gen_op_lswx_le_64_raw gen_op_lswx_raw
2541 #define gen_op_lswx_le_64_user gen_op_lswx_user
2542 #define gen_op_lswx_le_64_kernel gen_op_lswx_kernel
2543 #define gen_op_lswx_le_64_hypv gen_op_lswx_hypv
2544 static GenOpFunc3
*gen_op_lswx
[NB_MEM_FUNCS
] = {
2545 GEN_MEM_FUNCS(lswx
),
2547 #define gen_op_stsw_le_raw gen_op_stsw_raw
2548 #define gen_op_stsw_le_user gen_op_stsw_user
2549 #define gen_op_stsw_le_kernel gen_op_stsw_kernel
2550 #define gen_op_stsw_le_hypv gen_op_stsw_hypv
2551 #define gen_op_stsw_le_64_raw gen_op_stsw_raw
2552 #define gen_op_stsw_le_64_user gen_op_stsw_user
2553 #define gen_op_stsw_le_64_kernel gen_op_stsw_kernel
2554 #define gen_op_stsw_le_64_hypv gen_op_stsw_hypv
2555 static GenOpFunc1
*gen_op_stsw
[NB_MEM_FUNCS
] = {
2556 GEN_MEM_FUNCS(stsw
),
2560 /* PowerPC32 specification says we must generate an exception if
2561 * rA is in the range of registers to be loaded.
2562 * In an other hand, IBM says this is valid, but rA won't be loaded.
2563 * For now, I'll follow the spec...
2565 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
)
2567 int nb
= NB(ctx
->opcode
);
2568 int start
= rD(ctx
->opcode
);
2569 int ra
= rA(ctx
->opcode
);
2575 if (unlikely(((start
+ nr
) > 32 &&
2576 start
<= ra
&& (start
+ nr
- 32) > ra
) ||
2577 ((start
+ nr
) <= 32 && start
<= ra
&& (start
+ nr
) > ra
))) {
2578 GEN_EXCP(ctx
, POWERPC_EXCP_PROGRAM
,
2579 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_LSWX
);
2582 /* NIP cannot be restored if the memory exception comes from an helper */
2583 gen_update_nip(ctx
, ctx
->nip
- 4);
2584 gen_addr_register(ctx
);
2585 tcg_gen_movi_tl(cpu_T
[1], nb
);
2586 op_ldsts(lswi
, start
);
2590 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
)
2592 int ra
= rA(ctx
->opcode
);
2593 int rb
= rB(ctx
->opcode
);
2595 /* NIP cannot be restored if the memory exception comes from an helper */
2596 gen_update_nip(ctx
, ctx
->nip
- 4);
2597 gen_addr_reg_index(ctx
);
2601 gen_op_load_xer_bc();
2602 op_ldstsx(lswx
, rD(ctx
->opcode
), ra
, rb
);
2606 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
)
2608 int nb
= NB(ctx
->opcode
);
2610 /* NIP cannot be restored if the memory exception comes from an helper */
2611 gen_update_nip(ctx
, ctx
->nip
- 4);
2612 gen_addr_register(ctx
);
2615 tcg_gen_movi_tl(cpu_T
[1], nb
);
2616 op_ldsts(stsw
, rS(ctx
->opcode
));
2620 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
)
2622 /* NIP cannot be restored if the memory exception comes from an helper */
2623 gen_update_nip(ctx
, ctx
->nip
- 4);
2624 gen_addr_reg_index(ctx
);
2625 gen_op_load_xer_bc();
2626 op_ldsts(stsw
, rS(ctx
->opcode
));
2629 /*** Memory synchronisation ***/
2631 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO
)
2636 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
)
2641 #define op_lwarx() (*gen_op_lwarx[ctx->mem_idx])()
2642 #define op_stwcx() (*gen_op_stwcx[ctx->mem_idx])()
2643 static GenOpFunc
*gen_op_lwarx
[NB_MEM_FUNCS
] = {
2644 GEN_MEM_FUNCS(lwarx
),
2646 static GenOpFunc
*gen_op_stwcx
[NB_MEM_FUNCS
] = {
2647 GEN_MEM_FUNCS(stwcx
),
2651 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000001, PPC_RES
)
2653 /* NIP cannot be restored if the memory exception comes from an helper */
2654 gen_update_nip(ctx
, ctx
->nip
- 4);
2655 gen_addr_reg_index(ctx
);
2657 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[1]);
2661 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
)
2663 /* NIP cannot be restored if the memory exception comes from an helper */
2664 gen_update_nip(ctx
, ctx
->nip
- 4);
2665 gen_addr_reg_index(ctx
);
2666 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
2670 #if defined(TARGET_PPC64)
2671 #define op_ldarx() (*gen_op_ldarx[ctx->mem_idx])()
2672 #define op_stdcx() (*gen_op_stdcx[ctx->mem_idx])()
2673 static GenOpFunc
*gen_op_ldarx
[NB_MEM_FUNCS
] = {
2674 GEN_MEM_FUNCS(ldarx
),
2676 static GenOpFunc
*gen_op_stdcx
[NB_MEM_FUNCS
] = {
2677 GEN_MEM_FUNCS(stdcx
),
2681 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000001, PPC_64B
)
2683 /* NIP cannot be restored if the memory exception comes from an helper */
2684 gen_update_nip(ctx
, ctx
->nip
- 4);
2685 gen_addr_reg_index(ctx
);
2687 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[1]);
2691 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
)
2693 /* NIP cannot be restored if the memory exception comes from an helper */
2694 gen_update_nip(ctx
, ctx
->nip
- 4);
2695 gen_addr_reg_index(ctx
);
2696 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
2699 #endif /* defined(TARGET_PPC64) */
2702 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
)
2707 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
)
2709 /* Stop translation, as the CPU is supposed to sleep from now */
2711 GEN_EXCP(ctx
, EXCP_HLT
, 1);
2714 /*** Floating-point load ***/
2715 #define GEN_LDF(width, opc, type) \
2716 GEN_HANDLER(l##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2718 if (unlikely(!ctx->fpu_enabled)) { \
2719 GEN_EXCP_NO_FP(ctx); \
2722 gen_addr_imm_index(ctx, 0); \
2723 op_ldst(l##width); \
2724 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2727 #define GEN_LDUF(width, opc, type) \
2728 GEN_HANDLER(l##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2730 if (unlikely(!ctx->fpu_enabled)) { \
2731 GEN_EXCP_NO_FP(ctx); \
2734 if (unlikely(rA(ctx->opcode) == 0)) { \
2735 GEN_EXCP_INVAL(ctx); \
2738 gen_addr_imm_index(ctx, 0); \
2739 op_ldst(l##width); \
2740 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2741 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
2744 #define GEN_LDUXF(width, opc, type) \
2745 GEN_HANDLER(l##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \
2747 if (unlikely(!ctx->fpu_enabled)) { \
2748 GEN_EXCP_NO_FP(ctx); \
2751 if (unlikely(rA(ctx->opcode) == 0)) { \
2752 GEN_EXCP_INVAL(ctx); \
2755 gen_addr_reg_index(ctx); \
2756 op_ldst(l##width); \
2757 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2758 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
2761 #define GEN_LDXF(width, opc2, opc3, type) \
2762 GEN_HANDLER(l##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2764 if (unlikely(!ctx->fpu_enabled)) { \
2765 GEN_EXCP_NO_FP(ctx); \
2768 gen_addr_reg_index(ctx); \
2769 op_ldst(l##width); \
2770 tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_FT[0]); \
2773 #define GEN_LDFS(width, op, type) \
2774 OP_LD_TABLE(width); \
2775 GEN_LDF(width, op | 0x20, type); \
2776 GEN_LDUF(width, op | 0x21, type); \
2777 GEN_LDUXF(width, op | 0x01, type); \
2778 GEN_LDXF(width, 0x17, op | 0x00, type)
2780 /* lfd lfdu lfdux lfdx */
2781 GEN_LDFS(fd
, 0x12, PPC_FLOAT
);
2782 /* lfs lfsu lfsux lfsx */
2783 GEN_LDFS(fs
, 0x10, PPC_FLOAT
);
2785 /*** Floating-point store ***/
2786 #define GEN_STF(width, opc, type) \
2787 GEN_HANDLER(st##width, opc, 0xFF, 0xFF, 0x00000000, type) \
2789 if (unlikely(!ctx->fpu_enabled)) { \
2790 GEN_EXCP_NO_FP(ctx); \
2793 gen_addr_imm_index(ctx, 0); \
2794 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
2795 op_ldst(st##width); \
2798 #define GEN_STUF(width, opc, type) \
2799 GEN_HANDLER(st##width##u, opc, 0xFF, 0xFF, 0x00000000, type) \
2801 if (unlikely(!ctx->fpu_enabled)) { \
2802 GEN_EXCP_NO_FP(ctx); \
2805 if (unlikely(rA(ctx->opcode) == 0)) { \
2806 GEN_EXCP_INVAL(ctx); \
2809 gen_addr_imm_index(ctx, 0); \
2810 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
2811 op_ldst(st##width); \
2812 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
2815 #define GEN_STUXF(width, opc, type) \
2816 GEN_HANDLER(st##width##ux, 0x1F, 0x17, opc, 0x00000001, type) \
2818 if (unlikely(!ctx->fpu_enabled)) { \
2819 GEN_EXCP_NO_FP(ctx); \
2822 if (unlikely(rA(ctx->opcode) == 0)) { \
2823 GEN_EXCP_INVAL(ctx); \
2826 gen_addr_reg_index(ctx); \
2827 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
2828 op_ldst(st##width); \
2829 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_T[0]); \
2832 #define GEN_STXF(width, opc2, opc3, type) \
2833 GEN_HANDLER(st##width##x, 0x1F, opc2, opc3, 0x00000001, type) \
2835 if (unlikely(!ctx->fpu_enabled)) { \
2836 GEN_EXCP_NO_FP(ctx); \
2839 gen_addr_reg_index(ctx); \
2840 tcg_gen_mov_i64(cpu_FT[0], cpu_fpr[rS(ctx->opcode)]); \
2841 op_ldst(st##width); \
2844 #define GEN_STFS(width, op, type) \
2845 OP_ST_TABLE(width); \
2846 GEN_STF(width, op | 0x20, type); \
2847 GEN_STUF(width, op | 0x21, type); \
2848 GEN_STUXF(width, op | 0x01, type); \
2849 GEN_STXF(width, 0x17, op | 0x00, type)
2851 /* stfd stfdu stfdux stfdx */
2852 GEN_STFS(fd
, 0x16, PPC_FLOAT
);
2853 /* stfs stfsu stfsux stfsx */
2854 GEN_STFS(fs
, 0x14, PPC_FLOAT
);
2859 GEN_STXF(fiw
, 0x17, 0x1E, PPC_FLOAT_STFIWX
);
2862 static always_inline
void gen_goto_tb (DisasContext
*ctx
, int n
,
2865 TranslationBlock
*tb
;
2867 if ((tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
) &&
2868 likely(!ctx
->singlestep_enabled
)) {
2870 tcg_gen_movi_tl(cpu_T
[1], dest
);
2871 #if defined(TARGET_PPC64)
2877 tcg_gen_exit_tb((long)tb
+ n
);
2879 tcg_gen_movi_tl(cpu_T
[1], dest
);
2880 #if defined(TARGET_PPC64)
2886 if (unlikely(ctx
->singlestep_enabled
)) {
2887 if ((ctx
->singlestep_enabled
&
2888 (CPU_BRANCH_STEP
| CPU_SINGLE_STEP
)) &&
2889 ctx
->exception
== POWERPC_EXCP_BRANCH
) {
2890 target_ulong tmp
= ctx
->nip
;
2892 GEN_EXCP(ctx
, POWERPC_EXCP_TRACE
, 0);
2895 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
2896 gen_update_nip(ctx
, dest
);
2904 static always_inline
void gen_setlr (DisasContext
*ctx
, target_ulong nip
)
2906 #if defined(TARGET_PPC64)
2907 if (ctx
->sf_mode
!= 0 && (nip
>> 32))
2908 gen_op_setlr_64(ctx
->nip
>> 32, ctx
->nip
);
2911 gen_op_setlr(ctx
->nip
);
2915 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
2917 target_ulong li
, target
;
2919 ctx
->exception
= POWERPC_EXCP_BRANCH
;
2920 /* sign extend LI */
2921 #if defined(TARGET_PPC64)
2923 li
= ((int64_t)LI(ctx
->opcode
) << 38) >> 38;
2926 li
= ((int32_t)LI(ctx
->opcode
) << 6) >> 6;
2927 if (likely(AA(ctx
->opcode
) == 0))
2928 target
= ctx
->nip
+ li
- 4;
2931 #if defined(TARGET_PPC64)
2933 target
= (uint32_t)target
;
2935 if (LK(ctx
->opcode
))
2936 gen_setlr(ctx
, ctx
->nip
);
2937 gen_goto_tb(ctx
, 0, target
);
2944 static always_inline
void gen_bcond (DisasContext
*ctx
, int type
)
2946 target_ulong target
= 0;
2948 uint32_t bo
= BO(ctx
->opcode
);
2949 uint32_t bi
= BI(ctx
->opcode
);
2952 ctx
->exception
= POWERPC_EXCP_BRANCH
;
2953 if ((bo
& 0x4) == 0)
2957 li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
2958 if (likely(AA(ctx
->opcode
) == 0)) {
2959 target
= ctx
->nip
+ li
- 4;
2963 #if defined(TARGET_PPC64)
2965 target
= (uint32_t)target
;
2969 gen_op_movl_T1_ctr();
2973 gen_op_movl_T1_lr();
2976 if (LK(ctx
->opcode
))
2977 gen_setlr(ctx
, ctx
->nip
);
2979 /* No CR condition */
2982 #if defined(TARGET_PPC64)
2984 gen_op_test_ctr_64();
2990 #if defined(TARGET_PPC64)
2992 gen_op_test_ctrz_64();
3000 if (type
== BCOND_IM
) {
3001 gen_goto_tb(ctx
, 0, target
);
3004 #if defined(TARGET_PPC64)
3015 mask
= 1 << (3 - (bi
& 0x03));
3016 gen_op_load_crf_T0(bi
>> 2);
3020 #if defined(TARGET_PPC64)
3022 gen_op_test_ctr_true_64(mask
);
3025 gen_op_test_ctr_true(mask
);
3028 #if defined(TARGET_PPC64)
3030 gen_op_test_ctrz_true_64(mask
);
3033 gen_op_test_ctrz_true(mask
);
3038 gen_op_test_true(mask
);
3044 #if defined(TARGET_PPC64)
3046 gen_op_test_ctr_false_64(mask
);
3049 gen_op_test_ctr_false(mask
);
3052 #if defined(TARGET_PPC64)
3054 gen_op_test_ctrz_false_64(mask
);
3057 gen_op_test_ctrz_false(mask
);
3062 gen_op_test_false(mask
);
3067 if (type
== BCOND_IM
) {
3068 int l1
= gen_new_label();
3070 gen_goto_tb(ctx
, 0, target
);
3072 gen_goto_tb(ctx
, 1, ctx
->nip
);
3074 #if defined(TARGET_PPC64)
3076 gen_op_btest_T1_64(ctx
->nip
>> 32, ctx
->nip
);
3079 gen_op_btest_T1(ctx
->nip
);
3081 if (ctx
->singlestep_enabled
& GDBSTUB_SINGLE_STEP
) {
3082 gen_update_nip(ctx
, ctx
->nip
);
3089 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
3091 gen_bcond(ctx
, BCOND_IM
);
3094 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
)
3096 gen_bcond(ctx
, BCOND_CTR
);
3099 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
)
3101 gen_bcond(ctx
, BCOND_LR
);
3104 /*** Condition register logical ***/
3105 #define GEN_CRLOGIC(op, opc) \
3106 GEN_HANDLER(cr##op, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) \
3110 gen_op_load_crf_T0(crbA(ctx->opcode) >> 2); \
3111 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
3113 gen_op_srli_T0(sh); \
3115 gen_op_sli_T0(-sh); \
3116 gen_op_load_crf_T1(crbB(ctx->opcode) >> 2); \
3117 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
3119 gen_op_srli_T1(sh); \
3121 gen_op_sli_T1(-sh); \
3123 bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \
3124 gen_op_andi_T0(bitmask); \
3125 gen_op_load_crf_T1(crbD(ctx->opcode) >> 2); \
3126 gen_op_andi_T1(~bitmask); \
3128 gen_op_store_T0_crf(crbD(ctx->opcode) >> 2); \
3132 GEN_CRLOGIC(and, 0x08);
3134 GEN_CRLOGIC(andc
, 0x04);
3136 GEN_CRLOGIC(eqv
, 0x09);
3138 GEN_CRLOGIC(nand
, 0x07);
3140 GEN_CRLOGIC(nor
, 0x01);
3142 GEN_CRLOGIC(or, 0x0E);
3144 GEN_CRLOGIC(orc
, 0x0D);
3146 GEN_CRLOGIC(xor, 0x06);
3148 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
)
3150 gen_op_load_crf_T0(crfS(ctx
->opcode
));
3151 gen_op_store_T0_crf(crfD(ctx
->opcode
));
3154 /*** System linkage ***/
3155 /* rfi (supervisor only) */
3156 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
)
3158 #if defined(CONFIG_USER_ONLY)
3159 GEN_EXCP_PRIVOPC(ctx
);
3161 /* Restore CPU state */
3162 if (unlikely(!ctx
->supervisor
)) {
3163 GEN_EXCP_PRIVOPC(ctx
);
3171 #if defined(TARGET_PPC64)
3172 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
)
3174 #if defined(CONFIG_USER_ONLY)
3175 GEN_EXCP_PRIVOPC(ctx
);
3177 /* Restore CPU state */
3178 if (unlikely(!ctx
->supervisor
)) {
3179 GEN_EXCP_PRIVOPC(ctx
);
3187 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
)
3189 #if defined(CONFIG_USER_ONLY)
3190 GEN_EXCP_PRIVOPC(ctx
);
3192 /* Restore CPU state */
3193 if (unlikely(ctx
->supervisor
<= 1)) {
3194 GEN_EXCP_PRIVOPC(ctx
);
3204 #if defined(CONFIG_USER_ONLY)
3205 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
3207 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
3209 GEN_HANDLER(sc
, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW
)
3213 lev
= (ctx
->opcode
>> 5) & 0x7F;
3214 GEN_EXCP(ctx
, POWERPC_SYSCALL
, lev
);
3219 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
)
3221 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
3222 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
3223 /* Update the nip since this might generate a trap exception */
3224 gen_update_nip(ctx
, ctx
->nip
);
3225 gen_op_tw(TO(ctx
->opcode
));
3229 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
)
3231 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
3232 tcg_gen_movi_tl(cpu_T
[1], SIMM(ctx
->opcode
));
3233 /* Update the nip since this might generate a trap exception */
3234 gen_update_nip(ctx
, ctx
->nip
);
3235 gen_op_tw(TO(ctx
->opcode
));
3238 #if defined(TARGET_PPC64)
3240 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
)
3242 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
3243 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
3244 /* Update the nip since this might generate a trap exception */
3245 gen_update_nip(ctx
, ctx
->nip
);
3246 gen_op_td(TO(ctx
->opcode
));
3250 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
)
3252 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
3253 tcg_gen_movi_tl(cpu_T
[1], SIMM(ctx
->opcode
));
3254 /* Update the nip since this might generate a trap exception */
3255 gen_update_nip(ctx
, ctx
->nip
);
3256 gen_op_td(TO(ctx
->opcode
));
3260 /*** Processor control ***/
3262 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
)
3264 gen_op_load_xer_cr();
3265 gen_op_store_T0_crf(crfD(ctx
->opcode
));
3266 gen_op_clear_xer_ov();
3267 gen_op_clear_xer_ca();
3271 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
)
3275 if (likely(ctx
->opcode
& 0x00100000)) {
3276 crm
= CRM(ctx
->opcode
);
3277 if (likely((crm
^ (crm
- 1)) == 0)) {
3279 gen_op_load_cro(7 - crn
);
3284 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
3288 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
)
3290 #if defined(CONFIG_USER_ONLY)
3291 GEN_EXCP_PRIVREG(ctx
);
3293 if (unlikely(!ctx
->supervisor
)) {
3294 GEN_EXCP_PRIVREG(ctx
);
3298 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
3303 #define SPR_NOACCESS ((void *)(-1UL))
3305 static void spr_noaccess (void *opaque
, int sprn
)
3307 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
3308 printf("ERROR: try to access SPR %d !\n", sprn
);
3310 #define SPR_NOACCESS (&spr_noaccess)
3314 static always_inline
void gen_op_mfspr (DisasContext
*ctx
)
3316 void (*read_cb
)(void *opaque
, int sprn
);
3317 uint32_t sprn
= SPR(ctx
->opcode
);
3319 #if !defined(CONFIG_USER_ONLY)
3320 if (ctx
->supervisor
== 2)
3321 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
3322 else if (ctx
->supervisor
)
3323 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
3326 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
3327 if (likely(read_cb
!= NULL
)) {
3328 if (likely(read_cb
!= SPR_NOACCESS
)) {
3329 (*read_cb
)(ctx
, sprn
);
3330 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
3332 /* Privilege exception */
3333 /* This is a hack to avoid warnings when running Linux:
3334 * this OS breaks the PowerPC virtualisation model,
3335 * allowing userland application to read the PVR
3337 if (sprn
!= SPR_PVR
) {
3338 if (loglevel
!= 0) {
3339 fprintf(logfile
, "Trying to read privileged spr %d %03x at "
3340 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3342 printf("Trying to read privileged spr %d %03x at " ADDRX
"\n",
3343 sprn
, sprn
, ctx
->nip
);
3345 GEN_EXCP_PRIVREG(ctx
);
3349 if (loglevel
!= 0) {
3350 fprintf(logfile
, "Trying to read invalid spr %d %03x at "
3351 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3353 printf("Trying to read invalid spr %d %03x at " ADDRX
"\n",
3354 sprn
, sprn
, ctx
->nip
);
3355 GEN_EXCP(ctx
, POWERPC_EXCP_PROGRAM
,
3356 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_SPR
);
3360 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
)
3366 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
)
3372 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
)
3376 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
3377 crm
= CRM(ctx
->opcode
);
3378 if (likely((ctx
->opcode
& 0x00100000) || (crm
^ (crm
- 1)) == 0)) {
3380 gen_op_srli_T0(crn
* 4);
3381 gen_op_andi_T0(0xF);
3382 gen_op_store_cro(7 - crn
);
3384 gen_op_store_cr(crm
);
3389 #if defined(TARGET_PPC64)
3390 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
)
3392 #if defined(CONFIG_USER_ONLY)
3393 GEN_EXCP_PRIVREG(ctx
);
3395 if (unlikely(!ctx
->supervisor
)) {
3396 GEN_EXCP_PRIVREG(ctx
);
3399 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
3400 if (ctx
->opcode
& 0x00010000) {
3401 /* Special form that does not need any synchronisation */
3402 gen_op_update_riee();
3404 /* XXX: we need to update nip before the store
3405 * if we enter power saving mode, we will exit the loop
3406 * directly from ppc_store_msr
3408 gen_update_nip(ctx
, ctx
->nip
);
3410 /* Must stop the translation as machine state (may have) changed */
3411 /* Note that mtmsr is not always defined as context-synchronizing */
3412 ctx
->exception
= POWERPC_EXCP_STOP
;
3418 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC
)
3420 #if defined(CONFIG_USER_ONLY)
3421 GEN_EXCP_PRIVREG(ctx
);
3423 if (unlikely(!ctx
->supervisor
)) {
3424 GEN_EXCP_PRIVREG(ctx
);
3427 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
3428 if (ctx
->opcode
& 0x00010000) {
3429 /* Special form that does not need any synchronisation */
3430 gen_op_update_riee();
3432 /* XXX: we need to update nip before the store
3433 * if we enter power saving mode, we will exit the loop
3434 * directly from ppc_store_msr
3436 gen_update_nip(ctx
, ctx
->nip
);
3437 #if defined(TARGET_PPC64)
3439 gen_op_store_msr_32();
3443 /* Must stop the translation as machine state (may have) changed */
3444 /* Note that mtmsrd is not always defined as context-synchronizing */
3445 ctx
->exception
= POWERPC_EXCP_STOP
;
3451 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC
)
3453 void (*write_cb
)(void *opaque
, int sprn
);
3454 uint32_t sprn
= SPR(ctx
->opcode
);
3456 #if !defined(CONFIG_USER_ONLY)
3457 if (ctx
->supervisor
== 2)
3458 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
3459 else if (ctx
->supervisor
)
3460 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
3463 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
3464 if (likely(write_cb
!= NULL
)) {
3465 if (likely(write_cb
!= SPR_NOACCESS
)) {
3466 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
3467 (*write_cb
)(ctx
, sprn
);
3469 /* Privilege exception */
3470 if (loglevel
!= 0) {
3471 fprintf(logfile
, "Trying to write privileged spr %d %03x at "
3472 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3474 printf("Trying to write privileged spr %d %03x at " ADDRX
"\n",
3475 sprn
, sprn
, ctx
->nip
);
3476 GEN_EXCP_PRIVREG(ctx
);
3480 if (loglevel
!= 0) {
3481 fprintf(logfile
, "Trying to write invalid spr %d %03x at "
3482 ADDRX
"\n", sprn
, sprn
, ctx
->nip
);
3484 printf("Trying to write invalid spr %d %03x at " ADDRX
"\n",
3485 sprn
, sprn
, ctx
->nip
);
3486 GEN_EXCP(ctx
, POWERPC_EXCP_PROGRAM
,
3487 POWERPC_EXCP_INVAL
| POWERPC_EXCP_INVAL_SPR
);
3491 /*** Cache management ***/
3493 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
)
3495 /* XXX: specification says this is treated as a load by the MMU */
3496 gen_addr_reg_index(ctx
);
3500 /* dcbi (Supervisor only) */
3501 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
)
3503 #if defined(CONFIG_USER_ONLY)
3504 GEN_EXCP_PRIVOPC(ctx
);
3506 if (unlikely(!ctx
->supervisor
)) {
3507 GEN_EXCP_PRIVOPC(ctx
);
3510 gen_addr_reg_index(ctx
);
3511 /* XXX: specification says this should be treated as a store by the MMU */
3518 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
)
3520 /* XXX: specification say this is treated as a load by the MMU */
3521 gen_addr_reg_index(ctx
);
3526 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE
)
3528 /* interpreted as no-op */
3529 /* XXX: specification say this is treated as a load by the MMU
3530 * but does not generate any exception
3535 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE
)
3537 /* interpreted as no-op */
3538 /* XXX: specification say this is treated as a load by the MMU
3539 * but does not generate any exception
3544 #define op_dcbz(n) (*gen_op_dcbz[n][ctx->mem_idx])()
3545 static GenOpFunc
*gen_op_dcbz
[4][NB_MEM_FUNCS
] = {
3546 /* 32 bytes cache line size */
3548 #define gen_op_dcbz_l32_le_raw gen_op_dcbz_l32_raw
3549 #define gen_op_dcbz_l32_le_user gen_op_dcbz_l32_user
3550 #define gen_op_dcbz_l32_le_kernel gen_op_dcbz_l32_kernel
3551 #define gen_op_dcbz_l32_le_hypv gen_op_dcbz_l32_hypv
3552 #define gen_op_dcbz_l32_le_64_raw gen_op_dcbz_l32_64_raw
3553 #define gen_op_dcbz_l32_le_64_user gen_op_dcbz_l32_64_user
3554 #define gen_op_dcbz_l32_le_64_kernel gen_op_dcbz_l32_64_kernel
3555 #define gen_op_dcbz_l32_le_64_hypv gen_op_dcbz_l32_64_hypv
3556 GEN_MEM_FUNCS(dcbz_l32
),
3558 /* 64 bytes cache line size */
3560 #define gen_op_dcbz_l64_le_raw gen_op_dcbz_l64_raw
3561 #define gen_op_dcbz_l64_le_user gen_op_dcbz_l64_user
3562 #define gen_op_dcbz_l64_le_kernel gen_op_dcbz_l64_kernel
3563 #define gen_op_dcbz_l64_le_hypv gen_op_dcbz_l64_hypv
3564 #define gen_op_dcbz_l64_le_64_raw gen_op_dcbz_l64_64_raw
3565 #define gen_op_dcbz_l64_le_64_user gen_op_dcbz_l64_64_user
3566 #define gen_op_dcbz_l64_le_64_kernel gen_op_dcbz_l64_64_kernel
3567 #define gen_op_dcbz_l64_le_64_hypv gen_op_dcbz_l64_64_hypv
3568 GEN_MEM_FUNCS(dcbz_l64
),
3570 /* 128 bytes cache line size */
3572 #define gen_op_dcbz_l128_le_raw gen_op_dcbz_l128_raw
3573 #define gen_op_dcbz_l128_le_user gen_op_dcbz_l128_user
3574 #define gen_op_dcbz_l128_le_kernel gen_op_dcbz_l128_kernel
3575 #define gen_op_dcbz_l128_le_hypv gen_op_dcbz_l128_hypv
3576 #define gen_op_dcbz_l128_le_64_raw gen_op_dcbz_l128_64_raw
3577 #define gen_op_dcbz_l128_le_64_user gen_op_dcbz_l128_64_user
3578 #define gen_op_dcbz_l128_le_64_kernel gen_op_dcbz_l128_64_kernel
3579 #define gen_op_dcbz_l128_le_64_hypv gen_op_dcbz_l128_64_hypv
3580 GEN_MEM_FUNCS(dcbz_l128
),
3582 /* tunable cache line size */
3584 #define gen_op_dcbz_le_raw gen_op_dcbz_raw
3585 #define gen_op_dcbz_le_user gen_op_dcbz_user
3586 #define gen_op_dcbz_le_kernel gen_op_dcbz_kernel
3587 #define gen_op_dcbz_le_hypv gen_op_dcbz_hypv
3588 #define gen_op_dcbz_le_64_raw gen_op_dcbz_64_raw
3589 #define gen_op_dcbz_le_64_user gen_op_dcbz_64_user
3590 #define gen_op_dcbz_le_64_kernel gen_op_dcbz_64_kernel
3591 #define gen_op_dcbz_le_64_hypv gen_op_dcbz_64_hypv
3592 GEN_MEM_FUNCS(dcbz
),
3596 static always_inline
void handler_dcbz (DisasContext
*ctx
,
3597 int dcache_line_size
)
3601 switch (dcache_line_size
) {
3618 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03E00001, PPC_CACHE_DCBZ
)
3620 gen_addr_reg_index(ctx
);
3621 handler_dcbz(ctx
, ctx
->dcache_line_size
);
3622 gen_op_check_reservation();
3625 GEN_HANDLER2(dcbz_970
, "dcbz", 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZT
)
3627 gen_addr_reg_index(ctx
);
3628 if (ctx
->opcode
& 0x00200000)
3629 handler_dcbz(ctx
, ctx
->dcache_line_size
);
3631 handler_dcbz(ctx
, -1);
3632 gen_op_check_reservation();
3636 #define op_icbi() (*gen_op_icbi[ctx->mem_idx])()
3637 #define gen_op_icbi_le_raw gen_op_icbi_raw
3638 #define gen_op_icbi_le_user gen_op_icbi_user
3639 #define gen_op_icbi_le_kernel gen_op_icbi_kernel
3640 #define gen_op_icbi_le_hypv gen_op_icbi_hypv
3641 #define gen_op_icbi_le_64_raw gen_op_icbi_64_raw
3642 #define gen_op_icbi_le_64_user gen_op_icbi_64_user
3643 #define gen_op_icbi_le_64_kernel gen_op_icbi_64_kernel
3644 #define gen_op_icbi_le_64_hypv gen_op_icbi_64_hypv
3645 static GenOpFunc
*gen_op_icbi
[NB_MEM_FUNCS
] = {
3646 GEN_MEM_FUNCS(icbi
),
3649 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
)
3651 /* NIP cannot be restored if the memory exception comes from an helper */
3652 gen_update_nip(ctx
, ctx
->nip
- 4);
3653 gen_addr_reg_index(ctx
);
3659 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
)
3661 /* interpreted as no-op */
3662 /* XXX: specification say this is treated as a store by the MMU
3663 * but does not generate any exception
3667 /*** Segment register manipulation ***/
3668 /* Supervisor only: */
3670 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
)
3672 #if defined(CONFIG_USER_ONLY)
3673 GEN_EXCP_PRIVREG(ctx
);
3675 if (unlikely(!ctx
->supervisor
)) {
3676 GEN_EXCP_PRIVREG(ctx
);
3679 tcg_gen_movi_tl(cpu_T
[1], SR(ctx
->opcode
));
3681 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
3686 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
)
3688 #if defined(CONFIG_USER_ONLY)
3689 GEN_EXCP_PRIVREG(ctx
);
3691 if (unlikely(!ctx
->supervisor
)) {
3692 GEN_EXCP_PRIVREG(ctx
);
3695 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
3698 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
3703 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
)
3705 #if defined(CONFIG_USER_ONLY)
3706 GEN_EXCP_PRIVREG(ctx
);
3708 if (unlikely(!ctx
->supervisor
)) {
3709 GEN_EXCP_PRIVREG(ctx
);
3712 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
3713 tcg_gen_movi_tl(cpu_T
[1], SR(ctx
->opcode
));
3719 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
)
3721 #if defined(CONFIG_USER_ONLY)
3722 GEN_EXCP_PRIVREG(ctx
);
3724 if (unlikely(!ctx
->supervisor
)) {
3725 GEN_EXCP_PRIVREG(ctx
);
3728 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
3729 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
3735 #if defined(TARGET_PPC64)
3736 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
3738 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
)
3740 #if defined(CONFIG_USER_ONLY)
3741 GEN_EXCP_PRIVREG(ctx
);
3743 if (unlikely(!ctx
->supervisor
)) {
3744 GEN_EXCP_PRIVREG(ctx
);
3747 tcg_gen_movi_tl(cpu_T
[1], SR(ctx
->opcode
));
3749 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
3754 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
3757 #if defined(CONFIG_USER_ONLY)
3758 GEN_EXCP_PRIVREG(ctx
);
3760 if (unlikely(!ctx
->supervisor
)) {
3761 GEN_EXCP_PRIVREG(ctx
);
3764 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
3767 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
3772 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
)
3774 #if defined(CONFIG_USER_ONLY)
3775 GEN_EXCP_PRIVREG(ctx
);
3777 if (unlikely(!ctx
->supervisor
)) {
3778 GEN_EXCP_PRIVREG(ctx
);
3781 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
3782 tcg_gen_movi_tl(cpu_T
[1], SR(ctx
->opcode
));
3788 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
3791 #if defined(CONFIG_USER_ONLY)
3792 GEN_EXCP_PRIVREG(ctx
);
3794 if (unlikely(!ctx
->supervisor
)) {
3795 GEN_EXCP_PRIVREG(ctx
);
3798 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
3799 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
3804 #endif /* defined(TARGET_PPC64) */
3806 /*** Lookaside buffer management ***/
3807 /* Optional & supervisor only: */
3809 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
)
3811 #if defined(CONFIG_USER_ONLY)
3812 GEN_EXCP_PRIVOPC(ctx
);
3814 if (unlikely(!ctx
->supervisor
)) {
3815 GEN_EXCP_PRIVOPC(ctx
);
3823 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE
)
3825 #if defined(CONFIG_USER_ONLY)
3826 GEN_EXCP_PRIVOPC(ctx
);
3828 if (unlikely(!ctx
->supervisor
)) {
3829 GEN_EXCP_PRIVOPC(ctx
);
3832 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rB(ctx
->opcode
)]);
3833 #if defined(TARGET_PPC64)
3843 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
)
3845 #if defined(CONFIG_USER_ONLY)
3846 GEN_EXCP_PRIVOPC(ctx
);
3848 if (unlikely(!ctx
->supervisor
)) {
3849 GEN_EXCP_PRIVOPC(ctx
);
3852 /* This has no effect: it should ensure that all previous
3853 * tlbie have completed
3859 #if defined(TARGET_PPC64)
3861 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI
)
3863 #if defined(CONFIG_USER_ONLY)
3864 GEN_EXCP_PRIVOPC(ctx
);
3866 if (unlikely(!ctx
->supervisor
)) {
3867 GEN_EXCP_PRIVOPC(ctx
);
3875 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
)
3877 #if defined(CONFIG_USER_ONLY)
3878 GEN_EXCP_PRIVOPC(ctx
);
3880 if (unlikely(!ctx
->supervisor
)) {
3881 GEN_EXCP_PRIVOPC(ctx
);
3884 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rB(ctx
->opcode
)]);
3890 /*** External control ***/
3892 #define op_eciwx() (*gen_op_eciwx[ctx->mem_idx])()
3893 #define op_ecowx() (*gen_op_ecowx[ctx->mem_idx])()
3894 static GenOpFunc
*gen_op_eciwx
[NB_MEM_FUNCS
] = {
3895 GEN_MEM_FUNCS(eciwx
),
3897 static GenOpFunc
*gen_op_ecowx
[NB_MEM_FUNCS
] = {
3898 GEN_MEM_FUNCS(ecowx
),
3902 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
)
3904 /* Should check EAR[E] & alignment ! */
3905 gen_addr_reg_index(ctx
);
3907 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
3911 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
)
3913 /* Should check EAR[E] & alignment ! */
3914 gen_addr_reg_index(ctx
);
3915 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
3919 /* PowerPC 601 specific instructions */
3921 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
)
3923 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
3925 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
3926 if (unlikely(Rc(ctx
->opcode
) != 0))
3931 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
)
3933 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
3934 gen_op_POWER_abso();
3935 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
3936 if (unlikely(Rc(ctx
->opcode
) != 0))
3941 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
)
3943 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
3944 gen_op_POWER_clcs();
3945 /* Rc=1 sets CR0 to an undefined state */
3946 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
3950 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
)
3952 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
3953 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
3955 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
3956 if (unlikely(Rc(ctx
->opcode
) != 0))
3961 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
)
3963 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
3964 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
3965 gen_op_POWER_divo();
3966 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
3967 if (unlikely(Rc(ctx
->opcode
) != 0))
3972 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
)
3974 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
3975 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
3976 gen_op_POWER_divs();
3977 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
3978 if (unlikely(Rc(ctx
->opcode
) != 0))
3982 /* divso - divso. */
3983 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
)
3985 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
3986 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
3987 gen_op_POWER_divso();
3988 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
3989 if (unlikely(Rc(ctx
->opcode
) != 0))
3994 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
)
3996 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
3997 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
3999 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4000 if (unlikely(Rc(ctx
->opcode
) != 0))
4005 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
)
4007 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4008 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4009 gen_op_POWER_dozo();
4010 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4011 if (unlikely(Rc(ctx
->opcode
) != 0))
4016 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
)
4018 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4019 tcg_gen_movi_tl(cpu_T
[1], SIMM(ctx
->opcode
));
4021 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4024 /* As lscbx load from memory byte after byte, it's always endian safe.
4025 * Original POWER is 32 bits only, define 64 bits ops as 32 bits ones
4027 #define op_POWER_lscbx(start, ra, rb) \
4028 (*gen_op_POWER_lscbx[ctx->mem_idx])(start, ra, rb)
4029 #define gen_op_POWER_lscbx_64_raw gen_op_POWER_lscbx_raw
4030 #define gen_op_POWER_lscbx_64_user gen_op_POWER_lscbx_user
4031 #define gen_op_POWER_lscbx_64_kernel gen_op_POWER_lscbx_kernel
4032 #define gen_op_POWER_lscbx_64_hypv gen_op_POWER_lscbx_hypv
4033 #define gen_op_POWER_lscbx_le_raw gen_op_POWER_lscbx_raw
4034 #define gen_op_POWER_lscbx_le_user gen_op_POWER_lscbx_user
4035 #define gen_op_POWER_lscbx_le_kernel gen_op_POWER_lscbx_kernel
4036 #define gen_op_POWER_lscbx_le_hypv gen_op_POWER_lscbx_hypv
4037 #define gen_op_POWER_lscbx_le_64_raw gen_op_POWER_lscbx_raw
4038 #define gen_op_POWER_lscbx_le_64_user gen_op_POWER_lscbx_user
4039 #define gen_op_POWER_lscbx_le_64_kernel gen_op_POWER_lscbx_kernel
4040 #define gen_op_POWER_lscbx_le_64_hypv gen_op_POWER_lscbx_hypv
4041 static GenOpFunc3
*gen_op_POWER_lscbx
[NB_MEM_FUNCS
] = {
4042 GEN_MEM_FUNCS(POWER_lscbx
),
4045 /* lscbx - lscbx. */
4046 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
)
4048 int ra
= rA(ctx
->opcode
);
4049 int rb
= rB(ctx
->opcode
);
4051 gen_addr_reg_index(ctx
);
4055 /* NIP cannot be restored if the memory exception comes from an helper */
4056 gen_update_nip(ctx
, ctx
->nip
- 4);
4057 gen_op_load_xer_bc();
4058 gen_op_load_xer_cmp();
4059 op_POWER_lscbx(rD(ctx
->opcode
), ra
, rb
);
4060 gen_op_store_xer_bc();
4061 if (unlikely(Rc(ctx
->opcode
) != 0))
4065 /* maskg - maskg. */
4066 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
)
4068 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4069 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4070 gen_op_POWER_maskg();
4071 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4072 if (unlikely(Rc(ctx
->opcode
) != 0))
4076 /* maskir - maskir. */
4077 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
)
4079 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4080 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
4081 tcg_gen_mov_tl(cpu_T
[2], cpu_gpr
[rB(ctx
->opcode
)]);
4082 gen_op_POWER_maskir();
4083 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4084 if (unlikely(Rc(ctx
->opcode
) != 0))
4089 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
)
4091 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4092 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4094 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4095 if (unlikely(Rc(ctx
->opcode
) != 0))
4100 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
)
4102 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4103 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4104 gen_op_POWER_mulo();
4105 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4106 if (unlikely(Rc(ctx
->opcode
) != 0))
4111 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
)
4113 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4114 gen_op_POWER_nabs();
4115 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4116 if (unlikely(Rc(ctx
->opcode
) != 0))
4120 /* nabso - nabso. */
4121 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
)
4123 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4124 gen_op_POWER_nabso();
4125 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4126 if (unlikely(Rc(ctx
->opcode
) != 0))
4131 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
)
4135 mb
= MB(ctx
->opcode
);
4136 me
= ME(ctx
->opcode
);
4137 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4138 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rA(ctx
->opcode
)]);
4139 tcg_gen_mov_tl(cpu_T
[2], cpu_gpr
[rB(ctx
->opcode
)]);
4140 gen_op_POWER_rlmi(MASK(mb
, me
), ~MASK(mb
, me
));
4141 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4142 if (unlikely(Rc(ctx
->opcode
) != 0))
4147 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
)
4149 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4150 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rA(ctx
->opcode
)]);
4151 tcg_gen_mov_tl(cpu_T
[2], cpu_gpr
[rB(ctx
->opcode
)]);
4152 gen_op_POWER_rrib();
4153 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4154 if (unlikely(Rc(ctx
->opcode
) != 0))
4159 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
)
4161 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4162 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4164 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4165 if (unlikely(Rc(ctx
->opcode
) != 0))
4170 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
)
4172 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4173 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4174 gen_op_POWER_sleq();
4175 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4176 if (unlikely(Rc(ctx
->opcode
) != 0))
4181 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
)
4183 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4184 tcg_gen_movi_tl(cpu_T
[1], SH(ctx
->opcode
));
4186 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4187 if (unlikely(Rc(ctx
->opcode
) != 0))
4191 /* slliq - slliq. */
4192 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
)
4194 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4195 tcg_gen_movi_tl(cpu_T
[1], SH(ctx
->opcode
));
4196 gen_op_POWER_sleq();
4197 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4198 if (unlikely(Rc(ctx
->opcode
) != 0))
4203 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
)
4205 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4206 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4207 gen_op_POWER_sllq();
4208 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4209 if (unlikely(Rc(ctx
->opcode
) != 0))
4214 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
)
4216 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4217 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4219 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4220 if (unlikely(Rc(ctx
->opcode
) != 0))
4224 /* sraiq - sraiq. */
4225 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
)
4227 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4228 tcg_gen_movi_tl(cpu_T
[1], SH(ctx
->opcode
));
4229 gen_op_POWER_sraq();
4230 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4231 if (unlikely(Rc(ctx
->opcode
) != 0))
4236 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
)
4238 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4239 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4240 gen_op_POWER_sraq();
4241 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4242 if (unlikely(Rc(ctx
->opcode
) != 0))
4247 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
)
4249 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4250 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4252 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4253 if (unlikely(Rc(ctx
->opcode
) != 0))
4258 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
)
4260 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4261 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4262 gen_op_POWER_srea();
4263 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4264 if (unlikely(Rc(ctx
->opcode
) != 0))
4269 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
)
4271 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4272 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4273 gen_op_POWER_sreq();
4274 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4275 if (unlikely(Rc(ctx
->opcode
) != 0))
4280 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
)
4282 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4283 tcg_gen_movi_tl(cpu_T
[1], SH(ctx
->opcode
));
4285 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4286 if (unlikely(Rc(ctx
->opcode
) != 0))
4291 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
)
4293 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4294 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4295 tcg_gen_movi_tl(cpu_T
[1], SH(ctx
->opcode
));
4296 gen_op_POWER_srlq();
4297 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4298 if (unlikely(Rc(ctx
->opcode
) != 0))
4303 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
)
4305 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4306 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4307 gen_op_POWER_srlq();
4308 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4309 if (unlikely(Rc(ctx
->opcode
) != 0))
4314 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
)
4316 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
4317 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
4319 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
4320 if (unlikely(Rc(ctx
->opcode
) != 0))
4324 /* PowerPC 602 specific instructions */
4326 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
)
4329 GEN_EXCP_INVAL(ctx
);
4333 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
)
4336 GEN_EXCP_INVAL(ctx
);
4340 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
)
4342 #if defined(CONFIG_USER_ONLY)
4343 GEN_EXCP_PRIVOPC(ctx
);
4345 if (unlikely(!ctx
->supervisor
)) {
4346 GEN_EXCP_PRIVOPC(ctx
);
4349 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4351 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4355 /* 602 - 603 - G2 TLB management */
4357 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
)
4359 #if defined(CONFIG_USER_ONLY)
4360 GEN_EXCP_PRIVOPC(ctx
);
4362 if (unlikely(!ctx
->supervisor
)) {
4363 GEN_EXCP_PRIVOPC(ctx
);
4366 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rB(ctx
->opcode
)]);
4372 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
)
4374 #if defined(CONFIG_USER_ONLY)
4375 GEN_EXCP_PRIVOPC(ctx
);
4377 if (unlikely(!ctx
->supervisor
)) {
4378 GEN_EXCP_PRIVOPC(ctx
);
4381 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rB(ctx
->opcode
)]);
4386 /* 74xx TLB management */
4388 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
)
4390 #if defined(CONFIG_USER_ONLY)
4391 GEN_EXCP_PRIVOPC(ctx
);
4393 if (unlikely(!ctx
->supervisor
)) {
4394 GEN_EXCP_PRIVOPC(ctx
);
4397 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rB(ctx
->opcode
)]);
4398 gen_op_74xx_tlbld();
4403 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
)
4405 #if defined(CONFIG_USER_ONLY)
4406 GEN_EXCP_PRIVOPC(ctx
);
4408 if (unlikely(!ctx
->supervisor
)) {
4409 GEN_EXCP_PRIVOPC(ctx
);
4412 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rB(ctx
->opcode
)]);
4413 gen_op_74xx_tlbli();
4417 /* POWER instructions not in PowerPC 601 */
4419 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
)
4421 /* Cache line flush: implemented as no-op */
4425 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
)
4427 /* Cache line invalidate: privileged and treated as no-op */
4428 #if defined(CONFIG_USER_ONLY)
4429 GEN_EXCP_PRIVOPC(ctx
);
4431 if (unlikely(!ctx
->supervisor
)) {
4432 GEN_EXCP_PRIVOPC(ctx
);
4439 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
)
4441 /* Data cache line store: treated as no-op */
4444 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
)
4446 #if defined(CONFIG_USER_ONLY)
4447 GEN_EXCP_PRIVOPC(ctx
);
4449 if (unlikely(!ctx
->supervisor
)) {
4450 GEN_EXCP_PRIVOPC(ctx
);
4453 int ra
= rA(ctx
->opcode
);
4454 int rd
= rD(ctx
->opcode
);
4456 gen_addr_reg_index(ctx
);
4457 gen_op_POWER_mfsri();
4458 tcg_gen_mov_tl(cpu_gpr
[rd
], cpu_T
[0]);
4459 if (ra
!= 0 && ra
!= rd
)
4460 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_T
[1]);
4464 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
)
4466 #if defined(CONFIG_USER_ONLY)
4467 GEN_EXCP_PRIVOPC(ctx
);
4469 if (unlikely(!ctx
->supervisor
)) {
4470 GEN_EXCP_PRIVOPC(ctx
);
4473 gen_addr_reg_index(ctx
);
4475 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4479 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
)
4481 #if defined(CONFIG_USER_ONLY)
4482 GEN_EXCP_PRIVOPC(ctx
);
4484 if (unlikely(!ctx
->supervisor
)) {
4485 GEN_EXCP_PRIVOPC(ctx
);
4488 gen_op_POWER_rfsvc();
4493 /* svc is not implemented for now */
4495 /* POWER2 specific instructions */
4496 /* Quad manipulation (load/store two floats at a time) */
4497 /* Original POWER2 is 32 bits only, define 64 bits ops as 32 bits ones */
4498 #define op_POWER2_lfq() (*gen_op_POWER2_lfq[ctx->mem_idx])()
4499 #define op_POWER2_stfq() (*gen_op_POWER2_stfq[ctx->mem_idx])()
4500 #define gen_op_POWER2_lfq_64_raw gen_op_POWER2_lfq_raw
4501 #define gen_op_POWER2_lfq_64_user gen_op_POWER2_lfq_user
4502 #define gen_op_POWER2_lfq_64_kernel gen_op_POWER2_lfq_kernel
4503 #define gen_op_POWER2_lfq_64_hypv gen_op_POWER2_lfq_hypv
4504 #define gen_op_POWER2_lfq_le_64_raw gen_op_POWER2_lfq_le_raw
4505 #define gen_op_POWER2_lfq_le_64_user gen_op_POWER2_lfq_le_user
4506 #define gen_op_POWER2_lfq_le_64_kernel gen_op_POWER2_lfq_le_kernel
4507 #define gen_op_POWER2_lfq_le_64_hypv gen_op_POWER2_lfq_le_hypv
4508 #define gen_op_POWER2_stfq_64_raw gen_op_POWER2_stfq_raw
4509 #define gen_op_POWER2_stfq_64_user gen_op_POWER2_stfq_user
4510 #define gen_op_POWER2_stfq_64_kernel gen_op_POWER2_stfq_kernel
4511 #define gen_op_POWER2_stfq_64_hypv gen_op_POWER2_stfq_hypv
4512 #define gen_op_POWER2_stfq_le_64_raw gen_op_POWER2_stfq_le_raw
4513 #define gen_op_POWER2_stfq_le_64_user gen_op_POWER2_stfq_le_user
4514 #define gen_op_POWER2_stfq_le_64_kernel gen_op_POWER2_stfq_le_kernel
4515 #define gen_op_POWER2_stfq_le_64_hypv gen_op_POWER2_stfq_le_hypv
4516 static GenOpFunc
*gen_op_POWER2_lfq
[NB_MEM_FUNCS
] = {
4517 GEN_MEM_FUNCS(POWER2_lfq
),
4519 static GenOpFunc
*gen_op_POWER2_stfq
[NB_MEM_FUNCS
] = {
4520 GEN_MEM_FUNCS(POWER2_stfq
),
4524 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
4526 /* NIP cannot be restored if the memory exception comes from an helper */
4527 gen_update_nip(ctx
, ctx
->nip
- 4);
4528 gen_addr_imm_index(ctx
, 0);
4530 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_FT
[0]);
4531 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
) + 1], cpu_FT
[1]);
4535 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
4537 int ra
= rA(ctx
->opcode
);
4539 /* NIP cannot be restored if the memory exception comes from an helper */
4540 gen_update_nip(ctx
, ctx
->nip
- 4);
4541 gen_addr_imm_index(ctx
, 0);
4543 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_FT
[0]);
4544 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
) + 1], cpu_FT
[1]);
4546 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_T
[0]);
4550 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
)
4552 int ra
= rA(ctx
->opcode
);
4554 /* NIP cannot be restored if the memory exception comes from an helper */
4555 gen_update_nip(ctx
, ctx
->nip
- 4);
4556 gen_addr_reg_index(ctx
);
4558 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_FT
[0]);
4559 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
) + 1], cpu_FT
[1]);
4561 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_T
[0]);
4565 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
)
4567 /* NIP cannot be restored if the memory exception comes from an helper */
4568 gen_update_nip(ctx
, ctx
->nip
- 4);
4569 gen_addr_reg_index(ctx
);
4571 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
)], cpu_FT
[0]);
4572 tcg_gen_mov_i64(cpu_fpr
[rD(ctx
->opcode
) + 1], cpu_FT
[1]);
4576 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
4578 /* NIP cannot be restored if the memory exception comes from an helper */
4579 gen_update_nip(ctx
, ctx
->nip
- 4);
4580 gen_addr_imm_index(ctx
, 0);
4581 tcg_gen_mov_i64(cpu_FT
[0], cpu_fpr
[rS(ctx
->opcode
)]);
4582 tcg_gen_mov_i64(cpu_FT
[1], cpu_fpr
[rS(ctx
->opcode
) + 1]);
4587 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
)
4589 int ra
= rA(ctx
->opcode
);
4591 /* NIP cannot be restored if the memory exception comes from an helper */
4592 gen_update_nip(ctx
, ctx
->nip
- 4);
4593 gen_addr_imm_index(ctx
, 0);
4594 tcg_gen_mov_i64(cpu_FT
[0], cpu_fpr
[rS(ctx
->opcode
)]);
4595 tcg_gen_mov_i64(cpu_FT
[1], cpu_fpr
[rS(ctx
->opcode
) + 1]);
4598 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_T
[0]);
4602 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
)
4604 int ra
= rA(ctx
->opcode
);
4606 /* NIP cannot be restored if the memory exception comes from an helper */
4607 gen_update_nip(ctx
, ctx
->nip
- 4);
4608 gen_addr_reg_index(ctx
);
4609 tcg_gen_mov_i64(cpu_FT
[0], cpu_fpr
[rS(ctx
->opcode
)]);
4610 tcg_gen_mov_i64(cpu_FT
[1], cpu_fpr
[rS(ctx
->opcode
) + 1]);
4613 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_T
[0]);
4617 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
)
4619 /* NIP cannot be restored if the memory exception comes from an helper */
4620 gen_update_nip(ctx
, ctx
->nip
- 4);
4621 gen_addr_reg_index(ctx
);
4622 tcg_gen_mov_i64(cpu_FT
[0], cpu_fpr
[rS(ctx
->opcode
)]);
4623 tcg_gen_mov_i64(cpu_FT
[1], cpu_fpr
[rS(ctx
->opcode
) + 1]);
4627 /* BookE specific instructions */
4628 /* XXX: not implemented on 440 ? */
4629 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
)
4632 GEN_EXCP_INVAL(ctx
);
4635 /* XXX: not implemented on 440 ? */
4636 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
)
4638 #if defined(CONFIG_USER_ONLY)
4639 GEN_EXCP_PRIVOPC(ctx
);
4641 if (unlikely(!ctx
->supervisor
)) {
4642 GEN_EXCP_PRIVOPC(ctx
);
4645 gen_addr_reg_index(ctx
);
4646 /* Use the same micro-ops as for tlbie */
4647 #if defined(TARGET_PPC64)
4656 /* All 405 MAC instructions are translated here */
4657 static always_inline
void gen_405_mulladd_insn (DisasContext
*ctx
,
4659 int ra
, int rb
, int rt
, int Rc
)
4661 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[ra
]);
4662 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rb
]);
4663 switch (opc3
& 0x0D) {
4665 /* macchw - macchw. - macchwo - macchwo. */
4666 /* macchws - macchws. - macchwso - macchwso. */
4667 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
4668 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
4669 /* mulchw - mulchw. */
4670 gen_op_405_mulchw();
4673 /* macchwu - macchwu. - macchwuo - macchwuo. */
4674 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
4675 /* mulchwu - mulchwu. */
4676 gen_op_405_mulchwu();
4679 /* machhw - machhw. - machhwo - machhwo. */
4680 /* machhws - machhws. - machhwso - machhwso. */
4681 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
4682 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
4683 /* mulhhw - mulhhw. */
4684 gen_op_405_mulhhw();
4687 /* machhwu - machhwu. - machhwuo - machhwuo. */
4688 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
4689 /* mulhhwu - mulhhwu. */
4690 gen_op_405_mulhhwu();
4693 /* maclhw - maclhw. - maclhwo - maclhwo. */
4694 /* maclhws - maclhws. - maclhwso - maclhwso. */
4695 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
4696 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
4697 /* mullhw - mullhw. */
4698 gen_op_405_mullhw();
4701 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
4702 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
4703 /* mullhwu - mullhwu. */
4704 gen_op_405_mullhwu();
4708 /* nmultiply-and-accumulate (0x0E) */
4712 /* (n)multiply-and-accumulate (0x0C - 0x0E) */
4713 tcg_gen_mov_tl(cpu_T
[2], cpu_gpr
[rt
]);
4714 tcg_gen_mov_tl(cpu_T
[1], cpu_T
[0]);
4715 gen_op_405_add_T0_T2();
4718 /* Check overflow */
4720 gen_op_check_addo();
4722 gen_op_405_check_ovu();
4727 gen_op_405_check_sat();
4729 gen_op_405_check_satu();
4731 tcg_gen_mov_tl(cpu_gpr
[rt
], cpu_T
[0]);
4732 if (unlikely(Rc
) != 0) {
4738 #define GEN_MAC_HANDLER(name, opc2, opc3) \
4739 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC) \
4741 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
4742 rD(ctx->opcode), Rc(ctx->opcode)); \
4745 /* macchw - macchw. */
4746 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
4747 /* macchwo - macchwo. */
4748 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
4749 /* macchws - macchws. */
4750 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
4751 /* macchwso - macchwso. */
4752 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
4753 /* macchwsu - macchwsu. */
4754 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
4755 /* macchwsuo - macchwsuo. */
4756 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
4757 /* macchwu - macchwu. */
4758 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
4759 /* macchwuo - macchwuo. */
4760 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
4761 /* machhw - machhw. */
4762 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
4763 /* machhwo - machhwo. */
4764 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
4765 /* machhws - machhws. */
4766 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
4767 /* machhwso - machhwso. */
4768 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
4769 /* machhwsu - machhwsu. */
4770 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
4771 /* machhwsuo - machhwsuo. */
4772 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
4773 /* machhwu - machhwu. */
4774 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
4775 /* machhwuo - machhwuo. */
4776 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
4777 /* maclhw - maclhw. */
4778 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
4779 /* maclhwo - maclhwo. */
4780 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
4781 /* maclhws - maclhws. */
4782 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
4783 /* maclhwso - maclhwso. */
4784 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
4785 /* maclhwu - maclhwu. */
4786 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
4787 /* maclhwuo - maclhwuo. */
4788 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
4789 /* maclhwsu - maclhwsu. */
4790 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
4791 /* maclhwsuo - maclhwsuo. */
4792 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
4793 /* nmacchw - nmacchw. */
4794 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
4795 /* nmacchwo - nmacchwo. */
4796 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
4797 /* nmacchws - nmacchws. */
4798 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
4799 /* nmacchwso - nmacchwso. */
4800 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
4801 /* nmachhw - nmachhw. */
4802 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
4803 /* nmachhwo - nmachhwo. */
4804 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
4805 /* nmachhws - nmachhws. */
4806 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
4807 /* nmachhwso - nmachhwso. */
4808 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
4809 /* nmaclhw - nmaclhw. */
4810 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
4811 /* nmaclhwo - nmaclhwo. */
4812 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
4813 /* nmaclhws - nmaclhws. */
4814 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
4815 /* nmaclhwso - nmaclhwso. */
4816 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
4818 /* mulchw - mulchw. */
4819 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
4820 /* mulchwu - mulchwu. */
4821 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
4822 /* mulhhw - mulhhw. */
4823 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
4824 /* mulhhwu - mulhhwu. */
4825 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
4826 /* mullhw - mullhw. */
4827 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
4828 /* mullhwu - mullhwu. */
4829 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
4832 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
)
4834 #if defined(CONFIG_USER_ONLY)
4835 GEN_EXCP_PRIVREG(ctx
);
4837 uint32_t dcrn
= SPR(ctx
->opcode
);
4839 if (unlikely(!ctx
->supervisor
)) {
4840 GEN_EXCP_PRIVREG(ctx
);
4843 tcg_gen_movi_tl(cpu_T
[0], dcrn
);
4845 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4850 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
)
4852 #if defined(CONFIG_USER_ONLY)
4853 GEN_EXCP_PRIVREG(ctx
);
4855 uint32_t dcrn
= SPR(ctx
->opcode
);
4857 if (unlikely(!ctx
->supervisor
)) {
4858 GEN_EXCP_PRIVREG(ctx
);
4861 tcg_gen_movi_tl(cpu_T
[0], dcrn
);
4862 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
4868 /* XXX: not implemented on 440 ? */
4869 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
)
4871 #if defined(CONFIG_USER_ONLY)
4872 GEN_EXCP_PRIVREG(ctx
);
4874 if (unlikely(!ctx
->supervisor
)) {
4875 GEN_EXCP_PRIVREG(ctx
);
4878 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4880 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4881 /* Note: Rc update flag set leads to undefined state of Rc0 */
4886 /* XXX: not implemented on 440 ? */
4887 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
)
4889 #if defined(CONFIG_USER_ONLY)
4890 GEN_EXCP_PRIVREG(ctx
);
4892 if (unlikely(!ctx
->supervisor
)) {
4893 GEN_EXCP_PRIVREG(ctx
);
4896 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4897 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
4899 /* Note: Rc update flag set leads to undefined state of Rc0 */
4903 /* mfdcrux (PPC 460) : user-mode access to DCR */
4904 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
)
4906 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4908 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4909 /* Note: Rc update flag set leads to undefined state of Rc0 */
4912 /* mtdcrux (PPC 460) : user-mode access to DCR */
4913 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
)
4915 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
4916 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
4918 /* Note: Rc update flag set leads to undefined state of Rc0 */
4922 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
)
4924 #if defined(CONFIG_USER_ONLY)
4925 GEN_EXCP_PRIVOPC(ctx
);
4927 if (unlikely(!ctx
->supervisor
)) {
4928 GEN_EXCP_PRIVOPC(ctx
);
4931 /* interpreted as no-op */
4936 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
)
4938 #if defined(CONFIG_USER_ONLY)
4939 GEN_EXCP_PRIVOPC(ctx
);
4941 if (unlikely(!ctx
->supervisor
)) {
4942 GEN_EXCP_PRIVOPC(ctx
);
4945 gen_addr_reg_index(ctx
);
4947 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
4952 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
)
4954 /* interpreted as no-op */
4955 /* XXX: specification say this is treated as a load by the MMU
4956 * but does not generate any exception
4961 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
)
4963 #if defined(CONFIG_USER_ONLY)
4964 GEN_EXCP_PRIVOPC(ctx
);
4966 if (unlikely(!ctx
->supervisor
)) {
4967 GEN_EXCP_PRIVOPC(ctx
);
4970 /* interpreted as no-op */
4975 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
)
4977 #if defined(CONFIG_USER_ONLY)
4978 GEN_EXCP_PRIVOPC(ctx
);
4980 if (unlikely(!ctx
->supervisor
)) {
4981 GEN_EXCP_PRIVOPC(ctx
);
4984 /* interpreted as no-op */
4988 /* rfci (supervisor only) */
4989 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
)
4991 #if defined(CONFIG_USER_ONLY)
4992 GEN_EXCP_PRIVOPC(ctx
);
4994 if (unlikely(!ctx
->supervisor
)) {
4995 GEN_EXCP_PRIVOPC(ctx
);
4998 /* Restore CPU state */
5004 GEN_HANDLER(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
)
5006 #if defined(CONFIG_USER_ONLY)
5007 GEN_EXCP_PRIVOPC(ctx
);
5009 if (unlikely(!ctx
->supervisor
)) {
5010 GEN_EXCP_PRIVOPC(ctx
);
5013 /* Restore CPU state */
5019 /* BookE specific */
5020 /* XXX: not implemented on 440 ? */
5021 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
)
5023 #if defined(CONFIG_USER_ONLY)
5024 GEN_EXCP_PRIVOPC(ctx
);
5026 if (unlikely(!ctx
->supervisor
)) {
5027 GEN_EXCP_PRIVOPC(ctx
);
5030 /* Restore CPU state */
5036 /* XXX: not implemented on 440 ? */
5037 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
)
5039 #if defined(CONFIG_USER_ONLY)
5040 GEN_EXCP_PRIVOPC(ctx
);
5042 if (unlikely(!ctx
->supervisor
)) {
5043 GEN_EXCP_PRIVOPC(ctx
);
5046 /* Restore CPU state */
5052 /* TLB management - PowerPC 405 implementation */
5054 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
)
5056 #if defined(CONFIG_USER_ONLY)
5057 GEN_EXCP_PRIVOPC(ctx
);
5059 if (unlikely(!ctx
->supervisor
)) {
5060 GEN_EXCP_PRIVOPC(ctx
);
5063 switch (rB(ctx
->opcode
)) {
5065 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5066 gen_op_4xx_tlbre_hi();
5067 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
5070 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5071 gen_op_4xx_tlbre_lo();
5072 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
5075 GEN_EXCP_INVAL(ctx
);
5081 /* tlbsx - tlbsx. */
5082 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
)
5084 #if defined(CONFIG_USER_ONLY)
5085 GEN_EXCP_PRIVOPC(ctx
);
5087 if (unlikely(!ctx
->supervisor
)) {
5088 GEN_EXCP_PRIVOPC(ctx
);
5091 gen_addr_reg_index(ctx
);
5093 if (Rc(ctx
->opcode
))
5094 gen_op_4xx_tlbsx_check();
5095 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
5100 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
)
5102 #if defined(CONFIG_USER_ONLY)
5103 GEN_EXCP_PRIVOPC(ctx
);
5105 if (unlikely(!ctx
->supervisor
)) {
5106 GEN_EXCP_PRIVOPC(ctx
);
5109 switch (rB(ctx
->opcode
)) {
5111 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5112 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
5113 gen_op_4xx_tlbwe_hi();
5116 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5117 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
5118 gen_op_4xx_tlbwe_lo();
5121 GEN_EXCP_INVAL(ctx
);
5127 /* TLB management - PowerPC 440 implementation */
5129 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
)
5131 #if defined(CONFIG_USER_ONLY)
5132 GEN_EXCP_PRIVOPC(ctx
);
5134 if (unlikely(!ctx
->supervisor
)) {
5135 GEN_EXCP_PRIVOPC(ctx
);
5138 switch (rB(ctx
->opcode
)) {
5142 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5143 gen_op_440_tlbre(rB(ctx
->opcode
));
5144 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
5147 GEN_EXCP_INVAL(ctx
);
5153 /* tlbsx - tlbsx. */
5154 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
)
5156 #if defined(CONFIG_USER_ONLY)
5157 GEN_EXCP_PRIVOPC(ctx
);
5159 if (unlikely(!ctx
->supervisor
)) {
5160 GEN_EXCP_PRIVOPC(ctx
);
5163 gen_addr_reg_index(ctx
);
5165 if (Rc(ctx
->opcode
))
5166 gen_op_4xx_tlbsx_check();
5167 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
5172 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
)
5174 #if defined(CONFIG_USER_ONLY)
5175 GEN_EXCP_PRIVOPC(ctx
);
5177 if (unlikely(!ctx
->supervisor
)) {
5178 GEN_EXCP_PRIVOPC(ctx
);
5181 switch (rB(ctx
->opcode
)) {
5185 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5186 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rS(ctx
->opcode
)]);
5187 gen_op_440_tlbwe(rB(ctx
->opcode
));
5190 GEN_EXCP_INVAL(ctx
);
5197 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
)
5199 #if defined(CONFIG_USER_ONLY)
5200 GEN_EXCP_PRIVOPC(ctx
);
5202 if (unlikely(!ctx
->supervisor
)) {
5203 GEN_EXCP_PRIVOPC(ctx
);
5206 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rD(ctx
->opcode
)]);
5208 /* Stop translation to have a chance to raise an exception
5209 * if we just set msr_ee to 1
5216 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000EFC01, PPC_WRTEE
)
5218 #if defined(CONFIG_USER_ONLY)
5219 GEN_EXCP_PRIVOPC(ctx
);
5221 if (unlikely(!ctx
->supervisor
)) {
5222 GEN_EXCP_PRIVOPC(ctx
);
5225 tcg_gen_movi_tl(cpu_T
[0], ctx
->opcode
& 0x00010000);
5227 /* Stop translation to have a chance to raise an exception
5228 * if we just set msr_ee to 1
5234 /* PowerPC 440 specific instructions */
5236 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
)
5238 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rS(ctx
->opcode
)]);
5239 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
5241 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_T
[0]);
5242 gen_op_store_xer_bc();
5243 if (Rc(ctx
->opcode
)) {
5244 gen_op_440_dlmzb_update_Rc();
5245 gen_op_store_T0_crf(0);
5249 /* mbar replaces eieio on 440 */
5250 GEN_HANDLER(mbar
, 0x1F, 0x16, 0x13, 0x001FF801, PPC_BOOKE
)
5252 /* interpreted as no-op */
5255 /* msync replaces sync on 440 */
5256 GEN_HANDLER(msync
, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE
)
5258 /* interpreted as no-op */
5262 GEN_HANDLER2(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001, PPC_BOOKE
)
5264 /* interpreted as no-op */
5265 /* XXX: specification say this is treated as a load by the MMU
5266 * but does not generate any exception
5270 /*** Altivec vector extension ***/
5271 /* Altivec registers moves */
5273 static always_inline
void gen_load_avr(int t
, int reg
) {
5274 tcg_gen_mov_i64(cpu_AVRh
[t
], cpu_avrh
[reg
]);
5275 tcg_gen_mov_i64(cpu_AVRl
[t
], cpu_avrl
[reg
]);
5278 static always_inline
void gen_store_avr(int reg
, int t
) {
5279 tcg_gen_mov_i64(cpu_avrh
[reg
], cpu_AVRh
[t
]);
5280 tcg_gen_mov_i64(cpu_avrl
[reg
], cpu_AVRl
[t
]);
5283 #define op_vr_ldst(name) (*gen_op_##name[ctx->mem_idx])()
5284 #define OP_VR_LD_TABLE(name) \
5285 static GenOpFunc *gen_op_vr_l##name[NB_MEM_FUNCS] = { \
5286 GEN_MEM_FUNCS(vr_l##name), \
5288 #define OP_VR_ST_TABLE(name) \
5289 static GenOpFunc *gen_op_vr_st##name[NB_MEM_FUNCS] = { \
5290 GEN_MEM_FUNCS(vr_st##name), \
5293 #define GEN_VR_LDX(name, opc2, opc3) \
5294 GEN_HANDLER(l##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
5296 if (unlikely(!ctx->altivec_enabled)) { \
5297 GEN_EXCP_NO_VR(ctx); \
5300 gen_addr_reg_index(ctx); \
5301 op_vr_ldst(vr_l##name); \
5302 gen_store_avr(rD(ctx->opcode), 0); \
5305 #define GEN_VR_STX(name, opc2, opc3) \
5306 GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) \
5308 if (unlikely(!ctx->altivec_enabled)) { \
5309 GEN_EXCP_NO_VR(ctx); \
5312 gen_addr_reg_index(ctx); \
5313 gen_load_avr(0, rS(ctx->opcode)); \
5314 op_vr_ldst(vr_st##name); \
5318 GEN_VR_LDX(vx
, 0x07, 0x03);
5319 /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */
5320 #define gen_op_vr_lvxl gen_op_vr_lvx
5321 GEN_VR_LDX(vxl
, 0x07, 0x0B);
5324 GEN_VR_STX(vx
, 0x07, 0x07);
5325 /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */
5326 #define gen_op_vr_stvxl gen_op_vr_stvx
5327 GEN_VR_STX(vxl
, 0x07, 0x0F);
5329 /*** SPE extension ***/
5330 /* Register moves */
5332 static always_inline
void gen_load_gpr64(TCGv t
, int reg
) {
5333 #if defined(TARGET_PPC64)
5334 tcg_gen_mov_i64(t
, cpu_gpr
[reg
]);
5336 tcg_gen_extu_i32_i64(t
, cpu_gprh
[reg
]);
5337 tcg_gen_shli_i64(t
, t
, 32);
5338 TCGv tmp
= tcg_temp_local_new(TCG_TYPE_I64
);
5339 tcg_gen_extu_i32_i64(tmp
, cpu_gpr
[reg
]);
5340 tcg_gen_or_i64(t
, t
, tmp
);
5345 static always_inline
void gen_store_gpr64(int reg
, TCGv t
) {
5346 #if defined(TARGET_PPC64)
5347 tcg_gen_mov_i64(cpu_gpr
[reg
], t
);
5349 tcg_gen_trunc_i64_i32(cpu_gpr
[reg
], t
);
5350 TCGv tmp
= tcg_temp_local_new(TCG_TYPE_I64
);
5351 tcg_gen_shri_i64(tmp
, t
, 32);
5352 tcg_gen_trunc_i64_i32(cpu_gprh
[reg
], tmp
);
5357 #define GEN_SPE(name0, name1, opc2, opc3, inval, type) \
5358 GEN_HANDLER(name0##_##name1, 0x04, opc2, opc3, inval, type) \
5360 if (Rc(ctx->opcode)) \
5366 /* Handler for undefined SPE opcodes */
5367 static always_inline
void gen_speundef (DisasContext
*ctx
)
5369 GEN_EXCP_INVAL(ctx
);
5372 /* SPE load and stores */
5373 static always_inline
void gen_addr_spe_imm_index (DisasContext
*ctx
, int sh
)
5375 target_long simm
= rB(ctx
->opcode
);
5377 if (rA(ctx
->opcode
) == 0) {
5378 tcg_gen_movi_tl(cpu_T
[0], simm
<< sh
);
5380 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5381 if (likely(simm
!= 0))
5382 gen_op_addi(simm
<< sh
);
5386 #define op_spe_ldst(name) (*gen_op_##name[ctx->mem_idx])()
5387 #define OP_SPE_LD_TABLE(name) \
5388 static GenOpFunc *gen_op_spe_l##name[NB_MEM_FUNCS] = { \
5389 GEN_MEM_FUNCS(spe_l##name), \
5391 #define OP_SPE_ST_TABLE(name) \
5392 static GenOpFunc *gen_op_spe_st##name[NB_MEM_FUNCS] = { \
5393 GEN_MEM_FUNCS(spe_st##name), \
5396 #define GEN_SPE_LD(name, sh) \
5397 static always_inline void gen_evl##name (DisasContext *ctx) \
5399 if (unlikely(!ctx->spe_enabled)) { \
5400 GEN_EXCP_NO_AP(ctx); \
5403 gen_addr_spe_imm_index(ctx, sh); \
5404 op_spe_ldst(spe_l##name); \
5405 gen_store_gpr64(rD(ctx->opcode), cpu_T64[1]); \
5408 #define GEN_SPE_LDX(name) \
5409 static always_inline void gen_evl##name##x (DisasContext *ctx) \
5411 if (unlikely(!ctx->spe_enabled)) { \
5412 GEN_EXCP_NO_AP(ctx); \
5415 gen_addr_reg_index(ctx); \
5416 op_spe_ldst(spe_l##name); \
5417 gen_store_gpr64(rD(ctx->opcode), cpu_T64[1]); \
5420 #define GEN_SPEOP_LD(name, sh) \
5421 OP_SPE_LD_TABLE(name); \
5422 GEN_SPE_LD(name, sh); \
5425 #define GEN_SPE_ST(name, sh) \
5426 static always_inline void gen_evst##name (DisasContext *ctx) \
5428 if (unlikely(!ctx->spe_enabled)) { \
5429 GEN_EXCP_NO_AP(ctx); \
5432 gen_addr_spe_imm_index(ctx, sh); \
5433 gen_load_gpr64(cpu_T64[1], rS(ctx->opcode)); \
5434 op_spe_ldst(spe_st##name); \
5437 #define GEN_SPE_STX(name) \
5438 static always_inline void gen_evst##name##x (DisasContext *ctx) \
5440 if (unlikely(!ctx->spe_enabled)) { \
5441 GEN_EXCP_NO_AP(ctx); \
5444 gen_addr_reg_index(ctx); \
5445 gen_load_gpr64(cpu_T64[1], rS(ctx->opcode)); \
5446 op_spe_ldst(spe_st##name); \
5449 #define GEN_SPEOP_ST(name, sh) \
5450 OP_SPE_ST_TABLE(name); \
5451 GEN_SPE_ST(name, sh); \
5454 #define GEN_SPEOP_LDST(name, sh) \
5455 GEN_SPEOP_LD(name, sh); \
5456 GEN_SPEOP_ST(name, sh)
5458 /* SPE arithmetic and logic */
5459 #define GEN_SPEOP_ARITH2(name) \
5460 static always_inline void gen_##name (DisasContext *ctx) \
5462 if (unlikely(!ctx->spe_enabled)) { \
5463 GEN_EXCP_NO_AP(ctx); \
5466 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode)); \
5467 gen_load_gpr64(cpu_T64[1], rB(ctx->opcode)); \
5469 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
5472 #define GEN_SPEOP_ARITH1(name) \
5473 static always_inline void gen_##name (DisasContext *ctx) \
5475 if (unlikely(!ctx->spe_enabled)) { \
5476 GEN_EXCP_NO_AP(ctx); \
5479 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode)); \
5481 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
5484 #define GEN_SPEOP_COMP(name) \
5485 static always_inline void gen_##name (DisasContext *ctx) \
5487 if (unlikely(!ctx->spe_enabled)) { \
5488 GEN_EXCP_NO_AP(ctx); \
5491 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode)); \
5492 gen_load_gpr64(cpu_T64[1], rB(ctx->opcode)); \
5494 gen_op_store_T0_crf(crfD(ctx->opcode)); \
5498 GEN_SPEOP_ARITH2(evand
);
5499 GEN_SPEOP_ARITH2(evandc
);
5500 GEN_SPEOP_ARITH2(evxor
);
5501 GEN_SPEOP_ARITH2(evor
);
5502 GEN_SPEOP_ARITH2(evnor
);
5503 GEN_SPEOP_ARITH2(eveqv
);
5504 GEN_SPEOP_ARITH2(evorc
);
5505 GEN_SPEOP_ARITH2(evnand
);
5506 GEN_SPEOP_ARITH2(evsrwu
);
5507 GEN_SPEOP_ARITH2(evsrws
);
5508 GEN_SPEOP_ARITH2(evslw
);
5509 GEN_SPEOP_ARITH2(evrlw
);
5510 GEN_SPEOP_ARITH2(evmergehi
);
5511 GEN_SPEOP_ARITH2(evmergelo
);
5512 GEN_SPEOP_ARITH2(evmergehilo
);
5513 GEN_SPEOP_ARITH2(evmergelohi
);
5516 GEN_SPEOP_ARITH2(evaddw
);
5517 GEN_SPEOP_ARITH2(evsubfw
);
5518 GEN_SPEOP_ARITH1(evabs
);
5519 GEN_SPEOP_ARITH1(evneg
);
5520 GEN_SPEOP_ARITH1(evextsb
);
5521 GEN_SPEOP_ARITH1(evextsh
);
5522 GEN_SPEOP_ARITH1(evrndw
);
5523 GEN_SPEOP_ARITH1(evcntlzw
);
5524 GEN_SPEOP_ARITH1(evcntlsw
);
5525 static always_inline
void gen_brinc (DisasContext
*ctx
)
5527 /* Note: brinc is usable even if SPE is disabled */
5528 tcg_gen_mov_tl(cpu_T
[0], cpu_gpr
[rA(ctx
->opcode
)]);
5529 tcg_gen_mov_tl(cpu_T
[1], cpu_gpr
[rB(ctx
->opcode
)]);
5531 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_T
[0]);
5534 #define GEN_SPEOP_ARITH_IMM2(name) \
5535 static always_inline void gen_##name##i (DisasContext *ctx) \
5537 if (unlikely(!ctx->spe_enabled)) { \
5538 GEN_EXCP_NO_AP(ctx); \
5541 gen_load_gpr64(cpu_T64[0], rB(ctx->opcode)); \
5542 gen_op_splatwi_T1_64(rA(ctx->opcode)); \
5544 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
5547 #define GEN_SPEOP_LOGIC_IMM2(name) \
5548 static always_inline void gen_##name##i (DisasContext *ctx) \
5550 if (unlikely(!ctx->spe_enabled)) { \
5551 GEN_EXCP_NO_AP(ctx); \
5554 gen_load_gpr64(cpu_T64[0], rA(ctx->opcode)); \
5555 gen_op_splatwi_T1_64(rB(ctx->opcode)); \
5557 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
5560 GEN_SPEOP_ARITH_IMM2(evaddw
);
5561 #define gen_evaddiw gen_evaddwi
5562 GEN_SPEOP_ARITH_IMM2(evsubfw
);
5563 #define gen_evsubifw gen_evsubfwi
5564 GEN_SPEOP_LOGIC_IMM2(evslw
);
5565 GEN_SPEOP_LOGIC_IMM2(evsrwu
);
5566 #define gen_evsrwis gen_evsrwsi
5567 GEN_SPEOP_LOGIC_IMM2(evsrws
);
5568 #define gen_evsrwiu gen_evsrwui
5569 GEN_SPEOP_LOGIC_IMM2(evrlw
);
5571 static always_inline
void gen_evsplati (DisasContext
*ctx
)
5573 int32_t imm
= (int32_t)(rA(ctx
->opcode
) << 27) >> 27;
5575 gen_op_splatwi_T0_64(imm
);
5576 gen_store_gpr64(rD(ctx
->opcode
), cpu_T64
[0]);
5579 static always_inline
void gen_evsplatfi (DisasContext
*ctx
)
5581 uint32_t imm
= rA(ctx
->opcode
) << 27;
5583 gen_op_splatwi_T0_64(imm
);
5584 gen_store_gpr64(rD(ctx
->opcode
), cpu_T64
[0]);
5588 GEN_SPEOP_COMP(evcmpgtu
);
5589 GEN_SPEOP_COMP(evcmpgts
);
5590 GEN_SPEOP_COMP(evcmpltu
);
5591 GEN_SPEOP_COMP(evcmplts
);
5592 GEN_SPEOP_COMP(evcmpeq
);
5594 GEN_SPE(evaddw
, speundef
, 0x00, 0x08, 0x00000000, PPC_SPE
); ////
5595 GEN_SPE(evaddiw
, speundef
, 0x01, 0x08, 0x00000000, PPC_SPE
);
5596 GEN_SPE(evsubfw
, speundef
, 0x02, 0x08, 0x00000000, PPC_SPE
); ////
5597 GEN_SPE(evsubifw
, speundef
, 0x03, 0x08, 0x00000000, PPC_SPE
);
5598 GEN_SPE(evabs
, evneg
, 0x04, 0x08, 0x0000F800, PPC_SPE
); ////
5599 GEN_SPE(evextsb
, evextsh
, 0x05, 0x08, 0x0000F800, PPC_SPE
); ////
5600 GEN_SPE(evrndw
, evcntlzw
, 0x06, 0x08, 0x0000F800, PPC_SPE
); ////
5601 GEN_SPE(evcntlsw
, brinc
, 0x07, 0x08, 0x00000000, PPC_SPE
); //
5602 GEN_SPE(speundef
, evand
, 0x08, 0x08, 0x00000000, PPC_SPE
); ////
5603 GEN_SPE(evandc
, speundef
, 0x09, 0x08, 0x00000000, PPC_SPE
); ////
5604 GEN_SPE(evxor
, evor
, 0x0B, 0x08, 0x00000000, PPC_SPE
); ////
5605 GEN_SPE(evnor
, eveqv
, 0x0C, 0x08, 0x00000000, PPC_SPE
); ////
5606 GEN_SPE(speundef
, evorc
, 0x0D, 0x08, 0x00000000, PPC_SPE
); ////
5607 GEN_SPE(evnand
, speundef
, 0x0F, 0x08, 0x00000000, PPC_SPE
); ////
5608 GEN_SPE(evsrwu
, evsrws
, 0x10, 0x08, 0x00000000, PPC_SPE
); ////
5609 GEN_SPE(evsrwiu
, evsrwis
, 0x11, 0x08, 0x00000000, PPC_SPE
);
5610 GEN_SPE(evslw
, speundef
, 0x12, 0x08, 0x00000000, PPC_SPE
); ////
5611 GEN_SPE(evslwi
, speundef
, 0x13, 0x08, 0x00000000, PPC_SPE
);
5612 GEN_SPE(evrlw
, evsplati
, 0x14, 0x08, 0x00000000, PPC_SPE
); //
5613 GEN_SPE(evrlwi
, evsplatfi
, 0x15, 0x08, 0x00000000, PPC_SPE
);
5614 GEN_SPE(evmergehi
, evmergelo
, 0x16, 0x08, 0x00000000, PPC_SPE
); ////
5615 GEN_SPE(evmergehilo
, evmergelohi
, 0x17, 0x08, 0x00000000, PPC_SPE
); ////
5616 GEN_SPE(evcmpgtu
, evcmpgts
, 0x18, 0x08, 0x00600000, PPC_SPE
); ////
5617 GEN_SPE(evcmpltu
, evcmplts
, 0x19, 0x08, 0x00600000, PPC_SPE
); ////
5618 GEN_SPE(evcmpeq
, speundef
, 0x1A, 0x08, 0x00600000, PPC_SPE
); ////
5620 static always_inline
void gen_evsel (DisasContext
*ctx
)
5622 if (unlikely(!ctx
->spe_enabled
)) {
5623 GEN_EXCP_NO_AP(ctx
);
5626 gen_op_load_crf_T0(ctx
->opcode
& 0x7);
5627 gen_load_gpr64(cpu_T64
[0], rA(ctx
->opcode
));
5628 gen_load_gpr64(cpu_T64
[1], rB(ctx
->opcode
));
5630 gen_store_gpr64(rD(ctx
->opcode
), cpu_T64
[0]);
5633 GEN_HANDLER2(evsel0
, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE
)
5637 GEN_HANDLER2(evsel1
, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE
)
5641 GEN_HANDLER2(evsel2
, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE
)
5645 GEN_HANDLER2(evsel3
, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE
)
5650 /* Load and stores */
5651 #if defined(TARGET_PPC64)
5652 /* In that case, we already have 64 bits load & stores
5653 * so, spe_ldd is equivalent to ld and spe_std is equivalent to std
5655 #define gen_op_spe_ldd_raw gen_op_ld_raw
5656 #define gen_op_spe_ldd_user gen_op_ld_user
5657 #define gen_op_spe_ldd_kernel gen_op_ld_kernel
5658 #define gen_op_spe_ldd_hypv gen_op_ld_hypv
5659 #define gen_op_spe_ldd_64_raw gen_op_ld_64_raw
5660 #define gen_op_spe_ldd_64_user gen_op_ld_64_user
5661 #define gen_op_spe_ldd_64_kernel gen_op_ld_64_kernel
5662 #define gen_op_spe_ldd_64_hypv gen_op_ld_64_hypv
5663 #define gen_op_spe_ldd_le_raw gen_op_ld_le_raw
5664 #define gen_op_spe_ldd_le_user gen_op_ld_le_user
5665 #define gen_op_spe_ldd_le_kernel gen_op_ld_le_kernel
5666 #define gen_op_spe_ldd_le_hypv gen_op_ld_le_hypv
5667 #define gen_op_spe_ldd_le_64_raw gen_op_ld_le_64_raw
5668 #define gen_op_spe_ldd_le_64_user gen_op_ld_le_64_user
5669 #define gen_op_spe_ldd_le_64_kernel gen_op_ld_le_64_kernel
5670 #define gen_op_spe_ldd_le_64_hypv gen_op_ld_le_64_hypv
5671 #define gen_op_spe_stdd_raw gen_op_std_raw
5672 #define gen_op_spe_stdd_user gen_op_std_user
5673 #define gen_op_spe_stdd_kernel gen_op_std_kernel
5674 #define gen_op_spe_stdd_hypv gen_op_std_hypv
5675 #define gen_op_spe_stdd_64_raw gen_op_std_64_raw
5676 #define gen_op_spe_stdd_64_user gen_op_std_64_user
5677 #define gen_op_spe_stdd_64_kernel gen_op_std_64_kernel
5678 #define gen_op_spe_stdd_64_hypv gen_op_std_64_hypv
5679 #define gen_op_spe_stdd_le_raw gen_op_std_le_raw
5680 #define gen_op_spe_stdd_le_user gen_op_std_le_user
5681 #define gen_op_spe_stdd_le_kernel gen_op_std_le_kernel
5682 #define gen_op_spe_stdd_le_hypv gen_op_std_le_hypv
5683 #define gen_op_spe_stdd_le_64_raw gen_op_std_le_64_raw
5684 #define gen_op_spe_stdd_le_64_user gen_op_std_le_64_user
5685 #define gen_op_spe_stdd_le_64_kernel gen_op_std_le_64_kernel
5686 #define gen_op_spe_stdd_le_64_hypv gen_op_std_le_64_hypv
5687 #endif /* defined(TARGET_PPC64) */
5688 GEN_SPEOP_LDST(dd
, 3);
5689 GEN_SPEOP_LDST(dw
, 3);
5690 GEN_SPEOP_LDST(dh
, 3);
5691 GEN_SPEOP_LDST(whe
, 2);
5692 GEN_SPEOP_LD(whou
, 2);
5693 GEN_SPEOP_LD(whos
, 2);
5694 GEN_SPEOP_ST(who
, 2);
5696 #if defined(TARGET_PPC64)
5697 /* In that case, spe_stwwo is equivalent to stw */
5698 #define gen_op_spe_stwwo_raw gen_op_stw_raw
5699 #define gen_op_spe_stwwo_user gen_op_stw_user
5700 #define gen_op_spe_stwwo_kernel gen_op_stw_kernel
5701 #define gen_op_spe_stwwo_hypv gen_op_stw_hypv
5702 #define gen_op_spe_stwwo_le_raw gen_op_stw_le_raw
5703 #define gen_op_spe_stwwo_le_user gen_op_stw_le_user
5704 #define gen_op_spe_stwwo_le_kernel gen_op_stw_le_kernel
5705 #define gen_op_spe_stwwo_le_hypv gen_op_stw_le_hypv
5706 #define gen_op_spe_stwwo_64_raw gen_op_stw_64_raw
5707 #define gen_op_spe_stwwo_64_user gen_op_stw_64_user
5708 #define gen_op_spe_stwwo_64_kernel gen_op_stw_64_kernel
5709 #define gen_op_spe_stwwo_64_hypv gen_op_stw_64_hypv
5710 #define gen_op_spe_stwwo_le_64_raw gen_op_stw_le_64_raw
5711 #define gen_op_spe_stwwo_le_64_user gen_op_stw_le_64_user
5712 #define gen_op_spe_stwwo_le_64_kernel gen_op_stw_le_64_kernel
5713 #define gen_op_spe_stwwo_le_64_hypv gen_op_stw_le_64_hypv
5715 #define _GEN_OP_SPE_STWWE(suffix) \
5716 static always_inline void gen_op_spe_stwwe_##suffix (void) \
5718 gen_op_srli32_T1_64(); \
5719 gen_op_spe_stwwo_##suffix(); \
5721 #define _GEN_OP_SPE_STWWE_LE(suffix) \
5722 static always_inline void gen_op_spe_stwwe_le_##suffix (void) \
5724 gen_op_srli32_T1_64(); \
5725 gen_op_spe_stwwo_le_##suffix(); \
5727 #if defined(TARGET_PPC64)
5728 #define GEN_OP_SPE_STWWE(suffix) \
5729 _GEN_OP_SPE_STWWE(suffix); \
5730 _GEN_OP_SPE_STWWE_LE(suffix); \
5731 static always_inline void gen_op_spe_stwwe_64_##suffix (void) \
5733 gen_op_srli32_T1_64(); \
5734 gen_op_spe_stwwo_64_##suffix(); \
5736 static always_inline void gen_op_spe_stwwe_le_64_##suffix (void) \
5738 gen_op_srli32_T1_64(); \
5739 gen_op_spe_stwwo_le_64_##suffix(); \
5742 #define GEN_OP_SPE_STWWE(suffix) \
5743 _GEN_OP_SPE_STWWE(suffix); \
5744 _GEN_OP_SPE_STWWE_LE(suffix)
5746 #if defined(CONFIG_USER_ONLY)
5747 GEN_OP_SPE_STWWE(raw
);
5748 #else /* defined(CONFIG_USER_ONLY) */
5749 GEN_OP_SPE_STWWE(user
);
5750 GEN_OP_SPE_STWWE(kernel
);
5751 GEN_OP_SPE_STWWE(hypv
);
5752 #endif /* defined(CONFIG_USER_ONLY) */
5753 GEN_SPEOP_ST(wwe
, 2);
5754 GEN_SPEOP_ST(wwo
, 2);
5756 #define GEN_SPE_LDSPLAT(name, op, suffix) \
5757 static always_inline void gen_op_spe_l##name##_##suffix (void) \
5759 gen_op_##op##_##suffix(); \
5760 gen_op_splatw_T1_64(); \
5763 #define GEN_OP_SPE_LHE(suffix) \
5764 static always_inline void gen_op_spe_lhe_##suffix (void) \
5766 gen_op_spe_lh_##suffix(); \
5767 gen_op_sli16_T1_64(); \
5770 #define GEN_OP_SPE_LHX(suffix) \
5771 static always_inline void gen_op_spe_lhx_##suffix (void) \
5773 gen_op_spe_lh_##suffix(); \
5774 gen_op_extsh_T1_64(); \
5777 #if defined(CONFIG_USER_ONLY)
5778 GEN_OP_SPE_LHE(raw
);
5779 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, raw
);
5780 GEN_OP_SPE_LHE(le_raw
);
5781 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_raw
);
5782 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, raw
);
5783 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_raw
);
5784 GEN_OP_SPE_LHX(raw
);
5785 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, raw
);
5786 GEN_OP_SPE_LHX(le_raw
);
5787 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_raw
);
5788 #if defined(TARGET_PPC64)
5789 GEN_OP_SPE_LHE(64_raw
);
5790 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, 64_raw
);
5791 GEN_OP_SPE_LHE(le_64_raw
);
5792 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_64_raw
);
5793 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, 64_raw
);
5794 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_64_raw
);
5795 GEN_OP_SPE_LHX(64_raw
);
5796 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, 64_raw
);
5797 GEN_OP_SPE_LHX(le_64_raw
);
5798 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_64_raw
);
5801 GEN_OP_SPE_LHE(user
);
5802 GEN_OP_SPE_LHE(kernel
);
5803 GEN_OP_SPE_LHE(hypv
);
5804 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, user
);
5805 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, kernel
);
5806 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, hypv
);
5807 GEN_OP_SPE_LHE(le_user
);
5808 GEN_OP_SPE_LHE(le_kernel
);
5809 GEN_OP_SPE_LHE(le_hypv
);
5810 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_user
);
5811 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_kernel
);
5812 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_hypv
);
5813 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, user
);
5814 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, kernel
);
5815 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, hypv
);
5816 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_user
);
5817 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_kernel
);
5818 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_hypv
);
5819 GEN_OP_SPE_LHX(user
);
5820 GEN_OP_SPE_LHX(kernel
);
5821 GEN_OP_SPE_LHX(hypv
);
5822 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, user
);
5823 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, kernel
);
5824 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, hypv
);
5825 GEN_OP_SPE_LHX(le_user
);
5826 GEN_OP_SPE_LHX(le_kernel
);
5827 GEN_OP_SPE_LHX(le_hypv
);
5828 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_user
);
5829 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_kernel
);
5830 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_hypv
);
5831 #if defined(TARGET_PPC64)
5832 GEN_OP_SPE_LHE(64_user
);
5833 GEN_OP_SPE_LHE(64_kernel
);
5834 GEN_OP_SPE_LHE(64_hypv
);
5835 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, 64_user
);
5836 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, 64_kernel
);
5837 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, 64_hypv
);
5838 GEN_OP_SPE_LHE(le_64_user
);
5839 GEN_OP_SPE_LHE(le_64_kernel
);
5840 GEN_OP_SPE_LHE(le_64_hypv
);
5841 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_64_user
);
5842 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_64_kernel
);
5843 GEN_SPE_LDSPLAT(hhesplat
, spe_lhe
, le_64_hypv
);
5844 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, 64_user
);
5845 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, 64_kernel
);
5846 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, 64_hypv
);
5847 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_64_user
);
5848 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_64_kernel
);
5849 GEN_SPE_LDSPLAT(hhousplat
, spe_lh
, le_64_hypv
);
5850 GEN_OP_SPE_LHX(64_user
);
5851 GEN_OP_SPE_LHX(64_kernel
);
5852 GEN_OP_SPE_LHX(64_hypv
);
5853 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, 64_user
);
5854 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, 64_kernel
);
5855 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, 64_hypv
);
5856 GEN_OP_SPE_LHX(le_64_user
);
5857 GEN_OP_SPE_LHX(le_64_kernel
);
5858 GEN_OP_SPE_LHX(le_64_hypv
);
5859 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_64_user
);
5860 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_64_kernel
);
5861 GEN_SPE_LDSPLAT(hhossplat
, spe_lhx
, le_64_hypv
);
5864 GEN_SPEOP_LD(hhesplat
, 1);
5865 GEN_SPEOP_LD(hhousplat
, 1);
5866 GEN_SPEOP_LD(hhossplat
, 1);
5867 GEN_SPEOP_LD(wwsplat
, 2);
5868 GEN_SPEOP_LD(whsplat
, 2);
5870 GEN_SPE(evlddx
, evldd
, 0x00, 0x0C, 0x00000000, PPC_SPE
); //
5871 GEN_SPE(evldwx
, evldw
, 0x01, 0x0C, 0x00000000, PPC_SPE
); //
5872 GEN_SPE(evldhx
, evldh
, 0x02, 0x0C, 0x00000000, PPC_SPE
); //
5873 GEN_SPE(evlhhesplatx
, evlhhesplat
, 0x04, 0x0C, 0x00000000, PPC_SPE
); //
5874 GEN_SPE(evlhhousplatx
, evlhhousplat
, 0x06, 0x0C, 0x00000000, PPC_SPE
); //
5875 GEN_SPE(evlhhossplatx
, evlhhossplat
, 0x07, 0x0C, 0x00000000, PPC_SPE
); //
5876 GEN_SPE(evlwhex
, evlwhe
, 0x08, 0x0C, 0x00000000, PPC_SPE
); //
5877 GEN_SPE(evlwhoux
, evlwhou
, 0x0A, 0x0C, 0x00000000, PPC_SPE
); //
5878 GEN_SPE(evlwhosx
, evlwhos
, 0x0B, 0x0C, 0x00000000, PPC_SPE
); //
5879 GEN_SPE(evlwwsplatx
, evlwwsplat
, 0x0C, 0x0C, 0x00000000, PPC_SPE
); //
5880 GEN_SPE(evlwhsplatx
, evlwhsplat
, 0x0E, 0x0C, 0x00000000, PPC_SPE
); //
5881 GEN_SPE(evstddx
, evstdd
, 0x10, 0x0C, 0x00000000, PPC_SPE
); //
5882 GEN_SPE(evstdwx
, evstdw
, 0x11, 0x0C, 0x00000000, PPC_SPE
); //
5883 GEN_SPE(evstdhx
, evstdh
, 0x12, 0x0C, 0x00000000, PPC_SPE
); //
5884 GEN_SPE(evstwhex
, evstwhe
, 0x18, 0x0C, 0x00000000, PPC_SPE
); //
5885 GEN_SPE(evstwhox
, evstwho
, 0x1A, 0x0C, 0x00000000, PPC_SPE
); //
5886 GEN_SPE(evstwwex
, evstwwe
, 0x1C, 0x0C, 0x00000000, PPC_SPE
); //
5887 GEN_SPE(evstwwox
, evstwwo
, 0x1E, 0x0C, 0x00000000, PPC_SPE
); //
5889 /* Multiply and add - TODO */
5891 GEN_SPE(speundef
, evmhessf
, 0x01, 0x10, 0x00000000, PPC_SPE
);
5892 GEN_SPE(speundef
, evmhossf
, 0x03, 0x10, 0x00000000, PPC_SPE
);
5893 GEN_SPE(evmheumi
, evmhesmi
, 0x04, 0x10, 0x00000000, PPC_SPE
);
5894 GEN_SPE(speundef
, evmhesmf
, 0x05, 0x10, 0x00000000, PPC_SPE
);
5895 GEN_SPE(evmhoumi
, evmhosmi
, 0x06, 0x10, 0x00000000, PPC_SPE
);
5896 GEN_SPE(speundef
, evmhosmf
, 0x07, 0x10, 0x00000000, PPC_SPE
);
5897 GEN_SPE(speundef
, evmhessfa
, 0x11, 0x10, 0x00000000, PPC_SPE
);
5898 GEN_SPE(speundef
, evmhossfa
, 0x13, 0x10, 0x00000000, PPC_SPE
);
5899 GEN_SPE(evmheumia
, evmhesmia
, 0x14, 0x10, 0x00000000, PPC_SPE
);
5900 GEN_SPE(speundef
, evmhesmfa
, 0x15, 0x10, 0x00000000, PPC_SPE
);
5901 GEN_SPE(evmhoumia
, evmhosmia
, 0x16, 0x10, 0x00000000, PPC_SPE
);
5902 GEN_SPE(speundef
, evmhosmfa
, 0x17, 0x10, 0x00000000, PPC_SPE
);
5904 GEN_SPE(speundef
, evmwhssf
, 0x03, 0x11, 0x00000000, PPC_SPE
);
5905 GEN_SPE(evmwlumi
, speundef
, 0x04, 0x11, 0x00000000, PPC_SPE
);
5906 GEN_SPE(evmwhumi
, evmwhsmi
, 0x06, 0x11, 0x00000000, PPC_SPE
);
5907 GEN_SPE(speundef
, evmwhsmf
, 0x07, 0x11, 0x00000000, PPC_SPE
);
5908 GEN_SPE(speundef
, evmwssf
, 0x09, 0x11, 0x00000000, PPC_SPE
);
5909 GEN_SPE(evmwumi
, evmwsmi
, 0x0C, 0x11, 0x00000000, PPC_SPE
);
5910 GEN_SPE(speundef
, evmwsmf
, 0x0D, 0x11, 0x00000000, PPC_SPE
);
5911 GEN_SPE(speundef
, evmwhssfa
, 0x13, 0x11, 0x00000000, PPC_SPE
);
5912 GEN_SPE(evmwlumia
, speundef
, 0x14, 0x11, 0x00000000, PPC_SPE
);
5913 GEN_SPE(evmwhumia
, evmwhsmia
, 0x16, 0x11, 0x00000000, PPC_SPE
);
5914 GEN_SPE(speundef
, evmwhsmfa
, 0x17, 0x11, 0x00000000, PPC_SPE
);
5915 GEN_SPE(speundef
, evmwssfa
, 0x19, 0x11, 0x00000000, PPC_SPE
);
5916 GEN_SPE(evmwumia
, evmwsmia
, 0x1C, 0x11, 0x00000000, PPC_SPE
);
5917 GEN_SPE(speundef
, evmwsmfa
, 0x1D, 0x11, 0x00000000, PPC_SPE
);
5919 GEN_SPE(evadduiaaw
, evaddsiaaw
, 0x00, 0x13, 0x0000F800, PPC_SPE
);
5920 GEN_SPE(evsubfusiaaw
, evsubfssiaaw
, 0x01, 0x13, 0x0000F800, PPC_SPE
);
5921 GEN_SPE(evaddumiaaw
, evaddsmiaaw
, 0x04, 0x13, 0x0000F800, PPC_SPE
);
5922 GEN_SPE(evsubfumiaaw
, evsubfsmiaaw
, 0x05, 0x13, 0x0000F800, PPC_SPE
);
5923 GEN_SPE(evdivws
, evdivwu
, 0x06, 0x13, 0x00000000, PPC_SPE
);
5924 GEN_SPE(evmra
, speundef
, 0x07, 0x13, 0x0000F800, PPC_SPE
);
5926 GEN_SPE(evmheusiaaw
, evmhessiaaw
, 0x00, 0x14, 0x00000000, PPC_SPE
);
5927 GEN_SPE(speundef
, evmhessfaaw
, 0x01, 0x14, 0x00000000, PPC_SPE
);
5928 GEN_SPE(evmhousiaaw
, evmhossiaaw
, 0x02, 0x14, 0x00000000, PPC_SPE
);
5929 GEN_SPE(speundef
, evmhossfaaw
, 0x03, 0x14, 0x00000000, PPC_SPE
);
5930 GEN_SPE(evmheumiaaw
, evmhesmiaaw
, 0x04, 0x14, 0x00000000, PPC_SPE
);
5931 GEN_SPE(speundef
, evmhesmfaaw
, 0x05, 0x14, 0x00000000, PPC_SPE
);
5932 GEN_SPE(evmhoumiaaw
, evmhosmiaaw
, 0x06, 0x14, 0x00000000, PPC_SPE
);
5933 GEN_SPE(speundef
, evmhosmfaaw
, 0x07, 0x14, 0x00000000, PPC_SPE
);
5934 GEN_SPE(evmhegumiaa
, evmhegsmiaa
, 0x14, 0x14, 0x00000000, PPC_SPE
);
5935 GEN_SPE(speundef
, evmhegsmfaa
, 0x15, 0x14, 0x00000000, PPC_SPE
);
5936 GEN_SPE(evmhogumiaa
, evmhogsmiaa
, 0x16, 0x14, 0x00000000, PPC_SPE
);
5937 GEN_SPE(speundef
, evmhogsmfaa
, 0x17, 0x14, 0x00000000, PPC_SPE
);
5939 GEN_SPE(evmwlusiaaw
, evmwlssiaaw
, 0x00, 0x15, 0x00000000, PPC_SPE
);
5940 GEN_SPE(evmwlumiaaw
, evmwlsmiaaw
, 0x04, 0x15, 0x00000000, PPC_SPE
);
5941 GEN_SPE(speundef
, evmwssfaa
, 0x09, 0x15, 0x00000000, PPC_SPE
);
5942 GEN_SPE(evmwumiaa
, evmwsmiaa
, 0x0C, 0x15, 0x00000000, PPC_SPE
);
5943 GEN_SPE(speundef
, evmwsmfaa
, 0x0D, 0x15, 0x00000000, PPC_SPE
);
5945 GEN_SPE(evmheusianw
, evmhessianw
, 0x00, 0x16, 0x00000000, PPC_SPE
);
5946 GEN_SPE(speundef
, evmhessfanw
, 0x01, 0x16, 0x00000000, PPC_SPE
);
5947 GEN_SPE(evmhousianw
, evmhossianw
, 0x02, 0x16, 0x00000000, PPC_SPE
);
5948 GEN_SPE(speundef
, evmhossfanw
, 0x03, 0x16, 0x00000000, PPC_SPE
);
5949 GEN_SPE(evmheumianw
, evmhesmianw
, 0x04, 0x16, 0x00000000, PPC_SPE
);
5950 GEN_SPE(speundef
, evmhesmfanw
, 0x05, 0x16, 0x00000000, PPC_SPE
);
5951 GEN_SPE(evmhoumianw
, evmhosmianw
, 0x06, 0x16, 0x00000000, PPC_SPE
);
5952 GEN_SPE(speundef
, evmhosmfanw
, 0x07, 0x16, 0x00000000, PPC_SPE
);
5953 GEN_SPE(evmhegumian
, evmhegsmian
, 0x14, 0x16, 0x00000000, PPC_SPE
);
5954 GEN_SPE(speundef
, evmhegsmfan
, 0x15, 0x16, 0x00000000, PPC_SPE
);
5955 GEN_SPE(evmhigumian
, evmhigsmian
, 0x16, 0x16, 0x00000000, PPC_SPE
);
5956 GEN_SPE(speundef
, evmhogsmfan
, 0x17, 0x16, 0x00000000, PPC_SPE
);
5958 GEN_SPE(evmwlusianw
, evmwlssianw
, 0x00, 0x17, 0x00000000, PPC_SPE
);
5959 GEN_SPE(evmwlumianw
, evmwlsmianw
, 0x04, 0x17, 0x00000000, PPC_SPE
);
5960 GEN_SPE(speundef
, evmwssfan
, 0x09, 0x17, 0x00000000, PPC_SPE
);
5961 GEN_SPE(evmwumian
, evmwsmian
, 0x0C, 0x17, 0x00000000, PPC_SPE
);
5962 GEN_SPE(speundef
, evmwsmfan
, 0x0D, 0x17, 0x00000000, PPC_SPE
);
5965 /*** SPE floating-point extension ***/
5966 #define GEN_SPEFPUOP_CONV(name) \
5967 static always_inline void gen_##name (DisasContext *ctx) \
5969 gen_load_gpr64(cpu_T64[0], rB(ctx->opcode)); \
5971 gen_store_gpr64(rD(ctx->opcode), cpu_T64[0]); \
5974 /* Single precision floating-point vectors operations */
5976 GEN_SPEOP_ARITH2(evfsadd
);
5977 GEN_SPEOP_ARITH2(evfssub
);
5978 GEN_SPEOP_ARITH2(evfsmul
);
5979 GEN_SPEOP_ARITH2(evfsdiv
);
5980 GEN_SPEOP_ARITH1(evfsabs
);
5981 GEN_SPEOP_ARITH1(evfsnabs
);
5982 GEN_SPEOP_ARITH1(evfsneg
);
5984 GEN_SPEFPUOP_CONV(evfscfui
);
5985 GEN_SPEFPUOP_CONV(evfscfsi
);
5986 GEN_SPEFPUOP_CONV(evfscfuf
);
5987 GEN_SPEFPUOP_CONV(evfscfsf
);
5988 GEN_SPEFPUOP_CONV(evfsctui
);
5989 GEN_SPEFPUOP_CONV(evfsctsi
);
5990 GEN_SPEFPUOP_CONV(evfsctuf
);
5991 GEN_SPEFPUOP_CONV(evfsctsf
);
5992 GEN_SPEFPUOP_CONV(evfsctuiz
);
5993 GEN_SPEFPUOP_CONV(evfsctsiz
);
5995 GEN_SPEOP_COMP(evfscmpgt
);
5996 GEN_SPEOP_COMP(evfscmplt
);
5997 GEN_SPEOP_COMP(evfscmpeq
);
5998 GEN_SPEOP_COMP(evfststgt
);
5999 GEN_SPEOP_COMP(evfststlt
);
6000 GEN_SPEOP_COMP(evfststeq
);
6002 /* Opcodes definitions */
6003 GEN_SPE(evfsadd
, evfssub
, 0x00, 0x0A, 0x00000000, PPC_SPEFPU
); //
6004 GEN_SPE(evfsabs
, evfsnabs
, 0x02, 0x0A, 0x0000F800, PPC_SPEFPU
); //
6005 GEN_SPE(evfsneg
, speundef
, 0x03, 0x0A, 0x0000F800, PPC_SPEFPU
); //
6006 GEN_SPE(evfsmul
, evfsdiv
, 0x04, 0x0A, 0x00000000, PPC_SPEFPU
); //
6007 GEN_SPE(evfscmpgt
, evfscmplt
, 0x06, 0x0A, 0x00600000, PPC_SPEFPU
); //
6008 GEN_SPE(evfscmpeq
, speundef
, 0x07, 0x0A, 0x00600000, PPC_SPEFPU
); //
6009 GEN_SPE(evfscfui
, evfscfsi
, 0x08, 0x0A, 0x00180000, PPC_SPEFPU
); //
6010 GEN_SPE(evfscfuf
, evfscfsf
, 0x09, 0x0A, 0x00180000, PPC_SPEFPU
); //
6011 GEN_SPE(evfsctui
, evfsctsi
, 0x0A, 0x0A, 0x00180000, PPC_SPEFPU
); //
6012 GEN_SPE(evfsctuf
, evfsctsf
, 0x0B, 0x0A, 0x00180000, PPC_SPEFPU
); //
6013 GEN_SPE(evfsctuiz
, speundef
, 0x0C, 0x0A, 0x00180000, PPC_SPEFPU
); //
6014 GEN_SPE(evfsctsiz
, speundef
, 0x0D, 0x0A, 0x00180000, PPC_SPEFPU
); //
6015 GEN_SPE(evfststgt
, evfststlt
, 0x0E, 0x0A, 0x00600000, PPC_SPEFPU
); //
6016 GEN_SPE(evfststeq
, speundef
, 0x0F, 0x0A, 0x00600000, PPC_SPEFPU
); //
6018 /* Single precision floating-point operations */
6020 GEN_SPEOP_ARITH2(efsadd
);
6021 GEN_SPEOP_ARITH2(efssub
);
6022 GEN_SPEOP_ARITH2(efsmul
);
6023 GEN_SPEOP_ARITH2(efsdiv
);
6024 GEN_SPEOP_ARITH1(efsabs
);
6025 GEN_SPEOP_ARITH1(efsnabs
);
6026 GEN_SPEOP_ARITH1(efsneg
);
6028 GEN_SPEFPUOP_CONV(efscfui
);
6029 GEN_SPEFPUOP_CONV(efscfsi
);
6030 GEN_SPEFPUOP_CONV(efscfuf
);
6031 GEN_SPEFPUOP_CONV(efscfsf
);
6032 GEN_SPEFPUOP_CONV(efsctui
);
6033 GEN_SPEFPUOP_CONV(efsctsi
);
6034 GEN_SPEFPUOP_CONV(efsctuf
);
6035 GEN_SPEFPUOP_CONV(efsctsf
);
6036 GEN_SPEFPUOP_CONV(efsctuiz
);
6037 GEN_SPEFPUOP_CONV(efsctsiz
);
6038 GEN_SPEFPUOP_CONV(efscfd
);
6040 GEN_SPEOP_COMP(efscmpgt
);
6041 GEN_SPEOP_COMP(efscmplt
);
6042 GEN_SPEOP_COMP(efscmpeq
);
6043 GEN_SPEOP_COMP(efststgt
);
6044 GEN_SPEOP_COMP(efststlt
);
6045 GEN_SPEOP_COMP(efststeq
);
6047 /* Opcodes definitions */
6048 GEN_SPE(efsadd
, efssub
, 0x00, 0x0B, 0x00000000, PPC_SPEFPU
); //
6049 GEN_SPE(efsabs
, efsnabs
, 0x02, 0x0B, 0x0000F800, PPC_SPEFPU
); //
6050 GEN_SPE(efsneg
, speundef
, 0x03, 0x0B, 0x0000F800, PPC_SPEFPU
); //
6051 GEN_SPE(efsmul
, efsdiv
, 0x04, 0x0B, 0x00000000, PPC_SPEFPU
); //
6052 GEN_SPE(efscmpgt
, efscmplt
, 0x06, 0x0B, 0x00600000, PPC_SPEFPU
); //
6053 GEN_SPE(efscmpeq
, efscfd
, 0x07, 0x0B, 0x00600000, PPC_SPEFPU
); //
6054 GEN_SPE(efscfui
, efscfsi
, 0x08, 0x0B, 0x00180000, PPC_SPEFPU
); //
6055 GEN_SPE(efscfuf
, efscfsf
, 0x09, 0x0B, 0x00180000, PPC_SPEFPU
); //
6056 GEN_SPE(efsctui
, efsctsi
, 0x0A, 0x0B, 0x00180000, PPC_SPEFPU
); //
6057 GEN_SPE(efsctuf
, efsctsf
, 0x0B, 0x0B, 0x00180000, PPC_SPEFPU
); //
6058 GEN_SPE(efsctuiz
, speundef
, 0x0C, 0x0B, 0x00180000, PPC_SPEFPU
); //
6059 GEN_SPE(efsctsiz
, speundef
, 0x0D, 0x0B, 0x00180000, PPC_SPEFPU
); //
6060 GEN_SPE(efststgt
, efststlt
, 0x0E, 0x0B, 0x00600000, PPC_SPEFPU
); //
6061 GEN_SPE(efststeq
, speundef
, 0x0F, 0x0B, 0x00600000, PPC_SPEFPU
); //
6063 /* Double precision floating-point operations */
6065 GEN_SPEOP_ARITH2(efdadd
);
6066 GEN_SPEOP_ARITH2(efdsub
);
6067 GEN_SPEOP_ARITH2(efdmul
);
6068 GEN_SPEOP_ARITH2(efddiv
);
6069 GEN_SPEOP_ARITH1(efdabs
);
6070 GEN_SPEOP_ARITH1(efdnabs
);
6071 GEN_SPEOP_ARITH1(efdneg
);
6074 GEN_SPEFPUOP_CONV(efdcfui
);
6075 GEN_SPEFPUOP_CONV(efdcfsi
);
6076 GEN_SPEFPUOP_CONV(efdcfuf
);
6077 GEN_SPEFPUOP_CONV(efdcfsf
);
6078 GEN_SPEFPUOP_CONV(efdctui
);
6079 GEN_SPEFPUOP_CONV(efdctsi
);
6080 GEN_SPEFPUOP_CONV(efdctuf
);
6081 GEN_SPEFPUOP_CONV(efdctsf
);
6082 GEN_SPEFPUOP_CONV(efdctuiz
);
6083 GEN_SPEFPUOP_CONV(efdctsiz
);
6084 GEN_SPEFPUOP_CONV(efdcfs
);
6085 GEN_SPEFPUOP_CONV(efdcfuid
);
6086 GEN_SPEFPUOP_CONV(efdcfsid
);
6087 GEN_SPEFPUOP_CONV(efdctuidz
);
6088 GEN_SPEFPUOP_CONV(efdctsidz
);
6090 GEN_SPEOP_COMP(efdcmpgt
);
6091 GEN_SPEOP_COMP(efdcmplt
);
6092 GEN_SPEOP_COMP(efdcmpeq
);
6093 GEN_SPEOP_COMP(efdtstgt
);
6094 GEN_SPEOP_COMP(efdtstlt
);
6095 GEN_SPEOP_COMP(efdtsteq
);
6097 /* Opcodes definitions */
6098 GEN_SPE(efdadd
, efdsub
, 0x10, 0x0B, 0x00000000, PPC_SPEFPU
); //
6099 GEN_SPE(efdcfuid
, efdcfsid
, 0x11, 0x0B, 0x00180000, PPC_SPEFPU
); //
6100 GEN_SPE(efdabs
, efdnabs
, 0x12, 0x0B, 0x0000F800, PPC_SPEFPU
); //
6101 GEN_SPE(efdneg
, speundef
, 0x13, 0x0B, 0x0000F800, PPC_SPEFPU
); //
6102 GEN_SPE(efdmul
, efddiv
, 0x14, 0x0B, 0x00000000, PPC_SPEFPU
); //
6103 GEN_SPE(efdctuidz
, efdctsidz
, 0x15, 0x0B, 0x00180000, PPC_SPEFPU
); //
6104 GEN_SPE(efdcmpgt
, efdcmplt
, 0x16, 0x0B, 0x00600000, PPC_SPEFPU
); //
6105 GEN_SPE(efdcmpeq
, efdcfs
, 0x17, 0x0B, 0x00600000, PPC_SPEFPU
); //
6106 GEN_SPE(efdcfui
, efdcfsi
, 0x18, 0x0B, 0x00180000, PPC_SPEFPU
); //
6107 GEN_SPE(efdcfuf
, efdcfsf
, 0x19, 0x0B, 0x00180000, PPC_SPEFPU
); //
6108 GEN_SPE(efdctui
, efdctsi
, 0x1A, 0x0B, 0x00180000, PPC_SPEFPU
); //
6109 GEN_SPE(efdctuf
, efdctsf
, 0x1B, 0x0B, 0x00180000, PPC_SPEFPU
); //
6110 GEN_SPE(efdctuiz
, speundef
, 0x1C, 0x0B, 0x00180000, PPC_SPEFPU
); //
6111 GEN_SPE(efdctsiz
, speundef
, 0x1D, 0x0B, 0x00180000, PPC_SPEFPU
); //
6112 GEN_SPE(efdtstgt
, efdtstlt
, 0x1E, 0x0B, 0x00600000, PPC_SPEFPU
); //
6113 GEN_SPE(efdtsteq
, speundef
, 0x1F, 0x0B, 0x00600000, PPC_SPEFPU
); //
6115 /* End opcode list */
6116 GEN_OPCODE_MARK(end
);
6118 #include "translate_init.c"
6119 #include "helper_regs.h"
6121 /*****************************************************************************/
6122 /* Misc PowerPC helpers */
6123 void cpu_dump_state (CPUState
*env
, FILE *f
,
6124 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6132 cpu_fprintf(f
, "NIP " ADDRX
" LR " ADDRX
" CTR " ADDRX
" XER %08x\n",
6133 env
->nip
, env
->lr
, env
->ctr
, hreg_load_xer(env
));
6134 cpu_fprintf(f
, "MSR " ADDRX
" HID0 " ADDRX
" HF " ADDRX
" idx %d\n",
6135 env
->msr
, env
->spr
[SPR_HID0
], env
->hflags
, env
->mmu_idx
);
6136 #if !defined(NO_TIMER_DUMP)
6137 cpu_fprintf(f
, "TB %08x %08x "
6138 #if !defined(CONFIG_USER_ONLY)
6142 cpu_ppc_load_tbu(env
), cpu_ppc_load_tbl(env
)
6143 #if !defined(CONFIG_USER_ONLY)
6144 , cpu_ppc_load_decr(env
)
6148 for (i
= 0; i
< 32; i
++) {
6149 if ((i
& (RGPL
- 1)) == 0)
6150 cpu_fprintf(f
, "GPR%02d", i
);
6151 cpu_fprintf(f
, " " REGX
, ppc_dump_gpr(env
, i
));
6152 if ((i
& (RGPL
- 1)) == (RGPL
- 1))
6153 cpu_fprintf(f
, "\n");
6155 cpu_fprintf(f
, "CR ");
6156 for (i
= 0; i
< 8; i
++)
6157 cpu_fprintf(f
, "%01x", env
->crf
[i
]);
6158 cpu_fprintf(f
, " [");
6159 for (i
= 0; i
< 8; i
++) {
6161 if (env
->crf
[i
] & 0x08)
6163 else if (env
->crf
[i
] & 0x04)
6165 else if (env
->crf
[i
] & 0x02)
6167 cpu_fprintf(f
, " %c%c", a
, env
->crf
[i
] & 0x01 ? 'O' : ' ');
6169 cpu_fprintf(f
, " ] RES " ADDRX
"\n", env
->reserve
);
6170 for (i
= 0; i
< 32; i
++) {
6171 if ((i
& (RFPL
- 1)) == 0)
6172 cpu_fprintf(f
, "FPR%02d", i
);
6173 cpu_fprintf(f
, " %016" PRIx64
, *((uint64_t *)&env
->fpr
[i
]));
6174 if ((i
& (RFPL
- 1)) == (RFPL
- 1))
6175 cpu_fprintf(f
, "\n");
6177 #if !defined(CONFIG_USER_ONLY)
6178 cpu_fprintf(f
, "SRR0 " ADDRX
" SRR1 " ADDRX
" SDR1 " ADDRX
"\n",
6179 env
->spr
[SPR_SRR0
], env
->spr
[SPR_SRR1
], env
->sdr1
);
6186 void cpu_dump_statistics (CPUState
*env
, FILE*f
,
6187 int (*cpu_fprintf
)(FILE *f
, const char *fmt
, ...),
6190 #if defined(DO_PPC_STATISTICS)
6191 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
6195 for (op1
= 0; op1
< 64; op1
++) {
6197 if (is_indirect_opcode(handler
)) {
6198 t2
= ind_table(handler
);
6199 for (op2
= 0; op2
< 32; op2
++) {
6201 if (is_indirect_opcode(handler
)) {
6202 t3
= ind_table(handler
);
6203 for (op3
= 0; op3
< 32; op3
++) {
6205 if (handler
->count
== 0)
6207 cpu_fprintf(f
, "%02x %02x %02x (%02x %04d) %16s: "
6209 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
6211 handler
->count
, handler
->count
);
6214 if (handler
->count
== 0)
6216 cpu_fprintf(f
, "%02x %02x (%02x %04d) %16s: "
6218 op1
, op2
, op1
, op2
, handler
->oname
,
6219 handler
->count
, handler
->count
);
6223 if (handler
->count
== 0)
6225 cpu_fprintf(f
, "%02x (%02x ) %16s: %016llx %lld\n",
6226 op1
, op1
, handler
->oname
,
6227 handler
->count
, handler
->count
);
6233 /*****************************************************************************/
6234 static always_inline
void gen_intermediate_code_internal (CPUState
*env
,
6235 TranslationBlock
*tb
,
6238 DisasContext ctx
, *ctxp
= &ctx
;
6239 opc_handler_t
**table
, *handler
;
6240 target_ulong pc_start
;
6241 uint16_t *gen_opc_end
;
6242 int supervisor
, little_endian
;
6248 gen_opc_end
= gen_opc_buf
+ OPC_MAX_SIZE
;
6249 #if defined(OPTIMIZE_FPRF_UPDATE)
6250 gen_fprf_ptr
= gen_fprf_buf
;
6254 ctx
.exception
= POWERPC_EXCP_NONE
;
6255 ctx
.spr_cb
= env
->spr_cb
;
6256 supervisor
= env
->mmu_idx
;
6257 #if !defined(CONFIG_USER_ONLY)
6258 ctx
.supervisor
= supervisor
;
6260 little_endian
= env
->hflags
& (1 << MSR_LE
) ? 1 : 0;
6261 #if defined(TARGET_PPC64)
6262 ctx
.sf_mode
= msr_sf
;
6263 ctx
.mem_idx
= (supervisor
<< 2) | (msr_sf
<< 1) | little_endian
;
6265 ctx
.mem_idx
= (supervisor
<< 1) | little_endian
;
6267 ctx
.dcache_line_size
= env
->dcache_line_size
;
6268 ctx
.fpu_enabled
= msr_fp
;
6269 if ((env
->flags
& POWERPC_FLAG_SPE
) && msr_spe
)
6270 ctx
.spe_enabled
= msr_spe
;
6272 ctx
.spe_enabled
= 0;
6273 if ((env
->flags
& POWERPC_FLAG_VRE
) && msr_vr
)
6274 ctx
.altivec_enabled
= msr_vr
;
6276 ctx
.altivec_enabled
= 0;
6277 if ((env
->flags
& POWERPC_FLAG_SE
) && msr_se
)
6278 ctx
.singlestep_enabled
= CPU_SINGLE_STEP
;
6280 ctx
.singlestep_enabled
= 0;
6281 if ((env
->flags
& POWERPC_FLAG_BE
) && msr_be
)
6282 ctx
.singlestep_enabled
|= CPU_BRANCH_STEP
;
6283 if (unlikely(env
->singlestep_enabled
))
6284 ctx
.singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
6285 #if defined (DO_SINGLE_STEP) && 0
6286 /* Single step trace mode */
6290 max_insns
= tb
->cflags
& CF_COUNT_MASK
;
6292 max_insns
= CF_COUNT_MASK
;
6295 /* Set env in case of segfault during code fetch */
6296 while (ctx
.exception
== POWERPC_EXCP_NONE
&& gen_opc_ptr
< gen_opc_end
) {
6297 if (unlikely(env
->nb_breakpoints
> 0)) {
6298 for (j
= 0; j
< env
->nb_breakpoints
; j
++) {
6299 if (env
->breakpoints
[j
] == ctx
.nip
) {
6300 gen_update_nip(&ctx
, ctx
.nip
);
6306 if (unlikely(search_pc
)) {
6307 j
= gen_opc_ptr
- gen_opc_buf
;
6311 gen_opc_instr_start
[lj
++] = 0;
6312 gen_opc_pc
[lj
] = ctx
.nip
;
6313 gen_opc_instr_start
[lj
] = 1;
6314 gen_opc_icount
[lj
] = num_insns
;
6317 #if defined PPC_DEBUG_DISAS
6318 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
6319 fprintf(logfile
, "----------------\n");
6320 fprintf(logfile
, "nip=" ADDRX
" super=%d ir=%d\n",
6321 ctx
.nip
, supervisor
, (int)msr_ir
);
6324 if (num_insns
+ 1 == max_insns
&& (tb
->cflags
& CF_LAST_IO
))
6326 if (unlikely(little_endian
)) {
6327 ctx
.opcode
= bswap32(ldl_code(ctx
.nip
));
6329 ctx
.opcode
= ldl_code(ctx
.nip
);
6331 #if defined PPC_DEBUG_DISAS
6332 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
6333 fprintf(logfile
, "translate opcode %08x (%02x %02x %02x) (%s)\n",
6334 ctx
.opcode
, opc1(ctx
.opcode
), opc2(ctx
.opcode
),
6335 opc3(ctx
.opcode
), little_endian
? "little" : "big");
6339 table
= env
->opcodes
;
6341 handler
= table
[opc1(ctx
.opcode
)];
6342 if (is_indirect_opcode(handler
)) {
6343 table
= ind_table(handler
);
6344 handler
= table
[opc2(ctx
.opcode
)];
6345 if (is_indirect_opcode(handler
)) {
6346 table
= ind_table(handler
);
6347 handler
= table
[opc3(ctx
.opcode
)];
6350 /* Is opcode *REALLY* valid ? */
6351 if (unlikely(handler
->handler
== &gen_invalid
)) {
6352 if (loglevel
!= 0) {
6353 fprintf(logfile
, "invalid/unsupported opcode: "
6354 "%02x - %02x - %02x (%08x) " ADDRX
" %d\n",
6355 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
6356 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
6358 printf("invalid/unsupported opcode: "
6359 "%02x - %02x - %02x (%08x) " ADDRX
" %d\n",
6360 opc1(ctx
.opcode
), opc2(ctx
.opcode
),
6361 opc3(ctx
.opcode
), ctx
.opcode
, ctx
.nip
- 4, (int)msr_ir
);
6364 if (unlikely((ctx
.opcode
& handler
->inval
) != 0)) {
6365 if (loglevel
!= 0) {
6366 fprintf(logfile
, "invalid bits: %08x for opcode: "
6367 "%02x - %02x - %02x (%08x) " ADDRX
"\n",
6368 ctx
.opcode
& handler
->inval
, opc1(ctx
.opcode
),
6369 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
6370 ctx
.opcode
, ctx
.nip
- 4);
6372 printf("invalid bits: %08x for opcode: "
6373 "%02x - %02x - %02x (%08x) " ADDRX
"\n",
6374 ctx
.opcode
& handler
->inval
, opc1(ctx
.opcode
),
6375 opc2(ctx
.opcode
), opc3(ctx
.opcode
),
6376 ctx
.opcode
, ctx
.nip
- 4);
6378 GEN_EXCP_INVAL(ctxp
);
6382 (*(handler
->handler
))(&ctx
);
6383 #if defined(DO_PPC_STATISTICS)
6386 /* Check trace mode exceptions */
6387 if (unlikely(ctx
.singlestep_enabled
& CPU_SINGLE_STEP
&&
6388 (ctx
.nip
<= 0x100 || ctx
.nip
> 0xF00) &&
6389 ctx
.exception
!= POWERPC_SYSCALL
&&
6390 ctx
.exception
!= POWERPC_EXCP_TRAP
&&
6391 ctx
.exception
!= POWERPC_EXCP_BRANCH
)) {
6392 GEN_EXCP(ctxp
, POWERPC_EXCP_TRACE
, 0);
6393 } else if (unlikely(((ctx
.nip
& (TARGET_PAGE_SIZE
- 1)) == 0) ||
6394 (env
->singlestep_enabled
) ||
6395 num_insns
>= max_insns
)) {
6396 /* if we reach a page boundary or are single stepping, stop
6401 #if defined (DO_SINGLE_STEP)
6405 if (tb
->cflags
& CF_LAST_IO
)
6407 if (ctx
.exception
== POWERPC_EXCP_NONE
) {
6408 gen_goto_tb(&ctx
, 0, ctx
.nip
);
6409 } else if (ctx
.exception
!= POWERPC_EXCP_BRANCH
) {
6410 if (unlikely(env
->singlestep_enabled
)) {
6411 gen_update_nip(&ctx
, ctx
.nip
);
6414 /* Generate the return instruction */
6417 gen_icount_end(tb
, num_insns
);
6418 *gen_opc_ptr
= INDEX_op_end
;
6419 if (unlikely(search_pc
)) {
6420 j
= gen_opc_ptr
- gen_opc_buf
;
6423 gen_opc_instr_start
[lj
++] = 0;
6425 tb
->size
= ctx
.nip
- pc_start
;
6426 tb
->icount
= num_insns
;
6428 #if defined(DEBUG_DISAS)
6429 if (loglevel
& CPU_LOG_TB_CPU
) {
6430 fprintf(logfile
, "---------------- excp: %04x\n", ctx
.exception
);
6431 cpu_dump_state(env
, logfile
, fprintf
, 0);
6433 if (loglevel
& CPU_LOG_TB_IN_ASM
) {
6435 flags
= env
->bfd_mach
;
6436 flags
|= little_endian
<< 16;
6437 fprintf(logfile
, "IN: %s\n", lookup_symbol(pc_start
));
6438 target_disas(logfile
, pc_start
, ctx
.nip
- pc_start
, flags
);
6439 fprintf(logfile
, "\n");
6444 void gen_intermediate_code (CPUState
*env
, struct TranslationBlock
*tb
)
6446 gen_intermediate_code_internal(env
, tb
, 0);
6449 void gen_intermediate_code_pc (CPUState
*env
, struct TranslationBlock
*tb
)
6451 gen_intermediate_code_internal(env
, tb
, 1);
6454 void gen_pc_load(CPUState
*env
, TranslationBlock
*tb
,
6455 unsigned long searched_pc
, int pc_pos
, void *puc
)
6458 /* for PPC, we need to look at the micro operation to get the
6460 env
->nip
= gen_opc_pc
[pc_pos
];
6461 c
= gen_opc_buf
[pc_pos
];
6463 #if defined(CONFIG_USER_ONLY)
6465 case INDEX_op_ ## op ## _raw
6468 case INDEX_op_ ## op ## _user:\
6469 case INDEX_op_ ## op ## _kernel:\
6470 case INDEX_op_ ## op ## _hypv
6477 type
= ACCESS_FLOAT
;
6493 env
->access_type
= type
;