2 * PowerPC emulation for qemu: main translation routines.
4 * Copyright (c) 2003-2007 Jocelyn Mayer
5 * Copyright (C) 2011 Freescale Semiconductor, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
21 #include "qemu/osdep.h"
24 #include "disas/disas.h"
25 #include "exec/exec-all.h"
26 #include "tcg/tcg-op.h"
27 #include "tcg/tcg-op-gvec.h"
28 #include "qemu/host-utils.h"
29 #include "qemu/main-loop.h"
30 #include "exec/cpu_ldst.h"
32 #include "exec/helper-proto.h"
33 #include "exec/helper-gen.h"
35 #include "exec/translator.h"
37 #include "qemu/atomic128.h"
38 #include "spr_common.h"
39 #include "power8-pmu.h"
41 #include "qemu/qemu-print.h"
42 #include "qapi/error.h"
44 #define HELPER_H "helper.h"
45 #include "exec/helper-info.c.inc"
48 #define CPU_SINGLE_STEP 0x1
49 #define CPU_BRANCH_STEP 0x2
51 /* Include definitions for instructions classes and implementations flags */
52 /* #define PPC_DEBUG_DISAS */
54 #ifdef PPC_DEBUG_DISAS
55 # define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
57 # define LOG_DISAS(...) do { } while (0)
59 /*****************************************************************************/
60 /* Code translation helpers */
62 /* global register indexes */
63 static char cpu_reg_names
[10 * 3 + 22 * 4 /* GPR */
64 + 10 * 4 + 22 * 5 /* SPE GPRh */
66 static TCGv cpu_gpr
[32];
67 static TCGv cpu_gprh
[32];
68 static TCGv_i32 cpu_crf
[8];
73 #if defined(TARGET_PPC64)
76 static TCGv cpu_xer
, cpu_so
, cpu_ov
, cpu_ca
, cpu_ov32
, cpu_ca32
;
77 static TCGv cpu_reserve
;
78 static TCGv cpu_reserve_length
;
79 static TCGv cpu_reserve_val
;
80 static TCGv cpu_reserve_val2
;
81 static TCGv cpu_fpscr
;
82 static TCGv_i32 cpu_access_type
;
84 void ppc_translate_init(void)
88 size_t cpu_reg_names_size
;
91 cpu_reg_names_size
= sizeof(cpu_reg_names
);
93 for (i
= 0; i
< 8; i
++) {
94 snprintf(p
, cpu_reg_names_size
, "crf%d", i
);
95 cpu_crf
[i
] = tcg_global_mem_new_i32(cpu_env
,
96 offsetof(CPUPPCState
, crf
[i
]), p
);
98 cpu_reg_names_size
-= 5;
101 for (i
= 0; i
< 32; i
++) {
102 snprintf(p
, cpu_reg_names_size
, "r%d", i
);
103 cpu_gpr
[i
] = tcg_global_mem_new(cpu_env
,
104 offsetof(CPUPPCState
, gpr
[i
]), p
);
105 p
+= (i
< 10) ? 3 : 4;
106 cpu_reg_names_size
-= (i
< 10) ? 3 : 4;
107 snprintf(p
, cpu_reg_names_size
, "r%dH", i
);
108 cpu_gprh
[i
] = tcg_global_mem_new(cpu_env
,
109 offsetof(CPUPPCState
, gprh
[i
]), p
);
110 p
+= (i
< 10) ? 4 : 5;
111 cpu_reg_names_size
-= (i
< 10) ? 4 : 5;
114 cpu_nip
= tcg_global_mem_new(cpu_env
,
115 offsetof(CPUPPCState
, nip
), "nip");
117 cpu_msr
= tcg_global_mem_new(cpu_env
,
118 offsetof(CPUPPCState
, msr
), "msr");
120 cpu_ctr
= tcg_global_mem_new(cpu_env
,
121 offsetof(CPUPPCState
, ctr
), "ctr");
123 cpu_lr
= tcg_global_mem_new(cpu_env
,
124 offsetof(CPUPPCState
, lr
), "lr");
126 #if defined(TARGET_PPC64)
127 cpu_cfar
= tcg_global_mem_new(cpu_env
,
128 offsetof(CPUPPCState
, cfar
), "cfar");
131 cpu_xer
= tcg_global_mem_new(cpu_env
,
132 offsetof(CPUPPCState
, xer
), "xer");
133 cpu_so
= tcg_global_mem_new(cpu_env
,
134 offsetof(CPUPPCState
, so
), "SO");
135 cpu_ov
= tcg_global_mem_new(cpu_env
,
136 offsetof(CPUPPCState
, ov
), "OV");
137 cpu_ca
= tcg_global_mem_new(cpu_env
,
138 offsetof(CPUPPCState
, ca
), "CA");
139 cpu_ov32
= tcg_global_mem_new(cpu_env
,
140 offsetof(CPUPPCState
, ov32
), "OV32");
141 cpu_ca32
= tcg_global_mem_new(cpu_env
,
142 offsetof(CPUPPCState
, ca32
), "CA32");
144 cpu_reserve
= tcg_global_mem_new(cpu_env
,
145 offsetof(CPUPPCState
, reserve_addr
),
147 cpu_reserve_length
= tcg_global_mem_new(cpu_env
,
148 offsetof(CPUPPCState
,
151 cpu_reserve_val
= tcg_global_mem_new(cpu_env
,
152 offsetof(CPUPPCState
, reserve_val
),
154 cpu_reserve_val2
= tcg_global_mem_new(cpu_env
,
155 offsetof(CPUPPCState
, reserve_val2
),
158 cpu_fpscr
= tcg_global_mem_new(cpu_env
,
159 offsetof(CPUPPCState
, fpscr
), "fpscr");
161 cpu_access_type
= tcg_global_mem_new_i32(cpu_env
,
162 offsetof(CPUPPCState
, access_type
),
166 /* internal defines */
167 struct DisasContext
{
168 DisasContextBase base
;
169 target_ulong cia
; /* current instruction address */
171 /* Routine used to access memory */
172 bool pr
, hv
, dr
, le_mode
;
174 bool need_access_type
;
177 /* Translation flags */
178 MemOp default_tcg_memop_mask
;
179 #if defined(TARGET_PPC64)
184 bool altivec_enabled
;
195 ppc_spr_t
*spr_cb
; /* Needed to check rights for mfspr/mtspr */
196 int singlestep_enabled
;
198 uint64_t insns_flags
;
199 uint64_t insns_flags2
;
202 #define DISAS_EXIT DISAS_TARGET_0 /* exit to main loop, pc updated */
203 #define DISAS_EXIT_UPDATE DISAS_TARGET_1 /* exit to main loop, pc stale */
204 #define DISAS_CHAIN DISAS_TARGET_2 /* lookup next tb, pc updated */
205 #define DISAS_CHAIN_UPDATE DISAS_TARGET_3 /* lookup next tb, pc stale */
207 /* Return true iff byteswap is needed in a scalar memop */
208 static inline bool need_byteswap(const DisasContext
*ctx
)
210 #if TARGET_BIG_ENDIAN
213 return !ctx
->le_mode
;
217 /* True when active word size < size of target_long. */
219 # define NARROW_MODE(C) (!(C)->sf_mode)
221 # define NARROW_MODE(C) 0
224 struct opc_handler_t
{
225 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
227 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
229 /* instruction type */
231 /* extended instruction type */
234 void (*handler
)(DisasContext
*ctx
);
237 /* SPR load/store helpers */
238 static inline void gen_load_spr(TCGv t
, int reg
)
240 tcg_gen_ld_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
243 static inline void gen_store_spr(int reg
, TCGv t
)
245 tcg_gen_st_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
248 static inline void gen_set_access_type(DisasContext
*ctx
, int access_type
)
250 if (ctx
->need_access_type
&& ctx
->access_type
!= access_type
) {
251 tcg_gen_movi_i32(cpu_access_type
, access_type
);
252 ctx
->access_type
= access_type
;
256 static inline void gen_update_nip(DisasContext
*ctx
, target_ulong nip
)
258 if (NARROW_MODE(ctx
)) {
261 tcg_gen_movi_tl(cpu_nip
, nip
);
264 static void gen_exception_err(DisasContext
*ctx
, uint32_t excp
, uint32_t error
)
269 * These are all synchronous exceptions, we set the PC back to the
270 * faulting instruction
272 gen_update_nip(ctx
, ctx
->cia
);
273 t0
= tcg_constant_i32(excp
);
274 t1
= tcg_constant_i32(error
);
275 gen_helper_raise_exception_err(cpu_env
, t0
, t1
);
276 ctx
->base
.is_jmp
= DISAS_NORETURN
;
279 static void gen_exception(DisasContext
*ctx
, uint32_t excp
)
284 * These are all synchronous exceptions, we set the PC back to the
285 * faulting instruction
287 gen_update_nip(ctx
, ctx
->cia
);
288 t0
= tcg_constant_i32(excp
);
289 gen_helper_raise_exception(cpu_env
, t0
);
290 ctx
->base
.is_jmp
= DISAS_NORETURN
;
293 static void gen_exception_nip(DisasContext
*ctx
, uint32_t excp
,
298 gen_update_nip(ctx
, nip
);
299 t0
= tcg_constant_i32(excp
);
300 gen_helper_raise_exception(cpu_env
, t0
);
301 ctx
->base
.is_jmp
= DISAS_NORETURN
;
304 #if !defined(CONFIG_USER_ONLY)
305 static void gen_ppc_maybe_interrupt(DisasContext
*ctx
)
307 translator_io_start(&ctx
->base
);
308 gen_helper_ppc_maybe_interrupt(cpu_env
);
313 * Tells the caller what is the appropriate exception to generate and prepares
314 * SPR registers for this exception.
316 * The exception can be either POWERPC_EXCP_TRACE (on most PowerPCs) or
317 * POWERPC_EXCP_DEBUG (on BookE).
319 static uint32_t gen_prep_dbgex(DisasContext
*ctx
)
321 if (ctx
->flags
& POWERPC_FLAG_DE
) {
322 target_ulong dbsr
= 0;
323 if (ctx
->singlestep_enabled
& CPU_SINGLE_STEP
) {
326 /* Must have been branch */
329 TCGv t0
= tcg_temp_new();
330 gen_load_spr(t0
, SPR_BOOKE_DBSR
);
331 tcg_gen_ori_tl(t0
, t0
, dbsr
);
332 gen_store_spr(SPR_BOOKE_DBSR
, t0
);
333 return POWERPC_EXCP_DEBUG
;
335 return POWERPC_EXCP_TRACE
;
339 static void gen_debug_exception(DisasContext
*ctx
)
341 gen_helper_raise_exception(cpu_env
, tcg_constant_i32(gen_prep_dbgex(ctx
)));
342 ctx
->base
.is_jmp
= DISAS_NORETURN
;
345 static inline void gen_inval_exception(DisasContext
*ctx
, uint32_t error
)
347 /* Will be converted to program check if needed */
348 gen_exception_err(ctx
, POWERPC_EXCP_HV_EMU
, POWERPC_EXCP_INVAL
| error
);
351 static inline void gen_priv_exception(DisasContext
*ctx
, uint32_t error
)
353 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_PRIV
| error
);
356 static inline void gen_hvpriv_exception(DisasContext
*ctx
, uint32_t error
)
358 /* Will be converted to program check if needed */
359 gen_exception_err(ctx
, POWERPC_EXCP_HV_EMU
, POWERPC_EXCP_PRIV
| error
);
362 /*****************************************************************************/
363 /* SPR READ/WRITE CALLBACKS */
365 void spr_noaccess(DisasContext
*ctx
, int gprn
, int sprn
)
368 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
369 printf("ERROR: try to access SPR %d !\n", sprn
);
373 /* #define PPC_DUMP_SPR_ACCESSES */
377 * do nothing but store/retrieve spr value
379 static void spr_load_dump_spr(int sprn
)
381 #ifdef PPC_DUMP_SPR_ACCESSES
382 TCGv_i32 t0
= tcg_constant_i32(sprn
);
383 gen_helper_load_dump_spr(cpu_env
, t0
);
387 void spr_read_generic(DisasContext
*ctx
, int gprn
, int sprn
)
389 gen_load_spr(cpu_gpr
[gprn
], sprn
);
390 spr_load_dump_spr(sprn
);
393 static void spr_store_dump_spr(int sprn
)
395 #ifdef PPC_DUMP_SPR_ACCESSES
396 TCGv_i32 t0
= tcg_constant_i32(sprn
);
397 gen_helper_store_dump_spr(cpu_env
, t0
);
401 void spr_write_generic(DisasContext
*ctx
, int sprn
, int gprn
)
403 gen_store_spr(sprn
, cpu_gpr
[gprn
]);
404 spr_store_dump_spr(sprn
);
407 void spr_write_generic32(DisasContext
*ctx
, int sprn
, int gprn
)
410 TCGv t0
= tcg_temp_new();
411 tcg_gen_ext32u_tl(t0
, cpu_gpr
[gprn
]);
412 gen_store_spr(sprn
, t0
);
413 spr_store_dump_spr(sprn
);
415 spr_write_generic(ctx
, sprn
, gprn
);
419 void spr_write_CTRL(DisasContext
*ctx
, int sprn
, int gprn
)
421 spr_write_generic32(ctx
, sprn
, gprn
);
424 * SPR_CTRL writes must force a new translation block,
425 * allowing the PMU to calculate the run latch events with
428 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
431 #if !defined(CONFIG_USER_ONLY)
432 void spr_write_clear(DisasContext
*ctx
, int sprn
, int gprn
)
434 TCGv t0
= tcg_temp_new();
435 TCGv t1
= tcg_temp_new();
436 gen_load_spr(t0
, sprn
);
437 tcg_gen_neg_tl(t1
, cpu_gpr
[gprn
]);
438 tcg_gen_and_tl(t0
, t0
, t1
);
439 gen_store_spr(sprn
, t0
);
442 void spr_access_nop(DisasContext
*ctx
, int sprn
, int gprn
)
448 /* SPR common to all PowerPC */
450 void spr_read_xer(DisasContext
*ctx
, int gprn
, int sprn
)
452 TCGv dst
= cpu_gpr
[gprn
];
453 TCGv t0
= tcg_temp_new();
454 TCGv t1
= tcg_temp_new();
455 TCGv t2
= tcg_temp_new();
456 tcg_gen_mov_tl(dst
, cpu_xer
);
457 tcg_gen_shli_tl(t0
, cpu_so
, XER_SO
);
458 tcg_gen_shli_tl(t1
, cpu_ov
, XER_OV
);
459 tcg_gen_shli_tl(t2
, cpu_ca
, XER_CA
);
460 tcg_gen_or_tl(t0
, t0
, t1
);
461 tcg_gen_or_tl(dst
, dst
, t2
);
462 tcg_gen_or_tl(dst
, dst
, t0
);
463 if (is_isa300(ctx
)) {
464 tcg_gen_shli_tl(t0
, cpu_ov32
, XER_OV32
);
465 tcg_gen_or_tl(dst
, dst
, t0
);
466 tcg_gen_shli_tl(t0
, cpu_ca32
, XER_CA32
);
467 tcg_gen_or_tl(dst
, dst
, t0
);
471 void spr_write_xer(DisasContext
*ctx
, int sprn
, int gprn
)
473 TCGv src
= cpu_gpr
[gprn
];
474 /* Write all flags, while reading back check for isa300 */
475 tcg_gen_andi_tl(cpu_xer
, src
,
477 (1u << XER_OV
) | (1u << XER_OV32
) |
478 (1u << XER_CA
) | (1u << XER_CA32
)));
479 tcg_gen_extract_tl(cpu_ov32
, src
, XER_OV32
, 1);
480 tcg_gen_extract_tl(cpu_ca32
, src
, XER_CA32
, 1);
481 tcg_gen_extract_tl(cpu_so
, src
, XER_SO
, 1);
482 tcg_gen_extract_tl(cpu_ov
, src
, XER_OV
, 1);
483 tcg_gen_extract_tl(cpu_ca
, src
, XER_CA
, 1);
487 void spr_read_lr(DisasContext
*ctx
, int gprn
, int sprn
)
489 tcg_gen_mov_tl(cpu_gpr
[gprn
], cpu_lr
);
492 void spr_write_lr(DisasContext
*ctx
, int sprn
, int gprn
)
494 tcg_gen_mov_tl(cpu_lr
, cpu_gpr
[gprn
]);
498 #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY)
499 void spr_read_cfar(DisasContext
*ctx
, int gprn
, int sprn
)
501 tcg_gen_mov_tl(cpu_gpr
[gprn
], cpu_cfar
);
504 void spr_write_cfar(DisasContext
*ctx
, int sprn
, int gprn
)
506 tcg_gen_mov_tl(cpu_cfar
, cpu_gpr
[gprn
]);
508 #endif /* defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY) */
511 void spr_read_ctr(DisasContext
*ctx
, int gprn
, int sprn
)
513 tcg_gen_mov_tl(cpu_gpr
[gprn
], cpu_ctr
);
516 void spr_write_ctr(DisasContext
*ctx
, int sprn
, int gprn
)
518 tcg_gen_mov_tl(cpu_ctr
, cpu_gpr
[gprn
]);
521 /* User read access to SPR */
527 void spr_read_ureg(DisasContext
*ctx
, int gprn
, int sprn
)
529 gen_load_spr(cpu_gpr
[gprn
], sprn
+ 0x10);
532 #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY)
533 void spr_write_ureg(DisasContext
*ctx
, int sprn
, int gprn
)
535 gen_store_spr(sprn
+ 0x10, cpu_gpr
[gprn
]);
539 /* SPR common to all non-embedded PowerPC */
541 #if !defined(CONFIG_USER_ONLY)
542 void spr_read_decr(DisasContext
*ctx
, int gprn
, int sprn
)
544 translator_io_start(&ctx
->base
);
545 gen_helper_load_decr(cpu_gpr
[gprn
], cpu_env
);
548 void spr_write_decr(DisasContext
*ctx
, int sprn
, int gprn
)
550 translator_io_start(&ctx
->base
);
551 gen_helper_store_decr(cpu_env
, cpu_gpr
[gprn
]);
555 /* SPR common to all non-embedded PowerPC, except 601 */
557 void spr_read_tbl(DisasContext
*ctx
, int gprn
, int sprn
)
559 translator_io_start(&ctx
->base
);
560 gen_helper_load_tbl(cpu_gpr
[gprn
], cpu_env
);
563 void spr_read_tbu(DisasContext
*ctx
, int gprn
, int sprn
)
565 translator_io_start(&ctx
->base
);
566 gen_helper_load_tbu(cpu_gpr
[gprn
], cpu_env
);
569 void spr_read_atbl(DisasContext
*ctx
, int gprn
, int sprn
)
571 gen_helper_load_atbl(cpu_gpr
[gprn
], cpu_env
);
574 void spr_read_atbu(DisasContext
*ctx
, int gprn
, int sprn
)
576 gen_helper_load_atbu(cpu_gpr
[gprn
], cpu_env
);
579 #if !defined(CONFIG_USER_ONLY)
580 void spr_write_tbl(DisasContext
*ctx
, int sprn
, int gprn
)
582 translator_io_start(&ctx
->base
);
583 gen_helper_store_tbl(cpu_env
, cpu_gpr
[gprn
]);
586 void spr_write_tbu(DisasContext
*ctx
, int sprn
, int gprn
)
588 translator_io_start(&ctx
->base
);
589 gen_helper_store_tbu(cpu_env
, cpu_gpr
[gprn
]);
592 void spr_write_atbl(DisasContext
*ctx
, int sprn
, int gprn
)
594 gen_helper_store_atbl(cpu_env
, cpu_gpr
[gprn
]);
597 void spr_write_atbu(DisasContext
*ctx
, int sprn
, int gprn
)
599 gen_helper_store_atbu(cpu_env
, cpu_gpr
[gprn
]);
602 #if defined(TARGET_PPC64)
603 void spr_read_purr(DisasContext
*ctx
, int gprn
, int sprn
)
605 translator_io_start(&ctx
->base
);
606 gen_helper_load_purr(cpu_gpr
[gprn
], cpu_env
);
609 void spr_write_purr(DisasContext
*ctx
, int sprn
, int gprn
)
611 translator_io_start(&ctx
->base
);
612 gen_helper_store_purr(cpu_env
, cpu_gpr
[gprn
]);
616 void spr_read_hdecr(DisasContext
*ctx
, int gprn
, int sprn
)
618 translator_io_start(&ctx
->base
);
619 gen_helper_load_hdecr(cpu_gpr
[gprn
], cpu_env
);
622 void spr_write_hdecr(DisasContext
*ctx
, int sprn
, int gprn
)
624 translator_io_start(&ctx
->base
);
625 gen_helper_store_hdecr(cpu_env
, cpu_gpr
[gprn
]);
628 void spr_read_vtb(DisasContext
*ctx
, int gprn
, int sprn
)
630 translator_io_start(&ctx
->base
);
631 gen_helper_load_vtb(cpu_gpr
[gprn
], cpu_env
);
634 void spr_write_vtb(DisasContext
*ctx
, int sprn
, int gprn
)
636 translator_io_start(&ctx
->base
);
637 gen_helper_store_vtb(cpu_env
, cpu_gpr
[gprn
]);
640 void spr_write_tbu40(DisasContext
*ctx
, int sprn
, int gprn
)
642 translator_io_start(&ctx
->base
);
643 gen_helper_store_tbu40(cpu_env
, cpu_gpr
[gprn
]);
649 #if !defined(CONFIG_USER_ONLY)
650 /* IBAT0U...IBAT0U */
651 /* IBAT0L...IBAT7L */
652 void spr_read_ibat(DisasContext
*ctx
, int gprn
, int sprn
)
654 tcg_gen_ld_tl(cpu_gpr
[gprn
], cpu_env
,
655 offsetof(CPUPPCState
,
656 IBAT
[sprn
& 1][(sprn
- SPR_IBAT0U
) / 2]));
659 void spr_read_ibat_h(DisasContext
*ctx
, int gprn
, int sprn
)
661 tcg_gen_ld_tl(cpu_gpr
[gprn
], cpu_env
,
662 offsetof(CPUPPCState
,
663 IBAT
[sprn
& 1][((sprn
- SPR_IBAT4U
) / 2) + 4]));
666 void spr_write_ibatu(DisasContext
*ctx
, int sprn
, int gprn
)
668 TCGv_i32 t0
= tcg_constant_i32((sprn
- SPR_IBAT0U
) / 2);
669 gen_helper_store_ibatu(cpu_env
, t0
, cpu_gpr
[gprn
]);
672 void spr_write_ibatu_h(DisasContext
*ctx
, int sprn
, int gprn
)
674 TCGv_i32 t0
= tcg_constant_i32(((sprn
- SPR_IBAT4U
) / 2) + 4);
675 gen_helper_store_ibatu(cpu_env
, t0
, cpu_gpr
[gprn
]);
678 void spr_write_ibatl(DisasContext
*ctx
, int sprn
, int gprn
)
680 TCGv_i32 t0
= tcg_constant_i32((sprn
- SPR_IBAT0L
) / 2);
681 gen_helper_store_ibatl(cpu_env
, t0
, cpu_gpr
[gprn
]);
684 void spr_write_ibatl_h(DisasContext
*ctx
, int sprn
, int gprn
)
686 TCGv_i32 t0
= tcg_constant_i32(((sprn
- SPR_IBAT4L
) / 2) + 4);
687 gen_helper_store_ibatl(cpu_env
, t0
, cpu_gpr
[gprn
]);
690 /* DBAT0U...DBAT7U */
691 /* DBAT0L...DBAT7L */
692 void spr_read_dbat(DisasContext
*ctx
, int gprn
, int sprn
)
694 tcg_gen_ld_tl(cpu_gpr
[gprn
], cpu_env
,
695 offsetof(CPUPPCState
,
696 DBAT
[sprn
& 1][(sprn
- SPR_DBAT0U
) / 2]));
699 void spr_read_dbat_h(DisasContext
*ctx
, int gprn
, int sprn
)
701 tcg_gen_ld_tl(cpu_gpr
[gprn
], cpu_env
,
702 offsetof(CPUPPCState
,
703 DBAT
[sprn
& 1][((sprn
- SPR_DBAT4U
) / 2) + 4]));
706 void spr_write_dbatu(DisasContext
*ctx
, int sprn
, int gprn
)
708 TCGv_i32 t0
= tcg_constant_i32((sprn
- SPR_DBAT0U
) / 2);
709 gen_helper_store_dbatu(cpu_env
, t0
, cpu_gpr
[gprn
]);
712 void spr_write_dbatu_h(DisasContext
*ctx
, int sprn
, int gprn
)
714 TCGv_i32 t0
= tcg_constant_i32(((sprn
- SPR_DBAT4U
) / 2) + 4);
715 gen_helper_store_dbatu(cpu_env
, t0
, cpu_gpr
[gprn
]);
718 void spr_write_dbatl(DisasContext
*ctx
, int sprn
, int gprn
)
720 TCGv_i32 t0
= tcg_constant_i32((sprn
- SPR_DBAT0L
) / 2);
721 gen_helper_store_dbatl(cpu_env
, t0
, cpu_gpr
[gprn
]);
724 void spr_write_dbatl_h(DisasContext
*ctx
, int sprn
, int gprn
)
726 TCGv_i32 t0
= tcg_constant_i32(((sprn
- SPR_DBAT4L
) / 2) + 4);
727 gen_helper_store_dbatl(cpu_env
, t0
, cpu_gpr
[gprn
]);
731 void spr_write_sdr1(DisasContext
*ctx
, int sprn
, int gprn
)
733 gen_helper_store_sdr1(cpu_env
, cpu_gpr
[gprn
]);
736 #if defined(TARGET_PPC64)
737 /* 64 bits PowerPC specific SPRs */
739 void spr_write_pidr(DisasContext
*ctx
, int sprn
, int gprn
)
741 gen_helper_store_pidr(cpu_env
, cpu_gpr
[gprn
]);
744 void spr_write_lpidr(DisasContext
*ctx
, int sprn
, int gprn
)
746 gen_helper_store_lpidr(cpu_env
, cpu_gpr
[gprn
]);
749 void spr_read_hior(DisasContext
*ctx
, int gprn
, int sprn
)
751 tcg_gen_ld_tl(cpu_gpr
[gprn
], cpu_env
, offsetof(CPUPPCState
, excp_prefix
));
754 void spr_write_hior(DisasContext
*ctx
, int sprn
, int gprn
)
756 TCGv t0
= tcg_temp_new();
757 tcg_gen_andi_tl(t0
, cpu_gpr
[gprn
], 0x3FFFFF00000ULL
);
758 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, excp_prefix
));
760 void spr_write_ptcr(DisasContext
*ctx
, int sprn
, int gprn
)
762 gen_helper_store_ptcr(cpu_env
, cpu_gpr
[gprn
]);
765 void spr_write_pcr(DisasContext
*ctx
, int sprn
, int gprn
)
767 gen_helper_store_pcr(cpu_env
, cpu_gpr
[gprn
]);
771 void spr_read_dpdes(DisasContext
*ctx
, int gprn
, int sprn
)
773 gen_helper_load_dpdes(cpu_gpr
[gprn
], cpu_env
);
776 void spr_write_dpdes(DisasContext
*ctx
, int sprn
, int gprn
)
778 gen_helper_store_dpdes(cpu_env
, cpu_gpr
[gprn
]);
783 /* PowerPC 40x specific registers */
784 #if !defined(CONFIG_USER_ONLY)
785 void spr_read_40x_pit(DisasContext
*ctx
, int gprn
, int sprn
)
787 translator_io_start(&ctx
->base
);
788 gen_helper_load_40x_pit(cpu_gpr
[gprn
], cpu_env
);
791 void spr_write_40x_pit(DisasContext
*ctx
, int sprn
, int gprn
)
793 translator_io_start(&ctx
->base
);
794 gen_helper_store_40x_pit(cpu_env
, cpu_gpr
[gprn
]);
797 void spr_write_40x_dbcr0(DisasContext
*ctx
, int sprn
, int gprn
)
799 translator_io_start(&ctx
->base
);
800 gen_store_spr(sprn
, cpu_gpr
[gprn
]);
801 gen_helper_store_40x_dbcr0(cpu_env
, cpu_gpr
[gprn
]);
802 /* We must stop translation as we may have rebooted */
803 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
806 void spr_write_40x_sler(DisasContext
*ctx
, int sprn
, int gprn
)
808 translator_io_start(&ctx
->base
);
809 gen_helper_store_40x_sler(cpu_env
, cpu_gpr
[gprn
]);
812 void spr_write_40x_tcr(DisasContext
*ctx
, int sprn
, int gprn
)
814 translator_io_start(&ctx
->base
);
815 gen_helper_store_40x_tcr(cpu_env
, cpu_gpr
[gprn
]);
818 void spr_write_40x_tsr(DisasContext
*ctx
, int sprn
, int gprn
)
820 translator_io_start(&ctx
->base
);
821 gen_helper_store_40x_tsr(cpu_env
, cpu_gpr
[gprn
]);
824 void spr_write_40x_pid(DisasContext
*ctx
, int sprn
, int gprn
)
826 TCGv t0
= tcg_temp_new();
827 tcg_gen_andi_tl(t0
, cpu_gpr
[gprn
], 0xFF);
828 gen_helper_store_40x_pid(cpu_env
, t0
);
831 void spr_write_booke_tcr(DisasContext
*ctx
, int sprn
, int gprn
)
833 translator_io_start(&ctx
->base
);
834 gen_helper_store_booke_tcr(cpu_env
, cpu_gpr
[gprn
]);
837 void spr_write_booke_tsr(DisasContext
*ctx
, int sprn
, int gprn
)
839 translator_io_start(&ctx
->base
);
840 gen_helper_store_booke_tsr(cpu_env
, cpu_gpr
[gprn
]);
845 #if !defined(CONFIG_USER_ONLY)
846 void spr_write_pir(DisasContext
*ctx
, int sprn
, int gprn
)
848 TCGv t0
= tcg_temp_new();
849 tcg_gen_andi_tl(t0
, cpu_gpr
[gprn
], 0xF);
850 gen_store_spr(SPR_PIR
, t0
);
854 /* SPE specific registers */
855 void spr_read_spefscr(DisasContext
*ctx
, int gprn
, int sprn
)
857 TCGv_i32 t0
= tcg_temp_new_i32();
858 tcg_gen_ld_i32(t0
, cpu_env
, offsetof(CPUPPCState
, spe_fscr
));
859 tcg_gen_extu_i32_tl(cpu_gpr
[gprn
], t0
);
862 void spr_write_spefscr(DisasContext
*ctx
, int sprn
, int gprn
)
864 TCGv_i32 t0
= tcg_temp_new_i32();
865 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[gprn
]);
866 tcg_gen_st_i32(t0
, cpu_env
, offsetof(CPUPPCState
, spe_fscr
));
869 #if !defined(CONFIG_USER_ONLY)
870 /* Callback used to write the exception vector base */
871 void spr_write_excp_prefix(DisasContext
*ctx
, int sprn
, int gprn
)
873 TCGv t0
= tcg_temp_new();
874 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUPPCState
, ivpr_mask
));
875 tcg_gen_and_tl(t0
, t0
, cpu_gpr
[gprn
]);
876 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, excp_prefix
));
877 gen_store_spr(sprn
, t0
);
880 void spr_write_excp_vector(DisasContext
*ctx
, int sprn
, int gprn
)
884 if (sprn
>= SPR_BOOKE_IVOR0
&& sprn
<= SPR_BOOKE_IVOR15
) {
885 sprn_offs
= sprn
- SPR_BOOKE_IVOR0
;
886 } else if (sprn
>= SPR_BOOKE_IVOR32
&& sprn
<= SPR_BOOKE_IVOR37
) {
887 sprn_offs
= sprn
- SPR_BOOKE_IVOR32
+ 32;
888 } else if (sprn
>= SPR_BOOKE_IVOR38
&& sprn
<= SPR_BOOKE_IVOR42
) {
889 sprn_offs
= sprn
- SPR_BOOKE_IVOR38
+ 38;
891 qemu_log_mask(LOG_GUEST_ERROR
, "Trying to write an unknown exception"
892 " vector 0x%03x\n", sprn
);
893 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
897 TCGv t0
= tcg_temp_new();
898 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUPPCState
, ivor_mask
));
899 tcg_gen_and_tl(t0
, t0
, cpu_gpr
[gprn
]);
900 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, excp_vectors
[sprn_offs
]));
901 gen_store_spr(sprn
, t0
);
906 #ifndef CONFIG_USER_ONLY
907 void spr_write_amr(DisasContext
*ctx
, int sprn
, int gprn
)
909 TCGv t0
= tcg_temp_new();
910 TCGv t1
= tcg_temp_new();
911 TCGv t2
= tcg_temp_new();
914 * Note, the HV=1 PR=0 case is handled earlier by simply using
915 * spr_write_generic for HV mode in the SPR table
918 /* Build insertion mask into t1 based on context */
920 gen_load_spr(t1
, SPR_UAMOR
);
922 gen_load_spr(t1
, SPR_AMOR
);
925 /* Mask new bits into t2 */
926 tcg_gen_and_tl(t2
, t1
, cpu_gpr
[gprn
]);
928 /* Load AMR and clear new bits in t0 */
929 gen_load_spr(t0
, SPR_AMR
);
930 tcg_gen_andc_tl(t0
, t0
, t1
);
932 /* Or'in new bits and write it out */
933 tcg_gen_or_tl(t0
, t0
, t2
);
934 gen_store_spr(SPR_AMR
, t0
);
935 spr_store_dump_spr(SPR_AMR
);
938 void spr_write_uamor(DisasContext
*ctx
, int sprn
, int gprn
)
940 TCGv t0
= tcg_temp_new();
941 TCGv t1
= tcg_temp_new();
942 TCGv t2
= tcg_temp_new();
945 * Note, the HV=1 case is handled earlier by simply using
946 * spr_write_generic for HV mode in the SPR table
949 /* Build insertion mask into t1 based on context */
950 gen_load_spr(t1
, SPR_AMOR
);
952 /* Mask new bits into t2 */
953 tcg_gen_and_tl(t2
, t1
, cpu_gpr
[gprn
]);
955 /* Load AMR and clear new bits in t0 */
956 gen_load_spr(t0
, SPR_UAMOR
);
957 tcg_gen_andc_tl(t0
, t0
, t1
);
959 /* Or'in new bits and write it out */
960 tcg_gen_or_tl(t0
, t0
, t2
);
961 gen_store_spr(SPR_UAMOR
, t0
);
962 spr_store_dump_spr(SPR_UAMOR
);
965 void spr_write_iamr(DisasContext
*ctx
, int sprn
, int gprn
)
967 TCGv t0
= tcg_temp_new();
968 TCGv t1
= tcg_temp_new();
969 TCGv t2
= tcg_temp_new();
972 * Note, the HV=1 case is handled earlier by simply using
973 * spr_write_generic for HV mode in the SPR table
976 /* Build insertion mask into t1 based on context */
977 gen_load_spr(t1
, SPR_AMOR
);
979 /* Mask new bits into t2 */
980 tcg_gen_and_tl(t2
, t1
, cpu_gpr
[gprn
]);
982 /* Load AMR and clear new bits in t0 */
983 gen_load_spr(t0
, SPR_IAMR
);
984 tcg_gen_andc_tl(t0
, t0
, t1
);
986 /* Or'in new bits and write it out */
987 tcg_gen_or_tl(t0
, t0
, t2
);
988 gen_store_spr(SPR_IAMR
, t0
);
989 spr_store_dump_spr(SPR_IAMR
);
994 #ifndef CONFIG_USER_ONLY
995 void spr_read_thrm(DisasContext
*ctx
, int gprn
, int sprn
)
997 gen_helper_fixup_thrm(cpu_env
);
998 gen_load_spr(cpu_gpr
[gprn
], sprn
);
999 spr_load_dump_spr(sprn
);
1001 #endif /* !CONFIG_USER_ONLY */
1003 #if !defined(CONFIG_USER_ONLY)
1004 void spr_write_e500_l1csr0(DisasContext
*ctx
, int sprn
, int gprn
)
1006 TCGv t0
= tcg_temp_new();
1008 tcg_gen_andi_tl(t0
, cpu_gpr
[gprn
], L1CSR0_DCE
| L1CSR0_CPE
);
1009 gen_store_spr(sprn
, t0
);
1012 void spr_write_e500_l1csr1(DisasContext
*ctx
, int sprn
, int gprn
)
1014 TCGv t0
= tcg_temp_new();
1016 tcg_gen_andi_tl(t0
, cpu_gpr
[gprn
], L1CSR1_ICE
| L1CSR1_CPE
);
1017 gen_store_spr(sprn
, t0
);
1020 void spr_write_e500_l2csr0(DisasContext
*ctx
, int sprn
, int gprn
)
1022 TCGv t0
= tcg_temp_new();
1024 tcg_gen_andi_tl(t0
, cpu_gpr
[gprn
],
1025 ~(E500_L2CSR0_L2FI
| E500_L2CSR0_L2FL
| E500_L2CSR0_L2LFC
));
1026 gen_store_spr(sprn
, t0
);
1029 void spr_write_booke206_mmucsr0(DisasContext
*ctx
, int sprn
, int gprn
)
1031 gen_helper_booke206_tlbflush(cpu_env
, cpu_gpr
[gprn
]);
1034 void spr_write_booke_pid(DisasContext
*ctx
, int sprn
, int gprn
)
1036 TCGv_i32 t0
= tcg_constant_i32(sprn
);
1037 gen_helper_booke_setpid(cpu_env
, t0
, cpu_gpr
[gprn
]);
1040 void spr_write_eplc(DisasContext
*ctx
, int sprn
, int gprn
)
1042 gen_helper_booke_set_eplc(cpu_env
, cpu_gpr
[gprn
]);
1045 void spr_write_epsc(DisasContext
*ctx
, int sprn
, int gprn
)
1047 gen_helper_booke_set_epsc(cpu_env
, cpu_gpr
[gprn
]);
1052 #if !defined(CONFIG_USER_ONLY)
1053 void spr_write_mas73(DisasContext
*ctx
, int sprn
, int gprn
)
1055 TCGv val
= tcg_temp_new();
1056 tcg_gen_ext32u_tl(val
, cpu_gpr
[gprn
]);
1057 gen_store_spr(SPR_BOOKE_MAS3
, val
);
1058 tcg_gen_shri_tl(val
, cpu_gpr
[gprn
], 32);
1059 gen_store_spr(SPR_BOOKE_MAS7
, val
);
1062 void spr_read_mas73(DisasContext
*ctx
, int gprn
, int sprn
)
1064 TCGv mas7
= tcg_temp_new();
1065 TCGv mas3
= tcg_temp_new();
1066 gen_load_spr(mas7
, SPR_BOOKE_MAS7
);
1067 tcg_gen_shli_tl(mas7
, mas7
, 32);
1068 gen_load_spr(mas3
, SPR_BOOKE_MAS3
);
1069 tcg_gen_or_tl(cpu_gpr
[gprn
], mas3
, mas7
);
1075 static void gen_fscr_facility_check(DisasContext
*ctx
, int facility_sprn
,
1076 int bit
, int sprn
, int cause
)
1078 TCGv_i32 t1
= tcg_constant_i32(bit
);
1079 TCGv_i32 t2
= tcg_constant_i32(sprn
);
1080 TCGv_i32 t3
= tcg_constant_i32(cause
);
1082 gen_helper_fscr_facility_check(cpu_env
, t1
, t2
, t3
);
1085 static void gen_msr_facility_check(DisasContext
*ctx
, int facility_sprn
,
1086 int bit
, int sprn
, int cause
)
1088 TCGv_i32 t1
= tcg_constant_i32(bit
);
1089 TCGv_i32 t2
= tcg_constant_i32(sprn
);
1090 TCGv_i32 t3
= tcg_constant_i32(cause
);
1092 gen_helper_msr_facility_check(cpu_env
, t1
, t2
, t3
);
1095 void spr_read_prev_upper32(DisasContext
*ctx
, int gprn
, int sprn
)
1097 TCGv spr_up
= tcg_temp_new();
1098 TCGv spr
= tcg_temp_new();
1100 gen_load_spr(spr
, sprn
- 1);
1101 tcg_gen_shri_tl(spr_up
, spr
, 32);
1102 tcg_gen_ext32u_tl(cpu_gpr
[gprn
], spr_up
);
1105 void spr_write_prev_upper32(DisasContext
*ctx
, int sprn
, int gprn
)
1107 TCGv spr
= tcg_temp_new();
1109 gen_load_spr(spr
, sprn
- 1);
1110 tcg_gen_deposit_tl(spr
, spr
, cpu_gpr
[gprn
], 32, 32);
1111 gen_store_spr(sprn
- 1, spr
);
1114 #if !defined(CONFIG_USER_ONLY)
1115 void spr_write_hmer(DisasContext
*ctx
, int sprn
, int gprn
)
1117 TCGv hmer
= tcg_temp_new();
1119 gen_load_spr(hmer
, sprn
);
1120 tcg_gen_and_tl(hmer
, cpu_gpr
[gprn
], hmer
);
1121 gen_store_spr(sprn
, hmer
);
1122 spr_store_dump_spr(sprn
);
1125 void spr_write_lpcr(DisasContext
*ctx
, int sprn
, int gprn
)
1127 gen_helper_store_lpcr(cpu_env
, cpu_gpr
[gprn
]);
1129 #endif /* !defined(CONFIG_USER_ONLY) */
1131 void spr_read_tar(DisasContext
*ctx
, int gprn
, int sprn
)
1133 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_TAR
, sprn
, FSCR_IC_TAR
);
1134 spr_read_generic(ctx
, gprn
, sprn
);
1137 void spr_write_tar(DisasContext
*ctx
, int sprn
, int gprn
)
1139 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_TAR
, sprn
, FSCR_IC_TAR
);
1140 spr_write_generic(ctx
, sprn
, gprn
);
1143 void spr_read_tm(DisasContext
*ctx
, int gprn
, int sprn
)
1145 gen_msr_facility_check(ctx
, SPR_FSCR
, MSR_TM
, sprn
, FSCR_IC_TM
);
1146 spr_read_generic(ctx
, gprn
, sprn
);
1149 void spr_write_tm(DisasContext
*ctx
, int sprn
, int gprn
)
1151 gen_msr_facility_check(ctx
, SPR_FSCR
, MSR_TM
, sprn
, FSCR_IC_TM
);
1152 spr_write_generic(ctx
, sprn
, gprn
);
1155 void spr_read_tm_upper32(DisasContext
*ctx
, int gprn
, int sprn
)
1157 gen_msr_facility_check(ctx
, SPR_FSCR
, MSR_TM
, sprn
, FSCR_IC_TM
);
1158 spr_read_prev_upper32(ctx
, gprn
, sprn
);
1161 void spr_write_tm_upper32(DisasContext
*ctx
, int sprn
, int gprn
)
1163 gen_msr_facility_check(ctx
, SPR_FSCR
, MSR_TM
, sprn
, FSCR_IC_TM
);
1164 spr_write_prev_upper32(ctx
, sprn
, gprn
);
1167 void spr_read_ebb(DisasContext
*ctx
, int gprn
, int sprn
)
1169 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_EBB
, sprn
, FSCR_IC_EBB
);
1170 spr_read_generic(ctx
, gprn
, sprn
);
1173 void spr_write_ebb(DisasContext
*ctx
, int sprn
, int gprn
)
1175 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_EBB
, sprn
, FSCR_IC_EBB
);
1176 spr_write_generic(ctx
, sprn
, gprn
);
1179 void spr_read_ebb_upper32(DisasContext
*ctx
, int gprn
, int sprn
)
1181 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_EBB
, sprn
, FSCR_IC_EBB
);
1182 spr_read_prev_upper32(ctx
, gprn
, sprn
);
1185 void spr_write_ebb_upper32(DisasContext
*ctx
, int sprn
, int gprn
)
1187 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_EBB
, sprn
, FSCR_IC_EBB
);
1188 spr_write_prev_upper32(ctx
, sprn
, gprn
);
1191 void spr_read_dexcr_ureg(DisasContext
*ctx
, int gprn
, int sprn
)
1193 TCGv t0
= tcg_temp_new();
1196 * Access to the (H)DEXCR in problem state is done using separated
1197 * SPR indexes which are 16 below the SPR indexes which have full
1198 * access to the (H)DEXCR in privileged state. Problem state can
1199 * only read bits 32:63, bits 0:31 return 0.
1201 * See section 9.3.1-9.3.2 of PowerISA v3.1B
1204 gen_load_spr(t0
, sprn
+ 16);
1205 tcg_gen_ext32u_tl(cpu_gpr
[gprn
], t0
);
1209 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
1210 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
1212 #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
1213 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
1215 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
1216 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
1218 #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
1219 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
1221 #define GEN_HANDLER_E_2(name, opc1, opc2, opc3, opc4, inval, type, type2) \
1222 GEN_OPCODE3(name, opc1, opc2, opc3, opc4, inval, type, type2)
1224 #define GEN_HANDLER2_E_2(name, onam, opc1, opc2, opc3, opc4, inval, typ, typ2) \
1225 GEN_OPCODE4(name, onam, opc1, opc2, opc3, opc4, inval, typ, typ2)
1227 typedef struct opcode_t
{
1228 unsigned char opc1
, opc2
, opc3
, opc4
;
1229 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
1230 unsigned char pad
[4];
1232 opc_handler_t handler
;
1236 static void gen_priv_opc(DisasContext
*ctx
)
1238 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
1241 /* Helpers for priv. check */
1242 #define GEN_PRIV(CTX) \
1244 gen_priv_opc(CTX); return; \
1247 #if defined(CONFIG_USER_ONLY)
1248 #define CHK_HV(CTX) GEN_PRIV(CTX)
1249 #define CHK_SV(CTX) GEN_PRIV(CTX)
1250 #define CHK_HVRM(CTX) GEN_PRIV(CTX)
1252 #define CHK_HV(CTX) \
1254 if (unlikely(ctx->pr || !ctx->hv)) {\
1258 #define CHK_SV(CTX) \
1260 if (unlikely(ctx->pr)) { \
1264 #define CHK_HVRM(CTX) \
1266 if (unlikely(ctx->pr || !ctx->hv || ctx->dr)) { \
1272 #define CHK_NONE(CTX)
1274 /*****************************************************************************/
1275 /* PowerPC instructions table */
1277 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
1287 .handler = &gen_##name, \
1289 .oname = stringify(name), \
1291 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
1302 .handler = &gen_##name, \
1304 .oname = stringify(name), \
1306 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
1316 .handler = &gen_##name, \
1320 #define GEN_OPCODE3(name, op1, op2, op3, op4, invl, _typ, _typ2) \
1330 .handler = &gen_##name, \
1332 .oname = stringify(name), \
1334 #define GEN_OPCODE4(name, onam, op1, op2, op3, op4, invl, _typ, _typ2) \
1344 .handler = &gen_##name, \
1349 /* Invalid instruction */
1350 static void gen_invalid(DisasContext
*ctx
)
1352 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
1355 static opc_handler_t invalid_handler
= {
1356 .inval1
= 0xFFFFFFFF,
1357 .inval2
= 0xFFFFFFFF,
1360 .handler
= gen_invalid
,
1363 /*** Integer comparison ***/
1365 static inline void gen_op_cmp(TCGv arg0
, TCGv arg1
, int s
, int crf
)
1367 TCGv t0
= tcg_temp_new();
1368 TCGv t1
= tcg_temp_new();
1369 TCGv_i32 t
= tcg_temp_new_i32();
1371 tcg_gen_movi_tl(t0
, CRF_EQ
);
1372 tcg_gen_movi_tl(t1
, CRF_LT
);
1373 tcg_gen_movcond_tl((s
? TCG_COND_LT
: TCG_COND_LTU
),
1374 t0
, arg0
, arg1
, t1
, t0
);
1375 tcg_gen_movi_tl(t1
, CRF_GT
);
1376 tcg_gen_movcond_tl((s
? TCG_COND_GT
: TCG_COND_GTU
),
1377 t0
, arg0
, arg1
, t1
, t0
);
1379 tcg_gen_trunc_tl_i32(t
, t0
);
1380 tcg_gen_trunc_tl_i32(cpu_crf
[crf
], cpu_so
);
1381 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t
);
1384 static inline void gen_op_cmpi(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
1386 TCGv t0
= tcg_constant_tl(arg1
);
1387 gen_op_cmp(arg0
, t0
, s
, crf
);
1390 static inline void gen_op_cmp32(TCGv arg0
, TCGv arg1
, int s
, int crf
)
1393 t0
= tcg_temp_new();
1394 t1
= tcg_temp_new();
1396 tcg_gen_ext32s_tl(t0
, arg0
);
1397 tcg_gen_ext32s_tl(t1
, arg1
);
1399 tcg_gen_ext32u_tl(t0
, arg0
);
1400 tcg_gen_ext32u_tl(t1
, arg1
);
1402 gen_op_cmp(t0
, t1
, s
, crf
);
1405 static inline void gen_op_cmpi32(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
1407 TCGv t0
= tcg_constant_tl(arg1
);
1408 gen_op_cmp32(arg0
, t0
, s
, crf
);
1411 static inline void gen_set_Rc0(DisasContext
*ctx
, TCGv reg
)
1413 if (NARROW_MODE(ctx
)) {
1414 gen_op_cmpi32(reg
, 0, 1, 0);
1416 gen_op_cmpi(reg
, 0, 1, 0);
1420 /* cmprb - range comparison: isupper, isaplha, islower*/
1421 static void gen_cmprb(DisasContext
*ctx
)
1423 TCGv_i32 src1
= tcg_temp_new_i32();
1424 TCGv_i32 src2
= tcg_temp_new_i32();
1425 TCGv_i32 src2lo
= tcg_temp_new_i32();
1426 TCGv_i32 src2hi
= tcg_temp_new_i32();
1427 TCGv_i32 crf
= cpu_crf
[crfD(ctx
->opcode
)];
1429 tcg_gen_trunc_tl_i32(src1
, cpu_gpr
[rA(ctx
->opcode
)]);
1430 tcg_gen_trunc_tl_i32(src2
, cpu_gpr
[rB(ctx
->opcode
)]);
1432 tcg_gen_andi_i32(src1
, src1
, 0xFF);
1433 tcg_gen_ext8u_i32(src2lo
, src2
);
1434 tcg_gen_shri_i32(src2
, src2
, 8);
1435 tcg_gen_ext8u_i32(src2hi
, src2
);
1437 tcg_gen_setcond_i32(TCG_COND_LEU
, src2lo
, src2lo
, src1
);
1438 tcg_gen_setcond_i32(TCG_COND_LEU
, src2hi
, src1
, src2hi
);
1439 tcg_gen_and_i32(crf
, src2lo
, src2hi
);
1441 if (ctx
->opcode
& 0x00200000) {
1442 tcg_gen_shri_i32(src2
, src2
, 8);
1443 tcg_gen_ext8u_i32(src2lo
, src2
);
1444 tcg_gen_shri_i32(src2
, src2
, 8);
1445 tcg_gen_ext8u_i32(src2hi
, src2
);
1446 tcg_gen_setcond_i32(TCG_COND_LEU
, src2lo
, src2lo
, src1
);
1447 tcg_gen_setcond_i32(TCG_COND_LEU
, src2hi
, src1
, src2hi
);
1448 tcg_gen_and_i32(src2lo
, src2lo
, src2hi
);
1449 tcg_gen_or_i32(crf
, crf
, src2lo
);
1451 tcg_gen_shli_i32(crf
, crf
, CRF_GT_BIT
);
1454 #if defined(TARGET_PPC64)
1456 static void gen_cmpeqb(DisasContext
*ctx
)
1458 gen_helper_cmpeqb(cpu_crf
[crfD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1459 cpu_gpr
[rB(ctx
->opcode
)]);
1463 /* isel (PowerPC 2.03 specification) */
1464 static void gen_isel(DisasContext
*ctx
)
1466 uint32_t bi
= rC(ctx
->opcode
);
1467 uint32_t mask
= 0x08 >> (bi
& 0x03);
1468 TCGv t0
= tcg_temp_new();
1471 tcg_gen_extu_i32_tl(t0
, cpu_crf
[bi
>> 2]);
1472 tcg_gen_andi_tl(t0
, t0
, mask
);
1474 zr
= tcg_constant_tl(0);
1475 tcg_gen_movcond_tl(TCG_COND_NE
, cpu_gpr
[rD(ctx
->opcode
)], t0
, zr
,
1476 rA(ctx
->opcode
) ? cpu_gpr
[rA(ctx
->opcode
)] : zr
,
1477 cpu_gpr
[rB(ctx
->opcode
)]);
1480 /* cmpb: PowerPC 2.05 specification */
1481 static void gen_cmpb(DisasContext
*ctx
)
1483 gen_helper_cmpb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
1484 cpu_gpr
[rB(ctx
->opcode
)]);
1487 /*** Integer arithmetic ***/
1489 static inline void gen_op_arith_compute_ov(DisasContext
*ctx
, TCGv arg0
,
1490 TCGv arg1
, TCGv arg2
, int sub
)
1492 TCGv t0
= tcg_temp_new();
1494 tcg_gen_xor_tl(cpu_ov
, arg0
, arg2
);
1495 tcg_gen_xor_tl(t0
, arg1
, arg2
);
1497 tcg_gen_and_tl(cpu_ov
, cpu_ov
, t0
);
1499 tcg_gen_andc_tl(cpu_ov
, cpu_ov
, t0
);
1501 if (NARROW_MODE(ctx
)) {
1502 tcg_gen_extract_tl(cpu_ov
, cpu_ov
, 31, 1);
1503 if (is_isa300(ctx
)) {
1504 tcg_gen_mov_tl(cpu_ov32
, cpu_ov
);
1507 if (is_isa300(ctx
)) {
1508 tcg_gen_extract_tl(cpu_ov32
, cpu_ov
, 31, 1);
1510 tcg_gen_extract_tl(cpu_ov
, cpu_ov
, TARGET_LONG_BITS
- 1, 1);
1512 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1515 static inline void gen_op_arith_compute_ca32(DisasContext
*ctx
,
1516 TCGv res
, TCGv arg0
, TCGv arg1
,
1521 if (!is_isa300(ctx
)) {
1525 t0
= tcg_temp_new();
1527 tcg_gen_eqv_tl(t0
, arg0
, arg1
);
1529 tcg_gen_xor_tl(t0
, arg0
, arg1
);
1531 tcg_gen_xor_tl(t0
, t0
, res
);
1532 tcg_gen_extract_tl(ca32
, t0
, 32, 1);
1535 /* Common add function */
1536 static inline void gen_op_arith_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1537 TCGv arg2
, TCGv ca
, TCGv ca32
,
1538 bool add_ca
, bool compute_ca
,
1539 bool compute_ov
, bool compute_rc0
)
1543 if (compute_ca
|| compute_ov
) {
1544 t0
= tcg_temp_new();
1548 if (NARROW_MODE(ctx
)) {
1550 * Caution: a non-obvious corner case of the spec is that
1551 * we must produce the *entire* 64-bit addition, but
1552 * produce the carry into bit 32.
1554 TCGv t1
= tcg_temp_new();
1555 tcg_gen_xor_tl(t1
, arg1
, arg2
); /* add without carry */
1556 tcg_gen_add_tl(t0
, arg1
, arg2
);
1558 tcg_gen_add_tl(t0
, t0
, ca
);
1560 tcg_gen_xor_tl(ca
, t0
, t1
); /* bits changed w/ carry */
1561 tcg_gen_extract_tl(ca
, ca
, 32, 1);
1562 if (is_isa300(ctx
)) {
1563 tcg_gen_mov_tl(ca32
, ca
);
1566 TCGv zero
= tcg_constant_tl(0);
1568 tcg_gen_add2_tl(t0
, ca
, arg1
, zero
, ca
, zero
);
1569 tcg_gen_add2_tl(t0
, ca
, t0
, ca
, arg2
, zero
);
1571 tcg_gen_add2_tl(t0
, ca
, arg1
, zero
, arg2
, zero
);
1573 gen_op_arith_compute_ca32(ctx
, t0
, arg1
, arg2
, ca32
, 0);
1576 tcg_gen_add_tl(t0
, arg1
, arg2
);
1578 tcg_gen_add_tl(t0
, t0
, ca
);
1583 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 0);
1585 if (unlikely(compute_rc0
)) {
1586 gen_set_Rc0(ctx
, t0
);
1590 tcg_gen_mov_tl(ret
, t0
);
1593 /* Add functions with two operands */
1594 #define GEN_INT_ARITH_ADD(name, opc3, ca, add_ca, compute_ca, compute_ov) \
1595 static void glue(gen_, name)(DisasContext *ctx) \
1597 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
1598 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1600 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1602 /* Add functions with one operand and one immediate */
1603 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, ca, \
1604 add_ca, compute_ca, compute_ov) \
1605 static void glue(gen_, name)(DisasContext *ctx) \
1607 TCGv t0 = tcg_constant_tl(const_val); \
1608 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
1609 cpu_gpr[rA(ctx->opcode)], t0, \
1611 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1614 /* add add. addo addo. */
1615 GEN_INT_ARITH_ADD(add
, 0x08, cpu_ca
, 0, 0, 0)
1616 GEN_INT_ARITH_ADD(addo
, 0x18, cpu_ca
, 0, 0, 1)
1617 /* addc addc. addco addco. */
1618 GEN_INT_ARITH_ADD(addc
, 0x00, cpu_ca
, 0, 1, 0)
1619 GEN_INT_ARITH_ADD(addco
, 0x10, cpu_ca
, 0, 1, 1)
1620 /* adde adde. addeo addeo. */
1621 GEN_INT_ARITH_ADD(adde
, 0x04, cpu_ca
, 1, 1, 0)
1622 GEN_INT_ARITH_ADD(addeo
, 0x14, cpu_ca
, 1, 1, 1)
1623 /* addme addme. addmeo addmeo. */
1624 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, cpu_ca
, 1, 1, 0)
1625 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, cpu_ca
, 1, 1, 1)
1627 GEN_INT_ARITH_ADD(addex
, 0x05, cpu_ov
, 1, 1, 0);
1628 /* addze addze. addzeo addzeo.*/
1629 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, cpu_ca
, 1, 1, 0)
1630 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, cpu_ca
, 1, 1, 1)
1632 static inline void gen_op_addic(DisasContext
*ctx
, bool compute_rc0
)
1634 TCGv c
= tcg_constant_tl(SIMM(ctx
->opcode
));
1635 gen_op_arith_add(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1636 c
, cpu_ca
, cpu_ca32
, 0, 1, 0, compute_rc0
);
1639 static void gen_addic(DisasContext
*ctx
)
1641 gen_op_addic(ctx
, 0);
1644 static void gen_addic_(DisasContext
*ctx
)
1646 gen_op_addic(ctx
, 1);
1649 static inline void gen_op_arith_divw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1650 TCGv arg2
, int sign
, int compute_ov
)
1652 TCGv_i32 t0
= tcg_temp_new_i32();
1653 TCGv_i32 t1
= tcg_temp_new_i32();
1654 TCGv_i32 t2
= tcg_temp_new_i32();
1655 TCGv_i32 t3
= tcg_temp_new_i32();
1657 tcg_gen_trunc_tl_i32(t0
, arg1
);
1658 tcg_gen_trunc_tl_i32(t1
, arg2
);
1660 tcg_gen_setcondi_i32(TCG_COND_EQ
, t2
, t0
, INT_MIN
);
1661 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, -1);
1662 tcg_gen_and_i32(t2
, t2
, t3
);
1663 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, 0);
1664 tcg_gen_or_i32(t2
, t2
, t3
);
1665 tcg_gen_movi_i32(t3
, 0);
1666 tcg_gen_movcond_i32(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1667 tcg_gen_div_i32(t3
, t0
, t1
);
1668 tcg_gen_extu_i32_tl(ret
, t3
);
1670 tcg_gen_setcondi_i32(TCG_COND_EQ
, t2
, t1
, 0);
1671 tcg_gen_movi_i32(t3
, 0);
1672 tcg_gen_movcond_i32(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1673 tcg_gen_divu_i32(t3
, t0
, t1
);
1674 tcg_gen_extu_i32_tl(ret
, t3
);
1677 tcg_gen_extu_i32_tl(cpu_ov
, t2
);
1678 if (is_isa300(ctx
)) {
1679 tcg_gen_extu_i32_tl(cpu_ov32
, t2
);
1681 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1684 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1685 gen_set_Rc0(ctx
, ret
);
1689 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
1690 static void glue(gen_, name)(DisasContext *ctx) \
1692 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
1693 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1694 sign, compute_ov); \
1696 /* divwu divwu. divwuo divwuo. */
1697 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0);
1698 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1);
1699 /* divw divw. divwo divwo. */
1700 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0);
1701 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1);
1703 /* div[wd]eu[o][.] */
1704 #define GEN_DIVE(name, hlpr, compute_ov) \
1705 static void gen_##name(DisasContext *ctx) \
1707 TCGv_i32 t0 = tcg_constant_i32(compute_ov); \
1708 gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1709 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \
1710 if (unlikely(Rc(ctx->opcode) != 0)) { \
1711 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1715 GEN_DIVE(divweu
, divweu
, 0);
1716 GEN_DIVE(divweuo
, divweu
, 1);
1717 GEN_DIVE(divwe
, divwe
, 0);
1718 GEN_DIVE(divweo
, divwe
, 1);
1720 #if defined(TARGET_PPC64)
1721 static inline void gen_op_arith_divd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1722 TCGv arg2
, int sign
, int compute_ov
)
1724 TCGv_i64 t0
= tcg_temp_new_i64();
1725 TCGv_i64 t1
= tcg_temp_new_i64();
1726 TCGv_i64 t2
= tcg_temp_new_i64();
1727 TCGv_i64 t3
= tcg_temp_new_i64();
1729 tcg_gen_mov_i64(t0
, arg1
);
1730 tcg_gen_mov_i64(t1
, arg2
);
1732 tcg_gen_setcondi_i64(TCG_COND_EQ
, t2
, t0
, INT64_MIN
);
1733 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, -1);
1734 tcg_gen_and_i64(t2
, t2
, t3
);
1735 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, 0);
1736 tcg_gen_or_i64(t2
, t2
, t3
);
1737 tcg_gen_movi_i64(t3
, 0);
1738 tcg_gen_movcond_i64(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1739 tcg_gen_div_i64(ret
, t0
, t1
);
1741 tcg_gen_setcondi_i64(TCG_COND_EQ
, t2
, t1
, 0);
1742 tcg_gen_movi_i64(t3
, 0);
1743 tcg_gen_movcond_i64(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1744 tcg_gen_divu_i64(ret
, t0
, t1
);
1747 tcg_gen_mov_tl(cpu_ov
, t2
);
1748 if (is_isa300(ctx
)) {
1749 tcg_gen_mov_tl(cpu_ov32
, t2
);
1751 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1754 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1755 gen_set_Rc0(ctx
, ret
);
1759 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1760 static void glue(gen_, name)(DisasContext *ctx) \
1762 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1763 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1764 sign, compute_ov); \
1766 /* divdu divdu. divduo divduo. */
1767 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0);
1768 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1);
1769 /* divd divd. divdo divdo. */
1770 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0);
1771 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1);
1773 GEN_DIVE(divdeu
, divdeu
, 0);
1774 GEN_DIVE(divdeuo
, divdeu
, 1);
1775 GEN_DIVE(divde
, divde
, 0);
1776 GEN_DIVE(divdeo
, divde
, 1);
1779 static inline void gen_op_arith_modw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1780 TCGv arg2
, int sign
)
1782 TCGv_i32 t0
= tcg_temp_new_i32();
1783 TCGv_i32 t1
= tcg_temp_new_i32();
1785 tcg_gen_trunc_tl_i32(t0
, arg1
);
1786 tcg_gen_trunc_tl_i32(t1
, arg2
);
1788 TCGv_i32 t2
= tcg_temp_new_i32();
1789 TCGv_i32 t3
= tcg_temp_new_i32();
1790 tcg_gen_setcondi_i32(TCG_COND_EQ
, t2
, t0
, INT_MIN
);
1791 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, -1);
1792 tcg_gen_and_i32(t2
, t2
, t3
);
1793 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, 0);
1794 tcg_gen_or_i32(t2
, t2
, t3
);
1795 tcg_gen_movi_i32(t3
, 0);
1796 tcg_gen_movcond_i32(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1797 tcg_gen_rem_i32(t3
, t0
, t1
);
1798 tcg_gen_ext_i32_tl(ret
, t3
);
1800 TCGv_i32 t2
= tcg_constant_i32(1);
1801 TCGv_i32 t3
= tcg_constant_i32(0);
1802 tcg_gen_movcond_i32(TCG_COND_EQ
, t1
, t1
, t3
, t2
, t1
);
1803 tcg_gen_remu_i32(t0
, t0
, t1
);
1804 tcg_gen_extu_i32_tl(ret
, t0
);
1808 #define GEN_INT_ARITH_MODW(name, opc3, sign) \
1809 static void glue(gen_, name)(DisasContext *ctx) \
1811 gen_op_arith_modw(ctx, cpu_gpr[rD(ctx->opcode)], \
1812 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1816 GEN_INT_ARITH_MODW(moduw
, 0x08, 0);
1817 GEN_INT_ARITH_MODW(modsw
, 0x18, 1);
1819 #if defined(TARGET_PPC64)
1820 static inline void gen_op_arith_modd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1821 TCGv arg2
, int sign
)
1823 TCGv_i64 t0
= tcg_temp_new_i64();
1824 TCGv_i64 t1
= tcg_temp_new_i64();
1826 tcg_gen_mov_i64(t0
, arg1
);
1827 tcg_gen_mov_i64(t1
, arg2
);
1829 TCGv_i64 t2
= tcg_temp_new_i64();
1830 TCGv_i64 t3
= tcg_temp_new_i64();
1831 tcg_gen_setcondi_i64(TCG_COND_EQ
, t2
, t0
, INT64_MIN
);
1832 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, -1);
1833 tcg_gen_and_i64(t2
, t2
, t3
);
1834 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, 0);
1835 tcg_gen_or_i64(t2
, t2
, t3
);
1836 tcg_gen_movi_i64(t3
, 0);
1837 tcg_gen_movcond_i64(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1838 tcg_gen_rem_i64(ret
, t0
, t1
);
1840 TCGv_i64 t2
= tcg_constant_i64(1);
1841 TCGv_i64 t3
= tcg_constant_i64(0);
1842 tcg_gen_movcond_i64(TCG_COND_EQ
, t1
, t1
, t3
, t2
, t1
);
1843 tcg_gen_remu_i64(ret
, t0
, t1
);
1847 #define GEN_INT_ARITH_MODD(name, opc3, sign) \
1848 static void glue(gen_, name)(DisasContext *ctx) \
1850 gen_op_arith_modd(ctx, cpu_gpr[rD(ctx->opcode)], \
1851 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1855 GEN_INT_ARITH_MODD(modud
, 0x08, 0);
1856 GEN_INT_ARITH_MODD(modsd
, 0x18, 1);
1860 static void gen_mulhw(DisasContext
*ctx
)
1862 TCGv_i32 t0
= tcg_temp_new_i32();
1863 TCGv_i32 t1
= tcg_temp_new_i32();
1865 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1866 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1867 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1868 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1869 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1870 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1874 /* mulhwu mulhwu. */
1875 static void gen_mulhwu(DisasContext
*ctx
)
1877 TCGv_i32 t0
= tcg_temp_new_i32();
1878 TCGv_i32 t1
= tcg_temp_new_i32();
1880 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1881 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1882 tcg_gen_mulu2_i32(t0
, t1
, t0
, t1
);
1883 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1884 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1885 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1890 static void gen_mullw(DisasContext
*ctx
)
1892 #if defined(TARGET_PPC64)
1894 t0
= tcg_temp_new_i64();
1895 t1
= tcg_temp_new_i64();
1896 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1897 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1898 tcg_gen_mul_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
1900 tcg_gen_mul_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1901 cpu_gpr
[rB(ctx
->opcode
)]);
1903 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1904 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1908 /* mullwo mullwo. */
1909 static void gen_mullwo(DisasContext
*ctx
)
1911 TCGv_i32 t0
= tcg_temp_new_i32();
1912 TCGv_i32 t1
= tcg_temp_new_i32();
1914 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1915 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1916 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1917 #if defined(TARGET_PPC64)
1918 tcg_gen_concat_i32_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
1920 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1923 tcg_gen_sari_i32(t0
, t0
, 31);
1924 tcg_gen_setcond_i32(TCG_COND_NE
, t0
, t0
, t1
);
1925 tcg_gen_extu_i32_tl(cpu_ov
, t0
);
1926 if (is_isa300(ctx
)) {
1927 tcg_gen_mov_tl(cpu_ov32
, cpu_ov
);
1929 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1931 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1932 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1937 static void gen_mulli(DisasContext
*ctx
)
1939 tcg_gen_muli_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1943 #if defined(TARGET_PPC64)
1945 static void gen_mulhd(DisasContext
*ctx
)
1947 TCGv lo
= tcg_temp_new();
1948 tcg_gen_muls2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1949 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1950 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1951 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1955 /* mulhdu mulhdu. */
1956 static void gen_mulhdu(DisasContext
*ctx
)
1958 TCGv lo
= tcg_temp_new();
1959 tcg_gen_mulu2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1960 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1961 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1962 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1967 static void gen_mulld(DisasContext
*ctx
)
1969 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1970 cpu_gpr
[rB(ctx
->opcode
)]);
1971 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1972 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1976 /* mulldo mulldo. */
1977 static void gen_mulldo(DisasContext
*ctx
)
1979 TCGv_i64 t0
= tcg_temp_new_i64();
1980 TCGv_i64 t1
= tcg_temp_new_i64();
1982 tcg_gen_muls2_i64(t0
, t1
, cpu_gpr
[rA(ctx
->opcode
)],
1983 cpu_gpr
[rB(ctx
->opcode
)]);
1984 tcg_gen_mov_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1986 tcg_gen_sari_i64(t0
, t0
, 63);
1987 tcg_gen_setcond_i64(TCG_COND_NE
, cpu_ov
, t0
, t1
);
1988 if (is_isa300(ctx
)) {
1989 tcg_gen_mov_tl(cpu_ov32
, cpu_ov
);
1991 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1993 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1994 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1999 /* Common subf function */
2000 static inline void gen_op_arith_subf(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
2001 TCGv arg2
, bool add_ca
, bool compute_ca
,
2002 bool compute_ov
, bool compute_rc0
)
2006 if (compute_ca
|| compute_ov
) {
2007 t0
= tcg_temp_new();
2011 /* dest = ~arg1 + arg2 [+ ca]. */
2012 if (NARROW_MODE(ctx
)) {
2014 * Caution: a non-obvious corner case of the spec is that
2015 * we must produce the *entire* 64-bit addition, but
2016 * produce the carry into bit 32.
2018 TCGv inv1
= tcg_temp_new();
2019 TCGv t1
= tcg_temp_new();
2020 tcg_gen_not_tl(inv1
, arg1
);
2022 tcg_gen_add_tl(t0
, arg2
, cpu_ca
);
2024 tcg_gen_addi_tl(t0
, arg2
, 1);
2026 tcg_gen_xor_tl(t1
, arg2
, inv1
); /* add without carry */
2027 tcg_gen_add_tl(t0
, t0
, inv1
);
2028 tcg_gen_xor_tl(cpu_ca
, t0
, t1
); /* bits changes w/ carry */
2029 tcg_gen_extract_tl(cpu_ca
, cpu_ca
, 32, 1);
2030 if (is_isa300(ctx
)) {
2031 tcg_gen_mov_tl(cpu_ca32
, cpu_ca
);
2033 } else if (add_ca
) {
2034 TCGv zero
, inv1
= tcg_temp_new();
2035 tcg_gen_not_tl(inv1
, arg1
);
2036 zero
= tcg_constant_tl(0);
2037 tcg_gen_add2_tl(t0
, cpu_ca
, arg2
, zero
, cpu_ca
, zero
);
2038 tcg_gen_add2_tl(t0
, cpu_ca
, t0
, cpu_ca
, inv1
, zero
);
2039 gen_op_arith_compute_ca32(ctx
, t0
, inv1
, arg2
, cpu_ca32
, 0);
2041 tcg_gen_setcond_tl(TCG_COND_GEU
, cpu_ca
, arg2
, arg1
);
2042 tcg_gen_sub_tl(t0
, arg2
, arg1
);
2043 gen_op_arith_compute_ca32(ctx
, t0
, arg1
, arg2
, cpu_ca32
, 1);
2045 } else if (add_ca
) {
2047 * Since we're ignoring carry-out, we can simplify the
2048 * standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1.
2050 tcg_gen_sub_tl(t0
, arg2
, arg1
);
2051 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
2052 tcg_gen_subi_tl(t0
, t0
, 1);
2054 tcg_gen_sub_tl(t0
, arg2
, arg1
);
2058 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 1);
2060 if (unlikely(compute_rc0
)) {
2061 gen_set_Rc0(ctx
, t0
);
2065 tcg_gen_mov_tl(ret
, t0
);
2068 /* Sub functions with Two operands functions */
2069 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
2070 static void glue(gen_, name)(DisasContext *ctx) \
2072 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
2073 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
2074 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
2076 /* Sub functions with one operand and one immediate */
2077 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
2078 add_ca, compute_ca, compute_ov) \
2079 static void glue(gen_, name)(DisasContext *ctx) \
2081 TCGv t0 = tcg_constant_tl(const_val); \
2082 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
2083 cpu_gpr[rA(ctx->opcode)], t0, \
2084 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
2086 /* subf subf. subfo subfo. */
2087 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
2088 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
2089 /* subfc subfc. subfco subfco. */
2090 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
2091 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
2092 /* subfe subfe. subfeo subfo. */
2093 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
2094 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
2095 /* subfme subfme. subfmeo subfmeo. */
2096 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
2097 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
2098 /* subfze subfze. subfzeo subfzeo.*/
2099 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
2100 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
2103 static void gen_subfic(DisasContext
*ctx
)
2105 TCGv c
= tcg_constant_tl(SIMM(ctx
->opcode
));
2106 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
2110 /* neg neg. nego nego. */
2111 static inline void gen_op_arith_neg(DisasContext
*ctx
, bool compute_ov
)
2113 TCGv zero
= tcg_constant_tl(0);
2114 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
2115 zero
, 0, 0, compute_ov
, Rc(ctx
->opcode
));
2118 static void gen_neg(DisasContext
*ctx
)
2120 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
2121 if (unlikely(Rc(ctx
->opcode
))) {
2122 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
2126 static void gen_nego(DisasContext
*ctx
)
2128 gen_op_arith_neg(ctx
, 1);
2131 /*** Integer logical ***/
2132 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
2133 static void glue(gen_, name)(DisasContext *ctx) \
2135 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
2136 cpu_gpr[rB(ctx->opcode)]); \
2137 if (unlikely(Rc(ctx->opcode) != 0)) \
2138 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
2141 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
2142 static void glue(gen_, name)(DisasContext *ctx) \
2144 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
2145 if (unlikely(Rc(ctx->opcode) != 0)) \
2146 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
2150 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
);
2152 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
);
2155 static void gen_andi_(DisasContext
*ctx
)
2157 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
2159 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2163 static void gen_andis_(DisasContext
*ctx
)
2165 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
2166 UIMM(ctx
->opcode
) << 16);
2167 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2171 static void gen_cntlzw(DisasContext
*ctx
)
2173 TCGv_i32 t
= tcg_temp_new_i32();
2175 tcg_gen_trunc_tl_i32(t
, cpu_gpr
[rS(ctx
->opcode
)]);
2176 tcg_gen_clzi_i32(t
, t
, 32);
2177 tcg_gen_extu_i32_tl(cpu_gpr
[rA(ctx
->opcode
)], t
);
2179 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2180 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2185 static void gen_cnttzw(DisasContext
*ctx
)
2187 TCGv_i32 t
= tcg_temp_new_i32();
2189 tcg_gen_trunc_tl_i32(t
, cpu_gpr
[rS(ctx
->opcode
)]);
2190 tcg_gen_ctzi_i32(t
, t
, 32);
2191 tcg_gen_extu_i32_tl(cpu_gpr
[rA(ctx
->opcode
)], t
);
2193 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2194 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2199 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
);
2200 /* extsb & extsb. */
2201 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
);
2202 /* extsh & extsh. */
2203 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
);
2205 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
);
2207 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
);
2209 #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY)
2210 static void gen_pause(DisasContext
*ctx
)
2212 TCGv_i32 t0
= tcg_constant_i32(0);
2213 tcg_gen_st_i32(t0
, cpu_env
,
2214 -offsetof(PowerPCCPU
, env
) + offsetof(CPUState
, halted
));
2216 /* Stop translation, this gives other CPUs a chance to run */
2217 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
2219 #endif /* defined(TARGET_PPC64) */
2222 static void gen_or(DisasContext
*ctx
)
2226 rs
= rS(ctx
->opcode
);
2227 ra
= rA(ctx
->opcode
);
2228 rb
= rB(ctx
->opcode
);
2229 /* Optimisation for mr. ri case */
2230 if (rs
!= ra
|| rs
!= rb
) {
2232 tcg_gen_or_tl(cpu_gpr
[ra
], cpu_gpr
[rs
], cpu_gpr
[rb
]);
2234 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rs
]);
2236 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2237 gen_set_Rc0(ctx
, cpu_gpr
[ra
]);
2239 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
2240 gen_set_Rc0(ctx
, cpu_gpr
[rs
]);
2241 #if defined(TARGET_PPC64)
2242 } else if (rs
!= 0) { /* 0 is nop */
2247 /* Set process priority to low */
2251 /* Set process priority to medium-low */
2255 /* Set process priority to normal */
2258 #if !defined(CONFIG_USER_ONLY)
2261 /* Set process priority to very low */
2267 /* Set process priority to medium-hight */
2273 /* Set process priority to high */
2278 if (ctx
->hv
&& !ctx
->pr
) {
2279 /* Set process priority to very high */
2288 TCGv t0
= tcg_temp_new();
2289 gen_load_spr(t0
, SPR_PPR
);
2290 tcg_gen_andi_tl(t0
, t0
, ~0x001C000000000000ULL
);
2291 tcg_gen_ori_tl(t0
, t0
, ((uint64_t)prio
) << 50);
2292 gen_store_spr(SPR_PPR
, t0
);
2294 #if !defined(CONFIG_USER_ONLY)
2296 * Pause out of TCG otherwise spin loops with smt_low eat too
2297 * much CPU and the kernel hangs. This applies to all
2298 * encodings other than no-op, e.g., miso(rs=26), yield(27),
2299 * mdoio(29), mdoom(30), and all currently undefined.
2307 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
);
2310 static void gen_xor(DisasContext
*ctx
)
2312 /* Optimisation for "set to zero" case */
2313 if (rS(ctx
->opcode
) != rB(ctx
->opcode
)) {
2314 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
2315 cpu_gpr
[rB(ctx
->opcode
)]);
2317 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
2319 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2320 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2325 static void gen_ori(DisasContext
*ctx
)
2327 target_ulong uimm
= UIMM(ctx
->opcode
);
2329 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
2332 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
2336 static void gen_oris(DisasContext
*ctx
)
2338 target_ulong uimm
= UIMM(ctx
->opcode
);
2340 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
2344 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
2349 static void gen_xori(DisasContext
*ctx
)
2351 target_ulong uimm
= UIMM(ctx
->opcode
);
2353 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
2357 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
2361 static void gen_xoris(DisasContext
*ctx
)
2363 target_ulong uimm
= UIMM(ctx
->opcode
);
2365 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
2369 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
2373 /* popcntb : PowerPC 2.03 specification */
2374 static void gen_popcntb(DisasContext
*ctx
)
2376 gen_helper_popcntb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
2379 static void gen_popcntw(DisasContext
*ctx
)
2381 #if defined(TARGET_PPC64)
2382 gen_helper_popcntw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
2384 tcg_gen_ctpop_i32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
2388 #if defined(TARGET_PPC64)
2389 /* popcntd: PowerPC 2.06 specification */
2390 static void gen_popcntd(DisasContext
*ctx
)
2392 tcg_gen_ctpop_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
2396 /* prtyw: PowerPC 2.05 specification */
2397 static void gen_prtyw(DisasContext
*ctx
)
2399 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
2400 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
2401 TCGv t0
= tcg_temp_new();
2402 tcg_gen_shri_tl(t0
, rs
, 16);
2403 tcg_gen_xor_tl(ra
, rs
, t0
);
2404 tcg_gen_shri_tl(t0
, ra
, 8);
2405 tcg_gen_xor_tl(ra
, ra
, t0
);
2406 tcg_gen_andi_tl(ra
, ra
, (target_ulong
)0x100000001ULL
);
2409 #if defined(TARGET_PPC64)
2410 /* prtyd: PowerPC 2.05 specification */
2411 static void gen_prtyd(DisasContext
*ctx
)
2413 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
2414 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
2415 TCGv t0
= tcg_temp_new();
2416 tcg_gen_shri_tl(t0
, rs
, 32);
2417 tcg_gen_xor_tl(ra
, rs
, t0
);
2418 tcg_gen_shri_tl(t0
, ra
, 16);
2419 tcg_gen_xor_tl(ra
, ra
, t0
);
2420 tcg_gen_shri_tl(t0
, ra
, 8);
2421 tcg_gen_xor_tl(ra
, ra
, t0
);
2422 tcg_gen_andi_tl(ra
, ra
, 1);
2426 #if defined(TARGET_PPC64)
2428 static void gen_bpermd(DisasContext
*ctx
)
2430 gen_helper_bpermd(cpu_gpr
[rA(ctx
->opcode
)],
2431 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2435 #if defined(TARGET_PPC64)
2436 /* extsw & extsw. */
2437 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
);
2440 static void gen_cntlzd(DisasContext
*ctx
)
2442 tcg_gen_clzi_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], 64);
2443 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2444 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2449 static void gen_cnttzd(DisasContext
*ctx
)
2451 tcg_gen_ctzi_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], 64);
2452 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2453 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2458 static void gen_darn(DisasContext
*ctx
)
2460 int l
= L(ctx
->opcode
);
2463 tcg_gen_movi_i64(cpu_gpr
[rD(ctx
->opcode
)], -1);
2465 translator_io_start(&ctx
->base
);
2467 gen_helper_darn32(cpu_gpr
[rD(ctx
->opcode
)]);
2469 /* Return 64-bit random for both CRN and RRN */
2470 gen_helper_darn64(cpu_gpr
[rD(ctx
->opcode
)]);
2476 /*** Integer rotate ***/
2478 /* rlwimi & rlwimi. */
2479 static void gen_rlwimi(DisasContext
*ctx
)
2481 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2482 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2483 uint32_t sh
= SH(ctx
->opcode
);
2484 uint32_t mb
= MB(ctx
->opcode
);
2485 uint32_t me
= ME(ctx
->opcode
);
2487 if (sh
== (31 - me
) && mb
<= me
) {
2488 tcg_gen_deposit_tl(t_ra
, t_ra
, t_rs
, sh
, me
- mb
+ 1);
2491 bool mask_in_32b
= true;
2494 #if defined(TARGET_PPC64)
2498 mask
= MASK(mb
, me
);
2500 #if defined(TARGET_PPC64)
2501 if (mask
> 0xffffffffu
) {
2502 mask_in_32b
= false;
2505 t1
= tcg_temp_new();
2507 TCGv_i32 t0
= tcg_temp_new_i32();
2508 tcg_gen_trunc_tl_i32(t0
, t_rs
);
2509 tcg_gen_rotli_i32(t0
, t0
, sh
);
2510 tcg_gen_extu_i32_tl(t1
, t0
);
2512 #if defined(TARGET_PPC64)
2513 tcg_gen_deposit_i64(t1
, t_rs
, t_rs
, 32, 32);
2514 tcg_gen_rotli_i64(t1
, t1
, sh
);
2516 g_assert_not_reached();
2520 tcg_gen_andi_tl(t1
, t1
, mask
);
2521 tcg_gen_andi_tl(t_ra
, t_ra
, ~mask
);
2522 tcg_gen_or_tl(t_ra
, t_ra
, t1
);
2524 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2525 gen_set_Rc0(ctx
, t_ra
);
2529 /* rlwinm & rlwinm. */
2530 static void gen_rlwinm(DisasContext
*ctx
)
2532 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2533 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2534 int sh
= SH(ctx
->opcode
);
2535 int mb
= MB(ctx
->opcode
);
2536 int me
= ME(ctx
->opcode
);
2537 int len
= me
- mb
+ 1;
2538 int rsh
= (32 - sh
) & 31;
2540 if (sh
!= 0 && len
> 0 && me
== (31 - sh
)) {
2541 tcg_gen_deposit_z_tl(t_ra
, t_rs
, sh
, len
);
2542 } else if (me
== 31 && rsh
+ len
<= 32) {
2543 tcg_gen_extract_tl(t_ra
, t_rs
, rsh
, len
);
2546 bool mask_in_32b
= true;
2547 #if defined(TARGET_PPC64)
2551 mask
= MASK(mb
, me
);
2552 #if defined(TARGET_PPC64)
2553 if (mask
> 0xffffffffu
) {
2554 mask_in_32b
= false;
2559 tcg_gen_andi_tl(t_ra
, t_rs
, mask
);
2561 TCGv_i32 t0
= tcg_temp_new_i32();
2562 tcg_gen_trunc_tl_i32(t0
, t_rs
);
2563 tcg_gen_rotli_i32(t0
, t0
, sh
);
2564 tcg_gen_andi_i32(t0
, t0
, mask
);
2565 tcg_gen_extu_i32_tl(t_ra
, t0
);
2568 #if defined(TARGET_PPC64)
2569 tcg_gen_deposit_i64(t_ra
, t_rs
, t_rs
, 32, 32);
2570 tcg_gen_rotli_i64(t_ra
, t_ra
, sh
);
2571 tcg_gen_andi_i64(t_ra
, t_ra
, mask
);
2573 g_assert_not_reached();
2577 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2578 gen_set_Rc0(ctx
, t_ra
);
2582 /* rlwnm & rlwnm. */
2583 static void gen_rlwnm(DisasContext
*ctx
)
2585 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2586 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2587 TCGv t_rb
= cpu_gpr
[rB(ctx
->opcode
)];
2588 uint32_t mb
= MB(ctx
->opcode
);
2589 uint32_t me
= ME(ctx
->opcode
);
2591 bool mask_in_32b
= true;
2593 #if defined(TARGET_PPC64)
2597 mask
= MASK(mb
, me
);
2599 #if defined(TARGET_PPC64)
2600 if (mask
> 0xffffffffu
) {
2601 mask_in_32b
= false;
2605 TCGv_i32 t0
= tcg_temp_new_i32();
2606 TCGv_i32 t1
= tcg_temp_new_i32();
2607 tcg_gen_trunc_tl_i32(t0
, t_rb
);
2608 tcg_gen_trunc_tl_i32(t1
, t_rs
);
2609 tcg_gen_andi_i32(t0
, t0
, 0x1f);
2610 tcg_gen_rotl_i32(t1
, t1
, t0
);
2611 tcg_gen_extu_i32_tl(t_ra
, t1
);
2613 #if defined(TARGET_PPC64)
2614 TCGv_i64 t0
= tcg_temp_new_i64();
2615 tcg_gen_andi_i64(t0
, t_rb
, 0x1f);
2616 tcg_gen_deposit_i64(t_ra
, t_rs
, t_rs
, 32, 32);
2617 tcg_gen_rotl_i64(t_ra
, t_ra
, t0
);
2619 g_assert_not_reached();
2623 tcg_gen_andi_tl(t_ra
, t_ra
, mask
);
2625 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2626 gen_set_Rc0(ctx
, t_ra
);
2630 #if defined(TARGET_PPC64)
2631 #define GEN_PPC64_R2(name, opc1, opc2) \
2632 static void glue(gen_, name##0)(DisasContext *ctx) \
2634 gen_##name(ctx, 0); \
2637 static void glue(gen_, name##1)(DisasContext *ctx) \
2639 gen_##name(ctx, 1); \
2641 #define GEN_PPC64_R4(name, opc1, opc2) \
2642 static void glue(gen_, name##0)(DisasContext *ctx) \
2644 gen_##name(ctx, 0, 0); \
2647 static void glue(gen_, name##1)(DisasContext *ctx) \
2649 gen_##name(ctx, 0, 1); \
2652 static void glue(gen_, name##2)(DisasContext *ctx) \
2654 gen_##name(ctx, 1, 0); \
2657 static void glue(gen_, name##3)(DisasContext *ctx) \
2659 gen_##name(ctx, 1, 1); \
2662 static void gen_rldinm(DisasContext
*ctx
, int mb
, int me
, int sh
)
2664 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2665 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2666 int len
= me
- mb
+ 1;
2667 int rsh
= (64 - sh
) & 63;
2669 if (sh
!= 0 && len
> 0 && me
== (63 - sh
)) {
2670 tcg_gen_deposit_z_tl(t_ra
, t_rs
, sh
, len
);
2671 } else if (me
== 63 && rsh
+ len
<= 64) {
2672 tcg_gen_extract_tl(t_ra
, t_rs
, rsh
, len
);
2674 tcg_gen_rotli_tl(t_ra
, t_rs
, sh
);
2675 tcg_gen_andi_tl(t_ra
, t_ra
, MASK(mb
, me
));
2677 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2678 gen_set_Rc0(ctx
, t_ra
);
2682 /* rldicl - rldicl. */
2683 static inline void gen_rldicl(DisasContext
*ctx
, int mbn
, int shn
)
2687 sh
= SH(ctx
->opcode
) | (shn
<< 5);
2688 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2689 gen_rldinm(ctx
, mb
, 63, sh
);
2691 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
2693 /* rldicr - rldicr. */
2694 static inline void gen_rldicr(DisasContext
*ctx
, int men
, int shn
)
2698 sh
= SH(ctx
->opcode
) | (shn
<< 5);
2699 me
= MB(ctx
->opcode
) | (men
<< 5);
2700 gen_rldinm(ctx
, 0, me
, sh
);
2702 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
2704 /* rldic - rldic. */
2705 static inline void gen_rldic(DisasContext
*ctx
, int mbn
, int shn
)
2709 sh
= SH(ctx
->opcode
) | (shn
<< 5);
2710 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2711 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
2713 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
2715 static void gen_rldnm(DisasContext
*ctx
, int mb
, int me
)
2717 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2718 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2719 TCGv t_rb
= cpu_gpr
[rB(ctx
->opcode
)];
2722 t0
= tcg_temp_new();
2723 tcg_gen_andi_tl(t0
, t_rb
, 0x3f);
2724 tcg_gen_rotl_tl(t_ra
, t_rs
, t0
);
2726 tcg_gen_andi_tl(t_ra
, t_ra
, MASK(mb
, me
));
2727 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2728 gen_set_Rc0(ctx
, t_ra
);
2732 /* rldcl - rldcl. */
2733 static inline void gen_rldcl(DisasContext
*ctx
, int mbn
)
2737 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2738 gen_rldnm(ctx
, mb
, 63);
2740 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
2742 /* rldcr - rldcr. */
2743 static inline void gen_rldcr(DisasContext
*ctx
, int men
)
2747 me
= MB(ctx
->opcode
) | (men
<< 5);
2748 gen_rldnm(ctx
, 0, me
);
2750 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
2752 /* rldimi - rldimi. */
2753 static void gen_rldimi(DisasContext
*ctx
, int mbn
, int shn
)
2755 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2756 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2757 uint32_t sh
= SH(ctx
->opcode
) | (shn
<< 5);
2758 uint32_t mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2759 uint32_t me
= 63 - sh
;
2762 tcg_gen_deposit_tl(t_ra
, t_ra
, t_rs
, sh
, me
- mb
+ 1);
2764 target_ulong mask
= MASK(mb
, me
);
2765 TCGv t1
= tcg_temp_new();
2767 tcg_gen_rotli_tl(t1
, t_rs
, sh
);
2768 tcg_gen_andi_tl(t1
, t1
, mask
);
2769 tcg_gen_andi_tl(t_ra
, t_ra
, ~mask
);
2770 tcg_gen_or_tl(t_ra
, t_ra
, t1
);
2772 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2773 gen_set_Rc0(ctx
, t_ra
);
2776 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
2779 /*** Integer shift ***/
2782 static void gen_slw(DisasContext
*ctx
)
2786 t0
= tcg_temp_new();
2787 /* AND rS with a mask that is 0 when rB >= 0x20 */
2788 #if defined(TARGET_PPC64)
2789 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
2790 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2792 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
2793 tcg_gen_sari_tl(t0
, t0
, 0x1f);
2795 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2796 t1
= tcg_temp_new();
2797 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
2798 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2799 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
2800 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2801 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2806 static void gen_sraw(DisasContext
*ctx
)
2808 gen_helper_sraw(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
2809 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2810 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2811 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2815 /* srawi & srawi. */
2816 static void gen_srawi(DisasContext
*ctx
)
2818 int sh
= SH(ctx
->opcode
);
2819 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
2820 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
2822 tcg_gen_ext32s_tl(dst
, src
);
2823 tcg_gen_movi_tl(cpu_ca
, 0);
2824 if (is_isa300(ctx
)) {
2825 tcg_gen_movi_tl(cpu_ca32
, 0);
2829 tcg_gen_ext32s_tl(dst
, src
);
2830 tcg_gen_andi_tl(cpu_ca
, dst
, (1ULL << sh
) - 1);
2831 t0
= tcg_temp_new();
2832 tcg_gen_sari_tl(t0
, dst
, TARGET_LONG_BITS
- 1);
2833 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
2834 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
2835 if (is_isa300(ctx
)) {
2836 tcg_gen_mov_tl(cpu_ca32
, cpu_ca
);
2838 tcg_gen_sari_tl(dst
, dst
, sh
);
2840 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2841 gen_set_Rc0(ctx
, dst
);
2846 static void gen_srw(DisasContext
*ctx
)
2850 t0
= tcg_temp_new();
2851 /* AND rS with a mask that is 0 when rB >= 0x20 */
2852 #if defined(TARGET_PPC64)
2853 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
2854 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2856 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
2857 tcg_gen_sari_tl(t0
, t0
, 0x1f);
2859 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2860 tcg_gen_ext32u_tl(t0
, t0
);
2861 t1
= tcg_temp_new();
2862 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
2863 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2864 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2865 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2869 #if defined(TARGET_PPC64)
2871 static void gen_sld(DisasContext
*ctx
)
2875 t0
= tcg_temp_new();
2876 /* AND rS with a mask that is 0 when rB >= 0x40 */
2877 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
2878 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2879 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2880 t1
= tcg_temp_new();
2881 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
2882 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2883 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2884 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2889 static void gen_srad(DisasContext
*ctx
)
2891 gen_helper_srad(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
2892 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2893 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2894 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2897 /* sradi & sradi. */
2898 static inline void gen_sradi(DisasContext
*ctx
, int n
)
2900 int sh
= SH(ctx
->opcode
) + (n
<< 5);
2901 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
2902 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
2904 tcg_gen_mov_tl(dst
, src
);
2905 tcg_gen_movi_tl(cpu_ca
, 0);
2906 if (is_isa300(ctx
)) {
2907 tcg_gen_movi_tl(cpu_ca32
, 0);
2911 tcg_gen_andi_tl(cpu_ca
, src
, (1ULL << sh
) - 1);
2912 t0
= tcg_temp_new();
2913 tcg_gen_sari_tl(t0
, src
, TARGET_LONG_BITS
- 1);
2914 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
2915 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
2916 if (is_isa300(ctx
)) {
2917 tcg_gen_mov_tl(cpu_ca32
, cpu_ca
);
2919 tcg_gen_sari_tl(dst
, src
, sh
);
2921 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2922 gen_set_Rc0(ctx
, dst
);
2926 static void gen_sradi0(DisasContext
*ctx
)
2931 static void gen_sradi1(DisasContext
*ctx
)
2936 /* extswsli & extswsli. */
2937 static inline void gen_extswsli(DisasContext
*ctx
, int n
)
2939 int sh
= SH(ctx
->opcode
) + (n
<< 5);
2940 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
2941 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
2943 tcg_gen_ext32s_tl(dst
, src
);
2944 tcg_gen_shli_tl(dst
, dst
, sh
);
2945 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2946 gen_set_Rc0(ctx
, dst
);
2950 static void gen_extswsli0(DisasContext
*ctx
)
2952 gen_extswsli(ctx
, 0);
2955 static void gen_extswsli1(DisasContext
*ctx
)
2957 gen_extswsli(ctx
, 1);
2961 static void gen_srd(DisasContext
*ctx
)
2965 t0
= tcg_temp_new();
2966 /* AND rS with a mask that is 0 when rB >= 0x40 */
2967 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
2968 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2969 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2970 t1
= tcg_temp_new();
2971 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
2972 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2973 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2974 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2979 /*** Addressing modes ***/
2980 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2981 static inline void gen_addr_imm_index(DisasContext
*ctx
, TCGv EA
,
2984 target_long simm
= SIMM(ctx
->opcode
);
2987 if (rA(ctx
->opcode
) == 0) {
2988 if (NARROW_MODE(ctx
)) {
2989 simm
= (uint32_t)simm
;
2991 tcg_gen_movi_tl(EA
, simm
);
2992 } else if (likely(simm
!= 0)) {
2993 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
);
2994 if (NARROW_MODE(ctx
)) {
2995 tcg_gen_ext32u_tl(EA
, EA
);
2998 if (NARROW_MODE(ctx
)) {
2999 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
3001 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
3006 static inline void gen_addr_reg_index(DisasContext
*ctx
, TCGv EA
)
3008 if (rA(ctx
->opcode
) == 0) {
3009 if (NARROW_MODE(ctx
)) {
3010 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
3012 tcg_gen_mov_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
3015 tcg_gen_add_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
3016 if (NARROW_MODE(ctx
)) {
3017 tcg_gen_ext32u_tl(EA
, EA
);
3022 static inline void gen_addr_register(DisasContext
*ctx
, TCGv EA
)
3024 if (rA(ctx
->opcode
) == 0) {
3025 tcg_gen_movi_tl(EA
, 0);
3026 } else if (NARROW_MODE(ctx
)) {
3027 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
3029 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
3033 static inline void gen_addr_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
3036 tcg_gen_addi_tl(ret
, arg1
, val
);
3037 if (NARROW_MODE(ctx
)) {
3038 tcg_gen_ext32u_tl(ret
, ret
);
3042 static inline void gen_align_no_le(DisasContext
*ctx
)
3044 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
,
3045 (ctx
->opcode
& 0x03FF0000) | POWERPC_EXCP_ALIGN_LE
);
3048 static TCGv
do_ea_calc(DisasContext
*ctx
, int ra
, TCGv displ
)
3050 TCGv ea
= tcg_temp_new();
3052 tcg_gen_add_tl(ea
, cpu_gpr
[ra
], displ
);
3054 tcg_gen_mov_tl(ea
, displ
);
3056 if (NARROW_MODE(ctx
)) {
3057 tcg_gen_ext32u_tl(ea
, ea
);
3062 /*** Integer load ***/
3063 #define DEF_MEMOP(op) ((op) | ctx->default_tcg_memop_mask)
3064 #define BSWAP_MEMOP(op) ((op) | (ctx->default_tcg_memop_mask ^ MO_BSWAP))
3066 #define GEN_QEMU_LOAD_TL(ldop, op) \
3067 static void glue(gen_qemu_, ldop)(DisasContext *ctx, \
3071 tcg_gen_qemu_ld_tl(val, addr, ctx->mem_idx, op); \
3074 GEN_QEMU_LOAD_TL(ld8u
, DEF_MEMOP(MO_UB
))
3075 GEN_QEMU_LOAD_TL(ld16u
, DEF_MEMOP(MO_UW
))
3076 GEN_QEMU_LOAD_TL(ld16s
, DEF_MEMOP(MO_SW
))
3077 GEN_QEMU_LOAD_TL(ld32u
, DEF_MEMOP(MO_UL
))
3078 GEN_QEMU_LOAD_TL(ld32s
, DEF_MEMOP(MO_SL
))
3080 GEN_QEMU_LOAD_TL(ld16ur
, BSWAP_MEMOP(MO_UW
))
3081 GEN_QEMU_LOAD_TL(ld32ur
, BSWAP_MEMOP(MO_UL
))
3083 #define GEN_QEMU_LOAD_64(ldop, op) \
3084 static void glue(gen_qemu_, glue(ldop, _i64))(DisasContext *ctx, \
3088 tcg_gen_qemu_ld_i64(val, addr, ctx->mem_idx, op); \
3091 GEN_QEMU_LOAD_64(ld8u
, DEF_MEMOP(MO_UB
))
3092 GEN_QEMU_LOAD_64(ld16u
, DEF_MEMOP(MO_UW
))
3093 GEN_QEMU_LOAD_64(ld32u
, DEF_MEMOP(MO_UL
))
3094 GEN_QEMU_LOAD_64(ld32s
, DEF_MEMOP(MO_SL
))
3095 GEN_QEMU_LOAD_64(ld64
, DEF_MEMOP(MO_UQ
))
3097 #if defined(TARGET_PPC64)
3098 GEN_QEMU_LOAD_64(ld64ur
, BSWAP_MEMOP(MO_UQ
))
3101 #define GEN_QEMU_STORE_TL(stop, op) \
3102 static void glue(gen_qemu_, stop)(DisasContext *ctx, \
3106 tcg_gen_qemu_st_tl(val, addr, ctx->mem_idx, op); \
3109 #if defined(TARGET_PPC64) || !defined(CONFIG_USER_ONLY)
3110 GEN_QEMU_STORE_TL(st8
, DEF_MEMOP(MO_UB
))
3112 GEN_QEMU_STORE_TL(st16
, DEF_MEMOP(MO_UW
))
3113 GEN_QEMU_STORE_TL(st32
, DEF_MEMOP(MO_UL
))
3115 GEN_QEMU_STORE_TL(st16r
, BSWAP_MEMOP(MO_UW
))
3116 GEN_QEMU_STORE_TL(st32r
, BSWAP_MEMOP(MO_UL
))
3118 #define GEN_QEMU_STORE_64(stop, op) \
3119 static void glue(gen_qemu_, glue(stop, _i64))(DisasContext *ctx, \
3123 tcg_gen_qemu_st_i64(val, addr, ctx->mem_idx, op); \
3126 GEN_QEMU_STORE_64(st8
, DEF_MEMOP(MO_UB
))
3127 GEN_QEMU_STORE_64(st16
, DEF_MEMOP(MO_UW
))
3128 GEN_QEMU_STORE_64(st32
, DEF_MEMOP(MO_UL
))
3129 GEN_QEMU_STORE_64(st64
, DEF_MEMOP(MO_UQ
))
3131 #if defined(TARGET_PPC64)
3132 GEN_QEMU_STORE_64(st64r
, BSWAP_MEMOP(MO_UQ
))
3135 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2, chk) \
3136 static void glue(gen_, name##x)(DisasContext *ctx) \
3140 gen_set_access_type(ctx, ACCESS_INT); \
3141 EA = tcg_temp_new(); \
3142 gen_addr_reg_index(ctx, EA); \
3143 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
3146 #define GEN_LDX(name, ldop, opc2, opc3, type) \
3147 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE, CHK_NONE)
3149 #define GEN_LDX_HVRM(name, ldop, opc2, opc3, type) \
3150 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE, CHK_HVRM)
3152 #define GEN_LDEPX(name, ldop, opc2, opc3) \
3153 static void glue(gen_, name##epx)(DisasContext *ctx) \
3157 gen_set_access_type(ctx, ACCESS_INT); \
3158 EA = tcg_temp_new(); \
3159 gen_addr_reg_index(ctx, EA); \
3160 tcg_gen_qemu_ld_tl(cpu_gpr[rD(ctx->opcode)], EA, PPC_TLB_EPID_LOAD, ldop);\
3163 GEN_LDEPX(lb
, DEF_MEMOP(MO_UB
), 0x1F, 0x02)
3164 GEN_LDEPX(lh
, DEF_MEMOP(MO_UW
), 0x1F, 0x08)
3165 GEN_LDEPX(lw
, DEF_MEMOP(MO_UL
), 0x1F, 0x00)
3166 #if defined(TARGET_PPC64)
3167 GEN_LDEPX(ld
, DEF_MEMOP(MO_UQ
), 0x1D, 0x00)
3170 #if defined(TARGET_PPC64)
3171 /* CI load/store variants */
3172 GEN_LDX_HVRM(ldcix
, ld64_i64
, 0x15, 0x1b, PPC_CILDST
)
3173 GEN_LDX_HVRM(lwzcix
, ld32u
, 0x15, 0x15, PPC_CILDST
)
3174 GEN_LDX_HVRM(lhzcix
, ld16u
, 0x15, 0x19, PPC_CILDST
)
3175 GEN_LDX_HVRM(lbzcix
, ld8u
, 0x15, 0x1a, PPC_CILDST
)
3178 /*** Integer store ***/
3179 #define GEN_STX_E(name, stop, opc2, opc3, type, type2, chk) \
3180 static void glue(gen_, name##x)(DisasContext *ctx) \
3184 gen_set_access_type(ctx, ACCESS_INT); \
3185 EA = tcg_temp_new(); \
3186 gen_addr_reg_index(ctx, EA); \
3187 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
3189 #define GEN_STX(name, stop, opc2, opc3, type) \
3190 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE, CHK_NONE)
3192 #define GEN_STX_HVRM(name, stop, opc2, opc3, type) \
3193 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE, CHK_HVRM)
3195 #define GEN_STEPX(name, stop, opc2, opc3) \
3196 static void glue(gen_, name##epx)(DisasContext *ctx) \
3200 gen_set_access_type(ctx, ACCESS_INT); \
3201 EA = tcg_temp_new(); \
3202 gen_addr_reg_index(ctx, EA); \
3203 tcg_gen_qemu_st_tl( \
3204 cpu_gpr[rD(ctx->opcode)], EA, PPC_TLB_EPID_STORE, stop); \
3207 GEN_STEPX(stb
, DEF_MEMOP(MO_UB
), 0x1F, 0x06)
3208 GEN_STEPX(sth
, DEF_MEMOP(MO_UW
), 0x1F, 0x0C)
3209 GEN_STEPX(stw
, DEF_MEMOP(MO_UL
), 0x1F, 0x04)
3210 #if defined(TARGET_PPC64)
3211 GEN_STEPX(std
, DEF_MEMOP(MO_UQ
), 0x1d, 0x04)
3214 #if defined(TARGET_PPC64)
3215 GEN_STX_HVRM(stdcix
, st64_i64
, 0x15, 0x1f, PPC_CILDST
)
3216 GEN_STX_HVRM(stwcix
, st32
, 0x15, 0x1c, PPC_CILDST
)
3217 GEN_STX_HVRM(sthcix
, st16
, 0x15, 0x1d, PPC_CILDST
)
3218 GEN_STX_HVRM(stbcix
, st8
, 0x15, 0x1e, PPC_CILDST
)
3220 /*** Integer load and store with byte reverse ***/
3223 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
);
3226 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
);
3228 #if defined(TARGET_PPC64)
3230 GEN_LDX_E(ldbr
, ld64ur_i64
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
, CHK_NONE
);
3232 GEN_STX_E(stdbr
, st64r_i64
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
, CHK_NONE
);
3233 #endif /* TARGET_PPC64 */
3236 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
);
3238 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
);
3240 /*** Integer load and store multiple ***/
3243 static void gen_lmw(DisasContext
*ctx
)
3249 gen_align_no_le(ctx
);
3252 gen_set_access_type(ctx
, ACCESS_INT
);
3253 t0
= tcg_temp_new();
3254 t1
= tcg_constant_i32(rD(ctx
->opcode
));
3255 gen_addr_imm_index(ctx
, t0
, 0);
3256 gen_helper_lmw(cpu_env
, t0
, t1
);
3260 static void gen_stmw(DisasContext
*ctx
)
3266 gen_align_no_le(ctx
);
3269 gen_set_access_type(ctx
, ACCESS_INT
);
3270 t0
= tcg_temp_new();
3271 t1
= tcg_constant_i32(rS(ctx
->opcode
));
3272 gen_addr_imm_index(ctx
, t0
, 0);
3273 gen_helper_stmw(cpu_env
, t0
, t1
);
3276 /*** Integer load and store strings ***/
3280 * PowerPC32 specification says we must generate an exception if rA is
3281 * in the range of registers to be loaded. In an other hand, IBM says
3282 * this is valid, but rA won't be loaded. For now, I'll follow the
3285 static void gen_lswi(DisasContext
*ctx
)
3289 int nb
= NB(ctx
->opcode
);
3290 int start
= rD(ctx
->opcode
);
3291 int ra
= rA(ctx
->opcode
);
3295 gen_align_no_le(ctx
);
3301 nr
= DIV_ROUND_UP(nb
, 4);
3302 if (unlikely(lsw_reg_in_range(start
, nr
, ra
))) {
3303 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
3306 gen_set_access_type(ctx
, ACCESS_INT
);
3307 t0
= tcg_temp_new();
3308 gen_addr_register(ctx
, t0
);
3309 t1
= tcg_constant_i32(nb
);
3310 t2
= tcg_constant_i32(start
);
3311 gen_helper_lsw(cpu_env
, t0
, t1
, t2
);
3315 static void gen_lswx(DisasContext
*ctx
)
3318 TCGv_i32 t1
, t2
, t3
;
3321 gen_align_no_le(ctx
);
3324 gen_set_access_type(ctx
, ACCESS_INT
);
3325 t0
= tcg_temp_new();
3326 gen_addr_reg_index(ctx
, t0
);
3327 t1
= tcg_constant_i32(rD(ctx
->opcode
));
3328 t2
= tcg_constant_i32(rA(ctx
->opcode
));
3329 t3
= tcg_constant_i32(rB(ctx
->opcode
));
3330 gen_helper_lswx(cpu_env
, t0
, t1
, t2
, t3
);
3334 static void gen_stswi(DisasContext
*ctx
)
3338 int nb
= NB(ctx
->opcode
);
3341 gen_align_no_le(ctx
);
3344 gen_set_access_type(ctx
, ACCESS_INT
);
3345 t0
= tcg_temp_new();
3346 gen_addr_register(ctx
, t0
);
3350 t1
= tcg_constant_i32(nb
);
3351 t2
= tcg_constant_i32(rS(ctx
->opcode
));
3352 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3356 static void gen_stswx(DisasContext
*ctx
)
3362 gen_align_no_le(ctx
);
3365 gen_set_access_type(ctx
, ACCESS_INT
);
3366 t0
= tcg_temp_new();
3367 gen_addr_reg_index(ctx
, t0
);
3368 t1
= tcg_temp_new_i32();
3369 tcg_gen_trunc_tl_i32(t1
, cpu_xer
);
3370 tcg_gen_andi_i32(t1
, t1
, 0x7F);
3371 t2
= tcg_constant_i32(rS(ctx
->opcode
));
3372 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3375 /*** Memory synchronisation ***/
3377 static void gen_eieio(DisasContext
*ctx
)
3379 TCGBar bar
= TCG_MO_ALL
;
3382 * eieio has complex semanitcs. It provides memory ordering between
3383 * operations in the set:
3384 * - loads from CI memory.
3385 * - stores to CI memory.
3386 * - stores to WT memory.
3388 * It separately also orders memory for operations in the set:
3389 * - stores to cacheble memory.
3391 * It also serializes instructions:
3394 * It separately serializes:
3395 * - tlbie and tlbsync.
3397 * And separately serializes:
3398 * - slbieg, slbiag, and slbsync.
3400 * The end result is that CI memory ordering requires TCG_MO_ALL
3401 * and it is not possible to special-case more relaxed ordering for
3402 * cacheable accesses. TCG_BAR_SC is required to provide this
3407 * POWER9 has a eieio instruction variant using bit 6 as a hint to
3408 * tell the CPU it is a store-forwarding barrier.
3410 if (ctx
->opcode
& 0x2000000) {
3412 * ISA says that "Reserved fields in instructions are ignored
3413 * by the processor". So ignore the bit 6 on non-POWER9 CPU but
3414 * as this is not an instruction software should be using,
3415 * complain to the user.
3417 if (!(ctx
->insns_flags2
& PPC2_ISA300
)) {
3418 qemu_log_mask(LOG_GUEST_ERROR
, "invalid eieio using bit 6 at @"
3419 TARGET_FMT_lx
"\n", ctx
->cia
);
3425 tcg_gen_mb(bar
| TCG_BAR_SC
);
3428 #if !defined(CONFIG_USER_ONLY)
3429 static inline void gen_check_tlb_flush(DisasContext
*ctx
, bool global
)
3434 if (!ctx
->lazy_tlb_flush
) {
3437 l
= gen_new_label();
3438 t
= tcg_temp_new_i32();
3439 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUPPCState
, tlb_need_flush
));
3440 tcg_gen_brcondi_i32(TCG_COND_EQ
, t
, 0, l
);
3442 gen_helper_check_tlb_flush_global(cpu_env
);
3444 gen_helper_check_tlb_flush_local(cpu_env
);
3449 static inline void gen_check_tlb_flush(DisasContext
*ctx
, bool global
) { }
3453 static void gen_isync(DisasContext
*ctx
)
3456 * We need to check for a pending TLB flush. This can only happen in
3457 * kernel mode however so check MSR_PR
3460 gen_check_tlb_flush(ctx
, false);
3462 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_SC
);
3463 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
3466 #define MEMOP_GET_SIZE(x) (1 << ((x) & MO_SIZE))
3468 static void gen_load_locked(DisasContext
*ctx
, MemOp memop
)
3470 TCGv gpr
= cpu_gpr
[rD(ctx
->opcode
)];
3471 TCGv t0
= tcg_temp_new();
3473 gen_set_access_type(ctx
, ACCESS_RES
);
3474 gen_addr_reg_index(ctx
, t0
);
3475 tcg_gen_qemu_ld_tl(gpr
, t0
, ctx
->mem_idx
, memop
| MO_ALIGN
);
3476 tcg_gen_mov_tl(cpu_reserve
, t0
);
3477 tcg_gen_movi_tl(cpu_reserve_length
, memop_size(memop
));
3478 tcg_gen_mov_tl(cpu_reserve_val
, gpr
);
3481 #define LARX(name, memop) \
3482 static void gen_##name(DisasContext *ctx) \
3484 gen_load_locked(ctx, memop); \
3488 LARX(lbarx
, DEF_MEMOP(MO_UB
))
3489 LARX(lharx
, DEF_MEMOP(MO_UW
))
3490 LARX(lwarx
, DEF_MEMOP(MO_UL
))
3492 static void gen_fetch_inc_conditional(DisasContext
*ctx
, MemOp memop
,
3493 TCGv EA
, TCGCond cond
, int addend
)
3495 TCGv t
= tcg_temp_new();
3496 TCGv t2
= tcg_temp_new();
3497 TCGv u
= tcg_temp_new();
3499 tcg_gen_qemu_ld_tl(t
, EA
, ctx
->mem_idx
, memop
);
3500 tcg_gen_addi_tl(t2
, EA
, MEMOP_GET_SIZE(memop
));
3501 tcg_gen_qemu_ld_tl(t2
, t2
, ctx
->mem_idx
, memop
);
3502 tcg_gen_addi_tl(u
, t
, addend
);
3504 /* E.g. for fetch and increment bounded... */
3505 /* mem(EA,s) = (t != t2 ? u = t + 1 : t) */
3506 tcg_gen_movcond_tl(cond
, u
, t
, t2
, u
, t
);
3507 tcg_gen_qemu_st_tl(u
, EA
, ctx
->mem_idx
, memop
);
3509 /* RT = (t != t2 ? t : u = 1<<(s*8-1)) */
3510 tcg_gen_movi_tl(u
, 1 << (MEMOP_GET_SIZE(memop
) * 8 - 1));
3511 tcg_gen_movcond_tl(cond
, cpu_gpr
[rD(ctx
->opcode
)], t
, t2
, t
, u
);
3514 static void gen_ld_atomic(DisasContext
*ctx
, MemOp memop
)
3516 uint32_t gpr_FC
= FC(ctx
->opcode
);
3517 TCGv EA
= tcg_temp_new();
3518 int rt
= rD(ctx
->opcode
);
3522 gen_addr_register(ctx
, EA
);
3524 src
= cpu_gpr
[(rt
+ 1) & 31];
3526 need_serial
= false;
3529 case 0: /* Fetch and add */
3530 tcg_gen_atomic_fetch_add_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3532 case 1: /* Fetch and xor */
3533 tcg_gen_atomic_fetch_xor_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3535 case 2: /* Fetch and or */
3536 tcg_gen_atomic_fetch_or_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3538 case 3: /* Fetch and 'and' */
3539 tcg_gen_atomic_fetch_and_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3541 case 4: /* Fetch and max unsigned */
3542 tcg_gen_atomic_fetch_umax_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3544 case 5: /* Fetch and max signed */
3545 tcg_gen_atomic_fetch_smax_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3547 case 6: /* Fetch and min unsigned */
3548 tcg_gen_atomic_fetch_umin_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3550 case 7: /* Fetch and min signed */
3551 tcg_gen_atomic_fetch_smin_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3554 tcg_gen_atomic_xchg_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3557 case 16: /* Compare and swap not equal */
3558 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3561 TCGv t0
= tcg_temp_new();
3562 TCGv t1
= tcg_temp_new();
3564 tcg_gen_qemu_ld_tl(t0
, EA
, ctx
->mem_idx
, memop
);
3565 if ((memop
& MO_SIZE
) == MO_64
|| TARGET_LONG_BITS
== 32) {
3566 tcg_gen_mov_tl(t1
, src
);
3568 tcg_gen_ext32u_tl(t1
, src
);
3570 tcg_gen_movcond_tl(TCG_COND_NE
, t1
, t0
, t1
,
3571 cpu_gpr
[(rt
+ 2) & 31], t0
);
3572 tcg_gen_qemu_st_tl(t1
, EA
, ctx
->mem_idx
, memop
);
3573 tcg_gen_mov_tl(dst
, t0
);
3577 case 24: /* Fetch and increment bounded */
3578 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3581 gen_fetch_inc_conditional(ctx
, memop
, EA
, TCG_COND_NE
, 1);
3584 case 25: /* Fetch and increment equal */
3585 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3588 gen_fetch_inc_conditional(ctx
, memop
, EA
, TCG_COND_EQ
, 1);
3591 case 28: /* Fetch and decrement bounded */
3592 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3595 gen_fetch_inc_conditional(ctx
, memop
, EA
, TCG_COND_NE
, -1);
3600 /* invoke data storage error handler */
3601 gen_exception_err(ctx
, POWERPC_EXCP_DSI
, POWERPC_EXCP_INVAL
);
3605 /* Restart with exclusive lock. */
3606 gen_helper_exit_atomic(cpu_env
);
3607 ctx
->base
.is_jmp
= DISAS_NORETURN
;
3611 static void gen_lwat(DisasContext
*ctx
)
3613 gen_ld_atomic(ctx
, DEF_MEMOP(MO_UL
));
3617 static void gen_ldat(DisasContext
*ctx
)
3619 gen_ld_atomic(ctx
, DEF_MEMOP(MO_UQ
));
3623 static void gen_st_atomic(DisasContext
*ctx
, MemOp memop
)
3625 uint32_t gpr_FC
= FC(ctx
->opcode
);
3626 TCGv EA
= tcg_temp_new();
3629 gen_addr_register(ctx
, EA
);
3630 src
= cpu_gpr
[rD(ctx
->opcode
)];
3631 discard
= tcg_temp_new();
3635 case 0: /* add and Store */
3636 tcg_gen_atomic_add_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3638 case 1: /* xor and Store */
3639 tcg_gen_atomic_xor_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3641 case 2: /* Or and Store */
3642 tcg_gen_atomic_or_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3644 case 3: /* 'and' and Store */
3645 tcg_gen_atomic_and_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3647 case 4: /* Store max unsigned */
3648 tcg_gen_atomic_umax_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3650 case 5: /* Store max signed */
3651 tcg_gen_atomic_smax_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3653 case 6: /* Store min unsigned */
3654 tcg_gen_atomic_umin_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3656 case 7: /* Store min signed */
3657 tcg_gen_atomic_smin_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3659 case 24: /* Store twin */
3660 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3661 /* Restart with exclusive lock. */
3662 gen_helper_exit_atomic(cpu_env
);
3663 ctx
->base
.is_jmp
= DISAS_NORETURN
;
3665 TCGv t
= tcg_temp_new();
3666 TCGv t2
= tcg_temp_new();
3667 TCGv s
= tcg_temp_new();
3668 TCGv s2
= tcg_temp_new();
3669 TCGv ea_plus_s
= tcg_temp_new();
3671 tcg_gen_qemu_ld_tl(t
, EA
, ctx
->mem_idx
, memop
);
3672 tcg_gen_addi_tl(ea_plus_s
, EA
, MEMOP_GET_SIZE(memop
));
3673 tcg_gen_qemu_ld_tl(t2
, ea_plus_s
, ctx
->mem_idx
, memop
);
3674 tcg_gen_movcond_tl(TCG_COND_EQ
, s
, t
, t2
, src
, t
);
3675 tcg_gen_movcond_tl(TCG_COND_EQ
, s2
, t
, t2
, src
, t2
);
3676 tcg_gen_qemu_st_tl(s
, EA
, ctx
->mem_idx
, memop
);
3677 tcg_gen_qemu_st_tl(s2
, ea_plus_s
, ctx
->mem_idx
, memop
);
3681 /* invoke data storage error handler */
3682 gen_exception_err(ctx
, POWERPC_EXCP_DSI
, POWERPC_EXCP_INVAL
);
3686 static void gen_stwat(DisasContext
*ctx
)
3688 gen_st_atomic(ctx
, DEF_MEMOP(MO_UL
));
3692 static void gen_stdat(DisasContext
*ctx
)
3694 gen_st_atomic(ctx
, DEF_MEMOP(MO_UQ
));
3698 static void gen_conditional_store(DisasContext
*ctx
, MemOp memop
)
3704 int rs
= rS(ctx
->opcode
);
3706 lfail
= gen_new_label();
3707 EA
= tcg_temp_new();
3708 cr0
= tcg_temp_new();
3709 t0
= tcg_temp_new();
3711 tcg_gen_mov_tl(cr0
, cpu_so
);
3712 gen_set_access_type(ctx
, ACCESS_RES
);
3713 gen_addr_reg_index(ctx
, EA
);
3714 tcg_gen_brcond_tl(TCG_COND_NE
, EA
, cpu_reserve
, lfail
);
3715 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_reserve_length
, memop_size(memop
), lfail
);
3717 tcg_gen_atomic_cmpxchg_tl(t0
, cpu_reserve
, cpu_reserve_val
,
3718 cpu_gpr
[rs
], ctx
->mem_idx
,
3719 DEF_MEMOP(memop
) | MO_ALIGN
);
3720 tcg_gen_setcond_tl(TCG_COND_EQ
, t0
, t0
, cpu_reserve_val
);
3721 tcg_gen_shli_tl(t0
, t0
, CRF_EQ_BIT
);
3722 tcg_gen_or_tl(cr0
, cr0
, t0
);
3724 gen_set_label(lfail
);
3725 tcg_gen_trunc_tl_i32(cpu_crf
[0], cr0
);
3726 tcg_gen_movi_tl(cpu_reserve
, -1);
3729 #define STCX(name, memop) \
3730 static void gen_##name(DisasContext *ctx) \
3732 gen_conditional_store(ctx, memop); \
3735 STCX(stbcx_
, DEF_MEMOP(MO_UB
))
3736 STCX(sthcx_
, DEF_MEMOP(MO_UW
))
3737 STCX(stwcx_
, DEF_MEMOP(MO_UL
))
3739 #if defined(TARGET_PPC64)
3741 LARX(ldarx
, DEF_MEMOP(MO_UQ
))
3743 STCX(stdcx_
, DEF_MEMOP(MO_UQ
))
3746 static void gen_lqarx(DisasContext
*ctx
)
3748 int rd
= rD(ctx
->opcode
);
3752 if (unlikely((rd
& 1) || (rd
== rA(ctx
->opcode
)) ||
3753 (rd
== rB(ctx
->opcode
)))) {
3754 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3758 gen_set_access_type(ctx
, ACCESS_RES
);
3759 EA
= tcg_temp_new();
3760 gen_addr_reg_index(ctx
, EA
);
3762 /* Note that the low part is always in RD+1, even in LE mode. */
3763 lo
= cpu_gpr
[rd
+ 1];
3766 t16
= tcg_temp_new_i128();
3767 tcg_gen_qemu_ld_i128(t16
, EA
, ctx
->mem_idx
, DEF_MEMOP(MO_128
| MO_ALIGN
));
3768 tcg_gen_extr_i128_i64(lo
, hi
, t16
);
3770 tcg_gen_mov_tl(cpu_reserve
, EA
);
3771 tcg_gen_movi_tl(cpu_reserve_length
, 16);
3772 tcg_gen_st_tl(hi
, cpu_env
, offsetof(CPUPPCState
, reserve_val
));
3773 tcg_gen_st_tl(lo
, cpu_env
, offsetof(CPUPPCState
, reserve_val2
));
3777 static void gen_stqcx_(DisasContext
*ctx
)
3783 int rs
= rS(ctx
->opcode
);
3785 if (unlikely(rs
& 1)) {
3786 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3790 lfail
= gen_new_label();
3791 EA
= tcg_temp_new();
3792 cr0
= tcg_temp_new();
3794 tcg_gen_mov_tl(cr0
, cpu_so
);
3795 gen_set_access_type(ctx
, ACCESS_RES
);
3796 gen_addr_reg_index(ctx
, EA
);
3797 tcg_gen_brcond_tl(TCG_COND_NE
, EA
, cpu_reserve
, lfail
);
3798 tcg_gen_brcondi_tl(TCG_COND_NE
, cpu_reserve_length
, 16, lfail
);
3800 cmp
= tcg_temp_new_i128();
3801 val
= tcg_temp_new_i128();
3803 tcg_gen_concat_i64_i128(cmp
, cpu_reserve_val2
, cpu_reserve_val
);
3805 /* Note that the low part is always in RS+1, even in LE mode. */
3806 tcg_gen_concat_i64_i128(val
, cpu_gpr
[rs
+ 1], cpu_gpr
[rs
]);
3808 tcg_gen_atomic_cmpxchg_i128(val
, cpu_reserve
, cmp
, val
, ctx
->mem_idx
,
3809 DEF_MEMOP(MO_128
| MO_ALIGN
));
3811 t0
= tcg_temp_new();
3812 t1
= tcg_temp_new();
3813 tcg_gen_extr_i128_i64(t1
, t0
, val
);
3815 tcg_gen_xor_tl(t1
, t1
, cpu_reserve_val2
);
3816 tcg_gen_xor_tl(t0
, t0
, cpu_reserve_val
);
3817 tcg_gen_or_tl(t0
, t0
, t1
);
3819 tcg_gen_setcondi_tl(TCG_COND_EQ
, t0
, t0
, 0);
3820 tcg_gen_shli_tl(t0
, t0
, CRF_EQ_BIT
);
3821 tcg_gen_or_tl(cr0
, cr0
, t0
);
3823 gen_set_label(lfail
);
3824 tcg_gen_trunc_tl_i32(cpu_crf
[0], cr0
);
3825 tcg_gen_movi_tl(cpu_reserve
, -1);
3827 #endif /* defined(TARGET_PPC64) */
3830 static void gen_sync(DisasContext
*ctx
)
3832 TCGBar bar
= TCG_MO_ALL
;
3833 uint32_t l
= (ctx
->opcode
>> 21) & 3;
3835 if ((l
== 1) && (ctx
->insns_flags2
& PPC2_MEM_LWSYNC
)) {
3836 bar
= TCG_MO_LD_LD
| TCG_MO_LD_ST
| TCG_MO_ST_ST
;
3840 * We may need to check for a pending TLB flush.
3842 * We do this on ptesync (l == 2) on ppc64 and any sync pn ppc32.
3844 * Additionally, this can only happen in kernel mode however so
3845 * check MSR_PR as well.
3847 if (((l
== 2) || !(ctx
->insns_flags
& PPC_64B
)) && !ctx
->pr
) {
3848 gen_check_tlb_flush(ctx
, true);
3851 tcg_gen_mb(bar
| TCG_BAR_SC
);
3855 static void gen_wait(DisasContext
*ctx
)
3859 if (ctx
->insns_flags
& PPC_WAIT
) {
3860 /* v2.03-v2.07 define an older incompatible 'wait' encoding. */
3862 if (ctx
->insns_flags2
& PPC2_PM_ISA206
) {
3863 /* v2.06 introduced the WC field. WC > 0 may be treated as no-op. */
3864 wc
= WC(ctx
->opcode
);
3869 } else if (ctx
->insns_flags2
& PPC2_ISA300
) {
3870 /* v3.0 defines a new 'wait' encoding. */
3871 wc
= WC(ctx
->opcode
);
3872 if (ctx
->insns_flags2
& PPC2_ISA310
) {
3873 uint32_t pl
= PL(ctx
->opcode
);
3875 /* WC 1,2 may be treated as no-op. WC 3 is reserved. */
3881 /* PL 1-3 are reserved. If WC=2 then the insn is treated as noop. */
3882 if (pl
> 0 && wc
!= 2) {
3887 } else { /* ISA300 */
3888 /* WC 1-3 are reserved */
3896 warn_report("wait instruction decoded with wrong ISA flags.");
3902 * wait without WC field or with WC=0 waits for an exception / interrupt
3906 TCGv_i32 t0
= tcg_constant_i32(1);
3907 tcg_gen_st_i32(t0
, cpu_env
,
3908 -offsetof(PowerPCCPU
, env
) + offsetof(CPUState
, halted
));
3909 /* Stop translation, as the CPU is supposed to sleep from now */
3910 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
3914 * Other wait types must not just wait until an exception occurs because
3915 * ignoring their other wake-up conditions could cause a hang.
3917 * For v2.06 and 2.07, wc=1,2,3 are architected but may be implemented as
3920 * wc=1 and wc=3 explicitly allow the instruction to be treated as a no-op.
3922 * wc=2 waits for an implementation-specific condition, such could be
3923 * always true, so it can be implemented as a no-op.
3925 * For v3.1, wc=1,2 are architected but may be implemented as no-ops.
3927 * wc=1 (waitrsv) waits for an exception or a reservation to be lost.
3928 * Reservation-loss may have implementation-specific conditions, so it
3929 * can be implemented as a no-op.
3931 * wc=2 waits for an exception or an amount of time to pass. This
3932 * amount is implementation-specific so it can be implemented as a
3935 * ISA v3.1 allows for execution to resume "in the rare case of
3936 * an implementation-dependent event", so in any case software must
3937 * not depend on the architected resumption condition to become
3938 * true, so no-op implementations should be architecturally correct
3943 #if defined(TARGET_PPC64)
3944 static void gen_doze(DisasContext
*ctx
)
3946 #if defined(CONFIG_USER_ONLY)
3952 t
= tcg_constant_i32(PPC_PM_DOZE
);
3953 gen_helper_pminsn(cpu_env
, t
);
3954 /* Stop translation, as the CPU is supposed to sleep from now */
3955 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
3956 #endif /* defined(CONFIG_USER_ONLY) */
3959 static void gen_nap(DisasContext
*ctx
)
3961 #if defined(CONFIG_USER_ONLY)
3967 t
= tcg_constant_i32(PPC_PM_NAP
);
3968 gen_helper_pminsn(cpu_env
, t
);
3969 /* Stop translation, as the CPU is supposed to sleep from now */
3970 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
3971 #endif /* defined(CONFIG_USER_ONLY) */
3974 static void gen_stop(DisasContext
*ctx
)
3976 #if defined(CONFIG_USER_ONLY)
3982 t
= tcg_constant_i32(PPC_PM_STOP
);
3983 gen_helper_pminsn(cpu_env
, t
);
3984 /* Stop translation, as the CPU is supposed to sleep from now */
3985 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
3986 #endif /* defined(CONFIG_USER_ONLY) */
3989 static void gen_sleep(DisasContext
*ctx
)
3991 #if defined(CONFIG_USER_ONLY)
3997 t
= tcg_constant_i32(PPC_PM_SLEEP
);
3998 gen_helper_pminsn(cpu_env
, t
);
3999 /* Stop translation, as the CPU is supposed to sleep from now */
4000 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
4001 #endif /* defined(CONFIG_USER_ONLY) */
4004 static void gen_rvwinkle(DisasContext
*ctx
)
4006 #if defined(CONFIG_USER_ONLY)
4012 t
= tcg_constant_i32(PPC_PM_RVWINKLE
);
4013 gen_helper_pminsn(cpu_env
, t
);
4014 /* Stop translation, as the CPU is supposed to sleep from now */
4015 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
4016 #endif /* defined(CONFIG_USER_ONLY) */
4018 #endif /* #if defined(TARGET_PPC64) */
4020 static inline void gen_update_cfar(DisasContext
*ctx
, target_ulong nip
)
4022 #if defined(TARGET_PPC64)
4023 if (ctx
->has_cfar
) {
4024 tcg_gen_movi_tl(cpu_cfar
, nip
);
4029 #if defined(TARGET_PPC64)
4030 static void pmu_count_insns(DisasContext
*ctx
)
4033 * Do not bother calling the helper if the PMU isn't counting
4036 if (!ctx
->pmu_insn_cnt
) {
4040 #if !defined(CONFIG_USER_ONLY)
4045 * The PMU insns_inc() helper stops the internal PMU timer if a
4046 * counter overflows happens. In that case, if the guest is
4047 * running with icount and we do not handle it beforehand,
4048 * the helper can trigger a 'bad icount read'.
4050 translator_io_start(&ctx
->base
);
4052 /* Avoid helper calls when only PMC5-6 are enabled. */
4053 if (!ctx
->pmc_other
) {
4054 l
= gen_new_label();
4055 t0
= tcg_temp_new();
4057 gen_load_spr(t0
, SPR_POWER_PMC5
);
4058 tcg_gen_addi_tl(t0
, t0
, ctx
->base
.num_insns
);
4059 gen_store_spr(SPR_POWER_PMC5
, t0
);
4060 /* Check for overflow, if it's enabled */
4061 if (ctx
->mmcr0_pmcjce
) {
4062 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, PMC_COUNTER_NEGATIVE_VAL
, l
);
4063 gen_helper_handle_pmc5_overflow(cpu_env
);
4068 gen_helper_insns_inc(cpu_env
, tcg_constant_i32(ctx
->base
.num_insns
));
4072 * User mode can read (but not write) PMC5 and start/stop
4073 * the PMU via MMCR0_FC. In this case just increment
4074 * PMC5 with base.num_insns.
4076 TCGv t0
= tcg_temp_new();
4078 gen_load_spr(t0
, SPR_POWER_PMC5
);
4079 tcg_gen_addi_tl(t0
, t0
, ctx
->base
.num_insns
);
4080 gen_store_spr(SPR_POWER_PMC5
, t0
);
4081 #endif /* #if !defined(CONFIG_USER_ONLY) */
4084 static void pmu_count_insns(DisasContext
*ctx
)
4088 #endif /* #if defined(TARGET_PPC64) */
4090 static inline bool use_goto_tb(DisasContext
*ctx
, target_ulong dest
)
4092 return translator_use_goto_tb(&ctx
->base
, dest
);
4095 static void gen_lookup_and_goto_ptr(DisasContext
*ctx
)
4097 if (unlikely(ctx
->singlestep_enabled
)) {
4098 gen_debug_exception(ctx
);
4101 * tcg_gen_lookup_and_goto_ptr will exit the TB if
4102 * CF_NO_GOTO_PTR is set. Count insns now.
4104 if (ctx
->base
.tb
->flags
& CF_NO_GOTO_PTR
) {
4105 pmu_count_insns(ctx
);
4108 tcg_gen_lookup_and_goto_ptr();
4113 static void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
4115 if (NARROW_MODE(ctx
)) {
4116 dest
= (uint32_t) dest
;
4118 if (use_goto_tb(ctx
, dest
)) {
4119 pmu_count_insns(ctx
);
4121 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
4122 tcg_gen_exit_tb(ctx
->base
.tb
, n
);
4124 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
4125 gen_lookup_and_goto_ptr(ctx
);
4129 static inline void gen_setlr(DisasContext
*ctx
, target_ulong nip
)
4131 if (NARROW_MODE(ctx
)) {
4132 nip
= (uint32_t)nip
;
4134 tcg_gen_movi_tl(cpu_lr
, nip
);
4138 static void gen_b(DisasContext
*ctx
)
4140 target_ulong li
, target
;
4142 /* sign extend LI */
4143 li
= LI(ctx
->opcode
);
4144 li
= (li
^ 0x02000000) - 0x02000000;
4145 if (likely(AA(ctx
->opcode
) == 0)) {
4146 target
= ctx
->cia
+ li
;
4150 if (LK(ctx
->opcode
)) {
4151 gen_setlr(ctx
, ctx
->base
.pc_next
);
4153 gen_update_cfar(ctx
, ctx
->cia
);
4154 gen_goto_tb(ctx
, 0, target
);
4155 ctx
->base
.is_jmp
= DISAS_NORETURN
;
4163 static void gen_bcond(DisasContext
*ctx
, int type
)
4165 uint32_t bo
= BO(ctx
->opcode
);
4169 if (type
== BCOND_LR
|| type
== BCOND_CTR
|| type
== BCOND_TAR
) {
4170 target
= tcg_temp_new();
4171 if (type
== BCOND_CTR
) {
4172 tcg_gen_mov_tl(target
, cpu_ctr
);
4173 } else if (type
== BCOND_TAR
) {
4174 gen_load_spr(target
, SPR_TAR
);
4176 tcg_gen_mov_tl(target
, cpu_lr
);
4181 if (LK(ctx
->opcode
)) {
4182 gen_setlr(ctx
, ctx
->base
.pc_next
);
4184 l1
= gen_new_label();
4185 if ((bo
& 0x4) == 0) {
4186 /* Decrement and test CTR */
4187 TCGv temp
= tcg_temp_new();
4189 if (type
== BCOND_CTR
) {
4191 * All ISAs up to v3 describe this form of bcctr as invalid but
4192 * some processors, ie. 64-bit server processors compliant with
4193 * arch 2.x, do implement a "test and decrement" logic instead,
4194 * as described in their respective UMs. This logic involves CTR
4195 * to act as both the branch target and a counter, which makes
4196 * it basically useless and thus never used in real code.
4198 * This form was hence chosen to trigger extra micro-architectural
4199 * side-effect on real HW needed for the Spectre v2 workaround.
4200 * It is up to guests that implement such workaround, ie. linux, to
4201 * use this form in a way it just triggers the side-effect without
4202 * doing anything else harmful.
4204 if (unlikely(!is_book3s_arch2x(ctx
))) {
4205 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
4209 if (NARROW_MODE(ctx
)) {
4210 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
4212 tcg_gen_mov_tl(temp
, cpu_ctr
);
4215 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
4217 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
4219 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
4221 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
4222 if (NARROW_MODE(ctx
)) {
4223 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
4225 tcg_gen_mov_tl(temp
, cpu_ctr
);
4228 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
4230 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
4234 if ((bo
& 0x10) == 0) {
4236 uint32_t bi
= BI(ctx
->opcode
);
4237 uint32_t mask
= 0x08 >> (bi
& 0x03);
4238 TCGv_i32 temp
= tcg_temp_new_i32();
4241 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
4242 tcg_gen_brcondi_i32(TCG_COND_EQ
, temp
, 0, l1
);
4244 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
4245 tcg_gen_brcondi_i32(TCG_COND_NE
, temp
, 0, l1
);
4248 gen_update_cfar(ctx
, ctx
->cia
);
4249 if (type
== BCOND_IM
) {
4250 target_ulong li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
4251 if (likely(AA(ctx
->opcode
) == 0)) {
4252 gen_goto_tb(ctx
, 0, ctx
->cia
+ li
);
4254 gen_goto_tb(ctx
, 0, li
);
4257 if (NARROW_MODE(ctx
)) {
4258 tcg_gen_andi_tl(cpu_nip
, target
, (uint32_t)~3);
4260 tcg_gen_andi_tl(cpu_nip
, target
, ~3);
4262 gen_lookup_and_goto_ptr(ctx
);
4264 if ((bo
& 0x14) != 0x14) {
4265 /* fallthrough case */
4267 gen_goto_tb(ctx
, 1, ctx
->base
.pc_next
);
4269 ctx
->base
.is_jmp
= DISAS_NORETURN
;
4272 static void gen_bc(DisasContext
*ctx
)
4274 gen_bcond(ctx
, BCOND_IM
);
4277 static void gen_bcctr(DisasContext
*ctx
)
4279 gen_bcond(ctx
, BCOND_CTR
);
4282 static void gen_bclr(DisasContext
*ctx
)
4284 gen_bcond(ctx
, BCOND_LR
);
4287 static void gen_bctar(DisasContext
*ctx
)
4289 gen_bcond(ctx
, BCOND_TAR
);
4292 /*** Condition register logical ***/
4293 #define GEN_CRLOGIC(name, tcg_op, opc) \
4294 static void glue(gen_, name)(DisasContext *ctx) \
4299 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
4300 t0 = tcg_temp_new_i32(); \
4302 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
4304 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
4306 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
4307 t1 = tcg_temp_new_i32(); \
4308 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
4310 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
4312 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
4314 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
4315 tcg_op(t0, t0, t1); \
4316 bitmask = 0x08 >> (crbD(ctx->opcode) & 0x03); \
4317 tcg_gen_andi_i32(t0, t0, bitmask); \
4318 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
4319 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
4323 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08);
4325 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04);
4327 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09);
4329 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07);
4331 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01);
4333 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E);
4335 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D);
4337 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06);
4340 static void gen_mcrf(DisasContext
*ctx
)
4342 tcg_gen_mov_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfS(ctx
->opcode
)]);
4345 /*** System linkage ***/
4347 /* rfi (supervisor only) */
4348 static void gen_rfi(DisasContext
*ctx
)
4350 #if defined(CONFIG_USER_ONLY)
4354 * This instruction doesn't exist anymore on 64-bit server
4355 * processors compliant with arch 2.x
4357 if (is_book3s_arch2x(ctx
)) {
4358 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
4361 /* Restore CPU state */
4363 translator_io_start(&ctx
->base
);
4364 gen_update_cfar(ctx
, ctx
->cia
);
4365 gen_helper_rfi(cpu_env
);
4366 ctx
->base
.is_jmp
= DISAS_EXIT
;
4370 #if defined(TARGET_PPC64)
4371 static void gen_rfid(DisasContext
*ctx
)
4373 #if defined(CONFIG_USER_ONLY)
4376 /* Restore CPU state */
4378 translator_io_start(&ctx
->base
);
4379 gen_update_cfar(ctx
, ctx
->cia
);
4380 gen_helper_rfid(cpu_env
);
4381 ctx
->base
.is_jmp
= DISAS_EXIT
;
4385 #if !defined(CONFIG_USER_ONLY)
4386 static void gen_rfscv(DisasContext
*ctx
)
4388 #if defined(CONFIG_USER_ONLY)
4391 /* Restore CPU state */
4393 translator_io_start(&ctx
->base
);
4394 gen_update_cfar(ctx
, ctx
->cia
);
4395 gen_helper_rfscv(cpu_env
);
4396 ctx
->base
.is_jmp
= DISAS_EXIT
;
4401 static void gen_hrfid(DisasContext
*ctx
)
4403 #if defined(CONFIG_USER_ONLY)
4406 /* Restore CPU state */
4408 gen_helper_hrfid(cpu_env
);
4409 ctx
->base
.is_jmp
= DISAS_EXIT
;
4415 #if defined(CONFIG_USER_ONLY)
4416 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
4418 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
4419 #define POWERPC_SYSCALL_VECTORED POWERPC_EXCP_SYSCALL_VECTORED
4421 static void gen_sc(DisasContext
*ctx
)
4425 lev
= (ctx
->opcode
>> 5) & 0x7F;
4426 gen_exception_err(ctx
, POWERPC_SYSCALL
, lev
);
4429 #if defined(TARGET_PPC64)
4430 #if !defined(CONFIG_USER_ONLY)
4431 static void gen_scv(DisasContext
*ctx
)
4433 uint32_t lev
= (ctx
->opcode
>> 5) & 0x7F;
4435 /* Set the PC back to the faulting instruction. */
4436 gen_update_nip(ctx
, ctx
->cia
);
4437 gen_helper_scv(cpu_env
, tcg_constant_i32(lev
));
4439 ctx
->base
.is_jmp
= DISAS_NORETURN
;
4446 /* Check for unconditional traps (always or never) */
4447 static bool check_unconditional_trap(DisasContext
*ctx
)
4450 if (TO(ctx
->opcode
) == 0) {
4454 if (TO(ctx
->opcode
) == 31) {
4455 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_TRAP
);
4462 static void gen_tw(DisasContext
*ctx
)
4466 if (check_unconditional_trap(ctx
)) {
4469 t0
= tcg_constant_i32(TO(ctx
->opcode
));
4470 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
4475 static void gen_twi(DisasContext
*ctx
)
4480 if (check_unconditional_trap(ctx
)) {
4483 t0
= tcg_constant_tl(SIMM(ctx
->opcode
));
4484 t1
= tcg_constant_i32(TO(ctx
->opcode
));
4485 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4488 #if defined(TARGET_PPC64)
4490 static void gen_td(DisasContext
*ctx
)
4494 if (check_unconditional_trap(ctx
)) {
4497 t0
= tcg_constant_i32(TO(ctx
->opcode
));
4498 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
4503 static void gen_tdi(DisasContext
*ctx
)
4508 if (check_unconditional_trap(ctx
)) {
4511 t0
= tcg_constant_tl(SIMM(ctx
->opcode
));
4512 t1
= tcg_constant_i32(TO(ctx
->opcode
));
4513 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4517 /*** Processor control ***/
4520 static void gen_mcrxr(DisasContext
*ctx
)
4522 TCGv_i32 t0
= tcg_temp_new_i32();
4523 TCGv_i32 t1
= tcg_temp_new_i32();
4524 TCGv_i32 dst
= cpu_crf
[crfD(ctx
->opcode
)];
4526 tcg_gen_trunc_tl_i32(t0
, cpu_so
);
4527 tcg_gen_trunc_tl_i32(t1
, cpu_ov
);
4528 tcg_gen_trunc_tl_i32(dst
, cpu_ca
);
4529 tcg_gen_shli_i32(t0
, t0
, 3);
4530 tcg_gen_shli_i32(t1
, t1
, 2);
4531 tcg_gen_shli_i32(dst
, dst
, 1);
4532 tcg_gen_or_i32(dst
, dst
, t0
);
4533 tcg_gen_or_i32(dst
, dst
, t1
);
4535 tcg_gen_movi_tl(cpu_so
, 0);
4536 tcg_gen_movi_tl(cpu_ov
, 0);
4537 tcg_gen_movi_tl(cpu_ca
, 0);
4542 static void gen_mcrxrx(DisasContext
*ctx
)
4544 TCGv t0
= tcg_temp_new();
4545 TCGv t1
= tcg_temp_new();
4546 TCGv_i32 dst
= cpu_crf
[crfD(ctx
->opcode
)];
4548 /* copy OV and OV32 */
4549 tcg_gen_shli_tl(t0
, cpu_ov
, 1);
4550 tcg_gen_or_tl(t0
, t0
, cpu_ov32
);
4551 tcg_gen_shli_tl(t0
, t0
, 2);
4552 /* copy CA and CA32 */
4553 tcg_gen_shli_tl(t1
, cpu_ca
, 1);
4554 tcg_gen_or_tl(t1
, t1
, cpu_ca32
);
4555 tcg_gen_or_tl(t0
, t0
, t1
);
4556 tcg_gen_trunc_tl_i32(dst
, t0
);
4561 static void gen_mfcr(DisasContext
*ctx
)
4565 if (likely(ctx
->opcode
& 0x00100000)) {
4566 crm
= CRM(ctx
->opcode
);
4567 if (likely(crm
&& ((crm
& (crm
- 1)) == 0))) {
4569 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_crf
[7 - crn
]);
4570 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)],
4571 cpu_gpr
[rD(ctx
->opcode
)], crn
* 4);
4574 TCGv_i32 t0
= tcg_temp_new_i32();
4575 tcg_gen_mov_i32(t0
, cpu_crf
[0]);
4576 tcg_gen_shli_i32(t0
, t0
, 4);
4577 tcg_gen_or_i32(t0
, t0
, cpu_crf
[1]);
4578 tcg_gen_shli_i32(t0
, t0
, 4);
4579 tcg_gen_or_i32(t0
, t0
, cpu_crf
[2]);
4580 tcg_gen_shli_i32(t0
, t0
, 4);
4581 tcg_gen_or_i32(t0
, t0
, cpu_crf
[3]);
4582 tcg_gen_shli_i32(t0
, t0
, 4);
4583 tcg_gen_or_i32(t0
, t0
, cpu_crf
[4]);
4584 tcg_gen_shli_i32(t0
, t0
, 4);
4585 tcg_gen_or_i32(t0
, t0
, cpu_crf
[5]);
4586 tcg_gen_shli_i32(t0
, t0
, 4);
4587 tcg_gen_or_i32(t0
, t0
, cpu_crf
[6]);
4588 tcg_gen_shli_i32(t0
, t0
, 4);
4589 tcg_gen_or_i32(t0
, t0
, cpu_crf
[7]);
4590 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4595 static void gen_mfmsr(DisasContext
*ctx
)
4598 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_msr
);
4602 static inline void gen_op_mfspr(DisasContext
*ctx
)
4604 void (*read_cb
)(DisasContext
*ctx
, int gprn
, int sprn
);
4605 uint32_t sprn
= SPR(ctx
->opcode
);
4607 #if defined(CONFIG_USER_ONLY)
4608 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
4611 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
4612 } else if (ctx
->hv
) {
4613 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
4615 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
4618 if (likely(read_cb
!= NULL
)) {
4619 if (likely(read_cb
!= SPR_NOACCESS
)) {
4620 (*read_cb
)(ctx
, rD(ctx
->opcode
), sprn
);
4622 /* Privilege exception */
4624 * This is a hack to avoid warnings when running Linux:
4625 * this OS breaks the PowerPC virtualisation model,
4626 * allowing userland application to read the PVR
4628 if (sprn
!= SPR_PVR
) {
4629 qemu_log_mask(LOG_GUEST_ERROR
, "Trying to read privileged spr "
4630 "%d (0x%03x) at " TARGET_FMT_lx
"\n", sprn
, sprn
,
4633 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4636 /* ISA 2.07 defines these as no-ops */
4637 if ((ctx
->insns_flags2
& PPC2_ISA207S
) &&
4638 (sprn
>= 808 && sprn
<= 811)) {
4643 qemu_log_mask(LOG_GUEST_ERROR
,
4644 "Trying to read invalid spr %d (0x%03x) at "
4645 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->cia
);
4648 * The behaviour depends on MSR:PR and SPR# bit 0x10, it can
4649 * generate a priv, a hv emu or a no-op
4653 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4656 if (ctx
->pr
|| sprn
== 0 || sprn
== 4 || sprn
== 5 || sprn
== 6) {
4657 gen_hvpriv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4663 static void gen_mfspr(DisasContext
*ctx
)
4669 static void gen_mftb(DisasContext
*ctx
)
4675 static void gen_mtcrf(DisasContext
*ctx
)
4679 crm
= CRM(ctx
->opcode
);
4680 if (likely((ctx
->opcode
& 0x00100000))) {
4681 if (crm
&& ((crm
& (crm
- 1)) == 0)) {
4682 TCGv_i32 temp
= tcg_temp_new_i32();
4684 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
4685 tcg_gen_shri_i32(temp
, temp
, crn
* 4);
4686 tcg_gen_andi_i32(cpu_crf
[7 - crn
], temp
, 0xf);
4689 TCGv_i32 temp
= tcg_temp_new_i32();
4690 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
4691 for (crn
= 0 ; crn
< 8 ; crn
++) {
4692 if (crm
& (1 << crn
)) {
4693 tcg_gen_shri_i32(cpu_crf
[7 - crn
], temp
, crn
* 4);
4694 tcg_gen_andi_i32(cpu_crf
[7 - crn
], cpu_crf
[7 - crn
], 0xf);
4701 #if defined(TARGET_PPC64)
4702 static void gen_mtmsrd(DisasContext
*ctx
)
4704 if (unlikely(!is_book3s_arch2x(ctx
))) {
4711 #if !defined(CONFIG_USER_ONLY)
4715 t0
= tcg_temp_new();
4716 t1
= tcg_temp_new();
4718 translator_io_start(&ctx
->base
);
4720 if (ctx
->opcode
& 0x00010000) {
4721 /* L=1 form only updates EE and RI */
4722 mask
= (1ULL << MSR_RI
) | (1ULL << MSR_EE
);
4724 /* mtmsrd does not alter HV, S, ME, or LE */
4725 mask
= ~((1ULL << MSR_LE
) | (1ULL << MSR_ME
) | (1ULL << MSR_S
) |
4728 * XXX: we need to update nip before the store if we enter
4729 * power saving mode, we will exit the loop directly from
4732 gen_update_nip(ctx
, ctx
->base
.pc_next
);
4735 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], mask
);
4736 tcg_gen_andi_tl(t1
, cpu_msr
, ~mask
);
4737 tcg_gen_or_tl(t0
, t0
, t1
);
4739 gen_helper_store_msr(cpu_env
, t0
);
4741 /* Must stop the translation as machine state (may have) changed */
4742 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
4743 #endif /* !defined(CONFIG_USER_ONLY) */
4745 #endif /* defined(TARGET_PPC64) */
4747 static void gen_mtmsr(DisasContext
*ctx
)
4751 #if !defined(CONFIG_USER_ONLY)
4753 target_ulong mask
= 0xFFFFFFFF;
4755 t0
= tcg_temp_new();
4756 t1
= tcg_temp_new();
4758 translator_io_start(&ctx
->base
);
4759 if (ctx
->opcode
& 0x00010000) {
4760 /* L=1 form only updates EE and RI */
4761 mask
&= (1ULL << MSR_RI
) | (1ULL << MSR_EE
);
4763 /* mtmsr does not alter S, ME, or LE */
4764 mask
&= ~((1ULL << MSR_LE
) | (1ULL << MSR_ME
) | (1ULL << MSR_S
));
4767 * XXX: we need to update nip before the store if we enter
4768 * power saving mode, we will exit the loop directly from
4771 gen_update_nip(ctx
, ctx
->base
.pc_next
);
4774 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], mask
);
4775 tcg_gen_andi_tl(t1
, cpu_msr
, ~mask
);
4776 tcg_gen_or_tl(t0
, t0
, t1
);
4778 gen_helper_store_msr(cpu_env
, t0
);
4780 /* Must stop the translation as machine state (may have) changed */
4781 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
4786 static void gen_mtspr(DisasContext
*ctx
)
4788 void (*write_cb
)(DisasContext
*ctx
, int sprn
, int gprn
);
4789 uint32_t sprn
= SPR(ctx
->opcode
);
4791 #if defined(CONFIG_USER_ONLY)
4792 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
4795 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
4796 } else if (ctx
->hv
) {
4797 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
4799 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
4802 if (likely(write_cb
!= NULL
)) {
4803 if (likely(write_cb
!= SPR_NOACCESS
)) {
4804 (*write_cb
)(ctx
, sprn
, rS(ctx
->opcode
));
4806 /* Privilege exception */
4807 qemu_log_mask(LOG_GUEST_ERROR
, "Trying to write privileged spr "
4808 "%d (0x%03x) at " TARGET_FMT_lx
"\n", sprn
, sprn
,
4810 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4813 /* ISA 2.07 defines these as no-ops */
4814 if ((ctx
->insns_flags2
& PPC2_ISA207S
) &&
4815 (sprn
>= 808 && sprn
<= 811)) {
4821 qemu_log_mask(LOG_GUEST_ERROR
,
4822 "Trying to write invalid spr %d (0x%03x) at "
4823 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->cia
);
4827 * The behaviour depends on MSR:PR and SPR# bit 0x10, it can
4828 * generate a priv, a hv emu or a no-op
4832 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4835 if (ctx
->pr
|| sprn
== 0) {
4836 gen_hvpriv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4842 #if defined(TARGET_PPC64)
4844 static void gen_setb(DisasContext
*ctx
)
4846 TCGv_i32 t0
= tcg_temp_new_i32();
4847 TCGv_i32 t8
= tcg_constant_i32(8);
4848 TCGv_i32 tm1
= tcg_constant_i32(-1);
4849 int crf
= crfS(ctx
->opcode
);
4851 tcg_gen_setcondi_i32(TCG_COND_GEU
, t0
, cpu_crf
[crf
], 4);
4852 tcg_gen_movcond_i32(TCG_COND_GEU
, t0
, cpu_crf
[crf
], t8
, tm1
, t0
);
4853 tcg_gen_ext_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4857 /*** Cache management ***/
4860 static void gen_dcbf(DisasContext
*ctx
)
4862 /* XXX: specification says this is treated as a load by the MMU */
4864 gen_set_access_type(ctx
, ACCESS_CACHE
);
4865 t0
= tcg_temp_new();
4866 gen_addr_reg_index(ctx
, t0
);
4867 gen_qemu_ld8u(ctx
, t0
, t0
);
4870 /* dcbfep (external PID dcbf) */
4871 static void gen_dcbfep(DisasContext
*ctx
)
4873 /* XXX: specification says this is treated as a load by the MMU */
4876 gen_set_access_type(ctx
, ACCESS_CACHE
);
4877 t0
= tcg_temp_new();
4878 gen_addr_reg_index(ctx
, t0
);
4879 tcg_gen_qemu_ld_tl(t0
, t0
, PPC_TLB_EPID_LOAD
, DEF_MEMOP(MO_UB
));
4882 /* dcbi (Supervisor only) */
4883 static void gen_dcbi(DisasContext
*ctx
)
4885 #if defined(CONFIG_USER_ONLY)
4891 EA
= tcg_temp_new();
4892 gen_set_access_type(ctx
, ACCESS_CACHE
);
4893 gen_addr_reg_index(ctx
, EA
);
4894 val
= tcg_temp_new();
4895 /* XXX: specification says this should be treated as a store by the MMU */
4896 gen_qemu_ld8u(ctx
, val
, EA
);
4897 gen_qemu_st8(ctx
, val
, EA
);
4898 #endif /* defined(CONFIG_USER_ONLY) */
4902 static void gen_dcbst(DisasContext
*ctx
)
4904 /* XXX: specification say this is treated as a load by the MMU */
4906 gen_set_access_type(ctx
, ACCESS_CACHE
);
4907 t0
= tcg_temp_new();
4908 gen_addr_reg_index(ctx
, t0
);
4909 gen_qemu_ld8u(ctx
, t0
, t0
);
4912 /* dcbstep (dcbstep External PID version) */
4913 static void gen_dcbstep(DisasContext
*ctx
)
4915 /* XXX: specification say this is treated as a load by the MMU */
4917 gen_set_access_type(ctx
, ACCESS_CACHE
);
4918 t0
= tcg_temp_new();
4919 gen_addr_reg_index(ctx
, t0
);
4920 tcg_gen_qemu_ld_tl(t0
, t0
, PPC_TLB_EPID_LOAD
, DEF_MEMOP(MO_UB
));
4924 static void gen_dcbt(DisasContext
*ctx
)
4927 * interpreted as no-op
4928 * XXX: specification say this is treated as a load by the MMU but
4929 * does not generate any exception
4934 static void gen_dcbtep(DisasContext
*ctx
)
4937 * interpreted as no-op
4938 * XXX: specification say this is treated as a load by the MMU but
4939 * does not generate any exception
4944 static void gen_dcbtst(DisasContext
*ctx
)
4947 * interpreted as no-op
4948 * XXX: specification say this is treated as a load by the MMU but
4949 * does not generate any exception
4954 static void gen_dcbtstep(DisasContext
*ctx
)
4957 * interpreted as no-op
4958 * XXX: specification say this is treated as a load by the MMU but
4959 * does not generate any exception
4964 static void gen_dcbtls(DisasContext
*ctx
)
4966 /* Always fails locking the cache */
4967 TCGv t0
= tcg_temp_new();
4968 gen_load_spr(t0
, SPR_Exxx_L1CSR0
);
4969 tcg_gen_ori_tl(t0
, t0
, L1CSR0_CUL
);
4970 gen_store_spr(SPR_Exxx_L1CSR0
, t0
);
4974 static void gen_dcblc(DisasContext
*ctx
)
4977 * interpreted as no-op
4982 static void gen_dcbz(DisasContext
*ctx
)
4987 gen_set_access_type(ctx
, ACCESS_CACHE
);
4988 tcgv_addr
= tcg_temp_new();
4989 tcgv_op
= tcg_constant_i32(ctx
->opcode
& 0x03FF000);
4990 gen_addr_reg_index(ctx
, tcgv_addr
);
4991 gen_helper_dcbz(cpu_env
, tcgv_addr
, tcgv_op
);
4995 static void gen_dcbzep(DisasContext
*ctx
)
5000 gen_set_access_type(ctx
, ACCESS_CACHE
);
5001 tcgv_addr
= tcg_temp_new();
5002 tcgv_op
= tcg_constant_i32(ctx
->opcode
& 0x03FF000);
5003 gen_addr_reg_index(ctx
, tcgv_addr
);
5004 gen_helper_dcbzep(cpu_env
, tcgv_addr
, tcgv_op
);
5008 static void gen_dst(DisasContext
*ctx
)
5010 if (rA(ctx
->opcode
) == 0) {
5011 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5013 /* interpreted as no-op */
5018 static void gen_dstst(DisasContext
*ctx
)
5020 if (rA(ctx
->opcode
) == 0) {
5021 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5023 /* interpreted as no-op */
5029 static void gen_dss(DisasContext
*ctx
)
5031 /* interpreted as no-op */
5035 static void gen_icbi(DisasContext
*ctx
)
5038 gen_set_access_type(ctx
, ACCESS_CACHE
);
5039 t0
= tcg_temp_new();
5040 gen_addr_reg_index(ctx
, t0
);
5041 gen_helper_icbi(cpu_env
, t0
);
5045 static void gen_icbiep(DisasContext
*ctx
)
5048 gen_set_access_type(ctx
, ACCESS_CACHE
);
5049 t0
= tcg_temp_new();
5050 gen_addr_reg_index(ctx
, t0
);
5051 gen_helper_icbiep(cpu_env
, t0
);
5056 static void gen_dcba(DisasContext
*ctx
)
5059 * interpreted as no-op
5060 * XXX: specification say this is treated as a store by the MMU
5061 * but does not generate any exception
5065 /*** Segment register manipulation ***/
5066 /* Supervisor only: */
5069 static void gen_mfsr(DisasContext
*ctx
)
5071 #if defined(CONFIG_USER_ONLY)
5077 t0
= tcg_constant_tl(SR(ctx
->opcode
));
5078 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5079 #endif /* defined(CONFIG_USER_ONLY) */
5083 static void gen_mfsrin(DisasContext
*ctx
)
5085 #if defined(CONFIG_USER_ONLY)
5091 t0
= tcg_temp_new();
5092 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
5093 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5094 #endif /* defined(CONFIG_USER_ONLY) */
5098 static void gen_mtsr(DisasContext
*ctx
)
5100 #if defined(CONFIG_USER_ONLY)
5106 t0
= tcg_constant_tl(SR(ctx
->opcode
));
5107 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
5108 #endif /* defined(CONFIG_USER_ONLY) */
5112 static void gen_mtsrin(DisasContext
*ctx
)
5114 #if defined(CONFIG_USER_ONLY)
5120 t0
= tcg_temp_new();
5121 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
5122 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rD(ctx
->opcode
)]);
5123 #endif /* defined(CONFIG_USER_ONLY) */
5126 #if defined(TARGET_PPC64)
5127 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
5130 static void gen_mfsr_64b(DisasContext
*ctx
)
5132 #if defined(CONFIG_USER_ONLY)
5138 t0
= tcg_constant_tl(SR(ctx
->opcode
));
5139 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5140 #endif /* defined(CONFIG_USER_ONLY) */
5144 static void gen_mfsrin_64b(DisasContext
*ctx
)
5146 #if defined(CONFIG_USER_ONLY)
5152 t0
= tcg_temp_new();
5153 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
5154 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5155 #endif /* defined(CONFIG_USER_ONLY) */
5159 static void gen_mtsr_64b(DisasContext
*ctx
)
5161 #if defined(CONFIG_USER_ONLY)
5167 t0
= tcg_constant_tl(SR(ctx
->opcode
));
5168 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
5169 #endif /* defined(CONFIG_USER_ONLY) */
5173 static void gen_mtsrin_64b(DisasContext
*ctx
)
5175 #if defined(CONFIG_USER_ONLY)
5181 t0
= tcg_temp_new();
5182 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
5183 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
5184 #endif /* defined(CONFIG_USER_ONLY) */
5187 #endif /* defined(TARGET_PPC64) */
5189 /*** Lookaside buffer management ***/
5190 /* Optional & supervisor only: */
5193 static void gen_tlbia(DisasContext
*ctx
)
5195 #if defined(CONFIG_USER_ONLY)
5200 gen_helper_tlbia(cpu_env
);
5201 #endif /* defined(CONFIG_USER_ONLY) */
5205 static void gen_tlbsync(DisasContext
*ctx
)
5207 #if defined(CONFIG_USER_ONLY)
5212 CHK_SV(ctx
); /* If gtse is set then tlbsync is supervisor privileged */
5214 CHK_HV(ctx
); /* Else hypervisor privileged */
5217 /* BookS does both ptesync and tlbsync make tlbsync a nop for server */
5218 if (ctx
->insns_flags
& PPC_BOOKE
) {
5219 gen_check_tlb_flush(ctx
, true);
5221 #endif /* defined(CONFIG_USER_ONLY) */
5224 /*** External control ***/
5228 static void gen_eciwx(DisasContext
*ctx
)
5231 /* Should check EAR[E] ! */
5232 gen_set_access_type(ctx
, ACCESS_EXT
);
5233 t0
= tcg_temp_new();
5234 gen_addr_reg_index(ctx
, t0
);
5235 tcg_gen_qemu_ld_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, ctx
->mem_idx
,
5236 DEF_MEMOP(MO_UL
| MO_ALIGN
));
5240 static void gen_ecowx(DisasContext
*ctx
)
5243 /* Should check EAR[E] ! */
5244 gen_set_access_type(ctx
, ACCESS_EXT
);
5245 t0
= tcg_temp_new();
5246 gen_addr_reg_index(ctx
, t0
);
5247 tcg_gen_qemu_st_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, ctx
->mem_idx
,
5248 DEF_MEMOP(MO_UL
| MO_ALIGN
));
5251 /* 602 - 603 - G2 TLB management */
5254 static void gen_tlbld_6xx(DisasContext
*ctx
)
5256 #if defined(CONFIG_USER_ONLY)
5260 gen_helper_6xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5261 #endif /* defined(CONFIG_USER_ONLY) */
5265 static void gen_tlbli_6xx(DisasContext
*ctx
)
5267 #if defined(CONFIG_USER_ONLY)
5271 gen_helper_6xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5272 #endif /* defined(CONFIG_USER_ONLY) */
5275 /* BookE specific instructions */
5277 /* XXX: not implemented on 440 ? */
5278 static void gen_mfapidi(DisasContext
*ctx
)
5281 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5284 /* XXX: not implemented on 440 ? */
5285 static void gen_tlbiva(DisasContext
*ctx
)
5287 #if defined(CONFIG_USER_ONLY)
5293 t0
= tcg_temp_new();
5294 gen_addr_reg_index(ctx
, t0
);
5295 gen_helper_tlbiva(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5296 #endif /* defined(CONFIG_USER_ONLY) */
5299 /* All 405 MAC instructions are translated here */
5300 static inline void gen_405_mulladd_insn(DisasContext
*ctx
, int opc2
, int opc3
,
5301 int ra
, int rb
, int rt
, int Rc
)
5305 t0
= tcg_temp_new();
5306 t1
= tcg_temp_new();
5308 switch (opc3
& 0x0D) {
5310 /* macchw - macchw. - macchwo - macchwo. */
5311 /* macchws - macchws. - macchwso - macchwso. */
5312 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5313 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5314 /* mulchw - mulchw. */
5315 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5316 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5317 tcg_gen_ext16s_tl(t1
, t1
);
5320 /* macchwu - macchwu. - macchwuo - macchwuo. */
5321 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5322 /* mulchwu - mulchwu. */
5323 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5324 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5325 tcg_gen_ext16u_tl(t1
, t1
);
5328 /* machhw - machhw. - machhwo - machhwo. */
5329 /* machhws - machhws. - machhwso - machhwso. */
5330 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5331 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5332 /* mulhhw - mulhhw. */
5333 tcg_gen_sari_tl(t0
, cpu_gpr
[ra
], 16);
5334 tcg_gen_ext16s_tl(t0
, t0
);
5335 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5336 tcg_gen_ext16s_tl(t1
, t1
);
5339 /* machhwu - machhwu. - machhwuo - machhwuo. */
5340 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5341 /* mulhhwu - mulhhwu. */
5342 tcg_gen_shri_tl(t0
, cpu_gpr
[ra
], 16);
5343 tcg_gen_ext16u_tl(t0
, t0
);
5344 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5345 tcg_gen_ext16u_tl(t1
, t1
);
5348 /* maclhw - maclhw. - maclhwo - maclhwo. */
5349 /* maclhws - maclhws. - maclhwso - maclhwso. */
5350 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5351 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5352 /* mullhw - mullhw. */
5353 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5354 tcg_gen_ext16s_tl(t1
, cpu_gpr
[rb
]);
5357 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5358 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5359 /* mullhwu - mullhwu. */
5360 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5361 tcg_gen_ext16u_tl(t1
, cpu_gpr
[rb
]);
5365 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5366 tcg_gen_mul_tl(t1
, t0
, t1
);
5368 /* nmultiply-and-accumulate (0x0E) */
5369 tcg_gen_sub_tl(t0
, cpu_gpr
[rt
], t1
);
5371 /* multiply-and-accumulate (0x0C) */
5372 tcg_gen_add_tl(t0
, cpu_gpr
[rt
], t1
);
5376 /* Check overflow and/or saturate */
5377 TCGLabel
*l1
= gen_new_label();
5380 /* Start with XER OV disabled, the most likely case */
5381 tcg_gen_movi_tl(cpu_ov
, 0);
5385 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t1
);
5386 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
5387 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t0
);
5388 tcg_gen_brcondi_tl(TCG_COND_LT
, t1
, 0, l1
);
5391 tcg_gen_sari_tl(t0
, cpu_gpr
[rt
], 31);
5392 tcg_gen_xori_tl(t0
, t0
, 0x7fffffff);
5396 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
5399 tcg_gen_movi_tl(t0
, UINT32_MAX
);
5403 /* Check overflow */
5404 tcg_gen_movi_tl(cpu_ov
, 1);
5405 tcg_gen_movi_tl(cpu_so
, 1);
5408 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
5411 tcg_gen_mul_tl(cpu_gpr
[rt
], t0
, t1
);
5413 if (unlikely(Rc
) != 0) {
5415 gen_set_Rc0(ctx
, cpu_gpr
[rt
]);
5419 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5420 static void glue(gen_, name)(DisasContext *ctx) \
5422 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5423 rD(ctx->opcode), Rc(ctx->opcode)); \
5426 /* macchw - macchw. */
5427 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
5428 /* macchwo - macchwo. */
5429 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
5430 /* macchws - macchws. */
5431 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
5432 /* macchwso - macchwso. */
5433 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
5434 /* macchwsu - macchwsu. */
5435 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
5436 /* macchwsuo - macchwsuo. */
5437 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
5438 /* macchwu - macchwu. */
5439 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
5440 /* macchwuo - macchwuo. */
5441 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
5442 /* machhw - machhw. */
5443 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
5444 /* machhwo - machhwo. */
5445 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
5446 /* machhws - machhws. */
5447 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
5448 /* machhwso - machhwso. */
5449 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
5450 /* machhwsu - machhwsu. */
5451 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
5452 /* machhwsuo - machhwsuo. */
5453 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
5454 /* machhwu - machhwu. */
5455 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
5456 /* machhwuo - machhwuo. */
5457 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
5458 /* maclhw - maclhw. */
5459 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
5460 /* maclhwo - maclhwo. */
5461 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
5462 /* maclhws - maclhws. */
5463 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
5464 /* maclhwso - maclhwso. */
5465 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
5466 /* maclhwu - maclhwu. */
5467 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
5468 /* maclhwuo - maclhwuo. */
5469 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
5470 /* maclhwsu - maclhwsu. */
5471 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
5472 /* maclhwsuo - maclhwsuo. */
5473 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
5474 /* nmacchw - nmacchw. */
5475 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
5476 /* nmacchwo - nmacchwo. */
5477 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
5478 /* nmacchws - nmacchws. */
5479 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
5480 /* nmacchwso - nmacchwso. */
5481 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
5482 /* nmachhw - nmachhw. */
5483 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
5484 /* nmachhwo - nmachhwo. */
5485 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
5486 /* nmachhws - nmachhws. */
5487 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
5488 /* nmachhwso - nmachhwso. */
5489 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
5490 /* nmaclhw - nmaclhw. */
5491 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
5492 /* nmaclhwo - nmaclhwo. */
5493 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
5494 /* nmaclhws - nmaclhws. */
5495 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
5496 /* nmaclhwso - nmaclhwso. */
5497 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
5499 /* mulchw - mulchw. */
5500 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
5501 /* mulchwu - mulchwu. */
5502 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
5503 /* mulhhw - mulhhw. */
5504 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
5505 /* mulhhwu - mulhhwu. */
5506 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
5507 /* mullhw - mullhw. */
5508 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
5509 /* mullhwu - mullhwu. */
5510 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
5513 static void gen_mfdcr(DisasContext
*ctx
)
5515 #if defined(CONFIG_USER_ONLY)
5521 dcrn
= tcg_constant_tl(SPR(ctx
->opcode
));
5522 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, dcrn
);
5523 #endif /* defined(CONFIG_USER_ONLY) */
5527 static void gen_mtdcr(DisasContext
*ctx
)
5529 #if defined(CONFIG_USER_ONLY)
5535 dcrn
= tcg_constant_tl(SPR(ctx
->opcode
));
5536 gen_helper_store_dcr(cpu_env
, dcrn
, cpu_gpr
[rS(ctx
->opcode
)]);
5537 #endif /* defined(CONFIG_USER_ONLY) */
5541 /* XXX: not implemented on 440 ? */
5542 static void gen_mfdcrx(DisasContext
*ctx
)
5544 #if defined(CONFIG_USER_ONLY)
5548 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5549 cpu_gpr
[rA(ctx
->opcode
)]);
5550 /* Note: Rc update flag set leads to undefined state of Rc0 */
5551 #endif /* defined(CONFIG_USER_ONLY) */
5555 /* XXX: not implemented on 440 ? */
5556 static void gen_mtdcrx(DisasContext
*ctx
)
5558 #if defined(CONFIG_USER_ONLY)
5562 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5563 cpu_gpr
[rS(ctx
->opcode
)]);
5564 /* Note: Rc update flag set leads to undefined state of Rc0 */
5565 #endif /* defined(CONFIG_USER_ONLY) */
5569 static void gen_dccci(DisasContext
*ctx
)
5572 /* interpreted as no-op */
5576 static void gen_dcread(DisasContext
*ctx
)
5578 #if defined(CONFIG_USER_ONLY)
5584 gen_set_access_type(ctx
, ACCESS_CACHE
);
5585 EA
= tcg_temp_new();
5586 gen_addr_reg_index(ctx
, EA
);
5587 val
= tcg_temp_new();
5588 gen_qemu_ld32u(ctx
, val
, EA
);
5589 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], EA
);
5590 #endif /* defined(CONFIG_USER_ONLY) */
5594 static void gen_icbt_40x(DisasContext
*ctx
)
5597 * interpreted as no-op
5598 * XXX: specification say this is treated as a load by the MMU but
5599 * does not generate any exception
5604 static void gen_iccci(DisasContext
*ctx
)
5607 /* interpreted as no-op */
5611 static void gen_icread(DisasContext
*ctx
)
5614 /* interpreted as no-op */
5617 /* rfci (supervisor only) */
5618 static void gen_rfci_40x(DisasContext
*ctx
)
5620 #if defined(CONFIG_USER_ONLY)
5624 /* Restore CPU state */
5625 gen_helper_40x_rfci(cpu_env
);
5626 ctx
->base
.is_jmp
= DISAS_EXIT
;
5627 #endif /* defined(CONFIG_USER_ONLY) */
5630 static void gen_rfci(DisasContext
*ctx
)
5632 #if defined(CONFIG_USER_ONLY)
5636 /* Restore CPU state */
5637 gen_helper_rfci(cpu_env
);
5638 ctx
->base
.is_jmp
= DISAS_EXIT
;
5639 #endif /* defined(CONFIG_USER_ONLY) */
5642 /* BookE specific */
5644 /* XXX: not implemented on 440 ? */
5645 static void gen_rfdi(DisasContext
*ctx
)
5647 #if defined(CONFIG_USER_ONLY)
5651 /* Restore CPU state */
5652 gen_helper_rfdi(cpu_env
);
5653 ctx
->base
.is_jmp
= DISAS_EXIT
;
5654 #endif /* defined(CONFIG_USER_ONLY) */
5657 /* XXX: not implemented on 440 ? */
5658 static void gen_rfmci(DisasContext
*ctx
)
5660 #if defined(CONFIG_USER_ONLY)
5664 /* Restore CPU state */
5665 gen_helper_rfmci(cpu_env
);
5666 ctx
->base
.is_jmp
= DISAS_EXIT
;
5667 #endif /* defined(CONFIG_USER_ONLY) */
5670 /* TLB management - PowerPC 405 implementation */
5673 static void gen_tlbre_40x(DisasContext
*ctx
)
5675 #if defined(CONFIG_USER_ONLY)
5679 switch (rB(ctx
->opcode
)) {
5681 gen_helper_4xx_tlbre_hi(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5682 cpu_gpr
[rA(ctx
->opcode
)]);
5685 gen_helper_4xx_tlbre_lo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5686 cpu_gpr
[rA(ctx
->opcode
)]);
5689 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5692 #endif /* defined(CONFIG_USER_ONLY) */
5695 /* tlbsx - tlbsx. */
5696 static void gen_tlbsx_40x(DisasContext
*ctx
)
5698 #if defined(CONFIG_USER_ONLY)
5704 t0
= tcg_temp_new();
5705 gen_addr_reg_index(ctx
, t0
);
5706 gen_helper_4xx_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5707 if (Rc(ctx
->opcode
)) {
5708 TCGLabel
*l1
= gen_new_label();
5709 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
5710 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
5711 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
5714 #endif /* defined(CONFIG_USER_ONLY) */
5718 static void gen_tlbwe_40x(DisasContext
*ctx
)
5720 #if defined(CONFIG_USER_ONLY)
5725 switch (rB(ctx
->opcode
)) {
5727 gen_helper_4xx_tlbwe_hi(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5728 cpu_gpr
[rS(ctx
->opcode
)]);
5731 gen_helper_4xx_tlbwe_lo(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5732 cpu_gpr
[rS(ctx
->opcode
)]);
5735 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5738 #endif /* defined(CONFIG_USER_ONLY) */
5741 /* TLB management - PowerPC 440 implementation */
5744 static void gen_tlbre_440(DisasContext
*ctx
)
5746 #if defined(CONFIG_USER_ONLY)
5751 switch (rB(ctx
->opcode
)) {
5756 TCGv_i32 t0
= tcg_constant_i32(rB(ctx
->opcode
));
5757 gen_helper_440_tlbre(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5758 t0
, cpu_gpr
[rA(ctx
->opcode
)]);
5762 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5765 #endif /* defined(CONFIG_USER_ONLY) */
5768 /* tlbsx - tlbsx. */
5769 static void gen_tlbsx_440(DisasContext
*ctx
)
5771 #if defined(CONFIG_USER_ONLY)
5777 t0
= tcg_temp_new();
5778 gen_addr_reg_index(ctx
, t0
);
5779 gen_helper_440_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5780 if (Rc(ctx
->opcode
)) {
5781 TCGLabel
*l1
= gen_new_label();
5782 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
5783 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
5784 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
5787 #endif /* defined(CONFIG_USER_ONLY) */
5791 static void gen_tlbwe_440(DisasContext
*ctx
)
5793 #if defined(CONFIG_USER_ONLY)
5797 switch (rB(ctx
->opcode
)) {
5802 TCGv_i32 t0
= tcg_constant_i32(rB(ctx
->opcode
));
5803 gen_helper_440_tlbwe(cpu_env
, t0
, cpu_gpr
[rA(ctx
->opcode
)],
5804 cpu_gpr
[rS(ctx
->opcode
)]);
5808 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5811 #endif /* defined(CONFIG_USER_ONLY) */
5814 /* TLB management - PowerPC BookE 2.06 implementation */
5817 static void gen_tlbre_booke206(DisasContext
*ctx
)
5819 #if defined(CONFIG_USER_ONLY)
5823 gen_helper_booke206_tlbre(cpu_env
);
5824 #endif /* defined(CONFIG_USER_ONLY) */
5827 /* tlbsx - tlbsx. */
5828 static void gen_tlbsx_booke206(DisasContext
*ctx
)
5830 #if defined(CONFIG_USER_ONLY)
5836 if (rA(ctx
->opcode
)) {
5837 t0
= tcg_temp_new();
5838 tcg_gen_add_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
5840 t0
= cpu_gpr
[rB(ctx
->opcode
)];
5842 gen_helper_booke206_tlbsx(cpu_env
, t0
);
5843 #endif /* defined(CONFIG_USER_ONLY) */
5847 static void gen_tlbwe_booke206(DisasContext
*ctx
)
5849 #if defined(CONFIG_USER_ONLY)
5853 gen_helper_booke206_tlbwe(cpu_env
);
5854 #endif /* defined(CONFIG_USER_ONLY) */
5857 static void gen_tlbivax_booke206(DisasContext
*ctx
)
5859 #if defined(CONFIG_USER_ONLY)
5865 t0
= tcg_temp_new();
5866 gen_addr_reg_index(ctx
, t0
);
5867 gen_helper_booke206_tlbivax(cpu_env
, t0
);
5868 #endif /* defined(CONFIG_USER_ONLY) */
5871 static void gen_tlbilx_booke206(DisasContext
*ctx
)
5873 #if defined(CONFIG_USER_ONLY)
5879 t0
= tcg_temp_new();
5880 gen_addr_reg_index(ctx
, t0
);
5882 switch ((ctx
->opcode
>> 21) & 0x3) {
5884 gen_helper_booke206_tlbilx0(cpu_env
, t0
);
5887 gen_helper_booke206_tlbilx1(cpu_env
, t0
);
5890 gen_helper_booke206_tlbilx3(cpu_env
, t0
);
5893 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5896 #endif /* defined(CONFIG_USER_ONLY) */
5900 static void gen_wrtee(DisasContext
*ctx
)
5902 #if defined(CONFIG_USER_ONLY)
5908 t0
= tcg_temp_new();
5909 tcg_gen_andi_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)], (1 << MSR_EE
));
5910 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
5911 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
5912 gen_ppc_maybe_interrupt(ctx
);
5914 * Stop translation to have a chance to raise an exception if we
5915 * just set msr_ee to 1
5917 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
5918 #endif /* defined(CONFIG_USER_ONLY) */
5922 static void gen_wrteei(DisasContext
*ctx
)
5924 #if defined(CONFIG_USER_ONLY)
5928 if (ctx
->opcode
& 0x00008000) {
5929 tcg_gen_ori_tl(cpu_msr
, cpu_msr
, (1 << MSR_EE
));
5930 gen_ppc_maybe_interrupt(ctx
);
5931 /* Stop translation to have a chance to raise an exception */
5932 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
5934 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
5936 #endif /* defined(CONFIG_USER_ONLY) */
5939 /* PowerPC 440 specific instructions */
5942 static void gen_dlmzb(DisasContext
*ctx
)
5944 TCGv_i32 t0
= tcg_constant_i32(Rc(ctx
->opcode
));
5945 gen_helper_dlmzb(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
5946 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
5949 /* mbar replaces eieio on 440 */
5950 static void gen_mbar(DisasContext
*ctx
)
5952 /* interpreted as no-op */
5955 /* msync replaces sync on 440 */
5956 static void gen_msync_4xx(DisasContext
*ctx
)
5958 /* Only e500 seems to treat reserved bits as invalid */
5959 if ((ctx
->insns_flags2
& PPC2_BOOKE206
) &&
5960 (ctx
->opcode
& 0x03FFF801)) {
5961 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5963 /* otherwise interpreted as no-op */
5967 static void gen_icbt_440(DisasContext
*ctx
)
5970 * interpreted as no-op
5971 * XXX: specification say this is treated as a load by the MMU but
5972 * does not generate any exception
5976 #if defined(TARGET_PPC64)
5977 static void gen_maddld(DisasContext
*ctx
)
5979 TCGv_i64 t1
= tcg_temp_new_i64();
5981 tcg_gen_mul_i64(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
5982 tcg_gen_add_i64(cpu_gpr
[rD(ctx
->opcode
)], t1
, cpu_gpr
[rC(ctx
->opcode
)]);
5985 /* maddhd maddhdu */
5986 static void gen_maddhd_maddhdu(DisasContext
*ctx
)
5988 TCGv_i64 lo
= tcg_temp_new_i64();
5989 TCGv_i64 hi
= tcg_temp_new_i64();
5990 TCGv_i64 t1
= tcg_temp_new_i64();
5992 if (Rc(ctx
->opcode
)) {
5993 tcg_gen_mulu2_i64(lo
, hi
, cpu_gpr
[rA(ctx
->opcode
)],
5994 cpu_gpr
[rB(ctx
->opcode
)]);
5995 tcg_gen_movi_i64(t1
, 0);
5997 tcg_gen_muls2_i64(lo
, hi
, cpu_gpr
[rA(ctx
->opcode
)],
5998 cpu_gpr
[rB(ctx
->opcode
)]);
5999 tcg_gen_sari_i64(t1
, cpu_gpr
[rC(ctx
->opcode
)], 63);
6001 tcg_gen_add2_i64(t1
, cpu_gpr
[rD(ctx
->opcode
)], lo
, hi
,
6002 cpu_gpr
[rC(ctx
->opcode
)], t1
);
6004 #endif /* defined(TARGET_PPC64) */
6006 static void gen_tbegin(DisasContext
*ctx
)
6008 if (unlikely(!ctx
->tm_enabled
)) {
6009 gen_exception_err(ctx
, POWERPC_EXCP_FU
, FSCR_IC_TM
);
6012 gen_helper_tbegin(cpu_env
);
6015 #define GEN_TM_NOOP(name) \
6016 static inline void gen_##name(DisasContext *ctx) \
6018 if (unlikely(!ctx->tm_enabled)) { \
6019 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
6023 * Because tbegin always fails in QEMU, these user \
6024 * space instructions all have a simple implementation: \
6026 * CR[0] = 0b0 || MSR[TS] || 0b0 \
6027 * = 0b0 || 0b00 || 0b0 \
6029 tcg_gen_movi_i32(cpu_crf[0], 0); \
6033 GEN_TM_NOOP(tabort
);
6034 GEN_TM_NOOP(tabortwc
);
6035 GEN_TM_NOOP(tabortwci
);
6036 GEN_TM_NOOP(tabortdc
);
6037 GEN_TM_NOOP(tabortdci
);
6040 static inline void gen_cp_abort(DisasContext
*ctx
)
6045 #define GEN_CP_PASTE_NOOP(name) \
6046 static inline void gen_##name(DisasContext *ctx) \
6049 * Generate invalid exception until we have an \
6050 * implementation of the copy paste facility \
6055 GEN_CP_PASTE_NOOP(copy
)
6056 GEN_CP_PASTE_NOOP(paste
)
6058 static void gen_tcheck(DisasContext
*ctx
)
6060 if (unlikely(!ctx
->tm_enabled
)) {
6061 gen_exception_err(ctx
, POWERPC_EXCP_FU
, FSCR_IC_TM
);
6065 * Because tbegin always fails, the tcheck implementation is
6068 * CR[CRF] = TDOOMED || MSR[TS] || 0b0
6069 * = 0b1 || 0b00 || 0b0
6071 tcg_gen_movi_i32(cpu_crf
[crfD(ctx
->opcode
)], 0x8);
6074 #if defined(CONFIG_USER_ONLY)
6075 #define GEN_TM_PRIV_NOOP(name) \
6076 static inline void gen_##name(DisasContext *ctx) \
6078 gen_priv_opc(ctx); \
6083 #define GEN_TM_PRIV_NOOP(name) \
6084 static inline void gen_##name(DisasContext *ctx) \
6087 if (unlikely(!ctx->tm_enabled)) { \
6088 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
6092 * Because tbegin always fails, the implementation is \
6095 * CR[0] = 0b0 || MSR[TS] || 0b0 \
6096 * = 0b0 || 0b00 | 0b0 \
6098 tcg_gen_movi_i32(cpu_crf[0], 0); \
6103 GEN_TM_PRIV_NOOP(treclaim
);
6104 GEN_TM_PRIV_NOOP(trechkpt
);
6106 static inline void get_fpr(TCGv_i64 dst
, int regno
)
6108 tcg_gen_ld_i64(dst
, cpu_env
, fpr_offset(regno
));
6111 static inline void set_fpr(int regno
, TCGv_i64 src
)
6113 tcg_gen_st_i64(src
, cpu_env
, fpr_offset(regno
));
6115 * Before PowerISA v3.1 the result of doubleword 1 of the VSR
6116 * corresponding to the target FPR was undefined. However,
6117 * most (if not all) real hardware were setting the result to 0.
6118 * Starting at ISA v3.1, the result for doubleword 1 is now defined
6121 tcg_gen_st_i64(tcg_constant_i64(0), cpu_env
, vsr64_offset(regno
, false));
6124 static inline void get_avr64(TCGv_i64 dst
, int regno
, bool high
)
6126 tcg_gen_ld_i64(dst
, cpu_env
, avr64_offset(regno
, high
));
6129 static inline void set_avr64(int regno
, TCGv_i64 src
, bool high
)
6131 tcg_gen_st_i64(src
, cpu_env
, avr64_offset(regno
, high
));
6135 * Helpers for decodetree used by !function for decoding arguments.
6137 static int times_2(DisasContext
*ctx
, int x
)
6142 static int times_4(DisasContext
*ctx
, int x
)
6147 static int times_16(DisasContext
*ctx
, int x
)
6152 static int64_t dw_compose_ea(DisasContext
*ctx
, int x
)
6154 return deposit64(0xfffffffffffffe00, 3, 6, x
);
6158 * Helpers for trans_* functions to check for specific insns flags.
6159 * Use token pasting to ensure that we use the proper flag with the
6162 #define REQUIRE_INSNS_FLAGS(CTX, NAME) \
6164 if (((CTX)->insns_flags & PPC_##NAME) == 0) { \
6169 #define REQUIRE_INSNS_FLAGS2(CTX, NAME) \
6171 if (((CTX)->insns_flags2 & PPC2_##NAME) == 0) { \
6176 /* Then special-case the check for 64-bit so that we elide code for ppc32. */
6177 #if TARGET_LONG_BITS == 32
6178 # define REQUIRE_64BIT(CTX) return false
6180 # define REQUIRE_64BIT(CTX) REQUIRE_INSNS_FLAGS(CTX, 64B)
6183 #define REQUIRE_VECTOR(CTX) \
6185 if (unlikely(!(CTX)->altivec_enabled)) { \
6186 gen_exception((CTX), POWERPC_EXCP_VPU); \
6191 #define REQUIRE_VSX(CTX) \
6193 if (unlikely(!(CTX)->vsx_enabled)) { \
6194 gen_exception((CTX), POWERPC_EXCP_VSXU); \
6199 #define REQUIRE_FPU(ctx) \
6201 if (unlikely(!(ctx)->fpu_enabled)) { \
6202 gen_exception((ctx), POWERPC_EXCP_FPU); \
6207 #if !defined(CONFIG_USER_ONLY)
6208 #define REQUIRE_SV(CTX) \
6210 if (unlikely((CTX)->pr)) { \
6211 gen_priv_opc(CTX); \
6216 #define REQUIRE_HV(CTX) \
6218 if (unlikely((CTX)->pr || !(CTX)->hv)) { \
6219 gen_priv_opc(CTX); \
6224 #define REQUIRE_SV(CTX) do { gen_priv_opc(CTX); return true; } while (0)
6225 #define REQUIRE_HV(CTX) do { gen_priv_opc(CTX); return true; } while (0)
6229 * Helpers for implementing sets of trans_* functions.
6230 * Defer the implementation of NAME to FUNC, with optional extra arguments.
6232 #define TRANS(NAME, FUNC, ...) \
6233 static bool trans_##NAME(DisasContext *ctx, arg_##NAME *a) \
6234 { return FUNC(ctx, a, __VA_ARGS__); }
6235 #define TRANS_FLAGS(FLAGS, NAME, FUNC, ...) \
6236 static bool trans_##NAME(DisasContext *ctx, arg_##NAME *a) \
6238 REQUIRE_INSNS_FLAGS(ctx, FLAGS); \
6239 return FUNC(ctx, a, __VA_ARGS__); \
6241 #define TRANS_FLAGS2(FLAGS2, NAME, FUNC, ...) \
6242 static bool trans_##NAME(DisasContext *ctx, arg_##NAME *a) \
6244 REQUIRE_INSNS_FLAGS2(ctx, FLAGS2); \
6245 return FUNC(ctx, a, __VA_ARGS__); \
6248 #define TRANS64(NAME, FUNC, ...) \
6249 static bool trans_##NAME(DisasContext *ctx, arg_##NAME *a) \
6250 { REQUIRE_64BIT(ctx); return FUNC(ctx, a, __VA_ARGS__); }
6251 #define TRANS64_FLAGS2(FLAGS2, NAME, FUNC, ...) \
6252 static bool trans_##NAME(DisasContext *ctx, arg_##NAME *a) \
6254 REQUIRE_64BIT(ctx); \
6255 REQUIRE_INSNS_FLAGS2(ctx, FLAGS2); \
6256 return FUNC(ctx, a, __VA_ARGS__); \
6259 /* TODO: More TRANS* helpers for extra insn_flags checks. */
6262 #include "decode-insn32.c.inc"
6263 #include "decode-insn64.c.inc"
6264 #include "power8-pmu-regs.c.inc"
6267 * Incorporate CIA into the constant when R=1.
6268 * Validate that when R=1, RA=0.
6270 static bool resolve_PLS_D(DisasContext
*ctx
, arg_D
*d
, arg_PLS_D
*a
)
6276 if (unlikely(a
->ra
!= 0)) {
6285 #include "translate/fixedpoint-impl.c.inc"
6287 #include "translate/fp-impl.c.inc"
6289 #include "translate/vmx-impl.c.inc"
6291 #include "translate/vsx-impl.c.inc"
6293 #include "translate/dfp-impl.c.inc"
6295 #include "translate/spe-impl.c.inc"
6297 #include "translate/branch-impl.c.inc"
6299 #include "translate/processor-ctrl-impl.c.inc"
6301 #include "translate/storage-ctrl-impl.c.inc"
6304 static void gen_dform39(DisasContext
*ctx
)
6306 if ((ctx
->opcode
& 0x3) == 0) {
6307 if (ctx
->insns_flags2
& PPC2_ISA205
) {
6308 return gen_lfdp(ctx
);
6311 return gen_invalid(ctx
);
6315 static void gen_dform3D(DisasContext
*ctx
)
6317 if ((ctx
->opcode
& 3) == 0) { /* DS-FORM */
6319 if (ctx
->insns_flags2
& PPC2_ISA205
) {
6320 return gen_stfdp(ctx
);
6323 return gen_invalid(ctx
);
6326 #if defined(TARGET_PPC64)
6328 static void gen_brd(DisasContext
*ctx
)
6330 tcg_gen_bswap64_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
6334 static void gen_brw(DisasContext
*ctx
)
6336 tcg_gen_bswap64_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
6337 tcg_gen_rotli_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 32);
6342 static void gen_brh(DisasContext
*ctx
)
6344 TCGv_i64 mask
= tcg_constant_i64(0x00ff00ff00ff00ffull
);
6345 TCGv_i64 t1
= tcg_temp_new_i64();
6346 TCGv_i64 t2
= tcg_temp_new_i64();
6348 tcg_gen_shri_i64(t1
, cpu_gpr
[rS(ctx
->opcode
)], 8);
6349 tcg_gen_and_i64(t2
, t1
, mask
);
6350 tcg_gen_and_i64(t1
, cpu_gpr
[rS(ctx
->opcode
)], mask
);
6351 tcg_gen_shli_i64(t1
, t1
, 8);
6352 tcg_gen_or_i64(cpu_gpr
[rA(ctx
->opcode
)], t1
, t2
);
6356 static opcode_t opcodes
[] = {
6357 #if defined(TARGET_PPC64)
6358 GEN_HANDLER_E(brd
, 0x1F, 0x1B, 0x05, 0x0000F801, PPC_NONE
, PPC2_ISA310
),
6359 GEN_HANDLER_E(brw
, 0x1F, 0x1B, 0x04, 0x0000F801, PPC_NONE
, PPC2_ISA310
),
6360 GEN_HANDLER_E(brh
, 0x1F, 0x1B, 0x06, 0x0000F801, PPC_NONE
, PPC2_ISA310
),
6362 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
),
6363 #if defined(TARGET_PPC64)
6364 GEN_HANDLER_E(cmpeqb
, 0x1F, 0x00, 0x07, 0x00600000, PPC_NONE
, PPC2_ISA300
),
6366 GEN_HANDLER_E(cmpb
, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE
, PPC2_ISA205
),
6367 GEN_HANDLER_E(cmprb
, 0x1F, 0x00, 0x06, 0x00400001, PPC_NONE
, PPC2_ISA300
),
6368 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
),
6369 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6370 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6371 GEN_HANDLER(mulhw
, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER
),
6372 GEN_HANDLER(mulhwu
, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER
),
6373 GEN_HANDLER(mullw
, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER
),
6374 GEN_HANDLER(mullwo
, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER
),
6375 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6376 #if defined(TARGET_PPC64)
6377 GEN_HANDLER(mulld
, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B
),
6379 GEN_HANDLER(neg
, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER
),
6380 GEN_HANDLER(nego
, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER
),
6381 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6382 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6383 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6384 GEN_HANDLER(cntlzw
, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER
),
6385 GEN_HANDLER_E(cnttzw
, 0x1F, 0x1A, 0x10, 0x00000000, PPC_NONE
, PPC2_ISA300
),
6386 GEN_HANDLER_E(copy
, 0x1F, 0x06, 0x18, 0x03C00001, PPC_NONE
, PPC2_ISA300
),
6387 GEN_HANDLER_E(cp_abort
, 0x1F, 0x06, 0x1A, 0x03FFF801, PPC_NONE
, PPC2_ISA300
),
6388 GEN_HANDLER_E(paste
, 0x1F, 0x06, 0x1C, 0x03C00000, PPC_NONE
, PPC2_ISA300
),
6389 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
),
6390 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
),
6391 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6392 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6393 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6394 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6395 GEN_HANDLER(popcntb
, 0x1F, 0x1A, 0x03, 0x0000F801, PPC_POPCNTB
),
6396 GEN_HANDLER(popcntw
, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD
),
6397 GEN_HANDLER_E(prtyw
, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
6398 #if defined(TARGET_PPC64)
6399 GEN_HANDLER(popcntd
, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD
),
6400 GEN_HANDLER(cntlzd
, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B
),
6401 GEN_HANDLER_E(cnttzd
, 0x1F, 0x1A, 0x11, 0x00000000, PPC_NONE
, PPC2_ISA300
),
6402 GEN_HANDLER_E(darn
, 0x1F, 0x13, 0x17, 0x001CF801, PPC_NONE
, PPC2_ISA300
),
6403 GEN_HANDLER_E(prtyd
, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
6404 GEN_HANDLER_E(bpermd
, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE
, PPC2_PERM_ISA206
),
6406 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6407 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6408 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6409 GEN_HANDLER(slw
, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER
),
6410 GEN_HANDLER(sraw
, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER
),
6411 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
),
6412 GEN_HANDLER(srw
, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER
),
6413 #if defined(TARGET_PPC64)
6414 GEN_HANDLER(sld
, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B
),
6415 GEN_HANDLER(srad
, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B
),
6416 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
),
6417 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
),
6418 GEN_HANDLER(srd
, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B
),
6419 GEN_HANDLER2_E(extswsli0
, "extswsli", 0x1F, 0x1A, 0x1B, 0x00000000,
6420 PPC_NONE
, PPC2_ISA300
),
6421 GEN_HANDLER2_E(extswsli1
, "extswsli", 0x1F, 0x1B, 0x1B, 0x00000000,
6422 PPC_NONE
, PPC2_ISA300
),
6424 /* handles lfdp, lxsd, lxssp */
6425 GEN_HANDLER_E(dform39
, 0x39, 0xFF, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA205
),
6426 /* handles stfdp, stxsd, stxssp */
6427 GEN_HANDLER_E(dform3D
, 0x3D, 0xFF, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA205
),
6428 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6429 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6430 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
),
6431 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
),
6432 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
),
6433 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
),
6434 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x01FFF801, PPC_MEM_EIEIO
),
6435 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
),
6436 GEN_HANDLER_E(lbarx
, 0x1F, 0x14, 0x01, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
6437 GEN_HANDLER_E(lharx
, 0x1F, 0x14, 0x03, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
6438 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES
),
6439 GEN_HANDLER_E(lwat
, 0x1F, 0x06, 0x12, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6440 GEN_HANDLER_E(stwat
, 0x1F, 0x06, 0x16, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6441 GEN_HANDLER_E(stbcx_
, 0x1F, 0x16, 0x15, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
6442 GEN_HANDLER_E(sthcx_
, 0x1F, 0x16, 0x16, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
6443 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
),
6444 #if defined(TARGET_PPC64)
6445 GEN_HANDLER_E(ldat
, 0x1F, 0x06, 0x13, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6446 GEN_HANDLER_E(stdat
, 0x1F, 0x06, 0x17, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6447 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B
),
6448 GEN_HANDLER_E(lqarx
, 0x1F, 0x14, 0x08, 0, PPC_NONE
, PPC2_LSQ_ISA207
),
6449 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
),
6450 GEN_HANDLER_E(stqcx_
, 0x1F, 0x16, 0x05, 0, PPC_NONE
, PPC2_LSQ_ISA207
),
6452 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
),
6453 /* ISA v3.0 changed the extended opcode from 62 to 30 */
6454 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x039FF801, PPC_WAIT
),
6455 GEN_HANDLER_E(wait
, 0x1F, 0x1E, 0x00, 0x039CF801, PPC_NONE
, PPC2_ISA300
),
6456 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
6457 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
6458 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
),
6459 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
),
6460 GEN_HANDLER_E(bctar
, 0x13, 0x10, 0x11, 0x0000E000, PPC_NONE
, PPC2_BCTAR_ISA207
),
6461 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
),
6462 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
),
6463 #if defined(TARGET_PPC64)
6464 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
),
6465 #if !defined(CONFIG_USER_ONLY)
6466 /* Top bit of opc2 corresponds with low bit of LEV, so use two handlers */
6467 GEN_HANDLER_E(scv
, 0x11, 0x10, 0xFF, 0x03FFF01E, PPC_NONE
, PPC2_ISA300
),
6468 GEN_HANDLER_E(scv
, 0x11, 0x00, 0xFF, 0x03FFF01E, PPC_NONE
, PPC2_ISA300
),
6469 GEN_HANDLER_E(rfscv
, 0x13, 0x12, 0x02, 0x03FF8001, PPC_NONE
, PPC2_ISA300
),
6471 GEN_HANDLER_E(stop
, 0x13, 0x12, 0x0b, 0x03FFF801, PPC_NONE
, PPC2_ISA300
),
6472 GEN_HANDLER_E(doze
, 0x13, 0x12, 0x0c, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
6473 GEN_HANDLER_E(nap
, 0x13, 0x12, 0x0d, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
6474 GEN_HANDLER_E(sleep
, 0x13, 0x12, 0x0e, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
6475 GEN_HANDLER_E(rvwinkle
, 0x13, 0x12, 0x0f, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
6476 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
),
6478 /* Top bit of opc2 corresponds with low bit of LEV, so use two handlers */
6479 GEN_HANDLER(sc
, 0x11, 0x11, 0xFF, 0x03FFF01D, PPC_FLOW
),
6480 GEN_HANDLER(sc
, 0x11, 0x01, 0xFF, 0x03FFF01D, PPC_FLOW
),
6481 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
),
6482 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
6483 #if defined(TARGET_PPC64)
6484 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
),
6485 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
),
6487 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
),
6488 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
),
6489 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
),
6490 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
),
6491 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
),
6492 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
),
6493 #if defined(TARGET_PPC64)
6494 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
),
6495 GEN_HANDLER_E(setb
, 0x1F, 0x00, 0x04, 0x0003F801, PPC_NONE
, PPC2_ISA300
),
6496 GEN_HANDLER_E(mcrxrx
, 0x1F, 0x00, 0x12, 0x007FF801, PPC_NONE
, PPC2_ISA300
),
6498 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001EF801, PPC_MISC
),
6499 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000000, PPC_MISC
),
6500 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
),
6501 GEN_HANDLER_E(dcbfep
, 0x1F, 0x1F, 0x03, 0x03C00001, PPC_NONE
, PPC2_BOOKE206
),
6502 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
),
6503 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
),
6504 GEN_HANDLER_E(dcbstep
, 0x1F, 0x1F, 0x01, 0x03E00001, PPC_NONE
, PPC2_BOOKE206
),
6505 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE
),
6506 GEN_HANDLER_E(dcbtep
, 0x1F, 0x1F, 0x09, 0x00000001, PPC_NONE
, PPC2_BOOKE206
),
6507 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE
),
6508 GEN_HANDLER_E(dcbtstep
, 0x1F, 0x1F, 0x07, 0x00000001, PPC_NONE
, PPC2_BOOKE206
),
6509 GEN_HANDLER_E(dcbtls
, 0x1F, 0x06, 0x05, 0x02000001, PPC_BOOKE
, PPC2_BOOKE206
),
6510 GEN_HANDLER_E(dcblc
, 0x1F, 0x06, 0x0c, 0x02000001, PPC_BOOKE
, PPC2_BOOKE206
),
6511 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ
),
6512 GEN_HANDLER_E(dcbzep
, 0x1F, 0x1F, 0x1F, 0x03C00001, PPC_NONE
, PPC2_BOOKE206
),
6513 GEN_HANDLER(dst
, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC
),
6514 GEN_HANDLER(dstst
, 0x1F, 0x16, 0x0B, 0x01800001, PPC_ALTIVEC
),
6515 GEN_HANDLER(dss
, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC
),
6516 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
),
6517 GEN_HANDLER_E(icbiep
, 0x1F, 0x1F, 0x1E, 0x03E00001, PPC_NONE
, PPC2_BOOKE206
),
6518 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
),
6519 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
),
6520 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
),
6521 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
),
6522 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
),
6523 #if defined(TARGET_PPC64)
6524 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
),
6525 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
6527 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
),
6528 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
6531 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
),
6533 * XXX Those instructions will need to be handled differently for
6534 * different ISA versions
6536 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
),
6537 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
),
6538 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
),
6539 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
),
6540 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
),
6541 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
),
6542 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
),
6543 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
),
6544 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
),
6545 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
),
6546 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
),
6547 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
),
6548 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
),
6549 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
),
6550 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
),
6551 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
),
6552 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
),
6553 GEN_HANDLER_E(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
, PPC2_BOOKE206
),
6554 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
),
6555 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
),
6556 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
),
6557 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
),
6558 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
),
6559 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
),
6560 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
),
6561 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
),
6562 GEN_HANDLER2_E(tlbre_booke206
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
6563 PPC_NONE
, PPC2_BOOKE206
),
6564 GEN_HANDLER2_E(tlbsx_booke206
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
6565 PPC_NONE
, PPC2_BOOKE206
),
6566 GEN_HANDLER2_E(tlbwe_booke206
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
6567 PPC_NONE
, PPC2_BOOKE206
),
6568 GEN_HANDLER2_E(tlbivax_booke206
, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
6569 PPC_NONE
, PPC2_BOOKE206
),
6570 GEN_HANDLER2_E(tlbilx_booke206
, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
6571 PPC_NONE
, PPC2_BOOKE206
),
6572 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
),
6573 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE
),
6574 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
),
6575 GEN_HANDLER_E(mbar
, 0x1F, 0x16, 0x1a, 0x001FF801,
6576 PPC_BOOKE
, PPC2_BOOKE206
),
6577 GEN_HANDLER(msync_4xx
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_BOOKE
),
6578 GEN_HANDLER2_E(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
6579 PPC_BOOKE
, PPC2_BOOKE206
),
6580 GEN_HANDLER2(icbt_440
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001,
6582 GEN_HANDLER(lvsl
, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC
),
6583 GEN_HANDLER(lvsr
, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC
),
6584 GEN_HANDLER(mfvscr
, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC
),
6585 GEN_HANDLER(mtvscr
, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC
),
6586 #if defined(TARGET_PPC64)
6587 GEN_HANDLER_E(maddhd_maddhdu
, 0x04, 0x18, 0xFF, 0x00000000, PPC_NONE
,
6589 GEN_HANDLER_E(maddld
, 0x04, 0x19, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA300
),
6592 #undef GEN_INT_ARITH_ADD
6593 #undef GEN_INT_ARITH_ADD_CONST
6594 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
6595 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
6596 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
6597 add_ca, compute_ca, compute_ov) \
6598 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
6599 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
6600 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
6601 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
6602 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
6603 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
6604 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
6605 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
6606 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
6607 GEN_HANDLER_E(addex
, 0x1F, 0x0A, 0x05, 0x00000000, PPC_NONE
, PPC2_ISA300
),
6608 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
6609 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
6611 #undef GEN_INT_ARITH_DIVW
6612 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
6613 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
6614 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0),
6615 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1),
6616 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0),
6617 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1),
6618 GEN_HANDLER_E(divwe
, 0x1F, 0x0B, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6619 GEN_HANDLER_E(divweo
, 0x1F, 0x0B, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6620 GEN_HANDLER_E(divweu
, 0x1F, 0x0B, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6621 GEN_HANDLER_E(divweuo
, 0x1F, 0x0B, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6622 GEN_HANDLER_E(modsw
, 0x1F, 0x0B, 0x18, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6623 GEN_HANDLER_E(moduw
, 0x1F, 0x0B, 0x08, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6625 #if defined(TARGET_PPC64)
6626 #undef GEN_INT_ARITH_DIVD
6627 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
6628 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
6629 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0),
6630 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1),
6631 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0),
6632 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1),
6634 GEN_HANDLER_E(divdeu
, 0x1F, 0x09, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6635 GEN_HANDLER_E(divdeuo
, 0x1F, 0x09, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6636 GEN_HANDLER_E(divde
, 0x1F, 0x09, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6637 GEN_HANDLER_E(divdeo
, 0x1F, 0x09, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6638 GEN_HANDLER_E(modsd
, 0x1F, 0x09, 0x18, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6639 GEN_HANDLER_E(modud
, 0x1F, 0x09, 0x08, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6641 #undef GEN_INT_ARITH_MUL_HELPER
6642 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
6643 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
6644 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00),
6645 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02),
6646 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17),
6649 #undef GEN_INT_ARITH_SUBF
6650 #undef GEN_INT_ARITH_SUBF_CONST
6651 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
6652 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
6653 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
6654 add_ca, compute_ca, compute_ov) \
6655 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
6656 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
6657 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
6658 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
6659 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
6660 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
6661 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
6662 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
6663 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
6664 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
6665 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
6669 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
6670 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
6671 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
6672 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
6673 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
),
6674 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
),
6675 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
),
6676 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
),
6677 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
),
6678 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
),
6679 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
),
6680 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
),
6681 #if defined(TARGET_PPC64)
6682 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
),
6685 #if defined(TARGET_PPC64)
6688 #define GEN_PPC64_R2(name, opc1, opc2) \
6689 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
6690 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
6692 #define GEN_PPC64_R4(name, opc1, opc2) \
6693 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
6694 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
6696 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
6698 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
6700 GEN_PPC64_R4(rldicl
, 0x1E, 0x00),
6701 GEN_PPC64_R4(rldicr
, 0x1E, 0x02),
6702 GEN_PPC64_R4(rldic
, 0x1E, 0x04),
6703 GEN_PPC64_R2(rldcl
, 0x1E, 0x08),
6704 GEN_PPC64_R2(rldcr
, 0x1E, 0x09),
6705 GEN_PPC64_R4(rldimi
, 0x1E, 0x06),
6709 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2, chk) \
6710 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
6712 #if defined(TARGET_PPC64)
6713 GEN_LDX_E(ldbr
, ld64ur_i64
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
, CHK_NONE
)
6715 /* HV/P7 and later only */
6716 GEN_LDX_HVRM(ldcix
, ld64_i64
, 0x15, 0x1b, PPC_CILDST
)
6717 GEN_LDX_HVRM(lwzcix
, ld32u
, 0x15, 0x18, PPC_CILDST
)
6718 GEN_LDX_HVRM(lhzcix
, ld16u
, 0x15, 0x19, PPC_CILDST
)
6719 GEN_LDX_HVRM(lbzcix
, ld8u
, 0x15, 0x1a, PPC_CILDST
)
6721 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
)
6722 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
)
6724 /* External PID based load */
6726 #define GEN_LDEPX(name, ldop, opc2, opc3) \
6727 GEN_HANDLER_E(name##epx, 0x1F, opc2, opc3, \
6728 0x00000001, PPC_NONE, PPC2_BOOKE206),
6730 GEN_LDEPX(lb
, DEF_MEMOP(MO_UB
), 0x1F, 0x02)
6731 GEN_LDEPX(lh
, DEF_MEMOP(MO_UW
), 0x1F, 0x08)
6732 GEN_LDEPX(lw
, DEF_MEMOP(MO_UL
), 0x1F, 0x00)
6733 #if defined(TARGET_PPC64)
6734 GEN_LDEPX(ld
, DEF_MEMOP(MO_UQ
), 0x1D, 0x00)
6738 #define GEN_STX_E(name, stop, opc2, opc3, type, type2, chk) \
6739 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000000, type, type2),
6741 #if defined(TARGET_PPC64)
6742 GEN_STX_E(stdbr
, st64r_i64
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
, CHK_NONE
)
6743 GEN_STX_HVRM(stdcix
, st64_i64
, 0x15, 0x1f, PPC_CILDST
)
6744 GEN_STX_HVRM(stwcix
, st32
, 0x15, 0x1c, PPC_CILDST
)
6745 GEN_STX_HVRM(sthcix
, st16
, 0x15, 0x1d, PPC_CILDST
)
6746 GEN_STX_HVRM(stbcix
, st8
, 0x15, 0x1e, PPC_CILDST
)
6748 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
)
6749 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
)
6752 #define GEN_STEPX(name, ldop, opc2, opc3) \
6753 GEN_HANDLER_E(name##epx, 0x1F, opc2, opc3, \
6754 0x00000001, PPC_NONE, PPC2_BOOKE206),
6756 GEN_STEPX(stb
, DEF_MEMOP(MO_UB
), 0x1F, 0x06)
6757 GEN_STEPX(sth
, DEF_MEMOP(MO_UW
), 0x1F, 0x0C)
6758 GEN_STEPX(stw
, DEF_MEMOP(MO_UL
), 0x1F, 0x04)
6759 #if defined(TARGET_PPC64)
6760 GEN_STEPX(std
, DEF_MEMOP(MO_UQ
), 0x1D, 0x04)
6764 #define GEN_CRLOGIC(name, tcg_op, opc) \
6765 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
6766 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08),
6767 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04),
6768 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09),
6769 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07),
6770 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01),
6771 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E),
6772 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D),
6773 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06),
6775 #undef GEN_MAC_HANDLER
6776 #define GEN_MAC_HANDLER(name, opc2, opc3) \
6777 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
6778 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05),
6779 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15),
6780 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07),
6781 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17),
6782 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06),
6783 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16),
6784 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04),
6785 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14),
6786 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01),
6787 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11),
6788 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03),
6789 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13),
6790 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02),
6791 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12),
6792 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00),
6793 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10),
6794 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D),
6795 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D),
6796 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F),
6797 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F),
6798 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C),
6799 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C),
6800 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E),
6801 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E),
6802 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05),
6803 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15),
6804 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07),
6805 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17),
6806 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01),
6807 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11),
6808 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03),
6809 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13),
6810 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D),
6811 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D),
6812 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F),
6813 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F),
6814 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05),
6815 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04),
6816 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01),
6817 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00),
6818 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D),
6819 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C),
6821 GEN_HANDLER2_E(tbegin
, "tbegin", 0x1F, 0x0E, 0x14, 0x01DFF800, \
6823 GEN_HANDLER2_E(tend
, "tend", 0x1F, 0x0E, 0x15, 0x01FFF800, \
6825 GEN_HANDLER2_E(tabort
, "tabort", 0x1F, 0x0E, 0x1C, 0x03E0F800, \
6827 GEN_HANDLER2_E(tabortwc
, "tabortwc", 0x1F, 0x0E, 0x18, 0x00000000, \
6829 GEN_HANDLER2_E(tabortwci
, "tabortwci", 0x1F, 0x0E, 0x1A, 0x00000000, \
6831 GEN_HANDLER2_E(tabortdc
, "tabortdc", 0x1F, 0x0E, 0x19, 0x00000000, \
6833 GEN_HANDLER2_E(tabortdci
, "tabortdci", 0x1F, 0x0E, 0x1B, 0x00000000, \
6835 GEN_HANDLER2_E(tsr
, "tsr", 0x1F, 0x0E, 0x17, 0x03DFF800, \
6837 GEN_HANDLER2_E(tcheck
, "tcheck", 0x1F, 0x0E, 0x16, 0x007FF800, \
6839 GEN_HANDLER2_E(treclaim
, "treclaim", 0x1F, 0x0E, 0x1D, 0x03E0F800, \
6841 GEN_HANDLER2_E(trechkpt
, "trechkpt", 0x1F, 0x0E, 0x1F, 0x03FFF800, \
6844 #include "translate/fp-ops.c.inc"
6846 #include "translate/vmx-ops.c.inc"
6848 #include "translate/vsx-ops.c.inc"
6850 #include "translate/spe-ops.c.inc"
6853 /*****************************************************************************/
6856 PPC_DIRECT
= 0, /* Opcode routine */
6857 PPC_INDIRECT
= 1, /* Indirect opcode table */
6860 #define PPC_OPCODE_MASK 0x3
6862 static inline int is_indirect_opcode(void *handler
)
6864 return ((uintptr_t)handler
& PPC_OPCODE_MASK
) == PPC_INDIRECT
;
6867 static inline opc_handler_t
**ind_table(void *handler
)
6869 return (opc_handler_t
**)((uintptr_t)handler
& ~PPC_OPCODE_MASK
);
6872 /* Instruction table creation */
6873 /* Opcodes tables creation */
6874 static void fill_new_table(opc_handler_t
**table
, int len
)
6878 for (i
= 0; i
< len
; i
++) {
6879 table
[i
] = &invalid_handler
;
6883 static int create_new_table(opc_handler_t
**table
, unsigned char idx
)
6885 opc_handler_t
**tmp
;
6887 tmp
= g_new(opc_handler_t
*, PPC_CPU_INDIRECT_OPCODES_LEN
);
6888 fill_new_table(tmp
, PPC_CPU_INDIRECT_OPCODES_LEN
);
6889 table
[idx
] = (opc_handler_t
*)((uintptr_t)tmp
| PPC_INDIRECT
);
6894 static int insert_in_table(opc_handler_t
**table
, unsigned char idx
,
6895 opc_handler_t
*handler
)
6897 if (table
[idx
] != &invalid_handler
) {
6900 table
[idx
] = handler
;
6905 static int register_direct_insn(opc_handler_t
**ppc_opcodes
,
6906 unsigned char idx
, opc_handler_t
*handler
)
6908 if (insert_in_table(ppc_opcodes
, idx
, handler
) < 0) {
6909 printf("*** ERROR: opcode %02x already assigned in main "
6910 "opcode table\n", idx
);
6917 static int register_ind_in_table(opc_handler_t
**table
,
6918 unsigned char idx1
, unsigned char idx2
,
6919 opc_handler_t
*handler
)
6921 if (table
[idx1
] == &invalid_handler
) {
6922 if (create_new_table(table
, idx1
) < 0) {
6923 printf("*** ERROR: unable to create indirect table "
6924 "idx=%02x\n", idx1
);
6928 if (!is_indirect_opcode(table
[idx1
])) {
6929 printf("*** ERROR: idx %02x already assigned to a direct "
6934 if (handler
!= NULL
&&
6935 insert_in_table(ind_table(table
[idx1
]), idx2
, handler
) < 0) {
6936 printf("*** ERROR: opcode %02x already assigned in "
6937 "opcode table %02x\n", idx2
, idx1
);
6944 static int register_ind_insn(opc_handler_t
**ppc_opcodes
,
6945 unsigned char idx1
, unsigned char idx2
,
6946 opc_handler_t
*handler
)
6948 return register_ind_in_table(ppc_opcodes
, idx1
, idx2
, handler
);
6951 static int register_dblind_insn(opc_handler_t
**ppc_opcodes
,
6952 unsigned char idx1
, unsigned char idx2
,
6953 unsigned char idx3
, opc_handler_t
*handler
)
6955 if (register_ind_in_table(ppc_opcodes
, idx1
, idx2
, NULL
) < 0) {
6956 printf("*** ERROR: unable to join indirect table idx "
6957 "[%02x-%02x]\n", idx1
, idx2
);
6960 if (register_ind_in_table(ind_table(ppc_opcodes
[idx1
]), idx2
, idx3
,
6962 printf("*** ERROR: unable to insert opcode "
6963 "[%02x-%02x-%02x]\n", idx1
, idx2
, idx3
);
6970 static int register_trplind_insn(opc_handler_t
**ppc_opcodes
,
6971 unsigned char idx1
, unsigned char idx2
,
6972 unsigned char idx3
, unsigned char idx4
,
6973 opc_handler_t
*handler
)
6975 opc_handler_t
**table
;
6977 if (register_ind_in_table(ppc_opcodes
, idx1
, idx2
, NULL
) < 0) {
6978 printf("*** ERROR: unable to join indirect table idx "
6979 "[%02x-%02x]\n", idx1
, idx2
);
6982 table
= ind_table(ppc_opcodes
[idx1
]);
6983 if (register_ind_in_table(table
, idx2
, idx3
, NULL
) < 0) {
6984 printf("*** ERROR: unable to join 2nd-level indirect table idx "
6985 "[%02x-%02x-%02x]\n", idx1
, idx2
, idx3
);
6988 table
= ind_table(table
[idx2
]);
6989 if (register_ind_in_table(table
, idx3
, idx4
, handler
) < 0) {
6990 printf("*** ERROR: unable to insert opcode "
6991 "[%02x-%02x-%02x-%02x]\n", idx1
, idx2
, idx3
, idx4
);
6996 static int register_insn(opc_handler_t
**ppc_opcodes
, opcode_t
*insn
)
6998 if (insn
->opc2
!= 0xFF) {
6999 if (insn
->opc3
!= 0xFF) {
7000 if (insn
->opc4
!= 0xFF) {
7001 if (register_trplind_insn(ppc_opcodes
, insn
->opc1
, insn
->opc2
,
7002 insn
->opc3
, insn
->opc4
,
7003 &insn
->handler
) < 0) {
7007 if (register_dblind_insn(ppc_opcodes
, insn
->opc1
, insn
->opc2
,
7008 insn
->opc3
, &insn
->handler
) < 0) {
7013 if (register_ind_insn(ppc_opcodes
, insn
->opc1
,
7014 insn
->opc2
, &insn
->handler
) < 0) {
7019 if (register_direct_insn(ppc_opcodes
, insn
->opc1
, &insn
->handler
) < 0) {
7027 static int test_opcode_table(opc_handler_t
**table
, int len
)
7031 for (i
= 0, count
= 0; i
< len
; i
++) {
7032 /* Consistency fixup */
7033 if (table
[i
] == NULL
) {
7034 table
[i
] = &invalid_handler
;
7036 if (table
[i
] != &invalid_handler
) {
7037 if (is_indirect_opcode(table
[i
])) {
7038 tmp
= test_opcode_table(ind_table(table
[i
]),
7039 PPC_CPU_INDIRECT_OPCODES_LEN
);
7042 table
[i
] = &invalid_handler
;
7055 static void fix_opcode_tables(opc_handler_t
**ppc_opcodes
)
7057 if (test_opcode_table(ppc_opcodes
, PPC_CPU_OPCODES_LEN
) == 0) {
7058 printf("*** WARNING: no opcode defined !\n");
7062 /*****************************************************************************/
7063 void create_ppc_opcodes(PowerPCCPU
*cpu
, Error
**errp
)
7065 PowerPCCPUClass
*pcc
= POWERPC_CPU_GET_CLASS(cpu
);
7068 fill_new_table(cpu
->opcodes
, PPC_CPU_OPCODES_LEN
);
7069 for (opc
= opcodes
; opc
< &opcodes
[ARRAY_SIZE(opcodes
)]; opc
++) {
7070 if (((opc
->handler
.type
& pcc
->insns_flags
) != 0) ||
7071 ((opc
->handler
.type2
& pcc
->insns_flags2
) != 0)) {
7072 if (register_insn(cpu
->opcodes
, opc
) < 0) {
7073 error_setg(errp
, "ERROR initializing PowerPC instruction "
7074 "0x%02x 0x%02x 0x%02x", opc
->opc1
, opc
->opc2
,
7080 fix_opcode_tables(cpu
->opcodes
);
7085 void destroy_ppc_opcodes(PowerPCCPU
*cpu
)
7087 opc_handler_t
**table
, **table_2
;
7090 for (i
= 0; i
< PPC_CPU_OPCODES_LEN
; i
++) {
7091 if (cpu
->opcodes
[i
] == &invalid_handler
) {
7094 if (is_indirect_opcode(cpu
->opcodes
[i
])) {
7095 table
= ind_table(cpu
->opcodes
[i
]);
7096 for (j
= 0; j
< PPC_CPU_INDIRECT_OPCODES_LEN
; j
++) {
7097 if (table
[j
] == &invalid_handler
) {
7100 if (is_indirect_opcode(table
[j
])) {
7101 table_2
= ind_table(table
[j
]);
7102 for (k
= 0; k
< PPC_CPU_INDIRECT_OPCODES_LEN
; k
++) {
7103 if (table_2
[k
] != &invalid_handler
&&
7104 is_indirect_opcode(table_2
[k
])) {
7105 g_free((opc_handler_t
*)((uintptr_t)table_2
[k
] &
7109 g_free((opc_handler_t
*)((uintptr_t)table
[j
] &
7113 g_free((opc_handler_t
*)((uintptr_t)cpu
->opcodes
[i
] &
7119 int ppc_fixup_cpu(PowerPCCPU
*cpu
)
7121 CPUPPCState
*env
= &cpu
->env
;
7124 * TCG doesn't (yet) emulate some groups of instructions that are
7125 * implemented on some otherwise supported CPUs (e.g. VSX and
7126 * decimal floating point instructions on POWER7). We remove
7127 * unsupported instruction groups from the cpu state's instruction
7128 * masks and hope the guest can cope. For at least the pseries
7129 * machine, the unavailability of these instructions can be
7130 * advertised to the guest via the device tree.
7132 if ((env
->insns_flags
& ~PPC_TCG_INSNS
)
7133 || (env
->insns_flags2
& ~PPC_TCG_INSNS2
)) {
7134 warn_report("Disabling some instructions which are not "
7135 "emulated by TCG (0x%" PRIx64
", 0x%" PRIx64
")",
7136 env
->insns_flags
& ~PPC_TCG_INSNS
,
7137 env
->insns_flags2
& ~PPC_TCG_INSNS2
);
7139 env
->insns_flags
&= PPC_TCG_INSNS
;
7140 env
->insns_flags2
&= PPC_TCG_INSNS2
;
7144 static bool decode_legacy(PowerPCCPU
*cpu
, DisasContext
*ctx
, uint32_t insn
)
7146 opc_handler_t
**table
, *handler
;
7151 LOG_DISAS("translate opcode %08x (%02x %02x %02x %02x) (%s)\n",
7152 insn
, opc1(insn
), opc2(insn
), opc3(insn
), opc4(insn
),
7153 ctx
->le_mode
? "little" : "big");
7155 table
= cpu
->opcodes
;
7156 handler
= table
[opc1(insn
)];
7157 if (is_indirect_opcode(handler
)) {
7158 table
= ind_table(handler
);
7159 handler
= table
[opc2(insn
)];
7160 if (is_indirect_opcode(handler
)) {
7161 table
= ind_table(handler
);
7162 handler
= table
[opc3(insn
)];
7163 if (is_indirect_opcode(handler
)) {
7164 table
= ind_table(handler
);
7165 handler
= table
[opc4(insn
)];
7170 /* Is opcode *REALLY* valid ? */
7171 if (unlikely(handler
->handler
== &gen_invalid
)) {
7172 qemu_log_mask(LOG_GUEST_ERROR
, "invalid/unsupported opcode: "
7173 "%02x - %02x - %02x - %02x (%08x) "
7175 opc1(insn
), opc2(insn
), opc3(insn
), opc4(insn
),
7180 if (unlikely(handler
->type
& (PPC_SPE
| PPC_SPE_SINGLE
| PPC_SPE_DOUBLE
)
7182 inval
= handler
->inval2
;
7184 inval
= handler
->inval1
;
7187 if (unlikely((insn
& inval
) != 0)) {
7188 qemu_log_mask(LOG_GUEST_ERROR
, "invalid bits: %08x for opcode: "
7189 "%02x - %02x - %02x - %02x (%08x) "
7190 TARGET_FMT_lx
"\n", insn
& inval
,
7191 opc1(insn
), opc2(insn
), opc3(insn
), opc4(insn
),
7196 handler
->handler(ctx
);
7200 static void ppc_tr_init_disas_context(DisasContextBase
*dcbase
, CPUState
*cs
)
7202 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
7203 CPUPPCState
*env
= cs
->env_ptr
;
7204 uint32_t hflags
= ctx
->base
.tb
->flags
;
7206 ctx
->spr_cb
= env
->spr_cb
;
7207 ctx
->pr
= (hflags
>> HFLAGS_PR
) & 1;
7208 ctx
->mem_idx
= (hflags
>> HFLAGS_DMMU_IDX
) & 7;
7209 ctx
->dr
= (hflags
>> HFLAGS_DR
) & 1;
7210 ctx
->hv
= (hflags
>> HFLAGS_HV
) & 1;
7211 ctx
->insns_flags
= env
->insns_flags
;
7212 ctx
->insns_flags2
= env
->insns_flags2
;
7213 ctx
->access_type
= -1;
7214 ctx
->need_access_type
= !mmu_is_64bit(env
->mmu_model
);
7215 ctx
->le_mode
= (hflags
>> HFLAGS_LE
) & 1;
7216 ctx
->default_tcg_memop_mask
= ctx
->le_mode
? MO_LE
: MO_BE
;
7217 ctx
->flags
= env
->flags
;
7218 #if defined(TARGET_PPC64)
7219 ctx
->sf_mode
= (hflags
>> HFLAGS_64
) & 1;
7220 ctx
->has_cfar
= !!(env
->flags
& POWERPC_FLAG_CFAR
);
7222 ctx
->lazy_tlb_flush
= env
->mmu_model
== POWERPC_MMU_32B
7223 || env
->mmu_model
& POWERPC_MMU_64
;
7225 ctx
->fpu_enabled
= (hflags
>> HFLAGS_FP
) & 1;
7226 ctx
->spe_enabled
= (hflags
>> HFLAGS_SPE
) & 1;
7227 ctx
->altivec_enabled
= (hflags
>> HFLAGS_VR
) & 1;
7228 ctx
->vsx_enabled
= (hflags
>> HFLAGS_VSX
) & 1;
7229 ctx
->tm_enabled
= (hflags
>> HFLAGS_TM
) & 1;
7230 ctx
->gtse
= (hflags
>> HFLAGS_GTSE
) & 1;
7231 ctx
->hr
= (hflags
>> HFLAGS_HR
) & 1;
7232 ctx
->mmcr0_pmcc0
= (hflags
>> HFLAGS_PMCC0
) & 1;
7233 ctx
->mmcr0_pmcc1
= (hflags
>> HFLAGS_PMCC1
) & 1;
7234 ctx
->mmcr0_pmcjce
= (hflags
>> HFLAGS_PMCJCE
) & 1;
7235 ctx
->pmc_other
= (hflags
>> HFLAGS_PMC_OTHER
) & 1;
7236 ctx
->pmu_insn_cnt
= (hflags
>> HFLAGS_INSN_CNT
) & 1;
7238 ctx
->singlestep_enabled
= 0;
7239 if ((hflags
>> HFLAGS_SE
) & 1) {
7240 ctx
->singlestep_enabled
|= CPU_SINGLE_STEP
;
7241 ctx
->base
.max_insns
= 1;
7243 if ((hflags
>> HFLAGS_BE
) & 1) {
7244 ctx
->singlestep_enabled
|= CPU_BRANCH_STEP
;
7248 static void ppc_tr_tb_start(DisasContextBase
*db
, CPUState
*cs
)
7252 static void ppc_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cs
)
7254 tcg_gen_insn_start(dcbase
->pc_next
);
7257 static bool is_prefix_insn(DisasContext
*ctx
, uint32_t insn
)
7259 REQUIRE_INSNS_FLAGS2(ctx
, ISA310
);
7260 return opc1(insn
) == 1;
7263 static void ppc_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cs
)
7265 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
7266 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
7267 CPUPPCState
*env
= cs
->env_ptr
;
7272 LOG_DISAS("----------------\n");
7273 LOG_DISAS("nip=" TARGET_FMT_lx
" super=%d ir=%d\n",
7274 ctx
->base
.pc_next
, ctx
->mem_idx
, (int)msr_ir
);
7276 ctx
->cia
= pc
= ctx
->base
.pc_next
;
7277 insn
= translator_ldl_swap(env
, dcbase
, pc
, need_byteswap(ctx
));
7278 ctx
->base
.pc_next
= pc
+= 4;
7280 if (!is_prefix_insn(ctx
, insn
)) {
7281 ok
= (decode_insn32(ctx
, insn
) ||
7282 decode_legacy(cpu
, ctx
, insn
));
7283 } else if ((pc
& 63) == 0) {
7285 * Power v3.1, section 1.9 Exceptions:
7286 * attempt to execute a prefixed instruction that crosses a
7287 * 64-byte address boundary (system alignment error).
7289 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_INSN
);
7292 uint32_t insn2
= translator_ldl_swap(env
, dcbase
, pc
,
7293 need_byteswap(ctx
));
7294 ctx
->base
.pc_next
= pc
+= 4;
7295 ok
= decode_insn64(ctx
, deposit64(insn2
, 32, 32, insn
));
7301 /* End the TB when crossing a page boundary. */
7302 if (ctx
->base
.is_jmp
== DISAS_NEXT
&& !(pc
& ~TARGET_PAGE_MASK
)) {
7303 ctx
->base
.is_jmp
= DISAS_TOO_MANY
;
7307 static void ppc_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cs
)
7309 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
7310 DisasJumpType is_jmp
= ctx
->base
.is_jmp
;
7311 target_ulong nip
= ctx
->base
.pc_next
;
7313 if (is_jmp
== DISAS_NORETURN
) {
7314 /* We have already exited the TB. */
7318 /* Honor single stepping. */
7319 if (unlikely(ctx
->singlestep_enabled
& CPU_SINGLE_STEP
)
7320 && (nip
<= 0x100 || nip
> 0xf00)) {
7322 case DISAS_TOO_MANY
:
7323 case DISAS_EXIT_UPDATE
:
7324 case DISAS_CHAIN_UPDATE
:
7325 gen_update_nip(ctx
, nip
);
7331 g_assert_not_reached();
7334 gen_debug_exception(ctx
);
7339 case DISAS_TOO_MANY
:
7340 if (use_goto_tb(ctx
, nip
)) {
7341 pmu_count_insns(ctx
);
7343 gen_update_nip(ctx
, nip
);
7344 tcg_gen_exit_tb(ctx
->base
.tb
, 0);
7348 case DISAS_CHAIN_UPDATE
:
7349 gen_update_nip(ctx
, nip
);
7353 * tcg_gen_lookup_and_goto_ptr will exit the TB if
7354 * CF_NO_GOTO_PTR is set. Count insns now.
7356 if (ctx
->base
.tb
->flags
& CF_NO_GOTO_PTR
) {
7357 pmu_count_insns(ctx
);
7360 tcg_gen_lookup_and_goto_ptr();
7363 case DISAS_EXIT_UPDATE
:
7364 gen_update_nip(ctx
, nip
);
7367 pmu_count_insns(ctx
);
7368 tcg_gen_exit_tb(NULL
, 0);
7372 g_assert_not_reached();
7376 static void ppc_tr_disas_log(const DisasContextBase
*dcbase
,
7377 CPUState
*cs
, FILE *logfile
)
7379 fprintf(logfile
, "IN: %s\n", lookup_symbol(dcbase
->pc_first
));
7380 target_disas(logfile
, cs
, dcbase
->pc_first
, dcbase
->tb
->size
);
7383 static const TranslatorOps ppc_tr_ops
= {
7384 .init_disas_context
= ppc_tr_init_disas_context
,
7385 .tb_start
= ppc_tr_tb_start
,
7386 .insn_start
= ppc_tr_insn_start
,
7387 .translate_insn
= ppc_tr_translate_insn
,
7388 .tb_stop
= ppc_tr_tb_stop
,
7389 .disas_log
= ppc_tr_disas_log
,
7392 void gen_intermediate_code(CPUState
*cs
, TranslationBlock
*tb
, int *max_insns
,
7393 target_ulong pc
, void *host_pc
)
7397 translator_loop(cs
, tb
, max_insns
, pc
, host_pc
, &ppc_tr_ops
, &ctx
.base
);