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"
40 #include "qemu/qemu-print.h"
41 #include "qapi/error.h"
43 #define CPU_SINGLE_STEP 0x1
44 #define CPU_BRANCH_STEP 0x2
45 #define GDBSTUB_SINGLE_STEP 0x4
47 /* Include definitions for instructions classes and implementations flags */
48 /* #define PPC_DEBUG_DISAS */
50 #ifdef PPC_DEBUG_DISAS
51 # define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
53 # define LOG_DISAS(...) do { } while (0)
55 /*****************************************************************************/
56 /* Code translation helpers */
58 /* global register indexes */
59 static char cpu_reg_names
[10 * 3 + 22 * 4 /* GPR */
60 + 10 * 4 + 22 * 5 /* SPE GPRh */
62 static TCGv cpu_gpr
[32];
63 static TCGv cpu_gprh
[32];
64 static TCGv_i32 cpu_crf
[8];
69 #if defined(TARGET_PPC64)
72 static TCGv cpu_xer
, cpu_so
, cpu_ov
, cpu_ca
, cpu_ov32
, cpu_ca32
;
73 static TCGv cpu_reserve
;
74 static TCGv cpu_reserve_val
;
75 static TCGv cpu_fpscr
;
76 static TCGv_i32 cpu_access_type
;
78 #include "exec/gen-icount.h"
80 void ppc_translate_init(void)
84 size_t cpu_reg_names_size
;
87 cpu_reg_names_size
= sizeof(cpu_reg_names
);
89 for (i
= 0; i
< 8; i
++) {
90 snprintf(p
, cpu_reg_names_size
, "crf%d", i
);
91 cpu_crf
[i
] = tcg_global_mem_new_i32(cpu_env
,
92 offsetof(CPUPPCState
, crf
[i
]), p
);
94 cpu_reg_names_size
-= 5;
97 for (i
= 0; i
< 32; i
++) {
98 snprintf(p
, cpu_reg_names_size
, "r%d", i
);
99 cpu_gpr
[i
] = tcg_global_mem_new(cpu_env
,
100 offsetof(CPUPPCState
, gpr
[i
]), p
);
101 p
+= (i
< 10) ? 3 : 4;
102 cpu_reg_names_size
-= (i
< 10) ? 3 : 4;
103 snprintf(p
, cpu_reg_names_size
, "r%dH", i
);
104 cpu_gprh
[i
] = tcg_global_mem_new(cpu_env
,
105 offsetof(CPUPPCState
, gprh
[i
]), p
);
106 p
+= (i
< 10) ? 4 : 5;
107 cpu_reg_names_size
-= (i
< 10) ? 4 : 5;
110 cpu_nip
= tcg_global_mem_new(cpu_env
,
111 offsetof(CPUPPCState
, nip
), "nip");
113 cpu_msr
= tcg_global_mem_new(cpu_env
,
114 offsetof(CPUPPCState
, msr
), "msr");
116 cpu_ctr
= tcg_global_mem_new(cpu_env
,
117 offsetof(CPUPPCState
, ctr
), "ctr");
119 cpu_lr
= tcg_global_mem_new(cpu_env
,
120 offsetof(CPUPPCState
, lr
), "lr");
122 #if defined(TARGET_PPC64)
123 cpu_cfar
= tcg_global_mem_new(cpu_env
,
124 offsetof(CPUPPCState
, cfar
), "cfar");
127 cpu_xer
= tcg_global_mem_new(cpu_env
,
128 offsetof(CPUPPCState
, xer
), "xer");
129 cpu_so
= tcg_global_mem_new(cpu_env
,
130 offsetof(CPUPPCState
, so
), "SO");
131 cpu_ov
= tcg_global_mem_new(cpu_env
,
132 offsetof(CPUPPCState
, ov
), "OV");
133 cpu_ca
= tcg_global_mem_new(cpu_env
,
134 offsetof(CPUPPCState
, ca
), "CA");
135 cpu_ov32
= tcg_global_mem_new(cpu_env
,
136 offsetof(CPUPPCState
, ov32
), "OV32");
137 cpu_ca32
= tcg_global_mem_new(cpu_env
,
138 offsetof(CPUPPCState
, ca32
), "CA32");
140 cpu_reserve
= tcg_global_mem_new(cpu_env
,
141 offsetof(CPUPPCState
, reserve_addr
),
143 cpu_reserve_val
= tcg_global_mem_new(cpu_env
,
144 offsetof(CPUPPCState
, reserve_val
),
147 cpu_fpscr
= tcg_global_mem_new(cpu_env
,
148 offsetof(CPUPPCState
, fpscr
), "fpscr");
150 cpu_access_type
= tcg_global_mem_new_i32(cpu_env
,
151 offsetof(CPUPPCState
, access_type
),
155 /* internal defines */
156 struct DisasContext
{
157 DisasContextBase base
;
158 target_ulong cia
; /* current instruction address */
160 /* Routine used to access memory */
161 bool pr
, hv
, dr
, le_mode
;
163 bool need_access_type
;
166 /* Translation flags */
167 MemOp default_tcg_memop_mask
;
168 #if defined(TARGET_PPC64)
173 bool altivec_enabled
;
179 ppc_spr_t
*spr_cb
; /* Needed to check rights for mfspr/mtspr */
180 int singlestep_enabled
;
182 uint64_t insns_flags
;
183 uint64_t insns_flags2
;
186 #define DISAS_EXIT DISAS_TARGET_0 /* exit to main loop, pc updated */
187 #define DISAS_EXIT_UPDATE DISAS_TARGET_1 /* exit to main loop, pc stale */
188 #define DISAS_CHAIN DISAS_TARGET_2 /* lookup next tb, pc updated */
189 #define DISAS_CHAIN_UPDATE DISAS_TARGET_3 /* lookup next tb, pc stale */
191 /* Return true iff byteswap is needed in a scalar memop */
192 static inline bool need_byteswap(const DisasContext
*ctx
)
194 #if defined(TARGET_WORDS_BIGENDIAN)
197 return !ctx
->le_mode
;
201 /* True when active word size < size of target_long. */
203 # define NARROW_MODE(C) (!(C)->sf_mode)
205 # define NARROW_MODE(C) 0
208 struct opc_handler_t
{
209 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
211 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
213 /* instruction type */
215 /* extended instruction type */
218 void (*handler
)(DisasContext
*ctx
);
221 /* SPR load/store helpers */
222 static inline void gen_load_spr(TCGv t
, int reg
)
224 tcg_gen_ld_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
227 static inline void gen_store_spr(int reg
, TCGv t
)
229 tcg_gen_st_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
232 static inline void gen_set_access_type(DisasContext
*ctx
, int access_type
)
234 if (ctx
->need_access_type
&& ctx
->access_type
!= access_type
) {
235 tcg_gen_movi_i32(cpu_access_type
, access_type
);
236 ctx
->access_type
= access_type
;
240 static inline void gen_update_nip(DisasContext
*ctx
, target_ulong nip
)
242 if (NARROW_MODE(ctx
)) {
245 tcg_gen_movi_tl(cpu_nip
, nip
);
248 static void gen_exception_err(DisasContext
*ctx
, uint32_t excp
, uint32_t error
)
253 * These are all synchronous exceptions, we set the PC back to the
254 * faulting instruction
256 gen_update_nip(ctx
, ctx
->cia
);
257 t0
= tcg_const_i32(excp
);
258 t1
= tcg_const_i32(error
);
259 gen_helper_raise_exception_err(cpu_env
, t0
, t1
);
260 tcg_temp_free_i32(t0
);
261 tcg_temp_free_i32(t1
);
262 ctx
->base
.is_jmp
= DISAS_NORETURN
;
265 static void gen_exception(DisasContext
*ctx
, uint32_t excp
)
270 * These are all synchronous exceptions, we set the PC back to the
271 * faulting instruction
273 gen_update_nip(ctx
, ctx
->cia
);
274 t0
= tcg_const_i32(excp
);
275 gen_helper_raise_exception(cpu_env
, t0
);
276 tcg_temp_free_i32(t0
);
277 ctx
->base
.is_jmp
= DISAS_NORETURN
;
280 static void gen_exception_nip(DisasContext
*ctx
, uint32_t excp
,
285 gen_update_nip(ctx
, nip
);
286 t0
= tcg_const_i32(excp
);
287 gen_helper_raise_exception(cpu_env
, t0
);
288 tcg_temp_free_i32(t0
);
289 ctx
->base
.is_jmp
= DISAS_NORETURN
;
292 static void gen_icount_io_start(DisasContext
*ctx
)
294 if (tb_cflags(ctx
->base
.tb
) & CF_USE_ICOUNT
) {
297 * An I/O instruction must be last in the TB.
298 * Chain to the next TB, and let the code from gen_tb_start
299 * decide if we need to return to the main loop.
300 * Doing this first also allows this value to be overridden.
302 ctx
->base
.is_jmp
= DISAS_TOO_MANY
;
307 * Tells the caller what is the appropriate exception to generate and prepares
308 * SPR registers for this exception.
310 * The exception can be either POWERPC_EXCP_TRACE (on most PowerPCs) or
311 * POWERPC_EXCP_DEBUG (on BookE).
313 static uint32_t gen_prep_dbgex(DisasContext
*ctx
)
315 if (ctx
->flags
& POWERPC_FLAG_DE
) {
316 target_ulong dbsr
= 0;
317 if (ctx
->singlestep_enabled
& CPU_SINGLE_STEP
) {
320 /* Must have been branch */
323 TCGv t0
= tcg_temp_new();
324 gen_load_spr(t0
, SPR_BOOKE_DBSR
);
325 tcg_gen_ori_tl(t0
, t0
, dbsr
);
326 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(EXCP_DEBUG
));
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_const_i32(sprn
);
378 gen_helper_load_dump_spr(cpu_env
, t0
);
379 tcg_temp_free_i32(t0
);
383 void spr_read_generic(DisasContext
*ctx
, int gprn
, int sprn
)
385 gen_load_spr(cpu_gpr
[gprn
], sprn
);
386 spr_load_dump_spr(sprn
);
389 static void spr_store_dump_spr(int sprn
)
391 #ifdef PPC_DUMP_SPR_ACCESSES
392 TCGv_i32 t0
= tcg_const_i32(sprn
);
393 gen_helper_store_dump_spr(cpu_env
, t0
);
394 tcg_temp_free_i32(t0
);
398 void spr_write_generic(DisasContext
*ctx
, int sprn
, int gprn
)
400 gen_store_spr(sprn
, cpu_gpr
[gprn
]);
401 spr_store_dump_spr(sprn
);
404 #if !defined(CONFIG_USER_ONLY)
405 void spr_write_generic32(DisasContext
*ctx
, int sprn
, int gprn
)
408 TCGv t0
= tcg_temp_new();
409 tcg_gen_ext32u_tl(t0
, cpu_gpr
[gprn
]);
410 gen_store_spr(sprn
, t0
);
412 spr_store_dump_spr(sprn
);
414 spr_write_generic(ctx
, sprn
, gprn
);
418 void spr_write_clear(DisasContext
*ctx
, int sprn
, int gprn
)
420 TCGv t0
= tcg_temp_new();
421 TCGv t1
= tcg_temp_new();
422 gen_load_spr(t0
, sprn
);
423 tcg_gen_neg_tl(t1
, cpu_gpr
[gprn
]);
424 tcg_gen_and_tl(t0
, t0
, t1
);
425 gen_store_spr(sprn
, t0
);
430 void spr_access_nop(DisasContext
*ctx
, int sprn
, int gprn
)
436 /* SPR common to all PowerPC */
438 void spr_read_xer(DisasContext
*ctx
, int gprn
, int sprn
)
440 TCGv dst
= cpu_gpr
[gprn
];
441 TCGv t0
= tcg_temp_new();
442 TCGv t1
= tcg_temp_new();
443 TCGv t2
= tcg_temp_new();
444 tcg_gen_mov_tl(dst
, cpu_xer
);
445 tcg_gen_shli_tl(t0
, cpu_so
, XER_SO
);
446 tcg_gen_shli_tl(t1
, cpu_ov
, XER_OV
);
447 tcg_gen_shli_tl(t2
, cpu_ca
, XER_CA
);
448 tcg_gen_or_tl(t0
, t0
, t1
);
449 tcg_gen_or_tl(dst
, dst
, t2
);
450 tcg_gen_or_tl(dst
, dst
, t0
);
451 if (is_isa300(ctx
)) {
452 tcg_gen_shli_tl(t0
, cpu_ov32
, XER_OV32
);
453 tcg_gen_or_tl(dst
, dst
, t0
);
454 tcg_gen_shli_tl(t0
, cpu_ca32
, XER_CA32
);
455 tcg_gen_or_tl(dst
, dst
, t0
);
462 void spr_write_xer(DisasContext
*ctx
, int sprn
, int gprn
)
464 TCGv src
= cpu_gpr
[gprn
];
465 /* Write all flags, while reading back check for isa300 */
466 tcg_gen_andi_tl(cpu_xer
, src
,
468 (1u << XER_OV
) | (1u << XER_OV32
) |
469 (1u << XER_CA
) | (1u << XER_CA32
)));
470 tcg_gen_extract_tl(cpu_ov32
, src
, XER_OV32
, 1);
471 tcg_gen_extract_tl(cpu_ca32
, src
, XER_CA32
, 1);
472 tcg_gen_extract_tl(cpu_so
, src
, XER_SO
, 1);
473 tcg_gen_extract_tl(cpu_ov
, src
, XER_OV
, 1);
474 tcg_gen_extract_tl(cpu_ca
, src
, XER_CA
, 1);
478 void spr_read_lr(DisasContext
*ctx
, int gprn
, int sprn
)
480 tcg_gen_mov_tl(cpu_gpr
[gprn
], cpu_lr
);
483 void spr_write_lr(DisasContext
*ctx
, int sprn
, int gprn
)
485 tcg_gen_mov_tl(cpu_lr
, cpu_gpr
[gprn
]);
489 #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY)
490 void spr_read_cfar(DisasContext
*ctx
, int gprn
, int sprn
)
492 tcg_gen_mov_tl(cpu_gpr
[gprn
], cpu_cfar
);
495 void spr_write_cfar(DisasContext
*ctx
, int sprn
, int gprn
)
497 tcg_gen_mov_tl(cpu_cfar
, cpu_gpr
[gprn
]);
499 #endif /* defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY) */
502 void spr_read_ctr(DisasContext
*ctx
, int gprn
, int sprn
)
504 tcg_gen_mov_tl(cpu_gpr
[gprn
], cpu_ctr
);
507 void spr_write_ctr(DisasContext
*ctx
, int sprn
, int gprn
)
509 tcg_gen_mov_tl(cpu_ctr
, cpu_gpr
[gprn
]);
512 /* User read access to SPR */
518 void spr_read_ureg(DisasContext
*ctx
, int gprn
, int sprn
)
520 gen_load_spr(cpu_gpr
[gprn
], sprn
+ 0x10);
523 #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY)
524 void spr_write_ureg(DisasContext
*ctx
, int sprn
, int gprn
)
526 gen_store_spr(sprn
+ 0x10, cpu_gpr
[gprn
]);
530 /* SPR common to all non-embedded PowerPC */
532 #if !defined(CONFIG_USER_ONLY)
533 void spr_read_decr(DisasContext
*ctx
, int gprn
, int sprn
)
535 gen_icount_io_start(ctx
);
536 gen_helper_load_decr(cpu_gpr
[gprn
], cpu_env
);
539 void spr_write_decr(DisasContext
*ctx
, int sprn
, int gprn
)
541 gen_icount_io_start(ctx
);
542 gen_helper_store_decr(cpu_env
, cpu_gpr
[gprn
]);
546 /* SPR common to all non-embedded PowerPC, except 601 */
548 void spr_read_tbl(DisasContext
*ctx
, int gprn
, int sprn
)
550 gen_icount_io_start(ctx
);
551 gen_helper_load_tbl(cpu_gpr
[gprn
], cpu_env
);
554 void spr_read_tbu(DisasContext
*ctx
, int gprn
, int sprn
)
556 gen_icount_io_start(ctx
);
557 gen_helper_load_tbu(cpu_gpr
[gprn
], cpu_env
);
560 void spr_read_atbl(DisasContext
*ctx
, int gprn
, int sprn
)
562 gen_helper_load_atbl(cpu_gpr
[gprn
], cpu_env
);
565 void spr_read_atbu(DisasContext
*ctx
, int gprn
, int sprn
)
567 gen_helper_load_atbu(cpu_gpr
[gprn
], cpu_env
);
570 #if !defined(CONFIG_USER_ONLY)
571 void spr_write_tbl(DisasContext
*ctx
, int sprn
, int gprn
)
573 gen_icount_io_start(ctx
);
574 gen_helper_store_tbl(cpu_env
, cpu_gpr
[gprn
]);
577 void spr_write_tbu(DisasContext
*ctx
, int sprn
, int gprn
)
579 gen_icount_io_start(ctx
);
580 gen_helper_store_tbu(cpu_env
, cpu_gpr
[gprn
]);
583 void spr_write_atbl(DisasContext
*ctx
, int sprn
, int gprn
)
585 gen_helper_store_atbl(cpu_env
, cpu_gpr
[gprn
]);
588 void spr_write_atbu(DisasContext
*ctx
, int sprn
, int gprn
)
590 gen_helper_store_atbu(cpu_env
, cpu_gpr
[gprn
]);
593 #if defined(TARGET_PPC64)
594 void spr_read_purr(DisasContext
*ctx
, int gprn
, int sprn
)
596 gen_icount_io_start(ctx
);
597 gen_helper_load_purr(cpu_gpr
[gprn
], cpu_env
);
600 void spr_write_purr(DisasContext
*ctx
, int sprn
, int gprn
)
602 gen_icount_io_start(ctx
);
603 gen_helper_store_purr(cpu_env
, cpu_gpr
[gprn
]);
607 void spr_read_hdecr(DisasContext
*ctx
, int gprn
, int sprn
)
609 gen_icount_io_start(ctx
);
610 gen_helper_load_hdecr(cpu_gpr
[gprn
], cpu_env
);
613 void spr_write_hdecr(DisasContext
*ctx
, int sprn
, int gprn
)
615 gen_icount_io_start(ctx
);
616 gen_helper_store_hdecr(cpu_env
, cpu_gpr
[gprn
]);
619 void spr_read_vtb(DisasContext
*ctx
, int gprn
, int sprn
)
621 gen_icount_io_start(ctx
);
622 gen_helper_load_vtb(cpu_gpr
[gprn
], cpu_env
);
625 void spr_write_vtb(DisasContext
*ctx
, int sprn
, int gprn
)
627 gen_icount_io_start(ctx
);
628 gen_helper_store_vtb(cpu_env
, cpu_gpr
[gprn
]);
631 void spr_write_tbu40(DisasContext
*ctx
, int sprn
, int gprn
)
633 gen_icount_io_start(ctx
);
634 gen_helper_store_tbu40(cpu_env
, cpu_gpr
[gprn
]);
640 #if !defined(CONFIG_USER_ONLY)
641 /* IBAT0U...IBAT0U */
642 /* IBAT0L...IBAT7L */
643 void spr_read_ibat(DisasContext
*ctx
, int gprn
, int sprn
)
645 tcg_gen_ld_tl(cpu_gpr
[gprn
], cpu_env
,
646 offsetof(CPUPPCState
,
647 IBAT
[sprn
& 1][(sprn
- SPR_IBAT0U
) / 2]));
650 void spr_read_ibat_h(DisasContext
*ctx
, int gprn
, int sprn
)
652 tcg_gen_ld_tl(cpu_gpr
[gprn
], cpu_env
,
653 offsetof(CPUPPCState
,
654 IBAT
[sprn
& 1][((sprn
- SPR_IBAT4U
) / 2) + 4]));
657 void spr_write_ibatu(DisasContext
*ctx
, int sprn
, int gprn
)
659 TCGv_i32 t0
= tcg_const_i32((sprn
- SPR_IBAT0U
) / 2);
660 gen_helper_store_ibatu(cpu_env
, t0
, cpu_gpr
[gprn
]);
661 tcg_temp_free_i32(t0
);
664 void spr_write_ibatu_h(DisasContext
*ctx
, int sprn
, int gprn
)
666 TCGv_i32 t0
= tcg_const_i32(((sprn
- SPR_IBAT4U
) / 2) + 4);
667 gen_helper_store_ibatu(cpu_env
, t0
, cpu_gpr
[gprn
]);
668 tcg_temp_free_i32(t0
);
671 void spr_write_ibatl(DisasContext
*ctx
, int sprn
, int gprn
)
673 TCGv_i32 t0
= tcg_const_i32((sprn
- SPR_IBAT0L
) / 2);
674 gen_helper_store_ibatl(cpu_env
, t0
, cpu_gpr
[gprn
]);
675 tcg_temp_free_i32(t0
);
678 void spr_write_ibatl_h(DisasContext
*ctx
, int sprn
, int gprn
)
680 TCGv_i32 t0
= tcg_const_i32(((sprn
- SPR_IBAT4L
) / 2) + 4);
681 gen_helper_store_ibatl(cpu_env
, t0
, cpu_gpr
[gprn
]);
682 tcg_temp_free_i32(t0
);
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_const_i32((sprn
- SPR_DBAT0U
) / 2);
704 gen_helper_store_dbatu(cpu_env
, t0
, cpu_gpr
[gprn
]);
705 tcg_temp_free_i32(t0
);
708 void spr_write_dbatu_h(DisasContext
*ctx
, int sprn
, int gprn
)
710 TCGv_i32 t0
= tcg_const_i32(((sprn
- SPR_DBAT4U
) / 2) + 4);
711 gen_helper_store_dbatu(cpu_env
, t0
, cpu_gpr
[gprn
]);
712 tcg_temp_free_i32(t0
);
715 void spr_write_dbatl(DisasContext
*ctx
, int sprn
, int gprn
)
717 TCGv_i32 t0
= tcg_const_i32((sprn
- SPR_DBAT0L
) / 2);
718 gen_helper_store_dbatl(cpu_env
, t0
, cpu_gpr
[gprn
]);
719 tcg_temp_free_i32(t0
);
722 void spr_write_dbatl_h(DisasContext
*ctx
, int sprn
, int gprn
)
724 TCGv_i32 t0
= tcg_const_i32(((sprn
- SPR_DBAT4L
) / 2) + 4);
725 gen_helper_store_dbatl(cpu_env
, t0
, cpu_gpr
[gprn
]);
726 tcg_temp_free_i32(t0
);
730 void spr_write_sdr1(DisasContext
*ctx
, int sprn
, int gprn
)
732 gen_helper_store_sdr1(cpu_env
, cpu_gpr
[gprn
]);
735 #if defined(TARGET_PPC64)
736 /* 64 bits PowerPC specific SPRs */
738 void spr_write_pidr(DisasContext
*ctx
, int sprn
, int gprn
)
740 gen_helper_store_pidr(cpu_env
, cpu_gpr
[gprn
]);
743 void spr_write_lpidr(DisasContext
*ctx
, int sprn
, int gprn
)
745 gen_helper_store_lpidr(cpu_env
, cpu_gpr
[gprn
]);
748 void spr_read_hior(DisasContext
*ctx
, int gprn
, int sprn
)
750 tcg_gen_ld_tl(cpu_gpr
[gprn
], cpu_env
, offsetof(CPUPPCState
, excp_prefix
));
753 void spr_write_hior(DisasContext
*ctx
, int sprn
, int gprn
)
755 TCGv t0
= tcg_temp_new();
756 tcg_gen_andi_tl(t0
, cpu_gpr
[gprn
], 0x3FFFFF00000ULL
);
757 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, excp_prefix
));
760 void spr_write_ptcr(DisasContext
*ctx
, int sprn
, int gprn
)
762 gen_helper_store_ptcr(cpu_env
, cpu_gpr
[gprn
]);
765 void spr_write_pcr(DisasContext
*ctx
, int sprn
, int gprn
)
767 gen_helper_store_pcr(cpu_env
, cpu_gpr
[gprn
]);
771 void spr_read_dpdes(DisasContext
*ctx
, int gprn
, int sprn
)
773 gen_helper_load_dpdes(cpu_gpr
[gprn
], cpu_env
);
776 void spr_write_dpdes(DisasContext
*ctx
, int sprn
, int gprn
)
778 gen_helper_store_dpdes(cpu_env
, cpu_gpr
[gprn
]);
783 /* PowerPC 601 specific registers */
785 void spr_read_601_rtcl(DisasContext
*ctx
, int gprn
, int sprn
)
787 gen_helper_load_601_rtcl(cpu_gpr
[gprn
], cpu_env
);
790 void spr_read_601_rtcu(DisasContext
*ctx
, int gprn
, int sprn
)
792 gen_helper_load_601_rtcu(cpu_gpr
[gprn
], cpu_env
);
795 #if !defined(CONFIG_USER_ONLY)
796 void spr_write_601_rtcu(DisasContext
*ctx
, int sprn
, int gprn
)
798 gen_helper_store_601_rtcu(cpu_env
, cpu_gpr
[gprn
]);
801 void spr_write_601_rtcl(DisasContext
*ctx
, int sprn
, int gprn
)
803 gen_helper_store_601_rtcl(cpu_env
, cpu_gpr
[gprn
]);
806 void spr_write_hid0_601(DisasContext
*ctx
, int sprn
, int gprn
)
808 gen_helper_store_hid0_601(cpu_env
, cpu_gpr
[gprn
]);
809 /* Must stop the translation as endianness may have changed */
810 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
815 #if !defined(CONFIG_USER_ONLY)
816 void spr_read_601_ubat(DisasContext
*ctx
, int gprn
, int sprn
)
818 tcg_gen_ld_tl(cpu_gpr
[gprn
], cpu_env
,
819 offsetof(CPUPPCState
,
820 IBAT
[sprn
& 1][(sprn
- SPR_IBAT0U
) / 2]));
823 void spr_write_601_ubatu(DisasContext
*ctx
, int sprn
, int gprn
)
825 TCGv_i32 t0
= tcg_const_i32((sprn
- SPR_IBAT0U
) / 2);
826 gen_helper_store_601_batl(cpu_env
, t0
, cpu_gpr
[gprn
]);
827 tcg_temp_free_i32(t0
);
830 void spr_write_601_ubatl(DisasContext
*ctx
, int sprn
, int gprn
)
832 TCGv_i32 t0
= tcg_const_i32((sprn
- SPR_IBAT0U
) / 2);
833 gen_helper_store_601_batu(cpu_env
, t0
, cpu_gpr
[gprn
]);
834 tcg_temp_free_i32(t0
);
838 /* PowerPC 40x specific registers */
839 #if !defined(CONFIG_USER_ONLY)
840 void spr_read_40x_pit(DisasContext
*ctx
, int gprn
, int sprn
)
842 gen_icount_io_start(ctx
);
843 gen_helper_load_40x_pit(cpu_gpr
[gprn
], cpu_env
);
846 void spr_write_40x_pit(DisasContext
*ctx
, int sprn
, int gprn
)
848 gen_icount_io_start(ctx
);
849 gen_helper_store_40x_pit(cpu_env
, cpu_gpr
[gprn
]);
852 void spr_write_40x_dbcr0(DisasContext
*ctx
, int sprn
, int gprn
)
854 gen_icount_io_start(ctx
);
855 gen_store_spr(sprn
, cpu_gpr
[gprn
]);
856 gen_helper_store_40x_dbcr0(cpu_env
, cpu_gpr
[gprn
]);
857 /* We must stop translation as we may have rebooted */
858 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
861 void spr_write_40x_sler(DisasContext
*ctx
, int sprn
, int gprn
)
863 gen_icount_io_start(ctx
);
864 gen_helper_store_40x_sler(cpu_env
, cpu_gpr
[gprn
]);
867 void spr_write_booke_tcr(DisasContext
*ctx
, int sprn
, int gprn
)
869 gen_icount_io_start(ctx
);
870 gen_helper_store_booke_tcr(cpu_env
, cpu_gpr
[gprn
]);
873 void spr_write_booke_tsr(DisasContext
*ctx
, int sprn
, int gprn
)
875 gen_icount_io_start(ctx
);
876 gen_helper_store_booke_tsr(cpu_env
, cpu_gpr
[gprn
]);
880 /* PowerPC 403 specific registers */
881 /* PBL1 / PBU1 / PBL2 / PBU2 */
882 #if !defined(CONFIG_USER_ONLY)
883 void spr_read_403_pbr(DisasContext
*ctx
, int gprn
, int sprn
)
885 tcg_gen_ld_tl(cpu_gpr
[gprn
], cpu_env
,
886 offsetof(CPUPPCState
, pb
[sprn
- SPR_403_PBL1
]));
889 void spr_write_403_pbr(DisasContext
*ctx
, int sprn
, int gprn
)
891 TCGv_i32 t0
= tcg_const_i32(sprn
- SPR_403_PBL1
);
892 gen_helper_store_403_pbr(cpu_env
, t0
, cpu_gpr
[gprn
]);
893 tcg_temp_free_i32(t0
);
896 void spr_write_pir(DisasContext
*ctx
, int sprn
, int gprn
)
898 TCGv t0
= tcg_temp_new();
899 tcg_gen_andi_tl(t0
, cpu_gpr
[gprn
], 0xF);
900 gen_store_spr(SPR_PIR
, t0
);
905 /* SPE specific registers */
906 void spr_read_spefscr(DisasContext
*ctx
, int gprn
, int sprn
)
908 TCGv_i32 t0
= tcg_temp_new_i32();
909 tcg_gen_ld_i32(t0
, cpu_env
, offsetof(CPUPPCState
, spe_fscr
));
910 tcg_gen_extu_i32_tl(cpu_gpr
[gprn
], t0
);
911 tcg_temp_free_i32(t0
);
914 void spr_write_spefscr(DisasContext
*ctx
, int sprn
, int gprn
)
916 TCGv_i32 t0
= tcg_temp_new_i32();
917 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[gprn
]);
918 tcg_gen_st_i32(t0
, cpu_env
, offsetof(CPUPPCState
, spe_fscr
));
919 tcg_temp_free_i32(t0
);
922 #if !defined(CONFIG_USER_ONLY)
923 /* Callback used to write the exception vector base */
924 void spr_write_excp_prefix(DisasContext
*ctx
, int sprn
, int gprn
)
926 TCGv t0
= tcg_temp_new();
927 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUPPCState
, ivpr_mask
));
928 tcg_gen_and_tl(t0
, t0
, cpu_gpr
[gprn
]);
929 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, excp_prefix
));
930 gen_store_spr(sprn
, t0
);
934 void spr_write_excp_vector(DisasContext
*ctx
, int sprn
, int gprn
)
938 if (sprn
>= SPR_BOOKE_IVOR0
&& sprn
<= SPR_BOOKE_IVOR15
) {
939 sprn_offs
= sprn
- SPR_BOOKE_IVOR0
;
940 } else if (sprn
>= SPR_BOOKE_IVOR32
&& sprn
<= SPR_BOOKE_IVOR37
) {
941 sprn_offs
= sprn
- SPR_BOOKE_IVOR32
+ 32;
942 } else if (sprn
>= SPR_BOOKE_IVOR38
&& sprn
<= SPR_BOOKE_IVOR42
) {
943 sprn_offs
= sprn
- SPR_BOOKE_IVOR38
+ 38;
945 printf("Trying to write an unknown exception vector %d %03x\n",
947 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
951 TCGv t0
= tcg_temp_new();
952 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUPPCState
, ivor_mask
));
953 tcg_gen_and_tl(t0
, t0
, cpu_gpr
[gprn
]);
954 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, excp_vectors
[sprn_offs
]));
955 gen_store_spr(sprn
, t0
);
961 #ifndef CONFIG_USER_ONLY
962 void spr_write_amr(DisasContext
*ctx
, int sprn
, int gprn
)
964 TCGv t0
= tcg_temp_new();
965 TCGv t1
= tcg_temp_new();
966 TCGv t2
= tcg_temp_new();
969 * Note, the HV=1 PR=0 case is handled earlier by simply using
970 * spr_write_generic for HV mode in the SPR table
973 /* Build insertion mask into t1 based on context */
975 gen_load_spr(t1
, SPR_UAMOR
);
977 gen_load_spr(t1
, SPR_AMOR
);
980 /* Mask new bits into t2 */
981 tcg_gen_and_tl(t2
, t1
, cpu_gpr
[gprn
]);
983 /* Load AMR and clear new bits in t0 */
984 gen_load_spr(t0
, SPR_AMR
);
985 tcg_gen_andc_tl(t0
, t0
, t1
);
987 /* Or'in new bits and write it out */
988 tcg_gen_or_tl(t0
, t0
, t2
);
989 gen_store_spr(SPR_AMR
, t0
);
990 spr_store_dump_spr(SPR_AMR
);
997 void spr_write_uamor(DisasContext
*ctx
, int sprn
, int gprn
)
999 TCGv t0
= tcg_temp_new();
1000 TCGv t1
= tcg_temp_new();
1001 TCGv t2
= tcg_temp_new();
1004 * Note, the HV=1 case is handled earlier by simply using
1005 * spr_write_generic for HV mode in the SPR table
1008 /* Build insertion mask into t1 based on context */
1009 gen_load_spr(t1
, SPR_AMOR
);
1011 /* Mask new bits into t2 */
1012 tcg_gen_and_tl(t2
, t1
, cpu_gpr
[gprn
]);
1014 /* Load AMR and clear new bits in t0 */
1015 gen_load_spr(t0
, SPR_UAMOR
);
1016 tcg_gen_andc_tl(t0
, t0
, t1
);
1018 /* Or'in new bits and write it out */
1019 tcg_gen_or_tl(t0
, t0
, t2
);
1020 gen_store_spr(SPR_UAMOR
, t0
);
1021 spr_store_dump_spr(SPR_UAMOR
);
1028 void spr_write_iamr(DisasContext
*ctx
, int sprn
, int gprn
)
1030 TCGv t0
= tcg_temp_new();
1031 TCGv t1
= tcg_temp_new();
1032 TCGv t2
= tcg_temp_new();
1035 * Note, the HV=1 case is handled earlier by simply using
1036 * spr_write_generic for HV mode in the SPR table
1039 /* Build insertion mask into t1 based on context */
1040 gen_load_spr(t1
, SPR_AMOR
);
1042 /* Mask new bits into t2 */
1043 tcg_gen_and_tl(t2
, t1
, cpu_gpr
[gprn
]);
1045 /* Load AMR and clear new bits in t0 */
1046 gen_load_spr(t0
, SPR_IAMR
);
1047 tcg_gen_andc_tl(t0
, t0
, t1
);
1049 /* Or'in new bits and write it out */
1050 tcg_gen_or_tl(t0
, t0
, t2
);
1051 gen_store_spr(SPR_IAMR
, t0
);
1052 spr_store_dump_spr(SPR_IAMR
);
1061 #ifndef CONFIG_USER_ONLY
1062 void spr_read_thrm(DisasContext
*ctx
, int gprn
, int sprn
)
1064 gen_helper_fixup_thrm(cpu_env
);
1065 gen_load_spr(cpu_gpr
[gprn
], sprn
);
1066 spr_load_dump_spr(sprn
);
1068 #endif /* !CONFIG_USER_ONLY */
1070 #if !defined(CONFIG_USER_ONLY)
1071 void spr_write_e500_l1csr0(DisasContext
*ctx
, int sprn
, int gprn
)
1073 TCGv t0
= tcg_temp_new();
1075 tcg_gen_andi_tl(t0
, cpu_gpr
[gprn
], L1CSR0_DCE
| L1CSR0_CPE
);
1076 gen_store_spr(sprn
, t0
);
1080 void spr_write_e500_l1csr1(DisasContext
*ctx
, int sprn
, int gprn
)
1082 TCGv t0
= tcg_temp_new();
1084 tcg_gen_andi_tl(t0
, cpu_gpr
[gprn
], L1CSR1_ICE
| L1CSR1_CPE
);
1085 gen_store_spr(sprn
, t0
);
1089 void spr_write_e500_l2csr0(DisasContext
*ctx
, int sprn
, int gprn
)
1091 TCGv t0
= tcg_temp_new();
1093 tcg_gen_andi_tl(t0
, cpu_gpr
[gprn
],
1094 ~(E500_L2CSR0_L2FI
| E500_L2CSR0_L2FL
| E500_L2CSR0_L2LFC
));
1095 gen_store_spr(sprn
, t0
);
1099 void spr_write_booke206_mmucsr0(DisasContext
*ctx
, int sprn
, int gprn
)
1101 gen_helper_booke206_tlbflush(cpu_env
, cpu_gpr
[gprn
]);
1104 void spr_write_booke_pid(DisasContext
*ctx
, int sprn
, int gprn
)
1106 TCGv_i32 t0
= tcg_const_i32(sprn
);
1107 gen_helper_booke_setpid(cpu_env
, t0
, cpu_gpr
[gprn
]);
1108 tcg_temp_free_i32(t0
);
1110 void spr_write_eplc(DisasContext
*ctx
, int sprn
, int gprn
)
1112 gen_helper_booke_set_eplc(cpu_env
, cpu_gpr
[gprn
]);
1114 void spr_write_epsc(DisasContext
*ctx
, int sprn
, int gprn
)
1116 gen_helper_booke_set_epsc(cpu_env
, cpu_gpr
[gprn
]);
1121 #if !defined(CONFIG_USER_ONLY)
1122 void spr_write_mas73(DisasContext
*ctx
, int sprn
, int gprn
)
1124 TCGv val
= tcg_temp_new();
1125 tcg_gen_ext32u_tl(val
, cpu_gpr
[gprn
]);
1126 gen_store_spr(SPR_BOOKE_MAS3
, val
);
1127 tcg_gen_shri_tl(val
, cpu_gpr
[gprn
], 32);
1128 gen_store_spr(SPR_BOOKE_MAS7
, val
);
1132 void spr_read_mas73(DisasContext
*ctx
, int gprn
, int sprn
)
1134 TCGv mas7
= tcg_temp_new();
1135 TCGv mas3
= tcg_temp_new();
1136 gen_load_spr(mas7
, SPR_BOOKE_MAS7
);
1137 tcg_gen_shli_tl(mas7
, mas7
, 32);
1138 gen_load_spr(mas3
, SPR_BOOKE_MAS3
);
1139 tcg_gen_or_tl(cpu_gpr
[gprn
], mas3
, mas7
);
1140 tcg_temp_free(mas3
);
1141 tcg_temp_free(mas7
);
1147 static void gen_fscr_facility_check(DisasContext
*ctx
, int facility_sprn
,
1148 int bit
, int sprn
, int cause
)
1150 TCGv_i32 t1
= tcg_const_i32(bit
);
1151 TCGv_i32 t2
= tcg_const_i32(sprn
);
1152 TCGv_i32 t3
= tcg_const_i32(cause
);
1154 gen_helper_fscr_facility_check(cpu_env
, t1
, t2
, t3
);
1156 tcg_temp_free_i32(t3
);
1157 tcg_temp_free_i32(t2
);
1158 tcg_temp_free_i32(t1
);
1161 static void gen_msr_facility_check(DisasContext
*ctx
, int facility_sprn
,
1162 int bit
, int sprn
, int cause
)
1164 TCGv_i32 t1
= tcg_const_i32(bit
);
1165 TCGv_i32 t2
= tcg_const_i32(sprn
);
1166 TCGv_i32 t3
= tcg_const_i32(cause
);
1168 gen_helper_msr_facility_check(cpu_env
, t1
, t2
, t3
);
1170 tcg_temp_free_i32(t3
);
1171 tcg_temp_free_i32(t2
);
1172 tcg_temp_free_i32(t1
);
1175 void spr_read_prev_upper32(DisasContext
*ctx
, int gprn
, int sprn
)
1177 TCGv spr_up
= tcg_temp_new();
1178 TCGv spr
= tcg_temp_new();
1180 gen_load_spr(spr
, sprn
- 1);
1181 tcg_gen_shri_tl(spr_up
, spr
, 32);
1182 tcg_gen_ext32u_tl(cpu_gpr
[gprn
], spr_up
);
1185 tcg_temp_free(spr_up
);
1188 void spr_write_prev_upper32(DisasContext
*ctx
, int sprn
, int gprn
)
1190 TCGv spr
= tcg_temp_new();
1192 gen_load_spr(spr
, sprn
- 1);
1193 tcg_gen_deposit_tl(spr
, spr
, cpu_gpr
[gprn
], 32, 32);
1194 gen_store_spr(sprn
- 1, spr
);
1199 #if !defined(CONFIG_USER_ONLY)
1200 void spr_write_hmer(DisasContext
*ctx
, int sprn
, int gprn
)
1202 TCGv hmer
= tcg_temp_new();
1204 gen_load_spr(hmer
, sprn
);
1205 tcg_gen_and_tl(hmer
, cpu_gpr
[gprn
], hmer
);
1206 gen_store_spr(sprn
, hmer
);
1207 spr_store_dump_spr(sprn
);
1208 tcg_temp_free(hmer
);
1211 void spr_write_lpcr(DisasContext
*ctx
, int sprn
, int gprn
)
1213 gen_helper_store_lpcr(cpu_env
, cpu_gpr
[gprn
]);
1215 #endif /* !defined(CONFIG_USER_ONLY) */
1217 void spr_read_tar(DisasContext
*ctx
, int gprn
, int sprn
)
1219 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_TAR
, sprn
, FSCR_IC_TAR
);
1220 spr_read_generic(ctx
, gprn
, sprn
);
1223 void spr_write_tar(DisasContext
*ctx
, int sprn
, int gprn
)
1225 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_TAR
, sprn
, FSCR_IC_TAR
);
1226 spr_write_generic(ctx
, sprn
, gprn
);
1229 void spr_read_tm(DisasContext
*ctx
, int gprn
, int sprn
)
1231 gen_msr_facility_check(ctx
, SPR_FSCR
, MSR_TM
, sprn
, FSCR_IC_TM
);
1232 spr_read_generic(ctx
, gprn
, sprn
);
1235 void spr_write_tm(DisasContext
*ctx
, int sprn
, int gprn
)
1237 gen_msr_facility_check(ctx
, SPR_FSCR
, MSR_TM
, sprn
, FSCR_IC_TM
);
1238 spr_write_generic(ctx
, sprn
, gprn
);
1241 void spr_read_tm_upper32(DisasContext
*ctx
, int gprn
, int sprn
)
1243 gen_msr_facility_check(ctx
, SPR_FSCR
, MSR_TM
, sprn
, FSCR_IC_TM
);
1244 spr_read_prev_upper32(ctx
, gprn
, sprn
);
1247 void spr_write_tm_upper32(DisasContext
*ctx
, int sprn
, int gprn
)
1249 gen_msr_facility_check(ctx
, SPR_FSCR
, MSR_TM
, sprn
, FSCR_IC_TM
);
1250 spr_write_prev_upper32(ctx
, sprn
, gprn
);
1253 void spr_read_ebb(DisasContext
*ctx
, int gprn
, int sprn
)
1255 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_EBB
, sprn
, FSCR_IC_EBB
);
1256 spr_read_generic(ctx
, gprn
, sprn
);
1259 void spr_write_ebb(DisasContext
*ctx
, int sprn
, int gprn
)
1261 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_EBB
, sprn
, FSCR_IC_EBB
);
1262 spr_write_generic(ctx
, sprn
, gprn
);
1265 void spr_read_ebb_upper32(DisasContext
*ctx
, int gprn
, int sprn
)
1267 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_EBB
, sprn
, FSCR_IC_EBB
);
1268 spr_read_prev_upper32(ctx
, gprn
, sprn
);
1271 void spr_write_ebb_upper32(DisasContext
*ctx
, int sprn
, int gprn
)
1273 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_EBB
, sprn
, FSCR_IC_EBB
);
1274 spr_write_prev_upper32(ctx
, sprn
, gprn
);
1278 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
1279 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
1281 #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
1282 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
1284 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
1285 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
1287 #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
1288 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
1290 #define GEN_HANDLER_E_2(name, opc1, opc2, opc3, opc4, inval, type, type2) \
1291 GEN_OPCODE3(name, opc1, opc2, opc3, opc4, inval, type, type2)
1293 #define GEN_HANDLER2_E_2(name, onam, opc1, opc2, opc3, opc4, inval, typ, typ2) \
1294 GEN_OPCODE4(name, onam, opc1, opc2, opc3, opc4, inval, typ, typ2)
1296 typedef struct opcode_t
{
1297 unsigned char opc1
, opc2
, opc3
, opc4
;
1298 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
1299 unsigned char pad
[4];
1301 opc_handler_t handler
;
1305 /* Helpers for priv. check */
1308 gen_priv_exception(ctx, POWERPC_EXCP_PRIV_OPC); return; \
1311 #if defined(CONFIG_USER_ONLY)
1312 #define CHK_HV GEN_PRIV
1313 #define CHK_SV GEN_PRIV
1314 #define CHK_HVRM GEN_PRIV
1318 if (unlikely(ctx->pr || !ctx->hv)) { \
1324 if (unlikely(ctx->pr)) { \
1330 if (unlikely(ctx->pr || !ctx->hv || ctx->dr)) { \
1338 /*****************************************************************************/
1339 /* PowerPC instructions table */
1341 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
1351 .handler = &gen_##name, \
1353 .oname = stringify(name), \
1355 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
1366 .handler = &gen_##name, \
1368 .oname = stringify(name), \
1370 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
1380 .handler = &gen_##name, \
1384 #define GEN_OPCODE3(name, op1, op2, op3, op4, invl, _typ, _typ2) \
1394 .handler = &gen_##name, \
1396 .oname = stringify(name), \
1398 #define GEN_OPCODE4(name, onam, op1, op2, op3, op4, invl, _typ, _typ2) \
1408 .handler = &gen_##name, \
1413 /* Invalid instruction */
1414 static void gen_invalid(DisasContext
*ctx
)
1416 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
1419 static opc_handler_t invalid_handler
= {
1420 .inval1
= 0xFFFFFFFF,
1421 .inval2
= 0xFFFFFFFF,
1424 .handler
= gen_invalid
,
1427 /*** Integer comparison ***/
1429 static inline void gen_op_cmp(TCGv arg0
, TCGv arg1
, int s
, int crf
)
1431 TCGv t0
= tcg_temp_new();
1432 TCGv t1
= tcg_temp_new();
1433 TCGv_i32 t
= tcg_temp_new_i32();
1435 tcg_gen_movi_tl(t0
, CRF_EQ
);
1436 tcg_gen_movi_tl(t1
, CRF_LT
);
1437 tcg_gen_movcond_tl((s
? TCG_COND_LT
: TCG_COND_LTU
),
1438 t0
, arg0
, arg1
, t1
, t0
);
1439 tcg_gen_movi_tl(t1
, CRF_GT
);
1440 tcg_gen_movcond_tl((s
? TCG_COND_GT
: TCG_COND_GTU
),
1441 t0
, arg0
, arg1
, t1
, t0
);
1443 tcg_gen_trunc_tl_i32(t
, t0
);
1444 tcg_gen_trunc_tl_i32(cpu_crf
[crf
], cpu_so
);
1445 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t
);
1449 tcg_temp_free_i32(t
);
1452 static inline void gen_op_cmpi(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
1454 TCGv t0
= tcg_const_tl(arg1
);
1455 gen_op_cmp(arg0
, t0
, s
, crf
);
1459 static inline void gen_op_cmp32(TCGv arg0
, TCGv arg1
, int s
, int crf
)
1462 t0
= tcg_temp_new();
1463 t1
= tcg_temp_new();
1465 tcg_gen_ext32s_tl(t0
, arg0
);
1466 tcg_gen_ext32s_tl(t1
, arg1
);
1468 tcg_gen_ext32u_tl(t0
, arg0
);
1469 tcg_gen_ext32u_tl(t1
, arg1
);
1471 gen_op_cmp(t0
, t1
, s
, crf
);
1476 static inline void gen_op_cmpi32(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
1478 TCGv t0
= tcg_const_tl(arg1
);
1479 gen_op_cmp32(arg0
, t0
, s
, crf
);
1483 static inline void gen_set_Rc0(DisasContext
*ctx
, TCGv reg
)
1485 if (NARROW_MODE(ctx
)) {
1486 gen_op_cmpi32(reg
, 0, 1, 0);
1488 gen_op_cmpi(reg
, 0, 1, 0);
1492 /* cmprb - range comparison: isupper, isaplha, islower*/
1493 static void gen_cmprb(DisasContext
*ctx
)
1495 TCGv_i32 src1
= tcg_temp_new_i32();
1496 TCGv_i32 src2
= tcg_temp_new_i32();
1497 TCGv_i32 src2lo
= tcg_temp_new_i32();
1498 TCGv_i32 src2hi
= tcg_temp_new_i32();
1499 TCGv_i32 crf
= cpu_crf
[crfD(ctx
->opcode
)];
1501 tcg_gen_trunc_tl_i32(src1
, cpu_gpr
[rA(ctx
->opcode
)]);
1502 tcg_gen_trunc_tl_i32(src2
, cpu_gpr
[rB(ctx
->opcode
)]);
1504 tcg_gen_andi_i32(src1
, src1
, 0xFF);
1505 tcg_gen_ext8u_i32(src2lo
, src2
);
1506 tcg_gen_shri_i32(src2
, src2
, 8);
1507 tcg_gen_ext8u_i32(src2hi
, src2
);
1509 tcg_gen_setcond_i32(TCG_COND_LEU
, src2lo
, src2lo
, src1
);
1510 tcg_gen_setcond_i32(TCG_COND_LEU
, src2hi
, src1
, src2hi
);
1511 tcg_gen_and_i32(crf
, src2lo
, src2hi
);
1513 if (ctx
->opcode
& 0x00200000) {
1514 tcg_gen_shri_i32(src2
, src2
, 8);
1515 tcg_gen_ext8u_i32(src2lo
, src2
);
1516 tcg_gen_shri_i32(src2
, src2
, 8);
1517 tcg_gen_ext8u_i32(src2hi
, src2
);
1518 tcg_gen_setcond_i32(TCG_COND_LEU
, src2lo
, src2lo
, src1
);
1519 tcg_gen_setcond_i32(TCG_COND_LEU
, src2hi
, src1
, src2hi
);
1520 tcg_gen_and_i32(src2lo
, src2lo
, src2hi
);
1521 tcg_gen_or_i32(crf
, crf
, src2lo
);
1523 tcg_gen_shli_i32(crf
, crf
, CRF_GT_BIT
);
1524 tcg_temp_free_i32(src1
);
1525 tcg_temp_free_i32(src2
);
1526 tcg_temp_free_i32(src2lo
);
1527 tcg_temp_free_i32(src2hi
);
1530 #if defined(TARGET_PPC64)
1532 static void gen_cmpeqb(DisasContext
*ctx
)
1534 gen_helper_cmpeqb(cpu_crf
[crfD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1535 cpu_gpr
[rB(ctx
->opcode
)]);
1539 /* isel (PowerPC 2.03 specification) */
1540 static void gen_isel(DisasContext
*ctx
)
1542 uint32_t bi
= rC(ctx
->opcode
);
1543 uint32_t mask
= 0x08 >> (bi
& 0x03);
1544 TCGv t0
= tcg_temp_new();
1547 tcg_gen_extu_i32_tl(t0
, cpu_crf
[bi
>> 2]);
1548 tcg_gen_andi_tl(t0
, t0
, mask
);
1550 zr
= tcg_const_tl(0);
1551 tcg_gen_movcond_tl(TCG_COND_NE
, cpu_gpr
[rD(ctx
->opcode
)], t0
, zr
,
1552 rA(ctx
->opcode
) ? cpu_gpr
[rA(ctx
->opcode
)] : zr
,
1553 cpu_gpr
[rB(ctx
->opcode
)]);
1558 /* cmpb: PowerPC 2.05 specification */
1559 static void gen_cmpb(DisasContext
*ctx
)
1561 gen_helper_cmpb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
1562 cpu_gpr
[rB(ctx
->opcode
)]);
1565 /*** Integer arithmetic ***/
1567 static inline void gen_op_arith_compute_ov(DisasContext
*ctx
, TCGv arg0
,
1568 TCGv arg1
, TCGv arg2
, int sub
)
1570 TCGv t0
= tcg_temp_new();
1572 tcg_gen_xor_tl(cpu_ov
, arg0
, arg2
);
1573 tcg_gen_xor_tl(t0
, arg1
, arg2
);
1575 tcg_gen_and_tl(cpu_ov
, cpu_ov
, t0
);
1577 tcg_gen_andc_tl(cpu_ov
, cpu_ov
, t0
);
1580 if (NARROW_MODE(ctx
)) {
1581 tcg_gen_extract_tl(cpu_ov
, cpu_ov
, 31, 1);
1582 if (is_isa300(ctx
)) {
1583 tcg_gen_mov_tl(cpu_ov32
, cpu_ov
);
1586 if (is_isa300(ctx
)) {
1587 tcg_gen_extract_tl(cpu_ov32
, cpu_ov
, 31, 1);
1589 tcg_gen_extract_tl(cpu_ov
, cpu_ov
, TARGET_LONG_BITS
- 1, 1);
1591 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1594 static inline void gen_op_arith_compute_ca32(DisasContext
*ctx
,
1595 TCGv res
, TCGv arg0
, TCGv arg1
,
1600 if (!is_isa300(ctx
)) {
1604 t0
= tcg_temp_new();
1606 tcg_gen_eqv_tl(t0
, arg0
, arg1
);
1608 tcg_gen_xor_tl(t0
, arg0
, arg1
);
1610 tcg_gen_xor_tl(t0
, t0
, res
);
1611 tcg_gen_extract_tl(ca32
, t0
, 32, 1);
1615 /* Common add function */
1616 static inline void gen_op_arith_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1617 TCGv arg2
, TCGv ca
, TCGv ca32
,
1618 bool add_ca
, bool compute_ca
,
1619 bool compute_ov
, bool compute_rc0
)
1623 if (compute_ca
|| compute_ov
) {
1624 t0
= tcg_temp_new();
1628 if (NARROW_MODE(ctx
)) {
1630 * Caution: a non-obvious corner case of the spec is that
1631 * we must produce the *entire* 64-bit addition, but
1632 * produce the carry into bit 32.
1634 TCGv t1
= tcg_temp_new();
1635 tcg_gen_xor_tl(t1
, arg1
, arg2
); /* add without carry */
1636 tcg_gen_add_tl(t0
, arg1
, arg2
);
1638 tcg_gen_add_tl(t0
, t0
, ca
);
1640 tcg_gen_xor_tl(ca
, t0
, t1
); /* bits changed w/ carry */
1642 tcg_gen_extract_tl(ca
, ca
, 32, 1);
1643 if (is_isa300(ctx
)) {
1644 tcg_gen_mov_tl(ca32
, ca
);
1647 TCGv zero
= tcg_const_tl(0);
1649 tcg_gen_add2_tl(t0
, ca
, arg1
, zero
, ca
, zero
);
1650 tcg_gen_add2_tl(t0
, ca
, t0
, ca
, arg2
, zero
);
1652 tcg_gen_add2_tl(t0
, ca
, arg1
, zero
, arg2
, zero
);
1654 gen_op_arith_compute_ca32(ctx
, t0
, arg1
, arg2
, ca32
, 0);
1655 tcg_temp_free(zero
);
1658 tcg_gen_add_tl(t0
, arg1
, arg2
);
1660 tcg_gen_add_tl(t0
, t0
, ca
);
1665 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 0);
1667 if (unlikely(compute_rc0
)) {
1668 gen_set_Rc0(ctx
, t0
);
1672 tcg_gen_mov_tl(ret
, t0
);
1676 /* Add functions with two operands */
1677 #define GEN_INT_ARITH_ADD(name, opc3, ca, add_ca, compute_ca, compute_ov) \
1678 static void glue(gen_, name)(DisasContext *ctx) \
1680 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
1681 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1683 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1685 /* Add functions with one operand and one immediate */
1686 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, ca, \
1687 add_ca, compute_ca, compute_ov) \
1688 static void glue(gen_, name)(DisasContext *ctx) \
1690 TCGv t0 = tcg_const_tl(const_val); \
1691 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
1692 cpu_gpr[rA(ctx->opcode)], t0, \
1694 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1695 tcg_temp_free(t0); \
1698 /* add add. addo addo. */
1699 GEN_INT_ARITH_ADD(add
, 0x08, cpu_ca
, 0, 0, 0)
1700 GEN_INT_ARITH_ADD(addo
, 0x18, cpu_ca
, 0, 0, 1)
1701 /* addc addc. addco addco. */
1702 GEN_INT_ARITH_ADD(addc
, 0x00, cpu_ca
, 0, 1, 0)
1703 GEN_INT_ARITH_ADD(addco
, 0x10, cpu_ca
, 0, 1, 1)
1704 /* adde adde. addeo addeo. */
1705 GEN_INT_ARITH_ADD(adde
, 0x04, cpu_ca
, 1, 1, 0)
1706 GEN_INT_ARITH_ADD(addeo
, 0x14, cpu_ca
, 1, 1, 1)
1707 /* addme addme. addmeo addmeo. */
1708 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, cpu_ca
, 1, 1, 0)
1709 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, cpu_ca
, 1, 1, 1)
1711 GEN_INT_ARITH_ADD(addex
, 0x05, cpu_ov
, 1, 1, 0);
1712 /* addze addze. addzeo addzeo.*/
1713 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, cpu_ca
, 1, 1, 0)
1714 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, cpu_ca
, 1, 1, 1)
1716 static inline void gen_op_addic(DisasContext
*ctx
, bool compute_rc0
)
1718 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
1719 gen_op_arith_add(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1720 c
, cpu_ca
, cpu_ca32
, 0, 1, 0, compute_rc0
);
1724 static void gen_addic(DisasContext
*ctx
)
1726 gen_op_addic(ctx
, 0);
1729 static void gen_addic_(DisasContext
*ctx
)
1731 gen_op_addic(ctx
, 1);
1734 static inline void gen_op_arith_divw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1735 TCGv arg2
, int sign
, int compute_ov
)
1737 TCGv_i32 t0
= tcg_temp_new_i32();
1738 TCGv_i32 t1
= tcg_temp_new_i32();
1739 TCGv_i32 t2
= tcg_temp_new_i32();
1740 TCGv_i32 t3
= tcg_temp_new_i32();
1742 tcg_gen_trunc_tl_i32(t0
, arg1
);
1743 tcg_gen_trunc_tl_i32(t1
, arg2
);
1745 tcg_gen_setcondi_i32(TCG_COND_EQ
, t2
, t0
, INT_MIN
);
1746 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, -1);
1747 tcg_gen_and_i32(t2
, t2
, t3
);
1748 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, 0);
1749 tcg_gen_or_i32(t2
, t2
, t3
);
1750 tcg_gen_movi_i32(t3
, 0);
1751 tcg_gen_movcond_i32(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1752 tcg_gen_div_i32(t3
, t0
, t1
);
1753 tcg_gen_extu_i32_tl(ret
, t3
);
1755 tcg_gen_setcondi_i32(TCG_COND_EQ
, t2
, t1
, 0);
1756 tcg_gen_movi_i32(t3
, 0);
1757 tcg_gen_movcond_i32(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1758 tcg_gen_divu_i32(t3
, t0
, t1
);
1759 tcg_gen_extu_i32_tl(ret
, t3
);
1762 tcg_gen_extu_i32_tl(cpu_ov
, t2
);
1763 if (is_isa300(ctx
)) {
1764 tcg_gen_extu_i32_tl(cpu_ov32
, t2
);
1766 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1768 tcg_temp_free_i32(t0
);
1769 tcg_temp_free_i32(t1
);
1770 tcg_temp_free_i32(t2
);
1771 tcg_temp_free_i32(t3
);
1773 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1774 gen_set_Rc0(ctx
, ret
);
1778 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
1779 static void glue(gen_, name)(DisasContext *ctx) \
1781 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
1782 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1783 sign, compute_ov); \
1785 /* divwu divwu. divwuo divwuo. */
1786 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0);
1787 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1);
1788 /* divw divw. divwo divwo. */
1789 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0);
1790 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1);
1792 /* div[wd]eu[o][.] */
1793 #define GEN_DIVE(name, hlpr, compute_ov) \
1794 static void gen_##name(DisasContext *ctx) \
1796 TCGv_i32 t0 = tcg_const_i32(compute_ov); \
1797 gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1798 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \
1799 tcg_temp_free_i32(t0); \
1800 if (unlikely(Rc(ctx->opcode) != 0)) { \
1801 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1805 GEN_DIVE(divweu
, divweu
, 0);
1806 GEN_DIVE(divweuo
, divweu
, 1);
1807 GEN_DIVE(divwe
, divwe
, 0);
1808 GEN_DIVE(divweo
, divwe
, 1);
1810 #if defined(TARGET_PPC64)
1811 static inline void gen_op_arith_divd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1812 TCGv arg2
, int sign
, int compute_ov
)
1814 TCGv_i64 t0
= tcg_temp_new_i64();
1815 TCGv_i64 t1
= tcg_temp_new_i64();
1816 TCGv_i64 t2
= tcg_temp_new_i64();
1817 TCGv_i64 t3
= tcg_temp_new_i64();
1819 tcg_gen_mov_i64(t0
, arg1
);
1820 tcg_gen_mov_i64(t1
, arg2
);
1822 tcg_gen_setcondi_i64(TCG_COND_EQ
, t2
, t0
, INT64_MIN
);
1823 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, -1);
1824 tcg_gen_and_i64(t2
, t2
, t3
);
1825 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, 0);
1826 tcg_gen_or_i64(t2
, t2
, t3
);
1827 tcg_gen_movi_i64(t3
, 0);
1828 tcg_gen_movcond_i64(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1829 tcg_gen_div_i64(ret
, t0
, t1
);
1831 tcg_gen_setcondi_i64(TCG_COND_EQ
, t2
, t1
, 0);
1832 tcg_gen_movi_i64(t3
, 0);
1833 tcg_gen_movcond_i64(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1834 tcg_gen_divu_i64(ret
, t0
, t1
);
1837 tcg_gen_mov_tl(cpu_ov
, t2
);
1838 if (is_isa300(ctx
)) {
1839 tcg_gen_mov_tl(cpu_ov32
, t2
);
1841 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1843 tcg_temp_free_i64(t0
);
1844 tcg_temp_free_i64(t1
);
1845 tcg_temp_free_i64(t2
);
1846 tcg_temp_free_i64(t3
);
1848 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1849 gen_set_Rc0(ctx
, ret
);
1853 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
1854 static void glue(gen_, name)(DisasContext *ctx) \
1856 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
1857 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1858 sign, compute_ov); \
1860 /* divdu divdu. divduo divduo. */
1861 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0);
1862 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1);
1863 /* divd divd. divdo divdo. */
1864 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0);
1865 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1);
1867 GEN_DIVE(divdeu
, divdeu
, 0);
1868 GEN_DIVE(divdeuo
, divdeu
, 1);
1869 GEN_DIVE(divde
, divde
, 0);
1870 GEN_DIVE(divdeo
, divde
, 1);
1873 static inline void gen_op_arith_modw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1874 TCGv arg2
, int sign
)
1876 TCGv_i32 t0
= tcg_temp_new_i32();
1877 TCGv_i32 t1
= tcg_temp_new_i32();
1879 tcg_gen_trunc_tl_i32(t0
, arg1
);
1880 tcg_gen_trunc_tl_i32(t1
, arg2
);
1882 TCGv_i32 t2
= tcg_temp_new_i32();
1883 TCGv_i32 t3
= tcg_temp_new_i32();
1884 tcg_gen_setcondi_i32(TCG_COND_EQ
, t2
, t0
, INT_MIN
);
1885 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, -1);
1886 tcg_gen_and_i32(t2
, t2
, t3
);
1887 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, 0);
1888 tcg_gen_or_i32(t2
, t2
, t3
);
1889 tcg_gen_movi_i32(t3
, 0);
1890 tcg_gen_movcond_i32(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1891 tcg_gen_rem_i32(t3
, t0
, t1
);
1892 tcg_gen_ext_i32_tl(ret
, t3
);
1893 tcg_temp_free_i32(t2
);
1894 tcg_temp_free_i32(t3
);
1896 TCGv_i32 t2
= tcg_const_i32(1);
1897 TCGv_i32 t3
= tcg_const_i32(0);
1898 tcg_gen_movcond_i32(TCG_COND_EQ
, t1
, t1
, t3
, t2
, t1
);
1899 tcg_gen_remu_i32(t3
, t0
, t1
);
1900 tcg_gen_extu_i32_tl(ret
, t3
);
1901 tcg_temp_free_i32(t2
);
1902 tcg_temp_free_i32(t3
);
1904 tcg_temp_free_i32(t0
);
1905 tcg_temp_free_i32(t1
);
1908 #define GEN_INT_ARITH_MODW(name, opc3, sign) \
1909 static void glue(gen_, name)(DisasContext *ctx) \
1911 gen_op_arith_modw(ctx, cpu_gpr[rD(ctx->opcode)], \
1912 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1916 GEN_INT_ARITH_MODW(moduw
, 0x08, 0);
1917 GEN_INT_ARITH_MODW(modsw
, 0x18, 1);
1919 #if defined(TARGET_PPC64)
1920 static inline void gen_op_arith_modd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1921 TCGv arg2
, int sign
)
1923 TCGv_i64 t0
= tcg_temp_new_i64();
1924 TCGv_i64 t1
= tcg_temp_new_i64();
1926 tcg_gen_mov_i64(t0
, arg1
);
1927 tcg_gen_mov_i64(t1
, arg2
);
1929 TCGv_i64 t2
= tcg_temp_new_i64();
1930 TCGv_i64 t3
= tcg_temp_new_i64();
1931 tcg_gen_setcondi_i64(TCG_COND_EQ
, t2
, t0
, INT64_MIN
);
1932 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, -1);
1933 tcg_gen_and_i64(t2
, t2
, t3
);
1934 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, 0);
1935 tcg_gen_or_i64(t2
, t2
, t3
);
1936 tcg_gen_movi_i64(t3
, 0);
1937 tcg_gen_movcond_i64(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1938 tcg_gen_rem_i64(ret
, t0
, t1
);
1939 tcg_temp_free_i64(t2
);
1940 tcg_temp_free_i64(t3
);
1942 TCGv_i64 t2
= tcg_const_i64(1);
1943 TCGv_i64 t3
= tcg_const_i64(0);
1944 tcg_gen_movcond_i64(TCG_COND_EQ
, t1
, t1
, t3
, t2
, t1
);
1945 tcg_gen_remu_i64(ret
, t0
, t1
);
1946 tcg_temp_free_i64(t2
);
1947 tcg_temp_free_i64(t3
);
1949 tcg_temp_free_i64(t0
);
1950 tcg_temp_free_i64(t1
);
1953 #define GEN_INT_ARITH_MODD(name, opc3, sign) \
1954 static void glue(gen_, name)(DisasContext *ctx) \
1956 gen_op_arith_modd(ctx, cpu_gpr[rD(ctx->opcode)], \
1957 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1961 GEN_INT_ARITH_MODD(modud
, 0x08, 0);
1962 GEN_INT_ARITH_MODD(modsd
, 0x18, 1);
1966 static void gen_mulhw(DisasContext
*ctx
)
1968 TCGv_i32 t0
= tcg_temp_new_i32();
1969 TCGv_i32 t1
= tcg_temp_new_i32();
1971 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1972 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1973 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
1974 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1975 tcg_temp_free_i32(t0
);
1976 tcg_temp_free_i32(t1
);
1977 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1978 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
1982 /* mulhwu mulhwu. */
1983 static void gen_mulhwu(DisasContext
*ctx
)
1985 TCGv_i32 t0
= tcg_temp_new_i32();
1986 TCGv_i32 t1
= tcg_temp_new_i32();
1988 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
1989 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
1990 tcg_gen_mulu2_i32(t0
, t1
, t0
, t1
);
1991 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
1992 tcg_temp_free_i32(t0
);
1993 tcg_temp_free_i32(t1
);
1994 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1995 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
2000 static void gen_mullw(DisasContext
*ctx
)
2002 #if defined(TARGET_PPC64)
2004 t0
= tcg_temp_new_i64();
2005 t1
= tcg_temp_new_i64();
2006 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
2007 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
2008 tcg_gen_mul_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
2012 tcg_gen_mul_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
2013 cpu_gpr
[rB(ctx
->opcode
)]);
2015 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2016 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
2020 /* mullwo mullwo. */
2021 static void gen_mullwo(DisasContext
*ctx
)
2023 TCGv_i32 t0
= tcg_temp_new_i32();
2024 TCGv_i32 t1
= tcg_temp_new_i32();
2026 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
2027 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
2028 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
2029 #if defined(TARGET_PPC64)
2030 tcg_gen_concat_i32_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
2032 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], t0
);
2035 tcg_gen_sari_i32(t0
, t0
, 31);
2036 tcg_gen_setcond_i32(TCG_COND_NE
, t0
, t0
, t1
);
2037 tcg_gen_extu_i32_tl(cpu_ov
, t0
);
2038 if (is_isa300(ctx
)) {
2039 tcg_gen_mov_tl(cpu_ov32
, cpu_ov
);
2041 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
2043 tcg_temp_free_i32(t0
);
2044 tcg_temp_free_i32(t1
);
2045 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2046 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
2051 static void gen_mulli(DisasContext
*ctx
)
2053 tcg_gen_muli_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
2057 #if defined(TARGET_PPC64)
2059 static void gen_mulhd(DisasContext
*ctx
)
2061 TCGv lo
= tcg_temp_new();
2062 tcg_gen_muls2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
2063 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2065 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2066 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
2070 /* mulhdu mulhdu. */
2071 static void gen_mulhdu(DisasContext
*ctx
)
2073 TCGv lo
= tcg_temp_new();
2074 tcg_gen_mulu2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
2075 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2077 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2078 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
2083 static void gen_mulld(DisasContext
*ctx
)
2085 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
2086 cpu_gpr
[rB(ctx
->opcode
)]);
2087 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2088 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
2092 /* mulldo mulldo. */
2093 static void gen_mulldo(DisasContext
*ctx
)
2095 TCGv_i64 t0
= tcg_temp_new_i64();
2096 TCGv_i64 t1
= tcg_temp_new_i64();
2098 tcg_gen_muls2_i64(t0
, t1
, cpu_gpr
[rA(ctx
->opcode
)],
2099 cpu_gpr
[rB(ctx
->opcode
)]);
2100 tcg_gen_mov_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
);
2102 tcg_gen_sari_i64(t0
, t0
, 63);
2103 tcg_gen_setcond_i64(TCG_COND_NE
, cpu_ov
, t0
, t1
);
2104 if (is_isa300(ctx
)) {
2105 tcg_gen_mov_tl(cpu_ov32
, cpu_ov
);
2107 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
2109 tcg_temp_free_i64(t0
);
2110 tcg_temp_free_i64(t1
);
2112 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2113 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
2118 /* Common subf function */
2119 static inline void gen_op_arith_subf(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
2120 TCGv arg2
, bool add_ca
, bool compute_ca
,
2121 bool compute_ov
, bool compute_rc0
)
2125 if (compute_ca
|| compute_ov
) {
2126 t0
= tcg_temp_new();
2130 /* dest = ~arg1 + arg2 [+ ca]. */
2131 if (NARROW_MODE(ctx
)) {
2133 * Caution: a non-obvious corner case of the spec is that
2134 * we must produce the *entire* 64-bit addition, but
2135 * produce the carry into bit 32.
2137 TCGv inv1
= tcg_temp_new();
2138 TCGv t1
= tcg_temp_new();
2139 tcg_gen_not_tl(inv1
, arg1
);
2141 tcg_gen_add_tl(t0
, arg2
, cpu_ca
);
2143 tcg_gen_addi_tl(t0
, arg2
, 1);
2145 tcg_gen_xor_tl(t1
, arg2
, inv1
); /* add without carry */
2146 tcg_gen_add_tl(t0
, t0
, inv1
);
2147 tcg_temp_free(inv1
);
2148 tcg_gen_xor_tl(cpu_ca
, t0
, t1
); /* bits changes w/ carry */
2150 tcg_gen_extract_tl(cpu_ca
, cpu_ca
, 32, 1);
2151 if (is_isa300(ctx
)) {
2152 tcg_gen_mov_tl(cpu_ca32
, cpu_ca
);
2154 } else if (add_ca
) {
2155 TCGv zero
, inv1
= tcg_temp_new();
2156 tcg_gen_not_tl(inv1
, arg1
);
2157 zero
= tcg_const_tl(0);
2158 tcg_gen_add2_tl(t0
, cpu_ca
, arg2
, zero
, cpu_ca
, zero
);
2159 tcg_gen_add2_tl(t0
, cpu_ca
, t0
, cpu_ca
, inv1
, zero
);
2160 gen_op_arith_compute_ca32(ctx
, t0
, inv1
, arg2
, cpu_ca32
, 0);
2161 tcg_temp_free(zero
);
2162 tcg_temp_free(inv1
);
2164 tcg_gen_setcond_tl(TCG_COND_GEU
, cpu_ca
, arg2
, arg1
);
2165 tcg_gen_sub_tl(t0
, arg2
, arg1
);
2166 gen_op_arith_compute_ca32(ctx
, t0
, arg1
, arg2
, cpu_ca32
, 1);
2168 } else if (add_ca
) {
2170 * Since we're ignoring carry-out, we can simplify the
2171 * standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1.
2173 tcg_gen_sub_tl(t0
, arg2
, arg1
);
2174 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
2175 tcg_gen_subi_tl(t0
, t0
, 1);
2177 tcg_gen_sub_tl(t0
, arg2
, arg1
);
2181 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 1);
2183 if (unlikely(compute_rc0
)) {
2184 gen_set_Rc0(ctx
, t0
);
2188 tcg_gen_mov_tl(ret
, t0
);
2192 /* Sub functions with Two operands functions */
2193 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
2194 static void glue(gen_, name)(DisasContext *ctx) \
2196 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
2197 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
2198 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
2200 /* Sub functions with one operand and one immediate */
2201 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
2202 add_ca, compute_ca, compute_ov) \
2203 static void glue(gen_, name)(DisasContext *ctx) \
2205 TCGv t0 = tcg_const_tl(const_val); \
2206 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
2207 cpu_gpr[rA(ctx->opcode)], t0, \
2208 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
2209 tcg_temp_free(t0); \
2211 /* subf subf. subfo subfo. */
2212 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
2213 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
2214 /* subfc subfc. subfco subfco. */
2215 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
2216 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
2217 /* subfe subfe. subfeo subfo. */
2218 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
2219 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
2220 /* subfme subfme. subfmeo subfmeo. */
2221 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
2222 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
2223 /* subfze subfze. subfzeo subfzeo.*/
2224 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
2225 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
2228 static void gen_subfic(DisasContext
*ctx
)
2230 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
2231 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
2236 /* neg neg. nego nego. */
2237 static inline void gen_op_arith_neg(DisasContext
*ctx
, bool compute_ov
)
2239 TCGv zero
= tcg_const_tl(0);
2240 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
2241 zero
, 0, 0, compute_ov
, Rc(ctx
->opcode
));
2242 tcg_temp_free(zero
);
2245 static void gen_neg(DisasContext
*ctx
)
2247 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
2248 if (unlikely(Rc(ctx
->opcode
))) {
2249 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
2253 static void gen_nego(DisasContext
*ctx
)
2255 gen_op_arith_neg(ctx
, 1);
2258 /*** Integer logical ***/
2259 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
2260 static void glue(gen_, name)(DisasContext *ctx) \
2262 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
2263 cpu_gpr[rB(ctx->opcode)]); \
2264 if (unlikely(Rc(ctx->opcode) != 0)) \
2265 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
2268 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
2269 static void glue(gen_, name)(DisasContext *ctx) \
2271 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
2272 if (unlikely(Rc(ctx->opcode) != 0)) \
2273 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
2277 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
);
2279 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
);
2282 static void gen_andi_(DisasContext
*ctx
)
2284 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
2286 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2290 static void gen_andis_(DisasContext
*ctx
)
2292 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
2293 UIMM(ctx
->opcode
) << 16);
2294 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2298 static void gen_cntlzw(DisasContext
*ctx
)
2300 TCGv_i32 t
= tcg_temp_new_i32();
2302 tcg_gen_trunc_tl_i32(t
, cpu_gpr
[rS(ctx
->opcode
)]);
2303 tcg_gen_clzi_i32(t
, t
, 32);
2304 tcg_gen_extu_i32_tl(cpu_gpr
[rA(ctx
->opcode
)], t
);
2305 tcg_temp_free_i32(t
);
2307 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2308 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2313 static void gen_cnttzw(DisasContext
*ctx
)
2315 TCGv_i32 t
= tcg_temp_new_i32();
2317 tcg_gen_trunc_tl_i32(t
, cpu_gpr
[rS(ctx
->opcode
)]);
2318 tcg_gen_ctzi_i32(t
, t
, 32);
2319 tcg_gen_extu_i32_tl(cpu_gpr
[rA(ctx
->opcode
)], t
);
2320 tcg_temp_free_i32(t
);
2322 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2323 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2328 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
);
2329 /* extsb & extsb. */
2330 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
);
2331 /* extsh & extsh. */
2332 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
);
2334 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
);
2336 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
);
2338 #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY)
2339 static void gen_pause(DisasContext
*ctx
)
2341 TCGv_i32 t0
= tcg_const_i32(0);
2342 tcg_gen_st_i32(t0
, cpu_env
,
2343 -offsetof(PowerPCCPU
, env
) + offsetof(CPUState
, halted
));
2344 tcg_temp_free_i32(t0
);
2346 /* Stop translation, this gives other CPUs a chance to run */
2347 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
2349 #endif /* defined(TARGET_PPC64) */
2352 static void gen_or(DisasContext
*ctx
)
2356 rs
= rS(ctx
->opcode
);
2357 ra
= rA(ctx
->opcode
);
2358 rb
= rB(ctx
->opcode
);
2359 /* Optimisation for mr. ri case */
2360 if (rs
!= ra
|| rs
!= rb
) {
2362 tcg_gen_or_tl(cpu_gpr
[ra
], cpu_gpr
[rs
], cpu_gpr
[rb
]);
2364 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rs
]);
2366 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2367 gen_set_Rc0(ctx
, cpu_gpr
[ra
]);
2369 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
2370 gen_set_Rc0(ctx
, cpu_gpr
[rs
]);
2371 #if defined(TARGET_PPC64)
2372 } else if (rs
!= 0) { /* 0 is nop */
2377 /* Set process priority to low */
2381 /* Set process priority to medium-low */
2385 /* Set process priority to normal */
2388 #if !defined(CONFIG_USER_ONLY)
2391 /* Set process priority to very low */
2397 /* Set process priority to medium-hight */
2403 /* Set process priority to high */
2408 if (ctx
->hv
&& !ctx
->pr
) {
2409 /* Set process priority to very high */
2418 TCGv t0
= tcg_temp_new();
2419 gen_load_spr(t0
, SPR_PPR
);
2420 tcg_gen_andi_tl(t0
, t0
, ~0x001C000000000000ULL
);
2421 tcg_gen_ori_tl(t0
, t0
, ((uint64_t)prio
) << 50);
2422 gen_store_spr(SPR_PPR
, t0
);
2425 #if !defined(CONFIG_USER_ONLY)
2427 * Pause out of TCG otherwise spin loops with smt_low eat too
2428 * much CPU and the kernel hangs. This applies to all
2429 * encodings other than no-op, e.g., miso(rs=26), yield(27),
2430 * mdoio(29), mdoom(30), and all currently undefined.
2438 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
);
2441 static void gen_xor(DisasContext
*ctx
)
2443 /* Optimisation for "set to zero" case */
2444 if (rS(ctx
->opcode
) != rB(ctx
->opcode
)) {
2445 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
2446 cpu_gpr
[rB(ctx
->opcode
)]);
2448 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
2450 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2451 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2456 static void gen_ori(DisasContext
*ctx
)
2458 target_ulong uimm
= UIMM(ctx
->opcode
);
2460 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
2463 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
2467 static void gen_oris(DisasContext
*ctx
)
2469 target_ulong uimm
= UIMM(ctx
->opcode
);
2471 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
2475 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
2480 static void gen_xori(DisasContext
*ctx
)
2482 target_ulong uimm
= UIMM(ctx
->opcode
);
2484 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
2488 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
2492 static void gen_xoris(DisasContext
*ctx
)
2494 target_ulong uimm
= UIMM(ctx
->opcode
);
2496 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
2500 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
2504 /* popcntb : PowerPC 2.03 specification */
2505 static void gen_popcntb(DisasContext
*ctx
)
2507 gen_helper_popcntb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
2510 static void gen_popcntw(DisasContext
*ctx
)
2512 #if defined(TARGET_PPC64)
2513 gen_helper_popcntw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
2515 tcg_gen_ctpop_i32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
2519 #if defined(TARGET_PPC64)
2520 /* popcntd: PowerPC 2.06 specification */
2521 static void gen_popcntd(DisasContext
*ctx
)
2523 tcg_gen_ctpop_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
2527 /* prtyw: PowerPC 2.05 specification */
2528 static void gen_prtyw(DisasContext
*ctx
)
2530 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
2531 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
2532 TCGv t0
= tcg_temp_new();
2533 tcg_gen_shri_tl(t0
, rs
, 16);
2534 tcg_gen_xor_tl(ra
, rs
, t0
);
2535 tcg_gen_shri_tl(t0
, ra
, 8);
2536 tcg_gen_xor_tl(ra
, ra
, t0
);
2537 tcg_gen_andi_tl(ra
, ra
, (target_ulong
)0x100000001ULL
);
2541 #if defined(TARGET_PPC64)
2542 /* prtyd: PowerPC 2.05 specification */
2543 static void gen_prtyd(DisasContext
*ctx
)
2545 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
2546 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
2547 TCGv t0
= tcg_temp_new();
2548 tcg_gen_shri_tl(t0
, rs
, 32);
2549 tcg_gen_xor_tl(ra
, rs
, t0
);
2550 tcg_gen_shri_tl(t0
, ra
, 16);
2551 tcg_gen_xor_tl(ra
, ra
, t0
);
2552 tcg_gen_shri_tl(t0
, ra
, 8);
2553 tcg_gen_xor_tl(ra
, ra
, t0
);
2554 tcg_gen_andi_tl(ra
, ra
, 1);
2559 #if defined(TARGET_PPC64)
2561 static void gen_bpermd(DisasContext
*ctx
)
2563 gen_helper_bpermd(cpu_gpr
[rA(ctx
->opcode
)],
2564 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2568 #if defined(TARGET_PPC64)
2569 /* extsw & extsw. */
2570 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
);
2573 static void gen_cntlzd(DisasContext
*ctx
)
2575 tcg_gen_clzi_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], 64);
2576 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2577 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2582 static void gen_cnttzd(DisasContext
*ctx
)
2584 tcg_gen_ctzi_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], 64);
2585 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2586 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2591 static void gen_darn(DisasContext
*ctx
)
2593 int l
= L(ctx
->opcode
);
2596 tcg_gen_movi_i64(cpu_gpr
[rD(ctx
->opcode
)], -1);
2598 gen_icount_io_start(ctx
);
2600 gen_helper_darn32(cpu_gpr
[rD(ctx
->opcode
)]);
2602 /* Return 64-bit random for both CRN and RRN */
2603 gen_helper_darn64(cpu_gpr
[rD(ctx
->opcode
)]);
2609 /*** Integer rotate ***/
2611 /* rlwimi & rlwimi. */
2612 static void gen_rlwimi(DisasContext
*ctx
)
2614 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2615 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2616 uint32_t sh
= SH(ctx
->opcode
);
2617 uint32_t mb
= MB(ctx
->opcode
);
2618 uint32_t me
= ME(ctx
->opcode
);
2620 if (sh
== (31 - me
) && mb
<= me
) {
2621 tcg_gen_deposit_tl(t_ra
, t_ra
, t_rs
, sh
, me
- mb
+ 1);
2624 bool mask_in_32b
= true;
2627 #if defined(TARGET_PPC64)
2631 mask
= MASK(mb
, me
);
2633 #if defined(TARGET_PPC64)
2634 if (mask
> 0xffffffffu
) {
2635 mask_in_32b
= false;
2638 t1
= tcg_temp_new();
2640 TCGv_i32 t0
= tcg_temp_new_i32();
2641 tcg_gen_trunc_tl_i32(t0
, t_rs
);
2642 tcg_gen_rotli_i32(t0
, t0
, sh
);
2643 tcg_gen_extu_i32_tl(t1
, t0
);
2644 tcg_temp_free_i32(t0
);
2646 #if defined(TARGET_PPC64)
2647 tcg_gen_deposit_i64(t1
, t_rs
, t_rs
, 32, 32);
2648 tcg_gen_rotli_i64(t1
, t1
, sh
);
2650 g_assert_not_reached();
2654 tcg_gen_andi_tl(t1
, t1
, mask
);
2655 tcg_gen_andi_tl(t_ra
, t_ra
, ~mask
);
2656 tcg_gen_or_tl(t_ra
, t_ra
, t1
);
2659 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2660 gen_set_Rc0(ctx
, t_ra
);
2664 /* rlwinm & rlwinm. */
2665 static void gen_rlwinm(DisasContext
*ctx
)
2667 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2668 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2669 int sh
= SH(ctx
->opcode
);
2670 int mb
= MB(ctx
->opcode
);
2671 int me
= ME(ctx
->opcode
);
2672 int len
= me
- mb
+ 1;
2673 int rsh
= (32 - sh
) & 31;
2675 if (sh
!= 0 && len
> 0 && me
== (31 - sh
)) {
2676 tcg_gen_deposit_z_tl(t_ra
, t_rs
, sh
, len
);
2677 } else if (me
== 31 && rsh
+ len
<= 32) {
2678 tcg_gen_extract_tl(t_ra
, t_rs
, rsh
, len
);
2681 bool mask_in_32b
= true;
2682 #if defined(TARGET_PPC64)
2686 mask
= MASK(mb
, me
);
2687 #if defined(TARGET_PPC64)
2688 if (mask
> 0xffffffffu
) {
2689 mask_in_32b
= false;
2694 tcg_gen_andi_tl(t_ra
, t_rs
, mask
);
2696 TCGv_i32 t0
= tcg_temp_new_i32();
2697 tcg_gen_trunc_tl_i32(t0
, t_rs
);
2698 tcg_gen_rotli_i32(t0
, t0
, sh
);
2699 tcg_gen_andi_i32(t0
, t0
, mask
);
2700 tcg_gen_extu_i32_tl(t_ra
, t0
);
2701 tcg_temp_free_i32(t0
);
2704 #if defined(TARGET_PPC64)
2705 tcg_gen_deposit_i64(t_ra
, t_rs
, t_rs
, 32, 32);
2706 tcg_gen_rotli_i64(t_ra
, t_ra
, sh
);
2707 tcg_gen_andi_i64(t_ra
, t_ra
, mask
);
2709 g_assert_not_reached();
2713 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2714 gen_set_Rc0(ctx
, t_ra
);
2718 /* rlwnm & rlwnm. */
2719 static void gen_rlwnm(DisasContext
*ctx
)
2721 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2722 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2723 TCGv t_rb
= cpu_gpr
[rB(ctx
->opcode
)];
2724 uint32_t mb
= MB(ctx
->opcode
);
2725 uint32_t me
= ME(ctx
->opcode
);
2727 bool mask_in_32b
= true;
2729 #if defined(TARGET_PPC64)
2733 mask
= MASK(mb
, me
);
2735 #if defined(TARGET_PPC64)
2736 if (mask
> 0xffffffffu
) {
2737 mask_in_32b
= false;
2741 TCGv_i32 t0
= tcg_temp_new_i32();
2742 TCGv_i32 t1
= tcg_temp_new_i32();
2743 tcg_gen_trunc_tl_i32(t0
, t_rb
);
2744 tcg_gen_trunc_tl_i32(t1
, t_rs
);
2745 tcg_gen_andi_i32(t0
, t0
, 0x1f);
2746 tcg_gen_rotl_i32(t1
, t1
, t0
);
2747 tcg_gen_extu_i32_tl(t_ra
, t1
);
2748 tcg_temp_free_i32(t0
);
2749 tcg_temp_free_i32(t1
);
2751 #if defined(TARGET_PPC64)
2752 TCGv_i64 t0
= tcg_temp_new_i64();
2753 tcg_gen_andi_i64(t0
, t_rb
, 0x1f);
2754 tcg_gen_deposit_i64(t_ra
, t_rs
, t_rs
, 32, 32);
2755 tcg_gen_rotl_i64(t_ra
, t_ra
, t0
);
2756 tcg_temp_free_i64(t0
);
2758 g_assert_not_reached();
2762 tcg_gen_andi_tl(t_ra
, t_ra
, mask
);
2764 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2765 gen_set_Rc0(ctx
, t_ra
);
2769 #if defined(TARGET_PPC64)
2770 #define GEN_PPC64_R2(name, opc1, opc2) \
2771 static void glue(gen_, name##0)(DisasContext *ctx) \
2773 gen_##name(ctx, 0); \
2776 static void glue(gen_, name##1)(DisasContext *ctx) \
2778 gen_##name(ctx, 1); \
2780 #define GEN_PPC64_R4(name, opc1, opc2) \
2781 static void glue(gen_, name##0)(DisasContext *ctx) \
2783 gen_##name(ctx, 0, 0); \
2786 static void glue(gen_, name##1)(DisasContext *ctx) \
2788 gen_##name(ctx, 0, 1); \
2791 static void glue(gen_, name##2)(DisasContext *ctx) \
2793 gen_##name(ctx, 1, 0); \
2796 static void glue(gen_, name##3)(DisasContext *ctx) \
2798 gen_##name(ctx, 1, 1); \
2801 static void gen_rldinm(DisasContext
*ctx
, int mb
, int me
, int sh
)
2803 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2804 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2805 int len
= me
- mb
+ 1;
2806 int rsh
= (64 - sh
) & 63;
2808 if (sh
!= 0 && len
> 0 && me
== (63 - sh
)) {
2809 tcg_gen_deposit_z_tl(t_ra
, t_rs
, sh
, len
);
2810 } else if (me
== 63 && rsh
+ len
<= 64) {
2811 tcg_gen_extract_tl(t_ra
, t_rs
, rsh
, len
);
2813 tcg_gen_rotli_tl(t_ra
, t_rs
, sh
);
2814 tcg_gen_andi_tl(t_ra
, t_ra
, MASK(mb
, me
));
2816 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2817 gen_set_Rc0(ctx
, t_ra
);
2821 /* rldicl - rldicl. */
2822 static inline void gen_rldicl(DisasContext
*ctx
, int mbn
, int shn
)
2826 sh
= SH(ctx
->opcode
) | (shn
<< 5);
2827 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2828 gen_rldinm(ctx
, mb
, 63, sh
);
2830 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
2832 /* rldicr - rldicr. */
2833 static inline void gen_rldicr(DisasContext
*ctx
, int men
, int shn
)
2837 sh
= SH(ctx
->opcode
) | (shn
<< 5);
2838 me
= MB(ctx
->opcode
) | (men
<< 5);
2839 gen_rldinm(ctx
, 0, me
, sh
);
2841 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
2843 /* rldic - rldic. */
2844 static inline void gen_rldic(DisasContext
*ctx
, int mbn
, int shn
)
2848 sh
= SH(ctx
->opcode
) | (shn
<< 5);
2849 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2850 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
2852 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
2854 static void gen_rldnm(DisasContext
*ctx
, int mb
, int me
)
2856 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2857 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2858 TCGv t_rb
= cpu_gpr
[rB(ctx
->opcode
)];
2861 t0
= tcg_temp_new();
2862 tcg_gen_andi_tl(t0
, t_rb
, 0x3f);
2863 tcg_gen_rotl_tl(t_ra
, t_rs
, t0
);
2866 tcg_gen_andi_tl(t_ra
, t_ra
, MASK(mb
, me
));
2867 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2868 gen_set_Rc0(ctx
, t_ra
);
2872 /* rldcl - rldcl. */
2873 static inline void gen_rldcl(DisasContext
*ctx
, int mbn
)
2877 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2878 gen_rldnm(ctx
, mb
, 63);
2880 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
2882 /* rldcr - rldcr. */
2883 static inline void gen_rldcr(DisasContext
*ctx
, int men
)
2887 me
= MB(ctx
->opcode
) | (men
<< 5);
2888 gen_rldnm(ctx
, 0, me
);
2890 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
2892 /* rldimi - rldimi. */
2893 static void gen_rldimi(DisasContext
*ctx
, int mbn
, int shn
)
2895 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2896 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2897 uint32_t sh
= SH(ctx
->opcode
) | (shn
<< 5);
2898 uint32_t mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2899 uint32_t me
= 63 - sh
;
2902 tcg_gen_deposit_tl(t_ra
, t_ra
, t_rs
, sh
, me
- mb
+ 1);
2904 target_ulong mask
= MASK(mb
, me
);
2905 TCGv t1
= tcg_temp_new();
2907 tcg_gen_rotli_tl(t1
, t_rs
, sh
);
2908 tcg_gen_andi_tl(t1
, t1
, mask
);
2909 tcg_gen_andi_tl(t_ra
, t_ra
, ~mask
);
2910 tcg_gen_or_tl(t_ra
, t_ra
, t1
);
2913 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2914 gen_set_Rc0(ctx
, t_ra
);
2917 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
2920 /*** Integer shift ***/
2923 static void gen_slw(DisasContext
*ctx
)
2927 t0
= tcg_temp_new();
2928 /* AND rS with a mask that is 0 when rB >= 0x20 */
2929 #if defined(TARGET_PPC64)
2930 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
2931 tcg_gen_sari_tl(t0
, t0
, 0x3f);
2933 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
2934 tcg_gen_sari_tl(t0
, t0
, 0x1f);
2936 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
2937 t1
= tcg_temp_new();
2938 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
2939 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
2942 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
2943 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2944 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2949 static void gen_sraw(DisasContext
*ctx
)
2951 gen_helper_sraw(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
2952 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2953 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2954 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2958 /* srawi & srawi. */
2959 static void gen_srawi(DisasContext
*ctx
)
2961 int sh
= SH(ctx
->opcode
);
2962 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
2963 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
2965 tcg_gen_ext32s_tl(dst
, src
);
2966 tcg_gen_movi_tl(cpu_ca
, 0);
2967 if (is_isa300(ctx
)) {
2968 tcg_gen_movi_tl(cpu_ca32
, 0);
2972 tcg_gen_ext32s_tl(dst
, src
);
2973 tcg_gen_andi_tl(cpu_ca
, dst
, (1ULL << sh
) - 1);
2974 t0
= tcg_temp_new();
2975 tcg_gen_sari_tl(t0
, dst
, TARGET_LONG_BITS
- 1);
2976 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
2978 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
2979 if (is_isa300(ctx
)) {
2980 tcg_gen_mov_tl(cpu_ca32
, cpu_ca
);
2982 tcg_gen_sari_tl(dst
, dst
, sh
);
2984 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2985 gen_set_Rc0(ctx
, dst
);
2990 static void gen_srw(DisasContext
*ctx
)
2994 t0
= tcg_temp_new();
2995 /* AND rS with a mask that is 0 when rB >= 0x20 */
2996 #if defined(TARGET_PPC64)
2997 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
2998 tcg_gen_sari_tl(t0
, t0
, 0x3f);
3000 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
3001 tcg_gen_sari_tl(t0
, t0
, 0x1f);
3003 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3004 tcg_gen_ext32u_tl(t0
, t0
);
3005 t1
= tcg_temp_new();
3006 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
3007 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3010 if (unlikely(Rc(ctx
->opcode
) != 0)) {
3011 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
3015 #if defined(TARGET_PPC64)
3017 static void gen_sld(DisasContext
*ctx
)
3021 t0
= tcg_temp_new();
3022 /* AND rS with a mask that is 0 when rB >= 0x40 */
3023 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
3024 tcg_gen_sari_tl(t0
, t0
, 0x3f);
3025 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3026 t1
= tcg_temp_new();
3027 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
3028 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3031 if (unlikely(Rc(ctx
->opcode
) != 0)) {
3032 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
3037 static void gen_srad(DisasContext
*ctx
)
3039 gen_helper_srad(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
3040 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
3041 if (unlikely(Rc(ctx
->opcode
) != 0)) {
3042 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
3045 /* sradi & sradi. */
3046 static inline void gen_sradi(DisasContext
*ctx
, int n
)
3048 int sh
= SH(ctx
->opcode
) + (n
<< 5);
3049 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
3050 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
3052 tcg_gen_mov_tl(dst
, src
);
3053 tcg_gen_movi_tl(cpu_ca
, 0);
3054 if (is_isa300(ctx
)) {
3055 tcg_gen_movi_tl(cpu_ca32
, 0);
3059 tcg_gen_andi_tl(cpu_ca
, src
, (1ULL << sh
) - 1);
3060 t0
= tcg_temp_new();
3061 tcg_gen_sari_tl(t0
, src
, TARGET_LONG_BITS
- 1);
3062 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
3064 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
3065 if (is_isa300(ctx
)) {
3066 tcg_gen_mov_tl(cpu_ca32
, cpu_ca
);
3068 tcg_gen_sari_tl(dst
, src
, sh
);
3070 if (unlikely(Rc(ctx
->opcode
) != 0)) {
3071 gen_set_Rc0(ctx
, dst
);
3075 static void gen_sradi0(DisasContext
*ctx
)
3080 static void gen_sradi1(DisasContext
*ctx
)
3085 /* extswsli & extswsli. */
3086 static inline void gen_extswsli(DisasContext
*ctx
, int n
)
3088 int sh
= SH(ctx
->opcode
) + (n
<< 5);
3089 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
3090 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
3092 tcg_gen_ext32s_tl(dst
, src
);
3093 tcg_gen_shli_tl(dst
, dst
, sh
);
3094 if (unlikely(Rc(ctx
->opcode
) != 0)) {
3095 gen_set_Rc0(ctx
, dst
);
3099 static void gen_extswsli0(DisasContext
*ctx
)
3101 gen_extswsli(ctx
, 0);
3104 static void gen_extswsli1(DisasContext
*ctx
)
3106 gen_extswsli(ctx
, 1);
3110 static void gen_srd(DisasContext
*ctx
)
3114 t0
= tcg_temp_new();
3115 /* AND rS with a mask that is 0 when rB >= 0x40 */
3116 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
3117 tcg_gen_sari_tl(t0
, t0
, 0x3f);
3118 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3119 t1
= tcg_temp_new();
3120 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
3121 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3124 if (unlikely(Rc(ctx
->opcode
) != 0)) {
3125 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
3130 /*** Addressing modes ***/
3131 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
3132 static inline void gen_addr_imm_index(DisasContext
*ctx
, TCGv EA
,
3135 target_long simm
= SIMM(ctx
->opcode
);
3138 if (rA(ctx
->opcode
) == 0) {
3139 if (NARROW_MODE(ctx
)) {
3140 simm
= (uint32_t)simm
;
3142 tcg_gen_movi_tl(EA
, simm
);
3143 } else if (likely(simm
!= 0)) {
3144 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
);
3145 if (NARROW_MODE(ctx
)) {
3146 tcg_gen_ext32u_tl(EA
, EA
);
3149 if (NARROW_MODE(ctx
)) {
3150 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
3152 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
3157 static inline void gen_addr_reg_index(DisasContext
*ctx
, TCGv EA
)
3159 if (rA(ctx
->opcode
) == 0) {
3160 if (NARROW_MODE(ctx
)) {
3161 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
3163 tcg_gen_mov_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
3166 tcg_gen_add_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
3167 if (NARROW_MODE(ctx
)) {
3168 tcg_gen_ext32u_tl(EA
, EA
);
3173 static inline void gen_addr_register(DisasContext
*ctx
, TCGv EA
)
3175 if (rA(ctx
->opcode
) == 0) {
3176 tcg_gen_movi_tl(EA
, 0);
3177 } else if (NARROW_MODE(ctx
)) {
3178 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
3180 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
3184 static inline void gen_addr_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
3187 tcg_gen_addi_tl(ret
, arg1
, val
);
3188 if (NARROW_MODE(ctx
)) {
3189 tcg_gen_ext32u_tl(ret
, ret
);
3193 static inline void gen_align_no_le(DisasContext
*ctx
)
3195 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
,
3196 (ctx
->opcode
& 0x03FF0000) | POWERPC_EXCP_ALIGN_LE
);
3199 /*** Integer load ***/
3200 #define DEF_MEMOP(op) ((op) | ctx->default_tcg_memop_mask)
3201 #define BSWAP_MEMOP(op) ((op) | (ctx->default_tcg_memop_mask ^ MO_BSWAP))
3203 #define GEN_QEMU_LOAD_TL(ldop, op) \
3204 static void glue(gen_qemu_, ldop)(DisasContext *ctx, \
3208 tcg_gen_qemu_ld_tl(val, addr, ctx->mem_idx, op); \
3211 GEN_QEMU_LOAD_TL(ld8u
, DEF_MEMOP(MO_UB
))
3212 GEN_QEMU_LOAD_TL(ld16u
, DEF_MEMOP(MO_UW
))
3213 GEN_QEMU_LOAD_TL(ld16s
, DEF_MEMOP(MO_SW
))
3214 GEN_QEMU_LOAD_TL(ld32u
, DEF_MEMOP(MO_UL
))
3215 GEN_QEMU_LOAD_TL(ld32s
, DEF_MEMOP(MO_SL
))
3217 GEN_QEMU_LOAD_TL(ld16ur
, BSWAP_MEMOP(MO_UW
))
3218 GEN_QEMU_LOAD_TL(ld32ur
, BSWAP_MEMOP(MO_UL
))
3220 #define GEN_QEMU_LOAD_64(ldop, op) \
3221 static void glue(gen_qemu_, glue(ldop, _i64))(DisasContext *ctx, \
3225 tcg_gen_qemu_ld_i64(val, addr, ctx->mem_idx, op); \
3228 GEN_QEMU_LOAD_64(ld8u
, DEF_MEMOP(MO_UB
))
3229 GEN_QEMU_LOAD_64(ld16u
, DEF_MEMOP(MO_UW
))
3230 GEN_QEMU_LOAD_64(ld32u
, DEF_MEMOP(MO_UL
))
3231 GEN_QEMU_LOAD_64(ld32s
, DEF_MEMOP(MO_SL
))
3232 GEN_QEMU_LOAD_64(ld64
, DEF_MEMOP(MO_Q
))
3234 #if defined(TARGET_PPC64)
3235 GEN_QEMU_LOAD_64(ld64ur
, BSWAP_MEMOP(MO_Q
))
3238 #define GEN_QEMU_STORE_TL(stop, op) \
3239 static void glue(gen_qemu_, stop)(DisasContext *ctx, \
3243 tcg_gen_qemu_st_tl(val, addr, ctx->mem_idx, op); \
3246 #if defined(TARGET_PPC64) || !defined(CONFIG_USER_ONLY)
3247 GEN_QEMU_STORE_TL(st8
, DEF_MEMOP(MO_UB
))
3249 GEN_QEMU_STORE_TL(st16
, DEF_MEMOP(MO_UW
))
3250 GEN_QEMU_STORE_TL(st32
, DEF_MEMOP(MO_UL
))
3252 GEN_QEMU_STORE_TL(st16r
, BSWAP_MEMOP(MO_UW
))
3253 GEN_QEMU_STORE_TL(st32r
, BSWAP_MEMOP(MO_UL
))
3255 #define GEN_QEMU_STORE_64(stop, op) \
3256 static void glue(gen_qemu_, glue(stop, _i64))(DisasContext *ctx, \
3260 tcg_gen_qemu_st_i64(val, addr, ctx->mem_idx, op); \
3263 GEN_QEMU_STORE_64(st8
, DEF_MEMOP(MO_UB
))
3264 GEN_QEMU_STORE_64(st16
, DEF_MEMOP(MO_UW
))
3265 GEN_QEMU_STORE_64(st32
, DEF_MEMOP(MO_UL
))
3266 GEN_QEMU_STORE_64(st64
, DEF_MEMOP(MO_Q
))
3268 #if defined(TARGET_PPC64)
3269 GEN_QEMU_STORE_64(st64r
, BSWAP_MEMOP(MO_Q
))
3272 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2, chk) \
3273 static void glue(gen_, name##x)(DisasContext *ctx) \
3277 gen_set_access_type(ctx, ACCESS_INT); \
3278 EA = tcg_temp_new(); \
3279 gen_addr_reg_index(ctx, EA); \
3280 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
3281 tcg_temp_free(EA); \
3284 #define GEN_LDX(name, ldop, opc2, opc3, type) \
3285 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE, CHK_NONE)
3287 #define GEN_LDX_HVRM(name, ldop, opc2, opc3, type) \
3288 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE, CHK_HVRM)
3290 #define GEN_LDEPX(name, ldop, opc2, opc3) \
3291 static void glue(gen_, name##epx)(DisasContext *ctx) \
3295 gen_set_access_type(ctx, ACCESS_INT); \
3296 EA = tcg_temp_new(); \
3297 gen_addr_reg_index(ctx, EA); \
3298 tcg_gen_qemu_ld_tl(cpu_gpr[rD(ctx->opcode)], EA, PPC_TLB_EPID_LOAD, ldop);\
3299 tcg_temp_free(EA); \
3302 GEN_LDEPX(lb
, DEF_MEMOP(MO_UB
), 0x1F, 0x02)
3303 GEN_LDEPX(lh
, DEF_MEMOP(MO_UW
), 0x1F, 0x08)
3304 GEN_LDEPX(lw
, DEF_MEMOP(MO_UL
), 0x1F, 0x00)
3305 #if defined(TARGET_PPC64)
3306 GEN_LDEPX(ld
, DEF_MEMOP(MO_Q
), 0x1D, 0x00)
3309 #if defined(TARGET_PPC64)
3310 /* CI load/store variants */
3311 GEN_LDX_HVRM(ldcix
, ld64_i64
, 0x15, 0x1b, PPC_CILDST
)
3312 GEN_LDX_HVRM(lwzcix
, ld32u
, 0x15, 0x15, PPC_CILDST
)
3313 GEN_LDX_HVRM(lhzcix
, ld16u
, 0x15, 0x19, PPC_CILDST
)
3314 GEN_LDX_HVRM(lbzcix
, ld8u
, 0x15, 0x1a, PPC_CILDST
)
3317 static void gen_lq(DisasContext
*ctx
)
3322 /* lq is a legal user mode instruction starting in ISA 2.07 */
3323 bool legal_in_user_mode
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
3324 bool le_is_supported
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
3326 if (!legal_in_user_mode
&& ctx
->pr
) {
3327 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3331 if (!le_is_supported
&& ctx
->le_mode
) {
3332 gen_align_no_le(ctx
);
3335 ra
= rA(ctx
->opcode
);
3336 rd
= rD(ctx
->opcode
);
3337 if (unlikely((rd
& 1) || rd
== ra
)) {
3338 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3342 gen_set_access_type(ctx
, ACCESS_INT
);
3343 EA
= tcg_temp_new();
3344 gen_addr_imm_index(ctx
, EA
, 0x0F);
3346 /* Note that the low part is always in RD+1, even in LE mode. */
3347 lo
= cpu_gpr
[rd
+ 1];
3350 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3351 if (HAVE_ATOMIC128
) {
3352 TCGv_i32 oi
= tcg_temp_new_i32();
3354 tcg_gen_movi_i32(oi
, make_memop_idx(MO_LEQ
, ctx
->mem_idx
));
3355 gen_helper_lq_le_parallel(lo
, cpu_env
, EA
, oi
);
3357 tcg_gen_movi_i32(oi
, make_memop_idx(MO_BEQ
, ctx
->mem_idx
));
3358 gen_helper_lq_be_parallel(lo
, cpu_env
, EA
, oi
);
3360 tcg_temp_free_i32(oi
);
3361 tcg_gen_ld_i64(hi
, cpu_env
, offsetof(CPUPPCState
, retxh
));
3363 /* Restart with exclusive lock. */
3364 gen_helper_exit_atomic(cpu_env
);
3365 ctx
->base
.is_jmp
= DISAS_NORETURN
;
3367 } else if (ctx
->le_mode
) {
3368 tcg_gen_qemu_ld_i64(lo
, EA
, ctx
->mem_idx
, MO_LEQ
);
3369 gen_addr_add(ctx
, EA
, EA
, 8);
3370 tcg_gen_qemu_ld_i64(hi
, EA
, ctx
->mem_idx
, MO_LEQ
);
3372 tcg_gen_qemu_ld_i64(hi
, EA
, ctx
->mem_idx
, MO_BEQ
);
3373 gen_addr_add(ctx
, EA
, EA
, 8);
3374 tcg_gen_qemu_ld_i64(lo
, EA
, ctx
->mem_idx
, MO_BEQ
);
3380 /*** Integer store ***/
3381 #define GEN_STX_E(name, stop, opc2, opc3, type, type2, chk) \
3382 static void glue(gen_, name##x)(DisasContext *ctx) \
3386 gen_set_access_type(ctx, ACCESS_INT); \
3387 EA = tcg_temp_new(); \
3388 gen_addr_reg_index(ctx, EA); \
3389 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
3390 tcg_temp_free(EA); \
3392 #define GEN_STX(name, stop, opc2, opc3, type) \
3393 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE, CHK_NONE)
3395 #define GEN_STX_HVRM(name, stop, opc2, opc3, type) \
3396 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE, CHK_HVRM)
3398 #define GEN_STEPX(name, stop, opc2, opc3) \
3399 static void glue(gen_, name##epx)(DisasContext *ctx) \
3403 gen_set_access_type(ctx, ACCESS_INT); \
3404 EA = tcg_temp_new(); \
3405 gen_addr_reg_index(ctx, EA); \
3406 tcg_gen_qemu_st_tl( \
3407 cpu_gpr[rD(ctx->opcode)], EA, PPC_TLB_EPID_STORE, stop); \
3408 tcg_temp_free(EA); \
3411 GEN_STEPX(stb
, DEF_MEMOP(MO_UB
), 0x1F, 0x06)
3412 GEN_STEPX(sth
, DEF_MEMOP(MO_UW
), 0x1F, 0x0C)
3413 GEN_STEPX(stw
, DEF_MEMOP(MO_UL
), 0x1F, 0x04)
3414 #if defined(TARGET_PPC64)
3415 GEN_STEPX(std
, DEF_MEMOP(MO_Q
), 0x1d, 0x04)
3418 #if defined(TARGET_PPC64)
3419 GEN_STX_HVRM(stdcix
, st64_i64
, 0x15, 0x1f, PPC_CILDST
)
3420 GEN_STX_HVRM(stwcix
, st32
, 0x15, 0x1c, PPC_CILDST
)
3421 GEN_STX_HVRM(sthcix
, st16
, 0x15, 0x1d, PPC_CILDST
)
3422 GEN_STX_HVRM(stbcix
, st8
, 0x15, 0x1e, PPC_CILDST
)
3424 static void gen_std(DisasContext
*ctx
)
3429 rs
= rS(ctx
->opcode
);
3430 if ((ctx
->opcode
& 0x3) == 0x2) { /* stq */
3431 bool legal_in_user_mode
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
3432 bool le_is_supported
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
3435 if (!(ctx
->insns_flags
& PPC_64BX
)) {
3436 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3439 if (!legal_in_user_mode
&& ctx
->pr
) {
3440 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3444 if (!le_is_supported
&& ctx
->le_mode
) {
3445 gen_align_no_le(ctx
);
3449 if (unlikely(rs
& 1)) {
3450 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3453 gen_set_access_type(ctx
, ACCESS_INT
);
3454 EA
= tcg_temp_new();
3455 gen_addr_imm_index(ctx
, EA
, 0x03);
3457 /* Note that the low part is always in RS+1, even in LE mode. */
3458 lo
= cpu_gpr
[rs
+ 1];
3461 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3462 if (HAVE_ATOMIC128
) {
3463 TCGv_i32 oi
= tcg_temp_new_i32();
3465 tcg_gen_movi_i32(oi
, make_memop_idx(MO_LEQ
, ctx
->mem_idx
));
3466 gen_helper_stq_le_parallel(cpu_env
, EA
, lo
, hi
, oi
);
3468 tcg_gen_movi_i32(oi
, make_memop_idx(MO_BEQ
, ctx
->mem_idx
));
3469 gen_helper_stq_be_parallel(cpu_env
, EA
, lo
, hi
, oi
);
3471 tcg_temp_free_i32(oi
);
3473 /* Restart with exclusive lock. */
3474 gen_helper_exit_atomic(cpu_env
);
3475 ctx
->base
.is_jmp
= DISAS_NORETURN
;
3477 } else if (ctx
->le_mode
) {
3478 tcg_gen_qemu_st_i64(lo
, EA
, ctx
->mem_idx
, MO_LEQ
);
3479 gen_addr_add(ctx
, EA
, EA
, 8);
3480 tcg_gen_qemu_st_i64(hi
, EA
, ctx
->mem_idx
, MO_LEQ
);
3482 tcg_gen_qemu_st_i64(hi
, EA
, ctx
->mem_idx
, MO_BEQ
);
3483 gen_addr_add(ctx
, EA
, EA
, 8);
3484 tcg_gen_qemu_st_i64(lo
, EA
, ctx
->mem_idx
, MO_BEQ
);
3489 if (Rc(ctx
->opcode
)) {
3490 if (unlikely(rA(ctx
->opcode
) == 0)) {
3491 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3495 gen_set_access_type(ctx
, ACCESS_INT
);
3496 EA
= tcg_temp_new();
3497 gen_addr_imm_index(ctx
, EA
, 0x03);
3498 gen_qemu_st64_i64(ctx
, cpu_gpr
[rs
], EA
);
3499 if (Rc(ctx
->opcode
)) {
3500 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
3506 /*** Integer load and store with byte reverse ***/
3509 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
);
3512 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
);
3514 #if defined(TARGET_PPC64)
3516 GEN_LDX_E(ldbr
, ld64ur_i64
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
, CHK_NONE
);
3518 GEN_STX_E(stdbr
, st64r_i64
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
, CHK_NONE
);
3519 #endif /* TARGET_PPC64 */
3522 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
);
3524 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
);
3526 /*** Integer load and store multiple ***/
3529 static void gen_lmw(DisasContext
*ctx
)
3535 gen_align_no_le(ctx
);
3538 gen_set_access_type(ctx
, ACCESS_INT
);
3539 t0
= tcg_temp_new();
3540 t1
= tcg_const_i32(rD(ctx
->opcode
));
3541 gen_addr_imm_index(ctx
, t0
, 0);
3542 gen_helper_lmw(cpu_env
, t0
, t1
);
3544 tcg_temp_free_i32(t1
);
3548 static void gen_stmw(DisasContext
*ctx
)
3554 gen_align_no_le(ctx
);
3557 gen_set_access_type(ctx
, ACCESS_INT
);
3558 t0
= tcg_temp_new();
3559 t1
= tcg_const_i32(rS(ctx
->opcode
));
3560 gen_addr_imm_index(ctx
, t0
, 0);
3561 gen_helper_stmw(cpu_env
, t0
, t1
);
3563 tcg_temp_free_i32(t1
);
3566 /*** Integer load and store strings ***/
3570 * PowerPC32 specification says we must generate an exception if rA is
3571 * in the range of registers to be loaded. In an other hand, IBM says
3572 * this is valid, but rA won't be loaded. For now, I'll follow the
3575 static void gen_lswi(DisasContext
*ctx
)
3579 int nb
= NB(ctx
->opcode
);
3580 int start
= rD(ctx
->opcode
);
3581 int ra
= rA(ctx
->opcode
);
3585 gen_align_no_le(ctx
);
3591 nr
= DIV_ROUND_UP(nb
, 4);
3592 if (unlikely(lsw_reg_in_range(start
, nr
, ra
))) {
3593 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
3596 gen_set_access_type(ctx
, ACCESS_INT
);
3597 t0
= tcg_temp_new();
3598 gen_addr_register(ctx
, t0
);
3599 t1
= tcg_const_i32(nb
);
3600 t2
= tcg_const_i32(start
);
3601 gen_helper_lsw(cpu_env
, t0
, t1
, t2
);
3603 tcg_temp_free_i32(t1
);
3604 tcg_temp_free_i32(t2
);
3608 static void gen_lswx(DisasContext
*ctx
)
3611 TCGv_i32 t1
, t2
, t3
;
3614 gen_align_no_le(ctx
);
3617 gen_set_access_type(ctx
, ACCESS_INT
);
3618 t0
= tcg_temp_new();
3619 gen_addr_reg_index(ctx
, t0
);
3620 t1
= tcg_const_i32(rD(ctx
->opcode
));
3621 t2
= tcg_const_i32(rA(ctx
->opcode
));
3622 t3
= tcg_const_i32(rB(ctx
->opcode
));
3623 gen_helper_lswx(cpu_env
, t0
, t1
, t2
, t3
);
3625 tcg_temp_free_i32(t1
);
3626 tcg_temp_free_i32(t2
);
3627 tcg_temp_free_i32(t3
);
3631 static void gen_stswi(DisasContext
*ctx
)
3635 int nb
= NB(ctx
->opcode
);
3638 gen_align_no_le(ctx
);
3641 gen_set_access_type(ctx
, ACCESS_INT
);
3642 t0
= tcg_temp_new();
3643 gen_addr_register(ctx
, t0
);
3647 t1
= tcg_const_i32(nb
);
3648 t2
= tcg_const_i32(rS(ctx
->opcode
));
3649 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3651 tcg_temp_free_i32(t1
);
3652 tcg_temp_free_i32(t2
);
3656 static void gen_stswx(DisasContext
*ctx
)
3662 gen_align_no_le(ctx
);
3665 gen_set_access_type(ctx
, ACCESS_INT
);
3666 t0
= tcg_temp_new();
3667 gen_addr_reg_index(ctx
, t0
);
3668 t1
= tcg_temp_new_i32();
3669 tcg_gen_trunc_tl_i32(t1
, cpu_xer
);
3670 tcg_gen_andi_i32(t1
, t1
, 0x7F);
3671 t2
= tcg_const_i32(rS(ctx
->opcode
));
3672 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3674 tcg_temp_free_i32(t1
);
3675 tcg_temp_free_i32(t2
);
3678 /*** Memory synchronisation ***/
3680 static void gen_eieio(DisasContext
*ctx
)
3682 TCGBar bar
= TCG_MO_LD_ST
;
3685 * POWER9 has a eieio instruction variant using bit 6 as a hint to
3686 * tell the CPU it is a store-forwarding barrier.
3688 if (ctx
->opcode
& 0x2000000) {
3690 * ISA says that "Reserved fields in instructions are ignored
3691 * by the processor". So ignore the bit 6 on non-POWER9 CPU but
3692 * as this is not an instruction software should be using,
3693 * complain to the user.
3695 if (!(ctx
->insns_flags2
& PPC2_ISA300
)) {
3696 qemu_log_mask(LOG_GUEST_ERROR
, "invalid eieio using bit 6 at @"
3697 TARGET_FMT_lx
"\n", ctx
->cia
);
3703 tcg_gen_mb(bar
| TCG_BAR_SC
);
3706 #if !defined(CONFIG_USER_ONLY)
3707 static inline void gen_check_tlb_flush(DisasContext
*ctx
, bool global
)
3712 if (!ctx
->lazy_tlb_flush
) {
3715 l
= gen_new_label();
3716 t
= tcg_temp_new_i32();
3717 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUPPCState
, tlb_need_flush
));
3718 tcg_gen_brcondi_i32(TCG_COND_EQ
, t
, 0, l
);
3720 gen_helper_check_tlb_flush_global(cpu_env
);
3722 gen_helper_check_tlb_flush_local(cpu_env
);
3725 tcg_temp_free_i32(t
);
3728 static inline void gen_check_tlb_flush(DisasContext
*ctx
, bool global
) { }
3732 static void gen_isync(DisasContext
*ctx
)
3735 * We need to check for a pending TLB flush. This can only happen in
3736 * kernel mode however so check MSR_PR
3739 gen_check_tlb_flush(ctx
, false);
3741 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_SC
);
3742 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
3745 #define MEMOP_GET_SIZE(x) (1 << ((x) & MO_SIZE))
3747 static void gen_load_locked(DisasContext
*ctx
, MemOp memop
)
3749 TCGv gpr
= cpu_gpr
[rD(ctx
->opcode
)];
3750 TCGv t0
= tcg_temp_new();
3752 gen_set_access_type(ctx
, ACCESS_RES
);
3753 gen_addr_reg_index(ctx
, t0
);
3754 tcg_gen_qemu_ld_tl(gpr
, t0
, ctx
->mem_idx
, memop
| MO_ALIGN
);
3755 tcg_gen_mov_tl(cpu_reserve
, t0
);
3756 tcg_gen_mov_tl(cpu_reserve_val
, gpr
);
3757 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
3761 #define LARX(name, memop) \
3762 static void gen_##name(DisasContext *ctx) \
3764 gen_load_locked(ctx, memop); \
3768 LARX(lbarx
, DEF_MEMOP(MO_UB
))
3769 LARX(lharx
, DEF_MEMOP(MO_UW
))
3770 LARX(lwarx
, DEF_MEMOP(MO_UL
))
3772 static void gen_fetch_inc_conditional(DisasContext
*ctx
, MemOp memop
,
3773 TCGv EA
, TCGCond cond
, int addend
)
3775 TCGv t
= tcg_temp_new();
3776 TCGv t2
= tcg_temp_new();
3777 TCGv u
= tcg_temp_new();
3779 tcg_gen_qemu_ld_tl(t
, EA
, ctx
->mem_idx
, memop
);
3780 tcg_gen_addi_tl(t2
, EA
, MEMOP_GET_SIZE(memop
));
3781 tcg_gen_qemu_ld_tl(t2
, t2
, ctx
->mem_idx
, memop
);
3782 tcg_gen_addi_tl(u
, t
, addend
);
3784 /* E.g. for fetch and increment bounded... */
3785 /* mem(EA,s) = (t != t2 ? u = t + 1 : t) */
3786 tcg_gen_movcond_tl(cond
, u
, t
, t2
, u
, t
);
3787 tcg_gen_qemu_st_tl(u
, EA
, ctx
->mem_idx
, memop
);
3789 /* RT = (t != t2 ? t : u = 1<<(s*8-1)) */
3790 tcg_gen_movi_tl(u
, 1 << (MEMOP_GET_SIZE(memop
) * 8 - 1));
3791 tcg_gen_movcond_tl(cond
, cpu_gpr
[rD(ctx
->opcode
)], t
, t2
, t
, u
);
3798 static void gen_ld_atomic(DisasContext
*ctx
, MemOp memop
)
3800 uint32_t gpr_FC
= FC(ctx
->opcode
);
3801 TCGv EA
= tcg_temp_new();
3802 int rt
= rD(ctx
->opcode
);
3806 gen_addr_register(ctx
, EA
);
3808 src
= cpu_gpr
[(rt
+ 1) & 31];
3810 need_serial
= false;
3813 case 0: /* Fetch and add */
3814 tcg_gen_atomic_fetch_add_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3816 case 1: /* Fetch and xor */
3817 tcg_gen_atomic_fetch_xor_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3819 case 2: /* Fetch and or */
3820 tcg_gen_atomic_fetch_or_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3822 case 3: /* Fetch and 'and' */
3823 tcg_gen_atomic_fetch_and_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3825 case 4: /* Fetch and max unsigned */
3826 tcg_gen_atomic_fetch_umax_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3828 case 5: /* Fetch and max signed */
3829 tcg_gen_atomic_fetch_smax_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3831 case 6: /* Fetch and min unsigned */
3832 tcg_gen_atomic_fetch_umin_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3834 case 7: /* Fetch and min signed */
3835 tcg_gen_atomic_fetch_smin_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3838 tcg_gen_atomic_xchg_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
3841 case 16: /* Compare and swap not equal */
3842 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3845 TCGv t0
= tcg_temp_new();
3846 TCGv t1
= tcg_temp_new();
3848 tcg_gen_qemu_ld_tl(t0
, EA
, ctx
->mem_idx
, memop
);
3849 if ((memop
& MO_SIZE
) == MO_64
|| TARGET_LONG_BITS
== 32) {
3850 tcg_gen_mov_tl(t1
, src
);
3852 tcg_gen_ext32u_tl(t1
, src
);
3854 tcg_gen_movcond_tl(TCG_COND_NE
, t1
, t0
, t1
,
3855 cpu_gpr
[(rt
+ 2) & 31], t0
);
3856 tcg_gen_qemu_st_tl(t1
, EA
, ctx
->mem_idx
, memop
);
3857 tcg_gen_mov_tl(dst
, t0
);
3864 case 24: /* Fetch and increment bounded */
3865 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3868 gen_fetch_inc_conditional(ctx
, memop
, EA
, TCG_COND_NE
, 1);
3871 case 25: /* Fetch and increment equal */
3872 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3875 gen_fetch_inc_conditional(ctx
, memop
, EA
, TCG_COND_EQ
, 1);
3878 case 28: /* Fetch and decrement bounded */
3879 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3882 gen_fetch_inc_conditional(ctx
, memop
, EA
, TCG_COND_NE
, -1);
3887 /* invoke data storage error handler */
3888 gen_exception_err(ctx
, POWERPC_EXCP_DSI
, POWERPC_EXCP_INVAL
);
3893 /* Restart with exclusive lock. */
3894 gen_helper_exit_atomic(cpu_env
);
3895 ctx
->base
.is_jmp
= DISAS_NORETURN
;
3899 static void gen_lwat(DisasContext
*ctx
)
3901 gen_ld_atomic(ctx
, DEF_MEMOP(MO_UL
));
3905 static void gen_ldat(DisasContext
*ctx
)
3907 gen_ld_atomic(ctx
, DEF_MEMOP(MO_Q
));
3911 static void gen_st_atomic(DisasContext
*ctx
, MemOp memop
)
3913 uint32_t gpr_FC
= FC(ctx
->opcode
);
3914 TCGv EA
= tcg_temp_new();
3917 gen_addr_register(ctx
, EA
);
3918 src
= cpu_gpr
[rD(ctx
->opcode
)];
3919 discard
= tcg_temp_new();
3923 case 0: /* add and Store */
3924 tcg_gen_atomic_add_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3926 case 1: /* xor and Store */
3927 tcg_gen_atomic_xor_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3929 case 2: /* Or and Store */
3930 tcg_gen_atomic_or_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3932 case 3: /* 'and' and Store */
3933 tcg_gen_atomic_and_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3935 case 4: /* Store max unsigned */
3936 tcg_gen_atomic_umax_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3938 case 5: /* Store max signed */
3939 tcg_gen_atomic_smax_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3941 case 6: /* Store min unsigned */
3942 tcg_gen_atomic_umin_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3944 case 7: /* Store min signed */
3945 tcg_gen_atomic_smin_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
3947 case 24: /* Store twin */
3948 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3949 /* Restart with exclusive lock. */
3950 gen_helper_exit_atomic(cpu_env
);
3951 ctx
->base
.is_jmp
= DISAS_NORETURN
;
3953 TCGv t
= tcg_temp_new();
3954 TCGv t2
= tcg_temp_new();
3955 TCGv s
= tcg_temp_new();
3956 TCGv s2
= tcg_temp_new();
3957 TCGv ea_plus_s
= tcg_temp_new();
3959 tcg_gen_qemu_ld_tl(t
, EA
, ctx
->mem_idx
, memop
);
3960 tcg_gen_addi_tl(ea_plus_s
, EA
, MEMOP_GET_SIZE(memop
));
3961 tcg_gen_qemu_ld_tl(t2
, ea_plus_s
, ctx
->mem_idx
, memop
);
3962 tcg_gen_movcond_tl(TCG_COND_EQ
, s
, t
, t2
, src
, t
);
3963 tcg_gen_movcond_tl(TCG_COND_EQ
, s2
, t
, t2
, src
, t2
);
3964 tcg_gen_qemu_st_tl(s
, EA
, ctx
->mem_idx
, memop
);
3965 tcg_gen_qemu_st_tl(s2
, ea_plus_s
, ctx
->mem_idx
, memop
);
3967 tcg_temp_free(ea_plus_s
);
3975 /* invoke data storage error handler */
3976 gen_exception_err(ctx
, POWERPC_EXCP_DSI
, POWERPC_EXCP_INVAL
);
3978 tcg_temp_free(discard
);
3982 static void gen_stwat(DisasContext
*ctx
)
3984 gen_st_atomic(ctx
, DEF_MEMOP(MO_UL
));
3988 static void gen_stdat(DisasContext
*ctx
)
3990 gen_st_atomic(ctx
, DEF_MEMOP(MO_Q
));
3994 static void gen_conditional_store(DisasContext
*ctx
, MemOp memop
)
3996 TCGLabel
*l1
= gen_new_label();
3997 TCGLabel
*l2
= gen_new_label();
3998 TCGv t0
= tcg_temp_new();
3999 int reg
= rS(ctx
->opcode
);
4001 gen_set_access_type(ctx
, ACCESS_RES
);
4002 gen_addr_reg_index(ctx
, t0
);
4003 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
4006 t0
= tcg_temp_new();
4007 tcg_gen_atomic_cmpxchg_tl(t0
, cpu_reserve
, cpu_reserve_val
,
4008 cpu_gpr
[reg
], ctx
->mem_idx
,
4009 DEF_MEMOP(memop
) | MO_ALIGN
);
4010 tcg_gen_setcond_tl(TCG_COND_EQ
, t0
, t0
, cpu_reserve_val
);
4011 tcg_gen_shli_tl(t0
, t0
, CRF_EQ_BIT
);
4012 tcg_gen_or_tl(t0
, t0
, cpu_so
);
4013 tcg_gen_trunc_tl_i32(cpu_crf
[0], t0
);
4020 * Address mismatch implies failure. But we still need to provide
4021 * the memory barrier semantics of the instruction.
4023 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
4024 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
4027 tcg_gen_movi_tl(cpu_reserve
, -1);
4030 #define STCX(name, memop) \
4031 static void gen_##name(DisasContext *ctx) \
4033 gen_conditional_store(ctx, memop); \
4036 STCX(stbcx_
, DEF_MEMOP(MO_UB
))
4037 STCX(sthcx_
, DEF_MEMOP(MO_UW
))
4038 STCX(stwcx_
, DEF_MEMOP(MO_UL
))
4040 #if defined(TARGET_PPC64)
4042 LARX(ldarx
, DEF_MEMOP(MO_Q
))
4044 STCX(stdcx_
, DEF_MEMOP(MO_Q
))
4047 static void gen_lqarx(DisasContext
*ctx
)
4049 int rd
= rD(ctx
->opcode
);
4052 if (unlikely((rd
& 1) || (rd
== rA(ctx
->opcode
)) ||
4053 (rd
== rB(ctx
->opcode
)))) {
4054 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
4058 gen_set_access_type(ctx
, ACCESS_RES
);
4059 EA
= tcg_temp_new();
4060 gen_addr_reg_index(ctx
, EA
);
4062 /* Note that the low part is always in RD+1, even in LE mode. */
4063 lo
= cpu_gpr
[rd
+ 1];
4066 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
4067 if (HAVE_ATOMIC128
) {
4068 TCGv_i32 oi
= tcg_temp_new_i32();
4070 tcg_gen_movi_i32(oi
, make_memop_idx(MO_LEQ
| MO_ALIGN_16
,
4072 gen_helper_lq_le_parallel(lo
, cpu_env
, EA
, oi
);
4074 tcg_gen_movi_i32(oi
, make_memop_idx(MO_BEQ
| MO_ALIGN_16
,
4076 gen_helper_lq_be_parallel(lo
, cpu_env
, EA
, oi
);
4078 tcg_temp_free_i32(oi
);
4079 tcg_gen_ld_i64(hi
, cpu_env
, offsetof(CPUPPCState
, retxh
));
4081 /* Restart with exclusive lock. */
4082 gen_helper_exit_atomic(cpu_env
);
4083 ctx
->base
.is_jmp
= DISAS_NORETURN
;
4087 } else if (ctx
->le_mode
) {
4088 tcg_gen_qemu_ld_i64(lo
, EA
, ctx
->mem_idx
, MO_LEQ
| MO_ALIGN_16
);
4089 tcg_gen_mov_tl(cpu_reserve
, EA
);
4090 gen_addr_add(ctx
, EA
, EA
, 8);
4091 tcg_gen_qemu_ld_i64(hi
, EA
, ctx
->mem_idx
, MO_LEQ
);
4093 tcg_gen_qemu_ld_i64(hi
, EA
, ctx
->mem_idx
, MO_BEQ
| MO_ALIGN_16
);
4094 tcg_gen_mov_tl(cpu_reserve
, EA
);
4095 gen_addr_add(ctx
, EA
, EA
, 8);
4096 tcg_gen_qemu_ld_i64(lo
, EA
, ctx
->mem_idx
, MO_BEQ
);
4100 tcg_gen_st_tl(hi
, cpu_env
, offsetof(CPUPPCState
, reserve_val
));
4101 tcg_gen_st_tl(lo
, cpu_env
, offsetof(CPUPPCState
, reserve_val2
));
4105 static void gen_stqcx_(DisasContext
*ctx
)
4107 int rs
= rS(ctx
->opcode
);
4110 if (unlikely(rs
& 1)) {
4111 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
4115 gen_set_access_type(ctx
, ACCESS_RES
);
4116 EA
= tcg_temp_new();
4117 gen_addr_reg_index(ctx
, EA
);
4119 /* Note that the low part is always in RS+1, even in LE mode. */
4120 lo
= cpu_gpr
[rs
+ 1];
4123 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
4124 if (HAVE_CMPXCHG128
) {
4125 TCGv_i32 oi
= tcg_const_i32(DEF_MEMOP(MO_Q
) | MO_ALIGN_16
);
4127 gen_helper_stqcx_le_parallel(cpu_crf
[0], cpu_env
,
4130 gen_helper_stqcx_be_parallel(cpu_crf
[0], cpu_env
,
4133 tcg_temp_free_i32(oi
);
4135 /* Restart with exclusive lock. */
4136 gen_helper_exit_atomic(cpu_env
);
4137 ctx
->base
.is_jmp
= DISAS_NORETURN
;
4141 TCGLabel
*lab_fail
= gen_new_label();
4142 TCGLabel
*lab_over
= gen_new_label();
4143 TCGv_i64 t0
= tcg_temp_new_i64();
4144 TCGv_i64 t1
= tcg_temp_new_i64();
4146 tcg_gen_brcond_tl(TCG_COND_NE
, EA
, cpu_reserve
, lab_fail
);
4149 gen_qemu_ld64_i64(ctx
, t0
, cpu_reserve
);
4150 tcg_gen_ld_i64(t1
, cpu_env
, (ctx
->le_mode
4151 ? offsetof(CPUPPCState
, reserve_val2
)
4152 : offsetof(CPUPPCState
, reserve_val
)));
4153 tcg_gen_brcond_i64(TCG_COND_NE
, t0
, t1
, lab_fail
);
4155 tcg_gen_addi_i64(t0
, cpu_reserve
, 8);
4156 gen_qemu_ld64_i64(ctx
, t0
, t0
);
4157 tcg_gen_ld_i64(t1
, cpu_env
, (ctx
->le_mode
4158 ? offsetof(CPUPPCState
, reserve_val
)
4159 : offsetof(CPUPPCState
, reserve_val2
)));
4160 tcg_gen_brcond_i64(TCG_COND_NE
, t0
, t1
, lab_fail
);
4163 gen_qemu_st64_i64(ctx
, ctx
->le_mode
? lo
: hi
, cpu_reserve
);
4164 tcg_gen_addi_i64(t0
, cpu_reserve
, 8);
4165 gen_qemu_st64_i64(ctx
, ctx
->le_mode
? hi
: lo
, t0
);
4167 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
4168 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], CRF_EQ
);
4169 tcg_gen_br(lab_over
);
4171 gen_set_label(lab_fail
);
4172 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
4174 gen_set_label(lab_over
);
4175 tcg_gen_movi_tl(cpu_reserve
, -1);
4176 tcg_temp_free_i64(t0
);
4177 tcg_temp_free_i64(t1
);
4180 #endif /* defined(TARGET_PPC64) */
4183 static void gen_sync(DisasContext
*ctx
)
4185 uint32_t l
= (ctx
->opcode
>> 21) & 3;
4188 * We may need to check for a pending TLB flush.
4190 * We do this on ptesync (l == 2) on ppc64 and any sync pn ppc32.
4192 * Additionally, this can only happen in kernel mode however so
4193 * check MSR_PR as well.
4195 if (((l
== 2) || !(ctx
->insns_flags
& PPC_64B
)) && !ctx
->pr
) {
4196 gen_check_tlb_flush(ctx
, true);
4198 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_SC
);
4202 static void gen_wait(DisasContext
*ctx
)
4204 TCGv_i32 t0
= tcg_const_i32(1);
4205 tcg_gen_st_i32(t0
, cpu_env
,
4206 -offsetof(PowerPCCPU
, env
) + offsetof(CPUState
, halted
));
4207 tcg_temp_free_i32(t0
);
4208 /* Stop translation, as the CPU is supposed to sleep from now */
4209 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
4212 #if defined(TARGET_PPC64)
4213 static void gen_doze(DisasContext
*ctx
)
4215 #if defined(CONFIG_USER_ONLY)
4221 t
= tcg_const_i32(PPC_PM_DOZE
);
4222 gen_helper_pminsn(cpu_env
, t
);
4223 tcg_temp_free_i32(t
);
4224 /* Stop translation, as the CPU is supposed to sleep from now */
4225 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
4226 #endif /* defined(CONFIG_USER_ONLY) */
4229 static void gen_nap(DisasContext
*ctx
)
4231 #if defined(CONFIG_USER_ONLY)
4237 t
= tcg_const_i32(PPC_PM_NAP
);
4238 gen_helper_pminsn(cpu_env
, t
);
4239 tcg_temp_free_i32(t
);
4240 /* Stop translation, as the CPU is supposed to sleep from now */
4241 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
4242 #endif /* defined(CONFIG_USER_ONLY) */
4245 static void gen_stop(DisasContext
*ctx
)
4247 #if defined(CONFIG_USER_ONLY)
4253 t
= tcg_const_i32(PPC_PM_STOP
);
4254 gen_helper_pminsn(cpu_env
, t
);
4255 tcg_temp_free_i32(t
);
4256 /* Stop translation, as the CPU is supposed to sleep from now */
4257 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
4258 #endif /* defined(CONFIG_USER_ONLY) */
4261 static void gen_sleep(DisasContext
*ctx
)
4263 #if defined(CONFIG_USER_ONLY)
4269 t
= tcg_const_i32(PPC_PM_SLEEP
);
4270 gen_helper_pminsn(cpu_env
, t
);
4271 tcg_temp_free_i32(t
);
4272 /* Stop translation, as the CPU is supposed to sleep from now */
4273 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
4274 #endif /* defined(CONFIG_USER_ONLY) */
4277 static void gen_rvwinkle(DisasContext
*ctx
)
4279 #if defined(CONFIG_USER_ONLY)
4285 t
= tcg_const_i32(PPC_PM_RVWINKLE
);
4286 gen_helper_pminsn(cpu_env
, t
);
4287 tcg_temp_free_i32(t
);
4288 /* Stop translation, as the CPU is supposed to sleep from now */
4289 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
4290 #endif /* defined(CONFIG_USER_ONLY) */
4292 #endif /* #if defined(TARGET_PPC64) */
4294 static inline void gen_update_cfar(DisasContext
*ctx
, target_ulong nip
)
4296 #if defined(TARGET_PPC64)
4297 if (ctx
->has_cfar
) {
4298 tcg_gen_movi_tl(cpu_cfar
, nip
);
4303 static inline bool use_goto_tb(DisasContext
*ctx
, target_ulong dest
)
4305 return translator_use_goto_tb(&ctx
->base
, dest
);
4308 static void gen_lookup_and_goto_ptr(DisasContext
*ctx
)
4310 int sse
= ctx
->singlestep_enabled
;
4311 if (unlikely(sse
)) {
4312 if (sse
& GDBSTUB_SINGLE_STEP
) {
4313 gen_debug_exception(ctx
);
4314 } else if (sse
& (CPU_SINGLE_STEP
| CPU_BRANCH_STEP
)) {
4315 gen_helper_raise_exception(cpu_env
, tcg_constant_i32(gen_prep_dbgex(ctx
)));
4317 tcg_gen_exit_tb(NULL
, 0);
4320 tcg_gen_lookup_and_goto_ptr();
4325 static void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
4327 if (NARROW_MODE(ctx
)) {
4328 dest
= (uint32_t) dest
;
4330 if (use_goto_tb(ctx
, dest
)) {
4332 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
4333 tcg_gen_exit_tb(ctx
->base
.tb
, n
);
4335 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
4336 gen_lookup_and_goto_ptr(ctx
);
4340 static inline void gen_setlr(DisasContext
*ctx
, target_ulong nip
)
4342 if (NARROW_MODE(ctx
)) {
4343 nip
= (uint32_t)nip
;
4345 tcg_gen_movi_tl(cpu_lr
, nip
);
4349 static void gen_b(DisasContext
*ctx
)
4351 target_ulong li
, target
;
4353 /* sign extend LI */
4354 li
= LI(ctx
->opcode
);
4355 li
= (li
^ 0x02000000) - 0x02000000;
4356 if (likely(AA(ctx
->opcode
) == 0)) {
4357 target
= ctx
->cia
+ li
;
4361 if (LK(ctx
->opcode
)) {
4362 gen_setlr(ctx
, ctx
->base
.pc_next
);
4364 gen_update_cfar(ctx
, ctx
->cia
);
4365 gen_goto_tb(ctx
, 0, target
);
4366 ctx
->base
.is_jmp
= DISAS_NORETURN
;
4374 static void gen_bcond(DisasContext
*ctx
, int type
)
4376 uint32_t bo
= BO(ctx
->opcode
);
4380 if (type
== BCOND_LR
|| type
== BCOND_CTR
|| type
== BCOND_TAR
) {
4381 target
= tcg_temp_local_new();
4382 if (type
== BCOND_CTR
) {
4383 tcg_gen_mov_tl(target
, cpu_ctr
);
4384 } else if (type
== BCOND_TAR
) {
4385 gen_load_spr(target
, SPR_TAR
);
4387 tcg_gen_mov_tl(target
, cpu_lr
);
4392 if (LK(ctx
->opcode
)) {
4393 gen_setlr(ctx
, ctx
->base
.pc_next
);
4395 l1
= gen_new_label();
4396 if ((bo
& 0x4) == 0) {
4397 /* Decrement and test CTR */
4398 TCGv temp
= tcg_temp_new();
4400 if (type
== BCOND_CTR
) {
4402 * All ISAs up to v3 describe this form of bcctr as invalid but
4403 * some processors, ie. 64-bit server processors compliant with
4404 * arch 2.x, do implement a "test and decrement" logic instead,
4405 * as described in their respective UMs. This logic involves CTR
4406 * to act as both the branch target and a counter, which makes
4407 * it basically useless and thus never used in real code.
4409 * This form was hence chosen to trigger extra micro-architectural
4410 * side-effect on real HW needed for the Spectre v2 workaround.
4411 * It is up to guests that implement such workaround, ie. linux, to
4412 * use this form in a way it just triggers the side-effect without
4413 * doing anything else harmful.
4415 if (unlikely(!is_book3s_arch2x(ctx
))) {
4416 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
4417 tcg_temp_free(temp
);
4418 tcg_temp_free(target
);
4422 if (NARROW_MODE(ctx
)) {
4423 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
4425 tcg_gen_mov_tl(temp
, cpu_ctr
);
4428 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
4430 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
4432 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
4434 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
4435 if (NARROW_MODE(ctx
)) {
4436 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
4438 tcg_gen_mov_tl(temp
, cpu_ctr
);
4441 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
4443 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
4446 tcg_temp_free(temp
);
4448 if ((bo
& 0x10) == 0) {
4450 uint32_t bi
= BI(ctx
->opcode
);
4451 uint32_t mask
= 0x08 >> (bi
& 0x03);
4452 TCGv_i32 temp
= tcg_temp_new_i32();
4455 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
4456 tcg_gen_brcondi_i32(TCG_COND_EQ
, temp
, 0, l1
);
4458 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
4459 tcg_gen_brcondi_i32(TCG_COND_NE
, temp
, 0, l1
);
4461 tcg_temp_free_i32(temp
);
4463 gen_update_cfar(ctx
, ctx
->cia
);
4464 if (type
== BCOND_IM
) {
4465 target_ulong li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
4466 if (likely(AA(ctx
->opcode
) == 0)) {
4467 gen_goto_tb(ctx
, 0, ctx
->cia
+ li
);
4469 gen_goto_tb(ctx
, 0, li
);
4472 if (NARROW_MODE(ctx
)) {
4473 tcg_gen_andi_tl(cpu_nip
, target
, (uint32_t)~3);
4475 tcg_gen_andi_tl(cpu_nip
, target
, ~3);
4477 gen_lookup_and_goto_ptr(ctx
);
4478 tcg_temp_free(target
);
4480 if ((bo
& 0x14) != 0x14) {
4481 /* fallthrough case */
4483 gen_goto_tb(ctx
, 1, ctx
->base
.pc_next
);
4485 ctx
->base
.is_jmp
= DISAS_NORETURN
;
4488 static void gen_bc(DisasContext
*ctx
)
4490 gen_bcond(ctx
, BCOND_IM
);
4493 static void gen_bcctr(DisasContext
*ctx
)
4495 gen_bcond(ctx
, BCOND_CTR
);
4498 static void gen_bclr(DisasContext
*ctx
)
4500 gen_bcond(ctx
, BCOND_LR
);
4503 static void gen_bctar(DisasContext
*ctx
)
4505 gen_bcond(ctx
, BCOND_TAR
);
4508 /*** Condition register logical ***/
4509 #define GEN_CRLOGIC(name, tcg_op, opc) \
4510 static void glue(gen_, name)(DisasContext *ctx) \
4515 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
4516 t0 = tcg_temp_new_i32(); \
4518 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
4520 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
4522 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
4523 t1 = tcg_temp_new_i32(); \
4524 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
4526 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
4528 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
4530 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
4531 tcg_op(t0, t0, t1); \
4532 bitmask = 0x08 >> (crbD(ctx->opcode) & 0x03); \
4533 tcg_gen_andi_i32(t0, t0, bitmask); \
4534 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
4535 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
4536 tcg_temp_free_i32(t0); \
4537 tcg_temp_free_i32(t1); \
4541 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08);
4543 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04);
4545 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09);
4547 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07);
4549 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01);
4551 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E);
4553 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D);
4555 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06);
4558 static void gen_mcrf(DisasContext
*ctx
)
4560 tcg_gen_mov_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfS(ctx
->opcode
)]);
4563 /*** System linkage ***/
4565 /* rfi (supervisor only) */
4566 static void gen_rfi(DisasContext
*ctx
)
4568 #if defined(CONFIG_USER_ONLY)
4572 * This instruction doesn't exist anymore on 64-bit server
4573 * processors compliant with arch 2.x
4575 if (is_book3s_arch2x(ctx
)) {
4576 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
4579 /* Restore CPU state */
4581 gen_icount_io_start(ctx
);
4582 gen_update_cfar(ctx
, ctx
->cia
);
4583 gen_helper_rfi(cpu_env
);
4584 ctx
->base
.is_jmp
= DISAS_EXIT
;
4588 #if defined(TARGET_PPC64)
4589 static void gen_rfid(DisasContext
*ctx
)
4591 #if defined(CONFIG_USER_ONLY)
4594 /* Restore CPU state */
4596 gen_icount_io_start(ctx
);
4597 gen_update_cfar(ctx
, ctx
->cia
);
4598 gen_helper_rfid(cpu_env
);
4599 ctx
->base
.is_jmp
= DISAS_EXIT
;
4603 #if !defined(CONFIG_USER_ONLY)
4604 static void gen_rfscv(DisasContext
*ctx
)
4606 #if defined(CONFIG_USER_ONLY)
4609 /* Restore CPU state */
4611 gen_icount_io_start(ctx
);
4612 gen_update_cfar(ctx
, ctx
->cia
);
4613 gen_helper_rfscv(cpu_env
);
4614 ctx
->base
.is_jmp
= DISAS_EXIT
;
4619 static void gen_hrfid(DisasContext
*ctx
)
4621 #if defined(CONFIG_USER_ONLY)
4624 /* Restore CPU state */
4626 gen_helper_hrfid(cpu_env
);
4627 ctx
->base
.is_jmp
= DISAS_EXIT
;
4633 #if defined(CONFIG_USER_ONLY)
4634 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
4636 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
4637 #define POWERPC_SYSCALL_VECTORED POWERPC_EXCP_SYSCALL_VECTORED
4639 static void gen_sc(DisasContext
*ctx
)
4643 lev
= (ctx
->opcode
>> 5) & 0x7F;
4644 gen_exception_err(ctx
, POWERPC_SYSCALL
, lev
);
4647 #if defined(TARGET_PPC64)
4648 #if !defined(CONFIG_USER_ONLY)
4649 static void gen_scv(DisasContext
*ctx
)
4651 uint32_t lev
= (ctx
->opcode
>> 5) & 0x7F;
4653 /* Set the PC back to the faulting instruction. */
4654 gen_update_nip(ctx
, ctx
->cia
);
4655 gen_helper_scv(cpu_env
, tcg_constant_i32(lev
));
4657 ctx
->base
.is_jmp
= DISAS_NORETURN
;
4664 /* Check for unconditional traps (always or never) */
4665 static bool check_unconditional_trap(DisasContext
*ctx
)
4668 if (TO(ctx
->opcode
) == 0) {
4672 if (TO(ctx
->opcode
) == 31) {
4673 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_TRAP
);
4680 static void gen_tw(DisasContext
*ctx
)
4684 if (check_unconditional_trap(ctx
)) {
4687 t0
= tcg_const_i32(TO(ctx
->opcode
));
4688 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
4690 tcg_temp_free_i32(t0
);
4694 static void gen_twi(DisasContext
*ctx
)
4699 if (check_unconditional_trap(ctx
)) {
4702 t0
= tcg_const_tl(SIMM(ctx
->opcode
));
4703 t1
= tcg_const_i32(TO(ctx
->opcode
));
4704 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4706 tcg_temp_free_i32(t1
);
4709 #if defined(TARGET_PPC64)
4711 static void gen_td(DisasContext
*ctx
)
4715 if (check_unconditional_trap(ctx
)) {
4718 t0
= tcg_const_i32(TO(ctx
->opcode
));
4719 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
4721 tcg_temp_free_i32(t0
);
4725 static void gen_tdi(DisasContext
*ctx
)
4730 if (check_unconditional_trap(ctx
)) {
4733 t0
= tcg_const_tl(SIMM(ctx
->opcode
));
4734 t1
= tcg_const_i32(TO(ctx
->opcode
));
4735 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
4737 tcg_temp_free_i32(t1
);
4741 /*** Processor control ***/
4744 static void gen_mcrxr(DisasContext
*ctx
)
4746 TCGv_i32 t0
= tcg_temp_new_i32();
4747 TCGv_i32 t1
= tcg_temp_new_i32();
4748 TCGv_i32 dst
= cpu_crf
[crfD(ctx
->opcode
)];
4750 tcg_gen_trunc_tl_i32(t0
, cpu_so
);
4751 tcg_gen_trunc_tl_i32(t1
, cpu_ov
);
4752 tcg_gen_trunc_tl_i32(dst
, cpu_ca
);
4753 tcg_gen_shli_i32(t0
, t0
, 3);
4754 tcg_gen_shli_i32(t1
, t1
, 2);
4755 tcg_gen_shli_i32(dst
, dst
, 1);
4756 tcg_gen_or_i32(dst
, dst
, t0
);
4757 tcg_gen_or_i32(dst
, dst
, t1
);
4758 tcg_temp_free_i32(t0
);
4759 tcg_temp_free_i32(t1
);
4761 tcg_gen_movi_tl(cpu_so
, 0);
4762 tcg_gen_movi_tl(cpu_ov
, 0);
4763 tcg_gen_movi_tl(cpu_ca
, 0);
4768 static void gen_mcrxrx(DisasContext
*ctx
)
4770 TCGv t0
= tcg_temp_new();
4771 TCGv t1
= tcg_temp_new();
4772 TCGv_i32 dst
= cpu_crf
[crfD(ctx
->opcode
)];
4774 /* copy OV and OV32 */
4775 tcg_gen_shli_tl(t0
, cpu_ov
, 1);
4776 tcg_gen_or_tl(t0
, t0
, cpu_ov32
);
4777 tcg_gen_shli_tl(t0
, t0
, 2);
4778 /* copy CA and CA32 */
4779 tcg_gen_shli_tl(t1
, cpu_ca
, 1);
4780 tcg_gen_or_tl(t1
, t1
, cpu_ca32
);
4781 tcg_gen_or_tl(t0
, t0
, t1
);
4782 tcg_gen_trunc_tl_i32(dst
, t0
);
4789 static void gen_mfcr(DisasContext
*ctx
)
4793 if (likely(ctx
->opcode
& 0x00100000)) {
4794 crm
= CRM(ctx
->opcode
);
4795 if (likely(crm
&& ((crm
& (crm
- 1)) == 0))) {
4797 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_crf
[7 - crn
]);
4798 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)],
4799 cpu_gpr
[rD(ctx
->opcode
)], crn
* 4);
4802 TCGv_i32 t0
= tcg_temp_new_i32();
4803 tcg_gen_mov_i32(t0
, cpu_crf
[0]);
4804 tcg_gen_shli_i32(t0
, t0
, 4);
4805 tcg_gen_or_i32(t0
, t0
, cpu_crf
[1]);
4806 tcg_gen_shli_i32(t0
, t0
, 4);
4807 tcg_gen_or_i32(t0
, t0
, cpu_crf
[2]);
4808 tcg_gen_shli_i32(t0
, t0
, 4);
4809 tcg_gen_or_i32(t0
, t0
, cpu_crf
[3]);
4810 tcg_gen_shli_i32(t0
, t0
, 4);
4811 tcg_gen_or_i32(t0
, t0
, cpu_crf
[4]);
4812 tcg_gen_shli_i32(t0
, t0
, 4);
4813 tcg_gen_or_i32(t0
, t0
, cpu_crf
[5]);
4814 tcg_gen_shli_i32(t0
, t0
, 4);
4815 tcg_gen_or_i32(t0
, t0
, cpu_crf
[6]);
4816 tcg_gen_shli_i32(t0
, t0
, 4);
4817 tcg_gen_or_i32(t0
, t0
, cpu_crf
[7]);
4818 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
4819 tcg_temp_free_i32(t0
);
4824 static void gen_mfmsr(DisasContext
*ctx
)
4827 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_msr
);
4831 static inline void gen_op_mfspr(DisasContext
*ctx
)
4833 void (*read_cb
)(DisasContext
*ctx
, int gprn
, int sprn
);
4834 uint32_t sprn
= SPR(ctx
->opcode
);
4836 #if defined(CONFIG_USER_ONLY)
4837 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
4840 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
4841 } else if (ctx
->hv
) {
4842 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
4844 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
4847 if (likely(read_cb
!= NULL
)) {
4848 if (likely(read_cb
!= SPR_NOACCESS
)) {
4849 (*read_cb
)(ctx
, rD(ctx
->opcode
), sprn
);
4851 /* Privilege exception */
4853 * This is a hack to avoid warnings when running Linux:
4854 * this OS breaks the PowerPC virtualisation model,
4855 * allowing userland application to read the PVR
4857 if (sprn
!= SPR_PVR
) {
4858 qemu_log_mask(LOG_GUEST_ERROR
, "Trying to read privileged spr "
4859 "%d (0x%03x) at " TARGET_FMT_lx
"\n", sprn
, sprn
,
4862 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
4865 /* ISA 2.07 defines these as no-ops */
4866 if ((ctx
->insns_flags2
& PPC2_ISA207S
) &&
4867 (sprn
>= 808 && sprn
<= 811)) {
4872 qemu_log_mask(LOG_GUEST_ERROR
,
4873 "Trying to read invalid spr %d (0x%03x) at "
4874 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->cia
);
4877 * The behaviour depends on MSR:PR and SPR# bit 0x10, it can
4878 * generate a priv, a hv emu or a no-op
4882 gen_priv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4885 if (ctx
->pr
|| sprn
== 0 || sprn
== 4 || sprn
== 5 || sprn
== 6) {
4886 gen_hvpriv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
4892 static void gen_mfspr(DisasContext
*ctx
)
4898 static void gen_mftb(DisasContext
*ctx
)
4904 static void gen_mtcrf(DisasContext
*ctx
)
4908 crm
= CRM(ctx
->opcode
);
4909 if (likely((ctx
->opcode
& 0x00100000))) {
4910 if (crm
&& ((crm
& (crm
- 1)) == 0)) {
4911 TCGv_i32 temp
= tcg_temp_new_i32();
4913 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
4914 tcg_gen_shri_i32(temp
, temp
, crn
* 4);
4915 tcg_gen_andi_i32(cpu_crf
[7 - crn
], temp
, 0xf);
4916 tcg_temp_free_i32(temp
);
4919 TCGv_i32 temp
= tcg_temp_new_i32();
4920 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
4921 for (crn
= 0 ; crn
< 8 ; crn
++) {
4922 if (crm
& (1 << crn
)) {
4923 tcg_gen_shri_i32(cpu_crf
[7 - crn
], temp
, crn
* 4);
4924 tcg_gen_andi_i32(cpu_crf
[7 - crn
], cpu_crf
[7 - crn
], 0xf);
4927 tcg_temp_free_i32(temp
);
4932 #if defined(TARGET_PPC64)
4933 static void gen_mtmsrd(DisasContext
*ctx
)
4935 if (unlikely(!is_book3s_arch2x(ctx
))) {
4942 #if !defined(CONFIG_USER_ONLY)
4943 gen_icount_io_start(ctx
);
4944 if (ctx
->opcode
& 0x00010000) {
4945 /* L=1 form only updates EE and RI */
4946 TCGv t0
= tcg_temp_new();
4947 TCGv t1
= tcg_temp_new();
4948 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)],
4949 (1 << MSR_RI
) | (1 << MSR_EE
));
4950 tcg_gen_andi_tl(t1
, cpu_msr
,
4951 ~(target_ulong
)((1 << MSR_RI
) | (1 << MSR_EE
)));
4952 tcg_gen_or_tl(t1
, t1
, t0
);
4954 gen_helper_store_msr(cpu_env
, t1
);
4960 * XXX: we need to update nip before the store if we enter
4961 * power saving mode, we will exit the loop directly from
4964 gen_update_nip(ctx
, ctx
->base
.pc_next
);
4965 gen_helper_store_msr(cpu_env
, cpu_gpr
[rS(ctx
->opcode
)]);
4967 /* Must stop the translation as machine state (may have) changed */
4968 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
4969 #endif /* !defined(CONFIG_USER_ONLY) */
4971 #endif /* defined(TARGET_PPC64) */
4973 static void gen_mtmsr(DisasContext
*ctx
)
4977 #if !defined(CONFIG_USER_ONLY)
4978 gen_icount_io_start(ctx
);
4979 if (ctx
->opcode
& 0x00010000) {
4980 /* L=1 form only updates EE and RI */
4981 TCGv t0
= tcg_temp_new();
4982 TCGv t1
= tcg_temp_new();
4983 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)],
4984 (1 << MSR_RI
) | (1 << MSR_EE
));
4985 tcg_gen_andi_tl(t1
, cpu_msr
,
4986 ~(target_ulong
)((1 << MSR_RI
) | (1 << MSR_EE
)));
4987 tcg_gen_or_tl(t1
, t1
, t0
);
4989 gen_helper_store_msr(cpu_env
, t1
);
4994 TCGv msr
= tcg_temp_new();
4997 * XXX: we need to update nip before the store if we enter
4998 * power saving mode, we will exit the loop directly from
5001 gen_update_nip(ctx
, ctx
->base
.pc_next
);
5002 #if defined(TARGET_PPC64)
5003 tcg_gen_deposit_tl(msr
, cpu_msr
, cpu_gpr
[rS(ctx
->opcode
)], 0, 32);
5005 tcg_gen_mov_tl(msr
, cpu_gpr
[rS(ctx
->opcode
)]);
5007 gen_helper_store_msr(cpu_env
, msr
);
5010 /* Must stop the translation as machine state (may have) changed */
5011 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
5016 static void gen_mtspr(DisasContext
*ctx
)
5018 void (*write_cb
)(DisasContext
*ctx
, int sprn
, int gprn
);
5019 uint32_t sprn
= SPR(ctx
->opcode
);
5021 #if defined(CONFIG_USER_ONLY)
5022 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
5025 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
5026 } else if (ctx
->hv
) {
5027 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
5029 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
5032 if (likely(write_cb
!= NULL
)) {
5033 if (likely(write_cb
!= SPR_NOACCESS
)) {
5034 (*write_cb
)(ctx
, sprn
, rS(ctx
->opcode
));
5036 /* Privilege exception */
5037 qemu_log_mask(LOG_GUEST_ERROR
, "Trying to write privileged spr "
5038 "%d (0x%03x) at " TARGET_FMT_lx
"\n", sprn
, sprn
,
5040 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5043 /* ISA 2.07 defines these as no-ops */
5044 if ((ctx
->insns_flags2
& PPC2_ISA207S
) &&
5045 (sprn
>= 808 && sprn
<= 811)) {
5051 qemu_log_mask(LOG_GUEST_ERROR
,
5052 "Trying to write invalid spr %d (0x%03x) at "
5053 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->cia
);
5057 * The behaviour depends on MSR:PR and SPR# bit 0x10, it can
5058 * generate a priv, a hv emu or a no-op
5062 gen_priv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
5065 if (ctx
->pr
|| sprn
== 0) {
5066 gen_hvpriv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
5072 #if defined(TARGET_PPC64)
5074 static void gen_setb(DisasContext
*ctx
)
5076 TCGv_i32 t0
= tcg_temp_new_i32();
5077 TCGv_i32 t8
= tcg_temp_new_i32();
5078 TCGv_i32 tm1
= tcg_temp_new_i32();
5079 int crf
= crfS(ctx
->opcode
);
5081 tcg_gen_setcondi_i32(TCG_COND_GEU
, t0
, cpu_crf
[crf
], 4);
5082 tcg_gen_movi_i32(t8
, 8);
5083 tcg_gen_movi_i32(tm1
, -1);
5084 tcg_gen_movcond_i32(TCG_COND_GEU
, t0
, cpu_crf
[crf
], t8
, tm1
, t0
);
5085 tcg_gen_ext_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
5087 tcg_temp_free_i32(t0
);
5088 tcg_temp_free_i32(t8
);
5089 tcg_temp_free_i32(tm1
);
5093 /*** Cache management ***/
5096 static void gen_dcbf(DisasContext
*ctx
)
5098 /* XXX: specification says this is treated as a load by the MMU */
5100 gen_set_access_type(ctx
, ACCESS_CACHE
);
5101 t0
= tcg_temp_new();
5102 gen_addr_reg_index(ctx
, t0
);
5103 gen_qemu_ld8u(ctx
, t0
, t0
);
5107 /* dcbfep (external PID dcbf) */
5108 static void gen_dcbfep(DisasContext
*ctx
)
5110 /* XXX: specification says this is treated as a load by the MMU */
5113 gen_set_access_type(ctx
, ACCESS_CACHE
);
5114 t0
= tcg_temp_new();
5115 gen_addr_reg_index(ctx
, t0
);
5116 tcg_gen_qemu_ld_tl(t0
, t0
, PPC_TLB_EPID_LOAD
, DEF_MEMOP(MO_UB
));
5120 /* dcbi (Supervisor only) */
5121 static void gen_dcbi(DisasContext
*ctx
)
5123 #if defined(CONFIG_USER_ONLY)
5129 EA
= tcg_temp_new();
5130 gen_set_access_type(ctx
, ACCESS_CACHE
);
5131 gen_addr_reg_index(ctx
, EA
);
5132 val
= tcg_temp_new();
5133 /* XXX: specification says this should be treated as a store by the MMU */
5134 gen_qemu_ld8u(ctx
, val
, EA
);
5135 gen_qemu_st8(ctx
, val
, EA
);
5138 #endif /* defined(CONFIG_USER_ONLY) */
5142 static void gen_dcbst(DisasContext
*ctx
)
5144 /* XXX: specification say this is treated as a load by the MMU */
5146 gen_set_access_type(ctx
, ACCESS_CACHE
);
5147 t0
= tcg_temp_new();
5148 gen_addr_reg_index(ctx
, t0
);
5149 gen_qemu_ld8u(ctx
, t0
, t0
);
5153 /* dcbstep (dcbstep External PID version) */
5154 static void gen_dcbstep(DisasContext
*ctx
)
5156 /* XXX: specification say this is treated as a load by the MMU */
5158 gen_set_access_type(ctx
, ACCESS_CACHE
);
5159 t0
= tcg_temp_new();
5160 gen_addr_reg_index(ctx
, t0
);
5161 tcg_gen_qemu_ld_tl(t0
, t0
, PPC_TLB_EPID_LOAD
, DEF_MEMOP(MO_UB
));
5166 static void gen_dcbt(DisasContext
*ctx
)
5169 * interpreted as no-op
5170 * XXX: specification say this is treated as a load by the MMU but
5171 * does not generate any exception
5176 static void gen_dcbtep(DisasContext
*ctx
)
5179 * interpreted as no-op
5180 * XXX: specification say this is treated as a load by the MMU but
5181 * does not generate any exception
5186 static void gen_dcbtst(DisasContext
*ctx
)
5189 * interpreted as no-op
5190 * XXX: specification say this is treated as a load by the MMU but
5191 * does not generate any exception
5196 static void gen_dcbtstep(DisasContext
*ctx
)
5199 * interpreted as no-op
5200 * XXX: specification say this is treated as a load by the MMU but
5201 * does not generate any exception
5206 static void gen_dcbtls(DisasContext
*ctx
)
5208 /* Always fails locking the cache */
5209 TCGv t0
= tcg_temp_new();
5210 gen_load_spr(t0
, SPR_Exxx_L1CSR0
);
5211 tcg_gen_ori_tl(t0
, t0
, L1CSR0_CUL
);
5212 gen_store_spr(SPR_Exxx_L1CSR0
, t0
);
5217 static void gen_dcbz(DisasContext
*ctx
)
5222 gen_set_access_type(ctx
, ACCESS_CACHE
);
5223 tcgv_addr
= tcg_temp_new();
5224 tcgv_op
= tcg_const_i32(ctx
->opcode
& 0x03FF000);
5225 gen_addr_reg_index(ctx
, tcgv_addr
);
5226 gen_helper_dcbz(cpu_env
, tcgv_addr
, tcgv_op
);
5227 tcg_temp_free(tcgv_addr
);
5228 tcg_temp_free_i32(tcgv_op
);
5232 static void gen_dcbzep(DisasContext
*ctx
)
5237 gen_set_access_type(ctx
, ACCESS_CACHE
);
5238 tcgv_addr
= tcg_temp_new();
5239 tcgv_op
= tcg_const_i32(ctx
->opcode
& 0x03FF000);
5240 gen_addr_reg_index(ctx
, tcgv_addr
);
5241 gen_helper_dcbzep(cpu_env
, tcgv_addr
, tcgv_op
);
5242 tcg_temp_free(tcgv_addr
);
5243 tcg_temp_free_i32(tcgv_op
);
5247 static void gen_dst(DisasContext
*ctx
)
5249 if (rA(ctx
->opcode
) == 0) {
5250 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5252 /* interpreted as no-op */
5257 static void gen_dstst(DisasContext
*ctx
)
5259 if (rA(ctx
->opcode
) == 0) {
5260 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5262 /* interpreted as no-op */
5268 static void gen_dss(DisasContext
*ctx
)
5270 /* interpreted as no-op */
5274 static void gen_icbi(DisasContext
*ctx
)
5277 gen_set_access_type(ctx
, ACCESS_CACHE
);
5278 t0
= tcg_temp_new();
5279 gen_addr_reg_index(ctx
, t0
);
5280 gen_helper_icbi(cpu_env
, t0
);
5285 static void gen_icbiep(DisasContext
*ctx
)
5288 gen_set_access_type(ctx
, ACCESS_CACHE
);
5289 t0
= tcg_temp_new();
5290 gen_addr_reg_index(ctx
, t0
);
5291 gen_helper_icbiep(cpu_env
, t0
);
5297 static void gen_dcba(DisasContext
*ctx
)
5300 * interpreted as no-op
5301 * XXX: specification say this is treated as a store by the MMU
5302 * but does not generate any exception
5306 /*** Segment register manipulation ***/
5307 /* Supervisor only: */
5310 static void gen_mfsr(DisasContext
*ctx
)
5312 #if defined(CONFIG_USER_ONLY)
5318 t0
= tcg_const_tl(SR(ctx
->opcode
));
5319 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5321 #endif /* defined(CONFIG_USER_ONLY) */
5325 static void gen_mfsrin(DisasContext
*ctx
)
5327 #if defined(CONFIG_USER_ONLY)
5333 t0
= tcg_temp_new();
5334 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
5335 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5337 #endif /* defined(CONFIG_USER_ONLY) */
5341 static void gen_mtsr(DisasContext
*ctx
)
5343 #if defined(CONFIG_USER_ONLY)
5349 t0
= tcg_const_tl(SR(ctx
->opcode
));
5350 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
5352 #endif /* defined(CONFIG_USER_ONLY) */
5356 static void gen_mtsrin(DisasContext
*ctx
)
5358 #if defined(CONFIG_USER_ONLY)
5364 t0
= tcg_temp_new();
5365 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
5366 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rD(ctx
->opcode
)]);
5368 #endif /* defined(CONFIG_USER_ONLY) */
5371 #if defined(TARGET_PPC64)
5372 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
5375 static void gen_mfsr_64b(DisasContext
*ctx
)
5377 #if defined(CONFIG_USER_ONLY)
5383 t0
= tcg_const_tl(SR(ctx
->opcode
));
5384 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5386 #endif /* defined(CONFIG_USER_ONLY) */
5390 static void gen_mfsrin_64b(DisasContext
*ctx
)
5392 #if defined(CONFIG_USER_ONLY)
5398 t0
= tcg_temp_new();
5399 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
5400 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5402 #endif /* defined(CONFIG_USER_ONLY) */
5406 static void gen_mtsr_64b(DisasContext
*ctx
)
5408 #if defined(CONFIG_USER_ONLY)
5414 t0
= tcg_const_tl(SR(ctx
->opcode
));
5415 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
5417 #endif /* defined(CONFIG_USER_ONLY) */
5421 static void gen_mtsrin_64b(DisasContext
*ctx
)
5423 #if defined(CONFIG_USER_ONLY)
5429 t0
= tcg_temp_new();
5430 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
5431 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
5433 #endif /* defined(CONFIG_USER_ONLY) */
5437 static void gen_slbmte(DisasContext
*ctx
)
5439 #if defined(CONFIG_USER_ONLY)
5444 gen_helper_store_slb(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)],
5445 cpu_gpr
[rS(ctx
->opcode
)]);
5446 #endif /* defined(CONFIG_USER_ONLY) */
5449 static void gen_slbmfee(DisasContext
*ctx
)
5451 #if defined(CONFIG_USER_ONLY)
5456 gen_helper_load_slb_esid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
5457 cpu_gpr
[rB(ctx
->opcode
)]);
5458 #endif /* defined(CONFIG_USER_ONLY) */
5461 static void gen_slbmfev(DisasContext
*ctx
)
5463 #if defined(CONFIG_USER_ONLY)
5468 gen_helper_load_slb_vsid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
5469 cpu_gpr
[rB(ctx
->opcode
)]);
5470 #endif /* defined(CONFIG_USER_ONLY) */
5473 static void gen_slbfee_(DisasContext
*ctx
)
5475 #if defined(CONFIG_USER_ONLY)
5476 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5480 if (unlikely(ctx
->pr
)) {
5481 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5484 gen_helper_find_slb_vsid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
5485 cpu_gpr
[rB(ctx
->opcode
)]);
5486 l1
= gen_new_label();
5487 l2
= gen_new_label();
5488 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
5489 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rS(ctx
->opcode
)], -1, l1
);
5490 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], CRF_EQ
);
5493 tcg_gen_movi_tl(cpu_gpr
[rS(ctx
->opcode
)], 0);
5497 #endif /* defined(TARGET_PPC64) */
5499 /*** Lookaside buffer management ***/
5500 /* Optional & supervisor only: */
5503 static void gen_tlbia(DisasContext
*ctx
)
5505 #if defined(CONFIG_USER_ONLY)
5510 gen_helper_tlbia(cpu_env
);
5511 #endif /* defined(CONFIG_USER_ONLY) */
5515 static void gen_tlbiel(DisasContext
*ctx
)
5517 #if defined(CONFIG_USER_ONLY)
5520 bool psr
= (ctx
->opcode
>> 17) & 0x1;
5522 if (ctx
->pr
|| (!ctx
->hv
&& !psr
&& ctx
->hr
)) {
5524 * tlbiel is privileged except when PSR=0 and HR=1, making it
5525 * hypervisor privileged.
5530 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5531 #endif /* defined(CONFIG_USER_ONLY) */
5535 static void gen_tlbie(DisasContext
*ctx
)
5537 #if defined(CONFIG_USER_ONLY)
5540 bool psr
= (ctx
->opcode
>> 17) & 0x1;
5544 /* tlbie is privileged... */
5546 } else if (!ctx
->hv
) {
5547 if (!ctx
->gtse
|| (!psr
&& ctx
->hr
)) {
5549 * ... except when GTSE=0 or when PSR=0 and HR=1, making it
5550 * hypervisor privileged.
5556 if (NARROW_MODE(ctx
)) {
5557 TCGv t0
= tcg_temp_new();
5558 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
5559 gen_helper_tlbie(cpu_env
, t0
);
5562 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5564 t1
= tcg_temp_new_i32();
5565 tcg_gen_ld_i32(t1
, cpu_env
, offsetof(CPUPPCState
, tlb_need_flush
));
5566 tcg_gen_ori_i32(t1
, t1
, TLB_NEED_GLOBAL_FLUSH
);
5567 tcg_gen_st_i32(t1
, cpu_env
, offsetof(CPUPPCState
, tlb_need_flush
));
5568 tcg_temp_free_i32(t1
);
5569 #endif /* defined(CONFIG_USER_ONLY) */
5573 static void gen_tlbsync(DisasContext
*ctx
)
5575 #if defined(CONFIG_USER_ONLY)
5580 CHK_SV
; /* If gtse is set then tlbsync is supervisor privileged */
5582 CHK_HV
; /* Else hypervisor privileged */
5585 /* BookS does both ptesync and tlbsync make tlbsync a nop for server */
5586 if (ctx
->insns_flags
& PPC_BOOKE
) {
5587 gen_check_tlb_flush(ctx
, true);
5589 #endif /* defined(CONFIG_USER_ONLY) */
5592 #if defined(TARGET_PPC64)
5594 static void gen_slbia(DisasContext
*ctx
)
5596 #if defined(CONFIG_USER_ONLY)
5599 uint32_t ih
= (ctx
->opcode
>> 21) & 0x7;
5600 TCGv_i32 t0
= tcg_const_i32(ih
);
5604 gen_helper_slbia(cpu_env
, t0
);
5605 tcg_temp_free_i32(t0
);
5606 #endif /* defined(CONFIG_USER_ONLY) */
5610 static void gen_slbie(DisasContext
*ctx
)
5612 #if defined(CONFIG_USER_ONLY)
5617 gen_helper_slbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5618 #endif /* defined(CONFIG_USER_ONLY) */
5622 static void gen_slbieg(DisasContext
*ctx
)
5624 #if defined(CONFIG_USER_ONLY)
5629 gen_helper_slbieg(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5630 #endif /* defined(CONFIG_USER_ONLY) */
5634 static void gen_slbsync(DisasContext
*ctx
)
5636 #if defined(CONFIG_USER_ONLY)
5640 gen_check_tlb_flush(ctx
, true);
5641 #endif /* defined(CONFIG_USER_ONLY) */
5644 #endif /* defined(TARGET_PPC64) */
5646 /*** External control ***/
5650 static void gen_eciwx(DisasContext
*ctx
)
5653 /* Should check EAR[E] ! */
5654 gen_set_access_type(ctx
, ACCESS_EXT
);
5655 t0
= tcg_temp_new();
5656 gen_addr_reg_index(ctx
, t0
);
5657 tcg_gen_qemu_ld_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, ctx
->mem_idx
,
5658 DEF_MEMOP(MO_UL
| MO_ALIGN
));
5663 static void gen_ecowx(DisasContext
*ctx
)
5666 /* Should check EAR[E] ! */
5667 gen_set_access_type(ctx
, ACCESS_EXT
);
5668 t0
= tcg_temp_new();
5669 gen_addr_reg_index(ctx
, t0
);
5670 tcg_gen_qemu_st_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, ctx
->mem_idx
,
5671 DEF_MEMOP(MO_UL
| MO_ALIGN
));
5675 /* PowerPC 601 specific instructions */
5678 static void gen_abs(DisasContext
*ctx
)
5680 TCGv d
= cpu_gpr
[rD(ctx
->opcode
)];
5681 TCGv a
= cpu_gpr
[rA(ctx
->opcode
)];
5683 tcg_gen_abs_tl(d
, a
);
5684 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5685 gen_set_Rc0(ctx
, d
);
5690 static void gen_abso(DisasContext
*ctx
)
5692 TCGv d
= cpu_gpr
[rD(ctx
->opcode
)];
5693 TCGv a
= cpu_gpr
[rA(ctx
->opcode
)];
5695 tcg_gen_setcondi_tl(TCG_COND_EQ
, cpu_ov
, a
, 0x80000000);
5696 tcg_gen_abs_tl(d
, a
);
5697 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
5698 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5699 gen_set_Rc0(ctx
, d
);
5704 static void gen_clcs(DisasContext
*ctx
)
5706 TCGv_i32 t0
= tcg_const_i32(rA(ctx
->opcode
));
5707 gen_helper_clcs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5708 tcg_temp_free_i32(t0
);
5709 /* Rc=1 sets CR0 to an undefined state */
5713 static void gen_div(DisasContext
*ctx
)
5715 gen_helper_div(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5716 cpu_gpr
[rB(ctx
->opcode
)]);
5717 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5718 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5723 static void gen_divo(DisasContext
*ctx
)
5725 gen_helper_divo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5726 cpu_gpr
[rB(ctx
->opcode
)]);
5727 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5728 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5733 static void gen_divs(DisasContext
*ctx
)
5735 gen_helper_divs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
5736 cpu_gpr
[rB(ctx
->opcode
)]);
5737 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5738 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5742 /* divso - divso. */
5743 static void gen_divso(DisasContext
*ctx
)
5745 gen_helper_divso(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
5746 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
5747 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5748 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5753 static void gen_doz(DisasContext
*ctx
)
5755 TCGLabel
*l1
= gen_new_label();
5756 TCGLabel
*l2
= gen_new_label();
5757 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)],
5758 cpu_gpr
[rA(ctx
->opcode
)], l1
);
5759 tcg_gen_sub_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
5760 cpu_gpr
[rA(ctx
->opcode
)]);
5763 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
5765 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5766 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5771 static void gen_dozo(DisasContext
*ctx
)
5773 TCGLabel
*l1
= gen_new_label();
5774 TCGLabel
*l2
= gen_new_label();
5775 TCGv t0
= tcg_temp_new();
5776 TCGv t1
= tcg_temp_new();
5777 TCGv t2
= tcg_temp_new();
5778 /* Start with XER OV disabled, the most likely case */
5779 tcg_gen_movi_tl(cpu_ov
, 0);
5780 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)],
5781 cpu_gpr
[rA(ctx
->opcode
)], l1
);
5782 tcg_gen_sub_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5783 tcg_gen_xor_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5784 tcg_gen_xor_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], t0
);
5785 tcg_gen_andc_tl(t1
, t1
, t2
);
5786 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
5787 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
5788 tcg_gen_movi_tl(cpu_ov
, 1);
5789 tcg_gen_movi_tl(cpu_so
, 1);
5792 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
5797 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5798 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5803 static void gen_dozi(DisasContext
*ctx
)
5805 target_long simm
= SIMM(ctx
->opcode
);
5806 TCGLabel
*l1
= gen_new_label();
5807 TCGLabel
*l2
= gen_new_label();
5808 tcg_gen_brcondi_tl(TCG_COND_LT
, cpu_gpr
[rA(ctx
->opcode
)], simm
, l1
);
5809 tcg_gen_subfi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
, cpu_gpr
[rA(ctx
->opcode
)]);
5812 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
5814 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5815 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5819 /* lscbx - lscbx. */
5820 static void gen_lscbx(DisasContext
*ctx
)
5822 TCGv t0
= tcg_temp_new();
5823 TCGv_i32 t1
= tcg_const_i32(rD(ctx
->opcode
));
5824 TCGv_i32 t2
= tcg_const_i32(rA(ctx
->opcode
));
5825 TCGv_i32 t3
= tcg_const_i32(rB(ctx
->opcode
));
5827 gen_addr_reg_index(ctx
, t0
);
5828 gen_helper_lscbx(t0
, cpu_env
, t0
, t1
, t2
, t3
);
5829 tcg_temp_free_i32(t1
);
5830 tcg_temp_free_i32(t2
);
5831 tcg_temp_free_i32(t3
);
5832 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~0x7F);
5833 tcg_gen_or_tl(cpu_xer
, cpu_xer
, t0
);
5834 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5835 gen_set_Rc0(ctx
, t0
);
5840 /* maskg - maskg. */
5841 static void gen_maskg(DisasContext
*ctx
)
5843 TCGLabel
*l1
= gen_new_label();
5844 TCGv t0
= tcg_temp_new();
5845 TCGv t1
= tcg_temp_new();
5846 TCGv t2
= tcg_temp_new();
5847 TCGv t3
= tcg_temp_new();
5848 tcg_gen_movi_tl(t3
, 0xFFFFFFFF);
5849 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5850 tcg_gen_andi_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 0x1F);
5851 tcg_gen_addi_tl(t2
, t0
, 1);
5852 tcg_gen_shr_tl(t2
, t3
, t2
);
5853 tcg_gen_shr_tl(t3
, t3
, t1
);
5854 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], t2
, t3
);
5855 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
5856 tcg_gen_neg_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
5862 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5863 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5867 /* maskir - maskir. */
5868 static void gen_maskir(DisasContext
*ctx
)
5870 TCGv t0
= tcg_temp_new();
5871 TCGv t1
= tcg_temp_new();
5872 tcg_gen_and_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
5873 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
5874 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5877 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5878 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5883 static void gen_mul(DisasContext
*ctx
)
5885 TCGv_i64 t0
= tcg_temp_new_i64();
5886 TCGv_i64 t1
= tcg_temp_new_i64();
5887 TCGv t2
= tcg_temp_new();
5888 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
5889 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
5890 tcg_gen_mul_i64(t0
, t0
, t1
);
5891 tcg_gen_trunc_i64_tl(t2
, t0
);
5892 gen_store_spr(SPR_MQ
, t2
);
5893 tcg_gen_shri_i64(t1
, t0
, 32);
5894 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
5895 tcg_temp_free_i64(t0
);
5896 tcg_temp_free_i64(t1
);
5898 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5899 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5904 static void gen_mulo(DisasContext
*ctx
)
5906 TCGLabel
*l1
= gen_new_label();
5907 TCGv_i64 t0
= tcg_temp_new_i64();
5908 TCGv_i64 t1
= tcg_temp_new_i64();
5909 TCGv t2
= tcg_temp_new();
5910 /* Start with XER OV disabled, the most likely case */
5911 tcg_gen_movi_tl(cpu_ov
, 0);
5912 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
5913 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
5914 tcg_gen_mul_i64(t0
, t0
, t1
);
5915 tcg_gen_trunc_i64_tl(t2
, t0
);
5916 gen_store_spr(SPR_MQ
, t2
);
5917 tcg_gen_shri_i64(t1
, t0
, 32);
5918 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
5919 tcg_gen_ext32s_i64(t1
, t0
);
5920 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
5921 tcg_gen_movi_tl(cpu_ov
, 1);
5922 tcg_gen_movi_tl(cpu_so
, 1);
5924 tcg_temp_free_i64(t0
);
5925 tcg_temp_free_i64(t1
);
5927 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5928 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
5933 static void gen_nabs(DisasContext
*ctx
)
5935 TCGv d
= cpu_gpr
[rD(ctx
->opcode
)];
5936 TCGv a
= cpu_gpr
[rA(ctx
->opcode
)];
5938 tcg_gen_abs_tl(d
, a
);
5939 tcg_gen_neg_tl(d
, d
);
5940 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5941 gen_set_Rc0(ctx
, d
);
5945 /* nabso - nabso. */
5946 static void gen_nabso(DisasContext
*ctx
)
5948 TCGv d
= cpu_gpr
[rD(ctx
->opcode
)];
5949 TCGv a
= cpu_gpr
[rA(ctx
->opcode
)];
5951 tcg_gen_abs_tl(d
, a
);
5952 tcg_gen_neg_tl(d
, d
);
5953 /* nabs never overflows */
5954 tcg_gen_movi_tl(cpu_ov
, 0);
5955 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5956 gen_set_Rc0(ctx
, d
);
5961 static void gen_rlmi(DisasContext
*ctx
)
5963 uint32_t mb
= MB(ctx
->opcode
);
5964 uint32_t me
= ME(ctx
->opcode
);
5965 TCGv t0
= tcg_temp_new();
5966 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5967 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5968 tcg_gen_andi_tl(t0
, t0
, MASK(mb
, me
));
5969 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
5971 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], t0
);
5973 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5974 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5979 static void gen_rrib(DisasContext
*ctx
)
5981 TCGv t0
= tcg_temp_new();
5982 TCGv t1
= tcg_temp_new();
5983 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
5984 tcg_gen_movi_tl(t1
, 0x80000000);
5985 tcg_gen_shr_tl(t1
, t1
, t0
);
5986 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
5987 tcg_gen_and_tl(t0
, t0
, t1
);
5988 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], t1
);
5989 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5992 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5993 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
5998 static void gen_sle(DisasContext
*ctx
)
6000 TCGv t0
= tcg_temp_new();
6001 TCGv t1
= tcg_temp_new();
6002 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
6003 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
6004 tcg_gen_subfi_tl(t1
, 32, t1
);
6005 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
6006 tcg_gen_or_tl(t1
, t0
, t1
);
6007 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
6008 gen_store_spr(SPR_MQ
, t1
);
6011 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6012 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6017 static void gen_sleq(DisasContext
*ctx
)
6019 TCGv t0
= tcg_temp_new();
6020 TCGv t1
= tcg_temp_new();
6021 TCGv t2
= tcg_temp_new();
6022 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
6023 tcg_gen_movi_tl(t2
, 0xFFFFFFFF);
6024 tcg_gen_shl_tl(t2
, t2
, t0
);
6025 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
6026 gen_load_spr(t1
, SPR_MQ
);
6027 gen_store_spr(SPR_MQ
, t0
);
6028 tcg_gen_and_tl(t0
, t0
, t2
);
6029 tcg_gen_andc_tl(t1
, t1
, t2
);
6030 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
6034 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6035 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6040 static void gen_sliq(DisasContext
*ctx
)
6042 int sh
= SH(ctx
->opcode
);
6043 TCGv t0
= tcg_temp_new();
6044 TCGv t1
= tcg_temp_new();
6045 tcg_gen_shli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
6046 tcg_gen_shri_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
6047 tcg_gen_or_tl(t1
, t0
, t1
);
6048 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
6049 gen_store_spr(SPR_MQ
, t1
);
6052 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6053 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6057 /* slliq - slliq. */
6058 static void gen_slliq(DisasContext
*ctx
)
6060 int sh
= SH(ctx
->opcode
);
6061 TCGv t0
= tcg_temp_new();
6062 TCGv t1
= tcg_temp_new();
6063 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
6064 gen_load_spr(t1
, SPR_MQ
);
6065 gen_store_spr(SPR_MQ
, t0
);
6066 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
<< sh
));
6067 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
<< sh
));
6068 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
6071 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6072 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6077 static void gen_sllq(DisasContext
*ctx
)
6079 TCGLabel
*l1
= gen_new_label();
6080 TCGLabel
*l2
= gen_new_label();
6081 TCGv t0
= tcg_temp_local_new();
6082 TCGv t1
= tcg_temp_local_new();
6083 TCGv t2
= tcg_temp_local_new();
6084 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
6085 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
6086 tcg_gen_shl_tl(t1
, t1
, t2
);
6087 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
6088 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
6089 gen_load_spr(t0
, SPR_MQ
);
6090 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
6093 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
6094 gen_load_spr(t2
, SPR_MQ
);
6095 tcg_gen_andc_tl(t1
, t2
, t1
);
6096 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
6101 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6102 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6107 static void gen_slq(DisasContext
*ctx
)
6109 TCGLabel
*l1
= gen_new_label();
6110 TCGv t0
= tcg_temp_new();
6111 TCGv t1
= tcg_temp_new();
6112 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
6113 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
6114 tcg_gen_subfi_tl(t1
, 32, t1
);
6115 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
6116 tcg_gen_or_tl(t1
, t0
, t1
);
6117 gen_store_spr(SPR_MQ
, t1
);
6118 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
6119 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
6120 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
6121 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
6125 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6126 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6130 /* sraiq - sraiq. */
6131 static void gen_sraiq(DisasContext
*ctx
)
6133 int sh
= SH(ctx
->opcode
);
6134 TCGLabel
*l1
= gen_new_label();
6135 TCGv t0
= tcg_temp_new();
6136 TCGv t1
= tcg_temp_new();
6137 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
6138 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
6139 tcg_gen_or_tl(t0
, t0
, t1
);
6140 gen_store_spr(SPR_MQ
, t0
);
6141 tcg_gen_movi_tl(cpu_ca
, 0);
6142 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
6143 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
6144 tcg_gen_movi_tl(cpu_ca
, 1);
6146 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
6149 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6150 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6155 static void gen_sraq(DisasContext
*ctx
)
6157 TCGLabel
*l1
= gen_new_label();
6158 TCGLabel
*l2
= gen_new_label();
6159 TCGv t0
= tcg_temp_new();
6160 TCGv t1
= tcg_temp_local_new();
6161 TCGv t2
= tcg_temp_local_new();
6162 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
6163 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
6164 tcg_gen_sar_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
6165 tcg_gen_subfi_tl(t2
, 32, t2
);
6166 tcg_gen_shl_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
6167 tcg_gen_or_tl(t0
, t0
, t2
);
6168 gen_store_spr(SPR_MQ
, t0
);
6169 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
6170 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l1
);
6171 tcg_gen_mov_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
6172 tcg_gen_sari_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 31);
6175 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
);
6176 tcg_gen_movi_tl(cpu_ca
, 0);
6177 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
6178 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l2
);
6179 tcg_gen_movi_tl(cpu_ca
, 1);
6183 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6184 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6189 static void gen_sre(DisasContext
*ctx
)
6191 TCGv t0
= tcg_temp_new();
6192 TCGv t1
= tcg_temp_new();
6193 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
6194 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
6195 tcg_gen_subfi_tl(t1
, 32, t1
);
6196 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
6197 tcg_gen_or_tl(t1
, t0
, t1
);
6198 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
6199 gen_store_spr(SPR_MQ
, t1
);
6202 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6203 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6208 static void gen_srea(DisasContext
*ctx
)
6210 TCGv t0
= tcg_temp_new();
6211 TCGv t1
= tcg_temp_new();
6212 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
6213 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
6214 gen_store_spr(SPR_MQ
, t0
);
6215 tcg_gen_sar_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t1
);
6218 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6219 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6224 static void gen_sreq(DisasContext
*ctx
)
6226 TCGv t0
= tcg_temp_new();
6227 TCGv t1
= tcg_temp_new();
6228 TCGv t2
= tcg_temp_new();
6229 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
6230 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
6231 tcg_gen_shr_tl(t1
, t1
, t0
);
6232 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
6233 gen_load_spr(t2
, SPR_MQ
);
6234 gen_store_spr(SPR_MQ
, t0
);
6235 tcg_gen_and_tl(t0
, t0
, t1
);
6236 tcg_gen_andc_tl(t2
, t2
, t1
);
6237 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
6241 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6242 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6247 static void gen_sriq(DisasContext
*ctx
)
6249 int sh
= SH(ctx
->opcode
);
6250 TCGv t0
= tcg_temp_new();
6251 TCGv t1
= tcg_temp_new();
6252 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
6253 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
6254 tcg_gen_or_tl(t1
, t0
, t1
);
6255 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
6256 gen_store_spr(SPR_MQ
, t1
);
6259 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6260 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6265 static void gen_srliq(DisasContext
*ctx
)
6267 int sh
= SH(ctx
->opcode
);
6268 TCGv t0
= tcg_temp_new();
6269 TCGv t1
= tcg_temp_new();
6270 tcg_gen_rotri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
6271 gen_load_spr(t1
, SPR_MQ
);
6272 gen_store_spr(SPR_MQ
, t0
);
6273 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
>> sh
));
6274 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
>> sh
));
6275 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
6278 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6279 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6284 static void gen_srlq(DisasContext
*ctx
)
6286 TCGLabel
*l1
= gen_new_label();
6287 TCGLabel
*l2
= gen_new_label();
6288 TCGv t0
= tcg_temp_local_new();
6289 TCGv t1
= tcg_temp_local_new();
6290 TCGv t2
= tcg_temp_local_new();
6291 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
6292 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
6293 tcg_gen_shr_tl(t2
, t1
, t2
);
6294 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
6295 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
6296 gen_load_spr(t0
, SPR_MQ
);
6297 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
6300 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
6301 tcg_gen_and_tl(t0
, t0
, t2
);
6302 gen_load_spr(t1
, SPR_MQ
);
6303 tcg_gen_andc_tl(t1
, t1
, t2
);
6304 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
6309 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6310 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6315 static void gen_srq(DisasContext
*ctx
)
6317 TCGLabel
*l1
= gen_new_label();
6318 TCGv t0
= tcg_temp_new();
6319 TCGv t1
= tcg_temp_new();
6320 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
6321 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
6322 tcg_gen_subfi_tl(t1
, 32, t1
);
6323 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
6324 tcg_gen_or_tl(t1
, t0
, t1
);
6325 gen_store_spr(SPR_MQ
, t1
);
6326 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
6327 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
6328 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
6329 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
6333 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6334 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6338 /* PowerPC 602 specific instructions */
6341 static void gen_dsa(DisasContext
*ctx
)
6344 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6348 static void gen_esa(DisasContext
*ctx
)
6351 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6355 static void gen_mfrom(DisasContext
*ctx
)
6357 #if defined(CONFIG_USER_ONLY)
6361 gen_helper_602_mfrom(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6362 #endif /* defined(CONFIG_USER_ONLY) */
6365 /* 602 - 603 - G2 TLB management */
6368 static void gen_tlbld_6xx(DisasContext
*ctx
)
6370 #if defined(CONFIG_USER_ONLY)
6374 gen_helper_6xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6375 #endif /* defined(CONFIG_USER_ONLY) */
6379 static void gen_tlbli_6xx(DisasContext
*ctx
)
6381 #if defined(CONFIG_USER_ONLY)
6385 gen_helper_6xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6386 #endif /* defined(CONFIG_USER_ONLY) */
6389 /* 74xx TLB management */
6392 static void gen_tlbld_74xx(DisasContext
*ctx
)
6394 #if defined(CONFIG_USER_ONLY)
6398 gen_helper_74xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6399 #endif /* defined(CONFIG_USER_ONLY) */
6403 static void gen_tlbli_74xx(DisasContext
*ctx
)
6405 #if defined(CONFIG_USER_ONLY)
6409 gen_helper_74xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6410 #endif /* defined(CONFIG_USER_ONLY) */
6413 /* POWER instructions not in PowerPC 601 */
6416 static void gen_clf(DisasContext
*ctx
)
6418 /* Cache line flush: implemented as no-op */
6422 static void gen_cli(DisasContext
*ctx
)
6424 #if defined(CONFIG_USER_ONLY)
6427 /* Cache line invalidate: privileged and treated as no-op */
6429 #endif /* defined(CONFIG_USER_ONLY) */
6433 static void gen_dclst(DisasContext
*ctx
)
6435 /* Data cache line store: treated as no-op */
6438 static void gen_mfsri(DisasContext
*ctx
)
6440 #if defined(CONFIG_USER_ONLY)
6443 int ra
= rA(ctx
->opcode
);
6444 int rd
= rD(ctx
->opcode
);
6448 t0
= tcg_temp_new();
6449 gen_addr_reg_index(ctx
, t0
);
6450 tcg_gen_extract_tl(t0
, t0
, 28, 4);
6451 gen_helper_load_sr(cpu_gpr
[rd
], cpu_env
, t0
);
6453 if (ra
!= 0 && ra
!= rd
) {
6454 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rd
]);
6456 #endif /* defined(CONFIG_USER_ONLY) */
6459 static void gen_rac(DisasContext
*ctx
)
6461 #if defined(CONFIG_USER_ONLY)
6467 t0
= tcg_temp_new();
6468 gen_addr_reg_index(ctx
, t0
);
6469 gen_helper_rac(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
6471 #endif /* defined(CONFIG_USER_ONLY) */
6474 static void gen_rfsvc(DisasContext
*ctx
)
6476 #if defined(CONFIG_USER_ONLY)
6481 gen_helper_rfsvc(cpu_env
);
6482 ctx
->base
.is_jmp
= DISAS_EXIT
;
6483 #endif /* defined(CONFIG_USER_ONLY) */
6486 /* svc is not implemented for now */
6488 /* BookE specific instructions */
6490 /* XXX: not implemented on 440 ? */
6491 static void gen_mfapidi(DisasContext
*ctx
)
6494 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6497 /* XXX: not implemented on 440 ? */
6498 static void gen_tlbiva(DisasContext
*ctx
)
6500 #if defined(CONFIG_USER_ONLY)
6506 t0
= tcg_temp_new();
6507 gen_addr_reg_index(ctx
, t0
);
6508 gen_helper_tlbiva(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6510 #endif /* defined(CONFIG_USER_ONLY) */
6513 /* All 405 MAC instructions are translated here */
6514 static inline void gen_405_mulladd_insn(DisasContext
*ctx
, int opc2
, int opc3
,
6515 int ra
, int rb
, int rt
, int Rc
)
6519 t0
= tcg_temp_local_new();
6520 t1
= tcg_temp_local_new();
6522 switch (opc3
& 0x0D) {
6524 /* macchw - macchw. - macchwo - macchwo. */
6525 /* macchws - macchws. - macchwso - macchwso. */
6526 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
6527 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
6528 /* mulchw - mulchw. */
6529 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
6530 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
6531 tcg_gen_ext16s_tl(t1
, t1
);
6534 /* macchwu - macchwu. - macchwuo - macchwuo. */
6535 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
6536 /* mulchwu - mulchwu. */
6537 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
6538 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
6539 tcg_gen_ext16u_tl(t1
, t1
);
6542 /* machhw - machhw. - machhwo - machhwo. */
6543 /* machhws - machhws. - machhwso - machhwso. */
6544 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
6545 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
6546 /* mulhhw - mulhhw. */
6547 tcg_gen_sari_tl(t0
, cpu_gpr
[ra
], 16);
6548 tcg_gen_ext16s_tl(t0
, t0
);
6549 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
6550 tcg_gen_ext16s_tl(t1
, t1
);
6553 /* machhwu - machhwu. - machhwuo - machhwuo. */
6554 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
6555 /* mulhhwu - mulhhwu. */
6556 tcg_gen_shri_tl(t0
, cpu_gpr
[ra
], 16);
6557 tcg_gen_ext16u_tl(t0
, t0
);
6558 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
6559 tcg_gen_ext16u_tl(t1
, t1
);
6562 /* maclhw - maclhw. - maclhwo - maclhwo. */
6563 /* maclhws - maclhws. - maclhwso - maclhwso. */
6564 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
6565 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
6566 /* mullhw - mullhw. */
6567 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
6568 tcg_gen_ext16s_tl(t1
, cpu_gpr
[rb
]);
6571 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
6572 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
6573 /* mullhwu - mullhwu. */
6574 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
6575 tcg_gen_ext16u_tl(t1
, cpu_gpr
[rb
]);
6579 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
6580 tcg_gen_mul_tl(t1
, t0
, t1
);
6582 /* nmultiply-and-accumulate (0x0E) */
6583 tcg_gen_sub_tl(t0
, cpu_gpr
[rt
], t1
);
6585 /* multiply-and-accumulate (0x0C) */
6586 tcg_gen_add_tl(t0
, cpu_gpr
[rt
], t1
);
6590 /* Check overflow and/or saturate */
6591 TCGLabel
*l1
= gen_new_label();
6594 /* Start with XER OV disabled, the most likely case */
6595 tcg_gen_movi_tl(cpu_ov
, 0);
6599 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t1
);
6600 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
6601 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t0
);
6602 tcg_gen_brcondi_tl(TCG_COND_LT
, t1
, 0, l1
);
6605 tcg_gen_sari_tl(t0
, cpu_gpr
[rt
], 31);
6606 tcg_gen_xori_tl(t0
, t0
, 0x7fffffff);
6610 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
6613 tcg_gen_movi_tl(t0
, UINT32_MAX
);
6617 /* Check overflow */
6618 tcg_gen_movi_tl(cpu_ov
, 1);
6619 tcg_gen_movi_tl(cpu_so
, 1);
6622 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
6625 tcg_gen_mul_tl(cpu_gpr
[rt
], t0
, t1
);
6629 if (unlikely(Rc
) != 0) {
6631 gen_set_Rc0(ctx
, cpu_gpr
[rt
]);
6635 #define GEN_MAC_HANDLER(name, opc2, opc3) \
6636 static void glue(gen_, name)(DisasContext *ctx) \
6638 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
6639 rD(ctx->opcode), Rc(ctx->opcode)); \
6642 /* macchw - macchw. */
6643 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
6644 /* macchwo - macchwo. */
6645 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
6646 /* macchws - macchws. */
6647 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
6648 /* macchwso - macchwso. */
6649 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
6650 /* macchwsu - macchwsu. */
6651 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
6652 /* macchwsuo - macchwsuo. */
6653 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
6654 /* macchwu - macchwu. */
6655 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
6656 /* macchwuo - macchwuo. */
6657 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
6658 /* machhw - machhw. */
6659 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
6660 /* machhwo - machhwo. */
6661 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
6662 /* machhws - machhws. */
6663 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
6664 /* machhwso - machhwso. */
6665 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
6666 /* machhwsu - machhwsu. */
6667 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
6668 /* machhwsuo - machhwsuo. */
6669 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
6670 /* machhwu - machhwu. */
6671 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
6672 /* machhwuo - machhwuo. */
6673 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
6674 /* maclhw - maclhw. */
6675 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
6676 /* maclhwo - maclhwo. */
6677 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
6678 /* maclhws - maclhws. */
6679 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
6680 /* maclhwso - maclhwso. */
6681 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
6682 /* maclhwu - maclhwu. */
6683 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
6684 /* maclhwuo - maclhwuo. */
6685 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
6686 /* maclhwsu - maclhwsu. */
6687 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
6688 /* maclhwsuo - maclhwsuo. */
6689 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
6690 /* nmacchw - nmacchw. */
6691 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
6692 /* nmacchwo - nmacchwo. */
6693 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
6694 /* nmacchws - nmacchws. */
6695 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
6696 /* nmacchwso - nmacchwso. */
6697 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
6698 /* nmachhw - nmachhw. */
6699 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
6700 /* nmachhwo - nmachhwo. */
6701 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
6702 /* nmachhws - nmachhws. */
6703 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
6704 /* nmachhwso - nmachhwso. */
6705 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
6706 /* nmaclhw - nmaclhw. */
6707 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
6708 /* nmaclhwo - nmaclhwo. */
6709 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
6710 /* nmaclhws - nmaclhws. */
6711 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
6712 /* nmaclhwso - nmaclhwso. */
6713 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
6715 /* mulchw - mulchw. */
6716 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
6717 /* mulchwu - mulchwu. */
6718 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
6719 /* mulhhw - mulhhw. */
6720 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
6721 /* mulhhwu - mulhhwu. */
6722 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
6723 /* mullhw - mullhw. */
6724 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
6725 /* mullhwu - mullhwu. */
6726 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
6729 static void gen_mfdcr(DisasContext
*ctx
)
6731 #if defined(CONFIG_USER_ONLY)
6737 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
6738 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, dcrn
);
6739 tcg_temp_free(dcrn
);
6740 #endif /* defined(CONFIG_USER_ONLY) */
6744 static void gen_mtdcr(DisasContext
*ctx
)
6746 #if defined(CONFIG_USER_ONLY)
6752 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
6753 gen_helper_store_dcr(cpu_env
, dcrn
, cpu_gpr
[rS(ctx
->opcode
)]);
6754 tcg_temp_free(dcrn
);
6755 #endif /* defined(CONFIG_USER_ONLY) */
6759 /* XXX: not implemented on 440 ? */
6760 static void gen_mfdcrx(DisasContext
*ctx
)
6762 #if defined(CONFIG_USER_ONLY)
6766 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6767 cpu_gpr
[rA(ctx
->opcode
)]);
6768 /* Note: Rc update flag set leads to undefined state of Rc0 */
6769 #endif /* defined(CONFIG_USER_ONLY) */
6773 /* XXX: not implemented on 440 ? */
6774 static void gen_mtdcrx(DisasContext
*ctx
)
6776 #if defined(CONFIG_USER_ONLY)
6780 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6781 cpu_gpr
[rS(ctx
->opcode
)]);
6782 /* Note: Rc update flag set leads to undefined state of Rc0 */
6783 #endif /* defined(CONFIG_USER_ONLY) */
6786 /* mfdcrux (PPC 460) : user-mode access to DCR */
6787 static void gen_mfdcrux(DisasContext
*ctx
)
6789 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6790 cpu_gpr
[rA(ctx
->opcode
)]);
6791 /* Note: Rc update flag set leads to undefined state of Rc0 */
6794 /* mtdcrux (PPC 460) : user-mode access to DCR */
6795 static void gen_mtdcrux(DisasContext
*ctx
)
6797 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6798 cpu_gpr
[rS(ctx
->opcode
)]);
6799 /* Note: Rc update flag set leads to undefined state of Rc0 */
6803 static void gen_dccci(DisasContext
*ctx
)
6806 /* interpreted as no-op */
6810 static void gen_dcread(DisasContext
*ctx
)
6812 #if defined(CONFIG_USER_ONLY)
6818 gen_set_access_type(ctx
, ACCESS_CACHE
);
6819 EA
= tcg_temp_new();
6820 gen_addr_reg_index(ctx
, EA
);
6821 val
= tcg_temp_new();
6822 gen_qemu_ld32u(ctx
, val
, EA
);
6824 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], EA
);
6826 #endif /* defined(CONFIG_USER_ONLY) */
6830 static void gen_icbt_40x(DisasContext
*ctx
)
6833 * interpreted as no-op
6834 * XXX: specification say this is treated as a load by the MMU but
6835 * does not generate any exception
6840 static void gen_iccci(DisasContext
*ctx
)
6843 /* interpreted as no-op */
6847 static void gen_icread(DisasContext
*ctx
)
6850 /* interpreted as no-op */
6853 /* rfci (supervisor only) */
6854 static void gen_rfci_40x(DisasContext
*ctx
)
6856 #if defined(CONFIG_USER_ONLY)
6860 /* Restore CPU state */
6861 gen_helper_40x_rfci(cpu_env
);
6862 ctx
->base
.is_jmp
= DISAS_EXIT
;
6863 #endif /* defined(CONFIG_USER_ONLY) */
6866 static void gen_rfci(DisasContext
*ctx
)
6868 #if defined(CONFIG_USER_ONLY)
6872 /* Restore CPU state */
6873 gen_helper_rfci(cpu_env
);
6874 ctx
->base
.is_jmp
= DISAS_EXIT
;
6875 #endif /* defined(CONFIG_USER_ONLY) */
6878 /* BookE specific */
6880 /* XXX: not implemented on 440 ? */
6881 static void gen_rfdi(DisasContext
*ctx
)
6883 #if defined(CONFIG_USER_ONLY)
6887 /* Restore CPU state */
6888 gen_helper_rfdi(cpu_env
);
6889 ctx
->base
.is_jmp
= DISAS_EXIT
;
6890 #endif /* defined(CONFIG_USER_ONLY) */
6893 /* XXX: not implemented on 440 ? */
6894 static void gen_rfmci(DisasContext
*ctx
)
6896 #if defined(CONFIG_USER_ONLY)
6900 /* Restore CPU state */
6901 gen_helper_rfmci(cpu_env
);
6902 ctx
->base
.is_jmp
= DISAS_EXIT
;
6903 #endif /* defined(CONFIG_USER_ONLY) */
6906 /* TLB management - PowerPC 405 implementation */
6909 static void gen_tlbre_40x(DisasContext
*ctx
)
6911 #if defined(CONFIG_USER_ONLY)
6915 switch (rB(ctx
->opcode
)) {
6917 gen_helper_4xx_tlbre_hi(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6918 cpu_gpr
[rA(ctx
->opcode
)]);
6921 gen_helper_4xx_tlbre_lo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6922 cpu_gpr
[rA(ctx
->opcode
)]);
6925 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6928 #endif /* defined(CONFIG_USER_ONLY) */
6931 /* tlbsx - tlbsx. */
6932 static void gen_tlbsx_40x(DisasContext
*ctx
)
6934 #if defined(CONFIG_USER_ONLY)
6940 t0
= tcg_temp_new();
6941 gen_addr_reg_index(ctx
, t0
);
6942 gen_helper_4xx_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
6944 if (Rc(ctx
->opcode
)) {
6945 TCGLabel
*l1
= gen_new_label();
6946 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
6947 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
6948 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
6951 #endif /* defined(CONFIG_USER_ONLY) */
6955 static void gen_tlbwe_40x(DisasContext
*ctx
)
6957 #if defined(CONFIG_USER_ONLY)
6962 switch (rB(ctx
->opcode
)) {
6964 gen_helper_4xx_tlbwe_hi(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6965 cpu_gpr
[rS(ctx
->opcode
)]);
6968 gen_helper_4xx_tlbwe_lo(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6969 cpu_gpr
[rS(ctx
->opcode
)]);
6972 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6975 #endif /* defined(CONFIG_USER_ONLY) */
6978 /* TLB management - PowerPC 440 implementation */
6981 static void gen_tlbre_440(DisasContext
*ctx
)
6983 #if defined(CONFIG_USER_ONLY)
6988 switch (rB(ctx
->opcode
)) {
6993 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
6994 gen_helper_440_tlbre(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6995 t0
, cpu_gpr
[rA(ctx
->opcode
)]);
6996 tcg_temp_free_i32(t0
);
7000 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
7003 #endif /* defined(CONFIG_USER_ONLY) */
7006 /* tlbsx - tlbsx. */
7007 static void gen_tlbsx_440(DisasContext
*ctx
)
7009 #if defined(CONFIG_USER_ONLY)
7015 t0
= tcg_temp_new();
7016 gen_addr_reg_index(ctx
, t0
);
7017 gen_helper_440_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
7019 if (Rc(ctx
->opcode
)) {
7020 TCGLabel
*l1
= gen_new_label();
7021 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
7022 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
7023 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
7026 #endif /* defined(CONFIG_USER_ONLY) */
7030 static void gen_tlbwe_440(DisasContext
*ctx
)
7032 #if defined(CONFIG_USER_ONLY)
7036 switch (rB(ctx
->opcode
)) {
7041 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
7042 gen_helper_440_tlbwe(cpu_env
, t0
, cpu_gpr
[rA(ctx
->opcode
)],
7043 cpu_gpr
[rS(ctx
->opcode
)]);
7044 tcg_temp_free_i32(t0
);
7048 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
7051 #endif /* defined(CONFIG_USER_ONLY) */
7054 /* TLB management - PowerPC BookE 2.06 implementation */
7057 static void gen_tlbre_booke206(DisasContext
*ctx
)
7059 #if defined(CONFIG_USER_ONLY)
7063 gen_helper_booke206_tlbre(cpu_env
);
7064 #endif /* defined(CONFIG_USER_ONLY) */
7067 /* tlbsx - tlbsx. */
7068 static void gen_tlbsx_booke206(DisasContext
*ctx
)
7070 #if defined(CONFIG_USER_ONLY)
7076 if (rA(ctx
->opcode
)) {
7077 t0
= tcg_temp_new();
7078 tcg_gen_mov_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)]);
7080 t0
= tcg_const_tl(0);
7083 tcg_gen_add_tl(t0
, t0
, cpu_gpr
[rB(ctx
->opcode
)]);
7084 gen_helper_booke206_tlbsx(cpu_env
, t0
);
7086 #endif /* defined(CONFIG_USER_ONLY) */
7090 static void gen_tlbwe_booke206(DisasContext
*ctx
)
7092 #if defined(CONFIG_USER_ONLY)
7096 gen_helper_booke206_tlbwe(cpu_env
);
7097 #endif /* defined(CONFIG_USER_ONLY) */
7100 static void gen_tlbivax_booke206(DisasContext
*ctx
)
7102 #if defined(CONFIG_USER_ONLY)
7108 t0
= tcg_temp_new();
7109 gen_addr_reg_index(ctx
, t0
);
7110 gen_helper_booke206_tlbivax(cpu_env
, t0
);
7112 #endif /* defined(CONFIG_USER_ONLY) */
7115 static void gen_tlbilx_booke206(DisasContext
*ctx
)
7117 #if defined(CONFIG_USER_ONLY)
7123 t0
= tcg_temp_new();
7124 gen_addr_reg_index(ctx
, t0
);
7126 switch ((ctx
->opcode
>> 21) & 0x3) {
7128 gen_helper_booke206_tlbilx0(cpu_env
, t0
);
7131 gen_helper_booke206_tlbilx1(cpu_env
, t0
);
7134 gen_helper_booke206_tlbilx3(cpu_env
, t0
);
7137 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
7142 #endif /* defined(CONFIG_USER_ONLY) */
7147 static void gen_wrtee(DisasContext
*ctx
)
7149 #if defined(CONFIG_USER_ONLY)
7155 t0
= tcg_temp_new();
7156 tcg_gen_andi_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)], (1 << MSR_EE
));
7157 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
7158 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
7161 * Stop translation to have a chance to raise an exception if we
7162 * just set msr_ee to 1
7164 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
7165 #endif /* defined(CONFIG_USER_ONLY) */
7169 static void gen_wrteei(DisasContext
*ctx
)
7171 #if defined(CONFIG_USER_ONLY)
7175 if (ctx
->opcode
& 0x00008000) {
7176 tcg_gen_ori_tl(cpu_msr
, cpu_msr
, (1 << MSR_EE
));
7177 /* Stop translation to have a chance to raise an exception */
7178 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
7180 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
7182 #endif /* defined(CONFIG_USER_ONLY) */
7185 /* PowerPC 440 specific instructions */
7188 static void gen_dlmzb(DisasContext
*ctx
)
7190 TCGv_i32 t0
= tcg_const_i32(Rc(ctx
->opcode
));
7191 gen_helper_dlmzb(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
7192 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
7193 tcg_temp_free_i32(t0
);
7196 /* mbar replaces eieio on 440 */
7197 static void gen_mbar(DisasContext
*ctx
)
7199 /* interpreted as no-op */
7202 /* msync replaces sync on 440 */
7203 static void gen_msync_4xx(DisasContext
*ctx
)
7205 /* Only e500 seems to treat reserved bits as invalid */
7206 if ((ctx
->insns_flags2
& PPC2_BOOKE206
) &&
7207 (ctx
->opcode
& 0x03FFF801)) {
7208 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
7210 /* otherwise interpreted as no-op */
7214 static void gen_icbt_440(DisasContext
*ctx
)
7217 * interpreted as no-op
7218 * XXX: specification say this is treated as a load by the MMU but
7219 * does not generate any exception
7223 /* Embedded.Processor Control */
7225 static void gen_msgclr(DisasContext
*ctx
)
7227 #if defined(CONFIG_USER_ONLY)
7231 if (is_book3s_arch2x(ctx
)) {
7232 gen_helper_book3s_msgclr(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
7234 gen_helper_msgclr(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
7236 #endif /* defined(CONFIG_USER_ONLY) */
7239 static void gen_msgsnd(DisasContext
*ctx
)
7241 #if defined(CONFIG_USER_ONLY)
7245 if (is_book3s_arch2x(ctx
)) {
7246 gen_helper_book3s_msgsnd(cpu_gpr
[rB(ctx
->opcode
)]);
7248 gen_helper_msgsnd(cpu_gpr
[rB(ctx
->opcode
)]);
7250 #endif /* defined(CONFIG_USER_ONLY) */
7253 #if defined(TARGET_PPC64)
7254 static void gen_msgclrp(DisasContext
*ctx
)
7256 #if defined(CONFIG_USER_ONLY)
7260 gen_helper_book3s_msgclrp(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
7261 #endif /* defined(CONFIG_USER_ONLY) */
7264 static void gen_msgsndp(DisasContext
*ctx
)
7266 #if defined(CONFIG_USER_ONLY)
7270 gen_helper_book3s_msgsndp(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
7271 #endif /* defined(CONFIG_USER_ONLY) */
7275 static void gen_msgsync(DisasContext
*ctx
)
7277 #if defined(CONFIG_USER_ONLY)
7281 #endif /* defined(CONFIG_USER_ONLY) */
7282 /* interpreted as no-op */
7285 #if defined(TARGET_PPC64)
7286 static void gen_maddld(DisasContext
*ctx
)
7288 TCGv_i64 t1
= tcg_temp_new_i64();
7290 tcg_gen_mul_i64(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7291 tcg_gen_add_i64(cpu_gpr
[rD(ctx
->opcode
)], t1
, cpu_gpr
[rC(ctx
->opcode
)]);
7292 tcg_temp_free_i64(t1
);
7295 /* maddhd maddhdu */
7296 static void gen_maddhd_maddhdu(DisasContext
*ctx
)
7298 TCGv_i64 lo
= tcg_temp_new_i64();
7299 TCGv_i64 hi
= tcg_temp_new_i64();
7300 TCGv_i64 t1
= tcg_temp_new_i64();
7302 if (Rc(ctx
->opcode
)) {
7303 tcg_gen_mulu2_i64(lo
, hi
, cpu_gpr
[rA(ctx
->opcode
)],
7304 cpu_gpr
[rB(ctx
->opcode
)]);
7305 tcg_gen_movi_i64(t1
, 0);
7307 tcg_gen_muls2_i64(lo
, hi
, cpu_gpr
[rA(ctx
->opcode
)],
7308 cpu_gpr
[rB(ctx
->opcode
)]);
7309 tcg_gen_sari_i64(t1
, cpu_gpr
[rC(ctx
->opcode
)], 63);
7311 tcg_gen_add2_i64(t1
, cpu_gpr
[rD(ctx
->opcode
)], lo
, hi
,
7312 cpu_gpr
[rC(ctx
->opcode
)], t1
);
7313 tcg_temp_free_i64(lo
);
7314 tcg_temp_free_i64(hi
);
7315 tcg_temp_free_i64(t1
);
7317 #endif /* defined(TARGET_PPC64) */
7319 static void gen_tbegin(DisasContext
*ctx
)
7321 if (unlikely(!ctx
->tm_enabled
)) {
7322 gen_exception_err(ctx
, POWERPC_EXCP_FU
, FSCR_IC_TM
);
7325 gen_helper_tbegin(cpu_env
);
7328 #define GEN_TM_NOOP(name) \
7329 static inline void gen_##name(DisasContext *ctx) \
7331 if (unlikely(!ctx->tm_enabled)) { \
7332 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
7336 * Because tbegin always fails in QEMU, these user \
7337 * space instructions all have a simple implementation: \
7339 * CR[0] = 0b0 || MSR[TS] || 0b0 \
7340 * = 0b0 || 0b00 || 0b0 \
7342 tcg_gen_movi_i32(cpu_crf[0], 0); \
7346 GEN_TM_NOOP(tabort
);
7347 GEN_TM_NOOP(tabortwc
);
7348 GEN_TM_NOOP(tabortwci
);
7349 GEN_TM_NOOP(tabortdc
);
7350 GEN_TM_NOOP(tabortdci
);
7353 static inline void gen_cp_abort(DisasContext
*ctx
)
7358 #define GEN_CP_PASTE_NOOP(name) \
7359 static inline void gen_##name(DisasContext *ctx) \
7362 * Generate invalid exception until we have an \
7363 * implementation of the copy paste facility \
7368 GEN_CP_PASTE_NOOP(copy
)
7369 GEN_CP_PASTE_NOOP(paste
)
7371 static void gen_tcheck(DisasContext
*ctx
)
7373 if (unlikely(!ctx
->tm_enabled
)) {
7374 gen_exception_err(ctx
, POWERPC_EXCP_FU
, FSCR_IC_TM
);
7378 * Because tbegin always fails, the tcheck implementation is
7381 * CR[CRF] = TDOOMED || MSR[TS] || 0b0
7382 * = 0b1 || 0b00 || 0b0
7384 tcg_gen_movi_i32(cpu_crf
[crfD(ctx
->opcode
)], 0x8);
7387 #if defined(CONFIG_USER_ONLY)
7388 #define GEN_TM_PRIV_NOOP(name) \
7389 static inline void gen_##name(DisasContext *ctx) \
7391 gen_priv_exception(ctx, POWERPC_EXCP_PRIV_OPC); \
7396 #define GEN_TM_PRIV_NOOP(name) \
7397 static inline void gen_##name(DisasContext *ctx) \
7400 if (unlikely(!ctx->tm_enabled)) { \
7401 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
7405 * Because tbegin always fails, the implementation is \
7408 * CR[0] = 0b0 || MSR[TS] || 0b0 \
7409 * = 0b0 || 0b00 | 0b0 \
7411 tcg_gen_movi_i32(cpu_crf[0], 0); \
7416 GEN_TM_PRIV_NOOP(treclaim
);
7417 GEN_TM_PRIV_NOOP(trechkpt
);
7419 static inline void get_fpr(TCGv_i64 dst
, int regno
)
7421 tcg_gen_ld_i64(dst
, cpu_env
, fpr_offset(regno
));
7424 static inline void set_fpr(int regno
, TCGv_i64 src
)
7426 tcg_gen_st_i64(src
, cpu_env
, fpr_offset(regno
));
7429 static inline void get_avr64(TCGv_i64 dst
, int regno
, bool high
)
7431 tcg_gen_ld_i64(dst
, cpu_env
, avr64_offset(regno
, high
));
7434 static inline void set_avr64(int regno
, TCGv_i64 src
, bool high
)
7436 tcg_gen_st_i64(src
, cpu_env
, avr64_offset(regno
, high
));
7440 * Helpers for decodetree used by !function for decoding arguments.
7442 static int times_4(DisasContext
*ctx
, int x
)
7448 * Helpers for trans_* functions to check for specific insns flags.
7449 * Use token pasting to ensure that we use the proper flag with the
7452 #define REQUIRE_INSNS_FLAGS(CTX, NAME) \
7454 if (((CTX)->insns_flags & PPC_##NAME) == 0) { \
7459 #define REQUIRE_INSNS_FLAGS2(CTX, NAME) \
7461 if (((CTX)->insns_flags2 & PPC2_##NAME) == 0) { \
7466 /* Then special-case the check for 64-bit so that we elide code for ppc32. */
7467 #if TARGET_LONG_BITS == 32
7468 # define REQUIRE_64BIT(CTX) return false
7470 # define REQUIRE_64BIT(CTX) REQUIRE_INSNS_FLAGS(CTX, 64B)
7474 * Helpers for implementing sets of trans_* functions.
7475 * Defer the implementation of NAME to FUNC, with optional extra arguments.
7477 #define TRANS(NAME, FUNC, ...) \
7478 static bool trans_##NAME(DisasContext *ctx, arg_##NAME *a) \
7479 { return FUNC(ctx, a, __VA_ARGS__); }
7481 #define TRANS64(NAME, FUNC, ...) \
7482 static bool trans_##NAME(DisasContext *ctx, arg_##NAME *a) \
7483 { REQUIRE_64BIT(ctx); return FUNC(ctx, a, __VA_ARGS__); }
7485 /* TODO: More TRANS* helpers for extra insn_flags checks. */
7488 #include "decode-insn32.c.inc"
7489 #include "decode-insn64.c.inc"
7490 #include "translate/fixedpoint-impl.c.inc"
7492 #include "translate/fp-impl.c.inc"
7494 #include "translate/vmx-impl.c.inc"
7496 #include "translate/vsx-impl.c.inc"
7497 #include "translate/vector-impl.c.inc"
7499 #include "translate/dfp-impl.c.inc"
7501 #include "translate/spe-impl.c.inc"
7503 /* Handles lfdp, lxsd, lxssp */
7504 static void gen_dform39(DisasContext
*ctx
)
7506 switch (ctx
->opcode
& 0x3) {
7508 if (ctx
->insns_flags2
& PPC2_ISA205
) {
7509 return gen_lfdp(ctx
);
7513 if (ctx
->insns_flags2
& PPC2_ISA300
) {
7514 return gen_lxsd(ctx
);
7518 if (ctx
->insns_flags2
& PPC2_ISA300
) {
7519 return gen_lxssp(ctx
);
7523 return gen_invalid(ctx
);
7526 /* handles stfdp, lxv, stxsd, stxssp lxvx */
7527 static void gen_dform3D(DisasContext
*ctx
)
7529 if ((ctx
->opcode
& 3) == 1) { /* DQ-FORM */
7530 switch (ctx
->opcode
& 0x7) {
7532 if (ctx
->insns_flags2
& PPC2_ISA300
) {
7533 return gen_lxv(ctx
);
7537 if (ctx
->insns_flags2
& PPC2_ISA300
) {
7538 return gen_stxv(ctx
);
7542 } else { /* DS-FORM */
7543 switch (ctx
->opcode
& 0x3) {
7545 if (ctx
->insns_flags2
& PPC2_ISA205
) {
7546 return gen_stfdp(ctx
);
7550 if (ctx
->insns_flags2
& PPC2_ISA300
) {
7551 return gen_stxsd(ctx
);
7554 case 3: /* stxssp */
7555 if (ctx
->insns_flags2
& PPC2_ISA300
) {
7556 return gen_stxssp(ctx
);
7561 return gen_invalid(ctx
);
7564 #if defined(TARGET_PPC64)
7566 static void gen_brd(DisasContext
*ctx
)
7568 tcg_gen_bswap64_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
7572 static void gen_brw(DisasContext
*ctx
)
7574 tcg_gen_bswap64_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
7575 tcg_gen_rotli_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 32);
7580 static void gen_brh(DisasContext
*ctx
)
7582 TCGv_i64 t0
= tcg_temp_new_i64();
7583 TCGv_i64 t1
= tcg_temp_new_i64();
7584 TCGv_i64 t2
= tcg_temp_new_i64();
7586 tcg_gen_movi_i64(t0
, 0x00ff00ff00ff00ffull
);
7587 tcg_gen_shri_i64(t1
, cpu_gpr
[rS(ctx
->opcode
)], 8);
7588 tcg_gen_and_i64(t2
, t1
, t0
);
7589 tcg_gen_and_i64(t1
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
7590 tcg_gen_shli_i64(t1
, t1
, 8);
7591 tcg_gen_or_i64(cpu_gpr
[rA(ctx
->opcode
)], t1
, t2
);
7593 tcg_temp_free_i64(t0
);
7594 tcg_temp_free_i64(t1
);
7595 tcg_temp_free_i64(t2
);
7599 static opcode_t opcodes
[] = {
7600 #if defined(TARGET_PPC64)
7601 GEN_HANDLER_E(brd
, 0x1F, 0x1B, 0x05, 0x0000F801, PPC_NONE
, PPC2_ISA310
),
7602 GEN_HANDLER_E(brw
, 0x1F, 0x1B, 0x04, 0x0000F801, PPC_NONE
, PPC2_ISA310
),
7603 GEN_HANDLER_E(brh
, 0x1F, 0x1B, 0x06, 0x0000F801, PPC_NONE
, PPC2_ISA310
),
7605 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
),
7606 #if defined(TARGET_PPC64)
7607 GEN_HANDLER_E(cmpeqb
, 0x1F, 0x00, 0x07, 0x00600000, PPC_NONE
, PPC2_ISA300
),
7609 GEN_HANDLER_E(cmpb
, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE
, PPC2_ISA205
),
7610 GEN_HANDLER_E(cmprb
, 0x1F, 0x00, 0x06, 0x00400001, PPC_NONE
, PPC2_ISA300
),
7611 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
),
7612 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7613 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7614 GEN_HANDLER(mulhw
, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER
),
7615 GEN_HANDLER(mulhwu
, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER
),
7616 GEN_HANDLER(mullw
, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER
),
7617 GEN_HANDLER(mullwo
, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER
),
7618 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7619 #if defined(TARGET_PPC64)
7620 GEN_HANDLER(mulld
, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B
),
7622 GEN_HANDLER(neg
, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER
),
7623 GEN_HANDLER(nego
, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER
),
7624 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7625 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7626 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7627 GEN_HANDLER(cntlzw
, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER
),
7628 GEN_HANDLER_E(cnttzw
, 0x1F, 0x1A, 0x10, 0x00000000, PPC_NONE
, PPC2_ISA300
),
7629 GEN_HANDLER_E(copy
, 0x1F, 0x06, 0x18, 0x03C00001, PPC_NONE
, PPC2_ISA300
),
7630 GEN_HANDLER_E(cp_abort
, 0x1F, 0x06, 0x1A, 0x03FFF801, PPC_NONE
, PPC2_ISA300
),
7631 GEN_HANDLER_E(paste
, 0x1F, 0x06, 0x1C, 0x03C00000, PPC_NONE
, PPC2_ISA300
),
7632 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
),
7633 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
),
7634 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7635 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7636 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7637 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7638 GEN_HANDLER(popcntb
, 0x1F, 0x1A, 0x03, 0x0000F801, PPC_POPCNTB
),
7639 GEN_HANDLER(popcntw
, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD
),
7640 GEN_HANDLER_E(prtyw
, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
7641 #if defined(TARGET_PPC64)
7642 GEN_HANDLER(popcntd
, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD
),
7643 GEN_HANDLER(cntlzd
, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B
),
7644 GEN_HANDLER_E(cnttzd
, 0x1F, 0x1A, 0x11, 0x00000000, PPC_NONE
, PPC2_ISA300
),
7645 GEN_HANDLER_E(darn
, 0x1F, 0x13, 0x17, 0x001CF801, PPC_NONE
, PPC2_ISA300
),
7646 GEN_HANDLER_E(prtyd
, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
7647 GEN_HANDLER_E(bpermd
, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE
, PPC2_PERM_ISA206
),
7649 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7650 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7651 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7652 GEN_HANDLER(slw
, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER
),
7653 GEN_HANDLER(sraw
, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER
),
7654 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
),
7655 GEN_HANDLER(srw
, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER
),
7656 #if defined(TARGET_PPC64)
7657 GEN_HANDLER(sld
, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B
),
7658 GEN_HANDLER(srad
, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B
),
7659 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
),
7660 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
),
7661 GEN_HANDLER(srd
, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B
),
7662 GEN_HANDLER2_E(extswsli0
, "extswsli", 0x1F, 0x1A, 0x1B, 0x00000000,
7663 PPC_NONE
, PPC2_ISA300
),
7664 GEN_HANDLER2_E(extswsli1
, "extswsli", 0x1F, 0x1B, 0x1B, 0x00000000,
7665 PPC_NONE
, PPC2_ISA300
),
7667 #if defined(TARGET_PPC64)
7668 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
),
7669 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
),
7671 /* handles lfdp, lxsd, lxssp */
7672 GEN_HANDLER_E(dform39
, 0x39, 0xFF, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA205
),
7673 /* handles stfdp, lxv, stxsd, stxssp, stxv */
7674 GEN_HANDLER_E(dform3D
, 0x3D, 0xFF, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA205
),
7675 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7676 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7677 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
),
7678 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
),
7679 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
),
7680 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
),
7681 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x01FFF801, PPC_MEM_EIEIO
),
7682 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
),
7683 GEN_HANDLER_E(lbarx
, 0x1F, 0x14, 0x01, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
7684 GEN_HANDLER_E(lharx
, 0x1F, 0x14, 0x03, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
7685 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES
),
7686 GEN_HANDLER_E(lwat
, 0x1F, 0x06, 0x12, 0x00000001, PPC_NONE
, PPC2_ISA300
),
7687 GEN_HANDLER_E(stwat
, 0x1F, 0x06, 0x16, 0x00000001, PPC_NONE
, PPC2_ISA300
),
7688 GEN_HANDLER_E(stbcx_
, 0x1F, 0x16, 0x15, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
7689 GEN_HANDLER_E(sthcx_
, 0x1F, 0x16, 0x16, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
7690 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
),
7691 #if defined(TARGET_PPC64)
7692 GEN_HANDLER_E(ldat
, 0x1F, 0x06, 0x13, 0x00000001, PPC_NONE
, PPC2_ISA300
),
7693 GEN_HANDLER_E(stdat
, 0x1F, 0x06, 0x17, 0x00000001, PPC_NONE
, PPC2_ISA300
),
7694 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B
),
7695 GEN_HANDLER_E(lqarx
, 0x1F, 0x14, 0x08, 0, PPC_NONE
, PPC2_LSQ_ISA207
),
7696 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
),
7697 GEN_HANDLER_E(stqcx_
, 0x1F, 0x16, 0x05, 0, PPC_NONE
, PPC2_LSQ_ISA207
),
7699 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
),
7700 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
),
7701 GEN_HANDLER_E(wait
, 0x1F, 0x1E, 0x00, 0x039FF801, PPC_NONE
, PPC2_ISA300
),
7702 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
7703 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
7704 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
),
7705 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
),
7706 GEN_HANDLER_E(bctar
, 0x13, 0x10, 0x11, 0x0000E000, PPC_NONE
, PPC2_BCTAR_ISA207
),
7707 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
),
7708 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
),
7709 #if defined(TARGET_PPC64)
7710 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
),
7711 #if !defined(CONFIG_USER_ONLY)
7712 /* Top bit of opc2 corresponds with low bit of LEV, so use two handlers */
7713 GEN_HANDLER_E(scv
, 0x11, 0x10, 0xFF, 0x03FFF01E, PPC_NONE
, PPC2_ISA300
),
7714 GEN_HANDLER_E(scv
, 0x11, 0x00, 0xFF, 0x03FFF01E, PPC_NONE
, PPC2_ISA300
),
7715 GEN_HANDLER_E(rfscv
, 0x13, 0x12, 0x02, 0x03FF8001, PPC_NONE
, PPC2_ISA300
),
7717 GEN_HANDLER_E(stop
, 0x13, 0x12, 0x0b, 0x03FFF801, PPC_NONE
, PPC2_ISA300
),
7718 GEN_HANDLER_E(doze
, 0x13, 0x12, 0x0c, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
7719 GEN_HANDLER_E(nap
, 0x13, 0x12, 0x0d, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
7720 GEN_HANDLER_E(sleep
, 0x13, 0x12, 0x0e, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
7721 GEN_HANDLER_E(rvwinkle
, 0x13, 0x12, 0x0f, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
7722 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
),
7724 /* Top bit of opc2 corresponds with low bit of LEV, so use two handlers */
7725 GEN_HANDLER(sc
, 0x11, 0x11, 0xFF, 0x03FFF01D, PPC_FLOW
),
7726 GEN_HANDLER(sc
, 0x11, 0x01, 0xFF, 0x03FFF01D, PPC_FLOW
),
7727 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
),
7728 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
7729 #if defined(TARGET_PPC64)
7730 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
),
7731 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
),
7733 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
),
7734 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
),
7735 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
),
7736 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
),
7737 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
),
7738 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
),
7739 #if defined(TARGET_PPC64)
7740 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
),
7741 GEN_HANDLER_E(setb
, 0x1F, 0x00, 0x04, 0x0003F801, PPC_NONE
, PPC2_ISA300
),
7742 GEN_HANDLER_E(mcrxrx
, 0x1F, 0x00, 0x12, 0x007FF801, PPC_NONE
, PPC2_ISA300
),
7744 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001EF801, PPC_MISC
),
7745 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000000, PPC_MISC
),
7746 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
),
7747 GEN_HANDLER_E(dcbfep
, 0x1F, 0x1F, 0x03, 0x03C00001, PPC_NONE
, PPC2_BOOKE206
),
7748 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
),
7749 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
),
7750 GEN_HANDLER_E(dcbstep
, 0x1F, 0x1F, 0x01, 0x03E00001, PPC_NONE
, PPC2_BOOKE206
),
7751 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE
),
7752 GEN_HANDLER_E(dcbtep
, 0x1F, 0x1F, 0x09, 0x00000001, PPC_NONE
, PPC2_BOOKE206
),
7753 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE
),
7754 GEN_HANDLER_E(dcbtstep
, 0x1F, 0x1F, 0x07, 0x00000001, PPC_NONE
, PPC2_BOOKE206
),
7755 GEN_HANDLER_E(dcbtls
, 0x1F, 0x06, 0x05, 0x02000001, PPC_BOOKE
, PPC2_BOOKE206
),
7756 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ
),
7757 GEN_HANDLER_E(dcbzep
, 0x1F, 0x1F, 0x1F, 0x03C00001, PPC_NONE
, PPC2_BOOKE206
),
7758 GEN_HANDLER(dst
, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC
),
7759 GEN_HANDLER(dstst
, 0x1F, 0x16, 0x0B, 0x01800001, PPC_ALTIVEC
),
7760 GEN_HANDLER(dss
, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC
),
7761 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
),
7762 GEN_HANDLER_E(icbiep
, 0x1F, 0x1F, 0x1E, 0x03E00001, PPC_NONE
, PPC2_BOOKE206
),
7763 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
),
7764 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
),
7765 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
),
7766 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
),
7767 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
),
7768 #if defined(TARGET_PPC64)
7769 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
),
7770 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
7772 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
),
7773 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
7775 GEN_HANDLER2(slbmte
, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B
),
7776 GEN_HANDLER2(slbmfee
, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B
),
7777 GEN_HANDLER2(slbmfev
, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B
),
7778 GEN_HANDLER2(slbfee_
, "slbfee.", 0x1F, 0x13, 0x1E, 0x001F0000, PPC_SEGMENT_64B
),
7780 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
),
7782 * XXX Those instructions will need to be handled differently for
7783 * different ISA versions
7785 GEN_HANDLER(tlbiel
, 0x1F, 0x12, 0x08, 0x001F0001, PPC_MEM_TLBIE
),
7786 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x001F0001, PPC_MEM_TLBIE
),
7787 GEN_HANDLER_E(tlbiel
, 0x1F, 0x12, 0x08, 0x00100001, PPC_NONE
, PPC2_ISA300
),
7788 GEN_HANDLER_E(tlbie
, 0x1F, 0x12, 0x09, 0x00100001, PPC_NONE
, PPC2_ISA300
),
7789 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
),
7790 #if defined(TARGET_PPC64)
7791 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x031FFC01, PPC_SLBI
),
7792 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
),
7793 GEN_HANDLER_E(slbieg
, 0x1F, 0x12, 0x0E, 0x001F0001, PPC_NONE
, PPC2_ISA300
),
7794 GEN_HANDLER_E(slbsync
, 0x1F, 0x12, 0x0A, 0x03FFF801, PPC_NONE
, PPC2_ISA300
),
7796 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
),
7797 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
),
7798 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
),
7799 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
),
7800 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
),
7801 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
),
7802 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
),
7803 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
),
7804 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
),
7805 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
),
7806 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
),
7807 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
7808 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
),
7809 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
),
7810 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
),
7811 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
),
7812 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
),
7813 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
),
7814 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
),
7815 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
7816 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
),
7817 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
),
7818 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
),
7819 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
),
7820 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
),
7821 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
),
7822 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
),
7823 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
),
7824 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
),
7825 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
),
7826 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
),
7827 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
),
7828 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
),
7829 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
),
7830 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
),
7831 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
),
7832 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
),
7833 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
),
7834 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
),
7835 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
),
7836 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
),
7837 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
),
7838 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
),
7839 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
),
7840 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
),
7841 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
),
7842 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
),
7843 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
),
7844 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
),
7845 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
7846 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
7847 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
),
7848 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
),
7849 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
7850 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
7851 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
),
7852 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
),
7853 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
),
7854 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
),
7855 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
),
7856 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
),
7857 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
),
7858 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
),
7859 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
),
7860 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
),
7861 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
),
7862 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
),
7863 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
),
7864 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
),
7865 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
),
7866 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
),
7867 GEN_HANDLER_E(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
, PPC2_BOOKE206
),
7868 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
),
7869 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
),
7870 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
),
7871 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
),
7872 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
),
7873 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
),
7874 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
),
7875 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
),
7876 GEN_HANDLER2_E(tlbre_booke206
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
7877 PPC_NONE
, PPC2_BOOKE206
),
7878 GEN_HANDLER2_E(tlbsx_booke206
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
7879 PPC_NONE
, PPC2_BOOKE206
),
7880 GEN_HANDLER2_E(tlbwe_booke206
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
7881 PPC_NONE
, PPC2_BOOKE206
),
7882 GEN_HANDLER2_E(tlbivax_booke206
, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
7883 PPC_NONE
, PPC2_BOOKE206
),
7884 GEN_HANDLER2_E(tlbilx_booke206
, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
7885 PPC_NONE
, PPC2_BOOKE206
),
7886 GEN_HANDLER2_E(msgsnd
, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
7887 PPC_NONE
, PPC2_PRCNTL
),
7888 GEN_HANDLER2_E(msgclr
, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
7889 PPC_NONE
, PPC2_PRCNTL
),
7890 GEN_HANDLER2_E(msgsync
, "msgsync", 0x1F, 0x16, 0x1B, 0x00000000,
7891 PPC_NONE
, PPC2_PRCNTL
),
7892 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
),
7893 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE
),
7894 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
),
7895 GEN_HANDLER_E(mbar
, 0x1F, 0x16, 0x1a, 0x001FF801,
7896 PPC_BOOKE
, PPC2_BOOKE206
),
7897 GEN_HANDLER(msync_4xx
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_BOOKE
),
7898 GEN_HANDLER2_E(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
7899 PPC_BOOKE
, PPC2_BOOKE206
),
7900 GEN_HANDLER2(icbt_440
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001,
7902 GEN_HANDLER(lvsl
, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC
),
7903 GEN_HANDLER(lvsr
, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC
),
7904 GEN_HANDLER(mfvscr
, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC
),
7905 GEN_HANDLER(mtvscr
, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC
),
7906 GEN_HANDLER(vmladduhm
, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC
),
7907 #if defined(TARGET_PPC64)
7908 GEN_HANDLER_E(maddhd_maddhdu
, 0x04, 0x18, 0xFF, 0x00000000, PPC_NONE
,
7910 GEN_HANDLER_E(maddld
, 0x04, 0x19, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA300
),
7911 GEN_HANDLER2_E(msgsndp
, "msgsndp", 0x1F, 0x0E, 0x04, 0x03ff0001,
7912 PPC_NONE
, PPC2_ISA207S
),
7913 GEN_HANDLER2_E(msgclrp
, "msgclrp", 0x1F, 0x0E, 0x05, 0x03ff0001,
7914 PPC_NONE
, PPC2_ISA207S
),
7917 #undef GEN_INT_ARITH_ADD
7918 #undef GEN_INT_ARITH_ADD_CONST
7919 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
7920 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
7921 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
7922 add_ca, compute_ca, compute_ov) \
7923 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
7924 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
7925 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
7926 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
7927 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
7928 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
7929 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
7930 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
7931 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
7932 GEN_HANDLER_E(addex
, 0x1F, 0x0A, 0x05, 0x00000000, PPC_NONE
, PPC2_ISA300
),
7933 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
7934 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
7936 #undef GEN_INT_ARITH_DIVW
7937 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
7938 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
7939 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0),
7940 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1),
7941 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0),
7942 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1),
7943 GEN_HANDLER_E(divwe
, 0x1F, 0x0B, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
7944 GEN_HANDLER_E(divweo
, 0x1F, 0x0B, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
7945 GEN_HANDLER_E(divweu
, 0x1F, 0x0B, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
7946 GEN_HANDLER_E(divweuo
, 0x1F, 0x0B, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
7947 GEN_HANDLER_E(modsw
, 0x1F, 0x0B, 0x18, 0x00000001, PPC_NONE
, PPC2_ISA300
),
7948 GEN_HANDLER_E(moduw
, 0x1F, 0x0B, 0x08, 0x00000001, PPC_NONE
, PPC2_ISA300
),
7950 #if defined(TARGET_PPC64)
7951 #undef GEN_INT_ARITH_DIVD
7952 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
7953 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
7954 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0),
7955 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1),
7956 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0),
7957 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1),
7959 GEN_HANDLER_E(divdeu
, 0x1F, 0x09, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
7960 GEN_HANDLER_E(divdeuo
, 0x1F, 0x09, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
7961 GEN_HANDLER_E(divde
, 0x1F, 0x09, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
7962 GEN_HANDLER_E(divdeo
, 0x1F, 0x09, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
7963 GEN_HANDLER_E(modsd
, 0x1F, 0x09, 0x18, 0x00000001, PPC_NONE
, PPC2_ISA300
),
7964 GEN_HANDLER_E(modud
, 0x1F, 0x09, 0x08, 0x00000001, PPC_NONE
, PPC2_ISA300
),
7966 #undef GEN_INT_ARITH_MUL_HELPER
7967 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
7968 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
7969 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00),
7970 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02),
7971 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17),
7974 #undef GEN_INT_ARITH_SUBF
7975 #undef GEN_INT_ARITH_SUBF_CONST
7976 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
7977 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
7978 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
7979 add_ca, compute_ca, compute_ov) \
7980 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
7981 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
7982 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
7983 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
7984 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
7985 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
7986 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
7987 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
7988 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
7989 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
7990 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
7994 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
7995 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
7996 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
7997 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
7998 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
),
7999 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
),
8000 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
),
8001 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
),
8002 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
),
8003 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
),
8004 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
),
8005 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
),
8006 #if defined(TARGET_PPC64)
8007 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
),
8010 #if defined(TARGET_PPC64)
8013 #define GEN_PPC64_R2(name, opc1, opc2) \
8014 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8015 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
8017 #define GEN_PPC64_R4(name, opc1, opc2) \
8018 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8019 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
8021 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
8023 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
8025 GEN_PPC64_R4(rldicl
, 0x1E, 0x00),
8026 GEN_PPC64_R4(rldicr
, 0x1E, 0x02),
8027 GEN_PPC64_R4(rldic
, 0x1E, 0x04),
8028 GEN_PPC64_R2(rldcl
, 0x1E, 0x08),
8029 GEN_PPC64_R2(rldcr
, 0x1E, 0x09),
8030 GEN_PPC64_R4(rldimi
, 0x1E, 0x06),
8034 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2, chk) \
8035 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
8037 #if defined(TARGET_PPC64)
8038 GEN_LDX_E(ldbr
, ld64ur_i64
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
, CHK_NONE
)
8040 /* HV/P7 and later only */
8041 GEN_LDX_HVRM(ldcix
, ld64_i64
, 0x15, 0x1b, PPC_CILDST
)
8042 GEN_LDX_HVRM(lwzcix
, ld32u
, 0x15, 0x18, PPC_CILDST
)
8043 GEN_LDX_HVRM(lhzcix
, ld16u
, 0x15, 0x19, PPC_CILDST
)
8044 GEN_LDX_HVRM(lbzcix
, ld8u
, 0x15, 0x1a, PPC_CILDST
)
8046 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
)
8047 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
)
8049 /* External PID based load */
8051 #define GEN_LDEPX(name, ldop, opc2, opc3) \
8052 GEN_HANDLER_E(name##epx, 0x1F, opc2, opc3, \
8053 0x00000001, PPC_NONE, PPC2_BOOKE206),
8055 GEN_LDEPX(lb
, DEF_MEMOP(MO_UB
), 0x1F, 0x02)
8056 GEN_LDEPX(lh
, DEF_MEMOP(MO_UW
), 0x1F, 0x08)
8057 GEN_LDEPX(lw
, DEF_MEMOP(MO_UL
), 0x1F, 0x00)
8058 #if defined(TARGET_PPC64)
8059 GEN_LDEPX(ld
, DEF_MEMOP(MO_Q
), 0x1D, 0x00)
8063 #define GEN_STX_E(name, stop, opc2, opc3, type, type2, chk) \
8064 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000000, type, type2),
8066 #if defined(TARGET_PPC64)
8067 GEN_STX_E(stdbr
, st64r_i64
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
, CHK_NONE
)
8068 GEN_STX_HVRM(stdcix
, st64_i64
, 0x15, 0x1f, PPC_CILDST
)
8069 GEN_STX_HVRM(stwcix
, st32
, 0x15, 0x1c, PPC_CILDST
)
8070 GEN_STX_HVRM(sthcix
, st16
, 0x15, 0x1d, PPC_CILDST
)
8071 GEN_STX_HVRM(stbcix
, st8
, 0x15, 0x1e, PPC_CILDST
)
8073 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
)
8074 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
)
8077 #define GEN_STEPX(name, ldop, opc2, opc3) \
8078 GEN_HANDLER_E(name##epx, 0x1F, opc2, opc3, \
8079 0x00000001, PPC_NONE, PPC2_BOOKE206),
8081 GEN_STEPX(stb
, DEF_MEMOP(MO_UB
), 0x1F, 0x06)
8082 GEN_STEPX(sth
, DEF_MEMOP(MO_UW
), 0x1F, 0x0C)
8083 GEN_STEPX(stw
, DEF_MEMOP(MO_UL
), 0x1F, 0x04)
8084 #if defined(TARGET_PPC64)
8085 GEN_STEPX(std
, DEF_MEMOP(MO_Q
), 0x1D, 0x04)
8089 #define GEN_CRLOGIC(name, tcg_op, opc) \
8090 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
8091 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08),
8092 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04),
8093 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09),
8094 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07),
8095 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01),
8096 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E),
8097 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D),
8098 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06),
8100 #undef GEN_MAC_HANDLER
8101 #define GEN_MAC_HANDLER(name, opc2, opc3) \
8102 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
8103 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05),
8104 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15),
8105 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07),
8106 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17),
8107 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06),
8108 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16),
8109 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04),
8110 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14),
8111 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01),
8112 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11),
8113 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03),
8114 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13),
8115 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02),
8116 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12),
8117 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00),
8118 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10),
8119 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D),
8120 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D),
8121 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F),
8122 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F),
8123 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C),
8124 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C),
8125 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E),
8126 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E),
8127 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05),
8128 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15),
8129 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07),
8130 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17),
8131 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01),
8132 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11),
8133 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03),
8134 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13),
8135 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D),
8136 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D),
8137 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F),
8138 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F),
8139 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05),
8140 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04),
8141 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01),
8142 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00),
8143 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D),
8144 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C),
8146 GEN_HANDLER2_E(tbegin
, "tbegin", 0x1F, 0x0E, 0x14, 0x01DFF800, \
8148 GEN_HANDLER2_E(tend
, "tend", 0x1F, 0x0E, 0x15, 0x01FFF800, \
8150 GEN_HANDLER2_E(tabort
, "tabort", 0x1F, 0x0E, 0x1C, 0x03E0F800, \
8152 GEN_HANDLER2_E(tabortwc
, "tabortwc", 0x1F, 0x0E, 0x18, 0x00000000, \
8154 GEN_HANDLER2_E(tabortwci
, "tabortwci", 0x1F, 0x0E, 0x1A, 0x00000000, \
8156 GEN_HANDLER2_E(tabortdc
, "tabortdc", 0x1F, 0x0E, 0x19, 0x00000000, \
8158 GEN_HANDLER2_E(tabortdci
, "tabortdci", 0x1F, 0x0E, 0x1B, 0x00000000, \
8160 GEN_HANDLER2_E(tsr
, "tsr", 0x1F, 0x0E, 0x17, 0x03DFF800, \
8162 GEN_HANDLER2_E(tcheck
, "tcheck", 0x1F, 0x0E, 0x16, 0x007FF800, \
8164 GEN_HANDLER2_E(treclaim
, "treclaim", 0x1F, 0x0E, 0x1D, 0x03E0F800, \
8166 GEN_HANDLER2_E(trechkpt
, "trechkpt", 0x1F, 0x0E, 0x1F, 0x03FFF800, \
8169 #include "translate/fp-ops.c.inc"
8171 #include "translate/vmx-ops.c.inc"
8173 #include "translate/vsx-ops.c.inc"
8175 #include "translate/dfp-ops.c.inc"
8177 #include "translate/spe-ops.c.inc"
8180 /*****************************************************************************/
8183 PPC_DIRECT
= 0, /* Opcode routine */
8184 PPC_INDIRECT
= 1, /* Indirect opcode table */
8187 #define PPC_OPCODE_MASK 0x3
8189 static inline int is_indirect_opcode(void *handler
)
8191 return ((uintptr_t)handler
& PPC_OPCODE_MASK
) == PPC_INDIRECT
;
8194 static inline opc_handler_t
**ind_table(void *handler
)
8196 return (opc_handler_t
**)((uintptr_t)handler
& ~PPC_OPCODE_MASK
);
8199 /* Instruction table creation */
8200 /* Opcodes tables creation */
8201 static void fill_new_table(opc_handler_t
**table
, int len
)
8205 for (i
= 0; i
< len
; i
++) {
8206 table
[i
] = &invalid_handler
;
8210 static int create_new_table(opc_handler_t
**table
, unsigned char idx
)
8212 opc_handler_t
**tmp
;
8214 tmp
= g_new(opc_handler_t
*, PPC_CPU_INDIRECT_OPCODES_LEN
);
8215 fill_new_table(tmp
, PPC_CPU_INDIRECT_OPCODES_LEN
);
8216 table
[idx
] = (opc_handler_t
*)((uintptr_t)tmp
| PPC_INDIRECT
);
8221 static int insert_in_table(opc_handler_t
**table
, unsigned char idx
,
8222 opc_handler_t
*handler
)
8224 if (table
[idx
] != &invalid_handler
) {
8227 table
[idx
] = handler
;
8232 static int register_direct_insn(opc_handler_t
**ppc_opcodes
,
8233 unsigned char idx
, opc_handler_t
*handler
)
8235 if (insert_in_table(ppc_opcodes
, idx
, handler
) < 0) {
8236 printf("*** ERROR: opcode %02x already assigned in main "
8237 "opcode table\n", idx
);
8244 static int register_ind_in_table(opc_handler_t
**table
,
8245 unsigned char idx1
, unsigned char idx2
,
8246 opc_handler_t
*handler
)
8248 if (table
[idx1
] == &invalid_handler
) {
8249 if (create_new_table(table
, idx1
) < 0) {
8250 printf("*** ERROR: unable to create indirect table "
8251 "idx=%02x\n", idx1
);
8255 if (!is_indirect_opcode(table
[idx1
])) {
8256 printf("*** ERROR: idx %02x already assigned to a direct "
8261 if (handler
!= NULL
&&
8262 insert_in_table(ind_table(table
[idx1
]), idx2
, handler
) < 0) {
8263 printf("*** ERROR: opcode %02x already assigned in "
8264 "opcode table %02x\n", idx2
, idx1
);
8271 static int register_ind_insn(opc_handler_t
**ppc_opcodes
,
8272 unsigned char idx1
, unsigned char idx2
,
8273 opc_handler_t
*handler
)
8275 return register_ind_in_table(ppc_opcodes
, idx1
, idx2
, handler
);
8278 static int register_dblind_insn(opc_handler_t
**ppc_opcodes
,
8279 unsigned char idx1
, unsigned char idx2
,
8280 unsigned char idx3
, opc_handler_t
*handler
)
8282 if (register_ind_in_table(ppc_opcodes
, idx1
, idx2
, NULL
) < 0) {
8283 printf("*** ERROR: unable to join indirect table idx "
8284 "[%02x-%02x]\n", idx1
, idx2
);
8287 if (register_ind_in_table(ind_table(ppc_opcodes
[idx1
]), idx2
, idx3
,
8289 printf("*** ERROR: unable to insert opcode "
8290 "[%02x-%02x-%02x]\n", idx1
, idx2
, idx3
);
8297 static int register_trplind_insn(opc_handler_t
**ppc_opcodes
,
8298 unsigned char idx1
, unsigned char idx2
,
8299 unsigned char idx3
, unsigned char idx4
,
8300 opc_handler_t
*handler
)
8302 opc_handler_t
**table
;
8304 if (register_ind_in_table(ppc_opcodes
, idx1
, idx2
, NULL
) < 0) {
8305 printf("*** ERROR: unable to join indirect table idx "
8306 "[%02x-%02x]\n", idx1
, idx2
);
8309 table
= ind_table(ppc_opcodes
[idx1
]);
8310 if (register_ind_in_table(table
, idx2
, idx3
, NULL
) < 0) {
8311 printf("*** ERROR: unable to join 2nd-level indirect table idx "
8312 "[%02x-%02x-%02x]\n", idx1
, idx2
, idx3
);
8315 table
= ind_table(table
[idx2
]);
8316 if (register_ind_in_table(table
, idx3
, idx4
, handler
) < 0) {
8317 printf("*** ERROR: unable to insert opcode "
8318 "[%02x-%02x-%02x-%02x]\n", idx1
, idx2
, idx3
, idx4
);
8323 static int register_insn(opc_handler_t
**ppc_opcodes
, opcode_t
*insn
)
8325 if (insn
->opc2
!= 0xFF) {
8326 if (insn
->opc3
!= 0xFF) {
8327 if (insn
->opc4
!= 0xFF) {
8328 if (register_trplind_insn(ppc_opcodes
, insn
->opc1
, insn
->opc2
,
8329 insn
->opc3
, insn
->opc4
,
8330 &insn
->handler
) < 0) {
8334 if (register_dblind_insn(ppc_opcodes
, insn
->opc1
, insn
->opc2
,
8335 insn
->opc3
, &insn
->handler
) < 0) {
8340 if (register_ind_insn(ppc_opcodes
, insn
->opc1
,
8341 insn
->opc2
, &insn
->handler
) < 0) {
8346 if (register_direct_insn(ppc_opcodes
, insn
->opc1
, &insn
->handler
) < 0) {
8354 static int test_opcode_table(opc_handler_t
**table
, int len
)
8358 for (i
= 0, count
= 0; i
< len
; i
++) {
8359 /* Consistency fixup */
8360 if (table
[i
] == NULL
) {
8361 table
[i
] = &invalid_handler
;
8363 if (table
[i
] != &invalid_handler
) {
8364 if (is_indirect_opcode(table
[i
])) {
8365 tmp
= test_opcode_table(ind_table(table
[i
]),
8366 PPC_CPU_INDIRECT_OPCODES_LEN
);
8369 table
[i
] = &invalid_handler
;
8382 static void fix_opcode_tables(opc_handler_t
**ppc_opcodes
)
8384 if (test_opcode_table(ppc_opcodes
, PPC_CPU_OPCODES_LEN
) == 0) {
8385 printf("*** WARNING: no opcode defined !\n");
8389 /*****************************************************************************/
8390 void create_ppc_opcodes(PowerPCCPU
*cpu
, Error
**errp
)
8392 PowerPCCPUClass
*pcc
= POWERPC_CPU_GET_CLASS(cpu
);
8395 fill_new_table(cpu
->opcodes
, PPC_CPU_OPCODES_LEN
);
8396 for (opc
= opcodes
; opc
< &opcodes
[ARRAY_SIZE(opcodes
)]; opc
++) {
8397 if (((opc
->handler
.type
& pcc
->insns_flags
) != 0) ||
8398 ((opc
->handler
.type2
& pcc
->insns_flags2
) != 0)) {
8399 if (register_insn(cpu
->opcodes
, opc
) < 0) {
8400 error_setg(errp
, "ERROR initializing PowerPC instruction "
8401 "0x%02x 0x%02x 0x%02x", opc
->opc1
, opc
->opc2
,
8407 fix_opcode_tables(cpu
->opcodes
);
8412 void destroy_ppc_opcodes(PowerPCCPU
*cpu
)
8414 opc_handler_t
**table
, **table_2
;
8417 for (i
= 0; i
< PPC_CPU_OPCODES_LEN
; i
++) {
8418 if (cpu
->opcodes
[i
] == &invalid_handler
) {
8421 if (is_indirect_opcode(cpu
->opcodes
[i
])) {
8422 table
= ind_table(cpu
->opcodes
[i
]);
8423 for (j
= 0; j
< PPC_CPU_INDIRECT_OPCODES_LEN
; j
++) {
8424 if (table
[j
] == &invalid_handler
) {
8427 if (is_indirect_opcode(table
[j
])) {
8428 table_2
= ind_table(table
[j
]);
8429 for (k
= 0; k
< PPC_CPU_INDIRECT_OPCODES_LEN
; k
++) {
8430 if (table_2
[k
] != &invalid_handler
&&
8431 is_indirect_opcode(table_2
[k
])) {
8432 g_free((opc_handler_t
*)((uintptr_t)table_2
[k
] &
8436 g_free((opc_handler_t
*)((uintptr_t)table
[j
] &
8440 g_free((opc_handler_t
*)((uintptr_t)cpu
->opcodes
[i
] &
8446 int ppc_fixup_cpu(PowerPCCPU
*cpu
)
8448 CPUPPCState
*env
= &cpu
->env
;
8451 * TCG doesn't (yet) emulate some groups of instructions that are
8452 * implemented on some otherwise supported CPUs (e.g. VSX and
8453 * decimal floating point instructions on POWER7). We remove
8454 * unsupported instruction groups from the cpu state's instruction
8455 * masks and hope the guest can cope. For at least the pseries
8456 * machine, the unavailability of these instructions can be
8457 * advertised to the guest via the device tree.
8459 if ((env
->insns_flags
& ~PPC_TCG_INSNS
)
8460 || (env
->insns_flags2
& ~PPC_TCG_INSNS2
)) {
8461 warn_report("Disabling some instructions which are not "
8462 "emulated by TCG (0x%" PRIx64
", 0x%" PRIx64
")",
8463 env
->insns_flags
& ~PPC_TCG_INSNS
,
8464 env
->insns_flags2
& ~PPC_TCG_INSNS2
);
8466 env
->insns_flags
&= PPC_TCG_INSNS
;
8467 env
->insns_flags2
&= PPC_TCG_INSNS2
;
8471 static bool decode_legacy(PowerPCCPU
*cpu
, DisasContext
*ctx
, uint32_t insn
)
8473 opc_handler_t
**table
, *handler
;
8478 LOG_DISAS("translate opcode %08x (%02x %02x %02x %02x) (%s)\n",
8479 insn
, opc1(insn
), opc2(insn
), opc3(insn
), opc4(insn
),
8480 ctx
->le_mode
? "little" : "big");
8482 table
= cpu
->opcodes
;
8483 handler
= table
[opc1(insn
)];
8484 if (is_indirect_opcode(handler
)) {
8485 table
= ind_table(handler
);
8486 handler
= table
[opc2(insn
)];
8487 if (is_indirect_opcode(handler
)) {
8488 table
= ind_table(handler
);
8489 handler
= table
[opc3(insn
)];
8490 if (is_indirect_opcode(handler
)) {
8491 table
= ind_table(handler
);
8492 handler
= table
[opc4(insn
)];
8497 /* Is opcode *REALLY* valid ? */
8498 if (unlikely(handler
->handler
== &gen_invalid
)) {
8499 qemu_log_mask(LOG_GUEST_ERROR
, "invalid/unsupported opcode: "
8500 "%02x - %02x - %02x - %02x (%08x) "
8502 opc1(insn
), opc2(insn
), opc3(insn
), opc4(insn
),
8507 if (unlikely(handler
->type
& (PPC_SPE
| PPC_SPE_SINGLE
| PPC_SPE_DOUBLE
)
8509 inval
= handler
->inval2
;
8511 inval
= handler
->inval1
;
8514 if (unlikely((insn
& inval
) != 0)) {
8515 qemu_log_mask(LOG_GUEST_ERROR
, "invalid bits: %08x for opcode: "
8516 "%02x - %02x - %02x - %02x (%08x) "
8517 TARGET_FMT_lx
"\n", insn
& inval
,
8518 opc1(insn
), opc2(insn
), opc3(insn
), opc4(insn
),
8523 handler
->handler(ctx
);
8527 static void ppc_tr_init_disas_context(DisasContextBase
*dcbase
, CPUState
*cs
)
8529 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
8530 CPUPPCState
*env
= cs
->env_ptr
;
8531 uint32_t hflags
= ctx
->base
.tb
->flags
;
8533 ctx
->spr_cb
= env
->spr_cb
;
8534 ctx
->pr
= (hflags
>> HFLAGS_PR
) & 1;
8535 ctx
->mem_idx
= (hflags
>> HFLAGS_DMMU_IDX
) & 7;
8536 ctx
->dr
= (hflags
>> HFLAGS_DR
) & 1;
8537 ctx
->hv
= (hflags
>> HFLAGS_HV
) & 1;
8538 ctx
->insns_flags
= env
->insns_flags
;
8539 ctx
->insns_flags2
= env
->insns_flags2
;
8540 ctx
->access_type
= -1;
8541 ctx
->need_access_type
= !mmu_is_64bit(env
->mmu_model
);
8542 ctx
->le_mode
= (hflags
>> HFLAGS_LE
) & 1;
8543 ctx
->default_tcg_memop_mask
= ctx
->le_mode
? MO_LE
: MO_BE
;
8544 ctx
->flags
= env
->flags
;
8545 #if defined(TARGET_PPC64)
8546 ctx
->sf_mode
= (hflags
>> HFLAGS_64
) & 1;
8547 ctx
->has_cfar
= !!(env
->flags
& POWERPC_FLAG_CFAR
);
8549 ctx
->lazy_tlb_flush
= env
->mmu_model
== POWERPC_MMU_32B
8550 || env
->mmu_model
== POWERPC_MMU_601
8551 || env
->mmu_model
& POWERPC_MMU_64
;
8553 ctx
->fpu_enabled
= (hflags
>> HFLAGS_FP
) & 1;
8554 ctx
->spe_enabled
= (hflags
>> HFLAGS_SPE
) & 1;
8555 ctx
->altivec_enabled
= (hflags
>> HFLAGS_VR
) & 1;
8556 ctx
->vsx_enabled
= (hflags
>> HFLAGS_VSX
) & 1;
8557 ctx
->tm_enabled
= (hflags
>> HFLAGS_TM
) & 1;
8558 ctx
->gtse
= (hflags
>> HFLAGS_GTSE
) & 1;
8559 ctx
->hr
= (hflags
>> HFLAGS_HR
) & 1;
8561 ctx
->singlestep_enabled
= 0;
8562 if ((hflags
>> HFLAGS_SE
) & 1) {
8563 ctx
->singlestep_enabled
|= CPU_SINGLE_STEP
;
8565 if ((hflags
>> HFLAGS_BE
) & 1) {
8566 ctx
->singlestep_enabled
|= CPU_BRANCH_STEP
;
8568 if (unlikely(ctx
->base
.singlestep_enabled
)) {
8569 ctx
->singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
8572 if (ctx
->singlestep_enabled
& (CPU_SINGLE_STEP
| GDBSTUB_SINGLE_STEP
)) {
8573 ctx
->base
.max_insns
= 1;
8577 static void ppc_tr_tb_start(DisasContextBase
*db
, CPUState
*cs
)
8581 static void ppc_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cs
)
8583 tcg_gen_insn_start(dcbase
->pc_next
);
8586 static bool is_prefix_insn(DisasContext
*ctx
, uint32_t insn
)
8588 REQUIRE_INSNS_FLAGS2(ctx
, ISA310
);
8589 return opc1(insn
) == 1;
8592 static void ppc_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cs
)
8594 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
8595 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
8596 CPUPPCState
*env
= cs
->env_ptr
;
8601 LOG_DISAS("----------------\n");
8602 LOG_DISAS("nip=" TARGET_FMT_lx
" super=%d ir=%d\n",
8603 ctx
->base
.pc_next
, ctx
->mem_idx
, (int)msr_ir
);
8605 ctx
->cia
= pc
= ctx
->base
.pc_next
;
8606 insn
= translator_ldl_swap(env
, dcbase
, pc
, need_byteswap(ctx
));
8607 ctx
->base
.pc_next
= pc
+= 4;
8609 if (!is_prefix_insn(ctx
, insn
)) {
8610 ok
= (decode_insn32(ctx
, insn
) ||
8611 decode_legacy(cpu
, ctx
, insn
));
8612 } else if ((pc
& 63) == 0) {
8614 * Power v3.1, section 1.9 Exceptions:
8615 * attempt to execute a prefixed instruction that crosses a
8616 * 64-byte address boundary (system alignment error).
8618 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
, POWERPC_EXCP_ALIGN_INSN
);
8621 uint32_t insn2
= translator_ldl_swap(env
, dcbase
, pc
,
8622 need_byteswap(ctx
));
8623 ctx
->base
.pc_next
= pc
+= 4;
8624 ok
= decode_insn64(ctx
, deposit64(insn2
, 32, 32, insn
));
8630 /* End the TB when crossing a page boundary. */
8631 if (ctx
->base
.is_jmp
== DISAS_NEXT
&& !(pc
& ~TARGET_PAGE_MASK
)) {
8632 ctx
->base
.is_jmp
= DISAS_TOO_MANY
;
8635 translator_loop_temp_check(&ctx
->base
);
8638 static void ppc_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cs
)
8640 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
8641 DisasJumpType is_jmp
= ctx
->base
.is_jmp
;
8642 target_ulong nip
= ctx
->base
.pc_next
;
8645 if (is_jmp
== DISAS_NORETURN
) {
8646 /* We have already exited the TB. */
8650 /* Honor single stepping. */
8651 sse
= ctx
->singlestep_enabled
& (CPU_SINGLE_STEP
| GDBSTUB_SINGLE_STEP
);
8652 if (unlikely(sse
)) {
8654 case DISAS_TOO_MANY
:
8655 case DISAS_EXIT_UPDATE
:
8656 case DISAS_CHAIN_UPDATE
:
8657 gen_update_nip(ctx
, nip
);
8663 g_assert_not_reached();
8666 if (sse
& GDBSTUB_SINGLE_STEP
) {
8667 gen_debug_exception(ctx
);
8670 /* else CPU_SINGLE_STEP... */
8671 if (nip
<= 0x100 || nip
> 0xf00) {
8672 gen_helper_raise_exception(cpu_env
, tcg_constant_i32(gen_prep_dbgex(ctx
)));
8678 case DISAS_TOO_MANY
:
8679 if (use_goto_tb(ctx
, nip
)) {
8681 gen_update_nip(ctx
, nip
);
8682 tcg_gen_exit_tb(ctx
->base
.tb
, 0);
8686 case DISAS_CHAIN_UPDATE
:
8687 gen_update_nip(ctx
, nip
);
8690 tcg_gen_lookup_and_goto_ptr();
8693 case DISAS_EXIT_UPDATE
:
8694 gen_update_nip(ctx
, nip
);
8697 tcg_gen_exit_tb(NULL
, 0);
8701 g_assert_not_reached();
8705 static void ppc_tr_disas_log(const DisasContextBase
*dcbase
, CPUState
*cs
)
8707 qemu_log("IN: %s\n", lookup_symbol(dcbase
->pc_first
));
8708 log_target_disas(cs
, dcbase
->pc_first
, dcbase
->tb
->size
);
8711 static const TranslatorOps ppc_tr_ops
= {
8712 .init_disas_context
= ppc_tr_init_disas_context
,
8713 .tb_start
= ppc_tr_tb_start
,
8714 .insn_start
= ppc_tr_insn_start
,
8715 .translate_insn
= ppc_tr_translate_insn
,
8716 .tb_stop
= ppc_tr_tb_stop
,
8717 .disas_log
= ppc_tr_disas_log
,
8720 void gen_intermediate_code(CPUState
*cs
, TranslationBlock
*tb
, int max_insns
)
8724 translator_loop(&ppc_tr_ops
, &ctx
.base
, cs
, tb
, max_insns
);
8727 void restore_state_to_opc(CPUPPCState
*env
, TranslationBlock
*tb
,