]>
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 | |
79aceca5 | 21 | #include "cpu.h" |
76cad711 | 22 | #include "disas/disas.h" |
57fec1fe | 23 | #include "tcg-op.h" |
1de7afc9 | 24 | #include "qemu/host-utils.h" |
79aceca5 | 25 | |
a7812ae4 PB |
26 | #include "helper.h" |
27 | #define GEN_HELPER 1 | |
28 | #include "helper.h" | |
29 | ||
8cbcb4fa AJ |
30 | #define CPU_SINGLE_STEP 0x1 |
31 | #define CPU_BRANCH_STEP 0x2 | |
32 | #define GDBSTUB_SINGLE_STEP 0x4 | |
33 | ||
a750fc0b | 34 | /* Include definitions for instructions classes and implementations flags */ |
9fddaa0c | 35 | //#define PPC_DEBUG_DISAS |
76a66253 | 36 | //#define DO_PPC_STATISTICS |
79aceca5 | 37 | |
d12d51d5 | 38 | #ifdef PPC_DEBUG_DISAS |
93fcfe39 | 39 | # define LOG_DISAS(...) qemu_log_mask(CPU_LOG_TB_IN_ASM, ## __VA_ARGS__) |
d12d51d5 AL |
40 | #else |
41 | # define LOG_DISAS(...) do { } while (0) | |
42 | #endif | |
a750fc0b JM |
43 | /*****************************************************************************/ |
44 | /* Code translation helpers */ | |
c53be334 | 45 | |
f78fb44e | 46 | /* global register indexes */ |
a7812ae4 | 47 | static TCGv_ptr cpu_env; |
1d542695 | 48 | static char cpu_reg_names[10*3 + 22*4 /* GPR */ |
f78fb44e | 49 | #if !defined(TARGET_PPC64) |
1d542695 | 50 | + 10*4 + 22*5 /* SPE GPRh */ |
f78fb44e | 51 | #endif |
a5e26afa | 52 | + 10*4 + 22*5 /* FPR */ |
47e4661c | 53 | + 2*(10*6 + 22*7) /* AVRh, AVRl */ |
472b24ce | 54 | + 10*5 + 22*6 /* VSR */ |
47e4661c | 55 | + 8*5 /* CRF */]; |
f78fb44e AJ |
56 | static TCGv cpu_gpr[32]; |
57 | #if !defined(TARGET_PPC64) | |
58 | static TCGv cpu_gprh[32]; | |
59 | #endif | |
a7812ae4 PB |
60 | static TCGv_i64 cpu_fpr[32]; |
61 | static TCGv_i64 cpu_avrh[32], cpu_avrl[32]; | |
472b24ce | 62 | static TCGv_i64 cpu_vsr[32]; |
a7812ae4 | 63 | static TCGv_i32 cpu_crf[8]; |
bd568f18 | 64 | static TCGv cpu_nip; |
6527f6ea | 65 | static TCGv cpu_msr; |
cfdcd37a AJ |
66 | static TCGv cpu_ctr; |
67 | static TCGv cpu_lr; | |
697ab892 DG |
68 | #if defined(TARGET_PPC64) |
69 | static TCGv cpu_cfar; | |
70 | #endif | |
da91a00f | 71 | static TCGv cpu_xer, cpu_so, cpu_ov, cpu_ca; |
cf360a32 | 72 | static TCGv cpu_reserve; |
30304420 | 73 | static TCGv cpu_fpscr; |
a7859e89 | 74 | static TCGv_i32 cpu_access_type; |
f78fb44e | 75 | |
022c62cb | 76 | #include "exec/gen-icount.h" |
2e70f6ef PB |
77 | |
78 | void ppc_translate_init(void) | |
79 | { | |
f78fb44e AJ |
80 | int i; |
81 | char* p; | |
2dc766da | 82 | size_t cpu_reg_names_size; |
b2437bf2 | 83 | static int done_init = 0; |
f78fb44e | 84 | |
2e70f6ef PB |
85 | if (done_init) |
86 | return; | |
f78fb44e | 87 | |
a7812ae4 | 88 | cpu_env = tcg_global_reg_new_ptr(TCG_AREG0, "env"); |
a7812ae4 | 89 | |
f78fb44e | 90 | p = cpu_reg_names; |
2dc766da | 91 | cpu_reg_names_size = sizeof(cpu_reg_names); |
47e4661c AJ |
92 | |
93 | for (i = 0; i < 8; i++) { | |
2dc766da | 94 | snprintf(p, cpu_reg_names_size, "crf%d", i); |
a7812ae4 | 95 | cpu_crf[i] = tcg_global_mem_new_i32(TCG_AREG0, |
1328c2bf | 96 | offsetof(CPUPPCState, crf[i]), p); |
47e4661c | 97 | p += 5; |
2dc766da | 98 | cpu_reg_names_size -= 5; |
47e4661c AJ |
99 | } |
100 | ||
f78fb44e | 101 | for (i = 0; i < 32; i++) { |
2dc766da | 102 | snprintf(p, cpu_reg_names_size, "r%d", i); |
a7812ae4 | 103 | cpu_gpr[i] = tcg_global_mem_new(TCG_AREG0, |
1328c2bf | 104 | offsetof(CPUPPCState, gpr[i]), p); |
f78fb44e | 105 | p += (i < 10) ? 3 : 4; |
2dc766da | 106 | cpu_reg_names_size -= (i < 10) ? 3 : 4; |
f78fb44e | 107 | #if !defined(TARGET_PPC64) |
2dc766da | 108 | snprintf(p, cpu_reg_names_size, "r%dH", i); |
a7812ae4 | 109 | cpu_gprh[i] = tcg_global_mem_new_i32(TCG_AREG0, |
1328c2bf | 110 | offsetof(CPUPPCState, gprh[i]), p); |
f78fb44e | 111 | p += (i < 10) ? 4 : 5; |
2dc766da | 112 | cpu_reg_names_size -= (i < 10) ? 4 : 5; |
f78fb44e | 113 | #endif |
1d542695 | 114 | |
2dc766da | 115 | snprintf(p, cpu_reg_names_size, "fp%d", i); |
a7812ae4 | 116 | cpu_fpr[i] = tcg_global_mem_new_i64(TCG_AREG0, |
1328c2bf | 117 | offsetof(CPUPPCState, fpr[i]), p); |
ec1ac72d | 118 | p += (i < 10) ? 4 : 5; |
2dc766da | 119 | cpu_reg_names_size -= (i < 10) ? 4 : 5; |
a5e26afa | 120 | |
2dc766da | 121 | snprintf(p, cpu_reg_names_size, "avr%dH", i); |
e2542fe2 | 122 | #ifdef HOST_WORDS_BIGENDIAN |
fe1e5c53 | 123 | cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0, |
1328c2bf | 124 | offsetof(CPUPPCState, avr[i].u64[0]), p); |
fe1e5c53 | 125 | #else |
a7812ae4 | 126 | cpu_avrh[i] = tcg_global_mem_new_i64(TCG_AREG0, |
1328c2bf | 127 | offsetof(CPUPPCState, avr[i].u64[1]), p); |
fe1e5c53 | 128 | #endif |
1d542695 | 129 | p += (i < 10) ? 6 : 7; |
2dc766da | 130 | cpu_reg_names_size -= (i < 10) ? 6 : 7; |
ec1ac72d | 131 | |
2dc766da | 132 | snprintf(p, cpu_reg_names_size, "avr%dL", i); |
e2542fe2 | 133 | #ifdef HOST_WORDS_BIGENDIAN |
fe1e5c53 | 134 | cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0, |
1328c2bf | 135 | offsetof(CPUPPCState, avr[i].u64[1]), p); |
fe1e5c53 | 136 | #else |
a7812ae4 | 137 | cpu_avrl[i] = tcg_global_mem_new_i64(TCG_AREG0, |
1328c2bf | 138 | offsetof(CPUPPCState, avr[i].u64[0]), p); |
fe1e5c53 | 139 | #endif |
1d542695 | 140 | p += (i < 10) ? 6 : 7; |
2dc766da | 141 | cpu_reg_names_size -= (i < 10) ? 6 : 7; |
472b24ce TM |
142 | snprintf(p, cpu_reg_names_size, "vsr%d", i); |
143 | cpu_vsr[i] = tcg_global_mem_new_i64(TCG_AREG0, | |
144 | offsetof(CPUPPCState, vsr[i]), p); | |
145 | p += (i < 10) ? 5 : 6; | |
146 | cpu_reg_names_size -= (i < 10) ? 5 : 6; | |
f78fb44e | 147 | } |
f10dc08e | 148 | |
a7812ae4 | 149 | cpu_nip = tcg_global_mem_new(TCG_AREG0, |
1328c2bf | 150 | offsetof(CPUPPCState, nip), "nip"); |
bd568f18 | 151 | |
6527f6ea | 152 | cpu_msr = tcg_global_mem_new(TCG_AREG0, |
1328c2bf | 153 | offsetof(CPUPPCState, msr), "msr"); |
6527f6ea | 154 | |
a7812ae4 | 155 | cpu_ctr = tcg_global_mem_new(TCG_AREG0, |
1328c2bf | 156 | offsetof(CPUPPCState, ctr), "ctr"); |
cfdcd37a | 157 | |
a7812ae4 | 158 | cpu_lr = tcg_global_mem_new(TCG_AREG0, |
1328c2bf | 159 | offsetof(CPUPPCState, lr), "lr"); |
cfdcd37a | 160 | |
697ab892 DG |
161 | #if defined(TARGET_PPC64) |
162 | cpu_cfar = tcg_global_mem_new(TCG_AREG0, | |
1328c2bf | 163 | offsetof(CPUPPCState, cfar), "cfar"); |
697ab892 DG |
164 | #endif |
165 | ||
a7812ae4 | 166 | cpu_xer = tcg_global_mem_new(TCG_AREG0, |
1328c2bf | 167 | offsetof(CPUPPCState, xer), "xer"); |
da91a00f RH |
168 | cpu_so = tcg_global_mem_new(TCG_AREG0, |
169 | offsetof(CPUPPCState, so), "SO"); | |
170 | cpu_ov = tcg_global_mem_new(TCG_AREG0, | |
171 | offsetof(CPUPPCState, ov), "OV"); | |
172 | cpu_ca = tcg_global_mem_new(TCG_AREG0, | |
173 | offsetof(CPUPPCState, ca), "CA"); | |
3d7b417e | 174 | |
cf360a32 | 175 | cpu_reserve = tcg_global_mem_new(TCG_AREG0, |
1328c2bf | 176 | offsetof(CPUPPCState, reserve_addr), |
18b21a2f | 177 | "reserve_addr"); |
cf360a32 | 178 | |
30304420 DG |
179 | cpu_fpscr = tcg_global_mem_new(TCG_AREG0, |
180 | offsetof(CPUPPCState, fpscr), "fpscr"); | |
e1571908 | 181 | |
a7859e89 | 182 | cpu_access_type = tcg_global_mem_new_i32(TCG_AREG0, |
1328c2bf | 183 | offsetof(CPUPPCState, access_type), "access_type"); |
a7859e89 | 184 | |
2e70f6ef PB |
185 | done_init = 1; |
186 | } | |
187 | ||
79aceca5 FB |
188 | /* internal defines */ |
189 | typedef struct DisasContext { | |
190 | struct TranslationBlock *tb; | |
0fa85d43 | 191 | target_ulong nip; |
79aceca5 | 192 | uint32_t opcode; |
9a64fbe4 | 193 | uint32_t exception; |
3cc62370 FB |
194 | /* Routine used to access memory */ |
195 | int mem_idx; | |
76db3ba4 | 196 | int access_type; |
3cc62370 | 197 | /* Translation flags */ |
76db3ba4 | 198 | int le_mode; |
d9bce9d9 JM |
199 | #if defined(TARGET_PPC64) |
200 | int sf_mode; | |
697ab892 | 201 | int has_cfar; |
9a64fbe4 | 202 | #endif |
3cc62370 | 203 | int fpu_enabled; |
a9d9eb8f | 204 | int altivec_enabled; |
1f29871c | 205 | int vsx_enabled; |
0487d6a8 | 206 | int spe_enabled; |
c227f099 | 207 | ppc_spr_t *spr_cb; /* Needed to check rights for mfspr/mtspr */ |
ea4e754f | 208 | int singlestep_enabled; |
7d08d856 AJ |
209 | uint64_t insns_flags; |
210 | uint64_t insns_flags2; | |
79aceca5 FB |
211 | } DisasContext; |
212 | ||
79482e5a RH |
213 | /* True when active word size < size of target_long. */ |
214 | #ifdef TARGET_PPC64 | |
215 | # define NARROW_MODE(C) (!(C)->sf_mode) | |
216 | #else | |
217 | # define NARROW_MODE(C) 0 | |
218 | #endif | |
219 | ||
c227f099 | 220 | struct opc_handler_t { |
70560da7 FC |
221 | /* invalid bits for instruction 1 (Rc(opcode) == 0) */ |
222 | uint32_t inval1; | |
223 | /* invalid bits for instruction 2 (Rc(opcode) == 1) */ | |
224 | uint32_t inval2; | |
9a64fbe4 | 225 | /* instruction type */ |
0487d6a8 | 226 | uint64_t type; |
a5858d7a AG |
227 | /* extended instruction type */ |
228 | uint64_t type2; | |
79aceca5 FB |
229 | /* handler */ |
230 | void (*handler)(DisasContext *ctx); | |
a750fc0b | 231 | #if defined(DO_PPC_STATISTICS) || defined(PPC_DUMP_CPU) |
b55266b5 | 232 | const char *oname; |
a750fc0b JM |
233 | #endif |
234 | #if defined(DO_PPC_STATISTICS) | |
76a66253 JM |
235 | uint64_t count; |
236 | #endif | |
3fc6c082 | 237 | }; |
79aceca5 | 238 | |
636aa200 | 239 | static inline void gen_reset_fpstatus(void) |
7c58044c | 240 | { |
8e703949 | 241 | gen_helper_reset_fpstatus(cpu_env); |
7c58044c JM |
242 | } |
243 | ||
636aa200 | 244 | static inline void gen_compute_fprf(TCGv_i64 arg, int set_fprf, int set_rc) |
7c58044c | 245 | { |
0f2f39c2 | 246 | TCGv_i32 t0 = tcg_temp_new_i32(); |
af12906f | 247 | |
7c58044c JM |
248 | if (set_fprf != 0) { |
249 | /* This case might be optimized later */ | |
0f2f39c2 | 250 | tcg_gen_movi_i32(t0, 1); |
8e703949 | 251 | gen_helper_compute_fprf(t0, cpu_env, arg, t0); |
a7812ae4 | 252 | if (unlikely(set_rc)) { |
0f2f39c2 | 253 | tcg_gen_mov_i32(cpu_crf[1], t0); |
a7812ae4 | 254 | } |
8e703949 | 255 | gen_helper_float_check_status(cpu_env); |
7c58044c JM |
256 | } else if (unlikely(set_rc)) { |
257 | /* We always need to compute fpcc */ | |
0f2f39c2 | 258 | tcg_gen_movi_i32(t0, 0); |
8e703949 | 259 | gen_helper_compute_fprf(t0, cpu_env, arg, t0); |
0f2f39c2 | 260 | tcg_gen_mov_i32(cpu_crf[1], t0); |
7c58044c | 261 | } |
af12906f | 262 | |
0f2f39c2 | 263 | tcg_temp_free_i32(t0); |
7c58044c JM |
264 | } |
265 | ||
636aa200 | 266 | static inline void gen_set_access_type(DisasContext *ctx, int access_type) |
a7859e89 | 267 | { |
76db3ba4 AJ |
268 | if (ctx->access_type != access_type) { |
269 | tcg_gen_movi_i32(cpu_access_type, access_type); | |
270 | ctx->access_type = access_type; | |
271 | } | |
a7859e89 AJ |
272 | } |
273 | ||
636aa200 | 274 | static inline void gen_update_nip(DisasContext *ctx, target_ulong nip) |
d9bce9d9 | 275 | { |
e0c8f9ce RH |
276 | if (NARROW_MODE(ctx)) { |
277 | nip = (uint32_t)nip; | |
278 | } | |
279 | tcg_gen_movi_tl(cpu_nip, nip); | |
d9bce9d9 JM |
280 | } |
281 | ||
636aa200 | 282 | static inline void gen_exception_err(DisasContext *ctx, uint32_t excp, uint32_t error) |
e06fcd75 AJ |
283 | { |
284 | TCGv_i32 t0, t1; | |
285 | if (ctx->exception == POWERPC_EXCP_NONE) { | |
286 | gen_update_nip(ctx, ctx->nip); | |
287 | } | |
288 | t0 = tcg_const_i32(excp); | |
289 | t1 = tcg_const_i32(error); | |
e5f17ac6 | 290 | gen_helper_raise_exception_err(cpu_env, t0, t1); |
e06fcd75 AJ |
291 | tcg_temp_free_i32(t0); |
292 | tcg_temp_free_i32(t1); | |
293 | ctx->exception = (excp); | |
294 | } | |
e1833e1f | 295 | |
636aa200 | 296 | static inline void gen_exception(DisasContext *ctx, uint32_t excp) |
e06fcd75 AJ |
297 | { |
298 | TCGv_i32 t0; | |
299 | if (ctx->exception == POWERPC_EXCP_NONE) { | |
300 | gen_update_nip(ctx, ctx->nip); | |
301 | } | |
302 | t0 = tcg_const_i32(excp); | |
e5f17ac6 | 303 | gen_helper_raise_exception(cpu_env, t0); |
e06fcd75 AJ |
304 | tcg_temp_free_i32(t0); |
305 | ctx->exception = (excp); | |
306 | } | |
e1833e1f | 307 | |
636aa200 | 308 | static inline void gen_debug_exception(DisasContext *ctx) |
e06fcd75 AJ |
309 | { |
310 | TCGv_i32 t0; | |
5518f3a6 | 311 | |
ee2b3994 SB |
312 | if ((ctx->exception != POWERPC_EXCP_BRANCH) && |
313 | (ctx->exception != POWERPC_EXCP_SYNC)) { | |
5518f3a6 | 314 | gen_update_nip(ctx, ctx->nip); |
ee2b3994 | 315 | } |
e06fcd75 | 316 | t0 = tcg_const_i32(EXCP_DEBUG); |
e5f17ac6 | 317 | gen_helper_raise_exception(cpu_env, t0); |
e06fcd75 AJ |
318 | tcg_temp_free_i32(t0); |
319 | } | |
9a64fbe4 | 320 | |
636aa200 | 321 | static inline void gen_inval_exception(DisasContext *ctx, uint32_t error) |
e06fcd75 AJ |
322 | { |
323 | gen_exception_err(ctx, POWERPC_EXCP_PROGRAM, POWERPC_EXCP_INVAL | error); | |
324 | } | |
a9d9eb8f | 325 | |
f24e5695 | 326 | /* Stop translation */ |
636aa200 | 327 | static inline void gen_stop_exception(DisasContext *ctx) |
3fc6c082 | 328 | { |
d9bce9d9 | 329 | gen_update_nip(ctx, ctx->nip); |
e1833e1f | 330 | ctx->exception = POWERPC_EXCP_STOP; |
3fc6c082 FB |
331 | } |
332 | ||
f24e5695 | 333 | /* No need to update nip here, as execution flow will change */ |
636aa200 | 334 | static inline void gen_sync_exception(DisasContext *ctx) |
2be0071f | 335 | { |
e1833e1f | 336 | ctx->exception = POWERPC_EXCP_SYNC; |
2be0071f FB |
337 | } |
338 | ||
79aceca5 | 339 | #define GEN_HANDLER(name, opc1, opc2, opc3, inval, type) \ |
a5858d7a AG |
340 | GEN_OPCODE(name, opc1, opc2, opc3, inval, type, PPC_NONE) |
341 | ||
342 | #define GEN_HANDLER_E(name, opc1, opc2, opc3, inval, type, type2) \ | |
343 | GEN_OPCODE(name, opc1, opc2, opc3, inval, type, type2) | |
79aceca5 | 344 | |
c7697e1f | 345 | #define GEN_HANDLER2(name, onam, opc1, opc2, opc3, inval, type) \ |
a5858d7a AG |
346 | GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, PPC_NONE) |
347 | ||
348 | #define GEN_HANDLER2_E(name, onam, opc1, opc2, opc3, inval, type, type2) \ | |
349 | GEN_OPCODE2(name, onam, opc1, opc2, opc3, inval, type, type2) | |
c7697e1f | 350 | |
c227f099 | 351 | typedef struct opcode_t { |
79aceca5 | 352 | unsigned char opc1, opc2, opc3; |
1235fc06 | 353 | #if HOST_LONG_BITS == 64 /* Explicitly align to 64 bits */ |
18fba28c FB |
354 | unsigned char pad[5]; |
355 | #else | |
356 | unsigned char pad[1]; | |
357 | #endif | |
c227f099 | 358 | opc_handler_t handler; |
b55266b5 | 359 | const char *oname; |
c227f099 | 360 | } opcode_t; |
79aceca5 | 361 | |
a750fc0b | 362 | /*****************************************************************************/ |
79aceca5 FB |
363 | /*** Instruction decoding ***/ |
364 | #define EXTRACT_HELPER(name, shift, nb) \ | |
636aa200 | 365 | static inline uint32_t name(uint32_t opcode) \ |
79aceca5 FB |
366 | { \ |
367 | return (opcode >> (shift)) & ((1 << (nb)) - 1); \ | |
368 | } | |
369 | ||
370 | #define EXTRACT_SHELPER(name, shift, nb) \ | |
636aa200 | 371 | static inline int32_t name(uint32_t opcode) \ |
79aceca5 | 372 | { \ |
18fba28c | 373 | return (int16_t)((opcode >> (shift)) & ((1 << (nb)) - 1)); \ |
79aceca5 FB |
374 | } |
375 | ||
f9fc6d81 TM |
376 | #define EXTRACT_HELPER_SPLIT(name, shift1, nb1, shift2, nb2) \ |
377 | static inline uint32_t name(uint32_t opcode) \ | |
378 | { \ | |
379 | return (((opcode >> (shift1)) & ((1 << (nb1)) - 1)) << nb2) | \ | |
380 | ((opcode >> (shift2)) & ((1 << (nb2)) - 1)); \ | |
381 | } | |
79aceca5 FB |
382 | /* Opcode part 1 */ |
383 | EXTRACT_HELPER(opc1, 26, 6); | |
384 | /* Opcode part 2 */ | |
385 | EXTRACT_HELPER(opc2, 1, 5); | |
386 | /* Opcode part 3 */ | |
387 | EXTRACT_HELPER(opc3, 6, 5); | |
388 | /* Update Cr0 flags */ | |
389 | EXTRACT_HELPER(Rc, 0, 1); | |
390 | /* Destination */ | |
391 | EXTRACT_HELPER(rD, 21, 5); | |
392 | /* Source */ | |
393 | EXTRACT_HELPER(rS, 21, 5); | |
394 | /* First operand */ | |
395 | EXTRACT_HELPER(rA, 16, 5); | |
396 | /* Second operand */ | |
397 | EXTRACT_HELPER(rB, 11, 5); | |
398 | /* Third operand */ | |
399 | EXTRACT_HELPER(rC, 6, 5); | |
400 | /*** Get CRn ***/ | |
401 | EXTRACT_HELPER(crfD, 23, 3); | |
402 | EXTRACT_HELPER(crfS, 18, 3); | |
403 | EXTRACT_HELPER(crbD, 21, 5); | |
404 | EXTRACT_HELPER(crbA, 16, 5); | |
405 | EXTRACT_HELPER(crbB, 11, 5); | |
406 | /* SPR / TBL */ | |
3fc6c082 | 407 | EXTRACT_HELPER(_SPR, 11, 10); |
636aa200 | 408 | static inline uint32_t SPR(uint32_t opcode) |
3fc6c082 FB |
409 | { |
410 | uint32_t sprn = _SPR(opcode); | |
411 | ||
412 | return ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5); | |
413 | } | |
79aceca5 FB |
414 | /*** Get constants ***/ |
415 | EXTRACT_HELPER(IMM, 12, 8); | |
416 | /* 16 bits signed immediate value */ | |
417 | EXTRACT_SHELPER(SIMM, 0, 16); | |
418 | /* 16 bits unsigned immediate value */ | |
419 | EXTRACT_HELPER(UIMM, 0, 16); | |
21d21583 AJ |
420 | /* 5 bits signed immediate value */ |
421 | EXTRACT_HELPER(SIMM5, 16, 5); | |
27a4edb3 AJ |
422 | /* 5 bits signed immediate value */ |
423 | EXTRACT_HELPER(UIMM5, 16, 5); | |
79aceca5 FB |
424 | /* Bit count */ |
425 | EXTRACT_HELPER(NB, 11, 5); | |
426 | /* Shift count */ | |
427 | EXTRACT_HELPER(SH, 11, 5); | |
cd633b10 AJ |
428 | /* Vector shift count */ |
429 | EXTRACT_HELPER(VSH, 6, 4); | |
79aceca5 FB |
430 | /* Mask start */ |
431 | EXTRACT_HELPER(MB, 6, 5); | |
432 | /* Mask end */ | |
433 | EXTRACT_HELPER(ME, 1, 5); | |
fb0eaffc FB |
434 | /* Trap operand */ |
435 | EXTRACT_HELPER(TO, 21, 5); | |
79aceca5 FB |
436 | |
437 | EXTRACT_HELPER(CRM, 12, 8); | |
79aceca5 | 438 | EXTRACT_HELPER(SR, 16, 4); |
7d08d856 AJ |
439 | |
440 | /* mtfsf/mtfsfi */ | |
779f6590 | 441 | EXTRACT_HELPER(FPBF, 23, 3); |
e4bb997e | 442 | EXTRACT_HELPER(FPIMM, 12, 4); |
779f6590 | 443 | EXTRACT_HELPER(FPL, 25, 1); |
7d08d856 AJ |
444 | EXTRACT_HELPER(FPFLM, 17, 8); |
445 | EXTRACT_HELPER(FPW, 16, 1); | |
fb0eaffc | 446 | |
79aceca5 FB |
447 | /*** Jump target decoding ***/ |
448 | /* Displacement */ | |
449 | EXTRACT_SHELPER(d, 0, 16); | |
450 | /* Immediate address */ | |
636aa200 | 451 | static inline target_ulong LI(uint32_t opcode) |
79aceca5 FB |
452 | { |
453 | return (opcode >> 0) & 0x03FFFFFC; | |
454 | } | |
455 | ||
636aa200 | 456 | static inline uint32_t BD(uint32_t opcode) |
79aceca5 FB |
457 | { |
458 | return (opcode >> 0) & 0xFFFC; | |
459 | } | |
460 | ||
461 | EXTRACT_HELPER(BO, 21, 5); | |
462 | EXTRACT_HELPER(BI, 16, 5); | |
463 | /* Absolute/relative address */ | |
464 | EXTRACT_HELPER(AA, 1, 1); | |
465 | /* Link */ | |
466 | EXTRACT_HELPER(LK, 0, 1); | |
467 | ||
468 | /* Create a mask between <start> and <end> bits */ | |
636aa200 | 469 | static inline target_ulong MASK(uint32_t start, uint32_t end) |
79aceca5 | 470 | { |
76a66253 | 471 | target_ulong ret; |
79aceca5 | 472 | |
76a66253 JM |
473 | #if defined(TARGET_PPC64) |
474 | if (likely(start == 0)) { | |
6f2d8978 | 475 | ret = UINT64_MAX << (63 - end); |
76a66253 | 476 | } else if (likely(end == 63)) { |
6f2d8978 | 477 | ret = UINT64_MAX >> start; |
76a66253 JM |
478 | } |
479 | #else | |
480 | if (likely(start == 0)) { | |
6f2d8978 | 481 | ret = UINT32_MAX << (31 - end); |
76a66253 | 482 | } else if (likely(end == 31)) { |
6f2d8978 | 483 | ret = UINT32_MAX >> start; |
76a66253 JM |
484 | } |
485 | #endif | |
486 | else { | |
487 | ret = (((target_ulong)(-1ULL)) >> (start)) ^ | |
488 | (((target_ulong)(-1ULL) >> (end)) >> 1); | |
489 | if (unlikely(start > end)) | |
490 | return ~ret; | |
491 | } | |
79aceca5 FB |
492 | |
493 | return ret; | |
494 | } | |
495 | ||
f9fc6d81 TM |
496 | EXTRACT_HELPER_SPLIT(xT, 0, 1, 21, 5); |
497 | EXTRACT_HELPER_SPLIT(xS, 0, 1, 21, 5); | |
498 | EXTRACT_HELPER_SPLIT(xA, 2, 1, 16, 5); | |
499 | EXTRACT_HELPER_SPLIT(xB, 1, 1, 11, 5); | |
551e3ef7 | 500 | EXTRACT_HELPER_SPLIT(xC, 3, 1, 6, 5); |
f9fc6d81 | 501 | EXTRACT_HELPER(DM, 8, 2); |
76c15fe0 | 502 | EXTRACT_HELPER(UIM, 16, 2); |
acc42968 | 503 | EXTRACT_HELPER(SHW, 8, 2); |
a750fc0b | 504 | /*****************************************************************************/ |
a750fc0b | 505 | /* PowerPC instructions table */ |
933dc6eb | 506 | |
76a66253 | 507 | #if defined(DO_PPC_STATISTICS) |
a5858d7a | 508 | #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \ |
5c55ff99 | 509 | { \ |
79aceca5 FB |
510 | .opc1 = op1, \ |
511 | .opc2 = op2, \ | |
512 | .opc3 = op3, \ | |
18fba28c | 513 | .pad = { 0, }, \ |
79aceca5 | 514 | .handler = { \ |
70560da7 FC |
515 | .inval1 = invl, \ |
516 | .type = _typ, \ | |
517 | .type2 = _typ2, \ | |
518 | .handler = &gen_##name, \ | |
519 | .oname = stringify(name), \ | |
520 | }, \ | |
521 | .oname = stringify(name), \ | |
522 | } | |
523 | #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \ | |
524 | { \ | |
525 | .opc1 = op1, \ | |
526 | .opc2 = op2, \ | |
527 | .opc3 = op3, \ | |
528 | .pad = { 0, }, \ | |
529 | .handler = { \ | |
530 | .inval1 = invl1, \ | |
531 | .inval2 = invl2, \ | |
9a64fbe4 | 532 | .type = _typ, \ |
a5858d7a | 533 | .type2 = _typ2, \ |
79aceca5 | 534 | .handler = &gen_##name, \ |
76a66253 | 535 | .oname = stringify(name), \ |
79aceca5 | 536 | }, \ |
3fc6c082 | 537 | .oname = stringify(name), \ |
79aceca5 | 538 | } |
a5858d7a | 539 | #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \ |
5c55ff99 | 540 | { \ |
c7697e1f JM |
541 | .opc1 = op1, \ |
542 | .opc2 = op2, \ | |
543 | .opc3 = op3, \ | |
544 | .pad = { 0, }, \ | |
545 | .handler = { \ | |
70560da7 | 546 | .inval1 = invl, \ |
c7697e1f | 547 | .type = _typ, \ |
a5858d7a | 548 | .type2 = _typ2, \ |
c7697e1f JM |
549 | .handler = &gen_##name, \ |
550 | .oname = onam, \ | |
551 | }, \ | |
552 | .oname = onam, \ | |
553 | } | |
76a66253 | 554 | #else |
a5858d7a | 555 | #define GEN_OPCODE(name, op1, op2, op3, invl, _typ, _typ2) \ |
5c55ff99 | 556 | { \ |
c7697e1f JM |
557 | .opc1 = op1, \ |
558 | .opc2 = op2, \ | |
559 | .opc3 = op3, \ | |
560 | .pad = { 0, }, \ | |
561 | .handler = { \ | |
70560da7 FC |
562 | .inval1 = invl, \ |
563 | .type = _typ, \ | |
564 | .type2 = _typ2, \ | |
565 | .handler = &gen_##name, \ | |
566 | }, \ | |
567 | .oname = stringify(name), \ | |
568 | } | |
569 | #define GEN_OPCODE_DUAL(name, op1, op2, op3, invl1, invl2, _typ, _typ2) \ | |
570 | { \ | |
571 | .opc1 = op1, \ | |
572 | .opc2 = op2, \ | |
573 | .opc3 = op3, \ | |
574 | .pad = { 0, }, \ | |
575 | .handler = { \ | |
576 | .inval1 = invl1, \ | |
577 | .inval2 = invl2, \ | |
c7697e1f | 578 | .type = _typ, \ |
a5858d7a | 579 | .type2 = _typ2, \ |
c7697e1f | 580 | .handler = &gen_##name, \ |
5c55ff99 BS |
581 | }, \ |
582 | .oname = stringify(name), \ | |
583 | } | |
a5858d7a | 584 | #define GEN_OPCODE2(name, onam, op1, op2, op3, invl, _typ, _typ2) \ |
5c55ff99 BS |
585 | { \ |
586 | .opc1 = op1, \ | |
587 | .opc2 = op2, \ | |
588 | .opc3 = op3, \ | |
589 | .pad = { 0, }, \ | |
590 | .handler = { \ | |
70560da7 | 591 | .inval1 = invl, \ |
5c55ff99 | 592 | .type = _typ, \ |
a5858d7a | 593 | .type2 = _typ2, \ |
5c55ff99 BS |
594 | .handler = &gen_##name, \ |
595 | }, \ | |
596 | .oname = onam, \ | |
597 | } | |
598 | #endif | |
2e610050 | 599 | |
5c55ff99 | 600 | /* SPR load/store helpers */ |
636aa200 | 601 | static inline void gen_load_spr(TCGv t, int reg) |
5c55ff99 | 602 | { |
1328c2bf | 603 | tcg_gen_ld_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg])); |
5c55ff99 | 604 | } |
2e610050 | 605 | |
636aa200 | 606 | static inline void gen_store_spr(int reg, TCGv t) |
5c55ff99 | 607 | { |
1328c2bf | 608 | tcg_gen_st_tl(t, cpu_env, offsetof(CPUPPCState, spr[reg])); |
5c55ff99 | 609 | } |
2e610050 | 610 | |
54623277 | 611 | /* Invalid instruction */ |
99e300ef | 612 | static void gen_invalid(DisasContext *ctx) |
9a64fbe4 | 613 | { |
e06fcd75 | 614 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
9a64fbe4 FB |
615 | } |
616 | ||
c227f099 | 617 | static opc_handler_t invalid_handler = { |
70560da7 FC |
618 | .inval1 = 0xFFFFFFFF, |
619 | .inval2 = 0xFFFFFFFF, | |
9a64fbe4 | 620 | .type = PPC_NONE, |
a5858d7a | 621 | .type2 = PPC_NONE, |
79aceca5 FB |
622 | .handler = gen_invalid, |
623 | }; | |
624 | ||
e1571908 AJ |
625 | /*** Integer comparison ***/ |
626 | ||
636aa200 | 627 | static inline void gen_op_cmp(TCGv arg0, TCGv arg1, int s, int crf) |
e1571908 | 628 | { |
2fdcb629 RH |
629 | TCGv t0 = tcg_temp_new(); |
630 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
e1571908 | 631 | |
da91a00f | 632 | tcg_gen_trunc_tl_i32(cpu_crf[crf], cpu_so); |
e1571908 | 633 | |
2fdcb629 RH |
634 | tcg_gen_setcond_tl((s ? TCG_COND_LT: TCG_COND_LTU), t0, arg0, arg1); |
635 | tcg_gen_trunc_tl_i32(t1, t0); | |
636 | tcg_gen_shli_i32(t1, t1, CRF_LT); | |
637 | tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1); | |
638 | ||
639 | tcg_gen_setcond_tl((s ? TCG_COND_GT: TCG_COND_GTU), t0, arg0, arg1); | |
640 | tcg_gen_trunc_tl_i32(t1, t0); | |
641 | tcg_gen_shli_i32(t1, t1, CRF_GT); | |
642 | tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1); | |
643 | ||
644 | tcg_gen_setcond_tl(TCG_COND_EQ, t0, arg0, arg1); | |
645 | tcg_gen_trunc_tl_i32(t1, t0); | |
646 | tcg_gen_shli_i32(t1, t1, CRF_EQ); | |
647 | tcg_gen_or_i32(cpu_crf[crf], cpu_crf[crf], t1); | |
648 | ||
649 | tcg_temp_free(t0); | |
650 | tcg_temp_free_i32(t1); | |
e1571908 AJ |
651 | } |
652 | ||
636aa200 | 653 | static inline void gen_op_cmpi(TCGv arg0, target_ulong arg1, int s, int crf) |
e1571908 | 654 | { |
2fdcb629 | 655 | TCGv t0 = tcg_const_tl(arg1); |
ea363694 AJ |
656 | gen_op_cmp(arg0, t0, s, crf); |
657 | tcg_temp_free(t0); | |
e1571908 AJ |
658 | } |
659 | ||
636aa200 | 660 | static inline void gen_op_cmp32(TCGv arg0, TCGv arg1, int s, int crf) |
e1571908 | 661 | { |
ea363694 | 662 | TCGv t0, t1; |
2fdcb629 RH |
663 | t0 = tcg_temp_new(); |
664 | t1 = tcg_temp_new(); | |
e1571908 | 665 | if (s) { |
ea363694 AJ |
666 | tcg_gen_ext32s_tl(t0, arg0); |
667 | tcg_gen_ext32s_tl(t1, arg1); | |
e1571908 | 668 | } else { |
ea363694 AJ |
669 | tcg_gen_ext32u_tl(t0, arg0); |
670 | tcg_gen_ext32u_tl(t1, arg1); | |
e1571908 | 671 | } |
ea363694 AJ |
672 | gen_op_cmp(t0, t1, s, crf); |
673 | tcg_temp_free(t1); | |
674 | tcg_temp_free(t0); | |
e1571908 AJ |
675 | } |
676 | ||
636aa200 | 677 | static inline void gen_op_cmpi32(TCGv arg0, target_ulong arg1, int s, int crf) |
e1571908 | 678 | { |
2fdcb629 | 679 | TCGv t0 = tcg_const_tl(arg1); |
ea363694 AJ |
680 | gen_op_cmp32(arg0, t0, s, crf); |
681 | tcg_temp_free(t0); | |
e1571908 | 682 | } |
e1571908 | 683 | |
636aa200 | 684 | static inline void gen_set_Rc0(DisasContext *ctx, TCGv reg) |
e1571908 | 685 | { |
02765534 | 686 | if (NARROW_MODE(ctx)) { |
e1571908 | 687 | gen_op_cmpi32(reg, 0, 1, 0); |
02765534 | 688 | } else { |
e1571908 | 689 | gen_op_cmpi(reg, 0, 1, 0); |
02765534 | 690 | } |
e1571908 AJ |
691 | } |
692 | ||
693 | /* cmp */ | |
99e300ef | 694 | static void gen_cmp(DisasContext *ctx) |
e1571908 | 695 | { |
36f48d9c | 696 | if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) { |
e1571908 AJ |
697 | gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], |
698 | 1, crfD(ctx->opcode)); | |
36f48d9c AG |
699 | } else { |
700 | gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], | |
701 | 1, crfD(ctx->opcode)); | |
02765534 | 702 | } |
e1571908 AJ |
703 | } |
704 | ||
705 | /* cmpi */ | |
99e300ef | 706 | static void gen_cmpi(DisasContext *ctx) |
e1571908 | 707 | { |
36f48d9c | 708 | if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) { |
e1571908 AJ |
709 | gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode), |
710 | 1, crfD(ctx->opcode)); | |
36f48d9c AG |
711 | } else { |
712 | gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], SIMM(ctx->opcode), | |
713 | 1, crfD(ctx->opcode)); | |
02765534 | 714 | } |
e1571908 AJ |
715 | } |
716 | ||
717 | /* cmpl */ | |
99e300ef | 718 | static void gen_cmpl(DisasContext *ctx) |
e1571908 | 719 | { |
36f48d9c | 720 | if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) { |
e1571908 AJ |
721 | gen_op_cmp(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], |
722 | 0, crfD(ctx->opcode)); | |
36f48d9c AG |
723 | } else { |
724 | gen_op_cmp32(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], | |
725 | 0, crfD(ctx->opcode)); | |
02765534 | 726 | } |
e1571908 AJ |
727 | } |
728 | ||
729 | /* cmpli */ | |
99e300ef | 730 | static void gen_cmpli(DisasContext *ctx) |
e1571908 | 731 | { |
36f48d9c | 732 | if ((ctx->opcode & 0x00200000) && (ctx->insns_flags & PPC_64B)) { |
e1571908 AJ |
733 | gen_op_cmpi(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode), |
734 | 0, crfD(ctx->opcode)); | |
36f48d9c AG |
735 | } else { |
736 | gen_op_cmpi32(cpu_gpr[rA(ctx->opcode)], UIMM(ctx->opcode), | |
737 | 0, crfD(ctx->opcode)); | |
02765534 | 738 | } |
e1571908 AJ |
739 | } |
740 | ||
741 | /* isel (PowerPC 2.03 specification) */ | |
99e300ef | 742 | static void gen_isel(DisasContext *ctx) |
e1571908 AJ |
743 | { |
744 | int l1, l2; | |
745 | uint32_t bi = rC(ctx->opcode); | |
746 | uint32_t mask; | |
a7812ae4 | 747 | TCGv_i32 t0; |
e1571908 AJ |
748 | |
749 | l1 = gen_new_label(); | |
750 | l2 = gen_new_label(); | |
751 | ||
752 | mask = 1 << (3 - (bi & 0x03)); | |
a7812ae4 | 753 | t0 = tcg_temp_new_i32(); |
fea0c503 AJ |
754 | tcg_gen_andi_i32(t0, cpu_crf[bi >> 2], mask); |
755 | tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1); | |
e1571908 AJ |
756 | if (rA(ctx->opcode) == 0) |
757 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0); | |
758 | else | |
759 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
760 | tcg_gen_br(l2); | |
761 | gen_set_label(l1); | |
762 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
763 | gen_set_label(l2); | |
a7812ae4 | 764 | tcg_temp_free_i32(t0); |
e1571908 AJ |
765 | } |
766 | ||
fcfda20f AJ |
767 | /* cmpb: PowerPC 2.05 specification */ |
768 | static void gen_cmpb(DisasContext *ctx) | |
769 | { | |
770 | gen_helper_cmpb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], | |
771 | cpu_gpr[rB(ctx->opcode)]); | |
772 | } | |
773 | ||
79aceca5 | 774 | /*** Integer arithmetic ***/ |
79aceca5 | 775 | |
636aa200 BS |
776 | static inline void gen_op_arith_compute_ov(DisasContext *ctx, TCGv arg0, |
777 | TCGv arg1, TCGv arg2, int sub) | |
74637406 | 778 | { |
ffe30937 | 779 | TCGv t0 = tcg_temp_new(); |
79aceca5 | 780 | |
8e7a6db9 | 781 | tcg_gen_xor_tl(cpu_ov, arg0, arg2); |
74637406 | 782 | tcg_gen_xor_tl(t0, arg1, arg2); |
ffe30937 RH |
783 | if (sub) { |
784 | tcg_gen_and_tl(cpu_ov, cpu_ov, t0); | |
785 | } else { | |
786 | tcg_gen_andc_tl(cpu_ov, cpu_ov, t0); | |
787 | } | |
788 | tcg_temp_free(t0); | |
02765534 | 789 | if (NARROW_MODE(ctx)) { |
ffe30937 RH |
790 | tcg_gen_ext32s_tl(cpu_ov, cpu_ov); |
791 | } | |
ffe30937 RH |
792 | tcg_gen_shri_tl(cpu_ov, cpu_ov, TARGET_LONG_BITS - 1); |
793 | tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov); | |
79aceca5 FB |
794 | } |
795 | ||
74637406 | 796 | /* Common add function */ |
636aa200 | 797 | static inline void gen_op_arith_add(DisasContext *ctx, TCGv ret, TCGv arg1, |
b5a73f8d RH |
798 | TCGv arg2, bool add_ca, bool compute_ca, |
799 | bool compute_ov, bool compute_rc0) | |
74637406 | 800 | { |
b5a73f8d | 801 | TCGv t0 = ret; |
d9bce9d9 | 802 | |
752d634e | 803 | if (compute_ca || compute_ov) { |
146de60d | 804 | t0 = tcg_temp_new(); |
74637406 | 805 | } |
79aceca5 | 806 | |
da91a00f | 807 | if (compute_ca) { |
79482e5a | 808 | if (NARROW_MODE(ctx)) { |
752d634e RH |
809 | /* Caution: a non-obvious corner case of the spec is that we |
810 | must produce the *entire* 64-bit addition, but produce the | |
811 | carry into bit 32. */ | |
79482e5a | 812 | TCGv t1 = tcg_temp_new(); |
752d634e RH |
813 | tcg_gen_xor_tl(t1, arg1, arg2); /* add without carry */ |
814 | tcg_gen_add_tl(t0, arg1, arg2); | |
79482e5a RH |
815 | if (add_ca) { |
816 | tcg_gen_add_tl(t0, t0, cpu_ca); | |
817 | } | |
752d634e RH |
818 | tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changed w/ carry */ |
819 | tcg_temp_free(t1); | |
820 | tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */ | |
821 | tcg_gen_andi_tl(cpu_ca, cpu_ca, 1); | |
b5a73f8d | 822 | } else { |
79482e5a RH |
823 | TCGv zero = tcg_const_tl(0); |
824 | if (add_ca) { | |
825 | tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, cpu_ca, zero); | |
826 | tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, arg2, zero); | |
827 | } else { | |
828 | tcg_gen_add2_tl(t0, cpu_ca, arg1, zero, arg2, zero); | |
829 | } | |
830 | tcg_temp_free(zero); | |
b5a73f8d | 831 | } |
b5a73f8d RH |
832 | } else { |
833 | tcg_gen_add_tl(t0, arg1, arg2); | |
834 | if (add_ca) { | |
835 | tcg_gen_add_tl(t0, t0, cpu_ca); | |
836 | } | |
da91a00f | 837 | } |
79aceca5 | 838 | |
74637406 AJ |
839 | if (compute_ov) { |
840 | gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 0); | |
841 | } | |
b5a73f8d | 842 | if (unlikely(compute_rc0)) { |
74637406 | 843 | gen_set_Rc0(ctx, t0); |
b5a73f8d | 844 | } |
74637406 | 845 | |
a7812ae4 | 846 | if (!TCGV_EQUAL(t0, ret)) { |
74637406 AJ |
847 | tcg_gen_mov_tl(ret, t0); |
848 | tcg_temp_free(t0); | |
849 | } | |
39dd32ee | 850 | } |
74637406 AJ |
851 | /* Add functions with two operands */ |
852 | #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \ | |
b5a73f8d | 853 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 AJ |
854 | { \ |
855 | gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \ | |
856 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
b5a73f8d | 857 | add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \ |
74637406 AJ |
858 | } |
859 | /* Add functions with one operand and one immediate */ | |
860 | #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \ | |
861 | add_ca, compute_ca, compute_ov) \ | |
b5a73f8d | 862 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 | 863 | { \ |
b5a73f8d | 864 | TCGv t0 = tcg_const_tl(const_val); \ |
74637406 AJ |
865 | gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], \ |
866 | cpu_gpr[rA(ctx->opcode)], t0, \ | |
b5a73f8d | 867 | add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \ |
74637406 AJ |
868 | tcg_temp_free(t0); \ |
869 | } | |
870 | ||
871 | /* add add. addo addo. */ | |
872 | GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0) | |
873 | GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1) | |
874 | /* addc addc. addco addco. */ | |
875 | GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0) | |
876 | GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1) | |
877 | /* adde adde. addeo addeo. */ | |
878 | GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0) | |
879 | GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1) | |
880 | /* addme addme. addmeo addmeo. */ | |
881 | GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0) | |
882 | GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1) | |
883 | /* addze addze. addzeo addzeo.*/ | |
884 | GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0) | |
885 | GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1) | |
886 | /* addi */ | |
99e300ef | 887 | static void gen_addi(DisasContext *ctx) |
d9bce9d9 | 888 | { |
74637406 AJ |
889 | target_long simm = SIMM(ctx->opcode); |
890 | ||
891 | if (rA(ctx->opcode) == 0) { | |
892 | /* li case */ | |
893 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm); | |
894 | } else { | |
b5a73f8d RH |
895 | tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)], |
896 | cpu_gpr[rA(ctx->opcode)], simm); | |
74637406 | 897 | } |
d9bce9d9 | 898 | } |
74637406 | 899 | /* addic addic.*/ |
b5a73f8d | 900 | static inline void gen_op_addic(DisasContext *ctx, bool compute_rc0) |
d9bce9d9 | 901 | { |
b5a73f8d RH |
902 | TCGv c = tcg_const_tl(SIMM(ctx->opcode)); |
903 | gen_op_arith_add(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], | |
904 | c, 0, 1, 0, compute_rc0); | |
905 | tcg_temp_free(c); | |
d9bce9d9 | 906 | } |
99e300ef BS |
907 | |
908 | static void gen_addic(DisasContext *ctx) | |
d9bce9d9 | 909 | { |
b5a73f8d | 910 | gen_op_addic(ctx, 0); |
d9bce9d9 | 911 | } |
e8eaa2c0 BS |
912 | |
913 | static void gen_addic_(DisasContext *ctx) | |
d9bce9d9 | 914 | { |
b5a73f8d | 915 | gen_op_addic(ctx, 1); |
d9bce9d9 | 916 | } |
99e300ef | 917 | |
54623277 | 918 | /* addis */ |
99e300ef | 919 | static void gen_addis(DisasContext *ctx) |
d9bce9d9 | 920 | { |
74637406 AJ |
921 | target_long simm = SIMM(ctx->opcode); |
922 | ||
923 | if (rA(ctx->opcode) == 0) { | |
924 | /* lis case */ | |
925 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], simm << 16); | |
926 | } else { | |
b5a73f8d RH |
927 | tcg_gen_addi_tl(cpu_gpr[rD(ctx->opcode)], |
928 | cpu_gpr[rA(ctx->opcode)], simm << 16); | |
74637406 | 929 | } |
d9bce9d9 | 930 | } |
74637406 | 931 | |
636aa200 BS |
932 | static inline void gen_op_arith_divw(DisasContext *ctx, TCGv ret, TCGv arg1, |
933 | TCGv arg2, int sign, int compute_ov) | |
d9bce9d9 | 934 | { |
2ef1b120 AJ |
935 | int l1 = gen_new_label(); |
936 | int l2 = gen_new_label(); | |
a7812ae4 PB |
937 | TCGv_i32 t0 = tcg_temp_local_new_i32(); |
938 | TCGv_i32 t1 = tcg_temp_local_new_i32(); | |
74637406 | 939 | |
2ef1b120 AJ |
940 | tcg_gen_trunc_tl_i32(t0, arg1); |
941 | tcg_gen_trunc_tl_i32(t1, arg2); | |
942 | tcg_gen_brcondi_i32(TCG_COND_EQ, t1, 0, l1); | |
74637406 | 943 | if (sign) { |
2ef1b120 AJ |
944 | int l3 = gen_new_label(); |
945 | tcg_gen_brcondi_i32(TCG_COND_NE, t1, -1, l3); | |
946 | tcg_gen_brcondi_i32(TCG_COND_EQ, t0, INT32_MIN, l1); | |
74637406 | 947 | gen_set_label(l3); |
2ef1b120 | 948 | tcg_gen_div_i32(t0, t0, t1); |
74637406 | 949 | } else { |
2ef1b120 | 950 | tcg_gen_divu_i32(t0, t0, t1); |
74637406 AJ |
951 | } |
952 | if (compute_ov) { | |
da91a00f | 953 | tcg_gen_movi_tl(cpu_ov, 0); |
74637406 AJ |
954 | } |
955 | tcg_gen_br(l2); | |
956 | gen_set_label(l1); | |
957 | if (sign) { | |
2ef1b120 | 958 | tcg_gen_sari_i32(t0, t0, 31); |
74637406 AJ |
959 | } else { |
960 | tcg_gen_movi_i32(t0, 0); | |
961 | } | |
962 | if (compute_ov) { | |
da91a00f RH |
963 | tcg_gen_movi_tl(cpu_ov, 1); |
964 | tcg_gen_movi_tl(cpu_so, 1); | |
74637406 AJ |
965 | } |
966 | gen_set_label(l2); | |
2ef1b120 | 967 | tcg_gen_extu_i32_tl(ret, t0); |
a7812ae4 PB |
968 | tcg_temp_free_i32(t0); |
969 | tcg_temp_free_i32(t1); | |
74637406 AJ |
970 | if (unlikely(Rc(ctx->opcode) != 0)) |
971 | gen_set_Rc0(ctx, ret); | |
d9bce9d9 | 972 | } |
74637406 AJ |
973 | /* Div functions */ |
974 | #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \ | |
99e300ef | 975 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 AJ |
976 | { \ |
977 | gen_op_arith_divw(ctx, cpu_gpr[rD(ctx->opcode)], \ | |
978 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
979 | sign, compute_ov); \ | |
980 | } | |
981 | /* divwu divwu. divwuo divwuo. */ | |
982 | GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0); | |
983 | GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1); | |
984 | /* divw divw. divwo divwo. */ | |
985 | GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0); | |
986 | GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1); | |
98d1eb27 TM |
987 | |
988 | /* div[wd]eu[o][.] */ | |
989 | #define GEN_DIVE(name, hlpr, compute_ov) \ | |
990 | static void gen_##name(DisasContext *ctx) \ | |
991 | { \ | |
992 | TCGv_i32 t0 = tcg_const_i32(compute_ov); \ | |
993 | gen_helper_##hlpr(cpu_gpr[rD(ctx->opcode)], cpu_env, \ | |
994 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); \ | |
995 | tcg_temp_free_i32(t0); \ | |
996 | if (unlikely(Rc(ctx->opcode) != 0)) { \ | |
997 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); \ | |
998 | } \ | |
999 | } | |
1000 | ||
6a4fda33 TM |
1001 | GEN_DIVE(divweu, divweu, 0); |
1002 | GEN_DIVE(divweuo, divweu, 1); | |
a98eb9e9 TM |
1003 | GEN_DIVE(divwe, divwe, 0); |
1004 | GEN_DIVE(divweo, divwe, 1); | |
6a4fda33 | 1005 | |
d9bce9d9 | 1006 | #if defined(TARGET_PPC64) |
636aa200 BS |
1007 | static inline void gen_op_arith_divd(DisasContext *ctx, TCGv ret, TCGv arg1, |
1008 | TCGv arg2, int sign, int compute_ov) | |
d9bce9d9 | 1009 | { |
2ef1b120 AJ |
1010 | int l1 = gen_new_label(); |
1011 | int l2 = gen_new_label(); | |
74637406 AJ |
1012 | |
1013 | tcg_gen_brcondi_i64(TCG_COND_EQ, arg2, 0, l1); | |
1014 | if (sign) { | |
2ef1b120 | 1015 | int l3 = gen_new_label(); |
74637406 AJ |
1016 | tcg_gen_brcondi_i64(TCG_COND_NE, arg2, -1, l3); |
1017 | tcg_gen_brcondi_i64(TCG_COND_EQ, arg1, INT64_MIN, l1); | |
1018 | gen_set_label(l3); | |
74637406 AJ |
1019 | tcg_gen_div_i64(ret, arg1, arg2); |
1020 | } else { | |
1021 | tcg_gen_divu_i64(ret, arg1, arg2); | |
1022 | } | |
1023 | if (compute_ov) { | |
da91a00f | 1024 | tcg_gen_movi_tl(cpu_ov, 0); |
74637406 AJ |
1025 | } |
1026 | tcg_gen_br(l2); | |
1027 | gen_set_label(l1); | |
1028 | if (sign) { | |
1029 | tcg_gen_sari_i64(ret, arg1, 63); | |
1030 | } else { | |
1031 | tcg_gen_movi_i64(ret, 0); | |
1032 | } | |
1033 | if (compute_ov) { | |
da91a00f RH |
1034 | tcg_gen_movi_tl(cpu_ov, 1); |
1035 | tcg_gen_movi_tl(cpu_so, 1); | |
74637406 AJ |
1036 | } |
1037 | gen_set_label(l2); | |
1038 | if (unlikely(Rc(ctx->opcode) != 0)) | |
1039 | gen_set_Rc0(ctx, ret); | |
d9bce9d9 | 1040 | } |
74637406 | 1041 | #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \ |
99e300ef | 1042 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 | 1043 | { \ |
2ef1b120 AJ |
1044 | gen_op_arith_divd(ctx, cpu_gpr[rD(ctx->opcode)], \ |
1045 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
1046 | sign, compute_ov); \ | |
74637406 AJ |
1047 | } |
1048 | /* divwu divwu. divwuo divwuo. */ | |
1049 | GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0); | |
1050 | GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1); | |
1051 | /* divw divw. divwo divwo. */ | |
1052 | GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0); | |
1053 | GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1); | |
98d1eb27 TM |
1054 | |
1055 | GEN_DIVE(divdeu, divdeu, 0); | |
1056 | GEN_DIVE(divdeuo, divdeu, 1); | |
e44259b6 TM |
1057 | GEN_DIVE(divde, divde, 0); |
1058 | GEN_DIVE(divdeo, divde, 1); | |
d9bce9d9 | 1059 | #endif |
74637406 AJ |
1060 | |
1061 | /* mulhw mulhw. */ | |
99e300ef | 1062 | static void gen_mulhw(DisasContext *ctx) |
d9bce9d9 | 1063 | { |
23ad1d5d RH |
1064 | TCGv_i32 t0 = tcg_temp_new_i32(); |
1065 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
74637406 | 1066 | |
23ad1d5d RH |
1067 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); |
1068 | tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); | |
1069 | tcg_gen_muls2_i32(t0, t1, t0, t1); | |
1070 | tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1); | |
1071 | tcg_temp_free_i32(t0); | |
1072 | tcg_temp_free_i32(t1); | |
74637406 AJ |
1073 | if (unlikely(Rc(ctx->opcode) != 0)) |
1074 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1075 | } |
99e300ef | 1076 | |
54623277 | 1077 | /* mulhwu mulhwu. */ |
99e300ef | 1078 | static void gen_mulhwu(DisasContext *ctx) |
d9bce9d9 | 1079 | { |
23ad1d5d RH |
1080 | TCGv_i32 t0 = tcg_temp_new_i32(); |
1081 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
74637406 | 1082 | |
23ad1d5d RH |
1083 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); |
1084 | tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); | |
1085 | tcg_gen_mulu2_i32(t0, t1, t0, t1); | |
1086 | tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t1); | |
1087 | tcg_temp_free_i32(t0); | |
1088 | tcg_temp_free_i32(t1); | |
74637406 AJ |
1089 | if (unlikely(Rc(ctx->opcode) != 0)) |
1090 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1091 | } |
99e300ef | 1092 | |
54623277 | 1093 | /* mullw mullw. */ |
99e300ef | 1094 | static void gen_mullw(DisasContext *ctx) |
d9bce9d9 | 1095 | { |
74637406 AJ |
1096 | tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], |
1097 | cpu_gpr[rB(ctx->opcode)]); | |
1e4c090f | 1098 | tcg_gen_ext32s_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)]); |
74637406 AJ |
1099 | if (unlikely(Rc(ctx->opcode) != 0)) |
1100 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1101 | } |
99e300ef | 1102 | |
54623277 | 1103 | /* mullwo mullwo. */ |
99e300ef | 1104 | static void gen_mullwo(DisasContext *ctx) |
d9bce9d9 | 1105 | { |
e4a2c846 RH |
1106 | TCGv_i32 t0 = tcg_temp_new_i32(); |
1107 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
74637406 | 1108 | |
e4a2c846 RH |
1109 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); |
1110 | tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); | |
1111 | tcg_gen_muls2_i32(t0, t1, t0, t1); | |
1112 | tcg_gen_ext_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
1113 | ||
1114 | tcg_gen_sari_i32(t0, t0, 31); | |
1115 | tcg_gen_setcond_i32(TCG_COND_NE, t0, t0, t1); | |
1116 | tcg_gen_extu_i32_tl(cpu_ov, t0); | |
1117 | tcg_gen_or_tl(cpu_so, cpu_so, cpu_ov); | |
1118 | ||
1119 | tcg_temp_free_i32(t0); | |
1120 | tcg_temp_free_i32(t1); | |
74637406 AJ |
1121 | if (unlikely(Rc(ctx->opcode) != 0)) |
1122 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1123 | } |
99e300ef | 1124 | |
54623277 | 1125 | /* mulli */ |
99e300ef | 1126 | static void gen_mulli(DisasContext *ctx) |
d9bce9d9 | 1127 | { |
74637406 AJ |
1128 | tcg_gen_muli_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], |
1129 | SIMM(ctx->opcode)); | |
d9bce9d9 | 1130 | } |
23ad1d5d | 1131 | |
d9bce9d9 | 1132 | #if defined(TARGET_PPC64) |
74637406 | 1133 | /* mulhd mulhd. */ |
23ad1d5d RH |
1134 | static void gen_mulhd(DisasContext *ctx) |
1135 | { | |
1136 | TCGv lo = tcg_temp_new(); | |
1137 | tcg_gen_muls2_tl(lo, cpu_gpr[rD(ctx->opcode)], | |
1138 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
1139 | tcg_temp_free(lo); | |
1140 | if (unlikely(Rc(ctx->opcode) != 0)) { | |
1141 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
1142 | } | |
1143 | } | |
1144 | ||
74637406 | 1145 | /* mulhdu mulhdu. */ |
23ad1d5d RH |
1146 | static void gen_mulhdu(DisasContext *ctx) |
1147 | { | |
1148 | TCGv lo = tcg_temp_new(); | |
1149 | tcg_gen_mulu2_tl(lo, cpu_gpr[rD(ctx->opcode)], | |
1150 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
1151 | tcg_temp_free(lo); | |
1152 | if (unlikely(Rc(ctx->opcode) != 0)) { | |
1153 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
1154 | } | |
1155 | } | |
99e300ef | 1156 | |
54623277 | 1157 | /* mulld mulld. */ |
99e300ef | 1158 | static void gen_mulld(DisasContext *ctx) |
d9bce9d9 | 1159 | { |
74637406 AJ |
1160 | tcg_gen_mul_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], |
1161 | cpu_gpr[rB(ctx->opcode)]); | |
1162 | if (unlikely(Rc(ctx->opcode) != 0)) | |
1163 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
d9bce9d9 | 1164 | } |
d15f74fb | 1165 | |
74637406 | 1166 | /* mulldo mulldo. */ |
d15f74fb BS |
1167 | static void gen_mulldo(DisasContext *ctx) |
1168 | { | |
1169 | gen_helper_mulldo(cpu_gpr[rD(ctx->opcode)], cpu_env, | |
1170 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
1171 | if (unlikely(Rc(ctx->opcode) != 0)) { | |
1172 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
1173 | } | |
1174 | } | |
d9bce9d9 | 1175 | #endif |
74637406 | 1176 | |
74637406 | 1177 | /* Common subf function */ |
636aa200 | 1178 | static inline void gen_op_arith_subf(DisasContext *ctx, TCGv ret, TCGv arg1, |
b5a73f8d RH |
1179 | TCGv arg2, bool add_ca, bool compute_ca, |
1180 | bool compute_ov, bool compute_rc0) | |
79aceca5 | 1181 | { |
b5a73f8d | 1182 | TCGv t0 = ret; |
79aceca5 | 1183 | |
752d634e | 1184 | if (compute_ca || compute_ov) { |
b5a73f8d | 1185 | t0 = tcg_temp_new(); |
da91a00f | 1186 | } |
74637406 | 1187 | |
79482e5a RH |
1188 | if (compute_ca) { |
1189 | /* dest = ~arg1 + arg2 [+ ca]. */ | |
1190 | if (NARROW_MODE(ctx)) { | |
752d634e RH |
1191 | /* Caution: a non-obvious corner case of the spec is that we |
1192 | must produce the *entire* 64-bit addition, but produce the | |
1193 | carry into bit 32. */ | |
79482e5a | 1194 | TCGv inv1 = tcg_temp_new(); |
752d634e | 1195 | TCGv t1 = tcg_temp_new(); |
79482e5a | 1196 | tcg_gen_not_tl(inv1, arg1); |
79482e5a | 1197 | if (add_ca) { |
752d634e | 1198 | tcg_gen_add_tl(t0, arg2, cpu_ca); |
79482e5a | 1199 | } else { |
752d634e | 1200 | tcg_gen_addi_tl(t0, arg2, 1); |
79482e5a | 1201 | } |
752d634e | 1202 | tcg_gen_xor_tl(t1, arg2, inv1); /* add without carry */ |
79482e5a | 1203 | tcg_gen_add_tl(t0, t0, inv1); |
752d634e RH |
1204 | tcg_gen_xor_tl(cpu_ca, t0, t1); /* bits changes w/ carry */ |
1205 | tcg_temp_free(t1); | |
1206 | tcg_gen_shri_tl(cpu_ca, cpu_ca, 32); /* extract bit 32 */ | |
1207 | tcg_gen_andi_tl(cpu_ca, cpu_ca, 1); | |
79482e5a | 1208 | } else if (add_ca) { |
08f4a0f7 RH |
1209 | TCGv zero, inv1 = tcg_temp_new(); |
1210 | tcg_gen_not_tl(inv1, arg1); | |
b5a73f8d RH |
1211 | zero = tcg_const_tl(0); |
1212 | tcg_gen_add2_tl(t0, cpu_ca, arg2, zero, cpu_ca, zero); | |
08f4a0f7 | 1213 | tcg_gen_add2_tl(t0, cpu_ca, t0, cpu_ca, inv1, zero); |
b5a73f8d | 1214 | tcg_temp_free(zero); |
08f4a0f7 | 1215 | tcg_temp_free(inv1); |
b5a73f8d | 1216 | } else { |
79482e5a | 1217 | tcg_gen_setcond_tl(TCG_COND_GEU, cpu_ca, arg2, arg1); |
b5a73f8d | 1218 | tcg_gen_sub_tl(t0, arg2, arg1); |
b5a73f8d | 1219 | } |
79482e5a RH |
1220 | } else if (add_ca) { |
1221 | /* Since we're ignoring carry-out, we can simplify the | |
1222 | standard ~arg1 + arg2 + ca to arg2 - arg1 + ca - 1. */ | |
1223 | tcg_gen_sub_tl(t0, arg2, arg1); | |
1224 | tcg_gen_add_tl(t0, t0, cpu_ca); | |
1225 | tcg_gen_subi_tl(t0, t0, 1); | |
79aceca5 | 1226 | } else { |
b5a73f8d | 1227 | tcg_gen_sub_tl(t0, arg2, arg1); |
74637406 | 1228 | } |
b5a73f8d | 1229 | |
74637406 AJ |
1230 | if (compute_ov) { |
1231 | gen_op_arith_compute_ov(ctx, t0, arg1, arg2, 1); | |
1232 | } | |
b5a73f8d | 1233 | if (unlikely(compute_rc0)) { |
74637406 | 1234 | gen_set_Rc0(ctx, t0); |
b5a73f8d | 1235 | } |
74637406 | 1236 | |
a7812ae4 | 1237 | if (!TCGV_EQUAL(t0, ret)) { |
74637406 AJ |
1238 | tcg_gen_mov_tl(ret, t0); |
1239 | tcg_temp_free(t0); | |
79aceca5 | 1240 | } |
79aceca5 | 1241 | } |
74637406 AJ |
1242 | /* Sub functions with Two operands functions */ |
1243 | #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \ | |
b5a73f8d | 1244 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 AJ |
1245 | { \ |
1246 | gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \ | |
1247 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
b5a73f8d | 1248 | add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \ |
74637406 AJ |
1249 | } |
1250 | /* Sub functions with one operand and one immediate */ | |
1251 | #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \ | |
1252 | add_ca, compute_ca, compute_ov) \ | |
b5a73f8d | 1253 | static void glue(gen_, name)(DisasContext *ctx) \ |
74637406 | 1254 | { \ |
b5a73f8d | 1255 | TCGv t0 = tcg_const_tl(const_val); \ |
74637406 AJ |
1256 | gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], \ |
1257 | cpu_gpr[rA(ctx->opcode)], t0, \ | |
b5a73f8d | 1258 | add_ca, compute_ca, compute_ov, Rc(ctx->opcode)); \ |
74637406 AJ |
1259 | tcg_temp_free(t0); \ |
1260 | } | |
1261 | /* subf subf. subfo subfo. */ | |
1262 | GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0) | |
1263 | GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1) | |
1264 | /* subfc subfc. subfco subfco. */ | |
1265 | GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0) | |
1266 | GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1) | |
1267 | /* subfe subfe. subfeo subfo. */ | |
1268 | GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0) | |
1269 | GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1) | |
1270 | /* subfme subfme. subfmeo subfmeo. */ | |
1271 | GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0) | |
1272 | GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1) | |
1273 | /* subfze subfze. subfzeo subfzeo.*/ | |
1274 | GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0) | |
1275 | GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1) | |
99e300ef | 1276 | |
54623277 | 1277 | /* subfic */ |
99e300ef | 1278 | static void gen_subfic(DisasContext *ctx) |
79aceca5 | 1279 | { |
b5a73f8d RH |
1280 | TCGv c = tcg_const_tl(SIMM(ctx->opcode)); |
1281 | gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], | |
1282 | c, 0, 1, 0, 0); | |
1283 | tcg_temp_free(c); | |
79aceca5 FB |
1284 | } |
1285 | ||
fd3f0081 RH |
1286 | /* neg neg. nego nego. */ |
1287 | static inline void gen_op_arith_neg(DisasContext *ctx, bool compute_ov) | |
1288 | { | |
1289 | TCGv zero = tcg_const_tl(0); | |
1290 | gen_op_arith_subf(ctx, cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], | |
1291 | zero, 0, 0, compute_ov, Rc(ctx->opcode)); | |
1292 | tcg_temp_free(zero); | |
1293 | } | |
1294 | ||
1295 | static void gen_neg(DisasContext *ctx) | |
1296 | { | |
1297 | gen_op_arith_neg(ctx, 0); | |
1298 | } | |
1299 | ||
1300 | static void gen_nego(DisasContext *ctx) | |
1301 | { | |
1302 | gen_op_arith_neg(ctx, 1); | |
1303 | } | |
1304 | ||
79aceca5 | 1305 | /*** Integer logical ***/ |
26d67362 | 1306 | #define GEN_LOGICAL2(name, tcg_op, opc, type) \ |
99e300ef | 1307 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 1308 | { \ |
26d67362 AJ |
1309 | tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], \ |
1310 | cpu_gpr[rB(ctx->opcode)]); \ | |
76a66253 | 1311 | if (unlikely(Rc(ctx->opcode) != 0)) \ |
26d67362 | 1312 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \ |
79aceca5 | 1313 | } |
79aceca5 | 1314 | |
26d67362 | 1315 | #define GEN_LOGICAL1(name, tcg_op, opc, type) \ |
99e300ef | 1316 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 1317 | { \ |
26d67362 | 1318 | tcg_op(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); \ |
76a66253 | 1319 | if (unlikely(Rc(ctx->opcode) != 0)) \ |
26d67362 | 1320 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); \ |
79aceca5 FB |
1321 | } |
1322 | ||
1323 | /* and & and. */ | |
26d67362 | 1324 | GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER); |
79aceca5 | 1325 | /* andc & andc. */ |
26d67362 | 1326 | GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER); |
e8eaa2c0 | 1327 | |
54623277 | 1328 | /* andi. */ |
e8eaa2c0 | 1329 | static void gen_andi_(DisasContext *ctx) |
79aceca5 | 1330 | { |
26d67362 AJ |
1331 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode)); |
1332 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
79aceca5 | 1333 | } |
e8eaa2c0 | 1334 | |
54623277 | 1335 | /* andis. */ |
e8eaa2c0 | 1336 | static void gen_andis_(DisasContext *ctx) |
79aceca5 | 1337 | { |
26d67362 AJ |
1338 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], UIMM(ctx->opcode) << 16); |
1339 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
79aceca5 | 1340 | } |
99e300ef | 1341 | |
54623277 | 1342 | /* cntlzw */ |
99e300ef | 1343 | static void gen_cntlzw(DisasContext *ctx) |
26d67362 | 1344 | { |
a7812ae4 | 1345 | gen_helper_cntlzw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); |
26d67362 | 1346 | if (unlikely(Rc(ctx->opcode) != 0)) |
2e31f5d3 | 1347 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
26d67362 | 1348 | } |
79aceca5 | 1349 | /* eqv & eqv. */ |
26d67362 | 1350 | GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER); |
79aceca5 | 1351 | /* extsb & extsb. */ |
26d67362 | 1352 | GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER); |
79aceca5 | 1353 | /* extsh & extsh. */ |
26d67362 | 1354 | GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER); |
79aceca5 | 1355 | /* nand & nand. */ |
26d67362 | 1356 | GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER); |
79aceca5 | 1357 | /* nor & nor. */ |
26d67362 | 1358 | GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER); |
99e300ef | 1359 | |
54623277 | 1360 | /* or & or. */ |
99e300ef | 1361 | static void gen_or(DisasContext *ctx) |
9a64fbe4 | 1362 | { |
76a66253 JM |
1363 | int rs, ra, rb; |
1364 | ||
1365 | rs = rS(ctx->opcode); | |
1366 | ra = rA(ctx->opcode); | |
1367 | rb = rB(ctx->opcode); | |
1368 | /* Optimisation for mr. ri case */ | |
1369 | if (rs != ra || rs != rb) { | |
26d67362 AJ |
1370 | if (rs != rb) |
1371 | tcg_gen_or_tl(cpu_gpr[ra], cpu_gpr[rs], cpu_gpr[rb]); | |
1372 | else | |
1373 | tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rs]); | |
76a66253 | 1374 | if (unlikely(Rc(ctx->opcode) != 0)) |
26d67362 | 1375 | gen_set_Rc0(ctx, cpu_gpr[ra]); |
76a66253 | 1376 | } else if (unlikely(Rc(ctx->opcode) != 0)) { |
26d67362 | 1377 | gen_set_Rc0(ctx, cpu_gpr[rs]); |
c80f84e3 JM |
1378 | #if defined(TARGET_PPC64) |
1379 | } else { | |
26d67362 AJ |
1380 | int prio = 0; |
1381 | ||
c80f84e3 JM |
1382 | switch (rs) { |
1383 | case 1: | |
1384 | /* Set process priority to low */ | |
26d67362 | 1385 | prio = 2; |
c80f84e3 JM |
1386 | break; |
1387 | case 6: | |
1388 | /* Set process priority to medium-low */ | |
26d67362 | 1389 | prio = 3; |
c80f84e3 JM |
1390 | break; |
1391 | case 2: | |
1392 | /* Set process priority to normal */ | |
26d67362 | 1393 | prio = 4; |
c80f84e3 | 1394 | break; |
be147d08 JM |
1395 | #if !defined(CONFIG_USER_ONLY) |
1396 | case 31: | |
76db3ba4 | 1397 | if (ctx->mem_idx > 0) { |
be147d08 | 1398 | /* Set process priority to very low */ |
26d67362 | 1399 | prio = 1; |
be147d08 JM |
1400 | } |
1401 | break; | |
1402 | case 5: | |
76db3ba4 | 1403 | if (ctx->mem_idx > 0) { |
be147d08 | 1404 | /* Set process priority to medium-hight */ |
26d67362 | 1405 | prio = 5; |
be147d08 JM |
1406 | } |
1407 | break; | |
1408 | case 3: | |
76db3ba4 | 1409 | if (ctx->mem_idx > 0) { |
be147d08 | 1410 | /* Set process priority to high */ |
26d67362 | 1411 | prio = 6; |
be147d08 JM |
1412 | } |
1413 | break; | |
be147d08 | 1414 | case 7: |
76db3ba4 | 1415 | if (ctx->mem_idx > 1) { |
be147d08 | 1416 | /* Set process priority to very high */ |
26d67362 | 1417 | prio = 7; |
be147d08 JM |
1418 | } |
1419 | break; | |
be147d08 | 1420 | #endif |
c80f84e3 JM |
1421 | default: |
1422 | /* nop */ | |
1423 | break; | |
1424 | } | |
26d67362 | 1425 | if (prio) { |
a7812ae4 | 1426 | TCGv t0 = tcg_temp_new(); |
54cdcae6 | 1427 | gen_load_spr(t0, SPR_PPR); |
ea363694 AJ |
1428 | tcg_gen_andi_tl(t0, t0, ~0x001C000000000000ULL); |
1429 | tcg_gen_ori_tl(t0, t0, ((uint64_t)prio) << 50); | |
54cdcae6 | 1430 | gen_store_spr(SPR_PPR, t0); |
ea363694 | 1431 | tcg_temp_free(t0); |
26d67362 | 1432 | } |
c80f84e3 | 1433 | #endif |
9a64fbe4 | 1434 | } |
9a64fbe4 | 1435 | } |
79aceca5 | 1436 | /* orc & orc. */ |
26d67362 | 1437 | GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER); |
99e300ef | 1438 | |
54623277 | 1439 | /* xor & xor. */ |
99e300ef | 1440 | static void gen_xor(DisasContext *ctx) |
9a64fbe4 | 1441 | { |
9a64fbe4 | 1442 | /* Optimisation for "set to zero" case */ |
26d67362 | 1443 | if (rS(ctx->opcode) != rB(ctx->opcode)) |
312179c4 | 1444 | tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
26d67362 AJ |
1445 | else |
1446 | tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0); | |
76a66253 | 1447 | if (unlikely(Rc(ctx->opcode) != 0)) |
26d67362 | 1448 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
9a64fbe4 | 1449 | } |
99e300ef | 1450 | |
54623277 | 1451 | /* ori */ |
99e300ef | 1452 | static void gen_ori(DisasContext *ctx) |
79aceca5 | 1453 | { |
76a66253 | 1454 | target_ulong uimm = UIMM(ctx->opcode); |
79aceca5 | 1455 | |
9a64fbe4 FB |
1456 | if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { |
1457 | /* NOP */ | |
76a66253 | 1458 | /* XXX: should handle special NOPs for POWER series */ |
9a64fbe4 | 1459 | return; |
76a66253 | 1460 | } |
26d67362 | 1461 | tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm); |
79aceca5 | 1462 | } |
99e300ef | 1463 | |
54623277 | 1464 | /* oris */ |
99e300ef | 1465 | static void gen_oris(DisasContext *ctx) |
79aceca5 | 1466 | { |
76a66253 | 1467 | target_ulong uimm = UIMM(ctx->opcode); |
79aceca5 | 1468 | |
9a64fbe4 FB |
1469 | if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { |
1470 | /* NOP */ | |
1471 | return; | |
76a66253 | 1472 | } |
26d67362 | 1473 | tcg_gen_ori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16); |
79aceca5 | 1474 | } |
99e300ef | 1475 | |
54623277 | 1476 | /* xori */ |
99e300ef | 1477 | static void gen_xori(DisasContext *ctx) |
79aceca5 | 1478 | { |
76a66253 | 1479 | target_ulong uimm = UIMM(ctx->opcode); |
9a64fbe4 FB |
1480 | |
1481 | if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { | |
1482 | /* NOP */ | |
1483 | return; | |
1484 | } | |
26d67362 | 1485 | tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm); |
79aceca5 | 1486 | } |
99e300ef | 1487 | |
54623277 | 1488 | /* xoris */ |
99e300ef | 1489 | static void gen_xoris(DisasContext *ctx) |
79aceca5 | 1490 | { |
76a66253 | 1491 | target_ulong uimm = UIMM(ctx->opcode); |
9a64fbe4 FB |
1492 | |
1493 | if (rS(ctx->opcode) == rA(ctx->opcode) && uimm == 0) { | |
1494 | /* NOP */ | |
1495 | return; | |
1496 | } | |
26d67362 | 1497 | tcg_gen_xori_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], uimm << 16); |
79aceca5 | 1498 | } |
99e300ef | 1499 | |
54623277 | 1500 | /* popcntb : PowerPC 2.03 specification */ |
99e300ef | 1501 | static void gen_popcntb(DisasContext *ctx) |
d9bce9d9 | 1502 | { |
eaabeef2 DG |
1503 | gen_helper_popcntb(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); |
1504 | } | |
1505 | ||
1506 | static void gen_popcntw(DisasContext *ctx) | |
1507 | { | |
1508 | gen_helper_popcntw(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
1509 | } | |
1510 | ||
d9bce9d9 | 1511 | #if defined(TARGET_PPC64) |
eaabeef2 DG |
1512 | /* popcntd: PowerPC 2.06 specification */ |
1513 | static void gen_popcntd(DisasContext *ctx) | |
1514 | { | |
1515 | gen_helper_popcntd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
d9bce9d9 | 1516 | } |
eaabeef2 | 1517 | #endif |
d9bce9d9 | 1518 | |
725bcec2 AJ |
1519 | /* prtyw: PowerPC 2.05 specification */ |
1520 | static void gen_prtyw(DisasContext *ctx) | |
1521 | { | |
1522 | TCGv ra = cpu_gpr[rA(ctx->opcode)]; | |
1523 | TCGv rs = cpu_gpr[rS(ctx->opcode)]; | |
1524 | TCGv t0 = tcg_temp_new(); | |
1525 | tcg_gen_shri_tl(t0, rs, 16); | |
1526 | tcg_gen_xor_tl(ra, rs, t0); | |
1527 | tcg_gen_shri_tl(t0, ra, 8); | |
1528 | tcg_gen_xor_tl(ra, ra, t0); | |
1529 | tcg_gen_andi_tl(ra, ra, (target_ulong)0x100000001ULL); | |
1530 | tcg_temp_free(t0); | |
1531 | } | |
1532 | ||
1533 | #if defined(TARGET_PPC64) | |
1534 | /* prtyd: PowerPC 2.05 specification */ | |
1535 | static void gen_prtyd(DisasContext *ctx) | |
1536 | { | |
1537 | TCGv ra = cpu_gpr[rA(ctx->opcode)]; | |
1538 | TCGv rs = cpu_gpr[rS(ctx->opcode)]; | |
1539 | TCGv t0 = tcg_temp_new(); | |
1540 | tcg_gen_shri_tl(t0, rs, 32); | |
1541 | tcg_gen_xor_tl(ra, rs, t0); | |
1542 | tcg_gen_shri_tl(t0, ra, 16); | |
1543 | tcg_gen_xor_tl(ra, ra, t0); | |
1544 | tcg_gen_shri_tl(t0, ra, 8); | |
1545 | tcg_gen_xor_tl(ra, ra, t0); | |
1546 | tcg_gen_andi_tl(ra, ra, 1); | |
1547 | tcg_temp_free(t0); | |
1548 | } | |
1549 | #endif | |
1550 | ||
86ba37ed TM |
1551 | #if defined(TARGET_PPC64) |
1552 | /* bpermd */ | |
1553 | static void gen_bpermd(DisasContext *ctx) | |
1554 | { | |
1555 | gen_helper_bpermd(cpu_gpr[rA(ctx->opcode)], | |
1556 | cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
1557 | } | |
1558 | #endif | |
1559 | ||
d9bce9d9 JM |
1560 | #if defined(TARGET_PPC64) |
1561 | /* extsw & extsw. */ | |
26d67362 | 1562 | GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B); |
99e300ef | 1563 | |
54623277 | 1564 | /* cntlzd */ |
99e300ef | 1565 | static void gen_cntlzd(DisasContext *ctx) |
26d67362 | 1566 | { |
a7812ae4 | 1567 | gen_helper_cntlzd(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); |
26d67362 AJ |
1568 | if (unlikely(Rc(ctx->opcode) != 0)) |
1569 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1570 | } | |
d9bce9d9 JM |
1571 | #endif |
1572 | ||
79aceca5 | 1573 | /*** Integer rotate ***/ |
99e300ef | 1574 | |
54623277 | 1575 | /* rlwimi & rlwimi. */ |
99e300ef | 1576 | static void gen_rlwimi(DisasContext *ctx) |
79aceca5 | 1577 | { |
76a66253 | 1578 | uint32_t mb, me, sh; |
79aceca5 FB |
1579 | |
1580 | mb = MB(ctx->opcode); | |
1581 | me = ME(ctx->opcode); | |
76a66253 | 1582 | sh = SH(ctx->opcode); |
d03ef511 AJ |
1583 | if (likely(sh == 0 && mb == 0 && me == 31)) { |
1584 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
1585 | } else { | |
d03ef511 | 1586 | target_ulong mask; |
a7812ae4 PB |
1587 | TCGv t1; |
1588 | TCGv t0 = tcg_temp_new(); | |
54843a58 | 1589 | #if defined(TARGET_PPC64) |
a7812ae4 PB |
1590 | TCGv_i32 t2 = tcg_temp_new_i32(); |
1591 | tcg_gen_trunc_i64_i32(t2, cpu_gpr[rS(ctx->opcode)]); | |
1592 | tcg_gen_rotli_i32(t2, t2, sh); | |
1593 | tcg_gen_extu_i32_i64(t0, t2); | |
1594 | tcg_temp_free_i32(t2); | |
54843a58 AJ |
1595 | #else |
1596 | tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
1597 | #endif | |
76a66253 | 1598 | #if defined(TARGET_PPC64) |
d03ef511 AJ |
1599 | mb += 32; |
1600 | me += 32; | |
76a66253 | 1601 | #endif |
d03ef511 | 1602 | mask = MASK(mb, me); |
a7812ae4 | 1603 | t1 = tcg_temp_new(); |
d03ef511 AJ |
1604 | tcg_gen_andi_tl(t0, t0, mask); |
1605 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask); | |
1606 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
1607 | tcg_temp_free(t0); | |
1608 | tcg_temp_free(t1); | |
1609 | } | |
76a66253 | 1610 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1611 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
79aceca5 | 1612 | } |
99e300ef | 1613 | |
54623277 | 1614 | /* rlwinm & rlwinm. */ |
99e300ef | 1615 | static void gen_rlwinm(DisasContext *ctx) |
79aceca5 FB |
1616 | { |
1617 | uint32_t mb, me, sh; | |
3b46e624 | 1618 | |
79aceca5 FB |
1619 | sh = SH(ctx->opcode); |
1620 | mb = MB(ctx->opcode); | |
1621 | me = ME(ctx->opcode); | |
d03ef511 AJ |
1622 | |
1623 | if (likely(mb == 0 && me == (31 - sh))) { | |
1624 | if (likely(sh == 0)) { | |
1625 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
1626 | } else { | |
a7812ae4 | 1627 | TCGv t0 = tcg_temp_new(); |
d03ef511 AJ |
1628 | tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]); |
1629 | tcg_gen_shli_tl(t0, t0, sh); | |
1630 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
1631 | tcg_temp_free(t0); | |
79aceca5 | 1632 | } |
d03ef511 | 1633 | } else if (likely(sh != 0 && me == 31 && sh == (32 - mb))) { |
a7812ae4 | 1634 | TCGv t0 = tcg_temp_new(); |
d03ef511 AJ |
1635 | tcg_gen_ext32u_tl(t0, cpu_gpr[rS(ctx->opcode)]); |
1636 | tcg_gen_shri_tl(t0, t0, mb); | |
1637 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
1638 | tcg_temp_free(t0); | |
1639 | } else { | |
a7812ae4 | 1640 | TCGv t0 = tcg_temp_new(); |
54843a58 | 1641 | #if defined(TARGET_PPC64) |
a7812ae4 | 1642 | TCGv_i32 t1 = tcg_temp_new_i32(); |
54843a58 AJ |
1643 | tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]); |
1644 | tcg_gen_rotli_i32(t1, t1, sh); | |
1645 | tcg_gen_extu_i32_i64(t0, t1); | |
a7812ae4 | 1646 | tcg_temp_free_i32(t1); |
54843a58 AJ |
1647 | #else |
1648 | tcg_gen_rotli_i32(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
1649 | #endif | |
76a66253 | 1650 | #if defined(TARGET_PPC64) |
d03ef511 AJ |
1651 | mb += 32; |
1652 | me += 32; | |
76a66253 | 1653 | #endif |
d03ef511 AJ |
1654 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me)); |
1655 | tcg_temp_free(t0); | |
1656 | } | |
76a66253 | 1657 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1658 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
79aceca5 | 1659 | } |
99e300ef | 1660 | |
54623277 | 1661 | /* rlwnm & rlwnm. */ |
99e300ef | 1662 | static void gen_rlwnm(DisasContext *ctx) |
79aceca5 FB |
1663 | { |
1664 | uint32_t mb, me; | |
54843a58 AJ |
1665 | TCGv t0; |
1666 | #if defined(TARGET_PPC64) | |
a7812ae4 | 1667 | TCGv_i32 t1, t2; |
54843a58 | 1668 | #endif |
79aceca5 FB |
1669 | |
1670 | mb = MB(ctx->opcode); | |
1671 | me = ME(ctx->opcode); | |
a7812ae4 | 1672 | t0 = tcg_temp_new(); |
d03ef511 | 1673 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1f); |
54843a58 | 1674 | #if defined(TARGET_PPC64) |
a7812ae4 PB |
1675 | t1 = tcg_temp_new_i32(); |
1676 | t2 = tcg_temp_new_i32(); | |
54843a58 AJ |
1677 | tcg_gen_trunc_i64_i32(t1, cpu_gpr[rS(ctx->opcode)]); |
1678 | tcg_gen_trunc_i64_i32(t2, t0); | |
1679 | tcg_gen_rotl_i32(t1, t1, t2); | |
1680 | tcg_gen_extu_i32_i64(t0, t1); | |
a7812ae4 PB |
1681 | tcg_temp_free_i32(t1); |
1682 | tcg_temp_free_i32(t2); | |
54843a58 AJ |
1683 | #else |
1684 | tcg_gen_rotl_i32(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
1685 | #endif | |
76a66253 JM |
1686 | if (unlikely(mb != 0 || me != 31)) { |
1687 | #if defined(TARGET_PPC64) | |
1688 | mb += 32; | |
1689 | me += 32; | |
1690 | #endif | |
54843a58 | 1691 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me)); |
d03ef511 | 1692 | } else { |
54843a58 | 1693 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); |
79aceca5 | 1694 | } |
54843a58 | 1695 | tcg_temp_free(t0); |
76a66253 | 1696 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1697 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
79aceca5 FB |
1698 | } |
1699 | ||
d9bce9d9 JM |
1700 | #if defined(TARGET_PPC64) |
1701 | #define GEN_PPC64_R2(name, opc1, opc2) \ | |
e8eaa2c0 | 1702 | static void glue(gen_, name##0)(DisasContext *ctx) \ |
d9bce9d9 JM |
1703 | { \ |
1704 | gen_##name(ctx, 0); \ | |
1705 | } \ | |
e8eaa2c0 BS |
1706 | \ |
1707 | static void glue(gen_, name##1)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1708 | { \ |
1709 | gen_##name(ctx, 1); \ | |
1710 | } | |
1711 | #define GEN_PPC64_R4(name, opc1, opc2) \ | |
e8eaa2c0 | 1712 | static void glue(gen_, name##0)(DisasContext *ctx) \ |
d9bce9d9 JM |
1713 | { \ |
1714 | gen_##name(ctx, 0, 0); \ | |
1715 | } \ | |
e8eaa2c0 BS |
1716 | \ |
1717 | static void glue(gen_, name##1)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1718 | { \ |
1719 | gen_##name(ctx, 0, 1); \ | |
1720 | } \ | |
e8eaa2c0 BS |
1721 | \ |
1722 | static void glue(gen_, name##2)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1723 | { \ |
1724 | gen_##name(ctx, 1, 0); \ | |
1725 | } \ | |
e8eaa2c0 BS |
1726 | \ |
1727 | static void glue(gen_, name##3)(DisasContext *ctx) \ | |
d9bce9d9 JM |
1728 | { \ |
1729 | gen_##name(ctx, 1, 1); \ | |
1730 | } | |
51789c41 | 1731 | |
636aa200 BS |
1732 | static inline void gen_rldinm(DisasContext *ctx, uint32_t mb, uint32_t me, |
1733 | uint32_t sh) | |
51789c41 | 1734 | { |
d03ef511 AJ |
1735 | if (likely(sh != 0 && mb == 0 && me == (63 - sh))) { |
1736 | tcg_gen_shli_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh); | |
1737 | } else if (likely(sh != 0 && me == 63 && sh == (64 - mb))) { | |
1738 | tcg_gen_shri_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], mb); | |
1739 | } else { | |
a7812ae4 | 1740 | TCGv t0 = tcg_temp_new(); |
54843a58 | 1741 | tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); |
d03ef511 | 1742 | if (likely(mb == 0 && me == 63)) { |
54843a58 | 1743 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); |
d03ef511 AJ |
1744 | } else { |
1745 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me)); | |
51789c41 | 1746 | } |
d03ef511 | 1747 | tcg_temp_free(t0); |
51789c41 | 1748 | } |
51789c41 | 1749 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1750 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
51789c41 | 1751 | } |
d9bce9d9 | 1752 | /* rldicl - rldicl. */ |
636aa200 | 1753 | static inline void gen_rldicl(DisasContext *ctx, int mbn, int shn) |
d9bce9d9 | 1754 | { |
51789c41 | 1755 | uint32_t sh, mb; |
d9bce9d9 | 1756 | |
9d53c753 JM |
1757 | sh = SH(ctx->opcode) | (shn << 5); |
1758 | mb = MB(ctx->opcode) | (mbn << 5); | |
51789c41 | 1759 | gen_rldinm(ctx, mb, 63, sh); |
d9bce9d9 | 1760 | } |
51789c41 | 1761 | GEN_PPC64_R4(rldicl, 0x1E, 0x00); |
d9bce9d9 | 1762 | /* rldicr - rldicr. */ |
636aa200 | 1763 | static inline void gen_rldicr(DisasContext *ctx, int men, int shn) |
d9bce9d9 | 1764 | { |
51789c41 | 1765 | uint32_t sh, me; |
d9bce9d9 | 1766 | |
9d53c753 JM |
1767 | sh = SH(ctx->opcode) | (shn << 5); |
1768 | me = MB(ctx->opcode) | (men << 5); | |
51789c41 | 1769 | gen_rldinm(ctx, 0, me, sh); |
d9bce9d9 | 1770 | } |
51789c41 | 1771 | GEN_PPC64_R4(rldicr, 0x1E, 0x02); |
d9bce9d9 | 1772 | /* rldic - rldic. */ |
636aa200 | 1773 | static inline void gen_rldic(DisasContext *ctx, int mbn, int shn) |
d9bce9d9 | 1774 | { |
51789c41 | 1775 | uint32_t sh, mb; |
d9bce9d9 | 1776 | |
9d53c753 JM |
1777 | sh = SH(ctx->opcode) | (shn << 5); |
1778 | mb = MB(ctx->opcode) | (mbn << 5); | |
51789c41 JM |
1779 | gen_rldinm(ctx, mb, 63 - sh, sh); |
1780 | } | |
1781 | GEN_PPC64_R4(rldic, 0x1E, 0x04); | |
1782 | ||
636aa200 | 1783 | static inline void gen_rldnm(DisasContext *ctx, uint32_t mb, uint32_t me) |
51789c41 | 1784 | { |
54843a58 | 1785 | TCGv t0; |
d03ef511 | 1786 | |
a7812ae4 | 1787 | t0 = tcg_temp_new(); |
d03ef511 | 1788 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3f); |
54843a58 | 1789 | tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); |
51789c41 | 1790 | if (unlikely(mb != 0 || me != 63)) { |
54843a58 AJ |
1791 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], t0, MASK(mb, me)); |
1792 | } else { | |
1793 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
1794 | } | |
1795 | tcg_temp_free(t0); | |
51789c41 | 1796 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1797 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
d9bce9d9 | 1798 | } |
51789c41 | 1799 | |
d9bce9d9 | 1800 | /* rldcl - rldcl. */ |
636aa200 | 1801 | static inline void gen_rldcl(DisasContext *ctx, int mbn) |
d9bce9d9 | 1802 | { |
51789c41 | 1803 | uint32_t mb; |
d9bce9d9 | 1804 | |
9d53c753 | 1805 | mb = MB(ctx->opcode) | (mbn << 5); |
51789c41 | 1806 | gen_rldnm(ctx, mb, 63); |
d9bce9d9 | 1807 | } |
36081602 | 1808 | GEN_PPC64_R2(rldcl, 0x1E, 0x08); |
d9bce9d9 | 1809 | /* rldcr - rldcr. */ |
636aa200 | 1810 | static inline void gen_rldcr(DisasContext *ctx, int men) |
d9bce9d9 | 1811 | { |
51789c41 | 1812 | uint32_t me; |
d9bce9d9 | 1813 | |
9d53c753 | 1814 | me = MB(ctx->opcode) | (men << 5); |
51789c41 | 1815 | gen_rldnm(ctx, 0, me); |
d9bce9d9 | 1816 | } |
36081602 | 1817 | GEN_PPC64_R2(rldcr, 0x1E, 0x09); |
d9bce9d9 | 1818 | /* rldimi - rldimi. */ |
636aa200 | 1819 | static inline void gen_rldimi(DisasContext *ctx, int mbn, int shn) |
d9bce9d9 | 1820 | { |
271a916e | 1821 | uint32_t sh, mb, me; |
d9bce9d9 | 1822 | |
9d53c753 JM |
1823 | sh = SH(ctx->opcode) | (shn << 5); |
1824 | mb = MB(ctx->opcode) | (mbn << 5); | |
271a916e | 1825 | me = 63 - sh; |
d03ef511 AJ |
1826 | if (unlikely(sh == 0 && mb == 0)) { |
1827 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)]); | |
1828 | } else { | |
1829 | TCGv t0, t1; | |
1830 | target_ulong mask; | |
1831 | ||
a7812ae4 | 1832 | t0 = tcg_temp_new(); |
54843a58 | 1833 | tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); |
a7812ae4 | 1834 | t1 = tcg_temp_new(); |
d03ef511 AJ |
1835 | mask = MASK(mb, me); |
1836 | tcg_gen_andi_tl(t0, t0, mask); | |
1837 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], ~mask); | |
1838 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
1839 | tcg_temp_free(t0); | |
1840 | tcg_temp_free(t1); | |
51789c41 | 1841 | } |
51789c41 | 1842 | if (unlikely(Rc(ctx->opcode) != 0)) |
d03ef511 | 1843 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
d9bce9d9 | 1844 | } |
36081602 | 1845 | GEN_PPC64_R4(rldimi, 0x1E, 0x06); |
d9bce9d9 JM |
1846 | #endif |
1847 | ||
79aceca5 | 1848 | /*** Integer shift ***/ |
99e300ef | 1849 | |
54623277 | 1850 | /* slw & slw. */ |
99e300ef | 1851 | static void gen_slw(DisasContext *ctx) |
26d67362 | 1852 | { |
7fd6bf7d | 1853 | TCGv t0, t1; |
26d67362 | 1854 | |
7fd6bf7d AJ |
1855 | t0 = tcg_temp_new(); |
1856 | /* AND rS with a mask that is 0 when rB >= 0x20 */ | |
1857 | #if defined(TARGET_PPC64) | |
1858 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a); | |
1859 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
1860 | #else | |
1861 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a); | |
1862 | tcg_gen_sari_tl(t0, t0, 0x1f); | |
1863 | #endif | |
1864 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
1865 | t1 = tcg_temp_new(); | |
1866 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f); | |
1867 | tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
1868 | tcg_temp_free(t1); | |
fea0c503 | 1869 | tcg_temp_free(t0); |
7fd6bf7d | 1870 | tcg_gen_ext32u_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
26d67362 AJ |
1871 | if (unlikely(Rc(ctx->opcode) != 0)) |
1872 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1873 | } | |
99e300ef | 1874 | |
54623277 | 1875 | /* sraw & sraw. */ |
99e300ef | 1876 | static void gen_sraw(DisasContext *ctx) |
26d67362 | 1877 | { |
d15f74fb | 1878 | gen_helper_sraw(cpu_gpr[rA(ctx->opcode)], cpu_env, |
a7812ae4 | 1879 | cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
26d67362 AJ |
1880 | if (unlikely(Rc(ctx->opcode) != 0)) |
1881 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1882 | } | |
99e300ef | 1883 | |
54623277 | 1884 | /* srawi & srawi. */ |
99e300ef | 1885 | static void gen_srawi(DisasContext *ctx) |
79aceca5 | 1886 | { |
26d67362 | 1887 | int sh = SH(ctx->opcode); |
ba4af3e4 RH |
1888 | TCGv dst = cpu_gpr[rA(ctx->opcode)]; |
1889 | TCGv src = cpu_gpr[rS(ctx->opcode)]; | |
1890 | if (sh == 0) { | |
1891 | tcg_gen_mov_tl(dst, src); | |
da91a00f | 1892 | tcg_gen_movi_tl(cpu_ca, 0); |
26d67362 | 1893 | } else { |
ba4af3e4 RH |
1894 | TCGv t0; |
1895 | tcg_gen_ext32s_tl(dst, src); | |
1896 | tcg_gen_andi_tl(cpu_ca, dst, (1ULL << sh) - 1); | |
1897 | t0 = tcg_temp_new(); | |
1898 | tcg_gen_sari_tl(t0, dst, TARGET_LONG_BITS - 1); | |
1899 | tcg_gen_and_tl(cpu_ca, cpu_ca, t0); | |
1900 | tcg_temp_free(t0); | |
1901 | tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0); | |
1902 | tcg_gen_sari_tl(dst, dst, sh); | |
1903 | } | |
1904 | if (unlikely(Rc(ctx->opcode) != 0)) { | |
1905 | gen_set_Rc0(ctx, dst); | |
d9bce9d9 | 1906 | } |
79aceca5 | 1907 | } |
99e300ef | 1908 | |
54623277 | 1909 | /* srw & srw. */ |
99e300ef | 1910 | static void gen_srw(DisasContext *ctx) |
26d67362 | 1911 | { |
fea0c503 | 1912 | TCGv t0, t1; |
d9bce9d9 | 1913 | |
7fd6bf7d AJ |
1914 | t0 = tcg_temp_new(); |
1915 | /* AND rS with a mask that is 0 when rB >= 0x20 */ | |
1916 | #if defined(TARGET_PPC64) | |
1917 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x3a); | |
1918 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
1919 | #else | |
1920 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1a); | |
1921 | tcg_gen_sari_tl(t0, t0, 0x1f); | |
1922 | #endif | |
1923 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
1924 | tcg_gen_ext32u_tl(t0, t0); | |
a7812ae4 | 1925 | t1 = tcg_temp_new(); |
7fd6bf7d AJ |
1926 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1f); |
1927 | tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
fea0c503 | 1928 | tcg_temp_free(t1); |
fea0c503 | 1929 | tcg_temp_free(t0); |
26d67362 AJ |
1930 | if (unlikely(Rc(ctx->opcode) != 0)) |
1931 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1932 | } | |
54623277 | 1933 | |
d9bce9d9 JM |
1934 | #if defined(TARGET_PPC64) |
1935 | /* sld & sld. */ | |
99e300ef | 1936 | static void gen_sld(DisasContext *ctx) |
26d67362 | 1937 | { |
7fd6bf7d | 1938 | TCGv t0, t1; |
26d67362 | 1939 | |
7fd6bf7d AJ |
1940 | t0 = tcg_temp_new(); |
1941 | /* AND rS with a mask that is 0 when rB >= 0x40 */ | |
1942 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39); | |
1943 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
1944 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
1945 | t1 = tcg_temp_new(); | |
1946 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f); | |
1947 | tcg_gen_shl_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
1948 | tcg_temp_free(t1); | |
fea0c503 | 1949 | tcg_temp_free(t0); |
26d67362 AJ |
1950 | if (unlikely(Rc(ctx->opcode) != 0)) |
1951 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1952 | } | |
99e300ef | 1953 | |
54623277 | 1954 | /* srad & srad. */ |
99e300ef | 1955 | static void gen_srad(DisasContext *ctx) |
26d67362 | 1956 | { |
d15f74fb | 1957 | gen_helper_srad(cpu_gpr[rA(ctx->opcode)], cpu_env, |
a7812ae4 | 1958 | cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
26d67362 AJ |
1959 | if (unlikely(Rc(ctx->opcode) != 0)) |
1960 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
1961 | } | |
d9bce9d9 | 1962 | /* sradi & sradi. */ |
636aa200 | 1963 | static inline void gen_sradi(DisasContext *ctx, int n) |
d9bce9d9 | 1964 | { |
26d67362 | 1965 | int sh = SH(ctx->opcode) + (n << 5); |
ba4af3e4 RH |
1966 | TCGv dst = cpu_gpr[rA(ctx->opcode)]; |
1967 | TCGv src = cpu_gpr[rS(ctx->opcode)]; | |
1968 | if (sh == 0) { | |
1969 | tcg_gen_mov_tl(dst, src); | |
da91a00f | 1970 | tcg_gen_movi_tl(cpu_ca, 0); |
26d67362 | 1971 | } else { |
ba4af3e4 RH |
1972 | TCGv t0; |
1973 | tcg_gen_andi_tl(cpu_ca, src, (1ULL << sh) - 1); | |
1974 | t0 = tcg_temp_new(); | |
1975 | tcg_gen_sari_tl(t0, src, TARGET_LONG_BITS - 1); | |
1976 | tcg_gen_and_tl(cpu_ca, cpu_ca, t0); | |
1977 | tcg_temp_free(t0); | |
1978 | tcg_gen_setcondi_tl(TCG_COND_NE, cpu_ca, cpu_ca, 0); | |
1979 | tcg_gen_sari_tl(dst, src, sh); | |
1980 | } | |
1981 | if (unlikely(Rc(ctx->opcode) != 0)) { | |
1982 | gen_set_Rc0(ctx, dst); | |
d9bce9d9 | 1983 | } |
d9bce9d9 | 1984 | } |
e8eaa2c0 BS |
1985 | |
1986 | static void gen_sradi0(DisasContext *ctx) | |
d9bce9d9 JM |
1987 | { |
1988 | gen_sradi(ctx, 0); | |
1989 | } | |
e8eaa2c0 BS |
1990 | |
1991 | static void gen_sradi1(DisasContext *ctx) | |
d9bce9d9 JM |
1992 | { |
1993 | gen_sradi(ctx, 1); | |
1994 | } | |
99e300ef | 1995 | |
54623277 | 1996 | /* srd & srd. */ |
99e300ef | 1997 | static void gen_srd(DisasContext *ctx) |
26d67362 | 1998 | { |
7fd6bf7d | 1999 | TCGv t0, t1; |
26d67362 | 2000 | |
7fd6bf7d AJ |
2001 | t0 = tcg_temp_new(); |
2002 | /* AND rS with a mask that is 0 when rB >= 0x40 */ | |
2003 | tcg_gen_shli_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x39); | |
2004 | tcg_gen_sari_tl(t0, t0, 0x3f); | |
2005 | tcg_gen_andc_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
2006 | t1 = tcg_temp_new(); | |
2007 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x3f); | |
2008 | tcg_gen_shr_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
2009 | tcg_temp_free(t1); | |
fea0c503 | 2010 | tcg_temp_free(t0); |
26d67362 AJ |
2011 | if (unlikely(Rc(ctx->opcode) != 0)) |
2012 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); | |
2013 | } | |
d9bce9d9 | 2014 | #endif |
79aceca5 FB |
2015 | |
2016 | /*** Floating-Point arithmetic ***/ | |
7c58044c | 2017 | #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \ |
99e300ef | 2018 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2019 | { \ |
76a66253 | 2020 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2021 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2022 | return; \ |
2023 | } \ | |
eb44b959 AJ |
2024 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2025 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2026 | gen_reset_fpstatus(); \ |
8e703949 BS |
2027 | gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2028 | cpu_fpr[rA(ctx->opcode)], \ | |
af12906f | 2029 | cpu_fpr[rC(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); \ |
4ecc3190 | 2030 | if (isfloat) { \ |
8e703949 BS |
2031 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2032 | cpu_fpr[rD(ctx->opcode)]); \ | |
4ecc3190 | 2033 | } \ |
af12906f AJ |
2034 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], set_fprf, \ |
2035 | Rc(ctx->opcode) != 0); \ | |
9a64fbe4 FB |
2036 | } |
2037 | ||
7c58044c JM |
2038 | #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \ |
2039 | _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type); \ | |
2040 | _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type); | |
9a64fbe4 | 2041 | |
7c58044c | 2042 | #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \ |
99e300ef | 2043 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2044 | { \ |
76a66253 | 2045 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2046 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2047 | return; \ |
2048 | } \ | |
eb44b959 AJ |
2049 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2050 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2051 | gen_reset_fpstatus(); \ |
8e703949 BS |
2052 | gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2053 | cpu_fpr[rA(ctx->opcode)], \ | |
af12906f | 2054 | cpu_fpr[rB(ctx->opcode)]); \ |
4ecc3190 | 2055 | if (isfloat) { \ |
8e703949 BS |
2056 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2057 | cpu_fpr[rD(ctx->opcode)]); \ | |
4ecc3190 | 2058 | } \ |
af12906f AJ |
2059 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \ |
2060 | set_fprf, Rc(ctx->opcode) != 0); \ | |
9a64fbe4 | 2061 | } |
7c58044c JM |
2062 | #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \ |
2063 | _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type); \ | |
2064 | _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type); | |
9a64fbe4 | 2065 | |
7c58044c | 2066 | #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \ |
99e300ef | 2067 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2068 | { \ |
76a66253 | 2069 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2070 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2071 | return; \ |
2072 | } \ | |
eb44b959 AJ |
2073 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2074 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2075 | gen_reset_fpstatus(); \ |
8e703949 BS |
2076 | gen_helper_f##op(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2077 | cpu_fpr[rA(ctx->opcode)], \ | |
2078 | cpu_fpr[rC(ctx->opcode)]); \ | |
4ecc3190 | 2079 | if (isfloat) { \ |
8e703949 BS |
2080 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2081 | cpu_fpr[rD(ctx->opcode)]); \ | |
4ecc3190 | 2082 | } \ |
af12906f AJ |
2083 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \ |
2084 | set_fprf, Rc(ctx->opcode) != 0); \ | |
9a64fbe4 | 2085 | } |
7c58044c JM |
2086 | #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \ |
2087 | _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type); \ | |
2088 | _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type); | |
9a64fbe4 | 2089 | |
7c58044c | 2090 | #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \ |
99e300ef | 2091 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2092 | { \ |
76a66253 | 2093 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2094 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2095 | return; \ |
2096 | } \ | |
eb44b959 AJ |
2097 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2098 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2099 | gen_reset_fpstatus(); \ |
8e703949 BS |
2100 | gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2101 | cpu_fpr[rB(ctx->opcode)]); \ | |
af12906f AJ |
2102 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \ |
2103 | set_fprf, Rc(ctx->opcode) != 0); \ | |
79aceca5 FB |
2104 | } |
2105 | ||
7c58044c | 2106 | #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \ |
99e300ef | 2107 | static void gen_f##name(DisasContext *ctx) \ |
9a64fbe4 | 2108 | { \ |
76a66253 | 2109 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 2110 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
3cc62370 FB |
2111 | return; \ |
2112 | } \ | |
eb44b959 AJ |
2113 | /* NIP cannot be restored if the memory exception comes from an helper */ \ |
2114 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7c58044c | 2115 | gen_reset_fpstatus(); \ |
8e703949 BS |
2116 | gen_helper_f##name(cpu_fpr[rD(ctx->opcode)], cpu_env, \ |
2117 | cpu_fpr[rB(ctx->opcode)]); \ | |
af12906f AJ |
2118 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], \ |
2119 | set_fprf, Rc(ctx->opcode) != 0); \ | |
79aceca5 FB |
2120 | } |
2121 | ||
9a64fbe4 | 2122 | /* fadd - fadds */ |
7c58044c | 2123 | GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT); |
4ecc3190 | 2124 | /* fdiv - fdivs */ |
7c58044c | 2125 | GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT); |
4ecc3190 | 2126 | /* fmul - fmuls */ |
7c58044c | 2127 | GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT); |
79aceca5 | 2128 | |
d7e4b87e | 2129 | /* fre */ |
7c58044c | 2130 | GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2131 | |
a750fc0b | 2132 | /* fres */ |
7c58044c | 2133 | GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES); |
79aceca5 | 2134 | |
a750fc0b | 2135 | /* frsqrte */ |
7c58044c JM |
2136 | GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE); |
2137 | ||
2138 | /* frsqrtes */ | |
99e300ef | 2139 | static void gen_frsqrtes(DisasContext *ctx) |
7c58044c | 2140 | { |
af12906f | 2141 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2142 | gen_exception(ctx, POWERPC_EXCP_FPU); |
af12906f AJ |
2143 | return; |
2144 | } | |
eb44b959 AJ |
2145 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2146 | gen_update_nip(ctx, ctx->nip - 4); | |
af12906f | 2147 | gen_reset_fpstatus(); |
8e703949 BS |
2148 | gen_helper_frsqrte(cpu_fpr[rD(ctx->opcode)], cpu_env, |
2149 | cpu_fpr[rB(ctx->opcode)]); | |
2150 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, | |
2151 | cpu_fpr[rD(ctx->opcode)]); | |
af12906f | 2152 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0); |
7c58044c | 2153 | } |
79aceca5 | 2154 | |
a750fc0b | 2155 | /* fsel */ |
7c58044c | 2156 | _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL); |
4ecc3190 | 2157 | /* fsub - fsubs */ |
7c58044c | 2158 | GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT); |
79aceca5 | 2159 | /* Optional: */ |
99e300ef | 2160 | |
54623277 | 2161 | /* fsqrt */ |
99e300ef | 2162 | static void gen_fsqrt(DisasContext *ctx) |
c7d344af | 2163 | { |
76a66253 | 2164 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2165 | gen_exception(ctx, POWERPC_EXCP_FPU); |
c7d344af FB |
2166 | return; |
2167 | } | |
eb44b959 AJ |
2168 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2169 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2170 | gen_reset_fpstatus(); |
8e703949 BS |
2171 | gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env, |
2172 | cpu_fpr[rB(ctx->opcode)]); | |
af12906f | 2173 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0); |
c7d344af | 2174 | } |
79aceca5 | 2175 | |
99e300ef | 2176 | static void gen_fsqrts(DisasContext *ctx) |
79aceca5 | 2177 | { |
76a66253 | 2178 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2179 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2180 | return; |
2181 | } | |
eb44b959 AJ |
2182 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2183 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2184 | gen_reset_fpstatus(); |
8e703949 BS |
2185 | gen_helper_fsqrt(cpu_fpr[rD(ctx->opcode)], cpu_env, |
2186 | cpu_fpr[rB(ctx->opcode)]); | |
2187 | gen_helper_frsp(cpu_fpr[rD(ctx->opcode)], cpu_env, | |
2188 | cpu_fpr[rD(ctx->opcode)]); | |
af12906f | 2189 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 1, Rc(ctx->opcode) != 0); |
79aceca5 FB |
2190 | } |
2191 | ||
2192 | /*** Floating-Point multiply-and-add ***/ | |
4ecc3190 | 2193 | /* fmadd - fmadds */ |
7c58044c | 2194 | GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT); |
4ecc3190 | 2195 | /* fmsub - fmsubs */ |
7c58044c | 2196 | GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT); |
4ecc3190 | 2197 | /* fnmadd - fnmadds */ |
7c58044c | 2198 | GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT); |
4ecc3190 | 2199 | /* fnmsub - fnmsubs */ |
7c58044c | 2200 | GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT); |
79aceca5 FB |
2201 | |
2202 | /*** Floating-Point round & convert ***/ | |
2203 | /* fctiw */ | |
7c58044c | 2204 | GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT); |
fab7fe42 TM |
2205 | /* fctiwu */ |
2206 | GEN_FLOAT_B(ctiwu, 0x0E, 0x04, 0, PPC2_FP_CVT_ISA206); | |
79aceca5 | 2207 | /* fctiwz */ |
7c58044c | 2208 | GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT); |
fab7fe42 TM |
2209 | /* fctiwuz */ |
2210 | GEN_FLOAT_B(ctiwuz, 0x0F, 0x04, 0, PPC2_FP_CVT_ISA206); | |
79aceca5 | 2211 | /* frsp */ |
7c58044c | 2212 | GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT); |
426613db JM |
2213 | #if defined(TARGET_PPC64) |
2214 | /* fcfid */ | |
7c58044c | 2215 | GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B); |
28288b48 TM |
2216 | /* fcfids */ |
2217 | GEN_FLOAT_B(cfids, 0x0E, 0x1A, 0, PPC2_FP_CVT_ISA206); | |
2218 | /* fcfidu */ | |
2219 | GEN_FLOAT_B(cfidu, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206); | |
2220 | /* fcfidus */ | |
2221 | GEN_FLOAT_B(cfidus, 0x0E, 0x1E, 0, PPC2_FP_CVT_ISA206); | |
426613db | 2222 | /* fctid */ |
7c58044c | 2223 | GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B); |
fab7fe42 TM |
2224 | /* fctidu */ |
2225 | GEN_FLOAT_B(ctidu, 0x0E, 0x1D, 0, PPC2_FP_CVT_ISA206); | |
426613db | 2226 | /* fctidz */ |
7c58044c | 2227 | GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B); |
fab7fe42 TM |
2228 | /* fctidu */ |
2229 | GEN_FLOAT_B(ctiduz, 0x0F, 0x1D, 0, PPC2_FP_CVT_ISA206); | |
426613db | 2230 | #endif |
79aceca5 | 2231 | |
d7e4b87e | 2232 | /* frin */ |
7c58044c | 2233 | GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2234 | /* friz */ |
7c58044c | 2235 | GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2236 | /* frip */ |
7c58044c | 2237 | GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2238 | /* frim */ |
7c58044c | 2239 | GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT); |
d7e4b87e | 2240 | |
da29cb7b TM |
2241 | static void gen_ftdiv(DisasContext *ctx) |
2242 | { | |
2243 | if (unlikely(!ctx->fpu_enabled)) { | |
2244 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
2245 | return; | |
2246 | } | |
2247 | gen_helper_ftdiv(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], | |
2248 | cpu_fpr[rB(ctx->opcode)]); | |
2249 | } | |
2250 | ||
6d41d146 TM |
2251 | static void gen_ftsqrt(DisasContext *ctx) |
2252 | { | |
2253 | if (unlikely(!ctx->fpu_enabled)) { | |
2254 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
2255 | return; | |
2256 | } | |
2257 | gen_helper_ftsqrt(cpu_crf[crfD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); | |
2258 | } | |
2259 | ||
da29cb7b TM |
2260 | |
2261 | ||
79aceca5 | 2262 | /*** Floating-Point compare ***/ |
99e300ef | 2263 | |
54623277 | 2264 | /* fcmpo */ |
99e300ef | 2265 | static void gen_fcmpo(DisasContext *ctx) |
79aceca5 | 2266 | { |
330c483b | 2267 | TCGv_i32 crf; |
76a66253 | 2268 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2269 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2270 | return; |
2271 | } | |
eb44b959 AJ |
2272 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2273 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2274 | gen_reset_fpstatus(); |
9a819377 | 2275 | crf = tcg_const_i32(crfD(ctx->opcode)); |
8e703949 BS |
2276 | gen_helper_fcmpo(cpu_env, cpu_fpr[rA(ctx->opcode)], |
2277 | cpu_fpr[rB(ctx->opcode)], crf); | |
330c483b | 2278 | tcg_temp_free_i32(crf); |
8e703949 | 2279 | gen_helper_float_check_status(cpu_env); |
79aceca5 FB |
2280 | } |
2281 | ||
2282 | /* fcmpu */ | |
99e300ef | 2283 | static void gen_fcmpu(DisasContext *ctx) |
79aceca5 | 2284 | { |
330c483b | 2285 | TCGv_i32 crf; |
76a66253 | 2286 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2287 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2288 | return; |
2289 | } | |
eb44b959 AJ |
2290 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2291 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2292 | gen_reset_fpstatus(); |
9a819377 | 2293 | crf = tcg_const_i32(crfD(ctx->opcode)); |
8e703949 BS |
2294 | gen_helper_fcmpu(cpu_env, cpu_fpr[rA(ctx->opcode)], |
2295 | cpu_fpr[rB(ctx->opcode)], crf); | |
330c483b | 2296 | tcg_temp_free_i32(crf); |
8e703949 | 2297 | gen_helper_float_check_status(cpu_env); |
79aceca5 FB |
2298 | } |
2299 | ||
9a64fbe4 FB |
2300 | /*** Floating-point move ***/ |
2301 | /* fabs */ | |
7c58044c | 2302 | /* XXX: beware that fabs never checks for NaNs nor update FPSCR */ |
bf45a2e6 AJ |
2303 | static void gen_fabs(DisasContext *ctx) |
2304 | { | |
2305 | if (unlikely(!ctx->fpu_enabled)) { | |
2306 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
2307 | return; | |
2308 | } | |
2309 | tcg_gen_andi_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)], | |
2310 | ~(1ULL << 63)); | |
2311 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0); | |
2312 | } | |
9a64fbe4 FB |
2313 | |
2314 | /* fmr - fmr. */ | |
7c58044c | 2315 | /* XXX: beware that fmr never checks for NaNs nor update FPSCR */ |
99e300ef | 2316 | static void gen_fmr(DisasContext *ctx) |
9a64fbe4 | 2317 | { |
76a66253 | 2318 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2319 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2320 | return; |
2321 | } | |
af12906f AJ |
2322 | tcg_gen_mov_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)]); |
2323 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0); | |
9a64fbe4 FB |
2324 | } |
2325 | ||
2326 | /* fnabs */ | |
7c58044c | 2327 | /* XXX: beware that fnabs never checks for NaNs nor update FPSCR */ |
bf45a2e6 AJ |
2328 | static void gen_fnabs(DisasContext *ctx) |
2329 | { | |
2330 | if (unlikely(!ctx->fpu_enabled)) { | |
2331 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
2332 | return; | |
2333 | } | |
2334 | tcg_gen_ori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)], | |
2335 | 1ULL << 63); | |
2336 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0); | |
2337 | } | |
2338 | ||
9a64fbe4 | 2339 | /* fneg */ |
7c58044c | 2340 | /* XXX: beware that fneg never checks for NaNs nor update FPSCR */ |
bf45a2e6 AJ |
2341 | static void gen_fneg(DisasContext *ctx) |
2342 | { | |
2343 | if (unlikely(!ctx->fpu_enabled)) { | |
2344 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
2345 | return; | |
2346 | } | |
2347 | tcg_gen_xori_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rB(ctx->opcode)], | |
2348 | 1ULL << 63); | |
2349 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0); | |
2350 | } | |
9a64fbe4 | 2351 | |
f0332888 AJ |
2352 | /* fcpsgn: PowerPC 2.05 specification */ |
2353 | /* XXX: beware that fcpsgn never checks for NaNs nor update FPSCR */ | |
2354 | static void gen_fcpsgn(DisasContext *ctx) | |
2355 | { | |
2356 | if (unlikely(!ctx->fpu_enabled)) { | |
2357 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
2358 | return; | |
2359 | } | |
2360 | tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], | |
2361 | cpu_fpr[rB(ctx->opcode)], 0, 63); | |
2362 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0); | |
2363 | } | |
2364 | ||
097ec5d8 TM |
2365 | static void gen_fmrgew(DisasContext *ctx) |
2366 | { | |
2367 | TCGv_i64 b0; | |
2368 | if (unlikely(!ctx->fpu_enabled)) { | |
2369 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
2370 | return; | |
2371 | } | |
2372 | b0 = tcg_temp_new_i64(); | |
2373 | tcg_gen_shri_i64(b0, cpu_fpr[rB(ctx->opcode)], 32); | |
2374 | tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpr[rA(ctx->opcode)], | |
2375 | b0, 0, 32); | |
2376 | tcg_temp_free_i64(b0); | |
2377 | } | |
2378 | ||
2379 | static void gen_fmrgow(DisasContext *ctx) | |
2380 | { | |
2381 | if (unlikely(!ctx->fpu_enabled)) { | |
2382 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
2383 | return; | |
2384 | } | |
2385 | tcg_gen_deposit_i64(cpu_fpr[rD(ctx->opcode)], | |
2386 | cpu_fpr[rB(ctx->opcode)], | |
2387 | cpu_fpr[rA(ctx->opcode)], | |
2388 | 32, 32); | |
2389 | } | |
2390 | ||
79aceca5 | 2391 | /*** Floating-Point status & ctrl register ***/ |
99e300ef | 2392 | |
54623277 | 2393 | /* mcrfs */ |
99e300ef | 2394 | static void gen_mcrfs(DisasContext *ctx) |
79aceca5 | 2395 | { |
30304420 | 2396 | TCGv tmp = tcg_temp_new(); |
7c58044c JM |
2397 | int bfa; |
2398 | ||
76a66253 | 2399 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2400 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2401 | return; |
2402 | } | |
7c58044c | 2403 | bfa = 4 * (7 - crfS(ctx->opcode)); |
30304420 DG |
2404 | tcg_gen_shri_tl(tmp, cpu_fpscr, bfa); |
2405 | tcg_gen_trunc_tl_i32(cpu_crf[crfD(ctx->opcode)], tmp); | |
2406 | tcg_temp_free(tmp); | |
e1571908 | 2407 | tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], 0xf); |
30304420 | 2408 | tcg_gen_andi_tl(cpu_fpscr, cpu_fpscr, ~(0xF << bfa)); |
79aceca5 FB |
2409 | } |
2410 | ||
2411 | /* mffs */ | |
99e300ef | 2412 | static void gen_mffs(DisasContext *ctx) |
79aceca5 | 2413 | { |
76a66253 | 2414 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2415 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2416 | return; |
2417 | } | |
7c58044c | 2418 | gen_reset_fpstatus(); |
30304420 | 2419 | tcg_gen_extu_tl_i64(cpu_fpr[rD(ctx->opcode)], cpu_fpscr); |
af12906f | 2420 | gen_compute_fprf(cpu_fpr[rD(ctx->opcode)], 0, Rc(ctx->opcode) != 0); |
79aceca5 FB |
2421 | } |
2422 | ||
2423 | /* mtfsb0 */ | |
99e300ef | 2424 | static void gen_mtfsb0(DisasContext *ctx) |
79aceca5 | 2425 | { |
fb0eaffc | 2426 | uint8_t crb; |
3b46e624 | 2427 | |
76a66253 | 2428 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2429 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2430 | return; |
2431 | } | |
6e35d524 | 2432 | crb = 31 - crbD(ctx->opcode); |
7c58044c | 2433 | gen_reset_fpstatus(); |
6e35d524 | 2434 | if (likely(crb != FPSCR_FEX && crb != FPSCR_VX)) { |
eb44b959 AJ |
2435 | TCGv_i32 t0; |
2436 | /* NIP cannot be restored if the memory exception comes from an helper */ | |
2437 | gen_update_nip(ctx, ctx->nip - 4); | |
2438 | t0 = tcg_const_i32(crb); | |
8e703949 | 2439 | gen_helper_fpscr_clrbit(cpu_env, t0); |
6e35d524 AJ |
2440 | tcg_temp_free_i32(t0); |
2441 | } | |
7c58044c | 2442 | if (unlikely(Rc(ctx->opcode) != 0)) { |
30304420 DG |
2443 | tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr); |
2444 | tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX); | |
7c58044c | 2445 | } |
79aceca5 FB |
2446 | } |
2447 | ||
2448 | /* mtfsb1 */ | |
99e300ef | 2449 | static void gen_mtfsb1(DisasContext *ctx) |
79aceca5 | 2450 | { |
fb0eaffc | 2451 | uint8_t crb; |
3b46e624 | 2452 | |
76a66253 | 2453 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2454 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2455 | return; |
2456 | } | |
6e35d524 | 2457 | crb = 31 - crbD(ctx->opcode); |
7c58044c JM |
2458 | gen_reset_fpstatus(); |
2459 | /* XXX: we pretend we can only do IEEE floating-point computations */ | |
af12906f | 2460 | if (likely(crb != FPSCR_FEX && crb != FPSCR_VX && crb != FPSCR_NI)) { |
eb44b959 AJ |
2461 | TCGv_i32 t0; |
2462 | /* NIP cannot be restored if the memory exception comes from an helper */ | |
2463 | gen_update_nip(ctx, ctx->nip - 4); | |
2464 | t0 = tcg_const_i32(crb); | |
8e703949 | 2465 | gen_helper_fpscr_setbit(cpu_env, t0); |
0f2f39c2 | 2466 | tcg_temp_free_i32(t0); |
af12906f | 2467 | } |
7c58044c | 2468 | if (unlikely(Rc(ctx->opcode) != 0)) { |
30304420 DG |
2469 | tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr); |
2470 | tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX); | |
7c58044c JM |
2471 | } |
2472 | /* We can raise a differed exception */ | |
8e703949 | 2473 | gen_helper_float_check_status(cpu_env); |
79aceca5 FB |
2474 | } |
2475 | ||
2476 | /* mtfsf */ | |
99e300ef | 2477 | static void gen_mtfsf(DisasContext *ctx) |
79aceca5 | 2478 | { |
0f2f39c2 | 2479 | TCGv_i32 t0; |
7d08d856 | 2480 | int flm, l, w; |
af12906f | 2481 | |
76a66253 | 2482 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2483 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2484 | return; |
2485 | } | |
7d08d856 AJ |
2486 | flm = FPFLM(ctx->opcode); |
2487 | l = FPL(ctx->opcode); | |
2488 | w = FPW(ctx->opcode); | |
2489 | if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) { | |
2490 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); | |
2491 | return; | |
2492 | } | |
eb44b959 AJ |
2493 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2494 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2495 | gen_reset_fpstatus(); |
7d08d856 AJ |
2496 | if (l) { |
2497 | t0 = tcg_const_i32((ctx->insns_flags2 & PPC2_ISA205) ? 0xffff : 0xff); | |
2498 | } else { | |
2499 | t0 = tcg_const_i32(flm << (w * 8)); | |
2500 | } | |
8e703949 | 2501 | gen_helper_store_fpscr(cpu_env, cpu_fpr[rB(ctx->opcode)], t0); |
0f2f39c2 | 2502 | tcg_temp_free_i32(t0); |
7c58044c | 2503 | if (unlikely(Rc(ctx->opcode) != 0)) { |
30304420 DG |
2504 | tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr); |
2505 | tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX); | |
7c58044c JM |
2506 | } |
2507 | /* We can raise a differed exception */ | |
8e703949 | 2508 | gen_helper_float_check_status(cpu_env); |
79aceca5 FB |
2509 | } |
2510 | ||
2511 | /* mtfsfi */ | |
99e300ef | 2512 | static void gen_mtfsfi(DisasContext *ctx) |
79aceca5 | 2513 | { |
7d08d856 | 2514 | int bf, sh, w; |
0f2f39c2 AJ |
2515 | TCGv_i64 t0; |
2516 | TCGv_i32 t1; | |
7c58044c | 2517 | |
76a66253 | 2518 | if (unlikely(!ctx->fpu_enabled)) { |
e06fcd75 | 2519 | gen_exception(ctx, POWERPC_EXCP_FPU); |
3cc62370 FB |
2520 | return; |
2521 | } | |
7d08d856 AJ |
2522 | w = FPW(ctx->opcode); |
2523 | bf = FPBF(ctx->opcode); | |
2524 | if (unlikely(w & !(ctx->insns_flags2 & PPC2_ISA205))) { | |
2525 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); | |
2526 | return; | |
2527 | } | |
2528 | sh = (8 * w) + 7 - bf; | |
eb44b959 AJ |
2529 | /* NIP cannot be restored if the memory exception comes from an helper */ |
2530 | gen_update_nip(ctx, ctx->nip - 4); | |
7c58044c | 2531 | gen_reset_fpstatus(); |
7d08d856 | 2532 | t0 = tcg_const_i64(((uint64_t)FPIMM(ctx->opcode)) << (4 * sh)); |
af12906f | 2533 | t1 = tcg_const_i32(1 << sh); |
8e703949 | 2534 | gen_helper_store_fpscr(cpu_env, t0, t1); |
0f2f39c2 AJ |
2535 | tcg_temp_free_i64(t0); |
2536 | tcg_temp_free_i32(t1); | |
7c58044c | 2537 | if (unlikely(Rc(ctx->opcode) != 0)) { |
30304420 DG |
2538 | tcg_gen_trunc_tl_i32(cpu_crf[1], cpu_fpscr); |
2539 | tcg_gen_shri_i32(cpu_crf[1], cpu_crf[1], FPSCR_OX); | |
7c58044c JM |
2540 | } |
2541 | /* We can raise a differed exception */ | |
8e703949 | 2542 | gen_helper_float_check_status(cpu_env); |
79aceca5 FB |
2543 | } |
2544 | ||
76a66253 JM |
2545 | /*** Addressing modes ***/ |
2546 | /* Register indirect with immediate index : EA = (rA|0) + SIMM */ | |
636aa200 BS |
2547 | static inline void gen_addr_imm_index(DisasContext *ctx, TCGv EA, |
2548 | target_long maskl) | |
76a66253 JM |
2549 | { |
2550 | target_long simm = SIMM(ctx->opcode); | |
2551 | ||
be147d08 | 2552 | simm &= ~maskl; |
76db3ba4 | 2553 | if (rA(ctx->opcode) == 0) { |
c791fe84 RH |
2554 | if (NARROW_MODE(ctx)) { |
2555 | simm = (uint32_t)simm; | |
2556 | } | |
e2be8d8d | 2557 | tcg_gen_movi_tl(EA, simm); |
76db3ba4 | 2558 | } else if (likely(simm != 0)) { |
e2be8d8d | 2559 | tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], simm); |
c791fe84 | 2560 | if (NARROW_MODE(ctx)) { |
76db3ba4 AJ |
2561 | tcg_gen_ext32u_tl(EA, EA); |
2562 | } | |
76db3ba4 | 2563 | } else { |
c791fe84 | 2564 | if (NARROW_MODE(ctx)) { |
76db3ba4 | 2565 | tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]); |
c791fe84 RH |
2566 | } else { |
2567 | tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]); | |
2568 | } | |
76db3ba4 | 2569 | } |
76a66253 JM |
2570 | } |
2571 | ||
636aa200 | 2572 | static inline void gen_addr_reg_index(DisasContext *ctx, TCGv EA) |
76a66253 | 2573 | { |
76db3ba4 | 2574 | if (rA(ctx->opcode) == 0) { |
c791fe84 | 2575 | if (NARROW_MODE(ctx)) { |
76db3ba4 | 2576 | tcg_gen_ext32u_tl(EA, cpu_gpr[rB(ctx->opcode)]); |
c791fe84 RH |
2577 | } else { |
2578 | tcg_gen_mov_tl(EA, cpu_gpr[rB(ctx->opcode)]); | |
2579 | } | |
76db3ba4 | 2580 | } else { |
e2be8d8d | 2581 | tcg_gen_add_tl(EA, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
c791fe84 | 2582 | if (NARROW_MODE(ctx)) { |
76db3ba4 AJ |
2583 | tcg_gen_ext32u_tl(EA, EA); |
2584 | } | |
76db3ba4 | 2585 | } |
76a66253 JM |
2586 | } |
2587 | ||
636aa200 | 2588 | static inline void gen_addr_register(DisasContext *ctx, TCGv EA) |
76a66253 | 2589 | { |
76db3ba4 | 2590 | if (rA(ctx->opcode) == 0) { |
e2be8d8d | 2591 | tcg_gen_movi_tl(EA, 0); |
c791fe84 RH |
2592 | } else if (NARROW_MODE(ctx)) { |
2593 | tcg_gen_ext32u_tl(EA, cpu_gpr[rA(ctx->opcode)]); | |
76db3ba4 | 2594 | } else { |
c791fe84 | 2595 | tcg_gen_mov_tl(EA, cpu_gpr[rA(ctx->opcode)]); |
76db3ba4 AJ |
2596 | } |
2597 | } | |
2598 | ||
636aa200 BS |
2599 | static inline void gen_addr_add(DisasContext *ctx, TCGv ret, TCGv arg1, |
2600 | target_long val) | |
76db3ba4 AJ |
2601 | { |
2602 | tcg_gen_addi_tl(ret, arg1, val); | |
c791fe84 | 2603 | if (NARROW_MODE(ctx)) { |
76db3ba4 AJ |
2604 | tcg_gen_ext32u_tl(ret, ret); |
2605 | } | |
76a66253 JM |
2606 | } |
2607 | ||
636aa200 | 2608 | static inline void gen_check_align(DisasContext *ctx, TCGv EA, int mask) |
cf360a32 AJ |
2609 | { |
2610 | int l1 = gen_new_label(); | |
2611 | TCGv t0 = tcg_temp_new(); | |
2612 | TCGv_i32 t1, t2; | |
2613 | /* NIP cannot be restored if the memory exception comes from an helper */ | |
2614 | gen_update_nip(ctx, ctx->nip - 4); | |
2615 | tcg_gen_andi_tl(t0, EA, mask); | |
2616 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
2617 | t1 = tcg_const_i32(POWERPC_EXCP_ALIGN); | |
2618 | t2 = tcg_const_i32(0); | |
e5f17ac6 | 2619 | gen_helper_raise_exception_err(cpu_env, t1, t2); |
cf360a32 AJ |
2620 | tcg_temp_free_i32(t1); |
2621 | tcg_temp_free_i32(t2); | |
2622 | gen_set_label(l1); | |
2623 | tcg_temp_free(t0); | |
2624 | } | |
2625 | ||
7863667f | 2626 | /*** Integer load ***/ |
636aa200 | 2627 | static inline void gen_qemu_ld8u(DisasContext *ctx, TCGv arg1, TCGv arg2) |
76db3ba4 AJ |
2628 | { |
2629 | tcg_gen_qemu_ld8u(arg1, arg2, ctx->mem_idx); | |
2630 | } | |
2631 | ||
636aa200 | 2632 | static inline void gen_qemu_ld8s(DisasContext *ctx, TCGv arg1, TCGv arg2) |
76db3ba4 AJ |
2633 | { |
2634 | tcg_gen_qemu_ld8s(arg1, arg2, ctx->mem_idx); | |
2635 | } | |
2636 | ||
636aa200 | 2637 | static inline void gen_qemu_ld16u(DisasContext *ctx, TCGv arg1, TCGv arg2) |
76db3ba4 AJ |
2638 | { |
2639 | tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx); | |
2640 | if (unlikely(ctx->le_mode)) { | |
fa3966a3 | 2641 | tcg_gen_bswap16_tl(arg1, arg1); |
76db3ba4 | 2642 | } |
b61f2753 AJ |
2643 | } |
2644 | ||
636aa200 | 2645 | static inline void gen_qemu_ld16s(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2646 | { |
76db3ba4 | 2647 | if (unlikely(ctx->le_mode)) { |
76db3ba4 | 2648 | tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx); |
fa3966a3 | 2649 | tcg_gen_bswap16_tl(arg1, arg1); |
76db3ba4 | 2650 | tcg_gen_ext16s_tl(arg1, arg1); |
76db3ba4 AJ |
2651 | } else { |
2652 | tcg_gen_qemu_ld16s(arg1, arg2, ctx->mem_idx); | |
2653 | } | |
b61f2753 AJ |
2654 | } |
2655 | ||
636aa200 | 2656 | static inline void gen_qemu_ld32u(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2657 | { |
76db3ba4 AJ |
2658 | tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx); |
2659 | if (unlikely(ctx->le_mode)) { | |
fa3966a3 | 2660 | tcg_gen_bswap32_tl(arg1, arg1); |
76db3ba4 | 2661 | } |
b61f2753 AJ |
2662 | } |
2663 | ||
f976b09e AG |
2664 | static void gen_qemu_ld32u_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr) |
2665 | { | |
2666 | TCGv tmp = tcg_temp_new(); | |
2667 | gen_qemu_ld32u(ctx, tmp, addr); | |
2668 | tcg_gen_extu_tl_i64(val, tmp); | |
2669 | tcg_temp_free(tmp); | |
2670 | } | |
2671 | ||
636aa200 | 2672 | static inline void gen_qemu_ld32s(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2673 | { |
a457e7ee | 2674 | if (unlikely(ctx->le_mode)) { |
76db3ba4 | 2675 | tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx); |
fa3966a3 AJ |
2676 | tcg_gen_bswap32_tl(arg1, arg1); |
2677 | tcg_gen_ext32s_tl(arg1, arg1); | |
b61f2753 | 2678 | } else |
76db3ba4 | 2679 | tcg_gen_qemu_ld32s(arg1, arg2, ctx->mem_idx); |
b61f2753 AJ |
2680 | } |
2681 | ||
cac7f0ba TM |
2682 | static void gen_qemu_ld32s_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr) |
2683 | { | |
2684 | TCGv tmp = tcg_temp_new(); | |
2685 | gen_qemu_ld32s(ctx, tmp, addr); | |
2686 | tcg_gen_ext_tl_i64(val, tmp); | |
2687 | tcg_temp_free(tmp); | |
2688 | } | |
2689 | ||
636aa200 | 2690 | static inline void gen_qemu_ld64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
b61f2753 | 2691 | { |
76db3ba4 AJ |
2692 | tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx); |
2693 | if (unlikely(ctx->le_mode)) { | |
66896cb8 | 2694 | tcg_gen_bswap64_i64(arg1, arg1); |
76db3ba4 | 2695 | } |
b61f2753 AJ |
2696 | } |
2697 | ||
636aa200 | 2698 | static inline void gen_qemu_st8(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2699 | { |
76db3ba4 | 2700 | tcg_gen_qemu_st8(arg1, arg2, ctx->mem_idx); |
b61f2753 AJ |
2701 | } |
2702 | ||
636aa200 | 2703 | static inline void gen_qemu_st16(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2704 | { |
76db3ba4 | 2705 | if (unlikely(ctx->le_mode)) { |
76db3ba4 AJ |
2706 | TCGv t0 = tcg_temp_new(); |
2707 | tcg_gen_ext16u_tl(t0, arg1); | |
fa3966a3 | 2708 | tcg_gen_bswap16_tl(t0, t0); |
76db3ba4 AJ |
2709 | tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx); |
2710 | tcg_temp_free(t0); | |
76db3ba4 AJ |
2711 | } else { |
2712 | tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx); | |
2713 | } | |
b61f2753 AJ |
2714 | } |
2715 | ||
636aa200 | 2716 | static inline void gen_qemu_st32(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 2717 | { |
76db3ba4 | 2718 | if (unlikely(ctx->le_mode)) { |
fa3966a3 AJ |
2719 | TCGv t0 = tcg_temp_new(); |
2720 | tcg_gen_ext32u_tl(t0, arg1); | |
2721 | tcg_gen_bswap32_tl(t0, t0); | |
76db3ba4 AJ |
2722 | tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx); |
2723 | tcg_temp_free(t0); | |
76db3ba4 AJ |
2724 | } else { |
2725 | tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx); | |
2726 | } | |
b61f2753 AJ |
2727 | } |
2728 | ||
f976b09e AG |
2729 | static void gen_qemu_st32_i64(DisasContext *ctx, TCGv_i64 val, TCGv addr) |
2730 | { | |
2731 | TCGv tmp = tcg_temp_new(); | |
2732 | tcg_gen_trunc_i64_tl(tmp, val); | |
2733 | gen_qemu_st32(ctx, tmp, addr); | |
2734 | tcg_temp_free(tmp); | |
2735 | } | |
2736 | ||
636aa200 | 2737 | static inline void gen_qemu_st64(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
b61f2753 | 2738 | { |
76db3ba4 | 2739 | if (unlikely(ctx->le_mode)) { |
a7812ae4 | 2740 | TCGv_i64 t0 = tcg_temp_new_i64(); |
66896cb8 | 2741 | tcg_gen_bswap64_i64(t0, arg1); |
76db3ba4 | 2742 | tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx); |
a7812ae4 | 2743 | tcg_temp_free_i64(t0); |
b61f2753 | 2744 | } else |
76db3ba4 | 2745 | tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx); |
b61f2753 AJ |
2746 | } |
2747 | ||
0c8aacd4 | 2748 | #define GEN_LD(name, ldop, opc, type) \ |
99e300ef | 2749 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 2750 | { \ |
76db3ba4 AJ |
2751 | TCGv EA; \ |
2752 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2753 | EA = tcg_temp_new(); \ | |
2754 | gen_addr_imm_index(ctx, EA, 0); \ | |
2755 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 | 2756 | tcg_temp_free(EA); \ |
79aceca5 FB |
2757 | } |
2758 | ||
0c8aacd4 | 2759 | #define GEN_LDU(name, ldop, opc, type) \ |
99e300ef | 2760 | static void glue(gen_, name##u)(DisasContext *ctx) \ |
79aceca5 | 2761 | { \ |
b61f2753 | 2762 | TCGv EA; \ |
76a66253 JM |
2763 | if (unlikely(rA(ctx->opcode) == 0 || \ |
2764 | rA(ctx->opcode) == rD(ctx->opcode))) { \ | |
e06fcd75 | 2765 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2766 | return; \ |
9a64fbe4 | 2767 | } \ |
76db3ba4 | 2768 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2769 | EA = tcg_temp_new(); \ |
9d53c753 | 2770 | if (type == PPC_64B) \ |
76db3ba4 | 2771 | gen_addr_imm_index(ctx, EA, 0x03); \ |
9d53c753 | 2772 | else \ |
76db3ba4 AJ |
2773 | gen_addr_imm_index(ctx, EA, 0); \ |
2774 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2775 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2776 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2777 | } |
2778 | ||
0c8aacd4 | 2779 | #define GEN_LDUX(name, ldop, opc2, opc3, type) \ |
99e300ef | 2780 | static void glue(gen_, name##ux)(DisasContext *ctx) \ |
79aceca5 | 2781 | { \ |
b61f2753 | 2782 | TCGv EA; \ |
76a66253 JM |
2783 | if (unlikely(rA(ctx->opcode) == 0 || \ |
2784 | rA(ctx->opcode) == rD(ctx->opcode))) { \ | |
e06fcd75 | 2785 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2786 | return; \ |
9a64fbe4 | 2787 | } \ |
76db3ba4 | 2788 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2789 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
2790 | gen_addr_reg_index(ctx, EA); \ |
2791 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2792 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2793 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2794 | } |
2795 | ||
cd6e9320 | 2796 | #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \ |
99e300ef | 2797 | static void glue(gen_, name##x)(DisasContext *ctx) \ |
79aceca5 | 2798 | { \ |
76db3ba4 AJ |
2799 | TCGv EA; \ |
2800 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2801 | EA = tcg_temp_new(); \ | |
2802 | gen_addr_reg_index(ctx, EA); \ | |
2803 | gen_qemu_##ldop(ctx, cpu_gpr[rD(ctx->opcode)], EA); \ | |
b61f2753 | 2804 | tcg_temp_free(EA); \ |
79aceca5 | 2805 | } |
cd6e9320 TH |
2806 | #define GEN_LDX(name, ldop, opc2, opc3, type) \ |
2807 | GEN_LDX_E(name, ldop, opc2, opc3, type, PPC_NONE) | |
79aceca5 | 2808 | |
0c8aacd4 AJ |
2809 | #define GEN_LDS(name, ldop, op, type) \ |
2810 | GEN_LD(name, ldop, op | 0x20, type); \ | |
2811 | GEN_LDU(name, ldop, op | 0x21, type); \ | |
2812 | GEN_LDUX(name, ldop, 0x17, op | 0x01, type); \ | |
2813 | GEN_LDX(name, ldop, 0x17, op | 0x00, type) | |
79aceca5 FB |
2814 | |
2815 | /* lbz lbzu lbzux lbzx */ | |
0c8aacd4 | 2816 | GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER); |
79aceca5 | 2817 | /* lha lhau lhaux lhax */ |
0c8aacd4 | 2818 | GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER); |
79aceca5 | 2819 | /* lhz lhzu lhzux lhzx */ |
0c8aacd4 | 2820 | GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER); |
79aceca5 | 2821 | /* lwz lwzu lwzux lwzx */ |
0c8aacd4 | 2822 | GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER); |
d9bce9d9 | 2823 | #if defined(TARGET_PPC64) |
d9bce9d9 | 2824 | /* lwaux */ |
0c8aacd4 | 2825 | GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B); |
d9bce9d9 | 2826 | /* lwax */ |
0c8aacd4 | 2827 | GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B); |
d9bce9d9 | 2828 | /* ldux */ |
0c8aacd4 | 2829 | GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B); |
d9bce9d9 | 2830 | /* ldx */ |
0c8aacd4 | 2831 | GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B); |
99e300ef BS |
2832 | |
2833 | static void gen_ld(DisasContext *ctx) | |
d9bce9d9 | 2834 | { |
b61f2753 | 2835 | TCGv EA; |
d9bce9d9 JM |
2836 | if (Rc(ctx->opcode)) { |
2837 | if (unlikely(rA(ctx->opcode) == 0 || | |
2838 | rA(ctx->opcode) == rD(ctx->opcode))) { | |
e06fcd75 | 2839 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
d9bce9d9 JM |
2840 | return; |
2841 | } | |
2842 | } | |
76db3ba4 | 2843 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 2844 | EA = tcg_temp_new(); |
76db3ba4 | 2845 | gen_addr_imm_index(ctx, EA, 0x03); |
d9bce9d9 JM |
2846 | if (ctx->opcode & 0x02) { |
2847 | /* lwa (lwau is undefined) */ | |
76db3ba4 | 2848 | gen_qemu_ld32s(ctx, cpu_gpr[rD(ctx->opcode)], EA); |
d9bce9d9 JM |
2849 | } else { |
2850 | /* ld - ldu */ | |
76db3ba4 | 2851 | gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], EA); |
d9bce9d9 | 2852 | } |
d9bce9d9 | 2853 | if (Rc(ctx->opcode)) |
b61f2753 AJ |
2854 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); |
2855 | tcg_temp_free(EA); | |
d9bce9d9 | 2856 | } |
99e300ef | 2857 | |
54623277 | 2858 | /* lq */ |
99e300ef | 2859 | static void gen_lq(DisasContext *ctx) |
be147d08 JM |
2860 | { |
2861 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 2862 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
2863 | #else |
2864 | int ra, rd; | |
b61f2753 | 2865 | TCGv EA; |
be147d08 JM |
2866 | |
2867 | /* Restore CPU state */ | |
76db3ba4 | 2868 | if (unlikely(ctx->mem_idx == 0)) { |
e06fcd75 | 2869 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
2870 | return; |
2871 | } | |
2872 | ra = rA(ctx->opcode); | |
2873 | rd = rD(ctx->opcode); | |
2874 | if (unlikely((rd & 1) || rd == ra)) { | |
e06fcd75 | 2875 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
be147d08 JM |
2876 | return; |
2877 | } | |
76db3ba4 | 2878 | if (unlikely(ctx->le_mode)) { |
be147d08 | 2879 | /* Little-endian mode is not handled */ |
e06fcd75 | 2880 | gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE); |
be147d08 JM |
2881 | return; |
2882 | } | |
76db3ba4 | 2883 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 2884 | EA = tcg_temp_new(); |
76db3ba4 AJ |
2885 | gen_addr_imm_index(ctx, EA, 0x0F); |
2886 | gen_qemu_ld64(ctx, cpu_gpr[rd], EA); | |
2887 | gen_addr_add(ctx, EA, EA, 8); | |
2888 | gen_qemu_ld64(ctx, cpu_gpr[rd+1], EA); | |
b61f2753 | 2889 | tcg_temp_free(EA); |
be147d08 JM |
2890 | #endif |
2891 | } | |
d9bce9d9 | 2892 | #endif |
79aceca5 FB |
2893 | |
2894 | /*** Integer store ***/ | |
0c8aacd4 | 2895 | #define GEN_ST(name, stop, opc, type) \ |
99e300ef | 2896 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 2897 | { \ |
76db3ba4 AJ |
2898 | TCGv EA; \ |
2899 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2900 | EA = tcg_temp_new(); \ | |
2901 | gen_addr_imm_index(ctx, EA, 0); \ | |
2902 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 | 2903 | tcg_temp_free(EA); \ |
79aceca5 FB |
2904 | } |
2905 | ||
0c8aacd4 | 2906 | #define GEN_STU(name, stop, opc, type) \ |
99e300ef | 2907 | static void glue(gen_, stop##u)(DisasContext *ctx) \ |
79aceca5 | 2908 | { \ |
b61f2753 | 2909 | TCGv EA; \ |
76a66253 | 2910 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 2911 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2912 | return; \ |
9a64fbe4 | 2913 | } \ |
76db3ba4 | 2914 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2915 | EA = tcg_temp_new(); \ |
9d53c753 | 2916 | if (type == PPC_64B) \ |
76db3ba4 | 2917 | gen_addr_imm_index(ctx, EA, 0x03); \ |
9d53c753 | 2918 | else \ |
76db3ba4 AJ |
2919 | gen_addr_imm_index(ctx, EA, 0); \ |
2920 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2921 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2922 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2923 | } |
2924 | ||
0c8aacd4 | 2925 | #define GEN_STUX(name, stop, opc2, opc3, type) \ |
99e300ef | 2926 | static void glue(gen_, name##ux)(DisasContext *ctx) \ |
79aceca5 | 2927 | { \ |
b61f2753 | 2928 | TCGv EA; \ |
76a66253 | 2929 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 2930 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 2931 | return; \ |
9a64fbe4 | 2932 | } \ |
76db3ba4 | 2933 | gen_set_access_type(ctx, ACCESS_INT); \ |
0c8aacd4 | 2934 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
2935 | gen_addr_reg_index(ctx, EA); \ |
2936 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 AJ |
2937 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
2938 | tcg_temp_free(EA); \ | |
79aceca5 FB |
2939 | } |
2940 | ||
cd6e9320 TH |
2941 | #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \ |
2942 | static void glue(gen_, name##x)(DisasContext *ctx) \ | |
79aceca5 | 2943 | { \ |
76db3ba4 AJ |
2944 | TCGv EA; \ |
2945 | gen_set_access_type(ctx, ACCESS_INT); \ | |
2946 | EA = tcg_temp_new(); \ | |
2947 | gen_addr_reg_index(ctx, EA); \ | |
2948 | gen_qemu_##stop(ctx, cpu_gpr[rS(ctx->opcode)], EA); \ | |
b61f2753 | 2949 | tcg_temp_free(EA); \ |
79aceca5 | 2950 | } |
cd6e9320 TH |
2951 | #define GEN_STX(name, stop, opc2, opc3, type) \ |
2952 | GEN_STX_E(name, stop, opc2, opc3, type, PPC_NONE) | |
79aceca5 | 2953 | |
0c8aacd4 AJ |
2954 | #define GEN_STS(name, stop, op, type) \ |
2955 | GEN_ST(name, stop, op | 0x20, type); \ | |
2956 | GEN_STU(name, stop, op | 0x21, type); \ | |
2957 | GEN_STUX(name, stop, 0x17, op | 0x01, type); \ | |
2958 | GEN_STX(name, stop, 0x17, op | 0x00, type) | |
79aceca5 FB |
2959 | |
2960 | /* stb stbu stbux stbx */ | |
0c8aacd4 | 2961 | GEN_STS(stb, st8, 0x06, PPC_INTEGER); |
79aceca5 | 2962 | /* sth sthu sthux sthx */ |
0c8aacd4 | 2963 | GEN_STS(sth, st16, 0x0C, PPC_INTEGER); |
79aceca5 | 2964 | /* stw stwu stwux stwx */ |
0c8aacd4 | 2965 | GEN_STS(stw, st32, 0x04, PPC_INTEGER); |
d9bce9d9 | 2966 | #if defined(TARGET_PPC64) |
0c8aacd4 AJ |
2967 | GEN_STUX(std, st64, 0x15, 0x05, PPC_64B); |
2968 | GEN_STX(std, st64, 0x15, 0x04, PPC_64B); | |
99e300ef BS |
2969 | |
2970 | static void gen_std(DisasContext *ctx) | |
d9bce9d9 | 2971 | { |
be147d08 | 2972 | int rs; |
b61f2753 | 2973 | TCGv EA; |
be147d08 JM |
2974 | |
2975 | rs = rS(ctx->opcode); | |
2976 | if ((ctx->opcode & 0x3) == 0x2) { | |
2977 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 2978 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
2979 | #else |
2980 | /* stq */ | |
76db3ba4 | 2981 | if (unlikely(ctx->mem_idx == 0)) { |
e06fcd75 | 2982 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
2983 | return; |
2984 | } | |
2985 | if (unlikely(rs & 1)) { | |
e06fcd75 | 2986 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
d9bce9d9 JM |
2987 | return; |
2988 | } | |
76db3ba4 | 2989 | if (unlikely(ctx->le_mode)) { |
be147d08 | 2990 | /* Little-endian mode is not handled */ |
e06fcd75 | 2991 | gen_exception_err(ctx, POWERPC_EXCP_ALIGN, POWERPC_EXCP_ALIGN_LE); |
be147d08 JM |
2992 | return; |
2993 | } | |
76db3ba4 | 2994 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 2995 | EA = tcg_temp_new(); |
76db3ba4 AJ |
2996 | gen_addr_imm_index(ctx, EA, 0x03); |
2997 | gen_qemu_st64(ctx, cpu_gpr[rs], EA); | |
2998 | gen_addr_add(ctx, EA, EA, 8); | |
2999 | gen_qemu_st64(ctx, cpu_gpr[rs+1], EA); | |
b61f2753 | 3000 | tcg_temp_free(EA); |
be147d08 JM |
3001 | #endif |
3002 | } else { | |
3003 | /* std / stdu */ | |
3004 | if (Rc(ctx->opcode)) { | |
3005 | if (unlikely(rA(ctx->opcode) == 0)) { | |
e06fcd75 | 3006 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
be147d08 JM |
3007 | return; |
3008 | } | |
3009 | } | |
76db3ba4 | 3010 | gen_set_access_type(ctx, ACCESS_INT); |
a7812ae4 | 3011 | EA = tcg_temp_new(); |
76db3ba4 AJ |
3012 | gen_addr_imm_index(ctx, EA, 0x03); |
3013 | gen_qemu_st64(ctx, cpu_gpr[rs], EA); | |
be147d08 | 3014 | if (Rc(ctx->opcode)) |
b61f2753 AJ |
3015 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); |
3016 | tcg_temp_free(EA); | |
d9bce9d9 | 3017 | } |
d9bce9d9 JM |
3018 | } |
3019 | #endif | |
79aceca5 FB |
3020 | /*** Integer load and store with byte reverse ***/ |
3021 | /* lhbrx */ | |
86178a57 | 3022 | static inline void gen_qemu_ld16ur(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 3023 | { |
76db3ba4 AJ |
3024 | tcg_gen_qemu_ld16u(arg1, arg2, ctx->mem_idx); |
3025 | if (likely(!ctx->le_mode)) { | |
fa3966a3 | 3026 | tcg_gen_bswap16_tl(arg1, arg1); |
76db3ba4 | 3027 | } |
b61f2753 | 3028 | } |
0c8aacd4 | 3029 | GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER); |
b61f2753 | 3030 | |
79aceca5 | 3031 | /* lwbrx */ |
86178a57 | 3032 | static inline void gen_qemu_ld32ur(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 3033 | { |
76db3ba4 AJ |
3034 | tcg_gen_qemu_ld32u(arg1, arg2, ctx->mem_idx); |
3035 | if (likely(!ctx->le_mode)) { | |
fa3966a3 | 3036 | tcg_gen_bswap32_tl(arg1, arg1); |
76db3ba4 | 3037 | } |
b61f2753 | 3038 | } |
0c8aacd4 | 3039 | GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER); |
b61f2753 | 3040 | |
cd6e9320 TH |
3041 | #if defined(TARGET_PPC64) |
3042 | /* ldbrx */ | |
3043 | static inline void gen_qemu_ld64ur(DisasContext *ctx, TCGv arg1, TCGv arg2) | |
3044 | { | |
3045 | tcg_gen_qemu_ld64(arg1, arg2, ctx->mem_idx); | |
3046 | if (likely(!ctx->le_mode)) { | |
3047 | tcg_gen_bswap64_tl(arg1, arg1); | |
3048 | } | |
3049 | } | |
3050 | GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX); | |
3051 | #endif /* TARGET_PPC64 */ | |
3052 | ||
79aceca5 | 3053 | /* sthbrx */ |
86178a57 | 3054 | static inline void gen_qemu_st16r(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 3055 | { |
76db3ba4 | 3056 | if (likely(!ctx->le_mode)) { |
76db3ba4 AJ |
3057 | TCGv t0 = tcg_temp_new(); |
3058 | tcg_gen_ext16u_tl(t0, arg1); | |
fa3966a3 | 3059 | tcg_gen_bswap16_tl(t0, t0); |
76db3ba4 AJ |
3060 | tcg_gen_qemu_st16(t0, arg2, ctx->mem_idx); |
3061 | tcg_temp_free(t0); | |
76db3ba4 AJ |
3062 | } else { |
3063 | tcg_gen_qemu_st16(arg1, arg2, ctx->mem_idx); | |
3064 | } | |
b61f2753 | 3065 | } |
0c8aacd4 | 3066 | GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER); |
b61f2753 | 3067 | |
79aceca5 | 3068 | /* stwbrx */ |
86178a57 | 3069 | static inline void gen_qemu_st32r(DisasContext *ctx, TCGv arg1, TCGv arg2) |
b61f2753 | 3070 | { |
76db3ba4 | 3071 | if (likely(!ctx->le_mode)) { |
fa3966a3 AJ |
3072 | TCGv t0 = tcg_temp_new(); |
3073 | tcg_gen_ext32u_tl(t0, arg1); | |
3074 | tcg_gen_bswap32_tl(t0, t0); | |
76db3ba4 AJ |
3075 | tcg_gen_qemu_st32(t0, arg2, ctx->mem_idx); |
3076 | tcg_temp_free(t0); | |
76db3ba4 AJ |
3077 | } else { |
3078 | tcg_gen_qemu_st32(arg1, arg2, ctx->mem_idx); | |
3079 | } | |
b61f2753 | 3080 | } |
0c8aacd4 | 3081 | GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER); |
79aceca5 | 3082 | |
cd6e9320 TH |
3083 | #if defined(TARGET_PPC64) |
3084 | /* stdbrx */ | |
3085 | static inline void gen_qemu_st64r(DisasContext *ctx, TCGv arg1, TCGv arg2) | |
3086 | { | |
3087 | if (likely(!ctx->le_mode)) { | |
3088 | TCGv t0 = tcg_temp_new(); | |
3089 | tcg_gen_bswap64_tl(t0, arg1); | |
3090 | tcg_gen_qemu_st64(t0, arg2, ctx->mem_idx); | |
3091 | tcg_temp_free(t0); | |
3092 | } else { | |
3093 | tcg_gen_qemu_st64(arg1, arg2, ctx->mem_idx); | |
3094 | } | |
3095 | } | |
3096 | GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX); | |
3097 | #endif /* TARGET_PPC64 */ | |
3098 | ||
79aceca5 | 3099 | /*** Integer load and store multiple ***/ |
99e300ef | 3100 | |
54623277 | 3101 | /* lmw */ |
99e300ef | 3102 | static void gen_lmw(DisasContext *ctx) |
79aceca5 | 3103 | { |
76db3ba4 AJ |
3104 | TCGv t0; |
3105 | TCGv_i32 t1; | |
3106 | gen_set_access_type(ctx, ACCESS_INT); | |
76a66253 | 3107 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 3108 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
3109 | t0 = tcg_temp_new(); |
3110 | t1 = tcg_const_i32(rD(ctx->opcode)); | |
3111 | gen_addr_imm_index(ctx, t0, 0); | |
2f5a189c | 3112 | gen_helper_lmw(cpu_env, t0, t1); |
ff4a62cd AJ |
3113 | tcg_temp_free(t0); |
3114 | tcg_temp_free_i32(t1); | |
79aceca5 FB |
3115 | } |
3116 | ||
3117 | /* stmw */ | |
99e300ef | 3118 | static void gen_stmw(DisasContext *ctx) |
79aceca5 | 3119 | { |
76db3ba4 AJ |
3120 | TCGv t0; |
3121 | TCGv_i32 t1; | |
3122 | gen_set_access_type(ctx, ACCESS_INT); | |
76a66253 | 3123 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 3124 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
3125 | t0 = tcg_temp_new(); |
3126 | t1 = tcg_const_i32(rS(ctx->opcode)); | |
3127 | gen_addr_imm_index(ctx, t0, 0); | |
2f5a189c | 3128 | gen_helper_stmw(cpu_env, t0, t1); |
ff4a62cd AJ |
3129 | tcg_temp_free(t0); |
3130 | tcg_temp_free_i32(t1); | |
79aceca5 FB |
3131 | } |
3132 | ||
3133 | /*** Integer load and store strings ***/ | |
54623277 | 3134 | |
79aceca5 | 3135 | /* lswi */ |
3fc6c082 | 3136 | /* PowerPC32 specification says we must generate an exception if |
9a64fbe4 FB |
3137 | * rA is in the range of registers to be loaded. |
3138 | * In an other hand, IBM says this is valid, but rA won't be loaded. | |
3139 | * For now, I'll follow the spec... | |
3140 | */ | |
99e300ef | 3141 | static void gen_lswi(DisasContext *ctx) |
79aceca5 | 3142 | { |
dfbc799d AJ |
3143 | TCGv t0; |
3144 | TCGv_i32 t1, t2; | |
79aceca5 FB |
3145 | int nb = NB(ctx->opcode); |
3146 | int start = rD(ctx->opcode); | |
9a64fbe4 | 3147 | int ra = rA(ctx->opcode); |
79aceca5 FB |
3148 | int nr; |
3149 | ||
3150 | if (nb == 0) | |
3151 | nb = 32; | |
3152 | nr = nb / 4; | |
76a66253 JM |
3153 | if (unlikely(((start + nr) > 32 && |
3154 | start <= ra && (start + nr - 32) > ra) || | |
3155 | ((start + nr) <= 32 && start <= ra && (start + nr) > ra))) { | |
e06fcd75 | 3156 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX); |
9fddaa0c | 3157 | return; |
297d8e62 | 3158 | } |
76db3ba4 | 3159 | gen_set_access_type(ctx, ACCESS_INT); |
8dd4983c | 3160 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 3161 | gen_update_nip(ctx, ctx->nip - 4); |
dfbc799d | 3162 | t0 = tcg_temp_new(); |
76db3ba4 | 3163 | gen_addr_register(ctx, t0); |
dfbc799d AJ |
3164 | t1 = tcg_const_i32(nb); |
3165 | t2 = tcg_const_i32(start); | |
2f5a189c | 3166 | gen_helper_lsw(cpu_env, t0, t1, t2); |
dfbc799d AJ |
3167 | tcg_temp_free(t0); |
3168 | tcg_temp_free_i32(t1); | |
3169 | tcg_temp_free_i32(t2); | |
79aceca5 FB |
3170 | } |
3171 | ||
3172 | /* lswx */ | |
99e300ef | 3173 | static void gen_lswx(DisasContext *ctx) |
79aceca5 | 3174 | { |
76db3ba4 AJ |
3175 | TCGv t0; |
3176 | TCGv_i32 t1, t2, t3; | |
3177 | gen_set_access_type(ctx, ACCESS_INT); | |
76a66253 | 3178 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 3179 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
3180 | t0 = tcg_temp_new(); |
3181 | gen_addr_reg_index(ctx, t0); | |
3182 | t1 = tcg_const_i32(rD(ctx->opcode)); | |
3183 | t2 = tcg_const_i32(rA(ctx->opcode)); | |
3184 | t3 = tcg_const_i32(rB(ctx->opcode)); | |
2f5a189c | 3185 | gen_helper_lswx(cpu_env, t0, t1, t2, t3); |
dfbc799d AJ |
3186 | tcg_temp_free(t0); |
3187 | tcg_temp_free_i32(t1); | |
3188 | tcg_temp_free_i32(t2); | |
3189 | tcg_temp_free_i32(t3); | |
79aceca5 FB |
3190 | } |
3191 | ||
3192 | /* stswi */ | |
99e300ef | 3193 | static void gen_stswi(DisasContext *ctx) |
79aceca5 | 3194 | { |
76db3ba4 AJ |
3195 | TCGv t0; |
3196 | TCGv_i32 t1, t2; | |
4b3686fa | 3197 | int nb = NB(ctx->opcode); |
76db3ba4 | 3198 | gen_set_access_type(ctx, ACCESS_INT); |
76a66253 | 3199 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 3200 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
3201 | t0 = tcg_temp_new(); |
3202 | gen_addr_register(ctx, t0); | |
4b3686fa FB |
3203 | if (nb == 0) |
3204 | nb = 32; | |
dfbc799d | 3205 | t1 = tcg_const_i32(nb); |
76db3ba4 | 3206 | t2 = tcg_const_i32(rS(ctx->opcode)); |
2f5a189c | 3207 | gen_helper_stsw(cpu_env, t0, t1, t2); |
dfbc799d AJ |
3208 | tcg_temp_free(t0); |
3209 | tcg_temp_free_i32(t1); | |
3210 | tcg_temp_free_i32(t2); | |
79aceca5 FB |
3211 | } |
3212 | ||
3213 | /* stswx */ | |
99e300ef | 3214 | static void gen_stswx(DisasContext *ctx) |
79aceca5 | 3215 | { |
76db3ba4 AJ |
3216 | TCGv t0; |
3217 | TCGv_i32 t1, t2; | |
3218 | gen_set_access_type(ctx, ACCESS_INT); | |
8dd4983c | 3219 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5fafdf24 | 3220 | gen_update_nip(ctx, ctx->nip - 4); |
76db3ba4 AJ |
3221 | t0 = tcg_temp_new(); |
3222 | gen_addr_reg_index(ctx, t0); | |
3223 | t1 = tcg_temp_new_i32(); | |
dfbc799d AJ |
3224 | tcg_gen_trunc_tl_i32(t1, cpu_xer); |
3225 | tcg_gen_andi_i32(t1, t1, 0x7F); | |
76db3ba4 | 3226 | t2 = tcg_const_i32(rS(ctx->opcode)); |
2f5a189c | 3227 | gen_helper_stsw(cpu_env, t0, t1, t2); |
dfbc799d AJ |
3228 | tcg_temp_free(t0); |
3229 | tcg_temp_free_i32(t1); | |
3230 | tcg_temp_free_i32(t2); | |
79aceca5 FB |
3231 | } |
3232 | ||
3233 | /*** Memory synchronisation ***/ | |
3234 | /* eieio */ | |
99e300ef | 3235 | static void gen_eieio(DisasContext *ctx) |
79aceca5 | 3236 | { |
79aceca5 FB |
3237 | } |
3238 | ||
3239 | /* isync */ | |
99e300ef | 3240 | static void gen_isync(DisasContext *ctx) |
79aceca5 | 3241 | { |
e06fcd75 | 3242 | gen_stop_exception(ctx); |
79aceca5 FB |
3243 | } |
3244 | ||
5c77a786 TM |
3245 | #define LARX(name, len, loadop) \ |
3246 | static void gen_##name(DisasContext *ctx) \ | |
3247 | { \ | |
3248 | TCGv t0; \ | |
3249 | TCGv gpr = cpu_gpr[rD(ctx->opcode)]; \ | |
3250 | gen_set_access_type(ctx, ACCESS_RES); \ | |
3251 | t0 = tcg_temp_local_new(); \ | |
3252 | gen_addr_reg_index(ctx, t0); \ | |
3253 | if ((len) > 1) { \ | |
3254 | gen_check_align(ctx, t0, (len)-1); \ | |
3255 | } \ | |
3256 | gen_qemu_##loadop(ctx, gpr, t0); \ | |
3257 | tcg_gen_mov_tl(cpu_reserve, t0); \ | |
3258 | tcg_gen_st_tl(gpr, cpu_env, offsetof(CPUPPCState, reserve_val)); \ | |
3259 | tcg_temp_free(t0); \ | |
79aceca5 FB |
3260 | } |
3261 | ||
5c77a786 TM |
3262 | /* lwarx */ |
3263 | LARX(lbarx, 1, ld8u); | |
3264 | LARX(lharx, 2, ld16u); | |
3265 | LARX(lwarx, 4, ld32u); | |
3266 | ||
3267 | ||
4425265b | 3268 | #if defined(CONFIG_USER_ONLY) |
587c51f7 TM |
3269 | static void gen_conditional_store(DisasContext *ctx, TCGv EA, |
3270 | int reg, int size) | |
4425265b NF |
3271 | { |
3272 | TCGv t0 = tcg_temp_new(); | |
3273 | uint32_t save_exception = ctx->exception; | |
3274 | ||
1328c2bf | 3275 | tcg_gen_st_tl(EA, cpu_env, offsetof(CPUPPCState, reserve_ea)); |
4425265b | 3276 | tcg_gen_movi_tl(t0, (size << 5) | reg); |
1328c2bf | 3277 | tcg_gen_st_tl(t0, cpu_env, offsetof(CPUPPCState, reserve_info)); |
4425265b NF |
3278 | tcg_temp_free(t0); |
3279 | gen_update_nip(ctx, ctx->nip-4); | |
3280 | ctx->exception = POWERPC_EXCP_BRANCH; | |
3281 | gen_exception(ctx, POWERPC_EXCP_STCX); | |
3282 | ctx->exception = save_exception; | |
3283 | } | |
4425265b | 3284 | #else |
587c51f7 TM |
3285 | static void gen_conditional_store(DisasContext *ctx, TCGv EA, |
3286 | int reg, int size) | |
3287 | { | |
3288 | int l1; | |
4425265b | 3289 | |
587c51f7 TM |
3290 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so); |
3291 | l1 = gen_new_label(); | |
3292 | tcg_gen_brcond_tl(TCG_COND_NE, EA, cpu_reserve, l1); | |
3293 | tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 1 << CRF_EQ); | |
3294 | #if defined(TARGET_PPC64) | |
3295 | if (size == 8) { | |
3296 | gen_qemu_st64(ctx, cpu_gpr[reg], EA); | |
3297 | } else | |
3298 | #endif | |
3299 | if (size == 4) { | |
3300 | gen_qemu_st32(ctx, cpu_gpr[reg], EA); | |
3301 | } else if (size == 2) { | |
3302 | gen_qemu_st16(ctx, cpu_gpr[reg], EA); | |
3303 | } else { | |
3304 | gen_qemu_st8(ctx, cpu_gpr[reg], EA); | |
4425265b | 3305 | } |
587c51f7 TM |
3306 | gen_set_label(l1); |
3307 | tcg_gen_movi_tl(cpu_reserve, -1); | |
3308 | } | |
4425265b | 3309 | #endif |
587c51f7 TM |
3310 | |
3311 | #define STCX(name, len) \ | |
3312 | static void gen_##name(DisasContext *ctx) \ | |
3313 | { \ | |
3314 | TCGv t0; \ | |
3315 | gen_set_access_type(ctx, ACCESS_RES); \ | |
3316 | t0 = tcg_temp_local_new(); \ | |
3317 | gen_addr_reg_index(ctx, t0); \ | |
3318 | if (len > 1) { \ | |
3319 | gen_check_align(ctx, t0, (len)-1); \ | |
3320 | } \ | |
3321 | gen_conditional_store(ctx, t0, rS(ctx->opcode), len); \ | |
3322 | tcg_temp_free(t0); \ | |
79aceca5 FB |
3323 | } |
3324 | ||
587c51f7 TM |
3325 | STCX(stbcx_, 1); |
3326 | STCX(sthcx_, 2); | |
3327 | STCX(stwcx_, 4); | |
3328 | ||
426613db | 3329 | #if defined(TARGET_PPC64) |
426613db | 3330 | /* ldarx */ |
5c77a786 | 3331 | LARX(ldarx, 8, ld64); |
426613db JM |
3332 | |
3333 | /* stdcx. */ | |
587c51f7 | 3334 | STCX(stdcx_, 8); |
426613db JM |
3335 | #endif /* defined(TARGET_PPC64) */ |
3336 | ||
79aceca5 | 3337 | /* sync */ |
99e300ef | 3338 | static void gen_sync(DisasContext *ctx) |
79aceca5 | 3339 | { |
79aceca5 FB |
3340 | } |
3341 | ||
0db1b20e | 3342 | /* wait */ |
99e300ef | 3343 | static void gen_wait(DisasContext *ctx) |
0db1b20e | 3344 | { |
931ff272 | 3345 | TCGv_i32 t0 = tcg_temp_new_i32(); |
259186a7 AF |
3346 | tcg_gen_st_i32(t0, cpu_env, |
3347 | -offsetof(PowerPCCPU, env) + offsetof(CPUState, halted)); | |
931ff272 | 3348 | tcg_temp_free_i32(t0); |
0db1b20e | 3349 | /* Stop translation, as the CPU is supposed to sleep from now */ |
e06fcd75 | 3350 | gen_exception_err(ctx, EXCP_HLT, 1); |
0db1b20e JM |
3351 | } |
3352 | ||
79aceca5 | 3353 | /*** Floating-point load ***/ |
a0d7d5a7 | 3354 | #define GEN_LDF(name, ldop, opc, type) \ |
99e300ef | 3355 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 3356 | { \ |
a0d7d5a7 | 3357 | TCGv EA; \ |
76a66253 | 3358 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3359 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3360 | return; \ |
3361 | } \ | |
76db3ba4 | 3362 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3363 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3364 | gen_addr_imm_index(ctx, EA, 0); \ |
3365 | gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \ | |
a0d7d5a7 | 3366 | tcg_temp_free(EA); \ |
79aceca5 FB |
3367 | } |
3368 | ||
a0d7d5a7 | 3369 | #define GEN_LDUF(name, ldop, opc, type) \ |
99e300ef | 3370 | static void glue(gen_, name##u)(DisasContext *ctx) \ |
79aceca5 | 3371 | { \ |
a0d7d5a7 | 3372 | TCGv EA; \ |
76a66253 | 3373 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3374 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3375 | return; \ |
3376 | } \ | |
76a66253 | 3377 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 3378 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 3379 | return; \ |
9a64fbe4 | 3380 | } \ |
76db3ba4 | 3381 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3382 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3383 | gen_addr_imm_index(ctx, EA, 0); \ |
3384 | gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \ | |
a0d7d5a7 AJ |
3385 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
3386 | tcg_temp_free(EA); \ | |
79aceca5 FB |
3387 | } |
3388 | ||
a0d7d5a7 | 3389 | #define GEN_LDUXF(name, ldop, opc, type) \ |
99e300ef | 3390 | static void glue(gen_, name##ux)(DisasContext *ctx) \ |
79aceca5 | 3391 | { \ |
a0d7d5a7 | 3392 | TCGv EA; \ |
76a66253 | 3393 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3394 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3395 | return; \ |
3396 | } \ | |
76a66253 | 3397 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 3398 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 3399 | return; \ |
9a64fbe4 | 3400 | } \ |
76db3ba4 | 3401 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3402 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3403 | gen_addr_reg_index(ctx, EA); \ |
3404 | gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \ | |
a0d7d5a7 AJ |
3405 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
3406 | tcg_temp_free(EA); \ | |
79aceca5 FB |
3407 | } |
3408 | ||
a0d7d5a7 | 3409 | #define GEN_LDXF(name, ldop, opc2, opc3, type) \ |
99e300ef | 3410 | static void glue(gen_, name##x)(DisasContext *ctx) \ |
79aceca5 | 3411 | { \ |
a0d7d5a7 | 3412 | TCGv EA; \ |
76a66253 | 3413 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3414 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3415 | return; \ |
3416 | } \ | |
76db3ba4 | 3417 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3418 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3419 | gen_addr_reg_index(ctx, EA); \ |
3420 | gen_qemu_##ldop(ctx, cpu_fpr[rD(ctx->opcode)], EA); \ | |
a0d7d5a7 | 3421 | tcg_temp_free(EA); \ |
79aceca5 FB |
3422 | } |
3423 | ||
a0d7d5a7 AJ |
3424 | #define GEN_LDFS(name, ldop, op, type) \ |
3425 | GEN_LDF(name, ldop, op | 0x20, type); \ | |
3426 | GEN_LDUF(name, ldop, op | 0x21, type); \ | |
3427 | GEN_LDUXF(name, ldop, op | 0x01, type); \ | |
3428 | GEN_LDXF(name, ldop, 0x17, op | 0x00, type) | |
3429 | ||
636aa200 | 3430 | static inline void gen_qemu_ld32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
a0d7d5a7 AJ |
3431 | { |
3432 | TCGv t0 = tcg_temp_new(); | |
3433 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
76db3ba4 | 3434 | gen_qemu_ld32u(ctx, t0, arg2); |
a0d7d5a7 AJ |
3435 | tcg_gen_trunc_tl_i32(t1, t0); |
3436 | tcg_temp_free(t0); | |
8e703949 | 3437 | gen_helper_float32_to_float64(arg1, cpu_env, t1); |
a0d7d5a7 AJ |
3438 | tcg_temp_free_i32(t1); |
3439 | } | |
79aceca5 | 3440 | |
a0d7d5a7 AJ |
3441 | /* lfd lfdu lfdux lfdx */ |
3442 | GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT); | |
3443 | /* lfs lfsu lfsux lfsx */ | |
3444 | GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT); | |
79aceca5 | 3445 | |
05050ee8 AJ |
3446 | /* lfdp */ |
3447 | static void gen_lfdp(DisasContext *ctx) | |
3448 | { | |
3449 | TCGv EA; | |
3450 | if (unlikely(!ctx->fpu_enabled)) { | |
3451 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
3452 | return; | |
3453 | } | |
3454 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
3455 | EA = tcg_temp_new(); | |
3456 | gen_addr_imm_index(ctx, EA, 0); \ | |
3457 | if (unlikely(ctx->le_mode)) { | |
3458 | gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA); | |
3459 | tcg_gen_addi_tl(EA, EA, 8); | |
3460 | gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA); | |
3461 | } else { | |
3462 | gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA); | |
3463 | tcg_gen_addi_tl(EA, EA, 8); | |
3464 | gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA); | |
3465 | } | |
3466 | tcg_temp_free(EA); | |
3467 | } | |
3468 | ||
3469 | /* lfdpx */ | |
3470 | static void gen_lfdpx(DisasContext *ctx) | |
3471 | { | |
3472 | TCGv EA; | |
3473 | if (unlikely(!ctx->fpu_enabled)) { | |
3474 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
3475 | return; | |
3476 | } | |
3477 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
3478 | EA = tcg_temp_new(); | |
3479 | gen_addr_reg_index(ctx, EA); | |
3480 | if (unlikely(ctx->le_mode)) { | |
3481 | gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA); | |
3482 | tcg_gen_addi_tl(EA, EA, 8); | |
3483 | gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA); | |
3484 | } else { | |
3485 | gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode)], EA); | |
3486 | tcg_gen_addi_tl(EA, EA, 8); | |
3487 | gen_qemu_ld64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA); | |
3488 | } | |
3489 | tcg_temp_free(EA); | |
3490 | } | |
3491 | ||
199f830d AJ |
3492 | /* lfiwax */ |
3493 | static void gen_lfiwax(DisasContext *ctx) | |
3494 | { | |
3495 | TCGv EA; | |
3496 | TCGv t0; | |
3497 | if (unlikely(!ctx->fpu_enabled)) { | |
3498 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
3499 | return; | |
3500 | } | |
3501 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
3502 | EA = tcg_temp_new(); | |
3503 | t0 = tcg_temp_new(); | |
3504 | gen_addr_reg_index(ctx, EA); | |
909eedb7 | 3505 | gen_qemu_ld32s(ctx, t0, EA); |
199f830d | 3506 | tcg_gen_ext_tl_i64(cpu_fpr[rD(ctx->opcode)], t0); |
199f830d AJ |
3507 | tcg_temp_free(EA); |
3508 | tcg_temp_free(t0); | |
3509 | } | |
3510 | ||
79aceca5 | 3511 | /*** Floating-point store ***/ |
a0d7d5a7 | 3512 | #define GEN_STF(name, stop, opc, type) \ |
99e300ef | 3513 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 3514 | { \ |
a0d7d5a7 | 3515 | TCGv EA; \ |
76a66253 | 3516 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3517 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3518 | return; \ |
3519 | } \ | |
76db3ba4 | 3520 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3521 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3522 | gen_addr_imm_index(ctx, EA, 0); \ |
3523 | gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \ | |
a0d7d5a7 | 3524 | tcg_temp_free(EA); \ |
79aceca5 FB |
3525 | } |
3526 | ||
a0d7d5a7 | 3527 | #define GEN_STUF(name, stop, opc, type) \ |
99e300ef | 3528 | static void glue(gen_, name##u)(DisasContext *ctx) \ |
79aceca5 | 3529 | { \ |
a0d7d5a7 | 3530 | TCGv EA; \ |
76a66253 | 3531 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3532 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3533 | return; \ |
3534 | } \ | |
76a66253 | 3535 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 3536 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 3537 | return; \ |
9a64fbe4 | 3538 | } \ |
76db3ba4 | 3539 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3540 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3541 | gen_addr_imm_index(ctx, EA, 0); \ |
3542 | gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \ | |
a0d7d5a7 AJ |
3543 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
3544 | tcg_temp_free(EA); \ | |
79aceca5 FB |
3545 | } |
3546 | ||
a0d7d5a7 | 3547 | #define GEN_STUXF(name, stop, opc, type) \ |
99e300ef | 3548 | static void glue(gen_, name##ux)(DisasContext *ctx) \ |
79aceca5 | 3549 | { \ |
a0d7d5a7 | 3550 | TCGv EA; \ |
76a66253 | 3551 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3552 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3553 | return; \ |
3554 | } \ | |
76a66253 | 3555 | if (unlikely(rA(ctx->opcode) == 0)) { \ |
e06fcd75 | 3556 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); \ |
9fddaa0c | 3557 | return; \ |
9a64fbe4 | 3558 | } \ |
76db3ba4 | 3559 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3560 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3561 | gen_addr_reg_index(ctx, EA); \ |
3562 | gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \ | |
a0d7d5a7 AJ |
3563 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], EA); \ |
3564 | tcg_temp_free(EA); \ | |
79aceca5 FB |
3565 | } |
3566 | ||
a0d7d5a7 | 3567 | #define GEN_STXF(name, stop, opc2, opc3, type) \ |
99e300ef | 3568 | static void glue(gen_, name##x)(DisasContext *ctx) \ |
79aceca5 | 3569 | { \ |
a0d7d5a7 | 3570 | TCGv EA; \ |
76a66253 | 3571 | if (unlikely(!ctx->fpu_enabled)) { \ |
e06fcd75 | 3572 | gen_exception(ctx, POWERPC_EXCP_FPU); \ |
4ecc3190 FB |
3573 | return; \ |
3574 | } \ | |
76db3ba4 | 3575 | gen_set_access_type(ctx, ACCESS_FLOAT); \ |
a0d7d5a7 | 3576 | EA = tcg_temp_new(); \ |
76db3ba4 AJ |
3577 | gen_addr_reg_index(ctx, EA); \ |
3578 | gen_qemu_##stop(ctx, cpu_fpr[rS(ctx->opcode)], EA); \ | |
a0d7d5a7 | 3579 | tcg_temp_free(EA); \ |
79aceca5 FB |
3580 | } |
3581 | ||
a0d7d5a7 AJ |
3582 | #define GEN_STFS(name, stop, op, type) \ |
3583 | GEN_STF(name, stop, op | 0x20, type); \ | |
3584 | GEN_STUF(name, stop, op | 0x21, type); \ | |
3585 | GEN_STUXF(name, stop, op | 0x01, type); \ | |
3586 | GEN_STXF(name, stop, 0x17, op | 0x00, type) | |
3587 | ||
636aa200 | 3588 | static inline void gen_qemu_st32fs(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
a0d7d5a7 AJ |
3589 | { |
3590 | TCGv_i32 t0 = tcg_temp_new_i32(); | |
3591 | TCGv t1 = tcg_temp_new(); | |
8e703949 | 3592 | gen_helper_float64_to_float32(t0, cpu_env, arg1); |
a0d7d5a7 AJ |
3593 | tcg_gen_extu_i32_tl(t1, t0); |
3594 | tcg_temp_free_i32(t0); | |
76db3ba4 | 3595 | gen_qemu_st32(ctx, t1, arg2); |
a0d7d5a7 AJ |
3596 | tcg_temp_free(t1); |
3597 | } | |
79aceca5 FB |
3598 | |
3599 | /* stfd stfdu stfdux stfdx */ | |
a0d7d5a7 | 3600 | GEN_STFS(stfd, st64, 0x16, PPC_FLOAT); |
79aceca5 | 3601 | /* stfs stfsu stfsux stfsx */ |
a0d7d5a7 | 3602 | GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT); |
79aceca5 | 3603 | |
44bc0c4d AJ |
3604 | /* stfdp */ |
3605 | static void gen_stfdp(DisasContext *ctx) | |
3606 | { | |
3607 | TCGv EA; | |
3608 | if (unlikely(!ctx->fpu_enabled)) { | |
3609 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
3610 | return; | |
3611 | } | |
3612 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
3613 | EA = tcg_temp_new(); | |
3614 | gen_addr_imm_index(ctx, EA, 0); \ | |
3615 | if (unlikely(ctx->le_mode)) { | |
3616 | gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA); | |
3617 | tcg_gen_addi_tl(EA, EA, 8); | |
3618 | gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA); | |
3619 | } else { | |
3620 | gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA); | |
3621 | tcg_gen_addi_tl(EA, EA, 8); | |
3622 | gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA); | |
3623 | } | |
3624 | tcg_temp_free(EA); | |
3625 | } | |
3626 | ||
3627 | /* stfdpx */ | |
3628 | static void gen_stfdpx(DisasContext *ctx) | |
3629 | { | |
3630 | TCGv EA; | |
3631 | if (unlikely(!ctx->fpu_enabled)) { | |
3632 | gen_exception(ctx, POWERPC_EXCP_FPU); | |
3633 | return; | |
3634 | } | |
3635 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
3636 | EA = tcg_temp_new(); | |
3637 | gen_addr_reg_index(ctx, EA); | |
3638 | if (unlikely(ctx->le_mode)) { | |
3639 | gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA); | |
3640 | tcg_gen_addi_tl(EA, EA, 8); | |
3641 | gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA); | |
3642 | } else { | |
3643 | gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode)], EA); | |
3644 | tcg_gen_addi_tl(EA, EA, 8); | |
3645 | gen_qemu_st64(ctx, cpu_fpr[rD(ctx->opcode) + 1], EA); | |
3646 | } | |
3647 | tcg_temp_free(EA); | |
3648 | } | |
3649 | ||
79aceca5 | 3650 | /* Optional: */ |
636aa200 | 3651 | static inline void gen_qemu_st32fiw(DisasContext *ctx, TCGv_i64 arg1, TCGv arg2) |
a0d7d5a7 AJ |
3652 | { |
3653 | TCGv t0 = tcg_temp_new(); | |
3654 | tcg_gen_trunc_i64_tl(t0, arg1), | |
76db3ba4 | 3655 | gen_qemu_st32(ctx, t0, arg2); |
a0d7d5a7 AJ |
3656 | tcg_temp_free(t0); |
3657 | } | |
79aceca5 | 3658 | /* stfiwx */ |
a0d7d5a7 | 3659 | GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX); |
79aceca5 | 3660 | |
697ab892 DG |
3661 | static inline void gen_update_cfar(DisasContext *ctx, target_ulong nip) |
3662 | { | |
3663 | #if defined(TARGET_PPC64) | |
3664 | if (ctx->has_cfar) | |
3665 | tcg_gen_movi_tl(cpu_cfar, nip); | |
3666 | #endif | |
3667 | } | |
3668 | ||
79aceca5 | 3669 | /*** Branch ***/ |
636aa200 | 3670 | static inline void gen_goto_tb(DisasContext *ctx, int n, target_ulong dest) |
c1942362 FB |
3671 | { |
3672 | TranslationBlock *tb; | |
3673 | tb = ctx->tb; | |
e0c8f9ce | 3674 | if (NARROW_MODE(ctx)) { |
a2ffb812 | 3675 | dest = (uint32_t) dest; |
e0c8f9ce | 3676 | } |
57fec1fe | 3677 | if ((tb->pc & TARGET_PAGE_MASK) == (dest & TARGET_PAGE_MASK) && |
8cbcb4fa | 3678 | likely(!ctx->singlestep_enabled)) { |
57fec1fe | 3679 | tcg_gen_goto_tb(n); |
a2ffb812 | 3680 | tcg_gen_movi_tl(cpu_nip, dest & ~3); |
8cfd0495 | 3681 | tcg_gen_exit_tb((uintptr_t)tb + n); |
c1942362 | 3682 | } else { |
a2ffb812 | 3683 | tcg_gen_movi_tl(cpu_nip, dest & ~3); |
8cbcb4fa AJ |
3684 | if (unlikely(ctx->singlestep_enabled)) { |
3685 | if ((ctx->singlestep_enabled & | |
bdc4e053 | 3686 | (CPU_BRANCH_STEP | CPU_SINGLE_STEP)) && |
f0cc4aa8 JG |
3687 | (ctx->exception == POWERPC_EXCP_BRANCH || |
3688 | ctx->exception == POWERPC_EXCP_TRACE)) { | |
8cbcb4fa AJ |
3689 | target_ulong tmp = ctx->nip; |
3690 | ctx->nip = dest; | |
e06fcd75 | 3691 | gen_exception(ctx, POWERPC_EXCP_TRACE); |
8cbcb4fa AJ |
3692 | ctx->nip = tmp; |
3693 | } | |
3694 | if (ctx->singlestep_enabled & GDBSTUB_SINGLE_STEP) { | |
e06fcd75 | 3695 | gen_debug_exception(ctx); |
8cbcb4fa AJ |
3696 | } |
3697 | } | |
57fec1fe | 3698 | tcg_gen_exit_tb(0); |
c1942362 | 3699 | } |
c53be334 FB |
3700 | } |
3701 | ||
636aa200 | 3702 | static inline void gen_setlr(DisasContext *ctx, target_ulong nip) |
e1833e1f | 3703 | { |
e0c8f9ce RH |
3704 | if (NARROW_MODE(ctx)) { |
3705 | nip = (uint32_t)nip; | |
3706 | } | |
3707 | tcg_gen_movi_tl(cpu_lr, nip); | |
e1833e1f JM |
3708 | } |
3709 | ||
79aceca5 | 3710 | /* b ba bl bla */ |
99e300ef | 3711 | static void gen_b(DisasContext *ctx) |
79aceca5 | 3712 | { |
76a66253 | 3713 | target_ulong li, target; |
38a64f9d | 3714 | |
8cbcb4fa | 3715 | ctx->exception = POWERPC_EXCP_BRANCH; |
38a64f9d | 3716 | /* sign extend LI */ |
e0c8f9ce RH |
3717 | li = LI(ctx->opcode); |
3718 | li = (li ^ 0x02000000) - 0x02000000; | |
3719 | if (likely(AA(ctx->opcode) == 0)) { | |
046d6672 | 3720 | target = ctx->nip + li - 4; |
e0c8f9ce | 3721 | } else { |
9a64fbe4 | 3722 | target = li; |
e0c8f9ce RH |
3723 | } |
3724 | if (LK(ctx->opcode)) { | |
e1833e1f | 3725 | gen_setlr(ctx, ctx->nip); |
e0c8f9ce | 3726 | } |
697ab892 | 3727 | gen_update_cfar(ctx, ctx->nip); |
c1942362 | 3728 | gen_goto_tb(ctx, 0, target); |
79aceca5 FB |
3729 | } |
3730 | ||
e98a6e40 FB |
3731 | #define BCOND_IM 0 |
3732 | #define BCOND_LR 1 | |
3733 | #define BCOND_CTR 2 | |
3734 | ||
636aa200 | 3735 | static inline void gen_bcond(DisasContext *ctx, int type) |
d9bce9d9 | 3736 | { |
d9bce9d9 | 3737 | uint32_t bo = BO(ctx->opcode); |
05f92404 | 3738 | int l1; |
a2ffb812 | 3739 | TCGv target; |
e98a6e40 | 3740 | |
8cbcb4fa | 3741 | ctx->exception = POWERPC_EXCP_BRANCH; |
a2ffb812 | 3742 | if (type == BCOND_LR || type == BCOND_CTR) { |
a7812ae4 | 3743 | target = tcg_temp_local_new(); |
a2ffb812 AJ |
3744 | if (type == BCOND_CTR) |
3745 | tcg_gen_mov_tl(target, cpu_ctr); | |
3746 | else | |
3747 | tcg_gen_mov_tl(target, cpu_lr); | |
d2e9fd8f | 3748 | } else { |
3749 | TCGV_UNUSED(target); | |
e98a6e40 | 3750 | } |
e1833e1f JM |
3751 | if (LK(ctx->opcode)) |
3752 | gen_setlr(ctx, ctx->nip); | |
a2ffb812 AJ |
3753 | l1 = gen_new_label(); |
3754 | if ((bo & 0x4) == 0) { | |
3755 | /* Decrement and test CTR */ | |
a7812ae4 | 3756 | TCGv temp = tcg_temp_new(); |
a2ffb812 | 3757 | if (unlikely(type == BCOND_CTR)) { |
e06fcd75 | 3758 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
a2ffb812 AJ |
3759 | return; |
3760 | } | |
3761 | tcg_gen_subi_tl(cpu_ctr, cpu_ctr, 1); | |
e0c8f9ce | 3762 | if (NARROW_MODE(ctx)) { |
a2ffb812 | 3763 | tcg_gen_ext32u_tl(temp, cpu_ctr); |
e0c8f9ce | 3764 | } else { |
a2ffb812 | 3765 | tcg_gen_mov_tl(temp, cpu_ctr); |
e0c8f9ce | 3766 | } |
a2ffb812 AJ |
3767 | if (bo & 0x2) { |
3768 | tcg_gen_brcondi_tl(TCG_COND_NE, temp, 0, l1); | |
3769 | } else { | |
3770 | tcg_gen_brcondi_tl(TCG_COND_EQ, temp, 0, l1); | |
e98a6e40 | 3771 | } |
a7812ae4 | 3772 | tcg_temp_free(temp); |
a2ffb812 AJ |
3773 | } |
3774 | if ((bo & 0x10) == 0) { | |
3775 | /* Test CR */ | |
3776 | uint32_t bi = BI(ctx->opcode); | |
3777 | uint32_t mask = 1 << (3 - (bi & 0x03)); | |
a7812ae4 | 3778 | TCGv_i32 temp = tcg_temp_new_i32(); |
a2ffb812 | 3779 | |
d9bce9d9 | 3780 | if (bo & 0x8) { |
a2ffb812 AJ |
3781 | tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask); |
3782 | tcg_gen_brcondi_i32(TCG_COND_EQ, temp, 0, l1); | |
d9bce9d9 | 3783 | } else { |
a2ffb812 AJ |
3784 | tcg_gen_andi_i32(temp, cpu_crf[bi >> 2], mask); |
3785 | tcg_gen_brcondi_i32(TCG_COND_NE, temp, 0, l1); | |
d9bce9d9 | 3786 | } |
a7812ae4 | 3787 | tcg_temp_free_i32(temp); |
d9bce9d9 | 3788 | } |
697ab892 | 3789 | gen_update_cfar(ctx, ctx->nip); |
e98a6e40 | 3790 | if (type == BCOND_IM) { |
a2ffb812 AJ |
3791 | target_ulong li = (target_long)((int16_t)(BD(ctx->opcode))); |
3792 | if (likely(AA(ctx->opcode) == 0)) { | |
3793 | gen_goto_tb(ctx, 0, ctx->nip + li - 4); | |
3794 | } else { | |
3795 | gen_goto_tb(ctx, 0, li); | |
3796 | } | |
c53be334 | 3797 | gen_set_label(l1); |
c1942362 | 3798 | gen_goto_tb(ctx, 1, ctx->nip); |
e98a6e40 | 3799 | } else { |
e0c8f9ce | 3800 | if (NARROW_MODE(ctx)) { |
a2ffb812 | 3801 | tcg_gen_andi_tl(cpu_nip, target, (uint32_t)~3); |
e0c8f9ce | 3802 | } else { |
a2ffb812 | 3803 | tcg_gen_andi_tl(cpu_nip, target, ~3); |
e0c8f9ce | 3804 | } |
a2ffb812 AJ |
3805 | tcg_gen_exit_tb(0); |
3806 | gen_set_label(l1); | |
e0c8f9ce | 3807 | gen_update_nip(ctx, ctx->nip); |
57fec1fe | 3808 | tcg_gen_exit_tb(0); |
08e46e54 | 3809 | } |
e98a6e40 FB |
3810 | } |
3811 | ||
99e300ef | 3812 | static void gen_bc(DisasContext *ctx) |
3b46e624 | 3813 | { |
e98a6e40 FB |
3814 | gen_bcond(ctx, BCOND_IM); |
3815 | } | |
3816 | ||
99e300ef | 3817 | static void gen_bcctr(DisasContext *ctx) |
3b46e624 | 3818 | { |
e98a6e40 FB |
3819 | gen_bcond(ctx, BCOND_CTR); |
3820 | } | |
3821 | ||
99e300ef | 3822 | static void gen_bclr(DisasContext *ctx) |
3b46e624 | 3823 | { |
e98a6e40 FB |
3824 | gen_bcond(ctx, BCOND_LR); |
3825 | } | |
79aceca5 FB |
3826 | |
3827 | /*** Condition register logical ***/ | |
e1571908 | 3828 | #define GEN_CRLOGIC(name, tcg_op, opc) \ |
99e300ef | 3829 | static void glue(gen_, name)(DisasContext *ctx) \ |
79aceca5 | 3830 | { \ |
fc0d441e JM |
3831 | uint8_t bitmask; \ |
3832 | int sh; \ | |
a7812ae4 | 3833 | TCGv_i32 t0, t1; \ |
fc0d441e | 3834 | sh = (crbD(ctx->opcode) & 0x03) - (crbA(ctx->opcode) & 0x03); \ |
a7812ae4 | 3835 | t0 = tcg_temp_new_i32(); \ |
fc0d441e | 3836 | if (sh > 0) \ |
fea0c503 | 3837 | tcg_gen_shri_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], sh); \ |
fc0d441e | 3838 | else if (sh < 0) \ |
fea0c503 | 3839 | tcg_gen_shli_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2], -sh); \ |
e1571908 | 3840 | else \ |
fea0c503 | 3841 | tcg_gen_mov_i32(t0, cpu_crf[crbA(ctx->opcode) >> 2]); \ |
a7812ae4 | 3842 | t1 = tcg_temp_new_i32(); \ |
fc0d441e JM |
3843 | sh = (crbD(ctx->opcode) & 0x03) - (crbB(ctx->opcode) & 0x03); \ |
3844 | if (sh > 0) \ | |
fea0c503 | 3845 | tcg_gen_shri_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], sh); \ |
fc0d441e | 3846 | else if (sh < 0) \ |
fea0c503 | 3847 | tcg_gen_shli_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2], -sh); \ |
e1571908 | 3848 | else \ |
fea0c503 AJ |
3849 | tcg_gen_mov_i32(t1, cpu_crf[crbB(ctx->opcode) >> 2]); \ |
3850 | tcg_op(t0, t0, t1); \ | |
fc0d441e | 3851 | bitmask = 1 << (3 - (crbD(ctx->opcode) & 0x03)); \ |
fea0c503 AJ |
3852 | tcg_gen_andi_i32(t0, t0, bitmask); \ |
3853 | tcg_gen_andi_i32(t1, cpu_crf[crbD(ctx->opcode) >> 2], ~bitmask); \ | |
3854 | tcg_gen_or_i32(cpu_crf[crbD(ctx->opcode) >> 2], t0, t1); \ | |
a7812ae4 PB |
3855 | tcg_temp_free_i32(t0); \ |
3856 | tcg_temp_free_i32(t1); \ | |
79aceca5 FB |
3857 | } |
3858 | ||
3859 | /* crand */ | |
e1571908 | 3860 | GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08); |
79aceca5 | 3861 | /* crandc */ |
e1571908 | 3862 | GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04); |
79aceca5 | 3863 | /* creqv */ |
e1571908 | 3864 | GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09); |
79aceca5 | 3865 | /* crnand */ |
e1571908 | 3866 | GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07); |
79aceca5 | 3867 | /* crnor */ |
e1571908 | 3868 | GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01); |
79aceca5 | 3869 | /* cror */ |
e1571908 | 3870 | GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E); |
79aceca5 | 3871 | /* crorc */ |
e1571908 | 3872 | GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D); |
79aceca5 | 3873 | /* crxor */ |
e1571908 | 3874 | GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06); |
99e300ef | 3875 | |
54623277 | 3876 | /* mcrf */ |
99e300ef | 3877 | static void gen_mcrf(DisasContext *ctx) |
79aceca5 | 3878 | { |
47e4661c | 3879 | tcg_gen_mov_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfS(ctx->opcode)]); |
79aceca5 FB |
3880 | } |
3881 | ||
3882 | /*** System linkage ***/ | |
99e300ef | 3883 | |
54623277 | 3884 | /* rfi (mem_idx only) */ |
99e300ef | 3885 | static void gen_rfi(DisasContext *ctx) |
79aceca5 | 3886 | { |
9a64fbe4 | 3887 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 3888 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9a64fbe4 FB |
3889 | #else |
3890 | /* Restore CPU state */ | |
76db3ba4 | 3891 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 3892 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 3893 | return; |
9a64fbe4 | 3894 | } |
697ab892 | 3895 | gen_update_cfar(ctx, ctx->nip); |
e5f17ac6 | 3896 | gen_helper_rfi(cpu_env); |
e06fcd75 | 3897 | gen_sync_exception(ctx); |
9a64fbe4 | 3898 | #endif |
79aceca5 FB |
3899 | } |
3900 | ||
426613db | 3901 | #if defined(TARGET_PPC64) |
99e300ef | 3902 | static void gen_rfid(DisasContext *ctx) |
426613db JM |
3903 | { |
3904 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 3905 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db JM |
3906 | #else |
3907 | /* Restore CPU state */ | |
76db3ba4 | 3908 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 3909 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db JM |
3910 | return; |
3911 | } | |
697ab892 | 3912 | gen_update_cfar(ctx, ctx->nip); |
e5f17ac6 | 3913 | gen_helper_rfid(cpu_env); |
e06fcd75 | 3914 | gen_sync_exception(ctx); |
426613db JM |
3915 | #endif |
3916 | } | |
426613db | 3917 | |
99e300ef | 3918 | static void gen_hrfid(DisasContext *ctx) |
be147d08 JM |
3919 | { |
3920 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 3921 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
3922 | #else |
3923 | /* Restore CPU state */ | |
76db3ba4 | 3924 | if (unlikely(ctx->mem_idx <= 1)) { |
e06fcd75 | 3925 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
be147d08 JM |
3926 | return; |
3927 | } | |
e5f17ac6 | 3928 | gen_helper_hrfid(cpu_env); |
e06fcd75 | 3929 | gen_sync_exception(ctx); |
be147d08 JM |
3930 | #endif |
3931 | } | |
3932 | #endif | |
3933 | ||
79aceca5 | 3934 | /* sc */ |
417bf010 JM |
3935 | #if defined(CONFIG_USER_ONLY) |
3936 | #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL_USER | |
3937 | #else | |
3938 | #define POWERPC_SYSCALL POWERPC_EXCP_SYSCALL | |
3939 | #endif | |
99e300ef | 3940 | static void gen_sc(DisasContext *ctx) |
79aceca5 | 3941 | { |
e1833e1f JM |
3942 | uint32_t lev; |
3943 | ||
3944 | lev = (ctx->opcode >> 5) & 0x7F; | |
e06fcd75 | 3945 | gen_exception_err(ctx, POWERPC_SYSCALL, lev); |
79aceca5 FB |
3946 | } |
3947 | ||
3948 | /*** Trap ***/ | |
99e300ef | 3949 | |
54623277 | 3950 | /* tw */ |
99e300ef | 3951 | static void gen_tw(DisasContext *ctx) |
79aceca5 | 3952 | { |
cab3bee2 | 3953 | TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode)); |
db9a231d AJ |
3954 | /* Update the nip since this might generate a trap exception */ |
3955 | gen_update_nip(ctx, ctx->nip); | |
e5f17ac6 BS |
3956 | gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], |
3957 | t0); | |
cab3bee2 | 3958 | tcg_temp_free_i32(t0); |
79aceca5 FB |
3959 | } |
3960 | ||
3961 | /* twi */ | |
99e300ef | 3962 | static void gen_twi(DisasContext *ctx) |
79aceca5 | 3963 | { |
cab3bee2 AJ |
3964 | TCGv t0 = tcg_const_tl(SIMM(ctx->opcode)); |
3965 | TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode)); | |
db9a231d AJ |
3966 | /* Update the nip since this might generate a trap exception */ |
3967 | gen_update_nip(ctx, ctx->nip); | |
e5f17ac6 | 3968 | gen_helper_tw(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1); |
cab3bee2 AJ |
3969 | tcg_temp_free(t0); |
3970 | tcg_temp_free_i32(t1); | |
79aceca5 FB |
3971 | } |
3972 | ||
d9bce9d9 JM |
3973 | #if defined(TARGET_PPC64) |
3974 | /* td */ | |
99e300ef | 3975 | static void gen_td(DisasContext *ctx) |
d9bce9d9 | 3976 | { |
cab3bee2 | 3977 | TCGv_i32 t0 = tcg_const_i32(TO(ctx->opcode)); |
db9a231d AJ |
3978 | /* Update the nip since this might generate a trap exception */ |
3979 | gen_update_nip(ctx, ctx->nip); | |
e5f17ac6 BS |
3980 | gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], |
3981 | t0); | |
cab3bee2 | 3982 | tcg_temp_free_i32(t0); |
d9bce9d9 JM |
3983 | } |
3984 | ||
3985 | /* tdi */ | |
99e300ef | 3986 | static void gen_tdi(DisasContext *ctx) |
d9bce9d9 | 3987 | { |
cab3bee2 AJ |
3988 | TCGv t0 = tcg_const_tl(SIMM(ctx->opcode)); |
3989 | TCGv_i32 t1 = tcg_const_i32(TO(ctx->opcode)); | |
db9a231d AJ |
3990 | /* Update the nip since this might generate a trap exception */ |
3991 | gen_update_nip(ctx, ctx->nip); | |
e5f17ac6 | 3992 | gen_helper_td(cpu_env, cpu_gpr[rA(ctx->opcode)], t0, t1); |
cab3bee2 AJ |
3993 | tcg_temp_free(t0); |
3994 | tcg_temp_free_i32(t1); | |
d9bce9d9 JM |
3995 | } |
3996 | #endif | |
3997 | ||
79aceca5 | 3998 | /*** Processor control ***/ |
99e300ef | 3999 | |
da91a00f RH |
4000 | static void gen_read_xer(TCGv dst) |
4001 | { | |
4002 | TCGv t0 = tcg_temp_new(); | |
4003 | TCGv t1 = tcg_temp_new(); | |
4004 | TCGv t2 = tcg_temp_new(); | |
4005 | tcg_gen_mov_tl(dst, cpu_xer); | |
4006 | tcg_gen_shli_tl(t0, cpu_so, XER_SO); | |
4007 | tcg_gen_shli_tl(t1, cpu_ov, XER_OV); | |
4008 | tcg_gen_shli_tl(t2, cpu_ca, XER_CA); | |
4009 | tcg_gen_or_tl(t0, t0, t1); | |
4010 | tcg_gen_or_tl(dst, dst, t2); | |
4011 | tcg_gen_or_tl(dst, dst, t0); | |
4012 | tcg_temp_free(t0); | |
4013 | tcg_temp_free(t1); | |
4014 | tcg_temp_free(t2); | |
4015 | } | |
4016 | ||
4017 | static void gen_write_xer(TCGv src) | |
4018 | { | |
4019 | tcg_gen_andi_tl(cpu_xer, src, | |
4020 | ~((1u << XER_SO) | (1u << XER_OV) | (1u << XER_CA))); | |
4021 | tcg_gen_shri_tl(cpu_so, src, XER_SO); | |
4022 | tcg_gen_shri_tl(cpu_ov, src, XER_OV); | |
4023 | tcg_gen_shri_tl(cpu_ca, src, XER_CA); | |
4024 | tcg_gen_andi_tl(cpu_so, cpu_so, 1); | |
4025 | tcg_gen_andi_tl(cpu_ov, cpu_ov, 1); | |
4026 | tcg_gen_andi_tl(cpu_ca, cpu_ca, 1); | |
4027 | } | |
4028 | ||
54623277 | 4029 | /* mcrxr */ |
99e300ef | 4030 | static void gen_mcrxr(DisasContext *ctx) |
79aceca5 | 4031 | { |
da91a00f RH |
4032 | TCGv_i32 t0 = tcg_temp_new_i32(); |
4033 | TCGv_i32 t1 = tcg_temp_new_i32(); | |
4034 | TCGv_i32 dst = cpu_crf[crfD(ctx->opcode)]; | |
4035 | ||
4036 | tcg_gen_trunc_tl_i32(t0, cpu_so); | |
4037 | tcg_gen_trunc_tl_i32(t1, cpu_ov); | |
4038 | tcg_gen_trunc_tl_i32(dst, cpu_ca); | |
4039 | tcg_gen_shri_i32(t0, t0, 2); | |
4040 | tcg_gen_shri_i32(t1, t1, 1); | |
4041 | tcg_gen_or_i32(dst, dst, t0); | |
4042 | tcg_gen_or_i32(dst, dst, t1); | |
4043 | tcg_temp_free_i32(t0); | |
4044 | tcg_temp_free_i32(t1); | |
4045 | ||
4046 | tcg_gen_movi_tl(cpu_so, 0); | |
4047 | tcg_gen_movi_tl(cpu_ov, 0); | |
4048 | tcg_gen_movi_tl(cpu_ca, 0); | |
79aceca5 FB |
4049 | } |
4050 | ||
0cfe11ea | 4051 | /* mfcr mfocrf */ |
99e300ef | 4052 | static void gen_mfcr(DisasContext *ctx) |
79aceca5 | 4053 | { |
76a66253 | 4054 | uint32_t crm, crn; |
3b46e624 | 4055 | |
76a66253 JM |
4056 | if (likely(ctx->opcode & 0x00100000)) { |
4057 | crm = CRM(ctx->opcode); | |
8dd640e4 | 4058 | if (likely(crm && ((crm & (crm - 1)) == 0))) { |
0cfe11ea | 4059 | crn = ctz32 (crm); |
e1571908 | 4060 | tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], cpu_crf[7 - crn]); |
0497d2f4 AJ |
4061 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], |
4062 | cpu_gpr[rD(ctx->opcode)], crn * 4); | |
76a66253 | 4063 | } |
d9bce9d9 | 4064 | } else { |
651721b2 AJ |
4065 | TCGv_i32 t0 = tcg_temp_new_i32(); |
4066 | tcg_gen_mov_i32(t0, cpu_crf[0]); | |
4067 | tcg_gen_shli_i32(t0, t0, 4); | |
4068 | tcg_gen_or_i32(t0, t0, cpu_crf[1]); | |
4069 | tcg_gen_shli_i32(t0, t0, 4); | |
4070 | tcg_gen_or_i32(t0, t0, cpu_crf[2]); | |
4071 | tcg_gen_shli_i32(t0, t0, 4); | |
4072 | tcg_gen_or_i32(t0, t0, cpu_crf[3]); | |
4073 | tcg_gen_shli_i32(t0, t0, 4); | |
4074 | tcg_gen_or_i32(t0, t0, cpu_crf[4]); | |
4075 | tcg_gen_shli_i32(t0, t0, 4); | |
4076 | tcg_gen_or_i32(t0, t0, cpu_crf[5]); | |
4077 | tcg_gen_shli_i32(t0, t0, 4); | |
4078 | tcg_gen_or_i32(t0, t0, cpu_crf[6]); | |
4079 | tcg_gen_shli_i32(t0, t0, 4); | |
4080 | tcg_gen_or_i32(t0, t0, cpu_crf[7]); | |
4081 | tcg_gen_extu_i32_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
4082 | tcg_temp_free_i32(t0); | |
d9bce9d9 | 4083 | } |
79aceca5 FB |
4084 | } |
4085 | ||
4086 | /* mfmsr */ | |
99e300ef | 4087 | static void gen_mfmsr(DisasContext *ctx) |
79aceca5 | 4088 | { |
9a64fbe4 | 4089 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4090 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4091 | #else |
76db3ba4 | 4092 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4093 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4094 | return; |
9a64fbe4 | 4095 | } |
6527f6ea | 4096 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_msr); |
9a64fbe4 | 4097 | #endif |
79aceca5 FB |
4098 | } |
4099 | ||
7b13448f | 4100 | static void spr_noaccess(void *opaque, int gprn, int sprn) |
3fc6c082 | 4101 | { |
7b13448f | 4102 | #if 0 |
3fc6c082 FB |
4103 | sprn = ((sprn >> 5) & 0x1F) | ((sprn & 0x1F) << 5); |
4104 | printf("ERROR: try to access SPR %d !\n", sprn); | |
7b13448f | 4105 | #endif |
3fc6c082 FB |
4106 | } |
4107 | #define SPR_NOACCESS (&spr_noaccess) | |
3fc6c082 | 4108 | |
79aceca5 | 4109 | /* mfspr */ |
636aa200 | 4110 | static inline void gen_op_mfspr(DisasContext *ctx) |
79aceca5 | 4111 | { |
45d827d2 | 4112 | void (*read_cb)(void *opaque, int gprn, int sprn); |
79aceca5 FB |
4113 | uint32_t sprn = SPR(ctx->opcode); |
4114 | ||
3fc6c082 | 4115 | #if !defined(CONFIG_USER_ONLY) |
76db3ba4 | 4116 | if (ctx->mem_idx == 2) |
be147d08 | 4117 | read_cb = ctx->spr_cb[sprn].hea_read; |
76db3ba4 | 4118 | else if (ctx->mem_idx) |
3fc6c082 FB |
4119 | read_cb = ctx->spr_cb[sprn].oea_read; |
4120 | else | |
9a64fbe4 | 4121 | #endif |
3fc6c082 | 4122 | read_cb = ctx->spr_cb[sprn].uea_read; |
76a66253 JM |
4123 | if (likely(read_cb != NULL)) { |
4124 | if (likely(read_cb != SPR_NOACCESS)) { | |
45d827d2 | 4125 | (*read_cb)(ctx, rD(ctx->opcode), sprn); |
3fc6c082 FB |
4126 | } else { |
4127 | /* Privilege exception */ | |
9fceefa7 JM |
4128 | /* This is a hack to avoid warnings when running Linux: |
4129 | * this OS breaks the PowerPC virtualisation model, | |
4130 | * allowing userland application to read the PVR | |
4131 | */ | |
4132 | if (sprn != SPR_PVR) { | |
c05541ee AB |
4133 | qemu_log("Trying to read privileged spr %d (0x%03x) at " |
4134 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4); | |
4135 | printf("Trying to read privileged spr %d (0x%03x) at " | |
4136 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4); | |
f24e5695 | 4137 | } |
e06fcd75 | 4138 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
79aceca5 | 4139 | } |
3fc6c082 FB |
4140 | } else { |
4141 | /* Not defined */ | |
c05541ee AB |
4142 | qemu_log("Trying to read invalid spr %d (0x%03x) at " |
4143 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4); | |
4144 | printf("Trying to read invalid spr %d (0x%03x) at " | |
4145 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4); | |
e06fcd75 | 4146 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR); |
79aceca5 | 4147 | } |
79aceca5 FB |
4148 | } |
4149 | ||
99e300ef | 4150 | static void gen_mfspr(DisasContext *ctx) |
79aceca5 | 4151 | { |
3fc6c082 | 4152 | gen_op_mfspr(ctx); |
76a66253 | 4153 | } |
3fc6c082 FB |
4154 | |
4155 | /* mftb */ | |
99e300ef | 4156 | static void gen_mftb(DisasContext *ctx) |
3fc6c082 FB |
4157 | { |
4158 | gen_op_mfspr(ctx); | |
79aceca5 FB |
4159 | } |
4160 | ||
0cfe11ea | 4161 | /* mtcrf mtocrf*/ |
99e300ef | 4162 | static void gen_mtcrf(DisasContext *ctx) |
79aceca5 | 4163 | { |
76a66253 | 4164 | uint32_t crm, crn; |
3b46e624 | 4165 | |
76a66253 | 4166 | crm = CRM(ctx->opcode); |
8dd640e4 | 4167 | if (likely((ctx->opcode & 0x00100000))) { |
4168 | if (crm && ((crm & (crm - 1)) == 0)) { | |
4169 | TCGv_i32 temp = tcg_temp_new_i32(); | |
0cfe11ea | 4170 | crn = ctz32 (crm); |
8dd640e4 | 4171 | tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]); |
0cfe11ea AJ |
4172 | tcg_gen_shri_i32(temp, temp, crn * 4); |
4173 | tcg_gen_andi_i32(cpu_crf[7 - crn], temp, 0xf); | |
8dd640e4 | 4174 | tcg_temp_free_i32(temp); |
4175 | } | |
76a66253 | 4176 | } else { |
651721b2 AJ |
4177 | TCGv_i32 temp = tcg_temp_new_i32(); |
4178 | tcg_gen_trunc_tl_i32(temp, cpu_gpr[rS(ctx->opcode)]); | |
4179 | for (crn = 0 ; crn < 8 ; crn++) { | |
4180 | if (crm & (1 << crn)) { | |
4181 | tcg_gen_shri_i32(cpu_crf[7 - crn], temp, crn * 4); | |
4182 | tcg_gen_andi_i32(cpu_crf[7 - crn], cpu_crf[7 - crn], 0xf); | |
4183 | } | |
4184 | } | |
a7812ae4 | 4185 | tcg_temp_free_i32(temp); |
76a66253 | 4186 | } |
79aceca5 FB |
4187 | } |
4188 | ||
4189 | /* mtmsr */ | |
426613db | 4190 | #if defined(TARGET_PPC64) |
99e300ef | 4191 | static void gen_mtmsrd(DisasContext *ctx) |
426613db JM |
4192 | { |
4193 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4194 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
426613db | 4195 | #else |
76db3ba4 | 4196 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4197 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
426613db JM |
4198 | return; |
4199 | } | |
be147d08 JM |
4200 | if (ctx->opcode & 0x00010000) { |
4201 | /* Special form that does not need any synchronisation */ | |
6527f6ea AJ |
4202 | TCGv t0 = tcg_temp_new(); |
4203 | tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE)); | |
4204 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE))); | |
4205 | tcg_gen_or_tl(cpu_msr, cpu_msr, t0); | |
4206 | tcg_temp_free(t0); | |
be147d08 | 4207 | } else { |
056b05f8 JM |
4208 | /* XXX: we need to update nip before the store |
4209 | * if we enter power saving mode, we will exit the loop | |
4210 | * directly from ppc_store_msr | |
4211 | */ | |
be147d08 | 4212 | gen_update_nip(ctx, ctx->nip); |
e5f17ac6 | 4213 | gen_helper_store_msr(cpu_env, cpu_gpr[rS(ctx->opcode)]); |
be147d08 JM |
4214 | /* Must stop the translation as machine state (may have) changed */ |
4215 | /* Note that mtmsr is not always defined as context-synchronizing */ | |
e06fcd75 | 4216 | gen_stop_exception(ctx); |
be147d08 | 4217 | } |
426613db JM |
4218 | #endif |
4219 | } | |
4220 | #endif | |
4221 | ||
99e300ef | 4222 | static void gen_mtmsr(DisasContext *ctx) |
79aceca5 | 4223 | { |
9a64fbe4 | 4224 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4225 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4226 | #else |
76db3ba4 | 4227 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4228 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4229 | return; |
9a64fbe4 | 4230 | } |
be147d08 JM |
4231 | if (ctx->opcode & 0x00010000) { |
4232 | /* Special form that does not need any synchronisation */ | |
6527f6ea AJ |
4233 | TCGv t0 = tcg_temp_new(); |
4234 | tcg_gen_andi_tl(t0, cpu_gpr[rS(ctx->opcode)], (1 << MSR_RI) | (1 << MSR_EE)); | |
4235 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~((1 << MSR_RI) | (1 << MSR_EE))); | |
4236 | tcg_gen_or_tl(cpu_msr, cpu_msr, t0); | |
4237 | tcg_temp_free(t0); | |
be147d08 | 4238 | } else { |
8018dc63 AG |
4239 | TCGv msr = tcg_temp_new(); |
4240 | ||
056b05f8 JM |
4241 | /* XXX: we need to update nip before the store |
4242 | * if we enter power saving mode, we will exit the loop | |
4243 | * directly from ppc_store_msr | |
4244 | */ | |
be147d08 | 4245 | gen_update_nip(ctx, ctx->nip); |
d9bce9d9 | 4246 | #if defined(TARGET_PPC64) |
8018dc63 AG |
4247 | tcg_gen_deposit_tl(msr, cpu_msr, cpu_gpr[rS(ctx->opcode)], 0, 32); |
4248 | #else | |
4249 | tcg_gen_mov_tl(msr, cpu_gpr[rS(ctx->opcode)]); | |
d9bce9d9 | 4250 | #endif |
e5f17ac6 | 4251 | gen_helper_store_msr(cpu_env, msr); |
be147d08 | 4252 | /* Must stop the translation as machine state (may have) changed */ |
6527f6ea | 4253 | /* Note that mtmsr is not always defined as context-synchronizing */ |
e06fcd75 | 4254 | gen_stop_exception(ctx); |
be147d08 | 4255 | } |
9a64fbe4 | 4256 | #endif |
79aceca5 FB |
4257 | } |
4258 | ||
4259 | /* mtspr */ | |
99e300ef | 4260 | static void gen_mtspr(DisasContext *ctx) |
79aceca5 | 4261 | { |
45d827d2 | 4262 | void (*write_cb)(void *opaque, int sprn, int gprn); |
79aceca5 FB |
4263 | uint32_t sprn = SPR(ctx->opcode); |
4264 | ||
3fc6c082 | 4265 | #if !defined(CONFIG_USER_ONLY) |
76db3ba4 | 4266 | if (ctx->mem_idx == 2) |
be147d08 | 4267 | write_cb = ctx->spr_cb[sprn].hea_write; |
76db3ba4 | 4268 | else if (ctx->mem_idx) |
3fc6c082 FB |
4269 | write_cb = ctx->spr_cb[sprn].oea_write; |
4270 | else | |
9a64fbe4 | 4271 | #endif |
3fc6c082 | 4272 | write_cb = ctx->spr_cb[sprn].uea_write; |
76a66253 JM |
4273 | if (likely(write_cb != NULL)) { |
4274 | if (likely(write_cb != SPR_NOACCESS)) { | |
45d827d2 | 4275 | (*write_cb)(ctx, sprn, rS(ctx->opcode)); |
3fc6c082 FB |
4276 | } else { |
4277 | /* Privilege exception */ | |
c05541ee AB |
4278 | qemu_log("Trying to write privileged spr %d (0x%03x) at " |
4279 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4); | |
4280 | printf("Trying to write privileged spr %d (0x%03x) at " | |
4281 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4); | |
e06fcd75 | 4282 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 | 4283 | } |
3fc6c082 FB |
4284 | } else { |
4285 | /* Not defined */ | |
c05541ee AB |
4286 | qemu_log("Trying to write invalid spr %d (0x%03x) at " |
4287 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4); | |
4288 | printf("Trying to write invalid spr %d (0x%03x) at " | |
4289 | TARGET_FMT_lx "\n", sprn, sprn, ctx->nip - 4); | |
e06fcd75 | 4290 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_SPR); |
79aceca5 | 4291 | } |
79aceca5 FB |
4292 | } |
4293 | ||
4294 | /*** Cache management ***/ | |
99e300ef | 4295 | |
54623277 | 4296 | /* dcbf */ |
99e300ef | 4297 | static void gen_dcbf(DisasContext *ctx) |
79aceca5 | 4298 | { |
dac454af | 4299 | /* XXX: specification says this is treated as a load by the MMU */ |
76db3ba4 AJ |
4300 | TCGv t0; |
4301 | gen_set_access_type(ctx, ACCESS_CACHE); | |
4302 | t0 = tcg_temp_new(); | |
4303 | gen_addr_reg_index(ctx, t0); | |
4304 | gen_qemu_ld8u(ctx, t0, t0); | |
fea0c503 | 4305 | tcg_temp_free(t0); |
79aceca5 FB |
4306 | } |
4307 | ||
4308 | /* dcbi (Supervisor only) */ | |
99e300ef | 4309 | static void gen_dcbi(DisasContext *ctx) |
79aceca5 | 4310 | { |
a541f297 | 4311 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4312 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a541f297 | 4313 | #else |
b61f2753 | 4314 | TCGv EA, val; |
76db3ba4 | 4315 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4316 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 4317 | return; |
9a64fbe4 | 4318 | } |
a7812ae4 | 4319 | EA = tcg_temp_new(); |
76db3ba4 AJ |
4320 | gen_set_access_type(ctx, ACCESS_CACHE); |
4321 | gen_addr_reg_index(ctx, EA); | |
a7812ae4 | 4322 | val = tcg_temp_new(); |
76a66253 | 4323 | /* XXX: specification says this should be treated as a store by the MMU */ |
76db3ba4 AJ |
4324 | gen_qemu_ld8u(ctx, val, EA); |
4325 | gen_qemu_st8(ctx, val, EA); | |
b61f2753 AJ |
4326 | tcg_temp_free(val); |
4327 | tcg_temp_free(EA); | |
a541f297 | 4328 | #endif |
79aceca5 FB |
4329 | } |
4330 | ||
4331 | /* dcdst */ | |
99e300ef | 4332 | static void gen_dcbst(DisasContext *ctx) |
79aceca5 | 4333 | { |
76a66253 | 4334 | /* XXX: specification say this is treated as a load by the MMU */ |
76db3ba4 AJ |
4335 | TCGv t0; |
4336 | gen_set_access_type(ctx, ACCESS_CACHE); | |
4337 | t0 = tcg_temp_new(); | |
4338 | gen_addr_reg_index(ctx, t0); | |
4339 | gen_qemu_ld8u(ctx, t0, t0); | |
fea0c503 | 4340 | tcg_temp_free(t0); |
79aceca5 FB |
4341 | } |
4342 | ||
4343 | /* dcbt */ | |
99e300ef | 4344 | static void gen_dcbt(DisasContext *ctx) |
79aceca5 | 4345 | { |
0db1b20e | 4346 | /* interpreted as no-op */ |
76a66253 JM |
4347 | /* XXX: specification say this is treated as a load by the MMU |
4348 | * but does not generate any exception | |
4349 | */ | |
79aceca5 FB |
4350 | } |
4351 | ||
4352 | /* dcbtst */ | |
99e300ef | 4353 | static void gen_dcbtst(DisasContext *ctx) |
79aceca5 | 4354 | { |
0db1b20e | 4355 | /* interpreted as no-op */ |
76a66253 JM |
4356 | /* XXX: specification say this is treated as a load by the MMU |
4357 | * but does not generate any exception | |
4358 | */ | |
79aceca5 FB |
4359 | } |
4360 | ||
4361 | /* dcbz */ | |
99e300ef | 4362 | static void gen_dcbz(DisasContext *ctx) |
79aceca5 | 4363 | { |
8e33944f AG |
4364 | TCGv tcgv_addr; |
4365 | TCGv_i32 tcgv_is_dcbzl; | |
4366 | int is_dcbzl = ctx->opcode & 0x00200000 ? 1 : 0; | |
d63001d1 | 4367 | |
76db3ba4 | 4368 | gen_set_access_type(ctx, ACCESS_CACHE); |
799a8c8d AJ |
4369 | /* NIP cannot be restored if the memory exception comes from an helper */ |
4370 | gen_update_nip(ctx, ctx->nip - 4); | |
8e33944f AG |
4371 | tcgv_addr = tcg_temp_new(); |
4372 | tcgv_is_dcbzl = tcg_const_i32(is_dcbzl); | |
4373 | ||
4374 | gen_addr_reg_index(ctx, tcgv_addr); | |
4375 | gen_helper_dcbz(cpu_env, tcgv_addr, tcgv_is_dcbzl); | |
4376 | ||
4377 | tcg_temp_free(tcgv_addr); | |
4378 | tcg_temp_free_i32(tcgv_is_dcbzl); | |
79aceca5 FB |
4379 | } |
4380 | ||
ae1c1a3d | 4381 | /* dst / dstt */ |
99e300ef | 4382 | static void gen_dst(DisasContext *ctx) |
ae1c1a3d AJ |
4383 | { |
4384 | if (rA(ctx->opcode) == 0) { | |
4385 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX); | |
4386 | } else { | |
4387 | /* interpreted as no-op */ | |
4388 | } | |
4389 | } | |
4390 | ||
4391 | /* dstst /dststt */ | |
99e300ef | 4392 | static void gen_dstst(DisasContext *ctx) |
ae1c1a3d AJ |
4393 | { |
4394 | if (rA(ctx->opcode) == 0) { | |
4395 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_LSWX); | |
4396 | } else { | |
4397 | /* interpreted as no-op */ | |
4398 | } | |
4399 | ||
4400 | } | |
4401 | ||
4402 | /* dss / dssall */ | |
99e300ef | 4403 | static void gen_dss(DisasContext *ctx) |
ae1c1a3d AJ |
4404 | { |
4405 | /* interpreted as no-op */ | |
4406 | } | |
4407 | ||
79aceca5 | 4408 | /* icbi */ |
99e300ef | 4409 | static void gen_icbi(DisasContext *ctx) |
79aceca5 | 4410 | { |
76db3ba4 AJ |
4411 | TCGv t0; |
4412 | gen_set_access_type(ctx, ACCESS_CACHE); | |
30032c94 JM |
4413 | /* NIP cannot be restored if the memory exception comes from an helper */ |
4414 | gen_update_nip(ctx, ctx->nip - 4); | |
76db3ba4 AJ |
4415 | t0 = tcg_temp_new(); |
4416 | gen_addr_reg_index(ctx, t0); | |
2f5a189c | 4417 | gen_helper_icbi(cpu_env, t0); |
37d269df | 4418 | tcg_temp_free(t0); |
79aceca5 FB |
4419 | } |
4420 | ||
4421 | /* Optional: */ | |
4422 | /* dcba */ | |
99e300ef | 4423 | static void gen_dcba(DisasContext *ctx) |
79aceca5 | 4424 | { |
0db1b20e JM |
4425 | /* interpreted as no-op */ |
4426 | /* XXX: specification say this is treated as a store by the MMU | |
4427 | * but does not generate any exception | |
4428 | */ | |
79aceca5 FB |
4429 | } |
4430 | ||
4431 | /*** Segment register manipulation ***/ | |
4432 | /* Supervisor only: */ | |
99e300ef | 4433 | |
54623277 | 4434 | /* mfsr */ |
99e300ef | 4435 | static void gen_mfsr(DisasContext *ctx) |
79aceca5 | 4436 | { |
9a64fbe4 | 4437 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4438 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4439 | #else |
74d37793 | 4440 | TCGv t0; |
76db3ba4 | 4441 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4442 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4443 | return; |
9a64fbe4 | 4444 | } |
74d37793 | 4445 | t0 = tcg_const_tl(SR(ctx->opcode)); |
c6c7cf05 | 4446 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 | 4447 | tcg_temp_free(t0); |
9a64fbe4 | 4448 | #endif |
79aceca5 FB |
4449 | } |
4450 | ||
4451 | /* mfsrin */ | |
99e300ef | 4452 | static void gen_mfsrin(DisasContext *ctx) |
79aceca5 | 4453 | { |
9a64fbe4 | 4454 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4455 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4456 | #else |
74d37793 | 4457 | TCGv t0; |
76db3ba4 | 4458 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4459 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4460 | return; |
9a64fbe4 | 4461 | } |
74d37793 AJ |
4462 | t0 = tcg_temp_new(); |
4463 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28); | |
4464 | tcg_gen_andi_tl(t0, t0, 0xF); | |
c6c7cf05 | 4465 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 | 4466 | tcg_temp_free(t0); |
9a64fbe4 | 4467 | #endif |
79aceca5 FB |
4468 | } |
4469 | ||
4470 | /* mtsr */ | |
99e300ef | 4471 | static void gen_mtsr(DisasContext *ctx) |
79aceca5 | 4472 | { |
9a64fbe4 | 4473 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4474 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4475 | #else |
74d37793 | 4476 | TCGv t0; |
76db3ba4 | 4477 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4478 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4479 | return; |
9a64fbe4 | 4480 | } |
74d37793 | 4481 | t0 = tcg_const_tl(SR(ctx->opcode)); |
c6c7cf05 | 4482 | gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]); |
74d37793 | 4483 | tcg_temp_free(t0); |
9a64fbe4 | 4484 | #endif |
79aceca5 FB |
4485 | } |
4486 | ||
4487 | /* mtsrin */ | |
99e300ef | 4488 | static void gen_mtsrin(DisasContext *ctx) |
79aceca5 | 4489 | { |
9a64fbe4 | 4490 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4491 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9a64fbe4 | 4492 | #else |
74d37793 | 4493 | TCGv t0; |
76db3ba4 | 4494 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4495 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
9fddaa0c | 4496 | return; |
9a64fbe4 | 4497 | } |
74d37793 AJ |
4498 | t0 = tcg_temp_new(); |
4499 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28); | |
4500 | tcg_gen_andi_tl(t0, t0, 0xF); | |
c6c7cf05 | 4501 | gen_helper_store_sr(cpu_env, t0, cpu_gpr[rD(ctx->opcode)]); |
74d37793 | 4502 | tcg_temp_free(t0); |
9a64fbe4 | 4503 | #endif |
79aceca5 FB |
4504 | } |
4505 | ||
12de9a39 JM |
4506 | #if defined(TARGET_PPC64) |
4507 | /* Specific implementation for PowerPC 64 "bridge" emulation using SLB */ | |
e8eaa2c0 | 4508 | |
54623277 | 4509 | /* mfsr */ |
e8eaa2c0 | 4510 | static void gen_mfsr_64b(DisasContext *ctx) |
12de9a39 JM |
4511 | { |
4512 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4513 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 | 4514 | #else |
74d37793 | 4515 | TCGv t0; |
76db3ba4 | 4516 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4517 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 JM |
4518 | return; |
4519 | } | |
74d37793 | 4520 | t0 = tcg_const_tl(SR(ctx->opcode)); |
c6c7cf05 | 4521 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 | 4522 | tcg_temp_free(t0); |
12de9a39 JM |
4523 | #endif |
4524 | } | |
4525 | ||
4526 | /* mfsrin */ | |
e8eaa2c0 | 4527 | static void gen_mfsrin_64b(DisasContext *ctx) |
12de9a39 JM |
4528 | { |
4529 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4530 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 | 4531 | #else |
74d37793 | 4532 | TCGv t0; |
76db3ba4 | 4533 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4534 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 JM |
4535 | return; |
4536 | } | |
74d37793 AJ |
4537 | t0 = tcg_temp_new(); |
4538 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28); | |
4539 | tcg_gen_andi_tl(t0, t0, 0xF); | |
c6c7cf05 | 4540 | gen_helper_load_sr(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 | 4541 | tcg_temp_free(t0); |
12de9a39 JM |
4542 | #endif |
4543 | } | |
4544 | ||
4545 | /* mtsr */ | |
e8eaa2c0 | 4546 | static void gen_mtsr_64b(DisasContext *ctx) |
12de9a39 JM |
4547 | { |
4548 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4549 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 | 4550 | #else |
74d37793 | 4551 | TCGv t0; |
76db3ba4 | 4552 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4553 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 JM |
4554 | return; |
4555 | } | |
74d37793 | 4556 | t0 = tcg_const_tl(SR(ctx->opcode)); |
c6c7cf05 | 4557 | gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]); |
74d37793 | 4558 | tcg_temp_free(t0); |
12de9a39 JM |
4559 | #endif |
4560 | } | |
4561 | ||
4562 | /* mtsrin */ | |
e8eaa2c0 | 4563 | static void gen_mtsrin_64b(DisasContext *ctx) |
12de9a39 JM |
4564 | { |
4565 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4566 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 | 4567 | #else |
74d37793 | 4568 | TCGv t0; |
76db3ba4 | 4569 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4570 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
12de9a39 JM |
4571 | return; |
4572 | } | |
74d37793 AJ |
4573 | t0 = tcg_temp_new(); |
4574 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 28); | |
4575 | tcg_gen_andi_tl(t0, t0, 0xF); | |
c6c7cf05 | 4576 | gen_helper_store_sr(cpu_env, t0, cpu_gpr[rS(ctx->opcode)]); |
74d37793 | 4577 | tcg_temp_free(t0); |
12de9a39 JM |
4578 | #endif |
4579 | } | |
f6b868fc BS |
4580 | |
4581 | /* slbmte */ | |
e8eaa2c0 | 4582 | static void gen_slbmte(DisasContext *ctx) |
f6b868fc BS |
4583 | { |
4584 | #if defined(CONFIG_USER_ONLY) | |
4585 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4586 | #else | |
4587 | if (unlikely(!ctx->mem_idx)) { | |
4588 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4589 | return; | |
4590 | } | |
c6c7cf05 BS |
4591 | gen_helper_store_slb(cpu_env, cpu_gpr[rB(ctx->opcode)], |
4592 | cpu_gpr[rS(ctx->opcode)]); | |
f6b868fc BS |
4593 | #endif |
4594 | } | |
4595 | ||
efdef95f DG |
4596 | static void gen_slbmfee(DisasContext *ctx) |
4597 | { | |
4598 | #if defined(CONFIG_USER_ONLY) | |
4599 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4600 | #else | |
4601 | if (unlikely(!ctx->mem_idx)) { | |
4602 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4603 | return; | |
4604 | } | |
c6c7cf05 | 4605 | gen_helper_load_slb_esid(cpu_gpr[rS(ctx->opcode)], cpu_env, |
efdef95f DG |
4606 | cpu_gpr[rB(ctx->opcode)]); |
4607 | #endif | |
4608 | } | |
4609 | ||
4610 | static void gen_slbmfev(DisasContext *ctx) | |
4611 | { | |
4612 | #if defined(CONFIG_USER_ONLY) | |
4613 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4614 | #else | |
4615 | if (unlikely(!ctx->mem_idx)) { | |
4616 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); | |
4617 | return; | |
4618 | } | |
c6c7cf05 | 4619 | gen_helper_load_slb_vsid(cpu_gpr[rS(ctx->opcode)], cpu_env, |
efdef95f DG |
4620 | cpu_gpr[rB(ctx->opcode)]); |
4621 | #endif | |
4622 | } | |
12de9a39 JM |
4623 | #endif /* defined(TARGET_PPC64) */ |
4624 | ||
79aceca5 | 4625 | /*** Lookaside buffer management ***/ |
76db3ba4 | 4626 | /* Optional & mem_idx only: */ |
99e300ef | 4627 | |
54623277 | 4628 | /* tlbia */ |
99e300ef | 4629 | static void gen_tlbia(DisasContext *ctx) |
79aceca5 | 4630 | { |
9a64fbe4 | 4631 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4632 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9a64fbe4 | 4633 | #else |
76db3ba4 | 4634 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4635 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 4636 | return; |
9a64fbe4 | 4637 | } |
c6c7cf05 | 4638 | gen_helper_tlbia(cpu_env); |
9a64fbe4 | 4639 | #endif |
79aceca5 FB |
4640 | } |
4641 | ||
bf14b1ce | 4642 | /* tlbiel */ |
99e300ef | 4643 | static void gen_tlbiel(DisasContext *ctx) |
bf14b1ce BS |
4644 | { |
4645 | #if defined(CONFIG_USER_ONLY) | |
4646 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
4647 | #else | |
4648 | if (unlikely(!ctx->mem_idx)) { | |
4649 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
4650 | return; | |
4651 | } | |
c6c7cf05 | 4652 | gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
bf14b1ce BS |
4653 | #endif |
4654 | } | |
4655 | ||
79aceca5 | 4656 | /* tlbie */ |
99e300ef | 4657 | static void gen_tlbie(DisasContext *ctx) |
79aceca5 | 4658 | { |
9a64fbe4 | 4659 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4660 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9a64fbe4 | 4661 | #else |
76db3ba4 | 4662 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4663 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 4664 | return; |
9a64fbe4 | 4665 | } |
9ca3f7f3 | 4666 | if (NARROW_MODE(ctx)) { |
74d37793 AJ |
4667 | TCGv t0 = tcg_temp_new(); |
4668 | tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]); | |
c6c7cf05 | 4669 | gen_helper_tlbie(cpu_env, t0); |
74d37793 | 4670 | tcg_temp_free(t0); |
9ca3f7f3 | 4671 | } else { |
c6c7cf05 | 4672 | gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
9ca3f7f3 | 4673 | } |
9a64fbe4 | 4674 | #endif |
79aceca5 FB |
4675 | } |
4676 | ||
4677 | /* tlbsync */ | |
99e300ef | 4678 | static void gen_tlbsync(DisasContext *ctx) |
79aceca5 | 4679 | { |
9a64fbe4 | 4680 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 4681 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9a64fbe4 | 4682 | #else |
76db3ba4 | 4683 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4684 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
9fddaa0c | 4685 | return; |
9a64fbe4 FB |
4686 | } |
4687 | /* This has no effect: it should ensure that all previous | |
4688 | * tlbie have completed | |
4689 | */ | |
e06fcd75 | 4690 | gen_stop_exception(ctx); |
9a64fbe4 | 4691 | #endif |
79aceca5 FB |
4692 | } |
4693 | ||
426613db JM |
4694 | #if defined(TARGET_PPC64) |
4695 | /* slbia */ | |
99e300ef | 4696 | static void gen_slbia(DisasContext *ctx) |
426613db JM |
4697 | { |
4698 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4699 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db | 4700 | #else |
76db3ba4 | 4701 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4702 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db JM |
4703 | return; |
4704 | } | |
c6c7cf05 | 4705 | gen_helper_slbia(cpu_env); |
426613db JM |
4706 | #endif |
4707 | } | |
4708 | ||
4709 | /* slbie */ | |
99e300ef | 4710 | static void gen_slbie(DisasContext *ctx) |
426613db JM |
4711 | { |
4712 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 4713 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db | 4714 | #else |
76db3ba4 | 4715 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 4716 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
426613db JM |
4717 | return; |
4718 | } | |
c6c7cf05 | 4719 | gen_helper_slbie(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
426613db JM |
4720 | #endif |
4721 | } | |
4722 | #endif | |
4723 | ||
79aceca5 FB |
4724 | /*** External control ***/ |
4725 | /* Optional: */ | |
99e300ef | 4726 | |
54623277 | 4727 | /* eciwx */ |
99e300ef | 4728 | static void gen_eciwx(DisasContext *ctx) |
79aceca5 | 4729 | { |
76db3ba4 | 4730 | TCGv t0; |
fa407c03 | 4731 | /* Should check EAR[E] ! */ |
76db3ba4 AJ |
4732 | gen_set_access_type(ctx, ACCESS_EXT); |
4733 | t0 = tcg_temp_new(); | |
4734 | gen_addr_reg_index(ctx, t0); | |
fa407c03 | 4735 | gen_check_align(ctx, t0, 0x03); |
76db3ba4 | 4736 | gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], t0); |
fa407c03 | 4737 | tcg_temp_free(t0); |
76a66253 JM |
4738 | } |
4739 | ||
4740 | /* ecowx */ | |
99e300ef | 4741 | static void gen_ecowx(DisasContext *ctx) |
76a66253 | 4742 | { |
76db3ba4 | 4743 | TCGv t0; |
fa407c03 | 4744 | /* Should check EAR[E] ! */ |
76db3ba4 AJ |
4745 | gen_set_access_type(ctx, ACCESS_EXT); |
4746 | t0 = tcg_temp_new(); | |
4747 | gen_addr_reg_index(ctx, t0); | |
fa407c03 | 4748 | gen_check_align(ctx, t0, 0x03); |
76db3ba4 | 4749 | gen_qemu_st32(ctx, cpu_gpr[rD(ctx->opcode)], t0); |
fa407c03 | 4750 | tcg_temp_free(t0); |
76a66253 JM |
4751 | } |
4752 | ||
4753 | /* PowerPC 601 specific instructions */ | |
99e300ef | 4754 | |
54623277 | 4755 | /* abs - abs. */ |
99e300ef | 4756 | static void gen_abs(DisasContext *ctx) |
76a66253 | 4757 | { |
22e0e173 AJ |
4758 | int l1 = gen_new_label(); |
4759 | int l2 = gen_new_label(); | |
4760 | tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l1); | |
4761 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4762 | tcg_gen_br(l2); | |
4763 | gen_set_label(l1); | |
4764 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4765 | gen_set_label(l2); | |
76a66253 | 4766 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4767 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4768 | } |
4769 | ||
4770 | /* abso - abso. */ | |
99e300ef | 4771 | static void gen_abso(DisasContext *ctx) |
76a66253 | 4772 | { |
22e0e173 AJ |
4773 | int l1 = gen_new_label(); |
4774 | int l2 = gen_new_label(); | |
4775 | int l3 = gen_new_label(); | |
4776 | /* Start with XER OV disabled, the most likely case */ | |
da91a00f | 4777 | tcg_gen_movi_tl(cpu_ov, 0); |
22e0e173 AJ |
4778 | tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rA(ctx->opcode)], 0, l2); |
4779 | tcg_gen_brcondi_tl(TCG_COND_NE, cpu_gpr[rA(ctx->opcode)], 0x80000000, l1); | |
da91a00f RH |
4780 | tcg_gen_movi_tl(cpu_ov, 1); |
4781 | tcg_gen_movi_tl(cpu_so, 1); | |
22e0e173 AJ |
4782 | tcg_gen_br(l2); |
4783 | gen_set_label(l1); | |
4784 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4785 | tcg_gen_br(l3); | |
4786 | gen_set_label(l2); | |
4787 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4788 | gen_set_label(l3); | |
76a66253 | 4789 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4790 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4791 | } |
4792 | ||
4793 | /* clcs */ | |
99e300ef | 4794 | static void gen_clcs(DisasContext *ctx) |
76a66253 | 4795 | { |
22e0e173 | 4796 | TCGv_i32 t0 = tcg_const_i32(rA(ctx->opcode)); |
d523dd00 | 4797 | gen_helper_clcs(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
22e0e173 | 4798 | tcg_temp_free_i32(t0); |
c7697e1f | 4799 | /* Rc=1 sets CR0 to an undefined state */ |
76a66253 JM |
4800 | } |
4801 | ||
4802 | /* div - div. */ | |
99e300ef | 4803 | static void gen_div(DisasContext *ctx) |
76a66253 | 4804 | { |
d15f74fb BS |
4805 | gen_helper_div(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)], |
4806 | cpu_gpr[rB(ctx->opcode)]); | |
76a66253 | 4807 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4808 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4809 | } |
4810 | ||
4811 | /* divo - divo. */ | |
99e300ef | 4812 | static void gen_divo(DisasContext *ctx) |
76a66253 | 4813 | { |
d15f74fb BS |
4814 | gen_helper_divo(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)], |
4815 | cpu_gpr[rB(ctx->opcode)]); | |
76a66253 | 4816 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4817 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4818 | } |
4819 | ||
4820 | /* divs - divs. */ | |
99e300ef | 4821 | static void gen_divs(DisasContext *ctx) |
76a66253 | 4822 | { |
d15f74fb BS |
4823 | gen_helper_divs(cpu_gpr[rD(ctx->opcode)], cpu_env, cpu_gpr[rA(ctx->opcode)], |
4824 | cpu_gpr[rB(ctx->opcode)]); | |
76a66253 | 4825 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4826 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4827 | } |
4828 | ||
4829 | /* divso - divso. */ | |
99e300ef | 4830 | static void gen_divso(DisasContext *ctx) |
76a66253 | 4831 | { |
d15f74fb BS |
4832 | gen_helper_divso(cpu_gpr[rD(ctx->opcode)], cpu_env, |
4833 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
76a66253 | 4834 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4835 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4836 | } |
4837 | ||
4838 | /* doz - doz. */ | |
99e300ef | 4839 | static void gen_doz(DisasContext *ctx) |
76a66253 | 4840 | { |
22e0e173 AJ |
4841 | int l1 = gen_new_label(); |
4842 | int l2 = gen_new_label(); | |
4843 | tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1); | |
4844 | tcg_gen_sub_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4845 | tcg_gen_br(l2); | |
4846 | gen_set_label(l1); | |
4847 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0); | |
4848 | gen_set_label(l2); | |
76a66253 | 4849 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4850 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4851 | } |
4852 | ||
4853 | /* dozo - dozo. */ | |
99e300ef | 4854 | static void gen_dozo(DisasContext *ctx) |
76a66253 | 4855 | { |
22e0e173 AJ |
4856 | int l1 = gen_new_label(); |
4857 | int l2 = gen_new_label(); | |
4858 | TCGv t0 = tcg_temp_new(); | |
4859 | TCGv t1 = tcg_temp_new(); | |
4860 | TCGv t2 = tcg_temp_new(); | |
4861 | /* Start with XER OV disabled, the most likely case */ | |
da91a00f | 4862 | tcg_gen_movi_tl(cpu_ov, 0); |
22e0e173 AJ |
4863 | tcg_gen_brcond_tl(TCG_COND_GE, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], l1); |
4864 | tcg_gen_sub_tl(t0, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4865 | tcg_gen_xor_tl(t1, cpu_gpr[rB(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4866 | tcg_gen_xor_tl(t2, cpu_gpr[rA(ctx->opcode)], t0); | |
4867 | tcg_gen_andc_tl(t1, t1, t2); | |
4868 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
4869 | tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2); | |
da91a00f RH |
4870 | tcg_gen_movi_tl(cpu_ov, 1); |
4871 | tcg_gen_movi_tl(cpu_so, 1); | |
22e0e173 AJ |
4872 | tcg_gen_br(l2); |
4873 | gen_set_label(l1); | |
4874 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0); | |
4875 | gen_set_label(l2); | |
4876 | tcg_temp_free(t0); | |
4877 | tcg_temp_free(t1); | |
4878 | tcg_temp_free(t2); | |
76a66253 | 4879 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4880 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4881 | } |
4882 | ||
4883 | /* dozi */ | |
99e300ef | 4884 | static void gen_dozi(DisasContext *ctx) |
76a66253 | 4885 | { |
22e0e173 AJ |
4886 | target_long simm = SIMM(ctx->opcode); |
4887 | int l1 = gen_new_label(); | |
4888 | int l2 = gen_new_label(); | |
4889 | tcg_gen_brcondi_tl(TCG_COND_LT, cpu_gpr[rA(ctx->opcode)], simm, l1); | |
4890 | tcg_gen_subfi_tl(cpu_gpr[rD(ctx->opcode)], simm, cpu_gpr[rA(ctx->opcode)]); | |
4891 | tcg_gen_br(l2); | |
4892 | gen_set_label(l1); | |
4893 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], 0); | |
4894 | gen_set_label(l2); | |
4895 | if (unlikely(Rc(ctx->opcode) != 0)) | |
4896 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); | |
76a66253 JM |
4897 | } |
4898 | ||
76a66253 | 4899 | /* lscbx - lscbx. */ |
99e300ef | 4900 | static void gen_lscbx(DisasContext *ctx) |
76a66253 | 4901 | { |
bdb4b689 AJ |
4902 | TCGv t0 = tcg_temp_new(); |
4903 | TCGv_i32 t1 = tcg_const_i32(rD(ctx->opcode)); | |
4904 | TCGv_i32 t2 = tcg_const_i32(rA(ctx->opcode)); | |
4905 | TCGv_i32 t3 = tcg_const_i32(rB(ctx->opcode)); | |
76a66253 | 4906 | |
76db3ba4 | 4907 | gen_addr_reg_index(ctx, t0); |
76a66253 | 4908 | /* NIP cannot be restored if the memory exception comes from an helper */ |
d9bce9d9 | 4909 | gen_update_nip(ctx, ctx->nip - 4); |
2f5a189c | 4910 | gen_helper_lscbx(t0, cpu_env, t0, t1, t2, t3); |
bdb4b689 AJ |
4911 | tcg_temp_free_i32(t1); |
4912 | tcg_temp_free_i32(t2); | |
4913 | tcg_temp_free_i32(t3); | |
3d7b417e | 4914 | tcg_gen_andi_tl(cpu_xer, cpu_xer, ~0x7F); |
bdb4b689 | 4915 | tcg_gen_or_tl(cpu_xer, cpu_xer, t0); |
76a66253 | 4916 | if (unlikely(Rc(ctx->opcode) != 0)) |
bdb4b689 AJ |
4917 | gen_set_Rc0(ctx, t0); |
4918 | tcg_temp_free(t0); | |
76a66253 JM |
4919 | } |
4920 | ||
4921 | /* maskg - maskg. */ | |
99e300ef | 4922 | static void gen_maskg(DisasContext *ctx) |
76a66253 | 4923 | { |
22e0e173 AJ |
4924 | int l1 = gen_new_label(); |
4925 | TCGv t0 = tcg_temp_new(); | |
4926 | TCGv t1 = tcg_temp_new(); | |
4927 | TCGv t2 = tcg_temp_new(); | |
4928 | TCGv t3 = tcg_temp_new(); | |
4929 | tcg_gen_movi_tl(t3, 0xFFFFFFFF); | |
4930 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
4931 | tcg_gen_andi_tl(t1, cpu_gpr[rS(ctx->opcode)], 0x1F); | |
4932 | tcg_gen_addi_tl(t2, t0, 1); | |
4933 | tcg_gen_shr_tl(t2, t3, t2); | |
4934 | tcg_gen_shr_tl(t3, t3, t1); | |
4935 | tcg_gen_xor_tl(cpu_gpr[rA(ctx->opcode)], t2, t3); | |
4936 | tcg_gen_brcond_tl(TCG_COND_GE, t0, t1, l1); | |
4937 | tcg_gen_neg_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
4938 | gen_set_label(l1); | |
4939 | tcg_temp_free(t0); | |
4940 | tcg_temp_free(t1); | |
4941 | tcg_temp_free(t2); | |
4942 | tcg_temp_free(t3); | |
76a66253 | 4943 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4944 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4945 | } |
4946 | ||
4947 | /* maskir - maskir. */ | |
99e300ef | 4948 | static void gen_maskir(DisasContext *ctx) |
76a66253 | 4949 | { |
22e0e173 AJ |
4950 | TCGv t0 = tcg_temp_new(); |
4951 | TCGv t1 = tcg_temp_new(); | |
4952 | tcg_gen_and_tl(t0, cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
4953 | tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
4954 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
4955 | tcg_temp_free(t0); | |
4956 | tcg_temp_free(t1); | |
76a66253 | 4957 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4958 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
4959 | } |
4960 | ||
4961 | /* mul - mul. */ | |
99e300ef | 4962 | static void gen_mul(DisasContext *ctx) |
76a66253 | 4963 | { |
22e0e173 AJ |
4964 | TCGv_i64 t0 = tcg_temp_new_i64(); |
4965 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
4966 | TCGv t2 = tcg_temp_new(); | |
4967 | tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
4968 | tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
4969 | tcg_gen_mul_i64(t0, t0, t1); | |
4970 | tcg_gen_trunc_i64_tl(t2, t0); | |
4971 | gen_store_spr(SPR_MQ, t2); | |
4972 | tcg_gen_shri_i64(t1, t0, 32); | |
4973 | tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1); | |
4974 | tcg_temp_free_i64(t0); | |
4975 | tcg_temp_free_i64(t1); | |
4976 | tcg_temp_free(t2); | |
76a66253 | 4977 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 4978 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
4979 | } |
4980 | ||
4981 | /* mulo - mulo. */ | |
99e300ef | 4982 | static void gen_mulo(DisasContext *ctx) |
76a66253 | 4983 | { |
22e0e173 AJ |
4984 | int l1 = gen_new_label(); |
4985 | TCGv_i64 t0 = tcg_temp_new_i64(); | |
4986 | TCGv_i64 t1 = tcg_temp_new_i64(); | |
4987 | TCGv t2 = tcg_temp_new(); | |
4988 | /* Start with XER OV disabled, the most likely case */ | |
da91a00f | 4989 | tcg_gen_movi_tl(cpu_ov, 0); |
22e0e173 AJ |
4990 | tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); |
4991 | tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
4992 | tcg_gen_mul_i64(t0, t0, t1); | |
4993 | tcg_gen_trunc_i64_tl(t2, t0); | |
4994 | gen_store_spr(SPR_MQ, t2); | |
4995 | tcg_gen_shri_i64(t1, t0, 32); | |
4996 | tcg_gen_trunc_i64_tl(cpu_gpr[rD(ctx->opcode)], t1); | |
4997 | tcg_gen_ext32s_i64(t1, t0); | |
4998 | tcg_gen_brcond_i64(TCG_COND_EQ, t0, t1, l1); | |
da91a00f RH |
4999 | tcg_gen_movi_tl(cpu_ov, 1); |
5000 | tcg_gen_movi_tl(cpu_so, 1); | |
22e0e173 AJ |
5001 | gen_set_label(l1); |
5002 | tcg_temp_free_i64(t0); | |
5003 | tcg_temp_free_i64(t1); | |
5004 | tcg_temp_free(t2); | |
76a66253 | 5005 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 5006 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
5007 | } |
5008 | ||
5009 | /* nabs - nabs. */ | |
99e300ef | 5010 | static void gen_nabs(DisasContext *ctx) |
76a66253 | 5011 | { |
22e0e173 AJ |
5012 | int l1 = gen_new_label(); |
5013 | int l2 = gen_new_label(); | |
5014 | tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1); | |
5015 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
5016 | tcg_gen_br(l2); | |
5017 | gen_set_label(l1); | |
5018 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
5019 | gen_set_label(l2); | |
76a66253 | 5020 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 5021 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
5022 | } |
5023 | ||
5024 | /* nabso - nabso. */ | |
99e300ef | 5025 | static void gen_nabso(DisasContext *ctx) |
76a66253 | 5026 | { |
22e0e173 AJ |
5027 | int l1 = gen_new_label(); |
5028 | int l2 = gen_new_label(); | |
5029 | tcg_gen_brcondi_tl(TCG_COND_GT, cpu_gpr[rA(ctx->opcode)], 0, l1); | |
5030 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
5031 | tcg_gen_br(l2); | |
5032 | gen_set_label(l1); | |
5033 | tcg_gen_neg_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
5034 | gen_set_label(l2); | |
5035 | /* nabs never overflows */ | |
da91a00f | 5036 | tcg_gen_movi_tl(cpu_ov, 0); |
76a66253 | 5037 | if (unlikely(Rc(ctx->opcode) != 0)) |
22e0e173 | 5038 | gen_set_Rc0(ctx, cpu_gpr[rD(ctx->opcode)]); |
76a66253 JM |
5039 | } |
5040 | ||
5041 | /* rlmi - rlmi. */ | |
99e300ef | 5042 | static void gen_rlmi(DisasContext *ctx) |
76a66253 | 5043 | { |
7487953d AJ |
5044 | uint32_t mb = MB(ctx->opcode); |
5045 | uint32_t me = ME(ctx->opcode); | |
5046 | TCGv t0 = tcg_temp_new(); | |
5047 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5048 | tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
5049 | tcg_gen_andi_tl(t0, t0, MASK(mb, me)); | |
5050 | tcg_gen_andi_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~MASK(mb, me)); | |
5051 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], t0); | |
5052 | tcg_temp_free(t0); | |
76a66253 | 5053 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5054 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5055 | } |
5056 | ||
5057 | /* rrib - rrib. */ | |
99e300ef | 5058 | static void gen_rrib(DisasContext *ctx) |
76a66253 | 5059 | { |
7487953d AJ |
5060 | TCGv t0 = tcg_temp_new(); |
5061 | TCGv t1 = tcg_temp_new(); | |
5062 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5063 | tcg_gen_movi_tl(t1, 0x80000000); | |
5064 | tcg_gen_shr_tl(t1, t1, t0); | |
5065 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
5066 | tcg_gen_and_tl(t0, t0, t1); | |
5067 | tcg_gen_andc_tl(t1, cpu_gpr[rA(ctx->opcode)], t1); | |
5068 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5069 | tcg_temp_free(t0); | |
5070 | tcg_temp_free(t1); | |
76a66253 | 5071 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5072 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5073 | } |
5074 | ||
5075 | /* sle - sle. */ | |
99e300ef | 5076 | static void gen_sle(DisasContext *ctx) |
76a66253 | 5077 | { |
7487953d AJ |
5078 | TCGv t0 = tcg_temp_new(); |
5079 | TCGv t1 = tcg_temp_new(); | |
5080 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5081 | tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
5082 | tcg_gen_subfi_tl(t1, 32, t1); | |
5083 | tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
5084 | tcg_gen_or_tl(t1, t0, t1); | |
5085 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5086 | gen_store_spr(SPR_MQ, t1); | |
5087 | tcg_temp_free(t0); | |
5088 | tcg_temp_free(t1); | |
76a66253 | 5089 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5090 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5091 | } |
5092 | ||
5093 | /* sleq - sleq. */ | |
99e300ef | 5094 | static void gen_sleq(DisasContext *ctx) |
76a66253 | 5095 | { |
7487953d AJ |
5096 | TCGv t0 = tcg_temp_new(); |
5097 | TCGv t1 = tcg_temp_new(); | |
5098 | TCGv t2 = tcg_temp_new(); | |
5099 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5100 | tcg_gen_movi_tl(t2, 0xFFFFFFFF); | |
5101 | tcg_gen_shl_tl(t2, t2, t0); | |
5102 | tcg_gen_rotl_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
5103 | gen_load_spr(t1, SPR_MQ); | |
5104 | gen_store_spr(SPR_MQ, t0); | |
5105 | tcg_gen_and_tl(t0, t0, t2); | |
5106 | tcg_gen_andc_tl(t1, t1, t2); | |
5107 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5108 | tcg_temp_free(t0); | |
5109 | tcg_temp_free(t1); | |
5110 | tcg_temp_free(t2); | |
76a66253 | 5111 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5112 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5113 | } |
5114 | ||
5115 | /* sliq - sliq. */ | |
99e300ef | 5116 | static void gen_sliq(DisasContext *ctx) |
76a66253 | 5117 | { |
7487953d AJ |
5118 | int sh = SH(ctx->opcode); |
5119 | TCGv t0 = tcg_temp_new(); | |
5120 | TCGv t1 = tcg_temp_new(); | |
5121 | tcg_gen_shli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
5122 | tcg_gen_shri_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh); | |
5123 | tcg_gen_or_tl(t1, t0, t1); | |
5124 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5125 | gen_store_spr(SPR_MQ, t1); | |
5126 | tcg_temp_free(t0); | |
5127 | tcg_temp_free(t1); | |
76a66253 | 5128 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5129 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5130 | } |
5131 | ||
5132 | /* slliq - slliq. */ | |
99e300ef | 5133 | static void gen_slliq(DisasContext *ctx) |
76a66253 | 5134 | { |
7487953d AJ |
5135 | int sh = SH(ctx->opcode); |
5136 | TCGv t0 = tcg_temp_new(); | |
5137 | TCGv t1 = tcg_temp_new(); | |
5138 | tcg_gen_rotli_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
5139 | gen_load_spr(t1, SPR_MQ); | |
5140 | gen_store_spr(SPR_MQ, t0); | |
5141 | tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU << sh)); | |
5142 | tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU << sh)); | |
5143 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5144 | tcg_temp_free(t0); | |
5145 | tcg_temp_free(t1); | |
76a66253 | 5146 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5147 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5148 | } |
5149 | ||
5150 | /* sllq - sllq. */ | |
99e300ef | 5151 | static void gen_sllq(DisasContext *ctx) |
76a66253 | 5152 | { |
7487953d AJ |
5153 | int l1 = gen_new_label(); |
5154 | int l2 = gen_new_label(); | |
5155 | TCGv t0 = tcg_temp_local_new(); | |
5156 | TCGv t1 = tcg_temp_local_new(); | |
5157 | TCGv t2 = tcg_temp_local_new(); | |
5158 | tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5159 | tcg_gen_movi_tl(t1, 0xFFFFFFFF); | |
5160 | tcg_gen_shl_tl(t1, t1, t2); | |
5161 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20); | |
5162 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
5163 | gen_load_spr(t0, SPR_MQ); | |
5164 | tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5165 | tcg_gen_br(l2); | |
5166 | gen_set_label(l1); | |
5167 | tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t2); | |
5168 | gen_load_spr(t2, SPR_MQ); | |
5169 | tcg_gen_andc_tl(t1, t2, t1); | |
5170 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5171 | gen_set_label(l2); | |
5172 | tcg_temp_free(t0); | |
5173 | tcg_temp_free(t1); | |
5174 | tcg_temp_free(t2); | |
76a66253 | 5175 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5176 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5177 | } |
5178 | ||
5179 | /* slq - slq. */ | |
99e300ef | 5180 | static void gen_slq(DisasContext *ctx) |
76a66253 | 5181 | { |
7487953d AJ |
5182 | int l1 = gen_new_label(); |
5183 | TCGv t0 = tcg_temp_new(); | |
5184 | TCGv t1 = tcg_temp_new(); | |
5185 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5186 | tcg_gen_shl_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
5187 | tcg_gen_subfi_tl(t1, 32, t1); | |
5188 | tcg_gen_shr_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
5189 | tcg_gen_or_tl(t1, t0, t1); | |
5190 | gen_store_spr(SPR_MQ, t1); | |
5191 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20); | |
5192 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5193 | tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1); | |
5194 | tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0); | |
5195 | gen_set_label(l1); | |
5196 | tcg_temp_free(t0); | |
5197 | tcg_temp_free(t1); | |
76a66253 | 5198 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5199 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5200 | } |
5201 | ||
d9bce9d9 | 5202 | /* sraiq - sraiq. */ |
99e300ef | 5203 | static void gen_sraiq(DisasContext *ctx) |
76a66253 | 5204 | { |
7487953d AJ |
5205 | int sh = SH(ctx->opcode); |
5206 | int l1 = gen_new_label(); | |
5207 | TCGv t0 = tcg_temp_new(); | |
5208 | TCGv t1 = tcg_temp_new(); | |
5209 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
5210 | tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh); | |
5211 | tcg_gen_or_tl(t0, t0, t1); | |
5212 | gen_store_spr(SPR_MQ, t0); | |
da91a00f | 5213 | tcg_gen_movi_tl(cpu_ca, 0); |
7487953d AJ |
5214 | tcg_gen_brcondi_tl(TCG_COND_EQ, t1, 0, l1); |
5215 | tcg_gen_brcondi_tl(TCG_COND_GE, cpu_gpr[rS(ctx->opcode)], 0, l1); | |
da91a00f | 5216 | tcg_gen_movi_tl(cpu_ca, 1); |
7487953d AJ |
5217 | gen_set_label(l1); |
5218 | tcg_gen_sari_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], sh); | |
5219 | tcg_temp_free(t0); | |
5220 | tcg_temp_free(t1); | |
76a66253 | 5221 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5222 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5223 | } |
5224 | ||
5225 | /* sraq - sraq. */ | |
99e300ef | 5226 | static void gen_sraq(DisasContext *ctx) |
76a66253 | 5227 | { |
7487953d AJ |
5228 | int l1 = gen_new_label(); |
5229 | int l2 = gen_new_label(); | |
5230 | TCGv t0 = tcg_temp_new(); | |
5231 | TCGv t1 = tcg_temp_local_new(); | |
5232 | TCGv t2 = tcg_temp_local_new(); | |
5233 | tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5234 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2); | |
5235 | tcg_gen_sar_tl(t1, cpu_gpr[rS(ctx->opcode)], t2); | |
5236 | tcg_gen_subfi_tl(t2, 32, t2); | |
5237 | tcg_gen_shl_tl(t2, cpu_gpr[rS(ctx->opcode)], t2); | |
5238 | tcg_gen_or_tl(t0, t0, t2); | |
5239 | gen_store_spr(SPR_MQ, t0); | |
5240 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20); | |
5241 | tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l1); | |
5242 | tcg_gen_mov_tl(t2, cpu_gpr[rS(ctx->opcode)]); | |
5243 | tcg_gen_sari_tl(t1, cpu_gpr[rS(ctx->opcode)], 31); | |
5244 | gen_set_label(l1); | |
5245 | tcg_temp_free(t0); | |
5246 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t1); | |
da91a00f | 5247 | tcg_gen_movi_tl(cpu_ca, 0); |
7487953d AJ |
5248 | tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l2); |
5249 | tcg_gen_brcondi_tl(TCG_COND_EQ, t2, 0, l2); | |
da91a00f | 5250 | tcg_gen_movi_tl(cpu_ca, 1); |
7487953d AJ |
5251 | gen_set_label(l2); |
5252 | tcg_temp_free(t1); | |
5253 | tcg_temp_free(t2); | |
76a66253 | 5254 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5255 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5256 | } |
5257 | ||
5258 | /* sre - sre. */ | |
99e300ef | 5259 | static void gen_sre(DisasContext *ctx) |
76a66253 | 5260 | { |
7487953d AJ |
5261 | TCGv t0 = tcg_temp_new(); |
5262 | TCGv t1 = tcg_temp_new(); | |
5263 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5264 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
5265 | tcg_gen_subfi_tl(t1, 32, t1); | |
5266 | tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
5267 | tcg_gen_or_tl(t1, t0, t1); | |
5268 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5269 | gen_store_spr(SPR_MQ, t1); | |
5270 | tcg_temp_free(t0); | |
5271 | tcg_temp_free(t1); | |
76a66253 | 5272 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5273 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5274 | } |
5275 | ||
5276 | /* srea - srea. */ | |
99e300ef | 5277 | static void gen_srea(DisasContext *ctx) |
76a66253 | 5278 | { |
7487953d AJ |
5279 | TCGv t0 = tcg_temp_new(); |
5280 | TCGv t1 = tcg_temp_new(); | |
5281 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5282 | tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
5283 | gen_store_spr(SPR_MQ, t0); | |
5284 | tcg_gen_sar_tl(cpu_gpr[rA(ctx->opcode)], cpu_gpr[rS(ctx->opcode)], t1); | |
5285 | tcg_temp_free(t0); | |
5286 | tcg_temp_free(t1); | |
76a66253 | 5287 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5288 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5289 | } |
5290 | ||
5291 | /* sreq */ | |
99e300ef | 5292 | static void gen_sreq(DisasContext *ctx) |
76a66253 | 5293 | { |
7487953d AJ |
5294 | TCGv t0 = tcg_temp_new(); |
5295 | TCGv t1 = tcg_temp_new(); | |
5296 | TCGv t2 = tcg_temp_new(); | |
5297 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5298 | tcg_gen_movi_tl(t1, 0xFFFFFFFF); | |
5299 | tcg_gen_shr_tl(t1, t1, t0); | |
5300 | tcg_gen_rotr_tl(t0, cpu_gpr[rS(ctx->opcode)], t0); | |
5301 | gen_load_spr(t2, SPR_MQ); | |
5302 | gen_store_spr(SPR_MQ, t0); | |
5303 | tcg_gen_and_tl(t0, t0, t1); | |
5304 | tcg_gen_andc_tl(t2, t2, t1); | |
5305 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t2); | |
5306 | tcg_temp_free(t0); | |
5307 | tcg_temp_free(t1); | |
5308 | tcg_temp_free(t2); | |
76a66253 | 5309 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5310 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5311 | } |
5312 | ||
5313 | /* sriq */ | |
99e300ef | 5314 | static void gen_sriq(DisasContext *ctx) |
76a66253 | 5315 | { |
7487953d AJ |
5316 | int sh = SH(ctx->opcode); |
5317 | TCGv t0 = tcg_temp_new(); | |
5318 | TCGv t1 = tcg_temp_new(); | |
5319 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
5320 | tcg_gen_shli_tl(t1, cpu_gpr[rS(ctx->opcode)], 32 - sh); | |
5321 | tcg_gen_or_tl(t1, t0, t1); | |
5322 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5323 | gen_store_spr(SPR_MQ, t1); | |
5324 | tcg_temp_free(t0); | |
5325 | tcg_temp_free(t1); | |
76a66253 | 5326 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5327 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5328 | } |
5329 | ||
5330 | /* srliq */ | |
99e300ef | 5331 | static void gen_srliq(DisasContext *ctx) |
76a66253 | 5332 | { |
7487953d AJ |
5333 | int sh = SH(ctx->opcode); |
5334 | TCGv t0 = tcg_temp_new(); | |
5335 | TCGv t1 = tcg_temp_new(); | |
5336 | tcg_gen_rotri_tl(t0, cpu_gpr[rS(ctx->opcode)], sh); | |
5337 | gen_load_spr(t1, SPR_MQ); | |
5338 | gen_store_spr(SPR_MQ, t0); | |
5339 | tcg_gen_andi_tl(t0, t0, (0xFFFFFFFFU >> sh)); | |
5340 | tcg_gen_andi_tl(t1, t1, ~(0xFFFFFFFFU >> sh)); | |
5341 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5342 | tcg_temp_free(t0); | |
5343 | tcg_temp_free(t1); | |
76a66253 | 5344 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5345 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5346 | } |
5347 | ||
5348 | /* srlq */ | |
99e300ef | 5349 | static void gen_srlq(DisasContext *ctx) |
76a66253 | 5350 | { |
7487953d AJ |
5351 | int l1 = gen_new_label(); |
5352 | int l2 = gen_new_label(); | |
5353 | TCGv t0 = tcg_temp_local_new(); | |
5354 | TCGv t1 = tcg_temp_local_new(); | |
5355 | TCGv t2 = tcg_temp_local_new(); | |
5356 | tcg_gen_andi_tl(t2, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5357 | tcg_gen_movi_tl(t1, 0xFFFFFFFF); | |
5358 | tcg_gen_shr_tl(t2, t1, t2); | |
5359 | tcg_gen_andi_tl(t0, cpu_gpr[rB(ctx->opcode)], 0x20); | |
5360 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
5361 | gen_load_spr(t0, SPR_MQ); | |
5362 | tcg_gen_and_tl(cpu_gpr[rA(ctx->opcode)], t0, t2); | |
5363 | tcg_gen_br(l2); | |
5364 | gen_set_label(l1); | |
5365 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t2); | |
5366 | tcg_gen_and_tl(t0, t0, t2); | |
5367 | gen_load_spr(t1, SPR_MQ); | |
5368 | tcg_gen_andc_tl(t1, t1, t2); | |
5369 | tcg_gen_or_tl(cpu_gpr[rA(ctx->opcode)], t0, t1); | |
5370 | gen_set_label(l2); | |
5371 | tcg_temp_free(t0); | |
5372 | tcg_temp_free(t1); | |
5373 | tcg_temp_free(t2); | |
76a66253 | 5374 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5375 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5376 | } |
5377 | ||
5378 | /* srq */ | |
99e300ef | 5379 | static void gen_srq(DisasContext *ctx) |
76a66253 | 5380 | { |
7487953d AJ |
5381 | int l1 = gen_new_label(); |
5382 | TCGv t0 = tcg_temp_new(); | |
5383 | TCGv t1 = tcg_temp_new(); | |
5384 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x1F); | |
5385 | tcg_gen_shr_tl(t0, cpu_gpr[rS(ctx->opcode)], t1); | |
5386 | tcg_gen_subfi_tl(t1, 32, t1); | |
5387 | tcg_gen_shl_tl(t1, cpu_gpr[rS(ctx->opcode)], t1); | |
5388 | tcg_gen_or_tl(t1, t0, t1); | |
5389 | gen_store_spr(SPR_MQ, t1); | |
5390 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0x20); | |
5391 | tcg_gen_mov_tl(cpu_gpr[rA(ctx->opcode)], t0); | |
5392 | tcg_gen_brcondi_tl(TCG_COND_EQ, t0, 0, l1); | |
5393 | tcg_gen_movi_tl(cpu_gpr[rA(ctx->opcode)], 0); | |
5394 | gen_set_label(l1); | |
5395 | tcg_temp_free(t0); | |
5396 | tcg_temp_free(t1); | |
76a66253 | 5397 | if (unlikely(Rc(ctx->opcode) != 0)) |
7487953d | 5398 | gen_set_Rc0(ctx, cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5399 | } |
5400 | ||
5401 | /* PowerPC 602 specific instructions */ | |
99e300ef | 5402 | |
54623277 | 5403 | /* dsa */ |
99e300ef | 5404 | static void gen_dsa(DisasContext *ctx) |
76a66253 JM |
5405 | { |
5406 | /* XXX: TODO */ | |
e06fcd75 | 5407 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 JM |
5408 | } |
5409 | ||
5410 | /* esa */ | |
99e300ef | 5411 | static void gen_esa(DisasContext *ctx) |
76a66253 JM |
5412 | { |
5413 | /* XXX: TODO */ | |
e06fcd75 | 5414 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 JM |
5415 | } |
5416 | ||
5417 | /* mfrom */ | |
99e300ef | 5418 | static void gen_mfrom(DisasContext *ctx) |
76a66253 JM |
5419 | { |
5420 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5421 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5422 | #else |
76db3ba4 | 5423 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5424 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5425 | return; |
5426 | } | |
cf02a65c | 5427 | gen_helper_602_mfrom(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
76a66253 JM |
5428 | #endif |
5429 | } | |
5430 | ||
5431 | /* 602 - 603 - G2 TLB management */ | |
e8eaa2c0 | 5432 | |
54623277 | 5433 | /* tlbld */ |
e8eaa2c0 | 5434 | static void gen_tlbld_6xx(DisasContext *ctx) |
76a66253 JM |
5435 | { |
5436 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5437 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5438 | #else |
76db3ba4 | 5439 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5440 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5441 | return; |
5442 | } | |
c6c7cf05 | 5443 | gen_helper_6xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
76a66253 JM |
5444 | #endif |
5445 | } | |
5446 | ||
5447 | /* tlbli */ | |
e8eaa2c0 | 5448 | static void gen_tlbli_6xx(DisasContext *ctx) |
76a66253 JM |
5449 | { |
5450 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5451 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5452 | #else |
76db3ba4 | 5453 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5454 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5455 | return; |
5456 | } | |
c6c7cf05 | 5457 | gen_helper_6xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
76a66253 JM |
5458 | #endif |
5459 | } | |
5460 | ||
7dbe11ac | 5461 | /* 74xx TLB management */ |
e8eaa2c0 | 5462 | |
54623277 | 5463 | /* tlbld */ |
e8eaa2c0 | 5464 | static void gen_tlbld_74xx(DisasContext *ctx) |
7dbe11ac JM |
5465 | { |
5466 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5467 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
7dbe11ac | 5468 | #else |
76db3ba4 | 5469 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5470 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
7dbe11ac JM |
5471 | return; |
5472 | } | |
c6c7cf05 | 5473 | gen_helper_74xx_tlbd(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
7dbe11ac JM |
5474 | #endif |
5475 | } | |
5476 | ||
5477 | /* tlbli */ | |
e8eaa2c0 | 5478 | static void gen_tlbli_74xx(DisasContext *ctx) |
7dbe11ac JM |
5479 | { |
5480 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5481 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
7dbe11ac | 5482 | #else |
76db3ba4 | 5483 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5484 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
7dbe11ac JM |
5485 | return; |
5486 | } | |
c6c7cf05 | 5487 | gen_helper_74xx_tlbi(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
7dbe11ac JM |
5488 | #endif |
5489 | } | |
5490 | ||
76a66253 | 5491 | /* POWER instructions not in PowerPC 601 */ |
99e300ef | 5492 | |
54623277 | 5493 | /* clf */ |
99e300ef | 5494 | static void gen_clf(DisasContext *ctx) |
76a66253 JM |
5495 | { |
5496 | /* Cache line flush: implemented as no-op */ | |
5497 | } | |
5498 | ||
5499 | /* cli */ | |
99e300ef | 5500 | static void gen_cli(DisasContext *ctx) |
76a66253 | 5501 | { |
7f75ffd3 | 5502 | /* Cache line invalidate: privileged and treated as no-op */ |
76a66253 | 5503 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 5504 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5505 | #else |
76db3ba4 | 5506 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5507 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5508 | return; |
5509 | } | |
5510 | #endif | |
5511 | } | |
5512 | ||
5513 | /* dclst */ | |
99e300ef | 5514 | static void gen_dclst(DisasContext *ctx) |
76a66253 JM |
5515 | { |
5516 | /* Data cache line store: treated as no-op */ | |
5517 | } | |
5518 | ||
99e300ef | 5519 | static void gen_mfsri(DisasContext *ctx) |
76a66253 JM |
5520 | { |
5521 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5522 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5523 | #else |
74d37793 AJ |
5524 | int ra = rA(ctx->opcode); |
5525 | int rd = rD(ctx->opcode); | |
5526 | TCGv t0; | |
76db3ba4 | 5527 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5528 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5529 | return; |
5530 | } | |
74d37793 | 5531 | t0 = tcg_temp_new(); |
76db3ba4 | 5532 | gen_addr_reg_index(ctx, t0); |
74d37793 AJ |
5533 | tcg_gen_shri_tl(t0, t0, 28); |
5534 | tcg_gen_andi_tl(t0, t0, 0xF); | |
c6c7cf05 | 5535 | gen_helper_load_sr(cpu_gpr[rd], cpu_env, t0); |
74d37793 | 5536 | tcg_temp_free(t0); |
76a66253 | 5537 | if (ra != 0 && ra != rd) |
74d37793 | 5538 | tcg_gen_mov_tl(cpu_gpr[ra], cpu_gpr[rd]); |
76a66253 JM |
5539 | #endif |
5540 | } | |
5541 | ||
99e300ef | 5542 | static void gen_rac(DisasContext *ctx) |
76a66253 JM |
5543 | { |
5544 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5545 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5546 | #else |
22e0e173 | 5547 | TCGv t0; |
76db3ba4 | 5548 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5549 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5550 | return; |
5551 | } | |
22e0e173 | 5552 | t0 = tcg_temp_new(); |
76db3ba4 | 5553 | gen_addr_reg_index(ctx, t0); |
c6c7cf05 | 5554 | gen_helper_rac(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
22e0e173 | 5555 | tcg_temp_free(t0); |
76a66253 JM |
5556 | #endif |
5557 | } | |
5558 | ||
99e300ef | 5559 | static void gen_rfsvc(DisasContext *ctx) |
76a66253 JM |
5560 | { |
5561 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5562 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5563 | #else |
76db3ba4 | 5564 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5565 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5566 | return; |
5567 | } | |
e5f17ac6 | 5568 | gen_helper_rfsvc(cpu_env); |
e06fcd75 | 5569 | gen_sync_exception(ctx); |
76a66253 JM |
5570 | #endif |
5571 | } | |
5572 | ||
5573 | /* svc is not implemented for now */ | |
5574 | ||
5575 | /* POWER2 specific instructions */ | |
5576 | /* Quad manipulation (load/store two floats at a time) */ | |
76a66253 JM |
5577 | |
5578 | /* lfq */ | |
99e300ef | 5579 | static void gen_lfq(DisasContext *ctx) |
76a66253 | 5580 | { |
01a4afeb | 5581 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5582 | TCGv t0; |
5583 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5584 | t0 = tcg_temp_new(); | |
5585 | gen_addr_imm_index(ctx, t0, 0); | |
5586 | gen_qemu_ld64(ctx, cpu_fpr[rd], t0); | |
5587 | gen_addr_add(ctx, t0, t0, 8); | |
5588 | gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0); | |
01a4afeb | 5589 | tcg_temp_free(t0); |
76a66253 JM |
5590 | } |
5591 | ||
5592 | /* lfqu */ | |
99e300ef | 5593 | static void gen_lfqu(DisasContext *ctx) |
76a66253 JM |
5594 | { |
5595 | int ra = rA(ctx->opcode); | |
01a4afeb | 5596 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5597 | TCGv t0, t1; |
5598 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5599 | t0 = tcg_temp_new(); | |
5600 | t1 = tcg_temp_new(); | |
5601 | gen_addr_imm_index(ctx, t0, 0); | |
5602 | gen_qemu_ld64(ctx, cpu_fpr[rd], t0); | |
5603 | gen_addr_add(ctx, t1, t0, 8); | |
5604 | gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1); | |
76a66253 | 5605 | if (ra != 0) |
01a4afeb AJ |
5606 | tcg_gen_mov_tl(cpu_gpr[ra], t0); |
5607 | tcg_temp_free(t0); | |
5608 | tcg_temp_free(t1); | |
76a66253 JM |
5609 | } |
5610 | ||
5611 | /* lfqux */ | |
99e300ef | 5612 | static void gen_lfqux(DisasContext *ctx) |
76a66253 JM |
5613 | { |
5614 | int ra = rA(ctx->opcode); | |
01a4afeb | 5615 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5616 | gen_set_access_type(ctx, ACCESS_FLOAT); |
5617 | TCGv t0, t1; | |
5618 | t0 = tcg_temp_new(); | |
5619 | gen_addr_reg_index(ctx, t0); | |
5620 | gen_qemu_ld64(ctx, cpu_fpr[rd], t0); | |
5621 | t1 = tcg_temp_new(); | |
5622 | gen_addr_add(ctx, t1, t0, 8); | |
5623 | gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t1); | |
5624 | tcg_temp_free(t1); | |
76a66253 | 5625 | if (ra != 0) |
01a4afeb AJ |
5626 | tcg_gen_mov_tl(cpu_gpr[ra], t0); |
5627 | tcg_temp_free(t0); | |
76a66253 JM |
5628 | } |
5629 | ||
5630 | /* lfqx */ | |
99e300ef | 5631 | static void gen_lfqx(DisasContext *ctx) |
76a66253 | 5632 | { |
01a4afeb | 5633 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5634 | TCGv t0; |
5635 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5636 | t0 = tcg_temp_new(); | |
5637 | gen_addr_reg_index(ctx, t0); | |
5638 | gen_qemu_ld64(ctx, cpu_fpr[rd], t0); | |
5639 | gen_addr_add(ctx, t0, t0, 8); | |
5640 | gen_qemu_ld64(ctx, cpu_fpr[(rd + 1) % 32], t0); | |
01a4afeb | 5641 | tcg_temp_free(t0); |
76a66253 JM |
5642 | } |
5643 | ||
5644 | /* stfq */ | |
99e300ef | 5645 | static void gen_stfq(DisasContext *ctx) |
76a66253 | 5646 | { |
01a4afeb | 5647 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5648 | TCGv t0; |
5649 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5650 | t0 = tcg_temp_new(); | |
5651 | gen_addr_imm_index(ctx, t0, 0); | |
5652 | gen_qemu_st64(ctx, cpu_fpr[rd], t0); | |
5653 | gen_addr_add(ctx, t0, t0, 8); | |
5654 | gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0); | |
01a4afeb | 5655 | tcg_temp_free(t0); |
76a66253 JM |
5656 | } |
5657 | ||
5658 | /* stfqu */ | |
99e300ef | 5659 | static void gen_stfqu(DisasContext *ctx) |
76a66253 JM |
5660 | { |
5661 | int ra = rA(ctx->opcode); | |
01a4afeb | 5662 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5663 | TCGv t0, t1; |
5664 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5665 | t0 = tcg_temp_new(); | |
5666 | gen_addr_imm_index(ctx, t0, 0); | |
5667 | gen_qemu_st64(ctx, cpu_fpr[rd], t0); | |
5668 | t1 = tcg_temp_new(); | |
5669 | gen_addr_add(ctx, t1, t0, 8); | |
5670 | gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1); | |
5671 | tcg_temp_free(t1); | |
76a66253 | 5672 | if (ra != 0) |
01a4afeb AJ |
5673 | tcg_gen_mov_tl(cpu_gpr[ra], t0); |
5674 | tcg_temp_free(t0); | |
76a66253 JM |
5675 | } |
5676 | ||
5677 | /* stfqux */ | |
99e300ef | 5678 | static void gen_stfqux(DisasContext *ctx) |
76a66253 JM |
5679 | { |
5680 | int ra = rA(ctx->opcode); | |
01a4afeb | 5681 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5682 | TCGv t0, t1; |
5683 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5684 | t0 = tcg_temp_new(); | |
5685 | gen_addr_reg_index(ctx, t0); | |
5686 | gen_qemu_st64(ctx, cpu_fpr[rd], t0); | |
5687 | t1 = tcg_temp_new(); | |
5688 | gen_addr_add(ctx, t1, t0, 8); | |
5689 | gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t1); | |
5690 | tcg_temp_free(t1); | |
76a66253 | 5691 | if (ra != 0) |
01a4afeb AJ |
5692 | tcg_gen_mov_tl(cpu_gpr[ra], t0); |
5693 | tcg_temp_free(t0); | |
76a66253 JM |
5694 | } |
5695 | ||
5696 | /* stfqx */ | |
99e300ef | 5697 | static void gen_stfqx(DisasContext *ctx) |
76a66253 | 5698 | { |
01a4afeb | 5699 | int rd = rD(ctx->opcode); |
76db3ba4 AJ |
5700 | TCGv t0; |
5701 | gen_set_access_type(ctx, ACCESS_FLOAT); | |
5702 | t0 = tcg_temp_new(); | |
5703 | gen_addr_reg_index(ctx, t0); | |
5704 | gen_qemu_st64(ctx, cpu_fpr[rd], t0); | |
5705 | gen_addr_add(ctx, t0, t0, 8); | |
5706 | gen_qemu_st64(ctx, cpu_fpr[(rd + 1) % 32], t0); | |
01a4afeb | 5707 | tcg_temp_free(t0); |
76a66253 JM |
5708 | } |
5709 | ||
5710 | /* BookE specific instructions */ | |
99e300ef | 5711 | |
54623277 | 5712 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5713 | static void gen_mfapidi(DisasContext *ctx) |
76a66253 JM |
5714 | { |
5715 | /* XXX: TODO */ | |
e06fcd75 | 5716 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 JM |
5717 | } |
5718 | ||
2662a059 | 5719 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5720 | static void gen_tlbiva(DisasContext *ctx) |
76a66253 JM |
5721 | { |
5722 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5723 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 5724 | #else |
74d37793 | 5725 | TCGv t0; |
76db3ba4 | 5726 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5727 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
5728 | return; |
5729 | } | |
ec72e276 | 5730 | t0 = tcg_temp_new(); |
76db3ba4 | 5731 | gen_addr_reg_index(ctx, t0); |
c6c7cf05 | 5732 | gen_helper_tlbie(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
74d37793 | 5733 | tcg_temp_free(t0); |
76a66253 JM |
5734 | #endif |
5735 | } | |
5736 | ||
5737 | /* All 405 MAC instructions are translated here */ | |
636aa200 BS |
5738 | static inline void gen_405_mulladd_insn(DisasContext *ctx, int opc2, int opc3, |
5739 | int ra, int rb, int rt, int Rc) | |
76a66253 | 5740 | { |
182608d4 AJ |
5741 | TCGv t0, t1; |
5742 | ||
a7812ae4 PB |
5743 | t0 = tcg_temp_local_new(); |
5744 | t1 = tcg_temp_local_new(); | |
182608d4 | 5745 | |
76a66253 JM |
5746 | switch (opc3 & 0x0D) { |
5747 | case 0x05: | |
5748 | /* macchw - macchw. - macchwo - macchwo. */ | |
5749 | /* macchws - macchws. - macchwso - macchwso. */ | |
5750 | /* nmacchw - nmacchw. - nmacchwo - nmacchwo. */ | |
5751 | /* nmacchws - nmacchws. - nmacchwso - nmacchwso. */ | |
5752 | /* mulchw - mulchw. */ | |
182608d4 AJ |
5753 | tcg_gen_ext16s_tl(t0, cpu_gpr[ra]); |
5754 | tcg_gen_sari_tl(t1, cpu_gpr[rb], 16); | |
5755 | tcg_gen_ext16s_tl(t1, t1); | |
76a66253 JM |
5756 | break; |
5757 | case 0x04: | |
5758 | /* macchwu - macchwu. - macchwuo - macchwuo. */ | |
5759 | /* macchwsu - macchwsu. - macchwsuo - macchwsuo. */ | |
5760 | /* mulchwu - mulchwu. */ | |
182608d4 AJ |
5761 | tcg_gen_ext16u_tl(t0, cpu_gpr[ra]); |
5762 | tcg_gen_shri_tl(t1, cpu_gpr[rb], 16); | |
5763 | tcg_gen_ext16u_tl(t1, t1); | |
76a66253 JM |
5764 | break; |
5765 | case 0x01: | |
5766 | /* machhw - machhw. - machhwo - machhwo. */ | |
5767 | /* machhws - machhws. - machhwso - machhwso. */ | |
5768 | /* nmachhw - nmachhw. - nmachhwo - nmachhwo. */ | |
5769 | /* nmachhws - nmachhws. - nmachhwso - nmachhwso. */ | |
5770 | /* mulhhw - mulhhw. */ | |
182608d4 AJ |
5771 | tcg_gen_sari_tl(t0, cpu_gpr[ra], 16); |
5772 | tcg_gen_ext16s_tl(t0, t0); | |
5773 | tcg_gen_sari_tl(t1, cpu_gpr[rb], 16); | |
5774 | tcg_gen_ext16s_tl(t1, t1); | |
76a66253 JM |
5775 | break; |
5776 | case 0x00: | |
5777 | /* machhwu - machhwu. - machhwuo - machhwuo. */ | |
5778 | /* machhwsu - machhwsu. - machhwsuo - machhwsuo. */ | |
5779 | /* mulhhwu - mulhhwu. */ | |
182608d4 AJ |
5780 | tcg_gen_shri_tl(t0, cpu_gpr[ra], 16); |
5781 | tcg_gen_ext16u_tl(t0, t0); | |
5782 | tcg_gen_shri_tl(t1, cpu_gpr[rb], 16); | |
5783 | tcg_gen_ext16u_tl(t1, t1); | |
76a66253 JM |
5784 | break; |
5785 | case 0x0D: | |
5786 | /* maclhw - maclhw. - maclhwo - maclhwo. */ | |
5787 | /* maclhws - maclhws. - maclhwso - maclhwso. */ | |
5788 | /* nmaclhw - nmaclhw. - nmaclhwo - nmaclhwo. */ | |
5789 | /* nmaclhws - nmaclhws. - nmaclhwso - nmaclhwso. */ | |
5790 | /* mullhw - mullhw. */ | |
182608d4 AJ |
5791 | tcg_gen_ext16s_tl(t0, cpu_gpr[ra]); |
5792 | tcg_gen_ext16s_tl(t1, cpu_gpr[rb]); | |
76a66253 JM |
5793 | break; |
5794 | case 0x0C: | |
5795 | /* maclhwu - maclhwu. - maclhwuo - maclhwuo. */ | |
5796 | /* maclhwsu - maclhwsu. - maclhwsuo - maclhwsuo. */ | |
5797 | /* mullhwu - mullhwu. */ | |
182608d4 AJ |
5798 | tcg_gen_ext16u_tl(t0, cpu_gpr[ra]); |
5799 | tcg_gen_ext16u_tl(t1, cpu_gpr[rb]); | |
76a66253 JM |
5800 | break; |
5801 | } | |
76a66253 | 5802 | if (opc2 & 0x04) { |
182608d4 AJ |
5803 | /* (n)multiply-and-accumulate (0x0C / 0x0E) */ |
5804 | tcg_gen_mul_tl(t1, t0, t1); | |
5805 | if (opc2 & 0x02) { | |
5806 | /* nmultiply-and-accumulate (0x0E) */ | |
5807 | tcg_gen_sub_tl(t0, cpu_gpr[rt], t1); | |
5808 | } else { | |
5809 | /* multiply-and-accumulate (0x0C) */ | |
5810 | tcg_gen_add_tl(t0, cpu_gpr[rt], t1); | |
5811 | } | |
5812 | ||
5813 | if (opc3 & 0x12) { | |
5814 | /* Check overflow and/or saturate */ | |
5815 | int l1 = gen_new_label(); | |
5816 | ||
5817 | if (opc3 & 0x10) { | |
5818 | /* Start with XER OV disabled, the most likely case */ | |
da91a00f | 5819 | tcg_gen_movi_tl(cpu_ov, 0); |
182608d4 AJ |
5820 | } |
5821 | if (opc3 & 0x01) { | |
5822 | /* Signed */ | |
5823 | tcg_gen_xor_tl(t1, cpu_gpr[rt], t1); | |
5824 | tcg_gen_brcondi_tl(TCG_COND_GE, t1, 0, l1); | |
5825 | tcg_gen_xor_tl(t1, cpu_gpr[rt], t0); | |
5826 | tcg_gen_brcondi_tl(TCG_COND_LT, t1, 0, l1); | |
bdc4e053 | 5827 | if (opc3 & 0x02) { |
182608d4 AJ |
5828 | /* Saturate */ |
5829 | tcg_gen_sari_tl(t0, cpu_gpr[rt], 31); | |
5830 | tcg_gen_xori_tl(t0, t0, 0x7fffffff); | |
5831 | } | |
5832 | } else { | |
5833 | /* Unsigned */ | |
5834 | tcg_gen_brcond_tl(TCG_COND_GEU, t0, t1, l1); | |
bdc4e053 | 5835 | if (opc3 & 0x02) { |
182608d4 AJ |
5836 | /* Saturate */ |
5837 | tcg_gen_movi_tl(t0, UINT32_MAX); | |
5838 | } | |
5839 | } | |
5840 | if (opc3 & 0x10) { | |
5841 | /* Check overflow */ | |
da91a00f RH |
5842 | tcg_gen_movi_tl(cpu_ov, 1); |
5843 | tcg_gen_movi_tl(cpu_so, 1); | |
182608d4 AJ |
5844 | } |
5845 | gen_set_label(l1); | |
5846 | tcg_gen_mov_tl(cpu_gpr[rt], t0); | |
5847 | } | |
5848 | } else { | |
5849 | tcg_gen_mul_tl(cpu_gpr[rt], t0, t1); | |
76a66253 | 5850 | } |
182608d4 AJ |
5851 | tcg_temp_free(t0); |
5852 | tcg_temp_free(t1); | |
76a66253 JM |
5853 | if (unlikely(Rc) != 0) { |
5854 | /* Update Rc0 */ | |
182608d4 | 5855 | gen_set_Rc0(ctx, cpu_gpr[rt]); |
76a66253 JM |
5856 | } |
5857 | } | |
5858 | ||
a750fc0b | 5859 | #define GEN_MAC_HANDLER(name, opc2, opc3) \ |
99e300ef | 5860 | static void glue(gen_, name)(DisasContext *ctx) \ |
76a66253 JM |
5861 | { \ |
5862 | gen_405_mulladd_insn(ctx, opc2, opc3, rA(ctx->opcode), rB(ctx->opcode), \ | |
5863 | rD(ctx->opcode), Rc(ctx->opcode)); \ | |
5864 | } | |
5865 | ||
5866 | /* macchw - macchw. */ | |
a750fc0b | 5867 | GEN_MAC_HANDLER(macchw, 0x0C, 0x05); |
76a66253 | 5868 | /* macchwo - macchwo. */ |
a750fc0b | 5869 | GEN_MAC_HANDLER(macchwo, 0x0C, 0x15); |
76a66253 | 5870 | /* macchws - macchws. */ |
a750fc0b | 5871 | GEN_MAC_HANDLER(macchws, 0x0C, 0x07); |
76a66253 | 5872 | /* macchwso - macchwso. */ |
a750fc0b | 5873 | GEN_MAC_HANDLER(macchwso, 0x0C, 0x17); |
76a66253 | 5874 | /* macchwsu - macchwsu. */ |
a750fc0b | 5875 | GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06); |
76a66253 | 5876 | /* macchwsuo - macchwsuo. */ |
a750fc0b | 5877 | GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16); |
76a66253 | 5878 | /* macchwu - macchwu. */ |
a750fc0b | 5879 | GEN_MAC_HANDLER(macchwu, 0x0C, 0x04); |
76a66253 | 5880 | /* macchwuo - macchwuo. */ |
a750fc0b | 5881 | GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14); |
76a66253 | 5882 | /* machhw - machhw. */ |
a750fc0b | 5883 | GEN_MAC_HANDLER(machhw, 0x0C, 0x01); |
76a66253 | 5884 | /* machhwo - machhwo. */ |
a750fc0b | 5885 | GEN_MAC_HANDLER(machhwo, 0x0C, 0x11); |
76a66253 | 5886 | /* machhws - machhws. */ |
a750fc0b | 5887 | GEN_MAC_HANDLER(machhws, 0x0C, 0x03); |
76a66253 | 5888 | /* machhwso - machhwso. */ |
a750fc0b | 5889 | GEN_MAC_HANDLER(machhwso, 0x0C, 0x13); |
76a66253 | 5890 | /* machhwsu - machhwsu. */ |
a750fc0b | 5891 | GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02); |
76a66253 | 5892 | /* machhwsuo - machhwsuo. */ |
a750fc0b | 5893 | GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12); |
76a66253 | 5894 | /* machhwu - machhwu. */ |
a750fc0b | 5895 | GEN_MAC_HANDLER(machhwu, 0x0C, 0x00); |
76a66253 | 5896 | /* machhwuo - machhwuo. */ |
a750fc0b | 5897 | GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10); |
76a66253 | 5898 | /* maclhw - maclhw. */ |
a750fc0b | 5899 | GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D); |
76a66253 | 5900 | /* maclhwo - maclhwo. */ |
a750fc0b | 5901 | GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D); |
76a66253 | 5902 | /* maclhws - maclhws. */ |
a750fc0b | 5903 | GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F); |
76a66253 | 5904 | /* maclhwso - maclhwso. */ |
a750fc0b | 5905 | GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F); |
76a66253 | 5906 | /* maclhwu - maclhwu. */ |
a750fc0b | 5907 | GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C); |
76a66253 | 5908 | /* maclhwuo - maclhwuo. */ |
a750fc0b | 5909 | GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C); |
76a66253 | 5910 | /* maclhwsu - maclhwsu. */ |
a750fc0b | 5911 | GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E); |
76a66253 | 5912 | /* maclhwsuo - maclhwsuo. */ |
a750fc0b | 5913 | GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E); |
76a66253 | 5914 | /* nmacchw - nmacchw. */ |
a750fc0b | 5915 | GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05); |
76a66253 | 5916 | /* nmacchwo - nmacchwo. */ |
a750fc0b | 5917 | GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15); |
76a66253 | 5918 | /* nmacchws - nmacchws. */ |
a750fc0b | 5919 | GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07); |
76a66253 | 5920 | /* nmacchwso - nmacchwso. */ |
a750fc0b | 5921 | GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17); |
76a66253 | 5922 | /* nmachhw - nmachhw. */ |
a750fc0b | 5923 | GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01); |
76a66253 | 5924 | /* nmachhwo - nmachhwo. */ |
a750fc0b | 5925 | GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11); |
76a66253 | 5926 | /* nmachhws - nmachhws. */ |
a750fc0b | 5927 | GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03); |
76a66253 | 5928 | /* nmachhwso - nmachhwso. */ |
a750fc0b | 5929 | GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13); |
76a66253 | 5930 | /* nmaclhw - nmaclhw. */ |
a750fc0b | 5931 | GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D); |
76a66253 | 5932 | /* nmaclhwo - nmaclhwo. */ |
a750fc0b | 5933 | GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D); |
76a66253 | 5934 | /* nmaclhws - nmaclhws. */ |
a750fc0b | 5935 | GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F); |
76a66253 | 5936 | /* nmaclhwso - nmaclhwso. */ |
a750fc0b | 5937 | GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F); |
76a66253 JM |
5938 | |
5939 | /* mulchw - mulchw. */ | |
a750fc0b | 5940 | GEN_MAC_HANDLER(mulchw, 0x08, 0x05); |
76a66253 | 5941 | /* mulchwu - mulchwu. */ |
a750fc0b | 5942 | GEN_MAC_HANDLER(mulchwu, 0x08, 0x04); |
76a66253 | 5943 | /* mulhhw - mulhhw. */ |
a750fc0b | 5944 | GEN_MAC_HANDLER(mulhhw, 0x08, 0x01); |
76a66253 | 5945 | /* mulhhwu - mulhhwu. */ |
a750fc0b | 5946 | GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00); |
76a66253 | 5947 | /* mullhw - mullhw. */ |
a750fc0b | 5948 | GEN_MAC_HANDLER(mullhw, 0x08, 0x0D); |
76a66253 | 5949 | /* mullhwu - mullhwu. */ |
a750fc0b | 5950 | GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C); |
76a66253 JM |
5951 | |
5952 | /* mfdcr */ | |
99e300ef | 5953 | static void gen_mfdcr(DisasContext *ctx) |
76a66253 JM |
5954 | { |
5955 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5956 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 | 5957 | #else |
06dca6a7 | 5958 | TCGv dcrn; |
76db3ba4 | 5959 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5960 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 JM |
5961 | return; |
5962 | } | |
06dca6a7 AJ |
5963 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5964 | gen_update_nip(ctx, ctx->nip - 4); | |
5965 | dcrn = tcg_const_tl(SPR(ctx->opcode)); | |
d0f1562d | 5966 | gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, dcrn); |
06dca6a7 | 5967 | tcg_temp_free(dcrn); |
76a66253 JM |
5968 | #endif |
5969 | } | |
5970 | ||
5971 | /* mtdcr */ | |
99e300ef | 5972 | static void gen_mtdcr(DisasContext *ctx) |
76a66253 JM |
5973 | { |
5974 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5975 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 | 5976 | #else |
06dca6a7 | 5977 | TCGv dcrn; |
76db3ba4 | 5978 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5979 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
76a66253 JM |
5980 | return; |
5981 | } | |
06dca6a7 AJ |
5982 | /* NIP cannot be restored if the memory exception comes from an helper */ |
5983 | gen_update_nip(ctx, ctx->nip - 4); | |
5984 | dcrn = tcg_const_tl(SPR(ctx->opcode)); | |
d0f1562d | 5985 | gen_helper_store_dcr(cpu_env, dcrn, cpu_gpr[rS(ctx->opcode)]); |
06dca6a7 | 5986 | tcg_temp_free(dcrn); |
a42bd6cc JM |
5987 | #endif |
5988 | } | |
5989 | ||
5990 | /* mfdcrx */ | |
2662a059 | 5991 | /* XXX: not implemented on 440 ? */ |
99e300ef | 5992 | static void gen_mfdcrx(DisasContext *ctx) |
a42bd6cc JM |
5993 | { |
5994 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 5995 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
a42bd6cc | 5996 | #else |
76db3ba4 | 5997 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 5998 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
a42bd6cc JM |
5999 | return; |
6000 | } | |
06dca6a7 AJ |
6001 | /* NIP cannot be restored if the memory exception comes from an helper */ |
6002 | gen_update_nip(ctx, ctx->nip - 4); | |
d0f1562d BS |
6003 | gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, |
6004 | cpu_gpr[rA(ctx->opcode)]); | |
a750fc0b | 6005 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
a42bd6cc JM |
6006 | #endif |
6007 | } | |
6008 | ||
6009 | /* mtdcrx */ | |
2662a059 | 6010 | /* XXX: not implemented on 440 ? */ |
99e300ef | 6011 | static void gen_mtdcrx(DisasContext *ctx) |
a42bd6cc JM |
6012 | { |
6013 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6014 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
a42bd6cc | 6015 | #else |
76db3ba4 | 6016 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6017 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_REG); |
a42bd6cc JM |
6018 | return; |
6019 | } | |
06dca6a7 AJ |
6020 | /* NIP cannot be restored if the memory exception comes from an helper */ |
6021 | gen_update_nip(ctx, ctx->nip - 4); | |
d0f1562d BS |
6022 | gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)], |
6023 | cpu_gpr[rS(ctx->opcode)]); | |
a750fc0b | 6024 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
76a66253 JM |
6025 | #endif |
6026 | } | |
6027 | ||
a750fc0b | 6028 | /* mfdcrux (PPC 460) : user-mode access to DCR */ |
99e300ef | 6029 | static void gen_mfdcrux(DisasContext *ctx) |
a750fc0b | 6030 | { |
06dca6a7 AJ |
6031 | /* NIP cannot be restored if the memory exception comes from an helper */ |
6032 | gen_update_nip(ctx, ctx->nip - 4); | |
d0f1562d BS |
6033 | gen_helper_load_dcr(cpu_gpr[rD(ctx->opcode)], cpu_env, |
6034 | cpu_gpr[rA(ctx->opcode)]); | |
a750fc0b JM |
6035 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
6036 | } | |
6037 | ||
6038 | /* mtdcrux (PPC 460) : user-mode access to DCR */ | |
99e300ef | 6039 | static void gen_mtdcrux(DisasContext *ctx) |
a750fc0b | 6040 | { |
06dca6a7 AJ |
6041 | /* NIP cannot be restored if the memory exception comes from an helper */ |
6042 | gen_update_nip(ctx, ctx->nip - 4); | |
975e5463 | 6043 | gen_helper_store_dcr(cpu_env, cpu_gpr[rA(ctx->opcode)], |
d0f1562d | 6044 | cpu_gpr[rS(ctx->opcode)]); |
a750fc0b JM |
6045 | /* Note: Rc update flag set leads to undefined state of Rc0 */ |
6046 | } | |
6047 | ||
76a66253 | 6048 | /* dccci */ |
99e300ef | 6049 | static void gen_dccci(DisasContext *ctx) |
76a66253 JM |
6050 | { |
6051 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6052 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6053 | #else |
76db3ba4 | 6054 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6055 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6056 | return; |
6057 | } | |
6058 | /* interpreted as no-op */ | |
6059 | #endif | |
6060 | } | |
6061 | ||
6062 | /* dcread */ | |
99e300ef | 6063 | static void gen_dcread(DisasContext *ctx) |
76a66253 JM |
6064 | { |
6065 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6066 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6067 | #else |
b61f2753 | 6068 | TCGv EA, val; |
76db3ba4 | 6069 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6070 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6071 | return; |
6072 | } | |
76db3ba4 | 6073 | gen_set_access_type(ctx, ACCESS_CACHE); |
a7812ae4 | 6074 | EA = tcg_temp_new(); |
76db3ba4 | 6075 | gen_addr_reg_index(ctx, EA); |
a7812ae4 | 6076 | val = tcg_temp_new(); |
76db3ba4 | 6077 | gen_qemu_ld32u(ctx, val, EA); |
b61f2753 AJ |
6078 | tcg_temp_free(val); |
6079 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], EA); | |
6080 | tcg_temp_free(EA); | |
76a66253 JM |
6081 | #endif |
6082 | } | |
6083 | ||
6084 | /* icbt */ | |
e8eaa2c0 | 6085 | static void gen_icbt_40x(DisasContext *ctx) |
76a66253 JM |
6086 | { |
6087 | /* interpreted as no-op */ | |
6088 | /* XXX: specification say this is treated as a load by the MMU | |
6089 | * but does not generate any exception | |
6090 | */ | |
6091 | } | |
6092 | ||
6093 | /* iccci */ | |
99e300ef | 6094 | static void gen_iccci(DisasContext *ctx) |
76a66253 JM |
6095 | { |
6096 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6097 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6098 | #else |
76db3ba4 | 6099 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6100 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6101 | return; |
6102 | } | |
6103 | /* interpreted as no-op */ | |
6104 | #endif | |
6105 | } | |
6106 | ||
6107 | /* icread */ | |
99e300ef | 6108 | static void gen_icread(DisasContext *ctx) |
76a66253 JM |
6109 | { |
6110 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6111 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6112 | #else |
76db3ba4 | 6113 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6114 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6115 | return; |
6116 | } | |
6117 | /* interpreted as no-op */ | |
6118 | #endif | |
6119 | } | |
6120 | ||
76db3ba4 | 6121 | /* rfci (mem_idx only) */ |
e8eaa2c0 | 6122 | static void gen_rfci_40x(DisasContext *ctx) |
a42bd6cc JM |
6123 | { |
6124 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6125 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc | 6126 | #else |
76db3ba4 | 6127 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6128 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc JM |
6129 | return; |
6130 | } | |
6131 | /* Restore CPU state */ | |
e5f17ac6 | 6132 | gen_helper_40x_rfci(cpu_env); |
e06fcd75 | 6133 | gen_sync_exception(ctx); |
a42bd6cc JM |
6134 | #endif |
6135 | } | |
6136 | ||
99e300ef | 6137 | static void gen_rfci(DisasContext *ctx) |
a42bd6cc JM |
6138 | { |
6139 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6140 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc | 6141 | #else |
76db3ba4 | 6142 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6143 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc JM |
6144 | return; |
6145 | } | |
6146 | /* Restore CPU state */ | |
e5f17ac6 | 6147 | gen_helper_rfci(cpu_env); |
e06fcd75 | 6148 | gen_sync_exception(ctx); |
a42bd6cc JM |
6149 | #endif |
6150 | } | |
6151 | ||
6152 | /* BookE specific */ | |
99e300ef | 6153 | |
54623277 | 6154 | /* XXX: not implemented on 440 ? */ |
99e300ef | 6155 | static void gen_rfdi(DisasContext *ctx) |
76a66253 JM |
6156 | { |
6157 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6158 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6159 | #else |
76db3ba4 | 6160 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6161 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6162 | return; |
6163 | } | |
6164 | /* Restore CPU state */ | |
e5f17ac6 | 6165 | gen_helper_rfdi(cpu_env); |
e06fcd75 | 6166 | gen_sync_exception(ctx); |
76a66253 JM |
6167 | #endif |
6168 | } | |
6169 | ||
2662a059 | 6170 | /* XXX: not implemented on 440 ? */ |
99e300ef | 6171 | static void gen_rfmci(DisasContext *ctx) |
a42bd6cc JM |
6172 | { |
6173 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6174 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc | 6175 | #else |
76db3ba4 | 6176 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6177 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
a42bd6cc JM |
6178 | return; |
6179 | } | |
6180 | /* Restore CPU state */ | |
e5f17ac6 | 6181 | gen_helper_rfmci(cpu_env); |
e06fcd75 | 6182 | gen_sync_exception(ctx); |
a42bd6cc JM |
6183 | #endif |
6184 | } | |
5eb7995e | 6185 | |
d9bce9d9 | 6186 | /* TLB management - PowerPC 405 implementation */ |
e8eaa2c0 | 6187 | |
54623277 | 6188 | /* tlbre */ |
e8eaa2c0 | 6189 | static void gen_tlbre_40x(DisasContext *ctx) |
76a66253 JM |
6190 | { |
6191 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6192 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6193 | #else |
76db3ba4 | 6194 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6195 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6196 | return; |
6197 | } | |
6198 | switch (rB(ctx->opcode)) { | |
6199 | case 0: | |
c6c7cf05 BS |
6200 | gen_helper_4xx_tlbre_hi(cpu_gpr[rD(ctx->opcode)], cpu_env, |
6201 | cpu_gpr[rA(ctx->opcode)]); | |
76a66253 JM |
6202 | break; |
6203 | case 1: | |
c6c7cf05 BS |
6204 | gen_helper_4xx_tlbre_lo(cpu_gpr[rD(ctx->opcode)], cpu_env, |
6205 | cpu_gpr[rA(ctx->opcode)]); | |
76a66253 JM |
6206 | break; |
6207 | default: | |
e06fcd75 | 6208 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 | 6209 | break; |
9a64fbe4 | 6210 | } |
76a66253 JM |
6211 | #endif |
6212 | } | |
6213 | ||
d9bce9d9 | 6214 | /* tlbsx - tlbsx. */ |
e8eaa2c0 | 6215 | static void gen_tlbsx_40x(DisasContext *ctx) |
76a66253 JM |
6216 | { |
6217 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6218 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6219 | #else |
74d37793 | 6220 | TCGv t0; |
76db3ba4 | 6221 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6222 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6223 | return; |
6224 | } | |
74d37793 | 6225 | t0 = tcg_temp_new(); |
76db3ba4 | 6226 | gen_addr_reg_index(ctx, t0); |
c6c7cf05 | 6227 | gen_helper_4xx_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 AJ |
6228 | tcg_temp_free(t0); |
6229 | if (Rc(ctx->opcode)) { | |
6230 | int l1 = gen_new_label(); | |
da91a00f | 6231 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so); |
74d37793 AJ |
6232 | tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1); |
6233 | tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02); | |
6234 | gen_set_label(l1); | |
6235 | } | |
76a66253 | 6236 | #endif |
79aceca5 FB |
6237 | } |
6238 | ||
76a66253 | 6239 | /* tlbwe */ |
e8eaa2c0 | 6240 | static void gen_tlbwe_40x(DisasContext *ctx) |
79aceca5 | 6241 | { |
76a66253 | 6242 | #if defined(CONFIG_USER_ONLY) |
e06fcd75 | 6243 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6244 | #else |
76db3ba4 | 6245 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6246 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6247 | return; |
6248 | } | |
6249 | switch (rB(ctx->opcode)) { | |
6250 | case 0: | |
c6c7cf05 BS |
6251 | gen_helper_4xx_tlbwe_hi(cpu_env, cpu_gpr[rA(ctx->opcode)], |
6252 | cpu_gpr[rS(ctx->opcode)]); | |
76a66253 JM |
6253 | break; |
6254 | case 1: | |
c6c7cf05 BS |
6255 | gen_helper_4xx_tlbwe_lo(cpu_env, cpu_gpr[rA(ctx->opcode)], |
6256 | cpu_gpr[rS(ctx->opcode)]); | |
76a66253 JM |
6257 | break; |
6258 | default: | |
e06fcd75 | 6259 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
76a66253 | 6260 | break; |
9a64fbe4 | 6261 | } |
76a66253 JM |
6262 | #endif |
6263 | } | |
6264 | ||
a4bb6c3e | 6265 | /* TLB management - PowerPC 440 implementation */ |
e8eaa2c0 | 6266 | |
54623277 | 6267 | /* tlbre */ |
e8eaa2c0 | 6268 | static void gen_tlbre_440(DisasContext *ctx) |
5eb7995e JM |
6269 | { |
6270 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6271 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e | 6272 | #else |
76db3ba4 | 6273 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6274 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e JM |
6275 | return; |
6276 | } | |
6277 | switch (rB(ctx->opcode)) { | |
6278 | case 0: | |
5eb7995e | 6279 | case 1: |
5eb7995e | 6280 | case 2: |
74d37793 AJ |
6281 | { |
6282 | TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode)); | |
c6c7cf05 BS |
6283 | gen_helper_440_tlbre(cpu_gpr[rD(ctx->opcode)], cpu_env, |
6284 | t0, cpu_gpr[rA(ctx->opcode)]); | |
74d37793 AJ |
6285 | tcg_temp_free_i32(t0); |
6286 | } | |
5eb7995e JM |
6287 | break; |
6288 | default: | |
e06fcd75 | 6289 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
5eb7995e JM |
6290 | break; |
6291 | } | |
6292 | #endif | |
6293 | } | |
6294 | ||
6295 | /* tlbsx - tlbsx. */ | |
e8eaa2c0 | 6296 | static void gen_tlbsx_440(DisasContext *ctx) |
5eb7995e JM |
6297 | { |
6298 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6299 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e | 6300 | #else |
74d37793 | 6301 | TCGv t0; |
76db3ba4 | 6302 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6303 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e JM |
6304 | return; |
6305 | } | |
74d37793 | 6306 | t0 = tcg_temp_new(); |
76db3ba4 | 6307 | gen_addr_reg_index(ctx, t0); |
c6c7cf05 | 6308 | gen_helper_440_tlbsx(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); |
74d37793 AJ |
6309 | tcg_temp_free(t0); |
6310 | if (Rc(ctx->opcode)) { | |
6311 | int l1 = gen_new_label(); | |
da91a00f | 6312 | tcg_gen_trunc_tl_i32(cpu_crf[0], cpu_so); |
74d37793 AJ |
6313 | tcg_gen_brcondi_tl(TCG_COND_EQ, cpu_gpr[rD(ctx->opcode)], -1, l1); |
6314 | tcg_gen_ori_i32(cpu_crf[0], cpu_crf[0], 0x02); | |
6315 | gen_set_label(l1); | |
6316 | } | |
5eb7995e JM |
6317 | #endif |
6318 | } | |
6319 | ||
6320 | /* tlbwe */ | |
e8eaa2c0 | 6321 | static void gen_tlbwe_440(DisasContext *ctx) |
5eb7995e JM |
6322 | { |
6323 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6324 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e | 6325 | #else |
76db3ba4 | 6326 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6327 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
5eb7995e JM |
6328 | return; |
6329 | } | |
6330 | switch (rB(ctx->opcode)) { | |
6331 | case 0: | |
5eb7995e | 6332 | case 1: |
5eb7995e | 6333 | case 2: |
74d37793 AJ |
6334 | { |
6335 | TCGv_i32 t0 = tcg_const_i32(rB(ctx->opcode)); | |
c6c7cf05 BS |
6336 | gen_helper_440_tlbwe(cpu_env, t0, cpu_gpr[rA(ctx->opcode)], |
6337 | cpu_gpr[rS(ctx->opcode)]); | |
74d37793 AJ |
6338 | tcg_temp_free_i32(t0); |
6339 | } | |
5eb7995e JM |
6340 | break; |
6341 | default: | |
e06fcd75 | 6342 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
5eb7995e JM |
6343 | break; |
6344 | } | |
6345 | #endif | |
6346 | } | |
6347 | ||
01662f3e AG |
6348 | /* TLB management - PowerPC BookE 2.06 implementation */ |
6349 | ||
6350 | /* tlbre */ | |
6351 | static void gen_tlbre_booke206(DisasContext *ctx) | |
6352 | { | |
6353 | #if defined(CONFIG_USER_ONLY) | |
6354 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6355 | #else | |
6356 | if (unlikely(!ctx->mem_idx)) { | |
6357 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6358 | return; | |
6359 | } | |
6360 | ||
c6c7cf05 | 6361 | gen_helper_booke206_tlbre(cpu_env); |
01662f3e AG |
6362 | #endif |
6363 | } | |
6364 | ||
6365 | /* tlbsx - tlbsx. */ | |
6366 | static void gen_tlbsx_booke206(DisasContext *ctx) | |
6367 | { | |
6368 | #if defined(CONFIG_USER_ONLY) | |
6369 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6370 | #else | |
6371 | TCGv t0; | |
6372 | if (unlikely(!ctx->mem_idx)) { | |
6373 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6374 | return; | |
6375 | } | |
6376 | ||
6377 | if (rA(ctx->opcode)) { | |
6378 | t0 = tcg_temp_new(); | |
6379 | tcg_gen_mov_tl(t0, cpu_gpr[rD(ctx->opcode)]); | |
6380 | } else { | |
6381 | t0 = tcg_const_tl(0); | |
6382 | } | |
6383 | ||
6384 | tcg_gen_add_tl(t0, t0, cpu_gpr[rB(ctx->opcode)]); | |
c6c7cf05 | 6385 | gen_helper_booke206_tlbsx(cpu_env, t0); |
01662f3e AG |
6386 | #endif |
6387 | } | |
6388 | ||
6389 | /* tlbwe */ | |
6390 | static void gen_tlbwe_booke206(DisasContext *ctx) | |
6391 | { | |
6392 | #if defined(CONFIG_USER_ONLY) | |
6393 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6394 | #else | |
6395 | if (unlikely(!ctx->mem_idx)) { | |
6396 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6397 | return; | |
6398 | } | |
3f162d11 | 6399 | gen_update_nip(ctx, ctx->nip - 4); |
c6c7cf05 | 6400 | gen_helper_booke206_tlbwe(cpu_env); |
01662f3e AG |
6401 | #endif |
6402 | } | |
6403 | ||
6404 | static void gen_tlbivax_booke206(DisasContext *ctx) | |
6405 | { | |
6406 | #if defined(CONFIG_USER_ONLY) | |
6407 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6408 | #else | |
6409 | TCGv t0; | |
6410 | if (unlikely(!ctx->mem_idx)) { | |
6411 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6412 | return; | |
6413 | } | |
6414 | ||
6415 | t0 = tcg_temp_new(); | |
6416 | gen_addr_reg_index(ctx, t0); | |
6417 | ||
c6c7cf05 | 6418 | gen_helper_booke206_tlbivax(cpu_env, t0); |
01662f3e AG |
6419 | #endif |
6420 | } | |
6421 | ||
6d3db821 AG |
6422 | static void gen_tlbilx_booke206(DisasContext *ctx) |
6423 | { | |
6424 | #if defined(CONFIG_USER_ONLY) | |
6425 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6426 | #else | |
6427 | TCGv t0; | |
6428 | if (unlikely(!ctx->mem_idx)) { | |
6429 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6430 | return; | |
6431 | } | |
6432 | ||
6433 | t0 = tcg_temp_new(); | |
6434 | gen_addr_reg_index(ctx, t0); | |
6435 | ||
6436 | switch((ctx->opcode >> 21) & 0x3) { | |
6437 | case 0: | |
c6c7cf05 | 6438 | gen_helper_booke206_tlbilx0(cpu_env, t0); |
6d3db821 AG |
6439 | break; |
6440 | case 1: | |
c6c7cf05 | 6441 | gen_helper_booke206_tlbilx1(cpu_env, t0); |
6d3db821 AG |
6442 | break; |
6443 | case 3: | |
c6c7cf05 | 6444 | gen_helper_booke206_tlbilx3(cpu_env, t0); |
6d3db821 AG |
6445 | break; |
6446 | default: | |
6447 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); | |
6448 | break; | |
6449 | } | |
6450 | ||
6451 | tcg_temp_free(t0); | |
6452 | #endif | |
6453 | } | |
6454 | ||
01662f3e | 6455 | |
76a66253 | 6456 | /* wrtee */ |
99e300ef | 6457 | static void gen_wrtee(DisasContext *ctx) |
76a66253 JM |
6458 | { |
6459 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6460 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6461 | #else |
6527f6ea | 6462 | TCGv t0; |
76db3ba4 | 6463 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6464 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6465 | return; |
6466 | } | |
6527f6ea AJ |
6467 | t0 = tcg_temp_new(); |
6468 | tcg_gen_andi_tl(t0, cpu_gpr[rD(ctx->opcode)], (1 << MSR_EE)); | |
6469 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE)); | |
6470 | tcg_gen_or_tl(cpu_msr, cpu_msr, t0); | |
6471 | tcg_temp_free(t0); | |
dee96f6c JM |
6472 | /* Stop translation to have a chance to raise an exception |
6473 | * if we just set msr_ee to 1 | |
6474 | */ | |
e06fcd75 | 6475 | gen_stop_exception(ctx); |
76a66253 JM |
6476 | #endif |
6477 | } | |
6478 | ||
6479 | /* wrteei */ | |
99e300ef | 6480 | static void gen_wrteei(DisasContext *ctx) |
76a66253 JM |
6481 | { |
6482 | #if defined(CONFIG_USER_ONLY) | |
e06fcd75 | 6483 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 | 6484 | #else |
76db3ba4 | 6485 | if (unlikely(!ctx->mem_idx)) { |
e06fcd75 | 6486 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); |
76a66253 JM |
6487 | return; |
6488 | } | |
fbe73008 | 6489 | if (ctx->opcode & 0x00008000) { |
6527f6ea AJ |
6490 | tcg_gen_ori_tl(cpu_msr, cpu_msr, (1 << MSR_EE)); |
6491 | /* Stop translation to have a chance to raise an exception */ | |
e06fcd75 | 6492 | gen_stop_exception(ctx); |
6527f6ea | 6493 | } else { |
1b6e5f99 | 6494 | tcg_gen_andi_tl(cpu_msr, cpu_msr, ~(1 << MSR_EE)); |
6527f6ea | 6495 | } |
76a66253 JM |
6496 | #endif |
6497 | } | |
6498 | ||
08e46e54 | 6499 | /* PowerPC 440 specific instructions */ |
99e300ef | 6500 | |
54623277 | 6501 | /* dlmzb */ |
99e300ef | 6502 | static void gen_dlmzb(DisasContext *ctx) |
76a66253 | 6503 | { |
ef0d51af | 6504 | TCGv_i32 t0 = tcg_const_i32(Rc(ctx->opcode)); |
d15f74fb BS |
6505 | gen_helper_dlmzb(cpu_gpr[rA(ctx->opcode)], cpu_env, |
6506 | cpu_gpr[rS(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], t0); | |
ef0d51af | 6507 | tcg_temp_free_i32(t0); |
76a66253 JM |
6508 | } |
6509 | ||
6510 | /* mbar replaces eieio on 440 */ | |
99e300ef | 6511 | static void gen_mbar(DisasContext *ctx) |
76a66253 JM |
6512 | { |
6513 | /* interpreted as no-op */ | |
6514 | } | |
6515 | ||
6516 | /* msync replaces sync on 440 */ | |
dcb2b9e1 | 6517 | static void gen_msync_4xx(DisasContext *ctx) |
76a66253 JM |
6518 | { |
6519 | /* interpreted as no-op */ | |
6520 | } | |
6521 | ||
6522 | /* icbt */ | |
e8eaa2c0 | 6523 | static void gen_icbt_440(DisasContext *ctx) |
76a66253 JM |
6524 | { |
6525 | /* interpreted as no-op */ | |
6526 | /* XXX: specification say this is treated as a load by the MMU | |
6527 | * but does not generate any exception | |
6528 | */ | |
79aceca5 FB |
6529 | } |
6530 | ||
9e0b5cb1 AG |
6531 | /* Embedded.Processor Control */ |
6532 | ||
6533 | static void gen_msgclr(DisasContext *ctx) | |
6534 | { | |
6535 | #if defined(CONFIG_USER_ONLY) | |
6536 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6537 | #else | |
6538 | if (unlikely(ctx->mem_idx == 0)) { | |
6539 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6540 | return; | |
6541 | } | |
6542 | ||
e5f17ac6 | 6543 | gen_helper_msgclr(cpu_env, cpu_gpr[rB(ctx->opcode)]); |
9e0b5cb1 AG |
6544 | #endif |
6545 | } | |
6546 | ||
d5d11a39 AG |
6547 | static void gen_msgsnd(DisasContext *ctx) |
6548 | { | |
6549 | #if defined(CONFIG_USER_ONLY) | |
6550 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6551 | #else | |
6552 | if (unlikely(ctx->mem_idx == 0)) { | |
6553 | gen_inval_exception(ctx, POWERPC_EXCP_PRIV_OPC); | |
6554 | return; | |
6555 | } | |
6556 | ||
6557 | gen_helper_msgsnd(cpu_gpr[rB(ctx->opcode)]); | |
6558 | #endif | |
6559 | } | |
6560 | ||
a9d9eb8f JM |
6561 | /*** Altivec vector extension ***/ |
6562 | /* Altivec registers moves */ | |
a9d9eb8f | 6563 | |
636aa200 | 6564 | static inline TCGv_ptr gen_avr_ptr(int reg) |
564e571a | 6565 | { |
e4704b3b | 6566 | TCGv_ptr r = tcg_temp_new_ptr(); |
564e571a AJ |
6567 | tcg_gen_addi_ptr(r, cpu_env, offsetof(CPUPPCState, avr[reg])); |
6568 | return r; | |
6569 | } | |
6570 | ||
a9d9eb8f | 6571 | #define GEN_VR_LDX(name, opc2, opc3) \ |
99e300ef | 6572 | static void glue(gen_, name)(DisasContext *ctx) \ |
a9d9eb8f | 6573 | { \ |
fe1e5c53 | 6574 | TCGv EA; \ |
a9d9eb8f | 6575 | if (unlikely(!ctx->altivec_enabled)) { \ |
e06fcd75 | 6576 | gen_exception(ctx, POWERPC_EXCP_VPU); \ |
a9d9eb8f JM |
6577 | return; \ |
6578 | } \ | |
76db3ba4 | 6579 | gen_set_access_type(ctx, ACCESS_INT); \ |
fe1e5c53 | 6580 | EA = tcg_temp_new(); \ |
76db3ba4 | 6581 | gen_addr_reg_index(ctx, EA); \ |
fe1e5c53 | 6582 | tcg_gen_andi_tl(EA, EA, ~0xf); \ |
76db3ba4 AJ |
6583 | if (ctx->le_mode) { \ |
6584 | gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \ | |
fe1e5c53 | 6585 | tcg_gen_addi_tl(EA, EA, 8); \ |
76db3ba4 | 6586 | gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \ |
fe1e5c53 | 6587 | } else { \ |
76db3ba4 | 6588 | gen_qemu_ld64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \ |
fe1e5c53 | 6589 | tcg_gen_addi_tl(EA, EA, 8); \ |
76db3ba4 | 6590 | gen_qemu_ld64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \ |
fe1e5c53 AJ |
6591 | } \ |
6592 | tcg_temp_free(EA); \ | |
a9d9eb8f JM |
6593 | } |
6594 | ||
6595 | #define GEN_VR_STX(name, opc2, opc3) \ | |
99e300ef | 6596 | static void gen_st##name(DisasContext *ctx) \ |
a9d9eb8f | 6597 | { \ |
fe1e5c53 | 6598 | TCGv EA; \ |
a9d9eb8f | 6599 | if (unlikely(!ctx->altivec_enabled)) { \ |
e06fcd75 | 6600 | gen_exception(ctx, POWERPC_EXCP_VPU); \ |
a9d9eb8f JM |
6601 | return; \ |
6602 | } \ | |
76db3ba4 | 6603 | gen_set_access_type(ctx, ACCESS_INT); \ |
fe1e5c53 | 6604 | EA = tcg_temp_new(); \ |
76db3ba4 | 6605 | gen_addr_reg_index(ctx, EA); \ |
fe1e5c53 | 6606 | tcg_gen_andi_tl(EA, EA, ~0xf); \ |
76db3ba4 AJ |
6607 | if (ctx->le_mode) { \ |
6608 | gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \ | |
fe1e5c53 | 6609 | tcg_gen_addi_tl(EA, EA, 8); \ |
76db3ba4 | 6610 | gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \ |
fe1e5c53 | 6611 | } else { \ |
76db3ba4 | 6612 | gen_qemu_st64(ctx, cpu_avrh[rD(ctx->opcode)], EA); \ |
fe1e5c53 | 6613 | tcg_gen_addi_tl(EA, EA, 8); \ |
76db3ba4 | 6614 | gen_qemu_st64(ctx, cpu_avrl[rD(ctx->opcode)], EA); \ |
fe1e5c53 AJ |
6615 | } \ |
6616 | tcg_temp_free(EA); \ | |
a9d9eb8f JM |
6617 | } |
6618 | ||
cbfb6ae9 | 6619 | #define GEN_VR_LVE(name, opc2, opc3) \ |
99e300ef | 6620 | static void gen_lve##name(DisasContext *ctx) \ |
cbfb6ae9 AJ |
6621 | { \ |
6622 | TCGv EA; \ | |
6623 | TCGv_ptr rs; \ | |
6624 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6625 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6626 | return; \ | |
6627 | } \ | |
6628 | gen_set_access_type(ctx, ACCESS_INT); \ | |
6629 | EA = tcg_temp_new(); \ | |
6630 | gen_addr_reg_index(ctx, EA); \ | |
6631 | rs = gen_avr_ptr(rS(ctx->opcode)); \ | |
2f5a189c | 6632 | gen_helper_lve##name(cpu_env, rs, EA); \ |
cbfb6ae9 AJ |
6633 | tcg_temp_free(EA); \ |
6634 | tcg_temp_free_ptr(rs); \ | |
6635 | } | |
6636 | ||
6637 | #define GEN_VR_STVE(name, opc2, opc3) \ | |
99e300ef | 6638 | static void gen_stve##name(DisasContext *ctx) \ |
cbfb6ae9 AJ |
6639 | { \ |
6640 | TCGv EA; \ | |
6641 | TCGv_ptr rs; \ | |
6642 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6643 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6644 | return; \ | |
6645 | } \ | |
6646 | gen_set_access_type(ctx, ACCESS_INT); \ | |
6647 | EA = tcg_temp_new(); \ | |
6648 | gen_addr_reg_index(ctx, EA); \ | |
6649 | rs = gen_avr_ptr(rS(ctx->opcode)); \ | |
2f5a189c | 6650 | gen_helper_stve##name(cpu_env, rs, EA); \ |
cbfb6ae9 AJ |
6651 | tcg_temp_free(EA); \ |
6652 | tcg_temp_free_ptr(rs); \ | |
6653 | } | |
6654 | ||
fe1e5c53 | 6655 | GEN_VR_LDX(lvx, 0x07, 0x03); |
a9d9eb8f | 6656 | /* As we don't emulate the cache, lvxl is stricly equivalent to lvx */ |
fe1e5c53 | 6657 | GEN_VR_LDX(lvxl, 0x07, 0x0B); |
a9d9eb8f | 6658 | |
cbfb6ae9 AJ |
6659 | GEN_VR_LVE(bx, 0x07, 0x00); |
6660 | GEN_VR_LVE(hx, 0x07, 0x01); | |
6661 | GEN_VR_LVE(wx, 0x07, 0x02); | |
6662 | ||
fe1e5c53 | 6663 | GEN_VR_STX(svx, 0x07, 0x07); |
a9d9eb8f | 6664 | /* As we don't emulate the cache, stvxl is stricly equivalent to stvx */ |
fe1e5c53 | 6665 | GEN_VR_STX(svxl, 0x07, 0x0F); |
a9d9eb8f | 6666 | |
cbfb6ae9 AJ |
6667 | GEN_VR_STVE(bx, 0x07, 0x04); |
6668 | GEN_VR_STVE(hx, 0x07, 0x05); | |
6669 | GEN_VR_STVE(wx, 0x07, 0x06); | |
6670 | ||
99e300ef | 6671 | static void gen_lvsl(DisasContext *ctx) |
bf8d8ded AJ |
6672 | { |
6673 | TCGv_ptr rd; | |
6674 | TCGv EA; | |
6675 | if (unlikely(!ctx->altivec_enabled)) { | |
6676 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6677 | return; | |
6678 | } | |
6679 | EA = tcg_temp_new(); | |
6680 | gen_addr_reg_index(ctx, EA); | |
6681 | rd = gen_avr_ptr(rD(ctx->opcode)); | |
6682 | gen_helper_lvsl(rd, EA); | |
6683 | tcg_temp_free(EA); | |
6684 | tcg_temp_free_ptr(rd); | |
6685 | } | |
6686 | ||
99e300ef | 6687 | static void gen_lvsr(DisasContext *ctx) |
bf8d8ded AJ |
6688 | { |
6689 | TCGv_ptr rd; | |
6690 | TCGv EA; | |
6691 | if (unlikely(!ctx->altivec_enabled)) { | |
6692 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6693 | return; | |
6694 | } | |
6695 | EA = tcg_temp_new(); | |
6696 | gen_addr_reg_index(ctx, EA); | |
6697 | rd = gen_avr_ptr(rD(ctx->opcode)); | |
6698 | gen_helper_lvsr(rd, EA); | |
6699 | tcg_temp_free(EA); | |
6700 | tcg_temp_free_ptr(rd); | |
6701 | } | |
6702 | ||
99e300ef | 6703 | static void gen_mfvscr(DisasContext *ctx) |
785f451b AJ |
6704 | { |
6705 | TCGv_i32 t; | |
6706 | if (unlikely(!ctx->altivec_enabled)) { | |
6707 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6708 | return; | |
6709 | } | |
6710 | tcg_gen_movi_i64(cpu_avrh[rD(ctx->opcode)], 0); | |
6711 | t = tcg_temp_new_i32(); | |
1328c2bf | 6712 | tcg_gen_ld_i32(t, cpu_env, offsetof(CPUPPCState, vscr)); |
785f451b | 6713 | tcg_gen_extu_i32_i64(cpu_avrl[rD(ctx->opcode)], t); |
fce5ecb7 | 6714 | tcg_temp_free_i32(t); |
785f451b AJ |
6715 | } |
6716 | ||
99e300ef | 6717 | static void gen_mtvscr(DisasContext *ctx) |
785f451b | 6718 | { |
6e87b7c7 | 6719 | TCGv_ptr p; |
785f451b AJ |
6720 | if (unlikely(!ctx->altivec_enabled)) { |
6721 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
6722 | return; | |
6723 | } | |
6e87b7c7 | 6724 | p = gen_avr_ptr(rD(ctx->opcode)); |
d15f74fb | 6725 | gen_helper_mtvscr(cpu_env, p); |
6e87b7c7 | 6726 | tcg_temp_free_ptr(p); |
785f451b AJ |
6727 | } |
6728 | ||
7a9b96cf AJ |
6729 | /* Logical operations */ |
6730 | #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \ | |
99e300ef | 6731 | static void glue(gen_, name)(DisasContext *ctx) \ |
7a9b96cf AJ |
6732 | { \ |
6733 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6734 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6735 | return; \ | |
6736 | } \ | |
6737 | tcg_op(cpu_avrh[rD(ctx->opcode)], cpu_avrh[rA(ctx->opcode)], cpu_avrh[rB(ctx->opcode)]); \ | |
6738 | tcg_op(cpu_avrl[rD(ctx->opcode)], cpu_avrl[rA(ctx->opcode)], cpu_avrl[rB(ctx->opcode)]); \ | |
6739 | } | |
6740 | ||
6741 | GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16); | |
6742 | GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17); | |
6743 | GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18); | |
6744 | GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19); | |
6745 | GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20); | |
6746 | ||
8e27dd6f | 6747 | #define GEN_VXFORM(name, opc2, opc3) \ |
99e300ef | 6748 | static void glue(gen_, name)(DisasContext *ctx) \ |
8e27dd6f AJ |
6749 | { \ |
6750 | TCGv_ptr ra, rb, rd; \ | |
6751 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6752 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6753 | return; \ | |
6754 | } \ | |
6755 | ra = gen_avr_ptr(rA(ctx->opcode)); \ | |
6756 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6757 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6758 | gen_helper_##name (rd, ra, rb); \ | |
6759 | tcg_temp_free_ptr(ra); \ | |
6760 | tcg_temp_free_ptr(rb); \ | |
6761 | tcg_temp_free_ptr(rd); \ | |
6762 | } | |
6763 | ||
d15f74fb BS |
6764 | #define GEN_VXFORM_ENV(name, opc2, opc3) \ |
6765 | static void glue(gen_, name)(DisasContext *ctx) \ | |
6766 | { \ | |
6767 | TCGv_ptr ra, rb, rd; \ | |
6768 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6769 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6770 | return; \ | |
6771 | } \ | |
6772 | ra = gen_avr_ptr(rA(ctx->opcode)); \ | |
6773 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6774 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
54cddd21 | 6775 | gen_helper_##name(cpu_env, rd, ra, rb); \ |
d15f74fb BS |
6776 | tcg_temp_free_ptr(ra); \ |
6777 | tcg_temp_free_ptr(rb); \ | |
6778 | tcg_temp_free_ptr(rd); \ | |
6779 | } | |
6780 | ||
7872c51c AJ |
6781 | GEN_VXFORM(vaddubm, 0, 0); |
6782 | GEN_VXFORM(vadduhm, 0, 1); | |
6783 | GEN_VXFORM(vadduwm, 0, 2); | |
6784 | GEN_VXFORM(vsububm, 0, 16); | |
6785 | GEN_VXFORM(vsubuhm, 0, 17); | |
6786 | GEN_VXFORM(vsubuwm, 0, 18); | |
e4039339 AJ |
6787 | GEN_VXFORM(vmaxub, 1, 0); |
6788 | GEN_VXFORM(vmaxuh, 1, 1); | |
6789 | GEN_VXFORM(vmaxuw, 1, 2); | |
6790 | GEN_VXFORM(vmaxsb, 1, 4); | |
6791 | GEN_VXFORM(vmaxsh, 1, 5); | |
6792 | GEN_VXFORM(vmaxsw, 1, 6); | |
6793 | GEN_VXFORM(vminub, 1, 8); | |
6794 | GEN_VXFORM(vminuh, 1, 9); | |
6795 | GEN_VXFORM(vminuw, 1, 10); | |
6796 | GEN_VXFORM(vminsb, 1, 12); | |
6797 | GEN_VXFORM(vminsh, 1, 13); | |
6798 | GEN_VXFORM(vminsw, 1, 14); | |
fab3cbe9 AJ |
6799 | GEN_VXFORM(vavgub, 1, 16); |
6800 | GEN_VXFORM(vavguh, 1, 17); | |
6801 | GEN_VXFORM(vavguw, 1, 18); | |
6802 | GEN_VXFORM(vavgsb, 1, 20); | |
6803 | GEN_VXFORM(vavgsh, 1, 21); | |
6804 | GEN_VXFORM(vavgsw, 1, 22); | |
3b430048 AJ |
6805 | GEN_VXFORM(vmrghb, 6, 0); |
6806 | GEN_VXFORM(vmrghh, 6, 1); | |
6807 | GEN_VXFORM(vmrghw, 6, 2); | |
6808 | GEN_VXFORM(vmrglb, 6, 4); | |
6809 | GEN_VXFORM(vmrglh, 6, 5); | |
6810 | GEN_VXFORM(vmrglw, 6, 6); | |
2c277908 AJ |
6811 | GEN_VXFORM(vmuloub, 4, 0); |
6812 | GEN_VXFORM(vmulouh, 4, 1); | |
6813 | GEN_VXFORM(vmulosb, 4, 4); | |
6814 | GEN_VXFORM(vmulosh, 4, 5); | |
6815 | GEN_VXFORM(vmuleub, 4, 8); | |
6816 | GEN_VXFORM(vmuleuh, 4, 9); | |
6817 | GEN_VXFORM(vmulesb, 4, 12); | |
6818 | GEN_VXFORM(vmulesh, 4, 13); | |
d79f0809 AJ |
6819 | GEN_VXFORM(vslb, 2, 4); |
6820 | GEN_VXFORM(vslh, 2, 5); | |
6821 | GEN_VXFORM(vslw, 2, 6); | |
07ef34c3 AJ |
6822 | GEN_VXFORM(vsrb, 2, 8); |
6823 | GEN_VXFORM(vsrh, 2, 9); | |
6824 | GEN_VXFORM(vsrw, 2, 10); | |
6825 | GEN_VXFORM(vsrab, 2, 12); | |
6826 | GEN_VXFORM(vsrah, 2, 13); | |
6827 | GEN_VXFORM(vsraw, 2, 14); | |
7b239bec AJ |
6828 | GEN_VXFORM(vslo, 6, 16); |
6829 | GEN_VXFORM(vsro, 6, 17); | |
e343da72 AJ |
6830 | GEN_VXFORM(vaddcuw, 0, 6); |
6831 | GEN_VXFORM(vsubcuw, 0, 22); | |
d15f74fb BS |
6832 | GEN_VXFORM_ENV(vaddubs, 0, 8); |
6833 | GEN_VXFORM_ENV(vadduhs, 0, 9); | |
6834 | GEN_VXFORM_ENV(vadduws, 0, 10); | |
6835 | GEN_VXFORM_ENV(vaddsbs, 0, 12); | |
6836 | GEN_VXFORM_ENV(vaddshs, 0, 13); | |
6837 | GEN_VXFORM_ENV(vaddsws, 0, 14); | |
6838 | GEN_VXFORM_ENV(vsububs, 0, 24); | |
6839 | GEN_VXFORM_ENV(vsubuhs, 0, 25); | |
6840 | GEN_VXFORM_ENV(vsubuws, 0, 26); | |
6841 | GEN_VXFORM_ENV(vsubsbs, 0, 28); | |
6842 | GEN_VXFORM_ENV(vsubshs, 0, 29); | |
6843 | GEN_VXFORM_ENV(vsubsws, 0, 30); | |
5e1d0985 AJ |
6844 | GEN_VXFORM(vrlb, 2, 0); |
6845 | GEN_VXFORM(vrlh, 2, 1); | |
6846 | GEN_VXFORM(vrlw, 2, 2); | |
d9430add AJ |
6847 | GEN_VXFORM(vsl, 2, 7); |
6848 | GEN_VXFORM(vsr, 2, 11); | |
d15f74fb BS |
6849 | GEN_VXFORM_ENV(vpkuhum, 7, 0); |
6850 | GEN_VXFORM_ENV(vpkuwum, 7, 1); | |
6851 | GEN_VXFORM_ENV(vpkuhus, 7, 2); | |
6852 | GEN_VXFORM_ENV(vpkuwus, 7, 3); | |
6853 | GEN_VXFORM_ENV(vpkshus, 7, 4); | |
6854 | GEN_VXFORM_ENV(vpkswus, 7, 5); | |
6855 | GEN_VXFORM_ENV(vpkshss, 7, 6); | |
6856 | GEN_VXFORM_ENV(vpkswss, 7, 7); | |
1dd9ffb9 | 6857 | GEN_VXFORM(vpkpx, 7, 12); |
d15f74fb BS |
6858 | GEN_VXFORM_ENV(vsum4ubs, 4, 24); |
6859 | GEN_VXFORM_ENV(vsum4sbs, 4, 28); | |
6860 | GEN_VXFORM_ENV(vsum4shs, 4, 25); | |
6861 | GEN_VXFORM_ENV(vsum2sws, 4, 26); | |
6862 | GEN_VXFORM_ENV(vsumsws, 4, 30); | |
6863 | GEN_VXFORM_ENV(vaddfp, 5, 0); | |
6864 | GEN_VXFORM_ENV(vsubfp, 5, 1); | |
6865 | GEN_VXFORM_ENV(vmaxfp, 5, 16); | |
6866 | GEN_VXFORM_ENV(vminfp, 5, 17); | |
fab3cbe9 | 6867 | |
0cbcd906 | 6868 | #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \ |
e8eaa2c0 | 6869 | static void glue(gen_, name)(DisasContext *ctx) \ |
0cbcd906 AJ |
6870 | { \ |
6871 | TCGv_ptr ra, rb, rd; \ | |
6872 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6873 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6874 | return; \ | |
6875 | } \ | |
6876 | ra = gen_avr_ptr(rA(ctx->opcode)); \ | |
6877 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6878 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
d15f74fb | 6879 | gen_helper_##opname(cpu_env, rd, ra, rb); \ |
0cbcd906 AJ |
6880 | tcg_temp_free_ptr(ra); \ |
6881 | tcg_temp_free_ptr(rb); \ | |
6882 | tcg_temp_free_ptr(rd); \ | |
6883 | } | |
6884 | ||
6885 | #define GEN_VXRFORM(name, opc2, opc3) \ | |
6886 | GEN_VXRFORM1(name, name, #name, opc2, opc3) \ | |
6887 | GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4))) | |
6888 | ||
1add6e23 AJ |
6889 | GEN_VXRFORM(vcmpequb, 3, 0) |
6890 | GEN_VXRFORM(vcmpequh, 3, 1) | |
6891 | GEN_VXRFORM(vcmpequw, 3, 2) | |
6892 | GEN_VXRFORM(vcmpgtsb, 3, 12) | |
6893 | GEN_VXRFORM(vcmpgtsh, 3, 13) | |
6894 | GEN_VXRFORM(vcmpgtsw, 3, 14) | |
6895 | GEN_VXRFORM(vcmpgtub, 3, 8) | |
6896 | GEN_VXRFORM(vcmpgtuh, 3, 9) | |
6897 | GEN_VXRFORM(vcmpgtuw, 3, 10) | |
819ca121 AJ |
6898 | GEN_VXRFORM(vcmpeqfp, 3, 3) |
6899 | GEN_VXRFORM(vcmpgefp, 3, 7) | |
6900 | GEN_VXRFORM(vcmpgtfp, 3, 11) | |
6901 | GEN_VXRFORM(vcmpbfp, 3, 15) | |
1add6e23 | 6902 | |
c026766b | 6903 | #define GEN_VXFORM_SIMM(name, opc2, opc3) \ |
99e300ef | 6904 | static void glue(gen_, name)(DisasContext *ctx) \ |
c026766b AJ |
6905 | { \ |
6906 | TCGv_ptr rd; \ | |
6907 | TCGv_i32 simm; \ | |
6908 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6909 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6910 | return; \ | |
6911 | } \ | |
6912 | simm = tcg_const_i32(SIMM5(ctx->opcode)); \ | |
6913 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6914 | gen_helper_##name (rd, simm); \ | |
6915 | tcg_temp_free_i32(simm); \ | |
6916 | tcg_temp_free_ptr(rd); \ | |
6917 | } | |
6918 | ||
6919 | GEN_VXFORM_SIMM(vspltisb, 6, 12); | |
6920 | GEN_VXFORM_SIMM(vspltish, 6, 13); | |
6921 | GEN_VXFORM_SIMM(vspltisw, 6, 14); | |
6922 | ||
de5f2484 | 6923 | #define GEN_VXFORM_NOA(name, opc2, opc3) \ |
99e300ef | 6924 | static void glue(gen_, name)(DisasContext *ctx) \ |
de5f2484 AJ |
6925 | { \ |
6926 | TCGv_ptr rb, rd; \ | |
6927 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6928 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6929 | return; \ | |
6930 | } \ | |
6931 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6932 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6933 | gen_helper_##name (rd, rb); \ | |
6934 | tcg_temp_free_ptr(rb); \ | |
6935 | tcg_temp_free_ptr(rd); \ | |
6936 | } | |
6937 | ||
d15f74fb BS |
6938 | #define GEN_VXFORM_NOA_ENV(name, opc2, opc3) \ |
6939 | static void glue(gen_, name)(DisasContext *ctx) \ | |
6940 | { \ | |
6941 | TCGv_ptr rb, rd; \ | |
6942 | \ | |
6943 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6944 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6945 | return; \ | |
6946 | } \ | |
6947 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6948 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6949 | gen_helper_##name(cpu_env, rd, rb); \ | |
6950 | tcg_temp_free_ptr(rb); \ | |
6951 | tcg_temp_free_ptr(rd); \ | |
6952 | } | |
6953 | ||
6cf1c6e5 AJ |
6954 | GEN_VXFORM_NOA(vupkhsb, 7, 8); |
6955 | GEN_VXFORM_NOA(vupkhsh, 7, 9); | |
6956 | GEN_VXFORM_NOA(vupklsb, 7, 10); | |
6957 | GEN_VXFORM_NOA(vupklsh, 7, 11); | |
79f85c3a AJ |
6958 | GEN_VXFORM_NOA(vupkhpx, 7, 13); |
6959 | GEN_VXFORM_NOA(vupklpx, 7, 15); | |
d15f74fb BS |
6960 | GEN_VXFORM_NOA_ENV(vrefp, 5, 4); |
6961 | GEN_VXFORM_NOA_ENV(vrsqrtefp, 5, 5); | |
6962 | GEN_VXFORM_NOA_ENV(vexptefp, 5, 6); | |
6963 | GEN_VXFORM_NOA_ENV(vlogefp, 5, 7); | |
6964 | GEN_VXFORM_NOA_ENV(vrfim, 5, 8); | |
6965 | GEN_VXFORM_NOA_ENV(vrfin, 5, 9); | |
6966 | GEN_VXFORM_NOA_ENV(vrfip, 5, 10); | |
6967 | GEN_VXFORM_NOA_ENV(vrfiz, 5, 11); | |
79f85c3a | 6968 | |
21d21583 | 6969 | #define GEN_VXFORM_SIMM(name, opc2, opc3) \ |
99e300ef | 6970 | static void glue(gen_, name)(DisasContext *ctx) \ |
21d21583 AJ |
6971 | { \ |
6972 | TCGv_ptr rd; \ | |
6973 | TCGv_i32 simm; \ | |
6974 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6975 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6976 | return; \ | |
6977 | } \ | |
6978 | simm = tcg_const_i32(SIMM5(ctx->opcode)); \ | |
6979 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6980 | gen_helper_##name (rd, simm); \ | |
6981 | tcg_temp_free_i32(simm); \ | |
6982 | tcg_temp_free_ptr(rd); \ | |
6983 | } | |
6984 | ||
27a4edb3 | 6985 | #define GEN_VXFORM_UIMM(name, opc2, opc3) \ |
99e300ef | 6986 | static void glue(gen_, name)(DisasContext *ctx) \ |
27a4edb3 AJ |
6987 | { \ |
6988 | TCGv_ptr rb, rd; \ | |
6989 | TCGv_i32 uimm; \ | |
6990 | if (unlikely(!ctx->altivec_enabled)) { \ | |
6991 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
6992 | return; \ | |
6993 | } \ | |
6994 | uimm = tcg_const_i32(UIMM5(ctx->opcode)); \ | |
6995 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
6996 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
6997 | gen_helper_##name (rd, rb, uimm); \ | |
6998 | tcg_temp_free_i32(uimm); \ | |
6999 | tcg_temp_free_ptr(rb); \ | |
7000 | tcg_temp_free_ptr(rd); \ | |
7001 | } | |
7002 | ||
d15f74fb BS |
7003 | #define GEN_VXFORM_UIMM_ENV(name, opc2, opc3) \ |
7004 | static void glue(gen_, name)(DisasContext *ctx) \ | |
7005 | { \ | |
7006 | TCGv_ptr rb, rd; \ | |
7007 | TCGv_i32 uimm; \ | |
7008 | \ | |
7009 | if (unlikely(!ctx->altivec_enabled)) { \ | |
7010 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
7011 | return; \ | |
7012 | } \ | |
7013 | uimm = tcg_const_i32(UIMM5(ctx->opcode)); \ | |
7014 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
7015 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
7016 | gen_helper_##name(cpu_env, rd, rb, uimm); \ | |
7017 | tcg_temp_free_i32(uimm); \ | |
7018 | tcg_temp_free_ptr(rb); \ | |
7019 | tcg_temp_free_ptr(rd); \ | |
7020 | } | |
7021 | ||
e4e6bee7 AJ |
7022 | GEN_VXFORM_UIMM(vspltb, 6, 8); |
7023 | GEN_VXFORM_UIMM(vsplth, 6, 9); | |
7024 | GEN_VXFORM_UIMM(vspltw, 6, 10); | |
d15f74fb BS |
7025 | GEN_VXFORM_UIMM_ENV(vcfux, 5, 12); |
7026 | GEN_VXFORM_UIMM_ENV(vcfsx, 5, 13); | |
7027 | GEN_VXFORM_UIMM_ENV(vctuxs, 5, 14); | |
7028 | GEN_VXFORM_UIMM_ENV(vctsxs, 5, 15); | |
e4e6bee7 | 7029 | |
99e300ef | 7030 | static void gen_vsldoi(DisasContext *ctx) |
cd633b10 AJ |
7031 | { |
7032 | TCGv_ptr ra, rb, rd; | |
fce5ecb7 | 7033 | TCGv_i32 sh; |
cd633b10 AJ |
7034 | if (unlikely(!ctx->altivec_enabled)) { |
7035 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
7036 | return; | |
7037 | } | |
7038 | ra = gen_avr_ptr(rA(ctx->opcode)); | |
7039 | rb = gen_avr_ptr(rB(ctx->opcode)); | |
7040 | rd = gen_avr_ptr(rD(ctx->opcode)); | |
7041 | sh = tcg_const_i32(VSH(ctx->opcode)); | |
7042 | gen_helper_vsldoi (rd, ra, rb, sh); | |
7043 | tcg_temp_free_ptr(ra); | |
7044 | tcg_temp_free_ptr(rb); | |
7045 | tcg_temp_free_ptr(rd); | |
fce5ecb7 | 7046 | tcg_temp_free_i32(sh); |
cd633b10 AJ |
7047 | } |
7048 | ||
707cec33 | 7049 | #define GEN_VAFORM_PAIRED(name0, name1, opc2) \ |
d15f74fb | 7050 | static void glue(gen_, name0##_##name1)(DisasContext *ctx) \ |
707cec33 AJ |
7051 | { \ |
7052 | TCGv_ptr ra, rb, rc, rd; \ | |
7053 | if (unlikely(!ctx->altivec_enabled)) { \ | |
7054 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
7055 | return; \ | |
7056 | } \ | |
7057 | ra = gen_avr_ptr(rA(ctx->opcode)); \ | |
7058 | rb = gen_avr_ptr(rB(ctx->opcode)); \ | |
7059 | rc = gen_avr_ptr(rC(ctx->opcode)); \ | |
7060 | rd = gen_avr_ptr(rD(ctx->opcode)); \ | |
7061 | if (Rc(ctx->opcode)) { \ | |
d15f74fb | 7062 | gen_helper_##name1(cpu_env, rd, ra, rb, rc); \ |
707cec33 | 7063 | } else { \ |
d15f74fb | 7064 | gen_helper_##name0(cpu_env, rd, ra, rb, rc); \ |
707cec33 AJ |
7065 | } \ |
7066 | tcg_temp_free_ptr(ra); \ | |
7067 | tcg_temp_free_ptr(rb); \ | |
7068 | tcg_temp_free_ptr(rc); \ | |
7069 | tcg_temp_free_ptr(rd); \ | |
7070 | } | |
7071 | ||
b161ae27 AJ |
7072 | GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16) |
7073 | ||
99e300ef | 7074 | static void gen_vmladduhm(DisasContext *ctx) |
bcd2ee23 AJ |
7075 | { |
7076 | TCGv_ptr ra, rb, rc, rd; | |
7077 | if (unlikely(!ctx->altivec_enabled)) { | |
7078 | gen_exception(ctx, POWERPC_EXCP_VPU); | |
7079 | return; | |
7080 | } | |
7081 | ra = gen_avr_ptr(rA(ctx->opcode)); | |
7082 | rb = gen_avr_ptr(rB(ctx->opcode)); | |
7083 | rc = gen_avr_ptr(rC(ctx->opcode)); | |
7084 | rd = gen_avr_ptr(rD(ctx->opcode)); | |
7085 | gen_helper_vmladduhm(rd, ra, rb, rc); | |
7086 | tcg_temp_free_ptr(ra); | |
7087 | tcg_temp_free_ptr(rb); | |
7088 | tcg_temp_free_ptr(rc); | |
7089 | tcg_temp_free_ptr(rd); | |
7090 | } | |
7091 | ||
b04ae981 | 7092 | GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18) |
4d9903b6 | 7093 | GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19) |
eae07261 | 7094 | GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20) |
d1258698 | 7095 | GEN_VAFORM_PAIRED(vsel, vperm, 21) |
35cf7c7e | 7096 | GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23) |
b04ae981 | 7097 | |
472b24ce TM |
7098 | /*** VSX extension ***/ |
7099 | ||
7100 | static inline TCGv_i64 cpu_vsrh(int n) | |
7101 | { | |
7102 | if (n < 32) { | |
7103 | return cpu_fpr[n]; | |
7104 | } else { | |
7105 | return cpu_avrh[n-32]; | |
7106 | } | |
7107 | } | |
7108 | ||
7109 | static inline TCGv_i64 cpu_vsrl(int n) | |
7110 | { | |
7111 | if (n < 32) { | |
7112 | return cpu_vsr[n]; | |
7113 | } else { | |
7114 | return cpu_avrl[n-32]; | |
7115 | } | |
7116 | } | |
7117 | ||
e072fe79 TM |
7118 | #define VSX_LOAD_SCALAR(name, operation) \ |
7119 | static void gen_##name(DisasContext *ctx) \ | |
7120 | { \ | |
7121 | TCGv EA; \ | |
7122 | if (unlikely(!ctx->vsx_enabled)) { \ | |
7123 | gen_exception(ctx, POWERPC_EXCP_VSXU); \ | |
7124 | return; \ | |
7125 | } \ | |
7126 | gen_set_access_type(ctx, ACCESS_INT); \ | |
7127 | EA = tcg_temp_new(); \ | |
7128 | gen_addr_reg_index(ctx, EA); \ | |
7129 | gen_qemu_##operation(ctx, cpu_vsrh(xT(ctx->opcode)), EA); \ | |
7130 | /* NOTE: cpu_vsrl is undefined */ \ | |
7131 | tcg_temp_free(EA); \ | |
7132 | } | |
7133 | ||
7134 | VSX_LOAD_SCALAR(lxsdx, ld64) | |
cac7f0ba TM |
7135 | VSX_LOAD_SCALAR(lxsiwax, ld32s_i64) |
7136 | VSX_LOAD_SCALAR(lxsiwzx, ld32u_i64) | |
7137 | VSX_LOAD_SCALAR(lxsspx, ld32fs) | |
fa1832d7 | 7138 | |
304af367 TM |
7139 | static void gen_lxvd2x(DisasContext *ctx) |
7140 | { | |
7141 | TCGv EA; | |
7142 | if (unlikely(!ctx->vsx_enabled)) { | |
7143 | gen_exception(ctx, POWERPC_EXCP_VSXU); | |
7144 | return; | |
7145 | } | |
7146 | gen_set_access_type(ctx, ACCESS_INT); | |
7147 | EA = tcg_temp_new(); | |
7148 | gen_addr_reg_index(ctx, EA); | |
7149 | gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA); | |
7150 | tcg_gen_addi_tl(EA, EA, 8); | |
7151 | gen_qemu_ld64(ctx, cpu_vsrl(xT(ctx->opcode)), EA); | |
7152 | tcg_temp_free(EA); | |
7153 | } | |
7154 | ||
ca03b467 TM |
7155 | static void gen_lxvdsx(DisasContext *ctx) |
7156 | { | |
7157 | TCGv EA; | |
7158 | if (unlikely(!ctx->vsx_enabled)) { | |
7159 | gen_exception(ctx, POWERPC_EXCP_VSXU); | |
7160 | return; | |
7161 | } | |
7162 | gen_set_access_type(ctx, ACCESS_INT); | |
7163 | EA = tcg_temp_new(); | |
7164 | gen_addr_reg_index(ctx, EA); | |
7165 | gen_qemu_ld64(ctx, cpu_vsrh(xT(ctx->opcode)), EA); | |
f976b09e | 7166 | tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode))); |
ca03b467 TM |
7167 | tcg_temp_free(EA); |
7168 | } | |
7169 | ||
897e61d1 TM |
7170 | static void gen_lxvw4x(DisasContext *ctx) |
7171 | { | |
f976b09e AG |
7172 | TCGv EA; |
7173 | TCGv_i64 tmp; | |
897e61d1 TM |
7174 | TCGv_i64 xth = cpu_vsrh(xT(ctx->opcode)); |
7175 | TCGv_i64 xtl = cpu_vsrl(xT(ctx->opcode)); | |
7176 | if (unlikely(!ctx->vsx_enabled)) { | |
7177 | gen_exception(ctx, POWERPC_EXCP_VSXU); | |
7178 | return; | |
7179 | } | |
7180 | gen_set_access_type(ctx, ACCESS_INT); | |
7181 | EA = tcg_temp_new(); | |
f976b09e AG |
7182 | tmp = tcg_temp_new_i64(); |
7183 | ||
897e61d1 | 7184 | gen_addr_reg_index(ctx, EA); |
f976b09e | 7185 | gen_qemu_ld32u_i64(ctx, tmp, EA); |
897e61d1 | 7186 | tcg_gen_addi_tl(EA, EA, 4); |
f976b09e | 7187 | gen_qemu_ld32u_i64(ctx, xth, EA); |
897e61d1 TM |
7188 | tcg_gen_deposit_i64(xth, xth, tmp, 32, 32); |
7189 | ||
7190 | tcg_gen_addi_tl(EA, EA, 4); | |
f976b09e | 7191 | gen_qemu_ld32u_i64(ctx, tmp, EA); |
897e61d1 | 7192 | tcg_gen_addi_tl(EA, EA, 4); |
f976b09e | 7193 | gen_qemu_ld32u_i64(ctx, xtl, EA); |
897e61d1 TM |
7194 | tcg_gen_deposit_i64(xtl, xtl, tmp, 32, 32); |
7195 | ||
7196 | tcg_temp_free(EA); | |
f976b09e | 7197 | tcg_temp_free_i64(tmp); |
897e61d1 TM |
7198 | } |
7199 | ||
f026da78 TM |
7200 | #define VSX_STORE_SCALAR(name, operation) \ |
7201 | static void gen_##name(DisasContext *ctx) \ | |
7202 | { \ | |
7203 | TCGv EA; \ | |
7204 | if (unlikely(!ctx->vsx_enabled)) { \ | |
7205 | gen_exception(ctx, POWERPC_EXCP_VSXU); \ | |
7206 | return; \ | |
7207 | } \ | |
7208 | gen_set_access_type(ctx, ACCESS_INT); \ | |
7209 | EA = tcg_temp_new(); \ | |
7210 | gen_addr_reg_index(ctx, EA); \ | |
7211 | gen_qemu_##operation(ctx, cpu_vsrh(xS(ctx->opcode)), EA); \ | |
7212 | tcg_temp_free(EA); \ | |
9231ba9e TM |
7213 | } |
7214 | ||
f026da78 | 7215 | VSX_STORE_SCALAR(stxsdx, st64) |
e16a626b TM |
7216 | VSX_STORE_SCALAR(stxsiwx, st32_i64) |
7217 | VSX_STORE_SCALAR(stxsspx, st32fs) | |
f026da78 | 7218 | |
fbed2478 TM |
7219 | static void gen_stxvd2x(DisasContext *ctx) |
7220 | { | |
7221 | TCGv EA; | |
7222 | if (unlikely(!ctx->vsx_enabled)) { | |
7223 | gen_exception(ctx, POWERPC_EXCP_VSXU); | |
7224 | return; | |
7225 | } | |
7226 | gen_set_access_type(ctx, ACCESS_INT); | |
7227 | EA = tcg_temp_new(); | |
7228 | gen_addr_reg_index(ctx, EA); | |
7229 | gen_qemu_st64(ctx, cpu_vsrh(xS(ctx->opcode)), EA); | |
7230 | tcg_gen_addi_tl(EA, EA, 8); | |
7231 | gen_qemu_st64(ctx, cpu_vsrl(xS(ctx->opcode)), EA); | |
7232 | tcg_temp_free(EA); | |
7233 | } | |
7234 | ||
86e61ce3 TM |
7235 | static void gen_stxvw4x(DisasContext *ctx) |
7236 | { | |
f976b09e AG |
7237 | TCGv_i64 tmp; |
7238 | TCGv EA; | |
86e61ce3 TM |
7239 | if (unlikely(!ctx->vsx_enabled)) { |
7240 | gen_exception(ctx, POWERPC_EXCP_VSXU); | |
7241 | return; | |
7242 | } | |
7243 | gen_set_access_type(ctx, ACCESS_INT); | |
7244 | EA = tcg_temp_new(); | |
7245 | gen_addr_reg_index(ctx, EA); | |
f976b09e | 7246 | tmp = tcg_temp_new_i64(); |
86e61ce3 TM |
7247 | |
7248 | tcg_gen_shri_i64(tmp, cpu_vsrh(xS(ctx->opcode)), 32); | |
f976b09e | 7249 | gen_qemu_st32_i64(ctx, tmp, EA); |
86e61ce3 | 7250 | tcg_gen_addi_tl(EA, EA, 4); |
f976b09e | 7251 | gen_qemu_st32_i64(ctx, cpu_vsrh(xS(ctx->opcode)), EA); |
86e61ce3 TM |
7252 | |
7253 | tcg_gen_shri_i64(tmp, cpu_vsrl(xS(ctx->opcode)), 32); | |
7254 | tcg_gen_addi_tl(EA, EA, 4); | |
f976b09e | 7255 | gen_qemu_st32_i64(ctx, tmp, EA); |
86e61ce3 | 7256 | tcg_gen_addi_tl(EA, EA, 4); |
f976b09e | 7257 | gen_qemu_st32_i64(ctx, cpu_vsrl(xS(ctx->opcode)), EA); |
86e61ce3 TM |
7258 | |
7259 | tcg_temp_free(EA); | |
f976b09e | 7260 | tcg_temp_free_i64(tmp); |
86e61ce3 TM |
7261 | } |
7262 | ||
f5c0f7f9 TM |
7263 | #define MV_VSRW(name, tcgop1, tcgop2, target, source) \ |
7264 | static void gen_##name(DisasContext *ctx) \ | |
7265 | { \ | |
7266 | if (xS(ctx->opcode) < 32) { \ | |
7267 | if (unlikely(!ctx->fpu_enabled)) { \ | |
7268 | gen_exception(ctx, POWERPC_EXCP_FPU); \ | |
7269 | return; \ | |
7270 | } \ | |
7271 | } else { \ | |
7272 | if (unlikely(!ctx->altivec_enabled)) { \ | |
7273 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
7274 | return; \ | |
7275 | } \ | |
7276 | } \ | |
7277 | TCGv_i64 tmp = tcg_temp_new_i64(); \ | |
7278 | tcg_gen_##tcgop1(tmp, source); \ | |
7279 | tcg_gen_##tcgop2(target, tmp); \ | |
7280 | tcg_temp_free_i64(tmp); \ | |
7281 | } | |
7282 | ||
7283 | ||
7284 | MV_VSRW(mfvsrwz, ext32u_i64, trunc_i64_tl, cpu_gpr[rA(ctx->opcode)], \ | |
7285 | cpu_vsrh(xS(ctx->opcode))) | |
7286 | MV_VSRW(mtvsrwa, extu_tl_i64, ext32s_i64, cpu_vsrh(xT(ctx->opcode)), \ | |
7287 | cpu_gpr[rA(ctx->opcode)]) | |
7288 | MV_VSRW(mtvsrwz, extu_tl_i64, ext32u_i64, cpu_vsrh(xT(ctx->opcode)), \ | |
7289 | cpu_gpr[rA(ctx->opcode)]) | |
7290 | ||
7291 | #if defined(TARGET_PPC64) | |
7292 | #define MV_VSRD(name, target, source) \ | |
7293 | static void gen_##name(DisasContext *ctx) \ | |
7294 | { \ | |
7295 | if (xS(ctx->opcode) < 32) { \ | |
7296 | if (unlikely(!ctx->fpu_enabled)) { \ | |
7297 | gen_exception(ctx, POWERPC_EXCP_FPU); \ | |
7298 | return; \ | |
7299 | } \ | |
7300 | } else { \ | |
7301 | if (unlikely(!ctx->altivec_enabled)) { \ | |
7302 | gen_exception(ctx, POWERPC_EXCP_VPU); \ | |
7303 | return; \ | |
7304 | } \ | |
7305 | } \ | |
7306 | tcg_gen_mov_i64(target, source); \ | |
7307 | } | |
7308 | ||
7309 | MV_VSRD(mfvsrd, cpu_gpr[rA(ctx->opcode)], cpu_vsrh(xS(ctx->opcode))) | |
7310 | MV_VSRD(mtvsrd, cpu_vsrh(xT(ctx->opcode)), cpu_gpr[rA(ctx->opcode)]) | |
7311 | ||
7312 | #endif | |
7313 | ||
cd73f2c9 TM |
7314 | static void gen_xxpermdi(DisasContext *ctx) |
7315 | { | |
7316 | if (unlikely(!ctx->vsx_enabled)) { | |
7317 | gen_exception(ctx, POWERPC_EXCP_VSXU); | |
7318 | return; | |
7319 | } | |
7320 | ||
7321 | if ((DM(ctx->opcode) & 2) == 0) { | |
7322 | tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode))); | |
7323 | } else { | |
7324 | tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode))); | |
7325 | } | |
7326 | if ((DM(ctx->opcode) & 1) == 0) { | |
7327 | tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xB(ctx->opcode))); | |
7328 | } else { | |
7329 | tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xB(ctx->opcode))); | |
7330 | } | |
7331 | } | |
7332 | ||
df020ce0 TM |
7333 | #define OP_ABS 1 |
7334 | #define OP_NABS 2 | |
7335 | #define OP_NEG 3 | |
7336 | #define OP_CPSGN 4 | |
7337 | #define SGN_MASK_DP 0x8000000000000000ul | |
7338 | #define SGN_MASK_SP 0x8000000080000000ul | |
7339 | ||
7340 | #define VSX_SCALAR_MOVE(name, op, sgn_mask) \ | |
7341 | static void glue(gen_, name)(DisasContext * ctx) \ | |
7342 | { \ | |
7343 | TCGv_i64 xb, sgm; \ | |
7344 | if (unlikely(!ctx->vsx_enabled)) { \ | |
7345 | gen_exception(ctx, POWERPC_EXCP_VSXU); \ | |
7346 | return; \ | |
7347 | } \ | |
f976b09e AG |
7348 | xb = tcg_temp_new_i64(); \ |
7349 | sgm = tcg_temp_new_i64(); \ | |
df020ce0 TM |
7350 | tcg_gen_mov_i64(xb, cpu_vsrh(xB(ctx->opcode))); \ |
7351 | tcg_gen_movi_i64(sgm, sgn_mask); \ | |
7352 | switch (op) { \ | |
7353 | case OP_ABS: { \ | |
7354 | tcg_gen_andc_i64(xb, xb, sgm); \ | |
7355 | break; \ | |
7356 | } \ | |
7357 | case OP_NABS: { \ | |
7358 | tcg_gen_or_i64(xb, xb, sgm); \ | |
7359 | break; \ | |
7360 | } \ | |
7361 | case OP_NEG: { \ | |
7362 | tcg_gen_xor_i64(xb, xb, sgm); \ | |
7363 | break; \ | |
7364 | } \ | |
7365 | case OP_CPSGN: { \ | |
f976b09e | 7366 | TCGv_i64 xa = tcg_temp_new_i64(); \ |
df020ce0 TM |
7367 | tcg_gen_mov_i64(xa, cpu_vsrh(xA(ctx->opcode))); \ |
7368 | tcg_gen_and_i64(xa, xa, sgm); \ | |
7369 | tcg_gen_andc_i64(xb, xb, sgm); \ | |
7370 | tcg_gen_or_i64(xb, xb, xa); \ | |
f976b09e | 7371 | tcg_temp_free_i64(xa); \ |
df020ce0 TM |
7372 | break; \ |
7373 | } \ | |
7374 | } \ | |
7375 | tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xb); \ | |
f976b09e AG |
7376 | tcg_temp_free_i64(xb); \ |
7377 | tcg_temp_free_i64(sgm); \ | |
df020ce0 TM |
7378 | } |
7379 | ||
7380 | VSX_SCALAR_MOVE(xsabsdp, OP_ABS, SGN_MASK_DP) | |
7381 | VSX_SCALAR_MOVE(xsnabsdp, OP_NABS, SGN_MASK_DP) | |
7382 | VSX_SCALAR_MOVE(xsnegdp, OP_NEG, SGN_MASK_DP) | |
7383 | VSX_SCALAR_MOVE(xscpsgndp, OP_CPSGN, SGN_MASK_DP) | |
7384 | ||
be574920 TM |
7385 | #define VSX_VECTOR_MOVE(name, op, sgn_mask) \ |
7386 | static void glue(gen_, name)(DisasContext * ctx) \ | |
7387 | { \ | |
7388 | TCGv_i64 xbh, xbl, sgm; \ | |
7389 | if (unlikely(!ctx->vsx_enabled)) { \ | |
7390 | gen_exception(ctx, POWERPC_EXCP_VSXU); \ | |
7391 | return; \ | |
7392 | } \ | |
f976b09e AG |
7393 | xbh = tcg_temp_new_i64(); \ |
7394 | xbl = tcg_temp_new_i64(); \ | |
7395 | sgm = tcg_temp_new_i64(); \ | |
be574920 TM |
7396 | tcg_gen_mov_i64(xbh, cpu_vsrh(xB(ctx->opcode))); \ |
7397 | tcg_gen_mov_i64(xbl, cpu_vsrl(xB(ctx->opcode))); \ | |
7398 | tcg_gen_movi_i64(sgm, sgn_mask); \ | |
7399 | switch (op) { \ | |
7400 | case OP_ABS: { \ | |
7401 | tcg_gen_andc_i64(xbh, xbh, sgm); \ | |
7402 | tcg_gen_andc_i64(xbl, xbl, sgm); \ | |
7403 | break; \ | |
7404 | } \ | |
7405 | case OP_NABS: { \ | |
7406 | tcg_gen_or_i64(xbh, xbh, sgm); \ | |
7407 | tcg_gen_or_i64(xbl, xbl, sgm); \ | |
7408 | break; \ | |
7409 | } \ | |
7410 | case OP_NEG: { \ | |
7411 | tcg_gen_xor_i64(xbh, xbh, sgm); \ | |
7412 | tcg_gen_xor_i64(xbl, xbl, sgm); \ | |
7413 | break; \ | |
7414 | } \ | |
7415 | case OP_CPSGN: { \ | |
f976b09e AG |
7416 | TCGv_i64 xah = tcg_temp_new_i64(); \ |
7417 | TCGv_i64 xal = tcg_temp_new_i64(); \ | |
be574920 TM |
7418 | tcg_gen_mov_i64(xah, cpu_vsrh(xA(ctx->opcode))); \ |
7419 | tcg_gen_mov_i64(xal, cpu_vsrl(xA(ctx->opcode))); \ | |
7420 | tcg_gen_and_i64(xah, xah, sgm); \ | |
7421 | tcg_gen_and_i64(xal, xal, sgm); \ | |
7422 | tcg_gen_andc_i64(xbh, xbh, sgm); \ | |
7423 | tcg_gen_andc_i64(xbl, xbl, sgm); \ | |
7424 | tcg_gen_or_i64(xbh, xbh, xah); \ | |
7425 | tcg_gen_or_i64(xbl, xbl, xal); \ | |
f976b09e AG |
7426 | tcg_temp_free_i64(xah); \ |
7427 | tcg_temp_free_i64(xal); \ | |
be574920 TM |
7428 | break; \ |
7429 | } \ | |
7430 | } \ | |
7431 | tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xbh); \ | |
7432 | tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xbl); \ | |
f976b09e AG |
7433 | tcg_temp_free_i64(xbh); \ |
7434 | tcg_temp_free_i64(xbl); \ | |
7435 | tcg_temp_free_i64(sgm); \ | |
be574920 TM |
7436 | } |
7437 | ||
7438 | VSX_VECTOR_MOVE(xvabsdp, OP_ABS, SGN_MASK_DP) | |
7439 | VSX_VECTOR_MOVE(xvnabsdp, OP_NABS, SGN_MASK_DP) | |
7440 | VSX_VECTOR_MOVE(xvnegdp, OP_NEG, SGN_MASK_DP) | |
7441 | VSX_VECTOR_MOVE(xvcpsgndp, OP_CPSGN, SGN_MASK_DP) | |
7442 | VSX_VECTOR_MOVE(xvabssp, OP_ABS, SGN_MASK_SP) | |
7443 | VSX_VECTOR_MOVE(xvnabssp, OP_NABS, SGN_MASK_SP) | |
7444 | VSX_VECTOR_MOVE(xvnegsp, OP_NEG, SGN_MASK_SP) | |
7445 | VSX_VECTOR_MOVE(xvcpsgnsp, OP_CPSGN, SGN_MASK_SP) | |
7446 | ||
3c3cbbdc TM |
7447 | #define GEN_VSX_HELPER_2(name, op1, op2, inval, type) \ |
7448 | static void gen_##name(DisasContext * ctx) \ | |
7449 | { \ | |
7450 | TCGv_i32 opc; \ | |
7451 | if (unlikely(!ctx->vsx_enabled)) { \ | |
7452 | gen_exception(ctx, POWERPC_EXCP_VSXU); \ | |
7453 | return; \ | |
7454 | } \ | |
7455 | /* NIP cannot be restored if the memory exception comes from an helper */ \ | |
7456 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7457 | opc = tcg_const_i32(ctx->opcode); \ | |
7458 | gen_helper_##name(cpu_env, opc); \ | |
7459 | tcg_temp_free_i32(opc); \ | |
7460 | } | |
be574920 | 7461 | |
3d1140bf TM |
7462 | #define GEN_VSX_HELPER_XT_XB_ENV(name, op1, op2, inval, type) \ |
7463 | static void gen_##name(DisasContext * ctx) \ | |
7464 | { \ | |
7465 | if (unlikely(!ctx->vsx_enabled)) { \ | |
7466 | gen_exception(ctx, POWERPC_EXCP_VSXU); \ | |
7467 | return; \ | |
7468 | } \ | |
7469 | /* NIP cannot be restored if the exception comes */ \ | |
7470 | /* from a helper. */ \ | |
7471 | gen_update_nip(ctx, ctx->nip - 4); \ | |
7472 | \ | |
7473 | gen_helper_##name(cpu_vsrh(xT(ctx->opcode)), cpu_env, \ | |
7474 | cpu_vsrh(xB(ctx->opcode))); \ | |
7475 | } | |
7476 | ||
ee6e02c0 TM |
7477 | GEN_VSX_HELPER_2(xsadddp, 0x00, 0x04, 0, PPC2_VSX) |
7478 | GEN_VSX_HELPER_2(xssubdp, 0x00, 0x05, 0, PPC2_VSX) | |
5e591d88 | 7479 | GEN_VSX_HELPER_2(xsmuldp, 0x00, 0x06, 0, PPC2_VSX) |
4b98eeef | 7480 | GEN_VSX_HELPER_2(xsdivdp, 0x00, 0x07, 0, PPC2_VSX) |
2009227f | 7481 | GEN_VSX_HELPER_2(xsredp, 0x14, 0x05, 0, PPC2_VSX) |
d32404fe | 7482 | GEN_VSX_HELPER_2(xssqrtdp, 0x16, 0x04, 0, PPC2_VSX) |
d3f9df8f | 7483 | GEN_VSX_HELPER_2(xsrsqrtedp, 0x14, 0x04, 0, PPC2_VSX) |
bc80838f | 7484 | GEN_VSX_HELPER_2(xstdivdp, 0x14, 0x07, 0, PPC2_VSX) |
5cb151ac | 7485 | GEN_VSX_HELPER_2(xstsqrtdp, 0x14, 0x06, 0, PPC2_VSX) |
595c6eef TM |
7486 | GEN_VSX_HELPER_2(xsmaddadp, 0x04, 0x04, 0, PPC2_VSX) |
7487 | GEN_VSX_HELPER_2(xsmaddmdp, 0x04, 0x05, 0, PPC2_VSX) | |
7488 | GEN_VSX_HELPER_2(xsmsubadp, 0x04, 0x06, 0, PPC2_VSX) | |
7489 | GEN_VSX_HELPER_2(xsmsubmdp, 0x04, 0x07, 0, PPC2_VSX) | |
7490 | GEN_VSX_HELPER_2(xsnmaddadp, 0x04, 0x14, 0, PPC2_VSX) | |
7491 | GEN_VSX_HELPER_2(xsnmaddmdp, 0x04, 0x15, 0, PPC2_VSX) | |
7492 | GEN_VSX_HELPER_2(xsnmsubadp, 0x04, 0x16, 0, PPC2_VSX) | |
7493 | GEN_VSX_HELPER_2(xsnmsubmdp, 0x04, 0x17, 0, PPC2_VSX) | |
4f17e9c7 TM |
7494 | GEN_VSX_HELPER_2(xscmpodp, 0x0C, 0x05, 0, PPC2_VSX) |
7495 | GEN_VSX_HELPER_2(xscmpudp, 0x0C, 0x04, 0, PPC2_VSX) | |
959e9c9d TM |
7496 | GEN_VSX_HELPER_2(xsmaxdp, 0x00, 0x14, 0, PPC2_VSX) |
7497 | GEN_VSX_HELPER_2(xsmindp, 0x00, 0x15, 0, PPC2_VSX) | |
ed8ac568 | 7498 | GEN_VSX_HELPER_2(xscvdpsp, 0x12, 0x10, 0, PPC2_VSX) |
7ee19fb9 | 7499 | GEN_VSX_HELPER_XT_XB_ENV(xscvdpspn, 0x16, 0x10, 0, PPC2_VSX207) |
ed8ac568 | 7500 | GEN_VSX_HELPER_2(xscvspdp, 0x12, 0x14, 0, PPC2_VSX) |
7ee19fb9 | 7501 | GEN_VSX_HELPER_XT_XB_ENV(xscvspdpn, 0x16, 0x14, 0, PPC2_VSX207) |
5177d2ca TM |
7502 | GEN_VSX_HELPER_2(xscvdpsxds, 0x10, 0x15, 0, PPC2_VSX) |
7503 | GEN_VSX_HELPER_2(xscvdpsxws, 0x10, 0x05, 0, PPC2_VSX) | |
7504 | GEN_VSX_HELPER_2(xscvdpuxds, 0x10, 0x14, 0, PPC2_VSX) | |
7505 | GEN_VSX_HELPER_2(xscvdpuxws, 0x10, 0x04, 0, PPC2_VSX) | |
7506 | GEN_VSX_HELPER_2(xscvsxddp, 0x10, 0x17, 0, PPC2_VSX) | |
7507 | GEN_VSX_HELPER_2(xscvuxddp, 0x10, 0x16, 0, PPC2_VSX) | |
88e33d08 TM |
7508 | GEN_VSX_HELPER_2(xsrdpi, 0x12, 0x04, 0, PPC2_VSX) |
7509 | GEN_VSX_HELPER_2(xsrdpic, 0x16, 0x06, 0, PPC2_VSX) | |
7510 | GEN_VSX_HELPER_2(xsrdpim, 0x12, 0x07, 0, PPC2_VSX) | |
7511 | GEN_VSX_HELPER_2(xsrdpip, 0x12, 0x06, 0, PPC2_VSX) | |
7512 | GEN_VSX_HELPER_2(xsrdpiz, 0x12, 0x05, 0, PPC2_VSX) | |
3d1140bf | 7513 | GEN_VSX_HELPER_XT_XB_ENV(xsrsp, 0x12, 0x11, 0, PPC2_VSX207) |
ee6e02c0 | 7514 | |
3fd0aadf TM |
7515 | GEN_VSX_HELPER_2(xsaddsp, 0x00, 0x00, 0, PPC2_VSX207) |
7516 | GEN_VSX_HELPER_2(xssubsp, 0x00, 0x01, 0, PPC2_VSX207) | |
ab9408a2 | 7517 | GEN_VSX_HELPER_2(xsmulsp, 0x00, 0x02, 0, PPC2_VSX207) |
b24d0b47 | 7518 | GEN_VSX_HELPER_2(xsdivsp, 0x00, 0x03, 0, PPC2_VSX207) |
2c0c52ae | 7519 | GEN_VSX_HELPER_2(xsresp, 0x14, 0x01, 0, PPC2_VSX207) |
cea4e574 | 7520 | GEN_VSX_HELPER_2(xssqrtsp, 0x16, 0x00, 0, PPC2_VSX207) |
968e76bc | 7521 | GEN_VSX_HELPER_2(xsrsqrtesp, 0x14, 0x00, 0, PPC2_VSX207) |
f53f81e0 TM |
7522 | GEN_VSX_HELPER_2(xsmaddasp, 0x04, 0x00, 0, PPC2_VSX207) |
7523 | GEN_VSX_HELPER_2(xsmaddmsp, 0x04, 0x01, 0, PPC2_VSX207) | |
7524 | GEN_VSX_HELPER_2(xsmsubasp, 0x04, 0x02, 0, PPC2_VSX207) | |
7525 | GEN_VSX_HELPER_2(xsmsubmsp, 0x04, 0x03, 0, PPC2_VSX207) | |
7526 | GEN_VSX_HELPER_2(xsnmaddasp, 0x04, 0x10, 0, PPC2_VSX207) | |
7527 | GEN_VSX_HELPER_2(xsnmaddmsp, 0x04, 0x11, 0, PPC2_VSX207) | |
7528 | GEN_VSX_HELPER_2(xsnmsubasp, 0x04, 0x12, 0, PPC2_VSX207) | |
7529 | GEN_VSX_HELPER_2(xsnmsubmsp, 0x04, 0x13, 0, PPC2_VSX207) | |
74698350 TM |
7530 | GEN_VSX_HELPER_2(xscvsxdsp, 0x10, 0x13, 0, PPC2_VSX207) |
7531 | GEN_VSX_HELPER_2(xscvuxdsp, 0x10, 0x12, 0, PPC2_VSX207) | |
3fd0aadf | 7532 | |
ee6e02c0 TM |
7533 | GEN_VSX_HELPER_2(xvadddp, 0x00, 0x0C, 0, PPC2_VSX) |
7534 | GEN_VSX_HELPER_2(xvsubdp, 0x00, 0x0D, 0, PPC2_VSX) | |
5e591d88 | 7535 | GEN_VSX_HELPER_2(xvmuldp, 0x00, 0x0E, 0, PPC2_VSX) |
4b98eeef | 7536 | GEN_VSX_HELPER_2(xvdivdp, 0x00, 0x0F, 0, PPC2_VSX) |
2009227f | 7537 | GEN_VSX_HELPER_2(xvredp, 0x14, 0x0D, 0, PPC2_VSX) |
d32404fe | 7538 | GEN_VSX_HELPER_2(xvsqrtdp, 0x16, 0x0C, 0, PPC2_VSX) |
d3f9df8f | 7539 | GEN_VSX_HELPER_2(xvrsqrtedp, 0x14, 0x0C, 0, PPC2_VSX) |
bc80838f | 7540 | GEN_VSX_HELPER_2(xvtdivdp, 0x14, 0x0F, 0, PPC2_VSX) |
5cb151ac | 7541 | GEN_VSX_HELPER_2(xvtsqrtdp, 0x14, 0x0E, 0, PPC2_VSX) |
595c6eef TM |
7542 | GEN_VSX_HELPER_2(xvmaddadp, 0x04, 0x0C, 0, PPC2_VSX) |
7543 | GEN_VSX_HELPER_2(xvmaddmdp, 0x04, 0x0D, 0, PPC2_VSX) | |
7544 | GEN_VSX_HELPER_2(xvmsubadp, 0x04, 0x0E, 0, PPC2_VSX) | |
7545 | GEN_VSX_HELPER_2(xvmsubmdp, 0x04, 0x0F, 0, PPC2_VSX) | |
7546 | GEN_VSX_HELPER_2(xvnmaddadp, 0x04, 0x1C, 0, PPC2_VSX) | |
7547 | GEN_VSX_HELPER_2(xvnmaddmdp, 0x04, 0x1D, 0, PPC2_VSX) | |
7548 | GEN_VSX_HELPER_2(xvnmsubadp, 0x04, 0x1E, 0, PPC2_VSX) | |
7549 | GEN_VSX_HELPER_2(xvnmsubmdp, 0x04, 0x1F, 0, PPC2_VSX) | |
959e9c9d TM |
7550 | GEN_VSX_HELPER_2(xvmaxdp, 0x00, 0x1C, 0, PPC2_VSX) |
7551 | GEN_VSX_HELPER_2(xvmindp, 0x00, 0x1D, 0, PPC2_VSX) | |
354a6dec TM |
7552 | GEN_VSX_HELPER_2(xvcmpeqdp, 0x0C, 0x0C, 0, PPC2_VSX) |
7553 | GEN_VSX_HELPER_2(xvcmpgtdp, 0x0C, 0x0D, 0, PPC2_VSX) | |
7554 | GEN_VSX_HELPER_2(xvcmpgedp, 0x0C, 0x0E, 0, PPC2_VSX) | |
ed8ac568 | 7555 | GEN_VSX_HELPER_2(xvcvdpsp, 0x12, 0x18, 0, PPC2_VSX) |
5177d2ca TM |
7556 | GEN_VSX_HELPER_2(xvcvdpsxds, 0x10, 0x1D, 0, PPC2_VSX) |
7557 | GEN_VSX_HELPER_2(xvcvdpsxws, 0x10, 0x0D, 0, PPC2_VSX) | |
7558 | GEN_VSX_HELPER_2(xvcvdpuxds, 0x10, 0x1C, 0, PPC2_VSX) | |
7559 | GEN_VSX_HELPER_2(xvcvdpuxws, 0x10, 0x0C, 0, PPC2_VSX) | |
7560 | GEN_VSX_HELPER_2(xvcvsxddp, 0x10, 0x1F, 0, PPC2_VSX) | |
7561 | GEN_VSX_HELPER_2(xvcvuxddp, 0x10, 0x1E, 0, PPC2_VSX) | |
7562 | GEN_VSX_HELPER_2(xvcvsxwdp, 0x10, 0x0F, 0, PPC2_VSX) | |
7563 | GEN_VSX_HELPER_2(xvcvuxwdp, 0x10, 0x0E, 0, PPC2_VSX) | |
88e33d08 TM |
7564 | GEN_VSX_HELPER_2(xvrdpi, 0x12, 0x0C, 0, PPC2_VSX) |
7565 | GEN_VSX_HELPER_2(xvrdpic, 0x16, 0x0E, 0, PPC2_VSX) | |
7566 | GEN_VSX_HELPER_2(xvrdpim, 0x12, 0x0F, 0, PPC2_VSX) | |
7567 | GEN_VSX_HELPER_2(xvrdpip, 0x12, 0x0E, 0, PPC2_VSX) | |
7568 | GEN_VSX_HELPER_2(xvrdpiz, 0x12, 0x0D, 0, PPC2_VSX) | |
ee6e02c0 TM |
7569 | |
7570 | GEN_VSX_HELPER_2(xvaddsp, 0x00, 0x08, 0, PPC2_VSX) | |
7571 | GEN_VSX_HELPER_2(xvsubsp, 0x00, 0x09, 0, PPC2_VSX) | |
5e591d88 | 7572 | GEN_VSX_HELPER_2(xvmulsp, 0x00, 0x0A, 0, PPC2_VSX) |
4b98eeef | 7573 | GEN_VSX_HELPER_2(xvdivsp, 0x00, 0x0B, 0, PPC2_VSX) |
2009227f | 7574 | GEN_VSX_HELPER_2(xvresp, 0x14, 0x09, 0, PPC2_VSX) |
d32404fe | 7575 | GEN_VSX_HELPER_2(xvsqrtsp, 0x16, 0x08, 0, PPC2_VSX) |
d3f9df8f | 7576 | GEN_VSX_HELPER_2(xvrsqrtesp, 0x14, 0x08, 0, PPC2_VSX) |
bc80838f | 7577 | GEN_VSX_HELPER_2(xvtdivsp, 0x14, 0x0B, 0, PPC2_VSX) |
5cb151ac | 7578 | GEN_VSX_HELPER_2(xvtsqrtsp, 0x14, 0x0A, 0, PPC2_VSX) |
595c6eef TM |
7579 | GEN_VSX_HELPER_2(xvmaddasp, 0x04, 0x08, 0, PPC2_VSX) |
7580 | GEN_VSX_HELPER_2(xvmaddmsp, 0x04, 0x09, 0, PPC2_VSX) | |
7581 | GEN_VSX_HELPER_2(xvmsubasp, 0x04, 0x0A, 0, PPC2_VSX) | |
7582 | GEN_VSX_HELPER_2(xvmsubmsp, 0x04, 0x0B, 0, PPC2_VSX) | |
7583 | GEN_VSX_HELPER_2(xvnmaddasp, 0x04, 0x18, 0, PPC2_VSX) | |
7584 | GEN_VSX_HELPER_2(xvnmaddmsp, 0x04, 0x19, 0, PPC2_VSX) | |
7585 | GEN_VSX_HELPER_2(xvnmsubasp, 0x04, 0x1A, 0, PPC2_VSX) | |
7586 | GEN_VSX_HELPER_2(xvnmsubmsp, 0x04, 0x1B, 0, PPC2_VSX) | |
959e9c9d TM |
7587 | GEN_VSX_HELPER_2(xvmaxsp, 0x00, 0x18, 0, PPC2_VSX) |
7588 | GEN_VSX_HELPER_2(xvminsp, 0x00, 0x19, 0, PPC2_VSX) | |
354a6dec TM |
7589 | GEN_VSX_HELPER_2(xvcmpeqsp, 0x0C, 0x08, 0, PPC2_VSX) |
7590 | GEN_VSX_HELPER_2(xvcmpgtsp, 0x0C, 0x09, 0, PPC2_VSX) | |
7591 | GEN_VSX_HELPER_2(xvcmpgesp, 0x0C, 0x0A, 0, PPC2_VSX) | |
ed8ac568 | 7592 | GEN_VSX_HELPER_2(xvcvspdp, 0x12, 0x1C, 0, PPC2_VSX) |
5177d2ca TM |
7593 | GEN_VSX_HELPER_2(xvcvspsxds, 0x10, 0x19, 0, PPC2_VSX) |
7594 | GEN_VSX_HELPER_2(xvcvspsxws, 0x10, 0x09, 0, PPC2_VSX) | |
7595 | GEN_VSX_HELPER_2(xvcvspuxds, 0x10, 0x18, 0, PPC2_VSX) | |
7596 | GEN_VSX_HELPER_2(xvcvspuxws, 0x10, 0x08, 0, PPC2_VSX) | |
7597 | GEN_VSX_HELPER_2(xvcvsxdsp, 0x10, 0x1B, 0, PPC2_VSX) | |
7598 | GEN_VSX_HELPER_2(xvcvuxdsp, 0x10, 0x1A, 0, PPC2_VSX) | |
7599 | GEN_VSX_HELPER_2(xvcvsxwsp, 0x10, 0x0B, 0, PPC2_VSX) | |
7600 | GEN_VSX_HELPER_2(xvcvuxwsp, 0x10, 0x0A, 0, PPC2_VSX) | |
88e33d08 TM |
7601 | GEN_VSX_HELPER_2(xvrspi, 0x12, 0x08, 0, PPC2_VSX) |
7602 | GEN_VSX_HELPER_2(xvrspic, 0x16, 0x0A, 0, PPC2_VSX) | |
7603 | GEN_VSX_HELPER_2(xvrspim, 0x12, 0x0B, 0, PPC2_VSX) | |
7604 | GEN_VSX_HELPER_2(xvrspip, 0x12, 0x0A, 0, PPC2_VSX) | |
7605 | GEN_VSX_HELPER_2(xvrspiz, 0x12, 0x09, 0, PPC2_VSX) | |
ee6e02c0 | 7606 | |
79ca8a6a TM |
7607 | #define VSX_LOGICAL(name, tcg_op) \ |
7608 | static void glue(gen_, name)(DisasContext * ctx) \ | |
7609 | { \ | |
7610 | if (unlikely(!ctx->vsx_enabled)) { \ | |
7611 | gen_exception(ctx, POWERPC_EXCP_VSXU); \ | |
7612 | return; \ | |
7613 | } \ | |
7614 | tcg_op(cpu_vsrh(xT(ctx->opcode)), cpu_vsrh(xA(ctx->opcode)), \ | |
7615 | cpu_vsrh(xB(ctx->opcode))); \ | |
7616 | tcg_op(cpu_vsrl(xT(ctx->opcode)), cpu_vsrl(xA(ctx->opcode)), \ | |
7617 | cpu_vsrl(xB(ctx->opcode))); \ | |
7618 | } | |
7619 | ||
f976b09e AG |
7620 | VSX_LOGICAL(xxland, tcg_gen_and_i64) |
7621 | VSX_LOGICAL(xxlandc, tcg_gen_andc_i64) | |
7622 | VSX_LOGICAL(xxlor, tcg_gen_or_i64) | |
7623 | VSX_LOGICAL(xxlxor, tcg_gen_xor_i64) | |
7624 | VSX_LOGICAL(xxlnor, tcg_gen_nor_i64) | |
67a33f37 TM |
7625 | VSX_LOGICAL(xxleqv, tcg_gen_eqv_i64) |
7626 | VSX_LOGICAL(xxlnand, tcg_gen_nand_i64) | |
7627 | VSX_LOGICAL(xxlorc, tcg_gen_orc_i64) | |
df020ce0 | 7628 | |
ce577d2e TM |
7629 | #define VSX_XXMRG(name, high) \ |
7630 | static void glue(gen_, name)(DisasContext * ctx) \ | |
7631 | { \ | |
7632 | TCGv_i64 a0, a1, b0, b1; \ | |
7633 | if (unlikely(!ctx->vsx_enabled)) { \ | |
7634 | gen_exception(ctx, POWERPC_EXCP_VSXU); \ | |
7635 | return; \ | |
7636 | } \ | |
f976b09e AG |
7637 | a0 = tcg_temp_new_i64(); \ |
7638 | a1 = tcg_temp_new_i64(); \ | |
7639 | b0 = tcg_temp_new_i64(); \ | |
7640 | b1 = tcg_temp_new_i64(); \ | |
ce577d2e TM |
7641 | if (high) { \ |
7642 | tcg_gen_mov_i64(a0, cpu_vsrh(xA(ctx->opcode))); \ | |
7643 | tcg_gen_mov_i64(a1, cpu_vsrh(xA(ctx->opcode))); \ | |
7644 | tcg_gen_mov_i64(b0, cpu_vsrh(xB(ctx->opcode))); \ | |
7645 | tcg_gen_mov_i64(b1, cpu_vsrh(xB(ctx->opcode))); \ | |
7646 | } else { \ | |
7647 | tcg_gen_mov_i64(a0, cpu_vsrl(xA(ctx->opcode))); \ | |
7648 | tcg_gen_mov_i64(a1, cpu_vsrl(xA(ctx->opcode))); \ | |
7649 | tcg_gen_mov_i64(b0, cpu_vsrl(xB(ctx->opcode))); \ | |
7650 | tcg_gen_mov_i64(b1, cpu_vsrl(xB(ctx->opcode))); \ | |
7651 | } \ | |
7652 | tcg_gen_shri_i64(a0, a0, 32); \ | |
7653 | tcg_gen_shri_i64(b0, b0, 32); \ | |
7654 | tcg_gen_deposit_i64(cpu_vsrh(xT(ctx->opcode)), \ | |
7655 | b0, a0, 32, 32); \ | |
7656 | tcg_gen_deposit_i64(cpu_vsrl(xT(ctx->opcode)), \ | |
7657 | b1, a1, 32, 32); \ | |
f976b09e AG |
7658 | tcg_temp_free_i64(a0); \ |
7659 | tcg_temp_free_i64(a1); \ | |
7660 | tcg_temp_free_i64(b0); \ | |
7661 | tcg_temp_free_i64(b1); \ | |
ce577d2e TM |
7662 | } |
7663 | ||
7664 | VSX_XXMRG(xxmrghw, 1) | |
7665 | VSX_XXMRG(xxmrglw, 0) | |
7666 | ||
551e3ef7 TM |
7667 | static void gen_xxsel(DisasContext * ctx) |
7668 | { | |
7669 | TCGv_i64 a, b, c; | |
7670 | if (unlikely(!ctx->vsx_enabled)) { | |
7671 | gen_exception(ctx, POWERPC_EXCP_VSXU); | |
7672 | return; | |
7673 | } | |
f976b09e AG |
7674 | a = tcg_temp_new_i64(); |
7675 | b = tcg_temp_new_i64(); | |
7676 | c = tcg_temp_new_i64(); | |
551e3ef7 TM |
7677 | |
7678 | tcg_gen_mov_i64(a, cpu_vsrh(xA(ctx->opcode))); | |
7679 | tcg_gen_mov_i64(b, cpu_vsrh(xB(ctx->opcode))); | |
7680 | tcg_gen_mov_i64(c, cpu_vsrh(xC(ctx->opcode))); | |
7681 | ||
7682 | tcg_gen_and_i64(b, b, c); | |
7683 | tcg_gen_andc_i64(a, a, c); | |
7684 | tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), a, b); | |
7685 | ||
7686 | tcg_gen_mov_i64(a, cpu_vsrl(xA(ctx->opcode))); | |
7687 | tcg_gen_mov_i64(b, cpu_vsrl(xB(ctx->opcode))); | |
7688 | tcg_gen_mov_i64(c, cpu_vsrl(xC(ctx->opcode))); | |
7689 | ||
7690 | tcg_gen_and_i64(b, b, c); | |
7691 | tcg_gen_andc_i64(a, a, c); | |
7692 | tcg_gen_or_i64(cpu_vsrl(xT(ctx->opcode)), a, b); | |
7693 | ||
f976b09e AG |
7694 | tcg_temp_free_i64(a); |
7695 | tcg_temp_free_i64(b); | |
7696 | tcg_temp_free_i64(c); | |
551e3ef7 TM |
7697 | } |
7698 | ||
76c15fe0 TM |
7699 | static void gen_xxspltw(DisasContext *ctx) |
7700 | { | |
7701 | TCGv_i64 b, b2; | |
7702 | TCGv_i64 vsr = (UIM(ctx->opcode) & 2) ? | |
7703 | cpu_vsrl(xB(ctx->opcode)) : | |
7704 | cpu_vsrh(xB(ctx->opcode)); | |
7705 | ||
7706 | if (unlikely(!ctx->vsx_enabled)) { | |
7707 | gen_exception(ctx, POWERPC_EXCP_VSXU); | |
7708 | return; | |
7709 | } | |
7710 | ||
f976b09e AG |
7711 | b = tcg_temp_new_i64(); |
7712 | b2 = tcg_temp_new_i64(); | |
76c15fe0 TM |
7713 | |
7714 | if (UIM(ctx->opcode) & 1) { | |
7715 | tcg_gen_ext32u_i64(b, vsr); | |
7716 | } else { | |
7717 | tcg_gen_shri_i64(b, vsr, 32); | |
7718 | } | |
7719 | ||
7720 | tcg_gen_shli_i64(b2, b, 32); | |
7721 | tcg_gen_or_i64(cpu_vsrh(xT(ctx->opcode)), b, b2); | |
7722 | tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), cpu_vsrh(xT(ctx->opcode))); | |
7723 | ||
f976b09e AG |
7724 | tcg_temp_free_i64(b); |
7725 | tcg_temp_free_i64(b2); | |
76c15fe0 TM |
7726 | } |
7727 | ||
acc42968 TM |
7728 | static void gen_xxsldwi(DisasContext *ctx) |
7729 | { | |
7730 | TCGv_i64 xth, xtl; | |
7731 | if (unlikely(!ctx->vsx_enabled)) { | |
7732 | gen_exception(ctx, POWERPC_EXCP_VSXU); | |
7733 | return; | |
7734 | } | |
f976b09e AG |
7735 | xth = tcg_temp_new_i64(); |
7736 | xtl = tcg_temp_new_i64(); | |
acc42968 TM |
7737 | |
7738 | switch (SHW(ctx->opcode)) { | |
7739 | case 0: { | |
7740 | tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode))); | |
7741 | tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode))); | |
7742 | break; | |
7743 | } | |
7744 | case 1: { | |
f976b09e | 7745 | TCGv_i64 t0 = tcg_temp_new_i64(); |
acc42968 TM |
7746 | tcg_gen_mov_i64(xth, cpu_vsrh(xA(ctx->opcode))); |
7747 | tcg_gen_shli_i64(xth, xth, 32); | |
7748 | tcg_gen_mov_i64(t0, cpu_vsrl(xA(ctx->opcode))); | |
7749 | tcg_gen_shri_i64(t0, t0, 32); | |
7750 | tcg_gen_or_i64(xth, xth, t0); | |
7751 | tcg_gen_mov_i64(xtl, cpu_vsrl(xA(ctx->opcode))); | |
7752 | tcg_gen_shli_i64(xtl, xtl, 32); | |
7753 | tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode))); | |
7754 | tcg_gen_shri_i64(t0, t0, 32); | |
7755 | tcg_gen_or_i64(xtl, xtl, t0); | |
f976b09e | 7756 | tcg_temp_free_i64(t0); |
acc42968 TM |
7757 | break; |
7758 | } | |
7759 | case 2: { | |
7760 | tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode))); | |
7761 | tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode))); | |
7762 | break; | |
7763 | } | |
7764 | case 3: { | |
f976b09e | 7765 | TCGv_i64 t0 = tcg_temp_new_i64(); |
acc42968 TM |
7766 | tcg_gen_mov_i64(xth, cpu_vsrl(xA(ctx->opcode))); |
7767 | tcg_gen_shli_i64(xth, xth, 32); | |
7768 | tcg_gen_mov_i64(t0, cpu_vsrh(xB(ctx->opcode))); | |
7769 | tcg_gen_shri_i64(t0, t0, 32); | |
7770 | tcg_gen_or_i64(xth, xth, t0); | |
7771 | tcg_gen_mov_i64(xtl, cpu_vsrh(xB(ctx->opcode))); | |
7772 | tcg_gen_shli_i64(xtl, xtl, 32); | |
7773 | tcg_gen_mov_i64(t0, cpu_vsrl(xB(ctx->opcode))); | |
7774 | tcg_gen_shri_i64(t0, t0, 32); | |
7775 | tcg_gen_or_i64(xtl, xtl, t0); | |
f976b09e | 7776 | tcg_temp_free_i64(t0); |
acc42968 TM |
7777 | break; |
7778 | } | |
7779 | } | |
7780 | ||
7781 | tcg_gen_mov_i64(cpu_vsrh(xT(ctx->opcode)), xth); | |
7782 | tcg_gen_mov_i64(cpu_vsrl(xT(ctx->opcode)), xtl); | |
7783 | ||
f976b09e AG |
7784 | tcg_temp_free_i64(xth); |
7785 | tcg_temp_free_i64(xtl); | |
acc42968 TM |
7786 | } |
7787 | ||
ce577d2e | 7788 | |
0487d6a8 | 7789 | /*** SPE extension ***/ |
0487d6a8 | 7790 | /* Register moves */ |
3cd7d1dd | 7791 | |
a0e13900 FC |
7792 | static inline void gen_evmra(DisasContext *ctx) |
7793 | { | |
7794 | ||
7795 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 7796 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
7797 | return; |
7798 | } | |
7799 | ||
7800 | #if defined(TARGET_PPC64) | |
7801 | /* rD := rA */ | |
7802 | tcg_gen_mov_i64(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
7803 | ||
7804 | /* spe_acc := rA */ | |
7805 | tcg_gen_st_i64(cpu_gpr[rA(ctx->opcode)], | |
7806 | cpu_env, | |
1328c2bf | 7807 | offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
7808 | #else |
7809 | TCGv_i64 tmp = tcg_temp_new_i64(); | |
7810 | ||
7811 | /* tmp := rA_lo + rA_hi << 32 */ | |
7812 | tcg_gen_concat_i32_i64(tmp, cpu_gpr[rA(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
7813 | ||
7814 | /* spe_acc := tmp */ | |
1328c2bf | 7815 | tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
7816 | tcg_temp_free_i64(tmp); |
7817 | ||
7818 | /* rD := rA */ | |
7819 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
7820 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
7821 | #endif | |
7822 | } | |
7823 | ||
636aa200 BS |
7824 | static inline void gen_load_gpr64(TCGv_i64 t, int reg) |
7825 | { | |
f78fb44e AJ |
7826 | #if defined(TARGET_PPC64) |
7827 | tcg_gen_mov_i64(t, cpu_gpr[reg]); | |
7828 | #else | |
36aa55dc | 7829 | tcg_gen_concat_i32_i64(t, cpu_gpr[reg], cpu_gprh[reg]); |
3cd7d1dd | 7830 | #endif |
f78fb44e | 7831 | } |
3cd7d1dd | 7832 | |
636aa200 BS |
7833 | static inline void gen_store_gpr64(int reg, TCGv_i64 t) |
7834 | { | |
f78fb44e AJ |
7835 | #if defined(TARGET_PPC64) |
7836 | tcg_gen_mov_i64(cpu_gpr[reg], t); | |
7837 | #else | |
a7812ae4 | 7838 | TCGv_i64 tmp = tcg_temp_new_i64(); |
f78fb44e | 7839 | tcg_gen_trunc_i64_i32(cpu_gpr[reg], t); |
f78fb44e AJ |
7840 | tcg_gen_shri_i64(tmp, t, 32); |
7841 | tcg_gen_trunc_i64_i32(cpu_gprh[reg], tmp); | |
a7812ae4 | 7842 | tcg_temp_free_i64(tmp); |
3cd7d1dd | 7843 | #endif |
f78fb44e | 7844 | } |
3cd7d1dd | 7845 | |
70560da7 | 7846 | #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \ |
99e300ef | 7847 | static void glue(gen_, name0##_##name1)(DisasContext *ctx) \ |
0487d6a8 JM |
7848 | { \ |
7849 | if (Rc(ctx->opcode)) \ | |
7850 | gen_##name1(ctx); \ | |
7851 | else \ | |
7852 | gen_##name0(ctx); \ | |
7853 | } | |
7854 | ||
7855 | /* Handler for undefined SPE opcodes */ | |
636aa200 | 7856 | static inline void gen_speundef(DisasContext *ctx) |
0487d6a8 | 7857 | { |
e06fcd75 | 7858 | gen_inval_exception(ctx, POWERPC_EXCP_INVAL_INVAL); |
0487d6a8 JM |
7859 | } |
7860 | ||
57951c27 AJ |
7861 | /* SPE logic */ |
7862 | #if defined(TARGET_PPC64) | |
7863 | #define GEN_SPEOP_LOGIC2(name, tcg_op) \ | |
636aa200 | 7864 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
7865 | { \ |
7866 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7867 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
7868 | return; \ |
7869 | } \ | |
57951c27 AJ |
7870 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \ |
7871 | cpu_gpr[rB(ctx->opcode)]); \ | |
7872 | } | |
7873 | #else | |
7874 | #define GEN_SPEOP_LOGIC2(name, tcg_op) \ | |
636aa200 | 7875 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
7876 | { \ |
7877 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7878 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
7879 | return; \ |
7880 | } \ | |
7881 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \ | |
7882 | cpu_gpr[rB(ctx->opcode)]); \ | |
7883 | tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \ | |
7884 | cpu_gprh[rB(ctx->opcode)]); \ | |
0487d6a8 | 7885 | } |
57951c27 AJ |
7886 | #endif |
7887 | ||
7888 | GEN_SPEOP_LOGIC2(evand, tcg_gen_and_tl); | |
7889 | GEN_SPEOP_LOGIC2(evandc, tcg_gen_andc_tl); | |
7890 | GEN_SPEOP_LOGIC2(evxor, tcg_gen_xor_tl); | |
7891 | GEN_SPEOP_LOGIC2(evor, tcg_gen_or_tl); | |
7892 | GEN_SPEOP_LOGIC2(evnor, tcg_gen_nor_tl); | |
7893 | GEN_SPEOP_LOGIC2(eveqv, tcg_gen_eqv_tl); | |
7894 | GEN_SPEOP_LOGIC2(evorc, tcg_gen_orc_tl); | |
7895 | GEN_SPEOP_LOGIC2(evnand, tcg_gen_nand_tl); | |
0487d6a8 | 7896 | |
57951c27 AJ |
7897 | /* SPE logic immediate */ |
7898 | #if defined(TARGET_PPC64) | |
7899 | #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \ | |
636aa200 | 7900 | static inline void gen_##name(DisasContext *ctx) \ |
3d3a6a0a AJ |
7901 | { \ |
7902 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7903 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
3d3a6a0a AJ |
7904 | return; \ |
7905 | } \ | |
a7812ae4 PB |
7906 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
7907 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
7908 | TCGv_i64 t2 = tcg_temp_local_new_i64(); \ | |
57951c27 AJ |
7909 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ |
7910 | tcg_opi(t0, t0, rB(ctx->opcode)); \ | |
7911 | tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \ | |
7912 | tcg_gen_trunc_i64_i32(t1, t2); \ | |
a7812ae4 | 7913 | tcg_temp_free_i64(t2); \ |
57951c27 AJ |
7914 | tcg_opi(t1, t1, rB(ctx->opcode)); \ |
7915 | tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \ | |
a7812ae4 PB |
7916 | tcg_temp_free_i32(t0); \ |
7917 | tcg_temp_free_i32(t1); \ | |
3d3a6a0a | 7918 | } |
57951c27 AJ |
7919 | #else |
7920 | #define GEN_SPEOP_TCG_LOGIC_IMM2(name, tcg_opi) \ | |
636aa200 | 7921 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
7922 | { \ |
7923 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7924 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
7925 | return; \ |
7926 | } \ | |
57951c27 AJ |
7927 | tcg_opi(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \ |
7928 | rB(ctx->opcode)); \ | |
7929 | tcg_opi(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \ | |
7930 | rB(ctx->opcode)); \ | |
0487d6a8 | 7931 | } |
57951c27 AJ |
7932 | #endif |
7933 | GEN_SPEOP_TCG_LOGIC_IMM2(evslwi, tcg_gen_shli_i32); | |
7934 | GEN_SPEOP_TCG_LOGIC_IMM2(evsrwiu, tcg_gen_shri_i32); | |
7935 | GEN_SPEOP_TCG_LOGIC_IMM2(evsrwis, tcg_gen_sari_i32); | |
7936 | GEN_SPEOP_TCG_LOGIC_IMM2(evrlwi, tcg_gen_rotli_i32); | |
0487d6a8 | 7937 | |
57951c27 AJ |
7938 | /* SPE arithmetic */ |
7939 | #if defined(TARGET_PPC64) | |
7940 | #define GEN_SPEOP_ARITH1(name, tcg_op) \ | |
636aa200 | 7941 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
7942 | { \ |
7943 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7944 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
7945 | return; \ |
7946 | } \ | |
a7812ae4 PB |
7947 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
7948 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
7949 | TCGv_i64 t2 = tcg_temp_local_new_i64(); \ | |
57951c27 AJ |
7950 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ |
7951 | tcg_op(t0, t0); \ | |
7952 | tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \ | |
7953 | tcg_gen_trunc_i64_i32(t1, t2); \ | |
a7812ae4 | 7954 | tcg_temp_free_i64(t2); \ |
57951c27 AJ |
7955 | tcg_op(t1, t1); \ |
7956 | tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \ | |
a7812ae4 PB |
7957 | tcg_temp_free_i32(t0); \ |
7958 | tcg_temp_free_i32(t1); \ | |
0487d6a8 | 7959 | } |
57951c27 | 7960 | #else |
a7812ae4 | 7961 | #define GEN_SPEOP_ARITH1(name, tcg_op) \ |
636aa200 | 7962 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
7963 | { \ |
7964 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 7965 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
7966 | return; \ |
7967 | } \ | |
7968 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); \ | |
7969 | tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); \ | |
7970 | } | |
7971 | #endif | |
0487d6a8 | 7972 | |
636aa200 | 7973 | static inline void gen_op_evabs(TCGv_i32 ret, TCGv_i32 arg1) |
57951c27 AJ |
7974 | { |
7975 | int l1 = gen_new_label(); | |
7976 | int l2 = gen_new_label(); | |
0487d6a8 | 7977 | |
57951c27 AJ |
7978 | tcg_gen_brcondi_i32(TCG_COND_GE, arg1, 0, l1); |
7979 | tcg_gen_neg_i32(ret, arg1); | |
7980 | tcg_gen_br(l2); | |
7981 | gen_set_label(l1); | |
a7812ae4 | 7982 | tcg_gen_mov_i32(ret, arg1); |
57951c27 AJ |
7983 | gen_set_label(l2); |
7984 | } | |
7985 | GEN_SPEOP_ARITH1(evabs, gen_op_evabs); | |
7986 | GEN_SPEOP_ARITH1(evneg, tcg_gen_neg_i32); | |
7987 | GEN_SPEOP_ARITH1(evextsb, tcg_gen_ext8s_i32); | |
7988 | GEN_SPEOP_ARITH1(evextsh, tcg_gen_ext16s_i32); | |
636aa200 | 7989 | static inline void gen_op_evrndw(TCGv_i32 ret, TCGv_i32 arg1) |
0487d6a8 | 7990 | { |
57951c27 AJ |
7991 | tcg_gen_addi_i32(ret, arg1, 0x8000); |
7992 | tcg_gen_ext16u_i32(ret, ret); | |
7993 | } | |
7994 | GEN_SPEOP_ARITH1(evrndw, gen_op_evrndw); | |
a7812ae4 PB |
7995 | GEN_SPEOP_ARITH1(evcntlsw, gen_helper_cntlsw32); |
7996 | GEN_SPEOP_ARITH1(evcntlzw, gen_helper_cntlzw32); | |
0487d6a8 | 7997 | |
57951c27 AJ |
7998 | #if defined(TARGET_PPC64) |
7999 | #define GEN_SPEOP_ARITH2(name, tcg_op) \ | |
636aa200 | 8000 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
8001 | { \ |
8002 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8003 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
8004 | return; \ |
8005 | } \ | |
a7812ae4 PB |
8006 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
8007 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
8008 | TCGv_i32 t2 = tcg_temp_local_new_i32(); \ | |
501e23c4 | 8009 | TCGv_i64 t3 = tcg_temp_local_new_i64(); \ |
57951c27 AJ |
8010 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ |
8011 | tcg_gen_trunc_i64_i32(t2, cpu_gpr[rB(ctx->opcode)]); \ | |
8012 | tcg_op(t0, t0, t2); \ | |
8013 | tcg_gen_shri_i64(t3, cpu_gpr[rA(ctx->opcode)], 32); \ | |
8014 | tcg_gen_trunc_i64_i32(t1, t3); \ | |
8015 | tcg_gen_shri_i64(t3, cpu_gpr[rB(ctx->opcode)], 32); \ | |
8016 | tcg_gen_trunc_i64_i32(t2, t3); \ | |
a7812ae4 | 8017 | tcg_temp_free_i64(t3); \ |
57951c27 | 8018 | tcg_op(t1, t1, t2); \ |
a7812ae4 | 8019 | tcg_temp_free_i32(t2); \ |
57951c27 | 8020 | tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \ |
a7812ae4 PB |
8021 | tcg_temp_free_i32(t0); \ |
8022 | tcg_temp_free_i32(t1); \ | |
0487d6a8 | 8023 | } |
57951c27 AJ |
8024 | #else |
8025 | #define GEN_SPEOP_ARITH2(name, tcg_op) \ | |
636aa200 | 8026 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 JM |
8027 | { \ |
8028 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8029 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
0487d6a8 JM |
8030 | return; \ |
8031 | } \ | |
57951c27 AJ |
8032 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], \ |
8033 | cpu_gpr[rB(ctx->opcode)]); \ | |
8034 | tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], \ | |
8035 | cpu_gprh[rB(ctx->opcode)]); \ | |
0487d6a8 | 8036 | } |
57951c27 | 8037 | #endif |
0487d6a8 | 8038 | |
636aa200 | 8039 | static inline void gen_op_evsrwu(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
57951c27 | 8040 | { |
a7812ae4 | 8041 | TCGv_i32 t0; |
57951c27 | 8042 | int l1, l2; |
0487d6a8 | 8043 | |
57951c27 AJ |
8044 | l1 = gen_new_label(); |
8045 | l2 = gen_new_label(); | |
a7812ae4 | 8046 | t0 = tcg_temp_local_new_i32(); |
57951c27 AJ |
8047 | /* No error here: 6 bits are used */ |
8048 | tcg_gen_andi_i32(t0, arg2, 0x3F); | |
8049 | tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1); | |
8050 | tcg_gen_shr_i32(ret, arg1, t0); | |
8051 | tcg_gen_br(l2); | |
8052 | gen_set_label(l1); | |
8053 | tcg_gen_movi_i32(ret, 0); | |
0aef4261 | 8054 | gen_set_label(l2); |
a7812ae4 | 8055 | tcg_temp_free_i32(t0); |
57951c27 AJ |
8056 | } |
8057 | GEN_SPEOP_ARITH2(evsrwu, gen_op_evsrwu); | |
636aa200 | 8058 | static inline void gen_op_evsrws(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
57951c27 | 8059 | { |
a7812ae4 | 8060 | TCGv_i32 t0; |
57951c27 AJ |
8061 | int l1, l2; |
8062 | ||
8063 | l1 = gen_new_label(); | |
8064 | l2 = gen_new_label(); | |
a7812ae4 | 8065 | t0 = tcg_temp_local_new_i32(); |
57951c27 AJ |
8066 | /* No error here: 6 bits are used */ |
8067 | tcg_gen_andi_i32(t0, arg2, 0x3F); | |
8068 | tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1); | |
8069 | tcg_gen_sar_i32(ret, arg1, t0); | |
8070 | tcg_gen_br(l2); | |
8071 | gen_set_label(l1); | |
8072 | tcg_gen_movi_i32(ret, 0); | |
0aef4261 | 8073 | gen_set_label(l2); |
a7812ae4 | 8074 | tcg_temp_free_i32(t0); |
57951c27 AJ |
8075 | } |
8076 | GEN_SPEOP_ARITH2(evsrws, gen_op_evsrws); | |
636aa200 | 8077 | static inline void gen_op_evslw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
57951c27 | 8078 | { |
a7812ae4 | 8079 | TCGv_i32 t0; |
57951c27 AJ |
8080 | int l1, l2; |
8081 | ||
8082 | l1 = gen_new_label(); | |
8083 | l2 = gen_new_label(); | |
a7812ae4 | 8084 | t0 = tcg_temp_local_new_i32(); |
57951c27 AJ |
8085 | /* No error here: 6 bits are used */ |
8086 | tcg_gen_andi_i32(t0, arg2, 0x3F); | |
8087 | tcg_gen_brcondi_i32(TCG_COND_GE, t0, 32, l1); | |
8088 | tcg_gen_shl_i32(ret, arg1, t0); | |
8089 | tcg_gen_br(l2); | |
8090 | gen_set_label(l1); | |
8091 | tcg_gen_movi_i32(ret, 0); | |
e29ef9fa | 8092 | gen_set_label(l2); |
a7812ae4 | 8093 | tcg_temp_free_i32(t0); |
57951c27 AJ |
8094 | } |
8095 | GEN_SPEOP_ARITH2(evslw, gen_op_evslw); | |
636aa200 | 8096 | static inline void gen_op_evrlw(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
57951c27 | 8097 | { |
a7812ae4 | 8098 | TCGv_i32 t0 = tcg_temp_new_i32(); |
57951c27 AJ |
8099 | tcg_gen_andi_i32(t0, arg2, 0x1F); |
8100 | tcg_gen_rotl_i32(ret, arg1, t0); | |
a7812ae4 | 8101 | tcg_temp_free_i32(t0); |
57951c27 AJ |
8102 | } |
8103 | GEN_SPEOP_ARITH2(evrlw, gen_op_evrlw); | |
636aa200 | 8104 | static inline void gen_evmergehi(DisasContext *ctx) |
57951c27 AJ |
8105 | { |
8106 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8107 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
57951c27 AJ |
8108 | return; |
8109 | } | |
8110 | #if defined(TARGET_PPC64) | |
a7812ae4 PB |
8111 | TCGv t0 = tcg_temp_new(); |
8112 | TCGv t1 = tcg_temp_new(); | |
57951c27 AJ |
8113 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32); |
8114 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL); | |
8115 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1); | |
8116 | tcg_temp_free(t0); | |
8117 | tcg_temp_free(t1); | |
8118 | #else | |
8119 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); | |
8120 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
8121 | #endif | |
8122 | } | |
8123 | GEN_SPEOP_ARITH2(evaddw, tcg_gen_add_i32); | |
636aa200 | 8124 | static inline void gen_op_evsubf(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2) |
0487d6a8 | 8125 | { |
57951c27 AJ |
8126 | tcg_gen_sub_i32(ret, arg2, arg1); |
8127 | } | |
8128 | GEN_SPEOP_ARITH2(evsubfw, gen_op_evsubf); | |
0487d6a8 | 8129 | |
57951c27 AJ |
8130 | /* SPE arithmetic immediate */ |
8131 | #if defined(TARGET_PPC64) | |
8132 | #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \ | |
636aa200 | 8133 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
8134 | { \ |
8135 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8136 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
8137 | return; \ |
8138 | } \ | |
a7812ae4 PB |
8139 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
8140 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
8141 | TCGv_i64 t2 = tcg_temp_local_new_i64(); \ | |
57951c27 AJ |
8142 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rB(ctx->opcode)]); \ |
8143 | tcg_op(t0, t0, rA(ctx->opcode)); \ | |
8144 | tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \ | |
8145 | tcg_gen_trunc_i64_i32(t1, t2); \ | |
e06fcd75 | 8146 | tcg_temp_free_i64(t2); \ |
57951c27 AJ |
8147 | tcg_op(t1, t1, rA(ctx->opcode)); \ |
8148 | tcg_gen_concat_i32_i64(cpu_gpr[rD(ctx->opcode)], t0, t1); \ | |
a7812ae4 PB |
8149 | tcg_temp_free_i32(t0); \ |
8150 | tcg_temp_free_i32(t1); \ | |
57951c27 AJ |
8151 | } |
8152 | #else | |
8153 | #define GEN_SPEOP_ARITH_IMM2(name, tcg_op) \ | |
636aa200 | 8154 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
8155 | { \ |
8156 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8157 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
8158 | return; \ |
8159 | } \ | |
8160 | tcg_op(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)], \ | |
8161 | rA(ctx->opcode)); \ | |
8162 | tcg_op(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)], \ | |
8163 | rA(ctx->opcode)); \ | |
8164 | } | |
8165 | #endif | |
8166 | GEN_SPEOP_ARITH_IMM2(evaddiw, tcg_gen_addi_i32); | |
8167 | GEN_SPEOP_ARITH_IMM2(evsubifw, tcg_gen_subi_i32); | |
8168 | ||
8169 | /* SPE comparison */ | |
8170 | #if defined(TARGET_PPC64) | |
8171 | #define GEN_SPEOP_COMP(name, tcg_cond) \ | |
636aa200 | 8172 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
8173 | { \ |
8174 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8175 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
8176 | return; \ |
8177 | } \ | |
8178 | int l1 = gen_new_label(); \ | |
8179 | int l2 = gen_new_label(); \ | |
8180 | int l3 = gen_new_label(); \ | |
8181 | int l4 = gen_new_label(); \ | |
a7812ae4 PB |
8182 | TCGv_i32 t0 = tcg_temp_local_new_i32(); \ |
8183 | TCGv_i32 t1 = tcg_temp_local_new_i32(); \ | |
8184 | TCGv_i64 t2 = tcg_temp_local_new_i64(); \ | |
57951c27 AJ |
8185 | tcg_gen_trunc_i64_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ |
8186 | tcg_gen_trunc_i64_i32(t1, cpu_gpr[rB(ctx->opcode)]); \ | |
8187 | tcg_gen_brcond_i32(tcg_cond, t0, t1, l1); \ | |
a7812ae4 | 8188 | tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], 0); \ |
57951c27 AJ |
8189 | tcg_gen_br(l2); \ |
8190 | gen_set_label(l1); \ | |
8191 | tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \ | |
8192 | CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \ | |
8193 | gen_set_label(l2); \ | |
8194 | tcg_gen_shri_i64(t2, cpu_gpr[rA(ctx->opcode)], 32); \ | |
8195 | tcg_gen_trunc_i64_i32(t0, t2); \ | |
8196 | tcg_gen_shri_i64(t2, cpu_gpr[rB(ctx->opcode)], 32); \ | |
8197 | tcg_gen_trunc_i64_i32(t1, t2); \ | |
a7812ae4 | 8198 | tcg_temp_free_i64(t2); \ |
57951c27 AJ |
8199 | tcg_gen_brcond_i32(tcg_cond, t0, t1, l3); \ |
8200 | tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \ | |
8201 | ~(CRF_CH | CRF_CH_AND_CL)); \ | |
8202 | tcg_gen_br(l4); \ | |
8203 | gen_set_label(l3); \ | |
8204 | tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \ | |
8205 | CRF_CH | CRF_CH_OR_CL); \ | |
8206 | gen_set_label(l4); \ | |
a7812ae4 PB |
8207 | tcg_temp_free_i32(t0); \ |
8208 | tcg_temp_free_i32(t1); \ | |
57951c27 AJ |
8209 | } |
8210 | #else | |
8211 | #define GEN_SPEOP_COMP(name, tcg_cond) \ | |
636aa200 | 8212 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
8213 | { \ |
8214 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8215 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
8216 | return; \ |
8217 | } \ | |
8218 | int l1 = gen_new_label(); \ | |
8219 | int l2 = gen_new_label(); \ | |
8220 | int l3 = gen_new_label(); \ | |
8221 | int l4 = gen_new_label(); \ | |
8222 | \ | |
8223 | tcg_gen_brcond_i32(tcg_cond, cpu_gpr[rA(ctx->opcode)], \ | |
8224 | cpu_gpr[rB(ctx->opcode)], l1); \ | |
8225 | tcg_gen_movi_tl(cpu_crf[crfD(ctx->opcode)], 0); \ | |
8226 | tcg_gen_br(l2); \ | |
8227 | gen_set_label(l1); \ | |
8228 | tcg_gen_movi_i32(cpu_crf[crfD(ctx->opcode)], \ | |
8229 | CRF_CL | CRF_CH_OR_CL | CRF_CH_AND_CL); \ | |
8230 | gen_set_label(l2); \ | |
8231 | tcg_gen_brcond_i32(tcg_cond, cpu_gprh[rA(ctx->opcode)], \ | |
8232 | cpu_gprh[rB(ctx->opcode)], l3); \ | |
8233 | tcg_gen_andi_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \ | |
8234 | ~(CRF_CH | CRF_CH_AND_CL)); \ | |
8235 | tcg_gen_br(l4); \ | |
8236 | gen_set_label(l3); \ | |
8237 | tcg_gen_ori_i32(cpu_crf[crfD(ctx->opcode)], cpu_crf[crfD(ctx->opcode)], \ | |
8238 | CRF_CH | CRF_CH_OR_CL); \ | |
8239 | gen_set_label(l4); \ | |
8240 | } | |
8241 | #endif | |
8242 | GEN_SPEOP_COMP(evcmpgtu, TCG_COND_GTU); | |
8243 | GEN_SPEOP_COMP(evcmpgts, TCG_COND_GT); | |
8244 | GEN_SPEOP_COMP(evcmpltu, TCG_COND_LTU); | |
8245 | GEN_SPEOP_COMP(evcmplts, TCG_COND_LT); | |
8246 | GEN_SPEOP_COMP(evcmpeq, TCG_COND_EQ); | |
8247 | ||
8248 | /* SPE misc */ | |
636aa200 | 8249 | static inline void gen_brinc(DisasContext *ctx) |
57951c27 AJ |
8250 | { |
8251 | /* Note: brinc is usable even if SPE is disabled */ | |
a7812ae4 PB |
8252 | gen_helper_brinc(cpu_gpr[rD(ctx->opcode)], |
8253 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
0487d6a8 | 8254 | } |
636aa200 | 8255 | static inline void gen_evmergelo(DisasContext *ctx) |
57951c27 AJ |
8256 | { |
8257 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8258 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
57951c27 AJ |
8259 | return; |
8260 | } | |
8261 | #if defined(TARGET_PPC64) | |
a7812ae4 PB |
8262 | TCGv t0 = tcg_temp_new(); |
8263 | TCGv t1 = tcg_temp_new(); | |
17d9b3af | 8264 | tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]); |
57951c27 AJ |
8265 | tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32); |
8266 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1); | |
8267 | tcg_temp_free(t0); | |
8268 | tcg_temp_free(t1); | |
8269 | #else | |
57951c27 | 8270 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
33890b3e | 8271 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); |
57951c27 AJ |
8272 | #endif |
8273 | } | |
636aa200 | 8274 | static inline void gen_evmergehilo(DisasContext *ctx) |
57951c27 AJ |
8275 | { |
8276 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8277 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
57951c27 AJ |
8278 | return; |
8279 | } | |
8280 | #if defined(TARGET_PPC64) | |
a7812ae4 PB |
8281 | TCGv t0 = tcg_temp_new(); |
8282 | TCGv t1 = tcg_temp_new(); | |
17d9b3af | 8283 | tcg_gen_ext32u_tl(t0, cpu_gpr[rB(ctx->opcode)]); |
57951c27 AJ |
8284 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF0000000ULL); |
8285 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1); | |
8286 | tcg_temp_free(t0); | |
8287 | tcg_temp_free(t1); | |
8288 | #else | |
8289 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
8290 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
8291 | #endif | |
8292 | } | |
636aa200 | 8293 | static inline void gen_evmergelohi(DisasContext *ctx) |
57951c27 AJ |
8294 | { |
8295 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8296 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
57951c27 AJ |
8297 | return; |
8298 | } | |
8299 | #if defined(TARGET_PPC64) | |
a7812ae4 PB |
8300 | TCGv t0 = tcg_temp_new(); |
8301 | TCGv t1 = tcg_temp_new(); | |
57951c27 AJ |
8302 | tcg_gen_shri_tl(t0, cpu_gpr[rB(ctx->opcode)], 32); |
8303 | tcg_gen_shli_tl(t1, cpu_gpr[rA(ctx->opcode)], 32); | |
8304 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t0, t1); | |
8305 | tcg_temp_free(t0); | |
8306 | tcg_temp_free(t1); | |
8307 | #else | |
33890b3e NF |
8308 | if (rD(ctx->opcode) == rA(ctx->opcode)) { |
8309 | TCGv_i32 tmp = tcg_temp_new_i32(); | |
8310 | tcg_gen_mov_i32(tmp, cpu_gpr[rA(ctx->opcode)]); | |
8311 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); | |
8312 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], tmp); | |
8313 | tcg_temp_free_i32(tmp); | |
8314 | } else { | |
8315 | tcg_gen_mov_i32(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); | |
8316 | tcg_gen_mov_i32(cpu_gprh[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
8317 | } | |
57951c27 AJ |
8318 | #endif |
8319 | } | |
636aa200 | 8320 | static inline void gen_evsplati(DisasContext *ctx) |
57951c27 | 8321 | { |
ae01847f | 8322 | uint64_t imm = ((int32_t)(rA(ctx->opcode) << 27)) >> 27; |
0487d6a8 | 8323 | |
57951c27 | 8324 | #if defined(TARGET_PPC64) |
38d14952 | 8325 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm); |
57951c27 AJ |
8326 | #else |
8327 | tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm); | |
8328 | tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm); | |
8329 | #endif | |
8330 | } | |
636aa200 | 8331 | static inline void gen_evsplatfi(DisasContext *ctx) |
0487d6a8 | 8332 | { |
ae01847f | 8333 | uint64_t imm = rA(ctx->opcode) << 27; |
0487d6a8 | 8334 | |
57951c27 | 8335 | #if defined(TARGET_PPC64) |
38d14952 | 8336 | tcg_gen_movi_tl(cpu_gpr[rD(ctx->opcode)], (imm << 32) | imm); |
57951c27 AJ |
8337 | #else |
8338 | tcg_gen_movi_i32(cpu_gpr[rD(ctx->opcode)], imm); | |
8339 | tcg_gen_movi_i32(cpu_gprh[rD(ctx->opcode)], imm); | |
8340 | #endif | |
0487d6a8 JM |
8341 | } |
8342 | ||
636aa200 | 8343 | static inline void gen_evsel(DisasContext *ctx) |
57951c27 AJ |
8344 | { |
8345 | int l1 = gen_new_label(); | |
8346 | int l2 = gen_new_label(); | |
8347 | int l3 = gen_new_label(); | |
8348 | int l4 = gen_new_label(); | |
a7812ae4 | 8349 | TCGv_i32 t0 = tcg_temp_local_new_i32(); |
57951c27 | 8350 | #if defined(TARGET_PPC64) |
a7812ae4 PB |
8351 | TCGv t1 = tcg_temp_local_new(); |
8352 | TCGv t2 = tcg_temp_local_new(); | |
57951c27 AJ |
8353 | #endif |
8354 | tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 3); | |
8355 | tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l1); | |
8356 | #if defined(TARGET_PPC64) | |
8357 | tcg_gen_andi_tl(t1, cpu_gpr[rA(ctx->opcode)], 0xFFFFFFFF00000000ULL); | |
8358 | #else | |
8359 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)]); | |
8360 | #endif | |
8361 | tcg_gen_br(l2); | |
8362 | gen_set_label(l1); | |
8363 | #if defined(TARGET_PPC64) | |
8364 | tcg_gen_andi_tl(t1, cpu_gpr[rB(ctx->opcode)], 0xFFFFFFFF00000000ULL); | |
8365 | #else | |
8366 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rB(ctx->opcode)]); | |
8367 | #endif | |
8368 | gen_set_label(l2); | |
8369 | tcg_gen_andi_i32(t0, cpu_crf[ctx->opcode & 0x07], 1 << 2); | |
8370 | tcg_gen_brcondi_i32(TCG_COND_EQ, t0, 0, l3); | |
8371 | #if defined(TARGET_PPC64) | |
17d9b3af | 8372 | tcg_gen_ext32u_tl(t2, cpu_gpr[rA(ctx->opcode)]); |
57951c27 AJ |
8373 | #else |
8374 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); | |
8375 | #endif | |
8376 | tcg_gen_br(l4); | |
8377 | gen_set_label(l3); | |
8378 | #if defined(TARGET_PPC64) | |
17d9b3af | 8379 | tcg_gen_ext32u_tl(t2, cpu_gpr[rB(ctx->opcode)]); |
57951c27 AJ |
8380 | #else |
8381 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); | |
8382 | #endif | |
8383 | gen_set_label(l4); | |
a7812ae4 | 8384 | tcg_temp_free_i32(t0); |
57951c27 AJ |
8385 | #if defined(TARGET_PPC64) |
8386 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], t1, t2); | |
8387 | tcg_temp_free(t1); | |
8388 | tcg_temp_free(t2); | |
8389 | #endif | |
8390 | } | |
e8eaa2c0 BS |
8391 | |
8392 | static void gen_evsel0(DisasContext *ctx) | |
57951c27 AJ |
8393 | { |
8394 | gen_evsel(ctx); | |
8395 | } | |
e8eaa2c0 BS |
8396 | |
8397 | static void gen_evsel1(DisasContext *ctx) | |
57951c27 AJ |
8398 | { |
8399 | gen_evsel(ctx); | |
8400 | } | |
e8eaa2c0 BS |
8401 | |
8402 | static void gen_evsel2(DisasContext *ctx) | |
57951c27 AJ |
8403 | { |
8404 | gen_evsel(ctx); | |
8405 | } | |
e8eaa2c0 BS |
8406 | |
8407 | static void gen_evsel3(DisasContext *ctx) | |
57951c27 AJ |
8408 | { |
8409 | gen_evsel(ctx); | |
8410 | } | |
0487d6a8 | 8411 | |
a0e13900 FC |
8412 | /* Multiply */ |
8413 | ||
8414 | static inline void gen_evmwumi(DisasContext *ctx) | |
8415 | { | |
8416 | TCGv_i64 t0, t1; | |
8417 | ||
8418 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8419 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
8420 | return; |
8421 | } | |
8422 | ||
8423 | t0 = tcg_temp_new_i64(); | |
8424 | t1 = tcg_temp_new_i64(); | |
8425 | ||
8426 | /* t0 := rA; t1 := rB */ | |
8427 | #if defined(TARGET_PPC64) | |
8428 | tcg_gen_ext32u_tl(t0, cpu_gpr[rA(ctx->opcode)]); | |
8429 | tcg_gen_ext32u_tl(t1, cpu_gpr[rB(ctx->opcode)]); | |
8430 | #else | |
8431 | tcg_gen_extu_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
8432 | tcg_gen_extu_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
8433 | #endif | |
8434 | ||
8435 | tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */ | |
8436 | ||
8437 | gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */ | |
8438 | ||
8439 | tcg_temp_free_i64(t0); | |
8440 | tcg_temp_free_i64(t1); | |
8441 | } | |
8442 | ||
8443 | static inline void gen_evmwumia(DisasContext *ctx) | |
8444 | { | |
8445 | TCGv_i64 tmp; | |
8446 | ||
8447 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8448 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
8449 | return; |
8450 | } | |
8451 | ||
8452 | gen_evmwumi(ctx); /* rD := rA * rB */ | |
8453 | ||
8454 | tmp = tcg_temp_new_i64(); | |
8455 | ||
8456 | /* acc := rD */ | |
8457 | gen_load_gpr64(tmp, rD(ctx->opcode)); | |
1328c2bf | 8458 | tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
8459 | tcg_temp_free_i64(tmp); |
8460 | } | |
8461 | ||
8462 | static inline void gen_evmwumiaa(DisasContext *ctx) | |
8463 | { | |
8464 | TCGv_i64 acc; | |
8465 | TCGv_i64 tmp; | |
8466 | ||
8467 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8468 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
8469 | return; |
8470 | } | |
8471 | ||
8472 | gen_evmwumi(ctx); /* rD := rA * rB */ | |
8473 | ||
8474 | acc = tcg_temp_new_i64(); | |
8475 | tmp = tcg_temp_new_i64(); | |
8476 | ||
8477 | /* tmp := rD */ | |
8478 | gen_load_gpr64(tmp, rD(ctx->opcode)); | |
8479 | ||
8480 | /* Load acc */ | |
1328c2bf | 8481 | tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
8482 | |
8483 | /* acc := tmp + acc */ | |
8484 | tcg_gen_add_i64(acc, acc, tmp); | |
8485 | ||
8486 | /* Store acc */ | |
1328c2bf | 8487 | tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
8488 | |
8489 | /* rD := acc */ | |
8490 | gen_store_gpr64(rD(ctx->opcode), acc); | |
8491 | ||
8492 | tcg_temp_free_i64(acc); | |
8493 | tcg_temp_free_i64(tmp); | |
8494 | } | |
8495 | ||
8496 | static inline void gen_evmwsmi(DisasContext *ctx) | |
8497 | { | |
8498 | TCGv_i64 t0, t1; | |
8499 | ||
8500 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 8501 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
a0e13900 FC |
8502 | return; |
8503 | } | |
8504 | ||
8505 | t0 = tcg_temp_new_i64(); | |
8506 | t1 = tcg_temp_new_i64(); | |
8507 | ||
8508 | /* t0 := rA; t1 := rB */ | |
8509 | #if defined(TARGET_PPC64) | |
8510 | tcg_gen_ext32s_tl(t0, cpu_gpr[rA(ctx->opcode)]); | |
8511 | tcg_gen_ext32s_tl(t1, cpu_gpr[rB(ctx->opcode)]); | |
8512 | #else | |
8513 | tcg_gen_ext_tl_i64(t0, cpu_gpr[rA(ctx->opcode)]); | |
8514 | tcg_gen_ext_tl_i64(t1, cpu_gpr[rB(ctx->opcode)]); | |
8515 | #endif | |
8516 | ||
8517 | tcg_gen_mul_i64(t0, t0, t1); /* t0 := rA * rB */ | |
8518 | ||
8519 | gen_store_gpr64(rD(ctx->opcode), t0); /* rD := t0 */ | |
8520 | ||
8521 | tcg_temp_free_i64(t0); | |
8522 | tcg_temp_free_i64(t1); | |
8523 | } | |
8524 | ||
8525 | static inline void gen_evmwsmia(DisasContext *ctx) | |
8526 | { | |
8527 | TCGv_i64 tmp; | |
8528 | ||
8529 | gen_evmwsmi(ctx); /* rD := rA * rB */ | |
8530 | ||
8531 | tmp = tcg_temp_new_i64(); | |
8532 | ||
8533 | /* acc := rD */ | |
8534 | gen_load_gpr64(tmp, rD(ctx->opcode)); | |
1328c2bf | 8535 | tcg_gen_st_i64(tmp, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
8536 | |
8537 | tcg_temp_free_i64(tmp); | |
8538 | } | |
8539 | ||
8540 | static inline void gen_evmwsmiaa(DisasContext *ctx) | |
8541 | { | |
8542 | TCGv_i64 acc = tcg_temp_new_i64(); | |
8543 | TCGv_i64 tmp = tcg_temp_new_i64(); | |
8544 | ||
8545 | gen_evmwsmi(ctx); /* rD := rA * rB */ | |
8546 | ||
8547 | acc = tcg_temp_new_i64(); | |
8548 | tmp = tcg_temp_new_i64(); | |
8549 | ||
8550 | /* tmp := rD */ | |
8551 | gen_load_gpr64(tmp, rD(ctx->opcode)); | |
8552 | ||
8553 | /* Load acc */ | |
1328c2bf | 8554 | tcg_gen_ld_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
8555 | |
8556 | /* acc := tmp + acc */ | |
8557 | tcg_gen_add_i64(acc, acc, tmp); | |
8558 | ||
8559 | /* Store acc */ | |
1328c2bf | 8560 | tcg_gen_st_i64(acc, cpu_env, offsetof(CPUPPCState, spe_acc)); |
a0e13900 FC |
8561 | |
8562 | /* rD := acc */ | |
8563 | gen_store_gpr64(rD(ctx->opcode), acc); | |
8564 | ||
8565 | tcg_temp_free_i64(acc); | |
8566 | tcg_temp_free_i64(tmp); | |
8567 | } | |
8568 | ||
70560da7 FC |
8569 | GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// |
8570 | GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
8571 | GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// | |
8572 | GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
8573 | GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); //// | |
8574 | GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); //// | |
8575 | GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE); //// | |
8576 | GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE); // | |
8577 | GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE); | |
8578 | GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); //// | |
8579 | GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// | |
8580 | GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
8581 | GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
8582 | GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE); | |
8583 | GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE); | |
8584 | GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE); | |
8585 | GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE); //// | |
8586 | GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// | |
8587 | GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
8588 | GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE); | |
8589 | GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); //// | |
8590 | GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
8591 | GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE); // | |
8592 | GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE); | |
8593 | GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
8594 | GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE); //// | |
8595 | GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE); //// | |
8596 | GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE); //// | |
8597 | GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE); //// | |
0487d6a8 | 8598 | |
6a6ae23f | 8599 | /* SPE load and stores */ |
636aa200 | 8600 | static inline void gen_addr_spe_imm_index(DisasContext *ctx, TCGv EA, int sh) |
6a6ae23f AJ |
8601 | { |
8602 | target_ulong uimm = rB(ctx->opcode); | |
8603 | ||
76db3ba4 | 8604 | if (rA(ctx->opcode) == 0) { |
6a6ae23f | 8605 | tcg_gen_movi_tl(EA, uimm << sh); |
76db3ba4 | 8606 | } else { |
6a6ae23f | 8607 | tcg_gen_addi_tl(EA, cpu_gpr[rA(ctx->opcode)], uimm << sh); |
c791fe84 | 8608 | if (NARROW_MODE(ctx)) { |
76db3ba4 AJ |
8609 | tcg_gen_ext32u_tl(EA, EA); |
8610 | } | |
76db3ba4 | 8611 | } |
0487d6a8 | 8612 | } |
6a6ae23f | 8613 | |
636aa200 | 8614 | static inline void gen_op_evldd(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
8615 | { |
8616 | #if defined(TARGET_PPC64) | |
76db3ba4 | 8617 | gen_qemu_ld64(ctx, cpu_gpr[rD(ctx->opcode)], addr); |
6a6ae23f AJ |
8618 | #else |
8619 | TCGv_i64 t0 = tcg_temp_new_i64(); | |
76db3ba4 | 8620 | gen_qemu_ld64(ctx, t0, addr); |
6a6ae23f AJ |
8621 | tcg_gen_trunc_i64_i32(cpu_gpr[rD(ctx->opcode)], t0); |
8622 | tcg_gen_shri_i64(t0, t0, 32); | |
8623 | tcg_gen_trunc_i64_i32(cpu_gprh[rD(ctx->opcode)], t0); | |
8624 | tcg_temp_free_i64(t0); | |
8625 | #endif | |
0487d6a8 | 8626 | } |
6a6ae23f | 8627 | |
636aa200 | 8628 | static inline void gen_op_evldw(DisasContext *ctx, TCGv addr) |
6a6ae23f | 8629 | { |
0487d6a8 | 8630 | #if defined(TARGET_PPC64) |
6a6ae23f | 8631 | TCGv t0 = tcg_temp_new(); |
76db3ba4 | 8632 | gen_qemu_ld32u(ctx, t0, addr); |
6a6ae23f | 8633 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32); |
76db3ba4 AJ |
8634 | gen_addr_add(ctx, addr, addr, 4); |
8635 | gen_qemu_ld32u(ctx, t0, addr); | |
6a6ae23f AJ |
8636 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); |
8637 | tcg_temp_free(t0); | |
8638 | #else | |
76db3ba4 AJ |
8639 | gen_qemu_ld32u(ctx, cpu_gprh[rD(ctx->opcode)], addr); |
8640 | gen_addr_add(ctx, addr, addr, 4); | |
8641 | gen_qemu_ld32u(ctx, cpu_gpr[rD(ctx->opcode)], addr); | |
6a6ae23f | 8642 | #endif |
0487d6a8 | 8643 | } |
6a6ae23f | 8644 | |
636aa200 | 8645 | static inline void gen_op_evldh(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
8646 | { |
8647 | TCGv t0 = tcg_temp_new(); | |
8648 | #if defined(TARGET_PPC64) | |
76db3ba4 | 8649 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f | 8650 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48); |
76db3ba4 AJ |
8651 | gen_addr_add(ctx, addr, addr, 2); |
8652 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
8653 | tcg_gen_shli_tl(t0, t0, 32); |
8654 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
76db3ba4 AJ |
8655 | gen_addr_add(ctx, addr, addr, 2); |
8656 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
8657 | tcg_gen_shli_tl(t0, t0, 16); |
8658 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
76db3ba4 AJ |
8659 | gen_addr_add(ctx, addr, addr, 2); |
8660 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f | 8661 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); |
0487d6a8 | 8662 | #else |
76db3ba4 | 8663 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f | 8664 | tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16); |
76db3ba4 AJ |
8665 | gen_addr_add(ctx, addr, addr, 2); |
8666 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f | 8667 | tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0); |
76db3ba4 AJ |
8668 | gen_addr_add(ctx, addr, addr, 2); |
8669 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f | 8670 | tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16); |
76db3ba4 AJ |
8671 | gen_addr_add(ctx, addr, addr, 2); |
8672 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f | 8673 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); |
0487d6a8 | 8674 | #endif |
6a6ae23f | 8675 | tcg_temp_free(t0); |
0487d6a8 JM |
8676 | } |
8677 | ||
636aa200 | 8678 | static inline void gen_op_evlhhesplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
8679 | { |
8680 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 8681 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f AJ |
8682 | #if defined(TARGET_PPC64) |
8683 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48); | |
8684 | tcg_gen_shli_tl(t0, t0, 16); | |
8685 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
8686 | #else | |
8687 | tcg_gen_shli_tl(t0, t0, 16); | |
8688 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0); | |
8689 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
8690 | #endif | |
8691 | tcg_temp_free(t0); | |
0487d6a8 JM |
8692 | } |
8693 | ||
636aa200 | 8694 | static inline void gen_op_evlhhousplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
8695 | { |
8696 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 8697 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f AJ |
8698 | #if defined(TARGET_PPC64) |
8699 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32); | |
8700 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
8701 | #else | |
8702 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0); | |
8703 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
8704 | #endif | |
8705 | tcg_temp_free(t0); | |
0487d6a8 JM |
8706 | } |
8707 | ||
636aa200 | 8708 | static inline void gen_op_evlhhossplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
8709 | { |
8710 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 8711 | gen_qemu_ld16s(ctx, t0, addr); |
6a6ae23f AJ |
8712 | #if defined(TARGET_PPC64) |
8713 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32); | |
8714 | tcg_gen_ext32u_tl(t0, t0); | |
8715 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
8716 | #else | |
8717 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0); | |
8718 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
8719 | #endif | |
8720 | tcg_temp_free(t0); | |
8721 | } | |
8722 | ||
636aa200 | 8723 | static inline void gen_op_evlwhe(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
8724 | { |
8725 | TCGv t0 = tcg_temp_new(); | |
8726 | #if defined(TARGET_PPC64) | |
76db3ba4 | 8727 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f | 8728 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48); |
76db3ba4 AJ |
8729 | gen_addr_add(ctx, addr, addr, 2); |
8730 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
8731 | tcg_gen_shli_tl(t0, t0, 16); |
8732 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
8733 | #else | |
76db3ba4 | 8734 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f | 8735 | tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16); |
76db3ba4 AJ |
8736 | gen_addr_add(ctx, addr, addr, 2); |
8737 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
8738 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16); |
8739 | #endif | |
8740 | tcg_temp_free(t0); | |
8741 | } | |
8742 | ||
636aa200 | 8743 | static inline void gen_op_evlwhou(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
8744 | { |
8745 | #if defined(TARGET_PPC64) | |
8746 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 AJ |
8747 | gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr); |
8748 | gen_addr_add(ctx, addr, addr, 2); | |
8749 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
8750 | tcg_gen_shli_tl(t0, t0, 32); |
8751 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
8752 | tcg_temp_free(t0); | |
8753 | #else | |
76db3ba4 AJ |
8754 | gen_qemu_ld16u(ctx, cpu_gprh[rD(ctx->opcode)], addr); |
8755 | gen_addr_add(ctx, addr, addr, 2); | |
8756 | gen_qemu_ld16u(ctx, cpu_gpr[rD(ctx->opcode)], addr); | |
6a6ae23f AJ |
8757 | #endif |
8758 | } | |
8759 | ||
636aa200 | 8760 | static inline void gen_op_evlwhos(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
8761 | { |
8762 | #if defined(TARGET_PPC64) | |
8763 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 8764 | gen_qemu_ld16s(ctx, t0, addr); |
6a6ae23f | 8765 | tcg_gen_ext32u_tl(cpu_gpr[rD(ctx->opcode)], t0); |
76db3ba4 AJ |
8766 | gen_addr_add(ctx, addr, addr, 2); |
8767 | gen_qemu_ld16s(ctx, t0, addr); | |
6a6ae23f AJ |
8768 | tcg_gen_shli_tl(t0, t0, 32); |
8769 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
8770 | tcg_temp_free(t0); | |
8771 | #else | |
76db3ba4 AJ |
8772 | gen_qemu_ld16s(ctx, cpu_gprh[rD(ctx->opcode)], addr); |
8773 | gen_addr_add(ctx, addr, addr, 2); | |
8774 | gen_qemu_ld16s(ctx, cpu_gpr[rD(ctx->opcode)], addr); | |
6a6ae23f AJ |
8775 | #endif |
8776 | } | |
8777 | ||
636aa200 | 8778 | static inline void gen_op_evlwwsplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
8779 | { |
8780 | TCGv t0 = tcg_temp_new(); | |
76db3ba4 | 8781 | gen_qemu_ld32u(ctx, t0, addr); |
0487d6a8 | 8782 | #if defined(TARGET_PPC64) |
6a6ae23f AJ |
8783 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 32); |
8784 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
8785 | #else | |
8786 | tcg_gen_mov_tl(cpu_gprh[rD(ctx->opcode)], t0); | |
8787 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], t0); | |
8788 | #endif | |
8789 | tcg_temp_free(t0); | |
8790 | } | |
8791 | ||
636aa200 | 8792 | static inline void gen_op_evlwhsplat(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
8793 | { |
8794 | TCGv t0 = tcg_temp_new(); | |
8795 | #if defined(TARGET_PPC64) | |
76db3ba4 | 8796 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f AJ |
8797 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 48); |
8798 | tcg_gen_shli_tl(t0, t0, 32); | |
8799 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
76db3ba4 AJ |
8800 | gen_addr_add(ctx, addr, addr, 2); |
8801 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
8802 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); |
8803 | tcg_gen_shli_tl(t0, t0, 16); | |
8804 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t0); | |
8805 | #else | |
76db3ba4 | 8806 | gen_qemu_ld16u(ctx, t0, addr); |
6a6ae23f AJ |
8807 | tcg_gen_shli_tl(cpu_gprh[rD(ctx->opcode)], t0, 16); |
8808 | tcg_gen_or_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0); | |
76db3ba4 AJ |
8809 | gen_addr_add(ctx, addr, addr, 2); |
8810 | gen_qemu_ld16u(ctx, t0, addr); | |
6a6ae23f AJ |
8811 | tcg_gen_shli_tl(cpu_gpr[rD(ctx->opcode)], t0, 16); |
8812 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gprh[rD(ctx->opcode)], t0); | |
0487d6a8 | 8813 | #endif |
6a6ae23f AJ |
8814 | tcg_temp_free(t0); |
8815 | } | |
8816 | ||
636aa200 | 8817 | static inline void gen_op_evstdd(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
8818 | { |
8819 | #if defined(TARGET_PPC64) | |
76db3ba4 | 8820 | gen_qemu_st64(ctx, cpu_gpr[rS(ctx->opcode)], addr); |
0487d6a8 | 8821 | #else |
6a6ae23f AJ |
8822 | TCGv_i64 t0 = tcg_temp_new_i64(); |
8823 | tcg_gen_concat_i32_i64(t0, cpu_gpr[rS(ctx->opcode)], cpu_gprh[rS(ctx->opcode)]); | |
76db3ba4 | 8824 | gen_qemu_st64(ctx, t0, addr); |
6a6ae23f AJ |
8825 | tcg_temp_free_i64(t0); |
8826 | #endif | |
8827 | } | |
8828 | ||
636aa200 | 8829 | static inline void gen_op_evstdw(DisasContext *ctx, TCGv addr) |
6a6ae23f | 8830 | { |
0487d6a8 | 8831 | #if defined(TARGET_PPC64) |
6a6ae23f AJ |
8832 | TCGv t0 = tcg_temp_new(); |
8833 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32); | |
76db3ba4 | 8834 | gen_qemu_st32(ctx, t0, addr); |
6a6ae23f AJ |
8835 | tcg_temp_free(t0); |
8836 | #else | |
76db3ba4 | 8837 | gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr); |
6a6ae23f | 8838 | #endif |
76db3ba4 AJ |
8839 | gen_addr_add(ctx, addr, addr, 4); |
8840 | gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr); | |
6a6ae23f AJ |
8841 | } |
8842 | ||
636aa200 | 8843 | static inline void gen_op_evstdh(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
8844 | { |
8845 | TCGv t0 = tcg_temp_new(); | |
8846 | #if defined(TARGET_PPC64) | |
8847 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48); | |
8848 | #else | |
8849 | tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16); | |
8850 | #endif | |
76db3ba4 AJ |
8851 | gen_qemu_st16(ctx, t0, addr); |
8852 | gen_addr_add(ctx, addr, addr, 2); | |
6a6ae23f AJ |
8853 | #if defined(TARGET_PPC64) |
8854 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32); | |
76db3ba4 | 8855 | gen_qemu_st16(ctx, t0, addr); |
6a6ae23f | 8856 | #else |
76db3ba4 | 8857 | gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr); |
6a6ae23f | 8858 | #endif |
76db3ba4 | 8859 | gen_addr_add(ctx, addr, addr, 2); |
6a6ae23f | 8860 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16); |
76db3ba4 | 8861 | gen_qemu_st16(ctx, t0, addr); |
6a6ae23f | 8862 | tcg_temp_free(t0); |
76db3ba4 AJ |
8863 | gen_addr_add(ctx, addr, addr, 2); |
8864 | gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr); | |
6a6ae23f AJ |
8865 | } |
8866 | ||
636aa200 | 8867 | static inline void gen_op_evstwhe(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
8868 | { |
8869 | TCGv t0 = tcg_temp_new(); | |
8870 | #if defined(TARGET_PPC64) | |
8871 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 48); | |
8872 | #else | |
8873 | tcg_gen_shri_tl(t0, cpu_gprh[rS(ctx->opcode)], 16); | |
8874 | #endif | |
76db3ba4 AJ |
8875 | gen_qemu_st16(ctx, t0, addr); |
8876 | gen_addr_add(ctx, addr, addr, 2); | |
6a6ae23f | 8877 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 16); |
76db3ba4 | 8878 | gen_qemu_st16(ctx, t0, addr); |
6a6ae23f AJ |
8879 | tcg_temp_free(t0); |
8880 | } | |
8881 | ||
636aa200 | 8882 | static inline void gen_op_evstwho(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
8883 | { |
8884 | #if defined(TARGET_PPC64) | |
8885 | TCGv t0 = tcg_temp_new(); | |
8886 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32); | |
76db3ba4 | 8887 | gen_qemu_st16(ctx, t0, addr); |
6a6ae23f AJ |
8888 | tcg_temp_free(t0); |
8889 | #else | |
76db3ba4 | 8890 | gen_qemu_st16(ctx, cpu_gprh[rS(ctx->opcode)], addr); |
6a6ae23f | 8891 | #endif |
76db3ba4 AJ |
8892 | gen_addr_add(ctx, addr, addr, 2); |
8893 | gen_qemu_st16(ctx, cpu_gpr[rS(ctx->opcode)], addr); | |
6a6ae23f AJ |
8894 | } |
8895 | ||
636aa200 | 8896 | static inline void gen_op_evstwwe(DisasContext *ctx, TCGv addr) |
6a6ae23f AJ |
8897 | { |
8898 | #if defined(TARGET_PPC64) | |
8899 | TCGv t0 = tcg_temp_new(); | |
8900 | tcg_gen_shri_tl(t0, cpu_gpr[rS(ctx->opcode)], 32); | |
76db3ba4 | 8901 | gen_qemu_st32(ctx, t0, addr); |
6a6ae23f AJ |
8902 | tcg_temp_free(t0); |
8903 | #else | |
76db3ba4 | 8904 | gen_qemu_st32(ctx, cpu_gprh[rS(ctx->opcode)], addr); |
6a6ae23f AJ |
8905 | #endif |
8906 | } | |
8907 | ||
636aa200 | 8908 | static inline void gen_op_evstwwo(DisasContext *ctx, TCGv addr) |
6a6ae23f | 8909 | { |
76db3ba4 | 8910 | gen_qemu_st32(ctx, cpu_gpr[rS(ctx->opcode)], addr); |
6a6ae23f AJ |
8911 | } |
8912 | ||
8913 | #define GEN_SPEOP_LDST(name, opc2, sh) \ | |
99e300ef | 8914 | static void glue(gen_, name)(DisasContext *ctx) \ |
6a6ae23f AJ |
8915 | { \ |
8916 | TCGv t0; \ | |
8917 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 8918 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
6a6ae23f AJ |
8919 | return; \ |
8920 | } \ | |
76db3ba4 | 8921 | gen_set_access_type(ctx, ACCESS_INT); \ |
6a6ae23f AJ |
8922 | t0 = tcg_temp_new(); \ |
8923 | if (Rc(ctx->opcode)) { \ | |
76db3ba4 | 8924 | gen_addr_spe_imm_index(ctx, t0, sh); \ |
6a6ae23f | 8925 | } else { \ |
76db3ba4 | 8926 | gen_addr_reg_index(ctx, t0); \ |
6a6ae23f AJ |
8927 | } \ |
8928 | gen_op_##name(ctx, t0); \ | |
8929 | tcg_temp_free(t0); \ | |
8930 | } | |
8931 | ||
8932 | GEN_SPEOP_LDST(evldd, 0x00, 3); | |
8933 | GEN_SPEOP_LDST(evldw, 0x01, 3); | |
8934 | GEN_SPEOP_LDST(evldh, 0x02, 3); | |
8935 | GEN_SPEOP_LDST(evlhhesplat, 0x04, 1); | |
8936 | GEN_SPEOP_LDST(evlhhousplat, 0x06, 1); | |
8937 | GEN_SPEOP_LDST(evlhhossplat, 0x07, 1); | |
8938 | GEN_SPEOP_LDST(evlwhe, 0x08, 2); | |
8939 | GEN_SPEOP_LDST(evlwhou, 0x0A, 2); | |
8940 | GEN_SPEOP_LDST(evlwhos, 0x0B, 2); | |
8941 | GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2); | |
8942 | GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2); | |
8943 | ||
8944 | GEN_SPEOP_LDST(evstdd, 0x10, 3); | |
8945 | GEN_SPEOP_LDST(evstdw, 0x11, 3); | |
8946 | GEN_SPEOP_LDST(evstdh, 0x12, 3); | |
8947 | GEN_SPEOP_LDST(evstwhe, 0x18, 2); | |
8948 | GEN_SPEOP_LDST(evstwho, 0x1A, 2); | |
8949 | GEN_SPEOP_LDST(evstwwe, 0x1C, 2); | |
8950 | GEN_SPEOP_LDST(evstwwo, 0x1E, 2); | |
0487d6a8 JM |
8951 | |
8952 | /* Multiply and add - TODO */ | |
8953 | #if 0 | |
70560da7 FC |
8954 | GEN_SPE(speundef, evmhessf, 0x01, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE);// |
8955 | GEN_SPE(speundef, evmhossf, 0x03, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8956 | GEN_SPE(evmheumi, evmhesmi, 0x04, 0x10, 0x00000000, 0x00000000, PPC_SPE); | |
8957 | GEN_SPE(speundef, evmhesmf, 0x05, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8958 | GEN_SPE(evmhoumi, evmhosmi, 0x06, 0x10, 0x00000000, 0x00000000, PPC_SPE); | |
8959 | GEN_SPE(speundef, evmhosmf, 0x07, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8960 | GEN_SPE(speundef, evmhessfa, 0x11, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8961 | GEN_SPE(speundef, evmhossfa, 0x13, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8962 | GEN_SPE(evmheumia, evmhesmia, 0x14, 0x10, 0x00000000, 0x00000000, PPC_SPE); | |
8963 | GEN_SPE(speundef, evmhesmfa, 0x15, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8964 | GEN_SPE(evmhoumia, evmhosmia, 0x16, 0x10, 0x00000000, 0x00000000, PPC_SPE); | |
8965 | GEN_SPE(speundef, evmhosmfa, 0x17, 0x10, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8966 | ||
8967 | GEN_SPE(speundef, evmwhssf, 0x03, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8968 | GEN_SPE(evmwlumi, speundef, 0x04, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
8969 | GEN_SPE(evmwhumi, evmwhsmi, 0x06, 0x11, 0x00000000, 0x00000000, PPC_SPE); | |
8970 | GEN_SPE(speundef, evmwhsmf, 0x07, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8971 | GEN_SPE(speundef, evmwssf, 0x09, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8972 | GEN_SPE(speundef, evmwsmf, 0x0D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8973 | GEN_SPE(speundef, evmwhssfa, 0x13, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8974 | GEN_SPE(evmwlumia, speundef, 0x14, 0x11, 0x00000000, 0xFFFFFFFF, PPC_SPE); | |
8975 | GEN_SPE(evmwhumia, evmwhsmia, 0x16, 0x11, 0x00000000, 0x00000000, PPC_SPE); | |
8976 | GEN_SPE(speundef, evmwhsmfa, 0x17, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8977 | GEN_SPE(speundef, evmwssfa, 0x19, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8978 | GEN_SPE(speundef, evmwsmfa, 0x1D, 0x11, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8979 | ||
8980 | GEN_SPE(evadduiaaw, evaddsiaaw, 0x00, 0x13, 0x0000F800, 0x0000F800, PPC_SPE); | |
8981 | GEN_SPE(evsubfusiaaw, evsubfssiaaw, 0x01, 0x13, 0x0000F800, 0x0000F800, PPC_SPE); | |
8982 | GEN_SPE(evaddumiaaw, evaddsmiaaw, 0x04, 0x13, 0x0000F800, 0x0000F800, PPC_SPE); | |
8983 | GEN_SPE(evsubfumiaaw, evsubfsmiaaw, 0x05, 0x13, 0x0000F800, 0x0000F800, PPC_SPE); | |
8984 | GEN_SPE(evdivws, evdivwu, 0x06, 0x13, 0x00000000, 0x00000000, PPC_SPE); | |
8985 | ||
8986 | GEN_SPE(evmheusiaaw, evmhessiaaw, 0x00, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
8987 | GEN_SPE(speundef, evmhessfaaw, 0x01, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8988 | GEN_SPE(evmhousiaaw, evmhossiaaw, 0x02, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
8989 | GEN_SPE(speundef, evmhossfaaw, 0x03, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8990 | GEN_SPE(evmheumiaaw, evmhesmiaaw, 0x04, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
8991 | GEN_SPE(speundef, evmhesmfaaw, 0x05, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8992 | GEN_SPE(evmhoumiaaw, evmhosmiaaw, 0x06, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
8993 | GEN_SPE(speundef, evmhosmfaaw, 0x07, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8994 | GEN_SPE(evmhegumiaa, evmhegsmiaa, 0x14, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
8995 | GEN_SPE(speundef, evmhegsmfaa, 0x15, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8996 | GEN_SPE(evmhogumiaa, evmhogsmiaa, 0x16, 0x14, 0x00000000, 0x00000000, PPC_SPE); | |
8997 | GEN_SPE(speundef, evmhogsmfaa, 0x17, 0x14, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
8998 | ||
8999 | GEN_SPE(evmwlusiaaw, evmwlssiaaw, 0x00, 0x15, 0x00000000, 0x00000000, PPC_SPE); | |
9000 | GEN_SPE(evmwlumiaaw, evmwlsmiaaw, 0x04, 0x15, 0x00000000, 0x00000000, PPC_SPE); | |
9001 | GEN_SPE(speundef, evmwssfaa, 0x09, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9002 | GEN_SPE(speundef, evmwsmfaa, 0x0D, 0x15, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9003 | ||
9004 | GEN_SPE(evmheusianw, evmhessianw, 0x00, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
9005 | GEN_SPE(speundef, evmhessfanw, 0x01, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9006 | GEN_SPE(evmhousianw, evmhossianw, 0x02, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
9007 | GEN_SPE(speundef, evmhossfanw, 0x03, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9008 | GEN_SPE(evmheumianw, evmhesmianw, 0x04, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
9009 | GEN_SPE(speundef, evmhesmfanw, 0x05, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9010 | GEN_SPE(evmhoumianw, evmhosmianw, 0x06, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
9011 | GEN_SPE(speundef, evmhosmfanw, 0x07, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9012 | GEN_SPE(evmhegumian, evmhegsmian, 0x14, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
9013 | GEN_SPE(speundef, evmhegsmfan, 0x15, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9014 | GEN_SPE(evmhigumian, evmhigsmian, 0x16, 0x16, 0x00000000, 0x00000000, PPC_SPE); | |
9015 | GEN_SPE(speundef, evmhogsmfan, 0x17, 0x16, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9016 | ||
9017 | GEN_SPE(evmwlusianw, evmwlssianw, 0x00, 0x17, 0x00000000, 0x00000000, PPC_SPE); | |
9018 | GEN_SPE(evmwlumianw, evmwlsmianw, 0x04, 0x17, 0x00000000, 0x00000000, PPC_SPE); | |
9019 | GEN_SPE(speundef, evmwssfan, 0x09, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
9020 | GEN_SPE(evmwumian, evmwsmian, 0x0C, 0x17, 0x00000000, 0x00000000, PPC_SPE); | |
9021 | GEN_SPE(speundef, evmwsmfan, 0x0D, 0x17, 0xFFFFFFFF, 0x00000000, PPC_SPE); | |
0487d6a8 JM |
9022 | #endif |
9023 | ||
9024 | /*** SPE floating-point extension ***/ | |
1c97856d AJ |
9025 | #if defined(TARGET_PPC64) |
9026 | #define GEN_SPEFPUOP_CONV_32_32(name) \ | |
636aa200 | 9027 | static inline void gen_##name(DisasContext *ctx) \ |
0487d6a8 | 9028 | { \ |
1c97856d AJ |
9029 | TCGv_i32 t0; \ |
9030 | TCGv t1; \ | |
9031 | t0 = tcg_temp_new_i32(); \ | |
9032 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \ | |
8e703949 | 9033 | gen_helper_##name(t0, cpu_env, t0); \ |
1c97856d AJ |
9034 | t1 = tcg_temp_new(); \ |
9035 | tcg_gen_extu_i32_tl(t1, t0); \ | |
9036 | tcg_temp_free_i32(t0); \ | |
9037 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \ | |
9038 | 0xFFFFFFFF00000000ULL); \ | |
9039 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \ | |
9040 | tcg_temp_free(t1); \ | |
0487d6a8 | 9041 | } |
1c97856d | 9042 | #define GEN_SPEFPUOP_CONV_32_64(name) \ |
636aa200 | 9043 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
9044 | { \ |
9045 | TCGv_i32 t0; \ | |
9046 | TCGv t1; \ | |
9047 | t0 = tcg_temp_new_i32(); \ | |
8e703949 | 9048 | gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \ |
1c97856d AJ |
9049 | t1 = tcg_temp_new(); \ |
9050 | tcg_gen_extu_i32_tl(t1, t0); \ | |
9051 | tcg_temp_free_i32(t0); \ | |
9052 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \ | |
9053 | 0xFFFFFFFF00000000ULL); \ | |
9054 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t1); \ | |
9055 | tcg_temp_free(t1); \ | |
9056 | } | |
9057 | #define GEN_SPEFPUOP_CONV_64_32(name) \ | |
636aa200 | 9058 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
9059 | { \ |
9060 | TCGv_i32 t0 = tcg_temp_new_i32(); \ | |
9061 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rB(ctx->opcode)]); \ | |
8e703949 | 9062 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \ |
1c97856d AJ |
9063 | tcg_temp_free_i32(t0); \ |
9064 | } | |
9065 | #define GEN_SPEFPUOP_CONV_64_64(name) \ | |
636aa200 | 9066 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d | 9067 | { \ |
8e703949 BS |
9068 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \ |
9069 | cpu_gpr[rB(ctx->opcode)]); \ | |
1c97856d AJ |
9070 | } |
9071 | #define GEN_SPEFPUOP_ARITH2_32_32(name) \ | |
636aa200 | 9072 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 | 9073 | { \ |
1c97856d AJ |
9074 | TCGv_i32 t0, t1; \ |
9075 | TCGv_i64 t2; \ | |
57951c27 | 9076 | if (unlikely(!ctx->spe_enabled)) { \ |
27a69bb0 | 9077 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
9078 | return; \ |
9079 | } \ | |
1c97856d AJ |
9080 | t0 = tcg_temp_new_i32(); \ |
9081 | t1 = tcg_temp_new_i32(); \ | |
9082 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ | |
9083 | tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \ | |
8e703949 | 9084 | gen_helper_##name(t0, cpu_env, t0, t1); \ |
1c97856d AJ |
9085 | tcg_temp_free_i32(t1); \ |
9086 | t2 = tcg_temp_new(); \ | |
9087 | tcg_gen_extu_i32_tl(t2, t0); \ | |
9088 | tcg_temp_free_i32(t0); \ | |
9089 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], \ | |
9090 | 0xFFFFFFFF00000000ULL); \ | |
9091 | tcg_gen_or_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rD(ctx->opcode)], t2); \ | |
9092 | tcg_temp_free(t2); \ | |
57951c27 | 9093 | } |
1c97856d | 9094 | #define GEN_SPEFPUOP_ARITH2_64_64(name) \ |
636aa200 | 9095 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 AJ |
9096 | { \ |
9097 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 9098 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
9099 | return; \ |
9100 | } \ | |
8e703949 BS |
9101 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \ |
9102 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \ | |
57951c27 | 9103 | } |
1c97856d | 9104 | #define GEN_SPEFPUOP_COMP_32(name) \ |
636aa200 | 9105 | static inline void gen_##name(DisasContext *ctx) \ |
57951c27 | 9106 | { \ |
1c97856d | 9107 | TCGv_i32 t0, t1; \ |
57951c27 | 9108 | if (unlikely(!ctx->spe_enabled)) { \ |
27a69bb0 | 9109 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
57951c27 AJ |
9110 | return; \ |
9111 | } \ | |
1c97856d AJ |
9112 | t0 = tcg_temp_new_i32(); \ |
9113 | t1 = tcg_temp_new_i32(); \ | |
9114 | tcg_gen_trunc_tl_i32(t0, cpu_gpr[rA(ctx->opcode)]); \ | |
9115 | tcg_gen_trunc_tl_i32(t1, cpu_gpr[rB(ctx->opcode)]); \ | |
8e703949 | 9116 | gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \ |
1c97856d AJ |
9117 | tcg_temp_free_i32(t0); \ |
9118 | tcg_temp_free_i32(t1); \ | |
9119 | } | |
9120 | #define GEN_SPEFPUOP_COMP_64(name) \ | |
636aa200 | 9121 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
9122 | { \ |
9123 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 9124 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
9125 | return; \ |
9126 | } \ | |
8e703949 | 9127 | gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \ |
1c97856d AJ |
9128 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \ |
9129 | } | |
9130 | #else | |
9131 | #define GEN_SPEFPUOP_CONV_32_32(name) \ | |
636aa200 | 9132 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d | 9133 | { \ |
8e703949 BS |
9134 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \ |
9135 | cpu_gpr[rB(ctx->opcode)]); \ | |
57951c27 | 9136 | } |
1c97856d | 9137 | #define GEN_SPEFPUOP_CONV_32_64(name) \ |
636aa200 | 9138 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
9139 | { \ |
9140 | TCGv_i64 t0 = tcg_temp_new_i64(); \ | |
9141 | gen_load_gpr64(t0, rB(ctx->opcode)); \ | |
8e703949 | 9142 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, t0); \ |
1c97856d AJ |
9143 | tcg_temp_free_i64(t0); \ |
9144 | } | |
9145 | #define GEN_SPEFPUOP_CONV_64_32(name) \ | |
636aa200 | 9146 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
9147 | { \ |
9148 | TCGv_i64 t0 = tcg_temp_new_i64(); \ | |
8e703949 | 9149 | gen_helper_##name(t0, cpu_env, cpu_gpr[rB(ctx->opcode)]); \ |
1c97856d AJ |
9150 | gen_store_gpr64(rD(ctx->opcode), t0); \ |
9151 | tcg_temp_free_i64(t0); \ | |
9152 | } | |
9153 | #define GEN_SPEFPUOP_CONV_64_64(name) \ | |
636aa200 | 9154 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
9155 | { \ |
9156 | TCGv_i64 t0 = tcg_temp_new_i64(); \ | |
9157 | gen_load_gpr64(t0, rB(ctx->opcode)); \ | |
8e703949 | 9158 | gen_helper_##name(t0, cpu_env, t0); \ |
1c97856d AJ |
9159 | gen_store_gpr64(rD(ctx->opcode), t0); \ |
9160 | tcg_temp_free_i64(t0); \ | |
9161 | } | |
9162 | #define GEN_SPEFPUOP_ARITH2_32_32(name) \ | |
636aa200 | 9163 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
9164 | { \ |
9165 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 9166 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
9167 | return; \ |
9168 | } \ | |
8e703949 | 9169 | gen_helper_##name(cpu_gpr[rD(ctx->opcode)], cpu_env, \ |
1c97856d AJ |
9170 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \ |
9171 | } | |
9172 | #define GEN_SPEFPUOP_ARITH2_64_64(name) \ | |
636aa200 | 9173 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
9174 | { \ |
9175 | TCGv_i64 t0, t1; \ | |
9176 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 9177 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
9178 | return; \ |
9179 | } \ | |
9180 | t0 = tcg_temp_new_i64(); \ | |
9181 | t1 = tcg_temp_new_i64(); \ | |
9182 | gen_load_gpr64(t0, rA(ctx->opcode)); \ | |
9183 | gen_load_gpr64(t1, rB(ctx->opcode)); \ | |
8e703949 | 9184 | gen_helper_##name(t0, cpu_env, t0, t1); \ |
1c97856d AJ |
9185 | gen_store_gpr64(rD(ctx->opcode), t0); \ |
9186 | tcg_temp_free_i64(t0); \ | |
9187 | tcg_temp_free_i64(t1); \ | |
9188 | } | |
9189 | #define GEN_SPEFPUOP_COMP_32(name) \ | |
636aa200 | 9190 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
9191 | { \ |
9192 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 9193 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
9194 | return; \ |
9195 | } \ | |
8e703949 | 9196 | gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, \ |
1c97856d AJ |
9197 | cpu_gpr[rA(ctx->opcode)], cpu_gpr[rB(ctx->opcode)]); \ |
9198 | } | |
9199 | #define GEN_SPEFPUOP_COMP_64(name) \ | |
636aa200 | 9200 | static inline void gen_##name(DisasContext *ctx) \ |
1c97856d AJ |
9201 | { \ |
9202 | TCGv_i64 t0, t1; \ | |
9203 | if (unlikely(!ctx->spe_enabled)) { \ | |
27a69bb0 | 9204 | gen_exception(ctx, POWERPC_EXCP_SPEU); \ |
1c97856d AJ |
9205 | return; \ |
9206 | } \ | |
9207 | t0 = tcg_temp_new_i64(); \ | |
9208 | t1 = tcg_temp_new_i64(); \ | |
9209 | gen_load_gpr64(t0, rA(ctx->opcode)); \ | |
9210 | gen_load_gpr64(t1, rB(ctx->opcode)); \ | |
8e703949 | 9211 | gen_helper_##name(cpu_crf[crfD(ctx->opcode)], cpu_env, t0, t1); \ |
1c97856d AJ |
9212 | tcg_temp_free_i64(t0); \ |
9213 | tcg_temp_free_i64(t1); \ | |
9214 | } | |
9215 | #endif | |
57951c27 | 9216 | |
0487d6a8 JM |
9217 | /* Single precision floating-point vectors operations */ |
9218 | /* Arithmetic */ | |
1c97856d AJ |
9219 | GEN_SPEFPUOP_ARITH2_64_64(evfsadd); |
9220 | GEN_SPEFPUOP_ARITH2_64_64(evfssub); | |
9221 | GEN_SPEFPUOP_ARITH2_64_64(evfsmul); | |
9222 | GEN_SPEFPUOP_ARITH2_64_64(evfsdiv); | |
636aa200 | 9223 | static inline void gen_evfsabs(DisasContext *ctx) |
1c97856d AJ |
9224 | { |
9225 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 9226 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
9227 | return; |
9228 | } | |
9229 | #if defined(TARGET_PPC64) | |
6d5c34fa | 9230 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000080000000LL); |
1c97856d | 9231 | #else |
6d5c34fa MP |
9232 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x80000000); |
9233 | tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000); | |
1c97856d AJ |
9234 | #endif |
9235 | } | |
636aa200 | 9236 | static inline void gen_evfsnabs(DisasContext *ctx) |
1c97856d AJ |
9237 | { |
9238 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 9239 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
9240 | return; |
9241 | } | |
9242 | #if defined(TARGET_PPC64) | |
6d5c34fa | 9243 | tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL); |
1c97856d | 9244 | #else |
6d5c34fa MP |
9245 | tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000); |
9246 | tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000); | |
1c97856d AJ |
9247 | #endif |
9248 | } | |
636aa200 | 9249 | static inline void gen_evfsneg(DisasContext *ctx) |
1c97856d AJ |
9250 | { |
9251 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 9252 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
9253 | return; |
9254 | } | |
9255 | #if defined(TARGET_PPC64) | |
6d5c34fa | 9256 | tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000080000000LL); |
1c97856d | 9257 | #else |
6d5c34fa MP |
9258 | tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000); |
9259 | tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000); | |
1c97856d AJ |
9260 | #endif |
9261 | } | |
9262 | ||
0487d6a8 | 9263 | /* Conversion */ |
1c97856d AJ |
9264 | GEN_SPEFPUOP_CONV_64_64(evfscfui); |
9265 | GEN_SPEFPUOP_CONV_64_64(evfscfsi); | |
9266 | GEN_SPEFPUOP_CONV_64_64(evfscfuf); | |
9267 | GEN_SPEFPUOP_CONV_64_64(evfscfsf); | |
9268 | GEN_SPEFPUOP_CONV_64_64(evfsctui); | |
9269 | GEN_SPEFPUOP_CONV_64_64(evfsctsi); | |
9270 | GEN_SPEFPUOP_CONV_64_64(evfsctuf); | |
9271 | GEN_SPEFPUOP_CONV_64_64(evfsctsf); | |
9272 | GEN_SPEFPUOP_CONV_64_64(evfsctuiz); | |
9273 | GEN_SPEFPUOP_CONV_64_64(evfsctsiz); | |
9274 | ||
0487d6a8 | 9275 | /* Comparison */ |
1c97856d AJ |
9276 | GEN_SPEFPUOP_COMP_64(evfscmpgt); |
9277 | GEN_SPEFPUOP_COMP_64(evfscmplt); | |
9278 | GEN_SPEFPUOP_COMP_64(evfscmpeq); | |
9279 | GEN_SPEFPUOP_COMP_64(evfststgt); | |
9280 | GEN_SPEFPUOP_COMP_64(evfststlt); | |
9281 | GEN_SPEFPUOP_COMP_64(evfststeq); | |
0487d6a8 JM |
9282 | |
9283 | /* Opcodes definitions */ | |
70560da7 FC |
9284 | GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); // |
9285 | GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); // | |
9286 | GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
9287 | GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE); // | |
9288 | GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); // | |
9289 | GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
9290 | GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
9291 | GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
9292 | GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
9293 | GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
9294 | GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
9295 | GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
9296 | GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE); // | |
9297 | GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
0487d6a8 JM |
9298 | |
9299 | /* Single precision floating-point operations */ | |
9300 | /* Arithmetic */ | |
1c97856d AJ |
9301 | GEN_SPEFPUOP_ARITH2_32_32(efsadd); |
9302 | GEN_SPEFPUOP_ARITH2_32_32(efssub); | |
9303 | GEN_SPEFPUOP_ARITH2_32_32(efsmul); | |
9304 | GEN_SPEFPUOP_ARITH2_32_32(efsdiv); | |
636aa200 | 9305 | static inline void gen_efsabs(DisasContext *ctx) |
1c97856d AJ |
9306 | { |
9307 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 9308 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
9309 | return; |
9310 | } | |
6d5c34fa | 9311 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], (target_long)~0x80000000LL); |
1c97856d | 9312 | } |
636aa200 | 9313 | static inline void gen_efsnabs(DisasContext *ctx) |
1c97856d AJ |
9314 | { |
9315 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 9316 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
9317 | return; |
9318 | } | |
6d5c34fa | 9319 | tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000); |
1c97856d | 9320 | } |
636aa200 | 9321 | static inline void gen_efsneg(DisasContext *ctx) |
1c97856d AJ |
9322 | { |
9323 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 9324 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
9325 | return; |
9326 | } | |
6d5c34fa | 9327 | tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x80000000); |
1c97856d AJ |
9328 | } |
9329 | ||
0487d6a8 | 9330 | /* Conversion */ |
1c97856d AJ |
9331 | GEN_SPEFPUOP_CONV_32_32(efscfui); |
9332 | GEN_SPEFPUOP_CONV_32_32(efscfsi); | |
9333 | GEN_SPEFPUOP_CONV_32_32(efscfuf); | |
9334 | GEN_SPEFPUOP_CONV_32_32(efscfsf); | |
9335 | GEN_SPEFPUOP_CONV_32_32(efsctui); | |
9336 | GEN_SPEFPUOP_CONV_32_32(efsctsi); | |
9337 | GEN_SPEFPUOP_CONV_32_32(efsctuf); | |
9338 | GEN_SPEFPUOP_CONV_32_32(efsctsf); | |
9339 | GEN_SPEFPUOP_CONV_32_32(efsctuiz); | |
9340 | GEN_SPEFPUOP_CONV_32_32(efsctsiz); | |
9341 | GEN_SPEFPUOP_CONV_32_64(efscfd); | |
9342 | ||
0487d6a8 | 9343 | /* Comparison */ |
1c97856d AJ |
9344 | GEN_SPEFPUOP_COMP_32(efscmpgt); |
9345 | GEN_SPEFPUOP_COMP_32(efscmplt); | |
9346 | GEN_SPEFPUOP_COMP_32(efscmpeq); | |
9347 | GEN_SPEFPUOP_COMP_32(efststgt); | |
9348 | GEN_SPEFPUOP_COMP_32(efststlt); | |
9349 | GEN_SPEFPUOP_COMP_32(efststeq); | |
0487d6a8 JM |
9350 | |
9351 | /* Opcodes definitions */ | |
70560da7 FC |
9352 | GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); // |
9353 | GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE); // | |
9354 | GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
9355 | GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE); // | |
9356 | GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); // | |
9357 | GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE); // | |
9358 | GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
9359 | GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
9360 | GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
9361 | GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE); // | |
9362 | GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
9363 | GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
9364 | GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE); // | |
9365 | GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE); // | |
0487d6a8 JM |
9366 | |
9367 | /* Double precision floating-point operations */ | |
9368 | /* Arithmetic */ | |
1c97856d AJ |
9369 | GEN_SPEFPUOP_ARITH2_64_64(efdadd); |
9370 | GEN_SPEFPUOP_ARITH2_64_64(efdsub); | |
9371 | GEN_SPEFPUOP_ARITH2_64_64(efdmul); | |
9372 | GEN_SPEFPUOP_ARITH2_64_64(efddiv); | |
636aa200 | 9373 | static inline void gen_efdabs(DisasContext *ctx) |
1c97856d AJ |
9374 | { |
9375 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 9376 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
9377 | return; |
9378 | } | |
9379 | #if defined(TARGET_PPC64) | |
6d5c34fa | 9380 | tcg_gen_andi_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], ~0x8000000000000000LL); |
1c97856d | 9381 | #else |
6d5c34fa MP |
9382 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
9383 | tcg_gen_andi_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], ~0x80000000); | |
1c97856d AJ |
9384 | #endif |
9385 | } | |
636aa200 | 9386 | static inline void gen_efdnabs(DisasContext *ctx) |
1c97856d AJ |
9387 | { |
9388 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 9389 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
9390 | return; |
9391 | } | |
9392 | #if defined(TARGET_PPC64) | |
6d5c34fa | 9393 | tcg_gen_ori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL); |
1c97856d | 9394 | #else |
6d5c34fa MP |
9395 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
9396 | tcg_gen_ori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000); | |
1c97856d AJ |
9397 | #endif |
9398 | } | |
636aa200 | 9399 | static inline void gen_efdneg(DisasContext *ctx) |
1c97856d AJ |
9400 | { |
9401 | if (unlikely(!ctx->spe_enabled)) { | |
27a69bb0 | 9402 | gen_exception(ctx, POWERPC_EXCP_SPEU); |
1c97856d AJ |
9403 | return; |
9404 | } | |
9405 | #if defined(TARGET_PPC64) | |
6d5c34fa | 9406 | tcg_gen_xori_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)], 0x8000000000000000LL); |
1c97856d | 9407 | #else |
6d5c34fa MP |
9408 | tcg_gen_mov_tl(cpu_gpr[rD(ctx->opcode)], cpu_gpr[rA(ctx->opcode)]); |
9409 | tcg_gen_xori_tl(cpu_gprh[rD(ctx->opcode)], cpu_gprh[rA(ctx->opcode)], 0x80000000); | |
1c97856d AJ |
9410 | #endif |
9411 | } | |
9412 | ||
0487d6a8 | 9413 | /* Conversion */ |
1c97856d AJ |
9414 | GEN_SPEFPUOP_CONV_64_32(efdcfui); |
9415 | GEN_SPEFPUOP_CONV_64_32(efdcfsi); | |
9416 | GEN_SPEFPUOP_CONV_64_32(efdcfuf); | |
9417 | GEN_SPEFPUOP_CONV_64_32(efdcfsf); | |
9418 | GEN_SPEFPUOP_CONV_32_64(efdctui); | |
9419 | GEN_SPEFPUOP_CONV_32_64(efdctsi); | |
9420 | GEN_SPEFPUOP_CONV_32_64(efdctuf); | |
9421 | GEN_SPEFPUOP_CONV_32_64(efdctsf); | |
9422 | GEN_SPEFPUOP_CONV_32_64(efdctuiz); | |
9423 | GEN_SPEFPUOP_CONV_32_64(efdctsiz); | |
9424 | GEN_SPEFPUOP_CONV_64_32(efdcfs); | |
9425 | GEN_SPEFPUOP_CONV_64_64(efdcfuid); | |
9426 | GEN_SPEFPUOP_CONV_64_64(efdcfsid); | |
9427 | GEN_SPEFPUOP_CONV_64_64(efdctuidz); | |
9428 | GEN_SPEFPUOP_CONV_64_64(efdctsidz); | |
0487d6a8 | 9429 | |
0487d6a8 | 9430 | /* Comparison */ |
1c97856d AJ |
9431 | GEN_SPEFPUOP_COMP_64(efdcmpgt); |
9432 | GEN_SPEFPUOP_COMP_64(efdcmplt); | |
9433 | GEN_SPEFPUOP_COMP_64(efdcmpeq); | |
9434 | GEN_SPEFPUOP_COMP_64(efdtstgt); | |
9435 | GEN_SPEFPUOP_COMP_64(efdtstlt); | |
9436 | GEN_SPEFPUOP_COMP_64(efdtsteq); | |
0487d6a8 JM |
9437 | |
9438 | /* Opcodes definitions */ | |
70560da7 FC |
9439 | GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); // |
9440 | GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
9441 | GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE); // | |
9442 | GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE); // | |
9443 | GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE); // | |
9444 | GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
9445 | GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); // | |
9446 | GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE); // | |
9447 | GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
9448 | GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
9449 | GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
9450 | GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE); // | |
9451 | GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); // | |
9452 | GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE); // | |
9453 | GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE); // | |
9454 | GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE); // | |
0487d6a8 | 9455 | |
c227f099 | 9456 | static opcode_t opcodes[] = { |
5c55ff99 BS |
9457 | GEN_HANDLER(invalid, 0x00, 0x00, 0x00, 0xFFFFFFFF, PPC_NONE), |
9458 | GEN_HANDLER(cmp, 0x1F, 0x00, 0x00, 0x00400000, PPC_INTEGER), | |
9459 | GEN_HANDLER(cmpi, 0x0B, 0xFF, 0xFF, 0x00400000, PPC_INTEGER), | |
9460 | GEN_HANDLER(cmpl, 0x1F, 0x00, 0x01, 0x00400000, PPC_INTEGER), | |
9461 | GEN_HANDLER(cmpli, 0x0A, 0xFF, 0xFF, 0x00400000, PPC_INTEGER), | |
fcfda20f | 9462 | GEN_HANDLER_E(cmpb, 0x1F, 0x1C, 0x0F, 0x00000001, PPC_NONE, PPC2_ISA205), |
5c55ff99 BS |
9463 | GEN_HANDLER(isel, 0x1F, 0x0F, 0xFF, 0x00000001, PPC_ISEL), |
9464 | GEN_HANDLER(addi, 0x0E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
9465 | GEN_HANDLER(addic, 0x0C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
9466 | GEN_HANDLER2(addic_, "addic.", 0x0D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
9467 | GEN_HANDLER(addis, 0x0F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
9468 | GEN_HANDLER(mulhw, 0x1F, 0x0B, 0x02, 0x00000400, PPC_INTEGER), | |
9469 | GEN_HANDLER(mulhwu, 0x1F, 0x0B, 0x00, 0x00000400, PPC_INTEGER), | |
9470 | GEN_HANDLER(mullw, 0x1F, 0x0B, 0x07, 0x00000000, PPC_INTEGER), | |
9471 | GEN_HANDLER(mullwo, 0x1F, 0x0B, 0x17, 0x00000000, PPC_INTEGER), | |
9472 | GEN_HANDLER(mulli, 0x07, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
9473 | #if defined(TARGET_PPC64) | |
9474 | GEN_HANDLER(mulld, 0x1F, 0x09, 0x07, 0x00000000, PPC_64B), | |
9475 | #endif | |
9476 | GEN_HANDLER(neg, 0x1F, 0x08, 0x03, 0x0000F800, PPC_INTEGER), | |
9477 | GEN_HANDLER(nego, 0x1F, 0x08, 0x13, 0x0000F800, PPC_INTEGER), | |
9478 | GEN_HANDLER(subfic, 0x08, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
9479 | GEN_HANDLER2(andi_, "andi.", 0x1C, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
9480 | GEN_HANDLER2(andis_, "andis.", 0x1D, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
9481 | GEN_HANDLER(cntlzw, 0x1F, 0x1A, 0x00, 0x00000000, PPC_INTEGER), | |
9482 | GEN_HANDLER(or, 0x1F, 0x1C, 0x0D, 0x00000000, PPC_INTEGER), | |
9483 | GEN_HANDLER(xor, 0x1F, 0x1C, 0x09, 0x00000000, PPC_INTEGER), | |
9484 | GEN_HANDLER(ori, 0x18, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
9485 | GEN_HANDLER(oris, 0x19, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
9486 | GEN_HANDLER(xori, 0x1A, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
9487 | GEN_HANDLER(xoris, 0x1B, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
9488 | GEN_HANDLER(popcntb, 0x1F, 0x03, 0x03, 0x0000F801, PPC_POPCNTB), | |
eaabeef2 | 9489 | GEN_HANDLER(popcntw, 0x1F, 0x1A, 0x0b, 0x0000F801, PPC_POPCNTWD), |
725bcec2 | 9490 | GEN_HANDLER_E(prtyw, 0x1F, 0x1A, 0x04, 0x0000F801, PPC_NONE, PPC2_ISA205), |
5c55ff99 | 9491 | #if defined(TARGET_PPC64) |
eaabeef2 | 9492 | GEN_HANDLER(popcntd, 0x1F, 0x1A, 0x0F, 0x0000F801, PPC_POPCNTWD), |
5c55ff99 | 9493 | GEN_HANDLER(cntlzd, 0x1F, 0x1A, 0x01, 0x00000000, PPC_64B), |
725bcec2 | 9494 | GEN_HANDLER_E(prtyd, 0x1F, 0x1A, 0x05, 0x0000F801, PPC_NONE, PPC2_ISA205), |
86ba37ed | 9495 | GEN_HANDLER_E(bpermd, 0x1F, 0x1C, 0x07, 0x00000001, PPC_NONE, PPC2_PERM_ISA206), |
5c55ff99 BS |
9496 | #endif |
9497 | GEN_HANDLER(rlwimi, 0x14, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
9498 | GEN_HANDLER(rlwinm, 0x15, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
9499 | GEN_HANDLER(rlwnm, 0x17, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
9500 | GEN_HANDLER(slw, 0x1F, 0x18, 0x00, 0x00000000, PPC_INTEGER), | |
9501 | GEN_HANDLER(sraw, 0x1F, 0x18, 0x18, 0x00000000, PPC_INTEGER), | |
9502 | GEN_HANDLER(srawi, 0x1F, 0x18, 0x19, 0x00000000, PPC_INTEGER), | |
9503 | GEN_HANDLER(srw, 0x1F, 0x18, 0x10, 0x00000000, PPC_INTEGER), | |
9504 | #if defined(TARGET_PPC64) | |
9505 | GEN_HANDLER(sld, 0x1F, 0x1B, 0x00, 0x00000000, PPC_64B), | |
9506 | GEN_HANDLER(srad, 0x1F, 0x1A, 0x18, 0x00000000, PPC_64B), | |
9507 | GEN_HANDLER2(sradi0, "sradi", 0x1F, 0x1A, 0x19, 0x00000000, PPC_64B), | |
9508 | GEN_HANDLER2(sradi1, "sradi", 0x1F, 0x1B, 0x19, 0x00000000, PPC_64B), | |
9509 | GEN_HANDLER(srd, 0x1F, 0x1B, 0x10, 0x00000000, PPC_64B), | |
9510 | #endif | |
9511 | GEN_HANDLER(frsqrtes, 0x3B, 0x1A, 0xFF, 0x001F07C0, PPC_FLOAT_FRSQRTES), | |
9512 | GEN_HANDLER(fsqrt, 0x3F, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT), | |
9513 | GEN_HANDLER(fsqrts, 0x3B, 0x16, 0xFF, 0x001F07C0, PPC_FLOAT_FSQRT), | |
9514 | GEN_HANDLER(fcmpo, 0x3F, 0x00, 0x01, 0x00600001, PPC_FLOAT), | |
9515 | GEN_HANDLER(fcmpu, 0x3F, 0x00, 0x00, 0x00600001, PPC_FLOAT), | |
bf45a2e6 | 9516 | GEN_HANDLER(fabs, 0x3F, 0x08, 0x08, 0x001F0000, PPC_FLOAT), |
5c55ff99 | 9517 | GEN_HANDLER(fmr, 0x3F, 0x08, 0x02, 0x001F0000, PPC_FLOAT), |
bf45a2e6 AJ |
9518 | GEN_HANDLER(fnabs, 0x3F, 0x08, 0x04, 0x001F0000, PPC_FLOAT), |
9519 | GEN_HANDLER(fneg, 0x3F, 0x08, 0x01, 0x001F0000, PPC_FLOAT), | |
f0332888 | 9520 | GEN_HANDLER_E(fcpsgn, 0x3F, 0x08, 0x00, 0x00000000, PPC_NONE, PPC2_ISA205), |
097ec5d8 TM |
9521 | GEN_HANDLER_E(fmrgew, 0x3F, 0x06, 0x1E, 0x00000001, PPC_NONE, PPC2_VSX207), |
9522 | GEN_HANDLER_E(fmrgow, 0x3F, 0x06, 0x1A, 0x00000001, PPC_NONE, PPC2_VSX207), | |
5c55ff99 BS |
9523 | GEN_HANDLER(mcrfs, 0x3F, 0x00, 0x02, 0x0063F801, PPC_FLOAT), |
9524 | GEN_HANDLER(mffs, 0x3F, 0x07, 0x12, 0x001FF800, PPC_FLOAT), | |
9525 | GEN_HANDLER(mtfsb0, 0x3F, 0x06, 0x02, 0x001FF800, PPC_FLOAT), | |
9526 | GEN_HANDLER(mtfsb1, 0x3F, 0x06, 0x01, 0x001FF800, PPC_FLOAT), | |
7d08d856 AJ |
9527 | GEN_HANDLER(mtfsf, 0x3F, 0x07, 0x16, 0x00000000, PPC_FLOAT), |
9528 | GEN_HANDLER(mtfsfi, 0x3F, 0x06, 0x04, 0x006e0800, PPC_FLOAT), | |
5c55ff99 BS |
9529 | #if defined(TARGET_PPC64) |
9530 | GEN_HANDLER(ld, 0x3A, 0xFF, 0xFF, 0x00000000, PPC_64B), | |
9531 | GEN_HANDLER(lq, 0x38, 0xFF, 0xFF, 0x00000000, PPC_64BX), | |
9532 | GEN_HANDLER(std, 0x3E, 0xFF, 0xFF, 0x00000000, PPC_64B), | |
9533 | #endif | |
9534 | GEN_HANDLER(lmw, 0x2E, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
9535 | GEN_HANDLER(stmw, 0x2F, 0xFF, 0xFF, 0x00000000, PPC_INTEGER), | |
9536 | GEN_HANDLER(lswi, 0x1F, 0x15, 0x12, 0x00000001, PPC_STRING), | |
9537 | GEN_HANDLER(lswx, 0x1F, 0x15, 0x10, 0x00000001, PPC_STRING), | |
9538 | GEN_HANDLER(stswi, 0x1F, 0x15, 0x16, 0x00000001, PPC_STRING), | |
9539 | GEN_HANDLER(stswx, 0x1F, 0x15, 0x14, 0x00000001, PPC_STRING), | |
9540 | GEN_HANDLER(eieio, 0x1F, 0x16, 0x1A, 0x03FFF801, PPC_MEM_EIEIO), | |
9541 | GEN_HANDLER(isync, 0x13, 0x16, 0x04, 0x03FFF801, PPC_MEM), | |
5c77a786 TM |
9542 | GEN_HANDLER_E(lbarx, 0x1F, 0x14, 0x01, 0, PPC_NONE, PPC2_ATOMIC_ISA206), |
9543 | GEN_HANDLER_E(lharx, 0x1F, 0x14, 0x03, 0, PPC_NONE, PPC2_ATOMIC_ISA206), | |
f844c817 | 9544 | GEN_HANDLER(lwarx, 0x1F, 0x14, 0x00, 0x00000000, PPC_RES), |
587c51f7 TM |
9545 | GEN_HANDLER_E(stbcx_, 0x1F, 0x16, 0x15, 0, PPC_NONE, PPC2_ATOMIC_ISA206), |
9546 | GEN_HANDLER_E(sthcx_, 0x1F, 0x16, 0x16, 0, PPC_NONE, PPC2_ATOMIC_ISA206), | |
5c55ff99 BS |
9547 | GEN_HANDLER2(stwcx_, "stwcx.", 0x1F, 0x16, 0x04, 0x00000000, PPC_RES), |
9548 | #if defined(TARGET_PPC64) | |
f844c817 | 9549 | GEN_HANDLER(ldarx, 0x1F, 0x14, 0x02, 0x00000000, PPC_64B), |
5c55ff99 BS |
9550 | GEN_HANDLER2(stdcx_, "stdcx.", 0x1F, 0x16, 0x06, 0x00000000, PPC_64B), |
9551 | #endif | |
9552 | GEN_HANDLER(sync, 0x1F, 0x16, 0x12, 0x039FF801, PPC_MEM_SYNC), | |
9553 | GEN_HANDLER(wait, 0x1F, 0x1E, 0x01, 0x03FFF801, PPC_WAIT), | |
9554 | GEN_HANDLER(b, 0x12, 0xFF, 0xFF, 0x00000000, PPC_FLOW), | |
9555 | GEN_HANDLER(bc, 0x10, 0xFF, 0xFF, 0x00000000, PPC_FLOW), | |
9556 | GEN_HANDLER(bcctr, 0x13, 0x10, 0x10, 0x00000000, PPC_FLOW), | |
9557 | GEN_HANDLER(bclr, 0x13, 0x10, 0x00, 0x00000000, PPC_FLOW), | |
9558 | GEN_HANDLER(mcrf, 0x13, 0x00, 0xFF, 0x00000001, PPC_INTEGER), | |
9559 | GEN_HANDLER(rfi, 0x13, 0x12, 0x01, 0x03FF8001, PPC_FLOW), | |
9560 | #if defined(TARGET_PPC64) | |
9561 | GEN_HANDLER(rfid, 0x13, 0x12, 0x00, 0x03FF8001, PPC_64B), | |
9562 | GEN_HANDLER(hrfid, 0x13, 0x12, 0x08, 0x03FF8001, PPC_64H), | |
9563 | #endif | |
9564 | GEN_HANDLER(sc, 0x11, 0xFF, 0xFF, 0x03FFF01D, PPC_FLOW), | |
9565 | GEN_HANDLER(tw, 0x1F, 0x04, 0x00, 0x00000001, PPC_FLOW), | |
9566 | GEN_HANDLER(twi, 0x03, 0xFF, 0xFF, 0x00000000, PPC_FLOW), | |
9567 | #if defined(TARGET_PPC64) | |
9568 | GEN_HANDLER(td, 0x1F, 0x04, 0x02, 0x00000001, PPC_64B), | |
9569 | GEN_HANDLER(tdi, 0x02, 0xFF, 0xFF, 0x00000000, PPC_64B), | |
9570 | #endif | |
9571 | GEN_HANDLER(mcrxr, 0x1F, 0x00, 0x10, 0x007FF801, PPC_MISC), | |
9572 | GEN_HANDLER(mfcr, 0x1F, 0x13, 0x00, 0x00000801, PPC_MISC), | |
9573 | GEN_HANDLER(mfmsr, 0x1F, 0x13, 0x02, 0x001FF801, PPC_MISC), | |
9574 | GEN_HANDLER(mfspr, 0x1F, 0x13, 0x0A, 0x00000001, PPC_MISC), | |
9575 | GEN_HANDLER(mftb, 0x1F, 0x13, 0x0B, 0x00000001, PPC_MFTB), | |
9576 | GEN_HANDLER(mtcrf, 0x1F, 0x10, 0x04, 0x00000801, PPC_MISC), | |
9577 | #if defined(TARGET_PPC64) | |
9578 | GEN_HANDLER(mtmsrd, 0x1F, 0x12, 0x05, 0x001EF801, PPC_64B), | |
9579 | #endif | |
9580 | GEN_HANDLER(mtmsr, 0x1F, 0x12, 0x04, 0x001FF801, PPC_MISC), | |
9581 | GEN_HANDLER(mtspr, 0x1F, 0x13, 0x0E, 0x00000001, PPC_MISC), | |
9582 | GEN_HANDLER(dcbf, 0x1F, 0x16, 0x02, 0x03C00001, PPC_CACHE), | |
9583 | GEN_HANDLER(dcbi, 0x1F, 0x16, 0x0E, 0x03E00001, PPC_CACHE), | |
9584 | GEN_HANDLER(dcbst, 0x1F, 0x16, 0x01, 0x03E00001, PPC_CACHE), | |
9585 | GEN_HANDLER(dcbt, 0x1F, 0x16, 0x08, 0x02000001, PPC_CACHE), | |
9586 | GEN_HANDLER(dcbtst, 0x1F, 0x16, 0x07, 0x02000001, PPC_CACHE), | |
8e33944f | 9587 | GEN_HANDLER(dcbz, 0x1F, 0x16, 0x1F, 0x03C00001, PPC_CACHE_DCBZ), |
5c55ff99 BS |
9588 | GEN_HANDLER(dst, 0x1F, 0x16, 0x0A, 0x01800001, PPC_ALTIVEC), |
9589 | GEN_HANDLER(dstst, 0x1F, 0x16, 0x0B, 0x02000001, PPC_ALTIVEC), | |
9590 | GEN_HANDLER(dss, 0x1F, 0x16, 0x19, 0x019FF801, PPC_ALTIVEC), | |
9591 | GEN_HANDLER(icbi, 0x1F, 0x16, 0x1E, 0x03E00001, PPC_CACHE_ICBI), | |
9592 | GEN_HANDLER(dcba, 0x1F, 0x16, 0x17, 0x03E00001, PPC_CACHE_DCBA), | |
9593 | GEN_HANDLER(mfsr, 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT), | |
9594 | GEN_HANDLER(mfsrin, 0x1F, 0x13, 0x14, 0x001F0001, PPC_SEGMENT), | |
9595 | GEN_HANDLER(mtsr, 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT), | |
9596 | GEN_HANDLER(mtsrin, 0x1F, 0x12, 0x07, 0x001F0001, PPC_SEGMENT), | |
9597 | #if defined(TARGET_PPC64) | |
9598 | GEN_HANDLER2(mfsr_64b, "mfsr", 0x1F, 0x13, 0x12, 0x0010F801, PPC_SEGMENT_64B), | |
9599 | GEN_HANDLER2(mfsrin_64b, "mfsrin", 0x1F, 0x13, 0x14, 0x001F0001, | |
9600 | PPC_SEGMENT_64B), | |
9601 | GEN_HANDLER2(mtsr_64b, "mtsr", 0x1F, 0x12, 0x06, 0x0010F801, PPC_SEGMENT_64B), | |
9602 | GEN_HANDLER2(mtsrin_64b, "mtsrin", 0x1F, 0x12, 0x07, 0x001F0001, | |
9603 | PPC_SEGMENT_64B), | |
efdef95f DG |
9604 | GEN_HANDLER2(slbmte, "slbmte", 0x1F, 0x12, 0x0C, 0x001F0001, PPC_SEGMENT_64B), |
9605 | GEN_HANDLER2(slbmfee, "slbmfee", 0x1F, 0x13, 0x1C, 0x001F0001, PPC_SEGMENT_64B), | |
9606 | GEN_HANDLER2(slbmfev, "slbmfev", 0x1F, 0x13, 0x1A, 0x001F0001, PPC_SEGMENT_64B), | |
5c55ff99 BS |
9607 | #endif |
9608 | GEN_HANDLER(tlbia, 0x1F, 0x12, 0x0B, 0x03FFFC01, PPC_MEM_TLBIA), | |
9609 | GEN_HANDLER(tlbiel, 0x1F, 0x12, 0x08, 0x03FF0001, PPC_MEM_TLBIE), | |
9610 | GEN_HANDLER(tlbie, 0x1F, 0x12, 0x09, 0x03FF0001, PPC_MEM_TLBIE), | |
9611 | GEN_HANDLER(tlbsync, 0x1F, 0x16, 0x11, 0x03FFF801, PPC_MEM_TLBSYNC), | |
9612 | #if defined(TARGET_PPC64) | |
9613 | GEN_HANDLER(slbia, 0x1F, 0x12, 0x0F, 0x03FFFC01, PPC_SLBI), | |
9614 | GEN_HANDLER(slbie, 0x1F, 0x12, 0x0D, 0x03FF0001, PPC_SLBI), | |
9615 | #endif | |
9616 | GEN_HANDLER(eciwx, 0x1F, 0x16, 0x0D, 0x00000001, PPC_EXTERN), | |
9617 | GEN_HANDLER(ecowx, 0x1F, 0x16, 0x09, 0x00000001, PPC_EXTERN), | |
9618 | GEN_HANDLER(abs, 0x1F, 0x08, 0x0B, 0x0000F800, PPC_POWER_BR), | |
9619 | GEN_HANDLER(abso, 0x1F, 0x08, 0x1B, 0x0000F800, PPC_POWER_BR), | |
9620 | GEN_HANDLER(clcs, 0x1F, 0x10, 0x13, 0x0000F800, PPC_POWER_BR), | |
9621 | GEN_HANDLER(div, 0x1F, 0x0B, 0x0A, 0x00000000, PPC_POWER_BR), | |
9622 | GEN_HANDLER(divo, 0x1F, 0x0B, 0x1A, 0x00000000, PPC_POWER_BR), | |
9623 | GEN_HANDLER(divs, 0x1F, 0x0B, 0x0B, 0x00000000, PPC_POWER_BR), | |
9624 | GEN_HANDLER(divso, 0x1F, 0x0B, 0x1B, 0x00000000, PPC_POWER_BR), | |
9625 | GEN_HANDLER(doz, 0x1F, 0x08, 0x08, 0x00000000, PPC_POWER_BR), | |
9626 | GEN_HANDLER(dozo, 0x1F, 0x08, 0x18, 0x00000000, PPC_POWER_BR), | |
9627 | GEN_HANDLER(dozi, 0x09, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR), | |
9628 | GEN_HANDLER(lscbx, 0x1F, 0x15, 0x08, 0x00000000, PPC_POWER_BR), | |
9629 | GEN_HANDLER(maskg, 0x1F, 0x1D, 0x00, 0x00000000, PPC_POWER_BR), | |
9630 | GEN_HANDLER(maskir, 0x1F, 0x1D, 0x10, 0x00000000, PPC_POWER_BR), | |
9631 | GEN_HANDLER(mul, 0x1F, 0x0B, 0x03, 0x00000000, PPC_POWER_BR), | |
9632 | GEN_HANDLER(mulo, 0x1F, 0x0B, 0x13, 0x00000000, PPC_POWER_BR), | |
9633 | GEN_HANDLER(nabs, 0x1F, 0x08, 0x0F, 0x00000000, PPC_POWER_BR), | |
9634 | GEN_HANDLER(nabso, 0x1F, 0x08, 0x1F, 0x00000000, PPC_POWER_BR), | |
9635 | GEN_HANDLER(rlmi, 0x16, 0xFF, 0xFF, 0x00000000, PPC_POWER_BR), | |
9636 | GEN_HANDLER(rrib, 0x1F, 0x19, 0x10, 0x00000000, PPC_POWER_BR), | |
9637 | GEN_HANDLER(sle, 0x1F, 0x19, 0x04, 0x00000000, PPC_POWER_BR), | |
9638 | GEN_HANDLER(sleq, 0x1F, 0x19, 0x06, 0x00000000, PPC_POWER_BR), | |
9639 | GEN_HANDLER(sliq, 0x1F, 0x18, 0x05, 0x00000000, PPC_POWER_BR), | |
9640 | GEN_HANDLER(slliq, 0x1F, 0x18, 0x07, 0x00000000, PPC_POWER_BR), | |
9641 | GEN_HANDLER(sllq, 0x1F, 0x18, 0x06, 0x00000000, PPC_POWER_BR), | |
9642 | GEN_HANDLER(slq, 0x1F, 0x18, 0x04, 0x00000000, PPC_POWER_BR), | |
9643 | GEN_HANDLER(sraiq, 0x1F, 0x18, 0x1D, 0x00000000, PPC_POWER_BR), | |
9644 | GEN_HANDLER(sraq, 0x1F, 0x18, 0x1C, 0x00000000, PPC_POWER_BR), | |
9645 | GEN_HANDLER(sre, 0x1F, 0x19, 0x14, 0x00000000, PPC_POWER_BR), | |
9646 | GEN_HANDLER(srea, 0x1F, 0x19, 0x1C, 0x00000000, PPC_POWER_BR), | |
9647 | GEN_HANDLER(sreq, 0x1F, 0x19, 0x16, 0x00000000, PPC_POWER_BR), | |
9648 | GEN_HANDLER(sriq, 0x1F, 0x18, 0x15, 0x00000000, PPC_POWER_BR), | |
9649 | GEN_HANDLER(srliq, 0x1F, 0x18, 0x17, 0x00000000, PPC_POWER_BR), | |
9650 | GEN_HANDLER(srlq, 0x1F, 0x18, 0x16, 0x00000000, PPC_POWER_BR), | |
9651 | GEN_HANDLER(srq, 0x1F, 0x18, 0x14, 0x00000000, PPC_POWER_BR), | |
9652 | GEN_HANDLER(dsa, 0x1F, 0x14, 0x13, 0x03FFF801, PPC_602_SPEC), | |
9653 | GEN_HANDLER(esa, 0x1F, 0x14, 0x12, 0x03FFF801, PPC_602_SPEC), | |
9654 | GEN_HANDLER(mfrom, 0x1F, 0x09, 0x08, 0x03E0F801, PPC_602_SPEC), | |
9655 | GEN_HANDLER2(tlbld_6xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_6xx_TLB), | |
9656 | GEN_HANDLER2(tlbli_6xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_6xx_TLB), | |
9657 | GEN_HANDLER2(tlbld_74xx, "tlbld", 0x1F, 0x12, 0x1E, 0x03FF0001, PPC_74xx_TLB), | |
9658 | GEN_HANDLER2(tlbli_74xx, "tlbli", 0x1F, 0x12, 0x1F, 0x03FF0001, PPC_74xx_TLB), | |
9659 | GEN_HANDLER(clf, 0x1F, 0x16, 0x03, 0x03E00000, PPC_POWER), | |
9660 | GEN_HANDLER(cli, 0x1F, 0x16, 0x0F, 0x03E00000, PPC_POWER), | |
9661 | GEN_HANDLER(dclst, 0x1F, 0x16, 0x13, 0x03E00000, PPC_POWER), | |
9662 | GEN_HANDLER(mfsri, 0x1F, 0x13, 0x13, 0x00000001, PPC_POWER), | |
9663 | GEN_HANDLER(rac, 0x1F, 0x12, 0x19, 0x00000001, PPC_POWER), | |
9664 | GEN_HANDLER(rfsvc, 0x13, 0x12, 0x02, 0x03FFF0001, PPC_POWER), | |
9665 | GEN_HANDLER(lfq, 0x38, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
9666 | GEN_HANDLER(lfqu, 0x39, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
9667 | GEN_HANDLER(lfqux, 0x1F, 0x17, 0x19, 0x00000001, PPC_POWER2), | |
9668 | GEN_HANDLER(lfqx, 0x1F, 0x17, 0x18, 0x00000001, PPC_POWER2), | |
9669 | GEN_HANDLER(stfq, 0x3C, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
9670 | GEN_HANDLER(stfqu, 0x3D, 0xFF, 0xFF, 0x00000003, PPC_POWER2), | |
9671 | GEN_HANDLER(stfqux, 0x1F, 0x17, 0x1D, 0x00000001, PPC_POWER2), | |
9672 | GEN_HANDLER(stfqx, 0x1F, 0x17, 0x1C, 0x00000001, PPC_POWER2), | |
9673 | GEN_HANDLER(mfapidi, 0x1F, 0x13, 0x08, 0x0000F801, PPC_MFAPIDI), | |
9674 | GEN_HANDLER(tlbiva, 0x1F, 0x12, 0x18, 0x03FFF801, PPC_TLBIVA), | |
9675 | GEN_HANDLER(mfdcr, 0x1F, 0x03, 0x0A, 0x00000001, PPC_DCR), | |
9676 | GEN_HANDLER(mtdcr, 0x1F, 0x03, 0x0E, 0x00000001, PPC_DCR), | |
9677 | GEN_HANDLER(mfdcrx, 0x1F, 0x03, 0x08, 0x00000000, PPC_DCRX), | |
9678 | GEN_HANDLER(mtdcrx, 0x1F, 0x03, 0x0C, 0x00000000, PPC_DCRX), | |
9679 | GEN_HANDLER(mfdcrux, 0x1F, 0x03, 0x09, 0x00000000, PPC_DCRUX), | |
9680 | GEN_HANDLER(mtdcrux, 0x1F, 0x03, 0x0D, 0x00000000, PPC_DCRUX), | |
9681 | GEN_HANDLER(dccci, 0x1F, 0x06, 0x0E, 0x03E00001, PPC_4xx_COMMON), | |
9682 | GEN_HANDLER(dcread, 0x1F, 0x06, 0x0F, 0x00000001, PPC_4xx_COMMON), | |
9683 | GEN_HANDLER2(icbt_40x, "icbt", 0x1F, 0x06, 0x08, 0x03E00001, PPC_40x_ICBT), | |
9684 | GEN_HANDLER(iccci, 0x1F, 0x06, 0x1E, 0x00000001, PPC_4xx_COMMON), | |
9685 | GEN_HANDLER(icread, 0x1F, 0x06, 0x1F, 0x03E00001, PPC_4xx_COMMON), | |
9686 | GEN_HANDLER2(rfci_40x, "rfci", 0x13, 0x13, 0x01, 0x03FF8001, PPC_40x_EXCP), | |
01662f3e | 9687 | GEN_HANDLER_E(rfci, 0x13, 0x13, 0x01, 0x03FF8001, PPC_BOOKE, PPC2_BOOKE206), |
5c55ff99 BS |
9688 | GEN_HANDLER(rfdi, 0x13, 0x07, 0x01, 0x03FF8001, PPC_RFDI), |
9689 | GEN_HANDLER(rfmci, 0x13, 0x06, 0x01, 0x03FF8001, PPC_RFMCI), | |
9690 | GEN_HANDLER2(tlbre_40x, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_40x_TLB), | |
9691 | GEN_HANDLER2(tlbsx_40x, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_40x_TLB), | |
9692 | GEN_HANDLER2(tlbwe_40x, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_40x_TLB), | |
9693 | GEN_HANDLER2(tlbre_440, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, PPC_BOOKE), | |
9694 | GEN_HANDLER2(tlbsx_440, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, PPC_BOOKE), | |
9695 | GEN_HANDLER2(tlbwe_440, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, PPC_BOOKE), | |
01662f3e AG |
9696 | GEN_HANDLER2_E(tlbre_booke206, "tlbre", 0x1F, 0x12, 0x1D, 0x00000001, |
9697 | PPC_NONE, PPC2_BOOKE206), | |
9698 | GEN_HANDLER2_E(tlbsx_booke206, "tlbsx", 0x1F, 0x12, 0x1C, 0x00000000, | |
9699 | PPC_NONE, PPC2_BOOKE206), | |
9700 | GEN_HANDLER2_E(tlbwe_booke206, "tlbwe", 0x1F, 0x12, 0x1E, 0x00000001, | |
9701 | PPC_NONE, PPC2_BOOKE206), | |
9702 | GEN_HANDLER2_E(tlbivax_booke206, "tlbivax", 0x1F, 0x12, 0x18, 0x00000001, | |
9703 | PPC_NONE, PPC2_BOOKE206), | |
6d3db821 AG |
9704 | GEN_HANDLER2_E(tlbilx_booke206, "tlbilx", 0x1F, 0x12, 0x00, 0x03800001, |
9705 | PPC_NONE, PPC2_BOOKE206), | |
d5d11a39 AG |
9706 | GEN_HANDLER2_E(msgsnd, "msgsnd", 0x1F, 0x0E, 0x06, 0x03ff0001, |
9707 | PPC_NONE, PPC2_PRCNTL), | |
9e0b5cb1 AG |
9708 | GEN_HANDLER2_E(msgclr, "msgclr", 0x1F, 0x0E, 0x07, 0x03ff0001, |
9709 | PPC_NONE, PPC2_PRCNTL), | |
5c55ff99 | 9710 | GEN_HANDLER(wrtee, 0x1F, 0x03, 0x04, 0x000FFC01, PPC_WRTEE), |
fbe73008 | 9711 | GEN_HANDLER(wrteei, 0x1F, 0x03, 0x05, 0x000E7C01, PPC_WRTEE), |
5c55ff99 | 9712 | GEN_HANDLER(dlmzb, 0x1F, 0x0E, 0x02, 0x00000000, PPC_440_SPEC), |
01662f3e AG |
9713 | GEN_HANDLER_E(mbar, 0x1F, 0x16, 0x1a, 0x001FF801, |
9714 | PPC_BOOKE, PPC2_BOOKE206), | |
dcb2b9e1 | 9715 | GEN_HANDLER(msync_4xx, 0x1F, 0x16, 0x12, 0x03FFF801, PPC_BOOKE), |
01662f3e AG |
9716 | GEN_HANDLER2_E(icbt_440, "icbt", 0x1F, 0x16, 0x00, 0x03E00001, |
9717 | PPC_BOOKE, PPC2_BOOKE206), | |
5c55ff99 BS |
9718 | GEN_HANDLER(lvsl, 0x1f, 0x06, 0x00, 0x00000001, PPC_ALTIVEC), |
9719 | GEN_HANDLER(lvsr, 0x1f, 0x06, 0x01, 0x00000001, PPC_ALTIVEC), | |
9720 | GEN_HANDLER(mfvscr, 0x04, 0x2, 0x18, 0x001ff800, PPC_ALTIVEC), | |
9721 | GEN_HANDLER(mtvscr, 0x04, 0x2, 0x19, 0x03ff0000, PPC_ALTIVEC), | |
9722 | GEN_HANDLER(vsldoi, 0x04, 0x16, 0xFF, 0x00000400, PPC_ALTIVEC), | |
9723 | GEN_HANDLER(vmladduhm, 0x04, 0x11, 0xFF, 0x00000000, PPC_ALTIVEC), | |
9724 | GEN_HANDLER2(evsel0, "evsel", 0x04, 0x1c, 0x09, 0x00000000, PPC_SPE), | |
9725 | GEN_HANDLER2(evsel1, "evsel", 0x04, 0x1d, 0x09, 0x00000000, PPC_SPE), | |
9726 | GEN_HANDLER2(evsel2, "evsel", 0x04, 0x1e, 0x09, 0x00000000, PPC_SPE), | |
9727 | GEN_HANDLER2(evsel3, "evsel", 0x04, 0x1f, 0x09, 0x00000000, PPC_SPE), | |
9728 | ||
9729 | #undef GEN_INT_ARITH_ADD | |
9730 | #undef GEN_INT_ARITH_ADD_CONST | |
9731 | #define GEN_INT_ARITH_ADD(name, opc3, add_ca, compute_ca, compute_ov) \ | |
9732 | GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x00000000, PPC_INTEGER), | |
9733 | #define GEN_INT_ARITH_ADD_CONST(name, opc3, const_val, \ | |
9734 | add_ca, compute_ca, compute_ov) \ | |
9735 | GEN_HANDLER(name, 0x1F, 0x0A, opc3, 0x0000F800, PPC_INTEGER), | |
9736 | GEN_INT_ARITH_ADD(add, 0x08, 0, 0, 0) | |
9737 | GEN_INT_ARITH_ADD(addo, 0x18, 0, 0, 1) | |
9738 | GEN_INT_ARITH_ADD(addc, 0x00, 0, 1, 0) | |
9739 | GEN_INT_ARITH_ADD(addco, 0x10, 0, 1, 1) | |
9740 | GEN_INT_ARITH_ADD(adde, 0x04, 1, 1, 0) | |
9741 | GEN_INT_ARITH_ADD(addeo, 0x14, 1, 1, 1) | |
9742 | GEN_INT_ARITH_ADD_CONST(addme, 0x07, -1LL, 1, 1, 0) | |
9743 | GEN_INT_ARITH_ADD_CONST(addmeo, 0x17, -1LL, 1, 1, 1) | |
9744 | GEN_INT_ARITH_ADD_CONST(addze, 0x06, 0, 1, 1, 0) | |
9745 | GEN_INT_ARITH_ADD_CONST(addzeo, 0x16, 0, 1, 1, 1) | |
9746 | ||
9747 | #undef GEN_INT_ARITH_DIVW | |
9748 | #define GEN_INT_ARITH_DIVW(name, opc3, sign, compute_ov) \ | |
9749 | GEN_HANDLER(name, 0x1F, 0x0B, opc3, 0x00000000, PPC_INTEGER) | |
9750 | GEN_INT_ARITH_DIVW(divwu, 0x0E, 0, 0), | |
9751 | GEN_INT_ARITH_DIVW(divwuo, 0x1E, 0, 1), | |
9752 | GEN_INT_ARITH_DIVW(divw, 0x0F, 1, 0), | |
9753 | GEN_INT_ARITH_DIVW(divwo, 0x1F, 1, 1), | |
a98eb9e9 TM |
9754 | GEN_HANDLER_E(divwe, 0x1F, 0x0B, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206), |
9755 | GEN_HANDLER_E(divweo, 0x1F, 0x0B, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206), | |
6a4fda33 TM |
9756 | GEN_HANDLER_E(divweu, 0x1F, 0x0B, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206), |
9757 | GEN_HANDLER_E(divweuo, 0x1F, 0x0B, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206), | |
5c55ff99 BS |
9758 | |
9759 | #if defined(TARGET_PPC64) | |
9760 | #undef GEN_INT_ARITH_DIVD | |
9761 | #define GEN_INT_ARITH_DIVD(name, opc3, sign, compute_ov) \ | |
9762 | GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) | |
9763 | GEN_INT_ARITH_DIVD(divdu, 0x0E, 0, 0), | |
9764 | GEN_INT_ARITH_DIVD(divduo, 0x1E, 0, 1), | |
9765 | GEN_INT_ARITH_DIVD(divd, 0x0F, 1, 0), | |
9766 | GEN_INT_ARITH_DIVD(divdo, 0x1F, 1, 1), | |
9767 | ||
98d1eb27 TM |
9768 | GEN_HANDLER_E(divdeu, 0x1F, 0x09, 0x0C, 0, PPC_NONE, PPC2_DIVE_ISA206), |
9769 | GEN_HANDLER_E(divdeuo, 0x1F, 0x09, 0x1C, 0, PPC_NONE, PPC2_DIVE_ISA206), | |
e44259b6 TM |
9770 | GEN_HANDLER_E(divde, 0x1F, 0x09, 0x0D, 0, PPC_NONE, PPC2_DIVE_ISA206), |
9771 | GEN_HANDLER_E(divdeo, 0x1F, 0x09, 0x1D, 0, PPC_NONE, PPC2_DIVE_ISA206), | |
98d1eb27 | 9772 | |
5c55ff99 BS |
9773 | #undef GEN_INT_ARITH_MUL_HELPER |
9774 | #define GEN_INT_ARITH_MUL_HELPER(name, opc3) \ | |
9775 | GEN_HANDLER(name, 0x1F, 0x09, opc3, 0x00000000, PPC_64B) | |
9776 | GEN_INT_ARITH_MUL_HELPER(mulhdu, 0x00), | |
9777 | GEN_INT_ARITH_MUL_HELPER(mulhd, 0x02), | |
9778 | GEN_INT_ARITH_MUL_HELPER(mulldo, 0x17), | |
9779 | #endif | |
9780 | ||
9781 | #undef GEN_INT_ARITH_SUBF | |
9782 | #undef GEN_INT_ARITH_SUBF_CONST | |
9783 | #define GEN_INT_ARITH_SUBF(name, opc3, add_ca, compute_ca, compute_ov) \ | |
9784 | GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x00000000, PPC_INTEGER), | |
9785 | #define GEN_INT_ARITH_SUBF_CONST(name, opc3, const_val, \ | |
9786 | add_ca, compute_ca, compute_ov) \ | |
9787 | GEN_HANDLER(name, 0x1F, 0x08, opc3, 0x0000F800, PPC_INTEGER), | |
9788 | GEN_INT_ARITH_SUBF(subf, 0x01, 0, 0, 0) | |
9789 | GEN_INT_ARITH_SUBF(subfo, 0x11, 0, 0, 1) | |
9790 | GEN_INT_ARITH_SUBF(subfc, 0x00, 0, 1, 0) | |
9791 | GEN_INT_ARITH_SUBF(subfco, 0x10, 0, 1, 1) | |
9792 | GEN_INT_ARITH_SUBF(subfe, 0x04, 1, 1, 0) | |
9793 | GEN_INT_ARITH_SUBF(subfeo, 0x14, 1, 1, 1) | |
9794 | GEN_INT_ARITH_SUBF_CONST(subfme, 0x07, -1LL, 1, 1, 0) | |
9795 | GEN_INT_ARITH_SUBF_CONST(subfmeo, 0x17, -1LL, 1, 1, 1) | |
9796 | GEN_INT_ARITH_SUBF_CONST(subfze, 0x06, 0, 1, 1, 0) | |
9797 | GEN_INT_ARITH_SUBF_CONST(subfzeo, 0x16, 0, 1, 1, 1) | |
9798 | ||
9799 | #undef GEN_LOGICAL1 | |
9800 | #undef GEN_LOGICAL2 | |
9801 | #define GEN_LOGICAL2(name, tcg_op, opc, type) \ | |
9802 | GEN_HANDLER(name, 0x1F, 0x1C, opc, 0x00000000, type) | |
9803 | #define GEN_LOGICAL1(name, tcg_op, opc, type) \ | |
9804 | GEN_HANDLER(name, 0x1F, 0x1A, opc, 0x00000000, type) | |
9805 | GEN_LOGICAL2(and, tcg_gen_and_tl, 0x00, PPC_INTEGER), | |
9806 | GEN_LOGICAL2(andc, tcg_gen_andc_tl, 0x01, PPC_INTEGER), | |
9807 | GEN_LOGICAL2(eqv, tcg_gen_eqv_tl, 0x08, PPC_INTEGER), | |
9808 | GEN_LOGICAL1(extsb, tcg_gen_ext8s_tl, 0x1D, PPC_INTEGER), | |
9809 | GEN_LOGICAL1(extsh, tcg_gen_ext16s_tl, 0x1C, PPC_INTEGER), | |
9810 | GEN_LOGICAL2(nand, tcg_gen_nand_tl, 0x0E, PPC_INTEGER), | |
9811 | GEN_LOGICAL2(nor, tcg_gen_nor_tl, 0x03, PPC_INTEGER), | |
9812 | GEN_LOGICAL2(orc, tcg_gen_orc_tl, 0x0C, PPC_INTEGER), | |
9813 | #if defined(TARGET_PPC64) | |
9814 | GEN_LOGICAL1(extsw, tcg_gen_ext32s_tl, 0x1E, PPC_64B), | |
9815 | #endif | |
9816 | ||
9817 | #if defined(TARGET_PPC64) | |
9818 | #undef GEN_PPC64_R2 | |
9819 | #undef GEN_PPC64_R4 | |
9820 | #define GEN_PPC64_R2(name, opc1, opc2) \ | |
9821 | GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\ | |
9822 | GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \ | |
9823 | PPC_64B) | |
9824 | #define GEN_PPC64_R4(name, opc1, opc2) \ | |
9825 | GEN_HANDLER2(name##0, stringify(name), opc1, opc2, 0xFF, 0x00000000, PPC_64B),\ | |
9826 | GEN_HANDLER2(name##1, stringify(name), opc1, opc2 | 0x01, 0xFF, 0x00000000, \ | |
9827 | PPC_64B), \ | |
9828 | GEN_HANDLER2(name##2, stringify(name), opc1, opc2 | 0x10, 0xFF, 0x00000000, \ | |
9829 | PPC_64B), \ | |
9830 | GEN_HANDLER2(name##3, stringify(name), opc1, opc2 | 0x11, 0xFF, 0x00000000, \ | |
9831 | PPC_64B) | |
9832 | GEN_PPC64_R4(rldicl, 0x1E, 0x00), | |
9833 | GEN_PPC64_R4(rldicr, 0x1E, 0x02), | |
9834 | GEN_PPC64_R4(rldic, 0x1E, 0x04), | |
9835 | GEN_PPC64_R2(rldcl, 0x1E, 0x08), | |
9836 | GEN_PPC64_R2(rldcr, 0x1E, 0x09), | |
9837 | GEN_PPC64_R4(rldimi, 0x1E, 0x06), | |
9838 | #endif | |
9839 | ||
9840 | #undef _GEN_FLOAT_ACB | |
9841 | #undef GEN_FLOAT_ACB | |
9842 | #undef _GEN_FLOAT_AB | |
9843 | #undef GEN_FLOAT_AB | |
9844 | #undef _GEN_FLOAT_AC | |
9845 | #undef GEN_FLOAT_AC | |
9846 | #undef GEN_FLOAT_B | |
9847 | #undef GEN_FLOAT_BS | |
9848 | #define _GEN_FLOAT_ACB(name, op, op1, op2, isfloat, set_fprf, type) \ | |
9849 | GEN_HANDLER(f##name, op1, op2, 0xFF, 0x00000000, type) | |
9850 | #define GEN_FLOAT_ACB(name, op2, set_fprf, type) \ | |
9851 | _GEN_FLOAT_ACB(name, name, 0x3F, op2, 0, set_fprf, type), \ | |
9852 | _GEN_FLOAT_ACB(name##s, name, 0x3B, op2, 1, set_fprf, type) | |
9853 | #define _GEN_FLOAT_AB(name, op, op1, op2, inval, isfloat, set_fprf, type) \ | |
9854 | GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) | |
9855 | #define GEN_FLOAT_AB(name, op2, inval, set_fprf, type) \ | |
9856 | _GEN_FLOAT_AB(name, name, 0x3F, op2, inval, 0, set_fprf, type), \ | |
9857 | _GEN_FLOAT_AB(name##s, name, 0x3B, op2, inval, 1, set_fprf, type) | |
9858 | #define _GEN_FLOAT_AC(name, op, op1, op2, inval, isfloat, set_fprf, type) \ | |
9859 | GEN_HANDLER(f##name, op1, op2, 0xFF, inval, type) | |
9860 | #define GEN_FLOAT_AC(name, op2, inval, set_fprf, type) \ | |
9861 | _GEN_FLOAT_AC(name, name, 0x3F, op2, inval, 0, set_fprf, type), \ | |
9862 | _GEN_FLOAT_AC(name##s, name, 0x3B, op2, inval, 1, set_fprf, type) | |
9863 | #define GEN_FLOAT_B(name, op2, op3, set_fprf, type) \ | |
9864 | GEN_HANDLER(f##name, 0x3F, op2, op3, 0x001F0000, type) | |
9865 | #define GEN_FLOAT_BS(name, op1, op2, set_fprf, type) \ | |
9866 | GEN_HANDLER(f##name, op1, op2, 0xFF, 0x001F07C0, type) | |
9867 | ||
9868 | GEN_FLOAT_AB(add, 0x15, 0x000007C0, 1, PPC_FLOAT), | |
9869 | GEN_FLOAT_AB(div, 0x12, 0x000007C0, 1, PPC_FLOAT), | |
9870 | GEN_FLOAT_AC(mul, 0x19, 0x0000F800, 1, PPC_FLOAT), | |
9871 | GEN_FLOAT_BS(re, 0x3F, 0x18, 1, PPC_FLOAT_EXT), | |
9872 | GEN_FLOAT_BS(res, 0x3B, 0x18, 1, PPC_FLOAT_FRES), | |
9873 | GEN_FLOAT_BS(rsqrte, 0x3F, 0x1A, 1, PPC_FLOAT_FRSQRTE), | |
9874 | _GEN_FLOAT_ACB(sel, sel, 0x3F, 0x17, 0, 0, PPC_FLOAT_FSEL), | |
9875 | GEN_FLOAT_AB(sub, 0x14, 0x000007C0, 1, PPC_FLOAT), | |
9876 | GEN_FLOAT_ACB(madd, 0x1D, 1, PPC_FLOAT), | |
9877 | GEN_FLOAT_ACB(msub, 0x1C, 1, PPC_FLOAT), | |
9878 | GEN_FLOAT_ACB(nmadd, 0x1F, 1, PPC_FLOAT), | |
9879 | GEN_FLOAT_ACB(nmsub, 0x1E, 1, PPC_FLOAT), | |
da29cb7b | 9880 | GEN_HANDLER_E(ftdiv, 0x3F, 0x00, 0x04, 1, PPC_NONE, PPC2_FP_TST_ISA206), |
6d41d146 | 9881 | GEN_HANDLER_E(ftsqrt, 0x3F, 0x00, 0x05, 1, PPC_NONE, PPC2_FP_TST_ISA206), |
5c55ff99 | 9882 | GEN_FLOAT_B(ctiw, 0x0E, 0x00, 0, PPC_FLOAT), |
fab7fe42 | 9883 | GEN_HANDLER_E(fctiwu, 0x3F, 0x0E, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206), |
5c55ff99 | 9884 | GEN_FLOAT_B(ctiwz, 0x0F, 0x00, 0, PPC_FLOAT), |
fab7fe42 | 9885 | GEN_HANDLER_E(fctiwuz, 0x3F, 0x0F, 0x04, 0, PPC_NONE, PPC2_FP_CVT_ISA206), |
5c55ff99 BS |
9886 | GEN_FLOAT_B(rsp, 0x0C, 0x00, 1, PPC_FLOAT), |
9887 | #if defined(TARGET_PPC64) | |
9888 | GEN_FLOAT_B(cfid, 0x0E, 0x1A, 1, PPC_64B), | |
28288b48 TM |
9889 | GEN_HANDLER_E(fcfids, 0x3B, 0x0E, 0x1A, 0, PPC_NONE, PPC2_FP_CVT_ISA206), |
9890 | GEN_HANDLER_E(fcfidu, 0x3F, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206), | |
9891 | GEN_HANDLER_E(fcfidus, 0x3B, 0x0E, 0x1E, 0, PPC_NONE, PPC2_FP_CVT_ISA206), | |
5c55ff99 | 9892 | GEN_FLOAT_B(ctid, 0x0E, 0x19, 0, PPC_64B), |
fab7fe42 | 9893 | GEN_HANDLER_E(fctidu, 0x3F, 0x0E, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206), |
5c55ff99 | 9894 | GEN_FLOAT_B(ctidz, 0x0F, 0x19, 0, PPC_64B), |
fab7fe42 | 9895 | GEN_HANDLER_E(fctiduz, 0x3F, 0x0F, 0x1D, 0, PPC_NONE, PPC2_FP_CVT_ISA206), |
5c55ff99 BS |
9896 | #endif |
9897 | GEN_FLOAT_B(rin, 0x08, 0x0C, 1, PPC_FLOAT_EXT), | |
9898 | GEN_FLOAT_B(riz, 0x08, 0x0D, 1, PPC_FLOAT_EXT), | |
9899 | GEN_FLOAT_B(rip, 0x08, 0x0E, 1, PPC_FLOAT_EXT), | |
9900 | GEN_FLOAT_B(rim, 0x08, 0x0F, 1, PPC_FLOAT_EXT), | |
5c55ff99 BS |
9901 | |
9902 | #undef GEN_LD | |
9903 | #undef GEN_LDU | |
9904 | #undef GEN_LDUX | |
cd6e9320 | 9905 | #undef GEN_LDX_E |
5c55ff99 BS |
9906 | #undef GEN_LDS |
9907 | #define GEN_LD(name, ldop, opc, type) \ | |
9908 | GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), | |
9909 | #define GEN_LDU(name, ldop, opc, type) \ | |
9910 | GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type), | |
9911 | #define GEN_LDUX(name, ldop, opc2, opc3, type) \ | |
9912 | GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type), | |
cd6e9320 TH |
9913 | #define GEN_LDX_E(name, ldop, opc2, opc3, type, type2) \ |
9914 | GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2), | |
5c55ff99 BS |
9915 | #define GEN_LDS(name, ldop, op, type) \ |
9916 | GEN_LD(name, ldop, op | 0x20, type) \ | |
9917 | GEN_LDU(name, ldop, op | 0x21, type) \ | |
9918 | GEN_LDUX(name, ldop, 0x17, op | 0x01, type) \ | |
9919 | GEN_LDX(name, ldop, 0x17, op | 0x00, type) | |
9920 | ||
9921 | GEN_LDS(lbz, ld8u, 0x02, PPC_INTEGER) | |
9922 | GEN_LDS(lha, ld16s, 0x0A, PPC_INTEGER) | |
9923 | GEN_LDS(lhz, ld16u, 0x08, PPC_INTEGER) | |
9924 | GEN_LDS(lwz, ld32u, 0x00, PPC_INTEGER) | |
9925 | #if defined(TARGET_PPC64) | |
9926 | GEN_LDUX(lwa, ld32s, 0x15, 0x0B, PPC_64B) | |
9927 | GEN_LDX(lwa, ld32s, 0x15, 0x0A, PPC_64B) | |
9928 | GEN_LDUX(ld, ld64, 0x15, 0x01, PPC_64B) | |
9929 | GEN_LDX(ld, ld64, 0x15, 0x00, PPC_64B) | |
cd6e9320 | 9930 | GEN_LDX_E(ldbr, ld64ur, 0x14, 0x10, PPC_NONE, PPC2_DBRX) |
5c55ff99 BS |
9931 | #endif |
9932 | GEN_LDX(lhbr, ld16ur, 0x16, 0x18, PPC_INTEGER) | |
9933 | GEN_LDX(lwbr, ld32ur, 0x16, 0x10, PPC_INTEGER) | |
9934 | ||
9935 | #undef GEN_ST | |
9936 | #undef GEN_STU | |
9937 | #undef GEN_STUX | |
cd6e9320 | 9938 | #undef GEN_STX_E |
5c55ff99 BS |
9939 | #undef GEN_STS |
9940 | #define GEN_ST(name, stop, opc, type) \ | |
9941 | GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), | |
9942 | #define GEN_STU(name, stop, opc, type) \ | |
9943 | GEN_HANDLER(stop##u, opc, 0xFF, 0xFF, 0x00000000, type), | |
9944 | #define GEN_STUX(name, stop, opc2, opc3, type) \ | |
9945 | GEN_HANDLER(name##ux, 0x1F, opc2, opc3, 0x00000001, type), | |
cd6e9320 TH |
9946 | #define GEN_STX_E(name, stop, opc2, opc3, type, type2) \ |
9947 | GEN_HANDLER_E(name##x, 0x1F, opc2, opc3, 0x00000001, type, type2), | |
5c55ff99 BS |
9948 | #define GEN_STS(name, stop, op, type) \ |
9949 | GEN_ST(name, stop, op | 0x20, type) \ | |
9950 | GEN_STU(name, stop, op | 0x21, type) \ | |
9951 | GEN_STUX(name, stop, 0x17, op | 0x01, type) \ | |
9952 | GEN_STX(name, stop, 0x17, op | 0x00, type) | |
9953 | ||
9954 | GEN_STS(stb, st8, 0x06, PPC_INTEGER) | |
9955 | GEN_STS(sth, st16, 0x0C, PPC_INTEGER) | |
9956 | GEN_STS(stw, st32, 0x04, PPC_INTEGER) | |
9957 | #if defined(TARGET_PPC64) | |
9958 | GEN_STUX(std, st64, 0x15, 0x05, PPC_64B) | |
9959 | GEN_STX(std, st64, 0x15, 0x04, PPC_64B) | |
cd6e9320 | 9960 | GEN_STX_E(stdbr, st64r, 0x14, 0x14, PPC_NONE, PPC2_DBRX) |
5c55ff99 BS |
9961 | #endif |
9962 | GEN_STX(sthbr, st16r, 0x16, 0x1C, PPC_INTEGER) | |
9963 | GEN_STX(stwbr, st32r, 0x16, 0x14, PPC_INTEGER) | |
9964 | ||
9965 | #undef GEN_LDF | |
9966 | #undef GEN_LDUF | |
9967 | #undef GEN_LDUXF | |
9968 | #undef GEN_LDXF | |
9969 | #undef GEN_LDFS | |
9970 | #define GEN_LDF(name, ldop, opc, type) \ | |
9971 | GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), | |
9972 | #define GEN_LDUF(name, ldop, opc, type) \ | |
9973 | GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type), | |
9974 | #define GEN_LDUXF(name, ldop, opc, type) \ | |
9975 | GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type), | |
9976 | #define GEN_LDXF(name, ldop, opc2, opc3, type) \ | |
9977 | GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type), | |
9978 | #define GEN_LDFS(name, ldop, op, type) \ | |
9979 | GEN_LDF(name, ldop, op | 0x20, type) \ | |
9980 | GEN_LDUF(name, ldop, op | 0x21, type) \ | |
9981 | GEN_LDUXF(name, ldop, op | 0x01, type) \ | |
9982 | GEN_LDXF(name, ldop, 0x17, op | 0x00, type) | |
9983 | ||
9984 | GEN_LDFS(lfd, ld64, 0x12, PPC_FLOAT) | |
9985 | GEN_LDFS(lfs, ld32fs, 0x10, PPC_FLOAT) | |
199f830d | 9986 | GEN_HANDLER_E(lfiwax, 0x1f, 0x17, 0x1a, 0x00000001, PPC_NONE, PPC2_ISA205), |
05050ee8 AJ |
9987 | GEN_HANDLER_E(lfdp, 0x39, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205), |
9988 | GEN_HANDLER_E(lfdpx, 0x1F, 0x17, 0x18, 0x00200001, PPC_NONE, PPC2_ISA205), | |
5c55ff99 BS |
9989 | |
9990 | #undef GEN_STF | |
9991 | #undef GEN_STUF | |
9992 | #undef GEN_STUXF | |
9993 | #undef GEN_STXF | |
9994 | #undef GEN_STFS | |
9995 | #define GEN_STF(name, stop, opc, type) \ | |
9996 | GEN_HANDLER(name, opc, 0xFF, 0xFF, 0x00000000, type), | |
9997 | #define GEN_STUF(name, stop, opc, type) \ | |
9998 | GEN_HANDLER(name##u, opc, 0xFF, 0xFF, 0x00000000, type), | |
9999 | #define GEN_STUXF(name, stop, opc, type) \ | |
10000 | GEN_HANDLER(name##ux, 0x1F, 0x17, opc, 0x00000001, type), | |
10001 | #define GEN_STXF(name, stop, opc2, opc3, type) \ | |
10002 | GEN_HANDLER(name##x, 0x1F, opc2, opc3, 0x00000001, type), | |
10003 | #define GEN_STFS(name, stop, op, type) \ | |
10004 | GEN_STF(name, stop, op | 0x20, type) \ | |
10005 | GEN_STUF(name, stop, op | 0x21, type) \ | |
10006 | GEN_STUXF(name, stop, op | 0x01, type) \ | |
10007 | GEN_STXF(name, stop, 0x17, op | 0x00, type) | |
10008 | ||
10009 | GEN_STFS(stfd, st64, 0x16, PPC_FLOAT) | |
10010 | GEN_STFS(stfs, st32fs, 0x14, PPC_FLOAT) | |
10011 | GEN_STXF(stfiw, st32fiw, 0x17, 0x1E, PPC_FLOAT_STFIWX) | |
44bc0c4d AJ |
10012 | GEN_HANDLER_E(stfdp, 0x3D, 0xFF, 0xFF, 0x00200003, PPC_NONE, PPC2_ISA205), |
10013 | GEN_HANDLER_E(stfdpx, 0x1F, 0x17, 0x1C, 0x00200001, PPC_NONE, PPC2_ISA205), | |
5c55ff99 BS |
10014 | |
10015 | #undef GEN_CRLOGIC | |
10016 | #define GEN_CRLOGIC(name, tcg_op, opc) \ | |
10017 | GEN_HANDLER(name, 0x13, 0x01, opc, 0x00000001, PPC_INTEGER) | |
10018 | GEN_CRLOGIC(crand, tcg_gen_and_i32, 0x08), | |
10019 | GEN_CRLOGIC(crandc, tcg_gen_andc_i32, 0x04), | |
10020 | GEN_CRLOGIC(creqv, tcg_gen_eqv_i32, 0x09), | |
10021 | GEN_CRLOGIC(crnand, tcg_gen_nand_i32, 0x07), | |
10022 | GEN_CRLOGIC(crnor, tcg_gen_nor_i32, 0x01), | |
10023 | GEN_CRLOGIC(cror, tcg_gen_or_i32, 0x0E), | |
10024 | GEN_CRLOGIC(crorc, tcg_gen_orc_i32, 0x0D), | |
10025 | GEN_CRLOGIC(crxor, tcg_gen_xor_i32, 0x06), | |
10026 | ||
10027 | #undef GEN_MAC_HANDLER | |
10028 | #define GEN_MAC_HANDLER(name, opc2, opc3) \ | |
10029 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_405_MAC) | |
10030 | GEN_MAC_HANDLER(macchw, 0x0C, 0x05), | |
10031 | GEN_MAC_HANDLER(macchwo, 0x0C, 0x15), | |
10032 | GEN_MAC_HANDLER(macchws, 0x0C, 0x07), | |
10033 | GEN_MAC_HANDLER(macchwso, 0x0C, 0x17), | |
10034 | GEN_MAC_HANDLER(macchwsu, 0x0C, 0x06), | |
10035 | GEN_MAC_HANDLER(macchwsuo, 0x0C, 0x16), | |
10036 | GEN_MAC_HANDLER(macchwu, 0x0C, 0x04), | |
10037 | GEN_MAC_HANDLER(macchwuo, 0x0C, 0x14), | |
10038 | GEN_MAC_HANDLER(machhw, 0x0C, 0x01), | |
10039 | GEN_MAC_HANDLER(machhwo, 0x0C, 0x11), | |
10040 | GEN_MAC_HANDLER(machhws, 0x0C, 0x03), | |
10041 | GEN_MAC_HANDLER(machhwso, 0x0C, 0x13), | |
10042 | GEN_MAC_HANDLER(machhwsu, 0x0C, 0x02), | |
10043 | GEN_MAC_HANDLER(machhwsuo, 0x0C, 0x12), | |
10044 | GEN_MAC_HANDLER(machhwu, 0x0C, 0x00), | |
10045 | GEN_MAC_HANDLER(machhwuo, 0x0C, 0x10), | |
10046 | GEN_MAC_HANDLER(maclhw, 0x0C, 0x0D), | |
10047 | GEN_MAC_HANDLER(maclhwo, 0x0C, 0x1D), | |
10048 | GEN_MAC_HANDLER(maclhws, 0x0C, 0x0F), | |
10049 | GEN_MAC_HANDLER(maclhwso, 0x0C, 0x1F), | |
10050 | GEN_MAC_HANDLER(maclhwu, 0x0C, 0x0C), | |
10051 | GEN_MAC_HANDLER(maclhwuo, 0x0C, 0x1C), | |
10052 | GEN_MAC_HANDLER(maclhwsu, 0x0C, 0x0E), | |
10053 | GEN_MAC_HANDLER(maclhwsuo, 0x0C, 0x1E), | |
10054 | GEN_MAC_HANDLER(nmacchw, 0x0E, 0x05), | |
10055 | GEN_MAC_HANDLER(nmacchwo, 0x0E, 0x15), | |
10056 | GEN_MAC_HANDLER(nmacchws, 0x0E, 0x07), | |
10057 | GEN_MAC_HANDLER(nmacchwso, 0x0E, 0x17), | |
10058 | GEN_MAC_HANDLER(nmachhw, 0x0E, 0x01), | |
10059 | GEN_MAC_HANDLER(nmachhwo, 0x0E, 0x11), | |
10060 | GEN_MAC_HANDLER(nmachhws, 0x0E, 0x03), | |
10061 | GEN_MAC_HANDLER(nmachhwso, 0x0E, 0x13), | |
10062 | GEN_MAC_HANDLER(nmaclhw, 0x0E, 0x0D), | |
10063 | GEN_MAC_HANDLER(nmaclhwo, 0x0E, 0x1D), | |
10064 | GEN_MAC_HANDLER(nmaclhws, 0x0E, 0x0F), | |
10065 | GEN_MAC_HANDLER(nmaclhwso, 0x0E, 0x1F), | |
10066 | GEN_MAC_HANDLER(mulchw, 0x08, 0x05), | |
10067 | GEN_MAC_HANDLER(mulchwu, 0x08, 0x04), | |
10068 | GEN_MAC_HANDLER(mulhhw, 0x08, 0x01), | |
10069 | GEN_MAC_HANDLER(mulhhwu, 0x08, 0x00), | |
10070 | GEN_MAC_HANDLER(mullhw, 0x08, 0x0D), | |
10071 | GEN_MAC_HANDLER(mullhwu, 0x08, 0x0C), | |
10072 | ||
10073 | #undef GEN_VR_LDX | |
10074 | #undef GEN_VR_STX | |
10075 | #undef GEN_VR_LVE | |
10076 | #undef GEN_VR_STVE | |
10077 | #define GEN_VR_LDX(name, opc2, opc3) \ | |
10078 | GEN_HANDLER(name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) | |
10079 | #define GEN_VR_STX(name, opc2, opc3) \ | |
10080 | GEN_HANDLER(st##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) | |
10081 | #define GEN_VR_LVE(name, opc2, opc3) \ | |
10082 | GEN_HANDLER(lve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) | |
10083 | #define GEN_VR_STVE(name, opc2, opc3) \ | |
10084 | GEN_HANDLER(stve##name, 0x1F, opc2, opc3, 0x00000001, PPC_ALTIVEC) | |
10085 | GEN_VR_LDX(lvx, 0x07, 0x03), | |
10086 | GEN_VR_LDX(lvxl, 0x07, 0x0B), | |
10087 | GEN_VR_LVE(bx, 0x07, 0x00), | |
10088 | GEN_VR_LVE(hx, 0x07, 0x01), | |
10089 | GEN_VR_LVE(wx, 0x07, 0x02), | |
10090 | GEN_VR_STX(svx, 0x07, 0x07), | |
10091 | GEN_VR_STX(svxl, 0x07, 0x0F), | |
10092 | GEN_VR_STVE(bx, 0x07, 0x04), | |
10093 | GEN_VR_STVE(hx, 0x07, 0x05), | |
10094 | GEN_VR_STVE(wx, 0x07, 0x06), | |
10095 | ||
10096 | #undef GEN_VX_LOGICAL | |
10097 | #define GEN_VX_LOGICAL(name, tcg_op, opc2, opc3) \ | |
10098 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) | |
10099 | GEN_VX_LOGICAL(vand, tcg_gen_and_i64, 2, 16), | |
10100 | GEN_VX_LOGICAL(vandc, tcg_gen_andc_i64, 2, 17), | |
10101 | GEN_VX_LOGICAL(vor, tcg_gen_or_i64, 2, 18), | |
10102 | GEN_VX_LOGICAL(vxor, tcg_gen_xor_i64, 2, 19), | |
10103 | GEN_VX_LOGICAL(vnor, tcg_gen_nor_i64, 2, 20), | |
10104 | ||
10105 | #undef GEN_VXFORM | |
10106 | #define GEN_VXFORM(name, opc2, opc3) \ | |
10107 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) | |
10108 | GEN_VXFORM(vaddubm, 0, 0), | |
10109 | GEN_VXFORM(vadduhm, 0, 1), | |
10110 | GEN_VXFORM(vadduwm, 0, 2), | |
10111 | GEN_VXFORM(vsububm, 0, 16), | |
10112 | GEN_VXFORM(vsubuhm, 0, 17), | |
10113 | GEN_VXFORM(vsubuwm, 0, 18), | |
10114 | GEN_VXFORM(vmaxub, 1, 0), | |
10115 | GEN_VXFORM(vmaxuh, 1, 1), | |
10116 | GEN_VXFORM(vmaxuw, 1, 2), | |
10117 | GEN_VXFORM(vmaxsb, 1, 4), | |
10118 | GEN_VXFORM(vmaxsh, 1, 5), | |
10119 | GEN_VXFORM(vmaxsw, 1, 6), | |
10120 | GEN_VXFORM(vminub, 1, 8), | |
10121 | GEN_VXFORM(vminuh, 1, 9), | |
10122 | GEN_VXFORM(vminuw, 1, 10), | |
10123 | GEN_VXFORM(vminsb, 1, 12), | |
10124 | GEN_VXFORM(vminsh, 1, 13), | |
10125 | GEN_VXFORM(vminsw, 1, 14), | |
10126 | GEN_VXFORM(vavgub, 1, 16), | |
10127 | GEN_VXFORM(vavguh, 1, 17), | |
10128 | GEN_VXFORM(vavguw, 1, 18), | |
10129 | GEN_VXFORM(vavgsb, 1, 20), | |
10130 | GEN_VXFORM(vavgsh, 1, 21), | |
10131 | GEN_VXFORM(vavgsw, 1, 22), | |
10132 | GEN_VXFORM(vmrghb, 6, 0), | |
10133 | GEN_VXFORM(vmrghh, 6, 1), | |
10134 | GEN_VXFORM(vmrghw, 6, 2), | |
10135 | GEN_VXFORM(vmrglb, 6, 4), | |
10136 | GEN_VXFORM(vmrglh, 6, 5), | |
10137 | GEN_VXFORM(vmrglw, 6, 6), | |
10138 | GEN_VXFORM(vmuloub, 4, 0), | |
10139 | GEN_VXFORM(vmulouh, 4, 1), | |
10140 | GEN_VXFORM(vmulosb, 4, 4), | |
10141 | GEN_VXFORM(vmulosh, 4, 5), | |
10142 | GEN_VXFORM(vmuleub, 4, 8), | |
10143 | GEN_VXFORM(vmuleuh, 4, 9), | |
10144 | GEN_VXFORM(vmulesb, 4, 12), | |
10145 | GEN_VXFORM(vmulesh, 4, 13), | |
10146 | GEN_VXFORM(vslb, 2, 4), | |
10147 | GEN_VXFORM(vslh, 2, 5), | |
10148 | GEN_VXFORM(vslw, 2, 6), | |
10149 | GEN_VXFORM(vsrb, 2, 8), | |
10150 | GEN_VXFORM(vsrh, 2, 9), | |
10151 | GEN_VXFORM(vsrw, 2, 10), | |
10152 | GEN_VXFORM(vsrab, 2, 12), | |
10153 | GEN_VXFORM(vsrah, 2, 13), | |
10154 | GEN_VXFORM(vsraw, 2, 14), | |
10155 | GEN_VXFORM(vslo, 6, 16), | |
10156 | GEN_VXFORM(vsro, 6, 17), | |
10157 | GEN_VXFORM(vaddcuw, 0, 6), | |
10158 | GEN_VXFORM(vsubcuw, 0, 22), | |
10159 | GEN_VXFORM(vaddubs, 0, 8), | |
10160 | GEN_VXFORM(vadduhs, 0, 9), | |
10161 | GEN_VXFORM(vadduws, 0, 10), | |
10162 | GEN_VXFORM(vaddsbs, 0, 12), | |
10163 | GEN_VXFORM(vaddshs, 0, 13), | |
10164 | GEN_VXFORM(vaddsws, 0, 14), | |
10165 | GEN_VXFORM(vsububs, 0, 24), | |
10166 | GEN_VXFORM(vsubuhs, 0, 25), | |
10167 | GEN_VXFORM(vsubuws, 0, 26), | |
10168 | GEN_VXFORM(vsubsbs, 0, 28), | |
10169 | GEN_VXFORM(vsubshs, 0, 29), | |
10170 | GEN_VXFORM(vsubsws, 0, 30), | |
10171 | GEN_VXFORM(vrlb, 2, 0), | |
10172 | GEN_VXFORM(vrlh, 2, 1), | |
10173 | GEN_VXFORM(vrlw, 2, 2), | |
10174 | GEN_VXFORM(vsl, 2, 7), | |
10175 | GEN_VXFORM(vsr, 2, 11), | |
10176 | GEN_VXFORM(vpkuhum, 7, 0), | |
10177 | GEN_VXFORM(vpkuwum, 7, 1), | |
10178 | GEN_VXFORM(vpkuhus, 7, 2), | |
10179 | GEN_VXFORM(vpkuwus, 7, 3), | |
10180 | GEN_VXFORM(vpkshus, 7, 4), | |
10181 | GEN_VXFORM(vpkswus, 7, 5), | |
10182 | GEN_VXFORM(vpkshss, 7, 6), | |
10183 | GEN_VXFORM(vpkswss, 7, 7), | |
10184 | GEN_VXFORM(vpkpx, 7, 12), | |
10185 | GEN_VXFORM(vsum4ubs, 4, 24), | |
10186 | GEN_VXFORM(vsum4sbs, 4, 28), | |
10187 | GEN_VXFORM(vsum4shs, 4, 25), | |
10188 | GEN_VXFORM(vsum2sws, 4, 26), | |
10189 | GEN_VXFORM(vsumsws, 4, 30), | |
10190 | GEN_VXFORM(vaddfp, 5, 0), | |
10191 | GEN_VXFORM(vsubfp, 5, 1), | |
10192 | GEN_VXFORM(vmaxfp, 5, 16), | |
10193 | GEN_VXFORM(vminfp, 5, 17), | |
10194 | ||
10195 | #undef GEN_VXRFORM1 | |
10196 | #undef GEN_VXRFORM | |
10197 | #define GEN_VXRFORM1(opname, name, str, opc2, opc3) \ | |
10198 | GEN_HANDLER2(name, str, 0x4, opc2, opc3, 0x00000000, PPC_ALTIVEC), | |
10199 | #define GEN_VXRFORM(name, opc2, opc3) \ | |
10200 | GEN_VXRFORM1(name, name, #name, opc2, opc3) \ | |
10201 | GEN_VXRFORM1(name##_dot, name##_, #name ".", opc2, (opc3 | (0x1 << 4))) | |
10202 | GEN_VXRFORM(vcmpequb, 3, 0) | |
10203 | GEN_VXRFORM(vcmpequh, 3, 1) | |
10204 | GEN_VXRFORM(vcmpequw, 3, 2) | |
10205 | GEN_VXRFORM(vcmpgtsb, 3, 12) | |
10206 | GEN_VXRFORM(vcmpgtsh, 3, 13) | |
10207 | GEN_VXRFORM(vcmpgtsw, 3, 14) | |
10208 | GEN_VXRFORM(vcmpgtub, 3, 8) | |
10209 | GEN_VXRFORM(vcmpgtuh, 3, 9) | |
10210 | GEN_VXRFORM(vcmpgtuw, 3, 10) | |
10211 | GEN_VXRFORM(vcmpeqfp, 3, 3) | |
10212 | GEN_VXRFORM(vcmpgefp, 3, 7) | |
10213 | GEN_VXRFORM(vcmpgtfp, 3, 11) | |
10214 | GEN_VXRFORM(vcmpbfp, 3, 15) | |
10215 | ||
10216 | #undef GEN_VXFORM_SIMM | |
10217 | #define GEN_VXFORM_SIMM(name, opc2, opc3) \ | |
10218 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) | |
10219 | GEN_VXFORM_SIMM(vspltisb, 6, 12), | |
10220 | GEN_VXFORM_SIMM(vspltish, 6, 13), | |
10221 | GEN_VXFORM_SIMM(vspltisw, 6, 14), | |
10222 | ||
10223 | #undef GEN_VXFORM_NOA | |
10224 | #define GEN_VXFORM_NOA(name, opc2, opc3) \ | |
10225 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x001f0000, PPC_ALTIVEC) | |
10226 | GEN_VXFORM_NOA(vupkhsb, 7, 8), | |
10227 | GEN_VXFORM_NOA(vupkhsh, 7, 9), | |
10228 | GEN_VXFORM_NOA(vupklsb, 7, 10), | |
10229 | GEN_VXFORM_NOA(vupklsh, 7, 11), | |
10230 | GEN_VXFORM_NOA(vupkhpx, 7, 13), | |
10231 | GEN_VXFORM_NOA(vupklpx, 7, 15), | |
10232 | GEN_VXFORM_NOA(vrefp, 5, 4), | |
10233 | GEN_VXFORM_NOA(vrsqrtefp, 5, 5), | |
0bffbc6c | 10234 | GEN_VXFORM_NOA(vexptefp, 5, 6), |
5c55ff99 BS |
10235 | GEN_VXFORM_NOA(vlogefp, 5, 7), |
10236 | GEN_VXFORM_NOA(vrfim, 5, 8), | |
10237 | GEN_VXFORM_NOA(vrfin, 5, 9), | |
10238 | GEN_VXFORM_NOA(vrfip, 5, 10), | |
10239 | GEN_VXFORM_NOA(vrfiz, 5, 11), | |
10240 | ||
10241 | #undef GEN_VXFORM_UIMM | |
10242 | #define GEN_VXFORM_UIMM(name, opc2, opc3) \ | |
10243 | GEN_HANDLER(name, 0x04, opc2, opc3, 0x00000000, PPC_ALTIVEC) | |
10244 | GEN_VXFORM_UIMM(vspltb, 6, 8), | |
10245 | GEN_VXFORM_UIMM(vsplth, 6, 9), | |
10246 | GEN_VXFORM_UIMM(vspltw, 6, 10), | |
10247 | GEN_VXFORM_UIMM(vcfux, 5, 12), | |
10248 | GEN_VXFORM_UIMM(vcfsx, 5, 13), | |
10249 | GEN_VXFORM_UIMM(vctuxs, 5, 14), | |
10250 | GEN_VXFORM_UIMM(vctsxs, 5, 15), | |
10251 | ||
10252 | #undef GEN_VAFORM_PAIRED | |
10253 | #define GEN_VAFORM_PAIRED(name0, name1, opc2) \ | |
10254 | GEN_HANDLER(name0##_##name1, 0x04, opc2, 0xFF, 0x00000000, PPC_ALTIVEC) | |
10255 | GEN_VAFORM_PAIRED(vmhaddshs, vmhraddshs, 16), | |
10256 | GEN_VAFORM_PAIRED(vmsumubm, vmsummbm, 18), | |
10257 | GEN_VAFORM_PAIRED(vmsumuhm, vmsumuhs, 19), | |
10258 | GEN_VAFORM_PAIRED(vmsumshm, vmsumshs, 20), | |
10259 | GEN_VAFORM_PAIRED(vsel, vperm, 21), | |
10260 | GEN_VAFORM_PAIRED(vmaddfp, vnmsubfp, 23), | |
10261 | ||
fa1832d7 | 10262 | GEN_HANDLER_E(lxsdx, 0x1F, 0x0C, 0x12, 0, PPC_NONE, PPC2_VSX), |
cac7f0ba TM |
10263 | GEN_HANDLER_E(lxsiwax, 0x1F, 0x0C, 0x02, 0, PPC_NONE, PPC2_VSX207), |
10264 | GEN_HANDLER_E(lxsiwzx, 0x1F, 0x0C, 0x00, 0, PPC_NONE, PPC2_VSX207), | |
10265 | GEN_HANDLER_E(lxsspx, 0x1F, 0x0C, 0x10, 0, PPC_NONE, PPC2_VSX207), | |
304af367 | 10266 | GEN_HANDLER_E(lxvd2x, 0x1F, 0x0C, 0x1A, 0, PPC_NONE, PPC2_VSX), |
ca03b467 | 10267 | GEN_HANDLER_E(lxvdsx, 0x1F, 0x0C, 0x0A, 0, PPC_NONE, PPC2_VSX), |
897e61d1 | 10268 | GEN_HANDLER_E(lxvw4x, 0x1F, 0x0C, 0x18, 0, PPC_NONE, PPC2_VSX), |
304af367 | 10269 | |
9231ba9e | 10270 | GEN_HANDLER_E(stxsdx, 0x1F, 0xC, 0x16, 0, PPC_NONE, PPC2_VSX), |
e16a626b TM |
10271 | GEN_HANDLER_E(stxsiwx, 0x1F, 0xC, 0x04, 0, PPC_NONE, PPC2_VSX207), |
10272 | GEN_HANDLER_E(stxsspx, 0x1F, 0xC, 0x14, 0, PPC_NONE, PPC2_VSX207), | |
fbed2478 | 10273 | GEN_HANDLER_E(stxvd2x, 0x1F, 0xC, 0x1E, 0, PPC_NONE, PPC2_VSX), |
86e61ce3 | 10274 | GEN_HANDLER_E(stxvw4x, 0x1F, 0xC, 0x1C, 0, PPC_NONE, PPC2_VSX), |
fbed2478 | 10275 | |
f5c0f7f9 TM |
10276 | GEN_HANDLER_E(mfvsrwz, 0x1F, 0x13, 0x03, 0x0000F800, PPC_NONE, PPC2_VSX207), |
10277 | GEN_HANDLER_E(mtvsrwa, 0x1F, 0x13, 0x06, 0x0000F800, PPC_NONE, PPC2_VSX207), | |
10278 | GEN_HANDLER_E(mtvsrwz, 0x1F, 0x13, 0x07, 0x0000F800, PPC_NONE, PPC2_VSX207), | |
10279 | #if defined(TARGET_PPC64) | |
10280 | GEN_HANDLER_E(mfvsrd, 0x1F, 0x13, 0x01, 0x0000F800, PPC_NONE, PPC2_VSX207), | |
10281 | GEN_HANDLER_E(mtvsrd, 0x1F, 0x13, 0x05, 0x0000F800, PPC_NONE, PPC2_VSX207), | |
10282 | #endif | |
10283 | ||
df020ce0 TM |
10284 | #undef GEN_XX2FORM |
10285 | #define GEN_XX2FORM(name, opc2, opc3, fl2) \ | |
10286 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \ | |
10287 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2) | |
10288 | ||
10289 | #undef GEN_XX3FORM | |
10290 | #define GEN_XX3FORM(name, opc2, opc3, fl2) \ | |
10291 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0, opc3, 0, PPC_NONE, fl2), \ | |
10292 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 1, opc3, 0, PPC_NONE, fl2), \ | |
10293 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 2, opc3, 0, PPC_NONE, fl2), \ | |
10294 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 3, opc3, 0, PPC_NONE, fl2) | |
10295 | ||
354a6dec TM |
10296 | #undef GEN_XX3_RC_FORM |
10297 | #define GEN_XX3_RC_FORM(name, opc2, opc3, fl2) \ | |
10298 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x00, 0, PPC_NONE, fl2), \ | |
10299 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x00, 0, PPC_NONE, fl2), \ | |
10300 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x00, 0, PPC_NONE, fl2), \ | |
10301 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x00, 0, PPC_NONE, fl2), \ | |
10302 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x00, opc3 | 0x10, 0, PPC_NONE, fl2), \ | |
10303 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x01, opc3 | 0x10, 0, PPC_NONE, fl2), \ | |
10304 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x02, opc3 | 0x10, 0, PPC_NONE, fl2), \ | |
10305 | GEN_HANDLER2_E(name, #name, 0x3C, opc2 | 0x03, opc3 | 0x10, 0, PPC_NONE, fl2) | |
10306 | ||
cd73f2c9 TM |
10307 | #undef GEN_XX3FORM_DM |
10308 | #define GEN_XX3FORM_DM(name, opc2, opc3) \ | |
10309 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\ | |
10310 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\ | |
10311 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\ | |
10312 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x00, 0, PPC_NONE, PPC2_VSX),\ | |
10313 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\ | |
10314 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\ | |
10315 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\ | |
10316 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x04, 0, PPC_NONE, PPC2_VSX),\ | |
10317 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\ | |
10318 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\ | |
10319 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\ | |
10320 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x08, 0, PPC_NONE, PPC2_VSX),\ | |
10321 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x00, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\ | |
10322 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x01, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\ | |
10323 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x02, opc3|0x0C, 0, PPC_NONE, PPC2_VSX),\ | |
10324 | GEN_HANDLER2_E(name, #name, 0x3C, opc2|0x03, opc3|0x0C, 0, PPC_NONE, PPC2_VSX) | |
10325 | ||
df020ce0 TM |
10326 | GEN_XX2FORM(xsabsdp, 0x12, 0x15, PPC2_VSX), |
10327 | GEN_XX2FORM(xsnabsdp, 0x12, 0x16, PPC2_VSX), | |
10328 | GEN_XX2FORM(xsnegdp, 0x12, 0x17, PPC2_VSX), | |
10329 | GEN_XX3FORM(xscpsgndp, 0x00, 0x16, PPC2_VSX), | |
10330 | ||
be574920 TM |
10331 | GEN_XX2FORM(xvabsdp, 0x12, 0x1D, PPC2_VSX), |
10332 | GEN_XX2FORM(xvnabsdp, 0x12, 0x1E, PPC2_VSX), | |
10333 | GEN_XX2FORM(xvnegdp, 0x12, 0x1F, PPC2_VSX), | |
10334 | GEN_XX3FORM(xvcpsgndp, 0x00, 0x1E, PPC2_VSX), | |
10335 | GEN_XX2FORM(xvabssp, 0x12, 0x19, PPC2_VSX), | |
10336 | GEN_XX2FORM(xvnabssp, 0x12, 0x1A, PPC2_VSX), | |
10337 | GEN_XX2FORM(xvnegsp, 0x12, 0x1B, PPC2_VSX), | |
10338 | GEN_XX3FORM(xvcpsgnsp, 0x00, 0x1A, PPC2_VSX), | |
79ca8a6a | 10339 | |
ee6e02c0 TM |
10340 | GEN_XX3FORM(xsadddp, 0x00, 0x04, PPC2_VSX), |
10341 | GEN_XX3FORM(xssubdp, 0x00, 0x05, PPC2_VSX), | |
5e591d88 | 10342 | GEN_XX3FORM(xsmuldp, 0x00, 0x06, PPC2_VSX), |
4b98eeef | 10343 | GEN_XX3FORM(xsdivdp, 0x00, 0x07, PPC2_VSX), |
2009227f | 10344 | GEN_XX2FORM(xsredp, 0x14, 0x05, PPC2_VSX), |
d32404fe | 10345 | GEN_XX2FORM(xssqrtdp, 0x16, 0x04, PPC2_VSX), |
d3f9df8f | 10346 | GEN_XX2FORM(xsrsqrtedp, 0x14, 0x04, PPC2_VSX), |
bc80838f | 10347 | GEN_XX3FORM(xstdivdp, 0x14, 0x07, PPC2_VSX), |
5cb151ac | 10348 | GEN_XX2FORM(xstsqrtdp, 0x14, 0x06, PPC2_VSX), |
595c6eef TM |
10349 | GEN_XX3FORM(xsmaddadp, 0x04, 0x04, PPC2_VSX), |
10350 | GEN_XX3FORM(xsmaddmdp, 0x04, 0x05, PPC2_VSX), | |
10351 | GEN_XX3FORM(xsmsubadp, 0x04, 0x06, PPC2_VSX), | |
10352 | GEN_XX3FORM(xsmsubmdp, 0x04, 0x07, PPC2_VSX), | |
10353 | GEN_XX3FORM(xsnmaddadp, 0x04, 0x14, PPC2_VSX), | |
10354 | GEN_XX3FORM(xsnmaddmdp, 0x04, 0x15, PPC2_VSX), | |
10355 | GEN_XX3FORM(xsnmsubadp, 0x04, 0x16, PPC2_VSX), | |
10356 | GEN_XX3FORM(xsnmsubmdp, 0x04, 0x17, PPC2_VSX), | |
4f17e9c7 TM |
10357 | GEN_XX2FORM(xscmpodp, 0x0C, 0x05, PPC2_VSX), |
10358 | GEN_XX2FORM(xscmpudp, 0x0C, 0x04, PPC2_VSX), | |
959e9c9d TM |
10359 | GEN_XX3FORM(xsmaxdp, 0x00, 0x14, PPC2_VSX), |
10360 | GEN_XX3FORM(xsmindp, 0x00, 0x15, PPC2_VSX), | |
ed8ac568 | 10361 | GEN_XX2FORM(xscvdpsp, 0x12, 0x10, PPC2_VSX), |
7ee19fb9 | 10362 | GEN_XX2FORM(xscvdpspn, 0x16, 0x10, PPC2_VSX207), |
ed8ac568 | 10363 | GEN_XX2FORM(xscvspdp, 0x12, 0x14, PPC2_VSX), |
7ee19fb9 | 10364 | GEN_XX2FORM(xscvspdpn, 0x16, 0x14, PPC2_VSX207), |
5177d2ca TM |
10365 | GEN_XX2FORM(xscvdpsxds, 0x10, 0x15, PPC2_VSX), |
10366 | GEN_XX2FORM(xscvdpsxws, 0x10, 0x05, PPC2_VSX), | |
10367 | GEN_XX2FORM(xscvdpuxds, 0x10, 0x14, PPC2_VSX), | |
10368 | GEN_XX2FORM(xscvdpuxws, 0x10, 0x04, PPC2_VSX), | |
10369 | GEN_XX2FORM(xscvsxddp, 0x10, 0x17, PPC2_VSX), | |
10370 | GEN_XX2FORM(xscvuxddp, 0x10, 0x16, PPC2_VSX), | |
88e33d08 TM |
10371 | GEN_XX2FORM(xsrdpi, 0x12, 0x04, PPC2_VSX), |
10372 | GEN_XX2FORM(xsrdpic, 0x16, 0x06, PPC2_VSX), | |
10373 | GEN_XX2FORM(xsrdpim, 0x12, 0x07, PPC2_VSX), | |
10374 | GEN_XX2FORM(xsrdpip, 0x12, 0x06, PPC2_VSX), | |
10375 | GEN_XX2FORM(xsrdpiz, 0x12, 0x05, PPC2_VSX), | |
ee6e02c0 | 10376 | |
3fd0aadf TM |
10377 | GEN_XX3FORM(xsaddsp, 0x00, 0x00, PPC2_VSX207), |
10378 | GEN_XX3FORM(xssubsp, 0x00, 0x01, PPC2_VSX207), | |
ab9408a2 | 10379 | GEN_XX3FORM(xsmulsp, 0x00, 0x02, PPC2_VSX207), |
b24d0b47 | 10380 | GEN_XX3FORM(xsdivsp, 0x00, 0x03, PPC2_VSX207), |
2c0c52ae | 10381 | GEN_XX2FORM(xsresp, 0x14, 0x01, PPC2_VSX207), |
3d1140bf | 10382 | GEN_XX2FORM(xsrsp, 0x12, 0x11, PPC2_VSX207), |
cea4e574 | 10383 | GEN_XX2FORM(xssqrtsp, 0x16, 0x00, PPC2_VSX207), |
968e76bc | 10384 | GEN_XX2FORM(xsrsqrtesp, 0x14, 0x00, PPC2_VSX207), |
f53f81e0 TM |
10385 | GEN_XX3FORM(xsmaddasp, 0x04, 0x00, PPC2_VSX207), |
10386 | GEN_XX3FORM(xsmaddmsp, 0x04, 0x01, PPC2_VSX207), | |
10387 | GEN_XX3FORM(xsmsubasp, 0x04, 0x02, PPC2_VSX207), | |
10388 | GEN_XX3FORM(xsmsubmsp, 0x04, 0x03, PPC2_VSX207), | |
10389 | GEN_XX3FORM(xsnmaddasp, 0x04, 0x10, PPC2_VSX207), | |
10390 | GEN_XX3FORM(xsnmaddmsp, 0x04, 0x11, PPC2_VSX207), | |
10391 | GEN_XX3FORM(xsnmsubasp, 0x04, 0x12, PPC2_VSX207), | |
10392 | GEN_XX3FORM(xsnmsubmsp, 0x04, 0x13, PPC2_VSX207), | |
74698350 TM |
10393 | GEN_XX2FORM(xscvsxdsp, 0x10, 0x13, PPC2_VSX207), |
10394 | GEN_XX2FORM(xscvuxdsp, 0x10, 0x12, PPC2_VSX207), | |
3fd0aadf | 10395 | |
ee6e02c0 TM |
10396 | GEN_XX3FORM(xvadddp, 0x00, 0x0C, PPC2_VSX), |
10397 | GEN_XX3FORM(xvsubdp, 0x00, 0x0D, PPC2_VSX), | |
5e591d88 | 10398 | GEN_XX3FORM(xvmuldp, 0x00, 0x0E, PPC2_VSX), |
4b98eeef | 10399 | GEN_XX3FORM(xvdivdp, 0x00, 0x0F, PPC2_VSX), |
2009227f | 10400 | GEN_XX2FORM(xvredp, 0x14, 0x0D, PPC2_VSX), |
d32404fe | 10401 | GEN_XX2FORM(xvsqrtdp, 0x16, 0x0C, PPC2_VSX), |
d3f9df8f | 10402 | GEN_XX2FORM(xvrsqrtedp, 0x14, 0x0C, PPC2_VSX), |
bc80838f | 10403 | GEN_XX3FORM(xvtdivdp, 0x14, 0x0F, PPC2_VSX), |
5cb151ac | 10404 | GEN_XX2FORM(xvtsqrtdp, 0x14, 0x0E, PPC2_VSX), |
595c6eef TM |
10405 | GEN_XX3FORM(xvmaddadp, 0x04, 0x0C, PPC2_VSX), |
10406 | GEN_XX3FORM(xvmaddmdp, 0x04, 0x0D, PPC2_VSX), | |
10407 | GEN_XX3FORM(xvmsubadp, 0x04, 0x0E, PPC2_VSX), | |
10408 | GEN_XX3FORM(xvmsubmdp, 0x04, 0x0F, PPC2_VSX), | |
10409 | GEN_XX3FORM(xvnmaddadp, 0x04, 0x1C, PPC2_VSX), | |
10410 | GEN_XX3FORM(xvnmaddmdp, 0x04, 0x1D, PPC2_VSX), | |
10411 | GEN_XX3FORM(xvnmsubadp, 0x04, 0x1E, PPC2_VSX), | |
10412 | GEN_XX3FORM(xvnmsubmdp, 0x04, 0x1F, PPC2_VSX), | |
959e9c9d TM |
10413 | GEN_XX3FORM(xvmaxdp, 0x00, 0x1C, PPC2_VSX), |
10414 | GEN_XX3FORM(xvmindp, 0x00, 0x1D, PPC2_VSX), | |
354a6dec TM |
10415 | GEN_XX3_RC_FORM(xvcmpeqdp, 0x0C, 0x0C, PPC2_VSX), |
10416 | GEN_XX3_RC_FORM(xvcmpgtdp, 0x0C, 0x0D, PPC2_VSX), | |
10417 | GEN_XX3_RC_FORM(xvcmpgedp, 0x0C, 0x0E, PPC2_VSX), | |
ed8ac568 | 10418 | GEN_XX2FORM(xvcvdpsp, 0x12, 0x18, PPC2_VSX), |
5177d2ca TM |
10419 | GEN_XX2FORM(xvcvdpsxds, 0x10, 0x1D, PPC2_VSX), |
10420 | GEN_XX2FORM(xvcvdpsxws, 0x10, 0x0D, PPC2_VSX), | |
10421 | GEN_XX2FORM(xvcvdpuxds, 0x10, 0x1C, PPC2_VSX), | |
10422 | GEN_XX2FORM(xvcvdpuxws, 0x10, 0x0C, PPC2_VSX), | |
10423 | GEN_XX2FORM(xvcvsxddp, 0x10, 0x1F, PPC2_VSX), | |
10424 | GEN_XX2FORM(xvcvuxddp, 0x10, 0x1E, PPC2_VSX), | |
10425 | GEN_XX2FORM(xvcvsxwdp, 0x10, 0x0F, PPC2_VSX), | |
10426 | GEN_XX2FORM(xvcvuxwdp, 0x10, 0x0E, PPC2_VSX), | |
88e33d08 TM |
10427 | GEN_XX2FORM(xvrdpi, 0x12, 0x0C, PPC2_VSX), |
10428 | GEN_XX2FORM(xvrdpic, 0x16, 0x0E, PPC2_VSX), | |
10429 | GEN_XX2FORM(xvrdpim, 0x12, 0x0F, PPC2_VSX), | |
10430 | GEN_XX2FORM(xvrdpip, 0x12, 0x0E, PPC2_VSX), | |
10431 | GEN_XX2FORM(xvrdpiz, 0x12, 0x0D, PPC2_VSX), | |
ee6e02c0 TM |
10432 | |
10433 | GEN_XX3FORM(xvaddsp, 0x00, 0x08, PPC2_VSX), | |
10434 | GEN_XX3FORM(xvsubsp, 0x00, 0x09, PPC2_VSX), | |
5e591d88 | 10435 | GEN_XX3FORM(xvmulsp, 0x00, 0x0A, PPC2_VSX), |
4b98eeef | 10436 | GEN_XX3FORM(xvdivsp, 0x00, 0x0B, PPC2_VSX), |
2009227f | 10437 | GEN_XX2FORM(xvresp, 0x14, 0x09, PPC2_VSX), |
d32404fe | 10438 | GEN_XX2FORM(xvsqrtsp, 0x16, 0x08, PPC2_VSX), |
d3f9df8f | 10439 | GEN_XX2FORM(xvrsqrtesp, 0x14, 0x08, PPC2_VSX), |
bc80838f | 10440 | GEN_XX3FORM(xvtdivsp, 0x14, 0x0B, PPC2_VSX), |
5cb151ac | 10441 | GEN_XX2FORM(xvtsqrtsp, 0x14, 0x0A, PPC2_VSX), |
595c6eef TM |
10442 | GEN_XX3FORM(xvmaddasp, 0x04, 0x08, PPC2_VSX), |
10443 | GEN_XX3FORM(xvmaddmsp, 0x04, 0x09, PPC2_VSX), | |
10444 | GEN_XX3FORM(xvmsubasp, 0x04, 0x0A, PPC2_VSX), | |
10445 | GEN_XX3FORM(xvmsubmsp, 0x04, 0x0B, PPC2_VSX), | |
10446 | GEN_XX3FORM(xvnmaddasp, 0x04, 0x18, PPC2_VSX), | |
10447 | GEN_XX3FORM(xvnmaddmsp, 0x04, 0x19, PPC2_VSX), | |
10448 | GEN_XX3FORM(xvnmsubasp, 0x04, 0x1A, PPC2_VSX), | |
10449 | GEN_XX3FORM(xvnmsubmsp, 0x04, 0x1B, PPC2_VSX), | |
959e9c9d TM |
10450 | GEN_XX3FORM(xvmaxsp, 0x00, 0x18, PPC2_VSX), |
10451 | GEN_XX3FORM(xvminsp, 0x00, 0x19, PPC2_VSX), | |
354a6dec TM |
10452 | GEN_XX3_RC_FORM(xvcmpeqsp, 0x0C, 0x08, PPC2_VSX), |
10453 | GEN_XX3_RC_FORM(xvcmpgtsp, 0x0C, 0x09, PPC2_VSX), | |
10454 | GEN_XX3_RC_FORM(xvcmpgesp, 0x0C, 0x0A, PPC2_VSX), | |
ed8ac568 | 10455 | GEN_XX2FORM(xvcvspdp, 0x12, 0x1C, PPC2_VSX), |
5177d2ca TM |
10456 | GEN_XX2FORM(xvcvspsxds, 0x10, 0x19, PPC2_VSX), |
10457 | GEN_XX2FORM(xvcvspsxws, 0x10, 0x09, PPC2_VSX), | |
10458 | GEN_XX2FORM(xvcvspuxds, 0x10, 0x18, PPC2_VSX), | |
10459 | GEN_XX2FORM(xvcvspuxws, 0x10, 0x08, PPC2_VSX), | |
10460 | GEN_XX2FORM(xvcvsxdsp, 0x10, 0x1B, PPC2_VSX), | |
10461 | GEN_XX2FORM(xvcvuxdsp, 0x10, 0x1A, PPC2_VSX), | |
10462 | GEN_XX2FORM(xvcvsxwsp, 0x10, 0x0B, PPC2_VSX), | |
10463 | GEN_XX2FORM(xvcvuxwsp, 0x10, 0x0A, PPC2_VSX), | |
88e33d08 TM |
10464 | GEN_XX2FORM(xvrspi, 0x12, 0x08, PPC2_VSX), |
10465 | GEN_XX2FORM(xvrspic, 0x16, 0x0A, PPC2_VSX), | |
10466 | GEN_XX2FORM(xvrspim, 0x12, 0x0B, PPC2_VSX), | |
10467 | GEN_XX2FORM(xvrspip, 0x12, 0x0A, PPC2_VSX), | |
10468 | GEN_XX2FORM(xvrspiz, 0x12, 0x09, PPC2_VSX), | |
ee6e02c0 | 10469 | |
79ca8a6a TM |
10470 | #undef VSX_LOGICAL |
10471 | #define VSX_LOGICAL(name, opc2, opc3, fl2) \ | |
10472 | GEN_XX3FORM(name, opc2, opc3, fl2) | |
10473 | ||
10474 | VSX_LOGICAL(xxland, 0x8, 0x10, PPC2_VSX), | |
10475 | VSX_LOGICAL(xxlandc, 0x8, 0x11, PPC2_VSX), | |
10476 | VSX_LOGICAL(xxlor, 0x8, 0x12, PPC2_VSX), | |
10477 | VSX_LOGICAL(xxlxor, 0x8, 0x13, PPC2_VSX), | |
10478 | VSX_LOGICAL(xxlnor, 0x8, 0x14, PPC2_VSX), | |
67a33f37 TM |
10479 | VSX_LOGICAL(xxleqv, 0x8, 0x17, PPC2_VSX207), |
10480 | VSX_LOGICAL(xxlnand, 0x8, 0x16, PPC2_VSX207), | |
10481 | VSX_LOGICAL(xxlorc, 0x8, 0x15, PPC2_VSX207), | |
ce577d2e TM |
10482 | GEN_XX3FORM(xxmrghw, 0x08, 0x02, PPC2_VSX), |
10483 | GEN_XX3FORM(xxmrglw, 0x08, 0x06, PPC2_VSX), | |
76c15fe0 | 10484 | GEN_XX2FORM(xxspltw, 0x08, 0x0A, PPC2_VSX), |
acc42968 | 10485 | GEN_XX3FORM_DM(xxsldwi, 0x08, 0x00), |
79ca8a6a | 10486 | |
551e3ef7 TM |
10487 | #define GEN_XXSEL_ROW(opc3) \ |
10488 | GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x18, opc3, 0, PPC_NONE, PPC2_VSX), \ | |
10489 | GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x19, opc3, 0, PPC_NONE, PPC2_VSX), \ | |
10490 | GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1A, opc3, 0, PPC_NONE, PPC2_VSX), \ | |
10491 | GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1B, opc3, 0, PPC_NONE, PPC2_VSX), \ | |
10492 | GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1C, opc3, 0, PPC_NONE, PPC2_VSX), \ | |
10493 | GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1D, opc3, 0, PPC_NONE, PPC2_VSX), \ | |
10494 | GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1E, opc3, 0, PPC_NONE, PPC2_VSX), \ | |
10495 | GEN_HANDLER2_E(xxsel, "xxsel", 0x3C, 0x1F, opc3, 0, PPC_NONE, PPC2_VSX), \ | |
10496 | ||
10497 | GEN_XXSEL_ROW(0x00) | |
10498 | GEN_XXSEL_ROW(0x01) | |
10499 | GEN_XXSEL_ROW(0x02) | |
10500 | GEN_XXSEL_ROW(0x03) | |
10501 | GEN_XXSEL_ROW(0x04) | |
10502 | GEN_XXSEL_ROW(0x05) | |
10503 | GEN_XXSEL_ROW(0x06) | |
10504 | GEN_XXSEL_ROW(0x07) | |
10505 | GEN_XXSEL_ROW(0x08) | |
10506 | GEN_XXSEL_ROW(0x09) | |
10507 | GEN_XXSEL_ROW(0x0A) | |
10508 | GEN_XXSEL_ROW(0x0B) | |
10509 | GEN_XXSEL_ROW(0x0C) | |
10510 | GEN_XXSEL_ROW(0x0D) | |
10511 | GEN_XXSEL_ROW(0x0E) | |
10512 | GEN_XXSEL_ROW(0x0F) | |
10513 | GEN_XXSEL_ROW(0x10) | |
10514 | GEN_XXSEL_ROW(0x11) | |
10515 | GEN_XXSEL_ROW(0x12) | |
10516 | GEN_XXSEL_ROW(0x13) | |
10517 | GEN_XXSEL_ROW(0x14) | |
10518 | GEN_XXSEL_ROW(0x15) | |
10519 | GEN_XXSEL_ROW(0x16) | |
10520 | GEN_XXSEL_ROW(0x17) | |
10521 | GEN_XXSEL_ROW(0x18) | |
10522 | GEN_XXSEL_ROW(0x19) | |
10523 | GEN_XXSEL_ROW(0x1A) | |
10524 | GEN_XXSEL_ROW(0x1B) | |
10525 | GEN_XXSEL_ROW(0x1C) | |
10526 | GEN_XXSEL_ROW(0x1D) | |
10527 | GEN_XXSEL_ROW(0x1E) | |
10528 | GEN_XXSEL_ROW(0x1F) | |
10529 | ||
cd73f2c9 TM |
10530 | GEN_XX3FORM_DM(xxpermdi, 0x08, 0x01), |
10531 | ||
5c55ff99 | 10532 | #undef GEN_SPE |
70560da7 FC |
10533 | #define GEN_SPE(name0, name1, opc2, opc3, inval0, inval1, type) \ |
10534 | GEN_OPCODE_DUAL(name0##_##name1, 0x04, opc2, opc3, inval0, inval1, type, PPC_NONE) | |
10535 | GEN_SPE(evaddw, speundef, 0x00, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
10536 | GEN_SPE(evaddiw, speundef, 0x01, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
10537 | GEN_SPE(evsubfw, speundef, 0x02, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
10538 | GEN_SPE(evsubifw, speundef, 0x03, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
10539 | GEN_SPE(evabs, evneg, 0x04, 0x08, 0x0000F800, 0x0000F800, PPC_SPE), | |
10540 | GEN_SPE(evextsb, evextsh, 0x05, 0x08, 0x0000F800, 0x0000F800, PPC_SPE), | |
10541 | GEN_SPE(evrndw, evcntlzw, 0x06, 0x08, 0x0000F800, 0x0000F800, PPC_SPE), | |
10542 | GEN_SPE(evcntlsw, brinc, 0x07, 0x08, 0x0000F800, 0x00000000, PPC_SPE), | |
10543 | GEN_SPE(evmra, speundef, 0x02, 0x13, 0x0000F800, 0xFFFFFFFF, PPC_SPE), | |
10544 | GEN_SPE(speundef, evand, 0x08, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE), | |
10545 | GEN_SPE(evandc, speundef, 0x09, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
10546 | GEN_SPE(evxor, evor, 0x0B, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
10547 | GEN_SPE(evnor, eveqv, 0x0C, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
10548 | GEN_SPE(evmwumi, evmwsmi, 0x0C, 0x11, 0x00000000, 0x00000000, PPC_SPE), | |
10549 | GEN_SPE(evmwumia, evmwsmia, 0x1C, 0x11, 0x00000000, 0x00000000, PPC_SPE), | |
10550 | GEN_SPE(evmwumiaa, evmwsmiaa, 0x0C, 0x15, 0x00000000, 0x00000000, PPC_SPE), | |
10551 | GEN_SPE(speundef, evorc, 0x0D, 0x08, 0xFFFFFFFF, 0x00000000, PPC_SPE), | |
10552 | GEN_SPE(evnand, speundef, 0x0F, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
10553 | GEN_SPE(evsrwu, evsrws, 0x10, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
10554 | GEN_SPE(evsrwiu, evsrwis, 0x11, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
10555 | GEN_SPE(evslw, speundef, 0x12, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
10556 | GEN_SPE(evslwi, speundef, 0x13, 0x08, 0x00000000, 0xFFFFFFFF, PPC_SPE), | |
10557 | GEN_SPE(evrlw, evsplati, 0x14, 0x08, 0x00000000, 0x0000F800, PPC_SPE), | |
10558 | GEN_SPE(evrlwi, evsplatfi, 0x15, 0x08, 0x00000000, 0x0000F800, PPC_SPE), | |
10559 | GEN_SPE(evmergehi, evmergelo, 0x16, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
10560 | GEN_SPE(evmergehilo, evmergelohi, 0x17, 0x08, 0x00000000, 0x00000000, PPC_SPE), | |
10561 | GEN_SPE(evcmpgtu, evcmpgts, 0x18, 0x08, 0x00600000, 0x00600000, PPC_SPE), | |
10562 | GEN_SPE(evcmpltu, evcmplts, 0x19, 0x08, 0x00600000, 0x00600000, PPC_SPE), | |
10563 | GEN_SPE(evcmpeq, speundef, 0x1A, 0x08, 0x00600000, 0xFFFFFFFF, PPC_SPE), | |
10564 | ||
10565 | GEN_SPE(evfsadd, evfssub, 0x00, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE), | |
10566 | GEN_SPE(evfsabs, evfsnabs, 0x02, 0x0A, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE), | |
10567 | GEN_SPE(evfsneg, speundef, 0x03, 0x0A, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
10568 | GEN_SPE(evfsmul, evfsdiv, 0x04, 0x0A, 0x00000000, 0x00000000, PPC_SPE_SINGLE), | |
10569 | GEN_SPE(evfscmpgt, evfscmplt, 0x06, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE), | |
10570 | GEN_SPE(evfscmpeq, speundef, 0x07, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
10571 | GEN_SPE(evfscfui, evfscfsi, 0x08, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
10572 | GEN_SPE(evfscfuf, evfscfsf, 0x09, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
10573 | GEN_SPE(evfsctui, evfsctsi, 0x0A, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
10574 | GEN_SPE(evfsctuf, evfsctsf, 0x0B, 0x0A, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
10575 | GEN_SPE(evfsctuiz, speundef, 0x0C, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
10576 | GEN_SPE(evfsctsiz, speundef, 0x0D, 0x0A, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
10577 | GEN_SPE(evfststgt, evfststlt, 0x0E, 0x0A, 0x00600000, 0x00600000, PPC_SPE_SINGLE), | |
10578 | GEN_SPE(evfststeq, speundef, 0x0F, 0x0A, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
10579 | ||
10580 | GEN_SPE(efsadd, efssub, 0x00, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE), | |
10581 | GEN_SPE(efsabs, efsnabs, 0x02, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_SINGLE), | |
10582 | GEN_SPE(efsneg, speundef, 0x03, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
10583 | GEN_SPE(efsmul, efsdiv, 0x04, 0x0B, 0x00000000, 0x00000000, PPC_SPE_SINGLE), | |
10584 | GEN_SPE(efscmpgt, efscmplt, 0x06, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE), | |
10585 | GEN_SPE(efscmpeq, efscfd, 0x07, 0x0B, 0x00600000, 0x00180000, PPC_SPE_SINGLE), | |
10586 | GEN_SPE(efscfui, efscfsi, 0x08, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
10587 | GEN_SPE(efscfuf, efscfsf, 0x09, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
10588 | GEN_SPE(efsctui, efsctsi, 0x0A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
10589 | GEN_SPE(efsctuf, efsctsf, 0x0B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_SINGLE), | |
10590 | GEN_SPE(efsctuiz, speundef, 0x0C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
10591 | GEN_SPE(efsctsiz, speundef, 0x0D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
10592 | GEN_SPE(efststgt, efststlt, 0x0E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_SINGLE), | |
10593 | GEN_SPE(efststeq, speundef, 0x0F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_SINGLE), | |
10594 | ||
10595 | GEN_SPE(efdadd, efdsub, 0x10, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE), | |
10596 | GEN_SPE(efdcfuid, efdcfsid, 0x11, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
10597 | GEN_SPE(efdabs, efdnabs, 0x12, 0x0B, 0x0000F800, 0x0000F800, PPC_SPE_DOUBLE), | |
10598 | GEN_SPE(efdneg, speundef, 0x13, 0x0B, 0x0000F800, 0xFFFFFFFF, PPC_SPE_DOUBLE), | |
10599 | GEN_SPE(efdmul, efddiv, 0x14, 0x0B, 0x00000000, 0x00000000, PPC_SPE_DOUBLE), | |
10600 | GEN_SPE(efdctuidz, efdctsidz, 0x15, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
10601 | GEN_SPE(efdcmpgt, efdcmplt, 0x16, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE), | |
10602 | GEN_SPE(efdcmpeq, efdcfs, 0x17, 0x0B, 0x00600000, 0x00180000, PPC_SPE_DOUBLE), | |
10603 | GEN_SPE(efdcfui, efdcfsi, 0x18, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
10604 | GEN_SPE(efdcfuf, efdcfsf, 0x19, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
10605 | GEN_SPE(efdctui, efdctsi, 0x1A, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
10606 | GEN_SPE(efdctuf, efdctsf, 0x1B, 0x0B, 0x00180000, 0x00180000, PPC_SPE_DOUBLE), | |
10607 | GEN_SPE(efdctuiz, speundef, 0x1C, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE), | |
10608 | GEN_SPE(efdctsiz, speundef, 0x1D, 0x0B, 0x00180000, 0xFFFFFFFF, PPC_SPE_DOUBLE), | |
10609 | GEN_SPE(efdtstgt, efdtstlt, 0x1E, 0x0B, 0x00600000, 0x00600000, PPC_SPE_DOUBLE), | |
10610 | GEN_SPE(efdtsteq, speundef, 0x1F, 0x0B, 0x00600000, 0xFFFFFFFF, PPC_SPE_DOUBLE), | |
5c55ff99 BS |
10611 | |
10612 | #undef GEN_SPEOP_LDST | |
10613 | #define GEN_SPEOP_LDST(name, opc2, sh) \ | |
10614 | GEN_HANDLER(name, 0x04, opc2, 0x0C, 0x00000000, PPC_SPE) | |
10615 | GEN_SPEOP_LDST(evldd, 0x00, 3), | |
10616 | GEN_SPEOP_LDST(evldw, 0x01, 3), | |
10617 | GEN_SPEOP_LDST(evldh, 0x02, 3), | |
10618 | GEN_SPEOP_LDST(evlhhesplat, 0x04, 1), | |
10619 | GEN_SPEOP_LDST(evlhhousplat, 0x06, 1), | |
10620 | GEN_SPEOP_LDST(evlhhossplat, 0x07, 1), | |
10621 | GEN_SPEOP_LDST(evlwhe, 0x08, 2), | |
10622 | GEN_SPEOP_LDST(evlwhou, 0x0A, 2), | |
10623 | GEN_SPEOP_LDST(evlwhos, 0x0B, 2), | |
10624 | GEN_SPEOP_LDST(evlwwsplat, 0x0C, 2), | |
10625 | GEN_SPEOP_LDST(evlwhsplat, 0x0E, 2), | |
10626 | ||
10627 | GEN_SPEOP_LDST(evstdd, 0x10, 3), | |
10628 | GEN_SPEOP_LDST(evstdw, 0x11, 3), | |
10629 | GEN_SPEOP_LDST(evstdh, 0x12, 3), | |
10630 | GEN_SPEOP_LDST(evstwhe, 0x18, 2), | |
10631 | GEN_SPEOP_LDST(evstwho, 0x1A, 2), | |
10632 | GEN_SPEOP_LDST(evstwwe, 0x1C, 2), | |
10633 | GEN_SPEOP_LDST(evstwwo, 0x1E, 2), | |
10634 | }; | |
10635 | ||
0411a972 | 10636 | #include "helper_regs.h" |
a1389542 | 10637 | #include "translate_init.c" |
79aceca5 | 10638 | |
9a64fbe4 | 10639 | /*****************************************************************************/ |
3fc6c082 | 10640 | /* Misc PowerPC helpers */ |
878096ee AF |
10641 | void ppc_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf, |
10642 | int flags) | |
79aceca5 | 10643 | { |
3fc6c082 FB |
10644 | #define RGPL 4 |
10645 | #define RFPL 4 | |
3fc6c082 | 10646 | |
878096ee AF |
10647 | PowerPCCPU *cpu = POWERPC_CPU(cs); |
10648 | CPUPPCState *env = &cpu->env; | |
79aceca5 FB |
10649 | int i; |
10650 | ||
90e189ec | 10651 | cpu_fprintf(f, "NIP " TARGET_FMT_lx " LR " TARGET_FMT_lx " CTR " |
9a78eead | 10652 | TARGET_FMT_lx " XER " TARGET_FMT_lx "\n", |
da91a00f | 10653 | env->nip, env->lr, env->ctr, cpu_read_xer(env)); |
90e189ec BS |
10654 | cpu_fprintf(f, "MSR " TARGET_FMT_lx " HID0 " TARGET_FMT_lx " HF " |
10655 | TARGET_FMT_lx " idx %d\n", env->msr, env->spr[SPR_HID0], | |
10656 | env->hflags, env->mmu_idx); | |
d9bce9d9 | 10657 | #if !defined(NO_TIMER_DUMP) |
9a78eead | 10658 | cpu_fprintf(f, "TB %08" PRIu32 " %08" PRIu64 |
76a66253 | 10659 | #if !defined(CONFIG_USER_ONLY) |
9a78eead | 10660 | " DECR %08" PRIu32 |
76a66253 JM |
10661 | #endif |
10662 | "\n", | |
077fc206 | 10663 | cpu_ppc_load_tbu(env), cpu_ppc_load_tbl(env) |
76a66253 JM |
10664 | #if !defined(CONFIG_USER_ONLY) |
10665 | , cpu_ppc_load_decr(env) | |
10666 | #endif | |
10667 | ); | |
077fc206 | 10668 | #endif |
76a66253 | 10669 | for (i = 0; i < 32; i++) { |
3fc6c082 FB |
10670 | if ((i & (RGPL - 1)) == 0) |
10671 | cpu_fprintf(f, "GPR%02d", i); | |
b11ebf64 | 10672 | cpu_fprintf(f, " %016" PRIx64, ppc_dump_gpr(env, i)); |
3fc6c082 | 10673 | if ((i & (RGPL - 1)) == (RGPL - 1)) |
7fe48483 | 10674 | cpu_fprintf(f, "\n"); |
76a66253 | 10675 | } |
3fc6c082 | 10676 | cpu_fprintf(f, "CR "); |
76a66253 | 10677 | for (i = 0; i < 8; i++) |
7fe48483 FB |
10678 | cpu_fprintf(f, "%01x", env->crf[i]); |
10679 | cpu_fprintf(f, " ["); | |
76a66253 JM |
10680 | for (i = 0; i < 8; i++) { |
10681 | char a = '-'; | |
10682 | if (env->crf[i] & 0x08) | |
10683 | a = 'L'; | |
10684 | else if (env->crf[i] & 0x04) | |
10685 | a = 'G'; | |
10686 | else if (env->crf[i] & 0x02) | |
10687 | a = 'E'; | |
7fe48483 | 10688 | cpu_fprintf(f, " %c%c", a, env->crf[i] & 0x01 ? 'O' : ' '); |
76a66253 | 10689 | } |
90e189ec BS |
10690 | cpu_fprintf(f, " ] RES " TARGET_FMT_lx "\n", |
10691 | env->reserve_addr); | |
3fc6c082 FB |
10692 | for (i = 0; i < 32; i++) { |
10693 | if ((i & (RFPL - 1)) == 0) | |
10694 | cpu_fprintf(f, "FPR%02d", i); | |
26a76461 | 10695 | cpu_fprintf(f, " %016" PRIx64, *((uint64_t *)&env->fpr[i])); |
3fc6c082 | 10696 | if ((i & (RFPL - 1)) == (RFPL - 1)) |
7fe48483 | 10697 | cpu_fprintf(f, "\n"); |
79aceca5 | 10698 | } |
30304420 | 10699 | cpu_fprintf(f, "FPSCR " TARGET_FMT_lx "\n", env->fpscr); |
f2e63a42 | 10700 | #if !defined(CONFIG_USER_ONLY) |
90dc8812 SW |
10701 | cpu_fprintf(f, " SRR0 " TARGET_FMT_lx " SRR1 " TARGET_FMT_lx |
10702 | " PVR " TARGET_FMT_lx " VRSAVE " TARGET_FMT_lx "\n", | |
10703 | env->spr[SPR_SRR0], env->spr[SPR_SRR1], | |
10704 | env->spr[SPR_PVR], env->spr[SPR_VRSAVE]); | |
10705 | ||
10706 | cpu_fprintf(f, "SPRG0 " TARGET_FMT_lx " SPRG1 " TARGET_FMT_lx | |
10707 | " SPRG2 " TARGET_FMT_lx " SPRG3 " TARGET_FMT_lx "\n", | |
10708 | env->spr[SPR_SPRG0], env->spr[SPR_SPRG1], | |
10709 | env->spr[SPR_SPRG2], env->spr[SPR_SPRG3]); | |
10710 | ||
10711 | cpu_fprintf(f, "SPRG4 " TARGET_FMT_lx " SPRG5 " TARGET_FMT_lx | |
10712 | " SPRG6 " TARGET_FMT_lx " SPRG7 " TARGET_FMT_lx "\n", | |
10713 | env->spr[SPR_SPRG4], env->spr[SPR_SPRG5], | |
10714 | env->spr[SPR_SPRG6], env->spr[SPR_SPRG7]); | |
10715 | ||
10716 | if (env->excp_model == POWERPC_EXCP_BOOKE) { | |
10717 | cpu_fprintf(f, "CSRR0 " TARGET_FMT_lx " CSRR1 " TARGET_FMT_lx | |
10718 | " MCSRR0 " TARGET_FMT_lx " MCSRR1 " TARGET_FMT_lx "\n", | |
10719 | env->spr[SPR_BOOKE_CSRR0], env->spr[SPR_BOOKE_CSRR1], | |
10720 | env->spr[SPR_BOOKE_MCSRR0], env->spr[SPR_BOOKE_MCSRR1]); | |
10721 | ||
10722 | cpu_fprintf(f, " TCR " TARGET_FMT_lx " TSR " TARGET_FMT_lx | |
10723 | " ESR " TARGET_FMT_lx " DEAR " TARGET_FMT_lx "\n", | |
10724 | env->spr[SPR_BOOKE_TCR], env->spr[SPR_BOOKE_TSR], | |
10725 | env->spr[SPR_BOOKE_ESR], env->spr[SPR_BOOKE_DEAR]); | |
10726 | ||
10727 | cpu_fprintf(f, " PIR " TARGET_FMT_lx " DECAR " TARGET_FMT_lx | |
10728 | " IVPR " TARGET_FMT_lx " EPCR " TARGET_FMT_lx "\n", | |
10729 | env->spr[SPR_BOOKE_PIR], env->spr[SPR_BOOKE_DECAR], | |
10730 | env->spr[SPR_BOOKE_IVPR], env->spr[SPR_BOOKE_EPCR]); | |
10731 | ||
10732 | cpu_fprintf(f, " MCSR " TARGET_FMT_lx " SPRG8 " TARGET_FMT_lx | |
10733 | " EPR " TARGET_FMT_lx "\n", | |
10734 | env->spr[SPR_BOOKE_MCSR], env->spr[SPR_BOOKE_SPRG8], | |
10735 | env->spr[SPR_BOOKE_EPR]); | |
10736 | ||
10737 | /* FSL-specific */ | |
10738 | cpu_fprintf(f, " MCAR " TARGET_FMT_lx " PID1 " TARGET_FMT_lx | |
10739 | " PID2 " TARGET_FMT_lx " SVR " TARGET_FMT_lx "\n", | |
10740 | env->spr[SPR_Exxx_MCAR], env->spr[SPR_BOOKE_PID1], | |
10741 | env->spr[SPR_BOOKE_PID2], env->spr[SPR_E500_SVR]); | |
10742 | ||
10743 | /* | |
10744 | * IVORs are left out as they are large and do not change often -- | |
10745 | * they can be read with "p $ivor0", "p $ivor1", etc. | |
10746 | */ | |
10747 | } | |
10748 | ||
697ab892 DG |
10749 | #if defined(TARGET_PPC64) |
10750 | if (env->flags & POWERPC_FLAG_CFAR) { | |
10751 | cpu_fprintf(f, " CFAR " TARGET_FMT_lx"\n", env->cfar); | |
10752 | } | |
10753 | #endif | |
10754 | ||
90dc8812 SW |
10755 | switch (env->mmu_model) { |
10756 | case POWERPC_MMU_32B: | |
10757 | case POWERPC_MMU_601: | |
10758 | case POWERPC_MMU_SOFT_6xx: | |
10759 | case POWERPC_MMU_SOFT_74xx: | |
10760 | #if defined(TARGET_PPC64) | |
90dc8812 | 10761 | case POWERPC_MMU_64B: |
ca480de6 AB |
10762 | case POWERPC_MMU_2_06: |
10763 | case POWERPC_MMU_2_06a: | |
10764 | case POWERPC_MMU_2_06d: | |
90dc8812 | 10765 | #endif |
ca480de6 AB |
10766 | cpu_fprintf(f, " SDR1 " TARGET_FMT_lx " DAR " TARGET_FMT_lx |
10767 | " DSISR " TARGET_FMT_lx "\n", env->spr[SPR_SDR1], | |
10768 | env->spr[SPR_DAR], env->spr[SPR_DSISR]); | |
90dc8812 | 10769 | break; |
01662f3e | 10770 | case POWERPC_MMU_BOOKE206: |
90dc8812 SW |
10771 | cpu_fprintf(f, " MAS0 " TARGET_FMT_lx " MAS1 " TARGET_FMT_lx |
10772 | " MAS2 " TARGET_FMT_lx " MAS3 " TARGET_FMT_lx "\n", | |
10773 | env->spr[SPR_BOOKE_MAS0], env->spr[SPR_BOOKE_MAS1], | |
10774 | env->spr[SPR_BOOKE_MAS2], env->spr[SPR_BOOKE_MAS3]); | |
10775 | ||
10776 | cpu_fprintf(f, " MAS4 " TARGET_FMT_lx " MAS6 " TARGET_FMT_lx | |
10777 | " MAS7 " TARGET_FMT_lx " PID " TARGET_FMT_lx "\n", | |
10778 | env->spr[SPR_BOOKE_MAS4], env->spr[SPR_BOOKE_MAS6], | |
10779 | env->spr[SPR_BOOKE_MAS7], env->spr[SPR_BOOKE_PID]); | |
10780 | ||
10781 | cpu_fprintf(f, "MMUCFG " TARGET_FMT_lx " TLB0CFG " TARGET_FMT_lx | |
10782 | " TLB1CFG " TARGET_FMT_lx "\n", | |
10783 | env->spr[SPR_MMUCFG], env->spr[SPR_BOOKE_TLB0CFG], | |
10784 | env->spr[SPR_BOOKE_TLB1CFG]); | |
10785 | break; | |
10786 | default: | |
10787 | break; | |
10788 | } | |
f2e63a42 | 10789 | #endif |
79aceca5 | 10790 | |
3fc6c082 FB |
10791 | #undef RGPL |
10792 | #undef RFPL | |
79aceca5 FB |
10793 | } |
10794 | ||
878096ee AF |
10795 | void ppc_cpu_dump_statistics(CPUState *cs, FILE*f, |
10796 | fprintf_function cpu_fprintf, int flags) | |
76a66253 JM |
10797 | { |
10798 | #if defined(DO_PPC_STATISTICS) | |
878096ee | 10799 | PowerPCCPU *cpu = POWERPC_CPU(cs); |
c227f099 | 10800 | opc_handler_t **t1, **t2, **t3, *handler; |
76a66253 JM |
10801 | int op1, op2, op3; |
10802 | ||
878096ee | 10803 | t1 = cpu->env.opcodes; |
76a66253 JM |
10804 | for (op1 = 0; op1 < 64; op1++) { |
10805 | handler = t1[op1]; | |
10806 | if (is_indirect_opcode(handler)) { | |
10807 | t2 = ind_table(handler); | |
10808 | for (op2 = 0; op2 < 32; op2++) { | |
10809 | handler = t2[op2]; | |
10810 | if (is_indirect_opcode(handler)) { | |
10811 | t3 = ind_table(handler); | |
10812 | for (op3 = 0; op3 < 32; op3++) { | |
10813 | handler = t3[op3]; | |
10814 | if (handler->count == 0) | |
10815 | continue; | |
10816 | cpu_fprintf(f, "%02x %02x %02x (%02x %04d) %16s: " | |
0bfcd599 | 10817 | "%016" PRIx64 " %" PRId64 "\n", |
76a66253 JM |
10818 | op1, op2, op3, op1, (op3 << 5) | op2, |
10819 | handler->oname, | |
10820 | handler->count, handler->count); | |
10821 | } | |
10822 | } else { | |
10823 | if (handler->count == 0) | |
10824 | continue; | |
10825 | cpu_fprintf(f, "%02x %02x (%02x %04d) %16s: " | |
0bfcd599 | 10826 | "%016" PRIx64 " %" PRId64 "\n", |
76a66253 JM |
10827 | op1, op2, op1, op2, handler->oname, |
10828 | handler->count, handler->count); | |
10829 | } | |
10830 | } | |
10831 | } else { | |
10832 | if (handler->count == 0) | |
10833 | continue; | |
0bfcd599 BS |
10834 | cpu_fprintf(f, "%02x (%02x ) %16s: %016" PRIx64 |
10835 | " %" PRId64 "\n", | |
76a66253 JM |
10836 | op1, op1, handler->oname, |
10837 | handler->count, handler->count); | |
10838 | } | |
10839 | } | |
10840 | #endif | |
10841 | } | |
10842 | ||
9a64fbe4 | 10843 | /*****************************************************************************/ |
213fe1f5 | 10844 | static inline void gen_intermediate_code_internal(PowerPCCPU *cpu, |
636aa200 | 10845 | TranslationBlock *tb, |
213fe1f5 | 10846 | bool search_pc) |
79aceca5 | 10847 | { |
ed2803da | 10848 | CPUState *cs = CPU(cpu); |
213fe1f5 | 10849 | CPUPPCState *env = &cpu->env; |
9fddaa0c | 10850 | DisasContext ctx, *ctxp = &ctx; |
c227f099 | 10851 | opc_handler_t **table, *handler; |
0fa85d43 | 10852 | target_ulong pc_start; |
79aceca5 | 10853 | uint16_t *gen_opc_end; |
a1d1bb31 | 10854 | CPUBreakpoint *bp; |
79aceca5 | 10855 | int j, lj = -1; |
2e70f6ef PB |
10856 | int num_insns; |
10857 | int max_insns; | |
79aceca5 FB |
10858 | |
10859 | pc_start = tb->pc; | |
92414b31 | 10860 | gen_opc_end = tcg_ctx.gen_opc_buf + OPC_MAX_SIZE; |
046d6672 | 10861 | ctx.nip = pc_start; |
79aceca5 | 10862 | ctx.tb = tb; |
e1833e1f | 10863 | ctx.exception = POWERPC_EXCP_NONE; |
3fc6c082 | 10864 | ctx.spr_cb = env->spr_cb; |
76db3ba4 | 10865 | ctx.mem_idx = env->mmu_idx; |
7d08d856 AJ |
10866 | ctx.insns_flags = env->insns_flags; |
10867 | ctx.insns_flags2 = env->insns_flags2; | |
76db3ba4 AJ |
10868 | ctx.access_type = -1; |
10869 | ctx.le_mode = env->hflags & (1 << MSR_LE) ? 1 : 0; | |
d9bce9d9 | 10870 | #if defined(TARGET_PPC64) |
e42a61f1 | 10871 | ctx.sf_mode = msr_is_64bit(env, env->msr); |
697ab892 | 10872 | ctx.has_cfar = !!(env->flags & POWERPC_FLAG_CFAR); |
9a64fbe4 | 10873 | #endif |
3cc62370 | 10874 | ctx.fpu_enabled = msr_fp; |
a9d9eb8f | 10875 | if ((env->flags & POWERPC_FLAG_SPE) && msr_spe) |
d26bfc9a JM |
10876 | ctx.spe_enabled = msr_spe; |
10877 | else | |
10878 | ctx.spe_enabled = 0; | |
a9d9eb8f JM |
10879 | if ((env->flags & POWERPC_FLAG_VRE) && msr_vr) |
10880 | ctx.altivec_enabled = msr_vr; | |
10881 | else | |
10882 | ctx.altivec_enabled = 0; | |
1f29871c TM |
10883 | if ((env->flags & POWERPC_FLAG_VSX) && msr_vsx) { |
10884 | ctx.vsx_enabled = msr_vsx; | |
10885 | } else { | |
10886 | ctx.vsx_enabled = 0; | |
10887 | } | |
d26bfc9a | 10888 | if ((env->flags & POWERPC_FLAG_SE) && msr_se) |
8cbcb4fa | 10889 | ctx.singlestep_enabled = CPU_SINGLE_STEP; |
d26bfc9a | 10890 | else |
8cbcb4fa | 10891 | ctx.singlestep_enabled = 0; |
d26bfc9a | 10892 | if ((env->flags & POWERPC_FLAG_BE) && msr_be) |
8cbcb4fa | 10893 | ctx.singlestep_enabled |= CPU_BRANCH_STEP; |
ed2803da | 10894 | if (unlikely(cs->singlestep_enabled)) { |
8cbcb4fa | 10895 | ctx.singlestep_enabled |= GDBSTUB_SINGLE_STEP; |
ed2803da | 10896 | } |
3fc6c082 | 10897 | #if defined (DO_SINGLE_STEP) && 0 |
9a64fbe4 FB |
10898 | /* Single step trace mode */ |
10899 | msr_se = 1; | |
10900 | #endif | |
2e70f6ef PB |
10901 | num_insns = 0; |
10902 | max_insns = tb->cflags & CF_COUNT_MASK; | |
10903 | if (max_insns == 0) | |
10904 | max_insns = CF_COUNT_MASK; | |
10905 | ||
806f352d | 10906 | gen_tb_start(); |
9a64fbe4 | 10907 | /* Set env in case of segfault during code fetch */ |
efd7f486 EV |
10908 | while (ctx.exception == POWERPC_EXCP_NONE |
10909 | && tcg_ctx.gen_opc_ptr < gen_opc_end) { | |
72cf2d4f BS |
10910 | if (unlikely(!QTAILQ_EMPTY(&env->breakpoints))) { |
10911 | QTAILQ_FOREACH(bp, &env->breakpoints, entry) { | |
a1d1bb31 | 10912 | if (bp->pc == ctx.nip) { |
e06fcd75 | 10913 | gen_debug_exception(ctxp); |
ea4e754f FB |
10914 | break; |
10915 | } | |
10916 | } | |
10917 | } | |
76a66253 | 10918 | if (unlikely(search_pc)) { |
92414b31 | 10919 | j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf; |
79aceca5 FB |
10920 | if (lj < j) { |
10921 | lj++; | |
10922 | while (lj < j) | |
ab1103de | 10923 | tcg_ctx.gen_opc_instr_start[lj++] = 0; |
79aceca5 | 10924 | } |
25983cad | 10925 | tcg_ctx.gen_opc_pc[lj] = ctx.nip; |
ab1103de | 10926 | tcg_ctx.gen_opc_instr_start[lj] = 1; |
c9c99c22 | 10927 | tcg_ctx.gen_opc_icount[lj] = num_insns; |
79aceca5 | 10928 | } |
d12d51d5 | 10929 | LOG_DISAS("----------------\n"); |
90e189ec | 10930 | LOG_DISAS("nip=" TARGET_FMT_lx " super=%d ir=%d\n", |
d12d51d5 | 10931 | ctx.nip, ctx.mem_idx, (int)msr_ir); |
2e70f6ef PB |
10932 | if (num_insns + 1 == max_insns && (tb->cflags & CF_LAST_IO)) |
10933 | gen_io_start(); | |
76db3ba4 | 10934 | if (unlikely(ctx.le_mode)) { |
2f5a189c | 10935 | ctx.opcode = bswap32(cpu_ldl_code(env, ctx.nip)); |
056401ea | 10936 | } else { |
2f5a189c | 10937 | ctx.opcode = cpu_ldl_code(env, ctx.nip); |
111bfab3 | 10938 | } |
d12d51d5 | 10939 | LOG_DISAS("translate opcode %08x (%02x %02x %02x) (%s)\n", |
9a64fbe4 | 10940 | ctx.opcode, opc1(ctx.opcode), opc2(ctx.opcode), |
476b6d16 | 10941 | opc3(ctx.opcode), ctx.le_mode ? "little" : "big"); |
fdefe51c | 10942 | if (unlikely(qemu_loglevel_mask(CPU_LOG_TB_OP | CPU_LOG_TB_OP_OPT))) { |
731c54f8 | 10943 | tcg_gen_debug_insn_start(ctx.nip); |
fdefe51c | 10944 | } |
046d6672 | 10945 | ctx.nip += 4; |
3fc6c082 | 10946 | table = env->opcodes; |
2e70f6ef | 10947 | num_insns++; |
79aceca5 FB |
10948 | handler = table[opc1(ctx.opcode)]; |
10949 | if (is_indirect_opcode(handler)) { | |
10950 | table = ind_table(handler); | |
10951 | handler = table[opc2(ctx.opcode)]; | |
10952 | if (is_indirect_opcode(handler)) { | |
10953 | table = ind_table(handler); | |
10954 | handler = table[opc3(ctx.opcode)]; | |
10955 | } | |
10956 | } | |
10957 | /* Is opcode *REALLY* valid ? */ | |
76a66253 | 10958 | if (unlikely(handler->handler == &gen_invalid)) { |
93fcfe39 AL |
10959 | if (qemu_log_enabled()) { |
10960 | qemu_log("invalid/unsupported opcode: " | |
90e189ec BS |
10961 | "%02x - %02x - %02x (%08x) " TARGET_FMT_lx " %d\n", |
10962 | opc1(ctx.opcode), opc2(ctx.opcode), | |
10963 | opc3(ctx.opcode), ctx.opcode, ctx.nip - 4, (int)msr_ir); | |
4b3686fa | 10964 | } |
76a66253 | 10965 | } else { |
70560da7 FC |
10966 | uint32_t inval; |
10967 | ||
10968 | if (unlikely(handler->type & (PPC_SPE | PPC_SPE_SINGLE | PPC_SPE_DOUBLE) && Rc(ctx.opcode))) { | |
10969 | inval = handler->inval2; | |
10970 | } else { | |
10971 | inval = handler->inval1; | |
10972 | } | |
10973 | ||
10974 | if (unlikely((ctx.opcode & inval) != 0)) { | |
93fcfe39 AL |
10975 | if (qemu_log_enabled()) { |
10976 | qemu_log("invalid bits: %08x for opcode: " | |
90e189ec | 10977 | "%02x - %02x - %02x (%08x) " TARGET_FMT_lx "\n", |
70560da7 | 10978 | ctx.opcode & inval, opc1(ctx.opcode), |
90e189ec BS |
10979 | opc2(ctx.opcode), opc3(ctx.opcode), |
10980 | ctx.opcode, ctx.nip - 4); | |
76a66253 | 10981 | } |
e06fcd75 | 10982 | gen_inval_exception(ctxp, POWERPC_EXCP_INVAL_INVAL); |
4b3686fa | 10983 | break; |
79aceca5 | 10984 | } |
79aceca5 | 10985 | } |
4b3686fa | 10986 | (*(handler->handler))(&ctx); |
76a66253 JM |
10987 | #if defined(DO_PPC_STATISTICS) |
10988 | handler->count++; | |
10989 | #endif | |
9a64fbe4 | 10990 | /* Check trace mode exceptions */ |
8cbcb4fa AJ |
10991 | if (unlikely(ctx.singlestep_enabled & CPU_SINGLE_STEP && |
10992 | (ctx.nip <= 0x100 || ctx.nip > 0xF00) && | |
10993 | ctx.exception != POWERPC_SYSCALL && | |
10994 | ctx.exception != POWERPC_EXCP_TRAP && | |
10995 | ctx.exception != POWERPC_EXCP_BRANCH)) { | |
e06fcd75 | 10996 | gen_exception(ctxp, POWERPC_EXCP_TRACE); |
d26bfc9a | 10997 | } else if (unlikely(((ctx.nip & (TARGET_PAGE_SIZE - 1)) == 0) || |
ed2803da | 10998 | (cs->singlestep_enabled) || |
1b530a6d | 10999 | singlestep || |
2e70f6ef | 11000 | num_insns >= max_insns)) { |
d26bfc9a JM |
11001 | /* if we reach a page boundary or are single stepping, stop |
11002 | * generation | |
11003 | */ | |
8dd4983c | 11004 | break; |
76a66253 | 11005 | } |
3fc6c082 | 11006 | } |
2e70f6ef PB |
11007 | if (tb->cflags & CF_LAST_IO) |
11008 | gen_io_end(); | |
e1833e1f | 11009 | if (ctx.exception == POWERPC_EXCP_NONE) { |
c1942362 | 11010 | gen_goto_tb(&ctx, 0, ctx.nip); |
e1833e1f | 11011 | } else if (ctx.exception != POWERPC_EXCP_BRANCH) { |
ed2803da | 11012 | if (unlikely(cs->singlestep_enabled)) { |
e06fcd75 | 11013 | gen_debug_exception(ctxp); |
8cbcb4fa | 11014 | } |
76a66253 | 11015 | /* Generate the return instruction */ |
57fec1fe | 11016 | tcg_gen_exit_tb(0); |
9a64fbe4 | 11017 | } |
806f352d | 11018 | gen_tb_end(tb, num_insns); |
efd7f486 | 11019 | *tcg_ctx.gen_opc_ptr = INDEX_op_end; |
76a66253 | 11020 | if (unlikely(search_pc)) { |
92414b31 | 11021 | j = tcg_ctx.gen_opc_ptr - tcg_ctx.gen_opc_buf; |
9a64fbe4 FB |
11022 | lj++; |
11023 | while (lj <= j) | |
ab1103de | 11024 | tcg_ctx.gen_opc_instr_start[lj++] = 0; |
9a64fbe4 | 11025 | } else { |
046d6672 | 11026 | tb->size = ctx.nip - pc_start; |
2e70f6ef | 11027 | tb->icount = num_insns; |
9a64fbe4 | 11028 | } |
d9bce9d9 | 11029 | #if defined(DEBUG_DISAS) |
8fec2b8c | 11030 | if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) { |
76a66253 | 11031 | int flags; |
237c0af0 | 11032 | flags = env->bfd_mach; |
76db3ba4 | 11033 | flags |= ctx.le_mode << 16; |
93fcfe39 | 11034 | qemu_log("IN: %s\n", lookup_symbol(pc_start)); |
f4359b9f | 11035 | log_target_disas(env, pc_start, ctx.nip - pc_start, flags); |
93fcfe39 | 11036 | qemu_log("\n"); |
9fddaa0c | 11037 | } |
79aceca5 | 11038 | #endif |
79aceca5 FB |
11039 | } |
11040 | ||
1328c2bf | 11041 | void gen_intermediate_code (CPUPPCState *env, struct TranslationBlock *tb) |
79aceca5 | 11042 | { |
213fe1f5 | 11043 | gen_intermediate_code_internal(ppc_env_get_cpu(env), tb, false); |
79aceca5 FB |
11044 | } |
11045 | ||
1328c2bf | 11046 | void gen_intermediate_code_pc (CPUPPCState *env, struct TranslationBlock *tb) |
79aceca5 | 11047 | { |
213fe1f5 | 11048 | gen_intermediate_code_internal(ppc_env_get_cpu(env), tb, true); |
79aceca5 | 11049 | } |
d2856f1a | 11050 | |
1328c2bf | 11051 | void restore_state_to_opc(CPUPPCState *env, TranslationBlock *tb, int pc_pos) |
d2856f1a | 11052 | { |
25983cad | 11053 | env->nip = tcg_ctx.gen_opc_pc[pc_pos]; |
d2856f1a | 11054 | } |