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 "trace-tcg.h"
36 #include "exec/translator.h"
38 #include "qemu/atomic128.h"
41 #include "qemu/qemu-print.h"
42 #include "qapi/error.h"
44 #define CPU_SINGLE_STEP 0x1
45 #define CPU_BRANCH_STEP 0x2
46 #define GDBSTUB_SINGLE_STEP 0x4
48 /* Include definitions for instructions classes and implementations flags */
49 /* #define PPC_DEBUG_DISAS */
50 /* #define DO_PPC_STATISTICS */
52 #ifdef PPC_DEBUG_DISAS
53 # define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__)
55 # define LOG_DISAS(...) do { } while (0)
57 /*****************************************************************************/
58 /* Code translation helpers */
60 /* global register indexes */
61 static char cpu_reg_names
[10 * 3 + 22 * 4 /* GPR */
62 + 10 * 4 + 22 * 5 /* SPE GPRh */
64 static TCGv cpu_gpr
[32];
65 static TCGv cpu_gprh
[32];
66 static TCGv_i32 cpu_crf
[8];
71 #if defined(TARGET_PPC64)
74 static TCGv cpu_xer
, cpu_so
, cpu_ov
, cpu_ca
, cpu_ov32
, cpu_ca32
;
75 static TCGv cpu_reserve
;
76 static TCGv cpu_reserve_val
;
77 static TCGv cpu_fpscr
;
78 static TCGv_i32 cpu_access_type
;
80 #include "exec/gen-icount.h"
82 void ppc_translate_init(void)
86 size_t cpu_reg_names_size
;
89 cpu_reg_names_size
= sizeof(cpu_reg_names
);
91 for (i
= 0; i
< 8; i
++) {
92 snprintf(p
, cpu_reg_names_size
, "crf%d", i
);
93 cpu_crf
[i
] = tcg_global_mem_new_i32(cpu_env
,
94 offsetof(CPUPPCState
, crf
[i
]), p
);
96 cpu_reg_names_size
-= 5;
99 for (i
= 0; i
< 32; i
++) {
100 snprintf(p
, cpu_reg_names_size
, "r%d", i
);
101 cpu_gpr
[i
] = tcg_global_mem_new(cpu_env
,
102 offsetof(CPUPPCState
, gpr
[i
]), p
);
103 p
+= (i
< 10) ? 3 : 4;
104 cpu_reg_names_size
-= (i
< 10) ? 3 : 4;
105 snprintf(p
, cpu_reg_names_size
, "r%dH", i
);
106 cpu_gprh
[i
] = tcg_global_mem_new(cpu_env
,
107 offsetof(CPUPPCState
, gprh
[i
]), p
);
108 p
+= (i
< 10) ? 4 : 5;
109 cpu_reg_names_size
-= (i
< 10) ? 4 : 5;
112 cpu_nip
= tcg_global_mem_new(cpu_env
,
113 offsetof(CPUPPCState
, nip
), "nip");
115 cpu_msr
= tcg_global_mem_new(cpu_env
,
116 offsetof(CPUPPCState
, msr
), "msr");
118 cpu_ctr
= tcg_global_mem_new(cpu_env
,
119 offsetof(CPUPPCState
, ctr
), "ctr");
121 cpu_lr
= tcg_global_mem_new(cpu_env
,
122 offsetof(CPUPPCState
, lr
), "lr");
124 #if defined(TARGET_PPC64)
125 cpu_cfar
= tcg_global_mem_new(cpu_env
,
126 offsetof(CPUPPCState
, cfar
), "cfar");
129 cpu_xer
= tcg_global_mem_new(cpu_env
,
130 offsetof(CPUPPCState
, xer
), "xer");
131 cpu_so
= tcg_global_mem_new(cpu_env
,
132 offsetof(CPUPPCState
, so
), "SO");
133 cpu_ov
= tcg_global_mem_new(cpu_env
,
134 offsetof(CPUPPCState
, ov
), "OV");
135 cpu_ca
= tcg_global_mem_new(cpu_env
,
136 offsetof(CPUPPCState
, ca
), "CA");
137 cpu_ov32
= tcg_global_mem_new(cpu_env
,
138 offsetof(CPUPPCState
, ov32
), "OV32");
139 cpu_ca32
= tcg_global_mem_new(cpu_env
,
140 offsetof(CPUPPCState
, ca32
), "CA32");
142 cpu_reserve
= tcg_global_mem_new(cpu_env
,
143 offsetof(CPUPPCState
, reserve_addr
),
145 cpu_reserve_val
= tcg_global_mem_new(cpu_env
,
146 offsetof(CPUPPCState
, reserve_val
),
149 cpu_fpscr
= tcg_global_mem_new(cpu_env
,
150 offsetof(CPUPPCState
, fpscr
), "fpscr");
152 cpu_access_type
= tcg_global_mem_new_i32(cpu_env
,
153 offsetof(CPUPPCState
, access_type
),
157 /* internal defines */
158 struct DisasContext
{
159 DisasContextBase base
;
160 target_ulong cia
; /* current instruction address */
162 /* Routine used to access memory */
163 bool pr
, hv
, dr
, le_mode
;
165 bool need_access_type
;
168 /* Translation flags */
169 MemOp default_tcg_memop_mask
;
170 #if defined(TARGET_PPC64)
175 bool altivec_enabled
;
180 ppc_spr_t
*spr_cb
; /* Needed to check rights for mfspr/mtspr */
181 int singlestep_enabled
;
183 uint64_t insns_flags
;
184 uint64_t insns_flags2
;
187 #define DISAS_EXIT DISAS_TARGET_0 /* exit to main loop, pc updated */
188 #define DISAS_EXIT_UPDATE DISAS_TARGET_1 /* exit to main loop, pc stale */
189 #define DISAS_CHAIN DISAS_TARGET_2 /* lookup next tb, pc updated */
190 #define DISAS_CHAIN_UPDATE DISAS_TARGET_3 /* lookup next tb, pc stale */
192 /* Return true iff byteswap is needed in a scalar memop */
193 static inline bool need_byteswap(const DisasContext
*ctx
)
195 #if defined(TARGET_WORDS_BIGENDIAN)
198 return !ctx
->le_mode
;
202 /* True when active word size < size of target_long. */
204 # define NARROW_MODE(C) (!(C)->sf_mode)
206 # define NARROW_MODE(C) 0
209 struct opc_handler_t
{
210 /* invalid bits for instruction 1 (Rc(opcode) == 0) */
212 /* invalid bits for instruction 2 (Rc(opcode) == 1) */
214 /* instruction type */
216 /* extended instruction type */
219 void (*handler
)(DisasContext
*ctx
);
220 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
223 #if defined(DO_PPC_STATISTICS)
228 /* SPR load/store helpers */
229 static inline void gen_load_spr(TCGv t
, int reg
)
231 tcg_gen_ld_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
234 static inline void gen_store_spr(int reg
, TCGv t
)
236 tcg_gen_st_tl(t
, cpu_env
, offsetof(CPUPPCState
, spr
[reg
]));
239 static inline void gen_set_access_type(DisasContext
*ctx
, int access_type
)
241 if (ctx
->need_access_type
&& ctx
->access_type
!= access_type
) {
242 tcg_gen_movi_i32(cpu_access_type
, access_type
);
243 ctx
->access_type
= access_type
;
247 static inline void gen_update_nip(DisasContext
*ctx
, target_ulong nip
)
249 if (NARROW_MODE(ctx
)) {
252 tcg_gen_movi_tl(cpu_nip
, nip
);
255 static void gen_exception_err(DisasContext
*ctx
, uint32_t excp
, uint32_t error
)
260 * These are all synchronous exceptions, we set the PC back to the
261 * faulting instruction
263 gen_update_nip(ctx
, ctx
->cia
);
264 t0
= tcg_const_i32(excp
);
265 t1
= tcg_const_i32(error
);
266 gen_helper_raise_exception_err(cpu_env
, t0
, t1
);
267 tcg_temp_free_i32(t0
);
268 tcg_temp_free_i32(t1
);
269 ctx
->base
.is_jmp
= DISAS_NORETURN
;
272 static void gen_exception(DisasContext
*ctx
, uint32_t excp
)
277 * These are all synchronous exceptions, we set the PC back to the
278 * faulting instruction
280 gen_update_nip(ctx
, ctx
->cia
);
281 t0
= tcg_const_i32(excp
);
282 gen_helper_raise_exception(cpu_env
, t0
);
283 tcg_temp_free_i32(t0
);
284 ctx
->base
.is_jmp
= DISAS_NORETURN
;
287 static void gen_exception_nip(DisasContext
*ctx
, uint32_t excp
,
292 gen_update_nip(ctx
, nip
);
293 t0
= tcg_const_i32(excp
);
294 gen_helper_raise_exception(cpu_env
, t0
);
295 tcg_temp_free_i32(t0
);
296 ctx
->base
.is_jmp
= DISAS_NORETURN
;
299 static void gen_icount_io_start(DisasContext
*ctx
)
301 if (tb_cflags(ctx
->base
.tb
) & CF_USE_ICOUNT
) {
304 * An I/O instruction must be last in the TB.
305 * Chain to the next TB, and let the code from gen_tb_start
306 * decide if we need to return to the main loop.
307 * Doing this first also allows this value to be overridden.
309 ctx
->base
.is_jmp
= DISAS_TOO_MANY
;
314 * Tells the caller what is the appropriate exception to generate and prepares
315 * SPR registers for this exception.
317 * The exception can be either POWERPC_EXCP_TRACE (on most PowerPCs) or
318 * POWERPC_EXCP_DEBUG (on BookE).
320 static uint32_t gen_prep_dbgex(DisasContext
*ctx
)
322 if (ctx
->flags
& POWERPC_FLAG_DE
) {
323 target_ulong dbsr
= 0;
324 if (ctx
->singlestep_enabled
& CPU_SINGLE_STEP
) {
327 /* Must have been branch */
330 TCGv t0
= tcg_temp_new();
331 gen_load_spr(t0
, SPR_BOOKE_DBSR
);
332 tcg_gen_ori_tl(t0
, t0
, dbsr
);
333 gen_store_spr(SPR_BOOKE_DBSR
, t0
);
335 return POWERPC_EXCP_DEBUG
;
337 return POWERPC_EXCP_TRACE
;
341 static void gen_debug_exception(DisasContext
*ctx
)
343 gen_helper_raise_exception(cpu_env
, tcg_constant_i32(EXCP_DEBUG
));
344 ctx
->base
.is_jmp
= DISAS_NORETURN
;
347 static inline void gen_inval_exception(DisasContext
*ctx
, uint32_t error
)
349 /* Will be converted to program check if needed */
350 gen_exception_err(ctx
, POWERPC_EXCP_HV_EMU
, POWERPC_EXCP_INVAL
| error
);
353 static inline void gen_priv_exception(DisasContext
*ctx
, uint32_t error
)
355 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_PRIV
| error
);
358 static inline void gen_hvpriv_exception(DisasContext
*ctx
, uint32_t error
)
360 /* Will be converted to program check if needed */
361 gen_exception_err(ctx
, POWERPC_EXCP_HV_EMU
, POWERPC_EXCP_PRIV
| error
);
364 /*****************************************************************************/
365 /* SPR READ/WRITE CALLBACKS */
367 void spr_noaccess(DisasContext
*ctx
, int gprn
, int sprn
)
370 sprn
= ((sprn
>> 5) & 0x1F) | ((sprn
& 0x1F) << 5);
371 printf("ERROR: try to access SPR %d !\n", sprn
);
375 /* #define PPC_DUMP_SPR_ACCESSES */
379 * do nothing but store/retrieve spr value
381 static void spr_load_dump_spr(int sprn
)
383 #ifdef PPC_DUMP_SPR_ACCESSES
384 TCGv_i32 t0
= tcg_const_i32(sprn
);
385 gen_helper_load_dump_spr(cpu_env
, t0
);
386 tcg_temp_free_i32(t0
);
390 void spr_read_generic(DisasContext
*ctx
, int gprn
, int sprn
)
392 gen_load_spr(cpu_gpr
[gprn
], sprn
);
393 spr_load_dump_spr(sprn
);
396 static void spr_store_dump_spr(int sprn
)
398 #ifdef PPC_DUMP_SPR_ACCESSES
399 TCGv_i32 t0
= tcg_const_i32(sprn
);
400 gen_helper_store_dump_spr(cpu_env
, t0
);
401 tcg_temp_free_i32(t0
);
405 void spr_write_generic(DisasContext
*ctx
, int sprn
, int gprn
)
407 gen_store_spr(sprn
, cpu_gpr
[gprn
]);
408 spr_store_dump_spr(sprn
);
411 #if !defined(CONFIG_USER_ONLY)
412 void spr_write_generic32(DisasContext
*ctx
, int sprn
, int gprn
)
415 TCGv t0
= tcg_temp_new();
416 tcg_gen_ext32u_tl(t0
, cpu_gpr
[gprn
]);
417 gen_store_spr(sprn
, t0
);
419 spr_store_dump_spr(sprn
);
421 spr_write_generic(ctx
, sprn
, gprn
);
425 void spr_write_clear(DisasContext
*ctx
, int sprn
, int gprn
)
427 TCGv t0
= tcg_temp_new();
428 TCGv t1
= tcg_temp_new();
429 gen_load_spr(t0
, sprn
);
430 tcg_gen_neg_tl(t1
, cpu_gpr
[gprn
]);
431 tcg_gen_and_tl(t0
, t0
, t1
);
432 gen_store_spr(sprn
, t0
);
437 void spr_access_nop(DisasContext
*ctx
, int sprn
, int gprn
)
443 /* SPR common to all PowerPC */
445 void spr_read_xer(DisasContext
*ctx
, int gprn
, int sprn
)
447 TCGv dst
= cpu_gpr
[gprn
];
448 TCGv t0
= tcg_temp_new();
449 TCGv t1
= tcg_temp_new();
450 TCGv t2
= tcg_temp_new();
451 tcg_gen_mov_tl(dst
, cpu_xer
);
452 tcg_gen_shli_tl(t0
, cpu_so
, XER_SO
);
453 tcg_gen_shli_tl(t1
, cpu_ov
, XER_OV
);
454 tcg_gen_shli_tl(t2
, cpu_ca
, XER_CA
);
455 tcg_gen_or_tl(t0
, t0
, t1
);
456 tcg_gen_or_tl(dst
, dst
, t2
);
457 tcg_gen_or_tl(dst
, dst
, t0
);
458 if (is_isa300(ctx
)) {
459 tcg_gen_shli_tl(t0
, cpu_ov32
, XER_OV32
);
460 tcg_gen_or_tl(dst
, dst
, t0
);
461 tcg_gen_shli_tl(t0
, cpu_ca32
, XER_CA32
);
462 tcg_gen_or_tl(dst
, dst
, t0
);
469 void spr_write_xer(DisasContext
*ctx
, int sprn
, int gprn
)
471 TCGv src
= cpu_gpr
[gprn
];
472 /* Write all flags, while reading back check for isa300 */
473 tcg_gen_andi_tl(cpu_xer
, src
,
475 (1u << XER_OV
) | (1u << XER_OV32
) |
476 (1u << XER_CA
) | (1u << XER_CA32
)));
477 tcg_gen_extract_tl(cpu_ov32
, src
, XER_OV32
, 1);
478 tcg_gen_extract_tl(cpu_ca32
, src
, XER_CA32
, 1);
479 tcg_gen_extract_tl(cpu_so
, src
, XER_SO
, 1);
480 tcg_gen_extract_tl(cpu_ov
, src
, XER_OV
, 1);
481 tcg_gen_extract_tl(cpu_ca
, src
, XER_CA
, 1);
485 void spr_read_lr(DisasContext
*ctx
, int gprn
, int sprn
)
487 tcg_gen_mov_tl(cpu_gpr
[gprn
], cpu_lr
);
490 void spr_write_lr(DisasContext
*ctx
, int sprn
, int gprn
)
492 tcg_gen_mov_tl(cpu_lr
, cpu_gpr
[gprn
]);
496 #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY)
497 void spr_read_cfar(DisasContext
*ctx
, int gprn
, int sprn
)
499 tcg_gen_mov_tl(cpu_gpr
[gprn
], cpu_cfar
);
502 void spr_write_cfar(DisasContext
*ctx
, int sprn
, int gprn
)
504 tcg_gen_mov_tl(cpu_cfar
, cpu_gpr
[gprn
]);
506 #endif /* defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY) */
509 void spr_read_ctr(DisasContext
*ctx
, int gprn
, int sprn
)
511 tcg_gen_mov_tl(cpu_gpr
[gprn
], cpu_ctr
);
514 void spr_write_ctr(DisasContext
*ctx
, int sprn
, int gprn
)
516 tcg_gen_mov_tl(cpu_ctr
, cpu_gpr
[gprn
]);
519 /* User read access to SPR */
525 void spr_read_ureg(DisasContext
*ctx
, int gprn
, int sprn
)
527 gen_load_spr(cpu_gpr
[gprn
], sprn
+ 0x10);
530 #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY)
531 void spr_write_ureg(DisasContext
*ctx
, int sprn
, int gprn
)
533 gen_store_spr(sprn
+ 0x10, cpu_gpr
[gprn
]);
537 /* SPR common to all non-embedded PowerPC */
539 #if !defined(CONFIG_USER_ONLY)
540 void spr_read_decr(DisasContext
*ctx
, int gprn
, int sprn
)
542 gen_icount_io_start(ctx
);
543 gen_helper_load_decr(cpu_gpr
[gprn
], cpu_env
);
546 void spr_write_decr(DisasContext
*ctx
, int sprn
, int gprn
)
548 gen_icount_io_start(ctx
);
549 gen_helper_store_decr(cpu_env
, cpu_gpr
[gprn
]);
553 /* SPR common to all non-embedded PowerPC, except 601 */
555 void spr_read_tbl(DisasContext
*ctx
, int gprn
, int sprn
)
557 gen_icount_io_start(ctx
);
558 gen_helper_load_tbl(cpu_gpr
[gprn
], cpu_env
);
561 void spr_read_tbu(DisasContext
*ctx
, int gprn
, int sprn
)
563 gen_icount_io_start(ctx
);
564 gen_helper_load_tbu(cpu_gpr
[gprn
], cpu_env
);
567 void spr_read_atbl(DisasContext
*ctx
, int gprn
, int sprn
)
569 gen_helper_load_atbl(cpu_gpr
[gprn
], cpu_env
);
572 void spr_read_atbu(DisasContext
*ctx
, int gprn
, int sprn
)
574 gen_helper_load_atbu(cpu_gpr
[gprn
], cpu_env
);
577 #if !defined(CONFIG_USER_ONLY)
578 void spr_write_tbl(DisasContext
*ctx
, int sprn
, int gprn
)
580 gen_icount_io_start(ctx
);
581 gen_helper_store_tbl(cpu_env
, cpu_gpr
[gprn
]);
584 void spr_write_tbu(DisasContext
*ctx
, int sprn
, int gprn
)
586 gen_icount_io_start(ctx
);
587 gen_helper_store_tbu(cpu_env
, cpu_gpr
[gprn
]);
590 void spr_write_atbl(DisasContext
*ctx
, int sprn
, int gprn
)
592 gen_helper_store_atbl(cpu_env
, cpu_gpr
[gprn
]);
595 void spr_write_atbu(DisasContext
*ctx
, int sprn
, int gprn
)
597 gen_helper_store_atbu(cpu_env
, cpu_gpr
[gprn
]);
600 #if defined(TARGET_PPC64)
601 void spr_read_purr(DisasContext
*ctx
, int gprn
, int sprn
)
603 gen_icount_io_start(ctx
);
604 gen_helper_load_purr(cpu_gpr
[gprn
], cpu_env
);
607 void spr_write_purr(DisasContext
*ctx
, int sprn
, int gprn
)
609 gen_icount_io_start(ctx
);
610 gen_helper_store_purr(cpu_env
, cpu_gpr
[gprn
]);
614 void spr_read_hdecr(DisasContext
*ctx
, int gprn
, int sprn
)
616 gen_icount_io_start(ctx
);
617 gen_helper_load_hdecr(cpu_gpr
[gprn
], cpu_env
);
620 void spr_write_hdecr(DisasContext
*ctx
, int sprn
, int gprn
)
622 gen_icount_io_start(ctx
);
623 gen_helper_store_hdecr(cpu_env
, cpu_gpr
[gprn
]);
626 void spr_read_vtb(DisasContext
*ctx
, int gprn
, int sprn
)
628 gen_icount_io_start(ctx
);
629 gen_helper_load_vtb(cpu_gpr
[gprn
], cpu_env
);
632 void spr_write_vtb(DisasContext
*ctx
, int sprn
, int gprn
)
634 gen_icount_io_start(ctx
);
635 gen_helper_store_vtb(cpu_env
, cpu_gpr
[gprn
]);
638 void spr_write_tbu40(DisasContext
*ctx
, int sprn
, int gprn
)
640 gen_icount_io_start(ctx
);
641 gen_helper_store_tbu40(cpu_env
, cpu_gpr
[gprn
]);
647 #if !defined(CONFIG_USER_ONLY)
648 /* IBAT0U...IBAT0U */
649 /* IBAT0L...IBAT7L */
650 void spr_read_ibat(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_IBAT0U
) / 2]));
657 void spr_read_ibat_h(DisasContext
*ctx
, int gprn
, int sprn
)
659 tcg_gen_ld_tl(cpu_gpr
[gprn
], cpu_env
,
660 offsetof(CPUPPCState
,
661 IBAT
[sprn
& 1][((sprn
- SPR_IBAT4U
) / 2) + 4]));
664 void spr_write_ibatu(DisasContext
*ctx
, int sprn
, int gprn
)
666 TCGv_i32 t0
= tcg_const_i32((sprn
- SPR_IBAT0U
) / 2);
667 gen_helper_store_ibatu(cpu_env
, t0
, cpu_gpr
[gprn
]);
668 tcg_temp_free_i32(t0
);
671 void spr_write_ibatu_h(DisasContext
*ctx
, int sprn
, int gprn
)
673 TCGv_i32 t0
= tcg_const_i32(((sprn
- SPR_IBAT4U
) / 2) + 4);
674 gen_helper_store_ibatu(cpu_env
, t0
, cpu_gpr
[gprn
]);
675 tcg_temp_free_i32(t0
);
678 void spr_write_ibatl(DisasContext
*ctx
, int sprn
, int gprn
)
680 TCGv_i32 t0
= tcg_const_i32((sprn
- SPR_IBAT0L
) / 2);
681 gen_helper_store_ibatl(cpu_env
, t0
, cpu_gpr
[gprn
]);
682 tcg_temp_free_i32(t0
);
685 void spr_write_ibatl_h(DisasContext
*ctx
, int sprn
, int gprn
)
687 TCGv_i32 t0
= tcg_const_i32(((sprn
- SPR_IBAT4L
) / 2) + 4);
688 gen_helper_store_ibatl(cpu_env
, t0
, cpu_gpr
[gprn
]);
689 tcg_temp_free_i32(t0
);
692 /* DBAT0U...DBAT7U */
693 /* DBAT0L...DBAT7L */
694 void spr_read_dbat(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_DBAT0U
) / 2]));
701 void spr_read_dbat_h(DisasContext
*ctx
, int gprn
, int sprn
)
703 tcg_gen_ld_tl(cpu_gpr
[gprn
], cpu_env
,
704 offsetof(CPUPPCState
,
705 DBAT
[sprn
& 1][((sprn
- SPR_DBAT4U
) / 2) + 4]));
708 void spr_write_dbatu(DisasContext
*ctx
, int sprn
, int gprn
)
710 TCGv_i32 t0
= tcg_const_i32((sprn
- SPR_DBAT0U
) / 2);
711 gen_helper_store_dbatu(cpu_env
, t0
, cpu_gpr
[gprn
]);
712 tcg_temp_free_i32(t0
);
715 void spr_write_dbatu_h(DisasContext
*ctx
, int sprn
, int gprn
)
717 TCGv_i32 t0
= tcg_const_i32(((sprn
- SPR_DBAT4U
) / 2) + 4);
718 gen_helper_store_dbatu(cpu_env
, t0
, cpu_gpr
[gprn
]);
719 tcg_temp_free_i32(t0
);
722 void spr_write_dbatl(DisasContext
*ctx
, int sprn
, int gprn
)
724 TCGv_i32 t0
= tcg_const_i32((sprn
- SPR_DBAT0L
) / 2);
725 gen_helper_store_dbatl(cpu_env
, t0
, cpu_gpr
[gprn
]);
726 tcg_temp_free_i32(t0
);
729 void spr_write_dbatl_h(DisasContext
*ctx
, int sprn
, int gprn
)
731 TCGv_i32 t0
= tcg_const_i32(((sprn
- SPR_DBAT4L
) / 2) + 4);
732 gen_helper_store_dbatl(cpu_env
, t0
, cpu_gpr
[gprn
]);
733 tcg_temp_free_i32(t0
);
737 void spr_write_sdr1(DisasContext
*ctx
, int sprn
, int gprn
)
739 gen_helper_store_sdr1(cpu_env
, cpu_gpr
[gprn
]);
742 #if defined(TARGET_PPC64)
743 /* 64 bits PowerPC specific SPRs */
745 void spr_write_pidr(DisasContext
*ctx
, int sprn
, int gprn
)
747 gen_helper_store_pidr(cpu_env
, cpu_gpr
[gprn
]);
750 void spr_write_lpidr(DisasContext
*ctx
, int sprn
, int gprn
)
752 gen_helper_store_lpidr(cpu_env
, cpu_gpr
[gprn
]);
755 void spr_read_hior(DisasContext
*ctx
, int gprn
, int sprn
)
757 tcg_gen_ld_tl(cpu_gpr
[gprn
], cpu_env
, offsetof(CPUPPCState
, excp_prefix
));
760 void spr_write_hior(DisasContext
*ctx
, int sprn
, int gprn
)
762 TCGv t0
= tcg_temp_new();
763 tcg_gen_andi_tl(t0
, cpu_gpr
[gprn
], 0x3FFFFF00000ULL
);
764 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, excp_prefix
));
767 void spr_write_ptcr(DisasContext
*ctx
, int sprn
, int gprn
)
769 gen_helper_store_ptcr(cpu_env
, cpu_gpr
[gprn
]);
772 void spr_write_pcr(DisasContext
*ctx
, int sprn
, int gprn
)
774 gen_helper_store_pcr(cpu_env
, cpu_gpr
[gprn
]);
778 void spr_read_dpdes(DisasContext
*ctx
, int gprn
, int sprn
)
780 gen_helper_load_dpdes(cpu_gpr
[gprn
], cpu_env
);
783 void spr_write_dpdes(DisasContext
*ctx
, int sprn
, int gprn
)
785 gen_helper_store_dpdes(cpu_env
, cpu_gpr
[gprn
]);
790 /* PowerPC 601 specific registers */
792 void spr_read_601_rtcl(DisasContext
*ctx
, int gprn
, int sprn
)
794 gen_helper_load_601_rtcl(cpu_gpr
[gprn
], cpu_env
);
797 void spr_read_601_rtcu(DisasContext
*ctx
, int gprn
, int sprn
)
799 gen_helper_load_601_rtcu(cpu_gpr
[gprn
], cpu_env
);
802 #if !defined(CONFIG_USER_ONLY)
803 void spr_write_601_rtcu(DisasContext
*ctx
, int sprn
, int gprn
)
805 gen_helper_store_601_rtcu(cpu_env
, cpu_gpr
[gprn
]);
808 void spr_write_601_rtcl(DisasContext
*ctx
, int sprn
, int gprn
)
810 gen_helper_store_601_rtcl(cpu_env
, cpu_gpr
[gprn
]);
813 void spr_write_hid0_601(DisasContext
*ctx
, int sprn
, int gprn
)
815 gen_helper_store_hid0_601(cpu_env
, cpu_gpr
[gprn
]);
816 /* Must stop the translation as endianness may have changed */
817 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
822 #if !defined(CONFIG_USER_ONLY)
823 void spr_read_601_ubat(DisasContext
*ctx
, int gprn
, int sprn
)
825 tcg_gen_ld_tl(cpu_gpr
[gprn
], cpu_env
,
826 offsetof(CPUPPCState
,
827 IBAT
[sprn
& 1][(sprn
- SPR_IBAT0U
) / 2]));
830 void spr_write_601_ubatu(DisasContext
*ctx
, int sprn
, int gprn
)
832 TCGv_i32 t0
= tcg_const_i32((sprn
- SPR_IBAT0U
) / 2);
833 gen_helper_store_601_batl(cpu_env
, t0
, cpu_gpr
[gprn
]);
834 tcg_temp_free_i32(t0
);
837 void spr_write_601_ubatl(DisasContext
*ctx
, int sprn
, int gprn
)
839 TCGv_i32 t0
= tcg_const_i32((sprn
- SPR_IBAT0U
) / 2);
840 gen_helper_store_601_batu(cpu_env
, t0
, cpu_gpr
[gprn
]);
841 tcg_temp_free_i32(t0
);
845 /* PowerPC 40x specific registers */
846 #if !defined(CONFIG_USER_ONLY)
847 void spr_read_40x_pit(DisasContext
*ctx
, int gprn
, int sprn
)
849 gen_icount_io_start(ctx
);
850 gen_helper_load_40x_pit(cpu_gpr
[gprn
], cpu_env
);
853 void spr_write_40x_pit(DisasContext
*ctx
, int sprn
, int gprn
)
855 gen_icount_io_start(ctx
);
856 gen_helper_store_40x_pit(cpu_env
, cpu_gpr
[gprn
]);
859 void spr_write_40x_dbcr0(DisasContext
*ctx
, int sprn
, int gprn
)
861 gen_icount_io_start(ctx
);
862 gen_store_spr(sprn
, cpu_gpr
[gprn
]);
863 gen_helper_store_40x_dbcr0(cpu_env
, cpu_gpr
[gprn
]);
864 /* We must stop translation as we may have rebooted */
865 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
868 void spr_write_40x_sler(DisasContext
*ctx
, int sprn
, int gprn
)
870 gen_icount_io_start(ctx
);
871 gen_helper_store_40x_sler(cpu_env
, cpu_gpr
[gprn
]);
874 void spr_write_booke_tcr(DisasContext
*ctx
, int sprn
, int gprn
)
876 gen_icount_io_start(ctx
);
877 gen_helper_store_booke_tcr(cpu_env
, cpu_gpr
[gprn
]);
880 void spr_write_booke_tsr(DisasContext
*ctx
, int sprn
, int gprn
)
882 gen_icount_io_start(ctx
);
883 gen_helper_store_booke_tsr(cpu_env
, cpu_gpr
[gprn
]);
887 /* PowerPC 403 specific registers */
888 /* PBL1 / PBU1 / PBL2 / PBU2 */
889 #if !defined(CONFIG_USER_ONLY)
890 void spr_read_403_pbr(DisasContext
*ctx
, int gprn
, int sprn
)
892 tcg_gen_ld_tl(cpu_gpr
[gprn
], cpu_env
,
893 offsetof(CPUPPCState
, pb
[sprn
- SPR_403_PBL1
]));
896 void spr_write_403_pbr(DisasContext
*ctx
, int sprn
, int gprn
)
898 TCGv_i32 t0
= tcg_const_i32(sprn
- SPR_403_PBL1
);
899 gen_helper_store_403_pbr(cpu_env
, t0
, cpu_gpr
[gprn
]);
900 tcg_temp_free_i32(t0
);
903 void spr_write_pir(DisasContext
*ctx
, int sprn
, int gprn
)
905 TCGv t0
= tcg_temp_new();
906 tcg_gen_andi_tl(t0
, cpu_gpr
[gprn
], 0xF);
907 gen_store_spr(SPR_PIR
, t0
);
912 /* SPE specific registers */
913 void spr_read_spefscr(DisasContext
*ctx
, int gprn
, int sprn
)
915 TCGv_i32 t0
= tcg_temp_new_i32();
916 tcg_gen_ld_i32(t0
, cpu_env
, offsetof(CPUPPCState
, spe_fscr
));
917 tcg_gen_extu_i32_tl(cpu_gpr
[gprn
], t0
);
918 tcg_temp_free_i32(t0
);
921 void spr_write_spefscr(DisasContext
*ctx
, int sprn
, int gprn
)
923 TCGv_i32 t0
= tcg_temp_new_i32();
924 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[gprn
]);
925 tcg_gen_st_i32(t0
, cpu_env
, offsetof(CPUPPCState
, spe_fscr
));
926 tcg_temp_free_i32(t0
);
929 #if !defined(CONFIG_USER_ONLY)
930 /* Callback used to write the exception vector base */
931 void spr_write_excp_prefix(DisasContext
*ctx
, int sprn
, int gprn
)
933 TCGv t0
= tcg_temp_new();
934 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUPPCState
, ivpr_mask
));
935 tcg_gen_and_tl(t0
, t0
, cpu_gpr
[gprn
]);
936 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, excp_prefix
));
937 gen_store_spr(sprn
, t0
);
941 void spr_write_excp_vector(DisasContext
*ctx
, int sprn
, int gprn
)
945 if (sprn
>= SPR_BOOKE_IVOR0
&& sprn
<= SPR_BOOKE_IVOR15
) {
946 sprn_offs
= sprn
- SPR_BOOKE_IVOR0
;
947 } else if (sprn
>= SPR_BOOKE_IVOR32
&& sprn
<= SPR_BOOKE_IVOR37
) {
948 sprn_offs
= sprn
- SPR_BOOKE_IVOR32
+ 32;
949 } else if (sprn
>= SPR_BOOKE_IVOR38
&& sprn
<= SPR_BOOKE_IVOR42
) {
950 sprn_offs
= sprn
- SPR_BOOKE_IVOR38
+ 38;
952 printf("Trying to write an unknown exception vector %d %03x\n",
954 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
958 TCGv t0
= tcg_temp_new();
959 tcg_gen_ld_tl(t0
, cpu_env
, offsetof(CPUPPCState
, ivor_mask
));
960 tcg_gen_and_tl(t0
, t0
, cpu_gpr
[gprn
]);
961 tcg_gen_st_tl(t0
, cpu_env
, offsetof(CPUPPCState
, excp_vectors
[sprn_offs
]));
962 gen_store_spr(sprn
, t0
);
968 #ifndef CONFIG_USER_ONLY
969 void spr_write_amr(DisasContext
*ctx
, int sprn
, int gprn
)
971 TCGv t0
= tcg_temp_new();
972 TCGv t1
= tcg_temp_new();
973 TCGv t2
= tcg_temp_new();
976 * Note, the HV=1 PR=0 case is handled earlier by simply using
977 * spr_write_generic for HV mode in the SPR table
980 /* Build insertion mask into t1 based on context */
982 gen_load_spr(t1
, SPR_UAMOR
);
984 gen_load_spr(t1
, SPR_AMOR
);
987 /* Mask new bits into t2 */
988 tcg_gen_and_tl(t2
, t1
, cpu_gpr
[gprn
]);
990 /* Load AMR and clear new bits in t0 */
991 gen_load_spr(t0
, SPR_AMR
);
992 tcg_gen_andc_tl(t0
, t0
, t1
);
994 /* Or'in new bits and write it out */
995 tcg_gen_or_tl(t0
, t0
, t2
);
996 gen_store_spr(SPR_AMR
, t0
);
997 spr_store_dump_spr(SPR_AMR
);
1004 void spr_write_uamor(DisasContext
*ctx
, int sprn
, int gprn
)
1006 TCGv t0
= tcg_temp_new();
1007 TCGv t1
= tcg_temp_new();
1008 TCGv t2
= tcg_temp_new();
1011 * Note, the HV=1 case is handled earlier by simply using
1012 * spr_write_generic for HV mode in the SPR table
1015 /* Build insertion mask into t1 based on context */
1016 gen_load_spr(t1
, SPR_AMOR
);
1018 /* Mask new bits into t2 */
1019 tcg_gen_and_tl(t2
, t1
, cpu_gpr
[gprn
]);
1021 /* Load AMR and clear new bits in t0 */
1022 gen_load_spr(t0
, SPR_UAMOR
);
1023 tcg_gen_andc_tl(t0
, t0
, t1
);
1025 /* Or'in new bits and write it out */
1026 tcg_gen_or_tl(t0
, t0
, t2
);
1027 gen_store_spr(SPR_UAMOR
, t0
);
1028 spr_store_dump_spr(SPR_UAMOR
);
1035 void spr_write_iamr(DisasContext
*ctx
, int sprn
, int gprn
)
1037 TCGv t0
= tcg_temp_new();
1038 TCGv t1
= tcg_temp_new();
1039 TCGv t2
= tcg_temp_new();
1042 * Note, the HV=1 case is handled earlier by simply using
1043 * spr_write_generic for HV mode in the SPR table
1046 /* Build insertion mask into t1 based on context */
1047 gen_load_spr(t1
, SPR_AMOR
);
1049 /* Mask new bits into t2 */
1050 tcg_gen_and_tl(t2
, t1
, cpu_gpr
[gprn
]);
1052 /* Load AMR and clear new bits in t0 */
1053 gen_load_spr(t0
, SPR_IAMR
);
1054 tcg_gen_andc_tl(t0
, t0
, t1
);
1056 /* Or'in new bits and write it out */
1057 tcg_gen_or_tl(t0
, t0
, t2
);
1058 gen_store_spr(SPR_IAMR
, t0
);
1059 spr_store_dump_spr(SPR_IAMR
);
1068 #ifndef CONFIG_USER_ONLY
1069 void spr_read_thrm(DisasContext
*ctx
, int gprn
, int sprn
)
1071 gen_helper_fixup_thrm(cpu_env
);
1072 gen_load_spr(cpu_gpr
[gprn
], sprn
);
1073 spr_load_dump_spr(sprn
);
1075 #endif /* !CONFIG_USER_ONLY */
1077 #if !defined(CONFIG_USER_ONLY)
1078 void spr_write_e500_l1csr0(DisasContext
*ctx
, int sprn
, int gprn
)
1080 TCGv t0
= tcg_temp_new();
1082 tcg_gen_andi_tl(t0
, cpu_gpr
[gprn
], L1CSR0_DCE
| L1CSR0_CPE
);
1083 gen_store_spr(sprn
, t0
);
1087 void spr_write_e500_l1csr1(DisasContext
*ctx
, int sprn
, int gprn
)
1089 TCGv t0
= tcg_temp_new();
1091 tcg_gen_andi_tl(t0
, cpu_gpr
[gprn
], L1CSR1_ICE
| L1CSR1_CPE
);
1092 gen_store_spr(sprn
, t0
);
1096 void spr_write_e500_l2csr0(DisasContext
*ctx
, int sprn
, int gprn
)
1098 TCGv t0
= tcg_temp_new();
1100 tcg_gen_andi_tl(t0
, cpu_gpr
[gprn
],
1101 ~(E500_L2CSR0_L2FI
| E500_L2CSR0_L2FL
| E500_L2CSR0_L2LFC
));
1102 gen_store_spr(sprn
, t0
);
1106 void spr_write_booke206_mmucsr0(DisasContext
*ctx
, int sprn
, int gprn
)
1108 gen_helper_booke206_tlbflush(cpu_env
, cpu_gpr
[gprn
]);
1111 void spr_write_booke_pid(DisasContext
*ctx
, int sprn
, int gprn
)
1113 TCGv_i32 t0
= tcg_const_i32(sprn
);
1114 gen_helper_booke_setpid(cpu_env
, t0
, cpu_gpr
[gprn
]);
1115 tcg_temp_free_i32(t0
);
1117 void spr_write_eplc(DisasContext
*ctx
, int sprn
, int gprn
)
1119 gen_helper_booke_set_eplc(cpu_env
, cpu_gpr
[gprn
]);
1121 void spr_write_epsc(DisasContext
*ctx
, int sprn
, int gprn
)
1123 gen_helper_booke_set_epsc(cpu_env
, cpu_gpr
[gprn
]);
1128 #if !defined(CONFIG_USER_ONLY)
1129 void spr_write_mas73(DisasContext
*ctx
, int sprn
, int gprn
)
1131 TCGv val
= tcg_temp_new();
1132 tcg_gen_ext32u_tl(val
, cpu_gpr
[gprn
]);
1133 gen_store_spr(SPR_BOOKE_MAS3
, val
);
1134 tcg_gen_shri_tl(val
, cpu_gpr
[gprn
], 32);
1135 gen_store_spr(SPR_BOOKE_MAS7
, val
);
1139 void spr_read_mas73(DisasContext
*ctx
, int gprn
, int sprn
)
1141 TCGv mas7
= tcg_temp_new();
1142 TCGv mas3
= tcg_temp_new();
1143 gen_load_spr(mas7
, SPR_BOOKE_MAS7
);
1144 tcg_gen_shli_tl(mas7
, mas7
, 32);
1145 gen_load_spr(mas3
, SPR_BOOKE_MAS3
);
1146 tcg_gen_or_tl(cpu_gpr
[gprn
], mas3
, mas7
);
1147 tcg_temp_free(mas3
);
1148 tcg_temp_free(mas7
);
1154 static void gen_fscr_facility_check(DisasContext
*ctx
, int facility_sprn
,
1155 int bit
, int sprn
, int cause
)
1157 TCGv_i32 t1
= tcg_const_i32(bit
);
1158 TCGv_i32 t2
= tcg_const_i32(sprn
);
1159 TCGv_i32 t3
= tcg_const_i32(cause
);
1161 gen_helper_fscr_facility_check(cpu_env
, t1
, t2
, t3
);
1163 tcg_temp_free_i32(t3
);
1164 tcg_temp_free_i32(t2
);
1165 tcg_temp_free_i32(t1
);
1168 static void gen_msr_facility_check(DisasContext
*ctx
, int facility_sprn
,
1169 int bit
, int sprn
, int cause
)
1171 TCGv_i32 t1
= tcg_const_i32(bit
);
1172 TCGv_i32 t2
= tcg_const_i32(sprn
);
1173 TCGv_i32 t3
= tcg_const_i32(cause
);
1175 gen_helper_msr_facility_check(cpu_env
, t1
, t2
, t3
);
1177 tcg_temp_free_i32(t3
);
1178 tcg_temp_free_i32(t2
);
1179 tcg_temp_free_i32(t1
);
1182 void spr_read_prev_upper32(DisasContext
*ctx
, int gprn
, int sprn
)
1184 TCGv spr_up
= tcg_temp_new();
1185 TCGv spr
= tcg_temp_new();
1187 gen_load_spr(spr
, sprn
- 1);
1188 tcg_gen_shri_tl(spr_up
, spr
, 32);
1189 tcg_gen_ext32u_tl(cpu_gpr
[gprn
], spr_up
);
1192 tcg_temp_free(spr_up
);
1195 void spr_write_prev_upper32(DisasContext
*ctx
, int sprn
, int gprn
)
1197 TCGv spr
= tcg_temp_new();
1199 gen_load_spr(spr
, sprn
- 1);
1200 tcg_gen_deposit_tl(spr
, spr
, cpu_gpr
[gprn
], 32, 32);
1201 gen_store_spr(sprn
- 1, spr
);
1206 #if !defined(CONFIG_USER_ONLY)
1207 void spr_write_hmer(DisasContext
*ctx
, int sprn
, int gprn
)
1209 TCGv hmer
= tcg_temp_new();
1211 gen_load_spr(hmer
, sprn
);
1212 tcg_gen_and_tl(hmer
, cpu_gpr
[gprn
], hmer
);
1213 gen_store_spr(sprn
, hmer
);
1214 spr_store_dump_spr(sprn
);
1215 tcg_temp_free(hmer
);
1218 void spr_write_lpcr(DisasContext
*ctx
, int sprn
, int gprn
)
1220 gen_helper_store_lpcr(cpu_env
, cpu_gpr
[gprn
]);
1222 #endif /* !defined(CONFIG_USER_ONLY) */
1224 void spr_read_tar(DisasContext
*ctx
, int gprn
, int sprn
)
1226 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_TAR
, sprn
, FSCR_IC_TAR
);
1227 spr_read_generic(ctx
, gprn
, sprn
);
1230 void spr_write_tar(DisasContext
*ctx
, int sprn
, int gprn
)
1232 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_TAR
, sprn
, FSCR_IC_TAR
);
1233 spr_write_generic(ctx
, sprn
, gprn
);
1236 void spr_read_tm(DisasContext
*ctx
, int gprn
, int sprn
)
1238 gen_msr_facility_check(ctx
, SPR_FSCR
, MSR_TM
, sprn
, FSCR_IC_TM
);
1239 spr_read_generic(ctx
, gprn
, sprn
);
1242 void spr_write_tm(DisasContext
*ctx
, int sprn
, int gprn
)
1244 gen_msr_facility_check(ctx
, SPR_FSCR
, MSR_TM
, sprn
, FSCR_IC_TM
);
1245 spr_write_generic(ctx
, sprn
, gprn
);
1248 void spr_read_tm_upper32(DisasContext
*ctx
, int gprn
, int sprn
)
1250 gen_msr_facility_check(ctx
, SPR_FSCR
, MSR_TM
, sprn
, FSCR_IC_TM
);
1251 spr_read_prev_upper32(ctx
, gprn
, sprn
);
1254 void spr_write_tm_upper32(DisasContext
*ctx
, int sprn
, int gprn
)
1256 gen_msr_facility_check(ctx
, SPR_FSCR
, MSR_TM
, sprn
, FSCR_IC_TM
);
1257 spr_write_prev_upper32(ctx
, sprn
, gprn
);
1260 void spr_read_ebb(DisasContext
*ctx
, int gprn
, int sprn
)
1262 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_EBB
, sprn
, FSCR_IC_EBB
);
1263 spr_read_generic(ctx
, gprn
, sprn
);
1266 void spr_write_ebb(DisasContext
*ctx
, int sprn
, int gprn
)
1268 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_EBB
, sprn
, FSCR_IC_EBB
);
1269 spr_write_generic(ctx
, sprn
, gprn
);
1272 void spr_read_ebb_upper32(DisasContext
*ctx
, int gprn
, int sprn
)
1274 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_EBB
, sprn
, FSCR_IC_EBB
);
1275 spr_read_prev_upper32(ctx
, gprn
, sprn
);
1278 void spr_write_ebb_upper32(DisasContext
*ctx
, int sprn
, int gprn
)
1280 gen_fscr_facility_check(ctx
, SPR_FSCR
, FSCR_EBB
, sprn
, FSCR_IC_EBB
);
1281 spr_write_prev_upper32(ctx
, sprn
, gprn
);
1285 #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \
1286 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE)
1288 #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \
1289 GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2)
1291 #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \
1292 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE)
1294 #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \
1295 GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2)
1297 #define GEN_HANDLER_E_2(name, opc1, opc2, opc3, opc4, inval, type, type2) \
1298 GEN_OPCODE3(name, opc1, opc2, opc3, opc4, inval, type, type2)
1300 #define GEN_HANDLER2_E_2(name, onam, opc1, opc2, opc3, opc4, inval, typ, typ2) \
1301 GEN_OPCODE4(name, onam, opc1, opc2, opc3, opc4, inval, typ, typ2)
1303 typedef struct opcode_t
{
1304 unsigned char opc1
, opc2
, opc3
, opc4
;
1305 #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */
1306 unsigned char pad
[4];
1308 opc_handler_t handler
;
1312 /* Helpers for priv. check */
1315 gen_priv_exception(ctx, POWERPC_EXCP_PRIV_OPC); return; \
1318 #if defined(CONFIG_USER_ONLY)
1319 #define CHK_HV GEN_PRIV
1320 #define CHK_SV GEN_PRIV
1321 #define CHK_HVRM GEN_PRIV
1325 if (unlikely(ctx->pr || !ctx->hv)) { \
1331 if (unlikely(ctx->pr)) { \
1337 if (unlikely(ctx->pr || !ctx->hv || ctx->dr)) { \
1345 /*****************************************************************************/
1346 /* PowerPC instructions table */
1348 #if defined(DO_PPC_STATISTICS)
1349 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
1359 .handler = &gen_##name, \
1360 .oname = stringify(name), \
1362 .oname = stringify(name), \
1364 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
1375 .handler = &gen_##name, \
1376 .oname = stringify(name), \
1378 .oname = stringify(name), \
1380 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
1390 .handler = &gen_##name, \
1395 #define GEN_OPCODE3(name, op1, op2, op3, op4, invl, _typ, _typ2) \
1405 .handler = &gen_##name, \
1406 .oname = stringify(name), \
1408 .oname = stringify(name), \
1410 #define GEN_OPCODE4(name, onam, op1, op2, op3, op4, invl, _typ, _typ2) \
1420 .handler = &gen_##name, \
1426 #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \
1436 .handler = &gen_##name, \
1438 .oname = stringify(name), \
1440 #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \
1451 .handler = &gen_##name, \
1453 .oname = stringify(name), \
1455 #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \
1465 .handler = &gen_##name, \
1469 #define GEN_OPCODE3(name, op1, op2, op3, op4, invl, _typ, _typ2) \
1479 .handler = &gen_##name, \
1481 .oname = stringify(name), \
1483 #define GEN_OPCODE4(name, onam, op1, op2, op3, op4, invl, _typ, _typ2) \
1493 .handler = &gen_##name, \
1499 /* Invalid instruction */
1500 static void gen_invalid(DisasContext
*ctx
)
1502 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
1505 static opc_handler_t invalid_handler
= {
1506 .inval1
= 0xFFFFFFFF,
1507 .inval2
= 0xFFFFFFFF,
1510 .handler
= gen_invalid
,
1513 /*** Integer comparison ***/
1515 static inline void gen_op_cmp(TCGv arg0
, TCGv arg1
, int s
, int crf
)
1517 TCGv t0
= tcg_temp_new();
1518 TCGv t1
= tcg_temp_new();
1519 TCGv_i32 t
= tcg_temp_new_i32();
1521 tcg_gen_movi_tl(t0
, CRF_EQ
);
1522 tcg_gen_movi_tl(t1
, CRF_LT
);
1523 tcg_gen_movcond_tl((s
? TCG_COND_LT
: TCG_COND_LTU
),
1524 t0
, arg0
, arg1
, t1
, t0
);
1525 tcg_gen_movi_tl(t1
, CRF_GT
);
1526 tcg_gen_movcond_tl((s
? TCG_COND_GT
: TCG_COND_GTU
),
1527 t0
, arg0
, arg1
, t1
, t0
);
1529 tcg_gen_trunc_tl_i32(t
, t0
);
1530 tcg_gen_trunc_tl_i32(cpu_crf
[crf
], cpu_so
);
1531 tcg_gen_or_i32(cpu_crf
[crf
], cpu_crf
[crf
], t
);
1535 tcg_temp_free_i32(t
);
1538 static inline void gen_op_cmpi(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
1540 TCGv t0
= tcg_const_tl(arg1
);
1541 gen_op_cmp(arg0
, t0
, s
, crf
);
1545 static inline void gen_op_cmp32(TCGv arg0
, TCGv arg1
, int s
, int crf
)
1548 t0
= tcg_temp_new();
1549 t1
= tcg_temp_new();
1551 tcg_gen_ext32s_tl(t0
, arg0
);
1552 tcg_gen_ext32s_tl(t1
, arg1
);
1554 tcg_gen_ext32u_tl(t0
, arg0
);
1555 tcg_gen_ext32u_tl(t1
, arg1
);
1557 gen_op_cmp(t0
, t1
, s
, crf
);
1562 static inline void gen_op_cmpi32(TCGv arg0
, target_ulong arg1
, int s
, int crf
)
1564 TCGv t0
= tcg_const_tl(arg1
);
1565 gen_op_cmp32(arg0
, t0
, s
, crf
);
1569 static inline void gen_set_Rc0(DisasContext
*ctx
, TCGv reg
)
1571 if (NARROW_MODE(ctx
)) {
1572 gen_op_cmpi32(reg
, 0, 1, 0);
1574 gen_op_cmpi(reg
, 0, 1, 0);
1579 static void gen_cmp(DisasContext
*ctx
)
1581 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
1582 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
1583 1, crfD(ctx
->opcode
));
1585 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
1586 1, crfD(ctx
->opcode
));
1591 static void gen_cmpi(DisasContext
*ctx
)
1593 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
1594 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
1595 1, crfD(ctx
->opcode
));
1597 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], SIMM(ctx
->opcode
),
1598 1, crfD(ctx
->opcode
));
1603 static void gen_cmpl(DisasContext
*ctx
)
1605 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
1606 gen_op_cmp(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
1607 0, crfD(ctx
->opcode
));
1609 gen_op_cmp32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
1610 0, crfD(ctx
->opcode
));
1615 static void gen_cmpli(DisasContext
*ctx
)
1617 if ((ctx
->opcode
& 0x00200000) && (ctx
->insns_flags
& PPC_64B
)) {
1618 gen_op_cmpi(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
1619 0, crfD(ctx
->opcode
));
1621 gen_op_cmpi32(cpu_gpr
[rA(ctx
->opcode
)], UIMM(ctx
->opcode
),
1622 0, crfD(ctx
->opcode
));
1626 /* cmprb - range comparison: isupper, isaplha, islower*/
1627 static void gen_cmprb(DisasContext
*ctx
)
1629 TCGv_i32 src1
= tcg_temp_new_i32();
1630 TCGv_i32 src2
= tcg_temp_new_i32();
1631 TCGv_i32 src2lo
= tcg_temp_new_i32();
1632 TCGv_i32 src2hi
= tcg_temp_new_i32();
1633 TCGv_i32 crf
= cpu_crf
[crfD(ctx
->opcode
)];
1635 tcg_gen_trunc_tl_i32(src1
, cpu_gpr
[rA(ctx
->opcode
)]);
1636 tcg_gen_trunc_tl_i32(src2
, cpu_gpr
[rB(ctx
->opcode
)]);
1638 tcg_gen_andi_i32(src1
, src1
, 0xFF);
1639 tcg_gen_ext8u_i32(src2lo
, src2
);
1640 tcg_gen_shri_i32(src2
, src2
, 8);
1641 tcg_gen_ext8u_i32(src2hi
, src2
);
1643 tcg_gen_setcond_i32(TCG_COND_LEU
, src2lo
, src2lo
, src1
);
1644 tcg_gen_setcond_i32(TCG_COND_LEU
, src2hi
, src1
, src2hi
);
1645 tcg_gen_and_i32(crf
, src2lo
, src2hi
);
1647 if (ctx
->opcode
& 0x00200000) {
1648 tcg_gen_shri_i32(src2
, src2
, 8);
1649 tcg_gen_ext8u_i32(src2lo
, src2
);
1650 tcg_gen_shri_i32(src2
, src2
, 8);
1651 tcg_gen_ext8u_i32(src2hi
, src2
);
1652 tcg_gen_setcond_i32(TCG_COND_LEU
, src2lo
, src2lo
, src1
);
1653 tcg_gen_setcond_i32(TCG_COND_LEU
, src2hi
, src1
, src2hi
);
1654 tcg_gen_and_i32(src2lo
, src2lo
, src2hi
);
1655 tcg_gen_or_i32(crf
, crf
, src2lo
);
1657 tcg_gen_shli_i32(crf
, crf
, CRF_GT_BIT
);
1658 tcg_temp_free_i32(src1
);
1659 tcg_temp_free_i32(src2
);
1660 tcg_temp_free_i32(src2lo
);
1661 tcg_temp_free_i32(src2hi
);
1664 #if defined(TARGET_PPC64)
1666 static void gen_cmpeqb(DisasContext
*ctx
)
1668 gen_helper_cmpeqb(cpu_crf
[crfD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1669 cpu_gpr
[rB(ctx
->opcode
)]);
1673 /* isel (PowerPC 2.03 specification) */
1674 static void gen_isel(DisasContext
*ctx
)
1676 uint32_t bi
= rC(ctx
->opcode
);
1677 uint32_t mask
= 0x08 >> (bi
& 0x03);
1678 TCGv t0
= tcg_temp_new();
1681 tcg_gen_extu_i32_tl(t0
, cpu_crf
[bi
>> 2]);
1682 tcg_gen_andi_tl(t0
, t0
, mask
);
1684 zr
= tcg_const_tl(0);
1685 tcg_gen_movcond_tl(TCG_COND_NE
, cpu_gpr
[rD(ctx
->opcode
)], t0
, zr
,
1686 rA(ctx
->opcode
) ? cpu_gpr
[rA(ctx
->opcode
)] : zr
,
1687 cpu_gpr
[rB(ctx
->opcode
)]);
1692 /* cmpb: PowerPC 2.05 specification */
1693 static void gen_cmpb(DisasContext
*ctx
)
1695 gen_helper_cmpb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
1696 cpu_gpr
[rB(ctx
->opcode
)]);
1699 /*** Integer arithmetic ***/
1701 static inline void gen_op_arith_compute_ov(DisasContext
*ctx
, TCGv arg0
,
1702 TCGv arg1
, TCGv arg2
, int sub
)
1704 TCGv t0
= tcg_temp_new();
1706 tcg_gen_xor_tl(cpu_ov
, arg0
, arg2
);
1707 tcg_gen_xor_tl(t0
, arg1
, arg2
);
1709 tcg_gen_and_tl(cpu_ov
, cpu_ov
, t0
);
1711 tcg_gen_andc_tl(cpu_ov
, cpu_ov
, t0
);
1714 if (NARROW_MODE(ctx
)) {
1715 tcg_gen_extract_tl(cpu_ov
, cpu_ov
, 31, 1);
1716 if (is_isa300(ctx
)) {
1717 tcg_gen_mov_tl(cpu_ov32
, cpu_ov
);
1720 if (is_isa300(ctx
)) {
1721 tcg_gen_extract_tl(cpu_ov32
, cpu_ov
, 31, 1);
1723 tcg_gen_extract_tl(cpu_ov
, cpu_ov
, TARGET_LONG_BITS
- 1, 1);
1725 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1728 static inline void gen_op_arith_compute_ca32(DisasContext
*ctx
,
1729 TCGv res
, TCGv arg0
, TCGv arg1
,
1734 if (!is_isa300(ctx
)) {
1738 t0
= tcg_temp_new();
1740 tcg_gen_eqv_tl(t0
, arg0
, arg1
);
1742 tcg_gen_xor_tl(t0
, arg0
, arg1
);
1744 tcg_gen_xor_tl(t0
, t0
, res
);
1745 tcg_gen_extract_tl(ca32
, t0
, 32, 1);
1749 /* Common add function */
1750 static inline void gen_op_arith_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1751 TCGv arg2
, TCGv ca
, TCGv ca32
,
1752 bool add_ca
, bool compute_ca
,
1753 bool compute_ov
, bool compute_rc0
)
1757 if (compute_ca
|| compute_ov
) {
1758 t0
= tcg_temp_new();
1762 if (NARROW_MODE(ctx
)) {
1764 * Caution: a non-obvious corner case of the spec is that
1765 * we must produce the *entire* 64-bit addition, but
1766 * produce the carry into bit 32.
1768 TCGv t1
= tcg_temp_new();
1769 tcg_gen_xor_tl(t1
, arg1
, arg2
); /* add without carry */
1770 tcg_gen_add_tl(t0
, arg1
, arg2
);
1772 tcg_gen_add_tl(t0
, t0
, ca
);
1774 tcg_gen_xor_tl(ca
, t0
, t1
); /* bits changed w/ carry */
1776 tcg_gen_extract_tl(ca
, ca
, 32, 1);
1777 if (is_isa300(ctx
)) {
1778 tcg_gen_mov_tl(ca32
, ca
);
1781 TCGv zero
= tcg_const_tl(0);
1783 tcg_gen_add2_tl(t0
, ca
, arg1
, zero
, ca
, zero
);
1784 tcg_gen_add2_tl(t0
, ca
, t0
, ca
, arg2
, zero
);
1786 tcg_gen_add2_tl(t0
, ca
, arg1
, zero
, arg2
, zero
);
1788 gen_op_arith_compute_ca32(ctx
, t0
, arg1
, arg2
, ca32
, 0);
1789 tcg_temp_free(zero
);
1792 tcg_gen_add_tl(t0
, arg1
, arg2
);
1794 tcg_gen_add_tl(t0
, t0
, ca
);
1799 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 0);
1801 if (unlikely(compute_rc0
)) {
1802 gen_set_Rc0(ctx
, t0
);
1806 tcg_gen_mov_tl(ret
, t0
);
1810 /* Add functions with two operands */
1811 #define GEN_INT_ARITH_ADD(name, opc3, ca, add_ca, compute_ca, compute_ov) \
1812 static void glue(gen_, name)(DisasContext *ctx) \
1814 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
1815 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1817 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1819 /* Add functions with one operand and one immediate */
1820 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, ca, \
1821 add_ca, compute_ca, compute_ov) \
1822 static void glue(gen_, name)(DisasContext *ctx) \
1824 TCGv t0 = tcg_const_tl(const_val); \
1825 gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \
1826 cpu_gpr[rA(ctx->opcode)], t0, \
1828 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
1829 tcg_temp_free(t0); \
1832 /* add add. addo addo. */
1833 GEN_INT_ARITH_ADD(add
, 0x08, cpu_ca
, 0, 0, 0)
1834 GEN_INT_ARITH_ADD(addo
, 0x18, cpu_ca
, 0, 0, 1)
1835 /* addc addc. addco addco. */
1836 GEN_INT_ARITH_ADD(addc
, 0x00, cpu_ca
, 0, 1, 0)
1837 GEN_INT_ARITH_ADD(addco
, 0x10, cpu_ca
, 0, 1, 1)
1838 /* adde adde. addeo addeo. */
1839 GEN_INT_ARITH_ADD(adde
, 0x04, cpu_ca
, 1, 1, 0)
1840 GEN_INT_ARITH_ADD(addeo
, 0x14, cpu_ca
, 1, 1, 1)
1841 /* addme addme. addmeo addmeo. */
1842 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, cpu_ca
, 1, 1, 0)
1843 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, cpu_ca
, 1, 1, 1)
1845 GEN_INT_ARITH_ADD(addex
, 0x05, cpu_ov
, 1, 1, 0);
1846 /* addze addze. addzeo addzeo.*/
1847 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, cpu_ca
, 1, 1, 0)
1848 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, cpu_ca
, 1, 1, 1)
1850 static void gen_addi(DisasContext
*ctx
)
1852 target_long simm
= SIMM(ctx
->opcode
);
1854 if (rA(ctx
->opcode
) == 0) {
1856 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
);
1858 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)],
1859 cpu_gpr
[rA(ctx
->opcode
)], simm
);
1863 static inline void gen_op_addic(DisasContext
*ctx
, bool compute_rc0
)
1865 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
1866 gen_op_arith_add(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
1867 c
, cpu_ca
, cpu_ca32
, 0, 1, 0, compute_rc0
);
1871 static void gen_addic(DisasContext
*ctx
)
1873 gen_op_addic(ctx
, 0);
1876 static void gen_addic_(DisasContext
*ctx
)
1878 gen_op_addic(ctx
, 1);
1882 static void gen_addis(DisasContext
*ctx
)
1884 target_long simm
= SIMM(ctx
->opcode
);
1886 if (rA(ctx
->opcode
) == 0) {
1888 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
<< 16);
1890 tcg_gen_addi_tl(cpu_gpr
[rD(ctx
->opcode
)],
1891 cpu_gpr
[rA(ctx
->opcode
)], simm
<< 16);
1896 static void gen_addpcis(DisasContext
*ctx
)
1898 target_long d
= DX(ctx
->opcode
);
1900 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], ctx
->base
.pc_next
+ (d
<< 16));
1903 static inline void gen_op_arith_divw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1904 TCGv arg2
, int sign
, int compute_ov
)
1906 TCGv_i32 t0
= tcg_temp_new_i32();
1907 TCGv_i32 t1
= tcg_temp_new_i32();
1908 TCGv_i32 t2
= tcg_temp_new_i32();
1909 TCGv_i32 t3
= tcg_temp_new_i32();
1911 tcg_gen_trunc_tl_i32(t0
, arg1
);
1912 tcg_gen_trunc_tl_i32(t1
, arg2
);
1914 tcg_gen_setcondi_i32(TCG_COND_EQ
, t2
, t0
, INT_MIN
);
1915 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, -1);
1916 tcg_gen_and_i32(t2
, t2
, t3
);
1917 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, 0);
1918 tcg_gen_or_i32(t2
, t2
, t3
);
1919 tcg_gen_movi_i32(t3
, 0);
1920 tcg_gen_movcond_i32(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1921 tcg_gen_div_i32(t3
, t0
, t1
);
1922 tcg_gen_extu_i32_tl(ret
, t3
);
1924 tcg_gen_setcondi_i32(TCG_COND_EQ
, t2
, t1
, 0);
1925 tcg_gen_movi_i32(t3
, 0);
1926 tcg_gen_movcond_i32(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1927 tcg_gen_divu_i32(t3
, t0
, t1
);
1928 tcg_gen_extu_i32_tl(ret
, t3
);
1931 tcg_gen_extu_i32_tl(cpu_ov
, t2
);
1932 if (is_isa300(ctx
)) {
1933 tcg_gen_extu_i32_tl(cpu_ov32
, t2
);
1935 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
1937 tcg_temp_free_i32(t0
);
1938 tcg_temp_free_i32(t1
);
1939 tcg_temp_free_i32(t2
);
1940 tcg_temp_free_i32(t3
);
1942 if (unlikely(Rc(ctx
->opcode
) != 0)) {
1943 gen_set_Rc0(ctx
, ret
);
1947 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
1948 static void glue(gen_, name)(DisasContext *ctx) \
1950 gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \
1951 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
1952 sign, compute_ov); \
1954 /* divwu divwu. divwuo divwuo. */
1955 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0);
1956 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1);
1957 /* divw divw. divwo divwo. */
1958 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0);
1959 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1);
1961 /* div[wd]eu[o][.] */
1962 #define GEN_DIVE(name, hlpr, compute_ov) \
1963 static void gen_##name(DisasContext *ctx) \
1965 TCGv_i32 t0 = tcg_const_i32(compute_ov); \
1966 gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \
1967 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \
1968 tcg_temp_free_i32(t0); \
1969 if (unlikely(Rc(ctx->opcode) != 0)) { \
1970 gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \
1974 GEN_DIVE(divweu
, divweu
, 0);
1975 GEN_DIVE(divweuo
, divweu
, 1);
1976 GEN_DIVE(divwe
, divwe
, 0);
1977 GEN_DIVE(divweo
, divwe
, 1);
1979 #if defined(TARGET_PPC64)
1980 static inline void gen_op_arith_divd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
1981 TCGv arg2
, int sign
, int compute_ov
)
1983 TCGv_i64 t0
= tcg_temp_new_i64();
1984 TCGv_i64 t1
= tcg_temp_new_i64();
1985 TCGv_i64 t2
= tcg_temp_new_i64();
1986 TCGv_i64 t3
= tcg_temp_new_i64();
1988 tcg_gen_mov_i64(t0
, arg1
);
1989 tcg_gen_mov_i64(t1
, arg2
);
1991 tcg_gen_setcondi_i64(TCG_COND_EQ
, t2
, t0
, INT64_MIN
);
1992 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, -1);
1993 tcg_gen_and_i64(t2
, t2
, t3
);
1994 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, 0);
1995 tcg_gen_or_i64(t2
, t2
, t3
);
1996 tcg_gen_movi_i64(t3
, 0);
1997 tcg_gen_movcond_i64(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
1998 tcg_gen_div_i64(ret
, t0
, t1
);
2000 tcg_gen_setcondi_i64(TCG_COND_EQ
, t2
, t1
, 0);
2001 tcg_gen_movi_i64(t3
, 0);
2002 tcg_gen_movcond_i64(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
2003 tcg_gen_divu_i64(ret
, t0
, t1
);
2006 tcg_gen_mov_tl(cpu_ov
, t2
);
2007 if (is_isa300(ctx
)) {
2008 tcg_gen_mov_tl(cpu_ov32
, t2
);
2010 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
2012 tcg_temp_free_i64(t0
);
2013 tcg_temp_free_i64(t1
);
2014 tcg_temp_free_i64(t2
);
2015 tcg_temp_free_i64(t3
);
2017 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2018 gen_set_Rc0(ctx
, ret
);
2022 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
2023 static void glue(gen_, name)(DisasContext *ctx) \
2025 gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \
2026 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
2027 sign, compute_ov); \
2029 /* divdu divdu. divduo divduo. */
2030 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0);
2031 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1);
2032 /* divd divd. divdo divdo. */
2033 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0);
2034 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1);
2036 GEN_DIVE(divdeu
, divdeu
, 0);
2037 GEN_DIVE(divdeuo
, divdeu
, 1);
2038 GEN_DIVE(divde
, divde
, 0);
2039 GEN_DIVE(divdeo
, divde
, 1);
2042 static inline void gen_op_arith_modw(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
2043 TCGv arg2
, int sign
)
2045 TCGv_i32 t0
= tcg_temp_new_i32();
2046 TCGv_i32 t1
= tcg_temp_new_i32();
2048 tcg_gen_trunc_tl_i32(t0
, arg1
);
2049 tcg_gen_trunc_tl_i32(t1
, arg2
);
2051 TCGv_i32 t2
= tcg_temp_new_i32();
2052 TCGv_i32 t3
= tcg_temp_new_i32();
2053 tcg_gen_setcondi_i32(TCG_COND_EQ
, t2
, t0
, INT_MIN
);
2054 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, -1);
2055 tcg_gen_and_i32(t2
, t2
, t3
);
2056 tcg_gen_setcondi_i32(TCG_COND_EQ
, t3
, t1
, 0);
2057 tcg_gen_or_i32(t2
, t2
, t3
);
2058 tcg_gen_movi_i32(t3
, 0);
2059 tcg_gen_movcond_i32(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
2060 tcg_gen_rem_i32(t3
, t0
, t1
);
2061 tcg_gen_ext_i32_tl(ret
, t3
);
2062 tcg_temp_free_i32(t2
);
2063 tcg_temp_free_i32(t3
);
2065 TCGv_i32 t2
= tcg_const_i32(1);
2066 TCGv_i32 t3
= tcg_const_i32(0);
2067 tcg_gen_movcond_i32(TCG_COND_EQ
, t1
, t1
, t3
, t2
, t1
);
2068 tcg_gen_remu_i32(t3
, t0
, t1
);
2069 tcg_gen_extu_i32_tl(ret
, t3
);
2070 tcg_temp_free_i32(t2
);
2071 tcg_temp_free_i32(t3
);
2073 tcg_temp_free_i32(t0
);
2074 tcg_temp_free_i32(t1
);
2077 #define GEN_INT_ARITH_MODW(name, opc3, sign) \
2078 static void glue(gen_, name)(DisasContext *ctx) \
2080 gen_op_arith_modw(ctx, cpu_gpr[rD(ctx->opcode)], \
2081 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
2085 GEN_INT_ARITH_MODW(moduw
, 0x08, 0);
2086 GEN_INT_ARITH_MODW(modsw
, 0x18, 1);
2088 #if defined(TARGET_PPC64)
2089 static inline void gen_op_arith_modd(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
2090 TCGv arg2
, int sign
)
2092 TCGv_i64 t0
= tcg_temp_new_i64();
2093 TCGv_i64 t1
= tcg_temp_new_i64();
2095 tcg_gen_mov_i64(t0
, arg1
);
2096 tcg_gen_mov_i64(t1
, arg2
);
2098 TCGv_i64 t2
= tcg_temp_new_i64();
2099 TCGv_i64 t3
= tcg_temp_new_i64();
2100 tcg_gen_setcondi_i64(TCG_COND_EQ
, t2
, t0
, INT64_MIN
);
2101 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, -1);
2102 tcg_gen_and_i64(t2
, t2
, t3
);
2103 tcg_gen_setcondi_i64(TCG_COND_EQ
, t3
, t1
, 0);
2104 tcg_gen_or_i64(t2
, t2
, t3
);
2105 tcg_gen_movi_i64(t3
, 0);
2106 tcg_gen_movcond_i64(TCG_COND_NE
, t1
, t2
, t3
, t2
, t1
);
2107 tcg_gen_rem_i64(ret
, t0
, t1
);
2108 tcg_temp_free_i64(t2
);
2109 tcg_temp_free_i64(t3
);
2111 TCGv_i64 t2
= tcg_const_i64(1);
2112 TCGv_i64 t3
= tcg_const_i64(0);
2113 tcg_gen_movcond_i64(TCG_COND_EQ
, t1
, t1
, t3
, t2
, t1
);
2114 tcg_gen_remu_i64(ret
, t0
, t1
);
2115 tcg_temp_free_i64(t2
);
2116 tcg_temp_free_i64(t3
);
2118 tcg_temp_free_i64(t0
);
2119 tcg_temp_free_i64(t1
);
2122 #define GEN_INT_ARITH_MODD(name, opc3, sign) \
2123 static void glue(gen_, name)(DisasContext *ctx) \
2125 gen_op_arith_modd(ctx, cpu_gpr[rD(ctx->opcode)], \
2126 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
2130 GEN_INT_ARITH_MODD(modud
, 0x08, 0);
2131 GEN_INT_ARITH_MODD(modsd
, 0x18, 1);
2135 static void gen_mulhw(DisasContext
*ctx
)
2137 TCGv_i32 t0
= tcg_temp_new_i32();
2138 TCGv_i32 t1
= tcg_temp_new_i32();
2140 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
2141 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
2142 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
2143 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
2144 tcg_temp_free_i32(t0
);
2145 tcg_temp_free_i32(t1
);
2146 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2147 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
2151 /* mulhwu mulhwu. */
2152 static void gen_mulhwu(DisasContext
*ctx
)
2154 TCGv_i32 t0
= tcg_temp_new_i32();
2155 TCGv_i32 t1
= tcg_temp_new_i32();
2157 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
2158 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
2159 tcg_gen_mulu2_i32(t0
, t1
, t0
, t1
);
2160 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
2161 tcg_temp_free_i32(t0
);
2162 tcg_temp_free_i32(t1
);
2163 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2164 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
2169 static void gen_mullw(DisasContext
*ctx
)
2171 #if defined(TARGET_PPC64)
2173 t0
= tcg_temp_new_i64();
2174 t1
= tcg_temp_new_i64();
2175 tcg_gen_ext32s_tl(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
2176 tcg_gen_ext32s_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
2177 tcg_gen_mul_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
2181 tcg_gen_mul_i32(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
2182 cpu_gpr
[rB(ctx
->opcode
)]);
2184 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2185 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
2189 /* mullwo mullwo. */
2190 static void gen_mullwo(DisasContext
*ctx
)
2192 TCGv_i32 t0
= tcg_temp_new_i32();
2193 TCGv_i32 t1
= tcg_temp_new_i32();
2195 tcg_gen_trunc_tl_i32(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
2196 tcg_gen_trunc_tl_i32(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
2197 tcg_gen_muls2_i32(t0
, t1
, t0
, t1
);
2198 #if defined(TARGET_PPC64)
2199 tcg_gen_concat_i32_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
, t1
);
2201 tcg_gen_mov_i32(cpu_gpr
[rD(ctx
->opcode
)], t0
);
2204 tcg_gen_sari_i32(t0
, t0
, 31);
2205 tcg_gen_setcond_i32(TCG_COND_NE
, t0
, t0
, t1
);
2206 tcg_gen_extu_i32_tl(cpu_ov
, t0
);
2207 if (is_isa300(ctx
)) {
2208 tcg_gen_mov_tl(cpu_ov32
, cpu_ov
);
2210 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
2212 tcg_temp_free_i32(t0
);
2213 tcg_temp_free_i32(t1
);
2214 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2215 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
2220 static void gen_mulli(DisasContext
*ctx
)
2222 tcg_gen_muli_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
2226 #if defined(TARGET_PPC64)
2228 static void gen_mulhd(DisasContext
*ctx
)
2230 TCGv lo
= tcg_temp_new();
2231 tcg_gen_muls2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
2232 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2234 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2235 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
2239 /* mulhdu mulhdu. */
2240 static void gen_mulhdu(DisasContext
*ctx
)
2242 TCGv lo
= tcg_temp_new();
2243 tcg_gen_mulu2_tl(lo
, cpu_gpr
[rD(ctx
->opcode
)],
2244 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2246 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2247 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
2252 static void gen_mulld(DisasContext
*ctx
)
2254 tcg_gen_mul_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
2255 cpu_gpr
[rB(ctx
->opcode
)]);
2256 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2257 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
2261 /* mulldo mulldo. */
2262 static void gen_mulldo(DisasContext
*ctx
)
2264 TCGv_i64 t0
= tcg_temp_new_i64();
2265 TCGv_i64 t1
= tcg_temp_new_i64();
2267 tcg_gen_muls2_i64(t0
, t1
, cpu_gpr
[rA(ctx
->opcode
)],
2268 cpu_gpr
[rB(ctx
->opcode
)]);
2269 tcg_gen_mov_i64(cpu_gpr
[rD(ctx
->opcode
)], t0
);
2271 tcg_gen_sari_i64(t0
, t0
, 63);
2272 tcg_gen_setcond_i64(TCG_COND_NE
, cpu_ov
, t0
, t1
);
2273 if (is_isa300(ctx
)) {
2274 tcg_gen_mov_tl(cpu_ov32
, cpu_ov
);
2276 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
2278 tcg_temp_free_i64(t0
);
2279 tcg_temp_free_i64(t1
);
2281 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2282 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
2287 /* Common subf function */
2288 static inline void gen_op_arith_subf(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
2289 TCGv arg2
, bool add_ca
, bool compute_ca
,
2290 bool compute_ov
, bool compute_rc0
)
2294 if (compute_ca
|| compute_ov
) {
2295 t0
= tcg_temp_new();
2299 /* dest = ~arg1 + arg2 [+ ca]. */
2300 if (NARROW_MODE(ctx
)) {
2302 * Caution: a non-obvious corner case of the spec is that
2303 * we must produce the *entire* 64-bit addition, but
2304 * produce the carry into bit 32.
2306 TCGv inv1
= tcg_temp_new();
2307 TCGv t1
= tcg_temp_new();
2308 tcg_gen_not_tl(inv1
, arg1
);
2310 tcg_gen_add_tl(t0
, arg2
, cpu_ca
);
2312 tcg_gen_addi_tl(t0
, arg2
, 1);
2314 tcg_gen_xor_tl(t1
, arg2
, inv1
); /* add without carry */
2315 tcg_gen_add_tl(t0
, t0
, inv1
);
2316 tcg_temp_free(inv1
);
2317 tcg_gen_xor_tl(cpu_ca
, t0
, t1
); /* bits changes w/ carry */
2319 tcg_gen_extract_tl(cpu_ca
, cpu_ca
, 32, 1);
2320 if (is_isa300(ctx
)) {
2321 tcg_gen_mov_tl(cpu_ca32
, cpu_ca
);
2323 } else if (add_ca
) {
2324 TCGv zero
, inv1
= tcg_temp_new();
2325 tcg_gen_not_tl(inv1
, arg1
);
2326 zero
= tcg_const_tl(0);
2327 tcg_gen_add2_tl(t0
, cpu_ca
, arg2
, zero
, cpu_ca
, zero
);
2328 tcg_gen_add2_tl(t0
, cpu_ca
, t0
, cpu_ca
, inv1
, zero
);
2329 gen_op_arith_compute_ca32(ctx
, t0
, inv1
, arg2
, cpu_ca32
, 0);
2330 tcg_temp_free(zero
);
2331 tcg_temp_free(inv1
);
2333 tcg_gen_setcond_tl(TCG_COND_GEU
, cpu_ca
, arg2
, arg1
);
2334 tcg_gen_sub_tl(t0
, arg2
, arg1
);
2335 gen_op_arith_compute_ca32(ctx
, t0
, arg1
, arg2
, cpu_ca32
, 1);
2337 } else if (add_ca
) {
2339 * Since we're ignoring carry-out, we can simplify the
2340 * standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1.
2342 tcg_gen_sub_tl(t0
, arg2
, arg1
);
2343 tcg_gen_add_tl(t0
, t0
, cpu_ca
);
2344 tcg_gen_subi_tl(t0
, t0
, 1);
2346 tcg_gen_sub_tl(t0
, arg2
, arg1
);
2350 gen_op_arith_compute_ov(ctx
, t0
, arg1
, arg2
, 1);
2352 if (unlikely(compute_rc0
)) {
2353 gen_set_Rc0(ctx
, t0
);
2357 tcg_gen_mov_tl(ret
, t0
);
2361 /* Sub functions with Two operands functions */
2362 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
2363 static void glue(gen_, name)(DisasContext *ctx) \
2365 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
2366 cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \
2367 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
2369 /* Sub functions with one operand and one immediate */
2370 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
2371 add_ca, compute_ca, compute_ov) \
2372 static void glue(gen_, name)(DisasContext *ctx) \
2374 TCGv t0 = tcg_const_tl(const_val); \
2375 gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \
2376 cpu_gpr[rA(ctx->opcode)], t0, \
2377 add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \
2378 tcg_temp_free(t0); \
2380 /* subf subf. subfo subfo. */
2381 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
2382 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
2383 /* subfc subfc. subfco subfco. */
2384 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
2385 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
2386 /* subfe subfe. subfeo subfo. */
2387 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
2388 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
2389 /* subfme subfme. subfmeo subfmeo. */
2390 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
2391 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
2392 /* subfze subfze. subfzeo subfzeo.*/
2393 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
2394 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
2397 static void gen_subfic(DisasContext
*ctx
)
2399 TCGv c
= tcg_const_tl(SIMM(ctx
->opcode
));
2400 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
2405 /* neg neg. nego nego. */
2406 static inline void gen_op_arith_neg(DisasContext
*ctx
, bool compute_ov
)
2408 TCGv zero
= tcg_const_tl(0);
2409 gen_op_arith_subf(ctx
, cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
2410 zero
, 0, 0, compute_ov
, Rc(ctx
->opcode
));
2411 tcg_temp_free(zero
);
2414 static void gen_neg(DisasContext
*ctx
)
2416 tcg_gen_neg_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
2417 if (unlikely(Rc(ctx
->opcode
))) {
2418 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
2422 static void gen_nego(DisasContext
*ctx
)
2424 gen_op_arith_neg(ctx
, 1);
2427 /*** Integer logical ***/
2428 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
2429 static void glue(gen_, name)(DisasContext *ctx) \
2431 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \
2432 cpu_gpr[rB(ctx->opcode)]); \
2433 if (unlikely(Rc(ctx->opcode) != 0)) \
2434 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
2437 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
2438 static void glue(gen_, name)(DisasContext *ctx) \
2440 tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \
2441 if (unlikely(Rc(ctx->opcode) != 0)) \
2442 gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \
2446 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
);
2448 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
);
2451 static void gen_andi_(DisasContext
*ctx
)
2453 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
2455 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2459 static void gen_andis_(DisasContext
*ctx
)
2461 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
2462 UIMM(ctx
->opcode
) << 16);
2463 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2467 static void gen_cntlzw(DisasContext
*ctx
)
2469 TCGv_i32 t
= tcg_temp_new_i32();
2471 tcg_gen_trunc_tl_i32(t
, cpu_gpr
[rS(ctx
->opcode
)]);
2472 tcg_gen_clzi_i32(t
, t
, 32);
2473 tcg_gen_extu_i32_tl(cpu_gpr
[rA(ctx
->opcode
)], t
);
2474 tcg_temp_free_i32(t
);
2476 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2477 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2482 static void gen_cnttzw(DisasContext
*ctx
)
2484 TCGv_i32 t
= tcg_temp_new_i32();
2486 tcg_gen_trunc_tl_i32(t
, cpu_gpr
[rS(ctx
->opcode
)]);
2487 tcg_gen_ctzi_i32(t
, t
, 32);
2488 tcg_gen_extu_i32_tl(cpu_gpr
[rA(ctx
->opcode
)], t
);
2489 tcg_temp_free_i32(t
);
2491 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2492 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2497 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
);
2498 /* extsb & extsb. */
2499 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
);
2500 /* extsh & extsh. */
2501 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
);
2503 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
);
2505 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
);
2507 #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY)
2508 static void gen_pause(DisasContext
*ctx
)
2510 TCGv_i32 t0
= tcg_const_i32(0);
2511 tcg_gen_st_i32(t0
, cpu_env
,
2512 -offsetof(PowerPCCPU
, env
) + offsetof(CPUState
, halted
));
2513 tcg_temp_free_i32(t0
);
2515 /* Stop translation, this gives other CPUs a chance to run */
2516 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
2518 #endif /* defined(TARGET_PPC64) */
2521 static void gen_or(DisasContext
*ctx
)
2525 rs
= rS(ctx
->opcode
);
2526 ra
= rA(ctx
->opcode
);
2527 rb
= rB(ctx
->opcode
);
2528 /* Optimisation for mr. ri case */
2529 if (rs
!= ra
|| rs
!= rb
) {
2531 tcg_gen_or_tl(cpu_gpr
[ra
], cpu_gpr
[rs
], cpu_gpr
[rb
]);
2533 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rs
]);
2535 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2536 gen_set_Rc0(ctx
, cpu_gpr
[ra
]);
2538 } else if (unlikely(Rc(ctx
->opcode
) != 0)) {
2539 gen_set_Rc0(ctx
, cpu_gpr
[rs
]);
2540 #if defined(TARGET_PPC64)
2541 } else if (rs
!= 0) { /* 0 is nop */
2546 /* Set process priority to low */
2550 /* Set process priority to medium-low */
2554 /* Set process priority to normal */
2557 #if !defined(CONFIG_USER_ONLY)
2560 /* Set process priority to very low */
2566 /* Set process priority to medium-hight */
2572 /* Set process priority to high */
2577 if (ctx
->hv
&& !ctx
->pr
) {
2578 /* Set process priority to very high */
2587 TCGv t0
= tcg_temp_new();
2588 gen_load_spr(t0
, SPR_PPR
);
2589 tcg_gen_andi_tl(t0
, t0
, ~0x001C000000000000ULL
);
2590 tcg_gen_ori_tl(t0
, t0
, ((uint64_t)prio
) << 50);
2591 gen_store_spr(SPR_PPR
, t0
);
2594 #if !defined(CONFIG_USER_ONLY)
2596 * Pause out of TCG otherwise spin loops with smt_low eat too
2597 * much CPU and the kernel hangs. This applies to all
2598 * encodings other than no-op, e.g., miso(rs=26), yield(27),
2599 * mdoio(29), mdoom(30), and all currently undefined.
2607 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
);
2610 static void gen_xor(DisasContext
*ctx
)
2612 /* Optimisation for "set to zero" case */
2613 if (rS(ctx
->opcode
) != rB(ctx
->opcode
)) {
2614 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
2615 cpu_gpr
[rB(ctx
->opcode
)]);
2617 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
2619 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2620 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2625 static void gen_ori(DisasContext
*ctx
)
2627 target_ulong uimm
= UIMM(ctx
->opcode
);
2629 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
2632 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
2636 static void gen_oris(DisasContext
*ctx
)
2638 target_ulong uimm
= UIMM(ctx
->opcode
);
2640 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
2644 tcg_gen_ori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
2649 static void gen_xori(DisasContext
*ctx
)
2651 target_ulong uimm
= UIMM(ctx
->opcode
);
2653 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
2657 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], uimm
);
2661 static void gen_xoris(DisasContext
*ctx
)
2663 target_ulong uimm
= UIMM(ctx
->opcode
);
2665 if (rS(ctx
->opcode
) == rA(ctx
->opcode
) && uimm
== 0) {
2669 tcg_gen_xori_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)],
2673 /* popcntb : PowerPC 2.03 specification */
2674 static void gen_popcntb(DisasContext
*ctx
)
2676 gen_helper_popcntb(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
2679 static void gen_popcntw(DisasContext
*ctx
)
2681 #if defined(TARGET_PPC64)
2682 gen_helper_popcntw(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
2684 tcg_gen_ctpop_i32(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
2688 #if defined(TARGET_PPC64)
2689 /* popcntd: PowerPC 2.06 specification */
2690 static void gen_popcntd(DisasContext
*ctx
)
2692 tcg_gen_ctpop_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
2696 /* prtyw: PowerPC 2.05 specification */
2697 static void gen_prtyw(DisasContext
*ctx
)
2699 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
2700 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
2701 TCGv t0
= tcg_temp_new();
2702 tcg_gen_shri_tl(t0
, rs
, 16);
2703 tcg_gen_xor_tl(ra
, rs
, t0
);
2704 tcg_gen_shri_tl(t0
, ra
, 8);
2705 tcg_gen_xor_tl(ra
, ra
, t0
);
2706 tcg_gen_andi_tl(ra
, ra
, (target_ulong
)0x100000001ULL
);
2710 #if defined(TARGET_PPC64)
2711 /* prtyd: PowerPC 2.05 specification */
2712 static void gen_prtyd(DisasContext
*ctx
)
2714 TCGv ra
= cpu_gpr
[rA(ctx
->opcode
)];
2715 TCGv rs
= cpu_gpr
[rS(ctx
->opcode
)];
2716 TCGv t0
= tcg_temp_new();
2717 tcg_gen_shri_tl(t0
, rs
, 32);
2718 tcg_gen_xor_tl(ra
, rs
, t0
);
2719 tcg_gen_shri_tl(t0
, ra
, 16);
2720 tcg_gen_xor_tl(ra
, ra
, t0
);
2721 tcg_gen_shri_tl(t0
, ra
, 8);
2722 tcg_gen_xor_tl(ra
, ra
, t0
);
2723 tcg_gen_andi_tl(ra
, ra
, 1);
2728 #if defined(TARGET_PPC64)
2730 static void gen_bpermd(DisasContext
*ctx
)
2732 gen_helper_bpermd(cpu_gpr
[rA(ctx
->opcode
)],
2733 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
2737 #if defined(TARGET_PPC64)
2738 /* extsw & extsw. */
2739 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
);
2742 static void gen_cntlzd(DisasContext
*ctx
)
2744 tcg_gen_clzi_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], 64);
2745 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2746 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2751 static void gen_cnttzd(DisasContext
*ctx
)
2753 tcg_gen_ctzi_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], 64);
2754 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2755 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
2760 static void gen_darn(DisasContext
*ctx
)
2762 int l
= L(ctx
->opcode
);
2765 tcg_gen_movi_i64(cpu_gpr
[rD(ctx
->opcode
)], -1);
2767 gen_icount_io_start(ctx
);
2769 gen_helper_darn32(cpu_gpr
[rD(ctx
->opcode
)]);
2771 /* Return 64-bit random for both CRN and RRN */
2772 gen_helper_darn64(cpu_gpr
[rD(ctx
->opcode
)]);
2778 /*** Integer rotate ***/
2780 /* rlwimi & rlwimi. */
2781 static void gen_rlwimi(DisasContext
*ctx
)
2783 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2784 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2785 uint32_t sh
= SH(ctx
->opcode
);
2786 uint32_t mb
= MB(ctx
->opcode
);
2787 uint32_t me
= ME(ctx
->opcode
);
2789 if (sh
== (31 - me
) && mb
<= me
) {
2790 tcg_gen_deposit_tl(t_ra
, t_ra
, t_rs
, sh
, me
- mb
+ 1);
2793 bool mask_in_32b
= true;
2796 #if defined(TARGET_PPC64)
2800 mask
= MASK(mb
, me
);
2802 #if defined(TARGET_PPC64)
2803 if (mask
> 0xffffffffu
) {
2804 mask_in_32b
= false;
2807 t1
= tcg_temp_new();
2809 TCGv_i32 t0
= tcg_temp_new_i32();
2810 tcg_gen_trunc_tl_i32(t0
, t_rs
);
2811 tcg_gen_rotli_i32(t0
, t0
, sh
);
2812 tcg_gen_extu_i32_tl(t1
, t0
);
2813 tcg_temp_free_i32(t0
);
2815 #if defined(TARGET_PPC64)
2816 tcg_gen_deposit_i64(t1
, t_rs
, t_rs
, 32, 32);
2817 tcg_gen_rotli_i64(t1
, t1
, sh
);
2819 g_assert_not_reached();
2823 tcg_gen_andi_tl(t1
, t1
, mask
);
2824 tcg_gen_andi_tl(t_ra
, t_ra
, ~mask
);
2825 tcg_gen_or_tl(t_ra
, t_ra
, t1
);
2828 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2829 gen_set_Rc0(ctx
, t_ra
);
2833 /* rlwinm & rlwinm. */
2834 static void gen_rlwinm(DisasContext
*ctx
)
2836 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2837 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2838 int sh
= SH(ctx
->opcode
);
2839 int mb
= MB(ctx
->opcode
);
2840 int me
= ME(ctx
->opcode
);
2841 int len
= me
- mb
+ 1;
2842 int rsh
= (32 - sh
) & 31;
2844 if (sh
!= 0 && len
> 0 && me
== (31 - sh
)) {
2845 tcg_gen_deposit_z_tl(t_ra
, t_rs
, sh
, len
);
2846 } else if (me
== 31 && rsh
+ len
<= 32) {
2847 tcg_gen_extract_tl(t_ra
, t_rs
, rsh
, len
);
2850 bool mask_in_32b
= true;
2851 #if defined(TARGET_PPC64)
2855 mask
= MASK(mb
, me
);
2856 #if defined(TARGET_PPC64)
2857 if (mask
> 0xffffffffu
) {
2858 mask_in_32b
= false;
2863 tcg_gen_andi_tl(t_ra
, t_rs
, mask
);
2865 TCGv_i32 t0
= tcg_temp_new_i32();
2866 tcg_gen_trunc_tl_i32(t0
, t_rs
);
2867 tcg_gen_rotli_i32(t0
, t0
, sh
);
2868 tcg_gen_andi_i32(t0
, t0
, mask
);
2869 tcg_gen_extu_i32_tl(t_ra
, t0
);
2870 tcg_temp_free_i32(t0
);
2873 #if defined(TARGET_PPC64)
2874 tcg_gen_deposit_i64(t_ra
, t_rs
, t_rs
, 32, 32);
2875 tcg_gen_rotli_i64(t_ra
, t_ra
, sh
);
2876 tcg_gen_andi_i64(t_ra
, t_ra
, mask
);
2878 g_assert_not_reached();
2882 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2883 gen_set_Rc0(ctx
, t_ra
);
2887 /* rlwnm & rlwnm. */
2888 static void gen_rlwnm(DisasContext
*ctx
)
2890 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2891 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2892 TCGv t_rb
= cpu_gpr
[rB(ctx
->opcode
)];
2893 uint32_t mb
= MB(ctx
->opcode
);
2894 uint32_t me
= ME(ctx
->opcode
);
2896 bool mask_in_32b
= true;
2898 #if defined(TARGET_PPC64)
2902 mask
= MASK(mb
, me
);
2904 #if defined(TARGET_PPC64)
2905 if (mask
> 0xffffffffu
) {
2906 mask_in_32b
= false;
2910 TCGv_i32 t0
= tcg_temp_new_i32();
2911 TCGv_i32 t1
= tcg_temp_new_i32();
2912 tcg_gen_trunc_tl_i32(t0
, t_rb
);
2913 tcg_gen_trunc_tl_i32(t1
, t_rs
);
2914 tcg_gen_andi_i32(t0
, t0
, 0x1f);
2915 tcg_gen_rotl_i32(t1
, t1
, t0
);
2916 tcg_gen_extu_i32_tl(t_ra
, t1
);
2917 tcg_temp_free_i32(t0
);
2918 tcg_temp_free_i32(t1
);
2920 #if defined(TARGET_PPC64)
2921 TCGv_i64 t0
= tcg_temp_new_i64();
2922 tcg_gen_andi_i64(t0
, t_rb
, 0x1f);
2923 tcg_gen_deposit_i64(t_ra
, t_rs
, t_rs
, 32, 32);
2924 tcg_gen_rotl_i64(t_ra
, t_ra
, t0
);
2925 tcg_temp_free_i64(t0
);
2927 g_assert_not_reached();
2931 tcg_gen_andi_tl(t_ra
, t_ra
, mask
);
2933 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2934 gen_set_Rc0(ctx
, t_ra
);
2938 #if defined(TARGET_PPC64)
2939 #define GEN_PPC64_R2(name, opc1, opc2) \
2940 static void glue(gen_, name##0)(DisasContext *ctx) \
2942 gen_##name(ctx, 0); \
2945 static void glue(gen_, name##1)(DisasContext *ctx) \
2947 gen_##name(ctx, 1); \
2949 #define GEN_PPC64_R4(name, opc1, opc2) \
2950 static void glue(gen_, name##0)(DisasContext *ctx) \
2952 gen_##name(ctx, 0, 0); \
2955 static void glue(gen_, name##1)(DisasContext *ctx) \
2957 gen_##name(ctx, 0, 1); \
2960 static void glue(gen_, name##2)(DisasContext *ctx) \
2962 gen_##name(ctx, 1, 0); \
2965 static void glue(gen_, name##3)(DisasContext *ctx) \
2967 gen_##name(ctx, 1, 1); \
2970 static void gen_rldinm(DisasContext
*ctx
, int mb
, int me
, int sh
)
2972 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
2973 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
2974 int len
= me
- mb
+ 1;
2975 int rsh
= (64 - sh
) & 63;
2977 if (sh
!= 0 && len
> 0 && me
== (63 - sh
)) {
2978 tcg_gen_deposit_z_tl(t_ra
, t_rs
, sh
, len
);
2979 } else if (me
== 63 && rsh
+ len
<= 64) {
2980 tcg_gen_extract_tl(t_ra
, t_rs
, rsh
, len
);
2982 tcg_gen_rotli_tl(t_ra
, t_rs
, sh
);
2983 tcg_gen_andi_tl(t_ra
, t_ra
, MASK(mb
, me
));
2985 if (unlikely(Rc(ctx
->opcode
) != 0)) {
2986 gen_set_Rc0(ctx
, t_ra
);
2990 /* rldicl - rldicl. */
2991 static inline void gen_rldicl(DisasContext
*ctx
, int mbn
, int shn
)
2995 sh
= SH(ctx
->opcode
) | (shn
<< 5);
2996 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
2997 gen_rldinm(ctx
, mb
, 63, sh
);
2999 GEN_PPC64_R4(rldicl
, 0x1E, 0x00);
3001 /* rldicr - rldicr. */
3002 static inline void gen_rldicr(DisasContext
*ctx
, int men
, int shn
)
3006 sh
= SH(ctx
->opcode
) | (shn
<< 5);
3007 me
= MB(ctx
->opcode
) | (men
<< 5);
3008 gen_rldinm(ctx
, 0, me
, sh
);
3010 GEN_PPC64_R4(rldicr
, 0x1E, 0x02);
3012 /* rldic - rldic. */
3013 static inline void gen_rldic(DisasContext
*ctx
, int mbn
, int shn
)
3017 sh
= SH(ctx
->opcode
) | (shn
<< 5);
3018 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
3019 gen_rldinm(ctx
, mb
, 63 - sh
, sh
);
3021 GEN_PPC64_R4(rldic
, 0x1E, 0x04);
3023 static void gen_rldnm(DisasContext
*ctx
, int mb
, int me
)
3025 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
3026 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
3027 TCGv t_rb
= cpu_gpr
[rB(ctx
->opcode
)];
3030 t0
= tcg_temp_new();
3031 tcg_gen_andi_tl(t0
, t_rb
, 0x3f);
3032 tcg_gen_rotl_tl(t_ra
, t_rs
, t0
);
3035 tcg_gen_andi_tl(t_ra
, t_ra
, MASK(mb
, me
));
3036 if (unlikely(Rc(ctx
->opcode
) != 0)) {
3037 gen_set_Rc0(ctx
, t_ra
);
3041 /* rldcl - rldcl. */
3042 static inline void gen_rldcl(DisasContext
*ctx
, int mbn
)
3046 mb
= MB(ctx
->opcode
) | (mbn
<< 5);
3047 gen_rldnm(ctx
, mb
, 63);
3049 GEN_PPC64_R2(rldcl
, 0x1E, 0x08);
3051 /* rldcr - rldcr. */
3052 static inline void gen_rldcr(DisasContext
*ctx
, int men
)
3056 me
= MB(ctx
->opcode
) | (men
<< 5);
3057 gen_rldnm(ctx
, 0, me
);
3059 GEN_PPC64_R2(rldcr
, 0x1E, 0x09);
3061 /* rldimi - rldimi. */
3062 static void gen_rldimi(DisasContext
*ctx
, int mbn
, int shn
)
3064 TCGv t_ra
= cpu_gpr
[rA(ctx
->opcode
)];
3065 TCGv t_rs
= cpu_gpr
[rS(ctx
->opcode
)];
3066 uint32_t sh
= SH(ctx
->opcode
) | (shn
<< 5);
3067 uint32_t mb
= MB(ctx
->opcode
) | (mbn
<< 5);
3068 uint32_t me
= 63 - sh
;
3071 tcg_gen_deposit_tl(t_ra
, t_ra
, t_rs
, sh
, me
- mb
+ 1);
3073 target_ulong mask
= MASK(mb
, me
);
3074 TCGv t1
= tcg_temp_new();
3076 tcg_gen_rotli_tl(t1
, t_rs
, sh
);
3077 tcg_gen_andi_tl(t1
, t1
, mask
);
3078 tcg_gen_andi_tl(t_ra
, t_ra
, ~mask
);
3079 tcg_gen_or_tl(t_ra
, t_ra
, t1
);
3082 if (unlikely(Rc(ctx
->opcode
) != 0)) {
3083 gen_set_Rc0(ctx
, t_ra
);
3086 GEN_PPC64_R4(rldimi
, 0x1E, 0x06);
3089 /*** Integer shift ***/
3092 static void gen_slw(DisasContext
*ctx
)
3096 t0
= tcg_temp_new();
3097 /* AND rS with a mask that is 0 when rB >= 0x20 */
3098 #if defined(TARGET_PPC64)
3099 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
3100 tcg_gen_sari_tl(t0
, t0
, 0x3f);
3102 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
3103 tcg_gen_sari_tl(t0
, t0
, 0x1f);
3105 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3106 t1
= tcg_temp_new();
3107 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
3108 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3111 tcg_gen_ext32u_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
3112 if (unlikely(Rc(ctx
->opcode
) != 0)) {
3113 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
3118 static void gen_sraw(DisasContext
*ctx
)
3120 gen_helper_sraw(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
3121 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
3122 if (unlikely(Rc(ctx
->opcode
) != 0)) {
3123 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
3127 /* srawi & srawi. */
3128 static void gen_srawi(DisasContext
*ctx
)
3130 int sh
= SH(ctx
->opcode
);
3131 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
3132 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
3134 tcg_gen_ext32s_tl(dst
, src
);
3135 tcg_gen_movi_tl(cpu_ca
, 0);
3136 if (is_isa300(ctx
)) {
3137 tcg_gen_movi_tl(cpu_ca32
, 0);
3141 tcg_gen_ext32s_tl(dst
, src
);
3142 tcg_gen_andi_tl(cpu_ca
, dst
, (1ULL << sh
) - 1);
3143 t0
= tcg_temp_new();
3144 tcg_gen_sari_tl(t0
, dst
, TARGET_LONG_BITS
- 1);
3145 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
3147 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
3148 if (is_isa300(ctx
)) {
3149 tcg_gen_mov_tl(cpu_ca32
, cpu_ca
);
3151 tcg_gen_sari_tl(dst
, dst
, sh
);
3153 if (unlikely(Rc(ctx
->opcode
) != 0)) {
3154 gen_set_Rc0(ctx
, dst
);
3159 static void gen_srw(DisasContext
*ctx
)
3163 t0
= tcg_temp_new();
3164 /* AND rS with a mask that is 0 when rB >= 0x20 */
3165 #if defined(TARGET_PPC64)
3166 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x3a);
3167 tcg_gen_sari_tl(t0
, t0
, 0x3f);
3169 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1a);
3170 tcg_gen_sari_tl(t0
, t0
, 0x1f);
3172 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3173 tcg_gen_ext32u_tl(t0
, t0
);
3174 t1
= tcg_temp_new();
3175 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1f);
3176 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3179 if (unlikely(Rc(ctx
->opcode
) != 0)) {
3180 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
3184 #if defined(TARGET_PPC64)
3186 static void gen_sld(DisasContext
*ctx
)
3190 t0
= tcg_temp_new();
3191 /* AND rS with a mask that is 0 when rB >= 0x40 */
3192 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
3193 tcg_gen_sari_tl(t0
, t0
, 0x3f);
3194 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3195 t1
= tcg_temp_new();
3196 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
3197 tcg_gen_shl_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3200 if (unlikely(Rc(ctx
->opcode
) != 0)) {
3201 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
3206 static void gen_srad(DisasContext
*ctx
)
3208 gen_helper_srad(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
3209 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
3210 if (unlikely(Rc(ctx
->opcode
) != 0)) {
3211 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
3214 /* sradi & sradi. */
3215 static inline void gen_sradi(DisasContext
*ctx
, int n
)
3217 int sh
= SH(ctx
->opcode
) + (n
<< 5);
3218 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
3219 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
3221 tcg_gen_mov_tl(dst
, src
);
3222 tcg_gen_movi_tl(cpu_ca
, 0);
3223 if (is_isa300(ctx
)) {
3224 tcg_gen_movi_tl(cpu_ca32
, 0);
3228 tcg_gen_andi_tl(cpu_ca
, src
, (1ULL << sh
) - 1);
3229 t0
= tcg_temp_new();
3230 tcg_gen_sari_tl(t0
, src
, TARGET_LONG_BITS
- 1);
3231 tcg_gen_and_tl(cpu_ca
, cpu_ca
, t0
);
3233 tcg_gen_setcondi_tl(TCG_COND_NE
, cpu_ca
, cpu_ca
, 0);
3234 if (is_isa300(ctx
)) {
3235 tcg_gen_mov_tl(cpu_ca32
, cpu_ca
);
3237 tcg_gen_sari_tl(dst
, src
, sh
);
3239 if (unlikely(Rc(ctx
->opcode
) != 0)) {
3240 gen_set_Rc0(ctx
, dst
);
3244 static void gen_sradi0(DisasContext
*ctx
)
3249 static void gen_sradi1(DisasContext
*ctx
)
3254 /* extswsli & extswsli. */
3255 static inline void gen_extswsli(DisasContext
*ctx
, int n
)
3257 int sh
= SH(ctx
->opcode
) + (n
<< 5);
3258 TCGv dst
= cpu_gpr
[rA(ctx
->opcode
)];
3259 TCGv src
= cpu_gpr
[rS(ctx
->opcode
)];
3261 tcg_gen_ext32s_tl(dst
, src
);
3262 tcg_gen_shli_tl(dst
, dst
, sh
);
3263 if (unlikely(Rc(ctx
->opcode
) != 0)) {
3264 gen_set_Rc0(ctx
, dst
);
3268 static void gen_extswsli0(DisasContext
*ctx
)
3270 gen_extswsli(ctx
, 0);
3273 static void gen_extswsli1(DisasContext
*ctx
)
3275 gen_extswsli(ctx
, 1);
3279 static void gen_srd(DisasContext
*ctx
)
3283 t0
= tcg_temp_new();
3284 /* AND rS with a mask that is 0 when rB >= 0x40 */
3285 tcg_gen_shli_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x39);
3286 tcg_gen_sari_tl(t0
, t0
, 0x3f);
3287 tcg_gen_andc_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
3288 t1
= tcg_temp_new();
3289 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x3f);
3290 tcg_gen_shr_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
3293 if (unlikely(Rc(ctx
->opcode
) != 0)) {
3294 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
3299 /*** Addressing modes ***/
3300 /* Register indirect with immediate index : EA = (rA|0) + SIMM */
3301 static inline void gen_addr_imm_index(DisasContext
*ctx
, TCGv EA
,
3304 target_long simm
= SIMM(ctx
->opcode
);
3307 if (rA(ctx
->opcode
) == 0) {
3308 if (NARROW_MODE(ctx
)) {
3309 simm
= (uint32_t)simm
;
3311 tcg_gen_movi_tl(EA
, simm
);
3312 } else if (likely(simm
!= 0)) {
3313 tcg_gen_addi_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], simm
);
3314 if (NARROW_MODE(ctx
)) {
3315 tcg_gen_ext32u_tl(EA
, EA
);
3318 if (NARROW_MODE(ctx
)) {
3319 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
3321 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
3326 static inline void gen_addr_reg_index(DisasContext
*ctx
, TCGv EA
)
3328 if (rA(ctx
->opcode
) == 0) {
3329 if (NARROW_MODE(ctx
)) {
3330 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
3332 tcg_gen_mov_tl(EA
, cpu_gpr
[rB(ctx
->opcode
)]);
3335 tcg_gen_add_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
3336 if (NARROW_MODE(ctx
)) {
3337 tcg_gen_ext32u_tl(EA
, EA
);
3342 static inline void gen_addr_register(DisasContext
*ctx
, TCGv EA
)
3344 if (rA(ctx
->opcode
) == 0) {
3345 tcg_gen_movi_tl(EA
, 0);
3346 } else if (NARROW_MODE(ctx
)) {
3347 tcg_gen_ext32u_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
3349 tcg_gen_mov_tl(EA
, cpu_gpr
[rA(ctx
->opcode
)]);
3353 static inline void gen_addr_add(DisasContext
*ctx
, TCGv ret
, TCGv arg1
,
3356 tcg_gen_addi_tl(ret
, arg1
, val
);
3357 if (NARROW_MODE(ctx
)) {
3358 tcg_gen_ext32u_tl(ret
, ret
);
3362 static inline void gen_align_no_le(DisasContext
*ctx
)
3364 gen_exception_err(ctx
, POWERPC_EXCP_ALIGN
,
3365 (ctx
->opcode
& 0x03FF0000) | POWERPC_EXCP_ALIGN_LE
);
3368 /*** Integer load ***/
3369 #define DEF_MEMOP(op) ((op) | ctx->default_tcg_memop_mask)
3370 #define BSWAP_MEMOP(op) ((op) | (ctx->default_tcg_memop_mask ^ MO_BSWAP))
3372 #define GEN_QEMU_LOAD_TL(ldop, op) \
3373 static void glue(gen_qemu_, ldop)(DisasContext *ctx, \
3377 tcg_gen_qemu_ld_tl(val, addr, ctx->mem_idx, op); \
3380 GEN_QEMU_LOAD_TL(ld8u
, DEF_MEMOP(MO_UB
))
3381 GEN_QEMU_LOAD_TL(ld16u
, DEF_MEMOP(MO_UW
))
3382 GEN_QEMU_LOAD_TL(ld16s
, DEF_MEMOP(MO_SW
))
3383 GEN_QEMU_LOAD_TL(ld32u
, DEF_MEMOP(MO_UL
))
3384 GEN_QEMU_LOAD_TL(ld32s
, DEF_MEMOP(MO_SL
))
3386 GEN_QEMU_LOAD_TL(ld16ur
, BSWAP_MEMOP(MO_UW
))
3387 GEN_QEMU_LOAD_TL(ld32ur
, BSWAP_MEMOP(MO_UL
))
3389 #define GEN_QEMU_LOAD_64(ldop, op) \
3390 static void glue(gen_qemu_, glue(ldop, _i64))(DisasContext *ctx, \
3394 tcg_gen_qemu_ld_i64(val, addr, ctx->mem_idx, op); \
3397 GEN_QEMU_LOAD_64(ld8u
, DEF_MEMOP(MO_UB
))
3398 GEN_QEMU_LOAD_64(ld16u
, DEF_MEMOP(MO_UW
))
3399 GEN_QEMU_LOAD_64(ld32u
, DEF_MEMOP(MO_UL
))
3400 GEN_QEMU_LOAD_64(ld32s
, DEF_MEMOP(MO_SL
))
3401 GEN_QEMU_LOAD_64(ld64
, DEF_MEMOP(MO_Q
))
3403 #if defined(TARGET_PPC64)
3404 GEN_QEMU_LOAD_64(ld64ur
, BSWAP_MEMOP(MO_Q
))
3407 #define GEN_QEMU_STORE_TL(stop, op) \
3408 static void glue(gen_qemu_, stop)(DisasContext *ctx, \
3412 tcg_gen_qemu_st_tl(val, addr, ctx->mem_idx, op); \
3415 GEN_QEMU_STORE_TL(st8
, DEF_MEMOP(MO_UB
))
3416 GEN_QEMU_STORE_TL(st16
, DEF_MEMOP(MO_UW
))
3417 GEN_QEMU_STORE_TL(st32
, DEF_MEMOP(MO_UL
))
3419 GEN_QEMU_STORE_TL(st16r
, BSWAP_MEMOP(MO_UW
))
3420 GEN_QEMU_STORE_TL(st32r
, BSWAP_MEMOP(MO_UL
))
3422 #define GEN_QEMU_STORE_64(stop, op) \
3423 static void glue(gen_qemu_, glue(stop, _i64))(DisasContext *ctx, \
3427 tcg_gen_qemu_st_i64(val, addr, ctx->mem_idx, op); \
3430 GEN_QEMU_STORE_64(st8
, DEF_MEMOP(MO_UB
))
3431 GEN_QEMU_STORE_64(st16
, DEF_MEMOP(MO_UW
))
3432 GEN_QEMU_STORE_64(st32
, DEF_MEMOP(MO_UL
))
3433 GEN_QEMU_STORE_64(st64
, DEF_MEMOP(MO_Q
))
3435 #if defined(TARGET_PPC64)
3436 GEN_QEMU_STORE_64(st64r
, BSWAP_MEMOP(MO_Q
))
3439 #define GEN_LD(name, ldop, opc, type) \
3440 static void glue(gen_, name)(DisasContext *ctx) \
3443 gen_set_access_type(ctx, ACCESS_INT); \
3444 EA = tcg_temp_new(); \
3445 gen_addr_imm_index(ctx, EA, 0); \
3446 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
3447 tcg_temp_free(EA); \
3450 #define GEN_LDU(name, ldop, opc, type) \
3451 static void glue(gen_, name##u)(DisasContext *ctx) \
3454 if (unlikely(rA(ctx->opcode) == 0 || \
3455 rA(ctx->opcode) == rD(ctx->opcode))) { \
3456 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3459 gen_set_access_type(ctx, ACCESS_INT); \
3460 EA = tcg_temp_new(); \
3461 if (type == PPC_64B) \
3462 gen_addr_imm_index(ctx, EA, 0x03); \
3464 gen_addr_imm_index(ctx, EA, 0); \
3465 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
3466 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3467 tcg_temp_free(EA); \
3470 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
3471 static void glue(gen_, name##ux)(DisasContext *ctx) \
3474 if (unlikely(rA(ctx->opcode) == 0 || \
3475 rA(ctx->opcode) == rD(ctx->opcode))) { \
3476 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3479 gen_set_access_type(ctx, ACCESS_INT); \
3480 EA = tcg_temp_new(); \
3481 gen_addr_reg_index(ctx, EA); \
3482 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
3483 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3484 tcg_temp_free(EA); \
3487 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2, chk) \
3488 static void glue(gen_, name##x)(DisasContext *ctx) \
3492 gen_set_access_type(ctx, ACCESS_INT); \
3493 EA = tcg_temp_new(); \
3494 gen_addr_reg_index(ctx, EA); \
3495 gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \
3496 tcg_temp_free(EA); \
3499 #define GEN_LDX(name, ldop, opc2, opc3, type) \
3500 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE, CHK_NONE)
3502 #define GEN_LDX_HVRM(name, ldop, opc2, opc3, type) \
3503 GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE, CHK_HVRM)
3505 #define GEN_LDS(name, ldop, op, type) \
3506 GEN_LD(name, ldop, op | 0x20, type); \
3507 GEN_LDU(name, ldop, op | 0x21, type); \
3508 GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \
3509 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
3511 /* lbz lbzu lbzux lbzx */
3512 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
);
3513 /* lha lhau lhaux lhax */
3514 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
);
3515 /* lhz lhzu lhzux lhzx */
3516 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
);
3517 /* lwz lwzu lwzux lwzx */
3518 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
);
3520 #define GEN_LDEPX(name, ldop, opc2, opc3) \
3521 static void glue(gen_, name##epx)(DisasContext *ctx) \
3525 gen_set_access_type(ctx, ACCESS_INT); \
3526 EA = tcg_temp_new(); \
3527 gen_addr_reg_index(ctx, EA); \
3528 tcg_gen_qemu_ld_tl(cpu_gpr[rD(ctx->opcode)], EA, PPC_TLB_EPID_LOAD, ldop);\
3529 tcg_temp_free(EA); \
3532 GEN_LDEPX(lb
, DEF_MEMOP(MO_UB
), 0x1F, 0x02)
3533 GEN_LDEPX(lh
, DEF_MEMOP(MO_UW
), 0x1F, 0x08)
3534 GEN_LDEPX(lw
, DEF_MEMOP(MO_UL
), 0x1F, 0x00)
3535 #if defined(TARGET_PPC64)
3536 GEN_LDEPX(ld
, DEF_MEMOP(MO_Q
), 0x1D, 0x00)
3539 #if defined(TARGET_PPC64)
3541 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
);
3543 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
);
3545 GEN_LDUX(ld
, ld64_i64
, 0x15, 0x01, PPC_64B
);
3547 GEN_LDX(ld
, ld64_i64
, 0x15, 0x00, PPC_64B
);
3549 /* CI load/store variants */
3550 GEN_LDX_HVRM(ldcix
, ld64_i64
, 0x15, 0x1b, PPC_CILDST
)
3551 GEN_LDX_HVRM(lwzcix
, ld32u
, 0x15, 0x15, PPC_CILDST
)
3552 GEN_LDX_HVRM(lhzcix
, ld16u
, 0x15, 0x19, PPC_CILDST
)
3553 GEN_LDX_HVRM(lbzcix
, ld8u
, 0x15, 0x1a, PPC_CILDST
)
3555 static void gen_ld(DisasContext
*ctx
)
3558 if (Rc(ctx
->opcode
)) {
3559 if (unlikely(rA(ctx
->opcode
) == 0 ||
3560 rA(ctx
->opcode
) == rD(ctx
->opcode
))) {
3561 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3565 gen_set_access_type(ctx
, ACCESS_INT
);
3566 EA
= tcg_temp_new();
3567 gen_addr_imm_index(ctx
, EA
, 0x03);
3568 if (ctx
->opcode
& 0x02) {
3569 /* lwa (lwau is undefined) */
3570 gen_qemu_ld32s(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
3573 gen_qemu_ld64_i64(ctx
, cpu_gpr
[rD(ctx
->opcode
)], EA
);
3575 if (Rc(ctx
->opcode
)) {
3576 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
3582 static void gen_lq(DisasContext
*ctx
)
3587 /* lq is a legal user mode instruction starting in ISA 2.07 */
3588 bool legal_in_user_mode
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
3589 bool le_is_supported
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
3591 if (!legal_in_user_mode
&& ctx
->pr
) {
3592 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3596 if (!le_is_supported
&& ctx
->le_mode
) {
3597 gen_align_no_le(ctx
);
3600 ra
= rA(ctx
->opcode
);
3601 rd
= rD(ctx
->opcode
);
3602 if (unlikely((rd
& 1) || rd
== ra
)) {
3603 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3607 gen_set_access_type(ctx
, ACCESS_INT
);
3608 EA
= tcg_temp_new();
3609 gen_addr_imm_index(ctx
, EA
, 0x0F);
3611 /* Note that the low part is always in RD+1, even in LE mode. */
3612 lo
= cpu_gpr
[rd
+ 1];
3615 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3616 if (HAVE_ATOMIC128
) {
3617 TCGv_i32 oi
= tcg_temp_new_i32();
3619 tcg_gen_movi_i32(oi
, make_memop_idx(MO_LEQ
, ctx
->mem_idx
));
3620 gen_helper_lq_le_parallel(lo
, cpu_env
, EA
, oi
);
3622 tcg_gen_movi_i32(oi
, make_memop_idx(MO_BEQ
, ctx
->mem_idx
));
3623 gen_helper_lq_be_parallel(lo
, cpu_env
, EA
, oi
);
3625 tcg_temp_free_i32(oi
);
3626 tcg_gen_ld_i64(hi
, cpu_env
, offsetof(CPUPPCState
, retxh
));
3628 /* Restart with exclusive lock. */
3629 gen_helper_exit_atomic(cpu_env
);
3630 ctx
->base
.is_jmp
= DISAS_NORETURN
;
3632 } else if (ctx
->le_mode
) {
3633 tcg_gen_qemu_ld_i64(lo
, EA
, ctx
->mem_idx
, MO_LEQ
);
3634 gen_addr_add(ctx
, EA
, EA
, 8);
3635 tcg_gen_qemu_ld_i64(hi
, EA
, ctx
->mem_idx
, MO_LEQ
);
3637 tcg_gen_qemu_ld_i64(hi
, EA
, ctx
->mem_idx
, MO_BEQ
);
3638 gen_addr_add(ctx
, EA
, EA
, 8);
3639 tcg_gen_qemu_ld_i64(lo
, EA
, ctx
->mem_idx
, MO_BEQ
);
3645 /*** Integer store ***/
3646 #define GEN_ST(name, stop, opc, type) \
3647 static void glue(gen_, name)(DisasContext *ctx) \
3650 gen_set_access_type(ctx, ACCESS_INT); \
3651 EA = tcg_temp_new(); \
3652 gen_addr_imm_index(ctx, EA, 0); \
3653 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
3654 tcg_temp_free(EA); \
3657 #define GEN_STU(name, stop, opc, type) \
3658 static void glue(gen_, stop##u)(DisasContext *ctx) \
3661 if (unlikely(rA(ctx->opcode) == 0)) { \
3662 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3665 gen_set_access_type(ctx, ACCESS_INT); \
3666 EA = tcg_temp_new(); \
3667 if (type == PPC_64B) \
3668 gen_addr_imm_index(ctx, EA, 0x03); \
3670 gen_addr_imm_index(ctx, EA, 0); \
3671 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
3672 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3673 tcg_temp_free(EA); \
3676 #define GEN_STUX(name, stop, opc2, opc3, type) \
3677 static void glue(gen_, name##ux)(DisasContext *ctx) \
3680 if (unlikely(rA(ctx->opcode) == 0)) { \
3681 gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \
3684 gen_set_access_type(ctx, ACCESS_INT); \
3685 EA = tcg_temp_new(); \
3686 gen_addr_reg_index(ctx, EA); \
3687 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
3688 tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \
3689 tcg_temp_free(EA); \
3692 #define GEN_STX_E(name, stop, opc2, opc3, type, type2, chk) \
3693 static void glue(gen_, name##x)(DisasContext *ctx) \
3697 gen_set_access_type(ctx, ACCESS_INT); \
3698 EA = tcg_temp_new(); \
3699 gen_addr_reg_index(ctx, EA); \
3700 gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \
3701 tcg_temp_free(EA); \
3703 #define GEN_STX(name, stop, opc2, opc3, type) \
3704 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE, CHK_NONE)
3706 #define GEN_STX_HVRM(name, stop, opc2, opc3, type) \
3707 GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE, CHK_HVRM)
3709 #define GEN_STS(name, stop, op, type) \
3710 GEN_ST(name, stop, op | 0x20, type); \
3711 GEN_STU(name, stop, op | 0x21, type); \
3712 GEN_STUX(name, stop, 0x17, op | 0x01, type); \
3713 GEN_STX(name, stop, 0x17, op | 0x00, type)
3715 /* stb stbu stbux stbx */
3716 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
);
3717 /* sth sthu sthux sthx */
3718 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
);
3719 /* stw stwu stwux stwx */
3720 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
);
3722 #define GEN_STEPX(name, stop, opc2, opc3) \
3723 static void glue(gen_, name##epx)(DisasContext *ctx) \
3727 gen_set_access_type(ctx, ACCESS_INT); \
3728 EA = tcg_temp_new(); \
3729 gen_addr_reg_index(ctx, EA); \
3730 tcg_gen_qemu_st_tl( \
3731 cpu_gpr[rD(ctx->opcode)], EA, PPC_TLB_EPID_STORE, stop); \
3732 tcg_temp_free(EA); \
3735 GEN_STEPX(stb
, DEF_MEMOP(MO_UB
), 0x1F, 0x06)
3736 GEN_STEPX(sth
, DEF_MEMOP(MO_UW
), 0x1F, 0x0C)
3737 GEN_STEPX(stw
, DEF_MEMOP(MO_UL
), 0x1F, 0x04)
3738 #if defined(TARGET_PPC64)
3739 GEN_STEPX(std
, DEF_MEMOP(MO_Q
), 0x1d, 0x04)
3742 #if defined(TARGET_PPC64)
3743 GEN_STUX(std
, st64_i64
, 0x15, 0x05, PPC_64B
);
3744 GEN_STX(std
, st64_i64
, 0x15, 0x04, PPC_64B
);
3745 GEN_STX_HVRM(stdcix
, st64_i64
, 0x15, 0x1f, PPC_CILDST
)
3746 GEN_STX_HVRM(stwcix
, st32
, 0x15, 0x1c, PPC_CILDST
)
3747 GEN_STX_HVRM(sthcix
, st16
, 0x15, 0x1d, PPC_CILDST
)
3748 GEN_STX_HVRM(stbcix
, st8
, 0x15, 0x1e, PPC_CILDST
)
3750 static void gen_std(DisasContext
*ctx
)
3755 rs
= rS(ctx
->opcode
);
3756 if ((ctx
->opcode
& 0x3) == 0x2) { /* stq */
3757 bool legal_in_user_mode
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
3758 bool le_is_supported
= (ctx
->insns_flags2
& PPC2_LSQ_ISA207
) != 0;
3761 if (!(ctx
->insns_flags
& PPC_64BX
)) {
3762 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3765 if (!legal_in_user_mode
&& ctx
->pr
) {
3766 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_OPC
);
3770 if (!le_is_supported
&& ctx
->le_mode
) {
3771 gen_align_no_le(ctx
);
3775 if (unlikely(rs
& 1)) {
3776 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3779 gen_set_access_type(ctx
, ACCESS_INT
);
3780 EA
= tcg_temp_new();
3781 gen_addr_imm_index(ctx
, EA
, 0x03);
3783 /* Note that the low part is always in RS+1, even in LE mode. */
3784 lo
= cpu_gpr
[rs
+ 1];
3787 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
3788 if (HAVE_ATOMIC128
) {
3789 TCGv_i32 oi
= tcg_temp_new_i32();
3791 tcg_gen_movi_i32(oi
, make_memop_idx(MO_LEQ
, ctx
->mem_idx
));
3792 gen_helper_stq_le_parallel(cpu_env
, EA
, lo
, hi
, oi
);
3794 tcg_gen_movi_i32(oi
, make_memop_idx(MO_BEQ
, ctx
->mem_idx
));
3795 gen_helper_stq_be_parallel(cpu_env
, EA
, lo
, hi
, oi
);
3797 tcg_temp_free_i32(oi
);
3799 /* Restart with exclusive lock. */
3800 gen_helper_exit_atomic(cpu_env
);
3801 ctx
->base
.is_jmp
= DISAS_NORETURN
;
3803 } else if (ctx
->le_mode
) {
3804 tcg_gen_qemu_st_i64(lo
, EA
, ctx
->mem_idx
, MO_LEQ
);
3805 gen_addr_add(ctx
, EA
, EA
, 8);
3806 tcg_gen_qemu_st_i64(hi
, EA
, ctx
->mem_idx
, MO_LEQ
);
3808 tcg_gen_qemu_st_i64(hi
, EA
, ctx
->mem_idx
, MO_BEQ
);
3809 gen_addr_add(ctx
, EA
, EA
, 8);
3810 tcg_gen_qemu_st_i64(lo
, EA
, ctx
->mem_idx
, MO_BEQ
);
3815 if (Rc(ctx
->opcode
)) {
3816 if (unlikely(rA(ctx
->opcode
) == 0)) {
3817 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
3821 gen_set_access_type(ctx
, ACCESS_INT
);
3822 EA
= tcg_temp_new();
3823 gen_addr_imm_index(ctx
, EA
, 0x03);
3824 gen_qemu_st64_i64(ctx
, cpu_gpr
[rs
], EA
);
3825 if (Rc(ctx
->opcode
)) {
3826 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], EA
);
3832 /*** Integer load and store with byte reverse ***/
3835 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
);
3838 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
);
3840 #if defined(TARGET_PPC64)
3842 GEN_LDX_E(ldbr
, ld64ur_i64
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
, CHK_NONE
);
3844 GEN_STX_E(stdbr
, st64r_i64
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
, CHK_NONE
);
3845 #endif /* TARGET_PPC64 */
3848 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
);
3850 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
);
3852 /*** Integer load and store multiple ***/
3855 static void gen_lmw(DisasContext
*ctx
)
3861 gen_align_no_le(ctx
);
3864 gen_set_access_type(ctx
, ACCESS_INT
);
3865 t0
= tcg_temp_new();
3866 t1
= tcg_const_i32(rD(ctx
->opcode
));
3867 gen_addr_imm_index(ctx
, t0
, 0);
3868 gen_helper_lmw(cpu_env
, t0
, t1
);
3870 tcg_temp_free_i32(t1
);
3874 static void gen_stmw(DisasContext
*ctx
)
3880 gen_align_no_le(ctx
);
3883 gen_set_access_type(ctx
, ACCESS_INT
);
3884 t0
= tcg_temp_new();
3885 t1
= tcg_const_i32(rS(ctx
->opcode
));
3886 gen_addr_imm_index(ctx
, t0
, 0);
3887 gen_helper_stmw(cpu_env
, t0
, t1
);
3889 tcg_temp_free_i32(t1
);
3892 /*** Integer load and store strings ***/
3896 * PowerPC32 specification says we must generate an exception if rA is
3897 * in the range of registers to be loaded. In an other hand, IBM says
3898 * this is valid, but rA won't be loaded. For now, I'll follow the
3901 static void gen_lswi(DisasContext
*ctx
)
3905 int nb
= NB(ctx
->opcode
);
3906 int start
= rD(ctx
->opcode
);
3907 int ra
= rA(ctx
->opcode
);
3911 gen_align_no_le(ctx
);
3917 nr
= DIV_ROUND_UP(nb
, 4);
3918 if (unlikely(lsw_reg_in_range(start
, nr
, ra
))) {
3919 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_LSWX
);
3922 gen_set_access_type(ctx
, ACCESS_INT
);
3923 t0
= tcg_temp_new();
3924 gen_addr_register(ctx
, t0
);
3925 t1
= tcg_const_i32(nb
);
3926 t2
= tcg_const_i32(start
);
3927 gen_helper_lsw(cpu_env
, t0
, t1
, t2
);
3929 tcg_temp_free_i32(t1
);
3930 tcg_temp_free_i32(t2
);
3934 static void gen_lswx(DisasContext
*ctx
)
3937 TCGv_i32 t1
, t2
, t3
;
3940 gen_align_no_le(ctx
);
3943 gen_set_access_type(ctx
, ACCESS_INT
);
3944 t0
= tcg_temp_new();
3945 gen_addr_reg_index(ctx
, t0
);
3946 t1
= tcg_const_i32(rD(ctx
->opcode
));
3947 t2
= tcg_const_i32(rA(ctx
->opcode
));
3948 t3
= tcg_const_i32(rB(ctx
->opcode
));
3949 gen_helper_lswx(cpu_env
, t0
, t1
, t2
, t3
);
3951 tcg_temp_free_i32(t1
);
3952 tcg_temp_free_i32(t2
);
3953 tcg_temp_free_i32(t3
);
3957 static void gen_stswi(DisasContext
*ctx
)
3961 int nb
= NB(ctx
->opcode
);
3964 gen_align_no_le(ctx
);
3967 gen_set_access_type(ctx
, ACCESS_INT
);
3968 t0
= tcg_temp_new();
3969 gen_addr_register(ctx
, t0
);
3973 t1
= tcg_const_i32(nb
);
3974 t2
= tcg_const_i32(rS(ctx
->opcode
));
3975 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
3977 tcg_temp_free_i32(t1
);
3978 tcg_temp_free_i32(t2
);
3982 static void gen_stswx(DisasContext
*ctx
)
3988 gen_align_no_le(ctx
);
3991 gen_set_access_type(ctx
, ACCESS_INT
);
3992 t0
= tcg_temp_new();
3993 gen_addr_reg_index(ctx
, t0
);
3994 t1
= tcg_temp_new_i32();
3995 tcg_gen_trunc_tl_i32(t1
, cpu_xer
);
3996 tcg_gen_andi_i32(t1
, t1
, 0x7F);
3997 t2
= tcg_const_i32(rS(ctx
->opcode
));
3998 gen_helper_stsw(cpu_env
, t0
, t1
, t2
);
4000 tcg_temp_free_i32(t1
);
4001 tcg_temp_free_i32(t2
);
4004 /*** Memory synchronisation ***/
4006 static void gen_eieio(DisasContext
*ctx
)
4008 TCGBar bar
= TCG_MO_LD_ST
;
4011 * POWER9 has a eieio instruction variant using bit 6 as a hint to
4012 * tell the CPU it is a store-forwarding barrier.
4014 if (ctx
->opcode
& 0x2000000) {
4016 * ISA says that "Reserved fields in instructions are ignored
4017 * by the processor". So ignore the bit 6 on non-POWER9 CPU but
4018 * as this is not an instruction software should be using,
4019 * complain to the user.
4021 if (!(ctx
->insns_flags2
& PPC2_ISA300
)) {
4022 qemu_log_mask(LOG_GUEST_ERROR
, "invalid eieio using bit 6 at @"
4023 TARGET_FMT_lx
"\n", ctx
->cia
);
4029 tcg_gen_mb(bar
| TCG_BAR_SC
);
4032 #if !defined(CONFIG_USER_ONLY)
4033 static inline void gen_check_tlb_flush(DisasContext
*ctx
, bool global
)
4038 if (!ctx
->lazy_tlb_flush
) {
4041 l
= gen_new_label();
4042 t
= tcg_temp_new_i32();
4043 tcg_gen_ld_i32(t
, cpu_env
, offsetof(CPUPPCState
, tlb_need_flush
));
4044 tcg_gen_brcondi_i32(TCG_COND_EQ
, t
, 0, l
);
4046 gen_helper_check_tlb_flush_global(cpu_env
);
4048 gen_helper_check_tlb_flush_local(cpu_env
);
4051 tcg_temp_free_i32(t
);
4054 static inline void gen_check_tlb_flush(DisasContext
*ctx
, bool global
) { }
4058 static void gen_isync(DisasContext
*ctx
)
4061 * We need to check for a pending TLB flush. This can only happen in
4062 * kernel mode however so check MSR_PR
4065 gen_check_tlb_flush(ctx
, false);
4067 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_SC
);
4068 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
4071 #define MEMOP_GET_SIZE(x) (1 << ((x) & MO_SIZE))
4073 static void gen_load_locked(DisasContext
*ctx
, MemOp memop
)
4075 TCGv gpr
= cpu_gpr
[rD(ctx
->opcode
)];
4076 TCGv t0
= tcg_temp_new();
4078 gen_set_access_type(ctx
, ACCESS_RES
);
4079 gen_addr_reg_index(ctx
, t0
);
4080 tcg_gen_qemu_ld_tl(gpr
, t0
, ctx
->mem_idx
, memop
| MO_ALIGN
);
4081 tcg_gen_mov_tl(cpu_reserve
, t0
);
4082 tcg_gen_mov_tl(cpu_reserve_val
, gpr
);
4083 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_LDAQ
);
4087 #define LARX(name, memop) \
4088 static void gen_##name(DisasContext *ctx) \
4090 gen_load_locked(ctx, memop); \
4094 LARX(lbarx
, DEF_MEMOP(MO_UB
))
4095 LARX(lharx
, DEF_MEMOP(MO_UW
))
4096 LARX(lwarx
, DEF_MEMOP(MO_UL
))
4098 static void gen_fetch_inc_conditional(DisasContext
*ctx
, MemOp memop
,
4099 TCGv EA
, TCGCond cond
, int addend
)
4101 TCGv t
= tcg_temp_new();
4102 TCGv t2
= tcg_temp_new();
4103 TCGv u
= tcg_temp_new();
4105 tcg_gen_qemu_ld_tl(t
, EA
, ctx
->mem_idx
, memop
);
4106 tcg_gen_addi_tl(t2
, EA
, MEMOP_GET_SIZE(memop
));
4107 tcg_gen_qemu_ld_tl(t2
, t2
, ctx
->mem_idx
, memop
);
4108 tcg_gen_addi_tl(u
, t
, addend
);
4110 /* E.g. for fetch and increment bounded... */
4111 /* mem(EA,s) = (t != t2 ? u = t + 1 : t) */
4112 tcg_gen_movcond_tl(cond
, u
, t
, t2
, u
, t
);
4113 tcg_gen_qemu_st_tl(u
, EA
, ctx
->mem_idx
, memop
);
4115 /* RT = (t != t2 ? t : u = 1<<(s*8-1)) */
4116 tcg_gen_movi_tl(u
, 1 << (MEMOP_GET_SIZE(memop
) * 8 - 1));
4117 tcg_gen_movcond_tl(cond
, cpu_gpr
[rD(ctx
->opcode
)], t
, t2
, t
, u
);
4124 static void gen_ld_atomic(DisasContext
*ctx
, MemOp memop
)
4126 uint32_t gpr_FC
= FC(ctx
->opcode
);
4127 TCGv EA
= tcg_temp_new();
4128 int rt
= rD(ctx
->opcode
);
4132 gen_addr_register(ctx
, EA
);
4134 src
= cpu_gpr
[(rt
+ 1) & 31];
4136 need_serial
= false;
4139 case 0: /* Fetch and add */
4140 tcg_gen_atomic_fetch_add_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
4142 case 1: /* Fetch and xor */
4143 tcg_gen_atomic_fetch_xor_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
4145 case 2: /* Fetch and or */
4146 tcg_gen_atomic_fetch_or_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
4148 case 3: /* Fetch and 'and' */
4149 tcg_gen_atomic_fetch_and_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
4151 case 4: /* Fetch and max unsigned */
4152 tcg_gen_atomic_fetch_umax_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
4154 case 5: /* Fetch and max signed */
4155 tcg_gen_atomic_fetch_smax_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
4157 case 6: /* Fetch and min unsigned */
4158 tcg_gen_atomic_fetch_umin_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
4160 case 7: /* Fetch and min signed */
4161 tcg_gen_atomic_fetch_smin_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
4164 tcg_gen_atomic_xchg_tl(dst
, EA
, src
, ctx
->mem_idx
, memop
);
4167 case 16: /* Compare and swap not equal */
4168 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
4171 TCGv t0
= tcg_temp_new();
4172 TCGv t1
= tcg_temp_new();
4174 tcg_gen_qemu_ld_tl(t0
, EA
, ctx
->mem_idx
, memop
);
4175 if ((memop
& MO_SIZE
) == MO_64
|| TARGET_LONG_BITS
== 32) {
4176 tcg_gen_mov_tl(t1
, src
);
4178 tcg_gen_ext32u_tl(t1
, src
);
4180 tcg_gen_movcond_tl(TCG_COND_NE
, t1
, t0
, t1
,
4181 cpu_gpr
[(rt
+ 2) & 31], t0
);
4182 tcg_gen_qemu_st_tl(t1
, EA
, ctx
->mem_idx
, memop
);
4183 tcg_gen_mov_tl(dst
, t0
);
4190 case 24: /* Fetch and increment bounded */
4191 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
4194 gen_fetch_inc_conditional(ctx
, memop
, EA
, TCG_COND_NE
, 1);
4197 case 25: /* Fetch and increment equal */
4198 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
4201 gen_fetch_inc_conditional(ctx
, memop
, EA
, TCG_COND_EQ
, 1);
4204 case 28: /* Fetch and decrement bounded */
4205 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
4208 gen_fetch_inc_conditional(ctx
, memop
, EA
, TCG_COND_NE
, -1);
4213 /* invoke data storage error handler */
4214 gen_exception_err(ctx
, POWERPC_EXCP_DSI
, POWERPC_EXCP_INVAL
);
4219 /* Restart with exclusive lock. */
4220 gen_helper_exit_atomic(cpu_env
);
4221 ctx
->base
.is_jmp
= DISAS_NORETURN
;
4225 static void gen_lwat(DisasContext
*ctx
)
4227 gen_ld_atomic(ctx
, DEF_MEMOP(MO_UL
));
4231 static void gen_ldat(DisasContext
*ctx
)
4233 gen_ld_atomic(ctx
, DEF_MEMOP(MO_Q
));
4237 static void gen_st_atomic(DisasContext
*ctx
, MemOp memop
)
4239 uint32_t gpr_FC
= FC(ctx
->opcode
);
4240 TCGv EA
= tcg_temp_new();
4243 gen_addr_register(ctx
, EA
);
4244 src
= cpu_gpr
[rD(ctx
->opcode
)];
4245 discard
= tcg_temp_new();
4249 case 0: /* add and Store */
4250 tcg_gen_atomic_add_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
4252 case 1: /* xor and Store */
4253 tcg_gen_atomic_xor_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
4255 case 2: /* Or and Store */
4256 tcg_gen_atomic_or_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
4258 case 3: /* 'and' and Store */
4259 tcg_gen_atomic_and_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
4261 case 4: /* Store max unsigned */
4262 tcg_gen_atomic_umax_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
4264 case 5: /* Store max signed */
4265 tcg_gen_atomic_smax_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
4267 case 6: /* Store min unsigned */
4268 tcg_gen_atomic_umin_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
4270 case 7: /* Store min signed */
4271 tcg_gen_atomic_smin_fetch_tl(discard
, EA
, src
, ctx
->mem_idx
, memop
);
4273 case 24: /* Store twin */
4274 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
4275 /* Restart with exclusive lock. */
4276 gen_helper_exit_atomic(cpu_env
);
4277 ctx
->base
.is_jmp
= DISAS_NORETURN
;
4279 TCGv t
= tcg_temp_new();
4280 TCGv t2
= tcg_temp_new();
4281 TCGv s
= tcg_temp_new();
4282 TCGv s2
= tcg_temp_new();
4283 TCGv ea_plus_s
= tcg_temp_new();
4285 tcg_gen_qemu_ld_tl(t
, EA
, ctx
->mem_idx
, memop
);
4286 tcg_gen_addi_tl(ea_plus_s
, EA
, MEMOP_GET_SIZE(memop
));
4287 tcg_gen_qemu_ld_tl(t2
, ea_plus_s
, ctx
->mem_idx
, memop
);
4288 tcg_gen_movcond_tl(TCG_COND_EQ
, s
, t
, t2
, src
, t
);
4289 tcg_gen_movcond_tl(TCG_COND_EQ
, s2
, t
, t2
, src
, t2
);
4290 tcg_gen_qemu_st_tl(s
, EA
, ctx
->mem_idx
, memop
);
4291 tcg_gen_qemu_st_tl(s2
, ea_plus_s
, ctx
->mem_idx
, memop
);
4293 tcg_temp_free(ea_plus_s
);
4301 /* invoke data storage error handler */
4302 gen_exception_err(ctx
, POWERPC_EXCP_DSI
, POWERPC_EXCP_INVAL
);
4304 tcg_temp_free(discard
);
4308 static void gen_stwat(DisasContext
*ctx
)
4310 gen_st_atomic(ctx
, DEF_MEMOP(MO_UL
));
4314 static void gen_stdat(DisasContext
*ctx
)
4316 gen_st_atomic(ctx
, DEF_MEMOP(MO_Q
));
4320 static void gen_conditional_store(DisasContext
*ctx
, MemOp memop
)
4322 TCGLabel
*l1
= gen_new_label();
4323 TCGLabel
*l2
= gen_new_label();
4324 TCGv t0
= tcg_temp_new();
4325 int reg
= rS(ctx
->opcode
);
4327 gen_set_access_type(ctx
, ACCESS_RES
);
4328 gen_addr_reg_index(ctx
, t0
);
4329 tcg_gen_brcond_tl(TCG_COND_NE
, t0
, cpu_reserve
, l1
);
4332 t0
= tcg_temp_new();
4333 tcg_gen_atomic_cmpxchg_tl(t0
, cpu_reserve
, cpu_reserve_val
,
4334 cpu_gpr
[reg
], ctx
->mem_idx
,
4335 DEF_MEMOP(memop
) | MO_ALIGN
);
4336 tcg_gen_setcond_tl(TCG_COND_EQ
, t0
, t0
, cpu_reserve_val
);
4337 tcg_gen_shli_tl(t0
, t0
, CRF_EQ_BIT
);
4338 tcg_gen_or_tl(t0
, t0
, cpu_so
);
4339 tcg_gen_trunc_tl_i32(cpu_crf
[0], t0
);
4346 * Address mismatch implies failure. But we still need to provide
4347 * the memory barrier semantics of the instruction.
4349 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_STRL
);
4350 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
4353 tcg_gen_movi_tl(cpu_reserve
, -1);
4356 #define STCX(name, memop) \
4357 static void gen_##name(DisasContext *ctx) \
4359 gen_conditional_store(ctx, memop); \
4362 STCX(stbcx_
, DEF_MEMOP(MO_UB
))
4363 STCX(sthcx_
, DEF_MEMOP(MO_UW
))
4364 STCX(stwcx_
, DEF_MEMOP(MO_UL
))
4366 #if defined(TARGET_PPC64)
4368 LARX(ldarx
, DEF_MEMOP(MO_Q
))
4370 STCX(stdcx_
, DEF_MEMOP(MO_Q
))
4373 static void gen_lqarx(DisasContext
*ctx
)
4375 int rd
= rD(ctx
->opcode
);
4378 if (unlikely((rd
& 1) || (rd
== rA(ctx
->opcode
)) ||
4379 (rd
== rB(ctx
->opcode
)))) {
4380 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
4384 gen_set_access_type(ctx
, ACCESS_RES
);
4385 EA
= tcg_temp_new();
4386 gen_addr_reg_index(ctx
, EA
);
4388 /* Note that the low part is always in RD+1, even in LE mode. */
4389 lo
= cpu_gpr
[rd
+ 1];
4392 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
4393 if (HAVE_ATOMIC128
) {
4394 TCGv_i32 oi
= tcg_temp_new_i32();
4396 tcg_gen_movi_i32(oi
, make_memop_idx(MO_LEQ
| MO_ALIGN_16
,
4398 gen_helper_lq_le_parallel(lo
, cpu_env
, EA
, oi
);
4400 tcg_gen_movi_i32(oi
, make_memop_idx(MO_BEQ
| MO_ALIGN_16
,
4402 gen_helper_lq_be_parallel(lo
, cpu_env
, EA
, oi
);
4404 tcg_temp_free_i32(oi
);
4405 tcg_gen_ld_i64(hi
, cpu_env
, offsetof(CPUPPCState
, retxh
));
4407 /* Restart with exclusive lock. */
4408 gen_helper_exit_atomic(cpu_env
);
4409 ctx
->base
.is_jmp
= DISAS_NORETURN
;
4413 } else if (ctx
->le_mode
) {
4414 tcg_gen_qemu_ld_i64(lo
, EA
, ctx
->mem_idx
, MO_LEQ
| MO_ALIGN_16
);
4415 tcg_gen_mov_tl(cpu_reserve
, EA
);
4416 gen_addr_add(ctx
, EA
, EA
, 8);
4417 tcg_gen_qemu_ld_i64(hi
, EA
, ctx
->mem_idx
, MO_LEQ
);
4419 tcg_gen_qemu_ld_i64(hi
, EA
, ctx
->mem_idx
, MO_BEQ
| MO_ALIGN_16
);
4420 tcg_gen_mov_tl(cpu_reserve
, EA
);
4421 gen_addr_add(ctx
, EA
, EA
, 8);
4422 tcg_gen_qemu_ld_i64(lo
, EA
, ctx
->mem_idx
, MO_BEQ
);
4426 tcg_gen_st_tl(hi
, cpu_env
, offsetof(CPUPPCState
, reserve_val
));
4427 tcg_gen_st_tl(lo
, cpu_env
, offsetof(CPUPPCState
, reserve_val2
));
4431 static void gen_stqcx_(DisasContext
*ctx
)
4433 int rs
= rS(ctx
->opcode
);
4436 if (unlikely(rs
& 1)) {
4437 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
4441 gen_set_access_type(ctx
, ACCESS_RES
);
4442 EA
= tcg_temp_new();
4443 gen_addr_reg_index(ctx
, EA
);
4445 /* Note that the low part is always in RS+1, even in LE mode. */
4446 lo
= cpu_gpr
[rs
+ 1];
4449 if (tb_cflags(ctx
->base
.tb
) & CF_PARALLEL
) {
4450 if (HAVE_CMPXCHG128
) {
4451 TCGv_i32 oi
= tcg_const_i32(DEF_MEMOP(MO_Q
) | MO_ALIGN_16
);
4453 gen_helper_stqcx_le_parallel(cpu_crf
[0], cpu_env
,
4456 gen_helper_stqcx_be_parallel(cpu_crf
[0], cpu_env
,
4459 tcg_temp_free_i32(oi
);
4461 /* Restart with exclusive lock. */
4462 gen_helper_exit_atomic(cpu_env
);
4463 ctx
->base
.is_jmp
= DISAS_NORETURN
;
4467 TCGLabel
*lab_fail
= gen_new_label();
4468 TCGLabel
*lab_over
= gen_new_label();
4469 TCGv_i64 t0
= tcg_temp_new_i64();
4470 TCGv_i64 t1
= tcg_temp_new_i64();
4472 tcg_gen_brcond_tl(TCG_COND_NE
, EA
, cpu_reserve
, lab_fail
);
4475 gen_qemu_ld64_i64(ctx
, t0
, cpu_reserve
);
4476 tcg_gen_ld_i64(t1
, cpu_env
, (ctx
->le_mode
4477 ? offsetof(CPUPPCState
, reserve_val2
)
4478 : offsetof(CPUPPCState
, reserve_val
)));
4479 tcg_gen_brcond_i64(TCG_COND_NE
, t0
, t1
, lab_fail
);
4481 tcg_gen_addi_i64(t0
, cpu_reserve
, 8);
4482 gen_qemu_ld64_i64(ctx
, t0
, t0
);
4483 tcg_gen_ld_i64(t1
, cpu_env
, (ctx
->le_mode
4484 ? offsetof(CPUPPCState
, reserve_val
)
4485 : offsetof(CPUPPCState
, reserve_val2
)));
4486 tcg_gen_brcond_i64(TCG_COND_NE
, t0
, t1
, lab_fail
);
4489 gen_qemu_st64_i64(ctx
, ctx
->le_mode
? lo
: hi
, cpu_reserve
);
4490 tcg_gen_addi_i64(t0
, cpu_reserve
, 8);
4491 gen_qemu_st64_i64(ctx
, ctx
->le_mode
? hi
: lo
, t0
);
4493 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
4494 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], CRF_EQ
);
4495 tcg_gen_br(lab_over
);
4497 gen_set_label(lab_fail
);
4498 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
4500 gen_set_label(lab_over
);
4501 tcg_gen_movi_tl(cpu_reserve
, -1);
4502 tcg_temp_free_i64(t0
);
4503 tcg_temp_free_i64(t1
);
4506 #endif /* defined(TARGET_PPC64) */
4509 static void gen_sync(DisasContext
*ctx
)
4511 uint32_t l
= (ctx
->opcode
>> 21) & 3;
4514 * We may need to check for a pending TLB flush.
4516 * We do this on ptesync (l == 2) on ppc64 and any sync pn ppc32.
4518 * Additionally, this can only happen in kernel mode however so
4519 * check MSR_PR as well.
4521 if (((l
== 2) || !(ctx
->insns_flags
& PPC_64B
)) && !ctx
->pr
) {
4522 gen_check_tlb_flush(ctx
, true);
4524 tcg_gen_mb(TCG_MO_ALL
| TCG_BAR_SC
);
4528 static void gen_wait(DisasContext
*ctx
)
4530 TCGv_i32 t0
= tcg_const_i32(1);
4531 tcg_gen_st_i32(t0
, cpu_env
,
4532 -offsetof(PowerPCCPU
, env
) + offsetof(CPUState
, halted
));
4533 tcg_temp_free_i32(t0
);
4534 /* Stop translation, as the CPU is supposed to sleep from now */
4535 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
4538 #if defined(TARGET_PPC64)
4539 static void gen_doze(DisasContext
*ctx
)
4541 #if defined(CONFIG_USER_ONLY)
4547 t
= tcg_const_i32(PPC_PM_DOZE
);
4548 gen_helper_pminsn(cpu_env
, t
);
4549 tcg_temp_free_i32(t
);
4550 /* Stop translation, as the CPU is supposed to sleep from now */
4551 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
4552 #endif /* defined(CONFIG_USER_ONLY) */
4555 static void gen_nap(DisasContext
*ctx
)
4557 #if defined(CONFIG_USER_ONLY)
4563 t
= tcg_const_i32(PPC_PM_NAP
);
4564 gen_helper_pminsn(cpu_env
, t
);
4565 tcg_temp_free_i32(t
);
4566 /* Stop translation, as the CPU is supposed to sleep from now */
4567 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
4568 #endif /* defined(CONFIG_USER_ONLY) */
4571 static void gen_stop(DisasContext
*ctx
)
4573 #if defined(CONFIG_USER_ONLY)
4579 t
= tcg_const_i32(PPC_PM_STOP
);
4580 gen_helper_pminsn(cpu_env
, t
);
4581 tcg_temp_free_i32(t
);
4582 /* Stop translation, as the CPU is supposed to sleep from now */
4583 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
4584 #endif /* defined(CONFIG_USER_ONLY) */
4587 static void gen_sleep(DisasContext
*ctx
)
4589 #if defined(CONFIG_USER_ONLY)
4595 t
= tcg_const_i32(PPC_PM_SLEEP
);
4596 gen_helper_pminsn(cpu_env
, t
);
4597 tcg_temp_free_i32(t
);
4598 /* Stop translation, as the CPU is supposed to sleep from now */
4599 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
4600 #endif /* defined(CONFIG_USER_ONLY) */
4603 static void gen_rvwinkle(DisasContext
*ctx
)
4605 #if defined(CONFIG_USER_ONLY)
4611 t
= tcg_const_i32(PPC_PM_RVWINKLE
);
4612 gen_helper_pminsn(cpu_env
, t
);
4613 tcg_temp_free_i32(t
);
4614 /* Stop translation, as the CPU is supposed to sleep from now */
4615 gen_exception_nip(ctx
, EXCP_HLT
, ctx
->base
.pc_next
);
4616 #endif /* defined(CONFIG_USER_ONLY) */
4618 #endif /* #if defined(TARGET_PPC64) */
4620 static inline void gen_update_cfar(DisasContext
*ctx
, target_ulong nip
)
4622 #if defined(TARGET_PPC64)
4623 if (ctx
->has_cfar
) {
4624 tcg_gen_movi_tl(cpu_cfar
, nip
);
4629 static inline bool use_goto_tb(DisasContext
*ctx
, target_ulong dest
)
4631 if (unlikely(ctx
->singlestep_enabled
)) {
4635 #ifndef CONFIG_USER_ONLY
4636 return (ctx
->base
.tb
->pc
& TARGET_PAGE_MASK
) == (dest
& TARGET_PAGE_MASK
);
4642 static void gen_lookup_and_goto_ptr(DisasContext
*ctx
)
4644 int sse
= ctx
->singlestep_enabled
;
4645 if (unlikely(sse
)) {
4646 if (sse
& GDBSTUB_SINGLE_STEP
) {
4647 gen_debug_exception(ctx
);
4648 } else if (sse
& (CPU_SINGLE_STEP
| CPU_BRANCH_STEP
)) {
4649 uint32_t excp
= gen_prep_dbgex(ctx
);
4650 gen_exception(ctx
, excp
);
4652 tcg_gen_exit_tb(NULL
, 0);
4655 tcg_gen_lookup_and_goto_ptr();
4660 static void gen_goto_tb(DisasContext
*ctx
, int n
, target_ulong dest
)
4662 if (NARROW_MODE(ctx
)) {
4663 dest
= (uint32_t) dest
;
4665 if (use_goto_tb(ctx
, dest
)) {
4667 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
4668 tcg_gen_exit_tb(ctx
->base
.tb
, n
);
4670 tcg_gen_movi_tl(cpu_nip
, dest
& ~3);
4671 gen_lookup_and_goto_ptr(ctx
);
4675 static inline void gen_setlr(DisasContext
*ctx
, target_ulong nip
)
4677 if (NARROW_MODE(ctx
)) {
4678 nip
= (uint32_t)nip
;
4680 tcg_gen_movi_tl(cpu_lr
, nip
);
4684 static void gen_b(DisasContext
*ctx
)
4686 target_ulong li
, target
;
4688 /* sign extend LI */
4689 li
= LI(ctx
->opcode
);
4690 li
= (li
^ 0x02000000) - 0x02000000;
4691 if (likely(AA(ctx
->opcode
) == 0)) {
4692 target
= ctx
->cia
+ li
;
4696 if (LK(ctx
->opcode
)) {
4697 gen_setlr(ctx
, ctx
->base
.pc_next
);
4699 gen_update_cfar(ctx
, ctx
->cia
);
4700 gen_goto_tb(ctx
, 0, target
);
4701 ctx
->base
.is_jmp
= DISAS_NORETURN
;
4709 static void gen_bcond(DisasContext
*ctx
, int type
)
4711 uint32_t bo
= BO(ctx
->opcode
);
4715 if (type
== BCOND_LR
|| type
== BCOND_CTR
|| type
== BCOND_TAR
) {
4716 target
= tcg_temp_local_new();
4717 if (type
== BCOND_CTR
) {
4718 tcg_gen_mov_tl(target
, cpu_ctr
);
4719 } else if (type
== BCOND_TAR
) {
4720 gen_load_spr(target
, SPR_TAR
);
4722 tcg_gen_mov_tl(target
, cpu_lr
);
4727 if (LK(ctx
->opcode
)) {
4728 gen_setlr(ctx
, ctx
->base
.pc_next
);
4730 l1
= gen_new_label();
4731 if ((bo
& 0x4) == 0) {
4732 /* Decrement and test CTR */
4733 TCGv temp
= tcg_temp_new();
4735 if (type
== BCOND_CTR
) {
4737 * All ISAs up to v3 describe this form of bcctr as invalid but
4738 * some processors, ie. 64-bit server processors compliant with
4739 * arch 2.x, do implement a "test and decrement" logic instead,
4740 * as described in their respective UMs. This logic involves CTR
4741 * to act as both the branch target and a counter, which makes
4742 * it basically useless and thus never used in real code.
4744 * This form was hence chosen to trigger extra micro-architectural
4745 * side-effect on real HW needed for the Spectre v2 workaround.
4746 * It is up to guests that implement such workaround, ie. linux, to
4747 * use this form in a way it just triggers the side-effect without
4748 * doing anything else harmful.
4750 if (unlikely(!is_book3s_arch2x(ctx
))) {
4751 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
4752 tcg_temp_free(temp
);
4753 tcg_temp_free(target
);
4757 if (NARROW_MODE(ctx
)) {
4758 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
4760 tcg_gen_mov_tl(temp
, cpu_ctr
);
4763 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
4765 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
4767 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
4769 tcg_gen_subi_tl(cpu_ctr
, cpu_ctr
, 1);
4770 if (NARROW_MODE(ctx
)) {
4771 tcg_gen_ext32u_tl(temp
, cpu_ctr
);
4773 tcg_gen_mov_tl(temp
, cpu_ctr
);
4776 tcg_gen_brcondi_tl(TCG_COND_NE
, temp
, 0, l1
);
4778 tcg_gen_brcondi_tl(TCG_COND_EQ
, temp
, 0, l1
);
4781 tcg_temp_free(temp
);
4783 if ((bo
& 0x10) == 0) {
4785 uint32_t bi
= BI(ctx
->opcode
);
4786 uint32_t mask
= 0x08 >> (bi
& 0x03);
4787 TCGv_i32 temp
= tcg_temp_new_i32();
4790 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
4791 tcg_gen_brcondi_i32(TCG_COND_EQ
, temp
, 0, l1
);
4793 tcg_gen_andi_i32(temp
, cpu_crf
[bi
>> 2], mask
);
4794 tcg_gen_brcondi_i32(TCG_COND_NE
, temp
, 0, l1
);
4796 tcg_temp_free_i32(temp
);
4798 gen_update_cfar(ctx
, ctx
->cia
);
4799 if (type
== BCOND_IM
) {
4800 target_ulong li
= (target_long
)((int16_t)(BD(ctx
->opcode
)));
4801 if (likely(AA(ctx
->opcode
) == 0)) {
4802 gen_goto_tb(ctx
, 0, ctx
->cia
+ li
);
4804 gen_goto_tb(ctx
, 0, li
);
4807 if (NARROW_MODE(ctx
)) {
4808 tcg_gen_andi_tl(cpu_nip
, target
, (uint32_t)~3);
4810 tcg_gen_andi_tl(cpu_nip
, target
, ~3);
4812 gen_lookup_and_goto_ptr(ctx
);
4813 tcg_temp_free(target
);
4815 if ((bo
& 0x14) != 0x14) {
4816 /* fallthrough case */
4818 gen_goto_tb(ctx
, 1, ctx
->base
.pc_next
);
4820 ctx
->base
.is_jmp
= DISAS_NORETURN
;
4823 static void gen_bc(DisasContext
*ctx
)
4825 gen_bcond(ctx
, BCOND_IM
);
4828 static void gen_bcctr(DisasContext
*ctx
)
4830 gen_bcond(ctx
, BCOND_CTR
);
4833 static void gen_bclr(DisasContext
*ctx
)
4835 gen_bcond(ctx
, BCOND_LR
);
4838 static void gen_bctar(DisasContext
*ctx
)
4840 gen_bcond(ctx
, BCOND_TAR
);
4843 /*** Condition register logical ***/
4844 #define GEN_CRLOGIC(name, tcg_op, opc) \
4845 static void glue(gen_, name)(DisasContext *ctx) \
4850 sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \
4851 t0 = tcg_temp_new_i32(); \
4853 tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \
4855 tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \
4857 tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \
4858 t1 = tcg_temp_new_i32(); \
4859 sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \
4861 tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \
4863 tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \
4865 tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \
4866 tcg_op(t0, t0, t1); \
4867 bitmask = 0x08 >> (crbD(ctx->opcode) & 0x03); \
4868 tcg_gen_andi_i32(t0, t0, bitmask); \
4869 tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \
4870 tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \
4871 tcg_temp_free_i32(t0); \
4872 tcg_temp_free_i32(t1); \
4876 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08);
4878 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04);
4880 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09);
4882 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07);
4884 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01);
4886 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E);
4888 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D);
4890 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06);
4893 static void gen_mcrf(DisasContext
*ctx
)
4895 tcg_gen_mov_i32(cpu_crf
[crfD(ctx
->opcode
)], cpu_crf
[crfS(ctx
->opcode
)]);
4898 /*** System linkage ***/
4900 /* rfi (supervisor only) */
4901 static void gen_rfi(DisasContext
*ctx
)
4903 #if defined(CONFIG_USER_ONLY)
4907 * This instruction doesn't exist anymore on 64-bit server
4908 * processors compliant with arch 2.x
4910 if (is_book3s_arch2x(ctx
)) {
4911 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
4914 /* Restore CPU state */
4916 gen_icount_io_start(ctx
);
4917 gen_update_cfar(ctx
, ctx
->cia
);
4918 gen_helper_rfi(cpu_env
);
4919 ctx
->base
.is_jmp
= DISAS_EXIT
;
4923 #if defined(TARGET_PPC64)
4924 static void gen_rfid(DisasContext
*ctx
)
4926 #if defined(CONFIG_USER_ONLY)
4929 /* Restore CPU state */
4931 gen_icount_io_start(ctx
);
4932 gen_update_cfar(ctx
, ctx
->cia
);
4933 gen_helper_rfid(cpu_env
);
4934 ctx
->base
.is_jmp
= DISAS_EXIT
;
4938 #if !defined(CONFIG_USER_ONLY)
4939 static void gen_rfscv(DisasContext
*ctx
)
4941 #if defined(CONFIG_USER_ONLY)
4944 /* Restore CPU state */
4946 gen_icount_io_start(ctx
);
4947 gen_update_cfar(ctx
, ctx
->cia
);
4948 gen_helper_rfscv(cpu_env
);
4949 ctx
->base
.is_jmp
= DISAS_EXIT
;
4954 static void gen_hrfid(DisasContext
*ctx
)
4956 #if defined(CONFIG_USER_ONLY)
4959 /* Restore CPU state */
4961 gen_helper_hrfid(cpu_env
);
4962 ctx
->base
.is_jmp
= DISAS_EXIT
;
4968 #if defined(CONFIG_USER_ONLY)
4969 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER
4971 #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL
4972 #define POWERPC_SYSCALL_VECTORED POWERPC_EXCP_SYSCALL_VECTORED
4974 static void gen_sc(DisasContext
*ctx
)
4978 lev
= (ctx
->opcode
>> 5) & 0x7F;
4979 gen_exception_err(ctx
, POWERPC_SYSCALL
, lev
);
4982 #if defined(TARGET_PPC64)
4983 #if !defined(CONFIG_USER_ONLY)
4984 static void gen_scv(DisasContext
*ctx
)
4986 uint32_t lev
= (ctx
->opcode
>> 5) & 0x7F;
4988 /* Set the PC back to the faulting instruction. */
4989 gen_update_nip(ctx
, ctx
->cia
);
4990 gen_helper_scv(cpu_env
, tcg_constant_i32(lev
));
4992 ctx
->base
.is_jmp
= DISAS_NORETURN
;
4999 /* Check for unconditional traps (always or never) */
5000 static bool check_unconditional_trap(DisasContext
*ctx
)
5003 if (TO(ctx
->opcode
) == 0) {
5007 if (TO(ctx
->opcode
) == 31) {
5008 gen_exception_err(ctx
, POWERPC_EXCP_PROGRAM
, POWERPC_EXCP_TRAP
);
5015 static void gen_tw(DisasContext
*ctx
)
5019 if (check_unconditional_trap(ctx
)) {
5022 t0
= tcg_const_i32(TO(ctx
->opcode
));
5023 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
5025 tcg_temp_free_i32(t0
);
5029 static void gen_twi(DisasContext
*ctx
)
5034 if (check_unconditional_trap(ctx
)) {
5037 t0
= tcg_const_tl(SIMM(ctx
->opcode
));
5038 t1
= tcg_const_i32(TO(ctx
->opcode
));
5039 gen_helper_tw(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5041 tcg_temp_free_i32(t1
);
5044 #if defined(TARGET_PPC64)
5046 static void gen_td(DisasContext
*ctx
)
5050 if (check_unconditional_trap(ctx
)) {
5053 t0
= tcg_const_i32(TO(ctx
->opcode
));
5054 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
5056 tcg_temp_free_i32(t0
);
5060 static void gen_tdi(DisasContext
*ctx
)
5065 if (check_unconditional_trap(ctx
)) {
5068 t0
= tcg_const_tl(SIMM(ctx
->opcode
));
5069 t1
= tcg_const_i32(TO(ctx
->opcode
));
5070 gen_helper_td(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
5072 tcg_temp_free_i32(t1
);
5076 /*** Processor control ***/
5079 static void gen_mcrxr(DisasContext
*ctx
)
5081 TCGv_i32 t0
= tcg_temp_new_i32();
5082 TCGv_i32 t1
= tcg_temp_new_i32();
5083 TCGv_i32 dst
= cpu_crf
[crfD(ctx
->opcode
)];
5085 tcg_gen_trunc_tl_i32(t0
, cpu_so
);
5086 tcg_gen_trunc_tl_i32(t1
, cpu_ov
);
5087 tcg_gen_trunc_tl_i32(dst
, cpu_ca
);
5088 tcg_gen_shli_i32(t0
, t0
, 3);
5089 tcg_gen_shli_i32(t1
, t1
, 2);
5090 tcg_gen_shli_i32(dst
, dst
, 1);
5091 tcg_gen_or_i32(dst
, dst
, t0
);
5092 tcg_gen_or_i32(dst
, dst
, t1
);
5093 tcg_temp_free_i32(t0
);
5094 tcg_temp_free_i32(t1
);
5096 tcg_gen_movi_tl(cpu_so
, 0);
5097 tcg_gen_movi_tl(cpu_ov
, 0);
5098 tcg_gen_movi_tl(cpu_ca
, 0);
5103 static void gen_mcrxrx(DisasContext
*ctx
)
5105 TCGv t0
= tcg_temp_new();
5106 TCGv t1
= tcg_temp_new();
5107 TCGv_i32 dst
= cpu_crf
[crfD(ctx
->opcode
)];
5109 /* copy OV and OV32 */
5110 tcg_gen_shli_tl(t0
, cpu_ov
, 1);
5111 tcg_gen_or_tl(t0
, t0
, cpu_ov32
);
5112 tcg_gen_shli_tl(t0
, t0
, 2);
5113 /* copy CA and CA32 */
5114 tcg_gen_shli_tl(t1
, cpu_ca
, 1);
5115 tcg_gen_or_tl(t1
, t1
, cpu_ca32
);
5116 tcg_gen_or_tl(t0
, t0
, t1
);
5117 tcg_gen_trunc_tl_i32(dst
, t0
);
5124 static void gen_mfcr(DisasContext
*ctx
)
5128 if (likely(ctx
->opcode
& 0x00100000)) {
5129 crm
= CRM(ctx
->opcode
);
5130 if (likely(crm
&& ((crm
& (crm
- 1)) == 0))) {
5132 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_crf
[7 - crn
]);
5133 tcg_gen_shli_tl(cpu_gpr
[rD(ctx
->opcode
)],
5134 cpu_gpr
[rD(ctx
->opcode
)], crn
* 4);
5137 TCGv_i32 t0
= tcg_temp_new_i32();
5138 tcg_gen_mov_i32(t0
, cpu_crf
[0]);
5139 tcg_gen_shli_i32(t0
, t0
, 4);
5140 tcg_gen_or_i32(t0
, t0
, cpu_crf
[1]);
5141 tcg_gen_shli_i32(t0
, t0
, 4);
5142 tcg_gen_or_i32(t0
, t0
, cpu_crf
[2]);
5143 tcg_gen_shli_i32(t0
, t0
, 4);
5144 tcg_gen_or_i32(t0
, t0
, cpu_crf
[3]);
5145 tcg_gen_shli_i32(t0
, t0
, 4);
5146 tcg_gen_or_i32(t0
, t0
, cpu_crf
[4]);
5147 tcg_gen_shli_i32(t0
, t0
, 4);
5148 tcg_gen_or_i32(t0
, t0
, cpu_crf
[5]);
5149 tcg_gen_shli_i32(t0
, t0
, 4);
5150 tcg_gen_or_i32(t0
, t0
, cpu_crf
[6]);
5151 tcg_gen_shli_i32(t0
, t0
, 4);
5152 tcg_gen_or_i32(t0
, t0
, cpu_crf
[7]);
5153 tcg_gen_extu_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
5154 tcg_temp_free_i32(t0
);
5159 static void gen_mfmsr(DisasContext
*ctx
)
5162 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_msr
);
5166 static inline void gen_op_mfspr(DisasContext
*ctx
)
5168 void (*read_cb
)(DisasContext
*ctx
, int gprn
, int sprn
);
5169 uint32_t sprn
= SPR(ctx
->opcode
);
5171 #if defined(CONFIG_USER_ONLY)
5172 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
5175 read_cb
= ctx
->spr_cb
[sprn
].uea_read
;
5176 } else if (ctx
->hv
) {
5177 read_cb
= ctx
->spr_cb
[sprn
].hea_read
;
5179 read_cb
= ctx
->spr_cb
[sprn
].oea_read
;
5182 if (likely(read_cb
!= NULL
)) {
5183 if (likely(read_cb
!= SPR_NOACCESS
)) {
5184 (*read_cb
)(ctx
, rD(ctx
->opcode
), sprn
);
5186 /* Privilege exception */
5188 * This is a hack to avoid warnings when running Linux:
5189 * this OS breaks the PowerPC virtualisation model,
5190 * allowing userland application to read the PVR
5192 if (sprn
!= SPR_PVR
) {
5193 qemu_log_mask(LOG_GUEST_ERROR
, "Trying to read privileged spr "
5194 "%d (0x%03x) at " TARGET_FMT_lx
"\n", sprn
, sprn
,
5197 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5200 /* ISA 2.07 defines these as no-ops */
5201 if ((ctx
->insns_flags2
& PPC2_ISA207S
) &&
5202 (sprn
>= 808 && sprn
<= 811)) {
5207 qemu_log_mask(LOG_GUEST_ERROR
,
5208 "Trying to read invalid spr %d (0x%03x) at "
5209 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->cia
);
5212 * The behaviour depends on MSR:PR and SPR# bit 0x10, it can
5213 * generate a priv, a hv emu or a no-op
5217 gen_priv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
5220 if (ctx
->pr
|| sprn
== 0 || sprn
== 4 || sprn
== 5 || sprn
== 6) {
5221 gen_hvpriv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
5227 static void gen_mfspr(DisasContext
*ctx
)
5233 static void gen_mftb(DisasContext
*ctx
)
5239 static void gen_mtcrf(DisasContext
*ctx
)
5243 crm
= CRM(ctx
->opcode
);
5244 if (likely((ctx
->opcode
& 0x00100000))) {
5245 if (crm
&& ((crm
& (crm
- 1)) == 0)) {
5246 TCGv_i32 temp
= tcg_temp_new_i32();
5248 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
5249 tcg_gen_shri_i32(temp
, temp
, crn
* 4);
5250 tcg_gen_andi_i32(cpu_crf
[7 - crn
], temp
, 0xf);
5251 tcg_temp_free_i32(temp
);
5254 TCGv_i32 temp
= tcg_temp_new_i32();
5255 tcg_gen_trunc_tl_i32(temp
, cpu_gpr
[rS(ctx
->opcode
)]);
5256 for (crn
= 0 ; crn
< 8 ; crn
++) {
5257 if (crm
& (1 << crn
)) {
5258 tcg_gen_shri_i32(cpu_crf
[7 - crn
], temp
, crn
* 4);
5259 tcg_gen_andi_i32(cpu_crf
[7 - crn
], cpu_crf
[7 - crn
], 0xf);
5262 tcg_temp_free_i32(temp
);
5267 #if defined(TARGET_PPC64)
5268 static void gen_mtmsrd(DisasContext
*ctx
)
5272 #if !defined(CONFIG_USER_ONLY)
5273 gen_icount_io_start(ctx
);
5274 if (ctx
->opcode
& 0x00010000) {
5275 /* L=1 form only updates EE and RI */
5276 TCGv t0
= tcg_temp_new();
5277 TCGv t1
= tcg_temp_new();
5278 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)],
5279 (1 << MSR_RI
) | (1 << MSR_EE
));
5280 tcg_gen_andi_tl(t1
, cpu_msr
,
5281 ~(target_ulong
)((1 << MSR_RI
) | (1 << MSR_EE
)));
5282 tcg_gen_or_tl(t1
, t1
, t0
);
5284 gen_helper_store_msr(cpu_env
, t1
);
5290 * XXX: we need to update nip before the store if we enter
5291 * power saving mode, we will exit the loop directly from
5294 gen_update_nip(ctx
, ctx
->base
.pc_next
);
5295 gen_helper_store_msr(cpu_env
, cpu_gpr
[rS(ctx
->opcode
)]);
5297 /* Must stop the translation as machine state (may have) changed */
5298 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
5299 #endif /* !defined(CONFIG_USER_ONLY) */
5301 #endif /* defined(TARGET_PPC64) */
5303 static void gen_mtmsr(DisasContext
*ctx
)
5307 #if !defined(CONFIG_USER_ONLY)
5308 gen_icount_io_start(ctx
);
5309 if (ctx
->opcode
& 0x00010000) {
5310 /* L=1 form only updates EE and RI */
5311 TCGv t0
= tcg_temp_new();
5312 TCGv t1
= tcg_temp_new();
5313 tcg_gen_andi_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)],
5314 (1 << MSR_RI
) | (1 << MSR_EE
));
5315 tcg_gen_andi_tl(t1
, cpu_msr
,
5316 ~(target_ulong
)((1 << MSR_RI
) | (1 << MSR_EE
)));
5317 tcg_gen_or_tl(t1
, t1
, t0
);
5319 gen_helper_store_msr(cpu_env
, t1
);
5324 TCGv msr
= tcg_temp_new();
5327 * XXX: we need to update nip before the store if we enter
5328 * power saving mode, we will exit the loop directly from
5331 gen_update_nip(ctx
, ctx
->base
.pc_next
);
5332 #if defined(TARGET_PPC64)
5333 tcg_gen_deposit_tl(msr
, cpu_msr
, cpu_gpr
[rS(ctx
->opcode
)], 0, 32);
5335 tcg_gen_mov_tl(msr
, cpu_gpr
[rS(ctx
->opcode
)]);
5337 gen_helper_store_msr(cpu_env
, msr
);
5340 /* Must stop the translation as machine state (may have) changed */
5341 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
5346 static void gen_mtspr(DisasContext
*ctx
)
5348 void (*write_cb
)(DisasContext
*ctx
, int sprn
, int gprn
);
5349 uint32_t sprn
= SPR(ctx
->opcode
);
5351 #if defined(CONFIG_USER_ONLY)
5352 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
5355 write_cb
= ctx
->spr_cb
[sprn
].uea_write
;
5356 } else if (ctx
->hv
) {
5357 write_cb
= ctx
->spr_cb
[sprn
].hea_write
;
5359 write_cb
= ctx
->spr_cb
[sprn
].oea_write
;
5362 if (likely(write_cb
!= NULL
)) {
5363 if (likely(write_cb
!= SPR_NOACCESS
)) {
5364 (*write_cb
)(ctx
, sprn
, rS(ctx
->opcode
));
5366 /* Privilege exception */
5367 qemu_log_mask(LOG_GUEST_ERROR
, "Trying to write privileged spr "
5368 "%d (0x%03x) at " TARGET_FMT_lx
"\n", sprn
, sprn
,
5370 gen_priv_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5373 /* ISA 2.07 defines these as no-ops */
5374 if ((ctx
->insns_flags2
& PPC2_ISA207S
) &&
5375 (sprn
>= 808 && sprn
<= 811)) {
5381 qemu_log_mask(LOG_GUEST_ERROR
,
5382 "Trying to write invalid spr %d (0x%03x) at "
5383 TARGET_FMT_lx
"\n", sprn
, sprn
, ctx
->cia
);
5387 * The behaviour depends on MSR:PR and SPR# bit 0x10, it can
5388 * generate a priv, a hv emu or a no-op
5392 gen_priv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
5395 if (ctx
->pr
|| sprn
== 0) {
5396 gen_hvpriv_exception(ctx
, POWERPC_EXCP_INVAL_SPR
);
5402 #if defined(TARGET_PPC64)
5404 static void gen_setb(DisasContext
*ctx
)
5406 TCGv_i32 t0
= tcg_temp_new_i32();
5407 TCGv_i32 t8
= tcg_temp_new_i32();
5408 TCGv_i32 tm1
= tcg_temp_new_i32();
5409 int crf
= crfS(ctx
->opcode
);
5411 tcg_gen_setcondi_i32(TCG_COND_GEU
, t0
, cpu_crf
[crf
], 4);
5412 tcg_gen_movi_i32(t8
, 8);
5413 tcg_gen_movi_i32(tm1
, -1);
5414 tcg_gen_movcond_i32(TCG_COND_GEU
, t0
, cpu_crf
[crf
], t8
, tm1
, t0
);
5415 tcg_gen_ext_i32_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
5417 tcg_temp_free_i32(t0
);
5418 tcg_temp_free_i32(t8
);
5419 tcg_temp_free_i32(tm1
);
5423 /*** Cache management ***/
5426 static void gen_dcbf(DisasContext
*ctx
)
5428 /* XXX: specification says this is treated as a load by the MMU */
5430 gen_set_access_type(ctx
, ACCESS_CACHE
);
5431 t0
= tcg_temp_new();
5432 gen_addr_reg_index(ctx
, t0
);
5433 gen_qemu_ld8u(ctx
, t0
, t0
);
5437 /* dcbfep (external PID dcbf) */
5438 static void gen_dcbfep(DisasContext
*ctx
)
5440 /* XXX: specification says this is treated as a load by the MMU */
5443 gen_set_access_type(ctx
, ACCESS_CACHE
);
5444 t0
= tcg_temp_new();
5445 gen_addr_reg_index(ctx
, t0
);
5446 tcg_gen_qemu_ld_tl(t0
, t0
, PPC_TLB_EPID_LOAD
, DEF_MEMOP(MO_UB
));
5450 /* dcbi (Supervisor only) */
5451 static void gen_dcbi(DisasContext
*ctx
)
5453 #if defined(CONFIG_USER_ONLY)
5459 EA
= tcg_temp_new();
5460 gen_set_access_type(ctx
, ACCESS_CACHE
);
5461 gen_addr_reg_index(ctx
, EA
);
5462 val
= tcg_temp_new();
5463 /* XXX: specification says this should be treated as a store by the MMU */
5464 gen_qemu_ld8u(ctx
, val
, EA
);
5465 gen_qemu_st8(ctx
, val
, EA
);
5468 #endif /* defined(CONFIG_USER_ONLY) */
5472 static void gen_dcbst(DisasContext
*ctx
)
5474 /* XXX: specification say this is treated as a load by the MMU */
5476 gen_set_access_type(ctx
, ACCESS_CACHE
);
5477 t0
= tcg_temp_new();
5478 gen_addr_reg_index(ctx
, t0
);
5479 gen_qemu_ld8u(ctx
, t0
, t0
);
5483 /* dcbstep (dcbstep External PID version) */
5484 static void gen_dcbstep(DisasContext
*ctx
)
5486 /* XXX: specification say this is treated as a load by the MMU */
5488 gen_set_access_type(ctx
, ACCESS_CACHE
);
5489 t0
= tcg_temp_new();
5490 gen_addr_reg_index(ctx
, t0
);
5491 tcg_gen_qemu_ld_tl(t0
, t0
, PPC_TLB_EPID_LOAD
, DEF_MEMOP(MO_UB
));
5496 static void gen_dcbt(DisasContext
*ctx
)
5499 * interpreted as no-op
5500 * XXX: specification say this is treated as a load by the MMU but
5501 * does not generate any exception
5506 static void gen_dcbtep(DisasContext
*ctx
)
5509 * interpreted as no-op
5510 * XXX: specification say this is treated as a load by the MMU but
5511 * does not generate any exception
5516 static void gen_dcbtst(DisasContext
*ctx
)
5519 * interpreted as no-op
5520 * XXX: specification say this is treated as a load by the MMU but
5521 * does not generate any exception
5526 static void gen_dcbtstep(DisasContext
*ctx
)
5529 * interpreted as no-op
5530 * XXX: specification say this is treated as a load by the MMU but
5531 * does not generate any exception
5536 static void gen_dcbtls(DisasContext
*ctx
)
5538 /* Always fails locking the cache */
5539 TCGv t0
= tcg_temp_new();
5540 gen_load_spr(t0
, SPR_Exxx_L1CSR0
);
5541 tcg_gen_ori_tl(t0
, t0
, L1CSR0_CUL
);
5542 gen_store_spr(SPR_Exxx_L1CSR0
, t0
);
5547 static void gen_dcbz(DisasContext
*ctx
)
5552 gen_set_access_type(ctx
, ACCESS_CACHE
);
5553 tcgv_addr
= tcg_temp_new();
5554 tcgv_op
= tcg_const_i32(ctx
->opcode
& 0x03FF000);
5555 gen_addr_reg_index(ctx
, tcgv_addr
);
5556 gen_helper_dcbz(cpu_env
, tcgv_addr
, tcgv_op
);
5557 tcg_temp_free(tcgv_addr
);
5558 tcg_temp_free_i32(tcgv_op
);
5562 static void gen_dcbzep(DisasContext
*ctx
)
5567 gen_set_access_type(ctx
, ACCESS_CACHE
);
5568 tcgv_addr
= tcg_temp_new();
5569 tcgv_op
= tcg_const_i32(ctx
->opcode
& 0x03FF000);
5570 gen_addr_reg_index(ctx
, tcgv_addr
);
5571 gen_helper_dcbzep(cpu_env
, tcgv_addr
, tcgv_op
);
5572 tcg_temp_free(tcgv_addr
);
5573 tcg_temp_free_i32(tcgv_op
);
5577 static void gen_dst(DisasContext
*ctx
)
5579 if (rA(ctx
->opcode
) == 0) {
5580 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5582 /* interpreted as no-op */
5587 static void gen_dstst(DisasContext
*ctx
)
5589 if (rA(ctx
->opcode
) == 0) {
5590 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
5592 /* interpreted as no-op */
5598 static void gen_dss(DisasContext
*ctx
)
5600 /* interpreted as no-op */
5604 static void gen_icbi(DisasContext
*ctx
)
5607 gen_set_access_type(ctx
, ACCESS_CACHE
);
5608 t0
= tcg_temp_new();
5609 gen_addr_reg_index(ctx
, t0
);
5610 gen_helper_icbi(cpu_env
, t0
);
5615 static void gen_icbiep(DisasContext
*ctx
)
5618 gen_set_access_type(ctx
, ACCESS_CACHE
);
5619 t0
= tcg_temp_new();
5620 gen_addr_reg_index(ctx
, t0
);
5621 gen_helper_icbiep(cpu_env
, t0
);
5627 static void gen_dcba(DisasContext
*ctx
)
5630 * interpreted as no-op
5631 * XXX: specification say this is treated as a store by the MMU
5632 * but does not generate any exception
5636 /*** Segment register manipulation ***/
5637 /* Supervisor only: */
5640 static void gen_mfsr(DisasContext
*ctx
)
5642 #if defined(CONFIG_USER_ONLY)
5648 t0
= tcg_const_tl(SR(ctx
->opcode
));
5649 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5651 #endif /* defined(CONFIG_USER_ONLY) */
5655 static void gen_mfsrin(DisasContext
*ctx
)
5657 #if defined(CONFIG_USER_ONLY)
5663 t0
= tcg_temp_new();
5664 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
5665 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5667 #endif /* defined(CONFIG_USER_ONLY) */
5671 static void gen_mtsr(DisasContext
*ctx
)
5673 #if defined(CONFIG_USER_ONLY)
5679 t0
= tcg_const_tl(SR(ctx
->opcode
));
5680 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
5682 #endif /* defined(CONFIG_USER_ONLY) */
5686 static void gen_mtsrin(DisasContext
*ctx
)
5688 #if defined(CONFIG_USER_ONLY)
5694 t0
= tcg_temp_new();
5695 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
5696 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rD(ctx
->opcode
)]);
5698 #endif /* defined(CONFIG_USER_ONLY) */
5701 #if defined(TARGET_PPC64)
5702 /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */
5705 static void gen_mfsr_64b(DisasContext
*ctx
)
5707 #if defined(CONFIG_USER_ONLY)
5713 t0
= tcg_const_tl(SR(ctx
->opcode
));
5714 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5716 #endif /* defined(CONFIG_USER_ONLY) */
5720 static void gen_mfsrin_64b(DisasContext
*ctx
)
5722 #if defined(CONFIG_USER_ONLY)
5728 t0
= tcg_temp_new();
5729 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
5730 gen_helper_load_sr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
5732 #endif /* defined(CONFIG_USER_ONLY) */
5736 static void gen_mtsr_64b(DisasContext
*ctx
)
5738 #if defined(CONFIG_USER_ONLY)
5744 t0
= tcg_const_tl(SR(ctx
->opcode
));
5745 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
5747 #endif /* defined(CONFIG_USER_ONLY) */
5751 static void gen_mtsrin_64b(DisasContext
*ctx
)
5753 #if defined(CONFIG_USER_ONLY)
5759 t0
= tcg_temp_new();
5760 tcg_gen_extract_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 28, 4);
5761 gen_helper_store_sr(cpu_env
, t0
, cpu_gpr
[rS(ctx
->opcode
)]);
5763 #endif /* defined(CONFIG_USER_ONLY) */
5767 static void gen_slbmte(DisasContext
*ctx
)
5769 #if defined(CONFIG_USER_ONLY)
5774 gen_helper_store_slb(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)],
5775 cpu_gpr
[rS(ctx
->opcode
)]);
5776 #endif /* defined(CONFIG_USER_ONLY) */
5779 static void gen_slbmfee(DisasContext
*ctx
)
5781 #if defined(CONFIG_USER_ONLY)
5786 gen_helper_load_slb_esid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
5787 cpu_gpr
[rB(ctx
->opcode
)]);
5788 #endif /* defined(CONFIG_USER_ONLY) */
5791 static void gen_slbmfev(DisasContext
*ctx
)
5793 #if defined(CONFIG_USER_ONLY)
5798 gen_helper_load_slb_vsid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
5799 cpu_gpr
[rB(ctx
->opcode
)]);
5800 #endif /* defined(CONFIG_USER_ONLY) */
5803 static void gen_slbfee_(DisasContext
*ctx
)
5805 #if defined(CONFIG_USER_ONLY)
5806 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5810 if (unlikely(ctx
->pr
)) {
5811 gen_inval_exception(ctx
, POWERPC_EXCP_PRIV_REG
);
5814 gen_helper_find_slb_vsid(cpu_gpr
[rS(ctx
->opcode
)], cpu_env
,
5815 cpu_gpr
[rB(ctx
->opcode
)]);
5816 l1
= gen_new_label();
5817 l2
= gen_new_label();
5818 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
5819 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rS(ctx
->opcode
)], -1, l1
);
5820 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], CRF_EQ
);
5823 tcg_gen_movi_tl(cpu_gpr
[rS(ctx
->opcode
)], 0);
5827 #endif /* defined(TARGET_PPC64) */
5829 /*** Lookaside buffer management ***/
5830 /* Optional & supervisor only: */
5833 static void gen_tlbia(DisasContext
*ctx
)
5835 #if defined(CONFIG_USER_ONLY)
5840 gen_helper_tlbia(cpu_env
);
5841 #endif /* defined(CONFIG_USER_ONLY) */
5845 static void gen_tlbiel(DisasContext
*ctx
)
5847 #if defined(CONFIG_USER_ONLY)
5852 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5853 #endif /* defined(CONFIG_USER_ONLY) */
5857 static void gen_tlbie(DisasContext
*ctx
)
5859 #if defined(CONFIG_USER_ONLY)
5865 CHK_SV
; /* If gtse is set then tlbie is supervisor privileged */
5867 CHK_HV
; /* Else hypervisor privileged */
5870 if (NARROW_MODE(ctx
)) {
5871 TCGv t0
= tcg_temp_new();
5872 tcg_gen_ext32u_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)]);
5873 gen_helper_tlbie(cpu_env
, t0
);
5876 gen_helper_tlbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5878 t1
= tcg_temp_new_i32();
5879 tcg_gen_ld_i32(t1
, cpu_env
, offsetof(CPUPPCState
, tlb_need_flush
));
5880 tcg_gen_ori_i32(t1
, t1
, TLB_NEED_GLOBAL_FLUSH
);
5881 tcg_gen_st_i32(t1
, cpu_env
, offsetof(CPUPPCState
, tlb_need_flush
));
5882 tcg_temp_free_i32(t1
);
5883 #endif /* defined(CONFIG_USER_ONLY) */
5887 static void gen_tlbsync(DisasContext
*ctx
)
5889 #if defined(CONFIG_USER_ONLY)
5894 CHK_SV
; /* If gtse is set then tlbsync is supervisor privileged */
5896 CHK_HV
; /* Else hypervisor privileged */
5899 /* BookS does both ptesync and tlbsync make tlbsync a nop for server */
5900 if (ctx
->insns_flags
& PPC_BOOKE
) {
5901 gen_check_tlb_flush(ctx
, true);
5903 #endif /* defined(CONFIG_USER_ONLY) */
5906 #if defined(TARGET_PPC64)
5908 static void gen_slbia(DisasContext
*ctx
)
5910 #if defined(CONFIG_USER_ONLY)
5913 uint32_t ih
= (ctx
->opcode
>> 21) & 0x7;
5914 TCGv_i32 t0
= tcg_const_i32(ih
);
5918 gen_helper_slbia(cpu_env
, t0
);
5919 tcg_temp_free_i32(t0
);
5920 #endif /* defined(CONFIG_USER_ONLY) */
5924 static void gen_slbie(DisasContext
*ctx
)
5926 #if defined(CONFIG_USER_ONLY)
5931 gen_helper_slbie(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5932 #endif /* defined(CONFIG_USER_ONLY) */
5936 static void gen_slbieg(DisasContext
*ctx
)
5938 #if defined(CONFIG_USER_ONLY)
5943 gen_helper_slbieg(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
5944 #endif /* defined(CONFIG_USER_ONLY) */
5948 static void gen_slbsync(DisasContext
*ctx
)
5950 #if defined(CONFIG_USER_ONLY)
5954 gen_check_tlb_flush(ctx
, true);
5955 #endif /* defined(CONFIG_USER_ONLY) */
5958 #endif /* defined(TARGET_PPC64) */
5960 /*** External control ***/
5964 static void gen_eciwx(DisasContext
*ctx
)
5967 /* Should check EAR[E] ! */
5968 gen_set_access_type(ctx
, ACCESS_EXT
);
5969 t0
= tcg_temp_new();
5970 gen_addr_reg_index(ctx
, t0
);
5971 tcg_gen_qemu_ld_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, ctx
->mem_idx
,
5972 DEF_MEMOP(MO_UL
| MO_ALIGN
));
5977 static void gen_ecowx(DisasContext
*ctx
)
5980 /* Should check EAR[E] ! */
5981 gen_set_access_type(ctx
, ACCESS_EXT
);
5982 t0
= tcg_temp_new();
5983 gen_addr_reg_index(ctx
, t0
);
5984 tcg_gen_qemu_st_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
, ctx
->mem_idx
,
5985 DEF_MEMOP(MO_UL
| MO_ALIGN
));
5989 /* PowerPC 601 specific instructions */
5992 static void gen_abs(DisasContext
*ctx
)
5994 TCGv d
= cpu_gpr
[rD(ctx
->opcode
)];
5995 TCGv a
= cpu_gpr
[rA(ctx
->opcode
)];
5997 tcg_gen_abs_tl(d
, a
);
5998 if (unlikely(Rc(ctx
->opcode
) != 0)) {
5999 gen_set_Rc0(ctx
, d
);
6004 static void gen_abso(DisasContext
*ctx
)
6006 TCGv d
= cpu_gpr
[rD(ctx
->opcode
)];
6007 TCGv a
= cpu_gpr
[rA(ctx
->opcode
)];
6009 tcg_gen_setcondi_tl(TCG_COND_EQ
, cpu_ov
, a
, 0x80000000);
6010 tcg_gen_abs_tl(d
, a
);
6011 tcg_gen_or_tl(cpu_so
, cpu_so
, cpu_ov
);
6012 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6013 gen_set_Rc0(ctx
, d
);
6018 static void gen_clcs(DisasContext
*ctx
)
6020 TCGv_i32 t0
= tcg_const_i32(rA(ctx
->opcode
));
6021 gen_helper_clcs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
6022 tcg_temp_free_i32(t0
);
6023 /* Rc=1 sets CR0 to an undefined state */
6027 static void gen_div(DisasContext
*ctx
)
6029 gen_helper_div(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6030 cpu_gpr
[rB(ctx
->opcode
)]);
6031 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6032 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
6037 static void gen_divo(DisasContext
*ctx
)
6039 gen_helper_divo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6040 cpu_gpr
[rB(ctx
->opcode
)]);
6041 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6042 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
6047 static void gen_divs(DisasContext
*ctx
)
6049 gen_helper_divs(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
6050 cpu_gpr
[rB(ctx
->opcode
)]);
6051 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6052 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
6056 /* divso - divso. */
6057 static void gen_divso(DisasContext
*ctx
)
6059 gen_helper_divso(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
6060 cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6061 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6062 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
6067 static void gen_doz(DisasContext
*ctx
)
6069 TCGLabel
*l1
= gen_new_label();
6070 TCGLabel
*l2
= gen_new_label();
6071 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)],
6072 cpu_gpr
[rA(ctx
->opcode
)], l1
);
6073 tcg_gen_sub_tl(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)],
6074 cpu_gpr
[rA(ctx
->opcode
)]);
6077 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
6079 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6080 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
6085 static void gen_dozo(DisasContext
*ctx
)
6087 TCGLabel
*l1
= gen_new_label();
6088 TCGLabel
*l2
= gen_new_label();
6089 TCGv t0
= tcg_temp_new();
6090 TCGv t1
= tcg_temp_new();
6091 TCGv t2
= tcg_temp_new();
6092 /* Start with XER OV disabled, the most likely case */
6093 tcg_gen_movi_tl(cpu_ov
, 0);
6094 tcg_gen_brcond_tl(TCG_COND_GE
, cpu_gpr
[rB(ctx
->opcode
)],
6095 cpu_gpr
[rA(ctx
->opcode
)], l1
);
6096 tcg_gen_sub_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6097 tcg_gen_xor_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6098 tcg_gen_xor_tl(t2
, cpu_gpr
[rA(ctx
->opcode
)], t0
);
6099 tcg_gen_andc_tl(t1
, t1
, t2
);
6100 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], t0
);
6101 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
6102 tcg_gen_movi_tl(cpu_ov
, 1);
6103 tcg_gen_movi_tl(cpu_so
, 1);
6106 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
6111 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6112 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
6117 static void gen_dozi(DisasContext
*ctx
)
6119 target_long simm
= SIMM(ctx
->opcode
);
6120 TCGLabel
*l1
= gen_new_label();
6121 TCGLabel
*l2
= gen_new_label();
6122 tcg_gen_brcondi_tl(TCG_COND_LT
, cpu_gpr
[rA(ctx
->opcode
)], simm
, l1
);
6123 tcg_gen_subfi_tl(cpu_gpr
[rD(ctx
->opcode
)], simm
, cpu_gpr
[rA(ctx
->opcode
)]);
6126 tcg_gen_movi_tl(cpu_gpr
[rD(ctx
->opcode
)], 0);
6128 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6129 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
6133 /* lscbx - lscbx. */
6134 static void gen_lscbx(DisasContext
*ctx
)
6136 TCGv t0
= tcg_temp_new();
6137 TCGv_i32 t1
= tcg_const_i32(rD(ctx
->opcode
));
6138 TCGv_i32 t2
= tcg_const_i32(rA(ctx
->opcode
));
6139 TCGv_i32 t3
= tcg_const_i32(rB(ctx
->opcode
));
6141 gen_addr_reg_index(ctx
, t0
);
6142 gen_helper_lscbx(t0
, cpu_env
, t0
, t1
, t2
, t3
);
6143 tcg_temp_free_i32(t1
);
6144 tcg_temp_free_i32(t2
);
6145 tcg_temp_free_i32(t3
);
6146 tcg_gen_andi_tl(cpu_xer
, cpu_xer
, ~0x7F);
6147 tcg_gen_or_tl(cpu_xer
, cpu_xer
, t0
);
6148 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6149 gen_set_Rc0(ctx
, t0
);
6154 /* maskg - maskg. */
6155 static void gen_maskg(DisasContext
*ctx
)
6157 TCGLabel
*l1
= gen_new_label();
6158 TCGv t0
= tcg_temp_new();
6159 TCGv t1
= tcg_temp_new();
6160 TCGv t2
= tcg_temp_new();
6161 TCGv t3
= tcg_temp_new();
6162 tcg_gen_movi_tl(t3
, 0xFFFFFFFF);
6163 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
6164 tcg_gen_andi_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 0x1F);
6165 tcg_gen_addi_tl(t2
, t0
, 1);
6166 tcg_gen_shr_tl(t2
, t3
, t2
);
6167 tcg_gen_shr_tl(t3
, t3
, t1
);
6168 tcg_gen_xor_tl(cpu_gpr
[rA(ctx
->opcode
)], t2
, t3
);
6169 tcg_gen_brcond_tl(TCG_COND_GE
, t0
, t1
, l1
);
6170 tcg_gen_neg_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6176 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6177 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6181 /* maskir - maskir. */
6182 static void gen_maskir(DisasContext
*ctx
)
6184 TCGv t0
= tcg_temp_new();
6185 TCGv t1
= tcg_temp_new();
6186 tcg_gen_and_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6187 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
6188 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
6191 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6192 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6197 static void gen_mul(DisasContext
*ctx
)
6199 TCGv_i64 t0
= tcg_temp_new_i64();
6200 TCGv_i64 t1
= tcg_temp_new_i64();
6201 TCGv t2
= tcg_temp_new();
6202 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
6203 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
6204 tcg_gen_mul_i64(t0
, t0
, t1
);
6205 tcg_gen_trunc_i64_tl(t2
, t0
);
6206 gen_store_spr(SPR_MQ
, t2
);
6207 tcg_gen_shri_i64(t1
, t0
, 32);
6208 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
6209 tcg_temp_free_i64(t0
);
6210 tcg_temp_free_i64(t1
);
6212 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6213 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
6218 static void gen_mulo(DisasContext
*ctx
)
6220 TCGLabel
*l1
= gen_new_label();
6221 TCGv_i64 t0
= tcg_temp_new_i64();
6222 TCGv_i64 t1
= tcg_temp_new_i64();
6223 TCGv t2
= tcg_temp_new();
6224 /* Start with XER OV disabled, the most likely case */
6225 tcg_gen_movi_tl(cpu_ov
, 0);
6226 tcg_gen_extu_tl_i64(t0
, cpu_gpr
[rA(ctx
->opcode
)]);
6227 tcg_gen_extu_tl_i64(t1
, cpu_gpr
[rB(ctx
->opcode
)]);
6228 tcg_gen_mul_i64(t0
, t0
, t1
);
6229 tcg_gen_trunc_i64_tl(t2
, t0
);
6230 gen_store_spr(SPR_MQ
, t2
);
6231 tcg_gen_shri_i64(t1
, t0
, 32);
6232 tcg_gen_trunc_i64_tl(cpu_gpr
[rD(ctx
->opcode
)], t1
);
6233 tcg_gen_ext32s_i64(t1
, t0
);
6234 tcg_gen_brcond_i64(TCG_COND_EQ
, t0
, t1
, l1
);
6235 tcg_gen_movi_tl(cpu_ov
, 1);
6236 tcg_gen_movi_tl(cpu_so
, 1);
6238 tcg_temp_free_i64(t0
);
6239 tcg_temp_free_i64(t1
);
6241 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6242 gen_set_Rc0(ctx
, cpu_gpr
[rD(ctx
->opcode
)]);
6247 static void gen_nabs(DisasContext
*ctx
)
6249 TCGv d
= cpu_gpr
[rD(ctx
->opcode
)];
6250 TCGv a
= cpu_gpr
[rA(ctx
->opcode
)];
6252 tcg_gen_abs_tl(d
, a
);
6253 tcg_gen_neg_tl(d
, d
);
6254 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6255 gen_set_Rc0(ctx
, d
);
6259 /* nabso - nabso. */
6260 static void gen_nabso(DisasContext
*ctx
)
6262 TCGv d
= cpu_gpr
[rD(ctx
->opcode
)];
6263 TCGv a
= cpu_gpr
[rA(ctx
->opcode
)];
6265 tcg_gen_abs_tl(d
, a
);
6266 tcg_gen_neg_tl(d
, d
);
6267 /* nabs never overflows */
6268 tcg_gen_movi_tl(cpu_ov
, 0);
6269 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6270 gen_set_Rc0(ctx
, d
);
6275 static void gen_rlmi(DisasContext
*ctx
)
6277 uint32_t mb
= MB(ctx
->opcode
);
6278 uint32_t me
= ME(ctx
->opcode
);
6279 TCGv t0
= tcg_temp_new();
6280 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
6281 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
6282 tcg_gen_andi_tl(t0
, t0
, MASK(mb
, me
));
6283 tcg_gen_andi_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)],
6285 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], t0
);
6287 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6288 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6293 static void gen_rrib(DisasContext
*ctx
)
6295 TCGv t0
= tcg_temp_new();
6296 TCGv t1
= tcg_temp_new();
6297 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
6298 tcg_gen_movi_tl(t1
, 0x80000000);
6299 tcg_gen_shr_tl(t1
, t1
, t0
);
6300 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
6301 tcg_gen_and_tl(t0
, t0
, t1
);
6302 tcg_gen_andc_tl(t1
, cpu_gpr
[rA(ctx
->opcode
)], t1
);
6303 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
6306 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6307 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6312 static void gen_sle(DisasContext
*ctx
)
6314 TCGv t0
= tcg_temp_new();
6315 TCGv t1
= tcg_temp_new();
6316 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
6317 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
6318 tcg_gen_subfi_tl(t1
, 32, t1
);
6319 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
6320 tcg_gen_or_tl(t1
, t0
, t1
);
6321 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
6322 gen_store_spr(SPR_MQ
, t1
);
6325 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6326 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6331 static void gen_sleq(DisasContext
*ctx
)
6333 TCGv t0
= tcg_temp_new();
6334 TCGv t1
= tcg_temp_new();
6335 TCGv t2
= tcg_temp_new();
6336 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
6337 tcg_gen_movi_tl(t2
, 0xFFFFFFFF);
6338 tcg_gen_shl_tl(t2
, t2
, t0
);
6339 tcg_gen_rotl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
6340 gen_load_spr(t1
, SPR_MQ
);
6341 gen_store_spr(SPR_MQ
, t0
);
6342 tcg_gen_and_tl(t0
, t0
, t2
);
6343 tcg_gen_andc_tl(t1
, t1
, t2
);
6344 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
6348 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6349 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6354 static void gen_sliq(DisasContext
*ctx
)
6356 int sh
= SH(ctx
->opcode
);
6357 TCGv t0
= tcg_temp_new();
6358 TCGv t1
= tcg_temp_new();
6359 tcg_gen_shli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
6360 tcg_gen_shri_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
6361 tcg_gen_or_tl(t1
, t0
, t1
);
6362 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
6363 gen_store_spr(SPR_MQ
, t1
);
6366 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6367 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6371 /* slliq - slliq. */
6372 static void gen_slliq(DisasContext
*ctx
)
6374 int sh
= SH(ctx
->opcode
);
6375 TCGv t0
= tcg_temp_new();
6376 TCGv t1
= tcg_temp_new();
6377 tcg_gen_rotli_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
6378 gen_load_spr(t1
, SPR_MQ
);
6379 gen_store_spr(SPR_MQ
, t0
);
6380 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
<< sh
));
6381 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
<< sh
));
6382 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
6385 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6386 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6391 static void gen_sllq(DisasContext
*ctx
)
6393 TCGLabel
*l1
= gen_new_label();
6394 TCGLabel
*l2
= gen_new_label();
6395 TCGv t0
= tcg_temp_local_new();
6396 TCGv t1
= tcg_temp_local_new();
6397 TCGv t2
= tcg_temp_local_new();
6398 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
6399 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
6400 tcg_gen_shl_tl(t1
, t1
, t2
);
6401 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
6402 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
6403 gen_load_spr(t0
, SPR_MQ
);
6404 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
6407 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
6408 gen_load_spr(t2
, SPR_MQ
);
6409 tcg_gen_andc_tl(t1
, t2
, t1
);
6410 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
6415 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6416 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6421 static void gen_slq(DisasContext
*ctx
)
6423 TCGLabel
*l1
= gen_new_label();
6424 TCGv t0
= tcg_temp_new();
6425 TCGv t1
= tcg_temp_new();
6426 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
6427 tcg_gen_shl_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
6428 tcg_gen_subfi_tl(t1
, 32, t1
);
6429 tcg_gen_shr_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
6430 tcg_gen_or_tl(t1
, t0
, t1
);
6431 gen_store_spr(SPR_MQ
, t1
);
6432 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
6433 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
6434 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
6435 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
6439 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6440 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6444 /* sraiq - sraiq. */
6445 static void gen_sraiq(DisasContext
*ctx
)
6447 int sh
= SH(ctx
->opcode
);
6448 TCGLabel
*l1
= gen_new_label();
6449 TCGv t0
= tcg_temp_new();
6450 TCGv t1
= tcg_temp_new();
6451 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
6452 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
6453 tcg_gen_or_tl(t0
, t0
, t1
);
6454 gen_store_spr(SPR_MQ
, t0
);
6455 tcg_gen_movi_tl(cpu_ca
, 0);
6456 tcg_gen_brcondi_tl(TCG_COND_EQ
, t1
, 0, l1
);
6457 tcg_gen_brcondi_tl(TCG_COND_GE
, cpu_gpr
[rS(ctx
->opcode
)], 0, l1
);
6458 tcg_gen_movi_tl(cpu_ca
, 1);
6460 tcg_gen_sari_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], sh
);
6463 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6464 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6469 static void gen_sraq(DisasContext
*ctx
)
6471 TCGLabel
*l1
= gen_new_label();
6472 TCGLabel
*l2
= gen_new_label();
6473 TCGv t0
= tcg_temp_new();
6474 TCGv t1
= tcg_temp_local_new();
6475 TCGv t2
= tcg_temp_local_new();
6476 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
6477 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
6478 tcg_gen_sar_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
6479 tcg_gen_subfi_tl(t2
, 32, t2
);
6480 tcg_gen_shl_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
6481 tcg_gen_or_tl(t0
, t0
, t2
);
6482 gen_store_spr(SPR_MQ
, t0
);
6483 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
6484 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l1
);
6485 tcg_gen_mov_tl(t2
, cpu_gpr
[rS(ctx
->opcode
)]);
6486 tcg_gen_sari_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 31);
6489 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t1
);
6490 tcg_gen_movi_tl(cpu_ca
, 0);
6491 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l2
);
6492 tcg_gen_brcondi_tl(TCG_COND_EQ
, t2
, 0, l2
);
6493 tcg_gen_movi_tl(cpu_ca
, 1);
6497 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6498 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6503 static void gen_sre(DisasContext
*ctx
)
6505 TCGv t0
= tcg_temp_new();
6506 TCGv t1
= tcg_temp_new();
6507 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
6508 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
6509 tcg_gen_subfi_tl(t1
, 32, t1
);
6510 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
6511 tcg_gen_or_tl(t1
, t0
, t1
);
6512 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
6513 gen_store_spr(SPR_MQ
, t1
);
6516 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6517 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6522 static void gen_srea(DisasContext
*ctx
)
6524 TCGv t0
= tcg_temp_new();
6525 TCGv t1
= tcg_temp_new();
6526 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
6527 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
6528 gen_store_spr(SPR_MQ
, t0
);
6529 tcg_gen_sar_tl(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)], t1
);
6532 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6533 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6538 static void gen_sreq(DisasContext
*ctx
)
6540 TCGv t0
= tcg_temp_new();
6541 TCGv t1
= tcg_temp_new();
6542 TCGv t2
= tcg_temp_new();
6543 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
6544 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
6545 tcg_gen_shr_tl(t1
, t1
, t0
);
6546 tcg_gen_rotr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
6547 gen_load_spr(t2
, SPR_MQ
);
6548 gen_store_spr(SPR_MQ
, t0
);
6549 tcg_gen_and_tl(t0
, t0
, t1
);
6550 tcg_gen_andc_tl(t2
, t2
, t1
);
6551 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
6555 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6556 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6561 static void gen_sriq(DisasContext
*ctx
)
6563 int sh
= SH(ctx
->opcode
);
6564 TCGv t0
= tcg_temp_new();
6565 TCGv t1
= tcg_temp_new();
6566 tcg_gen_shri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
6567 tcg_gen_shli_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], 32 - sh
);
6568 tcg_gen_or_tl(t1
, t0
, t1
);
6569 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
6570 gen_store_spr(SPR_MQ
, t1
);
6573 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6574 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6579 static void gen_srliq(DisasContext
*ctx
)
6581 int sh
= SH(ctx
->opcode
);
6582 TCGv t0
= tcg_temp_new();
6583 TCGv t1
= tcg_temp_new();
6584 tcg_gen_rotri_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], sh
);
6585 gen_load_spr(t1
, SPR_MQ
);
6586 gen_store_spr(SPR_MQ
, t0
);
6587 tcg_gen_andi_tl(t0
, t0
, (0xFFFFFFFFU
>> sh
));
6588 tcg_gen_andi_tl(t1
, t1
, ~(0xFFFFFFFFU
>> sh
));
6589 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
6592 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6593 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6598 static void gen_srlq(DisasContext
*ctx
)
6600 TCGLabel
*l1
= gen_new_label();
6601 TCGLabel
*l2
= gen_new_label();
6602 TCGv t0
= tcg_temp_local_new();
6603 TCGv t1
= tcg_temp_local_new();
6604 TCGv t2
= tcg_temp_local_new();
6605 tcg_gen_andi_tl(t2
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
6606 tcg_gen_movi_tl(t1
, 0xFFFFFFFF);
6607 tcg_gen_shr_tl(t2
, t1
, t2
);
6608 tcg_gen_andi_tl(t0
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
6609 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
6610 gen_load_spr(t0
, SPR_MQ
);
6611 tcg_gen_and_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t2
);
6614 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t2
);
6615 tcg_gen_and_tl(t0
, t0
, t2
);
6616 gen_load_spr(t1
, SPR_MQ
);
6617 tcg_gen_andc_tl(t1
, t1
, t2
);
6618 tcg_gen_or_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
, t1
);
6623 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6624 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6629 static void gen_srq(DisasContext
*ctx
)
6631 TCGLabel
*l1
= gen_new_label();
6632 TCGv t0
= tcg_temp_new();
6633 TCGv t1
= tcg_temp_new();
6634 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x1F);
6635 tcg_gen_shr_tl(t0
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
6636 tcg_gen_subfi_tl(t1
, 32, t1
);
6637 tcg_gen_shl_tl(t1
, cpu_gpr
[rS(ctx
->opcode
)], t1
);
6638 tcg_gen_or_tl(t1
, t0
, t1
);
6639 gen_store_spr(SPR_MQ
, t1
);
6640 tcg_gen_andi_tl(t1
, cpu_gpr
[rB(ctx
->opcode
)], 0x20);
6641 tcg_gen_mov_tl(cpu_gpr
[rA(ctx
->opcode
)], t0
);
6642 tcg_gen_brcondi_tl(TCG_COND_EQ
, t0
, 0, l1
);
6643 tcg_gen_movi_tl(cpu_gpr
[rA(ctx
->opcode
)], 0);
6647 if (unlikely(Rc(ctx
->opcode
) != 0)) {
6648 gen_set_Rc0(ctx
, cpu_gpr
[rA(ctx
->opcode
)]);
6652 /* PowerPC 602 specific instructions */
6655 static void gen_dsa(DisasContext
*ctx
)
6658 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6662 static void gen_esa(DisasContext
*ctx
)
6665 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6669 static void gen_mfrom(DisasContext
*ctx
)
6671 #if defined(CONFIG_USER_ONLY)
6675 gen_helper_602_mfrom(cpu_gpr
[rD(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)]);
6676 #endif /* defined(CONFIG_USER_ONLY) */
6679 /* 602 - 603 - G2 TLB management */
6682 static void gen_tlbld_6xx(DisasContext
*ctx
)
6684 #if defined(CONFIG_USER_ONLY)
6688 gen_helper_6xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6689 #endif /* defined(CONFIG_USER_ONLY) */
6693 static void gen_tlbli_6xx(DisasContext
*ctx
)
6695 #if defined(CONFIG_USER_ONLY)
6699 gen_helper_6xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6700 #endif /* defined(CONFIG_USER_ONLY) */
6703 /* 74xx TLB management */
6706 static void gen_tlbld_74xx(DisasContext
*ctx
)
6708 #if defined(CONFIG_USER_ONLY)
6712 gen_helper_74xx_tlbd(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6713 #endif /* defined(CONFIG_USER_ONLY) */
6717 static void gen_tlbli_74xx(DisasContext
*ctx
)
6719 #if defined(CONFIG_USER_ONLY)
6723 gen_helper_74xx_tlbi(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6724 #endif /* defined(CONFIG_USER_ONLY) */
6727 /* POWER instructions not in PowerPC 601 */
6730 static void gen_clf(DisasContext
*ctx
)
6732 /* Cache line flush: implemented as no-op */
6736 static void gen_cli(DisasContext
*ctx
)
6738 #if defined(CONFIG_USER_ONLY)
6741 /* Cache line invalidate: privileged and treated as no-op */
6743 #endif /* defined(CONFIG_USER_ONLY) */
6747 static void gen_dclst(DisasContext
*ctx
)
6749 /* Data cache line store: treated as no-op */
6752 static void gen_mfsri(DisasContext
*ctx
)
6754 #if defined(CONFIG_USER_ONLY)
6757 int ra
= rA(ctx
->opcode
);
6758 int rd
= rD(ctx
->opcode
);
6762 t0
= tcg_temp_new();
6763 gen_addr_reg_index(ctx
, t0
);
6764 tcg_gen_extract_tl(t0
, t0
, 28, 4);
6765 gen_helper_load_sr(cpu_gpr
[rd
], cpu_env
, t0
);
6767 if (ra
!= 0 && ra
!= rd
) {
6768 tcg_gen_mov_tl(cpu_gpr
[ra
], cpu_gpr
[rd
]);
6770 #endif /* defined(CONFIG_USER_ONLY) */
6773 static void gen_rac(DisasContext
*ctx
)
6775 #if defined(CONFIG_USER_ONLY)
6781 t0
= tcg_temp_new();
6782 gen_addr_reg_index(ctx
, t0
);
6783 gen_helper_rac(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
6785 #endif /* defined(CONFIG_USER_ONLY) */
6788 static void gen_rfsvc(DisasContext
*ctx
)
6790 #if defined(CONFIG_USER_ONLY)
6795 gen_helper_rfsvc(cpu_env
);
6796 ctx
->base
.is_jmp
= DISAS_EXIT
;
6797 #endif /* defined(CONFIG_USER_ONLY) */
6800 /* svc is not implemented for now */
6802 /* BookE specific instructions */
6804 /* XXX: not implemented on 440 ? */
6805 static void gen_mfapidi(DisasContext
*ctx
)
6808 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
6811 /* XXX: not implemented on 440 ? */
6812 static void gen_tlbiva(DisasContext
*ctx
)
6814 #if defined(CONFIG_USER_ONLY)
6820 t0
= tcg_temp_new();
6821 gen_addr_reg_index(ctx
, t0
);
6822 gen_helper_tlbiva(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
6824 #endif /* defined(CONFIG_USER_ONLY) */
6827 /* All 405 MAC instructions are translated here */
6828 static inline void gen_405_mulladd_insn(DisasContext
*ctx
, int opc2
, int opc3
,
6829 int ra
, int rb
, int rt
, int Rc
)
6833 t0
= tcg_temp_local_new();
6834 t1
= tcg_temp_local_new();
6836 switch (opc3
& 0x0D) {
6838 /* macchw - macchw. - macchwo - macchwo. */
6839 /* macchws - macchws. - macchwso - macchwso. */
6840 /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */
6841 /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */
6842 /* mulchw - mulchw. */
6843 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
6844 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
6845 tcg_gen_ext16s_tl(t1
, t1
);
6848 /* macchwu - macchwu. - macchwuo - macchwuo. */
6849 /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */
6850 /* mulchwu - mulchwu. */
6851 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
6852 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
6853 tcg_gen_ext16u_tl(t1
, t1
);
6856 /* machhw - machhw. - machhwo - machhwo. */
6857 /* machhws - machhws. - machhwso - machhwso. */
6858 /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */
6859 /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */
6860 /* mulhhw - mulhhw. */
6861 tcg_gen_sari_tl(t0
, cpu_gpr
[ra
], 16);
6862 tcg_gen_ext16s_tl(t0
, t0
);
6863 tcg_gen_sari_tl(t1
, cpu_gpr
[rb
], 16);
6864 tcg_gen_ext16s_tl(t1
, t1
);
6867 /* machhwu - machhwu. - machhwuo - machhwuo. */
6868 /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */
6869 /* mulhhwu - mulhhwu. */
6870 tcg_gen_shri_tl(t0
, cpu_gpr
[ra
], 16);
6871 tcg_gen_ext16u_tl(t0
, t0
);
6872 tcg_gen_shri_tl(t1
, cpu_gpr
[rb
], 16);
6873 tcg_gen_ext16u_tl(t1
, t1
);
6876 /* maclhw - maclhw. - maclhwo - maclhwo. */
6877 /* maclhws - maclhws. - maclhwso - maclhwso. */
6878 /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */
6879 /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */
6880 /* mullhw - mullhw. */
6881 tcg_gen_ext16s_tl(t0
, cpu_gpr
[ra
]);
6882 tcg_gen_ext16s_tl(t1
, cpu_gpr
[rb
]);
6885 /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */
6886 /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */
6887 /* mullhwu - mullhwu. */
6888 tcg_gen_ext16u_tl(t0
, cpu_gpr
[ra
]);
6889 tcg_gen_ext16u_tl(t1
, cpu_gpr
[rb
]);
6893 /* (n)multiply-and-accumulate (0x0C / 0x0E) */
6894 tcg_gen_mul_tl(t1
, t0
, t1
);
6896 /* nmultiply-and-accumulate (0x0E) */
6897 tcg_gen_sub_tl(t0
, cpu_gpr
[rt
], t1
);
6899 /* multiply-and-accumulate (0x0C) */
6900 tcg_gen_add_tl(t0
, cpu_gpr
[rt
], t1
);
6904 /* Check overflow and/or saturate */
6905 TCGLabel
*l1
= gen_new_label();
6908 /* Start with XER OV disabled, the most likely case */
6909 tcg_gen_movi_tl(cpu_ov
, 0);
6913 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t1
);
6914 tcg_gen_brcondi_tl(TCG_COND_GE
, t1
, 0, l1
);
6915 tcg_gen_xor_tl(t1
, cpu_gpr
[rt
], t0
);
6916 tcg_gen_brcondi_tl(TCG_COND_LT
, t1
, 0, l1
);
6919 tcg_gen_sari_tl(t0
, cpu_gpr
[rt
], 31);
6920 tcg_gen_xori_tl(t0
, t0
, 0x7fffffff);
6924 tcg_gen_brcond_tl(TCG_COND_GEU
, t0
, t1
, l1
);
6927 tcg_gen_movi_tl(t0
, UINT32_MAX
);
6931 /* Check overflow */
6932 tcg_gen_movi_tl(cpu_ov
, 1);
6933 tcg_gen_movi_tl(cpu_so
, 1);
6936 tcg_gen_mov_tl(cpu_gpr
[rt
], t0
);
6939 tcg_gen_mul_tl(cpu_gpr
[rt
], t0
, t1
);
6943 if (unlikely(Rc
) != 0) {
6945 gen_set_Rc0(ctx
, cpu_gpr
[rt
]);
6949 #define GEN_MAC_HANDLER(name, opc2, opc3) \
6950 static void glue(gen_, name)(DisasContext *ctx) \
6952 gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \
6953 rD(ctx->opcode), Rc(ctx->opcode)); \
6956 /* macchw - macchw. */
6957 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05);
6958 /* macchwo - macchwo. */
6959 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15);
6960 /* macchws - macchws. */
6961 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07);
6962 /* macchwso - macchwso. */
6963 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17);
6964 /* macchwsu - macchwsu. */
6965 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06);
6966 /* macchwsuo - macchwsuo. */
6967 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16);
6968 /* macchwu - macchwu. */
6969 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04);
6970 /* macchwuo - macchwuo. */
6971 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14);
6972 /* machhw - machhw. */
6973 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01);
6974 /* machhwo - machhwo. */
6975 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11);
6976 /* machhws - machhws. */
6977 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03);
6978 /* machhwso - machhwso. */
6979 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13);
6980 /* machhwsu - machhwsu. */
6981 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02);
6982 /* machhwsuo - machhwsuo. */
6983 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12);
6984 /* machhwu - machhwu. */
6985 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00);
6986 /* machhwuo - machhwuo. */
6987 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10);
6988 /* maclhw - maclhw. */
6989 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D);
6990 /* maclhwo - maclhwo. */
6991 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D);
6992 /* maclhws - maclhws. */
6993 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F);
6994 /* maclhwso - maclhwso. */
6995 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F);
6996 /* maclhwu - maclhwu. */
6997 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C);
6998 /* maclhwuo - maclhwuo. */
6999 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C);
7000 /* maclhwsu - maclhwsu. */
7001 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E);
7002 /* maclhwsuo - maclhwsuo. */
7003 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E);
7004 /* nmacchw - nmacchw. */
7005 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05);
7006 /* nmacchwo - nmacchwo. */
7007 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15);
7008 /* nmacchws - nmacchws. */
7009 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07);
7010 /* nmacchwso - nmacchwso. */
7011 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17);
7012 /* nmachhw - nmachhw. */
7013 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01);
7014 /* nmachhwo - nmachhwo. */
7015 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11);
7016 /* nmachhws - nmachhws. */
7017 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03);
7018 /* nmachhwso - nmachhwso. */
7019 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13);
7020 /* nmaclhw - nmaclhw. */
7021 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D);
7022 /* nmaclhwo - nmaclhwo. */
7023 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D);
7024 /* nmaclhws - nmaclhws. */
7025 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F);
7026 /* nmaclhwso - nmaclhwso. */
7027 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F);
7029 /* mulchw - mulchw. */
7030 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05);
7031 /* mulchwu - mulchwu. */
7032 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04);
7033 /* mulhhw - mulhhw. */
7034 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01);
7035 /* mulhhwu - mulhhwu. */
7036 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00);
7037 /* mullhw - mullhw. */
7038 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D);
7039 /* mullhwu - mullhwu. */
7040 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C);
7043 static void gen_mfdcr(DisasContext
*ctx
)
7045 #if defined(CONFIG_USER_ONLY)
7051 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
7052 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, dcrn
);
7053 tcg_temp_free(dcrn
);
7054 #endif /* defined(CONFIG_USER_ONLY) */
7058 static void gen_mtdcr(DisasContext
*ctx
)
7060 #if defined(CONFIG_USER_ONLY)
7066 dcrn
= tcg_const_tl(SPR(ctx
->opcode
));
7067 gen_helper_store_dcr(cpu_env
, dcrn
, cpu_gpr
[rS(ctx
->opcode
)]);
7068 tcg_temp_free(dcrn
);
7069 #endif /* defined(CONFIG_USER_ONLY) */
7073 /* XXX: not implemented on 440 ? */
7074 static void gen_mfdcrx(DisasContext
*ctx
)
7076 #if defined(CONFIG_USER_ONLY)
7080 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
7081 cpu_gpr
[rA(ctx
->opcode
)]);
7082 /* Note: Rc update flag set leads to undefined state of Rc0 */
7083 #endif /* defined(CONFIG_USER_ONLY) */
7087 /* XXX: not implemented on 440 ? */
7088 static void gen_mtdcrx(DisasContext
*ctx
)
7090 #if defined(CONFIG_USER_ONLY)
7094 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
7095 cpu_gpr
[rS(ctx
->opcode
)]);
7096 /* Note: Rc update flag set leads to undefined state of Rc0 */
7097 #endif /* defined(CONFIG_USER_ONLY) */
7100 /* mfdcrux (PPC 460) : user-mode access to DCR */
7101 static void gen_mfdcrux(DisasContext
*ctx
)
7103 gen_helper_load_dcr(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
7104 cpu_gpr
[rA(ctx
->opcode
)]);
7105 /* Note: Rc update flag set leads to undefined state of Rc0 */
7108 /* mtdcrux (PPC 460) : user-mode access to DCR */
7109 static void gen_mtdcrux(DisasContext
*ctx
)
7111 gen_helper_store_dcr(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
7112 cpu_gpr
[rS(ctx
->opcode
)]);
7113 /* Note: Rc update flag set leads to undefined state of Rc0 */
7117 static void gen_dccci(DisasContext
*ctx
)
7120 /* interpreted as no-op */
7124 static void gen_dcread(DisasContext
*ctx
)
7126 #if defined(CONFIG_USER_ONLY)
7132 gen_set_access_type(ctx
, ACCESS_CACHE
);
7133 EA
= tcg_temp_new();
7134 gen_addr_reg_index(ctx
, EA
);
7135 val
= tcg_temp_new();
7136 gen_qemu_ld32u(ctx
, val
, EA
);
7138 tcg_gen_mov_tl(cpu_gpr
[rD(ctx
->opcode
)], EA
);
7140 #endif /* defined(CONFIG_USER_ONLY) */
7144 static void gen_icbt_40x(DisasContext
*ctx
)
7147 * interpreted as no-op
7148 * XXX: specification say this is treated as a load by the MMU but
7149 * does not generate any exception
7154 static void gen_iccci(DisasContext
*ctx
)
7157 /* interpreted as no-op */
7161 static void gen_icread(DisasContext
*ctx
)
7164 /* interpreted as no-op */
7167 /* rfci (supervisor only) */
7168 static void gen_rfci_40x(DisasContext
*ctx
)
7170 #if defined(CONFIG_USER_ONLY)
7174 /* Restore CPU state */
7175 gen_helper_40x_rfci(cpu_env
);
7176 ctx
->base
.is_jmp
= DISAS_EXIT
;
7177 #endif /* defined(CONFIG_USER_ONLY) */
7180 static void gen_rfci(DisasContext
*ctx
)
7182 #if defined(CONFIG_USER_ONLY)
7186 /* Restore CPU state */
7187 gen_helper_rfci(cpu_env
);
7188 ctx
->base
.is_jmp
= DISAS_EXIT
;
7189 #endif /* defined(CONFIG_USER_ONLY) */
7192 /* BookE specific */
7194 /* XXX: not implemented on 440 ? */
7195 static void gen_rfdi(DisasContext
*ctx
)
7197 #if defined(CONFIG_USER_ONLY)
7201 /* Restore CPU state */
7202 gen_helper_rfdi(cpu_env
);
7203 ctx
->base
.is_jmp
= DISAS_EXIT
;
7204 #endif /* defined(CONFIG_USER_ONLY) */
7207 /* XXX: not implemented on 440 ? */
7208 static void gen_rfmci(DisasContext
*ctx
)
7210 #if defined(CONFIG_USER_ONLY)
7214 /* Restore CPU state */
7215 gen_helper_rfmci(cpu_env
);
7216 ctx
->base
.is_jmp
= DISAS_EXIT
;
7217 #endif /* defined(CONFIG_USER_ONLY) */
7220 /* TLB management - PowerPC 405 implementation */
7223 static void gen_tlbre_40x(DisasContext
*ctx
)
7225 #if defined(CONFIG_USER_ONLY)
7229 switch (rB(ctx
->opcode
)) {
7231 gen_helper_4xx_tlbre_hi(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
7232 cpu_gpr
[rA(ctx
->opcode
)]);
7235 gen_helper_4xx_tlbre_lo(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
7236 cpu_gpr
[rA(ctx
->opcode
)]);
7239 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
7242 #endif /* defined(CONFIG_USER_ONLY) */
7245 /* tlbsx - tlbsx. */
7246 static void gen_tlbsx_40x(DisasContext
*ctx
)
7248 #if defined(CONFIG_USER_ONLY)
7254 t0
= tcg_temp_new();
7255 gen_addr_reg_index(ctx
, t0
);
7256 gen_helper_4xx_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
7258 if (Rc(ctx
->opcode
)) {
7259 TCGLabel
*l1
= gen_new_label();
7260 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
7261 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
7262 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
7265 #endif /* defined(CONFIG_USER_ONLY) */
7269 static void gen_tlbwe_40x(DisasContext
*ctx
)
7271 #if defined(CONFIG_USER_ONLY)
7276 switch (rB(ctx
->opcode
)) {
7278 gen_helper_4xx_tlbwe_hi(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
7279 cpu_gpr
[rS(ctx
->opcode
)]);
7282 gen_helper_4xx_tlbwe_lo(cpu_env
, cpu_gpr
[rA(ctx
->opcode
)],
7283 cpu_gpr
[rS(ctx
->opcode
)]);
7286 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
7289 #endif /* defined(CONFIG_USER_ONLY) */
7292 /* TLB management - PowerPC 440 implementation */
7295 static void gen_tlbre_440(DisasContext
*ctx
)
7297 #if defined(CONFIG_USER_ONLY)
7302 switch (rB(ctx
->opcode
)) {
7307 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
7308 gen_helper_440_tlbre(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
,
7309 t0
, cpu_gpr
[rA(ctx
->opcode
)]);
7310 tcg_temp_free_i32(t0
);
7314 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
7317 #endif /* defined(CONFIG_USER_ONLY) */
7320 /* tlbsx - tlbsx. */
7321 static void gen_tlbsx_440(DisasContext
*ctx
)
7323 #if defined(CONFIG_USER_ONLY)
7329 t0
= tcg_temp_new();
7330 gen_addr_reg_index(ctx
, t0
);
7331 gen_helper_440_tlbsx(cpu_gpr
[rD(ctx
->opcode
)], cpu_env
, t0
);
7333 if (Rc(ctx
->opcode
)) {
7334 TCGLabel
*l1
= gen_new_label();
7335 tcg_gen_trunc_tl_i32(cpu_crf
[0], cpu_so
);
7336 tcg_gen_brcondi_tl(TCG_COND_EQ
, cpu_gpr
[rD(ctx
->opcode
)], -1, l1
);
7337 tcg_gen_ori_i32(cpu_crf
[0], cpu_crf
[0], 0x02);
7340 #endif /* defined(CONFIG_USER_ONLY) */
7344 static void gen_tlbwe_440(DisasContext
*ctx
)
7346 #if defined(CONFIG_USER_ONLY)
7350 switch (rB(ctx
->opcode
)) {
7355 TCGv_i32 t0
= tcg_const_i32(rB(ctx
->opcode
));
7356 gen_helper_440_tlbwe(cpu_env
, t0
, cpu_gpr
[rA(ctx
->opcode
)],
7357 cpu_gpr
[rS(ctx
->opcode
)]);
7358 tcg_temp_free_i32(t0
);
7362 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
7365 #endif /* defined(CONFIG_USER_ONLY) */
7368 /* TLB management - PowerPC BookE 2.06 implementation */
7371 static void gen_tlbre_booke206(DisasContext
*ctx
)
7373 #if defined(CONFIG_USER_ONLY)
7377 gen_helper_booke206_tlbre(cpu_env
);
7378 #endif /* defined(CONFIG_USER_ONLY) */
7381 /* tlbsx - tlbsx. */
7382 static void gen_tlbsx_booke206(DisasContext
*ctx
)
7384 #if defined(CONFIG_USER_ONLY)
7390 if (rA(ctx
->opcode
)) {
7391 t0
= tcg_temp_new();
7392 tcg_gen_mov_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)]);
7394 t0
= tcg_const_tl(0);
7397 tcg_gen_add_tl(t0
, t0
, cpu_gpr
[rB(ctx
->opcode
)]);
7398 gen_helper_booke206_tlbsx(cpu_env
, t0
);
7400 #endif /* defined(CONFIG_USER_ONLY) */
7404 static void gen_tlbwe_booke206(DisasContext
*ctx
)
7406 #if defined(CONFIG_USER_ONLY)
7410 gen_helper_booke206_tlbwe(cpu_env
);
7411 #endif /* defined(CONFIG_USER_ONLY) */
7414 static void gen_tlbivax_booke206(DisasContext
*ctx
)
7416 #if defined(CONFIG_USER_ONLY)
7422 t0
= tcg_temp_new();
7423 gen_addr_reg_index(ctx
, t0
);
7424 gen_helper_booke206_tlbivax(cpu_env
, t0
);
7426 #endif /* defined(CONFIG_USER_ONLY) */
7429 static void gen_tlbilx_booke206(DisasContext
*ctx
)
7431 #if defined(CONFIG_USER_ONLY)
7437 t0
= tcg_temp_new();
7438 gen_addr_reg_index(ctx
, t0
);
7440 switch ((ctx
->opcode
>> 21) & 0x3) {
7442 gen_helper_booke206_tlbilx0(cpu_env
, t0
);
7445 gen_helper_booke206_tlbilx1(cpu_env
, t0
);
7448 gen_helper_booke206_tlbilx3(cpu_env
, t0
);
7451 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
7456 #endif /* defined(CONFIG_USER_ONLY) */
7461 static void gen_wrtee(DisasContext
*ctx
)
7463 #if defined(CONFIG_USER_ONLY)
7469 t0
= tcg_temp_new();
7470 tcg_gen_andi_tl(t0
, cpu_gpr
[rD(ctx
->opcode
)], (1 << MSR_EE
));
7471 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
7472 tcg_gen_or_tl(cpu_msr
, cpu_msr
, t0
);
7475 * Stop translation to have a chance to raise an exception if we
7476 * just set msr_ee to 1
7478 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
7479 #endif /* defined(CONFIG_USER_ONLY) */
7483 static void gen_wrteei(DisasContext
*ctx
)
7485 #if defined(CONFIG_USER_ONLY)
7489 if (ctx
->opcode
& 0x00008000) {
7490 tcg_gen_ori_tl(cpu_msr
, cpu_msr
, (1 << MSR_EE
));
7491 /* Stop translation to have a chance to raise an exception */
7492 ctx
->base
.is_jmp
= DISAS_EXIT_UPDATE
;
7494 tcg_gen_andi_tl(cpu_msr
, cpu_msr
, ~(1 << MSR_EE
));
7496 #endif /* defined(CONFIG_USER_ONLY) */
7499 /* PowerPC 440 specific instructions */
7502 static void gen_dlmzb(DisasContext
*ctx
)
7504 TCGv_i32 t0
= tcg_const_i32(Rc(ctx
->opcode
));
7505 gen_helper_dlmzb(cpu_gpr
[rA(ctx
->opcode
)], cpu_env
,
7506 cpu_gpr
[rS(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)], t0
);
7507 tcg_temp_free_i32(t0
);
7510 /* mbar replaces eieio on 440 */
7511 static void gen_mbar(DisasContext
*ctx
)
7513 /* interpreted as no-op */
7516 /* msync replaces sync on 440 */
7517 static void gen_msync_4xx(DisasContext
*ctx
)
7519 /* Only e500 seems to treat reserved bits as invalid */
7520 if ((ctx
->insns_flags2
& PPC2_BOOKE206
) &&
7521 (ctx
->opcode
& 0x03FFF801)) {
7522 gen_inval_exception(ctx
, POWERPC_EXCP_INVAL_INVAL
);
7524 /* otherwise interpreted as no-op */
7528 static void gen_icbt_440(DisasContext
*ctx
)
7531 * interpreted as no-op
7532 * XXX: specification say this is treated as a load by the MMU but
7533 * does not generate any exception
7537 /* Embedded.Processor Control */
7539 static void gen_msgclr(DisasContext
*ctx
)
7541 #if defined(CONFIG_USER_ONLY)
7545 if (is_book3s_arch2x(ctx
)) {
7546 gen_helper_book3s_msgclr(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
7548 gen_helper_msgclr(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
7550 #endif /* defined(CONFIG_USER_ONLY) */
7553 static void gen_msgsnd(DisasContext
*ctx
)
7555 #if defined(CONFIG_USER_ONLY)
7559 if (is_book3s_arch2x(ctx
)) {
7560 gen_helper_book3s_msgsnd(cpu_gpr
[rB(ctx
->opcode
)]);
7562 gen_helper_msgsnd(cpu_gpr
[rB(ctx
->opcode
)]);
7564 #endif /* defined(CONFIG_USER_ONLY) */
7567 #if defined(TARGET_PPC64)
7568 static void gen_msgclrp(DisasContext
*ctx
)
7570 #if defined(CONFIG_USER_ONLY)
7574 gen_helper_book3s_msgclrp(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
7575 #endif /* defined(CONFIG_USER_ONLY) */
7578 static void gen_msgsndp(DisasContext
*ctx
)
7580 #if defined(CONFIG_USER_ONLY)
7584 gen_helper_book3s_msgsndp(cpu_env
, cpu_gpr
[rB(ctx
->opcode
)]);
7585 #endif /* defined(CONFIG_USER_ONLY) */
7589 static void gen_msgsync(DisasContext
*ctx
)
7591 #if defined(CONFIG_USER_ONLY)
7595 #endif /* defined(CONFIG_USER_ONLY) */
7596 /* interpreted as no-op */
7599 #if defined(TARGET_PPC64)
7600 static void gen_maddld(DisasContext
*ctx
)
7602 TCGv_i64 t1
= tcg_temp_new_i64();
7604 tcg_gen_mul_i64(t1
, cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rB(ctx
->opcode
)]);
7605 tcg_gen_add_i64(cpu_gpr
[rD(ctx
->opcode
)], t1
, cpu_gpr
[rC(ctx
->opcode
)]);
7606 tcg_temp_free_i64(t1
);
7609 /* maddhd maddhdu */
7610 static void gen_maddhd_maddhdu(DisasContext
*ctx
)
7612 TCGv_i64 lo
= tcg_temp_new_i64();
7613 TCGv_i64 hi
= tcg_temp_new_i64();
7614 TCGv_i64 t1
= tcg_temp_new_i64();
7616 if (Rc(ctx
->opcode
)) {
7617 tcg_gen_mulu2_i64(lo
, hi
, cpu_gpr
[rA(ctx
->opcode
)],
7618 cpu_gpr
[rB(ctx
->opcode
)]);
7619 tcg_gen_movi_i64(t1
, 0);
7621 tcg_gen_muls2_i64(lo
, hi
, cpu_gpr
[rA(ctx
->opcode
)],
7622 cpu_gpr
[rB(ctx
->opcode
)]);
7623 tcg_gen_sari_i64(t1
, cpu_gpr
[rC(ctx
->opcode
)], 63);
7625 tcg_gen_add2_i64(t1
, cpu_gpr
[rD(ctx
->opcode
)], lo
, hi
,
7626 cpu_gpr
[rC(ctx
->opcode
)], t1
);
7627 tcg_temp_free_i64(lo
);
7628 tcg_temp_free_i64(hi
);
7629 tcg_temp_free_i64(t1
);
7631 #endif /* defined(TARGET_PPC64) */
7633 static void gen_tbegin(DisasContext
*ctx
)
7635 if (unlikely(!ctx
->tm_enabled
)) {
7636 gen_exception_err(ctx
, POWERPC_EXCP_FU
, FSCR_IC_TM
);
7639 gen_helper_tbegin(cpu_env
);
7642 #define GEN_TM_NOOP(name) \
7643 static inline void gen_##name(DisasContext *ctx) \
7645 if (unlikely(!ctx->tm_enabled)) { \
7646 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
7650 * Because tbegin always fails in QEMU, these user \
7651 * space instructions all have a simple implementation: \
7653 * CR[0] = 0b0 || MSR[TS] || 0b0 \
7654 * = 0b0 || 0b00 || 0b0 \
7656 tcg_gen_movi_i32(cpu_crf[0], 0); \
7660 GEN_TM_NOOP(tabort
);
7661 GEN_TM_NOOP(tabortwc
);
7662 GEN_TM_NOOP(tabortwci
);
7663 GEN_TM_NOOP(tabortdc
);
7664 GEN_TM_NOOP(tabortdci
);
7667 static inline void gen_cp_abort(DisasContext
*ctx
)
7672 #define GEN_CP_PASTE_NOOP(name) \
7673 static inline void gen_##name(DisasContext *ctx) \
7676 * Generate invalid exception until we have an \
7677 * implementation of the copy paste facility \
7682 GEN_CP_PASTE_NOOP(copy
)
7683 GEN_CP_PASTE_NOOP(paste
)
7685 static void gen_tcheck(DisasContext
*ctx
)
7687 if (unlikely(!ctx
->tm_enabled
)) {
7688 gen_exception_err(ctx
, POWERPC_EXCP_FU
, FSCR_IC_TM
);
7692 * Because tbegin always fails, the tcheck implementation is
7695 * CR[CRF] = TDOOMED || MSR[TS] || 0b0
7696 * = 0b1 || 0b00 || 0b0
7698 tcg_gen_movi_i32(cpu_crf
[crfD(ctx
->opcode
)], 0x8);
7701 #if defined(CONFIG_USER_ONLY)
7702 #define GEN_TM_PRIV_NOOP(name) \
7703 static inline void gen_##name(DisasContext *ctx) \
7705 gen_priv_exception(ctx, POWERPC_EXCP_PRIV_OPC); \
7710 #define GEN_TM_PRIV_NOOP(name) \
7711 static inline void gen_##name(DisasContext *ctx) \
7714 if (unlikely(!ctx->tm_enabled)) { \
7715 gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \
7719 * Because tbegin always fails, the implementation is \
7722 * CR[0] = 0b0 || MSR[TS] || 0b0 \
7723 * = 0b0 || 0b00 | 0b0 \
7725 tcg_gen_movi_i32(cpu_crf[0], 0); \
7730 GEN_TM_PRIV_NOOP(treclaim
);
7731 GEN_TM_PRIV_NOOP(trechkpt
);
7733 static inline void get_fpr(TCGv_i64 dst
, int regno
)
7735 tcg_gen_ld_i64(dst
, cpu_env
, fpr_offset(regno
));
7738 static inline void set_fpr(int regno
, TCGv_i64 src
)
7740 tcg_gen_st_i64(src
, cpu_env
, fpr_offset(regno
));
7743 static inline void get_avr64(TCGv_i64 dst
, int regno
, bool high
)
7745 tcg_gen_ld_i64(dst
, cpu_env
, avr64_offset(regno
, high
));
7748 static inline void set_avr64(int regno
, TCGv_i64 src
, bool high
)
7750 tcg_gen_st_i64(src
, cpu_env
, avr64_offset(regno
, high
));
7753 #include "translate/fp-impl.c.inc"
7755 #include "translate/vmx-impl.c.inc"
7757 #include "translate/vsx-impl.c.inc"
7759 #include "translate/dfp-impl.c.inc"
7761 #include "translate/spe-impl.c.inc"
7763 /* Handles lfdp, lxsd, lxssp */
7764 static void gen_dform39(DisasContext
*ctx
)
7766 switch (ctx
->opcode
& 0x3) {
7768 if (ctx
->insns_flags2
& PPC2_ISA205
) {
7769 return gen_lfdp(ctx
);
7773 if (ctx
->insns_flags2
& PPC2_ISA300
) {
7774 return gen_lxsd(ctx
);
7778 if (ctx
->insns_flags2
& PPC2_ISA300
) {
7779 return gen_lxssp(ctx
);
7783 return gen_invalid(ctx
);
7786 /* handles stfdp, lxv, stxsd, stxssp lxvx */
7787 static void gen_dform3D(DisasContext
*ctx
)
7789 if ((ctx
->opcode
& 3) == 1) { /* DQ-FORM */
7790 switch (ctx
->opcode
& 0x7) {
7792 if (ctx
->insns_flags2
& PPC2_ISA300
) {
7793 return gen_lxv(ctx
);
7797 if (ctx
->insns_flags2
& PPC2_ISA300
) {
7798 return gen_stxv(ctx
);
7802 } else { /* DS-FORM */
7803 switch (ctx
->opcode
& 0x3) {
7805 if (ctx
->insns_flags2
& PPC2_ISA205
) {
7806 return gen_stfdp(ctx
);
7810 if (ctx
->insns_flags2
& PPC2_ISA300
) {
7811 return gen_stxsd(ctx
);
7814 case 3: /* stxssp */
7815 if (ctx
->insns_flags2
& PPC2_ISA300
) {
7816 return gen_stxssp(ctx
);
7821 return gen_invalid(ctx
);
7824 #if defined(TARGET_PPC64)
7826 static void gen_brd(DisasContext
*ctx
)
7828 tcg_gen_bswap64_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
7832 static void gen_brw(DisasContext
*ctx
)
7834 tcg_gen_bswap64_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rS(ctx
->opcode
)]);
7835 tcg_gen_rotli_i64(cpu_gpr
[rA(ctx
->opcode
)], cpu_gpr
[rA(ctx
->opcode
)], 32);
7840 static void gen_brh(DisasContext
*ctx
)
7842 TCGv_i64 t0
= tcg_temp_new_i64();
7843 TCGv_i64 t1
= tcg_temp_new_i64();
7844 TCGv_i64 t2
= tcg_temp_new_i64();
7846 tcg_gen_movi_i64(t0
, 0x00ff00ff00ff00ffull
);
7847 tcg_gen_shri_i64(t1
, cpu_gpr
[rS(ctx
->opcode
)], 8);
7848 tcg_gen_and_i64(t2
, t1
, t0
);
7849 tcg_gen_and_i64(t1
, cpu_gpr
[rS(ctx
->opcode
)], t0
);
7850 tcg_gen_shli_i64(t1
, t1
, 8);
7851 tcg_gen_or_i64(cpu_gpr
[rA(ctx
->opcode
)], t1
, t2
);
7853 tcg_temp_free_i64(t0
);
7854 tcg_temp_free_i64(t1
);
7855 tcg_temp_free_i64(t2
);
7859 static opcode_t opcodes
[] = {
7860 #if defined(TARGET_PPC64)
7861 GEN_HANDLER_E(brd
, 0x1F, 0x1B, 0x05, 0x0000F801, PPC_NONE
, PPC2_ISA310
),
7862 GEN_HANDLER_E(brw
, 0x1F, 0x1B, 0x04, 0x0000F801, PPC_NONE
, PPC2_ISA310
),
7863 GEN_HANDLER_E(brh
, 0x1F, 0x1B, 0x06, 0x0000F801, PPC_NONE
, PPC2_ISA310
),
7865 GEN_HANDLER(invalid
, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE
),
7866 GEN_HANDLER(cmp
, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER
),
7867 GEN_HANDLER(cmpi
, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
7868 GEN_HANDLER(cmpl
, 0x1F, 0x00, 0x01, 0x00400001, PPC_INTEGER
),
7869 GEN_HANDLER(cmpli
, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER
),
7870 #if defined(TARGET_PPC64)
7871 GEN_HANDLER_E(cmpeqb
, 0x1F, 0x00, 0x07, 0x00600000, PPC_NONE
, PPC2_ISA300
),
7873 GEN_HANDLER_E(cmpb
, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE
, PPC2_ISA205
),
7874 GEN_HANDLER_E(cmprb
, 0x1F, 0x00, 0x06, 0x00400001, PPC_NONE
, PPC2_ISA300
),
7875 GEN_HANDLER(isel
, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL
),
7876 GEN_HANDLER(addi
, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7877 GEN_HANDLER(addic
, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7878 GEN_HANDLER2(addic_
, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7879 GEN_HANDLER(addis
, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7880 GEN_HANDLER_E(addpcis
, 0x13, 0x2, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA300
),
7881 GEN_HANDLER(mulhw
, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER
),
7882 GEN_HANDLER(mulhwu
, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER
),
7883 GEN_HANDLER(mullw
, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER
),
7884 GEN_HANDLER(mullwo
, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER
),
7885 GEN_HANDLER(mulli
, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7886 #if defined(TARGET_PPC64)
7887 GEN_HANDLER(mulld
, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B
),
7889 GEN_HANDLER(neg
, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER
),
7890 GEN_HANDLER(nego
, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER
),
7891 GEN_HANDLER(subfic
, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7892 GEN_HANDLER2(andi_
, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7893 GEN_HANDLER2(andis_
, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7894 GEN_HANDLER(cntlzw
, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER
),
7895 GEN_HANDLER_E(cnttzw
, 0x1F, 0x1A, 0x10, 0x00000000, PPC_NONE
, PPC2_ISA300
),
7896 GEN_HANDLER_E(copy
, 0x1F, 0x06, 0x18, 0x03C00001, PPC_NONE
, PPC2_ISA300
),
7897 GEN_HANDLER_E(cp_abort
, 0x1F, 0x06, 0x1A, 0x03FFF801, PPC_NONE
, PPC2_ISA300
),
7898 GEN_HANDLER_E(paste
, 0x1F, 0x06, 0x1C, 0x03C00000, PPC_NONE
, PPC2_ISA300
),
7899 GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER
),
7900 GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER
),
7901 GEN_HANDLER(ori
, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7902 GEN_HANDLER(oris
, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7903 GEN_HANDLER(xori
, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7904 GEN_HANDLER(xoris
, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7905 GEN_HANDLER(popcntb
, 0x1F, 0x1A, 0x03, 0x0000F801, PPC_POPCNTB
),
7906 GEN_HANDLER(popcntw
, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD
),
7907 GEN_HANDLER_E(prtyw
, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
7908 #if defined(TARGET_PPC64)
7909 GEN_HANDLER(popcntd
, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD
),
7910 GEN_HANDLER(cntlzd
, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B
),
7911 GEN_HANDLER_E(cnttzd
, 0x1F, 0x1A, 0x11, 0x00000000, PPC_NONE
, PPC2_ISA300
),
7912 GEN_HANDLER_E(darn
, 0x1F, 0x13, 0x17, 0x001CF801, PPC_NONE
, PPC2_ISA300
),
7913 GEN_HANDLER_E(prtyd
, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE
, PPC2_ISA205
),
7914 GEN_HANDLER_E(bpermd
, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE
, PPC2_PERM_ISA206
),
7916 GEN_HANDLER(rlwimi
, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7917 GEN_HANDLER(rlwinm
, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7918 GEN_HANDLER(rlwnm
, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7919 GEN_HANDLER(slw
, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER
),
7920 GEN_HANDLER(sraw
, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER
),
7921 GEN_HANDLER(srawi
, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER
),
7922 GEN_HANDLER(srw
, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER
),
7923 #if defined(TARGET_PPC64)
7924 GEN_HANDLER(sld
, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B
),
7925 GEN_HANDLER(srad
, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B
),
7926 GEN_HANDLER2(sradi0
, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B
),
7927 GEN_HANDLER2(sradi1
, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B
),
7928 GEN_HANDLER(srd
, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B
),
7929 GEN_HANDLER2_E(extswsli0
, "extswsli", 0x1F, 0x1A, 0x1B, 0x00000000,
7930 PPC_NONE
, PPC2_ISA300
),
7931 GEN_HANDLER2_E(extswsli1
, "extswsli", 0x1F, 0x1B, 0x1B, 0x00000000,
7932 PPC_NONE
, PPC2_ISA300
),
7934 #if defined(TARGET_PPC64)
7935 GEN_HANDLER(ld
, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B
),
7936 GEN_HANDLER(lq
, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX
),
7937 GEN_HANDLER(std
, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B
),
7939 /* handles lfdp, lxsd, lxssp */
7940 GEN_HANDLER_E(dform39
, 0x39, 0xFF, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA205
),
7941 /* handles stfdp, lxv, stxsd, stxssp, stxv */
7942 GEN_HANDLER_E(dform3D
, 0x3D, 0xFF, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA205
),
7943 GEN_HANDLER(lmw
, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7944 GEN_HANDLER(stmw
, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER
),
7945 GEN_HANDLER(lswi
, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING
),
7946 GEN_HANDLER(lswx
, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING
),
7947 GEN_HANDLER(stswi
, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING
),
7948 GEN_HANDLER(stswx
, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING
),
7949 GEN_HANDLER(eieio
, 0x1F, 0x16, 0x1A, 0x01FFF801, PPC_MEM_EIEIO
),
7950 GEN_HANDLER(isync
, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM
),
7951 GEN_HANDLER_E(lbarx
, 0x1F, 0x14, 0x01, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
7952 GEN_HANDLER_E(lharx
, 0x1F, 0x14, 0x03, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
7953 GEN_HANDLER(lwarx
, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES
),
7954 GEN_HANDLER_E(lwat
, 0x1F, 0x06, 0x12, 0x00000001, PPC_NONE
, PPC2_ISA300
),
7955 GEN_HANDLER_E(stwat
, 0x1F, 0x06, 0x16, 0x00000001, PPC_NONE
, PPC2_ISA300
),
7956 GEN_HANDLER_E(stbcx_
, 0x1F, 0x16, 0x15, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
7957 GEN_HANDLER_E(sthcx_
, 0x1F, 0x16, 0x16, 0, PPC_NONE
, PPC2_ATOMIC_ISA206
),
7958 GEN_HANDLER2(stwcx_
, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES
),
7959 #if defined(TARGET_PPC64)
7960 GEN_HANDLER_E(ldat
, 0x1F, 0x06, 0x13, 0x00000001, PPC_NONE
, PPC2_ISA300
),
7961 GEN_HANDLER_E(stdat
, 0x1F, 0x06, 0x17, 0x00000001, PPC_NONE
, PPC2_ISA300
),
7962 GEN_HANDLER(ldarx
, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B
),
7963 GEN_HANDLER_E(lqarx
, 0x1F, 0x14, 0x08, 0, PPC_NONE
, PPC2_LSQ_ISA207
),
7964 GEN_HANDLER2(stdcx_
, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B
),
7965 GEN_HANDLER_E(stqcx_
, 0x1F, 0x16, 0x05, 0, PPC_NONE
, PPC2_LSQ_ISA207
),
7967 GEN_HANDLER(sync
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC
),
7968 GEN_HANDLER(wait
, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT
),
7969 GEN_HANDLER_E(wait
, 0x1F, 0x1E, 0x00, 0x039FF801, PPC_NONE
, PPC2_ISA300
),
7970 GEN_HANDLER(b
, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
7971 GEN_HANDLER(bc
, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
7972 GEN_HANDLER(bcctr
, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW
),
7973 GEN_HANDLER(bclr
, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW
),
7974 GEN_HANDLER_E(bctar
, 0x13, 0x10, 0x11, 0x0000E000, PPC_NONE
, PPC2_BCTAR_ISA207
),
7975 GEN_HANDLER(mcrf
, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER
),
7976 GEN_HANDLER(rfi
, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW
),
7977 #if defined(TARGET_PPC64)
7978 GEN_HANDLER(rfid
, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B
),
7979 #if !defined(CONFIG_USER_ONLY)
7980 /* Top bit of opc2 corresponds with low bit of LEV, so use two handlers */
7981 GEN_HANDLER_E(scv
, 0x11, 0x10, 0xFF, 0x03FFF01E, PPC_NONE
, PPC2_ISA300
),
7982 GEN_HANDLER_E(scv
, 0x11, 0x00, 0xFF, 0x03FFF01E, PPC_NONE
, PPC2_ISA300
),
7983 GEN_HANDLER_E(rfscv
, 0x13, 0x12, 0x02, 0x03FF8001, PPC_NONE
, PPC2_ISA300
),
7985 GEN_HANDLER_E(stop
, 0x13, 0x12, 0x0b, 0x03FFF801, PPC_NONE
, PPC2_ISA300
),
7986 GEN_HANDLER_E(doze
, 0x13, 0x12, 0x0c, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
7987 GEN_HANDLER_E(nap
, 0x13, 0x12, 0x0d, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
7988 GEN_HANDLER_E(sleep
, 0x13, 0x12, 0x0e, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
7989 GEN_HANDLER_E(rvwinkle
, 0x13, 0x12, 0x0f, 0x03FFF801, PPC_NONE
, PPC2_PM_ISA206
),
7990 GEN_HANDLER(hrfid
, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H
),
7992 /* Top bit of opc2 corresponds with low bit of LEV, so use two handlers */
7993 GEN_HANDLER(sc
, 0x11, 0x11, 0xFF, 0x03FFF01D, PPC_FLOW
),
7994 GEN_HANDLER(sc
, 0x11, 0x01, 0xFF, 0x03FFF01D, PPC_FLOW
),
7995 GEN_HANDLER(tw
, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW
),
7996 GEN_HANDLER(twi
, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW
),
7997 #if defined(TARGET_PPC64)
7998 GEN_HANDLER(td
, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B
),
7999 GEN_HANDLER(tdi
, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B
),
8001 GEN_HANDLER(mcrxr
, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC
),
8002 GEN_HANDLER(mfcr
, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC
),
8003 GEN_HANDLER(mfmsr
, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC
),
8004 GEN_HANDLER(mfspr
, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC
),
8005 GEN_HANDLER(mftb
, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB
),
8006 GEN_HANDLER(mtcrf
, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC
),
8007 #if defined(TARGET_PPC64)
8008 GEN_HANDLER(mtmsrd
, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B
),
8009 GEN_HANDLER_E(setb
, 0x1F, 0x00, 0x04, 0x0003F801, PPC_NONE
, PPC2_ISA300
),
8010 GEN_HANDLER_E(mcrxrx
, 0x1F, 0x00, 0x12, 0x007FF801, PPC_NONE
, PPC2_ISA300
),
8012 GEN_HANDLER(mtmsr
, 0x1F, 0x12, 0x04, 0x001EF801, PPC_MISC
),
8013 GEN_HANDLER(mtspr
, 0x1F, 0x13, 0x0E, 0x00000000, PPC_MISC
),
8014 GEN_HANDLER(dcbf
, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE
),
8015 GEN_HANDLER_E(dcbfep
, 0x1F, 0x1F, 0x03, 0x03C00001, PPC_NONE
, PPC2_BOOKE206
),
8016 GEN_HANDLER(dcbi
, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE
),
8017 GEN_HANDLER(dcbst
, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE
),
8018 GEN_HANDLER_E(dcbstep
, 0x1F, 0x1F, 0x01, 0x03E00001, PPC_NONE
, PPC2_BOOKE206
),
8019 GEN_HANDLER(dcbt
, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE
),
8020 GEN_HANDLER_E(dcbtep
, 0x1F, 0x1F, 0x09, 0x00000001, PPC_NONE
, PPC2_BOOKE206
),
8021 GEN_HANDLER(dcbtst
, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE
),
8022 GEN_HANDLER_E(dcbtstep
, 0x1F, 0x1F, 0x07, 0x00000001, PPC_NONE
, PPC2_BOOKE206
),
8023 GEN_HANDLER_E(dcbtls
, 0x1F, 0x06, 0x05, 0x02000001, PPC_BOOKE
, PPC2_BOOKE206
),
8024 GEN_HANDLER(dcbz
, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ
),
8025 GEN_HANDLER_E(dcbzep
, 0x1F, 0x1F, 0x1F, 0x03C00001, PPC_NONE
, PPC2_BOOKE206
),
8026 GEN_HANDLER(dst
, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC
),
8027 GEN_HANDLER(dstst
, 0x1F, 0x16, 0x0B, 0x01800001, PPC_ALTIVEC
),
8028 GEN_HANDLER(dss
, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC
),
8029 GEN_HANDLER(icbi
, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI
),
8030 GEN_HANDLER_E(icbiep
, 0x1F, 0x1F, 0x1E, 0x03E00001, PPC_NONE
, PPC2_BOOKE206
),
8031 GEN_HANDLER(dcba
, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA
),
8032 GEN_HANDLER(mfsr
, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT
),
8033 GEN_HANDLER(mfsrin
, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT
),
8034 GEN_HANDLER(mtsr
, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT
),
8035 GEN_HANDLER(mtsrin
, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT
),
8036 #if defined(TARGET_PPC64)
8037 GEN_HANDLER2(mfsr_64b
, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B
),
8038 GEN_HANDLER2(mfsrin_64b
, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001,
8040 GEN_HANDLER2(mtsr_64b
, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B
),
8041 GEN_HANDLER2(mtsrin_64b
, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001,
8043 GEN_HANDLER2(slbmte
, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B
),
8044 GEN_HANDLER2(slbmfee
, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B
),
8045 GEN_HANDLER2(slbmfev
, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B
),
8046 GEN_HANDLER2(slbfee_
, "slbfee.", 0x1F, 0x13, 0x1E, 0x001F0000, PPC_SEGMENT_64B
),
8048 GEN_HANDLER(tlbia
, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA
),
8050 * XXX Those instructions will need to be handled differently for
8051 * different ISA versions
8053 GEN_HANDLER(tlbiel
, 0x1F, 0x12, 0x08, 0x001F0001, PPC_MEM_TLBIE
),
8054 GEN_HANDLER(tlbie
, 0x1F, 0x12, 0x09, 0x001F0001, PPC_MEM_TLBIE
),
8055 GEN_HANDLER_E(tlbiel
, 0x1F, 0x12, 0x08, 0x00100001, PPC_NONE
, PPC2_ISA300
),
8056 GEN_HANDLER_E(tlbie
, 0x1F, 0x12, 0x09, 0x00100001, PPC_NONE
, PPC2_ISA300
),
8057 GEN_HANDLER(tlbsync
, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC
),
8058 #if defined(TARGET_PPC64)
8059 GEN_HANDLER(slbia
, 0x1F, 0x12, 0x0F, 0x031FFC01, PPC_SLBI
),
8060 GEN_HANDLER(slbie
, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI
),
8061 GEN_HANDLER_E(slbieg
, 0x1F, 0x12, 0x0E, 0x001F0001, PPC_NONE
, PPC2_ISA300
),
8062 GEN_HANDLER_E(slbsync
, 0x1F, 0x12, 0x0A, 0x03FFF801, PPC_NONE
, PPC2_ISA300
),
8064 GEN_HANDLER(eciwx
, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN
),
8065 GEN_HANDLER(ecowx
, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN
),
8066 GEN_HANDLER(abs
, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR
),
8067 GEN_HANDLER(abso
, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR
),
8068 GEN_HANDLER(clcs
, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR
),
8069 GEN_HANDLER(div
, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR
),
8070 GEN_HANDLER(divo
, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR
),
8071 GEN_HANDLER(divs
, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR
),
8072 GEN_HANDLER(divso
, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR
),
8073 GEN_HANDLER(doz
, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR
),
8074 GEN_HANDLER(dozo
, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR
),
8075 GEN_HANDLER(dozi
, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
8076 GEN_HANDLER(lscbx
, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR
),
8077 GEN_HANDLER(maskg
, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR
),
8078 GEN_HANDLER(maskir
, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR
),
8079 GEN_HANDLER(mul
, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR
),
8080 GEN_HANDLER(mulo
, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR
),
8081 GEN_HANDLER(nabs
, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR
),
8082 GEN_HANDLER(nabso
, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR
),
8083 GEN_HANDLER(rlmi
, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR
),
8084 GEN_HANDLER(rrib
, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR
),
8085 GEN_HANDLER(sle
, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR
),
8086 GEN_HANDLER(sleq
, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR
),
8087 GEN_HANDLER(sliq
, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR
),
8088 GEN_HANDLER(slliq
, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR
),
8089 GEN_HANDLER(sllq
, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR
),
8090 GEN_HANDLER(slq
, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR
),
8091 GEN_HANDLER(sraiq
, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR
),
8092 GEN_HANDLER(sraq
, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR
),
8093 GEN_HANDLER(sre
, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR
),
8094 GEN_HANDLER(srea
, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR
),
8095 GEN_HANDLER(sreq
, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR
),
8096 GEN_HANDLER(sriq
, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR
),
8097 GEN_HANDLER(srliq
, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR
),
8098 GEN_HANDLER(srlq
, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR
),
8099 GEN_HANDLER(srq
, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR
),
8100 GEN_HANDLER(dsa
, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC
),
8101 GEN_HANDLER(esa
, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC
),
8102 GEN_HANDLER(mfrom
, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC
),
8103 GEN_HANDLER2(tlbld_6xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB
),
8104 GEN_HANDLER2(tlbli_6xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB
),
8105 GEN_HANDLER2(tlbld_74xx
, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB
),
8106 GEN_HANDLER2(tlbli_74xx
, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB
),
8107 GEN_HANDLER(clf
, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER
),
8108 GEN_HANDLER(cli
, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER
),
8109 GEN_HANDLER(dclst
, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER
),
8110 GEN_HANDLER(mfsri
, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER
),
8111 GEN_HANDLER(rac
, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER
),
8112 GEN_HANDLER(rfsvc
, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER
),
8113 GEN_HANDLER(lfq
, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8114 GEN_HANDLER(lfqu
, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8115 GEN_HANDLER(lfqux
, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2
),
8116 GEN_HANDLER(lfqx
, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2
),
8117 GEN_HANDLER(stfq
, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8118 GEN_HANDLER(stfqu
, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2
),
8119 GEN_HANDLER(stfqux
, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2
),
8120 GEN_HANDLER(stfqx
, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2
),
8121 GEN_HANDLER(mfapidi
, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI
),
8122 GEN_HANDLER(tlbiva
, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA
),
8123 GEN_HANDLER(mfdcr
, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR
),
8124 GEN_HANDLER(mtdcr
, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR
),
8125 GEN_HANDLER(mfdcrx
, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX
),
8126 GEN_HANDLER(mtdcrx
, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX
),
8127 GEN_HANDLER(mfdcrux
, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX
),
8128 GEN_HANDLER(mtdcrux
, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX
),
8129 GEN_HANDLER(dccci
, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON
),
8130 GEN_HANDLER(dcread
, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON
),
8131 GEN_HANDLER2(icbt_40x
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT
),
8132 GEN_HANDLER(iccci
, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON
),
8133 GEN_HANDLER(icread
, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON
),
8134 GEN_HANDLER2(rfci_40x
, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP
),
8135 GEN_HANDLER_E(rfci
, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE
, PPC2_BOOKE206
),
8136 GEN_HANDLER(rfdi
, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI
),
8137 GEN_HANDLER(rfmci
, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI
),
8138 GEN_HANDLER2(tlbre_40x
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB
),
8139 GEN_HANDLER2(tlbsx_40x
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB
),
8140 GEN_HANDLER2(tlbwe_40x
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB
),
8141 GEN_HANDLER2(tlbre_440
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE
),
8142 GEN_HANDLER2(tlbsx_440
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE
),
8143 GEN_HANDLER2(tlbwe_440
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE
),
8144 GEN_HANDLER2_E(tlbre_booke206
, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001,
8145 PPC_NONE
, PPC2_BOOKE206
),
8146 GEN_HANDLER2_E(tlbsx_booke206
, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000,
8147 PPC_NONE
, PPC2_BOOKE206
),
8148 GEN_HANDLER2_E(tlbwe_booke206
, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001,
8149 PPC_NONE
, PPC2_BOOKE206
),
8150 GEN_HANDLER2_E(tlbivax_booke206
, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001,
8151 PPC_NONE
, PPC2_BOOKE206
),
8152 GEN_HANDLER2_E(tlbilx_booke206
, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001,
8153 PPC_NONE
, PPC2_BOOKE206
),
8154 GEN_HANDLER2_E(msgsnd
, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001,
8155 PPC_NONE
, PPC2_PRCNTL
),
8156 GEN_HANDLER2_E(msgclr
, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001,
8157 PPC_NONE
, PPC2_PRCNTL
),
8158 GEN_HANDLER2_E(msgsync
, "msgsync", 0x1F, 0x16, 0x1B, 0x00000000,
8159 PPC_NONE
, PPC2_PRCNTL
),
8160 GEN_HANDLER(wrtee
, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE
),
8161 GEN_HANDLER(wrteei
, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE
),
8162 GEN_HANDLER(dlmzb
, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC
),
8163 GEN_HANDLER_E(mbar
, 0x1F, 0x16, 0x1a, 0x001FF801,
8164 PPC_BOOKE
, PPC2_BOOKE206
),
8165 GEN_HANDLER(msync_4xx
, 0x1F, 0x16, 0x12, 0x039FF801, PPC_BOOKE
),
8166 GEN_HANDLER2_E(icbt_440
, "icbt", 0x1F, 0x16, 0x00, 0x03E00001,
8167 PPC_BOOKE
, PPC2_BOOKE206
),
8168 GEN_HANDLER2(icbt_440
, "icbt", 0x1F, 0x06, 0x08, 0x03E00001,
8170 GEN_HANDLER(lvsl
, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC
),
8171 GEN_HANDLER(lvsr
, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC
),
8172 GEN_HANDLER(mfvscr
, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC
),
8173 GEN_HANDLER(mtvscr
, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC
),
8174 GEN_HANDLER(vmladduhm
, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC
),
8175 #if defined(TARGET_PPC64)
8176 GEN_HANDLER_E(maddhd_maddhdu
, 0x04, 0x18, 0xFF, 0x00000000, PPC_NONE
,
8178 GEN_HANDLER_E(maddld
, 0x04, 0x19, 0xFF, 0x00000000, PPC_NONE
, PPC2_ISA300
),
8179 GEN_HANDLER2_E(msgsndp
, "msgsndp", 0x1F, 0x0E, 0x04, 0x03ff0001,
8180 PPC_NONE
, PPC2_ISA207S
),
8181 GEN_HANDLER2_E(msgclrp
, "msgclrp", 0x1F, 0x0E, 0x05, 0x03ff0001,
8182 PPC_NONE
, PPC2_ISA207S
),
8185 #undef GEN_INT_ARITH_ADD
8186 #undef GEN_INT_ARITH_ADD_CONST
8187 #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \
8188 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER),
8189 #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \
8190 add_ca, compute_ca, compute_ov) \
8191 GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER),
8192 GEN_INT_ARITH_ADD(add
, 0x08, 0, 0, 0)
8193 GEN_INT_ARITH_ADD(addo
, 0x18, 0, 0, 1)
8194 GEN_INT_ARITH_ADD(addc
, 0x00, 0, 1, 0)
8195 GEN_INT_ARITH_ADD(addco
, 0x10, 0, 1, 1)
8196 GEN_INT_ARITH_ADD(adde
, 0x04, 1, 1, 0)
8197 GEN_INT_ARITH_ADD(addeo
, 0x14, 1, 1, 1)
8198 GEN_INT_ARITH_ADD_CONST(addme
, 0x07, -1LL, 1, 1, 0)
8199 GEN_INT_ARITH_ADD_CONST(addmeo
, 0x17, -1LL, 1, 1, 1)
8200 GEN_HANDLER_E(addex
, 0x1F, 0x0A, 0x05, 0x00000000, PPC_NONE
, PPC2_ISA300
),
8201 GEN_INT_ARITH_ADD_CONST(addze
, 0x06, 0, 1, 1, 0)
8202 GEN_INT_ARITH_ADD_CONST(addzeo
, 0x16, 0, 1, 1, 1)
8204 #undef GEN_INT_ARITH_DIVW
8205 #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \
8206 GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER)
8207 GEN_INT_ARITH_DIVW(divwu
, 0x0E, 0, 0),
8208 GEN_INT_ARITH_DIVW(divwuo
, 0x1E, 0, 1),
8209 GEN_INT_ARITH_DIVW(divw
, 0x0F, 1, 0),
8210 GEN_INT_ARITH_DIVW(divwo
, 0x1F, 1, 1),
8211 GEN_HANDLER_E(divwe
, 0x1F, 0x0B, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
8212 GEN_HANDLER_E(divweo
, 0x1F, 0x0B, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
8213 GEN_HANDLER_E(divweu
, 0x1F, 0x0B, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
8214 GEN_HANDLER_E(divweuo
, 0x1F, 0x0B, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
8215 GEN_HANDLER_E(modsw
, 0x1F, 0x0B, 0x18, 0x00000001, PPC_NONE
, PPC2_ISA300
),
8216 GEN_HANDLER_E(moduw
, 0x1F, 0x0B, 0x08, 0x00000001, PPC_NONE
, PPC2_ISA300
),
8218 #if defined(TARGET_PPC64)
8219 #undef GEN_INT_ARITH_DIVD
8220 #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \
8221 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8222 GEN_INT_ARITH_DIVD(divdu
, 0x0E, 0, 0),
8223 GEN_INT_ARITH_DIVD(divduo
, 0x1E, 0, 1),
8224 GEN_INT_ARITH_DIVD(divd
, 0x0F, 1, 0),
8225 GEN_INT_ARITH_DIVD(divdo
, 0x1F, 1, 1),
8227 GEN_HANDLER_E(divdeu
, 0x1F, 0x09, 0x0C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
8228 GEN_HANDLER_E(divdeuo
, 0x1F, 0x09, 0x1C, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
8229 GEN_HANDLER_E(divde
, 0x1F, 0x09, 0x0D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
8230 GEN_HANDLER_E(divdeo
, 0x1F, 0x09, 0x1D, 0, PPC_NONE
, PPC2_DIVE_ISA206
),
8231 GEN_HANDLER_E(modsd
, 0x1F, 0x09, 0x18, 0x00000001, PPC_NONE
, PPC2_ISA300
),
8232 GEN_HANDLER_E(modud
, 0x1F, 0x09, 0x08, 0x00000001, PPC_NONE
, PPC2_ISA300
),
8234 #undef GEN_INT_ARITH_MUL_HELPER
8235 #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \
8236 GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B)
8237 GEN_INT_ARITH_MUL_HELPER(mulhdu
, 0x00),
8238 GEN_INT_ARITH_MUL_HELPER(mulhd
, 0x02),
8239 GEN_INT_ARITH_MUL_HELPER(mulldo
, 0x17),
8242 #undef GEN_INT_ARITH_SUBF
8243 #undef GEN_INT_ARITH_SUBF_CONST
8244 #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \
8245 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER),
8246 #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \
8247 add_ca, compute_ca, compute_ov) \
8248 GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER),
8249 GEN_INT_ARITH_SUBF(subf
, 0x01, 0, 0, 0)
8250 GEN_INT_ARITH_SUBF(subfo
, 0x11, 0, 0, 1)
8251 GEN_INT_ARITH_SUBF(subfc
, 0x00, 0, 1, 0)
8252 GEN_INT_ARITH_SUBF(subfco
, 0x10, 0, 1, 1)
8253 GEN_INT_ARITH_SUBF(subfe
, 0x04, 1, 1, 0)
8254 GEN_INT_ARITH_SUBF(subfeo
, 0x14, 1, 1, 1)
8255 GEN_INT_ARITH_SUBF_CONST(subfme
, 0x07, -1LL, 1, 1, 0)
8256 GEN_INT_ARITH_SUBF_CONST(subfmeo
, 0x17, -1LL, 1, 1, 1)
8257 GEN_INT_ARITH_SUBF_CONST(subfze
, 0x06, 0, 1, 1, 0)
8258 GEN_INT_ARITH_SUBF_CONST(subfzeo
, 0x16, 0, 1, 1, 1)
8262 #define GEN_LOGICAL2(name, tcg_op, opc, type) \
8263 GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type)
8264 #define GEN_LOGICAL1(name, tcg_op, opc, type) \
8265 GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type)
8266 GEN_LOGICAL2(and, tcg_gen_and_tl
, 0x00, PPC_INTEGER
),
8267 GEN_LOGICAL2(andc
, tcg_gen_andc_tl
, 0x01, PPC_INTEGER
),
8268 GEN_LOGICAL2(eqv
, tcg_gen_eqv_tl
, 0x08, PPC_INTEGER
),
8269 GEN_LOGICAL1(extsb
, tcg_gen_ext8s_tl
, 0x1D, PPC_INTEGER
),
8270 GEN_LOGICAL1(extsh
, tcg_gen_ext16s_tl
, 0x1C, PPC_INTEGER
),
8271 GEN_LOGICAL2(nand
, tcg_gen_nand_tl
, 0x0E, PPC_INTEGER
),
8272 GEN_LOGICAL2(nor
, tcg_gen_nor_tl
, 0x03, PPC_INTEGER
),
8273 GEN_LOGICAL2(orc
, tcg_gen_orc_tl
, 0x0C, PPC_INTEGER
),
8274 #if defined(TARGET_PPC64)
8275 GEN_LOGICAL1(extsw
, tcg_gen_ext32s_tl
, 0x1E, PPC_64B
),
8278 #if defined(TARGET_PPC64)
8281 #define GEN_PPC64_R2(name, opc1, opc2) \
8282 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8283 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
8285 #define GEN_PPC64_R4(name, opc1, opc2) \
8286 GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\
8287 GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \
8289 GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \
8291 GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \
8293 GEN_PPC64_R4(rldicl
, 0x1E, 0x00),
8294 GEN_PPC64_R4(rldicr
, 0x1E, 0x02),
8295 GEN_PPC64_R4(rldic
, 0x1E, 0x04),
8296 GEN_PPC64_R2(rldcl
, 0x1E, 0x08),
8297 GEN_PPC64_R2(rldcr
, 0x1E, 0x09),
8298 GEN_PPC64_R4(rldimi
, 0x1E, 0x06),
8306 #define GEN_LD(name, ldop, opc, type) \
8307 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8308 #define GEN_LDU(name, ldop, opc, type) \
8309 GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type),
8310 #define GEN_LDUX(name, ldop, opc2, opc3, type) \
8311 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
8312 #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2, chk) \
8313 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2),
8314 #define GEN_LDS(name, ldop, op, type) \
8315 GEN_LD(name, ldop, op | 0x20, type) \
8316 GEN_LDU(name, ldop, op | 0x21, type) \
8317 GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \
8318 GEN_LDX(name, ldop, 0x17, op | 0x00, type)
8320 GEN_LDS(lbz
, ld8u
, 0x02, PPC_INTEGER
)
8321 GEN_LDS(lha
, ld16s
, 0x0A, PPC_INTEGER
)
8322 GEN_LDS(lhz
, ld16u
, 0x08, PPC_INTEGER
)
8323 GEN_LDS(lwz
, ld32u
, 0x00, PPC_INTEGER
)
8324 #if defined(TARGET_PPC64)
8325 GEN_LDUX(lwa
, ld32s
, 0x15, 0x0B, PPC_64B
)
8326 GEN_LDX(lwa
, ld32s
, 0x15, 0x0A, PPC_64B
)
8327 GEN_LDUX(ld
, ld64_i64
, 0x15, 0x01, PPC_64B
)
8328 GEN_LDX(ld
, ld64_i64
, 0x15, 0x00, PPC_64B
)
8329 GEN_LDX_E(ldbr
, ld64ur_i64
, 0x14, 0x10, PPC_NONE
, PPC2_DBRX
, CHK_NONE
)
8331 /* HV/P7 and later only */
8332 GEN_LDX_HVRM(ldcix
, ld64_i64
, 0x15, 0x1b, PPC_CILDST
)
8333 GEN_LDX_HVRM(lwzcix
, ld32u
, 0x15, 0x18, PPC_CILDST
)
8334 GEN_LDX_HVRM(lhzcix
, ld16u
, 0x15, 0x19, PPC_CILDST
)
8335 GEN_LDX_HVRM(lbzcix
, ld8u
, 0x15, 0x1a, PPC_CILDST
)
8337 GEN_LDX(lhbr
, ld16ur
, 0x16, 0x18, PPC_INTEGER
)
8338 GEN_LDX(lwbr
, ld32ur
, 0x16, 0x10, PPC_INTEGER
)
8340 /* External PID based load */
8342 #define GEN_LDEPX(name, ldop, opc2, opc3) \
8343 GEN_HANDLER_E(name##epx, 0x1F, opc2, opc3, \
8344 0x00000001, PPC_NONE, PPC2_BOOKE206),
8346 GEN_LDEPX(lb
, DEF_MEMOP(MO_UB
), 0x1F, 0x02)
8347 GEN_LDEPX(lh
, DEF_MEMOP(MO_UW
), 0x1F, 0x08)
8348 GEN_LDEPX(lw
, DEF_MEMOP(MO_UL
), 0x1F, 0x00)
8349 #if defined(TARGET_PPC64)
8350 GEN_LDEPX(ld
, DEF_MEMOP(MO_Q
), 0x1D, 0x00)
8358 #define GEN_ST(name, stop, opc, type) \
8359 GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type),
8360 #define GEN_STU(name, stop, opc, type) \
8361 GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type),
8362 #define GEN_STUX(name, stop, opc2, opc3, type) \
8363 GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type),
8364 #define GEN_STX_E(name, stop, opc2, opc3, type, type2, chk) \
8365 GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000000, type, type2),
8366 #define GEN_STS(name, stop, op, type) \
8367 GEN_ST(name, stop, op | 0x20, type) \
8368 GEN_STU(name, stop, op | 0x21, type) \
8369 GEN_STUX(name, stop, 0x17, op | 0x01, type) \
8370 GEN_STX(name, stop, 0x17, op | 0x00, type)
8372 GEN_STS(stb
, st8
, 0x06, PPC_INTEGER
)
8373 GEN_STS(sth
, st16
, 0x0C, PPC_INTEGER
)
8374 GEN_STS(stw
, st32
, 0x04, PPC_INTEGER
)
8375 #if defined(TARGET_PPC64)
8376 GEN_STUX(std
, st64_i64
, 0x15, 0x05, PPC_64B
)
8377 GEN_STX(std
, st64_i64
, 0x15, 0x04, PPC_64B
)
8378 GEN_STX_E(stdbr
, st64r_i64
, 0x14, 0x14, PPC_NONE
, PPC2_DBRX
, CHK_NONE
)
8379 GEN_STX_HVRM(stdcix
, st64_i64
, 0x15, 0x1f, PPC_CILDST
)
8380 GEN_STX_HVRM(stwcix
, st32
, 0x15, 0x1c, PPC_CILDST
)
8381 GEN_STX_HVRM(sthcix
, st16
, 0x15, 0x1d, PPC_CILDST
)
8382 GEN_STX_HVRM(stbcix
, st8
, 0x15, 0x1e, PPC_CILDST
)
8384 GEN_STX(sthbr
, st16r
, 0x16, 0x1C, PPC_INTEGER
)
8385 GEN_STX(stwbr
, st32r
, 0x16, 0x14, PPC_INTEGER
)
8388 #define GEN_STEPX(name, ldop, opc2, opc3) \
8389 GEN_HANDLER_E(name##epx, 0x1F, opc2, opc3, \
8390 0x00000001, PPC_NONE, PPC2_BOOKE206),
8392 GEN_STEPX(stb
, DEF_MEMOP(MO_UB
), 0x1F, 0x06)
8393 GEN_STEPX(sth
, DEF_MEMOP(MO_UW
), 0x1F, 0x0C)
8394 GEN_STEPX(stw
, DEF_MEMOP(MO_UL
), 0x1F, 0x04)
8395 #if defined(TARGET_PPC64)
8396 GEN_STEPX(std
, DEF_MEMOP(MO_Q
), 0x1D, 0x04)
8400 #define GEN_CRLOGIC(name, tcg_op, opc) \
8401 GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER)
8402 GEN_CRLOGIC(crand
, tcg_gen_and_i32
, 0x08),
8403 GEN_CRLOGIC(crandc
, tcg_gen_andc_i32
, 0x04),
8404 GEN_CRLOGIC(creqv
, tcg_gen_eqv_i32
, 0x09),
8405 GEN_CRLOGIC(crnand
, tcg_gen_nand_i32
, 0x07),
8406 GEN_CRLOGIC(crnor
, tcg_gen_nor_i32
, 0x01),
8407 GEN_CRLOGIC(cror
, tcg_gen_or_i32
, 0x0E),
8408 GEN_CRLOGIC(crorc
, tcg_gen_orc_i32
, 0x0D),
8409 GEN_CRLOGIC(crxor
, tcg_gen_xor_i32
, 0x06),
8411 #undef GEN_MAC_HANDLER
8412 #define GEN_MAC_HANDLER(name, opc2, opc3) \
8413 GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC)
8414 GEN_MAC_HANDLER(macchw
, 0x0C, 0x05),
8415 GEN_MAC_HANDLER(macchwo
, 0x0C, 0x15),
8416 GEN_MAC_HANDLER(macchws
, 0x0C, 0x07),
8417 GEN_MAC_HANDLER(macchwso
, 0x0C, 0x17),
8418 GEN_MAC_HANDLER(macchwsu
, 0x0C, 0x06),
8419 GEN_MAC_HANDLER(macchwsuo
, 0x0C, 0x16),
8420 GEN_MAC_HANDLER(macchwu
, 0x0C, 0x04),
8421 GEN_MAC_HANDLER(macchwuo
, 0x0C, 0x14),
8422 GEN_MAC_HANDLER(machhw
, 0x0C, 0x01),
8423 GEN_MAC_HANDLER(machhwo
, 0x0C, 0x11),
8424 GEN_MAC_HANDLER(machhws
, 0x0C, 0x03),
8425 GEN_MAC_HANDLER(machhwso
, 0x0C, 0x13),
8426 GEN_MAC_HANDLER(machhwsu
, 0x0C, 0x02),
8427 GEN_MAC_HANDLER(machhwsuo
, 0x0C, 0x12),
8428 GEN_MAC_HANDLER(machhwu
, 0x0C, 0x00),
8429 GEN_MAC_HANDLER(machhwuo
, 0x0C, 0x10),
8430 GEN_MAC_HANDLER(maclhw
, 0x0C, 0x0D),
8431 GEN_MAC_HANDLER(maclhwo
, 0x0C, 0x1D),
8432 GEN_MAC_HANDLER(maclhws
, 0x0C, 0x0F),
8433 GEN_MAC_HANDLER(maclhwso
, 0x0C, 0x1F),
8434 GEN_MAC_HANDLER(maclhwu
, 0x0C, 0x0C),
8435 GEN_MAC_HANDLER(maclhwuo
, 0x0C, 0x1C),
8436 GEN_MAC_HANDLER(maclhwsu
, 0x0C, 0x0E),
8437 GEN_MAC_HANDLER(maclhwsuo
, 0x0C, 0x1E),
8438 GEN_MAC_HANDLER(nmacchw
, 0x0E, 0x05),
8439 GEN_MAC_HANDLER(nmacchwo
, 0x0E, 0x15),
8440 GEN_MAC_HANDLER(nmacchws
, 0x0E, 0x07),
8441 GEN_MAC_HANDLER(nmacchwso
, 0x0E, 0x17),
8442 GEN_MAC_HANDLER(nmachhw
, 0x0E, 0x01),
8443 GEN_MAC_HANDLER(nmachhwo
, 0x0E, 0x11),
8444 GEN_MAC_HANDLER(nmachhws
, 0x0E, 0x03),
8445 GEN_MAC_HANDLER(nmachhwso
, 0x0E, 0x13),
8446 GEN_MAC_HANDLER(nmaclhw
, 0x0E, 0x0D),
8447 GEN_MAC_HANDLER(nmaclhwo
, 0x0E, 0x1D),
8448 GEN_MAC_HANDLER(nmaclhws
, 0x0E, 0x0F),
8449 GEN_MAC_HANDLER(nmaclhwso
, 0x0E, 0x1F),
8450 GEN_MAC_HANDLER(mulchw
, 0x08, 0x05),
8451 GEN_MAC_HANDLER(mulchwu
, 0x08, 0x04),
8452 GEN_MAC_HANDLER(mulhhw
, 0x08, 0x01),
8453 GEN_MAC_HANDLER(mulhhwu
, 0x08, 0x00),
8454 GEN_MAC_HANDLER(mullhw
, 0x08, 0x0D),
8455 GEN_MAC_HANDLER(mullhwu
, 0x08, 0x0C),
8457 GEN_HANDLER2_E(tbegin
, "tbegin", 0x1F, 0x0E, 0x14, 0x01DFF800, \
8459 GEN_HANDLER2_E(tend
, "tend", 0x1F, 0x0E, 0x15, 0x01FFF800, \
8461 GEN_HANDLER2_E(tabort
, "tabort", 0x1F, 0x0E, 0x1C, 0x03E0F800, \
8463 GEN_HANDLER2_E(tabortwc
, "tabortwc", 0x1F, 0x0E, 0x18, 0x00000000, \
8465 GEN_HANDLER2_E(tabortwci
, "tabortwci", 0x1F, 0x0E, 0x1A, 0x00000000, \
8467 GEN_HANDLER2_E(tabortdc
, "tabortdc", 0x1F, 0x0E, 0x19, 0x00000000, \
8469 GEN_HANDLER2_E(tabortdci
, "tabortdci", 0x1F, 0x0E, 0x1B, 0x00000000, \
8471 GEN_HANDLER2_E(tsr
, "tsr", 0x1F, 0x0E, 0x17, 0x03DFF800, \
8473 GEN_HANDLER2_E(tcheck
, "tcheck", 0x1F, 0x0E, 0x16, 0x007FF800, \
8475 GEN_HANDLER2_E(treclaim
, "treclaim", 0x1F, 0x0E, 0x1D, 0x03E0F800, \
8477 GEN_HANDLER2_E(trechkpt
, "trechkpt", 0x1F, 0x0E, 0x1F, 0x03FFF800, \
8480 #include "translate/fp-ops.c.inc"
8482 #include "translate/vmx-ops.c.inc"
8484 #include "translate/vsx-ops.c.inc"
8486 #include "translate/dfp-ops.c.inc"
8488 #include "translate/spe-ops.c.inc"
8491 /*****************************************************************************/
8494 PPC_DIRECT
= 0, /* Opcode routine */
8495 PPC_INDIRECT
= 1, /* Indirect opcode table */
8498 #define PPC_OPCODE_MASK 0x3
8500 static inline int is_indirect_opcode(void *handler
)
8502 return ((uintptr_t)handler
& PPC_OPCODE_MASK
) == PPC_INDIRECT
;
8505 static inline opc_handler_t
**ind_table(void *handler
)
8507 return (opc_handler_t
**)((uintptr_t)handler
& ~PPC_OPCODE_MASK
);
8510 /* Instruction table creation */
8511 /* Opcodes tables creation */
8512 static void fill_new_table(opc_handler_t
**table
, int len
)
8516 for (i
= 0; i
< len
; i
++) {
8517 table
[i
] = &invalid_handler
;
8521 static int create_new_table(opc_handler_t
**table
, unsigned char idx
)
8523 opc_handler_t
**tmp
;
8525 tmp
= g_new(opc_handler_t
*, PPC_CPU_INDIRECT_OPCODES_LEN
);
8526 fill_new_table(tmp
, PPC_CPU_INDIRECT_OPCODES_LEN
);
8527 table
[idx
] = (opc_handler_t
*)((uintptr_t)tmp
| PPC_INDIRECT
);
8532 static int insert_in_table(opc_handler_t
**table
, unsigned char idx
,
8533 opc_handler_t
*handler
)
8535 if (table
[idx
] != &invalid_handler
) {
8538 table
[idx
] = handler
;
8543 static int register_direct_insn(opc_handler_t
**ppc_opcodes
,
8544 unsigned char idx
, opc_handler_t
*handler
)
8546 if (insert_in_table(ppc_opcodes
, idx
, handler
) < 0) {
8547 printf("*** ERROR: opcode %02x already assigned in main "
8548 "opcode table\n", idx
);
8549 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
8550 printf(" Registered handler '%s' - new handler '%s'\n",
8551 ppc_opcodes
[idx
]->oname
, handler
->oname
);
8559 static int register_ind_in_table(opc_handler_t
**table
,
8560 unsigned char idx1
, unsigned char idx2
,
8561 opc_handler_t
*handler
)
8563 if (table
[idx1
] == &invalid_handler
) {
8564 if (create_new_table(table
, idx1
) < 0) {
8565 printf("*** ERROR: unable to create indirect table "
8566 "idx=%02x\n", idx1
);
8570 if (!is_indirect_opcode(table
[idx1
])) {
8571 printf("*** ERROR: idx %02x already assigned to a direct "
8573 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
8574 printf(" Registered handler '%s' - new handler '%s'\n",
8575 ind_table(table
[idx1
])[idx2
]->oname
, handler
->oname
);
8580 if (handler
!= NULL
&&
8581 insert_in_table(ind_table(table
[idx1
]), idx2
, handler
) < 0) {
8582 printf("*** ERROR: opcode %02x already assigned in "
8583 "opcode table %02x\n", idx2
, idx1
);
8584 #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU)
8585 printf(" Registered handler '%s' - new handler '%s'\n",
8586 ind_table(table
[idx1
])[idx2
]->oname
, handler
->oname
);
8594 static int register_ind_insn(opc_handler_t
**ppc_opcodes
,
8595 unsigned char idx1
, unsigned char idx2
,
8596 opc_handler_t
*handler
)
8598 return register_ind_in_table(ppc_opcodes
, idx1
, idx2
, handler
);
8601 static int register_dblind_insn(opc_handler_t
**ppc_opcodes
,
8602 unsigned char idx1
, unsigned char idx2
,
8603 unsigned char idx3
, opc_handler_t
*handler
)
8605 if (register_ind_in_table(ppc_opcodes
, idx1
, idx2
, NULL
) < 0) {
8606 printf("*** ERROR: unable to join indirect table idx "
8607 "[%02x-%02x]\n", idx1
, idx2
);
8610 if (register_ind_in_table(ind_table(ppc_opcodes
[idx1
]), idx2
, idx3
,
8612 printf("*** ERROR: unable to insert opcode "
8613 "[%02x-%02x-%02x]\n", idx1
, idx2
, idx3
);
8620 static int register_trplind_insn(opc_handler_t
**ppc_opcodes
,
8621 unsigned char idx1
, unsigned char idx2
,
8622 unsigned char idx3
, unsigned char idx4
,
8623 opc_handler_t
*handler
)
8625 opc_handler_t
**table
;
8627 if (register_ind_in_table(ppc_opcodes
, idx1
, idx2
, NULL
) < 0) {
8628 printf("*** ERROR: unable to join indirect table idx "
8629 "[%02x-%02x]\n", idx1
, idx2
);
8632 table
= ind_table(ppc_opcodes
[idx1
]);
8633 if (register_ind_in_table(table
, idx2
, idx3
, NULL
) < 0) {
8634 printf("*** ERROR: unable to join 2nd-level indirect table idx "
8635 "[%02x-%02x-%02x]\n", idx1
, idx2
, idx3
);
8638 table
= ind_table(table
[idx2
]);
8639 if (register_ind_in_table(table
, idx3
, idx4
, handler
) < 0) {
8640 printf("*** ERROR: unable to insert opcode "
8641 "[%02x-%02x-%02x-%02x]\n", idx1
, idx2
, idx3
, idx4
);
8646 static int register_insn(opc_handler_t
**ppc_opcodes
, opcode_t
*insn
)
8648 if (insn
->opc2
!= 0xFF) {
8649 if (insn
->opc3
!= 0xFF) {
8650 if (insn
->opc4
!= 0xFF) {
8651 if (register_trplind_insn(ppc_opcodes
, insn
->opc1
, insn
->opc2
,
8652 insn
->opc3
, insn
->opc4
,
8653 &insn
->handler
) < 0) {
8657 if (register_dblind_insn(ppc_opcodes
, insn
->opc1
, insn
->opc2
,
8658 insn
->opc3
, &insn
->handler
) < 0) {
8663 if (register_ind_insn(ppc_opcodes
, insn
->opc1
,
8664 insn
->opc2
, &insn
->handler
) < 0) {
8669 if (register_direct_insn(ppc_opcodes
, insn
->opc1
, &insn
->handler
) < 0) {
8677 static int test_opcode_table(opc_handler_t
**table
, int len
)
8681 for (i
= 0, count
= 0; i
< len
; i
++) {
8682 /* Consistency fixup */
8683 if (table
[i
] == NULL
) {
8684 table
[i
] = &invalid_handler
;
8686 if (table
[i
] != &invalid_handler
) {
8687 if (is_indirect_opcode(table
[i
])) {
8688 tmp
= test_opcode_table(ind_table(table
[i
]),
8689 PPC_CPU_INDIRECT_OPCODES_LEN
);
8692 table
[i
] = &invalid_handler
;
8705 static void fix_opcode_tables(opc_handler_t
**ppc_opcodes
)
8707 if (test_opcode_table(ppc_opcodes
, PPC_CPU_OPCODES_LEN
) == 0) {
8708 printf("*** WARNING: no opcode defined !\n");
8712 /*****************************************************************************/
8713 void create_ppc_opcodes(PowerPCCPU
*cpu
, Error
**errp
)
8715 PowerPCCPUClass
*pcc
= POWERPC_CPU_GET_CLASS(cpu
);
8718 fill_new_table(cpu
->opcodes
, PPC_CPU_OPCODES_LEN
);
8719 for (opc
= opcodes
; opc
< &opcodes
[ARRAY_SIZE(opcodes
)]; opc
++) {
8720 if (((opc
->handler
.type
& pcc
->insns_flags
) != 0) ||
8721 ((opc
->handler
.type2
& pcc
->insns_flags2
) != 0)) {
8722 if (register_insn(cpu
->opcodes
, opc
) < 0) {
8723 error_setg(errp
, "ERROR initializing PowerPC instruction "
8724 "0x%02x 0x%02x 0x%02x", opc
->opc1
, opc
->opc2
,
8730 fix_opcode_tables(cpu
->opcodes
);
8735 void destroy_ppc_opcodes(PowerPCCPU
*cpu
)
8737 opc_handler_t
**table
, **table_2
;
8740 for (i
= 0; i
< PPC_CPU_OPCODES_LEN
; i
++) {
8741 if (cpu
->opcodes
[i
] == &invalid_handler
) {
8744 if (is_indirect_opcode(cpu
->opcodes
[i
])) {
8745 table
= ind_table(cpu
->opcodes
[i
]);
8746 for (j
= 0; j
< PPC_CPU_INDIRECT_OPCODES_LEN
; j
++) {
8747 if (table
[j
] == &invalid_handler
) {
8750 if (is_indirect_opcode(table
[j
])) {
8751 table_2
= ind_table(table
[j
]);
8752 for (k
= 0; k
< PPC_CPU_INDIRECT_OPCODES_LEN
; k
++) {
8753 if (table_2
[k
] != &invalid_handler
&&
8754 is_indirect_opcode(table_2
[k
])) {
8755 g_free((opc_handler_t
*)((uintptr_t)table_2
[k
] &
8759 g_free((opc_handler_t
*)((uintptr_t)table
[j
] &
8763 g_free((opc_handler_t
*)((uintptr_t)cpu
->opcodes
[i
] &
8769 #if defined(PPC_DUMP_CPU)
8770 static void dump_ppc_insns(CPUPPCState
*env
)
8772 opc_handler_t
**table
, *handler
;
8774 uint8_t opc1
, opc2
, opc3
, opc4
;
8776 printf("Instructions set:\n");
8777 /* opc1 is 6 bits long */
8778 for (opc1
= 0x00; opc1
< PPC_CPU_OPCODES_LEN
; opc1
++) {
8779 table
= env
->opcodes
;
8780 handler
= table
[opc1
];
8781 if (is_indirect_opcode(handler
)) {
8782 /* opc2 is 5 bits long */
8783 for (opc2
= 0; opc2
< PPC_CPU_INDIRECT_OPCODES_LEN
; opc2
++) {
8784 table
= env
->opcodes
;
8785 handler
= env
->opcodes
[opc1
];
8786 table
= ind_table(handler
);
8787 handler
= table
[opc2
];
8788 if (is_indirect_opcode(handler
)) {
8789 table
= ind_table(handler
);
8790 /* opc3 is 5 bits long */
8791 for (opc3
= 0; opc3
< PPC_CPU_INDIRECT_OPCODES_LEN
;
8793 handler
= table
[opc3
];
8794 if (is_indirect_opcode(handler
)) {
8795 table
= ind_table(handler
);
8796 /* opc4 is 5 bits long */
8797 for (opc4
= 0; opc4
< PPC_CPU_INDIRECT_OPCODES_LEN
;
8799 handler
= table
[opc4
];
8800 if (handler
->handler
!= &gen_invalid
) {
8801 printf("INSN: %02x %02x %02x %02x -- "
8802 "(%02d %04d %02d) : %s\n",
8803 opc1
, opc2
, opc3
, opc4
,
8804 opc1
, (opc3
<< 5) | opc2
, opc4
,
8809 if (handler
->handler
!= &gen_invalid
) {
8810 /* Special hack to properly dump SPE insns */
8811 p
= strchr(handler
->oname
, '_');
8813 printf("INSN: %02x %02x %02x (%02d %04d) : "
8815 opc1
, opc2
, opc3
, opc1
,
8820 if ((p
- handler
->oname
) != strlen(q
)
8821 || (memcmp(handler
->oname
, q
, strlen(q
))
8823 /* First instruction */
8824 printf("INSN: %02x %02x %02x"
8825 "(%02d %04d) : %.*s\n",
8826 opc1
, opc2
<< 1, opc3
, opc1
,
8827 (opc3
<< 6) | (opc2
<< 1),
8828 (int)(p
- handler
->oname
),
8831 if (strcmp(p
+ 1, q
) != 0) {
8832 /* Second instruction */
8833 printf("INSN: %02x %02x %02x "
8834 "(%02d %04d) : %s\n", opc1
,
8835 (opc2
<< 1) | 1, opc3
, opc1
,
8836 (opc3
<< 6) | (opc2
<< 1) | 1,
8844 if (handler
->handler
!= &gen_invalid
) {
8845 printf("INSN: %02x %02x -- (%02d %04d) : %s\n",
8846 opc1
, opc2
, opc1
, opc2
, handler
->oname
);
8851 if (handler
->handler
!= &gen_invalid
) {
8852 printf("INSN: %02x -- -- (%02d ----) : %s\n",
8853 opc1
, opc1
, handler
->oname
);
8859 int ppc_fixup_cpu(PowerPCCPU
*cpu
)
8861 CPUPPCState
*env
= &cpu
->env
;
8864 * TCG doesn't (yet) emulate some groups of instructions that are
8865 * implemented on some otherwise supported CPUs (e.g. VSX and
8866 * decimal floating point instructions on POWER7). We remove
8867 * unsupported instruction groups from the cpu state's instruction
8868 * masks and hope the guest can cope. For at least the pseries
8869 * machine, the unavailability of these instructions can be
8870 * advertised to the guest via the device tree.
8872 if ((env
->insns_flags
& ~PPC_TCG_INSNS
)
8873 || (env
->insns_flags2
& ~PPC_TCG_INSNS2
)) {
8874 warn_report("Disabling some instructions which are not "
8875 "emulated by TCG (0x%" PRIx64
", 0x%" PRIx64
")",
8876 env
->insns_flags
& ~PPC_TCG_INSNS
,
8877 env
->insns_flags2
& ~PPC_TCG_INSNS2
);
8879 env
->insns_flags
&= PPC_TCG_INSNS
;
8880 env
->insns_flags2
&= PPC_TCG_INSNS2
;
8885 void ppc_cpu_dump_statistics(CPUState
*cs
, int flags
)
8887 #if defined(DO_PPC_STATISTICS)
8888 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
8889 opc_handler_t
**t1
, **t2
, **t3
, *handler
;
8892 t1
= cpu
->env
.opcodes
;
8893 for (op1
= 0; op1
< 64; op1
++) {
8895 if (is_indirect_opcode(handler
)) {
8896 t2
= ind_table(handler
);
8897 for (op2
= 0; op2
< 32; op2
++) {
8899 if (is_indirect_opcode(handler
)) {
8900 t3
= ind_table(handler
);
8901 for (op3
= 0; op3
< 32; op3
++) {
8903 if (handler
->count
== 0) {
8906 qemu_printf("%02x %02x %02x (%02x %04d) %16s: "
8907 "%016" PRIx64
" %" PRId64
"\n",
8908 op1
, op2
, op3
, op1
, (op3
<< 5) | op2
,
8910 handler
->count
, handler
->count
);
8913 if (handler
->count
== 0) {
8916 qemu_printf("%02x %02x (%02x %04d) %16s: "
8917 "%016" PRIx64
" %" PRId64
"\n",
8918 op1
, op2
, op1
, op2
, handler
->oname
,
8919 handler
->count
, handler
->count
);
8923 if (handler
->count
== 0) {
8926 qemu_printf("%02x (%02x ) %16s: %016" PRIx64
8928 op1
, op1
, handler
->oname
,
8929 handler
->count
, handler
->count
);
8935 static bool decode_legacy(PowerPCCPU
*cpu
, DisasContext
*ctx
, uint32_t insn
)
8937 opc_handler_t
**table
, *handler
;
8942 LOG_DISAS("translate opcode %08x (%02x %02x %02x %02x) (%s)\n",
8943 insn
, opc1(insn
), opc2(insn
), opc3(insn
), opc4(insn
),
8944 ctx
->le_mode
? "little" : "big");
8946 table
= cpu
->opcodes
;
8947 handler
= table
[opc1(insn
)];
8948 if (is_indirect_opcode(handler
)) {
8949 table
= ind_table(handler
);
8950 handler
= table
[opc2(insn
)];
8951 if (is_indirect_opcode(handler
)) {
8952 table
= ind_table(handler
);
8953 handler
= table
[opc3(insn
)];
8954 if (is_indirect_opcode(handler
)) {
8955 table
= ind_table(handler
);
8956 handler
= table
[opc4(insn
)];
8961 /* Is opcode *REALLY* valid ? */
8962 if (unlikely(handler
->handler
== &gen_invalid
)) {
8963 qemu_log_mask(LOG_GUEST_ERROR
, "invalid/unsupported opcode: "
8964 "%02x - %02x - %02x - %02x (%08x) "
8966 opc1(insn
), opc2(insn
), opc3(insn
), opc4(insn
),
8971 if (unlikely(handler
->type
& (PPC_SPE
| PPC_SPE_SINGLE
| PPC_SPE_DOUBLE
)
8973 inval
= handler
->inval2
;
8975 inval
= handler
->inval1
;
8978 if (unlikely((insn
& inval
) != 0)) {
8979 qemu_log_mask(LOG_GUEST_ERROR
, "invalid bits: %08x for opcode: "
8980 "%02x - %02x - %02x - %02x (%08x) "
8981 TARGET_FMT_lx
"\n", insn
& inval
,
8982 opc1(insn
), opc2(insn
), opc3(insn
), opc4(insn
),
8987 handler
->handler(ctx
);
8991 static void ppc_tr_init_disas_context(DisasContextBase
*dcbase
, CPUState
*cs
)
8993 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
8994 CPUPPCState
*env
= cs
->env_ptr
;
8995 uint32_t hflags
= ctx
->base
.tb
->flags
;
8997 ctx
->spr_cb
= env
->spr_cb
;
8998 ctx
->pr
= (hflags
>> HFLAGS_PR
) & 1;
8999 ctx
->mem_idx
= (hflags
>> HFLAGS_DMMU_IDX
) & 7;
9000 ctx
->dr
= (hflags
>> HFLAGS_DR
) & 1;
9001 ctx
->hv
= (hflags
>> HFLAGS_HV
) & 1;
9002 ctx
->insns_flags
= env
->insns_flags
;
9003 ctx
->insns_flags2
= env
->insns_flags2
;
9004 ctx
->access_type
= -1;
9005 ctx
->need_access_type
= !mmu_is_64bit(env
->mmu_model
);
9006 ctx
->le_mode
= (hflags
>> HFLAGS_LE
) & 1;
9007 ctx
->default_tcg_memop_mask
= ctx
->le_mode
? MO_LE
: MO_BE
;
9008 ctx
->flags
= env
->flags
;
9009 #if defined(TARGET_PPC64)
9010 ctx
->sf_mode
= (hflags
>> HFLAGS_64
) & 1;
9011 ctx
->has_cfar
= !!(env
->flags
& POWERPC_FLAG_CFAR
);
9013 ctx
->lazy_tlb_flush
= env
->mmu_model
== POWERPC_MMU_32B
9014 || env
->mmu_model
== POWERPC_MMU_601
9015 || env
->mmu_model
& POWERPC_MMU_64
;
9017 ctx
->fpu_enabled
= (hflags
>> HFLAGS_FP
) & 1;
9018 ctx
->spe_enabled
= (hflags
>> HFLAGS_SPE
) & 1;
9019 ctx
->altivec_enabled
= (hflags
>> HFLAGS_VR
) & 1;
9020 ctx
->vsx_enabled
= (hflags
>> HFLAGS_VSX
) & 1;
9021 ctx
->tm_enabled
= (hflags
>> HFLAGS_TM
) & 1;
9022 ctx
->gtse
= (hflags
>> HFLAGS_GTSE
) & 1;
9024 ctx
->singlestep_enabled
= 0;
9025 if ((hflags
>> HFLAGS_SE
) & 1) {
9026 ctx
->singlestep_enabled
|= CPU_SINGLE_STEP
;
9028 if ((hflags
>> HFLAGS_BE
) & 1) {
9029 ctx
->singlestep_enabled
|= CPU_BRANCH_STEP
;
9031 if (unlikely(ctx
->base
.singlestep_enabled
)) {
9032 ctx
->singlestep_enabled
|= GDBSTUB_SINGLE_STEP
;
9035 if (ctx
->singlestep_enabled
& (CPU_SINGLE_STEP
| GDBSTUB_SINGLE_STEP
)) {
9036 ctx
->base
.max_insns
= 1;
9038 int bound
= -(ctx
->base
.pc_first
| TARGET_PAGE_MASK
) / 4;
9039 ctx
->base
.max_insns
= MIN(ctx
->base
.max_insns
, bound
);
9043 static void ppc_tr_tb_start(DisasContextBase
*db
, CPUState
*cs
)
9047 static void ppc_tr_insn_start(DisasContextBase
*dcbase
, CPUState
*cs
)
9049 tcg_gen_insn_start(dcbase
->pc_next
);
9052 static bool ppc_tr_breakpoint_check(DisasContextBase
*dcbase
, CPUState
*cs
,
9053 const CPUBreakpoint
*bp
)
9055 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
9057 gen_update_nip(ctx
, ctx
->base
.pc_next
);
9058 gen_debug_exception(ctx
);
9060 * The address covered by the breakpoint must be included in
9061 * [tb->pc, tb->pc + tb->size) in order to for it to be properly
9062 * cleared -- thus we increment the PC here so that the logic
9063 * setting tb->size below does the right thing.
9065 ctx
->base
.pc_next
+= 4;
9069 static void ppc_tr_translate_insn(DisasContextBase
*dcbase
, CPUState
*cs
)
9071 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
9072 PowerPCCPU
*cpu
= POWERPC_CPU(cs
);
9073 CPUPPCState
*env
= cs
->env_ptr
;
9077 LOG_DISAS("----------------\n");
9078 LOG_DISAS("nip=" TARGET_FMT_lx
" super=%d ir=%d\n",
9079 ctx
->base
.pc_next
, ctx
->mem_idx
, (int)msr_ir
);
9081 ctx
->cia
= ctx
->base
.pc_next
;
9082 insn
= translator_ldl_swap(env
, ctx
->base
.pc_next
, need_byteswap(ctx
));
9083 ctx
->base
.pc_next
+= 4;
9085 ok
= decode_legacy(cpu
, ctx
, insn
);
9090 #if defined(DO_PPC_STATISTICS)
9094 translator_loop_temp_check(&ctx
->base
);
9097 static void ppc_tr_tb_stop(DisasContextBase
*dcbase
, CPUState
*cs
)
9099 DisasContext
*ctx
= container_of(dcbase
, DisasContext
, base
);
9100 DisasJumpType is_jmp
= ctx
->base
.is_jmp
;
9101 target_ulong nip
= ctx
->base
.pc_next
;
9104 if (is_jmp
== DISAS_NORETURN
) {
9105 /* We have already exited the TB. */
9109 /* Honor single stepping. */
9110 sse
= ctx
->singlestep_enabled
& (CPU_SINGLE_STEP
| GDBSTUB_SINGLE_STEP
);
9111 if (unlikely(sse
)) {
9113 case DISAS_TOO_MANY
:
9114 case DISAS_EXIT_UPDATE
:
9115 case DISAS_CHAIN_UPDATE
:
9116 gen_update_nip(ctx
, nip
);
9122 g_assert_not_reached();
9125 if (sse
& GDBSTUB_SINGLE_STEP
) {
9126 gen_debug_exception(ctx
);
9129 /* else CPU_SINGLE_STEP... */
9130 if (nip
<= 0x100 || nip
> 0xf00) {
9131 gen_exception(ctx
, gen_prep_dbgex(ctx
));
9137 case DISAS_TOO_MANY
:
9138 if (use_goto_tb(ctx
, nip
)) {
9140 gen_update_nip(ctx
, nip
);
9141 tcg_gen_exit_tb(ctx
->base
.tb
, 0);
9145 case DISAS_CHAIN_UPDATE
:
9146 gen_update_nip(ctx
, nip
);
9149 tcg_gen_lookup_and_goto_ptr();
9152 case DISAS_EXIT_UPDATE
:
9153 gen_update_nip(ctx
, nip
);
9156 tcg_gen_exit_tb(NULL
, 0);
9160 g_assert_not_reached();
9164 static void ppc_tr_disas_log(const DisasContextBase
*dcbase
, CPUState
*cs
)
9166 qemu_log("IN: %s\n", lookup_symbol(dcbase
->pc_first
));
9167 log_target_disas(cs
, dcbase
->pc_first
, dcbase
->tb
->size
);
9170 static const TranslatorOps ppc_tr_ops
= {
9171 .init_disas_context
= ppc_tr_init_disas_context
,
9172 .tb_start
= ppc_tr_tb_start
,
9173 .insn_start
= ppc_tr_insn_start
,
9174 .breakpoint_check
= ppc_tr_breakpoint_check
,
9175 .translate_insn
= ppc_tr_translate_insn
,
9176 .tb_stop
= ppc_tr_tb_stop
,
9177 .disas_log
= ppc_tr_disas_log
,
9180 void gen_intermediate_code(CPUState
*cs
, TranslationBlock
*tb
, int max_insns
)
9184 translator_loop(&ppc_tr_ops
, &ctx
.base
, cs
, tb
, max_insns
);
9187 void restore_state_to_opc(CPUPPCState
*env
, TranslationBlock
*tb
,