]>
Commit | Line | Data |
---|---|---|
79aceca5 | 1 | /* |
3fc6c082 | 2 | * PowerPC emulation for qemu: main translation routines. |
5fafdf24 | 3 | * |
76a66253 | 4 | * Copyright (c) 2003-2007 Jocelyn Mayer |
90dc8812 | 5 | * Copyright (C) 2011 Freescale Semiconductor, Inc. |
79aceca5 FB |
6 | * |
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 of the License, or (at your option) any later version. | |
11 | * | |
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. | |
16 | * | |
17 | * You should have received a copy of the GNU Lesser General Public | |
8167ee88 | 18 | * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
79aceca5 | 19 | */ |
c6a1c22b | 20 | |
0d75590d | 21 | #include "qemu/osdep.h" |
79aceca5 | 22 | #include "cpu.h" |
3e00884f | 23 | #include "internal.h" |
76cad711 | 24 | #include "disas/disas.h" |
63c91552 | 25 | #include "exec/exec-all.h" |
57fec1fe | 26 | #include "tcg-op.h" |
1de7afc9 | 27 | #include "qemu/host-utils.h" |
f08b6170 | 28 | #include "exec/cpu_ldst.h" |
79aceca5 | 29 | |
2ef6175a RH |
30 | #include "exec/helper-proto.h" |
31 | #include "exec/helper-gen.h" | |
a7812ae4 | 32 | |
a7e30d84 | 33 | #include "trace-tcg.h" |
b6bac4bc | 34 | #include "exec/translator.h" |
508127e2 | 35 | #include "exec/log.h" |
f34ec0f6 | 36 | #include "qemu/atomic128.h" |
a7e30d84 LV |
37 | |
38 | ||
8cbcb4fa AJ |
39 | #define CPU_SINGLE_STEP 0x1 |
40 | #define CPU_BRANCH_STEP 0x2 | |
41 | #define GDBSTUB_SINGLE_STEP 0x4 | |
42 | ||
a750fc0b | 43 | /* Include definitions for instructions classes and implementations flags */ |
9fddaa0c | 44 | //#define PPC_DEBUG_DISAS |
76a66253 | 45 | //#define DO_PPC_STATISTICS |
79aceca5 | 46 | |
d12d51d5 | 47 | #ifdef PPC_DEBUG_DISAS |
93fcfe39 | 48 | # define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__) |
d12d51d5 AL |
49 | #else |
50 | # define LOG_DISAS(...) do { } while (0) | |
51 | #endif | |
a750fc0b JM |
52 | /*****************************************************************************/ |
53 | /* Code translation helpers */ | |
c53be334 | 54 | |
f78fb44e | 55 | /* global register indexes */ |
1d542695 | 56 | static char cpu_reg_names[10*3 + 22*4 /* GPR */ |
1d542695 | 57 | + 10*4 + 22*5 /* SPE GPRh */ |
47e4661c | 58 | + 8*5 /* CRF */]; |
f78fb44e | 59 | static TCGv cpu_gpr[32]; |
f78fb44e | 60 | static TCGv cpu_gprh[32]; |
a7812ae4 | 61 | static TCGv_i32 cpu_crf[8]; |
bd568f18 | 62 | static TCGv cpu_nip; |
6527f6ea | 63 | static TCGv cpu_msr; |
cfdcd37a AJ |
64 | static TCGv cpu_ctr; |
65 | static TCGv cpu_lr; | |
697ab892 DG |
66 | #if defined(TARGET_PPC64) |
67 | static TCGv cpu_cfar; | |
68 | #endif | |
dd09c361 | 69 | static TCGv cpu_xer, cpu_so, cpu_ov, cpu_ca, cpu_ov32, cpu_ca32; |
cf360a32 | 70 | static TCGv cpu_reserve; |
253ce7b2 | 71 | static TCGv cpu_reserve_val; |
30304420 | 72 | static TCGv cpu_fpscr; |
a7859e89 | 73 | static TCGv_i32 cpu_access_type; |
f78fb44e | 74 | |
022c62cb | 75 | #include "exec/gen-icount.h" |
2e70f6ef PB |
76 | |
77 | void ppc_translate_init(void) | |
78 | { | |
f78fb44e AJ |
79 | int i; |
80 | char* p; | |
2dc766da | 81 | size_t cpu_reg_names_size; |
f78fb44e | 82 | |
f78fb44e | 83 | p = cpu_reg_names; |
2dc766da | 84 | cpu_reg_names_size = sizeof(cpu_reg_names); |
47e4661c AJ |
85 | |
86 | for (i = 0; i < 8; i++) { | |
2dc766da | 87 | snprintf(p, cpu_reg_names_size, "crf%d", i); |
e1ccc054 | 88 | cpu_crf[i] = tcg_global_mem_new_i32(cpu_env, |
1328c2bf | 89 | offsetof(CPUPPCState, crf[i]), p); |
47e4661c | 90 | p += 5; |
2dc766da | 91 | cpu_reg_names_size -= 5; |
47e4661c AJ |
92 | } |
93 | ||
f78fb44e | 94 | for (i = 0; i < 32; i++) { |
2dc766da | 95 | snprintf(p, cpu_reg_names_size, "r%d", i); |
e1ccc054 | 96 | cpu_gpr[i] = tcg_global_mem_new(cpu_env, |
1328c2bf | 97 | offsetof(CPUPPCState, gpr[i]), p); |
f78fb44e | 98 | p += (i < 10) ? 3 : 4; |
2dc766da | 99 | cpu_reg_names_size -= (i < 10) ? 3 : 4; |
2dc766da | 100 | snprintf(p, cpu_reg_names_size, "r%dH", i); |
e1ccc054 | 101 | cpu_gprh[i] = tcg_global_mem_new(cpu_env, |
13b6a455 | 102 | offsetof(CPUPPCState, gprh[i]), p); |
f78fb44e | 103 | p += (i < 10) ? 4 : 5; |
2dc766da | 104 | cpu_reg_names_size -= (i < 10) ? 4 : 5; |
f78fb44e | 105 | } |
f10dc08e | 106 | |
e1ccc054 | 107 | cpu_nip = tcg_global_mem_new(cpu_env, |
1328c2bf | 108 | offsetof(CPUPPCState, nip), "nip"); |
bd568f18 | 109 | |
e1ccc054 | 110 | cpu_msr = tcg_global_mem_new(cpu_env, |
1328c2bf | 111 | offsetof(CPUPPCState, msr), "msr"); |
6527f6ea | 112 | |
e1ccc054 | 113 | cpu_ctr = tcg_global_mem_new(cpu_env, |
1328c2bf | 114 | offsetof(CPUPPCState, ctr), "ctr"); |
cfdcd37a | 115 | |
e1ccc054 | 116 | cpu_lr = tcg_global_mem_new(cpu_env, |
1328c2bf | 117 | offsetof(CPUPPCState, lr), "lr"); |
cfdcd37a | 118 | |
697ab892 | 119 | #if defined(TARGET_PPC64) |
e1ccc054 | 120 | cpu_cfar = tcg_global_mem_new(cpu_env, |
1328c2bf | 121 | offsetof(CPUPPCState, cfar), "cfar"); |
697ab892 DG |
122 | #endif |
123 | ||
e1ccc054 | 124 | cpu_xer = tcg_global_mem_new(cpu_env, |
1328c2bf | 125 | offsetof(CPUPPCState, xer), "xer"); |
e1ccc054 | 126 | cpu_so = tcg_global_mem_new(cpu_env, |
da91a00f | 127 | offsetof(CPUPPCState, so), "SO"); |
e1ccc054 | 128 | cpu_ov = tcg_global_mem_new(cpu_env, |
da91a00f | 129 | offsetof(CPUPPCState, ov), "OV"); |
e1ccc054 | 130 | cpu_ca = tcg_global_mem_new(cpu_env, |
da91a00f | 131 | offsetof(CPUPPCState, ca), "CA"); |
dd09c361 ND |
132 | cpu_ov32 = tcg_global_mem_new(cpu_env, |
133 | offsetof(CPUPPCState, ov32), "OV32"); | |
134 | cpu_ca32 = tcg_global_mem_new(cpu_env, | |
135 | offsetof(CPUPPCState, ca32), "CA32"); | |
3d7b417e | 136 | |
e1ccc054 | 137 | cpu_reserve = tcg_global_mem_new(cpu_env, |
1328c2bf | 138 | offsetof(CPUPPCState, reserve_addr), |
18b21a2f | 139 | "reserve_addr"); |
253ce7b2 ND |
140 | cpu_reserve_val = tcg_global_mem_new(cpu_env, |
141 | offsetof(CPUPPCState, reserve_val), | |
142 | "reserve_val"); | |
cf360a32 | 143 | |
e1ccc054 | 144 | cpu_fpscr = tcg_global_mem_new(cpu_env, |
30304420 | 145 | offsetof(CPUPPCState, fpscr), "fpscr"); |
e1571908 | 146 | |
e1ccc054 | 147 | cpu_access_type = tcg_global_mem_new_i32(cpu_env, |
1328c2bf | 148 | offsetof(CPUPPCState, access_type), "access_type"); |
2e70f6ef PB |
149 | } |
150 | ||
79aceca5 | 151 | /* internal defines */ |
69b058c8 | 152 | struct DisasContext { |
b6bac4bc | 153 | DisasContextBase base; |
79aceca5 | 154 | uint32_t opcode; |
9a64fbe4 | 155 | uint32_t exception; |
3cc62370 | 156 | /* Routine used to access memory */ |
5c3ae929 | 157 | bool pr, hv, dr, le_mode; |
c5a8d8f3 | 158 | bool lazy_tlb_flush; |
5f2a6254 | 159 | bool need_access_type; |
3cc62370 | 160 | int mem_idx; |
76db3ba4 | 161 | int access_type; |
3cc62370 | 162 | /* Translation flags */ |
e22c357b | 163 | TCGMemOp default_tcg_memop_mask; |
d9bce9d9 | 164 | #if defined(TARGET_PPC64) |
5c3ae929 BH |
165 | bool sf_mode; |
166 | bool has_cfar; | |
9a64fbe4 | 167 | #endif |
5c3ae929 BH |
168 | bool fpu_enabled; |
169 | bool altivec_enabled; | |
170 | bool vsx_enabled; | |
171 | bool spe_enabled; | |
172 | bool tm_enabled; | |
c6fd28fd | 173 | bool gtse; |
c227f099 | 174 | ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */ |
ea4e754f | 175 | int singlestep_enabled; |
0e3bf489 | 176 | uint32_t flags; |
7d08d856 AJ |
177 | uint64_t insns_flags; |
178 | uint64_t insns_flags2; | |
69b058c8 | 179 | }; |
79aceca5 | 180 | |
e22c357b DK |
181 | /* Return true iff byteswap is needed in a scalar memop */ |
182 | static inline bool need_byteswap(const DisasContext *ctx) | |
183 | { | |
184 | #if defined(TARGET_WORDS_BIGENDIAN) | |
185 | return ctx->le_mode; | |
186 | #else | |
187 | return !ctx->le_mode; | |
188 | #endif | |
189 | } | |
190 | ||
79482e5a RH |
191 | /* True when active word size < size of target_long. */ |
192 | #ifdef TARGET_PPC64 | |
193 | # define NARROW_MODE(C) (!(C)->sf_mode) | |
194 | #else | |
195 | # define NARROW_MODE(C) 0 | |
196 | #endif | |
197 | ||
c227f099 | 198 | struct opc_handler_t { |
70560da7 FC |
199 | /* invalid bits for instruction 1 (Rc(opcode) == 0) */ |
200 | uint32_t inval1; | |
201 | /* invalid bits for instruction 2 (Rc(opcode) == 1) */ | |
202 | uint32_t inval2; | |
9a64fbe4 | 203 | /* instruction type */ |
0487d6a8 | 204 | uint64_t type; |
a5858d7a AG |
205 | /* extended instruction type */ |
206 | uint64_t type2; | |
79aceca5 FB |
207 | /* handler */ |
208 | void (*handler)(DisasContext *ctx); | |
a750fc0b | 209 | #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU) |
b55266b5 | 210 | const char *oname; |
a750fc0b JM |
211 | #endif |
212 | #if defined(DO_PPC_STATISTICS) | |
76a66253 JM |
213 | uint64_t count; |
214 | #endif | |
3fc6c082 | 215 | }; |
79aceca5 | 216 | |
0e3bf489 RK |
217 | /* SPR load/store helpers */ |
218 | static inline void gen_load_spr(TCGv t, int reg) | |
219 | { | |
220 | tcg_gen_ld_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg])); | |
221 | } | |
222 | ||
223 | static inline void gen_store_spr(int reg, TCGv t) | |
224 | { | |
225 | tcg_gen_st_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg])); | |
226 | } | |
227 | ||
636aa200 | 228 | static inline void gen_set_access_type(DisasContext *ctx, int access_type) |
a7859e89 | 229 | { |
5f2a6254 | 230 | if (ctx->need_access_type && ctx->access_type != access_type) { |
76db3ba4 AJ |
231 | tcg_gen_movi_i32(cpu_access_type, access_type); |
232 | ctx->access_type = access_type; | |
233 | } | |
a7859e89 AJ |
234 | } |
235 | ||
636aa200 | 236 | static inline void gen_update_nip(DisasContext *ctx, target_ulong nip) |
d9bce9d9 | 237 | { |
e0c8f9ce RH |
238 | if (NARROW_MODE(ctx)) { |
239 | nip = (uint32_t)nip; | |
240 | } | |
241 | tcg_gen_movi_tl(cpu_nip, nip); | |
d9bce9d9 JM |
242 | } |
243 | ||
b9971cc5 | 244 | static void gen_exception_err(DisasContext *ctx, uint32_t excp, uint32_t error) |
e06fcd75 AJ |
245 | { |
246 | TCGv_i32 t0, t1; | |
bd6fefe7 BH |
247 | |
248 | /* These are all synchronous exceptions, we set the PC back to | |
249 | * the faulting instruction | |
250 | */ | |
e06fcd75 | 251 | if (ctx->exception == POWERPC_EXCP_NONE) { |
b6bac4bc | 252 | gen_update_nip(ctx, ctx->base.pc_next - 4); |
e06fcd75 AJ |
253 | } |
254 | t0 = tcg_const_i32(excp); | |
255 | t1 = tcg_const_i32(error); | |
e5f17ac6 | 256 | gen_helper_raise_exception_err(cpu_env, t0, t1); |
e06fcd75 AJ |
257 | tcg_temp_free_i32(t0); |
258 | tcg_temp_free_i32(t1); | |
259 | ctx->exception = (excp); | |
260 | } | |
e1833e1f | 261 | |
b9971cc5 | 262 | static void gen_exception(DisasContext *ctx, uint32_t excp) |
e06fcd75 AJ |
263 | { |
264 | TCGv_i32 t0; | |
bd6fefe7 BH |
265 | |
266 | /* These are all synchronous exceptions, we set the PC back to | |
267 | * the faulting instruction | |
268 | */ | |
e06fcd75 | 269 | if (ctx->exception == POWERPC_EXCP_NONE) { |
b6bac4bc | 270 | gen_update_nip(ctx, ctx->base.pc_next - 4); |
e06fcd75 AJ |
271 | } |
272 | t0 = tcg_const_i32(excp); | |
e5f17ac6 | 273 | gen_helper_raise_exception(cpu_env, t0); |
e06fcd75 AJ |
274 | tcg_temp_free_i32(t0); |
275 | ctx->exception = (excp); | |
276 | } | |
e1833e1f | 277 | |
bd6fefe7 BH |
278 | static void gen_exception_nip(DisasContext *ctx, uint32_t excp, |
279 | target_ulong nip) | |
280 | { | |
281 | TCGv_i32 t0; | |
282 | ||
283 | gen_update_nip(ctx, nip); | |
284 | t0 = tcg_const_i32(excp); | |
285 | gen_helper_raise_exception(cpu_env, t0); | |
286 | tcg_temp_free_i32(t0); | |
287 | ctx->exception = (excp); | |
288 | } | |
289 | ||
e150ac89 RK |
290 | /* |
291 | * Tells the caller what is the appropriate exception to generate and prepares | |
292 | * SPR registers for this exception. | |
293 | * | |
294 | * The exception can be either POWERPC_EXCP_TRACE (on most PowerPCs) or | |
295 | * POWERPC_EXCP_DEBUG (on BookE). | |
0e3bf489 | 296 | */ |
e150ac89 | 297 | static uint32_t gen_prep_dbgex(DisasContext *ctx) |
0e3bf489 | 298 | { |
0e3bf489 RK |
299 | if (ctx->flags & POWERPC_FLAG_DE) { |
300 | target_ulong dbsr = 0; | |
e150ac89 | 301 | if (ctx->singlestep_enabled & CPU_SINGLE_STEP) { |
0e3bf489 | 302 | dbsr = DBCR0_ICMP; |
e150ac89 RK |
303 | } else { |
304 | /* Must have been branch */ | |
0e3bf489 | 305 | dbsr = DBCR0_BRT; |
0e3bf489 RK |
306 | } |
307 | TCGv t0 = tcg_temp_new(); | |
308 | gen_load_spr(t0, SPR_BOOKE_DBSR); | |
309 | tcg_gen_ori_tl(t0, t0, dbsr); | |
310 | gen_store_spr(SPR_BOOKE_DBSR, t0); | |
311 | tcg_temp_free(t0); | |
312 | return POWERPC_EXCP_DEBUG; | |
313 | } else { | |
e150ac89 | 314 | return POWERPC_EXCP_TRACE; |
0e3bf489 RK |
315 | } |
316 | } | |
317 | ||
b9971cc5 | 318 | static void gen_debug_exception(DisasContext *ctx) |
e06fcd75 AJ |
319 | { |
320 | TCGv_i32 t0; | |
5518f3a6 | 321 | |
bd6fefe7 BH |
322 | /* These are all synchronous exceptions, we set the PC back to |
323 | * the faulting instruction | |
324 | */ | |
ee2b3994 SB |
325 | if ((ctx->exception != POWERPC_EXCP_BRANCH) && |
326 | (ctx->exception != POWERPC_EXCP_SYNC)) { | |
b6bac4bc | 327 | gen_update_nip(ctx, ctx->base.pc_next); |
ee2b3994 | 328 | } |
e06fcd75 | 329 | t0 = tcg_const_i32(EXCP_DEBUG); |
e5f17ac6 | 330 | gen_helper_raise_exception(cpu_env, t0); |
e06fcd75 AJ |
331 | tcg_temp_free_i32(t0); |
332 | } | |
9a64fbe4 | 333 | |
636aa200 | 334 | static inline void gen_inval_exception(DisasContext *ctx, uint32_t error) |
e06fcd75 | 335 | { |
9b2fadda BH |
336 | /* Will be converted to program check if needed */ |
337 | gen_exception_err(ctx, POWERPC_EXCP_HV_EMU, POWERPC_EXCP_INVAL | error); | |
338 | } | |
339 | ||
340 | static inline void gen_priv_exception(DisasContext *ctx, uint32_t error) | |
341 | { | |
342 | gen_exception_err(ctx, POWERPC_EXCP_PROGRAM, POWERPC_EXCP_PRIV | error); | |
343 | } | |
344 | ||
345 | static inline void gen_hvpriv_exception(DisasContext *ctx, uint32_t error) | |
346 | { | |
347 | /* Will be converted to program check if needed */ | |
348 | gen_exception_err(ctx, POWERPC_EXCP_HV_EMU, POWERPC_EXCP_PRIV | error); | |
e06fcd75 | 349 | } |
a9d9eb8f | 350 | |
f24e5695 | 351 | /* Stop translation */ |
636aa200 | 352 | static inline void gen_stop_exception(DisasContext *ctx) |
3fc6c082 | 353 | { |
b6bac4bc | 354 | gen_update_nip(ctx, ctx->base.pc_next); |
e1833e1f | 355 | ctx->exception = POWERPC_EXCP_STOP; |
3fc6c082 FB |
356 | } |
357 | ||
466976d9 | 358 | #ifndef CONFIG_USER_ONLY |
f24e5695 | 359 | /* No need to update nip here, as execution flow will change */ |
636aa200 | 360 | static inline void gen_sync_exception(DisasContext *ctx) |
2be0071f | 361 | { |
e1833e1f | 362 | ctx->exception = POWERPC_EXCP_SYNC; |
2be0071f | 363 | } |
466976d9 | 364 | #endif |
2be0071f | 365 | |
79aceca5 | 366 | #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \ |
a5858d7a AG |
367 | GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE) |
368 | ||
369 | #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \ | |
370 | GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2) | |
79aceca5 | 371 | |
c7697e1f | 372 | #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \ |
a5858d7a AG |
373 | GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE) |
374 | ||
375 | #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \ | |
376 | GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2) | |
c7697e1f | 377 | |
323ad19b ND |
378 | #define GEN_HANDLER_E_2(name, opc1, opc2, opc3, opc4, inval, type, type2) \ |
379 | GEN_OPCODE3(name, opc1, opc2, opc3, opc4, inval, type, type2) | |
380 | ||
14fd8ab2 ND |
381 | #define GEN_HANDLER2_E_2(name, onam, opc1, opc2, opc3, opc4, inval, typ, typ2) \ |
382 | GEN_OPCODE4(name, onam, opc1, opc2, opc3, opc4, inval, typ, typ2) | |
383 | ||
c227f099 | 384 | typedef struct opcode_t { |
323ad19b | 385 | unsigned char opc1, opc2, opc3, opc4; |
1235fc06 | 386 | #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */ |
323ad19b | 387 | unsigned char pad[4]; |
18fba28c | 388 | #endif |
c227f099 | 389 | opc_handler_t handler; |
b55266b5 | 390 | const char *oname; |
c227f099 | 391 | } opcode_t; |
79aceca5 | 392 | |
9b2fadda BH |
393 | /* Helpers for priv. check */ |
394 | #define GEN_PRIV \ | |
395 | do { \ | |
396 | gen_priv_exception(ctx, POWERPC_EXCP_PRIV_OPC); return; \ | |
397 | } while (0) | |
398 | ||
399 | #if defined(CONFIG_USER_ONLY) | |
400 | #define CHK_HV GEN_PRIV | |
401 | #define CHK_SV GEN_PRIV | |
b7815375 | 402 | #define CHK_HVRM GEN_PRIV |
9b2fadda BH |
403 | #else |
404 | #define CHK_HV \ | |
405 | do { \ | |
406 | if (unlikely(ctx->pr || !ctx->hv)) { \ | |
407 | GEN_PRIV; \ | |
408 | } \ | |
409 | } while (0) | |
410 | #define CHK_SV \ | |
411 | do { \ | |
412 | if (unlikely(ctx->pr)) { \ | |
413 | GEN_PRIV; \ | |
414 | } \ | |
415 | } while (0) | |
b7815375 BH |
416 | #define CHK_HVRM \ |
417 | do { \ | |
418 | if (unlikely(ctx->pr || !ctx->hv || ctx->dr)) { \ | |
419 | GEN_PRIV; \ | |
420 | } \ | |
421 | } while (0) | |
9b2fadda BH |
422 | #endif |
423 | ||
424 | #define CHK_NONE | |
425 | ||
a750fc0b | 426 | /*****************************************************************************/ |
a750fc0b | 427 | /* PowerPC instructions table */ |
933dc6eb | 428 | |
76a66253 | 429 | #if defined(DO_PPC_STATISTICS) |
a5858d7a | 430 | #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \ |
5c55ff99 | 431 | { \ |
79aceca5 FB |
432 | .opc1 = op1, \ |
433 | .opc2 = op2, \ | |
434 | .opc3 = op3, \ | |
323ad19b | 435 | .opc4 = 0xff, \ |
79aceca5 | 436 | .handler = { \ |
70560da7 FC |
437 | .inval1 = invl, \ |
438 | .type = _typ, \ | |
439 | .type2 = _typ2, \ | |
440 | .handler = &gen_##name, \ | |
441 | .oname = stringify(name), \ | |
442 | }, \ | |
443 | .oname = stringify(name), \ | |
444 | } | |
445 | #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \ | |
446 | { \ | |
447 | .opc1 = op1, \ | |
448 | .opc2 = op2, \ | |
449 | .opc3 = op3, \ | |
323ad19b | 450 | .opc4 = 0xff, \ |
70560da7 FC |
451 | .handler = { \ |
452 | .inval1 = invl1, \ | |
453 | .inval2 = invl2, \ | |
9a64fbe4 | 454 | .type = _typ, \ |
a5858d7a | 455 | .type2 = _typ2, \ |
79aceca5 | 456 | .handler = &gen_##name, \ |
76a66253 | 457 | .oname = stringify(name), \ |
79aceca5 | 458 | }, \ |
3fc6c082 | 459 | .oname = stringify(name), \ |
79aceca5 | 460 | } |
a5858d7a | 461 | #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \ |
5c55ff99 | 462 | { \ |
c7697e1f JM |
463 | .opc1 = op1, \ |
464 | .opc2 = op2, \ | |
465 | .opc3 = op3, \ | |
323ad19b | 466 | .opc4 = 0xff, \ |
c7697e1f | 467 | .handler = { \ |
70560da7 | 468 | .inval1 = invl, \ |
c7697e1f | 469 | .type = _typ, \ |
a5858d7a | 470 | .type2 = _typ2, \ |
c7697e1f JM |
471 | .handler = &gen_##name, \ |
472 | .oname = onam, \ | |
473 | }, \ | |
474 | .oname = onam, \ | |
475 | } | |
323ad19b ND |
476 | #define GEN_OPCODE3(name, op1, op2, op3, op4, invl, _typ, _typ2) \ |
477 | { \ | |
478 | .opc1 = op1, \ | |
479 | .opc2 = op2, \ | |
480 | .opc3 = op3, \ | |
481 | .opc4 = op4, \ | |
482 | .handler = { \ | |
483 | .inval1 = invl, \ | |
484 | .type = _typ, \ | |
485 | .type2 = _typ2, \ | |
486 | .handler = &gen_##name, \ | |
487 | .oname = stringify(name), \ | |
488 | }, \ | |
489 | .oname = stringify(name), \ | |
490 | } | |
14fd8ab2 ND |
491 | #define GEN_OPCODE4(name, onam, op1, op2, op3, op4, invl, _typ, _typ2) \ |
492 | { \ | |
493 | .opc1 = op1, \ | |
494 | .opc2 = op2, \ | |
495 | .opc3 = op3, \ | |
496 | .opc4 = op4, \ | |
497 | .handler = { \ | |
498 | .inval1 = invl, \ | |
499 | .type = _typ, \ | |
500 | .type2 = _typ2, \ | |
501 | .handler = &gen_##name, \ | |
502 | .oname = onam, \ | |
503 | }, \ | |
504 | .oname = onam, \ | |
505 | } | |
76a66253 | 506 | #else |
a5858d7a | 507 | #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \ |
5c55ff99 | 508 | { \ |
c7697e1f JM |
509 | .opc1 = op1, \ |
510 | .opc2 = op2, \ | |
511 | .opc3 = op3, \ | |
323ad19b | 512 | .opc4 = 0xff, \ |
c7697e1f | 513 | .handler = { \ |
70560da7 FC |
514 | .inval1 = invl, \ |
515 | .type = _typ, \ | |
516 | .type2 = _typ2, \ | |
517 | .handler = &gen_##name, \ | |
518 | }, \ | |
519 | .oname = stringify(name), \ | |
520 | } | |
521 | #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \ | |
522 | { \ | |
523 | .opc1 = op1, \ | |
524 | .opc2 = op2, \ | |
525 | .opc3 = op3, \ | |
323ad19b | 526 | .opc4 = 0xff, \ |
70560da7 FC |
527 | .handler = { \ |
528 | .inval1 = invl1, \ | |
529 | .inval2 = invl2, \ | |
c7697e1f | 530 | .type = _typ, \ |
a5858d7a | 531 | .type2 = _typ2, \ |
c7697e1f | 532 | .handler = &gen_##name, \ |
5c55ff99 BS |
533 | }, \ |
534 | .oname = stringify(name), \ | |
535 | } | |
a5858d7a | 536 | #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \ |
5c55ff99 BS |
537 | { \ |
538 | .opc1 = op1, \ | |
539 | .opc2 = op2, \ | |
540 | .opc3 = op3, \ | |
323ad19b | 541 | .opc4 = 0xff, \ |
5c55ff99 | 542 | .handler = { \ |
70560da7 | 543 | .inval1 = invl, \ |
5c55ff99 | 544 | .type = _typ, \ |
a5858d7a | 545 | .type2 = _typ2, \ |
5c55ff99 BS |
546 | .handler = &gen_##name, \ |
547 | }, \ | |
548 | .oname = onam, \ | |
549 | } | |
323ad19b ND |
550 | #define GEN_OPCODE3(name, op1, op2, op3, op4, invl, _typ, _typ2) \ |
551 | { \ | |
552 | .opc1 = op1, \ | |
553 | .opc2 = op2, \ | |
554 | .opc3 = op3, \ | |
555 | .opc4 = op4, \ | |
556 | .handler = { \ | |
557 | .inval1 = invl, \ | |
558 | .type = _typ, \ | |
559 | .type2 = _typ2, \ | |
560 | .handler = &gen_##name, \ | |
561 | }, \ | |
562 | .oname = stringify(name), \ | |
563 | } | |
14fd8ab2 ND |
564 | #define GEN_OPCODE4(name, onam, op1, op2, op3, op4, invl, _typ, _typ2) \ |
565 | { \ | |
566 | .opc1 = op1, \ | |
567 | .opc2 = op2, \ | |
568 | .opc3 = op3, \ | |
569 | .opc4 = op4, \ | |
570 | .handler = { \ | |
571 | .inval1 = invl, \ | |
572 | .type = _typ, \ | |
573 | .type2 = _typ2, \ | |
574 | .handler = &gen_##name, \ | |
575 | }, \ | |
576 | .oname = onam, \ | |
577 | } | |
5c55ff99 | 578 | #endif |
2e610050 | 579 | |
54623277 | 580 | /* Invalid instruction */ |
99e300ef | 581 | static void gen_invalid(DisasContext *ctx) |
9a64fbe4 | 582 | { |
e06fcd75 | 583 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
9a64fbe4 FB |
584 | } |
585 | ||
c227f099 | 586 | static opc_handler_t invalid_handler = { |
70560da7 FC |
587 | .inval1 = 0xFFFFFFFF, |
588 | .inval2 = 0xFFFFFFFF, | |
9a64fbe4 | 589 | .type = PPC_NONE, |
a5858d7a | 590 | .type2 = PPC_NONE, |
79aceca5 FB |
591 | .handler = gen_invalid, |
592 | }; | |
593 | ||
e1571908 AJ |
594 | /*** Integer comparison ***/ |
595 | ||
636aa200 | 596 | static inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf) |
e1571908 | 597 | { |
2fdcb629 | 598 | TCGv t0 = tcg_temp_new(); |
b62b3686 PB |
599 | TCGv t1 = tcg_temp_new(); |
600 | TCGv_i32 t = tcg_temp_new_i32(); | |
e1571908 | 601 | |
b62b3686 PB |
602 | tcg_gen_movi_tl(t0, CRF_EQ); |
603 | tcg_gen_movi_tl(t1, CRF_LT); | |
604 | tcg_gen_movcond_tl((s ? TCG_COND_LT : TCG_COND_LTU), t0, arg0, arg1, t1, t0); | |
605 | tcg_gen_movi_tl(t1, CRF_GT); | |
606 | tcg_gen_movcond_tl((s ? TCG_COND_GT : TCG_COND_GTU), t0, arg0, arg1, t1, t0); | |
2fdcb629 | 607 | |
b62b3686 PB |
608 | tcg_gen_trunc_tl_i32(t, t0); |
609 | tcg_gen_trunc_tl_i32(cpu_crf[crf], cpu_so); | |
610 | tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t); | |
2fdcb629 RH |
611 | |
612 | tcg_temp_free(t0); | |
b62b3686 PB |
613 | tcg_temp_free(t1); |
614 | tcg_temp_free_i32(t); | |
e1571908 AJ |
615 | } |
616 | ||
636aa200 | 617 | static inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf) |
e1571908 | 618 | { |
2fdcb629 | 619 | TCGv t0 = tcg_const_tl(arg1); |
ea363694 AJ |
620 | gen_op_cmp(arg0, t0, s, crf); |
621 | tcg_temp_free(t0); | |
e1571908 AJ |
622 | } |
623 | ||
636aa200 | 624 | static inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf) |
e1571908 | 625 | { |
ea363694 | 626 | TCGv t0, t1; |
2fdcb629 RH |
627 | t0 = tcg_temp_new(); |
628 | t1 = tcg_temp_new(); | |
e1571908 | 629 | if (s) { |
ea363694 AJ |
630 | tcg_gen_ext32s_tl(t0, arg0); |
631 | tcg_gen_ext32s_tl(t1, arg1); | |
e1571908 | 632 | } else { |
ea363694 AJ |
633 | tcg_gen_ext32u_tl(t0, arg0); |
634 | tcg_gen_ext32u_tl(t1, arg1); | |
e1571908 | 635 | } |
ea363694 AJ |
636 | gen_op_cmp(t0, t1, s, crf); |
637 | tcg_temp_free(t1); | |
638 | tcg_temp_free(t0); | |
e1571908 AJ |
639 | } |
640 | ||
636aa200 | 641 | static inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf) |
e1571908 | 642 | { |
2fdcb629 | 643 | TCGv t0 = tcg_const_tl(arg1); |
ea363694 AJ |
644 | gen_op_cmp32(arg0, t0, s, crf); |
645 | tcg_temp_free(t0); | |
e1571908 | 646 | } |
e1571908 | 647 | |
636aa200 | 648 | static inline void gen_set_Rc0(DisasContext *ctx, TCGv reg) |
e1571908 | 649 | { |
02765534 | 650 | if (NARROW_MODE(ctx)) { |
e1571908 | 651 | gen_op_cmpi32(reg, 0, 1, 0); |
02765534 | 652 | } else { |
e1571908 | 653 | gen_op_cmpi(reg, 0, 1, 0); |
02765534 | 654 | } |
e1571908 AJ |
655 | } |
656 | ||
657 | /* cmp */ | |
99e300ef | 658 | static void gen_cmp(DisasContext *ctx) |
e1571908 | 659 | { |
36f48d9c | 660 | if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) { |
e1571908 AJ |
661 | gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], |
662 | 1, crfD(ctx->opcode)); | |
36f48d9c AG |
663 | } else { |
664 | gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], | |
665 | 1, crfD(ctx->opcode)); | |
02765534 | 666 | } |
e1571908 AJ |
667 | } |
668 | ||
669 | /* cmpi */ | |
99e300ef | 670 | static void gen_cmpi(DisasContext *ctx) |
e1571908 | 671 | { |
36f48d9c | 672 | if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) { |
e1571908 AJ |
673 | gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode), |
674 | 1, crfD(ctx->opcode)); | |
36f48d9c AG |
675 | } else { |
676 | gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode), | |
677 | 1, crfD(ctx->opcode)); | |
02765534 | 678 | } |
e1571908 AJ |
679 | } |
680 | ||
681 | /* cmpl */ | |
99e300ef | 682 | static void gen_cmpl(DisasContext *ctx) |
e1571908 | 683 | { |
36f48d9c | 684 | if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) { |
e1571908 AJ |
685 | gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], |
686 | 0, crfD(ctx->opcode)); | |
36f48d9c AG |
687 | } else { |
688 | gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], | |
689 | 0, crfD(ctx->opcode)); | |
02765534 | 690 | } |
e1571908 AJ |
691 | } |
692 | ||
693 | /* cmpli */ | |
99e300ef | 694 | static void gen_cmpli(DisasContext *ctx) |
e1571908 | 695 | { |
36f48d9c | 696 | if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) { |
e1571908 AJ |
697 | gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode), |
698 | 0, crfD(ctx->opcode)); | |
36f48d9c AG |
699 | } else { |
700 | gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode), | |
701 | 0, crfD(ctx->opcode)); | |
02765534 | 702 | } |
e1571908 AJ |
703 | } |
704 | ||
f2442ef9 ND |
705 | /* cmprb - range comparison: isupper, isaplha, islower*/ |
706 | static void gen_cmprb(DisasContext *ctx) | |
707 | { | |
708 | TCGv_i32 src1 = tcg_temp_new_i32(); | |
709 | TCGv_i32 src2 = tcg_temp_new_i32(); | |
710 | TCGv_i32 src2lo = tcg_temp_new_i32(); | |
711 | TCGv_i32 src2hi = tcg_temp_new_i32(); | |
712 | TCGv_i32 crf = cpu_crf[crfD(ctx->opcode)]; | |
713 | ||
714 | tcg_gen_trunc_tl_i32(src1, cpu_gpr[rA(ctx->opcode)]); | |
715 | tcg_gen_trunc_tl_i32(src2, cpu_gpr[rB(ctx->opcode)]); | |
716 | ||
717 | tcg_gen_andi_i32(src1, src1, 0xFF); | |
718 | tcg_gen_ext8u_i32(src2lo, src2); | |
719 | tcg_gen_shri_i32(src2, src2, 8); | |
720 | tcg_gen_ext8u_i32(src2hi, src2); | |
721 | ||
722 | tcg_gen_setcond_i32(TCG_COND_LEU, src2lo, src2lo, src1); | |
723 | tcg_gen_setcond_i32(TCG_COND_LEU, src2hi, src1, src2hi); | |
724 | tcg_gen_and_i32(crf, src2lo, src2hi); | |
725 | ||
726 | if (ctx->opcode & 0x00200000) { | |
727 | tcg_gen_shri_i32(src2, src2, 8); | |
728 | tcg_gen_ext8u_i32(src2lo, src2); | |
729 | tcg_gen_shri_i32(src2, src2, 8); | |
730 | tcg_gen_ext8u_i32(src2hi, src2); | |
731 | tcg_gen_setcond_i32(TCG_COND_LEU, src2lo, src2lo, src1); | |
732 | tcg_gen_setcond_i32(TCG_COND_LEU, src2hi, src1, src2hi); | |
733 | tcg_gen_and_i32(src2lo, src2lo, src2hi); | |
734 | tcg_gen_or_i32(crf, crf, src2lo); | |
735 | } | |
efa73196 | 736 | tcg_gen_shli_i32(crf, crf, CRF_GT_BIT); |
f2442ef9 ND |
737 | tcg_temp_free_i32(src1); |
738 | tcg_temp_free_i32(src2); | |
739 | tcg_temp_free_i32(src2lo); | |
740 | tcg_temp_free_i32(src2hi); | |
741 | } | |
742 | ||
082ce330 ND |
743 | #if defined(TARGET_PPC64) |
744 | /* cmpeqb */ | |
745 | static void gen_cmpeqb(DisasContext *ctx) | |
746 | { | |
747 | gen_helper_cmpeqb(cpu_crf[crfD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], | |
748 | cpu_gpr[rB(ctx->opcode)]); | |
749 | } | |
750 | #endif | |
751 | ||
e1571908 | 752 | /* isel (PowerPC 2.03 specification) */ |
99e300ef | 753 | static void gen_isel(DisasContext *ctx) |
e1571908 | 754 | { |
e1571908 | 755 | uint32_t bi = rC(ctx->opcode); |
24f9cd95 RH |
756 | uint32_t mask = 0x08 >> (bi & 0x03); |
757 | TCGv t0 = tcg_temp_new(); | |
758 | TCGv zr; | |
e1571908 | 759 | |
24f9cd95 RH |
760 | tcg_gen_extu_i32_tl(t0, cpu_crf[bi >> 2]); |
761 | tcg_gen_andi_tl(t0, t0, mask); | |
762 | ||
763 | zr = tcg_const_tl(0); | |
764 | tcg_gen_movcond_tl(TCG_COND_NE, cpu_gpr[rD(ctx->opcode)], t0, zr, | |
765 | rA(ctx->opcode) ? cpu_gpr[rA(ctx->opcode)] : zr, | |
766 | cpu_gpr[rB(ctx->opcode)]); | |
767 | tcg_temp_free(zr); | |
768 | tcg_temp_free(t0); | |
e1571908 AJ |
769 | } |
770 | ||
fcfda20f AJ |
771 | /* cmpb: PowerPC 2.05 specification */ |
772 | static void gen_cmpb(DisasContext *ctx) | |
773 | { | |
774 | gen_helper_cmpb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], | |
775 | cpu_gpr[rB(ctx->opcode)]); | |
776 | } | |
777 | ||
79aceca5 | 778 | /*** Integer arithmetic ***/ |
79aceca5 | 779 | |
636aa200 BS |
780 | static inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0, |
781 | TCGv arg1, TCGv arg2, int sub) | |
74637406 | 782 | { |
ffe30937 | 783 | TCGv t0 = tcg_temp_new(); |
79aceca5 | 784 | |
8e7a6db9 | 785 | tcg_gen_xor_tl(cpu_ov, arg0, arg2); |
74637406 | 786 | tcg_gen_xor_tl(t0, arg1, arg2); |
ffe30937 RH |
787 | if (sub) { |
788 | tcg_gen_and_tl(cpu_ov, cpu_ov, t0); | |
789 | } else { | |
790 | tcg_gen_andc_tl(cpu_ov, cpu_ov, t0); | |
791 | } | |
792 | tcg_temp_free(t0); | |
02765534 | 793 | if (NARROW_MODE(ctx)) { |
dc0ad844 ND |
794 | tcg_gen_extract_tl(cpu_ov, cpu_ov, 31, 1); |
795 | if (is_isa300(ctx)) { | |
796 | tcg_gen_mov_tl(cpu_ov32, cpu_ov); | |
797 | } | |
798 | } else { | |
799 | if (is_isa300(ctx)) { | |
800 | tcg_gen_extract_tl(cpu_ov32, cpu_ov, 31, 1); | |
801 | } | |
38a61d34 | 802 | tcg_gen_extract_tl(cpu_ov, cpu_ov, TARGET_LONG_BITS - 1, 1); |
ffe30937 | 803 | } |
ffe30937 | 804 | tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov); |
79aceca5 FB |
805 | } |
806 | ||
6b10d008 ND |
807 | static inline void gen_op_arith_compute_ca32(DisasContext *ctx, |
808 | TCGv res, TCGv arg0, TCGv arg1, | |
4c5920af | 809 | TCGv ca32, int sub) |
6b10d008 ND |
810 | { |
811 | TCGv t0; | |
812 | ||
813 | if (!is_isa300(ctx)) { | |
814 | return; | |
815 | } | |
816 | ||
817 | t0 = tcg_temp_new(); | |
33903d0a ND |
818 | if (sub) { |
819 | tcg_gen_eqv_tl(t0, arg0, arg1); | |
820 | } else { | |
821 | tcg_gen_xor_tl(t0, arg0, arg1); | |
822 | } | |
6b10d008 | 823 | tcg_gen_xor_tl(t0, t0, res); |
4c5920af | 824 | tcg_gen_extract_tl(ca32, t0, 32, 1); |
6b10d008 ND |
825 | tcg_temp_free(t0); |
826 | } | |
827 | ||
74637406 | 828 | /* Common add function */ |
636aa200 | 829 | static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1, |
4c5920af SJS |
830 | TCGv arg2, TCGv ca, TCGv ca32, |
831 | bool add_ca, bool compute_ca, | |
b5a73f8d | 832 | bool compute_ov, bool compute_rc0) |
74637406 | 833 | { |
b5a73f8d | 834 | TCGv t0 = ret; |
d9bce9d9 | 835 | |
752d634e | 836 | if (compute_ca || compute_ov) { |
146de60d | 837 | t0 = tcg_temp_new(); |
74637406 | 838 | } |
79aceca5 | 839 | |
da91a00f | 840 | if (compute_ca) { |
79482e5a | 841 | if (NARROW_MODE(ctx)) { |
752d634e RH |
842 | /* Caution: a non-obvious corner case of the spec is that we |
843 | must produce the *entire* 64-bit addition, but produce the | |
844 | carry into bit 32. */ | |
79482e5a | 845 | TCGv t1 = tcg_temp_new(); |
752d634e RH |
846 | tcg_gen_xor_tl(t1, arg1, arg2); /* add without carry */ |
847 | tcg_gen_add_tl(t0, arg1, arg2); | |
79482e5a | 848 | if (add_ca) { |
4c5920af | 849 | tcg_gen_add_tl(t0, t0, ca); |
79482e5a | 850 | } |
4c5920af | 851 | tcg_gen_xor_tl(ca, t0, t1); /* bits changed w/ carry */ |
752d634e | 852 | tcg_temp_free(t1); |
4c5920af | 853 | tcg_gen_extract_tl(ca, ca, 32, 1); |
6b10d008 | 854 | if (is_isa300(ctx)) { |
4c5920af | 855 | tcg_gen_mov_tl(ca32, ca); |
6b10d008 | 856 | } |
b5a73f8d | 857 | } else { |
79482e5a RH |
858 | TCGv zero = tcg_const_tl(0); |
859 | if (add_ca) { | |
4c5920af SJS |
860 | tcg_gen_add2_tl(t0, ca, arg1, zero, ca, zero); |
861 | tcg_gen_add2_tl(t0, ca, t0, ca, arg2, zero); | |
79482e5a | 862 | } else { |
4c5920af | 863 | tcg_gen_add2_tl(t0, ca, arg1, zero, arg2, zero); |
79482e5a | 864 | } |
4c5920af | 865 | gen_op_arith_compute_ca32(ctx, t0, arg1, arg2, ca32, 0); |
79482e5a | 866 | tcg_temp_free(zero); |
b5a73f8d | 867 | } |
b5a73f8d RH |
868 | } else { |
869 | tcg_gen_add_tl(t0, arg1, arg2); | |
870 | if (add_ca) { | |
4c5920af | 871 | tcg_gen_add_tl(t0, t0, ca); |
b5a73f8d | 872 | } |
da91a00f | 873 | } |
79aceca5 | 874 | |
74637406 AJ |
875 | if (compute_ov) { |
876 | gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 0); | |
877 | } | |
b5a73f8d | 878 | if (unlikely(compute_rc0)) { |
74637406 | 879 | gen_set_Rc0(ctx, t0); |
b5a73f8d | 880 | } |
74637406 | 881 | |
11f4e8f8 | 882 | if (t0 != ret) { |
74637406 AJ |
883 | tcg_gen_mov_tl(ret, t0); |
884 | tcg_temp_free(t0); | |
885 | } | |
39dd32ee | 886 | } |
74637406 | 887 | /* Add functions with two operands */ |
4c5920af | 888 | #define GEN_INT_ARITH_ADD(name, opc3, ca, add_ca, compute_ca, compute_ov) \ |
b5a73f8d | 889 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 AJ |
890 | { \ |
891 | gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \ | |
892 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
4c5920af | 893 | ca, glue(ca, 32), \ |
b5a73f8d | 894 | add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \ |
74637406 AJ |
895 | } |
896 | /* Add functions with one operand and one immediate */ | |
4c5920af | 897 | #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, ca, \ |
74637406 | 898 | add_ca, compute_ca, compute_ov) \ |
b5a73f8d | 899 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 | 900 | { \ |
b5a73f8d | 901 | TCGv t0 = tcg_const_tl(const_val); \ |
74637406 AJ |
902 | gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \ |
903 | cpu_gpr[rA(ctx->opcode)], t0, \ | |
4c5920af | 904 | ca, glue(ca, 32), \ |
b5a73f8d | 905 | add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \ |
74637406 AJ |
906 | tcg_temp_free(t0); \ |
907 | } | |
908 | ||
909 | /* add add. addo addo. */ | |
4c5920af SJS |
910 | GEN_INT_ARITH_ADD(add, 0x08, cpu_ca, 0, 0, 0) |
911 | GEN_INT_ARITH_ADD(addo, 0x18, cpu_ca, 0, 0, 1) | |
74637406 | 912 | /* addc addc. addco addco. */ |
4c5920af SJS |
913 | GEN_INT_ARITH_ADD(addc, 0x00, cpu_ca, 0, 1, 0) |
914 | GEN_INT_ARITH_ADD(addco, 0x10, cpu_ca, 0, 1, 1) | |
74637406 | 915 | /* adde adde. addeo addeo. */ |
4c5920af SJS |
916 | GEN_INT_ARITH_ADD(adde, 0x04, cpu_ca, 1, 1, 0) |
917 | GEN_INT_ARITH_ADD(addeo, 0x14, cpu_ca, 1, 1, 1) | |
74637406 | 918 | /* addme addme. addmeo addmeo. */ |
4c5920af SJS |
919 | GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, cpu_ca, 1, 1, 0) |
920 | GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, cpu_ca, 1, 1, 1) | |
921 | /* addex */ | |
922 | GEN_INT_ARITH_ADD(addex, 0x05, cpu_ov, 1, 1, 0); | |
74637406 | 923 | /* addze addze. addzeo addzeo.*/ |
4c5920af SJS |
924 | GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, cpu_ca, 1, 1, 0) |
925 | GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, cpu_ca, 1, 1, 1) | |
74637406 | 926 | /* addi */ |
99e300ef | 927 | static void gen_addi(DisasContext *ctx) |
d9bce9d9 | 928 | { |
74637406 AJ |
929 | target_long simm = SIMM(ctx->opcode); |
930 | ||
931 | if (rA(ctx->opcode) == 0) { | |
932 | /* li case */ | |
933 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm); | |
934 | } else { | |
b5a73f8d RH |
935 | tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)], |
936 | cpu_gpr[rA(ctx->opcode)], simm); | |
74637406 | 937 | } |
d9bce9d9 | 938 | } |
74637406 | 939 | /* addic addic.*/ |
b5a73f8d | 940 | static inline void gen_op_addic(DisasContext *ctx, bool compute_rc0) |
d9bce9d9 | 941 | { |
b5a73f8d RH |
942 | TCGv c = tcg_const_tl(SIMM(ctx->opcode)); |
943 | gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], | |
4c5920af | 944 | c, cpu_ca, cpu_ca32, 0, 1, 0, compute_rc0); |
b5a73f8d | 945 | tcg_temp_free(c); |
d9bce9d9 | 946 | } |
99e300ef BS |
947 | |
948 | static void gen_addic(DisasContext *ctx) | |
d9bce9d9 | 949 | { |
b5a73f8d | 950 | gen_op_addic(ctx, 0); |
d9bce9d9 | 951 | } |
e8eaa2c0 BS |
952 | |
953 | static void gen_addic_(DisasContext *ctx) | |
d9bce9d9 | 954 | { |
b5a73f8d | 955 | gen_op_addic(ctx, 1); |
d9bce9d9 | 956 | } |
99e300ef | 957 | |
54623277 | 958 | /* addis */ |
99e300ef | 959 | static void gen_addis(DisasContext *ctx) |
d9bce9d9 | 960 | { |
74637406 AJ |
961 | target_long simm = SIMM(ctx->opcode); |
962 | ||
963 | if (rA(ctx->opcode) == 0) { | |
964 | /* lis case */ | |
965 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm << 16); | |
966 | } else { | |
b5a73f8d RH |
967 | tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)], |
968 | cpu_gpr[rA(ctx->opcode)], simm << 16); | |
74637406 | 969 | } |
d9bce9d9 | 970 | } |
74637406 | 971 | |
c5b2b9ce ND |
972 | /* addpcis */ |
973 | static void gen_addpcis(DisasContext *ctx) | |
974 | { | |
975 | target_long d = DX(ctx->opcode); | |
976 | ||
b6bac4bc | 977 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], ctx->base.pc_next + (d << 16)); |
c5b2b9ce ND |
978 | } |
979 | ||
636aa200 BS |
980 | static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, TCGv arg1, |
981 | TCGv arg2, int sign, int compute_ov) | |
d9bce9d9 | 982 | { |
b07c32dc ND |
983 | TCGv_i32 t0 = tcg_temp_new_i32(); |
984 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
985 | TCGv_i32 t2 = tcg_temp_new_i32(); | |
986 | TCGv_i32 t3 = tcg_temp_new_i32(); | |
74637406 | 987 | |
2ef1b120 AJ |
988 | tcg_gen_trunc_tl_i32(t0, arg1); |
989 | tcg_gen_trunc_tl_i32(t1, arg2); | |
74637406 | 990 | if (sign) { |
b07c32dc ND |
991 | tcg_gen_setcondi_i32(TCG_COND_EQ, t2, t0, INT_MIN); |
992 | tcg_gen_setcondi_i32(TCG_COND_EQ, t3, t1, -1); | |
993 | tcg_gen_and_i32(t2, t2, t3); | |
994 | tcg_gen_setcondi_i32(TCG_COND_EQ, t3, t1, 0); | |
995 | tcg_gen_or_i32(t2, t2, t3); | |
996 | tcg_gen_movi_i32(t3, 0); | |
997 | tcg_gen_movcond_i32(TCG_COND_NE, t1, t2, t3, t2, t1); | |
998 | tcg_gen_div_i32(t3, t0, t1); | |
999 | tcg_gen_extu_i32_tl(ret, t3); | |
74637406 | 1000 | } else { |
b07c32dc ND |
1001 | tcg_gen_setcondi_i32(TCG_COND_EQ, t2, t1, 0); |
1002 | tcg_gen_movi_i32(t3, 0); | |
1003 | tcg_gen_movcond_i32(TCG_COND_NE, t1, t2, t3, t2, t1); | |
1004 | tcg_gen_divu_i32(t3, t0, t1); | |
1005 | tcg_gen_extu_i32_tl(ret, t3); | |
74637406 AJ |
1006 | } |
1007 | if (compute_ov) { | |
b07c32dc | 1008 | tcg_gen_extu_i32_tl(cpu_ov, t2); |
c44027ff ND |
1009 | if (is_isa300(ctx)) { |
1010 | tcg_gen_extu_i32_tl(cpu_ov32, t2); | |
1011 | } | |
b07c32dc | 1012 | tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov); |
74637406 | 1013 | } |
a7812ae4 PB |
1014 | tcg_temp_free_i32(t0); |
1015 | tcg_temp_free_i32(t1); | |
b07c32dc ND |
1016 | tcg_temp_free_i32(t2); |
1017 | tcg_temp_free_i32(t3); | |
1018 | ||
74637406 AJ |
1019 | if (unlikely(Rc(ctx->opcode) != 0)) |
1020 | gen_set_Rc0(ctx, ret); | |
d9bce9d9 | 1021 | } |
74637406 AJ |
1022 | /* Div functions */ |
1023 | #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \ | |
99e300ef | 1024 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 AJ |
1025 | { \ |
1026 | gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \ | |
1027 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
1028 | sign, compute_ov); \ | |
1029 | } | |
1030 | /* divwu divwu. divwuo divwuo. */ | |
1031 | GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0); | |
1032 | GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1); | |
1033 | /* divw divw. divwo divwo. */ | |
1034 | GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0); | |
1035 | GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1); | |
98d1eb27 TM |
1036 | |
1037 | /* div[wd]eu[o][.] */ | |
1038 | #define GEN_DIVE(name, hlpr, compute_ov) \ | |
1039 | static void gen_##name(DisasContext *ctx) \ | |
1040 | { \ | |
1041 | TCGv_i32 t0 = tcg_const_i32(compute_ov); \ | |
1042 | gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \ | |
1043 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \ | |
1044 | tcg_temp_free_i32(t0); \ | |
1045 | if (unlikely(Rc(ctx->opcode) != 0)) { \ | |
1046 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \ | |
1047 | } \ | |
1048 | } | |
1049 | ||
6a4fda33 TM |
1050 | GEN_DIVE(divweu, divweu, 0); |
1051 | GEN_DIVE(divweuo, divweu, 1); | |
a98eb9e9 TM |
1052 | GEN_DIVE(divwe, divwe, 0); |
1053 | GEN_DIVE(divweo, divwe, 1); | |
6a4fda33 | 1054 | |
d9bce9d9 | 1055 | #if defined(TARGET_PPC64) |
636aa200 BS |
1056 | static inline void gen_op_arith_divd(DisasContext *ctx, TCGv ret, TCGv arg1, |
1057 | TCGv arg2, int sign, int compute_ov) | |
d9bce9d9 | 1058 | { |
4110b586 ND |
1059 | TCGv_i64 t0 = tcg_temp_new_i64(); |
1060 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
1061 | TCGv_i64 t2 = tcg_temp_new_i64(); | |
1062 | TCGv_i64 t3 = tcg_temp_new_i64(); | |
74637406 | 1063 | |
4110b586 ND |
1064 | tcg_gen_mov_i64(t0, arg1); |
1065 | tcg_gen_mov_i64(t1, arg2); | |
74637406 | 1066 | if (sign) { |
4110b586 ND |
1067 | tcg_gen_setcondi_i64(TCG_COND_EQ, t2, t0, INT64_MIN); |
1068 | tcg_gen_setcondi_i64(TCG_COND_EQ, t3, t1, -1); | |
1069 | tcg_gen_and_i64(t2, t2, t3); | |
1070 | tcg_gen_setcondi_i64(TCG_COND_EQ, t3, t1, 0); | |
1071 | tcg_gen_or_i64(t2, t2, t3); | |
1072 | tcg_gen_movi_i64(t3, 0); | |
1073 | tcg_gen_movcond_i64(TCG_COND_NE, t1, t2, t3, t2, t1); | |
1074 | tcg_gen_div_i64(ret, t0, t1); | |
74637406 | 1075 | } else { |
4110b586 ND |
1076 | tcg_gen_setcondi_i64(TCG_COND_EQ, t2, t1, 0); |
1077 | tcg_gen_movi_i64(t3, 0); | |
1078 | tcg_gen_movcond_i64(TCG_COND_NE, t1, t2, t3, t2, t1); | |
1079 | tcg_gen_divu_i64(ret, t0, t1); | |
74637406 AJ |
1080 | } |
1081 | if (compute_ov) { | |
4110b586 | 1082 | tcg_gen_mov_tl(cpu_ov, t2); |
c44027ff ND |
1083 | if (is_isa300(ctx)) { |
1084 | tcg_gen_mov_tl(cpu_ov32, t2); | |
1085 | } | |
4110b586 | 1086 | tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov); |
74637406 | 1087 | } |
4110b586 ND |
1088 | tcg_temp_free_i64(t0); |
1089 | tcg_temp_free_i64(t1); | |
1090 | tcg_temp_free_i64(t2); | |
1091 | tcg_temp_free_i64(t3); | |
1092 | ||
74637406 AJ |
1093 | if (unlikely(Rc(ctx->opcode) != 0)) |
1094 | gen_set_Rc0(ctx, ret); | |
d9bce9d9 | 1095 | } |
4110b586 | 1096 | |
74637406 | 1097 | #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \ |
99e300ef | 1098 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 | 1099 | { \ |
2ef1b120 AJ |
1100 | gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \ |
1101 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
1102 | sign, compute_ov); \ | |
74637406 | 1103 | } |
c44027ff | 1104 | /* divdu divdu. divduo divduo. */ |
74637406 AJ |
1105 | GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0); |
1106 | GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1); | |
c44027ff | 1107 | /* divd divd. divdo divdo. */ |
74637406 AJ |
1108 | GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0); |
1109 | GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1); | |
98d1eb27 TM |
1110 | |
1111 | GEN_DIVE(divdeu, divdeu, 0); | |
1112 | GEN_DIVE(divdeuo, divdeu, 1); | |
e44259b6 TM |
1113 | GEN_DIVE(divde, divde, 0); |
1114 | GEN_DIVE(divdeo, divde, 1); | |
d9bce9d9 | 1115 | #endif |
74637406 | 1116 | |
af2c6620 ND |
1117 | static inline void gen_op_arith_modw(DisasContext *ctx, TCGv ret, TCGv arg1, |
1118 | TCGv arg2, int sign) | |
1119 | { | |
1120 | TCGv_i32 t0 = tcg_temp_new_i32(); | |
1121 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
1122 | ||
1123 | tcg_gen_trunc_tl_i32(t0, arg1); | |
1124 | tcg_gen_trunc_tl_i32(t1, arg2); | |
1125 | if (sign) { | |
1126 | TCGv_i32 t2 = tcg_temp_new_i32(); | |
1127 | TCGv_i32 t3 = tcg_temp_new_i32(); | |
1128 | tcg_gen_setcondi_i32(TCG_COND_EQ, t2, t0, INT_MIN); | |
1129 | tcg_gen_setcondi_i32(TCG_COND_EQ, t3, t1, -1); | |
1130 | tcg_gen_and_i32(t2, t2, t3); | |
1131 | tcg_gen_setcondi_i32(TCG_COND_EQ, t3, t1, 0); | |
1132 | tcg_gen_or_i32(t2, t2, t3); | |
1133 | tcg_gen_movi_i32(t3, 0); | |
1134 | tcg_gen_movcond_i32(TCG_COND_NE, t1, t2, t3, t2, t1); | |
1135 | tcg_gen_rem_i32(t3, t0, t1); | |
1136 | tcg_gen_ext_i32_tl(ret, t3); | |
1137 | tcg_temp_free_i32(t2); | |
1138 | tcg_temp_free_i32(t3); | |
1139 | } else { | |
1140 | TCGv_i32 t2 = tcg_const_i32(1); | |
1141 | TCGv_i32 t3 = tcg_const_i32(0); | |
1142 | tcg_gen_movcond_i32(TCG_COND_EQ, t1, t1, t3, t2, t1); | |
1143 | tcg_gen_remu_i32(t3, t0, t1); | |
1144 | tcg_gen_extu_i32_tl(ret, t3); | |
1145 | tcg_temp_free_i32(t2); | |
1146 | tcg_temp_free_i32(t3); | |
1147 | } | |
1148 | tcg_temp_free_i32(t0); | |
1149 | tcg_temp_free_i32(t1); | |
1150 | } | |
1151 | ||
1152 | #define GEN_INT_ARITH_MODW(name, opc3, sign) \ | |
1153 | static void glue(gen_, name)(DisasContext *ctx) \ | |
1154 | { \ | |
1155 | gen_op_arith_modw(ctx, cpu_gpr[rD(ctx->opcode)], \ | |
1156 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
1157 | sign); \ | |
1158 | } | |
1159 | ||
1160 | GEN_INT_ARITH_MODW(moduw, 0x08, 0); | |
1161 | GEN_INT_ARITH_MODW(modsw, 0x18, 1); | |
1162 | ||
063cf14f ND |
1163 | #if defined(TARGET_PPC64) |
1164 | static inline void gen_op_arith_modd(DisasContext *ctx, TCGv ret, TCGv arg1, | |
1165 | TCGv arg2, int sign) | |
1166 | { | |
1167 | TCGv_i64 t0 = tcg_temp_new_i64(); | |
1168 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
1169 | ||
1170 | tcg_gen_mov_i64(t0, arg1); | |
1171 | tcg_gen_mov_i64(t1, arg2); | |
1172 | if (sign) { | |
1173 | TCGv_i64 t2 = tcg_temp_new_i64(); | |
1174 | TCGv_i64 t3 = tcg_temp_new_i64(); | |
1175 | tcg_gen_setcondi_i64(TCG_COND_EQ, t2, t0, INT64_MIN); | |
1176 | tcg_gen_setcondi_i64(TCG_COND_EQ, t3, t1, -1); | |
1177 | tcg_gen_and_i64(t2, t2, t3); | |
1178 | tcg_gen_setcondi_i64(TCG_COND_EQ, t3, t1, 0); | |
1179 | tcg_gen_or_i64(t2, t2, t3); | |
1180 | tcg_gen_movi_i64(t3, 0); | |
1181 | tcg_gen_movcond_i64(TCG_COND_NE, t1, t2, t3, t2, t1); | |
1182 | tcg_gen_rem_i64(ret, t0, t1); | |
1183 | tcg_temp_free_i64(t2); | |
1184 | tcg_temp_free_i64(t3); | |
1185 | } else { | |
1186 | TCGv_i64 t2 = tcg_const_i64(1); | |
1187 | TCGv_i64 t3 = tcg_const_i64(0); | |
1188 | tcg_gen_movcond_i64(TCG_COND_EQ, t1, t1, t3, t2, t1); | |
1189 | tcg_gen_remu_i64(ret, t0, t1); | |
1190 | tcg_temp_free_i64(t2); | |
1191 | tcg_temp_free_i64(t3); | |
1192 | } | |
1193 | tcg_temp_free_i64(t0); | |
1194 | tcg_temp_free_i64(t1); | |
1195 | } | |
1196 | ||
1197 | #define GEN_INT_ARITH_MODD(name, opc3, sign) \ | |
1198 | static void glue(gen_, name)(DisasContext *ctx) \ | |
1199 | { \ | |
1200 | gen_op_arith_modd(ctx, cpu_gpr[rD(ctx->opcode)], \ | |
1201 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
1202 | sign); \ | |
1203 | } | |
1204 | ||
1205 | GEN_INT_ARITH_MODD(modud, 0x08, 0); | |
1206 | GEN_INT_ARITH_MODD(modsd, 0x18, 1); | |
1207 | #endif | |
1208 | ||
74637406 | 1209 | /* mulhw mulhw. */ |
99e300ef | 1210 | static void gen_mulhw(DisasContext *ctx) |
d9bce9d9 | 1211 | { |
23ad1d5d RH |
1212 | TCGv_i32 t0 = tcg_temp_new_i32(); |
1213 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
74637406 | 1214 | |
23ad1d5d RH |
1215 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); |
1216 | tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); | |
1217 | tcg_gen_muls2_i32(t0, t1, t0, t1); | |
1218 | tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1); | |
1219 | tcg_temp_free_i32(t0); | |
1220 | tcg_temp_free_i32(t1); | |
74637406 AJ |
1221 | if (unlikely(Rc(ctx->opcode) != 0)) |
1222 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1223 | } |
99e300ef | 1224 | |
54623277 | 1225 | /* mulhwu mulhwu. */ |
99e300ef | 1226 | static void gen_mulhwu(DisasContext *ctx) |
d9bce9d9 | 1227 | { |
23ad1d5d RH |
1228 | TCGv_i32 t0 = tcg_temp_new_i32(); |
1229 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
74637406 | 1230 | |
23ad1d5d RH |
1231 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); |
1232 | tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); | |
1233 | tcg_gen_mulu2_i32(t0, t1, t0, t1); | |
1234 | tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1); | |
1235 | tcg_temp_free_i32(t0); | |
1236 | tcg_temp_free_i32(t1); | |
74637406 AJ |
1237 | if (unlikely(Rc(ctx->opcode) != 0)) |
1238 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1239 | } |
99e300ef | 1240 | |
54623277 | 1241 | /* mullw mullw. */ |
99e300ef | 1242 | static void gen_mullw(DisasContext *ctx) |
d9bce9d9 | 1243 | { |
1fa74845 TM |
1244 | #if defined(TARGET_PPC64) |
1245 | TCGv_i64 t0, t1; | |
1246 | t0 = tcg_temp_new_i64(); | |
1247 | t1 = tcg_temp_new_i64(); | |
1248 | tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]); | |
1249 | tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]); | |
1250 | tcg_gen_mul_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); | |
1251 | tcg_temp_free(t0); | |
1252 | tcg_temp_free(t1); | |
1253 | #else | |
03039e5e TM |
1254 | tcg_gen_mul_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], |
1255 | cpu_gpr[rB(ctx->opcode)]); | |
1fa74845 | 1256 | #endif |
74637406 AJ |
1257 | if (unlikely(Rc(ctx->opcode) != 0)) |
1258 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1259 | } |
99e300ef | 1260 | |
54623277 | 1261 | /* mullwo mullwo. */ |
99e300ef | 1262 | static void gen_mullwo(DisasContext *ctx) |
d9bce9d9 | 1263 | { |
e4a2c846 RH |
1264 | TCGv_i32 t0 = tcg_temp_new_i32(); |
1265 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
74637406 | 1266 | |
e4a2c846 RH |
1267 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); |
1268 | tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); | |
1269 | tcg_gen_muls2_i32(t0, t1, t0, t1); | |
f11ebbf8 | 1270 | #if defined(TARGET_PPC64) |
26977876 TM |
1271 | tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); |
1272 | #else | |
1273 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], t0); | |
f11ebbf8 | 1274 | #endif |
e4a2c846 RH |
1275 | |
1276 | tcg_gen_sari_i32(t0, t0, 31); | |
1277 | tcg_gen_setcond_i32(TCG_COND_NE, t0, t0, t1); | |
1278 | tcg_gen_extu_i32_tl(cpu_ov, t0); | |
61aa9a69 ND |
1279 | if (is_isa300(ctx)) { |
1280 | tcg_gen_mov_tl(cpu_ov32, cpu_ov); | |
1281 | } | |
e4a2c846 RH |
1282 | tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov); |
1283 | ||
1284 | tcg_temp_free_i32(t0); | |
1285 | tcg_temp_free_i32(t1); | |
74637406 AJ |
1286 | if (unlikely(Rc(ctx->opcode) != 0)) |
1287 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1288 | } |
99e300ef | 1289 | |
54623277 | 1290 | /* mulli */ |
99e300ef | 1291 | static void gen_mulli(DisasContext *ctx) |
d9bce9d9 | 1292 | { |
74637406 AJ |
1293 | tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], |
1294 | SIMM(ctx->opcode)); | |
d9bce9d9 | 1295 | } |
23ad1d5d | 1296 | |
d9bce9d9 | 1297 | #if defined(TARGET_PPC64) |
74637406 | 1298 | /* mulhd mulhd. */ |
23ad1d5d RH |
1299 | static void gen_mulhd(DisasContext *ctx) |
1300 | { | |
1301 | TCGv lo = tcg_temp_new(); | |
1302 | tcg_gen_muls2_tl(lo, cpu_gpr[rD(ctx->opcode)], | |
1303 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
1304 | tcg_temp_free(lo); | |
1305 | if (unlikely(Rc(ctx->opcode) != 0)) { | |
1306 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
1307 | } | |
1308 | } | |
1309 | ||
74637406 | 1310 | /* mulhdu mulhdu. */ |
23ad1d5d RH |
1311 | static void gen_mulhdu(DisasContext *ctx) |
1312 | { | |
1313 | TCGv lo = tcg_temp_new(); | |
1314 | tcg_gen_mulu2_tl(lo, cpu_gpr[rD(ctx->opcode)], | |
1315 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
1316 | tcg_temp_free(lo); | |
1317 | if (unlikely(Rc(ctx->opcode) != 0)) { | |
1318 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
1319 | } | |
1320 | } | |
99e300ef | 1321 | |
54623277 | 1322 | /* mulld mulld. */ |
99e300ef | 1323 | static void gen_mulld(DisasContext *ctx) |
d9bce9d9 | 1324 | { |
74637406 AJ |
1325 | tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], |
1326 | cpu_gpr[rB(ctx->opcode)]); | |
1327 | if (unlikely(Rc(ctx->opcode) != 0)) | |
1328 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1329 | } |
d15f74fb | 1330 | |
74637406 | 1331 | /* mulldo mulldo. */ |
d15f74fb BS |
1332 | static void gen_mulldo(DisasContext *ctx) |
1333 | { | |
22ffad31 TM |
1334 | TCGv_i64 t0 = tcg_temp_new_i64(); |
1335 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
1336 | ||
1337 | tcg_gen_muls2_i64(t0, t1, cpu_gpr[rA(ctx->opcode)], | |
1338 | cpu_gpr[rB(ctx->opcode)]); | |
1339 | tcg_gen_mov_i64(cpu_gpr[rD(ctx->opcode)], t0); | |
1340 | ||
1341 | tcg_gen_sari_i64(t0, t0, 63); | |
1342 | tcg_gen_setcond_i64(TCG_COND_NE, cpu_ov, t0, t1); | |
61aa9a69 ND |
1343 | if (is_isa300(ctx)) { |
1344 | tcg_gen_mov_tl(cpu_ov32, cpu_ov); | |
1345 | } | |
22ffad31 TM |
1346 | tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov); |
1347 | ||
1348 | tcg_temp_free_i64(t0); | |
1349 | tcg_temp_free_i64(t1); | |
1350 | ||
d15f74fb BS |
1351 | if (unlikely(Rc(ctx->opcode) != 0)) { |
1352 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
1353 | } | |
1354 | } | |
d9bce9d9 | 1355 | #endif |
74637406 | 1356 | |
74637406 | 1357 | /* Common subf function */ |
636aa200 | 1358 | static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1, |
b5a73f8d RH |
1359 | TCGv arg2, bool add_ca, bool compute_ca, |
1360 | bool compute_ov, bool compute_rc0) | |
79aceca5 | 1361 | { |
b5a73f8d | 1362 | TCGv t0 = ret; |
79aceca5 | 1363 | |
752d634e | 1364 | if (compute_ca || compute_ov) { |
b5a73f8d | 1365 | t0 = tcg_temp_new(); |
da91a00f | 1366 | } |
74637406 | 1367 | |
79482e5a RH |
1368 | if (compute_ca) { |
1369 | /* dest = ~arg1 + arg2 [+ ca]. */ | |
1370 | if (NARROW_MODE(ctx)) { | |
752d634e RH |
1371 | /* Caution: a non-obvious corner case of the spec is that we |
1372 | must produce the *entire* 64-bit addition, but produce the | |
1373 | carry into bit 32. */ | |
79482e5a | 1374 | TCGv inv1 = tcg_temp_new(); |
752d634e | 1375 | TCGv t1 = tcg_temp_new(); |
79482e5a | 1376 | tcg_gen_not_tl(inv1, arg1); |
79482e5a | 1377 | if (add_ca) { |
752d634e | 1378 | tcg_gen_add_tl(t0, arg2, cpu_ca); |
79482e5a | 1379 | } else { |
752d634e | 1380 | tcg_gen_addi_tl(t0, arg2, 1); |
79482e5a | 1381 | } |
752d634e | 1382 | tcg_gen_xor_tl(t1, arg2, inv1); /* add without carry */ |
79482e5a | 1383 | tcg_gen_add_tl(t0, t0, inv1); |
c80d1df5 | 1384 | tcg_temp_free(inv1); |
752d634e RH |
1385 | tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changes w/ carry */ |
1386 | tcg_temp_free(t1); | |
e2622073 | 1387 | tcg_gen_extract_tl(cpu_ca, cpu_ca, 32, 1); |
33903d0a ND |
1388 | if (is_isa300(ctx)) { |
1389 | tcg_gen_mov_tl(cpu_ca32, cpu_ca); | |
1390 | } | |
79482e5a | 1391 | } else if (add_ca) { |
08f4a0f7 RH |
1392 | TCGv zero, inv1 = tcg_temp_new(); |
1393 | tcg_gen_not_tl(inv1, arg1); | |
b5a73f8d RH |
1394 | zero = tcg_const_tl(0); |
1395 | tcg_gen_add2_tl(t0, cpu_ca, arg2, zero, cpu_ca, zero); | |
08f4a0f7 | 1396 | tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, inv1, zero); |
4c5920af | 1397 | gen_op_arith_compute_ca32(ctx, t0, inv1, arg2, cpu_ca32, 0); |
b5a73f8d | 1398 | tcg_temp_free(zero); |
08f4a0f7 | 1399 | tcg_temp_free(inv1); |
b5a73f8d | 1400 | } else { |
79482e5a | 1401 | tcg_gen_setcond_tl(TCG_COND_GEU, cpu_ca, arg2, arg1); |
b5a73f8d | 1402 | tcg_gen_sub_tl(t0, arg2, arg1); |
4c5920af | 1403 | gen_op_arith_compute_ca32(ctx, t0, arg1, arg2, cpu_ca32, 1); |
b5a73f8d | 1404 | } |
79482e5a RH |
1405 | } else if (add_ca) { |
1406 | /* Since we're ignoring carry-out, we can simplify the | |
1407 | standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1. */ | |
1408 | tcg_gen_sub_tl(t0, arg2, arg1); | |
1409 | tcg_gen_add_tl(t0, t0, cpu_ca); | |
1410 | tcg_gen_subi_tl(t0, t0, 1); | |
79aceca5 | 1411 | } else { |
b5a73f8d | 1412 | tcg_gen_sub_tl(t0, arg2, arg1); |
74637406 | 1413 | } |
b5a73f8d | 1414 | |
74637406 AJ |
1415 | if (compute_ov) { |
1416 | gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1); | |
1417 | } | |
b5a73f8d | 1418 | if (unlikely(compute_rc0)) { |
74637406 | 1419 | gen_set_Rc0(ctx, t0); |
b5a73f8d | 1420 | } |
74637406 | 1421 | |
11f4e8f8 | 1422 | if (t0 != ret) { |
74637406 AJ |
1423 | tcg_gen_mov_tl(ret, t0); |
1424 | tcg_temp_free(t0); | |
79aceca5 | 1425 | } |
79aceca5 | 1426 | } |
74637406 AJ |
1427 | /* Sub functions with Two operands functions */ |
1428 | #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \ | |
b5a73f8d | 1429 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 AJ |
1430 | { \ |
1431 | gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \ | |
1432 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
b5a73f8d | 1433 | add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \ |
74637406 AJ |
1434 | } |
1435 | /* Sub functions with one operand and one immediate */ | |
1436 | #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \ | |
1437 | add_ca, compute_ca, compute_ov) \ | |
b5a73f8d | 1438 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 | 1439 | { \ |
b5a73f8d | 1440 | TCGv t0 = tcg_const_tl(const_val); \ |
74637406 AJ |
1441 | gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \ |
1442 | cpu_gpr[rA(ctx->opcode)], t0, \ | |
b5a73f8d | 1443 | add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \ |
74637406 AJ |
1444 | tcg_temp_free(t0); \ |
1445 | } | |
1446 | /* subf subf. subfo subfo. */ | |
1447 | GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0) | |
1448 | GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1) | |
1449 | /* subfc subfc. subfco subfco. */ | |
1450 | GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0) | |
1451 | GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1) | |
1452 | /* subfe subfe. subfeo subfo. */ | |
1453 | GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0) | |
1454 | GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1) | |
1455 | /* subfme subfme. subfmeo subfmeo. */ | |
1456 | GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0) | |
1457 | GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1) | |
1458 | /* subfze subfze. subfzeo subfzeo.*/ | |
1459 | GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0) | |
1460 | GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1) | |
99e300ef | 1461 | |
54623277 | 1462 | /* subfic */ |
99e300ef | 1463 | static void gen_subfic(DisasContext *ctx) |
79aceca5 | 1464 | { |
b5a73f8d RH |
1465 | TCGv c = tcg_const_tl(SIMM(ctx->opcode)); |
1466 | gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], | |
1467 | c, 0, 1, 0, 0); | |
1468 | tcg_temp_free(c); | |
79aceca5 FB |
1469 | } |
1470 | ||
fd3f0081 RH |
1471 | /* neg neg. nego nego. */ |
1472 | static inline void gen_op_arith_neg(DisasContext *ctx, bool compute_ov) | |
1473 | { | |
1474 | TCGv zero = tcg_const_tl(0); | |
1475 | gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], | |
1476 | zero, 0, 0, compute_ov, Rc(ctx->opcode)); | |
1477 | tcg_temp_free(zero); | |
1478 | } | |
1479 | ||
1480 | static void gen_neg(DisasContext *ctx) | |
1481 | { | |
1480d71c ND |
1482 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
1483 | if (unlikely(Rc(ctx->opcode))) { | |
1484 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
1485 | } | |
fd3f0081 RH |
1486 | } |
1487 | ||
1488 | static void gen_nego(DisasContext *ctx) | |
1489 | { | |
1490 | gen_op_arith_neg(ctx, 1); | |
1491 | } | |
1492 | ||
79aceca5 | 1493 | /*** Integer logical ***/ |
26d67362 | 1494 | #define GEN_LOGICAL2(name, tcg_op, opc, type) \ |
99e300ef | 1495 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 1496 | { \ |
26d67362 AJ |
1497 | tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \ |
1498 | cpu_gpr[rB(ctx->opcode)]); \ | |
76a66253 | 1499 | if (unlikely(Rc(ctx->opcode) != 0)) \ |
26d67362 | 1500 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \ |
79aceca5 | 1501 | } |
79aceca5 | 1502 | |
26d67362 | 1503 | #define GEN_LOGICAL1(name, tcg_op, opc, type) \ |
99e300ef | 1504 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 1505 | { \ |
26d67362 | 1506 | tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \ |
76a66253 | 1507 | if (unlikely(Rc(ctx->opcode) != 0)) \ |
26d67362 | 1508 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \ |
79aceca5 FB |
1509 | } |
1510 | ||
1511 | /* and & and. */ | |
26d67362 | 1512 | GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER); |
79aceca5 | 1513 | /* andc & andc. */ |
26d67362 | 1514 | GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER); |
e8eaa2c0 | 1515 | |
54623277 | 1516 | /* andi. */ |
e8eaa2c0 | 1517 | static void gen_andi_(DisasContext *ctx) |
79aceca5 | 1518 | { |
26d67362 AJ |
1519 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode)); |
1520 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
79aceca5 | 1521 | } |
e8eaa2c0 | 1522 | |
54623277 | 1523 | /* andis. */ |
e8eaa2c0 | 1524 | static void gen_andis_(DisasContext *ctx) |
79aceca5 | 1525 | { |
26d67362 AJ |
1526 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16); |
1527 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
79aceca5 | 1528 | } |
99e300ef | 1529 | |
54623277 | 1530 | /* cntlzw */ |
99e300ef | 1531 | static void gen_cntlzw(DisasContext *ctx) |
26d67362 | 1532 | { |
9b8514e5 RH |
1533 | TCGv_i32 t = tcg_temp_new_i32(); |
1534 | ||
1535 | tcg_gen_trunc_tl_i32(t, cpu_gpr[rS(ctx->opcode)]); | |
1536 | tcg_gen_clzi_i32(t, t, 32); | |
1537 | tcg_gen_extu_i32_tl(cpu_gpr[rA(ctx->opcode)], t); | |
1538 | tcg_temp_free_i32(t); | |
1539 | ||
26d67362 | 1540 | if (unlikely(Rc(ctx->opcode) != 0)) |
2e31f5d3 | 1541 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
26d67362 | 1542 | } |
b35344e4 ND |
1543 | |
1544 | /* cnttzw */ | |
1545 | static void gen_cnttzw(DisasContext *ctx) | |
1546 | { | |
9b8514e5 RH |
1547 | TCGv_i32 t = tcg_temp_new_i32(); |
1548 | ||
1549 | tcg_gen_trunc_tl_i32(t, cpu_gpr[rS(ctx->opcode)]); | |
1550 | tcg_gen_ctzi_i32(t, t, 32); | |
1551 | tcg_gen_extu_i32_tl(cpu_gpr[rA(ctx->opcode)], t); | |
1552 | tcg_temp_free_i32(t); | |
1553 | ||
b35344e4 ND |
1554 | if (unlikely(Rc(ctx->opcode) != 0)) { |
1555 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1556 | } | |
1557 | } | |
1558 | ||
79aceca5 | 1559 | /* eqv & eqv. */ |
26d67362 | 1560 | GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER); |
79aceca5 | 1561 | /* extsb & extsb. */ |
26d67362 | 1562 | GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER); |
79aceca5 | 1563 | /* extsh & extsh. */ |
26d67362 | 1564 | GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER); |
79aceca5 | 1565 | /* nand & nand. */ |
26d67362 | 1566 | GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER); |
79aceca5 | 1567 | /* nor & nor. */ |
26d67362 | 1568 | GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER); |
99e300ef | 1569 | |
7f2b1744 | 1570 | #if defined(TARGET_PPC64) && !defined(CONFIG_USER_ONLY) |
b68e60e6 BH |
1571 | static void gen_pause(DisasContext *ctx) |
1572 | { | |
1573 | TCGv_i32 t0 = tcg_const_i32(0); | |
1574 | tcg_gen_st_i32(t0, cpu_env, | |
1575 | -offsetof(PowerPCCPU, env) + offsetof(CPUState, halted)); | |
1576 | tcg_temp_free_i32(t0); | |
1577 | ||
1578 | /* Stop translation, this gives other CPUs a chance to run */ | |
b6bac4bc | 1579 | gen_exception_nip(ctx, EXCP_HLT, ctx->base.pc_next); |
b68e60e6 BH |
1580 | } |
1581 | #endif /* defined(TARGET_PPC64) */ | |
1582 | ||
54623277 | 1583 | /* or & or. */ |
99e300ef | 1584 | static void gen_or(DisasContext *ctx) |
9a64fbe4 | 1585 | { |
76a66253 JM |
1586 | int rs, ra, rb; |
1587 | ||
1588 | rs = rS(ctx->opcode); | |
1589 | ra = rA(ctx->opcode); | |
1590 | rb = rB(ctx->opcode); | |
1591 | /* Optimisation for mr. ri case */ | |
1592 | if (rs != ra || rs != rb) { | |
26d67362 AJ |
1593 | if (rs != rb) |
1594 | tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]); | |
1595 | else | |
1596 | tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]); | |
76a66253 | 1597 | if (unlikely(Rc(ctx->opcode) != 0)) |
26d67362 | 1598 | gen_set_Rc0(ctx, cpu_gpr[ra]); |
76a66253 | 1599 | } else if (unlikely(Rc(ctx->opcode) != 0)) { |
26d67362 | 1600 | gen_set_Rc0(ctx, cpu_gpr[rs]); |
c80f84e3 | 1601 | #if defined(TARGET_PPC64) |
9e196938 | 1602 | } else if (rs != 0) { /* 0 is nop */ |
26d67362 AJ |
1603 | int prio = 0; |
1604 | ||
c80f84e3 JM |
1605 | switch (rs) { |
1606 | case 1: | |
1607 | /* Set process priority to low */ | |
26d67362 | 1608 | prio = 2; |
c80f84e3 JM |
1609 | break; |
1610 | case 6: | |
1611 | /* Set process priority to medium-low */ | |
26d67362 | 1612 | prio = 3; |
c80f84e3 JM |
1613 | break; |
1614 | case 2: | |
1615 | /* Set process priority to normal */ | |
26d67362 | 1616 | prio = 4; |
c80f84e3 | 1617 | break; |
be147d08 JM |
1618 | #if !defined(CONFIG_USER_ONLY) |
1619 | case 31: | |
c47493f2 | 1620 | if (!ctx->pr) { |
be147d08 | 1621 | /* Set process priority to very low */ |
26d67362 | 1622 | prio = 1; |
be147d08 JM |
1623 | } |
1624 | break; | |
1625 | case 5: | |
c47493f2 | 1626 | if (!ctx->pr) { |
be147d08 | 1627 | /* Set process priority to medium-hight */ |
26d67362 | 1628 | prio = 5; |
be147d08 JM |
1629 | } |
1630 | break; | |
1631 | case 3: | |
c47493f2 | 1632 | if (!ctx->pr) { |
be147d08 | 1633 | /* Set process priority to high */ |
26d67362 | 1634 | prio = 6; |
be147d08 JM |
1635 | } |
1636 | break; | |
be147d08 | 1637 | case 7: |
b68e60e6 | 1638 | if (ctx->hv && !ctx->pr) { |
be147d08 | 1639 | /* Set process priority to very high */ |
26d67362 | 1640 | prio = 7; |
be147d08 JM |
1641 | } |
1642 | break; | |
be147d08 | 1643 | #endif |
c80f84e3 | 1644 | default: |
c80f84e3 JM |
1645 | break; |
1646 | } | |
26d67362 | 1647 | if (prio) { |
a7812ae4 | 1648 | TCGv t0 = tcg_temp_new(); |
54cdcae6 | 1649 | gen_load_spr(t0, SPR_PPR); |
ea363694 AJ |
1650 | tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL); |
1651 | tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50); | |
54cdcae6 | 1652 | gen_store_spr(SPR_PPR, t0); |
ea363694 | 1653 | tcg_temp_free(t0); |
9e196938 | 1654 | } |
7f2b1744 | 1655 | #if !defined(CONFIG_USER_ONLY) |
9e196938 AL |
1656 | /* Pause out of TCG otherwise spin loops with smt_low eat too much |
1657 | * CPU and the kernel hangs. This applies to all encodings other | |
1658 | * than no-op, e.g., miso(rs=26), yield(27), mdoio(29), mdoom(30), | |
1659 | * and all currently undefined. | |
1660 | */ | |
1661 | gen_pause(ctx); | |
7f2b1744 | 1662 | #endif |
c80f84e3 | 1663 | #endif |
9a64fbe4 | 1664 | } |
9a64fbe4 | 1665 | } |
79aceca5 | 1666 | /* orc & orc. */ |
26d67362 | 1667 | GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER); |
99e300ef | 1668 | |
54623277 | 1669 | /* xor & xor. */ |
99e300ef | 1670 | static void gen_xor(DisasContext *ctx) |
9a64fbe4 | 1671 | { |
9a64fbe4 | 1672 | /* Optimisation for "set to zero" case */ |
26d67362 | 1673 | if (rS(ctx->opcode) != rB(ctx->opcode)) |
312179c4 | 1674 | tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
26d67362 AJ |
1675 | else |
1676 | tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0); | |
76a66253 | 1677 | if (unlikely(Rc(ctx->opcode) != 0)) |
26d67362 | 1678 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
9a64fbe4 | 1679 | } |
99e300ef | 1680 | |
54623277 | 1681 | /* ori */ |
99e300ef | 1682 | static void gen_ori(DisasContext *ctx) |
79aceca5 | 1683 | { |
76a66253 | 1684 | target_ulong uimm = UIMM(ctx->opcode); |
79aceca5 | 1685 | |
9a64fbe4 | 1686 | if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { |
9a64fbe4 | 1687 | return; |
76a66253 | 1688 | } |
26d67362 | 1689 | tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm); |
79aceca5 | 1690 | } |
99e300ef | 1691 | |
54623277 | 1692 | /* oris */ |
99e300ef | 1693 | static void gen_oris(DisasContext *ctx) |
79aceca5 | 1694 | { |
76a66253 | 1695 | target_ulong uimm = UIMM(ctx->opcode); |
79aceca5 | 1696 | |
9a64fbe4 FB |
1697 | if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { |
1698 | /* NOP */ | |
1699 | return; | |
76a66253 | 1700 | } |
26d67362 | 1701 | tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16); |
79aceca5 | 1702 | } |
99e300ef | 1703 | |
54623277 | 1704 | /* xori */ |
99e300ef | 1705 | static void gen_xori(DisasContext *ctx) |
79aceca5 | 1706 | { |
76a66253 | 1707 | target_ulong uimm = UIMM(ctx->opcode); |
9a64fbe4 FB |
1708 | |
1709 | if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { | |
1710 | /* NOP */ | |
1711 | return; | |
1712 | } | |
26d67362 | 1713 | tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm); |
79aceca5 | 1714 | } |
99e300ef | 1715 | |
54623277 | 1716 | /* xoris */ |
99e300ef | 1717 | static void gen_xoris(DisasContext *ctx) |
79aceca5 | 1718 | { |
76a66253 | 1719 | target_ulong uimm = UIMM(ctx->opcode); |
9a64fbe4 FB |
1720 | |
1721 | if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { | |
1722 | /* NOP */ | |
1723 | return; | |
1724 | } | |
26d67362 | 1725 | tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16); |
79aceca5 | 1726 | } |
99e300ef | 1727 | |
54623277 | 1728 | /* popcntb : PowerPC 2.03 specification */ |
99e300ef | 1729 | static void gen_popcntb(DisasContext *ctx) |
d9bce9d9 | 1730 | { |
eaabeef2 DG |
1731 | gen_helper_popcntb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); |
1732 | } | |
1733 | ||
1734 | static void gen_popcntw(DisasContext *ctx) | |
1735 | { | |
79770002 | 1736 | #if defined(TARGET_PPC64) |
eaabeef2 | 1737 | gen_helper_popcntw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); |
79770002 RH |
1738 | #else |
1739 | tcg_gen_ctpop_i32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
1740 | #endif | |
eaabeef2 DG |
1741 | } |
1742 | ||
d9bce9d9 | 1743 | #if defined(TARGET_PPC64) |
eaabeef2 DG |
1744 | /* popcntd: PowerPC 2.06 specification */ |
1745 | static void gen_popcntd(DisasContext *ctx) | |
1746 | { | |
79770002 | 1747 | tcg_gen_ctpop_i64(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); |
d9bce9d9 | 1748 | } |
eaabeef2 | 1749 | #endif |
d9bce9d9 | 1750 | |
725bcec2 AJ |
1751 | /* prtyw: PowerPC 2.05 specification */ |
1752 | static void gen_prtyw(DisasContext *ctx) | |
1753 | { | |
1754 | TCGv ra = cpu_gpr[rA(ctx->opcode)]; | |
1755 | TCGv rs = cpu_gpr[rS(ctx->opcode)]; | |
1756 | TCGv t0 = tcg_temp_new(); | |
1757 | tcg_gen_shri_tl(t0, rs, 16); | |
1758 | tcg_gen_xor_tl(ra, rs, t0); | |
1759 | tcg_gen_shri_tl(t0, ra, 8); | |
1760 | tcg_gen_xor_tl(ra, ra, t0); | |
1761 | tcg_gen_andi_tl(ra, ra, (target_ulong)0x100000001ULL); | |
1762 | tcg_temp_free(t0); | |
1763 | } | |
1764 | ||
1765 | #if defined(TARGET_PPC64) | |
1766 | /* prtyd: PowerPC 2.05 specification */ | |
1767 | static void gen_prtyd(DisasContext *ctx) | |
1768 | { | |
1769 | TCGv ra = cpu_gpr[rA(ctx->opcode)]; | |
1770 | TCGv rs = cpu_gpr[rS(ctx->opcode)]; | |
1771 | TCGv t0 = tcg_temp_new(); | |
1772 | tcg_gen_shri_tl(t0, rs, 32); | |
1773 | tcg_gen_xor_tl(ra, rs, t0); | |
1774 | tcg_gen_shri_tl(t0, ra, 16); | |
1775 | tcg_gen_xor_tl(ra, ra, t0); | |
1776 | tcg_gen_shri_tl(t0, ra, 8); | |
1777 | tcg_gen_xor_tl(ra, ra, t0); | |
1778 | tcg_gen_andi_tl(ra, ra, 1); | |
1779 | tcg_temp_free(t0); | |
1780 | } | |
1781 | #endif | |
1782 | ||
86ba37ed TM |
1783 | #if defined(TARGET_PPC64) |
1784 | /* bpermd */ | |
1785 | static void gen_bpermd(DisasContext *ctx) | |
1786 | { | |
1787 | gen_helper_bpermd(cpu_gpr[rA(ctx->opcode)], | |
1788 | cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
1789 | } | |
1790 | #endif | |
1791 | ||
d9bce9d9 JM |
1792 | #if defined(TARGET_PPC64) |
1793 | /* extsw & extsw. */ | |
26d67362 | 1794 | GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B); |
99e300ef | 1795 | |
54623277 | 1796 | /* cntlzd */ |
99e300ef | 1797 | static void gen_cntlzd(DisasContext *ctx) |
26d67362 | 1798 | { |
9b8514e5 | 1799 | tcg_gen_clzi_i64(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], 64); |
26d67362 AJ |
1800 | if (unlikely(Rc(ctx->opcode) != 0)) |
1801 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1802 | } | |
e91d95b2 SD |
1803 | |
1804 | /* cnttzd */ | |
1805 | static void gen_cnttzd(DisasContext *ctx) | |
1806 | { | |
9b8514e5 | 1807 | tcg_gen_ctzi_i64(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], 64); |
e91d95b2 SD |
1808 | if (unlikely(Rc(ctx->opcode) != 0)) { |
1809 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1810 | } | |
1811 | } | |
fec5c62a RB |
1812 | |
1813 | /* darn */ | |
1814 | static void gen_darn(DisasContext *ctx) | |
1815 | { | |
1816 | int l = L(ctx->opcode); | |
1817 | ||
1818 | if (l == 0) { | |
1819 | gen_helper_darn32(cpu_gpr[rD(ctx->opcode)]); | |
1820 | } else if (l <= 2) { | |
1821 | /* Return 64-bit random for both CRN and RRN */ | |
1822 | gen_helper_darn64(cpu_gpr[rD(ctx->opcode)]); | |
1823 | } else { | |
1824 | tcg_gen_movi_i64(cpu_gpr[rD(ctx->opcode)], -1); | |
1825 | } | |
1826 | } | |
d9bce9d9 JM |
1827 | #endif |
1828 | ||
79aceca5 | 1829 | /*** Integer rotate ***/ |
99e300ef | 1830 | |
54623277 | 1831 | /* rlwimi & rlwimi. */ |
99e300ef | 1832 | static void gen_rlwimi(DisasContext *ctx) |
79aceca5 | 1833 | { |
63ae0915 RH |
1834 | TCGv t_ra = cpu_gpr[rA(ctx->opcode)]; |
1835 | TCGv t_rs = cpu_gpr[rS(ctx->opcode)]; | |
1836 | uint32_t sh = SH(ctx->opcode); | |
1837 | uint32_t mb = MB(ctx->opcode); | |
1838 | uint32_t me = ME(ctx->opcode); | |
1839 | ||
1840 | if (sh == (31-me) && mb <= me) { | |
1841 | tcg_gen_deposit_tl(t_ra, t_ra, t_rs, sh, me - mb + 1); | |
d03ef511 | 1842 | } else { |
d03ef511 | 1843 | target_ulong mask; |
a7812ae4 | 1844 | TCGv t1; |
63ae0915 | 1845 | |
76a66253 | 1846 | #if defined(TARGET_PPC64) |
d03ef511 AJ |
1847 | mb += 32; |
1848 | me += 32; | |
76a66253 | 1849 | #endif |
d03ef511 | 1850 | mask = MASK(mb, me); |
63ae0915 | 1851 | |
a7812ae4 | 1852 | t1 = tcg_temp_new(); |
2e11b15d RH |
1853 | if (mask <= 0xffffffffu) { |
1854 | TCGv_i32 t0 = tcg_temp_new_i32(); | |
1855 | tcg_gen_trunc_tl_i32(t0, t_rs); | |
1856 | tcg_gen_rotli_i32(t0, t0, sh); | |
1857 | tcg_gen_extu_i32_tl(t1, t0); | |
1858 | tcg_temp_free_i32(t0); | |
1859 | } else { | |
1860 | #if defined(TARGET_PPC64) | |
1861 | tcg_gen_deposit_i64(t1, t_rs, t_rs, 32, 32); | |
1862 | tcg_gen_rotli_i64(t1, t1, sh); | |
1863 | #else | |
1864 | g_assert_not_reached(); | |
1865 | #endif | |
1866 | } | |
63ae0915 RH |
1867 | |
1868 | tcg_gen_andi_tl(t1, t1, mask); | |
1869 | tcg_gen_andi_tl(t_ra, t_ra, ~mask); | |
1870 | tcg_gen_or_tl(t_ra, t_ra, t1); | |
d03ef511 AJ |
1871 | tcg_temp_free(t1); |
1872 | } | |
63ae0915 RH |
1873 | if (unlikely(Rc(ctx->opcode) != 0)) { |
1874 | gen_set_Rc0(ctx, t_ra); | |
1875 | } | |
79aceca5 | 1876 | } |
99e300ef | 1877 | |
54623277 | 1878 | /* rlwinm & rlwinm. */ |
99e300ef | 1879 | static void gen_rlwinm(DisasContext *ctx) |
79aceca5 | 1880 | { |
63ae0915 RH |
1881 | TCGv t_ra = cpu_gpr[rA(ctx->opcode)]; |
1882 | TCGv t_rs = cpu_gpr[rS(ctx->opcode)]; | |
7b4d326f RH |
1883 | int sh = SH(ctx->opcode); |
1884 | int mb = MB(ctx->opcode); | |
1885 | int me = ME(ctx->opcode); | |
1886 | int len = me - mb + 1; | |
1887 | int rsh = (32 - sh) & 31; | |
1888 | ||
1889 | if (sh != 0 && len > 0 && me == (31 - sh)) { | |
1890 | tcg_gen_deposit_z_tl(t_ra, t_rs, sh, len); | |
1891 | } else if (me == 31 && rsh + len <= 32) { | |
1892 | tcg_gen_extract_tl(t_ra, t_rs, rsh, len); | |
d03ef511 | 1893 | } else { |
2e11b15d | 1894 | target_ulong mask; |
76a66253 | 1895 | #if defined(TARGET_PPC64) |
d03ef511 AJ |
1896 | mb += 32; |
1897 | me += 32; | |
76a66253 | 1898 | #endif |
2e11b15d | 1899 | mask = MASK(mb, me); |
7b4d326f RH |
1900 | if (sh == 0) { |
1901 | tcg_gen_andi_tl(t_ra, t_rs, mask); | |
1902 | } else if (mask <= 0xffffffffu) { | |
63ae0915 | 1903 | TCGv_i32 t0 = tcg_temp_new_i32(); |
63ae0915 RH |
1904 | tcg_gen_trunc_tl_i32(t0, t_rs); |
1905 | tcg_gen_rotli_i32(t0, t0, sh); | |
2e11b15d | 1906 | tcg_gen_andi_i32(t0, t0, mask); |
63ae0915 RH |
1907 | tcg_gen_extu_i32_tl(t_ra, t0); |
1908 | tcg_temp_free_i32(t0); | |
2e11b15d RH |
1909 | } else { |
1910 | #if defined(TARGET_PPC64) | |
1911 | tcg_gen_deposit_i64(t_ra, t_rs, t_rs, 32, 32); | |
1912 | tcg_gen_rotli_i64(t_ra, t_ra, sh); | |
1913 | tcg_gen_andi_i64(t_ra, t_ra, mask); | |
1914 | #else | |
1915 | g_assert_not_reached(); | |
1916 | #endif | |
63ae0915 RH |
1917 | } |
1918 | } | |
1919 | if (unlikely(Rc(ctx->opcode) != 0)) { | |
1920 | gen_set_Rc0(ctx, t_ra); | |
d03ef511 | 1921 | } |
79aceca5 | 1922 | } |
99e300ef | 1923 | |
54623277 | 1924 | /* rlwnm & rlwnm. */ |
99e300ef | 1925 | static void gen_rlwnm(DisasContext *ctx) |
79aceca5 | 1926 | { |
63ae0915 RH |
1927 | TCGv t_ra = cpu_gpr[rA(ctx->opcode)]; |
1928 | TCGv t_rs = cpu_gpr[rS(ctx->opcode)]; | |
1929 | TCGv t_rb = cpu_gpr[rB(ctx->opcode)]; | |
1930 | uint32_t mb = MB(ctx->opcode); | |
1931 | uint32_t me = ME(ctx->opcode); | |
2e11b15d | 1932 | target_ulong mask; |
57fca134 | 1933 | |
54843a58 | 1934 | #if defined(TARGET_PPC64) |
63ae0915 RH |
1935 | mb += 32; |
1936 | me += 32; | |
54843a58 | 1937 | #endif |
2e11b15d RH |
1938 | mask = MASK(mb, me); |
1939 | ||
1940 | if (mask <= 0xffffffffu) { | |
1941 | TCGv_i32 t0 = tcg_temp_new_i32(); | |
1942 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
1943 | tcg_gen_trunc_tl_i32(t0, t_rb); | |
1944 | tcg_gen_trunc_tl_i32(t1, t_rs); | |
1945 | tcg_gen_andi_i32(t0, t0, 0x1f); | |
1946 | tcg_gen_rotl_i32(t1, t1, t0); | |
1947 | tcg_gen_extu_i32_tl(t_ra, t1); | |
1948 | tcg_temp_free_i32(t0); | |
1949 | tcg_temp_free_i32(t1); | |
1950 | } else { | |
1951 | #if defined(TARGET_PPC64) | |
1952 | TCGv_i64 t0 = tcg_temp_new_i64(); | |
1953 | tcg_gen_andi_i64(t0, t_rb, 0x1f); | |
1954 | tcg_gen_deposit_i64(t_ra, t_rs, t_rs, 32, 32); | |
1955 | tcg_gen_rotl_i64(t_ra, t_ra, t0); | |
1956 | tcg_temp_free_i64(t0); | |
1957 | #else | |
1958 | g_assert_not_reached(); | |
1959 | #endif | |
1960 | } | |
57fca134 | 1961 | |
2e11b15d | 1962 | tcg_gen_andi_tl(t_ra, t_ra, mask); |
63ae0915 RH |
1963 | |
1964 | if (unlikely(Rc(ctx->opcode) != 0)) { | |
1965 | gen_set_Rc0(ctx, t_ra); | |
79aceca5 | 1966 | } |
79aceca5 FB |
1967 | } |
1968 | ||
d9bce9d9 JM |
1969 | #if defined(TARGET_PPC64) |
1970 | #define GEN_PPC64_R2(name, opc1, opc2) \ | |
e8eaa2c0 | 1971 | static void glue(gen_, name##0)(DisasContext *ctx) \ |
d9bce9d9 JM |
1972 | { \ |
1973 | gen_##name(ctx, 0); \ | |
1974 | } \ | |
e8eaa2c0 BS |
1975 | \ |
1976 | static void glue(gen_, name##1)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1977 | { \ |
1978 | gen_##name(ctx, 1); \ | |
1979 | } | |
1980 | #define GEN_PPC64_R4(name, opc1, opc2) \ | |
e8eaa2c0 | 1981 | static void glue(gen_, name##0)(DisasContext *ctx) \ |
d9bce9d9 JM |
1982 | { \ |
1983 | gen_##name(ctx, 0, 0); \ | |
1984 | } \ | |
e8eaa2c0 BS |
1985 | \ |
1986 | static void glue(gen_, name##1)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1987 | { \ |
1988 | gen_##name(ctx, 0, 1); \ | |
1989 | } \ | |
e8eaa2c0 BS |
1990 | \ |
1991 | static void glue(gen_, name##2)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1992 | { \ |
1993 | gen_##name(ctx, 1, 0); \ | |
1994 | } \ | |
e8eaa2c0 BS |
1995 | \ |
1996 | static void glue(gen_, name##3)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1997 | { \ |
1998 | gen_##name(ctx, 1, 1); \ | |
1999 | } | |
51789c41 | 2000 | |
a7b2c8b9 | 2001 | static void gen_rldinm(DisasContext *ctx, int mb, int me, int sh) |
51789c41 | 2002 | { |
a7b2c8b9 RH |
2003 | TCGv t_ra = cpu_gpr[rA(ctx->opcode)]; |
2004 | TCGv t_rs = cpu_gpr[rS(ctx->opcode)]; | |
7b4d326f RH |
2005 | int len = me - mb + 1; |
2006 | int rsh = (64 - sh) & 63; | |
a7b2c8b9 | 2007 | |
7b4d326f RH |
2008 | if (sh != 0 && len > 0 && me == (63 - sh)) { |
2009 | tcg_gen_deposit_z_tl(t_ra, t_rs, sh, len); | |
2010 | } else if (me == 63 && rsh + len <= 64) { | |
2011 | tcg_gen_extract_tl(t_ra, t_rs, rsh, len); | |
d03ef511 | 2012 | } else { |
a7b2c8b9 RH |
2013 | tcg_gen_rotli_tl(t_ra, t_rs, sh); |
2014 | tcg_gen_andi_tl(t_ra, t_ra, MASK(mb, me)); | |
2015 | } | |
2016 | if (unlikely(Rc(ctx->opcode) != 0)) { | |
2017 | gen_set_Rc0(ctx, t_ra); | |
51789c41 | 2018 | } |
51789c41 | 2019 | } |
a7b2c8b9 | 2020 | |
d9bce9d9 | 2021 | /* rldicl - rldicl. */ |
636aa200 | 2022 | static inline void gen_rldicl(DisasContext *ctx, int mbn, int shn) |
d9bce9d9 | 2023 | { |
51789c41 | 2024 | uint32_t sh, mb; |
d9bce9d9 | 2025 | |
9d53c753 JM |
2026 | sh = SH(ctx->opcode) | (shn << 5); |
2027 | mb = MB(ctx->opcode) | (mbn << 5); | |
51789c41 | 2028 | gen_rldinm(ctx, mb, 63, sh); |
d9bce9d9 | 2029 | } |
51789c41 | 2030 | GEN_PPC64_R4(rldicl, 0x1E, 0x00); |
a7b2c8b9 | 2031 | |
d9bce9d9 | 2032 | /* rldicr - rldicr. */ |
636aa200 | 2033 | static inline void gen_rldicr(DisasContext *ctx, int men, int shn) |
d9bce9d9 | 2034 | { |
51789c41 | 2035 | uint32_t sh, me; |
d9bce9d9 | 2036 | |
9d53c753 JM |
2037 | sh = SH(ctx->opcode) | (shn << 5); |
2038 | me = MB(ctx->opcode) | (men << 5); | |
51789c41 | 2039 | gen_rldinm(ctx, 0, me, sh); |
d9bce9d9 | 2040 | } |
51789c41 | 2041 | GEN_PPC64_R4(rldicr, 0x1E, 0x02); |
a7b2c8b9 | 2042 | |
d9bce9d9 | 2043 | /* rldic - rldic. */ |
636aa200 | 2044 | static inline void gen_rldic(DisasContext *ctx, int mbn, int shn) |
d9bce9d9 | 2045 | { |
51789c41 | 2046 | uint32_t sh, mb; |
d9bce9d9 | 2047 | |
9d53c753 JM |
2048 | sh = SH(ctx->opcode) | (shn << 5); |
2049 | mb = MB(ctx->opcode) | (mbn << 5); | |
51789c41 JM |
2050 | gen_rldinm(ctx, mb, 63 - sh, sh); |
2051 | } | |
2052 | GEN_PPC64_R4(rldic, 0x1E, 0x04); | |
2053 | ||
a7b2c8b9 | 2054 | static void gen_rldnm(DisasContext *ctx, int mb, int me) |
51789c41 | 2055 | { |
a7b2c8b9 RH |
2056 | TCGv t_ra = cpu_gpr[rA(ctx->opcode)]; |
2057 | TCGv t_rs = cpu_gpr[rS(ctx->opcode)]; | |
2058 | TCGv t_rb = cpu_gpr[rB(ctx->opcode)]; | |
54843a58 | 2059 | TCGv t0; |
d03ef511 | 2060 | |
a7812ae4 | 2061 | t0 = tcg_temp_new(); |
a7b2c8b9 RH |
2062 | tcg_gen_andi_tl(t0, t_rb, 0x3f); |
2063 | tcg_gen_rotl_tl(t_ra, t_rs, t0); | |
54843a58 | 2064 | tcg_temp_free(t0); |
a7b2c8b9 RH |
2065 | |
2066 | tcg_gen_andi_tl(t_ra, t_ra, MASK(mb, me)); | |
2067 | if (unlikely(Rc(ctx->opcode) != 0)) { | |
2068 | gen_set_Rc0(ctx, t_ra); | |
2069 | } | |
d9bce9d9 | 2070 | } |
51789c41 | 2071 | |
d9bce9d9 | 2072 | /* rldcl - rldcl. */ |
636aa200 | 2073 | static inline void gen_rldcl(DisasContext *ctx, int mbn) |
d9bce9d9 | 2074 | { |
51789c41 | 2075 | uint32_t mb; |
d9bce9d9 | 2076 | |
9d53c753 | 2077 | mb = MB(ctx->opcode) | (mbn << 5); |
51789c41 | 2078 | gen_rldnm(ctx, mb, 63); |
d9bce9d9 | 2079 | } |
36081602 | 2080 | GEN_PPC64_R2(rldcl, 0x1E, 0x08); |
a7b2c8b9 | 2081 | |
d9bce9d9 | 2082 | /* rldcr - rldcr. */ |
636aa200 | 2083 | static inline void gen_rldcr(DisasContext *ctx, int men) |
d9bce9d9 | 2084 | { |
51789c41 | 2085 | uint32_t me; |
d9bce9d9 | 2086 | |
9d53c753 | 2087 | me = MB(ctx->opcode) | (men << 5); |
51789c41 | 2088 | gen_rldnm(ctx, 0, me); |
d9bce9d9 | 2089 | } |
36081602 | 2090 | GEN_PPC64_R2(rldcr, 0x1E, 0x09); |
a7b2c8b9 | 2091 | |
d9bce9d9 | 2092 | /* rldimi - rldimi. */ |
a7b2c8b9 | 2093 | static void gen_rldimi(DisasContext *ctx, int mbn, int shn) |
d9bce9d9 | 2094 | { |
a7b2c8b9 RH |
2095 | TCGv t_ra = cpu_gpr[rA(ctx->opcode)]; |
2096 | TCGv t_rs = cpu_gpr[rS(ctx->opcode)]; | |
2097 | uint32_t sh = SH(ctx->opcode) | (shn << 5); | |
2098 | uint32_t mb = MB(ctx->opcode) | (mbn << 5); | |
2099 | uint32_t me = 63 - sh; | |
d9bce9d9 | 2100 | |
a7b2c8b9 RH |
2101 | if (mb <= me) { |
2102 | tcg_gen_deposit_tl(t_ra, t_ra, t_rs, sh, me - mb + 1); | |
d03ef511 | 2103 | } else { |
a7b2c8b9 RH |
2104 | target_ulong mask = MASK(mb, me); |
2105 | TCGv t1 = tcg_temp_new(); | |
d03ef511 | 2106 | |
a7b2c8b9 RH |
2107 | tcg_gen_rotli_tl(t1, t_rs, sh); |
2108 | tcg_gen_andi_tl(t1, t1, mask); | |
2109 | tcg_gen_andi_tl(t_ra, t_ra, ~mask); | |
2110 | tcg_gen_or_tl(t_ra, t_ra, t1); | |
d03ef511 | 2111 | tcg_temp_free(t1); |
51789c41 | 2112 | } |
a7b2c8b9 RH |
2113 | if (unlikely(Rc(ctx->opcode) != 0)) { |
2114 | gen_set_Rc0(ctx, t_ra); | |
2115 | } | |
d9bce9d9 | 2116 | } |
36081602 | 2117 | GEN_PPC64_R4(rldimi, 0x1E, 0x06); |
d9bce9d9 JM |
2118 | #endif |
2119 | ||
79aceca5 | 2120 | /*** Integer shift ***/ |
99e300ef | 2121 | |
54623277 | 2122 | /* slw & slw. */ |
99e300ef | 2123 | static void gen_slw(DisasContext *ctx) |
26d67362 | 2124 | { |
7fd6bf7d | 2125 | TCGv t0, t1; |
26d67362 | 2126 | |
7fd6bf7d AJ |
2127 | t0 = tcg_temp_new(); |
2128 | /* AND rS with a mask that is 0 when rB >= 0x20 */ | |
2129 | #if defined(TARGET_PPC64) | |
2130 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a); | |
2131 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
2132 | #else | |
2133 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a); | |
2134 | tcg_gen_sari_tl(t0, t0, 0x1f); | |
2135 | #endif | |
2136 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
2137 | t1 = tcg_temp_new(); | |
2138 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f); | |
2139 | tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
2140 | tcg_temp_free(t1); | |
fea0c503 | 2141 | tcg_temp_free(t0); |
7fd6bf7d | 2142 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
26d67362 AJ |
2143 | if (unlikely(Rc(ctx->opcode) != 0)) |
2144 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
2145 | } | |
99e300ef | 2146 | |
54623277 | 2147 | /* sraw & sraw. */ |
99e300ef | 2148 | static void gen_sraw(DisasContext *ctx) |
26d67362 | 2149 | { |
d15f74fb | 2150 | gen_helper_sraw(cpu_gpr[rA(ctx->opcode)], cpu_env, |
a7812ae4 | 2151 | cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
26d67362 AJ |
2152 | if (unlikely(Rc(ctx->opcode) != 0)) |
2153 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
2154 | } | |
99e300ef | 2155 | |
54623277 | 2156 | /* srawi & srawi. */ |
99e300ef | 2157 | static void gen_srawi(DisasContext *ctx) |
79aceca5 | 2158 | { |
26d67362 | 2159 | int sh = SH(ctx->opcode); |
ba4af3e4 RH |
2160 | TCGv dst = cpu_gpr[rA(ctx->opcode)]; |
2161 | TCGv src = cpu_gpr[rS(ctx->opcode)]; | |
2162 | if (sh == 0) { | |
34a0fad1 | 2163 | tcg_gen_ext32s_tl(dst, src); |
da91a00f | 2164 | tcg_gen_movi_tl(cpu_ca, 0); |
af1c259f SD |
2165 | if (is_isa300(ctx)) { |
2166 | tcg_gen_movi_tl(cpu_ca32, 0); | |
2167 | } | |
26d67362 | 2168 | } else { |
ba4af3e4 RH |
2169 | TCGv t0; |
2170 | tcg_gen_ext32s_tl(dst, src); | |
2171 | tcg_gen_andi_tl(cpu_ca, dst, (1ULL << sh) - 1); | |
2172 | t0 = tcg_temp_new(); | |
2173 | tcg_gen_sari_tl(t0, dst, TARGET_LONG_BITS - 1); | |
2174 | tcg_gen_and_tl(cpu_ca, cpu_ca, t0); | |
2175 | tcg_temp_free(t0); | |
2176 | tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0); | |
af1c259f SD |
2177 | if (is_isa300(ctx)) { |
2178 | tcg_gen_mov_tl(cpu_ca32, cpu_ca); | |
2179 | } | |
ba4af3e4 RH |
2180 | tcg_gen_sari_tl(dst, dst, sh); |
2181 | } | |
2182 | if (unlikely(Rc(ctx->opcode) != 0)) { | |
2183 | gen_set_Rc0(ctx, dst); | |
d9bce9d9 | 2184 | } |
79aceca5 | 2185 | } |
99e300ef | 2186 | |
54623277 | 2187 | /* srw & srw. */ |
99e300ef | 2188 | static void gen_srw(DisasContext *ctx) |
26d67362 | 2189 | { |
fea0c503 | 2190 | TCGv t0, t1; |
d9bce9d9 | 2191 | |
7fd6bf7d AJ |
2192 | t0 = tcg_temp_new(); |
2193 | /* AND rS with a mask that is 0 when rB >= 0x20 */ | |
2194 | #if defined(TARGET_PPC64) | |
2195 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a); | |
2196 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
2197 | #else | |
2198 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a); | |
2199 | tcg_gen_sari_tl(t0, t0, 0x1f); | |
2200 | #endif | |
2201 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
2202 | tcg_gen_ext32u_tl(t0, t0); | |
a7812ae4 | 2203 | t1 = tcg_temp_new(); |
7fd6bf7d AJ |
2204 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f); |
2205 | tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
fea0c503 | 2206 | tcg_temp_free(t1); |
fea0c503 | 2207 | tcg_temp_free(t0); |
26d67362 AJ |
2208 | if (unlikely(Rc(ctx->opcode) != 0)) |
2209 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
2210 | } | |
54623277 | 2211 | |
d9bce9d9 JM |
2212 | #if defined(TARGET_PPC64) |
2213 | /* sld & sld. */ | |
99e300ef | 2214 | static void gen_sld(DisasContext *ctx) |
26d67362 | 2215 | { |
7fd6bf7d | 2216 | TCGv t0, t1; |
26d67362 | 2217 | |
7fd6bf7d AJ |
2218 | t0 = tcg_temp_new(); |
2219 | /* AND rS with a mask that is 0 when rB >= 0x40 */ | |
2220 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39); | |
2221 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
2222 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
2223 | t1 = tcg_temp_new(); | |
2224 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f); | |
2225 | tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
2226 | tcg_temp_free(t1); | |
fea0c503 | 2227 | tcg_temp_free(t0); |
26d67362 AJ |
2228 | if (unlikely(Rc(ctx->opcode) != 0)) |
2229 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
2230 | } | |
99e300ef | 2231 | |
54623277 | 2232 | /* srad & srad. */ |
99e300ef | 2233 | static void gen_srad(DisasContext *ctx) |
26d67362 | 2234 | { |
d15f74fb | 2235 | gen_helper_srad(cpu_gpr[rA(ctx->opcode)], cpu_env, |
a7812ae4 | 2236 | cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
26d67362 AJ |
2237 | if (unlikely(Rc(ctx->opcode) != 0)) |
2238 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
2239 | } | |
d9bce9d9 | 2240 | /* sradi & sradi. */ |
636aa200 | 2241 | static inline void gen_sradi(DisasContext *ctx, int n) |
d9bce9d9 | 2242 | { |
26d67362 | 2243 | int sh = SH(ctx->opcode) + (n << 5); |
ba4af3e4 RH |
2244 | TCGv dst = cpu_gpr[rA(ctx->opcode)]; |
2245 | TCGv src = cpu_gpr[rS(ctx->opcode)]; | |
2246 | if (sh == 0) { | |
2247 | tcg_gen_mov_tl(dst, src); | |
da91a00f | 2248 | tcg_gen_movi_tl(cpu_ca, 0); |
af1c259f SD |
2249 | if (is_isa300(ctx)) { |
2250 | tcg_gen_movi_tl(cpu_ca32, 0); | |
2251 | } | |
26d67362 | 2252 | } else { |
ba4af3e4 RH |
2253 | TCGv t0; |
2254 | tcg_gen_andi_tl(cpu_ca, src, (1ULL << sh) - 1); | |
2255 | t0 = tcg_temp_new(); | |
2256 | tcg_gen_sari_tl(t0, src, TARGET_LONG_BITS - 1); | |
2257 | tcg_gen_and_tl(cpu_ca, cpu_ca, t0); | |
2258 | tcg_temp_free(t0); | |
2259 | tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0); | |
af1c259f SD |
2260 | if (is_isa300(ctx)) { |
2261 | tcg_gen_mov_tl(cpu_ca32, cpu_ca); | |
2262 | } | |
ba4af3e4 RH |
2263 | tcg_gen_sari_tl(dst, src, sh); |
2264 | } | |
2265 | if (unlikely(Rc(ctx->opcode) != 0)) { | |
2266 | gen_set_Rc0(ctx, dst); | |
d9bce9d9 | 2267 | } |
d9bce9d9 | 2268 | } |
e8eaa2c0 BS |
2269 | |
2270 | static void gen_sradi0(DisasContext *ctx) | |
d9bce9d9 JM |
2271 | { |
2272 | gen_sradi(ctx, 0); | |
2273 | } | |
e8eaa2c0 BS |
2274 | |
2275 | static void gen_sradi1(DisasContext *ctx) | |
d9bce9d9 JM |
2276 | { |
2277 | gen_sradi(ctx, 1); | |
2278 | } | |
99e300ef | 2279 | |
787bbe37 ND |
2280 | /* extswsli & extswsli. */ |
2281 | static inline void gen_extswsli(DisasContext *ctx, int n) | |
2282 | { | |
2283 | int sh = SH(ctx->opcode) + (n << 5); | |
2284 | TCGv dst = cpu_gpr[rA(ctx->opcode)]; | |
2285 | TCGv src = cpu_gpr[rS(ctx->opcode)]; | |
2286 | ||
2287 | tcg_gen_ext32s_tl(dst, src); | |
2288 | tcg_gen_shli_tl(dst, dst, sh); | |
2289 | if (unlikely(Rc(ctx->opcode) != 0)) { | |
2290 | gen_set_Rc0(ctx, dst); | |
2291 | } | |
2292 | } | |
2293 | ||
2294 | static void gen_extswsli0(DisasContext *ctx) | |
2295 | { | |
2296 | gen_extswsli(ctx, 0); | |
2297 | } | |
2298 | ||
2299 | static void gen_extswsli1(DisasContext *ctx) | |
2300 | { | |
2301 | gen_extswsli(ctx, 1); | |
2302 | } | |
2303 | ||
54623277 | 2304 | /* srd & srd. */ |
99e300ef | 2305 | static void gen_srd(DisasContext *ctx) |
26d67362 | 2306 | { |
7fd6bf7d | 2307 | TCGv t0, t1; |
26d67362 | 2308 | |
7fd6bf7d AJ |
2309 | t0 = tcg_temp_new(); |
2310 | /* AND rS with a mask that is 0 when rB >= 0x40 */ | |
2311 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39); | |
2312 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
2313 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
2314 | t1 = tcg_temp_new(); | |
2315 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f); | |
2316 | tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
2317 | tcg_temp_free(t1); | |
fea0c503 | 2318 | tcg_temp_free(t0); |
26d67362 AJ |
2319 | if (unlikely(Rc(ctx->opcode) != 0)) |
2320 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
2321 | } | |
d9bce9d9 | 2322 | #endif |
79aceca5 | 2323 | |
76a66253 JM |
2324 | /*** Addressing modes ***/ |
2325 | /* Register indirect with immediate index : EA = (rA|0) + SIMM */ | |
636aa200 BS |
2326 | static inline void gen_addr_imm_index(DisasContext *ctx, TCGv EA, |
2327 | target_long maskl) | |
76a66253 JM |
2328 | { |
2329 | target_long simm = SIMM(ctx->opcode); | |
2330 | ||
be147d08 | 2331 | simm &= ~maskl; |
76db3ba4 | 2332 | if (rA(ctx->opcode) == 0) { |
c791fe84 RH |
2333 | if (NARROW_MODE(ctx)) { |
2334 | simm = (uint32_t)simm; | |
2335 | } | |
e2be8d8d | 2336 | tcg_gen_movi_tl(EA, simm); |
76db3ba4 | 2337 | } else if (likely(simm != 0)) { |
e2be8d8d | 2338 | tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm); |
c791fe84 | 2339 | if (NARROW_MODE(ctx)) { |
76db3ba4 AJ |
2340 | tcg_gen_ext32u_tl(EA, EA); |
2341 | } | |
76db3ba4 | 2342 | } else { |
c791fe84 | 2343 | if (NARROW_MODE(ctx)) { |
76db3ba4 | 2344 | tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]); |
c791fe84 RH |
2345 | } else { |
2346 | tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]); | |
2347 | } | |
76db3ba4 | 2348 | } |
76a66253 JM |
2349 | } |
2350 | ||
636aa200 | 2351 | static inline void gen_addr_reg_index(DisasContext *ctx, TCGv EA) |
76a66253 | 2352 | { |
76db3ba4 | 2353 | if (rA(ctx->opcode) == 0) { |
c791fe84 | 2354 | if (NARROW_MODE(ctx)) { |
76db3ba4 | 2355 | tcg_gen_ext32u_tl(EA, cpu_gpr[rB(ctx->opcode)]); |
c791fe84 RH |
2356 | } else { |
2357 | tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]); | |
2358 | } | |
76db3ba4 | 2359 | } else { |
e2be8d8d | 2360 | tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
c791fe84 | 2361 | if (NARROW_MODE(ctx)) { |
76db3ba4 AJ |
2362 | tcg_gen_ext32u_tl(EA, EA); |
2363 | } | |
76db3ba4 | 2364 | } |
76a66253 JM |
2365 | } |
2366 | ||
636aa200 | 2367 | static inline void gen_addr_register(DisasContext *ctx, TCGv EA) |
76a66253 | 2368 | { |
76db3ba4 | 2369 | if (rA(ctx->opcode) == 0) { |
e2be8d8d | 2370 | tcg_gen_movi_tl(EA, 0); |
c791fe84 RH |
2371 | } else if (NARROW_MODE(ctx)) { |
2372 | tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]); | |
76db3ba4 | 2373 | } else { |
c791fe84 | 2374 | tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]); |
76db3ba4 AJ |
2375 | } |
2376 | } | |
2377 | ||
636aa200 BS |
2378 | static inline void gen_addr_add(DisasContext *ctx, TCGv ret, TCGv arg1, |
2379 | target_long val) | |
76db3ba4 AJ |
2380 | { |
2381 | tcg_gen_addi_tl(ret, arg1, val); | |
c791fe84 | 2382 | if (NARROW_MODE(ctx)) { |
76db3ba4 AJ |
2383 | tcg_gen_ext32u_tl(ret, ret); |
2384 | } | |
76a66253 JM |
2385 | } |
2386 | ||
65f2475f BH |
2387 | static inline void gen_align_no_le(DisasContext *ctx) |
2388 | { | |
2389 | gen_exception_err(ctx, POWERPC_EXCP_ALIGN, | |
2390 | (ctx->opcode & 0x03FF0000) | POWERPC_EXCP_ALIGN_LE); | |
2391 | } | |
2392 | ||
7863667f | 2393 | /*** Integer load ***/ |
09bfe50d | 2394 | #define DEF_MEMOP(op) ((op) | ctx->default_tcg_memop_mask) |
ff5f3981 | 2395 | #define BSWAP_MEMOP(op) ((op) | (ctx->default_tcg_memop_mask ^ MO_BSWAP)) |
b61f2753 | 2396 | |
09bfe50d ND |
2397 | #define GEN_QEMU_LOAD_TL(ldop, op) \ |
2398 | static void glue(gen_qemu_, ldop)(DisasContext *ctx, \ | |
2399 | TCGv val, \ | |
2400 | TCGv addr) \ | |
2401 | { \ | |
2402 | tcg_gen_qemu_ld_tl(val, addr, ctx->mem_idx, op); \ | |
b61f2753 AJ |
2403 | } |
2404 | ||
09bfe50d ND |
2405 | GEN_QEMU_LOAD_TL(ld8u, DEF_MEMOP(MO_UB)) |
2406 | GEN_QEMU_LOAD_TL(ld16u, DEF_MEMOP(MO_UW)) | |
2407 | GEN_QEMU_LOAD_TL(ld16s, DEF_MEMOP(MO_SW)) | |
2408 | GEN_QEMU_LOAD_TL(ld32u, DEF_MEMOP(MO_UL)) | |
2409 | GEN_QEMU_LOAD_TL(ld32s, DEF_MEMOP(MO_SL)) | |
f976b09e | 2410 | |
ff5f3981 ND |
2411 | GEN_QEMU_LOAD_TL(ld16ur, BSWAP_MEMOP(MO_UW)) |
2412 | GEN_QEMU_LOAD_TL(ld32ur, BSWAP_MEMOP(MO_UL)) | |
2413 | ||
09bfe50d ND |
2414 | #define GEN_QEMU_LOAD_64(ldop, op) \ |
2415 | static void glue(gen_qemu_, glue(ldop, _i64))(DisasContext *ctx, \ | |
2416 | TCGv_i64 val, \ | |
2417 | TCGv addr) \ | |
2418 | { \ | |
2419 | tcg_gen_qemu_ld_i64(val, addr, ctx->mem_idx, op); \ | |
b61f2753 AJ |
2420 | } |
2421 | ||
740ae9a2 ND |
2422 | GEN_QEMU_LOAD_64(ld8u, DEF_MEMOP(MO_UB)) |
2423 | GEN_QEMU_LOAD_64(ld16u, DEF_MEMOP(MO_UW)) | |
09bfe50d ND |
2424 | GEN_QEMU_LOAD_64(ld32u, DEF_MEMOP(MO_UL)) |
2425 | GEN_QEMU_LOAD_64(ld32s, DEF_MEMOP(MO_SL)) | |
4f364fe7 | 2426 | GEN_QEMU_LOAD_64(ld64, DEF_MEMOP(MO_Q)) |
b61f2753 | 2427 | |
ff5f3981 ND |
2428 | #if defined(TARGET_PPC64) |
2429 | GEN_QEMU_LOAD_64(ld64ur, BSWAP_MEMOP(MO_Q)) | |
2430 | #endif | |
2431 | ||
761a89c6 ND |
2432 | #define GEN_QEMU_STORE_TL(stop, op) \ |
2433 | static void glue(gen_qemu_, stop)(DisasContext *ctx, \ | |
2434 | TCGv val, \ | |
2435 | TCGv addr) \ | |
2436 | { \ | |
2437 | tcg_gen_qemu_st_tl(val, addr, ctx->mem_idx, op); \ | |
b61f2753 AJ |
2438 | } |
2439 | ||
761a89c6 ND |
2440 | GEN_QEMU_STORE_TL(st8, DEF_MEMOP(MO_UB)) |
2441 | GEN_QEMU_STORE_TL(st16, DEF_MEMOP(MO_UW)) | |
2442 | GEN_QEMU_STORE_TL(st32, DEF_MEMOP(MO_UL)) | |
b61f2753 | 2443 | |
804108aa ND |
2444 | GEN_QEMU_STORE_TL(st16r, BSWAP_MEMOP(MO_UW)) |
2445 | GEN_QEMU_STORE_TL(st32r, BSWAP_MEMOP(MO_UL)) | |
2446 | ||
761a89c6 ND |
2447 | #define GEN_QEMU_STORE_64(stop, op) \ |
2448 | static void glue(gen_qemu_, glue(stop, _i64))(DisasContext *ctx, \ | |
2449 | TCGv_i64 val, \ | |
2450 | TCGv addr) \ | |
2451 | { \ | |
2452 | tcg_gen_qemu_st_i64(val, addr, ctx->mem_idx, op); \ | |
b61f2753 AJ |
2453 | } |
2454 | ||
ddb9ac50 ND |
2455 | GEN_QEMU_STORE_64(st8, DEF_MEMOP(MO_UB)) |
2456 | GEN_QEMU_STORE_64(st16, DEF_MEMOP(MO_UW)) | |
761a89c6 | 2457 | GEN_QEMU_STORE_64(st32, DEF_MEMOP(MO_UL)) |
2468f23d | 2458 | GEN_QEMU_STORE_64(st64, DEF_MEMOP(MO_Q)) |
b61f2753 | 2459 | |
804108aa ND |
2460 | #if defined(TARGET_PPC64) |
2461 | GEN_QEMU_STORE_64(st64r, BSWAP_MEMOP(MO_Q)) | |
2462 | #endif | |
2463 | ||
0c8aacd4 | 2464 | #define GEN_LD(name, ldop, opc, type) \ |
99e300ef | 2465 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 2466 | { \ |
76db3ba4 AJ |
2467 | TCGv EA; \ |
2468 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2469 | EA = tcg_temp_new(); \ | |
2470 | gen_addr_imm_index(ctx, EA, 0); \ | |
2471 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 | 2472 | tcg_temp_free(EA); \ |
79aceca5 FB |
2473 | } |
2474 | ||
0c8aacd4 | 2475 | #define GEN_LDU(name, ldop, opc, type) \ |
99e300ef | 2476 | static void glue(gen_, name##u)(DisasContext *ctx) \ |
79aceca5 | 2477 | { \ |
b61f2753 | 2478 | TCGv EA; \ |
76a66253 JM |
2479 | if (unlikely(rA(ctx->opcode) == 0 || \ |
2480 | rA(ctx->opcode) == rD(ctx->opcode))) { \ | |
e06fcd75 | 2481 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2482 | return; \ |
9a64fbe4 | 2483 | } \ |
76db3ba4 | 2484 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2485 | EA = tcg_temp_new(); \ |
9d53c753 | 2486 | if (type == PPC_64B) \ |
76db3ba4 | 2487 | gen_addr_imm_index(ctx, EA, 0x03); \ |
9d53c753 | 2488 | else \ |
76db3ba4 AJ |
2489 | gen_addr_imm_index(ctx, EA, 0); \ |
2490 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2491 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2492 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2493 | } |
2494 | ||
0c8aacd4 | 2495 | #define GEN_LDUX(name, ldop, opc2, opc3, type) \ |
99e300ef | 2496 | static void glue(gen_, name##ux)(DisasContext *ctx) \ |
79aceca5 | 2497 | { \ |
b61f2753 | 2498 | TCGv EA; \ |
76a66253 JM |
2499 | if (unlikely(rA(ctx->opcode) == 0 || \ |
2500 | rA(ctx->opcode) == rD(ctx->opcode))) { \ | |
e06fcd75 | 2501 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2502 | return; \ |
9a64fbe4 | 2503 | } \ |
76db3ba4 | 2504 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2505 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
2506 | gen_addr_reg_index(ctx, EA); \ |
2507 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2508 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2509 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2510 | } |
2511 | ||
b7815375 | 2512 | #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2, chk) \ |
99e300ef | 2513 | static void glue(gen_, name##x)(DisasContext *ctx) \ |
79aceca5 | 2514 | { \ |
76db3ba4 | 2515 | TCGv EA; \ |
b7815375 | 2516 | chk; \ |
76db3ba4 AJ |
2517 | gen_set_access_type(ctx, ACCESS_INT); \ |
2518 | EA = tcg_temp_new(); \ | |
2519 | gen_addr_reg_index(ctx, EA); \ | |
2520 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 | 2521 | tcg_temp_free(EA); \ |
79aceca5 | 2522 | } |
b7815375 | 2523 | |
cd6e9320 | 2524 | #define GEN_LDX(name, ldop, opc2, opc3, type) \ |
b7815375 BH |
2525 | GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE, CHK_NONE) |
2526 | ||
2527 | #define GEN_LDX_HVRM(name, ldop, opc2, opc3, type) \ | |
2528 | GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE, CHK_HVRM) | |
79aceca5 | 2529 | |
0c8aacd4 AJ |
2530 | #define GEN_LDS(name, ldop, op, type) \ |
2531 | GEN_LD(name, ldop, op | 0x20, type); \ | |
2532 | GEN_LDU(name, ldop, op | 0x21, type); \ | |
2533 | GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \ | |
2534 | GEN_LDX(name, ldop, 0x17, op | 0x00, type) | |
79aceca5 FB |
2535 | |
2536 | /* lbz lbzu lbzux lbzx */ | |
0c8aacd4 | 2537 | GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER); |
79aceca5 | 2538 | /* lha lhau lhaux lhax */ |
0c8aacd4 | 2539 | GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER); |
79aceca5 | 2540 | /* lhz lhzu lhzux lhzx */ |
0c8aacd4 | 2541 | GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER); |
79aceca5 | 2542 | /* lwz lwzu lwzux lwzx */ |
0c8aacd4 | 2543 | GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER); |
50728199 RK |
2544 | |
2545 | #define GEN_LDEPX(name, ldop, opc2, opc3) \ | |
2546 | static void glue(gen_, name##epx)(DisasContext *ctx) \ | |
2547 | { \ | |
2548 | TCGv EA; \ | |
2549 | CHK_SV; \ | |
2550 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2551 | EA = tcg_temp_new(); \ | |
2552 | gen_addr_reg_index(ctx, EA); \ | |
2553 | tcg_gen_qemu_ld_tl(cpu_gpr[rD(ctx->opcode)], EA, PPC_TLB_EPID_LOAD, ldop);\ | |
2554 | tcg_temp_free(EA); \ | |
2555 | } | |
2556 | ||
2557 | GEN_LDEPX(lb, DEF_MEMOP(MO_UB), 0x1F, 0x02) | |
2558 | GEN_LDEPX(lh, DEF_MEMOP(MO_UW), 0x1F, 0x08) | |
2559 | GEN_LDEPX(lw, DEF_MEMOP(MO_UL), 0x1F, 0x00) | |
2560 | #if defined(TARGET_PPC64) | |
2561 | GEN_LDEPX(ld, DEF_MEMOP(MO_Q), 0x1D, 0x00) | |
2562 | #endif | |
2563 | ||
d9bce9d9 | 2564 | #if defined(TARGET_PPC64) |
d9bce9d9 | 2565 | /* lwaux */ |
0c8aacd4 | 2566 | GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B); |
d9bce9d9 | 2567 | /* lwax */ |
0c8aacd4 | 2568 | GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B); |
d9bce9d9 | 2569 | /* ldux */ |
4f364fe7 | 2570 | GEN_LDUX(ld, ld64_i64, 0x15, 0x01, PPC_64B); |
d9bce9d9 | 2571 | /* ldx */ |
4f364fe7 | 2572 | GEN_LDX(ld, ld64_i64, 0x15, 0x00, PPC_64B); |
99e300ef | 2573 | |
b7815375 | 2574 | /* CI load/store variants */ |
4f364fe7 | 2575 | GEN_LDX_HVRM(ldcix, ld64_i64, 0x15, 0x1b, PPC_CILDST) |
b7815375 BH |
2576 | GEN_LDX_HVRM(lwzcix, ld32u, 0x15, 0x15, PPC_CILDST) |
2577 | GEN_LDX_HVRM(lhzcix, ld16u, 0x15, 0x19, PPC_CILDST) | |
2578 | GEN_LDX_HVRM(lbzcix, ld8u, 0x15, 0x1a, PPC_CILDST) | |
2579 | ||
99e300ef | 2580 | static void gen_ld(DisasContext *ctx) |
d9bce9d9 | 2581 | { |
b61f2753 | 2582 | TCGv EA; |
d9bce9d9 JM |
2583 | if (Rc(ctx->opcode)) { |
2584 | if (unlikely(rA(ctx->opcode) == 0 || | |
2585 | rA(ctx->opcode) == rD(ctx->opcode))) { | |
e06fcd75 | 2586 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
d9bce9d9 JM |
2587 | return; |
2588 | } | |
2589 | } | |
76db3ba4 | 2590 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 2591 | EA = tcg_temp_new(); |
76db3ba4 | 2592 | gen_addr_imm_index(ctx, EA, 0x03); |
d9bce9d9 JM |
2593 | if (ctx->opcode & 0x02) { |
2594 | /* lwa (lwau is undefined) */ | |
76db3ba4 | 2595 | gen_qemu_ld32s(ctx, cpu_gpr[rD(ctx->opcode)], EA); |
d9bce9d9 JM |
2596 | } else { |
2597 | /* ld - ldu */ | |
4f364fe7 | 2598 | gen_qemu_ld64_i64(ctx, cpu_gpr[rD(ctx->opcode)], EA); |
d9bce9d9 | 2599 | } |
d9bce9d9 | 2600 | if (Rc(ctx->opcode)) |
b61f2753 AJ |
2601 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); |
2602 | tcg_temp_free(EA); | |
d9bce9d9 | 2603 | } |
99e300ef | 2604 | |
54623277 | 2605 | /* lq */ |
99e300ef | 2606 | static void gen_lq(DisasContext *ctx) |
be147d08 | 2607 | { |
be147d08 | 2608 | int ra, rd; |
94bf2658 | 2609 | TCGv EA, hi, lo; |
be147d08 | 2610 | |
e0498daa TM |
2611 | /* lq is a legal user mode instruction starting in ISA 2.07 */ |
2612 | bool legal_in_user_mode = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0; | |
2613 | bool le_is_supported = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0; | |
2614 | ||
c47493f2 | 2615 | if (!legal_in_user_mode && ctx->pr) { |
9b2fadda | 2616 | gen_priv_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
2617 | return; |
2618 | } | |
e0498daa TM |
2619 | |
2620 | if (!le_is_supported && ctx->le_mode) { | |
65f2475f | 2621 | gen_align_no_le(ctx); |
e0498daa TM |
2622 | return; |
2623 | } | |
be147d08 JM |
2624 | ra = rA(ctx->opcode); |
2625 | rd = rD(ctx->opcode); | |
2626 | if (unlikely((rd & 1) || rd == ra)) { | |
e06fcd75 | 2627 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
be147d08 JM |
2628 | return; |
2629 | } | |
e0498daa | 2630 | |
76db3ba4 | 2631 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 2632 | EA = tcg_temp_new(); |
76db3ba4 | 2633 | gen_addr_imm_index(ctx, EA, 0x0F); |
e0498daa | 2634 | |
94bf2658 RH |
2635 | /* Note that the low part is always in RD+1, even in LE mode. */ |
2636 | lo = cpu_gpr[rd + 1]; | |
2637 | hi = cpu_gpr[rd]; | |
2638 | ||
2639 | if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { | |
f34ec0f6 RH |
2640 | if (HAVE_ATOMIC128) { |
2641 | TCGv_i32 oi = tcg_temp_new_i32(); | |
2642 | if (ctx->le_mode) { | |
2643 | tcg_gen_movi_i32(oi, make_memop_idx(MO_LEQ, ctx->mem_idx)); | |
2644 | gen_helper_lq_le_parallel(lo, cpu_env, EA, oi); | |
2645 | } else { | |
2646 | tcg_gen_movi_i32(oi, make_memop_idx(MO_BEQ, ctx->mem_idx)); | |
2647 | gen_helper_lq_be_parallel(lo, cpu_env, EA, oi); | |
2648 | } | |
2649 | tcg_temp_free_i32(oi); | |
2650 | tcg_gen_ld_i64(hi, cpu_env, offsetof(CPUPPCState, retxh)); | |
94bf2658 | 2651 | } else { |
f34ec0f6 RH |
2652 | /* Restart with exclusive lock. */ |
2653 | gen_helper_exit_atomic(cpu_env); | |
2654 | ctx->base.is_jmp = DISAS_NORETURN; | |
94bf2658 | 2655 | } |
94bf2658 RH |
2656 | } else if (ctx->le_mode) { |
2657 | tcg_gen_qemu_ld_i64(lo, EA, ctx->mem_idx, MO_LEQ); | |
e0498daa | 2658 | gen_addr_add(ctx, EA, EA, 8); |
94bf2658 | 2659 | tcg_gen_qemu_ld_i64(hi, EA, ctx->mem_idx, MO_LEQ); |
e0498daa | 2660 | } else { |
94bf2658 | 2661 | tcg_gen_qemu_ld_i64(hi, EA, ctx->mem_idx, MO_BEQ); |
e0498daa | 2662 | gen_addr_add(ctx, EA, EA, 8); |
94bf2658 | 2663 | tcg_gen_qemu_ld_i64(lo, EA, ctx->mem_idx, MO_BEQ); |
e0498daa | 2664 | } |
b61f2753 | 2665 | tcg_temp_free(EA); |
be147d08 | 2666 | } |
d9bce9d9 | 2667 | #endif |
79aceca5 FB |
2668 | |
2669 | /*** Integer store ***/ | |
0c8aacd4 | 2670 | #define GEN_ST(name, stop, opc, type) \ |
99e300ef | 2671 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 2672 | { \ |
76db3ba4 AJ |
2673 | TCGv EA; \ |
2674 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2675 | EA = tcg_temp_new(); \ | |
2676 | gen_addr_imm_index(ctx, EA, 0); \ | |
2677 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 | 2678 | tcg_temp_free(EA); \ |
79aceca5 FB |
2679 | } |
2680 | ||
0c8aacd4 | 2681 | #define GEN_STU(name, stop, opc, type) \ |
99e300ef | 2682 | static void glue(gen_, stop##u)(DisasContext *ctx) \ |
79aceca5 | 2683 | { \ |
b61f2753 | 2684 | TCGv EA; \ |
76a66253 | 2685 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 2686 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2687 | return; \ |
9a64fbe4 | 2688 | } \ |
76db3ba4 | 2689 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2690 | EA = tcg_temp_new(); \ |
9d53c753 | 2691 | if (type == PPC_64B) \ |
76db3ba4 | 2692 | gen_addr_imm_index(ctx, EA, 0x03); \ |
9d53c753 | 2693 | else \ |
76db3ba4 AJ |
2694 | gen_addr_imm_index(ctx, EA, 0); \ |
2695 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2696 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2697 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2698 | } |
2699 | ||
0c8aacd4 | 2700 | #define GEN_STUX(name, stop, opc2, opc3, type) \ |
99e300ef | 2701 | static void glue(gen_, name##ux)(DisasContext *ctx) \ |
79aceca5 | 2702 | { \ |
b61f2753 | 2703 | TCGv EA; \ |
76a66253 | 2704 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 2705 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2706 | return; \ |
9a64fbe4 | 2707 | } \ |
76db3ba4 | 2708 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2709 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
2710 | gen_addr_reg_index(ctx, EA); \ |
2711 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2712 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2713 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2714 | } |
2715 | ||
b7815375 | 2716 | #define GEN_STX_E(name, stop, opc2, opc3, type, type2, chk) \ |
cd6e9320 | 2717 | static void glue(gen_, name##x)(DisasContext *ctx) \ |
79aceca5 | 2718 | { \ |
76db3ba4 | 2719 | TCGv EA; \ |
b7815375 | 2720 | chk; \ |
76db3ba4 AJ |
2721 | gen_set_access_type(ctx, ACCESS_INT); \ |
2722 | EA = tcg_temp_new(); \ | |
2723 | gen_addr_reg_index(ctx, EA); \ | |
2724 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 | 2725 | tcg_temp_free(EA); \ |
79aceca5 | 2726 | } |
cd6e9320 | 2727 | #define GEN_STX(name, stop, opc2, opc3, type) \ |
b7815375 BH |
2728 | GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE, CHK_NONE) |
2729 | ||
2730 | #define GEN_STX_HVRM(name, stop, opc2, opc3, type) \ | |
2731 | GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE, CHK_HVRM) | |
79aceca5 | 2732 | |
0c8aacd4 AJ |
2733 | #define GEN_STS(name, stop, op, type) \ |
2734 | GEN_ST(name, stop, op | 0x20, type); \ | |
2735 | GEN_STU(name, stop, op | 0x21, type); \ | |
2736 | GEN_STUX(name, stop, 0x17, op | 0x01, type); \ | |
2737 | GEN_STX(name, stop, 0x17, op | 0x00, type) | |
79aceca5 FB |
2738 | |
2739 | /* stb stbu stbux stbx */ | |
0c8aacd4 | 2740 | GEN_STS(stb, st8, 0x06, PPC_INTEGER); |
79aceca5 | 2741 | /* sth sthu sthux sthx */ |
0c8aacd4 | 2742 | GEN_STS(sth, st16, 0x0C, PPC_INTEGER); |
79aceca5 | 2743 | /* stw stwu stwux stwx */ |
0c8aacd4 | 2744 | GEN_STS(stw, st32, 0x04, PPC_INTEGER); |
50728199 RK |
2745 | |
2746 | #define GEN_STEPX(name, stop, opc2, opc3) \ | |
2747 | static void glue(gen_, name##epx)(DisasContext *ctx) \ | |
2748 | { \ | |
2749 | TCGv EA; \ | |
2750 | CHK_SV; \ | |
2751 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2752 | EA = tcg_temp_new(); \ | |
2753 | gen_addr_reg_index(ctx, EA); \ | |
2754 | tcg_gen_qemu_st_tl( \ | |
2755 | cpu_gpr[rD(ctx->opcode)], EA, PPC_TLB_EPID_STORE, stop); \ | |
2756 | tcg_temp_free(EA); \ | |
2757 | } | |
2758 | ||
2759 | GEN_STEPX(stb, DEF_MEMOP(MO_UB), 0x1F, 0x06) | |
2760 | GEN_STEPX(sth, DEF_MEMOP(MO_UW), 0x1F, 0x0C) | |
2761 | GEN_STEPX(stw, DEF_MEMOP(MO_UL), 0x1F, 0x04) | |
2762 | #if defined(TARGET_PPC64) | |
2763 | GEN_STEPX(std, DEF_MEMOP(MO_Q), 0x1d, 0x04) | |
2764 | #endif | |
2765 | ||
d9bce9d9 | 2766 | #if defined(TARGET_PPC64) |
2468f23d ND |
2767 | GEN_STUX(std, st64_i64, 0x15, 0x05, PPC_64B); |
2768 | GEN_STX(std, st64_i64, 0x15, 0x04, PPC_64B); | |
2769 | GEN_STX_HVRM(stdcix, st64_i64, 0x15, 0x1f, PPC_CILDST) | |
b7815375 BH |
2770 | GEN_STX_HVRM(stwcix, st32, 0x15, 0x1c, PPC_CILDST) |
2771 | GEN_STX_HVRM(sthcix, st16, 0x15, 0x1d, PPC_CILDST) | |
2772 | GEN_STX_HVRM(stbcix, st8, 0x15, 0x1e, PPC_CILDST) | |
99e300ef BS |
2773 | |
2774 | static void gen_std(DisasContext *ctx) | |
d9bce9d9 | 2775 | { |
be147d08 | 2776 | int rs; |
b61f2753 | 2777 | TCGv EA; |
be147d08 JM |
2778 | |
2779 | rs = rS(ctx->opcode); | |
84cab1e2 | 2780 | if ((ctx->opcode & 0x3) == 0x2) { /* stq */ |
84cab1e2 TM |
2781 | bool legal_in_user_mode = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0; |
2782 | bool le_is_supported = (ctx->insns_flags2 & PPC2_LSQ_ISA207) != 0; | |
f89ced5f | 2783 | TCGv hi, lo; |
84cab1e2 | 2784 | |
dfdd3e43 BH |
2785 | if (!(ctx->insns_flags & PPC_64BX)) { |
2786 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); | |
2787 | } | |
2788 | ||
c47493f2 | 2789 | if (!legal_in_user_mode && ctx->pr) { |
9b2fadda | 2790 | gen_priv_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
2791 | return; |
2792 | } | |
84cab1e2 TM |
2793 | |
2794 | if (!le_is_supported && ctx->le_mode) { | |
65f2475f | 2795 | gen_align_no_le(ctx); |
d9bce9d9 JM |
2796 | return; |
2797 | } | |
84cab1e2 TM |
2798 | |
2799 | if (unlikely(rs & 1)) { | |
2800 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); | |
be147d08 JM |
2801 | return; |
2802 | } | |
76db3ba4 | 2803 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 2804 | EA = tcg_temp_new(); |
76db3ba4 | 2805 | gen_addr_imm_index(ctx, EA, 0x03); |
84cab1e2 | 2806 | |
f89ced5f RH |
2807 | /* Note that the low part is always in RS+1, even in LE mode. */ |
2808 | lo = cpu_gpr[rs + 1]; | |
2809 | hi = cpu_gpr[rs]; | |
2810 | ||
2811 | if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { | |
f34ec0f6 RH |
2812 | if (HAVE_ATOMIC128) { |
2813 | TCGv_i32 oi = tcg_temp_new_i32(); | |
2814 | if (ctx->le_mode) { | |
2815 | tcg_gen_movi_i32(oi, make_memop_idx(MO_LEQ, ctx->mem_idx)); | |
2816 | gen_helper_stq_le_parallel(cpu_env, EA, lo, hi, oi); | |
2817 | } else { | |
2818 | tcg_gen_movi_i32(oi, make_memop_idx(MO_BEQ, ctx->mem_idx)); | |
2819 | gen_helper_stq_be_parallel(cpu_env, EA, lo, hi, oi); | |
2820 | } | |
2821 | tcg_temp_free_i32(oi); | |
f89ced5f | 2822 | } else { |
f34ec0f6 RH |
2823 | /* Restart with exclusive lock. */ |
2824 | gen_helper_exit_atomic(cpu_env); | |
2825 | ctx->base.is_jmp = DISAS_NORETURN; | |
f89ced5f | 2826 | } |
f89ced5f RH |
2827 | } else if (ctx->le_mode) { |
2828 | tcg_gen_qemu_st_i64(lo, EA, ctx->mem_idx, MO_LEQ); | |
84cab1e2 | 2829 | gen_addr_add(ctx, EA, EA, 8); |
f89ced5f | 2830 | tcg_gen_qemu_st_i64(hi, EA, ctx->mem_idx, MO_LEQ); |
84cab1e2 | 2831 | } else { |
f89ced5f | 2832 | tcg_gen_qemu_st_i64(hi, EA, ctx->mem_idx, MO_BEQ); |
84cab1e2 | 2833 | gen_addr_add(ctx, EA, EA, 8); |
f89ced5f | 2834 | tcg_gen_qemu_st_i64(lo, EA, ctx->mem_idx, MO_BEQ); |
84cab1e2 | 2835 | } |
b61f2753 | 2836 | tcg_temp_free(EA); |
be147d08 | 2837 | } else { |
f89ced5f | 2838 | /* std / stdu */ |
be147d08 JM |
2839 | if (Rc(ctx->opcode)) { |
2840 | if (unlikely(rA(ctx->opcode) == 0)) { | |
e06fcd75 | 2841 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
be147d08 JM |
2842 | return; |
2843 | } | |
2844 | } | |
76db3ba4 | 2845 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 2846 | EA = tcg_temp_new(); |
76db3ba4 | 2847 | gen_addr_imm_index(ctx, EA, 0x03); |
2468f23d | 2848 | gen_qemu_st64_i64(ctx, cpu_gpr[rs], EA); |
be147d08 | 2849 | if (Rc(ctx->opcode)) |
b61f2753 AJ |
2850 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); |
2851 | tcg_temp_free(EA); | |
d9bce9d9 | 2852 | } |
d9bce9d9 JM |
2853 | } |
2854 | #endif | |
79aceca5 | 2855 | /*** Integer load and store with byte reverse ***/ |
e22c357b | 2856 | |
79aceca5 | 2857 | /* lhbrx */ |
0c8aacd4 | 2858 | GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER); |
b61f2753 | 2859 | |
79aceca5 | 2860 | /* lwbrx */ |
0c8aacd4 | 2861 | GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER); |
b61f2753 | 2862 | |
cd6e9320 TH |
2863 | #if defined(TARGET_PPC64) |
2864 | /* ldbrx */ | |
ff5f3981 | 2865 | GEN_LDX_E(ldbr, ld64ur_i64, 0x14, 0x10, PPC_NONE, PPC2_DBRX, CHK_NONE); |
804108aa ND |
2866 | /* stdbrx */ |
2867 | GEN_STX_E(stdbr, st64r_i64, 0x14, 0x14, PPC_NONE, PPC2_DBRX, CHK_NONE); | |
cd6e9320 TH |
2868 | #endif /* TARGET_PPC64 */ |
2869 | ||
79aceca5 | 2870 | /* sthbrx */ |
0c8aacd4 | 2871 | GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER); |
79aceca5 | 2872 | /* stwbrx */ |
0c8aacd4 | 2873 | GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER); |
79aceca5 FB |
2874 | |
2875 | /*** Integer load and store multiple ***/ | |
99e300ef | 2876 | |
54623277 | 2877 | /* lmw */ |
99e300ef | 2878 | static void gen_lmw(DisasContext *ctx) |
79aceca5 | 2879 | { |
76db3ba4 AJ |
2880 | TCGv t0; |
2881 | TCGv_i32 t1; | |
5817355e BH |
2882 | |
2883 | if (ctx->le_mode) { | |
2884 | gen_align_no_le(ctx); | |
2885 | return; | |
2886 | } | |
76db3ba4 | 2887 | gen_set_access_type(ctx, ACCESS_INT); |
76db3ba4 AJ |
2888 | t0 = tcg_temp_new(); |
2889 | t1 = tcg_const_i32(rD(ctx->opcode)); | |
2890 | gen_addr_imm_index(ctx, t0, 0); | |
2f5a189c | 2891 | gen_helper_lmw(cpu_env, t0, t1); |
ff4a62cd AJ |
2892 | tcg_temp_free(t0); |
2893 | tcg_temp_free_i32(t1); | |
79aceca5 FB |
2894 | } |
2895 | ||
2896 | /* stmw */ | |
99e300ef | 2897 | static void gen_stmw(DisasContext *ctx) |
79aceca5 | 2898 | { |
76db3ba4 AJ |
2899 | TCGv t0; |
2900 | TCGv_i32 t1; | |
5817355e BH |
2901 | |
2902 | if (ctx->le_mode) { | |
2903 | gen_align_no_le(ctx); | |
2904 | return; | |
2905 | } | |
76db3ba4 | 2906 | gen_set_access_type(ctx, ACCESS_INT); |
76db3ba4 AJ |
2907 | t0 = tcg_temp_new(); |
2908 | t1 = tcg_const_i32(rS(ctx->opcode)); | |
2909 | gen_addr_imm_index(ctx, t0, 0); | |
2f5a189c | 2910 | gen_helper_stmw(cpu_env, t0, t1); |
ff4a62cd AJ |
2911 | tcg_temp_free(t0); |
2912 | tcg_temp_free_i32(t1); | |
79aceca5 FB |
2913 | } |
2914 | ||
2915 | /*** Integer load and store strings ***/ | |
54623277 | 2916 | |
79aceca5 | 2917 | /* lswi */ |
3fc6c082 | 2918 | /* PowerPC32 specification says we must generate an exception if |
9a64fbe4 FB |
2919 | * rA is in the range of registers to be loaded. |
2920 | * In an other hand, IBM says this is valid, but rA won't be loaded. | |
2921 | * For now, I'll follow the spec... | |
2922 | */ | |
99e300ef | 2923 | static void gen_lswi(DisasContext *ctx) |
79aceca5 | 2924 | { |
dfbc799d AJ |
2925 | TCGv t0; |
2926 | TCGv_i32 t1, t2; | |
79aceca5 FB |
2927 | int nb = NB(ctx->opcode); |
2928 | int start = rD(ctx->opcode); | |
9a64fbe4 | 2929 | int ra = rA(ctx->opcode); |
79aceca5 FB |
2930 | int nr; |
2931 | ||
5817355e BH |
2932 | if (ctx->le_mode) { |
2933 | gen_align_no_le(ctx); | |
2934 | return; | |
2935 | } | |
79aceca5 FB |
2936 | if (nb == 0) |
2937 | nb = 32; | |
f0704d78 | 2938 | nr = DIV_ROUND_UP(nb, 4); |
afbee712 | 2939 | if (unlikely(lsw_reg_in_range(start, nr, ra))) { |
e06fcd75 | 2940 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX); |
9fddaa0c | 2941 | return; |
297d8e62 | 2942 | } |
76db3ba4 | 2943 | gen_set_access_type(ctx, ACCESS_INT); |
dfbc799d | 2944 | t0 = tcg_temp_new(); |
76db3ba4 | 2945 | gen_addr_register(ctx, t0); |
dfbc799d AJ |
2946 | t1 = tcg_const_i32(nb); |
2947 | t2 = tcg_const_i32(start); | |
2f5a189c | 2948 | gen_helper_lsw(cpu_env, t0, t1, t2); |
dfbc799d AJ |
2949 | tcg_temp_free(t0); |
2950 | tcg_temp_free_i32(t1); | |
2951 | tcg_temp_free_i32(t2); | |
79aceca5 FB |
2952 | } |
2953 | ||
2954 | /* lswx */ | |
99e300ef | 2955 | static void gen_lswx(DisasContext *ctx) |
79aceca5 | 2956 | { |
76db3ba4 AJ |
2957 | TCGv t0; |
2958 | TCGv_i32 t1, t2, t3; | |
5817355e BH |
2959 | |
2960 | if (ctx->le_mode) { | |
2961 | gen_align_no_le(ctx); | |
2962 | return; | |
2963 | } | |
76db3ba4 | 2964 | gen_set_access_type(ctx, ACCESS_INT); |
76db3ba4 AJ |
2965 | t0 = tcg_temp_new(); |
2966 | gen_addr_reg_index(ctx, t0); | |
2967 | t1 = tcg_const_i32(rD(ctx->opcode)); | |
2968 | t2 = tcg_const_i32(rA(ctx->opcode)); | |
2969 | t3 = tcg_const_i32(rB(ctx->opcode)); | |
2f5a189c | 2970 | gen_helper_lswx(cpu_env, t0, t1, t2, t3); |
dfbc799d AJ |
2971 | tcg_temp_free(t0); |
2972 | tcg_temp_free_i32(t1); | |
2973 | tcg_temp_free_i32(t2); | |
2974 | tcg_temp_free_i32(t3); | |
79aceca5 FB |
2975 | } |
2976 | ||
2977 | /* stswi */ | |
99e300ef | 2978 | static void gen_stswi(DisasContext *ctx) |
79aceca5 | 2979 | { |
76db3ba4 AJ |
2980 | TCGv t0; |
2981 | TCGv_i32 t1, t2; | |
4b3686fa | 2982 | int nb = NB(ctx->opcode); |
5817355e BH |
2983 | |
2984 | if (ctx->le_mode) { | |
2985 | gen_align_no_le(ctx); | |
2986 | return; | |
2987 | } | |
76db3ba4 | 2988 | gen_set_access_type(ctx, ACCESS_INT); |
76db3ba4 AJ |
2989 | t0 = tcg_temp_new(); |
2990 | gen_addr_register(ctx, t0); | |
4b3686fa FB |
2991 | if (nb == 0) |
2992 | nb = 32; | |
dfbc799d | 2993 | t1 = tcg_const_i32(nb); |
76db3ba4 | 2994 | t2 = tcg_const_i32(rS(ctx->opcode)); |
2f5a189c | 2995 | gen_helper_stsw(cpu_env, t0, t1, t2); |
dfbc799d AJ |
2996 | tcg_temp_free(t0); |
2997 | tcg_temp_free_i32(t1); | |
2998 | tcg_temp_free_i32(t2); | |
79aceca5 FB |
2999 | } |
3000 | ||
3001 | /* stswx */ | |
99e300ef | 3002 | static void gen_stswx(DisasContext *ctx) |
79aceca5 | 3003 | { |
76db3ba4 AJ |
3004 | TCGv t0; |
3005 | TCGv_i32 t1, t2; | |
5817355e BH |
3006 | |
3007 | if (ctx->le_mode) { | |
3008 | gen_align_no_le(ctx); | |
3009 | return; | |
3010 | } | |
76db3ba4 | 3011 | gen_set_access_type(ctx, ACCESS_INT); |
76db3ba4 AJ |
3012 | t0 = tcg_temp_new(); |
3013 | gen_addr_reg_index(ctx, t0); | |
3014 | t1 = tcg_temp_new_i32(); | |
dfbc799d AJ |
3015 | tcg_gen_trunc_tl_i32(t1, cpu_xer); |
3016 | tcg_gen_andi_i32(t1, t1, 0x7F); | |
76db3ba4 | 3017 | t2 = tcg_const_i32(rS(ctx->opcode)); |
2f5a189c | 3018 | gen_helper_stsw(cpu_env, t0, t1, t2); |
dfbc799d AJ |
3019 | tcg_temp_free(t0); |
3020 | tcg_temp_free_i32(t1); | |
3021 | tcg_temp_free_i32(t2); | |
79aceca5 FB |
3022 | } |
3023 | ||
3024 | /*** Memory synchronisation ***/ | |
3025 | /* eieio */ | |
99e300ef | 3026 | static void gen_eieio(DisasContext *ctx) |
79aceca5 | 3027 | { |
c8fd8373 CLG |
3028 | TCGBar bar = TCG_MO_LD_ST; |
3029 | ||
3030 | /* | |
3031 | * POWER9 has a eieio instruction variant using bit 6 as a hint to | |
3032 | * tell the CPU it is a store-forwarding barrier. | |
3033 | */ | |
3034 | if (ctx->opcode & 0x2000000) { | |
3035 | /* | |
3036 | * ISA says that "Reserved fields in instructions are ignored | |
3037 | * by the processor". So ignore the bit 6 on non-POWER9 CPU but | |
3038 | * as this is not an instruction software should be using, | |
3039 | * complain to the user. | |
3040 | */ | |
3041 | if (!(ctx->insns_flags2 & PPC2_ISA300)) { | |
3042 | qemu_log_mask(LOG_GUEST_ERROR, "invalid eieio using bit 6 at @" | |
3043 | TARGET_FMT_lx "\n", ctx->base.pc_next - 4); | |
3044 | } else { | |
3045 | bar = TCG_MO_ST_LD; | |
3046 | } | |
3047 | } | |
3048 | ||
3049 | tcg_gen_mb(bar | TCG_BAR_SC); | |
79aceca5 FB |
3050 | } |
3051 | ||
c5a8d8f3 | 3052 | #if !defined(CONFIG_USER_ONLY) |
e3cffe6f | 3053 | static inline void gen_check_tlb_flush(DisasContext *ctx, bool global) |
cd0c6f47 | 3054 | { |
c5a8d8f3 BH |
3055 | TCGv_i32 t; |
3056 | TCGLabel *l; | |
cd0c6f47 | 3057 | |
c5a8d8f3 BH |
3058 | if (!ctx->lazy_tlb_flush) { |
3059 | return; | |
3060 | } | |
3061 | l = gen_new_label(); | |
3062 | t = tcg_temp_new_i32(); | |
cd0c6f47 BH |
3063 | tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, tlb_need_flush)); |
3064 | tcg_gen_brcondi_i32(TCG_COND_EQ, t, 0, l); | |
e3cffe6f ND |
3065 | if (global) { |
3066 | gen_helper_check_tlb_flush_global(cpu_env); | |
3067 | } else { | |
3068 | gen_helper_check_tlb_flush_local(cpu_env); | |
3069 | } | |
cd0c6f47 BH |
3070 | gen_set_label(l); |
3071 | tcg_temp_free_i32(t); | |
3072 | } | |
3073 | #else | |
e3cffe6f | 3074 | static inline void gen_check_tlb_flush(DisasContext *ctx, bool global) { } |
cd0c6f47 BH |
3075 | #endif |
3076 | ||
79aceca5 | 3077 | /* isync */ |
99e300ef | 3078 | static void gen_isync(DisasContext *ctx) |
79aceca5 | 3079 | { |
cd0c6f47 BH |
3080 | /* |
3081 | * We need to check for a pending TLB flush. This can only happen in | |
3082 | * kernel mode however so check MSR_PR | |
3083 | */ | |
3084 | if (!ctx->pr) { | |
e3cffe6f | 3085 | gen_check_tlb_flush(ctx, false); |
cd0c6f47 | 3086 | } |
4771df23 | 3087 | tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC); |
e06fcd75 | 3088 | gen_stop_exception(ctx); |
79aceca5 FB |
3089 | } |
3090 | ||
48793c95 ND |
3091 | #define MEMOP_GET_SIZE(x) (1 << ((x) & MO_SIZE)) |
3092 | ||
2a4e6c1b RH |
3093 | static void gen_load_locked(DisasContext *ctx, TCGMemOp memop) |
3094 | { | |
3095 | TCGv gpr = cpu_gpr[rD(ctx->opcode)]; | |
3096 | TCGv t0 = tcg_temp_new(); | |
3097 | ||
3098 | gen_set_access_type(ctx, ACCESS_RES); | |
3099 | gen_addr_reg_index(ctx, t0); | |
3100 | tcg_gen_qemu_ld_tl(gpr, t0, ctx->mem_idx, memop | MO_ALIGN); | |
3101 | tcg_gen_mov_tl(cpu_reserve, t0); | |
3102 | tcg_gen_mov_tl(cpu_reserve_val, gpr); | |
3103 | tcg_gen_mb(TCG_MO_ALL | TCG_BAR_LDAQ); | |
3104 | tcg_temp_free(t0); | |
3105 | } | |
3106 | ||
3107 | #define LARX(name, memop) \ | |
3108 | static void gen_##name(DisasContext *ctx) \ | |
3109 | { \ | |
3110 | gen_load_locked(ctx, memop); \ | |
79aceca5 FB |
3111 | } |
3112 | ||
5c77a786 | 3113 | /* lwarx */ |
48793c95 ND |
3114 | LARX(lbarx, DEF_MEMOP(MO_UB)) |
3115 | LARX(lharx, DEF_MEMOP(MO_UW)) | |
3116 | LARX(lwarx, DEF_MEMOP(MO_UL)) | |
5c77a786 | 3117 | |
20923c1d RH |
3118 | static void gen_fetch_inc_conditional(DisasContext *ctx, TCGMemOp memop, |
3119 | TCGv EA, TCGCond cond, int addend) | |
3120 | { | |
3121 | TCGv t = tcg_temp_new(); | |
3122 | TCGv t2 = tcg_temp_new(); | |
3123 | TCGv u = tcg_temp_new(); | |
3124 | ||
3125 | tcg_gen_qemu_ld_tl(t, EA, ctx->mem_idx, memop); | |
3126 | tcg_gen_addi_tl(t2, EA, MEMOP_GET_SIZE(memop)); | |
3127 | tcg_gen_qemu_ld_tl(t2, t2, ctx->mem_idx, memop); | |
3128 | tcg_gen_addi_tl(u, t, addend); | |
3129 | ||
3130 | /* E.g. for fetch and increment bounded... */ | |
3131 | /* mem(EA,s) = (t != t2 ? u = t + 1 : t) */ | |
3132 | tcg_gen_movcond_tl(cond, u, t, t2, u, t); | |
3133 | tcg_gen_qemu_st_tl(u, EA, ctx->mem_idx, memop); | |
3134 | ||
3135 | /* RT = (t != t2 ? t : u = 1<<(s*8-1)) */ | |
3136 | tcg_gen_movi_tl(u, 1 << (MEMOP_GET_SIZE(memop) * 8 - 1)); | |
3137 | tcg_gen_movcond_tl(cond, cpu_gpr[rD(ctx->opcode)], t, t2, t, u); | |
3138 | ||
3139 | tcg_temp_free(t); | |
3140 | tcg_temp_free(t2); | |
3141 | tcg_temp_free(u); | |
3142 | } | |
3143 | ||
20ba8504 RH |
3144 | static void gen_ld_atomic(DisasContext *ctx, TCGMemOp memop) |
3145 | { | |
3146 | uint32_t gpr_FC = FC(ctx->opcode); | |
3147 | TCGv EA = tcg_temp_new(); | |
20923c1d RH |
3148 | int rt = rD(ctx->opcode); |
3149 | bool need_serial; | |
20ba8504 RH |
3150 | TCGv src, dst; |
3151 | ||
3152 | gen_addr_register(ctx, EA); | |
20923c1d RH |
3153 | dst = cpu_gpr[rt]; |
3154 | src = cpu_gpr[(rt + 1) & 31]; | |
20ba8504 | 3155 | |
20923c1d | 3156 | need_serial = false; |
20ba8504 RH |
3157 | memop |= MO_ALIGN; |
3158 | switch (gpr_FC) { | |
3159 | case 0: /* Fetch and add */ | |
3160 | tcg_gen_atomic_fetch_add_tl(dst, EA, src, ctx->mem_idx, memop); | |
3161 | break; | |
3162 | case 1: /* Fetch and xor */ | |
3163 | tcg_gen_atomic_fetch_xor_tl(dst, EA, src, ctx->mem_idx, memop); | |
3164 | break; | |
3165 | case 2: /* Fetch and or */ | |
3166 | tcg_gen_atomic_fetch_or_tl(dst, EA, src, ctx->mem_idx, memop); | |
3167 | break; | |
3168 | case 3: /* Fetch and 'and' */ | |
3169 | tcg_gen_atomic_fetch_and_tl(dst, EA, src, ctx->mem_idx, memop); | |
3170 | break; | |
20ba8504 | 3171 | case 4: /* Fetch and max unsigned */ |
b8ce0f86 RH |
3172 | tcg_gen_atomic_fetch_umax_tl(dst, EA, src, ctx->mem_idx, memop); |
3173 | break; | |
20ba8504 | 3174 | case 5: /* Fetch and max signed */ |
b8ce0f86 RH |
3175 | tcg_gen_atomic_fetch_smax_tl(dst, EA, src, ctx->mem_idx, memop); |
3176 | break; | |
20ba8504 | 3177 | case 6: /* Fetch and min unsigned */ |
b8ce0f86 RH |
3178 | tcg_gen_atomic_fetch_umin_tl(dst, EA, src, ctx->mem_idx, memop); |
3179 | break; | |
20ba8504 | 3180 | case 7: /* Fetch and min signed */ |
b8ce0f86 RH |
3181 | tcg_gen_atomic_fetch_smin_tl(dst, EA, src, ctx->mem_idx, memop); |
3182 | break; | |
3183 | case 8: /* Swap */ | |
3184 | tcg_gen_atomic_xchg_tl(dst, EA, src, ctx->mem_idx, memop); | |
3185 | break; | |
20923c1d RH |
3186 | |
3187 | case 16: /* Compare and swap not equal */ | |
3188 | if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { | |
3189 | need_serial = true; | |
3190 | } else { | |
3191 | TCGv t0 = tcg_temp_new(); | |
3192 | TCGv t1 = tcg_temp_new(); | |
3193 | ||
3194 | tcg_gen_qemu_ld_tl(t0, EA, ctx->mem_idx, memop); | |
3195 | if ((memop & MO_SIZE) == MO_64 || TARGET_LONG_BITS == 32) { | |
3196 | tcg_gen_mov_tl(t1, src); | |
3197 | } else { | |
3198 | tcg_gen_ext32u_tl(t1, src); | |
3199 | } | |
3200 | tcg_gen_movcond_tl(TCG_COND_NE, t1, t0, t1, | |
3201 | cpu_gpr[(rt + 2) & 31], t0); | |
3202 | tcg_gen_qemu_st_tl(t1, EA, ctx->mem_idx, memop); | |
3203 | tcg_gen_mov_tl(dst, t0); | |
3204 | ||
3205 | tcg_temp_free(t0); | |
3206 | tcg_temp_free(t1); | |
3207 | } | |
3208 | break; | |
3209 | ||
20ba8504 | 3210 | case 24: /* Fetch and increment bounded */ |
20923c1d RH |
3211 | if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { |
3212 | need_serial = true; | |
3213 | } else { | |
3214 | gen_fetch_inc_conditional(ctx, memop, EA, TCG_COND_NE, 1); | |
3215 | } | |
3216 | break; | |
20ba8504 | 3217 | case 25: /* Fetch and increment equal */ |
20923c1d RH |
3218 | if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { |
3219 | need_serial = true; | |
3220 | } else { | |
3221 | gen_fetch_inc_conditional(ctx, memop, EA, TCG_COND_EQ, 1); | |
3222 | } | |
3223 | break; | |
20ba8504 | 3224 | case 28: /* Fetch and decrement bounded */ |
20923c1d RH |
3225 | if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { |
3226 | need_serial = true; | |
3227 | } else { | |
3228 | gen_fetch_inc_conditional(ctx, memop, EA, TCG_COND_NE, -1); | |
3229 | } | |
20ba8504 | 3230 | break; |
20923c1d | 3231 | |
20ba8504 RH |
3232 | default: |
3233 | /* invoke data storage error handler */ | |
3234 | gen_exception_err(ctx, POWERPC_EXCP_DSI, POWERPC_EXCP_INVAL); | |
3235 | } | |
3236 | tcg_temp_free(EA); | |
20923c1d RH |
3237 | |
3238 | if (need_serial) { | |
3239 | /* Restart with exclusive lock. */ | |
3240 | gen_helper_exit_atomic(cpu_env); | |
3241 | ctx->base.is_jmp = DISAS_NORETURN; | |
3242 | } | |
20ba8504 RH |
3243 | } |
3244 | ||
3245 | static void gen_lwat(DisasContext *ctx) | |
3246 | { | |
3247 | gen_ld_atomic(ctx, DEF_MEMOP(MO_UL)); | |
3248 | } | |
3249 | ||
3250 | #ifdef TARGET_PPC64 | |
3251 | static void gen_ldat(DisasContext *ctx) | |
3252 | { | |
3253 | gen_ld_atomic(ctx, DEF_MEMOP(MO_Q)); | |
3254 | } | |
a68a6146 B |
3255 | #endif |
3256 | ||
9deb041c RH |
3257 | static void gen_st_atomic(DisasContext *ctx, TCGMemOp memop) |
3258 | { | |
3259 | uint32_t gpr_FC = FC(ctx->opcode); | |
3260 | TCGv EA = tcg_temp_new(); | |
3261 | TCGv src, discard; | |
3262 | ||
3263 | gen_addr_register(ctx, EA); | |
3264 | src = cpu_gpr[rD(ctx->opcode)]; | |
3265 | discard = tcg_temp_new(); | |
3266 | ||
3267 | memop |= MO_ALIGN; | |
3268 | switch (gpr_FC) { | |
3269 | case 0: /* add and Store */ | |
3270 | tcg_gen_atomic_add_fetch_tl(discard, EA, src, ctx->mem_idx, memop); | |
3271 | break; | |
3272 | case 1: /* xor and Store */ | |
3273 | tcg_gen_atomic_xor_fetch_tl(discard, EA, src, ctx->mem_idx, memop); | |
3274 | break; | |
3275 | case 2: /* Or and Store */ | |
3276 | tcg_gen_atomic_or_fetch_tl(discard, EA, src, ctx->mem_idx, memop); | |
3277 | break; | |
3278 | case 3: /* 'and' and Store */ | |
3279 | tcg_gen_atomic_and_fetch_tl(discard, EA, src, ctx->mem_idx, memop); | |
3280 | break; | |
3281 | case 4: /* Store max unsigned */ | |
b8ce0f86 RH |
3282 | tcg_gen_atomic_umax_fetch_tl(discard, EA, src, ctx->mem_idx, memop); |
3283 | break; | |
9deb041c | 3284 | case 5: /* Store max signed */ |
b8ce0f86 RH |
3285 | tcg_gen_atomic_smax_fetch_tl(discard, EA, src, ctx->mem_idx, memop); |
3286 | break; | |
9deb041c | 3287 | case 6: /* Store min unsigned */ |
b8ce0f86 RH |
3288 | tcg_gen_atomic_umin_fetch_tl(discard, EA, src, ctx->mem_idx, memop); |
3289 | break; | |
9deb041c | 3290 | case 7: /* Store min signed */ |
b8ce0f86 RH |
3291 | tcg_gen_atomic_smin_fetch_tl(discard, EA, src, ctx->mem_idx, memop); |
3292 | break; | |
9deb041c | 3293 | case 24: /* Store twin */ |
7fbc2b20 RH |
3294 | if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { |
3295 | /* Restart with exclusive lock. */ | |
3296 | gen_helper_exit_atomic(cpu_env); | |
3297 | ctx->base.is_jmp = DISAS_NORETURN; | |
3298 | } else { | |
3299 | TCGv t = tcg_temp_new(); | |
3300 | TCGv t2 = tcg_temp_new(); | |
3301 | TCGv s = tcg_temp_new(); | |
3302 | TCGv s2 = tcg_temp_new(); | |
3303 | TCGv ea_plus_s = tcg_temp_new(); | |
3304 | ||
3305 | tcg_gen_qemu_ld_tl(t, EA, ctx->mem_idx, memop); | |
3306 | tcg_gen_addi_tl(ea_plus_s, EA, MEMOP_GET_SIZE(memop)); | |
3307 | tcg_gen_qemu_ld_tl(t2, ea_plus_s, ctx->mem_idx, memop); | |
3308 | tcg_gen_movcond_tl(TCG_COND_EQ, s, t, t2, src, t); | |
3309 | tcg_gen_movcond_tl(TCG_COND_EQ, s2, t, t2, src, t2); | |
3310 | tcg_gen_qemu_st_tl(s, EA, ctx->mem_idx, memop); | |
3311 | tcg_gen_qemu_st_tl(s2, ea_plus_s, ctx->mem_idx, memop); | |
3312 | ||
3313 | tcg_temp_free(ea_plus_s); | |
3314 | tcg_temp_free(s2); | |
3315 | tcg_temp_free(s); | |
3316 | tcg_temp_free(t2); | |
3317 | tcg_temp_free(t); | |
3318 | } | |
9deb041c RH |
3319 | break; |
3320 | default: | |
3321 | /* invoke data storage error handler */ | |
3322 | gen_exception_err(ctx, POWERPC_EXCP_DSI, POWERPC_EXCP_INVAL); | |
3323 | } | |
3324 | tcg_temp_free(discard); | |
3325 | tcg_temp_free(EA); | |
3326 | } | |
3327 | ||
3328 | static void gen_stwat(DisasContext *ctx) | |
3329 | { | |
3330 | gen_st_atomic(ctx, DEF_MEMOP(MO_UL)); | |
3331 | } | |
3332 | ||
3333 | #ifdef TARGET_PPC64 | |
3334 | static void gen_stdat(DisasContext *ctx) | |
3335 | { | |
3336 | gen_st_atomic(ctx, DEF_MEMOP(MO_Q)); | |
3337 | } | |
a3401188 B |
3338 | #endif |
3339 | ||
d8b86898 | 3340 | static void gen_conditional_store(DisasContext *ctx, TCGMemOp memop) |
587c51f7 | 3341 | { |
253ce7b2 ND |
3342 | TCGLabel *l1 = gen_new_label(); |
3343 | TCGLabel *l2 = gen_new_label(); | |
d8b86898 RH |
3344 | TCGv t0 = tcg_temp_new(); |
3345 | int reg = rS(ctx->opcode); | |
4425265b | 3346 | |
d8b86898 RH |
3347 | gen_set_access_type(ctx, ACCESS_RES); |
3348 | gen_addr_reg_index(ctx, t0); | |
3349 | tcg_gen_brcond_tl(TCG_COND_NE, t0, cpu_reserve, l1); | |
3350 | tcg_temp_free(t0); | |
253ce7b2 ND |
3351 | |
3352 | t0 = tcg_temp_new(); | |
3353 | tcg_gen_atomic_cmpxchg_tl(t0, cpu_reserve, cpu_reserve_val, | |
3354 | cpu_gpr[reg], ctx->mem_idx, | |
3355 | DEF_MEMOP(memop) | MO_ALIGN); | |
3356 | tcg_gen_setcond_tl(TCG_COND_EQ, t0, t0, cpu_reserve_val); | |
3357 | tcg_gen_shli_tl(t0, t0, CRF_EQ_BIT); | |
3358 | tcg_gen_or_tl(t0, t0, cpu_so); | |
3359 | tcg_gen_trunc_tl_i32(cpu_crf[0], t0); | |
3360 | tcg_temp_free(t0); | |
3361 | tcg_gen_br(l2); | |
3362 | ||
587c51f7 | 3363 | gen_set_label(l1); |
4771df23 ND |
3364 | |
3365 | /* Address mismatch implies failure. But we still need to provide the | |
3366 | memory barrier semantics of the instruction. */ | |
3367 | tcg_gen_mb(TCG_MO_ALL | TCG_BAR_STRL); | |
253ce7b2 ND |
3368 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so); |
3369 | ||
3370 | gen_set_label(l2); | |
587c51f7 TM |
3371 | tcg_gen_movi_tl(cpu_reserve, -1); |
3372 | } | |
587c51f7 | 3373 | |
d8b86898 RH |
3374 | #define STCX(name, memop) \ |
3375 | static void gen_##name(DisasContext *ctx) \ | |
3376 | { \ | |
3377 | gen_conditional_store(ctx, memop); \ | |
2391b357 ND |
3378 | } |
3379 | ||
3380 | STCX(stbcx_, DEF_MEMOP(MO_UB)) | |
3381 | STCX(sthcx_, DEF_MEMOP(MO_UW)) | |
3382 | STCX(stwcx_, DEF_MEMOP(MO_UL)) | |
587c51f7 | 3383 | |
426613db | 3384 | #if defined(TARGET_PPC64) |
426613db | 3385 | /* ldarx */ |
48793c95 | 3386 | LARX(ldarx, DEF_MEMOP(MO_Q)) |
2391b357 ND |
3387 | /* stdcx. */ |
3388 | STCX(stdcx_, DEF_MEMOP(MO_Q)) | |
426613db | 3389 | |
9c294d5a TM |
3390 | /* lqarx */ |
3391 | static void gen_lqarx(DisasContext *ctx) | |
3392 | { | |
9c294d5a | 3393 | int rd = rD(ctx->opcode); |
94bf2658 | 3394 | TCGv EA, hi, lo; |
9c294d5a TM |
3395 | |
3396 | if (unlikely((rd & 1) || (rd == rA(ctx->opcode)) || | |
3397 | (rd == rB(ctx->opcode)))) { | |
3398 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); | |
3399 | return; | |
3400 | } | |
3401 | ||
3402 | gen_set_access_type(ctx, ACCESS_RES); | |
94bf2658 | 3403 | EA = tcg_temp_new(); |
9c294d5a | 3404 | gen_addr_reg_index(ctx, EA); |
94bf2658 RH |
3405 | |
3406 | /* Note that the low part is always in RD+1, even in LE mode. */ | |
3407 | lo = cpu_gpr[rd + 1]; | |
3408 | hi = cpu_gpr[rd]; | |
3409 | ||
3410 | if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { | |
f34ec0f6 RH |
3411 | if (HAVE_ATOMIC128) { |
3412 | TCGv_i32 oi = tcg_temp_new_i32(); | |
3413 | if (ctx->le_mode) { | |
3414 | tcg_gen_movi_i32(oi, make_memop_idx(MO_LEQ | MO_ALIGN_16, | |
3415 | ctx->mem_idx)); | |
3416 | gen_helper_lq_le_parallel(lo, cpu_env, EA, oi); | |
3417 | } else { | |
3418 | tcg_gen_movi_i32(oi, make_memop_idx(MO_BEQ | MO_ALIGN_16, | |
3419 | ctx->mem_idx)); | |
3420 | gen_helper_lq_be_parallel(lo, cpu_env, EA, oi); | |
3421 | } | |
3422 | tcg_temp_free_i32(oi); | |
3423 | tcg_gen_ld_i64(hi, cpu_env, offsetof(CPUPPCState, retxh)); | |
94bf2658 | 3424 | } else { |
f34ec0f6 RH |
3425 | /* Restart with exclusive lock. */ |
3426 | gen_helper_exit_atomic(cpu_env); | |
3427 | ctx->base.is_jmp = DISAS_NORETURN; | |
3428 | tcg_temp_free(EA); | |
3429 | return; | |
94bf2658 | 3430 | } |
94bf2658 RH |
3431 | } else if (ctx->le_mode) { |
3432 | tcg_gen_qemu_ld_i64(lo, EA, ctx->mem_idx, MO_LEQ | MO_ALIGN_16); | |
3433 | tcg_gen_mov_tl(cpu_reserve, EA); | |
3434 | gen_addr_add(ctx, EA, EA, 8); | |
3435 | tcg_gen_qemu_ld_i64(hi, EA, ctx->mem_idx, MO_LEQ); | |
9c294d5a | 3436 | } else { |
94bf2658 RH |
3437 | tcg_gen_qemu_ld_i64(hi, EA, ctx->mem_idx, MO_BEQ | MO_ALIGN_16); |
3438 | tcg_gen_mov_tl(cpu_reserve, EA); | |
3439 | gen_addr_add(ctx, EA, EA, 8); | |
3440 | tcg_gen_qemu_ld_i64(lo, EA, ctx->mem_idx, MO_BEQ); | |
9c294d5a | 3441 | } |
9c294d5a | 3442 | tcg_temp_free(EA); |
94bf2658 RH |
3443 | |
3444 | tcg_gen_st_tl(hi, cpu_env, offsetof(CPUPPCState, reserve_val)); | |
3445 | tcg_gen_st_tl(lo, cpu_env, offsetof(CPUPPCState, reserve_val2)); | |
9c294d5a TM |
3446 | } |
3447 | ||
aa2008af ND |
3448 | /* stqcx. */ |
3449 | static void gen_stqcx_(DisasContext *ctx) | |
3450 | { | |
4a9b3c5d RH |
3451 | int rs = rS(ctx->opcode); |
3452 | TCGv EA, hi, lo; | |
aa2008af | 3453 | |
4a9b3c5d | 3454 | if (unlikely(rs & 1)) { |
aa2008af ND |
3455 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
3456 | return; | |
3457 | } | |
4a9b3c5d | 3458 | |
aa2008af | 3459 | gen_set_access_type(ctx, ACCESS_RES); |
4a9b3c5d | 3460 | EA = tcg_temp_new(); |
aa2008af | 3461 | gen_addr_reg_index(ctx, EA); |
aa2008af | 3462 | |
4a9b3c5d RH |
3463 | /* Note that the low part is always in RS+1, even in LE mode. */ |
3464 | lo = cpu_gpr[rs + 1]; | |
3465 | hi = cpu_gpr[rs]; | |
aa2008af | 3466 | |
4a9b3c5d | 3467 | if (tb_cflags(ctx->base.tb) & CF_PARALLEL) { |
f34ec0f6 RH |
3468 | if (HAVE_CMPXCHG128) { |
3469 | TCGv_i32 oi = tcg_const_i32(DEF_MEMOP(MO_Q) | MO_ALIGN_16); | |
3470 | if (ctx->le_mode) { | |
3471 | gen_helper_stqcx_le_parallel(cpu_crf[0], cpu_env, | |
3472 | EA, lo, hi, oi); | |
3473 | } else { | |
3474 | gen_helper_stqcx_be_parallel(cpu_crf[0], cpu_env, | |
3475 | EA, lo, hi, oi); | |
3476 | } | |
3477 | tcg_temp_free_i32(oi); | |
4a9b3c5d | 3478 | } else { |
f34ec0f6 RH |
3479 | /* Restart with exclusive lock. */ |
3480 | gen_helper_exit_atomic(cpu_env); | |
3481 | ctx->base.is_jmp = DISAS_NORETURN; | |
4a9b3c5d | 3482 | } |
4a9b3c5d | 3483 | tcg_temp_free(EA); |
aa2008af | 3484 | } else { |
4a9b3c5d RH |
3485 | TCGLabel *lab_fail = gen_new_label(); |
3486 | TCGLabel *lab_over = gen_new_label(); | |
3487 | TCGv_i64 t0 = tcg_temp_new_i64(); | |
3488 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
aa2008af | 3489 | |
4a9b3c5d RH |
3490 | tcg_gen_brcond_tl(TCG_COND_NE, EA, cpu_reserve, lab_fail); |
3491 | tcg_temp_free(EA); | |
aa2008af | 3492 | |
4a9b3c5d RH |
3493 | gen_qemu_ld64_i64(ctx, t0, cpu_reserve); |
3494 | tcg_gen_ld_i64(t1, cpu_env, (ctx->le_mode | |
3495 | ? offsetof(CPUPPCState, reserve_val2) | |
3496 | : offsetof(CPUPPCState, reserve_val))); | |
3497 | tcg_gen_brcond_i64(TCG_COND_NE, t0, t1, lab_fail); | |
3498 | ||
3499 | tcg_gen_addi_i64(t0, cpu_reserve, 8); | |
3500 | gen_qemu_ld64_i64(ctx, t0, t0); | |
3501 | tcg_gen_ld_i64(t1, cpu_env, (ctx->le_mode | |
3502 | ? offsetof(CPUPPCState, reserve_val) | |
3503 | : offsetof(CPUPPCState, reserve_val2))); | |
3504 | tcg_gen_brcond_i64(TCG_COND_NE, t0, t1, lab_fail); | |
3505 | ||
3506 | /* Success */ | |
3507 | gen_qemu_st64_i64(ctx, ctx->le_mode ? lo : hi, cpu_reserve); | |
3508 | tcg_gen_addi_i64(t0, cpu_reserve, 8); | |
3509 | gen_qemu_st64_i64(ctx, ctx->le_mode ? hi : lo, t0); | |
3510 | ||
3511 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so); | |
3512 | tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], CRF_EQ); | |
3513 | tcg_gen_br(lab_over); | |
3514 | ||
3515 | gen_set_label(lab_fail); | |
3516 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so); | |
3517 | ||
3518 | gen_set_label(lab_over); | |
3519 | tcg_gen_movi_tl(cpu_reserve, -1); | |
3520 | tcg_temp_free_i64(t0); | |
3521 | tcg_temp_free_i64(t1); | |
3522 | } | |
3523 | } | |
426613db JM |
3524 | #endif /* defined(TARGET_PPC64) */ |
3525 | ||
79aceca5 | 3526 | /* sync */ |
99e300ef | 3527 | static void gen_sync(DisasContext *ctx) |
79aceca5 | 3528 | { |
cd0c6f47 BH |
3529 | uint32_t l = (ctx->opcode >> 21) & 3; |
3530 | ||
3531 | /* | |
c5a8d8f3 BH |
3532 | * We may need to check for a pending TLB flush. |
3533 | * | |
3534 | * We do this on ptesync (l == 2) on ppc64 and any sync pn ppc32. | |
3535 | * | |
3536 | * Additionally, this can only happen in kernel mode however so | |
3537 | * check MSR_PR as well. | |
cd0c6f47 | 3538 | */ |
c5a8d8f3 | 3539 | if (((l == 2) || !(ctx->insns_flags & PPC_64B)) && !ctx->pr) { |
e3cffe6f | 3540 | gen_check_tlb_flush(ctx, true); |
cd0c6f47 | 3541 | } |
4771df23 | 3542 | tcg_gen_mb(TCG_MO_ALL | TCG_BAR_SC); |
79aceca5 FB |
3543 | } |
3544 | ||
0db1b20e | 3545 | /* wait */ |
99e300ef | 3546 | static void gen_wait(DisasContext *ctx) |
0db1b20e | 3547 | { |
35b5066e | 3548 | TCGv_i32 t0 = tcg_const_i32(1); |
259186a7 AF |
3549 | tcg_gen_st_i32(t0, cpu_env, |
3550 | -offsetof(PowerPCCPU, env) + offsetof(CPUState, halted)); | |
931ff272 | 3551 | tcg_temp_free_i32(t0); |
0db1b20e | 3552 | /* Stop translation, as the CPU is supposed to sleep from now */ |
b6bac4bc | 3553 | gen_exception_nip(ctx, EXCP_HLT, ctx->base.pc_next); |
0db1b20e JM |
3554 | } |
3555 | ||
7778a575 BH |
3556 | #if defined(TARGET_PPC64) |
3557 | static void gen_doze(DisasContext *ctx) | |
3558 | { | |
3559 | #if defined(CONFIG_USER_ONLY) | |
3560 | GEN_PRIV; | |
3561 | #else | |
3562 | TCGv_i32 t; | |
3563 | ||
3564 | CHK_HV; | |
3565 | t = tcg_const_i32(PPC_PM_DOZE); | |
3566 | gen_helper_pminsn(cpu_env, t); | |
3567 | tcg_temp_free_i32(t); | |
3568 | gen_stop_exception(ctx); | |
3569 | #endif /* defined(CONFIG_USER_ONLY) */ | |
3570 | } | |
3571 | ||
3572 | static void gen_nap(DisasContext *ctx) | |
3573 | { | |
3574 | #if defined(CONFIG_USER_ONLY) | |
3575 | GEN_PRIV; | |
3576 | #else | |
3577 | TCGv_i32 t; | |
3578 | ||
3579 | CHK_HV; | |
3580 | t = tcg_const_i32(PPC_PM_NAP); | |
3581 | gen_helper_pminsn(cpu_env, t); | |
3582 | tcg_temp_free_i32(t); | |
3583 | gen_stop_exception(ctx); | |
3584 | #endif /* defined(CONFIG_USER_ONLY) */ | |
3585 | } | |
3586 | ||
cdee0e72 ND |
3587 | static void gen_stop(DisasContext *ctx) |
3588 | { | |
3589 | gen_nap(ctx); | |
3590 | } | |
3591 | ||
7778a575 BH |
3592 | static void gen_sleep(DisasContext *ctx) |
3593 | { | |
3594 | #if defined(CONFIG_USER_ONLY) | |
3595 | GEN_PRIV; | |
3596 | #else | |
3597 | TCGv_i32 t; | |
3598 | ||
3599 | CHK_HV; | |
3600 | t = tcg_const_i32(PPC_PM_SLEEP); | |
3601 | gen_helper_pminsn(cpu_env, t); | |
3602 | tcg_temp_free_i32(t); | |
3603 | gen_stop_exception(ctx); | |
3604 | #endif /* defined(CONFIG_USER_ONLY) */ | |
3605 | } | |
3606 | ||
3607 | static void gen_rvwinkle(DisasContext *ctx) | |
3608 | { | |
3609 | #if defined(CONFIG_USER_ONLY) | |
3610 | GEN_PRIV; | |
3611 | #else | |
3612 | TCGv_i32 t; | |
3613 | ||
3614 | CHK_HV; | |
3615 | t = tcg_const_i32(PPC_PM_RVWINKLE); | |
3616 | gen_helper_pminsn(cpu_env, t); | |
3617 | tcg_temp_free_i32(t); | |
3618 | gen_stop_exception(ctx); | |
3619 | #endif /* defined(CONFIG_USER_ONLY) */ | |
3620 | } | |
3621 | #endif /* #if defined(TARGET_PPC64) */ | |
3622 | ||
697ab892 DG |
3623 | static inline void gen_update_cfar(DisasContext *ctx, target_ulong nip) |
3624 | { | |
3625 | #if defined(TARGET_PPC64) | |
3626 | if (ctx->has_cfar) | |
3627 | tcg_gen_movi_tl(cpu_cfar, nip); | |
3628 | #endif | |
3629 | } | |
3630 | ||
90aa39a1 SF |
3631 | static inline bool use_goto_tb(DisasContext *ctx, target_ulong dest) |
3632 | { | |
3633 | if (unlikely(ctx->singlestep_enabled)) { | |
3634 | return false; | |
3635 | } | |
3636 | ||
3637 | #ifndef CONFIG_USER_ONLY | |
b6bac4bc | 3638 | return (ctx->base.tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK); |
90aa39a1 SF |
3639 | #else |
3640 | return true; | |
3641 | #endif | |
3642 | } | |
3643 | ||
0e3bf489 RK |
3644 | static void gen_lookup_and_goto_ptr(DisasContext *ctx) |
3645 | { | |
3646 | int sse = ctx->singlestep_enabled; | |
3647 | if (unlikely(sse)) { | |
3648 | if (sse & GDBSTUB_SINGLE_STEP) { | |
3649 | gen_debug_exception(ctx); | |
3650 | } else if (sse & (CPU_SINGLE_STEP | CPU_BRANCH_STEP)) { | |
e150ac89 RK |
3651 | uint32_t excp = gen_prep_dbgex(ctx); |
3652 | gen_exception(ctx, excp); | |
0e3bf489 RK |
3653 | } |
3654 | tcg_gen_exit_tb(NULL, 0); | |
3655 | } else { | |
3656 | tcg_gen_lookup_and_goto_ptr(); | |
3657 | } | |
3658 | } | |
3659 | ||
79aceca5 | 3660 | /*** Branch ***/ |
c4a2e3a9 | 3661 | static void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) |
c1942362 | 3662 | { |
e0c8f9ce | 3663 | if (NARROW_MODE(ctx)) { |
a2ffb812 | 3664 | dest = (uint32_t) dest; |
e0c8f9ce | 3665 | } |
90aa39a1 | 3666 | if (use_goto_tb(ctx, dest)) { |
57fec1fe | 3667 | tcg_gen_goto_tb(n); |
a2ffb812 | 3668 | tcg_gen_movi_tl(cpu_nip, dest & ~3); |
07ea28b4 | 3669 | tcg_gen_exit_tb(ctx->base.tb, n); |
c1942362 | 3670 | } else { |
a2ffb812 | 3671 | tcg_gen_movi_tl(cpu_nip, dest & ~3); |
0e3bf489 | 3672 | gen_lookup_and_goto_ptr(ctx); |
c1942362 | 3673 | } |
c53be334 FB |
3674 | } |
3675 | ||
636aa200 | 3676 | static inline void gen_setlr(DisasContext *ctx, target_ulong nip) |
e1833e1f | 3677 | { |
e0c8f9ce RH |
3678 | if (NARROW_MODE(ctx)) { |
3679 | nip = (uint32_t)nip; | |
3680 | } | |
3681 | tcg_gen_movi_tl(cpu_lr, nip); | |
e1833e1f JM |
3682 | } |
3683 | ||
79aceca5 | 3684 | /* b ba bl bla */ |
99e300ef | 3685 | static void gen_b(DisasContext *ctx) |
79aceca5 | 3686 | { |
76a66253 | 3687 | target_ulong li, target; |
38a64f9d | 3688 | |
8cbcb4fa | 3689 | ctx->exception = POWERPC_EXCP_BRANCH; |
38a64f9d | 3690 | /* sign extend LI */ |
e0c8f9ce RH |
3691 | li = LI(ctx->opcode); |
3692 | li = (li ^ 0x02000000) - 0x02000000; | |
3693 | if (likely(AA(ctx->opcode) == 0)) { | |
b6bac4bc | 3694 | target = ctx->base.pc_next + li - 4; |
e0c8f9ce | 3695 | } else { |
9a64fbe4 | 3696 | target = li; |
e0c8f9ce RH |
3697 | } |
3698 | if (LK(ctx->opcode)) { | |
b6bac4bc | 3699 | gen_setlr(ctx, ctx->base.pc_next); |
e0c8f9ce | 3700 | } |
b6bac4bc | 3701 | gen_update_cfar(ctx, ctx->base.pc_next - 4); |
c1942362 | 3702 | gen_goto_tb(ctx, 0, target); |
79aceca5 FB |
3703 | } |
3704 | ||
e98a6e40 FB |
3705 | #define BCOND_IM 0 |
3706 | #define BCOND_LR 1 | |
3707 | #define BCOND_CTR 2 | |
52a4984d | 3708 | #define BCOND_TAR 3 |
e98a6e40 | 3709 | |
c4a2e3a9 | 3710 | static void gen_bcond(DisasContext *ctx, int type) |
d9bce9d9 | 3711 | { |
d9bce9d9 | 3712 | uint32_t bo = BO(ctx->opcode); |
42a268c2 | 3713 | TCGLabel *l1; |
a2ffb812 | 3714 | TCGv target; |
8cbcb4fa | 3715 | ctx->exception = POWERPC_EXCP_BRANCH; |
0e3bf489 | 3716 | |
52a4984d | 3717 | if (type == BCOND_LR || type == BCOND_CTR || type == BCOND_TAR) { |
a7812ae4 | 3718 | target = tcg_temp_local_new(); |
a2ffb812 AJ |
3719 | if (type == BCOND_CTR) |
3720 | tcg_gen_mov_tl(target, cpu_ctr); | |
52a4984d TM |
3721 | else if (type == BCOND_TAR) |
3722 | gen_load_spr(target, SPR_TAR); | |
a2ffb812 AJ |
3723 | else |
3724 | tcg_gen_mov_tl(target, cpu_lr); | |
d2e9fd8f | 3725 | } else { |
f764718d | 3726 | target = NULL; |
e98a6e40 | 3727 | } |
e1833e1f | 3728 | if (LK(ctx->opcode)) |
b6bac4bc | 3729 | gen_setlr(ctx, ctx->base.pc_next); |
a2ffb812 AJ |
3730 | l1 = gen_new_label(); |
3731 | if ((bo & 0x4) == 0) { | |
3732 | /* Decrement and test CTR */ | |
a7812ae4 | 3733 | TCGv temp = tcg_temp_new(); |
a2ffb812 | 3734 | if (unlikely(type == BCOND_CTR)) { |
e06fcd75 | 3735 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
a2ffb812 AJ |
3736 | return; |
3737 | } | |
3738 | tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1); | |
e0c8f9ce | 3739 | if (NARROW_MODE(ctx)) { |
a2ffb812 | 3740 | tcg_gen_ext32u_tl(temp, cpu_ctr); |
e0c8f9ce | 3741 | } else { |
a2ffb812 | 3742 | tcg_gen_mov_tl(temp, cpu_ctr); |
e0c8f9ce | 3743 | } |
a2ffb812 AJ |
3744 | if (bo & 0x2) { |
3745 | tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1); | |
3746 | } else { | |
3747 | tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1); | |
e98a6e40 | 3748 | } |
a7812ae4 | 3749 | tcg_temp_free(temp); |
a2ffb812 AJ |
3750 | } |
3751 | if ((bo & 0x10) == 0) { | |
3752 | /* Test CR */ | |
3753 | uint32_t bi = BI(ctx->opcode); | |
8f9fb7ac | 3754 | uint32_t mask = 0x08 >> (bi & 0x03); |
a7812ae4 | 3755 | TCGv_i32 temp = tcg_temp_new_i32(); |
a2ffb812 | 3756 | |
d9bce9d9 | 3757 | if (bo & 0x8) { |
a2ffb812 AJ |
3758 | tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask); |
3759 | tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1); | |
d9bce9d9 | 3760 | } else { |
a2ffb812 AJ |
3761 | tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask); |
3762 | tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1); | |
d9bce9d9 | 3763 | } |
a7812ae4 | 3764 | tcg_temp_free_i32(temp); |
d9bce9d9 | 3765 | } |
b6bac4bc | 3766 | gen_update_cfar(ctx, ctx->base.pc_next - 4); |
e98a6e40 | 3767 | if (type == BCOND_IM) { |
a2ffb812 AJ |
3768 | target_ulong li = (target_long)((int16_t)(BD(ctx->opcode))); |
3769 | if (likely(AA(ctx->opcode) == 0)) { | |
b6bac4bc | 3770 | gen_goto_tb(ctx, 0, ctx->base.pc_next + li - 4); |
a2ffb812 AJ |
3771 | } else { |
3772 | gen_goto_tb(ctx, 0, li); | |
3773 | } | |
e98a6e40 | 3774 | } else { |
e0c8f9ce | 3775 | if (NARROW_MODE(ctx)) { |
a2ffb812 | 3776 | tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3); |
e0c8f9ce | 3777 | } else { |
a2ffb812 | 3778 | tcg_gen_andi_tl(cpu_nip, target, ~3); |
e0c8f9ce | 3779 | } |
0e3bf489 | 3780 | gen_lookup_and_goto_ptr(ctx); |
c80d1df5 AG |
3781 | tcg_temp_free(target); |
3782 | } | |
c4a2e3a9 | 3783 | if ((bo & 0x14) != 0x14) { |
0e3bf489 | 3784 | /* fallthrough case */ |
c4a2e3a9 | 3785 | gen_set_label(l1); |
b6bac4bc | 3786 | gen_goto_tb(ctx, 1, ctx->base.pc_next); |
c4a2e3a9 | 3787 | } |
e98a6e40 FB |
3788 | } |
3789 | ||
99e300ef | 3790 | static void gen_bc(DisasContext *ctx) |
3b46e624 | 3791 | { |
e98a6e40 FB |
3792 | gen_bcond(ctx, BCOND_IM); |
3793 | } | |
3794 | ||
99e300ef | 3795 | static void gen_bcctr(DisasContext *ctx) |
3b46e624 | 3796 | { |
e98a6e40 FB |
3797 | gen_bcond(ctx, BCOND_CTR); |
3798 | } | |
3799 | ||
99e300ef | 3800 | static void gen_bclr(DisasContext *ctx) |
3b46e624 | 3801 | { |
e98a6e40 FB |
3802 | gen_bcond(ctx, BCOND_LR); |
3803 | } | |
79aceca5 | 3804 | |
52a4984d TM |
3805 | static void gen_bctar(DisasContext *ctx) |
3806 | { | |
3807 | gen_bcond(ctx, BCOND_TAR); | |
3808 | } | |
3809 | ||
79aceca5 | 3810 | /*** Condition register logical ***/ |
e1571908 | 3811 | #define GEN_CRLOGIC(name, tcg_op, opc) \ |
99e300ef | 3812 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 3813 | { \ |
fc0d441e JM |
3814 | uint8_t bitmask; \ |
3815 | int sh; \ | |
a7812ae4 | 3816 | TCGv_i32 t0, t1; \ |
fc0d441e | 3817 | sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \ |
a7812ae4 | 3818 | t0 = tcg_temp_new_i32(); \ |
fc0d441e | 3819 | if (sh > 0) \ |
fea0c503 | 3820 | tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \ |
fc0d441e | 3821 | else if (sh < 0) \ |
fea0c503 | 3822 | tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \ |
e1571908 | 3823 | else \ |
fea0c503 | 3824 | tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \ |
a7812ae4 | 3825 | t1 = tcg_temp_new_i32(); \ |
fc0d441e JM |
3826 | sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \ |
3827 | if (sh > 0) \ | |
fea0c503 | 3828 | tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \ |
fc0d441e | 3829 | else if (sh < 0) \ |
fea0c503 | 3830 | tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \ |
e1571908 | 3831 | else \ |
fea0c503 AJ |
3832 | tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \ |
3833 | tcg_op(t0, t0, t1); \ | |
8f9fb7ac | 3834 | bitmask = 0x08 >> (crbD(ctx->opcode) & 0x03); \ |
fea0c503 AJ |
3835 | tcg_gen_andi_i32(t0, t0, bitmask); \ |
3836 | tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \ | |
3837 | tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \ | |
a7812ae4 PB |
3838 | tcg_temp_free_i32(t0); \ |
3839 | tcg_temp_free_i32(t1); \ | |
79aceca5 FB |
3840 | } |
3841 | ||
3842 | /* crand */ | |
e1571908 | 3843 | GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08); |
79aceca5 | 3844 | /* crandc */ |
e1571908 | 3845 | GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04); |
79aceca5 | 3846 | /* creqv */ |
e1571908 | 3847 | GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09); |
79aceca5 | 3848 | /* crnand */ |
e1571908 | 3849 | GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07); |
79aceca5 | 3850 | /* crnor */ |
e1571908 | 3851 | GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01); |
79aceca5 | 3852 | /* cror */ |
e1571908 | 3853 | GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E); |
79aceca5 | 3854 | /* crorc */ |
e1571908 | 3855 | GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D); |
79aceca5 | 3856 | /* crxor */ |
e1571908 | 3857 | GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06); |
99e300ef | 3858 | |
54623277 | 3859 | /* mcrf */ |
99e300ef | 3860 | static void gen_mcrf(DisasContext *ctx) |
79aceca5 | 3861 | { |
47e4661c | 3862 | tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]); |
79aceca5 FB |
3863 | } |
3864 | ||
3865 | /*** System linkage ***/ | |
99e300ef | 3866 | |
c47493f2 | 3867 | /* rfi (supervisor only) */ |
99e300ef | 3868 | static void gen_rfi(DisasContext *ctx) |
79aceca5 | 3869 | { |
9a64fbe4 | 3870 | #if defined(CONFIG_USER_ONLY) |
9b2fadda | 3871 | GEN_PRIV; |
9a64fbe4 | 3872 | #else |
6ca038c2 BH |
3873 | /* This instruction doesn't exist anymore on 64-bit server |
3874 | * processors compliant with arch 2.x | |
a2e71b28 | 3875 | */ |
6ca038c2 BH |
3876 | if (ctx->insns_flags & PPC_SEGMENT_64B) { |
3877 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); | |
3878 | return; | |
3879 | } | |
9a64fbe4 | 3880 | /* Restore CPU state */ |
9b2fadda | 3881 | CHK_SV; |
a59d628f MK |
3882 | if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) { |
3883 | gen_io_start(); | |
3884 | } | |
b6bac4bc | 3885 | gen_update_cfar(ctx, ctx->base.pc_next - 4); |
e5f17ac6 | 3886 | gen_helper_rfi(cpu_env); |
e06fcd75 | 3887 | gen_sync_exception(ctx); |
a59d628f MK |
3888 | if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) { |
3889 | gen_io_end(); | |
3890 | } | |
9a64fbe4 | 3891 | #endif |
79aceca5 FB |
3892 | } |
3893 | ||
426613db | 3894 | #if defined(TARGET_PPC64) |
99e300ef | 3895 | static void gen_rfid(DisasContext *ctx) |
426613db JM |
3896 | { |
3897 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 3898 | GEN_PRIV; |
426613db JM |
3899 | #else |
3900 | /* Restore CPU state */ | |
9b2fadda | 3901 | CHK_SV; |
a59d628f MK |
3902 | if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) { |
3903 | gen_io_start(); | |
3904 | } | |
b6bac4bc | 3905 | gen_update_cfar(ctx, ctx->base.pc_next - 4); |
e5f17ac6 | 3906 | gen_helper_rfid(cpu_env); |
e06fcd75 | 3907 | gen_sync_exception(ctx); |
a59d628f MK |
3908 | if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) { |
3909 | gen_io_end(); | |
3910 | } | |
426613db JM |
3911 | #endif |
3912 | } | |
426613db | 3913 | |
99e300ef | 3914 | static void gen_hrfid(DisasContext *ctx) |
be147d08 JM |
3915 | { |
3916 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 3917 | GEN_PRIV; |
be147d08 JM |
3918 | #else |
3919 | /* Restore CPU state */ | |
9b2fadda | 3920 | CHK_HV; |
e5f17ac6 | 3921 | gen_helper_hrfid(cpu_env); |
e06fcd75 | 3922 | gen_sync_exception(ctx); |
be147d08 JM |
3923 | #endif |
3924 | } | |
3925 | #endif | |
3926 | ||
79aceca5 | 3927 | /* sc */ |
417bf010 JM |
3928 | #if defined(CONFIG_USER_ONLY) |
3929 | #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER | |
3930 | #else | |
3931 | #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL | |
3932 | #endif | |
99e300ef | 3933 | static void gen_sc(DisasContext *ctx) |
79aceca5 | 3934 | { |
e1833e1f JM |
3935 | uint32_t lev; |
3936 | ||
3937 | lev = (ctx->opcode >> 5) & 0x7F; | |
e06fcd75 | 3938 | gen_exception_err(ctx, POWERPC_SYSCALL, lev); |
79aceca5 FB |
3939 | } |
3940 | ||
3941 | /*** Trap ***/ | |
99e300ef | 3942 | |
22b56ee5 BH |
3943 | /* Check for unconditional traps (always or never) */ |
3944 | static bool check_unconditional_trap(DisasContext *ctx) | |
3945 | { | |
3946 | /* Trap never */ | |
3947 | if (TO(ctx->opcode) == 0) { | |
3948 | return true; | |
3949 | } | |
3950 | /* Trap always */ | |
3951 | if (TO(ctx->opcode) == 31) { | |
3952 | gen_exception_err(ctx, POWERPC_EXCP_PROGRAM, POWERPC_EXCP_TRAP); | |
3953 | return true; | |
3954 | } | |
3955 | return false; | |
3956 | } | |
3957 | ||
54623277 | 3958 | /* tw */ |
99e300ef | 3959 | static void gen_tw(DisasContext *ctx) |
79aceca5 | 3960 | { |
22b56ee5 BH |
3961 | TCGv_i32 t0; |
3962 | ||
3963 | if (check_unconditional_trap(ctx)) { | |
3964 | return; | |
3965 | } | |
3966 | t0 = tcg_const_i32(TO(ctx->opcode)); | |
e5f17ac6 BS |
3967 | gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], |
3968 | t0); | |
cab3bee2 | 3969 | tcg_temp_free_i32(t0); |
79aceca5 FB |
3970 | } |
3971 | ||
3972 | /* twi */ | |
99e300ef | 3973 | static void gen_twi(DisasContext *ctx) |
79aceca5 | 3974 | { |
22b56ee5 BH |
3975 | TCGv t0; |
3976 | TCGv_i32 t1; | |
3977 | ||
3978 | if (check_unconditional_trap(ctx)) { | |
3979 | return; | |
3980 | } | |
3981 | t0 = tcg_const_tl(SIMM(ctx->opcode)); | |
3982 | t1 = tcg_const_i32(TO(ctx->opcode)); | |
e5f17ac6 | 3983 | gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1); |
cab3bee2 AJ |
3984 | tcg_temp_free(t0); |
3985 | tcg_temp_free_i32(t1); | |
79aceca5 FB |
3986 | } |
3987 | ||
d9bce9d9 JM |
3988 | #if defined(TARGET_PPC64) |
3989 | /* td */ | |
99e300ef | 3990 | static void gen_td(DisasContext *ctx) |
d9bce9d9 | 3991 | { |
22b56ee5 BH |
3992 | TCGv_i32 t0; |
3993 | ||
3994 | if (check_unconditional_trap(ctx)) { | |
3995 | return; | |
3996 | } | |
3997 | t0 = tcg_const_i32(TO(ctx->opcode)); | |
e5f17ac6 BS |
3998 | gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], |
3999 | t0); | |
cab3bee2 | 4000 | tcg_temp_free_i32(t0); |
d9bce9d9 JM |
4001 | } |
4002 | ||
4003 | /* tdi */ | |
99e300ef | 4004 | static void gen_tdi(DisasContext *ctx) |
d9bce9d9 | 4005 | { |
22b56ee5 BH |
4006 | TCGv t0; |
4007 | TCGv_i32 t1; | |
4008 | ||
4009 | if (check_unconditional_trap(ctx)) { | |
4010 | return; | |
4011 | } | |
4012 | t0 = tcg_const_tl(SIMM(ctx->opcode)); | |
4013 | t1 = tcg_const_i32(TO(ctx->opcode)); | |
e5f17ac6 | 4014 | gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1); |
cab3bee2 AJ |
4015 | tcg_temp_free(t0); |
4016 | tcg_temp_free_i32(t1); | |
d9bce9d9 JM |
4017 | } |
4018 | #endif | |
4019 | ||
79aceca5 | 4020 | /*** Processor control ***/ |
99e300ef | 4021 | |
dd09c361 | 4022 | static void gen_read_xer(DisasContext *ctx, TCGv dst) |
da91a00f RH |
4023 | { |
4024 | TCGv t0 = tcg_temp_new(); | |
4025 | TCGv t1 = tcg_temp_new(); | |
4026 | TCGv t2 = tcg_temp_new(); | |
4027 | tcg_gen_mov_tl(dst, cpu_xer); | |
4028 | tcg_gen_shli_tl(t0, cpu_so, XER_SO); | |
4029 | tcg_gen_shli_tl(t1, cpu_ov, XER_OV); | |
4030 | tcg_gen_shli_tl(t2, cpu_ca, XER_CA); | |
4031 | tcg_gen_or_tl(t0, t0, t1); | |
4032 | tcg_gen_or_tl(dst, dst, t2); | |
4033 | tcg_gen_or_tl(dst, dst, t0); | |
dd09c361 ND |
4034 | if (is_isa300(ctx)) { |
4035 | tcg_gen_shli_tl(t0, cpu_ov32, XER_OV32); | |
4036 | tcg_gen_or_tl(dst, dst, t0); | |
4037 | tcg_gen_shli_tl(t0, cpu_ca32, XER_CA32); | |
4038 | tcg_gen_or_tl(dst, dst, t0); | |
4039 | } | |
da91a00f RH |
4040 | tcg_temp_free(t0); |
4041 | tcg_temp_free(t1); | |
4042 | tcg_temp_free(t2); | |
4043 | } | |
4044 | ||
4045 | static void gen_write_xer(TCGv src) | |
4046 | { | |
dd09c361 | 4047 | /* Write all flags, while reading back check for isa300 */ |
da91a00f | 4048 | tcg_gen_andi_tl(cpu_xer, src, |
dd09c361 ND |
4049 | ~((1u << XER_SO) | |
4050 | (1u << XER_OV) | (1u << XER_OV32) | | |
4051 | (1u << XER_CA) | (1u << XER_CA32))); | |
4052 | tcg_gen_extract_tl(cpu_ov32, src, XER_OV32, 1); | |
4053 | tcg_gen_extract_tl(cpu_ca32, src, XER_CA32, 1); | |
1bd33d0d ND |
4054 | tcg_gen_extract_tl(cpu_so, src, XER_SO, 1); |
4055 | tcg_gen_extract_tl(cpu_ov, src, XER_OV, 1); | |
4056 | tcg_gen_extract_tl(cpu_ca, src, XER_CA, 1); | |
da91a00f RH |
4057 | } |
4058 | ||
54623277 | 4059 | /* mcrxr */ |
99e300ef | 4060 | static void gen_mcrxr(DisasContext *ctx) |
79aceca5 | 4061 | { |
da91a00f RH |
4062 | TCGv_i32 t0 = tcg_temp_new_i32(); |
4063 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
4064 | TCGv_i32 dst = cpu_crf[crfD(ctx->opcode)]; | |
4065 | ||
4066 | tcg_gen_trunc_tl_i32(t0, cpu_so); | |
4067 | tcg_gen_trunc_tl_i32(t1, cpu_ov); | |
4068 | tcg_gen_trunc_tl_i32(dst, cpu_ca); | |
294d1292 SB |
4069 | tcg_gen_shli_i32(t0, t0, 3); |
4070 | tcg_gen_shli_i32(t1, t1, 2); | |
4071 | tcg_gen_shli_i32(dst, dst, 1); | |
da91a00f RH |
4072 | tcg_gen_or_i32(dst, dst, t0); |
4073 | tcg_gen_or_i32(dst, dst, t1); | |
4074 | tcg_temp_free_i32(t0); | |
4075 | tcg_temp_free_i32(t1); | |
4076 | ||
4077 | tcg_gen_movi_tl(cpu_so, 0); | |
4078 | tcg_gen_movi_tl(cpu_ov, 0); | |
4079 | tcg_gen_movi_tl(cpu_ca, 0); | |
79aceca5 FB |
4080 | } |
4081 | ||
b63d0434 ND |
4082 | #ifdef TARGET_PPC64 |
4083 | /* mcrxrx */ | |
4084 | static void gen_mcrxrx(DisasContext *ctx) | |
4085 | { | |
4086 | TCGv t0 = tcg_temp_new(); | |
4087 | TCGv t1 = tcg_temp_new(); | |
4088 | TCGv_i32 dst = cpu_crf[crfD(ctx->opcode)]; | |
4089 | ||
4090 | /* copy OV and OV32 */ | |
4091 | tcg_gen_shli_tl(t0, cpu_ov, 1); | |
4092 | tcg_gen_or_tl(t0, t0, cpu_ov32); | |
4093 | tcg_gen_shli_tl(t0, t0, 2); | |
4094 | /* copy CA and CA32 */ | |
4095 | tcg_gen_shli_tl(t1, cpu_ca, 1); | |
4096 | tcg_gen_or_tl(t1, t1, cpu_ca32); | |
4097 | tcg_gen_or_tl(t0, t0, t1); | |
4098 | tcg_gen_trunc_tl_i32(dst, t0); | |
4099 | tcg_temp_free(t0); | |
4100 | tcg_temp_free(t1); | |
4101 | } | |
4102 | #endif | |
4103 | ||
0cfe11ea | 4104 | /* mfcr mfocrf */ |
99e300ef | 4105 | static void gen_mfcr(DisasContext *ctx) |
79aceca5 | 4106 | { |
76a66253 | 4107 | uint32_t crm, crn; |
3b46e624 | 4108 | |
76a66253 JM |
4109 | if (likely(ctx->opcode & 0x00100000)) { |
4110 | crm = CRM(ctx->opcode); | |
8dd640e4 | 4111 | if (likely(crm && ((crm & (crm - 1)) == 0))) { |
0cfe11ea | 4112 | crn = ctz32 (crm); |
e1571908 | 4113 | tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]); |
0497d2f4 AJ |
4114 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], |
4115 | cpu_gpr[rD(ctx->opcode)], crn * 4); | |
76a66253 | 4116 | } |
d9bce9d9 | 4117 | } else { |
651721b2 AJ |
4118 | TCGv_i32 t0 = tcg_temp_new_i32(); |
4119 | tcg_gen_mov_i32(t0, cpu_crf[0]); | |
4120 | tcg_gen_shli_i32(t0, t0, 4); | |
4121 | tcg_gen_or_i32(t0, t0, cpu_crf[1]); | |
4122 | tcg_gen_shli_i32(t0, t0, 4); | |
4123 | tcg_gen_or_i32(t0, t0, cpu_crf[2]); | |
4124 | tcg_gen_shli_i32(t0, t0, 4); | |
4125 | tcg_gen_or_i32(t0, t0, cpu_crf[3]); | |
4126 | tcg_gen_shli_i32(t0, t0, 4); | |
4127 | tcg_gen_or_i32(t0, t0, cpu_crf[4]); | |
4128 | tcg_gen_shli_i32(t0, t0, 4); | |
4129 | tcg_gen_or_i32(t0, t0, cpu_crf[5]); | |
4130 | tcg_gen_shli_i32(t0, t0, 4); | |
4131 | tcg_gen_or_i32(t0, t0, cpu_crf[6]); | |
4132 | tcg_gen_shli_i32(t0, t0, 4); | |
4133 | tcg_gen_or_i32(t0, t0, cpu_crf[7]); | |
4134 | tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
4135 | tcg_temp_free_i32(t0); | |
d9bce9d9 | 4136 | } |
79aceca5 FB |
4137 | } |
4138 | ||
4139 | /* mfmsr */ | |
99e300ef | 4140 | static void gen_mfmsr(DisasContext *ctx) |
79aceca5 | 4141 | { |
9b2fadda | 4142 | CHK_SV; |
6527f6ea | 4143 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_msr); |
79aceca5 FB |
4144 | } |
4145 | ||
69b058c8 | 4146 | static void spr_noaccess(DisasContext *ctx, int gprn, int sprn) |
3fc6c082 | 4147 | { |
7b13448f | 4148 | #if 0 |
3fc6c082 FB |
4149 | sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5); |
4150 | printf("ERROR: try to access SPR %d !\n", sprn); | |
7b13448f | 4151 | #endif |
3fc6c082 FB |
4152 | } |
4153 | #define SPR_NOACCESS (&spr_noaccess) | |
3fc6c082 | 4154 | |
79aceca5 | 4155 | /* mfspr */ |
636aa200 | 4156 | static inline void gen_op_mfspr(DisasContext *ctx) |
79aceca5 | 4157 | { |
69b058c8 | 4158 | void (*read_cb)(DisasContext *ctx, int gprn, int sprn); |
79aceca5 FB |
4159 | uint32_t sprn = SPR(ctx->opcode); |
4160 | ||
eb94268e BH |
4161 | #if defined(CONFIG_USER_ONLY) |
4162 | read_cb = ctx->spr_cb[sprn].uea_read; | |
4163 | #else | |
4164 | if (ctx->pr) { | |
4165 | read_cb = ctx->spr_cb[sprn].uea_read; | |
4166 | } else if (ctx->hv) { | |
be147d08 | 4167 | read_cb = ctx->spr_cb[sprn].hea_read; |
eb94268e | 4168 | } else { |
3fc6c082 | 4169 | read_cb = ctx->spr_cb[sprn].oea_read; |
eb94268e | 4170 | } |
9a64fbe4 | 4171 | #endif |
76a66253 JM |
4172 | if (likely(read_cb != NULL)) { |
4173 | if (likely(read_cb != SPR_NOACCESS)) { | |
45d827d2 | 4174 | (*read_cb)(ctx, rD(ctx->opcode), sprn); |
3fc6c082 FB |
4175 | } else { |
4176 | /* Privilege exception */ | |
9fceefa7 JM |
4177 | /* This is a hack to avoid warnings when running Linux: |
4178 | * this OS breaks the PowerPC virtualisation model, | |
4179 | * allowing userland application to read the PVR | |
4180 | */ | |
4181 | if (sprn != SPR_PVR) { | |
31085338 TH |
4182 | qemu_log_mask(LOG_GUEST_ERROR, "Trying to read privileged spr " |
4183 | "%d (0x%03x) at " TARGET_FMT_lx "\n", sprn, sprn, | |
4184 | ctx->base.pc_next - 4); | |
f24e5695 | 4185 | } |
9b2fadda | 4186 | gen_priv_exception(ctx, POWERPC_EXCP_PRIV_REG); |
79aceca5 | 4187 | } |
3fc6c082 | 4188 | } else { |
9b2fadda BH |
4189 | /* ISA 2.07 defines these as no-ops */ |
4190 | if ((ctx->insns_flags2 & PPC2_ISA207S) && | |
4191 | (sprn >= 808 && sprn <= 811)) { | |
4192 | /* This is a nop */ | |
4193 | return; | |
4194 | } | |
3fc6c082 | 4195 | /* Not defined */ |
31085338 TH |
4196 | qemu_log_mask(LOG_GUEST_ERROR, |
4197 | "Trying to read invalid spr %d (0x%03x) at " | |
4198 | TARGET_FMT_lx "\n", sprn, sprn, ctx->base.pc_next - 4); | |
9b2fadda BH |
4199 | |
4200 | /* The behaviour depends on MSR:PR and SPR# bit 0x10, | |
4201 | * it can generate a priv, a hv emu or a no-op | |
4202 | */ | |
4203 | if (sprn & 0x10) { | |
4204 | if (ctx->pr) { | |
4205 | gen_priv_exception(ctx, POWERPC_EXCP_INVAL_SPR); | |
4206 | } | |
4207 | } else { | |
4208 | if (ctx->pr || sprn == 0 || sprn == 4 || sprn == 5 || sprn == 6) { | |
4209 | gen_hvpriv_exception(ctx, POWERPC_EXCP_INVAL_SPR); | |
4210 | } | |
4d6a0680 | 4211 | } |
79aceca5 | 4212 | } |
79aceca5 FB |
4213 | } |
4214 | ||
99e300ef | 4215 | static void gen_mfspr(DisasContext *ctx) |
79aceca5 | 4216 | { |
3fc6c082 | 4217 | gen_op_mfspr(ctx); |
76a66253 | 4218 | } |
3fc6c082 FB |
4219 | |
4220 | /* mftb */ | |
99e300ef | 4221 | static void gen_mftb(DisasContext *ctx) |
3fc6c082 FB |
4222 | { |
4223 | gen_op_mfspr(ctx); | |
79aceca5 FB |
4224 | } |
4225 | ||
0cfe11ea | 4226 | /* mtcrf mtocrf*/ |
99e300ef | 4227 | static void gen_mtcrf(DisasContext *ctx) |
79aceca5 | 4228 | { |
76a66253 | 4229 | uint32_t crm, crn; |
3b46e624 | 4230 | |
76a66253 | 4231 | crm = CRM(ctx->opcode); |
8dd640e4 | 4232 | if (likely((ctx->opcode & 0x00100000))) { |
4233 | if (crm && ((crm & (crm - 1)) == 0)) { | |
4234 | TCGv_i32 temp = tcg_temp_new_i32(); | |
0cfe11ea | 4235 | crn = ctz32 (crm); |
8dd640e4 | 4236 | tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]); |
0cfe11ea AJ |
4237 | tcg_gen_shri_i32(temp, temp, crn * 4); |
4238 | tcg_gen_andi_i32(cpu_crf[7 - crn], temp, 0xf); | |
8dd640e4 | 4239 | tcg_temp_free_i32(temp); |
4240 | } | |
76a66253 | 4241 | } else { |
651721b2 AJ |
4242 | TCGv_i32 temp = tcg_temp_new_i32(); |
4243 | tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]); | |
4244 | for (crn = 0 ; crn < 8 ; crn++) { | |
4245 | if (crm & (1 << crn)) { | |
4246 | tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4); | |
4247 | tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf); | |
4248 | } | |
4249 | } | |
a7812ae4 | 4250 | tcg_temp_free_i32(temp); |
76a66253 | 4251 | } |
79aceca5 FB |
4252 | } |
4253 | ||
4254 | /* mtmsr */ | |
426613db | 4255 | #if defined(TARGET_PPC64) |
99e300ef | 4256 | static void gen_mtmsrd(DisasContext *ctx) |
426613db | 4257 | { |
9b2fadda BH |
4258 | CHK_SV; |
4259 | ||
4260 | #if !defined(CONFIG_USER_ONLY) | |
be147d08 JM |
4261 | if (ctx->opcode & 0x00010000) { |
4262 | /* Special form that does not need any synchronisation */ | |
6527f6ea AJ |
4263 | TCGv t0 = tcg_temp_new(); |
4264 | tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE)); | |
c409bc5d | 4265 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(target_ulong)((1 << MSR_RI) | (1 << MSR_EE))); |
6527f6ea AJ |
4266 | tcg_gen_or_tl(cpu_msr, cpu_msr, t0); |
4267 | tcg_temp_free(t0); | |
be147d08 | 4268 | } else { |
056b05f8 JM |
4269 | /* XXX: we need to update nip before the store |
4270 | * if we enter power saving mode, we will exit the loop | |
4271 | * directly from ppc_store_msr | |
4272 | */ | |
b8edea50 PD |
4273 | if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) { |
4274 | gen_io_start(); | |
4275 | } | |
b6bac4bc | 4276 | gen_update_nip(ctx, ctx->base.pc_next); |
e5f17ac6 | 4277 | gen_helper_store_msr(cpu_env, cpu_gpr[rS(ctx->opcode)]); |
be147d08 JM |
4278 | /* Must stop the translation as machine state (may have) changed */ |
4279 | /* Note that mtmsr is not always defined as context-synchronizing */ | |
e06fcd75 | 4280 | gen_stop_exception(ctx); |
b8edea50 PD |
4281 | if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) { |
4282 | gen_io_end(); | |
4283 | } | |
be147d08 | 4284 | } |
9b2fadda | 4285 | #endif /* !defined(CONFIG_USER_ONLY) */ |
426613db | 4286 | } |
9b2fadda | 4287 | #endif /* defined(TARGET_PPC64) */ |
426613db | 4288 | |
99e300ef | 4289 | static void gen_mtmsr(DisasContext *ctx) |
79aceca5 | 4290 | { |
9b2fadda BH |
4291 | CHK_SV; |
4292 | ||
4293 | #if !defined(CONFIG_USER_ONLY) | |
4294 | if (ctx->opcode & 0x00010000) { | |
be147d08 | 4295 | /* Special form that does not need any synchronisation */ |
6527f6ea AJ |
4296 | TCGv t0 = tcg_temp_new(); |
4297 | tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE)); | |
c409bc5d | 4298 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(target_ulong)((1 << MSR_RI) | (1 << MSR_EE))); |
6527f6ea AJ |
4299 | tcg_gen_or_tl(cpu_msr, cpu_msr, t0); |
4300 | tcg_temp_free(t0); | |
be147d08 | 4301 | } else { |
8018dc63 AG |
4302 | TCGv msr = tcg_temp_new(); |
4303 | ||
056b05f8 JM |
4304 | /* XXX: we need to update nip before the store |
4305 | * if we enter power saving mode, we will exit the loop | |
4306 | * directly from ppc_store_msr | |
4307 | */ | |
b8edea50 PD |
4308 | if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) { |
4309 | gen_io_start(); | |
4310 | } | |
b6bac4bc | 4311 | gen_update_nip(ctx, ctx->base.pc_next); |
d9bce9d9 | 4312 | #if defined(TARGET_PPC64) |
8018dc63 AG |
4313 | tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32); |
4314 | #else | |
4315 | tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]); | |
d9bce9d9 | 4316 | #endif |
e5f17ac6 | 4317 | gen_helper_store_msr(cpu_env, msr); |
b8edea50 PD |
4318 | if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) { |
4319 | gen_io_end(); | |
4320 | } | |
c80d1df5 | 4321 | tcg_temp_free(msr); |
be147d08 | 4322 | /* Must stop the translation as machine state (may have) changed */ |
6527f6ea | 4323 | /* Note that mtmsr is not always defined as context-synchronizing */ |
e06fcd75 | 4324 | gen_stop_exception(ctx); |
be147d08 | 4325 | } |
9a64fbe4 | 4326 | #endif |
79aceca5 FB |
4327 | } |
4328 | ||
4329 | /* mtspr */ | |
99e300ef | 4330 | static void gen_mtspr(DisasContext *ctx) |
79aceca5 | 4331 | { |
69b058c8 | 4332 | void (*write_cb)(DisasContext *ctx, int sprn, int gprn); |
79aceca5 FB |
4333 | uint32_t sprn = SPR(ctx->opcode); |
4334 | ||
eb94268e BH |
4335 | #if defined(CONFIG_USER_ONLY) |
4336 | write_cb = ctx->spr_cb[sprn].uea_write; | |
4337 | #else | |
4338 | if (ctx->pr) { | |
4339 | write_cb = ctx->spr_cb[sprn].uea_write; | |
4340 | } else if (ctx->hv) { | |
be147d08 | 4341 | write_cb = ctx->spr_cb[sprn].hea_write; |
eb94268e | 4342 | } else { |
3fc6c082 | 4343 | write_cb = ctx->spr_cb[sprn].oea_write; |
eb94268e | 4344 | } |
9a64fbe4 | 4345 | #endif |
76a66253 JM |
4346 | if (likely(write_cb != NULL)) { |
4347 | if (likely(write_cb != SPR_NOACCESS)) { | |
45d827d2 | 4348 | (*write_cb)(ctx, sprn, rS(ctx->opcode)); |
3fc6c082 FB |
4349 | } else { |
4350 | /* Privilege exception */ | |
31085338 TH |
4351 | qemu_log_mask(LOG_GUEST_ERROR, "Trying to write privileged spr " |
4352 | "%d (0x%03x) at " TARGET_FMT_lx "\n", sprn, sprn, | |
4353 | ctx->base.pc_next - 4); | |
9b2fadda | 4354 | gen_priv_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 | 4355 | } |
3fc6c082 | 4356 | } else { |
9b2fadda BH |
4357 | /* ISA 2.07 defines these as no-ops */ |
4358 | if ((ctx->insns_flags2 & PPC2_ISA207S) && | |
4359 | (sprn >= 808 && sprn <= 811)) { | |
4360 | /* This is a nop */ | |
4361 | return; | |
4362 | } | |
4363 | ||
3fc6c082 | 4364 | /* Not defined */ |
31085338 TH |
4365 | qemu_log_mask(LOG_GUEST_ERROR, |
4366 | "Trying to write invalid spr %d (0x%03x) at " | |
4367 | TARGET_FMT_lx "\n", sprn, sprn, ctx->base.pc_next - 4); | |
4d6a0680 | 4368 | |
9b2fadda BH |
4369 | |
4370 | /* The behaviour depends on MSR:PR and SPR# bit 0x10, | |
4371 | * it can generate a priv, a hv emu or a no-op | |
4372 | */ | |
4373 | if (sprn & 0x10) { | |
4374 | if (ctx->pr) { | |
4375 | gen_priv_exception(ctx, POWERPC_EXCP_INVAL_SPR); | |
4376 | } | |
4377 | } else { | |
4378 | if (ctx->pr || sprn == 0) { | |
4379 | gen_hvpriv_exception(ctx, POWERPC_EXCP_INVAL_SPR); | |
4380 | } | |
4d6a0680 | 4381 | } |
79aceca5 | 4382 | } |
79aceca5 FB |
4383 | } |
4384 | ||
dc2ee038 VAS |
4385 | #if defined(TARGET_PPC64) |
4386 | /* setb */ | |
4387 | static void gen_setb(DisasContext *ctx) | |
4388 | { | |
4389 | TCGv_i32 t0 = tcg_temp_new_i32(); | |
4390 | TCGv_i32 t8 = tcg_temp_new_i32(); | |
4391 | TCGv_i32 tm1 = tcg_temp_new_i32(); | |
4392 | int crf = crfS(ctx->opcode); | |
4393 | ||
4394 | tcg_gen_setcondi_i32(TCG_COND_GEU, t0, cpu_crf[crf], 4); | |
4395 | tcg_gen_movi_i32(t8, 8); | |
4396 | tcg_gen_movi_i32(tm1, -1); | |
4397 | tcg_gen_movcond_i32(TCG_COND_GEU, t0, cpu_crf[crf], t8, tm1, t0); | |
4398 | tcg_gen_ext_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
4399 | ||
4400 | tcg_temp_free_i32(t0); | |
4401 | tcg_temp_free_i32(t8); | |
4402 | tcg_temp_free_i32(tm1); | |
4403 | } | |
4404 | #endif | |
4405 | ||
79aceca5 | 4406 | /*** Cache management ***/ |
99e300ef | 4407 | |
54623277 | 4408 | /* dcbf */ |
99e300ef | 4409 | static void gen_dcbf(DisasContext *ctx) |
79aceca5 | 4410 | { |
dac454af | 4411 | /* XXX: specification says this is treated as a load by the MMU */ |
76db3ba4 AJ |
4412 | TCGv t0; |
4413 | gen_set_access_type(ctx, ACCESS_CACHE); | |
4414 | t0 = tcg_temp_new(); | |
4415 | gen_addr_reg_index(ctx, t0); | |
4416 | gen_qemu_ld8u(ctx, t0, t0); | |
fea0c503 | 4417 | tcg_temp_free(t0); |
79aceca5 FB |
4418 | } |
4419 | ||
50728199 RK |
4420 | /* dcbfep (external PID dcbf) */ |
4421 | static void gen_dcbfep(DisasContext *ctx) | |
4422 | { | |
4423 | /* XXX: specification says this is treated as a load by the MMU */ | |
4424 | TCGv t0; | |
4425 | CHK_SV; | |
4426 | gen_set_access_type(ctx, ACCESS_CACHE); | |
4427 | t0 = tcg_temp_new(); | |
4428 | gen_addr_reg_index(ctx, t0); | |
4429 | tcg_gen_qemu_ld_tl(t0, t0, PPC_TLB_EPID_LOAD, DEF_MEMOP(MO_UB)); | |
4430 | tcg_temp_free(t0); | |
4431 | } | |
4432 | ||
79aceca5 | 4433 | /* dcbi (Supervisor only) */ |
99e300ef | 4434 | static void gen_dcbi(DisasContext *ctx) |
79aceca5 | 4435 | { |
a541f297 | 4436 | #if defined(CONFIG_USER_ONLY) |
9b2fadda | 4437 | GEN_PRIV; |
a541f297 | 4438 | #else |
b61f2753 | 4439 | TCGv EA, val; |
9b2fadda BH |
4440 | |
4441 | CHK_SV; | |
a7812ae4 | 4442 | EA = tcg_temp_new(); |
76db3ba4 AJ |
4443 | gen_set_access_type(ctx, ACCESS_CACHE); |
4444 | gen_addr_reg_index(ctx, EA); | |
a7812ae4 | 4445 | val = tcg_temp_new(); |
76a66253 | 4446 | /* XXX: specification says this should be treated as a store by the MMU */ |
76db3ba4 AJ |
4447 | gen_qemu_ld8u(ctx, val, EA); |
4448 | gen_qemu_st8(ctx, val, EA); | |
b61f2753 AJ |
4449 | tcg_temp_free(val); |
4450 | tcg_temp_free(EA); | |
9b2fadda | 4451 | #endif /* defined(CONFIG_USER_ONLY) */ |
79aceca5 FB |
4452 | } |
4453 | ||
4454 | /* dcdst */ | |
99e300ef | 4455 | static void gen_dcbst(DisasContext *ctx) |
79aceca5 | 4456 | { |
76a66253 | 4457 | /* XXX: specification say this is treated as a load by the MMU */ |
76db3ba4 AJ |
4458 | TCGv t0; |
4459 | gen_set_access_type(ctx, ACCESS_CACHE); | |
4460 | t0 = tcg_temp_new(); | |
4461 | gen_addr_reg_index(ctx, t0); | |
4462 | gen_qemu_ld8u(ctx, t0, t0); | |
fea0c503 | 4463 | tcg_temp_free(t0); |
79aceca5 FB |
4464 | } |
4465 | ||
50728199 RK |
4466 | /* dcbstep (dcbstep External PID version) */ |
4467 | static void gen_dcbstep(DisasContext *ctx) | |
4468 | { | |
4469 | /* XXX: specification say this is treated as a load by the MMU */ | |
4470 | TCGv t0; | |
4471 | gen_set_access_type(ctx, ACCESS_CACHE); | |
4472 | t0 = tcg_temp_new(); | |
4473 | gen_addr_reg_index(ctx, t0); | |
4474 | tcg_gen_qemu_ld_tl(t0, t0, PPC_TLB_EPID_LOAD, DEF_MEMOP(MO_UB)); | |
4475 | tcg_temp_free(t0); | |
4476 | } | |
4477 | ||
79aceca5 | 4478 | /* dcbt */ |
99e300ef | 4479 | static void gen_dcbt(DisasContext *ctx) |
79aceca5 | 4480 | { |
0db1b20e | 4481 | /* interpreted as no-op */ |
76a66253 JM |
4482 | /* XXX: specification say this is treated as a load by the MMU |
4483 | * but does not generate any exception | |
4484 | */ | |
79aceca5 FB |
4485 | } |
4486 | ||
50728199 RK |
4487 | /* dcbtep */ |
4488 | static void gen_dcbtep(DisasContext *ctx) | |
4489 | { | |
4490 | /* interpreted as no-op */ | |
4491 | /* XXX: specification say this is treated as a load by the MMU | |
4492 | * but does not generate any exception | |
4493 | */ | |
4494 | } | |
4495 | ||
79aceca5 | 4496 | /* dcbtst */ |
99e300ef | 4497 | static void gen_dcbtst(DisasContext *ctx) |
79aceca5 | 4498 | { |
0db1b20e | 4499 | /* interpreted as no-op */ |
76a66253 JM |
4500 | /* XXX: specification say this is treated as a load by the MMU |
4501 | * but does not generate any exception | |
4502 | */ | |
79aceca5 FB |
4503 | } |
4504 | ||
50728199 RK |
4505 | /* dcbtstep */ |
4506 | static void gen_dcbtstep(DisasContext *ctx) | |
4507 | { | |
4508 | /* interpreted as no-op */ | |
4509 | /* XXX: specification say this is treated as a load by the MMU | |
4510 | * but does not generate any exception | |
4511 | */ | |
4512 | } | |
4513 | ||
4d09d529 AG |
4514 | /* dcbtls */ |
4515 | static void gen_dcbtls(DisasContext *ctx) | |
4516 | { | |
4517 | /* Always fails locking the cache */ | |
4518 | TCGv t0 = tcg_temp_new(); | |
4519 | gen_load_spr(t0, SPR_Exxx_L1CSR0); | |
4520 | tcg_gen_ori_tl(t0, t0, L1CSR0_CUL); | |
4521 | gen_store_spr(SPR_Exxx_L1CSR0, t0); | |
4522 | tcg_temp_free(t0); | |
4523 | } | |
4524 | ||
79aceca5 | 4525 | /* dcbz */ |
99e300ef | 4526 | static void gen_dcbz(DisasContext *ctx) |
79aceca5 | 4527 | { |
8e33944f | 4528 | TCGv tcgv_addr; |
c9f82d01 | 4529 | TCGv_i32 tcgv_op; |
d63001d1 | 4530 | |
76db3ba4 | 4531 | gen_set_access_type(ctx, ACCESS_CACHE); |
8e33944f | 4532 | tcgv_addr = tcg_temp_new(); |
c9f82d01 | 4533 | tcgv_op = tcg_const_i32(ctx->opcode & 0x03FF000); |
8e33944f | 4534 | gen_addr_reg_index(ctx, tcgv_addr); |
c9f82d01 | 4535 | gen_helper_dcbz(cpu_env, tcgv_addr, tcgv_op); |
8e33944f | 4536 | tcg_temp_free(tcgv_addr); |
c9f82d01 | 4537 | tcg_temp_free_i32(tcgv_op); |
79aceca5 FB |
4538 | } |
4539 | ||
50728199 RK |
4540 | /* dcbzep */ |
4541 | static void gen_dcbzep(DisasContext *ctx) | |
4542 | { | |
4543 | TCGv tcgv_addr; | |
4544 | TCGv_i32 tcgv_op; | |
4545 | ||
4546 | gen_set_access_type(ctx, ACCESS_CACHE); | |
4547 | tcgv_addr = tcg_temp_new(); | |
4548 | tcgv_op = tcg_const_i32(ctx->opcode & 0x03FF000); | |
4549 | gen_addr_reg_index(ctx, tcgv_addr); | |
4550 | gen_helper_dcbzep(cpu_env, tcgv_addr, tcgv_op); | |
4551 | tcg_temp_free(tcgv_addr); | |
4552 | tcg_temp_free_i32(tcgv_op); | |
4553 | } | |
4554 | ||
ae1c1a3d | 4555 | /* dst / dstt */ |
99e300ef | 4556 | static void gen_dst(DisasContext *ctx) |
ae1c1a3d AJ |
4557 | { |
4558 | if (rA(ctx->opcode) == 0) { | |
e41029b3 | 4559 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
ae1c1a3d AJ |
4560 | } else { |
4561 | /* interpreted as no-op */ | |
4562 | } | |
4563 | } | |
4564 | ||
4565 | /* dstst /dststt */ | |
99e300ef | 4566 | static void gen_dstst(DisasContext *ctx) |
ae1c1a3d AJ |
4567 | { |
4568 | if (rA(ctx->opcode) == 0) { | |
e41029b3 | 4569 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
ae1c1a3d AJ |
4570 | } else { |
4571 | /* interpreted as no-op */ | |
4572 | } | |
4573 | ||
4574 | } | |
4575 | ||
4576 | /* dss / dssall */ | |
99e300ef | 4577 | static void gen_dss(DisasContext *ctx) |
ae1c1a3d AJ |
4578 | { |
4579 | /* interpreted as no-op */ | |
4580 | } | |
4581 | ||
79aceca5 | 4582 | /* icbi */ |
99e300ef | 4583 | static void gen_icbi(DisasContext *ctx) |
79aceca5 | 4584 | { |
76db3ba4 AJ |
4585 | TCGv t0; |
4586 | gen_set_access_type(ctx, ACCESS_CACHE); | |
76db3ba4 AJ |
4587 | t0 = tcg_temp_new(); |
4588 | gen_addr_reg_index(ctx, t0); | |
2f5a189c | 4589 | gen_helper_icbi(cpu_env, t0); |
37d269df | 4590 | tcg_temp_free(t0); |
79aceca5 FB |
4591 | } |
4592 | ||
50728199 RK |
4593 | /* icbiep */ |
4594 | static void gen_icbiep(DisasContext *ctx) | |
4595 | { | |
4596 | TCGv t0; | |
4597 | gen_set_access_type(ctx, ACCESS_CACHE); | |
4598 | t0 = tcg_temp_new(); | |
4599 | gen_addr_reg_index(ctx, t0); | |
4600 | gen_helper_icbiep(cpu_env, t0); | |
4601 | tcg_temp_free(t0); | |
4602 | } | |
4603 | ||
79aceca5 FB |
4604 | /* Optional: */ |
4605 | /* dcba */ | |
99e300ef | 4606 | static void gen_dcba(DisasContext *ctx) |
79aceca5 | 4607 | { |
0db1b20e JM |
4608 | /* interpreted as no-op */ |
4609 | /* XXX: specification say this is treated as a store by the MMU | |
4610 | * but does not generate any exception | |
4611 | */ | |
79aceca5 FB |
4612 | } |
4613 | ||
4614 | /*** Segment register manipulation ***/ | |
4615 | /* Supervisor only: */ | |
99e300ef | 4616 | |
54623277 | 4617 | /* mfsr */ |
99e300ef | 4618 | static void gen_mfsr(DisasContext *ctx) |
79aceca5 | 4619 | { |
9a64fbe4 | 4620 | #if defined(CONFIG_USER_ONLY) |
9b2fadda | 4621 | GEN_PRIV; |
9a64fbe4 | 4622 | #else |
74d37793 | 4623 | TCGv t0; |
9b2fadda BH |
4624 | |
4625 | CHK_SV; | |
74d37793 | 4626 | t0 = tcg_const_tl(SR(ctx->opcode)); |
c6c7cf05 | 4627 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 | 4628 | tcg_temp_free(t0); |
9b2fadda | 4629 | #endif /* defined(CONFIG_USER_ONLY) */ |
79aceca5 FB |
4630 | } |
4631 | ||
4632 | /* mfsrin */ | |
99e300ef | 4633 | static void gen_mfsrin(DisasContext *ctx) |
79aceca5 | 4634 | { |
9a64fbe4 | 4635 | #if defined(CONFIG_USER_ONLY) |
9b2fadda | 4636 | GEN_PRIV; |
9a64fbe4 | 4637 | #else |
74d37793 | 4638 | TCGv t0; |
9b2fadda BH |
4639 | |
4640 | CHK_SV; | |
74d37793 | 4641 | t0 = tcg_temp_new(); |
e2622073 | 4642 | tcg_gen_extract_tl(t0, cpu_gpr[rB(ctx->opcode)], 28, 4); |
c6c7cf05 | 4643 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 | 4644 | tcg_temp_free(t0); |
9b2fadda | 4645 | #endif /* defined(CONFIG_USER_ONLY) */ |
79aceca5 FB |
4646 | } |
4647 | ||
4648 | /* mtsr */ | |
99e300ef | 4649 | static void gen_mtsr(DisasContext *ctx) |
79aceca5 | 4650 | { |
9a64fbe4 | 4651 | #if defined(CONFIG_USER_ONLY) |
9b2fadda | 4652 | GEN_PRIV; |
9a64fbe4 | 4653 | #else |
74d37793 | 4654 | TCGv t0; |
9b2fadda BH |
4655 | |
4656 | CHK_SV; | |
74d37793 | 4657 | t0 = tcg_const_tl(SR(ctx->opcode)); |
c6c7cf05 | 4658 | gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]); |
74d37793 | 4659 | tcg_temp_free(t0); |
9b2fadda | 4660 | #endif /* defined(CONFIG_USER_ONLY) */ |
79aceca5 FB |
4661 | } |
4662 | ||
4663 | /* mtsrin */ | |
99e300ef | 4664 | static void gen_mtsrin(DisasContext *ctx) |
79aceca5 | 4665 | { |
9a64fbe4 | 4666 | #if defined(CONFIG_USER_ONLY) |
9b2fadda | 4667 | GEN_PRIV; |
9a64fbe4 | 4668 | #else |
74d37793 | 4669 | TCGv t0; |
9b2fadda BH |
4670 | CHK_SV; |
4671 | ||
74d37793 | 4672 | t0 = tcg_temp_new(); |
e2622073 | 4673 | tcg_gen_extract_tl(t0, cpu_gpr[rB(ctx->opcode)], 28, 4); |
c6c7cf05 | 4674 | gen_helper_store_sr(cpu_env, t0, cpu_gpr[rD(ctx->opcode)]); |
74d37793 | 4675 | tcg_temp_free(t0); |
9b2fadda | 4676 | #endif /* defined(CONFIG_USER_ONLY) */ |
79aceca5 FB |
4677 | } |
4678 | ||
12de9a39 JM |
4679 | #if defined(TARGET_PPC64) |
4680 | /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */ | |
e8eaa2c0 | 4681 | |
54623277 | 4682 | /* mfsr */ |
e8eaa2c0 | 4683 | static void gen_mfsr_64b(DisasContext *ctx) |
12de9a39 JM |
4684 | { |
4685 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 4686 | GEN_PRIV; |
12de9a39 | 4687 | #else |
74d37793 | 4688 | TCGv t0; |
9b2fadda BH |
4689 | |
4690 | CHK_SV; | |
74d37793 | 4691 | t0 = tcg_const_tl(SR(ctx->opcode)); |
c6c7cf05 | 4692 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 | 4693 | tcg_temp_free(t0); |
9b2fadda | 4694 | #endif /* defined(CONFIG_USER_ONLY) */ |
12de9a39 JM |
4695 | } |
4696 | ||
4697 | /* mfsrin */ | |
e8eaa2c0 | 4698 | static void gen_mfsrin_64b(DisasContext *ctx) |
12de9a39 JM |
4699 | { |
4700 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 4701 | GEN_PRIV; |
12de9a39 | 4702 | #else |
74d37793 | 4703 | TCGv t0; |
9b2fadda BH |
4704 | |
4705 | CHK_SV; | |
74d37793 | 4706 | t0 = tcg_temp_new(); |
e2622073 | 4707 | tcg_gen_extract_tl(t0, cpu_gpr[rB(ctx->opcode)], 28, 4); |
c6c7cf05 | 4708 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 | 4709 | tcg_temp_free(t0); |
9b2fadda | 4710 | #endif /* defined(CONFIG_USER_ONLY) */ |
12de9a39 JM |
4711 | } |
4712 | ||
4713 | /* mtsr */ | |
e8eaa2c0 | 4714 | static void gen_mtsr_64b(DisasContext *ctx) |
12de9a39 JM |
4715 | { |
4716 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 4717 | GEN_PRIV; |
12de9a39 | 4718 | #else |
74d37793 | 4719 | TCGv t0; |
9b2fadda BH |
4720 | |
4721 | CHK_SV; | |
74d37793 | 4722 | t0 = tcg_const_tl(SR(ctx->opcode)); |
c6c7cf05 | 4723 | gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]); |
74d37793 | 4724 | tcg_temp_free(t0); |
9b2fadda | 4725 | #endif /* defined(CONFIG_USER_ONLY) */ |
12de9a39 JM |
4726 | } |
4727 | ||
4728 | /* mtsrin */ | |
e8eaa2c0 | 4729 | static void gen_mtsrin_64b(DisasContext *ctx) |
12de9a39 JM |
4730 | { |
4731 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 4732 | GEN_PRIV; |
12de9a39 | 4733 | #else |
74d37793 | 4734 | TCGv t0; |
9b2fadda BH |
4735 | |
4736 | CHK_SV; | |
74d37793 | 4737 | t0 = tcg_temp_new(); |
e2622073 | 4738 | tcg_gen_extract_tl(t0, cpu_gpr[rB(ctx->opcode)], 28, 4); |
c6c7cf05 | 4739 | gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]); |
74d37793 | 4740 | tcg_temp_free(t0); |
9b2fadda | 4741 | #endif /* defined(CONFIG_USER_ONLY) */ |
12de9a39 | 4742 | } |
f6b868fc BS |
4743 | |
4744 | /* slbmte */ | |
e8eaa2c0 | 4745 | static void gen_slbmte(DisasContext *ctx) |
f6b868fc BS |
4746 | { |
4747 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 4748 | GEN_PRIV; |
f6b868fc | 4749 | #else |
9b2fadda BH |
4750 | CHK_SV; |
4751 | ||
c6c7cf05 BS |
4752 | gen_helper_store_slb(cpu_env, cpu_gpr[rB(ctx->opcode)], |
4753 | cpu_gpr[rS(ctx->opcode)]); | |
9b2fadda | 4754 | #endif /* defined(CONFIG_USER_ONLY) */ |
f6b868fc BS |
4755 | } |
4756 | ||
efdef95f DG |
4757 | static void gen_slbmfee(DisasContext *ctx) |
4758 | { | |
4759 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 4760 | GEN_PRIV; |
efdef95f | 4761 | #else |
9b2fadda BH |
4762 | CHK_SV; |
4763 | ||
c6c7cf05 | 4764 | gen_helper_load_slb_esid(cpu_gpr[rS(ctx->opcode)], cpu_env, |
efdef95f | 4765 | cpu_gpr[rB(ctx->opcode)]); |
9b2fadda | 4766 | #endif /* defined(CONFIG_USER_ONLY) */ |
efdef95f DG |
4767 | } |
4768 | ||
4769 | static void gen_slbmfev(DisasContext *ctx) | |
4770 | { | |
4771 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 4772 | GEN_PRIV; |
efdef95f | 4773 | #else |
9b2fadda BH |
4774 | CHK_SV; |
4775 | ||
c6c7cf05 | 4776 | gen_helper_load_slb_vsid(cpu_gpr[rS(ctx->opcode)], cpu_env, |
efdef95f | 4777 | cpu_gpr[rB(ctx->opcode)]); |
9b2fadda | 4778 | #endif /* defined(CONFIG_USER_ONLY) */ |
efdef95f | 4779 | } |
c76c22d5 BH |
4780 | |
4781 | static void gen_slbfee_(DisasContext *ctx) | |
4782 | { | |
4783 | #if defined(CONFIG_USER_ONLY) | |
4784 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4785 | #else | |
4786 | TCGLabel *l1, *l2; | |
4787 | ||
4788 | if (unlikely(ctx->pr)) { | |
4789 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4790 | return; | |
4791 | } | |
4792 | gen_helper_find_slb_vsid(cpu_gpr[rS(ctx->opcode)], cpu_env, | |
4793 | cpu_gpr[rB(ctx->opcode)]); | |
4794 | l1 = gen_new_label(); | |
4795 | l2 = gen_new_label(); | |
4796 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so); | |
4797 | tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rS(ctx->opcode)], -1, l1); | |
efa73196 | 4798 | tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], CRF_EQ); |
c76c22d5 BH |
4799 | tcg_gen_br(l2); |
4800 | gen_set_label(l1); | |
4801 | tcg_gen_movi_tl(cpu_gpr[rS(ctx->opcode)], 0); | |
4802 | gen_set_label(l2); | |
4803 | #endif | |
4804 | } | |
12de9a39 JM |
4805 | #endif /* defined(TARGET_PPC64) */ |
4806 | ||
79aceca5 | 4807 | /*** Lookaside buffer management ***/ |
c47493f2 | 4808 | /* Optional & supervisor only: */ |
99e300ef | 4809 | |
54623277 | 4810 | /* tlbia */ |
99e300ef | 4811 | static void gen_tlbia(DisasContext *ctx) |
79aceca5 | 4812 | { |
9a64fbe4 | 4813 | #if defined(CONFIG_USER_ONLY) |
9b2fadda | 4814 | GEN_PRIV; |
9a64fbe4 | 4815 | #else |
9b2fadda BH |
4816 | CHK_HV; |
4817 | ||
c6c7cf05 | 4818 | gen_helper_tlbia(cpu_env); |
9b2fadda | 4819 | #endif /* defined(CONFIG_USER_ONLY) */ |
79aceca5 FB |
4820 | } |
4821 | ||
bf14b1ce | 4822 | /* tlbiel */ |
99e300ef | 4823 | static void gen_tlbiel(DisasContext *ctx) |
bf14b1ce BS |
4824 | { |
4825 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 4826 | GEN_PRIV; |
bf14b1ce | 4827 | #else |
9b2fadda BH |
4828 | CHK_SV; |
4829 | ||
c6c7cf05 | 4830 | gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
9b2fadda | 4831 | #endif /* defined(CONFIG_USER_ONLY) */ |
bf14b1ce BS |
4832 | } |
4833 | ||
79aceca5 | 4834 | /* tlbie */ |
99e300ef | 4835 | static void gen_tlbie(DisasContext *ctx) |
79aceca5 | 4836 | { |
9a64fbe4 | 4837 | #if defined(CONFIG_USER_ONLY) |
9b2fadda | 4838 | GEN_PRIV; |
9a64fbe4 | 4839 | #else |
d76ab5e1 | 4840 | TCGv_i32 t1; |
c6fd28fd SJS |
4841 | |
4842 | if (ctx->gtse) { | |
91c60f12 | 4843 | CHK_SV; /* If gtse is set then tlbie is supervisor privileged */ |
c6fd28fd SJS |
4844 | } else { |
4845 | CHK_HV; /* Else hypervisor privileged */ | |
4846 | } | |
9b2fadda | 4847 | |
9ca3f7f3 | 4848 | if (NARROW_MODE(ctx)) { |
74d37793 AJ |
4849 | TCGv t0 = tcg_temp_new(); |
4850 | tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]); | |
c6c7cf05 | 4851 | gen_helper_tlbie(cpu_env, t0); |
74d37793 | 4852 | tcg_temp_free(t0); |
9ca3f7f3 | 4853 | } else { |
c6c7cf05 | 4854 | gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
9ca3f7f3 | 4855 | } |
d76ab5e1 ND |
4856 | t1 = tcg_temp_new_i32(); |
4857 | tcg_gen_ld_i32(t1, cpu_env, offsetof(CPUPPCState, tlb_need_flush)); | |
4858 | tcg_gen_ori_i32(t1, t1, TLB_NEED_GLOBAL_FLUSH); | |
4859 | tcg_gen_st_i32(t1, cpu_env, offsetof(CPUPPCState, tlb_need_flush)); | |
4860 | tcg_temp_free_i32(t1); | |
9b2fadda | 4861 | #endif /* defined(CONFIG_USER_ONLY) */ |
79aceca5 FB |
4862 | } |
4863 | ||
4864 | /* tlbsync */ | |
99e300ef | 4865 | static void gen_tlbsync(DisasContext *ctx) |
79aceca5 | 4866 | { |
9a64fbe4 | 4867 | #if defined(CONFIG_USER_ONLY) |
9b2fadda | 4868 | GEN_PRIV; |
9a64fbe4 | 4869 | #else |
91c60f12 CLG |
4870 | |
4871 | if (ctx->gtse) { | |
4872 | CHK_SV; /* If gtse is set then tlbsync is supervisor privileged */ | |
4873 | } else { | |
4874 | CHK_HV; /* Else hypervisor privileged */ | |
4875 | } | |
9b2fadda | 4876 | |
e3cffe6f ND |
4877 | /* BookS does both ptesync and tlbsync make tlbsync a nop for server */ |
4878 | if (ctx->insns_flags & PPC_BOOKE) { | |
4879 | gen_check_tlb_flush(ctx, true); | |
4880 | } | |
9b2fadda | 4881 | #endif /* defined(CONFIG_USER_ONLY) */ |
79aceca5 FB |
4882 | } |
4883 | ||
426613db JM |
4884 | #if defined(TARGET_PPC64) |
4885 | /* slbia */ | |
99e300ef | 4886 | static void gen_slbia(DisasContext *ctx) |
426613db JM |
4887 | { |
4888 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 4889 | GEN_PRIV; |
426613db | 4890 | #else |
9b2fadda BH |
4891 | CHK_SV; |
4892 | ||
c6c7cf05 | 4893 | gen_helper_slbia(cpu_env); |
9b2fadda | 4894 | #endif /* defined(CONFIG_USER_ONLY) */ |
426613db JM |
4895 | } |
4896 | ||
4897 | /* slbie */ | |
99e300ef | 4898 | static void gen_slbie(DisasContext *ctx) |
426613db JM |
4899 | { |
4900 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 4901 | GEN_PRIV; |
426613db | 4902 | #else |
9b2fadda BH |
4903 | CHK_SV; |
4904 | ||
c6c7cf05 | 4905 | gen_helper_slbie(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
9b2fadda | 4906 | #endif /* defined(CONFIG_USER_ONLY) */ |
426613db | 4907 | } |
a63f1dfc ND |
4908 | |
4909 | /* slbieg */ | |
4910 | static void gen_slbieg(DisasContext *ctx) | |
4911 | { | |
4912 | #if defined(CONFIG_USER_ONLY) | |
4913 | GEN_PRIV; | |
4914 | #else | |
4915 | CHK_SV; | |
4916 | ||
4917 | gen_helper_slbieg(cpu_env, cpu_gpr[rB(ctx->opcode)]); | |
4918 | #endif /* defined(CONFIG_USER_ONLY) */ | |
4919 | } | |
4920 | ||
62d897ca ND |
4921 | /* slbsync */ |
4922 | static void gen_slbsync(DisasContext *ctx) | |
4923 | { | |
4924 | #if defined(CONFIG_USER_ONLY) | |
4925 | GEN_PRIV; | |
4926 | #else | |
4927 | CHK_SV; | |
4928 | gen_check_tlb_flush(ctx, true); | |
4929 | #endif /* defined(CONFIG_USER_ONLY) */ | |
4930 | } | |
4931 | ||
9b2fadda | 4932 | #endif /* defined(TARGET_PPC64) */ |
426613db | 4933 | |
79aceca5 FB |
4934 | /*** External control ***/ |
4935 | /* Optional: */ | |
99e300ef | 4936 | |
54623277 | 4937 | /* eciwx */ |
99e300ef | 4938 | static void gen_eciwx(DisasContext *ctx) |
79aceca5 | 4939 | { |
76db3ba4 | 4940 | TCGv t0; |
fa407c03 | 4941 | /* Should check EAR[E] ! */ |
76db3ba4 AJ |
4942 | gen_set_access_type(ctx, ACCESS_EXT); |
4943 | t0 = tcg_temp_new(); | |
4944 | gen_addr_reg_index(ctx, t0); | |
c674a983 RH |
4945 | tcg_gen_qemu_ld_tl(cpu_gpr[rD(ctx->opcode)], t0, ctx->mem_idx, |
4946 | DEF_MEMOP(MO_UL | MO_ALIGN)); | |
fa407c03 | 4947 | tcg_temp_free(t0); |
76a66253 JM |
4948 | } |
4949 | ||
4950 | /* ecowx */ | |
99e300ef | 4951 | static void gen_ecowx(DisasContext *ctx) |
76a66253 | 4952 | { |
76db3ba4 | 4953 | TCGv t0; |
fa407c03 | 4954 | /* Should check EAR[E] ! */ |
76db3ba4 AJ |
4955 | gen_set_access_type(ctx, ACCESS_EXT); |
4956 | t0 = tcg_temp_new(); | |
4957 | gen_addr_reg_index(ctx, t0); | |
c674a983 RH |
4958 | tcg_gen_qemu_st_tl(cpu_gpr[rD(ctx->opcode)], t0, ctx->mem_idx, |
4959 | DEF_MEMOP(MO_UL | MO_ALIGN)); | |
fa407c03 | 4960 | tcg_temp_free(t0); |
76a66253 JM |
4961 | } |
4962 | ||
4963 | /* PowerPC 601 specific instructions */ | |
99e300ef | 4964 | |
54623277 | 4965 | /* abs - abs. */ |
99e300ef | 4966 | static void gen_abs(DisasContext *ctx) |
76a66253 | 4967 | { |
42a268c2 RH |
4968 | TCGLabel *l1 = gen_new_label(); |
4969 | TCGLabel *l2 = gen_new_label(); | |
22e0e173 AJ |
4970 | tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l1); |
4971 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4972 | tcg_gen_br(l2); | |
4973 | gen_set_label(l1); | |
4974 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4975 | gen_set_label(l2); | |
76a66253 | 4976 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4977 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4978 | } |
4979 | ||
4980 | /* abso - abso. */ | |
99e300ef | 4981 | static void gen_abso(DisasContext *ctx) |
76a66253 | 4982 | { |
42a268c2 RH |
4983 | TCGLabel *l1 = gen_new_label(); |
4984 | TCGLabel *l2 = gen_new_label(); | |
4985 | TCGLabel *l3 = gen_new_label(); | |
22e0e173 | 4986 | /* Start with XER OV disabled, the most likely case */ |
da91a00f | 4987 | tcg_gen_movi_tl(cpu_ov, 0); |
22e0e173 AJ |
4988 | tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l2); |
4989 | tcg_gen_brcondi_tl(TCG_COND_NE, cpu_gpr[rA(ctx->opcode)], 0x80000000, l1); | |
da91a00f RH |
4990 | tcg_gen_movi_tl(cpu_ov, 1); |
4991 | tcg_gen_movi_tl(cpu_so, 1); | |
22e0e173 AJ |
4992 | tcg_gen_br(l2); |
4993 | gen_set_label(l1); | |
4994 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4995 | tcg_gen_br(l3); | |
4996 | gen_set_label(l2); | |
4997 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4998 | gen_set_label(l3); | |
76a66253 | 4999 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 5000 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
5001 | } |
5002 | ||
5003 | /* clcs */ | |
99e300ef | 5004 | static void gen_clcs(DisasContext *ctx) |
76a66253 | 5005 | { |
22e0e173 | 5006 | TCGv_i32 t0 = tcg_const_i32(rA(ctx->opcode)); |
d523dd00 | 5007 | gen_helper_clcs(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
22e0e173 | 5008 | tcg_temp_free_i32(t0); |
c7697e1f | 5009 | /* Rc=1 sets CR0 to an undefined state */ |
76a66253 JM |
5010 | } |
5011 | ||
5012 | /* div - div. */ | |
99e300ef | 5013 | static void gen_div(DisasContext *ctx) |
76a66253 | 5014 | { |
d15f74fb BS |
5015 | gen_helper_div(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)], |
5016 | cpu_gpr[rB(ctx->opcode)]); | |
76a66253 | 5017 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 5018 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
5019 | } |
5020 | ||
5021 | /* divo - divo. */ | |
99e300ef | 5022 | static void gen_divo(DisasContext *ctx) |
76a66253 | 5023 | { |
d15f74fb BS |
5024 | gen_helper_divo(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)], |
5025 | cpu_gpr[rB(ctx->opcode)]); | |
76a66253 | 5026 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 5027 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
5028 | } |
5029 | ||
5030 | /* divs - divs. */ | |
99e300ef | 5031 | static void gen_divs(DisasContext *ctx) |
76a66253 | 5032 | { |
d15f74fb BS |
5033 | gen_helper_divs(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)], |
5034 | cpu_gpr[rB(ctx->opcode)]); | |
76a66253 | 5035 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 5036 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
5037 | } |
5038 | ||
5039 | /* divso - divso. */ | |
99e300ef | 5040 | static void gen_divso(DisasContext *ctx) |
76a66253 | 5041 | { |
d15f74fb BS |
5042 | gen_helper_divso(cpu_gpr[rD(ctx->opcode)], cpu_env, |
5043 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
76a66253 | 5044 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 5045 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
5046 | } |
5047 | ||
5048 | /* doz - doz. */ | |
99e300ef | 5049 | static void gen_doz(DisasContext *ctx) |
76a66253 | 5050 | { |
42a268c2 RH |
5051 | TCGLabel *l1 = gen_new_label(); |
5052 | TCGLabel *l2 = gen_new_label(); | |
22e0e173 AJ |
5053 | tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1); |
5054 | tcg_gen_sub_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
5055 | tcg_gen_br(l2); | |
5056 | gen_set_label(l1); | |
5057 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0); | |
5058 | gen_set_label(l2); | |
76a66253 | 5059 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 5060 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
5061 | } |
5062 | ||
5063 | /* dozo - dozo. */ | |
99e300ef | 5064 | static void gen_dozo(DisasContext *ctx) |
76a66253 | 5065 | { |
42a268c2 RH |
5066 | TCGLabel *l1 = gen_new_label(); |
5067 | TCGLabel *l2 = gen_new_label(); | |
22e0e173 AJ |
5068 | TCGv t0 = tcg_temp_new(); |
5069 | TCGv t1 = tcg_temp_new(); | |
5070 | TCGv t2 = tcg_temp_new(); | |
5071 | /* Start with XER OV disabled, the most likely case */ | |
da91a00f | 5072 | tcg_gen_movi_tl(cpu_ov, 0); |
22e0e173 AJ |
5073 | tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1); |
5074 | tcg_gen_sub_tl(t0, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
5075 | tcg_gen_xor_tl(t1, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
5076 | tcg_gen_xor_tl(t2, cpu_gpr[rA(ctx->opcode)], t0); | |
5077 | tcg_gen_andc_tl(t1, t1, t2); | |
5078 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
5079 | tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2); | |
da91a00f RH |
5080 | tcg_gen_movi_tl(cpu_ov, 1); |
5081 | tcg_gen_movi_tl(cpu_so, 1); | |
22e0e173 AJ |
5082 | tcg_gen_br(l2); |
5083 | gen_set_label(l1); | |
5084 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0); | |
5085 | gen_set_label(l2); | |
5086 | tcg_temp_free(t0); | |
5087 | tcg_temp_free(t1); | |
5088 | tcg_temp_free(t2); | |
76a66253 | 5089 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 5090 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
5091 | } |
5092 | ||
5093 | /* dozi */ | |
99e300ef | 5094 | static void gen_dozi(DisasContext *ctx) |
76a66253 | 5095 | { |
22e0e173 | 5096 | target_long simm = SIMM(ctx->opcode); |
42a268c2 RH |
5097 | TCGLabel *l1 = gen_new_label(); |
5098 | TCGLabel *l2 = gen_new_label(); | |
22e0e173 AJ |
5099 | tcg_gen_brcondi_tl(TCG_COND_LT, cpu_gpr[rA(ctx->opcode)], simm, l1); |
5100 | tcg_gen_subfi_tl(cpu_gpr[rD(ctx->opcode)], simm, cpu_gpr[rA(ctx->opcode)]); | |
5101 | tcg_gen_br(l2); | |
5102 | gen_set_label(l1); | |
5103 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0); | |
5104 | gen_set_label(l2); | |
5105 | if (unlikely(Rc(ctx->opcode) != 0)) | |
5106 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
76a66253 JM |
5107 | } |
5108 | ||
76a66253 | 5109 | /* lscbx - lscbx. */ |
99e300ef | 5110 | static void gen_lscbx(DisasContext *ctx) |
76a66253 | 5111 | { |
bdb4b689 AJ |
5112 | TCGv t0 = tcg_temp_new(); |
5113 | TCGv_i32 t1 = tcg_const_i32(rD(ctx->opcode)); | |
5114 | TCGv_i32 t2 = tcg_const_i32(rA(ctx->opcode)); | |
5115 | TCGv_i32 t3 = tcg_const_i32(rB(ctx->opcode)); | |
76a66253 | 5116 | |
76db3ba4 | 5117 | gen_addr_reg_index(ctx, t0); |
2f5a189c | 5118 | gen_helper_lscbx(t0, cpu_env, t0, t1, t2, t3); |
bdb4b689 AJ |
5119 | tcg_temp_free_i32(t1); |
5120 | tcg_temp_free_i32(t2); | |
5121 | tcg_temp_free_i32(t3); | |
3d7b417e | 5122 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F); |
bdb4b689 | 5123 | tcg_gen_or_tl(cpu_xer, cpu_xer, t0); |
76a66253 | 5124 | if (unlikely(Rc(ctx->opcode) != 0)) |
bdb4b689 AJ |
5125 | gen_set_Rc0(ctx, t0); |
5126 | tcg_temp_free(t0); | |
76a66253 JM |
5127 | } |
5128 | ||
5129 | /* maskg - maskg. */ | |
99e300ef | 5130 | static void gen_maskg(DisasContext *ctx) |
76a66253 | 5131 | { |
42a268c2 | 5132 | TCGLabel *l1 = gen_new_label(); |
22e0e173 AJ |
5133 | TCGv t0 = tcg_temp_new(); |
5134 | TCGv t1 = tcg_temp_new(); | |
5135 | TCGv t2 = tcg_temp_new(); | |
5136 | TCGv t3 = tcg_temp_new(); | |
5137 | tcg_gen_movi_tl(t3, 0xFFFFFFFF); | |
5138 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5139 | tcg_gen_andi_tl(t1, cpu_gpr[rS(ctx->opcode)], 0x1F); | |
5140 | tcg_gen_addi_tl(t2, t0, 1); | |
5141 | tcg_gen_shr_tl(t2, t3, t2); | |
5142 | tcg_gen_shr_tl(t3, t3, t1); | |
5143 | tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], t2, t3); | |
5144 | tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1); | |
5145 | tcg_gen_neg_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
5146 | gen_set_label(l1); | |
5147 | tcg_temp_free(t0); | |
5148 | tcg_temp_free(t1); | |
5149 | tcg_temp_free(t2); | |
5150 | tcg_temp_free(t3); | |
76a66253 | 5151 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 5152 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5153 | } |
5154 | ||
5155 | /* maskir - maskir. */ | |
99e300ef | 5156 | static void gen_maskir(DisasContext *ctx) |
76a66253 | 5157 | { |
22e0e173 AJ |
5158 | TCGv t0 = tcg_temp_new(); |
5159 | TCGv t1 = tcg_temp_new(); | |
5160 | tcg_gen_and_tl(t0, cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
5161 | tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
5162 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5163 | tcg_temp_free(t0); | |
5164 | tcg_temp_free(t1); | |
76a66253 | 5165 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 5166 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5167 | } |
5168 | ||
5169 | /* mul - mul. */ | |
99e300ef | 5170 | static void gen_mul(DisasContext *ctx) |
76a66253 | 5171 | { |
22e0e173 AJ |
5172 | TCGv_i64 t0 = tcg_temp_new_i64(); |
5173 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
5174 | TCGv t2 = tcg_temp_new(); | |
5175 | tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
5176 | tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
5177 | tcg_gen_mul_i64(t0, t0, t1); | |
5178 | tcg_gen_trunc_i64_tl(t2, t0); | |
5179 | gen_store_spr(SPR_MQ, t2); | |
5180 | tcg_gen_shri_i64(t1, t0, 32); | |
5181 | tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1); | |
5182 | tcg_temp_free_i64(t0); | |
5183 | tcg_temp_free_i64(t1); | |
5184 | tcg_temp_free(t2); | |
76a66253 | 5185 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 5186 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
5187 | } |
5188 | ||
5189 | /* mulo - mulo. */ | |
99e300ef | 5190 | static void gen_mulo(DisasContext *ctx) |
76a66253 | 5191 | { |
42a268c2 | 5192 | TCGLabel *l1 = gen_new_label(); |
22e0e173 AJ |
5193 | TCGv_i64 t0 = tcg_temp_new_i64(); |
5194 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
5195 | TCGv t2 = tcg_temp_new(); | |
5196 | /* Start with XER OV disabled, the most likely case */ | |
da91a00f | 5197 | tcg_gen_movi_tl(cpu_ov, 0); |
22e0e173 AJ |
5198 | tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); |
5199 | tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
5200 | tcg_gen_mul_i64(t0, t0, t1); | |
5201 | tcg_gen_trunc_i64_tl(t2, t0); | |
5202 | gen_store_spr(SPR_MQ, t2); | |
5203 | tcg_gen_shri_i64(t1, t0, 32); | |
5204 | tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1); | |
5205 | tcg_gen_ext32s_i64(t1, t0); | |
5206 | tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1); | |
da91a00f RH |
5207 | tcg_gen_movi_tl(cpu_ov, 1); |
5208 | tcg_gen_movi_tl(cpu_so, 1); | |
22e0e173 AJ |
5209 | gen_set_label(l1); |
5210 | tcg_temp_free_i64(t0); | |
5211 | tcg_temp_free_i64(t1); | |
5212 | tcg_temp_free(t2); | |
76a66253 | 5213 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 5214 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
5215 | } |
5216 | ||
5217 | /* nabs - nabs. */ | |
99e300ef | 5218 | static void gen_nabs(DisasContext *ctx) |
76a66253 | 5219 | { |
42a268c2 RH |
5220 | TCGLabel *l1 = gen_new_label(); |
5221 | TCGLabel *l2 = gen_new_label(); | |
22e0e173 AJ |
5222 | tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1); |
5223 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
5224 | tcg_gen_br(l2); | |
5225 | gen_set_label(l1); | |
5226 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
5227 | gen_set_label(l2); | |
76a66253 | 5228 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 5229 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
5230 | } |
5231 | ||
5232 | /* nabso - nabso. */ | |
99e300ef | 5233 | static void gen_nabso(DisasContext *ctx) |
76a66253 | 5234 | { |
42a268c2 RH |
5235 | TCGLabel *l1 = gen_new_label(); |
5236 | TCGLabel *l2 = gen_new_label(); | |
22e0e173 AJ |
5237 | tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1); |
5238 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
5239 | tcg_gen_br(l2); | |
5240 | gen_set_label(l1); | |
5241 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
5242 | gen_set_label(l2); | |
5243 | /* nabs never overflows */ | |
da91a00f | 5244 | tcg_gen_movi_tl(cpu_ov, 0); |
76a66253 | 5245 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 5246 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
5247 | } |
5248 | ||
5249 | /* rlmi - rlmi. */ | |
99e300ef | 5250 | static void gen_rlmi(DisasContext *ctx) |
76a66253 | 5251 | { |
7487953d AJ |
5252 | uint32_t mb = MB(ctx->opcode); |
5253 | uint32_t me = ME(ctx->opcode); | |
5254 | TCGv t0 = tcg_temp_new(); | |
5255 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5256 | tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
5257 | tcg_gen_andi_tl(t0, t0, MASK(mb, me)); | |
5258 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~MASK(mb, me)); | |
5259 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], t0); | |
5260 | tcg_temp_free(t0); | |
76a66253 | 5261 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5262 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5263 | } |
5264 | ||
5265 | /* rrib - rrib. */ | |
99e300ef | 5266 | static void gen_rrib(DisasContext *ctx) |
76a66253 | 5267 | { |
7487953d AJ |
5268 | TCGv t0 = tcg_temp_new(); |
5269 | TCGv t1 = tcg_temp_new(); | |
5270 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5271 | tcg_gen_movi_tl(t1, 0x80000000); | |
5272 | tcg_gen_shr_tl(t1, t1, t0); | |
5273 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
5274 | tcg_gen_and_tl(t0, t0, t1); | |
5275 | tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], t1); | |
5276 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5277 | tcg_temp_free(t0); | |
5278 | tcg_temp_free(t1); | |
76a66253 | 5279 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5280 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5281 | } |
5282 | ||
5283 | /* sle - sle. */ | |
99e300ef | 5284 | static void gen_sle(DisasContext *ctx) |
76a66253 | 5285 | { |
7487953d AJ |
5286 | TCGv t0 = tcg_temp_new(); |
5287 | TCGv t1 = tcg_temp_new(); | |
5288 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5289 | tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
5290 | tcg_gen_subfi_tl(t1, 32, t1); | |
5291 | tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
5292 | tcg_gen_or_tl(t1, t0, t1); | |
5293 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5294 | gen_store_spr(SPR_MQ, t1); | |
5295 | tcg_temp_free(t0); | |
5296 | tcg_temp_free(t1); | |
76a66253 | 5297 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5298 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5299 | } |
5300 | ||
5301 | /* sleq - sleq. */ | |
99e300ef | 5302 | static void gen_sleq(DisasContext *ctx) |
76a66253 | 5303 | { |
7487953d AJ |
5304 | TCGv t0 = tcg_temp_new(); |
5305 | TCGv t1 = tcg_temp_new(); | |
5306 | TCGv t2 = tcg_temp_new(); | |
5307 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5308 | tcg_gen_movi_tl(t2, 0xFFFFFFFF); | |
5309 | tcg_gen_shl_tl(t2, t2, t0); | |
5310 | tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
5311 | gen_load_spr(t1, SPR_MQ); | |
5312 | gen_store_spr(SPR_MQ, t0); | |
5313 | tcg_gen_and_tl(t0, t0, t2); | |
5314 | tcg_gen_andc_tl(t1, t1, t2); | |
5315 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5316 | tcg_temp_free(t0); | |
5317 | tcg_temp_free(t1); | |
5318 | tcg_temp_free(t2); | |
76a66253 | 5319 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5320 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5321 | } |
5322 | ||
5323 | /* sliq - sliq. */ | |
99e300ef | 5324 | static void gen_sliq(DisasContext *ctx) |
76a66253 | 5325 | { |
7487953d AJ |
5326 | int sh = SH(ctx->opcode); |
5327 | TCGv t0 = tcg_temp_new(); | |
5328 | TCGv t1 = tcg_temp_new(); | |
5329 | tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
5330 | tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh); | |
5331 | tcg_gen_or_tl(t1, t0, t1); | |
5332 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5333 | gen_store_spr(SPR_MQ, t1); | |
5334 | tcg_temp_free(t0); | |
5335 | tcg_temp_free(t1); | |
76a66253 | 5336 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5337 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5338 | } |
5339 | ||
5340 | /* slliq - slliq. */ | |
99e300ef | 5341 | static void gen_slliq(DisasContext *ctx) |
76a66253 | 5342 | { |
7487953d AJ |
5343 | int sh = SH(ctx->opcode); |
5344 | TCGv t0 = tcg_temp_new(); | |
5345 | TCGv t1 = tcg_temp_new(); | |
5346 | tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
5347 | gen_load_spr(t1, SPR_MQ); | |
5348 | gen_store_spr(SPR_MQ, t0); | |
5349 | tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU << sh)); | |
5350 | tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU << sh)); | |
5351 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5352 | tcg_temp_free(t0); | |
5353 | tcg_temp_free(t1); | |
76a66253 | 5354 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5355 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5356 | } |
5357 | ||
5358 | /* sllq - sllq. */ | |
99e300ef | 5359 | static void gen_sllq(DisasContext *ctx) |
76a66253 | 5360 | { |
42a268c2 RH |
5361 | TCGLabel *l1 = gen_new_label(); |
5362 | TCGLabel *l2 = gen_new_label(); | |
7487953d AJ |
5363 | TCGv t0 = tcg_temp_local_new(); |
5364 | TCGv t1 = tcg_temp_local_new(); | |
5365 | TCGv t2 = tcg_temp_local_new(); | |
5366 | tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5367 | tcg_gen_movi_tl(t1, 0xFFFFFFFF); | |
5368 | tcg_gen_shl_tl(t1, t1, t2); | |
5369 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20); | |
5370 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
5371 | gen_load_spr(t0, SPR_MQ); | |
5372 | tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5373 | tcg_gen_br(l2); | |
5374 | gen_set_label(l1); | |
5375 | tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t2); | |
5376 | gen_load_spr(t2, SPR_MQ); | |
5377 | tcg_gen_andc_tl(t1, t2, t1); | |
5378 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5379 | gen_set_label(l2); | |
5380 | tcg_temp_free(t0); | |
5381 | tcg_temp_free(t1); | |
5382 | tcg_temp_free(t2); | |
76a66253 | 5383 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5384 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5385 | } |
5386 | ||
5387 | /* slq - slq. */ | |
99e300ef | 5388 | static void gen_slq(DisasContext *ctx) |
76a66253 | 5389 | { |
42a268c2 | 5390 | TCGLabel *l1 = gen_new_label(); |
7487953d AJ |
5391 | TCGv t0 = tcg_temp_new(); |
5392 | TCGv t1 = tcg_temp_new(); | |
5393 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5394 | tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
5395 | tcg_gen_subfi_tl(t1, 32, t1); | |
5396 | tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
5397 | tcg_gen_or_tl(t1, t0, t1); | |
5398 | gen_store_spr(SPR_MQ, t1); | |
5399 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20); | |
5400 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5401 | tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1); | |
5402 | tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0); | |
5403 | gen_set_label(l1); | |
5404 | tcg_temp_free(t0); | |
5405 | tcg_temp_free(t1); | |
76a66253 | 5406 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5407 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5408 | } |
5409 | ||
d9bce9d9 | 5410 | /* sraiq - sraiq. */ |
99e300ef | 5411 | static void gen_sraiq(DisasContext *ctx) |
76a66253 | 5412 | { |
7487953d | 5413 | int sh = SH(ctx->opcode); |
42a268c2 | 5414 | TCGLabel *l1 = gen_new_label(); |
7487953d AJ |
5415 | TCGv t0 = tcg_temp_new(); |
5416 | TCGv t1 = tcg_temp_new(); | |
5417 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
5418 | tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh); | |
5419 | tcg_gen_or_tl(t0, t0, t1); | |
5420 | gen_store_spr(SPR_MQ, t0); | |
da91a00f | 5421 | tcg_gen_movi_tl(cpu_ca, 0); |
7487953d AJ |
5422 | tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1); |
5423 | tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1); | |
da91a00f | 5424 | tcg_gen_movi_tl(cpu_ca, 1); |
7487953d AJ |
5425 | gen_set_label(l1); |
5426 | tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh); | |
5427 | tcg_temp_free(t0); | |
5428 | tcg_temp_free(t1); | |
76a66253 | 5429 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5430 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5431 | } |
5432 | ||
5433 | /* sraq - sraq. */ | |
99e300ef | 5434 | static void gen_sraq(DisasContext *ctx) |
76a66253 | 5435 | { |
42a268c2 RH |
5436 | TCGLabel *l1 = gen_new_label(); |
5437 | TCGLabel *l2 = gen_new_label(); | |
7487953d AJ |
5438 | TCGv t0 = tcg_temp_new(); |
5439 | TCGv t1 = tcg_temp_local_new(); | |
5440 | TCGv t2 = tcg_temp_local_new(); | |
5441 | tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5442 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2); | |
5443 | tcg_gen_sar_tl(t1, cpu_gpr[rS(ctx->opcode)], t2); | |
5444 | tcg_gen_subfi_tl(t2, 32, t2); | |
5445 | tcg_gen_shl_tl(t2, cpu_gpr[rS(ctx->opcode)], t2); | |
5446 | tcg_gen_or_tl(t0, t0, t2); | |
5447 | gen_store_spr(SPR_MQ, t0); | |
5448 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20); | |
5449 | tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l1); | |
5450 | tcg_gen_mov_tl(t2, cpu_gpr[rS(ctx->opcode)]); | |
5451 | tcg_gen_sari_tl(t1, cpu_gpr[rS(ctx->opcode)], 31); | |
5452 | gen_set_label(l1); | |
5453 | tcg_temp_free(t0); | |
5454 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t1); | |
da91a00f | 5455 | tcg_gen_movi_tl(cpu_ca, 0); |
7487953d AJ |
5456 | tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2); |
5457 | tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l2); | |
da91a00f | 5458 | tcg_gen_movi_tl(cpu_ca, 1); |
7487953d AJ |
5459 | gen_set_label(l2); |
5460 | tcg_temp_free(t1); | |
5461 | tcg_temp_free(t2); | |
76a66253 | 5462 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5463 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5464 | } |
5465 | ||
5466 | /* sre - sre. */ | |
99e300ef | 5467 | static void gen_sre(DisasContext *ctx) |
76a66253 | 5468 | { |
7487953d AJ |
5469 | TCGv t0 = tcg_temp_new(); |
5470 | TCGv t1 = tcg_temp_new(); | |
5471 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5472 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
5473 | tcg_gen_subfi_tl(t1, 32, t1); | |
5474 | tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
5475 | tcg_gen_or_tl(t1, t0, t1); | |
5476 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5477 | gen_store_spr(SPR_MQ, t1); | |
5478 | tcg_temp_free(t0); | |
5479 | tcg_temp_free(t1); | |
76a66253 | 5480 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5481 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5482 | } |
5483 | ||
5484 | /* srea - srea. */ | |
99e300ef | 5485 | static void gen_srea(DisasContext *ctx) |
76a66253 | 5486 | { |
7487953d AJ |
5487 | TCGv t0 = tcg_temp_new(); |
5488 | TCGv t1 = tcg_temp_new(); | |
5489 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5490 | tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
5491 | gen_store_spr(SPR_MQ, t0); | |
5492 | tcg_gen_sar_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t1); | |
5493 | tcg_temp_free(t0); | |
5494 | tcg_temp_free(t1); | |
76a66253 | 5495 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5496 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5497 | } |
5498 | ||
5499 | /* sreq */ | |
99e300ef | 5500 | static void gen_sreq(DisasContext *ctx) |
76a66253 | 5501 | { |
7487953d AJ |
5502 | TCGv t0 = tcg_temp_new(); |
5503 | TCGv t1 = tcg_temp_new(); | |
5504 | TCGv t2 = tcg_temp_new(); | |
5505 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5506 | tcg_gen_movi_tl(t1, 0xFFFFFFFF); | |
5507 | tcg_gen_shr_tl(t1, t1, t0); | |
5508 | tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
5509 | gen_load_spr(t2, SPR_MQ); | |
5510 | gen_store_spr(SPR_MQ, t0); | |
5511 | tcg_gen_and_tl(t0, t0, t1); | |
5512 | tcg_gen_andc_tl(t2, t2, t1); | |
5513 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t2); | |
5514 | tcg_temp_free(t0); | |
5515 | tcg_temp_free(t1); | |
5516 | tcg_temp_free(t2); | |
76a66253 | 5517 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5518 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5519 | } |
5520 | ||
5521 | /* sriq */ | |
99e300ef | 5522 | static void gen_sriq(DisasContext *ctx) |
76a66253 | 5523 | { |
7487953d AJ |
5524 | int sh = SH(ctx->opcode); |
5525 | TCGv t0 = tcg_temp_new(); | |
5526 | TCGv t1 = tcg_temp_new(); | |
5527 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
5528 | tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh); | |
5529 | tcg_gen_or_tl(t1, t0, t1); | |
5530 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5531 | gen_store_spr(SPR_MQ, t1); | |
5532 | tcg_temp_free(t0); | |
5533 | tcg_temp_free(t1); | |
76a66253 | 5534 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5535 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5536 | } |
5537 | ||
5538 | /* srliq */ | |
99e300ef | 5539 | static void gen_srliq(DisasContext *ctx) |
76a66253 | 5540 | { |
7487953d AJ |
5541 | int sh = SH(ctx->opcode); |
5542 | TCGv t0 = tcg_temp_new(); | |
5543 | TCGv t1 = tcg_temp_new(); | |
5544 | tcg_gen_rotri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
5545 | gen_load_spr(t1, SPR_MQ); | |
5546 | gen_store_spr(SPR_MQ, t0); | |
5547 | tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU >> sh)); | |
5548 | tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU >> sh)); | |
5549 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5550 | tcg_temp_free(t0); | |
5551 | tcg_temp_free(t1); | |
76a66253 | 5552 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5553 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5554 | } |
5555 | ||
5556 | /* srlq */ | |
99e300ef | 5557 | static void gen_srlq(DisasContext *ctx) |
76a66253 | 5558 | { |
42a268c2 RH |
5559 | TCGLabel *l1 = gen_new_label(); |
5560 | TCGLabel *l2 = gen_new_label(); | |
7487953d AJ |
5561 | TCGv t0 = tcg_temp_local_new(); |
5562 | TCGv t1 = tcg_temp_local_new(); | |
5563 | TCGv t2 = tcg_temp_local_new(); | |
5564 | tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5565 | tcg_gen_movi_tl(t1, 0xFFFFFFFF); | |
5566 | tcg_gen_shr_tl(t2, t1, t2); | |
5567 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20); | |
5568 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
5569 | gen_load_spr(t0, SPR_MQ); | |
5570 | tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t2); | |
5571 | tcg_gen_br(l2); | |
5572 | gen_set_label(l1); | |
5573 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2); | |
5574 | tcg_gen_and_tl(t0, t0, t2); | |
5575 | gen_load_spr(t1, SPR_MQ); | |
5576 | tcg_gen_andc_tl(t1, t1, t2); | |
5577 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5578 | gen_set_label(l2); | |
5579 | tcg_temp_free(t0); | |
5580 | tcg_temp_free(t1); | |
5581 | tcg_temp_free(t2); | |
76a66253 | 5582 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5583 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5584 | } |
5585 | ||
5586 | /* srq */ | |
99e300ef | 5587 | static void gen_srq(DisasContext *ctx) |
76a66253 | 5588 | { |
42a268c2 | 5589 | TCGLabel *l1 = gen_new_label(); |
7487953d AJ |
5590 | TCGv t0 = tcg_temp_new(); |
5591 | TCGv t1 = tcg_temp_new(); | |
5592 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5593 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
5594 | tcg_gen_subfi_tl(t1, 32, t1); | |
5595 | tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
5596 | tcg_gen_or_tl(t1, t0, t1); | |
5597 | gen_store_spr(SPR_MQ, t1); | |
5598 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20); | |
5599 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5600 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
5601 | tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0); | |
5602 | gen_set_label(l1); | |
5603 | tcg_temp_free(t0); | |
5604 | tcg_temp_free(t1); | |
76a66253 | 5605 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5606 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5607 | } |
5608 | ||
5609 | /* PowerPC 602 specific instructions */ | |
99e300ef | 5610 | |
54623277 | 5611 | /* dsa */ |
99e300ef | 5612 | static void gen_dsa(DisasContext *ctx) |
76a66253 JM |
5613 | { |
5614 | /* XXX: TODO */ | |
e06fcd75 | 5615 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 JM |
5616 | } |
5617 | ||
5618 | /* esa */ | |
99e300ef | 5619 | static void gen_esa(DisasContext *ctx) |
76a66253 JM |
5620 | { |
5621 | /* XXX: TODO */ | |
e06fcd75 | 5622 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 JM |
5623 | } |
5624 | ||
5625 | /* mfrom */ | |
99e300ef | 5626 | static void gen_mfrom(DisasContext *ctx) |
76a66253 JM |
5627 | { |
5628 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 5629 | GEN_PRIV; |
76a66253 | 5630 | #else |
9b2fadda | 5631 | CHK_SV; |
cf02a65c | 5632 | gen_helper_602_mfrom(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
9b2fadda | 5633 | #endif /* defined(CONFIG_USER_ONLY) */ |
76a66253 JM |
5634 | } |
5635 | ||
5636 | /* 602 - 603 - G2 TLB management */ | |
e8eaa2c0 | 5637 | |
54623277 | 5638 | /* tlbld */ |
e8eaa2c0 | 5639 | static void gen_tlbld_6xx(DisasContext *ctx) |
76a66253 JM |
5640 | { |
5641 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 5642 | GEN_PRIV; |
76a66253 | 5643 | #else |
9b2fadda | 5644 | CHK_SV; |
c6c7cf05 | 5645 | gen_helper_6xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
9b2fadda | 5646 | #endif /* defined(CONFIG_USER_ONLY) */ |
76a66253 JM |
5647 | } |
5648 | ||
5649 | /* tlbli */ | |
e8eaa2c0 | 5650 | static void gen_tlbli_6xx(DisasContext *ctx) |
76a66253 JM |
5651 | { |
5652 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 5653 | GEN_PRIV; |
76a66253 | 5654 | #else |
9b2fadda | 5655 | CHK_SV; |
c6c7cf05 | 5656 | gen_helper_6xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
9b2fadda | 5657 | #endif /* defined(CONFIG_USER_ONLY) */ |
76a66253 JM |
5658 | } |
5659 | ||
7dbe11ac | 5660 | /* 74xx TLB management */ |
e8eaa2c0 | 5661 | |
54623277 | 5662 | /* tlbld */ |
e8eaa2c0 | 5663 | static void gen_tlbld_74xx(DisasContext *ctx) |
7dbe11ac JM |
5664 | { |
5665 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 5666 | GEN_PRIV; |
7dbe11ac | 5667 | #else |
9b2fadda | 5668 | CHK_SV; |
c6c7cf05 | 5669 | gen_helper_74xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
9b2fadda | 5670 | #endif /* defined(CONFIG_USER_ONLY) */ |
7dbe11ac JM |
5671 | } |
5672 | ||
5673 | /* tlbli */ | |
e8eaa2c0 | 5674 | static void gen_tlbli_74xx(DisasContext *ctx) |
7dbe11ac JM |
5675 | { |
5676 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 5677 | GEN_PRIV; |
7dbe11ac | 5678 | #else |
9b2fadda | 5679 | CHK_SV; |
c6c7cf05 | 5680 | gen_helper_74xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
9b2fadda | 5681 | #endif /* defined(CONFIG_USER_ONLY) */ |
7dbe11ac JM |
5682 | } |
5683 | ||
76a66253 | 5684 | /* POWER instructions not in PowerPC 601 */ |
99e300ef | 5685 | |
54623277 | 5686 | /* clf */ |
99e300ef | 5687 | static void gen_clf(DisasContext *ctx) |
76a66253 JM |
5688 | { |
5689 | /* Cache line flush: implemented as no-op */ | |
5690 | } | |
5691 | ||
5692 | /* cli */ | |
99e300ef | 5693 | static void gen_cli(DisasContext *ctx) |
76a66253 | 5694 | { |
76a66253 | 5695 | #if defined(CONFIG_USER_ONLY) |
9b2fadda | 5696 | GEN_PRIV; |
76a66253 | 5697 | #else |
9b2fadda BH |
5698 | /* Cache line invalidate: privileged and treated as no-op */ |
5699 | CHK_SV; | |
5700 | #endif /* defined(CONFIG_USER_ONLY) */ | |
76a66253 JM |
5701 | } |
5702 | ||
5703 | /* dclst */ | |
99e300ef | 5704 | static void gen_dclst(DisasContext *ctx) |
76a66253 JM |
5705 | { |
5706 | /* Data cache line store: treated as no-op */ | |
5707 | } | |
5708 | ||
99e300ef | 5709 | static void gen_mfsri(DisasContext *ctx) |
76a66253 JM |
5710 | { |
5711 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 5712 | GEN_PRIV; |
76a66253 | 5713 | #else |
74d37793 AJ |
5714 | int ra = rA(ctx->opcode); |
5715 | int rd = rD(ctx->opcode); | |
5716 | TCGv t0; | |
9b2fadda BH |
5717 | |
5718 | CHK_SV; | |
74d37793 | 5719 | t0 = tcg_temp_new(); |
76db3ba4 | 5720 | gen_addr_reg_index(ctx, t0); |
e2622073 | 5721 | tcg_gen_extract_tl(t0, t0, 28, 4); |
c6c7cf05 | 5722 | gen_helper_load_sr(cpu_gpr[rd], cpu_env, t0); |
74d37793 | 5723 | tcg_temp_free(t0); |
76a66253 | 5724 | if (ra != 0 && ra != rd) |
74d37793 | 5725 | tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rd]); |
9b2fadda | 5726 | #endif /* defined(CONFIG_USER_ONLY) */ |
76a66253 JM |
5727 | } |
5728 | ||
99e300ef | 5729 | static void gen_rac(DisasContext *ctx) |
76a66253 JM |
5730 | { |
5731 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 5732 | GEN_PRIV; |
76a66253 | 5733 | #else |
22e0e173 | 5734 | TCGv t0; |
9b2fadda BH |
5735 | |
5736 | CHK_SV; | |
22e0e173 | 5737 | t0 = tcg_temp_new(); |
76db3ba4 | 5738 | gen_addr_reg_index(ctx, t0); |
c6c7cf05 | 5739 | gen_helper_rac(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
22e0e173 | 5740 | tcg_temp_free(t0); |
9b2fadda | 5741 | #endif /* defined(CONFIG_USER_ONLY) */ |
76a66253 JM |
5742 | } |
5743 | ||
99e300ef | 5744 | static void gen_rfsvc(DisasContext *ctx) |
76a66253 JM |
5745 | { |
5746 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 5747 | GEN_PRIV; |
76a66253 | 5748 | #else |
9b2fadda BH |
5749 | CHK_SV; |
5750 | ||
e5f17ac6 | 5751 | gen_helper_rfsvc(cpu_env); |
e06fcd75 | 5752 | gen_sync_exception(ctx); |
9b2fadda | 5753 | #endif /* defined(CONFIG_USER_ONLY) */ |
76a66253 JM |
5754 | } |
5755 | ||
f9651121 | 5756 | /* svc is not implemented for now */ |
76a66253 JM |
5757 | |
5758 | /* BookE specific instructions */ | |
99e300ef | 5759 | |
54623277 | 5760 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5761 | static void gen_mfapidi(DisasContext *ctx) |
76a66253 JM |
5762 | { |
5763 | /* XXX: TODO */ | |
e06fcd75 | 5764 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 JM |
5765 | } |
5766 | ||
2662a059 | 5767 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5768 | static void gen_tlbiva(DisasContext *ctx) |
76a66253 JM |
5769 | { |
5770 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 5771 | GEN_PRIV; |
76a66253 | 5772 | #else |
74d37793 | 5773 | TCGv t0; |
9b2fadda BH |
5774 | |
5775 | CHK_SV; | |
ec72e276 | 5776 | t0 = tcg_temp_new(); |
76db3ba4 | 5777 | gen_addr_reg_index(ctx, t0); |
4693364f | 5778 | gen_helper_tlbiva(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
74d37793 | 5779 | tcg_temp_free(t0); |
9b2fadda | 5780 | #endif /* defined(CONFIG_USER_ONLY) */ |
76a66253 JM |
5781 | } |
5782 | ||
5783 | /* All 405 MAC instructions are translated here */ | |
636aa200 BS |
5784 | static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3, |
5785 | int ra, int rb, int rt, int Rc) | |
76a66253 | 5786 | { |
182608d4 AJ |
5787 | TCGv t0, t1; |
5788 | ||
a7812ae4 PB |
5789 | t0 = tcg_temp_local_new(); |
5790 | t1 = tcg_temp_local_new(); | |
182608d4 | 5791 | |
76a66253 JM |
5792 | switch (opc3 & 0x0D) { |
5793 | case 0x05: | |
5794 | /* macchw - macchw. - macchwo - macchwo. */ | |
5795 | /* macchws - macchws. - macchwso - macchwso. */ | |
5796 | /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */ | |
5797 | /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */ | |
5798 | /* mulchw - mulchw. */ | |
182608d4 AJ |
5799 | tcg_gen_ext16s_tl(t0, cpu_gpr[ra]); |
5800 | tcg_gen_sari_tl(t1, cpu_gpr[rb], 16); | |
5801 | tcg_gen_ext16s_tl(t1, t1); | |
76a66253 JM |
5802 | break; |
5803 | case 0x04: | |
5804 | /* macchwu - macchwu. - macchwuo - macchwuo. */ | |
5805 | /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */ | |
5806 | /* mulchwu - mulchwu. */ | |
182608d4 AJ |
5807 | tcg_gen_ext16u_tl(t0, cpu_gpr[ra]); |
5808 | tcg_gen_shri_tl(t1, cpu_gpr[rb], 16); | |
5809 | tcg_gen_ext16u_tl(t1, t1); | |
76a66253 JM |
5810 | break; |
5811 | case 0x01: | |
5812 | /* machhw - machhw. - machhwo - machhwo. */ | |
5813 | /* machhws - machhws. - machhwso - machhwso. */ | |
5814 | /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */ | |
5815 | /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */ | |
5816 | /* mulhhw - mulhhw. */ | |
182608d4 AJ |
5817 | tcg_gen_sari_tl(t0, cpu_gpr[ra], 16); |
5818 | tcg_gen_ext16s_tl(t0, t0); | |
5819 | tcg_gen_sari_tl(t1, cpu_gpr[rb], 16); | |
5820 | tcg_gen_ext16s_tl(t1, t1); | |
76a66253 JM |
5821 | break; |
5822 | case 0x00: | |
5823 | /* machhwu - machhwu. - machhwuo - machhwuo. */ | |
5824 | /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */ | |
5825 | /* mulhhwu - mulhhwu. */ | |
182608d4 AJ |
5826 | tcg_gen_shri_tl(t0, cpu_gpr[ra], 16); |
5827 | tcg_gen_ext16u_tl(t0, t0); | |
5828 | tcg_gen_shri_tl(t1, cpu_gpr[rb], 16); | |
5829 | tcg_gen_ext16u_tl(t1, t1); | |
76a66253 JM |
5830 | break; |
5831 | case 0x0D: | |
5832 | /* maclhw - maclhw. - maclhwo - maclhwo. */ | |
5833 | /* maclhws - maclhws. - maclhwso - maclhwso. */ | |
5834 | /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */ | |
5835 | /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */ | |
5836 | /* mullhw - mullhw. */ | |
182608d4 AJ |
5837 | tcg_gen_ext16s_tl(t0, cpu_gpr[ra]); |
5838 | tcg_gen_ext16s_tl(t1, cpu_gpr[rb]); | |
76a66253 JM |
5839 | break; |
5840 | case 0x0C: | |
5841 | /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */ | |
5842 | /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */ | |
5843 | /* mullhwu - mullhwu. */ | |
182608d4 AJ |
5844 | tcg_gen_ext16u_tl(t0, cpu_gpr[ra]); |
5845 | tcg_gen_ext16u_tl(t1, cpu_gpr[rb]); | |
76a66253 JM |
5846 | break; |
5847 | } | |
76a66253 | 5848 | if (opc2 & 0x04) { |
182608d4 AJ |
5849 | /* (n)multiply-and-accumulate (0x0C / 0x0E) */ |
5850 | tcg_gen_mul_tl(t1, t0, t1); | |
5851 | if (opc2 & 0x02) { | |
5852 | /* nmultiply-and-accumulate (0x0E) */ | |
5853 | tcg_gen_sub_tl(t0, cpu_gpr[rt], t1); | |
5854 | } else { | |
5855 | /* multiply-and-accumulate (0x0C) */ | |
5856 | tcg_gen_add_tl(t0, cpu_gpr[rt], t1); | |
5857 | } | |
5858 | ||
5859 | if (opc3 & 0x12) { | |
5860 | /* Check overflow and/or saturate */ | |
42a268c2 | 5861 | TCGLabel *l1 = gen_new_label(); |
182608d4 AJ |
5862 | |
5863 | if (opc3 & 0x10) { | |
5864 | /* Start with XER OV disabled, the most likely case */ | |
da91a00f | 5865 | tcg_gen_movi_tl(cpu_ov, 0); |
182608d4 AJ |
5866 | } |
5867 | if (opc3 & 0x01) { | |
5868 | /* Signed */ | |
5869 | tcg_gen_xor_tl(t1, cpu_gpr[rt], t1); | |
5870 | tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1); | |
5871 | tcg_gen_xor_tl(t1, cpu_gpr[rt], t0); | |
5872 | tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1); | |
bdc4e053 | 5873 | if (opc3 & 0x02) { |
182608d4 AJ |
5874 | /* Saturate */ |
5875 | tcg_gen_sari_tl(t0, cpu_gpr[rt], 31); | |
5876 | tcg_gen_xori_tl(t0, t0, 0x7fffffff); | |
5877 | } | |
5878 | } else { | |
5879 | /* Unsigned */ | |
5880 | tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1); | |
bdc4e053 | 5881 | if (opc3 & 0x02) { |
182608d4 AJ |
5882 | /* Saturate */ |
5883 | tcg_gen_movi_tl(t0, UINT32_MAX); | |
5884 | } | |
5885 | } | |
5886 | if (opc3 & 0x10) { | |
5887 | /* Check overflow */ | |
da91a00f RH |
5888 | tcg_gen_movi_tl(cpu_ov, 1); |
5889 | tcg_gen_movi_tl(cpu_so, 1); | |
182608d4 AJ |
5890 | } |
5891 | gen_set_label(l1); | |
5892 | tcg_gen_mov_tl(cpu_gpr[rt], t0); | |
5893 | } | |
5894 | } else { | |
5895 | tcg_gen_mul_tl(cpu_gpr[rt], t0, t1); | |
76a66253 | 5896 | } |
182608d4 AJ |
5897 | tcg_temp_free(t0); |
5898 | tcg_temp_free(t1); | |
76a66253 JM |
5899 | if (unlikely(Rc) != 0) { |
5900 | /* Update Rc0 */ | |
182608d4 | 5901 | gen_set_Rc0(ctx, cpu_gpr[rt]); |
76a66253 JM |
5902 | } |
5903 | } | |
5904 | ||
a750fc0b | 5905 | #define GEN_MAC_HANDLER(name, opc2, opc3) \ |
99e300ef | 5906 | static void glue(gen_, name)(DisasContext *ctx) \ |
76a66253 JM |
5907 | { \ |
5908 | gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \ | |
5909 | rD(ctx->opcode), Rc(ctx->opcode)); \ | |
5910 | } | |
5911 | ||
5912 | /* macchw - macchw. */ | |
a750fc0b | 5913 | GEN_MAC_HANDLER(macchw, 0x0C, 0x05); |
76a66253 | 5914 | /* macchwo - macchwo. */ |
a750fc0b | 5915 | GEN_MAC_HANDLER(macchwo, 0x0C, 0x15); |
76a66253 | 5916 | /* macchws - macchws. */ |
a750fc0b | 5917 | GEN_MAC_HANDLER(macchws, 0x0C, 0x07); |
76a66253 | 5918 | /* macchwso - macchwso. */ |
a750fc0b | 5919 | GEN_MAC_HANDLER(macchwso, 0x0C, 0x17); |
76a66253 | 5920 | /* macchwsu - macchwsu. */ |
a750fc0b | 5921 | GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06); |
76a66253 | 5922 | /* macchwsuo - macchwsuo. */ |
a750fc0b | 5923 | GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16); |
76a66253 | 5924 | /* macchwu - macchwu. */ |
a750fc0b | 5925 | GEN_MAC_HANDLER(macchwu, 0x0C, 0x04); |
76a66253 | 5926 | /* macchwuo - macchwuo. */ |
a750fc0b | 5927 | GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14); |
76a66253 | 5928 | /* machhw - machhw. */ |
a750fc0b | 5929 | GEN_MAC_HANDLER(machhw, 0x0C, 0x01); |
76a66253 | 5930 | /* machhwo - machhwo. */ |
a750fc0b | 5931 | GEN_MAC_HANDLER(machhwo, 0x0C, 0x11); |
76a66253 | 5932 | /* machhws - machhws. */ |
a750fc0b | 5933 | GEN_MAC_HANDLER(machhws, 0x0C, 0x03); |
76a66253 | 5934 | /* machhwso - machhwso. */ |
a750fc0b | 5935 | GEN_MAC_HANDLER(machhwso, 0x0C, 0x13); |
76a66253 | 5936 | /* machhwsu - machhwsu. */ |
a750fc0b | 5937 | GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02); |
76a66253 | 5938 | /* machhwsuo - machhwsuo. */ |
a750fc0b | 5939 | GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12); |
76a66253 | 5940 | /* machhwu - machhwu. */ |
a750fc0b | 5941 | GEN_MAC_HANDLER(machhwu, 0x0C, 0x00); |
76a66253 | 5942 | /* machhwuo - machhwuo. */ |
a750fc0b | 5943 | GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10); |
76a66253 | 5944 | /* maclhw - maclhw. */ |
a750fc0b | 5945 | GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D); |
76a66253 | 5946 | /* maclhwo - maclhwo. */ |
a750fc0b | 5947 | GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D); |
76a66253 | 5948 | /* maclhws - maclhws. */ |
a750fc0b | 5949 | GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F); |
76a66253 | 5950 | /* maclhwso - maclhwso. */ |
a750fc0b | 5951 | GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F); |
76a66253 | 5952 | /* maclhwu - maclhwu. */ |
a750fc0b | 5953 | GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C); |
76a66253 | 5954 | /* maclhwuo - maclhwuo. */ |
a750fc0b | 5955 | GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C); |
76a66253 | 5956 | /* maclhwsu - maclhwsu. */ |
a750fc0b | 5957 | GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E); |
76a66253 | 5958 | /* maclhwsuo - maclhwsuo. */ |
a750fc0b | 5959 | GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E); |
76a66253 | 5960 | /* nmacchw - nmacchw. */ |
a750fc0b | 5961 | GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05); |
76a66253 | 5962 | /* nmacchwo - nmacchwo. */ |
a750fc0b | 5963 | GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15); |
76a66253 | 5964 | /* nmacchws - nmacchws. */ |
a750fc0b | 5965 | GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07); |
76a66253 | 5966 | /* nmacchwso - nmacchwso. */ |
a750fc0b | 5967 | GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17); |
76a66253 | 5968 | /* nmachhw - nmachhw. */ |
a750fc0b | 5969 | GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01); |
76a66253 | 5970 | /* nmachhwo - nmachhwo. */ |
a750fc0b | 5971 | GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11); |
76a66253 | 5972 | /* nmachhws - nmachhws. */ |
a750fc0b | 5973 | GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03); |
76a66253 | 5974 | /* nmachhwso - nmachhwso. */ |
a750fc0b | 5975 | GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13); |
76a66253 | 5976 | /* nmaclhw - nmaclhw. */ |
a750fc0b | 5977 | GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D); |
76a66253 | 5978 | /* nmaclhwo - nmaclhwo. */ |
a750fc0b | 5979 | GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D); |
76a66253 | 5980 | /* nmaclhws - nmaclhws. */ |
a750fc0b | 5981 | GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F); |
76a66253 | 5982 | /* nmaclhwso - nmaclhwso. */ |
a750fc0b | 5983 | GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F); |
76a66253 JM |
5984 | |
5985 | /* mulchw - mulchw. */ | |
a750fc0b | 5986 | GEN_MAC_HANDLER(mulchw, 0x08, 0x05); |
76a66253 | 5987 | /* mulchwu - mulchwu. */ |
a750fc0b | 5988 | GEN_MAC_HANDLER(mulchwu, 0x08, 0x04); |
76a66253 | 5989 | /* mulhhw - mulhhw. */ |
a750fc0b | 5990 | GEN_MAC_HANDLER(mulhhw, 0x08, 0x01); |
76a66253 | 5991 | /* mulhhwu - mulhhwu. */ |
a750fc0b | 5992 | GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00); |
76a66253 | 5993 | /* mullhw - mullhw. */ |
a750fc0b | 5994 | GEN_MAC_HANDLER(mullhw, 0x08, 0x0D); |
76a66253 | 5995 | /* mullhwu - mullhwu. */ |
a750fc0b | 5996 | GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C); |
76a66253 JM |
5997 | |
5998 | /* mfdcr */ | |
99e300ef | 5999 | static void gen_mfdcr(DisasContext *ctx) |
76a66253 JM |
6000 | { |
6001 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 6002 | GEN_PRIV; |
76a66253 | 6003 | #else |
06dca6a7 | 6004 | TCGv dcrn; |
9b2fadda BH |
6005 | |
6006 | CHK_SV; | |
06dca6a7 | 6007 | dcrn = tcg_const_tl(SPR(ctx->opcode)); |
d0f1562d | 6008 | gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, dcrn); |
06dca6a7 | 6009 | tcg_temp_free(dcrn); |
9b2fadda | 6010 | #endif /* defined(CONFIG_USER_ONLY) */ |
76a66253 JM |
6011 | } |
6012 | ||
6013 | /* mtdcr */ | |
99e300ef | 6014 | static void gen_mtdcr(DisasContext *ctx) |
76a66253 JM |
6015 | { |
6016 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 6017 | GEN_PRIV; |
76a66253 | 6018 | #else |
06dca6a7 | 6019 | TCGv dcrn; |
9b2fadda BH |
6020 | |
6021 | CHK_SV; | |
06dca6a7 | 6022 | dcrn = tcg_const_tl(SPR(ctx->opcode)); |
d0f1562d | 6023 | gen_helper_store_dcr(cpu_env, dcrn, cpu_gpr[rS(ctx->opcode)]); |
06dca6a7 | 6024 | tcg_temp_free(dcrn); |
9b2fadda | 6025 | #endif /* defined(CONFIG_USER_ONLY) */ |
a42bd6cc JM |
6026 | } |
6027 | ||
6028 | /* mfdcrx */ | |
2662a059 | 6029 | /* XXX: not implemented on 440 ? */ |
99e300ef | 6030 | static void gen_mfdcrx(DisasContext *ctx) |
a42bd6cc JM |
6031 | { |
6032 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 6033 | GEN_PRIV; |
a42bd6cc | 6034 | #else |
9b2fadda | 6035 | CHK_SV; |
d0f1562d BS |
6036 | gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, |
6037 | cpu_gpr[rA(ctx->opcode)]); | |
a750fc0b | 6038 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
9b2fadda | 6039 | #endif /* defined(CONFIG_USER_ONLY) */ |
a42bd6cc JM |
6040 | } |
6041 | ||
6042 | /* mtdcrx */ | |
2662a059 | 6043 | /* XXX: not implemented on 440 ? */ |
99e300ef | 6044 | static void gen_mtdcrx(DisasContext *ctx) |
a42bd6cc JM |
6045 | { |
6046 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 6047 | GEN_PRIV; |
a42bd6cc | 6048 | #else |
9b2fadda | 6049 | CHK_SV; |
d0f1562d BS |
6050 | gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)], |
6051 | cpu_gpr[rS(ctx->opcode)]); | |
a750fc0b | 6052 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
9b2fadda | 6053 | #endif /* defined(CONFIG_USER_ONLY) */ |
76a66253 JM |
6054 | } |
6055 | ||
a750fc0b | 6056 | /* mfdcrux (PPC 460) : user-mode access to DCR */ |
99e300ef | 6057 | static void gen_mfdcrux(DisasContext *ctx) |
a750fc0b | 6058 | { |
d0f1562d BS |
6059 | gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, |
6060 | cpu_gpr[rA(ctx->opcode)]); | |
a750fc0b JM |
6061 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
6062 | } | |
6063 | ||
6064 | /* mtdcrux (PPC 460) : user-mode access to DCR */ | |
99e300ef | 6065 | static void gen_mtdcrux(DisasContext *ctx) |
a750fc0b | 6066 | { |
975e5463 | 6067 | gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)], |
d0f1562d | 6068 | cpu_gpr[rS(ctx->opcode)]); |
a750fc0b JM |
6069 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
6070 | } | |
6071 | ||
76a66253 | 6072 | /* dccci */ |
99e300ef | 6073 | static void gen_dccci(DisasContext *ctx) |
76a66253 | 6074 | { |
9b2fadda | 6075 | CHK_SV; |
76a66253 | 6076 | /* interpreted as no-op */ |
76a66253 JM |
6077 | } |
6078 | ||
6079 | /* dcread */ | |
99e300ef | 6080 | static void gen_dcread(DisasContext *ctx) |
76a66253 JM |
6081 | { |
6082 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 6083 | GEN_PRIV; |
76a66253 | 6084 | #else |
b61f2753 | 6085 | TCGv EA, val; |
9b2fadda BH |
6086 | |
6087 | CHK_SV; | |
76db3ba4 | 6088 | gen_set_access_type(ctx, ACCESS_CACHE); |
a7812ae4 | 6089 | EA = tcg_temp_new(); |
76db3ba4 | 6090 | gen_addr_reg_index(ctx, EA); |
a7812ae4 | 6091 | val = tcg_temp_new(); |
76db3ba4 | 6092 | gen_qemu_ld32u(ctx, val, EA); |
b61f2753 AJ |
6093 | tcg_temp_free(val); |
6094 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA); | |
6095 | tcg_temp_free(EA); | |
9b2fadda | 6096 | #endif /* defined(CONFIG_USER_ONLY) */ |
76a66253 JM |
6097 | } |
6098 | ||
6099 | /* icbt */ | |
e8eaa2c0 | 6100 | static void gen_icbt_40x(DisasContext *ctx) |
76a66253 JM |
6101 | { |
6102 | /* interpreted as no-op */ | |
6103 | /* XXX: specification say this is treated as a load by the MMU | |
6104 | * but does not generate any exception | |
6105 | */ | |
6106 | } | |
6107 | ||
6108 | /* iccci */ | |
99e300ef | 6109 | static void gen_iccci(DisasContext *ctx) |
76a66253 | 6110 | { |
9b2fadda | 6111 | CHK_SV; |
76a66253 | 6112 | /* interpreted as no-op */ |
76a66253 JM |
6113 | } |
6114 | ||
6115 | /* icread */ | |
99e300ef | 6116 | static void gen_icread(DisasContext *ctx) |
76a66253 | 6117 | { |
9b2fadda | 6118 | CHK_SV; |
76a66253 | 6119 | /* interpreted as no-op */ |
76a66253 JM |
6120 | } |
6121 | ||
c47493f2 | 6122 | /* rfci (supervisor only) */ |
e8eaa2c0 | 6123 | static void gen_rfci_40x(DisasContext *ctx) |
a42bd6cc JM |
6124 | { |
6125 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 6126 | GEN_PRIV; |
a42bd6cc | 6127 | #else |
9b2fadda | 6128 | CHK_SV; |
a42bd6cc | 6129 | /* Restore CPU state */ |
e5f17ac6 | 6130 | gen_helper_40x_rfci(cpu_env); |
e06fcd75 | 6131 | gen_sync_exception(ctx); |
9b2fadda | 6132 | #endif /* defined(CONFIG_USER_ONLY) */ |
a42bd6cc JM |
6133 | } |
6134 | ||
99e300ef | 6135 | static void gen_rfci(DisasContext *ctx) |
a42bd6cc JM |
6136 | { |
6137 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 6138 | GEN_PRIV; |
a42bd6cc | 6139 | #else |
9b2fadda | 6140 | CHK_SV; |
a42bd6cc | 6141 | /* Restore CPU state */ |
e5f17ac6 | 6142 | gen_helper_rfci(cpu_env); |
e06fcd75 | 6143 | gen_sync_exception(ctx); |
9b2fadda | 6144 | #endif /* defined(CONFIG_USER_ONLY) */ |
a42bd6cc JM |
6145 | } |
6146 | ||
6147 | /* BookE specific */ | |
99e300ef | 6148 | |
54623277 | 6149 | /* XXX: not implemented on 440 ? */ |
99e300ef | 6150 | static void gen_rfdi(DisasContext *ctx) |
76a66253 JM |
6151 | { |
6152 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 6153 | GEN_PRIV; |
76a66253 | 6154 | #else |
9b2fadda | 6155 | CHK_SV; |
76a66253 | 6156 | /* Restore CPU state */ |
e5f17ac6 | 6157 | gen_helper_rfdi(cpu_env); |
e06fcd75 | 6158 | gen_sync_exception(ctx); |
9b2fadda | 6159 | #endif /* defined(CONFIG_USER_ONLY) */ |
76a66253 JM |
6160 | } |
6161 | ||
2662a059 | 6162 | /* XXX: not implemented on 440 ? */ |
99e300ef | 6163 | static void gen_rfmci(DisasContext *ctx) |
a42bd6cc JM |
6164 | { |
6165 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 6166 | GEN_PRIV; |
a42bd6cc | 6167 | #else |
9b2fadda | 6168 | CHK_SV; |
a42bd6cc | 6169 | /* Restore CPU state */ |
e5f17ac6 | 6170 | gen_helper_rfmci(cpu_env); |
e06fcd75 | 6171 | gen_sync_exception(ctx); |
9b2fadda | 6172 | #endif /* defined(CONFIG_USER_ONLY) */ |
a42bd6cc | 6173 | } |
5eb7995e | 6174 | |
d9bce9d9 | 6175 | /* TLB management - PowerPC 405 implementation */ |
e8eaa2c0 | 6176 | |
54623277 | 6177 | /* tlbre */ |
e8eaa2c0 | 6178 | static void gen_tlbre_40x(DisasContext *ctx) |
76a66253 JM |
6179 | { |
6180 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 6181 | GEN_PRIV; |
76a66253 | 6182 | #else |
9b2fadda | 6183 | CHK_SV; |
76a66253 JM |
6184 | switch (rB(ctx->opcode)) { |
6185 | case 0: | |
c6c7cf05 BS |
6186 | gen_helper_4xx_tlbre_hi(cpu_gpr[rD(ctx->opcode)], cpu_env, |
6187 | cpu_gpr[rA(ctx->opcode)]); | |
76a66253 JM |
6188 | break; |
6189 | case 1: | |
c6c7cf05 BS |
6190 | gen_helper_4xx_tlbre_lo(cpu_gpr[rD(ctx->opcode)], cpu_env, |
6191 | cpu_gpr[rA(ctx->opcode)]); | |
76a66253 JM |
6192 | break; |
6193 | default: | |
e06fcd75 | 6194 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 | 6195 | break; |
9a64fbe4 | 6196 | } |
9b2fadda | 6197 | #endif /* defined(CONFIG_USER_ONLY) */ |
76a66253 JM |
6198 | } |
6199 | ||
d9bce9d9 | 6200 | /* tlbsx - tlbsx. */ |
e8eaa2c0 | 6201 | static void gen_tlbsx_40x(DisasContext *ctx) |
76a66253 JM |
6202 | { |
6203 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 6204 | GEN_PRIV; |
76a66253 | 6205 | #else |
74d37793 | 6206 | TCGv t0; |
9b2fadda BH |
6207 | |
6208 | CHK_SV; | |
74d37793 | 6209 | t0 = tcg_temp_new(); |
76db3ba4 | 6210 | gen_addr_reg_index(ctx, t0); |
c6c7cf05 | 6211 | gen_helper_4xx_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 AJ |
6212 | tcg_temp_free(t0); |
6213 | if (Rc(ctx->opcode)) { | |
42a268c2 | 6214 | TCGLabel *l1 = gen_new_label(); |
da91a00f | 6215 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so); |
74d37793 AJ |
6216 | tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1); |
6217 | tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02); | |
6218 | gen_set_label(l1); | |
6219 | } | |
9b2fadda | 6220 | #endif /* defined(CONFIG_USER_ONLY) */ |
79aceca5 FB |
6221 | } |
6222 | ||
76a66253 | 6223 | /* tlbwe */ |
e8eaa2c0 | 6224 | static void gen_tlbwe_40x(DisasContext *ctx) |
79aceca5 | 6225 | { |
76a66253 | 6226 | #if defined(CONFIG_USER_ONLY) |
9b2fadda | 6227 | GEN_PRIV; |
76a66253 | 6228 | #else |
9b2fadda BH |
6229 | CHK_SV; |
6230 | ||
76a66253 JM |
6231 | switch (rB(ctx->opcode)) { |
6232 | case 0: | |
c6c7cf05 BS |
6233 | gen_helper_4xx_tlbwe_hi(cpu_env, cpu_gpr[rA(ctx->opcode)], |
6234 | cpu_gpr[rS(ctx->opcode)]); | |
76a66253 JM |
6235 | break; |
6236 | case 1: | |
c6c7cf05 BS |
6237 | gen_helper_4xx_tlbwe_lo(cpu_env, cpu_gpr[rA(ctx->opcode)], |
6238 | cpu_gpr[rS(ctx->opcode)]); | |
76a66253 JM |
6239 | break; |
6240 | default: | |
e06fcd75 | 6241 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 | 6242 | break; |
9a64fbe4 | 6243 | } |
9b2fadda | 6244 | #endif /* defined(CONFIG_USER_ONLY) */ |
76a66253 JM |
6245 | } |
6246 | ||
a4bb6c3e | 6247 | /* TLB management - PowerPC 440 implementation */ |
e8eaa2c0 | 6248 | |
54623277 | 6249 | /* tlbre */ |
e8eaa2c0 | 6250 | static void gen_tlbre_440(DisasContext *ctx) |
5eb7995e JM |
6251 | { |
6252 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 6253 | GEN_PRIV; |
5eb7995e | 6254 | #else |
9b2fadda BH |
6255 | CHK_SV; |
6256 | ||
5eb7995e JM |
6257 | switch (rB(ctx->opcode)) { |
6258 | case 0: | |
5eb7995e | 6259 | case 1: |
5eb7995e | 6260 | case 2: |
74d37793 AJ |
6261 | { |
6262 | TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode)); | |
c6c7cf05 BS |
6263 | gen_helper_440_tlbre(cpu_gpr[rD(ctx->opcode)], cpu_env, |
6264 | t0, cpu_gpr[rA(ctx->opcode)]); | |
74d37793 AJ |
6265 | tcg_temp_free_i32(t0); |
6266 | } | |
5eb7995e JM |
6267 | break; |
6268 | default: | |
e06fcd75 | 6269 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
5eb7995e JM |
6270 | break; |
6271 | } | |
9b2fadda | 6272 | #endif /* defined(CONFIG_USER_ONLY) */ |
5eb7995e JM |
6273 | } |
6274 | ||
6275 | /* tlbsx - tlbsx. */ | |
e8eaa2c0 | 6276 | static void gen_tlbsx_440(DisasContext *ctx) |
5eb7995e JM |
6277 | { |
6278 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 6279 | GEN_PRIV; |
5eb7995e | 6280 | #else |
74d37793 | 6281 | TCGv t0; |
9b2fadda BH |
6282 | |
6283 | CHK_SV; | |
74d37793 | 6284 | t0 = tcg_temp_new(); |
76db3ba4 | 6285 | gen_addr_reg_index(ctx, t0); |
c6c7cf05 | 6286 | gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 AJ |
6287 | tcg_temp_free(t0); |
6288 | if (Rc(ctx->opcode)) { | |
42a268c2 | 6289 | TCGLabel *l1 = gen_new_label(); |
da91a00f | 6290 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so); |
74d37793 AJ |
6291 | tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1); |
6292 | tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02); | |
6293 | gen_set_label(l1); | |
6294 | } | |
9b2fadda | 6295 | #endif /* defined(CONFIG_USER_ONLY) */ |
5eb7995e JM |
6296 | } |
6297 | ||
6298 | /* tlbwe */ | |
e8eaa2c0 | 6299 | static void gen_tlbwe_440(DisasContext *ctx) |
5eb7995e JM |
6300 | { |
6301 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 6302 | GEN_PRIV; |
5eb7995e | 6303 | #else |
9b2fadda | 6304 | CHK_SV; |
5eb7995e JM |
6305 | switch (rB(ctx->opcode)) { |
6306 | case 0: | |
5eb7995e | 6307 | case 1: |
5eb7995e | 6308 | case 2: |
74d37793 AJ |
6309 | { |
6310 | TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode)); | |
c6c7cf05 BS |
6311 | gen_helper_440_tlbwe(cpu_env, t0, cpu_gpr[rA(ctx->opcode)], |
6312 | cpu_gpr[rS(ctx->opcode)]); | |
74d37793 AJ |
6313 | tcg_temp_free_i32(t0); |
6314 | } | |
5eb7995e JM |
6315 | break; |
6316 | default: | |
e06fcd75 | 6317 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
5eb7995e JM |
6318 | break; |
6319 | } | |
9b2fadda | 6320 | #endif /* defined(CONFIG_USER_ONLY) */ |
5eb7995e JM |
6321 | } |
6322 | ||
01662f3e AG |
6323 | /* TLB management - PowerPC BookE 2.06 implementation */ |
6324 | ||
6325 | /* tlbre */ | |
6326 | static void gen_tlbre_booke206(DisasContext *ctx) | |
6327 | { | |
9b2fadda BH |
6328 | #if defined(CONFIG_USER_ONLY) |
6329 | GEN_PRIV; | |
01662f3e | 6330 | #else |
9b2fadda | 6331 | CHK_SV; |
c6c7cf05 | 6332 | gen_helper_booke206_tlbre(cpu_env); |
9b2fadda | 6333 | #endif /* defined(CONFIG_USER_ONLY) */ |
01662f3e AG |
6334 | } |
6335 | ||
6336 | /* tlbsx - tlbsx. */ | |
6337 | static void gen_tlbsx_booke206(DisasContext *ctx) | |
6338 | { | |
6339 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 6340 | GEN_PRIV; |
01662f3e AG |
6341 | #else |
6342 | TCGv t0; | |
01662f3e | 6343 | |
9b2fadda | 6344 | CHK_SV; |
01662f3e AG |
6345 | if (rA(ctx->opcode)) { |
6346 | t0 = tcg_temp_new(); | |
6347 | tcg_gen_mov_tl(t0, cpu_gpr[rD(ctx->opcode)]); | |
6348 | } else { | |
6349 | t0 = tcg_const_tl(0); | |
6350 | } | |
6351 | ||
6352 | tcg_gen_add_tl(t0, t0, cpu_gpr[rB(ctx->opcode)]); | |
c6c7cf05 | 6353 | gen_helper_booke206_tlbsx(cpu_env, t0); |
c80d1df5 | 6354 | tcg_temp_free(t0); |
9b2fadda | 6355 | #endif /* defined(CONFIG_USER_ONLY) */ |
01662f3e AG |
6356 | } |
6357 | ||
6358 | /* tlbwe */ | |
6359 | static void gen_tlbwe_booke206(DisasContext *ctx) | |
6360 | { | |
6361 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 6362 | GEN_PRIV; |
01662f3e | 6363 | #else |
9b2fadda | 6364 | CHK_SV; |
c6c7cf05 | 6365 | gen_helper_booke206_tlbwe(cpu_env); |
9b2fadda | 6366 | #endif /* defined(CONFIG_USER_ONLY) */ |
01662f3e AG |
6367 | } |
6368 | ||
6369 | static void gen_tlbivax_booke206(DisasContext *ctx) | |
6370 | { | |
6371 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 6372 | GEN_PRIV; |
01662f3e AG |
6373 | #else |
6374 | TCGv t0; | |
01662f3e | 6375 | |
9b2fadda | 6376 | CHK_SV; |
01662f3e AG |
6377 | t0 = tcg_temp_new(); |
6378 | gen_addr_reg_index(ctx, t0); | |
c6c7cf05 | 6379 | gen_helper_booke206_tlbivax(cpu_env, t0); |
c80d1df5 | 6380 | tcg_temp_free(t0); |
9b2fadda | 6381 | #endif /* defined(CONFIG_USER_ONLY) */ |
01662f3e AG |
6382 | } |
6383 | ||
6d3db821 AG |
6384 | static void gen_tlbilx_booke206(DisasContext *ctx) |
6385 | { | |
6386 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 6387 | GEN_PRIV; |
6d3db821 AG |
6388 | #else |
6389 | TCGv t0; | |
6d3db821 | 6390 | |
9b2fadda | 6391 | CHK_SV; |
6d3db821 AG |
6392 | t0 = tcg_temp_new(); |
6393 | gen_addr_reg_index(ctx, t0); | |
6394 | ||
6395 | switch((ctx->opcode >> 21) & 0x3) { | |
6396 | case 0: | |
c6c7cf05 | 6397 | gen_helper_booke206_tlbilx0(cpu_env, t0); |
6d3db821 AG |
6398 | break; |
6399 | case 1: | |
c6c7cf05 | 6400 | gen_helper_booke206_tlbilx1(cpu_env, t0); |
6d3db821 AG |
6401 | break; |
6402 | case 3: | |
c6c7cf05 | 6403 | gen_helper_booke206_tlbilx3(cpu_env, t0); |
6d3db821 AG |
6404 | break; |
6405 | default: | |
6406 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); | |
6407 | break; | |
6408 | } | |
6409 | ||
6410 | tcg_temp_free(t0); | |
9b2fadda | 6411 | #endif /* defined(CONFIG_USER_ONLY) */ |
6d3db821 AG |
6412 | } |
6413 | ||
01662f3e | 6414 | |
76a66253 | 6415 | /* wrtee */ |
99e300ef | 6416 | static void gen_wrtee(DisasContext *ctx) |
76a66253 JM |
6417 | { |
6418 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 6419 | GEN_PRIV; |
76a66253 | 6420 | #else |
6527f6ea | 6421 | TCGv t0; |
9b2fadda BH |
6422 | |
6423 | CHK_SV; | |
6527f6ea AJ |
6424 | t0 = tcg_temp_new(); |
6425 | tcg_gen_andi_tl(t0, cpu_gpr[rD(ctx->opcode)], (1 << MSR_EE)); | |
6426 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE)); | |
6427 | tcg_gen_or_tl(cpu_msr, cpu_msr, t0); | |
6428 | tcg_temp_free(t0); | |
dee96f6c JM |
6429 | /* Stop translation to have a chance to raise an exception |
6430 | * if we just set msr_ee to 1 | |
6431 | */ | |
e06fcd75 | 6432 | gen_stop_exception(ctx); |
9b2fadda | 6433 | #endif /* defined(CONFIG_USER_ONLY) */ |
76a66253 JM |
6434 | } |
6435 | ||
6436 | /* wrteei */ | |
99e300ef | 6437 | static void gen_wrteei(DisasContext *ctx) |
76a66253 JM |
6438 | { |
6439 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 6440 | GEN_PRIV; |
76a66253 | 6441 | #else |
9b2fadda | 6442 | CHK_SV; |
fbe73008 | 6443 | if (ctx->opcode & 0x00008000) { |
6527f6ea AJ |
6444 | tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE)); |
6445 | /* Stop translation to have a chance to raise an exception */ | |
e06fcd75 | 6446 | gen_stop_exception(ctx); |
6527f6ea | 6447 | } else { |
1b6e5f99 | 6448 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE)); |
6527f6ea | 6449 | } |
9b2fadda | 6450 | #endif /* defined(CONFIG_USER_ONLY) */ |
76a66253 JM |
6451 | } |
6452 | ||
08e46e54 | 6453 | /* PowerPC 440 specific instructions */ |
99e300ef | 6454 | |
54623277 | 6455 | /* dlmzb */ |
99e300ef | 6456 | static void gen_dlmzb(DisasContext *ctx) |
76a66253 | 6457 | { |
ef0d51af | 6458 | TCGv_i32 t0 = tcg_const_i32(Rc(ctx->opcode)); |
d15f74fb BS |
6459 | gen_helper_dlmzb(cpu_gpr[rA(ctx->opcode)], cpu_env, |
6460 | cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); | |
ef0d51af | 6461 | tcg_temp_free_i32(t0); |
76a66253 JM |
6462 | } |
6463 | ||
6464 | /* mbar replaces eieio on 440 */ | |
99e300ef | 6465 | static void gen_mbar(DisasContext *ctx) |
76a66253 JM |
6466 | { |
6467 | /* interpreted as no-op */ | |
6468 | } | |
6469 | ||
6470 | /* msync replaces sync on 440 */ | |
dcb2b9e1 | 6471 | static void gen_msync_4xx(DisasContext *ctx) |
76a66253 | 6472 | { |
27a3ea7e BZ |
6473 | /* Only e500 seems to treat reserved bits as invalid */ |
6474 | if ((ctx->insns_flags2 & PPC2_BOOKE206) && | |
6475 | (ctx->opcode & 0x03FFF801)) { | |
6476 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); | |
6477 | } | |
6478 | /* otherwise interpreted as no-op */ | |
76a66253 JM |
6479 | } |
6480 | ||
6481 | /* icbt */ | |
e8eaa2c0 | 6482 | static void gen_icbt_440(DisasContext *ctx) |
76a66253 JM |
6483 | { |
6484 | /* interpreted as no-op */ | |
6485 | /* XXX: specification say this is treated as a load by the MMU | |
6486 | * but does not generate any exception | |
6487 | */ | |
79aceca5 FB |
6488 | } |
6489 | ||
9e0b5cb1 AG |
6490 | /* Embedded.Processor Control */ |
6491 | ||
6492 | static void gen_msgclr(DisasContext *ctx) | |
6493 | { | |
6494 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 6495 | GEN_PRIV; |
9e0b5cb1 | 6496 | #else |
ebca5e6d | 6497 | CHK_HV; |
7af1e7b0 CLG |
6498 | /* 64-bit server processors compliant with arch 2.x */ |
6499 | if (ctx->insns_flags & PPC_SEGMENT_64B) { | |
6500 | gen_helper_book3s_msgclr(cpu_env, cpu_gpr[rB(ctx->opcode)]); | |
6501 | } else { | |
6502 | gen_helper_msgclr(cpu_env, cpu_gpr[rB(ctx->opcode)]); | |
6503 | } | |
9b2fadda | 6504 | #endif /* defined(CONFIG_USER_ONLY) */ |
9e0b5cb1 AG |
6505 | } |
6506 | ||
d5d11a39 AG |
6507 | static void gen_msgsnd(DisasContext *ctx) |
6508 | { | |
6509 | #if defined(CONFIG_USER_ONLY) | |
9b2fadda | 6510 | GEN_PRIV; |
d5d11a39 | 6511 | #else |
ebca5e6d | 6512 | CHK_HV; |
7af1e7b0 CLG |
6513 | /* 64-bit server processors compliant with arch 2.x */ |
6514 | if (ctx->insns_flags & PPC_SEGMENT_64B) { | |
6515 | gen_helper_book3s_msgsnd(cpu_gpr[rB(ctx->opcode)]); | |
6516 | } else { | |
6517 | gen_helper_msgsnd(cpu_gpr[rB(ctx->opcode)]); | |
6518 | } | |
9b2fadda | 6519 | #endif /* defined(CONFIG_USER_ONLY) */ |
d5d11a39 AG |
6520 | } |
6521 | ||
7af1e7b0 CLG |
6522 | static void gen_msgsync(DisasContext *ctx) |
6523 | { | |
6524 | #if defined(CONFIG_USER_ONLY) | |
6525 | GEN_PRIV; | |
6526 | #else | |
6527 | CHK_HV; | |
6528 | #endif /* defined(CONFIG_USER_ONLY) */ | |
6529 | /* interpreted as no-op */ | |
6530 | } | |
b04ae981 | 6531 | |
aeeb044c ND |
6532 | #if defined(TARGET_PPC64) |
6533 | static void gen_maddld(DisasContext *ctx) | |
6534 | { | |
6535 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
6536 | ||
6537 | tcg_gen_mul_i64(t1, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
6538 | tcg_gen_add_i64(cpu_gpr[rD(ctx->opcode)], t1, cpu_gpr[rC(ctx->opcode)]); | |
6539 | tcg_temp_free_i64(t1); | |
6540 | } | |
5f29cc82 ND |
6541 | |
6542 | /* maddhd maddhdu */ | |
6543 | static void gen_maddhd_maddhdu(DisasContext *ctx) | |
6544 | { | |
6545 | TCGv_i64 lo = tcg_temp_new_i64(); | |
6546 | TCGv_i64 hi = tcg_temp_new_i64(); | |
6547 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
6548 | ||
6549 | if (Rc(ctx->opcode)) { | |
6550 | tcg_gen_mulu2_i64(lo, hi, cpu_gpr[rA(ctx->opcode)], | |
6551 | cpu_gpr[rB(ctx->opcode)]); | |
6552 | tcg_gen_movi_i64(t1, 0); | |
6553 | } else { | |
6554 | tcg_gen_muls2_i64(lo, hi, cpu_gpr[rA(ctx->opcode)], | |
6555 | cpu_gpr[rB(ctx->opcode)]); | |
6556 | tcg_gen_sari_i64(t1, cpu_gpr[rC(ctx->opcode)], 63); | |
6557 | } | |
6558 | tcg_gen_add2_i64(t1, cpu_gpr[rD(ctx->opcode)], lo, hi, | |
6559 | cpu_gpr[rC(ctx->opcode)], t1); | |
6560 | tcg_temp_free_i64(lo); | |
6561 | tcg_temp_free_i64(hi); | |
6562 | tcg_temp_free_i64(t1); | |
6563 | } | |
aeeb044c ND |
6564 | #endif /* defined(TARGET_PPC64) */ |
6565 | ||
0ff93d11 TM |
6566 | static void gen_tbegin(DisasContext *ctx) |
6567 | { | |
6568 | if (unlikely(!ctx->tm_enabled)) { | |
6569 | gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); | |
6570 | return; | |
6571 | } | |
6572 | gen_helper_tbegin(cpu_env); | |
6573 | } | |
6574 | ||
56a84615 TM |
6575 | #define GEN_TM_NOOP(name) \ |
6576 | static inline void gen_##name(DisasContext *ctx) \ | |
6577 | { \ | |
6578 | if (unlikely(!ctx->tm_enabled)) { \ | |
6579 | gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \ | |
6580 | return; \ | |
6581 | } \ | |
6582 | /* Because tbegin always fails in QEMU, these user \ | |
6583 | * space instructions all have a simple implementation: \ | |
6584 | * \ | |
6585 | * CR[0] = 0b0 || MSR[TS] || 0b0 \ | |
6586 | * = 0b0 || 0b00 || 0b0 \ | |
6587 | */ \ | |
6588 | tcg_gen_movi_i32(cpu_crf[0], 0); \ | |
6589 | } | |
6590 | ||
6591 | GEN_TM_NOOP(tend); | |
6592 | GEN_TM_NOOP(tabort); | |
6593 | GEN_TM_NOOP(tabortwc); | |
6594 | GEN_TM_NOOP(tabortwci); | |
6595 | GEN_TM_NOOP(tabortdc); | |
6596 | GEN_TM_NOOP(tabortdci); | |
6597 | GEN_TM_NOOP(tsr); | |
b8b4576e SJS |
6598 | static inline void gen_cp_abort(DisasContext *ctx) |
6599 | { | |
6600 | // Do Nothing | |
6601 | } | |
56a84615 | 6602 | |
80b8c1ee ND |
6603 | #define GEN_CP_PASTE_NOOP(name) \ |
6604 | static inline void gen_##name(DisasContext *ctx) \ | |
6605 | { \ | |
6606 | /* Generate invalid exception until \ | |
6607 | * we have an implementation of the copy \ | |
6608 | * paste facility \ | |
6609 | */ \ | |
6610 | gen_invalid(ctx); \ | |
6611 | } | |
6612 | ||
6613 | GEN_CP_PASTE_NOOP(copy) | |
6614 | GEN_CP_PASTE_NOOP(paste) | |
6615 | ||
aeedd582 TM |
6616 | static void gen_tcheck(DisasContext *ctx) |
6617 | { | |
6618 | if (unlikely(!ctx->tm_enabled)) { | |
6619 | gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); | |
6620 | return; | |
6621 | } | |
6622 | /* Because tbegin always fails, the tcheck implementation | |
6623 | * is simple: | |
6624 | * | |
6625 | * CR[CRF] = TDOOMED || MSR[TS] || 0b0 | |
6626 | * = 0b1 || 0b00 || 0b0 | |
6627 | */ | |
6628 | tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0x8); | |
6629 | } | |
6630 | ||
f83c2378 TM |
6631 | #if defined(CONFIG_USER_ONLY) |
6632 | #define GEN_TM_PRIV_NOOP(name) \ | |
6633 | static inline void gen_##name(DisasContext *ctx) \ | |
6634 | { \ | |
9b2fadda | 6635 | gen_priv_exception(ctx, POWERPC_EXCP_PRIV_OPC); \ |
f83c2378 TM |
6636 | } |
6637 | ||
6638 | #else | |
6639 | ||
6640 | #define GEN_TM_PRIV_NOOP(name) \ | |
6641 | static inline void gen_##name(DisasContext *ctx) \ | |
6642 | { \ | |
9b2fadda | 6643 | CHK_SV; \ |
f83c2378 TM |
6644 | if (unlikely(!ctx->tm_enabled)) { \ |
6645 | gen_exception_err(ctx, POWERPC_EXCP_FU, FSCR_IC_TM); \ | |
6646 | return; \ | |
6647 | } \ | |
6648 | /* Because tbegin always fails, the implementation is \ | |
6649 | * simple: \ | |
6650 | * \ | |
6651 | * CR[0] = 0b0 || MSR[TS] || 0b0 \ | |
6652 | * = 0b0 || 0b00 | 0b0 \ | |
6653 | */ \ | |
6654 | tcg_gen_movi_i32(cpu_crf[0], 0); \ | |
6655 | } | |
6656 | ||
6657 | #endif | |
6658 | ||
6659 | GEN_TM_PRIV_NOOP(treclaim); | |
6660 | GEN_TM_PRIV_NOOP(trechkpt); | |
6661 | ||
1a404c91 MCA |
6662 | static inline void get_fpr(TCGv_i64 dst, int regno) |
6663 | { | |
ef96e3ae | 6664 | tcg_gen_ld_i64(dst, cpu_env, offsetof(CPUPPCState, vsr[regno].u64[0])); |
1a404c91 MCA |
6665 | } |
6666 | ||
6667 | static inline void set_fpr(int regno, TCGv_i64 src) | |
6668 | { | |
ef96e3ae | 6669 | tcg_gen_st_i64(src, cpu_env, offsetof(CPUPPCState, vsr[regno].u64[0])); |
1a404c91 MCA |
6670 | } |
6671 | ||
c4a18dbf MCA |
6672 | static inline void get_avr64(TCGv_i64 dst, int regno, bool high) |
6673 | { | |
7329fb62 MCA |
6674 | #ifdef HOST_WORDS_BIGENDIAN |
6675 | tcg_gen_ld_i64(dst, cpu_env, offsetof(CPUPPCState, | |
ef96e3ae | 6676 | vsr[32 + regno].u64[(high ? 0 : 1)])); |
7329fb62 MCA |
6677 | #else |
6678 | tcg_gen_ld_i64(dst, cpu_env, offsetof(CPUPPCState, | |
ef96e3ae | 6679 | vsr[32 + regno].u64[(high ? 1 : 0)])); |
7329fb62 | 6680 | #endif |
c4a18dbf MCA |
6681 | } |
6682 | ||
6683 | static inline void set_avr64(int regno, TCGv_i64 src, bool high) | |
6684 | { | |
7329fb62 MCA |
6685 | #ifdef HOST_WORDS_BIGENDIAN |
6686 | tcg_gen_st_i64(src, cpu_env, offsetof(CPUPPCState, | |
ef96e3ae | 6687 | vsr[32 + regno].u64[(high ? 0 : 1)])); |
7329fb62 MCA |
6688 | #else |
6689 | tcg_gen_st_i64(src, cpu_env, offsetof(CPUPPCState, | |
ef96e3ae | 6690 | vsr[32 + regno].u64[(high ? 1 : 0)])); |
7329fb62 | 6691 | #endif |
c4a18dbf MCA |
6692 | } |
6693 | ||
15848410 BH |
6694 | #include "translate/fp-impl.inc.c" |
6695 | ||
6696 | #include "translate/vmx-impl.inc.c" | |
6697 | ||
6698 | #include "translate/vsx-impl.inc.c" | |
6699 | ||
6700 | #include "translate/dfp-impl.inc.c" | |
6701 | ||
6702 | #include "translate/spe-impl.inc.c" | |
6703 | ||
5cb091a4 ND |
6704 | /* Handles lfdp, lxsd, lxssp */ |
6705 | static void gen_dform39(DisasContext *ctx) | |
6706 | { | |
6707 | switch (ctx->opcode & 0x3) { | |
6708 | case 0: /* lfdp */ | |
6709 | if (ctx->insns_flags2 & PPC2_ISA205) { | |
6710 | return gen_lfdp(ctx); | |
6711 | } | |
6712 | break; | |
6713 | case 2: /* lxsd */ | |
6714 | if (ctx->insns_flags2 & PPC2_ISA300) { | |
6715 | return gen_lxsd(ctx); | |
6716 | } | |
6717 | break; | |
6718 | case 3: /* lxssp */ | |
6719 | if (ctx->insns_flags2 & PPC2_ISA300) { | |
6720 | return gen_lxssp(ctx); | |
6721 | } | |
6722 | break; | |
6723 | } | |
6724 | return gen_invalid(ctx); | |
6725 | } | |
6726 | ||
d59ba583 | 6727 | /* handles stfdp, lxv, stxsd, stxssp lxvx */ |
e3001664 ND |
6728 | static void gen_dform3D(DisasContext *ctx) |
6729 | { | |
6730 | if ((ctx->opcode & 3) == 1) { /* DQ-FORM */ | |
6731 | switch (ctx->opcode & 0x7) { | |
6732 | case 1: /* lxv */ | |
d59ba583 ND |
6733 | if (ctx->insns_flags2 & PPC2_ISA300) { |
6734 | return gen_lxv(ctx); | |
6735 | } | |
e3001664 ND |
6736 | break; |
6737 | case 5: /* stxv */ | |
d59ba583 ND |
6738 | if (ctx->insns_flags2 & PPC2_ISA300) { |
6739 | return gen_stxv(ctx); | |
6740 | } | |
e3001664 ND |
6741 | break; |
6742 | } | |
6743 | } else { /* DS-FORM */ | |
6744 | switch (ctx->opcode & 0x3) { | |
6745 | case 0: /* stfdp */ | |
6746 | if (ctx->insns_flags2 & PPC2_ISA205) { | |
6747 | return gen_stfdp(ctx); | |
6748 | } | |
6749 | break; | |
6750 | case 2: /* stxsd */ | |
6751 | if (ctx->insns_flags2 & PPC2_ISA300) { | |
6752 | return gen_stxsd(ctx); | |
6753 | } | |
6754 | break; | |
6755 | case 3: /* stxssp */ | |
6756 | if (ctx->insns_flags2 & PPC2_ISA300) { | |
6757 | return gen_stxssp(ctx); | |
6758 | } | |
6759 | break; | |
6760 | } | |
6761 | } | |
6762 | return gen_invalid(ctx); | |
6763 | } | |
6764 | ||
c227f099 | 6765 | static opcode_t opcodes[] = { |
5c55ff99 BS |
6766 | GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE), |
6767 | GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER), | |
6768 | GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER), | |
4aaefd93 | 6769 | GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400001, PPC_INTEGER), |
5c55ff99 | 6770 | GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER), |
082ce330 ND |
6771 | #if defined(TARGET_PPC64) |
6772 | GEN_HANDLER_E(cmpeqb, 0x1F, 0x00, 0x07, 0x00600000, PPC_NONE, PPC2_ISA300), | |
6773 | #endif | |
fcfda20f | 6774 | GEN_HANDLER_E(cmpb, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE, PPC2_ISA205), |
f2442ef9 | 6775 | GEN_HANDLER_E(cmprb, 0x1F, 0x00, 0x06, 0x00400001, PPC_NONE, PPC2_ISA300), |
5c55ff99 BS |
6776 | GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL), |
6777 | GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
6778 | GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
6779 | GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
6780 | GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
c5b2b9ce | 6781 | GEN_HANDLER_E(addpcis, 0x13, 0x2, 0xFF, 0x00000000, PPC_NONE, PPC2_ISA300), |
5c55ff99 BS |
6782 | GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER), |
6783 | GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER), | |
6784 | GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER), | |
6785 | GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER), | |
6786 | GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
6787 | #if defined(TARGET_PPC64) | |
6788 | GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B), | |
6789 | #endif | |
6790 | GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER), | |
6791 | GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER), | |
6792 | GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
6793 | GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
6794 | GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
6795 | GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER), | |
b35344e4 | 6796 | GEN_HANDLER_E(cnttzw, 0x1F, 0x1A, 0x10, 0x00000000, PPC_NONE, PPC2_ISA300), |
80b8c1ee | 6797 | GEN_HANDLER_E(copy, 0x1F, 0x06, 0x18, 0x03C00001, PPC_NONE, PPC2_ISA300), |
b8b4576e | 6798 | GEN_HANDLER_E(cp_abort, 0x1F, 0x06, 0x1A, 0x03FFF801, PPC_NONE, PPC2_ISA300), |
80b8c1ee | 6799 | GEN_HANDLER_E(paste, 0x1F, 0x06, 0x1C, 0x03C00000, PPC_NONE, PPC2_ISA300), |
5c55ff99 BS |
6800 | GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER), |
6801 | GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER), | |
6802 | GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
6803 | GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
6804 | GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
6805 | GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
6ab39b1b | 6806 | GEN_HANDLER(popcntb, 0x1F, 0x1A, 0x03, 0x0000F801, PPC_POPCNTB), |
eaabeef2 | 6807 | GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD), |
725bcec2 | 6808 | GEN_HANDLER_E(prtyw, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE, PPC2_ISA205), |
5c55ff99 | 6809 | #if defined(TARGET_PPC64) |
eaabeef2 | 6810 | GEN_HANDLER(popcntd, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD), |
5c55ff99 | 6811 | GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B), |
e91d95b2 | 6812 | GEN_HANDLER_E(cnttzd, 0x1F, 0x1A, 0x11, 0x00000000, PPC_NONE, PPC2_ISA300), |
fec5c62a | 6813 | GEN_HANDLER_E(darn, 0x1F, 0x13, 0x17, 0x001CF801, PPC_NONE, PPC2_ISA300), |
725bcec2 | 6814 | GEN_HANDLER_E(prtyd, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE, PPC2_ISA205), |
86ba37ed | 6815 | GEN_HANDLER_E(bpermd, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE, PPC2_PERM_ISA206), |
5c55ff99 BS |
6816 | #endif |
6817 | GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
6818 | GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
6819 | GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
6820 | GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER), | |
6821 | GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER), | |
6822 | GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER), | |
6823 | GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER), | |
6824 | #if defined(TARGET_PPC64) | |
6825 | GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B), | |
6826 | GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B), | |
6827 | GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B), | |
6828 | GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B), | |
6829 | GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B), | |
787bbe37 ND |
6830 | GEN_HANDLER2_E(extswsli0, "extswsli", 0x1F, 0x1A, 0x1B, 0x00000000, |
6831 | PPC_NONE, PPC2_ISA300), | |
6832 | GEN_HANDLER2_E(extswsli1, "extswsli", 0x1F, 0x1B, 0x1B, 0x00000000, | |
6833 | PPC_NONE, PPC2_ISA300), | |
5c55ff99 | 6834 | #endif |
5c55ff99 BS |
6835 | #if defined(TARGET_PPC64) |
6836 | GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B), | |
6837 | GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX), | |
6838 | GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B), | |
6839 | #endif | |
5cb091a4 ND |
6840 | /* handles lfdp, lxsd, lxssp */ |
6841 | GEN_HANDLER_E(dform39, 0x39, 0xFF, 0xFF, 0x00000000, PPC_NONE, PPC2_ISA205), | |
d59ba583 | 6842 | /* handles stfdp, lxv, stxsd, stxssp, stxv */ |
e3001664 | 6843 | GEN_HANDLER_E(dform3D, 0x3D, 0xFF, 0xFF, 0x00000000, PPC_NONE, PPC2_ISA205), |
5c55ff99 BS |
6844 | GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), |
6845 | GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
6846 | GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING), | |
6847 | GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING), | |
6848 | GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING), | |
6849 | GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING), | |
c8fd8373 | 6850 | GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x01FFF801, PPC_MEM_EIEIO), |
5c55ff99 | 6851 | GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM), |
5c77a786 TM |
6852 | GEN_HANDLER_E(lbarx, 0x1F, 0x14, 0x01, 0, PPC_NONE, PPC2_ATOMIC_ISA206), |
6853 | GEN_HANDLER_E(lharx, 0x1F, 0x14, 0x03, 0, PPC_NONE, PPC2_ATOMIC_ISA206), | |
f844c817 | 6854 | GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES), |
a68a6146 | 6855 | GEN_HANDLER_E(lwat, 0x1F, 0x06, 0x12, 0x00000001, PPC_NONE, PPC2_ISA300), |
a3401188 | 6856 | GEN_HANDLER_E(stwat, 0x1F, 0x06, 0x16, 0x00000001, PPC_NONE, PPC2_ISA300), |
587c51f7 TM |
6857 | GEN_HANDLER_E(stbcx_, 0x1F, 0x16, 0x15, 0, PPC_NONE, PPC2_ATOMIC_ISA206), |
6858 | GEN_HANDLER_E(sthcx_, 0x1F, 0x16, 0x16, 0, PPC_NONE, PPC2_ATOMIC_ISA206), | |
5c55ff99 BS |
6859 | GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES), |
6860 | #if defined(TARGET_PPC64) | |
a68a6146 | 6861 | GEN_HANDLER_E(ldat, 0x1F, 0x06, 0x13, 0x00000001, PPC_NONE, PPC2_ISA300), |
a3401188 | 6862 | GEN_HANDLER_E(stdat, 0x1F, 0x06, 0x17, 0x00000001, PPC_NONE, PPC2_ISA300), |
f844c817 | 6863 | GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B), |
9c294d5a | 6864 | GEN_HANDLER_E(lqarx, 0x1F, 0x14, 0x08, 0, PPC_NONE, PPC2_LSQ_ISA207), |
5c55ff99 | 6865 | GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B), |
27b95bfe | 6866 | GEN_HANDLER_E(stqcx_, 0x1F, 0x16, 0x05, 0, PPC_NONE, PPC2_LSQ_ISA207), |
5c55ff99 BS |
6867 | #endif |
6868 | GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC), | |
6869 | GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT), | |
c09cec68 | 6870 | GEN_HANDLER_E(wait, 0x1F, 0x1E, 0x00, 0x039FF801, PPC_NONE, PPC2_ISA300), |
5c55ff99 BS |
6871 | GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW), |
6872 | GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW), | |
6873 | GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW), | |
6874 | GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW), | |
4aaefd93 | 6875 | GEN_HANDLER_E(bctar, 0x13, 0x10, 0x11, 0x0000E000, PPC_NONE, PPC2_BCTAR_ISA207), |
5c55ff99 BS |
6876 | GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER), |
6877 | GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW), | |
6878 | #if defined(TARGET_PPC64) | |
6879 | GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B), | |
cdee0e72 | 6880 | GEN_HANDLER_E(stop, 0x13, 0x12, 0x0b, 0x03FFF801, PPC_NONE, PPC2_ISA300), |
7778a575 BH |
6881 | GEN_HANDLER_E(doze, 0x13, 0x12, 0x0c, 0x03FFF801, PPC_NONE, PPC2_PM_ISA206), |
6882 | GEN_HANDLER_E(nap, 0x13, 0x12, 0x0d, 0x03FFF801, PPC_NONE, PPC2_PM_ISA206), | |
6883 | GEN_HANDLER_E(sleep, 0x13, 0x12, 0x0e, 0x03FFF801, PPC_NONE, PPC2_PM_ISA206), | |
6884 | GEN_HANDLER_E(rvwinkle, 0x13, 0x12, 0x0f, 0x03FFF801, PPC_NONE, PPC2_PM_ISA206), | |
5c55ff99 BS |
6885 | GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H), |
6886 | #endif | |
6887 | GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW), | |
6888 | GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW), | |
6889 | GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW), | |
6890 | #if defined(TARGET_PPC64) | |
6891 | GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B), | |
6892 | GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B), | |
6893 | #endif | |
6894 | GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC), | |
6895 | GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC), | |
6896 | GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC), | |
6897 | GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC), | |
6898 | GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB), | |
6899 | GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC), | |
6900 | #if defined(TARGET_PPC64) | |
6901 | GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B), | |
dc2ee038 | 6902 | GEN_HANDLER_E(setb, 0x1F, 0x00, 0x04, 0x0003F801, PPC_NONE, PPC2_ISA300), |
b63d0434 | 6903 | GEN_HANDLER_E(mcrxrx, 0x1F, 0x00, 0x12, 0x007FF801, PPC_NONE, PPC2_ISA300), |
5c55ff99 | 6904 | #endif |
5e31867f | 6905 | GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001EF801, PPC_MISC), |
4248b336 | 6906 | GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000000, PPC_MISC), |
5c55ff99 | 6907 | GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE), |
50728199 | 6908 | GEN_HANDLER_E(dcbfep, 0x1F, 0x1F, 0x03, 0x03C00001, PPC_NONE, PPC2_BOOKE206), |
5c55ff99 BS |
6909 | GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE), |
6910 | GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE), | |
50728199 | 6911 | GEN_HANDLER_E(dcbstep, 0x1F, 0x1F, 0x01, 0x03E00001, PPC_NONE, PPC2_BOOKE206), |
3f34cf91 | 6912 | GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x00000001, PPC_CACHE), |
50728199 | 6913 | GEN_HANDLER_E(dcbtep, 0x1F, 0x1F, 0x09, 0x00000001, PPC_NONE, PPC2_BOOKE206), |
3f34cf91 | 6914 | GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x00000001, PPC_CACHE), |
50728199 | 6915 | GEN_HANDLER_E(dcbtstep, 0x1F, 0x1F, 0x07, 0x00000001, PPC_NONE, PPC2_BOOKE206), |
4d09d529 | 6916 | GEN_HANDLER_E(dcbtls, 0x1F, 0x06, 0x05, 0x02000001, PPC_BOOKE, PPC2_BOOKE206), |
8e33944f | 6917 | GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ), |
50728199 | 6918 | GEN_HANDLER_E(dcbzep, 0x1F, 0x1F, 0x1F, 0x03C00001, PPC_NONE, PPC2_BOOKE206), |
5c55ff99 | 6919 | GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC), |
99d45f8f | 6920 | GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x01800001, PPC_ALTIVEC), |
5c55ff99 BS |
6921 | GEN_HANDLER(dss, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC), |
6922 | GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI), | |
50728199 | 6923 | GEN_HANDLER_E(icbiep, 0x1F, 0x1F, 0x1E, 0x03E00001, PPC_NONE, PPC2_BOOKE206), |
5c55ff99 BS |
6924 | GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA), |
6925 | GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT), | |
6926 | GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT), | |
6927 | GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT), | |
6928 | GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT), | |
6929 | #if defined(TARGET_PPC64) | |
6930 | GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B), | |
6931 | GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001, | |
6932 | PPC_SEGMENT_64B), | |
6933 | GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B), | |
6934 | GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001, | |
6935 | PPC_SEGMENT_64B), | |
efdef95f DG |
6936 | GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B), |
6937 | GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B), | |
6938 | GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B), | |
c76c22d5 | 6939 | GEN_HANDLER2(slbfee_, "slbfee.", 0x1F, 0x13, 0x1E, 0x001F0000, PPC_SEGMENT_64B), |
5c55ff99 BS |
6940 | #endif |
6941 | GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA), | |
f9ef0527 BH |
6942 | /* XXX Those instructions will need to be handled differently for |
6943 | * different ISA versions */ | |
6944 | GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x001F0001, PPC_MEM_TLBIE), | |
6945 | GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x001F0001, PPC_MEM_TLBIE), | |
c8830502 SJS |
6946 | GEN_HANDLER_E(tlbiel, 0x1F, 0x12, 0x08, 0x00100001, PPC_NONE, PPC2_ISA300), |
6947 | GEN_HANDLER_E(tlbie, 0x1F, 0x12, 0x09, 0x00100001, PPC_NONE, PPC2_ISA300), | |
5c55ff99 BS |
6948 | GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC), |
6949 | #if defined(TARGET_PPC64) | |
2f9254d9 | 6950 | GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x031FFC01, PPC_SLBI), |
5c55ff99 | 6951 | GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI), |
a63f1dfc | 6952 | GEN_HANDLER_E(slbieg, 0x1F, 0x12, 0x0E, 0x001F0001, PPC_NONE, PPC2_ISA300), |
62d897ca | 6953 | GEN_HANDLER_E(slbsync, 0x1F, 0x12, 0x0A, 0x03FFF801, PPC_NONE, PPC2_ISA300), |
5c55ff99 BS |
6954 | #endif |
6955 | GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN), | |
6956 | GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN), | |
6957 | GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR), | |
6958 | GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR), | |
6959 | GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR), | |
6960 | GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR), | |
6961 | GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR), | |
6962 | GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR), | |
6963 | GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR), | |
6964 | GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR), | |
6965 | GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR), | |
6966 | GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR), | |
6967 | GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR), | |
6968 | GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR), | |
6969 | GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR), | |
6970 | GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR), | |
6971 | GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR), | |
6972 | GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR), | |
6973 | GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR), | |
6974 | GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR), | |
6975 | GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR), | |
6976 | GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR), | |
6977 | GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR), | |
6978 | GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR), | |
6979 | GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR), | |
6980 | GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR), | |
6981 | GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR), | |
6982 | GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR), | |
6983 | GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR), | |
6984 | GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR), | |
6985 | GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR), | |
6986 | GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR), | |
6987 | GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR), | |
6988 | GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR), | |
6989 | GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR), | |
6990 | GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR), | |
6991 | GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC), | |
6992 | GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC), | |
6993 | GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC), | |
6994 | GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB), | |
6995 | GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB), | |
6996 | GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB), | |
6997 | GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB), | |
6998 | GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER), | |
6999 | GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER), | |
7000 | GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER), | |
7001 | GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER), | |
7002 | GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER), | |
7003 | GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER), | |
7004 | GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
7005 | GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
7006 | GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2), | |
7007 | GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2), | |
7008 | GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
7009 | GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
7010 | GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2), | |
7011 | GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2), | |
7012 | GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI), | |
7013 | GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA), | |
7014 | GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR), | |
7015 | GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR), | |
7016 | GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX), | |
7017 | GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX), | |
7018 | GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX), | |
7019 | GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX), | |
7020 | GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON), | |
7021 | GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON), | |
7022 | GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT), | |
7023 | GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON), | |
7024 | GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON), | |
7025 | GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP), | |
01662f3e | 7026 | GEN_HANDLER_E(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE, PPC2_BOOKE206), |
5c55ff99 BS |
7027 | GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI), |
7028 | GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI), | |
7029 | GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB), | |
7030 | GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB), | |
7031 | GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB), | |
7032 | GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE), | |
7033 | GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE), | |
7034 | GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE), | |
01662f3e AG |
7035 | GEN_HANDLER2_E(tlbre_booke206, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, |
7036 | PPC_NONE, PPC2_BOOKE206), | |
7037 | GEN_HANDLER2_E(tlbsx_booke206, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, | |
7038 | PPC_NONE, PPC2_BOOKE206), | |
7039 | GEN_HANDLER2_E(tlbwe_booke206, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, | |
7040 | PPC_NONE, PPC2_BOOKE206), | |
7041 | GEN_HANDLER2_E(tlbivax_booke206, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001, | |
7042 | PPC_NONE, PPC2_BOOKE206), | |
6d3db821 AG |
7043 | GEN_HANDLER2_E(tlbilx_booke206, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001, |
7044 | PPC_NONE, PPC2_BOOKE206), | |
d5d11a39 AG |
7045 | GEN_HANDLER2_E(msgsnd, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001, |
7046 | PPC_NONE, PPC2_PRCNTL), | |
9e0b5cb1 AG |
7047 | GEN_HANDLER2_E(msgclr, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001, |
7048 | PPC_NONE, PPC2_PRCNTL), | |
7af1e7b0 CLG |
7049 | GEN_HANDLER2_E(msgsync, "msgsync", 0x1F, 0x16, 0x1B, 0x00000000, |
7050 | PPC_NONE, PPC2_PRCNTL), | |
5c55ff99 | 7051 | GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE), |
fbe73008 | 7052 | GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE), |
5c55ff99 | 7053 | GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC), |
01662f3e AG |
7054 | GEN_HANDLER_E(mbar, 0x1F, 0x16, 0x1a, 0x001FF801, |
7055 | PPC_BOOKE, PPC2_BOOKE206), | |
27a3ea7e | 7056 | GEN_HANDLER(msync_4xx, 0x1F, 0x16, 0x12, 0x039FF801, PPC_BOOKE), |
01662f3e AG |
7057 | GEN_HANDLER2_E(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001, |
7058 | PPC_BOOKE, PPC2_BOOKE206), | |
0c8d8c8b | 7059 | GEN_HANDLER2(icbt_440, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, |
27a3ea7e | 7060 | PPC_440_SPEC), |
5c55ff99 BS |
7061 | GEN_HANDLER(lvsl, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC), |
7062 | GEN_HANDLER(lvsr, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC), | |
7063 | GEN_HANDLER(mfvscr, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC), | |
7064 | GEN_HANDLER(mtvscr, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC), | |
5c55ff99 | 7065 | GEN_HANDLER(vmladduhm, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC), |
aeeb044c | 7066 | #if defined(TARGET_PPC64) |
5f29cc82 ND |
7067 | GEN_HANDLER_E(maddhd_maddhdu, 0x04, 0x18, 0xFF, 0x00000000, PPC_NONE, |
7068 | PPC2_ISA300), | |
aeeb044c ND |
7069 | GEN_HANDLER_E(maddld, 0x04, 0x19, 0xFF, 0x00000000, PPC_NONE, PPC2_ISA300), |
7070 | #endif | |
5c55ff99 BS |
7071 | |
7072 | #undef GEN_INT_ARITH_ADD | |
7073 | #undef GEN_INT_ARITH_ADD_CONST | |
7074 | #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \ | |
7075 | GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER), | |
7076 | #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \ | |
7077 | add_ca, compute_ca, compute_ov) \ | |
7078 | GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER), | |
7079 | GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0) | |
7080 | GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1) | |
7081 | GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0) | |
7082 | GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1) | |
7083 | GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0) | |
7084 | GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1) | |
7085 | GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0) | |
7086 | GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1) | |
4c5920af | 7087 | GEN_HANDLER_E(addex, 0x1F, 0x0A, 0x05, 0x00000000, PPC_NONE, PPC2_ISA300), |
5c55ff99 BS |
7088 | GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0) |
7089 | GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1) | |
7090 | ||
7091 | #undef GEN_INT_ARITH_DIVW | |
7092 | #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \ | |
7093 | GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER) | |
7094 | GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0), | |
7095 | GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1), | |
7096 | GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0), | |
7097 | GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1), | |
a98eb9e9 TM |
7098 | GEN_HANDLER_E(divwe, 0x1F, 0x0B, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206), |
7099 | GEN_HANDLER_E(divweo, 0x1F, 0x0B, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206), | |
6a4fda33 TM |
7100 | GEN_HANDLER_E(divweu, 0x1F, 0x0B, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206), |
7101 | GEN_HANDLER_E(divweuo, 0x1F, 0x0B, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206), | |
af2c6620 ND |
7102 | GEN_HANDLER_E(modsw, 0x1F, 0x0B, 0x18, 0x00000001, PPC_NONE, PPC2_ISA300), |
7103 | GEN_HANDLER_E(moduw, 0x1F, 0x0B, 0x08, 0x00000001, PPC_NONE, PPC2_ISA300), | |
5c55ff99 BS |
7104 | |
7105 | #if defined(TARGET_PPC64) | |
7106 | #undef GEN_INT_ARITH_DIVD | |
7107 | #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \ | |
7108 | GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) | |
7109 | GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0), | |
7110 | GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1), | |
7111 | GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0), | |
7112 | GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1), | |
7113 | ||
98d1eb27 TM |
7114 | GEN_HANDLER_E(divdeu, 0x1F, 0x09, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206), |
7115 | GEN_HANDLER_E(divdeuo, 0x1F, 0x09, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206), | |
e44259b6 TM |
7116 | GEN_HANDLER_E(divde, 0x1F, 0x09, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206), |
7117 | GEN_HANDLER_E(divdeo, 0x1F, 0x09, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206), | |
063cf14f ND |
7118 | GEN_HANDLER_E(modsd, 0x1F, 0x09, 0x18, 0x00000001, PPC_NONE, PPC2_ISA300), |
7119 | GEN_HANDLER_E(modud, 0x1F, 0x09, 0x08, 0x00000001, PPC_NONE, PPC2_ISA300), | |
98d1eb27 | 7120 | |
5c55ff99 BS |
7121 | #undef GEN_INT_ARITH_MUL_HELPER |
7122 | #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \ | |
7123 | GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) | |
7124 | GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00), | |
7125 | GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02), | |
7126 | GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17), | |
7127 | #endif | |
7128 | ||
7129 | #undef GEN_INT_ARITH_SUBF | |
7130 | #undef GEN_INT_ARITH_SUBF_CONST | |
7131 | #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \ | |
7132 | GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER), | |
7133 | #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \ | |
7134 | add_ca, compute_ca, compute_ov) \ | |
7135 | GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER), | |
7136 | GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0) | |
7137 | GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1) | |
7138 | GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0) | |
7139 | GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1) | |
7140 | GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0) | |
7141 | GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1) | |
7142 | GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0) | |
7143 | GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1) | |
7144 | GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0) | |
7145 | GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1) | |
7146 | ||
7147 | #undef GEN_LOGICAL1 | |
7148 | #undef GEN_LOGICAL2 | |
7149 | #define GEN_LOGICAL2(name, tcg_op, opc, type) \ | |
7150 | GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type) | |
7151 | #define GEN_LOGICAL1(name, tcg_op, opc, type) \ | |
7152 | GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type) | |
7153 | GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER), | |
7154 | GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER), | |
7155 | GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER), | |
7156 | GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER), | |
7157 | GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER), | |
7158 | GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER), | |
7159 | GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER), | |
7160 | GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER), | |
7161 | #if defined(TARGET_PPC64) | |
7162 | GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B), | |
7163 | #endif | |
7164 | ||
7165 | #if defined(TARGET_PPC64) | |
7166 | #undef GEN_PPC64_R2 | |
7167 | #undef GEN_PPC64_R4 | |
7168 | #define GEN_PPC64_R2(name, opc1, opc2) \ | |
7169 | GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\ | |
7170 | GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \ | |
7171 | PPC_64B) | |
7172 | #define GEN_PPC64_R4(name, opc1, opc2) \ | |
7173 | GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\ | |
7174 | GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \ | |
7175 | PPC_64B), \ | |
7176 | GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \ | |
7177 | PPC_64B), \ | |
7178 | GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \ | |
7179 | PPC_64B) | |
7180 | GEN_PPC64_R4(rldicl, 0x1E, 0x00), | |
7181 | GEN_PPC64_R4(rldicr, 0x1E, 0x02), | |
7182 | GEN_PPC64_R4(rldic, 0x1E, 0x04), | |
7183 | GEN_PPC64_R2(rldcl, 0x1E, 0x08), | |
7184 | GEN_PPC64_R2(rldcr, 0x1E, 0x09), | |
7185 | GEN_PPC64_R4(rldimi, 0x1E, 0x06), | |
7186 | #endif | |
7187 | ||
5c55ff99 BS |
7188 | #undef GEN_LD |
7189 | #undef GEN_LDU | |
7190 | #undef GEN_LDUX | |
cd6e9320 | 7191 | #undef GEN_LDX_E |
5c55ff99 BS |
7192 | #undef GEN_LDS |
7193 | #define GEN_LD(name, ldop, opc, type) \ | |
7194 | GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), | |
7195 | #define GEN_LDU(name, ldop, opc, type) \ | |
7196 | GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type), | |
7197 | #define GEN_LDUX(name, ldop, opc2, opc3, type) \ | |
7198 | GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type), | |
b7815375 | 7199 | #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2, chk) \ |
cd6e9320 | 7200 | GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2), |
5c55ff99 BS |
7201 | #define GEN_LDS(name, ldop, op, type) \ |
7202 | GEN_LD(name, ldop, op | 0x20, type) \ | |
7203 | GEN_LDU(name, ldop, op | 0x21, type) \ | |
7204 | GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \ | |
7205 | GEN_LDX(name, ldop, 0x17, op | 0x00, type) | |
7206 | ||
7207 | GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER) | |
7208 | GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER) | |
7209 | GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER) | |
7210 | GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER) | |
7211 | #if defined(TARGET_PPC64) | |
7212 | GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B) | |
7213 | GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B) | |
4f364fe7 ND |
7214 | GEN_LDUX(ld, ld64_i64, 0x15, 0x01, PPC_64B) |
7215 | GEN_LDX(ld, ld64_i64, 0x15, 0x00, PPC_64B) | |
ff5f3981 | 7216 | GEN_LDX_E(ldbr, ld64ur_i64, 0x14, 0x10, PPC_NONE, PPC2_DBRX, CHK_NONE) |
b7815375 BH |
7217 | |
7218 | /* HV/P7 and later only */ | |
4f364fe7 | 7219 | GEN_LDX_HVRM(ldcix, ld64_i64, 0x15, 0x1b, PPC_CILDST) |
b7815375 BH |
7220 | GEN_LDX_HVRM(lwzcix, ld32u, 0x15, 0x18, PPC_CILDST) |
7221 | GEN_LDX_HVRM(lhzcix, ld16u, 0x15, 0x19, PPC_CILDST) | |
7222 | GEN_LDX_HVRM(lbzcix, ld8u, 0x15, 0x1a, PPC_CILDST) | |
5c55ff99 BS |
7223 | #endif |
7224 | GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER) | |
7225 | GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER) | |
7226 | ||
50728199 RK |
7227 | /* External PID based load */ |
7228 | #undef GEN_LDEPX | |
7229 | #define GEN_LDEPX(name, ldop, opc2, opc3) \ | |
7230 | GEN_HANDLER_E(name##epx, 0x1F, opc2, opc3, \ | |
7231 | 0x00000001, PPC_NONE, PPC2_BOOKE206), | |
7232 | ||
7233 | GEN_LDEPX(lb, DEF_MEMOP(MO_UB), 0x1F, 0x02) | |
7234 | GEN_LDEPX(lh, DEF_MEMOP(MO_UW), 0x1F, 0x08) | |
7235 | GEN_LDEPX(lw, DEF_MEMOP(MO_UL), 0x1F, 0x00) | |
7236 | #if defined(TARGET_PPC64) | |
7237 | GEN_LDEPX(ld, DEF_MEMOP(MO_Q), 0x1D, 0x00) | |
7238 | #endif | |
7239 | ||
5c55ff99 BS |
7240 | #undef GEN_ST |
7241 | #undef GEN_STU | |
7242 | #undef GEN_STUX | |
cd6e9320 | 7243 | #undef GEN_STX_E |
5c55ff99 BS |
7244 | #undef GEN_STS |
7245 | #define GEN_ST(name, stop, opc, type) \ | |
7246 | GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), | |
7247 | #define GEN_STU(name, stop, opc, type) \ | |
7248 | GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type), | |
7249 | #define GEN_STUX(name, stop, opc2, opc3, type) \ | |
7250 | GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type), | |
b7815375 | 7251 | #define GEN_STX_E(name, stop, opc2, opc3, type, type2, chk) \ |
0123d3cb | 7252 | GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000000, type, type2), |
5c55ff99 BS |
7253 | #define GEN_STS(name, stop, op, type) \ |
7254 | GEN_ST(name, stop, op | 0x20, type) \ | |
7255 | GEN_STU(name, stop, op | 0x21, type) \ | |
7256 | GEN_STUX(name, stop, 0x17, op | 0x01, type) \ | |
7257 | GEN_STX(name, stop, 0x17, op | 0x00, type) | |
7258 | ||
7259 | GEN_STS(stb, st8, 0x06, PPC_INTEGER) | |
7260 | GEN_STS(sth, st16, 0x0C, PPC_INTEGER) | |
7261 | GEN_STS(stw, st32, 0x04, PPC_INTEGER) | |
7262 | #if defined(TARGET_PPC64) | |
2468f23d ND |
7263 | GEN_STUX(std, st64_i64, 0x15, 0x05, PPC_64B) |
7264 | GEN_STX(std, st64_i64, 0x15, 0x04, PPC_64B) | |
804108aa | 7265 | GEN_STX_E(stdbr, st64r_i64, 0x14, 0x14, PPC_NONE, PPC2_DBRX, CHK_NONE) |
2468f23d | 7266 | GEN_STX_HVRM(stdcix, st64_i64, 0x15, 0x1f, PPC_CILDST) |
b7815375 BH |
7267 | GEN_STX_HVRM(stwcix, st32, 0x15, 0x1c, PPC_CILDST) |
7268 | GEN_STX_HVRM(sthcix, st16, 0x15, 0x1d, PPC_CILDST) | |
7269 | GEN_STX_HVRM(stbcix, st8, 0x15, 0x1e, PPC_CILDST) | |
5c55ff99 BS |
7270 | #endif |
7271 | GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER) | |
7272 | GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER) | |
7273 | ||
50728199 RK |
7274 | #undef GEN_STEPX |
7275 | #define GEN_STEPX(name, ldop, opc2, opc3) \ | |
7276 | GEN_HANDLER_E(name##epx, 0x1F, opc2, opc3, \ | |
7277 | 0x00000001, PPC_NONE, PPC2_BOOKE206), | |
7278 | ||
7279 | GEN_STEPX(stb, DEF_MEMOP(MO_UB), 0x1F, 0x06) | |
7280 | GEN_STEPX(sth, DEF_MEMOP(MO_UW), 0x1F, 0x0C) | |
7281 | GEN_STEPX(stw, DEF_MEMOP(MO_UL), 0x1F, 0x04) | |
7282 | #if defined(TARGET_PPC64) | |
7283 | GEN_STEPX(std, DEF_MEMOP(MO_Q), 0x1D, 0x04) | |
7284 | #endif | |
7285 | ||
5c55ff99 BS |
7286 | #undef GEN_CRLOGIC |
7287 | #define GEN_CRLOGIC(name, tcg_op, opc) \ | |
7288 | GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) | |
7289 | GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08), | |
7290 | GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04), | |
7291 | GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09), | |
7292 | GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07), | |
7293 | GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01), | |
7294 | GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E), | |
7295 | GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D), | |
7296 | GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06), | |
7297 | ||
7298 | #undef GEN_MAC_HANDLER | |
7299 | #define GEN_MAC_HANDLER(name, opc2, opc3) \ | |
7300 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC) | |
7301 | GEN_MAC_HANDLER(macchw, 0x0C, 0x05), | |
7302 | GEN_MAC_HANDLER(macchwo, 0x0C, 0x15), | |
7303 | GEN_MAC_HANDLER(macchws, 0x0C, 0x07), | |
7304 | GEN_MAC_HANDLER(macchwso, 0x0C, 0x17), | |
7305 | GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06), | |
7306 | GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16), | |
7307 | GEN_MAC_HANDLER(macchwu, 0x0C, 0x04), | |
7308 | GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14), | |
7309 | GEN_MAC_HANDLER(machhw, 0x0C, 0x01), | |
7310 | GEN_MAC_HANDLER(machhwo, 0x0C, 0x11), | |
7311 | GEN_MAC_HANDLER(machhws, 0x0C, 0x03), | |
7312 | GEN_MAC_HANDLER(machhwso, 0x0C, 0x13), | |
7313 | GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02), | |
7314 | GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12), | |
7315 | GEN_MAC_HANDLER(machhwu, 0x0C, 0x00), | |
7316 | GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10), | |
7317 | GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D), | |
7318 | GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D), | |
7319 | GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F), | |
7320 | GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F), | |
7321 | GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C), | |
7322 | GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C), | |
7323 | GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E), | |
7324 | GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E), | |
7325 | GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05), | |
7326 | GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15), | |
7327 | GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07), | |
7328 | GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17), | |
7329 | GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01), | |
7330 | GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11), | |
7331 | GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03), | |
7332 | GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13), | |
7333 | GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D), | |
7334 | GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D), | |
7335 | GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F), | |
7336 | GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F), | |
7337 | GEN_MAC_HANDLER(mulchw, 0x08, 0x05), | |
7338 | GEN_MAC_HANDLER(mulchwu, 0x08, 0x04), | |
7339 | GEN_MAC_HANDLER(mulhhw, 0x08, 0x01), | |
7340 | GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00), | |
7341 | GEN_MAC_HANDLER(mullhw, 0x08, 0x0D), | |
7342 | GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C), | |
7343 | ||
0ff93d11 TM |
7344 | GEN_HANDLER2_E(tbegin, "tbegin", 0x1F, 0x0E, 0x14, 0x01DFF800, \ |
7345 | PPC_NONE, PPC2_TM), | |
56a84615 TM |
7346 | GEN_HANDLER2_E(tend, "tend", 0x1F, 0x0E, 0x15, 0x01FFF800, \ |
7347 | PPC_NONE, PPC2_TM), | |
7348 | GEN_HANDLER2_E(tabort, "tabort", 0x1F, 0x0E, 0x1C, 0x03E0F800, \ | |
7349 | PPC_NONE, PPC2_TM), | |
7350 | GEN_HANDLER2_E(tabortwc, "tabortwc", 0x1F, 0x0E, 0x18, 0x00000000, \ | |
7351 | PPC_NONE, PPC2_TM), | |
7352 | GEN_HANDLER2_E(tabortwci, "tabortwci", 0x1F, 0x0E, 0x1A, 0x00000000, \ | |
7353 | PPC_NONE, PPC2_TM), | |
7354 | GEN_HANDLER2_E(tabortdc, "tabortdc", 0x1F, 0x0E, 0x19, 0x00000000, \ | |
7355 | PPC_NONE, PPC2_TM), | |
7356 | GEN_HANDLER2_E(tabortdci, "tabortdci", 0x1F, 0x0E, 0x1B, 0x00000000, \ | |
7357 | PPC_NONE, PPC2_TM), | |
7358 | GEN_HANDLER2_E(tsr, "tsr", 0x1F, 0x0E, 0x17, 0x03DFF800, \ | |
7359 | PPC_NONE, PPC2_TM), | |
aeedd582 TM |
7360 | GEN_HANDLER2_E(tcheck, "tcheck", 0x1F, 0x0E, 0x16, 0x007FF800, \ |
7361 | PPC_NONE, PPC2_TM), | |
f83c2378 TM |
7362 | GEN_HANDLER2_E(treclaim, "treclaim", 0x1F, 0x0E, 0x1D, 0x03E0F800, \ |
7363 | PPC_NONE, PPC2_TM), | |
7364 | GEN_HANDLER2_E(trechkpt, "trechkpt", 0x1F, 0x0E, 0x1F, 0x03FFF800, \ | |
7365 | PPC_NONE, PPC2_TM), | |
15848410 BH |
7366 | |
7367 | #include "translate/fp-ops.inc.c" | |
7368 | ||
7369 | #include "translate/vmx-ops.inc.c" | |
7370 | ||
7371 | #include "translate/vsx-ops.inc.c" | |
7372 | ||
7373 | #include "translate/dfp-ops.inc.c" | |
7374 | ||
7375 | #include "translate/spe-ops.inc.c" | |
5c55ff99 BS |
7376 | }; |
7377 | ||
0411a972 | 7378 | #include "helper_regs.h" |
5b27a92d | 7379 | #include "translate_init.inc.c" |
79aceca5 | 7380 | |
9a64fbe4 | 7381 | /*****************************************************************************/ |
3fc6c082 | 7382 | /* Misc PowerPC helpers */ |
878096ee AF |
7383 | void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf, |
7384 | int flags) | |
79aceca5 | 7385 | { |
3fc6c082 FB |
7386 | #define RGPL 4 |
7387 | #define RFPL 4 | |
3fc6c082 | 7388 | |
878096ee AF |
7389 | PowerPCCPU *cpu = POWERPC_CPU(cs); |
7390 | CPUPPCState *env = &cpu->env; | |
79aceca5 FB |
7391 | int i; |
7392 | ||
90e189ec | 7393 | cpu_fprintf(f, "NIP " TARGET_FMT_lx " LR " TARGET_FMT_lx " CTR " |
21e5d28a TG |
7394 | TARGET_FMT_lx " XER " TARGET_FMT_lx " CPU#%d\n", |
7395 | env->nip, env->lr, env->ctr, cpu_read_xer(env), | |
7396 | cs->cpu_index); | |
90e189ec | 7397 | cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx " HF " |
9fb04491 BH |
7398 | TARGET_FMT_lx " iidx %d didx %d\n", |
7399 | env->msr, env->spr[SPR_HID0], | |
7400 | env->hflags, env->immu_idx, env->dmmu_idx); | |
d9bce9d9 | 7401 | #if !defined(NO_TIMER_DUMP) |
9a78eead | 7402 | cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64 |
76a66253 | 7403 | #if !defined(CONFIG_USER_ONLY) |
9a78eead | 7404 | " DECR %08" PRIu32 |
76a66253 JM |
7405 | #endif |
7406 | "\n", | |
077fc206 | 7407 | cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env) |
76a66253 JM |
7408 | #if !defined(CONFIG_USER_ONLY) |
7409 | , cpu_ppc_load_decr(env) | |
7410 | #endif | |
7411 | ); | |
077fc206 | 7412 | #endif |
76a66253 | 7413 | for (i = 0; i < 32; i++) { |
3fc6c082 FB |
7414 | if ((i & (RGPL - 1)) == 0) |
7415 | cpu_fprintf(f, "GPR%02d", i); | |
b11ebf64 | 7416 | cpu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i)); |
3fc6c082 | 7417 | if ((i & (RGPL - 1)) == (RGPL - 1)) |
7fe48483 | 7418 | cpu_fprintf(f, "\n"); |
76a66253 | 7419 | } |
3fc6c082 | 7420 | cpu_fprintf(f, "CR "); |
76a66253 | 7421 | for (i = 0; i < 8; i++) |
7fe48483 FB |
7422 | cpu_fprintf(f, "%01x", env->crf[i]); |
7423 | cpu_fprintf(f, " ["); | |
76a66253 JM |
7424 | for (i = 0; i < 8; i++) { |
7425 | char a = '-'; | |
7426 | if (env->crf[i] & 0x08) | |
7427 | a = 'L'; | |
7428 | else if (env->crf[i] & 0x04) | |
7429 | a = 'G'; | |
7430 | else if (env->crf[i] & 0x02) | |
7431 | a = 'E'; | |
7fe48483 | 7432 | cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' '); |
76a66253 | 7433 | } |
90e189ec BS |
7434 | cpu_fprintf(f, " ] RES " TARGET_FMT_lx "\n", |
7435 | env->reserve_addr); | |
685f1ce2 RH |
7436 | |
7437 | if (flags & CPU_DUMP_FPU) { | |
7438 | for (i = 0; i < 32; i++) { | |
7439 | if ((i & (RFPL - 1)) == 0) { | |
7440 | cpu_fprintf(f, "FPR%02d", i); | |
7441 | } | |
ef96e3ae | 7442 | cpu_fprintf(f, " %016" PRIx64, *cpu_fpr_ptr(env, i)); |
685f1ce2 RH |
7443 | if ((i & (RFPL - 1)) == (RFPL - 1)) { |
7444 | cpu_fprintf(f, "\n"); | |
7445 | } | |
7446 | } | |
7447 | cpu_fprintf(f, "FPSCR " TARGET_FMT_lx "\n", env->fpscr); | |
79aceca5 | 7448 | } |
685f1ce2 | 7449 | |
f2e63a42 | 7450 | #if !defined(CONFIG_USER_ONLY) |
90dc8812 SW |
7451 | cpu_fprintf(f, " SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx |
7452 | " PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n", | |
7453 | env->spr[SPR_SRR0], env->spr[SPR_SRR1], | |
7454 | env->spr[SPR_PVR], env->spr[SPR_VRSAVE]); | |
7455 | ||
7456 | cpu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx | |
7457 | " SPRG2 " TARGET_FMT_lx " SPRG3 " TARGET_FMT_lx "\n", | |
7458 | env->spr[SPR_SPRG0], env->spr[SPR_SPRG1], | |
7459 | env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]); | |
7460 | ||
7461 | cpu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx | |
7462 | " SPRG6 " TARGET_FMT_lx " SPRG7 " TARGET_FMT_lx "\n", | |
7463 | env->spr[SPR_SPRG4], env->spr[SPR_SPRG5], | |
7464 | env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]); | |
7465 | ||
f2b70fde BH |
7466 | #if defined(TARGET_PPC64) |
7467 | if (env->excp_model == POWERPC_EXCP_POWER7 || | |
7468 | env->excp_model == POWERPC_EXCP_POWER8) { | |
7469 | cpu_fprintf(f, "HSRR0 " TARGET_FMT_lx " HSRR1 " TARGET_FMT_lx "\n", | |
7470 | env->spr[SPR_HSRR0], env->spr[SPR_HSRR1]); | |
7471 | } | |
7472 | #endif | |
90dc8812 SW |
7473 | if (env->excp_model == POWERPC_EXCP_BOOKE) { |
7474 | cpu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx | |
7475 | " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n", | |
7476 | env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1], | |
7477 | env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]); | |
7478 | ||
7479 | cpu_fprintf(f, " TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx | |
7480 | " ESR " TARGET_FMT_lx " DEAR " TARGET_FMT_lx "\n", | |
7481 | env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR], | |
7482 | env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]); | |
7483 | ||
7484 | cpu_fprintf(f, " PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx | |
7485 | " IVPR " TARGET_FMT_lx " EPCR " TARGET_FMT_lx "\n", | |
7486 | env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR], | |
7487 | env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]); | |
7488 | ||
7489 | cpu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx | |
7490 | " EPR " TARGET_FMT_lx "\n", | |
7491 | env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8], | |
7492 | env->spr[SPR_BOOKE_EPR]); | |
7493 | ||
7494 | /* FSL-specific */ | |
7495 | cpu_fprintf(f, " MCAR " TARGET_FMT_lx " PID1 " TARGET_FMT_lx | |
7496 | " PID2 " TARGET_FMT_lx " SVR " TARGET_FMT_lx "\n", | |
7497 | env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1], | |
7498 | env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]); | |
7499 | ||
7500 | /* | |
7501 | * IVORs are left out as they are large and do not change often -- | |
7502 | * they can be read with "p $ivor0", "p $ivor1", etc. | |
7503 | */ | |
7504 | } | |
7505 | ||
697ab892 DG |
7506 | #if defined(TARGET_PPC64) |
7507 | if (env->flags & POWERPC_FLAG_CFAR) { | |
7508 | cpu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar); | |
7509 | } | |
7510 | #endif | |
7511 | ||
d801a61e SJS |
7512 | if (env->spr_cb[SPR_LPCR].name) |
7513 | cpu_fprintf(f, " LPCR " TARGET_FMT_lx "\n", env->spr[SPR_LPCR]); | |
7514 | ||
0941d728 | 7515 | switch (env->mmu_model) { |
90dc8812 SW |
7516 | case POWERPC_MMU_32B: |
7517 | case POWERPC_MMU_601: | |
7518 | case POWERPC_MMU_SOFT_6xx: | |
7519 | case POWERPC_MMU_SOFT_74xx: | |
7520 | #if defined(TARGET_PPC64) | |
0941d728 DG |
7521 | case POWERPC_MMU_64B: |
7522 | case POWERPC_MMU_2_03: | |
7523 | case POWERPC_MMU_2_06: | |
7524 | case POWERPC_MMU_2_07: | |
7525 | case POWERPC_MMU_3_00: | |
90dc8812 | 7526 | #endif |
4f4f28ff SJS |
7527 | if (env->spr_cb[SPR_SDR1].name) { /* SDR1 Exists */ |
7528 | cpu_fprintf(f, " SDR1 " TARGET_FMT_lx " ", env->spr[SPR_SDR1]); | |
7529 | } | |
4a7518e0 CLG |
7530 | if (env->spr_cb[SPR_PTCR].name) { /* PTCR Exists */ |
7531 | cpu_fprintf(f, " PTCR " TARGET_FMT_lx " ", env->spr[SPR_PTCR]); | |
7532 | } | |
4f4f28ff | 7533 | cpu_fprintf(f, " DAR " TARGET_FMT_lx " DSISR " TARGET_FMT_lx "\n", |
ca480de6 | 7534 | env->spr[SPR_DAR], env->spr[SPR_DSISR]); |
90dc8812 | 7535 | break; |
01662f3e | 7536 | case POWERPC_MMU_BOOKE206: |
90dc8812 SW |
7537 | cpu_fprintf(f, " MAS0 " TARGET_FMT_lx " MAS1 " TARGET_FMT_lx |
7538 | " MAS2 " TARGET_FMT_lx " MAS3 " TARGET_FMT_lx "\n", | |
7539 | env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1], | |
7540 | env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]); | |
7541 | ||
7542 | cpu_fprintf(f, " MAS4 " TARGET_FMT_lx " MAS6 " TARGET_FMT_lx | |
7543 | " MAS7 " TARGET_FMT_lx " PID " TARGET_FMT_lx "\n", | |
7544 | env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6], | |
7545 | env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]); | |
7546 | ||
7547 | cpu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx | |
7548 | " TLB1CFG " TARGET_FMT_lx "\n", | |
7549 | env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG], | |
7550 | env->spr[SPR_BOOKE_TLB1CFG]); | |
7551 | break; | |
7552 | default: | |
7553 | break; | |
7554 | } | |
f2e63a42 | 7555 | #endif |
79aceca5 | 7556 | |
3fc6c082 FB |
7557 | #undef RGPL |
7558 | #undef RFPL | |
79aceca5 FB |
7559 | } |
7560 | ||
878096ee AF |
7561 | void ppc_cpu_dump_statistics(CPUState *cs, FILE*f, |
7562 | fprintf_function cpu_fprintf, int flags) | |
76a66253 JM |
7563 | { |
7564 | #if defined(DO_PPC_STATISTICS) | |
878096ee | 7565 | PowerPCCPU *cpu = POWERPC_CPU(cs); |
c227f099 | 7566 | opc_handler_t **t1, **t2, **t3, *handler; |
76a66253 JM |
7567 | int op1, op2, op3; |
7568 | ||
878096ee | 7569 | t1 = cpu->env.opcodes; |
76a66253 JM |
7570 | for (op1 = 0; op1 < 64; op1++) { |
7571 | handler = t1[op1]; | |
7572 | if (is_indirect_opcode(handler)) { | |
7573 | t2 = ind_table(handler); | |
7574 | for (op2 = 0; op2 < 32; op2++) { | |
7575 | handler = t2[op2]; | |
7576 | if (is_indirect_opcode(handler)) { | |
7577 | t3 = ind_table(handler); | |
7578 | for (op3 = 0; op3 < 32; op3++) { | |
7579 | handler = t3[op3]; | |
7580 | if (handler->count == 0) | |
7581 | continue; | |
7582 | cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: " | |
0bfcd599 | 7583 | "%016" PRIx64 " %" PRId64 "\n", |
76a66253 JM |
7584 | op1, op2, op3, op1, (op3 << 5) | op2, |
7585 | handler->oname, | |
7586 | handler->count, handler->count); | |
7587 | } | |
7588 | } else { | |
7589 | if (handler->count == 0) | |
7590 | continue; | |
7591 | cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: " | |
0bfcd599 | 7592 | "%016" PRIx64 " %" PRId64 "\n", |
76a66253 JM |
7593 | op1, op2, op1, op2, handler->oname, |
7594 | handler->count, handler->count); | |
7595 | } | |
7596 | } | |
7597 | } else { | |
7598 | if (handler->count == 0) | |
7599 | continue; | |
0bfcd599 BS |
7600 | cpu_fprintf(f, "%02x (%02x ) %16s: %016" PRIx64 |
7601 | " %" PRId64 "\n", | |
76a66253 JM |
7602 | op1, op1, handler->oname, |
7603 | handler->count, handler->count); | |
7604 | } | |
7605 | } | |
7606 | #endif | |
7607 | } | |
7608 | ||
b542683d | 7609 | static void ppc_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) |
79aceca5 | 7610 | { |
b0c2d521 | 7611 | DisasContext *ctx = container_of(dcbase, DisasContext, base); |
9c489ea6 | 7612 | CPUPPCState *env = cs->env_ptr; |
b0c2d521 EC |
7613 | int bound; |
7614 | ||
7615 | ctx->exception = POWERPC_EXCP_NONE; | |
7616 | ctx->spr_cb = env->spr_cb; | |
7617 | ctx->pr = msr_pr; | |
7618 | ctx->mem_idx = env->dmmu_idx; | |
7619 | ctx->dr = msr_dr; | |
932ccbdd | 7620 | #if !defined(CONFIG_USER_ONLY) |
b0c2d521 | 7621 | ctx->hv = msr_hv || !env->has_hv_mode; |
932ccbdd | 7622 | #endif |
b0c2d521 EC |
7623 | ctx->insns_flags = env->insns_flags; |
7624 | ctx->insns_flags2 = env->insns_flags2; | |
7625 | ctx->access_type = -1; | |
7626 | ctx->need_access_type = !(env->mmu_model & POWERPC_MMU_64B); | |
7627 | ctx->le_mode = !!(env->hflags & (1 << MSR_LE)); | |
7628 | ctx->default_tcg_memop_mask = ctx->le_mode ? MO_LE : MO_BE; | |
0e3bf489 | 7629 | ctx->flags = env->flags; |
d9bce9d9 | 7630 | #if defined(TARGET_PPC64) |
b0c2d521 EC |
7631 | ctx->sf_mode = msr_is_64bit(env, env->msr); |
7632 | ctx->has_cfar = !!(env->flags & POWERPC_FLAG_CFAR); | |
9a64fbe4 | 7633 | #endif |
e69ba2b4 DG |
7634 | ctx->lazy_tlb_flush = env->mmu_model == POWERPC_MMU_32B |
7635 | || env->mmu_model == POWERPC_MMU_601 | |
7636 | || (env->mmu_model & POWERPC_MMU_64B); | |
c5a8d8f3 | 7637 | |
b0c2d521 | 7638 | ctx->fpu_enabled = !!msr_fp; |
a9d9eb8f | 7639 | if ((env->flags & POWERPC_FLAG_SPE) && msr_spe) |
b0c2d521 | 7640 | ctx->spe_enabled = !!msr_spe; |
d26bfc9a | 7641 | else |
b0c2d521 | 7642 | ctx->spe_enabled = false; |
a9d9eb8f | 7643 | if ((env->flags & POWERPC_FLAG_VRE) && msr_vr) |
b0c2d521 | 7644 | ctx->altivec_enabled = !!msr_vr; |
a9d9eb8f | 7645 | else |
b0c2d521 | 7646 | ctx->altivec_enabled = false; |
1f29871c | 7647 | if ((env->flags & POWERPC_FLAG_VSX) && msr_vsx) { |
b0c2d521 | 7648 | ctx->vsx_enabled = !!msr_vsx; |
1f29871c | 7649 | } else { |
b0c2d521 | 7650 | ctx->vsx_enabled = false; |
1f29871c | 7651 | } |
69d1a937 TM |
7652 | #if defined(TARGET_PPC64) |
7653 | if ((env->flags & POWERPC_FLAG_TM) && msr_tm) { | |
b0c2d521 | 7654 | ctx->tm_enabled = !!msr_tm; |
69d1a937 | 7655 | } else { |
b0c2d521 | 7656 | ctx->tm_enabled = false; |
69d1a937 TM |
7657 | } |
7658 | #endif | |
b0c2d521 | 7659 | ctx->gtse = !!(env->spr[SPR_LPCR] & LPCR_GTSE); |
d26bfc9a | 7660 | if ((env->flags & POWERPC_FLAG_SE) && msr_se) |
b0c2d521 | 7661 | ctx->singlestep_enabled = CPU_SINGLE_STEP; |
d26bfc9a | 7662 | else |
b0c2d521 | 7663 | ctx->singlestep_enabled = 0; |
d26bfc9a | 7664 | if ((env->flags & POWERPC_FLAG_BE) && msr_be) |
b0c2d521 | 7665 | ctx->singlestep_enabled |= CPU_BRANCH_STEP; |
0e3bf489 RK |
7666 | if ((env->flags & POWERPC_FLAG_DE) && msr_de) { |
7667 | ctx->singlestep_enabled = 0; | |
7668 | target_ulong dbcr0 = env->spr[SPR_BOOKE_DBCR0]; | |
7669 | if (dbcr0 & DBCR0_ICMP) { | |
7670 | ctx->singlestep_enabled |= CPU_SINGLE_STEP; | |
7671 | } | |
7672 | if (dbcr0 & DBCR0_BRT) { | |
7673 | ctx->singlestep_enabled |= CPU_BRANCH_STEP; | |
7674 | } | |
7675 | ||
7676 | } | |
b0c2d521 EC |
7677 | if (unlikely(ctx->base.singlestep_enabled)) { |
7678 | ctx->singlestep_enabled |= GDBSTUB_SINGLE_STEP; | |
ed2803da | 7679 | } |
3fc6c082 | 7680 | #if defined (DO_SINGLE_STEP) && 0 |
9a64fbe4 FB |
7681 | /* Single step trace mode */ |
7682 | msr_se = 1; | |
7683 | #endif | |
b933066a | 7684 | |
b0c2d521 | 7685 | bound = -(ctx->base.pc_first | TARGET_PAGE_MASK) / 4; |
b542683d | 7686 | ctx->base.max_insns = MIN(ctx->base.max_insns, bound); |
b0c2d521 EC |
7687 | } |
7688 | ||
7689 | static void ppc_tr_tb_start(DisasContextBase *db, CPUState *cs) | |
7690 | { | |
7691 | } | |
7692 | ||
7693 | static void ppc_tr_insn_start(DisasContextBase *dcbase, CPUState *cs) | |
7694 | { | |
7695 | tcg_gen_insn_start(dcbase->pc_next); | |
7696 | } | |
7697 | ||
7698 | static bool ppc_tr_breakpoint_check(DisasContextBase *dcbase, CPUState *cs, | |
7699 | const CPUBreakpoint *bp) | |
7700 | { | |
7701 | DisasContext *ctx = container_of(dcbase, DisasContext, base); | |
7702 | ||
7703 | gen_debug_exception(ctx); | |
2a8ceefc | 7704 | dcbase->is_jmp = DISAS_NORETURN; |
b0c2d521 EC |
7705 | /* The address covered by the breakpoint must be included in |
7706 | [tb->pc, tb->pc + tb->size) in order to for it to be | |
7707 | properly cleared -- thus we increment the PC here so that | |
7708 | the logic setting tb->size below does the right thing. */ | |
7709 | ctx->base.pc_next += 4; | |
7710 | return true; | |
7711 | } | |
7712 | ||
7713 | static void ppc_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) | |
7714 | { | |
7715 | DisasContext *ctx = container_of(dcbase, DisasContext, base); | |
7716 | CPUPPCState *env = cs->env_ptr; | |
7717 | opc_handler_t **table, *handler; | |
7718 | ||
7719 | LOG_DISAS("----------------\n"); | |
7720 | LOG_DISAS("nip=" TARGET_FMT_lx " super=%d ir=%d\n", | |
7721 | ctx->base.pc_next, ctx->mem_idx, (int)msr_ir); | |
7722 | ||
7723 | if (unlikely(need_byteswap(ctx))) { | |
7724 | ctx->opcode = bswap32(cpu_ldl_code(env, ctx->base.pc_next)); | |
7725 | } else { | |
7726 | ctx->opcode = cpu_ldl_code(env, ctx->base.pc_next); | |
7727 | } | |
7728 | LOG_DISAS("translate opcode %08x (%02x %02x %02x %02x) (%s)\n", | |
7729 | ctx->opcode, opc1(ctx->opcode), opc2(ctx->opcode), | |
7730 | opc3(ctx->opcode), opc4(ctx->opcode), | |
7731 | ctx->le_mode ? "little" : "big"); | |
7732 | ctx->base.pc_next += 4; | |
7733 | table = env->opcodes; | |
7734 | handler = table[opc1(ctx->opcode)]; | |
7735 | if (is_indirect_opcode(handler)) { | |
7736 | table = ind_table(handler); | |
7737 | handler = table[opc2(ctx->opcode)]; | |
79aceca5 FB |
7738 | if (is_indirect_opcode(handler)) { |
7739 | table = ind_table(handler); | |
b0c2d521 | 7740 | handler = table[opc3(ctx->opcode)]; |
79aceca5 FB |
7741 | if (is_indirect_opcode(handler)) { |
7742 | table = ind_table(handler); | |
b0c2d521 | 7743 | handler = table[opc4(ctx->opcode)]; |
79aceca5 FB |
7744 | } |
7745 | } | |
b0c2d521 EC |
7746 | } |
7747 | /* Is opcode *REALLY* valid ? */ | |
7748 | if (unlikely(handler->handler == &gen_invalid)) { | |
7749 | qemu_log_mask(LOG_GUEST_ERROR, "invalid/unsupported opcode: " | |
7750 | "%02x - %02x - %02x - %02x (%08x) " | |
7751 | TARGET_FMT_lx " %d\n", | |
7752 | opc1(ctx->opcode), opc2(ctx->opcode), | |
7753 | opc3(ctx->opcode), opc4(ctx->opcode), | |
7754 | ctx->opcode, ctx->base.pc_next - 4, (int)msr_ir); | |
7755 | } else { | |
7756 | uint32_t inval; | |
70560da7 | 7757 | |
b0c2d521 EC |
7758 | if (unlikely(handler->type & (PPC_SPE | PPC_SPE_SINGLE | PPC_SPE_DOUBLE) |
7759 | && Rc(ctx->opcode))) { | |
7760 | inval = handler->inval2; | |
7761 | } else { | |
7762 | inval = handler->inval1; | |
7763 | } | |
70560da7 | 7764 | |
b0c2d521 EC |
7765 | if (unlikely((ctx->opcode & inval) != 0)) { |
7766 | qemu_log_mask(LOG_GUEST_ERROR, "invalid bits: %08x for opcode: " | |
7767 | "%02x - %02x - %02x - %02x (%08x) " | |
7768 | TARGET_FMT_lx "\n", ctx->opcode & inval, | |
7769 | opc1(ctx->opcode), opc2(ctx->opcode), | |
7770 | opc3(ctx->opcode), opc4(ctx->opcode), | |
7771 | ctx->opcode, ctx->base.pc_next - 4); | |
7772 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); | |
7773 | ctx->base.is_jmp = DISAS_NORETURN; | |
7774 | return; | |
79aceca5 | 7775 | } |
b0c2d521 EC |
7776 | } |
7777 | (*(handler->handler))(ctx); | |
76a66253 | 7778 | #if defined(DO_PPC_STATISTICS) |
b0c2d521 | 7779 | handler->count++; |
76a66253 | 7780 | #endif |
b0c2d521 EC |
7781 | /* Check trace mode exceptions */ |
7782 | if (unlikely(ctx->singlestep_enabled & CPU_SINGLE_STEP && | |
7783 | (ctx->base.pc_next <= 0x100 || ctx->base.pc_next > 0xF00) && | |
7784 | ctx->exception != POWERPC_SYSCALL && | |
7785 | ctx->exception != POWERPC_EXCP_TRAP && | |
7786 | ctx->exception != POWERPC_EXCP_BRANCH)) { | |
e150ac89 RK |
7787 | uint32_t excp = gen_prep_dbgex(ctx); |
7788 | gen_exception_nip(ctx, excp, ctx->base.pc_next); | |
b0c2d521 EC |
7789 | } |
7790 | ||
7791 | if (tcg_check_temp_count()) { | |
7792 | qemu_log("Opcode %02x %02x %02x %02x (%08x) leaked " | |
7793 | "temporaries\n", opc1(ctx->opcode), opc2(ctx->opcode), | |
7794 | opc3(ctx->opcode), opc4(ctx->opcode), ctx->opcode); | |
3fc6c082 | 7795 | } |
b0c2d521 EC |
7796 | |
7797 | ctx->base.is_jmp = ctx->exception == POWERPC_EXCP_NONE ? | |
7798 | DISAS_NEXT : DISAS_NORETURN; | |
7799 | } | |
7800 | ||
7801 | static void ppc_tr_tb_stop(DisasContextBase *dcbase, CPUState *cs) | |
7802 | { | |
7803 | DisasContext *ctx = container_of(dcbase, DisasContext, base); | |
7804 | ||
7805 | if (ctx->exception == POWERPC_EXCP_NONE) { | |
7806 | gen_goto_tb(ctx, 0, ctx->base.pc_next); | |
7807 | } else if (ctx->exception != POWERPC_EXCP_BRANCH) { | |
7808 | if (unlikely(ctx->base.singlestep_enabled)) { | |
7809 | gen_debug_exception(ctx); | |
8cbcb4fa | 7810 | } |
76a66253 | 7811 | /* Generate the return instruction */ |
07ea28b4 | 7812 | tcg_gen_exit_tb(NULL, 0); |
9a64fbe4 | 7813 | } |
b0c2d521 EC |
7814 | } |
7815 | ||
7816 | static void ppc_tr_disas_log(const DisasContextBase *dcbase, CPUState *cs) | |
7817 | { | |
7818 | qemu_log("IN: %s\n", lookup_symbol(dcbase->pc_first)); | |
7819 | log_target_disas(cs, dcbase->pc_first, dcbase->tb->size); | |
7820 | } | |
0a7df5da | 7821 | |
b0c2d521 EC |
7822 | static const TranslatorOps ppc_tr_ops = { |
7823 | .init_disas_context = ppc_tr_init_disas_context, | |
7824 | .tb_start = ppc_tr_tb_start, | |
7825 | .insn_start = ppc_tr_insn_start, | |
7826 | .breakpoint_check = ppc_tr_breakpoint_check, | |
7827 | .translate_insn = ppc_tr_translate_insn, | |
7828 | .tb_stop = ppc_tr_tb_stop, | |
7829 | .disas_log = ppc_tr_disas_log, | |
7830 | }; | |
4e5e1215 | 7831 | |
b0c2d521 EC |
7832 | void gen_intermediate_code(CPUState *cs, struct TranslationBlock *tb) |
7833 | { | |
7834 | DisasContext ctx; | |
7835 | ||
7836 | translator_loop(&ppc_tr_ops, &ctx.base, cs, tb); | |
79aceca5 FB |
7837 | } |
7838 | ||
bad729e2 RH |
7839 | void restore_state_to_opc(CPUPPCState *env, TranslationBlock *tb, |
7840 | target_ulong *data) | |
d2856f1a | 7841 | { |
bad729e2 | 7842 | env->nip = data[0]; |
d2856f1a | 7843 | } |