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_val
;
79 static TCGv cpu_reserve_val2
;
80 static TCGv cpu_fpscr
;
81 static TCGv_i32 cpu_access_type
;
83 void ppc_translate_init(void)
87 size_t cpu_reg_names_size
;
90 cpu_reg_names_size
= sizeof(cpu_reg_names
);
92 for (i
= 0; i
< 8; i
++) {
93 snprintf(p
, cpu_reg_names_size
, "crf%d", i
);
94 cpu_crf
[i
] = tcg_global_mem_new_i32(cpu_env
,
95 offsetof(CPUPPCState
, crf
[i
]), p
);
97 cpu_reg_names_size
-= 5;
100 for (i
= 0; i
< 32; i
++) {
101 snprintf(p
, cpu_reg_names_size
, "r%d", i
);
102 cpu_gpr
[i
] = tcg_global_mem_new(cpu_env
,
103 offsetof(CPUPPCState
, gpr
[i
]), p
);
104 p
+= (i
< 10) ? 3 : 4;
105 cpu_reg_names_size
-= (i
< 10) ? 3 : 4;
106 snprintf(p
, cpu_reg_names_size
, "r%dH", i
);
107 cpu_gprh
[i
] = tcg_global_mem_new(cpu_env
,
108 offsetof(CPUPPCState
, gprh
[i
]), p
);
109 p
+= (i
< 10) ? 4 : 5;
110 cpu_reg_names_size
-= (i
< 10) ? 4 : 5;
113 cpu_nip
= tcg_global_mem_new(cpu_env
,
114 offsetof(CPUPPCState
, nip
), "nip");
116 cpu_msr
= tcg_global_mem_new(cpu_env
,
117 offsetof(CPUPPCState
, msr
), "msr");
119 cpu_ctr
= tcg_global_mem_new(cpu_env
,
120 offsetof(CPUPPCState
, ctr
), "ctr");
122 cpu_lr
= tcg_global_mem_new(cpu_env
,
123 offsetof(CPUPPCState
, lr
), "lr");
125 #if defined(TARGET_PPC64)
126 cpu_cfar
= tcg_global_mem_new(cpu_env
,
127 offsetof(CPUPPCState
, cfar
), "cfar");
130 cpu_xer
= tcg_global_mem_new(cpu_env
,
131 offsetof(CPUPPCState
, xer
), "xer");
132 cpu_so
= tcg_global_mem_new(cpu_env
,
133 offsetof(CPUPPCState
, so
), "SO");
134 cpu_ov
= tcg_global_mem_new(cpu_env
,
135 offsetof(CPUPPCState
, ov
), "OV");
136 cpu_ca
= tcg_global_mem_new(cpu_env
,
137 offsetof(CPUPPCState
, ca
), "CA");
138 cpu_ov32
= tcg_global_mem_new(cpu_env
,
139 offsetof(CPUPPCState
, ov32
), "OV32");
140 cpu_ca32
= tcg_global_mem_new(cpu_env
,
141 offsetof(CPUPPCState
, ca32
), "CA32");
143 cpu_reserve
= tcg_global_mem_new(cpu_env
,
144 offsetof(CPUPPCState
, reserve_addr
),
146 cpu_reserve_val
= tcg_global_mem_new(cpu_env
,
147 offsetof(CPUPPCState
, reserve_val
),
149 cpu_reserve_val2
= tcg_global_mem_new(cpu_env
,
150 offsetof(CPUPPCState
, reserve_val2
),
153 cpu_fpscr
= tcg_global_mem_new(cpu_env
,
154 offsetof(CPUPPCState
, fpscr
), "fpscr");
156 cpu_access_type
= tcg_global_mem_new_i32(cpu_env
,
157 offsetof(CPUPPCState
, access_type
),
161 /* internal defines */
162 struct DisasContext
{
163 DisasContextBase base
;
164 target_ulong cia
; /* current instruction address */
166 /* Routine used to access memory */
167 bool pr
, hv
, dr
, le_mode
;
169 bool need_access_type
;
172 /* Translation flags */
173 MemOp default_tcg_memop_mask
;
174 #if defined(TARGET_PPC64)
179 bool altivec_enabled
;
190 ppc_spr_t
*spr_cb
; /* Needed to check rights for mfspr/mtspr */
191 int singlestep_enabled
;
193 uint64_t insns_flags
;
194 uint64_t insns_flags2
;
197 #define DISAS_EXIT DISAS_TARGET_0 /* exit to main loop, pc updated */
198 #define DISAS_EXIT_UPDATE DISAS_TARGET_1 /* exit to main loop, pc stale */
199 #define DISAS_CHAIN DISAS_TARGET_2 /* lookup next tb, pc updated */
200 #define DISAS_CHAIN_UPDATE DISAS_TARGET_3 /* lookup next tb, pc stale */
202 /* Return true iff byteswap is needed in a scalar memop */
203 static inline bool need_byteswap(const DisasContext
*ctx
)
205 #if TARGET_BIG_ENDIAN
208 return !ctx
->le_mode
;
212 /* True when active word size < size of target_long. */
214 # define NARROW_MODE(C) (!(C)->sf_mode)
216 # define NARROW_MODE(C) 0
219 struct opc_handler_t
{
220 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
222 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
224 /* instruction type */
226 /* extended instruction type */
229 void (*handler
)(DisasContext
*ctx
);
232 /* SPR load/store helpers */
233 static inline void gen_load_spr(TCGv t
, int reg
)
235 tcg_gen_ld_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
238 static inline void gen_store_spr(int reg
, TCGv t
)
240 tcg_gen_st_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
243 static inline void gen_set_access_type(DisasContext
*ctx
, int access_type
)
245 if (ctx
->need_access_type
&& ctx
->access_type
!= access_type
) {
246 tcg_gen_movi_i32(cpu_access_type
, access_type
);
247 ctx
->access_type
= access_type
;
251 static inline void gen_update_nip(DisasContext
*ctx
, target_ulong nip
)
253 if (NARROW_MODE(ctx
)) {
256 tcg_gen_movi_tl(cpu_nip
, nip
);
259 static void gen_exception_err(DisasContext
*ctx
, uint32_t excp
, uint32_t error
)
264 * These are all synchronous exceptions, we set the PC back to the
265 * faulting instruction
267 gen_update_nip(ctx
, ctx
->cia
);
268 t0
= tcg_constant_i32(excp
);
269 t1
= tcg_constant_i32(error
);
270 gen_helper_raise_exception_err(cpu_env
, t0
, t1
);
271 ctx
->base
.is_jmp
= DISAS_NORETURN
;
274 static void gen_exception(DisasContext
*ctx
, uint32_t excp
)
279 * These are all synchronous exceptions, we set the PC back to the
280 * faulting instruction
282 gen_update_nip(ctx
, ctx
->cia
);
283 t0
= tcg_constant_i32(excp
);
284 gen_helper_raise_exception(cpu_env
, t0
);
285 ctx
->base
.is_jmp
= DISAS_NORETURN
;
288 static void gen_exception_nip(DisasContext
*ctx
, uint32_t excp
,
293 gen_update_nip(ctx
, nip
);
294 t0
= tcg_constant_i32(excp
);
295 gen_helper_raise_exception(cpu_env
, t0
);
296 ctx
->base
.is_jmp
= DISAS_NORETURN
;
299 #if !defined(CONFIG_USER_ONLY)
300 static void gen_ppc_maybe_interrupt(DisasContext
*ctx
)
302 translator_io_start(&ctx
->base
);
303 gen_helper_ppc_maybe_interrupt(cpu_env
);
308 * Tells the caller what is the appropriate exception to generate and prepares
309 * SPR registers for this exception.
311 * The exception can be either POWERPC_EXCP_TRACE (on most PowerPCs) or
312 * POWERPC_EXCP_DEBUG (on BookE).
314 static uint32_t gen_prep_dbgex(DisasContext
*ctx
)
316 if (ctx
->flags
& POWERPC_FLAG_DE
) {
317 target_ulong dbsr
= 0;
318 if (ctx
->singlestep_enabled
& CPU_SINGLE_STEP
) {
321 /* Must have been branch */
324 TCGv t0
= tcg_temp_new();
325 gen_load_spr(t0
, SPR_BOOKE_DBSR
);
326 tcg_gen_ori_tl(t0
, t0
, dbsr
);
327 gen_store_spr(SPR_BOOKE_DBSR
, t0
);
328 return POWERPC_EXCP_DEBUG
;
330 return POWERPC_EXCP_TRACE
;
334 static void gen_debug_exception(DisasContext
*ctx
)
336 gen_helper_raise_exception(cpu_env
, tcg_constant_i32(gen_prep_dbgex(ctx
)));
337 ctx
->base
.is_jmp
= DISAS_NORETURN
;
340 static inline void gen_inval_exception(DisasContext
*ctx
, uint32_t error
)
342 /* Will be converted to program check if needed */
343 gen_exception_err(ctx
, POWERPC_EXCP_HV_EMU
, POWERPC_EXCP_INVAL
| error
);
346 static inline void gen_priv_exception(DisasContext
*ctx
, uint32_t error
)
348 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_PRIV
| error
);
351 static inline void gen_hvpriv_exception(DisasContext
*ctx
, uint32_t error
)
353 /* Will be converted to program check if needed */
354 gen_exception_err(ctx
, POWERPC_EXCP_HV_EMU
, POWERPC_EXCP_PRIV
| error
);
357 /*****************************************************************************/
358 /* SPR READ/WRITE CALLBACKS */
360 void spr_noaccess(DisasContext
*ctx
, int gprn
, int sprn
)
363 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
364 printf("ERROR: try to access SPR %d !\n", sprn
);
368 /* #define PPC_DUMP_SPR_ACCESSES */
372 * do nothing but store/retrieve spr value
374 static void spr_load_dump_spr(int sprn
)
376 #ifdef PPC_DUMP_SPR_ACCESSES
377 TCGv_i32 t0
= tcg_constant_i32(sprn
);
378 gen_helper_load_dump_spr(cpu_env
, t0
);
382 void spr_read_generic(DisasContext
*ctx
, int gprn
, int sprn
)
384 gen_load_spr(cpu_gpr
[gprn
], sprn
);
385 spr_load_dump_spr(sprn
);
388 static void spr_store_dump_spr(int sprn
)
390 #ifdef PPC_DUMP_SPR_ACCESSES
391 TCGv_i32 t0
= tcg_constant_i32(sprn
);
392 gen_helper_store_dump_spr(cpu_env
, t0
);
396 void spr_write_generic(DisasContext
*ctx
, int sprn
, int gprn
)
398 gen_store_spr(sprn
, cpu_gpr
[gprn
]);
399 spr_store_dump_spr(sprn
);
402 void spr_write_generic32(DisasContext
*ctx
, int sprn
, int gprn
)
405 TCGv t0
= tcg_temp_new();
406 tcg_gen_ext32u_tl(t0
, cpu_gpr
[gprn
]);
407 gen_store_spr(sprn
, t0
);
408 spr_store_dump_spr(sprn
);
410 spr_write_generic(ctx
, sprn
, gprn
);
414 void spr_write_CTRL(DisasContext
*ctx
, int sprn
, int gprn
)
416 spr_write_generic32(ctx
, sprn
, gprn
);
419 * SPR_CTRL writes must force a new translation block,
420 * allowing the PMU to calculate the run latch events with
423 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
426 #if !defined(CONFIG_USER_ONLY)
427 void spr_write_clear(DisasContext
*ctx
, int sprn
, int gprn
)
429 TCGv t0
= tcg_temp_new();
430 TCGv t1
= tcg_temp_new();
431 gen_load_spr(t0
, sprn
);
432 tcg_gen_neg_tl(t1
, cpu_gpr
[gprn
]);
433 tcg_gen_and_tl(t0
, t0
, t1
);
434 gen_store_spr(sprn
, t0
);
437 void spr_access_nop(DisasContext
*ctx
, int sprn
, int gprn
)
443 /* SPR common to all PowerPC */
445 void spr_read_xer(DisasContext
*ctx
, int gprn
, int sprn
)
447 TCGv dst
= cpu_gpr
[gprn
];
448 TCGv t0
= tcg_temp_new();
449 TCGv t1
= tcg_temp_new();
450 TCGv t2
= tcg_temp_new();
451 tcg_gen_mov_tl(dst
, cpu_xer
);
452 tcg_gen_shli_tl(t0
, cpu_so
, XER_SO
);
453 tcg_gen_shli_tl(t1
, cpu_ov
, XER_OV
);
454 tcg_gen_shli_tl(t2
, cpu_ca
, XER_CA
);
455 tcg_gen_or_tl(t0
, t0
, t1
);
456 tcg_gen_or_tl(dst
, dst
, t2
);
457 tcg_gen_or_tl(dst
, dst
, t0
);
458 if (is_isa300(ctx
)) {
459 tcg_gen_shli_tl(t0
, cpu_ov32
, XER_OV32
);
460 tcg_gen_or_tl(dst
, dst
, t0
);
461 tcg_gen_shli_tl(t0
, cpu_ca32
, XER_CA32
);
462 tcg_gen_or_tl(dst
, dst
, t0
);
466 void spr_write_xer(DisasContext
*ctx
, int sprn
, int gprn
)
468 TCGv src
= cpu_gpr
[gprn
];
469 /* Write all flags, while reading back check for isa300 */
470 tcg_gen_andi_tl(cpu_xer
, src
,
472 (1u << XER_OV
) | (1u << XER_OV32
) |
473 (1u << XER_CA
) | (1u << XER_CA32
)));
474 tcg_gen_extract_tl(cpu_ov32
, src
, XER_OV32
, 1);
475 tcg_gen_extract_tl(cpu_ca32
, src
, XER_CA32
, 1);
476 tcg_gen_extract_tl(cpu_so
, src
, XER_SO
, 1);
477 tcg_gen_extract_tl(cpu_ov
, src
, XER_OV
, 1);
478 tcg_gen_extract_tl(cpu_ca
, src
, XER_CA
, 1);
482 void spr_read_lr(DisasContext
*ctx
, int gprn
, int sprn
)
484 tcg_gen_mov_tl(cpu_gpr
[gprn
], cpu_lr
);
487 void spr_write_lr(DisasContext
*ctx
, int sprn
, int gprn
)
489 tcg_gen_mov_tl(cpu_lr
, cpu_gpr
[gprn
]);
493 #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY)
494 void spr_read_cfar(DisasContext
*ctx
, int gprn
, int sprn
)
496 tcg_gen_mov_tl(cpu_gpr
[gprn
], cpu_cfar
);
499 void spr_write_cfar(DisasContext
*ctx
, int sprn
, int gprn
)
501 tcg_gen_mov_tl(cpu_cfar
, cpu_gpr
[gprn
]);
503 #endif /* defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY) */
506 void spr_read_ctr(DisasContext
*ctx
, int gprn
, int sprn
)
508 tcg_gen_mov_tl(cpu_gpr
[gprn
], cpu_ctr
);
511 void spr_write_ctr(DisasContext
*ctx
, int sprn
, int gprn
)
513 tcg_gen_mov_tl(cpu_ctr
, cpu_gpr
[gprn
]);
516 /* User read access to SPR */
522 void spr_read_ureg(DisasContext
*ctx
, int gprn
, int sprn
)
524 gen_load_spr(cpu_gpr
[gprn
], sprn
+ 0x10);
527 #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY)
528 void spr_write_ureg(DisasContext
*ctx
, int sprn
, int gprn
)
530 gen_store_spr(sprn
+ 0x10, cpu_gpr
[gprn
]);
534 /* SPR common to all non-embedded PowerPC */
536 #if !defined(CONFIG_USER_ONLY)
537 void spr_read_decr(DisasContext
*ctx
, int gprn
, int sprn
)
539 translator_io_start(&ctx
->base
);
540 gen_helper_load_decr(cpu_gpr
[gprn
], cpu_env
);
543 void spr_write_decr(DisasContext
*ctx
, int sprn
, int gprn
)
545 translator_io_start(&ctx
->base
);
546 gen_helper_store_decr(cpu_env
, cpu_gpr
[gprn
]);
550 /* SPR common to all non-embedded PowerPC, except 601 */
552 void spr_read_tbl(DisasContext
*ctx
, int gprn
, int sprn
)
554 translator_io_start(&ctx
->base
);
555 gen_helper_load_tbl(cpu_gpr
[gprn
], cpu_env
);
558 void spr_read_tbu(DisasContext
*ctx
, int gprn
, int sprn
)
560 translator_io_start(&ctx
->base
);
561 gen_helper_load_tbu(cpu_gpr
[gprn
], cpu_env
);
564 void spr_read_atbl(DisasContext
*ctx
, int gprn
, int sprn
)
566 gen_helper_load_atbl(cpu_gpr
[gprn
], cpu_env
);
569 void spr_read_atbu(DisasContext
*ctx
, int gprn
, int sprn
)
571 gen_helper_load_atbu(cpu_gpr
[gprn
], cpu_env
);
574 #if !defined(CONFIG_USER_ONLY)
575 void spr_write_tbl(DisasContext
*ctx
, int sprn
, int gprn
)
577 translator_io_start(&ctx
->base
);
578 gen_helper_store_tbl(cpu_env
, cpu_gpr
[gprn
]);
581 void spr_write_tbu(DisasContext
*ctx
, int sprn
, int gprn
)
583 translator_io_start(&ctx
->base
);
584 gen_helper_store_tbu(cpu_env
, cpu_gpr
[gprn
]);
587 void spr_write_atbl(DisasContext
*ctx
, int sprn
, int gprn
)
589 gen_helper_store_atbl(cpu_env
, cpu_gpr
[gprn
]);
592 void spr_write_atbu(DisasContext
*ctx
, int sprn
, int gprn
)
594 gen_helper_store_atbu(cpu_env
, cpu_gpr
[gprn
]);
597 #if defined(TARGET_PPC64)
598 void spr_read_purr(DisasContext
*ctx
, int gprn
, int sprn
)
600 translator_io_start(&ctx
->base
);
601 gen_helper_load_purr(cpu_gpr
[gprn
], cpu_env
);
604 void spr_write_purr(DisasContext
*ctx
, int sprn
, int gprn
)
606 translator_io_start(&ctx
->base
);
607 gen_helper_store_purr(cpu_env
, cpu_gpr
[gprn
]);
611 void spr_read_hdecr(DisasContext
*ctx
, int gprn
, int sprn
)
613 translator_io_start(&ctx
->base
);
614 gen_helper_load_hdecr(cpu_gpr
[gprn
], cpu_env
);
617 void spr_write_hdecr(DisasContext
*ctx
, int sprn
, int gprn
)
619 translator_io_start(&ctx
->base
);
620 gen_helper_store_hdecr(cpu_env
, cpu_gpr
[gprn
]);
623 void spr_read_vtb(DisasContext
*ctx
, int gprn
, int sprn
)
625 translator_io_start(&ctx
->base
);
626 gen_helper_load_vtb(cpu_gpr
[gprn
], cpu_env
);
629 void spr_write_vtb(DisasContext
*ctx
, int sprn
, int gprn
)
631 translator_io_start(&ctx
->base
);
632 gen_helper_store_vtb(cpu_env
, cpu_gpr
[gprn
]);
635 void spr_write_tbu40(DisasContext
*ctx
, int sprn
, int gprn
)
637 translator_io_start(&ctx
->base
);
638 gen_helper_store_tbu40(cpu_env
, cpu_gpr
[gprn
]);
644 #if !defined(CONFIG_USER_ONLY)
645 /* IBAT0U...IBAT0U */
646 /* IBAT0L...IBAT7L */
647 void spr_read_ibat(DisasContext
*ctx
, int gprn
, int sprn
)
649 tcg_gen_ld_tl(cpu_gpr
[gprn
], cpu_env
,
650 offsetof(CPUPPCState
,
651 IBAT
[sprn
& 1][(sprn
- SPR_IBAT0U
) / 2]));
654 void spr_read_ibat_h(DisasContext
*ctx
, int gprn
, int sprn
)
656 tcg_gen_ld_tl(cpu_gpr
[gprn
], cpu_env
,
657 offsetof(CPUPPCState
,
658 IBAT
[sprn
& 1][((sprn
- SPR_IBAT4U
) / 2) + 4]));
661 void spr_write_ibatu(DisasContext
*ctx
, int sprn
, int gprn
)
663 TCGv_i32 t0
= tcg_constant_i32((sprn
- SPR_IBAT0U
) / 2);
664 gen_helper_store_ibatu(cpu_env
, t0
, cpu_gpr
[gprn
]);
667 void spr_write_ibatu_h(DisasContext
*ctx
, int sprn
, int gprn
)
669 TCGv_i32 t0
= tcg_constant_i32(((sprn
- SPR_IBAT4U
) / 2) + 4);
670 gen_helper_store_ibatu(cpu_env
, t0
, cpu_gpr
[gprn
]);
673 void spr_write_ibatl(DisasContext
*ctx
, int sprn
, int gprn
)
675 TCGv_i32 t0
= tcg_constant_i32((sprn
- SPR_IBAT0L
) / 2);
676 gen_helper_store_ibatl(cpu_env
, t0
, cpu_gpr
[gprn
]);
679 void spr_write_ibatl_h(DisasContext
*ctx
, int sprn
, int gprn
)
681 TCGv_i32 t0
= tcg_constant_i32(((sprn
- SPR_IBAT4L
) / 2) + 4);
682 gen_helper_store_ibatl(cpu_env
, t0
, cpu_gpr
[gprn
]);
685 /* DBAT0U...DBAT7U */
686 /* DBAT0L...DBAT7L */
687 void spr_read_dbat(DisasContext
*ctx
, int gprn
, int sprn
)
689 tcg_gen_ld_tl(cpu_gpr
[gprn
], cpu_env
,
690 offsetof(CPUPPCState
,
691 DBAT
[sprn
& 1][(sprn
- SPR_DBAT0U
) / 2]));
694 void spr_read_dbat_h(DisasContext
*ctx
, int gprn
, int sprn
)
696 tcg_gen_ld_tl(cpu_gpr
[gprn
], cpu_env
,
697 offsetof(CPUPPCState
,
698 DBAT
[sprn
& 1][((sprn
- SPR_DBAT4U
) / 2) + 4]));
701 void spr_write_dbatu(DisasContext
*ctx
, int sprn
, int gprn
)
703 TCGv_i32 t0
= tcg_constant_i32((sprn
- SPR_DBAT0U
) / 2);
704 gen_helper_store_dbatu(cpu_env
, t0
, cpu_gpr
[gprn
]);
707 void spr_write_dbatu_h(DisasContext
*ctx
, int sprn
, int gprn
)
709 TCGv_i32 t0
= tcg_constant_i32(((sprn
- SPR_DBAT4U
) / 2) + 4);
710 gen_helper_store_dbatu(cpu_env
, t0
, cpu_gpr
[gprn
]);
713 void spr_write_dbatl(DisasContext
*ctx
, int sprn
, int gprn
)
715 TCGv_i32 t0
= tcg_constant_i32((sprn
- SPR_DBAT0L
) / 2);
716 gen_helper_store_dbatl(cpu_env
, t0
, cpu_gpr
[gprn
]);
719 void spr_write_dbatl_h(DisasContext
*ctx
, int sprn
, int gprn
)
721 TCGv_i32 t0
= tcg_constant_i32(((sprn
- SPR_DBAT4L
) / 2) + 4);
722 gen_helper_store_dbatl(cpu_env
, t0
, cpu_gpr
[gprn
]);
726 void spr_write_sdr1(DisasContext
*ctx
, int sprn
, int gprn
)
728 gen_helper_store_sdr1(cpu_env
, cpu_gpr
[gprn
]);
731 #if defined(TARGET_PPC64)
732 /* 64 bits PowerPC specific SPRs */
734 void spr_write_pidr(DisasContext
*ctx
, int sprn
, int gprn
)
736 gen_helper_store_pidr(cpu_env
, cpu_gpr
[gprn
]);
739 void spr_write_lpidr(DisasContext
*ctx
, int sprn
, int gprn
)
741 gen_helper_store_lpidr(cpu_env
, cpu_gpr
[gprn
]);
744 void spr_read_hior(DisasContext
*ctx
, int gprn
, int sprn
)
746 tcg_gen_ld_tl(cpu_gpr
[gprn
], cpu_env
, offsetof(CPUPPCState
, excp_prefix
));
749 void spr_write_hior(DisasContext
*ctx
, int sprn
, int gprn
)
751 TCGv t0
= tcg_temp_new();
752 tcg_gen_andi_tl(t0
, cpu_gpr
[gprn
], 0x3FFFFF00000ULL
);
753 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, excp_prefix
));
755 void spr_write_ptcr(DisasContext
*ctx
, int sprn
, int gprn
)
757 gen_helper_store_ptcr(cpu_env
, cpu_gpr
[gprn
]);
760 void spr_write_pcr(DisasContext
*ctx
, int sprn
, int gprn
)
762 gen_helper_store_pcr(cpu_env
, cpu_gpr
[gprn
]);
766 void spr_read_dpdes(DisasContext
*ctx
, int gprn
, int sprn
)
768 gen_helper_load_dpdes(cpu_gpr
[gprn
], cpu_env
);
771 void spr_write_dpdes(DisasContext
*ctx
, int sprn
, int gprn
)
773 gen_helper_store_dpdes(cpu_env
, cpu_gpr
[gprn
]);
778 /* PowerPC 40x specific registers */
779 #if !defined(CONFIG_USER_ONLY)
780 void spr_read_40x_pit(DisasContext
*ctx
, int gprn
, int sprn
)
782 translator_io_start(&ctx
->base
);
783 gen_helper_load_40x_pit(cpu_gpr
[gprn
], cpu_env
);
786 void spr_write_40x_pit(DisasContext
*ctx
, int sprn
, int gprn
)
788 translator_io_start(&ctx
->base
);
789 gen_helper_store_40x_pit(cpu_env
, cpu_gpr
[gprn
]);
792 void spr_write_40x_dbcr0(DisasContext
*ctx
, int sprn
, int gprn
)
794 translator_io_start(&ctx
->base
);
795 gen_store_spr(sprn
, cpu_gpr
[gprn
]);
796 gen_helper_store_40x_dbcr0(cpu_env
, cpu_gpr
[gprn
]);
797 /* We must stop translation as we may have rebooted */
798 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
801 void spr_write_40x_sler(DisasContext
*ctx
, int sprn
, int gprn
)
803 translator_io_start(&ctx
->base
);
804 gen_helper_store_40x_sler(cpu_env
, cpu_gpr
[gprn
]);
807 void spr_write_40x_tcr(DisasContext
*ctx
, int sprn
, int gprn
)
809 translator_io_start(&ctx
->base
);
810 gen_helper_store_40x_tcr(cpu_env
, cpu_gpr
[gprn
]);
813 void spr_write_40x_tsr(DisasContext
*ctx
, int sprn
, int gprn
)
815 translator_io_start(&ctx
->base
);
816 gen_helper_store_40x_tsr(cpu_env
, cpu_gpr
[gprn
]);
819 void spr_write_40x_pid(DisasContext
*ctx
, int sprn
, int gprn
)
821 TCGv t0
= tcg_temp_new();
822 tcg_gen_andi_tl(t0
, cpu_gpr
[gprn
], 0xFF);
823 gen_helper_store_40x_pid(cpu_env
, t0
);
826 void spr_write_booke_tcr(DisasContext
*ctx
, int sprn
, int gprn
)
828 translator_io_start(&ctx
->base
);
829 gen_helper_store_booke_tcr(cpu_env
, cpu_gpr
[gprn
]);
832 void spr_write_booke_tsr(DisasContext
*ctx
, int sprn
, int gprn
)
834 translator_io_start(&ctx
->base
);
835 gen_helper_store_booke_tsr(cpu_env
, cpu_gpr
[gprn
]);
840 #if !defined(CONFIG_USER_ONLY)
841 void spr_write_pir(DisasContext
*ctx
, int sprn
, int gprn
)
843 TCGv t0
= tcg_temp_new();
844 tcg_gen_andi_tl(t0
, cpu_gpr
[gprn
], 0xF);
845 gen_store_spr(SPR_PIR
, t0
);
849 /* SPE specific registers */
850 void spr_read_spefscr(DisasContext
*ctx
, int gprn
, int sprn
)
852 TCGv_i32 t0
= tcg_temp_new_i32();
853 tcg_gen_ld_i32(t0
, cpu_env
, offsetof(CPUPPCState
, spe_fscr
));
854 tcg_gen_extu_i32_tl(cpu_gpr
[gprn
], t0
);
857 void spr_write_spefscr(DisasContext
*ctx
, int sprn
, int gprn
)
859 TCGv_i32 t0
= tcg_temp_new_i32();
860 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[gprn
]);
861 tcg_gen_st_i32(t0
, cpu_env
, offsetof(CPUPPCState
, spe_fscr
));
864 #if !defined(CONFIG_USER_ONLY)
865 /* Callback used to write the exception vector base */
866 void spr_write_excp_prefix(DisasContext
*ctx
, int sprn
, int gprn
)
868 TCGv t0
= tcg_temp_new();
869 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUPPCState
, ivpr_mask
));
870 tcg_gen_and_tl(t0
, t0
, cpu_gpr
[gprn
]);
871 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, excp_prefix
));
872 gen_store_spr(sprn
, t0
);
875 void spr_write_excp_vector(DisasContext
*ctx
, int sprn
, int gprn
)
879 if (sprn
>= SPR_BOOKE_IVOR0
&& sprn
<= SPR_BOOKE_IVOR15
) {
880 sprn_offs
= sprn
- SPR_BOOKE_IVOR0
;
881 } else if (sprn
>= SPR_BOOKE_IVOR32
&& sprn
<= SPR_BOOKE_IVOR37
) {
882 sprn_offs
= sprn
- SPR_BOOKE_IVOR32
+ 32;
883 } else if (sprn
>= SPR_BOOKE_IVOR38
&& sprn
<= SPR_BOOKE_IVOR42
) {
884 sprn_offs
= sprn
- SPR_BOOKE_IVOR38
+ 38;
886 qemu_log_mask(LOG_GUEST_ERROR
, "Trying to write an unknown exception"
887 " vector 0x%03x\n", sprn
);
888 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
892 TCGv t0
= tcg_temp_new();
893 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUPPCState
, ivor_mask
));
894 tcg_gen_and_tl(t0
, t0
, cpu_gpr
[gprn
]);
895 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, excp_vectors
[sprn_offs
]));
896 gen_store_spr(sprn
, t0
);
901 #ifndef CONFIG_USER_ONLY
902 void spr_write_amr(DisasContext
*ctx
, int sprn
, int gprn
)
904 TCGv t0
= tcg_temp_new();
905 TCGv t1
= tcg_temp_new();
906 TCGv t2
= tcg_temp_new();
909 * Note, the HV=1 PR=0 case is handled earlier by simply using
910 * spr_write_generic for HV mode in the SPR table
913 /* Build insertion mask into t1 based on context */
915 gen_load_spr(t1
, SPR_UAMOR
);
917 gen_load_spr(t1
, SPR_AMOR
);
920 /* Mask new bits into t2 */
921 tcg_gen_and_tl(t2
, t1
, cpu_gpr
[gprn
]);
923 /* Load AMR and clear new bits in t0 */
924 gen_load_spr(t0
, SPR_AMR
);
925 tcg_gen_andc_tl(t0
, t0
, t1
);
927 /* Or'in new bits and write it out */
928 tcg_gen_or_tl(t0
, t0
, t2
);
929 gen_store_spr(SPR_AMR
, t0
);
930 spr_store_dump_spr(SPR_AMR
);
933 void spr_write_uamor(DisasContext
*ctx
, int sprn
, int gprn
)
935 TCGv t0
= tcg_temp_new();
936 TCGv t1
= tcg_temp_new();
937 TCGv t2
= tcg_temp_new();
940 * Note, the HV=1 case is handled earlier by simply using
941 * spr_write_generic for HV mode in the SPR table
944 /* Build insertion mask into t1 based on context */
945 gen_load_spr(t1
, SPR_AMOR
);
947 /* Mask new bits into t2 */
948 tcg_gen_and_tl(t2
, t1
, cpu_gpr
[gprn
]);
950 /* Load AMR and clear new bits in t0 */
951 gen_load_spr(t0
, SPR_UAMOR
);
952 tcg_gen_andc_tl(t0
, t0
, t1
);
954 /* Or'in new bits and write it out */
955 tcg_gen_or_tl(t0
, t0
, t2
);
956 gen_store_spr(SPR_UAMOR
, t0
);
957 spr_store_dump_spr(SPR_UAMOR
);
960 void spr_write_iamr(DisasContext
*ctx
, int sprn
, int gprn
)
962 TCGv t0
= tcg_temp_new();
963 TCGv t1
= tcg_temp_new();
964 TCGv t2
= tcg_temp_new();
967 * Note, the HV=1 case is handled earlier by simply using
968 * spr_write_generic for HV mode in the SPR table
971 /* Build insertion mask into t1 based on context */
972 gen_load_spr(t1
, SPR_AMOR
);
974 /* Mask new bits into t2 */
975 tcg_gen_and_tl(t2
, t1
, cpu_gpr
[gprn
]);
977 /* Load AMR and clear new bits in t0 */
978 gen_load_spr(t0
, SPR_IAMR
);
979 tcg_gen_andc_tl(t0
, t0
, t1
);
981 /* Or'in new bits and write it out */
982 tcg_gen_or_tl(t0
, t0
, t2
);
983 gen_store_spr(SPR_IAMR
, t0
);
984 spr_store_dump_spr(SPR_IAMR
);
989 #ifndef CONFIG_USER_ONLY
990 void spr_read_thrm(DisasContext
*ctx
, int gprn
, int sprn
)
992 gen_helper_fixup_thrm(cpu_env
);
993 gen_load_spr(cpu_gpr
[gprn
], sprn
);
994 spr_load_dump_spr(sprn
);
996 #endif /* !CONFIG_USER_ONLY */
998 #if !defined(CONFIG_USER_ONLY)
999 void spr_write_e500_l1csr0(DisasContext
*ctx
, int sprn
, int gprn
)
1001 TCGv t0
= tcg_temp_new();
1003 tcg_gen_andi_tl(t0
, cpu_gpr
[gprn
], L1CSR0_DCE
| L1CSR0_CPE
);
1004 gen_store_spr(sprn
, t0
);
1007 void spr_write_e500_l1csr1(DisasContext
*ctx
, int sprn
, int gprn
)
1009 TCGv t0
= tcg_temp_new();
1011 tcg_gen_andi_tl(t0
, cpu_gpr
[gprn
], L1CSR1_ICE
| L1CSR1_CPE
);
1012 gen_store_spr(sprn
, t0
);
1015 void spr_write_e500_l2csr0(DisasContext
*ctx
, int sprn
, int gprn
)
1017 TCGv t0
= tcg_temp_new();
1019 tcg_gen_andi_tl(t0
, cpu_gpr
[gprn
],
1020 ~(E500_L2CSR0_L2FI
| E500_L2CSR0_L2FL
| E500_L2CSR0_L2LFC
));
1021 gen_store_spr(sprn
, t0
);
1024 void spr_write_booke206_mmucsr0(DisasContext
*ctx
, int sprn
, int gprn
)
1026 gen_helper_booke206_tlbflush(cpu_env
, cpu_gpr
[gprn
]);
1029 void spr_write_booke_pid(DisasContext
*ctx
, int sprn
, int gprn
)
1031 TCGv_i32 t0
= tcg_constant_i32(sprn
);
1032 gen_helper_booke_setpid(cpu_env
, t0
, cpu_gpr
[gprn
]);
1035 void spr_write_eplc(DisasContext
*ctx
, int sprn
, int gprn
)
1037 gen_helper_booke_set_eplc(cpu_env
, cpu_gpr
[gprn
]);
1040 void spr_write_epsc(DisasContext
*ctx
, int sprn
, int gprn
)
1042 gen_helper_booke_set_epsc(cpu_env
, cpu_gpr
[gprn
]);
1047 #if !defined(CONFIG_USER_ONLY)
1048 void spr_write_mas73(DisasContext
*ctx
, int sprn
, int gprn
)
1050 TCGv val
= tcg_temp_new();
1051 tcg_gen_ext32u_tl(val
, cpu_gpr
[gprn
]);
1052 gen_store_spr(SPR_BOOKE_MAS3
, val
);
1053 tcg_gen_shri_tl(val
, cpu_gpr
[gprn
], 32);
1054 gen_store_spr(SPR_BOOKE_MAS7
, val
);
1057 void spr_read_mas73(DisasContext
*ctx
, int gprn
, int sprn
)
1059 TCGv mas7
= tcg_temp_new();
1060 TCGv mas3
= tcg_temp_new();
1061 gen_load_spr(mas7
, SPR_BOOKE_MAS7
);
1062 tcg_gen_shli_tl(mas7
, mas7
, 32);
1063 gen_load_spr(mas3
, SPR_BOOKE_MAS3
);
1064 tcg_gen_or_tl(cpu_gpr
[gprn
], mas3
, mas7
);
1070 static void gen_fscr_facility_check(DisasContext
*ctx
, int facility_sprn
,
1071 int bit
, int sprn
, int cause
)
1073 TCGv_i32 t1
= tcg_constant_i32(bit
);
1074 TCGv_i32 t2
= tcg_constant_i32(sprn
);
1075 TCGv_i32 t3
= tcg_constant_i32(cause
);
1077 gen_helper_fscr_facility_check(cpu_env
, t1
, t2
, t3
);
1080 static void gen_msr_facility_check(DisasContext
*ctx
, int facility_sprn
,
1081 int bit
, int sprn
, int cause
)
1083 TCGv_i32 t1
= tcg_constant_i32(bit
);
1084 TCGv_i32 t2
= tcg_constant_i32(sprn
);
1085 TCGv_i32 t3
= tcg_constant_i32(cause
);
1087 gen_helper_msr_facility_check(cpu_env
, t1
, t2
, t3
);
1090 void spr_read_prev_upper32(DisasContext
*ctx
, int gprn
, int sprn
)
1092 TCGv spr_up
= tcg_temp_new();
1093 TCGv spr
= tcg_temp_new();
1095 gen_load_spr(spr
, sprn
- 1);
1096 tcg_gen_shri_tl(spr_up
, spr
, 32);
1097 tcg_gen_ext32u_tl(cpu_gpr
[gprn
], spr_up
);
1100 void spr_write_prev_upper32(DisasContext
*ctx
, int sprn
, int gprn
)
1102 TCGv spr
= tcg_temp_new();
1104 gen_load_spr(spr
, sprn
- 1);
1105 tcg_gen_deposit_tl(spr
, spr
, cpu_gpr
[gprn
], 32, 32);
1106 gen_store_spr(sprn
- 1, spr
);
1109 #if !defined(CONFIG_USER_ONLY)
1110 void spr_write_hmer(DisasContext
*ctx
, int sprn
, int gprn
)
1112 TCGv hmer
= tcg_temp_new();
1114 gen_load_spr(hmer
, sprn
);
1115 tcg_gen_and_tl(hmer
, cpu_gpr
[gprn
], hmer
);
1116 gen_store_spr(sprn
, hmer
);
1117 spr_store_dump_spr(sprn
);
1120 void spr_write_lpcr(DisasContext
*ctx
, int sprn
, int gprn
)
1122 gen_helper_store_lpcr(cpu_env
, cpu_gpr
[gprn
]);
1124 #endif /* !defined(CONFIG_USER_ONLY) */
1126 void spr_read_tar(DisasContext
*ctx
, int gprn
, int sprn
)
1128 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_TAR
, sprn
, FSCR_IC_TAR
);
1129 spr_read_generic(ctx
, gprn
, sprn
);
1132 void spr_write_tar(DisasContext
*ctx
, int sprn
, int gprn
)
1134 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_TAR
, sprn
, FSCR_IC_TAR
);
1135 spr_write_generic(ctx
, sprn
, gprn
);
1138 void spr_read_tm(DisasContext
*ctx
, int gprn
, int sprn
)
1140 gen_msr_facility_check(ctx
, SPR_FSCR
, MSR_TM
, sprn
, FSCR_IC_TM
);
1141 spr_read_generic(ctx
, gprn
, sprn
);
1144 void spr_write_tm(DisasContext
*ctx
, int sprn
, int gprn
)
1146 gen_msr_facility_check(ctx
, SPR_FSCR
, MSR_TM
, sprn
, FSCR_IC_TM
);
1147 spr_write_generic(ctx
, sprn
, gprn
);
1150 void spr_read_tm_upper32(DisasContext
*ctx
, int gprn
, int sprn
)
1152 gen_msr_facility_check(ctx
, SPR_FSCR
, MSR_TM
, sprn
, FSCR_IC_TM
);
1153 spr_read_prev_upper32(ctx
, gprn
, sprn
);
1156 void spr_write_tm_upper32(DisasContext
*ctx
, int sprn
, int gprn
)
1158 gen_msr_facility_check(ctx
, SPR_FSCR
, MSR_TM
, sprn
, FSCR_IC_TM
);
1159 spr_write_prev_upper32(ctx
, sprn
, gprn
);
1162 void spr_read_ebb(DisasContext
*ctx
, int gprn
, int sprn
)
1164 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_EBB
, sprn
, FSCR_IC_EBB
);
1165 spr_read_generic(ctx
, gprn
, sprn
);
1168 void spr_write_ebb(DisasContext
*ctx
, int sprn
, int gprn
)
1170 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_EBB
, sprn
, FSCR_IC_EBB
);
1171 spr_write_generic(ctx
, sprn
, gprn
);
1174 void spr_read_ebb_upper32(DisasContext
*ctx
, int gprn
, int sprn
)
1176 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_EBB
, sprn
, FSCR_IC_EBB
);
1177 spr_read_prev_upper32(ctx
, gprn
, sprn
);
1180 void spr_write_ebb_upper32(DisasContext
*ctx
, int sprn
, int gprn
)
1182 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_EBB
, sprn
, FSCR_IC_EBB
);
1183 spr_write_prev_upper32(ctx
, sprn
, gprn
);
1186 void spr_read_dexcr_ureg(DisasContext
*ctx
, int gprn
, int sprn
)
1188 TCGv t0
= tcg_temp_new();
1191 * Access to the (H)DEXCR in problem state is done using separated
1192 * SPR indexes which are 16 below the SPR indexes which have full
1193 * access to the (H)DEXCR in privileged state. Problem state can
1194 * only read bits 32:63, bits 0:31 return 0.
1196 * See section 9.3.1-9.3.2 of PowerISA v3.1B
1199 gen_load_spr(t0
, sprn
+ 16);
1200 tcg_gen_ext32u_tl(cpu_gpr
[gprn
], t0
);
1204 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
1205 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
1207 #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
1208 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
1210 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
1211 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
1213 #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
1214 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
1216 #define GEN_HANDLER_E_2(name, opc1, opc2, opc3, opc4, inval, type, type2) \
1217 GEN_OPCODE3(name, opc1, opc2, opc3, opc4, inval, type, type2)
1219 #define GEN_HANDLER2_E_2(name, onam, opc1, opc2, opc3, opc4, inval, typ, typ2) \
1220 GEN_OPCODE4(name, onam, opc1, opc2, opc3, opc4, inval, typ, typ2)
1222 typedef struct opcode_t
{
1223 unsigned char opc1
, opc2
, opc3
, opc4
;
1224 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
1225 unsigned char pad
[4];
1227 opc_handler_t handler
;
1231 static void gen_priv_opc(DisasContext
*ctx
)
1233 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
1236 /* Helpers for priv. check */
1237 #define GEN_PRIV(CTX) \
1239 gen_priv_opc(CTX); return; \
1242 #if defined(CONFIG_USER_ONLY)
1243 #define CHK_HV(CTX) GEN_PRIV(CTX)
1244 #define CHK_SV(CTX) GEN_PRIV(CTX)
1245 #define CHK_HVRM(CTX) GEN_PRIV(CTX)
1247 #define CHK_HV(CTX) \
1249 if (unlikely(ctx->pr || !ctx->hv)) {\
1253 #define CHK_SV(CTX) \
1255 if (unlikely(ctx->pr)) { \
1259 #define CHK_HVRM(CTX) \
1261 if (unlikely(ctx->pr || !ctx->hv || ctx->dr)) { \
1267 #define CHK_NONE(CTX)
1269 /*****************************************************************************/
1270 /* PowerPC instructions table */
1272 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
1282 .handler = &gen_##name, \
1284 .oname = stringify(name), \
1286 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
1297 .handler = &gen_##name, \
1299 .oname = stringify(name), \
1301 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
1311 .handler = &gen_##name, \
1315 #define GEN_OPCODE3(name, op1, op2, op3, op4, invl, _typ, _typ2) \
1325 .handler = &gen_##name, \
1327 .oname = stringify(name), \
1329 #define GEN_OPCODE4(name, onam, op1, op2, op3, op4, invl, _typ, _typ2) \
1339 .handler = &gen_##name, \
1344 /* Invalid instruction */
1345 static void gen_invalid(DisasContext
*ctx
)
1347 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
1350 static opc_handler_t invalid_handler
= {
1351 .inval1
= 0xFFFFFFFF,
1352 .inval2
= 0xFFFFFFFF,
1355 .handler
= gen_invalid
,
1358 /*** Integer comparison ***/
1360 static inline void gen_op_cmp(TCGv arg0
, TCGv arg1
, int s
, int crf
)
1362 TCGv t0
= tcg_temp_new();
1363 TCGv t1
= tcg_temp_new();
1364 TCGv_i32 t
= tcg_temp_new_i32();
1366 tcg_gen_movi_tl(t0
, CRF_EQ
);
1367 tcg_gen_movi_tl(t1
, CRF_LT
);
1368 tcg_gen_movcond_tl((s
? TCG_COND_LT
: TCG_COND_LTU
),
1369 t0
, arg0
, arg1
, t1
, t0
);
1370 tcg_gen_movi_tl(t1
, CRF_GT
);
1371 tcg_gen_movcond_tl((s
? TCG_COND_GT
: TCG_COND_GTU
),
1372 t0
, arg0
, arg1
, t1
, t0
);
1374 tcg_gen_trunc_tl_i32(t
, t0
);
1375 tcg_gen_trunc_tl_i32(cpu_crf
[crf
], cpu_so
);
1376 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t
);
1379 static inline void gen_op_cmpi(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
1381 TCGv t0
= tcg_constant_tl(arg1
);
1382 gen_op_cmp(arg0
, t0
, s
, crf
);
1385 static inline void gen_op_cmp32(TCGv arg0
, TCGv arg1
, int s
, int crf
)
1388 t0
= tcg_temp_new();
1389 t1
= tcg_temp_new();
1391 tcg_gen_ext32s_tl(t0
, arg0
);
1392 tcg_gen_ext32s_tl(t1
, arg1
);
1394 tcg_gen_ext32u_tl(t0
, arg0
);
1395 tcg_gen_ext32u_tl(t1
, arg1
);
1397 gen_op_cmp(t0
, t1
, s
, crf
);
1400 static inline void gen_op_cmpi32(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
1402 TCGv t0
= tcg_constant_tl(arg1
);
1403 gen_op_cmp32(arg0
, t0
, s
, crf
);
1406 static inline void gen_set_Rc0(DisasContext
*ctx
, TCGv reg
)
1408 if (NARROW_MODE(ctx
)) {
1409 gen_op_cmpi32(reg
, 0, 1, 0);
1411 gen_op_cmpi(reg
, 0, 1, 0);
1415 /* cmprb - range comparison: isupper, isaplha, islower*/
1416 static void gen_cmprb(DisasContext
*ctx
)
1418 TCGv_i32 src1
= tcg_temp_new_i32();
1419 TCGv_i32 src2
= tcg_temp_new_i32();
1420 TCGv_i32 src2lo
= tcg_temp_new_i32();
1421 TCGv_i32 src2hi
= tcg_temp_new_i32();
1422 TCGv_i32 crf
= cpu_crf
[crfD(ctx
->opcode
)];
1424 tcg_gen_trunc_tl_i32(src1
, cpu_gpr
[rA(ctx
->opcode
)]);
1425 tcg_gen_trunc_tl_i32(src2
, cpu_gpr
[rB(ctx
->opcode
)]);
1427 tcg_gen_andi_i32(src1
, src1
, 0xFF);
1428 tcg_gen_ext8u_i32(src2lo
, src2
);
1429 tcg_gen_shri_i32(src2
, src2
, 8);
1430 tcg_gen_ext8u_i32(src2hi
, src2
);
1432 tcg_gen_setcond_i32(TCG_COND_LEU
, src2lo
, src2lo
, src1
);
1433 tcg_gen_setcond_i32(TCG_COND_LEU
, src2hi
, src1
, src2hi
);
1434 tcg_gen_and_i32(crf
, src2lo
, src2hi
);
1436 if (ctx
->opcode
& 0x00200000) {
1437 tcg_gen_shri_i32(src2
, src2
, 8);
1438 tcg_gen_ext8u_i32(src2lo
, src2
);
1439 tcg_gen_shri_i32(src2
, src2
, 8);
1440 tcg_gen_ext8u_i32(src2hi
, src2
);
1441 tcg_gen_setcond_i32(TCG_COND_LEU
, src2lo
, src2lo
, src1
);
1442 tcg_gen_setcond_i32(TCG_COND_LEU
, src2hi
, src1
, src2hi
);
1443 tcg_gen_and_i32(src2lo
, src2lo
, src2hi
);
1444 tcg_gen_or_i32(crf
, crf
, src2lo
);
1446 tcg_gen_shli_i32(crf
, crf
, CRF_GT_BIT
);
1449 #if defined(TARGET_PPC64)
1451 static void gen_cmpeqb(DisasContext
*ctx
)
1453 gen_helper_cmpeqb(cpu_crf
[crfD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1454 cpu_gpr
[rB(ctx
->opcode
)]);
1458 /* isel (PowerPC 2.03 specification) */
1459 static void gen_isel(DisasContext
*ctx
)
1461 uint32_t bi
= rC(ctx
->opcode
);
1462 uint32_t mask
= 0x08 >> (bi
& 0x03);
1463 TCGv t0
= tcg_temp_new();
1466 tcg_gen_extu_i32_tl(t0
, cpu_crf
[bi
>> 2]);
1467 tcg_gen_andi_tl(t0
, t0
, mask
);
1469 zr
= tcg_constant_tl(0);
1470 tcg_gen_movcond_tl(TCG_COND_NE
, cpu_gpr
[rD(ctx
->opcode
)], t0
, zr
,
1471 rA(ctx
->opcode
) ? cpu_gpr
[rA(ctx
->opcode
)] : zr
,
1472 cpu_gpr
[rB(ctx
->opcode
)]);
1475 /* cmpb: PowerPC 2.05 specification */
1476 static void gen_cmpb(DisasContext
*ctx
)
1478 gen_helper_cmpb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
1479 cpu_gpr
[rB(ctx
->opcode
)]);
1482 /*** Integer arithmetic ***/
1484 static inline void gen_op_arith_compute_ov(DisasContext
*ctx
, TCGv arg0
,
1485 TCGv arg1
, TCGv arg2
, int sub
)
1487 TCGv t0
= tcg_temp_new();
1489 tcg_gen_xor_tl(cpu_ov
, arg0
, arg2
);
1490 tcg_gen_xor_tl(t0
, arg1
, arg2
);
1492 tcg_gen_and_tl(cpu_ov
, cpu_ov
, t0
);
1494 tcg_gen_andc_tl(cpu_ov
, cpu_ov
, t0
);
1496 if (NARROW_MODE(ctx
)) {
1497 tcg_gen_extract_tl(cpu_ov
, cpu_ov
, 31, 1);
1498 if (is_isa300(ctx
)) {
1499 tcg_gen_mov_tl(cpu_ov32
, cpu_ov
);
1502 if (is_isa300(ctx
)) {
1503 tcg_gen_extract_tl(cpu_ov32
, cpu_ov
, 31, 1);
1505 tcg_gen_extract_tl(cpu_ov
, cpu_ov
, TARGET_LONG_BITS
- 1, 1);
1507 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1510 static inline void gen_op_arith_compute_ca32(DisasContext
*ctx
,
1511 TCGv res
, TCGv arg0
, TCGv arg1
,
1516 if (!is_isa300(ctx
)) {
1520 t0
= tcg_temp_new();
1522 tcg_gen_eqv_tl(t0
, arg0
, arg1
);
1524 tcg_gen_xor_tl(t0
, arg0
, arg1
);
1526 tcg_gen_xor_tl(t0
, t0
, res
);
1527 tcg_gen_extract_tl(ca32
, t0
, 32, 1);
1530 /* Common add function */
1531 static inline void gen_op_arith_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1532 TCGv arg2
, TCGv ca
, TCGv ca32
,
1533 bool add_ca
, bool compute_ca
,
1534 bool compute_ov
, bool compute_rc0
)
1538 if (compute_ca
|| compute_ov
) {
1539 t0
= tcg_temp_new();
1543 if (NARROW_MODE(ctx
)) {
1545 * Caution: a non-obvious corner case of the spec is that
1546 * we must produce the *entire* 64-bit addition, but
1547 * produce the carry into bit 32.
1549 TCGv t1
= tcg_temp_new();
1550 tcg_gen_xor_tl(t1
, arg1
, arg2
); /* add without carry */
1551 tcg_gen_add_tl(t0
, arg1
, arg2
);
1553 tcg_gen_add_tl(t0
, t0
, ca
);
1555 tcg_gen_xor_tl(ca
, t0
, t1
); /* bits changed w/ carry */
1556 tcg_gen_extract_tl(ca
, ca
, 32, 1);
1557 if (is_isa300(ctx
)) {
1558 tcg_gen_mov_tl(ca32
, ca
);
1561 TCGv zero
= tcg_constant_tl(0);
1563 tcg_gen_add2_tl(t0
, ca
, arg1
, zero
, ca
, zero
);
1564 tcg_gen_add2_tl(t0
, ca
, t0
, ca
, arg2
, zero
);
1566 tcg_gen_add2_tl(t0
, ca
, arg1
, zero
, arg2
, zero
);
1568 gen_op_arith_compute_ca32(ctx
, t0
, arg1
, arg2
, ca32
, 0);
1571 tcg_gen_add_tl(t0
, arg1
, arg2
);
1573 tcg_gen_add_tl(t0
, t0
, ca
);
1578 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 0);
1580 if (unlikely(compute_rc0
)) {
1581 gen_set_Rc0(ctx
, t0
);
1585 tcg_gen_mov_tl(ret
, t0
);
1588 /* Add functions with two operands */
1589 #define GEN_INT_ARITH_ADD(name, opc3, ca, add_ca, compute_ca, compute_ov) \
1590 static void glue(gen_, name)(DisasContext *ctx) \
1592 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
1593 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1595 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1597 /* Add functions with one operand and one immediate */
1598 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, ca, \
1599 add_ca, compute_ca, compute_ov) \
1600 static void glue(gen_, name)(DisasContext *ctx) \
1602 TCGv t0 = tcg_constant_tl(const_val); \
1603 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
1604 cpu_gpr[rA(ctx->opcode)], t0, \
1606 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1609 /* add add. addo addo. */
1610 GEN_INT_ARITH_ADD(add
, 0x08, cpu_ca
, 0, 0, 0)
1611 GEN_INT_ARITH_ADD(addo
, 0x18, cpu_ca
, 0, 0, 1)
1612 /* addc addc. addco addco. */
1613 GEN_INT_ARITH_ADD(addc
, 0x00, cpu_ca
, 0, 1, 0)
1614 GEN_INT_ARITH_ADD(addco
, 0x10, cpu_ca
, 0, 1, 1)
1615 /* adde adde. addeo addeo. */
1616 GEN_INT_ARITH_ADD(adde
, 0x04, cpu_ca
, 1, 1, 0)
1617 GEN_INT_ARITH_ADD(addeo
, 0x14, cpu_ca
, 1, 1, 1)
1618 /* addme addme. addmeo addmeo. */
1619 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, cpu_ca
, 1, 1, 0)
1620 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, cpu_ca
, 1, 1, 1)
1622 GEN_INT_ARITH_ADD(addex
, 0x05, cpu_ov
, 1, 1, 0);
1623 /* addze addze. addzeo addzeo.*/
1624 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, cpu_ca
, 1, 1, 0)
1625 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, cpu_ca
, 1, 1, 1)
1627 static inline void gen_op_addic(DisasContext
*ctx
, bool compute_rc0
)
1629 TCGv c
= tcg_constant_tl(SIMM(ctx
->opcode
));
1630 gen_op_arith_add(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1631 c
, cpu_ca
, cpu_ca32
, 0, 1, 0, compute_rc0
);
1634 static void gen_addic(DisasContext
*ctx
)
1636 gen_op_addic(ctx
, 0);
1639 static void gen_addic_(DisasContext
*ctx
)
1641 gen_op_addic(ctx
, 1);
1644 static inline void gen_op_arith_divw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1645 TCGv arg2
, int sign
, int compute_ov
)
1647 TCGv_i32 t0
= tcg_temp_new_i32();
1648 TCGv_i32 t1
= tcg_temp_new_i32();
1649 TCGv_i32 t2
= tcg_temp_new_i32();
1650 TCGv_i32 t3
= tcg_temp_new_i32();
1652 tcg_gen_trunc_tl_i32(t0
, arg1
);
1653 tcg_gen_trunc_tl_i32(t1
, arg2
);
1655 tcg_gen_setcondi_i32(TCG_COND_EQ
, t2
, t0
, INT_MIN
);
1656 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, -1);
1657 tcg_gen_and_i32(t2
, t2
, t3
);
1658 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, 0);
1659 tcg_gen_or_i32(t2
, t2
, t3
);
1660 tcg_gen_movi_i32(t3
, 0);
1661 tcg_gen_movcond_i32(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1662 tcg_gen_div_i32(t3
, t0
, t1
);
1663 tcg_gen_extu_i32_tl(ret
, t3
);
1665 tcg_gen_setcondi_i32(TCG_COND_EQ
, t2
, t1
, 0);
1666 tcg_gen_movi_i32(t3
, 0);
1667 tcg_gen_movcond_i32(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1668 tcg_gen_divu_i32(t3
, t0
, t1
);
1669 tcg_gen_extu_i32_tl(ret
, t3
);
1672 tcg_gen_extu_i32_tl(cpu_ov
, t2
);
1673 if (is_isa300(ctx
)) {
1674 tcg_gen_extu_i32_tl(cpu_ov32
, t2
);
1676 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1679 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1680 gen_set_Rc0(ctx
, ret
);
1684 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
1685 static void glue(gen_, name)(DisasContext *ctx) \
1687 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
1688 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1689 sign, compute_ov); \
1691 /* divwu divwu. divwuo divwuo. */
1692 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0);
1693 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1);
1694 /* divw divw. divwo divwo. */
1695 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0);
1696 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1);
1698 /* div[wd]eu[o][.] */
1699 #define GEN_DIVE(name, hlpr, compute_ov) \
1700 static void gen_##name(DisasContext *ctx) \
1702 TCGv_i32 t0 = tcg_constant_i32(compute_ov); \
1703 gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1704 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \
1705 if (unlikely(Rc(ctx->opcode) != 0)) { \
1706 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1710 GEN_DIVE(divweu
, divweu
, 0);
1711 GEN_DIVE(divweuo
, divweu
, 1);
1712 GEN_DIVE(divwe
, divwe
, 0);
1713 GEN_DIVE(divweo
, divwe
, 1);
1715 #if defined(TARGET_PPC64)
1716 static inline void gen_op_arith_divd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1717 TCGv arg2
, int sign
, int compute_ov
)
1719 TCGv_i64 t0
= tcg_temp_new_i64();
1720 TCGv_i64 t1
= tcg_temp_new_i64();
1721 TCGv_i64 t2
= tcg_temp_new_i64();
1722 TCGv_i64 t3
= tcg_temp_new_i64();
1724 tcg_gen_mov_i64(t0
, arg1
);
1725 tcg_gen_mov_i64(t1
, arg2
);
1727 tcg_gen_setcondi_i64(TCG_COND_EQ
, t2
, t0
, INT64_MIN
);
1728 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, -1);
1729 tcg_gen_and_i64(t2
, t2
, t3
);
1730 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, 0);
1731 tcg_gen_or_i64(t2
, t2
, t3
);
1732 tcg_gen_movi_i64(t3
, 0);
1733 tcg_gen_movcond_i64(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1734 tcg_gen_div_i64(ret
, t0
, t1
);
1736 tcg_gen_setcondi_i64(TCG_COND_EQ
, t2
, t1
, 0);
1737 tcg_gen_movi_i64(t3
, 0);
1738 tcg_gen_movcond_i64(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1739 tcg_gen_divu_i64(ret
, t0
, t1
);
1742 tcg_gen_mov_tl(cpu_ov
, t2
);
1743 if (is_isa300(ctx
)) {
1744 tcg_gen_mov_tl(cpu_ov32
, t2
);
1746 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1749 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1750 gen_set_Rc0(ctx
, ret
);
1754 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1755 static void glue(gen_, name)(DisasContext *ctx) \
1757 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1758 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1759 sign, compute_ov); \
1761 /* divdu divdu. divduo divduo. */
1762 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0);
1763 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1);
1764 /* divd divd. divdo divdo. */
1765 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0);
1766 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1);
1768 GEN_DIVE(divdeu
, divdeu
, 0);
1769 GEN_DIVE(divdeuo
, divdeu
, 1);
1770 GEN_DIVE(divde
, divde
, 0);
1771 GEN_DIVE(divdeo
, divde
, 1);
1774 static inline void gen_op_arith_modw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1775 TCGv arg2
, int sign
)
1777 TCGv_i32 t0
= tcg_temp_new_i32();
1778 TCGv_i32 t1
= tcg_temp_new_i32();
1780 tcg_gen_trunc_tl_i32(t0
, arg1
);
1781 tcg_gen_trunc_tl_i32(t1
, arg2
);
1783 TCGv_i32 t2
= tcg_temp_new_i32();
1784 TCGv_i32 t3
= tcg_temp_new_i32();
1785 tcg_gen_setcondi_i32(TCG_COND_EQ
, t2
, t0
, INT_MIN
);
1786 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, -1);
1787 tcg_gen_and_i32(t2
, t2
, t3
);
1788 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, 0);
1789 tcg_gen_or_i32(t2
, t2
, t3
);
1790 tcg_gen_movi_i32(t3
, 0);
1791 tcg_gen_movcond_i32(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1792 tcg_gen_rem_i32(t3
, t0
, t1
);
1793 tcg_gen_ext_i32_tl(ret
, t3
);
1795 TCGv_i32 t2
= tcg_constant_i32(1);
1796 TCGv_i32 t3
= tcg_constant_i32(0);
1797 tcg_gen_movcond_i32(TCG_COND_EQ
, t1
, t1
, t3
, t2
, t1
);
1798 tcg_gen_remu_i32(t0
, t0
, t1
);
1799 tcg_gen_extu_i32_tl(ret
, t0
);
1803 #define GEN_INT_ARITH_MODW(name, opc3, sign) \
1804 static void glue(gen_, name)(DisasContext *ctx) \
1806 gen_op_arith_modw(ctx, cpu_gpr[rD(ctx->opcode)], \
1807 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1811 GEN_INT_ARITH_MODW(moduw
, 0x08, 0);
1812 GEN_INT_ARITH_MODW(modsw
, 0x18, 1);
1814 #if defined(TARGET_PPC64)
1815 static inline void gen_op_arith_modd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1816 TCGv arg2
, int sign
)
1818 TCGv_i64 t0
= tcg_temp_new_i64();
1819 TCGv_i64 t1
= tcg_temp_new_i64();
1821 tcg_gen_mov_i64(t0
, arg1
);
1822 tcg_gen_mov_i64(t1
, arg2
);
1824 TCGv_i64 t2
= tcg_temp_new_i64();
1825 TCGv_i64 t3
= tcg_temp_new_i64();
1826 tcg_gen_setcondi_i64(TCG_COND_EQ
, t2
, t0
, INT64_MIN
);
1827 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, -1);
1828 tcg_gen_and_i64(t2
, t2
, t3
);
1829 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, 0);
1830 tcg_gen_or_i64(t2
, t2
, t3
);
1831 tcg_gen_movi_i64(t3
, 0);
1832 tcg_gen_movcond_i64(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1833 tcg_gen_rem_i64(ret
, t0
, t1
);
1835 TCGv_i64 t2
= tcg_constant_i64(1);
1836 TCGv_i64 t3
= tcg_constant_i64(0);
1837 tcg_gen_movcond_i64(TCG_COND_EQ
, t1
, t1
, t3
, t2
, t1
);
1838 tcg_gen_remu_i64(ret
, t0
, t1
);
1842 #define GEN_INT_ARITH_MODD(name, opc3, sign) \
1843 static void glue(gen_, name)(DisasContext *ctx) \
1845 gen_op_arith_modd(ctx, cpu_gpr[rD(ctx->opcode)], \
1846 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1850 GEN_INT_ARITH_MODD(modud
, 0x08, 0);
1851 GEN_INT_ARITH_MODD(modsd
, 0x18, 1);
1855 static void gen_mulhw(DisasContext
*ctx
)
1857 TCGv_i32 t0
= tcg_temp_new_i32();
1858 TCGv_i32 t1
= tcg_temp_new_i32();
1860 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1861 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1862 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1863 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1864 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1865 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1869 /* mulhwu mulhwu. */
1870 static void gen_mulhwu(DisasContext
*ctx
)
1872 TCGv_i32 t0
= tcg_temp_new_i32();
1873 TCGv_i32 t1
= tcg_temp_new_i32();
1875 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1876 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1877 tcg_gen_mulu2_i32(t0
, t1
, t0
, t1
);
1878 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1879 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1880 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1885 static void gen_mullw(DisasContext
*ctx
)
1887 #if defined(TARGET_PPC64)
1889 t0
= tcg_temp_new_i64();
1890 t1
= tcg_temp_new_i64();
1891 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1892 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1893 tcg_gen_mul_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
1895 tcg_gen_mul_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1896 cpu_gpr
[rB(ctx
->opcode
)]);
1898 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1899 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1903 /* mullwo mullwo. */
1904 static void gen_mullwo(DisasContext
*ctx
)
1906 TCGv_i32 t0
= tcg_temp_new_i32();
1907 TCGv_i32 t1
= tcg_temp_new_i32();
1909 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1910 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1911 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1912 #if defined(TARGET_PPC64)
1913 tcg_gen_concat_i32_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
1915 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1918 tcg_gen_sari_i32(t0
, t0
, 31);
1919 tcg_gen_setcond_i32(TCG_COND_NE
, t0
, t0
, t1
);
1920 tcg_gen_extu_i32_tl(cpu_ov
, t0
);
1921 if (is_isa300(ctx
)) {
1922 tcg_gen_mov_tl(cpu_ov32
, cpu_ov
);
1924 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1926 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1927 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1932 static void gen_mulli(DisasContext
*ctx
)
1934 tcg_gen_muli_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1938 #if defined(TARGET_PPC64)
1940 static void gen_mulhd(DisasContext
*ctx
)
1942 TCGv lo
= tcg_temp_new();
1943 tcg_gen_muls2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1944 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1945 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1946 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1950 /* mulhdu mulhdu. */
1951 static void gen_mulhdu(DisasContext
*ctx
)
1953 TCGv lo
= tcg_temp_new();
1954 tcg_gen_mulu2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
1955 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
1956 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1957 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1962 static void gen_mulld(DisasContext
*ctx
)
1964 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1965 cpu_gpr
[rB(ctx
->opcode
)]);
1966 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1967 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1971 /* mulldo mulldo. */
1972 static void gen_mulldo(DisasContext
*ctx
)
1974 TCGv_i64 t0
= tcg_temp_new_i64();
1975 TCGv_i64 t1
= tcg_temp_new_i64();
1977 tcg_gen_muls2_i64(t0
, t1
, cpu_gpr
[rA(ctx
->opcode
)],
1978 cpu_gpr
[rB(ctx
->opcode
)]);
1979 tcg_gen_mov_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
);
1981 tcg_gen_sari_i64(t0
, t0
, 63);
1982 tcg_gen_setcond_i64(TCG_COND_NE
, cpu_ov
, t0
, t1
);
1983 if (is_isa300(ctx
)) {
1984 tcg_gen_mov_tl(cpu_ov32
, cpu_ov
);
1986 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1988 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1989 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1994 /* Common subf function */
1995 static inline void gen_op_arith_subf(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1996 TCGv arg2
, bool add_ca
, bool compute_ca
,
1997 bool compute_ov
, bool compute_rc0
)
2001 if (compute_ca
|| compute_ov
) {
2002 t0
= tcg_temp_new();
2006 /* dest = ~arg1 + arg2 [+ ca]. */
2007 if (NARROW_MODE(ctx
)) {
2009 * Caution: a non-obvious corner case of the spec is that
2010 * we must produce the *entire* 64-bit addition, but
2011 * produce the carry into bit 32.
2013 TCGv inv1
= tcg_temp_new();
2014 TCGv t1
= tcg_temp_new();
2015 tcg_gen_not_tl(inv1
, arg1
);
2017 tcg_gen_add_tl(t0
, arg2
, cpu_ca
);
2019 tcg_gen_addi_tl(t0
, arg2
, 1);
2021 tcg_gen_xor_tl(t1
, arg2
, inv1
); /* add without carry */
2022 tcg_gen_add_tl(t0
, t0
, inv1
);
2023 tcg_gen_xor_tl(cpu_ca
, t0
, t1
); /* bits changes w/ carry */
2024 tcg_gen_extract_tl(cpu_ca
, cpu_ca
, 32, 1);
2025 if (is_isa300(ctx
)) {
2026 tcg_gen_mov_tl(cpu_ca32
, cpu_ca
);
2028 } else if (add_ca
) {
2029 TCGv zero
, inv1
= tcg_temp_new();
2030 tcg_gen_not_tl(inv1
, arg1
);
2031 zero
= tcg_constant_tl(0);
2032 tcg_gen_add2_tl(t0
, cpu_ca
, arg2
, zero
, cpu_ca
, zero
);
2033 tcg_gen_add2_tl(t0
, cpu_ca
, t0
, cpu_ca
, inv1
, zero
);
2034 gen_op_arith_compute_ca32(ctx
, t0
, inv1
, arg2
, cpu_ca32
, 0);
2036 tcg_gen_setcond_tl(TCG_COND_GEU
, cpu_ca
, arg2
, arg1
);
2037 tcg_gen_sub_tl(t0
, arg2
, arg1
);
2038 gen_op_arith_compute_ca32(ctx
, t0
, arg1
, arg2
, cpu_ca32
, 1);
2040 } else if (add_ca
) {
2042 * Since we're ignoring carry-out, we can simplify the
2043 * standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1.
2045 tcg_gen_sub_tl(t0
, arg2
, arg1
);
2046 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
2047 tcg_gen_subi_tl(t0
, t0
, 1);
2049 tcg_gen_sub_tl(t0
, arg2
, arg1
);
2053 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 1);
2055 if (unlikely(compute_rc0
)) {
2056 gen_set_Rc0(ctx
, t0
);
2060 tcg_gen_mov_tl(ret
, t0
);
2063 /* Sub functions with Two operands functions */
2064 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
2065 static void glue(gen_, name)(DisasContext *ctx) \
2067 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
2068 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
2069 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
2071 /* Sub functions with one operand and one immediate */
2072 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
2073 add_ca, compute_ca, compute_ov) \
2074 static void glue(gen_, name)(DisasContext *ctx) \
2076 TCGv t0 = tcg_constant_tl(const_val); \
2077 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
2078 cpu_gpr[rA(ctx->opcode)], t0, \
2079 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
2081 /* subf subf. subfo subfo. */
2082 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
2083 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
2084 /* subfc subfc. subfco subfco. */
2085 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
2086 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
2087 /* subfe subfe. subfeo subfo. */
2088 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
2089 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
2090 /* subfme subfme. subfmeo subfmeo. */
2091 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
2092 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
2093 /* subfze subfze. subfzeo subfzeo.*/
2094 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
2095 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
2098 static void gen_subfic(DisasContext
*ctx
)
2100 TCGv c
= tcg_constant_tl(SIMM(ctx
->opcode
));
2101 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
2105 /* neg neg. nego nego. */
2106 static inline void gen_op_arith_neg(DisasContext
*ctx
, bool compute_ov
)
2108 TCGv zero
= tcg_constant_tl(0);
2109 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
2110 zero
, 0, 0, compute_ov
, Rc(ctx
->opcode
));
2113 static void gen_neg(DisasContext
*ctx
)
2115 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
2116 if (unlikely(Rc(ctx
->opcode
))) {
2117 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
2121 static void gen_nego(DisasContext
*ctx
)
2123 gen_op_arith_neg(ctx
, 1);
2126 /*** Integer logical ***/
2127 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
2128 static void glue(gen_, name)(DisasContext *ctx) \
2130 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
2131 cpu_gpr[rB(ctx->opcode)]); \
2132 if (unlikely(Rc(ctx->opcode) != 0)) \
2133 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
2136 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
2137 static void glue(gen_, name)(DisasContext *ctx) \
2139 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
2140 if (unlikely(Rc(ctx->opcode) != 0)) \
2141 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
2145 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
);
2147 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
);
2150 static void gen_andi_(DisasContext
*ctx
)
2152 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
2154 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2158 static void gen_andis_(DisasContext
*ctx
)
2160 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
2161 UIMM(ctx
->opcode
) << 16);
2162 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2166 static void gen_cntlzw(DisasContext
*ctx
)
2168 TCGv_i32 t
= tcg_temp_new_i32();
2170 tcg_gen_trunc_tl_i32(t
, cpu_gpr
[rS(ctx
->opcode
)]);
2171 tcg_gen_clzi_i32(t
, t
, 32);
2172 tcg_gen_extu_i32_tl(cpu_gpr
[rA(ctx
->opcode
)], t
);
2174 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2175 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2180 static void gen_cnttzw(DisasContext
*ctx
)
2182 TCGv_i32 t
= tcg_temp_new_i32();
2184 tcg_gen_trunc_tl_i32(t
, cpu_gpr
[rS(ctx
->opcode
)]);
2185 tcg_gen_ctzi_i32(t
, t
, 32);
2186 tcg_gen_extu_i32_tl(cpu_gpr
[rA(ctx
->opcode
)], t
);
2188 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2189 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2194 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
);
2195 /* extsb & extsb. */
2196 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
);
2197 /* extsh & extsh. */
2198 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
);
2200 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
);
2202 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
);
2204 #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY)
2205 static void gen_pause(DisasContext
*ctx
)
2207 TCGv_i32 t0
= tcg_constant_i32(0);
2208 tcg_gen_st_i32(t0
, cpu_env
,
2209 -offsetof(PowerPCCPU
, env
) + offsetof(CPUState
, halted
));
2211 /* Stop translation, this gives other CPUs a chance to run */
2212 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
2214 #endif /* defined(TARGET_PPC64) */
2217 static void gen_or(DisasContext
*ctx
)
2221 rs
= rS(ctx
->opcode
);
2222 ra
= rA(ctx
->opcode
);
2223 rb
= rB(ctx
->opcode
);
2224 /* Optimisation for mr. ri case */
2225 if (rs
!= ra
|| rs
!= rb
) {
2227 tcg_gen_or_tl(cpu_gpr
[ra
], cpu_gpr
[rs
], cpu_gpr
[rb
]);
2229 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rs
]);
2231 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2232 gen_set_Rc0(ctx
, cpu_gpr
[ra
]);
2234 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
2235 gen_set_Rc0(ctx
, cpu_gpr
[rs
]);
2236 #if defined(TARGET_PPC64)
2237 } else if (rs
!= 0) { /* 0 is nop */
2242 /* Set process priority to low */
2246 /* Set process priority to medium-low */
2250 /* Set process priority to normal */
2253 #if !defined(CONFIG_USER_ONLY)
2256 /* Set process priority to very low */
2262 /* Set process priority to medium-hight */
2268 /* Set process priority to high */
2273 if (ctx
->hv
&& !ctx
->pr
) {
2274 /* Set process priority to very high */
2283 TCGv t0
= tcg_temp_new();
2284 gen_load_spr(t0
, SPR_PPR
);
2285 tcg_gen_andi_tl(t0
, t0
, ~0x001C000000000000ULL
);
2286 tcg_gen_ori_tl(t0
, t0
, ((uint64_t)prio
) << 50);
2287 gen_store_spr(SPR_PPR
, t0
);
2289 #if !defined(CONFIG_USER_ONLY)
2291 * Pause out of TCG otherwise spin loops with smt_low eat too
2292 * much CPU and the kernel hangs. This applies to all
2293 * encodings other than no-op, e.g., miso(rs=26), yield(27),
2294 * mdoio(29), mdoom(30), and all currently undefined.
2302 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
);
2305 static void gen_xor(DisasContext
*ctx
)
2307 /* Optimisation for "set to zero" case */
2308 if (rS(ctx
->opcode
) != rB(ctx
->opcode
)) {
2309 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
2310 cpu_gpr
[rB(ctx
->opcode
)]);
2312 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
2314 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2315 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2320 static void gen_ori(DisasContext
*ctx
)
2322 target_ulong uimm
= UIMM(ctx
->opcode
);
2324 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
2327 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
2331 static void gen_oris(DisasContext
*ctx
)
2333 target_ulong uimm
= UIMM(ctx
->opcode
);
2335 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
2339 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
2344 static void gen_xori(DisasContext
*ctx
)
2346 target_ulong uimm
= UIMM(ctx
->opcode
);
2348 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
2352 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
2356 static void gen_xoris(DisasContext
*ctx
)
2358 target_ulong uimm
= UIMM(ctx
->opcode
);
2360 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
2364 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
2368 /* popcntb : PowerPC 2.03 specification */
2369 static void gen_popcntb(DisasContext
*ctx
)
2371 gen_helper_popcntb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
2374 static void gen_popcntw(DisasContext
*ctx
)
2376 #if defined(TARGET_PPC64)
2377 gen_helper_popcntw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
2379 tcg_gen_ctpop_i32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
2383 #if defined(TARGET_PPC64)
2384 /* popcntd: PowerPC 2.06 specification */
2385 static void gen_popcntd(DisasContext
*ctx
)
2387 tcg_gen_ctpop_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
2391 /* prtyw: PowerPC 2.05 specification */
2392 static void gen_prtyw(DisasContext
*ctx
)
2394 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
2395 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
2396 TCGv t0
= tcg_temp_new();
2397 tcg_gen_shri_tl(t0
, rs
, 16);
2398 tcg_gen_xor_tl(ra
, rs
, t0
);
2399 tcg_gen_shri_tl(t0
, ra
, 8);
2400 tcg_gen_xor_tl(ra
, ra
, t0
);
2401 tcg_gen_andi_tl(ra
, ra
, (target_ulong
)0x100000001ULL
);
2404 #if defined(TARGET_PPC64)
2405 /* prtyd: PowerPC 2.05 specification */
2406 static void gen_prtyd(DisasContext
*ctx
)
2408 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
2409 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
2410 TCGv t0
= tcg_temp_new();
2411 tcg_gen_shri_tl(t0
, rs
, 32);
2412 tcg_gen_xor_tl(ra
, rs
, t0
);
2413 tcg_gen_shri_tl(t0
, ra
, 16);
2414 tcg_gen_xor_tl(ra
, ra
, t0
);
2415 tcg_gen_shri_tl(t0
, ra
, 8);
2416 tcg_gen_xor_tl(ra
, ra
, t0
);
2417 tcg_gen_andi_tl(ra
, ra
, 1);
2421 #if defined(TARGET_PPC64)
2423 static void gen_bpermd(DisasContext
*ctx
)
2425 gen_helper_bpermd(cpu_gpr
[rA(ctx
->opcode
)],
2426 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2430 #if defined(TARGET_PPC64)
2431 /* extsw & extsw. */
2432 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
);
2435 static void gen_cntlzd(DisasContext
*ctx
)
2437 tcg_gen_clzi_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], 64);
2438 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2439 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2444 static void gen_cnttzd(DisasContext
*ctx
)
2446 tcg_gen_ctzi_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], 64);
2447 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2448 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2453 static void gen_darn(DisasContext
*ctx
)
2455 int l
= L(ctx
->opcode
);
2458 tcg_gen_movi_i64(cpu_gpr
[rD(ctx
->opcode
)], -1);
2460 translator_io_start(&ctx
->base
);
2462 gen_helper_darn32(cpu_gpr
[rD(ctx
->opcode
)]);
2464 /* Return 64-bit random for both CRN and RRN */
2465 gen_helper_darn64(cpu_gpr
[rD(ctx
->opcode
)]);
2471 /*** Integer rotate ***/
2473 /* rlwimi & rlwimi. */
2474 static void gen_rlwimi(DisasContext
*ctx
)
2476 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2477 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2478 uint32_t sh
= SH(ctx
->opcode
);
2479 uint32_t mb
= MB(ctx
->opcode
);
2480 uint32_t me
= ME(ctx
->opcode
);
2482 if (sh
== (31 - me
) && mb
<= me
) {
2483 tcg_gen_deposit_tl(t_ra
, t_ra
, t_rs
, sh
, me
- mb
+ 1);
2486 bool mask_in_32b
= true;
2489 #if defined(TARGET_PPC64)
2493 mask
= MASK(mb
, me
);
2495 #if defined(TARGET_PPC64)
2496 if (mask
> 0xffffffffu
) {
2497 mask_in_32b
= false;
2500 t1
= tcg_temp_new();
2502 TCGv_i32 t0
= tcg_temp_new_i32();
2503 tcg_gen_trunc_tl_i32(t0
, t_rs
);
2504 tcg_gen_rotli_i32(t0
, t0
, sh
);
2505 tcg_gen_extu_i32_tl(t1
, t0
);
2507 #if defined(TARGET_PPC64)
2508 tcg_gen_deposit_i64(t1
, t_rs
, t_rs
, 32, 32);
2509 tcg_gen_rotli_i64(t1
, t1
, sh
);
2511 g_assert_not_reached();
2515 tcg_gen_andi_tl(t1
, t1
, mask
);
2516 tcg_gen_andi_tl(t_ra
, t_ra
, ~mask
);
2517 tcg_gen_or_tl(t_ra
, t_ra
, t1
);
2519 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2520 gen_set_Rc0(ctx
, t_ra
);
2524 /* rlwinm & rlwinm. */
2525 static void gen_rlwinm(DisasContext
*ctx
)
2527 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2528 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2529 int sh
= SH(ctx
->opcode
);
2530 int mb
= MB(ctx
->opcode
);
2531 int me
= ME(ctx
->opcode
);
2532 int len
= me
- mb
+ 1;
2533 int rsh
= (32 - sh
) & 31;
2535 if (sh
!= 0 && len
> 0 && me
== (31 - sh
)) {
2536 tcg_gen_deposit_z_tl(t_ra
, t_rs
, sh
, len
);
2537 } else if (me
== 31 && rsh
+ len
<= 32) {
2538 tcg_gen_extract_tl(t_ra
, t_rs
, rsh
, len
);
2541 bool mask_in_32b
= true;
2542 #if defined(TARGET_PPC64)
2546 mask
= MASK(mb
, me
);
2547 #if defined(TARGET_PPC64)
2548 if (mask
> 0xffffffffu
) {
2549 mask_in_32b
= false;
2554 tcg_gen_andi_tl(t_ra
, t_rs
, mask
);
2556 TCGv_i32 t0
= tcg_temp_new_i32();
2557 tcg_gen_trunc_tl_i32(t0
, t_rs
);
2558 tcg_gen_rotli_i32(t0
, t0
, sh
);
2559 tcg_gen_andi_i32(t0
, t0
, mask
);
2560 tcg_gen_extu_i32_tl(t_ra
, t0
);
2563 #if defined(TARGET_PPC64)
2564 tcg_gen_deposit_i64(t_ra
, t_rs
, t_rs
, 32, 32);
2565 tcg_gen_rotli_i64(t_ra
, t_ra
, sh
);
2566 tcg_gen_andi_i64(t_ra
, t_ra
, mask
);
2568 g_assert_not_reached();
2572 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2573 gen_set_Rc0(ctx
, t_ra
);
2577 /* rlwnm & rlwnm. */
2578 static void gen_rlwnm(DisasContext
*ctx
)
2580 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2581 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2582 TCGv t_rb
= cpu_gpr
[rB(ctx
->opcode
)];
2583 uint32_t mb
= MB(ctx
->opcode
);
2584 uint32_t me
= ME(ctx
->opcode
);
2586 bool mask_in_32b
= true;
2588 #if defined(TARGET_PPC64)
2592 mask
= MASK(mb
, me
);
2594 #if defined(TARGET_PPC64)
2595 if (mask
> 0xffffffffu
) {
2596 mask_in_32b
= false;
2600 TCGv_i32 t0
= tcg_temp_new_i32();
2601 TCGv_i32 t1
= tcg_temp_new_i32();
2602 tcg_gen_trunc_tl_i32(t0
, t_rb
);
2603 tcg_gen_trunc_tl_i32(t1
, t_rs
);
2604 tcg_gen_andi_i32(t0
, t0
, 0x1f);
2605 tcg_gen_rotl_i32(t1
, t1
, t0
);
2606 tcg_gen_extu_i32_tl(t_ra
, t1
);
2608 #if defined(TARGET_PPC64)
2609 TCGv_i64 t0
= tcg_temp_new_i64();
2610 tcg_gen_andi_i64(t0
, t_rb
, 0x1f);
2611 tcg_gen_deposit_i64(t_ra
, t_rs
, t_rs
, 32, 32);
2612 tcg_gen_rotl_i64(t_ra
, t_ra
, t0
);
2614 g_assert_not_reached();
2618 tcg_gen_andi_tl(t_ra
, t_ra
, mask
);
2620 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2621 gen_set_Rc0(ctx
, t_ra
);
2625 #if defined(TARGET_PPC64)
2626 #define GEN_PPC64_R2(name, opc1, opc2) \
2627 static void glue(gen_, name##0)(DisasContext *ctx) \
2629 gen_##name(ctx, 0); \
2632 static void glue(gen_, name##1)(DisasContext *ctx) \
2634 gen_##name(ctx, 1); \
2636 #define GEN_PPC64_R4(name, opc1, opc2) \
2637 static void glue(gen_, name##0)(DisasContext *ctx) \
2639 gen_##name(ctx, 0, 0); \
2642 static void glue(gen_, name##1)(DisasContext *ctx) \
2644 gen_##name(ctx, 0, 1); \
2647 static void glue(gen_, name##2)(DisasContext *ctx) \
2649 gen_##name(ctx, 1, 0); \
2652 static void glue(gen_, name##3)(DisasContext *ctx) \
2654 gen_##name(ctx, 1, 1); \
2657 static void gen_rldinm(DisasContext
*ctx
, int mb
, int me
, int sh
)
2659 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2660 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2661 int len
= me
- mb
+ 1;
2662 int rsh
= (64 - sh
) & 63;
2664 if (sh
!= 0 && len
> 0 && me
== (63 - sh
)) {
2665 tcg_gen_deposit_z_tl(t_ra
, t_rs
, sh
, len
);
2666 } else if (me
== 63 && rsh
+ len
<= 64) {
2667 tcg_gen_extract_tl(t_ra
, t_rs
, rsh
, len
);
2669 tcg_gen_rotli_tl(t_ra
, t_rs
, sh
);
2670 tcg_gen_andi_tl(t_ra
, t_ra
, MASK(mb
, me
));
2672 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2673 gen_set_Rc0(ctx
, t_ra
);
2677 /* rldicl - rldicl. */
2678 static inline void gen_rldicl(DisasContext
*ctx
, int mbn
, int shn
)
2682 sh
= SH(ctx
->opcode
) | (shn
<< 5);
2683 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2684 gen_rldinm(ctx
, mb
, 63, sh
);
2686 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
2688 /* rldicr - rldicr. */
2689 static inline void gen_rldicr(DisasContext
*ctx
, int men
, int shn
)
2693 sh
= SH(ctx
->opcode
) | (shn
<< 5);
2694 me
= MB(ctx
->opcode
) | (men
<< 5);
2695 gen_rldinm(ctx
, 0, me
, sh
);
2697 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
2699 /* rldic - rldic. */
2700 static inline void gen_rldic(DisasContext
*ctx
, int mbn
, int shn
)
2704 sh
= SH(ctx
->opcode
) | (shn
<< 5);
2705 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2706 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
2708 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
2710 static void gen_rldnm(DisasContext
*ctx
, int mb
, int me
)
2712 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2713 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2714 TCGv t_rb
= cpu_gpr
[rB(ctx
->opcode
)];
2717 t0
= tcg_temp_new();
2718 tcg_gen_andi_tl(t0
, t_rb
, 0x3f);
2719 tcg_gen_rotl_tl(t_ra
, t_rs
, t0
);
2721 tcg_gen_andi_tl(t_ra
, t_ra
, MASK(mb
, me
));
2722 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2723 gen_set_Rc0(ctx
, t_ra
);
2727 /* rldcl - rldcl. */
2728 static inline void gen_rldcl(DisasContext
*ctx
, int mbn
)
2732 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2733 gen_rldnm(ctx
, mb
, 63);
2735 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
2737 /* rldcr - rldcr. */
2738 static inline void gen_rldcr(DisasContext
*ctx
, int men
)
2742 me
= MB(ctx
->opcode
) | (men
<< 5);
2743 gen_rldnm(ctx
, 0, me
);
2745 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
2747 /* rldimi - rldimi. */
2748 static void gen_rldimi(DisasContext
*ctx
, int mbn
, int shn
)
2750 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2751 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2752 uint32_t sh
= SH(ctx
->opcode
) | (shn
<< 5);
2753 uint32_t mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2754 uint32_t me
= 63 - sh
;
2757 tcg_gen_deposit_tl(t_ra
, t_ra
, t_rs
, sh
, me
- mb
+ 1);
2759 target_ulong mask
= MASK(mb
, me
);
2760 TCGv t1
= tcg_temp_new();
2762 tcg_gen_rotli_tl(t1
, t_rs
, sh
);
2763 tcg_gen_andi_tl(t1
, t1
, mask
);
2764 tcg_gen_andi_tl(t_ra
, t_ra
, ~mask
);
2765 tcg_gen_or_tl(t_ra
, t_ra
, t1
);
2767 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2768 gen_set_Rc0(ctx
, t_ra
);
2771 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
2774 /*** Integer shift ***/
2777 static void gen_slw(DisasContext
*ctx
)
2781 t0
= tcg_temp_new();
2782 /* AND rS with a mask that is 0 when rB >= 0x20 */
2783 #if defined(TARGET_PPC64)
2784 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
2785 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2787 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
2788 tcg_gen_sari_tl(t0
, t0
, 0x1f);
2790 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2791 t1
= tcg_temp_new();
2792 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
2793 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2794 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
2795 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2796 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2801 static void gen_sraw(DisasContext
*ctx
)
2803 gen_helper_sraw(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
2804 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2805 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2806 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2810 /* srawi & srawi. */
2811 static void gen_srawi(DisasContext
*ctx
)
2813 int sh
= SH(ctx
->opcode
);
2814 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
2815 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
2817 tcg_gen_ext32s_tl(dst
, src
);
2818 tcg_gen_movi_tl(cpu_ca
, 0);
2819 if (is_isa300(ctx
)) {
2820 tcg_gen_movi_tl(cpu_ca32
, 0);
2824 tcg_gen_ext32s_tl(dst
, src
);
2825 tcg_gen_andi_tl(cpu_ca
, dst
, (1ULL << sh
) - 1);
2826 t0
= tcg_temp_new();
2827 tcg_gen_sari_tl(t0
, dst
, TARGET_LONG_BITS
- 1);
2828 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
2829 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
2830 if (is_isa300(ctx
)) {
2831 tcg_gen_mov_tl(cpu_ca32
, cpu_ca
);
2833 tcg_gen_sari_tl(dst
, dst
, sh
);
2835 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2836 gen_set_Rc0(ctx
, dst
);
2841 static void gen_srw(DisasContext
*ctx
)
2845 t0
= tcg_temp_new();
2846 /* AND rS with a mask that is 0 when rB >= 0x20 */
2847 #if defined(TARGET_PPC64)
2848 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
2849 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2851 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
2852 tcg_gen_sari_tl(t0
, t0
, 0x1f);
2854 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2855 tcg_gen_ext32u_tl(t0
, t0
);
2856 t1
= tcg_temp_new();
2857 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
2858 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2859 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2860 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2864 #if defined(TARGET_PPC64)
2866 static void gen_sld(DisasContext
*ctx
)
2870 t0
= tcg_temp_new();
2871 /* AND rS with a mask that is 0 when rB >= 0x40 */
2872 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
2873 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2874 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2875 t1
= tcg_temp_new();
2876 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
2877 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2878 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2879 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2884 static void gen_srad(DisasContext
*ctx
)
2886 gen_helper_srad(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
2887 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2888 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2889 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2892 /* sradi & sradi. */
2893 static inline void gen_sradi(DisasContext
*ctx
, int n
)
2895 int sh
= SH(ctx
->opcode
) + (n
<< 5);
2896 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
2897 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
2899 tcg_gen_mov_tl(dst
, src
);
2900 tcg_gen_movi_tl(cpu_ca
, 0);
2901 if (is_isa300(ctx
)) {
2902 tcg_gen_movi_tl(cpu_ca32
, 0);
2906 tcg_gen_andi_tl(cpu_ca
, src
, (1ULL << sh
) - 1);
2907 t0
= tcg_temp_new();
2908 tcg_gen_sari_tl(t0
, src
, TARGET_LONG_BITS
- 1);
2909 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
2910 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
2911 if (is_isa300(ctx
)) {
2912 tcg_gen_mov_tl(cpu_ca32
, cpu_ca
);
2914 tcg_gen_sari_tl(dst
, src
, sh
);
2916 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2917 gen_set_Rc0(ctx
, dst
);
2921 static void gen_sradi0(DisasContext
*ctx
)
2926 static void gen_sradi1(DisasContext
*ctx
)
2931 /* extswsli & extswsli. */
2932 static inline void gen_extswsli(DisasContext
*ctx
, int n
)
2934 int sh
= SH(ctx
->opcode
) + (n
<< 5);
2935 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
2936 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
2938 tcg_gen_ext32s_tl(dst
, src
);
2939 tcg_gen_shli_tl(dst
, dst
, sh
);
2940 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2941 gen_set_Rc0(ctx
, dst
);
2945 static void gen_extswsli0(DisasContext
*ctx
)
2947 gen_extswsli(ctx
, 0);
2950 static void gen_extswsli1(DisasContext
*ctx
)
2952 gen_extswsli(ctx
, 1);
2956 static void gen_srd(DisasContext
*ctx
)
2960 t0
= tcg_temp_new();
2961 /* AND rS with a mask that is 0 when rB >= 0x40 */
2962 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
2963 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2964 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2965 t1
= tcg_temp_new();
2966 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
2967 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2968 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2969 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2974 /*** Addressing modes ***/
2975 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
2976 static inline void gen_addr_imm_index(DisasContext
*ctx
, TCGv EA
,
2979 target_long simm
= SIMM(ctx
->opcode
);
2982 if (rA(ctx
->opcode
) == 0) {
2983 if (NARROW_MODE(ctx
)) {
2984 simm
= (uint32_t)simm
;
2986 tcg_gen_movi_tl(EA
, simm
);
2987 } else if (likely(simm
!= 0)) {
2988 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
);
2989 if (NARROW_MODE(ctx
)) {
2990 tcg_gen_ext32u_tl(EA
, EA
);
2993 if (NARROW_MODE(ctx
)) {
2994 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
2996 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
3001 static inline void gen_addr_reg_index(DisasContext
*ctx
, TCGv EA
)
3003 if (rA(ctx
->opcode
) == 0) {
3004 if (NARROW_MODE(ctx
)) {
3005 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
3007 tcg_gen_mov_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
3010 tcg_gen_add_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
3011 if (NARROW_MODE(ctx
)) {
3012 tcg_gen_ext32u_tl(EA
, EA
);
3017 static inline void gen_addr_register(DisasContext
*ctx
, TCGv EA
)
3019 if (rA(ctx
->opcode
) == 0) {
3020 tcg_gen_movi_tl(EA
, 0);
3021 } else if (NARROW_MODE(ctx
)) {
3022 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
3024 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
3028 static inline void gen_addr_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
3031 tcg_gen_addi_tl(ret
, arg1
, val
);
3032 if (NARROW_MODE(ctx
)) {
3033 tcg_gen_ext32u_tl(ret
, ret
);
3037 static inline void gen_align_no_le(DisasContext
*ctx
)
3039 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
,
3040 (ctx
->opcode
& 0x03FF0000) | POWERPC_EXCP_ALIGN_LE
);
3043 static TCGv
do_ea_calc(DisasContext
*ctx
, int ra
, TCGv displ
)
3045 TCGv ea
= tcg_temp_new();
3047 tcg_gen_add_tl(ea
, cpu_gpr
[ra
], displ
);
3049 tcg_gen_mov_tl(ea
, displ
);
3051 if (NARROW_MODE(ctx
)) {
3052 tcg_gen_ext32u_tl(ea
, ea
);
3057 /*** Integer load ***/
3058 #define DEF_MEMOP(op) ((op) | ctx->default_tcg_memop_mask)
3059 #define BSWAP_MEMOP(op) ((op) | (ctx->default_tcg_memop_mask ^ MO_BSWAP))
3061 #define GEN_QEMU_LOAD_TL(ldop, op) \
3062 static void glue(gen_qemu_, ldop)(DisasContext *ctx, \
3066 tcg_gen_qemu_ld_tl(val, addr, ctx->mem_idx, op); \
3069 GEN_QEMU_LOAD_TL(ld8u
, DEF_MEMOP(MO_UB
))
3070 GEN_QEMU_LOAD_TL(ld16u
, DEF_MEMOP(MO_UW
))
3071 GEN_QEMU_LOAD_TL(ld16s
, DEF_MEMOP(MO_SW
))
3072 GEN_QEMU_LOAD_TL(ld32u
, DEF_MEMOP(MO_UL
))
3073 GEN_QEMU_LOAD_TL(ld32s
, DEF_MEMOP(MO_SL
))
3075 GEN_QEMU_LOAD_TL(ld16ur
, BSWAP_MEMOP(MO_UW
))
3076 GEN_QEMU_LOAD_TL(ld32ur
, BSWAP_MEMOP(MO_UL
))
3078 #define GEN_QEMU_LOAD_64(ldop, op) \
3079 static void glue(gen_qemu_, glue(ldop, _i64))(DisasContext *ctx, \
3083 tcg_gen_qemu_ld_i64(val, addr, ctx->mem_idx, op); \
3086 GEN_QEMU_LOAD_64(ld8u
, DEF_MEMOP(MO_UB
))
3087 GEN_QEMU_LOAD_64(ld16u
, DEF_MEMOP(MO_UW
))
3088 GEN_QEMU_LOAD_64(ld32u
, DEF_MEMOP(MO_UL
))
3089 GEN_QEMU_LOAD_64(ld32s
, DEF_MEMOP(MO_SL
))
3090 GEN_QEMU_LOAD_64(ld64
, DEF_MEMOP(MO_UQ
))
3092 #if defined(TARGET_PPC64)
3093 GEN_QEMU_LOAD_64(ld64ur
, BSWAP_MEMOP(MO_UQ
))
3096 #define GEN_QEMU_STORE_TL(stop, op) \
3097 static void glue(gen_qemu_, stop)(DisasContext *ctx, \
3101 tcg_gen_qemu_st_tl(val, addr, ctx->mem_idx, op); \
3104 #if defined(TARGET_PPC64) || !defined(CONFIG_USER_ONLY)
3105 GEN_QEMU_STORE_TL(st8
, DEF_MEMOP(MO_UB
))
3107 GEN_QEMU_STORE_TL(st16
, DEF_MEMOP(MO_UW
))
3108 GEN_QEMU_STORE_TL(st32
, DEF_MEMOP(MO_UL
))
3110 GEN_QEMU_STORE_TL(st16r
, BSWAP_MEMOP(MO_UW
))
3111 GEN_QEMU_STORE_TL(st32r
, BSWAP_MEMOP(MO_UL
))
3113 #define GEN_QEMU_STORE_64(stop, op) \
3114 static void glue(gen_qemu_, glue(stop, _i64))(DisasContext *ctx, \
3118 tcg_gen_qemu_st_i64(val, addr, ctx->mem_idx, op); \
3121 GEN_QEMU_STORE_64(st8
, DEF_MEMOP(MO_UB
))
3122 GEN_QEMU_STORE_64(st16
, DEF_MEMOP(MO_UW
))
3123 GEN_QEMU_STORE_64(st32
, DEF_MEMOP(MO_UL
))
3124 GEN_QEMU_STORE_64(st64
, DEF_MEMOP(MO_UQ
))
3126 #if defined(TARGET_PPC64)
3127 GEN_QEMU_STORE_64(st64r
, BSWAP_MEMOP(MO_UQ
))
3130 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2, chk) \
3131 static void glue(gen_, name##x)(DisasContext *ctx) \
3135 gen_set_access_type(ctx, ACCESS_INT); \
3136 EA = tcg_temp_new(); \
3137 gen_addr_reg_index(ctx, EA); \
3138 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
3141 #define GEN_LDX(name, ldop, opc2, opc3, type) \
3142 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE, CHK_NONE)
3144 #define GEN_LDX_HVRM(name, ldop, opc2, opc3, type) \
3145 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE, CHK_HVRM)
3147 #define GEN_LDEPX(name, ldop, opc2, opc3) \
3148 static void glue(gen_, name##epx)(DisasContext *ctx) \
3152 gen_set_access_type(ctx, ACCESS_INT); \
3153 EA = tcg_temp_new(); \
3154 gen_addr_reg_index(ctx, EA); \
3155 tcg_gen_qemu_ld_tl(cpu_gpr[rD(ctx->opcode)], EA, PPC_TLB_EPID_LOAD, ldop);\
3158 GEN_LDEPX(lb
, DEF_MEMOP(MO_UB
), 0x1F, 0x02)
3159 GEN_LDEPX(lh
, DEF_MEMOP(MO_UW
), 0x1F, 0x08)
3160 GEN_LDEPX(lw
, DEF_MEMOP(MO_UL
), 0x1F, 0x00)
3161 #if defined(TARGET_PPC64)
3162 GEN_LDEPX(ld
, DEF_MEMOP(MO_UQ
), 0x1D, 0x00)
3165 #if defined(TARGET_PPC64)
3166 /* CI load/store variants */
3167 GEN_LDX_HVRM(ldcix
, ld64_i64
, 0x15, 0x1b, PPC_CILDST
)
3168 GEN_LDX_HVRM(lwzcix
, ld32u
, 0x15, 0x15, PPC_CILDST
)
3169 GEN_LDX_HVRM(lhzcix
, ld16u
, 0x15, 0x19, PPC_CILDST
)
3170 GEN_LDX_HVRM(lbzcix
, ld8u
, 0x15, 0x1a, PPC_CILDST
)
3173 /*** Integer store ***/
3174 #define GEN_STX_E(name, stop, opc2, opc3, type, type2, chk) \
3175 static void glue(gen_, name##x)(DisasContext *ctx) \
3179 gen_set_access_type(ctx, ACCESS_INT); \
3180 EA = tcg_temp_new(); \
3181 gen_addr_reg_index(ctx, EA); \
3182 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
3184 #define GEN_STX(name, stop, opc2, opc3, type) \
3185 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE, CHK_NONE)
3187 #define GEN_STX_HVRM(name, stop, opc2, opc3, type) \
3188 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE, CHK_HVRM)
3190 #define GEN_STEPX(name, stop, opc2, opc3) \
3191 static void glue(gen_, name##epx)(DisasContext *ctx) \
3195 gen_set_access_type(ctx, ACCESS_INT); \
3196 EA = tcg_temp_new(); \
3197 gen_addr_reg_index(ctx, EA); \
3198 tcg_gen_qemu_st_tl( \
3199 cpu_gpr[rD(ctx->opcode)], EA, PPC_TLB_EPID_STORE, stop); \
3202 GEN_STEPX(stb
, DEF_MEMOP(MO_UB
), 0x1F, 0x06)
3203 GEN_STEPX(sth
, DEF_MEMOP(MO_UW
), 0x1F, 0x0C)
3204 GEN_STEPX(stw
, DEF_MEMOP(MO_UL
), 0x1F, 0x04)
3205 #if defined(TARGET_PPC64)
3206 GEN_STEPX(std
, DEF_MEMOP(MO_UQ
), 0x1d, 0x04)
3209 #if defined(TARGET_PPC64)
3210 GEN_STX_HVRM(stdcix
, st64_i64
, 0x15, 0x1f, PPC_CILDST
)
3211 GEN_STX_HVRM(stwcix
, st32
, 0x15, 0x1c, PPC_CILDST
)
3212 GEN_STX_HVRM(sthcix
, st16
, 0x15, 0x1d, PPC_CILDST
)
3213 GEN_STX_HVRM(stbcix
, st8
, 0x15, 0x1e, PPC_CILDST
)
3215 /*** Integer load and store with byte reverse ***/
3218 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
);
3221 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
);
3223 #if defined(TARGET_PPC64)
3225 GEN_LDX_E(ldbr
, ld64ur_i64
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
, CHK_NONE
);
3227 GEN_STX_E(stdbr
, st64r_i64
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
, CHK_NONE
);
3228 #endif /* TARGET_PPC64 */
3231 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
);
3233 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
);
3235 /*** Integer load and store multiple ***/
3238 static void gen_lmw(DisasContext
*ctx
)
3244 gen_align_no_le(ctx
);
3247 gen_set_access_type(ctx
, ACCESS_INT
);
3248 t0
= tcg_temp_new();
3249 t1
= tcg_constant_i32(rD(ctx
->opcode
));
3250 gen_addr_imm_index(ctx
, t0
, 0);
3251 gen_helper_lmw(cpu_env
, t0
, t1
);
3255 static void gen_stmw(DisasContext
*ctx
)
3261 gen_align_no_le(ctx
);
3264 gen_set_access_type(ctx
, ACCESS_INT
);
3265 t0
= tcg_temp_new();
3266 t1
= tcg_constant_i32(rS(ctx
->opcode
));
3267 gen_addr_imm_index(ctx
, t0
, 0);
3268 gen_helper_stmw(cpu_env
, t0
, t1
);
3271 /*** Integer load and store strings ***/
3275 * PowerPC32 specification says we must generate an exception if rA is
3276 * in the range of registers to be loaded. In an other hand, IBM says
3277 * this is valid, but rA won't be loaded. For now, I'll follow the
3280 static void gen_lswi(DisasContext
*ctx
)
3284 int nb
= NB(ctx
->opcode
);
3285 int start
= rD(ctx
->opcode
);
3286 int ra
= rA(ctx
->opcode
);
3290 gen_align_no_le(ctx
);
3296 nr
= DIV_ROUND_UP(nb
, 4);
3297 if (unlikely(lsw_reg_in_range(start
, nr
, ra
))) {
3298 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
3301 gen_set_access_type(ctx
, ACCESS_INT
);
3302 t0
= tcg_temp_new();
3303 gen_addr_register(ctx
, t0
);
3304 t1
= tcg_constant_i32(nb
);
3305 t2
= tcg_constant_i32(start
);
3306 gen_helper_lsw(cpu_env
, t0
, t1
, t2
);
3310 static void gen_lswx(DisasContext
*ctx
)
3313 TCGv_i32 t1
, t2
, t3
;
3316 gen_align_no_le(ctx
);
3319 gen_set_access_type(ctx
, ACCESS_INT
);
3320 t0
= tcg_temp_new();
3321 gen_addr_reg_index(ctx
, t0
);
3322 t1
= tcg_constant_i32(rD(ctx
->opcode
));
3323 t2
= tcg_constant_i32(rA(ctx
->opcode
));
3324 t3
= tcg_constant_i32(rB(ctx
->opcode
));
3325 gen_helper_lswx(cpu_env
, t0
, t1
, t2
, t3
);
3329 static void gen_stswi(DisasContext
*ctx
)
3333 int nb
= NB(ctx
->opcode
);
3336 gen_align_no_le(ctx
);
3339 gen_set_access_type(ctx
, ACCESS_INT
);
3340 t0
= tcg_temp_new();
3341 gen_addr_register(ctx
, t0
);
3345 t1
= tcg_constant_i32(nb
);
3346 t2
= tcg_constant_i32(rS(ctx
->opcode
));
3347 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3351 static void gen_stswx(DisasContext
*ctx
)
3357 gen_align_no_le(ctx
);
3360 gen_set_access_type(ctx
, ACCESS_INT
);
3361 t0
= tcg_temp_new();
3362 gen_addr_reg_index(ctx
, t0
);
3363 t1
= tcg_temp_new_i32();
3364 tcg_gen_trunc_tl_i32(t1
, cpu_xer
);
3365 tcg_gen_andi_i32(t1
, t1
, 0x7F);
3366 t2
= tcg_constant_i32(rS(ctx
->opcode
));
3367 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3370 /*** Memory synchronisation ***/
3372 static void gen_eieio(DisasContext
*ctx
)
3374 TCGBar bar
= TCG_MO_ALL
;
3377 * eieio has complex semanitcs. It provides memory ordering between
3378 * operations in the set:
3379 * - loads from CI memory.
3380 * - stores to CI memory.
3381 * - stores to WT memory.
3383 * It separately also orders memory for operations in the set:
3384 * - stores to cacheble memory.
3386 * It also serializes instructions:
3389 * It separately serializes:
3390 * - tlbie and tlbsync.
3392 * And separately serializes:
3393 * - slbieg, slbiag, and slbsync.
3395 * The end result is that CI memory ordering requires TCG_MO_ALL
3396 * and it is not possible to special-case more relaxed ordering for
3397 * cacheable accesses. TCG_BAR_SC is required to provide this
3402 * POWER9 has a eieio instruction variant using bit 6 as a hint to
3403 * tell the CPU it is a store-forwarding barrier.
3405 if (ctx
->opcode
& 0x2000000) {
3407 * ISA says that "Reserved fields in instructions are ignored
3408 * by the processor". So ignore the bit 6 on non-POWER9 CPU but
3409 * as this is not an instruction software should be using,
3410 * complain to the user.
3412 if (!(ctx
->insns_flags2
& PPC2_ISA300
)) {
3413 qemu_log_mask(LOG_GUEST_ERROR
, "invalid eieio using bit 6 at @"
3414 TARGET_FMT_lx
"\n", ctx
->cia
);
3420 tcg_gen_mb(bar
| TCG_BAR_SC
);
3423 #if !defined(CONFIG_USER_ONLY)
3424 static inline void gen_check_tlb_flush(DisasContext
*ctx
, bool global
)
3429 if (!ctx
->lazy_tlb_flush
) {
3432 l
= gen_new_label();
3433 t
= tcg_temp_new_i32();
3434 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUPPCState
, tlb_need_flush
));
3435 tcg_gen_brcondi_i32(TCG_COND_EQ
, t
, 0, l
);
3437 gen_helper_check_tlb_flush_global(cpu_env
);
3439 gen_helper_check_tlb_flush_local(cpu_env
);
3444 static inline void gen_check_tlb_flush(DisasContext
*ctx
, bool global
) { }
3448 static void gen_isync(DisasContext
*ctx
)
3451 * We need to check for a pending TLB flush. This can only happen in
3452 * kernel mode however so check MSR_PR
3455 gen_check_tlb_flush(ctx
, false);
3457 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_SC
);
3458 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
3461 #define MEMOP_GET_SIZE(x) (1 << ((x) & MO_SIZE))
3463 static void gen_load_locked(DisasContext
*ctx
, MemOp memop
)
3465 TCGv gpr
= cpu_gpr
[rD(ctx
->opcode
)];
3466 TCGv t0
= tcg_temp_new();
3468 gen_set_access_type(ctx
, ACCESS_RES
);
3469 gen_addr_reg_index(ctx
, t0
);
3470 tcg_gen_qemu_ld_tl(gpr
, t0
, ctx
->mem_idx
, memop
| MO_ALIGN
);
3471 tcg_gen_mov_tl(cpu_reserve
, t0
);
3472 tcg_gen_mov_tl(cpu_reserve_val
, gpr
);
3473 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
3476 #define LARX(name, memop) \
3477 static void gen_##name(DisasContext *ctx) \
3479 gen_load_locked(ctx, memop); \
3483 LARX(lbarx
, DEF_MEMOP(MO_UB
))
3484 LARX(lharx
, DEF_MEMOP(MO_UW
))
3485 LARX(lwarx
, DEF_MEMOP(MO_UL
))
3487 static void gen_fetch_inc_conditional(DisasContext
*ctx
, MemOp memop
,
3488 TCGv EA
, TCGCond cond
, int addend
)
3490 TCGv t
= tcg_temp_new();
3491 TCGv t2
= tcg_temp_new();
3492 TCGv u
= tcg_temp_new();
3494 tcg_gen_qemu_ld_tl(t
, EA
, ctx
->mem_idx
, memop
);
3495 tcg_gen_addi_tl(t2
, EA
, MEMOP_GET_SIZE(memop
));
3496 tcg_gen_qemu_ld_tl(t2
, t2
, ctx
->mem_idx
, memop
);
3497 tcg_gen_addi_tl(u
, t
, addend
);
3499 /* E.g. for fetch and increment bounded... */
3500 /* mem(EA,s) = (t != t2 ? u = t + 1 : t) */
3501 tcg_gen_movcond_tl(cond
, u
, t
, t2
, u
, t
);
3502 tcg_gen_qemu_st_tl(u
, EA
, ctx
->mem_idx
, memop
);
3504 /* RT = (t != t2 ? t : u = 1<<(s*8-1)) */
3505 tcg_gen_movi_tl(u
, 1 << (MEMOP_GET_SIZE(memop
) * 8 - 1));
3506 tcg_gen_movcond_tl(cond
, cpu_gpr
[rD(ctx
->opcode
)], t
, t2
, t
, u
);
3509 static void gen_ld_atomic(DisasContext
*ctx
, MemOp memop
)
3511 uint32_t gpr_FC
= FC(ctx
->opcode
);
3512 TCGv EA
= tcg_temp_new();
3513 int rt
= rD(ctx
->opcode
);
3517 gen_addr_register(ctx
, EA
);
3519 src
= cpu_gpr
[(rt
+ 1) & 31];
3521 need_serial
= false;
3524 case 0: /* Fetch and add */
3525 tcg_gen_atomic_fetch_add_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3527 case 1: /* Fetch and xor */
3528 tcg_gen_atomic_fetch_xor_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3530 case 2: /* Fetch and or */
3531 tcg_gen_atomic_fetch_or_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3533 case 3: /* Fetch and 'and' */
3534 tcg_gen_atomic_fetch_and_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3536 case 4: /* Fetch and max unsigned */
3537 tcg_gen_atomic_fetch_umax_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3539 case 5: /* Fetch and max signed */
3540 tcg_gen_atomic_fetch_smax_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3542 case 6: /* Fetch and min unsigned */
3543 tcg_gen_atomic_fetch_umin_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3545 case 7: /* Fetch and min signed */
3546 tcg_gen_atomic_fetch_smin_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3549 tcg_gen_atomic_xchg_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3552 case 16: /* Compare and swap not equal */
3553 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3556 TCGv t0
= tcg_temp_new();
3557 TCGv t1
= tcg_temp_new();
3559 tcg_gen_qemu_ld_tl(t0
, EA
, ctx
->mem_idx
, memop
);
3560 if ((memop
& MO_SIZE
) == MO_64
|| TARGET_LONG_BITS
== 32) {
3561 tcg_gen_mov_tl(t1
, src
);
3563 tcg_gen_ext32u_tl(t1
, src
);
3565 tcg_gen_movcond_tl(TCG_COND_NE
, t1
, t0
, t1
,
3566 cpu_gpr
[(rt
+ 2) & 31], t0
);
3567 tcg_gen_qemu_st_tl(t1
, EA
, ctx
->mem_idx
, memop
);
3568 tcg_gen_mov_tl(dst
, t0
);
3572 case 24: /* Fetch and increment bounded */
3573 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3576 gen_fetch_inc_conditional(ctx
, memop
, EA
, TCG_COND_NE
, 1);
3579 case 25: /* Fetch and increment equal */
3580 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3583 gen_fetch_inc_conditional(ctx
, memop
, EA
, TCG_COND_EQ
, 1);
3586 case 28: /* Fetch and decrement bounded */
3587 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3590 gen_fetch_inc_conditional(ctx
, memop
, EA
, TCG_COND_NE
, -1);
3595 /* invoke data storage error handler */
3596 gen_exception_err(ctx
, POWERPC_EXCP_DSI
, POWERPC_EXCP_INVAL
);
3600 /* Restart with exclusive lock. */
3601 gen_helper_exit_atomic(cpu_env
);
3602 ctx
->base
.is_jmp
= DISAS_NORETURN
;
3606 static void gen_lwat(DisasContext
*ctx
)
3608 gen_ld_atomic(ctx
, DEF_MEMOP(MO_UL
));
3612 static void gen_ldat(DisasContext
*ctx
)
3614 gen_ld_atomic(ctx
, DEF_MEMOP(MO_UQ
));
3618 static void gen_st_atomic(DisasContext
*ctx
, MemOp memop
)
3620 uint32_t gpr_FC
= FC(ctx
->opcode
);
3621 TCGv EA
= tcg_temp_new();
3624 gen_addr_register(ctx
, EA
);
3625 src
= cpu_gpr
[rD(ctx
->opcode
)];
3626 discard
= tcg_temp_new();
3630 case 0: /* add and Store */
3631 tcg_gen_atomic_add_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3633 case 1: /* xor and Store */
3634 tcg_gen_atomic_xor_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3636 case 2: /* Or and Store */
3637 tcg_gen_atomic_or_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3639 case 3: /* 'and' and Store */
3640 tcg_gen_atomic_and_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3642 case 4: /* Store max unsigned */
3643 tcg_gen_atomic_umax_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3645 case 5: /* Store max signed */
3646 tcg_gen_atomic_smax_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3648 case 6: /* Store min unsigned */
3649 tcg_gen_atomic_umin_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3651 case 7: /* Store min signed */
3652 tcg_gen_atomic_smin_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3654 case 24: /* Store twin */
3655 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3656 /* Restart with exclusive lock. */
3657 gen_helper_exit_atomic(cpu_env
);
3658 ctx
->base
.is_jmp
= DISAS_NORETURN
;
3660 TCGv t
= tcg_temp_new();
3661 TCGv t2
= tcg_temp_new();
3662 TCGv s
= tcg_temp_new();
3663 TCGv s2
= tcg_temp_new();
3664 TCGv ea_plus_s
= tcg_temp_new();
3666 tcg_gen_qemu_ld_tl(t
, EA
, ctx
->mem_idx
, memop
);
3667 tcg_gen_addi_tl(ea_plus_s
, EA
, MEMOP_GET_SIZE(memop
));
3668 tcg_gen_qemu_ld_tl(t2
, ea_plus_s
, ctx
->mem_idx
, memop
);
3669 tcg_gen_movcond_tl(TCG_COND_EQ
, s
, t
, t2
, src
, t
);
3670 tcg_gen_movcond_tl(TCG_COND_EQ
, s2
, t
, t2
, src
, t2
);
3671 tcg_gen_qemu_st_tl(s
, EA
, ctx
->mem_idx
, memop
);
3672 tcg_gen_qemu_st_tl(s2
, ea_plus_s
, ctx
->mem_idx
, memop
);
3676 /* invoke data storage error handler */
3677 gen_exception_err(ctx
, POWERPC_EXCP_DSI
, POWERPC_EXCP_INVAL
);
3681 static void gen_stwat(DisasContext
*ctx
)
3683 gen_st_atomic(ctx
, DEF_MEMOP(MO_UL
));
3687 static void gen_stdat(DisasContext
*ctx
)
3689 gen_st_atomic(ctx
, DEF_MEMOP(MO_UQ
));
3693 static void gen_conditional_store(DisasContext
*ctx
, MemOp memop
)
3695 TCGLabel
*l1
= gen_new_label();
3696 TCGLabel
*l2
= gen_new_label();
3697 TCGv t0
= tcg_temp_new();
3698 int reg
= rS(ctx
->opcode
);
3700 gen_set_access_type(ctx
, ACCESS_RES
);
3701 gen_addr_reg_index(ctx
, t0
);
3702 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
3704 t0
= tcg_temp_new();
3705 tcg_gen_atomic_cmpxchg_tl(t0
, cpu_reserve
, cpu_reserve_val
,
3706 cpu_gpr
[reg
], ctx
->mem_idx
,
3707 DEF_MEMOP(memop
) | MO_ALIGN
);
3708 tcg_gen_setcond_tl(TCG_COND_EQ
, t0
, t0
, cpu_reserve_val
);
3709 tcg_gen_shli_tl(t0
, t0
, CRF_EQ_BIT
);
3710 tcg_gen_or_tl(t0
, t0
, cpu_so
);
3711 tcg_gen_trunc_tl_i32(cpu_crf
[0], t0
);
3717 * Address mismatch implies failure. But we still need to provide
3718 * the memory barrier semantics of the instruction.
3720 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
3721 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
3724 tcg_gen_movi_tl(cpu_reserve
, -1);
3727 #define STCX(name, memop) \
3728 static void gen_##name(DisasContext *ctx) \
3730 gen_conditional_store(ctx, memop); \
3733 STCX(stbcx_
, DEF_MEMOP(MO_UB
))
3734 STCX(sthcx_
, DEF_MEMOP(MO_UW
))
3735 STCX(stwcx_
, DEF_MEMOP(MO_UL
))
3737 #if defined(TARGET_PPC64)
3739 LARX(ldarx
, DEF_MEMOP(MO_UQ
))
3741 STCX(stdcx_
, DEF_MEMOP(MO_UQ
))
3744 static void gen_lqarx(DisasContext
*ctx
)
3746 int rd
= rD(ctx
->opcode
);
3750 if (unlikely((rd
& 1) || (rd
== rA(ctx
->opcode
)) ||
3751 (rd
== rB(ctx
->opcode
)))) {
3752 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3756 gen_set_access_type(ctx
, ACCESS_RES
);
3757 EA
= tcg_temp_new();
3758 gen_addr_reg_index(ctx
, EA
);
3760 /* Note that the low part is always in RD+1, even in LE mode. */
3761 lo
= cpu_gpr
[rd
+ 1];
3764 t16
= tcg_temp_new_i128();
3765 tcg_gen_qemu_ld_i128(t16
, EA
, ctx
->mem_idx
, DEF_MEMOP(MO_128
| MO_ALIGN
));
3766 tcg_gen_extr_i128_i64(lo
, hi
, t16
);
3768 tcg_gen_st_tl(hi
, cpu_env
, offsetof(CPUPPCState
, reserve_val
));
3769 tcg_gen_st_tl(lo
, cpu_env
, offsetof(CPUPPCState
, reserve_val2
));
3773 static void gen_stqcx_(DisasContext
*ctx
)
3775 TCGLabel
*lab_fail
, *lab_over
;
3776 int rs
= rS(ctx
->opcode
);
3780 if (unlikely(rs
& 1)) {
3781 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3785 lab_fail
= gen_new_label();
3786 lab_over
= gen_new_label();
3788 gen_set_access_type(ctx
, ACCESS_RES
);
3789 EA
= tcg_temp_new();
3790 gen_addr_reg_index(ctx
, EA
);
3792 tcg_gen_brcond_tl(TCG_COND_NE
, EA
, cpu_reserve
, lab_fail
);
3794 cmp
= tcg_temp_new_i128();
3795 val
= tcg_temp_new_i128();
3797 tcg_gen_concat_i64_i128(cmp
, cpu_reserve_val2
, cpu_reserve_val
);
3799 /* Note that the low part is always in RS+1, even in LE mode. */
3800 tcg_gen_concat_i64_i128(val
, cpu_gpr
[rs
+ 1], cpu_gpr
[rs
]);
3802 tcg_gen_atomic_cmpxchg_i128(val
, cpu_reserve
, cmp
, val
, ctx
->mem_idx
,
3803 DEF_MEMOP(MO_128
| MO_ALIGN
));
3805 t0
= tcg_temp_new();
3806 t1
= tcg_temp_new();
3807 tcg_gen_extr_i128_i64(t1
, t0
, val
);
3809 tcg_gen_xor_tl(t1
, t1
, cpu_reserve_val2
);
3810 tcg_gen_xor_tl(t0
, t0
, cpu_reserve_val
);
3811 tcg_gen_or_tl(t0
, t0
, t1
);
3813 tcg_gen_setcondi_tl(TCG_COND_EQ
, t0
, t0
, 0);
3814 tcg_gen_shli_tl(t0
, t0
, CRF_EQ_BIT
);
3815 tcg_gen_or_tl(t0
, t0
, cpu_so
);
3816 tcg_gen_trunc_tl_i32(cpu_crf
[0], t0
);
3818 tcg_gen_br(lab_over
);
3819 gen_set_label(lab_fail
);
3822 * Address mismatch implies failure. But we still need to provide
3823 * the memory barrier semantics of the instruction.
3825 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
3826 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
3828 gen_set_label(lab_over
);
3829 tcg_gen_movi_tl(cpu_reserve
, -1);
3831 #endif /* defined(TARGET_PPC64) */
3834 static void gen_sync(DisasContext
*ctx
)
3836 TCGBar bar
= TCG_MO_ALL
;
3837 uint32_t l
= (ctx
->opcode
>> 21) & 3;
3839 if ((l
== 1) && (ctx
->insns_flags2
& PPC2_MEM_LWSYNC
)) {
3840 bar
= TCG_MO_LD_LD
| TCG_MO_LD_ST
| TCG_MO_ST_ST
;
3844 * We may need to check for a pending TLB flush.
3846 * We do this on ptesync (l == 2) on ppc64 and any sync pn ppc32.
3848 * Additionally, this can only happen in kernel mode however so
3849 * check MSR_PR as well.
3851 if (((l
== 2) || !(ctx
->insns_flags
& PPC_64B
)) && !ctx
->pr
) {
3852 gen_check_tlb_flush(ctx
, true);
3855 tcg_gen_mb(bar
| TCG_BAR_SC
);
3859 static void gen_wait(DisasContext
*ctx
)
3863 if (ctx
->insns_flags
& PPC_WAIT
) {
3864 /* v2.03-v2.07 define an older incompatible 'wait' encoding. */
3866 if (ctx
->insns_flags2
& PPC2_PM_ISA206
) {
3867 /* v2.06 introduced the WC field. WC > 0 may be treated as no-op. */
3868 wc
= WC(ctx
->opcode
);
3873 } else if (ctx
->insns_flags2
& PPC2_ISA300
) {
3874 /* v3.0 defines a new 'wait' encoding. */
3875 wc
= WC(ctx
->opcode
);
3876 if (ctx
->insns_flags2
& PPC2_ISA310
) {
3877 uint32_t pl
= PL(ctx
->opcode
);
3879 /* WC 1,2 may be treated as no-op. WC 3 is reserved. */
3885 /* PL 1-3 are reserved. If WC=2 then the insn is treated as noop. */
3886 if (pl
> 0 && wc
!= 2) {
3891 } else { /* ISA300 */
3892 /* WC 1-3 are reserved */
3900 warn_report("wait instruction decoded with wrong ISA flags.");
3906 * wait without WC field or with WC=0 waits for an exception / interrupt
3910 TCGv_i32 t0
= tcg_constant_i32(1);
3911 tcg_gen_st_i32(t0
, cpu_env
,
3912 -offsetof(PowerPCCPU
, env
) + offsetof(CPUState
, halted
));
3913 /* Stop translation, as the CPU is supposed to sleep from now */
3914 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
3918 * Other wait types must not just wait until an exception occurs because
3919 * ignoring their other wake-up conditions could cause a hang.
3921 * For v2.06 and 2.07, wc=1,2,3 are architected but may be implemented as
3924 * wc=1 and wc=3 explicitly allow the instruction to be treated as a no-op.
3926 * wc=2 waits for an implementation-specific condition, such could be
3927 * always true, so it can be implemented as a no-op.
3929 * For v3.1, wc=1,2 are architected but may be implemented as no-ops.
3931 * wc=1 (waitrsv) waits for an exception or a reservation to be lost.
3932 * Reservation-loss may have implementation-specific conditions, so it
3933 * can be implemented as a no-op.
3935 * wc=2 waits for an exception or an amount of time to pass. This
3936 * amount is implementation-specific so it can be implemented as a
3939 * ISA v3.1 allows for execution to resume "in the rare case of
3940 * an implementation-dependent event", so in any case software must
3941 * not depend on the architected resumption condition to become
3942 * true, so no-op implementations should be architecturally correct
3947 #if defined(TARGET_PPC64)
3948 static void gen_doze(DisasContext
*ctx
)
3950 #if defined(CONFIG_USER_ONLY)
3956 t
= tcg_constant_i32(PPC_PM_DOZE
);
3957 gen_helper_pminsn(cpu_env
, t
);
3958 /* Stop translation, as the CPU is supposed to sleep from now */
3959 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
3960 #endif /* defined(CONFIG_USER_ONLY) */
3963 static void gen_nap(DisasContext
*ctx
)
3965 #if defined(CONFIG_USER_ONLY)
3971 t
= tcg_constant_i32(PPC_PM_NAP
);
3972 gen_helper_pminsn(cpu_env
, t
);
3973 /* Stop translation, as the CPU is supposed to sleep from now */
3974 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
3975 #endif /* defined(CONFIG_USER_ONLY) */
3978 static void gen_stop(DisasContext
*ctx
)
3980 #if defined(CONFIG_USER_ONLY)
3986 t
= tcg_constant_i32(PPC_PM_STOP
);
3987 gen_helper_pminsn(cpu_env
, t
);
3988 /* Stop translation, as the CPU is supposed to sleep from now */
3989 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
3990 #endif /* defined(CONFIG_USER_ONLY) */
3993 static void gen_sleep(DisasContext
*ctx
)
3995 #if defined(CONFIG_USER_ONLY)
4001 t
= tcg_constant_i32(PPC_PM_SLEEP
);
4002 gen_helper_pminsn(cpu_env
, t
);
4003 /* Stop translation, as the CPU is supposed to sleep from now */
4004 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
4005 #endif /* defined(CONFIG_USER_ONLY) */
4008 static void gen_rvwinkle(DisasContext
*ctx
)
4010 #if defined(CONFIG_USER_ONLY)
4016 t
= tcg_constant_i32(PPC_PM_RVWINKLE
);
4017 gen_helper_pminsn(cpu_env
, t
);
4018 /* Stop translation, as the CPU is supposed to sleep from now */
4019 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
4020 #endif /* defined(CONFIG_USER_ONLY) */
4022 #endif /* #if defined(TARGET_PPC64) */
4024 static inline void gen_update_cfar(DisasContext
*ctx
, target_ulong nip
)
4026 #if defined(TARGET_PPC64)
4027 if (ctx
->has_cfar
) {
4028 tcg_gen_movi_tl(cpu_cfar
, nip
);
4033 #if defined(TARGET_PPC64)
4034 static void pmu_count_insns(DisasContext
*ctx
)
4037 * Do not bother calling the helper if the PMU isn't counting
4040 if (!ctx
->pmu_insn_cnt
) {
4044 #if !defined(CONFIG_USER_ONLY)
4049 * The PMU insns_inc() helper stops the internal PMU timer if a
4050 * counter overflows happens. In that case, if the guest is
4051 * running with icount and we do not handle it beforehand,
4052 * the helper can trigger a 'bad icount read'.
4054 translator_io_start(&ctx
->base
);
4056 /* Avoid helper calls when only PMC5-6 are enabled. */
4057 if (!ctx
->pmc_other
) {
4058 l
= gen_new_label();
4059 t0
= tcg_temp_new();
4061 gen_load_spr(t0
, SPR_POWER_PMC5
);
4062 tcg_gen_addi_tl(t0
, t0
, ctx
->base
.num_insns
);
4063 gen_store_spr(SPR_POWER_PMC5
, t0
);
4064 /* Check for overflow, if it's enabled */
4065 if (ctx
->mmcr0_pmcjce
) {
4066 tcg_gen_brcondi_tl(TCG_COND_LT
, t0
, PMC_COUNTER_NEGATIVE_VAL
, l
);
4067 gen_helper_handle_pmc5_overflow(cpu_env
);
4072 gen_helper_insns_inc(cpu_env
, tcg_constant_i32(ctx
->base
.num_insns
));
4076 * User mode can read (but not write) PMC5 and start/stop
4077 * the PMU via MMCR0_FC. In this case just increment
4078 * PMC5 with base.num_insns.
4080 TCGv t0
= tcg_temp_new();
4082 gen_load_spr(t0
, SPR_POWER_PMC5
);
4083 tcg_gen_addi_tl(t0
, t0
, ctx
->base
.num_insns
);
4084 gen_store_spr(SPR_POWER_PMC5
, t0
);
4085 #endif /* #if !defined(CONFIG_USER_ONLY) */
4088 static void pmu_count_insns(DisasContext
*ctx
)
4092 #endif /* #if defined(TARGET_PPC64) */
4094 static inline bool use_goto_tb(DisasContext
*ctx
, target_ulong dest
)
4096 return translator_use_goto_tb(&ctx
->base
, dest
);
4099 static void gen_lookup_and_goto_ptr(DisasContext
*ctx
)
4101 if (unlikely(ctx
->singlestep_enabled
)) {
4102 gen_debug_exception(ctx
);
4105 * tcg_gen_lookup_and_goto_ptr will exit the TB if
4106 * CF_NO_GOTO_PTR is set. Count insns now.
4108 if (ctx
->base
.tb
->flags
& CF_NO_GOTO_PTR
) {
4109 pmu_count_insns(ctx
);
4112 tcg_gen_lookup_and_goto_ptr();
4117 static void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
4119 if (NARROW_MODE(ctx
)) {
4120 dest
= (uint32_t) dest
;
4122 if (use_goto_tb(ctx
, dest
)) {
4123 pmu_count_insns(ctx
);
4125 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
4126 tcg_gen_exit_tb(ctx
->base
.tb
, n
);
4128 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
4129 gen_lookup_and_goto_ptr(ctx
);
4133 static inline void gen_setlr(DisasContext
*ctx
, target_ulong nip
)
4135 if (NARROW_MODE(ctx
)) {
4136 nip
= (uint32_t)nip
;
4138 tcg_gen_movi_tl(cpu_lr
, nip
);
4142 static void gen_b(DisasContext
*ctx
)
4144 target_ulong li
, target
;
4146 /* sign extend LI */
4147 li
= LI(ctx
->opcode
);
4148 li
= (li
^ 0x02000000) - 0x02000000;
4149 if (likely(AA(ctx
->opcode
) == 0)) {
4150 target
= ctx
->cia
+ li
;
4154 if (LK(ctx
->opcode
)) {
4155 gen_setlr(ctx
, ctx
->base
.pc_next
);
4157 gen_update_cfar(ctx
, ctx
->cia
);
4158 gen_goto_tb(ctx
, 0, target
);
4159 ctx
->base
.is_jmp
= DISAS_NORETURN
;
4167 static void gen_bcond(DisasContext
*ctx
, int type
)
4169 uint32_t bo
= BO(ctx
->opcode
);
4173 if (type
== BCOND_LR
|| type
== BCOND_CTR
|| type
== BCOND_TAR
) {
4174 target
= tcg_temp_new();
4175 if (type
== BCOND_CTR
) {
4176 tcg_gen_mov_tl(target
, cpu_ctr
);
4177 } else if (type
== BCOND_TAR
) {
4178 gen_load_spr(target
, SPR_TAR
);
4180 tcg_gen_mov_tl(target
, cpu_lr
);
4185 if (LK(ctx
->opcode
)) {
4186 gen_setlr(ctx
, ctx
->base
.pc_next
);
4188 l1
= gen_new_label();
4189 if ((bo
& 0x4) == 0) {
4190 /* Decrement and test CTR */
4191 TCGv temp
= tcg_temp_new();
4193 if (type
== BCOND_CTR
) {
4195 * All ISAs up to v3 describe this form of bcctr as invalid but
4196 * some processors, ie. 64-bit server processors compliant with
4197 * arch 2.x, do implement a "test and decrement" logic instead,
4198 * as described in their respective UMs. This logic involves CTR
4199 * to act as both the branch target and a counter, which makes
4200 * it basically useless and thus never used in real code.
4202 * This form was hence chosen to trigger extra micro-architectural
4203 * side-effect on real HW needed for the Spectre v2 workaround.
4204 * It is up to guests that implement such workaround, ie. linux, to
4205 * use this form in a way it just triggers the side-effect without
4206 * doing anything else harmful.
4208 if (unlikely(!is_book3s_arch2x(ctx
))) {
4209 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
4213 if (NARROW_MODE(ctx
)) {
4214 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
4216 tcg_gen_mov_tl(temp
, cpu_ctr
);
4219 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
4221 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
4223 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
4225 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
4226 if (NARROW_MODE(ctx
)) {
4227 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
4229 tcg_gen_mov_tl(temp
, cpu_ctr
);
4232 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
4234 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
4238 if ((bo
& 0x10) == 0) {
4240 uint32_t bi
= BI(ctx
->opcode
);
4241 uint32_t mask
= 0x08 >> (bi
& 0x03);
4242 TCGv_i32 temp
= tcg_temp_new_i32();
4245 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
4246 tcg_gen_brcondi_i32(TCG_COND_EQ
, temp
, 0, l1
);
4248 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
4249 tcg_gen_brcondi_i32(TCG_COND_NE
, temp
, 0, l1
);
4252 gen_update_cfar(ctx
, ctx
->cia
);
4253 if (type
== BCOND_IM
) {
4254 target_ulong li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
4255 if (likely(AA(ctx
->opcode
) == 0)) {
4256 gen_goto_tb(ctx
, 0, ctx
->cia
+ li
);
4258 gen_goto_tb(ctx
, 0, li
);
4261 if (NARROW_MODE(ctx
)) {
4262 tcg_gen_andi_tl(cpu_nip
, target
, (uint32_t)~3);
4264 tcg_gen_andi_tl(cpu_nip
, target
, ~3);
4266 gen_lookup_and_goto_ptr(ctx
);
4268 if ((bo
& 0x14) != 0x14) {
4269 /* fallthrough case */
4271 gen_goto_tb(ctx
, 1, ctx
->base
.pc_next
);
4273 ctx
->base
.is_jmp
= DISAS_NORETURN
;
4276 static void gen_bc(DisasContext
*ctx
)
4278 gen_bcond(ctx
, BCOND_IM
);
4281 static void gen_bcctr(DisasContext
*ctx
)
4283 gen_bcond(ctx
, BCOND_CTR
);
4286 static void gen_bclr(DisasContext
*ctx
)
4288 gen_bcond(ctx
, BCOND_LR
);
4291 static void gen_bctar(DisasContext
*ctx
)
4293 gen_bcond(ctx
, BCOND_TAR
);
4296 /*** Condition register logical ***/
4297 #define GEN_CRLOGIC(name, tcg_op, opc) \
4298 static void glue(gen_, name)(DisasContext *ctx) \
4303 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
4304 t0 = tcg_temp_new_i32(); \
4306 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
4308 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
4310 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
4311 t1 = tcg_temp_new_i32(); \
4312 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
4314 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
4316 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
4318 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
4319 tcg_op(t0, t0, t1); \
4320 bitmask = 0x08 >> (crbD(ctx->opcode) & 0x03); \
4321 tcg_gen_andi_i32(t0, t0, bitmask); \
4322 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
4323 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
4327 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08);
4329 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04);
4331 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09);
4333 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07);
4335 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01);
4337 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E);
4339 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D);
4341 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06);
4344 static void gen_mcrf(DisasContext
*ctx
)
4346 tcg_gen_mov_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfS(ctx
->opcode
)]);
4349 /*** System linkage ***/
4351 /* rfi (supervisor only) */
4352 static void gen_rfi(DisasContext
*ctx
)
4354 #if defined(CONFIG_USER_ONLY)
4358 * This instruction doesn't exist anymore on 64-bit server
4359 * processors compliant with arch 2.x
4361 if (is_book3s_arch2x(ctx
)) {
4362 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
4365 /* Restore CPU state */
4367 translator_io_start(&ctx
->base
);
4368 gen_update_cfar(ctx
, ctx
->cia
);
4369 gen_helper_rfi(cpu_env
);
4370 ctx
->base
.is_jmp
= DISAS_EXIT
;
4374 #if defined(TARGET_PPC64)
4375 static void gen_rfid(DisasContext
*ctx
)
4377 #if defined(CONFIG_USER_ONLY)
4380 /* Restore CPU state */
4382 translator_io_start(&ctx
->base
);
4383 gen_update_cfar(ctx
, ctx
->cia
);
4384 gen_helper_rfid(cpu_env
);
4385 ctx
->base
.is_jmp
= DISAS_EXIT
;
4389 #if !defined(CONFIG_USER_ONLY)
4390 static void gen_rfscv(DisasContext
*ctx
)
4392 #if defined(CONFIG_USER_ONLY)
4395 /* Restore CPU state */
4397 translator_io_start(&ctx
->base
);
4398 gen_update_cfar(ctx
, ctx
->cia
);
4399 gen_helper_rfscv(cpu_env
);
4400 ctx
->base
.is_jmp
= DISAS_EXIT
;
4405 static void gen_hrfid(DisasContext
*ctx
)
4407 #if defined(CONFIG_USER_ONLY)
4410 /* Restore CPU state */
4412 gen_helper_hrfid(cpu_env
);
4413 ctx
->base
.is_jmp
= DISAS_EXIT
;
4419 #if defined(CONFIG_USER_ONLY)
4420 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
4422 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
4423 #define POWERPC_SYSCALL_VECTORED POWERPC_EXCP_SYSCALL_VECTORED
4425 static void gen_sc(DisasContext
*ctx
)
4429 lev
= (ctx
->opcode
>> 5) & 0x7F;
4430 gen_exception_err(ctx
, POWERPC_SYSCALL
, lev
);
4433 #if defined(TARGET_PPC64)
4434 #if !defined(CONFIG_USER_ONLY)
4435 static void gen_scv(DisasContext
*ctx
)
4437 uint32_t lev
= (ctx
->opcode
>> 5) & 0x7F;
4439 /* Set the PC back to the faulting instruction. */
4440 gen_update_nip(ctx
, ctx
->cia
);
4441 gen_helper_scv(cpu_env
, tcg_constant_i32(lev
));
4443 ctx
->base
.is_jmp
= DISAS_NORETURN
;
4450 /* Check for unconditional traps (always or never) */
4451 static bool check_unconditional_trap(DisasContext
*ctx
)
4454 if (TO(ctx
->opcode
) == 0) {
4458 if (TO(ctx
->opcode
) == 31) {
4459 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_TRAP
);
4466 static void gen_tw(DisasContext
*ctx
)
4470 if (check_unconditional_trap(ctx
)) {
4473 t0
= tcg_constant_i32(TO(ctx
->opcode
));
4474 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
4479 static void gen_twi(DisasContext
*ctx
)
4484 if (check_unconditional_trap(ctx
)) {
4487 t0
= tcg_constant_tl(SIMM(ctx
->opcode
));
4488 t1
= tcg_constant_i32(TO(ctx
->opcode
));
4489 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4492 #if defined(TARGET_PPC64)
4494 static void gen_td(DisasContext
*ctx
)
4498 if (check_unconditional_trap(ctx
)) {
4501 t0
= tcg_constant_i32(TO(ctx
->opcode
));
4502 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
4507 static void gen_tdi(DisasContext
*ctx
)
4512 if (check_unconditional_trap(ctx
)) {
4515 t0
= tcg_constant_tl(SIMM(ctx
->opcode
));
4516 t1
= tcg_constant_i32(TO(ctx
->opcode
));
4517 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4521 /*** Processor control ***/
4524 static void gen_mcrxr(DisasContext
*ctx
)
4526 TCGv_i32 t0
= tcg_temp_new_i32();
4527 TCGv_i32 t1
= tcg_temp_new_i32();
4528 TCGv_i32 dst
= cpu_crf
[crfD(ctx
->opcode
)];
4530 tcg_gen_trunc_tl_i32(t0
, cpu_so
);
4531 tcg_gen_trunc_tl_i32(t1
, cpu_ov
);
4532 tcg_gen_trunc_tl_i32(dst
, cpu_ca
);
4533 tcg_gen_shli_i32(t0
, t0
, 3);
4534 tcg_gen_shli_i32(t1
, t1
, 2);
4535 tcg_gen_shli_i32(dst
, dst
, 1);
4536 tcg_gen_or_i32(dst
, dst
, t0
);
4537 tcg_gen_or_i32(dst
, dst
, t1
);
4539 tcg_gen_movi_tl(cpu_so
, 0);
4540 tcg_gen_movi_tl(cpu_ov
, 0);
4541 tcg_gen_movi_tl(cpu_ca
, 0);
4546 static void gen_mcrxrx(DisasContext
*ctx
)
4548 TCGv t0
= tcg_temp_new();
4549 TCGv t1
= tcg_temp_new();
4550 TCGv_i32 dst
= cpu_crf
[crfD(ctx
->opcode
)];
4552 /* copy OV and OV32 */
4553 tcg_gen_shli_tl(t0
, cpu_ov
, 1);
4554 tcg_gen_or_tl(t0
, t0
, cpu_ov32
);
4555 tcg_gen_shli_tl(t0
, t0
, 2);
4556 /* copy CA and CA32 */
4557 tcg_gen_shli_tl(t1
, cpu_ca
, 1);
4558 tcg_gen_or_tl(t1
, t1
, cpu_ca32
);
4559 tcg_gen_or_tl(t0
, t0
, t1
);
4560 tcg_gen_trunc_tl_i32(dst
, t0
);
4565 static void gen_mfcr(DisasContext
*ctx
)
4569 if (likely(ctx
->opcode
& 0x00100000)) {
4570 crm
= CRM(ctx
->opcode
);
4571 if (likely(crm
&& ((crm
& (crm
- 1)) == 0))) {
4573 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_crf
[7 - crn
]);
4574 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)],
4575 cpu_gpr
[rD(ctx
->opcode
)], crn
* 4);
4578 TCGv_i32 t0
= tcg_temp_new_i32();
4579 tcg_gen_mov_i32(t0
, cpu_crf
[0]);
4580 tcg_gen_shli_i32(t0
, t0
, 4);
4581 tcg_gen_or_i32(t0
, t0
, cpu_crf
[1]);
4582 tcg_gen_shli_i32(t0
, t0
, 4);
4583 tcg_gen_or_i32(t0
, t0
, cpu_crf
[2]);
4584 tcg_gen_shli_i32(t0
, t0
, 4);
4585 tcg_gen_or_i32(t0
, t0
, cpu_crf
[3]);
4586 tcg_gen_shli_i32(t0
, t0
, 4);
4587 tcg_gen_or_i32(t0
, t0
, cpu_crf
[4]);
4588 tcg_gen_shli_i32(t0
, t0
, 4);
4589 tcg_gen_or_i32(t0
, t0
, cpu_crf
[5]);
4590 tcg_gen_shli_i32(t0
, t0
, 4);
4591 tcg_gen_or_i32(t0
, t0
, cpu_crf
[6]);
4592 tcg_gen_shli_i32(t0
, t0
, 4);
4593 tcg_gen_or_i32(t0
, t0
, cpu_crf
[7]);
4594 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4599 static void gen_mfmsr(DisasContext
*ctx
)
4602 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_msr
);
4606 static inline void gen_op_mfspr(DisasContext
*ctx
)
4608 void (*read_cb
)(DisasContext
*ctx
, int gprn
, int sprn
);
4609 uint32_t sprn
= SPR(ctx
->opcode
);
4611 #if defined(CONFIG_USER_ONLY)
4612 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
4615 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
4616 } else if (ctx
->hv
) {
4617 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
4619 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
4622 if (likely(read_cb
!= NULL
)) {
4623 if (likely(read_cb
!= SPR_NOACCESS
)) {
4624 (*read_cb
)(ctx
, rD(ctx
->opcode
), sprn
);
4626 /* Privilege exception */
4628 * This is a hack to avoid warnings when running Linux:
4629 * this OS breaks the PowerPC virtualisation model,
4630 * allowing userland application to read the PVR
4632 if (sprn
!= SPR_PVR
) {
4633 qemu_log_mask(LOG_GUEST_ERROR
, "Trying to read privileged spr "
4634 "%d (0x%03x) at " TARGET_FMT_lx
"\n", sprn
, sprn
,
4637 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4640 /* ISA 2.07 defines these as no-ops */
4641 if ((ctx
->insns_flags2
& PPC2_ISA207S
) &&
4642 (sprn
>= 808 && sprn
<= 811)) {
4647 qemu_log_mask(LOG_GUEST_ERROR
,
4648 "Trying to read invalid spr %d (0x%03x) at "
4649 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->cia
);
4652 * The behaviour depends on MSR:PR and SPR# bit 0x10, it can
4653 * generate a priv, a hv emu or a no-op
4657 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4660 if (ctx
->pr
|| sprn
== 0 || sprn
== 4 || sprn
== 5 || sprn
== 6) {
4661 gen_hvpriv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4667 static void gen_mfspr(DisasContext
*ctx
)
4673 static void gen_mftb(DisasContext
*ctx
)
4679 static void gen_mtcrf(DisasContext
*ctx
)
4683 crm
= CRM(ctx
->opcode
);
4684 if (likely((ctx
->opcode
& 0x00100000))) {
4685 if (crm
&& ((crm
& (crm
- 1)) == 0)) {
4686 TCGv_i32 temp
= tcg_temp_new_i32();
4688 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
4689 tcg_gen_shri_i32(temp
, temp
, crn
* 4);
4690 tcg_gen_andi_i32(cpu_crf
[7 - crn
], temp
, 0xf);
4693 TCGv_i32 temp
= tcg_temp_new_i32();
4694 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
4695 for (crn
= 0 ; crn
< 8 ; crn
++) {
4696 if (crm
& (1 << crn
)) {
4697 tcg_gen_shri_i32(cpu_crf
[7 - crn
], temp
, crn
* 4);
4698 tcg_gen_andi_i32(cpu_crf
[7 - crn
], cpu_crf
[7 - crn
], 0xf);
4705 #if defined(TARGET_PPC64)
4706 static void gen_mtmsrd(DisasContext
*ctx
)
4708 if (unlikely(!is_book3s_arch2x(ctx
))) {
4715 #if !defined(CONFIG_USER_ONLY)
4719 t0
= tcg_temp_new();
4720 t1
= tcg_temp_new();
4722 translator_io_start(&ctx
->base
);
4724 if (ctx
->opcode
& 0x00010000) {
4725 /* L=1 form only updates EE and RI */
4726 mask
= (1ULL << MSR_RI
) | (1ULL << MSR_EE
);
4728 /* mtmsrd does not alter HV, S, ME, or LE */
4729 mask
= ~((1ULL << MSR_LE
) | (1ULL << MSR_ME
) | (1ULL << MSR_S
) |
4732 * XXX: we need to update nip before the store if we enter
4733 * power saving mode, we will exit the loop directly from
4736 gen_update_nip(ctx
, ctx
->base
.pc_next
);
4739 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], mask
);
4740 tcg_gen_andi_tl(t1
, cpu_msr
, ~mask
);
4741 tcg_gen_or_tl(t0
, t0
, t1
);
4743 gen_helper_store_msr(cpu_env
, t0
);
4745 /* Must stop the translation as machine state (may have) changed */
4746 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
4747 #endif /* !defined(CONFIG_USER_ONLY) */
4749 #endif /* defined(TARGET_PPC64) */
4751 static void gen_mtmsr(DisasContext
*ctx
)
4755 #if !defined(CONFIG_USER_ONLY)
4757 target_ulong mask
= 0xFFFFFFFF;
4759 t0
= tcg_temp_new();
4760 t1
= tcg_temp_new();
4762 translator_io_start(&ctx
->base
);
4763 if (ctx
->opcode
& 0x00010000) {
4764 /* L=1 form only updates EE and RI */
4765 mask
&= (1ULL << MSR_RI
) | (1ULL << MSR_EE
);
4767 /* mtmsr does not alter S, ME, or LE */
4768 mask
&= ~((1ULL << MSR_LE
) | (1ULL << MSR_ME
) | (1ULL << MSR_S
));
4771 * XXX: we need to update nip before the store if we enter
4772 * power saving mode, we will exit the loop directly from
4775 gen_update_nip(ctx
, ctx
->base
.pc_next
);
4778 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], mask
);
4779 tcg_gen_andi_tl(t1
, cpu_msr
, ~mask
);
4780 tcg_gen_or_tl(t0
, t0
, t1
);
4782 gen_helper_store_msr(cpu_env
, t0
);
4784 /* Must stop the translation as machine state (may have) changed */
4785 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
4790 static void gen_mtspr(DisasContext
*ctx
)
4792 void (*write_cb
)(DisasContext
*ctx
, int sprn
, int gprn
);
4793 uint32_t sprn
= SPR(ctx
->opcode
);
4795 #if defined(CONFIG_USER_ONLY)
4796 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
4799 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
4800 } else if (ctx
->hv
) {
4801 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
4803 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
4806 if (likely(write_cb
!= NULL
)) {
4807 if (likely(write_cb
!= SPR_NOACCESS
)) {
4808 (*write_cb
)(ctx
, sprn
, rS(ctx
->opcode
));
4810 /* Privilege exception */
4811 qemu_log_mask(LOG_GUEST_ERROR
, "Trying to write privileged spr "
4812 "%d (0x%03x) at " TARGET_FMT_lx
"\n", sprn
, sprn
,
4814 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4817 /* ISA 2.07 defines these as no-ops */
4818 if ((ctx
->insns_flags2
& PPC2_ISA207S
) &&
4819 (sprn
>= 808 && sprn
<= 811)) {
4825 qemu_log_mask(LOG_GUEST_ERROR
,
4826 "Trying to write invalid spr %d (0x%03x) at "
4827 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->cia
);
4831 * The behaviour depends on MSR:PR and SPR# bit 0x10, it can
4832 * generate a priv, a hv emu or a no-op
4836 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4839 if (ctx
->pr
|| sprn
== 0) {
4840 gen_hvpriv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4846 #if defined(TARGET_PPC64)
4848 static void gen_setb(DisasContext
*ctx
)
4850 TCGv_i32 t0
= tcg_temp_new_i32();
4851 TCGv_i32 t8
= tcg_constant_i32(8);
4852 TCGv_i32 tm1
= tcg_constant_i32(-1);
4853 int crf
= crfS(ctx
->opcode
);
4855 tcg_gen_setcondi_i32(TCG_COND_GEU
, t0
, cpu_crf
[crf
], 4);
4856 tcg_gen_movcond_i32(TCG_COND_GEU
, t0
, cpu_crf
[crf
], t8
, tm1
, t0
);
4857 tcg_gen_ext_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4861 /*** Cache management ***/
4864 static void gen_dcbf(DisasContext
*ctx
)
4866 /* XXX: specification says this is treated as a load by the MMU */
4868 gen_set_access_type(ctx
, ACCESS_CACHE
);
4869 t0
= tcg_temp_new();
4870 gen_addr_reg_index(ctx
, t0
);
4871 gen_qemu_ld8u(ctx
, t0
, t0
);
4874 /* dcbfep (external PID dcbf) */
4875 static void gen_dcbfep(DisasContext
*ctx
)
4877 /* XXX: specification says this is treated as a load by the MMU */
4880 gen_set_access_type(ctx
, ACCESS_CACHE
);
4881 t0
= tcg_temp_new();
4882 gen_addr_reg_index(ctx
, t0
);
4883 tcg_gen_qemu_ld_tl(t0
, t0
, PPC_TLB_EPID_LOAD
, DEF_MEMOP(MO_UB
));
4886 /* dcbi (Supervisor only) */
4887 static void gen_dcbi(DisasContext
*ctx
)
4889 #if defined(CONFIG_USER_ONLY)
4895 EA
= tcg_temp_new();
4896 gen_set_access_type(ctx
, ACCESS_CACHE
);
4897 gen_addr_reg_index(ctx
, EA
);
4898 val
= tcg_temp_new();
4899 /* XXX: specification says this should be treated as a store by the MMU */
4900 gen_qemu_ld8u(ctx
, val
, EA
);
4901 gen_qemu_st8(ctx
, val
, EA
);
4902 #endif /* defined(CONFIG_USER_ONLY) */
4906 static void gen_dcbst(DisasContext
*ctx
)
4908 /* XXX: specification say this is treated as a load by the MMU */
4910 gen_set_access_type(ctx
, ACCESS_CACHE
);
4911 t0
= tcg_temp_new();
4912 gen_addr_reg_index(ctx
, t0
);
4913 gen_qemu_ld8u(ctx
, t0
, t0
);
4916 /* dcbstep (dcbstep External PID version) */
4917 static void gen_dcbstep(DisasContext
*ctx
)
4919 /* XXX: specification say this is treated as a load by the MMU */
4921 gen_set_access_type(ctx
, ACCESS_CACHE
);
4922 t0
= tcg_temp_new();
4923 gen_addr_reg_index(ctx
, t0
);
4924 tcg_gen_qemu_ld_tl(t0
, t0
, PPC_TLB_EPID_LOAD
, DEF_MEMOP(MO_UB
));
4928 static void gen_dcbt(DisasContext
*ctx
)
4931 * interpreted as no-op
4932 * XXX: specification say this is treated as a load by the MMU but
4933 * does not generate any exception
4938 static void gen_dcbtep(DisasContext
*ctx
)
4941 * interpreted as no-op
4942 * XXX: specification say this is treated as a load by the MMU but
4943 * does not generate any exception
4948 static void gen_dcbtst(DisasContext
*ctx
)
4951 * interpreted as no-op
4952 * XXX: specification say this is treated as a load by the MMU but
4953 * does not generate any exception
4958 static void gen_dcbtstep(DisasContext
*ctx
)
4961 * interpreted as no-op
4962 * XXX: specification say this is treated as a load by the MMU but
4963 * does not generate any exception
4968 static void gen_dcbtls(DisasContext
*ctx
)
4970 /* Always fails locking the cache */
4971 TCGv t0
= tcg_temp_new();
4972 gen_load_spr(t0
, SPR_Exxx_L1CSR0
);
4973 tcg_gen_ori_tl(t0
, t0
, L1CSR0_CUL
);
4974 gen_store_spr(SPR_Exxx_L1CSR0
, t0
);
4978 static void gen_dcblc(DisasContext
*ctx
)
4981 * interpreted as no-op
4986 static void gen_dcbz(DisasContext
*ctx
)
4991 gen_set_access_type(ctx
, ACCESS_CACHE
);
4992 tcgv_addr
= tcg_temp_new();
4993 tcgv_op
= tcg_constant_i32(ctx
->opcode
& 0x03FF000);
4994 gen_addr_reg_index(ctx
, tcgv_addr
);
4995 gen_helper_dcbz(cpu_env
, tcgv_addr
, tcgv_op
);
4999 static void gen_dcbzep(DisasContext
*ctx
)
5004 gen_set_access_type(ctx
, ACCESS_CACHE
);
5005 tcgv_addr
= tcg_temp_new();
5006 tcgv_op
= tcg_constant_i32(ctx
->opcode
& 0x03FF000);
5007 gen_addr_reg_index(ctx
, tcgv_addr
);
5008 gen_helper_dcbzep(cpu_env
, tcgv_addr
, tcgv_op
);
5012 static void gen_dst(DisasContext
*ctx
)
5014 if (rA(ctx
->opcode
) == 0) {
5015 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5017 /* interpreted as no-op */
5022 static void gen_dstst(DisasContext
*ctx
)
5024 if (rA(ctx
->opcode
) == 0) {
5025 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5027 /* interpreted as no-op */
5033 static void gen_dss(DisasContext
*ctx
)
5035 /* interpreted as no-op */
5039 static void gen_icbi(DisasContext
*ctx
)
5042 gen_set_access_type(ctx
, ACCESS_CACHE
);
5043 t0
= tcg_temp_new();
5044 gen_addr_reg_index(ctx
, t0
);
5045 gen_helper_icbi(cpu_env
, t0
);
5049 static void gen_icbiep(DisasContext
*ctx
)
5052 gen_set_access_type(ctx
, ACCESS_CACHE
);
5053 t0
= tcg_temp_new();
5054 gen_addr_reg_index(ctx
, t0
);
5055 gen_helper_icbiep(cpu_env
, t0
);
5060 static void gen_dcba(DisasContext
*ctx
)
5063 * interpreted as no-op
5064 * XXX: specification say this is treated as a store by the MMU
5065 * but does not generate any exception
5069 /*** Segment register manipulation ***/
5070 /* Supervisor only: */
5073 static void gen_mfsr(DisasContext
*ctx
)
5075 #if defined(CONFIG_USER_ONLY)
5081 t0
= tcg_constant_tl(SR(ctx
->opcode
));
5082 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5083 #endif /* defined(CONFIG_USER_ONLY) */
5087 static void gen_mfsrin(DisasContext
*ctx
)
5089 #if defined(CONFIG_USER_ONLY)
5095 t0
= tcg_temp_new();
5096 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
5097 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5098 #endif /* defined(CONFIG_USER_ONLY) */
5102 static void gen_mtsr(DisasContext
*ctx
)
5104 #if defined(CONFIG_USER_ONLY)
5110 t0
= tcg_constant_tl(SR(ctx
->opcode
));
5111 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
5112 #endif /* defined(CONFIG_USER_ONLY) */
5116 static void gen_mtsrin(DisasContext
*ctx
)
5118 #if defined(CONFIG_USER_ONLY)
5124 t0
= tcg_temp_new();
5125 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
5126 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rD(ctx
->opcode
)]);
5127 #endif /* defined(CONFIG_USER_ONLY) */
5130 #if defined(TARGET_PPC64)
5131 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
5134 static void gen_mfsr_64b(DisasContext
*ctx
)
5136 #if defined(CONFIG_USER_ONLY)
5142 t0
= tcg_constant_tl(SR(ctx
->opcode
));
5143 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5144 #endif /* defined(CONFIG_USER_ONLY) */
5148 static void gen_mfsrin_64b(DisasContext
*ctx
)
5150 #if defined(CONFIG_USER_ONLY)
5156 t0
= tcg_temp_new();
5157 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
5158 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5159 #endif /* defined(CONFIG_USER_ONLY) */
5163 static void gen_mtsr_64b(DisasContext
*ctx
)
5165 #if defined(CONFIG_USER_ONLY)
5171 t0
= tcg_constant_tl(SR(ctx
->opcode
));
5172 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
5173 #endif /* defined(CONFIG_USER_ONLY) */
5177 static void gen_mtsrin_64b(DisasContext
*ctx
)
5179 #if defined(CONFIG_USER_ONLY)
5185 t0
= tcg_temp_new();
5186 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
5187 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
5188 #endif /* defined(CONFIG_USER_ONLY) */
5191 #endif /* defined(TARGET_PPC64) */
5193 /*** Lookaside buffer management ***/
5194 /* Optional & supervisor only: */
5197 static void gen_tlbia(DisasContext
*ctx
)
5199 #if defined(CONFIG_USER_ONLY)
5204 gen_helper_tlbia(cpu_env
);
5205 #endif /* defined(CONFIG_USER_ONLY) */
5209 static void gen_tlbsync(DisasContext
*ctx
)
5211 #if defined(CONFIG_USER_ONLY)
5216 CHK_SV(ctx
); /* If gtse is set then tlbsync is supervisor privileged */
5218 CHK_HV(ctx
); /* Else hypervisor privileged */
5221 /* BookS does both ptesync and tlbsync make tlbsync a nop for server */
5222 if (ctx
->insns_flags
& PPC_BOOKE
) {
5223 gen_check_tlb_flush(ctx
, true);
5225 #endif /* defined(CONFIG_USER_ONLY) */
5228 /*** External control ***/
5232 static void gen_eciwx(DisasContext
*ctx
)
5235 /* Should check EAR[E] ! */
5236 gen_set_access_type(ctx
, ACCESS_EXT
);
5237 t0
= tcg_temp_new();
5238 gen_addr_reg_index(ctx
, t0
);
5239 tcg_gen_qemu_ld_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, ctx
->mem_idx
,
5240 DEF_MEMOP(MO_UL
| MO_ALIGN
));
5244 static void gen_ecowx(DisasContext
*ctx
)
5247 /* Should check EAR[E] ! */
5248 gen_set_access_type(ctx
, ACCESS_EXT
);
5249 t0
= tcg_temp_new();
5250 gen_addr_reg_index(ctx
, t0
);
5251 tcg_gen_qemu_st_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, ctx
->mem_idx
,
5252 DEF_MEMOP(MO_UL
| MO_ALIGN
));
5255 /* 602 - 603 - G2 TLB management */
5258 static void gen_tlbld_6xx(DisasContext
*ctx
)
5260 #if defined(CONFIG_USER_ONLY)
5264 gen_helper_6xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5265 #endif /* defined(CONFIG_USER_ONLY) */
5269 static void gen_tlbli_6xx(DisasContext
*ctx
)
5271 #if defined(CONFIG_USER_ONLY)
5275 gen_helper_6xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5276 #endif /* defined(CONFIG_USER_ONLY) */
5279 /* BookE specific instructions */
5281 /* XXX: not implemented on 440 ? */
5282 static void gen_mfapidi(DisasContext
*ctx
)
5285 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5288 /* XXX: not implemented on 440 ? */
5289 static void gen_tlbiva(DisasContext
*ctx
)
5291 #if defined(CONFIG_USER_ONLY)
5297 t0
= tcg_temp_new();
5298 gen_addr_reg_index(ctx
, t0
);
5299 gen_helper_tlbiva(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5300 #endif /* defined(CONFIG_USER_ONLY) */
5303 /* All 405 MAC instructions are translated here */
5304 static inline void gen_405_mulladd_insn(DisasContext
*ctx
, int opc2
, int opc3
,
5305 int ra
, int rb
, int rt
, int Rc
)
5309 t0
= tcg_temp_new();
5310 t1
= tcg_temp_new();
5312 switch (opc3
& 0x0D) {
5314 /* macchw - macchw. - macchwo - macchwo. */
5315 /* macchws - macchws. - macchwso - macchwso. */
5316 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
5317 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
5318 /* mulchw - mulchw. */
5319 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5320 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5321 tcg_gen_ext16s_tl(t1
, t1
);
5324 /* macchwu - macchwu. - macchwuo - macchwuo. */
5325 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
5326 /* mulchwu - mulchwu. */
5327 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5328 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5329 tcg_gen_ext16u_tl(t1
, t1
);
5332 /* machhw - machhw. - machhwo - machhwo. */
5333 /* machhws - machhws. - machhwso - machhwso. */
5334 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
5335 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
5336 /* mulhhw - mulhhw. */
5337 tcg_gen_sari_tl(t0
, cpu_gpr
[ra
], 16);
5338 tcg_gen_ext16s_tl(t0
, t0
);
5339 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
5340 tcg_gen_ext16s_tl(t1
, t1
);
5343 /* machhwu - machhwu. - machhwuo - machhwuo. */
5344 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
5345 /* mulhhwu - mulhhwu. */
5346 tcg_gen_shri_tl(t0
, cpu_gpr
[ra
], 16);
5347 tcg_gen_ext16u_tl(t0
, t0
);
5348 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
5349 tcg_gen_ext16u_tl(t1
, t1
);
5352 /* maclhw - maclhw. - maclhwo - maclhwo. */
5353 /* maclhws - maclhws. - maclhwso - maclhwso. */
5354 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
5355 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
5356 /* mullhw - mullhw. */
5357 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
5358 tcg_gen_ext16s_tl(t1
, cpu_gpr
[rb
]);
5361 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
5362 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
5363 /* mullhwu - mullhwu. */
5364 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
5365 tcg_gen_ext16u_tl(t1
, cpu_gpr
[rb
]);
5369 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
5370 tcg_gen_mul_tl(t1
, t0
, t1
);
5372 /* nmultiply-and-accumulate (0x0E) */
5373 tcg_gen_sub_tl(t0
, cpu_gpr
[rt
], t1
);
5375 /* multiply-and-accumulate (0x0C) */
5376 tcg_gen_add_tl(t0
, cpu_gpr
[rt
], t1
);
5380 /* Check overflow and/or saturate */
5381 TCGLabel
*l1
= gen_new_label();
5384 /* Start with XER OV disabled, the most likely case */
5385 tcg_gen_movi_tl(cpu_ov
, 0);
5389 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t1
);
5390 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
5391 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t0
);
5392 tcg_gen_brcondi_tl(TCG_COND_LT
, t1
, 0, l1
);
5395 tcg_gen_sari_tl(t0
, cpu_gpr
[rt
], 31);
5396 tcg_gen_xori_tl(t0
, t0
, 0x7fffffff);
5400 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
5403 tcg_gen_movi_tl(t0
, UINT32_MAX
);
5407 /* Check overflow */
5408 tcg_gen_movi_tl(cpu_ov
, 1);
5409 tcg_gen_movi_tl(cpu_so
, 1);
5412 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
5415 tcg_gen_mul_tl(cpu_gpr
[rt
], t0
, t1
);
5417 if (unlikely(Rc
) != 0) {
5419 gen_set_Rc0(ctx
, cpu_gpr
[rt
]);
5423 #define GEN_MAC_HANDLER(name, opc2, opc3) \
5424 static void glue(gen_, name)(DisasContext *ctx) \
5426 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
5427 rD(ctx->opcode), Rc(ctx->opcode)); \
5430 /* macchw - macchw. */
5431 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
5432 /* macchwo - macchwo. */
5433 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
5434 /* macchws - macchws. */
5435 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
5436 /* macchwso - macchwso. */
5437 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
5438 /* macchwsu - macchwsu. */
5439 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
5440 /* macchwsuo - macchwsuo. */
5441 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
5442 /* macchwu - macchwu. */
5443 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
5444 /* macchwuo - macchwuo. */
5445 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
5446 /* machhw - machhw. */
5447 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
5448 /* machhwo - machhwo. */
5449 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
5450 /* machhws - machhws. */
5451 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
5452 /* machhwso - machhwso. */
5453 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
5454 /* machhwsu - machhwsu. */
5455 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
5456 /* machhwsuo - machhwsuo. */
5457 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
5458 /* machhwu - machhwu. */
5459 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
5460 /* machhwuo - machhwuo. */
5461 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
5462 /* maclhw - maclhw. */
5463 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
5464 /* maclhwo - maclhwo. */
5465 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
5466 /* maclhws - maclhws. */
5467 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
5468 /* maclhwso - maclhwso. */
5469 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
5470 /* maclhwu - maclhwu. */
5471 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
5472 /* maclhwuo - maclhwuo. */
5473 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
5474 /* maclhwsu - maclhwsu. */
5475 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
5476 /* maclhwsuo - maclhwsuo. */
5477 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
5478 /* nmacchw - nmacchw. */
5479 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
5480 /* nmacchwo - nmacchwo. */
5481 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
5482 /* nmacchws - nmacchws. */
5483 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
5484 /* nmacchwso - nmacchwso. */
5485 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
5486 /* nmachhw - nmachhw. */
5487 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
5488 /* nmachhwo - nmachhwo. */
5489 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
5490 /* nmachhws - nmachhws. */
5491 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
5492 /* nmachhwso - nmachhwso. */
5493 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
5494 /* nmaclhw - nmaclhw. */
5495 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
5496 /* nmaclhwo - nmaclhwo. */
5497 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
5498 /* nmaclhws - nmaclhws. */
5499 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
5500 /* nmaclhwso - nmaclhwso. */
5501 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
5503 /* mulchw - mulchw. */
5504 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
5505 /* mulchwu - mulchwu. */
5506 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
5507 /* mulhhw - mulhhw. */
5508 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
5509 /* mulhhwu - mulhhwu. */
5510 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
5511 /* mullhw - mullhw. */
5512 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
5513 /* mullhwu - mullhwu. */
5514 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
5517 static void gen_mfdcr(DisasContext
*ctx
)
5519 #if defined(CONFIG_USER_ONLY)
5525 dcrn
= tcg_constant_tl(SPR(ctx
->opcode
));
5526 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, dcrn
);
5527 #endif /* defined(CONFIG_USER_ONLY) */
5531 static void gen_mtdcr(DisasContext
*ctx
)
5533 #if defined(CONFIG_USER_ONLY)
5539 dcrn
= tcg_constant_tl(SPR(ctx
->opcode
));
5540 gen_helper_store_dcr(cpu_env
, dcrn
, cpu_gpr
[rS(ctx
->opcode
)]);
5541 #endif /* defined(CONFIG_USER_ONLY) */
5545 /* XXX: not implemented on 440 ? */
5546 static void gen_mfdcrx(DisasContext
*ctx
)
5548 #if defined(CONFIG_USER_ONLY)
5552 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5553 cpu_gpr
[rA(ctx
->opcode
)]);
5554 /* Note: Rc update flag set leads to undefined state of Rc0 */
5555 #endif /* defined(CONFIG_USER_ONLY) */
5559 /* XXX: not implemented on 440 ? */
5560 static void gen_mtdcrx(DisasContext
*ctx
)
5562 #if defined(CONFIG_USER_ONLY)
5566 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5567 cpu_gpr
[rS(ctx
->opcode
)]);
5568 /* Note: Rc update flag set leads to undefined state of Rc0 */
5569 #endif /* defined(CONFIG_USER_ONLY) */
5573 static void gen_dccci(DisasContext
*ctx
)
5576 /* interpreted as no-op */
5580 static void gen_dcread(DisasContext
*ctx
)
5582 #if defined(CONFIG_USER_ONLY)
5588 gen_set_access_type(ctx
, ACCESS_CACHE
);
5589 EA
= tcg_temp_new();
5590 gen_addr_reg_index(ctx
, EA
);
5591 val
= tcg_temp_new();
5592 gen_qemu_ld32u(ctx
, val
, EA
);
5593 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], EA
);
5594 #endif /* defined(CONFIG_USER_ONLY) */
5598 static void gen_icbt_40x(DisasContext
*ctx
)
5601 * interpreted as no-op
5602 * XXX: specification say this is treated as a load by the MMU but
5603 * does not generate any exception
5608 static void gen_iccci(DisasContext
*ctx
)
5611 /* interpreted as no-op */
5615 static void gen_icread(DisasContext
*ctx
)
5618 /* interpreted as no-op */
5621 /* rfci (supervisor only) */
5622 static void gen_rfci_40x(DisasContext
*ctx
)
5624 #if defined(CONFIG_USER_ONLY)
5628 /* Restore CPU state */
5629 gen_helper_40x_rfci(cpu_env
);
5630 ctx
->base
.is_jmp
= DISAS_EXIT
;
5631 #endif /* defined(CONFIG_USER_ONLY) */
5634 static void gen_rfci(DisasContext
*ctx
)
5636 #if defined(CONFIG_USER_ONLY)
5640 /* Restore CPU state */
5641 gen_helper_rfci(cpu_env
);
5642 ctx
->base
.is_jmp
= DISAS_EXIT
;
5643 #endif /* defined(CONFIG_USER_ONLY) */
5646 /* BookE specific */
5648 /* XXX: not implemented on 440 ? */
5649 static void gen_rfdi(DisasContext
*ctx
)
5651 #if defined(CONFIG_USER_ONLY)
5655 /* Restore CPU state */
5656 gen_helper_rfdi(cpu_env
);
5657 ctx
->base
.is_jmp
= DISAS_EXIT
;
5658 #endif /* defined(CONFIG_USER_ONLY) */
5661 /* XXX: not implemented on 440 ? */
5662 static void gen_rfmci(DisasContext
*ctx
)
5664 #if defined(CONFIG_USER_ONLY)
5668 /* Restore CPU state */
5669 gen_helper_rfmci(cpu_env
);
5670 ctx
->base
.is_jmp
= DISAS_EXIT
;
5671 #endif /* defined(CONFIG_USER_ONLY) */
5674 /* TLB management - PowerPC 405 implementation */
5677 static void gen_tlbre_40x(DisasContext
*ctx
)
5679 #if defined(CONFIG_USER_ONLY)
5683 switch (rB(ctx
->opcode
)) {
5685 gen_helper_4xx_tlbre_hi(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5686 cpu_gpr
[rA(ctx
->opcode
)]);
5689 gen_helper_4xx_tlbre_lo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5690 cpu_gpr
[rA(ctx
->opcode
)]);
5693 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5696 #endif /* defined(CONFIG_USER_ONLY) */
5699 /* tlbsx - tlbsx. */
5700 static void gen_tlbsx_40x(DisasContext
*ctx
)
5702 #if defined(CONFIG_USER_ONLY)
5708 t0
= tcg_temp_new();
5709 gen_addr_reg_index(ctx
, t0
);
5710 gen_helper_4xx_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5711 if (Rc(ctx
->opcode
)) {
5712 TCGLabel
*l1
= gen_new_label();
5713 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
5714 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
5715 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
5718 #endif /* defined(CONFIG_USER_ONLY) */
5722 static void gen_tlbwe_40x(DisasContext
*ctx
)
5724 #if defined(CONFIG_USER_ONLY)
5729 switch (rB(ctx
->opcode
)) {
5731 gen_helper_4xx_tlbwe_hi(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5732 cpu_gpr
[rS(ctx
->opcode
)]);
5735 gen_helper_4xx_tlbwe_lo(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5736 cpu_gpr
[rS(ctx
->opcode
)]);
5739 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5742 #endif /* defined(CONFIG_USER_ONLY) */
5745 /* TLB management - PowerPC 440 implementation */
5748 static void gen_tlbre_440(DisasContext
*ctx
)
5750 #if defined(CONFIG_USER_ONLY)
5755 switch (rB(ctx
->opcode
)) {
5760 TCGv_i32 t0
= tcg_constant_i32(rB(ctx
->opcode
));
5761 gen_helper_440_tlbre(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5762 t0
, cpu_gpr
[rA(ctx
->opcode
)]);
5766 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5769 #endif /* defined(CONFIG_USER_ONLY) */
5772 /* tlbsx - tlbsx. */
5773 static void gen_tlbsx_440(DisasContext
*ctx
)
5775 #if defined(CONFIG_USER_ONLY)
5781 t0
= tcg_temp_new();
5782 gen_addr_reg_index(ctx
, t0
);
5783 gen_helper_440_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5784 if (Rc(ctx
->opcode
)) {
5785 TCGLabel
*l1
= gen_new_label();
5786 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
5787 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
5788 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
5791 #endif /* defined(CONFIG_USER_ONLY) */
5795 static void gen_tlbwe_440(DisasContext
*ctx
)
5797 #if defined(CONFIG_USER_ONLY)
5801 switch (rB(ctx
->opcode
)) {
5806 TCGv_i32 t0
= tcg_constant_i32(rB(ctx
->opcode
));
5807 gen_helper_440_tlbwe(cpu_env
, t0
, cpu_gpr
[rA(ctx
->opcode
)],
5808 cpu_gpr
[rS(ctx
->opcode
)]);
5812 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5815 #endif /* defined(CONFIG_USER_ONLY) */
5818 /* TLB management - PowerPC BookE 2.06 implementation */
5821 static void gen_tlbre_booke206(DisasContext
*ctx
)
5823 #if defined(CONFIG_USER_ONLY)
5827 gen_helper_booke206_tlbre(cpu_env
);
5828 #endif /* defined(CONFIG_USER_ONLY) */
5831 /* tlbsx - tlbsx. */
5832 static void gen_tlbsx_booke206(DisasContext
*ctx
)
5834 #if defined(CONFIG_USER_ONLY)
5840 if (rA(ctx
->opcode
)) {
5841 t0
= tcg_temp_new();
5842 tcg_gen_add_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
5844 t0
= cpu_gpr
[rB(ctx
->opcode
)];
5846 gen_helper_booke206_tlbsx(cpu_env
, t0
);
5847 #endif /* defined(CONFIG_USER_ONLY) */
5851 static void gen_tlbwe_booke206(DisasContext
*ctx
)
5853 #if defined(CONFIG_USER_ONLY)
5857 gen_helper_booke206_tlbwe(cpu_env
);
5858 #endif /* defined(CONFIG_USER_ONLY) */
5861 static void gen_tlbivax_booke206(DisasContext
*ctx
)
5863 #if defined(CONFIG_USER_ONLY)
5869 t0
= tcg_temp_new();
5870 gen_addr_reg_index(ctx
, t0
);
5871 gen_helper_booke206_tlbivax(cpu_env
, t0
);
5872 #endif /* defined(CONFIG_USER_ONLY) */
5875 static void gen_tlbilx_booke206(DisasContext
*ctx
)
5877 #if defined(CONFIG_USER_ONLY)
5883 t0
= tcg_temp_new();
5884 gen_addr_reg_index(ctx
, t0
);
5886 switch ((ctx
->opcode
>> 21) & 0x3) {
5888 gen_helper_booke206_tlbilx0(cpu_env
, t0
);
5891 gen_helper_booke206_tlbilx1(cpu_env
, t0
);
5894 gen_helper_booke206_tlbilx3(cpu_env
, t0
);
5897 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5900 #endif /* defined(CONFIG_USER_ONLY) */
5904 static void gen_wrtee(DisasContext
*ctx
)
5906 #if defined(CONFIG_USER_ONLY)
5912 t0
= tcg_temp_new();
5913 tcg_gen_andi_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)], (1 << MSR_EE
));
5914 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
5915 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
5916 gen_ppc_maybe_interrupt(ctx
);
5918 * Stop translation to have a chance to raise an exception if we
5919 * just set msr_ee to 1
5921 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
5922 #endif /* defined(CONFIG_USER_ONLY) */
5926 static void gen_wrteei(DisasContext
*ctx
)
5928 #if defined(CONFIG_USER_ONLY)
5932 if (ctx
->opcode
& 0x00008000) {
5933 tcg_gen_ori_tl(cpu_msr
, cpu_msr
, (1 << MSR_EE
));
5934 gen_ppc_maybe_interrupt(ctx
);
5935 /* Stop translation to have a chance to raise an exception */
5936 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
5938 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
5940 #endif /* defined(CONFIG_USER_ONLY) */
5943 /* PowerPC 440 specific instructions */
5946 static void gen_dlmzb(DisasContext
*ctx
)
5948 TCGv_i32 t0
= tcg_constant_i32(Rc(ctx
->opcode
));
5949 gen_helper_dlmzb(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
5950 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
5953 /* mbar replaces eieio on 440 */
5954 static void gen_mbar(DisasContext
*ctx
)
5956 /* interpreted as no-op */
5959 /* msync replaces sync on 440 */
5960 static void gen_msync_4xx(DisasContext
*ctx
)
5962 /* Only e500 seems to treat reserved bits as invalid */
5963 if ((ctx
->insns_flags2
& PPC2_BOOKE206
) &&
5964 (ctx
->opcode
& 0x03FFF801)) {
5965 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5967 /* otherwise interpreted as no-op */
5971 static void gen_icbt_440(DisasContext
*ctx
)
5974 * interpreted as no-op
5975 * XXX: specification say this is treated as a load by the MMU but
5976 * does not generate any exception
5980 #if defined(TARGET_PPC64)
5981 static void gen_maddld(DisasContext
*ctx
)
5983 TCGv_i64 t1
= tcg_temp_new_i64();
5985 tcg_gen_mul_i64(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
5986 tcg_gen_add_i64(cpu_gpr
[rD(ctx
->opcode
)], t1
, cpu_gpr
[rC(ctx
->opcode
)]);
5989 /* maddhd maddhdu */
5990 static void gen_maddhd_maddhdu(DisasContext
*ctx
)
5992 TCGv_i64 lo
= tcg_temp_new_i64();
5993 TCGv_i64 hi
= tcg_temp_new_i64();
5994 TCGv_i64 t1
= tcg_temp_new_i64();
5996 if (Rc(ctx
->opcode
)) {
5997 tcg_gen_mulu2_i64(lo
, hi
, cpu_gpr
[rA(ctx
->opcode
)],
5998 cpu_gpr
[rB(ctx
->opcode
)]);
5999 tcg_gen_movi_i64(t1
, 0);
6001 tcg_gen_muls2_i64(lo
, hi
, cpu_gpr
[rA(ctx
->opcode
)],
6002 cpu_gpr
[rB(ctx
->opcode
)]);
6003 tcg_gen_sari_i64(t1
, cpu_gpr
[rC(ctx
->opcode
)], 63);
6005 tcg_gen_add2_i64(t1
, cpu_gpr
[rD(ctx
->opcode
)], lo
, hi
,
6006 cpu_gpr
[rC(ctx
->opcode
)], t1
);
6008 #endif /* defined(TARGET_PPC64) */
6010 static void gen_tbegin(DisasContext
*ctx
)
6012 if (unlikely(!ctx
->tm_enabled
)) {
6013 gen_exception_err(ctx
, POWERPC_EXCP_FU
, FSCR_IC_TM
);
6016 gen_helper_tbegin(cpu_env
);
6019 #define GEN_TM_NOOP(name) \
6020 static inline void gen_##name(DisasContext *ctx) \
6022 if (unlikely(!ctx->tm_enabled)) { \
6023 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
6027 * Because tbegin always fails in QEMU, these user \
6028 * space instructions all have a simple implementation: \
6030 * CR[0] = 0b0 || MSR[TS] || 0b0 \
6031 * = 0b0 || 0b00 || 0b0 \
6033 tcg_gen_movi_i32(cpu_crf[0], 0); \
6037 GEN_TM_NOOP(tabort
);
6038 GEN_TM_NOOP(tabortwc
);
6039 GEN_TM_NOOP(tabortwci
);
6040 GEN_TM_NOOP(tabortdc
);
6041 GEN_TM_NOOP(tabortdci
);
6044 static inline void gen_cp_abort(DisasContext
*ctx
)
6049 #define GEN_CP_PASTE_NOOP(name) \
6050 static inline void gen_##name(DisasContext *ctx) \
6053 * Generate invalid exception until we have an \
6054 * implementation of the copy paste facility \
6059 GEN_CP_PASTE_NOOP(copy
)
6060 GEN_CP_PASTE_NOOP(paste
)
6062 static void gen_tcheck(DisasContext
*ctx
)
6064 if (unlikely(!ctx
->tm_enabled
)) {
6065 gen_exception_err(ctx
, POWERPC_EXCP_FU
, FSCR_IC_TM
);
6069 * Because tbegin always fails, the tcheck implementation is
6072 * CR[CRF] = TDOOMED || MSR[TS] || 0b0
6073 * = 0b1 || 0b00 || 0b0
6075 tcg_gen_movi_i32(cpu_crf
[crfD(ctx
->opcode
)], 0x8);
6078 #if defined(CONFIG_USER_ONLY)
6079 #define GEN_TM_PRIV_NOOP(name) \
6080 static inline void gen_##name(DisasContext *ctx) \
6082 gen_priv_opc(ctx); \
6087 #define GEN_TM_PRIV_NOOP(name) \
6088 static inline void gen_##name(DisasContext *ctx) \
6091 if (unlikely(!ctx->tm_enabled)) { \
6092 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
6096 * Because tbegin always fails, the implementation is \
6099 * CR[0] = 0b0 || MSR[TS] || 0b0 \
6100 * = 0b0 || 0b00 | 0b0 \
6102 tcg_gen_movi_i32(cpu_crf[0], 0); \
6107 GEN_TM_PRIV_NOOP(treclaim
);
6108 GEN_TM_PRIV_NOOP(trechkpt
);
6110 static inline void get_fpr(TCGv_i64 dst
, int regno
)
6112 tcg_gen_ld_i64(dst
, cpu_env
, fpr_offset(regno
));
6115 static inline void set_fpr(int regno
, TCGv_i64 src
)
6117 tcg_gen_st_i64(src
, cpu_env
, fpr_offset(regno
));
6119 * Before PowerISA v3.1 the result of doubleword 1 of the VSR
6120 * corresponding to the target FPR was undefined. However,
6121 * most (if not all) real hardware were setting the result to 0.
6122 * Starting at ISA v3.1, the result for doubleword 1 is now defined
6125 tcg_gen_st_i64(tcg_constant_i64(0), cpu_env
, vsr64_offset(regno
, false));
6128 static inline void get_avr64(TCGv_i64 dst
, int regno
, bool high
)
6130 tcg_gen_ld_i64(dst
, cpu_env
, avr64_offset(regno
, high
));
6133 static inline void set_avr64(int regno
, TCGv_i64 src
, bool high
)
6135 tcg_gen_st_i64(src
, cpu_env
, avr64_offset(regno
, high
));
6139 * Helpers for decodetree used by !function for decoding arguments.
6141 static int times_2(DisasContext
*ctx
, int x
)
6146 static int times_4(DisasContext
*ctx
, int x
)
6151 static int times_16(DisasContext
*ctx
, int x
)
6156 static int64_t dw_compose_ea(DisasContext
*ctx
, int x
)
6158 return deposit64(0xfffffffffffffe00, 3, 6, x
);
6162 * Helpers for trans_* functions to check for specific insns flags.
6163 * Use token pasting to ensure that we use the proper flag with the
6166 #define REQUIRE_INSNS_FLAGS(CTX, NAME) \
6168 if (((CTX)->insns_flags & PPC_##NAME) == 0) { \
6173 #define REQUIRE_INSNS_FLAGS2(CTX, NAME) \
6175 if (((CTX)->insns_flags2 & PPC2_##NAME) == 0) { \
6180 /* Then special-case the check for 64-bit so that we elide code for ppc32. */
6181 #if TARGET_LONG_BITS == 32
6182 # define REQUIRE_64BIT(CTX) return false
6184 # define REQUIRE_64BIT(CTX) REQUIRE_INSNS_FLAGS(CTX, 64B)
6187 #define REQUIRE_VECTOR(CTX) \
6189 if (unlikely(!(CTX)->altivec_enabled)) { \
6190 gen_exception((CTX), POWERPC_EXCP_VPU); \
6195 #define REQUIRE_VSX(CTX) \
6197 if (unlikely(!(CTX)->vsx_enabled)) { \
6198 gen_exception((CTX), POWERPC_EXCP_VSXU); \
6203 #define REQUIRE_FPU(ctx) \
6205 if (unlikely(!(ctx)->fpu_enabled)) { \
6206 gen_exception((ctx), POWERPC_EXCP_FPU); \
6211 #if !defined(CONFIG_USER_ONLY)
6212 #define REQUIRE_SV(CTX) \
6214 if (unlikely((CTX)->pr)) { \
6215 gen_priv_opc(CTX); \
6220 #define REQUIRE_HV(CTX) \
6222 if (unlikely((CTX)->pr || !(CTX)->hv)) { \
6223 gen_priv_opc(CTX); \
6228 #define REQUIRE_SV(CTX) do { gen_priv_opc(CTX); return true; } while (0)
6229 #define REQUIRE_HV(CTX) do { gen_priv_opc(CTX); return true; } while (0)
6233 * Helpers for implementing sets of trans_* functions.
6234 * Defer the implementation of NAME to FUNC, with optional extra arguments.
6236 #define TRANS(NAME, FUNC, ...) \
6237 static bool trans_##NAME(DisasContext *ctx, arg_##NAME *a) \
6238 { return FUNC(ctx, a, __VA_ARGS__); }
6239 #define TRANS_FLAGS(FLAGS, NAME, FUNC, ...) \
6240 static bool trans_##NAME(DisasContext *ctx, arg_##NAME *a) \
6242 REQUIRE_INSNS_FLAGS(ctx, FLAGS); \
6243 return FUNC(ctx, a, __VA_ARGS__); \
6245 #define TRANS_FLAGS2(FLAGS2, NAME, FUNC, ...) \
6246 static bool trans_##NAME(DisasContext *ctx, arg_##NAME *a) \
6248 REQUIRE_INSNS_FLAGS2(ctx, FLAGS2); \
6249 return FUNC(ctx, a, __VA_ARGS__); \
6252 #define TRANS64(NAME, FUNC, ...) \
6253 static bool trans_##NAME(DisasContext *ctx, arg_##NAME *a) \
6254 { REQUIRE_64BIT(ctx); return FUNC(ctx, a, __VA_ARGS__); }
6255 #define TRANS64_FLAGS2(FLAGS2, NAME, FUNC, ...) \
6256 static bool trans_##NAME(DisasContext *ctx, arg_##NAME *a) \
6258 REQUIRE_64BIT(ctx); \
6259 REQUIRE_INSNS_FLAGS2(ctx, FLAGS2); \
6260 return FUNC(ctx, a, __VA_ARGS__); \
6263 /* TODO: More TRANS* helpers for extra insn_flags checks. */
6266 #include "decode-insn32.c.inc"
6267 #include "decode-insn64.c.inc"
6268 #include "power8-pmu-regs.c.inc"
6271 * Incorporate CIA into the constant when R=1.
6272 * Validate that when R=1, RA=0.
6274 static bool resolve_PLS_D(DisasContext
*ctx
, arg_D
*d
, arg_PLS_D
*a
)
6280 if (unlikely(a
->ra
!= 0)) {
6289 #include "translate/fixedpoint-impl.c.inc"
6291 #include "translate/fp-impl.c.inc"
6293 #include "translate/vmx-impl.c.inc"
6295 #include "translate/vsx-impl.c.inc"
6297 #include "translate/dfp-impl.c.inc"
6299 #include "translate/spe-impl.c.inc"
6301 #include "translate/branch-impl.c.inc"
6303 #include "translate/processor-ctrl-impl.c.inc"
6305 #include "translate/storage-ctrl-impl.c.inc"
6308 static void gen_dform39(DisasContext
*ctx
)
6310 if ((ctx
->opcode
& 0x3) == 0) {
6311 if (ctx
->insns_flags2
& PPC2_ISA205
) {
6312 return gen_lfdp(ctx
);
6315 return gen_invalid(ctx
);
6319 static void gen_dform3D(DisasContext
*ctx
)
6321 if ((ctx
->opcode
& 3) == 0) { /* DS-FORM */
6323 if (ctx
->insns_flags2
& PPC2_ISA205
) {
6324 return gen_stfdp(ctx
);
6327 return gen_invalid(ctx
);
6330 #if defined(TARGET_PPC64)
6332 static void gen_brd(DisasContext
*ctx
)
6334 tcg_gen_bswap64_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
6338 static void gen_brw(DisasContext
*ctx
)
6340 tcg_gen_bswap64_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
6341 tcg_gen_rotli_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 32);
6346 static void gen_brh(DisasContext
*ctx
)
6348 TCGv_i64 mask
= tcg_constant_i64(0x00ff00ff00ff00ffull
);
6349 TCGv_i64 t1
= tcg_temp_new_i64();
6350 TCGv_i64 t2
= tcg_temp_new_i64();
6352 tcg_gen_shri_i64(t1
, cpu_gpr
[rS(ctx
->opcode
)], 8);
6353 tcg_gen_and_i64(t2
, t1
, mask
);
6354 tcg_gen_and_i64(t1
, cpu_gpr
[rS(ctx
->opcode
)], mask
);
6355 tcg_gen_shli_i64(t1
, t1
, 8);
6356 tcg_gen_or_i64(cpu_gpr
[rA(ctx
->opcode
)], t1
, t2
);
6360 static opcode_t opcodes
[] = {
6361 #if defined(TARGET_PPC64)
6362 GEN_HANDLER_E(brd
, 0x1F, 0x1B, 0x05, 0x0000F801, PPC_NONE
, PPC2_ISA310
),
6363 GEN_HANDLER_E(brw
, 0x1F, 0x1B, 0x04, 0x0000F801, PPC_NONE
, PPC2_ISA310
),
6364 GEN_HANDLER_E(brh
, 0x1F, 0x1B, 0x06, 0x0000F801, PPC_NONE
, PPC2_ISA310
),
6366 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
),
6367 #if defined(TARGET_PPC64)
6368 GEN_HANDLER_E(cmpeqb
, 0x1F, 0x00, 0x07, 0x00600000, PPC_NONE
, PPC2_ISA300
),
6370 GEN_HANDLER_E(cmpb
, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE
, PPC2_ISA205
),
6371 GEN_HANDLER_E(cmprb
, 0x1F, 0x00, 0x06, 0x00400001, PPC_NONE
, PPC2_ISA300
),
6372 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
),
6373 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6374 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6375 GEN_HANDLER(mulhw
, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER
),
6376 GEN_HANDLER(mulhwu
, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER
),
6377 GEN_HANDLER(mullw
, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER
),
6378 GEN_HANDLER(mullwo
, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER
),
6379 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6380 #if defined(TARGET_PPC64)
6381 GEN_HANDLER(mulld
, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B
),
6383 GEN_HANDLER(neg
, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER
),
6384 GEN_HANDLER(nego
, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER
),
6385 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6386 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6387 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6388 GEN_HANDLER(cntlzw
, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER
),
6389 GEN_HANDLER_E(cnttzw
, 0x1F, 0x1A, 0x10, 0x00000000, PPC_NONE
, PPC2_ISA300
),
6390 GEN_HANDLER_E(copy
, 0x1F, 0x06, 0x18, 0x03C00001, PPC_NONE
, PPC2_ISA300
),
6391 GEN_HANDLER_E(cp_abort
, 0x1F, 0x06, 0x1A, 0x03FFF801, PPC_NONE
, PPC2_ISA300
),
6392 GEN_HANDLER_E(paste
, 0x1F, 0x06, 0x1C, 0x03C00000, PPC_NONE
, PPC2_ISA300
),
6393 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
),
6394 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
),
6395 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6396 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6397 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6398 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6399 GEN_HANDLER(popcntb
, 0x1F, 0x1A, 0x03, 0x0000F801, PPC_POPCNTB
),
6400 GEN_HANDLER(popcntw
, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD
),
6401 GEN_HANDLER_E(prtyw
, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
6402 #if defined(TARGET_PPC64)
6403 GEN_HANDLER(popcntd
, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD
),
6404 GEN_HANDLER(cntlzd
, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B
),
6405 GEN_HANDLER_E(cnttzd
, 0x1F, 0x1A, 0x11, 0x00000000, PPC_NONE
, PPC2_ISA300
),
6406 GEN_HANDLER_E(darn
, 0x1F, 0x13, 0x17, 0x001CF801, PPC_NONE
, PPC2_ISA300
),
6407 GEN_HANDLER_E(prtyd
, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
6408 GEN_HANDLER_E(bpermd
, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE
, PPC2_PERM_ISA206
),
6410 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6411 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6412 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6413 GEN_HANDLER(slw
, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER
),
6414 GEN_HANDLER(sraw
, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER
),
6415 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
),
6416 GEN_HANDLER(srw
, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER
),
6417 #if defined(TARGET_PPC64)
6418 GEN_HANDLER(sld
, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B
),
6419 GEN_HANDLER(srad
, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B
),
6420 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
),
6421 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
),
6422 GEN_HANDLER(srd
, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B
),
6423 GEN_HANDLER2_E(extswsli0
, "extswsli", 0x1F, 0x1A, 0x1B, 0x00000000,
6424 PPC_NONE
, PPC2_ISA300
),
6425 GEN_HANDLER2_E(extswsli1
, "extswsli", 0x1F, 0x1B, 0x1B, 0x00000000,
6426 PPC_NONE
, PPC2_ISA300
),
6428 /* handles lfdp, lxsd, lxssp */
6429 GEN_HANDLER_E(dform39
, 0x39, 0xFF, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA205
),
6430 /* handles stfdp, stxsd, stxssp */
6431 GEN_HANDLER_E(dform3D
, 0x3D, 0xFF, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA205
),
6432 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6433 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
6434 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
),
6435 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
),
6436 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
),
6437 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
),
6438 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x01FFF801, PPC_MEM_EIEIO
),
6439 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
),
6440 GEN_HANDLER_E(lbarx
, 0x1F, 0x14, 0x01, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
6441 GEN_HANDLER_E(lharx
, 0x1F, 0x14, 0x03, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
6442 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES
),
6443 GEN_HANDLER_E(lwat
, 0x1F, 0x06, 0x12, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6444 GEN_HANDLER_E(stwat
, 0x1F, 0x06, 0x16, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6445 GEN_HANDLER_E(stbcx_
, 0x1F, 0x16, 0x15, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
6446 GEN_HANDLER_E(sthcx_
, 0x1F, 0x16, 0x16, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
6447 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
),
6448 #if defined(TARGET_PPC64)
6449 GEN_HANDLER_E(ldat
, 0x1F, 0x06, 0x13, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6450 GEN_HANDLER_E(stdat
, 0x1F, 0x06, 0x17, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6451 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B
),
6452 GEN_HANDLER_E(lqarx
, 0x1F, 0x14, 0x08, 0, PPC_NONE
, PPC2_LSQ_ISA207
),
6453 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
),
6454 GEN_HANDLER_E(stqcx_
, 0x1F, 0x16, 0x05, 0, PPC_NONE
, PPC2_LSQ_ISA207
),
6456 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
),
6457 /* ISA v3.0 changed the extended opcode from 62 to 30 */
6458 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x039FF801, PPC_WAIT
),
6459 GEN_HANDLER_E(wait
, 0x1F, 0x1E, 0x00, 0x039CF801, PPC_NONE
, PPC2_ISA300
),
6460 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
6461 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
6462 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
),
6463 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
),
6464 GEN_HANDLER_E(bctar
, 0x13, 0x10, 0x11, 0x0000E000, PPC_NONE
, PPC2_BCTAR_ISA207
),
6465 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
),
6466 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
),
6467 #if defined(TARGET_PPC64)
6468 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
),
6469 #if !defined(CONFIG_USER_ONLY)
6470 /* Top bit of opc2 corresponds with low bit of LEV, so use two handlers */
6471 GEN_HANDLER_E(scv
, 0x11, 0x10, 0xFF, 0x03FFF01E, PPC_NONE
, PPC2_ISA300
),
6472 GEN_HANDLER_E(scv
, 0x11, 0x00, 0xFF, 0x03FFF01E, PPC_NONE
, PPC2_ISA300
),
6473 GEN_HANDLER_E(rfscv
, 0x13, 0x12, 0x02, 0x03FF8001, PPC_NONE
, PPC2_ISA300
),
6475 GEN_HANDLER_E(stop
, 0x13, 0x12, 0x0b, 0x03FFF801, PPC_NONE
, PPC2_ISA300
),
6476 GEN_HANDLER_E(doze
, 0x13, 0x12, 0x0c, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
6477 GEN_HANDLER_E(nap
, 0x13, 0x12, 0x0d, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
6478 GEN_HANDLER_E(sleep
, 0x13, 0x12, 0x0e, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
6479 GEN_HANDLER_E(rvwinkle
, 0x13, 0x12, 0x0f, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
6480 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
),
6482 /* Top bit of opc2 corresponds with low bit of LEV, so use two handlers */
6483 GEN_HANDLER(sc
, 0x11, 0x11, 0xFF, 0x03FFF01D, PPC_FLOW
),
6484 GEN_HANDLER(sc
, 0x11, 0x01, 0xFF, 0x03FFF01D, PPC_FLOW
),
6485 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
),
6486 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
6487 #if defined(TARGET_PPC64)
6488 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
),
6489 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
),
6491 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
),
6492 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
),
6493 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
),
6494 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
),
6495 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
),
6496 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
),
6497 #if defined(TARGET_PPC64)
6498 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
),
6499 GEN_HANDLER_E(setb
, 0x1F, 0x00, 0x04, 0x0003F801, PPC_NONE
, PPC2_ISA300
),
6500 GEN_HANDLER_E(mcrxrx
, 0x1F, 0x00, 0x12, 0x007FF801, PPC_NONE
, PPC2_ISA300
),
6502 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001EF801, PPC_MISC
),
6503 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000000, PPC_MISC
),
6504 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
),
6505 GEN_HANDLER_E(dcbfep
, 0x1F, 0x1F, 0x03, 0x03C00001, PPC_NONE
, PPC2_BOOKE206
),
6506 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
),
6507 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
),
6508 GEN_HANDLER_E(dcbstep
, 0x1F, 0x1F, 0x01, 0x03E00001, PPC_NONE
, PPC2_BOOKE206
),
6509 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE
),
6510 GEN_HANDLER_E(dcbtep
, 0x1F, 0x1F, 0x09, 0x00000001, PPC_NONE
, PPC2_BOOKE206
),
6511 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE
),
6512 GEN_HANDLER_E(dcbtstep
, 0x1F, 0x1F, 0x07, 0x00000001, PPC_NONE
, PPC2_BOOKE206
),
6513 GEN_HANDLER_E(dcbtls
, 0x1F, 0x06, 0x05, 0x02000001, PPC_BOOKE
, PPC2_BOOKE206
),
6514 GEN_HANDLER_E(dcblc
, 0x1F, 0x06, 0x0c, 0x02000001, PPC_BOOKE
, PPC2_BOOKE206
),
6515 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ
),
6516 GEN_HANDLER_E(dcbzep
, 0x1F, 0x1F, 0x1F, 0x03C00001, PPC_NONE
, PPC2_BOOKE206
),
6517 GEN_HANDLER(dst
, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC
),
6518 GEN_HANDLER(dstst
, 0x1F, 0x16, 0x0B, 0x01800001, PPC_ALTIVEC
),
6519 GEN_HANDLER(dss
, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC
),
6520 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
),
6521 GEN_HANDLER_E(icbiep
, 0x1F, 0x1F, 0x1E, 0x03E00001, PPC_NONE
, PPC2_BOOKE206
),
6522 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
),
6523 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
),
6524 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
),
6525 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
),
6526 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
),
6527 #if defined(TARGET_PPC64)
6528 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
),
6529 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
6531 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
),
6532 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
6535 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
),
6537 * XXX Those instructions will need to be handled differently for
6538 * different ISA versions
6540 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
),
6541 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
),
6542 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
),
6543 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
),
6544 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
),
6545 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
),
6546 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
),
6547 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
),
6548 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
),
6549 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
),
6550 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
),
6551 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
),
6552 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
),
6553 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
),
6554 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
),
6555 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
),
6556 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
),
6557 GEN_HANDLER_E(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
, PPC2_BOOKE206
),
6558 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
),
6559 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
),
6560 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
),
6561 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
),
6562 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
),
6563 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
),
6564 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
),
6565 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
),
6566 GEN_HANDLER2_E(tlbre_booke206
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
6567 PPC_NONE
, PPC2_BOOKE206
),
6568 GEN_HANDLER2_E(tlbsx_booke206
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
6569 PPC_NONE
, PPC2_BOOKE206
),
6570 GEN_HANDLER2_E(tlbwe_booke206
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
6571 PPC_NONE
, PPC2_BOOKE206
),
6572 GEN_HANDLER2_E(tlbivax_booke206
, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
6573 PPC_NONE
, PPC2_BOOKE206
),
6574 GEN_HANDLER2_E(tlbilx_booke206
, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
6575 PPC_NONE
, PPC2_BOOKE206
),
6576 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
),
6577 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE
),
6578 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
),
6579 GEN_HANDLER_E(mbar
, 0x1F, 0x16, 0x1a, 0x001FF801,
6580 PPC_BOOKE
, PPC2_BOOKE206
),
6581 GEN_HANDLER(msync_4xx
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_BOOKE
),
6582 GEN_HANDLER2_E(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
6583 PPC_BOOKE
, PPC2_BOOKE206
),
6584 GEN_HANDLER2(icbt_440
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001,
6586 GEN_HANDLER(lvsl
, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC
),
6587 GEN_HANDLER(lvsr
, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC
),
6588 GEN_HANDLER(mfvscr
, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC
),
6589 GEN_HANDLER(mtvscr
, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC
),
6590 #if defined(TARGET_PPC64)
6591 GEN_HANDLER_E(maddhd_maddhdu
, 0x04, 0x18, 0xFF, 0x00000000, PPC_NONE
,
6593 GEN_HANDLER_E(maddld
, 0x04, 0x19, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA300
),
6596 #undef GEN_INT_ARITH_ADD
6597 #undef GEN_INT_ARITH_ADD_CONST
6598 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
6599 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
6600 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
6601 add_ca, compute_ca, compute_ov) \
6602 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
6603 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
6604 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
6605 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
6606 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
6607 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
6608 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
6609 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
6610 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
6611 GEN_HANDLER_E(addex
, 0x1F, 0x0A, 0x05, 0x00000000, PPC_NONE
, PPC2_ISA300
),
6612 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
6613 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
6615 #undef GEN_INT_ARITH_DIVW
6616 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
6617 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
6618 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0),
6619 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1),
6620 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0),
6621 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1),
6622 GEN_HANDLER_E(divwe
, 0x1F, 0x0B, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6623 GEN_HANDLER_E(divweo
, 0x1F, 0x0B, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6624 GEN_HANDLER_E(divweu
, 0x1F, 0x0B, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6625 GEN_HANDLER_E(divweuo
, 0x1F, 0x0B, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6626 GEN_HANDLER_E(modsw
, 0x1F, 0x0B, 0x18, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6627 GEN_HANDLER_E(moduw
, 0x1F, 0x0B, 0x08, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6629 #if defined(TARGET_PPC64)
6630 #undef GEN_INT_ARITH_DIVD
6631 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
6632 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
6633 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0),
6634 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1),
6635 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0),
6636 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1),
6638 GEN_HANDLER_E(divdeu
, 0x1F, 0x09, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6639 GEN_HANDLER_E(divdeuo
, 0x1F, 0x09, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6640 GEN_HANDLER_E(divde
, 0x1F, 0x09, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6641 GEN_HANDLER_E(divdeo
, 0x1F, 0x09, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
6642 GEN_HANDLER_E(modsd
, 0x1F, 0x09, 0x18, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6643 GEN_HANDLER_E(modud
, 0x1F, 0x09, 0x08, 0x00000001, PPC_NONE
, PPC2_ISA300
),
6645 #undef GEN_INT_ARITH_MUL_HELPER
6646 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
6647 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
6648 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00),
6649 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02),
6650 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17),
6653 #undef GEN_INT_ARITH_SUBF
6654 #undef GEN_INT_ARITH_SUBF_CONST
6655 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
6656 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
6657 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
6658 add_ca, compute_ca, compute_ov) \
6659 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
6660 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
6661 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
6662 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
6663 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
6664 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
6665 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
6666 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
6667 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
6668 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
6669 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
6673 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
6674 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
6675 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
6676 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
6677 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
),
6678 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
),
6679 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
),
6680 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
),
6681 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
),
6682 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
),
6683 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
),
6684 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
),
6685 #if defined(TARGET_PPC64)
6686 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
),
6689 #if defined(TARGET_PPC64)
6692 #define GEN_PPC64_R2(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 | 0x10, 0xFF, 0x00000000, \
6696 #define GEN_PPC64_R4(name, opc1, opc2) \
6697 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
6698 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
6700 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
6702 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
6704 GEN_PPC64_R4(rldicl
, 0x1E, 0x00),
6705 GEN_PPC64_R4(rldicr
, 0x1E, 0x02),
6706 GEN_PPC64_R4(rldic
, 0x1E, 0x04),
6707 GEN_PPC64_R2(rldcl
, 0x1E, 0x08),
6708 GEN_PPC64_R2(rldcr
, 0x1E, 0x09),
6709 GEN_PPC64_R4(rldimi
, 0x1E, 0x06),
6713 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2, chk) \
6714 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
6716 #if defined(TARGET_PPC64)
6717 GEN_LDX_E(ldbr
, ld64ur_i64
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
, CHK_NONE
)
6719 /* HV/P7 and later only */
6720 GEN_LDX_HVRM(ldcix
, ld64_i64
, 0x15, 0x1b, PPC_CILDST
)
6721 GEN_LDX_HVRM(lwzcix
, ld32u
, 0x15, 0x18, PPC_CILDST
)
6722 GEN_LDX_HVRM(lhzcix
, ld16u
, 0x15, 0x19, PPC_CILDST
)
6723 GEN_LDX_HVRM(lbzcix
, ld8u
, 0x15, 0x1a, PPC_CILDST
)
6725 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
)
6726 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
)
6728 /* External PID based load */
6730 #define GEN_LDEPX(name, ldop, opc2, opc3) \
6731 GEN_HANDLER_E(name##epx, 0x1F, opc2, opc3, \
6732 0x00000001, PPC_NONE, PPC2_BOOKE206),
6734 GEN_LDEPX(lb
, DEF_MEMOP(MO_UB
), 0x1F, 0x02)
6735 GEN_LDEPX(lh
, DEF_MEMOP(MO_UW
), 0x1F, 0x08)
6736 GEN_LDEPX(lw
, DEF_MEMOP(MO_UL
), 0x1F, 0x00)
6737 #if defined(TARGET_PPC64)
6738 GEN_LDEPX(ld
, DEF_MEMOP(MO_UQ
), 0x1D, 0x00)
6742 #define GEN_STX_E(name, stop, opc2, opc3, type, type2, chk) \
6743 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000000, type, type2),
6745 #if defined(TARGET_PPC64)
6746 GEN_STX_E(stdbr
, st64r_i64
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
, CHK_NONE
)
6747 GEN_STX_HVRM(stdcix
, st64_i64
, 0x15, 0x1f, PPC_CILDST
)
6748 GEN_STX_HVRM(stwcix
, st32
, 0x15, 0x1c, PPC_CILDST
)
6749 GEN_STX_HVRM(sthcix
, st16
, 0x15, 0x1d, PPC_CILDST
)
6750 GEN_STX_HVRM(stbcix
, st8
, 0x15, 0x1e, PPC_CILDST
)
6752 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
)
6753 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
)
6756 #define GEN_STEPX(name, ldop, opc2, opc3) \
6757 GEN_HANDLER_E(name##epx, 0x1F, opc2, opc3, \
6758 0x00000001, PPC_NONE, PPC2_BOOKE206),
6760 GEN_STEPX(stb
, DEF_MEMOP(MO_UB
), 0x1F, 0x06)
6761 GEN_STEPX(sth
, DEF_MEMOP(MO_UW
), 0x1F, 0x0C)
6762 GEN_STEPX(stw
, DEF_MEMOP(MO_UL
), 0x1F, 0x04)
6763 #if defined(TARGET_PPC64)
6764 GEN_STEPX(std
, DEF_MEMOP(MO_UQ
), 0x1D, 0x04)
6768 #define GEN_CRLOGIC(name, tcg_op, opc) \
6769 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
6770 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08),
6771 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04),
6772 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09),
6773 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07),
6774 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01),
6775 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E),
6776 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D),
6777 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06),
6779 #undef GEN_MAC_HANDLER
6780 #define GEN_MAC_HANDLER(name, opc2, opc3) \
6781 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
6782 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05),
6783 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15),
6784 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07),
6785 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17),
6786 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06),
6787 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16),
6788 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04),
6789 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14),
6790 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01),
6791 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11),
6792 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03),
6793 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13),
6794 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02),
6795 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12),
6796 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00),
6797 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10),
6798 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D),
6799 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D),
6800 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F),
6801 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F),
6802 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C),
6803 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C),
6804 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E),
6805 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E),
6806 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05),
6807 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15),
6808 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07),
6809 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17),
6810 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01),
6811 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11),
6812 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03),
6813 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13),
6814 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D),
6815 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D),
6816 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F),
6817 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F),
6818 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05),
6819 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04),
6820 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01),
6821 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00),
6822 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D),
6823 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C),
6825 GEN_HANDLER2_E(tbegin
, "tbegin", 0x1F, 0x0E, 0x14, 0x01DFF800, \
6827 GEN_HANDLER2_E(tend
, "tend", 0x1F, 0x0E, 0x15, 0x01FFF800, \
6829 GEN_HANDLER2_E(tabort
, "tabort", 0x1F, 0x0E, 0x1C, 0x03E0F800, \
6831 GEN_HANDLER2_E(tabortwc
, "tabortwc", 0x1F, 0x0E, 0x18, 0x00000000, \
6833 GEN_HANDLER2_E(tabortwci
, "tabortwci", 0x1F, 0x0E, 0x1A, 0x00000000, \
6835 GEN_HANDLER2_E(tabortdc
, "tabortdc", 0x1F, 0x0E, 0x19, 0x00000000, \
6837 GEN_HANDLER2_E(tabortdci
, "tabortdci", 0x1F, 0x0E, 0x1B, 0x00000000, \
6839 GEN_HANDLER2_E(tsr
, "tsr", 0x1F, 0x0E, 0x17, 0x03DFF800, \
6841 GEN_HANDLER2_E(tcheck
, "tcheck", 0x1F, 0x0E, 0x16, 0x007FF800, \
6843 GEN_HANDLER2_E(treclaim
, "treclaim", 0x1F, 0x0E, 0x1D, 0x03E0F800, \
6845 GEN_HANDLER2_E(trechkpt
, "trechkpt", 0x1F, 0x0E, 0x1F, 0x03FFF800, \
6848 #include "translate/fp-ops.c.inc"
6850 #include "translate/vmx-ops.c.inc"
6852 #include "translate/vsx-ops.c.inc"
6854 #include "translate/spe-ops.c.inc"
6857 /*****************************************************************************/
6860 PPC_DIRECT
= 0, /* Opcode routine */
6861 PPC_INDIRECT
= 1, /* Indirect opcode table */
6864 #define PPC_OPCODE_MASK 0x3
6866 static inline int is_indirect_opcode(void *handler
)
6868 return ((uintptr_t)handler
& PPC_OPCODE_MASK
) == PPC_INDIRECT
;
6871 static inline opc_handler_t
**ind_table(void *handler
)
6873 return (opc_handler_t
**)((uintptr_t)handler
& ~PPC_OPCODE_MASK
);
6876 /* Instruction table creation */
6877 /* Opcodes tables creation */
6878 static void fill_new_table(opc_handler_t
**table
, int len
)
6882 for (i
= 0; i
< len
; i
++) {
6883 table
[i
] = &invalid_handler
;
6887 static int create_new_table(opc_handler_t
**table
, unsigned char idx
)
6889 opc_handler_t
**tmp
;
6891 tmp
= g_new(opc_handler_t
*, PPC_CPU_INDIRECT_OPCODES_LEN
);
6892 fill_new_table(tmp
, PPC_CPU_INDIRECT_OPCODES_LEN
);
6893 table
[idx
] = (opc_handler_t
*)((uintptr_t)tmp
| PPC_INDIRECT
);
6898 static int insert_in_table(opc_handler_t
**table
, unsigned char idx
,
6899 opc_handler_t
*handler
)
6901 if (table
[idx
] != &invalid_handler
) {
6904 table
[idx
] = handler
;
6909 static int register_direct_insn(opc_handler_t
**ppc_opcodes
,
6910 unsigned char idx
, opc_handler_t
*handler
)
6912 if (insert_in_table(ppc_opcodes
, idx
, handler
) < 0) {
6913 printf("*** ERROR: opcode %02x already assigned in main "
6914 "opcode table\n", idx
);
6921 static int register_ind_in_table(opc_handler_t
**table
,
6922 unsigned char idx1
, unsigned char idx2
,
6923 opc_handler_t
*handler
)
6925 if (table
[idx1
] == &invalid_handler
) {
6926 if (create_new_table(table
, idx1
) < 0) {
6927 printf("*** ERROR: unable to create indirect table "
6928 "idx=%02x\n", idx1
);
6932 if (!is_indirect_opcode(table
[idx1
])) {
6933 printf("*** ERROR: idx %02x already assigned to a direct "
6938 if (handler
!= NULL
&&
6939 insert_in_table(ind_table(table
[idx1
]), idx2
, handler
) < 0) {
6940 printf("*** ERROR: opcode %02x already assigned in "
6941 "opcode table %02x\n", idx2
, idx1
);
6948 static int register_ind_insn(opc_handler_t
**ppc_opcodes
,
6949 unsigned char idx1
, unsigned char idx2
,
6950 opc_handler_t
*handler
)
6952 return register_ind_in_table(ppc_opcodes
, idx1
, idx2
, handler
);
6955 static int register_dblind_insn(opc_handler_t
**ppc_opcodes
,
6956 unsigned char idx1
, unsigned char idx2
,
6957 unsigned char idx3
, opc_handler_t
*handler
)
6959 if (register_ind_in_table(ppc_opcodes
, idx1
, idx2
, NULL
) < 0) {
6960 printf("*** ERROR: unable to join indirect table idx "
6961 "[%02x-%02x]\n", idx1
, idx2
);
6964 if (register_ind_in_table(ind_table(ppc_opcodes
[idx1
]), idx2
, idx3
,
6966 printf("*** ERROR: unable to insert opcode "
6967 "[%02x-%02x-%02x]\n", idx1
, idx2
, idx3
);
6974 static int register_trplind_insn(opc_handler_t
**ppc_opcodes
,
6975 unsigned char idx1
, unsigned char idx2
,
6976 unsigned char idx3
, unsigned char idx4
,
6977 opc_handler_t
*handler
)
6979 opc_handler_t
**table
;
6981 if (register_ind_in_table(ppc_opcodes
, idx1
, idx2
, NULL
) < 0) {
6982 printf("*** ERROR: unable to join indirect table idx "
6983 "[%02x-%02x]\n", idx1
, idx2
);
6986 table
= ind_table(ppc_opcodes
[idx1
]);
6987 if (register_ind_in_table(table
, idx2
, idx3
, NULL
) < 0) {
6988 printf("*** ERROR: unable to join 2nd-level indirect table idx "
6989 "[%02x-%02x-%02x]\n", idx1
, idx2
, idx3
);
6992 table
= ind_table(table
[idx2
]);
6993 if (register_ind_in_table(table
, idx3
, idx4
, handler
) < 0) {
6994 printf("*** ERROR: unable to insert opcode "
6995 "[%02x-%02x-%02x-%02x]\n", idx1
, idx2
, idx3
, idx4
);
7000 static int register_insn(opc_handler_t
**ppc_opcodes
, opcode_t
*insn
)
7002 if (insn
->opc2
!= 0xFF) {
7003 if (insn
->opc3
!= 0xFF) {
7004 if (insn
->opc4
!= 0xFF) {
7005 if (register_trplind_insn(ppc_opcodes
, insn
->opc1
, insn
->opc2
,
7006 insn
->opc3
, insn
->opc4
,
7007 &insn
->handler
) < 0) {
7011 if (register_dblind_insn(ppc_opcodes
, insn
->opc1
, insn
->opc2
,
7012 insn
->opc3
, &insn
->handler
) < 0) {
7017 if (register_ind_insn(ppc_opcodes
, insn
->opc1
,
7018 insn
->opc2
, &insn
->handler
) < 0) {
7023 if (register_direct_insn(ppc_opcodes
, insn
->opc1
, &insn
->handler
) < 0) {
7031 static int test_opcode_table(opc_handler_t
**table
, int len
)
7035 for (i
= 0, count
= 0; i
< len
; i
++) {
7036 /* Consistency fixup */
7037 if (table
[i
] == NULL
) {
7038 table
[i
] = &invalid_handler
;
7040 if (table
[i
] != &invalid_handler
) {
7041 if (is_indirect_opcode(table
[i
])) {
7042 tmp
= test_opcode_table(ind_table(table
[i
]),
7043 PPC_CPU_INDIRECT_OPCODES_LEN
);
7046 table
[i
] = &invalid_handler
;
7059 static void fix_opcode_tables(opc_handler_t
**ppc_opcodes
)
7061 if (test_opcode_table(ppc_opcodes
, PPC_CPU_OPCODES_LEN
) == 0) {
7062 printf("*** WARNING: no opcode defined !\n");
7066 /*****************************************************************************/
7067 void create_ppc_opcodes(PowerPCCPU
*cpu
, Error
**errp
)
7069 PowerPCCPUClass
*pcc
= POWERPC_CPU_GET_CLASS(cpu
);
7072 fill_new_table(cpu
->opcodes
, PPC_CPU_OPCODES_LEN
);
7073 for (opc
= opcodes
; opc
< &opcodes
[ARRAY_SIZE(opcodes
)]; opc
++) {
7074 if (((opc
->handler
.type
& pcc
->insns_flags
) != 0) ||
7075 ((opc
->handler
.type2
& pcc
->insns_flags2
) != 0)) {
7076 if (register_insn(cpu
->opcodes
, opc
) < 0) {
7077 error_setg(errp
, "ERROR initializing PowerPC instruction "
7078 "0x%02x 0x%02x 0x%02x", opc
->opc1
, opc
->opc2
,
7084 fix_opcode_tables(cpu
->opcodes
);
7089 void destroy_ppc_opcodes(PowerPCCPU
*cpu
)
7091 opc_handler_t
**table
, **table_2
;
7094 for (i
= 0; i
< PPC_CPU_OPCODES_LEN
; i
++) {
7095 if (cpu
->opcodes
[i
] == &invalid_handler
) {
7098 if (is_indirect_opcode(cpu
->opcodes
[i
])) {
7099 table
= ind_table(cpu
->opcodes
[i
]);
7100 for (j
= 0; j
< PPC_CPU_INDIRECT_OPCODES_LEN
; j
++) {
7101 if (table
[j
] == &invalid_handler
) {
7104 if (is_indirect_opcode(table
[j
])) {
7105 table_2
= ind_table(table
[j
]);
7106 for (k
= 0; k
< PPC_CPU_INDIRECT_OPCODES_LEN
; k
++) {
7107 if (table_2
[k
] != &invalid_handler
&&
7108 is_indirect_opcode(table_2
[k
])) {
7109 g_free((opc_handler_t
*)((uintptr_t)table_2
[k
] &
7113 g_free((opc_handler_t
*)((uintptr_t)table
[j
] &
7117 g_free((opc_handler_t
*)((uintptr_t)cpu
->opcodes
[i
] &
7123 int ppc_fixup_cpu(PowerPCCPU
*cpu
)
7125 CPUPPCState
*env
= &cpu
->env
;
7128 * TCG doesn't (yet) emulate some groups of instructions that are
7129 * implemented on some otherwise supported CPUs (e.g. VSX and
7130 * decimal floating point instructions on POWER7). We remove
7131 * unsupported instruction groups from the cpu state's instruction
7132 * masks and hope the guest can cope. For at least the pseries
7133 * machine, the unavailability of these instructions can be
7134 * advertised to the guest via the device tree.
7136 if ((env
->insns_flags
& ~PPC_TCG_INSNS
)
7137 || (env
->insns_flags2
& ~PPC_TCG_INSNS2
)) {
7138 warn_report("Disabling some instructions which are not "
7139 "emulated by TCG (0x%" PRIx64
", 0x%" PRIx64
")",
7140 env
->insns_flags
& ~PPC_TCG_INSNS
,
7141 env
->insns_flags2
& ~PPC_TCG_INSNS2
);
7143 env
->insns_flags
&= PPC_TCG_INSNS
;
7144 env
->insns_flags2
&= PPC_TCG_INSNS2
;
7148 static bool decode_legacy(PowerPCCPU
*cpu
, DisasContext
*ctx
, uint32_t insn
)
7150 opc_handler_t
**table
, *handler
;
7155 LOG_DISAS("translate opcode %08x (%02x %02x %02x %02x) (%s)\n",
7156 insn
, opc1(insn
), opc2(insn
), opc3(insn
), opc4(insn
),
7157 ctx
->le_mode
? "little" : "big");
7159 table
= cpu
->opcodes
;
7160 handler
= table
[opc1(insn
)];
7161 if (is_indirect_opcode(handler
)) {
7162 table
= ind_table(handler
);
7163 handler
= table
[opc2(insn
)];
7164 if (is_indirect_opcode(handler
)) {
7165 table
= ind_table(handler
);
7166 handler
= table
[opc3(insn
)];
7167 if (is_indirect_opcode(handler
)) {
7168 table
= ind_table(handler
);
7169 handler
= table
[opc4(insn
)];
7174 /* Is opcode *REALLY* valid ? */
7175 if (unlikely(handler
->handler
== &gen_invalid
)) {
7176 qemu_log_mask(LOG_GUEST_ERROR
, "invalid/unsupported opcode: "
7177 "%02x - %02x - %02x - %02x (%08x) "
7179 opc1(insn
), opc2(insn
), opc3(insn
), opc4(insn
),
7184 if (unlikely(handler
->type
& (PPC_SPE
| PPC_SPE_SINGLE
| PPC_SPE_DOUBLE
)
7186 inval
= handler
->inval2
;
7188 inval
= handler
->inval1
;
7191 if (unlikely((insn
& inval
) != 0)) {
7192 qemu_log_mask(LOG_GUEST_ERROR
, "invalid bits: %08x for opcode: "
7193 "%02x - %02x - %02x - %02x (%08x) "
7194 TARGET_FMT_lx
"\n", insn
& inval
,
7195 opc1(insn
), opc2(insn
), opc3(insn
), opc4(insn
),
7200 handler
->handler(ctx
);
7204 static void ppc_tr_init_disas_context(DisasContextBase
*dcbase
, CPUState
*cs
)
7206 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
7207 CPUPPCState
*env
= cs
->env_ptr
;
7208 uint32_t hflags
= ctx
->base
.tb
->flags
;
7210 ctx
->spr_cb
= env
->spr_cb
;
7211 ctx
->pr
= (hflags
>> HFLAGS_PR
) & 1;
7212 ctx
->mem_idx
= (hflags
>> HFLAGS_DMMU_IDX
) & 7;
7213 ctx
->dr
= (hflags
>> HFLAGS_DR
) & 1;
7214 ctx
->hv
= (hflags
>> HFLAGS_HV
) & 1;
7215 ctx
->insns_flags
= env
->insns_flags
;
7216 ctx
->insns_flags2
= env
->insns_flags2
;
7217 ctx
->access_type
= -1;
7218 ctx
->need_access_type
= !mmu_is_64bit(env
->mmu_model
);
7219 ctx
->le_mode
= (hflags
>> HFLAGS_LE
) & 1;
7220 ctx
->default_tcg_memop_mask
= ctx
->le_mode
? MO_LE
: MO_BE
;
7221 ctx
->flags
= env
->flags
;
7222 #if defined(TARGET_PPC64)
7223 ctx
->sf_mode
= (hflags
>> HFLAGS_64
) & 1;
7224 ctx
->has_cfar
= !!(env
->flags
& POWERPC_FLAG_CFAR
);
7226 ctx
->lazy_tlb_flush
= env
->mmu_model
== POWERPC_MMU_32B
7227 || env
->mmu_model
& POWERPC_MMU_64
;
7229 ctx
->fpu_enabled
= (hflags
>> HFLAGS_FP
) & 1;
7230 ctx
->spe_enabled
= (hflags
>> HFLAGS_SPE
) & 1;
7231 ctx
->altivec_enabled
= (hflags
>> HFLAGS_VR
) & 1;
7232 ctx
->vsx_enabled
= (hflags
>> HFLAGS_VSX
) & 1;
7233 ctx
->tm_enabled
= (hflags
>> HFLAGS_TM
) & 1;
7234 ctx
->gtse
= (hflags
>> HFLAGS_GTSE
) & 1;
7235 ctx
->hr
= (hflags
>> HFLAGS_HR
) & 1;
7236 ctx
->mmcr0_pmcc0
= (hflags
>> HFLAGS_PMCC0
) & 1;
7237 ctx
->mmcr0_pmcc1
= (hflags
>> HFLAGS_PMCC1
) & 1;
7238 ctx
->mmcr0_pmcjce
= (hflags
>> HFLAGS_PMCJCE
) & 1;
7239 ctx
->pmc_other
= (hflags
>> HFLAGS_PMC_OTHER
) & 1;
7240 ctx
->pmu_insn_cnt
= (hflags
>> HFLAGS_INSN_CNT
) & 1;
7242 ctx
->singlestep_enabled
= 0;
7243 if ((hflags
>> HFLAGS_SE
) & 1) {
7244 ctx
->singlestep_enabled
|= CPU_SINGLE_STEP
;
7245 ctx
->base
.max_insns
= 1;
7247 if ((hflags
>> HFLAGS_BE
) & 1) {
7248 ctx
->singlestep_enabled
|= CPU_BRANCH_STEP
;
7252 static void ppc_tr_tb_start(DisasContextBase
*db
, CPUState
*cs
)
7256 static void ppc_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cs
)
7258 tcg_gen_insn_start(dcbase
->pc_next
);
7261 static bool is_prefix_insn(DisasContext
*ctx
, uint32_t insn
)
7263 REQUIRE_INSNS_FLAGS2(ctx
, ISA310
);
7264 return opc1(insn
) == 1;
7267 static void ppc_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cs
)
7269 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
7270 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
7271 CPUPPCState
*env
= cs
->env_ptr
;
7276 LOG_DISAS("----------------\n");
7277 LOG_DISAS("nip=" TARGET_FMT_lx
" super=%d ir=%d\n",
7278 ctx
->base
.pc_next
, ctx
->mem_idx
, (int)msr_ir
);
7280 ctx
->cia
= pc
= ctx
->base
.pc_next
;
7281 insn
= translator_ldl_swap(env
, dcbase
, pc
, need_byteswap(ctx
));
7282 ctx
->base
.pc_next
= pc
+= 4;
7284 if (!is_prefix_insn(ctx
, insn
)) {
7285 ok
= (decode_insn32(ctx
, insn
) ||
7286 decode_legacy(cpu
, ctx
, insn
));
7287 } else if ((pc
& 63) == 0) {
7289 * Power v3.1, section 1.9 Exceptions:
7290 * attempt to execute a prefixed instruction that crosses a
7291 * 64-byte address boundary (system alignment error).
7293 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_INSN
);
7296 uint32_t insn2
= translator_ldl_swap(env
, dcbase
, pc
,
7297 need_byteswap(ctx
));
7298 ctx
->base
.pc_next
= pc
+= 4;
7299 ok
= decode_insn64(ctx
, deposit64(insn2
, 32, 32, insn
));
7305 /* End the TB when crossing a page boundary. */
7306 if (ctx
->base
.is_jmp
== DISAS_NEXT
&& !(pc
& ~TARGET_PAGE_MASK
)) {
7307 ctx
->base
.is_jmp
= DISAS_TOO_MANY
;
7311 static void ppc_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cs
)
7313 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
7314 DisasJumpType is_jmp
= ctx
->base
.is_jmp
;
7315 target_ulong nip
= ctx
->base
.pc_next
;
7317 if (is_jmp
== DISAS_NORETURN
) {
7318 /* We have already exited the TB. */
7322 /* Honor single stepping. */
7323 if (unlikely(ctx
->singlestep_enabled
& CPU_SINGLE_STEP
)
7324 && (nip
<= 0x100 || nip
> 0xf00)) {
7326 case DISAS_TOO_MANY
:
7327 case DISAS_EXIT_UPDATE
:
7328 case DISAS_CHAIN_UPDATE
:
7329 gen_update_nip(ctx
, nip
);
7335 g_assert_not_reached();
7338 gen_debug_exception(ctx
);
7343 case DISAS_TOO_MANY
:
7344 if (use_goto_tb(ctx
, nip
)) {
7345 pmu_count_insns(ctx
);
7347 gen_update_nip(ctx
, nip
);
7348 tcg_gen_exit_tb(ctx
->base
.tb
, 0);
7352 case DISAS_CHAIN_UPDATE
:
7353 gen_update_nip(ctx
, nip
);
7357 * tcg_gen_lookup_and_goto_ptr will exit the TB if
7358 * CF_NO_GOTO_PTR is set. Count insns now.
7360 if (ctx
->base
.tb
->flags
& CF_NO_GOTO_PTR
) {
7361 pmu_count_insns(ctx
);
7364 tcg_gen_lookup_and_goto_ptr();
7367 case DISAS_EXIT_UPDATE
:
7368 gen_update_nip(ctx
, nip
);
7371 pmu_count_insns(ctx
);
7372 tcg_gen_exit_tb(NULL
, 0);
7376 g_assert_not_reached();
7380 static void ppc_tr_disas_log(const DisasContextBase
*dcbase
,
7381 CPUState
*cs
, FILE *logfile
)
7383 fprintf(logfile
, "IN: %s\n", lookup_symbol(dcbase
->pc_first
));
7384 target_disas(logfile
, cs
, dcbase
->pc_first
, dcbase
->tb
->size
);
7387 static const TranslatorOps ppc_tr_ops
= {
7388 .init_disas_context
= ppc_tr_init_disas_context
,
7389 .tb_start
= ppc_tr_tb_start
,
7390 .insn_start
= ppc_tr_insn_start
,
7391 .translate_insn
= ppc_tr_translate_insn
,
7392 .tb_stop
= ppc_tr_tb_stop
,
7393 .disas_log
= ppc_tr_disas_log
,
7396 void gen_intermediate_code(CPUState
*cs
, TranslationBlock
*tb
, int *max_insns
,
7397 target_ulong pc
, void *host_pc
)
7401 translator_loop(cs
, tb
, max_insns
, pc
, host_pc
, &ppc_tr_ops
, &ctx
.base
);